@assistant-ui/core 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +6 -7
- package/dist/internal.js +5 -6
- package/dist/react/AssistantProvider.d.ts +1 -1
- package/dist/react/AssistantProvider.d.ts.map +1 -1
- package/dist/react/AssistantProvider.js +35 -9
- package/dist/react/AssistantProvider.js.map +1 -1
- package/dist/react/AssistantRuntimeProvider.d.ts +1 -1
- package/dist/react/AssistantRuntimeProvider.js +1 -1
- package/dist/react/RuntimeAdapter.js +2 -2
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +17 -33
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/DataRenderers.js +1 -1
- package/dist/react/client/Interactables.js +1 -1
- package/dist/react/client/Tools.js +2 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/interactables-legacy/Interactables.js +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.js +1 -1
- package/dist/react/interactables-legacy/useInteractableState.js +2 -2
- package/dist/react/model-context/useAssistantContext.js +1 -1
- package/dist/react/model-context/useAssistantDataUI.js +2 -2
- package/dist/react/model-context/useAssistantInstructions.js +2 -2
- package/dist/react/model-context/useAssistantTool.js +2 -2
- package/dist/react/model-context/useAssistantToolUI.js +2 -2
- package/dist/react/model-context/useAuiToolOverrides.js +1 -1
- package/dist/react/model-context/useInlineRender.js +1 -1
- package/dist/react/model-context/useInteractable.js +1 -1
- package/dist/react/model-context/useInteractableState.js +2 -2
- package/dist/react/model-context/useInteractableVersions.js +2 -2
- package/dist/react/model-context/useToolArgsStatus.js +2 -2
- package/dist/react/primitive-hooks/useActionBarCopy.js +52 -25
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +2 -2
- package/dist/react/primitive-hooks/useActionBarFeedback.js +2 -2
- package/dist/react/primitive-hooks/useActionBarReload.js +2 -2
- package/dist/react/primitive-hooks/useActionBarSpeak.js +2 -2
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +2 -2
- package/dist/react/primitive-hooks/useBranchPickerNext.js +2 -2
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +2 -2
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +2 -2
- package/dist/react/primitive-hooks/useComposerCancel.js +2 -2
- package/dist/react/primitive-hooks/useComposerDictate.js +2 -2
- package/dist/react/primitive-hooks/useComposerSend.js +2 -2
- package/dist/react/primitive-hooks/useEditComposerCancel.js +2 -2
- package/dist/react/primitive-hooks/useEditComposerSend.js +2 -2
- package/dist/react/primitive-hooks/useMessageBranching.js +2 -2
- package/dist/react/primitive-hooks/useMessageReload.js +2 -2
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemArchive.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemDelete.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +2 -2
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -2
- package/dist/react/primitive-hooks/useThreadListNew.js +2 -2
- package/dist/react/primitive-hooks/useThreadMessageIds.js +1 -1
- package/dist/react/primitive-hooks/useVoice.js +2 -2
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +2 -2
- package/dist/react/primitives/composer/ComposerAttachments.js +2 -2
- package/dist/react/primitives/composer/ComposerIf.js +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.js +2 -2
- package/dist/react/primitives/message/MessageAttachments.js +2 -2
- package/dist/react/primitives/message/MessageGroupedParts.d.ts +2 -1
- package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +3 -3
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +2 -2
- package/dist/react/primitives/message/MessageQuote.js +2 -2
- package/dist/react/primitives/part/PartMessages.js +2 -2
- package/dist/react/primitives/thread/ThreadMessages.js +2 -2
- package/dist/react/primitives/thread/ThreadSuggestions.js +2 -2
- package/dist/react/primitives/threadList/ThreadListItems.js +2 -2
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.js +1 -1
- package/dist/react/providers/AttachmentByIndexProvider.js +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +1 -1
- package/dist/react/providers/MessageByIdProvider.js +1 -1
- package/dist/react/providers/MessageByIndexProvider.js +1 -1
- package/dist/react/providers/PartByIndexProvider.js +1 -1
- package/dist/react/providers/QueueItemByIndexProvider.js +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.js +2 -2
- package/dist/react/providers/SuggestionByIndexProvider.js +1 -1
- package/dist/react/providers/TextMessagePartProvider.js +2 -2
- package/dist/react/providers/ThreadListItemByIndexProvider.js +1 -1
- package/dist/react/providers/ThreadListItemRuntimeProvider.js +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +14 -13
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +3 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +22 -12
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RuntimeAdapterProvider.js +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +9 -23
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +24 -2
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +24 -5
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.js +1 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.js +1 -1
- package/dist/react/runtimes/useLocalRuntime.js +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +7 -13
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/utils/useJSONEqual.js +1 -1
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +5 -1
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/internal.d.ts +4 -4
- package/dist/runtime/internal.js +4 -4
- package/dist/runtime/utils/thread-message-like.js +2 -2
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +5 -4
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.js +30 -24
- package/dist/store/clients/chain-of-thought-client.js.map +1 -1
- package/dist/store/clients/model-context-client.js +1 -1
- package/dist/store/clients/no-op-composer-client.js +1 -1
- package/dist/store/clients/suggestions.js +2 -2
- package/dist/store/clients/thread-message-client.d.ts.map +1 -1
- package/dist/store/clients/thread-message-client.js +103 -91
- package/dist/store/clients/thread-message-client.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +2 -2
- package/dist/store/runtime-clients/message-runtime-client.js +2 -2
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +2 -2
- package/dist/store/runtime-clients/thread-list-runtime-client.js +2 -2
- package/dist/store/runtime-clients/thread-runtime-client.js +2 -2
- package/dist/store/scopes/thread.d.ts +1 -1
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/message.d.ts +11 -1
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/data-url.js +2 -2
- package/dist/utils/data-url.js.map +1 -1
- package/dist/utils/getGroupStatus.d.ts +9 -0
- package/dist/utils/getGroupStatus.d.ts.map +1 -0
- package/dist/utils/getGroupStatus.js +15 -0
- package/dist/utils/getGroupStatus.js.map +1 -0
- package/dist/utils/normalizePartStatus.d.ts +8 -0
- package/dist/utils/normalizePartStatus.d.ts.map +1 -0
- package/dist/utils/normalizePartStatus.js +39 -0
- package/dist/utils/normalizePartStatus.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/internal.ts +1 -7
- package/src/react/AssistantProvider.tsx +28 -15
- package/src/react/AssistantRuntimeProvider.test.tsx +101 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +28 -7
- package/src/react/index.ts +4 -0
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +109 -14
- package/src/react/primitive-hooks/useActionBarCopy.ts +27 -2
- package/src/react/primitives/message/MessageGroupedParts.tsx +4 -4
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +16 -13
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +53 -10
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +7 -5
- package/src/react/runtimes/cloud/auiV0.ts +51 -12
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +9 -15
- package/src/runtime/api/message-runtime.test.ts +140 -0
- package/src/runtime/api/message-runtime.ts +10 -5
- package/src/runtime/utils/thread-message-like.ts +2 -2
- package/src/runtimes/remote-thread-list/types.ts +5 -4
- package/src/store/clients/chain-of-thought-client.ts +2 -7
- package/src/store/clients/thread-message-client.test.ts +84 -0
- package/src/store/clients/thread-message-client.ts +14 -4
- package/src/store/scopes/thread.ts +1 -1
- package/src/tests/auiV0Encode.test.ts +93 -0
- package/src/tests/remote-thread-list-reactive-threadId.test.ts +0 -92
- package/src/tests/thread-message-like.test.ts +15 -0
- package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +293 -0
- package/src/types/index.ts +1 -0
- package/src/types/message.ts +19 -0
- package/src/utils/data-url.test.ts +26 -2
- package/src/utils/data-url.ts +2 -2
- package/src/utils/getGroupStatus.test.ts +36 -0
- package/src/utils/getGroupStatus.ts +31 -0
- package/src/utils/normalizePartStatus.test.ts +59 -0
- package/src/utils/normalizePartStatus.ts +55 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference path="./store/scope-registration.d.ts" />
|
|
2
|
-
import { AppendMessage, DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, ImageMessagePart, MCP_APP_URI_SCHEME, McpAppMetadata, MessagePartStatus, MessageRole, MessageStatus, MessageTiming, PartProviderMetadata, ReasoningMessagePart, RunConfig, SourceMessagePart, SourceProviderMetadata, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadMessage, ThreadStep, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolApprovalOption, ToolApprovalOptionKind, ToolApprovalResponse, ToolCallMessagePart, ToolCallMessagePartMcpMetadata, ToolCallMessagePartStatus, ToolCallTiming, ToolModelContentPart, Unstable_AudioMessagePart, isMcpAppUri } from "./types/message.js";
|
|
2
|
+
import { AppendMessage, DataMessagePart, FileMessagePart, GenerativeUIMessagePart, GenerativeUINode, GenerativeUISpec, ImageMessagePart, MCP_APP_URI_SCHEME, McpAppMetadata, MessagePartStatus, MessagePartStreamStatus, MessageRole, MessageStatus, MessageTiming, PartProviderMetadata, ReasoningMessagePart, RunConfig, SourceMessagePart, SourceProviderMetadata, TextMessagePart, ThreadAssistantMessage, ThreadAssistantMessagePart, ThreadMessage, ThreadStep, ThreadSystemMessage, ThreadUserMessage, ThreadUserMessagePart, ToolApprovalOption, ToolApprovalOptionKind, ToolApprovalResponse, ToolCallMessagePart, ToolCallMessagePartMcpMetadata, ToolCallMessagePartStatus, ToolCallTiming, ToolModelContentPart, Unstable_AudioMessagePart, isMcpAppUri } from "./types/message.js";
|
|
3
3
|
import { Attachment, AttachmentStatus, CompleteAttachment, CompleteAttachmentStatus, CreateAttachment, PendingAttachment, PendingAttachmentStatus } from "./types/attachment.js";
|
|
4
4
|
import { AttachmentAdapter, CompositeAttachmentAdapter, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter } from "./adapters/attachment.js";
|
|
5
5
|
import { Unstable_TriggerCategory, Unstable_TriggerItem } from "./types/trigger.js";
|
|
@@ -33,12 +33,12 @@ import { ThreadListItemCoreState, ThreadListItemStatus, ThreadListRuntimeCore }
|
|
|
33
33
|
import { AssistantRuntimeCore } from "./runtime/interfaces/assistant-runtime-core.js";
|
|
34
34
|
import { generateId } from "./utils/id.js";
|
|
35
35
|
import { ThreadListItemState } from "./runtime/api/bindings.js";
|
|
36
|
-
import { ThreadListItemEventCallback, ThreadListItemEventPayload, ThreadListItemEventType, ThreadListItemRuntime } from "./runtime/api/thread-list-item-runtime.js";
|
|
37
|
-
import { ThreadListRuntime, ThreadListState } from "./runtime/api/thread-list-runtime.js";
|
|
38
36
|
import { AttachmentRuntime, AttachmentState } from "./runtime/api/attachment-runtime.js";
|
|
39
37
|
import { ComposerRuntime, ComposerState, EditComposerRuntime, EditComposerState, ThreadComposerRuntime, ThreadComposerState } from "./runtime/api/composer-runtime.js";
|
|
40
38
|
import { MessagePartRuntime, MessagePartState } from "./runtime/api/message-part-runtime.js";
|
|
41
39
|
import { MessageRuntime, MessageState } from "./runtime/api/message-runtime.js";
|
|
40
|
+
import { ThreadListItemEventCallback, ThreadListItemEventPayload, ThreadListItemEventType, ThreadListItemRuntime } from "./runtime/api/thread-list-item-runtime.js";
|
|
41
|
+
import { ThreadListRuntime, ThreadListState } from "./runtime/api/thread-list-runtime.js";
|
|
42
42
|
import { bindExternalStoreMessage, getExternalStoreMessages } from "./runtime/utils/external-store-message.js";
|
|
43
43
|
import { LocalRuntimeOptionsBase } from "./runtimes/local/local-runtime-options.js";
|
|
44
44
|
import { ExternalThreadQueueAdapter } from "./runtime/queue/external-thread-queue-adapter.js";
|
|
@@ -52,4 +52,4 @@ import { ExternalThreadBranchAdapter } from "./runtime/branch/external-thread-br
|
|
|
52
52
|
import { MessageQueueController, MessageQueueDriver, createMessageQueue } from "./runtime/queue/message-queue.js";
|
|
53
53
|
import { InMemoryThreadListAdapter } from "./runtimes/remote-thread-list/adapter/in-memory.js";
|
|
54
54
|
import { createRequestHeaders } from "./runtimes/assistant-transport/utils.js";
|
|
55
|
-
export { type AddToolResultOptions, type AppendMessage, type AssistantContextConfig, type AssistantError, type AssistantErrorCode, AssistantFrameHost, AssistantFrameProvider, type AssistantInstructionsConfig, type AssistantRuntime, type AssistantRuntimeCore, type AssistantToolProps, type Attachment, type AttachmentAdapter, type AttachmentAddErrorEvent, type AttachmentAddErrorReason, type AttachmentRuntime, type AttachmentRuntimePath, type AttachmentState, type AttachmentStatus, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, type CompleteAttachment, type CompleteAttachmentStatus, type ComposerRuntime, type ComposerRuntimeCore, type ComposerRuntimeEventCallback, type ComposerRuntimeEventPayload, type ComposerRuntimeEventType, type ComposerRuntimePath, type ComposerState, CompositeAttachmentAdapter, type CoreChatModelRunResult, type CreateAppendMessage, type CreateAttachment, type CreateResumeRunConfig, type CreateStartRunConfig, type CreateSuggestionAdapterOptions, type DataMessagePart, type DictationAdapter, type DictationState, type EditComposerRuntime, type EditComposerRuntimeCore, type EditComposerState, type ErrorDisplay, type ErrorSeverity, ExportedMessageRepository, type ExportedMessageRepositoryItem, type ExternalStoreAdapter, type ExternalStoreBranchChange, type ExternalStoreMessageConverter, type ExternalStoreSharedOptions, type ExternalStoreThreadData, type ExternalStoreThreadListAdapter, type ExternalThreadBranchAdapter, type ExternalThreadQueueAdapter, FRAME_MESSAGE_CHANNEL, type FeedbackAdapter, type FileMessagePart, type FrameMessage, type FrameMessageType, type GenerativeUIMessagePart, type GenerativeUINode, type GenerativeUISpec, type GenericThreadHistoryAdapter, type ImageMessagePart, InMemoryThreadListAdapter, type LanguageModelConfig, type LanguageModelV1CallSettings, type LocalRuntimeOptionsBase, MCP_APP_URI_SCHEME, type McpAppMetadata, type MessageFormatAdapter, type MessageFormatItem, type MessageFormatRepository, type MessagePartRuntime, type MessagePartRuntimePath, type MessagePartState, type MessagePartStatus, type MessageQueueController, type MessageQueueDriver, type MessageRole, type MessageRuntime, type MessageRuntimePath, type MessageState, type MessageStatus, type MessageStorageEntry, type MessageTiming, type ModelContext, type ModelContextProvider, ModelContextRegistry, type ModelContextRegistryInstructionHandle, type ModelContextRegistryProviderHandle, type ModelContextRegistryToolHandle, type PartProviderMetadata, type PendingAttachment, type PendingAttachmentStatus, type QuoteInfo, type RealtimeVoiceAdapter, type ReasoningMessagePart, type RemoteThreadInitializeResponse, type RemoteThreadListAdapter, type RemoteThreadListOptions, type RemoteThreadListPageOptions, type RemoteThreadListResponse, type RemoteThreadMetadata, type RespondToToolApprovalOptions, type ResumeRunConfig, type ResumeToolCallOptions, type RunConfig, type RuntimeCapabilities, type SendOptions, type SerializedModelContext, type SerializedTool, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, type SourceMessagePart, type SourceProviderMetadata, type SpeechState, type SpeechSynthesisAdapter, type StartRunConfig, type StreamingTimingAccessors, type StreamingTimingOptions, type StreamingTimingState, type SubmitFeedbackOptions, type SubmittedFeedback, type SuggestionAdapter, type SuggestionAdapterGenerateOptions, type TextMessagePart, type ThreadAssistantMessage, type ThreadAssistantMessagePart, type ThreadComposerRuntime, type ThreadComposerRuntimeCore, type ThreadComposerState, type ThreadHistoryAdapter, type ThreadListItemCoreState, type ThreadListItemEventCallback, type ThreadListItemEventPayload, type ThreadListItemEventType, type ThreadListItemRuntime, type ThreadListItemRuntimePath, type ThreadListItemState, type ThreadListItemStatus, type ThreadListRuntime, type ThreadListRuntimeCore, type ThreadListState, type ThreadMessage, type ThreadMessageLike, type ThreadRuntime, type ThreadRuntimeCore, type ThreadRuntimeEventCallback, type ThreadRuntimeEventPayload, type ThreadRuntimeEventType, type ThreadRuntimePath, type ThreadState, type ThreadStep, type ThreadSuggestion, type ThreadSystemMessage, type ThreadUserMessage, type ThreadUserMessagePart, type ToolApprovalOption, type ToolApprovalOptionKind, type ToolApprovalResponse, type ToolCallMessagePart, type ToolCallMessagePartMcpMetadata, type ToolCallMessagePartStatus, type ToolCallTiming, type ToolExecutionStatus, type ToolModelContentPart, type Unstable_AudioMessagePart, type Unstable_DirectiveFormatter, type Unstable_DirectiveSegment, type Unstable_InteractableSnapshotEntry, type Unstable_InteractableVersion, type Unstable_TriggerAdapter, type Unstable_TriggerCategory, type Unstable_TriggerItem, type Unsubscribe, type VoiceSessionControls, type VoiceSessionHelpers, type VoiceSessionState, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createRequestHeaders, createSuggestionAdapter, createVoiceSession, fromThreadMessageLike, generateId, getExternalStoreMessages, isAssistantError, isMcpAppUri, mergeModelContexts, pickExternalStoreSharedOptions, stepStreamingTiming, toAssistantError, tool, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions };
|
|
55
|
+
export { type AddToolResultOptions, type AppendMessage, type AssistantContextConfig, type AssistantError, type AssistantErrorCode, AssistantFrameHost, AssistantFrameProvider, type AssistantInstructionsConfig, type AssistantRuntime, type AssistantRuntimeCore, type AssistantToolProps, type Attachment, type AttachmentAdapter, type AttachmentAddErrorEvent, type AttachmentAddErrorReason, type AttachmentRuntime, type AttachmentRuntimePath, type AttachmentState, type AttachmentStatus, type ChatModelAdapter, type ChatModelRunOptions, type ChatModelRunResult, type ChatModelRunUpdate, type CompleteAttachment, type CompleteAttachmentStatus, type ComposerRuntime, type ComposerRuntimeCore, type ComposerRuntimeEventCallback, type ComposerRuntimeEventPayload, type ComposerRuntimeEventType, type ComposerRuntimePath, type ComposerState, CompositeAttachmentAdapter, type CoreChatModelRunResult, type CreateAppendMessage, type CreateAttachment, type CreateResumeRunConfig, type CreateStartRunConfig, type CreateSuggestionAdapterOptions, type DataMessagePart, type DictationAdapter, type DictationState, type EditComposerRuntime, type EditComposerRuntimeCore, type EditComposerState, type ErrorDisplay, type ErrorSeverity, ExportedMessageRepository, type ExportedMessageRepositoryItem, type ExternalStoreAdapter, type ExternalStoreBranchChange, type ExternalStoreMessageConverter, type ExternalStoreSharedOptions, type ExternalStoreThreadData, type ExternalStoreThreadListAdapter, type ExternalThreadBranchAdapter, type ExternalThreadQueueAdapter, FRAME_MESSAGE_CHANNEL, type FeedbackAdapter, type FileMessagePart, type FrameMessage, type FrameMessageType, type GenerativeUIMessagePart, type GenerativeUINode, type GenerativeUISpec, type GenericThreadHistoryAdapter, type ImageMessagePart, InMemoryThreadListAdapter, type LanguageModelConfig, type LanguageModelV1CallSettings, type LocalRuntimeOptionsBase, MCP_APP_URI_SCHEME, type McpAppMetadata, type MessageFormatAdapter, type MessageFormatItem, type MessageFormatRepository, type MessagePartRuntime, type MessagePartRuntimePath, type MessagePartState, type MessagePartStatus, type MessagePartStreamStatus, type MessageQueueController, type MessageQueueDriver, type MessageRole, type MessageRuntime, type MessageRuntimePath, type MessageState, type MessageStatus, type MessageStorageEntry, type MessageTiming, type ModelContext, type ModelContextProvider, ModelContextRegistry, type ModelContextRegistryInstructionHandle, type ModelContextRegistryProviderHandle, type ModelContextRegistryToolHandle, type PartProviderMetadata, type PendingAttachment, type PendingAttachmentStatus, type QuoteInfo, type RealtimeVoiceAdapter, type ReasoningMessagePart, type RemoteThreadInitializeResponse, type RemoteThreadListAdapter, type RemoteThreadListOptions, type RemoteThreadListPageOptions, type RemoteThreadListResponse, type RemoteThreadMetadata, type RespondToToolApprovalOptions, type ResumeRunConfig, type ResumeToolCallOptions, type RunConfig, type RuntimeCapabilities, type SendOptions, type SerializedModelContext, type SerializedTool, SimpleImageAttachmentAdapter, SimpleTextAttachmentAdapter, type SourceMessagePart, type SourceProviderMetadata, type SpeechState, type SpeechSynthesisAdapter, type StartRunConfig, type StreamingTimingAccessors, type StreamingTimingOptions, type StreamingTimingState, type SubmitFeedbackOptions, type SubmittedFeedback, type SuggestionAdapter, type SuggestionAdapterGenerateOptions, type TextMessagePart, type ThreadAssistantMessage, type ThreadAssistantMessagePart, type ThreadComposerRuntime, type ThreadComposerRuntimeCore, type ThreadComposerState, type ThreadHistoryAdapter, type ThreadListItemCoreState, type ThreadListItemEventCallback, type ThreadListItemEventPayload, type ThreadListItemEventType, type ThreadListItemRuntime, type ThreadListItemRuntimePath, type ThreadListItemState, type ThreadListItemStatus, type ThreadListRuntime, type ThreadListRuntimeCore, type ThreadListState, type ThreadMessage, type ThreadMessageLike, type ThreadRuntime, type ThreadRuntimeCore, type ThreadRuntimeEventCallback, type ThreadRuntimeEventPayload, type ThreadRuntimeEventType, type ThreadRuntimePath, type ThreadState, type ThreadStep, type ThreadSuggestion, type ThreadSystemMessage, type ThreadUserMessage, type ThreadUserMessagePart, type ToolApprovalOption, type ToolApprovalOptionKind, type ToolApprovalResponse, type ToolCallMessagePart, type ToolCallMessagePartMcpMetadata, type ToolCallMessagePartStatus, type ToolCallTiming, type ToolExecutionStatus, type ToolModelContentPart, type Unstable_AudioMessagePart, type Unstable_DirectiveFormatter, type Unstable_DirectiveSegment, type Unstable_InteractableSnapshotEntry, type Unstable_InteractableVersion, type Unstable_TriggerAdapter, type Unstable_TriggerCategory, type Unstable_TriggerItem, type Unsubscribe, type VoiceSessionControls, type VoiceSessionHelpers, type VoiceSessionState, WebSpeechDictationAdapter, WebSpeechSynthesisAdapter, bindExternalStoreMessage, createMessageQueue, createRequestHeaders, createSuggestionAdapter, createVoiceSession, fromThreadMessageLike, generateId, getExternalStoreMessages, isAssistantError, isMcpAppUri, mergeModelContexts, pickExternalStoreSharedOptions, stepStreamingTiming, toAssistantError, tool, unstable_defaultDirectiveFormatter, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["checkDuplicateCore","process","env","NODE_ENV","TextMessagePart","ReasoningMessagePart","PartProviderMetadata","SourceProviderMetadata","SourceMessagePart","ImageMessagePart","FileMessagePart","DataMessagePart","GenerativeUIMessagePart","GenerativeUINode","GenerativeUISpec","Unstable_AudioMessagePart","ToolApprovalOption","ToolApprovalOptionKind","ToolApprovalResponse","ToolCallMessagePart","ToolCallTiming","ToolCallMessagePartMcpMetadata","McpAppMetadata","ToolModelContentPart","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","ToolCallMessagePartStatus","MessageStatus","MessageTiming","ThreadStep","ThreadSystemMessage","ThreadUserMessage","ThreadAssistantMessage","ThreadMessage","MessageRole","RunConfig","AppendMessage","MCP_APP_URI_SCHEME","isMcpAppUri","Attachment","PendingAttachment","PendingAttachmentStatus","CompleteAttachment","CompleteAttachmentStatus","AttachmentStatus","CreateAttachment","Unsubscribe","QuoteInfo","Unstable_DirectiveSegment","Unstable_DirectiveFormatter","Unstable_TriggerItem","Unstable_TriggerCategory","Unstable_TriggerAdapter","LanguageModelV1CallSettings","LanguageModelConfig","ModelContext","ModelContextProvider","AssistantToolProps","AssistantInstructionsConfig","AssistantContextConfig","mergeModelContexts","tool","unstable_getInteractableSnapshots","unstable_formatInteractableSnapshot","unstable_getInteractableVersions","Unstable_InteractableSnapshotEntry","Unstable_InteractableVersion","ToolExecutionStatus","ModelContextRegistry","ModelContextRegistryToolHandle","ModelContextRegistryInstructionHandle","ModelContextRegistryProviderHandle","AssistantFrameHost","AssistantFrameProvider","SerializedTool","SerializedModelContext","FrameMessageType","FrameMessage","FRAME_MESSAGE_CHANNEL","AttachmentAdapter","SimpleImageAttachmentAdapter","SimpleTextAttachmentAdapter","CompositeAttachmentAdapter","SpeechSynthesisAdapter","DictationAdapter","WebSpeechSynthesisAdapter","WebSpeechDictationAdapter","RealtimeVoiceAdapter","createVoiceSession","VoiceSessionControls","VoiceSessionHelpers","FeedbackAdapter","SuggestionAdapter","SuggestionAdapterGenerateOptions","CreateSuggestionAdapterOptions","createSuggestionAdapter","unstable_defaultDirectiveFormatter","ThreadHistoryAdapter","GenericThreadHistoryAdapter","MessageFormatAdapter","MessageFormatItem","MessageFormatRepository","MessageStorageEntry","ThreadListItemRuntimePath","ThreadRuntimePath","MessageRuntimePath","MessagePartRuntimePath","AttachmentRuntimePath","ComposerRuntimePath","AttachmentAddErrorEvent","AttachmentAddErrorReason","ComposerRuntimeCore","ComposerRuntimeEventCallback","ComposerRuntimeEventPayload","ComposerRuntimeEventType","DictationState","EditComposerRuntimeCore","SendOptions","ThreadComposerRuntimeCore","ErrorSeverity","ErrorDisplay","AssistantErrorCode","AssistantError","toAssistantError","isAssistantError","RuntimeCapabilities","AddToolResultOptions","ResumeToolCallOptions","RespondToToolApprovalOptions","SubmitFeedbackOptions","ThreadSuggestion","SpeechState","VoiceSessionState","SubmittedFeedback","ThreadRuntimeEventCallback","ThreadRuntimeEventPayload","ThreadRuntimeEventType","StartRunConfig","ResumeRunConfig","ThreadRuntimeCore","ThreadListItemStatus","ThreadListItemCoreState","ThreadListRuntimeCore","AssistantRuntimeCore","AssistantRuntime","CreateStartRunConfig","CreateResumeRunConfig","CreateAppendMessage","ThreadState","ThreadRuntime","ThreadListState","ThreadListRuntime","ThreadListItemEventCallback","ThreadListItemEventPayload","ThreadListItemEventType","ThreadListItemRuntime","ThreadListItemState","MessageState","MessageRuntime","MessagePartState","MessagePartRuntime","ThreadComposerState","EditComposerState","ComposerState","ComposerRuntime","ThreadComposerRuntime","EditComposerRuntime","AttachmentState","AttachmentRuntime","ChatModelRunUpdate","ChatModelRunResult","CoreChatModelRunResult","ChatModelRunOptions","ChatModelAdapter","ThreadMessageLike","fromThreadMessageLike","StreamingTimingAccessors","StreamingTimingOptions","StreamingTimingState","stepStreamingTiming","generateId","getExternalStoreMessages","bindExternalStoreMessage","ExportedMessageRepositoryItem","ExportedMessageRepository","LocalRuntimeOptionsBase","ExternalStoreAdapter","ExternalStoreMessageConverter","ExternalStoreThreadListAdapter","ExternalStoreThreadData","ExternalStoreBranchChange","ExternalStoreSharedOptions","pickExternalStoreSharedOptions","ExternalThreadQueueAdapter","ExternalThreadBranchAdapter","createMessageQueue","MessageQueueDriver","MessageQueueController","RemoteThreadListAdapter","RemoteThreadListOptions","RemoteThreadInitializeResponse","RemoteThreadMetadata","RemoteThreadListResponse","RemoteThreadListPageOptions","InMemoryThreadListAdapter","createRequestHeaders"],"sources":["../src/index.ts"],"sourcesContent":["// @assistant-ui/core - Framework-agnostic core runtime (public API)\n\n/// <reference path=\"./store/scope-registration.ts\" />\n\nimport { checkDuplicateCore } from \"./internal/duplicate-detection\";\n\nif (process.env.NODE_ENV !== \"production\") {\n checkDuplicateCore();\n}\n\nexport type {\n // Message parts\n TextMessagePart,\n ReasoningMessagePart,\n PartProviderMetadata,\n SourceProviderMetadata,\n SourceMessagePart,\n ImageMessagePart,\n FileMessagePart,\n DataMessagePart,\n GenerativeUIMessagePart,\n GenerativeUINode,\n GenerativeUISpec,\n Unstable_AudioMessagePart,\n ToolApprovalOption,\n ToolApprovalOptionKind,\n ToolApprovalResponse,\n ToolCallMessagePart,\n ToolCallTiming,\n ToolCallMessagePartMcpMetadata,\n McpAppMetadata,\n ToolModelContentPart,\n ThreadUserMessagePart,\n ThreadAssistantMessagePart,\n // Message status\n MessagePartStatus,\n ToolCallMessagePartStatus,\n MessageStatus,\n // Thread messages\n MessageTiming,\n ThreadStep,\n ThreadSystemMessage,\n ThreadUserMessage,\n ThreadAssistantMessage,\n ThreadMessage,\n MessageRole,\n // Config\n RunConfig,\n AppendMessage,\n} from \"./types/message\";\n\nexport { MCP_APP_URI_SCHEME, isMcpAppUri } from \"./types/message\";\n\nexport type {\n Attachment,\n PendingAttachment,\n PendingAttachmentStatus,\n CompleteAttachment,\n CompleteAttachmentStatus,\n AttachmentStatus,\n CreateAttachment,\n} from \"./types/attachment\";\n\nexport type { Unsubscribe } from \"./types/unsubscribe\";\n\nexport type { QuoteInfo } from \"./types/quote\";\n\nexport type {\n Unstable_DirectiveSegment,\n Unstable_DirectiveFormatter,\n} from \"./types/directive\";\n\nexport type {\n Unstable_TriggerItem,\n Unstable_TriggerCategory,\n} from \"./types/trigger\";\n\nexport type { Unstable_TriggerAdapter } from \"./adapters/trigger\";\n\nexport type {\n // Language model settings\n LanguageModelV1CallSettings,\n LanguageModelConfig,\n // Model context\n ModelContext,\n ModelContextProvider,\n // Tool & instruction config\n AssistantToolProps,\n AssistantInstructionsConfig,\n AssistantContextConfig,\n} from \"./model-context/types\";\nexport { mergeModelContexts } from \"./model-context/types\";\n\nexport { tool } from \"./model-context/tool\";\n\nexport {\n unstable_getInteractableSnapshots,\n unstable_formatInteractableSnapshot,\n unstable_getInteractableVersions,\n type Unstable_InteractableSnapshotEntry,\n type Unstable_InteractableVersion,\n} from \"./model-context/interactable-composer-metadata\";\n\nexport type { ToolExecutionStatus } from \"./runtimes/tool-invocations/ToolInvocationTracker\";\n\nexport { ModelContextRegistry } from \"./model-context/registry\";\nexport type {\n ModelContextRegistryToolHandle,\n ModelContextRegistryInstructionHandle,\n ModelContextRegistryProviderHandle,\n} from \"./model-context/registry-handles\";\n\nexport { AssistantFrameHost } from \"./model-context/frame/host\";\nexport { AssistantFrameProvider } from \"./model-context/frame/provider\";\nexport type {\n SerializedTool,\n SerializedModelContext,\n FrameMessageType,\n FrameMessage,\n} from \"./model-context/frame/types\";\nexport { FRAME_MESSAGE_CHANNEL } from \"./model-context/frame/types\";\n\n// Attachment adapters\nexport type { AttachmentAdapter } from \"./adapters/attachment\";\nexport {\n SimpleImageAttachmentAdapter,\n SimpleTextAttachmentAdapter,\n CompositeAttachmentAdapter,\n} from \"./adapters/attachment\";\n\n// Speech adapters\nexport type {\n SpeechSynthesisAdapter,\n DictationAdapter,\n} from \"./adapters/speech\";\nexport {\n WebSpeechSynthesisAdapter,\n WebSpeechDictationAdapter,\n} from \"./adapters/speech\";\n\n// Voice adapter\nexport type { RealtimeVoiceAdapter } from \"./adapters/voice\";\nexport { createVoiceSession } from \"./adapters/voice\";\nexport type {\n VoiceSessionControls,\n VoiceSessionHelpers,\n} from \"./adapters/voice\";\n\n// Feedback adapter\nexport type { FeedbackAdapter } from \"./adapters/feedback\";\n\n// Suggestion adapter\nexport type {\n SuggestionAdapter,\n SuggestionAdapterGenerateOptions,\n CreateSuggestionAdapterOptions,\n} from \"./adapters/suggestion\";\nexport { createSuggestionAdapter } from \"./adapters/suggestion\";\n\n// Directive formatter\nexport { unstable_defaultDirectiveFormatter } from \"./adapters/directive-formatter\";\n\n// Thread history adapters\nexport type {\n ThreadHistoryAdapter,\n GenericThreadHistoryAdapter,\n MessageFormatAdapter,\n MessageFormatItem,\n MessageFormatRepository,\n MessageStorageEntry,\n} from \"./adapters/thread-history\";\n\n// Path Types\nexport type {\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n MessageRuntimePath,\n MessagePartRuntimePath,\n AttachmentRuntimePath,\n ComposerRuntimePath,\n} from \"./runtime/api/paths\";\n\n// Runtime Core Interface Types\nexport type {\n AttachmentAddErrorEvent,\n AttachmentAddErrorReason,\n ComposerRuntimeCore,\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventPayload,\n ComposerRuntimeEventType,\n DictationState,\n EditComposerRuntimeCore,\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"./runtime/interfaces/composer-runtime-core\";\n\nexport type {\n ErrorSeverity,\n ErrorDisplay,\n AssistantErrorCode,\n AssistantError,\n} from \"./types/error\";\nexport { toAssistantError, isAssistantError } from \"./types/error\";\n\nexport type {\n RuntimeCapabilities,\n AddToolResultOptions,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n SubmitFeedbackOptions,\n ThreadSuggestion,\n SpeechState,\n VoiceSessionState,\n SubmittedFeedback,\n ThreadRuntimeEventCallback,\n ThreadRuntimeEventPayload,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n ThreadRuntimeCore,\n} from \"./runtime/interfaces/thread-runtime-core\";\n\nexport type {\n ThreadListItemStatus,\n ThreadListItemCoreState,\n ThreadListRuntimeCore,\n} from \"./runtime/interfaces/thread-list-runtime-core\";\n\nexport type { AssistantRuntimeCore } from \"./runtime/interfaces/assistant-runtime-core\";\n\n// Public Runtime Types\nexport type { AssistantRuntime } from \"./runtime/api/assistant-runtime\";\n\nexport type {\n CreateStartRunConfig,\n CreateResumeRunConfig,\n CreateAppendMessage,\n ThreadState,\n ThreadRuntime,\n} from \"./runtime/api/thread-runtime\";\n\nexport type {\n ThreadListState,\n ThreadListRuntime,\n} from \"./runtime/api/thread-list-runtime\";\n\nexport type {\n ThreadListItemEventCallback,\n ThreadListItemEventPayload,\n ThreadListItemEventType,\n ThreadListItemRuntime,\n} from \"./runtime/api/thread-list-item-runtime\";\n\nexport type { ThreadListItemState } from \"./runtime/api/bindings\";\n\nexport type {\n MessageState,\n MessageRuntime,\n} from \"./runtime/api/message-runtime\";\nexport type {\n MessagePartState,\n MessagePartRuntime,\n} from \"./runtime/api/message-part-runtime\";\n\nexport type {\n ThreadComposerState,\n EditComposerState,\n ComposerState,\n ComposerRuntime,\n ThreadComposerRuntime,\n EditComposerRuntime,\n} from \"./runtime/api/composer-runtime\";\n\nexport type {\n AttachmentState,\n AttachmentRuntime,\n} from \"./runtime/api/attachment-runtime\";\n\n// ChatModel Types\nexport type {\n ChatModelRunUpdate,\n ChatModelRunResult,\n CoreChatModelRunResult,\n ChatModelRunOptions,\n ChatModelAdapter,\n} from \"./runtime/utils/chat-model-adapter\";\n\n// ThreadMessageLike\nexport type { ThreadMessageLike } from \"./runtime/utils/thread-message-like\";\nexport { fromThreadMessageLike } from \"./runtime/utils/thread-message-like\";\n\n// Streaming timing (client-side)\nexport type {\n StreamingTimingAccessors,\n StreamingTimingOptions,\n StreamingTimingState,\n} from \"./runtime/utils/streaming-timing\";\nexport { stepStreamingTiming } from \"./runtime/utils/streaming-timing\";\n\n// ID generation\nexport { generateId } from \"./utils/id\";\n\n// External Store Message Utilities\nexport {\n getExternalStoreMessages,\n bindExternalStoreMessage,\n} from \"./runtime/utils/external-store-message\";\n\n// ExportedMessageRepository\nexport type { ExportedMessageRepositoryItem } from \"./runtime/utils/message-repository\";\nexport { ExportedMessageRepository } from \"./runtime/utils/message-repository\";\n\n// Local Runtime Options\nexport type { LocalRuntimeOptionsBase } from \"./runtimes/local/local-runtime-options\";\n\n// External Store Adapter Types (user-facing)\nexport type {\n ExternalStoreAdapter,\n ExternalStoreMessageConverter,\n ExternalStoreThreadListAdapter,\n ExternalStoreThreadData,\n ExternalStoreBranchChange,\n} from \"./runtimes/external-store/external-store-adapter\";\nexport type { ExternalStoreSharedOptions } from \"./runtimes/external-store/external-store-shared-options\";\nexport { pickExternalStoreSharedOptions } from \"./runtimes/external-store/external-store-shared-options\";\n\n// Message queue\nexport type { ExternalThreadQueueAdapter } from \"./runtime/queue/external-thread-queue-adapter\";\nexport type { ExternalThreadBranchAdapter } from \"./runtime/branch/external-thread-branch-adapter\";\nexport {\n createMessageQueue,\n type MessageQueueDriver,\n type MessageQueueController,\n} from \"./runtime/queue/message-queue\";\n\n// Remote Thread List (user-facing)\nexport type {\n RemoteThreadListAdapter,\n RemoteThreadListOptions,\n RemoteThreadInitializeResponse,\n RemoteThreadMetadata,\n RemoteThreadListResponse,\n RemoteThreadListPageOptions,\n} from \"./runtimes/remote-thread-list/types\";\n\nexport { InMemoryThreadListAdapter } from \"./runtimes/remote-thread-list/adapter/in-memory\";\n\n// Assistant Transport Utilities\nexport { createRequestHeaders } from \"./runtimes/assistant-transport/utils\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAIC,QAAQC,IAAIC,aAAa,cAC3BH,mBAAmB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["checkDuplicateCore","process","env","NODE_ENV","TextMessagePart","ReasoningMessagePart","PartProviderMetadata","SourceProviderMetadata","SourceMessagePart","ImageMessagePart","FileMessagePart","DataMessagePart","GenerativeUIMessagePart","GenerativeUINode","GenerativeUISpec","Unstable_AudioMessagePart","ToolApprovalOption","ToolApprovalOptionKind","ToolApprovalResponse","ToolCallMessagePart","ToolCallTiming","ToolCallMessagePartMcpMetadata","McpAppMetadata","ToolModelContentPart","ThreadUserMessagePart","ThreadAssistantMessagePart","MessagePartStatus","MessagePartStreamStatus","ToolCallMessagePartStatus","MessageStatus","MessageTiming","ThreadStep","ThreadSystemMessage","ThreadUserMessage","ThreadAssistantMessage","ThreadMessage","MessageRole","RunConfig","AppendMessage","MCP_APP_URI_SCHEME","isMcpAppUri","Attachment","PendingAttachment","PendingAttachmentStatus","CompleteAttachment","CompleteAttachmentStatus","AttachmentStatus","CreateAttachment","Unsubscribe","QuoteInfo","Unstable_DirectiveSegment","Unstable_DirectiveFormatter","Unstable_TriggerItem","Unstable_TriggerCategory","Unstable_TriggerAdapter","LanguageModelV1CallSettings","LanguageModelConfig","ModelContext","ModelContextProvider","AssistantToolProps","AssistantInstructionsConfig","AssistantContextConfig","mergeModelContexts","tool","unstable_getInteractableSnapshots","unstable_formatInteractableSnapshot","unstable_getInteractableVersions","Unstable_InteractableSnapshotEntry","Unstable_InteractableVersion","ToolExecutionStatus","ModelContextRegistry","ModelContextRegistryToolHandle","ModelContextRegistryInstructionHandle","ModelContextRegistryProviderHandle","AssistantFrameHost","AssistantFrameProvider","SerializedTool","SerializedModelContext","FrameMessageType","FrameMessage","FRAME_MESSAGE_CHANNEL","AttachmentAdapter","SimpleImageAttachmentAdapter","SimpleTextAttachmentAdapter","CompositeAttachmentAdapter","SpeechSynthesisAdapter","DictationAdapter","WebSpeechSynthesisAdapter","WebSpeechDictationAdapter","RealtimeVoiceAdapter","createVoiceSession","VoiceSessionControls","VoiceSessionHelpers","FeedbackAdapter","SuggestionAdapter","SuggestionAdapterGenerateOptions","CreateSuggestionAdapterOptions","createSuggestionAdapter","unstable_defaultDirectiveFormatter","ThreadHistoryAdapter","GenericThreadHistoryAdapter","MessageFormatAdapter","MessageFormatItem","MessageFormatRepository","MessageStorageEntry","ThreadListItemRuntimePath","ThreadRuntimePath","MessageRuntimePath","MessagePartRuntimePath","AttachmentRuntimePath","ComposerRuntimePath","AttachmentAddErrorEvent","AttachmentAddErrorReason","ComposerRuntimeCore","ComposerRuntimeEventCallback","ComposerRuntimeEventPayload","ComposerRuntimeEventType","DictationState","EditComposerRuntimeCore","SendOptions","ThreadComposerRuntimeCore","ErrorSeverity","ErrorDisplay","AssistantErrorCode","AssistantError","toAssistantError","isAssistantError","RuntimeCapabilities","AddToolResultOptions","ResumeToolCallOptions","RespondToToolApprovalOptions","SubmitFeedbackOptions","ThreadSuggestion","SpeechState","VoiceSessionState","SubmittedFeedback","ThreadRuntimeEventCallback","ThreadRuntimeEventPayload","ThreadRuntimeEventType","StartRunConfig","ResumeRunConfig","ThreadRuntimeCore","ThreadListItemStatus","ThreadListItemCoreState","ThreadListRuntimeCore","AssistantRuntimeCore","AssistantRuntime","CreateStartRunConfig","CreateResumeRunConfig","CreateAppendMessage","ThreadState","ThreadRuntime","ThreadListState","ThreadListRuntime","ThreadListItemEventCallback","ThreadListItemEventPayload","ThreadListItemEventType","ThreadListItemRuntime","ThreadListItemState","MessageState","MessageRuntime","MessagePartState","MessagePartRuntime","ThreadComposerState","EditComposerState","ComposerState","ComposerRuntime","ThreadComposerRuntime","EditComposerRuntime","AttachmentState","AttachmentRuntime","ChatModelRunUpdate","ChatModelRunResult","CoreChatModelRunResult","ChatModelRunOptions","ChatModelAdapter","ThreadMessageLike","fromThreadMessageLike","StreamingTimingAccessors","StreamingTimingOptions","StreamingTimingState","stepStreamingTiming","generateId","getExternalStoreMessages","bindExternalStoreMessage","ExportedMessageRepositoryItem","ExportedMessageRepository","LocalRuntimeOptionsBase","ExternalStoreAdapter","ExternalStoreMessageConverter","ExternalStoreThreadListAdapter","ExternalStoreThreadData","ExternalStoreBranchChange","ExternalStoreSharedOptions","pickExternalStoreSharedOptions","ExternalThreadQueueAdapter","ExternalThreadBranchAdapter","createMessageQueue","MessageQueueDriver","MessageQueueController","RemoteThreadListAdapter","RemoteThreadListOptions","RemoteThreadInitializeResponse","RemoteThreadMetadata","RemoteThreadListResponse","RemoteThreadListPageOptions","InMemoryThreadListAdapter","createRequestHeaders"],"sources":["../src/index.ts"],"sourcesContent":["// @assistant-ui/core - Framework-agnostic core runtime (public API)\n\n/// <reference path=\"./store/scope-registration.ts\" />\n\nimport { checkDuplicateCore } from \"./internal/duplicate-detection\";\n\nif (process.env.NODE_ENV !== \"production\") {\n checkDuplicateCore();\n}\n\nexport type {\n // Message parts\n TextMessagePart,\n ReasoningMessagePart,\n PartProviderMetadata,\n SourceProviderMetadata,\n SourceMessagePart,\n ImageMessagePart,\n FileMessagePart,\n DataMessagePart,\n GenerativeUIMessagePart,\n GenerativeUINode,\n GenerativeUISpec,\n Unstable_AudioMessagePart,\n ToolApprovalOption,\n ToolApprovalOptionKind,\n ToolApprovalResponse,\n ToolCallMessagePart,\n ToolCallTiming,\n ToolCallMessagePartMcpMetadata,\n McpAppMetadata,\n ToolModelContentPart,\n ThreadUserMessagePart,\n ThreadAssistantMessagePart,\n // Message status\n MessagePartStatus,\n MessagePartStreamStatus,\n ToolCallMessagePartStatus,\n MessageStatus,\n // Thread messages\n MessageTiming,\n ThreadStep,\n ThreadSystemMessage,\n ThreadUserMessage,\n ThreadAssistantMessage,\n ThreadMessage,\n MessageRole,\n // Config\n RunConfig,\n AppendMessage,\n} from \"./types/message\";\n\nexport { MCP_APP_URI_SCHEME, isMcpAppUri } from \"./types/message\";\n\nexport type {\n Attachment,\n PendingAttachment,\n PendingAttachmentStatus,\n CompleteAttachment,\n CompleteAttachmentStatus,\n AttachmentStatus,\n CreateAttachment,\n} from \"./types/attachment\";\n\nexport type { Unsubscribe } from \"./types/unsubscribe\";\n\nexport type { QuoteInfo } from \"./types/quote\";\n\nexport type {\n Unstable_DirectiveSegment,\n Unstable_DirectiveFormatter,\n} from \"./types/directive\";\n\nexport type {\n Unstable_TriggerItem,\n Unstable_TriggerCategory,\n} from \"./types/trigger\";\n\nexport type { Unstable_TriggerAdapter } from \"./adapters/trigger\";\n\nexport type {\n // Language model settings\n LanguageModelV1CallSettings,\n LanguageModelConfig,\n // Model context\n ModelContext,\n ModelContextProvider,\n // Tool & instruction config\n AssistantToolProps,\n AssistantInstructionsConfig,\n AssistantContextConfig,\n} from \"./model-context/types\";\nexport { mergeModelContexts } from \"./model-context/types\";\n\nexport { tool } from \"./model-context/tool\";\n\nexport {\n unstable_getInteractableSnapshots,\n unstable_formatInteractableSnapshot,\n unstable_getInteractableVersions,\n type Unstable_InteractableSnapshotEntry,\n type Unstable_InteractableVersion,\n} from \"./model-context/interactable-composer-metadata\";\n\nexport type { ToolExecutionStatus } from \"./runtimes/tool-invocations/ToolInvocationTracker\";\n\nexport { ModelContextRegistry } from \"./model-context/registry\";\nexport type {\n ModelContextRegistryToolHandle,\n ModelContextRegistryInstructionHandle,\n ModelContextRegistryProviderHandle,\n} from \"./model-context/registry-handles\";\n\nexport { AssistantFrameHost } from \"./model-context/frame/host\";\nexport { AssistantFrameProvider } from \"./model-context/frame/provider\";\nexport type {\n SerializedTool,\n SerializedModelContext,\n FrameMessageType,\n FrameMessage,\n} from \"./model-context/frame/types\";\nexport { FRAME_MESSAGE_CHANNEL } from \"./model-context/frame/types\";\n\n// Attachment adapters\nexport type { AttachmentAdapter } from \"./adapters/attachment\";\nexport {\n SimpleImageAttachmentAdapter,\n SimpleTextAttachmentAdapter,\n CompositeAttachmentAdapter,\n} from \"./adapters/attachment\";\n\n// Speech adapters\nexport type {\n SpeechSynthesisAdapter,\n DictationAdapter,\n} from \"./adapters/speech\";\nexport {\n WebSpeechSynthesisAdapter,\n WebSpeechDictationAdapter,\n} from \"./adapters/speech\";\n\n// Voice adapter\nexport type { RealtimeVoiceAdapter } from \"./adapters/voice\";\nexport { createVoiceSession } from \"./adapters/voice\";\nexport type {\n VoiceSessionControls,\n VoiceSessionHelpers,\n} from \"./adapters/voice\";\n\n// Feedback adapter\nexport type { FeedbackAdapter } from \"./adapters/feedback\";\n\n// Suggestion adapter\nexport type {\n SuggestionAdapter,\n SuggestionAdapterGenerateOptions,\n CreateSuggestionAdapterOptions,\n} from \"./adapters/suggestion\";\nexport { createSuggestionAdapter } from \"./adapters/suggestion\";\n\n// Directive formatter\nexport { unstable_defaultDirectiveFormatter } from \"./adapters/directive-formatter\";\n\n// Thread history adapters\nexport type {\n ThreadHistoryAdapter,\n GenericThreadHistoryAdapter,\n MessageFormatAdapter,\n MessageFormatItem,\n MessageFormatRepository,\n MessageStorageEntry,\n} from \"./adapters/thread-history\";\n\n// Path Types\nexport type {\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n MessageRuntimePath,\n MessagePartRuntimePath,\n AttachmentRuntimePath,\n ComposerRuntimePath,\n} from \"./runtime/api/paths\";\n\n// Runtime Core Interface Types\nexport type {\n AttachmentAddErrorEvent,\n AttachmentAddErrorReason,\n ComposerRuntimeCore,\n ComposerRuntimeEventCallback,\n ComposerRuntimeEventPayload,\n ComposerRuntimeEventType,\n DictationState,\n EditComposerRuntimeCore,\n SendOptions,\n ThreadComposerRuntimeCore,\n} from \"./runtime/interfaces/composer-runtime-core\";\n\nexport type {\n ErrorSeverity,\n ErrorDisplay,\n AssistantErrorCode,\n AssistantError,\n} from \"./types/error\";\nexport { toAssistantError, isAssistantError } from \"./types/error\";\n\nexport type {\n RuntimeCapabilities,\n AddToolResultOptions,\n ResumeToolCallOptions,\n RespondToToolApprovalOptions,\n SubmitFeedbackOptions,\n ThreadSuggestion,\n SpeechState,\n VoiceSessionState,\n SubmittedFeedback,\n ThreadRuntimeEventCallback,\n ThreadRuntimeEventPayload,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n ThreadRuntimeCore,\n} from \"./runtime/interfaces/thread-runtime-core\";\n\nexport type {\n ThreadListItemStatus,\n ThreadListItemCoreState,\n ThreadListRuntimeCore,\n} from \"./runtime/interfaces/thread-list-runtime-core\";\n\nexport type { AssistantRuntimeCore } from \"./runtime/interfaces/assistant-runtime-core\";\n\n// Public Runtime Types\nexport type { AssistantRuntime } from \"./runtime/api/assistant-runtime\";\n\nexport type {\n CreateStartRunConfig,\n CreateResumeRunConfig,\n CreateAppendMessage,\n ThreadState,\n ThreadRuntime,\n} from \"./runtime/api/thread-runtime\";\n\nexport type {\n ThreadListState,\n ThreadListRuntime,\n} from \"./runtime/api/thread-list-runtime\";\n\nexport type {\n ThreadListItemEventCallback,\n ThreadListItemEventPayload,\n ThreadListItemEventType,\n ThreadListItemRuntime,\n} from \"./runtime/api/thread-list-item-runtime\";\n\nexport type { ThreadListItemState } from \"./runtime/api/bindings\";\n\nexport type {\n MessageState,\n MessageRuntime,\n} from \"./runtime/api/message-runtime\";\nexport type {\n MessagePartState,\n MessagePartRuntime,\n} from \"./runtime/api/message-part-runtime\";\n\nexport type {\n ThreadComposerState,\n EditComposerState,\n ComposerState,\n ComposerRuntime,\n ThreadComposerRuntime,\n EditComposerRuntime,\n} from \"./runtime/api/composer-runtime\";\n\nexport type {\n AttachmentState,\n AttachmentRuntime,\n} from \"./runtime/api/attachment-runtime\";\n\n// ChatModel Types\nexport type {\n ChatModelRunUpdate,\n ChatModelRunResult,\n CoreChatModelRunResult,\n ChatModelRunOptions,\n ChatModelAdapter,\n} from \"./runtime/utils/chat-model-adapter\";\n\n// ThreadMessageLike\nexport type { ThreadMessageLike } from \"./runtime/utils/thread-message-like\";\nexport { fromThreadMessageLike } from \"./runtime/utils/thread-message-like\";\n\n// Streaming timing (client-side)\nexport type {\n StreamingTimingAccessors,\n StreamingTimingOptions,\n StreamingTimingState,\n} from \"./runtime/utils/streaming-timing\";\nexport { stepStreamingTiming } from \"./runtime/utils/streaming-timing\";\n\n// ID generation\nexport { generateId } from \"./utils/id\";\n\n// External Store Message Utilities\nexport {\n getExternalStoreMessages,\n bindExternalStoreMessage,\n} from \"./runtime/utils/external-store-message\";\n\n// ExportedMessageRepository\nexport type { ExportedMessageRepositoryItem } from \"./runtime/utils/message-repository\";\nexport { ExportedMessageRepository } from \"./runtime/utils/message-repository\";\n\n// Local Runtime Options\nexport type { LocalRuntimeOptionsBase } from \"./runtimes/local/local-runtime-options\";\n\n// External Store Adapter Types (user-facing)\nexport type {\n ExternalStoreAdapter,\n ExternalStoreMessageConverter,\n ExternalStoreThreadListAdapter,\n ExternalStoreThreadData,\n ExternalStoreBranchChange,\n} from \"./runtimes/external-store/external-store-adapter\";\nexport type { ExternalStoreSharedOptions } from \"./runtimes/external-store/external-store-shared-options\";\nexport { pickExternalStoreSharedOptions } from \"./runtimes/external-store/external-store-shared-options\";\n\n// Message queue\nexport type { ExternalThreadQueueAdapter } from \"./runtime/queue/external-thread-queue-adapter\";\nexport type { ExternalThreadBranchAdapter } from \"./runtime/branch/external-thread-branch-adapter\";\nexport {\n createMessageQueue,\n type MessageQueueDriver,\n type MessageQueueController,\n} from \"./runtime/queue/message-queue\";\n\n// Remote Thread List (user-facing)\nexport type {\n RemoteThreadListAdapter,\n RemoteThreadListOptions,\n RemoteThreadInitializeResponse,\n RemoteThreadMetadata,\n RemoteThreadListResponse,\n RemoteThreadListPageOptions,\n} from \"./runtimes/remote-thread-list/types\";\n\nexport { InMemoryThreadListAdapter } from \"./runtimes/remote-thread-list/adapter/in-memory\";\n\n// Assistant Transport Utilities\nexport { createRequestHeaders } from \"./runtimes/assistant-transport/utils\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAIC,QAAQC,IAAIC,aAAa,cAC3BH,mBAAmB"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -7,13 +7,16 @@ import { ToolInvocationTracker } from "./runtimes/tool-invocations/ToolInvocatio
|
|
|
7
7
|
import { BaseSubject, BaseSubscribable, EventSubscribable, EventSubscriptionSubject, LazyMemoizeSubject, NestedSubscribable, NestedSubscriptionSubject, SKIP_UPDATE, ShallowMemoizeSubject, Subscribable, SubscribableWithState } from "./subscribable/subscribable.js";
|
|
8
8
|
import { generateErrorMessageId, generateId, isErrorMessageId } from "./utils/id.js";
|
|
9
9
|
import { getThreadMessageText } from "./utils/text.js";
|
|
10
|
+
import { ComposerRuntimeCoreBinding, EditComposerRuntimeCoreBinding, MessageStateBinding, ThreadComposerRuntimeCoreBinding } from "./runtime/api/bindings.js";
|
|
11
|
+
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./runtime/api/attachment-runtime.js";
|
|
12
|
+
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./runtime/api/composer-runtime.js";
|
|
13
|
+
import { MessagePartRuntimeImpl } from "./runtime/api/message-part-runtime.js";
|
|
14
|
+
import { MessageRuntimeImpl, toMessagePartStatus } from "./runtime/api/message-runtime.js";
|
|
10
15
|
import { resolveToolApprovalResponse } from "./runtime/utils/resolveToolApprovalResponse.js";
|
|
11
16
|
import { CompositeContextProvider } from "./utils/composite-context-provider.js";
|
|
12
17
|
import { stableStringifyToolArgs, trackToolArgsKeyOrder } from "./utils/json/stable-stringify-tool-args.js";
|
|
13
18
|
import { isJSONValue, isRecord } from "./utils/json/is-json.js";
|
|
14
19
|
import { httpUrlPattern, parseDataUrl } from "./utils/data-url.js";
|
|
15
|
-
import { RuntimeExtras, createRuntimeExtras } from "./react/runtimes/createRuntimeExtras.js";
|
|
16
|
-
import { ComposerRuntimeCoreBinding, EditComposerRuntimeCoreBinding, MessageStateBinding, ThreadComposerRuntimeCoreBinding } from "./runtime/api/bindings.js";
|
|
17
20
|
import { BaseAssistantRuntimeCore } from "./runtime/base/base-assistant-runtime-core.js";
|
|
18
21
|
import { BaseComposerRuntimeCore } from "./runtime/base/base-composer-runtime-core.js";
|
|
19
22
|
import { DefaultThreadComposerRuntimeCore } from "./runtime/base/default-thread-composer-runtime-core.js";
|
|
@@ -21,10 +24,6 @@ import { DefaultEditComposerRuntimeCore } from "./runtime/base/default-edit-comp
|
|
|
21
24
|
import { BaseThreadRuntimeCore } from "./runtime/base/base-thread-runtime-core.js";
|
|
22
25
|
import { ThreadListItemRuntimeImpl, ThreadListItemStateBinding } from "./runtime/api/thread-list-item-runtime.js";
|
|
23
26
|
import { ThreadListRuntimeCoreBinding, ThreadListRuntimeImpl } from "./runtime/api/thread-list-runtime.js";
|
|
24
|
-
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./runtime/api/attachment-runtime.js";
|
|
25
|
-
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./runtime/api/composer-runtime.js";
|
|
26
|
-
import { MessagePartRuntimeImpl } from "./runtime/api/message-part-runtime.js";
|
|
27
|
-
import { MessageRuntimeImpl } from "./runtime/api/message-runtime.js";
|
|
28
27
|
import { symbolInnerMessage } from "./runtime/utils/external-store-message.js";
|
|
29
28
|
import { getAutoStatus, isAutoStatus } from "./runtime/utils/auto-status.js";
|
|
30
29
|
import "./runtime/internal.js";
|
|
@@ -45,4 +44,4 @@ import { RemoteThreadData, RemoteThreadState, THREAD_MAPPING_ID, createThreadMap
|
|
|
45
44
|
import "./runtimes/internal.js";
|
|
46
45
|
import { ThreadListItemRuntimeBinding, ThreadRuntimeCoreBinding, ThreadRuntimeImpl, getThreadState } from "./runtime/api/thread-runtime.js";
|
|
47
46
|
import { AssistantRuntimeImpl } from "./runtime/api/assistant-runtime.js";
|
|
48
|
-
export { AssistantRuntimeImpl, AttachmentRuntimeImpl, BaseAssistantRuntimeCore, BaseComposerRuntimeCore, BaseSubject, BaseSubscribable, BaseThreadRuntimeCore, type ComposerRuntimeCoreBinding, ComposerRuntimeImpl, CompositeContextProvider, type ConverterCallback, DefaultEditComposerRuntimeCore, DefaultThreadComposerRuntimeCore, EMPTY_THREAD_CORE, EditComposerAttachmentRuntimeImpl, type EditComposerRuntimeCoreBinding, EditComposerRuntimeImpl, type EventSubscribable, EventSubscriptionSubject, ExportedMessageRepository, type ExportedMessageRepositoryItem, ExternalStoreRuntimeCore, type ExternalStoreThreadFactory, ExternalStoreThreadListRuntimeCore, ExternalStoreThreadRuntimeCore, LazyMemoizeSubject, LocalRuntimeCore, type LocalRuntimeOptionsBase, type LocalThreadFactory, LocalThreadListRuntimeCore, LocalThreadRuntimeCore, MessageAttachmentRuntimeImpl, MessagePartRuntimeImpl, MessageRepository, MessageRuntimeImpl, type MessageStateBinding, type NestedSubscribable, NestedSubscriptionSubject, OptimisticState, ReadonlyThreadRuntimeCore, type RemoteThreadData, type RemoteThreadInitializeResponse, type RemoteThreadListOptions, type RemoteThreadState,
|
|
47
|
+
export { AssistantRuntimeImpl, AttachmentRuntimeImpl, BaseAssistantRuntimeCore, BaseComposerRuntimeCore, BaseSubject, BaseSubscribable, BaseThreadRuntimeCore, type ComposerRuntimeCoreBinding, ComposerRuntimeImpl, CompositeContextProvider, type ConverterCallback, DefaultEditComposerRuntimeCore, DefaultThreadComposerRuntimeCore, EMPTY_THREAD_CORE, EditComposerAttachmentRuntimeImpl, type EditComposerRuntimeCoreBinding, EditComposerRuntimeImpl, type EventSubscribable, EventSubscriptionSubject, ExportedMessageRepository, type ExportedMessageRepositoryItem, ExternalStoreRuntimeCore, type ExternalStoreThreadFactory, ExternalStoreThreadListRuntimeCore, ExternalStoreThreadRuntimeCore, LazyMemoizeSubject, LocalRuntimeCore, type LocalRuntimeOptionsBase, type LocalThreadFactory, LocalThreadListRuntimeCore, LocalThreadRuntimeCore, MessageAttachmentRuntimeImpl, MessagePartRuntimeImpl, MessageRepository, MessageRuntimeImpl, type MessageStateBinding, type NestedSubscribable, NestedSubscriptionSubject, OptimisticState, ReadonlyThreadRuntimeCore, type RemoteThreadData, type RemoteThreadInitializeResponse, type RemoteThreadListOptions, type RemoteThreadState, SKIP_UPDATE, type SKIP_UPDATE as SKIP_UPDATE_TYPE, ShallowMemoizeSubject, type Subscribable, type SubscribableWithState, type THREAD_MAPPING_ID, ThreadComposerAttachmentRuntimeImpl, type ThreadComposerRuntimeCoreBinding, ThreadComposerRuntimeImpl, type ThreadListItemRuntimeBinding, ThreadListItemRuntimeImpl, type ThreadListItemStateBinding, type ThreadListRuntimeCoreBinding, ThreadListRuntimeImpl, ThreadMessageConverter, type ThreadRuntimeCoreBinding, ThreadRuntimeImpl, ToolInvocationTracker, consumeSuggestionResult, createThreadMappingId, fileMatchesAccept, fromThreadMessageLike, generateErrorMessageId, generateId, getAutoStatus, getFileDataURL, getThreadData, getThreadMessageText, getThreadState, hasUpcomingMessage, httpUrlPattern, isAutoStatus, isCreateAttachment, isErrorMessageId, isJSONValue, isRecord, parseDataUrl, resolveToolApprovalResponse, shouldContinue, stableStringifyToolArgs, symbolInnerMessage, toMessagePartStatus, trackToolArgsKeyOrder, updateStatusReducer };
|
package/dist/internal.js
CHANGED
|
@@ -8,22 +8,21 @@ import { symbolInnerMessage } from "./runtime/utils/external-store-message.js";
|
|
|
8
8
|
import { getAutoStatus, isAutoStatus } from "./runtime/utils/auto-status.js";
|
|
9
9
|
import { ExportedMessageRepository, MessageRepository } from "./runtime/utils/message-repository.js";
|
|
10
10
|
import { BaseSubject, BaseSubscribable, EventSubscriptionSubject, LazyMemoizeSubject, NestedSubscriptionSubject, SKIP_UPDATE, ShallowMemoizeSubject } from "./subscribable/subscribable.js";
|
|
11
|
+
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./runtime/api/attachment-runtime.js";
|
|
12
|
+
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./runtime/api/composer-runtime.js";
|
|
11
13
|
import { resolveToolApprovalResponse } from "./runtime/utils/resolveToolApprovalResponse.js";
|
|
14
|
+
import { MessagePartRuntimeImpl } from "./runtime/api/message-part-runtime.js";
|
|
15
|
+
import { MessageRuntimeImpl, toMessagePartStatus } from "./runtime/api/message-runtime.js";
|
|
12
16
|
import { CompositeContextProvider } from "./utils/composite-context-provider.js";
|
|
13
17
|
import { isCreateAttachment } from "./types/attachment.js";
|
|
14
18
|
import { stableStringifyToolArgs, trackToolArgsKeyOrder } from "./utils/json/stable-stringify-tool-args.js";
|
|
15
19
|
import { httpUrlPattern, parseDataUrl } from "./utils/data-url.js";
|
|
16
|
-
import { createRuntimeExtras } from "./react/runtimes/createRuntimeExtras.js";
|
|
17
20
|
import { BaseAssistantRuntimeCore } from "./runtime/base/base-assistant-runtime-core.js";
|
|
18
21
|
import { BaseComposerRuntimeCore } from "./runtime/base/base-composer-runtime-core.js";
|
|
19
22
|
import { DefaultThreadComposerRuntimeCore } from "./runtime/base/default-thread-composer-runtime-core.js";
|
|
20
23
|
import { DefaultEditComposerRuntimeCore } from "./runtime/base/default-edit-composer-runtime-core.js";
|
|
21
24
|
import { BaseThreadRuntimeCore } from "./runtime/base/base-thread-runtime-core.js";
|
|
22
25
|
import { ThreadListItemRuntimeImpl } from "./runtime/api/thread-list-item-runtime.js";
|
|
23
|
-
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./runtime/api/attachment-runtime.js";
|
|
24
|
-
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./runtime/api/composer-runtime.js";
|
|
25
|
-
import { MessagePartRuntimeImpl } from "./runtime/api/message-part-runtime.js";
|
|
26
|
-
import { MessageRuntimeImpl } from "./runtime/api/message-runtime.js";
|
|
27
26
|
import { ThreadRuntimeImpl, getThreadState } from "./runtime/api/thread-runtime.js";
|
|
28
27
|
import { ThreadListRuntimeImpl } from "./runtime/api/thread-list-runtime.js";
|
|
29
28
|
import { AssistantRuntimeImpl } from "./runtime/api/assistant-runtime.js";
|
|
@@ -40,4 +39,4 @@ import { ReadonlyThreadRuntimeCore } from "./runtimes/readonly/ReadonlyThreadRun
|
|
|
40
39
|
import { OptimisticState } from "./runtimes/remote-thread-list/optimistic-state.js";
|
|
41
40
|
import { EMPTY_THREAD_CORE } from "./runtimes/remote-thread-list/empty-thread-core.js";
|
|
42
41
|
import { createThreadMappingId, getThreadData, updateStatusReducer } from "./runtimes/remote-thread-list/remote-thread-state.js";
|
|
43
|
-
export { AssistantRuntimeImpl, AttachmentRuntimeImpl, BaseAssistantRuntimeCore, BaseComposerRuntimeCore, BaseSubject, BaseSubscribable, BaseThreadRuntimeCore, ComposerRuntimeImpl, CompositeContextProvider, DefaultEditComposerRuntimeCore, DefaultThreadComposerRuntimeCore, EMPTY_THREAD_CORE, EditComposerAttachmentRuntimeImpl, EditComposerRuntimeImpl, EventSubscriptionSubject, ExportedMessageRepository, ExternalStoreRuntimeCore, ExternalStoreThreadListRuntimeCore, ExternalStoreThreadRuntimeCore, LazyMemoizeSubject, LocalRuntimeCore, LocalThreadListRuntimeCore, LocalThreadRuntimeCore, MessageAttachmentRuntimeImpl, MessagePartRuntimeImpl, MessageRepository, MessageRuntimeImpl, NestedSubscriptionSubject, OptimisticState, ReadonlyThreadRuntimeCore, SKIP_UPDATE, ShallowMemoizeSubject, ThreadComposerAttachmentRuntimeImpl, ThreadComposerRuntimeImpl, ThreadListItemRuntimeImpl, ThreadListRuntimeImpl, ThreadMessageConverter, ThreadRuntimeImpl, ToolInvocationTracker, consumeSuggestionResult,
|
|
42
|
+
export { AssistantRuntimeImpl, AttachmentRuntimeImpl, BaseAssistantRuntimeCore, BaseComposerRuntimeCore, BaseSubject, BaseSubscribable, BaseThreadRuntimeCore, ComposerRuntimeImpl, CompositeContextProvider, DefaultEditComposerRuntimeCore, DefaultThreadComposerRuntimeCore, EMPTY_THREAD_CORE, EditComposerAttachmentRuntimeImpl, EditComposerRuntimeImpl, EventSubscriptionSubject, ExportedMessageRepository, ExternalStoreRuntimeCore, ExternalStoreThreadListRuntimeCore, ExternalStoreThreadRuntimeCore, LazyMemoizeSubject, LocalRuntimeCore, LocalThreadListRuntimeCore, LocalThreadRuntimeCore, MessageAttachmentRuntimeImpl, MessagePartRuntimeImpl, MessageRepository, MessageRuntimeImpl, NestedSubscriptionSubject, OptimisticState, ReadonlyThreadRuntimeCore, SKIP_UPDATE, ShallowMemoizeSubject, ThreadComposerAttachmentRuntimeImpl, ThreadComposerRuntimeImpl, ThreadListItemRuntimeImpl, ThreadListRuntimeImpl, ThreadMessageConverter, ThreadRuntimeImpl, ToolInvocationTracker, consumeSuggestionResult, createThreadMappingId, fileMatchesAccept, fromThreadMessageLike, generateErrorMessageId, generateId, getAutoStatus, getFileDataURL, getThreadData, getThreadMessageText, getThreadState, hasUpcomingMessage, httpUrlPattern, isAutoStatus, isCreateAttachment, isErrorMessageId, isJSONValue, isRecord, parseDataUrl, resolveToolApprovalResponse, shouldContinue, stableStringifyToolArgs, symbolInnerMessage, toMessagePartStatus, trackToolArgsKeyOrder, updateStatusReducer };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssistantRuntime } from "../runtime/api/assistant-runtime.js";
|
|
2
|
-
import { AssistantClient } from "@assistant-ui/store";
|
|
3
2
|
import { ComponentType, FC, PropsWithChildren } from "react";
|
|
3
|
+
import { AssistantClient } from "@assistant-ui/store";
|
|
4
4
|
//#region src/react/AssistantProvider.d.ts
|
|
5
5
|
declare const getRenderComponent: (runtime: AssistantRuntime) => ComponentType | undefined;
|
|
6
6
|
type AssistantProviderBaseProps = PropsWithChildren<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantProvider.d.ts","names":[],"sources":["../../src/react/AssistantProvider.tsx"],"mappings":";;;;cAWa,qBAAsB,SAAS,qBAEnB;KAGb,6BAA6B;EACvC,SAAS;EACT,MAAM;;
|
|
1
|
+
{"version":3,"file":"AssistantProvider.d.ts","names":[],"sources":["../../src/react/AssistantProvider.tsx"],"mappings":";;;;cAWa,qBAAsB,SAAS,qBAEnB;KAGb,6BAA6B;EACvC,SAAS;EACT,MAAM;;cAuBK,uBAAuB,GAAG"}
|
|
@@ -1,24 +1,50 @@
|
|
|
1
1
|
import { RuntimeAdapter } from "./RuntimeAdapter.js";
|
|
2
|
-
import {
|
|
2
|
+
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
3
|
import { memo } from "@assistant-ui/tap/react-shim";
|
|
4
|
+
import { AuiProvider, useAui } from "@assistant-ui/store";
|
|
4
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
//#region src/react/AssistantProvider.tsx
|
|
6
7
|
const getRenderComponent = (runtime) => {
|
|
7
8
|
return runtime._core?.RenderComponent;
|
|
8
9
|
};
|
|
9
|
-
const
|
|
10
|
+
const AssistantProviderInner = ({ runtime, children }) => {
|
|
10
11
|
"use no memo";
|
|
11
|
-
const aui = useAui({ threads: RuntimeAdapter(runtime) }
|
|
12
|
+
const aui = useAui({ threads: RuntimeAdapter(runtime) });
|
|
12
13
|
const RenderComponent = getRenderComponent(runtime);
|
|
13
|
-
|
|
14
|
+
return /* @__PURE__ */ jsxs(AuiProvider, {
|
|
14
15
|
value: aui,
|
|
15
16
|
children: [RenderComponent && /* @__PURE__ */ jsx(RenderComponent, {}), children]
|
|
16
17
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
};
|
|
19
|
+
const AssistantProviderBase = memo((t0) => {
|
|
20
|
+
const $ = c(6);
|
|
21
|
+
const { runtime, aui: t1, children } = t0;
|
|
22
|
+
const aui = t1 === void 0 ? null : t1;
|
|
23
|
+
let t2;
|
|
24
|
+
if ($[0] !== children || $[1] !== runtime) {
|
|
25
|
+
t2 = /* @__PURE__ */ jsx(AssistantProviderInner, {
|
|
26
|
+
runtime,
|
|
27
|
+
children
|
|
28
|
+
});
|
|
29
|
+
$[0] = children;
|
|
30
|
+
$[1] = runtime;
|
|
31
|
+
$[2] = t2;
|
|
32
|
+
} else t2 = $[2];
|
|
33
|
+
const inner = t2;
|
|
34
|
+
let t3;
|
|
35
|
+
if ($[3] !== aui || $[4] !== inner) {
|
|
36
|
+
t3 = aui ? /* @__PURE__ */ jsx(AuiProvider, {
|
|
37
|
+
value: aui,
|
|
38
|
+
children: inner
|
|
39
|
+
}) : /* @__PURE__ */ jsx(AuiProvider, {
|
|
40
|
+
value: null,
|
|
41
|
+
children: inner
|
|
42
|
+
});
|
|
43
|
+
$[3] = aui;
|
|
44
|
+
$[4] = inner;
|
|
45
|
+
$[5] = t3;
|
|
46
|
+
} else t3 = $[5];
|
|
47
|
+
return t3;
|
|
22
48
|
});
|
|
23
49
|
//#endregion
|
|
24
50
|
export { AssistantProviderBase, getRenderComponent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssistantProvider.js","names":["memo","ComponentType","FC","PropsWithChildren","useAui","AuiProvider","AssistantClient","AssistantRuntime","AssistantRuntimeCore","RuntimeAdapter","getRenderComponent","runtime","_core","RenderComponent","AssistantProviderBaseProps","aui","AssistantProviderBase","
|
|
1
|
+
{"version":3,"file":"AssistantProvider.js","names":["memo","ComponentType","FC","PropsWithChildren","useAui","AuiProvider","AssistantClient","AssistantRuntime","AssistantRuntimeCore","RuntimeAdapter","getRenderComponent","runtime","_core","RenderComponent","AssistantProviderBaseProps","aui","AssistantProviderInner","children","threads","AssistantProviderBase","t0","$","_c","t1","undefined","t2","inner","t3"],"sources":["../../src/react/AssistantProvider.tsx"],"sourcesContent":["import {\n memo,\n type ComponentType,\n type FC,\n type PropsWithChildren,\n} from \"react\";\nimport { useAui, AuiProvider, type AssistantClient } from \"@assistant-ui/store\";\nimport type { AssistantRuntime } from \"../runtime/api/assistant-runtime\";\nimport type { AssistantRuntimeCore } from \"../runtime/interfaces/assistant-runtime-core\";\nimport { RuntimeAdapter } from \"./RuntimeAdapter\";\n\nexport const getRenderComponent = (runtime: AssistantRuntime) => {\n return (runtime as { _core?: AssistantRuntimeCore })._core\n ?.RenderComponent as ComponentType | undefined;\n};\n\nexport type AssistantProviderBaseProps = PropsWithChildren<{\n runtime: AssistantRuntime;\n aui?: AssistantClient | null;\n}>;\n\nconst AssistantProviderInner: FC<\n PropsWithChildren<{ runtime: AssistantRuntime }>\n> = ({ runtime, children }) => {\n // The runtime has a stable identity but mutates in place: its options are\n // pushed in by an unconditional effect inside <RenderComponent />, so that\n // element must be re-created every commit for React to re-render it and\n // re-run the effect. React Compiler caches <RenderComponent /> on the\n // stable RenderComponent type, which silences the effect and stops option\n // changes (e.g. unstable_enableMessageQueue) from reaching the runtime.\n \"use no memo\";\n const aui = useAui({ threads: RuntimeAdapter(runtime) });\n const RenderComponent = getRenderComponent(runtime);\n return (\n <AuiProvider value={aui}>\n {RenderComponent && <RenderComponent />}\n {children}\n </AuiProvider>\n );\n};\n\nexport const AssistantProviderBase: FC<AssistantProviderBaseProps> = memo(\n ({ runtime, aui = null, children }) => {\n const inner = (\n <AssistantProviderInner runtime={runtime}>\n {children}\n </AssistantProviderInner>\n );\n return aui ? (\n <AuiProvider value={aui}>{inner}</AuiProvider>\n ) : (\n <AuiProvider value={null}>{inner}</AuiProvider>\n );\n },\n);\n"],"mappings":";;;;;;AAWA,MAAaU,sBAAsBC,YAA8B;CAC/D,OAAQA,QAA6CC,OACjDC;AACN;AAOA,MAAMG,0BAED,EAAEL,SAASM,eAAe;CAO7B;CACA,MAAMF,MAAMX,OAAO,EAAEc,SAAST,eAAeE,OAAO,EAAE,CAAC;CACvD,MAAME,kBAAkBH,mBAAmBC,OAAO;CAClD,OACE,qBAAC,aAAD;EAAa,OAAOI;EAApB,UAAA,CACGF,mBAAmB,oBAAC,iBAAD,CAAgB,CAAA,GACnCI,QACU;;AAEjB;AAEA,MAAaE,wBAAwDnB,MACnEoB,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAX,SAAAI,KAAAQ,IAAAN,aAAAG;CAAW,MAAAL,MAAAQ,OAAAC,KAAAA,IAAA,OAAAD;CAAU,IAAAE;CAAA,IAAAJ,EAAA,OAAAJ,YAAAI,EAAA,OAAAV,SAAA;EAElBc,KAAA,oBAAC,wBAAD;GAAiCd;GAC9BM;EADoB,CAAA;EAEEI,EAAA,KAAAJ;EAAAI,EAAA,KAAAV;EAAAU,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAH3B,MAAAK,QACED;CAGA,IAAAE;CAAA,IAAAN,EAAA,OAAAN,OAAAM,EAAA,OAAAK,OAAA;EACKC,KAAAZ,MACL,oBAAC,aAAD;GAAoBA,OAAAA;GAAMW,UAAAA;EAAd,CAAA,IAEZ,oBAAC,aAAD;GAAoB,OAAA;GAAOA,UAAAA;EAAf,CAAA;EACbL,EAAA,KAAAN;EAAAM,EAAA,KAAAK;EAAAL,EAAA,KAAAM;CAAA,OAAAA,KAAAN,EAAA;CAAA,OAJMM;AAIN,CAEL"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssistantRuntime } from "../runtime/api/assistant-runtime.js";
|
|
2
|
-
import { AssistantClient } from "@assistant-ui/store";
|
|
3
2
|
import { ReactNode } from "react";
|
|
3
|
+
import { AssistantClient } from "@assistant-ui/store";
|
|
4
4
|
//#region src/react/AssistantRuntimeProvider.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Mounts an `AssistantRuntime` into the React tree.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssistantProviderBase } from "./AssistantProvider.js";
|
|
2
|
-
import { memo } from "@assistant-ui/tap/react-shim";
|
|
3
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { memo } from "@assistant-ui/tap/react-shim";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
//#region src/react/AssistantRuntimeProvider.tsx
|
|
6
6
|
/**
|
|
@@ -2,9 +2,9 @@ import { ThreadListClient } from "../store/runtime-clients/thread-list-runtime-c
|
|
|
2
2
|
import { baseRuntimeAdapterTransformScopes } from "../store/clients/runtime-adapter.js";
|
|
3
3
|
import { DataRenderers } from "./client/DataRenderers.js";
|
|
4
4
|
import { Tools } from "./client/Tools.js";
|
|
5
|
-
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store";
|
|
6
|
-
import { useEffect } from "@assistant-ui/tap/react-shim";
|
|
7
5
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
6
|
+
import { useEffect } from "@assistant-ui/tap/react-shim";
|
|
7
|
+
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store";
|
|
8
8
|
import { resource, useResource } from "@assistant-ui/tap";
|
|
9
9
|
//#region src/react/RuntimeAdapter.ts
|
|
10
10
|
const useRuntimeAdapter = (runtime) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalStorageThreadListAdapter.d.ts","names":[],"sources":["../../../src/react/adapters/LocalStorageThreadListAdapter.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"LocalStorageThreadListAdapter.d.ts","names":[],"sources":["../../../src/react/adapters/LocalStorageThreadListAdapter.tsx"],"mappings":";;;;;;KA0BY;EACV,QAAQ,cAAc;EACtB,QAAQ,aAAa,gBAAgB;EACrC,WAAW,cAAc;;KAkCtB;EACH,SAAS;EACT;EACA,iBAAiB;;KAGd;EACH;EACA;EACA;EACA;EACA,SAAS;;cAwIE,4BACX,uBACC;cAoCU,+BACX,uBACC;cA0HU,4BACX,SAAS,+BACR"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { RuntimeAdapterProvider } from "../runtimes/RuntimeAdapterProvider.js";
|
|
2
2
|
import { createAssistantStream } from "assistant-stream";
|
|
3
|
+
import { useEffect, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
3
4
|
import { useAui } from "@assistant-ui/store";
|
|
4
|
-
import "@assistant-ui/tap/react-shim";
|
|
5
|
-
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
6
5
|
import { jsx } from "react/jsx-runtime";
|
|
7
6
|
//#region src/react/adapters/LocalStorageThreadListAdapter.tsx
|
|
8
7
|
var KeyedMutationQueue = class {
|
|
@@ -144,15 +143,18 @@ const parseStoredMessageRepository = (raw) => {
|
|
|
144
143
|
};
|
|
145
144
|
var AsyncStorageHistoryAdapter = class {
|
|
146
145
|
storage;
|
|
147
|
-
|
|
146
|
+
getAui;
|
|
148
147
|
prefix;
|
|
149
148
|
mutationQueue;
|
|
150
|
-
constructor(storage,
|
|
149
|
+
constructor(storage, getAui, prefix, mutationQueue) {
|
|
151
150
|
this.storage = storage;
|
|
152
|
-
this.
|
|
151
|
+
this.getAui = getAui;
|
|
153
152
|
this.prefix = prefix;
|
|
154
153
|
this.mutationQueue = mutationQueue;
|
|
155
154
|
}
|
|
155
|
+
get aui() {
|
|
156
|
+
return this.getAui();
|
|
157
|
+
}
|
|
156
158
|
_messagesKey(remoteId) {
|
|
157
159
|
return `${this.prefix}messages:${remoteId}`;
|
|
158
160
|
}
|
|
@@ -177,35 +179,17 @@ var AsyncStorageHistoryAdapter = class {
|
|
|
177
179
|
}
|
|
178
180
|
};
|
|
179
181
|
const createHistoryProvider = (storage, prefix, mutationQueue) => {
|
|
180
|
-
const Provider = (
|
|
181
|
-
const $ = c(7);
|
|
182
|
-
const { children } = t0;
|
|
182
|
+
const Provider = ({ children }) => {
|
|
183
183
|
const aui = useAui();
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
t2 = { history };
|
|
194
|
-
$[2] = history;
|
|
195
|
-
$[3] = t2;
|
|
196
|
-
} else t2 = $[3];
|
|
197
|
-
const adapters = t2;
|
|
198
|
-
let t3;
|
|
199
|
-
if ($[4] !== adapters || $[5] !== children) {
|
|
200
|
-
t3 = /* @__PURE__ */ jsx(RuntimeAdapterProvider, {
|
|
201
|
-
adapters,
|
|
202
|
-
children
|
|
203
|
-
});
|
|
204
|
-
$[4] = adapters;
|
|
205
|
-
$[5] = children;
|
|
206
|
-
$[6] = t3;
|
|
207
|
-
} else t3 = $[6];
|
|
208
|
-
return t3;
|
|
184
|
+
const auiRef = useRef(aui);
|
|
185
|
+
useEffect(() => {
|
|
186
|
+
auiRef.current = aui;
|
|
187
|
+
});
|
|
188
|
+
const [history] = useState(() => new AsyncStorageHistoryAdapter(storage, () => auiRef.current, prefix, mutationQueue));
|
|
189
|
+
return /* @__PURE__ */ jsx(RuntimeAdapterProvider, {
|
|
190
|
+
adapters: useMemo(() => ({ history }), [history]),
|
|
191
|
+
children
|
|
192
|
+
});
|
|
209
193
|
};
|
|
210
194
|
return Provider;
|
|
211
195
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalStorageThreadListAdapter.js","names":["AssistantStream","createAssistantStream","FC","PropsWithChildren","useMemo","useAui","RemoteThreadInitializeResponse","RemoteThreadListAdapter","RemoteThreadListResponse","RemoteThreadMetadata","ThreadHistoryAdapter","ThreadMessage","RunConfig","ExportedMessageRepository","ExportedMessageRepositoryItem","RuntimeAdapterProvider","TitleGenerationAdapter","AsyncStorageLike","getItem","key","Promise","setItem","value","removeItem","KeyedMutationQueue","tails","Map","run","mutation","T","previous","get","result","then","tail","undefined","set","delete","mutationQueues","WeakMap","getMutationQueue","storage","queue","LocalStorageAdapterOptions","prefix","titleGenerator","StoredThreadMetadata","remoteId","externalId","status","title","custom","Record","StoredSystemMessage","Extract","role","StoredUserMessage","StoredAssistantMessage","isRecord","Array","isArray","parseJSON","raw","JSON","parse","parseStoredThread","parseDate","Date","Number","isNaN","getTime","date","isMessageRole","parseStoredThreadMessage","id","content","createdAt","metadata","type","submittedFeedback","submittedFeedbackType","unstable_state","unstable_annotations","unstable_data","steps","timing","NonNullable","isOptimistic","attachments","length","parseStoredThreadMetadata","parsed","flatMap","item","thread","parseStoredMessageRepositoryItem","message","parentId","runConfig","parseStoredMessageRepository","messages","candidateMessages","parsedItem","acceptedIds","Set","has","add","headId","some","AsyncStorageHistoryAdapter","aui","ReturnType","mutationQueue","constructor","_messagesKey","load","threadListItem","getState","append","initialize","repo","idx","findIndex","m","push","stringify","createHistoryProvider","Provider","t0","$","_c","children","t1","history","t2","adapters","t3","createLocalStorageAdapter","options","threadsKey","messagesKey","threadId","loadThreadMetadata","saveThreadMetadata","threads","updateThreadMetadata","update","find","adapter","unstable_Provider","list","map","t","unshift","rename","newTitle","updateCustom","archive","unarchive","filtered","filter","fetch","Error","generateTitle","controller","appendText"],"sources":["../../../src/react/adapters/LocalStorageThreadListAdapter.tsx"],"sourcesContent":["import { type AssistantStream, createAssistantStream } from \"assistant-stream\";\nimport { type FC, type PropsWithChildren, useMemo } from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n RemoteThreadListResponse,\n RemoteThreadMetadata,\n ThreadHistoryAdapter,\n ThreadMessage,\n RunConfig,\n} from \"../../index\";\nimport type {\n ExportedMessageRepository,\n ExportedMessageRepositoryItem,\n} from \"../../internal\";\nimport { RuntimeAdapterProvider } from \"../runtimes/RuntimeAdapterProvider\";\nimport type { TitleGenerationAdapter } from \"./TitleGenerationAdapter\";\n\nexport type AsyncStorageLike = {\n getItem(key: string): Promise<string | null>;\n setItem(key: string, value: string): Promise<void>;\n removeItem(key: string): Promise<void>;\n};\n\nclass KeyedMutationQueue {\n private readonly tails = new Map<string, Promise<void>>();\n\n run<T>(key: string, mutation: () => Promise<T>): Promise<T> {\n const previous = this.tails.get(key);\n const result = previous ? previous.then(mutation) : mutation();\n const tail = result.then(\n () => undefined,\n () => undefined,\n );\n\n this.tails.set(key, tail);\n void tail.then(() => {\n if (this.tails.get(key) === tail) this.tails.delete(key);\n });\n\n return result;\n }\n}\n\nconst mutationQueues = new WeakMap<AsyncStorageLike, KeyedMutationQueue>();\n\nconst getMutationQueue = (storage: AsyncStorageLike): KeyedMutationQueue => {\n let queue = mutationQueues.get(storage);\n if (!queue) {\n queue = new KeyedMutationQueue();\n mutationQueues.set(storage, queue);\n }\n return queue;\n};\n\ntype LocalStorageAdapterOptions = {\n storage: AsyncStorageLike;\n prefix?: string | undefined;\n titleGenerator?: TitleGenerationAdapter | undefined;\n};\n\ntype StoredThreadMetadata = {\n remoteId: string;\n externalId?: string;\n status: \"regular\" | \"archived\";\n title?: string;\n custom?: Record<string, unknown> | undefined;\n};\n\ntype StoredSystemMessage = Extract<ThreadMessage, { role: \"system\" }>;\ntype StoredUserMessage = Extract<ThreadMessage, { role: \"user\" }>;\ntype StoredAssistantMessage = Extract<ThreadMessage, { role: \"assistant\" }>;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst parseJSON = (raw: string | null): unknown => {\n if (!raw) return undefined;\n try {\n return JSON.parse(raw) as unknown;\n } catch {\n return undefined;\n }\n};\n\nconst parseStoredThread = (value: unknown): StoredThreadMetadata | null => {\n if (!isRecord(value) || typeof value.remoteId !== \"string\") return null;\n\n const status = value.status ?? \"regular\";\n if (status !== \"regular\" && status !== \"archived\") return null;\n\n return {\n remoteId: value.remoteId,\n status,\n ...(typeof value.externalId === \"string\"\n ? { externalId: value.externalId }\n : undefined),\n ...(typeof value.title === \"string\" ? { title: value.title } : undefined),\n ...(isRecord(value.custom) ? { custom: value.custom } : undefined),\n };\n};\n\nconst parseDate = (value: unknown): Date | null => {\n if (value instanceof Date && !Number.isNaN(value.getTime())) return value;\n if (typeof value !== \"string\" && typeof value !== \"number\") return null;\n\n const date = new Date(value);\n return Number.isNaN(date.getTime()) ? null : date;\n};\n\nconst isMessageRole = (value: unknown): value is ThreadMessage[\"role\"] =>\n value === \"system\" || value === \"user\" || value === \"assistant\";\n\nconst parseStoredThreadMessage = (value: unknown): ThreadMessage | null => {\n if (!isRecord(value) || typeof value.id !== \"string\") return null;\n if (!isMessageRole(value.role)) return null;\n if (!Array.isArray(value.content)) return null;\n\n const createdAt = parseDate(value.createdAt);\n if (!createdAt) return null;\n\n const metadata = value.metadata;\n if (!isRecord(metadata) || !isRecord(metadata.custom)) return null;\n\n if (value.role === \"assistant\") {\n const status = value.status;\n if (!isRecord(status) || typeof status.type !== \"string\") return null;\n\n const submittedFeedback = isRecord(metadata.submittedFeedback)\n ? metadata.submittedFeedback\n : undefined;\n const submittedFeedbackType = submittedFeedback?.type;\n\n return {\n id: value.id,\n role: \"assistant\",\n content: value.content as StoredAssistantMessage[\"content\"],\n status: status as StoredAssistantMessage[\"status\"],\n createdAt,\n metadata: {\n unstable_state: (metadata.unstable_state ??\n null) as StoredAssistantMessage[\"metadata\"][\"unstable_state\"],\n unstable_annotations: Array.isArray(metadata.unstable_annotations)\n ? (metadata.unstable_annotations as StoredAssistantMessage[\"metadata\"][\"unstable_annotations\"])\n : [],\n unstable_data: Array.isArray(metadata.unstable_data)\n ? (metadata.unstable_data as StoredAssistantMessage[\"metadata\"][\"unstable_data\"])\n : [],\n steps: Array.isArray(metadata.steps)\n ? (metadata.steps as StoredAssistantMessage[\"metadata\"][\"steps\"])\n : [],\n ...(submittedFeedbackType === \"positive\" ||\n submittedFeedbackType === \"negative\"\n ? {\n submittedFeedback: {\n type: submittedFeedbackType,\n },\n }\n : undefined),\n ...(metadata.timing !== undefined\n ? {\n timing: metadata.timing as NonNullable<\n StoredAssistantMessage[\"metadata\"][\"timing\"]\n >,\n }\n : undefined),\n ...(metadata.isOptimistic === true\n ? { isOptimistic: true }\n : undefined),\n custom: metadata.custom,\n },\n };\n }\n\n if (value.role === \"user\") {\n return {\n id: value.id,\n role: \"user\",\n content: value.content as StoredUserMessage[\"content\"],\n attachments: Array.isArray(value.attachments)\n ? (value.attachments as StoredUserMessage[\"attachments\"])\n : [],\n createdAt,\n metadata: {\n custom: metadata.custom,\n },\n };\n }\n\n if (value.content.length !== 1) return null;\n\n return {\n id: value.id,\n role: \"system\",\n content: [value.content[0] as StoredSystemMessage[\"content\"][0]],\n createdAt,\n metadata: {\n custom: metadata.custom,\n },\n };\n};\n\nexport const parseStoredThreadMetadata = (\n raw: string | null,\n): StoredThreadMetadata[] => {\n const parsed = parseJSON(raw);\n if (!Array.isArray(parsed)) return [];\n\n return parsed.flatMap((item) => {\n const thread = parseStoredThread(item);\n return thread ? [thread] : [];\n });\n};\n\nconst parseStoredMessageRepositoryItem = (\n value: unknown,\n): ExportedMessageRepositoryItem | null => {\n if (!isRecord(value)) return null;\n\n const message = parseStoredThreadMessage(value.message);\n if (!message) return null;\n\n const parentId = value.parentId;\n if (\n parentId !== undefined &&\n parentId !== null &&\n typeof parentId !== \"string\"\n ) {\n return null;\n }\n\n return {\n message,\n parentId: parentId ?? null,\n ...(isRecord(value.runConfig)\n ? { runConfig: value.runConfig as RunConfig }\n : undefined),\n };\n};\n\nexport const parseStoredMessageRepository = (\n raw: string | null,\n): ExportedMessageRepository => {\n const parsed = parseJSON(raw);\n if (!isRecord(parsed) || !Array.isArray(parsed.messages)) {\n return { messages: [] };\n }\n\n const candidateMessages = parsed.messages.flatMap((item) => {\n const parsedItem = parseStoredMessageRepositoryItem(item);\n return parsedItem ? [parsedItem] : [];\n });\n\n const acceptedIds = new Set<string>();\n const messages = candidateMessages.flatMap((item) => {\n if (acceptedIds.has(item.message.id)) return [];\n if (item.parentId !== null && !acceptedIds.has(item.parentId)) return [];\n\n acceptedIds.add(item.message.id);\n return [item];\n });\n\n const headId =\n parsed.headId === null ||\n (typeof parsed.headId === \"string\" &&\n messages.some((item) => item.message.id === parsed.headId))\n ? parsed.headId\n : undefined;\n\n return {\n ...(headId !== undefined ? { headId } : undefined),\n messages,\n };\n};\n\nclass AsyncStorageHistoryAdapter implements ThreadHistoryAdapter {\n private storage: AsyncStorageLike;\n private aui: ReturnType<typeof useAui>;\n private prefix: string;\n private mutationQueue: KeyedMutationQueue;\n\n constructor(\n storage: AsyncStorageLike,\n aui: ReturnType<typeof useAui>,\n prefix: string,\n mutationQueue: KeyedMutationQueue,\n ) {\n this.storage = storage;\n this.aui = aui;\n this.prefix = prefix;\n this.mutationQueue = mutationQueue;\n }\n\n private _messagesKey(remoteId: string) {\n return `${this.prefix}messages:${remoteId}`;\n }\n\n async load(): Promise<ExportedMessageRepository> {\n const remoteId = this.aui.threadListItem.getState().remoteId;\n if (!remoteId) return { messages: [] };\n\n const raw = await this.storage.getItem(this._messagesKey(remoteId));\n return parseStoredMessageRepository(raw);\n }\n\n async append(item: ExportedMessageRepositoryItem): Promise<void> {\n const { remoteId } = await this.aui.threadListItem.initialize();\n\n const key = this._messagesKey(remoteId);\n await this.mutationQueue.run(key, async () => {\n const raw = await this.storage.getItem(key);\n const repo = parseStoredMessageRepository(raw);\n\n const idx = repo.messages.findIndex(\n (m) => m.message.id === item.message.id,\n );\n if (idx >= 0) {\n repo.messages[idx] = item;\n } else {\n repo.messages.push(item);\n }\n repo.headId = item.message.id;\n\n await this.storage.setItem(key, JSON.stringify(repo));\n });\n }\n}\n\nconst createHistoryProvider = (\n storage: AsyncStorageLike,\n prefix: string,\n mutationQueue: KeyedMutationQueue,\n): FC<PropsWithChildren> => {\n const Provider: FC<PropsWithChildren> = ({ children }) => {\n const aui = useAui();\n const history = useMemo(\n () => new AsyncStorageHistoryAdapter(storage, aui, prefix, mutationQueue),\n [aui],\n );\n const adapters = useMemo(() => ({ history }), [history]);\n\n return (\n <RuntimeAdapterProvider adapters={adapters}>\n {children}\n </RuntimeAdapterProvider>\n );\n };\n return Provider;\n};\n\nexport const createLocalStorageAdapter = (\n options: LocalStorageAdapterOptions,\n): RemoteThreadListAdapter => {\n const { storage, prefix = \"@assistant-ui:\", titleGenerator } = options;\n\n const threadsKey = `${prefix}threads`;\n const messagesKey = (threadId: string) => `${prefix}messages:${threadId}`;\n const mutationQueue = getMutationQueue(storage);\n\n const loadThreadMetadata = async (): Promise<StoredThreadMetadata[]> => {\n const raw = await storage.getItem(threadsKey);\n return parseStoredThreadMetadata(raw);\n };\n\n const saveThreadMetadata = async (\n threads: StoredThreadMetadata[],\n ): Promise<void> => {\n await storage.setItem(threadsKey, JSON.stringify(threads));\n };\n\n const updateThreadMetadata = async (\n remoteId: string,\n update: (thread: StoredThreadMetadata) => void,\n ): Promise<void> => {\n await mutationQueue.run(threadsKey, async () => {\n const threads = await loadThreadMetadata();\n const thread = threads.find((item) => item.remoteId === remoteId);\n if (thread) {\n update(thread);\n await saveThreadMetadata(threads);\n }\n });\n };\n\n const adapter: RemoteThreadListAdapter = {\n unstable_Provider: createHistoryProvider(storage, prefix, mutationQueue),\n\n async list(): Promise<RemoteThreadListResponse> {\n const threads = await loadThreadMetadata();\n return {\n threads: threads.map((t) => ({\n remoteId: t.remoteId,\n externalId: t.externalId,\n status: t.status,\n title: t.title,\n custom: t.custom,\n })),\n };\n },\n\n async initialize(\n threadId: string,\n ): Promise<RemoteThreadInitializeResponse> {\n const remoteId = threadId;\n return mutationQueue.run(threadsKey, async () => {\n const threads = await loadThreadMetadata();\n\n // Only add if not already present\n if (!threads.some((t) => t.remoteId === remoteId)) {\n threads.unshift({\n remoteId,\n status: \"regular\",\n });\n await saveThreadMetadata(threads);\n }\n\n return { remoteId, externalId: undefined };\n });\n },\n\n async rename(remoteId: string, newTitle: string): Promise<void> {\n await updateThreadMetadata(remoteId, (thread) => {\n thread.title = newTitle;\n });\n },\n\n async updateCustom(\n remoteId: string,\n custom: Record<string, unknown> | undefined,\n ): Promise<void> {\n await updateThreadMetadata(remoteId, (thread) => {\n thread.custom = custom;\n });\n },\n\n async archive(remoteId: string): Promise<void> {\n await updateThreadMetadata(remoteId, (thread) => {\n thread.status = \"archived\";\n });\n },\n\n async unarchive(remoteId: string): Promise<void> {\n await updateThreadMetadata(remoteId, (thread) => {\n thread.status = \"regular\";\n });\n },\n\n async delete(remoteId: string): Promise<void> {\n await mutationQueue.run(threadsKey, async () => {\n const threads = await loadThreadMetadata();\n const filtered = threads.filter((t) => t.remoteId !== remoteId);\n await saveThreadMetadata(filtered);\n });\n const key = messagesKey(remoteId);\n await mutationQueue.run(key, () => storage.removeItem(key));\n },\n\n async fetch(threadId: string): Promise<RemoteThreadMetadata> {\n const threads = await loadThreadMetadata();\n const thread = threads.find((t) => t.remoteId === threadId);\n if (!thread)\n throw new Error(\n `Stored thread \"${threadId}\" not found while fetching thread metadata.`,\n );\n return {\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n custom: thread.custom,\n };\n },\n\n async generateTitle(\n remoteId: string,\n messages: readonly ThreadMessage[],\n ): Promise<AssistantStream> {\n if (titleGenerator) {\n const title = await titleGenerator.generateTitle(messages);\n\n // Update the stored title\n await updateThreadMetadata(remoteId, (thread) => {\n thread.title = title;\n });\n\n // Return a stream with a single text part\n return createAssistantStream((controller) => {\n controller.appendText(title);\n });\n }\n\n // No title generator — return empty stream\n return createAssistantStream(() => {});\n },\n };\n\n return adapter;\n};\n"],"mappings":";;;;;;;AAyBA,IAAMwB,qBAAN,MAAyB;CACvB,wBAAyB,IAAIE,IAA2B;CAExDC,IAAOR,KAAaS,UAAwC;EAC1D,MAAME,WAAW,KAAKL,MAAMM,IAAIZ,GAAG;EACnC,MAAMa,SAASF,WAAWA,SAASG,KAAKL,QAAQ,IAAIA,SAAS;EAC7D,MAAMM,OAAOF,OAAOC,WACZE,KAAAA,SACAA,KAAAA,CACR;EAEA,KAAKV,MAAMW,IAAIjB,KAAKe,IAAI;EACxB,KAAUD,WAAW;GACnB,IAAI,KAAKR,MAAMM,IAAIZ,GAAG,MAAMe,MAAM,KAAKT,MAAMY,OAAOlB,GAAG;EACzD,CAAC;EAED,OAAOa;CACT;AACF;AAEA,MAAMM,iCAAiB,IAAIC,QAA8C;AAEzE,MAAMC,oBAAoBC,YAAkD;CAC1E,IAAIC,QAAQJ,eAAeP,IAAIU,OAAO;CACtC,IAAI,CAACC,OAAO;EACVA,QAAQ,IAAIlB,mBAAmB;EAC/Bc,eAAeF,IAAIK,SAASC,KAAK;CACnC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/C;IACjBC,YAAY8C,OAAO9C;IACnBC,QAAQ6C,OAAO7C;IACfC,OAAO4C,OAAO5C;IACdC,QAAQ2C,OAAO3C;GACjB;EACF;EAEA,MAAMgH,cACJpH,UACAqD,UAC0B;GAC1B,IAAIvD,gBAAgB;IAClB,MAAMK,QAAQ,MAAML,eAAesH,cAAc/D,QAAQ;IAGzD,MAAM6C,qBAAqBlG,WAAW+C,WAAW;KAC/CA,OAAO5C,QAAQA;IACjB,CAAC;IAGD,OAAOjD,uBAAuBmK,eAAe;KAC3CA,WAAWC,WAAWnH,KAAK;IAC7B,CAAC;GACH;GAGA,OAAOjD,4BAA4B,CAAC,CAAC;EACvC;CAGKmJ;AACT"}
|
|
1
|
+
{"version":3,"file":"LocalStorageThreadListAdapter.js","names":["AssistantStream","createAssistantStream","FC","PropsWithChildren","useEffect","useMemo","useRef","useState","useAui","RemoteThreadInitializeResponse","RemoteThreadListAdapter","RemoteThreadListResponse","RemoteThreadMetadata","ThreadHistoryAdapter","ThreadMessage","RunConfig","ExportedMessageRepository","ExportedMessageRepositoryItem","RuntimeAdapterProvider","TitleGenerationAdapter","AsyncStorageLike","getItem","key","Promise","setItem","value","removeItem","KeyedMutationQueue","tails","Map","run","mutation","T","previous","get","result","then","tail","undefined","set","delete","mutationQueues","WeakMap","getMutationQueue","storage","queue","LocalStorageAdapterOptions","prefix","titleGenerator","StoredThreadMetadata","remoteId","externalId","status","title","custom","Record","StoredSystemMessage","Extract","role","StoredUserMessage","StoredAssistantMessage","isRecord","Array","isArray","parseJSON","raw","JSON","parse","parseStoredThread","parseDate","Date","Number","isNaN","getTime","date","isMessageRole","parseStoredThreadMessage","id","content","createdAt","metadata","type","submittedFeedback","submittedFeedbackType","unstable_state","unstable_annotations","unstable_data","steps","timing","NonNullable","isOptimistic","attachments","length","parseStoredThreadMetadata","parsed","flatMap","item","thread","parseStoredMessageRepositoryItem","message","parentId","runConfig","parseStoredMessageRepository","messages","candidateMessages","parsedItem","acceptedIds","Set","has","add","headId","some","AsyncStorageHistoryAdapter","getAui","ReturnType","mutationQueue","constructor","aui","_messagesKey","load","threadListItem","getState","append","initialize","repo","idx","findIndex","m","push","stringify","createHistoryProvider","Provider","children","auiRef","current","history","adapters","createLocalStorageAdapter","options","threadsKey","messagesKey","threadId","loadThreadMetadata","saveThreadMetadata","threads","updateThreadMetadata","update","find","adapter","unstable_Provider","list","map","t","unshift","rename","newTitle","updateCustom","archive","unarchive","filtered","filter","fetch","Error","generateTitle","controller","appendText"],"sources":["../../../src/react/adapters/LocalStorageThreadListAdapter.tsx"],"sourcesContent":["import { type AssistantStream, createAssistantStream } from \"assistant-stream\";\nimport {\n type FC,\n type PropsWithChildren,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { useAui } from \"@assistant-ui/store\";\nimport type {\n RemoteThreadInitializeResponse,\n RemoteThreadListAdapter,\n RemoteThreadListResponse,\n RemoteThreadMetadata,\n ThreadHistoryAdapter,\n ThreadMessage,\n RunConfig,\n} from \"../../index\";\nimport type {\n ExportedMessageRepository,\n ExportedMessageRepositoryItem,\n} from \"../../internal\";\nimport { RuntimeAdapterProvider } from \"../runtimes/RuntimeAdapterProvider\";\nimport type { TitleGenerationAdapter } from \"./TitleGenerationAdapter\";\n\nexport type AsyncStorageLike = {\n getItem(key: string): Promise<string | null>;\n setItem(key: string, value: string): Promise<void>;\n removeItem(key: string): Promise<void>;\n};\n\nclass KeyedMutationQueue {\n private readonly tails = new Map<string, Promise<void>>();\n\n run<T>(key: string, mutation: () => Promise<T>): Promise<T> {\n const previous = this.tails.get(key);\n const result = previous ? previous.then(mutation) : mutation();\n const tail = result.then(\n () => undefined,\n () => undefined,\n );\n\n this.tails.set(key, tail);\n void tail.then(() => {\n if (this.tails.get(key) === tail) this.tails.delete(key);\n });\n\n return result;\n }\n}\n\nconst mutationQueues = new WeakMap<AsyncStorageLike, KeyedMutationQueue>();\n\nconst getMutationQueue = (storage: AsyncStorageLike): KeyedMutationQueue => {\n let queue = mutationQueues.get(storage);\n if (!queue) {\n queue = new KeyedMutationQueue();\n mutationQueues.set(storage, queue);\n }\n return queue;\n};\n\ntype LocalStorageAdapterOptions = {\n storage: AsyncStorageLike;\n prefix?: string | undefined;\n titleGenerator?: TitleGenerationAdapter | undefined;\n};\n\ntype StoredThreadMetadata = {\n remoteId: string;\n externalId?: string;\n status: \"regular\" | \"archived\";\n title?: string;\n custom?: Record<string, unknown> | undefined;\n};\n\ntype StoredSystemMessage = Extract<ThreadMessage, { role: \"system\" }>;\ntype StoredUserMessage = Extract<ThreadMessage, { role: \"user\" }>;\ntype StoredAssistantMessage = Extract<ThreadMessage, { role: \"assistant\" }>;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nconst parseJSON = (raw: string | null): unknown => {\n if (!raw) return undefined;\n try {\n return JSON.parse(raw) as unknown;\n } catch {\n return undefined;\n }\n};\n\nconst parseStoredThread = (value: unknown): StoredThreadMetadata | null => {\n if (!isRecord(value) || typeof value.remoteId !== \"string\") return null;\n\n const status = value.status ?? \"regular\";\n if (status !== \"regular\" && status !== \"archived\") return null;\n\n return {\n remoteId: value.remoteId,\n status,\n ...(typeof value.externalId === \"string\"\n ? { externalId: value.externalId }\n : undefined),\n ...(typeof value.title === \"string\" ? { title: value.title } : undefined),\n ...(isRecord(value.custom) ? { custom: value.custom } : undefined),\n };\n};\n\nconst parseDate = (value: unknown): Date | null => {\n if (value instanceof Date && !Number.isNaN(value.getTime())) return value;\n if (typeof value !== \"string\" && typeof value !== \"number\") return null;\n\n const date = new Date(value);\n return Number.isNaN(date.getTime()) ? null : date;\n};\n\nconst isMessageRole = (value: unknown): value is ThreadMessage[\"role\"] =>\n value === \"system\" || value === \"user\" || value === \"assistant\";\n\nconst parseStoredThreadMessage = (value: unknown): ThreadMessage | null => {\n if (!isRecord(value) || typeof value.id !== \"string\") return null;\n if (!isMessageRole(value.role)) return null;\n if (!Array.isArray(value.content)) return null;\n\n const createdAt = parseDate(value.createdAt);\n if (!createdAt) return null;\n\n const metadata = value.metadata;\n if (!isRecord(metadata) || !isRecord(metadata.custom)) return null;\n\n if (value.role === \"assistant\") {\n const status = value.status;\n if (!isRecord(status) || typeof status.type !== \"string\") return null;\n\n const submittedFeedback = isRecord(metadata.submittedFeedback)\n ? metadata.submittedFeedback\n : undefined;\n const submittedFeedbackType = submittedFeedback?.type;\n\n return {\n id: value.id,\n role: \"assistant\",\n content: value.content as StoredAssistantMessage[\"content\"],\n status: status as StoredAssistantMessage[\"status\"],\n createdAt,\n metadata: {\n unstable_state: (metadata.unstable_state ??\n null) as StoredAssistantMessage[\"metadata\"][\"unstable_state\"],\n unstable_annotations: Array.isArray(metadata.unstable_annotations)\n ? (metadata.unstable_annotations as StoredAssistantMessage[\"metadata\"][\"unstable_annotations\"])\n : [],\n unstable_data: Array.isArray(metadata.unstable_data)\n ? (metadata.unstable_data as StoredAssistantMessage[\"metadata\"][\"unstable_data\"])\n : [],\n steps: Array.isArray(metadata.steps)\n ? (metadata.steps as StoredAssistantMessage[\"metadata\"][\"steps\"])\n : [],\n ...(submittedFeedbackType === \"positive\" ||\n submittedFeedbackType === \"negative\"\n ? {\n submittedFeedback: {\n type: submittedFeedbackType,\n },\n }\n : undefined),\n ...(metadata.timing !== undefined\n ? {\n timing: metadata.timing as NonNullable<\n StoredAssistantMessage[\"metadata\"][\"timing\"]\n >,\n }\n : undefined),\n ...(metadata.isOptimistic === true\n ? { isOptimistic: true }\n : undefined),\n custom: metadata.custom,\n },\n };\n }\n\n if (value.role === \"user\") {\n return {\n id: value.id,\n role: \"user\",\n content: value.content as StoredUserMessage[\"content\"],\n attachments: Array.isArray(value.attachments)\n ? (value.attachments as StoredUserMessage[\"attachments\"])\n : [],\n createdAt,\n metadata: {\n custom: metadata.custom,\n },\n };\n }\n\n if (value.content.length !== 1) return null;\n\n return {\n id: value.id,\n role: \"system\",\n content: [value.content[0] as StoredSystemMessage[\"content\"][0]],\n createdAt,\n metadata: {\n custom: metadata.custom,\n },\n };\n};\n\nexport const parseStoredThreadMetadata = (\n raw: string | null,\n): StoredThreadMetadata[] => {\n const parsed = parseJSON(raw);\n if (!Array.isArray(parsed)) return [];\n\n return parsed.flatMap((item) => {\n const thread = parseStoredThread(item);\n return thread ? [thread] : [];\n });\n};\n\nconst parseStoredMessageRepositoryItem = (\n value: unknown,\n): ExportedMessageRepositoryItem | null => {\n if (!isRecord(value)) return null;\n\n const message = parseStoredThreadMessage(value.message);\n if (!message) return null;\n\n const parentId = value.parentId;\n if (\n parentId !== undefined &&\n parentId !== null &&\n typeof parentId !== \"string\"\n ) {\n return null;\n }\n\n return {\n message,\n parentId: parentId ?? null,\n ...(isRecord(value.runConfig)\n ? { runConfig: value.runConfig as RunConfig }\n : undefined),\n };\n};\n\nexport const parseStoredMessageRepository = (\n raw: string | null,\n): ExportedMessageRepository => {\n const parsed = parseJSON(raw);\n if (!isRecord(parsed) || !Array.isArray(parsed.messages)) {\n return { messages: [] };\n }\n\n const candidateMessages = parsed.messages.flatMap((item) => {\n const parsedItem = parseStoredMessageRepositoryItem(item);\n return parsedItem ? [parsedItem] : [];\n });\n\n const acceptedIds = new Set<string>();\n const messages = candidateMessages.flatMap((item) => {\n if (acceptedIds.has(item.message.id)) return [];\n if (item.parentId !== null && !acceptedIds.has(item.parentId)) return [];\n\n acceptedIds.add(item.message.id);\n return [item];\n });\n\n const headId =\n parsed.headId === null ||\n (typeof parsed.headId === \"string\" &&\n messages.some((item) => item.message.id === parsed.headId))\n ? parsed.headId\n : undefined;\n\n return {\n ...(headId !== undefined ? { headId } : undefined),\n messages,\n };\n};\n\nclass AsyncStorageHistoryAdapter implements ThreadHistoryAdapter {\n private storage: AsyncStorageLike;\n private getAui: () => ReturnType<typeof useAui>;\n private prefix: string;\n private mutationQueue: KeyedMutationQueue;\n\n constructor(\n storage: AsyncStorageLike,\n getAui: () => ReturnType<typeof useAui>,\n prefix: string,\n mutationQueue: KeyedMutationQueue,\n ) {\n this.storage = storage;\n this.getAui = getAui;\n this.prefix = prefix;\n this.mutationQueue = mutationQueue;\n }\n\n private get aui(): ReturnType<typeof useAui> {\n return this.getAui();\n }\n\n private _messagesKey(remoteId: string) {\n return `${this.prefix}messages:${remoteId}`;\n }\n\n async load(): Promise<ExportedMessageRepository> {\n const remoteId = this.aui.threadListItem.getState().remoteId;\n if (!remoteId) return { messages: [] };\n\n const raw = await this.storage.getItem(this._messagesKey(remoteId));\n return parseStoredMessageRepository(raw);\n }\n\n async append(item: ExportedMessageRepositoryItem): Promise<void> {\n const { remoteId } = await this.aui.threadListItem.initialize();\n\n const key = this._messagesKey(remoteId);\n await this.mutationQueue.run(key, async () => {\n const raw = await this.storage.getItem(key);\n const repo = parseStoredMessageRepository(raw);\n\n const idx = repo.messages.findIndex(\n (m) => m.message.id === item.message.id,\n );\n if (idx >= 0) {\n repo.messages[idx] = item;\n } else {\n repo.messages.push(item);\n }\n repo.headId = item.message.id;\n\n await this.storage.setItem(key, JSON.stringify(repo));\n });\n }\n}\n\nconst createHistoryProvider = (\n storage: AsyncStorageLike,\n prefix: string,\n mutationQueue: KeyedMutationQueue,\n): FC<PropsWithChildren> => {\n const Provider: FC<PropsWithChildren> = ({ children }) => {\n const aui = useAui();\n // Not useEffectEvent: history adapter methods run during render (SSR load).\n const auiRef = useRef(aui);\n useEffect(() => {\n auiRef.current = aui;\n });\n const [history] = useState(\n () =>\n new AsyncStorageHistoryAdapter(\n storage,\n () => auiRef.current,\n prefix,\n mutationQueue,\n ),\n );\n const adapters = useMemo(() => ({ history }), [history]);\n\n return (\n <RuntimeAdapterProvider adapters={adapters}>\n {children}\n </RuntimeAdapterProvider>\n );\n };\n return Provider;\n};\n\nexport const createLocalStorageAdapter = (\n options: LocalStorageAdapterOptions,\n): RemoteThreadListAdapter => {\n const { storage, prefix = \"@assistant-ui:\", titleGenerator } = options;\n\n const threadsKey = `${prefix}threads`;\n const messagesKey = (threadId: string) => `${prefix}messages:${threadId}`;\n const mutationQueue = getMutationQueue(storage);\n\n const loadThreadMetadata = async (): Promise<StoredThreadMetadata[]> => {\n const raw = await storage.getItem(threadsKey);\n return parseStoredThreadMetadata(raw);\n };\n\n const saveThreadMetadata = async (\n threads: StoredThreadMetadata[],\n ): Promise<void> => {\n await storage.setItem(threadsKey, JSON.stringify(threads));\n };\n\n const updateThreadMetadata = async (\n remoteId: string,\n update: (thread: StoredThreadMetadata) => void,\n ): Promise<void> => {\n await mutationQueue.run(threadsKey, async () => {\n const threads = await loadThreadMetadata();\n const thread = threads.find((item) => item.remoteId === remoteId);\n if (thread) {\n update(thread);\n await saveThreadMetadata(threads);\n }\n });\n };\n\n const adapter: RemoteThreadListAdapter = {\n unstable_Provider: createHistoryProvider(storage, prefix, mutationQueue),\n\n async list(): Promise<RemoteThreadListResponse> {\n const threads = await loadThreadMetadata();\n return {\n threads: threads.map((t) => ({\n remoteId: t.remoteId,\n externalId: t.externalId,\n status: t.status,\n title: t.title,\n custom: t.custom,\n })),\n };\n },\n\n async initialize(\n threadId: string,\n ): Promise<RemoteThreadInitializeResponse> {\n const remoteId = threadId;\n return mutationQueue.run(threadsKey, async () => {\n const threads = await loadThreadMetadata();\n\n // Only add if not already present\n if (!threads.some((t) => t.remoteId === remoteId)) {\n threads.unshift({\n remoteId,\n status: \"regular\",\n });\n await saveThreadMetadata(threads);\n }\n\n return { remoteId, externalId: undefined };\n });\n },\n\n async rename(remoteId: string, newTitle: string): Promise<void> {\n await updateThreadMetadata(remoteId, (thread) => {\n thread.title = newTitle;\n });\n },\n\n async updateCustom(\n remoteId: string,\n custom: Record<string, unknown> | undefined,\n ): Promise<void> {\n await updateThreadMetadata(remoteId, (thread) => {\n thread.custom = custom;\n });\n },\n\n async archive(remoteId: string): Promise<void> {\n await updateThreadMetadata(remoteId, (thread) => {\n thread.status = \"archived\";\n });\n },\n\n async unarchive(remoteId: string): Promise<void> {\n await updateThreadMetadata(remoteId, (thread) => {\n thread.status = \"regular\";\n });\n },\n\n async delete(remoteId: string): Promise<void> {\n await mutationQueue.run(threadsKey, async () => {\n const threads = await loadThreadMetadata();\n const filtered = threads.filter((t) => t.remoteId !== remoteId);\n await saveThreadMetadata(filtered);\n });\n const key = messagesKey(remoteId);\n await mutationQueue.run(key, () => storage.removeItem(key));\n },\n\n async fetch(threadId: string): Promise<RemoteThreadMetadata> {\n const threads = await loadThreadMetadata();\n const thread = threads.find((t) => t.remoteId === threadId);\n if (!thread)\n throw new Error(\n `Stored thread \"${threadId}\" not found while fetching thread metadata.`,\n );\n return {\n remoteId: thread.remoteId,\n externalId: thread.externalId,\n status: thread.status,\n title: thread.title,\n custom: thread.custom,\n };\n },\n\n async generateTitle(\n remoteId: string,\n messages: readonly ThreadMessage[],\n ): Promise<AssistantStream> {\n if (titleGenerator) {\n const title = await titleGenerator.generateTitle(messages);\n\n // Update the stored title\n await updateThreadMetadata(remoteId, (thread) => {\n thread.title = title;\n });\n\n // Return a stream with a single text part\n return createAssistantStream((controller) => {\n controller.appendText(title);\n });\n }\n\n // No title generator — return empty stream\n return createAssistantStream(() => {});\n },\n };\n\n return adapter;\n};\n"],"mappings":";;;;;;AAgCA,IAAM2B,qBAAN,MAAyB;CACvB,wBAAyB,IAAIE,IAA2B;CAExDC,IAAOR,KAAaS,UAAwC;EAC1D,MAAME,WAAW,KAAKL,MAAMM,IAAIZ,GAAG;EACnC,MAAMa,SAASF,WAAWA,SAASG,KAAKL,QAAQ,IAAIA,SAAS;EAC7D,MAAMM,OAAOF,OAAOC,WACZE,KAAAA,SACAA,KAAAA,CACR;EAEA,KAAKV,MAAMW,IAAIjB,KAAKe,IAAI;EACxB,KAAUD,WAAW;GACnB,IAAI,KAAKR,MAAMM,IAAIZ,GAAG,MAAMe,MAAM,KAAKT,MAAMY,OAAOlB,GAAG;EACzD,CAAC;EAED,OAAOa;CACT;AACF;AAEA,MAAMM,iCAAiB,IAAIC,QAA8C;AAEzE,MAAMC,oBAAoBC,YAAkD;CAC1E,IAAIC,QAAQJ,eAAeP,IAAIU,OAAO;C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AQ;IAGzD,MAAM0C,qBAAqB/F,WAAW+C,WAAW;KAC/CA,OAAO5C,QAAQA;IACjB,CAAC;IAGD,OAAOpD,uBAAuBmK,eAAe;KAC3CA,WAAWC,WAAWhH,KAAK;IAC7B,CAAC;GACH;GAGA,OAAOpD,4BAA4B,CAAC,CAAC;EACvC;CAGKmJ;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useState } from "@assistant-ui/tap/react-shim";
|
|
2
1
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
2
|
+
import { useState } from "@assistant-ui/tap/react-shim";
|
|
3
3
|
import { resource } from "@assistant-ui/tap";
|
|
4
4
|
//#region src/react/client/DataRenderers.ts
|
|
5
5
|
/**
|
|
@@ -2,8 +2,8 @@ import { findModelKnownState, interactableToolName } from "../../model-context/i
|
|
|
2
2
|
import { ModelContext } from "../../store/clients/model-context-client.js";
|
|
3
3
|
import { buildInteractableModelContext } from "./interactable-model-context.js";
|
|
4
4
|
import { toJSONSchema, toPartialJSONSchema } from "assistant-stream";
|
|
5
|
-
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store";
|
|
6
5
|
import { useCallback, useEffect, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
6
|
+
import { attachTransformScopes, useAssistantClientRef } from "@assistant-ui/store";
|
|
7
7
|
import { resource } from "@assistant-ui/tap";
|
|
8
8
|
//#region src/react/client/Interactables.ts
|
|
9
9
|
const PERSISTENCE_DEBOUNCE_MS = 500;
|