| 1 | import type { ComposerDraft } from "./Composer"; |
| 2 | import type { PersistentComposerDraft } from "../lib/composerDraftTypes"; |
| 3 | |
| 4 | export function emptyComposerDraft(): ComposerDraft { |
| 5 | return { |
| 6 | text: "", |
| 7 | invocations: [], |
| 8 | attachments: [], |
| 9 | workspaceRefs: [], |
| 10 | pastedBlocks: [], |
| 11 | openPastedLabels: [], |
| 12 | sessionRefs: [], |
| 13 | selectedTextRefs: [], |
| 14 | attachmentDedupKeys: {}, |
| 15 | nextPasteId: 1, |
| 16 | historyIndex: -1, |
| 17 | savedText: "", |
| 18 | pendingGuidance: [], |
| 19 | guidanceExpanded: false, |
| 20 | guidanceSendingId: null, |
| 21 | pendingPaste: 0, |
| 22 | submitting: false, |
| 23 | }; |
| 24 | } |
| 25 | export function persistentComposerDraft(value: PersistentComposerDraft): ComposerDraft { |
| 26 | return { |
| 27 | ...emptyComposerDraft(), |
| 28 | text: value.text ?? "", |
| 29 | invocations: value.invocations ?? [], |
| 30 | attachments: value.attachments ?? [], |
| 31 | workspaceRefs: value.workspaceRefs ?? [], |
| 32 | pastedBlocks: value.pastedBlocks ?? [], |
| 33 | openPastedLabels: value.openPastedLabels ?? [], |
| 34 | sessionRefs: value.sessionRefs ?? [], |
| 35 | selectedTextRefs: value.selectedTextRefs ?? [], |
| 36 | }; |
| 37 | } |
| 38 | |
| 39 | export function persistentSnapshot(draft: ComposerDraft): PersistentComposerDraft { |
| 40 | return { |
| 41 | text: draft.text, |
| 42 | invocations: draft.invocations, |
| 43 | attachments: draft.attachments, |
| 44 | workspaceRefs: draft.workspaceRefs, |
| 45 | pastedBlocks: draft.pastedBlocks, |
| 46 | openPastedLabels: draft.openPastedLabels, |
| 47 | sessionRefs: draft.sessionRefs, |
| 48 | selectedTextRefs: draft.selectedTextRefs, |
| 49 | }; |
| 50 | } |
| 51 | |
| 52 | export function composerDraftFingerprint(draft: ComposerDraft): string { |
| 53 | return JSON.stringify([draft.text, draft.invocations, draft.attachments, draft.workspaceRefs, |
| 54 | draft.sessionRefs, draft.selectedTextRefs, draft.pastedBlocks]); |
| 55 | } |
| 56 |