@opengeni/react 6.35.1-canary.45051251770001 → 6.36.0
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/dist/app/app-state.js +32 -32
- package/dist/app/components/Composer.js +43 -43
- package/dist/app/components/add-card-dialog.js +1 -1
- package/dist/app/components/add-card.js +2 -2
- package/dist/app/components/agent/agent-capability-picker.js +9 -9
- package/dist/app/components/agents/agent-can-use.js +47 -47
- package/dist/app/components/agents/agent-form-page.js +139 -139
- package/dist/app/components/agents/agent-page.js +122 -122
- package/dist/app/components/agents/agent-setup-sections.js +74 -74
- package/dist/app/components/agents/agent-skills.js +13 -13
- package/dist/app/components/agents/agent-trigger-chat-field.js +6 -6
- package/dist/app/components/agents/agent-trigger-dialog.js +31 -31
- package/dist/app/components/agents/agent-trigger-picker.js +8 -8
- package/dist/app/components/agents/agents-page.js +87 -87
- package/dist/app/components/agents/composer-agent-chip.js +59 -59
- package/dist/app/components/agents/session-agent-chip.js +55 -55
- package/dist/app/components/artifacts/app-package.js +11 -11
- package/dist/app/components/artifacts/artifact-browse-controls.js +3 -3
- package/dist/app/components/artifacts/artifact-library.js +28 -28
- package/dist/app/components/artifacts/artifact-page-chrome.js +1 -1
- package/dist/app/components/artifacts/artifact-viewer.js +65 -65
- package/dist/app/components/artifacts/chat-interactive-block.js +27 -27
- package/dist/app/components/artifacts/copy-artifact-link.js +1 -1
- package/dist/app/components/artifacts/file-reach-dialog.js +12 -12
- package/dist/app/components/artifacts/inline-chat-image.js +52 -52
- package/dist/app/components/artifacts/retained-file-preview.js +58 -58
- package/dist/app/components/artifacts/retained-text-preview.js +8 -8
- package/dist/app/components/artifacts/site-actions.js +12 -12
- package/dist/app/components/artifacts/site-audience.js +7 -7
- package/dist/app/components/artifacts/site-conversations.js +34 -34
- package/dist/app/components/artifacts/site-data.js +26 -26
- package/dist/app/components/artifacts/site-public-link.js +3 -3
- package/dist/app/components/artifacts/site-publishing-page.js +69 -69
- package/dist/app/components/artifacts/site-publishing.js +54 -54
- package/dist/app/components/artifacts/site-settings.js +68 -68
- package/dist/app/components/artifacts/site-version-menu.js +9 -9
- package/dist/app/components/billing-class-mark.js +8 -8
- package/dist/app/components/capabilities/capability-detail-sheet.js +16 -16
- package/dist/app/components/capabilities/capability-logo-source.js +28 -28
- package/dist/app/components/capabilities/capability-logo.js +1 -1
- package/dist/app/components/capabilities/connection-account-picker.js +2 -2
- package/dist/app/components/capabilities/connector-tool-permissions.js +8 -8
- package/dist/app/components/capabilities/native-connect-setup.js +32 -32
- package/dist/app/components/capabilities/own-logins-shared-heads-up.js +6 -6
- package/dist/app/components/capabilities/perform-capability-action.js +4 -4
- package/dist/app/components/capabilities/prepared-mcp-setup-card.js +31 -31
- package/dist/app/components/capabilities/session-capability-card.js +146 -146
- package/dist/app/components/capabilities/session-chrome-card.js +49 -49
- package/dist/app/components/capabilities/session-connect-inputs-card.js +33 -33
- package/dist/app/components/capabilities/session-custom-mcp-card.js +38 -38
- package/dist/app/components/capabilities/session-github-card.js +44 -44
- package/dist/app/components/capabilities/session-machine-card.js +50 -50
- package/dist/app/components/capabilities/session-personal-github-card.js +32 -32
- package/dist/app/components/capabilities/session-plugin-card.js +21 -21
- package/dist/app/components/capabilities/use-capabilities-catalog.js +1 -1
- package/dist/app/components/capabilities/use-connection-accounts.js +3 -3
- package/dist/app/components/chat-payment-pages.js +2 -2
- package/dist/app/components/command-menu/chat-status.js +26 -26
- package/dist/app/components/command-menu/chat-switcher.js +86 -86
- package/dist/app/components/command-menu/command-menu.js +109 -109
- package/dist/app/components/command-menu/shortcut-sheet.js +23 -23
- package/dist/app/components/composer-capabilities-menu-body.js +7 -7
- package/dist/app/components/composer-mobile-plus-panel.js +29 -29
- package/dist/app/components/composer-mobile-plus.js +3 -3
- package/dist/app/components/credit-required-gate.js +6 -6
- package/dist/app/components/credit-required-prompt.js +24 -24
- package/dist/app/components/credits/checkout-credits-celebration.js +1 -1
- package/dist/app/components/credits/checkout-return.js +1 -1
- package/dist/app/components/credits/coupon-redeem.js +1 -1
- package/dist/app/components/credits/credit-refusal-notice.js +8 -8
- package/dist/app/components/credits/own-subscription-plan-notice.js +3 -3
- package/dist/app/components/desktop/app-shots.js +9 -9
- package/dist/app/components/desktop/app-update.js +3 -3
- package/dist/app/components/desktop/computer-use.js +3 -3
- package/dist/app/components/desktop/this-computer.js +6 -6
- package/dist/app/components/feedback.js +10 -10
- package/dist/app/components/follow-up-repository-menu-body.js +14 -14
- package/dist/app/components/follow-up-repository-picker.js +1 -1
- package/dist/app/components/github-app-connect-launcher.js +2 -2
- package/dist/app/components/in-app-help-link.js +3 -3
- package/dist/app/components/knowledge/agent-learning-settings.js +3 -3
- package/dist/app/components/machines/connect-machine-dialog.js +25 -25
- package/dist/app/components/manual-repository-editor.js +3 -3
- package/dist/app/components/markdown.js +16 -16
- package/dist/app/components/model-identity.js +3 -3
- package/dist/app/components/models/models-ui.js +17 -17
- package/dist/app/components/models/provider-mark.js +3 -3
- package/dist/app/components/models/subscription-usage.js +5 -5
- package/dist/app/components/my-things.js +15 -15
- package/dist/app/components/own-where-it-works.js +10 -10
- package/dist/app/components/personal-resource-attachment-surface.js +4 -4
- package/dist/app/components/pickers.js +12 -12
- package/dist/app/components/rail/channel-create-dialog.js +6 -6
- package/dist/app/components/rail/project-glyph.js +52 -52
- package/dist/app/components/rail/project-profile.js +73 -73
- package/dist/app/components/rail/rail-context.js +2 -2
- package/dist/app/components/rail/rail-sections.js +155 -155
- package/dist/app/components/rail/session-header.js +124 -124
- package/dist/app/components/rail/session-list.js +154 -154
- package/dist/app/components/rail/session-row-content.js +7 -7
- package/dist/app/components/rail/session-row-hover-details.js +37 -37
- package/dist/app/components/rail/session-shell.js +192 -192
- package/dist/app/components/rail/site-session-group-heading.js +36 -36
- package/dist/app/components/repository-picker.js +14 -14
- package/dist/app/components/secrets/session-secrets-panel.js +4 -4
- package/dist/app/components/session/agent-configuration-panel.js +48 -48
- package/dist/app/components/session/artifact-session-page.js +7 -7
- package/dist/app/components/session/banners.js +20 -20
- package/dist/app/components/session/chat-avatar.js +52 -52
- package/dist/app/components/session/console-new-conversation.js +111 -111
- package/dist/app/components/session/descendant-requests.js +109 -109
- package/dist/app/components/session/editable-artifacts-workspace.js +59 -59
- package/dist/app/components/session/failed-session-banner.js +30 -30
- package/dist/app/components/session/failure-recovery-boundary.js +3 -3
- package/dist/app/components/session/human-input-delegation-record.js +3 -3
- package/dist/app/components/session/human-input.js +86 -86
- package/dist/app/components/session/inspector.js +142 -142
- package/dist/app/components/session/linked-panel.js +3 -3
- package/dist/app/components/session/message-actions.js +10 -10
- package/dist/app/components/session/model-recovery-notice.js +4 -4
- package/dist/app/components/session/new-session-settings-menu.js +28 -28
- package/dist/app/components/session/new-session-setup-strip.js +55 -55
- package/dist/app/components/session/pull-request-panel.js +25 -25
- package/dist/app/components/session/sandbox-recovery-actions.js +3 -3
- package/dist/app/components/session/sandbox-switcher.js +22 -22
- package/dist/app/components/session/sandbox-workspace.js +118 -118
- package/dist/app/components/session/search-markdown-highlight.js +17 -17
- package/dist/app/components/session/search-results-view.js +18 -18
- package/dist/app/components/session/session-admin-access.js +13 -13
- package/dist/app/components/session/session-admission-notice.js +11 -11
- package/dist/app/components/session/session-avatar-picker.js +59 -59
- package/dist/app/components/session/session-avatar.js +54 -54
- package/dist/app/components/session/session-machine-access-notice.js +11 -11
- package/dist/app/components/session/session-profile-dialog.js +70 -70
- package/dist/app/components/session/session-profile-editor.js +71 -71
- package/dist/app/components/session/session-retention.js +6 -6
- package/dist/app/components/session/session-search-dialog.js +20 -20
- package/dist/app/components/session/session-skill-reviews.js +5 -5
- package/dist/app/components/session/session-tenancy-control.js +26 -26
- package/dist/app/components/session/session-unattended-setting.js +1 -1
- package/dist/app/components/session/session-usage-limit-section.js +11 -11
- package/dist/app/components/session/share-chat-dialog.js +10 -10
- package/dist/app/components/session/subagents.js +23 -23
- package/dist/app/components/session/subscription-account-indicator.js +25 -25
- package/dist/app/components/session/subscription-account-menu.js +7 -7
- package/dist/app/components/session-connectors-menu-body.js +10 -10
- package/dist/app/components/settings/row-select.js +6 -6
- package/dist/app/components/toaster.js +2 -2
- package/dist/app/components/transcription-settings.js +10 -10
- package/dist/app/components/ui/destructive-confirm.js +10 -10
- package/dist/app/components/usage/usage-entry.js +8 -8
- package/dist/app/components/window-bar.js +24 -24
- package/dist/app/components/workspace-composer-plus.js +43 -43
- package/dist/app/components/workspace-reach.js +6 -6
- package/dist/app/embed/session-app.js +398 -398
- package/dist/app/lib/actions/actions-provider.js +18 -18
- package/dist/app/lib/agent-capabilities.js +4 -4
- package/dist/app/lib/app-connect-card.js +14 -14
- package/dist/app/lib/app-shared-key-dialog.js +8 -8
- package/dist/app/lib/app-surfaces.js +1 -1
- package/dist/app/lib/app-sync-opt-in.js +4 -4
- package/dist/app/lib/codex-usage-query.js +3 -3
- package/dist/app/lib/composer-agent.js +2 -2
- package/dist/app/lib/composer-connectors.js +32 -32
- package/dist/app/lib/composer-send-blocking.js +3 -3
- package/dist/app/lib/console-site.js +6 -6
- package/dist/app/lib/console-text.js +2 -2
- package/dist/app/lib/deployment-free-model.js +2 -2
- package/dist/app/lib/events.js +29 -29
- package/dist/app/lib/failed-session-copy.js +6 -6
- package/dist/app/lib/feedback-capture.js +2 -2
- package/dist/app/lib/free-credit-gap.js +2 -2
- package/dist/app/lib/model-access-onboarding.js +5 -5
- package/dist/app/lib/model-policy.js +1 -1
- package/dist/app/lib/move-chat-to-machine.js +5 -5
- package/dist/app/lib/personal-resource-attachments.js +1 -1
- package/dist/app/lib/session-branch-cache.js +19 -19
- package/dist/app/lib/session-create.js +5 -5
- package/dist/app/lib/session-group-pagination.js +19 -19
- package/dist/app/lib/session-hover-facts.js +26 -26
- package/dist/app/lib/session-list-dirty-scopes.js +20 -20
- package/dist/app/lib/session-model.js +3 -3
- package/dist/app/lib/session-rail.js +16 -16
- package/dist/app/lib/session-rename.js +4 -4
- package/dist/app/lib/sessions-group.js +23 -23
- package/dist/app/lib/site-tool-consent-dialog.js +23 -23
- package/dist/app/lib/site-tool-consent.js +1 -1
- package/dist/app/lib/turn-failure-analytics.js +8 -8
- package/dist/app/lib/unavailable-session-model.js +2 -2
- package/dist/app/lib/use-artifact-catalog.js +2 -2
- package/dist/app/lib/use-duplicate-site.js +4 -4
- package/dist/app/lib/use-follow-up-repositories.js +5 -5
- package/dist/app/lib/use-personal-resource-attachment.js +2 -2
- package/dist/app/lib/use-workspace-machines.js +9 -9
- package/dist/app/lib/use-workspace-model-catalog.js +7 -7
- package/dist/app/lib/use-workspace-rigs.js +6 -6
- package/dist/app/lib/workspace-navigation-preference.js +5 -5
- package/dist/app/lib/workspace-scope-context.js +4 -4
- package/dist/app/routes/app-page-view.js +17 -17
- package/dist/app/routes/app-page.js +2 -2
- package/dist/app/routes/artifacts.js +152 -152
- package/dist/app/routes/retained-artifact.js +108 -108
- package/dist/app/routes/session-unavailable.js +5 -5
- package/dist/app/routes/session.js +249 -249
- package/dist/app/routes/sessions-index-hydration.js +6 -6
- package/dist/app/routes/sessions-index.js +207 -207
- package/dist/app/routes/site-view.js +200 -200
- package/dist/artifacts-document.js +4 -4
- package/dist/artifacts-presentation.js +7 -7
- package/dist/artifacts-spreadsheet.js +4 -4
- package/dist/artifacts.js +50 -50
- package/dist/automation-model.js +7 -7
- package/dist/automations.js +65 -65
- package/dist/browser-viewer-EIEMRVFF.js +23 -0
- package/dist/chat-interactive-block-FV37LWYZ.js +22 -0
- package/dist/chunk-2COBAJC7.js +818 -0
- package/dist/chunk-2HS3IUXE.js +170 -0
- package/dist/chunk-2JTMFYCT.js +296 -0
- package/dist/chunk-2JXKP4M6.js +114 -0
- package/dist/chunk-2P5K7CBH.js +269 -0
- package/dist/chunk-2XGRHMRI.js +250 -0
- package/dist/chunk-332BYSAZ.js +65 -0
- package/dist/chunk-3EM5GTP3.js +158 -0
- package/dist/chunk-3L5ATO4A.js +52 -0
- package/dist/chunk-3S3PJB7J.js +107 -0
- package/dist/chunk-3SBKYPNM.js +270 -0
- package/dist/chunk-3Z7VA6ET.js +114 -0
- package/dist/chunk-43BRJBEV.js +207 -0
- package/dist/chunk-46LZO4ZO.js +188 -0
- package/dist/chunk-46ZC5VNC.js +38 -0
- package/dist/chunk-4AH4EEHE.js +298 -0
- package/dist/chunk-4D3YJNVN.js +270 -0
- package/dist/chunk-4E5QVAT4.js +4480 -0
- package/dist/chunk-4E5QVAT4.js.map +1 -0
- package/dist/chunk-4I4RTI4D.js +37 -0
- package/dist/chunk-4KASGJTF.js +287 -0
- package/dist/chunk-4RUKLIOF.js +1263 -0
- package/dist/chunk-4UU7FN3I.js +650 -0
- package/dist/chunk-4VEIBNC2.js +427 -0
- package/dist/chunk-4VEIBNC2.js.map +1 -0
- package/dist/chunk-4ZRNASBF.js +2551 -0
- package/dist/chunk-5EJBPQI2.js +41 -0
- package/dist/chunk-5G4IGG7F.js +209 -0
- package/dist/chunk-5JAYZOAW.js +131 -0
- package/dist/chunk-5JOKVDSR.js +789 -0
- package/dist/chunk-5MP3G7ZV.js +1236 -0
- package/dist/chunk-5OVRMKP5.js +42 -0
- package/dist/chunk-5SGTRULO.js +1184 -0
- package/dist/chunk-5SOL4INY.js +572 -0
- package/dist/chunk-5Y34P32B.js +27 -0
- package/dist/chunk-62HIKJ5F.js +72 -0
- package/dist/chunk-62T2ZPD5.js +266 -0
- package/dist/chunk-63VNZRLY.js +386 -0
- package/dist/chunk-6CDBX3XG.js +33 -0
- package/dist/chunk-6D3D2JWY.js +278 -0
- package/dist/chunk-6DOIINY4.js +201 -0
- package/dist/chunk-6DQBUKGJ.js +112 -0
- package/dist/chunk-6SETNFNH.js +1399 -0
- package/dist/chunk-6XYFMHNT.js +56 -0
- package/dist/chunk-6YU3WV2P.js +33 -0
- package/dist/chunk-6YUHDFOZ.js +351 -0
- package/dist/chunk-72EOXOR7.js +1185 -0
- package/dist/chunk-72ND4ALI.js +532 -0
- package/dist/chunk-757LE32E.js +283 -0
- package/dist/chunk-7S2S4MXR.js +138 -0
- package/dist/chunk-7SYCHMXS.js +200 -0
- package/dist/chunk-7TVAPQOV.js +5089 -0
- package/dist/chunk-7UDLRDHK.js +214 -0
- package/dist/chunk-7YLQCMZP.js +357 -0
- package/dist/chunk-A5GX3CAE.js +849 -0
- package/dist/chunk-A7EBV2EB.js +318 -0
- package/dist/chunk-AB5SPXUR.js +114 -0
- package/dist/chunk-AHVQGL5A.js +202 -0
- package/dist/chunk-AI77ZKEV.js +26 -0
- package/dist/chunk-AIX2D6RB.js +1019 -0
- package/dist/chunk-AVSIHP7Q.js +192 -0
- package/dist/chunk-AWK23Q32.js +107 -0
- package/dist/chunk-AYVWA6KD.js +432 -0
- package/dist/chunk-AYZXE4IM.js +2553 -0
- package/dist/chunk-AZGGSPTE.js +124 -0
- package/dist/chunk-B45TB4HY.js +931 -0
- package/dist/chunk-BIUJHNVR.js +46 -0
- package/dist/chunk-BJUOKUE5.js +234 -0
- package/dist/chunk-BPEEVMKH.js +292 -0
- package/dist/chunk-BPHPAGYF.js +74 -0
- package/dist/chunk-BXMND6YU.js +307 -0
- package/dist/chunk-C6OM2SRG.js +117 -0
- package/dist/chunk-CIRCUDKF.js +1309 -0
- package/dist/chunk-CLKR4UG3.js +403 -0
- package/dist/chunk-CPX6BHER.js +554 -0
- package/dist/chunk-CVC4RO7D.js +155 -0
- package/dist/chunk-D3YJAQGK.js +103 -0
- package/dist/chunk-DFQ72BLS.js +1024 -0
- package/dist/chunk-DG65PJOZ.js +4564 -0
- package/dist/chunk-DNAXAS5R.js +406 -0
- package/dist/chunk-DO247ITS.js +175 -0
- package/dist/chunk-DONBARLL.js +154 -0
- package/dist/chunk-DTLXQ3ZU.js +373 -0
- package/dist/chunk-EAXTACI4.js +274 -0
- package/dist/chunk-EDPH7AJH.js +412 -0
- package/dist/chunk-EER3B3G5.js +10036 -0
- package/dist/chunk-EER3B3G5.js.map +1 -0
- package/dist/chunk-EFKQHCGJ.js +276 -0
- package/dist/chunk-EILSPMVD.js +133 -0
- package/dist/chunk-EK7KIETS.js +211 -0
- package/dist/chunk-EMWT6GOK.js +437 -0
- package/dist/chunk-EO22NST7.js +259 -0
- package/dist/chunk-ER5MYLIE.js +256 -0
- package/dist/chunk-ES5HKVQF.js +234 -0
- package/dist/chunk-EXRQ5ATC.js +738 -0
- package/dist/chunk-EXRQ5ATC.js.map +1 -0
- package/dist/chunk-F26YBYAZ.js +111 -0
- package/dist/chunk-F6QP4GSK.js +515 -0
- package/dist/chunk-F7QEO7M2.js +851 -0
- package/dist/chunk-FJFGDLXB.js +12 -0
- package/dist/chunk-FLLJ2WXW.js +113 -0
- package/dist/chunk-FMBJKMT4.js +107 -0
- package/dist/chunk-FPN4I4CG.js +3690 -0
- package/dist/chunk-FUXFJTXL.js +3070 -0
- package/dist/chunk-FXFOKD7A.js +449 -0
- package/dist/chunk-FZI4QOAV.js +3996 -0
- package/dist/chunk-FZI4QOAV.js.map +1 -0
- package/dist/chunk-G6SSSX5R.js +158 -0
- package/dist/chunk-GBGCMHBB.js +608 -0
- package/dist/chunk-GIHE7U3Y.js +174 -0
- package/dist/chunk-GJ4GTYOD.js +372 -0
- package/dist/chunk-GLSDWNFV.js +432 -0
- package/dist/chunk-GMGAW3T6.js +278 -0
- package/dist/chunk-GNGI6XFN.js +43 -0
- package/dist/chunk-GO5VIAA7.js +264 -0
- package/dist/chunk-GSW4YHZE.js +229 -0
- package/dist/chunk-GUC6IWEY.js +407 -0
- package/dist/chunk-GWAY3SO5.js +15 -0
- package/dist/chunk-GXOTNT5D.js +168 -0
- package/dist/chunk-GZZCVF76.js +3851 -0
- package/dist/chunk-H4VMHFOX.js +214 -0
- package/dist/chunk-HA5RFQAF.js +110 -0
- package/dist/chunk-HFROJDFQ.js +118 -0
- package/dist/chunk-HHFFPE67.js +220 -0
- package/dist/chunk-HJLHGXWL.js +103 -0
- package/dist/chunk-HKNMNL7B.js +2984 -0
- package/dist/chunk-HT7MBHLY.js +1021 -0
- package/dist/chunk-I5FSUZVW.js +584 -0
- package/dist/chunk-IINQO425.js +246 -0
- package/dist/chunk-IIXNEOK4.js +1022 -0
- package/dist/chunk-IM3WA5AL.js +311 -0
- package/dist/chunk-IX4P4OGR.js +399 -0
- package/dist/chunk-IX5VHZYS.js +129 -0
- package/dist/chunk-JB3TSUZO.js +263 -0
- package/dist/chunk-JIC6RLUB.js +27 -0
- package/dist/chunk-JNJIZCTN.js +172 -0
- package/dist/chunk-JNV5ZPUV.js +828 -0
- package/dist/chunk-JPQFVR24.js +50 -0
- package/dist/chunk-JPZVMXDP.js +1333 -0
- package/dist/chunk-JVPF34MX.js +215 -0
- package/dist/chunk-KED67KAF.js +85 -0
- package/dist/chunk-KJ72GMZ2.js +378 -0
- package/dist/chunk-KTGKGHEA.js +75 -0
- package/dist/chunk-KU77XHWB.js +285 -0
- package/dist/chunk-KVPQUADA.js +5915 -0
- package/dist/chunk-KVPQUADA.js.map +1 -0
- package/dist/chunk-KXBLLFOO.js +249 -0
- package/dist/chunk-L6WVCO6D.js +61 -0
- package/dist/chunk-LIOZ2MXJ.js +380 -0
- package/dist/chunk-LIOZ2MXJ.js.map +1 -0
- package/dist/chunk-LPEFULJY.js +73 -0
- package/dist/chunk-LRMGPO7E.js +98 -0
- package/dist/chunk-LVKTKORH.js +121 -0
- package/dist/chunk-MCPKUVMQ.js +99 -0
- package/dist/chunk-MFLU3466.js +99 -0
- package/dist/chunk-MIUJ3EH5.js +60 -0
- package/dist/chunk-MIUMNTIJ.js +175 -0
- package/dist/chunk-ML46TXRM.js +113 -0
- package/dist/chunk-MO3XJQN2.js +629 -0
- package/dist/chunk-MQRHTOQ2.js +218 -0
- package/dist/chunk-MVYQDBE6.js +79 -0
- package/dist/chunk-NIPON7YB.js +850 -0
- package/dist/chunk-NIPON7YB.js.map +1 -0
- package/dist/chunk-NPBEUU22.js +196 -0
- package/dist/chunk-NSXKGS2K.js +178 -0
- package/dist/chunk-NUEFORM6.js +2317 -0
- package/dist/chunk-NZOFNQNC.js +176 -0
- package/dist/chunk-O664PL2U.js +47 -0
- package/dist/chunk-O664PL2U.js.map +1 -0
- package/dist/chunk-OATXCLTY.js +211 -0
- package/dist/chunk-OG3ELROW.js +538 -0
- package/dist/chunk-OI4WS7FW.js +162 -0
- package/dist/chunk-OITGZUDC.js +82 -0
- package/dist/chunk-OKD2LBMK.js +333 -0
- package/dist/chunk-OLFOGAWU.js +273 -0
- package/dist/chunk-OLFOGAWU.js.map +1 -0
- package/dist/chunk-OSA4CGST.js +134 -0
- package/dist/chunk-OXYAKUFU.js +401 -0
- package/dist/chunk-OYMSMU5O.js +396 -0
- package/dist/chunk-P4NZ72KY.js +162 -0
- package/dist/chunk-PBYL2VIM.js +379 -0
- package/dist/chunk-PDW3OOSZ.js +505 -0
- package/dist/chunk-PGRKTQIW.js +523 -0
- package/dist/chunk-PPQJIVGM.js +175 -0
- package/dist/chunk-PYMQM65Y.js +125 -0
- package/dist/chunk-Q273Q33U.js +166 -0
- package/dist/chunk-Q4CLS2HL.js +340 -0
- package/dist/chunk-QA5UNVHD.js +85 -0
- package/dist/chunk-QFOBUA2J.js +428 -0
- package/dist/chunk-QLIM4D56.js +1095 -0
- package/dist/chunk-QMQF5U2D.js +20 -0
- package/dist/chunk-QNOWKKZ4.js +40 -0
- package/dist/chunk-QPOUPVPD.js +144 -0
- package/dist/chunk-QTJAQ6DS.js +48 -0
- package/dist/chunk-QUOFP3G7.js +404 -0
- package/dist/chunk-QVOTPOXK.js +29 -0
- package/dist/chunk-QYZ5RVGM.js +184 -0
- package/dist/chunk-R7CVDKRN.js +2580 -0
- package/dist/chunk-RB7MXNZD.js +639 -0
- package/dist/chunk-RDZQFZOQ.js +187 -0
- package/dist/chunk-RIHKEGWS.js +194 -0
- package/dist/chunk-ROSB7GF6.js +57 -0
- package/dist/chunk-RP3YMYCX.js +723 -0
- package/dist/chunk-RPHXJHNX.js +271 -0
- package/dist/chunk-RVC3M66H.js +191 -0
- package/dist/chunk-S3OTJAAC.js +283 -0
- package/dist/chunk-SBWPMVRN.js +56 -0
- package/dist/chunk-SERECSAR.js +138 -0
- package/dist/chunk-SHSEF3GJ.js +187 -0
- package/dist/chunk-SMS2M3RG.js +772 -0
- package/dist/chunk-SRDHDIRQ.js +177 -0
- package/dist/chunk-SXRYA7NN.js +389 -0
- package/dist/chunk-SYA3WYG4.js +1187 -0
- package/dist/chunk-SYYFA7W7.js +23 -0
- package/dist/chunk-T2QDSTBH.js +371 -0
- package/dist/chunk-TFSCGFYV.js +251 -0
- package/dist/chunk-TGCKZOSX.js +246 -0
- package/dist/chunk-THILLYQM.js +132 -0
- package/dist/chunk-TI6LGUEZ.js +2412 -0
- package/dist/chunk-TSY6YZL2.js +366 -0
- package/dist/chunk-TW2RHTLH.js +3321 -0
- package/dist/chunk-TWA5G277.js +141 -0
- package/dist/chunk-TZZ2S4XI.js +247 -0
- package/dist/chunk-U5D3K53R.js +58 -0
- package/dist/chunk-UECD27LX.js +251 -0
- package/dist/chunk-UFJDETKG.js +108 -0
- package/dist/chunk-UHCFYX4I.js +570 -0
- package/dist/chunk-UHTURYJO.js +898 -0
- package/dist/chunk-UJH63JT3.js +67 -0
- package/dist/chunk-UOLDS6S5.js +1152 -0
- package/dist/chunk-UUE3OGXI.js +84 -0
- package/dist/chunk-UUNJ2E57.js +391 -0
- package/dist/chunk-UYQVWRAH.js +199 -0
- package/dist/chunk-UYWVK7JQ.js +234 -0
- package/dist/chunk-UYWWUEL4.js +126 -0
- package/dist/chunk-V4CQKX5H.js +48 -0
- package/dist/chunk-V4QM7GDQ.js +3176 -0
- package/dist/chunk-V5Y74WII.js +91 -0
- package/dist/chunk-VGGZLUQK.js +129 -0
- package/dist/chunk-VGX636MB.js +311 -0
- package/dist/chunk-VGZLFQO2.js +773 -0
- package/dist/chunk-VJWZATNF.js +137 -0
- package/dist/chunk-VMWCIC2N.js +50 -0
- package/dist/chunk-VPWKTIU5.js +227 -0
- package/dist/chunk-VXOLG6YB.js +469 -0
- package/dist/chunk-W2NAU5VB.js +1628 -0
- package/dist/chunk-WGORKMR3.js +353 -0
- package/dist/chunk-WMIDELSJ.js +391 -0
- package/dist/chunk-WSOSGL2G.js +383 -0
- package/dist/chunk-WXUUOM4X.js +400 -0
- package/dist/chunk-WZ74QHLE.js +4863 -0
- package/dist/chunk-WZ74QHLE.js.map +1 -0
- package/dist/chunk-X2OWM2ME.js +1870 -0
- package/dist/chunk-X6UMGG4T.js +68 -0
- package/dist/chunk-XDXKB25W.js +93 -0
- package/dist/chunk-XE4PHI74.js +231 -0
- package/dist/chunk-XHF2XNU5.js +73 -0
- package/dist/chunk-XLJ4SQFS.js +230 -0
- package/dist/chunk-XOD4FX6M.js +2434 -0
- package/dist/chunk-XODQ2GPF.js +3110 -0
- package/dist/chunk-XT54RTAM.js +441 -0
- package/dist/chunk-YAVW5OJ5.js +131 -0
- package/dist/chunk-YDQHFJM2.js +83 -0
- package/dist/chunk-YH6O6OQ6.js +1356 -0
- package/dist/chunk-YIKPC2QP.js +794 -0
- package/dist/chunk-ZD7PKYC4.js +335 -0
- package/dist/chunk-ZEQYHEWP.js +406 -0
- package/dist/chunk-ZP3QCPYG.js +21 -0
- package/dist/chunk-ZRVUCTSI.js +265 -0
- package/dist/chunk-ZSI3ITRK.js +449 -0
- package/dist/chunk-ZZMEQCIZ.js +236 -0
- package/dist/components/browser-viewer.d.ts +4 -1
- package/dist/composer.js +35 -35
- package/dist/computer-viewer-ZBY3BPYW.js +21 -0
- package/dist/connect.js +30 -30
- package/dist/connection-step-up-JQ4OFSQN.js +145 -0
- package/dist/desktop-dictation.js +24 -24
- package/dist/desktop.js +2 -2
- package/dist/editor.js +2 -2
- package/dist/embedded-new-voice-ZB5XLKLU.js +25 -0
- package/dist/embedded-voice-MZJISDCS.js +25 -0
- package/dist/fleet-decision-row-LG3SYVR3.js +361 -0
- package/dist/human-input-model.d.ts +2 -0
- package/dist/in-chat-connect-model.js +6 -6
- package/dist/index.js +298 -298
- package/dist/interaction.d.ts +2 -0
- package/dist/interaction.js +11 -9
- package/dist/interaction.js.map +1 -1
- package/dist/latest-question-QWJTXMFA.js +1 -1
- package/dist/machine-request-model.js +1 -1
- package/dist/machines.js +8 -8
- package/dist/meetings-recorder.js +1 -1
- package/dist/meetings.js +116 -116
- package/dist/messages/en.d.ts +12 -0
- package/dist/messages.js +1 -1
- package/dist/model-levels.js +2 -2
- package/dist/model-picker-model.js +2 -2
- package/dist/model-policy-picker-menu-5Y72PLNF.js +23 -0
- package/dist/model-policy.js +1 -1
- package/dist/payment-page-card-YPSXRHBA.js +226 -0
- package/dist/platform-activity-row-ZU4MEBNK.js +156 -0
- package/dist/queue-surface-implementation-6Q25RPH6.js +932 -0
- package/dist/realtime.js +17 -17
- package/dist/recorder-host-JD4GWJ2Z.js +80 -0
- package/dist/recordings.js +3 -3
- package/dist/sandbox-files-HCLEEJMU.js +28 -0
- package/dist/session-app.js +398 -398
- package/dist/session-connect-cards-DRKEN3Z4.js +27 -0
- package/dist/session-list-model.js +3 -3
- package/dist/session-realtime-IZOTTRH6.js +30 -0
- package/dist/session-realtime.js +2 -2
- package/dist/session-ui.js +95 -95
- package/dist/session.js +42 -42
- package/dist/sites.js +3 -3
- package/dist/terminal.js +2 -2
- package/dist/this-computer.js +3 -3
- package/dist/timeline-annotation-markers-WWXNJOXI.js +157 -0
- package/dist/timeline-annotation-selection-ZKRIQFIQ.js +208 -0
- package/dist/timeline-annotations-dialog-4IMKTOXJ.js +283 -0
- package/dist/timeline-model.js +58 -58
- package/dist/ui/access-list.js +23 -23
- package/dist/ui/cadence-picker.js +7 -7
- package/dist/ui/choice-cards.js +3 -3
- package/dist/ui/confirm-dialog.js +2 -2
- package/dist/ui/copy-field.js +3 -3
- package/dist/ui/detail-page.js +5 -5
- package/dist/ui/detail-sheet.js +5 -5
- package/dist/ui/diff-view.js +3 -3
- package/dist/ui/disclosure.js +6 -6
- package/dist/ui/email-chips-input.js +3 -3
- package/dist/ui/field.js +2 -2
- package/dist/ui/flush-form-page.js +7 -7
- package/dist/ui/form-dialog.js +6 -6
- package/dist/ui/list-row.js +6 -6
- package/dist/ui/load-failure.js +3 -3
- package/dist/ui/relative-time.js +3 -3
- package/dist/ui/revision-history.js +13 -13
- package/dist/ui/role-select.js +11 -11
- package/dist/ui/select-menu.js +5 -5
- package/dist/ui/settings-nav.js +6 -6
- package/dist/ui/sheet.js +2 -2
- package/dist/ui/usage-meter.js +4 -4
- package/dist/usage.js +3 -3
- package/dist/workbench.js +11 -11
- package/package.json +5 -6
- package/src/components/browser-viewer.tsx +109 -72
- package/src/components/secret-question-field.tsx +2 -1
- package/src/human-input-model.ts +53 -10
- package/src/interaction.ts +2 -0
- package/src/messages/en.ts +12 -0
- package/src/model-policy.ts +3 -1
- package/dist/browser-viewer-5DCULGWS.js +0 -23
- package/dist/chat-interactive-block-ISMUKH3P.js +0 -22
- package/dist/chunk-22NKV5QE.js +0 -133
- package/dist/chunk-25SCFA2X.js +0 -794
- package/dist/chunk-2NJRDH3Z.js +0 -4480
- package/dist/chunk-2NJRDH3Z.js.map +0 -1
- package/dist/chunk-2O5EDTVB.js +0 -723
- package/dist/chunk-2R7AOT3Y.js +0 -400
- package/dist/chunk-2XQFDRP6.js +0 -234
- package/dist/chunk-34XY4PWB.js +0 -2412
- package/dist/chunk-37J33BLN.js +0 -107
- package/dist/chunk-3AXHBU7K.js +0 -818
- package/dist/chunk-3B4D4BV7.js +0 -270
- package/dist/chunk-3EQMXU5V.js +0 -403
- package/dist/chunk-3QUDVXDR.js +0 -227
- package/dist/chunk-3SKJO525.js +0 -215
- package/dist/chunk-3Y2VSFYS.js +0 -26
- package/dist/chunk-3Y7IJPHB.js +0 -3321
- package/dist/chunk-3YLXGP2I.js +0 -515
- package/dist/chunk-4AUUNEQY.js +0 -15
- package/dist/chunk-4D4XXJJJ.js +0 -379
- package/dist/chunk-4DW5QEAP.js +0 -201
- package/dist/chunk-4KF5I3H5.js +0 -335
- package/dist/chunk-4PG2BEQA.js +0 -175
- package/dist/chunk-4SW3EUNM.js +0 -83
- package/dist/chunk-4T2KWNYX.js +0 -378
- package/dist/chunk-4TTWUMDP.js +0 -168
- package/dist/chunk-4WKITG7P.js +0 -132
- package/dist/chunk-4YXA5UO3.js +0 -287
- package/dist/chunk-4ZCTHNOA.js +0 -298
- package/dist/chunk-52BUMJQB.js +0 -98
- package/dist/chunk-53ZK2JFE.js +0 -538
- package/dist/chunk-5ABIZ7YT.js +0 -371
- package/dist/chunk-5AHIKB3O.js +0 -449
- package/dist/chunk-5DEP55DK.js +0 -251
- package/dist/chunk-5ERDSF2C.js +0 -79
- package/dist/chunk-5G55HNJB.js +0 -412
- package/dist/chunk-62AHHCFV.js +0 -340
- package/dist/chunk-644P2VLV.js +0 -407
- package/dist/chunk-6F34IWSA.js +0 -47
- package/dist/chunk-6F34IWSA.js.map +0 -1
- package/dist/chunk-6QDXVH45.js +0 -114
- package/dist/chunk-6TBA45QF.js +0 -12
- package/dist/chunk-6Y3EFN4Q.js +0 -265
- package/dist/chunk-73P7NEOX.js +0 -52
- package/dist/chunk-7CLQ7RQV.js +0 -828
- package/dist/chunk-7M57K6K5.js +0 -505
- package/dist/chunk-7QORJTVI.js +0 -3690
- package/dist/chunk-ABO54U65.js +0 -108
- package/dist/chunk-ANCI6T7S.js +0 -406
- package/dist/chunk-AO27D7GY.js +0 -1021
- package/dist/chunk-ATQ3O5E6.js +0 -144
- package/dist/chunk-AXBSHKRP.js +0 -246
- package/dist/chunk-AZC5P5PV.js +0 -131
- package/dist/chunk-B6YDINPE.js +0 -68
- package/dist/chunk-BJNSS4UV.js +0 -399
- package/dist/chunk-BKYHS4IH.js +0 -276
- package/dist/chunk-BOCDCQYX.js +0 -41
- package/dist/chunk-BOP5TAUU.js +0 -229
- package/dist/chunk-BPD6VRVH.js +0 -432
- package/dist/chunk-BSAKPNKY.js +0 -263
- package/dist/chunk-BUBEMKK3.js +0 -4845
- package/dist/chunk-BUBEMKK3.js.map +0 -1
- package/dist/chunk-BXKNGFX5.js +0 -5089
- package/dist/chunk-CBHZXVSI.js +0 -207
- package/dist/chunk-CGEAOUXW.js +0 -246
- package/dist/chunk-CGWLKFQF.js +0 -2580
- package/dist/chunk-CIDJMJ44.js +0 -380
- package/dist/chunk-CIDJMJ44.js.map +0 -1
- package/dist/chunk-CNLR3MVZ.js +0 -175
- package/dist/chunk-CPN7JXYV.js +0 -93
- package/dist/chunk-DDCDQ4BF.js +0 -2551
- package/dist/chunk-DK5L6E4G.js +0 -391
- package/dist/chunk-DMDJPQCR.js +0 -5903
- package/dist/chunk-DMDJPQCR.js.map +0 -1
- package/dist/chunk-DNNW2FSP.js +0 -256
- package/dist/chunk-DRPIGAMM.js +0 -4564
- package/dist/chunk-DUZZB4C6.js +0 -283
- package/dist/chunk-DWH35C5X.js +0 -56
- package/dist/chunk-DWW2MA3S.js +0 -278
- package/dist/chunk-E4NQIEA3.js +0 -85
- package/dist/chunk-E4SAFP76.js +0 -112
- package/dist/chunk-EO7NZKIX.js +0 -249
- package/dist/chunk-EQSANTUC.js +0 -84
- package/dist/chunk-EVHNQCEM.js +0 -214
- package/dist/chunk-EVRLHFIG.js +0 -187
- package/dist/chunk-FAVXYNTK.js +0 -67
- package/dist/chunk-FRDJUZ6E.js +0 -91
- package/dist/chunk-FWRKCWQO.js +0 -141
- package/dist/chunk-G65TM5FL.js +0 -166
- package/dist/chunk-G7TU7QDO.js +0 -432
- package/dist/chunk-GGIPEZLL.js +0 -849
- package/dist/chunk-GKA5LFYR.js +0 -21
- package/dist/chunk-GMQFRX2V.js +0 -406
- package/dist/chunk-HE5BTYPR.js +0 -37
- package/dist/chunk-HI6TPRY5.js +0 -1356
- package/dist/chunk-HLNSIXSJ.js +0 -357
- package/dist/chunk-HUKGLWAY.js +0 -174
- package/dist/chunk-HUTQJY3F.js +0 -23
- package/dist/chunk-HWDHA4KS.js +0 -137
- package/dist/chunk-HWDKTGNX.js +0 -1263
- package/dist/chunk-HWOJ7JSO.js +0 -20
- package/dist/chunk-HWOYJOKK.js +0 -266
- package/dist/chunk-HXVKXFIC.js +0 -56
- package/dist/chunk-HYVRYGY3.js +0 -270
- package/dist/chunk-I5ZTAMDP.js +0 -27
- package/dist/chunk-IGVRNMXK.js +0 -154
- package/dist/chunk-IHNCZONS.js +0 -230
- package/dist/chunk-IIUBCLH6.js +0 -437
- package/dist/chunk-IQKLWMIF.js +0 -373
- package/dist/chunk-IQWAFZGW.js +0 -191
- package/dist/chunk-J3GK2LZP.js +0 -292
- package/dist/chunk-J4OOKDRV.js +0 -40
- package/dist/chunk-JBNCFLMW.js +0 -3996
- package/dist/chunk-JBNCFLMW.js.map +0 -1
- package/dist/chunk-JY4ACIKP.js +0 -194
- package/dist/chunk-KDZ7WKYY.js +0 -192
- package/dist/chunk-KGTZGR4F.js +0 -172
- package/dist/chunk-KKIJYI7N.js +0 -351
- package/dist/chunk-KLOB3IXX.js +0 -175
- package/dist/chunk-KMZUIWL6.js +0 -107
- package/dist/chunk-KUYTRUIE.js +0 -214
- package/dist/chunk-KYDLVMKA.js +0 -99
- package/dist/chunk-KZQDP2JM.js +0 -155
- package/dist/chunk-L22AVXXW.js +0 -187
- package/dist/chunk-L5AQCKRR.js +0 -311
- package/dist/chunk-LG3WCCUT.js +0 -188
- package/dist/chunk-LRE7WH6D.js +0 -1095
- package/dist/chunk-LSQP22UI.js +0 -176
- package/dist/chunk-LTNBDO5B.js +0 -72
- package/dist/chunk-LUUFLV27.js +0 -113
- package/dist/chunk-M2KDPKQC.js +0 -126
- package/dist/chunk-M5FX5KH5.js +0 -629
- package/dist/chunk-MD27CX2K.js +0 -1022
- package/dist/chunk-MEUAI3B7.js +0 -199
- package/dist/chunk-MFYH4N6I.js +0 -650
- package/dist/chunk-MPW67ODY.js +0 -639
- package/dist/chunk-MRNOTVGF.js +0 -366
- package/dist/chunk-MTOWY5MX.js +0 -307
- package/dist/chunk-MVLHO6AU.js +0 -441
- package/dist/chunk-N4AHWDN2.js +0 -121
- package/dist/chunk-NABGUV6O.js +0 -48
- package/dist/chunk-NH6OLIQD.js +0 -1628
- package/dist/chunk-NKCK4LBK.js +0 -103
- package/dist/chunk-NNE73MK2.js +0 -1333
- package/dist/chunk-NPKFHO6N.js +0 -584
- package/dist/chunk-NRRRO3NJ.js +0 -851
- package/dist/chunk-NSLCRIQ6.js +0 -386
- package/dist/chunk-NUZNJSL5.js +0 -285
- package/dist/chunk-NYTKZQ2V.js +0 -234
- package/dist/chunk-O4UAH7WR.js +0 -427
- package/dist/chunk-O4UAH7WR.js.map +0 -1
- package/dist/chunk-OAEI3MUO.js +0 -50
- package/dist/chunk-OCWCZRVU.js +0 -3110
- package/dist/chunk-ODR2Q4JQ.js +0 -1236
- package/dist/chunk-ODWNT3XC.js +0 -3176
- package/dist/chunk-OE6XABJ3.js +0 -269
- package/dist/chunk-OEGJWY2U.js +0 -3851
- package/dist/chunk-OHJXHKQT.js +0 -162
- package/dist/chunk-OJE3WTHK.js +0 -391
- package/dist/chunk-OJNZTTQE.js +0 -353
- package/dist/chunk-OMYNOB7U.js +0 -124
- package/dist/chunk-OX234K6A.js +0 -1399
- package/dist/chunk-OYJ7KP6H.js +0 -1152
- package/dist/chunk-OZGG6TS7.js +0 -554
- package/dist/chunk-P5DGNIGZ.js +0 -773
- package/dist/chunk-PCSRHFRF.js +0 -75
- package/dist/chunk-PGDGX6PO.js +0 -178
- package/dist/chunk-PGMXITPB.js +0 -85
- package/dist/chunk-PHNLFMBS.js +0 -158
- package/dist/chunk-PJF47YJJ.js +0 -202
- package/dist/chunk-PMBZMVKE.js +0 -33
- package/dist/chunk-PNLVWZSM.js +0 -211
- package/dist/chunk-PQ7WJAKL.js +0 -74
- package/dist/chunk-PTLRNXWE.js +0 -200
- package/dist/chunk-PTSRBKQC.js +0 -118
- package/dist/chunk-PX64T6XV.js +0 -134
- package/dist/chunk-PYS63BC6.js +0 -138
- package/dist/chunk-QHPB7VSA.js +0 -111
- package/dist/chunk-QJQTLBT3.js +0 -73
- package/dist/chunk-QR74WLXN.js +0 -65
- package/dist/chunk-QZSIADFZ.js +0 -523
- package/dist/chunk-R2T4IUNB.js +0 -29
- package/dist/chunk-R6CFPY3F.js +0 -278
- package/dist/chunk-R6OBJ7LF.js +0 -131
- package/dist/chunk-R6WQLIFX.js +0 -73
- package/dist/chunk-R7QHNWYL.js +0 -1309
- package/dist/chunk-R7ZIFQ7D.js +0 -738
- package/dist/chunk-R7ZIFQ7D.js.map +0 -1
- package/dist/chunk-RCKXQ2RY.js +0 -3070
- package/dist/chunk-RCN3SVJC.js +0 -211
- package/dist/chunk-RDTZN6HR.js +0 -372
- package/dist/chunk-RET43Z3F.js +0 -43
- package/dist/chunk-REUQ464X.js +0 -898
- package/dist/chunk-RIOTQESW.js +0 -107
- package/dist/chunk-RPJC2JCE.js +0 -209
- package/dist/chunk-RT2GW3LO.js +0 -10035
- package/dist/chunk-RT2GW3LO.js.map +0 -1
- package/dist/chunk-RULIWGQ6.js +0 -2984
- package/dist/chunk-RWZ5XML5.js +0 -103
- package/dist/chunk-RYWPD5WU.js +0 -572
- package/dist/chunk-RYYBQ4PW.js +0 -129
- package/dist/chunk-S44ADSZG.js +0 -236
- package/dist/chunk-SB3LGY34.js +0 -27
- package/dist/chunk-SG4FA5CX.js +0 -33
- package/dist/chunk-SMCHRNUL.js +0 -129
- package/dist/chunk-SMSEI6VH.js +0 -184
- package/dist/chunk-SNACGK3Z.js +0 -177
- package/dist/chunk-SOZTO34S.js +0 -2553
- package/dist/chunk-SP7XRRGB.js +0 -428
- package/dist/chunk-STA75WRF.js +0 -383
- package/dist/chunk-SUO5NPEX.js +0 -318
- package/dist/chunk-T2NC7ALH.js +0 -333
- package/dist/chunk-T3OUZVHU.js +0 -250
- package/dist/chunk-T4YOQ6DF.js +0 -789
- package/dist/chunk-TGG3ODCS.js +0 -99
- package/dist/chunk-TLR2SX7T.js +0 -2317
- package/dist/chunk-TXCGPEWC.js +0 -243
- package/dist/chunk-TXCGPEWC.js.map +0 -1
- package/dist/chunk-TZGJPDZL.js +0 -259
- package/dist/chunk-U7KNZEMU.js +0 -271
- package/dist/chunk-UDDZDC2Q.js +0 -772
- package/dist/chunk-UFIETNB2.js +0 -469
- package/dist/chunk-UFRXYZCJ.js +0 -125
- package/dist/chunk-UILJ5INQ.js +0 -170
- package/dist/chunk-UJ4DLPYG.js +0 -449
- package/dist/chunk-UKDLZ76A.js +0 -2434
- package/dist/chunk-UMYCZQSL.js +0 -1870
- package/dist/chunk-UPRN4FBY.js +0 -38
- package/dist/chunk-UQBYKWGG.js +0 -311
- package/dist/chunk-UQR5RZ5I.js +0 -218
- package/dist/chunk-UWPSCSIZ.js +0 -57
- package/dist/chunk-UYLO2JP2.js +0 -158
- package/dist/chunk-V2YSF3MJ.js +0 -114
- package/dist/chunk-VAJQQKSG.js +0 -283
- package/dist/chunk-VDHWFRTL.js +0 -58
- package/dist/chunk-VLDKWGHD.js +0 -61
- package/dist/chunk-VLODMRE3.js +0 -138
- package/dist/chunk-VM6BM3NV.js +0 -389
- package/dist/chunk-VRVB2XSO.js +0 -117
- package/dist/chunk-W2PBDF4F.js +0 -231
- package/dist/chunk-W7BNYXRT.js +0 -296
- package/dist/chunk-WCA777NS.js +0 -1187
- package/dist/chunk-WDDAHRBC.js +0 -404
- package/dist/chunk-WEXKKIPB.js +0 -1024
- package/dist/chunk-WG7OVUCV.js +0 -401
- package/dist/chunk-WMW4AXVG.js +0 -570
- package/dist/chunk-WRMMZYZC.js +0 -931
- package/dist/chunk-WYICOILE.js +0 -50
- package/dist/chunk-WYNXSYTH.js +0 -532
- package/dist/chunk-X62OJCQW.js +0 -234
- package/dist/chunk-XBFNNP6B.js +0 -608
- package/dist/chunk-XDXPGA3N.js +0 -850
- package/dist/chunk-XDXPGA3N.js.map +0 -1
- package/dist/chunk-XFP3AIZO.js +0 -247
- package/dist/chunk-XSL5GKL3.js +0 -110
- package/dist/chunk-XVXYLCSC.js +0 -82
- package/dist/chunk-XX2J7H2J.js +0 -196
- package/dist/chunk-Y6CNWBV3.js +0 -264
- package/dist/chunk-YEFIICAN.js +0 -46
- package/dist/chunk-YJBRNXFL.js +0 -1184
- package/dist/chunk-YP4SNX4P.js +0 -220
- package/dist/chunk-YQ6AYWGT.js +0 -162
- package/dist/chunk-YWKJSF3R.js +0 -396
- package/dist/chunk-Z3EQ3XBB.js +0 -114
- package/dist/chunk-ZD67RM6G.js +0 -60
- package/dist/chunk-ZMCVED5L.js +0 -1185
- package/dist/chunk-ZOTNM76R.js +0 -42
- package/dist/chunk-ZP7BJXQ5.js +0 -113
- package/dist/chunk-ZRNDPAED.js +0 -274
- package/dist/chunk-ZUQKQP3T.js +0 -251
- package/dist/chunk-ZVT2KQTH.js +0 -48
- package/dist/chunk-ZXDIEGD5.js +0 -1019
- package/dist/computer-viewer-KLRAA56S.js +0 -21
- package/dist/connection-step-up-PWIIW3KK.js +0 -145
- package/dist/embedded-new-voice-P2RCFI3X.js +0 -25
- package/dist/embedded-voice-HY5F4D2I.js +0 -25
- package/dist/fleet-decision-row-UEXT7NAN.js +0 -361
- package/dist/model-policy-picker-menu-AAGNLTEG.js +0 -23
- package/dist/payment-page-card-MHTYJHCW.js +0 -226
- package/dist/platform-activity-row-7VAPGRZQ.js +0 -156
- package/dist/queue-surface-implementation-AE5P3PSA.js +0 -932
- package/dist/recorder-host-I53BQIRX.js +0 -80
- package/dist/sandbox-files-LGE7EDX2.js +0 -28
- package/dist/session-connect-cards-QNL7WRKJ.js +0 -27
- package/dist/session-realtime-ZMXMK5EV.js +0 -30
- package/dist/timeline-annotation-markers-5RICTVVW.js +0 -157
- package/dist/timeline-annotation-selection-ITAHBOFW.js +0 -208
- package/dist/timeline-annotations-dialog-7PGBTPVD.js +0 -283
- /package/dist/{browser-viewer-5DCULGWS.js.map → browser-viewer-EIEMRVFF.js.map} +0 -0
- /package/dist/{chat-interactive-block-ISMUKH3P.js.map → chat-interactive-block-FV37LWYZ.js.map} +0 -0
- /package/dist/{chunk-3AXHBU7K.js.map → chunk-2COBAJC7.js.map} +0 -0
- /package/dist/{chunk-UILJ5INQ.js.map → chunk-2HS3IUXE.js.map} +0 -0
- /package/dist/{chunk-W7BNYXRT.js.map → chunk-2JTMFYCT.js.map} +0 -0
- /package/dist/{chunk-V2YSF3MJ.js.map → chunk-2JXKP4M6.js.map} +0 -0
- /package/dist/{chunk-OE6XABJ3.js.map → chunk-2P5K7CBH.js.map} +0 -0
- /package/dist/{chunk-T3OUZVHU.js.map → chunk-2XGRHMRI.js.map} +0 -0
- /package/dist/{chunk-QR74WLXN.js.map → chunk-332BYSAZ.js.map} +0 -0
- /package/dist/{chunk-UYLO2JP2.js.map → chunk-3EM5GTP3.js.map} +0 -0
- /package/dist/{chunk-73P7NEOX.js.map → chunk-3L5ATO4A.js.map} +0 -0
- /package/dist/{chunk-RIOTQESW.js.map → chunk-3S3PJB7J.js.map} +0 -0
- /package/dist/{chunk-HYVRYGY3.js.map → chunk-3SBKYPNM.js.map} +0 -0
- /package/dist/{chunk-6QDXVH45.js.map → chunk-3Z7VA6ET.js.map} +0 -0
- /package/dist/{chunk-CBHZXVSI.js.map → chunk-43BRJBEV.js.map} +0 -0
- /package/dist/{chunk-LG3WCCUT.js.map → chunk-46LZO4ZO.js.map} +0 -0
- /package/dist/{chunk-UPRN4FBY.js.map → chunk-46ZC5VNC.js.map} +0 -0
- /package/dist/{chunk-4ZCTHNOA.js.map → chunk-4AH4EEHE.js.map} +0 -0
- /package/dist/{chunk-3B4D4BV7.js.map → chunk-4D3YJNVN.js.map} +0 -0
- /package/dist/{chunk-HE5BTYPR.js.map → chunk-4I4RTI4D.js.map} +0 -0
- /package/dist/{chunk-4YXA5UO3.js.map → chunk-4KASGJTF.js.map} +0 -0
- /package/dist/{chunk-HWDKTGNX.js.map → chunk-4RUKLIOF.js.map} +0 -0
- /package/dist/{chunk-MFYH4N6I.js.map → chunk-4UU7FN3I.js.map} +0 -0
- /package/dist/{chunk-DDCDQ4BF.js.map → chunk-4ZRNASBF.js.map} +0 -0
- /package/dist/{chunk-BOCDCQYX.js.map → chunk-5EJBPQI2.js.map} +0 -0
- /package/dist/{chunk-RPJC2JCE.js.map → chunk-5G4IGG7F.js.map} +0 -0
- /package/dist/{chunk-AZC5P5PV.js.map → chunk-5JAYZOAW.js.map} +0 -0
- /package/dist/{chunk-T4YOQ6DF.js.map → chunk-5JOKVDSR.js.map} +0 -0
- /package/dist/{chunk-ODR2Q4JQ.js.map → chunk-5MP3G7ZV.js.map} +0 -0
- /package/dist/{chunk-ZOTNM76R.js.map → chunk-5OVRMKP5.js.map} +0 -0
- /package/dist/{chunk-YJBRNXFL.js.map → chunk-5SGTRULO.js.map} +0 -0
- /package/dist/{chunk-RYWPD5WU.js.map → chunk-5SOL4INY.js.map} +0 -0
- /package/dist/{chunk-SB3LGY34.js.map → chunk-5Y34P32B.js.map} +0 -0
- /package/dist/{chunk-LTNBDO5B.js.map → chunk-62HIKJ5F.js.map} +0 -0
- /package/dist/{chunk-HWOYJOKK.js.map → chunk-62T2ZPD5.js.map} +0 -0
- /package/dist/{chunk-NSLCRIQ6.js.map → chunk-63VNZRLY.js.map} +0 -0
- /package/dist/{chunk-PMBZMVKE.js.map → chunk-6CDBX3XG.js.map} +0 -0
- /package/dist/{chunk-R6CFPY3F.js.map → chunk-6D3D2JWY.js.map} +0 -0
- /package/dist/{chunk-4DW5QEAP.js.map → chunk-6DOIINY4.js.map} +0 -0
- /package/dist/{chunk-E4SAFP76.js.map → chunk-6DQBUKGJ.js.map} +0 -0
- /package/dist/{chunk-OX234K6A.js.map → chunk-6SETNFNH.js.map} +0 -0
- /package/dist/{chunk-HXVKXFIC.js.map → chunk-6XYFMHNT.js.map} +0 -0
- /package/dist/{chunk-SG4FA5CX.js.map → chunk-6YU3WV2P.js.map} +0 -0
- /package/dist/{chunk-KKIJYI7N.js.map → chunk-6YUHDFOZ.js.map} +0 -0
- /package/dist/{chunk-ZMCVED5L.js.map → chunk-72EOXOR7.js.map} +0 -0
- /package/dist/{chunk-WYNXSYTH.js.map → chunk-72ND4ALI.js.map} +0 -0
- /package/dist/{chunk-DUZZB4C6.js.map → chunk-757LE32E.js.map} +0 -0
- /package/dist/{chunk-VLODMRE3.js.map → chunk-7S2S4MXR.js.map} +0 -0
- /package/dist/{chunk-PTLRNXWE.js.map → chunk-7SYCHMXS.js.map} +0 -0
- /package/dist/{chunk-BXKNGFX5.js.map → chunk-7TVAPQOV.js.map} +0 -0
- /package/dist/{chunk-EVHNQCEM.js.map → chunk-7UDLRDHK.js.map} +0 -0
- /package/dist/{chunk-HLNSIXSJ.js.map → chunk-7YLQCMZP.js.map} +0 -0
- /package/dist/{chunk-GGIPEZLL.js.map → chunk-A5GX3CAE.js.map} +0 -0
- /package/dist/{chunk-SUO5NPEX.js.map → chunk-A7EBV2EB.js.map} +0 -0
- /package/dist/{chunk-Z3EQ3XBB.js.map → chunk-AB5SPXUR.js.map} +0 -0
- /package/dist/{chunk-PJF47YJJ.js.map → chunk-AHVQGL5A.js.map} +0 -0
- /package/dist/{chunk-3Y2VSFYS.js.map → chunk-AI77ZKEV.js.map} +0 -0
- /package/dist/{chunk-ZXDIEGD5.js.map → chunk-AIX2D6RB.js.map} +0 -0
- /package/dist/{chunk-KDZ7WKYY.js.map → chunk-AVSIHP7Q.js.map} +0 -0
- /package/dist/{chunk-37J33BLN.js.map → chunk-AWK23Q32.js.map} +0 -0
- /package/dist/{chunk-G7TU7QDO.js.map → chunk-AYVWA6KD.js.map} +0 -0
- /package/dist/{chunk-SOZTO34S.js.map → chunk-AYZXE4IM.js.map} +0 -0
- /package/dist/{chunk-OMYNOB7U.js.map → chunk-AZGGSPTE.js.map} +0 -0
- /package/dist/{chunk-WRMMZYZC.js.map → chunk-B45TB4HY.js.map} +0 -0
- /package/dist/{chunk-YEFIICAN.js.map → chunk-BIUJHNVR.js.map} +0 -0
- /package/dist/{chunk-NYTKZQ2V.js.map → chunk-BJUOKUE5.js.map} +0 -0
- /package/dist/{chunk-J3GK2LZP.js.map → chunk-BPEEVMKH.js.map} +0 -0
- /package/dist/{chunk-PQ7WJAKL.js.map → chunk-BPHPAGYF.js.map} +0 -0
- /package/dist/{chunk-MTOWY5MX.js.map → chunk-BXMND6YU.js.map} +0 -0
- /package/dist/{chunk-VRVB2XSO.js.map → chunk-C6OM2SRG.js.map} +0 -0
- /package/dist/{chunk-R7QHNWYL.js.map → chunk-CIRCUDKF.js.map} +0 -0
- /package/dist/{chunk-3EQMXU5V.js.map → chunk-CLKR4UG3.js.map} +0 -0
- /package/dist/{chunk-OZGG6TS7.js.map → chunk-CPX6BHER.js.map} +0 -0
- /package/dist/{chunk-KZQDP2JM.js.map → chunk-CVC4RO7D.js.map} +0 -0
- /package/dist/{chunk-NKCK4LBK.js.map → chunk-D3YJAQGK.js.map} +0 -0
- /package/dist/{chunk-WEXKKIPB.js.map → chunk-DFQ72BLS.js.map} +0 -0
- /package/dist/{chunk-DRPIGAMM.js.map → chunk-DG65PJOZ.js.map} +0 -0
- /package/dist/{chunk-GMQFRX2V.js.map → chunk-DNAXAS5R.js.map} +0 -0
- /package/dist/{chunk-CNLR3MVZ.js.map → chunk-DO247ITS.js.map} +0 -0
- /package/dist/{chunk-IGVRNMXK.js.map → chunk-DONBARLL.js.map} +0 -0
- /package/dist/{chunk-IQKLWMIF.js.map → chunk-DTLXQ3ZU.js.map} +0 -0
- /package/dist/{chunk-ZRNDPAED.js.map → chunk-EAXTACI4.js.map} +0 -0
- /package/dist/{chunk-5G55HNJB.js.map → chunk-EDPH7AJH.js.map} +0 -0
- /package/dist/{chunk-BKYHS4IH.js.map → chunk-EFKQHCGJ.js.map} +0 -0
- /package/dist/{chunk-22NKV5QE.js.map → chunk-EILSPMVD.js.map} +0 -0
- /package/dist/{chunk-PNLVWZSM.js.map → chunk-EK7KIETS.js.map} +0 -0
- /package/dist/{chunk-IIUBCLH6.js.map → chunk-EMWT6GOK.js.map} +0 -0
- /package/dist/{chunk-TZGJPDZL.js.map → chunk-EO22NST7.js.map} +0 -0
- /package/dist/{chunk-DNNW2FSP.js.map → chunk-ER5MYLIE.js.map} +0 -0
- /package/dist/{chunk-2XQFDRP6.js.map → chunk-ES5HKVQF.js.map} +0 -0
- /package/dist/{chunk-QHPB7VSA.js.map → chunk-F26YBYAZ.js.map} +0 -0
- /package/dist/{chunk-3YLXGP2I.js.map → chunk-F6QP4GSK.js.map} +0 -0
- /package/dist/{chunk-NRRRO3NJ.js.map → chunk-F7QEO7M2.js.map} +0 -0
- /package/dist/{chunk-6TBA45QF.js.map → chunk-FJFGDLXB.js.map} +0 -0
- /package/dist/{chunk-LUUFLV27.js.map → chunk-FLLJ2WXW.js.map} +0 -0
- /package/dist/{chunk-KMZUIWL6.js.map → chunk-FMBJKMT4.js.map} +0 -0
- /package/dist/{chunk-7QORJTVI.js.map → chunk-FPN4I4CG.js.map} +0 -0
- /package/dist/{chunk-RCKXQ2RY.js.map → chunk-FUXFJTXL.js.map} +0 -0
- /package/dist/{chunk-5AHIKB3O.js.map → chunk-FXFOKD7A.js.map} +0 -0
- /package/dist/{chunk-PHNLFMBS.js.map → chunk-G6SSSX5R.js.map} +0 -0
- /package/dist/{chunk-XBFNNP6B.js.map → chunk-GBGCMHBB.js.map} +0 -0
- /package/dist/{chunk-HUKGLWAY.js.map → chunk-GIHE7U3Y.js.map} +0 -0
- /package/dist/{chunk-RDTZN6HR.js.map → chunk-GJ4GTYOD.js.map} +0 -0
- /package/dist/{chunk-BPD6VRVH.js.map → chunk-GLSDWNFV.js.map} +0 -0
- /package/dist/{chunk-DWW2MA3S.js.map → chunk-GMGAW3T6.js.map} +0 -0
- /package/dist/{chunk-RET43Z3F.js.map → chunk-GNGI6XFN.js.map} +0 -0
- /package/dist/{chunk-Y6CNWBV3.js.map → chunk-GO5VIAA7.js.map} +0 -0
- /package/dist/{chunk-BOP5TAUU.js.map → chunk-GSW4YHZE.js.map} +0 -0
- /package/dist/{chunk-644P2VLV.js.map → chunk-GUC6IWEY.js.map} +0 -0
- /package/dist/{chunk-4AUUNEQY.js.map → chunk-GWAY3SO5.js.map} +0 -0
- /package/dist/{chunk-4TTWUMDP.js.map → chunk-GXOTNT5D.js.map} +0 -0
- /package/dist/{chunk-OEGJWY2U.js.map → chunk-GZZCVF76.js.map} +0 -0
- /package/dist/{chunk-KUYTRUIE.js.map → chunk-H4VMHFOX.js.map} +0 -0
- /package/dist/{chunk-XSL5GKL3.js.map → chunk-HA5RFQAF.js.map} +0 -0
- /package/dist/{chunk-PTSRBKQC.js.map → chunk-HFROJDFQ.js.map} +0 -0
- /package/dist/{chunk-YP4SNX4P.js.map → chunk-HHFFPE67.js.map} +0 -0
- /package/dist/{chunk-RWZ5XML5.js.map → chunk-HJLHGXWL.js.map} +0 -0
- /package/dist/{chunk-RULIWGQ6.js.map → chunk-HKNMNL7B.js.map} +0 -0
- /package/dist/{chunk-AO27D7GY.js.map → chunk-HT7MBHLY.js.map} +0 -0
- /package/dist/{chunk-NPKFHO6N.js.map → chunk-I5FSUZVW.js.map} +0 -0
- /package/dist/{chunk-AXBSHKRP.js.map → chunk-IINQO425.js.map} +0 -0
- /package/dist/{chunk-MD27CX2K.js.map → chunk-IIXNEOK4.js.map} +0 -0
- /package/dist/{chunk-UQBYKWGG.js.map → chunk-IM3WA5AL.js.map} +0 -0
- /package/dist/{chunk-BJNSS4UV.js.map → chunk-IX4P4OGR.js.map} +0 -0
- /package/dist/{chunk-SMCHRNUL.js.map → chunk-IX5VHZYS.js.map} +0 -0
- /package/dist/{chunk-BSAKPNKY.js.map → chunk-JB3TSUZO.js.map} +0 -0
- /package/dist/{chunk-I5ZTAMDP.js.map → chunk-JIC6RLUB.js.map} +0 -0
- /package/dist/{chunk-KGTZGR4F.js.map → chunk-JNJIZCTN.js.map} +0 -0
- /package/dist/{chunk-7CLQ7RQV.js.map → chunk-JNV5ZPUV.js.map} +0 -0
- /package/dist/{chunk-OAEI3MUO.js.map → chunk-JPQFVR24.js.map} +0 -0
- /package/dist/{chunk-NNE73MK2.js.map → chunk-JPZVMXDP.js.map} +0 -0
- /package/dist/{chunk-3SKJO525.js.map → chunk-JVPF34MX.js.map} +0 -0
- /package/dist/{chunk-E4NQIEA3.js.map → chunk-KED67KAF.js.map} +0 -0
- /package/dist/{chunk-4T2KWNYX.js.map → chunk-KJ72GMZ2.js.map} +0 -0
- /package/dist/{chunk-PCSRHFRF.js.map → chunk-KTGKGHEA.js.map} +0 -0
- /package/dist/{chunk-NUZNJSL5.js.map → chunk-KU77XHWB.js.map} +0 -0
- /package/dist/{chunk-EO7NZKIX.js.map → chunk-KXBLLFOO.js.map} +0 -0
- /package/dist/{chunk-VLDKWGHD.js.map → chunk-L6WVCO6D.js.map} +0 -0
- /package/dist/{chunk-QJQTLBT3.js.map → chunk-LPEFULJY.js.map} +0 -0
- /package/dist/{chunk-52BUMJQB.js.map → chunk-LRMGPO7E.js.map} +0 -0
- /package/dist/{chunk-N4AHWDN2.js.map → chunk-LVKTKORH.js.map} +0 -0
- /package/dist/{chunk-TGG3ODCS.js.map → chunk-MCPKUVMQ.js.map} +0 -0
- /package/dist/{chunk-KYDLVMKA.js.map → chunk-MFLU3466.js.map} +0 -0
- /package/dist/{chunk-ZD67RM6G.js.map → chunk-MIUJ3EH5.js.map} +0 -0
- /package/dist/{chunk-KLOB3IXX.js.map → chunk-MIUMNTIJ.js.map} +0 -0
- /package/dist/{chunk-ZP7BJXQ5.js.map → chunk-ML46TXRM.js.map} +0 -0
- /package/dist/{chunk-M5FX5KH5.js.map → chunk-MO3XJQN2.js.map} +0 -0
- /package/dist/{chunk-UQR5RZ5I.js.map → chunk-MQRHTOQ2.js.map} +0 -0
- /package/dist/{chunk-5ERDSF2C.js.map → chunk-MVYQDBE6.js.map} +0 -0
- /package/dist/{chunk-XX2J7H2J.js.map → chunk-NPBEUU22.js.map} +0 -0
- /package/dist/{chunk-PGDGX6PO.js.map → chunk-NSXKGS2K.js.map} +0 -0
- /package/dist/{chunk-TLR2SX7T.js.map → chunk-NUEFORM6.js.map} +0 -0
- /package/dist/{chunk-LSQP22UI.js.map → chunk-NZOFNQNC.js.map} +0 -0
- /package/dist/{chunk-RCN3SVJC.js.map → chunk-OATXCLTY.js.map} +0 -0
- /package/dist/{chunk-53ZK2JFE.js.map → chunk-OG3ELROW.js.map} +0 -0
- /package/dist/{chunk-YQ6AYWGT.js.map → chunk-OI4WS7FW.js.map} +0 -0
- /package/dist/{chunk-XVXYLCSC.js.map → chunk-OITGZUDC.js.map} +0 -0
- /package/dist/{chunk-T2NC7ALH.js.map → chunk-OKD2LBMK.js.map} +0 -0
- /package/dist/{chunk-PX64T6XV.js.map → chunk-OSA4CGST.js.map} +0 -0
- /package/dist/{chunk-WG7OVUCV.js.map → chunk-OXYAKUFU.js.map} +0 -0
- /package/dist/{chunk-YWKJSF3R.js.map → chunk-OYMSMU5O.js.map} +0 -0
- /package/dist/{chunk-OHJXHKQT.js.map → chunk-P4NZ72KY.js.map} +0 -0
- /package/dist/{chunk-4D4XXJJJ.js.map → chunk-PBYL2VIM.js.map} +0 -0
- /package/dist/{chunk-7M57K6K5.js.map → chunk-PDW3OOSZ.js.map} +0 -0
- /package/dist/{chunk-QZSIADFZ.js.map → chunk-PGRKTQIW.js.map} +0 -0
- /package/dist/{chunk-4PG2BEQA.js.map → chunk-PPQJIVGM.js.map} +0 -0
- /package/dist/{chunk-UFRXYZCJ.js.map → chunk-PYMQM65Y.js.map} +0 -0
- /package/dist/{chunk-G65TM5FL.js.map → chunk-Q273Q33U.js.map} +0 -0
- /package/dist/{chunk-62AHHCFV.js.map → chunk-Q4CLS2HL.js.map} +0 -0
- /package/dist/{chunk-PGMXITPB.js.map → chunk-QA5UNVHD.js.map} +0 -0
- /package/dist/{chunk-SP7XRRGB.js.map → chunk-QFOBUA2J.js.map} +0 -0
- /package/dist/{chunk-LRE7WH6D.js.map → chunk-QLIM4D56.js.map} +0 -0
- /package/dist/{chunk-HWOJ7JSO.js.map → chunk-QMQF5U2D.js.map} +0 -0
- /package/dist/{chunk-J4OOKDRV.js.map → chunk-QNOWKKZ4.js.map} +0 -0
- /package/dist/{chunk-ATQ3O5E6.js.map → chunk-QPOUPVPD.js.map} +0 -0
- /package/dist/{chunk-ZVT2KQTH.js.map → chunk-QTJAQ6DS.js.map} +0 -0
- /package/dist/{chunk-WDDAHRBC.js.map → chunk-QUOFP3G7.js.map} +0 -0
- /package/dist/{chunk-R2T4IUNB.js.map → chunk-QVOTPOXK.js.map} +0 -0
- /package/dist/{chunk-SMSEI6VH.js.map → chunk-QYZ5RVGM.js.map} +0 -0
- /package/dist/{chunk-CGWLKFQF.js.map → chunk-R7CVDKRN.js.map} +0 -0
- /package/dist/{chunk-MPW67ODY.js.map → chunk-RB7MXNZD.js.map} +0 -0
- /package/dist/{chunk-EVRLHFIG.js.map → chunk-RDZQFZOQ.js.map} +0 -0
- /package/dist/{chunk-JY4ACIKP.js.map → chunk-RIHKEGWS.js.map} +0 -0
- /package/dist/{chunk-UWPSCSIZ.js.map → chunk-ROSB7GF6.js.map} +0 -0
- /package/dist/{chunk-2O5EDTVB.js.map → chunk-RP3YMYCX.js.map} +0 -0
- /package/dist/{chunk-U7KNZEMU.js.map → chunk-RPHXJHNX.js.map} +0 -0
- /package/dist/{chunk-IQWAFZGW.js.map → chunk-RVC3M66H.js.map} +0 -0
- /package/dist/{chunk-VAJQQKSG.js.map → chunk-S3OTJAAC.js.map} +0 -0
- /package/dist/{chunk-DWH35C5X.js.map → chunk-SBWPMVRN.js.map} +0 -0
- /package/dist/{chunk-PYS63BC6.js.map → chunk-SERECSAR.js.map} +0 -0
- /package/dist/{chunk-L22AVXXW.js.map → chunk-SHSEF3GJ.js.map} +0 -0
- /package/dist/{chunk-UDDZDC2Q.js.map → chunk-SMS2M3RG.js.map} +0 -0
- /package/dist/{chunk-SNACGK3Z.js.map → chunk-SRDHDIRQ.js.map} +0 -0
- /package/dist/{chunk-VM6BM3NV.js.map → chunk-SXRYA7NN.js.map} +0 -0
- /package/dist/{chunk-WCA777NS.js.map → chunk-SYA3WYG4.js.map} +0 -0
- /package/dist/{chunk-HUTQJY3F.js.map → chunk-SYYFA7W7.js.map} +0 -0
- /package/dist/{chunk-5ABIZ7YT.js.map → chunk-T2QDSTBH.js.map} +0 -0
- /package/dist/{chunk-ZUQKQP3T.js.map → chunk-TFSCGFYV.js.map} +0 -0
- /package/dist/{chunk-CGEAOUXW.js.map → chunk-TGCKZOSX.js.map} +0 -0
- /package/dist/{chunk-4WKITG7P.js.map → chunk-THILLYQM.js.map} +0 -0
- /package/dist/{chunk-34XY4PWB.js.map → chunk-TI6LGUEZ.js.map} +0 -0
- /package/dist/{chunk-MRNOTVGF.js.map → chunk-TSY6YZL2.js.map} +0 -0
- /package/dist/{chunk-3Y7IJPHB.js.map → chunk-TW2RHTLH.js.map} +0 -0
- /package/dist/{chunk-FWRKCWQO.js.map → chunk-TWA5G277.js.map} +0 -0
- /package/dist/{chunk-XFP3AIZO.js.map → chunk-TZZ2S4XI.js.map} +0 -0
- /package/dist/{chunk-VDHWFRTL.js.map → chunk-U5D3K53R.js.map} +0 -0
- /package/dist/{chunk-5DEP55DK.js.map → chunk-UECD27LX.js.map} +0 -0
- /package/dist/{chunk-ABO54U65.js.map → chunk-UFJDETKG.js.map} +0 -0
- /package/dist/{chunk-WMW4AXVG.js.map → chunk-UHCFYX4I.js.map} +0 -0
- /package/dist/{chunk-REUQ464X.js.map → chunk-UHTURYJO.js.map} +0 -0
- /package/dist/{chunk-FAVXYNTK.js.map → chunk-UJH63JT3.js.map} +0 -0
- /package/dist/{chunk-OYJ7KP6H.js.map → chunk-UOLDS6S5.js.map} +0 -0
- /package/dist/{chunk-EQSANTUC.js.map → chunk-UUE3OGXI.js.map} +0 -0
- /package/dist/{chunk-OJE3WTHK.js.map → chunk-UUNJ2E57.js.map} +0 -0
- /package/dist/{chunk-MEUAI3B7.js.map → chunk-UYQVWRAH.js.map} +0 -0
- /package/dist/{chunk-X62OJCQW.js.map → chunk-UYWVK7JQ.js.map} +0 -0
- /package/dist/{chunk-M2KDPKQC.js.map → chunk-UYWWUEL4.js.map} +0 -0
- /package/dist/{chunk-NABGUV6O.js.map → chunk-V4CQKX5H.js.map} +0 -0
- /package/dist/{chunk-ODWNT3XC.js.map → chunk-V4QM7GDQ.js.map} +0 -0
- /package/dist/{chunk-FRDJUZ6E.js.map → chunk-V5Y74WII.js.map} +0 -0
- /package/dist/{chunk-RYYBQ4PW.js.map → chunk-VGGZLUQK.js.map} +0 -0
- /package/dist/{chunk-L5AQCKRR.js.map → chunk-VGX636MB.js.map} +0 -0
- /package/dist/{chunk-P5DGNIGZ.js.map → chunk-VGZLFQO2.js.map} +0 -0
- /package/dist/{chunk-HWDHA4KS.js.map → chunk-VJWZATNF.js.map} +0 -0
- /package/dist/{chunk-WYICOILE.js.map → chunk-VMWCIC2N.js.map} +0 -0
- /package/dist/{chunk-3QUDVXDR.js.map → chunk-VPWKTIU5.js.map} +0 -0
- /package/dist/{chunk-UFIETNB2.js.map → chunk-VXOLG6YB.js.map} +0 -0
- /package/dist/{chunk-NH6OLIQD.js.map → chunk-W2NAU5VB.js.map} +0 -0
- /package/dist/{chunk-OJNZTTQE.js.map → chunk-WGORKMR3.js.map} +0 -0
- /package/dist/{chunk-DK5L6E4G.js.map → chunk-WMIDELSJ.js.map} +0 -0
- /package/dist/{chunk-STA75WRF.js.map → chunk-WSOSGL2G.js.map} +0 -0
- /package/dist/{chunk-2R7AOT3Y.js.map → chunk-WXUUOM4X.js.map} +0 -0
- /package/dist/{chunk-UMYCZQSL.js.map → chunk-X2OWM2ME.js.map} +0 -0
- /package/dist/{chunk-B6YDINPE.js.map → chunk-X6UMGG4T.js.map} +0 -0
- /package/dist/{chunk-CPN7JXYV.js.map → chunk-XDXKB25W.js.map} +0 -0
- /package/dist/{chunk-W2PBDF4F.js.map → chunk-XE4PHI74.js.map} +0 -0
- /package/dist/{chunk-R6WQLIFX.js.map → chunk-XHF2XNU5.js.map} +0 -0
- /package/dist/{chunk-IHNCZONS.js.map → chunk-XLJ4SQFS.js.map} +0 -0
- /package/dist/{chunk-UKDLZ76A.js.map → chunk-XOD4FX6M.js.map} +0 -0
- /package/dist/{chunk-OCWCZRVU.js.map → chunk-XODQ2GPF.js.map} +0 -0
- /package/dist/{chunk-MVLHO6AU.js.map → chunk-XT54RTAM.js.map} +0 -0
- /package/dist/{chunk-R6OBJ7LF.js.map → chunk-YAVW5OJ5.js.map} +0 -0
- /package/dist/{chunk-4SW3EUNM.js.map → chunk-YDQHFJM2.js.map} +0 -0
- /package/dist/{chunk-HI6TPRY5.js.map → chunk-YH6O6OQ6.js.map} +0 -0
- /package/dist/{chunk-25SCFA2X.js.map → chunk-YIKPC2QP.js.map} +0 -0
- /package/dist/{chunk-4KF5I3H5.js.map → chunk-ZD7PKYC4.js.map} +0 -0
- /package/dist/{chunk-ANCI6T7S.js.map → chunk-ZEQYHEWP.js.map} +0 -0
- /package/dist/{chunk-GKA5LFYR.js.map → chunk-ZP3QCPYG.js.map} +0 -0
- /package/dist/{chunk-6Y3EFN4Q.js.map → chunk-ZRVUCTSI.js.map} +0 -0
- /package/dist/{chunk-UJ4DLPYG.js.map → chunk-ZSI3ITRK.js.map} +0 -0
- /package/dist/{chunk-S44ADSZG.js.map → chunk-ZZMEQCIZ.js.map} +0 -0
- /package/dist/{computer-viewer-KLRAA56S.js.map → computer-viewer-ZBY3BPYW.js.map} +0 -0
- /package/dist/{connection-step-up-PWIIW3KK.js.map → connection-step-up-JQ4OFSQN.js.map} +0 -0
- /package/dist/{embedded-new-voice-P2RCFI3X.js.map → embedded-new-voice-ZB5XLKLU.js.map} +0 -0
- /package/dist/{embedded-voice-HY5F4D2I.js.map → embedded-voice-MZJISDCS.js.map} +0 -0
- /package/dist/{fleet-decision-row-UEXT7NAN.js.map → fleet-decision-row-LG3SYVR3.js.map} +0 -0
- /package/dist/{model-policy-picker-menu-AAGNLTEG.js.map → model-policy-picker-menu-5Y72PLNF.js.map} +0 -0
- /package/dist/{payment-page-card-MHTYJHCW.js.map → payment-page-card-YPSXRHBA.js.map} +0 -0
- /package/dist/{platform-activity-row-7VAPGRZQ.js.map → platform-activity-row-ZU4MEBNK.js.map} +0 -0
- /package/dist/{queue-surface-implementation-AE5P3PSA.js.map → queue-surface-implementation-6Q25RPH6.js.map} +0 -0
- /package/dist/{recorder-host-I53BQIRX.js.map → recorder-host-JD4GWJ2Z.js.map} +0 -0
- /package/dist/{sandbox-files-LGE7EDX2.js.map → sandbox-files-HCLEEJMU.js.map} +0 -0
- /package/dist/{session-connect-cards-QNL7WRKJ.js.map → session-connect-cards-DRKEN3Z4.js.map} +0 -0
- /package/dist/{session-realtime-ZMXMK5EV.js.map → session-realtime-IZOTTRH6.js.map} +0 -0
- /package/dist/{timeline-annotation-markers-5RICTVVW.js.map → timeline-annotation-markers-WWXNJOXI.js.map} +0 -0
- /package/dist/{timeline-annotation-selection-ITAHBOFW.js.map → timeline-annotation-selection-ZKRIQFIQ.js.map} +0 -0
- /package/dist/{timeline-annotations-dialog-7PGBTPVD.js.map → timeline-annotations-dialog-4IMKTOXJ.js.map} +0 -0
|
@@ -0,0 +1,4480 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useSessionStartupState
|
|
4
|
+
} from "./chunk-D6LH6JPE.js";
|
|
5
|
+
import {
|
|
6
|
+
deniesRetainedView,
|
|
7
|
+
useRetainedSessionView
|
|
8
|
+
} from "./chunk-6CKSMBLT.js";
|
|
9
|
+
import {
|
|
10
|
+
forgetSessionHumanInputDrafts,
|
|
11
|
+
pruneHumanInputDrafts
|
|
12
|
+
} from "./chunk-UYWVK7JQ.js";
|
|
13
|
+
import {
|
|
14
|
+
uploadScopeForSession,
|
|
15
|
+
useFileAttachments
|
|
16
|
+
} from "./chunk-IE5MZEOM.js";
|
|
17
|
+
import {
|
|
18
|
+
projectPendingApprovals
|
|
19
|
+
} from "./chunk-BC7PTVXW.js";
|
|
20
|
+
import {
|
|
21
|
+
buildTimeline,
|
|
22
|
+
groupTimeline,
|
|
23
|
+
isToolOutputPreviewEvent,
|
|
24
|
+
sessionStatusFromEvents,
|
|
25
|
+
useToolOutputReads
|
|
26
|
+
} from "./chunk-JD6LHU26.js";
|
|
27
|
+
import {
|
|
28
|
+
useSharedQuery
|
|
29
|
+
} from "./chunk-DSQNSLQW.js";
|
|
30
|
+
import {
|
|
31
|
+
isActionableHumanInputRequest
|
|
32
|
+
} from "./chunk-57MB2QGY.js";
|
|
33
|
+
import {
|
|
34
|
+
readAcknowledgementFrontier,
|
|
35
|
+
sessionAttentionReadThroughSequence
|
|
36
|
+
} from "./chunk-IOBL5KYR.js";
|
|
37
|
+
import {
|
|
38
|
+
useClientConfigFlags
|
|
39
|
+
} from "./chunk-XESA3B7W.js";
|
|
40
|
+
import {
|
|
41
|
+
promptSendDestination,
|
|
42
|
+
sessionArchived,
|
|
43
|
+
sessionTurnKeepsRunControl
|
|
44
|
+
} from "./chunk-DG5DQFS4.js";
|
|
45
|
+
import {
|
|
46
|
+
FILE_ONLY_MESSAGE_TEXT,
|
|
47
|
+
notifyObserver,
|
|
48
|
+
useComposer
|
|
49
|
+
} from "./chunk-XODQ2GPF.js";
|
|
50
|
+
import {
|
|
51
|
+
joinClientConfigRead
|
|
52
|
+
} from "./chunk-IGVL3ELX.js";
|
|
53
|
+
import {
|
|
54
|
+
admissionRecheckControl
|
|
55
|
+
} from "./chunk-MRNAHGBL.js";
|
|
56
|
+
import {
|
|
57
|
+
DEFAULT_TRANSIENT_READ_RETRY,
|
|
58
|
+
projectionReadThrough,
|
|
59
|
+
transientReadRetryStep,
|
|
60
|
+
useDebouncedCallback,
|
|
61
|
+
useMutationRunner,
|
|
62
|
+
usePageLiveActivity,
|
|
63
|
+
usePolledValue,
|
|
64
|
+
useSessionEventTrigger
|
|
65
|
+
} from "./chunk-SW4S6I5E.js";
|
|
66
|
+
import {
|
|
67
|
+
normalizeError
|
|
68
|
+
} from "./chunk-CM7LVUKC.js";
|
|
69
|
+
import {
|
|
70
|
+
coerceReasoningEffortForModel,
|
|
71
|
+
defaultEffortForModel,
|
|
72
|
+
projectPickerRows,
|
|
73
|
+
runnableLatencyModesForModel,
|
|
74
|
+
sortPickerRows
|
|
75
|
+
} from "./chunk-4VEIBNC2.js";
|
|
76
|
+
import {
|
|
77
|
+
useEmbeddedGoal,
|
|
78
|
+
useEmbeddedHumanInputSession,
|
|
79
|
+
useEmbeddedSession,
|
|
80
|
+
useEmbeddedSessionRead,
|
|
81
|
+
useOpenGeni,
|
|
82
|
+
useOpenGeniClient
|
|
83
|
+
} from "./chunk-BVUAHAQX.js";
|
|
84
|
+
import {
|
|
85
|
+
useOpenGeniText
|
|
86
|
+
} from "./chunk-KVPQUADA.js";
|
|
87
|
+
|
|
88
|
+
// src/hooks/use-session.ts
|
|
89
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
90
|
+
|
|
91
|
+
// src/lib/session-detail-read.ts
|
|
92
|
+
var lastOrdinal = 0;
|
|
93
|
+
var reads = /* @__PURE__ */ new WeakMap();
|
|
94
|
+
function readKey(workspaceId, sessionId) {
|
|
95
|
+
return `${workspaceId}\0${sessionId}`;
|
|
96
|
+
}
|
|
97
|
+
function sessionDetailReadMark() {
|
|
98
|
+
return lastOrdinal;
|
|
99
|
+
}
|
|
100
|
+
function readFreshSessionDetail(client, workspaceId, sessionId, options = {}) {
|
|
101
|
+
const promise = client.getSession(workspaceId, sessionId, { ...options, fresh: true });
|
|
102
|
+
const read = { promise, ordinal: ++lastOrdinal };
|
|
103
|
+
let scoped = reads.get(client);
|
|
104
|
+
if (!scoped) {
|
|
105
|
+
scoped = /* @__PURE__ */ new Map();
|
|
106
|
+
reads.set(client, scoped);
|
|
107
|
+
}
|
|
108
|
+
const key = readKey(workspaceId, sessionId);
|
|
109
|
+
scoped.set(key, read);
|
|
110
|
+
promise.catch(() => {
|
|
111
|
+
if (scoped.get(key) === read) scoped.delete(key);
|
|
112
|
+
});
|
|
113
|
+
return promise;
|
|
114
|
+
}
|
|
115
|
+
function joinSessionDetailRead(client, workspaceId, sessionId, mark) {
|
|
116
|
+
const read = reads.get(client)?.get(readKey(workspaceId, sessionId));
|
|
117
|
+
return read && read.ordinal > mark ? read.promise : null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/hooks/use-session.ts
|
|
121
|
+
function isTitleEvent(event) {
|
|
122
|
+
return event.type === "session.title_set";
|
|
123
|
+
}
|
|
124
|
+
function isSessionDetailEvent(event) {
|
|
125
|
+
return isTitleEvent(event) || // Description or avatar edits (by a person or the agent) refresh the header.
|
|
126
|
+
event.type === "session.profile_set" || // The agent said it waits on a person, or stopped waiting.
|
|
127
|
+
event.type === "session.waiting_on.changed" || // The chat's model, effort or speed changed (for example by the agent).
|
|
128
|
+
event.type === "session.model_settings.updated" || event.type.startsWith("session.command.") || event.type.startsWith("session.wait.") || event.type === "session.status.changed" || event.type === "system.update.pending";
|
|
129
|
+
}
|
|
130
|
+
function useSession(sessionId, options = {}) {
|
|
131
|
+
const { client, workspaceId, workspaceControlEvent, registerSessionReconciler } = useEmbeddedSessionRead(options);
|
|
132
|
+
const enabled = (options.enabled ?? true) && Boolean(sessionId);
|
|
133
|
+
const [override, setOverride] = useState(null);
|
|
134
|
+
const nextReadRevision = useRef(0);
|
|
135
|
+
const nextReadGeneration = useRef(0);
|
|
136
|
+
const beginRead = options.beginRead;
|
|
137
|
+
const { run, mutating, mutationError, clearMutationError } = useMutationRunner();
|
|
138
|
+
const load = useCallback(
|
|
139
|
+
async (signal) => {
|
|
140
|
+
if (!sessionId) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
let readGeneration2 = 0;
|
|
144
|
+
const fetched = await readFreshSessionDetail(client, workspaceId, sessionId, {
|
|
145
|
+
signal,
|
|
146
|
+
onRequestStart: () => {
|
|
147
|
+
readGeneration2 = beginRead?.() ?? ++nextReadGeneration.current;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
setOverride(null);
|
|
151
|
+
return {
|
|
152
|
+
session: fetched,
|
|
153
|
+
revision: ++nextReadRevision.current,
|
|
154
|
+
readGeneration: readGeneration2
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
[beginRead, client, workspaceId, sessionId]
|
|
158
|
+
);
|
|
159
|
+
const { data, loading, error, refresh } = usePolledValue(load, {
|
|
160
|
+
pollIntervalMs: options.pollIntervalMs,
|
|
161
|
+
enabled
|
|
162
|
+
});
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (enabled && workspaceControlEvent) void refresh();
|
|
165
|
+
}, [enabled, refresh, workspaceControlEvent]);
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (!sessionId || !enabled) return;
|
|
168
|
+
return registerSessionReconciler(sessionId, "session", refresh);
|
|
169
|
+
}, [enabled, refresh, registerSessionReconciler, sessionId]);
|
|
170
|
+
const retained = useRetainedSessionView(
|
|
171
|
+
client,
|
|
172
|
+
workspaceId,
|
|
173
|
+
sessionId,
|
|
174
|
+
"detail",
|
|
175
|
+
data?.session ?? null,
|
|
176
|
+
{ enabled, discard: deniesRetainedView(error) }
|
|
177
|
+
);
|
|
178
|
+
const base = data?.session ?? null;
|
|
179
|
+
const readRevision = data?.revision ?? 0;
|
|
180
|
+
const readGeneration = data?.readGeneration ?? 0;
|
|
181
|
+
const session = useMemo(
|
|
182
|
+
() => base && override && override.id === base.id ? { ...base, title: override.title, titleSource: override.titleSource } : base ?? retained,
|
|
183
|
+
[base, override, retained]
|
|
184
|
+
);
|
|
185
|
+
const sharedEvents = options.events;
|
|
186
|
+
const refreshDetail = useCallback(() => void refresh(), [refresh]);
|
|
187
|
+
const onTitleEvent = useCallback(
|
|
188
|
+
(event) => {
|
|
189
|
+
if (sharedEvents?.some(
|
|
190
|
+
(item) => item.sessionId === sessionId && !isTitleEvent(item) && isSessionDetailEvent(item) && item.sequence > (base?.lastSequence ?? -1)
|
|
191
|
+
)) {
|
|
192
|
+
void refresh();
|
|
193
|
+
} else if (!isTitleEvent(event)) {
|
|
194
|
+
if (!base || event.sequence > base.lastSequence) void refresh();
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (!base || event.sequence <= base.lastSequence) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const payload = event.payload ?? {};
|
|
201
|
+
const title = payload.title;
|
|
202
|
+
if (typeof title !== "string") {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const source = payload.source === "user" || payload.source === "agent" ? payload.source : null;
|
|
206
|
+
setOverride((current) => {
|
|
207
|
+
const next = current ?? base;
|
|
208
|
+
return { ...next, title, titleSource: source };
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
[base, refresh, sharedEvents, sessionId]
|
|
212
|
+
);
|
|
213
|
+
useSessionEventTrigger(client, workspaceId, sessionId, isSessionDetailEvent, onTitleEvent, {
|
|
214
|
+
enabled,
|
|
215
|
+
...options.events !== void 0 ? { events: options.events } : {},
|
|
216
|
+
// The detail row is authoritative through its lastSequence: only a later
|
|
217
|
+
// event can make it stale, and one that arrives first waits for the read.
|
|
218
|
+
readThrough: base ? base.lastSequence : loading ? "reading" : null,
|
|
219
|
+
refresh: refreshDetail
|
|
220
|
+
});
|
|
221
|
+
const updateTitle = useCallback(
|
|
222
|
+
async (title) => {
|
|
223
|
+
if (!sessionId) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const result = await run(() => client.updateSession(workspaceId, sessionId, { title }));
|
|
227
|
+
if (result) {
|
|
228
|
+
setOverride(result);
|
|
229
|
+
}
|
|
230
|
+
return result;
|
|
231
|
+
},
|
|
232
|
+
[client, workspaceId, sessionId, run]
|
|
233
|
+
);
|
|
234
|
+
return {
|
|
235
|
+
session,
|
|
236
|
+
loading: loading && retained === null,
|
|
237
|
+
error,
|
|
238
|
+
readRevision,
|
|
239
|
+
readGeneration,
|
|
240
|
+
refresh,
|
|
241
|
+
updateTitle,
|
|
242
|
+
updating: mutating,
|
|
243
|
+
mutationError,
|
|
244
|
+
clearMutationError
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// src/older-history.ts
|
|
249
|
+
var activeReceiptCapture;
|
|
250
|
+
var preserveTailForAutomaticLoad = false;
|
|
251
|
+
function invokeOlderHistoryLoaderWithReceiptCapture(load, capture, preserveTail = false) {
|
|
252
|
+
const previousCapture = activeReceiptCapture;
|
|
253
|
+
const previousPreserveTail = preserveTailForAutomaticLoad;
|
|
254
|
+
activeReceiptCapture = capture;
|
|
255
|
+
preserveTailForAutomaticLoad = preserveTail;
|
|
256
|
+
try {
|
|
257
|
+
return load();
|
|
258
|
+
} finally {
|
|
259
|
+
activeReceiptCapture = previousCapture;
|
|
260
|
+
preserveTailForAutomaticLoad = previousPreserveTail;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
function createOlderHistoryLoadReceipt(load) {
|
|
264
|
+
let resolveResult;
|
|
265
|
+
let rejectResult;
|
|
266
|
+
const result = new Promise((resolve, reject) => {
|
|
267
|
+
resolveResult = resolve;
|
|
268
|
+
rejectResult = reject;
|
|
269
|
+
});
|
|
270
|
+
result.committed = false;
|
|
271
|
+
result.tailPreserved = false;
|
|
272
|
+
activeReceiptCapture?.(result);
|
|
273
|
+
try {
|
|
274
|
+
const loaded = load(
|
|
275
|
+
() => {
|
|
276
|
+
result.committed = true;
|
|
277
|
+
},
|
|
278
|
+
preserveTailForAutomaticLoad,
|
|
279
|
+
() => {
|
|
280
|
+
result.tailPreserved = true;
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
Promise.resolve(loaded).then(resolveResult, rejectResult);
|
|
284
|
+
} catch (error) {
|
|
285
|
+
rejectResult(error);
|
|
286
|
+
}
|
|
287
|
+
return result;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// src/hooks/use-session-events.ts
|
|
291
|
+
import {
|
|
292
|
+
isPresentedSessionToolCall,
|
|
293
|
+
isRetryableStreamError,
|
|
294
|
+
isSessionModelResponsePhase,
|
|
295
|
+
isTransientRequestError,
|
|
296
|
+
SESSION_EVENT_COMPAT_EXCLUDED_STEP_TYPES,
|
|
297
|
+
SESSION_EVENT_CONTENT_STEP_TYPES,
|
|
298
|
+
SESSION_EVENT_CONVERSATION_FILTER_VERSION,
|
|
299
|
+
SESSION_EVENT_STEP_TYPES,
|
|
300
|
+
sessionEventStreamCoveredThrough
|
|
301
|
+
} from "@opengeni/sdk";
|
|
302
|
+
import { startTransition, useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
303
|
+
|
|
304
|
+
// src/hooks/page-wake.ts
|
|
305
|
+
var PAGE_WAKE_CHECK_INTERVAL_MS = 2e3;
|
|
306
|
+
var PAGE_WAKE_GAP_MS = 15e3;
|
|
307
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
308
|
+
var stopDetector = null;
|
|
309
|
+
function subscribePageWake(listener) {
|
|
310
|
+
listeners.add(listener);
|
|
311
|
+
stopDetector ??= startDetector();
|
|
312
|
+
return () => {
|
|
313
|
+
listeners.delete(listener);
|
|
314
|
+
if (listeners.size === 0 && stopDetector) {
|
|
315
|
+
stopDetector();
|
|
316
|
+
stopDetector = null;
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function emitPageWake() {
|
|
321
|
+
for (const listener of [...listeners]) {
|
|
322
|
+
try {
|
|
323
|
+
listener();
|
|
324
|
+
} catch {
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
function startDetector() {
|
|
329
|
+
if (typeof window === "undefined" || typeof document === "undefined") return () => {
|
|
330
|
+
};
|
|
331
|
+
let lastTick = Date.now();
|
|
332
|
+
const check = () => {
|
|
333
|
+
const now = Date.now();
|
|
334
|
+
const elapsed = now - lastTick;
|
|
335
|
+
lastTick = now;
|
|
336
|
+
if (elapsed > PAGE_WAKE_GAP_MS) emitPageWake();
|
|
337
|
+
};
|
|
338
|
+
const onVisibility = () => {
|
|
339
|
+
if (document.visibilityState !== "hidden") check();
|
|
340
|
+
};
|
|
341
|
+
const onPageShow = (event) => {
|
|
342
|
+
lastTick = Date.now();
|
|
343
|
+
if (event?.persisted === true) emitPageWake();
|
|
344
|
+
};
|
|
345
|
+
const onResume = () => {
|
|
346
|
+
lastTick = Date.now();
|
|
347
|
+
emitPageWake();
|
|
348
|
+
};
|
|
349
|
+
const timer = setInterval(check, PAGE_WAKE_CHECK_INTERVAL_MS);
|
|
350
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
351
|
+
document.addEventListener("resume", onResume);
|
|
352
|
+
window.addEventListener("pageshow", onPageShow);
|
|
353
|
+
window.addEventListener("online", onResume);
|
|
354
|
+
return () => {
|
|
355
|
+
clearInterval(timer);
|
|
356
|
+
document.removeEventListener("visibilitychange", onVisibility);
|
|
357
|
+
document.removeEventListener("resume", onResume);
|
|
358
|
+
window.removeEventListener("pageshow", onPageShow);
|
|
359
|
+
window.removeEventListener("online", onResume);
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/hooks/turnless-output-gaps.ts
|
|
364
|
+
import { useCallback as useCallback2, useSyncExternalStore } from "react";
|
|
365
|
+
var MAX_IDLE_ENTRIES = 256;
|
|
366
|
+
var entries = /* @__PURE__ */ new Map();
|
|
367
|
+
function gapKey(workspaceId, sessionId) {
|
|
368
|
+
return `${workspaceId}\0${sessionId}`;
|
|
369
|
+
}
|
|
370
|
+
function gapEntry(key) {
|
|
371
|
+
let entry = entries.get(key);
|
|
372
|
+
if (!entry) {
|
|
373
|
+
entry = { generation: 0, listeners: /* @__PURE__ */ new Set() };
|
|
374
|
+
entries.set(key, entry);
|
|
375
|
+
if (entries.size > MAX_IDLE_ENTRIES) {
|
|
376
|
+
for (const [candidate, held] of entries) {
|
|
377
|
+
if (entries.size <= MAX_IDLE_ENTRIES) break;
|
|
378
|
+
if (candidate !== key && held.listeners.size === 0) entries.delete(candidate);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return entry;
|
|
383
|
+
}
|
|
384
|
+
function markTurnlessOutputGap(workspaceId, sessionId) {
|
|
385
|
+
const entry = gapEntry(gapKey(workspaceId, sessionId));
|
|
386
|
+
entry.generation += 1;
|
|
387
|
+
for (const listener of [...entry.listeners]) listener();
|
|
388
|
+
}
|
|
389
|
+
function useTurnlessOutputGap(workspaceId, sessionId) {
|
|
390
|
+
const key = sessionId ? gapKey(workspaceId, sessionId) : null;
|
|
391
|
+
const subscribe = useCallback2(
|
|
392
|
+
(listener) => {
|
|
393
|
+
if (!key) return () => {
|
|
394
|
+
};
|
|
395
|
+
const entry = gapEntry(key);
|
|
396
|
+
entry.listeners.add(listener);
|
|
397
|
+
return () => {
|
|
398
|
+
entry.listeners.delete(listener);
|
|
399
|
+
};
|
|
400
|
+
},
|
|
401
|
+
[key]
|
|
402
|
+
);
|
|
403
|
+
const read = useCallback2(() => key ? entries.get(key)?.generation ?? 0 : 0, [key]);
|
|
404
|
+
return useSyncExternalStore(subscribe, read, read);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// src/hooks/use-session-events.ts
|
|
408
|
+
import { errorMessage } from "@opengeni/contracts/values";
|
|
409
|
+
var SESSION_FIRST_WINDOW_PAGE_SIZE = 255;
|
|
410
|
+
var SESSION_HISTORY_PAGE_SIZE = 1e3;
|
|
411
|
+
var INITIAL_FETCH_CAP = 1;
|
|
412
|
+
var OLDER_GROUP_TARGET = 32;
|
|
413
|
+
var OLDER_FETCH_CAP = 2;
|
|
414
|
+
var NEWER_GROUP_TARGET = 32;
|
|
415
|
+
var NEWER_FETCH_CAP = 2;
|
|
416
|
+
var OLDEST_GROUP_TARGET = 32;
|
|
417
|
+
var OLDEST_FETCH_CAP = 2;
|
|
418
|
+
var BOUNDARY_PAGE_CAP = 1;
|
|
419
|
+
var FILTERED_PAGE_CAP = 32;
|
|
420
|
+
var DIRECT_REPLAY_MAX_SEQUENCES = 16;
|
|
421
|
+
var CATCHUP_MAX_PAGES = 2;
|
|
422
|
+
var STRICT_REJOIN_ATTEMPTS = 5;
|
|
423
|
+
var REJOIN_STALL_TIMEOUT_MS = 3e4;
|
|
424
|
+
var FOREGROUND_REJOIN_RETRY_MS = 500;
|
|
425
|
+
var FOREGROUND_REJOIN_RETRY_MAX_MS = 8e3;
|
|
426
|
+
var EMPTY_EVENTS = [];
|
|
427
|
+
var encoder = new TextEncoder();
|
|
428
|
+
var SESSION_EVENT_BROWSER_MAX_BYTES = 16 * 1024 * 1024;
|
|
429
|
+
var SESSION_EVENT_BROWSER_MAX_COUNT = 2e4;
|
|
430
|
+
var SESSION_EVENT_BROWSER_PENDING_MAX_BYTES = 1024 * 1024;
|
|
431
|
+
var SESSION_EVENT_BROWSER_PENDING_MAX_COUNT = 256;
|
|
432
|
+
var EMPTY_EVENT_WINDOW = {
|
|
433
|
+
events: EMPTY_EVENTS,
|
|
434
|
+
bytes: 2,
|
|
435
|
+
truncated: false
|
|
436
|
+
};
|
|
437
|
+
function useSessionEvents(sessionId, options = {}) {
|
|
438
|
+
const t = useOpenGeniText();
|
|
439
|
+
const { client, workspaceId, reconcileSession } = useEmbeddedSession(options);
|
|
440
|
+
const enabled = options.enabled ?? true;
|
|
441
|
+
const pageLive = usePageLiveActivity();
|
|
442
|
+
const streamEnabled = enabled && pageLive;
|
|
443
|
+
const after = options.after ?? 0;
|
|
444
|
+
const replay = options.replay ?? "windowed";
|
|
445
|
+
const fullReplay = replay === "full" || after !== 0;
|
|
446
|
+
const streamKey = `${workspaceId}\0${sessionId ?? ""}\0${after}\0${fullReplay ? "full" : "windowed"}`;
|
|
447
|
+
const navigationIdentityRef = useRef2({ client, streamKey, enabled });
|
|
448
|
+
if (navigationIdentityRef.current.client !== client || navigationIdentityRef.current.streamKey !== streamKey || navigationIdentityRef.current.enabled !== enabled) {
|
|
449
|
+
navigationIdentityRef.current = { client, streamKey, enabled };
|
|
450
|
+
}
|
|
451
|
+
const navigationIdentity = navigationIdentityRef.current;
|
|
452
|
+
const ownsNavigation = useCallback3(
|
|
453
|
+
() => navigationIdentityRef.current === navigationIdentity,
|
|
454
|
+
[navigationIdentity]
|
|
455
|
+
);
|
|
456
|
+
const [eventWindow, setEventWindow] = useState2(EMPTY_EVENT_WINDOW);
|
|
457
|
+
const [questionEvidence, setQuestionEvidence] = useState2(null);
|
|
458
|
+
const [connectionState, setConnectionState] = useState2("idle");
|
|
459
|
+
const [error, setError] = useState2(null);
|
|
460
|
+
const [newerError, setNewerError] = useState2(null);
|
|
461
|
+
const [hasOlder, setHasOlder] = useState2(false);
|
|
462
|
+
const [hasNewer, setHasNewer] = useState2(false);
|
|
463
|
+
const [sessionStatusProjection, setSessionStatusProjection] = useState2(
|
|
464
|
+
null
|
|
465
|
+
);
|
|
466
|
+
const [initialLoading, setInitialLoading] = useState2(true);
|
|
467
|
+
const [initialHistoryReady, setInitialHistoryReady] = useState2(false);
|
|
468
|
+
const [loadingOlder, setLoadingOlder] = useState2(false);
|
|
469
|
+
const [loadingNewer, setLoadingNewer] = useState2(false);
|
|
470
|
+
const [loadingOldest, setLoadingOldest] = useState2(false);
|
|
471
|
+
const [loadingLatest, setLoadingLatest] = useState2(false);
|
|
472
|
+
const [loadingTarget, setLoadingTarget] = useState2(false);
|
|
473
|
+
const loadingTargetRef = useRef2(false);
|
|
474
|
+
const [streamEpoch, setStreamEpoch] = useState2(0);
|
|
475
|
+
const [viewMode, setViewMode] = useState2("live");
|
|
476
|
+
const lastSequenceRef = useRef2(after);
|
|
477
|
+
const streamResumeSequenceRef = useRef2(after);
|
|
478
|
+
const skippedStepsThroughRef = useRef2(null);
|
|
479
|
+
const oldestSequenceRef = useRef2(null);
|
|
480
|
+
const newestSequenceRef = useRef2(null);
|
|
481
|
+
const hasOlderRef = useRef2(false);
|
|
482
|
+
const hasNewerRef = useRef2(false);
|
|
483
|
+
const loadingOlderRef = useRef2(false);
|
|
484
|
+
const loadingNewerRef = useRef2(false);
|
|
485
|
+
const loadingOldestRef = useRef2(false);
|
|
486
|
+
const loadingLatestRef = useRef2(false);
|
|
487
|
+
const viewModeRef = useRef2("live");
|
|
488
|
+
const initialWindowLoadedRef = useRef2(false);
|
|
489
|
+
const openedStreamKeyRef = useRef2(null);
|
|
490
|
+
const reconcileAfterPageResumeRef = useRef2(false);
|
|
491
|
+
const streamAbortRef = useRef2(null);
|
|
492
|
+
const streamKeyRef = useRef2(null);
|
|
493
|
+
const generationRef = useRef2(0);
|
|
494
|
+
const navigationGenerationRef = useRef2(0);
|
|
495
|
+
const eventWindowRef = useRef2(EMPTY_EVENT_WINDOW);
|
|
496
|
+
const sessionStatusRef = useRef2({
|
|
497
|
+
sequence: after,
|
|
498
|
+
status: null
|
|
499
|
+
});
|
|
500
|
+
const [stateStreamKey, setStateStreamKey] = useState2(streamKey);
|
|
501
|
+
const historyFilter = fullReplay ? void 0 : CONVERSATION_FILTER;
|
|
502
|
+
const [stepStores, setStepStores] = useState2(EMPTY_STEP_STORES);
|
|
503
|
+
const stepStoresRef = useRef2(EMPTY_STEP_STORES);
|
|
504
|
+
const [turnlessSteps, setTurnlessSteps] = useState2(EMPTY_TURNLESS_STEPS);
|
|
505
|
+
const turnlessStepsRef = useRef2(EMPTY_TURNLESS_STEPS);
|
|
506
|
+
const renderedTurnlessRef = useRef2({ appended: 0, marked: false });
|
|
507
|
+
useEffect2(() => {
|
|
508
|
+
renderedTurnlessRef.current = { appended: turnlessSteps.appended, marked: false };
|
|
509
|
+
}, [turnlessSteps]);
|
|
510
|
+
const liveThroughRef = useRef2(0);
|
|
511
|
+
const stepGenerationRef = useRef2(0);
|
|
512
|
+
const stepRequestRef = useRef2(0);
|
|
513
|
+
const retainedTurnsRef = useRef2(/* @__PURE__ */ new Map());
|
|
514
|
+
const turnStepHandlesRef = useRef2(/* @__PURE__ */ new Map());
|
|
515
|
+
const presentedCallIdsRef = useRef2(/* @__PURE__ */ new Set());
|
|
516
|
+
const presentedScanRef = useRef2(null);
|
|
517
|
+
const startupRef = useRef2(emptyStartupTurns());
|
|
518
|
+
const [presentedOutputs, setPresentedOutputs] = useState2(EMPTY_PRESENTED_OUTPUTS);
|
|
519
|
+
const presentedRequestedRef = useRef2(/* @__PURE__ */ new Map());
|
|
520
|
+
const presentedFailuresRef = useRef2(/* @__PURE__ */ new Map());
|
|
521
|
+
const [presentedPass, setPresentedPass] = useState2(0);
|
|
522
|
+
const rejoinPendingRef = useRef2(false);
|
|
523
|
+
const streamTransientStreakRef = useRef2(null);
|
|
524
|
+
const commitStepStores = useCallback3((next) => {
|
|
525
|
+
stepStoresRef.current = next;
|
|
526
|
+
setStepStores(next);
|
|
527
|
+
}, []);
|
|
528
|
+
const pruneStepStores = useCallback3(
|
|
529
|
+
(window2, sealedBy, rereading = null) => {
|
|
530
|
+
const present = windowTurns(window2);
|
|
531
|
+
const settled = sealedBy ? settledTurns(sealedBy) : null;
|
|
532
|
+
const next = /* @__PURE__ */ new Map();
|
|
533
|
+
for (const [turnId, store] of stepStoresRef.current) {
|
|
534
|
+
if (present.has(turnId) && (!settled || settled.has(turnId) || turnId === rereading)) {
|
|
535
|
+
next.set(turnId, store);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (next.size !== stepStoresRef.current.size) commitStepStores(next);
|
|
539
|
+
if (sealedBy) {
|
|
540
|
+
presentedRequestedRef.current = /* @__PURE__ */ new Map();
|
|
541
|
+
} else {
|
|
542
|
+
for (const [callId, request] of presentedRequestedRef.current) {
|
|
543
|
+
if (request.turnId && !present.has(request.turnId)) {
|
|
544
|
+
presentedRequestedRef.current.delete(callId);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
setPresentedOutputs((current) => {
|
|
549
|
+
let kept = null;
|
|
550
|
+
for (const [callId, output] of current) {
|
|
551
|
+
if (output.turnId && present.has(output.turnId)) continue;
|
|
552
|
+
kept ??= new Map(current);
|
|
553
|
+
kept.delete(callId);
|
|
554
|
+
}
|
|
555
|
+
return kept ?? current;
|
|
556
|
+
});
|
|
557
|
+
},
|
|
558
|
+
[commitStepStores]
|
|
559
|
+
);
|
|
560
|
+
const presentedCallIds = useCallback3((event) => {
|
|
561
|
+
const ids = presentedCallIdsRef.current;
|
|
562
|
+
if (event.type === "agent.toolCall.created") {
|
|
563
|
+
notePresentedCalls([event], ids);
|
|
564
|
+
} else if (event.type === "agent.toolCall.output") {
|
|
565
|
+
const payload = event.payload;
|
|
566
|
+
const windowEvents = eventWindowRef.current.events;
|
|
567
|
+
if (typeof payload?.id === "string" && !ids.has(payload.id) && presentedScanRef.current !== windowEvents) {
|
|
568
|
+
presentedScanRef.current = windowEvents;
|
|
569
|
+
notePresentedCalls(windowEvents, ids);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return ids;
|
|
573
|
+
}, []);
|
|
574
|
+
const startupTurns = useCallback3(() => {
|
|
575
|
+
const windowEvents = eventWindowRef.current.events;
|
|
576
|
+
if (startupRef.current.window !== windowEvents) {
|
|
577
|
+
const state = emptyStartupTurns();
|
|
578
|
+
noteStartupTurns(windowEvents, state);
|
|
579
|
+
state.window = windowEvents;
|
|
580
|
+
startupRef.current = state;
|
|
581
|
+
}
|
|
582
|
+
return startupRef.current;
|
|
583
|
+
}, []);
|
|
584
|
+
const appendLiveSteps = useCallback3(
|
|
585
|
+
(steps) => {
|
|
586
|
+
if (steps.some((event) => !event.turnId)) {
|
|
587
|
+
const incoming = steps.filter((event) => !event.turnId);
|
|
588
|
+
const turnless = appendTurnlessSteps(turnlessStepsRef.current, incoming);
|
|
589
|
+
const rendered = renderedTurnlessRef.current;
|
|
590
|
+
if (!rendered.marked && turnless.appended - rendered.appended > turnless.events.length) {
|
|
591
|
+
rendered.marked = true;
|
|
592
|
+
if (sessionId) markTurnlessOutputGap(workspaceId, sessionId);
|
|
593
|
+
}
|
|
594
|
+
turnlessStepsRef.current = turnless;
|
|
595
|
+
setTurnlessSteps(turnless);
|
|
596
|
+
}
|
|
597
|
+
const windowEvents = withTurnlessSteps(
|
|
598
|
+
eventWindowRef.current.events,
|
|
599
|
+
turnlessStepsRef.current
|
|
600
|
+
);
|
|
601
|
+
const next = new Map(stepStoresRef.current);
|
|
602
|
+
const now = Date.now();
|
|
603
|
+
for (const [turnId, events] of groupByTurn(steps)) {
|
|
604
|
+
const existing = next.get(turnId);
|
|
605
|
+
const store = existing ?? {
|
|
606
|
+
events: [],
|
|
607
|
+
bytes: 2,
|
|
608
|
+
// Earlier steps exist when the window skips sequences between the
|
|
609
|
+
// turn's start and this first live step.
|
|
610
|
+
hasOlder: turnHasHiddenSequences(windowEvents, turnId, events[0].sequence),
|
|
611
|
+
cursor: null,
|
|
612
|
+
floor: null,
|
|
613
|
+
pinned: null,
|
|
614
|
+
loading: false,
|
|
615
|
+
error: false,
|
|
616
|
+
touched: now,
|
|
617
|
+
requestId: 0
|
|
618
|
+
};
|
|
619
|
+
let updated = { ...store, ...appendStepEvents(store, events), touched: now };
|
|
620
|
+
if (!retainedTurnsRef.current.get(turnId)) updated = trimLiveStepTail(updated);
|
|
621
|
+
next.set(turnId, updated);
|
|
622
|
+
}
|
|
623
|
+
commitStepStores(boundStepStores(next, retainedTurnsRef.current));
|
|
624
|
+
},
|
|
625
|
+
[commitStepStores, workspaceId, sessionId]
|
|
626
|
+
);
|
|
627
|
+
const loadTurnSteps = useCallback3(
|
|
628
|
+
(turnId, before) => {
|
|
629
|
+
if (!ownsNavigation() || !sessionId || fullReplay) return;
|
|
630
|
+
const current = stepStoresRef.current.get(turnId);
|
|
631
|
+
const pinnedUpper = before ?? (current?.error && current.pinned !== null ? current.pinned : void 0);
|
|
632
|
+
const pinned = pinnedUpper !== void 0;
|
|
633
|
+
if (!pinned && current?.loading) return;
|
|
634
|
+
const bounds = conversationTurnBounds(eventWindowRef.current.events).get(turnId);
|
|
635
|
+
if (!bounds) return;
|
|
636
|
+
if (!pinned && current && !stepStoreHasOlder(current, bounds) && !current.error) return;
|
|
637
|
+
const upper = pinnedUpper ?? current?.cursor ?? current?.events[0]?.sequence ?? (bounds.terminal !== null ? bounds.terminal + 1 : Number.MAX_SAFE_INTEGER);
|
|
638
|
+
const exactStart = bounds.started !== null;
|
|
639
|
+
const lower = turnStepLowerBound(bounds);
|
|
640
|
+
const generation = stepGenerationRef.current;
|
|
641
|
+
const requestId = ++stepRequestRef.current;
|
|
642
|
+
const isCurrent = () => ownsNavigation() && generation === stepGenerationRef.current && stepStoresRef.current.get(turnId)?.requestId === requestId;
|
|
643
|
+
const base = current ?? {
|
|
644
|
+
events: [],
|
|
645
|
+
bytes: 2,
|
|
646
|
+
hasOlder: true,
|
|
647
|
+
cursor: null,
|
|
648
|
+
floor: null,
|
|
649
|
+
pinned: null,
|
|
650
|
+
loading: false,
|
|
651
|
+
error: false,
|
|
652
|
+
touched: 0,
|
|
653
|
+
requestId
|
|
654
|
+
};
|
|
655
|
+
commitStepStores(
|
|
656
|
+
new Map(stepStoresRef.current).set(turnId, {
|
|
657
|
+
...base,
|
|
658
|
+
pinned: pinned ? upper : null,
|
|
659
|
+
loading: true,
|
|
660
|
+
error: false,
|
|
661
|
+
touched: Date.now(),
|
|
662
|
+
requestId
|
|
663
|
+
})
|
|
664
|
+
);
|
|
665
|
+
void readEventPage(client, workspaceId, sessionId, {
|
|
666
|
+
// Bookkeeping too, whichever read built this window: rows it already
|
|
667
|
+
// holds (a fallback read keeps them) merge once by id.
|
|
668
|
+
includeTypes: [...TURN_STEP_READ_TYPES],
|
|
669
|
+
after: Math.max(0, lower),
|
|
670
|
+
before: upper,
|
|
671
|
+
direction: "before",
|
|
672
|
+
limit: SESSION_TURN_STEP_PAGE_SIZE,
|
|
673
|
+
compact: true,
|
|
674
|
+
payloadMode: "full",
|
|
675
|
+
// Large tool outputs arrive as bounded previews; a row reads its
|
|
676
|
+
// exact output when the reader needs it (see useToolOutputReads).
|
|
677
|
+
toolOutputs: "preview"
|
|
678
|
+
}).then(
|
|
679
|
+
(page) => {
|
|
680
|
+
if (!isCurrent()) return;
|
|
681
|
+
const own = page.events.filter((event) => event.turnId === turnId);
|
|
682
|
+
const latest = stepStoresRef.current.get(turnId);
|
|
683
|
+
const merged = pinned ? appendStepEvents(
|
|
684
|
+
{ events: [], bytes: 2 },
|
|
685
|
+
[...own, ...latest.events.filter((event) => event.sequence >= upper)].sort(
|
|
686
|
+
(left, right) => left.sequence - right.sequence
|
|
687
|
+
)
|
|
688
|
+
) : appendStepEvents(latest, own);
|
|
689
|
+
const oldestOwn = merged.events[0]?.sequence ?? upper;
|
|
690
|
+
const passedStart = !exactStart && page.events.some(
|
|
691
|
+
(event) => !!event.turnId && event.turnId !== turnId && event.sequence < oldestOwn
|
|
692
|
+
);
|
|
693
|
+
const moreBelow = !passedStart && (page.hasMore ?? page.events.length > 0);
|
|
694
|
+
const reachedFloor = !moreBelow && !passedStart && !exactStart;
|
|
695
|
+
const next = new Map(stepStoresRef.current).set(turnId, {
|
|
696
|
+
...merged,
|
|
697
|
+
// A page read without a continuation fact (a client without
|
|
698
|
+
// listEventPage) offers one more page until a read comes back empty.
|
|
699
|
+
hasOlder: moreBelow,
|
|
700
|
+
// The next page continues below this page's oldest row, even when
|
|
701
|
+
// the page held only other turns' rows, or below the floor.
|
|
702
|
+
cursor: reachedFloor ? lower + 1 : page.events.reduce((oldest, event) => Math.min(oldest, event.sequence), upper),
|
|
703
|
+
floor: reachedFloor ? lower : null,
|
|
704
|
+
pinned: null,
|
|
705
|
+
loading: false,
|
|
706
|
+
error: false,
|
|
707
|
+
touched: Date.now(),
|
|
708
|
+
requestId
|
|
709
|
+
});
|
|
710
|
+
commitStepStores(boundStepStores(next, retainedTurnsRef.current));
|
|
711
|
+
},
|
|
712
|
+
() => {
|
|
713
|
+
if (!isCurrent()) return;
|
|
714
|
+
const latest = stepStoresRef.current.get(turnId);
|
|
715
|
+
commitStepStores(
|
|
716
|
+
new Map(stepStoresRef.current).set(turnId, { ...latest, loading: false, error: true })
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
);
|
|
720
|
+
},
|
|
721
|
+
[client, workspaceId, sessionId, fullReplay, ownsNavigation, commitStepStores]
|
|
722
|
+
);
|
|
723
|
+
const loadTurnStepsRef = useRef2(loadTurnSteps);
|
|
724
|
+
useEffect2(() => {
|
|
725
|
+
loadTurnStepsRef.current = loadTurnSteps;
|
|
726
|
+
}, [loadTurnSteps]);
|
|
727
|
+
const turnStepHandle = useCallback3((turnId) => {
|
|
728
|
+
let handle = turnStepHandlesRef.current.get(turnId);
|
|
729
|
+
if (!handle) {
|
|
730
|
+
const retained = retainedTurnsRef.current;
|
|
731
|
+
handle = {
|
|
732
|
+
load: () => loadTurnStepsRef.current(turnId),
|
|
733
|
+
retain: () => {
|
|
734
|
+
retained.set(turnId, (retained.get(turnId) ?? 0) + 1);
|
|
735
|
+
let released = false;
|
|
736
|
+
return () => {
|
|
737
|
+
if (released) return;
|
|
738
|
+
released = true;
|
|
739
|
+
const count = (retained.get(turnId) ?? 1) - 1;
|
|
740
|
+
if (count > 0) retained.set(turnId, count);
|
|
741
|
+
else retained.delete(turnId);
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
turnStepHandlesRef.current.set(turnId, handle);
|
|
746
|
+
}
|
|
747
|
+
return handle;
|
|
748
|
+
}, []);
|
|
749
|
+
useEffect2(() => {
|
|
750
|
+
navigationGenerationRef.current += 1;
|
|
751
|
+
setNewerError(null);
|
|
752
|
+
loadingOlderRef.current = false;
|
|
753
|
+
loadingNewerRef.current = false;
|
|
754
|
+
loadingOldestRef.current = false;
|
|
755
|
+
loadingTargetRef.current = false;
|
|
756
|
+
setQuestionEvidence(null);
|
|
757
|
+
setLoadingTarget(false);
|
|
758
|
+
setLoadingOlder(false);
|
|
759
|
+
setLoadingNewer(false);
|
|
760
|
+
setLoadingOldest(false);
|
|
761
|
+
return () => {
|
|
762
|
+
navigationGenerationRef.current += 1;
|
|
763
|
+
};
|
|
764
|
+
}, [client, workspaceId, sessionId, after, enabled, fullReplay]);
|
|
765
|
+
useEffect2(() => {
|
|
766
|
+
if (streamKeyRef.current !== streamKey) {
|
|
767
|
+
streamKeyRef.current = streamKey;
|
|
768
|
+
setStateStreamKey(streamKey);
|
|
769
|
+
eventWindowRef.current = EMPTY_EVENT_WINDOW;
|
|
770
|
+
setEventWindow(EMPTY_EVENT_WINDOW);
|
|
771
|
+
setError(null);
|
|
772
|
+
setHasOlder(false);
|
|
773
|
+
setHasNewer(false);
|
|
774
|
+
sessionStatusRef.current = { sequence: after, status: null };
|
|
775
|
+
setSessionStatusProjection(null);
|
|
776
|
+
setLoadingOlder(false);
|
|
777
|
+
setLoadingNewer(false);
|
|
778
|
+
setLoadingOldest(false);
|
|
779
|
+
setLoadingLatest(false);
|
|
780
|
+
setInitialLoading(true);
|
|
781
|
+
setInitialHistoryReady(false);
|
|
782
|
+
lastSequenceRef.current = after;
|
|
783
|
+
streamResumeSequenceRef.current = after;
|
|
784
|
+
liveThroughRef.current = after;
|
|
785
|
+
skippedStepsThroughRef.current = null;
|
|
786
|
+
oldestSequenceRef.current = null;
|
|
787
|
+
newestSequenceRef.current = null;
|
|
788
|
+
hasOlderRef.current = false;
|
|
789
|
+
hasNewerRef.current = false;
|
|
790
|
+
loadingOlderRef.current = false;
|
|
791
|
+
loadingNewerRef.current = false;
|
|
792
|
+
loadingOldestRef.current = false;
|
|
793
|
+
loadingLatestRef.current = false;
|
|
794
|
+
viewModeRef.current = "live";
|
|
795
|
+
setViewMode("live");
|
|
796
|
+
initialWindowLoadedRef.current = false;
|
|
797
|
+
reconcileAfterPageResumeRef.current = false;
|
|
798
|
+
rejoinPendingRef.current = false;
|
|
799
|
+
streamTransientStreakRef.current = null;
|
|
800
|
+
stepGenerationRef.current += 1;
|
|
801
|
+
stepStoresRef.current = EMPTY_STEP_STORES;
|
|
802
|
+
setStepStores(EMPTY_STEP_STORES);
|
|
803
|
+
turnlessStepsRef.current = EMPTY_TURNLESS_STEPS;
|
|
804
|
+
setTurnlessSteps(EMPTY_TURNLESS_STEPS);
|
|
805
|
+
turnStepHandlesRef.current = /* @__PURE__ */ new Map();
|
|
806
|
+
presentedCallIdsRef.current = /* @__PURE__ */ new Set();
|
|
807
|
+
presentedScanRef.current = null;
|
|
808
|
+
startupRef.current = emptyStartupTurns();
|
|
809
|
+
presentedRequestedRef.current = /* @__PURE__ */ new Map();
|
|
810
|
+
presentedFailuresRef.current = /* @__PURE__ */ new Map();
|
|
811
|
+
setPresentedOutputs(EMPTY_PRESENTED_OUTPUTS);
|
|
812
|
+
}
|
|
813
|
+
const generation = generationRef.current + 1;
|
|
814
|
+
generationRef.current = generation;
|
|
815
|
+
if (!sessionId || !streamEnabled) {
|
|
816
|
+
streamTransientStreakRef.current = null;
|
|
817
|
+
if (sessionId && enabled && !pageLive && !fullReplay && viewModeRef.current === "live" && initialWindowLoadedRef.current) {
|
|
818
|
+
reconcileAfterPageResumeRef.current = true;
|
|
819
|
+
}
|
|
820
|
+
setConnectionState("idle");
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
if (viewMode === "history") {
|
|
824
|
+
reconcileAfterPageResumeRef.current = false;
|
|
825
|
+
setConnectionState("idle");
|
|
826
|
+
setInitialLoading(false);
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
const reconcileForegroundResume = reconcileAfterPageResumeRef.current && !fullReplay;
|
|
830
|
+
reconcileAfterPageResumeRef.current = false;
|
|
831
|
+
const controller = new AbortController();
|
|
832
|
+
const detailReadMark = sessionDetailReadMark();
|
|
833
|
+
const isCurrent = () => generationRef.current === generation && !controller.signal.aborted && navigationIdentityRef.current.client === client && navigationIdentityRef.current.streamKey === streamKey && navigationIdentityRef.current.enabled === enabled;
|
|
834
|
+
streamAbortRef.current = controller;
|
|
835
|
+
let transientRetryTimer = null;
|
|
836
|
+
const scheduleTransientRetry = (delayMs, retry) => {
|
|
837
|
+
if (transientRetryTimer !== null) clearTimeout(transientRetryTimer);
|
|
838
|
+
transientRetryTimer = setTimeout(() => {
|
|
839
|
+
transientRetryTimer = null;
|
|
840
|
+
if (isCurrent()) retry();
|
|
841
|
+
}, delayMs);
|
|
842
|
+
};
|
|
843
|
+
let pending = [];
|
|
844
|
+
let pendingBytes = 2;
|
|
845
|
+
let flushTimer = null;
|
|
846
|
+
const flush = () => {
|
|
847
|
+
if (flushTimer !== null) {
|
|
848
|
+
clearTimeout(flushTimer);
|
|
849
|
+
flushTimer = null;
|
|
850
|
+
}
|
|
851
|
+
if (!isCurrent()) {
|
|
852
|
+
pending = [];
|
|
853
|
+
pendingBytes = 2;
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
if (pending.length === 0) {
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
const batch = pending;
|
|
860
|
+
pending = [];
|
|
861
|
+
pendingBytes = 2;
|
|
862
|
+
const lastInBatch = batch[batch.length - 1];
|
|
863
|
+
if (lastInBatch) {
|
|
864
|
+
const batchResumeSequence = Math.max(...batch.map(eventResumeSequence));
|
|
865
|
+
lastSequenceRef.current = Math.max(lastSequenceRef.current, batchResumeSequence);
|
|
866
|
+
streamResumeSequenceRef.current = Math.max(
|
|
867
|
+
streamResumeSequenceRef.current,
|
|
868
|
+
batchResumeSequence
|
|
869
|
+
);
|
|
870
|
+
liveThroughRef.current = Math.max(liveThroughRef.current, batchResumeSequence);
|
|
871
|
+
}
|
|
872
|
+
const status = observeSessionStatus(batch, sessionStatusRef);
|
|
873
|
+
if (status !== void 0) {
|
|
874
|
+
setSessionStatusProjection(status);
|
|
875
|
+
}
|
|
876
|
+
let conversation = batch;
|
|
877
|
+
const steps = [];
|
|
878
|
+
if (!fullReplay) {
|
|
879
|
+
const windowNewest = newestSequenceRef.current ?? 0;
|
|
880
|
+
const startup = startupTurns();
|
|
881
|
+
conversation = [];
|
|
882
|
+
for (const event of batch) {
|
|
883
|
+
if (!isConversationHistoryEvent(event, presentedCallIds(event), startup.open)) {
|
|
884
|
+
steps.push(event);
|
|
885
|
+
} else if (event.sequence > windowNewest) conversation.push(event);
|
|
886
|
+
noteStartupTurns([event], startup);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
if (conversation.length > 0) {
|
|
890
|
+
const current = eventWindowRef.current;
|
|
891
|
+
const next = appendBrowserSessionEventWindow(current, conversation);
|
|
892
|
+
const retained = {
|
|
893
|
+
...next,
|
|
894
|
+
truncated: current.truncated || next.truncated
|
|
895
|
+
};
|
|
896
|
+
eventWindowRef.current = retained;
|
|
897
|
+
setEventWindow(retained);
|
|
898
|
+
if (!fullReplay) startupRef.current.window = retained.events;
|
|
899
|
+
oldestSequenceRef.current = retained.events[0]?.sequence ?? null;
|
|
900
|
+
newestSequenceRef.current = maxResumeSequenceOrNull(retained.events);
|
|
901
|
+
if (retained.truncated) {
|
|
902
|
+
hasOlderRef.current = true;
|
|
903
|
+
setHasOlder(true);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
if (steps.length > 0) appendLiveSteps(steps);
|
|
907
|
+
};
|
|
908
|
+
const scheduleFlush = () => {
|
|
909
|
+
if (!isCurrent()) return;
|
|
910
|
+
flushTimer ??= setTimeout(flush, 16);
|
|
911
|
+
};
|
|
912
|
+
const installCatchup = (events, head) => {
|
|
913
|
+
const current = eventWindowRef.current;
|
|
914
|
+
const windowNewest = newestSequenceRef.current ?? 0;
|
|
915
|
+
const fresh = events.filter((event) => event.sequence > windowNewest);
|
|
916
|
+
const status = observeSessionStatus(fresh, sessionStatusRef);
|
|
917
|
+
const next = appendBrowserSessionEventWindow(current, fresh);
|
|
918
|
+
const retained = { ...next, truncated: current.truncated || next.truncated };
|
|
919
|
+
eventWindowRef.current = retained;
|
|
920
|
+
oldestSequenceRef.current = retained.events[0]?.sequence ?? oldestSequenceRef.current;
|
|
921
|
+
newestSequenceRef.current = maxResumeSequenceOrNull(retained.events) ?? newestSequenceRef.current;
|
|
922
|
+
lastSequenceRef.current = Math.max(lastSequenceRef.current, head);
|
|
923
|
+
streamResumeSequenceRef.current = Math.max(streamResumeSequenceRef.current, head);
|
|
924
|
+
if (skippedStepsThroughRef.current !== null) {
|
|
925
|
+
skippedStepsThroughRef.current = Math.max(skippedStepsThroughRef.current, head);
|
|
926
|
+
}
|
|
927
|
+
if (status !== void 0) setSessionStatusProjection(status);
|
|
928
|
+
if (fresh.length > 0) setEventWindow(retained);
|
|
929
|
+
if (retained.truncated) {
|
|
930
|
+
hasOlderRef.current = true;
|
|
931
|
+
setHasOlder(true);
|
|
932
|
+
}
|
|
933
|
+
};
|
|
934
|
+
const effectScope = { signal: controller.signal, isCurrent };
|
|
935
|
+
const readSessionHead = async (mark, scope) => {
|
|
936
|
+
const joined = joinSessionDetailRead(client, workspaceId, sessionId, mark);
|
|
937
|
+
if (joined) {
|
|
938
|
+
try {
|
|
939
|
+
return await joined;
|
|
940
|
+
} catch (cause) {
|
|
941
|
+
if (scope.signal.aborted) throw cause;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
return await client.getSession(workspaceId, sessionId, {
|
|
945
|
+
fresh: true,
|
|
946
|
+
signal: scope.signal
|
|
947
|
+
});
|
|
948
|
+
};
|
|
949
|
+
const rejoinLive = async (force, {
|
|
950
|
+
strict = false,
|
|
951
|
+
mark = detailReadMark,
|
|
952
|
+
scope = effectScope
|
|
953
|
+
} = {}) => {
|
|
954
|
+
const activeTurn = activeConversationTurn(eventWindowRef.current.events);
|
|
955
|
+
if (!force && !activeTurn) return "joined";
|
|
956
|
+
const cursor = streamResumeSequenceRef.current;
|
|
957
|
+
let head;
|
|
958
|
+
let sessionActiveTurn = null;
|
|
959
|
+
try {
|
|
960
|
+
const session = await readSessionHead(mark, scope);
|
|
961
|
+
scope.progress?.();
|
|
962
|
+
head = session.lastSequence;
|
|
963
|
+
sessionActiveTurn = session.activeTurnId;
|
|
964
|
+
} catch (cause) {
|
|
965
|
+
if (!scope.isCurrent() || strict && isRetryableStreamError(cause)) throw cause;
|
|
966
|
+
return "joined";
|
|
967
|
+
}
|
|
968
|
+
if (!scope.isCurrent()) throw abortError();
|
|
969
|
+
if (!Number.isSafeInteger(head) || head - cursor <= DIRECT_REPLAY_MAX_SEQUENCES) {
|
|
970
|
+
return "joined";
|
|
971
|
+
}
|
|
972
|
+
let catchup;
|
|
973
|
+
try {
|
|
974
|
+
catchup = await loadConversationCatchup(
|
|
975
|
+
client,
|
|
976
|
+
workspaceId,
|
|
977
|
+
sessionId,
|
|
978
|
+
cursor,
|
|
979
|
+
head,
|
|
980
|
+
scope
|
|
981
|
+
);
|
|
982
|
+
} catch (cause) {
|
|
983
|
+
if (!scope.isCurrent() || strict && isRetryableStreamError(cause)) throw cause;
|
|
984
|
+
return "joined";
|
|
985
|
+
}
|
|
986
|
+
if (!scope.isCurrent()) throw abortError();
|
|
987
|
+
if (catchup === null) return "reload";
|
|
988
|
+
const previous = eventWindowRef.current.events;
|
|
989
|
+
installCatchup(catchup, head);
|
|
990
|
+
const working = sessionActiveTurn ?? activeConversationTurn(eventWindowRef.current.events);
|
|
991
|
+
pruneStepStores(eventWindowRef.current.events, previous, working);
|
|
992
|
+
if (working) loadTurnStepsRef.current(working, head + 1);
|
|
993
|
+
if (working && conversationTurnBounds(eventWindowRef.current.events).has(working)) {
|
|
994
|
+
skippedStepsThroughRef.current = null;
|
|
995
|
+
}
|
|
996
|
+
return "joined";
|
|
997
|
+
};
|
|
998
|
+
const loadLatestWindow = async (scope = effectScope) => {
|
|
999
|
+
const window2 = await loadEventWindow(t, client, workspaceId, sessionId, {
|
|
1000
|
+
before: Number.MAX_SAFE_INTEGER,
|
|
1001
|
+
pageSize: SESSION_FIRST_WINDOW_PAGE_SIZE,
|
|
1002
|
+
targetGroups: Number.POSITIVE_INFINITY,
|
|
1003
|
+
maxFetches: INITIAL_FETCH_CAP,
|
|
1004
|
+
boundaryPageCap: BOUNDARY_PAGE_CAP,
|
|
1005
|
+
signal: scope.signal,
|
|
1006
|
+
...scope.progress ? { progress: scope.progress } : {},
|
|
1007
|
+
filter: CONVERSATION_FILTER
|
|
1008
|
+
});
|
|
1009
|
+
if (!scope.isCurrent()) {
|
|
1010
|
+
return false;
|
|
1011
|
+
}
|
|
1012
|
+
const status = observeSessionStatus(window2.events, sessionStatusRef);
|
|
1013
|
+
const retained = boundBrowserSessionEventWindow(window2.events);
|
|
1014
|
+
navigationGenerationRef.current += 1;
|
|
1015
|
+
loadingOlderRef.current = false;
|
|
1016
|
+
loadingNewerRef.current = false;
|
|
1017
|
+
loadingOldestRef.current = false;
|
|
1018
|
+
setLoadingOlder(false);
|
|
1019
|
+
setLoadingNewer(false);
|
|
1020
|
+
setLoadingOldest(false);
|
|
1021
|
+
const previous = eventWindowRef.current.events;
|
|
1022
|
+
eventWindowRef.current = retained;
|
|
1023
|
+
pruneStepStores(retained.events, previous);
|
|
1024
|
+
oldestSequenceRef.current = retained.events[0]?.sequence ?? window2.oldestSequence ?? window2.scanCursor;
|
|
1025
|
+
newestSequenceRef.current = maxResumeSequenceOrNull(retained.events) ?? window2.newestSequence;
|
|
1026
|
+
hasOlderRef.current = window2.hasOlder || retained.truncated;
|
|
1027
|
+
hasNewerRef.current = false;
|
|
1028
|
+
lastSequenceRef.current = Math.max(lastSequenceRef.current, window2.newestSequence);
|
|
1029
|
+
streamResumeSequenceRef.current = window2.newestSequence;
|
|
1030
|
+
skippedStepsThroughRef.current = retained.events.length === 0 && window2.newestSequence > 0 ? window2.newestSequence : null;
|
|
1031
|
+
initialWindowLoadedRef.current = true;
|
|
1032
|
+
streamTransientStreakRef.current = null;
|
|
1033
|
+
setInitialHistoryReady(true);
|
|
1034
|
+
setError(null);
|
|
1035
|
+
if (status !== void 0) {
|
|
1036
|
+
setSessionStatusProjection(status);
|
|
1037
|
+
}
|
|
1038
|
+
setEventWindow(retained);
|
|
1039
|
+
setHasOlder(window2.hasOlder || retained.truncated);
|
|
1040
|
+
setHasNewer(false);
|
|
1041
|
+
setInitialLoading(false);
|
|
1042
|
+
return true;
|
|
1043
|
+
};
|
|
1044
|
+
const noteStreamResume = () => {
|
|
1045
|
+
if (!fullReplay && streamResumeSequenceRef.current > liveThroughRef.current) {
|
|
1046
|
+
markTurnlessOutputGap(workspaceId, sessionId);
|
|
1047
|
+
}
|
|
1048
|
+
liveThroughRef.current = Math.max(liveThroughRef.current, streamResumeSequenceRef.current);
|
|
1049
|
+
};
|
|
1050
|
+
const reconcileAfterOpen = (initialOpen, streak = null) => {
|
|
1051
|
+
void Promise.resolve().then(() => reconcileSession(sessionId, { initialOpen })).catch((cause) => {
|
|
1052
|
+
if (!isCurrent()) return;
|
|
1053
|
+
if (isTransientRequestError(cause)) {
|
|
1054
|
+
const now = Date.now();
|
|
1055
|
+
const current = streak ?? { since: now, attempts: 0, surfaced: false };
|
|
1056
|
+
const step = transientReadRetryStep(current, now, DEFAULT_TRANSIENT_READ_RETRY, cause);
|
|
1057
|
+
if (step.quiet) {
|
|
1058
|
+
scheduleTransientRetry(step.delayMs, () => reconcileAfterOpen(initialOpen, current));
|
|
1059
|
+
return;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
setError(normalizeError(cause));
|
|
1063
|
+
});
|
|
1064
|
+
};
|
|
1065
|
+
const boundedRejoin = async (strict, join) => {
|
|
1066
|
+
if (!isCurrent()) throw abortError();
|
|
1067
|
+
const attempt = new AbortController();
|
|
1068
|
+
let timedOut = false;
|
|
1069
|
+
const abortAttempt = () => attempt.abort();
|
|
1070
|
+
controller.signal.addEventListener("abort", abortAttempt, { once: true });
|
|
1071
|
+
const stalled = () => {
|
|
1072
|
+
timedOut = true;
|
|
1073
|
+
attempt.abort();
|
|
1074
|
+
};
|
|
1075
|
+
let timer = setTimeout(stalled, REJOIN_STALL_TIMEOUT_MS);
|
|
1076
|
+
let stopWaiting;
|
|
1077
|
+
const stopped = new Promise((_resolve, reject) => {
|
|
1078
|
+
stopWaiting = () => reject(abortError());
|
|
1079
|
+
attempt.signal.addEventListener("abort", stopWaiting, { once: true });
|
|
1080
|
+
});
|
|
1081
|
+
const scope = {
|
|
1082
|
+
signal: attempt.signal,
|
|
1083
|
+
isCurrent: () => isCurrent() && !attempt.signal.aborted,
|
|
1084
|
+
progress: () => {
|
|
1085
|
+
if (attempt.signal.aborted) return;
|
|
1086
|
+
clearTimeout(timer);
|
|
1087
|
+
timer = setTimeout(stalled, REJOIN_STALL_TIMEOUT_MS);
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
try {
|
|
1091
|
+
return await Promise.race([join(scope), stopped]);
|
|
1092
|
+
} catch (cause) {
|
|
1093
|
+
if (!isCurrent()) throw cause;
|
|
1094
|
+
if (timedOut) {
|
|
1095
|
+
return strict ? {
|
|
1096
|
+
retry: new TypeError(
|
|
1097
|
+
`rejoining the live session stalled for ${REJOIN_STALL_TIMEOUT_MS}ms`
|
|
1098
|
+
)
|
|
1099
|
+
} : "joined";
|
|
1100
|
+
}
|
|
1101
|
+
if (strict && isRetryableStreamError(cause)) return { retry: cause };
|
|
1102
|
+
throw cause;
|
|
1103
|
+
} finally {
|
|
1104
|
+
clearTimeout(timer);
|
|
1105
|
+
controller.signal.removeEventListener("abort", abortAttempt);
|
|
1106
|
+
if (stopWaiting) attempt.signal.removeEventListener("abort", stopWaiting);
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
const leniently = async (join) => {
|
|
1110
|
+
const result = await boundedRejoin(false, join);
|
|
1111
|
+
return typeof result === "string" ? result : "joined";
|
|
1112
|
+
};
|
|
1113
|
+
let strictFailures = 0;
|
|
1114
|
+
const beforeReconnect = async (cursor) => {
|
|
1115
|
+
flush();
|
|
1116
|
+
if (!isCurrent()) throw abortError();
|
|
1117
|
+
const strict = strictFailures < STRICT_REJOIN_ATTEMPTS;
|
|
1118
|
+
const mark = sessionDetailReadMark();
|
|
1119
|
+
let result;
|
|
1120
|
+
try {
|
|
1121
|
+
result = await boundedRejoin(strict, async (scope) => {
|
|
1122
|
+
if (await rejoinLive(true, { strict, mark, scope }) === "joined") return "joined";
|
|
1123
|
+
let loaded;
|
|
1124
|
+
try {
|
|
1125
|
+
loaded = await loadLatestWindow(scope);
|
|
1126
|
+
} catch (cause) {
|
|
1127
|
+
if (!scope.isCurrent() || strict && isRetryableStreamError(cause)) throw cause;
|
|
1128
|
+
return "joined";
|
|
1129
|
+
}
|
|
1130
|
+
if (!loaded) throw abortError();
|
|
1131
|
+
if (await rejoinLive(true, { strict, mark, scope }) === "reload" && strict) {
|
|
1132
|
+
throw new TypeError("the session outran a fresh window while rejoining it");
|
|
1133
|
+
}
|
|
1134
|
+
return "joined";
|
|
1135
|
+
});
|
|
1136
|
+
} catch (cause) {
|
|
1137
|
+
if (!isCurrent()) throw abortError();
|
|
1138
|
+
if (!isRetryableStreamError(cause)) throw cause;
|
|
1139
|
+
throw new Error(`rejoining the live session failed: ${errorMessage(cause)}`, { cause });
|
|
1140
|
+
}
|
|
1141
|
+
if (!isCurrent()) throw abortError();
|
|
1142
|
+
if (typeof result === "object") {
|
|
1143
|
+
strictFailures += 1;
|
|
1144
|
+
throw result.retry;
|
|
1145
|
+
}
|
|
1146
|
+
noteStreamResume();
|
|
1147
|
+
return Math.max(cursor, streamResumeSequenceRef.current);
|
|
1148
|
+
};
|
|
1149
|
+
void (async () => {
|
|
1150
|
+
try {
|
|
1151
|
+
if (reconcileForegroundResume) {
|
|
1152
|
+
setConnectionState("connecting");
|
|
1153
|
+
let outcome;
|
|
1154
|
+
for (let attempt = 0; ; attempt += 1) {
|
|
1155
|
+
const strict = attempt < STRICT_REJOIN_ATTEMPTS;
|
|
1156
|
+
const result = await boundedRejoin(
|
|
1157
|
+
strict,
|
|
1158
|
+
(scope) => rejoinLive(true, { strict, scope })
|
|
1159
|
+
);
|
|
1160
|
+
if (typeof result === "string") {
|
|
1161
|
+
outcome = result;
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
await abortableDelay(
|
|
1165
|
+
Math.min(FOREGROUND_REJOIN_RETRY_MS * 2 ** attempt, FOREGROUND_REJOIN_RETRY_MAX_MS),
|
|
1166
|
+
controller.signal
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
1169
|
+
if (outcome === "reload") {
|
|
1170
|
+
initialWindowLoadedRef.current = false;
|
|
1171
|
+
setError(null);
|
|
1172
|
+
}
|
|
1173
|
+
} else if (!fullReplay && initialWindowLoadedRef.current && rejoinPendingRef.current) {
|
|
1174
|
+
rejoinPendingRef.current = false;
|
|
1175
|
+
if (await leniently((scope) => rejoinLive(false, { scope })) === "reload") {
|
|
1176
|
+
initialWindowLoadedRef.current = false;
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
rejoinPendingRef.current = false;
|
|
1180
|
+
const windowPasses = fullReplay ? 0 : 2;
|
|
1181
|
+
for (let attempt = 0; attempt < windowPasses && !initialWindowLoadedRef.current; attempt += 1) {
|
|
1182
|
+
setConnectionState("connecting");
|
|
1183
|
+
if (!await loadLatestWindow()) {
|
|
1184
|
+
return;
|
|
1185
|
+
}
|
|
1186
|
+
if (await leniently((scope) => rejoinLive(true, { scope })) === "reload" && attempt === 0) {
|
|
1187
|
+
initialWindowLoadedRef.current = false;
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
if (fullReplay) {
|
|
1191
|
+
setInitialLoading(false);
|
|
1192
|
+
}
|
|
1193
|
+
noteStreamResume();
|
|
1194
|
+
const stream = client.streamEvents(workspaceId, sessionId, {
|
|
1195
|
+
after: streamResumeSequenceRef.current,
|
|
1196
|
+
signal: controller.signal,
|
|
1197
|
+
// Full replay keeps the SDK's exactly-once reconnects.
|
|
1198
|
+
...fullReplay ? {} : { beforeReconnect },
|
|
1199
|
+
onOpen: () => {
|
|
1200
|
+
const initialOpen = openedStreamKeyRef.current !== streamKey;
|
|
1201
|
+
openedStreamKeyRef.current = streamKey;
|
|
1202
|
+
strictFailures = 0;
|
|
1203
|
+
if (streamTransientStreakRef.current?.surfaced) setError(null);
|
|
1204
|
+
streamTransientStreakRef.current = null;
|
|
1205
|
+
reconcileAfterOpen(initialOpen);
|
|
1206
|
+
},
|
|
1207
|
+
onStateChange: (state) => {
|
|
1208
|
+
if (isCurrent()) {
|
|
1209
|
+
setConnectionState(state);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
});
|
|
1213
|
+
for await (const event of stream) {
|
|
1214
|
+
if (!isCurrent()) break;
|
|
1215
|
+
const boundedEvent = event;
|
|
1216
|
+
const boundedEventBytes = browserJsonBytes(boundedEvent);
|
|
1217
|
+
const separatorBytes = pending.length === 0 ? 0 : 1;
|
|
1218
|
+
if (pending.length > 0 && (pending.length >= SESSION_EVENT_BROWSER_PENDING_MAX_COUNT || pendingBytes + separatorBytes + boundedEventBytes > SESSION_EVENT_BROWSER_PENDING_MAX_BYTES)) {
|
|
1219
|
+
flush();
|
|
1220
|
+
}
|
|
1221
|
+
pending.push(boundedEvent);
|
|
1222
|
+
pendingBytes += (pending.length === 1 ? 0 : 1) + boundedEventBytes;
|
|
1223
|
+
if (pending.length >= SESSION_EVENT_BROWSER_PENDING_MAX_COUNT || pendingBytes >= SESSION_EVENT_BROWSER_PENDING_MAX_BYTES) {
|
|
1224
|
+
flush();
|
|
1225
|
+
} else {
|
|
1226
|
+
scheduleFlush();
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
if (isCurrent()) {
|
|
1230
|
+
flush();
|
|
1231
|
+
setConnectionState("ended");
|
|
1232
|
+
}
|
|
1233
|
+
} catch (cause) {
|
|
1234
|
+
if (isCurrent()) {
|
|
1235
|
+
flush();
|
|
1236
|
+
let announce = true;
|
|
1237
|
+
if (isTransientRequestError(cause)) {
|
|
1238
|
+
const now = Date.now();
|
|
1239
|
+
const streak = streamTransientStreakRef.current ??= {
|
|
1240
|
+
since: now,
|
|
1241
|
+
attempts: 0,
|
|
1242
|
+
surfaced: false
|
|
1243
|
+
};
|
|
1244
|
+
const step = transientReadRetryStep(streak, now, DEFAULT_TRANSIENT_READ_RETRY, cause);
|
|
1245
|
+
scheduleTransientRetry(step.delayMs, () => setStreamEpoch((epoch) => epoch + 1));
|
|
1246
|
+
if (step.quiet) {
|
|
1247
|
+
setConnectionState("connecting");
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
announce = !streak.surfaced;
|
|
1251
|
+
streak.surfaced = true;
|
|
1252
|
+
} else {
|
|
1253
|
+
streamTransientStreakRef.current = null;
|
|
1254
|
+
}
|
|
1255
|
+
if (announce) setError(normalizeError(cause));
|
|
1256
|
+
setConnectionState("error");
|
|
1257
|
+
setInitialLoading(false);
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
})();
|
|
1261
|
+
return () => {
|
|
1262
|
+
controller.abort();
|
|
1263
|
+
if (transientRetryTimer !== null) clearTimeout(transientRetryTimer);
|
|
1264
|
+
if (generationRef.current === generation) {
|
|
1265
|
+
generationRef.current = generation + 1;
|
|
1266
|
+
}
|
|
1267
|
+
if (streamAbortRef.current === controller) {
|
|
1268
|
+
streamAbortRef.current = null;
|
|
1269
|
+
}
|
|
1270
|
+
if (flushTimer !== null) {
|
|
1271
|
+
clearTimeout(flushTimer);
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
}, [
|
|
1275
|
+
client,
|
|
1276
|
+
workspaceId,
|
|
1277
|
+
sessionId,
|
|
1278
|
+
after,
|
|
1279
|
+
enabled,
|
|
1280
|
+
pageLive,
|
|
1281
|
+
streamEnabled,
|
|
1282
|
+
fullReplay,
|
|
1283
|
+
streamKey,
|
|
1284
|
+
streamEpoch,
|
|
1285
|
+
viewMode,
|
|
1286
|
+
reconcileSession,
|
|
1287
|
+
t,
|
|
1288
|
+
pruneStepStores,
|
|
1289
|
+
appendLiveSteps,
|
|
1290
|
+
presentedCallIds,
|
|
1291
|
+
startupTurns
|
|
1292
|
+
]);
|
|
1293
|
+
useEffect2(() => {
|
|
1294
|
+
if (!sessionId || !streamEnabled) return;
|
|
1295
|
+
return subscribePageWake(() => {
|
|
1296
|
+
const stream = streamAbortRef.current;
|
|
1297
|
+
if (!stream || stream.signal.aborted || viewModeRef.current !== "live") return;
|
|
1298
|
+
if (!fullReplay && initialWindowLoadedRef.current) {
|
|
1299
|
+
reconcileAfterPageResumeRef.current = true;
|
|
1300
|
+
}
|
|
1301
|
+
setStreamEpoch((epoch) => epoch + 1);
|
|
1302
|
+
});
|
|
1303
|
+
}, [sessionId, streamEnabled, fullReplay]);
|
|
1304
|
+
const navigationBusy = () => loadingTargetRef.current || loadingOlderRef.current || loadingNewerRef.current || loadingOldestRef.current || loadingLatestRef.current;
|
|
1305
|
+
const loadOlder = useCallback3(
|
|
1306
|
+
() => createOlderHistoryLoadReceipt(async (markCommitted, preserveTail, markTailPreserved) => {
|
|
1307
|
+
if (!ownsNavigation() || !sessionId || navigationBusy() || !hasOlderRef.current) {
|
|
1308
|
+
return false;
|
|
1309
|
+
}
|
|
1310
|
+
const before = oldestSequenceRef.current;
|
|
1311
|
+
if (before === null) {
|
|
1312
|
+
oldestSequenceRef.current = null;
|
|
1313
|
+
hasOlderRef.current = false;
|
|
1314
|
+
setHasOlder(false);
|
|
1315
|
+
return false;
|
|
1316
|
+
}
|
|
1317
|
+
const generation = navigationGenerationRef.current;
|
|
1318
|
+
const isCurrent = () => ownsNavigation() && navigationGenerationRef.current === generation;
|
|
1319
|
+
loadingOlderRef.current = true;
|
|
1320
|
+
setLoadingOlder(true);
|
|
1321
|
+
let published = false;
|
|
1322
|
+
try {
|
|
1323
|
+
const window2 = await loadEventWindow(t, client, workspaceId, sessionId, {
|
|
1324
|
+
before,
|
|
1325
|
+
pageSize: SESSION_HISTORY_PAGE_SIZE,
|
|
1326
|
+
targetGroups: OLDER_GROUP_TARGET,
|
|
1327
|
+
maxFetches: OLDER_FETCH_CAP,
|
|
1328
|
+
filteredPageCap: FILTERED_PAGE_CAP,
|
|
1329
|
+
isCurrent,
|
|
1330
|
+
filter: historyFilter
|
|
1331
|
+
});
|
|
1332
|
+
if (!isCurrent()) {
|
|
1333
|
+
return false;
|
|
1334
|
+
}
|
|
1335
|
+
if (window2.events.length === 0) {
|
|
1336
|
+
if (window2.hasOlder && window2.scanCursor < before) {
|
|
1337
|
+
oldestSequenceRef.current = window2.scanCursor;
|
|
1338
|
+
return true;
|
|
1339
|
+
}
|
|
1340
|
+
oldestSequenceRef.current = null;
|
|
1341
|
+
hasOlderRef.current = false;
|
|
1342
|
+
setHasOlder(false);
|
|
1343
|
+
return false;
|
|
1344
|
+
}
|
|
1345
|
+
const current = eventWindowRef.current;
|
|
1346
|
+
assertPrependOrder(current.events, window2.events);
|
|
1347
|
+
const next = boundBrowserSessionEventWindow([...window2.events, ...current.events], {
|
|
1348
|
+
direction: "oldest"
|
|
1349
|
+
});
|
|
1350
|
+
if (preserveTail && maxResumeSequence(next.events) < maxResumeSequence(current.events)) {
|
|
1351
|
+
markTailPreserved();
|
|
1352
|
+
return false;
|
|
1353
|
+
}
|
|
1354
|
+
const status = observeSessionStatus(window2.events, sessionStatusRef);
|
|
1355
|
+
const retained = {
|
|
1356
|
+
...next,
|
|
1357
|
+
truncated: current.truncated || next.truncated
|
|
1358
|
+
};
|
|
1359
|
+
const retainedOldest = retained.events[0]?.sequence ?? null;
|
|
1360
|
+
if (retainedOldest === null || retainedOldest >= before) {
|
|
1361
|
+
throw new Error("@opengeni/react: loadOlder made no durable sequence progress");
|
|
1362
|
+
}
|
|
1363
|
+
const retainedNewest = maxResumeSequenceOrNull(retained.events);
|
|
1364
|
+
const previousNewest = maxResumeSequenceOrNull(current.events);
|
|
1365
|
+
const evictedLiveTail = previousNewest !== null && retainedNewest !== null && retainedNewest < previousNewest;
|
|
1366
|
+
if (evictedLiveTail && viewModeRef.current === "live") {
|
|
1367
|
+
streamAbortRef.current?.abort();
|
|
1368
|
+
}
|
|
1369
|
+
eventWindowRef.current = retained;
|
|
1370
|
+
if (evictedLiveTail) {
|
|
1371
|
+
skippedStepsThroughRef.current = null;
|
|
1372
|
+
pruneStepStores(retained.events, current.events);
|
|
1373
|
+
} else {
|
|
1374
|
+
const skippedThrough = skippedStepsThroughRef.current;
|
|
1375
|
+
if (skippedThrough !== null && windowTurns(window2.events).size > 0) {
|
|
1376
|
+
skippedStepsThroughRef.current = null;
|
|
1377
|
+
const working = activeConversationTurn(retained.events);
|
|
1378
|
+
const bounds = working ? conversationTurnBounds(retained.events).get(working) : void 0;
|
|
1379
|
+
if (working && bounds && bounds.first <= skippedThrough) {
|
|
1380
|
+
loadTurnStepsRef.current(working, skippedThrough + 1);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
markCommitted();
|
|
1385
|
+
oldestSequenceRef.current = retainedOldest;
|
|
1386
|
+
newestSequenceRef.current = retainedNewest;
|
|
1387
|
+
if (evictedLiveTail) {
|
|
1388
|
+
streamResumeSequenceRef.current = maxResumeSequence(retained.events);
|
|
1389
|
+
}
|
|
1390
|
+
const olderStillAvailable = window2.hasOlder;
|
|
1391
|
+
hasOlderRef.current = olderStillAvailable;
|
|
1392
|
+
let newer = null;
|
|
1393
|
+
let enterHistory = false;
|
|
1394
|
+
if (viewModeRef.current === "history" || evictedLiveTail) {
|
|
1395
|
+
const highWater = lastSequenceRef.current;
|
|
1396
|
+
newer = retainedNewest !== null && (retainedNewest < highWater || retained.truncated);
|
|
1397
|
+
hasNewerRef.current = newer;
|
|
1398
|
+
if (evictedLiveTail) {
|
|
1399
|
+
viewModeRef.current = "history";
|
|
1400
|
+
enterHistory = true;
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
loadingOlderRef.current = false;
|
|
1404
|
+
startTransition(() => {
|
|
1405
|
+
if (status !== void 0) {
|
|
1406
|
+
setSessionStatusProjection(status);
|
|
1407
|
+
}
|
|
1408
|
+
setEventWindow(retained);
|
|
1409
|
+
setHasOlder(olderStillAvailable);
|
|
1410
|
+
if (newer !== null) {
|
|
1411
|
+
setHasNewer(newer);
|
|
1412
|
+
}
|
|
1413
|
+
if (enterHistory) {
|
|
1414
|
+
setViewMode("history");
|
|
1415
|
+
}
|
|
1416
|
+
setLoadingOlder(false);
|
|
1417
|
+
});
|
|
1418
|
+
published = true;
|
|
1419
|
+
return olderStillAvailable;
|
|
1420
|
+
} catch (reason) {
|
|
1421
|
+
if (!isCurrent()) return false;
|
|
1422
|
+
throw reason;
|
|
1423
|
+
} finally {
|
|
1424
|
+
if (!published && isCurrent()) {
|
|
1425
|
+
loadingOlderRef.current = false;
|
|
1426
|
+
setLoadingOlder(false);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
}),
|
|
1430
|
+
[client, workspaceId, sessionId, ownsNavigation, t, historyFilter, pruneStepStores]
|
|
1431
|
+
);
|
|
1432
|
+
const loadOldest = useCallback3(async () => {
|
|
1433
|
+
if (!ownsNavigation() || !sessionId || navigationBusy() || !hasOlderRef.current) {
|
|
1434
|
+
return false;
|
|
1435
|
+
}
|
|
1436
|
+
const generation = ++navigationGenerationRef.current;
|
|
1437
|
+
const isCurrent = () => ownsNavigation() && navigationGenerationRef.current === generation;
|
|
1438
|
+
setQuestionEvidence(null);
|
|
1439
|
+
loadingOldestRef.current = true;
|
|
1440
|
+
setLoadingOldest(true);
|
|
1441
|
+
let published = false;
|
|
1442
|
+
try {
|
|
1443
|
+
const window2 = await loadForwardEventWindow(t, client, workspaceId, sessionId, {
|
|
1444
|
+
after: 0,
|
|
1445
|
+
pageSize: SESSION_HISTORY_PAGE_SIZE,
|
|
1446
|
+
targetGroups: OLDEST_GROUP_TARGET,
|
|
1447
|
+
maxFetches: OLDEST_FETCH_CAP,
|
|
1448
|
+
isCurrent,
|
|
1449
|
+
filter: historyFilter
|
|
1450
|
+
});
|
|
1451
|
+
if (!isCurrent()) {
|
|
1452
|
+
return false;
|
|
1453
|
+
}
|
|
1454
|
+
if (window2.events.length === 0) {
|
|
1455
|
+
hasOlderRef.current = false;
|
|
1456
|
+
setHasOlder(false);
|
|
1457
|
+
return false;
|
|
1458
|
+
}
|
|
1459
|
+
streamAbortRef.current?.abort();
|
|
1460
|
+
const status = observeSessionStatus(window2.events, sessionStatusRef);
|
|
1461
|
+
const retained = boundBrowserSessionEventWindow(window2.events, { direction: "oldest" });
|
|
1462
|
+
const retainedOldest = retained.events[0]?.sequence ?? null;
|
|
1463
|
+
const retainedNewest = maxResumeSequenceOrNull(retained.events);
|
|
1464
|
+
const previous = eventWindowRef.current.events;
|
|
1465
|
+
eventWindowRef.current = retained;
|
|
1466
|
+
skippedStepsThroughRef.current = null;
|
|
1467
|
+
pruneStepStores(retained.events, previous);
|
|
1468
|
+
oldestSequenceRef.current = retainedOldest;
|
|
1469
|
+
newestSequenceRef.current = retainedNewest;
|
|
1470
|
+
hasOlderRef.current = false;
|
|
1471
|
+
const highWater = Math.max(lastSequenceRef.current, retainedNewest ?? 0);
|
|
1472
|
+
lastSequenceRef.current = highWater;
|
|
1473
|
+
const newer = window2.hasNewer || retained.truncated || retainedNewest !== null && retainedNewest < highWater;
|
|
1474
|
+
hasNewerRef.current = newer;
|
|
1475
|
+
initialWindowLoadedRef.current = true;
|
|
1476
|
+
setInitialHistoryReady(true);
|
|
1477
|
+
setError(null);
|
|
1478
|
+
viewModeRef.current = "history";
|
|
1479
|
+
loadingOldestRef.current = false;
|
|
1480
|
+
setNewerError(null);
|
|
1481
|
+
startTransition(() => {
|
|
1482
|
+
if (status !== void 0) {
|
|
1483
|
+
setSessionStatusProjection(status);
|
|
1484
|
+
}
|
|
1485
|
+
setEventWindow(retained);
|
|
1486
|
+
setHasOlder(false);
|
|
1487
|
+
setHasNewer(newer);
|
|
1488
|
+
setViewMode("history");
|
|
1489
|
+
setLoadingOldest(false);
|
|
1490
|
+
});
|
|
1491
|
+
published = true;
|
|
1492
|
+
return newer;
|
|
1493
|
+
} catch (reason) {
|
|
1494
|
+
if (!isCurrent()) return false;
|
|
1495
|
+
throw reason;
|
|
1496
|
+
} finally {
|
|
1497
|
+
if (!published && isCurrent()) {
|
|
1498
|
+
loadingOldestRef.current = false;
|
|
1499
|
+
setLoadingOldest(false);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}, [client, workspaceId, sessionId, ownsNavigation, t, historyFilter, pruneStepStores]);
|
|
1503
|
+
const loadNewer = useCallback3(async () => {
|
|
1504
|
+
if (!ownsNavigation() || !sessionId || navigationBusy() || !hasNewerRef.current) {
|
|
1505
|
+
return false;
|
|
1506
|
+
}
|
|
1507
|
+
const afterSequence = newestSequenceRef.current;
|
|
1508
|
+
if (afterSequence === null) {
|
|
1509
|
+
hasNewerRef.current = false;
|
|
1510
|
+
setHasNewer(false);
|
|
1511
|
+
return false;
|
|
1512
|
+
}
|
|
1513
|
+
const generation = navigationGenerationRef.current;
|
|
1514
|
+
const isCurrent = () => ownsNavigation() && navigationGenerationRef.current === generation;
|
|
1515
|
+
loadingNewerRef.current = true;
|
|
1516
|
+
setLoadingNewer(true);
|
|
1517
|
+
let published = false;
|
|
1518
|
+
try {
|
|
1519
|
+
const window2 = await loadForwardEventWindow(t, client, workspaceId, sessionId, {
|
|
1520
|
+
after: afterSequence,
|
|
1521
|
+
pageSize: SESSION_HISTORY_PAGE_SIZE,
|
|
1522
|
+
targetGroups: NEWER_GROUP_TARGET,
|
|
1523
|
+
maxFetches: NEWER_FETCH_CAP,
|
|
1524
|
+
filteredPageCap: FILTERED_PAGE_CAP,
|
|
1525
|
+
isCurrent,
|
|
1526
|
+
filter: historyFilter
|
|
1527
|
+
});
|
|
1528
|
+
if (!isCurrent()) {
|
|
1529
|
+
return false;
|
|
1530
|
+
}
|
|
1531
|
+
if (window2.events.length === 0) {
|
|
1532
|
+
if (window2.hasNewer && window2.scanCursor > afterSequence) {
|
|
1533
|
+
newestSequenceRef.current = window2.scanCursor;
|
|
1534
|
+
return true;
|
|
1535
|
+
}
|
|
1536
|
+
setNewerError(null);
|
|
1537
|
+
hasNewerRef.current = false;
|
|
1538
|
+
setHasNewer(false);
|
|
1539
|
+
streamResumeSequenceRef.current = afterSequence;
|
|
1540
|
+
rejoinPendingRef.current = true;
|
|
1541
|
+
viewModeRef.current = "live";
|
|
1542
|
+
setViewMode("live");
|
|
1543
|
+
setStreamEpoch((epoch) => epoch + 1);
|
|
1544
|
+
return false;
|
|
1545
|
+
}
|
|
1546
|
+
const current = eventWindowRef.current;
|
|
1547
|
+
assertAppendOrder(current.events, window2.events);
|
|
1548
|
+
const status = observeSessionStatus(window2.events, sessionStatusRef);
|
|
1549
|
+
const previousOldest = current.events[0]?.sequence ?? null;
|
|
1550
|
+
const next = appendBrowserSessionEventWindow(current, window2.events);
|
|
1551
|
+
const retained = {
|
|
1552
|
+
...next,
|
|
1553
|
+
truncated: current.truncated || next.truncated || window2.hasNewer
|
|
1554
|
+
};
|
|
1555
|
+
const retainedOldest = retained.events[0]?.sequence ?? null;
|
|
1556
|
+
const retainedNewest = maxResumeSequenceOrNull(retained.events);
|
|
1557
|
+
if (retainedNewest === null || retainedNewest <= afterSequence) {
|
|
1558
|
+
throw new Error("@opengeni/react: loadNewer made no durable sequence progress");
|
|
1559
|
+
}
|
|
1560
|
+
eventWindowRef.current = retained;
|
|
1561
|
+
pruneStepStores(retained.events, null);
|
|
1562
|
+
oldestSequenceRef.current = retainedOldest;
|
|
1563
|
+
newestSequenceRef.current = retainedNewest;
|
|
1564
|
+
if (retainedOldest !== null && (previousOldest === null || retainedOldest > previousOldest || retained.truncated && retained.events[0]?.type !== "session.created" && retainedOldest > 1)) {
|
|
1565
|
+
hasOlderRef.current = true;
|
|
1566
|
+
}
|
|
1567
|
+
const rearmedOlder = hasOlderRef.current;
|
|
1568
|
+
const highWater = Math.max(lastSequenceRef.current, retainedNewest);
|
|
1569
|
+
lastSequenceRef.current = highWater;
|
|
1570
|
+
const newer = window2.hasNewer || retainedNewest < highWater;
|
|
1571
|
+
hasNewerRef.current = newer;
|
|
1572
|
+
let resumeLive = false;
|
|
1573
|
+
if (!newer) {
|
|
1574
|
+
streamResumeSequenceRef.current = retainedNewest;
|
|
1575
|
+
rejoinPendingRef.current = true;
|
|
1576
|
+
viewModeRef.current = "live";
|
|
1577
|
+
resumeLive = true;
|
|
1578
|
+
}
|
|
1579
|
+
loadingNewerRef.current = false;
|
|
1580
|
+
setNewerError(null);
|
|
1581
|
+
startTransition(() => {
|
|
1582
|
+
if (status !== void 0) {
|
|
1583
|
+
setSessionStatusProjection(status);
|
|
1584
|
+
}
|
|
1585
|
+
setEventWindow(retained);
|
|
1586
|
+
setHasOlder(rearmedOlder);
|
|
1587
|
+
setHasNewer(newer);
|
|
1588
|
+
if (resumeLive) {
|
|
1589
|
+
setViewMode("live");
|
|
1590
|
+
setStreamEpoch((epoch) => epoch + 1);
|
|
1591
|
+
}
|
|
1592
|
+
setLoadingNewer(false);
|
|
1593
|
+
});
|
|
1594
|
+
published = true;
|
|
1595
|
+
return newer;
|
|
1596
|
+
} catch (reason) {
|
|
1597
|
+
if (!isCurrent()) {
|
|
1598
|
+
return false;
|
|
1599
|
+
}
|
|
1600
|
+
setNewerError(normalizeError(reason));
|
|
1601
|
+
throw reason;
|
|
1602
|
+
} finally {
|
|
1603
|
+
if (!published && isCurrent()) {
|
|
1604
|
+
loadingNewerRef.current = false;
|
|
1605
|
+
setLoadingNewer(false);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}, [client, workspaceId, sessionId, ownsNavigation, t, historyFilter, pruneStepStores]);
|
|
1609
|
+
const jumpToSequence = useCallback3(
|
|
1610
|
+
async (sequence, navigationOptions) => {
|
|
1611
|
+
const signal = navigationOptions?.signal;
|
|
1612
|
+
if (!ownsNavigation() || !sessionId || !Number.isSafeInteger(sequence) || sequence < 1)
|
|
1613
|
+
return false;
|
|
1614
|
+
if (signal?.aborted) return false;
|
|
1615
|
+
const generation = ++navigationGenerationRef.current;
|
|
1616
|
+
setQuestionEvidence(null);
|
|
1617
|
+
const current = () => generation === navigationGenerationRef.current && ownsNavigation();
|
|
1618
|
+
const previousMode = viewModeRef.current;
|
|
1619
|
+
streamAbortRef.current?.abort();
|
|
1620
|
+
generationRef.current += 1;
|
|
1621
|
+
viewModeRef.current = "history";
|
|
1622
|
+
setViewMode("history");
|
|
1623
|
+
loadingOlderRef.current = loadingNewerRef.current = loadingOldestRef.current = false;
|
|
1624
|
+
setLoadingOlder(false);
|
|
1625
|
+
setLoadingNewer(false);
|
|
1626
|
+
setLoadingOldest(false);
|
|
1627
|
+
loadingTargetRef.current = true;
|
|
1628
|
+
setLoadingTarget(true);
|
|
1629
|
+
let published = false;
|
|
1630
|
+
try {
|
|
1631
|
+
const around = (filter) => Promise.all([
|
|
1632
|
+
loadPreviousPage(client, workspaceId, sessionId, sequence + 1, {
|
|
1633
|
+
pageSize: 128,
|
|
1634
|
+
filter
|
|
1635
|
+
}),
|
|
1636
|
+
loadNextPage(client, workspaceId, sessionId, sequence, { pageSize: 128, filter })
|
|
1637
|
+
]);
|
|
1638
|
+
let [before, following] = await around(historyFilter);
|
|
1639
|
+
if (historyFilter && current() && !before.some((event) => event.sequence === sequence)) {
|
|
1640
|
+
[before, following] = await around(void 0);
|
|
1641
|
+
}
|
|
1642
|
+
if (signal?.aborted) return false;
|
|
1643
|
+
if (!current()) return false;
|
|
1644
|
+
if (!before.some((event) => event.sequence === sequence)) return false;
|
|
1645
|
+
const prefix = boundBrowserSessionEventWindow(before, {
|
|
1646
|
+
direction: "newest",
|
|
1647
|
+
maxBytes: SESSION_EVENT_BROWSER_MAX_BYTES / 2
|
|
1648
|
+
});
|
|
1649
|
+
const retained = boundBrowserSessionEventWindow([...prefix.events, ...following], {
|
|
1650
|
+
direction: "oldest"
|
|
1651
|
+
});
|
|
1652
|
+
if (!retained.events.some((event) => event.sequence === sequence)) return false;
|
|
1653
|
+
streamAbortRef.current?.abort();
|
|
1654
|
+
generationRef.current += 1;
|
|
1655
|
+
const status = observeSessionStatus(retained.events, sessionStatusRef);
|
|
1656
|
+
const previous = eventWindowRef.current.events;
|
|
1657
|
+
eventWindowRef.current = retained;
|
|
1658
|
+
pruneStepStores(retained.events, previous);
|
|
1659
|
+
oldestSequenceRef.current = retained.events[0].sequence;
|
|
1660
|
+
newestSequenceRef.current = maxResumeSequenceOrNull(retained.events);
|
|
1661
|
+
lastSequenceRef.current = Math.max(lastSequenceRef.current, newestSequenceRef.current ?? 0);
|
|
1662
|
+
hasOlderRef.current = !isLogStart(retained.events[0]);
|
|
1663
|
+
hasNewerRef.current = following.length > 0 || retained.truncated || (newestSequenceRef.current ?? 0) < lastSequenceRef.current;
|
|
1664
|
+
initialWindowLoadedRef.current = true;
|
|
1665
|
+
setInitialHistoryReady(true);
|
|
1666
|
+
setError(null);
|
|
1667
|
+
viewModeRef.current = "history";
|
|
1668
|
+
setEventWindow(retained);
|
|
1669
|
+
setHasOlder(hasOlderRef.current);
|
|
1670
|
+
setHasNewer(hasNewerRef.current);
|
|
1671
|
+
setInitialLoading(false);
|
|
1672
|
+
setViewMode("history");
|
|
1673
|
+
setNewerError(null);
|
|
1674
|
+
if (status !== void 0) setSessionStatusProjection(status);
|
|
1675
|
+
published = true;
|
|
1676
|
+
return true;
|
|
1677
|
+
} catch (reason) {
|
|
1678
|
+
if (!current() || signal?.aborted) return false;
|
|
1679
|
+
throw reason;
|
|
1680
|
+
} finally {
|
|
1681
|
+
if (current()) {
|
|
1682
|
+
loadingTargetRef.current = false;
|
|
1683
|
+
setLoadingTarget(false);
|
|
1684
|
+
if (!published && previousMode === "live") {
|
|
1685
|
+
viewModeRef.current = "live";
|
|
1686
|
+
setViewMode("live");
|
|
1687
|
+
setStreamEpoch((epoch) => epoch + 1);
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
},
|
|
1692
|
+
[client, workspaceId, sessionId, ownsNavigation, historyFilter, pruneStepStores]
|
|
1693
|
+
);
|
|
1694
|
+
const jumpToLatestQuestion = useCallback3(
|
|
1695
|
+
async (questionOptions) => {
|
|
1696
|
+
if (!sessionId || !ownsNavigation()) return null;
|
|
1697
|
+
let generation = navigationGenerationRef.current;
|
|
1698
|
+
const current = () => ownsNavigation() && generation === navigationGenerationRef.current;
|
|
1699
|
+
try {
|
|
1700
|
+
const { resolveLatestQuestion } = await import("./latest-question-QWJTXMFA.js");
|
|
1701
|
+
if (!current()) return null;
|
|
1702
|
+
const destination = await resolveLatestQuestion(t, {
|
|
1703
|
+
client,
|
|
1704
|
+
workspaceId,
|
|
1705
|
+
sessionId,
|
|
1706
|
+
isCurrent: current,
|
|
1707
|
+
resumeSequence: maxResumeSequence,
|
|
1708
|
+
options: questionOptions
|
|
1709
|
+
});
|
|
1710
|
+
if (!destination || !current()) return null;
|
|
1711
|
+
if (!eventWindowRef.current.events.some((event) => event.sequence === destination.anchor)) {
|
|
1712
|
+
const navigation = jumpToSequence(destination.anchor);
|
|
1713
|
+
generation = navigationGenerationRef.current;
|
|
1714
|
+
if (!await navigation || !current()) return null;
|
|
1715
|
+
}
|
|
1716
|
+
setQuestionEvidence({
|
|
1717
|
+
client,
|
|
1718
|
+
streamKey,
|
|
1719
|
+
anchor: destination.anchor,
|
|
1720
|
+
events: destination.events
|
|
1721
|
+
});
|
|
1722
|
+
return destination.questionSequence;
|
|
1723
|
+
} catch (reason) {
|
|
1724
|
+
if (!current()) return null;
|
|
1725
|
+
throw reason;
|
|
1726
|
+
}
|
|
1727
|
+
},
|
|
1728
|
+
[client, workspaceId, sessionId, streamKey, ownsNavigation, jumpToSequence, t]
|
|
1729
|
+
);
|
|
1730
|
+
const jumpToLatest = useCallback3(async () => {
|
|
1731
|
+
if (!ownsNavigation()) return;
|
|
1732
|
+
if (loadingTargetRef.current) {
|
|
1733
|
+
navigationGenerationRef.current += 1;
|
|
1734
|
+
loadingTargetRef.current = false;
|
|
1735
|
+
setLoadingTarget(false);
|
|
1736
|
+
}
|
|
1737
|
+
if (!sessionId || navigationBusy()) {
|
|
1738
|
+
return;
|
|
1739
|
+
}
|
|
1740
|
+
navigationGenerationRef.current += 1;
|
|
1741
|
+
setQuestionEvidence(null);
|
|
1742
|
+
loadingLatestRef.current = true;
|
|
1743
|
+
setLoadingLatest(true);
|
|
1744
|
+
setNewerError(null);
|
|
1745
|
+
setError(null);
|
|
1746
|
+
let published = false;
|
|
1747
|
+
try {
|
|
1748
|
+
streamAbortRef.current?.abort();
|
|
1749
|
+
hasNewerRef.current = false;
|
|
1750
|
+
hasOlderRef.current = false;
|
|
1751
|
+
newestSequenceRef.current = null;
|
|
1752
|
+
oldestSequenceRef.current = null;
|
|
1753
|
+
eventWindowRef.current = EMPTY_EVENT_WINDOW;
|
|
1754
|
+
initialWindowLoadedRef.current = false;
|
|
1755
|
+
streamResumeSequenceRef.current = after;
|
|
1756
|
+
viewModeRef.current = "live";
|
|
1757
|
+
loadingLatestRef.current = false;
|
|
1758
|
+
startTransition(() => {
|
|
1759
|
+
setHasNewer(false);
|
|
1760
|
+
setHasOlder(false);
|
|
1761
|
+
setEventWindow(EMPTY_EVENT_WINDOW);
|
|
1762
|
+
setInitialLoading(true);
|
|
1763
|
+
setViewMode("live");
|
|
1764
|
+
setStreamEpoch((epoch) => epoch + 1);
|
|
1765
|
+
setLoadingLatest(false);
|
|
1766
|
+
});
|
|
1767
|
+
published = true;
|
|
1768
|
+
await Promise.resolve();
|
|
1769
|
+
} finally {
|
|
1770
|
+
if (!published) {
|
|
1771
|
+
loadingLatestRef.current = false;
|
|
1772
|
+
setLoadingLatest(false);
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
}, [after, sessionId, ownsNavigation]);
|
|
1776
|
+
const identityMatches = stateStreamKey === streamKey;
|
|
1777
|
+
const freshTail = identityMatches && initialHistoryReady && viewMode === "live" && !fullReplay ? {
|
|
1778
|
+
events: eventWindow.events,
|
|
1779
|
+
hasOlder,
|
|
1780
|
+
truncated: eventWindow.truncated,
|
|
1781
|
+
bytes: eventWindow.bytes,
|
|
1782
|
+
sessionStatus: sessionStatusProjection
|
|
1783
|
+
} : null;
|
|
1784
|
+
const retainedTail = useRetainedSessionView(client, workspaceId, sessionId, "events", freshTail, {
|
|
1785
|
+
enabled: !fullReplay,
|
|
1786
|
+
bytes: (tail) => tail.bytes,
|
|
1787
|
+
budgetBytes: SESSION_EVENT_BROWSER_MAX_BYTES,
|
|
1788
|
+
discard: identityMatches && deniesRetainedView(error)
|
|
1789
|
+
});
|
|
1790
|
+
const showRetained = retainedTail !== null && !(identityMatches && initialHistoryReady);
|
|
1791
|
+
const visibleEvents = showRetained ? retainedTail.events : identityMatches ? eventWindow.events : EMPTY_EVENTS;
|
|
1792
|
+
const visibleHasOlder = showRetained ? retainedTail.hasOlder : identityMatches && hasOlder;
|
|
1793
|
+
const visibleTruncated = showRetained ? retainedTail.truncated : eventWindow.truncated;
|
|
1794
|
+
const liveSteps = identityMatches && !showRetained;
|
|
1795
|
+
const visibleStepStores = liveSteps ? stepStores : EMPTY_STEP_STORES;
|
|
1796
|
+
const visiblePresentedOutputs = liveSteps ? presentedOutputs : EMPTY_PRESENTED_OUTPUTS;
|
|
1797
|
+
const visibleTurnless = liveSteps ? turnlessSteps : EMPTY_TURNLESS_STEPS;
|
|
1798
|
+
const readToolOutput = useCallback3(
|
|
1799
|
+
async (sequence) => sessionId ? (await readEventPage(client, workspaceId, sessionId, {
|
|
1800
|
+
includeTypes: ["agent.toolCall.output"],
|
|
1801
|
+
after: Math.max(0, sequence - 1),
|
|
1802
|
+
before: sequence + 1,
|
|
1803
|
+
direction: "after",
|
|
1804
|
+
limit: 1,
|
|
1805
|
+
payloadMode: "full"
|
|
1806
|
+
})).events : [],
|
|
1807
|
+
[client, workspaceId, sessionId]
|
|
1808
|
+
);
|
|
1809
|
+
const toolOutputs = useToolOutputReads(readToolOutput, stepStores);
|
|
1810
|
+
const visibleToolOutputs = liveSteps ? toolOutputs.exact : EMPTY_PRESENTED_OUTPUTS;
|
|
1811
|
+
const loadedEvents = useMemo2(
|
|
1812
|
+
() => mergeLoadedEvents(
|
|
1813
|
+
visibleEvents,
|
|
1814
|
+
visibleStepStores,
|
|
1815
|
+
visiblePresentedOutputs,
|
|
1816
|
+
visibleTurnless.events,
|
|
1817
|
+
visibleToolOutputs
|
|
1818
|
+
),
|
|
1819
|
+
[
|
|
1820
|
+
visibleEvents,
|
|
1821
|
+
visibleStepStores,
|
|
1822
|
+
visiblePresentedOutputs,
|
|
1823
|
+
visibleTurnless,
|
|
1824
|
+
visibleToolOutputs
|
|
1825
|
+
]
|
|
1826
|
+
);
|
|
1827
|
+
const turnSteps = useMemo2(() => {
|
|
1828
|
+
if (fullReplay) return void 0;
|
|
1829
|
+
const markers = /* @__PURE__ */ new Map();
|
|
1830
|
+
const bounded = withTurnlessSteps(visibleEvents, visibleTurnless);
|
|
1831
|
+
for (const [turnId, bounds] of conversationTurnBounds(bounded)) {
|
|
1832
|
+
const store = visibleStepStores.get(turnId);
|
|
1833
|
+
if (store && !store.loading && !store.error && !stepStoreHasOlder(store, bounds)) {
|
|
1834
|
+
if (!store.events.some((event) => CONTENT_STEP_TYPES.has(event.type))) continue;
|
|
1835
|
+
}
|
|
1836
|
+
const state = store ? store.loading ? "loading" : store.error ? "error" : stepStoreHasOlder(store, bounds) ? "partial" : "complete" : bounds.hidden ? "idle" : null;
|
|
1837
|
+
if (state === null) continue;
|
|
1838
|
+
markers.set(turnId, { state, ...liveSteps ? turnStepHandle(turnId) : RETAINED_VIEW_STEPS });
|
|
1839
|
+
}
|
|
1840
|
+
return markers;
|
|
1841
|
+
}, [fullReplay, visibleEvents, visibleTurnless, visibleStepStores, liveSteps, turnStepHandle]);
|
|
1842
|
+
const timeline = useMemo2(() => {
|
|
1843
|
+
const witness = questionEvidence?.client === client && questionEvidence.streamKey === streamKey && visibleEvents.some((event) => event.sequence === questionEvidence.anchor) ? questionEvidence.events : EMPTY_EVENTS;
|
|
1844
|
+
const timelineOptions = {
|
|
1845
|
+
partialStart: visibleHasOlder || visibleTruncated || after > 0,
|
|
1846
|
+
...turnSteps ? { turnSteps } : {},
|
|
1847
|
+
...liveSteps ? { toolOutputs: toolOutputs.reader } : {}
|
|
1848
|
+
};
|
|
1849
|
+
if (witness.length === 0) return buildTimeline(t, loadedEvents, timelineOptions);
|
|
1850
|
+
const ids = new Set(loadedEvents.map((event) => event.id));
|
|
1851
|
+
return buildTimeline(
|
|
1852
|
+
t,
|
|
1853
|
+
[...loadedEvents, ...witness.filter((event) => !ids.has(event.id))],
|
|
1854
|
+
timelineOptions
|
|
1855
|
+
);
|
|
1856
|
+
}, [
|
|
1857
|
+
loadedEvents,
|
|
1858
|
+
visibleEvents,
|
|
1859
|
+
visibleHasOlder,
|
|
1860
|
+
visibleTruncated,
|
|
1861
|
+
after,
|
|
1862
|
+
questionEvidence,
|
|
1863
|
+
client,
|
|
1864
|
+
streamKey,
|
|
1865
|
+
turnSteps,
|
|
1866
|
+
liveSteps,
|
|
1867
|
+
toolOutputs.reader,
|
|
1868
|
+
t
|
|
1869
|
+
]);
|
|
1870
|
+
useEffect2(() => {
|
|
1871
|
+
if (fullReplay || !sessionId || !identityMatches || !initialHistoryReady) return;
|
|
1872
|
+
const resolved = new Set(presentedOutputs.keys());
|
|
1873
|
+
const collect = (events) => {
|
|
1874
|
+
for (const event of events) {
|
|
1875
|
+
if (event.type !== "agent.toolCall.output" || isToolOutputPreviewEvent(event)) continue;
|
|
1876
|
+
const id = event.payload?.id;
|
|
1877
|
+
if (typeof id === "string") resolved.add(id);
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
collect(eventWindow.events);
|
|
1881
|
+
for (const store of stepStores.values()) collect(store.events);
|
|
1882
|
+
const requested = presentedRequestedRef.current;
|
|
1883
|
+
let inFlight = 0;
|
|
1884
|
+
for (const request of requested.values()) if (request.pending) inFlight += 1;
|
|
1885
|
+
const room = PRESENTED_OUTPUT_READS_PER_PASS - inFlight;
|
|
1886
|
+
if (room <= 0) return;
|
|
1887
|
+
const missing = [];
|
|
1888
|
+
for (const event of eventWindow.events) {
|
|
1889
|
+
if (event.type !== "agent.toolCall.created") continue;
|
|
1890
|
+
const payload = event.payload;
|
|
1891
|
+
const callId = payload?.id;
|
|
1892
|
+
if (typeof callId !== "string" || resolved.has(callId) || requested.has(callId) || !isPresentedSessionToolCall(payload)) {
|
|
1893
|
+
continue;
|
|
1894
|
+
}
|
|
1895
|
+
missing.push({ callId, sequence: event.sequence, turnId: event.turnId ?? null });
|
|
1896
|
+
}
|
|
1897
|
+
if (missing.length === 0) return;
|
|
1898
|
+
const bounds = conversationTurnBounds(eventWindow.events);
|
|
1899
|
+
for (const { callId, sequence, turnId } of missing.slice(-room)) {
|
|
1900
|
+
const request = { turnId, pending: true };
|
|
1901
|
+
requested.set(callId, request);
|
|
1902
|
+
const isCurrent = () => presentedRequestedRef.current === requested && requested.get(callId) === request;
|
|
1903
|
+
const terminal = turnId ? bounds.get(turnId)?.terminal ?? null : null;
|
|
1904
|
+
void findPresentedOutput(client, workspaceId, sessionId, callId, sequence, terminal).then(
|
|
1905
|
+
(output) => {
|
|
1906
|
+
if (!ownsNavigation() || !isCurrent()) return;
|
|
1907
|
+
request.pending = false;
|
|
1908
|
+
if (output) setPresentedOutputs((current) => new Map(current).set(callId, output));
|
|
1909
|
+
setPresentedPass((pass) => pass + 1);
|
|
1910
|
+
},
|
|
1911
|
+
() => {
|
|
1912
|
+
if (!isCurrent()) return;
|
|
1913
|
+
requested.delete(callId);
|
|
1914
|
+
const failures = (presentedFailuresRef.current.get(callId) ?? 0) + 1;
|
|
1915
|
+
presentedFailuresRef.current.set(callId, failures);
|
|
1916
|
+
if (failures > PRESENTED_OUTPUT_RETRIES) return;
|
|
1917
|
+
setTimeout(() => {
|
|
1918
|
+
if (ownsNavigation()) setPresentedPass((pass) => pass + 1);
|
|
1919
|
+
}, PRESENTED_OUTPUT_RETRY_MS * failures);
|
|
1920
|
+
}
|
|
1921
|
+
);
|
|
1922
|
+
}
|
|
1923
|
+
}, [
|
|
1924
|
+
fullReplay,
|
|
1925
|
+
sessionId,
|
|
1926
|
+
identityMatches,
|
|
1927
|
+
initialHistoryReady,
|
|
1928
|
+
eventWindow,
|
|
1929
|
+
stepStores,
|
|
1930
|
+
presentedOutputs,
|
|
1931
|
+
presentedPass,
|
|
1932
|
+
client,
|
|
1933
|
+
workspaceId,
|
|
1934
|
+
ownsNavigation
|
|
1935
|
+
]);
|
|
1936
|
+
return {
|
|
1937
|
+
events: loadedEvents,
|
|
1938
|
+
timeline,
|
|
1939
|
+
sessionStatus: showRetained ? retainedTail.sessionStatus : identityMatches ? sessionStatusProjection : null,
|
|
1940
|
+
sessionStatusSequence: identityMatches ? sessionStatusRef.current.sequence : 0,
|
|
1941
|
+
connectionState: identityMatches ? connectionState : "idle",
|
|
1942
|
+
lastSequence: identityMatches ? lastSequenceRef.current : after,
|
|
1943
|
+
windowBytes: identityMatches ? eventWindow.bytes : 2,
|
|
1944
|
+
windowTruncated: identityMatches ? eventWindow.truncated : false,
|
|
1945
|
+
initialLoading: fullReplay || showRetained ? false : identityMatches ? initialLoading : true,
|
|
1946
|
+
initialHistoryReady: identityMatches && initialHistoryReady,
|
|
1947
|
+
hasOlder: visibleHasOlder,
|
|
1948
|
+
loadingOlder: !identityMatches ? false : loadingOlder,
|
|
1949
|
+
loadOlder,
|
|
1950
|
+
hasNewer: !identityMatches ? false : hasNewer,
|
|
1951
|
+
loadingNewer: !identityMatches ? false : loadingNewer,
|
|
1952
|
+
loadNewer,
|
|
1953
|
+
loadingOldest: !identityMatches ? false : loadingOldest,
|
|
1954
|
+
loadOldest,
|
|
1955
|
+
loadingLatest: !identityMatches ? false : loadingLatest,
|
|
1956
|
+
jumpToLatest,
|
|
1957
|
+
jumpToLatestQuestion,
|
|
1958
|
+
jumpToSequence,
|
|
1959
|
+
loadingTarget: identityMatches && loadingTarget,
|
|
1960
|
+
error: identityMatches ? newerError ?? error : null
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
function boundBrowserSessionEventWindow(events, options = {}) {
|
|
1964
|
+
const maxBytes = Math.max(1024, options.maxBytes ?? SESSION_EVENT_BROWSER_MAX_BYTES);
|
|
1965
|
+
const maxCount = Math.max(1, Math.floor(options.maxCount ?? SESSION_EVENT_BROWSER_MAX_COUNT));
|
|
1966
|
+
const safe = events;
|
|
1967
|
+
const selected = [];
|
|
1968
|
+
let bytes = 2;
|
|
1969
|
+
const direction = options.direction ?? "newest";
|
|
1970
|
+
const start = direction === "newest" ? safe.length - 1 : 0;
|
|
1971
|
+
const end = direction === "newest" ? Math.max(-1, safe.length - maxCount - 1) : safe.length;
|
|
1972
|
+
const step = direction === "newest" ? -1 : 1;
|
|
1973
|
+
for (let index = start; index !== end && selected.length < maxCount; index += step) {
|
|
1974
|
+
const event = safe[index];
|
|
1975
|
+
const eventBytes = browserJsonBytes(event);
|
|
1976
|
+
const separator = selected.length === 0 ? 0 : 1;
|
|
1977
|
+
if (selected.length > 0 && bytes + separator + eventBytes > maxBytes) break;
|
|
1978
|
+
selected.push(event);
|
|
1979
|
+
bytes += separator + eventBytes;
|
|
1980
|
+
}
|
|
1981
|
+
if (direction === "newest") selected.reverse();
|
|
1982
|
+
return {
|
|
1983
|
+
events: selected,
|
|
1984
|
+
bytes,
|
|
1985
|
+
truncated: selected.length < safe.length
|
|
1986
|
+
};
|
|
1987
|
+
}
|
|
1988
|
+
function appendBrowserSessionEventWindow(current, batch, options = {}) {
|
|
1989
|
+
const maxBytes = Math.max(1024, options.maxBytes ?? SESSION_EVENT_BROWSER_MAX_BYTES);
|
|
1990
|
+
const maxCount = Math.max(1, Math.floor(options.maxCount ?? SESSION_EVENT_BROWSER_MAX_COUNT));
|
|
1991
|
+
const events = [...current.events, ...batch];
|
|
1992
|
+
let bytes = current.bytes;
|
|
1993
|
+
for (let index = 0; index < batch.length; index += 1) {
|
|
1994
|
+
bytes += browserJsonBytes(batch[index]) + (current.events.length + index > 0 ? 1 : 0);
|
|
1995
|
+
}
|
|
1996
|
+
let start = 0;
|
|
1997
|
+
while (events.length - start > 1 && (bytes > maxBytes || events.length - start > maxCount)) {
|
|
1998
|
+
bytes -= browserJsonBytes(events[start]) + 1;
|
|
1999
|
+
start += 1;
|
|
2000
|
+
}
|
|
2001
|
+
return {
|
|
2002
|
+
events: start === 0 ? events : events.slice(start),
|
|
2003
|
+
bytes,
|
|
2004
|
+
truncated: current.truncated || start > 0
|
|
2005
|
+
};
|
|
2006
|
+
}
|
|
2007
|
+
function browserJsonBytes(value) {
|
|
2008
|
+
return encoder.encode(JSON.stringify(value)).byteLength;
|
|
2009
|
+
}
|
|
2010
|
+
function observeSessionStatus(events, ref) {
|
|
2011
|
+
let latest = null;
|
|
2012
|
+
for (const event of events) {
|
|
2013
|
+
const status = sessionStatusFromEvents([event]);
|
|
2014
|
+
if (status && (!latest || event.sequence >= latest.sequence)) {
|
|
2015
|
+
latest = { sequence: event.sequence, status };
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
if (!latest || latest.sequence < ref.current.sequence) return void 0;
|
|
2019
|
+
ref.current = latest;
|
|
2020
|
+
return latest.status;
|
|
2021
|
+
}
|
|
2022
|
+
async function loadConversationCatchup(client, workspaceId, sessionId, cursor, head, options) {
|
|
2023
|
+
const events = [];
|
|
2024
|
+
let after = cursor;
|
|
2025
|
+
for (let fetch = 0; fetch < CATCHUP_MAX_PAGES; fetch += 1) {
|
|
2026
|
+
if (options.signal?.aborted) throw abortError();
|
|
2027
|
+
const page = await readConversationPage(client, workspaceId, sessionId, {
|
|
2028
|
+
after,
|
|
2029
|
+
before: head + 1,
|
|
2030
|
+
direction: "after",
|
|
2031
|
+
limit: SESSION_HISTORY_PAGE_SIZE,
|
|
2032
|
+
compact: true,
|
|
2033
|
+
payloadMode: "full"
|
|
2034
|
+
});
|
|
2035
|
+
if (!options.isCurrent()) throw abortError();
|
|
2036
|
+
options.progress?.();
|
|
2037
|
+
const fresh = page.filter((event) => eventResumeSequence(event) > after);
|
|
2038
|
+
assertAscending(fresh);
|
|
2039
|
+
events.push(...fresh);
|
|
2040
|
+
if (page.raw.newest === null || page.raw.newest <= after) return events;
|
|
2041
|
+
after = page.raw.newest;
|
|
2042
|
+
if (after >= head || page.hasMore === false) return events;
|
|
2043
|
+
}
|
|
2044
|
+
return null;
|
|
2045
|
+
}
|
|
2046
|
+
async function loadEventWindow(t, client, workspaceId, sessionId, options) {
|
|
2047
|
+
let cursor = options.before;
|
|
2048
|
+
let buffer = [];
|
|
2049
|
+
let reachedStart = false;
|
|
2050
|
+
let fetches = 0;
|
|
2051
|
+
let filteredPages = 0;
|
|
2052
|
+
let rawNewest = 0;
|
|
2053
|
+
const counts = (page) => {
|
|
2054
|
+
rawNewest = Math.max(rawNewest, page.raw.newest ?? 0);
|
|
2055
|
+
return page.length > 0 || (filteredPages += 1) > (options.filteredPageCap ?? 0);
|
|
2056
|
+
};
|
|
2057
|
+
while (fetches < options.maxFetches) {
|
|
2058
|
+
if (buffer.length > 0 && groupCount(t, buffer) >= options.targetGroups) {
|
|
2059
|
+
break;
|
|
2060
|
+
}
|
|
2061
|
+
const page = await loadPreviousPage(client, workspaceId, sessionId, cursor, {
|
|
2062
|
+
pageSize: options.pageSize,
|
|
2063
|
+
filter: options.filter,
|
|
2064
|
+
...options.signal ? { signal: options.signal } : {}
|
|
2065
|
+
});
|
|
2066
|
+
if (options.isCurrent?.() === false) throw abortError();
|
|
2067
|
+
options.progress?.();
|
|
2068
|
+
if (page.raw.oldest === null) {
|
|
2069
|
+
reachedStart = true;
|
|
2070
|
+
break;
|
|
2071
|
+
}
|
|
2072
|
+
if (counts(page)) fetches += 1;
|
|
2073
|
+
assertAscending(page);
|
|
2074
|
+
buffer = [...page, ...buffer];
|
|
2075
|
+
cursor = page.raw.oldest;
|
|
2076
|
+
if (page.raw.oldest <= 1 || page[0] !== void 0 && isLogStart(page[0])) {
|
|
2077
|
+
reachedStart = true;
|
|
2078
|
+
break;
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
let snapPages = 0;
|
|
2082
|
+
while (!reachedStart && findBoundaryIndex(buffer) === -1 && snapPages < (options.boundaryPageCap ?? 0)) {
|
|
2083
|
+
const page = await loadPreviousPage(client, workspaceId, sessionId, cursor, {
|
|
2084
|
+
pageSize: options.pageSize,
|
|
2085
|
+
filter: options.filter,
|
|
2086
|
+
...options.signal ? { signal: options.signal } : {}
|
|
2087
|
+
});
|
|
2088
|
+
if (options.isCurrent?.() === false) throw abortError();
|
|
2089
|
+
options.progress?.();
|
|
2090
|
+
if (page.raw.oldest === null) {
|
|
2091
|
+
reachedStart = true;
|
|
2092
|
+
break;
|
|
2093
|
+
}
|
|
2094
|
+
if (counts(page)) {
|
|
2095
|
+
fetches += 1;
|
|
2096
|
+
snapPages += 1;
|
|
2097
|
+
}
|
|
2098
|
+
assertAscending(page);
|
|
2099
|
+
buffer = [...page, ...buffer];
|
|
2100
|
+
cursor = page.raw.oldest;
|
|
2101
|
+
if (page.raw.oldest <= 1 || page[0] !== void 0 && isLogStart(page[0])) {
|
|
2102
|
+
reachedStart = true;
|
|
2103
|
+
break;
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
if (!reachedStart) {
|
|
2107
|
+
const boundary = findBoundaryIndex(buffer);
|
|
2108
|
+
if (boundary > 0) {
|
|
2109
|
+
buffer = buffer.slice(boundary);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
const densityWindow = trimBackwardToGroupTarget(t, buffer, options.targetGroups);
|
|
2113
|
+
buffer = densityWindow.events;
|
|
2114
|
+
const oldest = buffer[0] ?? null;
|
|
2115
|
+
const newest = buffer[buffer.length - 1] ?? null;
|
|
2116
|
+
return {
|
|
2117
|
+
events: buffer,
|
|
2118
|
+
oldestSequence: oldest?.sequence ?? null,
|
|
2119
|
+
// A window that kept nothing resumes a live stream above the rows it read,
|
|
2120
|
+
// not at the start of history. Otherwise rows dropped above its newest
|
|
2121
|
+
// kept row are replayed (or caught up) into their turn's steps, so a
|
|
2122
|
+
// working turn's latest tool calls still show.
|
|
2123
|
+
newestSequence: newest ? maxResumeSequence(buffer) : rawNewest,
|
|
2124
|
+
// An empty window that stopped before the start is still pageable.
|
|
2125
|
+
hasOlder: buffer.length > 0 ? densityWindow.trimmed || !reachedStart && oldest?.type !== "session.created" : !reachedStart,
|
|
2126
|
+
scanCursor: cursor
|
|
2127
|
+
};
|
|
2128
|
+
}
|
|
2129
|
+
function findBoundaryIndex(events) {
|
|
2130
|
+
for (let index = 0; index < events.length; index += 1) {
|
|
2131
|
+
if (isTurnBoundary(events[index])) {
|
|
2132
|
+
return index;
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
return -1;
|
|
2136
|
+
}
|
|
2137
|
+
function isTurnBoundary(event) {
|
|
2138
|
+
return event.type === "session.created" || event.type === "user.message";
|
|
2139
|
+
}
|
|
2140
|
+
async function loadForwardEventWindow(t, client, workspaceId, sessionId, options) {
|
|
2141
|
+
let cursor = options.after;
|
|
2142
|
+
let buffer = [];
|
|
2143
|
+
let fetches = 0;
|
|
2144
|
+
let reachedEnd = false;
|
|
2145
|
+
let filteredPages = 0;
|
|
2146
|
+
while (fetches < options.maxFetches) {
|
|
2147
|
+
if (buffer.length > 0 && groupCount(t, buffer) >= options.targetGroups) {
|
|
2148
|
+
break;
|
|
2149
|
+
}
|
|
2150
|
+
const page = await loadNextPage(client, workspaceId, sessionId, cursor, {
|
|
2151
|
+
pageSize: options.pageSize,
|
|
2152
|
+
filter: options.filter,
|
|
2153
|
+
...options.signal ? { signal: options.signal } : {}
|
|
2154
|
+
});
|
|
2155
|
+
if (options.isCurrent?.() === false) throw abortError();
|
|
2156
|
+
if (page.raw.newest === null) {
|
|
2157
|
+
reachedEnd = true;
|
|
2158
|
+
break;
|
|
2159
|
+
}
|
|
2160
|
+
if (page.length > 0 || (filteredPages += 1) > (options.filteredPageCap ?? 0)) fetches += 1;
|
|
2161
|
+
assertAscending(page);
|
|
2162
|
+
buffer = [...buffer, ...page];
|
|
2163
|
+
cursor = page.raw.newest;
|
|
2164
|
+
}
|
|
2165
|
+
const densityWindow = trimForwardToGroupTarget(t, buffer, options.targetGroups);
|
|
2166
|
+
buffer = densityWindow.events;
|
|
2167
|
+
const oldest = buffer[0] ?? null;
|
|
2168
|
+
const newest = buffer[buffer.length - 1] ?? null;
|
|
2169
|
+
return {
|
|
2170
|
+
events: buffer,
|
|
2171
|
+
oldestSequence: oldest?.sequence ?? null,
|
|
2172
|
+
newestSequence: newest ? maxResumeSequence(buffer) : 0,
|
|
2173
|
+
// An empty window that stopped before the end is still pageable.
|
|
2174
|
+
hasNewer: buffer.length > 0 ? densityWindow.trimmed || !reachedEnd : !reachedEnd,
|
|
2175
|
+
scanCursor: cursor
|
|
2176
|
+
};
|
|
2177
|
+
}
|
|
2178
|
+
function trimBackwardToGroupTarget(t, events, targetGroups) {
|
|
2179
|
+
if (!Number.isFinite(targetGroups) || targetGroups <= 0 || events.length === 0) {
|
|
2180
|
+
return { events, trimmed: false };
|
|
2181
|
+
}
|
|
2182
|
+
for (let index = events.length - 1; index > 0; index -= 1) {
|
|
2183
|
+
if (!isTurnBoundary(events[index])) continue;
|
|
2184
|
+
const candidate = events.slice(index);
|
|
2185
|
+
if (groupCount(t, candidate) >= targetGroups) {
|
|
2186
|
+
return { events: candidate, trimmed: true };
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
return { events, trimmed: false };
|
|
2190
|
+
}
|
|
2191
|
+
function trimForwardToGroupTarget(t, events, targetGroups) {
|
|
2192
|
+
if (!Number.isFinite(targetGroups) || targetGroups <= 0 || events.length === 0) {
|
|
2193
|
+
return { events, trimmed: false };
|
|
2194
|
+
}
|
|
2195
|
+
for (let index = 1; index < events.length; index += 1) {
|
|
2196
|
+
if (!isTurnBoundary(events[index])) continue;
|
|
2197
|
+
const candidate = events.slice(0, index);
|
|
2198
|
+
if (groupCount(t, candidate) >= targetGroups) {
|
|
2199
|
+
return { events: candidate, trimmed: true };
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
return { events, trimmed: false };
|
|
2203
|
+
}
|
|
2204
|
+
function rawPageExtent(events) {
|
|
2205
|
+
return events.length === 0 ? { oldest: null, newest: null } : { oldest: events[0].sequence, newest: maxResumeSequence(events) };
|
|
2206
|
+
}
|
|
2207
|
+
function historyPage(events, requested, raw = rawPageExtent(events)) {
|
|
2208
|
+
return Object.assign(events, { requested, raw });
|
|
2209
|
+
}
|
|
2210
|
+
async function loadPreviousPage(client, workspaceId, sessionId, before, options) {
|
|
2211
|
+
if (options.signal?.aborted) {
|
|
2212
|
+
throw abortError();
|
|
2213
|
+
}
|
|
2214
|
+
const requested = options.pageSize;
|
|
2215
|
+
if (requested === 0) {
|
|
2216
|
+
return historyPage([], requested);
|
|
2217
|
+
}
|
|
2218
|
+
const read = {
|
|
2219
|
+
before,
|
|
2220
|
+
limit: requested,
|
|
2221
|
+
compact: true,
|
|
2222
|
+
// Monitoring summaries omit correlation fields once a bounded durable
|
|
2223
|
+
// payload exceeds their preview threshold. The browser timeline needs the
|
|
2224
|
+
// exact stored payload so persisted tool outputs still match their
|
|
2225
|
+
// calls and expose truthful truncation telemetry after a reload.
|
|
2226
|
+
payloadMode: "full"
|
|
2227
|
+
};
|
|
2228
|
+
const page = options.filter ? await readConversationPage(client, workspaceId, sessionId, read) : historyPage(await client.listEvents(workspaceId, sessionId, read), requested);
|
|
2229
|
+
if (options.signal?.aborted) {
|
|
2230
|
+
throw abortError();
|
|
2231
|
+
}
|
|
2232
|
+
return Object.assign(page, { requested });
|
|
2233
|
+
}
|
|
2234
|
+
async function loadNextPage(client, workspaceId, sessionId, after, options) {
|
|
2235
|
+
if (options.signal?.aborted) {
|
|
2236
|
+
throw abortError();
|
|
2237
|
+
}
|
|
2238
|
+
const requested = options.pageSize;
|
|
2239
|
+
if (requested === 0) {
|
|
2240
|
+
return historyPage([], requested);
|
|
2241
|
+
}
|
|
2242
|
+
const read = {
|
|
2243
|
+
...options.before !== void 0 ? { before: options.before } : {},
|
|
2244
|
+
after,
|
|
2245
|
+
limit: requested,
|
|
2246
|
+
compact: true,
|
|
2247
|
+
direction: "after",
|
|
2248
|
+
payloadMode: "full"
|
|
2249
|
+
};
|
|
2250
|
+
const page = options.filter ? await readConversationPage(client, workspaceId, sessionId, read) : historyPage(await client.listEvents(workspaceId, sessionId, read), requested);
|
|
2251
|
+
if (options.signal?.aborted) {
|
|
2252
|
+
throw abortError();
|
|
2253
|
+
}
|
|
2254
|
+
return Object.assign(page, { requested });
|
|
2255
|
+
}
|
|
2256
|
+
function groupCount(t, events) {
|
|
2257
|
+
if (events.length === 0) {
|
|
2258
|
+
return 0;
|
|
2259
|
+
}
|
|
2260
|
+
return groupTimeline(t, buildTimeline(t, events)).length;
|
|
2261
|
+
}
|
|
2262
|
+
function isLogStart(event) {
|
|
2263
|
+
return event.type === "session.created" || event.sequence <= 1;
|
|
2264
|
+
}
|
|
2265
|
+
function maxResumeSequence(events) {
|
|
2266
|
+
return events.reduce((max, event) => Math.max(max, eventResumeSequence(event)), 0);
|
|
2267
|
+
}
|
|
2268
|
+
function maxResumeSequenceOrNull(events) {
|
|
2269
|
+
return events.length > 0 ? maxResumeSequence(events) : null;
|
|
2270
|
+
}
|
|
2271
|
+
function eventResumeSequence(event) {
|
|
2272
|
+
const streamedCoverage = sessionEventStreamCoveredThrough(event);
|
|
2273
|
+
if (streamedCoverage !== null) return streamedCoverage;
|
|
2274
|
+
return typeof event.coveredThrough === "number" && Number.isSafeInteger(event.coveredThrough) && event.coveredThrough >= event.sequence ? event.coveredThrough : event.sequence;
|
|
2275
|
+
}
|
|
2276
|
+
function assertAscending(events) {
|
|
2277
|
+
for (let index = 1; index < events.length; index += 1) {
|
|
2278
|
+
if (events[index - 1].sequence >= events[index].sequence) {
|
|
2279
|
+
throw new Error("@opengeni/react: session events must be ordered by ascending sequence");
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
function assertPrependOrder(existing, older) {
|
|
2284
|
+
if (!shouldAssertDevelopment() || existing.length === 0 || older.length === 0) {
|
|
2285
|
+
return;
|
|
2286
|
+
}
|
|
2287
|
+
if (older[older.length - 1].sequence >= existing[0].sequence) {
|
|
2288
|
+
throw new Error("@opengeni/react: loadOlder returned overlapping session events");
|
|
2289
|
+
}
|
|
2290
|
+
}
|
|
2291
|
+
function assertAppendOrder(existing, newer) {
|
|
2292
|
+
if (!shouldAssertDevelopment() || existing.length === 0 || newer.length === 0) {
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
if (newer[0].sequence <= existing[existing.length - 1].sequence) {
|
|
2296
|
+
throw new Error("@opengeni/react: loadNewer returned overlapping session events");
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
function shouldAssertDevelopment() {
|
|
2300
|
+
const processEnv = globalThis.process?.env;
|
|
2301
|
+
return processEnv !== void 0 && processEnv.NODE_ENV !== "production";
|
|
2302
|
+
}
|
|
2303
|
+
function abortError() {
|
|
2304
|
+
const error = new Error("The operation was aborted.");
|
|
2305
|
+
error.name = "AbortError";
|
|
2306
|
+
return error;
|
|
2307
|
+
}
|
|
2308
|
+
function abortableDelay(ms, signal) {
|
|
2309
|
+
return new Promise((resolve, reject) => {
|
|
2310
|
+
if (signal.aborted) {
|
|
2311
|
+
reject(abortError());
|
|
2312
|
+
return;
|
|
2313
|
+
}
|
|
2314
|
+
const onAbort = () => {
|
|
2315
|
+
clearTimeout(timer);
|
|
2316
|
+
reject(abortError());
|
|
2317
|
+
};
|
|
2318
|
+
const timer = setTimeout(() => {
|
|
2319
|
+
signal.removeEventListener("abort", onAbort);
|
|
2320
|
+
resolve();
|
|
2321
|
+
}, ms);
|
|
2322
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
var CONTENT_STEP_TYPES = new Set(SESSION_EVENT_CONTENT_STEP_TYPES);
|
|
2326
|
+
var COMPAT_EXCLUDED_TYPES = new Set(
|
|
2327
|
+
SESSION_EVENT_COMPAT_EXCLUDED_STEP_TYPES
|
|
2328
|
+
);
|
|
2329
|
+
var CONVERSATION_FILTER = "conversation";
|
|
2330
|
+
var SESSION_TURN_STEP_PAGE_SIZE = 200;
|
|
2331
|
+
var SESSION_TURN_LIVE_STEP_TAIL = 200;
|
|
2332
|
+
var SESSION_TURN_LIVE_STEP_TAIL_BYTES = 2 * 1024 * 1024;
|
|
2333
|
+
var TURNLESS_STEP_TAIL = 1e3;
|
|
2334
|
+
var TURNLESS_STEP_TAIL_BYTES = 4 * 1024 * 1024;
|
|
2335
|
+
var TURN_STEP_READ_TYPES = SESSION_EVENT_STEP_TYPES.filter(
|
|
2336
|
+
(type) => type !== "terminal.pty.output.delta"
|
|
2337
|
+
);
|
|
2338
|
+
var SESSION_STEP_BROWSER_MAX_BYTES = 16 * 1024 * 1024;
|
|
2339
|
+
var TERMINAL_TURN_TYPES = /* @__PURE__ */ new Set([
|
|
2340
|
+
"turn.completed",
|
|
2341
|
+
"turn.failed",
|
|
2342
|
+
"turn.cancelled",
|
|
2343
|
+
"turn.superseded"
|
|
2344
|
+
]);
|
|
2345
|
+
var EMPTY_STEP_STORES = /* @__PURE__ */ new Map();
|
|
2346
|
+
var EMPTY_TURNLESS_STEPS = { events: [], bytes: 2, ranges: [], appended: 0 };
|
|
2347
|
+
var TURNLESS_STEP_MAX_RANGES = 4096;
|
|
2348
|
+
function appendTurnlessSteps(current, incoming) {
|
|
2349
|
+
const ranges = current.ranges.map((range) => [range[0], range[1]]);
|
|
2350
|
+
for (const event of incoming) {
|
|
2351
|
+
const sequence = event.sequence;
|
|
2352
|
+
const last = ranges.at(-1);
|
|
2353
|
+
if (last && sequence >= last[0] && sequence <= last[1]) continue;
|
|
2354
|
+
if (last && sequence === last[1] + 1) last[1] = sequence;
|
|
2355
|
+
else if (!last || sequence > last[1]) ranges.push([sequence, sequence]);
|
|
2356
|
+
else if (!ranges.some(([first, end]) => sequence >= first && sequence <= end)) {
|
|
2357
|
+
ranges.push([sequence, sequence]);
|
|
2358
|
+
ranges.sort((left, right) => left[0] - right[0]);
|
|
2359
|
+
}
|
|
2360
|
+
}
|
|
2361
|
+
if (ranges.length > TURNLESS_STEP_MAX_RANGES) {
|
|
2362
|
+
ranges.splice(0, ranges.length - TURNLESS_STEP_MAX_RANGES);
|
|
2363
|
+
}
|
|
2364
|
+
const next = appendStepEvents(current, incoming);
|
|
2365
|
+
const appended = current.appended + incoming.length;
|
|
2366
|
+
if (next.events.length <= TURNLESS_STEP_TAIL && next.bytes <= TURNLESS_STEP_TAIL_BYTES) {
|
|
2367
|
+
return { ...next, ranges, appended };
|
|
2368
|
+
}
|
|
2369
|
+
const kept = boundBrowserSessionEventWindow(next.events, {
|
|
2370
|
+
maxCount: TURNLESS_STEP_TAIL,
|
|
2371
|
+
maxBytes: TURNLESS_STEP_TAIL_BYTES
|
|
2372
|
+
});
|
|
2373
|
+
return { events: kept.events, bytes: kept.bytes, ranges, appended };
|
|
2374
|
+
}
|
|
2375
|
+
function withTurnlessSteps(window2, turnless) {
|
|
2376
|
+
const first = window2[0]?.sequence;
|
|
2377
|
+
if (first === void 0 || turnless.ranges.length === 0) return window2;
|
|
2378
|
+
const placeholders = [];
|
|
2379
|
+
for (const [start, end] of turnless.ranges) {
|
|
2380
|
+
if (end < first) continue;
|
|
2381
|
+
placeholders.push({
|
|
2382
|
+
id: `turnless-steps-${start}`,
|
|
2383
|
+
workspaceId: window2[0].workspaceId,
|
|
2384
|
+
sessionId: window2[0].sessionId,
|
|
2385
|
+
sequence: start,
|
|
2386
|
+
coveredThrough: end,
|
|
2387
|
+
type: "terminal.pty.output.delta",
|
|
2388
|
+
payload: null,
|
|
2389
|
+
occurredAt: window2[0].occurredAt,
|
|
2390
|
+
turnId: null
|
|
2391
|
+
});
|
|
2392
|
+
}
|
|
2393
|
+
if (placeholders.length === 0) return window2;
|
|
2394
|
+
return [...window2, ...placeholders].sort((left, right) => left.sequence - right.sequence);
|
|
2395
|
+
}
|
|
2396
|
+
function turnStepLowerBound(bounds) {
|
|
2397
|
+
return bounds.started !== null ? bounds.started - 1 : bounds.previous;
|
|
2398
|
+
}
|
|
2399
|
+
function stepStoreHasOlder(store, bounds) {
|
|
2400
|
+
return store.hasOlder || store.floor !== null && turnStepLowerBound(bounds) < store.floor;
|
|
2401
|
+
}
|
|
2402
|
+
function isConversationHistoryEvent(event, presentedCallIds, startupTurns) {
|
|
2403
|
+
if (event.turnId) {
|
|
2404
|
+
if (event.type === "agent.model.usage") return startupTurns === void 0;
|
|
2405
|
+
if (event.type === "agent.model.request") {
|
|
2406
|
+
return startupTurns === void 0 || startupTurns.has(event.turnId);
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
if (!CONTENT_STEP_TYPES.has(event.type)) return true;
|
|
2410
|
+
const payload = event.payload;
|
|
2411
|
+
if (event.type === "agent.toolCall.created") return isPresentedSessionToolCall(payload);
|
|
2412
|
+
if (event.type === "agent.toolCall.output") {
|
|
2413
|
+
return typeof payload?.id === "string" && presentedCallIds.has(payload.id);
|
|
2414
|
+
}
|
|
2415
|
+
return false;
|
|
2416
|
+
}
|
|
2417
|
+
function emptyStartupTurns() {
|
|
2418
|
+
return { window: null, open: /* @__PURE__ */ new Set(), responded: /* @__PURE__ */ new Set() };
|
|
2419
|
+
}
|
|
2420
|
+
function noteStartupTurns(events, state) {
|
|
2421
|
+
for (const event of events) {
|
|
2422
|
+
const turnId = event.turnId;
|
|
2423
|
+
if (!turnId) continue;
|
|
2424
|
+
if (event.type === "turn.started") {
|
|
2425
|
+
if (!state.responded.has(turnId)) state.open.add(turnId);
|
|
2426
|
+
} else if (event.type === "agent.model.request" && isSessionModelResponsePhase(event.payload?.phase)) {
|
|
2427
|
+
state.open.delete(turnId);
|
|
2428
|
+
state.responded.add(turnId);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
var conversationFilterModes = /* @__PURE__ */ new WeakMap();
|
|
2433
|
+
var CONVERSATION_READS = {
|
|
2434
|
+
v2: { excludeTypes: [...SESSION_EVENT_STEP_TYPES], presentedToolCalls: "include" },
|
|
2435
|
+
compat: {
|
|
2436
|
+
excludeTypes: [...SESSION_EVENT_COMPAT_EXCLUDED_STEP_TYPES],
|
|
2437
|
+
presentedToolCalls: "include"
|
|
2438
|
+
}
|
|
2439
|
+
};
|
|
2440
|
+
function conversationFilterMode(client) {
|
|
2441
|
+
if (typeof client.listEventPage !== "function") {
|
|
2442
|
+
return "compat";
|
|
2443
|
+
}
|
|
2444
|
+
return conversationFilterModes.get(client) ?? "v2";
|
|
2445
|
+
}
|
|
2446
|
+
async function readConversationPage(client, workspaceId, sessionId, options) {
|
|
2447
|
+
let mode = conversationFilterMode(client);
|
|
2448
|
+
for (; ; ) {
|
|
2449
|
+
const read = await readEventPage(client, workspaceId, sessionId, {
|
|
2450
|
+
...CONVERSATION_READS[mode],
|
|
2451
|
+
...options
|
|
2452
|
+
});
|
|
2453
|
+
const announced = (read.conversationFilter ?? 0) >= SESSION_EVENT_CONVERSATION_FILTER_VERSION;
|
|
2454
|
+
if (read.conversationFilter !== void 0) {
|
|
2455
|
+
conversationFilterModes.set(client, announced ? "v2" : "compat");
|
|
2456
|
+
}
|
|
2457
|
+
if (mode === "v2" && !announced) {
|
|
2458
|
+
mode = "compat";
|
|
2459
|
+
continue;
|
|
2460
|
+
}
|
|
2461
|
+
const events = mode === "compat" ? read.events.filter(isCompatConversationEvent) : read.events;
|
|
2462
|
+
return Object.assign(events === read.events ? [...events] : events, {
|
|
2463
|
+
requested: options.limit,
|
|
2464
|
+
raw: rawPageExtent(read.events),
|
|
2465
|
+
hasMore: read.hasMore
|
|
2466
|
+
});
|
|
2467
|
+
}
|
|
2468
|
+
}
|
|
2469
|
+
function isCompatConversationEvent(event) {
|
|
2470
|
+
if (COMPAT_EXCLUDED_TYPES.has(event.type)) return false;
|
|
2471
|
+
if (event.type !== "agent.toolCall.created") return true;
|
|
2472
|
+
return isPresentedSessionToolCall(event.payload);
|
|
2473
|
+
}
|
|
2474
|
+
function notePresentedCalls(events, ids) {
|
|
2475
|
+
for (const event of events) {
|
|
2476
|
+
if (event.type !== "agent.toolCall.created") continue;
|
|
2477
|
+
const payload = event.payload;
|
|
2478
|
+
if (typeof payload?.id === "string" && isPresentedSessionToolCall(payload)) {
|
|
2479
|
+
ids.add(payload.id);
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
}
|
|
2483
|
+
function conversationTurnBounds(events) {
|
|
2484
|
+
const bounds = /* @__PURE__ */ new Map();
|
|
2485
|
+
const gaps = [];
|
|
2486
|
+
let expected = null;
|
|
2487
|
+
let previous = 0;
|
|
2488
|
+
for (const event of events) {
|
|
2489
|
+
if (expected !== null && event.sequence > expected) gaps.push(expected);
|
|
2490
|
+
const resume = eventResumeSequence(event);
|
|
2491
|
+
expected = Math.max(expected ?? 0, resume + 1);
|
|
2492
|
+
const turnId = event.turnId;
|
|
2493
|
+
if (!turnId) continue;
|
|
2494
|
+
const current = bounds.get(turnId);
|
|
2495
|
+
if (!current) {
|
|
2496
|
+
bounds.set(turnId, {
|
|
2497
|
+
first: event.sequence,
|
|
2498
|
+
started: event.type === "turn.started" ? event.sequence : null,
|
|
2499
|
+
previous,
|
|
2500
|
+
last: resume,
|
|
2501
|
+
terminal: TERMINAL_TURN_TYPES.has(event.type) ? event.sequence : null,
|
|
2502
|
+
hidden: false
|
|
2503
|
+
});
|
|
2504
|
+
} else {
|
|
2505
|
+
current.last = Math.max(current.last, resume);
|
|
2506
|
+
if (event.type === "turn.started" && current.started === null) {
|
|
2507
|
+
current.started = event.sequence;
|
|
2508
|
+
}
|
|
2509
|
+
if (TERMINAL_TURN_TYPES.has(event.type)) current.terminal = event.sequence;
|
|
2510
|
+
}
|
|
2511
|
+
if (!PRE_START_TURN_TYPES.has(event.type)) previous = resume;
|
|
2512
|
+
}
|
|
2513
|
+
for (const turn of bounds.values()) {
|
|
2514
|
+
let low = 0;
|
|
2515
|
+
let high = gaps.length;
|
|
2516
|
+
while (low < high) {
|
|
2517
|
+
const middle = low + high >> 1;
|
|
2518
|
+
if (gaps[middle] <= turn.first) low = middle + 1;
|
|
2519
|
+
else high = middle;
|
|
2520
|
+
}
|
|
2521
|
+
turn.hidden = low < gaps.length && gaps[low] < turn.last;
|
|
2522
|
+
}
|
|
2523
|
+
return bounds;
|
|
2524
|
+
}
|
|
2525
|
+
function activeConversationTurn(events) {
|
|
2526
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
2527
|
+
const event = events[index];
|
|
2528
|
+
if (!event.turnId) continue;
|
|
2529
|
+
if (TERMINAL_TURN_TYPES.has(event.type)) return null;
|
|
2530
|
+
if (event.type === "turn.started") return event.turnId;
|
|
2531
|
+
}
|
|
2532
|
+
return null;
|
|
2533
|
+
}
|
|
2534
|
+
function settledTurns(events) {
|
|
2535
|
+
const settled = /* @__PURE__ */ new Set();
|
|
2536
|
+
for (const event of events) {
|
|
2537
|
+
if (event.turnId && TERMINAL_TURN_TYPES.has(event.type)) settled.add(event.turnId);
|
|
2538
|
+
}
|
|
2539
|
+
return settled;
|
|
2540
|
+
}
|
|
2541
|
+
function windowTurns(events) {
|
|
2542
|
+
const turns = /* @__PURE__ */ new Set();
|
|
2543
|
+
for (const event of events) if (event.turnId) turns.add(event.turnId);
|
|
2544
|
+
return turns;
|
|
2545
|
+
}
|
|
2546
|
+
var EMPTY_PRESENTED_OUTPUTS = /* @__PURE__ */ new Map();
|
|
2547
|
+
var PRE_START_TURN_TYPES = /* @__PURE__ */ new Set(["turn.queued", "turn.capacity_waiting"]);
|
|
2548
|
+
var PRESENTED_OUTPUT_READS_PER_PASS = 8;
|
|
2549
|
+
var PRESENTED_OUTPUT_PAGE_SIZE = 16;
|
|
2550
|
+
var PRESENTED_OUTPUT_MAX_PAGES = 16;
|
|
2551
|
+
var PRESENTED_OUTPUT_RETRIES = 3;
|
|
2552
|
+
var PRESENTED_OUTPUT_RETRY_MS = 2e3;
|
|
2553
|
+
var RETAINED_VIEW_STEPS = {
|
|
2554
|
+
load: () => {
|
|
2555
|
+
},
|
|
2556
|
+
retain: () => () => {
|
|
2557
|
+
}
|
|
2558
|
+
};
|
|
2559
|
+
function mergeLoadedEvents(conversation, stores, presented, turnless, exactOutputs = EMPTY_PRESENTED_OUTPUTS) {
|
|
2560
|
+
if (stores.size === 0 && presented.size === 0 && turnless.length === 0 && exactOutputs.size === 0) {
|
|
2561
|
+
return conversation;
|
|
2562
|
+
}
|
|
2563
|
+
const turns = windowTurns(conversation);
|
|
2564
|
+
const ids = new Set(conversation.map((event) => event.id));
|
|
2565
|
+
const extra = [];
|
|
2566
|
+
const add = (event) => {
|
|
2567
|
+
if (ids.has(event.id) || !event.turnId || !turns.has(event.turnId)) return;
|
|
2568
|
+
ids.add(event.id);
|
|
2569
|
+
extra.push(event);
|
|
2570
|
+
};
|
|
2571
|
+
presented.forEach(add);
|
|
2572
|
+
exactOutputs.forEach(add);
|
|
2573
|
+
for (const [turnId, store] of stores) if (turns.has(turnId)) store.events.forEach(add);
|
|
2574
|
+
for (const event of turnless) {
|
|
2575
|
+
if (ids.has(event.id)) continue;
|
|
2576
|
+
ids.add(event.id);
|
|
2577
|
+
extra.push(event);
|
|
2578
|
+
}
|
|
2579
|
+
if (extra.length === 0) return conversation;
|
|
2580
|
+
return [...conversation, ...extra].sort((left, right) => left.sequence - right.sequence);
|
|
2581
|
+
}
|
|
2582
|
+
function groupByTurn(events) {
|
|
2583
|
+
const turns = /* @__PURE__ */ new Map();
|
|
2584
|
+
for (const event of events) {
|
|
2585
|
+
if (!event.turnId) continue;
|
|
2586
|
+
const list = turns.get(event.turnId);
|
|
2587
|
+
if (list) list.push(event);
|
|
2588
|
+
else turns.set(event.turnId, [event]);
|
|
2589
|
+
}
|
|
2590
|
+
return turns;
|
|
2591
|
+
}
|
|
2592
|
+
function appendStepEvents(store, incoming) {
|
|
2593
|
+
if (incoming.length === 0) return { events: store.events, bytes: store.bytes };
|
|
2594
|
+
const ids = new Set(store.events.map((event) => event.id));
|
|
2595
|
+
let bytes = store.bytes;
|
|
2596
|
+
const fresh = [];
|
|
2597
|
+
for (const event of incoming) {
|
|
2598
|
+
if (ids.has(event.id)) continue;
|
|
2599
|
+
ids.add(event.id);
|
|
2600
|
+
fresh.push(event);
|
|
2601
|
+
bytes += browserJsonBytes(event) + (store.events.length + fresh.length > 1 ? 1 : 0);
|
|
2602
|
+
}
|
|
2603
|
+
if (fresh.length === 0) return { events: store.events, bytes: store.bytes };
|
|
2604
|
+
const last = store.events[store.events.length - 1];
|
|
2605
|
+
const events = [...store.events, ...fresh];
|
|
2606
|
+
if (last && fresh.some((event) => event.sequence < last.sequence)) {
|
|
2607
|
+
events.sort((left, right) => left.sequence - right.sequence);
|
|
2608
|
+
} else if (!last) {
|
|
2609
|
+
events.sort((left, right) => left.sequence - right.sequence);
|
|
2610
|
+
}
|
|
2611
|
+
return { events, bytes };
|
|
2612
|
+
}
|
|
2613
|
+
function turnHasHiddenSequences(events, turnId, before) {
|
|
2614
|
+
const start = events.findIndex((event) => event.turnId === turnId);
|
|
2615
|
+
if (start < 0) return true;
|
|
2616
|
+
let expected = eventResumeSequence(events[start]) + 1;
|
|
2617
|
+
for (let index = start + 1; index < events.length; index += 1) {
|
|
2618
|
+
const event = events[index];
|
|
2619
|
+
if (event.sequence >= before) break;
|
|
2620
|
+
if (event.sequence > expected) return true;
|
|
2621
|
+
expected = Math.max(expected, eventResumeSequence(event) + 1);
|
|
2622
|
+
}
|
|
2623
|
+
return expected < before;
|
|
2624
|
+
}
|
|
2625
|
+
function trimLiveStepTail(store) {
|
|
2626
|
+
if (store.events.length <= SESSION_TURN_LIVE_STEP_TAIL && store.bytes <= SESSION_TURN_LIVE_STEP_TAIL_BYTES) {
|
|
2627
|
+
return store;
|
|
2628
|
+
}
|
|
2629
|
+
const kept = boundBrowserSessionEventWindow(store.events, {
|
|
2630
|
+
maxCount: SESSION_TURN_LIVE_STEP_TAIL,
|
|
2631
|
+
maxBytes: SESSION_TURN_LIVE_STEP_TAIL_BYTES
|
|
2632
|
+
});
|
|
2633
|
+
return { ...store, events: kept.events, bytes: kept.bytes, hasOlder: true, cursor: null };
|
|
2634
|
+
}
|
|
2635
|
+
function boundStepStores(stores, retained) {
|
|
2636
|
+
let total = 0;
|
|
2637
|
+
for (const [turnId, store] of stores) {
|
|
2638
|
+
if (!retained.get(turnId)) total += store.bytes;
|
|
2639
|
+
}
|
|
2640
|
+
if (total <= SESSION_STEP_BROWSER_MAX_BYTES) return stores;
|
|
2641
|
+
const candidates = [...stores].filter(([turnId, store]) => !retained.get(turnId) && !store.loading).sort((left, right) => left[1].touched - right[1].touched);
|
|
2642
|
+
for (const [turnId, store] of candidates) {
|
|
2643
|
+
if (total <= SESSION_STEP_BROWSER_MAX_BYTES) break;
|
|
2644
|
+
stores.delete(turnId);
|
|
2645
|
+
total -= store.bytes;
|
|
2646
|
+
}
|
|
2647
|
+
return stores;
|
|
2648
|
+
}
|
|
2649
|
+
async function findPresentedOutput(client, workspaceId, sessionId, callId, after, terminal) {
|
|
2650
|
+
let cursor = after;
|
|
2651
|
+
for (let page = 0; page < PRESENTED_OUTPUT_MAX_PAGES; page += 1) {
|
|
2652
|
+
const read = await readEventPage(client, workspaceId, sessionId, {
|
|
2653
|
+
includeTypes: ["agent.toolCall.output"],
|
|
2654
|
+
after: cursor,
|
|
2655
|
+
...terminal !== null ? { before: terminal + 1 } : {},
|
|
2656
|
+
direction: "after",
|
|
2657
|
+
limit: PRESENTED_OUTPUT_PAGE_SIZE,
|
|
2658
|
+
payloadMode: "full"
|
|
2659
|
+
});
|
|
2660
|
+
const output = read.events.find(
|
|
2661
|
+
(event) => event.payload?.id === callId
|
|
2662
|
+
);
|
|
2663
|
+
if (output) return output;
|
|
2664
|
+
const last = read.events.at(-1);
|
|
2665
|
+
if (!last || !(read.hasMore ?? read.events.length >= PRESENTED_OUTPUT_PAGE_SIZE)) return null;
|
|
2666
|
+
cursor = last.sequence;
|
|
2667
|
+
}
|
|
2668
|
+
return null;
|
|
2669
|
+
}
|
|
2670
|
+
async function readEventPage(client, workspaceId, sessionId, options) {
|
|
2671
|
+
const pageClient = client;
|
|
2672
|
+
if (typeof pageClient.listEventPage === "function") {
|
|
2673
|
+
const page = await pageClient.listEventPage(workspaceId, sessionId, options);
|
|
2674
|
+
return {
|
|
2675
|
+
events: page.events,
|
|
2676
|
+
hasMore: page.hasMore,
|
|
2677
|
+
// An SDK that predates the announcement reports nothing: treat it as none.
|
|
2678
|
+
conversationFilter: page.conversationFilter ?? null
|
|
2679
|
+
};
|
|
2680
|
+
}
|
|
2681
|
+
return { events: await client.listEvents(workspaceId, sessionId, options), hasMore: null };
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2684
|
+
// src/hooks/use-turn-queue.ts
|
|
2685
|
+
import { isTransientRequestError as isTransientRequestError2 } from "@opengeni/sdk";
|
|
2686
|
+
import { useCallback as useCallback4, useEffect as useEffect3, useLayoutEffect, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
|
|
2687
|
+
function isTurnQueueEvent(event) {
|
|
2688
|
+
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.");
|
|
2689
|
+
}
|
|
2690
|
+
function queueSnapshotCovers(candidate, observed) {
|
|
2691
|
+
return Boolean(
|
|
2692
|
+
candidate && candidate.version >= observed.version && candidate.effectiveControl.controlVersion >= observed.effectiveControl.controlVersion
|
|
2693
|
+
);
|
|
2694
|
+
}
|
|
2695
|
+
var EMPTY_PENDING_BY_TURN = {};
|
|
2696
|
+
function useTurnQueue(sessionId, options = {}) {
|
|
2697
|
+
const t = useOpenGeniText();
|
|
2698
|
+
const { client, workspaceId, workspaceControlEvent, registerSessionReconciler } = useEmbeddedSession(options);
|
|
2699
|
+
const enabled = (options.enabled ?? true) && Boolean(sessionId);
|
|
2700
|
+
const targetKey = `${workspaceId}\0${sessionId ?? ""}`;
|
|
2701
|
+
const pageLive = usePageLiveActivity();
|
|
2702
|
+
const pageLiveRef = useRef3(pageLive);
|
|
2703
|
+
pageLiveRef.current = pageLive;
|
|
2704
|
+
const [snapshot, setSnapshot] = useState3(null);
|
|
2705
|
+
const [stateTargetKey, setStateTargetKey] = useState3(targetKey);
|
|
2706
|
+
const [loading, setLoading] = useState3(enabled);
|
|
2707
|
+
const [error, setError] = useState3(null);
|
|
2708
|
+
const [mutationError, setMutationError] = useState3(null);
|
|
2709
|
+
const [pendingByTurn, setPendingByTurn] = useState3({});
|
|
2710
|
+
const [acceptedSteers, setAcceptedSteers] = useState3([]);
|
|
2711
|
+
const pendingRef = useRef3({});
|
|
2712
|
+
const readGeneration = useRef3(0);
|
|
2713
|
+
const targetKeyRef = useRef3(targetKey);
|
|
2714
|
+
const snapshotRef = useRef3(null);
|
|
2715
|
+
const transientStreakRef = useRef3(
|
|
2716
|
+
null
|
|
2717
|
+
);
|
|
2718
|
+
const transientRetryTimerRef = useRef3(null);
|
|
2719
|
+
const cancelTransientRetry = useCallback4(() => {
|
|
2720
|
+
if (transientRetryTimerRef.current !== null) {
|
|
2721
|
+
clearTimeout(transientRetryTimerRef.current);
|
|
2722
|
+
transientRetryTimerRef.current = null;
|
|
2723
|
+
}
|
|
2724
|
+
}, []);
|
|
2725
|
+
useLayoutEffect(() => {
|
|
2726
|
+
if (targetKeyRef.current === targetKey) return;
|
|
2727
|
+
targetKeyRef.current = targetKey;
|
|
2728
|
+
readGeneration.current += 1;
|
|
2729
|
+
snapshotRef.current = null;
|
|
2730
|
+
pendingRef.current = {};
|
|
2731
|
+
setStateTargetKey(targetKey);
|
|
2732
|
+
setSnapshot(null);
|
|
2733
|
+
setLoading(enabled);
|
|
2734
|
+
setError(null);
|
|
2735
|
+
transientStreakRef.current = null;
|
|
2736
|
+
cancelTransientRetry();
|
|
2737
|
+
setMutationError(null);
|
|
2738
|
+
setPendingByTurn({});
|
|
2739
|
+
setAcceptedSteers([]);
|
|
2740
|
+
}, [cancelTransientRetry, enabled, targetKey]);
|
|
2741
|
+
useEffect3(() => {
|
|
2742
|
+
if (acceptedSteers.length === 0 || options.events === void 0) return;
|
|
2743
|
+
const durablyConsumedTurnIds = new Set(
|
|
2744
|
+
options.events.flatMap(
|
|
2745
|
+
(event) => [
|
|
2746
|
+
"turn.started",
|
|
2747
|
+
"turn.superseded",
|
|
2748
|
+
"turn.cancelled",
|
|
2749
|
+
"turn.failed",
|
|
2750
|
+
"turn.completed"
|
|
2751
|
+
].includes(event.type) && event.turnId ? [event.turnId] : []
|
|
2752
|
+
)
|
|
2753
|
+
);
|
|
2754
|
+
if (durablyConsumedTurnIds.size === 0) return;
|
|
2755
|
+
setAcceptedSteers(
|
|
2756
|
+
(current) => current.filter((steer) => !durablyConsumedTurnIds.has(steer.turnId))
|
|
2757
|
+
);
|
|
2758
|
+
}, [acceptedSteers.length, options.events]);
|
|
2759
|
+
const acceptSnapshot = useCallback4(
|
|
2760
|
+
(ownedTargetKey, next) => {
|
|
2761
|
+
if (targetKeyRef.current !== ownedTargetKey) return false;
|
|
2762
|
+
const current = snapshotRef.current;
|
|
2763
|
+
if (next && current && (next.version < current.version || next.effectiveControl.controlVersion < current.effectiveControl.controlVersion)) {
|
|
2764
|
+
return false;
|
|
2765
|
+
}
|
|
2766
|
+
snapshotRef.current = next;
|
|
2767
|
+
setStateTargetKey(ownedTargetKey);
|
|
2768
|
+
setSnapshot(next);
|
|
2769
|
+
return true;
|
|
2770
|
+
},
|
|
2771
|
+
[]
|
|
2772
|
+
);
|
|
2773
|
+
const load = useCallback4(
|
|
2774
|
+
async (rejectOnFailure = false, fresh = false) => {
|
|
2775
|
+
if (!sessionId) return;
|
|
2776
|
+
const ownedTargetKey = `${workspaceId}\0${sessionId}`;
|
|
2777
|
+
const ticket = ++readGeneration.current;
|
|
2778
|
+
try {
|
|
2779
|
+
const fetched = fresh ? await client.getQueue(workspaceId, sessionId, { fresh: true }) : await client.getQueue(workspaceId, sessionId);
|
|
2780
|
+
if (targetKeyRef.current !== ownedTargetKey) return;
|
|
2781
|
+
transientStreakRef.current = null;
|
|
2782
|
+
cancelTransientRetry();
|
|
2783
|
+
const ownsLatestRead = ticket === readGeneration.current;
|
|
2784
|
+
if (rejectOnFailure) {
|
|
2785
|
+
const committed = acceptSnapshot(ownedTargetKey, fetched);
|
|
2786
|
+
if (!committed && !queueSnapshotCovers(snapshotRef.current, fetched)) {
|
|
2787
|
+
throw new TypeError("Queue reconciliation did not commit authoritative state");
|
|
2788
|
+
}
|
|
2789
|
+
setError(null);
|
|
2790
|
+
if (ownsLatestRead) setLoading(false);
|
|
2791
|
+
} else if (ownsLatestRead) {
|
|
2792
|
+
acceptSnapshot(ownedTargetKey, fetched);
|
|
2793
|
+
setError(null);
|
|
2794
|
+
setLoading(false);
|
|
2795
|
+
}
|
|
2796
|
+
} catch (cause) {
|
|
2797
|
+
if (targetKeyRef.current === ownedTargetKey && (ticket === readGeneration.current || rejectOnFailure)) {
|
|
2798
|
+
if (isTransientRequestError2(cause)) {
|
|
2799
|
+
const now = Date.now();
|
|
2800
|
+
const streak = transientStreakRef.current ??= {
|
|
2801
|
+
since: now,
|
|
2802
|
+
attempts: 0,
|
|
2803
|
+
surfaced: false
|
|
2804
|
+
};
|
|
2805
|
+
const step = transientReadRetryStep(streak, now, DEFAULT_TRANSIENT_READ_RETRY, cause);
|
|
2806
|
+
if (!step.quiet) {
|
|
2807
|
+
if (!streak.surfaced) setError(asError(cause));
|
|
2808
|
+
streak.surfaced = true;
|
|
2809
|
+
if (ticket === readGeneration.current) setLoading(false);
|
|
2810
|
+
}
|
|
2811
|
+
if (!rejectOnFailure && pageLiveRef.current) {
|
|
2812
|
+
cancelTransientRetry();
|
|
2813
|
+
transientRetryTimerRef.current = setTimeout(() => {
|
|
2814
|
+
transientRetryTimerRef.current = null;
|
|
2815
|
+
if (targetKeyRef.current === ownedTargetKey) void loadRef.current(false, fresh);
|
|
2816
|
+
}, step.delayMs);
|
|
2817
|
+
}
|
|
2818
|
+
} else {
|
|
2819
|
+
transientStreakRef.current = null;
|
|
2820
|
+
setError(asError(cause));
|
|
2821
|
+
if (ticket === readGeneration.current) setLoading(false);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
if (rejectOnFailure) throw cause;
|
|
2825
|
+
}
|
|
2826
|
+
},
|
|
2827
|
+
[client, workspaceId, sessionId, acceptSnapshot, cancelTransientRetry]
|
|
2828
|
+
);
|
|
2829
|
+
const loadRef = useRef3(load);
|
|
2830
|
+
loadRef.current = load;
|
|
2831
|
+
useEffect3(() => cancelTransientRetry, [cancelTransientRetry]);
|
|
2832
|
+
useEffect3(() => {
|
|
2833
|
+
if (!enabled || !pageLive) {
|
|
2834
|
+
cancelTransientRetry();
|
|
2835
|
+
setLoading(false);
|
|
2836
|
+
return;
|
|
2837
|
+
}
|
|
2838
|
+
setLoading(true);
|
|
2839
|
+
const pollIntervalMs = options.pollIntervalMs;
|
|
2840
|
+
if (pollIntervalMs === void 0 || pollIntervalMs <= 0) {
|
|
2841
|
+
void load();
|
|
2842
|
+
return () => {
|
|
2843
|
+
readGeneration.current += 1;
|
|
2844
|
+
};
|
|
2845
|
+
}
|
|
2846
|
+
let cancelled = false;
|
|
2847
|
+
let timer = null;
|
|
2848
|
+
const schedule = () => {
|
|
2849
|
+
if (cancelled) return;
|
|
2850
|
+
timer = setTimeout(() => {
|
|
2851
|
+
timer = null;
|
|
2852
|
+
void load().finally(schedule);
|
|
2853
|
+
}, pollIntervalMs);
|
|
2854
|
+
};
|
|
2855
|
+
void load().finally(schedule);
|
|
2856
|
+
return () => {
|
|
2857
|
+
cancelled = true;
|
|
2858
|
+
if (timer !== null) clearTimeout(timer);
|
|
2859
|
+
readGeneration.current += 1;
|
|
2860
|
+
};
|
|
2861
|
+
}, [cancelTransientRetry, load, enabled, pageLive, options.pollIntervalMs]);
|
|
2862
|
+
const loadFresh = useCallback4(() => load(false, true), [load]);
|
|
2863
|
+
useEffect3(() => {
|
|
2864
|
+
if (enabled && workspaceControlEvent) void loadFresh();
|
|
2865
|
+
}, [enabled, loadFresh, workspaceControlEvent]);
|
|
2866
|
+
useEffect3(() => {
|
|
2867
|
+
if (!sessionId || !enabled) return;
|
|
2868
|
+
return registerSessionReconciler(sessionId, "queue", loadFresh);
|
|
2869
|
+
}, [enabled, loadFresh, registerSessionReconciler, sessionId]);
|
|
2870
|
+
const scheduleRefresh = useDebouncedCallback(() => void loadFresh());
|
|
2871
|
+
const freshSnapshot = stateTargetKey === targetKey ? snapshot : null;
|
|
2872
|
+
const freshLoading = stateTargetKey === targetKey ? loading : enabled;
|
|
2873
|
+
useSessionEventTrigger(
|
|
2874
|
+
client,
|
|
2875
|
+
workspaceId,
|
|
2876
|
+
sessionId,
|
|
2877
|
+
isTurnQueueEvent,
|
|
2878
|
+
scheduleRefresh,
|
|
2879
|
+
{
|
|
2880
|
+
enabled,
|
|
2881
|
+
...options.events !== void 0 ? { events: options.events } : {},
|
|
2882
|
+
readThrough: projectionReadThrough(freshSnapshot, freshLoading),
|
|
2883
|
+
refresh: scheduleRefresh
|
|
2884
|
+
},
|
|
2885
|
+
async () => await load(true, true)
|
|
2886
|
+
);
|
|
2887
|
+
const retainedSnapshot = useRetainedSessionView(
|
|
2888
|
+
client,
|
|
2889
|
+
workspaceId,
|
|
2890
|
+
sessionId,
|
|
2891
|
+
"queue",
|
|
2892
|
+
freshSnapshot,
|
|
2893
|
+
{ enabled, discard: stateTargetKey === targetKey && deniesRetainedView(error) }
|
|
2894
|
+
);
|
|
2895
|
+
const mutate = useCallback4(
|
|
2896
|
+
async (turnId, kind, command, failure = {}) => {
|
|
2897
|
+
const ownedTargetKey = targetKey;
|
|
2898
|
+
if (!sessionId || targetKeyRef.current !== ownedTargetKey || pendingRef.current[turnId]) {
|
|
2899
|
+
return null;
|
|
2900
|
+
}
|
|
2901
|
+
const current = snapshotRef.current;
|
|
2902
|
+
const turn = current?.items.find((candidate) => candidate.id === turnId);
|
|
2903
|
+
if (!current || !turn) return null;
|
|
2904
|
+
pendingRef.current = { ...pendingRef.current, [turnId]: kind };
|
|
2905
|
+
setStateTargetKey(ownedTargetKey);
|
|
2906
|
+
setPendingByTurn(pendingRef.current);
|
|
2907
|
+
setMutationError(null);
|
|
2908
|
+
const clientEventId = operationKey();
|
|
2909
|
+
try {
|
|
2910
|
+
let result;
|
|
2911
|
+
try {
|
|
2912
|
+
result = await command(current, turn, clientEventId);
|
|
2913
|
+
} catch (cause) {
|
|
2914
|
+
if (!isOutcomeUnknownError(cause)) throw cause;
|
|
2915
|
+
result = await command(current, turn, clientEventId);
|
|
2916
|
+
}
|
|
2917
|
+
if (targetKeyRef.current !== ownedTargetKey) return null;
|
|
2918
|
+
acceptSnapshot(ownedTargetKey, result.snapshot);
|
|
2919
|
+
return result;
|
|
2920
|
+
} catch (cause) {
|
|
2921
|
+
if (targetKeyRef.current === ownedTargetKey) {
|
|
2922
|
+
if (failure.quietWhenGone) {
|
|
2923
|
+
await loadFresh();
|
|
2924
|
+
const stillWaiting = snapshotRef.current?.items.some(
|
|
2925
|
+
(candidate) => candidate.id === turnId
|
|
2926
|
+
);
|
|
2927
|
+
if (stillWaiting !== false && targetKeyRef.current === ownedTargetKey) {
|
|
2928
|
+
setMutationError(asError(cause));
|
|
2929
|
+
}
|
|
2930
|
+
} else {
|
|
2931
|
+
setMutationError(asError(cause));
|
|
2932
|
+
await loadFresh();
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
return null;
|
|
2936
|
+
} finally {
|
|
2937
|
+
if (targetKeyRef.current === ownedTargetKey && turnId in pendingRef.current) {
|
|
2938
|
+
const next = { ...pendingRef.current };
|
|
2939
|
+
delete next[turnId];
|
|
2940
|
+
pendingRef.current = next;
|
|
2941
|
+
setPendingByTurn(next);
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
},
|
|
2945
|
+
[acceptSnapshot, loadFresh, sessionId, targetKey]
|
|
2946
|
+
);
|
|
2947
|
+
const moveTurn = useCallback4(
|
|
2948
|
+
async (turnId, beforeTurnId) => {
|
|
2949
|
+
const result = await mutate(
|
|
2950
|
+
turnId,
|
|
2951
|
+
"move",
|
|
2952
|
+
(current, _turn, clientEventId) => client.moveQueueItem(workspaceId, sessionId, turnId, {
|
|
2953
|
+
clientEventId,
|
|
2954
|
+
expectedQueueVersion: current.version,
|
|
2955
|
+
beforeTurnId
|
|
2956
|
+
})
|
|
2957
|
+
);
|
|
2958
|
+
return result !== null;
|
|
2959
|
+
},
|
|
2960
|
+
[client, mutate, sessionId, workspaceId]
|
|
2961
|
+
);
|
|
2962
|
+
const editTurn = useCallback4(
|
|
2963
|
+
async (turnId, edit) => {
|
|
2964
|
+
const result = await mutate(
|
|
2965
|
+
turnId,
|
|
2966
|
+
"edit",
|
|
2967
|
+
(_current, turn, clientEventId) => client.editQueueItem(workspaceId, sessionId, turnId, {
|
|
2968
|
+
clientEventId,
|
|
2969
|
+
expectedTurnVersion: turn.version,
|
|
2970
|
+
expectedDraftRevision: edit.expectedDraftRevision,
|
|
2971
|
+
replaceDraft: edit.replaceDraft
|
|
2972
|
+
})
|
|
2973
|
+
);
|
|
2974
|
+
return result?.draft ?? null;
|
|
2975
|
+
},
|
|
2976
|
+
[client, mutate, sessionId, workspaceId]
|
|
2977
|
+
);
|
|
2978
|
+
const recallTurn = useCallback4(
|
|
2979
|
+
async (turnId, recall) => {
|
|
2980
|
+
const ownedTargetKey = targetKey;
|
|
2981
|
+
const known = snapshotRef.current?.items.some((candidate) => candidate.id === turnId);
|
|
2982
|
+
if (known === false) return { status: "already_sent" };
|
|
2983
|
+
const result = await mutate(
|
|
2984
|
+
turnId,
|
|
2985
|
+
"edit",
|
|
2986
|
+
(_current, turn, clientEventId) => client.editQueueItem(workspaceId, sessionId, turnId, {
|
|
2987
|
+
clientEventId,
|
|
2988
|
+
expectedTurnVersion: turn.version,
|
|
2989
|
+
expectedDraftRevision: recall.expectedDraftRevision,
|
|
2990
|
+
replaceDraft: false
|
|
2991
|
+
}),
|
|
2992
|
+
{ quietWhenGone: true }
|
|
2993
|
+
);
|
|
2994
|
+
if (targetKeyRef.current !== ownedTargetKey) return { status: "failed" };
|
|
2995
|
+
if (result?.draft) return { status: "recalled", draft: result.draft };
|
|
2996
|
+
const stillWaiting = snapshotRef.current?.items.some((candidate) => candidate.id === turnId);
|
|
2997
|
+
return result === null && stillWaiting === false ? { status: "already_sent" } : { status: "failed" };
|
|
2998
|
+
},
|
|
2999
|
+
[client, mutate, sessionId, targetKey, workspaceId]
|
|
3000
|
+
);
|
|
3001
|
+
const steerTurn = useCallback4(
|
|
3002
|
+
async (turnId) => {
|
|
3003
|
+
const ownedTargetKey = targetKey;
|
|
3004
|
+
const turn = snapshotRef.current?.items.find((candidate) => candidate.id === turnId);
|
|
3005
|
+
if (targetKeyRef.current !== ownedTargetKey) return false;
|
|
3006
|
+
if (!turn) {
|
|
3007
|
+
setMutationError(new Error(t("hooks.useTurnQueue.thatQueuedPromptChangedBefore")));
|
|
3008
|
+
await loadFresh();
|
|
3009
|
+
return false;
|
|
3010
|
+
}
|
|
3011
|
+
const optimistic = {
|
|
3012
|
+
turnId: turn.id,
|
|
3013
|
+
triggerEventId: turn.triggerEventId,
|
|
3014
|
+
text: turn.prompt,
|
|
3015
|
+
annotations: turn.annotations ?? [],
|
|
3016
|
+
resources: turn.resources,
|
|
3017
|
+
tools: turn.tools,
|
|
3018
|
+
occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3019
|
+
state: "sending"
|
|
3020
|
+
};
|
|
3021
|
+
setAcceptedSteers((current) => [
|
|
3022
|
+
...current.filter((steer) => steer.turnId !== turnId),
|
|
3023
|
+
optimistic
|
|
3024
|
+
]);
|
|
3025
|
+
const result = await mutate(
|
|
3026
|
+
turnId,
|
|
3027
|
+
"steer",
|
|
3028
|
+
(current, queuedTurn, clientEventId) => client.steerQueueItem(workspaceId, sessionId, turnId, {
|
|
3029
|
+
clientEventId,
|
|
3030
|
+
expectedTurnVersion: queuedTurn.version,
|
|
3031
|
+
controlEtag: current.effectiveControl.controlEtag
|
|
3032
|
+
})
|
|
3033
|
+
);
|
|
3034
|
+
if (targetKeyRef.current !== ownedTargetKey) return false;
|
|
3035
|
+
const advancedWithoutSteer = result === null && snapshotRef.current !== null && !snapshotRef.current.items.some((candidate) => candidate.id === turnId);
|
|
3036
|
+
if (advancedWithoutSteer) {
|
|
3037
|
+
setMutationError(null);
|
|
3038
|
+
setAcceptedSteers((current) => current.filter((steer) => steer.turnId !== turnId));
|
|
3039
|
+
return true;
|
|
3040
|
+
}
|
|
3041
|
+
const accepted = result !== null || snapshotRef.current?.items.some(
|
|
3042
|
+
(candidate) => candidate.id === turnId && candidate.metadata.delivery === "steer"
|
|
3043
|
+
) === true;
|
|
3044
|
+
setAcceptedSteers(
|
|
3045
|
+
(current) => accepted ? current.map(
|
|
3046
|
+
(steer) => steer.turnId === turnId ? { ...steer, state: "queued" } : steer
|
|
3047
|
+
) : current.filter((steer) => steer.turnId !== turnId)
|
|
3048
|
+
);
|
|
3049
|
+
return accepted;
|
|
3050
|
+
},
|
|
3051
|
+
[client, loadFresh, mutate, sessionId, targetKey, workspaceId, t]
|
|
3052
|
+
);
|
|
3053
|
+
const removeTurn = useCallback4(
|
|
3054
|
+
async (turnId) => {
|
|
3055
|
+
const result = await mutate(
|
|
3056
|
+
turnId,
|
|
3057
|
+
"delete",
|
|
3058
|
+
(_current, turn, clientEventId) => client.deleteQueueItem(workspaceId, sessionId, turnId, {
|
|
3059
|
+
clientEventId,
|
|
3060
|
+
expectedTurnVersion: turn.version,
|
|
3061
|
+
reason: "Deleted from the prompt queue"
|
|
3062
|
+
})
|
|
3063
|
+
);
|
|
3064
|
+
return result !== null;
|
|
3065
|
+
},
|
|
3066
|
+
[client, mutate, sessionId, workspaceId]
|
|
3067
|
+
);
|
|
3068
|
+
const identityMatches = stateTargetKey === targetKey;
|
|
3069
|
+
const visibleSnapshot = freshSnapshot ?? retainedSnapshot;
|
|
3070
|
+
const visiblePendingByTurn = identityMatches ? pendingByTurn : EMPTY_PENDING_BY_TURN;
|
|
3071
|
+
const mutating = useMemo3(
|
|
3072
|
+
() => Object.keys(visiblePendingByTurn).length > 0,
|
|
3073
|
+
[visiblePendingByTurn]
|
|
3074
|
+
);
|
|
3075
|
+
const mutationFor = useCallback4(
|
|
3076
|
+
(turnId) => visiblePendingByTurn[turnId] ?? null,
|
|
3077
|
+
[visiblePendingByTurn]
|
|
3078
|
+
);
|
|
3079
|
+
return {
|
|
3080
|
+
snapshot: visibleSnapshot,
|
|
3081
|
+
queue: visibleSnapshot?.items ?? [],
|
|
3082
|
+
pendingInputs: visibleSnapshot?.pendingInputs ?? [],
|
|
3083
|
+
pendingInputAttachment: visibleSnapshot?.pendingInputAttachment ?? null,
|
|
3084
|
+
activePersonalConnections: visibleSnapshot?.activePersonalConnections ?? [],
|
|
3085
|
+
effectiveControl: visibleSnapshot?.effectiveControl ?? null,
|
|
3086
|
+
stoppingPreviousAttempt: visibleSnapshot?.stoppingPreviousAttempt ?? false,
|
|
3087
|
+
loading: freshLoading && retainedSnapshot === null,
|
|
3088
|
+
error: identityMatches ? error : null,
|
|
3089
|
+
refresh: load,
|
|
3090
|
+
moveTurn,
|
|
3091
|
+
editTurn,
|
|
3092
|
+
recallTurn,
|
|
3093
|
+
steerTurn,
|
|
3094
|
+
removeTurn,
|
|
3095
|
+
pendingByTurn: visiblePendingByTurn,
|
|
3096
|
+
mutationFor,
|
|
3097
|
+
mutating,
|
|
3098
|
+
mutationError: identityMatches ? mutationError : null,
|
|
3099
|
+
clearMutationError: useCallback4(() => {
|
|
3100
|
+
if (targetKeyRef.current === targetKey) setMutationError(null);
|
|
3101
|
+
}, [targetKey]),
|
|
3102
|
+
acceptedSteers: identityMatches ? acceptedSteers : []
|
|
3103
|
+
};
|
|
3104
|
+
}
|
|
3105
|
+
function operationKey() {
|
|
3106
|
+
return globalThis.crypto.randomUUID();
|
|
3107
|
+
}
|
|
3108
|
+
function asError(cause) {
|
|
3109
|
+
return normalizeError(cause);
|
|
3110
|
+
}
|
|
3111
|
+
function isOutcomeUnknownError(cause) {
|
|
3112
|
+
return typeof cause === "object" && cause !== null && cause.outcomeUnknown === true;
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
// src/hooks/use-goal.ts
|
|
3116
|
+
import {
|
|
3117
|
+
OpenGeniApiError,
|
|
3118
|
+
observedSessionSequence
|
|
3119
|
+
} from "@opengeni/sdk";
|
|
3120
|
+
import { useCallback as useCallback5, useEffect as useEffect4, useLayoutEffect as useLayoutEffect2, useRef as useRef4, useState as useState4 } from "react";
|
|
3121
|
+
function isGoalEvent(event) {
|
|
3122
|
+
return event.type.startsWith("goal.");
|
|
3123
|
+
}
|
|
3124
|
+
function isGoalRefreshEvent(event) {
|
|
3125
|
+
const type = event.type;
|
|
3126
|
+
return isGoalEvent(event) || type.startsWith("turn.") || type.startsWith("session.") || type.startsWith("system.update.") || type.startsWith("workspace.inference.") || type.startsWith("user.");
|
|
3127
|
+
}
|
|
3128
|
+
function useGoal(sessionId, options = {}) {
|
|
3129
|
+
const { client, workspaceId } = useEmbeddedGoal(options);
|
|
3130
|
+
const enabled = (options.enabled ?? true) && Boolean(sessionId);
|
|
3131
|
+
const sharedEvents = options.events;
|
|
3132
|
+
const sharedFeed = sharedEvents !== void 0;
|
|
3133
|
+
const pageLive = usePageLiveActivity();
|
|
3134
|
+
const [goal, setGoal] = useState4(null);
|
|
3135
|
+
const [loading, setLoading] = useState4(enabled);
|
|
3136
|
+
const [error, setError] = useState4(null);
|
|
3137
|
+
const [readAbsent, setReadAbsent] = useState4(false);
|
|
3138
|
+
const { run, mutating, mutationError, clearMutationError } = useMutationRunner();
|
|
3139
|
+
const generation = useRef4(0);
|
|
3140
|
+
const targetKeyRef = useRef4(null);
|
|
3141
|
+
const goalAbsentRef = useRef4(false);
|
|
3142
|
+
const pendingRefreshRef = useRef4("none");
|
|
3143
|
+
const sharedEventsRef = useRef4(sharedEvents);
|
|
3144
|
+
useLayoutEffect2(() => {
|
|
3145
|
+
sharedEventsRef.current = sharedEvents;
|
|
3146
|
+
}, [sharedEvents]);
|
|
3147
|
+
const loadAbort = useRef4(null);
|
|
3148
|
+
const scheduleRefreshRef = useRef4(() => void 0);
|
|
3149
|
+
const retireLoads = useCallback5(() => {
|
|
3150
|
+
generation.current += 1;
|
|
3151
|
+
loadAbort.current?.abort();
|
|
3152
|
+
loadAbort.current = null;
|
|
3153
|
+
}, []);
|
|
3154
|
+
const load = useCallback5(async () => {
|
|
3155
|
+
if (!sessionId) {
|
|
3156
|
+
return;
|
|
3157
|
+
}
|
|
3158
|
+
const ticket = ++generation.current;
|
|
3159
|
+
pendingRefreshRef.current = "none";
|
|
3160
|
+
loadAbort.current?.abort();
|
|
3161
|
+
const controller = new AbortController();
|
|
3162
|
+
loadAbort.current = controller;
|
|
3163
|
+
let fetchedGoal = null;
|
|
3164
|
+
try {
|
|
3165
|
+
const fetched = typeof client.findGoal === "function" ? await client.findGoal(workspaceId, sessionId, { signal: controller.signal }) : await client.getGoal(workspaceId, sessionId, { signal: controller.signal });
|
|
3166
|
+
fetchedGoal = fetched;
|
|
3167
|
+
if (ticket === generation.current) {
|
|
3168
|
+
goalAbsentRef.current = fetched === null;
|
|
3169
|
+
setReadAbsent(fetched === null);
|
|
3170
|
+
setGoal(fetched);
|
|
3171
|
+
setError(null);
|
|
3172
|
+
setLoading(false);
|
|
3173
|
+
}
|
|
3174
|
+
} catch (cause) {
|
|
3175
|
+
if (ticket !== generation.current) {
|
|
3176
|
+
return;
|
|
3177
|
+
}
|
|
3178
|
+
if (cause instanceof OpenGeniApiError && cause.status === 404) {
|
|
3179
|
+
goalAbsentRef.current = true;
|
|
3180
|
+
setReadAbsent(true);
|
|
3181
|
+
setGoal(null);
|
|
3182
|
+
setError(null);
|
|
3183
|
+
} else {
|
|
3184
|
+
setError(normalizeError(cause));
|
|
3185
|
+
}
|
|
3186
|
+
setLoading(false);
|
|
3187
|
+
} finally {
|
|
3188
|
+
if (loadAbort.current === controller) loadAbort.current = null;
|
|
3189
|
+
}
|
|
3190
|
+
if (ticket !== generation.current || pendingRefreshRef.current === "none") {
|
|
3191
|
+
return;
|
|
3192
|
+
}
|
|
3193
|
+
const readThrough = fetchedGoal ? observedSessionSequence(fetchedGoal) : void 0;
|
|
3194
|
+
if (readThrough !== void 0 && sharedEventsRef.current !== void 0) {
|
|
3195
|
+
const events = sharedEventsRef.current;
|
|
3196
|
+
const newest = events[events.length - 1];
|
|
3197
|
+
if (!newest || newest.sequence <= readThrough) {
|
|
3198
|
+
pendingRefreshRef.current = "none";
|
|
3199
|
+
return;
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
if (goalAbsentRef.current && pendingRefreshRef.current === "refresh") {
|
|
3203
|
+
const events = sharedEventsRef.current ?? [];
|
|
3204
|
+
let latestGoalEvent;
|
|
3205
|
+
for (let index = events.length - 1; index >= 0 && !latestGoalEvent; index -= 1) {
|
|
3206
|
+
const event = events[index];
|
|
3207
|
+
if (event && isGoalEvent(event)) latestGoalEvent = event;
|
|
3208
|
+
}
|
|
3209
|
+
if (!latestGoalEvent || latestGoalEvent.type === "goal.cleared") {
|
|
3210
|
+
pendingRefreshRef.current = "none";
|
|
3211
|
+
return;
|
|
3212
|
+
}
|
|
3213
|
+
pendingRefreshRef.current = "goal";
|
|
3214
|
+
}
|
|
3215
|
+
scheduleRefreshRef.current();
|
|
3216
|
+
}, [client, workspaceId, sessionId]);
|
|
3217
|
+
useEffect4(() => {
|
|
3218
|
+
const targetKey = `${workspaceId} ${sessionId ?? ""}`;
|
|
3219
|
+
if (targetKeyRef.current !== targetKey) {
|
|
3220
|
+
targetKeyRef.current = targetKey;
|
|
3221
|
+
goalAbsentRef.current = false;
|
|
3222
|
+
pendingRefreshRef.current = "none";
|
|
3223
|
+
setReadAbsent(false);
|
|
3224
|
+
setGoal(null);
|
|
3225
|
+
setError(null);
|
|
3226
|
+
}
|
|
3227
|
+
if (!enabled || !pageLive) {
|
|
3228
|
+
retireLoads();
|
|
3229
|
+
setLoading(false);
|
|
3230
|
+
return;
|
|
3231
|
+
}
|
|
3232
|
+
if (sharedFeed) {
|
|
3233
|
+
setLoading(true);
|
|
3234
|
+
void load();
|
|
3235
|
+
return () => {
|
|
3236
|
+
retireLoads();
|
|
3237
|
+
};
|
|
3238
|
+
}
|
|
3239
|
+
setLoading(true);
|
|
3240
|
+
const pollIntervalMs = options.pollIntervalMs;
|
|
3241
|
+
if (pollIntervalMs === void 0 || pollIntervalMs <= 0) {
|
|
3242
|
+
void load();
|
|
3243
|
+
return () => {
|
|
3244
|
+
retireLoads();
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
3247
|
+
let cancelled = false;
|
|
3248
|
+
let timer = null;
|
|
3249
|
+
const schedule = () => {
|
|
3250
|
+
if (cancelled) return;
|
|
3251
|
+
timer = setTimeout(() => {
|
|
3252
|
+
timer = null;
|
|
3253
|
+
void load().finally(schedule);
|
|
3254
|
+
}, pollIntervalMs);
|
|
3255
|
+
};
|
|
3256
|
+
void load().finally(schedule);
|
|
3257
|
+
return () => {
|
|
3258
|
+
cancelled = true;
|
|
3259
|
+
if (timer !== null) clearTimeout(timer);
|
|
3260
|
+
retireLoads();
|
|
3261
|
+
};
|
|
3262
|
+
}, [
|
|
3263
|
+
load,
|
|
3264
|
+
enabled,
|
|
3265
|
+
pageLive,
|
|
3266
|
+
workspaceId,
|
|
3267
|
+
sessionId,
|
|
3268
|
+
options.pollIntervalMs,
|
|
3269
|
+
retireLoads,
|
|
3270
|
+
sharedFeed
|
|
3271
|
+
]);
|
|
3272
|
+
const scheduleRefresh = useDebouncedCallback(() => {
|
|
3273
|
+
const pending = pendingRefreshRef.current;
|
|
3274
|
+
if (pending === "none" || loadAbort.current !== null) return;
|
|
3275
|
+
if (pending === "refresh" && goalAbsentRef.current) {
|
|
3276
|
+
pendingRefreshRef.current = "none";
|
|
3277
|
+
return;
|
|
3278
|
+
}
|
|
3279
|
+
void load();
|
|
3280
|
+
});
|
|
3281
|
+
useLayoutEffect2(() => {
|
|
3282
|
+
scheduleRefreshRef.current = scheduleRefresh;
|
|
3283
|
+
}, [scheduleRefresh]);
|
|
3284
|
+
const isRefreshEvent = useCallback5(
|
|
3285
|
+
(event) => goalAbsentRef.current ? isGoalEvent(event) : isGoalRefreshEvent(event),
|
|
3286
|
+
[]
|
|
3287
|
+
);
|
|
3288
|
+
const refreshGoal = useCallback5(() => {
|
|
3289
|
+
pendingRefreshRef.current = "goal";
|
|
3290
|
+
scheduleRefresh();
|
|
3291
|
+
}, [scheduleRefresh]);
|
|
3292
|
+
const onRefreshEvent = useCallback5(
|
|
3293
|
+
(event) => {
|
|
3294
|
+
if (isGoalEvent(event)) pendingRefreshRef.current = "goal";
|
|
3295
|
+
else if (pendingRefreshRef.current === "none") pendingRefreshRef.current = "refresh";
|
|
3296
|
+
scheduleRefresh();
|
|
3297
|
+
},
|
|
3298
|
+
[scheduleRefresh]
|
|
3299
|
+
);
|
|
3300
|
+
useSessionEventTrigger(client, workspaceId, sessionId, isRefreshEvent, onRefreshEvent, {
|
|
3301
|
+
enabled,
|
|
3302
|
+
...sharedEvents !== void 0 ? { events: sharedEvents } : {},
|
|
3303
|
+
// The load settles events that arrive during its read itself (above).
|
|
3304
|
+
readThrough: projectionReadThrough(goal, false),
|
|
3305
|
+
refresh: refreshGoal
|
|
3306
|
+
});
|
|
3307
|
+
const retainedGoal = useRetainedSessionView(
|
|
3308
|
+
client,
|
|
3309
|
+
workspaceId,
|
|
3310
|
+
sessionId,
|
|
3311
|
+
"goal",
|
|
3312
|
+
loading ? null : goal,
|
|
3313
|
+
{ enabled, discard: readAbsent || deniesRetainedView(error) }
|
|
3314
|
+
);
|
|
3315
|
+
const visibleGoal = loading ? goal ?? retainedGoal : goal;
|
|
3316
|
+
const goalRef = useRef4(goal);
|
|
3317
|
+
const shownRetainedRef = useRef4(null);
|
|
3318
|
+
const readWaitersRef = useRef4([]);
|
|
3319
|
+
useLayoutEffect2(() => {
|
|
3320
|
+
goalRef.current = goal;
|
|
3321
|
+
shownRetainedRef.current = loading && goal === null ? retainedGoal : null;
|
|
3322
|
+
});
|
|
3323
|
+
useEffect4(() => {
|
|
3324
|
+
if (loading) return;
|
|
3325
|
+
const waiters = readWaitersRef.current;
|
|
3326
|
+
readWaitersRef.current = [];
|
|
3327
|
+
for (const resolve of waiters) resolve();
|
|
3328
|
+
}, [loading]);
|
|
3329
|
+
useEffect4(
|
|
3330
|
+
() => () => {
|
|
3331
|
+
goalRef.current = null;
|
|
3332
|
+
const waiters = readWaitersRef.current;
|
|
3333
|
+
readWaitersRef.current = [];
|
|
3334
|
+
for (const resolve of waiters) resolve();
|
|
3335
|
+
},
|
|
3336
|
+
[workspaceId, sessionId]
|
|
3337
|
+
);
|
|
3338
|
+
const aimedAtCurrentGoal = useCallback5(async () => {
|
|
3339
|
+
const shown = shownRetainedRef.current;
|
|
3340
|
+
if (!shown) return true;
|
|
3341
|
+
await new Promise((resolve) => readWaitersRef.current.push(resolve));
|
|
3342
|
+
const fresh = goalRef.current;
|
|
3343
|
+
return fresh !== null && fresh.id === shown.id && fresh.objectiveRevision === shown.objectiveRevision;
|
|
3344
|
+
}, []);
|
|
3345
|
+
const pause = useCallback5(
|
|
3346
|
+
async (rationale) => {
|
|
3347
|
+
if (!sessionId || !await aimedAtCurrentGoal()) {
|
|
3348
|
+
return null;
|
|
3349
|
+
}
|
|
3350
|
+
const result = await run(
|
|
3351
|
+
() => client.updateGoal(workspaceId, sessionId, {
|
|
3352
|
+
status: "paused",
|
|
3353
|
+
...rationale !== void 0 ? { rationale } : {}
|
|
3354
|
+
})
|
|
3355
|
+
);
|
|
3356
|
+
if (result) {
|
|
3357
|
+
setGoal(result);
|
|
3358
|
+
}
|
|
3359
|
+
return result;
|
|
3360
|
+
},
|
|
3361
|
+
[client, workspaceId, sessionId, run, aimedAtCurrentGoal]
|
|
3362
|
+
);
|
|
3363
|
+
const resume = useCallback5(async () => {
|
|
3364
|
+
if (!sessionId || !await aimedAtCurrentGoal()) {
|
|
3365
|
+
return null;
|
|
3366
|
+
}
|
|
3367
|
+
const result = await run(() => client.updateGoal(workspaceId, sessionId, { status: "active" }));
|
|
3368
|
+
if (result) {
|
|
3369
|
+
setGoal(result);
|
|
3370
|
+
}
|
|
3371
|
+
return result;
|
|
3372
|
+
}, [client, workspaceId, sessionId, run, aimedAtCurrentGoal]);
|
|
3373
|
+
const clearGoal = useCallback5(async () => {
|
|
3374
|
+
if (!sessionId || !await aimedAtCurrentGoal()) {
|
|
3375
|
+
return;
|
|
3376
|
+
}
|
|
3377
|
+
const ok = await run(async () => {
|
|
3378
|
+
await client.deleteGoal(workspaceId, sessionId);
|
|
3379
|
+
return true;
|
|
3380
|
+
});
|
|
3381
|
+
if (ok) {
|
|
3382
|
+
retireLoads();
|
|
3383
|
+
setReadAbsent(true);
|
|
3384
|
+
setGoal(null);
|
|
3385
|
+
setError(null);
|
|
3386
|
+
}
|
|
3387
|
+
}, [client, workspaceId, sessionId, run, retireLoads, aimedAtCurrentGoal]);
|
|
3388
|
+
return {
|
|
3389
|
+
goal: visibleGoal,
|
|
3390
|
+
isActive: visibleGoal?.status === "active",
|
|
3391
|
+
isPaused: visibleGoal?.status === "paused",
|
|
3392
|
+
isCompleted: visibleGoal?.status === "completed",
|
|
3393
|
+
loading: loading && retainedGoal === null,
|
|
3394
|
+
error,
|
|
3395
|
+
refresh: load,
|
|
3396
|
+
pause,
|
|
3397
|
+
resume,
|
|
3398
|
+
clearGoal,
|
|
3399
|
+
deleteGoal: clearGoal,
|
|
3400
|
+
updating: mutating,
|
|
3401
|
+
mutationError,
|
|
3402
|
+
clearMutationError
|
|
3403
|
+
};
|
|
3404
|
+
}
|
|
3405
|
+
|
|
3406
|
+
// src/hooks/use-session-control.ts
|
|
3407
|
+
import { useCallback as useCallback6, useLayoutEffect as useLayoutEffect3, useRef as useRef5 } from "react";
|
|
3408
|
+
function useSessionControl(sessionId, options = {}) {
|
|
3409
|
+
const { client, workspaceId } = useEmbeddedSession(options);
|
|
3410
|
+
const approvalTargetKey = `${workspaceId}\0${sessionId ?? ""}`;
|
|
3411
|
+
const pendingApproval = useRef5(null);
|
|
3412
|
+
useLayoutEffect3(() => {
|
|
3413
|
+
if (pendingApproval.current?.targetKey !== approvalTargetKey) {
|
|
3414
|
+
pendingApproval.current = null;
|
|
3415
|
+
}
|
|
3416
|
+
}, [approvalTargetKey]);
|
|
3417
|
+
const {
|
|
3418
|
+
run: runControl,
|
|
3419
|
+
mutating: controlling,
|
|
3420
|
+
mutationError: controlError,
|
|
3421
|
+
clearMutationError: clearControlError
|
|
3422
|
+
} = useMutationRunner(approvalTargetKey);
|
|
3423
|
+
const {
|
|
3424
|
+
run: runApproval,
|
|
3425
|
+
mutating: responding,
|
|
3426
|
+
mutationError: approvalError,
|
|
3427
|
+
clearMutationError: clearApprovalError
|
|
3428
|
+
} = useMutationRunner(approvalTargetKey);
|
|
3429
|
+
const pause = useCallback6(
|
|
3430
|
+
async (reason) => {
|
|
3431
|
+
if (!sessionId) {
|
|
3432
|
+
return null;
|
|
3433
|
+
}
|
|
3434
|
+
return await runControl(
|
|
3435
|
+
() => client.pauseSession(workspaceId, sessionId, reason !== void 0 ? { reason } : {})
|
|
3436
|
+
);
|
|
3437
|
+
},
|
|
3438
|
+
[client, workspaceId, sessionId, runControl]
|
|
3439
|
+
);
|
|
3440
|
+
const resume = useCallback6(
|
|
3441
|
+
async (reason) => {
|
|
3442
|
+
if (!sessionId) return null;
|
|
3443
|
+
return await runControl(
|
|
3444
|
+
() => client.resumeSession(workspaceId, sessionId, reason !== void 0 ? { reason } : {})
|
|
3445
|
+
);
|
|
3446
|
+
},
|
|
3447
|
+
[client, workspaceId, sessionId, runControl]
|
|
3448
|
+
);
|
|
3449
|
+
const decide = useCallback6(
|
|
3450
|
+
async (approvalId, decision, message, answer, decisionOptions = {}) => {
|
|
3451
|
+
if (!sessionId) {
|
|
3452
|
+
return null;
|
|
3453
|
+
}
|
|
3454
|
+
const decisionKey = JSON.stringify([approvalId, decision, message ?? null, answer ?? null]);
|
|
3455
|
+
if (pendingApproval.current?.decisionKey !== decisionKey) {
|
|
3456
|
+
pendingApproval.current = {
|
|
3457
|
+
targetKey: approvalTargetKey,
|
|
3458
|
+
decisionKey,
|
|
3459
|
+
clientEventId: crypto.randomUUID()
|
|
3460
|
+
};
|
|
3461
|
+
}
|
|
3462
|
+
const clientEventId = pendingApproval.current.clientEventId;
|
|
3463
|
+
let refusal = null;
|
|
3464
|
+
const accepted = await runApproval(async () => {
|
|
3465
|
+
try {
|
|
3466
|
+
return await client.sendApprovalDecision(workspaceId, sessionId, {
|
|
3467
|
+
approvalId,
|
|
3468
|
+
decision,
|
|
3469
|
+
...message !== void 0 ? { message } : {},
|
|
3470
|
+
...answer !== void 0 ? answer : {},
|
|
3471
|
+
clientEventId
|
|
3472
|
+
});
|
|
3473
|
+
} catch (cause) {
|
|
3474
|
+
refusal = { cause };
|
|
3475
|
+
throw cause;
|
|
3476
|
+
}
|
|
3477
|
+
});
|
|
3478
|
+
if (decisionOptions.throwOnError && refusal) throw refusal.cause;
|
|
3479
|
+
if (accepted !== null && pendingApproval.current?.targetKey === approvalTargetKey && pendingApproval.current.clientEventId === clientEventId) {
|
|
3480
|
+
pendingApproval.current = null;
|
|
3481
|
+
}
|
|
3482
|
+
return accepted;
|
|
3483
|
+
},
|
|
3484
|
+
[approvalTargetKey, client, workspaceId, sessionId, runApproval]
|
|
3485
|
+
);
|
|
3486
|
+
const approve = useCallback6(
|
|
3487
|
+
async (approvalId, message, answer, decisionOptions) => await decide(approvalId, "approve", message, answer, decisionOptions),
|
|
3488
|
+
[decide]
|
|
3489
|
+
);
|
|
3490
|
+
const reject = useCallback6(
|
|
3491
|
+
async (approvalId, message, decisionOptions) => await decide(approvalId, "reject", message, void 0, decisionOptions),
|
|
3492
|
+
[decide]
|
|
3493
|
+
);
|
|
3494
|
+
const error = approvalError ?? controlError;
|
|
3495
|
+
const clearError = useCallback6(() => {
|
|
3496
|
+
clearControlError();
|
|
3497
|
+
clearApprovalError();
|
|
3498
|
+
}, [clearControlError, clearApprovalError]);
|
|
3499
|
+
return {
|
|
3500
|
+
pause,
|
|
3501
|
+
resume,
|
|
3502
|
+
controlling,
|
|
3503
|
+
approve,
|
|
3504
|
+
reject,
|
|
3505
|
+
responding,
|
|
3506
|
+
error,
|
|
3507
|
+
clearError
|
|
3508
|
+
};
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3511
|
+
// src/hooks/use-available-models.ts
|
|
3512
|
+
import { useCallback as useCallback7 } from "react";
|
|
3513
|
+
function useAvailableModels(options = {}) {
|
|
3514
|
+
const client = useOpenGeniClient(options);
|
|
3515
|
+
const load = useCallback7(
|
|
3516
|
+
async (signal) => await client.getClientConfig({ signal }),
|
|
3517
|
+
[client]
|
|
3518
|
+
);
|
|
3519
|
+
const state = useSharedQuery(client, ["available-models"], load, {
|
|
3520
|
+
pollIntervalMs: options.pollIntervalMs,
|
|
3521
|
+
enabled: options.enabled
|
|
3522
|
+
});
|
|
3523
|
+
return {
|
|
3524
|
+
models: state.data?.models ?? [],
|
|
3525
|
+
defaultModel: state.data?.defaultModel ?? null,
|
|
3526
|
+
loading: state.loading,
|
|
3527
|
+
error: state.error,
|
|
3528
|
+
refresh: state.refresh
|
|
3529
|
+
};
|
|
3530
|
+
}
|
|
3531
|
+
function useWorkspaceModelCatalog(options) {
|
|
3532
|
+
const t = useOpenGeniText();
|
|
3533
|
+
const client = useOpenGeniClient(options);
|
|
3534
|
+
const load = useCallback7(
|
|
3535
|
+
async (signal) => {
|
|
3536
|
+
if (!options.workspaceId) {
|
|
3537
|
+
return { models: [], defaultModel: null };
|
|
3538
|
+
}
|
|
3539
|
+
const [catalog, config] = await Promise.all([
|
|
3540
|
+
client.getWorkspaceModelCatalog(options.workspaceId, { signal }),
|
|
3541
|
+
// Joins the same workspace's config read already in flight (for
|
|
3542
|
+
// example the composer's voice availability).
|
|
3543
|
+
joinClientConfigRead(client, options.workspaceId)
|
|
3544
|
+
]);
|
|
3545
|
+
return {
|
|
3546
|
+
models: catalog.models,
|
|
3547
|
+
defaultModel: config.defaultModel
|
|
3548
|
+
};
|
|
3549
|
+
},
|
|
3550
|
+
[client, options.workspaceId]
|
|
3551
|
+
);
|
|
3552
|
+
const state = useSharedQuery(client, ["workspace-model-catalog", options.workspaceId], load, {
|
|
3553
|
+
pollIntervalMs: options.pollIntervalMs,
|
|
3554
|
+
enabled: options.enabled !== false && Boolean(options.workspaceId)
|
|
3555
|
+
});
|
|
3556
|
+
const rows = sortPickerRows(projectPickerRows(t, state.data?.models ?? []));
|
|
3557
|
+
return {
|
|
3558
|
+
models: state.data?.models ?? [],
|
|
3559
|
+
rows,
|
|
3560
|
+
defaultModel: state.data?.defaultModel ?? null,
|
|
3561
|
+
loading: state.loading,
|
|
3562
|
+
error: state.error,
|
|
3563
|
+
refresh: state.refresh
|
|
3564
|
+
};
|
|
3565
|
+
}
|
|
3566
|
+
|
|
3567
|
+
// src/hooks/use-human-input.ts
|
|
3568
|
+
import { useCallback as useCallback8, useEffect as useEffect5, useRef as useRef6, useState as useState5 } from "react";
|
|
3569
|
+
function isHumanInputEvent(event) {
|
|
3570
|
+
return event.type === "session.humanInput.requested" || event.type === "user.humanInputResponse" || event.type === "turn.completed" || event.type === "turn.failed" || event.type === "turn.cancelled";
|
|
3571
|
+
}
|
|
3572
|
+
function useHumanInputRequests(sessionId, options = {}) {
|
|
3573
|
+
const { client, workspaceId, registerSessionReconciler } = useEmbeddedHumanInputSession(options);
|
|
3574
|
+
const enabled = (options.enabled ?? true) && Boolean(sessionId);
|
|
3575
|
+
const load = useCallback8(async () => {
|
|
3576
|
+
if (!sessionId) return [];
|
|
3577
|
+
const readStartedAt = Date.now();
|
|
3578
|
+
const requests = await client.listHumanInputRequests(workspaceId, sessionId, {
|
|
3579
|
+
status: "pending"
|
|
3580
|
+
});
|
|
3581
|
+
const now2 = Date.now();
|
|
3582
|
+
pruneHumanInputDrafts(
|
|
3583
|
+
workspaceId,
|
|
3584
|
+
sessionId,
|
|
3585
|
+
requests.filter((request) => isActionableHumanInputRequest(request, now2)).map((request) => request.id),
|
|
3586
|
+
readStartedAt
|
|
3587
|
+
);
|
|
3588
|
+
return requests;
|
|
3589
|
+
}, [client, sessionId, workspaceId]);
|
|
3590
|
+
const state = usePolledValue(load, {
|
|
3591
|
+
enabled,
|
|
3592
|
+
pollIntervalMs: options.pollIntervalMs
|
|
3593
|
+
});
|
|
3594
|
+
const loadedRequests = state.data;
|
|
3595
|
+
const refreshRequests = state.refresh;
|
|
3596
|
+
const readDenied = enabled && Boolean(sessionId) && deniesRetainedView(state.error);
|
|
3597
|
+
useEffect5(() => {
|
|
3598
|
+
if (readDenied && sessionId) forgetSessionHumanInputDrafts(workspaceId, sessionId);
|
|
3599
|
+
}, [readDenied, sessionId, workspaceId]);
|
|
3600
|
+
const mutation = useMutationRunner(`${workspaceId}\0${sessionId ?? ""}`);
|
|
3601
|
+
const [respondingRequestId, setRespondingRequestId] = useState5(null);
|
|
3602
|
+
const [deadlineVersion, setDeadlineVersion] = useState5(0);
|
|
3603
|
+
const respondingRequestRef = useRef6(null);
|
|
3604
|
+
useEffect5(() => {
|
|
3605
|
+
respondingRequestRef.current = null;
|
|
3606
|
+
setRespondingRequestId(null);
|
|
3607
|
+
}, [sessionId, workspaceId]);
|
|
3608
|
+
useEffect5(() => {
|
|
3609
|
+
if (!sessionId || !enabled) return;
|
|
3610
|
+
return registerSessionReconciler(sessionId, "human-input", state.refresh);
|
|
3611
|
+
}, [enabled, registerSessionReconciler, sessionId, state.refresh]);
|
|
3612
|
+
const scheduleRefresh = useDebouncedCallback(() => void state.refresh());
|
|
3613
|
+
useSessionEventTrigger(client, workspaceId, sessionId, isHumanInputEvent, scheduleRefresh, {
|
|
3614
|
+
enabled,
|
|
3615
|
+
...options.events !== void 0 ? { events: options.events } : {},
|
|
3616
|
+
readThrough: projectionReadThrough(state.data, state.loading),
|
|
3617
|
+
refresh: scheduleRefresh
|
|
3618
|
+
});
|
|
3619
|
+
const retainedRequests = useRetainedSessionView(
|
|
3620
|
+
client,
|
|
3621
|
+
workspaceId,
|
|
3622
|
+
sessionId,
|
|
3623
|
+
"human-input",
|
|
3624
|
+
state.data,
|
|
3625
|
+
{ enabled, discard: deniesRetainedView(state.error) }
|
|
3626
|
+
);
|
|
3627
|
+
useEffect5(() => {
|
|
3628
|
+
const now2 = Date.now();
|
|
3629
|
+
const nextDeadline = (loadedRequests ?? []).reduce((next, request) => {
|
|
3630
|
+
if (request.status !== "pending" || !request.expiresAt) return next;
|
|
3631
|
+
const deadline = Date.parse(request.expiresAt);
|
|
3632
|
+
if (!Number.isFinite(deadline) || deadline <= now2) return next;
|
|
3633
|
+
return next === null ? deadline : Math.min(next, deadline);
|
|
3634
|
+
}, null);
|
|
3635
|
+
if (nextDeadline === null) return;
|
|
3636
|
+
const timer = globalThis.setTimeout(
|
|
3637
|
+
() => {
|
|
3638
|
+
setDeadlineVersion((current) => current + 1);
|
|
3639
|
+
void refreshRequests();
|
|
3640
|
+
},
|
|
3641
|
+
Math.min(2147483647, Math.max(0, nextDeadline - now2 + 1))
|
|
3642
|
+
);
|
|
3643
|
+
return () => globalThis.clearTimeout(timer);
|
|
3644
|
+
}, [loadedRequests, refreshRequests]);
|
|
3645
|
+
const respond = useCallback8(
|
|
3646
|
+
async (requestId, response) => {
|
|
3647
|
+
if (!sessionId || respondingRequestRef.current !== null) return null;
|
|
3648
|
+
respondingRequestRef.current = requestId;
|
|
3649
|
+
setRespondingRequestId(requestId);
|
|
3650
|
+
try {
|
|
3651
|
+
const event = await mutation.run(
|
|
3652
|
+
() => client.submitHumanInputResponse(workspaceId, sessionId, requestId, response, {
|
|
3653
|
+
clientEventId: globalThis.crypto.randomUUID()
|
|
3654
|
+
})
|
|
3655
|
+
);
|
|
3656
|
+
if (event) await state.refresh();
|
|
3657
|
+
return event;
|
|
3658
|
+
} finally {
|
|
3659
|
+
if (respondingRequestRef.current === requestId) {
|
|
3660
|
+
respondingRequestRef.current = null;
|
|
3661
|
+
setRespondingRequestId(null);
|
|
3662
|
+
}
|
|
3663
|
+
}
|
|
3664
|
+
},
|
|
3665
|
+
[client, mutation, sessionId, state, workspaceId]
|
|
3666
|
+
);
|
|
3667
|
+
const now = Date.now();
|
|
3668
|
+
void deadlineVersion;
|
|
3669
|
+
return {
|
|
3670
|
+
requests: [...state.data ?? retainedRequests ?? []].filter((request) => isActionableHumanInputRequest(request, now)).sort(
|
|
3671
|
+
(left, right) => left.createdAt.localeCompare(right.createdAt) || left.id.localeCompare(right.id)
|
|
3672
|
+
),
|
|
3673
|
+
loading: state.loading && retainedRequests === null,
|
|
3674
|
+
error: state.error,
|
|
3675
|
+
refresh: state.refresh,
|
|
3676
|
+
respond,
|
|
3677
|
+
respondingRequestId,
|
|
3678
|
+
mutationError: mutation.mutationError,
|
|
3679
|
+
clearMutationError: mutation.clearMutationError
|
|
3680
|
+
};
|
|
3681
|
+
}
|
|
3682
|
+
|
|
3683
|
+
// src/conversation-timeline.ts
|
|
3684
|
+
function conversationTimeline(items, queue, composer) {
|
|
3685
|
+
const queued = new Set(
|
|
3686
|
+
queue.queue.filter((turn) => turn.metadata.delivery !== "steer").map((turn) => turn.triggerEventId)
|
|
3687
|
+
);
|
|
3688
|
+
const pending = composer.optimisticMessages ?? [];
|
|
3689
|
+
const pendingQueue = new Set(
|
|
3690
|
+
pending.filter(
|
|
3691
|
+
(message) => message.destination === "queue" && !(message.turnId && message.appliedQueueVersion != null && queue.snapshot && queue.snapshot.version >= message.appliedQueueVersion && !queue.queue.some((turn) => turn.id === message.turnId))
|
|
3692
|
+
).map((message) => `user-message:${message.clientEventId}`)
|
|
3693
|
+
);
|
|
3694
|
+
const visible = items.filter(
|
|
3695
|
+
(item) => item.kind !== "user-message" || !queued.has(item.id) && !pendingQueue.has(item.reconciliationKey ?? "")
|
|
3696
|
+
);
|
|
3697
|
+
const keys = new Set(
|
|
3698
|
+
visible.flatMap((item) => item.kind === "user-message" ? [item.reconciliationKey] : [])
|
|
3699
|
+
);
|
|
3700
|
+
const optimistic = pending.filter(
|
|
3701
|
+
(message) => (message.destination === "chat" || message.state === "failed") && !keys.has(`user-message:${message.clientEventId}`) && !queue.queue.some((turn) => turn.id === message.turnId)
|
|
3702
|
+
).map((message) => ({
|
|
3703
|
+
kind: "user-message",
|
|
3704
|
+
id: `optimistic:${message.clientEventId}`,
|
|
3705
|
+
reconciliationKey: `user-message:${message.clientEventId}`,
|
|
3706
|
+
text: message.text,
|
|
3707
|
+
annotations: message.annotations.map((annotation, ordinal) => ({ ...annotation, ordinal })),
|
|
3708
|
+
resources: message.resources,
|
|
3709
|
+
tools: [],
|
|
3710
|
+
occurredAt: message.occurredAt,
|
|
3711
|
+
delivery: {
|
|
3712
|
+
state: message.state,
|
|
3713
|
+
...message.error ? { error: message.error } : {},
|
|
3714
|
+
...message.state === "failed" ? {
|
|
3715
|
+
...message.retryable !== false && composer.retryOptimisticMessage ? { onRetry: () => composer.retryOptimisticMessage?.(message.clientEventId) } : {},
|
|
3716
|
+
...message.retryable === false && composer.restoreOptimisticMessage ? { onEdit: () => composer.restoreOptimisticMessage?.(message.clientEventId) } : {},
|
|
3717
|
+
onRemove: () => composer.removeOptimisticMessage?.(message.clientEventId)
|
|
3718
|
+
} : {}
|
|
3719
|
+
}
|
|
3720
|
+
}));
|
|
3721
|
+
const failed = optimistic.filter((message) => message.delivery?.state === "failed");
|
|
3722
|
+
const unsent = optimistic.filter((message) => message.delivery?.state !== "failed");
|
|
3723
|
+
const ids = new Set(visible.map((item) => item.id));
|
|
3724
|
+
const steers = (queue.acceptedSteers ?? []).filter((steer) => !ids.has(steer.triggerEventId)).map((steer) => ({
|
|
3725
|
+
kind: "user-message",
|
|
3726
|
+
id: steer.triggerEventId,
|
|
3727
|
+
text: steer.text,
|
|
3728
|
+
annotations: steer.annotations,
|
|
3729
|
+
resources: steer.resources,
|
|
3730
|
+
tools: steer.tools,
|
|
3731
|
+
occurredAt: steer.occurredAt,
|
|
3732
|
+
delivery: { state: steer.state }
|
|
3733
|
+
}));
|
|
3734
|
+
return [...placeFailedSends(visible, failed), ...unsent, ...steers];
|
|
3735
|
+
}
|
|
3736
|
+
function placeFailedSends(items, failed) {
|
|
3737
|
+
if (failed.length === 0) return items;
|
|
3738
|
+
const before = /* @__PURE__ */ new Map();
|
|
3739
|
+
const last = [];
|
|
3740
|
+
for (const message of failed) {
|
|
3741
|
+
const sentAt = Date.parse(message.occurredAt);
|
|
3742
|
+
const newer = items.findIndex(
|
|
3743
|
+
(item) => item.kind === "user-message" && Date.parse(item.occurredAt) > sentAt
|
|
3744
|
+
);
|
|
3745
|
+
if (newer === -1) {
|
|
3746
|
+
last.push(message);
|
|
3747
|
+
} else {
|
|
3748
|
+
before.set(newer, [...before.get(newer) ?? [], message]);
|
|
3749
|
+
}
|
|
3750
|
+
}
|
|
3751
|
+
return [...items.flatMap((item, index) => [...before.get(index) ?? [], item]), ...last];
|
|
3752
|
+
}
|
|
3753
|
+
|
|
3754
|
+
// src/lib/session-startup-timeline.tsx
|
|
3755
|
+
import { useRef as useRef7 } from "react";
|
|
3756
|
+
function currentEvents(events) {
|
|
3757
|
+
return events.filter(
|
|
3758
|
+
(event) => !event.duplicateOfEventId && (!event.turnAssociation || event.turnAssociation === "current")
|
|
3759
|
+
).sort((a, b) => a.sequence - b.sequence);
|
|
3760
|
+
}
|
|
3761
|
+
function payloadOf(event) {
|
|
3762
|
+
return event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
3763
|
+
}
|
|
3764
|
+
function sessionStartupTimeline(items, input) {
|
|
3765
|
+
const { session, optimisticMessages, hasNewer } = input;
|
|
3766
|
+
if (hasNewer || session.effectiveControl.state !== "active" || !["idle", "queued", "running"].includes(session.status) || session.status === "idle" && session.inputWait)
|
|
3767
|
+
return items;
|
|
3768
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
3769
|
+
const pending = /* @__PURE__ */ new Map();
|
|
3770
|
+
let queueVersion = session.queueVersion;
|
|
3771
|
+
let newerProgress = false;
|
|
3772
|
+
let observedActiveTurn = null;
|
|
3773
|
+
let previousTurnEndedAt = null;
|
|
3774
|
+
for (const event of currentEvents(input.events)) {
|
|
3775
|
+
const payload = payloadOf(event);
|
|
3776
|
+
if (event.turnId && ["turn.completed", "turn.failed", "turn.cancelled", "turn.superseded"].includes(event.type))
|
|
3777
|
+
previousTurnEndedAt = event.occurredAt;
|
|
3778
|
+
if (event.sequence > session.lastSequence && ([
|
|
3779
|
+
"turn.started",
|
|
3780
|
+
"turn.completed",
|
|
3781
|
+
"turn.failed",
|
|
3782
|
+
"turn.cancelled",
|
|
3783
|
+
"turn.superseded"
|
|
3784
|
+
].includes(event.type) || event.type === "session.status.changed" && payload.status !== "queued" || event.type === "session.queue.changed" && ["edit", "delete"].includes(String(payload.operation))))
|
|
3785
|
+
newerProgress = true;
|
|
3786
|
+
if (event.type === "session.queue.changed" && typeof payload.queueVersion === "number")
|
|
3787
|
+
queueVersion = Math.max(queueVersion, payload.queueVersion);
|
|
3788
|
+
const turnId2 = event.turnId ?? (typeof payload.turnId === "string" ? payload.turnId : null);
|
|
3789
|
+
if (!turnId2) continue;
|
|
3790
|
+
if (event.sequence > session.lastSequence) {
|
|
3791
|
+
if (event.type === "turn.started") observedActiveTurn = turnId2;
|
|
3792
|
+
else if (observedActiveTurn === turnId2 && ["turn.completed", "turn.failed", "turn.cancelled", "turn.superseded"].includes(event.type))
|
|
3793
|
+
observedActiveTurn = null;
|
|
3794
|
+
}
|
|
3795
|
+
if ([
|
|
3796
|
+
"turn.started",
|
|
3797
|
+
"turn.completed",
|
|
3798
|
+
"turn.failed",
|
|
3799
|
+
"turn.cancelled",
|
|
3800
|
+
"turn.superseded"
|
|
3801
|
+
].includes(event.type) || event.type === "session.queue.changed" && ["edit", "delete"].includes(String(payload.operation)))
|
|
3802
|
+
claimed.add(turnId2);
|
|
3803
|
+
if ((event.type === "turn.queued" || event.type === "user.message") && payload.routing === "accepted_for_execution" && (session.status !== "idle" || event.sequence > session.lastSequence))
|
|
3804
|
+
pending.set(turnId2, event.occurredAt);
|
|
3805
|
+
}
|
|
3806
|
+
for (const message of optimisticMessages ?? []) {
|
|
3807
|
+
if (message.state === "queued" && message.destination === "chat" && message.delivery === "send" && message.turnId && !pending.has(message.turnId) && (session.status !== "idle" || message.appliedQueueVersion != null && message.appliedQueueVersion > session.queueVersion))
|
|
3808
|
+
pending.set(message.turnId, message.occurredAt);
|
|
3809
|
+
}
|
|
3810
|
+
const head = input.queue && input.queue.version >= queueVersion ? input.queue.items[0] : null;
|
|
3811
|
+
if (session.status === "queued" && !session.activeTurnId && head && !pending.has(head.id))
|
|
3812
|
+
pending.set(
|
|
3813
|
+
head.id,
|
|
3814
|
+
previousTurnEndedAt && previousTurnEndedAt > head.createdAt ? previousTurnEndedAt : head.createdAt
|
|
3815
|
+
);
|
|
3816
|
+
const candidate = [...pending].find(
|
|
3817
|
+
([turnId2]) => !claimed.has(turnId2) && (!session.activeTurnId || session.activeTurnId === turnId2) && (!observedActiveTurn || observedActiveTurn === turnId2) && !items.some((item) => "turnId" in item && item.turnId === turnId2)
|
|
3818
|
+
);
|
|
3819
|
+
const fallback = !candidate && !newerProgress && session.status === "queued" && !session.activeTurnId && input.fallbackStartedAt;
|
|
3820
|
+
if (!candidate && !fallback) return items;
|
|
3821
|
+
const [turnId, startedAt] = candidate ?? [
|
|
3822
|
+
`pending-startup:${session.id}`,
|
|
3823
|
+
input.fallbackStartedAt
|
|
3824
|
+
];
|
|
3825
|
+
return [
|
|
3826
|
+
...items,
|
|
3827
|
+
{
|
|
3828
|
+
kind: "startup-phase",
|
|
3829
|
+
id: `${turnId}-queue`,
|
|
3830
|
+
turnId,
|
|
3831
|
+
phase: "queue",
|
|
3832
|
+
status: "running",
|
|
3833
|
+
startedAt,
|
|
3834
|
+
occurredAt: startedAt,
|
|
3835
|
+
completedAt: null,
|
|
3836
|
+
durationMs: null,
|
|
3837
|
+
outcome: null,
|
|
3838
|
+
...session.activeTurnId ? {} : { dispatchWait: session.status === "queued" ? session.dispatchWait ?? null : null }
|
|
3839
|
+
}
|
|
3840
|
+
];
|
|
3841
|
+
}
|
|
3842
|
+
var PENDING_SCOPE = "pending-prompt";
|
|
3843
|
+
var PENDING_PROMPT_STARTUP_ID = "pending-prompt-startup";
|
|
3844
|
+
function pendingPromptItems(prompt) {
|
|
3845
|
+
return [
|
|
3846
|
+
{
|
|
3847
|
+
kind: "user-message",
|
|
3848
|
+
id: "pending-prompt-message",
|
|
3849
|
+
text: prompt.text,
|
|
3850
|
+
resources: prompt.resources ?? [],
|
|
3851
|
+
tools: [],
|
|
3852
|
+
occurredAt: prompt.sentAt
|
|
3853
|
+
},
|
|
3854
|
+
{
|
|
3855
|
+
kind: "startup-phase",
|
|
3856
|
+
id: PENDING_PROMPT_STARTUP_ID,
|
|
3857
|
+
turnId: PENDING_SCOPE,
|
|
3858
|
+
phase: "queue",
|
|
3859
|
+
status: "running",
|
|
3860
|
+
startedAt: prompt.sentAt,
|
|
3861
|
+
occurredAt: prompt.sentAt,
|
|
3862
|
+
completedAt: null,
|
|
3863
|
+
durationMs: null,
|
|
3864
|
+
outcome: null
|
|
3865
|
+
}
|
|
3866
|
+
];
|
|
3867
|
+
}
|
|
3868
|
+
function useSessionStartupTimeline(items, input) {
|
|
3869
|
+
const startup = useSessionStartupState(input.session);
|
|
3870
|
+
const bridgeRef = useRef7(null);
|
|
3871
|
+
const { pendingPrompt } = input;
|
|
3872
|
+
if (pendingPrompt && (!input.session || input.historyReady === false)) {
|
|
3873
|
+
bridgeRef.current = {
|
|
3874
|
+
scope: PENDING_SCOPE,
|
|
3875
|
+
id: PENDING_PROMPT_STARTUP_ID,
|
|
3876
|
+
turnId: null,
|
|
3877
|
+
since: pendingPrompt.sentAt,
|
|
3878
|
+
sequence: 0
|
|
3879
|
+
};
|
|
3880
|
+
return [...items, ...pendingPromptItems(pendingPrompt)];
|
|
3881
|
+
}
|
|
3882
|
+
if (!input.session) {
|
|
3883
|
+
bridgeRef.current = null;
|
|
3884
|
+
return items;
|
|
3885
|
+
}
|
|
3886
|
+
const scope = `${input.session.workspaceId}:${input.session.id}`;
|
|
3887
|
+
if (bridgeRef.current?.scope === PENDING_SCOPE)
|
|
3888
|
+
bridgeRef.current = { ...bridgeRef.current, scope };
|
|
3889
|
+
if (bridgeRef.current?.scope !== scope || input.hasNewer || input.session.effectiveControl.state !== "active" || !["queued", "running", "idle"].includes(input.session.status))
|
|
3890
|
+
bridgeRef.current = null;
|
|
3891
|
+
const boundTurn = bridgeRef.current?.turnId;
|
|
3892
|
+
const settled = boundTurn && currentEvents(input.events).find(
|
|
3893
|
+
(event) => event.turnId === boundTurn && ["turn.completed", "turn.failed", "turn.cancelled", "turn.superseded"].includes(event.type)
|
|
3894
|
+
);
|
|
3895
|
+
let fallbackStartedAt = bridgeRef.current?.turnId === null ? bridgeRef.current.since : startup?.startedAt;
|
|
3896
|
+
if (settled) {
|
|
3897
|
+
bridgeRef.current = null;
|
|
3898
|
+
fallbackStartedAt = input.session.status === "queued" && input.session.lastSequence >= settled.sequence ? input.session.updatedAt : void 0;
|
|
3899
|
+
}
|
|
3900
|
+
const projected = sessionStartupTimeline(items, {
|
|
3901
|
+
...input,
|
|
3902
|
+
session: input.session,
|
|
3903
|
+
fallbackStartedAt
|
|
3904
|
+
});
|
|
3905
|
+
if (projected !== items) {
|
|
3906
|
+
const phase2 = projected.at(-1);
|
|
3907
|
+
if (phase2.kind !== "startup-phase") return projected;
|
|
3908
|
+
const turnId2 = phase2.turnId === `pending-startup:${input.session.id}` ? null : phase2.turnId;
|
|
3909
|
+
let bridge2 = bridgeRef.current;
|
|
3910
|
+
if (!bridge2 || bridge2.turnId && turnId2 && bridge2.turnId !== turnId2) {
|
|
3911
|
+
bridge2 = {
|
|
3912
|
+
scope,
|
|
3913
|
+
id: phase2.id,
|
|
3914
|
+
turnId: turnId2,
|
|
3915
|
+
since: phase2.startedAt,
|
|
3916
|
+
sequence: input.session.lastSequence
|
|
3917
|
+
};
|
|
3918
|
+
} else
|
|
3919
|
+
bridge2 = {
|
|
3920
|
+
...bridge2,
|
|
3921
|
+
turnId: turnId2 ?? bridge2.turnId,
|
|
3922
|
+
since: bridge2.since < phase2.startedAt ? bridge2.since : phase2.startedAt
|
|
3923
|
+
};
|
|
3924
|
+
bridgeRef.current = bridge2;
|
|
3925
|
+
return [
|
|
3926
|
+
...projected.slice(0, -1),
|
|
3927
|
+
{ ...phase2, id: bridge2.id, startedAt: bridge2.since, occurredAt: bridge2.since }
|
|
3928
|
+
];
|
|
3929
|
+
}
|
|
3930
|
+
const bridge = bridgeRef.current;
|
|
3931
|
+
if (!bridge) return items;
|
|
3932
|
+
if (input.session.status === "idle") {
|
|
3933
|
+
bridgeRef.current = null;
|
|
3934
|
+
return items;
|
|
3935
|
+
}
|
|
3936
|
+
const started = currentEvents(input.events).find(
|
|
3937
|
+
(event) => event.type === "turn.started" && (bridge.turnId ? event.turnId === bridge.turnId : event.sequence > bridge.sequence)
|
|
3938
|
+
);
|
|
3939
|
+
const turnId = bridge.turnId ?? started?.turnId ?? input.session.activeTurnId;
|
|
3940
|
+
const phase = items.find((item) => item.kind === "startup-phase" && item.turnId === turnId);
|
|
3941
|
+
if (phase?.kind === "startup-phase") {
|
|
3942
|
+
bridgeRef.current = { ...bridge, turnId };
|
|
3943
|
+
return items.map(
|
|
3944
|
+
(item) => item === phase ? {
|
|
3945
|
+
...phase,
|
|
3946
|
+
id: bridge.id,
|
|
3947
|
+
loadingStartedAt: bridge.since < phase.startedAt ? bridge.since : phase.startedAt
|
|
3948
|
+
} : item
|
|
3949
|
+
);
|
|
3950
|
+
}
|
|
3951
|
+
if (turnId && (started || input.session.activeTurnId === turnId)) {
|
|
3952
|
+
bridgeRef.current = { ...bridge, turnId };
|
|
3953
|
+
return [
|
|
3954
|
+
...items,
|
|
3955
|
+
{
|
|
3956
|
+
kind: "startup-phase",
|
|
3957
|
+
id: bridge.id,
|
|
3958
|
+
turnId,
|
|
3959
|
+
phase: "queue",
|
|
3960
|
+
status: "complete",
|
|
3961
|
+
startedAt: bridge.since,
|
|
3962
|
+
occurredAt: bridge.since,
|
|
3963
|
+
completedAt: started?.occurredAt ?? input.session.updatedAt,
|
|
3964
|
+
durationMs: null,
|
|
3965
|
+
outcome: null
|
|
3966
|
+
}
|
|
3967
|
+
];
|
|
3968
|
+
}
|
|
3969
|
+
if (turnId) bridgeRef.current = null;
|
|
3970
|
+
return items;
|
|
3971
|
+
}
|
|
3972
|
+
|
|
3973
|
+
// src/hooks/use-session-conversation.ts
|
|
3974
|
+
import { useLayoutEffect as useLayoutEffect4, useMemo as useMemo4, useRef as useRef8, useState as useState6 } from "react";
|
|
3975
|
+
function useSessionConversation(sessionId, options = {}) {
|
|
3976
|
+
const [initialPrompt] = useState6(() => options.pendingPrompt ?? null);
|
|
3977
|
+
const context = useOpenGeni(options);
|
|
3978
|
+
const scope = { client: context.client, workspaceId: context.workspaceId };
|
|
3979
|
+
const config = useClientConfigFlags(context.client);
|
|
3980
|
+
const showModelPicker = options.modelPicker ?? config.modelSelection;
|
|
3981
|
+
const catalog = useWorkspaceModelCatalog({ ...scope, enabled: showModelPicker });
|
|
3982
|
+
const feed = useSessionEvents(sessionId, scope);
|
|
3983
|
+
const pendingPrompt = usePendingPrompt(initialPrompt, sessionId, feed.initialHistoryReady);
|
|
3984
|
+
const eventOptions = { ...scope, events: feed.events };
|
|
3985
|
+
const detail = useSession(sessionId, eventOptions);
|
|
3986
|
+
const queue = useTurnQueue(sessionId, eventOptions);
|
|
3987
|
+
const human = useHumanInputRequests(sessionId, eventOptions);
|
|
3988
|
+
const control = useSessionControl(sessionId, scope);
|
|
3989
|
+
const approvals = useMemo4(() => projectPendingApprovals(feed.events), [feed.events]);
|
|
3990
|
+
const files = useFileAttachments({ ...scope, scope: uploadScopeForSession(detail.session) });
|
|
3991
|
+
const clearFiles = files.clear;
|
|
3992
|
+
const attachmentSession = useRef8(sessionId);
|
|
3993
|
+
useLayoutEffect4(() => {
|
|
3994
|
+
if (attachmentSession.current === sessionId) return;
|
|
3995
|
+
const created = attachmentSession.current === null;
|
|
3996
|
+
attachmentSession.current = sessionId;
|
|
3997
|
+
if (created) return;
|
|
3998
|
+
clearFiles();
|
|
3999
|
+
}, [clearFiles, sessionId]);
|
|
4000
|
+
const uploadsEnabled = (options.attachments ?? true) && config.uploads;
|
|
4001
|
+
const status = feed.sessionStatus ?? detail.session?.status;
|
|
4002
|
+
const terminal = status === "cancelled" || (detail.session ? sessionArchived(detail.session) : false);
|
|
4003
|
+
const importedArchive = detail.session?.importedArchive?.readOnly === true;
|
|
4004
|
+
const host = options.composerOptions;
|
|
4005
|
+
const resolveExtras = () => typeof host?.sendExtras === "function" ? host.sendExtras() : host?.sendExtras;
|
|
4006
|
+
const releaseSentFiles = (input) => files.removeReadyFiles(
|
|
4007
|
+
(input.resources ?? []).flatMap(
|
|
4008
|
+
(resource) => resource.kind === "file" ? [resource.fileId] : []
|
|
4009
|
+
)
|
|
4010
|
+
);
|
|
4011
|
+
const composer = useComposer(sessionId, {
|
|
4012
|
+
...eventOptions,
|
|
4013
|
+
initialDraft: host?.initialDraft,
|
|
4014
|
+
busySend: host?.busySend,
|
|
4015
|
+
offerQueue: host?.offerQueue,
|
|
4016
|
+
effectiveControl: queue.effectiveControl ?? detail.session?.effectiveControl,
|
|
4017
|
+
// As in the console and the native screen: a turn that is still current
|
|
4018
|
+
// (running or recovering) means a Send waits. A turn parked on provider
|
|
4019
|
+
// capacity does not: the Send replaces it and starts right away.
|
|
4020
|
+
sendDestination: () => promptSendDestination({
|
|
4021
|
+
status,
|
|
4022
|
+
activeTurnId: detail.session?.activeTurnId,
|
|
4023
|
+
queuedPrompts: queue.queue.length,
|
|
4024
|
+
admissionBlock: detail.session?.admissionBlock
|
|
4025
|
+
}),
|
|
4026
|
+
sendExtras: () => {
|
|
4027
|
+
const extras = resolveExtras();
|
|
4028
|
+
return {
|
|
4029
|
+
...extras,
|
|
4030
|
+
resources: [...extras?.resources ?? [], ...uploadsEnabled ? files.readyResources : []]
|
|
4031
|
+
};
|
|
4032
|
+
},
|
|
4033
|
+
sendBlocked: () => sessionId === null || terminal || importedArchive || uploadsEnabled && files.hasUnresolved || host?.sendBlocked?.() === true,
|
|
4034
|
+
onSubmitted: (text, input) => {
|
|
4035
|
+
releaseSentFiles(input);
|
|
4036
|
+
return host?.onSubmitted?.(text, input);
|
|
4037
|
+
},
|
|
4038
|
+
onSent: (text, input) => {
|
|
4039
|
+
releaseSentFiles(input);
|
|
4040
|
+
return host?.onSent?.(text, input);
|
|
4041
|
+
},
|
|
4042
|
+
onDeliveryError: host?.onDeliveryError
|
|
4043
|
+
});
|
|
4044
|
+
const conversation = useMemo4(
|
|
4045
|
+
() => conversationTimeline(feed.timeline, queue, composer),
|
|
4046
|
+
[feed.timeline, queue, composer]
|
|
4047
|
+
);
|
|
4048
|
+
const session = detail.session;
|
|
4049
|
+
const sessionControl = session?.effectiveControl;
|
|
4050
|
+
const timeline = useSessionStartupTimeline(conversation, {
|
|
4051
|
+
session: session && sessionControl ? {
|
|
4052
|
+
...session,
|
|
4053
|
+
effectiveControl: admissionRecheckControl(
|
|
4054
|
+
sessionControl,
|
|
4055
|
+
queue.effectiveControl,
|
|
4056
|
+
composer.effectiveControl
|
|
4057
|
+
)
|
|
4058
|
+
} : null,
|
|
4059
|
+
events: feed.events,
|
|
4060
|
+
optimisticMessages: composer.optimisticMessages,
|
|
4061
|
+
hasNewer: feed.hasNewer,
|
|
4062
|
+
queue: queue.snapshot,
|
|
4063
|
+
pendingPrompt,
|
|
4064
|
+
historyReady: sessionId !== null && feed.initialHistoryReady
|
|
4065
|
+
});
|
|
4066
|
+
const error = detail.error ?? feed.error ?? human.error;
|
|
4067
|
+
const loadFailed = Boolean(feed.error) && !feed.initialHistoryReady;
|
|
4068
|
+
const retry = async () => {
|
|
4069
|
+
await Promise.all([
|
|
4070
|
+
...detail.error ? [detail.refresh()] : [],
|
|
4071
|
+
...human.error ? [human.refresh()] : [],
|
|
4072
|
+
...feed.error ? [feed.jumpToLatest()] : []
|
|
4073
|
+
]);
|
|
4074
|
+
};
|
|
4075
|
+
return {
|
|
4076
|
+
...scope,
|
|
4077
|
+
sessionId,
|
|
4078
|
+
config,
|
|
4079
|
+
catalog,
|
|
4080
|
+
showModelPicker,
|
|
4081
|
+
feed,
|
|
4082
|
+
detail,
|
|
4083
|
+
queue,
|
|
4084
|
+
human,
|
|
4085
|
+
control,
|
|
4086
|
+
approvals,
|
|
4087
|
+
files,
|
|
4088
|
+
uploadsEnabled,
|
|
4089
|
+
composer,
|
|
4090
|
+
/** The same live application context for text and durable voice messages. */
|
|
4091
|
+
getModelContext: () => resolveExtras()?.modelContext,
|
|
4092
|
+
timeline,
|
|
4093
|
+
status,
|
|
4094
|
+
terminal,
|
|
4095
|
+
importedArchive,
|
|
4096
|
+
running: sessionTurnKeepsRunControl(status),
|
|
4097
|
+
error,
|
|
4098
|
+
loadFailed,
|
|
4099
|
+
retry
|
|
4100
|
+
};
|
|
4101
|
+
}
|
|
4102
|
+
function usePendingPrompt(prompt, sessionId, historyReady) {
|
|
4103
|
+
const owner = useRef8({
|
|
4104
|
+
sessionId,
|
|
4105
|
+
retired: prompt === null
|
|
4106
|
+
});
|
|
4107
|
+
const current = owner.current;
|
|
4108
|
+
if (!current.retired && current.sessionId !== sessionId) {
|
|
4109
|
+
if (current.sessionId === null) current.sessionId = sessionId;
|
|
4110
|
+
else current.retired = true;
|
|
4111
|
+
}
|
|
4112
|
+
if (!current.retired && sessionId !== null && historyReady) current.retired = true;
|
|
4113
|
+
return current.retired ? null : prompt;
|
|
4114
|
+
}
|
|
4115
|
+
|
|
4116
|
+
// src/hooks/use-session-read-acknowledgement.ts
|
|
4117
|
+
import { useEffect as useEffect6, useMemo as useMemo5, useRef as useRef9 } from "react";
|
|
4118
|
+
var SESSION_READ_ACKNOWLEDGEMENT_RETRY_MS = 1e3;
|
|
4119
|
+
function isPermanentRejection(error) {
|
|
4120
|
+
const status = error && typeof error === "object" ? error.status : void 0;
|
|
4121
|
+
return typeof status === "number" && status >= 400 && status < 500 && status !== 408 && status !== 429;
|
|
4122
|
+
}
|
|
4123
|
+
function useSessionReadAcknowledgement(input) {
|
|
4124
|
+
const { client, workspaceId, sessionId, events, active } = input;
|
|
4125
|
+
const session = input.session && (input.session.id ?? sessionId) === sessionId ? input.session : null;
|
|
4126
|
+
const attentionThrough = useMemo5(() => sessionAttentionReadThroughSequence(events), [events]);
|
|
4127
|
+
const { readThrough, unread } = readAcknowledgementFrontier(session, attentionThrough);
|
|
4128
|
+
const hasSession = session !== null;
|
|
4129
|
+
const receipt = useRef9(null);
|
|
4130
|
+
const refused = useRef9(/* @__PURE__ */ new Set());
|
|
4131
|
+
const retryTimer = useRef9(null);
|
|
4132
|
+
useEffect6(
|
|
4133
|
+
() => () => {
|
|
4134
|
+
if (retryTimer.current !== null) clearTimeout(retryTimer.current);
|
|
4135
|
+
retryTimer.current = null;
|
|
4136
|
+
receipt.current = null;
|
|
4137
|
+
},
|
|
4138
|
+
[]
|
|
4139
|
+
);
|
|
4140
|
+
useEffect6(() => {
|
|
4141
|
+
if (!active || !hasSession || !unread || readThrough <= 0) return;
|
|
4142
|
+
if (!workspaceId || !sessionId || typeof client.updateSessionAttention !== "function") return;
|
|
4143
|
+
const scope = `${workspaceId}:${sessionId}`;
|
|
4144
|
+
if (refused.current.has(scope)) return;
|
|
4145
|
+
const key = `${scope}:${readThrough}`;
|
|
4146
|
+
if (receipt.current === key) return;
|
|
4147
|
+
receipt.current = key;
|
|
4148
|
+
if (retryTimer.current !== null) clearTimeout(retryTimer.current);
|
|
4149
|
+
retryTimer.current = null;
|
|
4150
|
+
const attempt = (retried) => {
|
|
4151
|
+
void Promise.resolve().then(
|
|
4152
|
+
() => client.updateSessionAttention(workspaceId, sessionId, {
|
|
4153
|
+
unread: false,
|
|
4154
|
+
acknowledgedThroughSequence: readThrough
|
|
4155
|
+
})
|
|
4156
|
+
).catch((error) => {
|
|
4157
|
+
if (receipt.current !== key) return;
|
|
4158
|
+
if (isPermanentRejection(error)) {
|
|
4159
|
+
refused.current.add(scope);
|
|
4160
|
+
return;
|
|
4161
|
+
}
|
|
4162
|
+
if (!retried) {
|
|
4163
|
+
retryTimer.current = setTimeout(() => {
|
|
4164
|
+
retryTimer.current = null;
|
|
4165
|
+
if (receipt.current === key) attempt(true);
|
|
4166
|
+
}, SESSION_READ_ACKNOWLEDGEMENT_RETRY_MS);
|
|
4167
|
+
return;
|
|
4168
|
+
}
|
|
4169
|
+
receipt.current = null;
|
|
4170
|
+
});
|
|
4171
|
+
};
|
|
4172
|
+
attempt(false);
|
|
4173
|
+
}, [active, client, hasSession, readThrough, sessionId, unread, workspaceId]);
|
|
4174
|
+
}
|
|
4175
|
+
|
|
4176
|
+
// src/hooks/use-new-conversation.ts
|
|
4177
|
+
import {
|
|
4178
|
+
OpenGeniApiError as OpenGeniApiError2
|
|
4179
|
+
} from "@opengeni/sdk";
|
|
4180
|
+
import { useLayoutEffect as useLayoutEffect5, useMemo as useMemo6, useRef as useRef10, useState as useState7 } from "react";
|
|
4181
|
+
var NOOP_ASYNC = async () => {
|
|
4182
|
+
};
|
|
4183
|
+
function useNewConversation(options = {}) {
|
|
4184
|
+
const t = useOpenGeniText();
|
|
4185
|
+
const context = useOpenGeni(options);
|
|
4186
|
+
const scope = { client: context.client, workspaceId: context.workspaceId };
|
|
4187
|
+
const config = useClientConfigFlags(context.client);
|
|
4188
|
+
const showModelPicker = options.modelPicker ?? config.modelSelection;
|
|
4189
|
+
const catalog = useWorkspaceModelCatalog({ ...scope, enabled: showModelPicker });
|
|
4190
|
+
const preferredModel = options.defaultModel && catalog.models.some(
|
|
4191
|
+
(row) => row.id === options.defaultModel && row.availability?.selectable !== false
|
|
4192
|
+
) ? options.defaultModel : void 0;
|
|
4193
|
+
const defaultModel = preferredModel ?? catalog.defaultModel;
|
|
4194
|
+
const files = useFileAttachments(scope);
|
|
4195
|
+
const uploadsEnabled = (options.attachments ?? true) && config.uploads;
|
|
4196
|
+
const available = options.enabled !== false && (options.createSession !== void 0 || config.sessionCreation);
|
|
4197
|
+
const [text, setText] = useState7("");
|
|
4198
|
+
const [choice, setChoice] = useState7({});
|
|
4199
|
+
const [sending, setSending] = useState7(false);
|
|
4200
|
+
const [error, setError] = useState7(null);
|
|
4201
|
+
const [pending, setPending] = useState7(null);
|
|
4202
|
+
const [completion, setCompletion] = useState7(null);
|
|
4203
|
+
const textRef = useRef10(text);
|
|
4204
|
+
const textRevision = useRef10(0);
|
|
4205
|
+
const choiceRef = useRef10(choice);
|
|
4206
|
+
const filesRef = useRef10(files);
|
|
4207
|
+
filesRef.current = files;
|
|
4208
|
+
const pendingRef = useRef10(null);
|
|
4209
|
+
const completionRef = useRef10(null);
|
|
4210
|
+
const inFlight = useRef10(false);
|
|
4211
|
+
const lifetime = useRef10({ mounted: true, generation: 0 }).current;
|
|
4212
|
+
const identity = useMemo6(
|
|
4213
|
+
() => ({
|
|
4214
|
+
client: context.client,
|
|
4215
|
+
workspaceId: context.workspaceId,
|
|
4216
|
+
scopeKey: options.scopeKey
|
|
4217
|
+
}),
|
|
4218
|
+
[context.client, context.workspaceId, options.scopeKey]
|
|
4219
|
+
);
|
|
4220
|
+
const committedIdentity = useRef10(identity);
|
|
4221
|
+
useLayoutEffect5(() => {
|
|
4222
|
+
lifetime.mounted = true;
|
|
4223
|
+
return () => {
|
|
4224
|
+
lifetime.mounted = false;
|
|
4225
|
+
lifetime.generation++;
|
|
4226
|
+
};
|
|
4227
|
+
}, [lifetime]);
|
|
4228
|
+
useLayoutEffect5(() => {
|
|
4229
|
+
if (committedIdentity.current === identity) return;
|
|
4230
|
+
committedIdentity.current = identity;
|
|
4231
|
+
lifetime.generation++;
|
|
4232
|
+
inFlight.current = false;
|
|
4233
|
+
pendingRef.current = null;
|
|
4234
|
+
completionRef.current = null;
|
|
4235
|
+
textRef.current = "";
|
|
4236
|
+
textRevision.current = 0;
|
|
4237
|
+
choiceRef.current = {};
|
|
4238
|
+
setText("");
|
|
4239
|
+
setChoice({});
|
|
4240
|
+
setSending(false);
|
|
4241
|
+
setError(null);
|
|
4242
|
+
setPending(null);
|
|
4243
|
+
setCompletion(null);
|
|
4244
|
+
filesRef.current.clear();
|
|
4245
|
+
}, [identity, lifetime]);
|
|
4246
|
+
const ownsScope = () => lifetime.mounted && committedIdentity.current === identity;
|
|
4247
|
+
const updateText = (value) => {
|
|
4248
|
+
if (!ownsScope()) return;
|
|
4249
|
+
if (value !== textRef.current) textRevision.current++;
|
|
4250
|
+
textRef.current = value;
|
|
4251
|
+
setText(value);
|
|
4252
|
+
};
|
|
4253
|
+
const updateChoice = (patch) => {
|
|
4254
|
+
if (!ownsScope()) return;
|
|
4255
|
+
const next = { ...choiceRef.current, ...patch };
|
|
4256
|
+
const model = catalog.models.find((row) => row.id === (next.model ?? defaultModel));
|
|
4257
|
+
if (model) {
|
|
4258
|
+
if (next.reasoningEffort)
|
|
4259
|
+
next.reasoningEffort = coerceReasoningEffortForModel(model, next.reasoningEffort);
|
|
4260
|
+
if (next.latencyMode && !runnableLatencyModesForModel(model).includes(next.latencyMode))
|
|
4261
|
+
next.latencyMode = "standard";
|
|
4262
|
+
}
|
|
4263
|
+
choiceRef.current = next;
|
|
4264
|
+
setChoice(choiceRef.current);
|
|
4265
|
+
if (!pendingRef.current) setError(null);
|
|
4266
|
+
};
|
|
4267
|
+
const preferredChoice = () => preferredModel ? { model: preferredModel } : {};
|
|
4268
|
+
const effectivePolicy = () => {
|
|
4269
|
+
const model = choiceRef.current.model ?? defaultModel;
|
|
4270
|
+
const definition = catalog.models.find((row) => row.id === model);
|
|
4271
|
+
const effort = choiceRef.current.reasoningEffort ?? (definition ? defaultEffortForModel(definition) : config.defaultReasoningEffort ?? "medium");
|
|
4272
|
+
return showModelPicker && model ? {
|
|
4273
|
+
model,
|
|
4274
|
+
reasoningEffort: definition ? coerceReasoningEffortForModel(definition, effort) : effort,
|
|
4275
|
+
latencyMode: choiceRef.current.latencyMode ?? "standard"
|
|
4276
|
+
} : void 0;
|
|
4277
|
+
};
|
|
4278
|
+
const create = options.createSession ?? (async (initialMessage, idempotencyKey, input) => {
|
|
4279
|
+
const creator = context.client.createSession;
|
|
4280
|
+
if (typeof creator !== "function")
|
|
4281
|
+
throw new Error(t("hooks.useNewConversation.newChatsAreNotEnabled"));
|
|
4282
|
+
const created = await creator.call(context.client, context.workspaceId, {
|
|
4283
|
+
...input.startMode === "realtime" ? {} : { initialMessage },
|
|
4284
|
+
idempotencyKey,
|
|
4285
|
+
...input
|
|
4286
|
+
});
|
|
4287
|
+
return created.id;
|
|
4288
|
+
});
|
|
4289
|
+
const finishCreation = (accepted) => {
|
|
4290
|
+
if (!lifetime.mounted || lifetime.generation !== accepted.generation) return;
|
|
4291
|
+
const { attempt, sessionId } = accepted;
|
|
4292
|
+
const sentFiles = new Set(attempt.options.resources?.map((resource) => resource.fileId) ?? []);
|
|
4293
|
+
const policyChanged = ["model", "reasoningEffort", "latencyMode"].some(
|
|
4294
|
+
(field) => choiceRef.current[field] !== attempt.options[field]
|
|
4295
|
+
);
|
|
4296
|
+
const draft = {
|
|
4297
|
+
text: attempt.clearDraft && textRevision.current === attempt.textRevision ? "" : textRef.current,
|
|
4298
|
+
resources: filesRef.current.readyResources.filter(
|
|
4299
|
+
(resource) => !sentFiles.has(resource.fileId)
|
|
4300
|
+
),
|
|
4301
|
+
// Unchanged choices are already part of the created session. Do not
|
|
4302
|
+
// replace server-owned defaults with a browser's catalog estimate.
|
|
4303
|
+
...policyChanged ? { policy: effectivePolicy() } : {}
|
|
4304
|
+
};
|
|
4305
|
+
pendingRef.current = null;
|
|
4306
|
+
completionRef.current = null;
|
|
4307
|
+
setPending(null);
|
|
4308
|
+
setCompletion(null);
|
|
4309
|
+
updateText(draft.text);
|
|
4310
|
+
filesRef.current.removeReadyFiles(sentFiles);
|
|
4311
|
+
notifyObserver(options.onCreated, {
|
|
4312
|
+
sessionId,
|
|
4313
|
+
initialMessage: attempt.initialMessage,
|
|
4314
|
+
sentAt: attempt.sentAt,
|
|
4315
|
+
draft,
|
|
4316
|
+
...attempt.realtimeModel ? { realtimeModel: attempt.realtimeModel } : {}
|
|
4317
|
+
});
|
|
4318
|
+
};
|
|
4319
|
+
const finishRef = useRef10(finishCreation);
|
|
4320
|
+
finishRef.current = finishCreation;
|
|
4321
|
+
useLayoutEffect5(() => {
|
|
4322
|
+
if (completion && !files.hasUnresolved) finishRef.current(completion);
|
|
4323
|
+
}, [completion, files.hasUnresolved]);
|
|
4324
|
+
const deliver = async (attempt) => {
|
|
4325
|
+
if (!ownsScope() || inFlight.current || completionRef.current || !available) return false;
|
|
4326
|
+
const ownedGeneration = lifetime.generation;
|
|
4327
|
+
inFlight.current = true;
|
|
4328
|
+
pendingRef.current = attempt;
|
|
4329
|
+
setSending(true);
|
|
4330
|
+
setError(null);
|
|
4331
|
+
setPending(null);
|
|
4332
|
+
try {
|
|
4333
|
+
const sessionId = await attempt.create(
|
|
4334
|
+
attempt.initialMessage,
|
|
4335
|
+
attempt.key,
|
|
4336
|
+
structuredClone(attempt.options)
|
|
4337
|
+
);
|
|
4338
|
+
if (!lifetime.mounted || lifetime.generation !== ownedGeneration) return true;
|
|
4339
|
+
const accepted = { sessionId, attempt, generation: ownedGeneration };
|
|
4340
|
+
completionRef.current = accepted;
|
|
4341
|
+
if (filesRef.current.hasUnresolved) setCompletion(accepted);
|
|
4342
|
+
else finishCreation(accepted);
|
|
4343
|
+
return true;
|
|
4344
|
+
} catch (cause) {
|
|
4345
|
+
if (!lifetime.mounted || lifetime.generation !== ownedGeneration) return false;
|
|
4346
|
+
setError({ cause });
|
|
4347
|
+
if (cause instanceof OpenGeniApiError2 && cause.outcomeUnknown === false) {
|
|
4348
|
+
pendingRef.current = null;
|
|
4349
|
+
} else {
|
|
4350
|
+
setPending(attempt);
|
|
4351
|
+
}
|
|
4352
|
+
return false;
|
|
4353
|
+
} finally {
|
|
4354
|
+
if (lifetime.mounted && lifetime.generation === ownedGeneration) {
|
|
4355
|
+
inFlight.current = false;
|
|
4356
|
+
setSending(false);
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
};
|
|
4360
|
+
const submit = async (explicit) => {
|
|
4361
|
+
if (!ownsScope() || !available || inFlight.current || pendingRef.current || uploadsEnabled && filesRef.current.hasUnresolved)
|
|
4362
|
+
return false;
|
|
4363
|
+
const resources = uploadsEnabled ? filesRef.current.readyResources : [];
|
|
4364
|
+
const draftText = explicit ?? textRef.current;
|
|
4365
|
+
const initialMessage = draftText.trim() || (resources.length > 0 ? FILE_ONLY_MESSAGE_TEXT(t) : "");
|
|
4366
|
+
if (!initialMessage) return false;
|
|
4367
|
+
return deliver({
|
|
4368
|
+
key: crypto.randomUUID(),
|
|
4369
|
+
initialMessage,
|
|
4370
|
+
sentAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4371
|
+
textRevision: textRevision.current,
|
|
4372
|
+
clearDraft: explicit === void 0,
|
|
4373
|
+
create,
|
|
4374
|
+
options: {
|
|
4375
|
+
...resources.length ? { resources: structuredClone(resources) } : {},
|
|
4376
|
+
...showModelPicker ? { ...preferredChoice(), ...choiceRef.current } : {}
|
|
4377
|
+
}
|
|
4378
|
+
});
|
|
4379
|
+
};
|
|
4380
|
+
const startRealtime = async (model) => {
|
|
4381
|
+
if (!ownsScope() || !available || inFlight.current || pendingRef.current || !config.realtimeVoice || !(options.realtimeVoice ?? config.realtimeVoiceOffered))
|
|
4382
|
+
return false;
|
|
4383
|
+
if (filesRef.current.hasUnresolved) return false;
|
|
4384
|
+
return deliver({
|
|
4385
|
+
key: crypto.randomUUID(),
|
|
4386
|
+
initialMessage: "",
|
|
4387
|
+
sentAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4388
|
+
textRevision: textRevision.current,
|
|
4389
|
+
clearDraft: false,
|
|
4390
|
+
create,
|
|
4391
|
+
options: {
|
|
4392
|
+
...showModelPicker ? { ...preferredChoice(), ...choiceRef.current } : {},
|
|
4393
|
+
startMode: "realtime"
|
|
4394
|
+
},
|
|
4395
|
+
realtimeModel: model
|
|
4396
|
+
});
|
|
4397
|
+
};
|
|
4398
|
+
const composer = {
|
|
4399
|
+
value: text,
|
|
4400
|
+
setValue: updateText,
|
|
4401
|
+
hasDraftContent: () => textRef.current.length > 0 || filesRef.current.attachments.length > 0,
|
|
4402
|
+
send: submit,
|
|
4403
|
+
steer: submit,
|
|
4404
|
+
// Nothing runs before the conversation exists: Send just sends.
|
|
4405
|
+
working: false,
|
|
4406
|
+
sending,
|
|
4407
|
+
canSend: available && !sending && !pending && !completion && (text.trim().length > 0 || uploadsEnabled && files.readyResources.length > 0) && !(uploadsEnabled && files.hasUnresolved),
|
|
4408
|
+
pause: NOOP_ASYNC,
|
|
4409
|
+
pausing: false,
|
|
4410
|
+
resume: NOOP_ASYNC,
|
|
4411
|
+
resumeScope: NOOP_ASYNC,
|
|
4412
|
+
resuming: false,
|
|
4413
|
+
draft: null,
|
|
4414
|
+
draftRevision: 0,
|
|
4415
|
+
draftLoading: false,
|
|
4416
|
+
draftSaving: false,
|
|
4417
|
+
draftConflict: null,
|
|
4418
|
+
policy: effectivePolicy() ?? null,
|
|
4419
|
+
setModel: (model) => updateChoice({ model }),
|
|
4420
|
+
setReasoningEffort: (reasoningEffort) => updateChoice({ reasoningEffort }),
|
|
4421
|
+
setLatencyMode: (latencyMode) => updateChoice({ latencyMode }),
|
|
4422
|
+
draftPersistence: "disabled",
|
|
4423
|
+
applyDraft: () => {
|
|
4424
|
+
},
|
|
4425
|
+
reloadDraft: NOOP_ASYNC,
|
|
4426
|
+
resolveDraftConflict: NOOP_ASYNC,
|
|
4427
|
+
restoredResources: [],
|
|
4428
|
+
removeRestoredResource: () => {
|
|
4429
|
+
},
|
|
4430
|
+
error: null,
|
|
4431
|
+
clearError: () => {
|
|
4432
|
+
if (ownsScope()) setError(null);
|
|
4433
|
+
}
|
|
4434
|
+
};
|
|
4435
|
+
return {
|
|
4436
|
+
...scope,
|
|
4437
|
+
config,
|
|
4438
|
+
files,
|
|
4439
|
+
uploadsEnabled,
|
|
4440
|
+
available,
|
|
4441
|
+
showModelPicker,
|
|
4442
|
+
catalog,
|
|
4443
|
+
composer,
|
|
4444
|
+
realtimeVoiceEnabled: config.realtimeVoice && (options.realtimeVoice ?? config.realtimeVoiceOffered),
|
|
4445
|
+
error,
|
|
4446
|
+
finishingUploads: completion !== null,
|
|
4447
|
+
pending: pending ? { idempotencyKey: pending.key, realtimeModel: pending.realtimeModel } : null,
|
|
4448
|
+
retry: () => pendingRef.current ? deliver(pendingRef.current) : Promise.resolve(false),
|
|
4449
|
+
startRealtime
|
|
4450
|
+
};
|
|
4451
|
+
}
|
|
4452
|
+
|
|
4453
|
+
export {
|
|
4454
|
+
isTitleEvent,
|
|
4455
|
+
useSession,
|
|
4456
|
+
invokeOlderHistoryLoaderWithReceiptCapture,
|
|
4457
|
+
createOlderHistoryLoadReceipt,
|
|
4458
|
+
useTurnlessOutputGap,
|
|
4459
|
+
SESSION_EVENT_BROWSER_MAX_BYTES,
|
|
4460
|
+
SESSION_EVENT_BROWSER_MAX_COUNT,
|
|
4461
|
+
SESSION_EVENT_BROWSER_PENDING_MAX_BYTES,
|
|
4462
|
+
SESSION_EVENT_BROWSER_PENDING_MAX_COUNT,
|
|
4463
|
+
useSessionEvents,
|
|
4464
|
+
boundBrowserSessionEventWindow,
|
|
4465
|
+
isTurnQueueEvent,
|
|
4466
|
+
useTurnQueue,
|
|
4467
|
+
isGoalEvent,
|
|
4468
|
+
useGoal,
|
|
4469
|
+
useSessionControl,
|
|
4470
|
+
useAvailableModels,
|
|
4471
|
+
useWorkspaceModelCatalog,
|
|
4472
|
+
isHumanInputEvent,
|
|
4473
|
+
useHumanInputRequests,
|
|
4474
|
+
conversationTimeline,
|
|
4475
|
+
useSessionStartupTimeline,
|
|
4476
|
+
useSessionConversation,
|
|
4477
|
+
useSessionReadAcknowledgement,
|
|
4478
|
+
useNewConversation
|
|
4479
|
+
};
|
|
4480
|
+
//# sourceMappingURL=chunk-4E5QVAT4.js.map
|