{"version":3,"file":"composerStore.mjs","names":[],"sources":["../../../src/web/stores/composerStore.ts"],"sourcesContent":["import {\n  contextFields,\n  isCaptureShape,\n  decodeCanonicalBase64,\n  validCaptureDimensions,\n  MAX_COMPOSER_IMAGE_BYTES,\n  MAX_COMPOSER_TEXT_BYTES,\n} from '../lib/composerCapture';\nexport { validateComposerCapture, MAX_COMPOSER_IMAGE_BYTES, MAX_COMPOSER_TEXT_BYTES } from '../lib/composerCapture';\nimport type { ComposerCapture, TransientTab, WebPluginContextItem } from '@agimon-ai/po-core/web';\nimport { useStore } from '@tanstack/react-store';\nimport { Store } from '@tanstack/store';\n\nimport { traceStore } from '../lib/uiTrace';\n\nexport interface ComposerImageAttachment {\n  id: string;\n  kind: 'image';\n  name: string;\n  size: number;\n  dataUrl: string;\n  data: string;\n  mimeType: string;\n  /** Where the host stored a copy, when the best-effort upload succeeded. */\n  path?: string;\n}\n\nexport interface ComposerTextAttachment {\n  id: string;\n  kind: 'text';\n  name: string;\n  size: number;\n  content: string;\n  /** Where the host stored a copy, when the best-effort upload succeeded. */\n  path?: string;\n}\n\n/** Any other file: stored on the host and referenced by path, never inlined. */\nexport interface ComposerFileAttachment {\n  id: string;\n  kind: 'file';\n  name: string;\n  size: number;\n  mimeType: string;\n  path: string;\n}\n\nexport interface ComposerContextAttachment {\n  id: string;\n  kind: 'context';\n  name: string;\n  size: number;\n  content: string;\n  source: string;\n  contextId: string;\n  contextKind: string;\n  url?: string;\n}\n\nexport type ComposerAttachment =\n  | ComposerContextAttachment\n  | ComposerFileAttachment\n  | ComposerImageAttachment\n  | ComposerTextAttachment;\n\nexport const MAX_COMPOSER_ATTACHMENTS = 8;\nexport const MAX_COMPOSER_TOTAL_IMAGE_BYTES = 20 * 1024 * 1024;\nexport const MAX_COMPOSER_TOTAL_TEXT_BYTES = 200 * 1024;\n/** The host's upload limit for one stored attachment. */\nexport const MAX_COMPOSER_UPLOAD_BYTES = 8 * 1024 * 1024;\n\n/** Bytes counted against the inline text budget: stored files and images travel separately. */\nexport function inlineTextBytes(attachments: ComposerAttachment[]): number {\n  return attachments.reduce(\n    (total, attachment) => total + (attachment.kind === 'text' || attachment.kind === 'context' ? attachment.size : 0),\n    0,\n  );\n}\n\nexport interface ComposerSessionState {\n  draft: string;\n  caret: number;\n  dismissedToken: number | null;\n  attachments: ComposerAttachment[];\n  attachmentError: string;\n  nextAttachmentId: number;\n  /** File batches still being read or uploaded; sending waits until they are staged. */\n  pendingAttachments: number;\n}\n\ntype ComposerState = Partial<Record<string, ComposerSessionState>>;\n\nconst EMPTY_COMPOSER_SESSION: ComposerSessionState = {\n  draft: '',\n  caret: 0,\n  dismissedToken: null,\n  attachments: [],\n  attachmentError: '',\n  nextAttachmentId: 0,\n  pendingAttachments: 0,\n};\n\n/** Browser-only composer state, retained independently for each live session. */\nexport const composerStore = traceStore('composer', new Store<ComposerState>({}));\n\nfunction composerStateOf(state: ComposerState, sessionId: string | null): ComposerSessionState {\n  return (sessionId === null ? undefined : state[sessionId]) ?? EMPTY_COMPOSER_SESSION;\n}\n\nexport function useComposerState(sessionId: string | null): ComposerSessionState {\n  return useStore(composerStore, (state) => composerStateOf(state, sessionId));\n}\n\nexport function updateComposerState(\n  sessionId: string | null,\n  update: (state: ComposerSessionState) => ComposerSessionState,\n): void {\n  if (sessionId === null) return;\n  composerStore.setState((state) => ({ ...state, [sessionId]: update(composerStateOf(state, sessionId)) }));\n}\n\n/** Appends non-empty text to the latest draft for one session. */\nexport function appendComposerDraft(sessionId: string | null, text: string): void {\n  const transcript = text.trim();\n  if (sessionId === null || transcript === '') return;\n  updateComposerState(sessionId, (state) => {\n    const separator = state.draft === '' || /\\s$/.test(state.draft) ? '' : ' ';\n    const draft = `${state.draft}${separator}${transcript}`;\n    return { ...state, draft, caret: draft.length, dismissedToken: null };\n  });\n}\n\n/** Empties one session's draft and returns what it held. */\nexport function takeComposerDraft(sessionId: string | null): string {\n  if (sessionId === null) return '';\n  const { draft } = composerStateOf(composerStore.state, sessionId);\n  if (draft !== '')\n    updateComposerState(sessionId, (state) => ({ ...state, draft: '', caret: 0, dismissedToken: null }));\n  return draft;\n}\n\n/** The open tab's context for one message. Slash commands, invalid items and failing reads send without it. */\nexport function tabComposerContext(\n  read: TransientTab['composerContext'],\n  sessionId: string,\n  draft: string,\n): WebPluginContextItem | undefined {\n  // A slash command is an action: appended text would become its arguments (builtinCommandFrame).\n  if (read === undefined || draft.trim().startsWith('/')) return undefined;\n  let item: WebPluginContextItem | undefined;\n  try {\n    item = read(sessionId);\n  } catch {\n    return undefined; // Documented fallback: a plugin bug must not block the user's message.\n  }\n  if (item === undefined) return undefined;\n  const { name, content, valid } = contextFields(item);\n  if (!valid || new TextEncoder().encode(content).byteLength > MAX_COMPOSER_TEXT_BYTES) return undefined;\n  return { ...item, label: name, content };\n}\n\n/** Adds structured plugin context without changing the visible composer draft. */\nexport function attachComposerContext(sessionId: string | null, item: WebPluginContextItem): void {\n  if (sessionId === null) return;\n  const { name, content, valid } = contextFields(item);\n  updateComposerState(sessionId, (state) => {\n    if (!valid) {\n      return { ...state, attachmentError: 'Context needs a source, id, label, and content.' };\n    }\n    if (state.attachments.length >= MAX_COMPOSER_ATTACHMENTS) {\n      return { ...state, attachmentError: `Only ${String(MAX_COMPOSER_ATTACHMENTS)} attachments are allowed.` };\n    }\n    const size = new TextEncoder().encode(content).byteLength;\n    if (size > MAX_COMPOSER_TEXT_BYTES) {\n      return { ...state, attachmentError: `${name} exceeds the 100 KB context limit.` };\n    }\n    const textBytes = inlineTextBytes(state.attachments);\n    if (textBytes + size > MAX_COMPOSER_TOTAL_TEXT_BYTES) {\n      return { ...state, attachmentError: `${name} exceeds the 200 KB total text limit.` };\n    }\n    return {\n      ...state,\n      attachments: [\n        ...state.attachments,\n        {\n          id: `context-${String(state.nextAttachmentId)}`,\n          kind: 'context',\n          name,\n          size,\n          content,\n          source: item.source,\n          contextId: item.id,\n          contextKind: item.kind,\n          ...(item.url === undefined ? {} : { url: item.url }),\n        },\n      ],\n      attachmentError: '',\n      nextAttachmentId: state.nextAttachmentId + 1,\n    };\n  });\n}\n\n/**\n * Stages a capture as one image and one context chip in a single store update.\n * Nothing is transported until the reader explicitly submits or queues it.\n */\nexport function attachComposerCapture(sessionId: string | null, capture: ComposerCapture): void {\n  if (sessionId === null) return;\n  updateComposerState(sessionId, (state) => {\n    if (!isCaptureShape(capture)) {\n      return { ...state, attachmentError: 'Capture needs a base64 PNG or JPEG image and valid context.' };\n    }\n    const { name, content, valid } = contextFields(capture.context);\n    if (!valid) {\n      return { ...state, attachmentError: 'Capture needs a base64 PNG or JPEG image and valid context.' };\n    }\n    if (capture.data.length > Math.ceil(MAX_COMPOSER_IMAGE_BYTES / 3) * 4) {\n      return { ...state, attachmentError: `${name} exceeds the 10 MB image limit.` };\n    }\n    const decodedImage = decodeCanonicalBase64(capture.data);\n    if (decodedImage === null || !validCaptureDimensions(decodedImage, capture.mimeType)) {\n      return { ...state, attachmentError: 'Capture needs a base64 PNG or JPEG image and valid context.' };\n    }\n    const imageSize = decodedImage.length;\n    if (state.attachments.length > MAX_COMPOSER_ATTACHMENTS - 2) {\n      return { ...state, attachmentError: `Only ${String(MAX_COMPOSER_ATTACHMENTS)} attachments are allowed.` };\n    }\n    if (imageSize > MAX_COMPOSER_IMAGE_BYTES) {\n      return { ...state, attachmentError: `${name} exceeds the 10 MB image limit.` };\n    }\n    const imageBytes = state.attachments.reduce(\n      (total, attachment) => total + (attachment.kind === 'image' ? attachment.size : 0),\n      0,\n    );\n    if (imageBytes + imageSize > MAX_COMPOSER_TOTAL_IMAGE_BYTES) {\n      return { ...state, attachmentError: `${name} exceeds the 20 MB total image limit.` };\n    }\n    const contextSize = new TextEncoder().encode(content).byteLength;\n    if (contextSize > MAX_COMPOSER_TEXT_BYTES) {\n      return { ...state, attachmentError: `${name} exceeds the 100 KB context limit.` };\n    }\n    const textBytes = inlineTextBytes(state.attachments);\n    if (textBytes + contextSize > MAX_COMPOSER_TOTAL_TEXT_BYTES) {\n      return { ...state, attachmentError: `${name} exceeds the 200 KB total text limit.` };\n    }\n\n    const imageId = state.nextAttachmentId;\n    const extension = capture.mimeType === 'image/png' ? 'png' : 'jpg';\n    return {\n      ...state,\n      attachments: [\n        ...state.attachments,\n        {\n          id: `capture-${String(imageId)}`,\n          kind: 'image',\n          name: `${name}.${extension}`,\n          size: imageSize,\n          dataUrl: `data:${capture.mimeType};base64,${capture.data}`,\n          data: capture.data,\n          mimeType: capture.mimeType,\n        },\n        {\n          id: `context-${String(imageId + 1)}`,\n          kind: 'context',\n          name,\n          size: contextSize,\n          content,\n          source: capture.context.source,\n          contextId: capture.context.id,\n          contextKind: capture.context.kind,\n          ...(capture.context.url === undefined ? {} : { url: capture.context.url }),\n        },\n      ],\n      attachmentError: '',\n      nextAttachmentId: imageId + 2,\n    };\n  });\n}\n/** Adds message text as a Markdown blockquote and leaves the caret ready for an instruction. */\nexport function appendComposerQuote(sessionId: string | null, text: string): number | null {\n  const transcript = text.trim().replace(/\\r\\n?/g, '\\n');\n  if (sessionId === null || transcript === '') return null;\n  let caret = 0;\n  updateComposerState(sessionId, (state) => {\n    const separator =\n      state.draft === '' ? '' : state.draft.endsWith('\\n\\n') ? '' : state.draft.endsWith('\\n') ? '\\n' : '\\n\\n';\n    const quote = transcript\n      .split('\\n')\n      .map((line) => (line === '' ? '>' : `> ${line}`))\n      .join('\\n');\n    const draft = `${state.draft}${separator}${quote}\\n\\n`;\n    caret = draft.length;\n    return { ...state, draft, caret, dismissedToken: null };\n  });\n  return caret;\n}\n\n/** Empties the composer but keeps the id counter and pending batches, so a batch still uploading lands with a fresh id. */\nexport function clearComposerState(sessionId: string | null): void {\n  if (sessionId === null) return;\n  updateComposerState(sessionId, ({ nextAttachmentId, pendingAttachments }) => ({\n    ...EMPTY_COMPOSER_SESSION,\n    nextAttachmentId,\n    pendingAttachments,\n  }));\n}\n\n/** A session that left takes its unfinished composer state with it. */\nexport function dropComposerState(sessionId: string): void {\n  composerStore.setState((state) => {\n    if (!(sessionId in state)) return state;\n    const next = { ...state };\n    delete next[sessionId];\n    return next;\n  });\n}\n\nconst DRAFT_STORAGE_KEY = 'po:composer-drafts';\n\ninterface StoredDraft {\n  draft: string;\n  caret: number;\n}\n\n/**\n * Holds unsent text across a reload the person did not ask for.\n *\n * A verified bundle update reloads the page underneath whoever is typing, so\n * the text has to outlive the document. Only the draft and the caret travel:\n * attachments carry base64 image payloads that would not fit a storage quota,\n * and re-attaching a file is a smaller loss than losing a written message.\n */\nexport function saveComposerDrafts(): void {\n  try {\n    const drafts: Record<string, StoredDraft> = {};\n    for (const [sessionId, state] of Object.entries(composerStore.state)) {\n      if (state !== undefined && state.draft !== '') drafts[sessionId] = { draft: state.draft, caret: state.caret };\n    }\n    if (Object.keys(drafts).length === 0) window.sessionStorage.removeItem(DRAFT_STORAGE_KEY);\n    else window.sessionStorage.setItem(DRAFT_STORAGE_KEY, JSON.stringify(drafts));\n  } catch {\n    // Losing a draft is not worth breaking the reload that was already decided.\n  }\n}\n\n/** Seeds the store from the last save, then forgets it so a later reload starts clean. */\nexport function restoreComposerDrafts(): void {\n  let stored: unknown;\n  try {\n    const raw = window.sessionStorage.getItem(DRAFT_STORAGE_KEY);\n    window.sessionStorage.removeItem(DRAFT_STORAGE_KEY);\n    if (raw === null) return;\n    stored = JSON.parse(raw);\n  } catch {\n    return;\n  }\n  if (typeof stored !== 'object' || stored === null || Array.isArray(stored)) return;\n  for (const [sessionId, value] of Object.entries(stored as Record<string, unknown>)) {\n    if (typeof value !== 'object' || value === null) continue;\n    const entry = value as Record<string, unknown>;\n    if (typeof entry.draft !== 'string' || entry.draft === '' || !Number.isSafeInteger(entry.caret)) continue;\n    const caret = Math.max(0, Math.min(Number(entry.caret), entry.draft.length));\n    updateComposerState(sessionId, (state) => ({ ...state, draft: entry.draft as string, caret }));\n  }\n}\n\n/** Test seam. */\nexport function resetComposerStore(): void {\n  composerStore.setState(() => ({}));\n}\n"],"mappings":";;;;;AAiEA,MAAa,2BAA2B;AACxC,MAA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