@assistant-ui/core 0.2.21 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/attachment.d.ts.map +1 -1
- package/dist/adapters/speech.d.ts.map +1 -1
- package/dist/adapters/speech.js +9 -2
- package/dist/adapters/speech.js.map +1 -1
- package/dist/adapters/thread-history.d.ts +8 -0
- package/dist/adapters/thread-history.d.ts.map +1 -1
- package/dist/adapters/voice.d.ts.map +1 -1
- package/dist/adapters/voice.js +13 -5
- package/dist/adapters/voice.js.map +1 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.js +5 -2
- package/dist/model-context/frame/host.d.ts +1 -0
- package/dist/model-context/frame/host.d.ts.map +1 -1
- package/dist/model-context/frame/host.js +41 -21
- package/dist/model-context/frame/host.js.map +1 -1
- package/dist/model-context/frame/provider.d.ts.map +1 -1
- package/dist/model-context/frame/provider.js +1 -0
- package/dist/model-context/frame/provider.js.map +1 -1
- package/dist/model-context/interactable-composer-metadata.js.map +1 -1
- package/dist/model-context/types.d.ts.map +1 -1
- package/dist/model-context/types.js +13 -4
- package/dist/model-context/types.js.map +1 -1
- package/dist/react/AssistantProvider.js.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +78 -50
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/Interactables.js.map +1 -1
- package/dist/react/client/Tools.d.ts.map +1 -1
- package/dist/react/client/interactable-model-context.d.ts.map +1 -1
- package/dist/react/client/interactable-model-context.js +1 -0
- package/dist/react/client/interactable-model-context.js.map +1 -1
- package/dist/react/interactables-legacy/useInteractableState.js +1 -0
- package/dist/react/interactables-legacy/useInteractableState.js.map +1 -1
- package/dist/react/model-context/useInteractable.js.map +1 -1
- package/dist/react/model-context/useInteractableState.js +1 -0
- package/dist/react/model-context/useInteractableState.js.map +1 -1
- package/dist/react/model-context/useInteractableVersions.js +1 -0
- package/dist/react/model-context/useInteractableVersions.js.map +1 -1
- package/dist/react/model-context/useToolArgsStatus.js +1 -0
- package/dist/react/model-context/useToolArgsStatus.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarCopy.js +14 -13
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +1 -0
- package/dist/react/primitive-hooks/useActionBarEdit.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarFeedback.js +1 -0
- package/dist/react/primitive-hooks/useActionBarFeedback.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarReload.js +1 -0
- package/dist/react/primitive-hooks/useActionBarReload.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarSpeak.js +1 -0
- package/dist/react/primitive-hooks/useActionBarSpeak.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +1 -0
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerNext.js +1 -0
- package/dist/react/primitive-hooks/useBranchPickerNext.js.map +1 -1
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +1 -0
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +1 -0
- package/dist/react/primitive-hooks/useComposerAddAttachment.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerCancel.js +1 -0
- package/dist/react/primitive-hooks/useComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerDictate.js +1 -0
- package/dist/react/primitive-hooks/useComposerDictate.js.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.d.ts.map +1 -1
- package/dist/react/primitive-hooks/useComposerSend.js +1 -0
- package/dist/react/primitive-hooks/useComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerCancel.js +1 -0
- package/dist/react/primitive-hooks/useEditComposerCancel.js.map +1 -1
- package/dist/react/primitive-hooks/useEditComposerSend.js +1 -0
- package/dist/react/primitive-hooks/useEditComposerSend.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageBranching.js +1 -0
- package/dist/react/primitive-hooks/useMessageBranching.js.map +1 -1
- package/dist/react/primitive-hooks/useMessageReload.js +1 -0
- package/dist/react/primitive-hooks/useMessageReload.js.map +1 -1
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +1 -0
- package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemArchive.js +1 -0
- package/dist/react/primitive-hooks/useThreadListItemArchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemDelete.js +1 -0
- package/dist/react/primitive-hooks/useThreadListItemDelete.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js +1 -0
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +1 -0
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +1 -0
- package/dist/react/primitive-hooks/useThreadListLoadMore.js.map +1 -1
- package/dist/react/primitive-hooks/useThreadListNew.js +1 -0
- package/dist/react/primitive-hooks/useThreadListNew.js.map +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.d.ts.map +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +1 -1
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js.map +1 -1
- 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.map +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageAttachments.js.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.d.ts +2 -1
- package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +46 -36
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/primitives/part/PartMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadMessages.js.map +1 -1
- package/dist/react/primitives/thread/ThreadSuggestions.js.map +1 -1
- package/dist/react/primitives/threadList/ThreadListItems.js.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +18 -30
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js.map +1 -1
- package/dist/react/providers/PartByIndexProvider.d.ts.map +1 -1
- package/dist/react/providers/PartByIndexProvider.js +18 -30
- package/dist/react/providers/PartByIndexProvider.js.map +1 -1
- package/dist/react/providers/TextMessagePartProvider.js +1 -0
- package/dist/react/providers/TextMessagePartProvider.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +1 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +9 -2
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +55 -12
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts +31 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +12 -2
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js +3 -2
- package/dist/react/runtimes/cloud/CloudFileAttachmentAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +12 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +2 -1
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +75 -73
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/createMessageConverter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +2 -2
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.js +1 -0
- package/dist/react/runtimes/useExternalStoreSharedOptions.js.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.d.ts.map +1 -1
- package/dist/react/runtimes/useLocalRuntime.js +9 -1
- package/dist/react/runtimes/useLocalRuntime.js.map +1 -1
- package/dist/runtime/api/assistant-runtime.d.ts +1 -1
- package/dist/runtime/api/assistant-runtime.d.ts.map +1 -1
- package/dist/runtime/api/assistant-runtime.js +1 -1
- package/dist/runtime/api/assistant-runtime.js.map +1 -1
- package/dist/runtime/api/attachment-runtime.d.ts +1 -1
- package/dist/runtime/api/attachment-runtime.d.ts.map +1 -1
- package/dist/runtime/api/attachment-runtime.js +1 -1
- package/dist/runtime/api/attachment-runtime.js.map +1 -1
- package/dist/runtime/api/composer-runtime.d.ts +2 -2
- package/dist/runtime/api/composer-runtime.d.ts.map +1 -1
- package/dist/runtime/api/composer-runtime.js +2 -2
- package/dist/runtime/api/composer-runtime.js.map +1 -1
- package/dist/runtime/api/message-part-runtime.d.ts +4 -4
- package/dist/runtime/api/message-part-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-part-runtime.js +3 -3
- package/dist/runtime/api/message-part-runtime.js.map +1 -1
- package/dist/runtime/api/message-runtime.d.ts +1 -1
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +6 -6
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.d.ts +1 -1
- package/dist/runtime/api/thread-list-item-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-item-runtime.js +4 -3
- package/dist/runtime/api/thread-list-item-runtime.js.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +1 -1
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +4 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +41 -14
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts +1 -1
- package/dist/runtime/base/base-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-thread-runtime-core.js +3 -2
- package/dist/runtime/base/base-thread-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts +2 -2
- package/dist/runtime/base/default-edit-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-edit-composer-runtime-core.js +6 -4
- package/dist/runtime/base/default-edit-composer-runtime-core.js.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/default-thread-composer-runtime-core.js +3 -3
- package/dist/runtime/base/default-thread-composer-runtime-core.js.map +1 -1
- package/dist/runtime/utils/message-repository.d.ts.map +1 -1
- package/dist/runtime/utils/message-repository.js +4 -2
- package/dist/runtime/utils/message-repository.js.map +1 -1
- package/dist/runtime/utils/thread-message-like.js +4 -1
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/external-store/external-store-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +12 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/internal.d.ts +2 -1
- package/dist/runtimes/internal.js +2 -1
- package/dist/runtimes/local/local-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +3 -0
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +49 -15
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/optimistic-state.d.ts +4 -4
- package/dist/runtimes/remote-thread-list/optimistic-state.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/optimistic-state.js +22 -9
- package/dist/runtimes/remote-thread-list/optimistic-state.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts +32 -27
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.d.ts.map +1 -1
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js +3 -2
- package/dist/runtimes/tool-invocations/ToolInvocationTracker.js.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/no-op-composer-client.d.ts.map +1 -1
- package/dist/store/clients/no-op-composer-client.js +1 -0
- package/dist/store/clients/no-op-composer-client.js.map +1 -1
- package/dist/store/runtime-clients/attachment-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-part-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/message-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +1 -0
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-runtime-client.js +17 -15
- package/dist/store/runtime-clients/thread-runtime-client.js.map +1 -1
- package/dist/store/scopes/thread.d.ts +1 -0
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/subscribable/subscribable.d.ts +4 -4
- package/dist/subscribable/subscribable.d.ts.map +1 -1
- package/dist/subscribable/subscribable.js +14 -6
- package/dist/subscribable/subscribable.js.map +1 -1
- package/dist/tests/remote-thread-list-test-helpers.d.ts +2 -1
- package/dist/tests/remote-thread-list-test-helpers.d.ts.map +1 -1
- package/dist/tests/remote-thread-list-test-helpers.js +5 -2
- package/dist/tests/remote-thread-list-test-helpers.js.map +1 -1
- package/dist/types/attachment.d.ts +2 -1
- package/dist/types/attachment.d.ts.map +1 -1
- package/dist/types/attachment.js +6 -0
- package/dist/types/attachment.js.map +1 -0
- package/dist/types/message.d.ts +1 -0
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/data-url.d.ts +9 -0
- package/dist/utils/data-url.d.ts.map +1 -0
- package/dist/utils/data-url.js +14 -0
- package/dist/utils/data-url.js.map +1 -0
- package/dist/utils/notify-event-listeners.d.ts +6 -0
- package/dist/utils/notify-event-listeners.d.ts.map +1 -0
- package/dist/utils/notify-event-listeners.js +16 -0
- package/dist/utils/notify-event-listeners.js.map +1 -0
- package/package.json +10 -9
- package/src/adapters/speech.test.ts +88 -0
- package/src/adapters/speech.ts +17 -2
- package/src/adapters/thread-history.ts +8 -0
- package/src/adapters/voice.test.ts +130 -0
- package/src/adapters/voice.ts +26 -6
- package/src/internal.ts +6 -1
- package/src/model-context/frame/host.test.ts +147 -0
- package/src/model-context/frame/host.ts +56 -19
- package/src/model-context/frame/provider.test.ts +83 -0
- package/src/model-context/frame/provider.ts +1 -0
- package/src/model-context/types.ts +16 -6
- package/src/react/adapters/LocalStorageThreadListAdapter.test.ts +82 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +108 -58
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +79 -0
- package/src/react/primitive-hooks/useActionBarCopy.ts +4 -3
- package/src/react/primitives/chainOfThought/ChainOfThoughtParts.tsx +1 -3
- package/src/react/primitives/message/MessageParts.tsx +48 -35
- package/src/react/providers/ChainOfThoughtPartByIndexProvider.tsx +19 -2
- package/src/react/providers/PartByIndexProvider.tsx +16 -2
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +18 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +1 -0
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +68 -13
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.ts +34 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.test.tsx +69 -0
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +27 -6
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.test.ts +16 -0
- package/src/react/runtimes/cloud/CloudFileAttachmentAdapter.ts +7 -2
- package/src/react/runtimes/cloud/auiV0.ts +14 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +90 -88
- package/src/react/runtimes/external-message-converter.test.ts +346 -0
- package/src/react/runtimes/external-message-converter.test.tsx +21 -0
- package/src/react/runtimes/external-message-converter.ts +2 -2
- package/src/react/runtimes/useLocalRuntime.test.tsx +99 -0
- package/src/react/runtimes/useLocalRuntime.ts +13 -1
- package/src/runtime/api/assistant-runtime.ts +4 -1
- package/src/runtime/api/attachment-runtime.ts +8 -2
- package/src/runtime/api/composer-runtime.ts +9 -5
- package/src/runtime/api/message-part-runtime.ts +10 -3
- package/src/runtime/api/message-runtime.test.ts +81 -0
- package/src/runtime/api/message-runtime.ts +11 -8
- package/src/runtime/api/thread-list-item-runtime.ts +13 -3
- package/src/runtime/api/thread-list-runtime.ts +10 -2
- package/src/runtime/base/base-composer-runtime-core.ts +77 -31
- package/src/runtime/base/base-thread-runtime-core.ts +7 -2
- package/src/runtime/base/default-edit-composer-runtime-core.ts +18 -4
- package/src/runtime/base/default-thread-composer-runtime-core.ts +13 -3
- package/src/runtime/utils/message-repository.ts +19 -13
- package/src/runtime/utils/thread-message-like.ts +1 -0
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +4 -1
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +15 -0
- package/src/runtimes/internal.ts +3 -0
- package/src/runtimes/local/local-thread-runtime-core.test.ts +746 -1
- package/src/runtimes/local/local-thread-runtime-core.ts +89 -23
- package/src/runtimes/local/should-continue.test.ts +122 -0
- package/src/runtimes/remote-thread-list/optimistic-state.test.ts +63 -0
- package/src/runtimes/remote-thread-list/optimistic-state.ts +49 -17
- package/src/runtimes/remote-thread-list/types.ts +1 -1
- package/src/runtimes/tool-invocations/EDGE_CASES.md +13 -19
- package/src/runtimes/tool-invocations/ToolInvocationTracker.test.ts +128 -8
- package/src/runtimes/tool-invocations/ToolInvocationTracker.ts +42 -34
- package/src/store/clients/model-context-client.test.ts +21 -1
- package/src/store/runtime-clients/thread-runtime-client.ts +2 -1
- package/src/store/scopes/thread.ts +1 -0
- package/src/subscribable/subscribable.test.ts +58 -0
- package/src/subscribable/subscribable.ts +29 -11
- package/src/tests/MessageRepository.test.ts +12 -0
- package/src/tests/OptimisticState-list-race.test.ts +33 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-order.test.ts +223 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-position.test.ts +121 -0
- package/src/tests/auiV0Encode.test.ts +74 -0
- package/src/tests/base-composer-runtime-core-addAttachment.test.ts +44 -0
- package/src/tests/base-composer-runtime-core-send.test.ts +433 -5
- package/src/tests/base-composer-runtime-core.test.ts +422 -0
- package/src/tests/default-edit-composer-runtime-core.test.ts +43 -5
- package/src/tests/event-subscription-listener-errors.test.ts +205 -0
- package/src/tests/external-store-thread-list-runtime-core.test.ts +6 -6
- package/src/tests/external-store-thread-runtime-core-adapter.test.ts +575 -0
- package/src/tests/external-store-thread-runtime-core.test.ts +55 -1
- package/src/tests/remote-thread-list-test-helpers.ts +14 -7
- package/src/tests/thread-message-like.test.ts +57 -0
- package/src/types/attachment.ts +5 -0
- package/src/types/message.ts +1 -0
- package/src/utils/data-url.test.ts +50 -0
- package/src/utils/data-url.ts +9 -0
- package/src/utils/notify-event-listeners.ts +30 -0
- package/src/tests/OptimisticState-delete-crash.test.ts +0 -208
|
@@ -73,7 +73,8 @@ function auiV0Encode(message) {
|
|
|
73
73
|
toolName: part.toolName,
|
|
74
74
|
...JSON.stringify(part.args) === part.argsText ? { args: part.args } : { argsText: part.argsText },
|
|
75
75
|
...part.result ? { result: part.result } : void 0,
|
|
76
|
-
...part.isError ? { isError: true } : void 0
|
|
76
|
+
...part.isError ? { isError: true } : void 0,
|
|
77
|
+
...part.approval ? { approval: part.approval } : void 0
|
|
77
78
|
};
|
|
78
79
|
case "image": return {
|
|
79
80
|
type: "image",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auiV0.js","names":["DataMessagePart","FileMessagePart","ImageMessagePart","MessageStatus","SourceProviderMetadata","ThreadMessage","TextMessagePart","Unstable_AudioMessagePart","CompleteAttachment","fromThreadMessageLike","CloudMessage","isJSONValue","ReadonlyJSONObject","ReadonlyJSONValue","ExportedMessageRepositoryItem","AuiV0MessagePart","type","text","sourceType","id","url","title","providerMetadata","mediaType","filename","toolCallId","toolName","args","result","isError","argsText","image","data","mimeType","AuiV0AttachmentPart","AuiV0Attachment","name","contentType","status","content","AuiV0Message","role","attachments","metadata","unstable_state","unstable_annotations","unstable_data","steps","usage","inputTokens","outputTokens","custom","encodeAttachmentPart","part","console","warn","JSON","stringify","unhandledType","Error","encodeAttachments","message","length","undefined","map","auiV0Encode","reason","auiV0Decode","cloudMessage","format","payload","createdAt","created_at","parentId","parent_id"],"sources":["../../../../src/react/runtimes/cloud/auiV0.ts"],"sourcesContent":["import type {\n DataMessagePart,\n FileMessagePart,\n ImageMessagePart,\n MessageStatus,\n SourceProviderMetadata,\n ThreadMessage,\n TextMessagePart,\n Unstable_AudioMessagePart,\n} from \"../../../types/message\";\nimport type { CompleteAttachment } from \"../../../types/attachment\";\nimport { fromThreadMessageLike } from \"../../../runtime/utils/thread-message-like\";\nimport type { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"../../../utils/json/is-json\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ExportedMessageRepositoryItem } from \"../../../runtime/utils/message-repository\";\n\ntype AuiV0MessagePart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: ReadonlyJSONObject;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly argsText: string;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n };\n\ntype AuiV0AttachmentPart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | Unstable_AudioMessagePart\n | DataMessagePart<ReadonlyJSONValue>;\n\ntype AuiV0Attachment = {\n readonly id: string;\n readonly type: CompleteAttachment[\"type\"];\n readonly name: string;\n readonly contentType?: string;\n readonly status: CompleteAttachment[\"status\"];\n readonly content: readonly AuiV0AttachmentPart[];\n};\n\ntype AuiV0Message = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly status?: MessageStatus;\n readonly content: readonly AuiV0MessagePart[];\n readonly attachments?: readonly AuiV0Attachment[];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly {\n readonly usage?: {\n readonly inputTokens: number;\n readonly outputTokens: number;\n };\n }[];\n readonly custom: ReadonlyJSONObject;\n };\n};\n\nconst encodeAttachmentPart = (\n part: CompleteAttachment[\"content\"][number],\n): AuiV0AttachmentPart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"image\":\n case \"file\":\n case \"audio\":\n return part;\n\n case \"data\": {\n if (!isJSONValue(part.data)) {\n console.warn(`attachment data is not JSON! ${JSON.stringify(part)}`);\n }\n return { ...part, data: part.data as ReadonlyJSONValue };\n }\n\n default: {\n const unhandledType: never = type;\n throw new Error(\n `Attachment part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n};\n\nconst encodeAttachments = (\n message: ThreadMessage,\n): readonly AuiV0Attachment[] | undefined => {\n if (message.role !== \"user\" || message.attachments.length === 0) {\n return undefined;\n }\n\n return message.attachments.map(\n ({ id, type, name, contentType, status, content }) => ({\n id,\n type,\n name,\n status,\n ...(contentType != null ? { contentType } : undefined),\n content: content.map(encodeAttachmentPart),\n }),\n );\n};\n\nexport function auiV0Encode(message: ThreadMessage): AuiV0Message {\n // info: ID and createdAt are ignored (we use the server value instead)\n const status: MessageStatus | undefined =\n message.status?.type === \"running\"\n ? { type: \"incomplete\", reason: \"cancelled\" }\n : message.status;\n const attachments = encodeAttachments(message);\n\n return {\n role: message.role,\n content: message.content.map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"reasoning\":\n return { type: \"reasoning\", text: part.text };\n\n case \"source\":\n if (part.sourceType === \"url\") {\n return {\n type: \"source\",\n sourceType: \"url\",\n id: part.id,\n url: part.url,\n ...(part.title != null ? { title: part.title } : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n }\n\n return {\n type: \"source\",\n sourceType: \"document\",\n id: part.id,\n title: part.title,\n mediaType: part.mediaType,\n ...(part.filename != null\n ? { filename: part.filename }\n : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n\n case \"tool-call\": {\n if (!isJSONValue(part.result)) {\n console.warn(\n `tool-call result is not JSON! ${JSON.stringify(part)}`,\n );\n }\n return {\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n ...(JSON.stringify(part.args) === part.argsText\n ? { args: part.args }\n : { argsText: part.argsText }),\n ...(part.result\n ? { result: part.result as ReadonlyJSONValue }\n : undefined),\n ...(part.isError ? { isError: true } : undefined),\n };\n }\n\n case \"image\":\n return { type: \"image\", image: part.image };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename ? { filename: part.filename } : undefined),\n };\n\n default: {\n const unhandledType: \"audio\" | \"data\" | \"generative-ui\" = type;\n throw new Error(\n `Message part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n }),\n metadata: message.metadata as AuiV0Message[\"metadata\"],\n ...(status ? { status } : undefined),\n ...(attachments ? { attachments } : undefined),\n };\n}\n\nexport function auiV0Decode(\n cloudMessage: CloudMessage & { format: \"aui/v0\" },\n): ExportedMessageRepositoryItem {\n const payload = cloudMessage.content as unknown as AuiV0Message;\n const message = fromThreadMessageLike(\n {\n id: cloudMessage.id,\n createdAt: cloudMessage.created_at,\n ...payload,\n },\n cloudMessage.id,\n { type: \"complete\", reason: \"unknown\" },\n );\n\n return {\n parentId: cloudMessage.parent_id,\n message,\n };\n}\n"],"mappings":";;;AA4GA,MAAMoD,wBACJC,SACwB;CACxB,MAAMrC,OAAOqC,KAAKrC;CAClB,QAAQA,MAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,OAAOqC;EAET,KAAK;GACH,IAAI,CAAC1C,YAAY0C,KAAKrB,IAAI,GACxBsB,QAAQC,KAAK,gCAAgCC,KAAKC,UAAUJ,IAAI,GAAG;GAErE,OAAO;IAAE,GAAGA;IAAMrB,MAAMqB,KAAKrB;GAA0B;EAGzD,SAEE,MAAM,IAAI2B,MACR,iDAAiDD,MACnD;CAEJ;AACF;AAEA,MAAME,qBACJC,YAC2C;CAC3C,IAAIA,QAAQpB,SAAS,UAAUoB,QAAQnB,YAAYoB,WAAW,GAC5D;CAGF,OAAOD,QAAQnB,YAAYsB,KACxB,EAAE7C,IAAIH,MAAMoB,MAAMC,aAAaC,QAAQC,eAAe;EACrDpB;EACAH;EACAoB;EACAE;EACA,GAAID,eAAe,OAAO,EAAEA,YAAY,IAAI0B,KAAAA;EAC5CxB,SAASA,QAAQyB,IAAIZ,oBAAoB;CAC3C,EACF;AACF;AAEA,SAAgBa,YAAYJ,SAAsC;CAEhE,MAAMvB,SACJuB,QAAQvB,QAAQtB,SAAS,YACrB;EAAEA,MAAM;EAAckD,QAAQ;CAAY,IAC1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AEA,QAAQyB,KAAKzB,OAA4B,IAC3CmC,KAAAA;MACJ,GAAIV,KAAKxB,UAAU,EAAEA,SAAS,KAAK,IAAIkC,KAAAA;KACzC;IAGF,KAAK,SACH,OAAO;KAAE/C,MAAM;KAASe,OAAOsB,KAAKtB;IAAM;IAE5C,KAAK,QACH,OAAO;KACLf,MAAM;KACNgB,MAAMqB,KAAKrB;KACXC,UAAUoB,KAAKpB;KACf,GAAIoB,KAAK7B,WAAW,EAAEA,UAAU6B,KAAK7B,SAAS,IAAIuC,KAAAA;IACpD;IAEF,SAEE,MAAM,IAAIJ,MACR,8CAA8CD,MAChD;GAEJ;EACF,CAAC;EACDf,UAAUkB,QAAQlB;EAClB,GAAIL,SAAS,EAAEA,OAAO,IAAIyB,KAAAA;EAC1B,GAAIrB,cAAc,EAAEA,YAAY,IAAIqB,KAAAA;CACtC;AACF;AAEA,SAAgBI,YACdC,cAC+B;CAC/B,MAAME,UAAUF,aAAa7B;CAC7B,MAAMsB,UAAUpD,sBACd;EACEU,IAAIiD,aAAajD;EACjBoD,WAAWH,aAAaI;EACxB,GAAGF;CACL,GACAF,aAAajD,IACb;EAAEH,MAAM;EAAYkD,QAAQ;CAAU,CACxC;CAEA,OAAO;EACLO,UAAUL,aAAaM;EACvBb;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"auiV0.js","names":["DataMessagePart","FileMessagePart","ImageMessagePart","MessageStatus","SourceProviderMetadata","ThreadMessage","TextMessagePart","ToolApprovalOption","Unstable_AudioMessagePart","CompleteAttachment","fromThreadMessageLike","CloudMessage","isJSONValue","ReadonlyJSONObject","ReadonlyJSONValue","ExportedMessageRepositoryItem","AuiV0ToolApproval","id","approved","reason","isAutomatic","options","optionId","resolution","AuiV0MessagePart","type","text","sourceType","url","title","providerMetadata","mediaType","filename","toolCallId","toolName","args","result","isError","approval","argsText","image","data","mimeType","AuiV0AttachmentPart","AuiV0Attachment","name","contentType","status","content","AuiV0Message","role","attachments","metadata","unstable_state","unstable_annotations","unstable_data","steps","usage","inputTokens","outputTokens","custom","encodeAttachmentPart","part","console","warn","JSON","stringify","unhandledType","Error","encodeAttachments","message","length","undefined","map","auiV0Encode","auiV0Decode","cloudMessage","format","payload","createdAt","created_at","parentId","parent_id"],"sources":["../../../../src/react/runtimes/cloud/auiV0.ts"],"sourcesContent":["import type {\n DataMessagePart,\n FileMessagePart,\n ImageMessagePart,\n MessageStatus,\n SourceProviderMetadata,\n ThreadMessage,\n TextMessagePart,\n ToolApprovalOption,\n Unstable_AudioMessagePart,\n} from \"../../../types/message\";\nimport type { CompleteAttachment } from \"../../../types/attachment\";\nimport { fromThreadMessageLike } from \"../../../runtime/utils/thread-message-like\";\nimport type { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"../../../utils/json/is-json\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ExportedMessageRepositoryItem } from \"../../../runtime/utils/message-repository\";\n\ntype AuiV0ToolApproval = {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n readonly options?: readonly ToolApprovalOption[];\n readonly optionId?: string;\n readonly resolution?: \"cancelled\" | \"expired\";\n};\n\ntype AuiV0MessagePart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: ReadonlyJSONObject;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly argsText: string;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n };\n\ntype AuiV0AttachmentPart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | Unstable_AudioMessagePart\n | DataMessagePart<ReadonlyJSONValue>;\n\ntype AuiV0Attachment = {\n readonly id: string;\n readonly type: CompleteAttachment[\"type\"];\n readonly name: string;\n readonly contentType?: string;\n readonly status: CompleteAttachment[\"status\"];\n readonly content: readonly AuiV0AttachmentPart[];\n};\n\ntype AuiV0Message = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly status?: MessageStatus;\n readonly content: readonly AuiV0MessagePart[];\n readonly attachments?: readonly AuiV0Attachment[];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly {\n readonly usage?: {\n readonly inputTokens: number;\n readonly outputTokens: number;\n };\n }[];\n readonly custom: ReadonlyJSONObject;\n };\n};\n\nconst encodeAttachmentPart = (\n part: CompleteAttachment[\"content\"][number],\n): AuiV0AttachmentPart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"image\":\n case \"file\":\n case \"audio\":\n return part;\n\n case \"data\": {\n if (!isJSONValue(part.data)) {\n console.warn(`attachment data is not JSON! ${JSON.stringify(part)}`);\n }\n return { ...part, data: part.data as ReadonlyJSONValue };\n }\n\n default: {\n const unhandledType: never = type;\n throw new Error(\n `Attachment part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n};\n\nconst encodeAttachments = (\n message: ThreadMessage,\n): readonly AuiV0Attachment[] | undefined => {\n if (message.role !== \"user\" || message.attachments.length === 0) {\n return undefined;\n }\n\n return message.attachments.map(\n ({ id, type, name, contentType, status, content }) => ({\n id,\n type,\n name,\n status,\n ...(contentType != null ? { contentType } : undefined),\n content: content.map(encodeAttachmentPart),\n }),\n );\n};\n\nexport function auiV0Encode(message: ThreadMessage): AuiV0Message {\n // info: ID and createdAt are ignored (we use the server value instead)\n const status: MessageStatus | undefined =\n message.status?.type === \"running\"\n ? { type: \"incomplete\", reason: \"cancelled\" }\n : message.status;\n const attachments = encodeAttachments(message);\n\n return {\n role: message.role,\n content: message.content.map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"reasoning\":\n return { type: \"reasoning\", text: part.text };\n\n case \"source\":\n if (part.sourceType === \"url\") {\n return {\n type: \"source\",\n sourceType: \"url\",\n id: part.id,\n url: part.url,\n ...(part.title != null ? { title: part.title } : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n }\n\n return {\n type: \"source\",\n sourceType: \"document\",\n id: part.id,\n title: part.title,\n mediaType: part.mediaType,\n ...(part.filename != null\n ? { filename: part.filename }\n : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n\n case \"tool-call\": {\n if (!isJSONValue(part.result)) {\n console.warn(\n `tool-call result is not JSON! ${JSON.stringify(part)}`,\n );\n }\n return {\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n ...(JSON.stringify(part.args) === part.argsText\n ? { args: part.args }\n : { argsText: part.argsText }),\n ...(part.result\n ? { result: part.result as ReadonlyJSONValue }\n : undefined),\n ...(part.isError ? { isError: true } : undefined),\n ...(part.approval ? { approval: part.approval } : undefined),\n };\n }\n\n case \"image\":\n return { type: \"image\", image: part.image };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename ? { filename: part.filename } : undefined),\n };\n\n default: {\n const unhandledType: \"audio\" | \"data\" | \"generative-ui\" = type;\n throw new Error(\n `Message part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n }),\n metadata: message.metadata as AuiV0Message[\"metadata\"],\n ...(status ? { status } : undefined),\n ...(attachments ? { attachments } : undefined),\n };\n}\n\nexport function auiV0Decode(\n cloudMessage: CloudMessage & { format: \"aui/v0\" },\n): ExportedMessageRepositoryItem {\n const payload = cloudMessage.content as unknown as AuiV0Message;\n const message = fromThreadMessageLike(\n {\n id: cloudMessage.id,\n createdAt: cloudMessage.created_at,\n ...payload,\n },\n cloudMessage.id,\n { type: \"complete\", reason: \"unknown\" },\n );\n\n return {\n parentId: cloudMessage.parent_id,\n message,\n };\n}\n"],"mappings":";;;AAyHA,MAAM6D,wBACJC,SACwB;CACxB,MAAMrC,OAAOqC,KAAKrC;CAClB,QAAQA,MAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,OAAOqC;EAET,KAAK;GACH,IAAI,CAAClD,YAAYkD,KAAKrB,IAAI,GACxBsB,QAAQC,KAAK,gCAAgCC,KAAKC,UAAUJ,IAAI,GAAG;GAErE,OAAO;IAAE,GAAGA;IAAMrB,MAAMqB,KAAKrB;GAA0B;EAGzD,SAEE,MAAM,IAAI2B,MACR,iDAAiDD,MACnD;CAEJ;AACF;AAEA,MAAME,qBACJC,YAC2C;CAC3C,IAAIA,QAAQpB,SAAS,UAAUoB,QAAQnB,YAAYoB,WAAW,GAC5D;CAGF,OAAOD,QAAQnB,YAAYsB,KACxB,EAAExD,IAAIQ,MAAMoB,MAAMC,aAAaC,QAAQC,eAAe;EACrD/B;EACAQ;EACAoB;EACAE;EACA,GAAID,eAAe,OAAO,EAAEA,YAAY,IAAI0B,KAAAA;EAC5CxB,SAASA,QAAQyB,IAAIZ,oBAAoB;CAC3C,EACF;AACF;AAEA,SAAgBa,YAAYJ,SAAsC;CAEhE,MAAMvB,SACJuB,QAAQvB,QAAQtB,SAAS,YACrB;EAAEA,MAAM;EAAcN,QAAQ;CAAY,IAC1CmD,QAAQvB;CACd,MAAMI,cAA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AA4B,IAC3CoC,KAAAA;MACJ,GAAIV,KAAKzB,UAAU,EAAEA,SAAS,KAAK,IAAImC,KAAAA;MACvC,GAAIV,KAAKxB,WAAW,EAAEA,UAAUwB,KAAKxB,SAAS,IAAIkC,KAAAA;KACpD;IAGF,KAAK,SACH,OAAO;KAAE/C,MAAM;KAASe,OAAOsB,KAAKtB;IAAM;IAE5C,KAAK,QACH,OAAO;KACLf,MAAM;KACNgB,MAAMqB,KAAKrB;KACXC,UAAUoB,KAAKpB;KACf,GAAIoB,KAAK9B,WAAW,EAAEA,UAAU8B,KAAK9B,SAAS,IAAIwC,KAAAA;IACpD;IAEF,SAEE,MAAM,IAAIJ,MACR,8CAA8CD,MAChD;GAEJ;EACF,CAAC;EACDf,UAAUkB,QAAQlB;EAClB,GAAIL,SAAS,EAAEA,OAAO,IAAIyB,KAAAA;EAC1B,GAAIrB,cAAc,EAAEA,YAAY,IAAIqB,KAAAA;CACtC;AACF;AAEA,SAAgBG,YACdC,cAC+B;CAC/B,MAAME,UAAUF,aAAa5B;CAC7B,MAAMsB,UAAU5D,sBACd;EACEO,IAAI2D,aAAa3D;EACjB8D,WAAWH,aAAaI;EACxB,GAAGF;CACL,GACAF,aAAa3D,IACb;EAAEQ,MAAM;EAAYN,QAAQ;CAAU,CACxC;CAEA,OAAO;EACL8D,UAAUL,aAAaM;EACvBZ;CACF;AACF"}
|
|
@@ -33,81 +33,83 @@ const useCloudThreadListAdapter = (adapter) => {
|
|
|
33
33
|
});
|
|
34
34
|
}, []);
|
|
35
35
|
const cloud = adapter.cloud ?? autoCloud;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
36
|
+
return useMemo(() => {
|
|
37
|
+
if (!cloud) {
|
|
38
|
+
const ref = adapterRef;
|
|
39
|
+
const inMemory = new InMemoryThreadListAdapter();
|
|
40
|
+
inMemory.initialize = async (threadId) => {
|
|
41
|
+
return {
|
|
42
|
+
remoteId: threadId,
|
|
43
|
+
externalId: (await ref.current.create?.())?.externalId
|
|
44
|
+
};
|
|
43
45
|
};
|
|
46
|
+
return inMemory;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
list: async () => {
|
|
50
|
+
const { threads } = await cloud.threads.list();
|
|
51
|
+
return { threads: threads.map((t) => ({
|
|
52
|
+
status: t.is_archived ? "archived" : "regular",
|
|
53
|
+
remoteId: t.id,
|
|
54
|
+
title: t.title,
|
|
55
|
+
lastMessageAt: t.last_message_at ? new Date(t.last_message_at) : void 0,
|
|
56
|
+
externalId: t.external_id ?? void 0,
|
|
57
|
+
custom: toCustom(t.metadata)
|
|
58
|
+
})) };
|
|
59
|
+
},
|
|
60
|
+
initialize: async () => {
|
|
61
|
+
const t_0 = await (adapterRef.current.create?.() ?? Promise.resolve());
|
|
62
|
+
const external_id = t_0 ? t_0.externalId : void 0;
|
|
63
|
+
const { thread_id: remoteId } = await cloud.threads.create({
|
|
64
|
+
last_message_at: /* @__PURE__ */ new Date(),
|
|
65
|
+
external_id
|
|
66
|
+
});
|
|
67
|
+
return {
|
|
68
|
+
externalId: external_id,
|
|
69
|
+
remoteId
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
rename: async (threadId_0, newTitle) => {
|
|
73
|
+
return cloud.threads.update(threadId_0, { title: newTitle });
|
|
74
|
+
},
|
|
75
|
+
updateCustom: async (threadId_1, custom) => {
|
|
76
|
+
return cloud.threads.update(threadId_1, { metadata: custom ?? null });
|
|
77
|
+
},
|
|
78
|
+
archive: async (threadId_2) => {
|
|
79
|
+
return cloud.threads.update(threadId_2, { is_archived: true });
|
|
80
|
+
},
|
|
81
|
+
unarchive: async (threadId_3) => {
|
|
82
|
+
return cloud.threads.update(threadId_3, { is_archived: false });
|
|
83
|
+
},
|
|
84
|
+
delete: async (threadId_4) => {
|
|
85
|
+
await adapterRef.current.delete?.(threadId_4);
|
|
86
|
+
return cloud.threads.delete(threadId_4);
|
|
87
|
+
},
|
|
88
|
+
generateTitle: async (threadId_5, messages) => {
|
|
89
|
+
const filteredMessages = messages.map((msg) => ({
|
|
90
|
+
...msg,
|
|
91
|
+
content: msg.content.filter((part) => part.type === "text" || part.type === "tool-call")
|
|
92
|
+
}));
|
|
93
|
+
return cloud.runs.stream({
|
|
94
|
+
thread_id: threadId_5,
|
|
95
|
+
assistant_id: "system/thread_title",
|
|
96
|
+
messages: filteredMessages
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
fetch: async (threadId_6) => {
|
|
100
|
+
const thread = await cloud.threads.get(threadId_6);
|
|
101
|
+
return {
|
|
102
|
+
status: thread.is_archived ? "archived" : "regular",
|
|
103
|
+
remoteId: thread.id,
|
|
104
|
+
title: thread.title,
|
|
105
|
+
lastMessageAt: thread.last_message_at ? new Date(thread.last_message_at) : void 0,
|
|
106
|
+
externalId: thread.external_id ?? void 0,
|
|
107
|
+
custom: toCustom(thread.metadata)
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
unstable_Provider
|
|
44
111
|
};
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
list: async () => {
|
|
49
|
-
const { threads } = await cloud.threads.list();
|
|
50
|
-
return { threads: threads.map((t) => ({
|
|
51
|
-
status: t.is_archived ? "archived" : "regular",
|
|
52
|
-
remoteId: t.id,
|
|
53
|
-
title: t.title,
|
|
54
|
-
lastMessageAt: t.last_message_at ? new Date(t.last_message_at) : void 0,
|
|
55
|
-
externalId: t.external_id ?? void 0,
|
|
56
|
-
custom: toCustom(t.metadata)
|
|
57
|
-
})) };
|
|
58
|
-
},
|
|
59
|
-
initialize: async () => {
|
|
60
|
-
const t_0 = await (adapter.create?.() ?? Promise.resolve());
|
|
61
|
-
const external_id = t_0 ? t_0.externalId : void 0;
|
|
62
|
-
const { thread_id: remoteId } = await cloud.threads.create({
|
|
63
|
-
last_message_at: /* @__PURE__ */ new Date(),
|
|
64
|
-
external_id
|
|
65
|
-
});
|
|
66
|
-
return {
|
|
67
|
-
externalId: external_id,
|
|
68
|
-
remoteId
|
|
69
|
-
};
|
|
70
|
-
},
|
|
71
|
-
rename: async (threadId_0, newTitle) => {
|
|
72
|
-
return cloud.threads.update(threadId_0, { title: newTitle });
|
|
73
|
-
},
|
|
74
|
-
updateCustom: async (threadId_1, custom) => {
|
|
75
|
-
return cloud.threads.update(threadId_1, { metadata: custom ?? null });
|
|
76
|
-
},
|
|
77
|
-
archive: async (threadId_2) => {
|
|
78
|
-
return cloud.threads.update(threadId_2, { is_archived: true });
|
|
79
|
-
},
|
|
80
|
-
unarchive: async (threadId_3) => {
|
|
81
|
-
return cloud.threads.update(threadId_3, { is_archived: false });
|
|
82
|
-
},
|
|
83
|
-
delete: async (threadId_4) => {
|
|
84
|
-
await adapter.delete?.(threadId_4);
|
|
85
|
-
return cloud.threads.delete(threadId_4);
|
|
86
|
-
},
|
|
87
|
-
generateTitle: async (threadId_5, messages) => {
|
|
88
|
-
const filteredMessages = messages.map((msg) => ({
|
|
89
|
-
...msg,
|
|
90
|
-
content: msg.content.filter((part) => part.type === "text" || part.type === "tool-call")
|
|
91
|
-
}));
|
|
92
|
-
return cloud.runs.stream({
|
|
93
|
-
thread_id: threadId_5,
|
|
94
|
-
assistant_id: "system/thread_title",
|
|
95
|
-
messages: filteredMessages
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
fetch: async (threadId_6) => {
|
|
99
|
-
const thread = await cloud.threads.get(threadId_6);
|
|
100
|
-
return {
|
|
101
|
-
status: thread.is_archived ? "archived" : "regular",
|
|
102
|
-
remoteId: thread.id,
|
|
103
|
-
title: thread.title,
|
|
104
|
-
lastMessageAt: thread.last_message_at ? new Date(thread.last_message_at) : void 0,
|
|
105
|
-
externalId: thread.external_id ?? void 0,
|
|
106
|
-
custom: toCustom(thread.metadata)
|
|
107
|
-
};
|
|
108
|
-
},
|
|
109
|
-
unstable_Provider
|
|
110
|
-
};
|
|
112
|
+
}, [cloud, unstable_Provider]);
|
|
111
113
|
};
|
|
112
114
|
//#endregion
|
|
113
115
|
export { useCloudThreadListAdapter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCloudThreadListAdapter.js","names":["process","env","Record","FC","PropsWithChildren","useCallback","useEffect","useMemo","useRef","AssistantCloud","RemoteThreadListAdapter","InMemoryThreadListAdapter","useAssistantCloudThreadHistoryAdapter","RuntimeAdapterProvider","CloudFileAttachmentAdapter","isRecord","ThreadData","externalId","CloudThreadListAdapterOptions","cloud","create","Promise","delete","threadId","toCustom","value","undefined","baseUrl","NEXT_PUBLIC_ASSISTANT_BASE_URL","autoCloud","anonymous","useCloudThreadListAdapter","adapter","adapterRef","current","unstable_Provider","Provider","children","history","cloudInstance","attachments","adapters","ref","inMemory","initialize","result","remoteId","list","threads","map","t","status","is_archived","id","title","lastMessageAt","last_message_at","Date","external_id","custom","metadata","createTask","resolve","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 useCallback,\n useEffect,\n useMemo,\n useRef,\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 { RuntimeAdapterProvider } 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\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_Provider = useCallback<FC<PropsWithChildren>>(\n function Provider({ children }) {\n const history = useAssistantCloudThreadHistoryAdapter({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n });\n const cloudInstance = adapterRef.current.cloud ?? autoCloud!;\n const attachments = useMemo(\n () => new CloudFileAttachmentAdapter(cloudInstance),\n [cloudInstance],\n );\n\n const adapters = useMemo(\n () => ({\n history,\n attachments,\n }),\n [history, attachments],\n );\n\n return (\n <RuntimeAdapterProvider adapters={adapters}>\n {children}\n </RuntimeAdapterProvider>\n );\n },\n [],\n );\n\n const cloud = adapter.cloud ?? autoCloud;\n if (!cloud) {\n
|
|
1
|
+
{"version":3,"file":"useCloudThreadListAdapter.js","names":["process","env","Record","FC","PropsWithChildren","useCallback","useEffect","useMemo","useRef","AssistantCloud","RemoteThreadListAdapter","InMemoryThreadListAdapter","useAssistantCloudThreadHistoryAdapter","RuntimeAdapterProvider","CloudFileAttachmentAdapter","isRecord","ThreadData","externalId","CloudThreadListAdapterOptions","cloud","create","Promise","delete","threadId","toCustom","value","undefined","baseUrl","NEXT_PUBLIC_ASSISTANT_BASE_URL","autoCloud","anonymous","useCloudThreadListAdapter","adapter","adapterRef","current","unstable_Provider","Provider","children","history","cloudInstance","attachments","adapters","ref","inMemory","initialize","result","remoteId","list","threads","map","t","status","is_archived","id","title","lastMessageAt","last_message_at","Date","external_id","custom","metadata","createTask","resolve","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 useCallback,\n useEffect,\n useMemo,\n useRef,\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 { RuntimeAdapterProvider } 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\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_Provider = useCallback<FC<PropsWithChildren>>(\n function Provider({ children }) {\n const history = useAssistantCloudThreadHistoryAdapter({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n });\n const cloudInstance = adapterRef.current.cloud ?? autoCloud!;\n const attachments = useMemo(\n () => new CloudFileAttachmentAdapter(cloudInstance),\n [cloudInstance],\n );\n\n const adapters = useMemo(\n () => ({\n history,\n attachments,\n }),\n [history, attachments],\n );\n\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 () => {\n const { threads } = await cloud.threads.list();\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 };\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 };\n }, [cloud, unstable_Provider]);\n};\n"],"mappings":";;;;;;;;;AA6BA,MAAMwB,YAAYC,UAChBV,SAASU,KAAK,IAAIA,QAAQC,KAAAA;AAE5B,MAAMC,UACJ,OAAO3B,YAAY,eACnBA,SAASC,KAAK2B;AAChB,MAAMC,YAAYF,UACd,IAAIlB,eAAe;CAAEkB;CAASG,WAAW;AAAK,CAAC,IAC/CJ,KAAAA;AAEJ,MAAaK,6BACXC,YAC4B;CAC5B,MAAMC,aAAazB,OAAOwB,OAAO;CACjC1B,gBAAgB;EACd2B,WAAWC,UAAUF;CACvB,GAAG,CAACA,OAAO,CAAC;CAEZ,MAAMG,oBAAoB9B,YACxB,SAAS+B,SAAS,EAAEC,YAAY;EAC9B,MAAMC,UAAU1B,sCAAsC,EACpD,IAAIsB,UAAU;GACZ,OAAOD,WAAWC,QAAQf,SAASU;EACrC,EACF,CAAC;EACD,MAAMU,gBAAgBN,WAAWC,QAAQf,SAASU;EAClD,MAAMW,cAAcjC,cACZ,IAAIO,2BAA2ByB,aAAa,GAClD,CAACA,aAAa,CAChB;EAUA,OACE,oBAAC,wBAAD;GAAwB,UATThC,eACR;IACL+B;IACAE;GACF,IACA,CAACF,SAASE,WAAW,CAIaC;GAC/BJ;EACqB,CAAA;CAE5B,GACA,CAAA,CACF;CAEA,MAAMlB,QAAQa,QAAQb,SAASU;CAC/B,OAAOtB,cAAuC;EAC5C,IAAI,CAACY,OAAO;GACV,MAAMuB,MAAMT;GACZ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WAAW,OAAO9C,eAAa;IAC7B,OAAOJ,MAAM6B,QAAQkB,OAAO3C,YAAU,EAAE6B,aAAa,MAAM,CAAC;GAC9D;GACA9B,QAAQ,OAAOC,eAAa;IAC1B,MAAMU,WAAWC,QAAQZ,SAASC,UAAQ;IAC1C,OAAOJ,MAAM6B,QAAQ1B,OAAOC,UAAQ;GACtC;GAEA+C,eAAe,OAAO/C,YAAUgD,aAAa;IAI3C,MAAMC,mBAAmBD,SAAStB,KAAKwB,SAAS;KAC9C,GAAGA;KACHC,SAASD,IAAIC,QAAQC,QAClBC,SAASA,KAAKC,SAAS,UAAUD,KAAKC,SAAS,WAClD;IACF,EAAE;IAEF,OAAO1D,MAAM2D,KAAKC,OAAO;KACvBhB,WAAWxC;KACXyD,cAAc;KACdT,UAAUC;IACZ,CAAC;GACH;GAEAS,OAAO,OAAO1D,eAAqB;IACjC,MAAM2D,SAAS,MAAM/D,MAAM6B,QAAQmC,IAAI5D,UAAQ;IAC/C,OAAO;KACL4B,QAAQ+B,OAAO9B,cAAc,aAAa;KAC1CN,UAAUoC,OAAO7B;KACjBC,OAAO4B,OAAO5B;KACdC,eAAe2B,OAAO1B,kBAClB,IAAIC,KAAKyB,OAAO1B,eAAe,IAC/B9B,KAAAA;KACJT,YAAYiE,OAAOxB,eAAehC,KAAAA;KAClCiC,QAAQnC,SAAS0D,OAAOtB,QAAQ;IAClC;GACF;GAEAzB;EACF;CACF,GAAG,CAAChB,OAAOgB,iBAAiB,CAAC;AAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMessageConverter.d.ts","names":[],"sources":["../../../src/react/runtimes/createMessageConverter.ts"],"mappings":";;;;cAWa,yBAA0B,kBACrC,UAAU,4BAA4B,SAAS
|
|
1
|
+
{"version":3,"file":"createMessageConverter.d.ts","names":[],"sources":["../../../src/react/runtimes/createMessageConverter.ts"],"mappings":";;;;cAWa,yBAA0B,kBACrC,UAAU,4BAA4B,SAAS;EAQ1C,sBAAA,UAAA,WAAA,cAAA;IACD,UAAU;IACV;IACA,eAAe;IACf,WAAW,4BAA4B;QACxC;EAUW,mBAAA,UAAA,KAAG,qBAAA,WAEH,4BAA4B,aAAQ;EAKvC,qBAAA,OAAA,cAAc,gBAAgB;EAO9B,oBAAA,OAAA,cAAc,gBAAgB"}
|
|
@@ -22,7 +22,7 @@ const joinExternalMessages = (messages) => {
|
|
|
22
22
|
const toolCallIdx = assistantMessage.content.findIndex((c) => c.type === "tool-call" && c.toolCallId === output.toolCallId);
|
|
23
23
|
if (toolCallIdx !== -1) {
|
|
24
24
|
const toolCall = assistantMessage.content[toolCallIdx];
|
|
25
|
-
if (output.toolName
|
|
25
|
+
if (output.toolName != null) {
|
|
26
26
|
if (toolCall.toolName !== output.toolName) throw new Error(`Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`);
|
|
27
27
|
}
|
|
28
28
|
assistantMessage.content[toolCallIdx] = {
|
|
@@ -57,7 +57,7 @@ const joinExternalMessages = (messages) => {
|
|
|
57
57
|
if (output.attachments) assistantMessage.attachments = [...assistantMessage.attachments ?? [], ...output.attachments];
|
|
58
58
|
if (output.metadata) {
|
|
59
59
|
assistantMessage.metadata ??= {};
|
|
60
|
-
if (output.metadata.unstable_state) assistantMessage.metadata.unstable_state = output.metadata.unstable_state;
|
|
60
|
+
if (output.metadata.unstable_state !== void 0) assistantMessage.metadata.unstable_state = output.metadata.unstable_state;
|
|
61
61
|
if (output.metadata.unstable_annotations) assistantMessage.metadata.unstable_annotations = [...assistantMessage.metadata.unstable_annotations ?? [], ...output.metadata.unstable_annotations];
|
|
62
62
|
if (output.metadata.unstable_data) assistantMessage.metadata.unstable_data = [...assistantMessage.metadata.unstable_data ?? [], ...output.metadata.unstable_data];
|
|
63
63
|
if (output.metadata.steps) assistantMessage.metadata.steps = [...assistantMessage.metadata.steps ?? [], ...output.metadata.steps];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-message-converter.js","names":["c","_c","useMemo","useState","ThreadMessageConverter","getExternalStoreMessages","symbolInnerMessage","bindExternalStoreMessage","fromThreadMessageLike","ThreadMessageLike","getAutoStatus","isAutoStatus","ToolExecutionStatus","ReadonlyJSONValue","generateErrorMessageId","ThreadAssistantMessage","ThreadMessage","ToolCallMessagePart","MessageTiming","JoinStrategy","ThreadMessageLikeContentItem","Exclude","isPendingToolCall","type","result","undefined","isInterruptedToolCall","interrupt","approval","approved","resolution","useExternalMessageConverter","Message","convertConfig","joinStrategy","role","toolCallId","toolName","artifact","isError","messages","Metadata","toolStatuses","Record","error","messageTiming","Callback","message","T","metadata","CallbackResult","input","outputs","CallbackCacheEntry","callback","ChunkResult","inputs","Mutable","P","mergeInnerMessages","existing","incoming","joinExternalMessages","assistantMessage","Omit","content","output","toolCallIdx","findIndex","toolCall","Error","const","text","map","length","id","createdAt","status","attachments","unstable_state","unstable_annotations","unstable_data","steps","custom","timing","submittedFeedback","isOptimistic","part","existingIdx","parentId","push","unsupportedRole","chunkExternalMessages","callbackResults","results","isAssistant","pendingNone","flush","callbackResult","at","createErrorAssistantMessage","msg","reason","Date","convertExternalMessages","WeakKey","isRunning","Array","isArray","chunks","idx","isLast","joined","hasInterruptedToolCalls","some","hasPendingToolCalls","autoStatus","newMessage","toString","lastMessage","t0","$","caches","_temp","t1","t2","state","threadMessages","callbackCache","get","set","t3","chunkCache","m","key","cached","shallowArrayEqual","converterCache","convertMessages","cache","message_0","a","b","i","WeakMap"],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport { ThreadMessageConverter } from \"../../runtimes/external-store/thread-message-converter\";\nimport {\n getExternalStoreMessages,\n symbolInnerMessage,\n bindExternalStoreMessage,\n} from \"../../runtime/utils/external-store-message\";\nimport {\n fromThreadMessageLike,\n type ThreadMessageLike,\n} from \"../../runtime/utils/thread-message-like\";\nimport { getAutoStatus, isAutoStatus } from \"../../runtime/utils/auto-status\";\nimport type { ToolExecutionStatus } from \"../../runtimes/tool-invocations/ToolInvocationTracker\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { generateErrorMessageId } from \"../../utils/id\";\nimport type {\n ThreadAssistantMessage,\n ThreadMessage,\n ToolCallMessagePart,\n} from \"../../types/message\";\nimport type { MessageTiming } from \"../../types/message\";\n\nexport type JoinStrategy = \"concat-content\" | \"none\";\n\ntype ThreadMessageLikeContentItem = Exclude<\n ThreadMessageLike[\"content\"],\n string\n>[number];\n\nconst isPendingToolCall = (c: ThreadMessageLikeContentItem): boolean =>\n c.type === \"tool-call\" && c.result === undefined;\n\nconst isInterruptedToolCall = (c: ThreadMessageLikeContentItem): boolean => {\n if (c.type !== \"tool-call\" || c.result !== undefined) return false;\n return (\n c.interrupt != null ||\n (c.approval != null &&\n c.approval.approved === undefined &&\n c.approval.resolution === undefined)\n );\n};\n\nexport namespace useExternalMessageConverter {\n export type Message =\n | (ThreadMessageLike & {\n readonly convertConfig?: {\n readonly joinStrategy?: JoinStrategy;\n };\n })\n | {\n role: \"tool\";\n toolCallId: string;\n toolName?: string | undefined;\n result: any;\n artifact?: any;\n isError?: boolean;\n messages?: readonly ThreadMessage[];\n };\n\n export type Metadata = {\n readonly toolStatuses?: Record<string, ToolExecutionStatus>;\n readonly error?: ReadonlyJSONValue;\n readonly messageTiming?: Record<string, MessageTiming>;\n };\n\n export type Callback<T> = (\n message: T,\n metadata: Metadata,\n ) => Message | Message[];\n}\n\ntype CallbackResult<T> = {\n input: T;\n outputs: useExternalMessageConverter.Message[];\n};\n\ntype CallbackCacheEntry<T> = CallbackResult<T> & {\n metadata: useExternalMessageConverter.Metadata;\n callback: useExternalMessageConverter.Callback<T>;\n};\n\ntype ChunkResult<T> = {\n inputs: T[];\n outputs: useExternalMessageConverter.Message[];\n};\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\nconst mergeInnerMessages = (existing: object, incoming: object) => ({\n [symbolInnerMessage]: [\n ...((existing as any)[symbolInnerMessage] ?? []),\n ...((incoming as any)[symbolInnerMessage] ?? []),\n ],\n});\n\nconst joinExternalMessages = (\n messages: readonly useExternalMessageConverter.Message[],\n): ThreadMessageLike => {\n const assistantMessage: Mutable<Omit<ThreadMessageLike, \"metadata\">> & {\n content: Exclude<ThreadMessageLike[\"content\"][0], string>[];\n metadata?: Mutable<ThreadMessageLike[\"metadata\"]>;\n } = {\n role: \"assistant\",\n content: [],\n };\n for (const output of messages) {\n if (output.role === \"tool\") {\n const toolCallIdx = assistantMessage.content.findIndex(\n (c) => c.type === \"tool-call\" && c.toolCallId === output.toolCallId,\n );\n // Ignore orphaned tool results so one bad tool message does not\n // prevent rendering the rest of the conversation.\n if (toolCallIdx !== -1) {\n const toolCall = assistantMessage.content[\n toolCallIdx\n ]! as ToolCallMessagePart;\n if (output.toolName !== undefined) {\n if (toolCall.toolName !== output.toolName)\n throw new Error(\n `Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`,\n );\n }\n assistantMessage.content[toolCallIdx] = {\n ...toolCall,\n ...{\n [symbolInnerMessage]: [\n ...((toolCall as any)[symbolInnerMessage] ?? []),\n output,\n ],\n },\n result: output.result,\n artifact: output.artifact,\n isError: output.isError,\n messages: output.messages,\n };\n }\n } else {\n const role = output.role;\n const content = (\n typeof output.content === \"string\"\n ? [{ type: \"text\" as const, text: output.content }]\n : output.content\n ).map((c) => ({\n ...c,\n ...{ [symbolInnerMessage]: [output] },\n }));\n switch (role) {\n case \"system\":\n case \"user\":\n return {\n ...output,\n content,\n };\n case \"assistant\":\n if (assistantMessage.content.length === 0) {\n assistantMessage.id = output.id;\n assistantMessage.createdAt ??= output.createdAt;\n assistantMessage.status ??= output.status;\n\n if (output.attachments) {\n assistantMessage.attachments = [\n ...(assistantMessage.attachments ?? []),\n ...output.attachments,\n ];\n }\n\n if (output.metadata) {\n assistantMessage.metadata ??= {};\n if (output.metadata.unstable_state) {\n assistantMessage.metadata.unstable_state =\n output.metadata.unstable_state;\n }\n if (output.metadata.unstable_annotations) {\n assistantMessage.metadata.unstable_annotations = [\n ...(assistantMessage.metadata.unstable_annotations ?? []),\n ...output.metadata.unstable_annotations,\n ];\n }\n if (output.metadata.unstable_data) {\n assistantMessage.metadata.unstable_data = [\n ...(assistantMessage.metadata.unstable_data ?? []),\n ...output.metadata.unstable_data,\n ];\n }\n if (output.metadata.steps) {\n assistantMessage.metadata.steps = [\n ...(assistantMessage.metadata.steps ?? []),\n ...output.metadata.steps,\n ];\n }\n if (output.metadata.custom) {\n assistantMessage.metadata.custom = {\n ...(assistantMessage.metadata.custom ?? {}),\n ...output.metadata.custom,\n };\n }\n\n if (output.metadata.timing) {\n assistantMessage.metadata.timing = output.metadata.timing;\n }\n\n if (output.metadata.submittedFeedback) {\n assistantMessage.metadata.submittedFeedback =\n output.metadata.submittedFeedback;\n }\n\n if (output.metadata.isOptimistic) {\n assistantMessage.metadata.isOptimistic = true;\n }\n }\n // TODO keep this in sync\n }\n\n // Add content parts, merging reasoning parts with same parentId\n for (const part of content) {\n if (part.type === \"tool-call\") {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"tool-call\" && c.toolCallId === part.toolCallId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n ...part,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n\n if (\n part.type === \"reasoning\" &&\n \"parentId\" in part &&\n part.parentId\n ) {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"reasoning\" &&\n \"parentId\" in c &&\n c.parentId === part.parentId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n text: `${existing.text}\\n\\n${part.text}`,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n assistantMessage.content.push(part);\n }\n break;\n default: {\n const unsupportedRole: never = role;\n throw new Error(`Unknown message role: ${unsupportedRole}`);\n }\n }\n }\n }\n return assistantMessage;\n};\n\nconst chunkExternalMessages = <T>(\n callbackResults: CallbackResult<T>[],\n joinStrategy?: JoinStrategy,\n) => {\n const results: ChunkResult<T>[] = [];\n let isAssistant = false;\n let pendingNone = false; // true if the previous assistant message had joinStrategy \"none\"\n let inputs: T[] = [];\n let outputs: useExternalMessageConverter.Message[] = [];\n\n const flush = () => {\n if (outputs.length) {\n results.push({\n inputs,\n outputs,\n });\n }\n inputs = [];\n outputs = [];\n isAssistant = false;\n pendingNone = false;\n };\n\n for (const callbackResult of callbackResults) {\n for (const output of callbackResult.outputs) {\n if (\n (pendingNone && output.role !== \"tool\") ||\n !isAssistant ||\n output.role === \"user\" ||\n output.role === \"system\"\n ) {\n flush();\n }\n isAssistant = output.role === \"assistant\" || output.role === \"tool\";\n\n if (inputs.at(-1) !== callbackResult.input) {\n inputs.push(callbackResult.input);\n }\n outputs.push(output);\n\n if (\n output.role === \"assistant\" &&\n (output.convertConfig?.joinStrategy === \"none\" ||\n joinStrategy === \"none\")\n ) {\n pendingNone = true;\n }\n }\n }\n flush();\n return results;\n};\n\nfunction createErrorAssistantMessage(\n error: ReadonlyJSONValue,\n): ThreadAssistantMessage {\n const msg: ThreadAssistantMessage = {\n id: generateErrorMessageId(),\n role: \"assistant\",\n content: [],\n status: { type: \"incomplete\", reason: \"error\", error },\n createdAt: new Date(),\n metadata: {\n unstable_state: null,\n unstable_annotations: [],\n unstable_data: [],\n custom: {},\n steps: [],\n },\n };\n bindExternalStoreMessage(msg, []);\n return msg;\n}\n\nexport const convertExternalMessages = <T extends WeakKey>(\n messages: T[],\n callback: useExternalMessageConverter.Callback<T>,\n isRunning: boolean,\n metadata: useExternalMessageConverter.Metadata,\n) => {\n const callbackResults: CallbackResult<T>[] = [];\n for (const message of messages) {\n const output = callback(message, metadata);\n const outputs = Array.isArray(output) ? output : [output];\n const result = { input: message, outputs };\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults);\n\n const result = chunks.map((message, idx) => {\n const isLast = idx === chunks.length - 1;\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? metadata.error : undefined,\n );\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n });\n\n if (metadata.error) {\n const lastMessage = result.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n result.push(createErrorAssistantMessage(metadata.error));\n }\n }\n\n return result;\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 useExternalMessageConverter.Message,\n ChunkResult<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: CallbackResult<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 const output = state.callback(message, state.metadata);\n const outputs = Array.isArray(output) ? output : [output];\n result = {\n input: message,\n outputs,\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 (m) => {\n const key = m.outputs[0];\n if (!key) return m;\n\n const cached = state.chunkCache.get(key);\n if (cached && shallowArrayEqual(cached.outputs, m.outputs))\n return cached;\n state.chunkCache.set(key, m);\n return m;\n },\n );\n\n const threadMessages = state.converterCache.convertMessages(\n chunks,\n (cache, message, idx) => {\n const isLast = idx === chunks.length - 1;\n\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? state.metadata.error : undefined,\n );\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n ) {\n const inputs = getExternalStoreMessages<T>(cache);\n if (shallowArrayEqual(inputs, message.inputs)) {\n return cache;\n }\n }\n\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n },\n );\n\n bindExternalStoreMessage(threadMessages, messages);\n\n if (state.metadata.error) {\n const lastMessage = threadMessages.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n threadMessages.push(createErrorAssistantMessage(state.metadata.error));\n }\n }\n\n return threadMessages;\n }, [state, messages, isRunning, joinStrategy]);\n};\n\nconst shallowArrayEqual = (a: unknown[], b: unknown[]) => {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\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AAAA,iBAAAN,EAAA;CAAA,OAEDM;AAAsB;AAI1B,MAAMS,qBAAqBK,GAAcC,MAAiB;CACxD,IAAID,EAAEnE,WAAWoE,EAAEpE,QAAQ,OAAO;CAClC,KAAK,IAAIqE,IAAI,GAAGA,IAAIF,EAAEnE,QAAQqE,KAC5B,IAAIF,EAAEE,OAAOD,EAAEC,IAAI,OAAO;CAE5B,OAAO;AACT;AAtI2C,SAAApB,QAAA;CAAA,OAoBR;EAAAK,+BAChB,IAAIgB,QAAkC;EAACZ,4BAC1C,IAAIY,QAGd;EAACP,gBACa,IAAIrI,uBAAuB;CAC7C;AAAC"}
|
|
1
|
+
{"version":3,"file":"external-message-converter.js","names":["c","_c","useMemo","useState","ThreadMessageConverter","getExternalStoreMessages","symbolInnerMessage","bindExternalStoreMessage","fromThreadMessageLike","ThreadMessageLike","getAutoStatus","isAutoStatus","ToolExecutionStatus","ReadonlyJSONValue","generateErrorMessageId","ThreadAssistantMessage","ThreadMessage","ToolCallMessagePart","MessageTiming","JoinStrategy","ThreadMessageLikeContentItem","Exclude","isPendingToolCall","type","result","undefined","isInterruptedToolCall","interrupt","approval","approved","resolution","useExternalMessageConverter","Message","convertConfig","joinStrategy","role","toolCallId","toolName","artifact","isError","messages","Metadata","toolStatuses","Record","error","messageTiming","Callback","message","T","metadata","CallbackResult","input","outputs","CallbackCacheEntry","callback","ChunkResult","inputs","Mutable","P","mergeInnerMessages","existing","incoming","joinExternalMessages","assistantMessage","Omit","content","output","toolCallIdx","findIndex","toolCall","Error","const","text","map","length","id","createdAt","status","attachments","unstable_state","unstable_annotations","unstable_data","steps","custom","timing","submittedFeedback","isOptimistic","part","existingIdx","parentId","push","unsupportedRole","chunkExternalMessages","callbackResults","results","isAssistant","pendingNone","flush","callbackResult","at","createErrorAssistantMessage","msg","reason","Date","convertExternalMessages","WeakKey","isRunning","Array","isArray","chunks","idx","isLast","joined","hasInterruptedToolCalls","some","hasPendingToolCalls","autoStatus","newMessage","toString","lastMessage","t0","$","caches","_temp","t1","t2","state","threadMessages","callbackCache","get","set","t3","chunkCache","m","key","cached","shallowArrayEqual","converterCache","convertMessages","cache","message_0","a","b","i","WeakMap"],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport { ThreadMessageConverter } from \"../../runtimes/external-store/thread-message-converter\";\nimport {\n getExternalStoreMessages,\n symbolInnerMessage,\n bindExternalStoreMessage,\n} from \"../../runtime/utils/external-store-message\";\nimport {\n fromThreadMessageLike,\n type ThreadMessageLike,\n} from \"../../runtime/utils/thread-message-like\";\nimport { getAutoStatus, isAutoStatus } from \"../../runtime/utils/auto-status\";\nimport type { ToolExecutionStatus } from \"../../runtimes/tool-invocations/ToolInvocationTracker\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { generateErrorMessageId } from \"../../utils/id\";\nimport type {\n ThreadAssistantMessage,\n ThreadMessage,\n ToolCallMessagePart,\n} from \"../../types/message\";\nimport type { MessageTiming } from \"../../types/message\";\n\nexport type JoinStrategy = \"concat-content\" | \"none\";\n\ntype ThreadMessageLikeContentItem = Exclude<\n ThreadMessageLike[\"content\"],\n string\n>[number];\n\nconst isPendingToolCall = (c: ThreadMessageLikeContentItem): boolean =>\n c.type === \"tool-call\" && c.result === undefined;\n\nconst isInterruptedToolCall = (c: ThreadMessageLikeContentItem): boolean => {\n if (c.type !== \"tool-call\" || c.result !== undefined) return false;\n return (\n c.interrupt != null ||\n (c.approval != null &&\n c.approval.approved === undefined &&\n c.approval.resolution === undefined)\n );\n};\n\nexport namespace useExternalMessageConverter {\n export type Message =\n | (ThreadMessageLike & {\n readonly convertConfig?: {\n readonly joinStrategy?: JoinStrategy;\n };\n })\n | {\n role: \"tool\";\n toolCallId: string;\n toolName?: string | undefined;\n result: any;\n artifact?: any;\n isError?: boolean;\n messages?: readonly ThreadMessage[];\n };\n\n export type Metadata = {\n readonly toolStatuses?: Record<string, ToolExecutionStatus>;\n readonly error?: ReadonlyJSONValue;\n readonly messageTiming?: Record<string, MessageTiming>;\n };\n\n export type Callback<T> = (\n message: T,\n metadata: Metadata,\n ) => Message | Message[];\n}\n\ntype CallbackResult<T> = {\n input: T;\n outputs: useExternalMessageConverter.Message[];\n};\n\ntype CallbackCacheEntry<T> = CallbackResult<T> & {\n metadata: useExternalMessageConverter.Metadata;\n callback: useExternalMessageConverter.Callback<T>;\n};\n\ntype ChunkResult<T> = {\n inputs: T[];\n outputs: useExternalMessageConverter.Message[];\n};\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\nconst mergeInnerMessages = (existing: object, incoming: object) => ({\n [symbolInnerMessage]: [\n ...((existing as any)[symbolInnerMessage] ?? []),\n ...((incoming as any)[symbolInnerMessage] ?? []),\n ],\n});\n\nconst joinExternalMessages = (\n messages: readonly useExternalMessageConverter.Message[],\n): ThreadMessageLike => {\n const assistantMessage: Mutable<Omit<ThreadMessageLike, \"metadata\">> & {\n content: Exclude<ThreadMessageLike[\"content\"][0], string>[];\n metadata?: Mutable<ThreadMessageLike[\"metadata\"]>;\n } = {\n role: \"assistant\",\n content: [],\n };\n for (const output of messages) {\n if (output.role === \"tool\") {\n const toolCallIdx = assistantMessage.content.findIndex(\n (c) => c.type === \"tool-call\" && c.toolCallId === output.toolCallId,\n );\n // Ignore orphaned tool results so one bad tool message does not\n // prevent rendering the rest of the conversation.\n if (toolCallIdx !== -1) {\n const toolCall = assistantMessage.content[\n toolCallIdx\n ]! as ToolCallMessagePart;\n if (output.toolName != null) {\n if (toolCall.toolName !== output.toolName)\n throw new Error(\n `Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`,\n );\n }\n assistantMessage.content[toolCallIdx] = {\n ...toolCall,\n ...{\n [symbolInnerMessage]: [\n ...((toolCall as any)[symbolInnerMessage] ?? []),\n output,\n ],\n },\n result: output.result,\n artifact: output.artifact,\n isError: output.isError,\n messages: output.messages,\n };\n }\n } else {\n const role = output.role;\n const content = (\n typeof output.content === \"string\"\n ? [{ type: \"text\" as const, text: output.content }]\n : output.content\n ).map((c) => ({\n ...c,\n ...{ [symbolInnerMessage]: [output] },\n }));\n switch (role) {\n case \"system\":\n case \"user\":\n return {\n ...output,\n content,\n };\n case \"assistant\":\n if (assistantMessage.content.length === 0) {\n assistantMessage.id = output.id;\n assistantMessage.createdAt ??= output.createdAt;\n assistantMessage.status ??= output.status;\n\n if (output.attachments) {\n assistantMessage.attachments = [\n ...(assistantMessage.attachments ?? []),\n ...output.attachments,\n ];\n }\n\n if (output.metadata) {\n assistantMessage.metadata ??= {};\n if (output.metadata.unstable_state !== undefined) {\n assistantMessage.metadata.unstable_state =\n output.metadata.unstable_state;\n }\n if (output.metadata.unstable_annotations) {\n assistantMessage.metadata.unstable_annotations = [\n ...(assistantMessage.metadata.unstable_annotations ?? []),\n ...output.metadata.unstable_annotations,\n ];\n }\n if (output.metadata.unstable_data) {\n assistantMessage.metadata.unstable_data = [\n ...(assistantMessage.metadata.unstable_data ?? []),\n ...output.metadata.unstable_data,\n ];\n }\n if (output.metadata.steps) {\n assistantMessage.metadata.steps = [\n ...(assistantMessage.metadata.steps ?? []),\n ...output.metadata.steps,\n ];\n }\n if (output.metadata.custom) {\n assistantMessage.metadata.custom = {\n ...(assistantMessage.metadata.custom ?? {}),\n ...output.metadata.custom,\n };\n }\n\n if (output.metadata.timing) {\n assistantMessage.metadata.timing = output.metadata.timing;\n }\n\n if (output.metadata.submittedFeedback) {\n assistantMessage.metadata.submittedFeedback =\n output.metadata.submittedFeedback;\n }\n\n if (output.metadata.isOptimistic) {\n assistantMessage.metadata.isOptimistic = true;\n }\n }\n // TODO keep this in sync\n }\n\n // Add content parts, merging reasoning parts with same parentId\n for (const part of content) {\n if (part.type === \"tool-call\") {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"tool-call\" && c.toolCallId === part.toolCallId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n ...part,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n\n if (\n part.type === \"reasoning\" &&\n \"parentId\" in part &&\n part.parentId\n ) {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"reasoning\" &&\n \"parentId\" in c &&\n c.parentId === part.parentId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n text: `${existing.text}\\n\\n${part.text}`,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n assistantMessage.content.push(part);\n }\n break;\n default: {\n const unsupportedRole: never = role;\n throw new Error(`Unknown message role: ${unsupportedRole}`);\n }\n }\n }\n }\n return assistantMessage;\n};\n\nconst chunkExternalMessages = <T>(\n callbackResults: CallbackResult<T>[],\n joinStrategy?: JoinStrategy,\n) => {\n const results: ChunkResult<T>[] = [];\n let isAssistant = false;\n let pendingNone = false; // true if the previous assistant message had joinStrategy \"none\"\n let inputs: T[] = [];\n let outputs: useExternalMessageConverter.Message[] = [];\n\n const flush = () => {\n if (outputs.length) {\n results.push({\n inputs,\n outputs,\n });\n }\n inputs = [];\n outputs = [];\n isAssistant = false;\n pendingNone = false;\n };\n\n for (const callbackResult of callbackResults) {\n for (const output of callbackResult.outputs) {\n if (\n (pendingNone && output.role !== \"tool\") ||\n !isAssistant ||\n output.role === \"user\" ||\n output.role === \"system\"\n ) {\n flush();\n }\n isAssistant = output.role === \"assistant\" || output.role === \"tool\";\n\n if (inputs.at(-1) !== callbackResult.input) {\n inputs.push(callbackResult.input);\n }\n outputs.push(output);\n\n if (\n output.role === \"assistant\" &&\n (output.convertConfig?.joinStrategy === \"none\" ||\n joinStrategy === \"none\")\n ) {\n pendingNone = true;\n }\n }\n }\n flush();\n return results;\n};\n\nfunction createErrorAssistantMessage(\n error: ReadonlyJSONValue,\n): ThreadAssistantMessage {\n const msg: ThreadAssistantMessage = {\n id: generateErrorMessageId(),\n role: \"assistant\",\n content: [],\n status: { type: \"incomplete\", reason: \"error\", error },\n createdAt: new Date(),\n metadata: {\n unstable_state: null,\n unstable_annotations: [],\n unstable_data: [],\n custom: {},\n steps: [],\n },\n };\n bindExternalStoreMessage(msg, []);\n return msg;\n}\n\nexport const convertExternalMessages = <T extends WeakKey>(\n messages: T[],\n callback: useExternalMessageConverter.Callback<T>,\n isRunning: boolean,\n metadata: useExternalMessageConverter.Metadata,\n) => {\n const callbackResults: CallbackResult<T>[] = [];\n for (const message of messages) {\n const output = callback(message, metadata);\n const outputs = Array.isArray(output) ? output : [output];\n const result = { input: message, outputs };\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults);\n\n const result = chunks.map((message, idx) => {\n const isLast = idx === chunks.length - 1;\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? metadata.error : undefined,\n );\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n });\n\n if (metadata.error) {\n const lastMessage = result.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n result.push(createErrorAssistantMessage(metadata.error));\n }\n }\n\n return result;\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 useExternalMessageConverter.Message,\n ChunkResult<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: CallbackResult<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 const output = state.callback(message, state.metadata);\n const outputs = Array.isArray(output) ? output : [output];\n result = {\n input: message,\n outputs,\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 (m) => {\n const key = m.outputs[0];\n if (!key) return m;\n\n const cached = state.chunkCache.get(key);\n if (cached && shallowArrayEqual(cached.outputs, m.outputs))\n return cached;\n state.chunkCache.set(key, m);\n return m;\n },\n );\n\n const threadMessages = state.converterCache.convertMessages(\n chunks,\n (cache, message, idx) => {\n const isLast = idx === chunks.length - 1;\n\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? state.metadata.error : undefined,\n );\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n ) {\n const inputs = getExternalStoreMessages<T>(cache);\n if (shallowArrayEqual(inputs, message.inputs)) {\n return cache;\n }\n }\n\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n },\n );\n\n bindExternalStoreMessage(threadMessages, messages);\n\n if (state.metadata.error) {\n const lastMessage = threadMessages.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n threadMessages.push(createErrorAssistantMessage(state.metadata.error));\n }\n }\n\n return threadMessages;\n }, [state, messages, isRunning, joinStrategy]);\n};\n\nconst shallowArrayEqual = (a: unknown[], b: unknown[]) => {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n};\n"],"mappings":";;;;;;;;;AA+BA,MAAMsB,qBAAqBtB,MACzBA,EAAEuB,SAAS,eAAevB,EAAEwB,WAAWC,KAAAA;AAEzC,MAAMC,yBAAyB1B,MAA6C;CAC1E,IAAIA,EAAEuB,SAAS,eAAevB,EAAEwB,WAAWC,KAAAA,GAAW,OAAO;CAC7D,OACEzB,EAAE2B,aAAa,QACd3B,EAAE4B,YAAY,QACb5B,EAAE4B,SAASC,aAAaJ,KAAAA,KACxBzB,EAAE4B,SAASE,eAAeL,KAAAA;AAEhC;AAkDA,MAAMkC,sBAAsBC,UAAkBC,cAAsB,GACjEvD,qBAAqB,CACpB,GAAKsD,SAAiBtD,uBAAuB,CAAA,GAC7C,GAAKuD,SAAiBvD,uBAAuB,CAAA,CAAG,EAEpD;AAEA,MAAMwD,wBACJtB,aACsB;CACtB,MAAMuB,mBAGF;EACF5B,MAAM;EACN8B,SAAS,CAAA;CACX;CACA,KAAK,MAAMC,UAAU1B,UACnB,IAAI0B,OAAO/B,SAAS,QAAQ;EAC1B,MAAMgC,cAAcJ,iBAAiBE,QAAQG,WAC1CpE,MAAMA,EAAEuB,SAAS,eAAevB,EAAEoC,eAAe8B,OAAO9B,UAC3D;EAGA,IAAI+B,gBAAgB,IAAI;GACtB,MAAME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BACjBwG,QACAF,IAAGQ,SAAU,GACbF,UACF;GACA7G,yBAAyB8G,YAAYtE,UAAOS,MAAO;GAAC,OAC7C6D;EAAU,CAErB;EAEA9G,yBAAyBwH,gBAAgBvF,QAAQ;EAEjD,IAAIsF,MAAK7E,SAASL,OAAM;GACtB,MAAA2E,cAAoBQ,eAAc5B,GAAI,EAAE;GACxC,IAAI,CAACoB,eAAeA,YAAWpF,SAAU,aACvC4F,eAAcrC,KAAMU,4BAA4B0B,MAAK7E,SAASL,KAAM,CAAC;EACtE;EACF6E,EAAA,KAAAf;EAAAe,EAAA,KAAAvF;EAAAuF,EAAA,KAAAjF;EAAAiF,EAAA,KAAAK;EAAAL,EAAA,MAAAM;CAAA,OAAAA,iBAAAN,EAAA;CAAA,OAEDM;AAAsB;AAI1B,MAAMS,qBAAqBK,GAAcC,MAAiB;CACxD,IAAID,EAAEnE,WAAWoE,EAAEpE,QAAQ,OAAO;CAClC,KAAK,IAAIqE,IAAI,GAAGA,IAAIF,EAAEnE,QAAQqE,KAC5B,IAAIF,EAAEE,OAAOD,EAAEC,IAAI,OAAO;CAE5B,OAAO;AACT;AAtI2C,SAAApB,QAAA;CAAA,OAoBR;EAAAK,+BAChB,IAAIgB,QAAkC;EAACZ,4BAC1C,IAAIY,QAGd;EAACP,gBACa,IAAIrI,uBAAuB;CAC7C;AAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalStoreSharedOptions.js","names":["c","_c","useMemo","ExternalStoreSharedOptions","useExternalStoreSharedOptions","options","$","isDisabled","isSendDisabled","unstable_capabilities","suggestions","t0","Required","K"],"sources":["../../../src/react/runtimes/useExternalStoreSharedOptions.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ExternalStoreSharedOptions } from \"../../runtimes/external-store/external-store-shared-options\";\n\nexport const useExternalStoreSharedOptions = (\n options: ExternalStoreSharedOptions,\n): ExternalStoreSharedOptions => {\n const { isDisabled, isSendDisabled, unstable_capabilities, suggestions } =\n options;\n return useMemo(\n () =>\n ({\n isDisabled,\n isSendDisabled,\n unstable_capabilities,\n suggestions,\n }) satisfies {\n [K in keyof Required<ExternalStoreSharedOptions>]: ExternalStoreSharedOptions[K];\n },\n [isDisabled, isSendDisabled, unstable_capabilities, suggestions],\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useExternalStoreSharedOptions.js","names":["c","_c","useMemo","ExternalStoreSharedOptions","useExternalStoreSharedOptions","options","$","isDisabled","isSendDisabled","unstable_capabilities","suggestions","t0","Required","K"],"sources":["../../../src/react/runtimes/useExternalStoreSharedOptions.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo } from \"react\";\nimport type { ExternalStoreSharedOptions } from \"../../runtimes/external-store/external-store-shared-options\";\n\nexport const useExternalStoreSharedOptions = (\n options: ExternalStoreSharedOptions,\n): ExternalStoreSharedOptions => {\n const { isDisabled, isSendDisabled, unstable_capabilities, suggestions } =\n options;\n return useMemo(\n () =>\n ({\n isDisabled,\n isSendDisabled,\n unstable_capabilities,\n suggestions,\n }) satisfies {\n [K in keyof Required<ExternalStoreSharedOptions>]: ExternalStoreSharedOptions[K];\n },\n [isDisabled, isSendDisabled, unstable_capabilities, suggestions],\n );\n};\n"],"mappings":";;;;AAKA,MAAaI,iCAAgCC,YAAA;CAAA,MAAAC,IAAAL,EAAA,CAAA;CAG3C,MAAA,EAAAM,YAAAC,gBAAAC,uBAAAC,gBACEL;CAAQ,IAAAM;CAAA,IAAAL,EAAA,OAAAC,cAAAD,EAAA,OAAAE,kBAAAF,EAAA,OAAAI,eAAAJ,EAAA,OAAAG,uBAAA;EAGLE,KAAA;GAAAJ;GAAAC;GAAAC;GAAAC;EAKD;EAACJ,EAAA,KAAAC;EAAAD,EAAA,KAAAE;EAAAF,EAAA,KAAAI;EAAAJ,EAAA,KAAAG;EAAAH,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAA,OALAK;AAOA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalRuntime.d.ts","names":[],"sources":["../../../src/react/runtimes/useLocalRuntime.ts"],"mappings":";;;;;;;;;;;;;KAcY,sBAAsB,KAAK;EACrC,QAAQ;EACR,2BAA2B;EAC3B,WAAW,KAAK;;
|
|
1
|
+
{"version":3,"file":"useLocalRuntime.d.ts","names":[],"sources":["../../../src/react/runtimes/useLocalRuntime.ts"],"mappings":";;;;;;;;;;;;;KAcY,sBAAsB,KAAK;EACrC,QAAQ;EACR,2BAA2B;EAC3B,WAAW,KAAK;;cA2DL,2BAA4B,UAAU,qBACjD,SAAS;;;;;;;;;;;;;;;;;;;;cAyBE,kBACX,WAAW,oBACX,UAAA,YAAuB,wBACtB"}
|
|
@@ -18,6 +18,7 @@ const useLocalThreadRuntime = (chatModel, { initialMessages, ...options }) => {
|
|
|
18
18
|
};
|
|
19
19
|
const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));
|
|
20
20
|
const threadIdRef = useRef(void 0);
|
|
21
|
+
const historyLoadPromiseRef = useRef(void 0);
|
|
21
22
|
threadIdRef.current = useAuiState((s) => s.threadListItem.remoteId);
|
|
22
23
|
useEffect(() => {
|
|
23
24
|
runtime.threads.getMainThreadRuntimeCore().__internal_setGetThreadId(() => threadIdRef.current);
|
|
@@ -29,8 +30,15 @@ const useLocalThreadRuntime = (chatModel, { initialMessages, ...options }) => {
|
|
|
29
30
|
}, [runtime]);
|
|
30
31
|
useEffect(() => {
|
|
31
32
|
runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);
|
|
32
|
-
runtime.threads.getMainThreadRuntimeCore().__internal_load();
|
|
33
33
|
});
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const loadPromise = runtime.threads.getMainThreadRuntimeCore().__internal_load();
|
|
36
|
+
if (historyLoadPromiseRef.current === loadPromise) return;
|
|
37
|
+
historyLoadPromiseRef.current = loadPromise;
|
|
38
|
+
loadPromise.catch((error) => {
|
|
39
|
+
console.error("[assistant-ui] local thread history load failed:", error);
|
|
40
|
+
});
|
|
41
|
+
}, [runtime]);
|
|
34
42
|
useEffect(() => {
|
|
35
43
|
if (!modelContext) return void 0;
|
|
36
44
|
return runtime.registerModelContextProvider(modelContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalRuntime.js","names":["useEffect","useMemo","useRef","useState","AssistantRuntime","ChatModelAdapter","ThreadMessageLike","LocalRuntimeOptionsBase","AssistantRuntimeImpl","LocalRuntimeCore","useAuiState","useRemoteThreadListRuntime","useCloudThreadListAdapter","useRuntimeAdapters","AssistantCloud","LocalRuntimeOptions","Omit","cloud","initialMessages","adapters","useLocalThreadRuntime","chatModel","options","modelContext","threadListAdapters","opt","runtime","threadIdRef","undefined","current","s","threadListItem","remoteId","threads","getMainThreadRuntimeCore","__internal_setGetThreadId","detach","__internal_setOptions","__internal_load","registerModelContextProvider","splitLocalRuntimeOptions","T","maxSteps","unstable_humanToolNames","unstable_enableMessageQueue","rest","localRuntimeOptions","otherOptions","useLocalRuntime","cloudAdapter","runtimeHook","RuntimeHook","adapter","allowNesting"],"sources":["../../../src/react/runtimes/useLocalRuntime.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from \"react\";\nimport type {\n AssistantRuntime,\n ChatModelAdapter,\n ThreadMessageLike,\n} from \"../../index\";\nimport type { LocalRuntimeOptionsBase } from \"../../runtimes/local/local-runtime-options\";\nimport { AssistantRuntimeImpl, LocalRuntimeCore } from \"../../internal\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport { useRemoteThreadListRuntime } from \"./useRemoteThreadListRuntime\";\nimport { useCloudThreadListAdapter } from \"./cloud/useCloudThreadListAdapter\";\nimport { useRuntimeAdapters } from \"./RuntimeAdapterProvider\";\nimport type { AssistantCloud } from \"assistant-cloud\";\n\nexport type LocalRuntimeOptions = Omit<LocalRuntimeOptionsBase, \"adapters\"> & {\n cloud?: AssistantCloud | undefined;\n initialMessages?: readonly ThreadMessageLike[] | undefined;\n adapters?: Omit<LocalRuntimeOptionsBase[\"adapters\"], \"chatModel\"> | undefined;\n};\n\nconst useLocalThreadRuntime = (\n chatModel: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions,\n): AssistantRuntime => {\n const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};\n const opt = {\n ...options,\n adapters: {\n ...threadListAdapters,\n ...options.adapters,\n chatModel,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n const threadIdRef = useRef<string | undefined>(undefined);\n threadIdRef.current = useAuiState((s) => s.threadListItem.remoteId);\n\n useEffect(() => {\n runtime.threads\n .getMainThreadRuntimeCore()\n .__internal_setGetThreadId(() => threadIdRef.current);\n }, [runtime]);\n\n useEffect(() => {\n return () => {\n runtime.threads.getMainThreadRuntimeCore().detach();\n };\n }, [runtime]);\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n runtime.threads.getMainThreadRuntimeCore().__internal_load();\n });\n\n useEffect(() => {\n if (!modelContext) return undefined;\n return runtime.registerModelContextProvider(modelContext);\n }, [modelContext, runtime]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const splitLocalRuntimeOptions = <T extends LocalRuntimeOptions>(\n options: T,\n) => {\n const {\n cloud,\n initialMessages,\n maxSteps,\n adapters,\n unstable_humanToolNames,\n unstable_enableMessageQueue,\n ...rest\n } = options;\n\n return {\n localRuntimeOptions: {\n cloud,\n initialMessages,\n maxSteps,\n adapters,\n unstable_humanToolNames,\n unstable_enableMessageQueue,\n },\n otherOptions: rest,\n };\n};\n\nexport const useLocalRuntime = (\n chatModel: ChatModelAdapter,\n { cloud, ...options }: LocalRuntimeOptions = {},\n): AssistantRuntime => {\n const cloudAdapter = useCloudThreadListAdapter({ cloud });\n return useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useLocalThreadRuntime(chatModel, options);\n },\n adapter: cloudAdapter,\n allowNesting: true,\n });\n};\n"],"mappings":";;;;;;;;AAoBA,MAAMoB,yBACJC,WACA,EAAEH,iBAAiB,GAAGI,cACD;CACrB,MAAM,EAAEC,cAAc,GAAGC,uBAAuBX,mBAAmB,KAAK,CAAC;CACzE,MAAMY,MAAM;EACV,GAAGH;EACHH,UAAU;GACR,GAAGK;GACH,GAAGF,QAAQH;GACXE;EACF;CACF;CAEA,MAAM,CAACK,WAAWvB,eAAe,IAAIM,iBAAiBgB,KAAKP,eAAe,CAAC;CAE3E,MAAMS,cAAczB,OAA2B0B,KAAAA,CAAS;
|
|
1
|
+
{"version":3,"file":"useLocalRuntime.js","names":["useEffect","useMemo","useRef","useState","AssistantRuntime","ChatModelAdapter","ThreadMessageLike","LocalRuntimeOptionsBase","AssistantRuntimeImpl","LocalRuntimeCore","useAuiState","useRemoteThreadListRuntime","useCloudThreadListAdapter","useRuntimeAdapters","AssistantCloud","LocalRuntimeOptions","Omit","cloud","initialMessages","adapters","useLocalThreadRuntime","chatModel","options","modelContext","threadListAdapters","opt","runtime","threadIdRef","undefined","historyLoadPromiseRef","Promise","current","s","threadListItem","remoteId","threads","getMainThreadRuntimeCore","__internal_setGetThreadId","detach","__internal_setOptions","loadPromise","__internal_load","catch","error","console","registerModelContextProvider","splitLocalRuntimeOptions","T","maxSteps","unstable_humanToolNames","unstable_enableMessageQueue","rest","localRuntimeOptions","otherOptions","useLocalRuntime","cloudAdapter","runtimeHook","RuntimeHook","adapter","allowNesting"],"sources":["../../../src/react/runtimes/useLocalRuntime.ts"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from \"react\";\nimport type {\n AssistantRuntime,\n ChatModelAdapter,\n ThreadMessageLike,\n} from \"../../index\";\nimport type { LocalRuntimeOptionsBase } from \"../../runtimes/local/local-runtime-options\";\nimport { AssistantRuntimeImpl, LocalRuntimeCore } from \"../../internal\";\nimport { useAuiState } from \"@assistant-ui/store\";\nimport { useRemoteThreadListRuntime } from \"./useRemoteThreadListRuntime\";\nimport { useCloudThreadListAdapter } from \"./cloud/useCloudThreadListAdapter\";\nimport { useRuntimeAdapters } from \"./RuntimeAdapterProvider\";\nimport type { AssistantCloud } from \"assistant-cloud\";\n\nexport type LocalRuntimeOptions = Omit<LocalRuntimeOptionsBase, \"adapters\"> & {\n cloud?: AssistantCloud | undefined;\n initialMessages?: readonly ThreadMessageLike[] | undefined;\n adapters?: Omit<LocalRuntimeOptionsBase[\"adapters\"], \"chatModel\"> | undefined;\n};\n\nconst useLocalThreadRuntime = (\n chatModel: ChatModelAdapter,\n { initialMessages, ...options }: LocalRuntimeOptions,\n): AssistantRuntime => {\n const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};\n const opt = {\n ...options,\n adapters: {\n ...threadListAdapters,\n ...options.adapters,\n chatModel,\n },\n };\n\n const [runtime] = useState(() => new LocalRuntimeCore(opt, initialMessages));\n\n const threadIdRef = useRef<string | undefined>(undefined);\n const historyLoadPromiseRef = useRef<Promise<void> | undefined>(undefined);\n threadIdRef.current = useAuiState((s) => s.threadListItem.remoteId);\n\n useEffect(() => {\n runtime.threads\n .getMainThreadRuntimeCore()\n .__internal_setGetThreadId(() => threadIdRef.current);\n }, [runtime]);\n\n useEffect(() => {\n return () => {\n runtime.threads.getMainThreadRuntimeCore().detach();\n };\n }, [runtime]);\n\n useEffect(() => {\n runtime.threads.getMainThreadRuntimeCore().__internal_setOptions(opt);\n });\n\n useEffect(() => {\n const loadPromise = runtime.threads\n .getMainThreadRuntimeCore()\n .__internal_load();\n if (historyLoadPromiseRef.current === loadPromise) return;\n\n historyLoadPromiseRef.current = loadPromise;\n void loadPromise.catch((error: unknown) => {\n console.error(\"[assistant-ui] local thread history load failed:\", error);\n });\n }, [runtime]);\n\n useEffect(() => {\n if (!modelContext) return undefined;\n return runtime.registerModelContextProvider(modelContext);\n }, [modelContext, runtime]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const splitLocalRuntimeOptions = <T extends LocalRuntimeOptions>(\n options: T,\n) => {\n const {\n cloud,\n initialMessages,\n maxSteps,\n adapters,\n unstable_humanToolNames,\n unstable_enableMessageQueue,\n ...rest\n } = options;\n\n return {\n localRuntimeOptions: {\n cloud,\n initialMessages,\n maxSteps,\n adapters,\n unstable_humanToolNames,\n unstable_enableMessageQueue,\n },\n otherOptions: rest,\n };\n};\n\nexport const useLocalRuntime = (\n chatModel: ChatModelAdapter,\n { cloud, ...options }: LocalRuntimeOptions = {},\n): AssistantRuntime => {\n const cloudAdapter = useCloudThreadListAdapter({ cloud });\n return useRemoteThreadListRuntime({\n runtimeHook: function RuntimeHook() {\n return useLocalThreadRuntime(chatModel, options);\n },\n adapter: cloudAdapter,\n allowNesting: true,\n });\n};\n"],"mappings":";;;;;;;;AAoBA,MAAMoB,yBACJC,WACA,EAAEH,iBAAiB,GAAGI,cACD;CACrB,MAAM,EAAEC,cAAc,GAAGC,uBAAuBX,mBAAmB,KAAK,CAAC;CACzE,MAAMY,MAAM;EACV,GAAGH;EACHH,UAAU;GACR,GAAGK;GACH,GAAGF,QAAQH;GACXE;EACF;CACF;CAEA,MAAM,CAACK,WAAWvB,eAAe,IAAIM,iBAAiBgB,KAAKP,eAAe,CAAC;CAE3E,MAAMS,cAAczB,OAA2B0B,KAAAA,CAAS;CACxD,MAAMC,wBAAwB3B,OAAkC0B,KAAAA,CAAS;CACzED,YAAYI,UAAUrB,aAAasB,MAAMA,EAAEC,eAAeC,QAAQ;CAElElC,gBAAgB;EACd0B,QAAQS,QACLC,yBAAyB,CAAC,CAC1BC,gCAAgCV,YAAYI,OAAO;CACxD,GAAG,CAACL,OAAO,CAAC;CAEZ1B,gBAAgB;EACd,aAAa;GACX0B,QAAQS,QAAQC,yBAAyB,CAAC,CAACE,OAAO;EACpD;CACF,GAAG,CAACZ,OAAO,CAAC;CAEZ1B,gBAAgB;EACd0B,QAAQS,QAAQC,yBAAyB,CAAC,CAACG,sBAAsBd,GAAG;CACtE,CAAC;CAEDzB,gBAAgB;EACd,MAAMwC,cAAcd,QAAQS,QACzBC,yBAAyB,CAAC,CAC1BK,gBAAgB;EACnB,IAAIZ,sBAAsBE,YAAYS,aAAa;EAEnDX,sBAAsBE,UAAUS;EAChC,YAAiBE,OAAOC,UAAmB;GACzCC,QAAQD,MAAM,oDAAoDA,KAAK;EACzE,CAAC;CACH,GAAG,CAACjB,OAAO,CAAC;CAEZ1B,gBAAgB;EACd,IAAI,CAACuB,cAAc,OAAOK,KAAAA;EAC1B,OAAOF,QAAQmB,6BAA6BtB,YAAY;CAC1D,GAAG,CAACA,cAAcG,OAAO,CAAC;CAE1B,OAAOzB,cAAc,IAAIO,qBAAqBkB,OAAO,GAAG,CAACA,OAAO,CAAC;AACnE;AAEA,MAAaoB,4BACXxB,YACG;CACH,MAAM,EACJL,OACAC,iBACA8B,UACA7B,UACA8B,yBACAC,6BACA,GAAGC,SACD7B;CAEJ,OAAO;EACL8B,qBAAqB;GACnBnC;GACAC;GACA8B;GACA7B;GACA8B;GACAC;EACF;EACAG,cAAcF;CAChB;AACF;AAEA,MAAaG,mBACXjC,WACA,EAAEJ,OAAO,GAAGK,YAAiC,CAAC,MACzB;CAErB,OAAOX,2BAA2B;EAChC6C,aAAa,SAASC,cAAc;GAClC,OAAOrC,sBAAsBC,WAAWC,OAAO;EACjD;EACAoC,SALmB9C,0BAA0B,EAAEK,MAAM,CAK5CsC;EACTI,cAAc;CAChB,CAAC;AACH"}
|
|
@@ -21,9 +21,9 @@ type AssistantRuntime = {
|
|
|
21
21
|
registerModelContextProvider(provider: ModelContextProvider): Unsubscribe;
|
|
22
22
|
};
|
|
23
23
|
declare class AssistantRuntimeImpl implements AssistantRuntime {
|
|
24
|
-
private readonly _core;
|
|
25
24
|
readonly threads: ThreadListRuntimeImpl;
|
|
26
25
|
readonly _thread: ThreadRuntime;
|
|
26
|
+
private readonly _core;
|
|
27
27
|
constructor(_core: AssistantRuntimeCore);
|
|
28
28
|
protected __internal_bindMethods(): void;
|
|
29
29
|
get thread(): ThreadRuntime;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/assistant-runtime.ts"],"mappings":";;;;;;KASY;;;;WAID,SAAS;;;;WAKT,QAAQ;;;;;;EAOjB,6BAA6B,UAAU,uBAAuB;;cAGnD,gCAAgC;
|
|
1
|
+
{"version":3,"file":"assistant-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/assistant-runtime.ts"],"mappings":";;;;;;KASY;;;;WAID,SAAS;;;;WAKT,QAAQ;;;;;;EAOjB,6BAA6B,UAAU,uBAAuB;;cAGnD,gCAAgC;WAC3B,SAAO;WAEP,SAAS;mBAER;EAEL,YAAA,OAAO;YAQT;MAKC,UAAM;EAIV,6BAA6B,UAAU,uBAAoB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ThreadListRuntimeImpl } from "./thread-list-runtime.js";
|
|
2
2
|
//#region src/runtime/api/assistant-runtime.ts
|
|
3
3
|
var AssistantRuntimeImpl = class {
|
|
4
|
-
_core;
|
|
5
4
|
threads;
|
|
6
5
|
_thread;
|
|
6
|
+
_core;
|
|
7
7
|
constructor(_core) {
|
|
8
8
|
this._core = _core;
|
|
9
9
|
this.threads = new ThreadListRuntimeImpl(_core.threads);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant-runtime.js","names":["Unsubscribe","ModelContextProvider","AssistantRuntimeCore","ThreadRuntime","ThreadListRuntime","ThreadListRuntimeImpl","AssistantRuntime","threads","thread","registerModelContextProvider","provider","AssistantRuntimeImpl","_thread","
|
|
1
|
+
{"version":3,"file":"assistant-runtime.js","names":["Unsubscribe","ModelContextProvider","AssistantRuntimeCore","ThreadRuntime","ThreadListRuntime","ThreadListRuntimeImpl","AssistantRuntime","threads","thread","registerModelContextProvider","provider","AssistantRuntimeImpl","_thread","_core","constructor","main","__internal_bindMethods","bind"],"sources":["../../../src/runtime/api/assistant-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { ModelContextProvider } from \"../../model-context/types\";\nimport type { AssistantRuntimeCore } from \"../interfaces/assistant-runtime-core\";\nimport type { ThreadRuntime } from \"./thread-runtime\";\nimport {\n type ThreadListRuntime,\n ThreadListRuntimeImpl,\n} from \"./thread-list-runtime\";\n\nexport type AssistantRuntime = {\n /**\n * The threads in this assistant.\n */\n readonly threads: ThreadListRuntime;\n\n /**\n * The currently selected main thread. Equivalent to `threads.main`.\n */\n readonly thread: ThreadRuntime;\n\n /**\n * Register a model context provider. Model context providers are configuration such as system message, temperature, etc. that are set in the frontend.\n *\n * @param provider The model context provider to register.\n */\n registerModelContextProvider(provider: ModelContextProvider): Unsubscribe;\n};\n\nexport class AssistantRuntimeImpl implements AssistantRuntime {\n public readonly threads;\n\n public readonly _thread: ThreadRuntime;\n\n private readonly _core: AssistantRuntimeCore;\n\n constructor(_core: AssistantRuntimeCore) {\n this._core = _core;\n this.threads = new ThreadListRuntimeImpl(_core.threads);\n this._thread = this.threads.main;\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.registerModelContextProvider =\n this.registerModelContextProvider.bind(this);\n }\n\n public get thread() {\n return this._thread;\n }\n\n public registerModelContextProvider(provider: ModelContextProvider) {\n return this._core.registerModelContextProvider(provider);\n }\n}\n"],"mappings":";;AA4BA,IAAaW,uBAAb,MAA8D;CAC5D;CAEA;CAEA;CAEAG,YAAYD,OAA6B;EACvC,KAAKA,QAAQA;EACb,KAAKN,UAAU,IAAIF,sBAAsBQ,MAAMN,OAAO;EACtD,KAAKK,UAAU,KAAKL,QAAQQ;EAE5B,KAAKC,uBAAuB;CAC9B;CAEA,yBAAmC;EACjC,KAAKP,+BACH,KAAKA,6BAA6BQ,KAAK,IAAI;CAC/C;CAEA,IAAWT,SAAS;EAClB,OAAO,KAAKI;CACd;CAEA,6BAAoCF,UAAgC;EAClE,OAAO,KAAKG,MAAMJ,6BAA6BC,QAAQ;CACzD;AACF"}
|
|
@@ -32,11 +32,11 @@ type AttachmentRuntime<TSource extends AttachmentRuntimeSource = AttachmentRunti
|
|
|
32
32
|
subscribe(callback: () => void): Unsubscribe;
|
|
33
33
|
};
|
|
34
34
|
declare abstract class AttachmentRuntimeImpl<Source extends AttachmentRuntimeSource = AttachmentRuntimeSource> implements AttachmentRuntime {
|
|
35
|
-
private _core;
|
|
36
35
|
get path(): AttachmentRuntimePath & {
|
|
37
36
|
attachmentSource: Source;
|
|
38
37
|
};
|
|
39
38
|
abstract get source(): Source;
|
|
39
|
+
private _core;
|
|
40
40
|
constructor(_core: AttachmentSnapshotBinding<Source>);
|
|
41
41
|
protected __internal_bindMethods(): void;
|
|
42
42
|
getState(): AttachmentState & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/attachment-runtime.ts"],"mappings":";;;;;;KAOK,yBAAyB;WACnB;;KAGN,gCAAgC;WAC1B;;KAGN,8BAA8B;WACxB;;KAGC,kBACR,gCACA,8BACA;KAEC,0BAA0B,eAAe,2BAC5C,sBACE;EAAoB,QAAQ;GAC5B;EAA0B,kBAAkB;;KAG3C,0BAA0B;KAEnB,kBACV,gBAAgB,0BAA0B;WAEjC,MAAM;IAA0B,kBAAkB;;WAClD,QAAQ;EACjB,YAAY;IAAoB,QAAQ;;EACxC,UAAU;EACV,UAAU,uBAAuB;;uBAGb,sBACpB,eAAe,0BAA0B,oCAC9B;
|
|
1
|
+
{"version":3,"file":"attachment-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/attachment-runtime.ts"],"mappings":";;;;;;KAOK,yBAAyB;WACnB;;KAGN,gCAAgC;WAC1B;;KAGN,8BAA8B;WACxB;;KAGC,kBACR,gCACA,8BACA;KAEC,0BAA0B,eAAe,2BAC5C,sBACE;EAAoB,QAAQ;GAC5B;EAA0B,kBAAkB;;KAG3C,0BAA0B;KAEnB,kBACV,gBAAgB,0BAA0B;WAEjC,MAAM;IAA0B,kBAAkB;;WAClD,QAAQ;EACjB,YAAY;IAAoB,QAAQ;;EACxC,UAAU;EACV,UAAU,uBAAuB;;uBAGb,sBACpB,eAAe,0BAA0B,oCAC9B;MACA,QAAI;;;eAIK,UAAU;UAEtB;EAEI,YAAA,OAAO,0BAA0B;YAKnC;EAMH,YAAY;IAAoB,QAAQ;;WAI/B,UAAU;EAEnB,UAAU,uBAAoB;;uBAKxB,0BACb,4DACQ,sBAAsB;UACtB;EAGN,YAAA,MAAM,0BAA0B,SAChC,cAAc;EAMT,UAAM;;cAOF,4CAA4C;MAC5C;;cAKA,0CAA0C;MAC1C;;cAKA,qCAAqC;MACrC;EAIJ"}
|