@athenaintel/react 0.43.0 → 0.48.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/README.md +215 -3
- package/dist/agent-runtime/src/answer-label.cjs +137 -0
- package/dist/agent-runtime/src/answer-label.cjs.map +1 -0
- package/dist/agent-runtime/src/answer-label.d.ts +104 -0
- package/dist/agent-runtime/src/answer-label.js +137 -0
- package/dist/agent-runtime/src/answer-label.js.map +1 -0
- package/dist/agent-runtime/src/answer-rows.cjs +180 -0
- package/dist/agent-runtime/src/answer-rows.cjs.map +1 -0
- package/dist/agent-runtime/src/answer-rows.d.ts +86 -0
- package/dist/agent-runtime/src/answer-rows.js +180 -0
- package/dist/agent-runtime/src/answer-rows.js.map +1 -0
- package/dist/agent-runtime/src/client-tool-bridge.cjs +15 -15
- package/dist/agent-runtime/src/client-tool-bridge.cjs.map +1 -1
- package/dist/agent-runtime/src/conversation-index.cjs +8 -8
- package/dist/agent-runtime/src/conversation-index.cjs.map +1 -1
- package/dist/agent-runtime/src/decision-checks.cjs +207 -0
- package/dist/agent-runtime/src/decision-checks.cjs.map +1 -0
- package/dist/agent-runtime/src/decision-checks.d.ts +142 -0
- package/dist/agent-runtime/src/decision-checks.js +207 -0
- package/dist/agent-runtime/src/decision-checks.js.map +1 -0
- package/dist/agent-runtime/src/desktop-handoff.d.ts +12 -0
- package/dist/agent-runtime/src/errors.cjs +18 -0
- package/dist/agent-runtime/src/errors.cjs.map +1 -1
- package/dist/agent-runtime/src/errors.d.ts +7 -0
- package/dist/agent-runtime/src/errors.js +18 -0
- package/dist/agent-runtime/src/errors.js.map +1 -1
- package/dist/agent-runtime/src/generated/runconfig-contract.cjs +12 -0
- package/dist/agent-runtime/src/generated/runconfig-contract.cjs.map +1 -1
- package/dist/agent-runtime/src/generated/runconfig-contract.d.ts +6 -6
- package/dist/agent-runtime/src/generated/runconfig-contract.js +12 -0
- package/dist/agent-runtime/src/generated/runconfig-contract.js.map +1 -1
- package/dist/agent-runtime/src/handoff-arrival.cjs +60 -0
- package/dist/agent-runtime/src/handoff-arrival.cjs.map +1 -0
- package/dist/agent-runtime/src/handoff-arrival.d.ts +46 -0
- package/dist/agent-runtime/src/handoff-arrival.js +60 -0
- package/dist/agent-runtime/src/handoff-arrival.js.map +1 -0
- package/dist/agent-runtime/src/index.d.ts +14 -8
- package/dist/agent-runtime/src/interrupts.cjs +43 -18
- package/dist/agent-runtime/src/interrupts.cjs.map +1 -1
- package/dist/agent-runtime/src/interrupts.d.ts +19 -2
- package/dist/agent-runtime/src/interrupts.js +28 -3
- package/dist/agent-runtime/src/interrupts.js.map +1 -1
- package/dist/agent-runtime/src/lane-history.cjs +8 -8
- package/dist/agent-runtime/src/lane-history.cjs.map +1 -1
- package/dist/agent-runtime/src/messages.cjs +43 -8
- package/dist/agent-runtime/src/messages.cjs.map +1 -1
- package/dist/agent-runtime/src/messages.d.ts +25 -3
- package/dist/agent-runtime/src/messages.js +43 -8
- package/dist/agent-runtime/src/messages.js.map +1 -1
- package/dist/agent-runtime/src/offline-status.cjs +36 -0
- package/dist/agent-runtime/src/offline-status.cjs.map +1 -0
- package/dist/agent-runtime/src/offline-status.d.ts +118 -3
- package/dist/agent-runtime/src/offline-status.js +36 -0
- package/dist/agent-runtime/src/offline-status.js.map +1 -0
- package/dist/agent-runtime/src/queue.cjs +0 -9
- package/dist/agent-runtime/src/queue.cjs.map +1 -1
- package/dist/agent-runtime/src/queue.js +0 -9
- package/dist/agent-runtime/src/queue.js.map +1 -1
- package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs +9 -9
- package/dist/agent-runtime/src/quota-safe-local-storage-session.cjs.map +1 -1
- package/dist/agent-runtime/src/runtime-catalog.cjs +42 -0
- package/dist/agent-runtime/src/runtime-catalog.cjs.map +1 -0
- package/dist/agent-runtime/src/runtime-catalog.d.ts +35 -0
- package/dist/agent-runtime/src/runtime-catalog.js +42 -0
- package/dist/agent-runtime/src/runtime-catalog.js.map +1 -0
- package/dist/agent-runtime/src/runtime-messages.cjs.map +1 -1
- package/dist/agent-runtime/src/runtime-messages.d.ts +1 -1
- package/dist/agent-runtime/src/runtime-messages.js.map +1 -1
- package/dist/agent-runtime/src/runtime.d.ts +40 -0
- package/dist/agent-runtime/src/statewire-suspended.cjs +3 -3
- package/dist/agent-runtime/src/statewire-suspended.cjs.map +1 -1
- package/dist/agent-runtime/src/subagents.cjs +32 -2
- package/dist/agent-runtime/src/subagents.cjs.map +1 -1
- package/dist/agent-runtime/src/subagents.d.ts +9 -0
- package/dist/agent-runtime/src/subagents.js +30 -0
- package/dist/agent-runtime/src/subagents.js.map +1 -1
- package/dist/agent-runtime/src/thread-driver.cjs +67 -0
- package/dist/agent-runtime/src/thread-driver.cjs.map +1 -0
- package/dist/agent-runtime/src/thread-driver.d.ts +49 -0
- package/dist/agent-runtime/src/thread-driver.js +67 -0
- package/dist/agent-runtime/src/thread-driver.js.map +1 -0
- package/dist/agent-runtime/src/thread-handoff-flow-machine.d.ts +172 -0
- package/dist/agent-runtime/src/thread-handoff-protocol.d.ts +756 -0
- package/dist/agent-runtime/src/thread-handoff-qr.d.ts +11 -0
- package/dist/agent-runtime/src/thread-handoff.d.ts +3 -364
- package/dist/agent-runtime/src/thread-status.cjs +3 -3
- package/dist/agent-runtime/src/thread-status.cjs.map +1 -1
- package/dist/agent-runtime/src/tool-metadata.cjs +210 -25
- package/dist/agent-runtime/src/tool-metadata.cjs.map +1 -1
- package/dist/agent-runtime/src/tool-metadata.d.ts +12 -0
- package/dist/agent-runtime/src/tool-metadata.js +210 -25
- package/dist/agent-runtime/src/tool-metadata.js.map +1 -1
- package/dist/agent-runtime/src/tool-names.cjs +2 -0
- package/dist/agent-runtime/src/tool-names.cjs.map +1 -1
- package/dist/agent-runtime/src/tool-names.d.ts +2 -0
- package/dist/agent-runtime/src/tool-names.js +2 -0
- package/dist/agent-runtime/src/tool-names.js.map +1 -1
- package/dist/agent-runtime/src/types.d.ts +10 -2
- package/dist/agent-runtime/src/use-conversation-list.cjs +11 -11
- package/dist/agent-runtime/src/use-conversation-list.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs +24 -19
- package/dist/agent-runtime/src/use-deep-agent-chat-outbox.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-chat-outbox.d.ts +2 -1
- package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js +6 -1
- package/dist/agent-runtime/src/use-deep-agent-chat-outbox.js.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-config.cjs +14 -14
- package/dist/agent-runtime/src/use-deep-agent-config.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs +6 -6
- package/dist/agent-runtime/src/use-deep-agent-edit-submit.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-runtime.cjs +16 -16
- package/dist/agent-runtime/src/use-deep-agent-runtime.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-thread.cjs +45 -45
- package/dist/agent-runtime/src/use-deep-agent-thread.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-voice.cjs +547 -124
- package/dist/agent-runtime/src/use-deep-agent-voice.cjs.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-voice.d.ts +129 -10
- package/dist/agent-runtime/src/use-deep-agent-voice.js +487 -64
- package/dist/agent-runtime/src/use-deep-agent-voice.js.map +1 -1
- package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs +26 -26
- package/dist/agent-runtime/src/use-deep-agent-window-sync.cjs.map +1 -1
- package/dist/agent-runtime/src/use-historical-edit-attachments.cjs +4 -4
- package/dist/agent-runtime/src/use-historical-edit-attachments.cjs.map +1 -1
- package/dist/agent-runtime/src/use-thread-handoff-flow.d.ts +28 -26
- package/dist/agent-runtime/src/voice-media.cjs +117 -0
- package/dist/agent-runtime/src/voice-media.cjs.map +1 -0
- package/dist/agent-runtime/src/voice-media.d.ts +49 -0
- package/dist/agent-runtime/src/voice-media.js +117 -0
- package/dist/agent-runtime/src/voice-media.js.map +1 -0
- package/dist/agent-runtime/src/voice-wire-types.d.ts +32 -0
- package/dist/assets/AssetPanel.cjs +11 -11
- package/dist/assets/AssetPanel.cjs.map +1 -1
- package/dist/assets/AthenaAssetEmbed.cjs +11 -9
- package/dist/assets/AthenaAssetEmbed.cjs.map +1 -1
- package/dist/assets/AthenaAssetEmbed.d.ts +7 -0
- package/dist/assets/AthenaAssetEmbed.js +4 -2
- package/dist/assets/AthenaAssetEmbed.js.map +1 -1
- package/dist/assets/AthenaLayout.cjs +16 -16
- package/dist/assets/AthenaLayout.cjs.map +1 -1
- package/dist/assets/use-asset-content.cjs +4 -4
- package/dist/assets/use-asset-content.cjs.map +1 -1
- package/dist/assets/use-asset-embed.cjs +14 -7
- package/dist/assets/use-asset-embed.cjs.map +1 -1
- package/dist/assets/use-asset-embed.d.ts +11 -1
- package/dist/assets/use-asset-embed.js +10 -3
- package/dist/assets/use-asset-embed.js.map +1 -1
- package/dist/auth/AthenaAuthContext.cjs +3 -3
- package/dist/auth/AthenaAuthContext.cjs.map +1 -1
- package/dist/auth/AthenaAuthProvider.cjs +8 -8
- package/dist/auth/AthenaAuthProvider.cjs.map +1 -1
- package/dist/auth/AthenaCredentialSourceContext.cjs +5 -5
- package/dist/auth/AthenaCredentialSourceContext.cjs.map +1 -1
- package/dist/auth/AthenaSSOProvider.cjs +14 -14
- package/dist/auth/AthenaSSOProvider.cjs.map +1 -1
- package/dist/auth/credential-source.cjs +26 -13
- package/dist/auth/credential-source.cjs.map +1 -1
- package/dist/auth/credential-source.d.ts +8 -0
- package/dist/auth/credential-source.js +26 -13
- package/dist/auth/credential-source.js.map +1 -1
- package/dist/catalog/agent-model-options.cjs +25 -17
- package/dist/catalog/agent-model-options.cjs.map +1 -1
- package/dist/catalog/agent-model-options.d.ts +38 -5
- package/dist/catalog/agent-model-options.js +25 -17
- package/dist/catalog/agent-model-options.js.map +1 -1
- package/dist/catalog/channel-refusal.cjs +36 -0
- package/dist/catalog/channel-refusal.cjs.map +1 -0
- package/dist/catalog/channel-refusal.d.ts +29 -0
- package/dist/catalog/channel-refusal.js +36 -0
- package/dist/catalog/channel-refusal.js.map +1 -0
- package/dist/catalog/chat-pickers.cjs +60 -24
- package/dist/catalog/chat-pickers.cjs.map +1 -1
- package/dist/catalog/chat-pickers.d.ts +12 -2
- package/dist/catalog/chat-pickers.js +56 -20
- package/dist/catalog/chat-pickers.js.map +1 -1
- package/dist/catalog/runtime-catalog.cjs +89 -23
- package/dist/catalog/runtime-catalog.cjs.map +1 -1
- package/dist/catalog/runtime-catalog.d.ts +8 -2
- package/dist/catalog/runtime-catalog.js +83 -17
- package/dist/catalog/runtime-catalog.js.map +1 -1
- package/dist/catalog/use-athena-chat-mode.cjs +12 -12
- package/dist/catalog/use-athena-chat-mode.cjs.map +1 -1
- package/dist/chat/AthenaChat.cjs +155 -67
- package/dist/chat/AthenaChat.cjs.map +1 -1
- package/dist/chat/AthenaChat.d.ts +42 -2
- package/dist/chat/AthenaChat.js +106 -18
- package/dist/chat/AthenaChat.js.map +1 -1
- package/dist/chat/AthenaChatErrorBoundary.cjs +3 -3
- package/dist/chat/AthenaChatErrorBoundary.cjs.map +1 -1
- package/dist/chat/DrivingOnChip.cjs +23 -0
- package/dist/chat/DrivingOnChip.cjs.map +1 -0
- package/dist/chat/DrivingOnChip.d.ts +17 -0
- package/dist/chat/DrivingOnChip.js +23 -0
- package/dist/chat/DrivingOnChip.js.map +1 -0
- package/dist/chat/StatewireApprovalCard.cjs +125 -31
- package/dist/chat/StatewireApprovalCard.cjs.map +1 -1
- package/dist/chat/StatewireApprovalCard.d.ts +73 -1
- package/dist/chat/StatewireApprovalCard.js +115 -21
- package/dist/chat/StatewireApprovalCard.js.map +1 -1
- package/dist/chat/StatewireClientToolBridge.cjs +2 -2
- package/dist/chat/StatewireClientToolBridge.cjs.map +1 -1
- package/dist/chat/StatewireQueuedMessages.cjs +25 -63
- package/dist/chat/StatewireQueuedMessages.cjs.map +1 -1
- package/dist/chat/StatewireQueuedMessages.d.ts +11 -13
- package/dist/chat/StatewireQueuedMessages.js +16 -54
- package/dist/chat/StatewireQueuedMessages.js.map +1 -1
- package/dist/chat/WaitingOnYouBanner.cjs +3 -3
- package/dist/chat/WaitingOnYouBanner.cjs.map +1 -1
- package/dist/chat/athena-chat-welcome.cjs +2 -2
- package/dist/chat/athena-chat-welcome.cjs.map +1 -1
- package/dist/chat/athena-citation-links.cjs +5 -5
- package/dist/chat/athena-citation-links.cjs.map +1 -1
- package/dist/chat/athena-composer-controls.cjs +26 -16
- package/dist/chat/athena-composer-controls.cjs.map +1 -1
- package/dist/chat/athena-composer-controls.d.ts +6 -0
- package/dist/chat/athena-composer-controls.js +26 -16
- package/dist/chat/athena-composer-controls.js.map +1 -1
- package/dist/chat/athena-turn-end-status.cjs +42 -0
- package/dist/chat/athena-turn-end-status.cjs.map +1 -0
- package/dist/chat/athena-turn-end-status.d.ts +24 -0
- package/dist/chat/athena-turn-end-status.js +42 -0
- package/dist/chat/athena-turn-end-status.js.map +1 -0
- package/dist/chat/browser-decision-check.cjs +131 -0
- package/dist/chat/browser-decision-check.cjs.map +1 -0
- package/dist/chat/browser-decision-check.d.ts +61 -0
- package/dist/chat/browser-decision-check.js +131 -0
- package/dist/chat/browser-decision-check.js.map +1 -0
- package/dist/chat/chat-outbox-rows.cjs +3 -3
- package/dist/chat/chat-outbox-rows.cjs.map +1 -1
- package/dist/chat/chat-voice-controls.cjs +93 -28
- package/dist/chat/chat-voice-controls.cjs.map +1 -1
- package/dist/chat/chat-voice-controls.d.ts +36 -2
- package/dist/chat/chat-voice-controls.js +89 -24
- package/dist/chat/chat-voice-controls.js.map +1 -1
- package/dist/chat/composer-keyboard-hint.cjs +5 -5
- package/dist/chat/composer-keyboard-hint.cjs.map +1 -1
- package/dist/chat/device-operation.cjs +29 -0
- package/dist/chat/device-operation.cjs.map +1 -0
- package/dist/chat/device-operation.d.ts +34 -0
- package/dist/chat/device-operation.js +29 -0
- package/dist/chat/device-operation.js.map +1 -0
- package/dist/chat/super-grouping/CollapsibleGroup.cjs +14 -14
- package/dist/chat/super-grouping/CollapsibleGroup.cjs.map +1 -1
- package/dist/chat/super-grouping/GroupedMessageParts.cjs +4 -4
- package/dist/chat/super-grouping/GroupedMessageParts.cjs.map +1 -1
- package/dist/chat/super-grouping/SuperGroupingCard.cjs +52 -36
- package/dist/chat/super-grouping/SuperGroupingCard.cjs.map +1 -1
- package/dist/chat/super-grouping/SuperGroupingCard.d.ts +19 -4
- package/dist/chat/super-grouping/SuperGroupingCard.js +29 -13
- package/dist/chat/super-grouping/SuperGroupingCard.js.map +1 -1
- package/dist/chat/super-grouping/SuperGroupingTranscript.cjs +32 -32
- package/dist/chat/super-grouping/SuperGroupingTranscript.cjs.map +1 -1
- package/dist/chat/super-grouping/SuperGroupingTranscript.js +3 -3
- package/dist/chat/super-grouping/SuperGroupingTranscript.js.map +1 -1
- package/dist/chat/super-grouping/ToolTimeline.cjs +73 -40
- package/dist/chat/super-grouping/ToolTimeline.cjs.map +1 -1
- package/dist/chat/super-grouping/ToolTimeline.d.ts +10 -2
- package/dist/chat/super-grouping/ToolTimeline.js +69 -36
- package/dist/chat/super-grouping/ToolTimeline.js.map +1 -1
- package/dist/chat/super-grouping/activity-timeline.cjs +47 -12
- package/dist/chat/super-grouping/activity-timeline.cjs.map +1 -1
- package/dist/chat/super-grouping/activity-timeline.d.ts +21 -0
- package/dist/chat/super-grouping/activity-timeline.js +47 -12
- package/dist/chat/super-grouping/activity-timeline.js.map +1 -1
- package/dist/chat/super-grouping/grouping-function.cjs +4 -0
- package/dist/chat/super-grouping/grouping-function.cjs.map +1 -1
- package/dist/chat/super-grouping/grouping-function.d.ts +7 -0
- package/dist/chat/super-grouping/grouping-function.js +5 -1
- package/dist/chat/super-grouping/grouping-function.js.map +1 -1
- package/dist/chat/super-grouping/index.cjs +6 -0
- package/dist/chat/super-grouping/index.cjs.map +1 -1
- package/dist/chat/super-grouping/index.d.ts +5 -2
- package/dist/chat/super-grouping/index.js +7 -1
- package/dist/chat/super-grouping/index.js.map +1 -1
- package/dist/chat/super-grouping/tool-part-placement.cjs +17 -0
- package/dist/chat/super-grouping/tool-part-placement.cjs.map +1 -0
- package/dist/chat/super-grouping/tool-part-placement.d.ts +22 -0
- package/dist/chat/super-grouping/tool-part-placement.js +17 -0
- package/dist/chat/super-grouping/tool-part-placement.js.map +1 -0
- package/dist/chat/thread-scroll-to-bottom.cjs +2 -2
- package/dist/chat/thread-scroll-to-bottom.cjs.map +1 -1
- package/dist/chat/thread-scroll-to-bottom.d.ts +10 -7
- package/dist/chat/thread-scroll-to-bottom.js +2 -2
- package/dist/chat/thread-scroll-to-bottom.js.map +1 -1
- package/dist/chat/tooltip-icon-button.cjs +2 -2
- package/dist/chat/tooltip-icon-button.cjs.map +1 -1
- package/dist/chat/use-athena-voice-live.cjs +11 -0
- package/dist/chat/use-athena-voice-live.cjs.map +1 -0
- package/dist/chat/use-athena-voice-live.d.ts +11 -0
- package/dist/chat/use-athena-voice-live.js +11 -0
- package/dist/chat/use-athena-voice-live.js.map +1 -0
- package/dist/chat/use-statewire-approval-request.cjs +56 -24
- package/dist/chat/use-statewire-approval-request.cjs.map +1 -1
- package/dist/chat/use-statewire-approval-request.d.ts +33 -4
- package/dist/chat/use-statewire-approval-request.js +41 -9
- package/dist/chat/use-statewire-approval-request.js.map +1 -1
- package/dist/chat-ui/auth/sign-in-card.cjs +2 -2
- package/dist/chat-ui/auth/sign-in-card.cjs.map +1 -1
- package/dist/chat-ui/composer/tiptap-composer.cjs +138 -107
- package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
- package/dist/chat-ui/composer/tiptap-composer.d.ts +20 -4
- package/dist/chat-ui/composer/tiptap-composer.js +85 -54
- package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
- package/dist/chat-ui/header/conversation-history-panel.cjs +49 -23
- package/dist/chat-ui/header/conversation-history-panel.cjs.map +1 -1
- package/dist/chat-ui/header/conversation-history-panel.d.ts +12 -1
- package/dist/chat-ui/header/conversation-history-panel.js +38 -12
- package/dist/chat-ui/header/conversation-history-panel.js.map +1 -1
- package/dist/chat-ui/index.cjs +18 -0
- package/dist/chat-ui/index.cjs.map +1 -1
- package/dist/chat-ui/index.d.ts +7 -1
- package/dist/chat-ui/index.js +18 -0
- package/dist/chat-ui/index.js.map +1 -1
- package/dist/chat-ui/mentions/mention-chip.cjs +4 -4
- package/dist/chat-ui/mentions/mention-chip.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-list.cjs +10 -9
- package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-list.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-list.js +3 -2
- package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-list.js.map +1 -1
- package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-popup.cjs +2 -2
- package/dist/chat-ui/mentions/suggestions/components/mention-suggestion-popup.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/components/menu-list.cjs +29 -6
- package/dist/chat-ui/mentions/suggestions/components/menu-list.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/components/menu-list.d.ts +7 -1
- package/dist/chat-ui/mentions/suggestions/components/menu-list.js +25 -2
- package/dist/chat-ui/mentions/suggestions/components/menu-list.js.map +1 -1
- package/dist/chat-ui/mentions/suggestions/components/use-keyboard-navigation.cjs +2 -2
- package/dist/chat-ui/mentions/suggestions/components/use-keyboard-navigation.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/components/use-menu-navigation.cjs +2 -2
- package/dist/chat-ui/mentions/suggestions/components/use-menu-navigation.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/data/api-client.cjs +3 -3
- package/dist/chat-ui/mentions/suggestions/data/api-client.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/data/orchestrator.cjs +56 -2
- package/dist/chat-ui/mentions/suggestions/data/orchestrator.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/data/orchestrator.d.ts +12 -0
- package/dist/chat-ui/mentions/suggestions/data/orchestrator.js +56 -2
- package/dist/chat-ui/mentions/suggestions/data/orchestrator.js.map +1 -1
- package/dist/chat-ui/mentions/suggestions/data/sources/index.cjs +24 -3
- package/dist/chat-ui/mentions/suggestions/data/sources/index.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/data/sources/index.d.ts +7 -0
- package/dist/chat-ui/mentions/suggestions/data/sources/index.js +24 -3
- package/dist/chat-ui/mentions/suggestions/data/sources/index.js.map +1 -1
- package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.cjs +35 -13
- package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.d.ts +15 -1
- package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.js +28 -6
- package/dist/chat-ui/mentions/suggestions/data/use-mention-suggestions.js.map +1 -1
- package/dist/chat-ui/mentions/suggestions/data/use-menu-items.cjs +9 -6
- package/dist/chat-ui/mentions/suggestions/data/use-menu-items.cjs.map +1 -1
- package/dist/chat-ui/mentions/suggestions/data/use-menu-items.d.ts +3 -0
- package/dist/chat-ui/mentions/suggestions/data/use-menu-items.js +5 -2
- package/dist/chat-ui/mentions/suggestions/data/use-menu-items.js.map +1 -1
- package/dist/chat-ui/mentions/use-account-workspace-id.cjs +45 -10
- package/dist/chat-ui/mentions/use-account-workspace-id.cjs.map +1 -1
- package/dist/chat-ui/mentions/use-account-workspace-id.d.ts +24 -1
- package/dist/chat-ui/mentions/use-account-workspace-id.js +46 -11
- package/dist/chat-ui/mentions/use-account-workspace-id.js.map +1 -1
- package/dist/chat-ui/mentions/use-member-avatar.cjs +4 -4
- package/dist/chat-ui/mentions/use-member-avatar.cjs.map +1 -1
- package/dist/chat-ui/mentions/use-mention-asset.cjs +3 -3
- package/dist/chat-ui/mentions/use-mention-asset.cjs.map +1 -1
- package/dist/chat-ui/messages/answer-label.cjs +42 -0
- package/dist/chat-ui/messages/answer-label.cjs.map +1 -0
- package/dist/chat-ui/messages/answer-label.d.ts +33 -0
- package/dist/chat-ui/messages/answer-label.js +42 -0
- package/dist/chat-ui/messages/answer-label.js.map +1 -0
- package/dist/chat-ui/messages/arrival-animation.cjs +13 -0
- package/dist/chat-ui/messages/arrival-animation.cjs.map +1 -0
- package/dist/chat-ui/messages/arrival-animation.d.ts +14 -0
- package/dist/chat-ui/messages/arrival-animation.js +13 -0
- package/dist/chat-ui/messages/arrival-animation.js.map +1 -0
- package/dist/chat-ui/messages/continue-pill.cjs +5 -5
- package/dist/chat-ui/messages/continue-pill.cjs.map +1 -1
- package/dist/chat-ui/messages/handoff-arrival-divider.cjs +44 -0
- package/dist/chat-ui/messages/handoff-arrival-divider.cjs.map +1 -0
- package/dist/chat-ui/messages/handoff-arrival-divider.d.ts +17 -0
- package/dist/chat-ui/messages/handoff-arrival-divider.js +44 -0
- package/dist/chat-ui/messages/handoff-arrival-divider.js.map +1 -0
- package/dist/chat-ui/messages/message-actions-config.cjs +3 -3
- package/dist/chat-ui/messages/message-actions-config.cjs.map +1 -1
- package/dist/chat-ui/messages/message-components.cjs +8 -4
- package/dist/chat-ui/messages/message-components.cjs.map +1 -1
- package/dist/chat-ui/messages/message-components.js +5 -1
- package/dist/chat-ui/messages/message-components.js.map +1 -1
- package/dist/chat-ui/messages/message-images.cjs +66 -0
- package/dist/chat-ui/messages/message-images.cjs.map +1 -0
- package/dist/chat-ui/messages/message-images.d.ts +16 -0
- package/dist/chat-ui/messages/message-images.js +66 -0
- package/dist/chat-ui/messages/message-images.js.map +1 -0
- package/dist/chat-ui/messages/user-edit-composer.cjs +2 -2
- package/dist/chat-ui/messages/user-edit-composer.cjs.map +1 -1
- package/dist/chat-ui/messages/wake-marker.cjs +3 -3
- package/dist/chat-ui/messages/wake-marker.cjs.map +1 -1
- package/dist/chat-ui/rich-text/chat-link.cjs +2 -2
- package/dist/chat-ui/rich-text/chat-link.cjs.map +1 -1
- package/dist/chat-ui/rich-text/chat-message-body.cjs +8 -8
- package/dist/chat-ui/rich-text/chat-message-body.cjs.map +1 -1
- package/dist/chat-ui/rich-text/chat-node-views.cjs +6 -6
- package/dist/chat-ui/rich-text/chat-node-views.cjs.map +1 -1
- package/dist/chat-ui/rich-text/dom-output-spec.cjs +2 -2
- package/dist/chat-ui/rich-text/dom-output-spec.cjs.map +1 -1
- package/dist/chat-ui/statewire.cjs +3 -0
- package/dist/chat-ui/statewire.cjs.map +1 -1
- package/dist/chat-ui/statewire.d.ts +2 -1
- package/dist/chat-ui/statewire.js +3 -0
- package/dist/chat-ui/statewire.js.map +1 -1
- package/dist/chat-ui/thread/chat-thread-shell.cjs +43 -14
- package/dist/chat-ui/thread/chat-thread-shell.cjs.map +1 -1
- package/dist/chat-ui/thread/chat-thread-shell.d.ts +16 -2
- package/dist/chat-ui/thread/chat-thread-shell.js +35 -6
- package/dist/chat-ui/thread/chat-thread-shell.js.map +1 -1
- package/dist/chat-ui/thread/composer-send-or-stop.cjs +30 -20
- package/dist/chat-ui/thread/composer-send-or-stop.cjs.map +1 -1
- package/dist/chat-ui/thread/composer-send-or-stop.d.ts +8 -0
- package/dist/chat-ui/thread/composer-send-or-stop.js +29 -19
- package/dist/chat-ui/thread/composer-send-or-stop.js.map +1 -1
- package/dist/chat-ui/thread/statewire-history-edge.cjs +20 -21
- package/dist/chat-ui/thread/statewire-history-edge.cjs.map +1 -1
- package/dist/chat-ui/thread/statewire-history-edge.js +3 -4
- package/dist/chat-ui/thread/statewire-history-edge.js.map +1 -1
- package/dist/chat-ui/thread/thread-loading-overlay.cjs +5 -5
- package/dist/chat-ui/thread/thread-loading-overlay.cjs.map +1 -1
- package/dist/collab/client.cjs +40 -3
- package/dist/collab/client.cjs.map +1 -1
- package/dist/collab/client.d.ts +25 -0
- package/dist/collab/client.js +40 -3
- package/dist/collab/client.js.map +1 -1
- package/dist/collab/document-status.cjs +150 -0
- package/dist/collab/document-status.cjs.map +1 -0
- package/dist/collab/document-status.d.ts +68 -0
- package/dist/collab/document-status.js +150 -0
- package/dist/collab/document-status.js.map +1 -0
- package/dist/collab/index.cjs +7 -0
- package/dist/collab/index.cjs.map +1 -1
- package/dist/collab/index.d.ts +6 -1
- package/dist/collab/index.js +7 -0
- package/dist/collab/index.js.map +1 -1
- package/dist/collab/presence-react.cjs +11 -11
- package/dist/collab/presence-react.cjs.map +1 -1
- package/dist/collab/react.cjs +6 -6
- package/dist/collab/react.cjs.map +1 -1
- package/dist/composer/AttachmentContext.cjs +24 -11
- package/dist/composer/AttachmentContext.cjs.map +1 -1
- package/dist/composer/AttachmentContext.js +18 -5
- package/dist/composer/AttachmentContext.js.map +1 -1
- package/dist/composer/ComposerAttachmentPreview.cjs +78 -23
- package/dist/composer/ComposerAttachmentPreview.cjs.map +1 -1
- package/dist/composer/ComposerAttachmentPreview.d.ts +5 -3
- package/dist/composer/ComposerAttachmentPreview.js +79 -24
- package/dist/composer/ComposerAttachmentPreview.js.map +1 -1
- package/dist/composer/ComposerDropZone.cjs +7 -7
- package/dist/composer/ComposerDropZone.cjs.map +1 -1
- package/dist/composer/FileUploadButton.cjs +37 -22
- package/dist/composer/FileUploadButton.cjs.map +1 -1
- package/dist/composer/FileUploadButton.d.ts +6 -0
- package/dist/composer/FileUploadButton.js +34 -19
- package/dist/composer/FileUploadButton.js.map +1 -1
- package/dist/composer/QuoteContext.cjs +8 -8
- package/dist/composer/QuoteContext.cjs.map +1 -1
- package/dist/composer/composer-handoff.cjs +4 -4
- package/dist/composer/composer-handoff.cjs.map +1 -1
- package/dist/composer/useAppendToComposer.cjs +4 -4
- package/dist/composer/useAppendToComposer.cjs.map +1 -1
- package/dist/composer/useAttachFiles.cjs +23 -6
- package/dist/composer/useAttachFiles.cjs.map +1 -1
- package/dist/composer/useAttachFiles.d.ts +15 -7
- package/dist/composer/useAttachFiles.js +22 -5
- package/dist/composer/useAttachFiles.js.map +1 -1
- package/dist/composer/useComposerAttachment.cjs +4 -4
- package/dist/composer/useComposerAttachment.cjs.map +1 -1
- package/dist/composer/useFileUpload.cjs +21 -16
- package/dist/composer/useFileUpload.cjs.map +1 -1
- package/dist/composer/useFileUpload.d.ts +12 -0
- package/dist/composer/useFileUpload.js +12 -7
- package/dist/composer/useFileUpload.js.map +1 -1
- package/dist/composer/useReadComposerDraft.cjs +2 -2
- package/dist/composer/useReadComposerDraft.cjs.map +1 -1
- package/dist/composer/useSendMessage.cjs +4 -4
- package/dist/composer/useSendMessage.cjs.map +1 -1
- package/dist/diagnostics/useAthenaDiagnostics.cjs +4 -4
- package/dist/diagnostics/useAthenaDiagnostics.cjs.map +1 -1
- package/dist/dictation/audio-level-history.cjs +3 -3
- package/dist/dictation/audio-level-history.cjs.map +1 -1
- package/dist/dictation/dictation-controls.cjs +24 -20
- package/dist/dictation/dictation-controls.cjs.map +1 -1
- package/dist/dictation/dictation-controls.d.ts +6 -1
- package/dist/dictation/dictation-controls.js +24 -20
- package/dist/dictation/dictation-controls.js.map +1 -1
- package/dist/dictation/use-athena-dictation-engine.cjs +3 -3
- package/dist/dictation/use-athena-dictation-engine.cjs.map +1 -1
- package/dist/dictation/use-dictation.cjs +22 -22
- package/dist/dictation/use-dictation.cjs.map +1 -1
- package/dist/index.cjs +26 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +15 -3
- package/dist/index.js +26 -2
- package/dist/index.js.map +1 -1
- package/dist/keryx-http/src/receive-only-socket.cjs +40 -0
- package/dist/keryx-http/src/receive-only-socket.cjs.map +1 -0
- package/dist/keryx-http/src/receive-only-socket.d.ts +27 -0
- package/dist/keryx-http/src/receive-only-socket.js +40 -0
- package/dist/keryx-http/src/receive-only-socket.js.map +1 -0
- package/dist/keryx-http/src/update-attributions.cjs +111 -0
- package/dist/keryx-http/src/update-attributions.cjs.map +1 -0
- package/dist/keryx-http/src/update-attributions.d.ts +75 -0
- package/dist/keryx-http/src/update-attributions.js +111 -0
- package/dist/keryx-http/src/update-attributions.js.map +1 -0
- package/dist/lib/owner-document.cjs +6 -6
- package/dist/lib/owner-document.cjs.map +1 -1
- package/dist/lib/use-athena-rest-query.cjs +4 -4
- package/dist/lib/use-athena-rest-query.cjs.map +1 -1
- package/dist/lib/use-document-active.cjs +4 -4
- package/dist/lib/use-document-active.cjs.map +1 -1
- package/dist/lib/use-prefers-reduced-motion.cjs +2 -2
- package/dist/lib/use-prefers-reduced-motion.cjs.map +1 -1
- package/dist/offline/offline-history.cjs +7 -7
- package/dist/offline/offline-history.cjs.map +1 -1
- package/dist/provider/AthenaContext.cjs +3 -3
- package/dist/provider/AthenaContext.cjs.map +1 -1
- package/dist/provider/AthenaProvider.cjs +116 -79
- package/dist/provider/AthenaProvider.cjs.map +1 -1
- package/dist/provider/AthenaProvider.js +40 -3
- package/dist/provider/AthenaProvider.js.map +1 -1
- package/dist/provider/PostHogProvider.cjs +2 -2
- package/dist/provider/PostHogProvider.cjs.map +1 -1
- package/dist/provider/agent-selection-context.cjs +2 -2
- package/dist/provider/agent-selection-context.cjs.map +1 -1
- package/dist/provider/chat-mode-context.cjs +2 -2
- package/dist/provider/chat-mode-context.cjs.map +1 -1
- package/dist/provider/session-persistence-context.cjs +10 -0
- package/dist/provider/session-persistence-context.cjs.map +1 -0
- package/dist/provider/session-persistence-context.d.ts +15 -0
- package/dist/provider/session-persistence-context.js +10 -0
- package/dist/provider/session-persistence-context.js.map +1 -0
- package/dist/provider/statewire-history-context.cjs +4 -4
- package/dist/provider/statewire-history-context.cjs.map +1 -1
- package/dist/provider/statewire-lifecycle-context.cjs +3 -3
- package/dist/provider/statewire-lifecycle-context.cjs.map +1 -1
- package/dist/provider/statewire-window-context.cjs +3 -3
- package/dist/provider/statewire-window-context.cjs.map +1 -1
- package/dist/provider/theme-style-context.cjs +3 -3
- package/dist/provider/theme-style-context.cjs.map +1 -1
- package/dist/react/package.json.cjs +1 -1
- package/dist/react/package.json.js +1 -1
- package/dist/runtime/StatewireThreadConfigLaneSync.cjs +10 -10
- package/dist/runtime/StatewireThreadConfigLaneSync.cjs.map +1 -1
- package/dist/runtime/auth-refusal-restart.cjs +7 -7
- package/dist/runtime/auth-refusal-restart.cjs.map +1 -1
- package/dist/runtime/auth.cjs +13 -13
- package/dist/runtime/auth.cjs.map +1 -1
- package/dist/runtime/statewire-lifecycle.cjs +1 -0
- package/dist/runtime/statewire-lifecycle.cjs.map +1 -1
- package/dist/runtime/statewire-lifecycle.d.ts +3 -1
- package/dist/runtime/statewire-lifecycle.js +2 -1
- package/dist/runtime/statewire-lifecycle.js.map +1 -1
- package/dist/runtime/statewire-server-lane-context.cjs +2 -2
- package/dist/runtime/statewire-server-lane-context.cjs.map +1 -1
- package/dist/runtime/statewire-session-lane.cjs +4 -4
- package/dist/runtime/statewire-session-lane.cjs.map +1 -1
- package/dist/runtime/useAthenaStatewireRuntime.cjs +10 -8
- package/dist/runtime/useAthenaStatewireRuntime.cjs.map +1 -1
- package/dist/runtime/useAthenaStatewireRuntime.d.ts +2 -0
- package/dist/runtime/useAthenaStatewireRuntime.js +2 -0
- package/dist/runtime/useAthenaStatewireRuntime.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/threads/Inbox.cjs +8 -8
- package/dist/threads/Inbox.cjs.map +1 -1
- package/dist/threads/SessionList.cjs +9 -9
- package/dist/threads/SessionList.cjs.map +1 -1
- package/dist/threads/SessionsPage.cjs +11 -11
- package/dist/threads/SessionsPage.cjs.map +1 -1
- package/dist/threads/index-triggered-refresh.cjs +10 -10
- package/dist/threads/index-triggered-refresh.cjs.map +1 -1
- package/dist/threads/mark-viewed-thread-read.cjs +12 -12
- package/dist/threads/mark-viewed-thread-read.cjs.map +1 -1
- package/dist/threads/offline-session-list.cjs +3 -3
- package/dist/threads/offline-session-list.cjs.map +1 -1
- package/dist/threads/session-list-tab-share.cjs +5 -5
- package/dist/threads/session-list-tab-share.cjs.map +1 -1
- package/dist/threads/statewire-thread-list.cjs +51 -51
- package/dist/threads/statewire-thread-list.cjs.map +1 -1
- package/dist/threads/thread-id-context.cjs +5 -5
- package/dist/threads/thread-id-context.cjs.map +1 -1
- package/dist/threads/use-athena-session-attention.cjs +2 -2
- package/dist/threads/use-athena-session-attention.cjs.map +1 -1
- package/dist/threads/use-athena-sessions.cjs +10 -10
- package/dist/threads/use-athena-sessions.cjs.map +1 -1
- package/dist/threads/use-athena-thread-model.cjs +3 -3
- package/dist/threads/use-athena-thread-model.cjs.map +1 -1
- package/dist/threads/use-rest-conversation-history.cjs +3 -3
- package/dist/threads/use-rest-conversation-history.cjs.map +1 -1
- package/dist/threads/use-statewire-conversation-history.cjs +8 -8
- package/dist/threads/use-statewire-conversation-history.cjs.map +1 -1
- package/dist/threads/use-thread-archive.cjs +9 -9
- package/dist/threads/use-thread-archive.cjs.map +1 -1
- package/dist/threads/use-thread-favorite.cjs +2 -2
- package/dist/threads/use-thread-favorite.cjs.map +1 -1
- package/dist/threads/use-thread-field-override.cjs +20 -20
- package/dist/threads/use-thread-field-override.cjs.map +1 -1
- package/dist/threads/use-thread-read-state.cjs +4 -4
- package/dist/threads/use-thread-read-state.cjs.map +1 -1
- package/dist/threads/use-thread-rename.cjs +2 -2
- package/dist/threads/use-thread-rename.cjs.map +1 -1
- package/dist/threads/useAthenaThreadManager.cjs +2 -2
- package/dist/threads/useAthenaThreadManager.cjs.map +1 -1
- package/dist/tools/NestedPtcMessages.cjs +6 -6
- package/dist/tools/NestedPtcMessages.cjs.map +1 -1
- package/dist/tools/append-document-tool-ui.cjs +7 -7
- package/dist/tools/append-document-tool-ui.cjs.map +1 -1
- package/dist/tools/file-tool-uis.cjs +2 -2
- package/dist/tools/file-tool-uis.cjs.map +1 -1
- package/dist/tools/misc-tool-uis.cjs +2 -2
- package/dist/tools/misc-tool-uis.cjs.map +1 -1
- package/dist/tools/primitives.cjs +6 -6
- package/dist/tools/primitives.cjs.map +1 -1
- package/dist/tools/read-asset-tool-ui.cjs +6 -6
- package/dist/tools/read-asset-tool-ui.cjs.map +1 -1
- package/dist/tools/subagent-task-tool-ui.cjs +21 -21
- package/dist/tools/subagent-task-tool-ui.cjs.map +1 -1
- package/dist/tools/test-recording-tool-uis.cjs +16 -16
- package/dist/tools/test-recording-tool-uis.cjs.map +1 -1
- package/dist/tools/todo-plan-store.cjs +4 -4
- package/dist/tools/todo-plan-store.cjs.map +1 -1
- package/dist/tools/tool-appearance.cjs +3 -3
- package/dist/tools/tool-appearance.cjs.map +1 -1
- package/dist/tools/tool-fallback.cjs +14 -14
- package/dist/tools/tool-fallback.cjs.map +1 -1
- package/dist/tools/tool-uis.cjs +74 -74
- package/dist/tools/tool-uis.cjs.map +1 -1
- package/dist/tools/use-elapsed-seconds.cjs +3 -3
- package/dist/tools/use-elapsed-seconds.cjs.map +1 -1
- package/dist/tools/write-todos-tool-ui.cjs +9 -9
- package/dist/tools/write-todos-tool-ui.cjs.map +1 -1
- package/dist/ui/image-viewer.cjs +382 -0
- package/dist/ui/image-viewer.cjs.map +1 -0
- package/dist/ui/image-viewer.d.ts +50 -0
- package/dist/ui/image-viewer.js +382 -0
- package/dist/ui/image-viewer.js.map +1 -0
- package/dist/voice/chat.cjs +6 -0
- package/dist/voice/chat.cjs.map +1 -1
- package/dist/voice/chat.d.ts +1 -1
- package/dist/voice/chat.js +8 -2
- package/dist/voice/livekit-join.cjs +52 -101
- package/dist/voice/livekit-join.cjs.map +1 -1
- package/dist/voice/livekit-join.d.ts +1 -6
- package/dist/voice/livekit-join.js +52 -101
- package/dist/voice/livekit-join.js.map +1 -1
- package/dist/voice/livekit.cjs.map +1 -1
- package/dist/voice/livekit.d.ts +11 -1
- package/dist/voice/livekit.js.map +1 -1
- package/dist/voice/use-athena-voice-session.cjs +34 -34
- package/dist/voice/use-athena-voice-session.cjs.map +1 -1
- package/dist/workbench/ComputerLiveDesktop.cjs +13 -13
- package/dist/workbench/ComputerLiveDesktop.cjs.map +1 -1
- package/dist/workbench/SessionWorkbench.cjs +22 -22
- package/dist/workbench/SessionWorkbench.cjs.map +1 -1
- package/dist/workbench/session-workbench-context.cjs +3 -3
- package/dist/workbench/session-workbench-context.cjs.map +1 -1
- package/dist/workbench/session-workbench-panes.cjs +8 -8
- package/dist/workbench/session-workbench-panes.cjs.map +1 -1
- package/dist/workbench/workbench-layout-context.cjs +3 -3
- package/dist/workbench/workbench-layout-context.cjs.map +1 -1
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-deep-agent-config.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-config.ts"],"sourcesContent":["import { useStatewireSendCommand, useStatewireState } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n applyConfigPatch,\n applyToolsDisable,\n applyToolsEnable,\n type ThreadConfigCustom,\n type ThreadConfigPatch,\n} from './config-mutations';\nimport { statewireRejectionPayload } from './errors';\nimport { DEEP_AGENT_CONFIG_COMMANDS } from './generated/runconfig-contract';\nimport { readDeepAgentStateThreadId } from './statewire-state';\n\ndeclare module '@assistant-ui/core' {\n namespace Assistant {\n interface Commands {\n /** Set / unset top-level keys of the thread's server config (`null` unsets). */\n configPatch: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch;\n patch: Record<string, unknown>;\n };\n /** Append ids to the thread's `enabled_tools`. */\n configToolsEnable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable;\n toolIds: string[];\n };\n /** Remove ids from the thread's `enabled_tools`. */\n configToolsDisable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable;\n toolIds: string[];\n };\n }\n }\n}\n\n/**\n * The replicated `state.config` lane of a thread with server-authoritative\n * run config. Absent — and `readServerConfig` returns `null` — while the\n * thread has never been configured (version 0: a brand-new thread, or one\n * created by a client predating the lane).\n */\nexport interface DeepAgentServerConfig {\n /** Monotonic server-incremented version; always >= 1 when the lane exists. */\n version: number;\n /** The thread-config keys every run on this thread uses as its base. */\n custom: ThreadConfigCustom;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read the server-config lane off a raw statewire state.\n *\n * Identity-preserving (returns the raw `state.config` reference), so it is\n * safe as a `useStatewireState` selector: the reference only changes when the\n * server writes the lane.\n */\nexport function readServerConfig(state: unknown): DeepAgentServerConfig | null {\n const config = (state as { config?: unknown } | null | undefined)?.config;\n if (!isRecord(config)) return null;\n const version = config.version;\n if (typeof version !== 'number' || !Number.isInteger(version) || version <= 0) return null;\n if (!isRecord(config.custom)) return null;\n return config as unknown as DeepAgentServerConfig;\n}\n\n/** The thread's server config version: 0 while the thread has never been configured. */\nexport function readConfigVersion(state: unknown): number {\n return readServerConfig(state)?.version ?? 0;\n}\n\n/**\n * {@link readServerConfig}, but only from a state `threadId`'s own attach\n * produced (`readDeepAgentStateThreadId`); any other state reads as\n * unconfigured. With no `threadId` it is {@link readServerConfig} unchanged.\n *\n * Identity-preserving like {@link readServerConfig}, so it is safe as a\n * `useStatewireState` selector.\n */\nexport function readThreadServerConfig({\n state,\n threadId,\n}: {\n state: unknown;\n threadId: string | undefined;\n}): DeepAgentServerConfig | null {\n if (threadId !== undefined && readDeepAgentStateThreadId(state) !== threadId) return null;\n return readServerConfig(state);\n}\n\n/**\n * The 403 rejection codes a view-only collaborator's `config/*` write can\n * come back with: `config_write_forbidden` from the config host's own gate,\n * or `thread_write_forbidden` from the host-wide mutation gate that runs\n * ahead of it and refuses every thread-mutating command on a view grant.\n */\nconst CONFIG_WRITE_FORBIDDEN_CODES: ReadonlySet<string> = new Set([\n 'config_write_forbidden',\n 'thread_write_forbidden',\n]);\n\n/**\n * Whether a rejected `config/*` command was refused because the submitter\n * only has view access to the session, or because the conversation is\n * archived (`conversation_archived`, a 409: read-only until it is restored).\n * The write is not retriable by that user; hosts disable their config\n * controls.\n */\nexport function isConfigWriteForbiddenRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n const detail = payload?.detail as { code?: unknown } | undefined;\n if (payload?.status === 409) return detail?.code === 'conversation_archived';\n if (payload?.status !== 403) return false;\n return typeof detail?.code === 'string' && CONFIG_WRITE_FORBIDDEN_CODES.has(detail.code);\n}\n\n/**\n * Whether a rejected `config/*` command was refused because the thread's\n * workspace cannot hold server config at all (`config_sync_unavailable`, a\n * regionally-pinned workspace). No write will ever succeed on the thread;\n * hosts stop issuing them and send their full config per run instead.\n */\nexport function isConfigSyncUnavailableRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n if (payload?.status !== 400) return false;\n const detail = payload.detail as { code?: unknown } | undefined;\n return detail?.code === 'config_sync_unavailable';\n}\n\n/** The settled result of a `config/*` command: the new server config. */\nexport interface DeepAgentConfigWriteResult {\n version: number;\n custom: ThreadConfigCustom;\n}\n\n/** An observed server-config version, delivered to the host callback. */\nexport interface DeepAgentServerConfigEvent {\n version: number;\n /** The server config with this client's still-pending writes folded over. */\n custom: ThreadConfigCustom;\n}\n\ninterface PendingOp {\n id: number;\n apply: (custom: ThreadConfigCustom) => ThreadConfigCustom;\n /** The version the server assigned this op; retired once the lane reaches it. */\n settledVersion: number | null;\n}\n\n/**\n * Fold the pending optimistic ops over the server config — the effective\n * config a client shows and sends against. Pure, for the tests.\n */\nexport function foldPendingConfigOps(\n serverConfig: DeepAgentServerConfig | null,\n ops: readonly Pick<PendingOp, 'apply' | 'settledVersion'>[]\n): ThreadConfigCustom {\n const version = serverConfig?.version ?? 0;\n let custom: ThreadConfigCustom = serverConfig?.custom ?? {};\n for (const op of ops) {\n if (op.settledVersion !== null && op.settledVersion <= version) continue;\n custom = op.apply(custom);\n }\n return custom;\n}\n\nexport interface UseDeepAgentConfigOptions {\n /**\n * Fired whenever the server writes a new version of the lane (another\n * device, the seed, or the echo of our own command), with this client's\n * still-pending writes folded over — hosts mirror it into their local\n * store; nothing is ever clobbered because pending edits stay on top.\n */\n onServerConfig?: (event: DeepAgentServerConfigEvent) => void;\n /**\n * The thread this binding serves. When set, the lane is read only from a\n * state that thread's own attach produced ({@link readThreadServerConfig}):\n * for the first render after a thread switch the client still projects the\n * previous thread's state, and adopting its lane would report the previous\n * thread's config and version as this thread's.\n */\n threadId?: string;\n}\n\nexport interface UseDeepAgentConfigResult {\n /** Reactive server config version (0 while the thread has never been configured). */\n configVersion: number;\n /** Reactive server-config lane, or `null` at version 0. */\n serverConfig: DeepAgentServerConfig | null;\n /**\n * The effective thread config: the server lane with this client's pending\n * writes folded over. `{}` at version 0 with nothing pending.\n */\n custom: ThreadConfigCustom;\n /** `true` while at least one `config/*` command is unacknowledged by the server. */\n hasPendingWrites: boolean;\n /** `config/patch` — set / unset top-level keys; `null` unsets. */\n patchConfig: (patch: ThreadConfigPatch) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/enable`. */\n enableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/disable`. */\n disableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n}\n\ntype ConfigCommand =\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch; patch: Record<string, unknown> }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable; toolIds: string[] }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable; toolIds: string[] };\n\n/**\n * The server-authoritative thread config of a deep-agent thread.\n *\n * Every capability a run depends on — model, agent binding, enabled tools,\n * sandbox, environment, … — lives on the thread's server config lane and is\n * changed only through the `config/*` commands. Sends carry per-send keys\n * only (`pickPerSendCustom`). The commands are applied optimistically: each\n * one folds its transform over the server config the moment it is issued\n * (`custom`), and retires once the lane reaches the version the server\n * assigned it; a rejection drops it, so the UI snaps back to the truth.\n *\n * Must be mounted under the thread's statewire context (an `AuiProvider`\n * holding `useDeepAgentThread`'s element), keyed by the thread identity so a\n * thread switch remounts it with an empty pending set. A binding that persists\n * what it reads per thread passes `threadId`, so the render that still sees\n * the previous thread's state after a switch reads no lane at all.\n */\nexport function useDeepAgentConfig({\n threadId,\n ...options\n}: UseDeepAgentConfigOptions = {}): UseDeepAgentConfigResult {\n const sendCommand = useStatewireSendCommand();\n const selectServerConfig = useCallback(\n (state: unknown) => readThreadServerConfig({ state, threadId }),\n [threadId]\n );\n const serverConfig = useStatewireState(selectServerConfig);\n return useDeepAgentConfigController({\n serverConfig,\n sendCommand: (command) => Promise.resolve(sendCommand(command as never)),\n ...options,\n });\n}\n\nexport interface DeepAgentConfigControllerInputs extends UseDeepAgentConfigOptions {\n serverConfig: DeepAgentServerConfig | null;\n sendCommand: (command: ConfigCommand) => Promise<unknown>;\n}\n\n/**\n * The transport-agnostic body of {@link useDeepAgentConfig}, with the reactive\n * inputs injected — so the optimistic-overlay behavior is testable without a\n * statewire session.\n */\nexport function useDeepAgentConfigController({\n serverConfig,\n sendCommand,\n onServerConfig,\n}: DeepAgentConfigControllerInputs): UseDeepAgentConfigResult {\n const [ops, setOps] = useState<readonly PendingOp[]>([]);\n const nextOpIdRef = useRef(1);\n const sendCommandRef = useRef(sendCommand);\n sendCommandRef.current = sendCommand;\n const onServerConfigRef = useRef(onServerConfig);\n onServerConfigRef.current = onServerConfig;\n\n const custom = useMemo(() => foldPendingConfigOps(serverConfig, ops), [serverConfig, ops]);\n\n // Retire ops the lane has caught up with (their transform is now part of\n // the server config itself).\n const serverVersion = serverConfig?.version ?? 0;\n const serverVersionRef = useRef(serverVersion);\n serverVersionRef.current = serverVersion;\n useEffect(() => {\n setOps((current) => {\n const kept = current.filter(\n (op) => op.settledVersion === null || op.settledVersion > serverVersion\n );\n return kept.length === current.length ? current : kept;\n });\n }, [serverVersion]);\n\n const lastNotifiedRef = useRef<DeepAgentServerConfig | null>(null);\n useEffect(() => {\n if (serverConfig === null || serverConfig === lastNotifiedRef.current) return;\n lastNotifiedRef.current = serverConfig;\n onServerConfigRef.current?.({ version: serverConfig.version, custom });\n }, [serverConfig, custom]);\n\n const run = useCallback(\n async (\n command: ConfigCommand,\n apply: PendingOp['apply']\n ): Promise<DeepAgentConfigWriteResult> => {\n const id = nextOpIdRef.current++;\n setOps((current) => [...current, { id, apply, settledVersion: null }]);\n try {\n const raw = (await sendCommandRef.current(command)) as\n | { version?: unknown; custom?: unknown }\n | null\n | undefined;\n const version = typeof raw?.version === 'number' ? raw.version : Number.POSITIVE_INFINITY;\n // The lane echo may have landed before the acknowledgement: retire\n // now if so, otherwise stamp the version for the retire effect.\n setOps((current) =>\n version <= serverVersionRef.current\n ? current.filter((op) => op.id !== id)\n : current.map((op) => (op.id === id ? { ...op, settledVersion: version } : op))\n );\n return {\n version: Number.isFinite(version) ? version : 0,\n custom: isRecord(raw?.custom) ? raw.custom : apply({}),\n };\n } catch (error) {\n setOps((current) => current.filter((op) => op.id !== id));\n throw error;\n }\n },\n []\n );\n\n const patchConfig = useCallback(\n (patch: ThreadConfigPatch) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.patch, patch }, (base) =>\n applyConfigPatch(base, patch)\n ),\n [run]\n );\n const enableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsEnable, toolIds: [...toolIds] }, (base) =>\n applyToolsEnable(base, toolIds)\n ),\n [run]\n );\n const disableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsDisable, toolIds: [...toolIds] }, (base) =>\n applyToolsDisable(base, toolIds)\n ),\n [run]\n );\n\n return {\n configVersion: serverVersion,\n serverConfig,\n custom,\n hasPendingWrites: ops.some((op) => op.settledVersion === null),\n patchConfig,\n enableTools,\n disableTools,\n };\n}\n"],"names":["statewireRejectionPayload","useState","useRef","useMemo","useEffect","useCallback","DEEP_AGENT_CONFIG_COMMANDS","applyConfigPatch","applyToolsEnable","applyToolsDisable"],"mappings":";;;;;;;AAgDA,MAAM,WAAW,CAAC,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAS9D,SAAS,iBAAiB,OAA8C;AAC7E,QAAM,SAAU,+BAAmD;AACnE,MAAI,CAAC,SAA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AAM,CAAA,CAAE;AAAA,QAAA;AAAA,MAEzD,SAAS,OAAO;AACd,eAAO,CAAC,YAAY,QAAQ,OAAO,CAAC,OAAO,GAAG,OAAO,EAAE,CAAC;AACxD,cAAM;AAAA,MACR;AAAA,IACF;AAAA,IACA,CAAA;AAAA,EAAC;AAGH,QAAM,cAAcA,MAAAA;AAAAA,IAClB,CAAC,UACC;AAAA,MAAI,EAAE,MAAMC,kBAAAA,2BAA2B,OAAO,MAAA;AAAA,MAAS,CAAC,SACtDC,iCAAiB,MAAM,KAAK;AAAA,IAAA;AAAA,IAEhC,CAAC,GAAG;AAAA,EAAA;AAEN,QAAM,cAAcF,MAAAA;AAAAA,IAClB,CAAC,YACC;AAAA,MAAI,EAAE,MAAMC,kBAAAA,2BAA2B,aAAa,SAAS,CAAC,GAAG,OAAO,EAAA;AAAA,MAAK,CAAC,SAC5EE,iCAAiB,MAAM,OAAO;AAAA,IAAA;AAAA,IAElC,CAAC,GAAG;AAAA,EAAA;AAEN,QAAM,eAAeH,MAAAA;AAAAA,IACnB,CAAC,YACC;AAAA,MAAI,EAAE,MAAMC,kBAAAA,2BAA2B,cAAc,SAAS,CAAC,GAAG,OAAO,EAAA;AAAA,MAAK,CAAC,SAC7EG,kCAAkB,MAAM,OAAO;AAAA,IAAA;AAAA,IAEnC,CAAC,GAAG;AAAA,EAAA;AAGN,SAAO;AAAA,IACL,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,kBAAkB,IAAI,KAAK,CAAC,OAAO,GAAG,mBAAmB,IAAI;AAAA,IAC7D;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;;;;;;"}
|
|
1
|
+
{"version":3,"file":"use-deep-agent-config.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-config.ts"],"sourcesContent":["import { useStatewireSendCommand, useStatewireState } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport {\n applyConfigPatch,\n applyToolsDisable,\n applyToolsEnable,\n type ThreadConfigCustom,\n type ThreadConfigPatch,\n} from './config-mutations';\nimport { statewireRejectionPayload } from './errors';\nimport { DEEP_AGENT_CONFIG_COMMANDS } from './generated/runconfig-contract';\nimport { readDeepAgentStateThreadId } from './statewire-state';\n\ndeclare module '@assistant-ui/core' {\n namespace Assistant {\n interface Commands {\n /** Set / unset top-level keys of the thread's server config (`null` unsets). */\n configPatch: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch;\n patch: Record<string, unknown>;\n };\n /** Append ids to the thread's `enabled_tools`. */\n configToolsEnable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable;\n toolIds: string[];\n };\n /** Remove ids from the thread's `enabled_tools`. */\n configToolsDisable: {\n type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable;\n toolIds: string[];\n };\n }\n }\n}\n\n/**\n * The replicated `state.config` lane of a thread with server-authoritative\n * run config. Absent — and `readServerConfig` returns `null` — while the\n * thread has never been configured (version 0: a brand-new thread, or one\n * created by a client predating the lane).\n */\nexport interface DeepAgentServerConfig {\n /** Monotonic server-incremented version; always >= 1 when the lane exists. */\n version: number;\n /** The thread-config keys every run on this thread uses as its base. */\n custom: ThreadConfigCustom;\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read the server-config lane off a raw statewire state.\n *\n * Identity-preserving (returns the raw `state.config` reference), so it is\n * safe as a `useStatewireState` selector: the reference only changes when the\n * server writes the lane.\n */\nexport function readServerConfig(state: unknown): DeepAgentServerConfig | null {\n const config = (state as { config?: unknown } | null | undefined)?.config;\n if (!isRecord(config)) return null;\n const version = config.version;\n if (typeof version !== 'number' || !Number.isInteger(version) || version <= 0) return null;\n if (!isRecord(config.custom)) return null;\n return config as unknown as DeepAgentServerConfig;\n}\n\n/** The thread's server config version: 0 while the thread has never been configured. */\nexport function readConfigVersion(state: unknown): number {\n return readServerConfig(state)?.version ?? 0;\n}\n\n/**\n * {@link readServerConfig}, but only from a state `threadId`'s own attach\n * produced (`readDeepAgentStateThreadId`); any other state reads as\n * unconfigured. With no `threadId` it is {@link readServerConfig} unchanged.\n *\n * Identity-preserving like {@link readServerConfig}, so it is safe as a\n * `useStatewireState` selector.\n */\nexport function readThreadServerConfig({\n state,\n threadId,\n}: {\n state: unknown;\n threadId: string | undefined;\n}): DeepAgentServerConfig | null {\n if (threadId !== undefined && readDeepAgentStateThreadId(state) !== threadId) return null;\n return readServerConfig(state);\n}\n\n/**\n * The 403 rejection codes a view-only collaborator's `config/*` write can\n * come back with: `config_write_forbidden` from the config host's own gate,\n * or `thread_write_forbidden` from the host-wide mutation gate that runs\n * ahead of it and refuses every thread-mutating command on a view grant.\n */\nconst CONFIG_WRITE_FORBIDDEN_CODES: ReadonlySet<string> = new Set([\n 'config_write_forbidden',\n 'thread_write_forbidden',\n]);\n\n/**\n * Whether a rejected `config/*` command was refused because the submitter\n * only has view access to the session, or because the conversation is\n * archived (`conversation_archived`, a 409: read-only until it is restored).\n * The write is not retriable by that user; hosts disable their config\n * controls.\n */\nexport function isConfigWriteForbiddenRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n const detail = payload?.detail as { code?: unknown } | undefined;\n if (payload?.status === 409) return detail?.code === 'conversation_archived';\n if (payload?.status !== 403) return false;\n return typeof detail?.code === 'string' && CONFIG_WRITE_FORBIDDEN_CODES.has(detail.code);\n}\n\n/**\n * Whether a rejected `config/*` command was refused because the thread's\n * workspace cannot hold server config at all (`config_sync_unavailable`, a\n * regionally-pinned workspace). No write will ever succeed on the thread;\n * hosts stop issuing them and send their full config per run instead.\n */\nexport function isConfigSyncUnavailableRejection(error: unknown): boolean {\n const payload = statewireRejectionPayload(error);\n if (payload?.status !== 400) return false;\n const detail = payload.detail as { code?: unknown } | undefined;\n return detail?.code === 'config_sync_unavailable';\n}\n\n/** The settled result of a `config/*` command: the new server config. */\nexport interface DeepAgentConfigWriteResult {\n version: number;\n custom: ThreadConfigCustom;\n}\n\n/** An observed server-config version, delivered to the host callback. */\nexport interface DeepAgentServerConfigEvent {\n version: number;\n /** The server config with this client's still-pending writes folded over. */\n custom: ThreadConfigCustom;\n}\n\ninterface PendingOp {\n id: number;\n apply: (custom: ThreadConfigCustom) => ThreadConfigCustom;\n /** The version the server assigned this op; retired once the lane reaches it. */\n settledVersion: number | null;\n}\n\n/**\n * Fold the pending optimistic ops over the server config — the effective\n * config a client shows and sends against. Pure, for the tests.\n */\nexport function foldPendingConfigOps(\n serverConfig: DeepAgentServerConfig | null,\n ops: readonly Pick<PendingOp, 'apply' | 'settledVersion'>[]\n): ThreadConfigCustom {\n const version = serverConfig?.version ?? 0;\n let custom: ThreadConfigCustom = serverConfig?.custom ?? {};\n for (const op of ops) {\n if (op.settledVersion !== null && op.settledVersion <= version) continue;\n custom = op.apply(custom);\n }\n return custom;\n}\n\nexport interface UseDeepAgentConfigOptions {\n /**\n * Fired whenever the server writes a new version of the lane (another\n * device, the seed, or the echo of our own command), with this client's\n * still-pending writes folded over — hosts mirror it into their local\n * store; nothing is ever clobbered because pending edits stay on top.\n */\n onServerConfig?: (event: DeepAgentServerConfigEvent) => void;\n /**\n * The thread this binding serves. When set, the lane is read only from a\n * state that thread's own attach produced ({@link readThreadServerConfig}):\n * for the first render after a thread switch the client still projects the\n * previous thread's state, and adopting its lane would report the previous\n * thread's config and version as this thread's.\n */\n threadId?: string;\n}\n\nexport interface UseDeepAgentConfigResult {\n /** Reactive server config version (0 while the thread has never been configured). */\n configVersion: number;\n /** Reactive server-config lane, or `null` at version 0. */\n serverConfig: DeepAgentServerConfig | null;\n /**\n * The effective thread config: the server lane with this client's pending\n * writes folded over. `{}` at version 0 with nothing pending.\n */\n custom: ThreadConfigCustom;\n /** `true` while at least one `config/*` command is unacknowledged by the server. */\n hasPendingWrites: boolean;\n /** `config/patch` — set / unset top-level keys; `null` unsets. */\n patchConfig: (patch: ThreadConfigPatch) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/enable`. */\n enableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n /** `config/tools/disable`. */\n disableTools: (toolIds: readonly string[]) => Promise<DeepAgentConfigWriteResult>;\n}\n\ntype ConfigCommand =\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.patch; patch: Record<string, unknown> }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsEnable; toolIds: string[] }\n | { type: typeof DEEP_AGENT_CONFIG_COMMANDS.toolsDisable; toolIds: string[] };\n\n/**\n * The server-authoritative thread config of a deep-agent thread.\n *\n * Every capability a run depends on — model, agent binding, enabled tools,\n * sandbox, environment, … — lives on the thread's server config lane and is\n * changed only through the `config/*` commands. Sends carry per-send keys\n * only (`pickPerSendCustom`). The commands are applied optimistically: each\n * one folds its transform over the server config the moment it is issued\n * (`custom`), and retires once the lane reaches the version the server\n * assigned it; a rejection drops it, so the UI snaps back to the truth.\n *\n * Must be mounted under the thread's statewire context (an `AuiProvider`\n * holding `useDeepAgentThread`'s element), keyed by the thread identity so a\n * thread switch remounts it with an empty pending set. A binding that persists\n * what it reads per thread passes `threadId`, so the render that still sees\n * the previous thread's state after a switch reads no lane at all.\n */\nexport function useDeepAgentConfig({\n threadId,\n ...options\n}: UseDeepAgentConfigOptions = {}): UseDeepAgentConfigResult {\n const sendCommand = useStatewireSendCommand();\n const selectServerConfig = useCallback(\n (state: unknown) => readThreadServerConfig({ state, threadId }),\n [threadId]\n );\n const serverConfig = useStatewireState(selectServerConfig);\n return useDeepAgentConfigController({\n serverConfig,\n sendCommand: (command) => Promise.resolve(sendCommand(command as never)),\n ...options,\n });\n}\n\nexport interface DeepAgentConfigControllerInputs extends UseDeepAgentConfigOptions {\n serverConfig: DeepAgentServerConfig | null;\n sendCommand: (command: ConfigCommand) => Promise<unknown>;\n}\n\n/**\n * The transport-agnostic body of {@link useDeepAgentConfig}, with the reactive\n * inputs injected — so the optimistic-overlay behavior is testable without a\n * statewire session.\n */\nexport function useDeepAgentConfigController({\n serverConfig,\n sendCommand,\n onServerConfig,\n}: DeepAgentConfigControllerInputs): UseDeepAgentConfigResult {\n const [ops, setOps] = useState<readonly PendingOp[]>([]);\n const nextOpIdRef = useRef(1);\n const sendCommandRef = useRef(sendCommand);\n sendCommandRef.current = sendCommand;\n const onServerConfigRef = useRef(onServerConfig);\n onServerConfigRef.current = onServerConfig;\n\n const custom = useMemo(() => foldPendingConfigOps(serverConfig, ops), [serverConfig, ops]);\n\n // Retire ops the lane has caught up with (their transform is now part of\n // the server config itself).\n const serverVersion = serverConfig?.version ?? 0;\n const serverVersionRef = useRef(serverVersion);\n serverVersionRef.current = serverVersion;\n useEffect(() => {\n setOps((current) => {\n const kept = current.filter(\n (op) => op.settledVersion === null || op.settledVersion > serverVersion\n );\n return kept.length === current.length ? current : kept;\n });\n }, [serverVersion]);\n\n const lastNotifiedRef = useRef<DeepAgentServerConfig | null>(null);\n useEffect(() => {\n if (serverConfig === null || serverConfig === lastNotifiedRef.current) return;\n lastNotifiedRef.current = serverConfig;\n onServerConfigRef.current?.({ version: serverConfig.version, custom });\n }, [serverConfig, custom]);\n\n const run = useCallback(\n async (\n command: ConfigCommand,\n apply: PendingOp['apply']\n ): Promise<DeepAgentConfigWriteResult> => {\n const id = nextOpIdRef.current++;\n setOps((current) => [...current, { id, apply, settledVersion: null }]);\n try {\n const raw = (await sendCommandRef.current(command)) as\n | { version?: unknown; custom?: unknown }\n | null\n | undefined;\n const version = typeof raw?.version === 'number' ? raw.version : Number.POSITIVE_INFINITY;\n // The lane echo may have landed before the acknowledgement: retire\n // now if so, otherwise stamp the version for the retire effect.\n setOps((current) =>\n version <= serverVersionRef.current\n ? current.filter((op) => op.id !== id)\n : current.map((op) => (op.id === id ? { ...op, settledVersion: version } : op))\n );\n return {\n version: Number.isFinite(version) ? version : 0,\n custom: isRecord(raw?.custom) ? raw.custom : apply({}),\n };\n } catch (error) {\n setOps((current) => current.filter((op) => op.id !== id));\n throw error;\n }\n },\n []\n );\n\n const patchConfig = useCallback(\n (patch: ThreadConfigPatch) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.patch, patch }, (base) =>\n applyConfigPatch(base, patch)\n ),\n [run]\n );\n const enableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsEnable, toolIds: [...toolIds] }, (base) =>\n applyToolsEnable(base, toolIds)\n ),\n [run]\n );\n const disableTools = useCallback(\n (toolIds: readonly string[]) =>\n run({ type: DEEP_AGENT_CONFIG_COMMANDS.toolsDisable, toolIds: [...toolIds] }, (base) =>\n applyToolsDisable(base, toolIds)\n ),\n [run]\n );\n\n return {\n configVersion: serverVersion,\n serverConfig,\n custom,\n hasPendingWrites: ops.some((op) => op.settledVersion === null),\n patchConfig,\n enableTools,\n disableTools,\n };\n}\n"],"names":["statewireRejectionPayload","useState","useRef","useMemo","useEffect","useCallback","DEEP_AGENT_CONFIG_COMMANDS","applyConfigPatch","applyToolsEnable","applyToolsDisable"],"mappings":";;;;;;;AAgDA,MAAM,WAAW,CAAC,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAS9D,SAAS,iBAAiB,OAA8C;AAC7E,QAAM,SAAU,+BAAmD;AACnE,MAAI,CAAC,SAAS,MAAM,EAAG,QAAO;AAC9B,QAAM,UAAU,OAAO;AACvB,MAAI,OAAO,YAAY,YAAY,CAAC,OAAO,UAAU,OAAO,KAAK,WAAW,EAAG,QAAO;AACtF,MAAI,CAAC,SAAS,OAAO,MAAM,EAAG,QAAO;AACrC,SAAO;AACT;AAgCA,MAAM,mDAAwD,IAAI;AAAA,EAChE;AAAA,EACA;AACF,CAAC;AASM,SAAS,gCAAgC,OAAyB;AACvE,QAAM,UAAUA,OAAAA,0BAA0B,KAAK;AAC/C,QAAM,SAAS,mCAAS;AACxB,OAAI,mCAAS,YAAW,IAAK,SAAO,iCAAQ,UAAS;AACrD,OAAI,mCAAS,YAAW,IAAK,QAAO;AACpC,S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AAAA,MAAI,EAAE,MAAMC,kBAAAA,2BAA2B,aAAa,SAAS,CAAC,GAAG,OAAO,EAAA;AAAA,MAAK,CAAC,SAC5EE,iCAAiB,MAAM,OAAO;AAAA,IAAA;AAAA,IAElC,CAAC,GAAG;AAAA,EAAA;AAEN,QAAM,eAAeH,WAAAA;AAAAA,IACnB,CAAC,YACC;AAAA,MAAI,EAAE,MAAMC,kBAAAA,2BAA2B,cAAc,SAAS,CAAC,GAAG,OAAO,EAAA;AAAA,MAAK,CAAC,SAC7EG,kCAAkB,MAAM,OAAO;AAAA,IAAA;AAAA,IAEnC,CAAC,GAAG;AAAA,EAAA;AAGN,SAAO;AAAA,IACL,eAAe;AAAA,IACf;AAAA,IACA;AAAA,IACA,kBAAkB,IAAI,KAAK,CAAC,OAAO,GAAG,mBAAmB,IAAI;AAAA,IAC7D;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const store = require("@assistant-ui/store");
|
|
4
|
-
const
|
|
4
|
+
const require$$0 = require("react");
|
|
5
5
|
const chatOutbox = require("./chat-outbox.cjs");
|
|
6
6
|
const editCommand = require("./edit-command.cjs");
|
|
7
7
|
const useDeepAgentChatOutbox = require("./use-deep-agent-chat-outbox.cjs");
|
|
@@ -10,17 +10,17 @@ function useDeepAgentMessageEditSubmit() {
|
|
|
10
10
|
useHistoricalEditAttachments.useHistoricalEditAttachments();
|
|
11
11
|
const aui = store.useAui();
|
|
12
12
|
const outbox = useDeepAgentChatOutbox.useDeepAgentChatOutboxContext();
|
|
13
|
-
const outboxRef =
|
|
13
|
+
const outboxRef = require$$0.useRef(outbox);
|
|
14
14
|
outboxRef.current = outbox;
|
|
15
|
-
const alive =
|
|
16
|
-
const submitting =
|
|
17
|
-
|
|
15
|
+
const alive = require$$0.useRef(true);
|
|
16
|
+
const submitting = require$$0.useRef(false);
|
|
17
|
+
require$$0.useEffect(() => {
|
|
18
18
|
alive.current = true;
|
|
19
19
|
return () => {
|
|
20
20
|
alive.current = false;
|
|
21
21
|
};
|
|
22
22
|
}, []);
|
|
23
|
-
return
|
|
23
|
+
return require$$0.useCallback(async () => {
|
|
24
24
|
var _a, _b, _c;
|
|
25
25
|
if (submitting.current) return false;
|
|
26
26
|
const composer = aui.message().composer();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-deep-agent-edit-submit.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-edit-submit.ts"],"sourcesContent":["import { useAui } from '@assistant-ui/store';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useRef } from 'react';\nimport { ChatEditUnreachableError } from './chat-outbox';\nimport { readDeepAgentStatewireExtras, resolveDeepAgentEditCommand } from './edit-command';\nimport { useDeepAgentChatOutboxContext } from './use-deep-agent-chat-outbox';\nimport { useHistoricalEditAttachments } from './use-historical-edit-attachments';\n\n/**\n * The submit handler of a message's edit composer on a deep-agent thread: the\n * edited text leaves as a `run/edit` anchored on the host's own parent of the\n * message (see `edit-command.ts`) — older pages stated first for a message at\n * or below the loaded window's edge — instead of the library's\n * converted-message anchor, which the host rejects `wrong-anchor` after a\n * chunked assistant turn and at the window edge.\n *\n * Read inside the message scope (`aui.message()`): the library's optimistic\n * fold shows the edited bubble and rewinds the visible history the moment the\n * command is dispatched, so the edit composer closes right away. Falls back\n * to the composer's own `send()` when the thread is not a statewire thread or\n * the host has not settled the message yet. Resolves `false` for an empty\n * draft, a duplicate submission, or an edit cancelled during preparation.\n *\n * While the thread's chat outbox (a host that keeps one) says Athena can't be\n * reached, it rejects with {@link ChatEditUnreachableError} and sends nothing:\n * an edit rewinds and re-runs the conversation, and statewire would replay a\n * journaled one the moment its connection returns, from a hidden window too.\n * The draft stays in the edit composer, which says why.\n */\nexport function useDeepAgentMessageEditSubmit(): () => Promise<boolean> {\n useHistoricalEditAttachments();\n const aui = useAui();\n const outbox = useDeepAgentChatOutboxContext();\n const outboxRef = useRef(outbox);\n outboxRef.current = outbox;\n const alive = useRef(true);\n const submitting = useRef(false);\n useEffect(() => {\n alive.current = true;\n return () => {\n alive.current = false;\n };\n }, []);\n return useCallback(async () => {\n if (submitting.current) return false;\n const composer = aui.message().composer();\n const draft = composer.getState();\n const text = draft.text.trim();\n if (!text && draft.attachments.length === 0) return false;\n // Read at the submit (an edit begun while Athena answered and sent after it went is refused\n // too) and again right before anything is sent: preparing an edit can page older history in.\n const refuseWhileUnreachable = (): void => {\n const reachability = outboxRef.current?.reachability;\n if (reachability && !reachability.get()) throw new ChatEditUnreachableError();\n };\n refuseWhileUnreachable();\n const files: StatewireThread.FilePart[] = [];\n const texts = text ? [text] : [];\n // beginEdit lifts original inline images/files into completed composer\n // attachments. The anchored command must carry those too: a text-only\n // reconstruction silently deleted them when editing a cross-device turn.\n for (const attachment of draft.attachments) {\n if (attachment.status.type !== 'complete')\n throw new Error('Wait for attachments to finish before sending your edit.');\n for (const part of attachment.content ?? []) {\n if (part.type === 'text') texts.push(part.text);\n else if (part.type === 'image')\n files.push({ type: 'file', mediaType: 'image/*', url: part.image });\n else if (part.type === 'file')\n files.push({\n type: 'file',\n mediaType: part.mimeType,\n url: part.data,\n ...(part.filename && { filename: part.filename }),\n });\n else throw new Error('This attachment cannot be edited here.');\n }\n }\n submitting.current = true;\n try {\n const sourceId = aui.message().getState().id;\n const readExtras = () =>\n alive.current ? readDeepAgentStatewireExtras(aui.thread().getState().extras) : null;\n const extras = readExtras();\n if (extras) {\n const preparedMetadata = extras.prepareMessageMetadata?.();\n try {\n const command = await resolveDeepAgentEditCommand({\n readExtras,\n sourceId,\n text,\n });\n if (!alive.current || !composer.getState().isEditing) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n return false;\n }\n // Athena can have gone while older history was paged in: the edit stays a draft (the\n // catch below lets its prepared metadata go).\n refuseWhileUnreachable();\n if (command) {\n void Promise.resolve(\n extras.sendCommand(\n {\n ...command,\n message: {\n ...command.message,\n parts: [\n ...files,\n ...(texts.length\n ? [{ type: 'text' as const, text: texts.join('\\n\\n') }]\n : []),\n ],\n },\n },\n preparedMetadata === undefined ? undefined : { preparedMetadata },\n ),\n ).catch(() => undefined);\n composer.cancel();\n return true;\n }\n if (preparedMetadata && extras.sendPreparedEdit) {\n extras.sendPreparedEdit(sourceId, preparedMetadata);\n return true;\n }\n } catch (error) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n throw error;\n }\n }\n refuseWhileUnreachable();\n composer.send();\n return true;\n } finally {\n submitting.current = false;\n }\n }, [aui]);\n}\n"],"names":["useHistoricalEditAttachments","useAui","useDeepAgentChatOutboxContext","useRef","useEffect","useCallback","_a","ChatEditUnreachableError","readDeepAgentStatewireExtras","resolveDeepAgentEditCommand"],"mappings":";;;;;;;;AA6BO,SAAS,gCAAwD;AACtEA,4DAAA;AACA,QAAM,MAAMC,MAAAA,OAAA;AACZ,QAAM,SAASC,uBAAAA,8BAAA;AACf,QAAM,YAAYC,
|
|
1
|
+
{"version":3,"file":"use-deep-agent-edit-submit.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-edit-submit.ts"],"sourcesContent":["import { useAui } from '@assistant-ui/store';\nimport type { StatewireThread } from '@assistant-ui/react-statewire';\nimport { useCallback, useEffect, useRef } from 'react';\nimport { ChatEditUnreachableError } from './chat-outbox';\nimport { readDeepAgentStatewireExtras, resolveDeepAgentEditCommand } from './edit-command';\nimport { useDeepAgentChatOutboxContext } from './use-deep-agent-chat-outbox';\nimport { useHistoricalEditAttachments } from './use-historical-edit-attachments';\n\n/**\n * The submit handler of a message's edit composer on a deep-agent thread: the\n * edited text leaves as a `run/edit` anchored on the host's own parent of the\n * message (see `edit-command.ts`) — older pages stated first for a message at\n * or below the loaded window's edge — instead of the library's\n * converted-message anchor, which the host rejects `wrong-anchor` after a\n * chunked assistant turn and at the window edge.\n *\n * Read inside the message scope (`aui.message()`): the library's optimistic\n * fold shows the edited bubble and rewinds the visible history the moment the\n * command is dispatched, so the edit composer closes right away. Falls back\n * to the composer's own `send()` when the thread is not a statewire thread or\n * the host has not settled the message yet. Resolves `false` for an empty\n * draft, a duplicate submission, or an edit cancelled during preparation.\n *\n * While the thread's chat outbox (a host that keeps one) says Athena can't be\n * reached, it rejects with {@link ChatEditUnreachableError} and sends nothing:\n * an edit rewinds and re-runs the conversation, and statewire would replay a\n * journaled one the moment its connection returns, from a hidden window too.\n * The draft stays in the edit composer, which says why.\n */\nexport function useDeepAgentMessageEditSubmit(): () => Promise<boolean> {\n useHistoricalEditAttachments();\n const aui = useAui();\n const outbox = useDeepAgentChatOutboxContext();\n const outboxRef = useRef(outbox);\n outboxRef.current = outbox;\n const alive = useRef(true);\n const submitting = useRef(false);\n useEffect(() => {\n alive.current = true;\n return () => {\n alive.current = false;\n };\n }, []);\n return useCallback(async () => {\n if (submitting.current) return false;\n const composer = aui.message().composer();\n const draft = composer.getState();\n const text = draft.text.trim();\n if (!text && draft.attachments.length === 0) return false;\n // Read at the submit (an edit begun while Athena answered and sent after it went is refused\n // too) and again right before anything is sent: preparing an edit can page older history in.\n const refuseWhileUnreachable = (): void => {\n const reachability = outboxRef.current?.reachability;\n if (reachability && !reachability.get()) throw new ChatEditUnreachableError();\n };\n refuseWhileUnreachable();\n const files: StatewireThread.FilePart[] = [];\n const texts = text ? [text] : [];\n // beginEdit lifts original inline images/files into completed composer\n // attachments. The anchored command must carry those too: a text-only\n // reconstruction silently deleted them when editing a cross-device turn.\n for (const attachment of draft.attachments) {\n if (attachment.status.type !== 'complete')\n throw new Error('Wait for attachments to finish before sending your edit.');\n for (const part of attachment.content ?? []) {\n if (part.type === 'text') texts.push(part.text);\n else if (part.type === 'image')\n files.push({ type: 'file', mediaType: 'image/*', url: part.image });\n else if (part.type === 'file')\n files.push({\n type: 'file',\n mediaType: part.mimeType,\n url: part.data,\n ...(part.filename && { filename: part.filename }),\n });\n else throw new Error('This attachment cannot be edited here.');\n }\n }\n submitting.current = true;\n try {\n const sourceId = aui.message().getState().id;\n const readExtras = () =>\n alive.current ? readDeepAgentStatewireExtras(aui.thread().getState().extras) : null;\n const extras = readExtras();\n if (extras) {\n const preparedMetadata = extras.prepareMessageMetadata?.();\n try {\n const command = await resolveDeepAgentEditCommand({\n readExtras,\n sourceId,\n text,\n });\n if (!alive.current || !composer.getState().isEditing) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n return false;\n }\n // Athena can have gone while older history was paged in: the edit stays a draft (the\n // catch below lets its prepared metadata go).\n refuseWhileUnreachable();\n if (command) {\n void Promise.resolve(\n extras.sendCommand(\n {\n ...command,\n message: {\n ...command.message,\n parts: [\n ...files,\n ...(texts.length\n ? [{ type: 'text' as const, text: texts.join('\\n\\n') }]\n : []),\n ],\n },\n },\n preparedMetadata === undefined ? undefined : { preparedMetadata },\n ),\n ).catch(() => undefined);\n composer.cancel();\n return true;\n }\n if (preparedMetadata && extras.sendPreparedEdit) {\n extras.sendPreparedEdit(sourceId, preparedMetadata);\n return true;\n }\n } catch (error) {\n if (preparedMetadata) extras.discardPreparedMessageMetadata?.(preparedMetadata);\n throw error;\n }\n }\n refuseWhileUnreachable();\n composer.send();\n return true;\n } finally {\n submitting.current = false;\n }\n }, [aui]);\n}\n"],"names":["useHistoricalEditAttachments","useAui","useDeepAgentChatOutboxContext","useRef","useEffect","useCallback","_a","ChatEditUnreachableError","readDeepAgentStatewireExtras","resolveDeepAgentEditCommand"],"mappings":";;;;;;;;AA6BO,SAAS,gCAAwD;AACtEA,4DAAA;AACA,QAAM,MAAMC,MAAAA,OAAA;AACZ,QAAM,SAASC,uBAAAA,8BAAA;AACf,QAAM,YAAYC,WAAAA,OAAO,MAAM;AAC/B,YAAU,UAAU;AACpB,QAAM,QAAQA,WAAAA,OAAO,IAAI;AACzB,QAAM,aAAaA,WAAAA,OAAO,KAAK;AAC/BC,aAAAA,UAAU,MAAM;A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I,SAAS,WAAW,MAAM,IAAI;AACjF,YAAM,SAAS,WAAA;AACf,UAAI,QAAQ;AACV,cAAM,oBAAmB,YAAO,2BAAP;AACzB,YAAI;AACF,gBAAM,UAAU,MAAMC,wCAA4B;AAAA,YAChD;AAAA,YACA;AAAA,YACA;AAAA,UAAA,CACD;AACD,cAAI,CAAC,MAAM,WAAW,CAAC,SAAS,SAAA,EAAW,WAAW;AACpD,gBAAI,iBAAkB,cAAO,mCAAP,gCAAwC;AAC9D,mBAAO;AAAA,UACT;AAGA,iCAAA;AACA,cAAI,SAAS;AACX,iBAAK,QAAQ;AAAA,cACX,OAAO;AAAA,gBACL;AAAA,kBACE,GAAG;AAAA,kBACH,SAAS;AAAA,oBACP,GAAG,QAAQ;AAAA,oBACX,OAAO;AAAA,sBACL,GAAG;AAAA,sBACH,GAAI,MAAM,SACN,CAAC,EAAE,MAAM,QAAiB,MAAM,MAAM,KAAK,MAAM,EAAA,CAAG,IACpD,CAAA;AAAA,oBAAC;AAAA,kBACP;AAAA,gBACF;AAAA,gBAEF,qBAAqB,SAAY,SAAY,EAAE,iBAAA;AAAA,cAAiB;AAAA,YAClE,EACA,MAAM,MAAM,MAAS;AACvB,qBAAS,OAAA;AACT,mBAAO;AAAA,UACT;AACA,cAAI,oBAAoB,OAAO,kBAAkB;AAC/C,mBAAO,iBAAiB,UAAU,gBAAgB;AAClD,mBAAO;AAAA,UACT;AAAA,QACF,SAAS,OAAO;AACd,cAAI,iBAAkB,cAAO,mCAAP,gCAAwC;AAC9D,gBAAM;AAAA,QACR;AAAA,MACF;AACA,6BAAA;AACA,eAAS,KAAA;AACT,aAAO;AAAA,IACT,UAAA;AACE,iBAAW,UAAU;AAAA,IACvB;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AACV;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const require$$0 = require("react");
|
|
4
4
|
const errors = require("./errors.cjs");
|
|
5
5
|
const modelContext = require("./model-context.cjs");
|
|
6
6
|
const quotaSafeLocalStorageSession = require("./quota-safe-local-storage-session.cjs");
|
|
@@ -60,26 +60,26 @@ function useDeepAgentRuntime(options) {
|
|
|
60
60
|
onCommandChange,
|
|
61
61
|
...threadOptions
|
|
62
62
|
} = options;
|
|
63
|
-
const [canPersistLocalSession] =
|
|
64
|
-
const onErrorRef =
|
|
63
|
+
const [canPersistLocalSession] = require$$0.useState(canPersistDeepAgentSession);
|
|
64
|
+
const onErrorRef = require$$0.useRef(onError);
|
|
65
65
|
onErrorRef.current = onError;
|
|
66
|
-
const surfaceRef =
|
|
66
|
+
const surfaceRef = require$$0.useRef(surface);
|
|
67
67
|
surfaceRef.current = surface;
|
|
68
|
-
const onStateChangeRef =
|
|
68
|
+
const onStateChangeRef = require$$0.useRef(onStateChange);
|
|
69
69
|
onStateChangeRef.current = onStateChange;
|
|
70
|
-
const onCommandChangeRef =
|
|
70
|
+
const onCommandChangeRef = require$$0.useRef(onCommandChange);
|
|
71
71
|
onCommandChangeRef.current = onCommandChange;
|
|
72
|
-
const diagnosticsRef =
|
|
72
|
+
const diagnosticsRef = require$$0.useRef(threadOptions.diagnostics);
|
|
73
73
|
diagnosticsRef.current = threadOptions.diagnostics;
|
|
74
|
-
const clientRef =
|
|
75
|
-
const failureStampsRef =
|
|
74
|
+
const clientRef = require$$0.useRef(null);
|
|
75
|
+
const failureStampsRef = require$$0.useRef(
|
|
76
76
|
void 0
|
|
77
77
|
);
|
|
78
78
|
failureStampsRef.current = session === false || session.kind === "pending" ? void 0 : session.kind === "local-storage" ? canPersistLocalSession ? () => quotaSafeLocalStorageSession.readPersistedFailedSendStamps(session.key(threadOptions.threadId)) : void 0 : () => quotaSafeLocalStorageSession.readFailedSendStampsFromRecord(loadSessionRecord(session.store));
|
|
79
79
|
const sessionPending = session !== false && session.kind === "pending";
|
|
80
80
|
const attachKey = sessionPending ? pendingSessionAttachKey(threadOptions.attachKey) : threadOptions.attachKey;
|
|
81
81
|
const laneKey = session !== false && session.kind === "local-storage" ? session.key : null;
|
|
82
|
-
const [laneEpochState, setLaneEpochState] =
|
|
82
|
+
const [laneEpochState, setLaneEpochState] = require$$0.useState(
|
|
83
83
|
() => sessionLaneScope.nextSessionLaneEpoch({
|
|
84
84
|
previous: sessionLaneScope.INITIAL_SESSION_LANE_EPOCH,
|
|
85
85
|
threadId: threadOptions.threadId,
|
|
@@ -94,7 +94,7 @@ function useDeepAgentRuntime(options) {
|
|
|
94
94
|
if (nextLaneEpochState !== laneEpochState) setLaneEpochState(nextLaneEpochState);
|
|
95
95
|
const laneEpoch = nextLaneEpochState.epoch;
|
|
96
96
|
const attachId = useDeepAgentThread.deepAgentAttachId({ threadId: threadOptions.threadId, attachKey, laneEpoch });
|
|
97
|
-
const sendRecovery$1 =
|
|
97
|
+
const sendRecovery$1 = require$$0.useMemo(
|
|
98
98
|
() => sendRecovery.createDeepAgentSendRecovery({
|
|
99
99
|
lane: () => {
|
|
100
100
|
const client2 = clientRef.current;
|
|
@@ -109,8 +109,8 @@ function useDeepAgentRuntime(options) {
|
|
|
109
109
|
}),
|
|
110
110
|
[attachId]
|
|
111
111
|
);
|
|
112
|
-
|
|
113
|
-
const sendRecoveryRef =
|
|
112
|
+
require$$0.useEffect(() => () => sendRecovery$1.dispose(), [sendRecovery$1]);
|
|
113
|
+
const sendRecoveryRef = require$$0.useRef(sendRecovery$1);
|
|
114
114
|
sendRecoveryRef.current = sendRecovery$1;
|
|
115
115
|
const thread = useDeepAgentThread.useDeepAgentThread({
|
|
116
116
|
...threadOptions,
|
|
@@ -158,16 +158,16 @@ function useDeepAgentRuntime(options) {
|
|
|
158
158
|
});
|
|
159
159
|
const client = useClient(thread);
|
|
160
160
|
clientRef.current = client;
|
|
161
|
-
|
|
161
|
+
require$$0.useEffect(() => {
|
|
162
162
|
const unsubscribe = client.subscribe(() => sendRecovery$1.observeFailedLaneChange());
|
|
163
163
|
sendRecovery$1.observeFailedLaneChange();
|
|
164
164
|
return unsubscribe;
|
|
165
165
|
}, [client, sendRecovery$1]);
|
|
166
|
-
const getRunConfigRef =
|
|
166
|
+
const getRunConfigRef = require$$0.useRef(runConfig == null ? void 0 : runConfig.get);
|
|
167
167
|
getRunConfigRef.current = runConfig == null ? void 0 : runConfig.get;
|
|
168
168
|
const hasRunConfig = runConfig !== void 0;
|
|
169
169
|
const runConfigKey = runConfig == null ? void 0 : runConfig.key;
|
|
170
|
-
|
|
170
|
+
require$$0.useEffect(() => {
|
|
171
171
|
if (!hasRunConfig) return void 0;
|
|
172
172
|
return modelContext.registerDeepAgentRunConfig(client, () => {
|
|
173
173
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-deep-agent-runtime.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-runtime.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport { isStatewireChannelTeardown } from './errors';\nimport { type DeepAgentModelContextHost, registerDeepAgentRunConfig } from './model-context';\nimport {\n isStorageQuotaError,\n QuotaSafeLocalStorageSession,\n readFailedSendStampsFromRecord,\n readPersistedFailedSendStamps,\n type SessionStorageDegradation,\n} from './quota-safe-local-storage-session';\nimport { createDeepAgentSendRecovery } from './send-recovery';\nimport { INITIAL_SESSION_LANE_EPOCH, nextSessionLaneEpoch } from './session-lane-scope';\nimport type { StatewireTransportOptions } from './statewire-transport';\nimport { readStatewireFailedSendLane } from './thread-extras';\nimport { isConfigSyncUnavailableRejection } from './use-deep-agent-config';\nimport {\n deepAgentAttachId,\n useDeepAgentThread,\n type UseDeepAgentThreadOptions,\n} from './use-deep-agent-thread';\n\n/** The thread element `useDeepAgentThread` produces — what the host's `useAui`\n * consumes (`useAui({ thread })`). */\nexport type DeepAgentThreadElement = ReturnType<typeof useDeepAgentThread>;\n\n/**\n * Durable command-lane persistence for the thread — where the lane identity and\n * the commands still awaiting a durable verdict live, so a reload resumes the\n * lane instead of minting a new client.\n *\n * - `local-storage`: browser hosts. Backed by {@link QuotaSafeLocalStorageSession}\n * (the upstream `LocalStorageSession` contract with Athena keys, legacy\n * metadata, and retention). A storage failure after mounting — the origin\n * out of quota after statewire's own sweep, a lockdown-mode write refusal —\n * degrades the session to memory-only persistence and is reported through\n * `onStorageDegraded` (default: one console warning); it never stops the\n * connection. Guarded by a shared availability probe: SSR, storage-blocked\n * iframes, and locked-down browsers keep the session process-local, exactly\n * as before the seam existed, while an origin that is merely full mounts the\n * session and lets it degrade. `key` scopes the stored lane — a thread id is\n * only meaningful against the backend (and, where relevant, principal) that\n * minted it, so include the sync-host URL.\n * - `session-store`: React Native hosts pass a hydrated library store backed\n * by AsyncStorage. Its synchronous `load()` is\n * also the send-recovery freshness gate's view of the persisted failed lane,\n * so a store that persists `failed` gets the same 24 h staleness rule as the\n * browser hosts.\n * - `pending`: the principal the lane is scoped by is not known yet (the\n * host's signed-in user is still loading). See {@link DeepAgentPendingSession}.\n * - `false`: process-local session (a reload mints a new client).\n *\n * A `local-storage` `key` names one principal's lanes (and one backend's). The\n * statewire session that mounts on a lane keeps the client id, lane clocks and\n * journal it loaded there, and everything in that journal is sent under\n * whatever credential the transport holds at its next attach. So a mounted\n * session never moves to another key: when the key starts naming another\n * principal's lanes for the same thread (another account signed in under a\n * mounted chat), the runtime starts a new lane epoch\n * (`UseDeepAgentThreadOptions['laneEpoch']`). The whole statewire thread\n * remounts on the new principal's lane and attaches afresh, as that lane's own\n * client, with nothing remembered or pooled from before. The previous\n * principal's record stays where it is, with its client id and whatever it had\n * journaled and not yet delivered: that principal's next mount on this browser\n * resends it as them, and the retention sweep retires it otherwise. It is never\n * sent as anyone else. A key for the same principal (a token refresh, a fresh\n * `key` function) and a thread switch keep the lane as it is. A host whose\n * principal arrives after mount passes `pending` until it does, never a\n * stand-in key: moving off a stand-in would be a principal change, a second\n * attach.\n */\nexport type DeepAgentSessionPersistence =\n | {\n kind: 'local-storage';\n key: (threadId: string) => string;\n onStorageDegraded?: (degradation: SessionStorageDegradation) => void;\n }\n | { kind: 'session-store'; store: NonNullable<StatewireTransportOptions['sessionStore']> }\n | DeepAgentPendingSession\n | false;\n\n/**\n * The durable lane's principal is not known yet. A lane belongs to one\n * principal and a mounted session cannot move to another lane (see\n * {@link DeepAgentSessionPersistence}), so nothing is mounted, nothing is\n * journaled and the transport stays parked — no dial — until the host passes\n * the real persistence. The park is an attach identity of its own: the attach\n * that follows makes every per-attach decision afresh (the remembered-snapshot\n * seed, the pooled hello, which the park leaves in the pool) and dials the real\n * lane once, as the thread's first attach. The park carries no connection\n * message, so it reads like a never-started chat rather than a paused one; a\n * host suspension, when one applies, wins.\n */\nexport type DeepAgentPendingSession = { kind: 'pending' };\n\n/**\n * The attach key a pending-lane park runs under. It differs from every key the\n * host passes, so the real attach after it is a new attach identity.\n */\nexport function pendingSessionAttachKey(attachKey: string | number | undefined): string {\n return `session-pending:${attachKey ?? ''}`;\n}\n\n/** Structural view of the browser storage global — this package compiles\n * without the DOM lib (React Native honesty; see `globals.d.ts`). */\ntype StorageGlobals = {\n localStorage?: {\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n };\n navigator?: { locks?: unknown };\n};\n\n/**\n * Whether a localStorage-backed session can persist here. A write probe, not a\n * `typeof` check: storage-blocked iframes (SDK embeds under third-party-storage\n * blocking) throw from the `localStorage` accessor itself, and lockdown-mode\n * origins throw from `setItem` — each of those must mean \"stay process-local\",\n * never a crash at mount. An origin that is merely out of quota still reads\n * and takes locks, so it mounts the session: {@link QuotaSafeLocalStorageSession}\n * degrades that to memory-only persistence and recovers when room frees,\n * where staying process-local would give up cross-tab sharing for the whole\n * page load over a condition that clears.\n *\n * The Web Locks API is probed too: the session storage serializes the shared\n * record across tabs through `navigator.locks` and refuses to mount without it\n * (the same precondition as the vendor `LocalStorageSession`), so an origin\n * with localStorage but no Web Locks — older WebViews, Safari before 15.4 —\n * must also stay process-local instead of throwing at mount.\n */\nexport function canPersistDeepAgentSession(): boolean {\n try {\n const globals = globalThis as StorageGlobals;\n if (!globals.navigator?.locks) return false;\n const storage = globals.localStorage;\n if (!storage) return false;\n const probeKey = '__athena_statewire_session_probe__';\n try {\n storage.setItem(probeKey, probeKey);\n storage.removeItem(probeKey);\n } catch (error) {\n return isStorageQuotaError(error);\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** A host session store's current record, or `null` when the read throws —\n * the recovery gate must never take the runtime down over a storage fault. */\nfunction loadSessionRecord(\n store: NonNullable<StatewireTransportOptions['sessionStore']>\n): ReturnType<NonNullable<StatewireTransportOptions['sessionStore']>['load']> | null {\n try {\n return store.load();\n } catch {\n return null;\n }\n}\n\n/**\n * The shared tail of every surface's transport error policy: channel teardown\n * is lifecycle noise (logged at debug), as is `config_sync_unavailable` — only\n * `config/*` writes emit it, and the host's config sync already handles it\n * through its own command promise (regionally-pinned workspaces run on\n * local-only config); everything else is a real transport error. Hosts with their own error chain\n * (paywall, telemetry, send-failure stores) end it with this so the fallback\n * logging stays uniform per surface.\n */\nexport function logUnhandledStatewireError(surface: string, error: Error): void {\n if (isStatewireChannelTeardown(error)) {\n console.debug(`[${surface}] statewire channel teardown:`, error);\n return;\n }\n if (isConfigSyncUnavailableRejection(error)) {\n console.debug(`[${surface}] config sync unavailable (handled by config sync):`, error);\n return;\n }\n console.error(`[${surface}] statewire transport error:`, error);\n}\n\n/**\n * The imperative thread-state slice of an assistant-ui client — structural so\n * web and native `useAui` results both satisfy it. The send-recovery layer\n * reads the statewire thread extras through it (the sanctioned imperative\n * pattern: `aui.thread().getState()` inside callbacks/effects, never render).\n */\nexport interface DeepAgentThreadStateClientHost {\n thread: () => { getState: () => { extras?: unknown } };\n subscribe: (listener: () => void) => () => void;\n}\n\n/** Deep-agent runConfig registration on the ambient model context (see\n * {@link registerDeepAgentRunConfig}). */\nexport interface DeepAgentRunConfigRegistration {\n /**\n * Builds the `runConfig` that drives the run. The core pulls it when the\n * model context notifies (mount and each key change); the server reads that\n * synced value at command admission. The per-render ref makes each pull use\n * the latest closure but does not trigger a pull itself.\n */\n get: () => Record<string, unknown>;\n /**\n * Re-registers the provider and notifies model-context sync when this value\n * changes (reference equality). Include getter inputs that can change while\n * mounted; they reach the server only after a key change triggers a pull.\n */\n key?: unknown;\n}\n\nexport interface UseDeepAgentRuntimeOptions<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n> extends Omit<UseDeepAgentThreadOptions, 'storage' | 'sessionStore' | 'laneEpoch'> {\n /** Host surface tag for the shared fallback error logging (e.g.\n * `'AthenaDeepAgent'`, `'AthenaSDK'`, `'ChromeStatewire'`). */\n surface: string;\n /** Durable command-lane persistence; defaults to process-local. */\n session?: DeepAgentSessionPersistence;\n /**\n * Builds the host's assistant-ui client from the thread element — pass the\n * platform `useAui` (web hosts from `@assistant-ui/react`, React Native\n * hosts from `@assistant-ui/react-native`; this package imports neither).\n * Called unconditionally on every render, so it MUST be (or call) a hook\n * following the rules of hooks — define it at module scope with a `use*`\n * name: `const useHostClient = (thread: DeepAgentThreadElement) =>\n * useAui({ thread })`.\n */\n useClient: (thread: DeepAgentThreadElement) => TClient;\n /** Registers the deep-agent runConfig on the client's model context. Hosts\n * that register elsewhere (e.g. a bridge component mounted under the\n * provider) omit it. */\n runConfig?: DeepAgentRunConfigRegistration;\n}\n\n/**\n * The configurable deep-agent statewire runtime — the one hook every Athena\n * chat surface (Olympus, `@athenaintel/react` SDK, Chrome extension, Office\n * add-in, mobile) mounts its assistant-ui client through.\n *\n * Composes the pieces every surface previously wired by hand:\n * `useDeepAgentThread` (attach lifecycle, auth parking, lane projection,\n * connection/running observers), durable session persistence with the shared\n * availability guard, transport-level send recovery (failed sends the server\n * never judged auto-retry under their original message id — `send-recovery.ts`),\n * the platform client via `useClient`, and the\n * runConfig model-context registration on provider notifications. Everything\n * host-specific — auth headers, run-config building, error policy, adapters,\n * diagnostics recorders — stays an option, so per-surface behavior is\n * configuration, not a fork.\n */\nexport function useDeepAgentRuntime<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n>(options: UseDeepAgentRuntimeOptions<TClient>): TClient {\n const {\n surface,\n session = false,\n useClient,\n runConfig,\n onError,\n onStateChange,\n onCommandChange,\n ...threadOptions\n } = options;\n\n // Probed once per mount, like every browser host did individually: an origin\n // that cannot persist stays process-local for the mount's lifetime.\n const [canPersistLocalSession] = useState(canPersistDeepAgentSession);\n\n // Per-render refs so the transport never remounts on a new closure identity\n // and always reads the latest policy.\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n const surfaceRef = useRef(surface);\n surfaceRef.current = surface;\n const onStateChangeRef = useRef(onStateChange);\n onStateChangeRef.current = onStateChange;\n const onCommandChangeRef = useRef(onCommandChange);\n onCommandChangeRef.current = onCommandChange;\n const diagnosticsRef = useRef(threadOptions.diagnostics);\n diagnosticsRef.current = threadOptions.diagnostics;\n const clientRef = useRef<TClient | null>(null);\n\n // Where the persisted session record lives, for the recovery freshness gate\n // (read per sweep — undefined means \"no persistence, everything is fresh\").\n const failureStampsRef = useRef<(() => ReadonlyMap<string, number> | null) | undefined>(\n undefined\n );\n failureStampsRef.current =\n session === false || session.kind === 'pending'\n ? undefined\n : session.kind === 'local-storage'\n ? canPersistLocalSession\n ? () => readPersistedFailedSendStamps(session.key(threadOptions.threadId))\n : undefined\n : () => readFailedSendStampsFromRecord(loadSessionRecord(session.store));\n\n // A pending lane parks the thread under an attach identity of its own (see\n // `DeepAgentPendingSession`), so the attach once the lane is known is new.\n const sessionPending = session !== false && session.kind === 'pending';\n const attachKey = sessionPending\n ? pendingSessionAttachKey(threadOptions.attachKey)\n : threadOptions.attachKey;\n\n // The lane's scope, as the host's `key` names it: whose lanes this mount\n // runs on. A key that starts naming another principal's lanes starts a new\n // lane epoch, which remounts the whole thread on the new lane instead of\n // moving the mounted session there (see `DeepAgentSessionPersistence`).\n // Tracked whether or not this origin can persist: a process-local session\n // holds the previous principal's journal in memory just the same. A pending\n // lane keeps the last known scope, so a sign-out and a sign-in as someone\n // else with a gap between them is still a change.\n const laneKey = session !== false && session.kind === 'local-storage' ? session.key : null;\n const [laneEpochState, setLaneEpochState] = useState(() =>\n nextSessionLaneEpoch({\n previous: INITIAL_SESSION_LANE_EPOCH,\n threadId: threadOptions.threadId,\n key: laneKey,\n })\n );\n const nextLaneEpochState = nextSessionLaneEpoch({\n previous: laneEpochState,\n threadId: threadOptions.threadId,\n key: laneKey,\n });\n // React's derived-state update: re-renders at once with the new epoch, and\n // this render already uses it, so no render pairs the new key with the\n // mounted thread.\n if (nextLaneEpochState !== laneEpochState) setLaneEpochState(nextLaneEpochState);\n const laneEpoch = nextLaneEpochState.epoch;\n\n // Send recovery, keyed by attach identity exactly like the thread's session\n // (a switch, re-attach or new lane epoch gets fresh hydration gating and\n // retry budgets, so it never re-dispatches a previous principal's failed\n // sends). The controller re-dispatches failed sends the server never judged;\n // see `send-recovery.ts` for the contract.\n const attachId = deepAgentAttachId({ threadId: threadOptions.threadId, attachKey, laneEpoch });\n // biome-ignore lint/correctness/useExhaustiveDependencies: keyed by attach identity on purpose; every other input is read through a per-render ref.\n const sendRecovery = useMemo(\n () =>\n createDeepAgentSendRecovery({\n lane: () => {\n const client = clientRef.current;\n if (!client) return null;\n return readStatewireFailedSendLane(client.thread().getState().extras);\n },\n failureStamps: () => failureStampsRef.current?.() ?? null,\n diagnostics: () => diagnosticsRef.current,\n }),\n [attachId]\n );\n useEffect(() => () => sendRecovery.dispose(), [sendRecovery]);\n const sendRecoveryRef = useRef(sendRecovery);\n sendRecoveryRef.current = sendRecovery;\n\n const thread = useDeepAgentThread({\n ...threadOptions,\n ...(attachKey !== undefined && { attachKey }),\n laneEpoch,\n // Parked without a message (a host suspension, when one applies, wins):\n // nothing dials and nothing journals until the lane is known. What paints\n // the first frame is the real attach's to report, not the park's.\n ...(sessionPending && {\n suspended: threadOptions.suspended || {},\n onAttachSource: undefined,\n }),\n // A pooled dial for the thread is the real attach's to take: a park that\n // only waits for the lane neither takes nor discards it. A host suspension\n // still discards it, as it does without a pending lane.\n ...(sessionPending && !threadOptions.suspended && { prewarmPool: undefined }),\n ...(session !== false &&\n session.kind === 'local-storage' &&\n canPersistLocalSession && {\n storage: {\n session: QuotaSafeLocalStorageSession({\n threadId: threadOptions.threadId,\n key: session.key,\n ...(session.onStorageDegraded === undefined\n ? {}\n : { onStorageDegraded: session.onStorageDegraded }),\n }),\n },\n }),\n ...(session !== false && session.kind === 'session-store' && { sessionStore: session.store }),\n onStateChange: (state, ctx) => {\n sendRecoveryRef.current.observeStateChange(state);\n onStateChangeRef.current?.(state, ctx);\n },\n onCommandChange: (update, ctx) => {\n sendRecoveryRef.current.observeCommand(update);\n onCommandChangeRef.current?.(update, ctx);\n },\n onError: (error) => {\n const handler = onErrorRef.current;\n if (handler) {\n handler(error);\n return;\n }\n logUnhandledStatewireError(surfaceRef.current, error);\n },\n });\n\n const client = useClient(thread);\n clientRef.current = client;\n\n // A locked shared journal can publish failed history after onCommandChange,\n // with no canonical state change to wake recovery. Observe the client that\n // owns the visible failed lane; the controller guards in-flight retries.\n useEffect(() => {\n const unsubscribe = client.subscribe(() => sendRecovery.observeFailedLaneChange());\n sendRecovery.observeFailedLaneChange();\n return unsubscribe;\n }, [client, sendRecovery]);\n\n // Commands travel bare, so the runConfig that drives the run rides the\n // ambient model context: `contextSync: 'command-send'` mirrors it to the\n // server, which reads `config.runConfig` at command admission. The core pulls\n // on model-context notifications; the per-render ref ensures each pull uses\n // the latest closure but does not trigger a pull itself.\n const getRunConfigRef = useRef(runConfig?.get);\n getRunConfigRef.current = runConfig?.get;\n const hasRunConfig = runConfig !== undefined;\n const runConfigKey = runConfig?.key;\n useEffect(() => {\n if (!hasRunConfig) return undefined;\n return registerDeepAgentRunConfig(client, () => getRunConfigRef.current?.() ?? {});\n }, [client, hasRunConfig, runConfigKey]);\n\n return client;\n}\n\n"],"names":["isStorageQuotaError","isStatewireChannelTeardown","isConfigSyncUnavailableRejection","useState","useRef","readPersistedFailedSendStamps","readFailedSendStampsFromRecord","nextSessionLaneEpoch","INITIAL_SESSION_LANE_EPOCH","deepAgentAttachId","sendRecovery","useMemo","createDeepAgentSendRecovery","client","readStatewireFailedSendLane","useEffect","useDeepAgentThread","QuotaSafeLocalStorageSession","registerDeepAgentRunConfig"],"mappings":";;;;;;;;;;;AAkGO,SAAS,wBAAwB,WAAgD;AACtF,SAAO,mBAAmB,aAAa,EAAE;AAC3C;AA6BO,SAAS,6BAAsC;;AACpD,MAAI;AACF,UAAM,UAAU;AAChB,QAAI,GAAC,aAAQ,cAAR,mBAAmB,OAAO,QAAO;AACtC,UAAM,UAAU,QAAQ;AACxB,QAAI,CAAC,QAAS,QAAO;AACrB,UAAM,WAAW;AACjB,QAAI;AACF,cAAQ,QAAQ,UAAU,QAAQ;AAClC,cAAQ,WAAW,QAAQ;AAAA,IAC7B,SAAS,OAAO;AACd,aAAOA,6BAAAA,oBAAoB,KAAK;AAAA,IAClC;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAIA,SAAS,kBACP,OACmF;AACnF,MAAI;AACF,WAAO,MAAM,KAAA;AAAA,EACf,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAWO,SAAS,2BAA2B,SAAiB,OAAoB;AAC9E,MAAIC,OAAAA,2BAA2B,KAAK,GAAG;AACrC,YAAQ,MAAM,IAAI,OAAO,iCAAiC,KAAK;AAC/D;AAAA,EACF;AACA,MAAIC,mBAAAA,iCAAiC,KAAK,GAAG;AAC3C,YAAQ,MAAM,IAAI,OAAO,uDAAuD,KAAK;AACrF;AAAA,EACF;AACA,UAAQ,MAAM,IAAI,OAAO,gCAAgC,KAAK;AAChE;AAuEO,SAAS,oBAEd,SAAuD;AACvD,QAAM;AAAA,IACJ;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAIJ,QAAM,CAAC,sBAAsB,IAAIC,MAAAA,SAAS,0BAA0B;AAIpE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AAAA,IACpC;AAAA,IACA,iBAAiB,CAAC,QAAQ,QAAQ;;AAChC,sBAAgB,QAAQ,eAAe,MAAM;AAC7C,+BAAmB,YAAnB,4CAA6B,QAAQ;AAAA,IACvC;AAAA,IACA,SAAS,CAAC,UAAU;AAClB,YAAM,UAAU,WAAW;AAC3B,UAAI,SAAS;AACX,gBAAQ,KAAK;AACb;AAAA,MACF;AACA,iCAA2B,WAAW,SAAS,KAAK;AAAA,IACtD;AAAA,EAAA,CACD;AAED,QAAM,SAAS,UAAU,MAAM;AAC/B,YAAU,UAAU;AAKpBF,QAAAA,UAAU,MAAM;AACd,UAAM,cAAc,OAAO,UAAU,MAAML,eAAa,yBAAyB;AACjFA,mBAAa,wBAAA;AACb,WAAO;AAAA,EACT,GAAG,CAAC,QAAQA,cAAY,CAAC;AAOzB,QAAM,kBAAkBN,MAAAA,OAAO,uCAAW,GAAG;AAC7C,kBAAgB,UAAU,uCAAW;AACrC,QAAM,eAAe,cAAc;AACnC,QAAM,eAAe,uCAAW;AAChCW,QAAAA,UAAU,MAAM;AACd,QAAI,CAAC,aAAc,QAAO;AAC1B,WAAOG,aAAAA,2BAA2B,QAAQ,MAAA;;AAAM,oCAAgB,YAAhB,6CAA+B,CAAA;AAAA,KAAE;AAAA,EACnF,GAAG,CAAC,QAAQ,cAAc,YAAY,CAAC;AAEvC,SAAO;AACT;;;;;"}
|
|
1
|
+
{"version":3,"file":"use-deep-agent-runtime.cjs","sources":["../../../../agent-runtime/src/use-deep-agent-runtime.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport { isStatewireChannelTeardown } from './errors';\nimport { type DeepAgentModelContextHost, registerDeepAgentRunConfig } from './model-context';\nimport {\n isStorageQuotaError,\n QuotaSafeLocalStorageSession,\n readFailedSendStampsFromRecord,\n readPersistedFailedSendStamps,\n type SessionStorageDegradation,\n} from './quota-safe-local-storage-session';\nimport { createDeepAgentSendRecovery } from './send-recovery';\nimport { INITIAL_SESSION_LANE_EPOCH, nextSessionLaneEpoch } from './session-lane-scope';\nimport type { StatewireTransportOptions } from './statewire-transport';\nimport { readStatewireFailedSendLane } from './thread-extras';\nimport { isConfigSyncUnavailableRejection } from './use-deep-agent-config';\nimport {\n deepAgentAttachId,\n useDeepAgentThread,\n type UseDeepAgentThreadOptions,\n} from './use-deep-agent-thread';\n\n/** The thread element `useDeepAgentThread` produces — what the host's `useAui`\n * consumes (`useAui({ thread })`). */\nexport type DeepAgentThreadElement = ReturnType<typeof useDeepAgentThread>;\n\n/**\n * Durable command-lane persistence for the thread — where the lane identity and\n * the commands still awaiting a durable verdict live, so a reload resumes the\n * lane instead of minting a new client.\n *\n * - `local-storage`: browser hosts. Backed by {@link QuotaSafeLocalStorageSession}\n * (the upstream `LocalStorageSession` contract with Athena keys, legacy\n * metadata, and retention). A storage failure after mounting — the origin\n * out of quota after statewire's own sweep, a lockdown-mode write refusal —\n * degrades the session to memory-only persistence and is reported through\n * `onStorageDegraded` (default: one console warning); it never stops the\n * connection. Guarded by a shared availability probe: SSR, storage-blocked\n * iframes, and locked-down browsers keep the session process-local, exactly\n * as before the seam existed, while an origin that is merely full mounts the\n * session and lets it degrade. `key` scopes the stored lane — a thread id is\n * only meaningful against the backend (and, where relevant, principal) that\n * minted it, so include the sync-host URL.\n * - `session-store`: React Native hosts pass a hydrated library store backed\n * by AsyncStorage. Its synchronous `load()` is\n * also the send-recovery freshness gate's view of the persisted failed lane,\n * so a store that persists `failed` gets the same 24 h staleness rule as the\n * browser hosts.\n * - `pending`: the principal the lane is scoped by is not known yet (the\n * host's signed-in user is still loading). See {@link DeepAgentPendingSession}.\n * - `false`: process-local session (a reload mints a new client).\n *\n * A `local-storage` `key` names one principal's lanes (and one backend's). The\n * statewire session that mounts on a lane keeps the client id, lane clocks and\n * journal it loaded there, and everything in that journal is sent under\n * whatever credential the transport holds at its next attach. So a mounted\n * session never moves to another key: when the key starts naming another\n * principal's lanes for the same thread (another account signed in under a\n * mounted chat), the runtime starts a new lane epoch\n * (`UseDeepAgentThreadOptions['laneEpoch']`). The whole statewire thread\n * remounts on the new principal's lane and attaches afresh, as that lane's own\n * client, with nothing remembered or pooled from before. The previous\n * principal's record stays where it is, with its client id and whatever it had\n * journaled and not yet delivered: that principal's next mount on this browser\n * resends it as them, and the retention sweep retires it otherwise. It is never\n * sent as anyone else. A key for the same principal (a token refresh, a fresh\n * `key` function) and a thread switch keep the lane as it is. A host whose\n * principal arrives after mount passes `pending` until it does, never a\n * stand-in key: moving off a stand-in would be a principal change, a second\n * attach.\n */\nexport type DeepAgentSessionPersistence =\n | {\n kind: 'local-storage';\n key: (threadId: string) => string;\n onStorageDegraded?: (degradation: SessionStorageDegradation) => void;\n }\n | { kind: 'session-store'; store: NonNullable<StatewireTransportOptions['sessionStore']> }\n | DeepAgentPendingSession\n | false;\n\n/**\n * The durable lane's principal is not known yet. A lane belongs to one\n * principal and a mounted session cannot move to another lane (see\n * {@link DeepAgentSessionPersistence}), so nothing is mounted, nothing is\n * journaled and the transport stays parked — no dial — until the host passes\n * the real persistence. The park is an attach identity of its own: the attach\n * that follows makes every per-attach decision afresh (the remembered-snapshot\n * seed, the pooled hello, which the park leaves in the pool) and dials the real\n * lane once, as the thread's first attach. The park carries no connection\n * message, so it reads like a never-started chat rather than a paused one; a\n * host suspension, when one applies, wins.\n */\nexport type DeepAgentPendingSession = { kind: 'pending' };\n\n/**\n * The attach key a pending-lane park runs under. It differs from every key the\n * host passes, so the real attach after it is a new attach identity.\n */\nexport function pendingSessionAttachKey(attachKey: string | number | undefined): string {\n return `session-pending:${attachKey ?? ''}`;\n}\n\n/** Structural view of the browser storage global — this package compiles\n * without the DOM lib (React Native honesty; see `globals.d.ts`). */\ntype StorageGlobals = {\n localStorage?: {\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n };\n navigator?: { locks?: unknown };\n};\n\n/**\n * Whether a localStorage-backed session can persist here. A write probe, not a\n * `typeof` check: storage-blocked iframes (SDK embeds under third-party-storage\n * blocking) throw from the `localStorage` accessor itself, and lockdown-mode\n * origins throw from `setItem` — each of those must mean \"stay process-local\",\n * never a crash at mount. An origin that is merely out of quota still reads\n * and takes locks, so it mounts the session: {@link QuotaSafeLocalStorageSession}\n * degrades that to memory-only persistence and recovers when room frees,\n * where staying process-local would give up cross-tab sharing for the whole\n * page load over a condition that clears.\n *\n * The Web Locks API is probed too: the session storage serializes the shared\n * record across tabs through `navigator.locks` and refuses to mount without it\n * (the same precondition as the vendor `LocalStorageSession`), so an origin\n * with localStorage but no Web Locks — older WebViews, Safari before 15.4 —\n * must also stay process-local instead of throwing at mount.\n */\nexport function canPersistDeepAgentSession(): boolean {\n try {\n const globals = globalThis as StorageGlobals;\n if (!globals.navigator?.locks) return false;\n const storage = globals.localStorage;\n if (!storage) return false;\n const probeKey = '__athena_statewire_session_probe__';\n try {\n storage.setItem(probeKey, probeKey);\n storage.removeItem(probeKey);\n } catch (error) {\n return isStorageQuotaError(error);\n }\n return true;\n } catch {\n return false;\n }\n}\n\n/** A host session store's current record, or `null` when the read throws —\n * the recovery gate must never take the runtime down over a storage fault. */\nfunction loadSessionRecord(\n store: NonNullable<StatewireTransportOptions['sessionStore']>\n): ReturnType<NonNullable<StatewireTransportOptions['sessionStore']>['load']> | null {\n try {\n return store.load();\n } catch {\n return null;\n }\n}\n\n/**\n * The shared tail of every surface's transport error policy: channel teardown\n * is lifecycle noise (logged at debug), as is `config_sync_unavailable` — only\n * `config/*` writes emit it, and the host's config sync already handles it\n * through its own command promise (regionally-pinned workspaces run on\n * local-only config); everything else is a real transport error. Hosts with their own error chain\n * (paywall, telemetry, send-failure stores) end it with this so the fallback\n * logging stays uniform per surface.\n */\nexport function logUnhandledStatewireError(surface: string, error: Error): void {\n if (isStatewireChannelTeardown(error)) {\n console.debug(`[${surface}] statewire channel teardown:`, error);\n return;\n }\n if (isConfigSyncUnavailableRejection(error)) {\n console.debug(`[${surface}] config sync unavailable (handled by config sync):`, error);\n return;\n }\n console.error(`[${surface}] statewire transport error:`, error);\n}\n\n/**\n * The imperative thread-state slice of an assistant-ui client — structural so\n * web and native `useAui` results both satisfy it. The send-recovery layer\n * reads the statewire thread extras through it (the sanctioned imperative\n * pattern: `aui.thread().getState()` inside callbacks/effects, never render).\n */\nexport interface DeepAgentThreadStateClientHost {\n thread: () => { getState: () => { extras?: unknown } };\n subscribe: (listener: () => void) => () => void;\n}\n\n/** Deep-agent runConfig registration on the ambient model context (see\n * {@link registerDeepAgentRunConfig}). */\nexport interface DeepAgentRunConfigRegistration {\n /**\n * Builds the `runConfig` that drives the run. The core pulls it when the\n * model context notifies (mount and each key change); the server reads that\n * synced value at command admission. The per-render ref makes each pull use\n * the latest closure but does not trigger a pull itself.\n */\n get: () => Record<string, unknown>;\n /**\n * Re-registers the provider and notifies model-context sync when this value\n * changes (reference equality). Include getter inputs that can change while\n * mounted; they reach the server only after a key change triggers a pull.\n */\n key?: unknown;\n}\n\nexport interface UseDeepAgentRuntimeOptions<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n> extends Omit<UseDeepAgentThreadOptions, 'storage' | 'sessionStore' | 'laneEpoch'> {\n /** Host surface tag for the shared fallback error logging (e.g.\n * `'AthenaDeepAgent'`, `'AthenaSDK'`, `'ChromeStatewire'`). */\n surface: string;\n /** Durable command-lane persistence; defaults to process-local. */\n session?: DeepAgentSessionPersistence;\n /**\n * Builds the host's assistant-ui client from the thread element — pass the\n * platform `useAui` (web hosts from `@assistant-ui/react`, React Native\n * hosts from `@assistant-ui/react-native`; this package imports neither).\n * Called unconditionally on every render, so it MUST be (or call) a hook\n * following the rules of hooks — define it at module scope with a `use*`\n * name: `const useHostClient = (thread: DeepAgentThreadElement) =>\n * useAui({ thread })`.\n */\n useClient: (thread: DeepAgentThreadElement) => TClient;\n /** Registers the deep-agent runConfig on the client's model context. Hosts\n * that register elsewhere (e.g. a bridge component mounted under the\n * provider) omit it. */\n runConfig?: DeepAgentRunConfigRegistration;\n}\n\n/**\n * The configurable deep-agent statewire runtime — the one hook every Athena\n * chat surface (Olympus, `@athenaintel/react` SDK, Chrome extension, Office\n * add-in, mobile) mounts its assistant-ui client through.\n *\n * Composes the pieces every surface previously wired by hand:\n * `useDeepAgentThread` (attach lifecycle, auth parking, lane projection,\n * connection/running observers), durable session persistence with the shared\n * availability guard, transport-level send recovery (failed sends the server\n * never judged auto-retry under their original message id — `send-recovery.ts`),\n * the platform client via `useClient`, and the\n * runConfig model-context registration on provider notifications. Everything\n * host-specific — auth headers, run-config building, error policy, adapters,\n * diagnostics recorders — stays an option, so per-surface behavior is\n * configuration, not a fork.\n */\nexport function useDeepAgentRuntime<\n TClient extends DeepAgentModelContextHost & DeepAgentThreadStateClientHost,\n>(options: UseDeepAgentRuntimeOptions<TClient>): TClient {\n const {\n surface,\n session = false,\n useClient,\n runConfig,\n onError,\n onStateChange,\n onCommandChange,\n ...threadOptions\n } = options;\n\n // Probed once per mount, like every browser host did individually: an origin\n // that cannot persist stays process-local for the mount's lifetime.\n const [canPersistLocalSession] = useState(canPersistDeepAgentSession);\n\n // Per-render refs so the transport never remounts on a new closure identity\n // and always reads the latest policy.\n const onErrorRef = useRef(onError);\n onErrorRef.current = onError;\n const surfaceRef = useRef(surface);\n surfaceRef.current = surface;\n const onStateChangeRef = useRef(onStateChange);\n onStateChangeRef.current = onStateChange;\n const onCommandChangeRef = useRef(onCommandChange);\n onCommandChangeRef.current = onCommandChange;\n const diagnosticsRef = useRef(threadOptions.diagnostics);\n diagnosticsRef.current = threadOptions.diagnostics;\n const clientRef = useRef<TClient | null>(null);\n\n // Where the persisted session record lives, for the recovery freshness gate\n // (read per sweep — undefined means \"no persistence, everything is fresh\").\n const failureStampsRef = useRef<(() => ReadonlyMap<string, number> | null) | undefined>(\n undefined\n );\n failureStampsRef.current =\n session === false || session.kind === 'pending'\n ? undefined\n : session.kind === 'local-storage'\n ? canPersistLocalSession\n ? () => readPersistedFailedSendStamps(session.key(threadOptions.threadId))\n : undefined\n : () => readFailedSendStampsFromRecord(loadSessionRecord(session.store));\n\n // A pending lane parks the thread under an attach identity of its own (see\n // `DeepAgentPendingSession`), so the attach once the lane is known is new.\n const sessionPending = session !== false && session.kind === 'pending';\n const attachKey = sessionPending\n ? pendingSessionAttachKey(threadOptions.attachKey)\n : threadOptions.attachKey;\n\n // The lane's scope, as the host's `key` names it: whose lanes this mount\n // runs on. A key that starts naming another principal's lanes starts a new\n // lane epoch, which remounts the whole thread on the new lane instead of\n // moving the mounted session there (see `DeepAgentSessionPersistence`).\n // Tracked whether or not this origin can persist: a process-local session\n // holds the previous principal's journal in memory just the same. A pending\n // lane keeps the last known scope, so a sign-out and a sign-in as someone\n // else with a gap between them is still a change.\n const laneKey = session !== false && session.kind === 'local-storage' ? session.key : null;\n const [laneEpochState, setLaneEpochState] = useState(() =>\n nextSessionLaneEpoch({\n previous: INITIAL_SESSION_LANE_EPOCH,\n threadId: threadOptions.threadId,\n key: laneKey,\n })\n );\n const nextLaneEpochState = nextSessionLaneEpoch({\n previous: laneEpochState,\n threadId: threadOptions.threadId,\n key: laneKey,\n });\n // React's derived-state update: re-renders at once with the new epoch, and\n // this render already uses it, so no render pairs the new key with the\n // mounted thread.\n if (nextLaneEpochState !== laneEpochState) setLaneEpochState(nextLaneEpochState);\n const laneEpoch = nextLaneEpochState.epoch;\n\n // Send recovery, keyed by attach identity exactly like the thread's session\n // (a switch, re-attach or new lane epoch gets fresh hydration gating and\n // retry budgets, so it never re-dispatches a previous principal's failed\n // sends). The controller re-dispatches failed sends the server never judged;\n // see `send-recovery.ts` for the contract.\n const attachId = deepAgentAttachId({ threadId: threadOptions.threadId, attachKey, laneEpoch });\n // biome-ignore lint/correctness/useExhaustiveDependencies: keyed by attach identity on purpose; every other input is read through a per-render ref.\n const sendRecovery = useMemo(\n () =>\n createDeepAgentSendRecovery({\n lane: () => {\n const client = clientRef.current;\n if (!client) return null;\n return readStatewireFailedSendLane(client.thread().getState().extras);\n },\n failureStamps: () => failureStampsRef.current?.() ?? null,\n diagnostics: () => diagnosticsRef.current,\n }),\n [attachId]\n );\n useEffect(() => () => sendRecovery.dispose(), [sendRecovery]);\n const sendRecoveryRef = useRef(sendRecovery);\n sendRecoveryRef.current = sendRecovery;\n\n const thread = useDeepAgentThread({\n ...threadOptions,\n ...(attachKey !== undefined && { attachKey }),\n laneEpoch,\n // Parked without a message (a host suspension, when one applies, wins):\n // nothing dials and nothing journals until the lane is known. What paints\n // the first frame is the real attach's to report, not the park's.\n ...(sessionPending && {\n suspended: threadOptions.suspended || {},\n onAttachSource: undefined,\n }),\n // A pooled dial for the thread is the real attach's to take: a park that\n // only waits for the lane neither takes nor discards it. A host suspension\n // still discards it, as it does without a pending lane.\n ...(sessionPending && !threadOptions.suspended && { prewarmPool: undefined }),\n ...(session !== false &&\n session.kind === 'local-storage' &&\n canPersistLocalSession && {\n storage: {\n session: QuotaSafeLocalStorageSession({\n threadId: threadOptions.threadId,\n key: session.key,\n ...(session.onStorageDegraded === undefined\n ? {}\n : { onStorageDegraded: session.onStorageDegraded }),\n }),\n },\n }),\n ...(session !== false && session.kind === 'session-store' && { sessionStore: session.store }),\n onStateChange: (state, ctx) => {\n sendRecoveryRef.current.observeStateChange(state);\n onStateChangeRef.current?.(state, ctx);\n },\n onCommandChange: (update, ctx) => {\n sendRecoveryRef.current.observeCommand(update);\n onCommandChangeRef.current?.(update, ctx);\n },\n onError: (error) => {\n const handler = onErrorRef.current;\n if (handler) {\n handler(error);\n return;\n }\n logUnhandledStatewireError(surfaceRef.current, error);\n },\n });\n\n const client = useClient(thread);\n clientRef.current = client;\n\n // A locked shared journal can publish failed history after onCommandChange,\n // with no canonical state change to wake recovery. Observe the client that\n // owns the visible failed lane; the controller guards in-flight retries.\n useEffect(() => {\n const unsubscribe = client.subscribe(() => sendRecovery.observeFailedLaneChange());\n sendRecovery.observeFailedLaneChange();\n return unsubscribe;\n }, [client, sendRecovery]);\n\n // Commands travel bare, so the runConfig that drives the run rides the\n // ambient model context: `contextSync: 'command-send'` mirrors it to the\n // server, which reads `config.runConfig` at command admission. The core pulls\n // on model-context notifications; the per-render ref ensures each pull uses\n // the latest closure but does not trigger a pull itself.\n const getRunConfigRef = useRef(runConfig?.get);\n getRunConfigRef.current = runConfig?.get;\n const hasRunConfig = runConfig !== undefined;\n const runConfigKey = runConfig?.key;\n useEffect(() => {\n if (!hasRunConfig) return undefined;\n return registerDeepAgentRunConfig(client, () => getRunConfigRef.current?.() ?? {});\n }, [client, hasRunConfig, runConfigKey]);\n\n return client;\n}\n\n"],"names":["isStorageQuotaError","isStatewireChannelTeardown","isConfigSyncUnavailableRejection","useState","useRef","readPersistedFailedSendStamps","readFailedSendStampsFromRecord","nextSessionLaneEpoch","INITIAL_SESSION_LANE_EPOCH","deepAgentAttachId","sendRecovery","useMemo","createDeepAgentSendRecovery","client","readStatewireFailedSendLane","useEffect","useDeepAgentThread","QuotaSafeLocalStorageSession","registerDeepAgentRunConfig"],"mappings":";;;;;;;;;;;AAkGO,SAAS,wBAAwB,WAAgD;AACtF,SAAO,mBAAmB,aAAa,EAAE;AAC3C;AA6BO,SAAS,6BAAsC;;AACpD,MAAI;AACF,UAAM,UAAU;AAChB,QAAI,GAAC,aAAQ,cAAR,mBAAmB,OAAO,QAAO;AACtC,UAAM,UAAU,QAAQ;AACxB,QAAI,CAAC,QAAS,QAAO;AACrB,UAAM,WAAW;AACjB,QAAI;AACF,cAAQ,QAAQ,UAAU,QAAQ;AAClC,cAAQ,WAAW,QAAQ;AAAA,IAC7B,SAAS,OAAO;AACd,aAAOA,6BAAAA,oBAAoB,KAAK;AAAA,IAClC;AACA,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAIA,SAAS,kBACP,OACmF;AACnF,MAAI;AACF,WAAO,MAAM,KAAA;AAAA,EACf,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAWO,SAAS,2BAA2B,SAAiB,OAAoB;AAC9E,MAAIC,OAAAA,2BAA2B,KAAK,GAAG;AACrC,YAAQ,MAAM,IAAI,OAAO,iCAAiC,KAA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AAO;AACT;;;;;"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const reactStatewire = require("@assistant-ui/react-statewire");
|
|
4
4
|
const tap = require("@assistant-ui/tap");
|
|
5
|
-
const
|
|
5
|
+
const require$$0 = require("react");
|
|
6
6
|
const authDenial = require("./auth-denial.cjs");
|
|
7
7
|
const deepAgentTransportRecipe = require("./deep-agent-transport-recipe.cjs");
|
|
8
8
|
const errors = require("./errors.cjs");
|
|
@@ -74,72 +74,72 @@ function useDeepAgentThread({
|
|
|
74
74
|
onProtocolChange
|
|
75
75
|
}) {
|
|
76
76
|
var _a;
|
|
77
|
-
const onRunningChangeRef =
|
|
77
|
+
const onRunningChangeRef = require$$0.useRef(onRunningChange);
|
|
78
78
|
onRunningChangeRef.current = onRunningChange;
|
|
79
|
-
const onSessionPersistedChangeRef =
|
|
79
|
+
const onSessionPersistedChangeRef = require$$0.useRef(onSessionPersistedChange);
|
|
80
80
|
onSessionPersistedChangeRef.current = onSessionPersistedChange;
|
|
81
|
-
const onConnectionChangeRef =
|
|
81
|
+
const onConnectionChangeRef = require$$0.useRef(onConnectionChange);
|
|
82
82
|
onConnectionChangeRef.current = onConnectionChange;
|
|
83
|
-
const onServerRunConfigRef =
|
|
83
|
+
const onServerRunConfigRef = require$$0.useRef(onServerRunConfig);
|
|
84
84
|
onServerRunConfigRef.current = onServerRunConfig;
|
|
85
|
-
const onOutOfBandRunActiveRef =
|
|
85
|
+
const onOutOfBandRunActiveRef = require$$0.useRef(onOutOfBandRunActive);
|
|
86
86
|
onOutOfBandRunActiveRef.current = onOutOfBandRunActive;
|
|
87
|
-
const onProtocolChangeRef =
|
|
87
|
+
const onProtocolChangeRef = require$$0.useRef(onProtocolChange);
|
|
88
88
|
onProtocolChangeRef.current = onProtocolChange;
|
|
89
|
-
const onErrorRef =
|
|
89
|
+
const onErrorRef = require$$0.useRef(onError);
|
|
90
90
|
onErrorRef.current = onError;
|
|
91
|
-
const onStateChangeRef =
|
|
91
|
+
const onStateChangeRef = require$$0.useRef(onStateChange);
|
|
92
92
|
onStateChangeRef.current = onStateChange;
|
|
93
|
-
const onCommandChangeRef =
|
|
93
|
+
const onCommandChangeRef = require$$0.useRef(onCommandChange);
|
|
94
94
|
onCommandChangeRef.current = onCommandChange;
|
|
95
|
-
const onRawConnectionChangeRef =
|
|
95
|
+
const onRawConnectionChangeRef = require$$0.useRef(onRawConnectionChange);
|
|
96
96
|
onRawConnectionChangeRef.current = onRawConnectionChange;
|
|
97
|
-
const headersRef =
|
|
97
|
+
const headersRef = require$$0.useRef(headers);
|
|
98
98
|
headersRef.current = headers;
|
|
99
|
-
const messageWindowRef =
|
|
99
|
+
const messageWindowRef = require$$0.useRef(messageWindow$1);
|
|
100
100
|
messageWindowRef.current = messageWindow$1;
|
|
101
|
-
const laneHistoryRef =
|
|
101
|
+
const laneHistoryRef = require$$0.useRef(laneHistory);
|
|
102
102
|
laneHistoryRef.current = laneHistory;
|
|
103
|
-
const interestRef =
|
|
104
|
-
const lastMessagesRef =
|
|
105
|
-
const [toolOutputsVersion, setToolOutputsVersion] =
|
|
106
|
-
|
|
103
|
+
const interestRef = require$$0.useRef({ attachId: "", stated: false });
|
|
104
|
+
const lastMessagesRef = require$$0.useRef(null);
|
|
105
|
+
const [toolOutputsVersion, setToolOutputsVersion] = require$$0.useState(0);
|
|
106
|
+
require$$0.useEffect(() => {
|
|
107
107
|
if (!toolOutputs) return void 0;
|
|
108
108
|
return toolOutputs.subscribe(() => setToolOutputsVersion((version) => version + 1));
|
|
109
109
|
}, [toolOutputs]);
|
|
110
|
-
const [withdrawnTurnsVersion, setWithdrawnTurnsVersion] =
|
|
111
|
-
|
|
110
|
+
const [withdrawnTurnsVersion, setWithdrawnTurnsVersion] = require$$0.useState(0);
|
|
111
|
+
require$$0.useEffect(() => {
|
|
112
112
|
if (!withdrawnTurns) return void 0;
|
|
113
113
|
return withdrawnTurns.subscribe(() => setWithdrawnTurnsVersion((version) => version + 1));
|
|
114
114
|
}, [withdrawnTurns]);
|
|
115
|
-
const diagnosticsRef =
|
|
115
|
+
const diagnosticsRef = require$$0.useRef(diagnostics);
|
|
116
116
|
diagnosticsRef.current = diagnostics;
|
|
117
|
-
const onAttachTimingRef =
|
|
117
|
+
const onAttachTimingRef = require$$0.useRef(onAttachTiming);
|
|
118
118
|
onAttachTimingRef.current = onAttachTiming;
|
|
119
|
-
const onAttachSourceRef =
|
|
119
|
+
const onAttachSourceRef = require$$0.useRef(onAttachSource);
|
|
120
120
|
onAttachSourceRef.current = onAttachSource;
|
|
121
|
-
const lastRunningRef =
|
|
122
|
-
const lastOutOfBandRunActiveRef =
|
|
123
|
-
const lastSessionPersistedRef =
|
|
124
|
-
const lastProtocolRef =
|
|
125
|
-
const appliedStateRunConfigThreadRef =
|
|
126
|
-
const absentStateRunConfigAttachRef =
|
|
127
|
-
const threadIdRef =
|
|
121
|
+
const lastRunningRef = require$$0.useRef(null);
|
|
122
|
+
const lastOutOfBandRunActiveRef = require$$0.useRef(null);
|
|
123
|
+
const lastSessionPersistedRef = require$$0.useRef(null);
|
|
124
|
+
const lastProtocolRef = require$$0.useRef(null);
|
|
125
|
+
const appliedStateRunConfigThreadRef = require$$0.useRef(null);
|
|
126
|
+
const absentStateRunConfigAttachRef = require$$0.useRef(null);
|
|
127
|
+
const threadIdRef = require$$0.useRef(threadId);
|
|
128
128
|
threadIdRef.current = threadId;
|
|
129
129
|
const attachId = deepAgentAttachId({ threadId, attachKey, laneEpoch });
|
|
130
|
-
const attachIdRef =
|
|
130
|
+
const attachIdRef = require$$0.useRef(attachId);
|
|
131
131
|
attachIdRef.current = attachId;
|
|
132
|
-
const [authParked, setAuthParked] =
|
|
133
|
-
const authDenialRef =
|
|
132
|
+
const [authParked, setAuthParked] = require$$0.useState(null);
|
|
133
|
+
const authDenialRef = require$$0.useRef({
|
|
134
134
|
attachId,
|
|
135
135
|
state: authDenial.initialAuthDenialTrackerState()
|
|
136
136
|
});
|
|
137
|
-
|
|
137
|
+
require$$0.useEffect(() => {
|
|
138
138
|
setAuthParked((prev) => prev !== null && prev.attachId !== attachId ? null : prev);
|
|
139
139
|
}, [attachId]);
|
|
140
|
-
const [stableSelfAuthor, setStableSelfAuthor] =
|
|
140
|
+
const [stableSelfAuthor, setStableSelfAuthor] = require$$0.useState(selfAuthor);
|
|
141
141
|
if (!messageAuthor.isSameMessageAuthor(stableSelfAuthor, selfAuthor)) setStableSelfAuthor(selfAuthor);
|
|
142
|
-
const converter =
|
|
142
|
+
const converter = require$$0.useMemo(
|
|
143
143
|
() => (state, isRunning, conversionCache2) => {
|
|
144
144
|
var _a2;
|
|
145
145
|
const stateRunConfig = state == null ? void 0 : state.runConfig;
|
|
@@ -215,12 +215,12 @@ function useDeepAgentThread({
|
|
|
215
215
|
withdrawnTurnsVersion
|
|
216
216
|
]
|
|
217
217
|
);
|
|
218
|
-
const materialize =
|
|
218
|
+
const materialize = require$$0.useMemo(
|
|
219
219
|
() => messages.createDeepAgentMaterialize({ selfAuthor: stableSelfAuthor }),
|
|
220
220
|
[stableSelfAuthor]
|
|
221
221
|
);
|
|
222
|
-
const lastConnectionRef =
|
|
223
|
-
|
|
222
|
+
const lastConnectionRef = require$$0.useRef(null);
|
|
223
|
+
require$$0.useEffect(
|
|
224
224
|
() => () => {
|
|
225
225
|
var _a2;
|
|
226
226
|
lastConnectionRef.current = null;
|
|
@@ -228,12 +228,12 @@ function useDeepAgentThread({
|
|
|
228
228
|
},
|
|
229
229
|
[]
|
|
230
230
|
);
|
|
231
|
-
const preloadRef =
|
|
231
|
+
const preloadRef = require$$0.useRef({ threadId, laneEpoch, preload: isNewChat });
|
|
232
232
|
if (preloadRef.current.threadId !== threadId || preloadRef.current.laneEpoch !== laneEpoch)
|
|
233
233
|
preloadRef.current = { threadId, laneEpoch, preload: isNewChat };
|
|
234
|
-
const snapshotCacheRef =
|
|
234
|
+
const snapshotCacheRef = require$$0.useRef(snapshotCache);
|
|
235
235
|
snapshotCacheRef.current = snapshotCache;
|
|
236
|
-
const snapshotSeedRef =
|
|
236
|
+
const snapshotSeedRef = require$$0.useRef(null);
|
|
237
237
|
if (snapshotSeedRef.current === null || snapshotSeedRef.current.attachId !== attachId) {
|
|
238
238
|
const preload = preloadRef.current.preload;
|
|
239
239
|
const laneReplaced = snapshotSeedRef.current !== null && snapshotSeedRef.current.laneEpoch !== laneEpoch;
|
|
@@ -253,7 +253,7 @@ function useDeepAgentThread({
|
|
|
253
253
|
const notifySource = onAttachSourceRef.current;
|
|
254
254
|
if (notifySource) queueMicrotask(() => notifySource({ threadId, source }));
|
|
255
255
|
}
|
|
256
|
-
const conversionCacheRef =
|
|
256
|
+
const conversionCacheRef = require$$0.useRef(null);
|
|
257
257
|
if (conversionCacheRef.current === null || conversionCacheRef.current.attachId !== attachId || conversionCacheRef.current.showQuietTools !== showQuietTools) {
|
|
258
258
|
conversionCacheRef.current = {
|
|
259
259
|
attachId,
|
|
@@ -262,10 +262,10 @@ function useDeepAgentThread({
|
|
|
262
262
|
};
|
|
263
263
|
}
|
|
264
264
|
const conversionCache = conversionCacheRef.current.cache;
|
|
265
|
-
const lastStateMessagesRef =
|
|
265
|
+
const lastStateMessagesRef = require$$0.useRef(
|
|
266
266
|
null
|
|
267
267
|
);
|
|
268
|
-
const threadConverter =
|
|
268
|
+
const threadConverter = require$$0.useCallback(
|
|
269
269
|
(wireState, meta) => {
|
|
270
270
|
var _a2, _b, _c, _d, _e, _f, _g;
|
|
271
271
|
const values = statewireState.readDeepAgentStreamValues(wireState);
|