diff --git a/packages/opencode/migration/20260227213759_add_session_org_id/migration.sql b/packages/opencode/migration/20260227213759_add_session_org_id/migration.sql new file mode 100644 index 0000000000..7513b0af38 --- /dev/null +++ b/packages/opencode/migration/20260227213759_add_session_org_id/migration.sql @@ -0,0 +1,2 @@ +ALTER TABLE `session` ADD `org_id` text;--> statement-breakpoint +CREATE INDEX `session_org_idx` ON `session` (`org_id`); \ No newline at end of file diff --git a/packages/opencode/migration/20260227213759_add_session_workspace_id/snapshot.json b/packages/opencode/migration/20260227213759_add_session_org_id/snapshot.json similarity index 99% rename from packages/opencode/migration/20260227213759_add_session_workspace_id/snapshot.json rename to packages/opencode/migration/20260227213759_add_session_org_id/snapshot.json index 8cd94d0052..751dbfe5e5 100644 --- a/packages/opencode/migration/20260227213759_add_session_workspace_id/snapshot.json +++ b/packages/opencode/migration/20260227213759_add_session_org_id/snapshot.json @@ -446,7 +446,7 @@ "autoincrement": false, "default": null, "generated": null, - "name": "workspace_id", + "name": "org_id", "entityType": "columns", "table": "session" }, @@ -939,14 +939,14 @@ { "columns": [ { - "value": "workspace_id", + "value": "org_id", "isExpression": false } ], "isUnique": false, "where": null, "origin": "manual", - "name": "session_workspace_idx", + "name": "session_org_idx", "entityType": "indexes", "table": "session" }, diff --git a/packages/opencode/migration/20260227213759_add_session_workspace_id/migration.sql b/packages/opencode/migration/20260227213759_add_session_workspace_id/migration.sql deleted file mode 100644 index f5488af218..0000000000 --- a/packages/opencode/migration/20260227213759_add_session_workspace_id/migration.sql +++ /dev/null @@ -1,2 +0,0 @@ -ALTER TABLE `session` ADD `workspace_id` text;--> statement-breakpoint -CREATE INDEX `session_workspace_idx` ON `session` (`workspace_id`); \ No newline at end of file diff --git a/packages/opencode/migration/20260228203230_blue_harpoon/migration.sql b/packages/opencode/migration/20260228203230_blue_harpoon/migration.sql index 19ce1e5f6f..897c0f473e 100644 --- a/packages/opencode/migration/20260228203230_blue_harpoon/migration.sql +++ b/packages/opencode/migration/20260228203230_blue_harpoon/migration.sql @@ -5,7 +5,7 @@ CREATE TABLE `account` ( `access_token` text NOT NULL, `refresh_token` text NOT NULL, `token_expiry` integer, - `workspace_id` text, + `org_id` text, `time_created` integer NOT NULL, `time_updated` integer NOT NULL ); diff --git a/packages/opencode/migration/20260228203230_blue_harpoon/snapshot.json b/packages/opencode/migration/20260228203230_blue_harpoon/snapshot.json index 4fb8465f6e..108641acc1 100644 --- a/packages/opencode/migration/20260228203230_blue_harpoon/snapshot.json +++ b/packages/opencode/migration/20260228203230_blue_harpoon/snapshot.json @@ -112,7 +112,7 @@ "autoincrement": false, "default": null, "generated": null, - "name": "workspace_id", + "name": "org_id", "entityType": "columns", "table": "account" }, diff --git a/packages/opencode/src/account/account.sql.ts b/packages/opencode/src/account/account.sql.ts index 7f6ba97ae9..deeb8a4fcf 100644 --- a/packages/opencode/src/account/account.sql.ts +++ b/packages/opencode/src/account/account.sql.ts @@ -8,7 +8,7 @@ export const AccountTable = sqliteTable("account", { access_token: text().notNull(), refresh_token: text().notNull(), token_expiry: integer(), - workspace_id: text(), + org_id: text(), ...Timestamps, }) diff --git a/packages/opencode/src/account/index.ts b/packages/opencode/src/account/index.ts index d6b503cf33..3bb02c057a 100644 --- a/packages/opencode/src/account/index.ts +++ b/packages/opencode/src/account/index.ts @@ -8,7 +8,7 @@ export namespace Account { id: z.string(), email: z.string(), url: z.string(), - workspace_id: z.string().nullable(), + org_id: z.string().nullable(), }) export type Account = z.infer @@ -17,12 +17,12 @@ export namespace Account { id: row.id, email: row.email, url: row.url, - workspace_id: row.workspace_id, + org_id: row.org_id, } } export function active(): Account | undefined { - const row = Database.use((db) => db.select().from(AccountTable).where(isNotNull(AccountTable.workspace_id)).get()) + const row = Database.use((db) => db.select().from(AccountTable).where(isNotNull(AccountTable.org_id)).get()) return row ? fromRow(row) : undefined } @@ -34,13 +34,13 @@ export namespace Account { Database.use((db) => db.delete(AccountTable).where(eq(AccountTable.id, accountID)).run()) } - export function use(accountID: string, workspaceID: string | null) { + export function use(accountID: string, orgID: string | null) { Database.use((db) => - db.update(AccountTable).set({ workspace_id: workspaceID }).where(eq(AccountTable.id, accountID)).run(), + db.update(AccountTable).set({ org_id: orgID }).where(eq(AccountTable.id, accountID)).run(), ) } - export async function workspaces(accountID: string): Promise<{ id: string; name: string }[]> { + export async function orgs(accountID: string): Promise<{ id: string; name: string }[]> { const row = Database.use((db) => db.select().from(AccountTable).where(eq(AccountTable.id, accountID)).get()) if (!row) return [] @@ -57,7 +57,7 @@ export namespace Account { return json.map((x) => ({ id: x.id ?? "", name: x.name ?? "" })) } - export async function config(accountID: string, workspaceID: string): Promise | undefined> { + export async function config(accountID: string, orgID: string): Promise | undefined> { const row = Database.use((db) => db.select().from(AccountTable).where(eq(AccountTable.id, accountID)).get()) if (!row) return undefined @@ -65,7 +65,7 @@ export namespace Account { if (!access) return undefined const res = await fetch(`${row.url}/api/config`, { - headers: { authorization: `Bearer ${access}`, "x-org-id": workspaceID }, + headers: { authorization: `Bearer ${access}`, "x-org-id": orgID }, }) if (!res.ok) return undefined @@ -192,15 +192,15 @@ export namespace Account { const expiry = Date.now() + json.expires_in! * 1000 const refresh = json.refresh_token ?? "" - // Fetch workspaces and get first one + // Fetch orgs and get first one const orgsRes = await fetch(`${input.server}/api/orgs`, { headers: { authorization: `Bearer ${access}` }, }) const orgs = (await orgsRes.json()) as Array<{ id?: string; name?: string }> - const firstWorkspaceId = orgs.length > 0 ? orgs[0].id : null + const firstOrgId = orgs.length > 0 ? orgs[0].id : null Database.use((db) => { - db.update(AccountTable).set({ workspace_id: null }).run() + db.update(AccountTable).set({ org_id: null }).run() db.insert(AccountTable) .values({ id, @@ -209,7 +209,7 @@ export namespace Account { access_token: access, refresh_token: refresh, token_expiry: expiry, - workspace_id: firstWorkspaceId, + org_id: firstOrgId, }) .onConflictDoUpdate({ target: AccountTable.id, @@ -217,7 +217,7 @@ export namespace Account { access_token: access, refresh_token: refresh, token_expiry: expiry, - workspace_id: firstWorkspaceId, + org_id: firstOrgId, }, }) .run() diff --git a/packages/opencode/src/cli/cmd/account.ts b/packages/opencode/src/cli/cmd/account.ts index ef1c64c806..c5d85083f1 100644 --- a/packages/opencode/src/cli/cmd/account.ts +++ b/packages/opencode/src/cli/cmd/account.ts @@ -104,7 +104,7 @@ export const LogoutCommand = cmd({ export const SwitchCommand = cmd({ command: "switch", - describe: "switch active workspace", + describe: "switch active org", async handler() { UI.empty() @@ -114,35 +114,35 @@ export const SwitchCommand = cmd({ return } - const workspaces = await Account.workspaces(active.id) - if (workspaces.length === 0) { - UI.println("No workspaces found") + const orgs = await Account.orgs(active.id) + if (orgs.length === 0) { + UI.println("No orgs found") return } - prompts.intro("Switch workspace") + prompts.intro("Switch org") - const opts = workspaces.map((w) => ({ - value: w.id, - label: w.id === active.workspace_id ? w.name + UI.Style.TEXT_DIM + " (active)" : w.name, + const opts = orgs.map((o) => ({ + value: o.id, + label: o.id === active.org_id ? o.name + UI.Style.TEXT_DIM + " (active)" : o.name, })) const selected = await prompts.select({ - message: "Select workspace", + message: "Select org", options: opts, }) if (prompts.isCancel(selected)) return Account.use(active.id, selected as string) - prompts.outro("Switched to " + workspaces.find((w) => w.id === selected)?.name) + prompts.outro("Switched to " + orgs.find((o) => o.id === selected)?.name) }, }) -export const WorkspacesCommand = cmd({ - command: "workspaces", - aliases: ["workspace"], - describe: "list all workspaces", +export const OrgsCommand = cmd({ + command: "orgs", + aliases: ["org"], + describe: "list all orgs", async handler() { const accounts = Account.list() @@ -152,9 +152,9 @@ export const WorkspacesCommand = cmd({ } for (const account of accounts) { - const workspaces = await Account.workspaces(account.id) - for (const space of workspaces) { - UI.println([space.name, account.email, space.id].join("\t")) + const orgs = await Account.orgs(account.id) + for (const org of orgs) { + UI.println([org.name, account.email, org.id].join("\t")) } } }, diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index 405bd8b979..39aa77405f 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -174,8 +174,8 @@ export namespace Config { } const active = Account.active() - if (active?.workspace_id) { - const config = await Account.config(active.id, active.workspace_id) + if (active?.org_id) { + const config = await Account.config(active.id, active.org_id) result = mergeConfigConcatArrays(result, config ?? {}) const token = await Account.token(active.id) // TODO: this is bad diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts index e4b85e3902..8af2f07266 100644 --- a/packages/opencode/src/index.ts +++ b/packages/opencode/src/index.ts @@ -3,7 +3,7 @@ import { hideBin } from "yargs/helpers" import { RunCommand } from "./cli/cmd/run" import { GenerateCommand } from "./cli/cmd/generate" import { Log } from "./util/log" -import { LoginCommand, LogoutCommand, SwitchCommand, WorkspacesCommand } from "./cli/cmd/account" +import { LoginCommand, LogoutCommand, SwitchCommand, OrgsCommand } from "./cli/cmd/account" import { ProvidersCommand } from "./cli/cmd/providers" import { AgentCommand } from "./cli/cmd/agent" import { UpgradeCommand } from "./cli/cmd/upgrade" @@ -133,7 +133,7 @@ let cli = yargs(hideBin(process.argv)) .command(LoginCommand) .command(LogoutCommand) .command(SwitchCommand) - .command(WorkspacesCommand) + .command(OrgsCommand) .command(ProvidersCommand) .command(AgentCommand) .command(UpgradeCommand) diff --git a/packages/opencode/src/session/index.ts b/packages/opencode/src/session/index.ts index e8db405fdd..a57d1f80d1 100644 --- a/packages/opencode/src/session/index.ts +++ b/packages/opencode/src/session/index.ts @@ -64,7 +64,7 @@ export namespace Session { id: row.id, slug: row.slug, projectID: row.project_id, - workspaceID: row.workspace_id ?? undefined, + orgID: row.org_id ?? undefined, directory: row.directory, parentID: row.parent_id ?? undefined, title: row.title, @@ -86,7 +86,7 @@ export namespace Session { return { id: info.id, project_id: info.projectID, - workspace_id: info.workspaceID, + org_id: info.orgID, parent_id: info.parentID, slug: info.slug, directory: info.directory, @@ -121,7 +121,7 @@ export namespace Session { id: Identifier.schema("session"), slug: z.string(), projectID: z.string(), - workspaceID: z.string().optional(), + orgID: z.string().optional(), directory: z.string(), parentID: Identifier.schema("session").optional(), summary: z @@ -301,7 +301,7 @@ export namespace Session { version: Installation.VERSION, projectID: Instance.project.id, directory: input.directory, - workspaceID: WorkspaceContext.workspaceID, + orgID: WorkspaceContext.workspaceID, parentID: input.parentID, title: input.title ?? createDefaultTitle(!!input.parentID), permission: input.permission, @@ -532,7 +532,7 @@ export namespace Session { export function* list(input?: { directory?: string - workspaceID?: string + orgID?: string roots?: boolean start?: number search?: string @@ -542,7 +542,7 @@ export namespace Session { const conditions = [eq(SessionTable.project_id, project.id)] if (WorkspaceContext.workspaceID) { - conditions.push(eq(SessionTable.workspace_id, WorkspaceContext.workspaceID)) + conditions.push(eq(SessionTable.org_id, WorkspaceContext.workspaceID)) } if (input?.directory) { conditions.push(eq(SessionTable.directory, input.directory)) diff --git a/packages/opencode/src/session/session.sql.ts b/packages/opencode/src/session/session.sql.ts index 0630760f3b..2573ad1cb5 100644 --- a/packages/opencode/src/session/session.sql.ts +++ b/packages/opencode/src/session/session.sql.ts @@ -15,7 +15,7 @@ export const SessionTable = sqliteTable( project_id: text() .notNull() .references(() => ProjectTable.id, { onDelete: "cascade" }), - workspace_id: text(), + org_id: text(), parent_id: text(), slug: text().notNull(), directory: text().notNull(), @@ -34,7 +34,7 @@ export const SessionTable = sqliteTable( }, (table) => [ index("session_project_idx").on(table.project_id), - index("session_workspace_idx").on(table.workspace_id), + index("session_org_idx").on(table.org_id), index("session_parent_idx").on(table.parent_id), ], ) diff --git a/packages/sdk/js/src/v2/gen/types.gen.ts b/packages/sdk/js/src/v2/gen/types.gen.ts index 669883590d..ca1de76323 100644 --- a/packages/sdk/js/src/v2/gen/types.gen.ts +++ b/packages/sdk/js/src/v2/gen/types.gen.ts @@ -808,7 +808,7 @@ export type Session = { id: string slug: string projectID: string - workspaceID?: string + orgID?: string directory: string parentID?: string summary?: { @@ -1672,7 +1672,7 @@ export type GlobalSession = { id: string slug: string projectID: string - workspaceID?: string + orgID?: string directory: string parentID?: string summary?: { diff --git a/packages/sdk/openapi.json b/packages/sdk/openapi.json index 8e88b09691..a1faa83837 100644 --- a/packages/sdk/openapi.json +++ b/packages/sdk/openapi.json @@ -9046,7 +9046,7 @@ "projectID": { "type": "string" }, - "workspaceID": { + "orgID": { "type": "string" }, "directory": { @@ -11111,7 +11111,7 @@ "projectID": { "type": "string" }, - "workspaceID": { + "orgID": { "type": "string" }, "directory": {