MCPcopy Index your code
hub / github.com/xintaofei/codeg / loadMessageInputDraftV2

Function loadMessageInputDraftV2

src/lib/message-input-draft.ts:197–221  ·  view source on GitHub ↗
(draftKey: string)

Source from the content-addressed store, hash-verified

195 * so an unedited migration is never lost.
196 */
197export function loadMessageInputDraftV2(draftKey: string): LoadedDraftV2 {
198 const cached = draftDocCache.get(draftKey)
199 if (cached) return { kind: "doc", doc: cached }
200
201 if (typeof window !== "undefined") {
202 try {
203 const raw = localStorage.getItem(storageKeyForDraftKeyV2(draftKey))
204 if (raw) {
205 const parsed = JSON.parse(raw) as Partial<PersistedDraftStateV2>
206 if (isTiptapDoc(parsed?.doc)) {
207 draftDocCache.set(draftKey, parsed.doc)
208 return { kind: "doc", doc: parsed.doc }
209 }
210 }
211 } catch {
212 // Fall through to the legacy v1 draft.
213 }
214 }
215
216 const legacy = loadMessageInputDraft(draftKey)
217 if (legacy != null && legacy.length > 0) {
218 return { kind: "legacyMarkdown", markdown: legacy }
219 }
220 return null
221}
222
223/**
224 * Persist the composer document for a key (v2). The host calls this only for a

Callers 2

MessageInputFunction · 0.90

Calls 3

storageKeyForDraftKeyV2Function · 0.85
isTiptapDocFunction · 0.85
loadMessageInputDraftFunction · 0.85

Tested by

no test coverage detected