Skip to content

Commit a4330a2

Browse files
authored
feat(core): allow passing workspaceID into session create endpoint (anomalyco#16798)
1 parent 69ddc91 commit a4330a2

8 files changed

Lines changed: 18 additions & 3 deletions

File tree

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,12 @@ function App() {
402402
const current = promptRef.current
403403
// Don't require focus - if there's any text, preserve it
404404
const currentPrompt = current?.current?.input ? current.current : undefined
405+
const workspaceID =
406+
route.data.type === "session" ? sync.session.get(route.data.sessionID)?.workspaceID : undefined
405407
route.navigate({
406408
type: "home",
407409
initialPrompt: currentPrompt,
410+
workspaceID,
408411
})
409412
dialog.clear()
410413
},

packages/opencode/src/cli/cmd/tui/component/dialog-workspace-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function openWorkspace(input: {
4747
}
4848
let created: Session | undefined
4949
while (!created) {
50-
const result = await client.session.create({}).catch(() => undefined)
50+
const result = await client.session.create({ workspaceID: input.workspaceID }).catch(() => undefined)
5151
if (!result) {
5252
input.toast.show({
5353
message: "Failed to open workspace",

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { DialogSkill } from "../dialog-skill"
3737

3838
export type PromptProps = {
3939
sessionID?: string
40+
workspaceID?: string
4041
visible?: boolean
4142
disabled?: boolean
4243
onSubmit?: () => void
@@ -542,7 +543,9 @@ export function Prompt(props: PromptProps) {
542543

543544
let sessionID = props.sessionID
544545
if (sessionID == null) {
545-
const res = await sdk.client.session.create({})
546+
const res = await sdk.client.session.create({
547+
workspaceID: props.workspaceID,
548+
})
546549

547550
if (res.error) {
548551
console.log("Creating a session failed:", res.error)

packages/opencode/src/cli/cmd/tui/context/route.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { PromptInfo } from "../component/prompt/history"
55
export type HomeRoute = {
66
type: "home"
77
initialPrompt?: PromptInfo
8+
workspaceID?: string
89
}
910

1011
export type SessionRoute = {

packages/opencode/src/cli/cmd/tui/routes/home.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export function Home() {
121121
promptRef.set(r)
122122
}}
123123
hint={Hint}
124+
workspaceID={route.workspaceID}
124125
/>
125126
</box>
126127
<box height={4} minHeight={0} width="100%" maxWidth={75} alignItems="center" paddingTop={3} flexShrink={1}>

packages/opencode/src/session/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export namespace Session {
219219
parentID: Identifier.schema("session").optional(),
220220
title: z.string().optional(),
221221
permission: Info.shape.permission,
222+
workspaceID: Identifier.schema("workspace").optional(),
222223
})
223224
.optional(),
224225
async (input) => {
@@ -227,6 +228,7 @@ export namespace Session {
227228
directory: Instance.directory,
228229
title: input?.title,
229230
permission: input?.permission,
231+
workspaceID: input?.workspaceID,
230232
})
231233
},
232234
)
@@ -242,6 +244,7 @@ export namespace Session {
242244
const title = getForkedTitle(original.title)
243245
const session = await createNext({
244246
directory: Instance.directory,
247+
workspaceID: original.workspaceID,
245248
title,
246249
})
247250
const msgs = await messages({ sessionID: input.sessionID })
@@ -292,6 +295,7 @@ export namespace Session {
292295
id?: string
293296
title?: string
294297
parentID?: string
298+
workspaceID?: string
295299
directory: string
296300
permission?: PermissionNext.Ruleset
297301
}) {
@@ -301,7 +305,7 @@ export namespace Session {
301305
version: Installation.VERSION,
302306
projectID: Instance.project.id,
303307
directory: input.directory,
304-
workspaceID: WorkspaceContext.workspaceID,
308+
workspaceID: input.workspaceID,
305309
parentID: input.parentID,
306310
title: input.title ?? createDefaultTitle(!!input.parentID),
307311
permission: input.permission,

packages/sdk/js/src/v2/gen/sdk.gen.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,7 @@ export class Session2 extends HeyApiClient {
12951295
parentID?: string
12961296
title?: string
12971297
permission?: PermissionRuleset
1298+
workspaceID?: string
12981299
},
12991300
options?: Options<never, ThrowOnError>,
13001301
) {
@@ -1308,6 +1309,7 @@ export class Session2 extends HeyApiClient {
13081309
{ in: "body", key: "parentID" },
13091310
{ in: "body", key: "title" },
13101311
{ in: "body", key: "permission" },
1312+
{ in: "body", key: "workspaceID" },
13111313
],
13121314
},
13131315
],

packages/sdk/js/src/v2/gen/types.gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2764,6 +2764,7 @@ export type SessionCreateData = {
27642764
parentID?: string
27652765
title?: string
27662766
permission?: PermissionRuleset
2767+
workspaceID?: string
27672768
}
27682769
path?: never
27692770
query?: {

0 commit comments

Comments
 (0)