@opengeni/react 4.0.2 → 4.0.5-canary.39118806767001
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 +787 -26
- package/dist/accounts.js +2 -0
- package/dist/accounts.js.map +1 -1
- package/dist/approvals.d.ts +2 -1
- package/dist/artifacts-document.js +6 -3
- package/dist/artifacts-presentation.js +6 -3
- package/dist/artifacts-spreadsheet.d.ts +1 -1
- package/dist/artifacts-spreadsheet.js +6 -3
- package/dist/artifacts.d.ts +5 -1
- package/dist/artifacts.js +542 -278
- package/dist/artifacts.js.map +1 -1
- package/dist/browser-viewer-GEHX3KYE.js +20 -0
- package/dist/capability-catalog-row.d.ts +20 -0
- package/dist/capability-logo-fallback.d.ts +3 -0
- package/dist/chat-interactive-block-5V3BGLXT.js +15 -0
- package/dist/chunk-2DDJ6YH6.js +41 -0
- package/dist/chunk-2DDJ6YH6.js.map +1 -0
- package/dist/chunk-2EGXXUG4.js +1161 -0
- package/dist/chunk-2EGXXUG4.js.map +1 -0
- package/dist/chunk-2XKRY4GF.js +302 -0
- package/dist/chunk-2XKRY4GF.js.map +1 -0
- package/dist/chunk-2ZUUIMBY.js +343 -0
- package/dist/chunk-2ZUUIMBY.js.map +1 -0
- package/dist/chunk-4F4FGCH2.js +34 -0
- package/dist/chunk-4F4FGCH2.js.map +1 -0
- package/dist/{chunk-Z7WBDB4E.js → chunk-4M2MJLY3.js} +848 -867
- package/dist/chunk-4M2MJLY3.js.map +1 -0
- package/dist/chunk-4U7SHFQ2.js +193 -0
- package/dist/chunk-4U7SHFQ2.js.map +1 -0
- package/dist/chunk-5I4VRWBB.js +56 -0
- package/dist/chunk-5I4VRWBB.js.map +1 -0
- package/dist/{chunk-24M4YBCL.js → chunk-62XZ3IX3.js} +1751 -845
- package/dist/chunk-62XZ3IX3.js.map +1 -0
- package/dist/chunk-77THWHSU.js +308 -0
- package/dist/chunk-77THWHSU.js.map +1 -0
- package/dist/chunk-7CZLTFXF.js +466 -0
- package/dist/chunk-7CZLTFXF.js.map +1 -0
- package/dist/chunk-7N5AD2TC.js +327 -0
- package/dist/chunk-7N5AD2TC.js.map +1 -0
- package/dist/chunk-7SZ7MMCY.js +325 -0
- package/dist/chunk-7SZ7MMCY.js.map +1 -0
- package/dist/chunk-7TG6KTR2.js +3153 -0
- package/dist/chunk-7TG6KTR2.js.map +1 -0
- package/dist/chunk-AIX25FIQ.js +409 -0
- package/dist/chunk-AIX25FIQ.js.map +1 -0
- package/dist/chunk-AT2HD6RQ.js +1936 -0
- package/dist/chunk-AT2HD6RQ.js.map +1 -0
- package/dist/chunk-B27E3V37.js +29 -0
- package/dist/chunk-B27E3V37.js.map +1 -0
- package/dist/{chunk-5M6VTFJ5.js → chunk-B4EDAXMC.js} +37 -13
- package/dist/chunk-B4EDAXMC.js.map +1 -0
- package/dist/chunk-BOG2FED3.js +35 -0
- package/dist/chunk-BOG2FED3.js.map +1 -0
- package/dist/chunk-BQYQU5QW.js +109 -0
- package/dist/chunk-BQYQU5QW.js.map +1 -0
- package/dist/{chunk-PAJU5KKL.js → chunk-BRIOXCLH.js} +68 -25
- package/dist/chunk-BRIOXCLH.js.map +1 -0
- package/dist/chunk-CM7LVUKC.js +35 -0
- package/dist/chunk-CM7LVUKC.js.map +1 -0
- package/dist/{chunk-KCGXPP5V.js → chunk-CXIGFHVL.js} +35 -23
- package/dist/chunk-CXIGFHVL.js.map +1 -0
- package/dist/chunk-DHXKEJBH.js +71 -0
- package/dist/chunk-DHXKEJBH.js.map +1 -0
- package/dist/{chunk-NOSYBS2D.js → chunk-DN3TKURW.js} +12 -9
- package/dist/chunk-DN3TKURW.js.map +1 -0
- package/dist/chunk-DNJ23AWQ.js +35 -0
- package/dist/chunk-DNJ23AWQ.js.map +1 -0
- package/dist/chunk-ESAMXNBZ.js +3237 -0
- package/dist/chunk-ESAMXNBZ.js.map +1 -0
- package/dist/{chunk-4MDLEHXL.js → chunk-EWATYP5L.js} +64 -44
- package/dist/chunk-EWATYP5L.js.map +1 -0
- package/dist/{chunk-YBM6CQRU.js → chunk-FQ5CXNUG.js} +65 -42
- package/dist/chunk-FQ5CXNUG.js.map +1 -0
- package/dist/chunk-HEVQKE27.js +150 -0
- package/dist/chunk-HEVQKE27.js.map +1 -0
- package/dist/chunk-HZ47S3DP.js +1086 -0
- package/dist/chunk-HZ47S3DP.js.map +1 -0
- package/dist/chunk-I5BJ7ENY.js +174 -0
- package/dist/chunk-I5BJ7ENY.js.map +1 -0
- package/dist/chunk-IGFZFLI2.js +1390 -0
- package/dist/chunk-IGFZFLI2.js.map +1 -0
- package/dist/chunk-IGVL3ELX.js +46 -0
- package/dist/chunk-IGVL3ELX.js.map +1 -0
- package/dist/chunk-IOD24LGR.js +384 -0
- package/dist/chunk-IOD24LGR.js.map +1 -0
- package/dist/chunk-IOYHDEP3.js +38 -0
- package/dist/chunk-IOYHDEP3.js.map +1 -0
- package/dist/chunk-IQL77TMM.js +803 -0
- package/dist/chunk-IQL77TMM.js.map +1 -0
- package/dist/chunk-IZV5FTJC.js +55 -0
- package/dist/chunk-IZV5FTJC.js.map +1 -0
- package/dist/{chunk-H5YGYNXS.js → chunk-JAYYFOOB.js} +75 -28
- package/dist/chunk-JAYYFOOB.js.map +1 -0
- package/dist/chunk-KN2MYSCC.js +409 -0
- package/dist/chunk-KN2MYSCC.js.map +1 -0
- package/dist/{chunk-PEI6RANI.js → chunk-KYVJMTXL.js} +434 -145
- package/dist/chunk-KYVJMTXL.js.map +1 -0
- package/dist/{chunk-ZYRGEKWS.js → chunk-LJUMYUBO.js} +3 -1
- package/dist/{chunk-ZYRGEKWS.js.map → chunk-LJUMYUBO.js.map} +1 -1
- package/dist/{chunk-ICA6R6TW.js → chunk-LNUD3JNI.js} +1532 -395
- package/dist/chunk-LNUD3JNI.js.map +1 -0
- package/dist/chunk-M357MHH3.js +2 -0
- package/dist/{chunk-BV5A4OTE.js → chunk-MEL6PH2I.js} +1218 -537
- package/dist/chunk-MEL6PH2I.js.map +1 -0
- package/dist/chunk-MF6WS2XF.js +386 -0
- package/dist/chunk-MF6WS2XF.js.map +1 -0
- package/dist/chunk-MK2TQO4Y.js +24 -0
- package/dist/chunk-MK2TQO4Y.js.map +1 -0
- package/dist/chunk-N7S72EXK.js +25 -0
- package/dist/chunk-N7S72EXK.js.map +1 -0
- package/dist/{chunk-KZ73RL76.js → chunk-NAWXARTY.js} +58 -9
- package/dist/chunk-NAWXARTY.js.map +1 -0
- package/dist/chunk-NX4ADH73.js +14 -0
- package/dist/chunk-NX4ADH73.js.map +1 -0
- package/dist/chunk-OYQQJL3J.js +16 -0
- package/dist/chunk-OYQQJL3J.js.map +1 -0
- package/dist/chunk-P4MKPCTC.js +51 -0
- package/dist/chunk-P4MKPCTC.js.map +1 -0
- package/dist/{chunk-JVYQRRC4.js → chunk-PEHTX3V7.js} +21 -1
- package/dist/chunk-PEHTX3V7.js.map +1 -0
- package/dist/chunk-PMV53IMM.js +26 -0
- package/dist/chunk-PMV53IMM.js.map +1 -0
- package/dist/chunk-PYSEGV5X.js +14396 -0
- package/dist/chunk-PYSEGV5X.js.map +1 -0
- package/dist/{chunk-HUIKIDM5.js → chunk-QOEWDOFW.js} +295 -156
- package/dist/chunk-QOEWDOFW.js.map +1 -0
- package/dist/chunk-QV3DJVRZ.js +11 -0
- package/dist/chunk-QV3DJVRZ.js.map +1 -0
- package/dist/{chunk-HUMIRRYI.js → chunk-QYUYVSNG.js} +1103 -1699
- package/dist/chunk-QYUYVSNG.js.map +1 -0
- package/dist/{chunk-6J56T3MG.js → chunk-RRAQ5FV5.js} +186 -60
- package/dist/chunk-RRAQ5FV5.js.map +1 -0
- package/dist/{chunk-5YK2ZDIG.js → chunk-TNEZNMSN.js} +4 -10
- package/dist/chunk-TNEZNMSN.js.map +1 -0
- package/dist/{chunk-22KP6LR5.js → chunk-TXS65BB2.js} +3 -1
- package/dist/{chunk-22KP6LR5.js.map → chunk-TXS65BB2.js.map} +1 -1
- package/dist/chunk-UIWIOB4U.js +2215 -0
- package/dist/chunk-UIWIOB4U.js.map +1 -0
- package/dist/chunk-UNJPZGNK.js +63 -0
- package/dist/chunk-UNJPZGNK.js.map +1 -0
- package/dist/chunk-V7UGCQHQ.js +86 -0
- package/dist/chunk-V7UGCQHQ.js.map +1 -0
- package/dist/chunk-VU4QUISJ.js +3405 -0
- package/dist/chunk-VU4QUISJ.js.map +1 -0
- package/dist/chunk-WEY5J52U.js +467 -0
- package/dist/chunk-WEY5J52U.js.map +1 -0
- package/dist/chunk-WH2CBESG.js +409 -0
- package/dist/chunk-WH2CBESG.js.map +1 -0
- package/dist/{chunk-VZTQ73XT.js → chunk-XEA5BCMA.js} +3 -1
- package/dist/{chunk-VZTQ73XT.js.map → chunk-XEA5BCMA.js.map} +1 -1
- package/dist/{chunk-NLTS7JHI.js → chunk-XEIHS3RN.js} +834 -403
- package/dist/chunk-XEIHS3RN.js.map +1 -0
- package/dist/chunk-YNXZRE3F.js +408 -0
- package/dist/chunk-YNXZRE3F.js.map +1 -0
- package/dist/chunk-YSRBFJMQ.js +43 -0
- package/dist/chunk-YSRBFJMQ.js.map +1 -0
- package/dist/{chunk-NEXLLTP4.js → chunk-ZGFU4LVW.js} +6 -5
- package/dist/chunk-ZGFU4LVW.js.map +1 -0
- package/dist/chunk-ZO35BAMO.js +172 -0
- package/dist/chunk-ZO35BAMO.js.map +1 -0
- package/dist/chunk-ZUWF4NF7.js +13 -0
- package/dist/chunk-ZUWF4NF7.js.map +1 -0
- package/dist/client.d.ts +15 -6
- package/dist/clipboard.js +3 -1
- package/dist/commands/registry.d.ts +2 -1
- package/dist/commands/types.d.ts +2 -0
- package/dist/components/anthropic-mark.d.ts +3 -0
- package/dist/components/approval-surface.d.ts +21 -7
- package/dist/components/artifacts/artifact-chrome.d.ts +121 -0
- package/dist/components/artifacts/artifact-sandbox.d.ts +30 -0
- package/dist/components/artifacts/artifact-surface.d.ts +4 -2
- package/dist/components/artifacts/chat-interactive-block.d.ts +29 -0
- package/dist/components/artifacts/deferred-chat-media.d.ts +15 -0
- package/dist/components/artifacts/document-editor.d.ts +4 -2
- package/dist/components/artifacts/editable-artifact-ui.d.ts +4 -2
- package/dist/components/artifacts/editable-artifact-view.d.ts +48 -0
- package/dist/components/artifacts/editable-document.d.ts +3 -2
- package/dist/components/artifacts/editable-presentation.d.ts +4 -3
- package/dist/components/artifacts/editable-spreadsheet.d.ts +8 -3
- package/dist/components/artifacts/index.d.ts +8 -1
- package/dist/components/artifacts/inline-html-document.d.ts +2 -0
- package/dist/components/artifacts/latest-task-runner.d.ts +15 -0
- package/dist/components/artifacts/presentation-editor.d.ts +6 -2
- package/dist/components/artifacts/published-html-artifact-frame.d.ts +17 -40
- package/dist/components/artifacts/session-artifact-viewer.d.ts +39 -0
- package/dist/components/artifacts/site-view.d.ts +26 -0
- package/dist/components/artifacts/spreadsheet-command-queue.d.ts +20 -0
- package/dist/components/artifacts/spreadsheet-download.d.ts +7 -0
- package/dist/components/artifacts/spreadsheet-general-display.d.ts +24 -0
- package/dist/components/artifacts/spreadsheet-grid.d.ts +11 -4
- package/dist/components/artifacts/spreadsheet-resize.d.ts +50 -0
- package/dist/components/artifacts/spreadsheet-submissions.d.ts +9 -0
- package/dist/components/artifacts/visualization-assets.gen.d.ts +2 -0
- package/dist/components/browser-select-control.d.ts +16 -0
- package/dist/components/browser-viewer.d.ts +11 -2
- package/dist/components/chat-composer.d.ts +21 -3
- package/dist/components/child-session-link.d.ts +5 -1
- package/dist/components/claude-mark.d.ts +3 -0
- package/dist/components/code-editor.d.ts +1 -4
- package/dist/components/command-palette.d.ts +1 -1
- package/dist/components/composer-transcription-control.d.ts +7 -0
- package/dist/components/composer.d.ts +30 -67
- package/dist/components/computer-viewer.d.ts +1 -1
- package/dist/components/copy-button.d.ts +3 -1
- package/dist/components/desktop-viewer.d.ts +1 -1
- package/dist/components/generated-video-player.d.ts +1 -1
- package/dist/components/grok-mark.d.ts +26 -0
- package/dist/components/human-input-form.d.ts +26 -32
- package/dist/components/human-input-surface.d.ts +5 -1
- package/dist/components/linkified-text.d.ts +18 -0
- package/dist/components/machine-input-display.d.ts +25 -3
- package/dist/components/machine-status-pill.d.ts +3 -2
- package/dist/components/machines/agent-status-icon.d.ts +6 -0
- package/dist/components/machines/health.d.ts +2 -1
- package/dist/components/machines/machine-detail.d.ts +7 -1
- package/dist/components/machines/machine-status.d.ts +49 -0
- package/dist/components/machines/metric-history-chart.d.ts +1 -1
- package/dist/components/machines/series.d.ts +3 -2
- package/dist/components/markdown-table-layout.d.ts +11 -2
- package/dist/components/markdown.d.ts +37 -4
- package/dist/components/message-timeline.d.ts +79 -7
- package/dist/components/model-mark.d.ts +29 -0
- package/dist/components/model-picker.d.ts +1 -1
- package/dist/components/model-policy-picker.d.ts +31 -22
- package/dist/components/new-conversation.d.ts +32 -0
- package/dist/components/open-geni-chat.d.ts +73 -0
- package/dist/components/open-geni-links.d.ts +69 -0
- package/dist/components/openrouter-mark.d.ts +6 -0
- package/dist/components/opper-mark.d.ts +7 -0
- package/dist/components/preview-loading.d.ts +2 -0
- package/dist/components/provider-recovery-notice.d.ts +17 -0
- package/dist/components/queue-item-content.d.ts +10 -0
- package/dist/components/rehype-secret-refs.d.ts +23 -0
- package/dist/components/remark-soft-line-breaks.d.ts +38 -0
- package/dist/components/sandbox-workspace.d.ts +18 -0
- package/dist/components/secret-question-field.d.ts +31 -0
- package/dist/components/secret-ref-chip.d.ts +35 -0
- package/dist/components/session-capability-frame.d.ts +37 -0
- package/dist/components/session-chrome.d.ts +20 -7
- package/dist/components/session-commands.d.ts +6 -0
- package/dist/components/session-connection-request.d.ts +8 -0
- package/dist/components/session-conversation.d.ts +147 -6
- package/dist/components/session-list.d.ts +39 -0
- package/dist/components/session-mcp-capability-card.d.ts +41 -0
- package/dist/components/session-proxy-scope.d.ts +35 -0
- package/dist/components/session-status.d.ts +6 -2
- package/dist/components/session-usage-limit-notice.d.ts +39 -0
- package/dist/components/this-computer/illustrations.d.ts +38 -0
- package/dist/components/this-computer/labels.d.ts +111 -0
- package/dist/components/this-computer/this-computer-card.d.ts +40 -0
- package/dist/components/this-computer/this-computer-setup.d.ts +35 -0
- package/dist/components/this-computer/this-computer-status.d.ts +42 -0
- package/dist/components/this-computer/use-this-computer.d.ts +29 -0
- package/dist/components/timeline-anchor.d.ts +3 -0
- package/dist/components/timeline-annotation-shared.d.ts +3 -2
- package/dist/components/timeline-annotations-dialog.d.ts +2 -1
- package/dist/components/timeline-annotations.d.ts +5 -1
- package/dist/components/timeline-reading-progress.d.ts +11 -0
- package/dist/components/timeline-search.d.ts +34 -0
- package/dist/components/timeline-settlement.d.ts +16 -0
- package/dist/components/tool-action-review.d.ts +48 -0
- package/dist/components/tool-review-history.d.ts +25 -0
- package/dist/components/usage-limit-notice.d.ts +50 -0
- package/dist/components/usage-member-list.d.ts +92 -0
- package/dist/components/usage-meter.d.ts +74 -0
- package/dist/components/use-viewer-menu-dismiss.d.ts +2 -0
- package/dist/components/user-message-body.d.ts +10 -1
- package/dist/components/workbench-changes.d.ts +2 -1
- package/dist/composer-messages.d.ts +75 -0
- package/dist/composer-messages.js +9 -0
- package/dist/composer-messages.js.map +1 -0
- package/dist/composer-voice-events.d.ts +8 -0
- package/dist/composer.d.ts +3 -3
- package/dist/composer.js +25 -12
- package/dist/computer-viewer-VOIOZGVZ.js +21 -0
- package/dist/computer-viewer-VOIOZGVZ.js.map +1 -0
- package/dist/connect-account-identity.d.ts +8 -0
- package/dist/connect-accounts.d.ts +15 -0
- package/dist/connect-chooser.d.ts +18 -0
- package/dist/connect-panel.d.ts +18 -0
- package/dist/connect-setup.d.ts +18 -0
- package/dist/connect.d.ts +21 -0
- package/dist/connect.js +2216 -0
- package/dist/connect.js.map +1 -0
- package/dist/connection-catalog.d.ts +38 -0
- package/dist/connection-discovery.d.ts +12 -0
- package/dist/connection-installed.d.ts +17 -0
- package/dist/connection-logo.d.ts +9 -0
- package/dist/connection-service-logo.d.ts +8 -0
- package/dist/connection-service-presentation.d.ts +13 -0
- package/dist/connection-skeleton.d.ts +5 -0
- package/dist/connection-type-picker.d.ts +6 -0
- package/dist/conversation-timeline.d.ts +1 -1
- package/dist/desktop.d.ts +7 -0
- package/dist/desktop.js +28 -0
- package/dist/desktop.js.map +1 -0
- package/dist/device-authorization.d.ts +23 -0
- package/dist/diffs.d.ts +8 -0
- package/dist/diffs.js +15 -0
- package/dist/diffs.js.map +1 -0
- package/dist/discovery-cache.d.ts +5 -0
- package/dist/editor.d.ts +7 -0
- package/dist/editor.js +23 -0
- package/dist/editor.js.map +1 -0
- package/dist/embedded-new-voice-KPLC5UJZ.js +19 -0
- package/dist/embedded-new-voice-KPLC5UJZ.js.map +1 -0
- package/dist/embedded-voice-V2RFSLIU.js +19 -0
- package/dist/embedded-voice-V2RFSLIU.js.map +1 -0
- package/dist/fleet-decision-row-FE73NSQ6.js +361 -0
- package/dist/fleet-decision-row-FE73NSQ6.js.map +1 -0
- package/dist/hooks/internal.d.ts +27 -2
- package/dist/hooks/latest-question.d.ts +26 -0
- package/dist/hooks/session-view-cache.d.ts +38 -0
- package/dist/hooks/shared-machines-list.d.ts +4 -0
- package/dist/hooks/shared-query.d.ts +123 -0
- package/dist/hooks/use-attached-browsers.d.ts +1 -1
- package/dist/hooks/use-auth-runs.d.ts +1 -4
- package/dist/hooks/use-available-models.d.ts +8 -3
- package/dist/hooks/use-browser-frame-stream.d.ts +1 -1
- package/dist/hooks/use-browser-session.d.ts +12 -1
- package/dist/hooks/use-client-config-flags.d.ts +49 -0
- package/dist/hooks/use-codex-accounts.d.ts +48 -9
- package/dist/hooks/use-composer.d.ts +24 -3
- package/dist/hooks/use-computer-frame-stream.d.ts +1 -1
- package/dist/hooks/use-computer-input-posture.d.ts +13 -0
- package/dist/hooks/use-computer-session.d.ts +5 -0
- package/dist/hooks/use-connect.d.ts +23 -0
- package/dist/hooks/use-desktop-stream.d.ts +1 -1
- package/dist/hooks/use-file-attachments.d.ts +4 -0
- package/dist/hooks/use-goal.d.ts +2 -1
- package/dist/hooks/use-last-started-turn-policy.d.ts +5 -1
- package/dist/hooks/use-machine-chip.d.ts +3 -2
- package/dist/hooks/use-new-conversation.d.ts +56 -0
- package/dist/hooks/use-new-session-draft.d.ts +74 -0
- package/dist/hooks/use-realtime-voice-models.d.ts +7 -0
- package/dist/hooks/use-sandbox-files.d.ts +3 -2
- package/dist/hooks/use-session-conversation.d.ts +49 -0
- package/dist/hooks/use-session-events.d.ts +21 -2
- package/dist/hooks/use-session-mcp-approval-policy.d.ts +2 -2
- package/dist/hooks/use-session-model-account.d.ts +48 -0
- package/dist/hooks/use-supergrok-accounts.d.ts +7 -1
- package/dist/hooks/use-terminal-stream.d.ts +11 -5
- package/dist/hooks/use-transcription.d.ts +2 -1
- package/dist/hooks/use-usage.d.ts +40 -0
- package/dist/hooks/use-vaults.d.ts +53 -0
- package/dist/hooks/use-voice-input.d.ts +8 -1
- package/dist/hooks/use-workspace-sessions.d.ts +24 -5
- package/dist/human-input-model.d.ts +123 -0
- package/dist/identity-link-accounts.d.ts +11 -0
- package/dist/identity-link-consent.d.ts +18 -0
- package/dist/index.d.ts +83 -18
- package/dist/index.js +2317 -6453
- package/dist/index.js.map +1 -1
- package/dist/interaction.d.ts +1 -1
- package/dist/interaction.js +20 -29
- package/dist/interaction.js.map +1 -1
- package/dist/latest-question-SXBXROBT.js +118 -0
- package/dist/latest-question-SXBXROBT.js.map +1 -0
- package/dist/lib/client-config-read.d.ts +31 -0
- package/dist/lib/clipboard.d.ts +7 -0
- package/dist/lib/error-message.d.ts +7 -0
- package/dist/lib/format.d.ts +59 -9
- package/dist/lib/host-theme.d.ts +77 -0
- package/dist/lib/interaction-errors.d.ts +3 -0
- package/dist/lib/menu-styles.d.ts +22 -0
- package/dist/lib/notify-observer.d.ts +2 -0
- package/dist/lib/pierre-diffs-loader.d.ts +20 -0
- package/dist/lib/provider-recovery.d.ts +56 -0
- package/dist/lib/scrollbars.d.ts +11 -0
- package/dist/lib/terminal-input-readiness.d.ts +11 -0
- package/dist/lib/transient-retry.d.ts +26 -0
- package/dist/lib/workbench-peers.d.ts +36 -0
- package/dist/lib/xterm-theme.d.ts +7 -5
- package/dist/machines.js +12 -6
- package/dist/{markdown-table-layout-3Z3AWBY7.js → markdown-table-layout-3PV2UAAH.js} +51 -9
- package/dist/markdown-table-layout-3PV2UAAH.js.map +1 -0
- package/dist/mcp-connection-status.d.ts +15 -0
- package/dist/messages/en.d.ts +3328 -0
- package/dist/messages/runtime.d.ts +69 -0
- package/dist/messages.d.ts +3 -0
- package/dist/messages.js +16 -0
- package/dist/messages.js.map +1 -0
- package/dist/model-mark-paths.d.ts +34 -0
- package/dist/model-mark-paths.js +16 -0
- package/dist/model-mark-paths.js.map +1 -0
- package/dist/model-picker-model.d.ts +112 -0
- package/dist/model-picker-model.js +25 -0
- package/dist/model-picker-model.js.map +1 -0
- package/dist/model-policy-picker-menu-NWIETWSR.js +18 -0
- package/dist/model-policy-picker-menu-NWIETWSR.js.map +1 -0
- package/dist/model-policy.d.ts +35 -10
- package/dist/model-policy.js +12 -1
- package/dist/native-previews.d.ts +29 -0
- package/dist/native-previews.js +82 -0
- package/dist/native-previews.js.map +1 -0
- package/dist/new-session-draft.d.ts +7 -0
- package/dist/new-session-draft.js +639 -0
- package/dist/new-session-draft.js.map +1 -0
- package/dist/notification-text.d.ts +27 -0
- package/dist/{noto-sans-arabic-loader-IA2T4X2A.js → noto-sans-arabic-loader-XSH2KYWJ.js} +3 -1
- package/dist/{noto-sans-arabic-loader-IA2T4X2A.js.map → noto-sans-arabic-loader-XSH2KYWJ.js.map} +1 -1
- package/dist/{noto-sans-jp-loader.generated-HFGLYBR3.js → noto-sans-jp-loader.generated-MR5L6V7K.js} +3 -1
- package/dist/{noto-sans-jp-loader.generated-HFGLYBR3.js.map → noto-sans-jp-loader.generated-MR5L6V7K.js.map} +1 -1
- package/dist/organization-model.d.ts +33 -0
- package/dist/organization-model.js +65 -0
- package/dist/organization-model.js.map +1 -0
- package/dist/platform-activity-row-VSQ2FZ5T.js +119 -0
- package/dist/platform-activity-row-VSQ2FZ5T.js.map +1 -0
- package/dist/plugin-details.d.ts +14 -0
- package/dist/plugin-discovery.d.ts +25 -0
- package/dist/preview-loading-paint.d.ts +20 -0
- package/dist/provider.d.ts +37 -2
- package/dist/queue-presentation-model.d.ts +73 -0
- package/dist/queue-presentation-model.js +38 -0
- package/dist/queue-presentation-model.js.map +1 -0
- package/dist/{queue-surface-implementation-LK3S4BIW.js → queue-surface-implementation-MEKXXWGR.js} +189 -343
- package/dist/queue-surface-implementation-MEKXXWGR.js.map +1 -0
- package/dist/realtime/embedded-new-voice.d.ts +1 -0
- package/dist/realtime/embedded-voice.d.ts +1 -0
- package/dist/realtime/realtime-control.d.ts +4 -65
- package/dist/realtime/session-realtime.d.ts +79 -0
- package/dist/realtime.js +26 -1333
- package/dist/realtime.js.map +1 -1
- package/dist/sandbox-files-5NRC2QUT.js +24 -0
- package/dist/sandbox-files-5NRC2QUT.js.map +1 -0
- package/dist/sandbox-label-model.d.ts +31 -0
- package/dist/sandbox-label-model.js +20 -0
- package/dist/sandbox-label-model.js.map +1 -0
- package/dist/scrollbars.d.ts +1 -0
- package/dist/scrollbars.js +10 -0
- package/dist/scrollbars.js.map +1 -0
- package/dist/secret-reference-label.d.ts +15 -0
- package/dist/secrets-ui.d.ts +57 -0
- package/dist/session-agents-model.d.ts +11 -0
- package/dist/session-agents-model.js +25 -0
- package/dist/session-agents-model.js.map +1 -0
- package/dist/session-attention-model.d.ts +8 -0
- package/dist/session-attention-model.js +47 -0
- package/dist/session-attention-model.js.map +1 -0
- package/dist/session-auth-recommendation.d.ts +6 -0
- package/dist/session-capability-policy.d.ts +32 -0
- package/dist/session-context.d.ts +9 -1
- package/dist/session-feedback-model.d.ts +21 -0
- package/dist/session-feedback-model.js +56 -0
- package/dist/session-feedback-model.js.map +1 -0
- package/dist/session-list-model.d.ts +139 -0
- package/dist/session-list-model.js +274 -0
- package/dist/session-list-model.js.map +1 -0
- package/dist/session-realtime-OZCE6IKP.js +22 -0
- package/dist/session-realtime-OZCE6IKP.js.map +1 -0
- package/dist/session-realtime.d.ts +7 -0
- package/dist/session-realtime.js +20 -0
- package/dist/session-realtime.js.map +1 -0
- package/dist/session-status-model.d.ts +37 -0
- package/dist/session-ui.d.ts +40 -3
- package/dist/session-ui.js +127 -21
- package/dist/session-ui.js.map +1 -1
- package/dist/session.d.ts +10 -2
- package/dist/session.js +44 -20
- package/dist/site-snapshot.d.ts +14 -0
- package/dist/sites-ui.d.ts +24 -0
- package/dist/sites.d.ts +3 -0
- package/dist/sites.js +15 -0
- package/dist/sites.js.map +1 -0
- package/dist/skill-discovery.d.ts +47 -0
- package/dist/terminal.d.ts +8 -0
- package/dist/terminal.js +33 -0
- package/dist/terminal.js.map +1 -0
- package/dist/testing/session-scenarios.d.ts +10 -0
- package/dist/testing/session-scenarios.js +367 -0
- package/dist/testing/session-scenarios.js.map +1 -0
- package/dist/this-computer.d.ts +8 -0
- package/dist/this-computer.js +1042 -0
- package/dist/this-computer.js.map +1 -0
- package/dist/timeline/activity-rail.d.ts +12 -2
- package/dist/timeline/agent-identity.d.ts +30 -0
- package/dist/timeline/agent-row.d.ts +31 -0
- package/dist/timeline/allowance-exhausted-row.d.ts +24 -0
- package/dist/timeline/compaction-copy.d.ts +47 -0
- package/dist/timeline/focus-sequence.d.ts +9 -0
- package/dist/timeline/genie-copy.d.ts +4 -0
- package/dist/timeline/genie-loading.d.ts +48 -0
- package/dist/timeline/index.d.ts +12 -5
- package/dist/timeline/invoked-tool.d.ts +6 -0
- package/dist/timeline/knowledge-receipt.d.ts +17 -0
- package/dist/timeline/learning-refusal-copy.d.ts +23 -0
- package/dist/timeline/learning-refusal-row.d.ts +19 -0
- package/dist/timeline/message-sender.d.ts +19 -0
- package/dist/timeline/notice-presentation.d.ts +14 -0
- package/dist/timeline/parsers.d.ts +11 -0
- package/dist/timeline/patch-apply-command.d.ts +19 -0
- package/dist/timeline/platform-activity-presentation.d.ts +26 -0
- package/dist/timeline/platform-activity-row.d.ts +1 -2
- package/dist/timeline/presented-image.d.ts +11 -0
- package/dist/timeline/projection.d.ts +32 -2
- package/dist/timeline/provider-logo.d.ts +15 -0
- package/dist/timeline/question-nav-model.d.ts +23 -0
- package/dist/timeline/registry.d.ts +10 -1
- package/dist/timeline/retained-image.d.ts +18 -0
- package/dist/timeline/retained-loaders.d.ts +27 -0
- package/dist/timeline/rolling-activity.d.ts +11 -0
- package/dist/timeline/screenshot-lightbox.d.ts +23 -1
- package/dist/timeline/session-usage-limit-row.d.ts +11 -0
- package/dist/timeline/shared.d.ts +8 -3
- package/dist/timeline/startup-dispatch-details.d.ts +5 -0
- package/dist/timeline/startup-preference.d.ts +3 -0
- package/dist/timeline/startup-timings.d.ts +4 -0
- package/dist/timeline/tool-display-name.d.ts +6 -2
- package/dist/timeline/tool-presentation.d.ts +185 -0
- package/dist/timeline/turn-summary-model.d.ts +102 -0
- package/dist/timeline/turn-summary.d.ts +20 -54
- package/dist/timeline/types.d.ts +184 -7
- package/dist/timeline/work-presentation.d.ts +61 -0
- package/dist/{timeline-annotation-markers-DRSTLEM6.js → timeline-annotation-markers-HYLRTT6S.js} +11 -6
- package/dist/timeline-annotation-markers-HYLRTT6S.js.map +1 -0
- package/dist/{timeline-annotation-selection-IHLUGVND.js → timeline-annotation-selection-LBKW5GHA.js} +15 -5
- package/dist/timeline-annotation-selection-LBKW5GHA.js.map +1 -0
- package/dist/{timeline-annotations-dialog-6Q53N5FG.js → timeline-annotations-dialog-JKVINC42.js} +34 -19
- package/dist/timeline-annotations-dialog-JKVINC42.js.map +1 -0
- package/dist/timeline-model.d.ts +29 -0
- package/dist/timeline-model.js +254 -0
- package/dist/timeline-model.js.map +1 -0
- package/dist/usage/allowance-copy.d.ts +26 -0
- package/dist/usage/session-usage-limit.d.ts +89 -0
- package/dist/usage/summary.d.ts +35 -0
- package/dist/usage.d.ts +17 -0
- package/dist/usage.js +1201 -0
- package/dist/usage.js.map +1 -0
- package/dist/voice-recording-owner.d.ts +7 -0
- package/package.json +119 -7
- package/src/approvals.ts +8 -1
- package/src/artifacts-spreadsheet.ts +1 -0
- package/src/artifacts.ts +41 -0
- package/src/assets/README.md +8 -0
- package/src/assets/gmail.ico +0 -0
- package/src/assets/outlook.ico +0 -0
- package/src/capability-catalog-row.tsx +96 -0
- package/src/capability-logo-fallback.ts +22 -0
- package/src/client.ts +18 -30
- package/src/commands/registry.ts +46 -36
- package/src/commands/types.ts +2 -0
- package/src/components/anthropic-mark.tsx +10 -0
- package/src/components/approval-surface.tsx +407 -142
- package/src/components/artifacts/artifact-chrome.tsx +425 -0
- package/src/components/artifacts/artifact-sandbox.tsx +193 -0
- package/src/components/artifacts/artifact-surface.tsx +48 -26
- package/src/components/artifacts/chat-interactive-block.tsx +260 -0
- package/src/components/artifacts/deferred-chat-media.tsx +72 -0
- package/src/components/artifacts/document-editor.tsx +193 -45
- package/src/components/artifacts/editable-artifact-ui.tsx +23 -11
- package/src/components/artifacts/editable-artifact-view.tsx +199 -0
- package/src/components/artifacts/editable-artifact-workbench.tsx +8 -3
- package/src/components/artifacts/editable-document.tsx +76 -54
- package/src/components/artifacts/editable-presentation.tsx +86 -40
- package/src/components/artifacts/editable-spreadsheet.tsx +581 -121
- package/src/components/artifacts/index.ts +42 -0
- package/src/components/artifacts/inline-html-document.ts +24 -0
- package/src/components/artifacts/latest-task-runner.ts +49 -0
- package/src/components/artifacts/presentation-editor.tsx +422 -122
- package/src/components/artifacts/published-html-artifact-frame.tsx +79 -265
- package/src/components/artifacts/session-artifact-viewer.tsx +381 -0
- package/src/components/artifacts/site-view.tsx +129 -0
- package/src/components/artifacts/spreadsheet-canvas.ts +5 -10
- package/src/components/artifacts/spreadsheet-command-queue.ts +190 -0
- package/src/components/artifacts/spreadsheet-download.tsx +117 -0
- package/src/components/artifacts/spreadsheet-general-display.ts +43 -0
- package/src/components/artifacts/spreadsheet-grid.tsx +390 -172
- package/src/components/artifacts/spreadsheet-resize.tsx +432 -0
- package/src/components/artifacts/spreadsheet-submissions.tsx +46 -0
- package/src/components/artifacts/visualization-assets/base.css +1015 -0
- package/src/components/artifacts/visualization-assets/helpers.html +349 -0
- package/src/components/artifacts/visualization-assets.gen.ts +3 -0
- package/src/components/browser-select-control.tsx +320 -0
- package/src/components/browser-viewer.tsx +1102 -505
- package/src/components/chat-composer.tsx +42 -3
- package/src/components/child-session-link.tsx +16 -5
- package/src/components/claude-mark.tsx +11 -0
- package/src/components/code-editor.tsx +38 -27
- package/src/components/command-palette.tsx +4 -1
- package/src/components/composer-transcription-control.tsx +151 -50
- package/src/components/composer.tsx +281 -176
- package/src/components/computer-viewer.tsx +1013 -341
- package/src/components/copy-button.tsx +17 -7
- package/src/components/desktop-viewer.tsx +42 -33
- package/src/components/diff-view.tsx +3 -1
- package/src/components/enrollment-consent.tsx +39 -34
- package/src/components/enrollment-device-flow.tsx +31 -19
- package/src/components/file-browser.tsx +47 -35
- package/src/components/fleet-tile.tsx +8 -4
- package/src/components/generated-video-player.tsx +10 -5
- package/src/components/grok-mark.tsx +34 -0
- package/src/components/human-input-form.tsx +438 -251
- package/src/components/human-input-surface.tsx +8 -0
- package/src/components/interaction-intervention-banner.tsx +15 -13
- package/src/components/linkified-text.tsx +79 -0
- package/src/components/machine-card.tsx +56 -89
- package/src/components/machine-dock-bar.tsx +10 -4
- package/src/components/machine-health-pill.tsx +4 -2
- package/src/components/machine-input-display.ts +309 -34
- package/src/components/machine-metrics.tsx +10 -7
- package/src/components/machine-status-pill.tsx +23 -15
- package/src/components/machines/agent-status-icon.tsx +31 -0
- package/src/components/machines/health.ts +53 -10
- package/src/components/machines/machine-detail.tsx +230 -42
- package/src/components/machines/machine-operation-policy.tsx +36 -29
- package/src/components/machines/machine-status.ts +264 -0
- package/src/components/machines/metric-history-chart.tsx +8 -2
- package/src/components/machines/series.ts +12 -11
- package/src/components/machines-dashboard.tsx +16 -9
- package/src/components/markdown-table-layout.ts +67 -9
- package/src/components/markdown.tsx +470 -133
- package/src/components/message-timeline.tsx +2290 -752
- package/src/components/model-mark.tsx +102 -0
- package/src/components/model-picker.tsx +27 -9
- package/src/components/model-policy-picker-menu.tsx +204 -100
- package/src/components/model-policy-picker.tsx +215 -152
- package/src/components/new-conversation.tsx +223 -0
- package/src/components/open-geni-chat.tsx +311 -0
- package/src/components/open-geni-links.tsx +183 -0
- package/src/components/openrouter-mark.tsx +13 -0
- package/src/components/opper-mark.tsx +18 -0
- package/src/components/pierre-diff.tsx +47 -19
- package/src/components/pierre-file.tsx +38 -11
- package/src/components/preview-loading.tsx +111 -0
- package/src/components/provider-recovery-notice.tsx +51 -0
- package/src/components/queue-item-content.ts +16 -0
- package/src/components/queue-surface-implementation.tsx +185 -420
- package/src/components/queue-surface-state.tsx +13 -8
- package/src/components/queue-surface.tsx +3 -1
- package/src/components/rehype-secret-refs.ts +98 -0
- package/src/components/remark-soft-line-breaks.ts +166 -0
- package/src/components/sandbox-files.tsx +75 -44
- package/src/components/sandbox-terminal.tsx +103 -22
- package/src/components/sandbox-workspace.tsx +168 -78
- package/src/components/secret-question-field.tsx +326 -0
- package/src/components/secret-ref-chip.tsx +187 -0
- package/src/components/session-capability-frame.tsx +203 -0
- package/src/components/session-chrome.tsx +559 -328
- package/src/components/session-commands-panel.tsx +34 -17
- package/src/components/session-commands.tsx +18 -0
- package/src/components/session-connection-request.tsx +99 -0
- package/src/components/session-conversation.tsx +853 -118
- package/src/components/session-list.tsx +259 -0
- package/src/components/session-mcp-capability-card.tsx +681 -0
- package/src/components/session-proxy-scope.tsx +160 -0
- package/src/components/session-status.tsx +35 -21
- package/src/components/session-usage-limit-notice.tsx +176 -0
- package/src/components/this-computer/illustrations.tsx +164 -0
- package/src/components/this-computer/labels.ts +234 -0
- package/src/components/this-computer/this-computer-card.tsx +203 -0
- package/src/components/this-computer/this-computer-setup.tsx +433 -0
- package/src/components/this-computer/this-computer-status.tsx +329 -0
- package/src/components/this-computer/use-this-computer.ts +183 -0
- package/src/components/timeline-anchor.tsx +43 -15
- package/src/components/timeline-annotation-chrome.tsx +33 -9
- package/src/components/timeline-annotation-markers.tsx +4 -2
- package/src/components/timeline-annotation-selection.tsx +11 -2
- package/src/components/timeline-annotation-shared.ts +9 -8
- package/src/components/timeline-annotations-dialog.tsx +30 -9
- package/src/components/timeline-annotations.tsx +24 -7
- package/src/components/timeline-reading-progress.ts +80 -0
- package/src/components/timeline-search.tsx +168 -0
- package/src/components/timeline-settlement.ts +60 -0
- package/src/components/tool-action-review.tsx +670 -0
- package/src/components/tool-review-history.tsx +88 -0
- package/src/components/usage-limit-notice.tsx +183 -0
- package/src/components/usage-member-list.tsx +797 -0
- package/src/components/usage-meter.tsx +386 -0
- package/src/components/use-viewer-menu-dismiss.ts +33 -0
- package/src/components/user-message-body.tsx +33 -2
- package/src/components/workbench-changes.tsx +28 -16
- package/src/components/workspace-dock.tsx +45 -13
- package/src/composer-messages.ts +153 -0
- package/src/composer-voice-events.ts +12 -0
- package/src/composer.ts +4 -0
- package/src/connect-account-identity.tsx +38 -0
- package/src/connect-accounts.tsx +233 -0
- package/src/connect-chooser.tsx +339 -0
- package/src/connect-panel.tsx +104 -0
- package/src/connect-setup.tsx +354 -0
- package/src/connect.ts +60 -0
- package/src/connection-assets.d.ts +4 -0
- package/src/connection-catalog.tsx +175 -0
- package/src/connection-discovery.tsx +251 -0
- package/src/connection-installed.tsx +56 -0
- package/src/connection-logo.tsx +37 -0
- package/src/connection-service-logo.tsx +55 -0
- package/src/connection-service-presentation.ts +46 -0
- package/src/connection-skeleton.tsx +16 -0
- package/src/connection-type-picker.tsx +38 -0
- package/src/conversation-timeline.ts +11 -2
- package/src/desktop.ts +24 -0
- package/src/device-authorization.tsx +111 -0
- package/src/diffs.ts +16 -0
- package/src/discovery-cache.ts +42 -0
- package/src/editor.ts +13 -0
- package/src/hooks/internal.ts +93 -10
- package/src/hooks/latest-question.ts +168 -0
- package/src/hooks/session-view-cache.ts +167 -0
- package/src/hooks/shared-machines-list.ts +34 -1
- package/src/hooks/shared-query.ts +744 -0
- package/src/hooks/use-attached-browsers.ts +1 -1
- package/src/hooks/use-auth-runs.ts +0 -27
- package/src/hooks/use-available-models.ts +20 -10
- package/src/hooks/use-browser-frame-stream.ts +23 -4
- package/src/hooks/use-browser-session.ts +684 -206
- package/src/hooks/use-browser-sessions.ts +32 -1
- package/src/hooks/use-client-config-flags.ts +102 -0
- package/src/hooks/use-codex-accounts.ts +216 -43
- package/src/hooks/use-composer.ts +240 -59
- package/src/hooks/use-computer-frame-stream.ts +29 -9
- package/src/hooks/use-computer-input-posture.ts +96 -0
- package/src/hooks/use-computer-session.ts +419 -100
- package/src/hooks/use-connect.ts +23 -0
- package/src/hooks/use-desktop-stream.ts +19 -28
- package/src/hooks/use-file-attachments.ts +19 -3
- package/src/hooks/use-goal.ts +172 -21
- package/src/hooks/use-human-input.ts +16 -2
- package/src/hooks/use-last-started-turn-policy.ts +37 -11
- package/src/hooks/use-machine-chip.ts +13 -8
- package/src/hooks/use-machines.ts +24 -10
- package/src/hooks/use-new-conversation.ts +377 -0
- package/src/hooks/use-new-session-draft.ts +813 -0
- package/src/hooks/use-realtime-voice-models.ts +46 -0
- package/src/hooks/use-sandbox-files.ts +22 -16
- package/src/hooks/use-session-background-commands.ts +2 -2
- package/src/hooks/use-session-capabilities.ts +3 -2
- package/src/hooks/use-session-conversation.ts +150 -0
- package/src/hooks/use-session-events.ts +403 -64
- package/src/hooks/use-session-lineage.ts +47 -9
- package/src/hooks/use-session-mcp-approval-policy.ts +13 -5
- package/src/hooks/use-session-model-account.ts +174 -0
- package/src/hooks/use-session.ts +19 -3
- package/src/hooks/use-slash-commands.ts +6 -11
- package/src/hooks/use-supergrok-accounts.ts +22 -8
- package/src/hooks/use-terminal-stream.ts +153 -27
- package/src/hooks/use-transcription.ts +45 -19
- package/src/hooks/use-turn-queue.ts +25 -5
- package/src/hooks/use-usage.ts +100 -0
- package/src/hooks/use-vaults.ts +153 -0
- package/src/hooks/use-video-artifact-playback.ts +1 -1
- package/src/hooks/use-voice-input.ts +127 -19
- package/src/hooks/use-workspace-capture.ts +3 -2
- package/src/hooks/use-workspace-sessions.ts +74 -7
- package/src/human-input-model.ts +374 -0
- package/src/identity-link-accounts.tsx +149 -0
- package/src/identity-link-consent.tsx +193 -0
- package/src/index.ts +282 -16
- package/src/interaction.ts +1 -0
- package/src/lib/client-config-read.ts +76 -0
- package/src/lib/clipboard.ts +29 -0
- package/src/lib/error-message.ts +37 -0
- package/src/lib/format.ts +231 -36
- package/src/lib/host-theme.ts +529 -0
- package/src/lib/interaction-errors.ts +15 -0
- package/src/lib/menu-styles.ts +44 -0
- package/src/lib/notify-observer.ts +15 -0
- package/src/lib/pierre-diffs-loader.ts +53 -0
- package/src/lib/provider-recovery.ts +255 -0
- package/src/lib/scrollbars.ts +30 -0
- package/src/lib/terminal-input-readiness.ts +51 -0
- package/src/lib/transient-retry.ts +101 -0
- package/src/lib/workbench-peers.ts +62 -0
- package/src/lib/xterm-theme.ts +23 -21
- package/src/mcp-connection-status.ts +39 -0
- package/src/messages/en.ts +3810 -0
- package/src/messages/runtime.tsx +175 -0
- package/src/messages.ts +19 -0
- package/src/model-mark-paths.ts +53 -0
- package/src/model-picker-model.ts +343 -0
- package/src/model-policy.ts +301 -79
- package/src/native-previews.ts +104 -0
- package/src/new-session-draft.ts +22 -0
- package/src/notification-text.ts +81 -0
- package/src/organization-model.ts +123 -0
- package/src/plugin-details.tsx +192 -0
- package/src/plugin-discovery.tsx +209 -0
- package/src/preview-loading-paint.ts +68 -0
- package/src/provider.tsx +105 -21
- package/src/queue-presentation-model.ts +475 -0
- package/src/realtime/dropdown-menu.tsx +19 -12
- package/src/realtime/embedded-new-voice.tsx +1 -0
- package/src/realtime/embedded-voice.tsx +3 -0
- package/src/realtime/realtime-control.tsx +240 -609
- package/src/realtime/session-realtime.ts +582 -0
- package/src/sandbox-label-model.ts +56 -0
- package/src/scrollbars.ts +3 -0
- package/src/secret-reference-label.ts +47 -0
- package/src/secrets-ui.tsx +59 -0
- package/src/session-agents-model.ts +40 -0
- package/src/session-attention-model.ts +62 -0
- package/src/session-auth-recommendation.ts +50 -0
- package/src/session-capability-policy.ts +200 -0
- package/src/session-context.ts +13 -5
- package/src/session-feedback-model.ts +101 -0
- package/src/session-list-model.ts +437 -0
- package/src/session-realtime.ts +18 -0
- package/src/session-status-model.ts +99 -0
- package/src/session-ui.ts +102 -3
- package/src/session.ts +19 -1
- package/src/site-snapshot.ts +74 -0
- package/src/sites-ui.tsx +350 -0
- package/src/sites.ts +3 -0
- package/src/skill-discovery.tsx +221 -0
- package/src/terminal.ts +26 -0
- package/src/testing/session-scenarios.ts +404 -0
- package/src/this-computer.ts +62 -0
- package/src/timeline/activity-rail.tsx +289 -119
- package/src/timeline/agent-identity.tsx +84 -0
- package/src/timeline/agent-row.tsx +235 -0
- package/src/timeline/allowance-exhausted-row.tsx +90 -0
- package/src/timeline/compaction-copy.ts +125 -0
- package/src/timeline/fleet-decision-row.tsx +120 -101
- package/src/timeline/focus-sequence.ts +44 -0
- package/src/timeline/genie-copy.ts +22 -0
- package/src/timeline/genie-loading.tsx +158 -0
- package/src/timeline/index.ts +37 -2
- package/src/timeline/invoked-tool.ts +15 -0
- package/src/timeline/knowledge-receipt.tsx +104 -0
- package/src/timeline/learning-refusal-copy.ts +67 -0
- package/src/timeline/learning-refusal-row.tsx +70 -0
- package/src/timeline/message-sender.tsx +71 -0
- package/src/timeline/notice-presentation.ts +67 -0
- package/src/timeline/parsers.ts +42 -2
- package/src/timeline/patch-apply-command.tsx +139 -0
- package/src/timeline/platform-activity-presentation.ts +219 -0
- package/src/timeline/platform-activity-row.tsx +34 -98
- package/src/timeline/presented-image.ts +63 -0
- package/src/timeline/projection.ts +1556 -71
- package/src/timeline/provider-logo.tsx +53 -0
- package/src/timeline/question-nav-model.ts +28 -0
- package/src/timeline/registry.ts +11 -1
- package/src/timeline/retained-image.ts +102 -0
- package/src/timeline/retained-loaders.ts +91 -0
- package/src/timeline/rolling-activity.tsx +84 -0
- package/src/timeline/screenshot-lightbox.tsx +250 -10
- package/src/timeline/session-usage-limit-row.tsx +44 -0
- package/src/timeline/shared.tsx +76 -29
- package/src/timeline/startup-dispatch-details.tsx +43 -0
- package/src/timeline/startup-preference.ts +33 -0
- package/src/timeline/startup-timings.tsx +164 -0
- package/src/timeline/tool-diff.tsx +3 -1
- package/src/timeline/tool-display-name.ts +38 -6
- package/src/timeline/tool-presentation.ts +1552 -0
- package/src/timeline/tool-renderers.tsx +1023 -1265
- package/src/timeline/turn-summary-model.ts +363 -0
- package/src/timeline/turn-summary.tsx +288 -367
- package/src/timeline/types.ts +191 -7
- package/src/timeline/work-presentation.ts +196 -0
- package/src/timeline-model.ts +143 -0
- package/src/usage/allowance-copy.ts +70 -0
- package/src/usage/session-usage-limit.ts +270 -0
- package/src/usage/summary.ts +93 -0
- package/src/usage.ts +70 -0
- package/src/voice-recording-owner.ts +22 -0
- package/styles/compiled.css +2010 -651
- package/styles/connect.css +290 -0
- package/styles/connect.d.ts +1 -0
- package/styles/effective-tokens.css +1 -0
- package/styles/index.css +286 -9
- package/styles/responsive.css +98 -6
- package/styles/session-capability.css +44 -0
- package/styles/this-computer.css +1042 -0
- package/styles/this-computer.d.ts +1 -0
- package/styles/tokens.css +132 -64
- package/dist/browser-viewer-NTD6UIPR.js +0 -14
- package/dist/chunk-24M4YBCL.js.map +0 -1
- package/dist/chunk-4MDLEHXL.js.map +0 -1
- package/dist/chunk-5M6VTFJ5.js.map +0 -1
- package/dist/chunk-5PQJOCX5.js +0 -902
- package/dist/chunk-5PQJOCX5.js.map +0 -1
- package/dist/chunk-5YK2ZDIG.js.map +0 -1
- package/dist/chunk-6J56T3MG.js.map +0 -1
- package/dist/chunk-BV5A4OTE.js.map +0 -1
- package/dist/chunk-CQG7YUJB.js +0 -10883
- package/dist/chunk-CQG7YUJB.js.map +0 -1
- package/dist/chunk-H5YGYNXS.js.map +0 -1
- package/dist/chunk-HUIKIDM5.js.map +0 -1
- package/dist/chunk-HUMIRRYI.js.map +0 -1
- package/dist/chunk-ICA6R6TW.js.map +0 -1
- package/dist/chunk-JVYQRRC4.js.map +0 -1
- package/dist/chunk-KCGXPP5V.js.map +0 -1
- package/dist/chunk-KZ73RL76.js.map +0 -1
- package/dist/chunk-NEXLLTP4.js.map +0 -1
- package/dist/chunk-NLTS7JHI.js.map +0 -1
- package/dist/chunk-NOSYBS2D.js.map +0 -1
- package/dist/chunk-PAJU5KKL.js.map +0 -1
- package/dist/chunk-PEI6RANI.js.map +0 -1
- package/dist/chunk-PLYRL5ER.js +0 -164
- package/dist/chunk-PLYRL5ER.js.map +0 -1
- package/dist/chunk-R4KRSFGA.js +0 -290
- package/dist/chunk-R4KRSFGA.js.map +0 -1
- package/dist/chunk-UMECRJRV.js +0 -223
- package/dist/chunk-UMECRJRV.js.map +0 -1
- package/dist/chunk-VRBL3F5E.js +0 -241
- package/dist/chunk-VRBL3F5E.js.map +0 -1
- package/dist/chunk-YBM6CQRU.js.map +0 -1
- package/dist/chunk-Z7WBDB4E.js.map +0 -1
- package/dist/computer-viewer-7TEZC6Y2.js +0 -16
- package/dist/fleet-decision-row-YZ3ZKWMM.js +0 -352
- package/dist/fleet-decision-row-YZ3ZKWMM.js.map +0 -1
- package/dist/hooks/use-environments.d.ts +0 -41
- package/dist/hooks/use-packs.d.ts +0 -32
- package/dist/markdown-table-layout-3Z3AWBY7.js.map +0 -1
- package/dist/model-policy-picker-menu-3R336DP2.js +0 -13
- package/dist/platform-activity-row-27LKAWZD.js +0 -169
- package/dist/platform-activity-row-27LKAWZD.js.map +0 -1
- package/dist/queue-surface-implementation-LK3S4BIW.js.map +0 -1
- package/dist/timeline-annotation-markers-DRSTLEM6.js.map +0 -1
- package/dist/timeline-annotation-selection-IHLUGVND.js.map +0 -1
- package/dist/timeline-annotations-dialog-6Q53N5FG.js.map +0 -1
- package/src/hooks/use-environments.ts +0 -182
- package/src/hooks/use-packs.ts +0 -157
- /package/dist/{browser-viewer-NTD6UIPR.js.map → browser-viewer-GEHX3KYE.js.map} +0 -0
- /package/dist/{computer-viewer-7TEZC6Y2.js.map → chat-interactive-block-5V3BGLXT.js.map} +0 -0
- /package/dist/{model-policy-picker-menu-3R336DP2.js.map → chunk-M357MHH3.js.map} +0 -0
|
@@ -0,0 +1,3237 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
buildTimeline,
|
|
4
|
+
groupTimeline,
|
|
5
|
+
sessionStatusFromEvents
|
|
6
|
+
} from "./chunk-QYUYVSNG.js";
|
|
7
|
+
import {
|
|
8
|
+
invalidateSharedQueries,
|
|
9
|
+
peekSharedQuery,
|
|
10
|
+
sharedQueryWriter,
|
|
11
|
+
useSharedQuery
|
|
12
|
+
} from "./chunk-WEY5J52U.js";
|
|
13
|
+
import {
|
|
14
|
+
cachedClientConfigRead,
|
|
15
|
+
joinClientConfigRead
|
|
16
|
+
} from "./chunk-IGVL3ELX.js";
|
|
17
|
+
import {
|
|
18
|
+
isActionableHumanInputRequest
|
|
19
|
+
} from "./chunk-IZV5FTJC.js";
|
|
20
|
+
import {
|
|
21
|
+
FILE_ONLY_MESSAGE_TEXT,
|
|
22
|
+
notifyObserver,
|
|
23
|
+
useComposer
|
|
24
|
+
} from "./chunk-RRAQ5FV5.js";
|
|
25
|
+
import {
|
|
26
|
+
coerceReasoningEffortForModel,
|
|
27
|
+
defaultEffortForModel,
|
|
28
|
+
projectPickerRows,
|
|
29
|
+
runnableLatencyModesForModel,
|
|
30
|
+
sortPickerRows
|
|
31
|
+
} from "./chunk-2ZUUIMBY.js";
|
|
32
|
+
import {
|
|
33
|
+
projectionReadThrough,
|
|
34
|
+
useDebouncedCallback,
|
|
35
|
+
useMutationRunner,
|
|
36
|
+
usePageLiveActivity,
|
|
37
|
+
usePolledValue,
|
|
38
|
+
useSessionEventTrigger
|
|
39
|
+
} from "./chunk-NAWXARTY.js";
|
|
40
|
+
import {
|
|
41
|
+
normalizeError,
|
|
42
|
+
useErrorMessage
|
|
43
|
+
} from "./chunk-CM7LVUKC.js";
|
|
44
|
+
import {
|
|
45
|
+
useEmbeddedFileAttachments,
|
|
46
|
+
useEmbeddedGoal,
|
|
47
|
+
useEmbeddedHumanInputSession,
|
|
48
|
+
useEmbeddedSession,
|
|
49
|
+
useEmbeddedSessionRead,
|
|
50
|
+
useOpenGeni,
|
|
51
|
+
useOpenGeniClient
|
|
52
|
+
} from "./chunk-ZGFU4LVW.js";
|
|
53
|
+
import {
|
|
54
|
+
useOpenGeniText
|
|
55
|
+
} from "./chunk-VU4QUISJ.js";
|
|
56
|
+
|
|
57
|
+
// src/approvals.ts
|
|
58
|
+
import {
|
|
59
|
+
parseToolDisplayMetadata
|
|
60
|
+
} from "@opengeni/sdk";
|
|
61
|
+
function approvalsFromRequiresAction(payload) {
|
|
62
|
+
const approvals = payload && typeof payload === "object" ? payload.approvals : void 0;
|
|
63
|
+
if (!Array.isArray(approvals)) {
|
|
64
|
+
return [];
|
|
65
|
+
}
|
|
66
|
+
return approvals.map((approval, index) => {
|
|
67
|
+
const raw = approval && typeof approval === "object" ? approval : {};
|
|
68
|
+
const rawItem = raw.rawItem && typeof raw.rawItem === "object" ? raw.rawItem : {};
|
|
69
|
+
const display = parseToolDisplayMetadata(raw.display);
|
|
70
|
+
return {
|
|
71
|
+
// Mirror the runtime's canonical interruption identity before retaining
|
|
72
|
+
// the legacy top-level callId fallback for already-normalized payloads.
|
|
73
|
+
id: String(rawItem.callId ?? rawItem.id ?? raw.id ?? raw.callId ?? raw.name ?? index),
|
|
74
|
+
name: String(raw.name ?? raw.toolName ?? rawItem.name ?? "approval"),
|
|
75
|
+
...display ? { display } : {},
|
|
76
|
+
arguments: raw.arguments ?? rawItem.arguments,
|
|
77
|
+
raw: approval
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function projectPendingApprovals(events) {
|
|
82
|
+
let pending = [];
|
|
83
|
+
let owningTurnId = null;
|
|
84
|
+
for (const event of events) {
|
|
85
|
+
switch (event.type) {
|
|
86
|
+
case "session.requiresAction": {
|
|
87
|
+
pending = approvalsFromRequiresAction(event.payload);
|
|
88
|
+
owningTurnId = event.turnId ?? null;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case "user.approvalDecision": {
|
|
92
|
+
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
93
|
+
if (typeof payload.approvalId === "string") {
|
|
94
|
+
pending = pending.filter((approval) => approval.id !== payload.approvalId);
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "turn.completed":
|
|
99
|
+
case "turn.failed":
|
|
100
|
+
case "turn.cancelled": {
|
|
101
|
+
if (owningTurnId === null || event.turnId == null || event.turnId === owningTurnId) {
|
|
102
|
+
pending = [];
|
|
103
|
+
owningTurnId = null;
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
default:
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return pending;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/older-history.ts
|
|
115
|
+
var activeReceiptCapture;
|
|
116
|
+
var preserveTailForAutomaticLoad = false;
|
|
117
|
+
function invokeOlderHistoryLoaderWithReceiptCapture(load, capture, preserveTail = false) {
|
|
118
|
+
const previousCapture = activeReceiptCapture;
|
|
119
|
+
const previousPreserveTail = preserveTailForAutomaticLoad;
|
|
120
|
+
activeReceiptCapture = capture;
|
|
121
|
+
preserveTailForAutomaticLoad = preserveTail;
|
|
122
|
+
try {
|
|
123
|
+
return load();
|
|
124
|
+
} finally {
|
|
125
|
+
activeReceiptCapture = previousCapture;
|
|
126
|
+
preserveTailForAutomaticLoad = previousPreserveTail;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function createOlderHistoryLoadReceipt(load) {
|
|
130
|
+
let resolveResult;
|
|
131
|
+
let rejectResult;
|
|
132
|
+
const result = new Promise((resolve, reject) => {
|
|
133
|
+
resolveResult = resolve;
|
|
134
|
+
rejectResult = reject;
|
|
135
|
+
});
|
|
136
|
+
result.committed = false;
|
|
137
|
+
result.tailPreserved = false;
|
|
138
|
+
activeReceiptCapture?.(result);
|
|
139
|
+
try {
|
|
140
|
+
const loaded = load(
|
|
141
|
+
() => {
|
|
142
|
+
result.committed = true;
|
|
143
|
+
},
|
|
144
|
+
preserveTailForAutomaticLoad,
|
|
145
|
+
() => {
|
|
146
|
+
result.tailPreserved = true;
|
|
147
|
+
}
|
|
148
|
+
);
|
|
149
|
+
Promise.resolve(loaded).then(resolveResult, rejectResult);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
rejectResult(error);
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// src/conversation-timeline.ts
|
|
157
|
+
function conversationTimeline(items, queue, composer) {
|
|
158
|
+
const queued = new Set(
|
|
159
|
+
queue.queue.filter((turn) => turn.metadata.delivery !== "steer").map((turn) => turn.triggerEventId)
|
|
160
|
+
);
|
|
161
|
+
const pending = composer.optimisticMessages ?? [];
|
|
162
|
+
const pendingQueue = new Set(
|
|
163
|
+
pending.filter(
|
|
164
|
+
(message) => message.destination === "queue" && !(message.turnId && message.appliedQueueVersion != null && queue.snapshot && queue.snapshot.version >= message.appliedQueueVersion && !queue.queue.some((turn) => turn.id === message.turnId))
|
|
165
|
+
).map((message) => `user-message:${message.clientEventId}`)
|
|
166
|
+
);
|
|
167
|
+
const visible = items.filter(
|
|
168
|
+
(item) => item.kind !== "user-message" || !queued.has(item.id) && !pendingQueue.has(item.reconciliationKey ?? "")
|
|
169
|
+
);
|
|
170
|
+
const keys = new Set(
|
|
171
|
+
visible.flatMap((item) => item.kind === "user-message" ? [item.reconciliationKey] : [])
|
|
172
|
+
);
|
|
173
|
+
const optimistic = pending.filter(
|
|
174
|
+
(message) => (message.destination === "chat" || message.state === "failed") && !keys.has(`user-message:${message.clientEventId}`) && !queue.queue.some((turn) => turn.id === message.turnId)
|
|
175
|
+
).map((message) => ({
|
|
176
|
+
kind: "user-message",
|
|
177
|
+
id: `optimistic:${message.clientEventId}`,
|
|
178
|
+
reconciliationKey: `user-message:${message.clientEventId}`,
|
|
179
|
+
text: message.text,
|
|
180
|
+
annotations: message.annotations.map((annotation, ordinal) => ({ ...annotation, ordinal })),
|
|
181
|
+
resources: message.resources,
|
|
182
|
+
tools: [],
|
|
183
|
+
occurredAt: message.occurredAt,
|
|
184
|
+
delivery: {
|
|
185
|
+
state: message.state,
|
|
186
|
+
...message.error ? { error: message.error } : {},
|
|
187
|
+
...message.state === "failed" ? {
|
|
188
|
+
...message.retryable !== false && composer.retryOptimisticMessage ? { onRetry: () => composer.retryOptimisticMessage?.(message.clientEventId) } : {},
|
|
189
|
+
...message.retryable === false && composer.restoreOptimisticMessage ? { onEdit: () => composer.restoreOptimisticMessage?.(message.clientEventId) } : {},
|
|
190
|
+
onRemove: () => composer.removeOptimisticMessage?.(message.clientEventId)
|
|
191
|
+
} : {}
|
|
192
|
+
}
|
|
193
|
+
}));
|
|
194
|
+
const ids = new Set(visible.map((item) => item.id));
|
|
195
|
+
const steers = (queue.acceptedSteers ?? []).filter((steer) => !ids.has(steer.triggerEventId)).map((steer) => ({
|
|
196
|
+
kind: "user-message",
|
|
197
|
+
id: steer.triggerEventId,
|
|
198
|
+
text: steer.text,
|
|
199
|
+
annotations: steer.annotations,
|
|
200
|
+
resources: steer.resources,
|
|
201
|
+
tools: steer.tools,
|
|
202
|
+
occurredAt: steer.occurredAt,
|
|
203
|
+
delivery: { state: steer.state }
|
|
204
|
+
}));
|
|
205
|
+
return [...visible, ...optimistic, ...steers];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/hooks/use-available-models.ts
|
|
209
|
+
import { useCallback } from "react";
|
|
210
|
+
function useAvailableModels(options = {}) {
|
|
211
|
+
const client = useOpenGeniClient(options);
|
|
212
|
+
const load = useCallback(
|
|
213
|
+
async (signal) => await client.getClientConfig({ signal }),
|
|
214
|
+
[client]
|
|
215
|
+
);
|
|
216
|
+
const state = useSharedQuery(client, ["available-models"], load, {
|
|
217
|
+
pollIntervalMs: options.pollIntervalMs,
|
|
218
|
+
enabled: options.enabled
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
models: state.data?.models ?? [],
|
|
222
|
+
defaultModel: state.data?.defaultModel ?? null,
|
|
223
|
+
loading: state.loading,
|
|
224
|
+
error: state.error,
|
|
225
|
+
refresh: state.refresh
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function useWorkspaceModelCatalog(options) {
|
|
229
|
+
const t = useOpenGeniText();
|
|
230
|
+
const client = useOpenGeniClient(options);
|
|
231
|
+
const load = useCallback(
|
|
232
|
+
async (signal) => {
|
|
233
|
+
if (!options.workspaceId) {
|
|
234
|
+
return { models: [], defaultModel: null };
|
|
235
|
+
}
|
|
236
|
+
const [catalog, config] = await Promise.all([
|
|
237
|
+
client.getWorkspaceModelCatalog(options.workspaceId, { signal }),
|
|
238
|
+
// Joins the same workspace's config read already in flight (for
|
|
239
|
+
// example the composer's voice availability).
|
|
240
|
+
joinClientConfigRead(client, options.workspaceId)
|
|
241
|
+
]);
|
|
242
|
+
return {
|
|
243
|
+
models: catalog.models,
|
|
244
|
+
defaultModel: config.defaultModel
|
|
245
|
+
};
|
|
246
|
+
},
|
|
247
|
+
[client, options.workspaceId]
|
|
248
|
+
);
|
|
249
|
+
const state = useSharedQuery(client, ["workspace-model-catalog", options.workspaceId], load, {
|
|
250
|
+
pollIntervalMs: options.pollIntervalMs,
|
|
251
|
+
enabled: options.enabled !== false && Boolean(options.workspaceId)
|
|
252
|
+
});
|
|
253
|
+
const rows = sortPickerRows(projectPickerRows(t, state.data?.models ?? []));
|
|
254
|
+
return {
|
|
255
|
+
models: state.data?.models ?? [],
|
|
256
|
+
rows,
|
|
257
|
+
defaultModel: state.data?.defaultModel ?? null,
|
|
258
|
+
loading: state.loading,
|
|
259
|
+
error: state.error,
|
|
260
|
+
refresh: state.refresh
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// src/hooks/use-file-attachments.ts
|
|
265
|
+
import { useCallback as useCallback2, useEffect, useRef, useState } from "react";
|
|
266
|
+
var isImage = (file) => file.type.startsWith("image/");
|
|
267
|
+
var fallbackAttachmentId = 0;
|
|
268
|
+
function createAttachmentId() {
|
|
269
|
+
const cryptoSource = globalThis.crypto;
|
|
270
|
+
if (typeof cryptoSource?.randomUUID === "function") return cryptoSource.randomUUID();
|
|
271
|
+
fallbackAttachmentId += 1;
|
|
272
|
+
return `attachment:${Date.now().toString(36)}:${fallbackAttachmentId.toString(36)}`;
|
|
273
|
+
}
|
|
274
|
+
function secureContextRequiredErrorCode(error) {
|
|
275
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === "secure_context_required" ? error.code : void 0;
|
|
276
|
+
}
|
|
277
|
+
function useFileAttachments(options = {}) {
|
|
278
|
+
const { client, workspaceId } = useEmbeddedFileAttachments(options);
|
|
279
|
+
const formatError = useErrorMessage();
|
|
280
|
+
const pasteFilter = options.pasteFilter ?? isImage;
|
|
281
|
+
const [attachments, setAttachments] = useState([]);
|
|
282
|
+
const attachmentsRef = useRef(attachments);
|
|
283
|
+
attachmentsRef.current = attachments;
|
|
284
|
+
const sources = useRef(/* @__PURE__ */ new Map());
|
|
285
|
+
const previewUrls = useRef(/* @__PURE__ */ new Map());
|
|
286
|
+
const previewRetainers = useRef(/* @__PURE__ */ new Map());
|
|
287
|
+
const pendingPreviewRevocations = useRef(/* @__PURE__ */ new Set());
|
|
288
|
+
const revokePreview = useCallback2((id) => {
|
|
289
|
+
const previewUrl = previewUrls.current.get(id);
|
|
290
|
+
if (!previewUrl) return;
|
|
291
|
+
if ((previewRetainers.current.get(id) ?? 0) > 0) {
|
|
292
|
+
pendingPreviewRevocations.current.add(id);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
previewUrls.current.delete(id);
|
|
296
|
+
pendingPreviewRevocations.current.delete(id);
|
|
297
|
+
URL.revokeObjectURL(previewUrl);
|
|
298
|
+
}, []);
|
|
299
|
+
const revokeAllPreviews = useCallback2(() => {
|
|
300
|
+
for (const id of previewUrls.current.keys()) revokePreview(id);
|
|
301
|
+
}, [revokePreview]);
|
|
302
|
+
const retainPreview = useCallback2(
|
|
303
|
+
(id) => {
|
|
304
|
+
if (!previewUrls.current.has(id)) return void 0;
|
|
305
|
+
previewRetainers.current.set(id, (previewRetainers.current.get(id) ?? 0) + 1);
|
|
306
|
+
let released = false;
|
|
307
|
+
return () => {
|
|
308
|
+
if (released) return;
|
|
309
|
+
released = true;
|
|
310
|
+
const remaining = (previewRetainers.current.get(id) ?? 1) - 1;
|
|
311
|
+
if (remaining > 0) {
|
|
312
|
+
previewRetainers.current.set(id, remaining);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
previewRetainers.current.delete(id);
|
|
316
|
+
if (pendingPreviewRevocations.current.has(id)) revokePreview(id);
|
|
317
|
+
};
|
|
318
|
+
},
|
|
319
|
+
[revokePreview]
|
|
320
|
+
);
|
|
321
|
+
const committedAttachmentIds = useRef(/* @__PURE__ */ new Set());
|
|
322
|
+
useEffect(() => {
|
|
323
|
+
const currentIds = new Set(attachments.map((attachment) => attachment.id));
|
|
324
|
+
for (const id of committedAttachmentIds.current) {
|
|
325
|
+
if (!currentIds.has(id)) revokePreview(id);
|
|
326
|
+
}
|
|
327
|
+
committedAttachmentIds.current = currentIds;
|
|
328
|
+
}, [attachments, revokePreview]);
|
|
329
|
+
const scopeGeneration = useRef(0);
|
|
330
|
+
const previousScope = useRef({ client, workspaceId });
|
|
331
|
+
useEffect(() => {
|
|
332
|
+
const previous = previousScope.current;
|
|
333
|
+
if (previous.client === client && previous.workspaceId === workspaceId) return;
|
|
334
|
+
previousScope.current = { client, workspaceId };
|
|
335
|
+
scopeGeneration.current += 1;
|
|
336
|
+
sources.current.clear();
|
|
337
|
+
revokeAllPreviews();
|
|
338
|
+
setAttachments([]);
|
|
339
|
+
}, [client, revokeAllPreviews, workspaceId]);
|
|
340
|
+
useEffect(
|
|
341
|
+
() => () => {
|
|
342
|
+
scopeGeneration.current += 1;
|
|
343
|
+
sources.current.clear();
|
|
344
|
+
revokeAllPreviews();
|
|
345
|
+
},
|
|
346
|
+
[revokeAllPreviews]
|
|
347
|
+
);
|
|
348
|
+
const startUpload = useCallback2(
|
|
349
|
+
(id, file) => {
|
|
350
|
+
const generation = scopeGeneration.current;
|
|
351
|
+
void client.uploadFile(workspaceId, {
|
|
352
|
+
filename: file.name || "file",
|
|
353
|
+
contentType: file.type || "application/octet-stream",
|
|
354
|
+
data: file,
|
|
355
|
+
...options.scope ? { scope: options.scope } : {}
|
|
356
|
+
}).then((asset) => {
|
|
357
|
+
if (scopeGeneration.current !== generation) return;
|
|
358
|
+
sources.current.delete(id);
|
|
359
|
+
setAttachments(
|
|
360
|
+
(current) => current.map(
|
|
361
|
+
(attachment) => attachment.id === id ? {
|
|
362
|
+
...attachment,
|
|
363
|
+
status: "ready",
|
|
364
|
+
file: asset,
|
|
365
|
+
name: asset.filename,
|
|
366
|
+
contentType: asset.contentType,
|
|
367
|
+
sizeBytes: asset.sizeBytes,
|
|
368
|
+
errorCode: void 0,
|
|
369
|
+
error: void 0,
|
|
370
|
+
errorCause: void 0
|
|
371
|
+
} : attachment
|
|
372
|
+
)
|
|
373
|
+
);
|
|
374
|
+
}).catch((error) => {
|
|
375
|
+
if (scopeGeneration.current !== generation) return;
|
|
376
|
+
setAttachments(
|
|
377
|
+
(current) => current.map(
|
|
378
|
+
(attachment) => attachment.id === id ? {
|
|
379
|
+
...attachment,
|
|
380
|
+
status: "failed",
|
|
381
|
+
errorCode: secureContextRequiredErrorCode(error),
|
|
382
|
+
error: formatError(error),
|
|
383
|
+
errorCause: error
|
|
384
|
+
} : attachment
|
|
385
|
+
)
|
|
386
|
+
);
|
|
387
|
+
});
|
|
388
|
+
},
|
|
389
|
+
[client, workspaceId, options.scope, formatError]
|
|
390
|
+
);
|
|
391
|
+
const addFiles = useCallback2(
|
|
392
|
+
(files) => {
|
|
393
|
+
for (const file of files) {
|
|
394
|
+
const id = createAttachmentId();
|
|
395
|
+
sources.current.set(id, file);
|
|
396
|
+
const previewUrl = isImage(file) ? URL.createObjectURL(file) : void 0;
|
|
397
|
+
if (previewUrl) previewUrls.current.set(id, previewUrl);
|
|
398
|
+
setAttachments((current) => [
|
|
399
|
+
...current,
|
|
400
|
+
{
|
|
401
|
+
id,
|
|
402
|
+
name: file.name || "image",
|
|
403
|
+
contentType: file.type || "application/octet-stream",
|
|
404
|
+
sizeBytes: file.size,
|
|
405
|
+
status: "uploading",
|
|
406
|
+
...previewUrl ? { previewUrl } : {}
|
|
407
|
+
}
|
|
408
|
+
]);
|
|
409
|
+
startUpload(id, file);
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
[startUpload]
|
|
413
|
+
);
|
|
414
|
+
const retry = useCallback2(
|
|
415
|
+
(id) => {
|
|
416
|
+
const file = sources.current.get(id);
|
|
417
|
+
if (!file) {
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
setAttachments(
|
|
421
|
+
(current) => current.map(
|
|
422
|
+
(attachment) => attachment.id === id ? {
|
|
423
|
+
...attachment,
|
|
424
|
+
status: "uploading",
|
|
425
|
+
errorCode: void 0,
|
|
426
|
+
error: void 0,
|
|
427
|
+
errorCause: void 0
|
|
428
|
+
} : attachment
|
|
429
|
+
)
|
|
430
|
+
);
|
|
431
|
+
startUpload(id, file);
|
|
432
|
+
},
|
|
433
|
+
[startUpload]
|
|
434
|
+
);
|
|
435
|
+
const addFromPaste = useCallback2(
|
|
436
|
+
(event) => {
|
|
437
|
+
const clipboardFiles = event.clipboardData?.files;
|
|
438
|
+
if (!clipboardFiles) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const files = [...clipboardFiles].filter(pasteFilter);
|
|
442
|
+
if (files.length > 0) {
|
|
443
|
+
addFiles(files);
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
[addFiles, pasteFilter]
|
|
447
|
+
);
|
|
448
|
+
const restoreReadyFiles = useCallback2(
|
|
449
|
+
(files) => {
|
|
450
|
+
const incoming = /* @__PURE__ */ new Map();
|
|
451
|
+
for (const file of files) {
|
|
452
|
+
if (file.status === "ready" && file.workspaceId === workspaceId) {
|
|
453
|
+
incoming.set(file.id, file);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
setAttachments((current) => {
|
|
457
|
+
const unresolved = current.filter((attachment) => attachment.status !== "ready");
|
|
458
|
+
const existingReady = new Map(
|
|
459
|
+
current.flatMap(
|
|
460
|
+
(attachment) => attachment.status === "ready" && attachment.file ? [[attachment.file.id, attachment]] : []
|
|
461
|
+
)
|
|
462
|
+
);
|
|
463
|
+
const restored = [...incoming.values()].map((file) => {
|
|
464
|
+
const existing = existingReady.get(file.id);
|
|
465
|
+
return existing ? {
|
|
466
|
+
...existing,
|
|
467
|
+
name: file.filename,
|
|
468
|
+
contentType: file.contentType,
|
|
469
|
+
sizeBytes: file.sizeBytes,
|
|
470
|
+
status: "ready",
|
|
471
|
+
file,
|
|
472
|
+
errorCode: void 0,
|
|
473
|
+
error: void 0,
|
|
474
|
+
errorCause: void 0
|
|
475
|
+
} : {
|
|
476
|
+
id: `restored:${file.id}`,
|
|
477
|
+
name: file.filename,
|
|
478
|
+
contentType: file.contentType,
|
|
479
|
+
sizeBytes: file.sizeBytes,
|
|
480
|
+
status: "ready",
|
|
481
|
+
file
|
|
482
|
+
// No source File and no object URL: server metadata is the
|
|
483
|
+
// only authority restored across page/device boundaries.
|
|
484
|
+
};
|
|
485
|
+
});
|
|
486
|
+
return [...unresolved, ...restored];
|
|
487
|
+
});
|
|
488
|
+
},
|
|
489
|
+
[workspaceId]
|
|
490
|
+
);
|
|
491
|
+
const loadPreview = useCallback2(
|
|
492
|
+
async (id, signal) => {
|
|
493
|
+
const generation = scopeGeneration.current;
|
|
494
|
+
const attachment = attachmentsRef.current.find((candidate) => candidate.id === id);
|
|
495
|
+
const createDownloadUrl = client.createFileDownloadUrl;
|
|
496
|
+
if (!attachment || attachment.status !== "ready" || !attachment.file || !attachment.contentType.startsWith("image/") || typeof createDownloadUrl !== "function" || signal?.aborted) {
|
|
497
|
+
return void 0;
|
|
498
|
+
}
|
|
499
|
+
const fileId = attachment.file.id;
|
|
500
|
+
const signed = await createDownloadUrl.call(client, workspaceId, fileId, { signal });
|
|
501
|
+
if (scopeGeneration.current !== generation || signal?.aborted) return void 0;
|
|
502
|
+
const current = attachmentsRef.current.find((candidate) => candidate.id === id);
|
|
503
|
+
if (current?.status !== "ready" || current.file?.id !== fileId) return void 0;
|
|
504
|
+
return signed.url;
|
|
505
|
+
},
|
|
506
|
+
[client, workspaceId]
|
|
507
|
+
);
|
|
508
|
+
const remove = useCallback2(
|
|
509
|
+
(id) => {
|
|
510
|
+
sources.current.delete(id);
|
|
511
|
+
revokePreview(id);
|
|
512
|
+
setAttachments((current) => current.filter((attachment) => attachment.id !== id));
|
|
513
|
+
},
|
|
514
|
+
[revokePreview]
|
|
515
|
+
);
|
|
516
|
+
const removeReadyFiles = useCallback2((fileIds) => {
|
|
517
|
+
const accepted = new Set(fileIds);
|
|
518
|
+
if (accepted.size === 0) return;
|
|
519
|
+
setAttachments(
|
|
520
|
+
(current) => current.filter((attachment) => {
|
|
521
|
+
return !(attachment.status === "ready" && attachment.file !== void 0 && accepted.has(attachment.file.id));
|
|
522
|
+
})
|
|
523
|
+
);
|
|
524
|
+
}, []);
|
|
525
|
+
const clear = useCallback2(() => {
|
|
526
|
+
sources.current.clear();
|
|
527
|
+
revokeAllPreviews();
|
|
528
|
+
setAttachments([]);
|
|
529
|
+
}, [revokeAllPreviews]);
|
|
530
|
+
return {
|
|
531
|
+
attachments,
|
|
532
|
+
readyResources: attachments.flatMap(
|
|
533
|
+
(attachment) => attachment.status === "ready" && attachment.file ? [{ kind: "file", fileId: attachment.file.id }] : []
|
|
534
|
+
),
|
|
535
|
+
uploading: attachments.some((attachment) => attachment.status === "uploading"),
|
|
536
|
+
hasUnresolved: attachments.some((attachment) => attachment.status !== "ready"),
|
|
537
|
+
addFiles,
|
|
538
|
+
addFromPaste,
|
|
539
|
+
restoreReadyFiles,
|
|
540
|
+
...typeof client.createFileDownloadUrl === "function" ? { loadPreview } : {},
|
|
541
|
+
retry,
|
|
542
|
+
retainPreview,
|
|
543
|
+
remove,
|
|
544
|
+
removeReadyFiles,
|
|
545
|
+
clear
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
// src/hooks/use-human-input.ts
|
|
550
|
+
import { useCallback as useCallback3, useEffect as useEffect3, useRef as useRef3, useState as useState2 } from "react";
|
|
551
|
+
|
|
552
|
+
// src/hooks/session-view-cache.ts
|
|
553
|
+
import { OpenGeniApiError } from "@opengeni/sdk";
|
|
554
|
+
import { useEffect as useEffect2, useLayoutEffect, useMemo, useRef as useRef2 } from "react";
|
|
555
|
+
var SESSION_VIEW_ROOT = "session-view";
|
|
556
|
+
var retainedByClient = /* @__PURE__ */ new WeakMap();
|
|
557
|
+
function viewKey(workspaceId, sessionId) {
|
|
558
|
+
return `${workspaceId}\0${sessionId}`;
|
|
559
|
+
}
|
|
560
|
+
function peekSessionView(client, workspaceId, sessionId, part) {
|
|
561
|
+
return peekSharedQuery(client, [SESSION_VIEW_ROOT, workspaceId, sessionId, part])?.data ?? null;
|
|
562
|
+
}
|
|
563
|
+
function recordSessionView(client, write, workspaceId, sessionId, part, value, bytes, budgetBytes) {
|
|
564
|
+
if (!write([SESSION_VIEW_ROOT, workspaceId, sessionId, part], value)) return;
|
|
565
|
+
let retained = retainedByClient.get(client);
|
|
566
|
+
if (!retained) {
|
|
567
|
+
retained = { order: /* @__PURE__ */ new Map() };
|
|
568
|
+
retainedByClient.set(client, retained);
|
|
569
|
+
}
|
|
570
|
+
const key = viewKey(workspaceId, sessionId);
|
|
571
|
+
const previous = retained.order.get(key);
|
|
572
|
+
retained.order.delete(key);
|
|
573
|
+
retained.order.set(key, {
|
|
574
|
+
workspaceId,
|
|
575
|
+
sessionId,
|
|
576
|
+
bytes: part === "events" ? bytes : previous?.bytes ?? 0
|
|
577
|
+
});
|
|
578
|
+
let total = 0;
|
|
579
|
+
for (const entry of retained.order.values()) total += entry.bytes;
|
|
580
|
+
for (const [oldestKey, oldest] of retained.order) {
|
|
581
|
+
if (total <= budgetBytes || oldestKey === key) break;
|
|
582
|
+
retained.order.delete(oldestKey);
|
|
583
|
+
total -= oldest.bytes;
|
|
584
|
+
void invalidateSharedQueries(client, [SESSION_VIEW_ROOT, oldest.workspaceId, oldest.sessionId]);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
function deniesRetainedView(error) {
|
|
588
|
+
return error instanceof OpenGeniApiError && (error.status === 401 || error.status === 403 || error.status === 404);
|
|
589
|
+
}
|
|
590
|
+
function useRetainedSessionView(client, workspaceId, sessionId, part, current, options) {
|
|
591
|
+
const enabled = options.enabled && Boolean(sessionId);
|
|
592
|
+
const discard = options.discard === true;
|
|
593
|
+
const retained = useMemo(
|
|
594
|
+
() => enabled && sessionId ? peekSessionView(client, workspaceId, sessionId, part) : null,
|
|
595
|
+
[client, enabled, part, sessionId, workspaceId]
|
|
596
|
+
);
|
|
597
|
+
const target = enabled && sessionId ? `${viewKey(workspaceId, sessionId)}\0${part}` : null;
|
|
598
|
+
const box = useRef2(null);
|
|
599
|
+
const bytesRef = useRef2(options.bytes);
|
|
600
|
+
const budgetBytes = options.budgetBytes ?? Number.POSITIVE_INFINITY;
|
|
601
|
+
useLayoutEffect(() => {
|
|
602
|
+
bytesRef.current = options.bytes;
|
|
603
|
+
if (box.current && box.current.target === target) {
|
|
604
|
+
box.current.value = current;
|
|
605
|
+
box.current.discard = discard;
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
useEffect2(() => {
|
|
609
|
+
if (!discard || !enabled || !sessionId) return;
|
|
610
|
+
void invalidateSharedQueries(client, [SESSION_VIEW_ROOT, workspaceId, sessionId, part]);
|
|
611
|
+
}, [client, discard, enabled, part, sessionId, workspaceId]);
|
|
612
|
+
useEffect2(() => {
|
|
613
|
+
if (!target || !sessionId) return;
|
|
614
|
+
const write = sharedQueryWriter(client);
|
|
615
|
+
const owned = { target, value: current, discard };
|
|
616
|
+
box.current = owned;
|
|
617
|
+
return () => {
|
|
618
|
+
if (box.current === owned) box.current = null;
|
|
619
|
+
const value = owned.value;
|
|
620
|
+
if (owned.discard) {
|
|
621
|
+
void invalidateSharedQueries(client, [SESSION_VIEW_ROOT, workspaceId, sessionId, part]);
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
if (value === null) return;
|
|
625
|
+
recordSessionView(
|
|
626
|
+
client,
|
|
627
|
+
write,
|
|
628
|
+
workspaceId,
|
|
629
|
+
sessionId,
|
|
630
|
+
part,
|
|
631
|
+
value,
|
|
632
|
+
bytesRef.current?.(value) ?? 0,
|
|
633
|
+
budgetBytes
|
|
634
|
+
);
|
|
635
|
+
};
|
|
636
|
+
}, [budgetBytes, client, part, sessionId, target, workspaceId]);
|
|
637
|
+
const dropped = useRef2(null);
|
|
638
|
+
if (discard && target) dropped.current = target;
|
|
639
|
+
return discard || target !== null && dropped.current === target ? null : retained;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// src/hooks/use-human-input.ts
|
|
643
|
+
function isHumanInputEvent(event) {
|
|
644
|
+
return event.type === "session.humanInput.requested" || event.type === "user.humanInputResponse" || event.type === "turn.completed" || event.type === "turn.failed" || event.type === "turn.cancelled";
|
|
645
|
+
}
|
|
646
|
+
function useHumanInputRequests(sessionId, options = {}) {
|
|
647
|
+
const { client, workspaceId, registerSessionReconciler } = useEmbeddedHumanInputSession(options);
|
|
648
|
+
const enabled = (options.enabled ?? true) && Boolean(sessionId);
|
|
649
|
+
const load = useCallback3(
|
|
650
|
+
async () => sessionId ? await client.listHumanInputRequests(workspaceId, sessionId, { status: "pending" }) : [],
|
|
651
|
+
[client, sessionId, workspaceId]
|
|
652
|
+
);
|
|
653
|
+
const state = usePolledValue(load, {
|
|
654
|
+
enabled,
|
|
655
|
+
pollIntervalMs: options.pollIntervalMs
|
|
656
|
+
});
|
|
657
|
+
const loadedRequests = state.data;
|
|
658
|
+
const refreshRequests = state.refresh;
|
|
659
|
+
const mutation = useMutationRunner(`${workspaceId}\0${sessionId ?? ""}`);
|
|
660
|
+
const [respondingRequestId, setRespondingRequestId] = useState2(null);
|
|
661
|
+
const [deadlineVersion, setDeadlineVersion] = useState2(0);
|
|
662
|
+
const respondingRequestRef = useRef3(null);
|
|
663
|
+
useEffect3(() => {
|
|
664
|
+
respondingRequestRef.current = null;
|
|
665
|
+
setRespondingRequestId(null);
|
|
666
|
+
}, [sessionId, workspaceId]);
|
|
667
|
+
useEffect3(() => {
|
|
668
|
+
if (!sessionId || !enabled) return;
|
|
669
|
+
return registerSessionReconciler(sessionId, "human-input", state.refresh);
|
|
670
|
+
}, [enabled, registerSessionReconciler, sessionId, state.refresh]);
|
|
671
|
+
const scheduleRefresh = useDebouncedCallback(() => void state.refresh());
|
|
672
|
+
useSessionEventTrigger(client, workspaceId, sessionId, isHumanInputEvent, scheduleRefresh, {
|
|
673
|
+
enabled,
|
|
674
|
+
...options.events !== void 0 ? { events: options.events } : {},
|
|
675
|
+
readThrough: projectionReadThrough(state.data, state.loading),
|
|
676
|
+
refresh: scheduleRefresh
|
|
677
|
+
});
|
|
678
|
+
const retainedRequests = useRetainedSessionView(
|
|
679
|
+
client,
|
|
680
|
+
workspaceId,
|
|
681
|
+
sessionId,
|
|
682
|
+
"human-input",
|
|
683
|
+
state.data,
|
|
684
|
+
{ enabled, discard: deniesRetainedView(state.error) }
|
|
685
|
+
);
|
|
686
|
+
useEffect3(() => {
|
|
687
|
+
const now2 = Date.now();
|
|
688
|
+
const nextDeadline = (loadedRequests ?? []).reduce((next, request) => {
|
|
689
|
+
if (request.status !== "pending" || !request.expiresAt) return next;
|
|
690
|
+
const deadline = Date.parse(request.expiresAt);
|
|
691
|
+
if (!Number.isFinite(deadline) || deadline <= now2) return next;
|
|
692
|
+
return next === null ? deadline : Math.min(next, deadline);
|
|
693
|
+
}, null);
|
|
694
|
+
if (nextDeadline === null) return;
|
|
695
|
+
const timer = globalThis.setTimeout(
|
|
696
|
+
() => {
|
|
697
|
+
setDeadlineVersion((current) => current + 1);
|
|
698
|
+
void refreshRequests();
|
|
699
|
+
},
|
|
700
|
+
Math.min(2147483647, Math.max(0, nextDeadline - now2 + 1))
|
|
701
|
+
);
|
|
702
|
+
return () => globalThis.clearTimeout(timer);
|
|
703
|
+
}, [loadedRequests, refreshRequests]);
|
|
704
|
+
const respond = useCallback3(
|
|
705
|
+
async (requestId, response) => {
|
|
706
|
+
if (!sessionId || respondingRequestRef.current !== null) return null;
|
|
707
|
+
respondingRequestRef.current = requestId;
|
|
708
|
+
setRespondingRequestId(requestId);
|
|
709
|
+
try {
|
|
710
|
+
const event = await mutation.run(
|
|
711
|
+
() => client.submitHumanInputResponse(workspaceId, sessionId, requestId, response, {
|
|
712
|
+
clientEventId: globalThis.crypto.randomUUID()
|
|
713
|
+
})
|
|
714
|
+
);
|
|
715
|
+
if (event) await state.refresh();
|
|
716
|
+
return event;
|
|
717
|
+
} finally {
|
|
718
|
+
if (respondingRequestRef.current === requestId) {
|
|
719
|
+
respondingRequestRef.current = null;
|
|
720
|
+
setRespondingRequestId(null);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
},
|
|
724
|
+
[client, mutation, sessionId, state, workspaceId]
|
|
725
|
+
);
|
|
726
|
+
const now = Date.now();
|
|
727
|
+
void deadlineVersion;
|
|
728
|
+
return {
|
|
729
|
+
requests: [...state.data ?? retainedRequests ?? []].filter((request) => isActionableHumanInputRequest(request, now)).sort(
|
|
730
|
+
(left, right) => left.createdAt.localeCompare(right.createdAt) || left.id.localeCompare(right.id)
|
|
731
|
+
),
|
|
732
|
+
loading: state.loading && retainedRequests === null,
|
|
733
|
+
error: state.error,
|
|
734
|
+
refresh: state.refresh,
|
|
735
|
+
respond,
|
|
736
|
+
respondingRequestId,
|
|
737
|
+
mutationError: mutation.mutationError,
|
|
738
|
+
clearMutationError: mutation.clearMutationError
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// src/hooks/use-session.ts
|
|
743
|
+
import { useCallback as useCallback4, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef4, useState as useState3 } from "react";
|
|
744
|
+
function isTitleEvent(event) {
|
|
745
|
+
return event.type === "session.title_set";
|
|
746
|
+
}
|
|
747
|
+
function isSessionDetailEvent(event) {
|
|
748
|
+
return isTitleEvent(event) || event.type.startsWith("session.command.") || event.type.startsWith("session.wait.") || event.type === "session.status.changed" || event.type === "system.update.pending";
|
|
749
|
+
}
|
|
750
|
+
function useSession(sessionId, options = {}) {
|
|
751
|
+
const { client, workspaceId, workspaceControlEvent, registerSessionReconciler } = useEmbeddedSessionRead(options);
|
|
752
|
+
const enabled = (options.enabled ?? true) && Boolean(sessionId);
|
|
753
|
+
const [override, setOverride] = useState3(null);
|
|
754
|
+
const nextReadRevision = useRef4(0);
|
|
755
|
+
const nextReadGeneration = useRef4(0);
|
|
756
|
+
const beginRead = options.beginRead;
|
|
757
|
+
const { run, mutating, mutationError, clearMutationError } = useMutationRunner();
|
|
758
|
+
const load = useCallback4(
|
|
759
|
+
async (signal) => {
|
|
760
|
+
if (!sessionId) {
|
|
761
|
+
return null;
|
|
762
|
+
}
|
|
763
|
+
let readGeneration2 = 0;
|
|
764
|
+
const fetched = await client.getSession(workspaceId, sessionId, {
|
|
765
|
+
fresh: true,
|
|
766
|
+
signal,
|
|
767
|
+
onRequestStart: () => {
|
|
768
|
+
readGeneration2 = beginRead?.() ?? ++nextReadGeneration.current;
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
setOverride(null);
|
|
772
|
+
return {
|
|
773
|
+
session: fetched,
|
|
774
|
+
revision: ++nextReadRevision.current,
|
|
775
|
+
readGeneration: readGeneration2
|
|
776
|
+
};
|
|
777
|
+
},
|
|
778
|
+
[beginRead, client, workspaceId, sessionId]
|
|
779
|
+
);
|
|
780
|
+
const { data, loading, error, refresh } = usePolledValue(load, {
|
|
781
|
+
pollIntervalMs: options.pollIntervalMs,
|
|
782
|
+
enabled
|
|
783
|
+
});
|
|
784
|
+
useEffect4(() => {
|
|
785
|
+
if (enabled && workspaceControlEvent) void refresh();
|
|
786
|
+
}, [enabled, refresh, workspaceControlEvent]);
|
|
787
|
+
useEffect4(() => {
|
|
788
|
+
if (!sessionId || !enabled) return;
|
|
789
|
+
return registerSessionReconciler(sessionId, "session", refresh);
|
|
790
|
+
}, [enabled, refresh, registerSessionReconciler, sessionId]);
|
|
791
|
+
const retained = useRetainedSessionView(
|
|
792
|
+
client,
|
|
793
|
+
workspaceId,
|
|
794
|
+
sessionId,
|
|
795
|
+
"detail",
|
|
796
|
+
data?.session ?? null,
|
|
797
|
+
{ enabled, discard: deniesRetainedView(error) }
|
|
798
|
+
);
|
|
799
|
+
const base = data?.session ?? null;
|
|
800
|
+
const readRevision = data?.revision ?? 0;
|
|
801
|
+
const readGeneration = data?.readGeneration ?? 0;
|
|
802
|
+
const session = useMemo2(
|
|
803
|
+
() => base && override && override.id === base.id ? { ...base, title: override.title, titleSource: override.titleSource } : base ?? retained,
|
|
804
|
+
[base, override, retained]
|
|
805
|
+
);
|
|
806
|
+
const sharedEvents = options.events;
|
|
807
|
+
const refreshDetail = useCallback4(() => void refresh(), [refresh]);
|
|
808
|
+
const onTitleEvent = useCallback4(
|
|
809
|
+
(event) => {
|
|
810
|
+
if (sharedEvents?.some(
|
|
811
|
+
(item) => item.sessionId === sessionId && !isTitleEvent(item) && isSessionDetailEvent(item) && item.sequence > (base?.lastSequence ?? -1)
|
|
812
|
+
)) {
|
|
813
|
+
void refresh();
|
|
814
|
+
} else if (!isTitleEvent(event)) {
|
|
815
|
+
if (!base || event.sequence > base.lastSequence) void refresh();
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
if (!base || event.sequence <= base.lastSequence) {
|
|
819
|
+
return;
|
|
820
|
+
}
|
|
821
|
+
const payload = event.payload ?? {};
|
|
822
|
+
const title = payload.title;
|
|
823
|
+
if (typeof title !== "string") {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
const source = payload.source === "user" || payload.source === "agent" ? payload.source : null;
|
|
827
|
+
setOverride((current) => {
|
|
828
|
+
const next = current ?? base;
|
|
829
|
+
return { ...next, title, titleSource: source };
|
|
830
|
+
});
|
|
831
|
+
},
|
|
832
|
+
[base, refresh, sharedEvents, sessionId]
|
|
833
|
+
);
|
|
834
|
+
useSessionEventTrigger(client, workspaceId, sessionId, isSessionDetailEvent, onTitleEvent, {
|
|
835
|
+
enabled,
|
|
836
|
+
...options.events !== void 0 ? { events: options.events } : {},
|
|
837
|
+
// The detail row is authoritative through its lastSequence: only a later
|
|
838
|
+
// event can make it stale, and one that arrives first waits for the read.
|
|
839
|
+
readThrough: base ? base.lastSequence : loading ? "reading" : null,
|
|
840
|
+
refresh: refreshDetail
|
|
841
|
+
});
|
|
842
|
+
const updateTitle = useCallback4(
|
|
843
|
+
async (title) => {
|
|
844
|
+
if (!sessionId) {
|
|
845
|
+
return null;
|
|
846
|
+
}
|
|
847
|
+
const result = await run(() => client.updateSession(workspaceId, sessionId, { title }));
|
|
848
|
+
if (result) {
|
|
849
|
+
setOverride(result);
|
|
850
|
+
}
|
|
851
|
+
return result;
|
|
852
|
+
},
|
|
853
|
+
[client, workspaceId, sessionId, run]
|
|
854
|
+
);
|
|
855
|
+
return {
|
|
856
|
+
session,
|
|
857
|
+
loading: loading && retained === null,
|
|
858
|
+
error,
|
|
859
|
+
readRevision,
|
|
860
|
+
readGeneration,
|
|
861
|
+
refresh,
|
|
862
|
+
updateTitle,
|
|
863
|
+
updating: mutating,
|
|
864
|
+
mutationError,
|
|
865
|
+
clearMutationError
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
// src/hooks/use-session-control.ts
|
|
870
|
+
import { useCallback as useCallback5, useLayoutEffect as useLayoutEffect2, useRef as useRef5 } from "react";
|
|
871
|
+
function useSessionControl(sessionId, options = {}) {
|
|
872
|
+
const { client, workspaceId } = useEmbeddedSession(options);
|
|
873
|
+
const approvalTargetKey = `${workspaceId}\0${sessionId ?? ""}`;
|
|
874
|
+
const pendingApproval = useRef5(null);
|
|
875
|
+
useLayoutEffect2(() => {
|
|
876
|
+
if (pendingApproval.current?.targetKey !== approvalTargetKey) {
|
|
877
|
+
pendingApproval.current = null;
|
|
878
|
+
}
|
|
879
|
+
}, [approvalTargetKey]);
|
|
880
|
+
const {
|
|
881
|
+
run: runControl,
|
|
882
|
+
mutating: controlling,
|
|
883
|
+
mutationError: controlError,
|
|
884
|
+
clearMutationError: clearControlError
|
|
885
|
+
} = useMutationRunner(approvalTargetKey);
|
|
886
|
+
const {
|
|
887
|
+
run: runApproval,
|
|
888
|
+
mutating: responding,
|
|
889
|
+
mutationError: approvalError,
|
|
890
|
+
clearMutationError: clearApprovalError
|
|
891
|
+
} = useMutationRunner(approvalTargetKey);
|
|
892
|
+
const pause = useCallback5(
|
|
893
|
+
async (reason) => {
|
|
894
|
+
if (!sessionId) {
|
|
895
|
+
return null;
|
|
896
|
+
}
|
|
897
|
+
return await runControl(
|
|
898
|
+
() => client.pauseSession(workspaceId, sessionId, reason !== void 0 ? { reason } : {})
|
|
899
|
+
);
|
|
900
|
+
},
|
|
901
|
+
[client, workspaceId, sessionId, runControl]
|
|
902
|
+
);
|
|
903
|
+
const resume = useCallback5(
|
|
904
|
+
async (reason) => {
|
|
905
|
+
if (!sessionId) return null;
|
|
906
|
+
return await runControl(
|
|
907
|
+
() => client.resumeSession(workspaceId, sessionId, reason !== void 0 ? { reason } : {})
|
|
908
|
+
);
|
|
909
|
+
},
|
|
910
|
+
[client, workspaceId, sessionId, runControl]
|
|
911
|
+
);
|
|
912
|
+
const decide = useCallback5(
|
|
913
|
+
async (approvalId, decision, message) => {
|
|
914
|
+
if (!sessionId) {
|
|
915
|
+
return null;
|
|
916
|
+
}
|
|
917
|
+
const decisionKey = JSON.stringify([approvalId, decision, message ?? null]);
|
|
918
|
+
if (pendingApproval.current?.decisionKey !== decisionKey) {
|
|
919
|
+
pendingApproval.current = {
|
|
920
|
+
targetKey: approvalTargetKey,
|
|
921
|
+
decisionKey,
|
|
922
|
+
clientEventId: crypto.randomUUID()
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
const clientEventId = pendingApproval.current.clientEventId;
|
|
926
|
+
const accepted = await runApproval(
|
|
927
|
+
() => client.sendApprovalDecision(workspaceId, sessionId, {
|
|
928
|
+
approvalId,
|
|
929
|
+
decision,
|
|
930
|
+
...message !== void 0 ? { message } : {},
|
|
931
|
+
clientEventId
|
|
932
|
+
})
|
|
933
|
+
);
|
|
934
|
+
if (accepted !== null && pendingApproval.current?.targetKey === approvalTargetKey && pendingApproval.current.clientEventId === clientEventId) {
|
|
935
|
+
pendingApproval.current = null;
|
|
936
|
+
}
|
|
937
|
+
return accepted;
|
|
938
|
+
},
|
|
939
|
+
[approvalTargetKey, client, workspaceId, sessionId, runApproval]
|
|
940
|
+
);
|
|
941
|
+
const approve = useCallback5(
|
|
942
|
+
async (approvalId, message) => await decide(approvalId, "approve", message),
|
|
943
|
+
[decide]
|
|
944
|
+
);
|
|
945
|
+
const reject = useCallback5(
|
|
946
|
+
async (approvalId, message) => await decide(approvalId, "reject", message),
|
|
947
|
+
[decide]
|
|
948
|
+
);
|
|
949
|
+
const error = approvalError ?? controlError;
|
|
950
|
+
const clearError = useCallback5(() => {
|
|
951
|
+
clearControlError();
|
|
952
|
+
clearApprovalError();
|
|
953
|
+
}, [clearControlError, clearApprovalError]);
|
|
954
|
+
return {
|
|
955
|
+
pause,
|
|
956
|
+
resume,
|
|
957
|
+
controlling,
|
|
958
|
+
approve,
|
|
959
|
+
reject,
|
|
960
|
+
responding,
|
|
961
|
+
error,
|
|
962
|
+
clearError
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// src/hooks/use-session-events.ts
|
|
967
|
+
import {
|
|
968
|
+
sessionEventStreamCoveredThrough
|
|
969
|
+
} from "@opengeni/sdk";
|
|
970
|
+
import { startTransition, useCallback as useCallback6, useEffect as useEffect5, useMemo as useMemo3, useRef as useRef6, useState as useState4 } from "react";
|
|
971
|
+
var SESSION_HISTORY_PAGE_SIZE = 1e3;
|
|
972
|
+
var INITIAL_FETCH_CAP = 1;
|
|
973
|
+
var OLDER_GROUP_TARGET = 32;
|
|
974
|
+
var OLDER_FETCH_CAP = 2;
|
|
975
|
+
var NEWER_GROUP_TARGET = 32;
|
|
976
|
+
var NEWER_FETCH_CAP = 2;
|
|
977
|
+
var OLDEST_GROUP_TARGET = 32;
|
|
978
|
+
var OLDEST_FETCH_CAP = 2;
|
|
979
|
+
var BOUNDARY_PAGE_CAP = 1;
|
|
980
|
+
var FOREGROUND_DIRECT_REPLAY_MAX_SEQUENCES = 16;
|
|
981
|
+
var FOREGROUND_COMPACT_PROBE_MAX_SEQUENCES = SESSION_HISTORY_PAGE_SIZE;
|
|
982
|
+
var FOREGROUND_COMPACT_CATCHUP_MAX_EVENTS = 128;
|
|
983
|
+
var FOREGROUND_COMPACT_CATCHUP_MAX_GROUPS = 16;
|
|
984
|
+
var FOREGROUND_COMPACT_CATCHUP_MAX_BYTES = 512 * 1024;
|
|
985
|
+
var EMPTY_EVENTS = [];
|
|
986
|
+
var encoder = new TextEncoder();
|
|
987
|
+
var SESSION_EVENT_BROWSER_MAX_BYTES = 16 * 1024 * 1024;
|
|
988
|
+
var SESSION_EVENT_BROWSER_MAX_COUNT = 2e4;
|
|
989
|
+
var SESSION_EVENT_BROWSER_PENDING_MAX_BYTES = 1024 * 1024;
|
|
990
|
+
var SESSION_EVENT_BROWSER_PENDING_MAX_COUNT = 256;
|
|
991
|
+
var EMPTY_EVENT_WINDOW = {
|
|
992
|
+
events: EMPTY_EVENTS,
|
|
993
|
+
bytes: 2,
|
|
994
|
+
truncated: false
|
|
995
|
+
};
|
|
996
|
+
function useSessionEvents(sessionId, options = {}) {
|
|
997
|
+
const t = useOpenGeniText();
|
|
998
|
+
const { client, workspaceId, reconcileSession } = useEmbeddedSession(options);
|
|
999
|
+
const enabled = options.enabled ?? true;
|
|
1000
|
+
const pageLive = usePageLiveActivity();
|
|
1001
|
+
const streamEnabled = enabled && pageLive;
|
|
1002
|
+
const after = options.after ?? 0;
|
|
1003
|
+
const replay = options.replay ?? "windowed";
|
|
1004
|
+
const fullReplay = replay === "full" || after !== 0;
|
|
1005
|
+
const streamKey = `${workspaceId}\0${sessionId ?? ""}\0${after}\0${fullReplay ? "full" : "windowed"}`;
|
|
1006
|
+
const navigationIdentityRef = useRef6({ client, streamKey, enabled });
|
|
1007
|
+
if (navigationIdentityRef.current.client !== client || navigationIdentityRef.current.streamKey !== streamKey || navigationIdentityRef.current.enabled !== enabled) {
|
|
1008
|
+
navigationIdentityRef.current = { client, streamKey, enabled };
|
|
1009
|
+
}
|
|
1010
|
+
const navigationIdentity = navigationIdentityRef.current;
|
|
1011
|
+
const ownsNavigation = useCallback6(
|
|
1012
|
+
() => navigationIdentityRef.current === navigationIdentity,
|
|
1013
|
+
[navigationIdentity]
|
|
1014
|
+
);
|
|
1015
|
+
const [eventWindow, setEventWindow] = useState4(EMPTY_EVENT_WINDOW);
|
|
1016
|
+
const [questionEvidence, setQuestionEvidence] = useState4(null);
|
|
1017
|
+
const [connectionState, setConnectionState] = useState4("idle");
|
|
1018
|
+
const [error, setError] = useState4(null);
|
|
1019
|
+
const [newerError, setNewerError] = useState4(null);
|
|
1020
|
+
const [hasOlder, setHasOlder] = useState4(false);
|
|
1021
|
+
const [hasNewer, setHasNewer] = useState4(false);
|
|
1022
|
+
const [sessionStatusProjection, setSessionStatusProjection] = useState4(
|
|
1023
|
+
null
|
|
1024
|
+
);
|
|
1025
|
+
const [initialLoading, setInitialLoading] = useState4(true);
|
|
1026
|
+
const [initialHistoryReady, setInitialHistoryReady] = useState4(false);
|
|
1027
|
+
const [loadingOlder, setLoadingOlder] = useState4(false);
|
|
1028
|
+
const [loadingNewer, setLoadingNewer] = useState4(false);
|
|
1029
|
+
const [loadingOldest, setLoadingOldest] = useState4(false);
|
|
1030
|
+
const [loadingLatest, setLoadingLatest] = useState4(false);
|
|
1031
|
+
const [loadingTarget, setLoadingTarget] = useState4(false);
|
|
1032
|
+
const loadingTargetRef = useRef6(false);
|
|
1033
|
+
const [streamEpoch, setStreamEpoch] = useState4(0);
|
|
1034
|
+
const [viewMode, setViewMode] = useState4("live");
|
|
1035
|
+
const lastSequenceRef = useRef6(after);
|
|
1036
|
+
const streamResumeSequenceRef = useRef6(after);
|
|
1037
|
+
const oldestSequenceRef = useRef6(null);
|
|
1038
|
+
const newestSequenceRef = useRef6(null);
|
|
1039
|
+
const hasOlderRef = useRef6(false);
|
|
1040
|
+
const hasNewerRef = useRef6(false);
|
|
1041
|
+
const loadingOlderRef = useRef6(false);
|
|
1042
|
+
const loadingNewerRef = useRef6(false);
|
|
1043
|
+
const loadingOldestRef = useRef6(false);
|
|
1044
|
+
const loadingLatestRef = useRef6(false);
|
|
1045
|
+
const viewModeRef = useRef6("live");
|
|
1046
|
+
const initialWindowLoadedRef = useRef6(false);
|
|
1047
|
+
const openedStreamKeyRef = useRef6(null);
|
|
1048
|
+
const reconcileAfterPageResumeRef = useRef6(false);
|
|
1049
|
+
const streamAbortRef = useRef6(null);
|
|
1050
|
+
const streamKeyRef = useRef6(null);
|
|
1051
|
+
const generationRef = useRef6(0);
|
|
1052
|
+
const navigationGenerationRef = useRef6(0);
|
|
1053
|
+
const eventWindowRef = useRef6(EMPTY_EVENT_WINDOW);
|
|
1054
|
+
const sessionStatusRef = useRef6({
|
|
1055
|
+
sequence: after,
|
|
1056
|
+
status: null
|
|
1057
|
+
});
|
|
1058
|
+
const [stateStreamKey, setStateStreamKey] = useState4(streamKey);
|
|
1059
|
+
useEffect5(() => {
|
|
1060
|
+
navigationGenerationRef.current += 1;
|
|
1061
|
+
setNewerError(null);
|
|
1062
|
+
loadingOlderRef.current = false;
|
|
1063
|
+
loadingNewerRef.current = false;
|
|
1064
|
+
loadingOldestRef.current = false;
|
|
1065
|
+
loadingTargetRef.current = false;
|
|
1066
|
+
setQuestionEvidence(null);
|
|
1067
|
+
setLoadingTarget(false);
|
|
1068
|
+
setLoadingOlder(false);
|
|
1069
|
+
setLoadingNewer(false);
|
|
1070
|
+
setLoadingOldest(false);
|
|
1071
|
+
return () => {
|
|
1072
|
+
navigationGenerationRef.current += 1;
|
|
1073
|
+
};
|
|
1074
|
+
}, [client, workspaceId, sessionId, after, enabled, fullReplay]);
|
|
1075
|
+
useEffect5(() => {
|
|
1076
|
+
if (streamKeyRef.current !== streamKey) {
|
|
1077
|
+
streamKeyRef.current = streamKey;
|
|
1078
|
+
setStateStreamKey(streamKey);
|
|
1079
|
+
eventWindowRef.current = EMPTY_EVENT_WINDOW;
|
|
1080
|
+
setEventWindow(EMPTY_EVENT_WINDOW);
|
|
1081
|
+
setError(null);
|
|
1082
|
+
setHasOlder(false);
|
|
1083
|
+
setHasNewer(false);
|
|
1084
|
+
sessionStatusRef.current = { sequence: after, status: null };
|
|
1085
|
+
setSessionStatusProjection(null);
|
|
1086
|
+
setLoadingOlder(false);
|
|
1087
|
+
setLoadingNewer(false);
|
|
1088
|
+
setLoadingOldest(false);
|
|
1089
|
+
setLoadingLatest(false);
|
|
1090
|
+
setInitialLoading(true);
|
|
1091
|
+
setInitialHistoryReady(false);
|
|
1092
|
+
lastSequenceRef.current = after;
|
|
1093
|
+
streamResumeSequenceRef.current = after;
|
|
1094
|
+
oldestSequenceRef.current = null;
|
|
1095
|
+
newestSequenceRef.current = null;
|
|
1096
|
+
hasOlderRef.current = false;
|
|
1097
|
+
hasNewerRef.current = false;
|
|
1098
|
+
loadingOlderRef.current = false;
|
|
1099
|
+
loadingNewerRef.current = false;
|
|
1100
|
+
loadingOldestRef.current = false;
|
|
1101
|
+
loadingLatestRef.current = false;
|
|
1102
|
+
viewModeRef.current = "live";
|
|
1103
|
+
setViewMode("live");
|
|
1104
|
+
initialWindowLoadedRef.current = false;
|
|
1105
|
+
reconcileAfterPageResumeRef.current = false;
|
|
1106
|
+
}
|
|
1107
|
+
const generation = generationRef.current + 1;
|
|
1108
|
+
generationRef.current = generation;
|
|
1109
|
+
if (!sessionId || !streamEnabled) {
|
|
1110
|
+
if (sessionId && enabled && !pageLive && !fullReplay && viewModeRef.current === "live" && initialWindowLoadedRef.current) {
|
|
1111
|
+
reconcileAfterPageResumeRef.current = true;
|
|
1112
|
+
}
|
|
1113
|
+
setConnectionState("idle");
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
if (viewMode === "history") {
|
|
1117
|
+
reconcileAfterPageResumeRef.current = false;
|
|
1118
|
+
setConnectionState("idle");
|
|
1119
|
+
setInitialLoading(false);
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
const reconcileForegroundResume = reconcileAfterPageResumeRef.current && !fullReplay;
|
|
1123
|
+
reconcileAfterPageResumeRef.current = false;
|
|
1124
|
+
const controller = new AbortController();
|
|
1125
|
+
const isCurrent = () => generationRef.current === generation && !controller.signal.aborted && navigationIdentityRef.current.client === client && navigationIdentityRef.current.streamKey === streamKey && navigationIdentityRef.current.enabled === enabled;
|
|
1126
|
+
streamAbortRef.current = controller;
|
|
1127
|
+
let pending = [];
|
|
1128
|
+
let pendingBytes = 2;
|
|
1129
|
+
let flushTimer = null;
|
|
1130
|
+
const flush = () => {
|
|
1131
|
+
if (flushTimer !== null) {
|
|
1132
|
+
clearTimeout(flushTimer);
|
|
1133
|
+
flushTimer = null;
|
|
1134
|
+
}
|
|
1135
|
+
if (!isCurrent()) {
|
|
1136
|
+
pending = [];
|
|
1137
|
+
pendingBytes = 2;
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
if (pending.length === 0) {
|
|
1141
|
+
return;
|
|
1142
|
+
}
|
|
1143
|
+
const batch = pending;
|
|
1144
|
+
pending = [];
|
|
1145
|
+
pendingBytes = 2;
|
|
1146
|
+
const lastInBatch = batch[batch.length - 1];
|
|
1147
|
+
if (lastInBatch) {
|
|
1148
|
+
const batchResumeSequence = Math.max(...batch.map(eventResumeSequence));
|
|
1149
|
+
lastSequenceRef.current = Math.max(lastSequenceRef.current, batchResumeSequence);
|
|
1150
|
+
streamResumeSequenceRef.current = Math.max(
|
|
1151
|
+
streamResumeSequenceRef.current,
|
|
1152
|
+
batchResumeSequence
|
|
1153
|
+
);
|
|
1154
|
+
}
|
|
1155
|
+
const status = observeSessionStatus(batch, sessionStatusRef);
|
|
1156
|
+
if (status !== void 0) {
|
|
1157
|
+
setSessionStatusProjection(status);
|
|
1158
|
+
}
|
|
1159
|
+
const current = eventWindowRef.current;
|
|
1160
|
+
const next = appendBrowserSessionEventWindow(current, batch);
|
|
1161
|
+
const retained = {
|
|
1162
|
+
...next,
|
|
1163
|
+
truncated: current.truncated || next.truncated
|
|
1164
|
+
};
|
|
1165
|
+
eventWindowRef.current = retained;
|
|
1166
|
+
setEventWindow(retained);
|
|
1167
|
+
oldestSequenceRef.current = retained.events[0]?.sequence ?? null;
|
|
1168
|
+
newestSequenceRef.current = maxResumeSequenceOrNull(retained.events);
|
|
1169
|
+
if (retained.truncated) {
|
|
1170
|
+
hasOlderRef.current = true;
|
|
1171
|
+
setHasOlder(true);
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
const scheduleFlush = () => {
|
|
1175
|
+
if (!isCurrent()) return;
|
|
1176
|
+
flushTimer ??= setTimeout(flush, 16);
|
|
1177
|
+
};
|
|
1178
|
+
void (async () => {
|
|
1179
|
+
try {
|
|
1180
|
+
if (reconcileForegroundResume) {
|
|
1181
|
+
setConnectionState("connecting");
|
|
1182
|
+
const cursor = streamResumeSequenceRef.current;
|
|
1183
|
+
let plan = { kind: "resume" };
|
|
1184
|
+
try {
|
|
1185
|
+
plan = await planForegroundCatchup(t, client, workspaceId, sessionId, cursor, {
|
|
1186
|
+
signal: controller.signal
|
|
1187
|
+
});
|
|
1188
|
+
} catch {
|
|
1189
|
+
if (controller.signal.aborted) return;
|
|
1190
|
+
plan = { kind: "resume" };
|
|
1191
|
+
}
|
|
1192
|
+
if (!isCurrent()) return;
|
|
1193
|
+
if (plan.kind === "append") {
|
|
1194
|
+
const current = eventWindowRef.current;
|
|
1195
|
+
assertAppendOrder(current.events, plan.events);
|
|
1196
|
+
const status = observeSessionStatus(plan.events, sessionStatusRef);
|
|
1197
|
+
const next = appendBrowserSessionEventWindow(current, plan.events);
|
|
1198
|
+
const retained = {
|
|
1199
|
+
...next,
|
|
1200
|
+
truncated: current.truncated || next.truncated
|
|
1201
|
+
};
|
|
1202
|
+
eventWindowRef.current = retained;
|
|
1203
|
+
oldestSequenceRef.current = retained.events[0]?.sequence ?? null;
|
|
1204
|
+
newestSequenceRef.current = maxResumeSequenceOrNull(retained.events);
|
|
1205
|
+
lastSequenceRef.current = Math.max(lastSequenceRef.current, plan.resumeSequence);
|
|
1206
|
+
streamResumeSequenceRef.current = Math.max(
|
|
1207
|
+
streamResumeSequenceRef.current,
|
|
1208
|
+
plan.resumeSequence
|
|
1209
|
+
);
|
|
1210
|
+
if (status !== void 0) {
|
|
1211
|
+
setSessionStatusProjection(status);
|
|
1212
|
+
}
|
|
1213
|
+
setEventWindow(retained);
|
|
1214
|
+
if (retained.truncated) {
|
|
1215
|
+
hasOlderRef.current = true;
|
|
1216
|
+
setHasOlder(true);
|
|
1217
|
+
}
|
|
1218
|
+
} else if (plan.kind === "reload") {
|
|
1219
|
+
initialWindowLoadedRef.current = false;
|
|
1220
|
+
setError(null);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
if (!fullReplay && !initialWindowLoadedRef.current) {
|
|
1224
|
+
setConnectionState("connecting");
|
|
1225
|
+
const window = await loadEventWindow(t, client, workspaceId, sessionId, {
|
|
1226
|
+
before: Number.MAX_SAFE_INTEGER,
|
|
1227
|
+
pageSize: SESSION_HISTORY_PAGE_SIZE,
|
|
1228
|
+
targetGroups: Number.POSITIVE_INFINITY,
|
|
1229
|
+
maxFetches: INITIAL_FETCH_CAP,
|
|
1230
|
+
boundaryPageCap: BOUNDARY_PAGE_CAP,
|
|
1231
|
+
signal: controller.signal
|
|
1232
|
+
});
|
|
1233
|
+
if (!isCurrent()) {
|
|
1234
|
+
return;
|
|
1235
|
+
}
|
|
1236
|
+
const status = observeSessionStatus(window.events, sessionStatusRef);
|
|
1237
|
+
const retained = boundBrowserSessionEventWindow(window.events);
|
|
1238
|
+
navigationGenerationRef.current += 1;
|
|
1239
|
+
loadingOlderRef.current = false;
|
|
1240
|
+
loadingNewerRef.current = false;
|
|
1241
|
+
loadingOldestRef.current = false;
|
|
1242
|
+
setLoadingOlder(false);
|
|
1243
|
+
setLoadingNewer(false);
|
|
1244
|
+
setLoadingOldest(false);
|
|
1245
|
+
eventWindowRef.current = retained;
|
|
1246
|
+
oldestSequenceRef.current = retained.events[0]?.sequence ?? window.oldestSequence;
|
|
1247
|
+
newestSequenceRef.current = maxResumeSequenceOrNull(retained.events) ?? window.newestSequence;
|
|
1248
|
+
hasOlderRef.current = window.hasOlder || retained.truncated;
|
|
1249
|
+
hasNewerRef.current = false;
|
|
1250
|
+
lastSequenceRef.current = window.newestSequence;
|
|
1251
|
+
streamResumeSequenceRef.current = window.newestSequence;
|
|
1252
|
+
initialWindowLoadedRef.current = true;
|
|
1253
|
+
setInitialHistoryReady(true);
|
|
1254
|
+
setError(null);
|
|
1255
|
+
if (status !== void 0) {
|
|
1256
|
+
setSessionStatusProjection(status);
|
|
1257
|
+
}
|
|
1258
|
+
setEventWindow(retained);
|
|
1259
|
+
setHasOlder(window.hasOlder || retained.truncated);
|
|
1260
|
+
setHasNewer(false);
|
|
1261
|
+
setInitialLoading(false);
|
|
1262
|
+
}
|
|
1263
|
+
if (fullReplay) {
|
|
1264
|
+
setInitialLoading(false);
|
|
1265
|
+
}
|
|
1266
|
+
const stream = client.streamEvents(workspaceId, sessionId, {
|
|
1267
|
+
after: streamResumeSequenceRef.current,
|
|
1268
|
+
signal: controller.signal,
|
|
1269
|
+
onOpen: () => {
|
|
1270
|
+
const initialOpen = openedStreamKeyRef.current !== streamKey;
|
|
1271
|
+
openedStreamKeyRef.current = streamKey;
|
|
1272
|
+
void Promise.resolve().then(() => reconcileSession(sessionId, { initialOpen })).catch((cause) => {
|
|
1273
|
+
if (isCurrent()) {
|
|
1274
|
+
setError(normalizeError(cause));
|
|
1275
|
+
}
|
|
1276
|
+
});
|
|
1277
|
+
},
|
|
1278
|
+
onStateChange: (state) => {
|
|
1279
|
+
if (isCurrent()) {
|
|
1280
|
+
setConnectionState(state);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
for await (const event of stream) {
|
|
1285
|
+
if (!isCurrent()) break;
|
|
1286
|
+
const boundedEvent = event;
|
|
1287
|
+
const boundedEventBytes = browserJsonBytes(boundedEvent);
|
|
1288
|
+
const separatorBytes = pending.length === 0 ? 0 : 1;
|
|
1289
|
+
if (pending.length > 0 && (pending.length >= SESSION_EVENT_BROWSER_PENDING_MAX_COUNT || pendingBytes + separatorBytes + boundedEventBytes > SESSION_EVENT_BROWSER_PENDING_MAX_BYTES)) {
|
|
1290
|
+
flush();
|
|
1291
|
+
}
|
|
1292
|
+
pending.push(boundedEvent);
|
|
1293
|
+
pendingBytes += (pending.length === 1 ? 0 : 1) + boundedEventBytes;
|
|
1294
|
+
if (pending.length >= SESSION_EVENT_BROWSER_PENDING_MAX_COUNT || pendingBytes >= SESSION_EVENT_BROWSER_PENDING_MAX_BYTES) {
|
|
1295
|
+
flush();
|
|
1296
|
+
} else {
|
|
1297
|
+
scheduleFlush();
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
if (isCurrent()) {
|
|
1301
|
+
flush();
|
|
1302
|
+
setConnectionState("ended");
|
|
1303
|
+
}
|
|
1304
|
+
} catch (cause) {
|
|
1305
|
+
if (isCurrent()) {
|
|
1306
|
+
flush();
|
|
1307
|
+
setError(normalizeError(cause));
|
|
1308
|
+
setConnectionState("error");
|
|
1309
|
+
setInitialLoading(false);
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
})();
|
|
1313
|
+
return () => {
|
|
1314
|
+
controller.abort();
|
|
1315
|
+
if (generationRef.current === generation) {
|
|
1316
|
+
generationRef.current = generation + 1;
|
|
1317
|
+
}
|
|
1318
|
+
if (streamAbortRef.current === controller) {
|
|
1319
|
+
streamAbortRef.current = null;
|
|
1320
|
+
}
|
|
1321
|
+
if (flushTimer !== null) {
|
|
1322
|
+
clearTimeout(flushTimer);
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
}, [
|
|
1326
|
+
client,
|
|
1327
|
+
workspaceId,
|
|
1328
|
+
sessionId,
|
|
1329
|
+
after,
|
|
1330
|
+
enabled,
|
|
1331
|
+
pageLive,
|
|
1332
|
+
streamEnabled,
|
|
1333
|
+
fullReplay,
|
|
1334
|
+
streamKey,
|
|
1335
|
+
streamEpoch,
|
|
1336
|
+
viewMode,
|
|
1337
|
+
reconcileSession,
|
|
1338
|
+
t
|
|
1339
|
+
]);
|
|
1340
|
+
const navigationBusy = () => loadingTargetRef.current || loadingOlderRef.current || loadingNewerRef.current || loadingOldestRef.current || loadingLatestRef.current;
|
|
1341
|
+
const loadOlder = useCallback6(
|
|
1342
|
+
() => createOlderHistoryLoadReceipt(async (markCommitted, preserveTail, markTailPreserved) => {
|
|
1343
|
+
if (!ownsNavigation() || !sessionId || navigationBusy() || !hasOlderRef.current) {
|
|
1344
|
+
return false;
|
|
1345
|
+
}
|
|
1346
|
+
const before = oldestSequenceRef.current;
|
|
1347
|
+
if (before === null) {
|
|
1348
|
+
oldestSequenceRef.current = null;
|
|
1349
|
+
hasOlderRef.current = false;
|
|
1350
|
+
setHasOlder(false);
|
|
1351
|
+
return false;
|
|
1352
|
+
}
|
|
1353
|
+
const generation = navigationGenerationRef.current;
|
|
1354
|
+
const isCurrent = () => ownsNavigation() && navigationGenerationRef.current === generation;
|
|
1355
|
+
loadingOlderRef.current = true;
|
|
1356
|
+
setLoadingOlder(true);
|
|
1357
|
+
let published = false;
|
|
1358
|
+
try {
|
|
1359
|
+
const window = await loadEventWindow(t, client, workspaceId, sessionId, {
|
|
1360
|
+
before,
|
|
1361
|
+
pageSize: SESSION_HISTORY_PAGE_SIZE,
|
|
1362
|
+
targetGroups: OLDER_GROUP_TARGET,
|
|
1363
|
+
maxFetches: OLDER_FETCH_CAP,
|
|
1364
|
+
isCurrent
|
|
1365
|
+
});
|
|
1366
|
+
if (!isCurrent()) {
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
if (window.events.length === 0) {
|
|
1370
|
+
oldestSequenceRef.current = null;
|
|
1371
|
+
hasOlderRef.current = false;
|
|
1372
|
+
setHasOlder(false);
|
|
1373
|
+
return false;
|
|
1374
|
+
}
|
|
1375
|
+
const current = eventWindowRef.current;
|
|
1376
|
+
assertPrependOrder(current.events, window.events);
|
|
1377
|
+
const next = boundBrowserSessionEventWindow([...window.events, ...current.events], {
|
|
1378
|
+
direction: "oldest"
|
|
1379
|
+
});
|
|
1380
|
+
if (preserveTail && maxResumeSequence(next.events) < maxResumeSequence(current.events)) {
|
|
1381
|
+
markTailPreserved();
|
|
1382
|
+
return false;
|
|
1383
|
+
}
|
|
1384
|
+
const status = observeSessionStatus(window.events, sessionStatusRef);
|
|
1385
|
+
const retained = {
|
|
1386
|
+
...next,
|
|
1387
|
+
truncated: current.truncated || next.truncated
|
|
1388
|
+
};
|
|
1389
|
+
const retainedOldest = retained.events[0]?.sequence ?? null;
|
|
1390
|
+
if (retainedOldest === null || retainedOldest >= before) {
|
|
1391
|
+
throw new Error("@opengeni/react: loadOlder made no durable sequence progress");
|
|
1392
|
+
}
|
|
1393
|
+
const retainedNewest = maxResumeSequenceOrNull(retained.events);
|
|
1394
|
+
const previousNewest = maxResumeSequenceOrNull(current.events);
|
|
1395
|
+
const evictedLiveTail = previousNewest !== null && retainedNewest !== null && retainedNewest < previousNewest;
|
|
1396
|
+
if (evictedLiveTail && viewModeRef.current === "live") {
|
|
1397
|
+
streamAbortRef.current?.abort();
|
|
1398
|
+
}
|
|
1399
|
+
eventWindowRef.current = retained;
|
|
1400
|
+
markCommitted();
|
|
1401
|
+
oldestSequenceRef.current = retainedOldest;
|
|
1402
|
+
newestSequenceRef.current = retainedNewest;
|
|
1403
|
+
if (evictedLiveTail) {
|
|
1404
|
+
streamResumeSequenceRef.current = maxResumeSequence(retained.events);
|
|
1405
|
+
}
|
|
1406
|
+
const olderStillAvailable = window.hasOlder;
|
|
1407
|
+
hasOlderRef.current = olderStillAvailable;
|
|
1408
|
+
let newer = null;
|
|
1409
|
+
let enterHistory = false;
|
|
1410
|
+
if (viewModeRef.current === "history" || evictedLiveTail) {
|
|
1411
|
+
const highWater = lastSequenceRef.current;
|
|
1412
|
+
newer = retainedNewest !== null && (retainedNewest < highWater || retained.truncated);
|
|
1413
|
+
hasNewerRef.current = newer;
|
|
1414
|
+
if (evictedLiveTail) {
|
|
1415
|
+
viewModeRef.current = "history";
|
|
1416
|
+
enterHistory = true;
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
loadingOlderRef.current = false;
|
|
1420
|
+
startTransition(() => {
|
|
1421
|
+
if (status !== void 0) {
|
|
1422
|
+
setSessionStatusProjection(status);
|
|
1423
|
+
}
|
|
1424
|
+
setEventWindow(retained);
|
|
1425
|
+
setHasOlder(olderStillAvailable);
|
|
1426
|
+
if (newer !== null) {
|
|
1427
|
+
setHasNewer(newer);
|
|
1428
|
+
}
|
|
1429
|
+
if (enterHistory) {
|
|
1430
|
+
setViewMode("history");
|
|
1431
|
+
}
|
|
1432
|
+
setLoadingOlder(false);
|
|
1433
|
+
});
|
|
1434
|
+
published = true;
|
|
1435
|
+
return olderStillAvailable;
|
|
1436
|
+
} catch (reason) {
|
|
1437
|
+
if (!isCurrent()) return false;
|
|
1438
|
+
throw reason;
|
|
1439
|
+
} finally {
|
|
1440
|
+
if (!published && isCurrent()) {
|
|
1441
|
+
loadingOlderRef.current = false;
|
|
1442
|
+
setLoadingOlder(false);
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
}),
|
|
1446
|
+
[client, workspaceId, sessionId, ownsNavigation, t]
|
|
1447
|
+
);
|
|
1448
|
+
const loadOldest = useCallback6(async () => {
|
|
1449
|
+
if (!ownsNavigation() || !sessionId || navigationBusy() || !hasOlderRef.current) {
|
|
1450
|
+
return false;
|
|
1451
|
+
}
|
|
1452
|
+
const generation = ++navigationGenerationRef.current;
|
|
1453
|
+
const isCurrent = () => ownsNavigation() && navigationGenerationRef.current === generation;
|
|
1454
|
+
setQuestionEvidence(null);
|
|
1455
|
+
loadingOldestRef.current = true;
|
|
1456
|
+
setLoadingOldest(true);
|
|
1457
|
+
let published = false;
|
|
1458
|
+
try {
|
|
1459
|
+
const window = await loadForwardEventWindow(t, client, workspaceId, sessionId, {
|
|
1460
|
+
after: 0,
|
|
1461
|
+
pageSize: SESSION_HISTORY_PAGE_SIZE,
|
|
1462
|
+
targetGroups: OLDEST_GROUP_TARGET,
|
|
1463
|
+
maxFetches: OLDEST_FETCH_CAP,
|
|
1464
|
+
isCurrent
|
|
1465
|
+
});
|
|
1466
|
+
if (!isCurrent()) {
|
|
1467
|
+
return false;
|
|
1468
|
+
}
|
|
1469
|
+
if (window.events.length === 0) {
|
|
1470
|
+
hasOlderRef.current = false;
|
|
1471
|
+
setHasOlder(false);
|
|
1472
|
+
return false;
|
|
1473
|
+
}
|
|
1474
|
+
streamAbortRef.current?.abort();
|
|
1475
|
+
const status = observeSessionStatus(window.events, sessionStatusRef);
|
|
1476
|
+
const retained = boundBrowserSessionEventWindow(window.events, { direction: "oldest" });
|
|
1477
|
+
const retainedOldest = retained.events[0]?.sequence ?? null;
|
|
1478
|
+
const retainedNewest = maxResumeSequenceOrNull(retained.events);
|
|
1479
|
+
eventWindowRef.current = retained;
|
|
1480
|
+
oldestSequenceRef.current = retainedOldest;
|
|
1481
|
+
newestSequenceRef.current = retainedNewest;
|
|
1482
|
+
hasOlderRef.current = false;
|
|
1483
|
+
const highWater = Math.max(lastSequenceRef.current, retainedNewest ?? 0);
|
|
1484
|
+
lastSequenceRef.current = highWater;
|
|
1485
|
+
const newer = window.hasNewer || retained.truncated || retainedNewest !== null && retainedNewest < highWater;
|
|
1486
|
+
hasNewerRef.current = newer;
|
|
1487
|
+
initialWindowLoadedRef.current = true;
|
|
1488
|
+
setInitialHistoryReady(true);
|
|
1489
|
+
setError(null);
|
|
1490
|
+
viewModeRef.current = "history";
|
|
1491
|
+
loadingOldestRef.current = false;
|
|
1492
|
+
setNewerError(null);
|
|
1493
|
+
startTransition(() => {
|
|
1494
|
+
if (status !== void 0) {
|
|
1495
|
+
setSessionStatusProjection(status);
|
|
1496
|
+
}
|
|
1497
|
+
setEventWindow(retained);
|
|
1498
|
+
setHasOlder(false);
|
|
1499
|
+
setHasNewer(newer);
|
|
1500
|
+
setViewMode("history");
|
|
1501
|
+
setLoadingOldest(false);
|
|
1502
|
+
});
|
|
1503
|
+
published = true;
|
|
1504
|
+
return newer;
|
|
1505
|
+
} catch (reason) {
|
|
1506
|
+
if (!isCurrent()) return false;
|
|
1507
|
+
throw reason;
|
|
1508
|
+
} finally {
|
|
1509
|
+
if (!published && isCurrent()) {
|
|
1510
|
+
loadingOldestRef.current = false;
|
|
1511
|
+
setLoadingOldest(false);
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
}, [client, workspaceId, sessionId, ownsNavigation, t]);
|
|
1515
|
+
const loadNewer = useCallback6(async () => {
|
|
1516
|
+
if (!ownsNavigation() || !sessionId || navigationBusy() || !hasNewerRef.current) {
|
|
1517
|
+
return false;
|
|
1518
|
+
}
|
|
1519
|
+
const afterSequence = newestSequenceRef.current;
|
|
1520
|
+
if (afterSequence === null) {
|
|
1521
|
+
hasNewerRef.current = false;
|
|
1522
|
+
setHasNewer(false);
|
|
1523
|
+
return false;
|
|
1524
|
+
}
|
|
1525
|
+
const generation = navigationGenerationRef.current;
|
|
1526
|
+
const isCurrent = () => ownsNavigation() && navigationGenerationRef.current === generation;
|
|
1527
|
+
loadingNewerRef.current = true;
|
|
1528
|
+
setLoadingNewer(true);
|
|
1529
|
+
let published = false;
|
|
1530
|
+
try {
|
|
1531
|
+
const window = await loadForwardEventWindow(t, client, workspaceId, sessionId, {
|
|
1532
|
+
after: afterSequence,
|
|
1533
|
+
pageSize: SESSION_HISTORY_PAGE_SIZE,
|
|
1534
|
+
targetGroups: NEWER_GROUP_TARGET,
|
|
1535
|
+
maxFetches: NEWER_FETCH_CAP,
|
|
1536
|
+
isCurrent
|
|
1537
|
+
});
|
|
1538
|
+
if (!isCurrent()) {
|
|
1539
|
+
return false;
|
|
1540
|
+
}
|
|
1541
|
+
if (window.events.length === 0) {
|
|
1542
|
+
setNewerError(null);
|
|
1543
|
+
hasNewerRef.current = false;
|
|
1544
|
+
setHasNewer(false);
|
|
1545
|
+
streamResumeSequenceRef.current = afterSequence;
|
|
1546
|
+
viewModeRef.current = "live";
|
|
1547
|
+
setViewMode("live");
|
|
1548
|
+
setStreamEpoch((epoch) => epoch + 1);
|
|
1549
|
+
return false;
|
|
1550
|
+
}
|
|
1551
|
+
const current = eventWindowRef.current;
|
|
1552
|
+
assertAppendOrder(current.events, window.events);
|
|
1553
|
+
const status = observeSessionStatus(window.events, sessionStatusRef);
|
|
1554
|
+
const previousOldest = current.events[0]?.sequence ?? null;
|
|
1555
|
+
const next = appendBrowserSessionEventWindow(current, window.events);
|
|
1556
|
+
const retained = {
|
|
1557
|
+
...next,
|
|
1558
|
+
truncated: current.truncated || next.truncated || window.hasNewer
|
|
1559
|
+
};
|
|
1560
|
+
const retainedOldest = retained.events[0]?.sequence ?? null;
|
|
1561
|
+
const retainedNewest = maxResumeSequenceOrNull(retained.events);
|
|
1562
|
+
if (retainedNewest === null || retainedNewest <= afterSequence) {
|
|
1563
|
+
throw new Error("@opengeni/react: loadNewer made no durable sequence progress");
|
|
1564
|
+
}
|
|
1565
|
+
eventWindowRef.current = retained;
|
|
1566
|
+
oldestSequenceRef.current = retainedOldest;
|
|
1567
|
+
newestSequenceRef.current = retainedNewest;
|
|
1568
|
+
if (retainedOldest !== null && (previousOldest === null || retainedOldest > previousOldest || retained.truncated && retained.events[0]?.type !== "session.created" && retainedOldest > 1)) {
|
|
1569
|
+
hasOlderRef.current = true;
|
|
1570
|
+
}
|
|
1571
|
+
const rearmedOlder = hasOlderRef.current;
|
|
1572
|
+
const highWater = Math.max(lastSequenceRef.current, retainedNewest);
|
|
1573
|
+
lastSequenceRef.current = highWater;
|
|
1574
|
+
const newer = window.hasNewer || retainedNewest < highWater;
|
|
1575
|
+
hasNewerRef.current = newer;
|
|
1576
|
+
let resumeLive = false;
|
|
1577
|
+
if (!newer) {
|
|
1578
|
+
streamResumeSequenceRef.current = retainedNewest;
|
|
1579
|
+
viewModeRef.current = "live";
|
|
1580
|
+
resumeLive = true;
|
|
1581
|
+
}
|
|
1582
|
+
loadingNewerRef.current = false;
|
|
1583
|
+
setNewerError(null);
|
|
1584
|
+
startTransition(() => {
|
|
1585
|
+
if (status !== void 0) {
|
|
1586
|
+
setSessionStatusProjection(status);
|
|
1587
|
+
}
|
|
1588
|
+
setEventWindow(retained);
|
|
1589
|
+
setHasOlder(rearmedOlder);
|
|
1590
|
+
setHasNewer(newer);
|
|
1591
|
+
if (resumeLive) {
|
|
1592
|
+
setViewMode("live");
|
|
1593
|
+
setStreamEpoch((epoch) => epoch + 1);
|
|
1594
|
+
}
|
|
1595
|
+
setLoadingNewer(false);
|
|
1596
|
+
});
|
|
1597
|
+
published = true;
|
|
1598
|
+
return newer;
|
|
1599
|
+
} catch (reason) {
|
|
1600
|
+
if (!isCurrent()) {
|
|
1601
|
+
return false;
|
|
1602
|
+
}
|
|
1603
|
+
setNewerError(normalizeError(reason));
|
|
1604
|
+
throw reason;
|
|
1605
|
+
} finally {
|
|
1606
|
+
if (!published && isCurrent()) {
|
|
1607
|
+
loadingNewerRef.current = false;
|
|
1608
|
+
setLoadingNewer(false);
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
}, [client, workspaceId, sessionId, ownsNavigation, t]);
|
|
1612
|
+
const jumpToSequence = useCallback6(
|
|
1613
|
+
async (sequence, navigationOptions) => {
|
|
1614
|
+
const signal = navigationOptions?.signal;
|
|
1615
|
+
if (!ownsNavigation() || !sessionId || !Number.isSafeInteger(sequence) || sequence < 1)
|
|
1616
|
+
return false;
|
|
1617
|
+
if (signal?.aborted) return false;
|
|
1618
|
+
const generation = ++navigationGenerationRef.current;
|
|
1619
|
+
setQuestionEvidence(null);
|
|
1620
|
+
const current = () => generation === navigationGenerationRef.current && ownsNavigation();
|
|
1621
|
+
const previousMode = viewModeRef.current;
|
|
1622
|
+
streamAbortRef.current?.abort();
|
|
1623
|
+
generationRef.current += 1;
|
|
1624
|
+
viewModeRef.current = "history";
|
|
1625
|
+
setViewMode("history");
|
|
1626
|
+
loadingOlderRef.current = loadingNewerRef.current = loadingOldestRef.current = false;
|
|
1627
|
+
setLoadingOlder(false);
|
|
1628
|
+
setLoadingNewer(false);
|
|
1629
|
+
setLoadingOldest(false);
|
|
1630
|
+
loadingTargetRef.current = true;
|
|
1631
|
+
setLoadingTarget(true);
|
|
1632
|
+
let published = false;
|
|
1633
|
+
try {
|
|
1634
|
+
const [before, following] = await Promise.all([
|
|
1635
|
+
loadPreviousPage(client, workspaceId, sessionId, sequence + 1, { pageSize: 128 }),
|
|
1636
|
+
loadNextPage(client, workspaceId, sessionId, sequence, { pageSize: 128 })
|
|
1637
|
+
]);
|
|
1638
|
+
if (signal?.aborted) return false;
|
|
1639
|
+
if (!current()) return false;
|
|
1640
|
+
if (!before.some((event) => event.sequence === sequence)) return false;
|
|
1641
|
+
const prefix = boundBrowserSessionEventWindow(before, {
|
|
1642
|
+
direction: "newest",
|
|
1643
|
+
maxBytes: SESSION_EVENT_BROWSER_MAX_BYTES / 2
|
|
1644
|
+
});
|
|
1645
|
+
const retained = boundBrowserSessionEventWindow([...prefix.events, ...following], {
|
|
1646
|
+
direction: "oldest"
|
|
1647
|
+
});
|
|
1648
|
+
if (!retained.events.some((event) => event.sequence === sequence)) return false;
|
|
1649
|
+
streamAbortRef.current?.abort();
|
|
1650
|
+
generationRef.current += 1;
|
|
1651
|
+
const status = observeSessionStatus(retained.events, sessionStatusRef);
|
|
1652
|
+
eventWindowRef.current = retained;
|
|
1653
|
+
oldestSequenceRef.current = retained.events[0].sequence;
|
|
1654
|
+
newestSequenceRef.current = maxResumeSequenceOrNull(retained.events);
|
|
1655
|
+
lastSequenceRef.current = Math.max(lastSequenceRef.current, newestSequenceRef.current ?? 0);
|
|
1656
|
+
hasOlderRef.current = !isLogStart(retained.events[0]);
|
|
1657
|
+
hasNewerRef.current = following.length > 0 || retained.truncated || (newestSequenceRef.current ?? 0) < lastSequenceRef.current;
|
|
1658
|
+
initialWindowLoadedRef.current = true;
|
|
1659
|
+
setInitialHistoryReady(true);
|
|
1660
|
+
setError(null);
|
|
1661
|
+
viewModeRef.current = "history";
|
|
1662
|
+
setEventWindow(retained);
|
|
1663
|
+
setHasOlder(hasOlderRef.current);
|
|
1664
|
+
setHasNewer(hasNewerRef.current);
|
|
1665
|
+
setInitialLoading(false);
|
|
1666
|
+
setViewMode("history");
|
|
1667
|
+
setNewerError(null);
|
|
1668
|
+
if (status !== void 0) setSessionStatusProjection(status);
|
|
1669
|
+
published = true;
|
|
1670
|
+
return true;
|
|
1671
|
+
} catch (reason) {
|
|
1672
|
+
if (!current() || signal?.aborted) return false;
|
|
1673
|
+
throw reason;
|
|
1674
|
+
} finally {
|
|
1675
|
+
if (current()) {
|
|
1676
|
+
loadingTargetRef.current = false;
|
|
1677
|
+
setLoadingTarget(false);
|
|
1678
|
+
if (!published && previousMode === "live") {
|
|
1679
|
+
viewModeRef.current = "live";
|
|
1680
|
+
setViewMode("live");
|
|
1681
|
+
setStreamEpoch((epoch) => epoch + 1);
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
}
|
|
1685
|
+
},
|
|
1686
|
+
[client, workspaceId, sessionId, ownsNavigation]
|
|
1687
|
+
);
|
|
1688
|
+
const jumpToLatestQuestion = useCallback6(
|
|
1689
|
+
async (questionOptions) => {
|
|
1690
|
+
if (!sessionId || !ownsNavigation()) return null;
|
|
1691
|
+
let generation = navigationGenerationRef.current;
|
|
1692
|
+
const current = () => ownsNavigation() && generation === navigationGenerationRef.current;
|
|
1693
|
+
try {
|
|
1694
|
+
const { resolveLatestQuestion } = await import("./latest-question-SXBXROBT.js");
|
|
1695
|
+
if (!current()) return null;
|
|
1696
|
+
const destination = await resolveLatestQuestion(t, {
|
|
1697
|
+
client,
|
|
1698
|
+
workspaceId,
|
|
1699
|
+
sessionId,
|
|
1700
|
+
isCurrent: current,
|
|
1701
|
+
resumeSequence: maxResumeSequence,
|
|
1702
|
+
options: questionOptions
|
|
1703
|
+
});
|
|
1704
|
+
if (!destination || !current()) return null;
|
|
1705
|
+
if (!eventWindowRef.current.events.some((event) => event.sequence === destination.anchor)) {
|
|
1706
|
+
const navigation = jumpToSequence(destination.anchor);
|
|
1707
|
+
generation = navigationGenerationRef.current;
|
|
1708
|
+
if (!await navigation || !current()) return null;
|
|
1709
|
+
}
|
|
1710
|
+
setQuestionEvidence({
|
|
1711
|
+
client,
|
|
1712
|
+
streamKey,
|
|
1713
|
+
anchor: destination.anchor,
|
|
1714
|
+
events: destination.events
|
|
1715
|
+
});
|
|
1716
|
+
return destination.questionSequence;
|
|
1717
|
+
} catch (reason) {
|
|
1718
|
+
if (!current()) return null;
|
|
1719
|
+
throw reason;
|
|
1720
|
+
}
|
|
1721
|
+
},
|
|
1722
|
+
[client, workspaceId, sessionId, streamKey, ownsNavigation, jumpToSequence, t]
|
|
1723
|
+
);
|
|
1724
|
+
const jumpToLatest = useCallback6(async () => {
|
|
1725
|
+
if (!ownsNavigation()) return;
|
|
1726
|
+
if (loadingTargetRef.current) {
|
|
1727
|
+
navigationGenerationRef.current += 1;
|
|
1728
|
+
loadingTargetRef.current = false;
|
|
1729
|
+
setLoadingTarget(false);
|
|
1730
|
+
}
|
|
1731
|
+
if (!sessionId || navigationBusy()) {
|
|
1732
|
+
return;
|
|
1733
|
+
}
|
|
1734
|
+
navigationGenerationRef.current += 1;
|
|
1735
|
+
setQuestionEvidence(null);
|
|
1736
|
+
loadingLatestRef.current = true;
|
|
1737
|
+
setLoadingLatest(true);
|
|
1738
|
+
setNewerError(null);
|
|
1739
|
+
setError(null);
|
|
1740
|
+
let published = false;
|
|
1741
|
+
try {
|
|
1742
|
+
streamAbortRef.current?.abort();
|
|
1743
|
+
hasNewerRef.current = false;
|
|
1744
|
+
hasOlderRef.current = false;
|
|
1745
|
+
newestSequenceRef.current = null;
|
|
1746
|
+
oldestSequenceRef.current = null;
|
|
1747
|
+
eventWindowRef.current = EMPTY_EVENT_WINDOW;
|
|
1748
|
+
initialWindowLoadedRef.current = false;
|
|
1749
|
+
streamResumeSequenceRef.current = after;
|
|
1750
|
+
viewModeRef.current = "live";
|
|
1751
|
+
loadingLatestRef.current = false;
|
|
1752
|
+
startTransition(() => {
|
|
1753
|
+
setHasNewer(false);
|
|
1754
|
+
setHasOlder(false);
|
|
1755
|
+
setEventWindow(EMPTY_EVENT_WINDOW);
|
|
1756
|
+
setInitialLoading(true);
|
|
1757
|
+
setViewMode("live");
|
|
1758
|
+
setStreamEpoch((epoch) => epoch + 1);
|
|
1759
|
+
setLoadingLatest(false);
|
|
1760
|
+
});
|
|
1761
|
+
published = true;
|
|
1762
|
+
await Promise.resolve();
|
|
1763
|
+
} finally {
|
|
1764
|
+
if (!published) {
|
|
1765
|
+
loadingLatestRef.current = false;
|
|
1766
|
+
setLoadingLatest(false);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
}, [after, sessionId, ownsNavigation]);
|
|
1770
|
+
const identityMatches = stateStreamKey === streamKey;
|
|
1771
|
+
const freshTail = identityMatches && initialHistoryReady && viewMode === "live" && !fullReplay ? {
|
|
1772
|
+
events: eventWindow.events,
|
|
1773
|
+
hasOlder,
|
|
1774
|
+
truncated: eventWindow.truncated,
|
|
1775
|
+
bytes: eventWindow.bytes,
|
|
1776
|
+
sessionStatus: sessionStatusProjection
|
|
1777
|
+
} : null;
|
|
1778
|
+
const retainedTail = useRetainedSessionView(client, workspaceId, sessionId, "events", freshTail, {
|
|
1779
|
+
enabled: !fullReplay,
|
|
1780
|
+
bytes: (tail) => tail.bytes,
|
|
1781
|
+
budgetBytes: SESSION_EVENT_BROWSER_MAX_BYTES,
|
|
1782
|
+
discard: identityMatches && deniesRetainedView(error)
|
|
1783
|
+
});
|
|
1784
|
+
const showRetained = retainedTail !== null && !(identityMatches && initialHistoryReady);
|
|
1785
|
+
const visibleEvents = showRetained ? retainedTail.events : identityMatches ? eventWindow.events : EMPTY_EVENTS;
|
|
1786
|
+
const visibleHasOlder = showRetained ? retainedTail.hasOlder : identityMatches && hasOlder;
|
|
1787
|
+
const visibleTruncated = showRetained ? retainedTail.truncated : eventWindow.truncated;
|
|
1788
|
+
const timeline = useMemo3(() => {
|
|
1789
|
+
const witness = questionEvidence?.client === client && questionEvidence.streamKey === streamKey && visibleEvents.some((event) => event.sequence === questionEvidence.anchor) ? questionEvidence.events : EMPTY_EVENTS;
|
|
1790
|
+
const timelineOptions = { partialStart: visibleHasOlder || visibleTruncated || after > 0 };
|
|
1791
|
+
if (witness.length === 0) return buildTimeline(t, visibleEvents, timelineOptions);
|
|
1792
|
+
const ids = new Set(visibleEvents.map((event) => event.id));
|
|
1793
|
+
return buildTimeline(
|
|
1794
|
+
t,
|
|
1795
|
+
[...visibleEvents, ...witness.filter((event) => !ids.has(event.id))],
|
|
1796
|
+
timelineOptions
|
|
1797
|
+
);
|
|
1798
|
+
}, [
|
|
1799
|
+
visibleEvents,
|
|
1800
|
+
visibleHasOlder,
|
|
1801
|
+
visibleTruncated,
|
|
1802
|
+
after,
|
|
1803
|
+
questionEvidence,
|
|
1804
|
+
client,
|
|
1805
|
+
streamKey,
|
|
1806
|
+
t
|
|
1807
|
+
]);
|
|
1808
|
+
return {
|
|
1809
|
+
events: visibleEvents,
|
|
1810
|
+
timeline,
|
|
1811
|
+
sessionStatus: showRetained ? retainedTail.sessionStatus : identityMatches ? sessionStatusProjection : null,
|
|
1812
|
+
sessionStatusSequence: identityMatches ? sessionStatusRef.current.sequence : 0,
|
|
1813
|
+
connectionState: identityMatches ? connectionState : "idle",
|
|
1814
|
+
lastSequence: identityMatches ? lastSequenceRef.current : after,
|
|
1815
|
+
windowBytes: identityMatches ? eventWindow.bytes : 2,
|
|
1816
|
+
windowTruncated: identityMatches ? eventWindow.truncated : false,
|
|
1817
|
+
initialLoading: fullReplay || showRetained ? false : identityMatches ? initialLoading : true,
|
|
1818
|
+
initialHistoryReady: identityMatches && initialHistoryReady,
|
|
1819
|
+
hasOlder: visibleHasOlder,
|
|
1820
|
+
loadingOlder: !identityMatches ? false : loadingOlder,
|
|
1821
|
+
loadOlder,
|
|
1822
|
+
hasNewer: !identityMatches ? false : hasNewer,
|
|
1823
|
+
loadingNewer: !identityMatches ? false : loadingNewer,
|
|
1824
|
+
loadNewer,
|
|
1825
|
+
loadingOldest: !identityMatches ? false : loadingOldest,
|
|
1826
|
+
loadOldest,
|
|
1827
|
+
loadingLatest: !identityMatches ? false : loadingLatest,
|
|
1828
|
+
jumpToLatest,
|
|
1829
|
+
jumpToLatestQuestion,
|
|
1830
|
+
jumpToSequence,
|
|
1831
|
+
loadingTarget: identityMatches && loadingTarget,
|
|
1832
|
+
error: identityMatches ? newerError ?? error : null
|
|
1833
|
+
};
|
|
1834
|
+
}
|
|
1835
|
+
function boundBrowserSessionEventWindow(events, options = {}) {
|
|
1836
|
+
const maxBytes = Math.max(1024, options.maxBytes ?? SESSION_EVENT_BROWSER_MAX_BYTES);
|
|
1837
|
+
const maxCount = Math.max(1, Math.floor(options.maxCount ?? SESSION_EVENT_BROWSER_MAX_COUNT));
|
|
1838
|
+
const safe = events;
|
|
1839
|
+
const selected = [];
|
|
1840
|
+
let bytes = 2;
|
|
1841
|
+
const direction = options.direction ?? "newest";
|
|
1842
|
+
const start = direction === "newest" ? safe.length - 1 : 0;
|
|
1843
|
+
const end = direction === "newest" ? Math.max(-1, safe.length - maxCount - 1) : safe.length;
|
|
1844
|
+
const step = direction === "newest" ? -1 : 1;
|
|
1845
|
+
for (let index = start; index !== end && selected.length < maxCount; index += step) {
|
|
1846
|
+
const event = safe[index];
|
|
1847
|
+
const eventBytes = browserJsonBytes(event);
|
|
1848
|
+
const separator = selected.length === 0 ? 0 : 1;
|
|
1849
|
+
if (selected.length > 0 && bytes + separator + eventBytes > maxBytes) break;
|
|
1850
|
+
selected.push(event);
|
|
1851
|
+
bytes += separator + eventBytes;
|
|
1852
|
+
}
|
|
1853
|
+
if (direction === "newest") selected.reverse();
|
|
1854
|
+
return {
|
|
1855
|
+
events: selected,
|
|
1856
|
+
bytes,
|
|
1857
|
+
truncated: selected.length < safe.length
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
function appendBrowserSessionEventWindow(current, batch, options = {}) {
|
|
1861
|
+
const maxBytes = Math.max(1024, options.maxBytes ?? SESSION_EVENT_BROWSER_MAX_BYTES);
|
|
1862
|
+
const maxCount = Math.max(1, Math.floor(options.maxCount ?? SESSION_EVENT_BROWSER_MAX_COUNT));
|
|
1863
|
+
const events = [...current.events, ...batch];
|
|
1864
|
+
let bytes = current.bytes;
|
|
1865
|
+
for (let index = 0; index < batch.length; index += 1) {
|
|
1866
|
+
bytes += browserJsonBytes(batch[index]) + (current.events.length + index > 0 ? 1 : 0);
|
|
1867
|
+
}
|
|
1868
|
+
let start = 0;
|
|
1869
|
+
while (events.length - start > 1 && (bytes > maxBytes || events.length - start > maxCount)) {
|
|
1870
|
+
bytes -= browserJsonBytes(events[start]) + 1;
|
|
1871
|
+
start += 1;
|
|
1872
|
+
}
|
|
1873
|
+
return {
|
|
1874
|
+
events: start === 0 ? events : events.slice(start),
|
|
1875
|
+
bytes,
|
|
1876
|
+
truncated: current.truncated || start > 0
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
function browserJsonBytes(value) {
|
|
1880
|
+
return encoder.encode(JSON.stringify(value)).byteLength;
|
|
1881
|
+
}
|
|
1882
|
+
function observeSessionStatus(events, ref) {
|
|
1883
|
+
let latest = null;
|
|
1884
|
+
for (const event of events) {
|
|
1885
|
+
const status = sessionStatusFromEvents([event]);
|
|
1886
|
+
if (status && (!latest || event.sequence >= latest.sequence)) {
|
|
1887
|
+
latest = { sequence: event.sequence, status };
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1890
|
+
if (!latest || latest.sequence < ref.current.sequence) return void 0;
|
|
1891
|
+
ref.current = latest;
|
|
1892
|
+
return latest.status;
|
|
1893
|
+
}
|
|
1894
|
+
async function planForegroundCatchup(t, client, workspaceId, sessionId, cursor, options = {}) {
|
|
1895
|
+
if (options.signal?.aborted) throw abortError();
|
|
1896
|
+
const session = await client.getSession(workspaceId, sessionId, {
|
|
1897
|
+
fresh: true,
|
|
1898
|
+
...options.signal ? { signal: options.signal } : {}
|
|
1899
|
+
});
|
|
1900
|
+
if (options.signal?.aborted) throw abortError();
|
|
1901
|
+
const durableHead = Math.max(cursor, session.lastSequence);
|
|
1902
|
+
const rawGap = durableHead - cursor;
|
|
1903
|
+
if (rawGap <= FOREGROUND_DIRECT_REPLAY_MAX_SEQUENCES) {
|
|
1904
|
+
return { kind: "resume" };
|
|
1905
|
+
}
|
|
1906
|
+
if (rawGap > FOREGROUND_COMPACT_PROBE_MAX_SEQUENCES) {
|
|
1907
|
+
return { kind: "reload" };
|
|
1908
|
+
}
|
|
1909
|
+
const page = await loadNextPage(client, workspaceId, sessionId, cursor, {
|
|
1910
|
+
pageSize: rawGap,
|
|
1911
|
+
...options.signal ? { signal: options.signal } : {}
|
|
1912
|
+
});
|
|
1913
|
+
const events = page.filter((event) => eventResumeSequence(event) > cursor);
|
|
1914
|
+
if (events.length === 0) {
|
|
1915
|
+
return { kind: "reload" };
|
|
1916
|
+
}
|
|
1917
|
+
assertAscending(events);
|
|
1918
|
+
const resumeSequence = maxResumeSequence(events);
|
|
1919
|
+
if (resumeSequence < durableHead) {
|
|
1920
|
+
return { kind: "reload" };
|
|
1921
|
+
}
|
|
1922
|
+
if (events.length > FOREGROUND_COMPACT_CATCHUP_MAX_EVENTS || groupCount(t, events) > FOREGROUND_COMPACT_CATCHUP_MAX_GROUPS || browserJsonBytes(events) > FOREGROUND_COMPACT_CATCHUP_MAX_BYTES) {
|
|
1923
|
+
return { kind: "reload" };
|
|
1924
|
+
}
|
|
1925
|
+
return { kind: "append", events, resumeSequence };
|
|
1926
|
+
}
|
|
1927
|
+
async function loadEventWindow(t, client, workspaceId, sessionId, options) {
|
|
1928
|
+
let cursor = options.before;
|
|
1929
|
+
let buffer = [];
|
|
1930
|
+
let reachedStart = false;
|
|
1931
|
+
let fetches = 0;
|
|
1932
|
+
while (fetches < options.maxFetches) {
|
|
1933
|
+
if (buffer.length > 0 && groupCount(t, buffer) >= options.targetGroups) {
|
|
1934
|
+
break;
|
|
1935
|
+
}
|
|
1936
|
+
const page = await loadPreviousPage(client, workspaceId, sessionId, cursor, {
|
|
1937
|
+
pageSize: options.pageSize,
|
|
1938
|
+
...options.signal ? { signal: options.signal } : {}
|
|
1939
|
+
});
|
|
1940
|
+
if (options.isCurrent?.() === false) throw abortError();
|
|
1941
|
+
fetches += 1;
|
|
1942
|
+
if (page.length === 0) {
|
|
1943
|
+
reachedStart = true;
|
|
1944
|
+
break;
|
|
1945
|
+
}
|
|
1946
|
+
assertAscending(page);
|
|
1947
|
+
buffer = [...page, ...buffer];
|
|
1948
|
+
cursor = page[0].sequence;
|
|
1949
|
+
if (isLogStart(page[0])) {
|
|
1950
|
+
reachedStart = true;
|
|
1951
|
+
break;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
let snapPages = 0;
|
|
1955
|
+
while (!reachedStart && findBoundaryIndex(buffer) === -1 && snapPages < (options.boundaryPageCap ?? 0)) {
|
|
1956
|
+
const page = await loadPreviousPage(client, workspaceId, sessionId, cursor, {
|
|
1957
|
+
pageSize: options.pageSize,
|
|
1958
|
+
...options.signal ? { signal: options.signal } : {}
|
|
1959
|
+
});
|
|
1960
|
+
if (options.isCurrent?.() === false) throw abortError();
|
|
1961
|
+
fetches += 1;
|
|
1962
|
+
snapPages += 1;
|
|
1963
|
+
if (page.length === 0) {
|
|
1964
|
+
reachedStart = true;
|
|
1965
|
+
break;
|
|
1966
|
+
}
|
|
1967
|
+
assertAscending(page);
|
|
1968
|
+
buffer = [...page, ...buffer];
|
|
1969
|
+
cursor = page[0].sequence;
|
|
1970
|
+
if (isLogStart(page[0])) {
|
|
1971
|
+
reachedStart = true;
|
|
1972
|
+
break;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
if (!reachedStart) {
|
|
1976
|
+
const boundary = findBoundaryIndex(buffer);
|
|
1977
|
+
if (boundary > 0) {
|
|
1978
|
+
buffer = buffer.slice(boundary);
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
const densityWindow = trimBackwardToGroupTarget(t, buffer, options.targetGroups);
|
|
1982
|
+
buffer = densityWindow.events;
|
|
1983
|
+
const oldest = buffer[0] ?? null;
|
|
1984
|
+
const newest = buffer[buffer.length - 1] ?? null;
|
|
1985
|
+
return {
|
|
1986
|
+
events: buffer,
|
|
1987
|
+
oldestSequence: oldest?.sequence ?? null,
|
|
1988
|
+
newestSequence: newest ? maxResumeSequence(buffer) : 0,
|
|
1989
|
+
hasOlder: buffer.length > 0 && (densityWindow.trimmed || !reachedStart && oldest?.type !== "session.created")
|
|
1990
|
+
};
|
|
1991
|
+
}
|
|
1992
|
+
function findBoundaryIndex(events) {
|
|
1993
|
+
for (let index = 0; index < events.length; index += 1) {
|
|
1994
|
+
if (isTurnBoundary(events[index])) {
|
|
1995
|
+
return index;
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
return -1;
|
|
1999
|
+
}
|
|
2000
|
+
function isTurnBoundary(event) {
|
|
2001
|
+
return event.type === "session.created" || event.type === "user.message";
|
|
2002
|
+
}
|
|
2003
|
+
async function loadForwardEventWindow(t, client, workspaceId, sessionId, options) {
|
|
2004
|
+
let cursor = options.after;
|
|
2005
|
+
let buffer = [];
|
|
2006
|
+
let fetches = 0;
|
|
2007
|
+
let reachedEnd = false;
|
|
2008
|
+
while (fetches < options.maxFetches) {
|
|
2009
|
+
if (buffer.length > 0 && groupCount(t, buffer) >= options.targetGroups) {
|
|
2010
|
+
break;
|
|
2011
|
+
}
|
|
2012
|
+
const page = await loadNextPage(client, workspaceId, sessionId, cursor, {
|
|
2013
|
+
pageSize: options.pageSize,
|
|
2014
|
+
...options.signal ? { signal: options.signal } : {}
|
|
2015
|
+
});
|
|
2016
|
+
if (options.isCurrent?.() === false) throw abortError();
|
|
2017
|
+
fetches += 1;
|
|
2018
|
+
if (page.length === 0) {
|
|
2019
|
+
reachedEnd = true;
|
|
2020
|
+
break;
|
|
2021
|
+
}
|
|
2022
|
+
assertAscending(page);
|
|
2023
|
+
buffer = [...buffer, ...page];
|
|
2024
|
+
cursor = maxResumeSequence(page);
|
|
2025
|
+
}
|
|
2026
|
+
const densityWindow = trimForwardToGroupTarget(t, buffer, options.targetGroups);
|
|
2027
|
+
buffer = densityWindow.events;
|
|
2028
|
+
const oldest = buffer[0] ?? null;
|
|
2029
|
+
const newest = buffer[buffer.length - 1] ?? null;
|
|
2030
|
+
return {
|
|
2031
|
+
events: buffer,
|
|
2032
|
+
oldestSequence: oldest?.sequence ?? null,
|
|
2033
|
+
newestSequence: newest ? maxResumeSequence(buffer) : 0,
|
|
2034
|
+
hasNewer: buffer.length > 0 && (densityWindow.trimmed || !reachedEnd)
|
|
2035
|
+
};
|
|
2036
|
+
}
|
|
2037
|
+
function trimBackwardToGroupTarget(t, events, targetGroups) {
|
|
2038
|
+
if (!Number.isFinite(targetGroups) || targetGroups <= 0 || events.length === 0) {
|
|
2039
|
+
return { events, trimmed: false };
|
|
2040
|
+
}
|
|
2041
|
+
for (let index = events.length - 1; index > 0; index -= 1) {
|
|
2042
|
+
if (!isTurnBoundary(events[index])) continue;
|
|
2043
|
+
const candidate = events.slice(index);
|
|
2044
|
+
if (groupCount(t, candidate) >= targetGroups) {
|
|
2045
|
+
return { events: candidate, trimmed: true };
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
return { events, trimmed: false };
|
|
2049
|
+
}
|
|
2050
|
+
function trimForwardToGroupTarget(t, events, targetGroups) {
|
|
2051
|
+
if (!Number.isFinite(targetGroups) || targetGroups <= 0 || events.length === 0) {
|
|
2052
|
+
return { events, trimmed: false };
|
|
2053
|
+
}
|
|
2054
|
+
for (let index = 1; index < events.length; index += 1) {
|
|
2055
|
+
if (!isTurnBoundary(events[index])) continue;
|
|
2056
|
+
const candidate = events.slice(0, index);
|
|
2057
|
+
if (groupCount(t, candidate) >= targetGroups) {
|
|
2058
|
+
return { events: candidate, trimmed: true };
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
return { events, trimmed: false };
|
|
2062
|
+
}
|
|
2063
|
+
async function loadPreviousPage(client, workspaceId, sessionId, before, options) {
|
|
2064
|
+
if (options.signal?.aborted) {
|
|
2065
|
+
throw abortError();
|
|
2066
|
+
}
|
|
2067
|
+
const requested = options.pageSize;
|
|
2068
|
+
if (requested === 0) {
|
|
2069
|
+
return Object.assign([], { requested });
|
|
2070
|
+
}
|
|
2071
|
+
const page = await client.listEvents(workspaceId, sessionId, {
|
|
2072
|
+
before,
|
|
2073
|
+
limit: requested,
|
|
2074
|
+
compact: true,
|
|
2075
|
+
// Monitoring summaries omit correlation fields once a bounded durable
|
|
2076
|
+
// payload exceeds their preview threshold. The browser timeline needs the
|
|
2077
|
+
// exact stored payload so persisted tool outputs still match their
|
|
2078
|
+
// calls and expose truthful truncation telemetry after a reload.
|
|
2079
|
+
payloadMode: "full"
|
|
2080
|
+
});
|
|
2081
|
+
if (options.signal?.aborted) {
|
|
2082
|
+
throw abortError();
|
|
2083
|
+
}
|
|
2084
|
+
return Object.assign(page, { requested });
|
|
2085
|
+
}
|
|
2086
|
+
async function loadNextPage(client, workspaceId, sessionId, after, options) {
|
|
2087
|
+
if (options.signal?.aborted) {
|
|
2088
|
+
throw abortError();
|
|
2089
|
+
}
|
|
2090
|
+
const requested = options.pageSize;
|
|
2091
|
+
if (requested === 0) {
|
|
2092
|
+
return Object.assign([], { requested });
|
|
2093
|
+
}
|
|
2094
|
+
const page = await client.listEvents(workspaceId, sessionId, {
|
|
2095
|
+
after,
|
|
2096
|
+
limit: requested,
|
|
2097
|
+
compact: true,
|
|
2098
|
+
direction: "after",
|
|
2099
|
+
payloadMode: "full"
|
|
2100
|
+
});
|
|
2101
|
+
if (options.signal?.aborted) {
|
|
2102
|
+
throw abortError();
|
|
2103
|
+
}
|
|
2104
|
+
return Object.assign(page, { requested });
|
|
2105
|
+
}
|
|
2106
|
+
function groupCount(t, events) {
|
|
2107
|
+
if (events.length === 0) {
|
|
2108
|
+
return 0;
|
|
2109
|
+
}
|
|
2110
|
+
return groupTimeline(t, buildTimeline(t, events)).length;
|
|
2111
|
+
}
|
|
2112
|
+
function isLogStart(event) {
|
|
2113
|
+
return event.type === "session.created" || event.sequence <= 1;
|
|
2114
|
+
}
|
|
2115
|
+
function maxResumeSequence(events) {
|
|
2116
|
+
return events.reduce((max, event) => Math.max(max, eventResumeSequence(event)), 0);
|
|
2117
|
+
}
|
|
2118
|
+
function maxResumeSequenceOrNull(events) {
|
|
2119
|
+
return events.length > 0 ? maxResumeSequence(events) : null;
|
|
2120
|
+
}
|
|
2121
|
+
function eventResumeSequence(event) {
|
|
2122
|
+
const streamedCoverage = sessionEventStreamCoveredThrough(event);
|
|
2123
|
+
if (streamedCoverage !== null) return streamedCoverage;
|
|
2124
|
+
return typeof event.coveredThrough === "number" && Number.isSafeInteger(event.coveredThrough) && event.coveredThrough >= event.sequence ? event.coveredThrough : event.sequence;
|
|
2125
|
+
}
|
|
2126
|
+
function assertAscending(events) {
|
|
2127
|
+
for (let index = 1; index < events.length; index += 1) {
|
|
2128
|
+
if (events[index - 1].sequence >= events[index].sequence) {
|
|
2129
|
+
throw new Error("@opengeni/react: session events must be ordered by ascending sequence");
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
function assertPrependOrder(existing, older) {
|
|
2134
|
+
if (!shouldAssertDevelopment() || existing.length === 0 || older.length === 0) {
|
|
2135
|
+
return;
|
|
2136
|
+
}
|
|
2137
|
+
if (older[older.length - 1].sequence >= existing[0].sequence) {
|
|
2138
|
+
throw new Error("@opengeni/react: loadOlder returned overlapping session events");
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
function assertAppendOrder(existing, newer) {
|
|
2142
|
+
if (!shouldAssertDevelopment() || existing.length === 0 || newer.length === 0) {
|
|
2143
|
+
return;
|
|
2144
|
+
}
|
|
2145
|
+
if (newer[0].sequence <= existing[existing.length - 1].sequence) {
|
|
2146
|
+
throw new Error("@opengeni/react: loadNewer returned overlapping session events");
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
function shouldAssertDevelopment() {
|
|
2150
|
+
const processEnv = globalThis.process?.env;
|
|
2151
|
+
return processEnv !== void 0 && processEnv.NODE_ENV !== "production";
|
|
2152
|
+
}
|
|
2153
|
+
function abortError() {
|
|
2154
|
+
const error = new Error("The operation was aborted.");
|
|
2155
|
+
error.name = "AbortError";
|
|
2156
|
+
return error;
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
// src/hooks/use-turn-queue.ts
|
|
2160
|
+
import { useCallback as useCallback7, useEffect as useEffect6, useLayoutEffect as useLayoutEffect3, useMemo as useMemo4, useRef as useRef7, useState as useState5 } from "react";
|
|
2161
|
+
function isTurnQueueEvent(event) {
|
|
2162
|
+
return event.type.startsWith("turn.") || event.type.startsWith("session.queue.") || event.type.startsWith("session.control.") || event.type.startsWith("system.update.") || event.type.startsWith("workspace.inference.");
|
|
2163
|
+
}
|
|
2164
|
+
function queueSnapshotCovers(candidate, observed) {
|
|
2165
|
+
return Boolean(
|
|
2166
|
+
candidate && candidate.version >= observed.version && candidate.effectiveControl.controlVersion >= observed.effectiveControl.controlVersion
|
|
2167
|
+
);
|
|
2168
|
+
}
|
|
2169
|
+
var EMPTY_PENDING_BY_TURN = {};
|
|
2170
|
+
function useTurnQueue(sessionId, options = {}) {
|
|
2171
|
+
const t = useOpenGeniText();
|
|
2172
|
+
const { client, workspaceId, workspaceControlEvent, registerSessionReconciler } = useEmbeddedSession(options);
|
|
2173
|
+
const enabled = (options.enabled ?? true) && Boolean(sessionId);
|
|
2174
|
+
const targetKey = `${workspaceId}\0${sessionId ?? ""}`;
|
|
2175
|
+
const pageLive = usePageLiveActivity();
|
|
2176
|
+
const [snapshot, setSnapshot] = useState5(null);
|
|
2177
|
+
const [stateTargetKey, setStateTargetKey] = useState5(targetKey);
|
|
2178
|
+
const [loading, setLoading] = useState5(enabled);
|
|
2179
|
+
const [error, setError] = useState5(null);
|
|
2180
|
+
const [mutationError, setMutationError] = useState5(null);
|
|
2181
|
+
const [pendingByTurn, setPendingByTurn] = useState5({});
|
|
2182
|
+
const [acceptedSteers, setAcceptedSteers] = useState5([]);
|
|
2183
|
+
const pendingRef = useRef7({});
|
|
2184
|
+
const readGeneration = useRef7(0);
|
|
2185
|
+
const targetKeyRef = useRef7(targetKey);
|
|
2186
|
+
const snapshotRef = useRef7(null);
|
|
2187
|
+
useLayoutEffect3(() => {
|
|
2188
|
+
if (targetKeyRef.current === targetKey) return;
|
|
2189
|
+
targetKeyRef.current = targetKey;
|
|
2190
|
+
readGeneration.current += 1;
|
|
2191
|
+
snapshotRef.current = null;
|
|
2192
|
+
pendingRef.current = {};
|
|
2193
|
+
setStateTargetKey(targetKey);
|
|
2194
|
+
setSnapshot(null);
|
|
2195
|
+
setLoading(enabled);
|
|
2196
|
+
setError(null);
|
|
2197
|
+
setMutationError(null);
|
|
2198
|
+
setPendingByTurn({});
|
|
2199
|
+
setAcceptedSteers([]);
|
|
2200
|
+
}, [enabled, targetKey]);
|
|
2201
|
+
useEffect6(() => {
|
|
2202
|
+
if (acceptedSteers.length === 0 || options.events === void 0) return;
|
|
2203
|
+
const durablyStartedTurnIds = new Set(
|
|
2204
|
+
options.events.flatMap(
|
|
2205
|
+
(event) => event.type === "turn.started" && event.turnId ? [event.turnId] : []
|
|
2206
|
+
)
|
|
2207
|
+
);
|
|
2208
|
+
if (durablyStartedTurnIds.size === 0) return;
|
|
2209
|
+
setAcceptedSteers(
|
|
2210
|
+
(current) => current.filter((steer) => !durablyStartedTurnIds.has(steer.turnId))
|
|
2211
|
+
);
|
|
2212
|
+
}, [acceptedSteers.length, options.events]);
|
|
2213
|
+
const acceptSnapshot = useCallback7(
|
|
2214
|
+
(ownedTargetKey, next) => {
|
|
2215
|
+
if (targetKeyRef.current !== ownedTargetKey) return false;
|
|
2216
|
+
const current = snapshotRef.current;
|
|
2217
|
+
if (next && current && (next.version < current.version || next.effectiveControl.controlVersion < current.effectiveControl.controlVersion)) {
|
|
2218
|
+
return false;
|
|
2219
|
+
}
|
|
2220
|
+
snapshotRef.current = next;
|
|
2221
|
+
setStateTargetKey(ownedTargetKey);
|
|
2222
|
+
setSnapshot(next);
|
|
2223
|
+
return true;
|
|
2224
|
+
},
|
|
2225
|
+
[]
|
|
2226
|
+
);
|
|
2227
|
+
const load = useCallback7(
|
|
2228
|
+
async (rejectOnFailure = false) => {
|
|
2229
|
+
if (!sessionId) return;
|
|
2230
|
+
const ownedTargetKey = `${workspaceId}\0${sessionId}`;
|
|
2231
|
+
const ticket = ++readGeneration.current;
|
|
2232
|
+
try {
|
|
2233
|
+
const fetched = await client.getQueue(workspaceId, sessionId);
|
|
2234
|
+
if (targetKeyRef.current !== ownedTargetKey) return;
|
|
2235
|
+
const ownsLatestRead = ticket === readGeneration.current;
|
|
2236
|
+
if (rejectOnFailure) {
|
|
2237
|
+
const committed = acceptSnapshot(ownedTargetKey, fetched);
|
|
2238
|
+
if (!committed && !queueSnapshotCovers(snapshotRef.current, fetched)) {
|
|
2239
|
+
throw new TypeError("Queue reconciliation did not commit authoritative state");
|
|
2240
|
+
}
|
|
2241
|
+
setError(null);
|
|
2242
|
+
if (ownsLatestRead) setLoading(false);
|
|
2243
|
+
} else if (ownsLatestRead) {
|
|
2244
|
+
acceptSnapshot(ownedTargetKey, fetched);
|
|
2245
|
+
setError(null);
|
|
2246
|
+
setLoading(false);
|
|
2247
|
+
}
|
|
2248
|
+
} catch (cause) {
|
|
2249
|
+
if (targetKeyRef.current === ownedTargetKey && (ticket === readGeneration.current || rejectOnFailure)) {
|
|
2250
|
+
setError(asError(cause));
|
|
2251
|
+
if (ticket === readGeneration.current) setLoading(false);
|
|
2252
|
+
}
|
|
2253
|
+
if (rejectOnFailure) throw cause;
|
|
2254
|
+
}
|
|
2255
|
+
},
|
|
2256
|
+
[client, workspaceId, sessionId, acceptSnapshot]
|
|
2257
|
+
);
|
|
2258
|
+
useEffect6(() => {
|
|
2259
|
+
if (!enabled || !pageLive) {
|
|
2260
|
+
setLoading(false);
|
|
2261
|
+
return;
|
|
2262
|
+
}
|
|
2263
|
+
setLoading(true);
|
|
2264
|
+
const pollIntervalMs = options.pollIntervalMs;
|
|
2265
|
+
if (pollIntervalMs === void 0 || pollIntervalMs <= 0) {
|
|
2266
|
+
void load();
|
|
2267
|
+
return () => {
|
|
2268
|
+
readGeneration.current += 1;
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
let cancelled = false;
|
|
2272
|
+
let timer = null;
|
|
2273
|
+
const schedule = () => {
|
|
2274
|
+
if (cancelled) return;
|
|
2275
|
+
timer = setTimeout(() => {
|
|
2276
|
+
timer = null;
|
|
2277
|
+
void load().finally(schedule);
|
|
2278
|
+
}, pollIntervalMs);
|
|
2279
|
+
};
|
|
2280
|
+
void load().finally(schedule);
|
|
2281
|
+
return () => {
|
|
2282
|
+
cancelled = true;
|
|
2283
|
+
if (timer !== null) clearTimeout(timer);
|
|
2284
|
+
readGeneration.current += 1;
|
|
2285
|
+
};
|
|
2286
|
+
}, [load, enabled, pageLive, options.pollIntervalMs]);
|
|
2287
|
+
useEffect6(() => {
|
|
2288
|
+
if (enabled && workspaceControlEvent) void load();
|
|
2289
|
+
}, [enabled, load, workspaceControlEvent]);
|
|
2290
|
+
useEffect6(() => {
|
|
2291
|
+
if (!sessionId || !enabled) return;
|
|
2292
|
+
return registerSessionReconciler(sessionId, "queue", load);
|
|
2293
|
+
}, [enabled, load, registerSessionReconciler, sessionId]);
|
|
2294
|
+
const scheduleRefresh = useDebouncedCallback(() => void load());
|
|
2295
|
+
const freshSnapshot = stateTargetKey === targetKey ? snapshot : null;
|
|
2296
|
+
const freshLoading = stateTargetKey === targetKey ? loading : enabled;
|
|
2297
|
+
useSessionEventTrigger(
|
|
2298
|
+
client,
|
|
2299
|
+
workspaceId,
|
|
2300
|
+
sessionId,
|
|
2301
|
+
isTurnQueueEvent,
|
|
2302
|
+
scheduleRefresh,
|
|
2303
|
+
{
|
|
2304
|
+
enabled,
|
|
2305
|
+
...options.events !== void 0 ? { events: options.events } : {},
|
|
2306
|
+
readThrough: projectionReadThrough(freshSnapshot, freshLoading),
|
|
2307
|
+
refresh: scheduleRefresh
|
|
2308
|
+
},
|
|
2309
|
+
async () => await load(true)
|
|
2310
|
+
);
|
|
2311
|
+
const retainedSnapshot = useRetainedSessionView(
|
|
2312
|
+
client,
|
|
2313
|
+
workspaceId,
|
|
2314
|
+
sessionId,
|
|
2315
|
+
"queue",
|
|
2316
|
+
freshSnapshot,
|
|
2317
|
+
{ enabled, discard: stateTargetKey === targetKey && deniesRetainedView(error) }
|
|
2318
|
+
);
|
|
2319
|
+
const mutate = useCallback7(
|
|
2320
|
+
async (turnId, kind, command) => {
|
|
2321
|
+
const ownedTargetKey = targetKey;
|
|
2322
|
+
if (!sessionId || targetKeyRef.current !== ownedTargetKey || pendingRef.current[turnId]) {
|
|
2323
|
+
return null;
|
|
2324
|
+
}
|
|
2325
|
+
const current = snapshotRef.current;
|
|
2326
|
+
const turn = current?.items.find((candidate) => candidate.id === turnId);
|
|
2327
|
+
if (!current || !turn) return null;
|
|
2328
|
+
pendingRef.current = { ...pendingRef.current, [turnId]: kind };
|
|
2329
|
+
setStateTargetKey(ownedTargetKey);
|
|
2330
|
+
setPendingByTurn(pendingRef.current);
|
|
2331
|
+
setMutationError(null);
|
|
2332
|
+
const clientEventId = operationKey();
|
|
2333
|
+
try {
|
|
2334
|
+
let result;
|
|
2335
|
+
try {
|
|
2336
|
+
result = await command(current, turn, clientEventId);
|
|
2337
|
+
} catch (cause) {
|
|
2338
|
+
if (!isOutcomeUnknownError(cause)) throw cause;
|
|
2339
|
+
result = await command(current, turn, clientEventId);
|
|
2340
|
+
}
|
|
2341
|
+
if (targetKeyRef.current !== ownedTargetKey) return null;
|
|
2342
|
+
acceptSnapshot(ownedTargetKey, result.snapshot);
|
|
2343
|
+
return result;
|
|
2344
|
+
} catch (cause) {
|
|
2345
|
+
if (targetKeyRef.current === ownedTargetKey) {
|
|
2346
|
+
setMutationError(asError(cause));
|
|
2347
|
+
await load();
|
|
2348
|
+
}
|
|
2349
|
+
return null;
|
|
2350
|
+
} finally {
|
|
2351
|
+
if (targetKeyRef.current === ownedTargetKey && turnId in pendingRef.current) {
|
|
2352
|
+
const next = { ...pendingRef.current };
|
|
2353
|
+
delete next[turnId];
|
|
2354
|
+
pendingRef.current = next;
|
|
2355
|
+
setPendingByTurn(next);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
},
|
|
2359
|
+
[acceptSnapshot, load, sessionId, targetKey]
|
|
2360
|
+
);
|
|
2361
|
+
const moveTurn = useCallback7(
|
|
2362
|
+
async (turnId, beforeTurnId) => {
|
|
2363
|
+
const result = await mutate(
|
|
2364
|
+
turnId,
|
|
2365
|
+
"move",
|
|
2366
|
+
(current, _turn, clientEventId) => client.moveQueueItem(workspaceId, sessionId, turnId, {
|
|
2367
|
+
clientEventId,
|
|
2368
|
+
expectedQueueVersion: current.version,
|
|
2369
|
+
beforeTurnId
|
|
2370
|
+
})
|
|
2371
|
+
);
|
|
2372
|
+
return result !== null;
|
|
2373
|
+
},
|
|
2374
|
+
[client, mutate, sessionId, workspaceId]
|
|
2375
|
+
);
|
|
2376
|
+
const editTurn = useCallback7(
|
|
2377
|
+
async (turnId, edit) => {
|
|
2378
|
+
const result = await mutate(
|
|
2379
|
+
turnId,
|
|
2380
|
+
"edit",
|
|
2381
|
+
(_current, turn, clientEventId) => client.editQueueItem(workspaceId, sessionId, turnId, {
|
|
2382
|
+
clientEventId,
|
|
2383
|
+
expectedTurnVersion: turn.version,
|
|
2384
|
+
expectedDraftRevision: edit.expectedDraftRevision,
|
|
2385
|
+
replaceDraft: edit.replaceDraft
|
|
2386
|
+
})
|
|
2387
|
+
);
|
|
2388
|
+
return result?.draft ?? null;
|
|
2389
|
+
},
|
|
2390
|
+
[client, mutate, sessionId, workspaceId]
|
|
2391
|
+
);
|
|
2392
|
+
const steerTurn = useCallback7(
|
|
2393
|
+
async (turnId) => {
|
|
2394
|
+
const ownedTargetKey = targetKey;
|
|
2395
|
+
const turn = snapshotRef.current?.items.find((candidate) => candidate.id === turnId);
|
|
2396
|
+
if (targetKeyRef.current !== ownedTargetKey) return false;
|
|
2397
|
+
if (!turn) {
|
|
2398
|
+
setMutationError(new Error(t("hooks.useTurnQueue.thatQueuedPromptChangedBefore")));
|
|
2399
|
+
await load();
|
|
2400
|
+
return false;
|
|
2401
|
+
}
|
|
2402
|
+
const optimistic = {
|
|
2403
|
+
turnId: turn.id,
|
|
2404
|
+
triggerEventId: turn.triggerEventId,
|
|
2405
|
+
text: turn.prompt,
|
|
2406
|
+
annotations: turn.annotations ?? [],
|
|
2407
|
+
resources: turn.resources,
|
|
2408
|
+
tools: turn.tools,
|
|
2409
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
2410
|
+
state: "sending"
|
|
2411
|
+
};
|
|
2412
|
+
setAcceptedSteers((current) => [
|
|
2413
|
+
...current.filter((steer) => steer.turnId !== turnId),
|
|
2414
|
+
optimistic
|
|
2415
|
+
]);
|
|
2416
|
+
const result = await mutate(
|
|
2417
|
+
turnId,
|
|
2418
|
+
"steer",
|
|
2419
|
+
(current, queuedTurn, clientEventId) => client.steerQueueItem(workspaceId, sessionId, turnId, {
|
|
2420
|
+
clientEventId,
|
|
2421
|
+
expectedTurnVersion: queuedTurn.version,
|
|
2422
|
+
controlEtag: current.effectiveControl.controlEtag
|
|
2423
|
+
})
|
|
2424
|
+
);
|
|
2425
|
+
if (targetKeyRef.current !== ownedTargetKey) return false;
|
|
2426
|
+
const advancedWithoutSteer = result === null && snapshotRef.current !== null && !snapshotRef.current.items.some((candidate) => candidate.id === turnId);
|
|
2427
|
+
if (advancedWithoutSteer) {
|
|
2428
|
+
setMutationError(null);
|
|
2429
|
+
setAcceptedSteers((current) => current.filter((steer) => steer.turnId !== turnId));
|
|
2430
|
+
return true;
|
|
2431
|
+
}
|
|
2432
|
+
const accepted = result !== null || snapshotRef.current?.items.some(
|
|
2433
|
+
(candidate) => candidate.id === turnId && candidate.metadata.delivery === "steer"
|
|
2434
|
+
) === true;
|
|
2435
|
+
setAcceptedSteers(
|
|
2436
|
+
(current) => accepted ? current.map(
|
|
2437
|
+
(steer) => steer.turnId === turnId ? { ...steer, state: "queued" } : steer
|
|
2438
|
+
) : current.filter((steer) => steer.turnId !== turnId)
|
|
2439
|
+
);
|
|
2440
|
+
return accepted;
|
|
2441
|
+
},
|
|
2442
|
+
[client, load, mutate, sessionId, targetKey, workspaceId, t]
|
|
2443
|
+
);
|
|
2444
|
+
const removeTurn = useCallback7(
|
|
2445
|
+
async (turnId) => {
|
|
2446
|
+
const result = await mutate(
|
|
2447
|
+
turnId,
|
|
2448
|
+
"delete",
|
|
2449
|
+
(_current, turn, clientEventId) => client.deleteQueueItem(workspaceId, sessionId, turnId, {
|
|
2450
|
+
clientEventId,
|
|
2451
|
+
expectedTurnVersion: turn.version,
|
|
2452
|
+
reason: "Deleted from the prompt queue"
|
|
2453
|
+
})
|
|
2454
|
+
);
|
|
2455
|
+
return result !== null;
|
|
2456
|
+
},
|
|
2457
|
+
[client, mutate, sessionId, workspaceId]
|
|
2458
|
+
);
|
|
2459
|
+
const identityMatches = stateTargetKey === targetKey;
|
|
2460
|
+
const visibleSnapshot = freshSnapshot ?? retainedSnapshot;
|
|
2461
|
+
const visiblePendingByTurn = identityMatches ? pendingByTurn : EMPTY_PENDING_BY_TURN;
|
|
2462
|
+
const mutating = useMemo4(
|
|
2463
|
+
() => Object.keys(visiblePendingByTurn).length > 0,
|
|
2464
|
+
[visiblePendingByTurn]
|
|
2465
|
+
);
|
|
2466
|
+
const mutationFor = useCallback7(
|
|
2467
|
+
(turnId) => visiblePendingByTurn[turnId] ?? null,
|
|
2468
|
+
[visiblePendingByTurn]
|
|
2469
|
+
);
|
|
2470
|
+
return {
|
|
2471
|
+
snapshot: visibleSnapshot,
|
|
2472
|
+
queue: visibleSnapshot?.items ?? [],
|
|
2473
|
+
pendingInputs: visibleSnapshot?.pendingInputs ?? [],
|
|
2474
|
+
pendingInputAttachment: visibleSnapshot?.pendingInputAttachment ?? null,
|
|
2475
|
+
activePersonalConnections: visibleSnapshot?.activePersonalConnections ?? [],
|
|
2476
|
+
effectiveControl: visibleSnapshot?.effectiveControl ?? null,
|
|
2477
|
+
stoppingPreviousAttempt: visibleSnapshot?.stoppingPreviousAttempt ?? false,
|
|
2478
|
+
loading: freshLoading && retainedSnapshot === null,
|
|
2479
|
+
error: identityMatches ? error : null,
|
|
2480
|
+
refresh: load,
|
|
2481
|
+
moveTurn,
|
|
2482
|
+
editTurn,
|
|
2483
|
+
steerTurn,
|
|
2484
|
+
removeTurn,
|
|
2485
|
+
pendingByTurn: visiblePendingByTurn,
|
|
2486
|
+
mutationFor,
|
|
2487
|
+
mutating,
|
|
2488
|
+
mutationError: identityMatches ? mutationError : null,
|
|
2489
|
+
clearMutationError: useCallback7(() => {
|
|
2490
|
+
if (targetKeyRef.current === targetKey) setMutationError(null);
|
|
2491
|
+
}, [targetKey]),
|
|
2492
|
+
acceptedSteers: identityMatches ? acceptedSteers : []
|
|
2493
|
+
};
|
|
2494
|
+
}
|
|
2495
|
+
function operationKey() {
|
|
2496
|
+
return globalThis.crypto.randomUUID();
|
|
2497
|
+
}
|
|
2498
|
+
function asError(cause) {
|
|
2499
|
+
return normalizeError(cause);
|
|
2500
|
+
}
|
|
2501
|
+
function isOutcomeUnknownError(cause) {
|
|
2502
|
+
return typeof cause === "object" && cause !== null && cause.outcomeUnknown === true;
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
// src/hooks/use-session-conversation.ts
|
|
2506
|
+
import { useLayoutEffect as useLayoutEffect4, useMemo as useMemo5, useRef as useRef8 } from "react";
|
|
2507
|
+
|
|
2508
|
+
// src/hooks/use-client-config-flags.ts
|
|
2509
|
+
import { useEffect as useEffect7, useState as useState6 } from "react";
|
|
2510
|
+
var INITIAL_FLAGS = {
|
|
2511
|
+
loaded: false,
|
|
2512
|
+
uploads: false,
|
|
2513
|
+
modelSelection: false,
|
|
2514
|
+
sandboxFiles: false,
|
|
2515
|
+
defaultReasoningEffort: null,
|
|
2516
|
+
artifacts: true,
|
|
2517
|
+
sessionCreation: true,
|
|
2518
|
+
archive: true,
|
|
2519
|
+
voiceInput: null,
|
|
2520
|
+
realtimeVoice: false,
|
|
2521
|
+
realtimeVoiceOffered: false
|
|
2522
|
+
};
|
|
2523
|
+
function useClientConfigFlags(client) {
|
|
2524
|
+
const [flags, setFlags] = useState6(INITIAL_FLAGS);
|
|
2525
|
+
useEffect7(() => {
|
|
2526
|
+
if (typeof client.getClientConfig !== "function") return;
|
|
2527
|
+
let live = true;
|
|
2528
|
+
cachedClientConfigRead(client).then(
|
|
2529
|
+
(config) => {
|
|
2530
|
+
if (live) {
|
|
2531
|
+
setFlags({
|
|
2532
|
+
loaded: true,
|
|
2533
|
+
uploads: config.fileUploads?.enabled === true,
|
|
2534
|
+
// Only an explicit offer shows end users the picker.
|
|
2535
|
+
modelSelection: config.modelSelection === true,
|
|
2536
|
+
sandboxFiles: config.sandboxFiles !== false,
|
|
2537
|
+
defaultReasoningEffort: config.defaultReasoningEffort ?? null,
|
|
2538
|
+
artifacts: config.artifacts !== false,
|
|
2539
|
+
sessionCreation: config.sessionCreation !== false,
|
|
2540
|
+
archive: config.archive !== false,
|
|
2541
|
+
voiceInput: config.voiceInput?.available === true ? config.voiceInput : null,
|
|
2542
|
+
realtimeVoice: config.realtimeVoice !== false,
|
|
2543
|
+
realtimeVoiceOffered: config.realtimeVoice === true
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2546
|
+
},
|
|
2547
|
+
() => void 0
|
|
2548
|
+
);
|
|
2549
|
+
return () => {
|
|
2550
|
+
live = false;
|
|
2551
|
+
};
|
|
2552
|
+
}, [client]);
|
|
2553
|
+
return flags;
|
|
2554
|
+
}
|
|
2555
|
+
|
|
2556
|
+
// src/hooks/use-session-conversation.ts
|
|
2557
|
+
function useSessionConversation(sessionId, options = {}) {
|
|
2558
|
+
const context = useOpenGeni(options);
|
|
2559
|
+
const scope = { client: context.client, workspaceId: context.workspaceId };
|
|
2560
|
+
const config = useClientConfigFlags(context.client);
|
|
2561
|
+
const showModelPicker = options.modelPicker ?? config.modelSelection;
|
|
2562
|
+
const catalog = useWorkspaceModelCatalog({ ...scope, enabled: showModelPicker });
|
|
2563
|
+
const feed = useSessionEvents(sessionId, scope);
|
|
2564
|
+
const eventOptions = { ...scope, events: feed.events };
|
|
2565
|
+
const detail = useSession(sessionId, eventOptions);
|
|
2566
|
+
const queue = useTurnQueue(sessionId, eventOptions);
|
|
2567
|
+
const human = useHumanInputRequests(sessionId, eventOptions);
|
|
2568
|
+
const control = useSessionControl(sessionId, scope);
|
|
2569
|
+
const approvals = useMemo5(() => projectPendingApprovals(feed.events), [feed.events]);
|
|
2570
|
+
const files = useFileAttachments(scope);
|
|
2571
|
+
const clearFiles = files.clear;
|
|
2572
|
+
const attachmentSession = useRef8(sessionId);
|
|
2573
|
+
useLayoutEffect4(() => {
|
|
2574
|
+
if (attachmentSession.current === sessionId) return;
|
|
2575
|
+
attachmentSession.current = sessionId;
|
|
2576
|
+
clearFiles();
|
|
2577
|
+
}, [clearFiles, sessionId]);
|
|
2578
|
+
const uploadsEnabled = (options.attachments ?? true) && config.uploads;
|
|
2579
|
+
const status = feed.sessionStatus ?? detail.session?.status;
|
|
2580
|
+
const terminal = status === "cancelled";
|
|
2581
|
+
const importedArchive = detail.session?.importedArchive?.readOnly === true;
|
|
2582
|
+
const host = options.composerOptions;
|
|
2583
|
+
const resolveExtras = () => typeof host?.sendExtras === "function" ? host.sendExtras() : host?.sendExtras;
|
|
2584
|
+
const releaseSentFiles = (input) => files.removeReadyFiles(
|
|
2585
|
+
(input.resources ?? []).flatMap(
|
|
2586
|
+
(resource) => resource.kind === "file" ? [resource.fileId] : []
|
|
2587
|
+
)
|
|
2588
|
+
);
|
|
2589
|
+
const composer = useComposer(sessionId, {
|
|
2590
|
+
...eventOptions,
|
|
2591
|
+
initialDraft: host?.initialDraft,
|
|
2592
|
+
effectiveControl: queue.effectiveControl ?? detail.session?.effectiveControl,
|
|
2593
|
+
sendDestination: () => queue.queue.length > 0 || status === "running" ? "queue" : "chat",
|
|
2594
|
+
sendExtras: () => {
|
|
2595
|
+
const extras = resolveExtras();
|
|
2596
|
+
return {
|
|
2597
|
+
...extras,
|
|
2598
|
+
resources: [...extras?.resources ?? [], ...uploadsEnabled ? files.readyResources : []]
|
|
2599
|
+
};
|
|
2600
|
+
},
|
|
2601
|
+
sendBlocked: () => terminal || importedArchive || uploadsEnabled && files.hasUnresolved || host?.sendBlocked?.() === true,
|
|
2602
|
+
onSubmitted: (text, input) => {
|
|
2603
|
+
releaseSentFiles(input);
|
|
2604
|
+
return host?.onSubmitted?.(text, input);
|
|
2605
|
+
},
|
|
2606
|
+
onSent: (text, input) => {
|
|
2607
|
+
releaseSentFiles(input);
|
|
2608
|
+
return host?.onSent?.(text, input);
|
|
2609
|
+
},
|
|
2610
|
+
onDeliveryError: host?.onDeliveryError
|
|
2611
|
+
});
|
|
2612
|
+
const timeline = useMemo5(
|
|
2613
|
+
() => conversationTimeline(feed.timeline, queue, composer),
|
|
2614
|
+
[feed.timeline, queue, composer]
|
|
2615
|
+
);
|
|
2616
|
+
const error = detail.error ?? feed.error ?? human.error;
|
|
2617
|
+
const loadFailed = Boolean(feed.error) && !feed.initialHistoryReady;
|
|
2618
|
+
const retry = async () => {
|
|
2619
|
+
await Promise.all([
|
|
2620
|
+
...detail.error ? [detail.refresh()] : [],
|
|
2621
|
+
...human.error ? [human.refresh()] : [],
|
|
2622
|
+
...feed.error ? [feed.jumpToLatest()] : []
|
|
2623
|
+
]);
|
|
2624
|
+
};
|
|
2625
|
+
return {
|
|
2626
|
+
...scope,
|
|
2627
|
+
sessionId,
|
|
2628
|
+
config,
|
|
2629
|
+
catalog,
|
|
2630
|
+
showModelPicker,
|
|
2631
|
+
feed,
|
|
2632
|
+
detail,
|
|
2633
|
+
queue,
|
|
2634
|
+
human,
|
|
2635
|
+
control,
|
|
2636
|
+
approvals,
|
|
2637
|
+
files,
|
|
2638
|
+
uploadsEnabled,
|
|
2639
|
+
composer,
|
|
2640
|
+
/** The same live application context for text and durable voice messages. */
|
|
2641
|
+
getModelContext: () => resolveExtras()?.modelContext,
|
|
2642
|
+
timeline,
|
|
2643
|
+
status,
|
|
2644
|
+
terminal,
|
|
2645
|
+
importedArchive,
|
|
2646
|
+
running: status === "running" || status === "recovering" || status === "waiting_capacity",
|
|
2647
|
+
error,
|
|
2648
|
+
loadFailed,
|
|
2649
|
+
retry
|
|
2650
|
+
};
|
|
2651
|
+
}
|
|
2652
|
+
|
|
2653
|
+
// src/hooks/use-goal.ts
|
|
2654
|
+
import {
|
|
2655
|
+
OpenGeniApiError as OpenGeniApiError2,
|
|
2656
|
+
observedSessionSequence
|
|
2657
|
+
} from "@opengeni/sdk";
|
|
2658
|
+
import { useCallback as useCallback8, useEffect as useEffect8, useLayoutEffect as useLayoutEffect5, useRef as useRef9, useState as useState7 } from "react";
|
|
2659
|
+
function isGoalEvent(event) {
|
|
2660
|
+
return event.type.startsWith("goal.");
|
|
2661
|
+
}
|
|
2662
|
+
function isGoalRefreshEvent(event) {
|
|
2663
|
+
const type = event.type;
|
|
2664
|
+
return isGoalEvent(event) || type.startsWith("turn.") || type.startsWith("session.") || type.startsWith("system.update.") || type.startsWith("workspace.inference.") || type.startsWith("user.");
|
|
2665
|
+
}
|
|
2666
|
+
function useGoal(sessionId, options = {}) {
|
|
2667
|
+
const { client, workspaceId } = useEmbeddedGoal(options);
|
|
2668
|
+
const enabled = (options.enabled ?? true) && Boolean(sessionId);
|
|
2669
|
+
const sharedEvents = options.events;
|
|
2670
|
+
const sharedFeed = sharedEvents !== void 0;
|
|
2671
|
+
const pageLive = usePageLiveActivity();
|
|
2672
|
+
const [goal, setGoal] = useState7(null);
|
|
2673
|
+
const [loading, setLoading] = useState7(enabled);
|
|
2674
|
+
const [error, setError] = useState7(null);
|
|
2675
|
+
const [readAbsent, setReadAbsent] = useState7(false);
|
|
2676
|
+
const { run, mutating, mutationError, clearMutationError } = useMutationRunner();
|
|
2677
|
+
const generation = useRef9(0);
|
|
2678
|
+
const targetKeyRef = useRef9(null);
|
|
2679
|
+
const goalAbsentRef = useRef9(false);
|
|
2680
|
+
const pendingRefreshRef = useRef9("none");
|
|
2681
|
+
const sharedEventsRef = useRef9(sharedEvents);
|
|
2682
|
+
useLayoutEffect5(() => {
|
|
2683
|
+
sharedEventsRef.current = sharedEvents;
|
|
2684
|
+
}, [sharedEvents]);
|
|
2685
|
+
const loadAbort = useRef9(null);
|
|
2686
|
+
const scheduleRefreshRef = useRef9(() => void 0);
|
|
2687
|
+
const retireLoads = useCallback8(() => {
|
|
2688
|
+
generation.current += 1;
|
|
2689
|
+
loadAbort.current?.abort();
|
|
2690
|
+
loadAbort.current = null;
|
|
2691
|
+
}, []);
|
|
2692
|
+
const load = useCallback8(async () => {
|
|
2693
|
+
if (!sessionId) {
|
|
2694
|
+
return;
|
|
2695
|
+
}
|
|
2696
|
+
const ticket = ++generation.current;
|
|
2697
|
+
pendingRefreshRef.current = "none";
|
|
2698
|
+
loadAbort.current?.abort();
|
|
2699
|
+
const controller = new AbortController();
|
|
2700
|
+
loadAbort.current = controller;
|
|
2701
|
+
let fetchedGoal = null;
|
|
2702
|
+
try {
|
|
2703
|
+
const fetched = typeof client.findGoal === "function" ? await client.findGoal(workspaceId, sessionId, { signal: controller.signal }) : await client.getGoal(workspaceId, sessionId, { signal: controller.signal });
|
|
2704
|
+
fetchedGoal = fetched;
|
|
2705
|
+
if (ticket === generation.current) {
|
|
2706
|
+
goalAbsentRef.current = fetched === null;
|
|
2707
|
+
setReadAbsent(fetched === null);
|
|
2708
|
+
setGoal(fetched);
|
|
2709
|
+
setError(null);
|
|
2710
|
+
setLoading(false);
|
|
2711
|
+
}
|
|
2712
|
+
} catch (cause) {
|
|
2713
|
+
if (ticket !== generation.current) {
|
|
2714
|
+
return;
|
|
2715
|
+
}
|
|
2716
|
+
if (cause instanceof OpenGeniApiError2 && cause.status === 404) {
|
|
2717
|
+
goalAbsentRef.current = true;
|
|
2718
|
+
setReadAbsent(true);
|
|
2719
|
+
setGoal(null);
|
|
2720
|
+
setError(null);
|
|
2721
|
+
} else {
|
|
2722
|
+
setError(normalizeError(cause));
|
|
2723
|
+
}
|
|
2724
|
+
setLoading(false);
|
|
2725
|
+
} finally {
|
|
2726
|
+
if (loadAbort.current === controller) loadAbort.current = null;
|
|
2727
|
+
}
|
|
2728
|
+
if (ticket !== generation.current || pendingRefreshRef.current === "none") {
|
|
2729
|
+
return;
|
|
2730
|
+
}
|
|
2731
|
+
const readThrough = fetchedGoal ? observedSessionSequence(fetchedGoal) : void 0;
|
|
2732
|
+
if (readThrough !== void 0 && sharedEventsRef.current !== void 0) {
|
|
2733
|
+
const events = sharedEventsRef.current;
|
|
2734
|
+
const newest = events[events.length - 1];
|
|
2735
|
+
if (!newest || newest.sequence <= readThrough) {
|
|
2736
|
+
pendingRefreshRef.current = "none";
|
|
2737
|
+
return;
|
|
2738
|
+
}
|
|
2739
|
+
}
|
|
2740
|
+
if (goalAbsentRef.current && pendingRefreshRef.current === "refresh") {
|
|
2741
|
+
const events = sharedEventsRef.current ?? [];
|
|
2742
|
+
let latestGoalEvent;
|
|
2743
|
+
for (let index = events.length - 1; index >= 0 && !latestGoalEvent; index -= 1) {
|
|
2744
|
+
const event = events[index];
|
|
2745
|
+
if (event && isGoalEvent(event)) latestGoalEvent = event;
|
|
2746
|
+
}
|
|
2747
|
+
if (!latestGoalEvent || latestGoalEvent.type === "goal.cleared") {
|
|
2748
|
+
pendingRefreshRef.current = "none";
|
|
2749
|
+
return;
|
|
2750
|
+
}
|
|
2751
|
+
pendingRefreshRef.current = "goal";
|
|
2752
|
+
}
|
|
2753
|
+
scheduleRefreshRef.current();
|
|
2754
|
+
}, [client, workspaceId, sessionId]);
|
|
2755
|
+
useEffect8(() => {
|
|
2756
|
+
const targetKey = `${workspaceId} ${sessionId ?? ""}`;
|
|
2757
|
+
if (targetKeyRef.current !== targetKey) {
|
|
2758
|
+
targetKeyRef.current = targetKey;
|
|
2759
|
+
goalAbsentRef.current = false;
|
|
2760
|
+
pendingRefreshRef.current = "none";
|
|
2761
|
+
setReadAbsent(false);
|
|
2762
|
+
setGoal(null);
|
|
2763
|
+
setError(null);
|
|
2764
|
+
}
|
|
2765
|
+
if (!enabled || !pageLive) {
|
|
2766
|
+
retireLoads();
|
|
2767
|
+
setLoading(false);
|
|
2768
|
+
return;
|
|
2769
|
+
}
|
|
2770
|
+
if (sharedFeed) {
|
|
2771
|
+
setLoading(true);
|
|
2772
|
+
void load();
|
|
2773
|
+
return () => {
|
|
2774
|
+
retireLoads();
|
|
2775
|
+
};
|
|
2776
|
+
}
|
|
2777
|
+
setLoading(true);
|
|
2778
|
+
const pollIntervalMs = options.pollIntervalMs;
|
|
2779
|
+
if (pollIntervalMs === void 0 || pollIntervalMs <= 0) {
|
|
2780
|
+
void load();
|
|
2781
|
+
return () => {
|
|
2782
|
+
retireLoads();
|
|
2783
|
+
};
|
|
2784
|
+
}
|
|
2785
|
+
let cancelled = false;
|
|
2786
|
+
let timer = null;
|
|
2787
|
+
const schedule = () => {
|
|
2788
|
+
if (cancelled) return;
|
|
2789
|
+
timer = setTimeout(() => {
|
|
2790
|
+
timer = null;
|
|
2791
|
+
void load().finally(schedule);
|
|
2792
|
+
}, pollIntervalMs);
|
|
2793
|
+
};
|
|
2794
|
+
void load().finally(schedule);
|
|
2795
|
+
return () => {
|
|
2796
|
+
cancelled = true;
|
|
2797
|
+
if (timer !== null) clearTimeout(timer);
|
|
2798
|
+
retireLoads();
|
|
2799
|
+
};
|
|
2800
|
+
}, [
|
|
2801
|
+
load,
|
|
2802
|
+
enabled,
|
|
2803
|
+
pageLive,
|
|
2804
|
+
workspaceId,
|
|
2805
|
+
sessionId,
|
|
2806
|
+
options.pollIntervalMs,
|
|
2807
|
+
retireLoads,
|
|
2808
|
+
sharedFeed
|
|
2809
|
+
]);
|
|
2810
|
+
const scheduleRefresh = useDebouncedCallback(() => {
|
|
2811
|
+
const pending = pendingRefreshRef.current;
|
|
2812
|
+
if (pending === "none" || loadAbort.current !== null) return;
|
|
2813
|
+
if (pending === "refresh" && goalAbsentRef.current) {
|
|
2814
|
+
pendingRefreshRef.current = "none";
|
|
2815
|
+
return;
|
|
2816
|
+
}
|
|
2817
|
+
void load();
|
|
2818
|
+
});
|
|
2819
|
+
useLayoutEffect5(() => {
|
|
2820
|
+
scheduleRefreshRef.current = scheduleRefresh;
|
|
2821
|
+
}, [scheduleRefresh]);
|
|
2822
|
+
const isRefreshEvent = useCallback8(
|
|
2823
|
+
(event) => goalAbsentRef.current ? isGoalEvent(event) : isGoalRefreshEvent(event),
|
|
2824
|
+
[]
|
|
2825
|
+
);
|
|
2826
|
+
const refreshGoal = useCallback8(() => {
|
|
2827
|
+
pendingRefreshRef.current = "goal";
|
|
2828
|
+
scheduleRefresh();
|
|
2829
|
+
}, [scheduleRefresh]);
|
|
2830
|
+
const onRefreshEvent = useCallback8(
|
|
2831
|
+
(event) => {
|
|
2832
|
+
if (isGoalEvent(event)) pendingRefreshRef.current = "goal";
|
|
2833
|
+
else if (pendingRefreshRef.current === "none") pendingRefreshRef.current = "refresh";
|
|
2834
|
+
scheduleRefresh();
|
|
2835
|
+
},
|
|
2836
|
+
[scheduleRefresh]
|
|
2837
|
+
);
|
|
2838
|
+
useSessionEventTrigger(client, workspaceId, sessionId, isRefreshEvent, onRefreshEvent, {
|
|
2839
|
+
enabled,
|
|
2840
|
+
...sharedEvents !== void 0 ? { events: sharedEvents } : {},
|
|
2841
|
+
// The load settles events that arrive during its read itself (above).
|
|
2842
|
+
readThrough: projectionReadThrough(goal, false),
|
|
2843
|
+
refresh: refreshGoal
|
|
2844
|
+
});
|
|
2845
|
+
const retainedGoal = useRetainedSessionView(
|
|
2846
|
+
client,
|
|
2847
|
+
workspaceId,
|
|
2848
|
+
sessionId,
|
|
2849
|
+
"goal",
|
|
2850
|
+
loading ? null : goal,
|
|
2851
|
+
{ enabled, discard: readAbsent || deniesRetainedView(error) }
|
|
2852
|
+
);
|
|
2853
|
+
const visibleGoal = loading ? goal ?? retainedGoal : goal;
|
|
2854
|
+
const goalRef = useRef9(goal);
|
|
2855
|
+
const shownRetainedRef = useRef9(null);
|
|
2856
|
+
const readWaitersRef = useRef9([]);
|
|
2857
|
+
useLayoutEffect5(() => {
|
|
2858
|
+
goalRef.current = goal;
|
|
2859
|
+
shownRetainedRef.current = loading && goal === null ? retainedGoal : null;
|
|
2860
|
+
});
|
|
2861
|
+
useEffect8(() => {
|
|
2862
|
+
if (loading) return;
|
|
2863
|
+
const waiters = readWaitersRef.current;
|
|
2864
|
+
readWaitersRef.current = [];
|
|
2865
|
+
for (const resolve of waiters) resolve();
|
|
2866
|
+
}, [loading]);
|
|
2867
|
+
useEffect8(
|
|
2868
|
+
() => () => {
|
|
2869
|
+
goalRef.current = null;
|
|
2870
|
+
const waiters = readWaitersRef.current;
|
|
2871
|
+
readWaitersRef.current = [];
|
|
2872
|
+
for (const resolve of waiters) resolve();
|
|
2873
|
+
},
|
|
2874
|
+
[workspaceId, sessionId]
|
|
2875
|
+
);
|
|
2876
|
+
const aimedAtCurrentGoal = useCallback8(async () => {
|
|
2877
|
+
const shown = shownRetainedRef.current;
|
|
2878
|
+
if (!shown) return true;
|
|
2879
|
+
await new Promise((resolve) => readWaitersRef.current.push(resolve));
|
|
2880
|
+
const fresh = goalRef.current;
|
|
2881
|
+
return fresh !== null && fresh.id === shown.id && fresh.objectiveRevision === shown.objectiveRevision;
|
|
2882
|
+
}, []);
|
|
2883
|
+
const pause = useCallback8(
|
|
2884
|
+
async (rationale) => {
|
|
2885
|
+
if (!sessionId || !await aimedAtCurrentGoal()) {
|
|
2886
|
+
return null;
|
|
2887
|
+
}
|
|
2888
|
+
const result = await run(
|
|
2889
|
+
() => client.updateGoal(workspaceId, sessionId, {
|
|
2890
|
+
status: "paused",
|
|
2891
|
+
...rationale !== void 0 ? { rationale } : {}
|
|
2892
|
+
})
|
|
2893
|
+
);
|
|
2894
|
+
if (result) {
|
|
2895
|
+
setGoal(result);
|
|
2896
|
+
}
|
|
2897
|
+
return result;
|
|
2898
|
+
},
|
|
2899
|
+
[client, workspaceId, sessionId, run, aimedAtCurrentGoal]
|
|
2900
|
+
);
|
|
2901
|
+
const resume = useCallback8(async () => {
|
|
2902
|
+
if (!sessionId || !await aimedAtCurrentGoal()) {
|
|
2903
|
+
return null;
|
|
2904
|
+
}
|
|
2905
|
+
const result = await run(() => client.updateGoal(workspaceId, sessionId, { status: "active" }));
|
|
2906
|
+
if (result) {
|
|
2907
|
+
setGoal(result);
|
|
2908
|
+
}
|
|
2909
|
+
return result;
|
|
2910
|
+
}, [client, workspaceId, sessionId, run, aimedAtCurrentGoal]);
|
|
2911
|
+
const clearGoal = useCallback8(async () => {
|
|
2912
|
+
if (!sessionId || !await aimedAtCurrentGoal()) {
|
|
2913
|
+
return;
|
|
2914
|
+
}
|
|
2915
|
+
const ok = await run(async () => {
|
|
2916
|
+
await client.deleteGoal(workspaceId, sessionId);
|
|
2917
|
+
return true;
|
|
2918
|
+
});
|
|
2919
|
+
if (ok) {
|
|
2920
|
+
retireLoads();
|
|
2921
|
+
setReadAbsent(true);
|
|
2922
|
+
setGoal(null);
|
|
2923
|
+
setError(null);
|
|
2924
|
+
}
|
|
2925
|
+
}, [client, workspaceId, sessionId, run, retireLoads, aimedAtCurrentGoal]);
|
|
2926
|
+
return {
|
|
2927
|
+
goal: visibleGoal,
|
|
2928
|
+
isActive: visibleGoal?.status === "active",
|
|
2929
|
+
isPaused: visibleGoal?.status === "paused",
|
|
2930
|
+
isCompleted: visibleGoal?.status === "completed",
|
|
2931
|
+
loading: loading && retainedGoal === null,
|
|
2932
|
+
error,
|
|
2933
|
+
refresh: load,
|
|
2934
|
+
pause,
|
|
2935
|
+
resume,
|
|
2936
|
+
clearGoal,
|
|
2937
|
+
deleteGoal: clearGoal,
|
|
2938
|
+
updating: mutating,
|
|
2939
|
+
mutationError,
|
|
2940
|
+
clearMutationError
|
|
2941
|
+
};
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
// src/hooks/use-new-conversation.ts
|
|
2945
|
+
import {
|
|
2946
|
+
OpenGeniApiError as OpenGeniApiError3
|
|
2947
|
+
} from "@opengeni/sdk";
|
|
2948
|
+
import { useLayoutEffect as useLayoutEffect6, useMemo as useMemo6, useRef as useRef10, useState as useState8 } from "react";
|
|
2949
|
+
var NOOP_ASYNC = async () => {
|
|
2950
|
+
};
|
|
2951
|
+
function useNewConversation(options = {}) {
|
|
2952
|
+
const t = useOpenGeniText();
|
|
2953
|
+
const context = useOpenGeni(options);
|
|
2954
|
+
const scope = { client: context.client, workspaceId: context.workspaceId };
|
|
2955
|
+
const config = useClientConfigFlags(context.client);
|
|
2956
|
+
const showModelPicker = options.modelPicker ?? config.modelSelection;
|
|
2957
|
+
const catalog = useWorkspaceModelCatalog({ ...scope, enabled: showModelPicker });
|
|
2958
|
+
const files = useFileAttachments(scope);
|
|
2959
|
+
const uploadsEnabled = (options.attachments ?? true) && config.uploads;
|
|
2960
|
+
const available = options.enabled !== false && (options.createSession !== void 0 || config.sessionCreation);
|
|
2961
|
+
const [text, setText] = useState8("");
|
|
2962
|
+
const [choice, setChoice] = useState8({});
|
|
2963
|
+
const [sending, setSending] = useState8(false);
|
|
2964
|
+
const [error, setError] = useState8(null);
|
|
2965
|
+
const [pending, setPending] = useState8(null);
|
|
2966
|
+
const [completion, setCompletion] = useState8(null);
|
|
2967
|
+
const textRef = useRef10(text);
|
|
2968
|
+
const textRevision = useRef10(0);
|
|
2969
|
+
const choiceRef = useRef10(choice);
|
|
2970
|
+
const filesRef = useRef10(files);
|
|
2971
|
+
filesRef.current = files;
|
|
2972
|
+
const pendingRef = useRef10(null);
|
|
2973
|
+
const completionRef = useRef10(null);
|
|
2974
|
+
const inFlight = useRef10(false);
|
|
2975
|
+
const lifetime = useRef10({ mounted: true, generation: 0 }).current;
|
|
2976
|
+
const identity = useMemo6(
|
|
2977
|
+
() => ({
|
|
2978
|
+
client: context.client,
|
|
2979
|
+
workspaceId: context.workspaceId,
|
|
2980
|
+
scopeKey: options.scopeKey
|
|
2981
|
+
}),
|
|
2982
|
+
[context.client, context.workspaceId, options.scopeKey]
|
|
2983
|
+
);
|
|
2984
|
+
const committedIdentity = useRef10(identity);
|
|
2985
|
+
useLayoutEffect6(() => {
|
|
2986
|
+
lifetime.mounted = true;
|
|
2987
|
+
return () => {
|
|
2988
|
+
lifetime.mounted = false;
|
|
2989
|
+
lifetime.generation++;
|
|
2990
|
+
};
|
|
2991
|
+
}, [lifetime]);
|
|
2992
|
+
useLayoutEffect6(() => {
|
|
2993
|
+
if (committedIdentity.current === identity) return;
|
|
2994
|
+
committedIdentity.current = identity;
|
|
2995
|
+
lifetime.generation++;
|
|
2996
|
+
inFlight.current = false;
|
|
2997
|
+
pendingRef.current = null;
|
|
2998
|
+
completionRef.current = null;
|
|
2999
|
+
textRef.current = "";
|
|
3000
|
+
textRevision.current = 0;
|
|
3001
|
+
choiceRef.current = {};
|
|
3002
|
+
setText("");
|
|
3003
|
+
setChoice({});
|
|
3004
|
+
setSending(false);
|
|
3005
|
+
setError(null);
|
|
3006
|
+
setPending(null);
|
|
3007
|
+
setCompletion(null);
|
|
3008
|
+
filesRef.current.clear();
|
|
3009
|
+
}, [identity, lifetime]);
|
|
3010
|
+
const ownsScope = () => lifetime.mounted && committedIdentity.current === identity;
|
|
3011
|
+
const updateText = (value) => {
|
|
3012
|
+
if (!ownsScope()) return;
|
|
3013
|
+
if (value !== textRef.current) textRevision.current++;
|
|
3014
|
+
textRef.current = value;
|
|
3015
|
+
setText(value);
|
|
3016
|
+
};
|
|
3017
|
+
const updateChoice = (patch) => {
|
|
3018
|
+
if (!ownsScope()) return;
|
|
3019
|
+
const next = { ...choiceRef.current, ...patch };
|
|
3020
|
+
const model = catalog.models.find((row) => row.id === (next.model ?? catalog.defaultModel));
|
|
3021
|
+
if (model) {
|
|
3022
|
+
if (next.reasoningEffort)
|
|
3023
|
+
next.reasoningEffort = coerceReasoningEffortForModel(model, next.reasoningEffort);
|
|
3024
|
+
if (next.latencyMode && !runnableLatencyModesForModel(model).includes(next.latencyMode))
|
|
3025
|
+
next.latencyMode = "standard";
|
|
3026
|
+
}
|
|
3027
|
+
choiceRef.current = next;
|
|
3028
|
+
setChoice(choiceRef.current);
|
|
3029
|
+
};
|
|
3030
|
+
const effectivePolicy = () => {
|
|
3031
|
+
const model = choiceRef.current.model ?? catalog.defaultModel;
|
|
3032
|
+
const definition = catalog.models.find((row) => row.id === model);
|
|
3033
|
+
const effort = choiceRef.current.reasoningEffort ?? (definition ? defaultEffortForModel(definition) : config.defaultReasoningEffort ?? "medium");
|
|
3034
|
+
return showModelPicker && model ? {
|
|
3035
|
+
model,
|
|
3036
|
+
reasoningEffort: definition ? coerceReasoningEffortForModel(definition, effort) : effort,
|
|
3037
|
+
latencyMode: choiceRef.current.latencyMode ?? "standard"
|
|
3038
|
+
} : void 0;
|
|
3039
|
+
};
|
|
3040
|
+
const create = options.createSession ?? (async (initialMessage, idempotencyKey, input) => {
|
|
3041
|
+
const creator = context.client.createSession;
|
|
3042
|
+
if (typeof creator !== "function")
|
|
3043
|
+
throw new Error(t("hooks.useNewConversation.newChatsAreNotEnabled"));
|
|
3044
|
+
const created = await creator.call(context.client, context.workspaceId, {
|
|
3045
|
+
...input.startMode === "realtime" ? {} : { initialMessage },
|
|
3046
|
+
idempotencyKey,
|
|
3047
|
+
...input
|
|
3048
|
+
});
|
|
3049
|
+
return created.id;
|
|
3050
|
+
});
|
|
3051
|
+
const finishCreation = (accepted) => {
|
|
3052
|
+
if (!lifetime.mounted || lifetime.generation !== accepted.generation) return;
|
|
3053
|
+
const { attempt, sessionId } = accepted;
|
|
3054
|
+
const sentFiles = new Set(attempt.options.resources?.map((resource) => resource.fileId) ?? []);
|
|
3055
|
+
const policyChanged = ["model", "reasoningEffort", "latencyMode"].some(
|
|
3056
|
+
(field) => choiceRef.current[field] !== attempt.options[field]
|
|
3057
|
+
);
|
|
3058
|
+
const draft = {
|
|
3059
|
+
text: attempt.clearDraft && textRevision.current === attempt.textRevision ? "" : textRef.current,
|
|
3060
|
+
resources: filesRef.current.readyResources.filter(
|
|
3061
|
+
(resource) => !sentFiles.has(resource.fileId)
|
|
3062
|
+
),
|
|
3063
|
+
// Unchanged choices are already part of the created session. Do not
|
|
3064
|
+
// replace server-owned defaults with a browser's catalog estimate.
|
|
3065
|
+
...policyChanged ? { policy: effectivePolicy() } : {}
|
|
3066
|
+
};
|
|
3067
|
+
pendingRef.current = null;
|
|
3068
|
+
completionRef.current = null;
|
|
3069
|
+
setPending(null);
|
|
3070
|
+
setCompletion(null);
|
|
3071
|
+
updateText(draft.text);
|
|
3072
|
+
filesRef.current.removeReadyFiles(sentFiles);
|
|
3073
|
+
notifyObserver(options.onCreated, {
|
|
3074
|
+
sessionId,
|
|
3075
|
+
initialMessage: attempt.initialMessage,
|
|
3076
|
+
draft,
|
|
3077
|
+
...attempt.realtimeModel ? { realtimeModel: attempt.realtimeModel } : {}
|
|
3078
|
+
});
|
|
3079
|
+
};
|
|
3080
|
+
const finishRef = useRef10(finishCreation);
|
|
3081
|
+
finishRef.current = finishCreation;
|
|
3082
|
+
useLayoutEffect6(() => {
|
|
3083
|
+
if (completion && !files.hasUnresolved) finishRef.current(completion);
|
|
3084
|
+
}, [completion, files.hasUnresolved]);
|
|
3085
|
+
const deliver = async (attempt) => {
|
|
3086
|
+
if (!ownsScope() || inFlight.current || completionRef.current || !available) return false;
|
|
3087
|
+
const ownedGeneration = lifetime.generation;
|
|
3088
|
+
inFlight.current = true;
|
|
3089
|
+
pendingRef.current = attempt;
|
|
3090
|
+
setSending(true);
|
|
3091
|
+
setError(null);
|
|
3092
|
+
setPending(null);
|
|
3093
|
+
try {
|
|
3094
|
+
const sessionId = await attempt.create(
|
|
3095
|
+
attempt.initialMessage,
|
|
3096
|
+
attempt.key,
|
|
3097
|
+
structuredClone(attempt.options)
|
|
3098
|
+
);
|
|
3099
|
+
if (!lifetime.mounted || lifetime.generation !== ownedGeneration) return true;
|
|
3100
|
+
const accepted = { sessionId, attempt, generation: ownedGeneration };
|
|
3101
|
+
completionRef.current = accepted;
|
|
3102
|
+
if (filesRef.current.hasUnresolved) setCompletion(accepted);
|
|
3103
|
+
else finishCreation(accepted);
|
|
3104
|
+
return true;
|
|
3105
|
+
} catch (cause) {
|
|
3106
|
+
if (!lifetime.mounted || lifetime.generation !== ownedGeneration) return false;
|
|
3107
|
+
setError({ cause });
|
|
3108
|
+
if (cause instanceof OpenGeniApiError3 && cause.outcomeUnknown === false) {
|
|
3109
|
+
pendingRef.current = null;
|
|
3110
|
+
} else {
|
|
3111
|
+
setPending(attempt);
|
|
3112
|
+
}
|
|
3113
|
+
return false;
|
|
3114
|
+
} finally {
|
|
3115
|
+
if (lifetime.mounted && lifetime.generation === ownedGeneration) {
|
|
3116
|
+
inFlight.current = false;
|
|
3117
|
+
setSending(false);
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
};
|
|
3121
|
+
const submit = async (explicit) => {
|
|
3122
|
+
if (!ownsScope() || !available || inFlight.current || pendingRef.current || uploadsEnabled && filesRef.current.hasUnresolved)
|
|
3123
|
+
return false;
|
|
3124
|
+
const resources = uploadsEnabled ? filesRef.current.readyResources : [];
|
|
3125
|
+
const draftText = explicit ?? textRef.current;
|
|
3126
|
+
const initialMessage = draftText.trim() || (resources.length > 0 ? FILE_ONLY_MESSAGE_TEXT(t) : "");
|
|
3127
|
+
if (!initialMessage) return false;
|
|
3128
|
+
return deliver({
|
|
3129
|
+
key: crypto.randomUUID(),
|
|
3130
|
+
initialMessage,
|
|
3131
|
+
textRevision: textRevision.current,
|
|
3132
|
+
clearDraft: explicit === void 0,
|
|
3133
|
+
create,
|
|
3134
|
+
options: {
|
|
3135
|
+
...resources.length ? { resources: structuredClone(resources) } : {},
|
|
3136
|
+
...showModelPicker ? { ...choiceRef.current } : {}
|
|
3137
|
+
}
|
|
3138
|
+
});
|
|
3139
|
+
};
|
|
3140
|
+
const startRealtime = async (model) => {
|
|
3141
|
+
if (!ownsScope() || !available || inFlight.current || pendingRef.current || !config.realtimeVoice || !(options.realtimeVoice ?? config.realtimeVoiceOffered))
|
|
3142
|
+
return false;
|
|
3143
|
+
if (filesRef.current.hasUnresolved) return false;
|
|
3144
|
+
return deliver({
|
|
3145
|
+
key: crypto.randomUUID(),
|
|
3146
|
+
initialMessage: "",
|
|
3147
|
+
textRevision: textRevision.current,
|
|
3148
|
+
clearDraft: false,
|
|
3149
|
+
create,
|
|
3150
|
+
options: { ...showModelPicker ? { ...choiceRef.current } : {}, startMode: "realtime" },
|
|
3151
|
+
realtimeModel: model
|
|
3152
|
+
});
|
|
3153
|
+
};
|
|
3154
|
+
const composer = {
|
|
3155
|
+
value: text,
|
|
3156
|
+
setValue: updateText,
|
|
3157
|
+
hasDraftContent: () => textRef.current.length > 0 || filesRef.current.attachments.length > 0,
|
|
3158
|
+
send: submit,
|
|
3159
|
+
steer: submit,
|
|
3160
|
+
sending,
|
|
3161
|
+
canSend: available && !sending && !pending && !completion && (text.trim().length > 0 || uploadsEnabled && files.readyResources.length > 0) && !(uploadsEnabled && files.hasUnresolved),
|
|
3162
|
+
pause: NOOP_ASYNC,
|
|
3163
|
+
pausing: false,
|
|
3164
|
+
resume: NOOP_ASYNC,
|
|
3165
|
+
resumeScope: NOOP_ASYNC,
|
|
3166
|
+
resuming: false,
|
|
3167
|
+
draft: null,
|
|
3168
|
+
draftRevision: 0,
|
|
3169
|
+
draftLoading: false,
|
|
3170
|
+
draftSaving: false,
|
|
3171
|
+
draftConflict: null,
|
|
3172
|
+
policy: effectivePolicy() ?? null,
|
|
3173
|
+
setModel: (model) => updateChoice({ model }),
|
|
3174
|
+
setReasoningEffort: (reasoningEffort) => updateChoice({ reasoningEffort }),
|
|
3175
|
+
setLatencyMode: (latencyMode) => updateChoice({ latencyMode }),
|
|
3176
|
+
draftPersistence: "disabled",
|
|
3177
|
+
applyDraft: () => {
|
|
3178
|
+
},
|
|
3179
|
+
reloadDraft: NOOP_ASYNC,
|
|
3180
|
+
resolveDraftConflict: NOOP_ASYNC,
|
|
3181
|
+
restoredResources: [],
|
|
3182
|
+
removeRestoredResource: () => {
|
|
3183
|
+
},
|
|
3184
|
+
error: null,
|
|
3185
|
+
clearError: () => {
|
|
3186
|
+
if (ownsScope()) setError(null);
|
|
3187
|
+
}
|
|
3188
|
+
};
|
|
3189
|
+
return {
|
|
3190
|
+
...scope,
|
|
3191
|
+
config,
|
|
3192
|
+
files,
|
|
3193
|
+
uploadsEnabled,
|
|
3194
|
+
available,
|
|
3195
|
+
showModelPicker,
|
|
3196
|
+
catalog,
|
|
3197
|
+
composer,
|
|
3198
|
+
realtimeVoiceEnabled: config.realtimeVoice && (options.realtimeVoice ?? config.realtimeVoiceOffered),
|
|
3199
|
+
error,
|
|
3200
|
+
finishingUploads: completion !== null,
|
|
3201
|
+
pending: pending ? { idempotencyKey: pending.key, realtimeModel: pending.realtimeModel } : null,
|
|
3202
|
+
retry: () => pendingRef.current ? deliver(pendingRef.current) : Promise.resolve(false),
|
|
3203
|
+
startRealtime
|
|
3204
|
+
};
|
|
3205
|
+
}
|
|
3206
|
+
|
|
3207
|
+
export {
|
|
3208
|
+
approvalsFromRequiresAction,
|
|
3209
|
+
projectPendingApprovals,
|
|
3210
|
+
invokeOlderHistoryLoaderWithReceiptCapture,
|
|
3211
|
+
createOlderHistoryLoadReceipt,
|
|
3212
|
+
conversationTimeline,
|
|
3213
|
+
useAvailableModels,
|
|
3214
|
+
useWorkspaceModelCatalog,
|
|
3215
|
+
useClientConfigFlags,
|
|
3216
|
+
useFileAttachments,
|
|
3217
|
+
deniesRetainedView,
|
|
3218
|
+
useRetainedSessionView,
|
|
3219
|
+
isHumanInputEvent,
|
|
3220
|
+
useHumanInputRequests,
|
|
3221
|
+
isTitleEvent,
|
|
3222
|
+
useSession,
|
|
3223
|
+
useSessionControl,
|
|
3224
|
+
SESSION_EVENT_BROWSER_MAX_BYTES,
|
|
3225
|
+
SESSION_EVENT_BROWSER_MAX_COUNT,
|
|
3226
|
+
SESSION_EVENT_BROWSER_PENDING_MAX_BYTES,
|
|
3227
|
+
SESSION_EVENT_BROWSER_PENDING_MAX_COUNT,
|
|
3228
|
+
useSessionEvents,
|
|
3229
|
+
boundBrowserSessionEventWindow,
|
|
3230
|
+
isTurnQueueEvent,
|
|
3231
|
+
useTurnQueue,
|
|
3232
|
+
useSessionConversation,
|
|
3233
|
+
isGoalEvent,
|
|
3234
|
+
useGoal,
|
|
3235
|
+
useNewConversation
|
|
3236
|
+
};
|
|
3237
|
+
//# sourceMappingURL=chunk-ESAMXNBZ.js.map
|