@opengeni/react 6.1.0-canary.2 → 6.1.0-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/{browser-viewer-NTD6UIPR.js → browser-viewer-LGH4IP47.js} +3 -3
- package/dist/chunk-AWEBVNVX.js +1398 -0
- package/dist/chunk-AWEBVNVX.js.map +1 -0
- package/dist/{chunk-NYESIADM.js → chunk-B7TTSUEW.js} +3 -1
- package/dist/chunk-B7TTSUEW.js.map +1 -0
- package/dist/{chunk-UWVY3OXF.js → chunk-BC7BFCMN.js} +277 -455
- package/dist/chunk-BC7BFCMN.js.map +1 -0
- package/dist/chunk-BRM6FVZA.js +302 -0
- package/dist/chunk-BRM6FVZA.js.map +1 -0
- package/dist/{chunk-KZ4QDBGM.js → chunk-GHSSI2BK.js} +925 -1265
- package/dist/chunk-GHSSI2BK.js.map +1 -0
- package/dist/{chunk-NLTS7JHI.js → chunk-JPHDWKZE.js} +5 -5
- package/dist/{chunk-L5VJYZIW.js → chunk-O53CQZ6T.js} +7 -7
- package/dist/{chunk-24M4YBCL.js → chunk-PNAVEK2U.js} +4 -4
- package/dist/components/preview-loading.d.ts +2 -0
- package/dist/composer.js +4 -4
- package/dist/connect-setup.d.ts +2 -0
- package/dist/connect.js +19 -8
- package/dist/connect.js.map +1 -1
- package/dist/index.js +27 -27
- package/dist/interaction.js +2 -2
- package/dist/machines.js +2 -2
- package/dist/plugin-discovery.d.ts +2 -0
- package/dist/realtime.js +20 -20
- package/dist/realtime.js.map +1 -1
- package/dist/session-ui.js +7 -7
- package/dist/session.js +3 -3
- package/package.json +3 -3
- package/src/components/markdown.tsx +13 -21
- package/src/components/preview-loading.tsx +154 -0
- package/src/connect-setup.tsx +17 -5
- package/src/hooks/use-composer.ts +6 -0
- package/src/plugin-discovery.tsx +10 -6
- package/src/realtime/realtime-control.tsx +6 -8
- package/styles/compiled.css +48 -8
- package/styles/index.css +45 -0
- package/dist/chunk-G5JFM6ZE.js +0 -911
- package/dist/chunk-G5JFM6ZE.js.map +0 -1
- package/dist/chunk-HQV2I5HV.js +0 -124
- package/dist/chunk-HQV2I5HV.js.map +0 -1
- package/dist/chunk-KZ4QDBGM.js.map +0 -1
- package/dist/chunk-NYESIADM.js.map +0 -1
- package/dist/chunk-UWVY3OXF.js.map +0 -1
- /package/dist/{browser-viewer-NTD6UIPR.js.map → browser-viewer-LGH4IP47.js.map} +0 -0
- /package/dist/{chunk-NLTS7JHI.js.map → chunk-JPHDWKZE.js.map} +0 -0
- /package/dist/{chunk-L5VJYZIW.js.map → chunk-O53CQZ6T.js.map} +0 -0
- /package/dist/{chunk-24M4YBCL.js.map → chunk-PNAVEK2U.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-composer.ts"],"sourcesContent":["import {\n DEFAULT_FILE_RESOURCE_MOUNT_ROOT,\n type ComposerDraft,\n type DraftTimelineAnnotation,\n type EffectiveControlResumeOption,\n type EffectiveSessionControl,\n type LatencyMode,\n type OpenGeniApiError,\n type ReasoningEffort,\n type ResourceRef,\n type SaveComposerDraftRequest,\n type SendMessageInput,\n type SessionEvent,\n type SubmitComposerDraftResponse,\n} from \"@opengeni/sdk\";\nimport { useCallback, useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport { useEmbeddedSession, type EmbeddedSessionClientOverride } from \"../session-context\";\nimport { useSessionEventTrigger, type SessionEventFeedOptions } from \"./internal\";\n\nexport type ComposerPolicy = {\n model: string;\n reasoningEffort: ReasoningEffort;\n latencyMode: LatencyMode;\n};\n\nexport type ComposerSendExtras = Omit<\n SendMessageInput,\n \"text\" | \"clientEventId\" | \"annotations\" | \"model\" | \"reasoningEffort\" | \"latencyMode\"\n>;\n\nexport type UseComposerOptions = EmbeddedSessionClientOverride &\n SessionEventFeedOptions & {\n /** Called synchronously after an ordinary Send is accepted by the local UI. */\n onSubmitted?: ((text: string, input: SendMessageInput) => void) | undefined;\n /** Called with the exact accepted wire input after a successful send. */\n onSent?: ((text: string, input: SendMessageInput) => void) | undefined;\n /** Called with the exact wire input after a delivery failure. */\n onDeliveryError?:\n | ((error: Error, input: SendMessageInput, delivery: \"send\" | \"steer\") => void)\n | undefined;\n /**\n * Non-policy message fields merged into every send. Durable policy belongs\n * to this composer draft; attachments and credentials may remain host-owned.\n */\n sendExtras?: ComposerSendExtras | (() => ComposerSendExtras) | undefined;\n /**\n * Fail-closed delivery guard evaluated at send time. Attachment hosts use\n * this to preserve unresolved upload cards until the operator waits,\n * retries, or removes them; direct hook callers cannot bypass the UI gate.\n */\n sendBlocked?: (() => boolean) | undefined;\n /** Latest server-derived workstream control; bound into Send/Steer OCC. */\n effectiveControl?: EffectiveSessionControl | null | undefined;\n /** Immediate user-visible destination for an ordinary Send before admission replies. */\n sendDestination?: (() => \"chat\" | \"queue\") | undefined;\n /** Disable remote composer-draft reads and writes for embedded hosts. */\n draftPersistence?: \"durable\" | \"disabled\" | undefined;\n /** Required explicit authority when durable draft persistence is disabled. */\n initialPolicy?: ComposerPolicy | undefined;\n };\n\ntype ComposerDraftShadow = {\n text: string;\n resources: ResourceRef[];\n annotations: DraftTimelineAnnotation[];\n policy?: ComposerPolicy | undefined;\n};\n\ntype PendingComposerOperation = {\n delivery: \"send\" | \"steer\";\n input: SendMessageInput;\n draftAtSend: string;\n resourcesAtSend: ResourceRef[];\n annotationsAtSend: DraftTimelineAnnotation[];\n /** Latest local text/resources that must survive an uncertain delivery. */\n newerShadow: ComposerDraftShadow;\n clearDraftOnAccept: boolean;\n /** False after remount when the original input carried secret credentials. */\n canRetry: boolean;\n};\n\ntype StoredPendingComposerOperation = Omit<PendingComposerOperation, \"input\" | \"canRetry\"> & {\n input: Omit<SendMessageInput, \"mcpCredentialUpdates\">;\n hasMcpCredentialUpdates: boolean;\n};\n\nexport type ComposerOptimisticMessage = {\n clientEventId: string;\n delivery: \"send\" | \"steer\";\n destination: \"chat\" | \"queue\";\n text: string;\n annotations: DraftTimelineAnnotation[];\n resources: ResourceRef[];\n occurredAt: string;\n state: \"sending\" | \"queued\" | \"failed\";\n turnId?: string | null | undefined;\n triggerEventId?: string | null | undefined;\n appliedQueueVersion?: number | null | undefined;\n error?: string | undefined;\n outcomeUnknown?: boolean | undefined;\n};\n\ntype OptimisticSendOperation = ComposerOptimisticMessage & {\n input: SendMessageInput;\n draftPayload: SaveComposerDraftRequest | null;\n /** Latest unsent local draft that must survive this operation and remounts. */\n newerShadow: ComposerDraftShadow;\n canRetry: boolean;\n};\n\ntype StoredOptimisticSendOperation = Omit<OptimisticSendOperation, \"input\" | \"canRetry\"> & {\n input: Omit<SendMessageInput, \"mcpCredentialUpdates\">;\n hasMcpCredentialUpdates: boolean;\n};\n\nconst PENDING_COMPOSER_STORAGE_PREFIX = \"opengeni.pending-composer.v1:\";\nconst OPTIMISTIC_SEND_STORAGE_PREFIX = \"opengeni.optimistic-sends.v1:\";\n// A remount must not manufacture a new operation while the previous mutation\n// is still outcome-unknown. Keep only non-credential request fields here; the\n// mounted hook retains the exact input, including any credential updates. The\n// safe shadow is also session-scoped so a refresh cannot lose newer edits.\nconst pendingComposerOperations = new Map<string, StoredPendingComposerOperation>();\nconst optimisticSendOperations = new Map<string, StoredOptimisticSendOperation[]>();\n\nfunction pendingComposerOperationKey(\n workspaceId: string,\n sessionId: string | null | undefined,\n): string | null {\n return sessionId ? `${workspaceId}\\u0000${sessionId}` : null;\n}\n\nfunction pendingComposerStorage(): Storage | null {\n try {\n return typeof window === \"undefined\" ? null : window.sessionStorage;\n } catch {\n return null;\n }\n}\n\nfunction pendingComposerStorageKey(key: string): string {\n return `${PENDING_COMPOSER_STORAGE_PREFIX}${encodeURIComponent(key)}`;\n}\n\nfunction optimisticSendStorageKey(key: string): string {\n return `${OPTIMISTIC_SEND_STORAGE_PREFIX}${encodeURIComponent(key)}`;\n}\n\nfunction restoreOptimisticSendOperations(key: string | null): OptimisticSendOperation[] {\n if (!key) return [];\n let stored = optimisticSendOperations.get(key);\n if (!stored) {\n const storage = pendingComposerStorage();\n try {\n const parsed: unknown = JSON.parse(storage?.getItem(optimisticSendStorageKey(key)) ?? \"[]\");\n stored = Array.isArray(parsed)\n ? (parsed.filter(\n (candidate): candidate is StoredOptimisticSendOperation =>\n typeof candidate === \"object\" &&\n candidate !== null &&\n typeof candidate.clientEventId === \"string\" &&\n typeof candidate.text === \"string\" &&\n typeof candidate.occurredAt === \"string\" &&\n (candidate.state === \"sending\" || candidate.state === \"failed\") &&\n typeof candidate.input === \"object\" &&\n candidate.input !== null &&\n typeof candidate.input.text === \"string\" &&\n typeof candidate.hasMcpCredentialUpdates === \"boolean\",\n ) as StoredOptimisticSendOperation[])\n : [];\n } catch {\n stored = [];\n }\n }\n return stored.map(({ hasMcpCredentialUpdates, ...operation }) => ({\n ...operation,\n delivery: \"send\",\n destination: operation.destination === \"queue\" ? \"queue\" : \"chat\",\n newerShadow: operation.newerShadow ?? { text: \"\", resources: [], annotations: [] },\n state:\n operation.state === \"sending\" || operation.state === \"queued\" ? \"sending\" : operation.state,\n outcomeUnknown:\n operation.state === \"sending\" || operation.state === \"queued\"\n ? true\n : operation.outcomeUnknown,\n error:\n operation.state === \"sending\"\n ? \"Delivery was interrupted; retry to reconcile this message.\"\n : operation.error,\n input: operation.input,\n canRetry: !hasMcpCredentialUpdates,\n }));\n}\n\nfunction rememberOptimisticSendOperations(\n key: string | null,\n operations: OptimisticSendOperation[],\n): void {\n if (!key) return;\n const stored = operations\n .filter((operation) => operation.state !== \"queued\")\n .map((operation) => {\n const { canRetry: _canRetry, input, ...rest } = operation;\n const { mcpCredentialUpdates: _credentials, ...safeInput } = input;\n return {\n ...rest,\n input: safeInput,\n hasMcpCredentialUpdates: input.mcpCredentialUpdates !== undefined,\n } satisfies StoredOptimisticSendOperation;\n });\n if (stored.length === 0) {\n optimisticSendOperations.delete(key);\n try {\n pendingComposerStorage()?.removeItem(optimisticSendStorageKey(key));\n } catch {\n // Best effort; the in-memory entry is already gone.\n }\n return;\n }\n optimisticSendOperations.set(key, stored);\n try {\n pendingComposerStorage()?.setItem(optimisticSendStorageKey(key), JSON.stringify(stored));\n } catch {\n // Best effort; the in-memory queue still owns this mount.\n }\n}\n\nfunction resourceList(value: unknown): value is ResourceRef[] {\n return (\n Array.isArray(value) &&\n value.every((candidate) => {\n if (typeof candidate !== \"object\" || candidate === null) return false;\n const resource = candidate as Record<string, unknown>;\n return resource.kind === \"file\"\n ? typeof resource.fileId === \"string\"\n : resource.kind === \"repository\" &&\n typeof resource.uri === \"string\" &&\n typeof resource.ref === \"string\";\n })\n );\n}\n\nfunction timelineAnnotationList(value: unknown): value is DraftTimelineAnnotation[] {\n return (\n Array.isArray(value) &&\n value.every((candidate) => {\n if (typeof candidate !== \"object\" || candidate === null) return false;\n const annotation = candidate as Record<string, unknown>;\n const source = annotation.source;\n if (typeof source !== \"object\" || source === null) return false;\n const sourceRecord = source as Record<string, unknown>;\n return (\n typeof annotation.id === \"string\" &&\n typeof annotation.quote === \"string\" &&\n typeof annotation.note === \"string\" &&\n typeof sourceRecord.eventId === \"string\" &&\n typeof sourceRecord.eventType === \"string\" &&\n typeof sourceRecord.sequence === \"number\" &&\n (typeof sourceRecord.turnId === \"string\" || sourceRecord.turnId === null) &&\n typeof sourceRecord.startOffset === \"number\" &&\n typeof sourceRecord.endOffset === \"number\" &&\n typeof sourceRecord.contextBefore === \"string\" &&\n typeof sourceRecord.contextAfter === \"string\"\n );\n })\n );\n}\n\nfunction cloneAnnotations(\n annotations: readonly DraftTimelineAnnotation[],\n): DraftTimelineAnnotation[] {\n return annotations.map((annotation) => ({\n ...annotation,\n source: { ...annotation.source },\n }));\n}\n\nfunction readStoredPendingComposerOperation(\n key: string | null,\n): StoredPendingComposerOperation | null {\n const storage = key ? pendingComposerStorage() : null;\n if (!storage || !key) return null;\n try {\n const parsed: unknown = JSON.parse(storage.getItem(pendingComposerStorageKey(key)) ?? \"null\");\n if (typeof parsed !== \"object\" || parsed === null) return null;\n const record = parsed as Record<string, unknown>;\n const input = record.input;\n const shadow = record.newerShadow;\n if (\n typeof input !== \"object\" ||\n input === null ||\n typeof shadow !== \"object\" ||\n shadow === null\n ) {\n return null;\n }\n const inputRecord = input as Record<string, unknown>;\n const shadowRecord = shadow as Record<string, unknown>;\n if (\n (record.delivery !== \"send\" && record.delivery !== \"steer\") ||\n typeof record.draftAtSend !== \"string\" ||\n !resourceList(record.resourcesAtSend) ||\n (record.annotationsAtSend !== undefined &&\n !timelineAnnotationList(record.annotationsAtSend)) ||\n typeof shadowRecord.text !== \"string\" ||\n !resourceList(shadowRecord.resources) ||\n (shadowRecord.annotations !== undefined &&\n !timelineAnnotationList(shadowRecord.annotations)) ||\n typeof record.clearDraftOnAccept !== \"boolean\" ||\n typeof record.hasMcpCredentialUpdates !== \"boolean\" ||\n typeof inputRecord.text !== \"string\" ||\n typeof inputRecord.clientEventId !== \"string\" ||\n \"mcpCredentialUpdates\" in inputRecord ||\n (\"resources\" in inputRecord && !resourceList(inputRecord.resources)) ||\n (\"annotations\" in inputRecord && !timelineAnnotationList(inputRecord.annotations))\n ) {\n return null;\n }\n return {\n ...(record as StoredPendingComposerOperation),\n annotationsAtSend: timelineAnnotationList(record.annotationsAtSend)\n ? record.annotationsAtSend\n : [],\n newerShadow: {\n ...(shadow as ComposerDraftShadow),\n annotations: timelineAnnotationList(shadowRecord.annotations)\n ? shadowRecord.annotations\n : [],\n },\n };\n } catch {\n return null;\n }\n}\n\nfunction writePendingComposerOperation(\n key: string,\n operation: StoredPendingComposerOperation,\n): void {\n const storage = pendingComposerStorage();\n if (!storage) return;\n try {\n storage.setItem(pendingComposerStorageKey(key), JSON.stringify(operation));\n } catch {\n // Storage is best effort; the in-memory record still protects remounts.\n }\n}\n\nfunction restorePendingComposerOperation(key: string | null): PendingComposerOperation | null {\n const stored =\n (key && pendingComposerOperations.get(key)) ?? readStoredPendingComposerOperation(key);\n if (!stored) return null;\n return {\n ...stored,\n input: stored.input,\n newerShadow: stored.newerShadow ?? {\n text: stored.draftAtSend,\n resources: stored.resourcesAtSend,\n annotations: stored.annotationsAtSend,\n },\n canRetry: !stored.hasMcpCredentialUpdates,\n };\n}\n\nfunction rememberPendingComposerOperation(\n key: string | null,\n operation: PendingComposerOperation,\n): void {\n if (!key) return;\n const { canRetry: _retry, ...safeOperation } = operation;\n const { input: originalInput, ...withoutInput } = safeOperation;\n const { mcpCredentialUpdates: _storedMcp, ...safeInput } = originalInput;\n const stored = {\n ...withoutInput,\n input: safeInput,\n hasMcpCredentialUpdates: operation.input.mcpCredentialUpdates !== undefined,\n newerShadow: {\n text: operation.newerShadow.text,\n resources: [...operation.newerShadow.resources],\n annotations: cloneAnnotations(operation.newerShadow.annotations),\n ...(operation.newerShadow.policy ? { policy: { ...operation.newerShadow.policy } } : {}),\n },\n } satisfies StoredPendingComposerOperation;\n pendingComposerOperations.set(key, stored);\n writePendingComposerOperation(key, stored);\n}\n\nfunction forgetPendingComposerOperation(key: string | null): void {\n if (!key) return;\n pendingComposerOperations.delete(key);\n const storage = pendingComposerStorage();\n if (!storage) return;\n try {\n storage.removeItem(pendingComposerStorageKey(key));\n } catch {\n // Ignore a blocked storage implementation; delivery has already settled.\n }\n}\n\nfunction updatePendingComposerShadow(\n key: string | null,\n operation: PendingComposerOperation | null,\n shadow: ComposerDraftShadow,\n): PendingComposerOperation | null {\n if (!key || !operation) return operation;\n const next = {\n ...operation,\n newerShadow: {\n ...shadow,\n resources: [...shadow.resources],\n annotations: cloneAnnotations(shadow.annotations),\n },\n };\n rememberPendingComposerOperation(key, next);\n return next;\n}\n\nexport type ComposerState = {\n value: string;\n setValue: (value: string) => void;\n annotations?: DraftTimelineAnnotation[] | undefined;\n addAnnotation?: ((annotation: DraftTimelineAnnotation) => void) | undefined;\n updateAnnotation?: ((id: string, note: string) => void) | undefined;\n removeAnnotation?: ((id: string) => void) | undefined;\n /** Newly captured annotation the review surface should focus. */\n annotationReviewTargetId?: string | null | undefined;\n clearAnnotationReviewTarget?: (() => void) | undefined;\n /** Focus an annotation, or the first incomplete note when omitted. */\n requestAnnotationReview?: ((id?: string) => void) | undefined;\n /** Read the current draft synchronously before a destructive replacement. */\n hasDraftContent: () => boolean;\n /** Append the draft behind prompts already visible in the queue. */\n send: (text?: string) => Promise<boolean>;\n /** Locally acknowledged ordinary sends awaiting durable timeline reconciliation. */\n optimisticMessages?: ComposerOptimisticMessage[] | undefined;\n retryOptimisticMessage?: ((clientEventId: string) => void) | undefined;\n removeOptimisticMessage?: ((clientEventId: string) => void) | undefined;\n /** Supersede current direction with the draft. */\n steer: (text?: string) => Promise<boolean>;\n /** Optimistic-to-durable projection for a Steer that has not started yet. */\n steering?: ComposerSteeringState | null | undefined;\n /** Immediate mutation-receipt projection while physical cancellation settles. */\n stoppingAttempt?: \"current\" | \"previous\" | null | undefined;\n sending: boolean;\n canSend: boolean;\n /** Pause the session without deleting its prompt queue. */\n pause: (reason?: string) => Promise<void>;\n pausing: boolean;\n resume: (reason?: string) => Promise<void>;\n resumeScope: (option: EffectiveControlResumeOption) => Promise<void>;\n resuming: boolean;\n /** Mutation-confirmed control while the streamed queue projection catches up. */\n effectiveControl?: EffectiveSessionControl | null | undefined;\n draft: ComposerDraft | null;\n draftRevision: number;\n draftLoading: boolean;\n draftSaving: boolean;\n draftConflict: Error | null;\n /** Exact policy owned by this actor/session composer. Null while hydrating. */\n policy?: ComposerPolicy | null | undefined;\n setModel?: ((model: string) => void) | undefined;\n setReasoningEffort?: ((effort: ReasoningEffort) => void) | undefined;\n setLatencyMode?: ((mode: LatencyMode) => void) | undefined;\n /** Whether this controller owns a durable server-side draft. */\n draftPersistence?: \"durable\" | \"disabled\" | undefined;\n /** Apply an atomic queue Edit checkout without a second read. */\n applyDraft: (draft: ComposerDraft) => void;\n reloadDraft: () => Promise<void>;\n resolveDraftConflict: (choice: \"keep_mine\" | \"use_remote\") => Promise<void>;\n restoredResources: ResourceRef[];\n removeRestoredResource: (index: number) => void;\n error: Error | null;\n clearError: () => void;\n};\n\nexport type ComposerControllerState = ComposerState & {\n policy: ComposerPolicy | null;\n setModel: (model: string) => void;\n setReasoningEffort: (effort: ReasoningEffort) => void;\n setLatencyMode: (mode: LatencyMode) => void;\n};\n\nexport type ComposerSteeringState = {\n phase: \"submitting\" | \"accepted\" | \"failed\";\n text: string;\n clientEventId: string | null;\n triggerEventId: string | null;\n turnId: string | null;\n /** True only when the accepted Steer durably interrupted a live attempt. */\n stoppingPreviousAttempt?: boolean | undefined;\n error?: string | undefined;\n outcomeUnknown?: boolean | undefined;\n};\n\nconst STEERING_SETTLEMENT_EVENT_TYPES = new Set([\n \"turn.started\",\n \"turn.completed\",\n \"turn.failed\",\n \"turn.cancelled\",\n \"turn.superseded\",\n]);\n\nfunction isSteeringSettlementEvent(event: SessionEvent): boolean {\n return STEERING_SETTLEMENT_EVENT_TYPES.has(event.type);\n}\n\nfunction steeringAcceptedEvent(\n steering: ComposerSteeringState,\n events: readonly SessionEvent[],\n): SessionEvent | undefined {\n return events.find(\n (event) =>\n event.type === \"user.message\" &&\n steering.clientEventId !== null &&\n event.clientEventId === steering.clientEventId,\n );\n}\n\nfunction promptTurnIdForTrigger(\n triggerEventId: string | null | undefined,\n events: readonly SessionEvent[],\n): string | null {\n if (!triggerEventId) return null;\n const queued = events.find((event) => {\n if (event.type !== \"turn.queued\") return false;\n const payload = event.payload;\n return (\n typeof payload === \"object\" &&\n payload !== null &&\n \"triggerEventId\" in payload &&\n payload.triggerEventId === triggerEventId\n );\n });\n if (!queued) return null;\n if (queued.turnId) return queued.turnId;\n const payload = queued.payload;\n return typeof payload === \"object\" &&\n payload !== null &&\n \"turnId\" in payload &&\n typeof payload.turnId === \"string\"\n ? payload.turnId\n : null;\n}\n\nfunction steeringSettledByEvents(\n steering: ComposerSteeringState,\n events: readonly SessionEvent[],\n): boolean {\n const acceptedEventId =\n steering.triggerEventId ?? steeringAcceptedEvent(steering, events)?.id ?? null;\n return events.some((event) => {\n if (steering.turnId && event.turnId === steering.turnId && isSteeringSettlementEvent(event)) {\n return true;\n }\n if (event.type !== \"turn.started\" || !acceptedEventId) return false;\n const payload = event.payload;\n return (\n typeof payload === \"object\" &&\n payload !== null &&\n \"triggerEventId\" in payload &&\n payload.triggerEventId === acceptedEventId\n );\n });\n}\n\nfunction reconcileOptimisticSendFromEvents(\n operation: OptimisticSendOperation,\n events: readonly SessionEvent[],\n): { operation: OptimisticSendOperation; admitted: boolean; settled: boolean } {\n const accepted = events.find(\n (event) => event.type === \"user.message\" && event.clientEventId === operation.clientEventId,\n );\n const triggerEventId = operation.triggerEventId ?? accepted?.id ?? null;\n const turnId = operation.turnId ?? promptTurnIdForTrigger(triggerEventId, events);\n const acceptedRouting = promptRoutingFromAcceptedEvent(accepted ?? null);\n const destination =\n acceptedRouting === \"queued_for_execution\"\n ? \"queue\"\n : acceptedRouting === \"accepted_for_execution\" || acceptedRouting === \"accepted_for_steering\"\n ? \"chat\"\n : operation.destination;\n const needsAdmissionUpdate =\n accepted !== undefined &&\n (operation.state !== \"queued\" ||\n operation.destination !== destination ||\n operation.triggerEventId !== triggerEventId ||\n operation.turnId !== turnId ||\n operation.error !== undefined ||\n operation.outcomeUnknown !== false);\n const reconciled: OptimisticSendOperation = needsAdmissionUpdate\n ? {\n ...operation,\n state: \"queued\",\n destination,\n triggerEventId,\n turnId,\n error: undefined,\n outcomeUnknown: false,\n }\n : operation;\n const withdrawnFromQueue = events.some((event) => {\n if (event.type !== \"session.queue.changed\" || !turnId) return false;\n const payload = event.payload;\n if (typeof payload !== \"object\" || payload === null || Array.isArray(payload)) return false;\n const record = payload as Record<string, unknown>;\n return (\n record.turnId === turnId && (record.operation === \"edit\" || record.operation === \"delete\")\n );\n });\n return {\n operation: reconciled,\n admitted: accepted !== undefined,\n // Edit/Delete atomically withdraw the queued turn. Keeping its optimistic\n // send alive after that point lets its old `newerShadow` become the newest\n // composer draft again when a later turn settles, duplicating submitted\n // text. The queue mutation is the durable terminal fact for this send.\n settled:\n withdrawnFromQueue ||\n steeringSettledByEvents(\n {\n phase: \"accepted\",\n text: reconciled.text,\n clientEventId: reconciled.clientEventId,\n triggerEventId: reconciled.triggerEventId ?? null,\n turnId: reconciled.turnId ?? null,\n },\n events,\n ),\n };\n}\n\n/**\n * Draft + send + Pause/Resume state for the chat composer — the only\n * human-to-agent input surface. The draft survives a failed send (nothing is\n * more hostile than losing a typed message); each send carries a generated\n * `clientEventId` so retries stay idempotent server-side.\n */\nexport function useComposer(\n sessionId: string | null | undefined,\n options: UseComposerOptions = {},\n): ComposerControllerState {\n const { client, workspaceId, registerSessionReconciler } = useEmbeddedSession(options);\n const durableDrafts = options.draftPersistence !== \"disabled\";\n if (!durableDrafts && !options.initialPolicy) {\n throw new Error(\"useComposer requires initialPolicy when draft persistence is disabled\");\n }\n const targetKey = `${workspaceId}\\u0000${sessionId ?? \"\"}\\u0000${durableDrafts ? \"durable\" : \"disabled\"}`;\n const pendingOperationKey = pendingComposerOperationKey(workspaceId, sessionId);\n const initialPendingOperation = restorePendingComposerOperation(pendingOperationKey);\n const initialOptimisticSends = restoreOptimisticSendOperations(pendingOperationKey);\n const initialShadow =\n initialPendingOperation?.newerShadow ?? initialOptimisticSends.at(-1)?.newerShadow;\n const [value, setValue] = useState(() => initialShadow?.text ?? \"\");\n const [annotations, setAnnotations] = useState<DraftTimelineAnnotation[]>(\n () => initialShadow?.annotations ?? [],\n );\n const [annotationReviewTargetId, setAnnotationReviewTargetId] = useState<string | null>(null);\n // Keep rendered state behind the committed target identity for one frame:\n // a parent may switch sessionId without remounting this public hook.\n const [stateTargetKey, setStateTargetKey] = useState(targetKey);\n const [sending, setSending] = useState(false);\n const [optimisticSends, setOptimisticSends] =\n useState<OptimisticSendOperation[]>(initialOptimisticSends);\n const [steering, setSteering] = useState<ComposerSteeringState | null>(() =>\n initialPendingOperation?.delivery === \"steer\"\n ? {\n phase: \"failed\",\n text: initialPendingOperation.input.text,\n clientEventId: initialPendingOperation.input.clientEventId ?? null,\n triggerEventId: null,\n turnId: null,\n error: \"Not confirmed. Retry to check the same direction change.\",\n outcomeUnknown: true,\n }\n : null,\n );\n const [pausing, setPausing] = useState(false);\n const [acceptedControl, setAcceptedControl] = useState<EffectiveSessionControl | null>(null);\n const [resuming, setResuming] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n // Background draft reads recover independently of Send/Steer/control failures.\n const [draftReadError, setDraftReadError] = useState<Error | null>(null);\n const [draft, setDraft] = useState<ComposerDraft | null>(null);\n const [draftLoading, setDraftLoading] = useState(Boolean(sessionId) && durableDrafts);\n const [draftSaving, setDraftSaving] = useState(false);\n const [draftConflict, setDraftConflict] = useState<Error | null>(null);\n const [policy, setPolicy] = useState<ComposerPolicy | null>(\n () => initialShadow?.policy ?? options.initialPolicy ?? null,\n );\n const [restoredResources, setRestoredResources] = useState<ResourceRef[]>(\n () => initialShadow?.resources ?? [],\n );\n const pendingOperationRef = useRef<PendingComposerOperation | null>(initialPendingOperation);\n const optimisticSendsRef = useRef<OptimisticSendOperation[]>(initialOptimisticSends);\n const optimisticProcessorBusyRef = useRef(false);\n const optimisticCallbackIdsRef = useRef(new Set<string>());\n const steeringSettlementEventsRef = useRef<SessionEvent[]>([]);\n const steeringRef = useRef(steering);\n const steeringOccurredAtRef = useRef(new Date().toISOString());\n const pendingClientEventId = useRef<string | null>(\n initialPendingOperation?.input.clientEventId ?? null,\n );\n const valueRef = useRef(initialShadow?.text ?? \"\");\n const annotationsRef = useRef<DraftTimelineAnnotation[]>(initialShadow?.annotations ?? []);\n const policyRef = useRef<ComposerPolicy | null>(\n initialShadow?.policy ?? options.initialPolicy ?? null,\n );\n const draftRef = useRef<ComposerDraft | null>(null);\n const restoredResourcesRef = useRef<ResourceRef[]>(initialShadow?.resources ?? []);\n const localEditRevision = useRef(initialShadow ? 1 : 0);\n const targetGeneration = useRef(0);\n const draftReadGeneration = useRef(0);\n const draftReadInFlightRef = useRef<string | null>(null);\n const draftReadAbortRef = useRef<AbortController | null>(null);\n const draftReadRetryRef = useRef<{\n targetKey: string;\n failures: number;\n timer: ReturnType<typeof setTimeout> | null;\n }>({ targetKey, failures: 0, timer: null });\n const lastSavedSignature = useRef<string | null>(null);\n const saveChain = useRef<Promise<void>>(Promise.resolve());\n const onSent = options.onSent;\n const onSubmitted = options.onSubmitted;\n const onDeliveryErrorRef = useRef(options.onDeliveryError);\n onDeliveryErrorRef.current = options.onDeliveryError;\n useLayoutEffect(() => {\n steeringRef.current = steering;\n }, [steering]);\n // Read through a ref so a new extras closure (created every render by\n // callers passing inline functions) does not invalidate `send`.\n const sendExtrasRef = useRef(options.sendExtras);\n sendExtrasRef.current = options.sendExtras;\n const sendDestinationRef = useRef(options.sendDestination);\n sendDestinationRef.current = options.sendDestination;\n const sendBlockedRef = useRef(options.sendBlocked);\n sendBlockedRef.current = options.sendBlocked;\n const effectiveControlRef = useRef<EffectiveSessionControl | null>(\n acceptedControl ?? options.effectiveControl ?? null,\n );\n effectiveControlRef.current = acceptedControl ?? options.effectiveControl ?? null;\n const liveExtrasVersion = JSON.stringify(resolveSendExtras(options.sendExtras));\n\n // A composer is bound to one session: switching targets must not leak the\n // previous session's draft, error, or retry idempotency key.\n const targetKeyRef = useRef(targetKey);\n useLayoutEffect(() => {\n if (targetKeyRef.current === targetKey) return;\n if (draftReadRetryRef.current.timer !== null) {\n clearTimeout(draftReadRetryRef.current.timer);\n }\n draftReadAbortRef.current?.abort();\n draftReadAbortRef.current = null;\n draftReadRetryRef.current = { targetKey, failures: 0, timer: null };\n targetKeyRef.current = targetKey;\n targetGeneration.current += 1;\n draftReadGeneration.current += 1;\n pendingOperationRef.current = restorePendingComposerOperation(pendingOperationKey);\n const restoredOptimisticSends = restoreOptimisticSendOperations(pendingOperationKey);\n optimisticSendsRef.current = restoredOptimisticSends;\n optimisticProcessorBusyRef.current = false;\n optimisticCallbackIdsRef.current = new Set();\n steeringSettlementEventsRef.current = [];\n pendingClientEventId.current = pendingOperationRef.current?.input.clientEventId ?? null;\n const shadow =\n pendingOperationRef.current?.newerShadow ?? restoredOptimisticSends.at(-1)?.newerShadow;\n localEditRevision.current = shadow ? 1 : 0;\n valueRef.current = shadow?.text ?? \"\";\n annotationsRef.current = shadow?.annotations ?? [];\n policyRef.current = shadow?.policy ?? options.initialPolicy ?? null;\n draftRef.current = null;\n restoredResourcesRef.current = shadow?.resources ?? [];\n lastSavedSignature.current = null;\n // Old saves may still be awaiting the network. Their generation fence\n // prevents settlement, and a fresh chain avoids blocking this target.\n saveChain.current = Promise.resolve();\n setStateTargetKey(targetKey);\n setValue(shadow?.text ?? \"\");\n setAnnotations(shadow?.annotations ?? []);\n setPolicy(policyRef.current);\n setAnnotationReviewTargetId(null);\n setSending(false);\n setOptimisticSends(restoredOptimisticSends);\n setSteering(\n pendingOperationRef.current?.delivery === \"steer\"\n ? {\n phase: \"failed\",\n text: pendingOperationRef.current.input.text,\n clientEventId: pendingOperationRef.current.input.clientEventId ?? null,\n triggerEventId: null,\n turnId: null,\n error: \"Not confirmed. Retry to check the same direction change.\",\n outcomeUnknown: true,\n }\n : null,\n );\n setPausing(false);\n setAcceptedControl(null);\n setResuming(false);\n setError(null);\n setDraftReadError(null);\n setDraft(null);\n setDraftLoading(Boolean(sessionId) && durableDrafts);\n setDraftSaving(false);\n setDraftConflict(null);\n setRestoredResources(shadow?.resources ?? []);\n }, [durableDrafts, options.initialPolicy, pendingOperationKey, sessionId, targetKey]);\n useEffect(\n () => () => {\n if (draftReadRetryRef.current.timer !== null) {\n clearTimeout(draftReadRetryRef.current.timer);\n }\n targetGeneration.current += 1;\n draftReadGeneration.current += 1;\n draftReadInFlightRef.current = null;\n draftReadAbortRef.current?.abort();\n draftReadAbortRef.current = null;\n },\n [],\n );\n\n const setOptimisticDraftShadow = useCallback(\n (shadow: ComposerDraftShadow): void => {\n if (optimisticSendsRef.current.length === 0) return;\n const next = optimisticSendsRef.current.map((operation) => ({\n ...operation,\n newerShadow: {\n text: shadow.text,\n resources: [...shadow.resources],\n annotations: cloneAnnotations(shadow.annotations),\n ...(shadow.policy ? { policy: { ...shadow.policy } } : {}),\n },\n }));\n optimisticSendsRef.current = next;\n rememberOptimisticSendOperations(pendingOperationKey, next);\n setOptimisticSends(next);\n },\n [pendingOperationKey],\n );\n\n const applyDraft = useCallback(\n (next: ComposerDraft): void => {\n if (targetKeyRef.current !== targetKey) return;\n if (!durableDrafts) {\n const nextPolicy = policyFromDraft(next);\n localEditRevision.current += 1;\n valueRef.current = next.text;\n annotationsRef.current = next.annotations ?? [];\n policyRef.current = nextPolicy;\n restoredResourcesRef.current = next.resources;\n draftRef.current = null;\n lastSavedSignature.current = null;\n setDraft(null);\n setValue(next.text);\n setAnnotations(next.annotations ?? []);\n setPolicy(nextPolicy);\n setRestoredResources(next.resources);\n pendingOperationRef.current = updatePendingComposerShadow(\n pendingOperationKey,\n pendingOperationRef.current,\n {\n text: next.text,\n resources: mergeResources(\n next.resources,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: next.annotations ?? [],\n policy: nextPolicy,\n },\n );\n setOptimisticDraftShadow({\n text: next.text,\n resources: mergeResources(\n next.resources,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: next.annotations ?? [],\n policy: nextPolicy,\n });\n setDraftConflict(null);\n return;\n }\n const nextPolicy = policyFromDraft(next);\n valueRef.current = next.text;\n annotationsRef.current = next.annotations ?? [];\n policyRef.current = nextPolicy;\n draftRef.current = next;\n restoredResourcesRef.current = next.resources;\n lastSavedSignature.current = draftSignature(draftPayload(next));\n localEditRevision.current += 1;\n setDraft(next);\n setValue(next.text);\n setAnnotations(next.annotations ?? []);\n setPolicy(nextPolicy);\n setRestoredResources(next.resources);\n pendingOperationRef.current = updatePendingComposerShadow(\n pendingOperationKey,\n pendingOperationRef.current,\n {\n text: next.text,\n resources: mergeResources(\n next.resources,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: next.annotations ?? [],\n policy: nextPolicy,\n },\n );\n setOptimisticDraftShadow({\n text: next.text,\n resources: mergeResources(\n next.resources,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: next.annotations ?? [],\n policy: nextPolicy,\n });\n setDraftConflict(null);\n },\n [durableDrafts, pendingOperationKey, setOptimisticDraftShadow, targetKey],\n );\n\n const loadDraft = useCallback(\n async (replaceLocal: boolean): Promise<void> => {\n if (targetKeyRef.current !== targetKey) return;\n if (!sessionId || !durableDrafts) {\n setDraftLoading(false);\n setDraftReadError(null);\n return;\n }\n let retry = draftReadRetryRef.current;\n if (retry.targetKey !== targetKey) {\n if (retry.timer !== null) clearTimeout(retry.timer);\n retry = { targetKey, failures: 0, timer: null };\n draftReadRetryRef.current = retry;\n }\n const scheduleRetry = (): void => {\n if (retry.timer !== null) return;\n retry.timer = setTimeout(\n () => {\n if (draftReadRetryRef.current !== retry || targetKeyRef.current !== targetKey) return;\n retry.timer = null;\n void loadDraft(false);\n },\n Math.min(25_000, 1_000 * 2 ** (retry.failures - 1)) * (0.8 + Math.random() * 0.4),\n );\n };\n if (!replaceLocal && retry.timer !== null) return;\n if (draftReadInFlightRef.current === targetKey) return;\n if (retry.timer !== null) {\n clearTimeout(retry.timer);\n retry.timer = null;\n }\n draftReadInFlightRef.current = targetKey;\n const generation = targetGeneration.current;\n const readTicket = ++draftReadGeneration.current;\n const requestAbort = new AbortController();\n draftReadAbortRef.current?.abort();\n draftReadAbortRef.current = requestAbort;\n const localAtStart = localEditRevision.current;\n const baseAtStart = draftRef.current;\n const policyAtStart = policyRef.current;\n const localSignatureAtStart = baseAtStart\n ? policyAtStart\n ? draftSignature(\n composerDraftPayload(\n baseAtStart,\n valueRef.current,\n restoredResourcesRef.current,\n annotationsRef.current,\n policyAtStart,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n )\n : null\n : null;\n const localWasDirtyAtStart =\n localSignatureAtStart === null\n ? localAtStart !== 0\n : localSignatureAtStart !== lastSavedSignature.current;\n // Only blank the picker on first hydrate / hard reload. Reconcile and\n // event-triggered soft reloads (loadOlder SSE reconnect) must not flicker\n // draftLoading — stale-while-revalidate keeps the settled UI mounted.\n const showLoading = replaceLocal || draftRef.current === null;\n if (showLoading) {\n setDraftLoading(true);\n }\n try {\n const fetched = await client.getComposerDraft(workspaceId, sessionId, {\n signal: requestAbort.signal,\n });\n if (\n generation !== targetGeneration.current ||\n targetKeyRef.current !== targetKey ||\n readTicket !== draftReadGeneration.current\n ) {\n return;\n }\n if (retry.timer !== null) clearTimeout(retry.timer);\n retry.failures = 0;\n retry.timer = null;\n // Recovery also counts when the server returns the same draft revision.\n setDraftReadError(null);\n const currentRevision = draftRef.current?.revision ?? -1;\n // Reconnect and client-generation effects can legitimately ask for the\n // draft again. A same-revision response is not new authority: publishing\n // its freshly decoded object back into React creates a response -> render\n // -> read feedback loop. Hard reload remains the explicit exception.\n if (replaceLocal || fetched.revision > currentRevision) {\n draftRef.current = fetched;\n setDraft(fetched);\n setDraftConflict(null);\n const shadow =\n pendingOperationRef.current?.newerShadow ??\n optimisticSendsRef.current.at(-1)?.newerShadow;\n if (shadow) {\n // The server can only know the original operation. Never replace\n // newer local edits while that operation is still uncertain.\n valueRef.current = shadow.text;\n restoredResourcesRef.current = shadow.resources;\n annotationsRef.current = shadow.annotations;\n if (shadow.policy) policyRef.current = shadow.policy;\n localEditRevision.current ||= 1;\n setValue(shadow.text);\n setRestoredResources(shadow.resources);\n setAnnotations(shadow.annotations);\n if (shadow.policy) setPolicy(shadow.policy);\n } else if (\n replaceLocal ||\n (!localWasDirtyAtStart && localAtStart === localEditRevision.current)\n ) {\n const fetchedPolicy = policyFromDraft(fetched);\n valueRef.current = fetched.text;\n restoredResourcesRef.current = fetched.resources;\n annotationsRef.current = fetched.annotations ?? [];\n policyRef.current = fetchedPolicy;\n lastSavedSignature.current = draftSignature(draftPayload(fetched));\n setValue(fetched.text);\n setRestoredResources(fetched.resources);\n setAnnotations(fetched.annotations ?? []);\n setPolicy(fetchedPolicy);\n } else {\n // Keep the in-flight edit, but the fetched row is still the OCC\n // base. First hydrate has no local policy until this read lands;\n // without it autosave cannot persist the typed text.\n lastSavedSignature.current = draftSignature(draftPayload(fetched));\n if (!policyRef.current) {\n const fetchedPolicy = policyFromDraft(fetched);\n policyRef.current = fetchedPolicy;\n setPolicy(fetchedPolicy);\n }\n }\n }\n } catch (cause) {\n if (\n !requestAbort.signal.aborted &&\n generation === targetGeneration.current &&\n targetKeyRef.current === targetKey &&\n readTicket === draftReadGeneration.current\n ) {\n const problem = asError(cause);\n const timedOut = problem.name === \"TimeoutError\";\n setDraftReadError(\n timedOut ? new Error(\"Draft sync timed out. Retrying…\", { cause }) : problem,\n );\n if (\n timedOut ||\n cause instanceof TypeError ||\n (cause && typeof cause === \"object\" && \"retryable\" in cause && cause.retryable === true)\n ) {\n retry.failures += 1;\n scheduleRetry();\n } else {\n if (retry.timer !== null) clearTimeout(retry.timer);\n retry.failures = 0;\n retry.timer = null;\n }\n }\n } finally {\n if (\n generation === targetGeneration.current &&\n targetKeyRef.current === targetKey &&\n readTicket === draftReadGeneration.current\n ) {\n setDraftLoading(false);\n }\n if (draftReadInFlightRef.current === targetKey) {\n draftReadInFlightRef.current = null;\n }\n if (draftReadAbortRef.current === requestAbort) {\n draftReadAbortRef.current = null;\n }\n }\n },\n [client, durableDrafts, sessionId, targetKey, workspaceId],\n );\n\n useEffect(() => {\n if (!sessionId || !durableDrafts) {\n setDraftLoading(false);\n return;\n }\n void loadDraft(false);\n }, [durableDrafts, loadDraft, sessionId]);\n // After long background / sleep the in-memory revision is often stale while\n // a prior autosave already advanced the server. Soft-reload on wake so the\n // next keystroke does not OCC against a dead revision.\n useEffect(() => {\n if (!sessionId || !durableDrafts) return;\n const onWake = () => {\n if (typeof document !== \"undefined\" && document.visibilityState === \"hidden\") return;\n void loadDraft(false);\n };\n document.addEventListener(\"visibilitychange\", onWake);\n window.addEventListener(\"pageshow\", onWake);\n return () => {\n document.removeEventListener(\"visibilitychange\", onWake);\n window.removeEventListener(\"pageshow\", onWake);\n };\n }, [durableDrafts, loadDraft, sessionId]);\n useEffect(() => {\n if (!sessionId || !durableDrafts) return;\n return registerSessionReconciler(sessionId, \"composer\", async () => await loadDraft(false));\n }, [durableDrafts, loadDraft, registerSessionReconciler, sessionId]);\n const reconcileSteering = useCallback(async (): Promise<void> => {\n if (!sessionId || !steeringRef.current) return;\n const ownedTargetKey = targetKey;\n let events: SessionEvent[];\n try {\n events = await client.listEvents(workspaceId, sessionId, {\n includeTypes: [\n \"user.message\",\n \"turn.started\",\n \"turn.completed\",\n \"turn.failed\",\n \"turn.cancelled\",\n \"turn.superseded\",\n ],\n limit: 250,\n payloadMode: \"full\",\n });\n } catch {\n // Best effort: the live stream still settles steering when its event arrives.\n return;\n }\n if (targetKeyRef.current !== ownedTargetKey) return;\n setSteering((current) => {\n if (!current) return current;\n if (steeringSettledByEvents(current, events)) {\n steeringSettlementEventsRef.current = [];\n return null;\n }\n const accepted = steeringAcceptedEvent(current, events);\n if (!accepted || current.triggerEventId) return current;\n return {\n ...current,\n phase: \"accepted\",\n triggerEventId: accepted.id,\n };\n });\n }, [client, sessionId, targetKey, workspaceId]);\n useSessionEventTrigger(\n client,\n workspaceId,\n sessionId,\n (event) => isComposerDraftEvent(event) || isSteeringSettlementEvent(event),\n (event) => {\n if (isComposerDraftEvent(event)) void loadDraft(false);\n if (!isSteeringSettlementEvent(event)) return;\n steeringSettlementEventsRef.current = [\n ...steeringSettlementEventsRef.current.slice(-15),\n event,\n ];\n setSteering((current) => {\n if (!current || !steeringSettledByEvents(current, [event])) return current;\n steeringSettlementEventsRef.current = [];\n return null;\n });\n },\n {\n enabled: Boolean(sessionId) && (durableDrafts || steering !== null),\n ...(options.events !== undefined ? { events: options.events } : {}),\n },\n reconcileSteering,\n );\n\n useEffect(() => {\n if (!steering) return;\n const observed = [...(options.events ?? []), ...steeringSettlementEventsRef.current];\n if (!steeringSettledByEvents(steering, observed)) return;\n steeringSettlementEventsRef.current = [];\n setSteering(null);\n }, [options.events, steering]);\n\n useEffect(() => {\n if (!acceptedControl) return;\n const effectiveControl = options.effectiveControl;\n if (!effectiveControl || effectiveControl.controlVersion < acceptedControl.controlVersion) {\n return;\n }\n setAcceptedControl((current) => (current === acceptedControl ? null : current));\n }, [acceptedControl, options.effectiveControl]);\n\n const currentDraftPayload = useCallback((): SaveComposerDraftRequest | null => {\n if (!durableDrafts || targetKeyRef.current !== targetKey) return null;\n const base = draftRef.current;\n const currentPolicy = policyRef.current;\n if (!base || !currentPolicy) return null;\n return composerDraftPayload(\n base,\n value,\n restoredResources,\n annotations,\n currentPolicy,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n );\n }, [annotations, durableDrafts, restoredResources, targetKey, value]);\n\n const adoptDraftBase = useCallback(\n (next: ComposerDraft): void => {\n if (targetKeyRef.current !== targetKey) return;\n draftRef.current = next;\n setDraft(next);\n lastSavedSignature.current = draftSignature(draftPayload(next));\n setDraftConflict(null);\n setError(null);\n },\n [targetKey],\n );\n\n const persistPayload = useCallback(\n async (payload: SaveComposerDraftRequest): Promise<boolean> => {\n const ownedTargetKey = targetKey;\n const ownedGeneration = targetGeneration.current;\n if (!sessionId || !durableDrafts || targetKeyRef.current !== ownedTargetKey) {\n return false;\n }\n let success = false;\n const run = async () => {\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return;\n }\n const current = draftRef.current;\n if (!current) return;\n const request = { ...payload, expectedRevision: current.revision };\n const signature = draftSignature(request);\n if (signature === lastSavedSignature.current) {\n success = true;\n return;\n }\n setDraftSaving(true);\n try {\n const saved = await client.saveComposerDraft(workspaceId, sessionId, request);\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return;\n }\n adoptDraftBase(saved);\n success = true;\n } catch (cause) {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n const problem = asError(cause);\n if (isDraftConflictError(problem)) setDraftConflict(problem);\n setError(problem);\n }\n } finally {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setDraftSaving(false);\n }\n }\n };\n saveChain.current = saveChain.current.then(run, run);\n await saveChain.current;\n return success;\n },\n [adoptDraftBase, client, durableDrafts, sessionId, targetKey, workspaceId],\n );\n\n const replaceOptimisticSends = useCallback(\n (\n update: (current: OptimisticSendOperation[]) => OptimisticSendOperation[],\n ): OptimisticSendOperation[] => {\n const next = update(optimisticSendsRef.current);\n optimisticSendsRef.current = next;\n rememberOptimisticSendOperations(pendingOperationKey, next);\n setOptimisticSends(next);\n return next;\n },\n [pendingOperationKey],\n );\n\n const markOptimisticAccepted = useCallback(\n (operation: OptimisticSendOperation): void => {\n if (!optimisticCallbackIdsRef.current.has(operation.clientEventId)) {\n optimisticCallbackIdsRef.current.add(operation.clientEventId);\n onSent?.(operation.input.text, operation.input);\n }\n replaceOptimisticSends((current) =>\n current.filter((candidate) => candidate.clientEventId !== operation.clientEventId),\n );\n },\n [onSent, replaceOptimisticSends],\n );\n\n useEffect(() => {\n const events = options.events ?? [];\n if (events.length === 0 || optimisticSendsRef.current.length === 0) return;\n const reconciled = optimisticSendsRef.current.map((operation) =>\n reconcileOptimisticSendFromEvents(operation, events),\n );\n const settledIds = new Set(\n reconciled.filter((item) => item.settled).map((item) => item.operation.clientEventId),\n );\n const changed = reconciled.some(\n (item, index) =>\n item.operation !== optimisticSendsRef.current[index] &&\n !settledIds.has(item.operation.clientEventId),\n );\n for (const item of reconciled) {\n if (item.admitted && !optimisticCallbackIdsRef.current.has(item.operation.clientEventId)) {\n optimisticCallbackIdsRef.current.add(item.operation.clientEventId);\n onSent?.(item.operation.input.text, item.operation.input);\n }\n if (item.settled) markOptimisticAccepted(item.operation);\n }\n if (changed) {\n replaceOptimisticSends((current) =>\n current\n .map(\n (operation) =>\n reconciled.find((item) => item.operation.clientEventId === operation.clientEventId)\n ?.operation ?? operation,\n )\n .filter((operation) => !settledIds.has(operation.clientEventId)),\n );\n }\n if (durableDrafts && reconciled.some((item) => item.admitted)) void loadDraft(false);\n }, [\n durableDrafts,\n loadDraft,\n markOptimisticAccepted,\n onSent,\n options.events,\n replaceOptimisticSends,\n ]);\n\n const processOptimisticSends = useCallback((): void => {\n if (!sessionId || optimisticProcessorBusyRef.current) return;\n const currentOperations = optimisticSendsRef.current;\n const operationIndex = currentOperations.findIndex(\n (candidate) => candidate.state === \"sending\",\n );\n const operation = operationIndex < 0 ? undefined : currentOperations[operationIndex];\n if (!operation) return;\n const ownedTargetKey = targetKey;\n const ownedGeneration = targetGeneration.current;\n optimisticProcessorBusyRef.current = true;\n void (async () => {\n let mutationFailureObserved = false;\n const markFailed = (problem: Error, outcomeUnknown: boolean): void => {\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return;\n }\n replaceOptimisticSends((current) =>\n current.map((candidate) =>\n candidate.clientEventId === operation.clientEventId\n ? {\n ...candidate,\n state: \"failed\",\n error: problem.message,\n outcomeUnknown,\n }\n : candidate,\n ),\n );\n };\n try {\n if (operation.outcomeUnknown) {\n let events: SessionEvent[];\n try {\n events = await client.listEvents(workspaceId, sessionId, {\n includeTypes: [\n \"user.message\",\n \"turn.queued\",\n \"turn.started\",\n \"turn.completed\",\n \"turn.failed\",\n \"turn.cancelled\",\n \"turn.superseded\",\n ],\n limit: 250,\n payloadMode: \"full\",\n });\n } catch (cause) {\n // This read cannot settle the prior mutation in either direction.\n // Preserve its exact key and uncertain status until reconciliation\n // succeeds or that same mutation is actually replayed.\n markFailed(asError(cause), true);\n return;\n }\n const reconciled = reconcileOptimisticSendFromEvents(operation, events);\n if (reconciled.admitted) {\n if (durableDrafts) await loadDraft(false);\n if (reconciled.settled) {\n markOptimisticAccepted(reconciled.operation);\n } else {\n replaceOptimisticSends((current) =>\n current.map((candidate) =>\n candidate.clientEventId === operation.clientEventId\n ? reconciled.operation\n : candidate,\n ),\n );\n if (!optimisticCallbackIdsRef.current.has(operation.clientEventId)) {\n optimisticCallbackIdsRef.current.add(operation.clientEventId);\n onSent?.(reconciled.operation.input.text, reconciled.operation.input);\n }\n }\n return;\n }\n if (!operation.canRetry) {\n throw new Error(\n \"OpenGeni cannot safely retry this uncertain request after remount; reconcile the session before sending again.\",\n );\n }\n }\n let expectedDraftRevision: number | undefined;\n if (durableDrafts && operation.draftPayload) {\n if (!(await persistPayload(operation.draftPayload))) {\n throw new Error(\"The message draft could not be saved before delivery.\");\n }\n expectedDraftRevision = draftRef.current?.revision;\n }\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return;\n }\n const wireInput = {\n ...operation.input,\n ...(expectedDraftRevision !== undefined ? { expectedDraftRevision } : {}),\n };\n let acceptedResult: SubmitComposerDraftResponse | null = null;\n let acceptedEvent: SessionEvent | null = null;\n if (durableDrafts) {\n if (!operation.draftPayload || expectedDraftRevision === undefined) {\n throw new Error(\"The durable composer draft is not ready for delivery.\");\n }\n const result = await client\n .submitComposerDraft(workspaceId, sessionId, {\n text: operation.draftPayload.text,\n annotations: operation.draftPayload.annotations,\n resources: operation.draftPayload.resources,\n model: operation.draftPayload.model,\n reasoningEffort: operation.draftPayload.reasoningEffort,\n latencyMode: operation.draftPayload.latencyMode,\n expectedDraftRevision,\n clientEventId: operation.clientEventId,\n delivery: \"send\",\n ...(wireInput.controlEtag ? { controlEtag: wireInput.controlEtag } : {}),\n ...(wireInput.modelContext ? { modelContext: wireInput.modelContext } : {}),\n ...(wireInput.mcpCredentialUpdates\n ? { mcpCredentialUpdates: wireInput.mcpCredentialUpdates }\n : {}),\n ...(wireInput.connectionAuthorities\n ? { connectionAuthorities: wireInput.connectionAuthorities }\n : {}),\n ...(wireInput.personalResourceAttachment\n ? { personalResourceAttachment: wireInput.personalResourceAttachment }\n : {}),\n })\n .catch((cause: unknown) => {\n mutationFailureObserved = true;\n throw cause;\n });\n acceptedResult = result;\n adoptDraftBase(result.draft);\n } else {\n acceptedEvent = await client\n .sendMessage(workspaceId, sessionId, wireInput)\n .catch((cause: unknown) => {\n mutationFailureObserved = true;\n throw cause;\n });\n }\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return;\n }\n const acceptedRouting =\n acceptedResult?.routing ?? promptRoutingFromAcceptedEvent(acceptedEvent);\n const acceptedDestination =\n acceptedRouting === \"queued_for_execution\"\n ? \"queue\"\n : acceptedRouting === \"accepted_for_execution\" ||\n acceptedRouting === \"accepted_for_steering\"\n ? \"chat\"\n : operation.destination;\n if (options.events === undefined && acceptedDestination === \"chat\") {\n markOptimisticAccepted({ ...operation, input: wireInput });\n } else {\n replaceOptimisticSends((current) =>\n current.map((candidate) =>\n candidate.clientEventId === operation.clientEventId\n ? {\n ...candidate,\n input: wireInput,\n destination: acceptedDestination,\n turnId: acceptedResult?.turn.id ?? candidate.turnId,\n triggerEventId:\n acceptedResult?.accepted.id ?? acceptedEvent?.id ?? candidate.triggerEventId,\n appliedQueueVersion:\n acceptedResult?.receipt?.appliedQueueVersion ?? candidate.appliedQueueVersion,\n state: \"queued\",\n error: undefined,\n }\n : candidate,\n ),\n );\n }\n if (!optimisticCallbackIdsRef.current.has(operation.clientEventId)) {\n optimisticCallbackIdsRef.current.add(operation.clientEventId);\n onSent?.(wireInput.text, wireInput);\n }\n } catch (cause) {\n const current = optimisticSendsRef.current.find(\n (candidate) => candidate.clientEventId === operation.clientEventId,\n );\n // A live durable event can prove admission before the original HTTP\n // response times out. Never regress that confirmed state to failure.\n if (!current || (current.state === \"queued\" && current.outcomeUnknown === false)) {\n return;\n }\n const problem = asError(cause);\n onDeliveryErrorRef.current?.(problem, operation.input, \"send\");\n // Only an actual mutation replay can replace prior uncertainty with a\n // definitive response. Local preparation failures remain retry-only.\n const outcomeUnknown =\n operation.outcomeUnknown && !mutationFailureObserved\n ? true\n : isOutcomeUnknownError(cause);\n markFailed(problem, outcomeUnknown);\n } finally {\n optimisticProcessorBusyRef.current = false;\n if (targetKeyRef.current === ownedTargetKey) {\n setOptimisticSends([...optimisticSendsRef.current]);\n }\n }\n })();\n }, [\n adoptDraftBase,\n client,\n durableDrafts,\n markOptimisticAccepted,\n loadDraft,\n onSent,\n options.events,\n persistPayload,\n replaceOptimisticSends,\n sessionId,\n targetKey,\n workspaceId,\n ]);\n\n useEffect(() => {\n processOptimisticSends();\n }, [optimisticSends, processOptimisticSends]);\n\n // Private durable autosave. A newer local edit is never replaced by an older\n // response; saves serialize and each reads the latest acknowledged revision.\n useEffect(() => {\n const pending = pendingOperationRef.current;\n if (pending) {\n const shadow = {\n text: valueRef.current,\n resources: mergeResources(\n restoredResourcesRef.current,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: annotationsRef.current,\n ...(policyRef.current ? { policy: policyRef.current } : {}),\n };\n if (\n pending.newerShadow.text !== shadow.text ||\n JSON.stringify(pending.newerShadow.resources) !== JSON.stringify(shadow.resources) ||\n JSON.stringify(pending.newerShadow.annotations) !== JSON.stringify(shadow.annotations) ||\n JSON.stringify(pending.newerShadow.policy) !== JSON.stringify(shadow.policy)\n ) {\n pendingOperationRef.current = updatePendingComposerShadow(\n pendingOperationKey,\n pending,\n shadow,\n );\n }\n return;\n }\n const optimistic = optimisticSendsRef.current.at(-1);\n if (optimistic) {\n const shadow = {\n text: valueRef.current,\n resources: mergeResources(\n restoredResourcesRef.current,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: annotationsRef.current,\n ...(policyRef.current ? { policy: policyRef.current } : {}),\n };\n if (\n optimistic.newerShadow.text !== shadow.text ||\n JSON.stringify(optimistic.newerShadow.resources) !== JSON.stringify(shadow.resources) ||\n JSON.stringify(optimistic.newerShadow.annotations) !== JSON.stringify(shadow.annotations) ||\n JSON.stringify(optimistic.newerShadow.policy) !== JSON.stringify(shadow.policy)\n ) {\n setOptimisticDraftShadow(shadow);\n }\n }\n if (optimisticSendsRef.current.some((operation) => operation.state === \"sending\")) {\n return;\n }\n if (\n !durableDrafts ||\n !sessionId ||\n draftLoading ||\n sending ||\n !draftRef.current ||\n draftConflict\n )\n return;\n const payload = currentDraftPayload();\n if (!payload || draftSignature(payload) === lastSavedSignature.current) return;\n const timer = window.setTimeout(() => void persistPayload(payload), 500);\n return () => window.clearTimeout(timer);\n }, [\n currentDraftPayload,\n durableDrafts,\n draftConflict,\n draftLoading,\n liveExtrasVersion,\n pendingOperationKey,\n persistPayload,\n setOptimisticDraftShadow,\n sending,\n sessionId,\n ]);\n\n const dispatch = useCallback(\n async (delivery: \"send\" | \"steer\", explicit?: string): Promise<boolean> => {\n const ownedTargetKey = targetKey;\n const ownedGeneration = targetGeneration.current;\n const operationKey = pendingComposerOperationKey(workspaceId, sessionId);\n const pending = pendingOperationRef.current ?? restorePendingComposerOperation(operationKey);\n if (pending && !pendingOperationRef.current) {\n pendingOperationRef.current = pending;\n pendingClientEventId.current = pending.input.clientEventId ?? null;\n }\n const draftAtSend = value;\n const annotationsAtSend = annotations;\n const rawText = explicit ?? draftAtSend;\n const hasText = rawText.trim().length > 0;\n const hasAnnotations = annotationsAtSend.length > 0;\n const currentPolicy = policyRef.current;\n const annotationsComplete = annotationsAtSend.every(\n (annotation) => annotation.note.trim().length > 0,\n );\n // Resolve the extras once: a file-only message (empty text + ≥1 ready\n // resource) is legitimate, so we must not bail on empty text alone.\n const extras = pending ? {} : resolveSendExtras(sendExtrasRef.current);\n const hasResources = restoredResources.length > 0 || (extras.resources?.length ?? 0) > 0;\n if (\n (!pending && (!annotationsComplete || (!hasText && !hasResources && !hasAnnotations))) ||\n !sessionId ||\n !currentPolicy ||\n sending ||\n sendBlockedRef.current?.() === true ||\n targetKeyRef.current !== ownedTargetKey\n ) {\n return false;\n }\n\n const clearPending = (): void => {\n pendingOperationRef.current = null;\n pendingClientEventId.current = null;\n forgetPendingComposerOperation(operationKey);\n };\n\n let keepSteering = pending?.delivery === \"steer\";\n\n const settleAccepted = (operation: PendingComposerOperation): void => {\n clearPending();\n const draftWasUnchanged = valueRef.current === operation.draftAtSend;\n const resourcesWereUnchanged =\n JSON.stringify(restoredResourcesRef.current) ===\n JSON.stringify(operation.resourcesAtSend);\n const annotationsWereUnchanged =\n JSON.stringify(annotationsRef.current) === JSON.stringify(operation.annotationsAtSend);\n if (resourcesWereUnchanged) {\n restoredResourcesRef.current = [];\n setRestoredResources([]);\n }\n if (annotationsWereUnchanged) {\n annotationsRef.current = [];\n setAnnotations([]);\n setAnnotationReviewTargetId(null);\n }\n if (operation.clearDraftOnAccept && draftWasUnchanged) {\n valueRef.current = \"\";\n setValue(\"\");\n }\n onSent?.(operation.input.text, operation.input);\n };\n\n const deliver = async (operation: PendingComposerOperation) => {\n if (durableDrafts) {\n const input = operation.input;\n if (\n input.expectedDraftRevision === undefined ||\n input.clientEventId === undefined ||\n input.model === undefined ||\n input.reasoningEffort === undefined ||\n input.latencyMode === undefined\n ) {\n throw new Error(\"The durable composer draft is not ready for delivery.\");\n }\n const result = await client.submitComposerDraft(workspaceId, sessionId, {\n text: input.text,\n annotations: input.annotations ?? [],\n resources: input.resources ?? [],\n model: input.model,\n reasoningEffort: input.reasoningEffort,\n latencyMode: input.latencyMode,\n expectedDraftRevision: input.expectedDraftRevision,\n clientEventId: input.clientEventId,\n delivery: operation.delivery,\n ...(input.controlEtag ? { controlEtag: input.controlEtag } : {}),\n ...(input.modelContext ? { modelContext: input.modelContext } : {}),\n ...(input.mcpCredentialUpdates\n ? { mcpCredentialUpdates: input.mcpCredentialUpdates }\n : {}),\n ...(input.connectionAuthorities\n ? { connectionAuthorities: input.connectionAuthorities }\n : {}),\n ...(input.personalResourceAttachment\n ? { personalResourceAttachment: input.personalResourceAttachment }\n : {}),\n });\n adoptDraftBase(result.draft);\n return result;\n }\n if (operation.delivery === \"steer\") {\n return await client.steerMessage(workspaceId, sessionId, operation.input);\n }\n await client.sendMessage(workspaceId, sessionId, operation.input);\n return null;\n };\n\n if (delivery === \"steer\") {\n if (steeringRef.current?.clientEventId !== pending?.input.clientEventId) {\n steeringOccurredAtRef.current = new Date().toISOString();\n }\n setSteering({\n phase: \"submitting\",\n text: rawText,\n clientEventId: pending?.input.clientEventId ?? pendingClientEventId.current,\n triggerEventId: null,\n turnId: null,\n });\n }\n setSending(true);\n setError(null);\n try {\n if (pending) {\n let acceptedEvent: SessionEvent | null = null;\n try {\n const events = await client.listEvents(workspaceId, sessionId, {\n includeTypes: [\"user.message\"],\n limit: 100,\n payloadMode: \"none\",\n });\n acceptedEvent =\n events.find(\n (event) =>\n event.type === \"user.message\" &&\n event.clientEventId === pending.input.clientEventId,\n ) ?? null;\n } catch (cause) {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n const problem = asError(cause);\n setError(problem);\n if (pending.delivery === \"steer\") {\n keepSteering = true;\n setSteering({\n phase: \"failed\",\n text: pending.input.text,\n clientEventId: pending.input.clientEventId ?? null,\n triggerEventId: null,\n turnId: null,\n error: \"Not confirmed. Retry.\",\n outcomeUnknown: true,\n });\n }\n }\n return false;\n }\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return false;\n }\n if (acceptedEvent) {\n if (durableDrafts) await loadDraft(false);\n if (pending.delivery === \"steer\") {\n keepSteering = true;\n setSteering({\n phase: \"accepted\",\n text: pending.input.text,\n clientEventId: pending.input.clientEventId ?? null,\n triggerEventId: acceptedEvent.id,\n turnId: null,\n });\n }\n settleAccepted(pending);\n return true;\n }\n if (!pending.canRetry) {\n setError(\n new Error(\n \"OpenGeni cannot safely retry this uncertain request after remount; reconcile the session before sending again.\",\n ),\n );\n return false;\n }\n try {\n const result = await deliver(pending);\n if (pending.delivery === \"steer\" && result) {\n keepSteering = true;\n setSteering({\n phase: \"accepted\",\n text: pending.input.text,\n clientEventId: pending.input.clientEventId ?? null,\n triggerEventId: result.accepted.id,\n turnId: result.turn.id,\n stoppingPreviousAttempt:\n result.replay !== true && (result.interruptionCount ?? 0) > 0,\n });\n }\n } catch (cause) {\n const problem = asError(cause);\n const outcomeUnknown = isOutcomeUnknownError(cause);\n onDeliveryErrorRef.current?.(problem, pending.input, pending.delivery);\n if (!outcomeUnknown) {\n clearPending();\n keepSteering = false;\n } else if (pending.delivery === \"steer\") {\n keepSteering = true;\n setSteering({\n phase: \"failed\",\n text: pending.input.text,\n clientEventId: pending.input.clientEventId ?? null,\n triggerEventId: null,\n turnId: null,\n error: \"Not confirmed. Retry.\",\n outcomeUnknown: true,\n });\n }\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setError(problem);\n }\n return false;\n }\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return false;\n }\n settleAccepted(pending);\n return true;\n }\n\n // Trimming is only an emptiness check. A non-blank prompt is persisted\n // and submitted byte-for-byte, while file-only sends use the same\n // placeholder for both operations so the server content fence cannot\n // reject its own client.\n const sendText = hasText ? rawText : hasAnnotations ? \"\" : FILE_ONLY_MESSAGE_TEXT;\n const currentPayload = currentDraftPayload();\n const payload = currentPayload ? { ...currentPayload, text: sendText } : null;\n if (payload && !(await persistPayload(payload))) return false;\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return false;\n }\n // The wire contract requires non-empty text (z.string().min(1)) and the\n // worker rejects whitespace-only text; a file-only message therefore\n // carries a minimal default so the attachments still get delivered.\n pendingClientEventId.current ??= generateClientEventId();\n const effectiveControl = effectiveControlRef.current;\n const input = composeSendInput(sendText, pendingClientEventId.current, extras, {\n ...currentPolicy,\n ...(effectiveControl?.controlEtag ? { controlEtag: effectiveControl.controlEtag } : {}),\n ...(durableDrafts && draftRef.current\n ? { expectedDraftRevision: draftRef.current.revision }\n : {}),\n resources: mergeResources(restoredResources, extras.resources ?? []),\n annotations: cloneAnnotations(annotationsAtSend),\n });\n const operation: PendingComposerOperation = {\n delivery,\n input,\n draftAtSend,\n resourcesAtSend: [...restoredResources],\n annotationsAtSend: cloneAnnotations(annotationsAtSend),\n newerShadow: {\n text: draftAtSend,\n resources: mergeResources(restoredResources, extras.resources ?? []),\n annotations: cloneAnnotations(annotationsAtSend),\n policy: currentPolicy,\n },\n clearDraftOnAccept: explicit === undefined,\n canRetry: true,\n };\n pendingOperationRef.current = operation;\n rememberPendingComposerOperation(operationKey, operation);\n if (delivery === \"steer\") {\n setSteering({\n phase: \"submitting\",\n text: sendText,\n clientEventId: input.clientEventId ?? null,\n triggerEventId: null,\n turnId: null,\n });\n }\n try {\n const result = await deliver(operation);\n if (delivery === \"steer\" && result) {\n keepSteering = true;\n setSteering({\n phase: \"accepted\",\n text: sendText,\n clientEventId: input.clientEventId ?? null,\n triggerEventId: result.accepted.id,\n turnId: result.turn.id,\n stoppingPreviousAttempt:\n result.replay !== true && (result.interruptionCount ?? 0) > 0,\n });\n }\n } catch (cause) {\n onDeliveryErrorRef.current?.(asError(cause), operation.input, operation.delivery);\n if (!isOutcomeUnknownError(cause)) {\n clearPending();\n } else if (delivery === \"steer\") {\n keepSteering = true;\n setSteering({\n phase: \"failed\",\n text: operation.input.text,\n clientEventId: operation.input.clientEventId ?? null,\n triggerEventId: null,\n turnId: null,\n error: \"Not confirmed. Retry.\",\n outcomeUnknown: true,\n });\n }\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setError(asError(cause));\n }\n return false;\n }\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return false;\n }\n settleAccepted(operation);\n return true;\n } finally {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setSending(false);\n if (delivery === \"steer\" && !keepSteering) setSteering(null);\n }\n }\n },\n [\n client,\n currentDraftPayload,\n durableDrafts,\n onSent,\n persistPayload,\n restoredResources,\n annotations,\n adoptDraftBase,\n sending,\n sessionId,\n targetKey,\n value,\n workspaceId,\n loadDraft,\n ],\n );\n\n const send = useCallback(\n async (explicit?: string): Promise<boolean> => {\n if (pendingOperationRef.current?.delivery === \"send\") {\n return await dispatch(\"send\", explicit);\n }\n const rawText = explicit ?? valueRef.current;\n const annotationsAtSend = cloneAnnotations(annotationsRef.current);\n const currentPolicy = policyRef.current;\n const hasText = rawText.trim().length > 0;\n const hasAnnotations = annotationsAtSend.length > 0;\n const annotationsComplete = annotationsAtSend.every(\n (annotation) => annotation.note.trim().length > 0,\n );\n const extras = resolveSendExtras(sendExtrasRef.current);\n const resources = mergeResources(restoredResourcesRef.current, extras.resources ?? []);\n if (\n !sessionId ||\n !currentPolicy ||\n sending ||\n !annotationsComplete ||\n (!hasText && !hasAnnotations && resources.length === 0) ||\n sendBlockedRef.current?.() === true ||\n targetKeyRef.current !== targetKey\n ) {\n return false;\n }\n const sendText = hasText ? rawText : hasAnnotations ? \"\" : FILE_ONLY_MESSAGE_TEXT;\n const clientEventId = generateClientEventId();\n const effectiveControl = effectiveControlRef.current;\n const input = composeSendInput(sendText, clientEventId, extras, {\n ...currentPolicy,\n ...(effectiveControl?.controlEtag ? { controlEtag: effectiveControl.controlEtag } : {}),\n resources,\n annotations: annotationsAtSend,\n });\n const currentPayload = currentDraftPayload();\n const hasEarlierUnsettledSend = optimisticSendsRef.current.some(\n (candidate) => candidate.state !== \"failed\" || candidate.outcomeUnknown === true,\n );\n const operation: OptimisticSendOperation = {\n clientEventId,\n delivery: \"send\",\n destination:\n effectiveControl?.state === \"paused\" || hasEarlierUnsettledSend\n ? \"queue\"\n : (sendDestinationRef.current?.() ?? \"chat\"),\n text: sendText,\n annotations: annotationsAtSend,\n resources,\n occurredAt: new Date().toISOString(),\n state: \"sending\",\n input,\n draftPayload: currentPayload ? { ...currentPayload, text: sendText } : null,\n newerShadow: {\n text: explicit === undefined ? \"\" : valueRef.current,\n resources: explicit === undefined ? [] : [...restoredResourcesRef.current],\n annotations: explicit === undefined ? [] : cloneAnnotations(annotationsRef.current),\n policy: currentPolicy,\n },\n canRetry: true,\n };\n // The local submission acknowledgement owns the composer before any\n // host callback or queued processor can observe it. Hosts commonly use\n // onSubmitted to remove attachment/repository state, and those updates\n // may synchronously re-render the controlled composer. Clear the refs\n // first so that handoff cannot re-project the submitted text as the next\n // draft. The immutable operation above still owns the exact retry input.\n if (explicit === undefined) {\n valueRef.current = \"\";\n annotationsRef.current = [];\n restoredResourcesRef.current = [];\n localEditRevision.current += 1;\n setValue(\"\");\n setAnnotations([]);\n setAnnotationReviewTargetId(null);\n setRestoredResources([]);\n }\n replaceOptimisticSends((current) => [...current, operation]);\n queueMicrotask(processOptimisticSends);\n setError(null);\n onSubmitted?.(sendText, input);\n return true;\n },\n [\n currentDraftPayload,\n dispatch,\n onSubmitted,\n processOptimisticSends,\n replaceOptimisticSends,\n sending,\n sessionId,\n targetKey,\n ],\n );\n const steer = useCallback(async (text?: string) => await dispatch(\"steer\", text), [dispatch]);\n\n const retryOptimisticMessage = useCallback(\n (clientEventId: string): void => {\n if (sendBlockedRef.current?.() === true) return;\n const currentSteering = steeringRef.current;\n if (currentSteering?.phase === \"failed\" && currentSteering.clientEventId === clientEventId) {\n void dispatch(\"steer\");\n return;\n }\n replaceOptimisticSends((current) =>\n current.map((operation) => {\n if (operation.clientEventId !== clientEventId || operation.state !== \"failed\") {\n return operation;\n }\n if (operation.outcomeUnknown) {\n return { ...operation, state: \"sending\", error: undefined };\n }\n const nextClientEventId = generateClientEventId();\n const currentPersonalResourceAttachment = resolveSendExtras(\n sendExtrasRef.current,\n ).personalResourceAttachment;\n const retryInput = composeSendInput(\n operation.text,\n nextClientEventId,\n {\n ...operation.input,\n ...(currentPersonalResourceAttachment\n ? { personalResourceAttachment: currentPersonalResourceAttachment }\n : {}),\n },\n {\n ...(effectiveControlRef.current?.controlEtag\n ? { controlEtag: effectiveControlRef.current.controlEtag }\n : {}),\n resources: operation.resources,\n annotations: operation.annotations,\n },\n );\n return {\n ...operation,\n clientEventId: nextClientEventId,\n input: retryInput,\n draftPayload: operation.draftPayload,\n occurredAt: new Date().toISOString(),\n state: \"sending\",\n error: undefined,\n outcomeUnknown: false,\n canRetry: true,\n };\n }),\n );\n queueMicrotask(processOptimisticSends);\n },\n [dispatch, processOptimisticSends, replaceOptimisticSends],\n );\n\n const removeOptimisticMessage = useCallback(\n (clientEventId: string): void => {\n if (steeringRef.current?.clientEventId === clientEventId) {\n pendingOperationRef.current = null;\n pendingClientEventId.current = null;\n forgetPendingComposerOperation(pendingComposerOperationKey(workspaceId, sessionId));\n setSteering(null);\n setError(null);\n return;\n }\n replaceOptimisticSends((current) =>\n current.filter((operation) => operation.clientEventId !== clientEventId),\n );\n },\n [replaceOptimisticSends, sessionId, workspaceId],\n );\n\n // A send is possible with non-empty text OR with ≥1 attached resource (a\n // file-only message). Resources ride in `sendExtras`, so we resolve them here\n // — keeping useComposer attachment-agnostic while still lighting up the send\n // affordance the moment a file is ready. Attachment hosts bind `sendBlocked`\n // to unresolved uploads so direct send()/steer() calls fail closed too.\n const hasReadyResources =\n restoredResources.length > 0 ||\n (resolveSendExtras(sendExtrasRef.current).resources?.length ?? 0) > 0;\n const hasPendingOperation = pendingOperationRef.current !== null;\n const annotationsComplete = annotations.every((annotation) => annotation.note.trim().length > 0);\n\n const pause = useCallback(\n async (reason?: string): Promise<void> => {\n const ownedTargetKey = targetKey;\n const ownedGeneration = targetGeneration.current;\n if (!sessionId || pausing || targetKeyRef.current !== ownedTargetKey) {\n return;\n }\n setPausing(true);\n setError(null);\n try {\n const clientEventId = generateClientEventId();\n const effectiveControl = effectiveControlRef.current;\n const result = await replayOutcomeUnknown(() =>\n client.pauseSession(workspaceId, sessionId, {\n clientEventId,\n ...(reason !== undefined ? { reason } : {}),\n ...(effectiveControl?.controlEtag\n ? { expectedControlEtag: effectiveControl.controlEtag }\n : {}),\n }),\n );\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setAcceptedControl(result.effectiveControl);\n }\n } catch (cause) {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setError(cause instanceof Error ? cause : new Error(String(cause)));\n }\n } finally {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setPausing(false);\n }\n }\n },\n [client, workspaceId, sessionId, pausing, targetKey],\n );\n\n const resume = useCallback(\n async (reason?: string): Promise<void> => {\n const ownedTargetKey = targetKey;\n const ownedGeneration = targetGeneration.current;\n if (!sessionId || resuming || targetKeyRef.current !== ownedTargetKey) return;\n setResuming(true);\n setError(null);\n try {\n const clientEventId = generateClientEventId();\n const effectiveControl = effectiveControlRef.current;\n const result = await replayOutcomeUnknown(() =>\n client.resumeSession(workspaceId, sessionId, {\n clientEventId,\n ...(reason !== undefined ? { reason } : {}),\n ...(effectiveControl?.controlEtag\n ? { expectedControlEtag: effectiveControl.controlEtag }\n : {}),\n }),\n );\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setAcceptedControl(result.effectiveControl);\n }\n } catch (cause) {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setError(cause instanceof Error ? cause : new Error(String(cause)));\n }\n } finally {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setResuming(false);\n }\n }\n },\n [client, workspaceId, sessionId, resuming, targetKey],\n );\n\n const resumeScope = useCallback(\n async (option: EffectiveControlResumeOption): Promise<void> => {\n const ownedTargetKey = targetKey;\n const ownedGeneration = targetGeneration.current;\n if (!sessionId || resuming || targetKeyRef.current !== ownedTargetKey) return;\n setResuming(true);\n setError(null);\n try {\n if (option.scope === \"workspace\") {\n const workspaceBlocker = effectiveControlRef.current?.blockers.find(\n (blocker) => blocker.kind === \"workspace\",\n );\n if (!client.setWorkspaceInferenceState) {\n throw new Error(\n \"@opengeni/react: workspace-scoped resume requires setWorkspaceInferenceState.\",\n );\n }\n const clientEventId = generateClientEventId();\n await replayOutcomeUnknown(() =>\n client.setWorkspaceInferenceState!(workspaceId, {\n action: \"resume\",\n clientEventId,\n ...(workspaceBlocker ? { expectedRevision: workspaceBlocker.revision } : {}),\n }),\n );\n } else if (option.scope === \"session\" && option.targetId) {\n const target = await client.getQueue(workspaceId, option.targetId);\n if (\n targetKeyRef.current !== ownedTargetKey ||\n targetGeneration.current !== ownedGeneration\n ) {\n return;\n }\n const clientEventId = generateClientEventId();\n await replayOutcomeUnknown(() =>\n client.resumeSession(workspaceId, option.targetId!, {\n clientEventId,\n expectedControlEtag: target.effectiveControl.controlEtag,\n }),\n );\n } else {\n const clientEventId = generateClientEventId();\n const effectiveControl = effectiveControlRef.current;\n const result = await replayOutcomeUnknown(() =>\n client.resumeSession(workspaceId, sessionId, {\n clientEventId,\n ...(effectiveControl?.controlEtag\n ? { expectedControlEtag: effectiveControl.controlEtag }\n : {}),\n }),\n );\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setAcceptedControl(result.effectiveControl);\n }\n }\n } catch (cause) {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setError(asError(cause));\n }\n } finally {\n if (\n targetKeyRef.current === ownedTargetKey &&\n targetGeneration.current === ownedGeneration\n ) {\n setResuming(false);\n }\n }\n },\n [client, resuming, sessionId, targetKey, workspaceId],\n );\n\n const updateValue = useCallback(\n (next: string) => {\n if (targetKeyRef.current !== targetKey) return;\n localEditRevision.current += 1;\n valueRef.current = next;\n pendingOperationRef.current = updatePendingComposerShadow(\n pendingOperationKey,\n pendingOperationRef.current,\n {\n text: next,\n resources: mergeResources(\n restoredResourcesRef.current,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: annotationsRef.current,\n policy: policyRef.current ?? undefined,\n },\n );\n setOptimisticDraftShadow({\n text: next,\n resources: mergeResources(\n restoredResourcesRef.current,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: annotationsRef.current,\n policy: policyRef.current ?? undefined,\n });\n setValue(next);\n },\n [pendingOperationKey, setOptimisticDraftShadow, targetKey],\n );\n\n const updateAnnotations = useCallback(\n (next: DraftTimelineAnnotation[], reviewTargetId: string | null = null) => {\n if (targetKeyRef.current !== targetKey) return;\n localEditRevision.current += 1;\n annotationsRef.current = next;\n pendingOperationRef.current = updatePendingComposerShadow(\n pendingOperationKey,\n pendingOperationRef.current,\n {\n text: valueRef.current,\n resources: mergeResources(\n restoredResourcesRef.current,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: next,\n policy: policyRef.current ?? undefined,\n },\n );\n setOptimisticDraftShadow({\n text: valueRef.current,\n resources: mergeResources(\n restoredResourcesRef.current,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: next,\n policy: policyRef.current ?? undefined,\n });\n setAnnotations(next);\n setAnnotationReviewTargetId(reviewTargetId);\n },\n [pendingOperationKey, setOptimisticDraftShadow, targetKey],\n );\n\n const addAnnotation = useCallback(\n (annotation: DraftTimelineAnnotation) => {\n if (annotationsRef.current.length >= 12) {\n setError(new Error(\"A message can include at most 12 timeline annotations.\"));\n return;\n }\n const next = [...annotationsRef.current, annotation];\n updateAnnotations(next, annotation.id);\n },\n [updateAnnotations],\n );\n\n const updateAnnotation = useCallback(\n (id: string, note: string) => {\n updateAnnotations(\n annotationsRef.current.map((annotation) =>\n annotation.id === id ? { ...annotation, note } : annotation,\n ),\n );\n },\n [updateAnnotations],\n );\n\n const removeAnnotation = useCallback(\n (id: string) => {\n updateAnnotations(annotationsRef.current.filter((annotation) => annotation.id !== id));\n },\n [updateAnnotations],\n );\n\n const clearAnnotationReviewTarget = useCallback(() => {\n setAnnotationReviewTargetId(null);\n }, []);\n\n const requestAnnotationReview = useCallback((id?: string) => {\n const current = annotationsRef.current;\n if (current.length === 0) {\n setAnnotationReviewTargetId(null);\n return;\n }\n if (id && current.some((annotation) => annotation.id === id)) {\n setAnnotationReviewTargetId(id);\n return;\n }\n const incomplete = current.find((annotation) => annotation.note.trim().length === 0);\n setAnnotationReviewTargetId(incomplete?.id ?? current[0]!.id);\n }, []);\n\n const updatePolicy = useCallback(\n (next: ComposerPolicy): void => {\n if (targetKeyRef.current !== targetKey) return;\n localEditRevision.current += 1;\n policyRef.current = next;\n const shadow = {\n text: valueRef.current,\n resources: mergeResources(\n restoredResourcesRef.current,\n resolveSendExtras(sendExtrasRef.current).resources ?? [],\n ),\n annotations: annotationsRef.current,\n policy: next,\n };\n pendingOperationRef.current = updatePendingComposerShadow(\n pendingOperationKey,\n pendingOperationRef.current,\n shadow,\n );\n setOptimisticDraftShadow(shadow);\n setPolicy(next);\n },\n [pendingOperationKey, setOptimisticDraftShadow, targetKey],\n );\n\n const updateModel = useCallback(\n (model: string): void => {\n const current = policyRef.current;\n if (current) updatePolicy({ ...current, model });\n },\n [updatePolicy],\n );\n\n const updateReasoningEffort = useCallback(\n (reasoningEffort: ReasoningEffort): void => {\n const current = policyRef.current;\n if (current) updatePolicy({ ...current, reasoningEffort });\n },\n [updatePolicy],\n );\n\n const updateLatencyMode = useCallback(\n (latencyMode: LatencyMode): void => {\n const current = policyRef.current;\n if (current) updatePolicy({ ...current, latencyMode });\n },\n [updatePolicy],\n );\n\n const removeRestoredResource = useCallback(\n (index: number) => {\n if (targetKeyRef.current !== targetKey) return;\n localEditRevision.current += 1;\n const next = restoredResourcesRef.current.filter((_, candidate) => candidate !== index);\n restoredResourcesRef.current = next;\n pendingOperationRef.current = updatePendingComposerShadow(\n pendingOperationKey,\n pendingOperationRef.current,\n {\n text: valueRef.current,\n resources: mergeResources(next, resolveSendExtras(sendExtrasRef.current).resources ?? []),\n annotations: annotationsRef.current,\n policy: policyRef.current ?? undefined,\n },\n );\n setOptimisticDraftShadow({\n text: valueRef.current,\n resources: mergeResources(next, resolveSendExtras(sendExtrasRef.current).resources ?? []),\n annotations: annotationsRef.current,\n policy: policyRef.current ?? undefined,\n });\n setRestoredResources(next);\n },\n [pendingOperationKey, setOptimisticDraftShadow, targetKey],\n );\n\n const hasDraftContent = useCallback((): boolean => {\n const current = draftRef.current;\n const extras = resolveSendExtras(sendExtrasRef.current);\n return (\n valueRef.current.length > 0 ||\n annotationsRef.current.length > 0 ||\n restoredResourcesRef.current.length > 0 ||\n (extras.resources?.length ?? 0) > 0 ||\n (current?.sourceTurnId !== null && current?.sourceTurnId !== undefined)\n );\n }, []);\n\n const resolveDraftConflict = useCallback(\n async (choice: \"keep_mine\" | \"use_remote\"): Promise<void> => {\n const ownedTargetKey = targetKey;\n const ownedGeneration = targetGeneration.current;\n if (!sessionId || !durableDrafts || targetKeyRef.current !== ownedTargetKey) return;\n const remote = await client.getComposerDraft(workspaceId, sessionId);\n if (targetKeyRef.current !== ownedTargetKey || targetGeneration.current !== ownedGeneration) {\n return;\n }\n if (choice === \"use_remote\") {\n applyDraft(remote);\n setError(null);\n return;\n }\n draftRef.current = remote;\n setDraft(remote);\n setDraftConflict(null);\n setError(null);\n const payload = currentDraftPayload();\n if (payload) await persistPayload({ ...payload, expectedRevision: remote.revision });\n },\n [\n applyDraft,\n client,\n currentDraftPayload,\n durableDrafts,\n persistPayload,\n sessionId,\n targetKey,\n workspaceId,\n ],\n );\n\n const identityMatches = stateTargetKey === targetKey;\n const visibleSteering = identityMatches ? steering : null;\n const visibleOptimisticMessages: ComposerOptimisticMessage[] = identityMatches\n ? [\n ...optimisticSends.map(\n ({ input: _input, draftPayload: _payload, canRetry: _retry, ...item }) => item,\n ),\n ...(visibleSteering?.clientEventId\n ? [\n {\n clientEventId: visibleSteering.clientEventId,\n delivery: \"steer\" as const,\n destination: \"chat\" as const,\n text: visibleSteering.text,\n annotations:\n pendingOperationRef.current?.delivery === \"steer\"\n ? pendingOperationRef.current.annotationsAtSend\n : [],\n resources:\n pendingOperationRef.current?.delivery === \"steer\"\n ? pendingOperationRef.current.resourcesAtSend\n : [],\n occurredAt: steeringOccurredAtRef.current,\n state:\n visibleSteering.phase === \"submitting\"\n ? (\"sending\" as const)\n : visibleSteering.phase === \"failed\"\n ? (\"failed\" as const)\n : (\"queued\" as const),\n turnId: visibleSteering.turnId,\n triggerEventId: visibleSteering.triggerEventId,\n ...(visibleSteering.error ? { error: visibleSteering.error } : {}),\n ...(visibleSteering.outcomeUnknown !== undefined\n ? { outcomeUnknown: visibleSteering.outcomeUnknown }\n : {}),\n },\n ]\n : []),\n ]\n : [];\n const reloadDraft = useCallback(async () => await loadDraft(true), [loadDraft]);\n const clearError = useCallback(() => {\n if (targetKeyRef.current !== targetKey) return;\n setError(null);\n setDraftReadError(null);\n setDraftConflict(null);\n }, [targetKey]);\n // `valueRef` is the synchronous composer authority. React state exists to\n // schedule renders, but a concurrent autosave settlement can render the\n // previous state lane after a newer input event has already updated the ref.\n // Projecting that stale state into a controlled textarea rewrites the old\n // draft for one commit, which moves the caret and can briefly resurrect a\n // submitted message. Never let an incidental render outrank the latest\n // local lifecycle decision.\n const visibleValue = identityMatches ? valueRef.current : \"\";\n\n return {\n value: visibleValue,\n setValue: updateValue,\n annotations: identityMatches ? annotations : [],\n addAnnotation,\n updateAnnotation,\n removeAnnotation,\n annotationReviewTargetId: identityMatches ? annotationReviewTargetId : null,\n clearAnnotationReviewTarget,\n requestAnnotationReview,\n hasDraftContent,\n send,\n optimisticMessages: visibleOptimisticMessages,\n retryOptimisticMessage,\n removeOptimisticMessage,\n steer,\n steering: visibleSteering,\n stoppingAttempt: identityMatches\n ? visibleSteering?.phase === \"accepted\" && visibleSteering.stoppingPreviousAttempt === true\n ? \"previous\"\n : null\n : null,\n sending: identityMatches ? sending : false,\n canSend:\n identityMatches &&\n Boolean(sessionId) &&\n !sending &&\n !draftLoading &&\n policy !== null &&\n sendBlockedRef.current?.() !== true &&\n annotationsComplete &&\n (hasPendingOperation ||\n visibleValue.trim().length > 0 ||\n hasReadyResources ||\n annotations.length > 0),\n pause,\n pausing: identityMatches ? pausing : false,\n resume,\n resumeScope,\n resuming: identityMatches ? resuming : false,\n effectiveControl: identityMatches ? effectiveControlRef.current : null,\n draft: identityMatches ? draft : null,\n draftRevision: identityMatches ? (draft?.revision ?? 0) : 0,\n draftLoading: identityMatches ? draftLoading : Boolean(sessionId) && durableDrafts,\n draftSaving: identityMatches ? draftSaving : false,\n draftConflict: identityMatches ? draftConflict : null,\n policy: identityMatches ? policy : null,\n setModel: updateModel,\n setReasoningEffort: updateReasoningEffort,\n setLatencyMode: updateLatencyMode,\n draftPersistence: durableDrafts ? \"durable\" : \"disabled\",\n applyDraft,\n reloadDraft,\n resolveDraftConflict,\n restoredResources: identityMatches ? restoredResources : [],\n removeRestoredResource,\n error: identityMatches ? (error ?? draftReadError) : null,\n clearError,\n };\n}\n\n/** Events that can atomically replace or clear this subject's durable draft. */\nexport function isComposerDraftEvent(event: Pick<SessionEvent, \"type\">): boolean {\n return event.type === \"user.message\" || event.type === \"session.queue.changed\";\n}\n\n/**\n * Default text for a resource-only message (attachments present, no typed\n * draft). Kept non-empty so the wire contract (`text: z.string().min(1)`) and\n * the worker's non-whitespace guard accept it. The export name is retained for\n * compatibility now that repositories can ride beside files in `resources`.\n */\nexport const FILE_ONLY_MESSAGE_TEXT = \"(see attached context)\";\n\n/** Resolve possibly-deferred extras to a concrete bag (function evaluated now). */\nexport function resolveSendExtras(\n extras: ComposerSendExtras | (() => ComposerSendExtras) | undefined,\n): ComposerSendExtras {\n return (typeof extras === \"function\" ? extras() : extras) ?? {};\n}\n\n/**\n * Merge the draft text + idempotency key with caller-provided extras. The\n * text and clientEventId always win over extras. Exported for tests.\n */\nexport function composeSendInput(\n text: string,\n clientEventId: string,\n extras: ComposerSendExtras | (() => ComposerSendExtras) | undefined,\n bound: Partial<SendMessageInput> = {},\n): SendMessageInput {\n return { ...resolveSendExtras(extras), ...bound, text, clientEventId };\n}\n\n/** Submit on plain Enter; Shift+Enter inserts a newline. Exported for tests. */\nexport function shouldSubmitOnKey(event: {\n key: string;\n shiftKey: boolean;\n metaKey?: boolean;\n ctrlKey?: boolean;\n nativeEvent?: { isComposing?: boolean };\n}): boolean {\n if (event.key !== \"Enter\" || event.shiftKey) {\n return false;\n }\n return event.nativeEvent?.isComposing !== true;\n}\n\n/** Cmd/Ctrl+Enter steers; ordinary Enter appends to the queue. */\nexport function shouldSteerOnKey(event: { metaKey?: boolean; ctrlKey?: boolean }): boolean {\n return event.metaKey === true || event.ctrlKey === true;\n}\n\nfunction generateClientEventId(): string {\n return globalThis.crypto.randomUUID();\n}\n\nfunction isOutcomeUnknownError(cause: unknown): boolean {\n return (\n typeof cause === \"object\" &&\n cause !== null &&\n (cause as { outcomeUnknown?: unknown }).outcomeUnknown === true\n );\n}\n\nasync function replayOutcomeUnknown<T>(command: () => Promise<T>): Promise<T> {\n try {\n return await command();\n } catch (cause) {\n if (!isOutcomeUnknownError(cause)) throw cause;\n return await command();\n }\n}\n\nfunction asError(cause: unknown): Error {\n return cause instanceof Error ? cause : new Error(String(cause));\n}\n\nfunction promptRoutingFromAcceptedEvent(\n event: SessionEvent | null,\n): \"accepted_for_execution\" | \"queued_for_execution\" | \"accepted_for_steering\" | null {\n if (\n typeof event?.payload !== \"object\" ||\n event.payload === null ||\n Array.isArray(event.payload)\n ) {\n return null;\n }\n const routing = (event.payload as Record<string, unknown>).routing;\n return routing === \"accepted_for_execution\" ||\n routing === \"queued_for_execution\" ||\n routing === \"accepted_for_steering\"\n ? routing\n : null;\n}\n\nfunction isDraftConflictError(error: Error): boolean {\n const apiError = error as Partial<OpenGeniApiError>;\n return (\n apiError.status === 409 && apiError.outcomeUnknown !== true && apiError.code === \"DRAFT_CHANGED\"\n );\n}\n\nfunction draftPayload(draft: ComposerDraft): SaveComposerDraftRequest {\n return {\n expectedRevision: draft.revision,\n text: draft.text,\n resources: draft.resources,\n annotations: draft.annotations ?? [],\n model: draft.model,\n reasoningEffort: draft.reasoningEffort,\n latencyMode: draft.latencyMode,\n };\n}\n\nfunction policyFromDraft(draft: ComposerDraft): ComposerPolicy {\n return {\n model: draft.model,\n reasoningEffort: draft.reasoningEffort,\n latencyMode: draft.latencyMode,\n };\n}\n\nfunction composerDraftPayload(\n base: ComposerDraft,\n text: string,\n restoredResources: ResourceRef[],\n annotations: DraftTimelineAnnotation[],\n policy: ComposerPolicy,\n additionalResources: ResourceRef[],\n): SaveComposerDraftRequest {\n return {\n expectedRevision: base.revision,\n text,\n resources: mergeResources(restoredResources, additionalResources),\n annotations,\n model: policy.model,\n reasoningEffort: policy.reasoningEffort,\n latencyMode: policy.latencyMode,\n };\n}\n\nfunction draftSignature(payload: SaveComposerDraftRequest): string {\n const { expectedRevision: _revision, ...content } = payload;\n return JSON.stringify(content);\n}\n\nfunction mergeResources(base: ResourceRef[], additions: ResourceRef[]): ResourceRef[] {\n const seen = new Set<string>();\n return [...base, ...additions].filter((resource) => {\n // Reconnect reconciliation can restore the canonical server form while\n // the still-mounted upload card supplies the same ready file without its\n // default mount. Treat those two wire shapes as one selected attachment;\n // preserving the first representation keeps custom mounts and ordering\n // intact while preventing the draft and command paths from seeing\n // different duplicate counts after server normalization.\n const key =\n resource.kind === \"file\"\n ? `file:${resource.fileId}\\u0000${resource.mountPath ?? `${DEFAULT_FILE_RESOURCE_MOUNT_ROOT}/${resource.fileId}`}`\n : JSON.stringify(resource);\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n}\n"],"mappings":";;;;;;;;AAAA;AAAA,EACE;AAAA,OAaK;AACP,SAAS,aAAa,WAAW,iBAAiB,QAAQ,gBAAgB;AAoG1E,IAAM,kCAAkC;AACxC,IAAM,iCAAiC;AAKvC,IAAM,4BAA4B,oBAAI,IAA4C;AAClF,IAAM,2BAA2B,oBAAI,IAA6C;AAElF,SAAS,4BACP,aACA,WACe;AACf,SAAO,YAAY,GAAG,WAAW,KAAS,SAAS,KAAK;AAC1D;AAEA,SAAS,yBAAyC;AAChD,MAAI;AACF,WAAO,OAAO,WAAW,cAAc,OAAO,OAAO;AAAA,EACvD,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,0BAA0B,KAAqB;AACtD,SAAO,GAAG,+BAA+B,GAAG,mBAAmB,GAAG,CAAC;AACrE;AAEA,SAAS,yBAAyB,K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