@assistant-ui/core 0.3.10 → 0.3.12
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 +5 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +6 -5
- package/dist/internal.js +5 -4
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js +17 -10
- package/dist/react/runtimes/cloud/useCloudThreadListAdapter.js.map +1 -1
- package/dist/react/runtimes/external-message-converter.d.ts.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +15 -2
- package/dist/react/runtimes/external-message-converter.js.map +1 -1
- package/dist/runtime/api/message-runtime.d.ts +2 -3
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +2 -16
- 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/store/clients/external-thread.d.ts +54 -0
- package/dist/store/clients/external-thread.d.ts.map +1 -0
- package/dist/store/clients/external-thread.js +1354 -0
- package/dist/store/clients/external-thread.js.map +1 -0
- package/dist/store/clients/single-thread-list.d.ts +9 -0
- package/dist/store/clients/single-thread-list.d.ts.map +1 -0
- package/dist/store/clients/single-thread-list.js +171 -0
- package/dist/store/clients/single-thread-list.js.map +1 -0
- package/dist/store/index.d.ts +3 -1
- package/dist/store/index.js +3 -1
- package/dist/types/augmentations.d.ts +33 -0
- package/dist/types/augmentations.d.ts.map +1 -0
- package/dist/types/augmentations.js +0 -0
- package/dist/utils/normalizePartStatus.d.ts +3 -2
- package/dist/utils/normalizePartStatus.d.ts.map +1 -1
- package/dist/utils/normalizePartStatus.js +15 -1
- package/dist/utils/normalizePartStatus.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +6 -0
- package/src/internal.ts +1 -1
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.test.tsx +49 -0
- package/src/react/runtimes/cloud/useCloudThreadListAdapter.tsx +11 -2
- package/src/react/runtimes/external-message-converter.test.ts +71 -0
- package/src/react/runtimes/external-message-converter.test.tsx +9 -0
- package/src/react/runtimes/external-message-converter.ts +35 -2
- package/src/runtime/api/message-runtime.test.ts +1 -1
- package/src/runtime/api/message-runtime.ts +2 -35
- package/src/store/clients/external-thread.ts +1152 -0
- package/src/store/clients/single-thread-list.ts +115 -0
- package/src/store/index.ts +6 -0
- package/src/tests/external-thread-attachments.test.tsx +370 -0
- package/src/tests/external-thread-branches.test.tsx +157 -0
- package/src/tests/external-thread-feedback.test.tsx +204 -0
- package/src/tests/external-thread-parity.test.tsx +494 -0
- package/src/tests/external-thread-speech.test.tsx +328 -0
- package/src/types/augmentations.ts +33 -0
- package/src/utils/normalizePartStatus.ts +27 -0
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { AddToolResultOptions, RespondToToolApprovalOptions, ResumeRunConfig, Re
|
|
|
20
20
|
import { CreateSuggestionAdapterOptions, SuggestionAdapter, SuggestionAdapterGenerateOptions, createSuggestionAdapter } from "./adapters/suggestion.js";
|
|
21
21
|
import { Unstable_TriggerAdapter } from "./adapters/trigger.js";
|
|
22
22
|
import { GenericThreadHistoryAdapter, MessageFormatAdapter, MessageFormatItem, MessageFormatRepository, MessageStorageEntry, ThreadHistoryAdapter } from "./adapters/thread-history.js";
|
|
23
|
+
import { Assistant, UserCommands, UserExternalState } from "./types/augmentations.js";
|
|
23
24
|
import { tool } from "./model-context/tool.js";
|
|
24
25
|
import { Unstable_InteractableSnapshotEntry, Unstable_InteractableVersion, unstable_formatInteractableSnapshot, unstable_getInteractableSnapshots, unstable_getInteractableVersions } from "./model-context/interactable-composer-metadata.js";
|
|
25
26
|
import { ToolExecutionStatus } from "./runtimes/tool-invocations/ToolInvocationTracker.js";
|
|
@@ -34,22 +35,22 @@ import { ThreadListItemCoreState, ThreadListItemStatus, ThreadListRuntimeCore }
|
|
|
34
35
|
import { AssistantRuntimeCore } from "./runtime/interfaces/assistant-runtime-core.js";
|
|
35
36
|
import { generateId } from "./utils/id.js";
|
|
36
37
|
import { ThreadListItemState } from "./runtime/api/bindings.js";
|
|
38
|
+
import { ThreadListItemEventCallback, ThreadListItemEventPayload, ThreadListItemEventType, ThreadListItemRuntime } from "./runtime/api/thread-list-item-runtime.js";
|
|
39
|
+
import { ThreadListRuntime, ThreadListState } from "./runtime/api/thread-list-runtime.js";
|
|
37
40
|
import { AttachmentRuntime, AttachmentState } from "./runtime/api/attachment-runtime.js";
|
|
38
41
|
import { ComposerRuntime, ComposerState, EditComposerRuntime, EditComposerState, ThreadComposerRuntime, ThreadComposerState } from "./runtime/api/composer-runtime.js";
|
|
39
42
|
import { MessagePartRuntime, MessagePartState } from "./runtime/api/message-part-runtime.js";
|
|
40
43
|
import { MessageRuntime, MessageState } from "./runtime/api/message-runtime.js";
|
|
41
|
-
import { ThreadListItemEventCallback, ThreadListItemEventPayload, ThreadListItemEventType, ThreadListItemRuntime } from "./runtime/api/thread-list-item-runtime.js";
|
|
42
|
-
import { ThreadListRuntime, ThreadListState } from "./runtime/api/thread-list-runtime.js";
|
|
43
44
|
import { bindExternalStoreMessage, getExternalStoreMessages } from "./runtime/utils/external-store-message.js";
|
|
44
45
|
import { LocalRuntimeOptionsBase } from "./runtimes/local/local-runtime-options.js";
|
|
45
46
|
import { ExternalStoreAdapter, ExternalStoreBranchChange, ExternalStoreMessageConverter, ExternalStoreThreadData, ExternalStoreThreadListAdapter } from "./runtimes/external-store/external-store-adapter.js";
|
|
46
47
|
import { StreamingTimingAccessors, StreamingTimingOptions, StreamingTimingState, stepStreamingTiming } from "./runtime/utils/streaming-timing.js";
|
|
48
|
+
import { ExternalThreadBranchAdapter } from "./runtime/branch/external-thread-branch-adapter.js";
|
|
47
49
|
import { RemoteThreadInitializeResponse, RemoteThreadListAdapter, RemoteThreadListOptions, RemoteThreadListPageOptions, RemoteThreadListProviderComponent, RemoteThreadListResponse, RemoteThreadMetadata } from "./runtimes/remote-thread-list/types.js";
|
|
48
50
|
import { CreateAppendMessage, CreateResumeRunConfig, CreateStartRunConfig, ThreadRuntime, ThreadState } from "./runtime/api/thread-runtime.js";
|
|
49
51
|
import { AssistantRuntime } from "./runtime/api/assistant-runtime.js";
|
|
50
52
|
import { ExternalStoreSharedOptions, pickExternalStoreSharedOptions } from "./runtimes/external-store/external-store-shared-options.js";
|
|
51
|
-
import { ExternalThreadBranchAdapter } from "./runtime/branch/external-thread-branch-adapter.js";
|
|
52
53
|
import { MessageQueueController, MessageQueueDriver, createMessageQueue } from "./runtime/queue/message-queue.js";
|
|
53
54
|
import { InMemoryThreadListAdapter } from "./runtimes/remote-thread-list/adapter/in-memory.js";
|
|
54
55
|
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 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 QueuePlacement, type QuoteInfo, type RealtimeVoiceAdapter, type ReasoningMessagePart, type RemoteThreadInitializeResponse, type RemoteThreadListAdapter, type RemoteThreadListOptions, type RemoteThreadListPageOptions, type RemoteThreadListProviderComponent, 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 };
|
|
56
|
+
export { type AddToolResultOptions, type AppendMessage, type Assistant, 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 QueuePlacement, type QuoteInfo, type RealtimeVoiceAdapter, type ReasoningMessagePart, type RemoteThreadInitializeResponse, type RemoteThreadListAdapter, type RemoteThreadListOptions, type RemoteThreadListPageOptions, type RemoteThreadListProviderComponent, 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 UserCommands, type UserExternalState, 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","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","QueuePlacement","ExternalThreadBranchAdapter","createMessageQueue","MessageQueueDriver","MessageQueueController","RemoteThreadListAdapter","RemoteThreadListOptions","RemoteThreadListProviderComponent","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 {\n ExternalThreadQueueAdapter,\n QueuePlacement,\n} 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 RemoteThreadListProviderComponent,\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","Assistant","UserCommands","UserExternalState","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","QueuePlacement","ExternalThreadBranchAdapter","createMessageQueue","MessageQueueDriver","MessageQueueController","RemoteThreadListAdapter","RemoteThreadListOptions","RemoteThreadListProviderComponent","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 {\n Assistant,\n UserCommands,\n UserExternalState,\n} from \"./types/augmentations\";\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 {\n ExternalThreadQueueAdapter,\n QueuePlacement,\n} 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 RemoteThreadListProviderComponent,\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,11 +7,7 @@ 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 {
|
|
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
|
+
import { toMessagePartStatus } from "./utils/normalizePartStatus.js";
|
|
15
11
|
import { resolveToolApprovalResponse } from "./runtime/utils/resolveToolApprovalResponse.js";
|
|
16
12
|
import { CompositeContextProvider } from "./utils/composite-context-provider.js";
|
|
17
13
|
import { stableStringifyToolArgs, trackToolArgsKeyOrder } from "./utils/json/stable-stringify-tool-args.js";
|
|
@@ -19,6 +15,7 @@ import { isJSONValue, isRecord } from "./utils/json/is-json.js";
|
|
|
19
15
|
import { dataUrlMediaType, httpUrlPattern, isParsableUrl, parseDataUrl } from "./utils/data-url.js";
|
|
20
16
|
import { detectImageMediaType } from "./utils/image-media-type.js";
|
|
21
17
|
import { resolveFileMediaType, resolveImageMediaType, toMediaWireUrl } from "./utils/wire-media.js";
|
|
18
|
+
import { ComposerRuntimeCoreBinding, EditComposerRuntimeCoreBinding, MessageStateBinding, ThreadComposerRuntimeCoreBinding } from "./runtime/api/bindings.js";
|
|
22
19
|
import { BaseAssistantRuntimeCore } from "./runtime/base/base-assistant-runtime-core.js";
|
|
23
20
|
import { BaseComposerRuntimeCore } from "./runtime/base/base-composer-runtime-core.js";
|
|
24
21
|
import { DefaultThreadComposerRuntimeCore } from "./runtime/base/default-thread-composer-runtime-core.js";
|
|
@@ -26,6 +23,10 @@ import { DefaultEditComposerRuntimeCore } from "./runtime/base/default-edit-comp
|
|
|
26
23
|
import { BaseThreadRuntimeCore } from "./runtime/base/base-thread-runtime-core.js";
|
|
27
24
|
import { ThreadListItemRuntimeImpl, ThreadListItemStateBinding } from "./runtime/api/thread-list-item-runtime.js";
|
|
28
25
|
import { ThreadListRuntimeCoreBinding, ThreadListRuntimeImpl } from "./runtime/api/thread-list-runtime.js";
|
|
26
|
+
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./runtime/api/attachment-runtime.js";
|
|
27
|
+
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./runtime/api/composer-runtime.js";
|
|
28
|
+
import { MessagePartRuntimeImpl } from "./runtime/api/message-part-runtime.js";
|
|
29
|
+
import { MessageRuntimeImpl } from "./runtime/api/message-runtime.js";
|
|
29
30
|
import { symbolInnerMessage } from "./runtime/utils/external-store-message.js";
|
|
30
31
|
import { getAutoStatus, isAutoStatus } from "./runtime/utils/auto-status.js";
|
|
31
32
|
import "./runtime/internal.js";
|
package/dist/internal.js
CHANGED
|
@@ -9,11 +9,8 @@ import { symbolInnerMessage } from "./runtime/utils/external-store-message.js";
|
|
|
9
9
|
import { getAutoStatus, isAutoStatus } from "./runtime/utils/auto-status.js";
|
|
10
10
|
import { ExportedMessageRepository, MessageRepository } from "./runtime/utils/message-repository.js";
|
|
11
11
|
import { BaseSubject, BaseSubscribable, EventSubscriptionSubject, LazyMemoizeSubject, NestedSubscriptionSubject, SKIP_UPDATE, ShallowMemoizeSubject } from "./subscribable/subscribable.js";
|
|
12
|
-
import {
|
|
13
|
-
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./runtime/api/composer-runtime.js";
|
|
12
|
+
import { toMessagePartStatus } from "./utils/normalizePartStatus.js";
|
|
14
13
|
import { resolveToolApprovalResponse } from "./runtime/utils/resolveToolApprovalResponse.js";
|
|
15
|
-
import { MessagePartRuntimeImpl } from "./runtime/api/message-part-runtime.js";
|
|
16
|
-
import { MessageRuntimeImpl, toMessagePartStatus } from "./runtime/api/message-runtime.js";
|
|
17
14
|
import { CompositeContextProvider } from "./utils/composite-context-provider.js";
|
|
18
15
|
import { isCreateAttachment } from "./types/attachment.js";
|
|
19
16
|
import { stableStringifyToolArgs, trackToolArgsKeyOrder } from "./utils/json/stable-stringify-tool-args.js";
|
|
@@ -25,6 +22,10 @@ import { DefaultThreadComposerRuntimeCore } from "./runtime/base/default-thread-
|
|
|
25
22
|
import { DefaultEditComposerRuntimeCore } from "./runtime/base/default-edit-composer-runtime-core.js";
|
|
26
23
|
import { BaseThreadRuntimeCore } from "./runtime/base/base-thread-runtime-core.js";
|
|
27
24
|
import { ThreadListItemRuntimeImpl } from "./runtime/api/thread-list-item-runtime.js";
|
|
25
|
+
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./runtime/api/attachment-runtime.js";
|
|
26
|
+
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./runtime/api/composer-runtime.js";
|
|
27
|
+
import { MessagePartRuntimeImpl } from "./runtime/api/message-part-runtime.js";
|
|
28
|
+
import { MessageRuntimeImpl } from "./runtime/api/message-runtime.js";
|
|
28
29
|
import { ThreadRuntimeImpl, getThreadState } from "./runtime/api/thread-runtime.js";
|
|
29
30
|
import { ThreadListRuntimeImpl } from "./runtime/api/thread-list-runtime.js";
|
|
30
31
|
import { AssistantRuntimeImpl } from "./runtime/api/assistant-runtime.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCloudThreadListAdapter.d.ts","names":[],"sources":["../../../../src/react/runtimes/cloud/useCloudThreadListAdapter.tsx"],"mappings":";;;KAkBK;EACH;;KAGG;EACH,QAAQ;EAER,gBAAgB,QAAQ;EACxB,WAAW,qBAAqB;;
|
|
1
|
+
{"version":3,"file":"useCloudThreadListAdapter.d.ts","names":[],"sources":["../../../../src/react/runtimes/cloud/useCloudThreadListAdapter.tsx"],"mappings":";;;KAkBK;EACH;;KAGG;EACH,QAAQ;EAER,gBAAgB,QAAQ;EACxB,WAAW,qBAAqB;;cAerB,4BACX,SAAS,kCACR"}
|
|
@@ -13,6 +13,7 @@ const autoCloud = baseUrl ? new AssistantCloud({
|
|
|
13
13
|
baseUrl,
|
|
14
14
|
anonymous: true
|
|
15
15
|
}) : void 0;
|
|
16
|
+
const CLOUD_THREAD_PAGE_SIZE = 20;
|
|
16
17
|
const useCloudThreadListAdapter = (adapter) => {
|
|
17
18
|
const adapterRef = useRef(adapter);
|
|
18
19
|
useEffect(() => {
|
|
@@ -47,16 +48,22 @@ const useCloudThreadListAdapter = (adapter) => {
|
|
|
47
48
|
return inMemory;
|
|
48
49
|
}
|
|
49
50
|
return {
|
|
50
|
-
list: async () => {
|
|
51
|
-
const { threads } = await cloud.threads.list(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
list: async ({ after } = {}) => {
|
|
52
|
+
const { threads } = await cloud.threads.list({
|
|
53
|
+
limit: CLOUD_THREAD_PAGE_SIZE,
|
|
54
|
+
...after ? { after } : {}
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
threads: threads.map((t) => ({
|
|
58
|
+
status: t.is_archived ? "archived" : "regular",
|
|
59
|
+
remoteId: t.id,
|
|
60
|
+
title: t.title,
|
|
61
|
+
lastMessageAt: t.last_message_at ? new Date(t.last_message_at) : void 0,
|
|
62
|
+
externalId: t.external_id ?? void 0,
|
|
63
|
+
custom: toCustom(t.metadata)
|
|
64
|
+
})),
|
|
65
|
+
nextCursor: threads.length === CLOUD_THREAD_PAGE_SIZE ? threads.at(-1)?.id : void 0
|
|
66
|
+
};
|
|
60
67
|
},
|
|
61
68
|
initialize: async () => {
|
|
62
69
|
const t_0 = await (adapterRef.current.create?.() ?? Promise.resolve());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCloudThreadListAdapter.js","names":["process","env","Record","FC","PropsWithChildren","useCallback","useEffect","useMemo","useRef","AssistantCloud","RemoteThreadListAdapter","InMemoryThreadListAdapter","useAssistantCloudThreadHistoryAdapter","RuntimeAdapterProvider","CloudFileAttachmentAdapter","isRecord","ThreadData","externalId","CloudThreadListAdapterOptions","cloud","create","Promise","delete","threadId","toCustom","value","undefined","baseUrl","NEXT_PUBLIC_ASSISTANT_BASE_URL","autoCloud","anonymous","useCloudThreadListAdapter","adapter","adapterRef","current","unstable_Provider","Provider","children","history","cloudInstance","attachments","adapters","ref","inMemory","initialize","result","remoteId","list","threads","map","t","status","is_archived","id","title","lastMessageAt","last_message_at","Date","external_id","custom","metadata","createTask","resolve","thread_id","rename","newTitle","update","updateCustom","archive","unarchive","generateTitle","messages","filteredMessages","msg","content","filter","part","type","runs","stream","assistant_id","fetch","thread","get"],"sources":["../../../../src/react/runtimes/cloud/useCloudThreadListAdapter.tsx"],"sourcesContent":["declare const process: { env: Record<string, string | undefined> };\n\nimport {\n type FC,\n type PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { AssistantCloud } from \"assistant-cloud\";\nimport type { RemoteThreadListAdapter } from \"../../../runtimes/remote-thread-list/types\";\nimport { InMemoryThreadListAdapter } from \"../../../runtimes/remote-thread-list/adapter/in-memory\";\nimport { useAssistantCloudThreadHistoryAdapter } from \"./AssistantCloudThreadHistoryAdapter\";\nimport { RuntimeAdapterProvider } from \"../RuntimeAdapterProvider\";\nimport { CloudFileAttachmentAdapter } from \"./CloudFileAttachmentAdapter\";\nimport { isRecord } from \"../../../utils/json/is-json\";\n\ntype ThreadData = {\n externalId: string | undefined;\n};\n\ntype CloudThreadListAdapterOptions = {\n cloud?: AssistantCloud | undefined;\n\n create?: (() => Promise<ThreadData>) | undefined;\n delete?: ((threadId: string) => Promise<void>) | undefined;\n};\n\nconst toCustom = (value: unknown): Record<string, unknown> | undefined =>\n isRecord(value) ? value : undefined;\n\nconst baseUrl =\n typeof process !== \"undefined\" &&\n process?.env?.NEXT_PUBLIC_ASSISTANT_BASE_URL;\nconst autoCloud = baseUrl\n ? new AssistantCloud({ baseUrl, anonymous: true })\n : undefined;\n\nexport const useCloudThreadListAdapter = (\n adapter: CloudThreadListAdapterOptions,\n): RemoteThreadListAdapter => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const unstable_Provider = useCallback<FC<PropsWithChildren>>(\n function Provider({ children }) {\n const history = useAssistantCloudThreadHistoryAdapter({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n });\n const cloudInstance = adapterRef.current.cloud ?? autoCloud!;\n const attachments = useMemo(\n () => new CloudFileAttachmentAdapter(cloudInstance),\n [cloudInstance],\n );\n\n const adapters = useMemo(\n () => ({\n history,\n attachments,\n }),\n [history, attachments],\n );\n\n return (\n <RuntimeAdapterProvider adapters={adapters}>\n {children}\n </RuntimeAdapterProvider>\n );\n },\n [],\n );\n\n const cloud = adapter.cloud ?? autoCloud;\n return useMemo<RemoteThreadListAdapter>(() => {\n if (!cloud) {\n const ref = adapterRef;\n const inMemory = new InMemoryThreadListAdapter();\n inMemory.initialize = async (threadId: string) => {\n const result = await ref.current.create?.();\n return { remoteId: threadId, externalId: result?.externalId };\n };\n return inMemory;\n }\n\n return {\n list: async () => {\n const { threads } = await cloud.threads.list();\n return {\n threads: threads.map((t) => ({\n status: t.is_archived ? \"archived\" : \"regular\",\n remoteId: t.id,\n title: t.title,\n lastMessageAt: t.last_message_at\n ? new Date(t.last_message_at)\n : undefined,\n externalId: t.external_id ?? undefined,\n custom: toCustom(t.metadata),\n })),\n };\n },\n\n initialize: async () => {\n const createTask = adapterRef.current.create?.() ?? Promise.resolve();\n const t = await createTask;\n const external_id = t ? t.externalId : undefined;\n const { thread_id: remoteId } = await cloud.threads.create({\n last_message_at: new Date(),\n external_id,\n });\n\n return { externalId: external_id, remoteId: remoteId };\n },\n\n rename: async (threadId, newTitle) => {\n return cloud.threads.update(threadId, { title: newTitle });\n },\n updateCustom: async (threadId, custom) => {\n return cloud.threads.update(threadId, { metadata: custom ?? null });\n },\n archive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapterRef.current.delete?.(threadId);\n return cloud.threads.delete(threadId);\n },\n\n generateTitle: async (threadId, messages) => {\n // Filter messages to only include content types the title generator understands\n // (reasoning, source, etc. are not needed for title generation)\n // TODO serialize these to a more efficient format\n const filteredMessages = messages.map((msg) => ({\n ...msg,\n content: msg.content.filter(\n (part) => part.type === \"text\" || part.type === \"tool-call\",\n ),\n }));\n\n return cloud.runs.stream({\n thread_id: threadId,\n assistant_id: \"system/thread_title\",\n messages: filteredMessages,\n });\n },\n\n fetch: async (threadId: string) => {\n const thread = await cloud.threads.get(threadId);\n return {\n status: thread.is_archived ? \"archived\" : \"regular\",\n remoteId: thread.id,\n title: thread.title,\n lastMessageAt: thread.last_message_at\n ? new Date(thread.last_message_at)\n : undefined,\n externalId: thread.external_id ?? undefined,\n custom: toCustom(thread.metadata),\n };\n },\n\n unstable_Provider,\n };\n }, [cloud, unstable_Provider]);\n};\n"],"mappings":";;;;;;;;;AA6BA,MAAMwB,YAAYC,UAChBV,SAASU,KAAK,IAAIA,QAAQC,KAAAA;AAE5B,MAAMC,UACJ,OAAO3B,YAAY,eACnBA,SAASC,KAAK2B;AAChB,MAAMC,YAAYF,UACd,IAAIlB,eAAe;CAAEkB;CAASG,WAAW;AAAK,CAAC,IAC/CJ,KAAAA;AAEJ,MAAaK,6BACXC,YAC4B;CAC5B,MAAMC,aAAazB,OAAOwB,OAAO;CACjC1B,gBAAgB;EACd2B,WAAWC,UAAUF;CACvB,GAAG,CAACA,OAAO,CAAC;CAEZ,MAAMG,oBAAoB9B,YACxB,SAAS+B,SAAS,EAAEC,YAAY;EAC9B,MAAMC,UAAU1B,sCAAsC,EACpD,IAAIsB,UAAU;GACZ,OAAOD,WAAWC,QAAQf,SAASU;EACrC,EACF,CAAC;EACD,MAAMU,gBAAgBN,WAAWC,QAAQf,SAASU;EAClD,MAAMW,cAAcjC,cACZ,IAAIO,2BAA2ByB,aAAa,GAClD,CAACA,aAAa,CAChB;EAEA,MAAME,WAAWlC,eACR;GACL+B;GACAE;EACF,IACA,CAACF,SAASE,WAAW,CACvB;EAEA,OACE,oBAAC,wBAAD;GAAkCC;GAC/BJ;EACqB,CAAA;CAE5B,GACA,CAAA,CACF;CAEA,MAAMlB,QAAQa,QAAQb,SAASU;CAC/B,OAAOtB,cAAuC;EAC5C,IAAI,CAACY,OAAO;GACV,MAAMuB,MAAMT;GACZ,MAAMU,WAAW,IAAIhC,0BAA0B;GAC/CgC,SAASC,aAAa,OAAOrB,aAAqB;IAEhD,OAAO;KAAEuB,UAAUvB;KAAUN,aAAY4B,MADpBH,IAAIR,QAAQd,SAAS,E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WAAWC,QAAQZ,SAASC,UAAQ;IAC1C,OAAOJ,MAAM6B,QAAQ1B,OAAOC,UAAQ;GACtC;GAEA+C,eAAe,OAAO/C,YAAUgD,aAAa;IAI3C,MAAMC,mBAAmBD,SAAStB,KAAKwB,SAAS;KAC9C,GAAGA;KACHC,SAASD,IAAIC,QAAQC,QAClBC,SAASA,KAAKC,SAAS,UAAUD,KAAKC,SAAS,WAClD;IACF,EAAE;IAEF,OAAO1D,MAAM2D,KAAKC,OAAO;KACvBhB,WAAWxC;KACXyD,cAAc;KACdT,UAAUC;IACZ,CAAC;GACH;GAEAS,OAAO,OAAO1D,eAAqB;IACjC,MAAM2D,SAAS,MAAM/D,MAAM6B,QAAQmC,IAAI5D,UAAQ;IAC/C,OAAO;KACL4B,QAAQ+B,OAAO9B,cAAc,aAAa;KAC1CN,UAAUoC,OAAO7B;KACjBC,OAAO4B,OAAO5B;KACdC,eAAe2B,OAAO1B,kBAClB,IAAIC,KAAKyB,OAAO1B,eAAe,IAC/B9B,KAAAA;KACJT,YAAYiE,OAAOxB,eAAehC,KAAAA;KAClCiC,QAAQnC,SAAS0D,OAAOtB,QAAQ;IAClC;GACF;GAEAzB;EACF;CACF,GAAG,CAAChB,OAAOgB,iBAAiB,CAAC;AAC/B"}
|
|
1
|
+
{"version":3,"file":"useCloudThreadListAdapter.js","names":["process","env","Record","FC","PropsWithChildren","useCallback","useEffect","useMemo","useRef","AssistantCloud","RemoteThreadListAdapter","InMemoryThreadListAdapter","useAssistantCloudThreadHistoryAdapter","RuntimeAdapterProvider","CloudFileAttachmentAdapter","isRecord","ThreadData","externalId","CloudThreadListAdapterOptions","cloud","create","Promise","delete","threadId","toCustom","value","undefined","baseUrl","NEXT_PUBLIC_ASSISTANT_BASE_URL","autoCloud","anonymous","CLOUD_THREAD_PAGE_SIZE","useCloudThreadListAdapter","adapter","adapterRef","current","unstable_Provider","Provider","children","history","cloudInstance","attachments","adapters","ref","inMemory","initialize","result","remoteId","list","after","threads","limit","map","t","status","is_archived","id","title","lastMessageAt","last_message_at","Date","external_id","custom","metadata","nextCursor","length","at","createTask","resolve","thread_id","rename","newTitle","update","updateCustom","archive","unarchive","generateTitle","messages","filteredMessages","msg","content","filter","part","type","runs","stream","assistant_id","fetch","thread","get"],"sources":["../../../../src/react/runtimes/cloud/useCloudThreadListAdapter.tsx"],"sourcesContent":["declare const process: { env: Record<string, string | undefined> };\n\nimport {\n type FC,\n type PropsWithChildren,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n} from \"react\";\nimport { AssistantCloud } from \"assistant-cloud\";\nimport type { RemoteThreadListAdapter } from \"../../../runtimes/remote-thread-list/types\";\nimport { InMemoryThreadListAdapter } from \"../../../runtimes/remote-thread-list/adapter/in-memory\";\nimport { useAssistantCloudThreadHistoryAdapter } from \"./AssistantCloudThreadHistoryAdapter\";\nimport { RuntimeAdapterProvider } from \"../RuntimeAdapterProvider\";\nimport { CloudFileAttachmentAdapter } from \"./CloudFileAttachmentAdapter\";\nimport { isRecord } from \"../../../utils/json/is-json\";\n\ntype ThreadData = {\n externalId: string | undefined;\n};\n\ntype CloudThreadListAdapterOptions = {\n cloud?: AssistantCloud | undefined;\n\n create?: (() => Promise<ThreadData>) | undefined;\n delete?: ((threadId: string) => Promise<void>) | undefined;\n};\n\nconst toCustom = (value: unknown): Record<string, unknown> | undefined =>\n isRecord(value) ? value : undefined;\n\nconst baseUrl =\n typeof process !== \"undefined\" &&\n process?.env?.NEXT_PUBLIC_ASSISTANT_BASE_URL;\nconst autoCloud = baseUrl\n ? new AssistantCloud({ baseUrl, anonymous: true })\n : undefined;\n\nconst CLOUD_THREAD_PAGE_SIZE = 20;\n\nexport const useCloudThreadListAdapter = (\n adapter: CloudThreadListAdapterOptions,\n): RemoteThreadListAdapter => {\n const adapterRef = useRef(adapter);\n useEffect(() => {\n adapterRef.current = adapter;\n }, [adapter]);\n\n const unstable_Provider = useCallback<FC<PropsWithChildren>>(\n function Provider({ children }) {\n const history = useAssistantCloudThreadHistoryAdapter({\n get current() {\n return adapterRef.current.cloud ?? autoCloud!;\n },\n });\n const cloudInstance = adapterRef.current.cloud ?? autoCloud!;\n const attachments = useMemo(\n () => new CloudFileAttachmentAdapter(cloudInstance),\n [cloudInstance],\n );\n\n const adapters = useMemo(\n () => ({\n history,\n attachments,\n }),\n [history, attachments],\n );\n\n return (\n <RuntimeAdapterProvider adapters={adapters}>\n {children}\n </RuntimeAdapterProvider>\n );\n },\n [],\n );\n\n const cloud = adapter.cloud ?? autoCloud;\n return useMemo<RemoteThreadListAdapter>(() => {\n if (!cloud) {\n const ref = adapterRef;\n const inMemory = new InMemoryThreadListAdapter();\n inMemory.initialize = async (threadId: string) => {\n const result = await ref.current.create?.();\n return { remoteId: threadId, externalId: result?.externalId };\n };\n return inMemory;\n }\n\n return {\n list: async ({ after } = {}) => {\n const { threads } = await cloud.threads.list({\n limit: CLOUD_THREAD_PAGE_SIZE,\n ...(after ? { after } : {}),\n });\n return {\n threads: threads.map((t) => ({\n status: t.is_archived ? \"archived\" : \"regular\",\n remoteId: t.id,\n title: t.title,\n lastMessageAt: t.last_message_at\n ? new Date(t.last_message_at)\n : undefined,\n externalId: t.external_id ?? undefined,\n custom: toCustom(t.metadata),\n })),\n nextCursor:\n threads.length === CLOUD_THREAD_PAGE_SIZE\n ? threads.at(-1)?.id\n : undefined,\n };\n },\n\n initialize: async () => {\n const createTask = adapterRef.current.create?.() ?? Promise.resolve();\n const t = await createTask;\n const external_id = t ? t.externalId : undefined;\n const { thread_id: remoteId } = await cloud.threads.create({\n last_message_at: new Date(),\n external_id,\n });\n\n return { externalId: external_id, remoteId: remoteId };\n },\n\n rename: async (threadId, newTitle) => {\n return cloud.threads.update(threadId, { title: newTitle });\n },\n updateCustom: async (threadId, custom) => {\n return cloud.threads.update(threadId, { metadata: custom ?? null });\n },\n archive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: true });\n },\n unarchive: async (threadId) => {\n return cloud.threads.update(threadId, { is_archived: false });\n },\n delete: async (threadId) => {\n await adapterRef.current.delete?.(threadId);\n return cloud.threads.delete(threadId);\n },\n\n generateTitle: async (threadId, messages) => {\n // Filter messages to only include content types the title generator understands\n // (reasoning, source, etc. are not needed for title generation)\n // TODO serialize these to a more efficient format\n const filteredMessages = messages.map((msg) => ({\n ...msg,\n content: msg.content.filter(\n (part) => part.type === \"text\" || part.type === \"tool-call\",\n ),\n }));\n\n return cloud.runs.stream({\n thread_id: threadId,\n assistant_id: \"system/thread_title\",\n messages: filteredMessages,\n });\n },\n\n fetch: async (threadId: string) => {\n const thread = await cloud.threads.get(threadId);\n return {\n status: thread.is_archived ? \"archived\" : \"regular\",\n remoteId: thread.id,\n title: thread.title,\n lastMessageAt: thread.last_message_at\n ? new Date(thread.last_message_at)\n : undefined,\n externalId: thread.external_id ?? undefined,\n custom: toCustom(thread.metadata),\n };\n },\n\n unstable_Provider,\n };\n }, [cloud, unstable_Provider]);\n};\n"],"mappings":";;;;;;;;;AA6BA,MAAMwB,YAAYC,UAChBV,SAASU,KAAK,IAAIA,QAAQC,KAAAA;AAE5B,MAAMC,UACJ,OAAO3B,YAAY,eACnBA,SAASC,KAAK2B;AAChB,MAAMC,YAAYF,UACd,IAAIlB,eAAe;CAAEkB;CAASG,WAAW;AAAK,CAAC,IAC/CJ,KAAAA;AAEJ,MAAMK,yBAAyB;AAE/B,MAAaC,6BACXC,YAC4B;CAC5B,MAAMC,aAAa1B,OAAOyB,OAAO;CACjC3B,gBAAgB;EACd4B,WAAWC,UAAUF;CACvB,GAAG,CAACA,OAAO,CAAC;CAEZ,MAAMG,oBAAoB/B,YACxB,SAASgC,SAAS,EAAEC,YAAY;EAC9B,MAAMC,UAAU3B,sCAAsC,EACpD,IAAIuB,UAAU;GACZ,OAAOD,WAAWC,QAAQhB,SAASU;EACrC,EACF,CAAC;EACD,MAAMW,gBAAgBN,WAAWC,QAAQhB,SAASU;EAClD,MAAMY,cAAclC,cACZ,IAAIO,2BAA2B0B,aAAa,GAClD,CAACA,aAAa,CA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uE,OAAO3B,eAAenC,KAAAA;KAClCoC,QAAQtC,SAASgE,OAAOzB,QAAQ;IAClC;GACF;GAEA3B;EACF;CACF,GAAG,CAACjB,OAAOiB,iBAAiB,CAAC;AAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-message-converter.d.ts","names":[],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"mappings":";;;;;KAwBY;kBAoBK;OACH,WACP;aACU;eACE,eAAe;;;IAI1B;IACA;IACA;IACA;IACA;IACA;IACA,oBAAoB;;OAGd;aACD,eAAe,eAAe;aAC9B,QAAQ;aACR,gBAAgB,eAAe;;OAG9B,SAAS,MACnB,SAAS,GACT,UAAU,aACP,UAAU;;
|
|
1
|
+
{"version":3,"file":"external-message-converter.d.ts","names":[],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"mappings":";;;;;KAwBY;kBAoBK;OACH,WACP;aACU;eACE,eAAe;;;IAI1B;IACA;IACA;IACA;IACA;IACA;IACA,oBAAoB;;OAGd;aACD,eAAe,eAAe;aAC9B,QAAQ;aACR,gBAAgB,eAAe;;OAG9B,SAAS,MACnB,SAAS,GACT,UAAU,aACP,UAAU;;cAsTJ,0BAA2B,UAAU,SAChD,UAAU,KACV,UAAU,4BAA4B,SAAS,IAC/C,oBACA,UAAU,4BAA4B,aAAQ;cA+CnC,8BAA+B,UAAU,WAAS,UAAA,UAAA,WAAA,cAAA;EAO7D,UAAU,4BAA4B,SAAS;EAC/C,UAAU;EACV;EACA,eAAe;EACf,WAAW,4BAA4B;MACxC"}
|
|
@@ -12,6 +12,19 @@ const isInterruptedToolCall = (c) => {
|
|
|
12
12
|
if (c.type !== "tool-call" || c.result !== void 0) return false;
|
|
13
13
|
return c.interrupt != null || c.approval != null && c.approval.approved === void 0 && c.approval.resolution === void 0;
|
|
14
14
|
};
|
|
15
|
+
const stringifyForError = (value) => {
|
|
16
|
+
let text;
|
|
17
|
+
try {
|
|
18
|
+
text = value instanceof Error ? String(value) : JSON.stringify(value);
|
|
19
|
+
} catch {}
|
|
20
|
+
text ??= String(value);
|
|
21
|
+
return text.length > 200 ? `${text.slice(0, 200)}…` : text;
|
|
22
|
+
};
|
|
23
|
+
const toCallbackOutputs = (output, input) => {
|
|
24
|
+
const outputs = Array.isArray(output) ? output : [output];
|
|
25
|
+
for (const o of outputs) if (!(typeof o === "object" && o !== null && (o.role === "tool" || (o.role === "assistant" || o.role === "user" || o.role === "system") && (typeof o.content === "string" || Array.isArray(o.content))))) throw new Error(`External message converter: the converter callback returned an invalid message (${stringifyForError(o)}) for input ${stringifyForError(input)}. Return an empty array to skip a message.`);
|
|
26
|
+
return outputs;
|
|
27
|
+
};
|
|
15
28
|
const mergeInnerMessages = (existing, incoming) => ({ [symbolInnerMessage]: [...existing[symbolInnerMessage] ?? [], ...incoming[symbolInnerMessage] ?? []] });
|
|
16
29
|
const joinExternalMessages = (messages) => {
|
|
17
30
|
const assistantMessage = {
|
|
@@ -157,7 +170,7 @@ const convertExternalMessages = (messages, callback, isRunning, metadata) => {
|
|
|
157
170
|
const output = callback(message, metadata);
|
|
158
171
|
const result = {
|
|
159
172
|
input: message,
|
|
160
|
-
outputs:
|
|
173
|
+
outputs: toCallbackOutputs(output, message)
|
|
161
174
|
};
|
|
162
175
|
callbackResults.push(result);
|
|
163
176
|
}
|
|
@@ -210,7 +223,7 @@ const useExternalMessageConverter = (t0) => {
|
|
|
210
223
|
const output = state.callback(message, state.metadata);
|
|
211
224
|
result = {
|
|
212
225
|
input: message,
|
|
213
|
-
outputs:
|
|
226
|
+
outputs: toCallbackOutputs(output, message),
|
|
214
227
|
metadata: state.metadata,
|
|
215
228
|
callback: state.callback
|
|
216
229
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-message-converter.js","names":["c","_c","useMemo","useState","ThreadMessageConverter","getExternalStoreMessages","symbolInnerMessage","bindExternalStoreMessage","fromThreadMessageLike","ThreadMessageLike","getAutoStatus","isAutoStatus","ToolExecutionStatus","ReadonlyJSONValue","generateErrorMessageId","ThreadAssistantMessage","ThreadMessage","ToolCallMessagePart","MessageTiming","JoinStrategy","ThreadMessageLikeContentItem","Exclude","isPendingToolCall","type","result","undefined","isInterruptedToolCall","interrupt","approval","approved","resolution","useExternalMessageConverter","Message","convertConfig","joinStrategy","role","toolCallId","toolName","artifact","isError","messages","Metadata","toolStatuses","Record","error","messageTiming","Callback","message","T","metadata","CallbackResult","input","outputs","CallbackCacheEntry","callback","ChunkResult","inputs","Mutable","P","mergeInnerMessages","existing","incoming","joinExternalMessages","assistantMessage","Omit","content","output","toolCallIdx","findIndex","toolCall","Error","const","text","map","length","id","createdAt","status","attachments","unstable_state","unstable_annotations","unstable_data","steps","custom","timing","submittedFeedback","isOptimistic","part","existingIdx","parentId","push","unsupportedRole","chunkExternalMessages","callbackResults","results","isAssistant","pendingNone","flush","callbackResult","at","createErrorAssistantMessage","msg","reason","Date","convertExternalMessages","WeakKey","isRunning","Array","isArray","chunks","idx","isLast","joined","hasInterruptedToolCalls","some","hasPendingToolCalls","autoStatus","newMessage","toString","lastMessage","t0","$","caches","_temp","t1","t2","state","threadMessages","callbackCache","get","set","t3","chunkCache","m","key","cached","shallowArrayEqual","converterCache","convertMessages","cache","message_0","a","b","i","WeakMap"],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport { ThreadMessageConverter } from \"../../runtimes/external-store/thread-message-converter\";\nimport {\n getExternalStoreMessages,\n symbolInnerMessage,\n bindExternalStoreMessage,\n} from \"../../runtime/utils/external-store-message\";\nimport {\n fromThreadMessageLike,\n type ThreadMessageLike,\n} from \"../../runtime/utils/thread-message-like\";\nimport { getAutoStatus, isAutoStatus } from \"../../runtime/utils/auto-status\";\nimport type { ToolExecutionStatus } from \"../../runtimes/tool-invocations/ToolInvocationTracker\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { generateErrorMessageId } from \"../../utils/id\";\nimport type {\n ThreadAssistantMessage,\n ThreadMessage,\n ToolCallMessagePart,\n} from \"../../types/message\";\nimport type { MessageTiming } from \"../../types/message\";\n\nexport type JoinStrategy = \"concat-content\" | \"none\";\n\ntype ThreadMessageLikeContentItem = Exclude<\n ThreadMessageLike[\"content\"],\n string\n>[number];\n\nconst isPendingToolCall = (c: ThreadMessageLikeContentItem): boolean =>\n c.type === \"tool-call\" && c.result === undefined;\n\nconst isInterruptedToolCall = (c: ThreadMessageLikeContentItem): boolean => {\n if (c.type !== \"tool-call\" || c.result !== undefined) return false;\n return (\n c.interrupt != null ||\n (c.approval != null &&\n c.approval.approved === undefined &&\n c.approval.resolution === undefined)\n );\n};\n\nexport namespace useExternalMessageConverter {\n export type Message =\n | (ThreadMessageLike & {\n readonly convertConfig?: {\n readonly joinStrategy?: JoinStrategy;\n };\n })\n | {\n role: \"tool\";\n toolCallId: string;\n toolName?: string | undefined;\n result: any;\n artifact?: any;\n isError?: boolean;\n messages?: readonly ThreadMessage[];\n };\n\n export type Metadata = {\n readonly toolStatuses?: Record<string, ToolExecutionStatus>;\n readonly error?: ReadonlyJSONValue;\n readonly messageTiming?: Record<string, MessageTiming>;\n };\n\n export type Callback<T> = (\n message: T,\n metadata: Metadata,\n ) => Message | Message[];\n}\n\ntype CallbackResult<T> = {\n input: T;\n outputs: useExternalMessageConverter.Message[];\n};\n\ntype CallbackCacheEntry<T> = CallbackResult<T> & {\n metadata: useExternalMessageConverter.Metadata;\n callback: useExternalMessageConverter.Callback<T>;\n};\n\ntype ChunkResult<T> = {\n inputs: T[];\n outputs: useExternalMessageConverter.Message[];\n};\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\nconst mergeInnerMessages = (existing: object, incoming: object) => ({\n [symbolInnerMessage]: [\n ...((existing as any)[symbolInnerMessage] ?? []),\n ...((incoming as any)[symbolInnerMessage] ?? []),\n ],\n});\n\nconst joinExternalMessages = (\n messages: readonly useExternalMessageConverter.Message[],\n): ThreadMessageLike => {\n const assistantMessage: Mutable<Omit<ThreadMessageLike, \"metadata\">> & {\n content: Exclude<ThreadMessageLike[\"content\"][0], string>[];\n metadata?: Mutable<ThreadMessageLike[\"metadata\"]>;\n } = {\n role: \"assistant\",\n content: [],\n };\n for (const output of messages) {\n if (output.role === \"tool\") {\n const toolCallIdx = assistantMessage.content.findIndex(\n (c) => c.type === \"tool-call\" && c.toolCallId === output.toolCallId,\n );\n // Ignore orphaned tool results so one bad tool message does not\n // prevent rendering the rest of the conversation.\n if (toolCallIdx !== -1) {\n const toolCall = assistantMessage.content[\n toolCallIdx\n ]! as ToolCallMessagePart;\n if (output.toolName != null) {\n if (toolCall.toolName !== output.toolName)\n throw new Error(\n `Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`,\n );\n }\n assistantMessage.content[toolCallIdx] = {\n ...toolCall,\n ...{\n [symbolInnerMessage]: [\n ...((toolCall as any)[symbolInnerMessage] ?? []),\n output,\n ],\n },\n result: output.result,\n artifact: output.artifact,\n isError: output.isError,\n messages: output.messages,\n };\n }\n } else {\n const role = output.role;\n const content = (\n typeof output.content === \"string\"\n ? [{ type: \"text\" as const, text: output.content }]\n : output.content\n ).map((c) => ({\n ...c,\n ...{ [symbolInnerMessage]: [output] },\n }));\n switch (role) {\n case \"system\":\n case \"user\":\n return {\n ...output,\n content,\n };\n case \"assistant\":\n if (assistantMessage.content.length === 0) {\n assistantMessage.id = output.id;\n assistantMessage.createdAt ??= output.createdAt;\n assistantMessage.status ??= output.status;\n\n if (output.attachments) {\n assistantMessage.attachments = [\n ...(assistantMessage.attachments ?? []),\n ...output.attachments,\n ];\n }\n\n if (output.metadata) {\n assistantMessage.metadata ??= {};\n if (output.metadata.unstable_state !== undefined) {\n assistantMessage.metadata.unstable_state =\n output.metadata.unstable_state;\n }\n if (output.metadata.unstable_annotations) {\n assistantMessage.metadata.unstable_annotations = [\n ...(assistantMessage.metadata.unstable_annotations ?? []),\n ...output.metadata.unstable_annotations,\n ];\n }\n if (output.metadata.unstable_data) {\n assistantMessage.metadata.unstable_data = [\n ...(assistantMessage.metadata.unstable_data ?? []),\n ...output.metadata.unstable_data,\n ];\n }\n if (output.metadata.steps) {\n assistantMessage.metadata.steps = [\n ...(assistantMessage.metadata.steps ?? []),\n ...output.metadata.steps,\n ];\n }\n if (output.metadata.custom) {\n assistantMessage.metadata.custom = {\n ...(assistantMessage.metadata.custom ?? {}),\n ...output.metadata.custom,\n };\n }\n\n if (output.metadata.timing) {\n assistantMessage.metadata.timing = output.metadata.timing;\n }\n\n if (output.metadata.submittedFeedback) {\n assistantMessage.metadata.submittedFeedback =\n output.metadata.submittedFeedback;\n }\n\n if (output.metadata.isOptimistic) {\n assistantMessage.metadata.isOptimistic = true;\n }\n }\n // TODO keep this in sync\n }\n\n // Add content parts, merging reasoning parts with same parentId\n for (const part of content) {\n if (part.type === \"tool-call\") {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"tool-call\" && c.toolCallId === part.toolCallId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n ...part,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n\n if (\n part.type === \"reasoning\" &&\n \"parentId\" in part &&\n part.parentId\n ) {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"reasoning\" &&\n \"parentId\" in c &&\n c.parentId === part.parentId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n text: `${existing.text}\\n\\n${part.text}`,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n assistantMessage.content.push(part);\n }\n break;\n default: {\n const unsupportedRole: never = role;\n throw new Error(`Unknown message role: ${unsupportedRole}`);\n }\n }\n }\n }\n return assistantMessage;\n};\n\nconst chunkExternalMessages = <T>(\n callbackResults: CallbackResult<T>[],\n joinStrategy?: JoinStrategy,\n) => {\n const results: ChunkResult<T>[] = [];\n let isAssistant = false;\n let pendingNone = false; // true if the previous assistant message had joinStrategy \"none\"\n let inputs: T[] = [];\n let outputs: useExternalMessageConverter.Message[] = [];\n\n const flush = () => {\n if (outputs.length) {\n results.push({\n inputs,\n outputs,\n });\n }\n inputs = [];\n outputs = [];\n isAssistant = false;\n pendingNone = false;\n };\n\n for (const callbackResult of callbackResults) {\n for (const output of callbackResult.outputs) {\n if (\n (pendingNone && output.role !== \"tool\") ||\n !isAssistant ||\n output.role === \"user\" ||\n output.role === \"system\"\n ) {\n flush();\n }\n isAssistant = output.role === \"assistant\" || output.role === \"tool\";\n\n if (inputs.at(-1) !== callbackResult.input) {\n inputs.push(callbackResult.input);\n }\n outputs.push(output);\n\n if (\n output.role === \"assistant\" &&\n (output.convertConfig?.joinStrategy === \"none\" ||\n joinStrategy === \"none\")\n ) {\n pendingNone = true;\n }\n }\n }\n flush();\n return results;\n};\n\nfunction createErrorAssistantMessage(\n error: ReadonlyJSONValue,\n): ThreadAssistantMessage {\n const msg: ThreadAssistantMessage = {\n id: generateErrorMessageId(),\n role: \"assistant\",\n content: [],\n status: { type: \"incomplete\", reason: \"error\", error },\n createdAt: new Date(),\n metadata: {\n unstable_state: null,\n unstable_annotations: [],\n unstable_data: [],\n custom: {},\n steps: [],\n },\n };\n bindExternalStoreMessage(msg, []);\n return msg;\n}\n\nexport const convertExternalMessages = <T extends WeakKey>(\n messages: T[],\n callback: useExternalMessageConverter.Callback<T>,\n isRunning: boolean,\n metadata: useExternalMessageConverter.Metadata,\n) => {\n const callbackResults: CallbackResult<T>[] = [];\n for (const message of messages) {\n const output = callback(message, metadata);\n const outputs = Array.isArray(output) ? output : [output];\n const result = { input: message, outputs };\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults);\n\n const result = chunks.map((message, idx) => {\n const isLast = idx === chunks.length - 1;\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? metadata.error : undefined,\n );\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n });\n\n if (metadata.error) {\n const lastMessage = result.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n result.push(createErrorAssistantMessage(metadata.error));\n }\n }\n\n return result;\n};\n\nexport const useExternalMessageConverter = <T extends WeakKey>({\n callback,\n messages,\n isRunning,\n joinStrategy,\n metadata,\n}: {\n callback: useExternalMessageConverter.Callback<T>;\n messages: T[];\n isRunning: boolean;\n joinStrategy?: JoinStrategy | undefined;\n metadata?: useExternalMessageConverter.Metadata | undefined;\n}) => {\n // The caches live for the component lifetime; React Compiler hoists\n // allocations without reactive dependencies out of useMemo, so re-creating\n // them on dependency change would not survive compilation. Staleness is\n // instead tracked per entry via the metadata/callback that produced it,\n // keeping correctness independent of memoization (which React treats as\n // droppable). A \"use no memo\" opt-out would restore the useMemo semantics\n // but leave cache flushing coupled to memo firing.\n const [caches] = useState(() => ({\n callbackCache: new WeakMap<T, CallbackCacheEntry<T>>(),\n chunkCache: new WeakMap<\n useExternalMessageConverter.Message,\n ChunkResult<T>\n >(),\n converterCache: new ThreadMessageConverter(),\n }));\n\n const state = useMemo(\n () => ({\n metadata: metadata ?? {},\n callback,\n ...caches,\n }),\n [callback, metadata, caches],\n );\n\n return useMemo(() => {\n const callbackResults: CallbackResult<T>[] = [];\n for (const message of messages) {\n let result = state.callbackCache.get(message);\n if (\n !result ||\n result.metadata !== state.metadata ||\n result.callback !== state.callback\n ) {\n const output = state.callback(message, state.metadata);\n const outputs = Array.isArray(output) ? output : [output];\n result = {\n input: message,\n outputs,\n metadata: state.metadata,\n callback: state.callback,\n };\n state.callbackCache.set(message, result);\n }\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults, joinStrategy).map(\n (m) => {\n const key = m.outputs[0];\n if (!key) return m;\n\n const cached = state.chunkCache.get(key);\n if (cached && shallowArrayEqual(cached.outputs, m.outputs))\n return cached;\n state.chunkCache.set(key, m);\n return m;\n },\n );\n\n const threadMessages = state.converterCache.convertMessages(\n chunks,\n (cache, message, idx) => {\n const isLast = idx === chunks.length - 1;\n\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? state.metadata.error : undefined,\n );\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n ) {\n const inputs = getExternalStoreMessages<T>(cache);\n if (shallowArrayEqual(inputs, message.inputs)) {\n return cache;\n }\n }\n\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n },\n );\n\n bindExternalStoreMessage(threadMessages, messages);\n\n if (state.metadata.error) {\n const lastMessage = threadMessages.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n threadMessages.push(createErrorAssistantMessage(state.metadata.error));\n }\n }\n\n return threadMessages;\n }, [state, messages, isRunning, joinStrategy]);\n};\n\nconst shallowArrayEqual = (a: unknown[], b: unknown[]) => {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n};\n"],"mappings":";;;;;;;;;AA+BA,MAAMsB,qBAAqBtB,MACzBA,EAAEuB,SAAS,eAAevB,EAAEwB,WAAWC,KAAAA;AAEzC,MAAM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cC,MAAiB;CACxD,IAAID,EAAEnE,WAAWoE,EAAEpE,QAAQ,OAAO;CAClC,KAAK,IAAIqE,IAAI,GAAGA,IAAIF,EAAEnE,QAAQqE,KAC5B,IAAIF,EAAEE,OAAOD,EAAEC,IAAI,OAAO;CAE5B,OAAO;AACT;AAtI2C,SAAApB,QAAA;CAAA,OAoBR;EAAAK,+BAChB,IAAIgB,QAAkC;EAACZ,4BAC1C,IAAIY,QAGd;EAACP,gBACa,IAAIrI,uBAAuB;CAC7C;AAAC"}
|
|
1
|
+
{"version":3,"file":"external-message-converter.js","names":["c","_c","useMemo","useState","ThreadMessageConverter","getExternalStoreMessages","symbolInnerMessage","bindExternalStoreMessage","fromThreadMessageLike","ThreadMessageLike","getAutoStatus","isAutoStatus","ToolExecutionStatus","ReadonlyJSONValue","generateErrorMessageId","ThreadAssistantMessage","ThreadMessage","ToolCallMessagePart","MessageTiming","JoinStrategy","ThreadMessageLikeContentItem","Exclude","isPendingToolCall","type","result","undefined","isInterruptedToolCall","interrupt","approval","approved","resolution","useExternalMessageConverter","Message","convertConfig","joinStrategy","role","toolCallId","toolName","artifact","isError","messages","Metadata","toolStatuses","Record","error","messageTiming","Callback","message","T","metadata","CallbackResult","input","outputs","stringifyForError","value","text","Error","String","JSON","stringify","length","slice","toCallbackOutputs","output","Array","isArray","o","valid","content","CallbackCacheEntry","callback","ChunkResult","inputs","Mutable","P","mergeInnerMessages","existing","incoming","joinExternalMessages","assistantMessage","Omit","toolCallIdx","findIndex","toolCall","const","map","id","createdAt","status","attachments","unstable_state","unstable_annotations","unstable_data","steps","custom","timing","submittedFeedback","isOptimistic","part","existingIdx","parentId","push","unsupportedRole","chunkExternalMessages","callbackResults","results","isAssistant","pendingNone","flush","callbackResult","at","createErrorAssistantMessage","msg","reason","Date","convertExternalMessages","WeakKey","isRunning","chunks","idx","isLast","joined","hasInterruptedToolCalls","some","hasPendingToolCalls","autoStatus","newMessage","toString","lastMessage","t0","$","caches","_temp","t1","t2","state","threadMessages","callbackCache","get","set","t3","chunkCache","m","key","cached","shallowArrayEqual","converterCache","convertMessages","cache","message_0","a","b","i","WeakMap"],"sources":["../../../src/react/runtimes/external-message-converter.ts"],"sourcesContent":["\"use client\";\n\nimport { useMemo, useState } from \"react\";\nimport { ThreadMessageConverter } from \"../../runtimes/external-store/thread-message-converter\";\nimport {\n getExternalStoreMessages,\n symbolInnerMessage,\n bindExternalStoreMessage,\n} from \"../../runtime/utils/external-store-message\";\nimport {\n fromThreadMessageLike,\n type ThreadMessageLike,\n} from \"../../runtime/utils/thread-message-like\";\nimport { getAutoStatus, isAutoStatus } from \"../../runtime/utils/auto-status\";\nimport type { ToolExecutionStatus } from \"../../runtimes/tool-invocations/ToolInvocationTracker\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\nimport { generateErrorMessageId } from \"../../utils/id\";\nimport type {\n ThreadAssistantMessage,\n ThreadMessage,\n ToolCallMessagePart,\n} from \"../../types/message\";\nimport type { MessageTiming } from \"../../types/message\";\n\nexport type JoinStrategy = \"concat-content\" | \"none\";\n\ntype ThreadMessageLikeContentItem = Exclude<\n ThreadMessageLike[\"content\"],\n string\n>[number];\n\nconst isPendingToolCall = (c: ThreadMessageLikeContentItem): boolean =>\n c.type === \"tool-call\" && c.result === undefined;\n\nconst isInterruptedToolCall = (c: ThreadMessageLikeContentItem): boolean => {\n if (c.type !== \"tool-call\" || c.result !== undefined) return false;\n return (\n c.interrupt != null ||\n (c.approval != null &&\n c.approval.approved === undefined &&\n c.approval.resolution === undefined)\n );\n};\n\nexport namespace useExternalMessageConverter {\n export type Message =\n | (ThreadMessageLike & {\n readonly convertConfig?: {\n readonly joinStrategy?: JoinStrategy;\n };\n })\n | {\n role: \"tool\";\n toolCallId: string;\n toolName?: string | undefined;\n result: any;\n artifact?: any;\n isError?: boolean;\n messages?: readonly ThreadMessage[];\n };\n\n export type Metadata = {\n readonly toolStatuses?: Record<string, ToolExecutionStatus>;\n readonly error?: ReadonlyJSONValue;\n readonly messageTiming?: Record<string, MessageTiming>;\n };\n\n export type Callback<T> = (\n message: T,\n metadata: Metadata,\n ) => Message | Message[];\n}\n\ntype CallbackResult<T> = {\n input: T;\n outputs: useExternalMessageConverter.Message[];\n};\n\nconst stringifyForError = (value: unknown) => {\n let text;\n try {\n text = value instanceof Error ? String(value) : JSON.stringify(value);\n } catch {\n /* circular */\n }\n text ??= String(value);\n return text.length > 200 ? `${text.slice(0, 200)}…` : text;\n};\n\nconst toCallbackOutputs = (\n output:\n | useExternalMessageConverter.Message\n | useExternalMessageConverter.Message[],\n input: unknown,\n): useExternalMessageConverter.Message[] => {\n const outputs = Array.isArray(output) ? output : [output];\n for (const o of outputs) {\n const valid =\n typeof o === \"object\" &&\n o !== null &&\n (o.role === \"tool\" ||\n ((o.role === \"assistant\" || o.role === \"user\" || o.role === \"system\") &&\n (typeof o.content === \"string\" || Array.isArray(o.content))));\n if (!valid)\n throw new Error(\n `External message converter: the converter callback returned an invalid message (${stringifyForError(o)}) for input ${stringifyForError(input)}. Return an empty array to skip a message.`,\n );\n }\n return outputs;\n};\n\ntype CallbackCacheEntry<T> = CallbackResult<T> & {\n metadata: useExternalMessageConverter.Metadata;\n callback: useExternalMessageConverter.Callback<T>;\n};\n\ntype ChunkResult<T> = {\n inputs: T[];\n outputs: useExternalMessageConverter.Message[];\n};\n\ntype Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\nconst mergeInnerMessages = (existing: object, incoming: object) => ({\n [symbolInnerMessage]: [\n ...((existing as any)[symbolInnerMessage] ?? []),\n ...((incoming as any)[symbolInnerMessage] ?? []),\n ],\n});\n\nconst joinExternalMessages = (\n messages: readonly useExternalMessageConverter.Message[],\n): ThreadMessageLike => {\n const assistantMessage: Mutable<Omit<ThreadMessageLike, \"metadata\">> & {\n content: Exclude<ThreadMessageLike[\"content\"][0], string>[];\n metadata?: Mutable<ThreadMessageLike[\"metadata\"]>;\n } = {\n role: \"assistant\",\n content: [],\n };\n for (const output of messages) {\n if (output.role === \"tool\") {\n const toolCallIdx = assistantMessage.content.findIndex(\n (c) => c.type === \"tool-call\" && c.toolCallId === output.toolCallId,\n );\n // Ignore orphaned tool results so one bad tool message does not\n // prevent rendering the rest of the conversation.\n if (toolCallIdx !== -1) {\n const toolCall = assistantMessage.content[\n toolCallIdx\n ]! as ToolCallMessagePart;\n if (output.toolName != null) {\n if (toolCall.toolName !== output.toolName)\n throw new Error(\n `Tool call name ${output.toolCallId} ${output.toolName} does not match existing tool call ${toolCall.toolName}`,\n );\n }\n assistantMessage.content[toolCallIdx] = {\n ...toolCall,\n ...{\n [symbolInnerMessage]: [\n ...((toolCall as any)[symbolInnerMessage] ?? []),\n output,\n ],\n },\n result: output.result,\n artifact: output.artifact,\n isError: output.isError,\n messages: output.messages,\n };\n }\n } else {\n const role = output.role;\n const content = (\n typeof output.content === \"string\"\n ? [{ type: \"text\" as const, text: output.content }]\n : output.content\n ).map((c) => ({\n ...c,\n ...{ [symbolInnerMessage]: [output] },\n }));\n switch (role) {\n case \"system\":\n case \"user\":\n return {\n ...output,\n content,\n };\n case \"assistant\":\n if (assistantMessage.content.length === 0) {\n assistantMessage.id = output.id;\n assistantMessage.createdAt ??= output.createdAt;\n assistantMessage.status ??= output.status;\n\n if (output.attachments) {\n assistantMessage.attachments = [\n ...(assistantMessage.attachments ?? []),\n ...output.attachments,\n ];\n }\n\n if (output.metadata) {\n assistantMessage.metadata ??= {};\n if (output.metadata.unstable_state !== undefined) {\n assistantMessage.metadata.unstable_state =\n output.metadata.unstable_state;\n }\n if (output.metadata.unstable_annotations) {\n assistantMessage.metadata.unstable_annotations = [\n ...(assistantMessage.metadata.unstable_annotations ?? []),\n ...output.metadata.unstable_annotations,\n ];\n }\n if (output.metadata.unstable_data) {\n assistantMessage.metadata.unstable_data = [\n ...(assistantMessage.metadata.unstable_data ?? []),\n ...output.metadata.unstable_data,\n ];\n }\n if (output.metadata.steps) {\n assistantMessage.metadata.steps = [\n ...(assistantMessage.metadata.steps ?? []),\n ...output.metadata.steps,\n ];\n }\n if (output.metadata.custom) {\n assistantMessage.metadata.custom = {\n ...(assistantMessage.metadata.custom ?? {}),\n ...output.metadata.custom,\n };\n }\n\n if (output.metadata.timing) {\n assistantMessage.metadata.timing = output.metadata.timing;\n }\n\n if (output.metadata.submittedFeedback) {\n assistantMessage.metadata.submittedFeedback =\n output.metadata.submittedFeedback;\n }\n\n if (output.metadata.isOptimistic) {\n assistantMessage.metadata.isOptimistic = true;\n }\n }\n // TODO keep this in sync\n }\n\n // Add content parts, merging reasoning parts with same parentId\n for (const part of content) {\n if (part.type === \"tool-call\") {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"tool-call\" && c.toolCallId === part.toolCallId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n ...part,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n\n if (\n part.type === \"reasoning\" &&\n \"parentId\" in part &&\n part.parentId\n ) {\n const existingIdx = assistantMessage.content.findIndex(\n (c) =>\n c.type === \"reasoning\" &&\n \"parentId\" in c &&\n c.parentId === part.parentId,\n );\n if (existingIdx !== -1) {\n const existing = assistantMessage.content[\n existingIdx\n ] as typeof part;\n assistantMessage.content[existingIdx] = {\n ...existing,\n text: `${existing.text}\\n\\n${part.text}`,\n ...mergeInnerMessages(existing, part),\n };\n continue;\n }\n }\n assistantMessage.content.push(part);\n }\n break;\n default: {\n const unsupportedRole: never = role;\n throw new Error(`Unknown message role: ${unsupportedRole}`);\n }\n }\n }\n }\n return assistantMessage;\n};\n\nconst chunkExternalMessages = <T>(\n callbackResults: CallbackResult<T>[],\n joinStrategy?: JoinStrategy,\n) => {\n const results: ChunkResult<T>[] = [];\n let isAssistant = false;\n let pendingNone = false; // true if the previous assistant message had joinStrategy \"none\"\n let inputs: T[] = [];\n let outputs: useExternalMessageConverter.Message[] = [];\n\n const flush = () => {\n if (outputs.length) {\n results.push({\n inputs,\n outputs,\n });\n }\n inputs = [];\n outputs = [];\n isAssistant = false;\n pendingNone = false;\n };\n\n for (const callbackResult of callbackResults) {\n for (const output of callbackResult.outputs) {\n if (\n (pendingNone && output.role !== \"tool\") ||\n !isAssistant ||\n output.role === \"user\" ||\n output.role === \"system\"\n ) {\n flush();\n }\n isAssistant = output.role === \"assistant\" || output.role === \"tool\";\n\n if (inputs.at(-1) !== callbackResult.input) {\n inputs.push(callbackResult.input);\n }\n outputs.push(output);\n\n if (\n output.role === \"assistant\" &&\n (output.convertConfig?.joinStrategy === \"none\" ||\n joinStrategy === \"none\")\n ) {\n pendingNone = true;\n }\n }\n }\n flush();\n return results;\n};\n\nfunction createErrorAssistantMessage(\n error: ReadonlyJSONValue,\n): ThreadAssistantMessage {\n const msg: ThreadAssistantMessage = {\n id: generateErrorMessageId(),\n role: \"assistant\",\n content: [],\n status: { type: \"incomplete\", reason: \"error\", error },\n createdAt: new Date(),\n metadata: {\n unstable_state: null,\n unstable_annotations: [],\n unstable_data: [],\n custom: {},\n steps: [],\n },\n };\n bindExternalStoreMessage(msg, []);\n return msg;\n}\n\nexport const convertExternalMessages = <T extends WeakKey>(\n messages: T[],\n callback: useExternalMessageConverter.Callback<T>,\n isRunning: boolean,\n metadata: useExternalMessageConverter.Metadata,\n) => {\n const callbackResults: CallbackResult<T>[] = [];\n for (const message of messages) {\n const output = callback(message, metadata);\n const outputs = toCallbackOutputs(output, message);\n const result = { input: message, outputs };\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults);\n\n const result = chunks.map((message, idx) => {\n const isLast = idx === chunks.length - 1;\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? metadata.error : undefined,\n );\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n });\n\n if (metadata.error) {\n const lastMessage = result.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n result.push(createErrorAssistantMessage(metadata.error));\n }\n }\n\n return result;\n};\n\nexport const useExternalMessageConverter = <T extends WeakKey>({\n callback,\n messages,\n isRunning,\n joinStrategy,\n metadata,\n}: {\n callback: useExternalMessageConverter.Callback<T>;\n messages: T[];\n isRunning: boolean;\n joinStrategy?: JoinStrategy | undefined;\n metadata?: useExternalMessageConverter.Metadata | undefined;\n}) => {\n // The caches live for the component lifetime; React Compiler hoists\n // allocations without reactive dependencies out of useMemo, so re-creating\n // them on dependency change would not survive compilation. Staleness is\n // instead tracked per entry via the metadata/callback that produced it,\n // keeping correctness independent of memoization (which React treats as\n // droppable). A \"use no memo\" opt-out would restore the useMemo semantics\n // but leave cache flushing coupled to memo firing.\n const [caches] = useState(() => ({\n callbackCache: new WeakMap<T, CallbackCacheEntry<T>>(),\n chunkCache: new WeakMap<\n useExternalMessageConverter.Message,\n ChunkResult<T>\n >(),\n converterCache: new ThreadMessageConverter(),\n }));\n\n const state = useMemo(\n () => ({\n metadata: metadata ?? {},\n callback,\n ...caches,\n }),\n [callback, metadata, caches],\n );\n\n return useMemo(() => {\n const callbackResults: CallbackResult<T>[] = [];\n for (const message of messages) {\n let result = state.callbackCache.get(message);\n if (\n !result ||\n result.metadata !== state.metadata ||\n result.callback !== state.callback\n ) {\n const output = state.callback(message, state.metadata);\n const outputs = toCallbackOutputs(output, message);\n result = {\n input: message,\n outputs,\n metadata: state.metadata,\n callback: state.callback,\n };\n state.callbackCache.set(message, result);\n }\n callbackResults.push(result);\n }\n\n const chunks = chunkExternalMessages(callbackResults, joinStrategy).map(\n (m) => {\n const key = m.outputs[0];\n if (!key) return m;\n\n const cached = state.chunkCache.get(key);\n if (cached && shallowArrayEqual(cached.outputs, m.outputs))\n return cached;\n state.chunkCache.set(key, m);\n return m;\n },\n );\n\n const threadMessages = state.converterCache.convertMessages(\n chunks,\n (cache, message, idx) => {\n const isLast = idx === chunks.length - 1;\n\n const joined = joinExternalMessages(message.outputs);\n const hasInterruptedToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isInterruptedToolCall);\n const hasPendingToolCalls =\n typeof joined.content === \"object\" &&\n joined.content.some(isPendingToolCall);\n const autoStatus = getAutoStatus(\n isLast,\n isRunning,\n hasInterruptedToolCalls,\n hasPendingToolCalls,\n isLast ? state.metadata.error : undefined,\n );\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n ) {\n const inputs = getExternalStoreMessages<T>(cache);\n if (shallowArrayEqual(inputs, message.inputs)) {\n return cache;\n }\n }\n\n const newMessage = fromThreadMessageLike(\n joined,\n idx.toString(),\n autoStatus,\n );\n bindExternalStoreMessage(newMessage, message.inputs);\n return newMessage;\n },\n );\n\n bindExternalStoreMessage(threadMessages, messages);\n\n if (state.metadata.error) {\n const lastMessage = threadMessages.at(-1);\n if (!lastMessage || lastMessage.role !== \"assistant\") {\n threadMessages.push(createErrorAssistantMessage(state.metadata.error));\n }\n }\n\n return threadMessages;\n }, [state, messages, isRunning, joinStrategy]);\n};\n\nconst shallowArrayEqual = (a: unknown[], b: unknown[]) => {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n};\n"],"mappings":";;;;;;;;;AA+BA,MAAMsB,qBAAqBtB,MACzBA,EAAEuB,SAAS,eAAevB,EAAEwB,WAAWC,KAAAA;AAEzC,MAAMC,yBAAyB1B,MAA6C;CAC1E,IAAIA,EAAEuB,SAAS,eAAevB,EAAEwB,WAAWC,KAAAA,GAAW,OAAO;CAC7D,OACEzB,EAAE2B,aAAa,QACd3B,EAAE4B,YAAY,QACb5B,EAAE4B,SAASC,aAAaJ,KAAA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ACAF,IAAGQ,SAAU,GACbF,UACF;GACAtH,yBAAyBuH,YAAY/E,UAAOyB,MAAO;GAAC,OAC7CsD;EAAU,CAErB;EAEAvH,yBAAyBiI,gBAAgBhG,QAAQ;EAEjD,IAAI+F,MAAKtF,SAASL,OAAM;GACtB,MAAAoF,cAAoBQ,eAAc1B,GAAI,EAAE;GACxC,IAAI,CAACkB,eAAeA,YAAW7F,SAAU,aACvCqG,eAAcnC,KAAMU,4BAA4BwB,MAAKtF,SAASL,KAAM,CAAC;EACtE;EACFsF,EAAA,KAAAb;EAAAa,EAAA,KAAAhG;EAAAgG,EAAA,KAAA1F;EAAA0F,EAAA,KAAAK;EAAAL,EAAA,MAAAM;CAAA,OAAAA,iBAAAN,EAAA;CAAA,OAEDM;AAAsB;AAI1B,MAAMS,qBAAqBK,GAAcC,MAAiB;CACxD,IAAID,EAAE1F,WAAW2F,EAAE3F,QAAQ,OAAO;CAClC,KAAK,IAAI4F,IAAI,GAAGA,IAAIF,EAAE1F,QAAQ4F,KAC5B,IAAIF,EAAEE,OAAOD,EAAEC,IAAI,OAAO;CAE5B,OAAO;AACT;AAtI2C,SAAApB,QAAA;CAAA,OAoBR;EAAAK,+BAChB,IAAIgB,QAAkC;EAACZ,4BAC1C,IAAIY,QAGd;EAACP,gBACa,IAAI9I,uBAAuB;CAC7C;AAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RunConfig,
|
|
1
|
+
import { RunConfig, ThreadMessage } from "../../types/message.js";
|
|
2
2
|
import { Unsubscribe } from "../../types/unsubscribe.js";
|
|
3
3
|
import { SpeechState } from "../interfaces/thread-runtime-core.js";
|
|
4
4
|
import { MessageRuntimePath } from "./paths.js";
|
|
@@ -8,7 +8,6 @@ import { EditComposerRuntime, EditComposerRuntimeImpl } from "./composer-runtime
|
|
|
8
8
|
import { MessagePartRuntime, MessagePartRuntimeImpl } from "./message-part-runtime.js";
|
|
9
9
|
import { ThreadRuntimeCoreBinding } from "./thread-runtime.js";
|
|
10
10
|
//#region src/runtime/api/message-runtime.d.ts
|
|
11
|
-
declare const toMessagePartStatus: (message: ThreadMessage, partIndex: number, part: ThreadUserMessagePart | ThreadAssistantMessagePart) => ToolCallMessagePartStatus;
|
|
12
11
|
type MessageState = ThreadMessage & {
|
|
13
12
|
readonly parentId: string | null;
|
|
14
13
|
/** The position of this message in the thread (0 for first message) */
|
|
@@ -87,5 +86,5 @@ declare class MessageRuntimeImpl implements MessageRuntime {
|
|
|
87
86
|
getAttachmentByIndex(idx: number): MessageAttachmentRuntimeImpl;
|
|
88
87
|
}
|
|
89
88
|
//#endregion
|
|
90
|
-
export { MessageRuntime, MessageRuntimeImpl, MessageState, type MessageStateBinding
|
|
89
|
+
export { MessageRuntime, MessageRuntimeImpl, MessageState, type MessageStateBinding };
|
|
91
90
|
//# sourceMappingURL=message-runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;KAgDY,eAAe;WAChB;;WAEA;WACA;WAEA;WACA;;;;WAKA,QAAQ;;KAKd;EACH,YAAY;;KAGF;WACD,MAAM;WAEN,UAAU;EAEnB,YAAY;EACZ,iBAAiB;EACjB,OAAO,SAAS;;;;EAIhB;;;;EAIA;EACA,iBAAiB;IAAU;;EAC3B,iBACE,UACA;IAEA;IACA;;EAEF;EAEA,UAAU,uBAAuB;EAEjC,sBAAsB,cAAc;EACpC,2BAA2B,qBAAqB;EAEhD,qBAAqB,cAAc;IAAsB;;;cAG9C,8BAA8B;MAC9B,QAAI;UAIP;UACA;EAGN,YAAA,OAAO,qBACP,gBAAgB;YAoBR;WAgBM,UAAQ;UAEhB;EAMD,YAAQ;;;;;;;;EAIR,iBAAM;EAKN,OAAO,eAAc;EAkBrB;EAKA;EAUA,iBAAiB;IAAU;;EAQ3B,iBACL,UACA;IAEA;IACA;;EAsBK;EAIA,UAAU,uBAAoB;EAI9B,sBAAsB,cAAW;EAmBjC,2BAA2B,qBAAkB;EAwB7C,qBAAqB,cAAW"}
|
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import { getThreadMessageText } from "../../utils/text.js";
|
|
2
2
|
import { symbolInnerMessage } from "../utils/external-store-message.js";
|
|
3
3
|
import { NestedSubscriptionSubject, SKIP_UPDATE, ShallowMemoizeSubject } from "../../subscribable/subscribable.js";
|
|
4
|
-
import {
|
|
4
|
+
import { toMessagePartStatus } from "../../utils/normalizePartStatus.js";
|
|
5
5
|
import { MessageAttachmentRuntimeImpl } from "./attachment-runtime.js";
|
|
6
6
|
import { EditComposerRuntimeImpl } from "./composer-runtime.js";
|
|
7
7
|
import { MessagePartRuntimeImpl } from "./message-part-runtime.js";
|
|
8
8
|
//#region src/runtime/api/message-runtime.ts
|
|
9
|
-
const toMessagePartStatus = (message, partIndex, part) => {
|
|
10
|
-
if (message.role !== "assistant") return COMPLETE_STATUS;
|
|
11
|
-
if (part.type === "tool-call") {
|
|
12
|
-
if (part.result === void 0) return message.status;
|
|
13
|
-
else return COMPLETE_STATUS;
|
|
14
|
-
}
|
|
15
|
-
if (message.status.type === "running") {
|
|
16
|
-
const status = normalizePartStatus(part);
|
|
17
|
-
if (status) return status;
|
|
18
|
-
}
|
|
19
|
-
const isLastPart = partIndex === Math.max(0, message.content.length - 1);
|
|
20
|
-
if (message.status.type === "requires-action") return COMPLETE_STATUS;
|
|
21
|
-
return isLastPart ? message.status : COMPLETE_STATUS;
|
|
22
|
-
};
|
|
23
9
|
const getMessagePartState = (message, partIndex) => {
|
|
24
10
|
const part = message.content[partIndex];
|
|
25
11
|
if (!part) return SKIP_UPDATE;
|
|
@@ -181,6 +167,6 @@ var MessageRuntimeImpl = class {
|
|
|
181
167
|
}
|
|
182
168
|
};
|
|
183
169
|
//#endregion
|
|
184
|
-
export { MessageRuntimeImpl
|
|
170
|
+
export { MessageRuntimeImpl };
|
|
185
171
|
|
|
186
172
|
//# sourceMappingURL=message-runtime.js.map
|