@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
|
@@ -1,166 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { RuntimeAdapterProvider } from "../RuntimeAdapterProvider.js";
|
|
4
|
-
import { useAssistantCloudThreadHistoryAdapter } from "./AssistantCloudThreadHistoryAdapter.js";
|
|
5
|
-
import { CloudFileAttachmentAdapter } from "./CloudFileAttachmentAdapter.js";
|
|
6
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
import { AssistantCloud } from "assistant-cloud";
|
|
1
|
+
import { autoCloud, createCloudThreadListAdapter, useCloudRuntimeAdapters } from "./createCloudThreadListAdapter.js";
|
|
2
|
+
import { useCallback, useInsertionEffect, useMemo, useRef } from "@assistant-ui/tap/react-shim";
|
|
9
3
|
//#region src/react/runtimes/cloud/useCloudThreadListAdapter.tsx
|
|
10
|
-
const toCustom = (value) => isRecord(value) ? value : void 0;
|
|
11
|
-
const baseUrl = typeof process !== "undefined" && process?.env?.NEXT_PUBLIC_ASSISTANT_BASE_URL;
|
|
12
|
-
const autoCloud = baseUrl ? new AssistantCloud({
|
|
13
|
-
baseUrl,
|
|
14
|
-
anonymous: true
|
|
15
|
-
}) : void 0;
|
|
16
|
-
const CLOUD_THREAD_PAGE_SIZE = 20;
|
|
17
|
-
const parseListCursor = (after) => {
|
|
18
|
-
const fallback = {
|
|
19
|
-
activeCursor: after,
|
|
20
|
-
archivedCursor: void 0,
|
|
21
|
-
activeExhausted: false,
|
|
22
|
-
archivedExhausted: false
|
|
23
|
-
};
|
|
24
|
-
if (!after || !after.startsWith("{")) return fallback;
|
|
25
|
-
try {
|
|
26
|
-
const parsed = JSON.parse(after);
|
|
27
|
-
if (!isRecord(parsed)) return fallback;
|
|
28
|
-
return {
|
|
29
|
-
activeCursor: typeof parsed.a === "string" ? parsed.a : void 0,
|
|
30
|
-
archivedCursor: typeof parsed.r === "string" ? parsed.r : void 0,
|
|
31
|
-
activeExhausted: parsed.ae === true,
|
|
32
|
-
archivedExhausted: parsed.re === true
|
|
33
|
-
};
|
|
34
|
-
} catch {
|
|
35
|
-
return fallback;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
const useCloudThreadListAdapters = (adapterRef) => {
|
|
39
|
-
const history = useAssistantCloudThreadHistoryAdapter({ get current() {
|
|
40
|
-
return adapterRef.current.cloud ?? autoCloud;
|
|
41
|
-
} });
|
|
42
|
-
const [attachments] = useState(() => new CloudFileAttachmentAdapter(() => adapterRef.current.cloud ?? autoCloud));
|
|
43
|
-
return useMemo(() => ({
|
|
44
|
-
history,
|
|
45
|
-
attachments
|
|
46
|
-
}), [history, attachments]);
|
|
47
|
-
};
|
|
48
4
|
const useCloudThreadListAdapter = (adapter) => {
|
|
49
5
|
const adapterRef = useRef(adapter);
|
|
50
|
-
|
|
6
|
+
useInsertionEffect(() => {
|
|
51
7
|
adapterRef.current = adapter;
|
|
52
8
|
}, [adapter]);
|
|
53
|
-
const unstable_useAdapters = useCallback(function useCloudAdapters() {
|
|
54
|
-
return useCloudThreadListAdapters(adapterRef);
|
|
55
|
-
}, []);
|
|
56
|
-
const unstable_Provider = useCallback(function Provider({ children }) {
|
|
57
|
-
const adapters = useCloudThreadListAdapters(adapterRef);
|
|
58
|
-
return /* @__PURE__ */ jsx(RuntimeAdapterProvider, {
|
|
59
|
-
adapters,
|
|
60
|
-
children
|
|
61
|
-
});
|
|
62
|
-
}, []);
|
|
63
9
|
const cloud = adapter.cloud ?? autoCloud;
|
|
10
|
+
const base = useMemo(() => createCloudThreadListAdapter(() => ({
|
|
11
|
+
...adapterRef.current,
|
|
12
|
+
cloud
|
|
13
|
+
})), [cloud]);
|
|
14
|
+
const cloudRef = useMemo(() => ({ get current() {
|
|
15
|
+
return adapterRef.current.cloud ?? autoCloud;
|
|
16
|
+
} }), []);
|
|
17
|
+
const unstable_useAdapters = useCallback(function useCloudAdapters() {
|
|
18
|
+
return useCloudRuntimeAdapters(cloudRef);
|
|
19
|
+
}, [cloudRef]);
|
|
64
20
|
return useMemo(() => {
|
|
65
|
-
if (
|
|
66
|
-
const ref = adapterRef;
|
|
67
|
-
const inMemory = new InMemoryThreadListAdapter();
|
|
68
|
-
inMemory.initialize = async (threadId) => {
|
|
69
|
-
return {
|
|
70
|
-
remoteId: threadId,
|
|
71
|
-
externalId: (await ref.current.create?.())?.externalId
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
return inMemory;
|
|
75
|
-
}
|
|
21
|
+
if (base.unstable_useAdapters === void 0) return base;
|
|
76
22
|
return {
|
|
77
|
-
|
|
78
|
-
const { activeCursor, archivedCursor, activeExhausted, archivedExhausted } = parseListCursor(after);
|
|
79
|
-
const [{ threads: activeThreads }, { threads: archivedThreads }] = await Promise.all([activeExhausted ? Promise.resolve({ threads: [] }) : cloud.threads.list({
|
|
80
|
-
limit: CLOUD_THREAD_PAGE_SIZE,
|
|
81
|
-
...activeCursor ? { after: activeCursor } : {}
|
|
82
|
-
}), archivedExhausted ? Promise.resolve({ threads: [] }) : cloud.threads.list({
|
|
83
|
-
is_archived: true,
|
|
84
|
-
limit: CLOUD_THREAD_PAGE_SIZE,
|
|
85
|
-
...archivedCursor ? { after: archivedCursor } : {}
|
|
86
|
-
})]);
|
|
87
|
-
const activeNext = !activeExhausted && activeThreads.length === CLOUD_THREAD_PAGE_SIZE ? activeThreads.at(-1)?.id : void 0;
|
|
88
|
-
const archivedNext = !archivedExhausted && archivedThreads.length === CLOUD_THREAD_PAGE_SIZE ? archivedThreads.at(-1)?.id : void 0;
|
|
89
|
-
return {
|
|
90
|
-
threads: [...activeThreads, ...archivedThreads].map((t) => ({
|
|
91
|
-
status: t.is_archived ? "archived" : "regular",
|
|
92
|
-
remoteId: t.id,
|
|
93
|
-
title: t.title,
|
|
94
|
-
lastMessageAt: t.last_message_at ? new Date(t.last_message_at) : void 0,
|
|
95
|
-
externalId: t.external_id ?? void 0,
|
|
96
|
-
custom: toCustom(t.metadata)
|
|
97
|
-
})),
|
|
98
|
-
nextCursor: activeNext || archivedNext ? JSON.stringify({
|
|
99
|
-
a: activeNext,
|
|
100
|
-
r: archivedNext,
|
|
101
|
-
...activeNext === void 0 ? { ae: true } : {},
|
|
102
|
-
...archivedNext === void 0 ? { re: true } : {}
|
|
103
|
-
}) : void 0
|
|
104
|
-
};
|
|
105
|
-
},
|
|
106
|
-
initialize: async () => {
|
|
107
|
-
const t_0 = await (adapterRef.current.create?.() ?? Promise.resolve());
|
|
108
|
-
const external_id = t_0 ? t_0.externalId : void 0;
|
|
109
|
-
const { thread_id: remoteId } = await cloud.threads.create({
|
|
110
|
-
last_message_at: /* @__PURE__ */ new Date(),
|
|
111
|
-
external_id
|
|
112
|
-
});
|
|
113
|
-
return {
|
|
114
|
-
externalId: external_id,
|
|
115
|
-
remoteId
|
|
116
|
-
};
|
|
117
|
-
},
|
|
118
|
-
rename: async (threadId_0, newTitle) => {
|
|
119
|
-
return cloud.threads.update(threadId_0, { title: newTitle });
|
|
120
|
-
},
|
|
121
|
-
updateCustom: async (threadId_1, custom) => {
|
|
122
|
-
return cloud.threads.update(threadId_1, { metadata: custom ?? null });
|
|
123
|
-
},
|
|
124
|
-
archive: async (threadId_2) => {
|
|
125
|
-
return cloud.threads.update(threadId_2, { is_archived: true });
|
|
126
|
-
},
|
|
127
|
-
unarchive: async (threadId_3) => {
|
|
128
|
-
return cloud.threads.update(threadId_3, { is_archived: false });
|
|
129
|
-
},
|
|
130
|
-
delete: async (threadId_4) => {
|
|
131
|
-
await adapterRef.current.delete?.(threadId_4);
|
|
132
|
-
return cloud.threads.delete(threadId_4);
|
|
133
|
-
},
|
|
134
|
-
generateTitle: async (threadId_5, messages) => {
|
|
135
|
-
const filteredMessages = messages.map((msg) => ({
|
|
136
|
-
...msg,
|
|
137
|
-
content: msg.content.filter((part) => part.type === "text" || part.type === "tool-call")
|
|
138
|
-
}));
|
|
139
|
-
return cloud.runs.stream({
|
|
140
|
-
thread_id: threadId_5,
|
|
141
|
-
assistant_id: "system/thread_title",
|
|
142
|
-
messages: filteredMessages
|
|
143
|
-
});
|
|
144
|
-
},
|
|
145
|
-
fetch: async (threadId_6) => {
|
|
146
|
-
const thread = await cloud.threads.get(threadId_6);
|
|
147
|
-
return {
|
|
148
|
-
status: thread.is_archived ? "archived" : "regular",
|
|
149
|
-
remoteId: thread.id,
|
|
150
|
-
title: thread.title,
|
|
151
|
-
lastMessageAt: thread.last_message_at ? new Date(thread.last_message_at) : void 0,
|
|
152
|
-
externalId: thread.external_id ?? void 0,
|
|
153
|
-
custom: toCustom(thread.metadata)
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
unstable_Provider,
|
|
23
|
+
...base,
|
|
157
24
|
unstable_useAdapters
|
|
158
25
|
};
|
|
159
|
-
}, [
|
|
160
|
-
cloud,
|
|
161
|
-
unstable_Provider,
|
|
162
|
-
unstable_useAdapters
|
|
163
|
-
]);
|
|
26
|
+
}, [base, unstable_useAdapters]);
|
|
164
27
|
};
|
|
165
28
|
//#endregion
|
|
166
29
|
export { useCloudThreadListAdapter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCloudThreadListAdapter.js","names":["process","env","Record","FC","PropsWithChildren","RefObject","useCallback","useEffect","useMemo","useRef","useState","AssistantCloud","RemoteThreadListAdapter","InMemoryThreadListAdapter","useAssistantCloudThreadHistoryAdapter","RuntimeAdapterProvider","RuntimeAdapters","CloudFileAttachmentAdapter","isRecord","ThreadData","externalId","CloudThreadListAdapterOptions","cloud","create","Promise","delete","threadId","toCustom","value","undefined","baseUrl","NEXT_PUBLIC_ASSISTANT_BASE_URL","autoCloud","anonymous","CLOUD_THREAD_PAGE_SIZE","CloudListCursor","activeCursor","archivedCursor","activeExhausted","archivedExhausted","parseListCursor","after","fallback","startsWith","parsed","JSON","parse","a","r","ae","re","useCloudThreadListAdapters","adapterRef","history","current","attachments","useCloudThreadListAdapter","adapter","unstable_useAdapters","useCloudAdapters","unstable_Provider","Provider","children","adapters","ref","inMemory","initialize","result","remoteId","list","threads","activeThreads","archivedThreads","all","resolve","limit","is_archived","activeNext","length","at","id","archivedNext","map","t","status","title","lastMessageAt","last_message_at","Date","external_id","custom","metadata","nextCursor","stringify","createTask","thread_id","rename","newTitle","update","updateCustom","archive","unarchive","generateTitle","messages","filteredMessages","msg","content","filter","part","type","runs","stream","assistant_id","fetch","thread","get"],"sources":["../../../../src/react/runtimes/cloud/useCloudThreadListAdapter.tsx"],"sourcesContent":["declare const process: { env: Record<string, string | undefined> };\n\nimport {\n type FC,\n type PropsWithChildren,\n type RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { AssistantCloud } from \"assistant-cloud\";\nimport type { RemoteThreadListAdapter } from \"../../../runtimes/remote-thread-list/types\";\nimport { InMemoryThreadListAdapter } from \"../../../runtimes/remote-thread-list/adapter/in-memory\";\nimport { useAssistantCloudThreadHistoryAdapter } from \"./AssistantCloudThreadHistoryAdapter\";\nimport {\n RuntimeAdapterProvider,\n type RuntimeAdapters,\n} from \"../RuntimeAdapterProvider\";\nimport { CloudFileAttachmentAdapter } from \"./CloudFileAttachmentAdapter\";\nimport { isRecord } from \"../../../utils/json/is-json\";\n\ntype ThreadData = {\n externalId: string | undefined;\n};\n\ntype CloudThreadListAdapterOptions = {\n cloud?: AssistantCloud | undefined;\n\n create?: (() => Promise<ThreadData>) | undefined;\n delete?: ((threadId: string) => Promise<void>) | undefined;\n};\n\nconst toCustom = (value: unknown): Record<string, unknown> | undefined =>\n isRecord(value) ? value : undefined;\n\nconst baseUrl =\n typeof process !== \"undefined\" &&\n process?.env?.NEXT_PUBLIC_ASSISTANT_BASE_URL;\nconst autoCloud = baseUrl\n ? new AssistantCloud({ baseUrl, anonymous: true })\n : undefined;\n\nconst CLOUD_THREAD_PAGE_SIZE = 20;\n\ntype CloudListCursor = {\n activeCursor: string | undefined;\n archivedCursor: string | undefined;\n activeExhausted: boolean;\n archivedExhausted: boolean;\n};\n\nconst parseListCursor = (after: string | undefined): CloudListCursor => {\n const fallback: CloudListCursor = {\n activeCursor: after,\n archivedCursor: undefined,\n activeExhausted: false,\n archivedExhausted: false,\n };\n if (!after || !after.startsWith(\"{\")) return fallback;\n try {\n const parsed = JSON.parse(after);\n if (!isRecord(parsed)) return fallback;\n return {\n activeCursor: typeof parsed.a === \"string\" ? parsed.a : undefined,\n archivedCursor: typeof parsed.r === \"string\" ? parsed.r : undefined,\n activeExhausted: parsed.ae === true,\n archivedExhausted: parsed.re === true,\n };\n } catch {\n return fallback;\n }\n};\n\nconst useCloudThreadListAdapters = (\n adapterRef: RefObject<CloudThreadListAdapterOptions>,\n): RuntimeAdapters => {\n const history = useAssistantCloudThreadHistoryAdapter({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n });\n const [attachments] = useState(\n () =>\n new CloudFileAttachmentAdapter(\n () => adapterRef.current.cloud ?? autoCloud!,\n ),\n );\n return useMemo(\n () => ({\n history,\n attachments,\n }),\n [history, attachments],\n );\n};\n\nexport const useCloudThreadListAdapter = (\n adapter: CloudThreadListAdapterOptions,\n): RemoteThreadListAdapter => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const unstable_useAdapters = useCallback(function useCloudAdapters() {\n return useCloudThreadListAdapters(adapterRef);\n }, []);\n\n const unstable_Provider = useCallback<FC<PropsWithChildren>>(\n function Provider({ children }) {\n const adapters = useCloudThreadListAdapters(adapterRef);\n return (\n <RuntimeAdapterProvider adapters={adapters}>\n {children}\n </RuntimeAdapterProvider>\n );\n },\n [],\n );\n\n const cloud = adapter.cloud ?? autoCloud;\n return useMemo<RemoteThreadListAdapter>(() => {\n if (!cloud) {\n const ref = adapterRef;\n const inMemory = new InMemoryThreadListAdapter();\n inMemory.initialize = async (threadId: string) => {\n const result = await ref.current.create?.();\n return { remoteId: threadId, externalId: result?.externalId };\n };\n return inMemory;\n }\n\n return {\n list: async ({ after } = {}) => {\n const {\n activeCursor,\n archivedCursor,\n activeExhausted,\n archivedExhausted,\n } = parseListCursor(after);\n const [{ threads: activeThreads }, { threads: archivedThreads }] =\n await Promise.all([\n activeExhausted\n ? Promise.resolve({ threads: [] })\n : cloud.threads.list({\n limit: CLOUD_THREAD_PAGE_SIZE,\n ...(activeCursor ? { after: activeCursor } : {}),\n }),\n archivedExhausted\n ? Promise.resolve({ threads: [] })\n : cloud.threads.list({\n is_archived: true,\n limit: CLOUD_THREAD_PAGE_SIZE,\n ...(archivedCursor ? { after: archivedCursor } : {}),\n }),\n ]);\n const activeNext =\n !activeExhausted && activeThreads.length === CLOUD_THREAD_PAGE_SIZE\n ? activeThreads.at(-1)?.id\n : undefined;\n const archivedNext =\n !archivedExhausted &&\n archivedThreads.length === CLOUD_THREAD_PAGE_SIZE\n ? archivedThreads.at(-1)?.id\n : undefined;\n const threads = [...activeThreads, ...archivedThreads];\n return {\n threads: threads.map((t) => ({\n status: t.is_archived ? \"archived\" : \"regular\",\n remoteId: t.id,\n title: t.title,\n lastMessageAt: t.last_message_at\n ? new Date(t.last_message_at)\n : undefined,\n externalId: t.external_id ?? undefined,\n custom: toCustom(t.metadata),\n })),\n nextCursor:\n activeNext || archivedNext\n ? JSON.stringify({\n a: activeNext,\n r: archivedNext,\n ...(activeNext === undefined ? { ae: true } : {}),\n ...(archivedNext === undefined ? { re: true } : {}),\n })\n : undefined,\n };\n },\n\n initialize: async () => {\n const createTask = adapterRef.current.create?.() ?? Promise.resolve();\n const t = await createTask;\n const external_id = t ? t.externalId : undefined;\n const { thread_id: remoteId } = await cloud.threads.create({\n last_message_at: new Date(),\n external_id,\n });\n\n return { externalId: external_id, remoteId: remoteId };\n },\n\n rename: async (threadId, newTitle) => {\n return cloud.threads.update(threadId, { title: newTitle });\n },\n updateCustom: async (threadId, custom) => {\n return cloud.threads.update(threadId, { metadata: custom ?? null });\n },\n archive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapterRef.current.delete?.(threadId);\n return cloud.threads.delete(threadId);\n },\n\n generateTitle: async (threadId, messages) => {\n // Filter messages to only include content types the title generator understands\n // (reasoning, source, etc. are not needed for title generation)\n // TODO serialize these to a more efficient format\n const filteredMessages = messages.map((msg) => ({\n ...msg,\n content: msg.content.filter(\n (part) => part.type === \"text\" || part.type === \"tool-call\",\n ),\n }));\n\n return cloud.runs.stream({\n thread_id: threadId,\n assistant_id: \"system/thread_title\",\n messages: filteredMessages,\n });\n },\n\n fetch: async (threadId: string) => {\n const thread = await cloud.threads.get(threadId);\n return {\n status: thread.is_archived ? \"archived\" : \"regular\",\n remoteId: thread.id,\n title: thread.title,\n lastMessageAt: thread.last_message_at\n ? new Date(thread.last_message_at)\n : undefined,\n externalId: thread.external_id ?? undefined,\n custom: toCustom(thread.metadata),\n };\n },\n\n unstable_Provider,\n unstable_useAdapters,\n };\n }, [cloud, unstable_Provider, unstable_useAdapters]);\n};\n"],"mappings":";;;;;;;;;AAkCA,MAAM2B,YAAYC,UAChBV,SAASU,KAAK,IAAIA,QAAQC,KAAAA;AAE5B,MAAMC,UACJ,OAAO9B,YAAY,eACnBA,SAASC,KAAK8B;AAChB,MAAMC,YAAYF,UACd,IAAInB,eAAe;CAAEmB;CAASG,WAAW;AAAK,CAAC,IAC/CJ,KAAAA;AAEJ,MAAMK,yBAAyB;AAS/B,MAAMM,mBAAmBC,UAA+C;CACtE,MAAMC,WAA4B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,MAAMgD,QAAQ7C,OAAOC,UAAQ;GACtC;GAEA4E,eAAe,OAAO5E,YAAU6E,aAAa;IAI3C,MAAMC,mBAAmBD,SAASrB,KAAKuB,SAAS;KAC9C,GAAGA;KACHC,SAASD,IAAIC,QAAQC,QAClBC,SAASA,KAAKC,SAAS,UAAUD,KAAKC,SAAS,WAClD;IACF,EAAE;IAEF,OAAOvF,MAAMwF,KAAKC,OAAO;KACvBhB,WAAWrE;KACXsF,cAAc;KACdT,UAAUC;IACZ,CAAC;GACH;GAEAS,OAAO,OAAOvF,eAAqB;IACjC,MAAMwF,SAAS,MAAM5F,MAAMgD,QAAQ6C,IAAIzF,UAAQ;IAC/C,OAAO;KACL0D,QAAQ8B,OAAOtC,cAAc,aAAa;KAC1CR,UAAU8C,OAAOlC;KACjBK,OAAO6B,OAAO7B;KACdC,eAAe4B,OAAO3B,kBAClB,IAAIC,KAAK0B,OAAO3B,eAAe,IAC/B1D,KAAAA;KACJT,YAAY8F,OAAOzB,eAAe5D,KAAAA;KAClC6D,QAAQ/D,SAASuF,OAAOvB,QAAQ;IAClC;GACF;GAEA/B;GACAF;EACF;CACF,GAAG;EAACpC;EAAOsC;EAAmBF;CAAoB,CAAC;AACrD"}
|
|
1
|
+
{"version":3,"file":"useCloudThreadListAdapter.js","names":["useCallback","useInsertionEffect","useMemo","useRef","RemoteThreadListAdapter","autoCloud","createCloudThreadListAdapter","CloudThreadListAdapterOptions","useCloudRuntimeAdapters","useCloudThreadListAdapter","adapter","adapterRef","current","cloud","base","cloudRef","unstable_useAdapters","useCloudAdapters","undefined"],"sources":["../../../../src/react/runtimes/cloud/useCloudThreadListAdapter.tsx"],"sourcesContent":["import { useCallback, useInsertionEffect, useMemo, useRef } from \"react\";\nimport type { RemoteThreadListAdapter } from \"../../../runtimes/remote-thread-list/types\";\nimport {\n autoCloud,\n createCloudThreadListAdapter,\n type CloudThreadListAdapterOptions,\n useCloudRuntimeAdapters,\n} from \"./createCloudThreadListAdapter\";\n\nexport const useCloudThreadListAdapter = (\n adapter: CloudThreadListAdapterOptions,\n): RemoteThreadListAdapter => {\n const adapterRef = useRef(adapter);\n useInsertionEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const cloud = adapter.cloud ?? autoCloud;\n const base = useMemo(\n () =>\n createCloudThreadListAdapter(() => ({\n ...adapterRef.current,\n cloud,\n })),\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- the factory pins the cloud instance; changing callbacks are read from the committed ref\n [cloud],\n );\n\n const cloudRef = useMemo(\n () => ({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n }),\n [],\n );\n\n const unstable_useAdapters = useCallback(\n function useCloudAdapters() {\n return useCloudRuntimeAdapters(cloudRef);\n },\n [cloudRef],\n );\n\n return useMemo<RemoteThreadListAdapter>(() => {\n if (base.unstable_useAdapters === undefined) return base;\n return {\n ...base,\n unstable_useAdapters,\n };\n }, [base, unstable_useAdapters]);\n};\n"],"mappings":";;;AASA,MAAaS,6BACXC,YAC4B;CAC5B,MAAMC,aAAaR,OAAOO,OAAO;CACjCT,yBAAyB;EACvBU,WAAWC,UAAUF;CACvB,GAAG,CAACA,OAAO,CAAC;CAEZ,MAAMG,QAAQH,QAAQG,SAASR;CAC/B,MAAMS,OAAOZ,cAETI,oCAAoC;EAClC,GAAGK,WAAWC;EACdC;CACF,EAAE,GAEJ,CAACA,KAAK,CACR;CAEA,MAAME,WAAWb,eACR,EACL,IAAIU,UAAU;EACZ,OAAOD,WAAWC,QAAQC,SAASR;CACrC,EACF,IACA,CAAA,CACF;CAEA,MAAMW,uBAAuBhB,YAC3B,SAASiB,mBAAmB;EAC1B,OAAOT,wBAAwBO,QAAQ;CACzC,GACA,CAACA,QAAQ,CACX;CAEA,OAAOb,cAAuC;EAC5C,IAAIY,KAAKE,yBAAyBE,KAAAA,GAAW,OAAOJ;EACpD,OAAO;GACL,GAAGA;GACHE;EACF;CACF,GAAG,CAACF,MAAME,oBAAoB,CAAC;AACjC"}
|
|
@@ -62,7 +62,7 @@ const useExternalMessageConverter = (t0) => {
|
|
|
62
62
|
const threadMessages = state.converterCache.convertMessages(chunks, (cache, message_1, idx) => convertExternalMessageChunk(message_1, idx, chunks.length, isRunning, state.metadata.error, {
|
|
63
63
|
message: cache,
|
|
64
64
|
generatedFallbackMessages
|
|
65
|
-
}));
|
|
65
|
+
}, state.metadata.cancelledMessageIds));
|
|
66
66
|
bindExternalStoreMessage(threadMessages, messages);
|
|
67
67
|
t3 = completeExternalMessageConversion(threadMessages, state.metadata.error);
|
|
68
68
|
$[6] = isRunning;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-message-converter.js","names":["c","_c","useMemo","useState","chunkExternalMessages","completeExternalMessageConversion","convertExternalMessageCallback","convertExternalMessageChunk","convertExternalMessages","convertExternalMessagesInternal","shallowArrayEqual","ExternalMessageConverterCallback","ExternalMessageConverterCallbackResult","ExternalMessageConverterChunk","ExternalMessageConverterMessage","ExternalMessageConverterMetadata","JoinStrategy","bindExternalStoreMessage","ThreadMessageConverter","ThreadMessage","generatedFallbackMessages","WeakSet","useExternalMessageConverter","Message","Metadata","Callback","T","WeakKey","messages","callback","isRunning","metadata","CallbackCacheEntry","t0","$","joinStrategy","caches","_temp","t1","t2","state","t3","callbackCache","chunkCache","converterCache","callbackResults","message","result","get","set","push","t4","message_0","key","outputs","cached","chunks","map","threadMessages","convertMessages","cache","message_1","idx","length","error","WeakMap"],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport {\n chunkExternalMessages,\n completeExternalMessageConversion,\n convertExternalMessageCallback,\n convertExternalMessageChunk,\n convertExternalMessages as convertExternalMessagesInternal,\n shallowArrayEqual,\n type ExternalMessageConverterCallback,\n type ExternalMessageConverterCallbackResult,\n type ExternalMessageConverterChunk,\n type ExternalMessageConverterMessage,\n type ExternalMessageConverterMetadata,\n type JoinStrategy,\n} from \"../../runtime/utils/external-message-conversion\";\nimport { bindExternalStoreMessage } from \"../../runtime/utils/external-store-message\";\nimport { ThreadMessageConverter } from \"../../runtimes/external-store/thread-message-converter\";\nimport type { ThreadMessage } from \"../../types/message\";\n\n// Generatedness is tracked by identity, not by id shape: a caller-supplied id\n// that happens to match the generated pattern must never be rewritten.\nconst generatedFallbackMessages = new WeakSet<object>();\n\nexport type { JoinStrategy };\n\nexport namespace useExternalMessageConverter {\n export type Message = ExternalMessageConverterMessage;\n export type Metadata = ExternalMessageConverterMetadata;\n export type Callback<T> = ExternalMessageConverterCallback<T>;\n}\n\nexport const convertExternalMessages: <T extends WeakKey>(\n messages: T[],\n callback: useExternalMessageConverter.Callback<T>,\n isRunning: boolean,\n metadata: useExternalMessageConverter.Metadata,\n) => ThreadMessage[] = convertExternalMessagesInternal;\n\ntype CallbackCacheEntry<T> = ExternalMessageConverterCallbackResult<T> & {\n metadata: useExternalMessageConverter.Metadata;\n callback: useExternalMessageConverter.Callback<T>;\n};\n\nexport const useExternalMessageConverter = <T extends WeakKey>({\n callback,\n messages,\n isRunning,\n joinStrategy,\n metadata,\n}: {\n callback: useExternalMessageConverter.Callback<T>;\n messages: T[];\n isRunning: boolean;\n joinStrategy?: JoinStrategy | undefined;\n metadata?: useExternalMessageConverter.Metadata | undefined;\n}) => {\n // The caches live for the component lifetime; React Compiler hoists\n // allocations without reactive dependencies out of useMemo, so re-creating\n // them on dependency change would not survive compilation. Staleness is\n // instead tracked per entry via the metadata/callback that produced it,\n // keeping correctness independent of memoization (which React treats as\n // droppable). A \"use no memo\" opt-out would restore the useMemo semantics\n // but leave cache flushing coupled to memo firing.\n const [caches] = useState(() => ({\n callbackCache: new WeakMap<T, CallbackCacheEntry<T>>(),\n chunkCache: new WeakMap<\n ExternalMessageConverterMessage,\n ExternalMessageConverterChunk<T>\n >(),\n converterCache: new ThreadMessageConverter(),\n }));\n\n const state = useMemo(\n () => ({\n metadata: metadata ?? {},\n callback,\n ...caches,\n }),\n [callback, metadata, caches],\n );\n\n return useMemo(() => {\n const callbackResults: ExternalMessageConverterCallbackResult<T>[] = [];\n for (const message of messages) {\n let result = state.callbackCache.get(message);\n if (\n !result ||\n result.metadata !== state.metadata ||\n result.callback !== state.callback\n ) {\n result = {\n ...convertExternalMessageCallback(\n message,\n state.callback,\n state.metadata,\n ),\n metadata: state.metadata,\n callback: state.callback,\n };\n state.callbackCache.set(message, result);\n }\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults, joinStrategy).map(\n (message) => {\n const key = message.outputs[0];\n if (!key) return message;\n\n const cached = state.chunkCache.get(key);\n if (cached && shallowArrayEqual(cached.outputs, message.outputs)) {\n return cached;\n }\n state.chunkCache.set(key, message);\n return message;\n },\n );\n\n const threadMessages = state.converterCache.convertMessages(\n chunks,\n (cache, message, idx) =>\n convertExternalMessageChunk(\n message,\n idx,\n chunks.length,\n isRunning,\n state.metadata.error,\n {\n message: cache,\n generatedFallbackMessages,\n },\n ),\n );\n\n bindExternalStoreMessage(threadMessages, messages);\n return completeExternalMessageConversion(\n threadMessages,\n state.metadata.error,\n );\n }, [state, messages, isRunning, joinStrategy]);\n};\n"],"mappings":";;;;;;;AAuBA,MAAMoB,4CAA4B,IAAIC,QAAgB;AAUtD,MAAab,0BAKUC;AAOvB,MAAaa,+BAA8BW,OAAA;CAAA,MAAAC,IAAAjC,EAAA,EAAA;CAAoB,MAAA,EAAA4B,UAAAD,UAAAE,WAAAK,cAAAJ,aAAAE;CAoB7D,MAAA,CAAAG,UAAiBjC,SAASkC,KAOxB;CAAE,IAAAC;CAAA,IAAAJ,EAAA,OAAAH,UAAA;EAIUO,KAAAP,YAAA,CAAa;EAACG,EAAA,KAAAH;EAAAG,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,IAAAK;CAAA,IAAAL,EAAA,OAAAE,UAAAF,EAAA,OAAAL,YAAAK,EAAA,OAAAI,IAAA;EADnBC,KAAA;GAAAR,UACKO;GAAcT;GAAA,GAErBO;EACL;EAACF,EAAA,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BAAuBlB,MAAKI,eAAee,gBACzCH,SACAI,OAAAC,WAAAC,QACEvD,4BACEuC,WACAgB,KACAN,OAAMO,QACNjC,WACAU,MAAKT,SAASiC,OACd;GAAAlB,SACWc;GAAKxC;EAEhB,
|
|
1
|
+
{"version":3,"file":"external-message-converter.js","names":["c","_c","useMemo","useState","chunkExternalMessages","completeExternalMessageConversion","convertExternalMessageCallback","convertExternalMessageChunk","convertExternalMessages","convertExternalMessagesInternal","shallowArrayEqual","ExternalMessageConverterCallback","ExternalMessageConverterCallbackResult","ExternalMessageConverterChunk","ExternalMessageConverterMessage","ExternalMessageConverterMetadata","JoinStrategy","bindExternalStoreMessage","ThreadMessageConverter","ThreadMessage","generatedFallbackMessages","WeakSet","useExternalMessageConverter","Message","Metadata","Callback","T","WeakKey","messages","callback","isRunning","metadata","CallbackCacheEntry","t0","$","joinStrategy","caches","_temp","t1","t2","state","t3","callbackCache","chunkCache","converterCache","callbackResults","message","result","get","set","push","t4","message_0","key","outputs","cached","chunks","map","threadMessages","convertMessages","cache","message_1","idx","length","error","cancelledMessageIds","WeakMap"],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport {\n chunkExternalMessages,\n completeExternalMessageConversion,\n convertExternalMessageCallback,\n convertExternalMessageChunk,\n convertExternalMessages as convertExternalMessagesInternal,\n shallowArrayEqual,\n type ExternalMessageConverterCallback,\n type ExternalMessageConverterCallbackResult,\n type ExternalMessageConverterChunk,\n type ExternalMessageConverterMessage,\n type ExternalMessageConverterMetadata,\n type JoinStrategy,\n} from \"../../runtime/utils/external-message-conversion\";\nimport { bindExternalStoreMessage } from \"../../runtime/utils/external-store-message\";\nimport { ThreadMessageConverter } from \"../../runtimes/external-store/thread-message-converter\";\nimport type { ThreadMessage } from \"../../types/message\";\n\n// Generatedness is tracked by identity, not by id shape: a caller-supplied id\n// that happens to match the generated pattern must never be rewritten.\nconst generatedFallbackMessages = new WeakSet<object>();\n\nexport type { JoinStrategy };\n\nexport namespace useExternalMessageConverter {\n export type Message = ExternalMessageConverterMessage;\n export type Metadata = ExternalMessageConverterMetadata;\n export type Callback<T> = ExternalMessageConverterCallback<T>;\n}\n\nexport const convertExternalMessages: <T extends WeakKey>(\n messages: T[],\n callback: useExternalMessageConverter.Callback<T>,\n isRunning: boolean,\n metadata: useExternalMessageConverter.Metadata,\n) => ThreadMessage[] = convertExternalMessagesInternal;\n\ntype CallbackCacheEntry<T> = ExternalMessageConverterCallbackResult<T> & {\n metadata: useExternalMessageConverter.Metadata;\n callback: useExternalMessageConverter.Callback<T>;\n};\n\nexport const useExternalMessageConverter = <T extends WeakKey>({\n callback,\n messages,\n isRunning,\n joinStrategy,\n metadata,\n}: {\n callback: useExternalMessageConverter.Callback<T>;\n messages: T[];\n isRunning: boolean;\n joinStrategy?: JoinStrategy | undefined;\n metadata?: useExternalMessageConverter.Metadata | undefined;\n}) => {\n // The caches live for the component lifetime; React Compiler hoists\n // allocations without reactive dependencies out of useMemo, so re-creating\n // them on dependency change would not survive compilation. Staleness is\n // instead tracked per entry via the metadata/callback that produced it,\n // keeping correctness independent of memoization (which React treats as\n // droppable). A \"use no memo\" opt-out would restore the useMemo semantics\n // but leave cache flushing coupled to memo firing.\n const [caches] = useState(() => ({\n callbackCache: new WeakMap<T, CallbackCacheEntry<T>>(),\n chunkCache: new WeakMap<\n ExternalMessageConverterMessage,\n ExternalMessageConverterChunk<T>\n >(),\n converterCache: new ThreadMessageConverter(),\n }));\n\n const state = useMemo(\n () => ({\n metadata: metadata ?? {},\n callback,\n ...caches,\n }),\n [callback, metadata, caches],\n );\n\n return useMemo(() => {\n const callbackResults: ExternalMessageConverterCallbackResult<T>[] = [];\n for (const message of messages) {\n let result = state.callbackCache.get(message);\n if (\n !result ||\n result.metadata !== state.metadata ||\n result.callback !== state.callback\n ) {\n result = {\n ...convertExternalMessageCallback(\n message,\n state.callback,\n state.metadata,\n ),\n metadata: state.metadata,\n callback: state.callback,\n };\n state.callbackCache.set(message, result);\n }\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults, joinStrategy).map(\n (message) => {\n const key = message.outputs[0];\n if (!key) return message;\n\n const cached = state.chunkCache.get(key);\n if (cached && shallowArrayEqual(cached.outputs, message.outputs)) {\n return cached;\n }\n state.chunkCache.set(key, message);\n return message;\n },\n );\n\n const threadMessages = state.converterCache.convertMessages(\n chunks,\n (cache, message, idx) =>\n convertExternalMessageChunk(\n message,\n idx,\n chunks.length,\n isRunning,\n state.metadata.error,\n {\n message: cache,\n generatedFallbackMessages,\n },\n state.metadata.cancelledMessageIds,\n ),\n );\n\n bindExternalStoreMessage(threadMessages, messages);\n return completeExternalMessageConversion(\n threadMessages,\n state.metadata.error,\n );\n }, [state, messages, isRunning, joinStrategy]);\n};\n"],"mappings":";;;;;;;AAuBA,MAAMoB,4CAA4B,IAAIC,QAAgB;AAUtD,MAAab,0BAKUC;AAOvB,MAAaa,+BAA8BW,OAAA;CAAA,MAAAC,IAAAjC,EAAA,EAAA;CAAoB,MAAA,EAAA4B,UAAAD,UAAAE,WAAAK,cAAAJ,aAAAE;CAoB7D,MAAA,CAAAG,UAAiBjC,SAASkC,KAOxB;CAAE,IAAAC;CAAA,IAAAJ,EAAA,OAAAH,UAAA;EAIUO,KAAAP,YAAA,CAAa;EAACG,EAAA,KAAAH;EAAAG,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,IAAAK;CAAA,IAAAL,EAAA,OAAAE,UAAAF,EAAA,OAAAL,YAAAK,EAAA,OAAAI,IAAA;EADnBC,KAAA;GAAAR,UACKO;GAAcT;GAAA,GAErBO;EACL;EAACF,EAAA,KAAAE;EAAAF,EAAA,KAAAL;EAAAK,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CALH,MAAAM,QACSD;CAMP,IAAAE;CAAA,IAAAP,EAAA,OAAAJ,aAAAI,EAAA,OAAAC,gBAAAD,EAAA,O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D,yBAAyByC,gBAAgB9B,QAAQ;EAC1Ca,KAAApC,kCACLqD,gBACAlB,MAAKT,SAASiC,KAChB;EAAC9B,EAAA,KAAAJ;EAAAI,EAAA,KAAAC;EAAAD,EAAA,KAAAN;EAAAM,EAAA,KAAAM,MAAAX;EAAAK,EAAA,MAAAM,MAAAE;EAAAR,EAAA,MAAAM,MAAAG;EAAAT,EAAA,MAAAM,MAAAI;EAAAV,EAAA,MAAAM,MAAAT;EAAAG,EAAA,MAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,OAHDO;AAGE;AAhGqC,SAAAJ,QAAA;CAAA,OAoBR;EAAAK,+BAChB,IAAIwB,QAAkC;EAACvB,4BAC1C,IAAIuB,QAGd;EAACtB,gBACa,IAAI1B,uBAAuB;CAC7C;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoteThreadListRuntime.d.ts","names":[],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"useRemoteThreadListRuntime.d.ts","names":[],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"mappings":";;;cAiDa,6BACX,SAAS,4BACR"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { WritableSubscribable } from "../../subscribable/subscribable.js";
|
|
1
2
|
import { BaseAssistantRuntimeCore } from "../../runtime/base/base-assistant-runtime-core.js";
|
|
2
3
|
import { AssistantRuntimeImpl } from "../../runtime/api/assistant-runtime.js";
|
|
4
|
+
import { useSubscribable } from "../../store/runtime-clients/useSubscribable.js";
|
|
3
5
|
import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore.js";
|
|
4
6
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
5
7
|
import { useCallback, useEffect, useEffectEvent, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
@@ -51,12 +53,18 @@ const useRemoteThreadListRuntimeImpl = (options) => {
|
|
|
51
53
|
return t3;
|
|
52
54
|
};
|
|
53
55
|
const useRemoteThreadListRuntime = (options) => {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
+
const [runtimeHookStore] = useState(() => new WritableSubscribable(options.runtimeHook));
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
runtimeHookStore.setState(options.runtimeHook);
|
|
59
|
+
}, [runtimeHookStore, options.runtimeHook]);
|
|
56
60
|
const initialThreadIdRef = useRef(options.initialThreadId);
|
|
57
|
-
const stableRuntimeHook = useCallback(()
|
|
58
|
-
return
|
|
59
|
-
|
|
61
|
+
const stableRuntimeHook = useCallback(function useCommittedRuntimeHook() {
|
|
62
|
+
return useSubscribable({
|
|
63
|
+
subscribe: runtimeHookStore.subscribe,
|
|
64
|
+
getState: runtimeHookStore.getState,
|
|
65
|
+
getServerSnapshot: runtimeHookStore.getState
|
|
66
|
+
})();
|
|
67
|
+
}, [runtimeHookStore]);
|
|
60
68
|
const onThreadIdChange = useEffectEvent((threadId) => {
|
|
61
69
|
options.onThreadIdChange?.(threadId);
|
|
62
70
|
});
|
|
@@ -75,7 +83,7 @@ const useRemoteThreadListRuntime = (options) => {
|
|
|
75
83
|
]);
|
|
76
84
|
if (useAui().threadListItem.source !== null) {
|
|
77
85
|
if (!stableOptions.allowNesting) throw new Error("useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. Set allowNesting: true to allow nesting (the inner runtime will become a no-op).");
|
|
78
|
-
return
|
|
86
|
+
return options.runtimeHook();
|
|
79
87
|
}
|
|
80
88
|
return useRemoteThreadListRuntimeImpl(stableOptions);
|
|
81
89
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoteThreadListRuntime.js","names":["useState","useEffect","useMemo","useRef","useCallback","useEffectEvent","BaseAssistantRuntimeCore","AssistantRuntimeImpl","RemoteThreadListOptions","AssistantRuntimeCore","AssistantRuntime","RemoteThreadListThreadListRuntimeCore","useAui","RemoteThreadListRuntimeCore","threads","constructor","options","_contextProvider","RenderComponent","__internal_RenderComponent","useRemoteThreadListRuntimeImpl","$","_c","t0","runtime","t1","__internal_setOptions","__internal_load","t2","t3","useRemoteThreadListRuntime","
|
|
1
|
+
{"version":3,"file":"useRemoteThreadListRuntime.js","names":["useState","useEffect","useMemo","useRef","useCallback","useEffectEvent","BaseAssistantRuntimeCore","AssistantRuntimeImpl","RemoteThreadListOptions","AssistantRuntimeCore","AssistantRuntime","RemoteThreadListThreadListRuntimeCore","WritableSubscribable","useSubscribable","useAui","RemoteThreadListRuntimeCore","threads","constructor","options","_contextProvider","RenderComponent","__internal_RenderComponent","useRemoteThreadListRuntimeImpl","$","_c","t0","runtime","t1","__internal_setOptions","__internal_load","t2","t3","useRemoteThreadListRuntime","runtimeHookStore","runtimeHook","setState","initialThreadIdRef","initialThreadId","stableRuntimeHook","useCommittedRuntimeHook","subscribe","getState","getServerSnapshot","onThreadIdChange","threadId","stableOptions","adapter","allowNesting","current","aui","isNested","threadListItem","source","Error"],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"sourcesContent":["import {\n useState,\n useEffect,\n useMemo,\n useRef,\n useCallback,\n useEffectEvent,\n} from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../../runtime/base/base-assistant-runtime-core\";\nimport { AssistantRuntimeImpl } from \"../../runtime/api/assistant-runtime\";\nimport type { RemoteThreadListOptions } from \"../../runtimes/remote-thread-list/types\";\nimport type { AssistantRuntimeCore } from \"../../runtime/interfaces/assistant-runtime-core\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { WritableSubscribable } from \"../../subscribable/subscribable\";\nimport { useSubscribable } from \"../../store/runtime-clients/useSubscribable\";\nimport { useAui } from \"@assistant-ui/store\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(options: RemoteThreadListOptions) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(\n options,\n this._contextProvider,\n );\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nconst useRemoteThreadListRuntimeImpl = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));\n useEffect(() => {\n runtime.threads.__internal_setOptions(options);\n runtime.threads.__internal_load();\n }, [runtime, options]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const useRemoteThreadListRuntime = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const [runtimeHookStore] = useState(\n () => new WritableSubscribable(options.runtimeHook),\n );\n useEffect(() => {\n runtimeHookStore.setState(options.runtimeHook);\n }, [runtimeHookStore, options.runtimeHook]);\n\n const initialThreadIdRef = useRef(options.initialThreadId);\n\n // Thread resources subscribe to the store rather than reading a ref, so a\n // hook published at commit reaches exactly the resources that use it and an\n // abandoned render publishes nothing. The store pins its server snapshot to\n // the constructor value for hydration, which tap reads on any never-mounted\n // fiber, so the live state serves as the server snapshot here.\n const stableRuntimeHook = useCallback(\n function useCommittedRuntimeHook() {\n return useSubscribable({\n subscribe: runtimeHookStore.subscribe,\n getState: runtimeHookStore.getState,\n getServerSnapshot: runtimeHookStore.getState,\n })();\n },\n [runtimeHookStore],\n );\n\n const onThreadIdChange = useEffectEvent((threadId: string | undefined) => {\n options.onThreadIdChange?.(threadId);\n });\n\n const stableOptions = useMemo<RemoteThreadListOptions>(\n () => ({\n adapter: options.adapter,\n allowNesting: options.allowNesting,\n threadId: options.threadId,\n initialThreadId: initialThreadIdRef.current,\n runtimeHook: stableRuntimeHook,\n onThreadIdChange,\n }),\n [\n options.adapter,\n options.allowNesting,\n options.threadId,\n stableRuntimeHook,\n ],\n );\n\n const aui = useAui();\n const isNested = aui.threadListItem.source !== null;\n\n if (isNested) {\n if (!stableOptions.allowNesting) {\n throw new Error(\n \"useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. \" +\n \"Set allowNesting: true to allow nesting (the inner runtime will become a no-op).\",\n );\n }\n\n // If allowNesting is true and already inside a thread list context,\n // just call the runtimeHook directly (no-op behavior)\n return options.runtimeHook();\n }\n\n const runtime = useRemoteThreadListRuntimeImpl(stableOptions);\n\n return runtime;\n};\n"],"mappings":";;;;;;;;;AAkBA,IAAMe,8BAAN,cACUT,yBAEV;CACE;CAEAW,YAAYC,SAAkC;EAC5C,MAAM;EACN,KAAKF,UAAU,IAAIL,sCACjBO,SACA,KAAKC,gBACP;CACF;CAEA,IAAWC,kBAAkB;EAC3B,OAAO,KAAKJ,QAAQK;CACtB;AACF;AAEA,MAAMC,kCAAiCJ,YAAA;CAAA,MAAAK,IAAAC,EAAA,EAAA;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAL,SAAA;EAGVO,WAAM,IAAIV,4BAA4BG,OAAO;EAACK,EAAA,KAAAL;EAAAK,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAzE,MAAA,CAAAG,WAAkB1B,SAASyB,EAA8C;CAAE,IAAAE;CAAA,IAAAJ,EAAA,OAAAL,WAAAK,EAAA,OAAAG,QAAAV,SAAA;EACjEW,WAAA;GACRD,QAAOV,QAAQY,sBAAuBV,OAAO;GAC7CQ,QAAOV,QAAQa,gBAAiB;EAAC;EAClCN,EAAA,KAAAL;EAAAK,EAAA,KAAAG,QAAAV;EAAAO,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,IAAAO;CAAA,IAAAP,EAAA,OAAAL,WAAAK,EAAA,OAAAG,SAAA;EAAEI,KAAA,CAACJ,SAASR,OAAO;EAACK,EAAA,KAAAL;EAAAK,EAAA,KAAAG;EAAAH,EAAA,KAAAO;CAAA,OAAAA,KAAAP,EAAA;CAHrBtB,UAAU0B,IAGPG,EAAkB;CAAC,IAAAC;CAAA,IAAAR,EAAA,OAAAG,SAAA;EAEDK,KAAA,IAAIxB,qBAAqBmB,OAAO;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CAAA,OAAjCQ;AAAiC;AAGxD,MAAaC,8BACXd,YACqB;CACrB,MAAM,CAACe,oBAAoBjC,eACnB,IAAIY,qBAAqBM,QAAQgB,WAAW,CACpD;CACAjC,gBAAgB;EACdgC,iBAAiBE,SAASjB,QAAQgB,WAAW;CAC/C,GAAG,CAACD,kBAAkBf,QAAQgB,WAAW,CAAC;CAE1C,MAAME,qBAAqBjC,OAAOe,QAAQmB,eAAe;CAOzD,MAAMC,oBAAoBlC,YACxB,SAASmC,0BAA0B;EACjC,OAAO1B,gBAAgB;GACrB2B,WAAWP,iBAAiBO;GAC5BC,UAAUR,iBAAiBQ;GAC3BC,mBAAmBT,iBAAiBQ;EACtC,CAAC,CAAC,CAAC;CACL,GACA,CAACR,gBAAgB,CACnB;CAEA,MAAMU,mBAAmBtC,gBAAgBuC,aAAiC;EACxE1B,QAAQyB,mBAAmBC,QAAQ;CACrC,CAAC;CAED,MAAMC,gBAAgB3C,eACb;EACL4C,SAAS5B,QAAQ4B;EACjBC,cAAc7B,QAAQ6B;EACtBH,UAAU1B,QAAQ0B;EAClBP,iBAAiBD,mBAAmBY;EACpCd,aAAaI;EACbK;CACF,IACA;EACEzB,QAAQ4B;EACR5B,QAAQ6B;EACR7B,QAAQ0B;EACRN;CAAiB,CAErB;CAKA,IAHYxB,OACKmC,CAAG,CAACE,eAAeC,WAAW,MAEjC;EACZ,IAAI,CAACP,cAAcE,cACjB,MAAM,IAAIM,MACR,sKAEF;EAKF,OAAOnC,QAAQgB,YAAY;CAC7B;CAIA,OAFgBZ,+BAA+BuB,aAExCnB;AACT"}
|
|
@@ -52,10 +52,14 @@ type ToolCallMessagePartProps<TArgs = any, TResult = unknown> = MessagePartState
|
|
|
52
52
|
/**
|
|
53
53
|
* Responds to a server-side tool approval gate. Only valid while
|
|
54
54
|
* `approval` is set on the part, `approval.approved === undefined`, and
|
|
55
|
-
* no `approval.resolution` is recorded. Accepts a boolean decision
|
|
56
|
-
* id of one of `approval.options
|
|
55
|
+
* no `approval.resolution` is recorded. Accepts a boolean decision, the
|
|
56
|
+
* id of one of `approval.options` (option kinds resolve to the boolean),
|
|
57
|
+
* or a free-form answer when the request accepts one.
|
|
58
|
+
*
|
|
59
|
+
* Resolves once the runtime has accepted the response, and rejects when
|
|
60
|
+
* it could not be recorded, so the controls can stay retryable.
|
|
57
61
|
*/
|
|
58
|
-
respondToApproval: (response: ToolApprovalResponse) => void
|
|
62
|
+
respondToApproval: (response: ToolApprovalResponse) => Promise<void>;
|
|
59
63
|
};
|
|
60
64
|
/** Component used to render a tool-call message part. */
|
|
61
65
|
type ToolCallMessagePartComponent<TArgs = any, TResult = any> = ComponentType<ToolCallMessagePartProps<TArgs, TResult>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessagePartComponentTypes.d.ts","names":[],"sources":["../../../src/react/types/MessagePartComponentTypes.ts"],"mappings":";;;;;;;KAmBY;EACV,QAAQ;;KAEE,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;KAEzC,4BAA4B,mBAAmB;KAC/C,gCACV,cAAc;KAEJ,sBAAsB;EAChC;EACA;;KAEU,0BAA0B,cAAc;KAExC,yBAAyB,mBAAmB;KAC5C,6BAA6B,cAAc;KAE3C,wBAAwB,mBAAmB;KAC3C,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;;;;;KAMzC,iCAAiC,mBAC3C;;;;;KAKU,qCACV,cAAc;KAEJ,qBAAqB,WAAW,mBAC1C,gBAAgB;KACN,yBAAyB,WAAW,cAC9C,qBAAqB;KAGX,yBACV,aACA,qBACE,mBACF,oBAAoB,OAAO;;;;;;;EAOzB,YAAY,QAAQ,UAAU,aAAa;;;;;EAK3C,SAAS
|
|
1
|
+
{"version":3,"file":"MessagePartComponentTypes.d.ts","names":[],"sources":["../../../src/react/types/MessagePartComponentTypes.ts"],"mappings":";;;;;;;KAmBY;EACV,QAAQ;;KAEE,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;KAEzC,4BAA4B,mBAAmB;KAC/C,gCACV,cAAc;KAEJ,sBAAsB;EAChC;EACA;;KAEU,0BAA0B,cAAc;KAExC,yBAAyB,mBAAmB;KAC5C,6BAA6B,cAAc;KAE3C,wBAAwB,mBAAmB;KAC3C,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;;;;;KAMzC,iCAAiC,mBAC3C;;;;;KAKU,qCACV,cAAc;KAEJ,qBAAqB,WAAW,mBAC1C,gBAAgB;KACN,yBAAyB,WAAW,cAC9C,qBAAqB;KAGX,yBACV,aACA,qBACE,mBACF,oBAAoB,OAAO;;;;;;;EAOzB,YAAY,QAAQ,UAAU,aAAa;;;;;EAK3C,SAAS;;;;;;;;;;;EAWT,oBAAoB,UAAU,yBAAyB;;;KAI/C,6BACV,aACA,iBACE,cAAc,yBAAyB,OAAO;KAEtC,wBAAwB;KACxB,4BAA4B,cAAc;;;;;;;;;KAU1C,gCAAgC,eAAe;KAE/C,+BAA+B,mBACzC;KACU,mCACV,cAAc;KAEJ;;EAEV,MAAM;;EAEN,YAAY;;EAEZ,WAAW;IAAgB;IAAmB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Unsubscribe } from "../../../types/unsubscribe.js";
|
|
2
|
+
import { ToolCallText } from "../../../model-context/tool-call-text.js";
|
|
2
3
|
import { ToolCallMessagePartComponent } from "../MessagePartComponentTypes.js";
|
|
3
4
|
import "../../../index.js";
|
|
4
5
|
//#region src/react/types/scopes/tools.d.ts
|
|
@@ -12,6 +13,7 @@ type McpAppResourceOutput = {
|
|
|
12
13
|
*/
|
|
13
14
|
type ToolRegistration = {
|
|
14
15
|
readonly render: ToolCallMessagePartComponent;
|
|
16
|
+
readonly renderText?: ToolCallText<any, any, unknown> | undefined;
|
|
15
17
|
/** Whether this UI renders standalone, outside the chain-of-thought trace. */
|
|
16
18
|
readonly standalone: boolean;
|
|
17
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","names":[],"sources":["../../../../src/react/types/scopes/tools.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.d.ts","names":[],"sources":["../../../../src/react/types/scopes/tools.ts"],"mappings":";;;;;KAIY;WACD,QAAQ;;;;;;;KAQd;WACM,QAAQ;WACR,aAAa;;WAEb;;KAGC;;EAEV,SAAS,wBAAwB;EACjC,SAAS;;KAGC;EACV,YAAY;EACZ,UACE,kBACA,QAAQ,8BACR;IAAY;MACX;;KAGO;EACV,SAAS"}
|
|
@@ -13,7 +13,7 @@ type MessagePartSnapshotBinding = SubscribableWithState<MessagePartState, Messag
|
|
|
13
13
|
type MessagePartRuntime = {
|
|
14
14
|
addToolResult(result: any | ToolResponse<any>): void;
|
|
15
15
|
resumeToolCall(payload: unknown): void;
|
|
16
|
-
respondToToolApproval(response: ToolApprovalResponse): void
|
|
16
|
+
respondToToolApproval(response: ToolApprovalResponse): Promise<void>;
|
|
17
17
|
readonly path: MessagePartRuntimePath;
|
|
18
18
|
getState(): MessagePartState;
|
|
19
19
|
subscribe(callback: () => void): Unsubscribe;
|
|
@@ -28,7 +28,7 @@ declare class MessagePartRuntimeImpl implements MessagePartRuntime {
|
|
|
28
28
|
getState(): MessagePartState;
|
|
29
29
|
addToolResult(result: any | ToolResponse<any>): void;
|
|
30
30
|
resumeToolCall(payload: unknown): void;
|
|
31
|
-
respondToToolApproval(response: ToolApprovalResponse): void
|
|
31
|
+
respondToToolApproval(response: ToolApprovalResponse): Promise<void>;
|
|
32
32
|
subscribe(callback: () => void): Unsubscribe;
|
|
33
33
|
}
|
|
34
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-part-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"mappings":";;;;;;;;KAeY,oBACR,wBACA;WAEO,QAAQ,oBAAoB;;KAGlC,6BAA6B,sBAChC,kBACA;KAGU;EACV,cAAc,cAAc;EAC5B,eAAe;EACf,sBAAsB,UAAU;
|
|
1
|
+
{"version":3,"file":"message-part-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"mappings":";;;;;;;;KAeY,oBACR,wBACA;WAEO,QAAQ,oBAAoB;;KAGlC,6BAA6B,sBAChC,kBACA;KAGU;EACV,cAAc,cAAc;EAC5B,eAAe;EACf,sBAAsB,UAAU,uBAAuB;WAE9C,MAAM;EACf,YAAY;EACZ,UAAU,uBAAuB;;cAGtB,kCAAkC;MAClC,QAAI;UAIP;UACA;UACA;EAGN,YAAA,gBAAgB,4BAChB,aAAa,qBACb,YAAY;YAQJ;EAQH,YAAQ;EAIR,cAAc,cAAc;EA8B5B,eAAe;EAgBf,sBAAsB,UAAU,uBAAuB;EAyBvD,UAAU,uBAAoB"}
|
|
@@ -61,7 +61,7 @@ var MessagePartRuntimeImpl = class {
|
|
|
61
61
|
if (state.type !== "tool-call") throw new Error("Tried to respond to tool approval on non-tool message part");
|
|
62
62
|
if (!state.approval || state.approval.approved !== void 0 || state.approval.resolution !== void 0) throw new Error("Tool call has no pending approval");
|
|
63
63
|
if (!this.threadApi) throw new Error("Thread API is not available");
|
|
64
|
-
this.threadApi.getState().respondToToolApproval(resolveToolApprovalResponse(state.approval, response));
|
|
64
|
+
return this.threadApi.getState().respondToToolApproval(resolveToolApprovalResponse(state.approval, response));
|
|
65
65
|
}
|
|
66
66
|
subscribe(callback) {
|
|
67
67
|
return this.contentBinding.subscribe(callback);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-part-runtime.js","names":["ThreadAssistantMessagePart","ThreadUserMessagePart","ToolApprovalResponse","ToolCallMessagePartStatus","resolveToolApprovalResponse","Unsubscribe","MessagePartStatus","SubscribableWithState","ThreadRuntimeCoreBinding","MessageStateBinding","MessagePartRuntimePath","ToolResponse","MessagePartState","status","MessagePartSnapshotBinding","MessagePartRuntime","addToolResult","result","resumeToolCall","payload","respondToToolApproval","response","path","getState","subscribe","callback","MessagePartRuntimeImpl","contentBinding","messageApi","threadApi","constructor","__internal_bindMethods","bind","state","Error","type","message","toolName","toolCallId","toResponse","messageId","id","artifact","isError","approval","approved","undefined","resolution"],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ToolApprovalResponse,\n ToolCallMessagePartStatus,\n} from \"../../types/message\";\nimport { resolveToolApprovalResponse } from \"../utils/resolveToolApprovalResponse\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\nimport type { MessagePartRuntimePath } from \"./paths\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n addToolResult(result: any | ToolResponse<any>): void;\n resumeToolCall(payload: unknown): void;\n respondToToolApproval(response: ToolApprovalResponse): void
|
|
1
|
+
{"version":3,"file":"message-part-runtime.js","names":["ThreadAssistantMessagePart","ThreadUserMessagePart","ToolApprovalResponse","ToolCallMessagePartStatus","resolveToolApprovalResponse","Unsubscribe","MessagePartStatus","SubscribableWithState","ThreadRuntimeCoreBinding","MessageStateBinding","MessagePartRuntimePath","ToolResponse","MessagePartState","status","MessagePartSnapshotBinding","MessagePartRuntime","addToolResult","result","resumeToolCall","payload","respondToToolApproval","response","Promise","path","getState","subscribe","callback","MessagePartRuntimeImpl","contentBinding","messageApi","threadApi","constructor","__internal_bindMethods","bind","state","Error","type","message","toolName","toolCallId","toResponse","messageId","id","artifact","isError","approval","approved","undefined","resolution"],"sources":["../../../src/runtime/api/message-part-runtime.ts"],"sourcesContent":["import type {\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n ToolApprovalResponse,\n ToolCallMessagePartStatus,\n} from \"../../types/message\";\nimport { resolveToolApprovalResponse } from \"../utils/resolveToolApprovalResponse\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\nimport type { MessagePartRuntimePath } from \"./paths\";\nimport { ToolResponse } from \"assistant-stream\";\n\nexport type MessagePartState = (\n | ThreadUserMessagePart\n | ThreadAssistantMessagePart\n) & {\n readonly status: MessagePartStatus | ToolCallMessagePartStatus;\n};\n\ntype MessagePartSnapshotBinding = SubscribableWithState<\n MessagePartState,\n MessagePartRuntimePath\n>;\n\nexport type MessagePartRuntime = {\n addToolResult(result: any | ToolResponse<any>): void;\n resumeToolCall(payload: unknown): void;\n respondToToolApproval(response: ToolApprovalResponse): Promise<void>;\n\n readonly path: MessagePartRuntimePath;\n getState(): MessagePartState;\n subscribe(callback: () => void): Unsubscribe;\n};\n\nexport class MessagePartRuntimeImpl implements MessagePartRuntime {\n public get path() {\n return this.contentBinding.path;\n }\n\n private contentBinding: MessagePartSnapshotBinding;\n private messageApi: MessageStateBinding | undefined;\n private threadApi: ThreadRuntimeCoreBinding | undefined;\n\n constructor(\n contentBinding: MessagePartSnapshotBinding,\n messageApi?: MessageStateBinding,\n threadApi?: ThreadRuntimeCoreBinding,\n ) {\n this.contentBinding = contentBinding;\n this.messageApi = messageApi;\n this.threadApi = threadApi;\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.addToolResult = this.addToolResult.bind(this);\n this.resumeToolCall = this.resumeToolCall.bind(this);\n this.respondToToolApproval = this.respondToToolApproval.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n }\n\n public getState() {\n return this.contentBinding.getState();\n }\n\n public addToolResult(result: any | ToolResponse<any>) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to add tool result to non-tool message part\");\n\n if (!this.messageApi)\n throw new Error(\n \"Message API is not available. This is likely a bug in assistant-ui.\",\n );\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const message = this.messageApi.getState();\n if (!message) throw new Error(\"Message is not available\");\n\n const toolName = state.toolName;\n const toolCallId = state.toolCallId;\n\n const response = ToolResponse.toResponse(result);\n this.threadApi.getState().addToolResult({\n messageId: message.id,\n toolName,\n toolCallId,\n result: response.result,\n artifact: response.artifact,\n isError: response.isError,\n });\n }\n\n public resumeToolCall(payload: unknown) {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\"Tried to resume tool call on non-tool message part\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n const toolCallId = state.toolCallId;\n this.threadApi.getState().resumeToolCall({\n toolCallId,\n payload,\n });\n }\n\n public respondToToolApproval(response: ToolApprovalResponse): Promise<void> {\n const state = this.contentBinding.getState();\n if (!state) throw new Error(\"Message part is not available\");\n\n if (state.type !== \"tool-call\")\n throw new Error(\n \"Tried to respond to tool approval on non-tool message part\",\n );\n\n if (\n !state.approval ||\n state.approval.approved !== undefined ||\n state.approval.resolution !== undefined\n )\n throw new Error(\"Tool call has no pending approval\");\n\n if (!this.threadApi) throw new Error(\"Thread API is not available\");\n\n return this.threadApi\n .getState()\n .respondToToolApproval(\n resolveToolApprovalResponse(state.approval, response),\n );\n }\n\n public subscribe(callback: () => void) {\n return this.contentBinding.subscribe(callback);\n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,MAAMe,QAAQ,KAAKN,eAAeJ,SAAS;EAC3C,IAAI,CAACU,OAAO,MAAM,IAAIC,MAAM,+BAA+B;EAE3D,IAAID,MAAME,SAAS,aACjB,MAAM,IAAID,MAAM,oDAAoD;EAEtE,IAAI,CAAC,KAAKL,WAAW,MAAM,IAAIK,MAAM,6BAA6B;EAElE,MAAMI,aAAaL,MAAMK;EACzB,KAAKT,UAAUN,SAAS,CAAC,CAACN,eAAe;GACvCqB;GACApB;EACF,CAAC;CACH;CAEA,sBAA6BE,UAA+C;EAC1E,MAAMa,QAAQ,KAAKN,eAAeJ,SAAS;EAC3C,IAAI,CAACU,OAAO,MAAM,IAAIC,MAAM,+BAA+B;EAE3D,IAAID,MAAME,SAAS,aACjB,MAAM,IAAID,MACR,4DACF;EAEF,IACE,CAACD,MAAMW,YACPX,MAAMW,SAASC,aAAaC,KAAAA,KAC5Bb,MAAMW,SAASG,eAAeD,KAAAA,GAE9B,MAAM,IAAIZ,MAAM,mCAAmC;EAErD,IAAI,CAAC,KAAKL,WAAW,MAAM,IAAIK,MAAM,6BAA6B;EAElE,OAAO,KAAKL,UACTN,SAAS,CAAC,CACVJ,sBACChB,4BAA4B8B,MAAMW,UAAUxB,QAAQ,CACtD;CACJ;CAEA,UAAiBK,UAAsB;EACrC,OAAO,KAAKE,eAAeH,UAAUC,QAAQ;CAC/C;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Unsubscribe } from "../../types/unsubscribe.js";
|
|
2
|
-
import { ThreadListRuntimeCore } from "../interfaces/thread-list-runtime-core.js";
|
|
2
|
+
import { ThreadListRuntimeCore, ThreadListRuntimeEvent } from "../interfaces/thread-list-runtime-core.js";
|
|
3
3
|
import { ThreadListItemState } from "./bindings.js";
|
|
4
4
|
import { ThreadListItemRuntime, ThreadListItemRuntimeImpl } from "./thread-list-item-runtime.js";
|
|
5
5
|
import { ThreadListItemRuntimeBinding, ThreadRuntime, ThreadRuntimeCoreBinding } from "./thread-runtime.js";
|
|
@@ -27,6 +27,13 @@ type ThreadListRuntime = {
|
|
|
27
27
|
unarchive?: boolean;
|
|
28
28
|
}): Promise<void>;
|
|
29
29
|
switchToNewThread(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Observes lifecycle events on every thread this list keeps alive, so an
|
|
32
|
+
* event that fires while its thread is not selected stays observable. Thread
|
|
33
|
+
* lists that mount only the main thread never emit; their main thread's
|
|
34
|
+
* runtime is observed directly.
|
|
35
|
+
*/
|
|
36
|
+
unstable_subscribeThreadEvents(callback: (event: ThreadListRuntimeEvent) => void): Unsubscribe;
|
|
30
37
|
getLoadThreadsPromise(): Promise<void>;
|
|
31
38
|
reload(): Promise<void>;
|
|
32
39
|
/**
|
|
@@ -55,6 +62,7 @@ declare class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
|
55
62
|
unarchive?: boolean;
|
|
56
63
|
}): Promise<void>;
|
|
57
64
|
switchToNewThread(): Promise<void>;
|
|
65
|
+
unstable_subscribeThreadEvents(callback: (event: ThreadListRuntimeEvent) => void): Unsubscribe;
|
|
58
66
|
getLoadThreadsPromise(): Promise<void>;
|
|
59
67
|
reload(): Promise<void>;
|
|
60
68
|
reloadMainThread(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;KA4BY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,aAAa,SACpB,eAEE,KAAK;;KAKC;EACV,YAAY;EAEZ,UAAU,uBAAuB;WAExB,MAAM;EACf,QAAQ,mBAAmB;WAElB,UAAU;EACnB,YAAY,mBAAmB;EAC/B,eAAe,cAAc;EAC7B,uBAAuB,cAAc;EAErC,eACE,kBACA;IAAY;MACX;EACH,qBAAqB;;;;;;;EAQrB,+BACE,WAAW,OAAO,kCACjB;EAEH,yBAAyB;EACzB,UAAU;;;;;;;;;;;;EAYV,oBAAoB;EACpB,YAAY;;KAuCF,+BAA+B;cAE9B,iCAAiC;UACpC;UACA;UACA;UACA;EAMN,YAAA,OAAO,8BACP,uBACE,SAAS,0BACT,uBAAuB,iCACpB;YA0CG;EAiBH,eACL,kBACA;IAAY;MACX;EAII,qBAAqB;EAIrB,+BACL,WAAW,OAAO,kCACjB;EAMI,yBAAyB;EAIzB,UAAU;EAIV,oBAAoB;EAIpB,YAAY;EAIZ,YAAY;EAIZ,UAAU,uBAAuB;UAIhC;WAEQ,MAAM;MAEX,YAAQ;EAIZ,QAAQ,mBAAgB;EAcxB,eAAe,cAAW;EAgB1B,uBAAuB,cAAW;EAmBlC,YAAY,mBAAgB"}
|
|
@@ -3,6 +3,7 @@ import { ThreadRuntimeImpl } from "./thread-runtime.js";
|
|
|
3
3
|
import { ThreadListItemRuntimeImpl } from "./thread-list-item-runtime.js";
|
|
4
4
|
//#region src/runtime/api/thread-list-runtime.ts
|
|
5
5
|
const RESOLVED_PROMISE = Promise.resolve();
|
|
6
|
+
const NOOP_UNSUBSCRIBE = () => {};
|
|
6
7
|
const getThreadListState = (threadList) => {
|
|
7
8
|
return {
|
|
8
9
|
mainThreadId: threadList.mainThreadId,
|
|
@@ -69,6 +70,7 @@ var ThreadListRuntimeImpl = class {
|
|
|
69
70
|
__internal_bindMethods() {
|
|
70
71
|
this.switchToThread = this.switchToThread.bind(this);
|
|
71
72
|
this.switchToNewThread = this.switchToNewThread.bind(this);
|
|
73
|
+
this.unstable_subscribeThreadEvents = this.unstable_subscribeThreadEvents.bind(this);
|
|
72
74
|
this.getLoadThreadsPromise = this.getLoadThreadsPromise.bind(this);
|
|
73
75
|
this.reload = this.reload.bind(this);
|
|
74
76
|
this.reloadMainThread = this.reloadMainThread.bind(this);
|
|
@@ -86,6 +88,9 @@ var ThreadListRuntimeImpl = class {
|
|
|
86
88
|
switchToNewThread() {
|
|
87
89
|
return this._core.switchToNewThread();
|
|
88
90
|
}
|
|
91
|
+
unstable_subscribeThreadEvents(callback) {
|
|
92
|
+
return this._core.unstable_subscribeThreadEvents?.(callback) ?? NOOP_UNSUBSCRIBE;
|
|
93
|
+
}
|
|
89
94
|
getLoadThreadsPromise() {
|
|
90
95
|
return this._core.getLoadThreadsPromise();
|
|
91
96
|
}
|