Skip to content

Commit c4ccb50

Browse files
authored
fix(app): fork should copy prompt into new session (#17375)
1 parent 5aaf1dd commit c4ccb50

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

packages/app/src/components/dialog-fork.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const DialogFork: Component = () => {
6666
directory: sdk.directory,
6767
attachmentName: language.t("common.attachment"),
6868
})
69+
const dir = base64Encode(sdk.directory)
6970

7071
sdk.client.session
7172
.fork({ sessionID, messageID: item.id })
@@ -75,10 +76,8 @@ export const DialogFork: Component = () => {
7576
return
7677
}
7778
dialog.close()
78-
navigate(`/${base64Encode(sdk.directory)}/session/${forked.data.id}`)
79-
requestAnimationFrame(() => {
80-
prompt.set(restored)
81-
})
79+
prompt.set(restored, undefined, { dir, id: forked.data.id })
80+
navigate(`/${dir}/session/${forked.data.id}`)
8281
})
8382
.catch((err: unknown) => {
8483
const message = err instanceof Error ? err.message : String(err)

packages/app/src/context/prompt.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ const MAX_PROMPT_SESSIONS = 20
151151

152152
type PromptSession = ReturnType<typeof createPromptSession>
153153

154+
type Scope = {
155+
dir: string
156+
id?: string
157+
}
158+
154159
type PromptCacheEntry = {
155160
value: PromptSession
156161
dispose: VoidFunction
@@ -265,6 +270,7 @@ export const { use: usePrompt, provider: PromptProvider } = createSimpleContext(
265270
}
266271

267272
const session = createMemo(() => load(params.dir!, params.id))
273+
const pick = (scope?: Scope) => (scope ? load(scope.dir, scope.id) : session())
268274

269275
return {
270276
ready: () => session().ready(),
@@ -280,8 +286,8 @@ export const { use: usePrompt, provider: PromptProvider } = createSimpleContext(
280286
session().context.updateComment(path, commentID, next),
281287
replaceComments: (items: FileContextItem[]) => session().context.replaceComments(items),
282288
},
283-
set: (prompt: Prompt, cursorPosition?: number) => session().set(prompt, cursorPosition),
284-
reset: () => session().reset(),
289+
set: (prompt: Prompt, cursorPosition?: number, scope?: Scope) => pick(scope).set(prompt, cursorPosition),
290+
reset: (scope?: Scope) => pick(scope).reset(),
285291
}
286292
},
287293
})

packages/app/src/pages/session.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,7 @@ export default function Page() {
14771477

14781478
const fork = (input: { sessionID: string; messageID: string }) => {
14791479
const value = draft(input.messageID)
1480+
const dir = base64Encode(sdk.directory)
14801481
return sdk.client.session
14811482
.fork(input)
14821483
.then((result) => {
@@ -1488,10 +1489,8 @@ export default function Page() {
14881489
})
14891490
return
14901491
}
1491-
navigate(`/${base64Encode(sdk.directory)}/session/${next.id}`)
1492-
requestAnimationFrame(() => {
1493-
prompt.set(value)
1494-
})
1492+
prompt.set(value, undefined, { dir, id: next.id })
1493+
navigate(`/${dir}/session/${next.id}`)
14951494
})
14961495
.catch(fail)
14971496
}

0 commit comments

Comments
 (0)