@stigmer/react 0.3.4 → 0.4.1
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/billing/AutoRechargeCard.d.ts +38 -0
- package/billing/AutoRechargeCard.d.ts.map +1 -0
- package/billing/AutoRechargeCard.js +90 -0
- package/billing/AutoRechargeCard.js.map +1 -0
- package/billing/BillingSection.d.ts +32 -0
- package/billing/BillingSection.d.ts.map +1 -0
- package/billing/BillingSection.js +81 -0
- package/billing/BillingSection.js.map +1 -0
- package/billing/CreditBalanceCard.d.ts +25 -0
- package/billing/CreditBalanceCard.d.ts.map +1 -0
- package/billing/CreditBalanceCard.js +28 -0
- package/billing/CreditBalanceCard.js.map +1 -0
- package/billing/CreditLedgerTable.d.ts +22 -0
- package/billing/CreditLedgerTable.d.ts.map +1 -0
- package/billing/CreditLedgerTable.js +75 -0
- package/billing/CreditLedgerTable.js.map +1 -0
- package/billing/CreditPackGrid.d.ts +31 -0
- package/billing/CreditPackGrid.d.ts.map +1 -0
- package/billing/CreditPackGrid.js +35 -0
- package/billing/CreditPackGrid.js.map +1 -0
- package/billing/LowBalanceBanner.d.ts +26 -0
- package/billing/LowBalanceBanner.d.ts.map +1 -0
- package/billing/LowBalanceBanner.js +33 -0
- package/billing/LowBalanceBanner.js.map +1 -0
- package/billing/PaymentMethodCard.d.ts +35 -0
- package/billing/PaymentMethodCard.d.ts.map +1 -0
- package/billing/PaymentMethodCard.js +48 -0
- package/billing/PaymentMethodCard.js.map +1 -0
- package/billing/credit-packs.d.ts +25 -0
- package/billing/credit-packs.d.ts.map +1 -0
- package/billing/credit-packs.js +39 -0
- package/billing/credit-packs.js.map +1 -0
- package/billing/format.d.ts +39 -0
- package/billing/format.d.ts.map +1 -0
- package/billing/format.js +90 -0
- package/billing/format.js.map +1 -0
- package/billing/index.d.ts +32 -0
- package/billing/index.d.ts.map +1 -0
- package/billing/index.js +21 -0
- package/billing/index.js.map +1 -0
- package/billing/useBillingAccount.d.ts +40 -0
- package/billing/useBillingAccount.d.ts.map +1 -0
- package/billing/useBillingAccount.js +35 -0
- package/billing/useBillingAccount.js.map +1 -0
- package/billing/useBillingUsageReport.d.ts +42 -0
- package/billing/useBillingUsageReport.d.ts.map +1 -0
- package/billing/useBillingUsageReport.js +43 -0
- package/billing/useBillingUsageReport.js.map +1 -0
- package/billing/useCreateBillingPortalSession.d.ts +35 -0
- package/billing/useCreateBillingPortalSession.d.ts.map +1 -0
- package/billing/useCreateBillingPortalSession.js +50 -0
- package/billing/useCreateBillingPortalSession.js.map +1 -0
- package/billing/useCreateCheckoutSession.d.ts +54 -0
- package/billing/useCreateCheckoutSession.d.ts.map +1 -0
- package/billing/useCreateCheckoutSession.js +58 -0
- package/billing/useCreateCheckoutSession.js.map +1 -0
- package/billing/useCreditLedger.d.ts +48 -0
- package/billing/useCreditLedger.d.ts.map +1 -0
- package/billing/useCreditLedger.js +39 -0
- package/billing/useCreditLedger.js.map +1 -0
- package/billing/useCustomerModelPricing.d.ts +41 -0
- package/billing/useCustomerModelPricing.d.ts.map +1 -0
- package/billing/useCustomerModelPricing.js +37 -0
- package/billing/useCustomerModelPricing.js.map +1 -0
- package/billing/useSetAutoRechargeConfig.d.ts +50 -0
- package/billing/useSetAutoRechargeConfig.d.ts.map +1 -0
- package/billing/useSetAutoRechargeConfig.js +53 -0
- package/billing/useSetAutoRechargeConfig.js.map +1 -0
- package/composer/ComposerToolbar.js +1 -1
- package/composer/ComposerToolbar.js.map +1 -1
- package/composer/SessionComposer.d.ts +1 -1
- package/composer/SessionComposer.d.ts.map +1 -1
- package/composer/SessionComposer.js +19 -4
- package/composer/SessionComposer.js.map +1 -1
- package/composer/__tests__/SessionComposer-memo.test.d.ts +2 -0
- package/composer/__tests__/SessionComposer-memo.test.d.ts.map +1 -0
- package/composer/__tests__/SessionComposer-memo.test.js +23 -0
- package/composer/__tests__/SessionComposer-memo.test.js.map +1 -0
- package/execution/ApprovalCard.d.ts +5 -1
- package/execution/ApprovalCard.d.ts.map +1 -1
- package/execution/ApprovalCard.js +7 -3
- package/execution/ApprovalCard.js.map +1 -1
- package/execution/ExecutionPhaseBadge.d.ts +1 -1
- package/execution/ExecutionPhaseBadge.d.ts.map +1 -1
- package/execution/ExecutionPhaseBadge.js +3 -2
- package/execution/ExecutionPhaseBadge.js.map +1 -1
- package/execution/MessageEntry.d.ts +7 -3
- package/execution/MessageEntry.d.ts.map +1 -1
- package/execution/MessageEntry.js +19 -8
- package/execution/MessageEntry.js.map +1 -1
- package/execution/MessageThread.d.ts +84 -3
- package/execution/MessageThread.d.ts.map +1 -1
- package/execution/MessageThread.js +113 -65
- package/execution/MessageThread.js.map +1 -1
- package/execution/SetupProgress.d.ts +1 -1
- package/execution/SetupProgress.d.ts.map +1 -1
- package/execution/SetupProgress.js +3 -3
- package/execution/SetupProgress.js.map +1 -1
- package/execution/SubAgentSection.d.ts +5 -1
- package/execution/SubAgentSection.d.ts.map +1 -1
- package/execution/SubAgentSection.js +13 -7
- package/execution/SubAgentSection.js.map +1 -1
- package/execution/ThreadSkeleton.d.ts +22 -0
- package/execution/ThreadSkeleton.d.ts.map +1 -0
- package/execution/ThreadSkeleton.js +26 -0
- package/execution/ThreadSkeleton.js.map +1 -0
- package/execution/ToolCallGroup.d.ts +16 -1
- package/execution/ToolCallGroup.d.ts.map +1 -1
- package/execution/ToolCallGroup.js +31 -3
- package/execution/ToolCallGroup.js.map +1 -1
- package/execution/UsageWidget.d.ts +1 -1
- package/execution/__tests__/message-entry.test.d.ts +2 -0
- package/execution/__tests__/message-entry.test.d.ts.map +1 -0
- package/execution/__tests__/message-entry.test.js +178 -0
- package/execution/__tests__/message-entry.test.js.map +1 -0
- package/execution/__tests__/thread-keys.test.d.ts +2 -0
- package/execution/__tests__/thread-keys.test.d.ts.map +1 -0
- package/execution/__tests__/thread-keys.test.js +289 -0
- package/execution/__tests__/thread-keys.test.js.map +1 -0
- package/execution/__tests__/thread-memoization.test.d.ts +2 -0
- package/execution/__tests__/thread-memoization.test.d.ts.map +1 -0
- package/execution/__tests__/thread-memoization.test.js +262 -0
- package/execution/__tests__/thread-memoization.test.js.map +1 -0
- package/execution/__tests__/thread-skeleton.test.d.ts +2 -0
- package/execution/__tests__/thread-skeleton.test.d.ts.map +1 -0
- package/execution/__tests__/thread-skeleton.test.js +35 -0
- package/execution/__tests__/thread-skeleton.test.js.map +1 -0
- package/execution/__tests__/useExecutionStream.test.js +73 -10
- package/execution/__tests__/useExecutionStream.test.js.map +1 -1
- package/execution/__tests__/useSessionVariables-stability.test.d.ts +2 -0
- package/execution/__tests__/useSessionVariables-stability.test.d.ts.map +1 -0
- package/execution/__tests__/useSessionVariables-stability.test.js +69 -0
- package/execution/__tests__/useSessionVariables-stability.test.js.map +1 -0
- package/execution/__tests__/virtualized-thread.test.d.ts +2 -0
- package/execution/__tests__/virtualized-thread.test.d.ts.map +1 -0
- package/execution/__tests__/virtualized-thread.test.js +274 -0
- package/execution/__tests__/virtualized-thread.test.js.map +1 -0
- package/execution/index.d.ts +2 -0
- package/execution/index.d.ts.map +1 -1
- package/execution/index.js +1 -0
- package/execution/index.js.map +1 -1
- package/execution/useExecutionStream.d.ts +35 -10
- package/execution/useExecutionStream.d.ts.map +1 -1
- package/execution/useExecutionStream.js +79 -40
- package/execution/useExecutionStream.js.map +1 -1
- package/execution/useSessionVariables.d.ts.map +1 -1
- package/execution/useSessionVariables.js +4 -3
- package/execution/useSessionVariables.js.map +1 -1
- package/github/useGitHubConnection.d.ts.map +1 -1
- package/github/useGitHubConnection.js +5 -4
- package/github/useGitHubConnection.js.map +1 -1
- package/identity-account/index.d.ts +2 -0
- package/identity-account/index.d.ts.map +1 -0
- package/identity-account/index.js +2 -0
- package/identity-account/index.js.map +1 -0
- package/identity-account/useIdentityAccountGate.d.ts +81 -0
- package/identity-account/useIdentityAccountGate.d.ts.map +1 -0
- package/identity-account/useIdentityAccountGate.js +100 -0
- package/identity-account/useIdentityAccountGate.js.map +1 -0
- package/index.d.ts +10 -4
- package/index.d.ts.map +1 -1
- package/index.js +8 -2
- package/index.js.map +1 -1
- package/internal/FetchCacheProvider.d.ts +44 -0
- package/internal/FetchCacheProvider.d.ts.map +1 -0
- package/internal/FetchCacheProvider.js +61 -0
- package/internal/FetchCacheProvider.js.map +1 -0
- package/internal/JumpToLatestButton.d.ts +14 -0
- package/internal/JumpToLatestButton.d.ts.map +1 -0
- package/internal/JumpToLatestButton.js +19 -0
- package/internal/JumpToLatestButton.js.map +1 -0
- package/internal/ThreadItemWrapper.d.ts +20 -0
- package/internal/ThreadItemWrapper.d.ts.map +1 -0
- package/internal/ThreadItemWrapper.js +44 -0
- package/internal/ThreadItemWrapper.js.map +1 -0
- package/internal/VirtualizedThread.d.ts +25 -0
- package/internal/VirtualizedThread.d.ts.map +1 -0
- package/internal/VirtualizedThread.js +58 -0
- package/internal/VirtualizedThread.js.map +1 -0
- package/internal/__tests__/fetch-cache.test.d.ts +2 -0
- package/internal/__tests__/fetch-cache.test.d.ts.map +1 -0
- package/internal/__tests__/fetch-cache.test.js +182 -0
- package/internal/__tests__/fetch-cache.test.js.map +1 -0
- package/internal/__tests__/stream-controller.test.d.ts +2 -0
- package/internal/__tests__/stream-controller.test.d.ts.map +1 -0
- package/internal/__tests__/stream-controller.test.js +294 -0
- package/internal/__tests__/stream-controller.test.js.map +1 -0
- package/internal/__tests__/thread-animation.test.d.ts +2 -0
- package/internal/__tests__/thread-animation.test.d.ts.map +1 -0
- package/internal/__tests__/thread-animation.test.js +79 -0
- package/internal/__tests__/thread-animation.test.js.map +1 -0
- package/internal/__tests__/useAutoScroll.test.d.ts +2 -0
- package/internal/__tests__/useAutoScroll.test.d.ts.map +1 -0
- package/internal/__tests__/useAutoScroll.test.js +188 -0
- package/internal/__tests__/useAutoScroll.test.js.map +1 -0
- package/internal/__tests__/useFetch-cache.test.d.ts +2 -0
- package/internal/__tests__/useFetch-cache.test.d.ts.map +1 -0
- package/internal/__tests__/useFetch-cache.test.js +137 -0
- package/internal/__tests__/useFetch-cache.test.js.map +1 -0
- package/internal/dev/__tests__/use-key-stability.test.d.ts +2 -0
- package/internal/dev/__tests__/use-key-stability.test.d.ts.map +1 -0
- package/internal/dev/__tests__/use-key-stability.test.js +72 -0
- package/internal/dev/__tests__/use-key-stability.test.js.map +1 -0
- package/internal/dev/__tests__/use-render-tracer.test.d.ts +2 -0
- package/internal/dev/__tests__/use-render-tracer.test.d.ts.map +1 -0
- package/internal/dev/__tests__/use-render-tracer.test.js +55 -0
- package/internal/dev/__tests__/use-render-tracer.test.js.map +1 -0
- package/internal/dev/dom-counter.d.ts +14 -0
- package/internal/dev/dom-counter.d.ts.map +1 -0
- package/internal/dev/dom-counter.js +39 -0
- package/internal/dev/dom-counter.js.map +1 -0
- package/internal/dev/index.d.ts +6 -0
- package/internal/dev/index.d.ts.map +1 -0
- package/internal/dev/index.js +6 -0
- package/internal/dev/index.js.map +1 -0
- package/internal/dev/profiler-wrapper.d.ts +16 -0
- package/internal/dev/profiler-wrapper.d.ts.map +1 -0
- package/internal/dev/profiler-wrapper.js +31 -0
- package/internal/dev/profiler-wrapper.js.map +1 -0
- package/internal/dev/use-key-stability.d.ts +22 -0
- package/internal/dev/use-key-stability.d.ts.map +1 -0
- package/internal/dev/use-key-stability.js +67 -0
- package/internal/dev/use-key-stability.js.map +1 -0
- package/internal/dev/use-render-tracer.d.ts +13 -0
- package/internal/dev/use-render-tracer.d.ts.map +1 -0
- package/internal/dev/use-render-tracer.js +57 -0
- package/internal/dev/use-render-tracer.js.map +1 -0
- package/internal/dev/use-stream-rate.d.ts +23 -0
- package/internal/dev/use-stream-rate.d.ts.map +1 -0
- package/internal/dev/use-stream-rate.js +94 -0
- package/internal/dev/use-stream-rate.js.map +1 -0
- package/internal/fetch-cache.d.ts +72 -0
- package/internal/fetch-cache.d.ts.map +1 -0
- package/internal/fetch-cache.js +118 -0
- package/internal/fetch-cache.js.map +1 -0
- package/internal/store/__tests__/conversation-store.test.d.ts +2 -0
- package/internal/store/__tests__/conversation-store.test.d.ts.map +1 -0
- package/internal/store/__tests__/conversation-store.test.js +200 -0
- package/internal/store/__tests__/conversation-store.test.js.map +1 -0
- package/internal/store/__tests__/structural-share.test.d.ts +2 -0
- package/internal/store/__tests__/structural-share.test.d.ts.map +1 -0
- package/internal/store/__tests__/structural-share.test.js +368 -0
- package/internal/store/__tests__/structural-share.test.js.map +1 -0
- package/internal/store/conversation-store.d.ts +62 -0
- package/internal/store/conversation-store.d.ts.map +1 -0
- package/internal/store/conversation-store.js +95 -0
- package/internal/store/conversation-store.js.map +1 -0
- package/internal/store/index.d.ts +31 -0
- package/internal/store/index.d.ts.map +1 -0
- package/internal/store/index.js +54 -0
- package/internal/store/index.js.map +1 -0
- package/internal/store/structural-share.d.ts +13 -0
- package/internal/store/structural-share.d.ts.map +1 -0
- package/internal/store/structural-share.js +240 -0
- package/internal/store/structural-share.js.map +1 -0
- package/internal/stream-controller.d.ts +85 -0
- package/internal/stream-controller.d.ts.map +1 -0
- package/internal/stream-controller.js +146 -0
- package/internal/stream-controller.js.map +1 -0
- package/internal/useAutoScroll.d.ts +32 -0
- package/internal/useAutoScroll.d.ts.map +1 -0
- package/internal/useAutoScroll.js +97 -0
- package/internal/useAutoScroll.js.map +1 -0
- package/internal/useFetch.d.ts +14 -0
- package/internal/useFetch.d.ts.map +1 -1
- package/internal/useFetch.js +32 -2
- package/internal/useFetch.js.map +1 -1
- package/mcp-server/McpServerDetailView.d.ts.map +1 -1
- package/mcp-server/McpServerDetailView.js +3 -3
- package/mcp-server/McpServerDetailView.js.map +1 -1
- package/mcp-server/useMcpServerOAuthConnect.d.ts.map +1 -1
- package/mcp-server/useMcpServerOAuthConnect.js +37 -9
- package/mcp-server/useMcpServerOAuthConnect.js.map +1 -1
- package/package.json +7 -5
- package/session/__tests__/useNewSessionFlow.test.js +16 -0
- package/session/__tests__/useNewSessionFlow.test.js.map +1 -1
- package/session/__tests__/usePersistedModel.test.d.ts +2 -0
- package/session/__tests__/usePersistedModel.test.d.ts.map +1 -0
- package/session/__tests__/usePersistedModel.test.js +82 -0
- package/session/__tests__/usePersistedModel.test.js.map +1 -0
- package/session/__tests__/useSession.test.d.ts +2 -0
- package/session/__tests__/useSession.test.d.ts.map +1 -0
- package/session/__tests__/useSession.test.js +130 -0
- package/session/__tests__/useSession.test.js.map +1 -0
- package/session/useNewSessionFlow.d.ts.map +1 -1
- package/session/useNewSessionFlow.js +12 -6
- package/session/useNewSessionFlow.js.map +1 -1
- package/session/usePersistedModel.d.ts +3 -0
- package/session/usePersistedModel.d.ts.map +1 -1
- package/session/usePersistedModel.js +27 -2
- package/session/usePersistedModel.js.map +1 -1
- package/session/useSession.d.ts.map +1 -1
- package/session/useSession.js +1 -1
- package/session/useSession.js.map +1 -1
- package/session/useSessionConversation.d.ts.map +1 -1
- package/session/useSessionConversation.js +9 -1
- package/session/useSessionConversation.js.map +1 -1
- package/session/useSessionExecutions.d.ts.map +1 -1
- package/session/useSessionExecutions.js +1 -1
- package/session/useSessionExecutions.js.map +1 -1
- package/session/useSessionPageFlow.js +1 -1
- package/session/useSessionPageFlow.js.map +1 -1
- package/session/useSessionUsage.d.ts +24 -40
- package/session/useSessionUsage.d.ts.map +1 -1
- package/session/useSessionUsage.js +64 -97
- package/session/useSessionUsage.js.map +1 -1
- package/settings/BillingSection.d.ts +3 -0
- package/settings/BillingSection.d.ts.map +1 -0
- package/settings/BillingSection.js +3 -0
- package/settings/BillingSection.js.map +1 -0
- package/settings/index.d.ts +2 -0
- package/settings/index.d.ts.map +1 -1
- package/settings/index.js +1 -0
- package/settings/index.js.map +1 -1
- package/settings/settings-nav.js +1 -1
- package/settings/settings-nav.js.map +1 -1
- package/src/billing/AutoRechargeCard.tsx +274 -0
- package/src/billing/BillingSection.tsx +255 -0
- package/src/billing/CreditBalanceCard.tsx +81 -0
- package/src/billing/CreditLedgerTable.tsx +281 -0
- package/src/billing/CreditPackGrid.tsx +132 -0
- package/src/billing/LowBalanceBanner.tsx +67 -0
- package/src/billing/PaymentMethodCard.tsx +133 -0
- package/src/billing/credit-packs.ts +54 -0
- package/src/billing/format.ts +97 -0
- package/src/billing/index.ts +51 -0
- package/src/billing/useBillingAccount.ts +64 -0
- package/src/billing/useBillingUsageReport.ts +73 -0
- package/src/billing/useCreateBillingPortalSession.ts +76 -0
- package/src/billing/useCreateCheckoutSession.ts +101 -0
- package/src/billing/useCreditLedger.ts +79 -0
- package/src/billing/useCustomerModelPricing.ts +67 -0
- package/src/billing/useSetAutoRechargeConfig.ts +90 -0
- package/src/composer/ComposerToolbar.tsx +1 -1
- package/src/composer/SessionComposer.tsx +22 -4
- package/src/composer/__tests__/SessionComposer-memo.test.ts +26 -0
- package/src/execution/ApprovalCard.tsx +7 -3
- package/src/execution/ExecutionPhaseBadge.tsx +3 -2
- package/src/execution/MessageEntry.tsx +27 -16
- package/src/execution/MessageThread.tsx +308 -131
- package/src/execution/SetupProgress.tsx +3 -3
- package/src/execution/SubAgentSection.tsx +14 -6
- package/src/execution/ThreadSkeleton.tsx +73 -0
- package/src/execution/ToolCallGroup.tsx +36 -3
- package/src/execution/UsageWidget.tsx +1 -1
- package/src/execution/__tests__/message-entry.test.tsx +236 -0
- package/src/execution/__tests__/thread-keys.test.ts +409 -0
- package/src/execution/__tests__/thread-memoization.test.ts +320 -0
- package/src/execution/__tests__/thread-skeleton.test.tsx +44 -0
- package/src/execution/__tests__/useExecutionStream.test.tsx +109 -12
- package/src/execution/__tests__/useSessionVariables-stability.test.ts +95 -0
- package/src/execution/__tests__/virtualized-thread.test.tsx +401 -0
- package/src/execution/index.ts +3 -0
- package/src/execution/useExecutionStream.ts +123 -48
- package/src/execution/useSessionVariables.ts +17 -12
- package/src/github/useGitHubConnection.ts +18 -13
- package/src/identity-account/index.ts +5 -0
- package/src/identity-account/useIdentityAccountGate.ts +163 -0
- package/src/index.ts +73 -0
- package/src/internal/FetchCacheProvider.tsx +74 -0
- package/src/internal/JumpToLatestButton.tsx +61 -0
- package/src/internal/ThreadItemWrapper.tsx +65 -0
- package/src/internal/VirtualizedThread.tsx +162 -0
- package/src/internal/__tests__/fetch-cache.test.ts +230 -0
- package/src/internal/__tests__/stream-controller.test.ts +395 -0
- package/src/internal/__tests__/thread-animation.test.tsx +121 -0
- package/src/internal/__tests__/useAutoScroll.test.tsx +261 -0
- package/src/internal/__tests__/useFetch-cache.test.ts +214 -0
- package/src/internal/dev/__tests__/use-key-stability.test.ts +124 -0
- package/src/internal/dev/__tests__/use-render-tracer.test.ts +78 -0
- package/src/internal/dev/dom-counter.ts +47 -0
- package/src/internal/dev/index.ts +5 -0
- package/src/internal/dev/profiler-wrapper.tsx +52 -0
- package/src/internal/dev/use-key-stability.ts +86 -0
- package/src/internal/dev/use-render-tracer.ts +70 -0
- package/src/internal/dev/use-stream-rate.ts +138 -0
- package/src/internal/fetch-cache.ts +155 -0
- package/src/internal/store/__tests__/conversation-store.test.ts +257 -0
- package/src/internal/store/__tests__/structural-share.test.ts +454 -0
- package/src/internal/store/conversation-store.ts +128 -0
- package/src/internal/store/index.ts +68 -0
- package/src/internal/store/structural-share.ts +318 -0
- package/src/internal/stream-controller.ts +201 -0
- package/src/internal/useAutoScroll.ts +121 -0
- package/src/internal/useFetch.ts +51 -2
- package/src/mcp-server/McpServerDetailView.tsx +15 -0
- package/src/mcp-server/useMcpServerOAuthConnect.ts +37 -9
- package/src/session/__tests__/useNewSessionFlow.test.tsx +22 -0
- package/src/session/__tests__/usePersistedModel.test.tsx +117 -0
- package/src/session/__tests__/useSession.test.tsx +187 -0
- package/src/session/useNewSessionFlow.ts +12 -6
- package/src/session/usePersistedModel.ts +28 -2
- package/src/session/useSession.ts +1 -0
- package/src/session/useSessionConversation.ts +11 -2
- package/src/session/useSessionExecutions.ts +1 -0
- package/src/session/useSessionPageFlow.ts +1 -1
- package/src/session/useSessionUsage.ts +102 -123
- package/src/settings/BillingSection.tsx +4 -0
- package/src/settings/index.ts +2 -0
- package/src/settings/settings-nav.ts +1 -1
- package/src/styles.css +31 -0
- package/src/usage/AgentBreakdownList.tsx +147 -0
- package/src/usage/CreditRunwayIndicator.tsx +71 -0
- package/src/usage/ExportButton.tsx +115 -0
- package/src/usage/HarnessSplitCard.tsx +103 -0
- package/src/usage/OrgUsagePanel.tsx +109 -45
- package/src/usage/index.ts +15 -0
- package/src/usage/useExportCSV.ts +115 -0
- package/src/usage/useOrgUsageReport.ts +2 -1
- package/src/workspace/__tests__/useWorkspaceEntries-stability.test.ts +76 -0
- package/src/workspace/useWorkspaceEntries.ts +16 -11
- package/styles.css +1 -1
- package/usage/AgentBreakdownList.d.ts +21 -0
- package/usage/AgentBreakdownList.d.ts.map +1 -0
- package/usage/AgentBreakdownList.js +44 -0
- package/usage/AgentBreakdownList.js.map +1 -0
- package/usage/CreditRunwayIndicator.d.ts +21 -0
- package/usage/CreditRunwayIndicator.d.ts.map +1 -0
- package/usage/CreditRunwayIndicator.js +38 -0
- package/usage/CreditRunwayIndicator.js.map +1 -0
- package/usage/ExportButton.d.ts +20 -0
- package/usage/ExportButton.d.ts.map +1 -0
- package/usage/ExportButton.js +36 -0
- package/usage/ExportButton.js.map +1 -0
- package/usage/HarnessSplitCard.d.ts +17 -0
- package/usage/HarnessSplitCard.d.ts.map +1 -0
- package/usage/HarnessSplitCard.js +38 -0
- package/usage/HarnessSplitCard.js.map +1 -0
- package/usage/OrgUsagePanel.d.ts.map +1 -1
- package/usage/OrgUsagePanel.js +30 -22
- package/usage/OrgUsagePanel.js.map +1 -1
- package/usage/index.d.ts +10 -0
- package/usage/index.d.ts.map +1 -1
- package/usage/index.js +5 -0
- package/usage/index.js.map +1 -1
- package/usage/useExportCSV.d.ts +23 -0
- package/usage/useExportCSV.d.ts.map +1 -0
- package/usage/useExportCSV.js +81 -0
- package/usage/useExportCSV.js.map +1 -0
- package/usage/useOrgUsageReport.d.ts +2 -1
- package/usage/useOrgUsageReport.d.ts.map +1 -1
- package/usage/useOrgUsageReport.js +2 -1
- package/usage/useOrgUsageReport.js.map +1 -1
- package/workspace/__tests__/useWorkspaceEntries-stability.test.d.ts +2 -0
- package/workspace/__tests__/useWorkspaceEntries-stability.test.d.ts.map +1 -0
- package/workspace/__tests__/useWorkspaceEntries-stability.test.js +57 -0
- package/workspace/__tests__/useWorkspaceEntries-stability.test.js.map +1 -0
- package/workspace/useWorkspaceEntries.d.ts.map +1 -1
- package/workspace/useWorkspaceEntries.js +5 -4
- package/workspace/useWorkspaceEntries.js.map +1 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { FetchCache } from "../fetch-cache";
|
|
3
|
+
|
|
4
|
+
describe("FetchCache", () => {
|
|
5
|
+
// -------------------------------------------------------------------
|
|
6
|
+
// get / set / has
|
|
7
|
+
// -------------------------------------------------------------------
|
|
8
|
+
|
|
9
|
+
it("returns undefined for a missing key", () => {
|
|
10
|
+
const cache = new FetchCache();
|
|
11
|
+
expect(cache.get("nope")).toBeUndefined();
|
|
12
|
+
expect(cache.has("nope")).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("stores and retrieves a value", () => {
|
|
16
|
+
const cache = new FetchCache();
|
|
17
|
+
const obj = { id: "ses_1", name: "Test" };
|
|
18
|
+
cache.set("session:ses_1", obj);
|
|
19
|
+
|
|
20
|
+
expect(cache.get("session:ses_1")).toBe(obj);
|
|
21
|
+
expect(cache.has("session:ses_1")).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("overwrites an existing entry", () => {
|
|
25
|
+
const cache = new FetchCache();
|
|
26
|
+
cache.set("k", "first");
|
|
27
|
+
cache.set("k", "second");
|
|
28
|
+
expect(cache.get("k")).toBe("second");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("preserves reference identity (no cloning)", () => {
|
|
32
|
+
const cache = new FetchCache();
|
|
33
|
+
const arr = [1, 2, 3];
|
|
34
|
+
cache.set("k", arr);
|
|
35
|
+
expect(cache.get("k")).toBe(arr);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// -------------------------------------------------------------------
|
|
39
|
+
// TTL
|
|
40
|
+
// -------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
describe("TTL expiration", () => {
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
vi.useFakeTimers();
|
|
45
|
+
});
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
vi.useRealTimers();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("returns the value before TTL expires", () => {
|
|
51
|
+
const cache = new FetchCache({ ttl: 1000 });
|
|
52
|
+
cache.set("k", "v");
|
|
53
|
+
|
|
54
|
+
vi.advanceTimersByTime(999);
|
|
55
|
+
expect(cache.get("k")).toBe("v");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("returns undefined after TTL expires", () => {
|
|
59
|
+
const cache = new FetchCache({ ttl: 1000 });
|
|
60
|
+
cache.set("k", "v");
|
|
61
|
+
|
|
62
|
+
vi.advanceTimersByTime(1001);
|
|
63
|
+
expect(cache.get("k")).toBeUndefined();
|
|
64
|
+
expect(cache.has("k")).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("expired entries are excluded from size", () => {
|
|
68
|
+
const cache = new FetchCache({ ttl: 500 });
|
|
69
|
+
cache.set("a", 1);
|
|
70
|
+
cache.set("b", 2);
|
|
71
|
+
|
|
72
|
+
vi.advanceTimersByTime(501);
|
|
73
|
+
expect(cache.size).toBe(0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("writing refreshes the timestamp", () => {
|
|
77
|
+
const cache = new FetchCache({ ttl: 1000 });
|
|
78
|
+
cache.set("k", "first");
|
|
79
|
+
|
|
80
|
+
vi.advanceTimersByTime(800);
|
|
81
|
+
cache.set("k", "second");
|
|
82
|
+
|
|
83
|
+
vi.advanceTimersByTime(800);
|
|
84
|
+
expect(cache.get("k")).toBe("second");
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// -------------------------------------------------------------------
|
|
89
|
+
// LRU eviction
|
|
90
|
+
// -------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
it("evicts the oldest entries when maxEntries is exceeded", () => {
|
|
93
|
+
const cache = new FetchCache({ maxEntries: 3 });
|
|
94
|
+
cache.set("a", 1);
|
|
95
|
+
cache.set("b", 2);
|
|
96
|
+
cache.set("c", 3);
|
|
97
|
+
cache.set("d", 4);
|
|
98
|
+
|
|
99
|
+
expect(cache.has("a")).toBe(false);
|
|
100
|
+
expect(cache.get("b")).toBe(2);
|
|
101
|
+
expect(cache.get("c")).toBe(3);
|
|
102
|
+
expect(cache.get("d")).toBe(4);
|
|
103
|
+
expect(cache.size).toBe(3);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("re-setting a key moves it to the tail (LRU refresh)", () => {
|
|
107
|
+
const cache = new FetchCache({ maxEntries: 3 });
|
|
108
|
+
cache.set("a", 1);
|
|
109
|
+
cache.set("b", 2);
|
|
110
|
+
cache.set("c", 3);
|
|
111
|
+
|
|
112
|
+
// Touch "a" — moves it to the tail.
|
|
113
|
+
cache.set("a", 10);
|
|
114
|
+
|
|
115
|
+
// Adding "d" should evict "b" (the oldest untouched), not "a".
|
|
116
|
+
cache.set("d", 4);
|
|
117
|
+
|
|
118
|
+
expect(cache.has("b")).toBe(false);
|
|
119
|
+
expect(cache.get("a")).toBe(10);
|
|
120
|
+
expect(cache.get("c")).toBe(3);
|
|
121
|
+
expect(cache.get("d")).toBe(4);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// -------------------------------------------------------------------
|
|
125
|
+
// invalidate / invalidatePrefix / clear
|
|
126
|
+
// -------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
it("invalidate removes a single entry", () => {
|
|
129
|
+
const cache = new FetchCache();
|
|
130
|
+
cache.set("a", 1);
|
|
131
|
+
cache.set("b", 2);
|
|
132
|
+
|
|
133
|
+
cache.invalidate("a");
|
|
134
|
+
|
|
135
|
+
expect(cache.has("a")).toBe(false);
|
|
136
|
+
expect(cache.has("b")).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("invalidate is a no-op for missing keys", () => {
|
|
140
|
+
const cache = new FetchCache();
|
|
141
|
+
expect(() => cache.invalidate("nope")).not.toThrow();
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("invalidatePrefix removes all matching entries", () => {
|
|
145
|
+
const cache = new FetchCache();
|
|
146
|
+
cache.set("session:1", "s1");
|
|
147
|
+
cache.set("session:2", "s2");
|
|
148
|
+
cache.set("session-executions:1", "e1");
|
|
149
|
+
cache.set("agent:a", "ag");
|
|
150
|
+
|
|
151
|
+
cache.invalidatePrefix("session:");
|
|
152
|
+
|
|
153
|
+
expect(cache.has("session:1")).toBe(false);
|
|
154
|
+
expect(cache.has("session:2")).toBe(false);
|
|
155
|
+
expect(cache.has("session-executions:1")).toBe(true);
|
|
156
|
+
expect(cache.has("agent:a")).toBe(true);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("clear drops all entries", () => {
|
|
160
|
+
const cache = new FetchCache();
|
|
161
|
+
cache.set("a", 1);
|
|
162
|
+
cache.set("b", 2);
|
|
163
|
+
cache.set("c", 3);
|
|
164
|
+
|
|
165
|
+
cache.clear();
|
|
166
|
+
|
|
167
|
+
expect(cache.size).toBe(0);
|
|
168
|
+
expect(cache.has("a")).toBe(false);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// -------------------------------------------------------------------
|
|
172
|
+
// prefetch
|
|
173
|
+
// -------------------------------------------------------------------
|
|
174
|
+
|
|
175
|
+
it("prefetch writes successful result to cache", async () => {
|
|
176
|
+
const cache = new FetchCache();
|
|
177
|
+
const fetchFn = vi.fn(async () => ({ id: "ses_1" }));
|
|
178
|
+
|
|
179
|
+
cache.prefetch("session:ses_1", fetchFn);
|
|
180
|
+
await vi.waitFor(() => expect(cache.has("session:ses_1")).toBe(true));
|
|
181
|
+
|
|
182
|
+
expect(cache.get("session:ses_1")).toEqual({ id: "ses_1" });
|
|
183
|
+
expect(fetchFn).toHaveBeenCalledOnce();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("prefetch silently swallows errors", async () => {
|
|
187
|
+
const cache = new FetchCache();
|
|
188
|
+
const fetchFn = vi.fn(async () => {
|
|
189
|
+
throw new Error("network down");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
cache.prefetch("k", fetchFn);
|
|
193
|
+
|
|
194
|
+
// Give the microtask queue time to process the rejection.
|
|
195
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
196
|
+
|
|
197
|
+
expect(cache.has("k")).toBe(false);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// -------------------------------------------------------------------
|
|
201
|
+
// size
|
|
202
|
+
// -------------------------------------------------------------------
|
|
203
|
+
|
|
204
|
+
it("reports correct size", () => {
|
|
205
|
+
const cache = new FetchCache();
|
|
206
|
+
expect(cache.size).toBe(0);
|
|
207
|
+
|
|
208
|
+
cache.set("a", 1);
|
|
209
|
+
cache.set("b", 2);
|
|
210
|
+
expect(cache.size).toBe(2);
|
|
211
|
+
|
|
212
|
+
cache.invalidate("a");
|
|
213
|
+
expect(cache.size).toBe(1);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// -------------------------------------------------------------------
|
|
217
|
+
// defaults
|
|
218
|
+
// -------------------------------------------------------------------
|
|
219
|
+
|
|
220
|
+
it("uses default maxEntries of 100", () => {
|
|
221
|
+
const cache = new FetchCache();
|
|
222
|
+
for (let i = 0; i < 110; i++) {
|
|
223
|
+
cache.set(`k${i}`, i);
|
|
224
|
+
}
|
|
225
|
+
expect(cache.size).toBe(100);
|
|
226
|
+
// First 10 should have been evicted.
|
|
227
|
+
expect(cache.has("k0")).toBe(false);
|
|
228
|
+
expect(cache.has("k10")).toBe(true);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
+
import { create } from "@bufbuild/protobuf";
|
|
3
|
+
import {
|
|
4
|
+
AgentExecutionSchema,
|
|
5
|
+
AgentExecutionStatusSchema,
|
|
6
|
+
type AgentExecution,
|
|
7
|
+
} from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/api_pb";
|
|
8
|
+
import { ExecutionPhase } from "@stigmer/protos/ai/stigmer/agentic/agentexecution/v1/enum_pb";
|
|
9
|
+
import {
|
|
10
|
+
StreamController,
|
|
11
|
+
type StreamControllerSink,
|
|
12
|
+
} from "../stream-controller";
|
|
13
|
+
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// Helpers
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
function makeSnapshot(
|
|
19
|
+
phase: ExecutionPhase,
|
|
20
|
+
messageCount = 0,
|
|
21
|
+
): AgentExecution {
|
|
22
|
+
const exec = create(AgentExecutionSchema);
|
|
23
|
+
const status = create(AgentExecutionStatusSchema);
|
|
24
|
+
status.phase = phase;
|
|
25
|
+
for (let i = 0; i < messageCount; i++) {
|
|
26
|
+
status.messages.push({} as never);
|
|
27
|
+
}
|
|
28
|
+
exec.status = status;
|
|
29
|
+
return exec;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function createTestSink(): StreamControllerSink & {
|
|
33
|
+
snapshots: AgentExecution[];
|
|
34
|
+
states: Array<{ stage: string; executionId?: string; error?: Error }>;
|
|
35
|
+
} {
|
|
36
|
+
const snapshots: AgentExecution[] = [];
|
|
37
|
+
const states: Array<{ stage: string; executionId?: string; error?: Error }> =
|
|
38
|
+
[];
|
|
39
|
+
return {
|
|
40
|
+
snapshots,
|
|
41
|
+
states,
|
|
42
|
+
ingestSnapshot(snapshot) {
|
|
43
|
+
snapshots.push(snapshot);
|
|
44
|
+
},
|
|
45
|
+
setStreamState(state) {
|
|
46
|
+
states.push(state as never);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type FlushCallback = () => void;
|
|
52
|
+
|
|
53
|
+
function createSynchronousScheduler() {
|
|
54
|
+
const pending: Array<{ id: number; cb: FlushCallback }> = [];
|
|
55
|
+
let nextId = 1;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
pending,
|
|
59
|
+
schedule(cb: FlushCallback): number {
|
|
60
|
+
const id = nextId++;
|
|
61
|
+
pending.push({ id, cb });
|
|
62
|
+
return id;
|
|
63
|
+
},
|
|
64
|
+
cancel(id: number): void {
|
|
65
|
+
const idx = pending.findIndex((p) => p.id === id);
|
|
66
|
+
if (idx !== -1) pending.splice(idx, 1);
|
|
67
|
+
},
|
|
68
|
+
flush(): void {
|
|
69
|
+
const toRun = [...pending];
|
|
70
|
+
pending.length = 0;
|
|
71
|
+
for (const { cb } of toRun) cb();
|
|
72
|
+
},
|
|
73
|
+
get size() {
|
|
74
|
+
return pending.length;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
// Tests
|
|
81
|
+
// ---------------------------------------------------------------------------
|
|
82
|
+
|
|
83
|
+
describe("StreamController", () => {
|
|
84
|
+
let sink: ReturnType<typeof createTestSink>;
|
|
85
|
+
let scheduler: ReturnType<typeof createSynchronousScheduler>;
|
|
86
|
+
let controller: StreamController;
|
|
87
|
+
|
|
88
|
+
beforeEach(() => {
|
|
89
|
+
sink = createTestSink();
|
|
90
|
+
scheduler = createSynchronousScheduler();
|
|
91
|
+
controller = new StreamController(
|
|
92
|
+
sink,
|
|
93
|
+
scheduler.schedule,
|
|
94
|
+
scheduler.cancel,
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe("initial state", () => {
|
|
99
|
+
it("starts in idle", () => {
|
|
100
|
+
expect(controller.state).toEqual({ stage: "idle" });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("has no pending flush", () => {
|
|
104
|
+
expect(controller.hasPendingFlush).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("start()", () => {
|
|
109
|
+
it("transitions to connecting", () => {
|
|
110
|
+
controller.start("exec-1");
|
|
111
|
+
expect(controller.state).toEqual({
|
|
112
|
+
stage: "connecting",
|
|
113
|
+
executionId: "exec-1",
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("notifies the sink of the state transition", () => {
|
|
118
|
+
controller.start("exec-1");
|
|
119
|
+
expect(sink.states).toEqual([
|
|
120
|
+
{ stage: "connecting", executionId: "exec-1" },
|
|
121
|
+
]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("resets when starting a different execution", () => {
|
|
125
|
+
controller.start("exec-1");
|
|
126
|
+
controller.handleSnapshot(
|
|
127
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS),
|
|
128
|
+
);
|
|
129
|
+
controller.start("exec-2");
|
|
130
|
+
expect(controller.state).toEqual({
|
|
131
|
+
stage: "connecting",
|
|
132
|
+
executionId: "exec-2",
|
|
133
|
+
});
|
|
134
|
+
expect(scheduler.size).toBe(0);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("handleSnapshot() — non-terminal", () => {
|
|
139
|
+
beforeEach(() => {
|
|
140
|
+
controller.start("exec-1");
|
|
141
|
+
sink.states.length = 0;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("transitions from connecting to streaming on first snapshot", () => {
|
|
145
|
+
controller.handleSnapshot(
|
|
146
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS),
|
|
147
|
+
);
|
|
148
|
+
expect(controller.state).toEqual({
|
|
149
|
+
stage: "streaming",
|
|
150
|
+
executionId: "exec-1",
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("buffers the snapshot (does not flush immediately)", () => {
|
|
155
|
+
controller.handleSnapshot(
|
|
156
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS),
|
|
157
|
+
);
|
|
158
|
+
expect(sink.snapshots).toHaveLength(0);
|
|
159
|
+
expect(controller.hasPendingFlush).toBe(true);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("flushes on scheduler callback", () => {
|
|
163
|
+
const snap = makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS);
|
|
164
|
+
controller.handleSnapshot(snap);
|
|
165
|
+
scheduler.flush();
|
|
166
|
+
expect(sink.snapshots).toEqual([snap]);
|
|
167
|
+
expect(controller.hasPendingFlush).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("coalesces multiple snapshots into one flush", () => {
|
|
171
|
+
const snap1 = makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS, 1);
|
|
172
|
+
const snap2 = makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS, 2);
|
|
173
|
+
const snap3 = makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS, 3);
|
|
174
|
+
|
|
175
|
+
controller.handleSnapshot(snap1);
|
|
176
|
+
controller.handleSnapshot(snap2);
|
|
177
|
+
controller.handleSnapshot(snap3);
|
|
178
|
+
|
|
179
|
+
expect(scheduler.size).toBe(1);
|
|
180
|
+
scheduler.flush();
|
|
181
|
+
expect(sink.snapshots).toEqual([snap3]);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("schedules a new flush after the previous one fires", () => {
|
|
185
|
+
controller.handleSnapshot(
|
|
186
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS, 1),
|
|
187
|
+
);
|
|
188
|
+
scheduler.flush();
|
|
189
|
+
expect(scheduler.size).toBe(0);
|
|
190
|
+
|
|
191
|
+
controller.handleSnapshot(
|
|
192
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS, 2),
|
|
193
|
+
);
|
|
194
|
+
expect(scheduler.size).toBe(1);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe("handleSnapshot() — terminal", () => {
|
|
199
|
+
beforeEach(() => {
|
|
200
|
+
controller.start("exec-1");
|
|
201
|
+
sink.states.length = 0;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("flushes immediately without waiting for scheduler", () => {
|
|
205
|
+
const snap = makeSnapshot(ExecutionPhase.EXECUTION_COMPLETED);
|
|
206
|
+
controller.handleSnapshot(snap);
|
|
207
|
+
expect(sink.snapshots).toEqual([snap]);
|
|
208
|
+
expect(scheduler.size).toBe(0);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("transitions to complete", () => {
|
|
212
|
+
controller.handleSnapshot(
|
|
213
|
+
makeSnapshot(ExecutionPhase.EXECUTION_COMPLETED),
|
|
214
|
+
);
|
|
215
|
+
expect(controller.state).toEqual({
|
|
216
|
+
stage: "complete",
|
|
217
|
+
executionId: "exec-1",
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("cancels any pending non-terminal flush", () => {
|
|
222
|
+
controller.handleSnapshot(
|
|
223
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS, 1),
|
|
224
|
+
);
|
|
225
|
+
expect(scheduler.size).toBe(1);
|
|
226
|
+
|
|
227
|
+
controller.handleSnapshot(
|
|
228
|
+
makeSnapshot(ExecutionPhase.EXECUTION_COMPLETED),
|
|
229
|
+
);
|
|
230
|
+
expect(scheduler.size).toBe(0);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("handles terminal as first snapshot (connecting -> complete)", () => {
|
|
234
|
+
controller.handleSnapshot(
|
|
235
|
+
makeSnapshot(ExecutionPhase.EXECUTION_COMPLETED),
|
|
236
|
+
);
|
|
237
|
+
expect(controller.state).toEqual({
|
|
238
|
+
stage: "complete",
|
|
239
|
+
executionId: "exec-1",
|
|
240
|
+
});
|
|
241
|
+
expect(sink.states).toEqual([
|
|
242
|
+
{ stage: "complete", executionId: "exec-1" },
|
|
243
|
+
]);
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it("handles EXECUTION_FAILED as terminal", () => {
|
|
247
|
+
controller.handleSnapshot(
|
|
248
|
+
makeSnapshot(ExecutionPhase.EXECUTION_FAILED),
|
|
249
|
+
);
|
|
250
|
+
expect(controller.state.stage).toBe("complete");
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("handles EXECUTION_CANCELLED as terminal", () => {
|
|
254
|
+
controller.handleSnapshot(
|
|
255
|
+
makeSnapshot(ExecutionPhase.EXECUTION_CANCELLED),
|
|
256
|
+
);
|
|
257
|
+
expect(controller.state.stage).toBe("complete");
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("handles EXECUTION_TERMINATED as terminal", () => {
|
|
261
|
+
controller.handleSnapshot(
|
|
262
|
+
makeSnapshot(ExecutionPhase.EXECUTION_TERMINATED),
|
|
263
|
+
);
|
|
264
|
+
expect(controller.state.stage).toBe("complete");
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe("handleStreamEnd()", () => {
|
|
269
|
+
it("flushes buffered snapshot and transitions to complete", () => {
|
|
270
|
+
controller.start("exec-1");
|
|
271
|
+
const snap = makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS);
|
|
272
|
+
controller.handleSnapshot(snap);
|
|
273
|
+
controller.handleStreamEnd();
|
|
274
|
+
|
|
275
|
+
expect(sink.snapshots).toEqual([snap]);
|
|
276
|
+
expect(controller.state).toEqual({
|
|
277
|
+
stage: "complete",
|
|
278
|
+
executionId: "exec-1",
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("no-ops if already complete (terminal snapshot already handled)", () => {
|
|
283
|
+
controller.start("exec-1");
|
|
284
|
+
controller.handleSnapshot(
|
|
285
|
+
makeSnapshot(ExecutionPhase.EXECUTION_COMPLETED),
|
|
286
|
+
);
|
|
287
|
+
sink.states.length = 0;
|
|
288
|
+
|
|
289
|
+
controller.handleStreamEnd();
|
|
290
|
+
expect(sink.states).toHaveLength(0);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("no-ops if idle", () => {
|
|
294
|
+
controller.handleStreamEnd();
|
|
295
|
+
expect(sink.states).toHaveLength(0);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
describe("handleError()", () => {
|
|
300
|
+
it("transitions to error state", () => {
|
|
301
|
+
controller.start("exec-1");
|
|
302
|
+
const err = new Error("network timeout");
|
|
303
|
+
controller.handleError(err);
|
|
304
|
+
|
|
305
|
+
expect(controller.state).toEqual({
|
|
306
|
+
stage: "error",
|
|
307
|
+
executionId: "exec-1",
|
|
308
|
+
error: err,
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("flushes buffered snapshot before transitioning", () => {
|
|
313
|
+
controller.start("exec-1");
|
|
314
|
+
const snap = makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS);
|
|
315
|
+
controller.handleSnapshot(snap);
|
|
316
|
+
controller.handleError(new Error("fail"));
|
|
317
|
+
|
|
318
|
+
expect(sink.snapshots).toEqual([snap]);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("cancels pending rAF", () => {
|
|
322
|
+
controller.start("exec-1");
|
|
323
|
+
controller.handleSnapshot(
|
|
324
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS),
|
|
325
|
+
);
|
|
326
|
+
expect(scheduler.size).toBe(1);
|
|
327
|
+
|
|
328
|
+
controller.handleError(new Error("fail"));
|
|
329
|
+
expect(scheduler.size).toBe(0);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("no-ops if idle", () => {
|
|
333
|
+
controller.handleError(new Error("orphan"));
|
|
334
|
+
expect(sink.states).toHaveLength(0);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
describe("reset()", () => {
|
|
339
|
+
it("transitions to idle", () => {
|
|
340
|
+
controller.start("exec-1");
|
|
341
|
+
controller.reset();
|
|
342
|
+
expect(controller.state).toEqual({ stage: "idle" });
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("cancels pending flush", () => {
|
|
346
|
+
controller.start("exec-1");
|
|
347
|
+
controller.handleSnapshot(
|
|
348
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS),
|
|
349
|
+
);
|
|
350
|
+
controller.reset();
|
|
351
|
+
expect(scheduler.size).toBe(0);
|
|
352
|
+
expect(controller.hasPendingFlush).toBe(false);
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("clears buffered snapshot", () => {
|
|
356
|
+
controller.start("exec-1");
|
|
357
|
+
controller.handleSnapshot(
|
|
358
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS),
|
|
359
|
+
);
|
|
360
|
+
controller.reset();
|
|
361
|
+
scheduler.flush();
|
|
362
|
+
expect(sink.snapshots).toHaveLength(0);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it("no-ops if already idle", () => {
|
|
366
|
+
controller.reset();
|
|
367
|
+
expect(sink.states).toHaveLength(0);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("notifies sink of idle transition", () => {
|
|
371
|
+
controller.start("exec-1");
|
|
372
|
+
sink.states.length = 0;
|
|
373
|
+
controller.reset();
|
|
374
|
+
expect(sink.states).toEqual([{ stage: "idle" }]);
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
describe("stale event guard", () => {
|
|
379
|
+
it("ignores snapshots after reset", () => {
|
|
380
|
+
controller.start("exec-1");
|
|
381
|
+
controller.reset();
|
|
382
|
+
controller.handleSnapshot(
|
|
383
|
+
makeSnapshot(ExecutionPhase.EXECUTION_IN_PROGRESS),
|
|
384
|
+
);
|
|
385
|
+
expect(sink.snapshots).toHaveLength(0);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it("ignores errors after reset", () => {
|
|
389
|
+
controller.start("exec-1");
|
|
390
|
+
controller.reset();
|
|
391
|
+
controller.handleError(new Error("stale"));
|
|
392
|
+
expect(controller.state).toEqual({ stage: "idle" });
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
});
|