@assistant-ui/core 0.3.16 → 0.3.17
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/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +2 -1
- package/dist/internal.js +2 -1
- package/dist/model-context/frame/provider.d.ts +3 -0
- package/dist/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +71 -21
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/tool-call-text.d.ts +26 -0
- package/dist/model-context/tool-call-text.d.ts.map +1 -0
- package/dist/model-context/tool-call-text.js +18 -0
- package/dist/model-context/tool-call-text.js.map +1 -0
- package/dist/react/RuntimeAdapter.js +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/AdaptedRemoteThread.js +1 -1
- package/dist/react/client/InMemoryThreadList.js +1 -1
- package/dist/react/client/Interactables.js +1 -1
- package/dist/react/client/RemoteThreadList.d.ts +15 -0
- package/dist/react/client/RemoteThreadList.d.ts.map +1 -1
- package/dist/react/client/RemoteThreadList.js +240 -138
- package/dist/react/client/RemoteThreadList.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/Tools.js +6 -2
- package/dist/react/client/Tools.js.map +1 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/interactables-legacy/Interactables.js +4 -4
- package/dist/react/interactables-legacy/Interactables.js.map +1 -1
- package/dist/react/model-context/toolbox.d.ts +2 -14
- package/dist/react/model-context/toolbox.d.ts.map +1 -1
- package/dist/react/model-context/toolbox.js +1 -13
- package/dist/react/model-context/toolbox.js.map +1 -1
- package/dist/react/model-context/useAssistantContext.js +37 -7
- package/dist/react/model-context/useAssistantContext.js.map +1 -1
- package/dist/react/model-context/useAuiToolOverrides.js +31 -5
- package/dist/react/model-context/useAuiToolOverrides.js.map +1 -1
- package/dist/react/model-context/useInlineRender.d.ts.map +1 -1
- package/dist/react/model-context/useInlineRender.js +10 -36
- package/dist/react/model-context/useInlineRender.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useMessageError.js +2 -8
- package/dist/react/primitive-hooks/useMessageError.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -4
- package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerAttachments.js +4 -3
- package/dist/react/primitives/composer/ComposerAttachments.js.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.d.ts.map +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +4 -3
- package/dist/react/primitives/composer/ComposerQueue.js.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js +7 -6
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +2 -2
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +3 -3
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.d.ts.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js +5 -4
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +6 -4
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +44 -22
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +6 -5
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +79 -62
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.d.ts +1 -6
- package/dist/react/runtimes/RemoteThreadResource.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadResource.js +3 -3
- package/dist/react/runtimes/RemoteThreadResource.js.map +1 -1
- package/dist/react/runtimes/assistant-transport/useLatestRef.js +2 -2
- package/dist/react/runtimes/assistant-transport/useLatestRef.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +23 -18
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +5 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts +29 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.d.ts.map +1 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js +159 -0
- package/dist/react/runtimes/cloud/createCloudThreadListAdapter.js.map +1 -0
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts +1 -9
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +16 -153
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +1 -1
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +14 -6
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/types/MessagePartComponentTypes.d.ts +7 -3
- package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/react/types/scopes/tools.d.ts +2 -0
- package/dist/react/types/scopes/tools.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.d.ts +2 -2
- package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.js +1 -1
- package/dist/runtime/api/message-part-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +9 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +5 -0
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +2 -2
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +2 -2
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +14 -2
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +15 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.d.ts +1 -1
- package/dist/runtime/utils/auto-status.d.ts.map +1 -1
- package/dist/runtime/utils/auto-status.js +6 -2
- package/dist/runtime/utils/auto-status.js.map +1 -1
- package/dist/runtime/utils/external-message-conversion.d.ts +3 -2
- package/dist/runtime/utils/external-message-conversion.d.ts.map +1 -1
- package/dist/runtime/utils/external-message-conversion.js +4 -3
- package/dist/runtime/utils/external-message-conversion.js.map +1 -1
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts +6 -3
- package/dist/runtime/utils/resolveToolApprovalResponse.d.ts.map +1 -1
- package/dist/runtime/utils/resolveToolApprovalResponse.js +12 -3
- package/dist/runtime/utils/resolveToolApprovalResponse.js.map +1 -1
- package/dist/runtime/utils/thread-message-like.d.ts +2 -10
- package/dist/runtime/utils/thread-message-like.d.ts.map +1 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtime/utils/tool-call-tree.d.ts +39 -0
- package/dist/runtime/utils/tool-call-tree.d.ts.map +1 -0
- package/dist/runtime/utils/tool-call-tree.js +85 -0
- package/dist/runtime/utils/tool-call-tree.js.map +1 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts +29 -2
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +2 -1
- 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 +34 -28
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/inert/InertThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +3 -1
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/remote-thread-state.js +30 -13
- package/dist/runtimes/remote-thread-list/remote-thread-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/title.d.ts +9 -0
- package/dist/runtimes/remote-thread-list/title.d.ts.map +1 -0
- package/dist/runtimes/remote-thread-list/title.js +6 -0
- package/dist/runtimes/remote-thread-list/title.js.map +1 -0
- package/dist/runtimes/remote-thread-list/types.d.ts +6 -5
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +31 -8
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +97 -60
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/external-thread.d.ts +1 -1
- package/dist/store/clients/external-thread.d.ts.map +1 -1
- package/dist/store/clients/external-thread.js +11 -4
- package/dist/store/clients/external-thread.js.map +1 -1
- package/dist/store/clients/single-thread-list.js +1 -1
- package/dist/store/clients/suggestions.d.ts.map +1 -1
- package/dist/store/clients/suggestions.js +18 -6
- package/dist/store/clients/suggestions.js.map +1 -1
- package/dist/store/clients/thread-message-client.js +1 -1
- package/dist/store/clients/thread-selection-events.js +1 -1
- package/dist/store/index.d.ts +2 -1
- package/dist/store/index.js +2 -1
- package/dist/store/internal.d.ts +2 -2
- package/dist/store/internal.js +2 -2
- package/dist/store/primitive-predicates.d.ts +4 -1
- package/dist/store/primitive-predicates.d.ts.map +1 -1
- package/dist/store/primitive-predicates.js +9 -1
- package/dist/store/primitive-predicates.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +1 -1
- package/dist/store/runtime-clients/message-runtime-client.js +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +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 +124 -105
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +1 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts +3 -1
- package/dist/store/runtime-clients/useSubscribable.d.ts.map +1 -1
- package/dist/store/runtime-clients/useSubscribable.js +1 -1
- package/dist/store/runtime-clients/useSubscribable.js.map +1 -1
- package/dist/store/scopes/part.d.ts +6 -3
- package/dist/store/scopes/part.d.ts.map +1 -1
- package/dist/subscribable/subscribable.d.ts +8 -1
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +24 -16
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/types/message.d.ts +40 -1
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js +7 -1
- package/dist/types/message.js.map +1 -1
- package/package.json +12 -17
- package/src/index.ts +6 -1
- package/src/internal.ts +8 -0
- package/src/model-context/frame/provider.test.ts +217 -1
- package/src/model-context/frame/provider.ts +111 -23
- package/src/model-context/tool-call-text.test.ts +67 -0
- package/src/model-context/tool-call-text.ts +67 -0
- package/src/react/AssistantRuntimeProvider.test.tsx +66 -2
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +1 -3
- package/src/react/client/RemoteThreadList.background.test.ts +384 -0
- package/src/react/client/RemoteThreadList.concurrent.test.tsx +274 -0
- package/src/react/client/RemoteThreadList.test.ts +273 -1
- package/src/react/client/RemoteThreadList.ts +293 -83
- package/src/react/client/Tools.ts +7 -1
- package/src/react/index.ts +4 -0
- package/src/react/model-context/modelContextHooks.test.tsx +131 -0
- package/src/react/model-context/toolbox.test.ts +9 -9
- package/src/react/model-context/toolbox.ts +9 -36
- package/src/react/model-context/useAssistantContext.ts +4 -2
- package/src/react/model-context/useAuiToolOverrides.ts +4 -2
- package/src/react/model-context/useInlineRender.test.tsx +48 -0
- package/src/react/model-context/useInlineRender.ts +14 -10
- package/src/react/primitive-hooks/useMessageError.ts +2 -19
- package/src/react/primitive-hooks/useThreadListLoadMore.ts +2 -3
- package/src/react/primitives/composer/ComposerAttachments.test.tsx +76 -0
- package/src/react/primitives/composer/ComposerAttachments.tsx +9 -4
- package/src/react/primitives/composer/ComposerQueue.test.tsx +72 -0
- package/src/react/primitives/composer/ComposerQueue.tsx +7 -4
- package/src/react/primitives/message/MessageAttachments.test.tsx +107 -37
- package/src/react/primitives/message/MessageAttachments.tsx +10 -7
- package/src/react/primitives/message/MessageGroupedParts.tsx +2 -2
- package/src/react/primitives/message/MessageParts.tsx +3 -3
- package/src/react/primitives/threadList/ThreadListItems.test.tsx +99 -0
- package/src/react/primitives/threadList/ThreadListItems.tsx +8 -5
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +94 -1
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +72 -31
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.switch-delete.test.ts +169 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +114 -68
- package/src/react/runtimes/RemoteThreadResource.ts +1 -4
- package/src/react/runtimes/assistant-transport/transport-scheduling.test.ts +51 -2
- package/src/react/runtimes/assistant-transport/useLatestRef.ts +2 -2
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +45 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +65 -1
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +42 -35
- package/src/react/runtimes/cloud/auiV0.ts +5 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.test.ts +88 -0
- package/src/react/runtimes/cloud/createCloudThreadListAdapter.ts +236 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +90 -1
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +33 -238
- package/src/react/runtimes/external-message-converter.ts +1 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.concurrent.test.tsx +216 -0
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +24 -6
- package/src/react/types/MessagePartComponentTypes.ts +7 -3
- package/src/react/types/scopes/tools.ts +2 -0
- package/src/runtime/api/message-part-runtime.ts +3 -3
- package/src/runtime/api/thread-list-runtime.ts +25 -1
- package/src/runtime/base/base-thread-runtime-core.test.ts +94 -3
- package/src/runtime/base/base-thread-runtime-core.ts +10 -4
- package/src/runtime/interfaces/thread-list-runtime-core.ts +20 -1
- package/src/runtime/interfaces/thread-runtime-core.ts +17 -1
- package/src/runtime/utils/auto-status.test.ts +57 -0
- package/src/runtime/utils/auto-status.ts +13 -1
- package/src/runtime/utils/external-message-conversion.test.ts +97 -0
- package/src/runtime/utils/external-message-conversion.ts +17 -1
- package/src/runtime/utils/resolveToolApprovalResponse.test.ts +73 -0
- package/src/runtime/utils/resolveToolApprovalResponse.ts +27 -6
- package/src/runtime/utils/thread-message-like.ts +2 -10
- package/src/runtime/utils/tool-call-tree.test.ts +191 -0
- package/src/runtime/utils/tool-call-tree.ts +97 -0
- package/src/runtimes/external-store/external-store-adapter.ts +38 -2
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +56 -33
- package/src/runtimes/inert/InertThreadRuntimeCore.ts +1 -1
- package/src/runtimes/local/local-thread-runtime-core.test.ts +29 -3
- package/src/runtimes/local/local-thread-runtime-core.ts +5 -1
- package/src/runtimes/remote-thread-list/remote-thread-state.test.ts +112 -0
- package/src/runtimes/remote-thread-list/remote-thread-state.ts +55 -16
- package/src/runtimes/remote-thread-list/title.ts +3 -0
- package/src/runtimes/remote-thread-list/types.ts +6 -5
- package/src/runtimes/tool-invocations/EDGE_CASES.md +110 -5
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +750 -136
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +144 -91
- package/src/store/clients/external-thread.ts +14 -8
- package/src/store/clients/suggestions.test.ts +155 -1
- package/src/store/clients/suggestions.ts +42 -34
- package/src/store/index.ts +4 -0
- package/src/store/internal.ts +2 -0
- package/src/store/primitive-predicates.ts +35 -0
- package/src/store/runtime-clients/thread-list-runtime-client.ts +16 -2
- package/src/store/runtime-clients/useSubscribable.ts +8 -2
- package/src/store/scopes/part.ts +6 -3
- package/src/subscribable/subscribable.test.ts +50 -0
- package/src/subscribable/subscribable.ts +33 -21
- package/src/tests/RemoteThreadListThreadListRuntimeCore-load-race.test.ts +111 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-loadMore.test.ts +78 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-reload.test.ts +52 -0
- package/src/tests/external-store-optimistic-id.test.ts +79 -0
- package/src/tests/external-store-repository-instance.test.ts +166 -0
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +22 -16
- package/src/tests/external-thread-attachments.test.tsx +85 -1
- package/src/tests/remote-thread-list-adapter-switch.test.ts +66 -1
- package/src/tests/thread-switch-events.test.tsx +397 -2
- package/src/types/message.ts +50 -2
|
@@ -7,7 +7,7 @@ import { QueueItemState } from "../../runtime/queue/queue-item.js";
|
|
|
7
7
|
import { QueuePlacement } from "../../runtime/queue/external-thread-queue-adapter.js";
|
|
8
8
|
import { EditComposerRuntimeCore, ThreadComposerRuntimeCore } from "../../runtime/interfaces/composer-runtime-core.js";
|
|
9
9
|
import { AddToolResultOptions, RespondToToolApprovalOptions, ResumeRunConfig, ResumeToolCallOptions, RuntimeCapabilities, SpeechState, StartRunConfig, SubmitFeedbackOptions, ThreadRuntimeEventCallback, ThreadRuntimeEventType, ThreadSuggestion, VoiceSessionState } from "../../runtime/interfaces/thread-runtime-core.js";
|
|
10
|
-
import { ThreadListRuntimeCore } from "../../runtime/interfaces/thread-list-runtime-core.js";
|
|
10
|
+
import { ThreadListRuntimeCore, ThreadListRuntimeEvent } from "../../runtime/interfaces/thread-list-runtime-core.js";
|
|
11
11
|
import { BaseSubscribable } from "../../subscribable/subscribable.js";
|
|
12
12
|
import { RuntimeAdapters } from "../../runtimes/remote-thread-list/types.js";
|
|
13
13
|
import "../../store/index.js";
|
|
@@ -44,7 +44,7 @@ declare class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
44
44
|
unstable_notifySessionReset: () => void;
|
|
45
45
|
addToolResult: (options: AddToolResultOptions) => void;
|
|
46
46
|
resumeToolCall: (options: ResumeToolCallOptions) => void;
|
|
47
|
-
respondToToolApproval: (options: RespondToToolApprovalOptions) => void
|
|
47
|
+
respondToToolApproval: (options: RespondToToolApprovalOptions) => Promise<void>;
|
|
48
48
|
speak: (messageId: string) => void;
|
|
49
49
|
stopSpeaking: () => void;
|
|
50
50
|
connectVoice: () => void;
|
|
@@ -98,7 +98,7 @@ declare class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
98
98
|
unstable_notifySessionReset: () => void;
|
|
99
99
|
addToolResult: (options: AddToolResultOptions) => void;
|
|
100
100
|
resumeToolCall: (options: ResumeToolCallOptions) => void;
|
|
101
|
-
respondToToolApproval: (options: RespondToToolApprovalOptions) => void
|
|
101
|
+
respondToToolApproval: (options: RespondToToolApprovalOptions) => Promise<void>;
|
|
102
102
|
speak: (messageId: string) => void;
|
|
103
103
|
stopSpeaking: () => void;
|
|
104
104
|
connectVoice: () => void;
|
|
@@ -152,7 +152,7 @@ declare class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
152
152
|
unstable_notifySessionReset: () => void;
|
|
153
153
|
addToolResult: (options: AddToolResultOptions) => void;
|
|
154
154
|
resumeToolCall: (options: ResumeToolCallOptions) => void;
|
|
155
|
-
respondToToolApproval: (options: RespondToToolApprovalOptions) => void
|
|
155
|
+
respondToToolApproval: (options: RespondToToolApprovalOptions) => Promise<void>;
|
|
156
156
|
speak: (messageId: string) => void;
|
|
157
157
|
stopSpeaking: () => void;
|
|
158
158
|
connectVoice: () => void;
|
|
@@ -193,6 +193,8 @@ declare class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
|
193
193
|
__internal_isThreadRunning(threadId: string): boolean;
|
|
194
194
|
private runningSubscribers;
|
|
195
195
|
__internal_subscribeRunningChanged(callback: () => void): Unsubscribe;
|
|
196
|
+
private threadEventSubscribers;
|
|
197
|
+
__internal_subscribeThreadEvents(callback: (event: ThreadListRuntimeEvent) => void): Unsubscribe;
|
|
196
198
|
private _publish;
|
|
197
199
|
private _publishThreadRuntime;
|
|
198
200
|
private replacedSubscribers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListHookInstanceManager.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"RemoteThreadListHookInstanceManager.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;cA4Ea,4CAA4C;UAC/C;mBACS;mBAIA;mBAIA;UAIT;UACA;UACA;EAGN,YAAA,aAAa,sBACb,QAAQ;UAOF;EAsBD,mBAAmB,mBAAgB,QAAA;;;eA7BhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CH,gCAAgC,mBAAgB,QAAA;;;eAbb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBnC,qBAAqB,mBAAgB;;;eAZW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBhD,2BAA2B;UAI1B;EAED,mCAAmC,uBAAuB;UAKzD;EAID,iCACL,WAAW,OAAO,kCACjB;UAKK;UAQA;UAsBA;EAED,oCACL,uBACC;UAKK;UAiCA;EASD,kBAAkB;EAUlB,eAAe,gBAAgB;EAO/B,8BAA8B,UAAU;EAMxC,6BACL,kBACA,UAAU;EASL;UAMC;EAUD,mBAAmB,cAAc,kBAAA;EAyBjC,iCAAiC;IACtC,UAAU,cAAc;;EAenB,iBAAiB;IAAK,cAAc;;UAOnC;UAmCA"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { notifyEventListeners } from "../../utils/notify-event-listeners.js";
|
|
2
|
+
import { BaseSubscribable, WritableSubscribable } from "../../subscribable/subscribable.js";
|
|
2
3
|
import { getThreadRuntimeCoreIsRunning } from "../../runtime/api/thread-runtime.js";
|
|
3
4
|
import { ThreadListRuntimeImpl } from "../../runtime/api/thread-list-runtime.js";
|
|
4
5
|
import { invalidateThreadRuntime } from "../../runtime/utils/thread-runtime-lifecycle.js";
|
|
6
|
+
import { useSubscribable } from "../../store/runtime-clients/useSubscribable.js";
|
|
5
7
|
import { useRuntimeAdapters } from "./useRuntimeAdapters.js";
|
|
6
8
|
import { ThreadListItemRuntimeProvider } from "../providers/ThreadListItemRuntimeProvider.js";
|
|
7
9
|
import { RemoteThreadResource } from "./RemoteThreadResource.js";
|
|
@@ -9,8 +11,13 @@ import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
|
9
11
|
import { Fragment, memo, useEffect, useLayoutEffect, useMemo, useRef } from "@assistant-ui/tap/react-shim";
|
|
10
12
|
import { useResources, withKey } from "@assistant-ui/tap";
|
|
11
13
|
import { jsx } from "react/jsx-runtime";
|
|
12
|
-
import { create } from "zustand";
|
|
13
14
|
//#region src/react/runtimes/RemoteThreadListHookInstanceManager.tsx
|
|
15
|
+
const THREAD_EVENTS = [
|
|
16
|
+
"runStart",
|
|
17
|
+
"runEnd",
|
|
18
|
+
"initialize",
|
|
19
|
+
"modelContextUpdate"
|
|
20
|
+
];
|
|
14
21
|
const ProviderRenderDetector = (t0) => {
|
|
15
22
|
const $ = c(3);
|
|
16
23
|
const { detectorRef } = t0;
|
|
@@ -33,14 +40,14 @@ const ProviderRenderDetector = (t0) => {
|
|
|
33
40
|
};
|
|
34
41
|
var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
35
42
|
runtimeHook;
|
|
36
|
-
adapterStore =
|
|
43
|
+
adapterStore = new WritableSubscribable({
|
|
37
44
|
defaultAdapters: null,
|
|
38
45
|
threadAdapters: /* @__PURE__ */ new Map()
|
|
39
|
-
})
|
|
40
|
-
hostStore =
|
|
46
|
+
});
|
|
47
|
+
hostStore = new WritableSubscribable({
|
|
41
48
|
threads: [],
|
|
42
49
|
hookEpoch: 0
|
|
43
|
-
})
|
|
50
|
+
});
|
|
44
51
|
pendingThreadAdapters = /* @__PURE__ */ new Map();
|
|
45
52
|
instances = /* @__PURE__ */ new Map();
|
|
46
53
|
nextGeneration = 0;
|
|
@@ -100,6 +107,11 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
100
107
|
this.runningSubscribers.add(callback);
|
|
101
108
|
return () => this.runningSubscribers.delete(callback);
|
|
102
109
|
}
|
|
110
|
+
threadEventSubscribers = /* @__PURE__ */ new Set();
|
|
111
|
+
__internal_subscribeThreadEvents(callback) {
|
|
112
|
+
this.threadEventSubscribers.add(callback);
|
|
113
|
+
return () => this.threadEventSubscribers.delete(callback);
|
|
114
|
+
}
|
|
103
115
|
_publish = (threadId, runtime, generation) => {
|
|
104
116
|
this._publishThreadRuntime(threadId, runtime, generation);
|
|
105
117
|
};
|
|
@@ -110,7 +122,7 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
110
122
|
const previousRuntime = instance.runtime;
|
|
111
123
|
instance.runtime = runtime;
|
|
112
124
|
instance.publishedGeneration = generation;
|
|
113
|
-
if (previousRuntime !== runtime) this._trackRunning(instance);
|
|
125
|
+
if (previousRuntime !== runtime) this._trackRunning(threadId, instance);
|
|
114
126
|
this._notifySubscribers();
|
|
115
127
|
if (previousRuntime !== void 0 && previousRuntime !== runtime) for (const callback of this.replacedSubscribers) callback();
|
|
116
128
|
}
|
|
@@ -119,7 +131,7 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
119
131
|
this.replacedSubscribers.add(callback);
|
|
120
132
|
return () => this.replacedSubscribers.delete(callback);
|
|
121
133
|
}
|
|
122
|
-
_trackRunning(instance) {
|
|
134
|
+
_trackRunning(threadId, instance) {
|
|
123
135
|
instance.unsubscribeRunning?.();
|
|
124
136
|
const runtime = instance.runtime;
|
|
125
137
|
if (!runtime) {
|
|
@@ -128,9 +140,17 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
128
140
|
return;
|
|
129
141
|
}
|
|
130
142
|
this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));
|
|
131
|
-
|
|
143
|
+
const unsubscribers = [runtime.subscribe(() => {
|
|
132
144
|
this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));
|
|
133
|
-
})
|
|
145
|
+
}), ...THREAD_EVENTS.map((type) => runtime.unstable_on(type, () => {
|
|
146
|
+
notifyEventListeners(this.threadEventSubscribers, {
|
|
147
|
+
threadId,
|
|
148
|
+
type
|
|
149
|
+
}, `Thread event "${type}"`);
|
|
150
|
+
}))];
|
|
151
|
+
instance.unsubscribeRunning = () => {
|
|
152
|
+
for (const unsubscribe of unsubscribers) unsubscribe();
|
|
153
|
+
};
|
|
134
154
|
}
|
|
135
155
|
_setRunning(instance, isRunning) {
|
|
136
156
|
if (instance.isRunning === isRunning) return;
|
|
@@ -149,10 +169,11 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
149
169
|
setRuntimeHook(newRuntimeHook) {
|
|
150
170
|
if (this.runtimeHook === newRuntimeHook) return;
|
|
151
171
|
this.runtimeHook = newRuntimeHook;
|
|
152
|
-
this.hostStore.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
172
|
+
const host = this.hostStore.getState();
|
|
173
|
+
this.hostStore.setState({
|
|
174
|
+
...host,
|
|
175
|
+
hookEpoch: host.hookEpoch + 1
|
|
176
|
+
});
|
|
156
177
|
}
|
|
157
178
|
__internal_setDefaultAdapters(adapters) {
|
|
158
179
|
const current = this.adapterStore.getState();
|
|
@@ -160,7 +181,7 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
160
181
|
this.adapterStore.setState({
|
|
161
182
|
...current,
|
|
162
183
|
defaultAdapters: adapters
|
|
163
|
-
}
|
|
184
|
+
});
|
|
164
185
|
}
|
|
165
186
|
__internal_setThreadAdapters(threadId, adapters) {
|
|
166
187
|
const current = this.adapterStore.getState();
|
|
@@ -170,23 +191,24 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
170
191
|
this.adapterStore.setState({
|
|
171
192
|
...current,
|
|
172
193
|
threadAdapters: next
|
|
173
|
-
}
|
|
194
|
+
});
|
|
174
195
|
}
|
|
175
196
|
__internal_dispose() {
|
|
176
197
|
for (const threadId of [...this.instances.keys()]) this.stopThreadRuntime(threadId);
|
|
177
198
|
}
|
|
178
199
|
_syncHostThreads() {
|
|
179
|
-
this.hostStore.
|
|
180
|
-
|
|
200
|
+
const host = this.hostStore.getState();
|
|
201
|
+
this.hostStore.setState({
|
|
202
|
+
...host,
|
|
181
203
|
threads: Array.from(this.instances.entries()).map(([id, { generation }]) => ({
|
|
182
204
|
id,
|
|
183
205
|
generation
|
|
184
206
|
}))
|
|
185
|
-
})
|
|
207
|
+
});
|
|
186
208
|
}
|
|
187
209
|
__internal_useHost(parentClient) {
|
|
188
|
-
const { threads, hookEpoch } = this.hostStore
|
|
189
|
-
const adapters = this.adapterStore
|
|
210
|
+
const { threads, hookEpoch } = useSubscribable(this.hostStore);
|
|
211
|
+
const adapters = useSubscribable(this.adapterStore);
|
|
190
212
|
const runtimeHook = this.runtimeHook;
|
|
191
213
|
return useResources(threads.map(({ id, generation }) => {
|
|
192
214
|
const threadAdapters = this.pendingThreadAdapters.has(id) ? this.pendingThreadAdapters.get(id) : adapters.threadAdapters.get(id) ?? adapters.defaultAdapters;
|
|
@@ -202,7 +224,7 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
|
202
224
|
}));
|
|
203
225
|
}
|
|
204
226
|
__internal_RenderThreadRuntimes = ({ provider }) => {
|
|
205
|
-
this.hostStore
|
|
227
|
+
useSubscribable(this.hostStore);
|
|
206
228
|
return Array.from(this.instances.entries()).map(([threadId, { generation }]) => /* @__PURE__ */ jsx(this._OuterActiveThreadProvider, {
|
|
207
229
|
threadId,
|
|
208
230
|
provider
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListHookInstanceManager.js","names":["FC","RefObject","useEffect","useLayoutEffect","useMemo","useRef","memo","PropsWithChildren","ComponentType","Fragment","create","useResources","withKey","AssistantClient","ThreadListItemRuntimeProvider","ThreadRuntimeCore","ThreadListRuntimeCore","Unsubscribe","BaseSubscribable","getThreadRuntimeCoreIsRunning","ThreadListRuntimeImpl","invalidateThreadRuntime","useRuntimeAdapters","RuntimeAdapters","RemoteThreadResource","RemoteThreadListHook","RemoteThreadListHookInstance","runtime","publishedGeneration","generation","isRunning","unsubscribeRunning","AdapterSnapshot","defaultAdapters","threadAdapters","ReadonlyMap","HostSnapshot","threads","id","hookEpoch","ProviderRenderDetector","detectorRef","t0","$","_c","t1","t2","current","RemoteThreadListHookInstanceManager","runtimeHook","adapterStore","Map","hostStore","pendingThreadAdapters","instances","nextGeneration","parent","constructor","_whenRuntimeAttached","threadId","Promise","resolve","reject","callback","instance","get","dispose","Error","subscribe","startThreadRuntime","has","set","_syncHostThreads","__internal_restartThreadRuntime","_notifySubscribers","getThreadRuntimeCore","undefined","__internal_isThreadRunning","runningSubscribers","Set","__internal_subscribeRunningChanged","add","delete","_publish","_publishThreadRuntime","previousRuntime","_trackRunning","replacedSubscribers","__internal_subscribeRuntimeReplaced","_setRunning","stopThreadRuntime","setRuntimeHook","newRuntimeHook","setState","state","__internal_setDefaultAdapters","adapters","getState","__internal_setThreadAdapters","next","__internal_dispose","keys","Array","from","entries","map","__internal_useHost","parentClient","parentList","publish","__internal_RenderThreadRuntimes","provider","__internal_Host","_OuterActiveThreadProvider","Provider","getItemById","process","env","NODE_ENV","setTimeout","console","warn","clearTimeout","_AdapterSink"],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"sourcesContent":["import {\n type FC,\n type RefObject,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n memo,\n type PropsWithChildren,\n type ComponentType,\n Fragment,\n} from \"react\";\nimport { create } from \"zustand\";\nimport { useResources, withKey } from \"@assistant-ui/tap\";\nimport type { AssistantClient } from \"@assistant-ui/store\";\nimport { ThreadListItemRuntimeProvider } from \"../providers/ThreadListItemRuntimeProvider\";\nimport type { ThreadRuntimeCore } from \"../../runtime/interfaces/thread-runtime-core\";\nimport type { ThreadListRuntimeCore } from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport { BaseSubscribable } from \"../../subscribable/subscribable\";\nimport { getThreadRuntimeCoreIsRunning } from \"../../runtime/api/thread-runtime\";\nimport { ThreadListRuntimeImpl } from \"../../runtime/api/thread-list-runtime\";\nimport { invalidateThreadRuntime } from \"../../runtime/utils/thread-runtime-lifecycle\";\nimport {\n useRuntimeAdapters,\n type RuntimeAdapters,\n} from \"./RuntimeAdapterProvider\";\nimport {\n RemoteThreadResource,\n type RemoteThreadListHook,\n} from \"./RemoteThreadResource\";\n\ntype RemoteThreadListHookInstance = {\n runtime?: ThreadRuntimeCore | undefined;\n publishedGeneration?: number | undefined;\n generation: number;\n isRunning: boolean;\n unsubscribeRunning?: Unsubscribe | undefined;\n};\n\ntype AdapterSnapshot = {\n defaultAdapters: RuntimeAdapters | null;\n threadAdapters: ReadonlyMap<string, RuntimeAdapters | null>;\n};\n\ntype HostSnapshot = {\n threads: readonly { id: string; generation: number }[];\n hookEpoch: number;\n};\n\nconst ProviderRenderDetector: FC<{\n detectorRef: RefObject<boolean>;\n}> = ({ detectorRef }) => {\n useLayoutEffect(() => {\n detectorRef.current = true;\n }, [detectorRef]);\n return null;\n};\n\nexport class RemoteThreadListHookInstanceManager extends BaseSubscribable {\n private runtimeHook: RemoteThreadListHook;\n private readonly adapterStore = create<AdapterSnapshot>(() => ({\n defaultAdapters: null,\n threadAdapters: new Map(),\n }));\n private readonly hostStore = create<HostSnapshot>(() => ({\n threads: [],\n hookEpoch: 0,\n }));\n private readonly pendingThreadAdapters = new Map<\n string,\n RuntimeAdapters | null\n >();\n private instances = new Map<string, RemoteThreadListHookInstance>();\n private nextGeneration = 0;\n private parent: ThreadListRuntimeCore;\n\n constructor(\n runtimeHook: RemoteThreadListHook,\n parent: ThreadListRuntimeCore,\n ) {\n super();\n this.parent = parent;\n this.runtimeHook = runtimeHook;\n }\n\n private _whenRuntimeAttached(threadId: string) {\n return new Promise<ThreadRuntimeCore>((resolve, reject) => {\n const callback = () => {\n const instance = this.instances.get(threadId);\n if (!instance) {\n dispose();\n reject(new Error(\"Thread was deleted before runtime was started\"));\n } else if (\n !instance.runtime ||\n instance.publishedGeneration !== instance.generation\n ) {\n return;\n } else {\n dispose();\n resolve(instance.runtime);\n }\n };\n const dispose = this.subscribe(callback);\n callback();\n });\n }\n\n public startThreadRuntime(threadId: string) {\n if (!this.instances.has(threadId)) {\n const generation = this.nextGeneration++;\n this.instances.set(threadId, {\n generation,\n isRunning: false,\n });\n this._syncHostThreads();\n }\n\n return this._whenRuntimeAttached(threadId);\n }\n\n public __internal_restartThreadRuntime(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return this.startThreadRuntime(threadId);\n\n if (instance.runtime) invalidateThreadRuntime(instance.runtime);\n instance.generation = this.nextGeneration++;\n this._syncHostThreads();\n this._notifySubscribers();\n\n return this._whenRuntimeAttached(threadId);\n }\n\n public getThreadRuntimeCore(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return undefined;\n return instance.runtime;\n }\n\n public __internal_isThreadRunning(threadId: string) {\n return this.instances.get(threadId)?.isRunning ?? false;\n }\n\n private runningSubscribers = new Set<() => void>();\n\n public __internal_subscribeRunningChanged(callback: () => void): Unsubscribe {\n this.runningSubscribers.add(callback);\n return () => this.runningSubscribers.delete(callback);\n }\n\n private _publish = (\n threadId: string,\n runtime: ThreadRuntimeCore,\n generation: number,\n ) => {\n this._publishThreadRuntime(threadId, runtime, generation);\n };\n\n private _publishThreadRuntime(\n threadId: string,\n runtime: ThreadRuntimeCore,\n generation: number,\n ) {\n const instance = this.instances.get(threadId);\n if (!instance) return;\n\n if (instance.generation !== generation) return;\n\n const previousRuntime = instance.runtime;\n instance.runtime = runtime;\n instance.publishedGeneration = generation;\n if (previousRuntime !== runtime) {\n this._trackRunning(instance);\n }\n this._notifySubscribers();\n if (previousRuntime !== undefined && previousRuntime !== runtime) {\n for (const callback of this.replacedSubscribers) callback();\n }\n }\n\n private replacedSubscribers = new Set<() => void>();\n\n public __internal_subscribeRuntimeReplaced(\n callback: () => void,\n ): Unsubscribe {\n this.replacedSubscribers.add(callback);\n return () => this.replacedSubscribers.delete(callback);\n }\n\n private _trackRunning(instance: RemoteThreadListHookInstance) {\n instance.unsubscribeRunning?.();\n\n const runtime = instance.runtime;\n if (!runtime) {\n instance.unsubscribeRunning = undefined;\n this._setRunning(instance, false);\n return;\n }\n\n this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));\n instance.unsubscribeRunning = runtime.subscribe(() => {\n this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));\n });\n }\n\n private _setRunning(\n instance: RemoteThreadListHookInstance,\n isRunning: boolean,\n ) {\n if (instance.isRunning === isRunning) return;\n instance.isRunning = isRunning;\n for (const callback of this.runningSubscribers) callback();\n }\n\n public stopThreadRuntime(threadId: string) {\n const instance = this.instances.get(threadId);\n if (instance?.runtime) invalidateThreadRuntime(instance.runtime);\n instance?.unsubscribeRunning?.();\n this.instances.delete(threadId);\n this.pendingThreadAdapters.delete(threadId);\n this._syncHostThreads();\n this._notifySubscribers();\n }\n\n public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {\n if (this.runtimeHook === newRuntimeHook) return;\n this.runtimeHook = newRuntimeHook;\n this.hostStore.setState(\n (state) => ({ ...state, hookEpoch: state.hookEpoch + 1 }),\n true,\n );\n }\n\n public __internal_setDefaultAdapters(adapters: RuntimeAdapters | null) {\n const current = this.adapterStore.getState();\n if (current.defaultAdapters === adapters) return;\n this.adapterStore.setState({ ...current, defaultAdapters: adapters }, true);\n }\n\n public __internal_setThreadAdapters(\n threadId: string,\n adapters: RuntimeAdapters | null,\n ) {\n const current = this.adapterStore.getState();\n const next = new Map(current.threadAdapters);\n if (adapters === null) next.delete(threadId);\n else next.set(threadId, adapters);\n this.adapterStore.setState({ ...current, threadAdapters: next }, true);\n }\n\n public __internal_dispose() {\n for (const threadId of [...this.instances.keys()]) {\n this.stopThreadRuntime(threadId);\n }\n }\n\n private _syncHostThreads() {\n this.hostStore.setState(\n (state) => ({\n ...state,\n threads: Array.from(this.instances.entries()).map(\n ([id, { generation }]) => ({ id, generation }),\n ),\n }),\n true,\n );\n }\n\n public __internal_useHost(parentClient: AssistantClient) {\n const { threads, hookEpoch } = this.hostStore();\n const adapters = this.adapterStore();\n const runtimeHook = this.runtimeHook;\n return useResources(\n threads.map(({ id, generation }) => {\n const threadAdapters = this.pendingThreadAdapters.has(id)\n ? this.pendingThreadAdapters.get(id)!\n : (adapters.threadAdapters.get(id) ?? adapters.defaultAdapters);\n return withKey(\n `${id}:${generation}:${hookEpoch}`,\n RemoteThreadResource({\n threadId: id,\n generation,\n parentList: this.parent,\n runtimeHook,\n parentClient,\n adapters: threadAdapters,\n publish: this._publish,\n }),\n );\n }),\n );\n }\n\n public __internal_RenderThreadRuntimes: FC<{\n provider: ComponentType<PropsWithChildren>;\n }> = ({ provider }) => {\n this.hostStore();\n\n return Array.from(this.instances.entries()).map(\n ([threadId, { generation }]) => (\n <this._OuterActiveThreadProvider\n key={`${threadId}:${generation}`}\n threadId={threadId}\n provider={provider}\n />\n ),\n );\n };\n\n public __internal_Host: FC<{ parentClient: AssistantClient }> = ({\n parentClient,\n }) => {\n this.__internal_useHost(parentClient);\n return null;\n };\n\n private _OuterActiveThreadProvider: FC<{\n threadId: string;\n provider: ComponentType<PropsWithChildren>;\n }> = memo(({ threadId, provider: Provider }) => {\n const runtime = useMemo(\n () => new ThreadListRuntimeImpl(this.parent).getItemById(threadId),\n [threadId],\n );\n\n const detectorRef = useRef(false);\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\" && Provider !== Fragment) {\n const id = setTimeout(() => {\n if (!detectorRef.current) {\n console.warn(\n \"RemoteThreadListAdapter.unstable_Provider did not render its `children` synchronously. \" +\n \"Render `children` on first commit; deferring them behind a loading state, Suspense boundary, \" +\n \"or `useEffect` gate strands the runtime host and leaves the thread without context.\",\n );\n }\n }, 100);\n return () => clearTimeout(id);\n }\n return undefined;\n }, [Provider]);\n\n return (\n <ThreadListItemRuntimeProvider runtime={runtime}>\n <Provider>\n <this._AdapterSink threadId={threadId} detectorRef={detectorRef} />\n </Provider>\n </ThreadListItemRuntimeProvider>\n );\n });\n\n private _AdapterSink: FC<{\n threadId: string;\n detectorRef: RefObject<boolean>;\n }> = ({ threadId, detectorRef }) => {\n const adapters = useRuntimeAdapters();\n this.pendingThreadAdapters.set(threadId, adapters);\n useLayoutEffect(() => {\n this.__internal_setThreadAdapters(threadId, adapters);\n return () => {\n if (this.pendingThreadAdapters.get(threadId) === adapters) {\n this.pendingThreadAdapters.delete(threadId);\n }\n this.__internal_setThreadAdapters(threadId, null);\n };\n }, [threadId, adapters]);\n return <ProviderRenderDetector detectorRef={detectorRef} />;\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAkDA,MAAMwC,0BAEDE,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAH,gBAAAC;CAAe,IAAAG;CAAA,IAAAC;CAAA,IAAAH,EAAA,OAAAF,aAAA;EACHI,WAAA;GACdJ,YAAWM,UAAW;EAAH;EAClBD,KAAA,CAACL,WAAW;EAACE,EAAA,KAAAF;EAAAE,EAAA,KAAAE;EAAAF,EAAA,KAAAG;CAAA,OAAA;EAAAD,KAAAF,EAAA;EAAAG,KAAAH,EAAA;CAAA;CAFhBxC,gBAAgB0C,IAEbC,EAAa;CAAC,OACV;AAAI;AAGb,IAAaE,sCAAb,cAAyD9B,iBAAiB;CACxE;CACA,eAAgCR,cAA+B;EAC7DuB,iBAAiB;EACjBC,gCAAgB,IAAIiB,IAAI;CAC1B,EAAE;CACF,YAA6BzC,cAA4B;EACvD2B,SAAS,CAAA;EACTE,WAAW;CACb,EAAE;CACF,wCAAyC,IAAIY,IAG3C;CACF,4BAAoB,IAAIA,IAA0C;CAClE,iBAAyB;CACzB;C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gBAAgBJ,aAAazG,UAAU;IAClE,MAAM6B,KAAKiF,iBAAiB;KAC1B,IAAI,CAAC9E,YAAYM,SACfyE,QAAQC,KACN,yQAGF;IAEJ,GAAG,GAAG;IACN,aAAaC,aAAapF,EAAE;GAC9B;EAEF,GAAG,CAAC4E,QAAQ,CAAC;EAEb,OACE,oBAAC,+BAAD;GAAwCvF;GACtC,UAAA,oBAAC,UAAD,EAAA,UACE,oBAAC,KAAK,cAAN;IAA6BgC;IAAuBlB;GAAY,CAAA,EACxD,CAAA;EACmB,CAAA;CAEnC,CAAC;CAED,gBAGM,EAAEkB,UAAUlB,kBAAkB;EAClC,MAAMuD,WAAW1E,mBAAmB;EACpC,KAAK+B,sBAAsBkB,IAAIZ,UAAUqC,QAAQ;EACjD7F,sBAAsB;GACpB,KAAK+F,6BAA6BvC,UAAUqC,QAAQ;GACpD,aAAa;IACX,IAAI,KAAK3C,sBAAsBY,IAAIN,QAAQ,MAAMqC,UAC/C,KAAK3C,sBAAsB6B,OAAOvB,QAAQ;IAE5C,KAAKuC,6BAA6BvC,UAAU,IAAI;GAClD;EACF,GAAG,CAACA,UAAUqC,QAAQ,CAAC;EACvB,OAAO,oBAAC,wBAAD,EAAqCvD,YAAY,CAAA;CAC1D;AACF"}
|
|
1
|
+
{"version":3,"file":"RemoteThreadListHookInstanceManager.js","names":["FC","RefObject","useEffect","useLayoutEffect","useMemo","useRef","memo","PropsWithChildren","ComponentType","Fragment","useResources","withKey","AssistantClient","ThreadListItemRuntimeProvider","ThreadRuntimeCore","ThreadRuntimeEventType","ThreadListRuntimeCore","ThreadListRuntimeEvent","Unsubscribe","BaseSubscribable","WritableSubscribable","useSubscribable","getThreadRuntimeCoreIsRunning","ThreadListRuntimeImpl","invalidateThreadRuntime","notifyEventListeners","useRuntimeAdapters","RuntimeAdapters","RemoteThreadResource","RemoteThreadListHook","THREAD_EVENTS","const","RemoteThreadListHookInstance","runtime","publishedGeneration","generation","isRunning","unsubscribeRunning","AdapterSnapshot","defaultAdapters","threadAdapters","ReadonlyMap","HostSnapshot","threads","id","hookEpoch","ProviderRenderDetector","detectorRef","t0","$","_c","t1","t2","current","RemoteThreadListHookInstanceManager","runtimeHook","adapterStore","Map","hostStore","pendingThreadAdapters","instances","nextGeneration","parent","constructor","_whenRuntimeAttached","threadId","Promise","resolve","reject","callback","instance","get","dispose","Error","subscribe","startThreadRuntime","has","set","_syncHostThreads","__internal_restartThreadRuntime","_notifySubscribers","getThreadRuntimeCore","undefined","__internal_isThreadRunning","runningSubscribers","Set","__internal_subscribeRunningChanged","add","delete","threadEventSubscribers","event","__internal_subscribeThreadEvents","_publish","_publishThreadRuntime","previousRuntime","_trackRunning","replacedSubscribers","__internal_subscribeRuntimeReplaced","_setRunning","unsubscribers","map","type","unstable_on","unsubscribe","stopThreadRuntime","setRuntimeHook","newRuntimeHook","host","getState","setState","__internal_setDefaultAdapters","adapters","__internal_setThreadAdapters","next","__internal_dispose","keys","Array","from","entries","__internal_useHost","parentClient","parentList","publish","__internal_RenderThreadRuntimes","provider","__internal_Host","_OuterActiveThreadProvider","Provider","getItemById","process","env","NODE_ENV","setTimeout","console","warn","clearTimeout","_AdapterSink"],"sources":["../../../src/react/runtimes/RemoteThreadListHookInstanceManager.tsx"],"sourcesContent":["import {\n type FC,\n type RefObject,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n memo,\n type PropsWithChildren,\n type ComponentType,\n Fragment,\n} from \"react\";\nimport { useResources, withKey } from \"@assistant-ui/tap\";\nimport type { AssistantClient } from \"@assistant-ui/store\";\nimport { ThreadListItemRuntimeProvider } from \"../providers/ThreadListItemRuntimeProvider\";\nimport type {\n ThreadRuntimeCore,\n ThreadRuntimeEventType,\n} from \"../../runtime/interfaces/thread-runtime-core\";\nimport type {\n ThreadListRuntimeCore,\n ThreadListRuntimeEvent,\n} from \"../../runtime/interfaces/thread-list-runtime-core\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport {\n BaseSubscribable,\n WritableSubscribable,\n} from \"../../subscribable/subscribable\";\nimport { useSubscribable } from \"../../store/runtime-clients/useSubscribable\";\nimport { getThreadRuntimeCoreIsRunning } from \"../../runtime/api/thread-runtime\";\nimport { ThreadListRuntimeImpl } from \"../../runtime/api/thread-list-runtime\";\nimport { invalidateThreadRuntime } from \"../../runtime/utils/thread-runtime-lifecycle\";\nimport { notifyEventListeners } from \"../../utils/notify-event-listeners\";\nimport {\n useRuntimeAdapters,\n type RuntimeAdapters,\n} from \"./RuntimeAdapterProvider\";\nimport {\n RemoteThreadResource,\n type RemoteThreadListHook,\n} from \"./RemoteThreadResource\";\n\nconst THREAD_EVENTS = [\n \"runStart\",\n \"runEnd\",\n \"initialize\",\n \"modelContextUpdate\",\n] as const satisfies readonly ThreadRuntimeEventType[];\n\ntype RemoteThreadListHookInstance = {\n runtime?: ThreadRuntimeCore | undefined;\n publishedGeneration?: number | undefined;\n generation: number;\n isRunning: boolean;\n unsubscribeRunning?: Unsubscribe | undefined;\n};\n\ntype AdapterSnapshot = {\n defaultAdapters: RuntimeAdapters | null;\n threadAdapters: ReadonlyMap<string, RuntimeAdapters | null>;\n};\n\ntype HostSnapshot = {\n threads: readonly { id: string; generation: number }[];\n hookEpoch: number;\n};\n\nconst ProviderRenderDetector: FC<{\n detectorRef: RefObject<boolean>;\n}> = ({ detectorRef }) => {\n useLayoutEffect(() => {\n detectorRef.current = true;\n }, [detectorRef]);\n return null;\n};\n\nexport class RemoteThreadListHookInstanceManager extends BaseSubscribable {\n private runtimeHook: RemoteThreadListHook;\n private readonly adapterStore = new WritableSubscribable<AdapterSnapshot>({\n defaultAdapters: null,\n threadAdapters: new Map(),\n });\n private readonly hostStore = new WritableSubscribable<HostSnapshot>({\n threads: [],\n hookEpoch: 0,\n });\n private readonly pendingThreadAdapters = new Map<\n string,\n RuntimeAdapters | null\n >();\n private instances = new Map<string, RemoteThreadListHookInstance>();\n private nextGeneration = 0;\n private parent: ThreadListRuntimeCore;\n\n constructor(\n runtimeHook: RemoteThreadListHook,\n parent: ThreadListRuntimeCore,\n ) {\n super();\n this.parent = parent;\n this.runtimeHook = runtimeHook;\n }\n\n private _whenRuntimeAttached(threadId: string) {\n return new Promise<ThreadRuntimeCore>((resolve, reject) => {\n const callback = () => {\n const instance = this.instances.get(threadId);\n if (!instance) {\n dispose();\n reject(new Error(\"Thread was deleted before runtime was started\"));\n } else if (\n !instance.runtime ||\n instance.publishedGeneration !== instance.generation\n ) {\n return;\n } else {\n dispose();\n resolve(instance.runtime);\n }\n };\n const dispose = this.subscribe(callback);\n callback();\n });\n }\n\n public startThreadRuntime(threadId: string) {\n if (!this.instances.has(threadId)) {\n const generation = this.nextGeneration++;\n this.instances.set(threadId, {\n generation,\n isRunning: false,\n });\n this._syncHostThreads();\n }\n\n return this._whenRuntimeAttached(threadId);\n }\n\n public __internal_restartThreadRuntime(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return this.startThreadRuntime(threadId);\n\n if (instance.runtime) invalidateThreadRuntime(instance.runtime);\n instance.generation = this.nextGeneration++;\n this._syncHostThreads();\n this._notifySubscribers();\n\n return this._whenRuntimeAttached(threadId);\n }\n\n public getThreadRuntimeCore(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return undefined;\n return instance.runtime;\n }\n\n public __internal_isThreadRunning(threadId: string) {\n return this.instances.get(threadId)?.isRunning ?? false;\n }\n\n private runningSubscribers = new Set<() => void>();\n\n public __internal_subscribeRunningChanged(callback: () => void): Unsubscribe {\n this.runningSubscribers.add(callback);\n return () => this.runningSubscribers.delete(callback);\n }\n\n private threadEventSubscribers = new Set<\n (event: ThreadListRuntimeEvent) => void\n >();\n\n public __internal_subscribeThreadEvents(\n callback: (event: ThreadListRuntimeEvent) => void,\n ): Unsubscribe {\n this.threadEventSubscribers.add(callback);\n return () => this.threadEventSubscribers.delete(callback);\n }\n\n private _publish = (\n threadId: string,\n runtime: ThreadRuntimeCore,\n generation: number,\n ) => {\n this._publishThreadRuntime(threadId, runtime, generation);\n };\n\n private _publishThreadRuntime(\n threadId: string,\n runtime: ThreadRuntimeCore,\n generation: number,\n ) {\n const instance = this.instances.get(threadId);\n if (!instance) return;\n\n if (instance.generation !== generation) return;\n\n const previousRuntime = instance.runtime;\n instance.runtime = runtime;\n instance.publishedGeneration = generation;\n if (previousRuntime !== runtime) {\n this._trackRunning(threadId, instance);\n }\n this._notifySubscribers();\n if (previousRuntime !== undefined && previousRuntime !== runtime) {\n for (const callback of this.replacedSubscribers) callback();\n }\n }\n\n private replacedSubscribers = new Set<() => void>();\n\n public __internal_subscribeRuntimeReplaced(\n callback: () => void,\n ): Unsubscribe {\n this.replacedSubscribers.add(callback);\n return () => this.replacedSubscribers.delete(callback);\n }\n\n private _trackRunning(\n threadId: string,\n instance: RemoteThreadListHookInstance,\n ) {\n instance.unsubscribeRunning?.();\n\n const runtime = instance.runtime;\n if (!runtime) {\n instance.unsubscribeRunning = undefined;\n this._setRunning(instance, false);\n return;\n }\n\n this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));\n const unsubscribers = [\n runtime.subscribe(() => {\n this._setRunning(instance, getThreadRuntimeCoreIsRunning(runtime));\n }),\n ...THREAD_EVENTS.map((type) =>\n runtime.unstable_on(type, () => {\n notifyEventListeners(\n this.threadEventSubscribers,\n { threadId, type },\n `Thread event \"${type}\"`,\n );\n }),\n ),\n ];\n instance.unsubscribeRunning = () => {\n for (const unsubscribe of unsubscribers) unsubscribe();\n };\n }\n\n private _setRunning(\n instance: RemoteThreadListHookInstance,\n isRunning: boolean,\n ) {\n if (instance.isRunning === isRunning) return;\n instance.isRunning = isRunning;\n for (const callback of this.runningSubscribers) callback();\n }\n\n public stopThreadRuntime(threadId: string) {\n const instance = this.instances.get(threadId);\n if (instance?.runtime) invalidateThreadRuntime(instance.runtime);\n instance?.unsubscribeRunning?.();\n this.instances.delete(threadId);\n this.pendingThreadAdapters.delete(threadId);\n this._syncHostThreads();\n this._notifySubscribers();\n }\n\n public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {\n if (this.runtimeHook === newRuntimeHook) return;\n this.runtimeHook = newRuntimeHook;\n const host = this.hostStore.getState();\n this.hostStore.setState({ ...host, hookEpoch: host.hookEpoch + 1 });\n }\n\n public __internal_setDefaultAdapters(adapters: RuntimeAdapters | null) {\n const current = this.adapterStore.getState();\n if (current.defaultAdapters === adapters) return;\n this.adapterStore.setState({ ...current, defaultAdapters: adapters });\n }\n\n public __internal_setThreadAdapters(\n threadId: string,\n adapters: RuntimeAdapters | null,\n ) {\n const current = this.adapterStore.getState();\n const next = new Map(current.threadAdapters);\n if (adapters === null) next.delete(threadId);\n else next.set(threadId, adapters);\n this.adapterStore.setState({ ...current, threadAdapters: next });\n }\n\n public __internal_dispose() {\n for (const threadId of [...this.instances.keys()]) {\n this.stopThreadRuntime(threadId);\n }\n }\n\n private _syncHostThreads() {\n const host = this.hostStore.getState();\n this.hostStore.setState({\n ...host,\n threads: Array.from(this.instances.entries()).map(\n ([id, { generation }]) => ({ id, generation }),\n ),\n });\n }\n\n public __internal_useHost(parentClient: AssistantClient) {\n const { threads, hookEpoch } = useSubscribable(this.hostStore);\n const adapters = useSubscribable(this.adapterStore);\n const runtimeHook = this.runtimeHook;\n return useResources(\n threads.map(({ id, generation }) => {\n const threadAdapters = this.pendingThreadAdapters.has(id)\n ? this.pendingThreadAdapters.get(id)!\n : (adapters.threadAdapters.get(id) ?? adapters.defaultAdapters);\n return withKey(\n `${id}:${generation}:${hookEpoch}`,\n RemoteThreadResource({\n threadId: id,\n generation,\n parentList: this.parent,\n runtimeHook,\n parentClient,\n adapters: threadAdapters,\n publish: this._publish,\n }),\n );\n }),\n );\n }\n\n public __internal_RenderThreadRuntimes: FC<{\n provider: ComponentType<PropsWithChildren>;\n }> = ({ provider }) => {\n useSubscribable(this.hostStore);\n\n return Array.from(this.instances.entries()).map(\n ([threadId, { generation }]) => (\n <this._OuterActiveThreadProvider\n key={`${threadId}:${generation}`}\n threadId={threadId}\n provider={provider}\n />\n ),\n );\n };\n\n public __internal_Host: FC<{ parentClient: AssistantClient }> = ({\n parentClient,\n }) => {\n this.__internal_useHost(parentClient);\n return null;\n };\n\n private _OuterActiveThreadProvider: FC<{\n threadId: string;\n provider: ComponentType<PropsWithChildren>;\n }> = memo(({ threadId, provider: Provider }) => {\n const runtime = useMemo(\n () => new ThreadListRuntimeImpl(this.parent).getItemById(threadId),\n [threadId],\n );\n\n const detectorRef = useRef(false);\n useEffect(() => {\n if (process.env.NODE_ENV !== \"production\" && Provider !== Fragment) {\n const id = setTimeout(() => {\n if (!detectorRef.current) {\n console.warn(\n \"RemoteThreadListAdapter.unstable_Provider did not render its `children` synchronously. \" +\n \"Render `children` on first commit; deferring them behind a loading state, Suspense boundary, \" +\n \"or `useEffect` gate strands the runtime host and leaves the thread without context.\",\n );\n }\n }, 100);\n return () => clearTimeout(id);\n }\n return undefined;\n }, [Provider]);\n\n return (\n <ThreadListItemRuntimeProvider runtime={runtime}>\n <Provider>\n <this._AdapterSink threadId={threadId} detectorRef={detectorRef} />\n </Provider>\n </ThreadListItemRuntimeProvider>\n );\n });\n\n private _AdapterSink: FC<{\n threadId: string;\n detectorRef: RefObject<boolean>;\n }> = ({ threadId, detectorRef }) => {\n const adapters = useRuntimeAdapters();\n this.pendingThreadAdapters.set(threadId, adapters);\n useLayoutEffect(() => {\n this.__internal_setThreadAdapters(threadId, adapters);\n return () => {\n if (this.pendingThreadAdapters.get(threadId) === adapters) {\n this.pendingThreadAdapters.delete(threadId);\n }\n this.__internal_setThreadAdapters(threadId, null);\n };\n }, [threadId, adapters]);\n return <ProviderRenderDetector detectorRef={detectorRef} />;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAM8B,gBAAgB;CACpB;CACA;CACA;CACA;AAAoB;AAqBtB,MAAMgB,0BAEDE,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAH,gBAAAC;CAAe,IAAAG;CAAA,IAAAC;CAAA,IAAAH,EAAA,OAAAF,aAAA;EACHI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UAAD,EAAA,UACE,oBAAC,KAAK,cAAN;IAA6BgC;IAAuBlB;GAAY,CAAA,EACxD,CAAA;EACmB,CAAA;CAEnC,CAAC;CAED,gBAGM,EAAEkB,UAAUlB,kBAAkB;EAClC,MAAMgE,WAAWrF,mBAAmB;EACpC,KAAKiC,sBAAsBkB,IAAIZ,UAAU8C,QAAQ;EACjD5G,sBAAsB;GACpB,KAAK6G,6BAA6B/C,UAAU8C,QAAQ;GACpD,aAAa;IACX,IAAI,KAAKpD,sBAAsBY,IAAIN,QAAQ,MAAM8C,UAC/C,KAAKpD,sBAAsB6B,OAAOvB,QAAQ;IAE5C,KAAK+C,6BAA6B/C,UAAU,IAAI;GAClD;EACF,GAAG,CAACA,UAAU8C,QAAQ,CAAC;EACvB,OAAO,oBAAC,wBAAD,EAAqChE,YAAY,CAAA;CAC1D;AACF"}
|
|
@@ -7,7 +7,7 @@ import { QueueItemState } from "../../runtime/queue/queue-item.js";
|
|
|
7
7
|
import { QueuePlacement } from "../../runtime/queue/external-thread-queue-adapter.js";
|
|
8
8
|
import { EditComposerRuntimeCore, ThreadComposerRuntimeCore } from "../../runtime/interfaces/composer-runtime-core.js";
|
|
9
9
|
import { AddToolResultOptions, RespondToToolApprovalOptions, ResumeRunConfig, ResumeToolCallOptions, RuntimeCapabilities, SpeechState, StartRunConfig, SubmitFeedbackOptions, ThreadRuntimeEventCallback, ThreadRuntimeEventType, ThreadSuggestion, VoiceSessionState } from "../../runtime/interfaces/thread-runtime-core.js";
|
|
10
|
-
import { ThreadListRuntimeCore } from "../../runtime/interfaces/thread-list-runtime-core.js";
|
|
10
|
+
import { ThreadListRuntimeCore, ThreadListRuntimeEvent } from "../../runtime/interfaces/thread-list-runtime-core.js";
|
|
11
11
|
import { BaseSubscribable } from "../../subscribable/subscribable.js";
|
|
12
12
|
import { RemoteThreadListOptions } from "../../runtimes/remote-thread-list/types.js";
|
|
13
13
|
import "../../store/index.js";
|
|
@@ -38,7 +38,7 @@ declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable imp
|
|
|
38
38
|
loadMore(): Promise<void>;
|
|
39
39
|
constructor(options: RemoteThreadListOptions, contextProvider: ModelContextProvider);
|
|
40
40
|
private _initialThreadLoaded;
|
|
41
|
-
private
|
|
41
|
+
private providerStore;
|
|
42
42
|
__internal_setOptions(options: RemoteThreadListOptions): void;
|
|
43
43
|
private _requireAdapterGeneration;
|
|
44
44
|
private _requireAdapterSettled;
|
|
@@ -72,7 +72,7 @@ declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable imp
|
|
|
72
72
|
unstable_notifySessionReset: () => void;
|
|
73
73
|
addToolResult: (options: AddToolResultOptions) => void;
|
|
74
74
|
resumeToolCall: (options: ResumeToolCallOptions) => void;
|
|
75
|
-
respondToToolApproval: (options: RespondToToolApprovalOptions) => void
|
|
75
|
+
respondToToolApproval: (options: RespondToToolApprovalOptions) => Promise<void>;
|
|
76
76
|
speak: (messageId: string) => void;
|
|
77
77
|
stopSpeaking: () => void;
|
|
78
78
|
connectVoice: () => void;
|
|
@@ -126,7 +126,7 @@ declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable imp
|
|
|
126
126
|
unstable_notifySessionReset: () => void;
|
|
127
127
|
addToolResult: (options: AddToolResultOptions) => void;
|
|
128
128
|
resumeToolCall: (options: ResumeToolCallOptions) => void;
|
|
129
|
-
respondToToolApproval: (options: RespondToToolApprovalOptions) => void
|
|
129
|
+
respondToToolApproval: (options: RespondToToolApprovalOptions) => Promise<void>;
|
|
130
130
|
speak: (messageId: string) => void;
|
|
131
131
|
stopSpeaking: () => void;
|
|
132
132
|
connectVoice: () => void;
|
|
@@ -165,6 +165,7 @@ declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable imp
|
|
|
165
165
|
unstable_on<E extends ThreadRuntimeEventType>(event: E, callback: ThreadRuntimeEventCallback<E>): Unsubscribe;
|
|
166
166
|
}>;
|
|
167
167
|
unstable_isThreadRunning(threadIdOrRemoteId: string): boolean;
|
|
168
|
+
unstable_subscribeThreadEvents(callback: (event: ThreadListRuntimeEvent) => void): Unsubscribe;
|
|
168
169
|
getItemById(threadIdOrRemoteId: string): RemoteThreadData | undefined;
|
|
169
170
|
switchToThread(threadIdOrRemoteId: string, options?: {
|
|
170
171
|
unarchive?: boolean;
|
|
@@ -188,7 +189,7 @@ declare class RemoteThreadListThreadListRuntimeCore extends BaseSubscribable imp
|
|
|
188
189
|
delete(threadIdOrRemoteId: string): Promise<void>;
|
|
189
190
|
__internal_dispose(): void;
|
|
190
191
|
detach(threadIdOrRemoteId: string): Promise<void>;
|
|
191
|
-
private
|
|
192
|
+
private boundIdsStore;
|
|
192
193
|
__internal_RenderComponent: FC;
|
|
193
194
|
}
|
|
194
195
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx"],"mappings":";;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"RemoteThreadListThreadListRuntimeCore.d.ts","names":[],"sources":["../../../src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx"],"mappings":";;;;;;;;;;;;;;;;;;cA+Da,8CACH,4BACG;UAEH;mBACS;mBACA;UAET;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UAEA;mBACS;mBAIA;mBAYA;UAcT;MAUG,eAAW,SAAA,OA1DX,mBA0DW;EAIf,yBAAqB;EA4ErB,YAAY;EAwDjB,YAAA,SAAS,yBACT,iBAAiB;UA6BX;UACA;EAED,sBAAsB,SAAS;UAwC9B;UAMA;UAMA;EAsGD;EAgBM,oBAAoB;EA4B1B,UAAM;MAWF;MAIA;MAIA;MAIA;MAIA;MAIA;MAIA;cAMC;UAKJ;UAEA;EASD,4BAAwB;;;eAzDlB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+DN,qBAAqB,6BAA0B;;;eANvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmBxB,yBAAyB;EAMzB,+BACL,WAAW,OAAO,kCAAA;EAKb,YAAY,6BAA0B;EAItC,eACL,4BACA;IAAY;MACX;UAIK;UAgBM;EA0HP,qBAAqB;UAIpB;UAMA;UAOM;EAwBP,aAAoB,qBAAgB;;;;EA8EpC,gBAAuB,qBAAgB;EA6CjC,OACX,4BACA,mBACC;EAiCU,aACX,4BACA,QAAQ,sCACP;UAoDW;EAsBD,QAAQ,6BAA0B;EAwBlC,UAAU,6BAA6B;EA4BvC,OAAO,6BAA0B;EAyBvC;EAIM,OAAO,6BAA6B;UAYzC;EAED,4BAA4B"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { BaseSubscribable } from "../../subscribable/subscribable.js";
|
|
1
|
+
import { BaseSubscribable, WritableSubscribable } from "../../subscribable/subscribable.js";
|
|
2
2
|
import { OptimisticState } from "../../runtimes/remote-thread-list/optimistic-state.js";
|
|
3
3
|
import { EMPTY_THREAD_CORE } from "../../runtimes/remote-thread-list/empty-thread-core.js";
|
|
4
4
|
import { classifyThreads, createEmptyRemoteThreadState, createThreadMappingId, getThreadData, normalizeCursor, preserveMidLoadTransitions, seedNewThread, statusSnapshot, updateStatusReducer } from "../../runtimes/remote-thread-list/remote-thread-state.js";
|
|
5
|
+
import { useSubscribable } from "../../store/runtime-clients/useSubscribable.js";
|
|
5
6
|
import { ThreadListAdapterChangedError } from "../../runtimes/remote-thread-list/adapter-changed.js";
|
|
6
7
|
import { useStableRuntimeAdapters } from "./useRuntimeAdapters.js";
|
|
8
|
+
import { isTitleSourceMessage } from "../../runtimes/remote-thread-list/title.js";
|
|
7
9
|
import { RuntimeAdapterProvider } from "./RuntimeAdapterProvider.js";
|
|
8
|
-
import { isTitleSourceMessage } from "./RemoteThreadResource.js";
|
|
9
10
|
import { RemoteThreadListHookInstanceManager } from "./RemoteThreadListHookInstanceManager.js";
|
|
10
11
|
import { AssistantMessageStream } from "assistant-stream";
|
|
11
12
|
import { Fragment, useEffect, useId } from "@assistant-ui/tap/react-shim";
|
|
12
13
|
import { useAui } from "@assistant-ui/store";
|
|
13
14
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { create } from "zustand";
|
|
15
15
|
//#region src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx
|
|
16
16
|
const threadNotFoundError = (threadIdOrRemoteId, action) => /* @__PURE__ */ new Error(`Thread "${threadIdOrRemoteId}" not found while ${action}.`);
|
|
17
17
|
const threadStatusError = (threadIdOrRemoteId, status, action) => /* @__PURE__ */ new Error(`Thread "${threadIdOrRemoteId}" has status "${status}", so it cannot ${action}.`);
|
|
@@ -62,6 +62,7 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
62
62
|
this._loadThreadsPromise = this._state.optimisticUpdate({
|
|
63
63
|
execute: () => this._options.adapter.list(),
|
|
64
64
|
loading: (state) => {
|
|
65
|
+
if (generation !== this._loadGeneration) return state;
|
|
65
66
|
return {
|
|
66
67
|
...state,
|
|
67
68
|
isLoading: true
|
|
@@ -77,8 +78,8 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
77
78
|
const fresh = classifyThreads(l.threads, {
|
|
78
79
|
threadIds: [],
|
|
79
80
|
archivedThreadIds: [],
|
|
80
|
-
threadIdMap: {},
|
|
81
|
-
threadData: {}
|
|
81
|
+
threadIdMap: { ...state.threadIdMap },
|
|
82
|
+
threadData: { ...state.threadData }
|
|
82
83
|
});
|
|
83
84
|
const merged = {
|
|
84
85
|
...state,
|
|
@@ -86,14 +87,8 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
86
87
|
cursor: normalizeCursor(l.nextCursor),
|
|
87
88
|
threadIds: fresh.threadIds,
|
|
88
89
|
archivedThreadIds: fresh.archivedThreadIds,
|
|
89
|
-
threadIdMap:
|
|
90
|
-
|
|
91
|
-
...fresh.threadIdMap
|
|
92
|
-
},
|
|
93
|
-
threadData: {
|
|
94
|
-
...state.threadData,
|
|
95
|
-
...fresh.threadData
|
|
96
|
-
}
|
|
90
|
+
threadIdMap: fresh.threadIdMap,
|
|
91
|
+
threadData: fresh.threadData
|
|
97
92
|
};
|
|
98
93
|
return preserveMidLoadTransitions(merged, state, statusAtRequest);
|
|
99
94
|
}
|
|
@@ -130,10 +125,13 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
130
125
|
const cursor = initialState.cursor;
|
|
131
126
|
const dedup = this._state.optimisticUpdate({
|
|
132
127
|
execute: () => adapter.list({ after: cursor }),
|
|
133
|
-
loading: (state) =>
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
loading: (state) => {
|
|
129
|
+
if (generation !== this._loadGeneration) return state;
|
|
130
|
+
return {
|
|
131
|
+
...state,
|
|
132
|
+
isLoadingMore: true
|
|
133
|
+
};
|
|
134
|
+
},
|
|
137
135
|
then: (state, l) => {
|
|
138
136
|
if (generation !== this._loadGeneration) return state;
|
|
139
137
|
if (adapter !== this._options.adapter) return state;
|
|
@@ -175,19 +173,18 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
175
173
|
this._hookManager.__internal_subscribeRuntimeReplaced(() => {
|
|
176
174
|
queueMicrotask(() => this._notifySubscribers());
|
|
177
175
|
});
|
|
178
|
-
this.
|
|
176
|
+
this.providerStore = new WritableSubscribable(this.resolveProvider(options.adapter));
|
|
179
177
|
this.__internal_setOptions(options);
|
|
180
178
|
this.switchToNewThread();
|
|
181
179
|
}
|
|
182
180
|
_initialThreadLoaded = false;
|
|
183
|
-
|
|
181
|
+
providerStore;
|
|
184
182
|
__internal_setOptions(options) {
|
|
185
183
|
if (this._options === options) return;
|
|
186
184
|
const adapterChanged = this._options !== void 0 && this._options.adapter !== options.adapter;
|
|
187
185
|
const controlledThreadIdChanged = this._initialThreadLoaded && this._options !== void 0 && this._options.threadId !== options.threadId;
|
|
188
186
|
this._options = options;
|
|
189
|
-
|
|
190
|
-
if (Provider !== this.useProvider.getState().Provider) this.useProvider.setState({ Provider }, true);
|
|
187
|
+
this.providerStore.setState(this.resolveProvider(options.adapter));
|
|
191
188
|
this._hookManager.setRuntimeHook(options.runtimeHook);
|
|
192
189
|
if (adapterChanged) {
|
|
193
190
|
this._loadGeneration++;
|
|
@@ -212,38 +209,40 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
212
209
|
if (this._replaceListOnNextLoad) throw new ThreadListAdapterChangedError();
|
|
213
210
|
}
|
|
214
211
|
_replaceWithThreads(state, threads, cursor) {
|
|
215
|
-
const
|
|
216
|
-
threadIds: [],
|
|
217
|
-
archivedThreadIds: [],
|
|
218
|
-
threadIdMap: {},
|
|
219
|
-
threadData: {}
|
|
220
|
-
});
|
|
221
|
-
const threadIdMap = { ...fresh.threadIdMap };
|
|
222
|
-
const threadData = { ...fresh.threadData };
|
|
223
|
-
const threadIds = [...fresh.threadIds];
|
|
224
|
-
const archivedThreadIds = [...fresh.archivedThreadIds];
|
|
212
|
+
const carried = [];
|
|
225
213
|
if (state.newThreadId) {
|
|
226
214
|
const mappingId = state.threadIdMap[state.newThreadId];
|
|
227
215
|
const draft = mappingId ? state.threadData[mappingId] : void 0;
|
|
228
|
-
if (draft?.status === "new")
|
|
229
|
-
threadIdMap[state.newThreadId] = mappingId;
|
|
230
|
-
threadData[mappingId] = draft;
|
|
231
|
-
}
|
|
216
|
+
if (draft?.status === "new") carried.push(draft);
|
|
232
217
|
}
|
|
233
218
|
const stale = this._staleThreadIdsOnReplace;
|
|
234
219
|
if (stale) for (const item of Object.values(state.threadData)) {
|
|
235
220
|
if (stale.has(item.id)) continue;
|
|
236
221
|
if (item.status !== "new" && item.remoteId === void 0) continue;
|
|
222
|
+
carried.push(item);
|
|
223
|
+
}
|
|
224
|
+
this._staleThreadIdsOnReplace = void 0;
|
|
225
|
+
const seed = {
|
|
226
|
+
threadIds: [],
|
|
227
|
+
archivedThreadIds: [],
|
|
228
|
+
threadIdMap: {},
|
|
229
|
+
threadData: {}
|
|
230
|
+
};
|
|
231
|
+
for (const item of carried) {
|
|
237
232
|
const mappingId = createThreadMappingId(item.id);
|
|
238
|
-
if (threadData[mappingId]) continue;
|
|
239
|
-
threadIdMap[item.id] = mappingId;
|
|
240
|
-
if (item.remoteId !== void 0) threadIdMap[item.remoteId] = mappingId;
|
|
241
|
-
threadData[mappingId] = item;
|
|
233
|
+
if (seed.threadData[mappingId]) continue;
|
|
234
|
+
seed.threadIdMap[item.id] = mappingId;
|
|
235
|
+
if (item.remoteId !== void 0) seed.threadIdMap[item.remoteId] = mappingId;
|
|
236
|
+
seed.threadData[mappingId] = item;
|
|
237
|
+
}
|
|
238
|
+
const { threadIds, archivedThreadIds, threadIdMap, threadData } = classifyThreads(threads, seed);
|
|
239
|
+
for (const item of carried) {
|
|
242
240
|
if (item.remoteId === void 0) continue;
|
|
243
|
-
|
|
244
|
-
|
|
241
|
+
const current = threadData[createThreadMappingId(item.id)];
|
|
242
|
+
if (current === void 0) continue;
|
|
243
|
+
if (current.status === "regular" && !threadIds.includes(current.id)) threadIds.push(current.id);
|
|
244
|
+
else if (current.status === "archived" && !archivedThreadIds.includes(current.id)) archivedThreadIds.push(current.id);
|
|
245
245
|
}
|
|
246
|
-
this._staleThreadIdsOnReplace = void 0;
|
|
247
246
|
let nextState = {
|
|
248
247
|
...state,
|
|
249
248
|
isLoading: false,
|
|
@@ -351,6 +350,9 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
351
350
|
if (!data) return false;
|
|
352
351
|
return this._hookManager.__internal_isThreadRunning(data.id);
|
|
353
352
|
}
|
|
353
|
+
unstable_subscribeThreadEvents(callback) {
|
|
354
|
+
return this._hookManager.__internal_subscribeThreadEvents(callback);
|
|
355
|
+
}
|
|
354
356
|
getItemById(threadIdOrRemoteId) {
|
|
355
357
|
return getThreadData(this._state.value, threadIdOrRemoteId);
|
|
356
358
|
}
|
|
@@ -412,11 +414,21 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
412
414
|
if (this.mainThreadId !== void 0) await task;
|
|
413
415
|
else task.then(() => this._notifySubscribers(), () => void 0);
|
|
414
416
|
if (generation !== this._switchGeneration) return;
|
|
415
|
-
|
|
416
|
-
|
|
417
|
+
let current = this.getItemById(data.id);
|
|
418
|
+
if (current?.id !== data.id) return;
|
|
419
|
+
if (current.status === "archived" && options?.unarchive !== false) {
|
|
420
|
+
await current.initializeTask;
|
|
417
421
|
if (generation !== this._switchGeneration) return;
|
|
422
|
+
current = this.getItemById(data.id);
|
|
423
|
+
if (current?.id !== data.id) return;
|
|
424
|
+
if (current.status === "archived") {
|
|
425
|
+
await this.unarchive(current.id);
|
|
426
|
+
if (generation !== this._switchGeneration) return;
|
|
427
|
+
current = this.getItemById(data.id);
|
|
428
|
+
if (current?.id !== data.id) return;
|
|
429
|
+
}
|
|
418
430
|
}
|
|
419
|
-
this._mainThreadId =
|
|
431
|
+
this._mainThreadId = current.id;
|
|
420
432
|
this._notifySubscribers();
|
|
421
433
|
this._notifyThreadIdChange(emitThreadIdChange);
|
|
422
434
|
}
|
|
@@ -487,24 +499,29 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
487
499
|
const data = getThreadData(state, threadId);
|
|
488
500
|
if (!data) return state;
|
|
489
501
|
const mappingId = createThreadMappingId(threadId);
|
|
502
|
+
const listedMappingId = state.threadIdMap[remoteId];
|
|
503
|
+
const orphan = listedMappingId !== void 0 && listedMappingId !== mappingId ? state.threadData[listedMappingId] : void 0;
|
|
504
|
+
const threadData = { ...state.threadData };
|
|
505
|
+
if (orphan !== void 0) delete threadData[listedMappingId];
|
|
506
|
+
threadData[mappingId] = {
|
|
507
|
+
...data,
|
|
508
|
+
initializeTask: Promise.resolve({
|
|
509
|
+
remoteId,
|
|
510
|
+
externalId
|
|
511
|
+
}),
|
|
512
|
+
remoteId,
|
|
513
|
+
externalId
|
|
514
|
+
};
|
|
515
|
+
const rewire = (ids) => orphan === void 0 ? ids : ids.filter((id) => id !== orphan.id);
|
|
490
516
|
return {
|
|
491
517
|
...state,
|
|
518
|
+
threadIds: rewire(state.threadIds),
|
|
519
|
+
archivedThreadIds: rewire(state.archivedThreadIds),
|
|
492
520
|
threadIdMap: {
|
|
493
521
|
...state.threadIdMap,
|
|
494
522
|
[remoteId]: mappingId
|
|
495
523
|
},
|
|
496
|
-
threadData
|
|
497
|
-
...state.threadData,
|
|
498
|
-
[mappingId]: {
|
|
499
|
-
...data,
|
|
500
|
-
initializeTask: Promise.resolve({
|
|
501
|
-
remoteId,
|
|
502
|
-
externalId
|
|
503
|
-
}),
|
|
504
|
-
remoteId,
|
|
505
|
-
externalId
|
|
506
|
-
}
|
|
507
|
-
}
|
|
524
|
+
threadData
|
|
508
525
|
};
|
|
509
526
|
}
|
|
510
527
|
});
|
|
@@ -702,17 +719,17 @@ var RemoteThreadListThreadListRuntimeCore = class extends BaseSubscribable {
|
|
|
702
719
|
this._requireAdapterGeneration(adapterGeneration);
|
|
703
720
|
this._hookManager.stopThreadRuntime(data.id);
|
|
704
721
|
}
|
|
705
|
-
|
|
722
|
+
boundIdsStore = new WritableSubscribable([]);
|
|
706
723
|
__internal_RenderComponent = () => {
|
|
707
724
|
const id = useId();
|
|
708
725
|
useEffect(() => {
|
|
709
|
-
this.
|
|
726
|
+
this.boundIdsStore.setState([...this.boundIdsStore.getState(), id]);
|
|
710
727
|
return () => {
|
|
711
|
-
this.
|
|
728
|
+
this.boundIdsStore.setState(this.boundIdsStore.getState().filter((i) => i !== id));
|
|
712
729
|
};
|
|
713
730
|
}, [id]);
|
|
714
|
-
const boundIds = this.
|
|
715
|
-
const
|
|
731
|
+
const boundIds = useSubscribable(this.boundIdsStore);
|
|
732
|
+
const Provider = useSubscribable(this.providerStore);
|
|
716
733
|
const aui = useAui();
|
|
717
734
|
return (boundIds.length === 0 || boundIds[0] === id) && /* @__PURE__ */ jsxs(RuntimeAdapterProvider, {
|
|
718
735
|
adapters: this._runtimeAdapters,
|