Open History to see the last commit
1import {
2 composerTargetKey,
3 type ComposerThreadTarget,
4 useComposerDraftStore,
5} from "../../composerDraftStore";
6import {
7 type ComposerContextReference,
8 ensureInlineContextReferences,
9} from "../../lib/composerContextReferences";
10
11/** Route references that finish preparing asynchronously to the draft that accepted them. */
12export function insertAttachmentReferencesForDraft(input: {
13 target: ComposerThreadTarget;
14 liveAttachmentTargetKey: string;
15 references: ReadonlyArray<ComposerContextReference>;
16 insertReferences: () => boolean;
17}): boolean {
18 if (composerTargetKey(input.target) !== input.liveAttachmentTargetKey) {
19 // The shared editor and prompt ref now belong to another draft or question.
20 const store = useComposerDraftStore.getState();
21 const prompt = store.getComposerDraft(input.target)?.prompt ?? "";
22 store.setPrompt(input.target, ensureInlineContextReferences(prompt, input.references));
23 return true;
24 }
25 return input.insertReferences();
26}