@assistant-ui/core 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +6 -7
- package/dist/internal.js +5 -6
- package/dist/react/AssistantProvider.d.ts +1 -1
- package/dist/react/AssistantProvider.d.ts.map +1 -1
- package/dist/react/AssistantProvider.js +35 -9
- package/dist/react/AssistantProvider.js.map +1 -1
- package/dist/react/AssistantRuntimeProvider.d.ts +1 -1
- package/dist/react/AssistantRuntimeProvider.js +1 -1
- package/dist/react/RuntimeAdapter.js +2 -2
- package/dist/react/adapters/LocalStorageThreadListAdapter.d.ts.map +1 -1
- package/dist/react/adapters/LocalStorageThreadListAdapter.js +17 -33
- package/dist/react/adapters/LocalStorageThreadListAdapter.js.map +1 -1
- package/dist/react/client/DataRenderers.js +1 -1
- package/dist/react/client/Interactables.js +1 -1
- package/dist/react/client/Tools.js +2 -2
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +2 -1
- package/dist/react/interactables-legacy/Interactables.js +1 -1
- package/dist/react/interactables-legacy/useAssistantInteractable.js +1 -1
- package/dist/react/interactables-legacy/useInteractableState.js +2 -2
- package/dist/react/model-context/useAssistantContext.js +1 -1
- package/dist/react/model-context/useAssistantDataUI.js +2 -2
- package/dist/react/model-context/useAssistantInstructions.js +2 -2
- package/dist/react/model-context/useAssistantTool.js +2 -2
- package/dist/react/model-context/useAssistantToolUI.js +2 -2
- package/dist/react/model-context/useAuiToolOverrides.js +1 -1
- package/dist/react/model-context/useInlineRender.js +1 -1
- package/dist/react/model-context/useInteractable.js +1 -1
- package/dist/react/model-context/useInteractableState.js +2 -2
- package/dist/react/model-context/useInteractableVersions.js +2 -2
- package/dist/react/model-context/useToolArgsStatus.js +2 -2
- package/dist/react/primitive-hooks/useActionBarCopy.js +52 -25
- package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
- package/dist/react/primitive-hooks/useActionBarEdit.js +2 -2
- package/dist/react/primitive-hooks/useActionBarFeedback.js +2 -2
- package/dist/react/primitive-hooks/useActionBarReload.js +2 -2
- package/dist/react/primitive-hooks/useActionBarSpeak.js +2 -2
- package/dist/react/primitive-hooks/useActionBarStopSpeaking.js +2 -2
- package/dist/react/primitive-hooks/useBranchPickerNext.js +2 -2
- package/dist/react/primitive-hooks/useBranchPickerPrevious.js +2 -2
- package/dist/react/primitive-hooks/useComposerAddAttachment.js +2 -2
- package/dist/react/primitive-hooks/useComposerCancel.js +2 -2
- package/dist/react/primitive-hooks/useComposerDictate.js +2 -2
- package/dist/react/primitive-hooks/useComposerSend.js +2 -2
- package/dist/react/primitive-hooks/useEditComposerCancel.js +2 -2
- package/dist/react/primitive-hooks/useEditComposerSend.js +2 -2
- package/dist/react/primitive-hooks/useMessageBranching.js +2 -2
- package/dist/react/primitive-hooks/useMessageReload.js +2 -2
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemArchive.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemDelete.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemTrigger.js +2 -2
- package/dist/react/primitive-hooks/useThreadListItemUnarchive.js +2 -2
- package/dist/react/primitive-hooks/useThreadListLoadMore.js +2 -2
- package/dist/react/primitive-hooks/useThreadListNew.js +2 -2
- package/dist/react/primitive-hooks/useThreadMessageIds.js +1 -1
- package/dist/react/primitive-hooks/useVoice.js +2 -2
- package/dist/react/primitives/chainOfThought/ChainOfThoughtParts.js +2 -2
- package/dist/react/primitives/composer/ComposerAttachments.js +2 -2
- package/dist/react/primitives/composer/ComposerIf.js +1 -1
- package/dist/react/primitives/composer/ComposerQueue.js +1 -1
- package/dist/react/primitives/generativeUI/GenerativeUI.js +2 -2
- package/dist/react/primitives/message/MessageAttachments.js +2 -2
- package/dist/react/primitives/message/MessageGroupedParts.d.ts +2 -1
- package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageGroupedParts.js +3 -3
- package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.js +2 -2
- package/dist/react/primitives/message/MessageQuote.js +2 -2
- package/dist/react/primitives/part/PartMessages.js +2 -2
- package/dist/react/primitives/thread/ThreadMessages.js +2 -2
- package/dist/react/primitives/thread/ThreadSuggestions.js +2 -2
- package/dist/react/primitives/threadList/ThreadListItems.js +2 -2
- package/dist/react/primitives/threadListItem/ThreadListItemTitle.js +1 -1
- package/dist/react/providers/AttachmentByIndexProvider.js +1 -1
- package/dist/react/providers/ChainOfThoughtByIndicesProvider.js +1 -1
- package/dist/react/providers/ChainOfThoughtPartByIndexProvider.js +1 -1
- package/dist/react/providers/MessageByIdProvider.js +1 -1
- package/dist/react/providers/MessageByIndexProvider.js +1 -1
- package/dist/react/providers/PartByIndexProvider.js +1 -1
- package/dist/react/providers/QueueItemByIndexProvider.js +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.js +2 -2
- package/dist/react/providers/SuggestionByIndexProvider.js +1 -1
- package/dist/react/providers/TextMessagePartProvider.js +2 -2
- package/dist/react/providers/ThreadListItemByIndexProvider.js +1 -1
- package/dist/react/providers/ThreadListItemRuntimeProvider.js +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +14 -13
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +3 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +22 -12
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/RuntimeAdapterProvider.js +1 -1
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js +9 -23
- package/dist/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +24 -2
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +24 -5
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/runtimes/external-message-converter.js +1 -1
- package/dist/react/runtimes/useExternalStoreRuntime.js +1 -1
- package/dist/react/runtimes/useExternalStoreSharedOptions.js +1 -1
- package/dist/react/runtimes/useLocalRuntime.js +1 -1
- package/dist/react/runtimes/useRemoteThreadListRuntime.js +7 -13
- package/dist/react/runtimes/useRemoteThreadListRuntime.js.map +1 -1
- package/dist/react/utils/useJSONEqual.js +1 -1
- package/dist/runtime/api/message-runtime.d.ts.map +1 -1
- package/dist/runtime/api/message-runtime.js +5 -1
- package/dist/runtime/api/message-runtime.js.map +1 -1
- package/dist/runtime/internal.d.ts +4 -4
- package/dist/runtime/internal.js +4 -4
- package/dist/runtime/utils/thread-message-like.js +2 -2
- package/dist/runtime/utils/thread-message-like.js.map +1 -1
- package/dist/runtimes/remote-thread-list/types.d.ts +5 -4
- package/dist/runtimes/remote-thread-list/types.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
- package/dist/store/clients/chain-of-thought-client.js +30 -24
- package/dist/store/clients/chain-of-thought-client.js.map +1 -1
- package/dist/store/clients/model-context-client.js +1 -1
- package/dist/store/clients/no-op-composer-client.js +1 -1
- package/dist/store/clients/suggestions.js +2 -2
- package/dist/store/clients/thread-message-client.d.ts.map +1 -1
- package/dist/store/clients/thread-message-client.js +103 -91
- package/dist/store/clients/thread-message-client.js.map +1 -1
- package/dist/store/runtime-clients/composer-runtime-client.js +2 -2
- package/dist/store/runtime-clients/message-runtime-client.js +2 -2
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +2 -2
- package/dist/store/runtime-clients/thread-list-runtime-client.js +2 -2
- package/dist/store/runtime-clients/thread-runtime-client.js +2 -2
- package/dist/store/scopes/thread.d.ts +1 -1
- package/dist/store/scopes/thread.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/message.d.ts +11 -1
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/data-url.js +2 -2
- package/dist/utils/data-url.js.map +1 -1
- package/dist/utils/getGroupStatus.d.ts +9 -0
- package/dist/utils/getGroupStatus.d.ts.map +1 -0
- package/dist/utils/getGroupStatus.js +15 -0
- package/dist/utils/getGroupStatus.js.map +1 -0
- package/dist/utils/normalizePartStatus.d.ts +8 -0
- package/dist/utils/normalizePartStatus.d.ts.map +1 -0
- package/dist/utils/normalizePartStatus.js +39 -0
- package/dist/utils/normalizePartStatus.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/internal.ts +1 -7
- package/src/react/AssistantProvider.tsx +28 -15
- package/src/react/AssistantRuntimeProvider.test.tsx +101 -0
- package/src/react/adapters/LocalStorageThreadListAdapter.tsx +28 -7
- package/src/react/index.ts +4 -0
- package/src/react/primitive-hooks/useActionBarCopy.test.ts +109 -14
- package/src/react/primitive-hooks/useActionBarCopy.ts +27 -2
- package/src/react/primitives/message/MessageGroupedParts.tsx +4 -4
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +16 -13
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +53 -10
- package/src/react/runtimes/cloud/AssistantCloudThreadHistoryAdapter.ts +7 -5
- package/src/react/runtimes/cloud/auiV0.ts +51 -12
- package/src/react/runtimes/useRemoteThreadListRuntime.ts +9 -15
- package/src/runtime/api/message-runtime.test.ts +140 -0
- package/src/runtime/api/message-runtime.ts +10 -5
- package/src/runtime/utils/thread-message-like.ts +2 -2
- package/src/runtimes/remote-thread-list/types.ts +5 -4
- package/src/store/clients/chain-of-thought-client.ts +2 -7
- package/src/store/clients/thread-message-client.test.ts +84 -0
- package/src/store/clients/thread-message-client.ts +14 -4
- package/src/store/scopes/thread.ts +1 -1
- package/src/tests/auiV0Encode.test.ts +93 -0
- package/src/tests/remote-thread-list-reactive-threadId.test.ts +0 -92
- package/src/tests/thread-message-like.test.ts +15 -0
- package/src/tests/useRemoteThreadListRuntime-controlled.test.tsx +293 -0
- package/src/types/index.ts +1 -0
- package/src/types/message.ts +19 -0
- package/src/utils/data-url.test.ts +26 -2
- package/src/utils/data-url.ts +2 -2
- package/src/utils/getGroupStatus.test.ts +36 -0
- package/src/utils/getGroupStatus.ts +31 -0
- package/src/utils/normalizePartStatus.test.ts +59 -0
- package/src/utils/normalizePartStatus.ts +55 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auiV0.js","names":["DataMessagePart","FileMessagePart","ImageMessagePart","MessageStatus","SourceProviderMetadata","ThreadMessage","TextMessagePart","ToolApprovalOption","Unstable_AudioMessagePart","CompleteAttachment","fromThreadMessageLike","CloudMessage","isJSONValue","ReadonlyJSONObject","ReadonlyJSONValue","ExportedMessageRepositoryItem","AuiV0ToolApproval","id","approved","reason","isAutomatic","options","optionId","resolution","AuiV0MessagePart","type","text","sourceType","url","title","providerMetadata","mediaType","filename","toolCallId","toolName","args","result","isError","approval","argsText","image","data","mimeType","AuiV0AttachmentPart","AuiV0Attachment","name","contentType","status","content","AuiV0Message","role","attachments","metadata","unstable_state","unstable_annotations","unstable_data","steps","usage","inputTokens","outputTokens","custom","encodeAttachmentPart","part","console","warn","JSON","stringify","unhandledType","Error","encodeAttachments","message","length","undefined","map","auiV0Encode","auiV0Decode","cloudMessage","format","payload","createdAt","created_at","parentId","parent_id"],"sources":["../../../../src/react/runtimes/cloud/auiV0.ts"],"sourcesContent":["import type {\n DataMessagePart,\n FileMessagePart,\n ImageMessagePart,\n MessageStatus,\n SourceProviderMetadata,\n ThreadMessage,\n TextMessagePart,\n ToolApprovalOption,\n Unstable_AudioMessagePart,\n} from \"../../../types/message\";\nimport type { CompleteAttachment } from \"../../../types/attachment\";\nimport { fromThreadMessageLike } from \"../../../runtime/utils/thread-message-like\";\nimport type { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"../../../utils/json/is-json\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ExportedMessageRepositoryItem } from \"../../../runtime/utils/message-repository\";\n\ntype AuiV0ToolApproval = {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n readonly options?: readonly ToolApprovalOption[];\n readonly optionId?: string;\n readonly resolution?: \"cancelled\" | \"expired\";\n};\n\ntype AuiV0MessagePart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: ReadonlyJSONObject;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly argsText: string;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n };\n\ntype AuiV0AttachmentPart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | Unstable_AudioMessagePart\n | DataMessagePart<ReadonlyJSONValue>;\n\ntype AuiV0Attachment = {\n readonly id: string;\n readonly type: CompleteAttachment[\"type\"];\n readonly name: string;\n readonly contentType?: string;\n readonly status: CompleteAttachment[\"status\"];\n readonly content: readonly AuiV0AttachmentPart[];\n};\n\ntype AuiV0Message = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly status?: MessageStatus;\n readonly content: readonly AuiV0MessagePart[];\n readonly attachments?: readonly AuiV0Attachment[];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly {\n readonly usage?: {\n readonly inputTokens: number;\n readonly outputTokens: number;\n };\n }[];\n readonly custom: ReadonlyJSONObject;\n };\n};\n\nconst encodeAttachmentPart = (\n part: CompleteAttachment[\"content\"][number],\n): AuiV0AttachmentPart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"image\":\n case \"file\":\n case \"audio\":\n return part;\n\n case \"data\": {\n if (!isJSONValue(part.data)) {\n console.warn(`attachment data is not JSON! ${JSON.stringify(part)}`);\n }\n return { ...part, data: part.data as ReadonlyJSONValue };\n }\n\n default: {\n const unhandledType: never = type;\n throw new Error(\n `Attachment part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n};\n\nconst encodeAttachments = (\n message: ThreadMessage,\n): readonly AuiV0Attachment[] | undefined => {\n if (message.role !== \"user\" || message.attachments.length === 0) {\n return undefined;\n }\n\n return message.attachments.map(\n ({ id, type, name, contentType, status, content }) => ({\n id,\n type,\n name,\n status,\n ...(contentType != null ? { contentType } : undefined),\n content: content.map(encodeAttachmentPart),\n }),\n );\n};\n\nexport function auiV0Encode(message: ThreadMessage): AuiV0Message {\n // info: ID and createdAt are ignored (we use the server value instead)\n const status: MessageStatus | undefined =\n message.status?.type === \"running\"\n ? { type: \"incomplete\", reason: \"cancelled\" }\n : message.status;\n const attachments = encodeAttachments(message);\n\n return {\n role: message.role,\n content: message.content.map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"reasoning\":\n return { type: \"reasoning\", text: part.text };\n\n case \"source\":\n if (part.sourceType === \"url\") {\n return {\n type: \"source\",\n sourceType: \"url\",\n id: part.id,\n url: part.url,\n ...(part.title != null ? { title: part.title } : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n }\n\n return {\n type: \"source\",\n sourceType: \"document\",\n id: part.id,\n title: part.title,\n mediaType: part.mediaType,\n ...(part.filename != null\n ? { filename: part.filename }\n : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n\n case \"tool-call\": {\n if (!isJSONValue(part.result)) {\n console.warn(\n `tool-call result is not JSON! ${JSON.stringify(part)}`,\n );\n }\n return {\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n ...(JSON.stringify(part.args) === part.argsText\n ? { args: part.args }\n : { argsText: part.argsText }),\n ...(part.result\n ? { result: part.result as ReadonlyJSONValue }\n : undefined),\n ...(part.isError ? { isError: true } : undefined),\n ...(part.approval ? { approval: part.approval } : undefined),\n };\n }\n\n case \"image\":\n return { type: \"image\", image: part.image };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename ? { filename: part.filename } : undefined),\n };\n\n default: {\n const unhandledType: \"audio\" | \"data\" | \"generative-ui\" = type;\n throw new Error(\n `Message part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n }),\n metadata: message.metadata as AuiV0Message[\"metadata\"],\n ...(status ? { status } : undefined),\n ...(attachments ? { attachments } : undefined),\n };\n}\n\nexport function auiV0Decode(\n cloudMessage: CloudMessage & { format: \"aui/v0\" },\n): ExportedMessageRepositoryItem {\n const payload = cloudMessage.content as unknown as AuiV0Message;\n const message = fromThreadMessageLike(\n {\n id: cloudMessage.id,\n createdAt: cloudMessage.created_at,\n ...payload,\n },\n cloudMessage.id,\n { type: \"complete\", reason: \"unknown\" },\n );\n\n return {\n parentId: cloudMessage.parent_id,\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AIwC,KAAAA;IACpD;IAEF,SAEE,MAAM,IAAIJ,MACR,8CAA8CD,MAChD;GAEJ;EACF,CAAC;EACDf,UAAUkB,QAAQlB;EAClB,GAAIL,SAAS,EAAEA,OAAO,IAAIyB,KAAAA;EAC1B,GAAIrB,cAAc,EAAEA,YAAY,IAAIqB,KAAAA;CACtC;AACF;AAEA,SAAgBG,YACdC,cAC+B;CAC/B,MAAME,UAAUF,aAAa5B;CAC7B,MAAMsB,UAAU5D,sBACd;EACEO,IAAI2D,aAAa3D;EACjB8D,WAAWH,aAAaI;EACxB,GAAGF;CACL,GACAF,aAAa3D,IACb;EAAEQ,MAAM;EAAYN,QAAQ;CAAU,CACxC;CAEA,OAAO;EACL8D,UAAUL,aAAaM;EACvBZ;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"auiV0.js","names":["MessageStatus","SourceProviderMetadata","ThreadMessage","ToolApprovalOption","CompleteAttachment","fromThreadMessageLike","CloudMessage","isJSONValue","ReadonlyJSONObject","ReadonlyJSONValue","ExportedMessageRepositoryItem","AuiV0ToolApproval","id","approved","reason","isAutomatic","options","optionId","resolution","AuiV0MessagePart","type","text","sourceType","url","title","providerMetadata","mediaType","filename","toolCallId","toolName","args","result","isError","approval","argsText","image","data","mimeType","AuiV0AttachmentPart","audio","format","name","AuiV0Attachment","contentType","status","content","AuiV0Message","role","attachments","metadata","unstable_state","unstable_annotations","unstable_data","steps","usage","inputTokens","outputTokens","custom","encodeAttachmentPart","part","undefined","console","warn","JSON","stringify","unhandledType","Error","encodeAttachments","message","length","map","auiV0Encode","auiV0Decode","cloudMessage","payload","createdAt","created_at","parentId","parent_id"],"sources":["../../../../src/react/runtimes/cloud/auiV0.ts"],"sourcesContent":["import type {\n MessageStatus,\n SourceProviderMetadata,\n ThreadMessage,\n ToolApprovalOption,\n} from \"../../../types/message\";\nimport type { CompleteAttachment } from \"../../../types/attachment\";\nimport { fromThreadMessageLike } from \"../../../runtime/utils/thread-message-like\";\nimport type { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"../../../utils/json/is-json\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ExportedMessageRepositoryItem } from \"../../../runtime/utils/message-repository\";\n\ntype AuiV0ToolApproval = {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n readonly options?: readonly ToolApprovalOption[];\n readonly optionId?: string;\n readonly resolution?: \"cancelled\" | \"expired\";\n};\n\ntype AuiV0MessagePart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: ReadonlyJSONObject;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly argsText: string;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n };\n\ntype AuiV0AttachmentPart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n }\n | {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n }\n | {\n readonly type: \"data\";\n readonly name: string;\n readonly data: ReadonlyJSONValue;\n };\n\ntype AuiV0Attachment = {\n readonly id: string;\n readonly type: CompleteAttachment[\"type\"];\n readonly name: string;\n readonly contentType?: string;\n readonly status: CompleteAttachment[\"status\"];\n readonly content: readonly AuiV0AttachmentPart[];\n};\n\ntype AuiV0Message = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly status?: MessageStatus;\n readonly content: readonly AuiV0MessagePart[];\n readonly attachments?: readonly AuiV0Attachment[];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly {\n readonly usage?: {\n readonly inputTokens: number;\n readonly outputTokens: number;\n };\n }[];\n readonly custom: ReadonlyJSONObject;\n };\n};\n\nconst encodeAttachmentPart = (\n part: CompleteAttachment[\"content\"][number],\n): AuiV0AttachmentPart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"image\":\n return {\n type: \"image\",\n image: part.image,\n ...(part.filename != null ? { filename: part.filename } : undefined),\n };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename != null ? { filename: part.filename } : undefined),\n };\n\n case \"audio\":\n return {\n type: \"audio\",\n audio: { data: part.audio.data, format: part.audio.format },\n };\n\n case \"data\": {\n if (!isJSONValue(part.data)) {\n console.warn(`attachment data is not JSON! ${JSON.stringify(part)}`);\n }\n return {\n type: \"data\",\n name: part.name,\n data: part.data as ReadonlyJSONValue,\n };\n }\n\n default: {\n const unhandledType: never = type;\n throw new Error(\n `Attachment part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n};\n\nconst encodeAttachments = (\n message: ThreadMessage,\n): readonly AuiV0Attachment[] | undefined => {\n if (message.role !== \"user\" || message.attachments.length === 0) {\n return undefined;\n }\n\n return message.attachments.map(\n ({ id, type, name, contentType, status, content }) => ({\n id,\n type,\n name,\n status,\n ...(contentType != null ? { contentType } : undefined),\n content: content.map(encodeAttachmentPart),\n }),\n );\n};\n\nexport function auiV0Encode(message: ThreadMessage): AuiV0Message {\n // info: ID and createdAt are ignored (we use the server value instead)\n const status: MessageStatus | undefined =\n message.status?.type === \"running\"\n ? { type: \"incomplete\", reason: \"cancelled\" }\n : message.status;\n const attachments = encodeAttachments(message);\n\n return {\n role: message.role,\n content: message.content.map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"reasoning\":\n return { type: \"reasoning\", text: part.text };\n\n case \"source\":\n if (part.sourceType === \"url\") {\n return {\n type: \"source\",\n sourceType: \"url\",\n id: part.id,\n url: part.url,\n ...(part.title != null ? { title: part.title } : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n }\n\n return {\n type: \"source\",\n sourceType: \"document\",\n id: part.id,\n title: part.title,\n mediaType: part.mediaType,\n ...(part.filename != null\n ? { filename: part.filename }\n : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n\n case \"tool-call\": {\n if (!isJSONValue(part.result)) {\n console.warn(\n `tool-call result is not JSON! ${JSON.stringify(part)}`,\n );\n }\n return {\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n ...(JSON.stringify(part.args) === part.argsText\n ? { args: part.args }\n : { argsText: part.argsText }),\n ...(part.result\n ? { result: part.result as ReadonlyJSONValue }\n : undefined),\n ...(part.isError ? { isError: true } : undefined),\n ...(part.approval ? { approval: part.approval } : undefined),\n };\n }\n\n case \"image\":\n return { type: \"image\", image: part.image };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename ? { filename: part.filename } : undefined),\n };\n\n default: {\n const unhandledType: \"audio\" | \"data\" | \"generative-ui\" = type;\n throw new Error(\n `Message part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n }),\n metadata: message.metadata as AuiV0Message[\"metadata\"],\n ...(status ? { status } : undefined),\n ...(attachments ? { attachments } : undefined),\n };\n}\n\nexport function auiV0Decode(\n cloudMessage: CloudMessage & { format: \"aui/v0\" },\n): ExportedMessageRepositoryItem {\n const payload = cloudMessage.content as unknown as AuiV0Message;\n const message = fromThreadMessageLike(\n {\n id: cloudMessage.id,\n createdAt: cloudMessage.created_at,\n ...payload,\n },\n cloudMessage.id,\n { type: \"complete\", reason: \"unknown\" },\n );\n\n return {\n parentId: cloudMessage.parent_id,\n message,\n };\n}\n"],"mappings":";;;AA0IA,MAAM0D,wBACJC,SACwB;CACxB,MAAMvC,OAAOuC,KAAKvC;CAClB,QAAQA,MAAR;EACE,KAAK,QACH,OAAO;GAAEA,MAAM;GAAQC,MAAMsC,KAAKtC;EAAK;EAEzC,KAAK,SACH,OAAO;GACLD,MAAM;GACNe,OAAOwB,KAAKxB;GACZ,GAAIwB,KAAKhC,YAAY,OAAO,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;EAC5D;EAEF,KAAK,QACH,OAAO;GACLxC,MAAM;GACNgB,MAAMuB,KAAKvB;GACXC,UAAUsB,KAAKtB;GACf,GAAIsB,KAAKhC,YAAY,OAAO,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;EAC5D;EAEF,KAAK,SACH,OAAO;GACLxC,MAAM;GACNmB,OAAO;IAAEH,MAAMuB,KAAKpB,MAAMH;IAAMI,QAAQmB,KAAKpB,MAAMC;GAAO;EAC5D;EAEF,KAAK;GACH,IAAI,CAACjC,YAAYoD,KAAKvB,IAAI,GACxByB,QAAQC,KAAK,gCAAgCC,KAAKC,UAAUL,IAAI,GAAG;GAErE,OAAO;IACLvC,MAAM;IACNqB,MAAMkB,KAAKlB;IACXL,MAAMuB,KAAKvB;GACb;EAGF,SAEE,MAAM,IAAI8B,MACR,iDAAiDD,MACnD;CAEJ;AACF;AAEA,MAAME,qBACJC,YAC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CACxC;CAEA,OAAO;EACL+D,UAAUJ,aAAaK;EACvBV;CACF;AACF"}
|
|
@@ -4,8 +4,8 @@ import { fromThreadMessageLike } from "../../runtime/utils/thread-message-like.j
|
|
|
4
4
|
import { bindExternalStoreMessage, getExternalStoreMessages, symbolInnerMessage } from "../../runtime/utils/external-store-message.js";
|
|
5
5
|
import { getAutoStatus, isAutoStatus } from "../../runtime/utils/auto-status.js";
|
|
6
6
|
import { ThreadMessageConverter } from "../../runtimes/external-store/thread-message-converter.js";
|
|
7
|
-
import { useState } from "@assistant-ui/tap/react-shim";
|
|
8
7
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
8
|
+
import { useState } from "@assistant-ui/tap/react-shim";
|
|
9
9
|
//#region src/react/runtimes/external-message-converter.ts
|
|
10
10
|
const isPendingToolCall = (c) => c.type === "tool-call" && c.result === void 0;
|
|
11
11
|
const isInterruptedToolCall = (c) => {
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { AssistantRuntimeImpl } from "../../runtime/api/assistant-runtime.js";
|
|
3
3
|
import { ExternalStoreRuntimeCore } from "../../runtimes/external-store/external-store-runtime-core.js";
|
|
4
4
|
import { useRuntimeAdapters } from "./RuntimeAdapterProvider.js";
|
|
5
|
-
import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
6
5
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
6
|
+
import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
7
7
|
//#region src/react/runtimes/useExternalStoreRuntime.ts
|
|
8
8
|
const useExternalStoreRuntime = (store) => {
|
|
9
9
|
const $ = c(11);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import "@assistant-ui/tap/react-shim";
|
|
3
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import "@assistant-ui/tap/react-shim";
|
|
4
4
|
//#region src/react/runtimes/useExternalStoreSharedOptions.ts
|
|
5
5
|
const useExternalStoreSharedOptions = (options) => {
|
|
6
6
|
const $ = c(5);
|
|
@@ -3,8 +3,8 @@ import { LocalRuntimeCore } from "../../runtimes/local/local-runtime-core.js";
|
|
|
3
3
|
import { useRuntimeAdapters } from "./RuntimeAdapterProvider.js";
|
|
4
4
|
import { useRemoteThreadListRuntime } from "./useRemoteThreadListRuntime.js";
|
|
5
5
|
import { useCloudThreadListAdapter } from "./cloud/useCloudThreadListAdapter.js";
|
|
6
|
-
import { useAuiState } from "@assistant-ui/store";
|
|
7
6
|
import { useEffect, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
7
|
+
import { useAuiState } from "@assistant-ui/store";
|
|
8
8
|
//#region src/react/runtimes/useLocalRuntime.ts
|
|
9
9
|
const useLocalThreadRuntime = (chatModel, { initialMessages, ...options }) => {
|
|
10
10
|
const { modelContext, ...threadListAdapters } = useRuntimeAdapters() ?? {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseAssistantRuntimeCore } from "../../runtime/base/base-assistant-runtime-core.js";
|
|
2
2
|
import { AssistantRuntimeImpl } from "../../runtime/api/assistant-runtime.js";
|
|
3
3
|
import { RemoteThreadListThreadListRuntimeCore } from "./RemoteThreadListThreadListRuntimeCore.js";
|
|
4
|
-
import { useAui } from "@assistant-ui/store";
|
|
5
|
-
import { useCallback, useEffect, useEffectEvent, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
6
4
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
5
|
+
import { useCallback, useEffect, useEffectEvent, useMemo, useRef, useState } from "@assistant-ui/tap/react-shim";
|
|
6
|
+
import { useAui } from "@assistant-ui/store";
|
|
7
7
|
//#region src/react/runtimes/useRemoteThreadListRuntime.ts
|
|
8
8
|
var RemoteThreadListRuntimeCore = class extends BaseAssistantRuntimeCore {
|
|
9
9
|
threads;
|
|
@@ -53,7 +53,7 @@ const useRemoteThreadListRuntimeImpl = (options) => {
|
|
|
53
53
|
const useRemoteThreadListRuntime = (options) => {
|
|
54
54
|
const runtimeHookRef = useRef(options.runtimeHook);
|
|
55
55
|
runtimeHookRef.current = options.runtimeHook;
|
|
56
|
-
const
|
|
56
|
+
const initialThreadIdRef = useRef(options.initialThreadId);
|
|
57
57
|
const stableRuntimeHook = useCallback(() => {
|
|
58
58
|
return runtimeHookRef.current();
|
|
59
59
|
}, []);
|
|
@@ -63,27 +63,21 @@ const useRemoteThreadListRuntime = (options) => {
|
|
|
63
63
|
const stableOptions = useMemo(() => ({
|
|
64
64
|
adapter: options.adapter,
|
|
65
65
|
allowNesting: options.allowNesting,
|
|
66
|
-
|
|
66
|
+
threadId: options.threadId,
|
|
67
|
+
initialThreadId: initialThreadIdRef.current,
|
|
67
68
|
runtimeHook: stableRuntimeHook,
|
|
68
69
|
onThreadIdChange
|
|
69
70
|
}), [
|
|
70
71
|
options.adapter,
|
|
71
72
|
options.allowNesting,
|
|
73
|
+
options.threadId,
|
|
72
74
|
stableRuntimeHook
|
|
73
75
|
]);
|
|
74
76
|
if (useAui().threadListItem.source !== null) {
|
|
75
77
|
if (!stableOptions.allowNesting) throw new Error("useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. Set allowNesting: true to allow nesting (the inner runtime will become a no-op).");
|
|
76
78
|
return stableRuntimeHook();
|
|
77
79
|
}
|
|
78
|
-
|
|
79
|
-
const prevThreadIdRef = useRef(options.threadId);
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
if (options.threadId === prevThreadIdRef.current) return;
|
|
82
|
-
prevThreadIdRef.current = options.threadId;
|
|
83
|
-
if (options.threadId) runtime.threads.switchToThread(options.threadId).catch(() => {});
|
|
84
|
-
else runtime.threads.switchToNewThread().catch(() => {});
|
|
85
|
-
}, [runtime, options.threadId]);
|
|
86
|
-
return runtime;
|
|
80
|
+
return useRemoteThreadListRuntimeImpl(stableOptions);
|
|
87
81
|
};
|
|
88
82
|
//#endregion
|
|
89
83
|
export { useRemoteThreadListRuntime };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRemoteThreadListRuntime.js","names":["useState","useEffect","useMemo","useRef","useCallback","useEffectEvent","BaseAssistantRuntimeCore","AssistantRuntimeImpl","RemoteThreadListOptions","AssistantRuntimeCore","AssistantRuntime","RemoteThreadListThreadListRuntimeCore","useAui","RemoteThreadListRuntimeCore","threads","constructor","options","_contextProvider","RenderComponent","__internal_RenderComponent","useRemoteThreadListRuntimeImpl","$","_c","t0","runtime","t1","__internal_setOptions","__internal_load","t2","t3","useRemoteThreadListRuntime","runtimeHookRef","runtimeHook","current","
|
|
1
|
+
{"version":3,"file":"useRemoteThreadListRuntime.js","names":["useState","useEffect","useMemo","useRef","useCallback","useEffectEvent","BaseAssistantRuntimeCore","AssistantRuntimeImpl","RemoteThreadListOptions","AssistantRuntimeCore","AssistantRuntime","RemoteThreadListThreadListRuntimeCore","useAui","RemoteThreadListRuntimeCore","threads","constructor","options","_contextProvider","RenderComponent","__internal_RenderComponent","useRemoteThreadListRuntimeImpl","$","_c","t0","runtime","t1","__internal_setOptions","__internal_load","t2","t3","useRemoteThreadListRuntime","runtimeHookRef","runtimeHook","current","initialThreadIdRef","initialThreadId","stableRuntimeHook","onThreadIdChange","threadId","stableOptions","adapter","allowNesting","aui","isNested","threadListItem","source","Error"],"sources":["../../../src/react/runtimes/useRemoteThreadListRuntime.ts"],"sourcesContent":["import {\n useState,\n useEffect,\n useMemo,\n useRef,\n useCallback,\n useEffectEvent,\n} from \"react\";\nimport { BaseAssistantRuntimeCore } from \"../../runtime/base/base-assistant-runtime-core\";\nimport { AssistantRuntimeImpl } from \"../../runtime/api/assistant-runtime\";\nimport type { RemoteThreadListOptions } from \"../../runtimes/remote-thread-list/types\";\nimport type { AssistantRuntimeCore } from \"../../runtime/interfaces/assistant-runtime-core\";\nimport type { AssistantRuntime } from \"../../runtime/api/assistant-runtime\";\nimport { RemoteThreadListThreadListRuntimeCore } from \"./RemoteThreadListThreadListRuntimeCore\";\nimport { useAui } from \"@assistant-ui/store\";\n\nclass RemoteThreadListRuntimeCore\n extends BaseAssistantRuntimeCore\n implements AssistantRuntimeCore\n{\n public readonly threads;\n\n constructor(options: RemoteThreadListOptions) {\n super();\n this.threads = new RemoteThreadListThreadListRuntimeCore(\n options,\n this._contextProvider,\n );\n }\n\n public get RenderComponent() {\n return this.threads.__internal_RenderComponent;\n }\n}\n\nconst useRemoteThreadListRuntimeImpl = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const [runtime] = useState(() => new RemoteThreadListRuntimeCore(options));\n useEffect(() => {\n runtime.threads.__internal_setOptions(options);\n runtime.threads.__internal_load();\n }, [runtime, options]);\n\n return useMemo(() => new AssistantRuntimeImpl(runtime), [runtime]);\n};\n\nexport const useRemoteThreadListRuntime = (\n options: RemoteThreadListOptions,\n): AssistantRuntime => {\n const runtimeHookRef = useRef(options.runtimeHook);\n runtimeHookRef.current = options.runtimeHook;\n\n const initialThreadIdRef = useRef(options.initialThreadId);\n\n const stableRuntimeHook = useCallback(() => {\n return runtimeHookRef.current();\n }, []);\n\n const onThreadIdChange = useEffectEvent((threadId: string | undefined) => {\n options.onThreadIdChange?.(threadId);\n });\n\n const stableOptions = useMemo<RemoteThreadListOptions>(\n () => ({\n adapter: options.adapter,\n allowNesting: options.allowNesting,\n threadId: options.threadId,\n initialThreadId: initialThreadIdRef.current,\n runtimeHook: stableRuntimeHook,\n onThreadIdChange,\n }),\n [\n options.adapter,\n options.allowNesting,\n options.threadId,\n stableRuntimeHook,\n ],\n );\n\n const aui = useAui();\n const isNested = aui.threadListItem.source !== null;\n\n if (isNested) {\n if (!stableOptions.allowNesting) {\n throw new Error(\n \"useRemoteThreadListRuntime cannot be nested inside another RemoteThreadListRuntime. \" +\n \"Set allowNesting: true to allow nesting (the inner runtime will become a no-op).\",\n );\n }\n\n // If allowNesting is true and already inside a thread list context,\n // just call the runtimeHook directly (no-op behavior)\n return stableRuntimeHook();\n }\n\n const runtime = useRemoteThreadListRuntimeImpl(st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,QAAQgB;CAEjC,MAAME,qBAAqB/B,OAAOa,QAAQmB,eAAe;CAEzD,MAAMC,oBAAoBhC,kBAAkB;EAC1C,OAAO2B,eAAeE,QAAQ;CAChC,GAAG,CAAA,CAAE;CAEL,MAAMI,mBAAmBhC,gBAAgBiC,aAAiC;EACxEtB,QAAQqB,mBAAmBC,QAAQ;CACrC,CAAC;CAED,MAAMC,gBAAgBrC,eACb;EACLsC,SAASxB,QAAQwB;EACjBC,cAAczB,QAAQyB;EACtBH,UAAUtB,QAAQsB;EAClBH,iBAAiBD,mBAAmBD;EACpCD,aAAaI;EACbC;CACF,IACA;EACErB,QAAQwB;EACRxB,QAAQyB;EACRzB,QAAQsB;EACRF;CAAiB,CAErB;CAKA,IAHYxB,OACK8B,CAAG,CAACE,eAAeC,WAAW,MAEjC;EACZ,IAAI,CAACN,cAAcE,cACjB,MAAM,IAAIK,MACR,sKAEF;EAKF,OAAOV,kBAAkB;CAC3B;CAIA,OAFgBhB,+BAA+BmB,aAExCf;AACT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isJSONValueEqual } from "../../utils/json/is-json-equal.js";
|
|
2
|
-
import { useRef } from "@assistant-ui/tap/react-shim";
|
|
3
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { useRef } from "@assistant-ui/tap/react-shim";
|
|
4
4
|
//#region src/react/utils/useJSONEqual.ts
|
|
5
5
|
/**
|
|
6
6
|
* Like `useShallow`, but with JSON deep-equality. Use when a selector derives an
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;cAsCa,sBACX,SAAS,eACT,mBACA,MAAM,wBAAwB,+BAC7B;
|
|
1
|
+
{"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;cAsCa,sBACX,SAAS,eACT,mBACA,MAAM,wBAAwB,+BAC7B;KAuCS,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,15 +1,19 @@
|
|
|
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 { COMPLETE_STATUS, normalizePartStatus } from "../../utils/normalizePartStatus.js";
|
|
4
5
|
import { MessageAttachmentRuntimeImpl } from "./attachment-runtime.js";
|
|
5
6
|
import { EditComposerRuntimeImpl } from "./composer-runtime.js";
|
|
6
7
|
import { MessagePartRuntimeImpl } from "./message-part-runtime.js";
|
|
7
8
|
//#region src/runtime/api/message-runtime.ts
|
|
8
|
-
const COMPLETE_STATUS = Object.freeze({ type: "complete" });
|
|
9
9
|
const toMessagePartStatus = (message, partIndex, part) => {
|
|
10
10
|
if (message.role !== "assistant") return COMPLETE_STATUS;
|
|
11
11
|
if (part.type === "tool-call") if (!part.result) return message.status;
|
|
12
12
|
else return COMPLETE_STATUS;
|
|
13
|
+
if (message.status.type === "running") {
|
|
14
|
+
const status = normalizePartStatus(part);
|
|
15
|
+
if (status) return status;
|
|
16
|
+
}
|
|
13
17
|
const isLastPart = partIndex === Math.max(0, message.content.length - 1);
|
|
14
18
|
if (message.status.type === "requires-action") return COMPLETE_STATUS;
|
|
15
19
|
return isLastPart ? message.status : COMPLETE_STATUS;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ToolCallMessagePartStatus","ThreadMessage","ThreadAssistantMessagePart","ThreadUserMessagePart","Unsubscribe","MessagePartStatus","RunConfig","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","COMPLETE_STATUS","Object","freeze","type","toMessagePartStatus","message","partIndex","part","role","result","status","isLastPart","Math","max","content","length","getMessagePartState","MessageState","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","_threadBinding","constructor","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type {\n ToolCallMessagePartStatus,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallMessagePartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n /** The position of this message in the thread (0 for first message) */\n readonly index: number;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport type { MessageStateBinding } from \"./bindings\";\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n delete(): void | Promise<void>;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n private _core: MessageStateBinding;\n private _threadBinding: ThreadRuntimeCoreBinding;\n\n constructor(\n _core: MessageStateBinding,\n _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadBinding = _threadBinding;\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getMessagePartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;AAkCA,MAAMwB,kBAAqCC,OAAOC,OAAO,EACvDC,MAAM,WACR,CAAC;AAED,MAAaC,uBACXC,SACAC,WACAC,SAC8B;CAC9B,IAAIF,QAAQG,SAAS,aAAa,OAAOR;CAEzC,IAAIO,KAAKJ,SAAS,aAChB,IAAI,CAACI,KAAKE,QACR,OAAOJ,QAAQK;MAEf,OAAOV;CAIX,MAAMW,aAAaL,cAAcM,KAAKC,IAAI,GAAGR,QAAQS,QAAQC,SAAS,CAAC;CACvE,IAAIV,QAAQK,OAAOP,SAAS,mBAAmB,OAAOH;CACtD,OAAOW,aAAcN,QAAQK,SAA+BV;AAC9D;AAEA,MAAMgB,uBACJX,SACAC,cACmC;CACnC,MAAMC,OAAOF,QAAQS,QAAQR;CAC7B,IAAI,CAACC,MACH,OAAOpB;CAIT,MAAMuB,SAASN,oBAAoBC,SAASC,WAAWC,IAAI;CAC3D,OAAON,OAAOC,OAAO;EACnB,GAAGK;GACG9B,qBAAsB8B,KAAa9B;EACzCiC;CACF,CAAC;AACH;AAyDA,IAAauC,qBAAb,MAA0D;CACxD,IAAWtB,OAAO;EAChB,OAAO,KAAKuB,MAAMvB;CACpB;CAEA;CACA;CAEAyB,YACEF,OACAC,gBACA;EACA,KAAKD,QAAQA;EACb,KAAKC,iBAAiBA;EACtB,KAAKvB,WAAW,IAAInC,wBAClB,IAAIP,0BAA0B;GAC5ByC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG;IACrBC,gBAAgB;GAClB;GACAzB,UAAU,KAAK0B;GACfd,YAAY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CAEA,qBAA4BP,KAAa;EACvC,OAAO,IAAIrD,6BACT,IAAIH,sBAAsB;GACxBuC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG,eAAgBT,IAAG;IACxCkC,kBAAkB;IAClBC,oBAAoB;KAAE5E,MAAM;KAASgB,OAAOyB;IAAI;GAClD;GACAf,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACmD,cACHpC;IACjC,IAAI,CAACqC,YAAY,OAAO9F;IAExB,OAAO;KACL,GAAG8F;KACHjC,QAAQ;IACV;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ToolCallMessagePartStatus","ThreadMessage","ThreadAssistantMessagePart","ThreadUserMessagePart","Unsubscribe","MessagePartStatus","RunConfig","COMPLETE_STATUS","normalizePartStatus","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","toMessagePartStatus","message","partIndex","part","role","type","result","status","isLastPart","Math","max","content","length","getMessagePartState","MessageState","Object","freeze","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","_threadBinding","constructor","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type {\n ToolCallMessagePartStatus,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport {\n COMPLETE_STATUS,\n normalizePartStatus,\n} from \"../../utils/normalizePartStatus\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallMessagePartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n if (message.status.type === \"running\") {\n const status = normalizePartStatus(part);\n if (status) return status;\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status: status as MessagePartStatus,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n /** The position of this message in the thread (0 for first message) */\n readonly index: number;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport type { MessageStateBinding } from \"./bindings\";\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n delete(): void | Promise<void>;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n private _core: MessageStateBinding;\n private _threadBinding: ThreadRuntimeCoreBinding;\n\n constructor(\n _core: MessageStateBinding,\n _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadBinding = _threadBinding;\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getMessagePartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;;AAsCA,MAAa0B,uBACXC,SACAC,WACAC,SAC8B;CAC9B,IAAIF,QAAQG,SAAS,aAAa,OAAOrB;CAEzC,IAAIoB,KAAKE,SAAS,aAChB,IAAI,CAACF,KAAKG,QACR,OAAOL,QAAQM;MAEf,OAAOxB;CAIX,IAAIkB,QAAQM,OAAOF,SAAS,WAAW;EACrC,MAAME,SAASvB,oBAAoBmB,IAAI;EACvC,IAAII,QAAQ,OAAOA;CACrB;CAEA,MAAMC,aAAaN,cAAcO,KAAKC,IAAI,GAAGT,QAAQU,QAAQC,SAAS,CAAC;CACvE,IAAIX,QAAQM,OAAOF,SAAS,mBAAmB,OAAOtB;CACtD,OAAOyB,aAAcP,QAAQM,SAA+BxB;AAC9D;AAEA,MAAM8B,uBACJZ,SACAC,cACmC;CACnC,MAAMC,OAAOF,QAAQU,QAAQT;CAC7B,IAAI,CAACC,MACH,OAAOhB;CAIT,MAAMoB,SAASP,oBAAoBC,SAASC,WAAWC,IAAI;CAC3D,OAAOY,OAAOC,OAAO;EACnB,GAAGb;GACG5B,qBAAsB4B,KAAa5B;EACjCgC;CACV,CAAC;AACH;AAyDA,IAAayC,qBAAb,MAA0D;CACxD,IAAWtB,OAAO;EAChB,OAAO,KAAKuB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S;IAClC,MAAMe,MAAMiB,MAAMjD,QAAQiE,WACvBzE,SACCA,KAAKE,SAAS,eAAeF,KAAK0C,eAAeA,UACrD;IACA,IAAIF,QAAQ,IAAI,OAAOxD;IACvB,OAAO0B,oBAAoB+C,OAAOjB,GAAG;GACvC;GACAH,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKQ,OACL,KAAKC,cACP;CACF;CAEA,qBAA4BP,KAAa;EACvC,OAAO,IAAIpD,6BACT,IAAIH,sBAAsB;GACxBsC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG,eAAgBT,IAAG;IACxCkC,kBAAkB;IAClBC,oBAAoB;KAAEzE,MAAM;KAASa,OAAOyB;IAAI;GAClD;GACAf,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACmD,cACHpC;IACjC,IAAI,CAACqC,YAAY,OAAO7F;IAExB,OAAO;KACL,GAAG6F;KACHjC,QAAQ;IACV;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { fromThreadMessageLike } from "./utils/thread-message-like.js";
|
|
2
2
|
import { ExportedMessageRepository, ExportedMessageRepositoryItem, MessageRepository } from "./utils/message-repository.js";
|
|
3
3
|
import { ComposerRuntimeCoreBinding, EditComposerRuntimeCoreBinding, MessageStateBinding, ThreadComposerRuntimeCoreBinding } from "./api/bindings.js";
|
|
4
|
+
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
|
|
5
|
+
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
|
|
6
|
+
import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
|
|
7
|
+
import { MessageRuntimeImpl } from "./api/message-runtime.js";
|
|
4
8
|
import { BaseAssistantRuntimeCore } from "./base/base-assistant-runtime-core.js";
|
|
5
9
|
import { BaseComposerRuntimeCore } from "./base/base-composer-runtime-core.js";
|
|
6
10
|
import { DefaultThreadComposerRuntimeCore } from "./base/default-thread-composer-runtime-core.js";
|
|
@@ -8,10 +12,6 @@ import { DefaultEditComposerRuntimeCore } from "./base/default-edit-composer-run
|
|
|
8
12
|
import { BaseThreadRuntimeCore } from "./base/base-thread-runtime-core.js";
|
|
9
13
|
import { ThreadListItemRuntimeImpl, ThreadListItemStateBinding } from "./api/thread-list-item-runtime.js";
|
|
10
14
|
import { ThreadListRuntimeCoreBinding, ThreadListRuntimeImpl } from "./api/thread-list-runtime.js";
|
|
11
|
-
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
|
|
12
|
-
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
|
|
13
|
-
import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
|
|
14
|
-
import { MessageRuntimeImpl } from "./api/message-runtime.js";
|
|
15
15
|
import { symbolInnerMessage } from "./utils/external-store-message.js";
|
|
16
16
|
import { getAutoStatus, isAutoStatus } from "./utils/auto-status.js";
|
|
17
17
|
import { ThreadListItemRuntimeBinding, ThreadRuntimeCoreBinding, ThreadRuntimeImpl, getThreadState } from "./api/thread-runtime.js";
|
package/dist/runtime/internal.js
CHANGED
|
@@ -2,16 +2,16 @@ import { fromThreadMessageLike } from "./utils/thread-message-like.js";
|
|
|
2
2
|
import { symbolInnerMessage } from "./utils/external-store-message.js";
|
|
3
3
|
import { getAutoStatus, isAutoStatus } from "./utils/auto-status.js";
|
|
4
4
|
import { ExportedMessageRepository, MessageRepository } from "./utils/message-repository.js";
|
|
5
|
+
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
|
|
6
|
+
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
|
|
7
|
+
import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
|
|
8
|
+
import { MessageRuntimeImpl } from "./api/message-runtime.js";
|
|
5
9
|
import { BaseAssistantRuntimeCore } from "./base/base-assistant-runtime-core.js";
|
|
6
10
|
import { BaseComposerRuntimeCore } from "./base/base-composer-runtime-core.js";
|
|
7
11
|
import { DefaultThreadComposerRuntimeCore } from "./base/default-thread-composer-runtime-core.js";
|
|
8
12
|
import { DefaultEditComposerRuntimeCore } from "./base/default-edit-composer-runtime-core.js";
|
|
9
13
|
import { BaseThreadRuntimeCore } from "./base/base-thread-runtime-core.js";
|
|
10
14
|
import { ThreadListItemRuntimeImpl } from "./api/thread-list-item-runtime.js";
|
|
11
|
-
import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
|
|
12
|
-
import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
|
|
13
|
-
import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
|
|
14
|
-
import { MessageRuntimeImpl } from "./api/message-runtime.js";
|
|
15
15
|
import { ThreadRuntimeImpl, getThreadState } from "./api/thread-runtime.js";
|
|
16
16
|
import { ThreadListRuntimeImpl } from "./api/thread-list-runtime.js";
|
|
17
17
|
import { AssistantRuntimeImpl } from "./api/assistant-runtime.js";
|
|
@@ -24,11 +24,11 @@ const fromThreadMessageLike = (like, fallbackId, fallbackStatus) => {
|
|
|
24
24
|
}] : like.content;
|
|
25
25
|
const sanitizeImageContent = ({ image, ...rest }) => {
|
|
26
26
|
if (typeof image !== "string") return null;
|
|
27
|
-
if (image.match(/^data:image\/(png|jpeg|jpg|gif|webp|svg\+xml);base64,(.*)$/)) return {
|
|
27
|
+
if (image.match(/^data:image\/(png|jpeg|jpg|gif|webp|svg\+xml);base64,(.*)$/i)) return {
|
|
28
28
|
...rest,
|
|
29
29
|
image
|
|
30
30
|
};
|
|
31
|
-
if (/^(https:\/\/|blob:)
|
|
31
|
+
if (/^(https:\/\/|blob:)/i.test(image)) return {
|
|
32
32
|
...rest,
|
|
33
33
|
image
|
|
34
34
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-message-like.js","names":["parsePartialJsonObject","generateId","ReasoningMessagePart","SourceMessagePart","ThreadStep","MessageStatus","ImageMessagePart","ThreadMessage","ThreadAssistantMessagePart","ThreadAssistantMessage","ThreadUserMessagePart","ThreadUserMessage","ThreadSystemMessage","FileMessagePart","DataMessagePart","GenerativeUIMessagePart","Unstable_AudioMessagePart","CompleteAttachment","MessageTiming","PartProviderMetadata","TextMessagePart","ToolApprovalOption","ToolCallTiming","ReadonlyJSONObject","ReadonlyJSONValue","DataPrefixedPart","type","data","ThreadMessageLike","role","content","toolCallId","toolName","args","argsText","artifact","result","isError","parentId","messages","interrupt","payload","timing","providerMetadata","approval","id","approved","reason","isAutomatic","options","optionId","resolution","createdAt","Date","status","attachments","Omit","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","isOptimistic","custom","Record","convertDataPrefixedPart","startsWith","undefined","name","substring","fromThreadMessageLike","like","fallbackId","fallbackStatus","common","const","text","sanitizeImageContent","image","rest","dataUri","match","test","console","warn","length","Error","map","part","trim","basePart","commonProps","JSON","stringify","converted","filter","c","att","unsupportedRole"],"sources":["../../../src/runtime/utils/thread-message-like.ts"],"sourcesContent":["import { parsePartialJsonObject } from \"assistant-stream/utils\";\nimport { generateId } from \"../../utils/id\";\nimport type {\n ReasoningMessagePart,\n SourceMessagePart,\n ThreadStep,\n MessageStatus,\n ImageMessagePart,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadAssistantMessage,\n ThreadUserMessagePart,\n ThreadUserMessage,\n ThreadSystemMessage,\n FileMessagePart,\n DataMessagePart,\n GenerativeUIMessagePart,\n Unstable_AudioMessagePart,\n} from \"../../types/message\";\nimport type { CompleteAttachment } from \"../../types/attachment\";\nimport type {\n MessageTiming,\n PartProviderMetadata,\n TextMessagePart,\n ToolApprovalOption,\n ToolCallTiming,\n} from \"../../types/message\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\n\ntype DataPrefixedPart = {\n readonly type: `data-${string}`;\n readonly data: any;\n};\n\nexport type ThreadMessageLike = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly content:\n | string\n | readonly (\n | TextMessagePart\n | ReasoningMessagePart\n | SourceMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart\n | Unstable_AudioMessagePart\n | DataPrefixedPart\n | {\n readonly type: \"tool-call\";\n readonly toolCallId?: string;\n readonly toolName: string;\n readonly args?: ReadonlyJSONObject;\n readonly argsText?: string;\n readonly artifact?: any;\n readonly result?: any | undefined;\n readonly isError?: boolean | undefined;\n readonly parentId?: string | undefined;\n readonly messages?: readonly ThreadMessage[] | undefined;\n readonly interrupt?: { type: \"human\"; payload: unknown };\n readonly timing?: ToolCallTiming;\n readonly providerMetadata?: PartProviderMetadata;\n readonly approval?: {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n readonly options?: readonly ToolApprovalOption[];\n readonly optionId?: string;\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n }\n )[];\n readonly id?: string | undefined;\n readonly createdAt?: Date | undefined;\n readonly status?: MessageStatus | undefined;\n readonly attachments?:\n | readonly (Omit<CompleteAttachment, \"content\"> & {\n readonly content: readonly (ThreadUserMessagePart | DataPrefixedPart)[];\n })[]\n | undefined;\n readonly metadata?:\n | {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?:\n | readonly ReadonlyJSONValue[]\n | undefined;\n readonly unstable_data?: readonly ReadonlyJSONValue[] | undefined;\n readonly steps?: readonly ThreadStep[] | undefined;\n readonly timing?: MessageTiming | undefined;\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly isOptimistic?: boolean | undefined;\n readonly custom?: Record<string, unknown> | undefined;\n }\n | undefined;\n};\n\nconst convertDataPrefixedPart = (\n type: string,\n data: unknown,\n): DataMessagePart | undefined => {\n if (!type.startsWith(\"data-\")) return undefined;\n return { type: \"data\", name: type.substring(5), data };\n};\n\n/**\n * @deprecated This API is experimental and may change without notice.\n */\nexport const fromThreadMessageLike = (\n like: ThreadMessageLike,\n fallbackId: string,\n fallbackStatus: MessageStatus,\n): ThreadMessage => {\n const { role, id, createdAt, attachments, status, metadata } = like;\n const common = {\n id: id ?? fallbackId,\n createdAt: createdAt ?? new Date(),\n };\n\n const content =\n typeof like.content === \"string\"\n ? [{ type: \"text\" as const, text: like.content }]\n : like.content;\n\n const sanitizeImageContent = ({\n image,\n ...rest\n }: ImageMessagePart): ImageMessagePart | null => {\n if (typeof image !== \"string\") return null;\n const dataUri = image.match(\n /^data:image\\/(png|jpeg|jpg|gif|webp|svg\\+xml);base64,(.*)$/,\n );\n if (dataUri) {\n return { ...rest, image };\n }\n if (/^(https:\\/\\/|blob:)/.test(image)) {\n return { ...rest, image };\n }\n console.warn(`Invalid image data format detected`);\n return null;\n };\n\n if (role !== \"user\" && attachments?.length)\n throw new Error(\"attachments are only supported for user messages\");\n\n if (role !== \"assistant\" && status)\n throw new Error(\"status is only supported for assistant messages\");\n\n if (role !== \"assistant\" && metadata?.steps)\n throw new Error(\"metadata.steps is only supported for assistant messages\");\n\n switch (role) {\n case \"assistant\":\n return {\n ...common,\n role,\n content: content\n .map((part): ThreadAssistantMessagePart | null => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"reasoning\":\n if (!part.text?.trim()) return null;\n return part;\n\n case \"file\":\n case \"source\":\n return part;\n\n case \"image\":\n return sanitizeImageContent(part);\n\n case \"data\":\n return part;\n\n case \"generative-ui\":\n return part;\n\n case \"tool-call\": {\n const { parentId, messages, ...basePart } = part;\n const commonProps = {\n ...basePart,\n toolCallId: part.toolCallId ?? `tool-${generateId()}`,\n ...(parentId !== undefined && { parentId }),\n ...(messages !== undefined && { messages }),\n };\n\n if (part.args) {\n return {\n ...commonProps,\n args: part.args,\n argsText: part.argsText ?? JSON.stringify(part.args),\n };\n }\n return {\n ...commonProps,\n args: parsePartialJsonObject(part.argsText ?? \"\") ?? {},\n argsText: part.argsText ?? \"\",\n };\n }\n\n default: {\n const converted = convertDataPrefixedPart(\n type,\n (part as DataPrefixedPart).data,\n );\n if (converted) return converted;\n throw new Error(\n `Unsupported assistant message part type: ${type}`,\n );\n }\n }\n })\n .filter((c) => !!c),\n status: status ?? fallbackStatus,\n metadata: {\n unstable_state: metadata?.unstable_state ?? null,\n unstable_annotations: metadata?.unstable_annotations ?? [],\n unstable_data: metadata?.unstable_data ?? [],\n custom: metadata?.custom ?? {},\n steps: metadata?.steps ?? [],\n ...(metadata?.timing && { timing: metadata.timing }),\n ...(metadata?.submittedFeedback && {\n submittedFeedback: metadata.submittedFeedback,\n }),\n ...(metadata?.isOptimistic && { isOptimistic: true }),\n },\n } satisfies ThreadAssistantMessage;\n\n case \"user\":\n return {\n ...common,\n role,\n content: content.map((part): ThreadUserMessagePart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"image\":\n case \"audio\":\n case \"file\":\n case \"data\":\n return part;\n\n default: {\n const converted = convertDataPrefixedPart(\n type,\n (part as DataPrefixedPart).data,\n );\n if (converted) return converted;\n throw new Error(`Unsupported user message part type: ${type}`);\n }\n }\n }),\n attachments: (attachments ?? []).map((att) => ({\n ...att,\n content: att.content.map((part): ThreadUserMessagePart => {\n const converted = convertDataPrefixedPart(\n part.type,\n (part as DataPrefixedPart).data,\n );\n return converted ?? (part as ThreadUserMessagePart);\n }),\n })),\n metadata: {\n custom: metadata?.custom ?? {},\n ...(metadata?.isOptimistic && { isOptimistic: true }),\n },\n } satisfies ThreadUserMessage;\n\n case \"system\":\n if (content.length !== 1 || content[0]!.type !== \"text\")\n throw new Error(\n \"System messages must have exactly one text message part.\",\n );\n\n return {\n ...common,\n role,\n content: content as [TextMessagePart],\n metadata: {\n custom: metadata?.custom ?? {},\n },\n } satisfies ThreadSystemMessage;\n\n default: {\n const unsupportedRole: never = role;\n throw new Error(`Unknown message role: ${unsupportedRole}`);\n }\n }\n};\n"],"mappings":";;;AAoGA,MAAMkE,2BACJxC,MACAC,SACgC;CAChC,IAAI,CAACD,KAAKyC,WAAW,OAAO,GAAG,OAAOC,KAAAA;CACtC,OAAO;EAAE1C,MAAM;EAAQ2C,MAAM3C,KAAK4C,UAAU,CAAC;EAAG3C;CAAK;AACvD;;;;AAKA,MAAa4C,yBACXC,MACAC,YACAC,mBACkB;CAClB,MAAM,EAAE7C,MAAMgB,IAAIO,WAAWG,aAAaD,QAAQG,aAAae;CAC/D,MAAMG,SAAS;EACb9B,IAAIA,MAAM4B;EACVrB,WAAWA,6BAAa,IAAIC,KAAK;CACnC;CAEA,MAAMvB,UACJ,OAAO0C,KAAK1C,YAAY,WACpB,CAAC;EAAEJ,MAAM;EAAiBmD,MAAML,KAAK1C;CAAQ,CAAC,IAC9C0C,KAAK1C;CAEX,MAAMgD,wBAAwB,EAC5BC,OACA,GAAGC,WAC4C;EAC/C,IAAI,OAAOD,UAAU,UAAU,OAAO;EAItC,IAHgBA,MAAMG,MACpB,4DAEED,GACF,OAAO;GAAE,GAAGD;GAAMD;EAAM;EAE1B,IAAI,sBAAsBI,KAAKJ,KAAK,GAClC,OAAO;GAAE,GAAGC;GAAMD;EAAM;EAE1BK,QAAQC,KAAK,oCAAoC;EACjD,OAAO;CACT;CAEA,IAAIxD,SAAS,UAAU0B,aAAa+B,QAClC,MAAM,IAAIC,MAAM,kDAAkD;CAEpE,IAAI1D,SAAS,eAAeyB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AAIuB,MAAM,yBAAyBY,MAAiB;CAE9D;AACF"}
|
|
1
|
+
{"version":3,"file":"thread-message-like.js","names":["parsePartialJsonObject","generateId","ReasoningMessagePart","SourceMessagePart","ThreadStep","MessageStatus","ImageMessagePart","ThreadMessage","ThreadAssistantMessagePart","ThreadAssistantMessage","ThreadUserMessagePart","ThreadUserMessage","ThreadSystemMessage","FileMessagePart","DataMessagePart","GenerativeUIMessagePart","Unstable_AudioMessagePart","CompleteAttachment","MessageTiming","PartProviderMetadata","TextMessagePart","ToolApprovalOption","ToolCallTiming","ReadonlyJSONObject","ReadonlyJSONValue","DataPrefixedPart","type","data","ThreadMessageLike","role","content","toolCallId","toolName","args","argsText","artifact","result","isError","parentId","messages","interrupt","payload","timing","providerMetadata","approval","id","approved","reason","isAutomatic","options","optionId","resolution","createdAt","Date","status","attachments","Omit","metadata","unstable_state","unstable_annotations","unstable_data","steps","submittedFeedback","isOptimistic","custom","Record","convertDataPrefixedPart","startsWith","undefined","name","substring","fromThreadMessageLike","like","fallbackId","fallbackStatus","common","const","text","sanitizeImageContent","image","rest","dataUri","match","test","console","warn","length","Error","map","part","trim","basePart","commonProps","JSON","stringify","converted","filter","c","att","unsupportedRole"],"sources":["../../../src/runtime/utils/thread-message-like.ts"],"sourcesContent":["import { parsePartialJsonObject } from \"assistant-stream/utils\";\nimport { generateId } from \"../../utils/id\";\nimport type {\n ReasoningMessagePart,\n SourceMessagePart,\n ThreadStep,\n MessageStatus,\n ImageMessagePart,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadAssistantMessage,\n ThreadUserMessagePart,\n ThreadUserMessage,\n ThreadSystemMessage,\n FileMessagePart,\n DataMessagePart,\n GenerativeUIMessagePart,\n Unstable_AudioMessagePart,\n} from \"../../types/message\";\nimport type { CompleteAttachment } from \"../../types/attachment\";\nimport type {\n MessageTiming,\n PartProviderMetadata,\n TextMessagePart,\n ToolApprovalOption,\n ToolCallTiming,\n} from \"../../types/message\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\n\ntype DataPrefixedPart = {\n readonly type: `data-${string}`;\n readonly data: any;\n};\n\nexport type ThreadMessageLike = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly content:\n | string\n | readonly (\n | TextMessagePart\n | ReasoningMessagePart\n | SourceMessagePart\n | ImageMessagePart\n | FileMessagePart\n | DataMessagePart\n | GenerativeUIMessagePart\n | Unstable_AudioMessagePart\n | DataPrefixedPart\n | {\n readonly type: \"tool-call\";\n readonly toolCallId?: string;\n readonly toolName: string;\n readonly args?: ReadonlyJSONObject;\n readonly argsText?: string;\n readonly artifact?: any;\n readonly result?: any | undefined;\n readonly isError?: boolean | undefined;\n readonly parentId?: string | undefined;\n readonly messages?: readonly ThreadMessage[] | undefined;\n readonly interrupt?: { type: \"human\"; payload: unknown };\n readonly timing?: ToolCallTiming;\n readonly providerMetadata?: PartProviderMetadata;\n readonly approval?: {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n readonly options?: readonly ToolApprovalOption[];\n readonly optionId?: string;\n readonly resolution?: \"cancelled\" | \"expired\";\n };\n }\n )[];\n readonly id?: string | undefined;\n readonly createdAt?: Date | undefined;\n readonly status?: MessageStatus | undefined;\n readonly attachments?:\n | readonly (Omit<CompleteAttachment, \"content\"> & {\n readonly content: readonly (ThreadUserMessagePart | DataPrefixedPart)[];\n })[]\n | undefined;\n readonly metadata?:\n | {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations?:\n | readonly ReadonlyJSONValue[]\n | undefined;\n readonly unstable_data?: readonly ReadonlyJSONValue[] | undefined;\n readonly steps?: readonly ThreadStep[] | undefined;\n readonly timing?: MessageTiming | undefined;\n readonly submittedFeedback?: { readonly type: \"positive\" | \"negative\" };\n readonly isOptimistic?: boolean | undefined;\n readonly custom?: Record<string, unknown> | undefined;\n }\n | undefined;\n};\n\nconst convertDataPrefixedPart = (\n type: string,\n data: unknown,\n): DataMessagePart | undefined => {\n if (!type.startsWith(\"data-\")) return undefined;\n return { type: \"data\", name: type.substring(5), data };\n};\n\n/**\n * @deprecated This API is experimental and may change without notice.\n */\nexport const fromThreadMessageLike = (\n like: ThreadMessageLike,\n fallbackId: string,\n fallbackStatus: MessageStatus,\n): ThreadMessage => {\n const { role, id, createdAt, attachments, status, metadata } = like;\n const common = {\n id: id ?? fallbackId,\n createdAt: createdAt ?? new Date(),\n };\n\n const content =\n typeof like.content === \"string\"\n ? [{ type: \"text\" as const, text: like.content }]\n : like.content;\n\n const sanitizeImageContent = ({\n image,\n ...rest\n }: ImageMessagePart): ImageMessagePart | null => {\n if (typeof image !== \"string\") return null;\n const dataUri = image.match(\n /^data:image\\/(png|jpeg|jpg|gif|webp|svg\\+xml);base64,(.*)$/i,\n );\n if (dataUri) {\n return { ...rest, image };\n }\n if (/^(https:\\/\\/|blob:)/i.test(image)) {\n return { ...rest, image };\n }\n console.warn(`Invalid image data format detected`);\n return null;\n };\n\n if (role !== \"user\" && attachments?.length)\n throw new Error(\"attachments are only supported for user messages\");\n\n if (role !== \"assistant\" && status)\n throw new Error(\"status is only supported for assistant messages\");\n\n if (role !== \"assistant\" && metadata?.steps)\n throw new Error(\"metadata.steps is only supported for assistant messages\");\n\n switch (role) {\n case \"assistant\":\n return {\n ...common,\n role,\n content: content\n .map((part): ThreadAssistantMessagePart | null => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"reasoning\":\n if (!part.text?.trim()) return null;\n return part;\n\n case \"file\":\n case \"source\":\n return part;\n\n case \"image\":\n return sanitizeImageContent(part);\n\n case \"data\":\n return part;\n\n case \"generative-ui\":\n return part;\n\n case \"tool-call\": {\n const { parentId, messages, ...basePart } = part;\n const commonProps = {\n ...basePart,\n toolCallId: part.toolCallId ?? `tool-${generateId()}`,\n ...(parentId !== undefined && { parentId }),\n ...(messages !== undefined && { messages }),\n };\n\n if (part.args) {\n return {\n ...commonProps,\n args: part.args,\n argsText: part.argsText ?? JSON.stringify(part.args),\n };\n }\n return {\n ...commonProps,\n args: parsePartialJsonObject(part.argsText ?? \"\") ?? {},\n argsText: part.argsText ?? \"\",\n };\n }\n\n default: {\n const converted = convertDataPrefixedPart(\n type,\n (part as DataPrefixedPart).data,\n );\n if (converted) return converted;\n throw new Error(\n `Unsupported assistant message part type: ${type}`,\n );\n }\n }\n })\n .filter((c) => !!c),\n status: status ?? fallbackStatus,\n metadata: {\n unstable_state: metadata?.unstable_state ?? null,\n unstable_annotations: metadata?.unstable_annotations ?? [],\n unstable_data: metadata?.unstable_data ?? [],\n custom: metadata?.custom ?? {},\n steps: metadata?.steps ?? [],\n ...(metadata?.timing && { timing: metadata.timing }),\n ...(metadata?.submittedFeedback && {\n submittedFeedback: metadata.submittedFeedback,\n }),\n ...(metadata?.isOptimistic && { isOptimistic: true }),\n },\n } satisfies ThreadAssistantMessage;\n\n case \"user\":\n return {\n ...common,\n role,\n content: content.map((part): ThreadUserMessagePart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"image\":\n case \"audio\":\n case \"file\":\n case \"data\":\n return part;\n\n default: {\n const converted = convertDataPrefixedPart(\n type,\n (part as DataPrefixedPart).data,\n );\n if (converted) return converted;\n throw new Error(`Unsupported user message part type: ${type}`);\n }\n }\n }),\n attachments: (attachments ?? []).map((att) => ({\n ...att,\n content: att.content.map((part): ThreadUserMessagePart => {\n const converted = convertDataPrefixedPart(\n part.type,\n (part as DataPrefixedPart).data,\n );\n return converted ?? (part as ThreadUserMessagePart);\n }),\n })),\n metadata: {\n custom: metadata?.custom ?? {},\n ...(metadata?.isOptimistic && { isOptimistic: true }),\n },\n } satisfies ThreadUserMessage;\n\n case \"system\":\n if (content.length !== 1 || content[0]!.type !== \"text\")\n throw new Error(\n \"System messages must have exactly one text message part.\",\n );\n\n return {\n ...common,\n role,\n content: content as [TextMessagePart],\n metadata: {\n custom: metadata?.custom ?? {},\n },\n } satisfies ThreadSystemMessage;\n\n default: {\n const unsupportedRole: never = role;\n throw new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AAUM,gBAAgB,EAAEA,cAAc,KAAK;GACrD;EACF;EAEF,KAAK,QACH,OAAO;GACL,GAAGY;GACH9C;GACAC,SAASA,QAAQ0D,KAAKC,SAAgC;IACpD,MAAM/D,OAAO+D,KAAK/D;IAClB,QAAQA,MAAR;KACE,KAAK;KACL,KAAK;KACL,KAAK;KACL,KAAK;KACL,KAAK,QACH,OAAO+D;KAET,SAAS;MACP,MAAMM,YAAY7B,wBAChBxC,MACC+D,KAA0B9D,IAC7B;MACA,IAAIoE,WAAW,OAAOA;MACtB,MAAM,IAAIR,MAAM,uCAAuC7D,MAAM;KAC/D;IACF;GACF,CAAC;GACD6B,cAAcA,eAAe,CAAA,EAAA,CAAIiC,KAAKU,SAAS;IAC7C,GAAGA;IACHpE,SAASoE,IAAIpE,QAAQ0D,KAAKC,SAAgC;KAKxD,OAJkBvB,wBAChBuB,KAAK/D,MACJ+D,KAA0B9D,IAEtBoE,KAAcN;IACvB,CAAC;GACH,EAAE;GACFhC,UAAU;IACRO,QAAQP,UAAUO,UAAU,CAAC;IAC7B,GAAIP,UAAUM,gBAAgB,EAAEA,cAAc,KAAK;GACrD;EACF;EAEF,KAAK;GACH,IAAIjC,QAAQwD,WAAW,KAAKxD,QAAQ,EAAE,CAAEJ,SAAS,QAC/C,MAAM,IAAI6D,MACR,0DACF;GAEF,OAAO;IACL,GAAGZ;IACH9C;IACSC;IACT2B,UAAU,EACRO,QAAQP,UAAUO,UAAU,CAAC,EAC/B;GACF;EAEF,SAEE,MAAM,IAAIuB,MAAM,yBAAyBY,MAAiB;CAE9D;AACF"}
|
|
@@ -62,10 +62,11 @@ type RemoteThreadListOptions = {
|
|
|
62
62
|
*/
|
|
63
63
|
threadId?: string | undefined;
|
|
64
64
|
/**
|
|
65
|
-
* Called whenever the active thread's canonical (remote)
|
|
66
|
-
* value can be treated as a managed/controlled variable (e.g.
|
|
67
|
-
* URL query param).
|
|
68
|
-
*
|
|
65
|
+
* Called whenever the runtime changes the active thread's canonical (remote)
|
|
66
|
+
* ID, so the value can be treated as a managed/controlled variable (e.g.
|
|
67
|
+
* synced to a URL query param). Changes initiated by the controlled
|
|
68
|
+
* `threadId` option are not echoed back. Together these options form the
|
|
69
|
+
* controlled pattern: `threadId` in, `onThreadIdChange` out.
|
|
69
70
|
*
|
|
70
71
|
* Only the settled remote ID is emitted: while a freshly created thread is
|
|
71
72
|
* still optimistic (no remote ID yet) the value is `undefined`, and the real
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/runtimes/remote-thread-list/types.ts"],"mappings":";;;;;KAKY;EACV;EACA;;KAGU;WACD;WACA;WACA;WACA;WACA,gBAAgB;WAChB,SAAS;;KAGR;EACV,SAAS;EACT;;KAGU;EACV;;KAGU;EACV,KAAK,SAAS,8BAA8B,QAAQ;EAEpD,OAAO,kBAAkB,mBAAmB;EAC5C,cACE,kBACA,QAAQ,sCACP;EACH,QAAQ,mBAAmB;EAC3B,UAAU,mBAAmB;EAC7B,OAAO,mBAAmB;EAC1B,WAAW,mBAAmB,QAAQ;EACtC,cACE,kBACA,4BAA4B,kBAC3B,QAAQ;EACX,MAAM,mBAAmB,QAAQ;;;;;;;;;;;EAYjC,oBAAoB,cAAc;;KAGxB;EACV,mBAAmB;EACnB,SAAS;;;;;;;;EAST;;;;;;EAOA
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/runtimes/remote-thread-list/types.ts"],"mappings":";;;;;KAKY;EACV;EACA;;KAGU;WACD;WACA;WACA;WACA;WACA,gBAAgB;WAChB,SAAS;;KAGR;EACV,SAAS;EACT;;KAGU;EACV;;KAGU;EACV,KAAK,SAAS,8BAA8B,QAAQ;EAEpD,OAAO,kBAAkB,mBAAmB;EAC5C,cACE,kBACA,QAAQ,sCACP;EACH,QAAQ,mBAAmB;EAC3B,UAAU,mBAAmB;EAC7B,OAAO,mBAAmB;EAC1B,WAAW,mBAAmB,QAAQ;EACtC,cACE,kBACA,4BAA4B,kBAC3B,QAAQ;EACX,MAAM,mBAAmB,QAAQ;;;;;;;;;;;EAYjC,oBAAoB,cAAc;;KAGxB;EACV,mBAAmB;EACnB,SAAS;;;;;;;;EAST;;;;;;EAOA;;;;;;;;;;;;;EAcA,qBAAqB;;;;;;EAOrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain-of-thought-client.d.ts","names":[],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"chain-of-thought-client.d.ts","names":[],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"mappings":";;;;cAmCa,kDAAoB,SAAA;EArBxB,gBAAS;EACA,iBAAC;IAAY;QAAoB"}
|
|
@@ -1,44 +1,50 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getGroupStatus } from "../../utils/getGroupStatus.js";
|
|
2
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { useState } from "@assistant-ui/tap/react-shim";
|
|
3
4
|
import { resource } from "@assistant-ui/tap";
|
|
4
5
|
//#region src/store/clients/chain-of-thought-client.ts
|
|
5
|
-
const COMPLETE_STATUS = Object.freeze({ type: "complete" });
|
|
6
6
|
const useChainOfThoughtClient = (t0) => {
|
|
7
|
-
const $ = c(
|
|
7
|
+
const $ = c(11);
|
|
8
8
|
const { parts, getMessagePart } = t0;
|
|
9
9
|
const [collapsed, setCollapsed] = useState(true);
|
|
10
|
-
const status = parts[parts.length - 1]?.status ?? COMPLETE_STATUS;
|
|
11
10
|
let t1;
|
|
12
|
-
if ($[0] !==
|
|
13
|
-
t1 =
|
|
11
|
+
if ($[0] !== parts) {
|
|
12
|
+
t1 = getGroupStatus(parts);
|
|
13
|
+
$[0] = parts;
|
|
14
|
+
$[1] = t1;
|
|
15
|
+
} else t1 = $[1];
|
|
16
|
+
const status = t1;
|
|
17
|
+
let t2;
|
|
18
|
+
if ($[2] !== collapsed || $[3] !== parts || $[4] !== status) {
|
|
19
|
+
t2 = {
|
|
14
20
|
parts,
|
|
15
21
|
collapsed,
|
|
16
22
|
status
|
|
17
23
|
};
|
|
18
|
-
$[
|
|
19
|
-
$[
|
|
20
|
-
$[
|
|
21
|
-
$[3] = t1;
|
|
22
|
-
} else t1 = $[3];
|
|
23
|
-
const state = t1;
|
|
24
|
-
let t2;
|
|
25
|
-
if ($[4] !== state) {
|
|
26
|
-
t2 = () => state;
|
|
27
|
-
$[4] = state;
|
|
24
|
+
$[2] = collapsed;
|
|
25
|
+
$[3] = parts;
|
|
26
|
+
$[4] = status;
|
|
28
27
|
$[5] = t2;
|
|
29
28
|
} else t2 = $[5];
|
|
29
|
+
const state = t2;
|
|
30
30
|
let t3;
|
|
31
|
-
if ($[6] !==
|
|
32
|
-
t3 =
|
|
33
|
-
|
|
31
|
+
if ($[6] !== state) {
|
|
32
|
+
t3 = () => state;
|
|
33
|
+
$[6] = state;
|
|
34
|
+
$[7] = t3;
|
|
35
|
+
} else t3 = $[7];
|
|
36
|
+
let t4;
|
|
37
|
+
if ($[8] !== getMessagePart || $[9] !== t3) {
|
|
38
|
+
t4 = {
|
|
39
|
+
getState: t3,
|
|
34
40
|
setCollapsed,
|
|
35
41
|
part: getMessagePart
|
|
36
42
|
};
|
|
37
|
-
$[
|
|
38
|
-
$[
|
|
39
|
-
$[
|
|
40
|
-
} else
|
|
41
|
-
return
|
|
43
|
+
$[8] = getMessagePart;
|
|
44
|
+
$[9] = t3;
|
|
45
|
+
$[10] = t4;
|
|
46
|
+
} else t4 = $[10];
|
|
47
|
+
return t4;
|
|
42
48
|
};
|
|
43
49
|
const ChainOfThoughtClient = resource(useChainOfThoughtClient);
|
|
44
50
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain-of-thought-client.js","names":["useMemo","useState","resource","ClientOutput","ChainOfThoughtState","ChainOfThoughtPart","
|
|
1
|
+
{"version":3,"file":"chain-of-thought-client.js","names":["useMemo","useState","resource","ClientOutput","ChainOfThoughtState","ChainOfThoughtPart","PartMethods","getGroupStatus","useChainOfThoughtClient","t0","$","_c","parts","getMessagePart","collapsed","setCollapsed","t1","status","t2","state","t3","t4","getState","part","ChainOfThoughtClient"],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"sourcesContent":["import { useMemo, useState } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type {\n ChainOfThoughtState,\n ChainOfThoughtPart,\n} from \"../scopes/chain-of-thought\";\nimport type { PartMethods } from \"../scopes/part\";\nimport { getGroupStatus } from \"../../utils/getGroupStatus\";\n\nconst useChainOfThoughtClient = ({\n parts,\n getMessagePart,\n}: {\n parts: readonly ChainOfThoughtPart[];\n getMessagePart: (selector: { index: number }) => PartMethods;\n}): ClientOutput<\"chainOfThought\"> => {\n const [collapsed, setCollapsed] = useState(true);\n\n const status = useMemo(() => {\n return getGroupStatus(parts);\n }, [parts]);\n\n const state = useMemo<ChainOfThoughtState>(\n () => ({ parts, collapsed, status }),\n [parts, collapsed, status],\n );\n\n return {\n getState: () => state,\n setCollapsed,\n part: getMessagePart,\n };\n};\n\nexport const ChainOfThoughtClient = resource(useChainOfThoughtClient);\n"],"mappings":";;;;;AAUA,MAAMQ,2BAA0BC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAC,MAAA,EAAAC,OAAAC,mBAAAJ;CAO/B,MAAA,CAAAK,WAAAC,gBAAkCd,SAAS,IAAI;CAAE,IAAAe;CAAA,IAAAN,EAAA,OAAAE,OAAA;EAGxCI,KAAAT,eAAeK,KAAK;EAACF,EAAA,KAAAE;EAAAF,EAAA,KAAAM;CAAA,OAAAA,KAAAN,EAAA;CAD9B,MAAAO,SACED;CACU,IAAAE;CAAA,IAAAR,EAAA,OAAAI,aAAAJ,EAAA,OAAAE,SAAAF,EAAA,OAAAO,QAAA;EAGHC,KAAA;GAAAN;GAAAE;GAAAG;EAA2B;EAACP,EAAA,KAAAI;EAAAJ,EAAA,KAAAE;EAAAF,EAAA,KAAAO;EAAAP,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CADrC,MAAAS,QACSD;CAEP,IAAAE;CAAA,IAAAV,EAAA,OAAAS,OAAA;EAGUC,WAAMD;EAAKT,EAAA,KAAAS;EAAAT,EAAA,KAAAU;CAAA,OAAAA,KAAAV,EAAA;CAAA,IAAAW;CAAA,IAAAX,EAAA,OAAAG,kBAAAH,EAAA,OAAAU,IAAA;EADhBC,KAAA;GAAAC,UACKF;GAAWL;GAAAQ,MAEfV;EACR;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAU;EAAAV,EAAA,MAAAW;CAAA,OAAAA,KAAAX,EAAA;CAAA,OAJMW;AAIN;AAGH,MAAaG,uBAAuBtB,SAASM,uBAAuB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CompositeContextProvider } from "../../utils/composite-context-provider.js";
|
|
2
|
-
import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
3
2
|
import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
|
|
3
|
+
import { useEffect, useState } from "@assistant-ui/tap/react-shim";
|
|
4
4
|
import { resource } from "@assistant-ui/tap";
|
|
5
5
|
//#region src/store/clients/model-context-client.ts
|
|
6
6
|
const EMPTY_TOOL_NAMES = [];
|