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
11export function insertAttachmentReferencesForDraft(input: {
12 target: ComposerThreadTarget;
13 liveAttachmentTargetKey: string;
14 references: ReadonlyArray<ComposerContextReference>;
15 insertReferences: () => boolean;
16}): boolean {
17 if (composerTargetKey(input.target) !== input.liveAttachmentTargetKey) {
18 // The shared editor now belongs to another draft or question.
19 const store = useComposerDraftStore.getState();
20 const prompt = store.getComposerDraft(input.target)?.prompt ?? "";
21 store.setPrompt(input.target, ensureInlineContextReferences(prompt, input.references));
22 return true;
23 }
24 return input.insertReferences();
25}