@assistant-ui/core 0.3.13 → 0.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/speech.d.ts.map +1 -1
- package/dist/adapters/speech.js +9 -15
- package/dist/adapters/speech.js.map +1 -1
- package/dist/adapters/thread-history.d.ts +2 -0
- package/dist/adapters/thread-history.d.ts.map +1 -1
- package/dist/adapters/voice.d.ts.map +1 -1
- package/dist/adapters/voice.js +27 -15
- package/dist/adapters/voice.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +6 -6
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +2 -1
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/registry.d.ts.map +1 -1
- package/dist/model-context/registry.js +16 -4
- package/dist/model-context/registry.js.map +1 -1
- package/dist/react/RuntimeAdapter.d.ts +8 -1
- package/dist/react/RuntimeAdapter.d.ts.map +1 -1
- package/dist/react/RuntimeAdapter.js +23 -18
- package/dist/react/RuntimeAdapter.js.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +28 -12
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/AdaptedRemoteThread.d.ts +11 -0
- package/dist/react/client/AdaptedRemoteThread.d.ts.map +1 -0
- package/dist/react/client/AdaptedRemoteThread.js +27 -0
- package/dist/react/client/AdaptedRemoteThread.js.map +1 -0
- package/dist/react/client/InMemoryThreadList.d.ts +19 -0
- package/dist/react/client/InMemoryThreadList.d.ts.map +1 -0
- package/dist/react/client/InMemoryThreadList.js +418 -0
- package/dist/react/client/InMemoryThreadList.js.map +1 -0
- package/dist/react/client/Interactables.d.ts.map +1 -1
- package/dist/react/client/Interactables.js +159 -102
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/RemoteThreadList.d.ts +34 -0
- package/dist/react/client/RemoteThreadList.d.ts.map +1 -0
- package/dist/react/client/RemoteThreadList.js +826 -0
- package/dist/react/client/RemoteThreadList.js.map +1 -0
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +38 -27
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +7 -2
- package/dist/react/index.js +5 -2
- package/dist/react/interactables-legacy/Interactables.d.ts.map +1 -1
- package/dist/react/interactables-legacy/Interactables.js +145 -110
- package/dist/react/interactables-legacy/Interactables.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js +13 -18
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +2 -4
- package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.js +2 -4
- package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js +2 -6
- package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +2 -6
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.js +2 -4
- package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.js +2 -4
- package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +6 -2
- package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.d.ts +13 -0
- package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.d.ts.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +22 -10
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +109 -71
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +8 -2
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +40 -13
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.d.ts +30 -0
- package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -0
- package/dist/react/runtimes/RemoteThreadResource.js +134 -0
- package/dist/react/runtimes/RemoteThreadResource.js.map +1 -0
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts +3 -10
- package/dist/react/runtimes/RuntimeAdapterProvider.d.ts.map +1 -1
- package/dist/react/runtimes/RuntimeAdapterProvider.js +3 -6
- package/dist/react/runtimes/RuntimeAdapterProvider.js.map +1 -1
- package/dist/react/runtimes/assistant-transport/commandQueue.d.ts +17 -0
- package/dist/react/runtimes/assistant-transport/commandQueue.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/commandQueue.js +55 -0
- package/dist/react/runtimes/assistant-transport/commandQueue.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/replayBoundaryStream.d.ts +11 -0
- package/dist/react/runtimes/assistant-transport/replayBoundaryStream.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/replayBoundaryStream.js +165 -0
- package/dist/react/runtimes/assistant-transport/replayBoundaryStream.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/runManager.d.ts +15 -0
- package/dist/react/runtimes/assistant-transport/runManager.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/runManager.js +86 -0
- package/dist/react/runtimes/assistant-transport/runManager.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/types.d.ts +130 -0
- package/dist/react/runtimes/assistant-transport/types.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/types.js +0 -0
- package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.d.ts +14 -0
- package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.js +296 -0
- package/dist/react/runtimes/assistant-transport/useAssistantTransportRuntime.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/useConvertedState.d.ts +7 -0
- package/dist/react/runtimes/assistant-transport/useConvertedState.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/useConvertedState.js +25 -0
- package/dist/react/runtimes/assistant-transport/useConvertedState.js.map +1 -0
- package/dist/react/runtimes/assistant-transport/useLatestRef.d.ts +7 -0
- package/dist/react/runtimes/assistant-transport/useLatestRef.d.ts.map +1 -0
- package/dist/react/runtimes/assistant-transport/useLatestRef.js +27 -0
- package/dist/react/runtimes/assistant-transport/useLatestRef.js.map +1 -0
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +39 -13
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +2 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +3 -3
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +4 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +7 -0
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +22 -12
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.d.ts +16 -0
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js +36 -0
- package/dist/react/runtimes/cloud/useCloudThreadListRuntime.js.map +1 -0
- package/dist/react/runtimes/external-message-converter.js +14 -14
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.js +44 -28
- package/dist/react/runtimes/useExternalStoreRuntime.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.js +1 -1
- package/dist/react/runtimes/useRuntimeAdapters.d.ts +9 -0
- package/dist/react/runtimes/useRuntimeAdapters.d.ts.map +1 -0
- package/dist/react/runtimes/useRuntimeAdapters.js +20 -0
- package/dist/react/runtimes/useRuntimeAdapters.js.map +1 -0
- package/dist/runtime/api/composer-runtime.d.ts +5 -0
- package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/message-runtime.js +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +1 -0
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +4 -2
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +12 -2
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js +8 -2
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +8 -7
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -0
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +3 -3
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +0 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +10 -4
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +6 -0
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/internal.js +5 -5
- package/dist/runtime/queue/message-queue.d.ts.map +1 -1
- package/dist/runtime/queue/message-queue.js +2 -1
- package/dist/runtime/queue/message-queue.js.map +1 -1
- package/dist/runtime/utils/thread-runtime-lifecycle.d.ts +8 -0
- package/dist/runtime/utils/thread-runtime-lifecycle.d.ts.map +1 -0
- package/dist/runtime/utils/thread-runtime-lifecycle.js +11 -0
- package/dist/runtime/utils/thread-runtime-lifecycle.js.map +1 -0
- package/dist/runtimes/external-store/external-store-shared-options.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +4 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +8 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +35 -13
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/internal.d.ts +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +3 -0
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +53 -13
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +1 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +3 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js +3 -0
- package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +29 -1
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +1 -12
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +67 -38
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/suggestions.js +2 -2
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-selection-events.d.ts +10 -0
- package/dist/store/clients/thread-selection-events.d.ts.map +1 -0
- package/dist/store/clients/thread-selection-events.js +40 -0
- package/dist/store/clients/thread-selection-events.js.map +1 -0
- package/dist/store/env.d.ts +5 -0
- package/dist/store/env.d.ts.map +1 -0
- package/dist/store/env.js +12 -0
- package/dist/store/env.js.map +1 -0
- package/dist/store/index.d.ts +5 -3
- package/dist/store/index.js +4 -2
- package/dist/store/internal.d.ts +4 -1
- package/dist/store/internal.js +4 -1
- package/dist/store/primitive-predicates.d.ts +19 -0
- package/dist/store/primitive-predicates.d.ts.map +1 -0
- package/dist/store/primitive-predicates.js +19 -0
- package/dist/store/primitive-predicates.js.map +1 -0
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.js +18 -11
- package/dist/store/runtime-clients/attachment-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/handle-runtime-action.d.ts +5 -0
- package/dist/store/runtime-clients/handle-runtime-action.d.ts.map +1 -0
- package/dist/store/runtime-clients/handle-runtime-action.js +12 -0
- package/dist/store/runtime-clients/handle-runtime-action.js.map +1 -0
- package/dist/store/runtime-clients/handle-thread-list-action.d.ts +5 -0
- package/dist/store/runtime-clients/handle-thread-list-action.d.ts.map +1 -0
- package/dist/store/runtime-clients/handle-thread-list-action.js +7 -0
- package/dist/store/runtime-clients/handle-thread-list-action.js.map +1 -0
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +62 -29
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +5 -6
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/scopes/composer.d.ts +9 -4
- package/dist/store/scopes/composer.d.ts.map +1 -1
- package/dist/store/scopes/thread-list-item.d.ts +7 -6
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/dist/store/scopes/thread.d.ts +8 -7
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/store/scopes/threads.d.ts +17 -1
- package/dist/store/scopes/threads.d.ts.map +1 -1
- package/dist/subscribable/subscribable.d.ts +2 -1
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +23 -18
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/utils/composite-context-provider.d.ts +1 -0
- package/dist/utils/composite-context-provider.d.ts.map +1 -1
- package/dist/utils/composite-context-provider.js +25 -9
- package/dist/utils/composite-context-provider.js.map +1 -1
- package/dist/utils/notify-event-listeners.d.ts +2 -2
- package/dist/utils/notify-event-listeners.d.ts.map +1 -1
- package/dist/utils/notify-event-listeners.js +2 -2
- package/dist/utils/notify-event-listeners.js.map +1 -1
- package/package.json +7 -7
- package/src/adapters/speech.test.ts +118 -1
- package/src/adapters/speech.ts +21 -22
- package/src/adapters/thread-history.ts +2 -0
- package/src/adapters/voice.test.ts +69 -0
- package/src/adapters/voice.ts +27 -27
- package/src/index.ts +1 -0
- package/src/model-context/frame/host.test.ts +23 -0
- package/src/model-context/frame/host.ts +2 -1
- package/src/model-context/registry.test.ts +131 -0
- package/src/model-context/registry.ts +16 -6
- package/src/react/RuntimeAdapter.test.ts +2 -0
- package/src/react/RuntimeAdapter.ts +20 -8
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +34 -17
- package/src/react/client/AdaptedRemoteThread.ts +41 -0
- package/src/react/client/InMemoryThreadList.test.tsx +148 -0
- package/src/react/client/InMemoryThreadList.ts +290 -0
- package/src/react/client/Interactables.test.ts +326 -2
- package/src/react/client/Interactables.ts +227 -110
- package/src/react/client/RemoteThreadList.test.ts +1026 -0
- package/src/react/client/RemoteThreadList.ts +1067 -0
- package/src/react/client/Tools.ts +36 -29
- package/src/react/index.ts +13 -0
- package/src/react/interactables-legacy/Interactables.test.ts +317 -0
- package/src/react/interactables-legacy/Interactables.ts +204 -128
- package/src/react/primitive-hooks/useActionBarCopy.ts +2 -7
- package/src/react/primitive-hooks/useActionBarEdit.ts +2 -1
- package/src/react/primitive-hooks/useActionBarReload.ts +2 -6
- package/src/react/primitive-hooks/useBranchPickerNext.ts +2 -7
- package/src/react/primitive-hooks/useBranchPickerPrevious.ts +2 -7
- package/src/react/primitive-hooks/useComposerCancel.ts +2 -1
- package/src/react/primitive-hooks/useComposerSend.ts +2 -5
- package/src/react/primitive-hooks/useSuggestionTrigger.test.ts +11 -0
- package/src/react/primitive-hooks/useSuggestionTrigger.ts +4 -5
- package/src/react/primitives/message/MessageParts.tsx +0 -1
- package/src/react/primitives/thread/ThreadMessages.tsx +2 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.retry.test.tsx +116 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +1 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +57 -6
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.title.test.tsx +272 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +159 -124
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +59 -20
- package/src/react/runtimes/RemoteThreadResource.test.ts +141 -0
- package/src/react/runtimes/RemoteThreadResource.ts +231 -0
- package/src/react/runtimes/RuntimeAdapterProvider.tsx +8 -20
- package/src/react/runtimes/assistant-transport/commandQueue.ts +68 -0
- package/src/react/runtimes/assistant-transport/replayBoundaryStream.test.ts +455 -0
- package/src/react/runtimes/assistant-transport/replayBoundaryStream.ts +172 -0
- package/src/react/runtimes/assistant-transport/runManager.ts +124 -0
- package/src/react/runtimes/assistant-transport/transport-delivery.test.tsx +79 -0
- package/src/react/runtimes/assistant-transport/transport-parentid.test.tsx +97 -0
- package/src/react/runtimes/assistant-transport/transport-scheduling.test.ts +414 -0
- package/src/react/runtimes/assistant-transport/types.ts +170 -0
- package/src/react/runtimes/assistant-transport/useAssistantTransport.spec.md +141 -0
- package/src/react/runtimes/assistant-transport/useAssistantTransportRuntime.test.tsx +625 -0
- package/src/react/runtimes/assistant-transport/useAssistantTransportRuntime.ts +481 -0
- package/src/react/runtimes/assistant-transport/useConvertedState.ts +20 -0
- package/src/react/runtimes/assistant-transport/useLatestRef.ts +9 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +131 -6
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +61 -15
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +6 -4
- package/src/react/runtimes/cloud/auiV0.ts +17 -1
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +36 -21
- package/src/react/runtimes/cloud/useCloudThreadListRuntime.test.tsx +56 -0
- package/src/react/runtimes/cloud/useCloudThreadListRuntime.ts +31 -0
- package/src/react/runtimes/external-message-converter.test.ts +143 -0
- package/src/react/runtimes/external-message-converter.ts +41 -41
- package/src/react/runtimes/remote-thread-hook-on-tap.test.ts +58 -0
- package/src/react/runtimes/useExternalStoreRuntime.lifecycle.test.tsx +83 -0
- package/src/react/runtimes/useExternalStoreRuntime.suggestions.test.tsx +13 -3
- package/src/react/runtimes/useExternalStoreRuntime.ts +7 -0
- package/src/react/runtimes/useExternalStoreSharedOptions.ts +3 -1
- package/src/react/runtimes/useLocalRuntime.test.tsx +130 -4
- package/src/react/runtimes/useRuntimeAdapters.test.tsx +62 -0
- package/src/react/runtimes/useRuntimeAdapters.ts +28 -0
- package/src/runtime/api/composer-runtime.ts +5 -0
- package/src/runtime/api/thread-list-runtime.ts +3 -1
- package/src/runtime/api/thread-runtime.ts +20 -2
- package/src/runtime/base/base-composer-runtime-core.ts +6 -5
- package/src/runtime/base/base-thread-runtime-core.test.ts +191 -0
- package/src/runtime/base/base-thread-runtime-core.ts +11 -2
- package/src/runtime/base/default-thread-composer-runtime-core.ts +12 -4
- package/src/runtime/interfaces/thread-runtime-core.ts +6 -0
- package/src/runtime/queue/message-queue.ts +2 -1
- package/src/runtime/utils/thread-runtime-lifecycle.ts +18 -0
- package/src/runtimes/external-store/external-store-shared-options.ts +3 -1
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +4 -1
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +99 -34
- package/src/runtimes/local/local-thread-runtime-core.test.ts +373 -4
- package/src/runtimes/local/local-thread-runtime-core.ts +79 -14
- package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +4 -0
- package/src/runtimes/remote-thread-list/empty-thread-core.ts +4 -0
- package/src/runtimes/remote-thread-list/types.ts +30 -0
- package/src/runtimes/tool-invocations/EDGE_CASES.md +17 -6
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +243 -0
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +127 -61
- package/src/store/clients/model-context-client.test.ts +16 -8
- package/src/store/clients/suggestions.ts +2 -2
- package/src/store/clients/thread-selection-events.ts +21 -0
- package/src/store/env.ts +11 -0
- package/src/store/index.ts +14 -1
- package/src/store/internal.ts +13 -0
- package/src/store/primitive-predicates.test.ts +184 -0
- package/src/store/primitive-predicates.ts +43 -0
- package/src/store/runtime-clients/attachment-runtime-client.test.ts +41 -0
- package/src/store/runtime-clients/attachment-runtime-client.ts +2 -1
- package/src/store/runtime-clients/handle-runtime-action.ts +11 -0
- package/src/store/runtime-clients/handle-thread-list-action.test.ts +69 -0
- package/src/store/runtime-clients/handle-thread-list-action.ts +6 -0
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +15 -7
- package/src/store/runtime-clients/thread-list-runtime-client.ts +9 -6
- package/src/store/scopes/composer.ts +9 -4
- package/src/store/scopes/thread-list-item.ts +7 -6
- package/src/store/scopes/thread.ts +8 -7
- package/src/store/scopes/threads.ts +14 -0
- package/src/subscribable/subscribable.test.ts +77 -1
- package/src/subscribable/subscribable.ts +38 -23
- package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-unarchive.test.ts +25 -0
- package/src/tests/auiV0Encode.test.ts +66 -0
- package/src/tests/base-composer-runtime-core-send.test.ts +30 -0
- package/src/tests/base-composer-runtime-core.test.ts +28 -0
- package/src/tests/composer-can-cancel.test.ts +101 -0
- package/src/tests/external-store-thread-list-runtime-core.test.ts +101 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +191 -1
- package/src/tests/external-store-thread-runtime-core.test.ts +124 -0
- package/src/tests/interactables-toolui-migration.test.tsx +66 -0
- package/src/tests/message-queue.test.ts +28 -0
- package/src/tests/session-reset-notification.test.ts +145 -0
- package/src/tests/thread-switch-events.test.tsx +99 -1
- package/src/tests/tools-scope-migration.test.tsx +58 -0
- package/src/utils/composite-context-provider.test.ts +139 -0
- package/src/utils/composite-context-provider.ts +26 -8
- package/src/utils/notify-event-listeners.ts +10 -5
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
|
|
3
|
-
import { act, render } from "@testing-library/react";
|
|
3
|
+
import { act, render, waitFor } from "@testing-library/react";
|
|
4
4
|
import { describe, expect, it, vi } from "vitest";
|
|
5
5
|
import { AuiProvider, useAui, useAuiEvent } from "@assistant-ui/store";
|
|
6
|
+
import { AssistantRuntimeProvider } from "../react/AssistantRuntimeProvider";
|
|
7
|
+
import { useExternalStoreRuntime } from "../react/runtimes/useExternalStoreRuntime";
|
|
8
|
+
import { useRemoteThreadListRuntime } from "../react/runtimes/useRemoteThreadListRuntime";
|
|
9
|
+
import { makeAdapter } from "./remote-thread-list-test-helpers";
|
|
6
10
|
import { RuntimeAdapter } from "../react/RuntimeAdapter";
|
|
7
11
|
import { AssistantRuntimeImpl } from "../runtime/api/assistant-runtime";
|
|
8
12
|
import { ExternalStoreRuntimeCore } from "../runtimes/external-store/external-store-runtime-core";
|
|
@@ -10,6 +14,15 @@ import type { ExternalStoreAdapter } from "../runtimes/external-store/external-s
|
|
|
10
14
|
|
|
11
15
|
type DemoMessage = { id: string; role: "user" | "assistant"; text: string };
|
|
12
16
|
|
|
17
|
+
const EMPTY_MESSAGES: readonly never[] = [];
|
|
18
|
+
|
|
19
|
+
const useTestThreadRuntime = () =>
|
|
20
|
+
useExternalStoreRuntime({
|
|
21
|
+
messages: EMPTY_MESSAGES,
|
|
22
|
+
isRunning: false,
|
|
23
|
+
onNew: async () => {},
|
|
24
|
+
});
|
|
25
|
+
|
|
13
26
|
const createRuntime = () => {
|
|
14
27
|
const threads = [
|
|
15
28
|
{
|
|
@@ -110,6 +123,57 @@ describe("thread switch events", () => {
|
|
|
110
123
|
expect(switchedAwayStar).toHaveBeenLastCalledWith({ threadId: "t2" });
|
|
111
124
|
});
|
|
112
125
|
|
|
126
|
+
it("delivers threads.selectionChanged with the new and previous thread ids", async () => {
|
|
127
|
+
const runtime = createRuntime();
|
|
128
|
+
const selectionChanged = vi.fn();
|
|
129
|
+
const auiOn = vi.fn();
|
|
130
|
+
let aui!: ReturnType<typeof useAui>;
|
|
131
|
+
const Consumer = () => {
|
|
132
|
+
useAuiEvent(
|
|
133
|
+
"threads.selectionChanged" as never,
|
|
134
|
+
selectionChanged as never,
|
|
135
|
+
);
|
|
136
|
+
return null;
|
|
137
|
+
};
|
|
138
|
+
const Harness = () => {
|
|
139
|
+
aui = useAui({ threads: RuntimeAdapter(runtime) } as never);
|
|
140
|
+
return (
|
|
141
|
+
<AuiProvider value={aui}>
|
|
142
|
+
<Consumer />
|
|
143
|
+
</AuiProvider>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
render(<Harness />);
|
|
147
|
+
await act(async () => {});
|
|
148
|
+
|
|
149
|
+
aui.on("threads.selectionChanged" as never, auiOn as never);
|
|
150
|
+
|
|
151
|
+
await act(async () => {
|
|
152
|
+
aui.threads.item({ index: 1 }).switchTo();
|
|
153
|
+
});
|
|
154
|
+
await act(async () => {});
|
|
155
|
+
|
|
156
|
+
expect(selectionChanged).toHaveBeenCalledExactlyOnceWith({
|
|
157
|
+
threadId: "t2",
|
|
158
|
+
previousThreadId: "t1",
|
|
159
|
+
});
|
|
160
|
+
expect(auiOn).toHaveBeenCalledExactlyOnceWith({
|
|
161
|
+
threadId: "t2",
|
|
162
|
+
previousThreadId: "t1",
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
await act(async () => {
|
|
166
|
+
aui.threads.item({ index: 0 }).switchTo();
|
|
167
|
+
});
|
|
168
|
+
await act(async () => {});
|
|
169
|
+
|
|
170
|
+
expect(selectionChanged).toHaveBeenCalledTimes(2);
|
|
171
|
+
expect(selectionChanged).toHaveBeenLastCalledWith({
|
|
172
|
+
threadId: "t1",
|
|
173
|
+
previousThreadId: "t2",
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
113
177
|
it("does not emit for the initially selected thread on mount", async () => {
|
|
114
178
|
const runtime = createRuntime();
|
|
115
179
|
const anySwitch = vi.fn();
|
|
@@ -118,6 +182,10 @@ describe("thread switch events", () => {
|
|
|
118
182
|
{ scope: "*", event: "threadListItem.switchedTo" } as never,
|
|
119
183
|
anySwitch as never,
|
|
120
184
|
);
|
|
185
|
+
useAuiEvent(
|
|
186
|
+
{ scope: "*", event: "threads.selectionChanged" } as never,
|
|
187
|
+
anySwitch as never,
|
|
188
|
+
);
|
|
121
189
|
return null;
|
|
122
190
|
};
|
|
123
191
|
const Harness = () => {
|
|
@@ -133,4 +201,34 @@ describe("thread switch events", () => {
|
|
|
133
201
|
|
|
134
202
|
expect(anySwitch).not.toHaveBeenCalled();
|
|
135
203
|
});
|
|
204
|
+
|
|
205
|
+
it("emits when a deep-linked initial thread resolves after mount", async () => {
|
|
206
|
+
const adapter = makeAdapter();
|
|
207
|
+
const selectionChanged = vi.fn();
|
|
208
|
+
const Listener = () => {
|
|
209
|
+
useAuiEvent("threads.selectionChanged", selectionChanged);
|
|
210
|
+
return null;
|
|
211
|
+
};
|
|
212
|
+
const Harness = () => {
|
|
213
|
+
const runtime = useRemoteThreadListRuntime({
|
|
214
|
+
adapter,
|
|
215
|
+
initialThreadId: "thread-a",
|
|
216
|
+
runtimeHook: useTestThreadRuntime,
|
|
217
|
+
});
|
|
218
|
+
return (
|
|
219
|
+
<AssistantRuntimeProvider runtime={runtime}>
|
|
220
|
+
<Listener />
|
|
221
|
+
</AssistantRuntimeProvider>
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
render(<Harness />);
|
|
225
|
+
|
|
226
|
+
await waitFor(() => expect(selectionChanged).toHaveBeenCalledTimes(1));
|
|
227
|
+
const payload = selectionChanged.mock.calls[0]![0] as {
|
|
228
|
+
threadId: string;
|
|
229
|
+
previousThreadId: string;
|
|
230
|
+
};
|
|
231
|
+
expect(payload.threadId).toBe("thread-a");
|
|
232
|
+
expect(payload.previousThreadId).toMatch(/^__LOCALID_/);
|
|
233
|
+
});
|
|
136
234
|
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
|
|
3
|
+
import { act, cleanup, render } from "@testing-library/react";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import { withKey } from "@assistant-ui/tap";
|
|
6
|
+
import { useAui } from "@assistant-ui/store";
|
|
7
|
+
import { Tools } from "../react/client/Tools";
|
|
8
|
+
import { ModelContext } from "../store/clients/model-context-client";
|
|
9
|
+
import type { Toolkit } from "../react/model-context/toolbox";
|
|
10
|
+
|
|
11
|
+
type AnyClient = Record<string, any>;
|
|
12
|
+
|
|
13
|
+
const toolkit = {
|
|
14
|
+
lookup: {
|
|
15
|
+
description: "look something up",
|
|
16
|
+
parameters: { type: "object", properties: {} },
|
|
17
|
+
execute: async () => "ok",
|
|
18
|
+
},
|
|
19
|
+
} as unknown as Toolkit;
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
cleanup();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe("Tools model-context registration", () => {
|
|
26
|
+
it("migrates to a structurally replaced modelContext scope", async () => {
|
|
27
|
+
let aui!: AnyClient;
|
|
28
|
+
const Harness = ({ generation }: { generation: number }) => {
|
|
29
|
+
aui = useAui({
|
|
30
|
+
tools: Tools({ toolkit }),
|
|
31
|
+
modelContext: withKey(String(generation), ModelContext()),
|
|
32
|
+
} as never);
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
const view = render(<Harness generation={0} />);
|
|
36
|
+
|
|
37
|
+
expect(
|
|
38
|
+
Object.keys(aui.modelContext().getModelContext().tools ?? {}),
|
|
39
|
+
).toContain("lookup");
|
|
40
|
+
|
|
41
|
+
// A rerender inside an outer act would not land until that act exits,
|
|
42
|
+
// so the swap happens first and only the scheduler wait is wrapped
|
|
43
|
+
view.rerender(<Harness generation={1} />);
|
|
44
|
+
|
|
45
|
+
// The registration lands one scheduler macrotask after the swap: the
|
|
46
|
+
// mount-time register marks the tap scheduler dirty, which defers the
|
|
47
|
+
// structural publish to the scheduler's drain. The remounted scope
|
|
48
|
+
// starts from fresh state, so the tools reappearing proves the
|
|
49
|
+
// registration migrated to the replacement instance.
|
|
50
|
+
await act(async () => {
|
|
51
|
+
await vi.waitFor(() =>
|
|
52
|
+
expect(
|
|
53
|
+
Object.keys(aui.modelContext().getModelContext().tools ?? {}),
|
|
54
|
+
).toContain("lookup"),
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { CompositeContextProvider } from "./composite-context-provider";
|
|
3
|
+
|
|
4
|
+
describe("CompositeContextProvider", () => {
|
|
5
|
+
it("notifies every subscriber and rethrows when a registration subscriber throws", () => {
|
|
6
|
+
const composite = new CompositeContextProvider();
|
|
7
|
+
const error = new Error("subscriber failed");
|
|
8
|
+
const laterSubscriber = vi.fn();
|
|
9
|
+
|
|
10
|
+
composite.subscribe(() => {
|
|
11
|
+
throw error;
|
|
12
|
+
});
|
|
13
|
+
composite.subscribe(laterSubscriber);
|
|
14
|
+
|
|
15
|
+
expect(() =>
|
|
16
|
+
composite.registerModelContextProvider({
|
|
17
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
18
|
+
}),
|
|
19
|
+
).toThrow(error);
|
|
20
|
+
|
|
21
|
+
expect(composite.getModelContext().system).toBe("provider instructions");
|
|
22
|
+
expect(laterSubscriber).toHaveBeenCalledTimes(1);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("rolls back providers that fail to subscribe", () => {
|
|
26
|
+
const composite = new CompositeContextProvider();
|
|
27
|
+
const error = new Error("subscription failed");
|
|
28
|
+
const observedSystems: Array<string | undefined> = [];
|
|
29
|
+
|
|
30
|
+
composite.subscribe(() => {
|
|
31
|
+
observedSystems.push(composite.getModelContext().system);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
expect(() =>
|
|
35
|
+
composite.registerModelContextProvider({
|
|
36
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
37
|
+
subscribe: (callback) => {
|
|
38
|
+
callback();
|
|
39
|
+
throw error;
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
).toThrow(error);
|
|
43
|
+
|
|
44
|
+
expect(composite.getModelContext().system).toBeUndefined();
|
|
45
|
+
expect(observedSystems).toEqual(["provider instructions", undefined]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("rethrows the provider subscription failure when a rollback subscriber throws", () => {
|
|
49
|
+
const composite = new CompositeContextProvider();
|
|
50
|
+
const subscriptionError = new Error("subscription failed");
|
|
51
|
+
const subscriberError = new Error("subscriber failed");
|
|
52
|
+
const consoleError = vi
|
|
53
|
+
.spyOn(console, "error")
|
|
54
|
+
.mockImplementation(() => {});
|
|
55
|
+
|
|
56
|
+
composite.subscribe(() => {
|
|
57
|
+
throw subscriberError;
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
expect(() =>
|
|
62
|
+
composite.registerModelContextProvider({
|
|
63
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
64
|
+
subscribe: () => {
|
|
65
|
+
throw subscriptionError;
|
|
66
|
+
},
|
|
67
|
+
}),
|
|
68
|
+
).toThrow(subscriptionError);
|
|
69
|
+
|
|
70
|
+
expect(composite.getModelContext().system).toBeUndefined();
|
|
71
|
+
expect(consoleError).toHaveBeenCalledWith(subscriberError);
|
|
72
|
+
} finally {
|
|
73
|
+
consoleError.mockRestore();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("preserves an earlier registration when a duplicate fails to subscribe", () => {
|
|
78
|
+
const composite = new CompositeContextProvider();
|
|
79
|
+
const error = new Error("subscription failed");
|
|
80
|
+
let subscriptionCount = 0;
|
|
81
|
+
const provider = {
|
|
82
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
83
|
+
subscribe: () => {
|
|
84
|
+
subscriptionCount++;
|
|
85
|
+
if (subscriptionCount === 2) throw error;
|
|
86
|
+
return () => {};
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const unregister = composite.registerModelContextProvider(provider);
|
|
91
|
+
|
|
92
|
+
expect(() => composite.registerModelContextProvider(provider)).toThrow(
|
|
93
|
+
error,
|
|
94
|
+
);
|
|
95
|
+
expect(composite.getModelContext().system).toBe("provider instructions");
|
|
96
|
+
|
|
97
|
+
unregister();
|
|
98
|
+
expect(composite.getModelContext().system).toBeUndefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("keeps duplicate registrations independent", () => {
|
|
102
|
+
const composite = new CompositeContextProvider();
|
|
103
|
+
const provider = {
|
|
104
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const unregisterFirst = composite.registerModelContextProvider(provider);
|
|
108
|
+
const unregisterSecond = composite.registerModelContextProvider(provider);
|
|
109
|
+
|
|
110
|
+
unregisterFirst();
|
|
111
|
+
expect(composite.getModelContext().system).toBe("provider instructions");
|
|
112
|
+
|
|
113
|
+
unregisterSecond();
|
|
114
|
+
expect(composite.getModelContext().system).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("notifies every subscriber and rethrows on provider updates", () => {
|
|
118
|
+
const composite = new CompositeContextProvider();
|
|
119
|
+
const error = new Error("subscriber failed");
|
|
120
|
+
const laterSubscriber = vi.fn();
|
|
121
|
+
let publishUpdate = () => {};
|
|
122
|
+
|
|
123
|
+
composite.registerModelContextProvider({
|
|
124
|
+
getModelContext: () => ({ system: "provider instructions" }),
|
|
125
|
+
subscribe: (callback) => {
|
|
126
|
+
publishUpdate = callback;
|
|
127
|
+
return () => {};
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
composite.subscribe(() => {
|
|
132
|
+
throw error;
|
|
133
|
+
});
|
|
134
|
+
composite.subscribe(laterSubscriber);
|
|
135
|
+
|
|
136
|
+
expect(() => publishUpdate()).toThrow(error);
|
|
137
|
+
expect(laterSubscriber).toHaveBeenCalledTimes(1);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -2,23 +2,41 @@ import {
|
|
|
2
2
|
type ModelContextProvider,
|
|
3
3
|
mergeModelContexts,
|
|
4
4
|
} from "../model-context/types";
|
|
5
|
+
import { notifySubscribers as notifyStateSubscribers } from "../subscribable/subscribable";
|
|
6
|
+
import type { Unsubscribe } from "../types/unsubscribe";
|
|
5
7
|
|
|
6
8
|
export class CompositeContextProvider implements ModelContextProvider {
|
|
7
|
-
private _providers = new
|
|
9
|
+
private _providers = new Map<symbol, ModelContextProvider>();
|
|
10
|
+
private _providerUnsubscribes = new Map<symbol, Unsubscribe | undefined>();
|
|
8
11
|
|
|
9
12
|
getModelContext() {
|
|
10
|
-
return mergeModelContexts(this._providers);
|
|
13
|
+
return mergeModelContexts(new Set(this._providers.values()));
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
registerModelContextProvider(provider: ModelContextProvider) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const id = Symbol();
|
|
18
|
+
this._providers.set(id, provider);
|
|
19
|
+
let unsubscribe: Unsubscribe | undefined;
|
|
20
|
+
try {
|
|
21
|
+
unsubscribe = provider.subscribe?.(() => {
|
|
22
|
+
this.notifySubscribers();
|
|
23
|
+
});
|
|
24
|
+
} catch (error) {
|
|
25
|
+
this._providers.delete(id);
|
|
26
|
+
try {
|
|
27
|
+
this.notifySubscribers();
|
|
28
|
+
} catch (notifyError) {
|
|
29
|
+
console.error(notifyError);
|
|
30
|
+
}
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
this._providerUnsubscribes.set(id, unsubscribe);
|
|
18
34
|
this.notifySubscribers();
|
|
19
35
|
return () => {
|
|
20
|
-
this._providers.delete(
|
|
36
|
+
this._providers.delete(id);
|
|
37
|
+
const unsubscribe = this._providerUnsubscribes.get(id);
|
|
21
38
|
unsubscribe?.();
|
|
39
|
+
this._providerUnsubscribes.delete(id);
|
|
22
40
|
this.notifySubscribers();
|
|
23
41
|
};
|
|
24
42
|
}
|
|
@@ -26,7 +44,7 @@ export class CompositeContextProvider implements ModelContextProvider {
|
|
|
26
44
|
private _subscribers = new Set<() => void>();
|
|
27
45
|
|
|
28
46
|
notifySubscribers() {
|
|
29
|
-
|
|
47
|
+
notifyStateSubscribers(this._subscribers);
|
|
30
48
|
}
|
|
31
49
|
|
|
32
50
|
subscribe(callback: () => void) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
type EventListener = (payload
|
|
1
|
+
type EventListener<T> = (payload: T) => unknown;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
// A function payload is indistinguishable from a factory and gets invoked; wrap a function-typed payload in a factory.
|
|
4
|
+
export const notifyEventListeners = <T>(
|
|
5
|
+
listeners: Iterable<EventListener<T>>,
|
|
6
|
+
payloadOrFactory: T | (() => T),
|
|
6
7
|
errorContext: string,
|
|
7
8
|
) => {
|
|
8
9
|
const reportError = (error: unknown) => {
|
|
@@ -14,7 +15,11 @@ export const notifyEventListeners = (
|
|
|
14
15
|
|
|
15
16
|
for (const listener of listeners) {
|
|
16
17
|
try {
|
|
17
|
-
const result = listener(
|
|
18
|
+
const result = listener(
|
|
19
|
+
typeof payloadOrFactory === "function"
|
|
20
|
+
? (payloadOrFactory as () => T)()
|
|
21
|
+
: payloadOrFactory,
|
|
22
|
+
);
|
|
18
23
|
if (
|
|
19
24
|
result !== null &&
|
|
20
25
|
(typeof result === "object" || typeof result === "function") &&
|