@assistant-ui/core 0.3.3 → 0.3.5
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/internal.d.ts +4 -2
- package/dist/internal.js +4 -2
- package/dist/react/primitive-hooks/useSuggestionTrigger.js +29 -25
- package/dist/react/primitive-hooks/useSuggestionTrigger.js.map +1 -1
- package/dist/react/primitives/message/MessageParts.d.ts +6 -1
- package/dist/react/primitives/message/MessageParts.d.ts.map +1 -1
- package/dist/react/primitives/message/MessageParts.js.map +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.d.ts.map +1 -1
- package/dist/react/providers/ReadonlyThreadProvider.js +1 -0
- package/dist/react/providers/ReadonlyThreadProvider.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts +67 -0
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js +76 -15
- package/dist/react/runtimes/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts +4 -0
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js +22 -1
- package/dist/react/runtimes/RemoteThreadListThreadListRuntimeCore.js.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.d.ts +2 -0
- package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
- package/dist/react/runtimes/cloud/auiV0.js +6 -4
- package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
- package/dist/react/types/MessagePartComponentTypes.d.ts +8 -0
- package/dist/react/types/MessagePartComponentTypes.d.ts.map +1 -1
- package/dist/runtime/api/bindings.d.ts +5 -0
- package/dist/runtime/api/bindings.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.d.ts +14 -1
- package/dist/runtime/api/thread-list-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-list-runtime.js +6 -1
- package/dist/runtime/api/thread-list-runtime.js.map +1 -1
- package/dist/runtime/api/thread-runtime.d.ts +7 -1
- package/dist/runtime/api/thread-runtime.d.ts.map +1 -1
- package/dist/runtime/api/thread-runtime.js +11 -3
- package/dist/runtime/api/thread-runtime.js.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.d.ts +3 -0
- package/dist/runtime/base/base-composer-runtime-core.d.ts.map +1 -1
- package/dist/runtime/base/base-composer-runtime-core.js +54 -12
- package/dist/runtime/base/base-composer-runtime-core.js.map +1 -1
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts +10 -0
- package/dist/runtime/interfaces/thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtime/interfaces/thread-runtime-core.d.ts +14 -0
- package/dist/runtime/interfaces/thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-adapter.d.ts +9 -0
- package/dist/runtimes/external-store/external-store-adapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts +1 -0
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js +4 -0
- package/dist/runtimes/external-store/external-store-thread-list-runtime-core.js.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts +1 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js +6 -0
- package/dist/runtimes/external-store/external-store-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.d.ts +1 -0
- package/dist/runtimes/local/local-thread-runtime-core.d.ts.map +1 -1
- package/dist/runtimes/local/local-thread-runtime-core.js +1 -0
- package/dist/runtimes/local/local-thread-runtime-core.js.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts +1 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js +1 -0
- package/dist/runtimes/readonly/ReadonlyThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/remote-thread-list/empty-thread-core.js +1 -0
- package/dist/runtimes/remote-thread-list/empty-thread-core.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts +1 -0
- package/dist/store/runtime-clients/thread-list-item-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js +66 -45
- package/dist/store/runtime-clients/thread-list-item-runtime-client.js.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.d.ts.map +1 -1
- package/dist/store/runtime-clients/thread-list-runtime-client.js +91 -75
- package/dist/store/runtime-clients/thread-list-runtime-client.js.map +1 -1
- package/dist/store/scopes/thread-list-item.d.ts +7 -0
- package/dist/store/scopes/thread-list-item.d.ts.map +1 -1
- package/dist/store/scopes/threads.d.ts +1 -0
- package/dist/store/scopes/threads.d.ts.map +1 -1
- package/dist/types/message.d.ts +11 -0
- package/dist/types/message.d.ts.map +1 -1
- package/dist/types/message.js.map +1 -1
- package/dist/utils/data-url.d.ts +14 -1
- package/dist/utils/data-url.d.ts.map +1 -1
- package/dist/utils/data-url.js +23 -1
- package/dist/utils/data-url.js.map +1 -1
- package/dist/utils/image-media-type.d.ts +13 -0
- package/dist/utils/image-media-type.d.ts.map +1 -0
- package/dist/utils/image-media-type.js +141 -0
- package/dist/utils/image-media-type.js.map +1 -0
- package/dist/utils/wire-media.d.ts +35 -0
- package/dist/utils/wire-media.d.ts.map +1 -0
- package/dist/utils/wire-media.js +55 -0
- package/dist/utils/wire-media.js.map +1 -0
- package/package.json +4 -4
- package/src/internal.ts +12 -1
- package/src/react/primitive-hooks/useSuggestionTrigger.test.ts +148 -0
- package/src/react/primitive-hooks/useSuggestionTrigger.ts +10 -4
- package/src/react/primitives/message/MessageParts.tsx +6 -1
- package/src/react/providers/ReadonlyThreadProvider.tsx +1 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.running.test.tsx +157 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.test.tsx +160 -0
- package/src/react/runtimes/RemoteThreadListHookInstanceManager.tsx +135 -32
- package/src/react/runtimes/RemoteThreadListThreadListRuntimeCore.tsx +41 -1
- package/src/react/runtimes/cloud/auiV0.ts +8 -2
- package/src/react/types/MessagePartComponentTypes.ts +8 -0
- package/src/runtime/api/bindings.ts +5 -0
- package/src/runtime/api/thread-list-runtime.ts +22 -1
- package/src/runtime/api/thread-runtime.ts +15 -6
- package/src/runtime/base/base-composer-runtime-core.ts +72 -19
- package/src/runtime/interfaces/thread-list-runtime-core.ts +11 -0
- package/src/runtime/interfaces/thread-runtime-core.ts +15 -0
- package/src/runtimes/external-store/external-store-adapter.ts +9 -0
- package/src/runtimes/external-store/external-store-thread-list-runtime-core.ts +9 -0
- package/src/runtimes/external-store/external-store-thread-runtime-core.ts +8 -0
- package/src/runtimes/local/local-thread-runtime-core.ts +1 -0
- package/src/runtimes/readonly/ReadonlyThreadRuntimeCore.ts +1 -0
- package/src/runtimes/remote-thread-list/empty-thread-core.ts +1 -0
- package/src/store/runtime-clients/thread-list-item-runtime-client.ts +13 -2
- package/src/store/runtime-clients/thread-list-runtime-client.ts +13 -1
- package/src/store/scopes/thread-list-item.ts +7 -0
- package/src/store/scopes/threads.ts +1 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-reloadMainThread.test.ts +257 -0
- package/src/tests/RemoteThreadListThreadListRuntimeCore-switchToThread-order.test.ts +31 -0
- package/src/tests/auiV0Encode.test.ts +125 -1
- package/src/tests/base-composer-runtime-core-addAttachment.test.ts +296 -0
- package/src/tests/event-subscription-listener-errors.test.ts +1 -0
- package/src/tests/external-store-thread-list-runtime-core.test.ts +39 -1
- package/src/types/message.ts +11 -0
- package/src/utils/data-url.ts +24 -0
- package/src/utils/image-media-type.test.ts +96 -0
- package/src/utils/image-media-type.ts +118 -0
- package/src/utils/wire-media.test.ts +96 -0
- package/src/utils/wire-media.ts +70 -0
|
@@ -1 +1 @@
|
|
|
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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5B,SACL,EAAEA,QAAQ4B,KAAK5B,OAA4B,IAC3C6B,KAAAA;MACJ,GAAID,KAAK3B,UAAU,EAAEA,SAAS,KAAK,IAAI4B,KAAAA;MACvC,GAAID,KAAK1B,WAAW,EAAEA,UAAU0B,KAAK1B,SAAS,IAAI2B,KAAAA;KACpD;IAGF,KAAK,SACH,OAAO;KAAExC,MAAM;KAASe,OAAOwB,KAAKxB;IAAM;IAE5C,KAAK,QACH,OAAO;KACLf,MAAM;KACNgB,MAAMuB,KAAKvB;KACXC,UAAUsB,KAAKtB;KACf,GAAIsB,KAAKhC,WAAW,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;IACpD;IAEF,SAEE,MAAM,IAAIM,MACR,8CAA8CD,MAChD;GAEJ;EACF,CAAC;EACDhB,UAAUmB,QAAQnB;EAClB,GAAIL,SAAS,EAAEA,OAAO,IAAIgB,KAAAA;EAC1B,GAAIZ,cAAc,EAAEA,YAAY,IAAIY,KAAAA;CACtC;AACF;AAEA,SAAgBY,YACdC,cAC+B;CAC/B,MAAMC,UAAUD,aAAa5B;CAC7B,MAAMuB,UAAU/D,sBACd;EACEO,IAAI6D,aAAa7D;EACjB+D,WAAWF,aAAaG;EACxB,GAAGF;CACL,GACAD,aAAa7D,IACb;EAAEQ,MAAM;EAAYN,QAAQ;CAAU,CACxC;CAEA,OAAO;EACL+D,UAAUJ,aAAaK;EACvBV;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 readonly sourceType?: \"url\" | \"id\";\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 readonly sourceType?: \"url\" | \"id\";\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 ...(part.sourceType != null\n ? { sourceType: part.sourceType }\n : 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 (part.result !== undefined && !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 !== undefined\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 ...(part.sourceType ? { sourceType: part.sourceType } : 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":";;;AA4IA,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,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,EAAEA,UAAU0B,KAAK1B,SAAS,IAAI2B,KAAAA;KACpD;IAGF,KAAK,SACH,OAAO;KAAExC,MAAM;KAASe,OAAOwB,KAAKxB;IAAM;IAE5C,KAAK,QACH,OAAO;KACLf,MAAM;KACNgB,MAAMuB,KAAKvB;KACXC,UAAUsB,KAAKtB;KACf,GAAIsB,KAAKhC,WAAW,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;KAClD,GAAID,KAAKrC,aAAa,EAAEA,YAAYqC,KAAKrC,WAAW,IAAIsC,KAAAA;IAC1D;IAEF,SAEE,MAAM,IAAIM,MACR,8CAA8CD,MAChD;GAEJ;EACF,CAAC;EACDhB,UAAUmB,QAAQnB;EAClB,GAAIL,SAAS,EAAEA,OAAO,IAAIgB,KAAAA;EAC1B,GAAIZ,cAAc,EAAEA,YAAY,IAAIY,KAAAA;CACtC;AACF;AAEA,SAAgBY,YACdC,cAC+B;CAC/B,MAAMC,UAAUD,aAAa5B;CAC7B,MAAMuB,UAAU/D,sBACd;EACEO,IAAI6D,aAAa7D;EACjB+D,WAAWF,aAAaG;EACxB,GAAGF;CACL,GACAD,aAAa7D,IACb;EAAEQ,MAAM;EAAYN,QAAQ;CAAU,CACxC;CAEA,OAAO;EACL+D,UAAUJ,aAAaK;EACvBV;CACF;AACF"}
|
|
@@ -24,7 +24,15 @@ type ImageMessagePartProps = MessagePartState & ImageMessagePart;
|
|
|
24
24
|
type ImageMessagePartComponent = ComponentType<ImageMessagePartProps>;
|
|
25
25
|
type FileMessagePartProps = MessagePartState & FileMessagePart;
|
|
26
26
|
type FileMessagePartComponent = ComponentType<FileMessagePartProps>;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use {@link FileMessagePartProps} and render `audio/*` mime types
|
|
29
|
+
* from the `File` slot.
|
|
30
|
+
*/
|
|
27
31
|
type Unstable_AudioMessagePartProps = MessagePartState & Unstable_AudioMessagePart;
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use {@link FileMessagePartComponent} and render `audio/*` mime
|
|
34
|
+
* types from the `File` slot.
|
|
35
|
+
*/
|
|
28
36
|
type Unstable_AudioMessagePartComponent = ComponentType<Unstable_AudioMessagePartProps>;
|
|
29
37
|
type DataMessagePartProps<T = any> = MessagePartState & DataMessagePart<T>;
|
|
30
38
|
type DataMessagePartComponent<T = any> = ComponentType<DataMessagePartProps<T>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessagePartComponentTypes.d.ts","names":[],"sources":["../../../src/react/types/MessagePartComponentTypes.ts"],"mappings":";;;;;;;KAmBY;EACV,QAAQ;;KAEE,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;KAEzC,4BAA4B,mBAAmB;KAC/C,gCACV,cAAc;KAEJ,sBAAsB;EAChC;EACA;;KAEU,0BAA0B,cAAc;KAExC,yBAAyB,mBAAmB;KAC5C,6BAA6B,cAAc;KAE3C,wBAAwB,mBAAmB;KAC3C,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc
|
|
1
|
+
{"version":3,"file":"MessagePartComponentTypes.d.ts","names":[],"sources":["../../../src/react/types/MessagePartComponentTypes.ts"],"mappings":";;;;;;;KAmBY;EACV,QAAQ;;KAEE,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;KAEzC,4BAA4B,mBAAmB;KAC/C,gCACV,cAAc;KAEJ,sBAAsB;EAChC;EACA;;KAEU,0BAA0B,cAAc;KAExC,yBAAyB,mBAAmB;KAC5C,6BAA6B,cAAc;KAE3C,wBAAwB,mBAAmB;KAC3C,4BAA4B,cAAc;KAE1C,uBAAuB,mBAAmB;KAC1C,2BAA2B,cAAc;;;;;KAMzC,iCAAiC,mBAC3C;;;;;KAKU,qCACV,cAAc;KAEJ,qBAAqB,WAAW,mBAC1C,gBAAgB;KACN,yBAAyB,WAAW,cAC9C,qBAAqB;KAGX,yBACV,aACA,qBACE,mBACF,oBAAoB,OAAO;;;;;;;EAOzB,YAAY,QAAQ,UAAU,aAAa;;;;;EAK3C,SAAS;;;;;;;EAOT,oBAAoB,UAAU;;;KAItB,6BACV,aACA,iBACE,cAAc,yBAAyB,OAAO;KAEtC,wBAAwB;KACxB,4BAA4B,cAAc;;;;;;;;;KAU1C,gCAAgC,eAAe;KAE/C,+BAA+B,mBACzC;KACU,mCACV,cAAc;KAEJ;;EAEV,MAAM;;EAEN,YAAY;;EAEZ,WAAW;IAAgB;IAAmB"}
|
|
@@ -22,6 +22,11 @@ type MessageStateBinding = SubscribableWithState<ThreadMessage & {
|
|
|
22
22
|
}, MessageRuntimePath>;
|
|
23
23
|
type ThreadListItemState = {
|
|
24
24
|
readonly isMain: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether this thread has a run in progress, including a run that continues
|
|
27
|
+
* after the user switches to another thread.
|
|
28
|
+
*/
|
|
29
|
+
readonly isRunning: boolean;
|
|
25
30
|
readonly id: string;
|
|
26
31
|
readonly remoteId: string | undefined;
|
|
27
32
|
readonly externalId: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bindings.d.ts","names":[],"sources":["../../../src/runtime/api/bindings.ts"],"mappings":";;;;;;;KAUY,6BAA6B,sBACvC,iCACA;KAGU,mCAAmC,sBAC7C,uCACA;EAAwB;;KAGd,iCAAiC,sBAC3C,qCACA;EAAwB;;KAGd,sBAAsB,sBAChC;WACW;WACA;WACA;WACA;WACA;WACA,QAAQ;GAEnB;KAGU;WACD;WACA;WACA;WACA;WACA,
|
|
1
|
+
{"version":3,"file":"bindings.d.ts","names":[],"sources":["../../../src/runtime/api/bindings.ts"],"mappings":";;;;;;;KAUY,6BAA6B,sBACvC,iCACA;KAGU,mCAAmC,sBAC7C,uCACA;EAAwB;;KAGd,iCAAiC,sBAC3C,qCACA;EAAwB;;KAGd,sBAAsB,sBAChC;WACW;WACA;WACA;WACA;WACA;WACA,QAAQ;GAEnB;KAGU;WACD;;;;;WAKA;WACA;WACA;WACA;WACA,QAVC;WAWD;WACA,gBAAgB;WAChB,SAAS"}
|
|
@@ -12,7 +12,7 @@ type ThreadListState = {
|
|
|
12
12
|
readonly isLoading: boolean;
|
|
13
13
|
readonly isLoadingMore: boolean;
|
|
14
14
|
readonly hasMore: boolean;
|
|
15
|
-
readonly threadItems: Readonly<Record<string, Omit<ThreadListItemState, "isMain" | "threadId">>>;
|
|
15
|
+
readonly threadItems: Readonly<Record<string, Omit<ThreadListItemState, "isMain" | "threadId" | "isRunning">>>;
|
|
16
16
|
};
|
|
17
17
|
type ThreadListRuntime = {
|
|
18
18
|
getState(): ThreadListState;
|
|
@@ -29,6 +29,18 @@ type ThreadListRuntime = {
|
|
|
29
29
|
switchToNewThread(): Promise<void>;
|
|
30
30
|
getLoadThreadsPromise(): Promise<void>;
|
|
31
31
|
reload(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Refetches the open thread's remote state, for state that changed out of
|
|
34
|
+
* band and so never reached the stream. When the runtime declares the
|
|
35
|
+
* in-place capability (`unstable_refetchThread`), composer drafts survive,
|
|
36
|
+
* existing messages stay rendered during the refetch, and the promise
|
|
37
|
+
* settles with the refetch, rejecting if it fails; that runtime also owns
|
|
38
|
+
* what happens to a run in progress, since this does not stop one. Runtimes
|
|
39
|
+
* without the capability have their hook remounted instead, which discards
|
|
40
|
+
* unsent composer input and ends any run, and the promise resolves once the
|
|
41
|
+
* new runtime attaches. A thread that has not been sent yet is left alone.
|
|
42
|
+
*/
|
|
43
|
+
reloadMainThread(): Promise<void>;
|
|
32
44
|
loadMore(): Promise<void>;
|
|
33
45
|
};
|
|
34
46
|
type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;
|
|
@@ -44,6 +56,7 @@ declare class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
|
44
56
|
switchToNewThread(): Promise<void>;
|
|
45
57
|
getLoadThreadsPromise(): Promise<void>;
|
|
46
58
|
reload(): Promise<void>;
|
|
59
|
+
reloadMainThread(): Promise<void>;
|
|
47
60
|
loadMore(): Promise<void>;
|
|
48
61
|
getState(): ThreadListState;
|
|
49
62
|
subscribe(callback: () => void): Unsubscribe;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;KAwBY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,aAAa,SACpB,
|
|
1
|
+
{"version":3,"file":"thread-list-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"mappings":";;;;;;KAwBY;WACD;WACA;WACA;WACA;WACA;WACA;WACA;WACA,aAAa,SACpB,eAEE,KAAK;;KAKC;EACV,YAAY;EAEZ,UAAU,uBAAuB;WAExB,MAAM;EACf,QAAQ,mBAAmB;WAElB,UAAU;EACnB,YAAY,mBAAmB;EAC/B,eAAe,cAAc;EAC7B,uBAAuB,cAAc;EAErC,eACE,kBACA;IAAY;MACX;EACH,qBAAqB;EAErB,yBAAyB;EACzB,UAAU;;;;;;;;;;;;EAYV,oBAAoB;EACpB,YAAY;;KAuCF,+BAA+B;cAE9B,iCAAiC;UACpC;UACA;UACA;EAMN,YAAA,OAAO,8BACP,uBACE,SAAS,0BACT,uBAAuB,iCACpB;YAyCG;EAeH,eACL,kBACA;IAAY;MACX;EAII,qBAAqB;EAIrB,yBAAyB;EAIzB,UAAU;EAIV,oBAAoB;EAIpB,YAAY;EAIZ,YAAY;EAIZ,UAAU,uBAAuB;UAIhC;WAEQ,MAAM;MAEX,YAAQ;EAIZ,QAAQ,mBAAgB;EAcxB,eAAe,cAAW;EAgB1B,uBAAuB,cAAW;EAmBlC,YAAY,mBAAgB"}
|
|
@@ -27,7 +27,8 @@ const getThreadListItemState = (threadList, threadId) => {
|
|
|
27
27
|
status: threadData.status,
|
|
28
28
|
lastMessageAt: threadData.lastMessageAt,
|
|
29
29
|
custom: threadData.custom,
|
|
30
|
-
isMain: threadData.id === threadList.mainThreadId
|
|
30
|
+
isMain: threadData.id === threadList.mainThreadId,
|
|
31
|
+
isRunning: threadList.unstable_isThreadRunning?.(threadData.id) ?? false
|
|
31
32
|
};
|
|
32
33
|
};
|
|
33
34
|
var ThreadListRuntimeImpl = class {
|
|
@@ -68,6 +69,7 @@ var ThreadListRuntimeImpl = class {
|
|
|
68
69
|
this.switchToNewThread = this.switchToNewThread.bind(this);
|
|
69
70
|
this.getLoadThreadsPromise = this.getLoadThreadsPromise.bind(this);
|
|
70
71
|
this.reload = this.reload.bind(this);
|
|
72
|
+
this.reloadMainThread = this.reloadMainThread.bind(this);
|
|
71
73
|
this.loadMore = this.loadMore.bind(this);
|
|
72
74
|
this.getState = this.getState.bind(this);
|
|
73
75
|
this.subscribe = this.subscribe.bind(this);
|
|
@@ -88,6 +90,9 @@ var ThreadListRuntimeImpl = class {
|
|
|
88
90
|
reload() {
|
|
89
91
|
return this._core.reload?.() ?? RESOLVED_PROMISE;
|
|
90
92
|
}
|
|
93
|
+
reloadMainThread() {
|
|
94
|
+
return this._core.reloadMainThread?.() ?? RESOLVED_PROMISE;
|
|
95
|
+
}
|
|
91
96
|
loadMore() {
|
|
92
97
|
return this._core.loadMore?.() ?? RESOLVED_PROMISE;
|
|
93
98
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-list-runtime.js","names":["Unsubscribe","LazyMemoizeSubject","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","ThreadListRuntimeCore","ThreadListItemRuntime","ThreadListItemRuntimeImpl","ThreadListItemState","ThreadListItemRuntimeBinding","ThreadRuntime","ThreadRuntimeCoreBinding","ThreadRuntimeImpl","RESOLVED_PROMISE","Promise","resolve","ThreadListState","mainThreadId","newThreadId","threadIds","archivedThreadIds","isLoading","isLoadingMore","hasMore","threadItems","Readonly","Record","Omit","ThreadListRuntime","getState","subscribe","callback","main","getById","threadId","mainItem","getItemById","getItemByIndex","idx","getArchivedItemByIndex","switchToThread","options","unarchive","switchToNewThread","getLoadThreadsPromise","reload","loadMore","getThreadListState","threadList","getThreadListItemState","undefined","threadData","id","remoteId","externalId","title","status","lastMessageAt","custom","isMain","ThreadListRuntimeCoreBinding","ThreadListRuntimeImpl","_getState","_core","_runtimeFactory","binding","threadListItemBinding","constructor","stateBinding","path","bind","_mainThreadListItemRuntime","ref","threadSelector","type","getMainThreadRuntimeCore","__internal_bindMethods","JSON","stringify","getThreadRuntimeCore","index"],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport {\n LazyMemoizeSubject,\n NestedSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport type { ThreadListRuntimeCore } from \"../interfaces/thread-list-runtime-core\";\nimport {\n type ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n type ThreadListItemState,\n} from \"./thread-list-item-runtime\";\nimport {\n type ThreadListItemRuntimeBinding,\n type ThreadRuntime,\n type ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./thread-runtime\";\n\nconst RESOLVED_PROMISE = Promise.resolve();\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly isLoading: boolean;\n readonly isLoadingMore: boolean;\n readonly hasMore: boolean;\n readonly threadItems: Readonly<\n Record<string, Omit<ThreadListItemState, \"isMain\" | \"threadId\">>\n >;\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void>;\n switchToNewThread(): Promise<void>;\n\n getLoadThreadsPromise(): Promise<void>;\n reload(): Promise<void>;\n loadMore(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThreadId: threadList.newThreadId,\n threadIds: threadList.threadIds,\n archivedThreadIds: threadList.archivedThreadIds,\n isLoading: threadList.isLoading,\n isLoadingMore: threadList.isLoadingMore ?? false,\n hasMore: threadList.hasMore ?? false,\n threadItems: threadList.threadItems,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.id,\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n lastMessageAt: threadData.lastMessageAt,\n custom: threadData.custom,\n isMain: threadData.id === threadList.mainThreadId,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n private _core: ThreadListRuntimeCoreBinding;\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime;\n\n constructor(\n _core: ThreadListRuntimeCoreBinding,\n _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n this._core = _core;\n this._runtimeFactory = _runtimeFactory;\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime,\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.getLoadThreadsPromise = this.getLoadThreadsPromise.bind(this);\n this.reload = this.reload.bind(this);\n this.loadMore = this.loadMore.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void> {\n return this._core.switchToThread(threadId, options);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return this._core.getLoadThreadsPromise();\n }\n\n public reload(): Promise<void> {\n return this._core.reload?.() ?? RESOLVED_PROMISE;\n }\n\n public loadMore(): Promise<void> {\n return this._core.loadMore?.() ?? RESOLVED_PROMISE;\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: `threads[threadId=${JSON.stringify(threadId)}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem,\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";;;;AAsBA,MAAMa,mBAAmBC,QAAQC,QAAQ;AAuCzC,MAAMgC,sBACJC,eACoB;CACpB,OAAO;EACL/B,cAAc+B,WAAW/B;EACzBC,aAAa8B,WAAW9B;EACxBC,WAAW6B,WAAW7B;EACtBC,mBAAmB4B,WAAW5B;EAC9BC,WAAW2B,WAAW3B;EACtBC,eAAe0B,WAAW1B,iBAAiB;EAC3CC,SAASyB,WAAWzB,WAAW;EAC/BC,aAAawB,WAAWxB;CAC1B;AACF;AAEA,MAAMyB,0BACJD,YACAd,aACsC;CACtC,IAAIA,aAAag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qBAAqB7C,QAAQ;GACxDJ,YAAYC,aAAa,KAAKgC,MAAMjC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKI,QACP;CACF;CAEA,eAAsBG,KAAa;EACjC,OAAO,IAAI/B,0BACT,IAAIH,sBAAsB;GACxBiE,MAAM;IACJG,KAAK,eAAelC,IAAG;IACvBmC,gBAAgB;KAAEC,MAAM;KAASM,OAAO1C;IAAI;GAC9C;GACAT,gBAAgB;IACd,OAAOoB,uBAAuB,KAAKc,OAAO,KAAKA,MAAM5C,UAAUmB,IAAI;GACrE;GACAR,YAAYC,aAAa,KAAKgC,MAAMjC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKgC,KACP;CACF;CAEA,uBAA8BzB,KAAa;EACzC,OAAO,IAAI/B,0BACT,IAAIH,sBAAsB;GACxBiE,MAAM;IACJG,KAAK,uBAAuBlC,IAAG;IAC/BmC,gBAAgB;KAAEC,MAAM;KAAgBM,OAAO1C;IAAI;GACrD;GACAT,gBAAgB;IACd,OAAOoB,uBACL,KAAKc,OACL,KAAKA,MAAM3C,kBAAkBkB,IAC/B;GACF;GACAR,YAAYC,aAAa,KAAKgC,MAAMjC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKgC,KACP;CACF;CAEA,YAAmB7B,UAAkB;EACnC,OAAO,IAAI3B,0BACT,IAAIH,sBAAsB;GACxBiE,MAAM;IACJG,KAAK,wBAAwBtC,SAAQ;IACrCuC,gBAAgB;KAAEC,MAAM;KAAYxC;IAAS;GAC/C;GACAL,gBAAgB;IACd,OAAOoB,uBAAuB,KAAKc,OAAO7B,QAAQ;GACpD;GACAJ,YAAYC,aAAa,KAAKgC,MAAMjC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKgC,KACP;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"thread-list-runtime.js","names":["Unsubscribe","LazyMemoizeSubject","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","ThreadListRuntimeCore","ThreadListItemRuntime","ThreadListItemRuntimeImpl","ThreadListItemState","ThreadListItemRuntimeBinding","ThreadRuntime","ThreadRuntimeCoreBinding","ThreadRuntimeImpl","RESOLVED_PROMISE","Promise","resolve","ThreadListState","mainThreadId","newThreadId","threadIds","archivedThreadIds","isLoading","isLoadingMore","hasMore","threadItems","Readonly","Record","Omit","ThreadListRuntime","getState","subscribe","callback","main","getById","threadId","mainItem","getItemById","getItemByIndex","idx","getArchivedItemByIndex","switchToThread","options","unarchive","switchToNewThread","getLoadThreadsPromise","reload","reloadMainThread","loadMore","getThreadListState","threadList","getThreadListItemState","undefined","threadData","id","remoteId","externalId","title","status","lastMessageAt","custom","isMain","isRunning","unstable_isThreadRunning","ThreadListRuntimeCoreBinding","ThreadListRuntimeImpl","_getState","_core","_runtimeFactory","binding","threadListItemBinding","constructor","stateBinding","path","bind","_mainThreadListItemRuntime","ref","threadSelector","type","getMainThreadRuntimeCore","__internal_bindMethods","JSON","stringify","getThreadRuntimeCore","index"],"sources":["../../../src/runtime/api/thread-list-runtime.ts"],"sourcesContent":["import type { Unsubscribe } from \"../../types/unsubscribe\";\nimport {\n LazyMemoizeSubject,\n NestedSubscriptionSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport type { ThreadListRuntimeCore } from \"../interfaces/thread-list-runtime-core\";\nimport {\n type ThreadListItemRuntime,\n ThreadListItemRuntimeImpl,\n type ThreadListItemState,\n} from \"./thread-list-item-runtime\";\nimport {\n type ThreadListItemRuntimeBinding,\n type ThreadRuntime,\n type ThreadRuntimeCoreBinding,\n ThreadRuntimeImpl,\n} from \"./thread-runtime\";\n\nconst RESOLVED_PROMISE = Promise.resolve();\n\nexport type ThreadListState = {\n readonly mainThreadId: string;\n readonly newThreadId: string | undefined;\n readonly threadIds: readonly string[];\n readonly archivedThreadIds: readonly string[];\n readonly isLoading: boolean;\n readonly isLoadingMore: boolean;\n readonly hasMore: boolean;\n readonly threadItems: Readonly<\n Record<\n string,\n Omit<ThreadListItemState, \"isMain\" | \"threadId\" | \"isRunning\">\n >\n >;\n};\n\nexport type ThreadListRuntime = {\n getState(): ThreadListState;\n\n subscribe(callback: () => void): Unsubscribe;\n\n readonly main: ThreadRuntime;\n getById(threadId: string): ThreadRuntime;\n\n readonly mainItem: ThreadListItemRuntime;\n getItemById(threadId: string): ThreadListItemRuntime;\n getItemByIndex(idx: number): ThreadListItemRuntime;\n getArchivedItemByIndex(idx: number): ThreadListItemRuntime;\n\n switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void>;\n switchToNewThread(): Promise<void>;\n\n getLoadThreadsPromise(): Promise<void>;\n reload(): Promise<void>;\n /**\n * Refetches the open thread's remote state, for state that changed out of\n * band and so never reached the stream. When the runtime declares the\n * in-place capability (`unstable_refetchThread`), composer drafts survive,\n * existing messages stay rendered during the refetch, and the promise\n * settles with the refetch, rejecting if it fails; that runtime also owns\n * what happens to a run in progress, since this does not stop one. Runtimes\n * without the capability have their hook remounted instead, which discards\n * unsent composer input and ends any run, and the promise resolves once the\n * new runtime attaches. A thread that has not been sent yet is left alone.\n */\n reloadMainThread(): Promise<void>;\n loadMore(): Promise<void>;\n};\n\nconst getThreadListState = (\n threadList: ThreadListRuntimeCore,\n): ThreadListState => {\n return {\n mainThreadId: threadList.mainThreadId,\n newThreadId: threadList.newThreadId,\n threadIds: threadList.threadIds,\n archivedThreadIds: threadList.archivedThreadIds,\n isLoading: threadList.isLoading,\n isLoadingMore: threadList.isLoadingMore ?? false,\n hasMore: threadList.hasMore ?? false,\n threadItems: threadList.threadItems,\n };\n};\n\nconst getThreadListItemState = (\n threadList: ThreadListRuntimeCore,\n threadId: string | undefined,\n): ThreadListItemState | SKIP_UPDATE => {\n if (threadId === undefined) return SKIP_UPDATE;\n\n const threadData = threadList.getItemById(threadId);\n if (!threadData) return SKIP_UPDATE;\n return {\n id: threadData.id,\n remoteId: threadData.remoteId,\n externalId: threadData.externalId,\n title: threadData.title,\n status: threadData.status,\n lastMessageAt: threadData.lastMessageAt,\n custom: threadData.custom,\n isMain: threadData.id === threadList.mainThreadId,\n isRunning: threadList.unstable_isThreadRunning?.(threadData.id) ?? false,\n };\n};\n\nexport type ThreadListRuntimeCoreBinding = ThreadListRuntimeCore;\n\nexport class ThreadListRuntimeImpl implements ThreadListRuntime {\n private _getState;\n private _core: ThreadListRuntimeCoreBinding;\n private _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime;\n\n constructor(\n _core: ThreadListRuntimeCoreBinding,\n _runtimeFactory: new (\n binding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) => ThreadRuntime = ThreadRuntimeImpl,\n ) {\n this._core = _core;\n this._runtimeFactory = _runtimeFactory;\n const stateBinding = new LazyMemoizeSubject({\n path: {},\n getState: () => getThreadListState(_core),\n subscribe: (callback) => _core.subscribe(callback),\n });\n\n this._getState = stateBinding.getState.bind(stateBinding);\n\n this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[main]`,\n threadSelector: { type: \"main\" },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.mainThreadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n\n this.main = new _runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: \"threads.main\",\n threadSelector: { type: \"main\" },\n },\n getState: () => _core.getMainThreadRuntimeCore(),\n subscribe: (callback) => _core.subscribe(callback),\n }),\n this._mainThreadListItemRuntime,\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.switchToThread = this.switchToThread.bind(this);\n this.switchToNewThread = this.switchToNewThread.bind(this);\n this.getLoadThreadsPromise = this.getLoadThreadsPromise.bind(this);\n this.reload = this.reload.bind(this);\n this.reloadMainThread = this.reloadMainThread.bind(this);\n this.loadMore = this.loadMore.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getById = this.getById.bind(this);\n this.getItemById = this.getItemById.bind(this);\n this.getItemByIndex = this.getItemByIndex.bind(this);\n this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);\n }\n\n public switchToThread(\n threadId: string,\n options?: { unarchive?: boolean },\n ): Promise<void> {\n return this._core.switchToThread(threadId, options);\n }\n\n public switchToNewThread(): Promise<void> {\n return this._core.switchToNewThread();\n }\n\n public getLoadThreadsPromise(): Promise<void> {\n return this._core.getLoadThreadsPromise();\n }\n\n public reload(): Promise<void> {\n return this._core.reload?.() ?? RESOLVED_PROMISE;\n }\n\n public reloadMainThread(): Promise<void> {\n return this._core.reloadMainThread?.() ?? RESOLVED_PROMISE;\n }\n\n public loadMore(): Promise<void> {\n return this._core.loadMore?.() ?? RESOLVED_PROMISE;\n }\n\n public getState(): ThreadListState {\n return this._getState();\n }\n\n public subscribe(callback: () => void): Unsubscribe {\n return this._core.subscribe(callback);\n }\n\n private _mainThreadListItemRuntime;\n\n public readonly main: ThreadRuntime;\n\n public get mainItem() {\n return this._mainThreadListItemRuntime;\n }\n\n public getById(threadId: string) {\n return new this._runtimeFactory(\n new NestedSubscriptionSubject({\n path: {\n ref: `threads[threadId=${JSON.stringify(threadId)}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => this._core.getThreadRuntimeCore(threadId),\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this.mainItem,\n );\n }\n\n public getItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[${idx}]`,\n threadSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(this._core, this._core.threadIds[idx]);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getArchivedItemByIndex(idx: number) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `archivedThreadItems[${idx}]`,\n threadSelector: { type: \"archiveIndex\", index: idx },\n },\n getState: () => {\n return getThreadListItemState(\n this._core,\n this._core.archivedThreadIds[idx],\n );\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n\n public getItemById(threadId: string) {\n return new ThreadListItemRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ref: `threadItems[threadId=${threadId}]`,\n threadSelector: { type: \"threadId\", threadId },\n },\n getState: () => {\n return getThreadListItemState(this._core, threadId);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n );\n }\n}\n"],"mappings":";;;;AAsBA,MAAMa,mBAAmBC,QAAQC,QAAQ;AAsDzC,MAAMiC,sBACJC,eACoB;CACpB,OAAO;EACLhC,cAAcgC,WAAWhC;EACzBC,aAAa+B,WAAW/B;EACxBC,WAAW8B,WAAW9B;EACtBC,mBAAmB6B,WAAW7B;EAC9BC,WAAW4B,WAAW5B;EACtBC,eAAe2B,WAAW3B,iBAAiB;EAC3CC,SAAS0B,WAAW1B,WAAW;EAC/BC,aAAayB,WAAWzB;CAC1B;AACF;AAEA,MAAM0B,0BACJD,YACAf,aACsC;CACtC,IAAIA,aAAaiB,KAAAA,GAAW,OAAOhD;CAEnC,MAAMiD,aAAaH,WAAWb,YAAYF,QAAQ;CAClD,IAAI,CAACkB,YAAY,OAAOjD;CACxB,OAAO;EACLkD,IAAID,WAAWC;EACfC,UAAUF,WAAWE;EACrBC,YAAYH,WAAWG;EACvBC,OAAOJ,WAAWI;EAClBC,QAAQL,WAAWK;EACnBC,eAAeN,WAAWM;EAC1BC,QAAQP,WAAWO;EACnBC,QAAQR,WAAWC,OAAOJ,WAAWhC;EACrC4C,WAAWZ,WAAWa,2BAA2BV,WAAWC,EAAE,KAAK;CACrE;AACF;AAIA,IAAaW,wBAAb,MAAgE;CAC9D;CACA;CACA;CAKAM,YACEJ,OACAC,kBAGqBvD,mBACrB;EACA,KAAKsD,QA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uBAAuB,KAAKgB,OAAO,KAAKA,MAAM/C,UAAUmB,IAAI;GACrE;GACAR,YAAYC,aAAa,KAAKmC,MAAMpC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKmC,KACP;CACF;CAEA,uBAA8B5B,KAAa;EACzC,OAAO,IAAI/B,0BACT,IAAIH,sBAAsB;GACxBoE,MAAM;IACJG,KAAK,uBAAuBrC,IAAG;IAC/BsC,gBAAgB;KAAEC,MAAM;KAAgBM,OAAO7C;IAAI;GACrD;GACAT,gBAAgB;IACd,OAAOqB,uBACL,KAAKgB,OACL,KAAKA,MAAM9C,kBAAkBkB,IAC/B;GACF;GACAR,YAAYC,aAAa,KAAKmC,MAAMpC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKmC,KACP;CACF;CAEA,YAAmBhC,UAAkB;EACnC,OAAO,IAAI3B,0BACT,IAAIH,sBAAsB;GACxBoE,MAAM;IACJG,KAAK,wBAAwBzC,SAAQ;IACrC0C,gBAAgB;KAAEC,MAAM;KAAY3C;IAAS;GAC/C;GACAL,gBAAgB;IACd,OAAOqB,uBAAuB,KAAKgB,OAAOhC,QAAQ;GACpD;GACAJ,YAAYC,aAAa,KAAKmC,MAAMpC,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKmC,KACP;CACF;AACF"}
|
|
@@ -94,6 +94,11 @@ type ThreadState = {
|
|
|
94
94
|
readonly speech: SpeechState | undefined;
|
|
95
95
|
readonly voice: VoiceSessionState | undefined;
|
|
96
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* The canonical `isRunning` derivation. A runtime that tracks run state itself
|
|
99
|
+
* reports it directly; the rest fall back to the trailing assistant message.
|
|
100
|
+
*/
|
|
101
|
+
declare const getThreadRuntimeCoreIsRunning: (runtime: ThreadRuntimeCore) => boolean;
|
|
97
102
|
declare const getThreadState: (runtime: ThreadRuntimeCore, threadListItemState: ThreadListItemState) => ThreadState;
|
|
98
103
|
type ThreadRuntime = {
|
|
99
104
|
/**
|
|
@@ -257,6 +262,7 @@ declare class ThreadRuntimeImpl implements ThreadRuntime {
|
|
|
257
262
|
exportExternalState(): any;
|
|
258
263
|
importExternalState(state: any): void;
|
|
259
264
|
reset(initialMessages?: readonly ThreadMessageLike[]): void;
|
|
265
|
+
unstable_refetchThread?: (() => Promise<void>) | undefined;
|
|
260
266
|
unstable_on<E extends ThreadRuntimeEventType>(event: E, callback: ThreadRuntimeEventCallback<E>): Unsubscribe;
|
|
261
267
|
}>;
|
|
262
268
|
} & {
|
|
@@ -295,5 +301,5 @@ declare class ThreadRuntimeImpl implements ThreadRuntime {
|
|
|
295
301
|
unstable_on<E extends ThreadRuntimeEventType>(event: E, callback: ThreadRuntimeEventCallback<E>): Unsubscribe;
|
|
296
302
|
}
|
|
297
303
|
//#endregion
|
|
298
|
-
export { CreateAppendMessage, CreateResumeRunConfig, CreateStartRunConfig, ThreadListItemRuntimeBinding, ThreadRuntime, ThreadRuntimeCoreBinding, ThreadRuntimeImpl, ThreadState, getThreadState };
|
|
304
|
+
export { CreateAppendMessage, CreateResumeRunConfig, CreateStartRunConfig, ThreadListItemRuntimeBinding, ThreadRuntime, ThreadRuntimeCoreBinding, ThreadRuntimeImpl, ThreadState, getThreadRuntimeCoreIsRunning, getThreadState };
|
|
299
305
|
//# sourceMappingURL=thread-runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/thread-runtime.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;KA8CY;EACV;EACA;EACA,YAAY;;KAGF,wBAAwB;EAClC,UACE,SAAS,wBACN,eAAe;;KAoBV;EAGN;EACA;EACA,OAAO;EACP,SAAS;EACT,cAAc;EACd,WAAW;EACX,YAAY;EACZ,YAAY;EACZ;;KAiCM,2BAA2B,sBACrC,mBACA;EAEA,eAAe,uBAAuB;;KAG5B,+BAA+B,sBACzC,qBACA;KAGU;;;;;WAKD;;;;;;WAOA,UAAU;;;;WAKV;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA9PT,OAAA;;wBAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgDkB,eAAA,uBAAa;;IAuNnB,iBAAA;;mBADF;EAKf,YAAA,eAAe,0BACf,uBAAuB;YA0Cf;WA0BM,UAAQ;EAEjB,YAAQ;EAIR,OAAO,SAAS;EAQhB,cAAc,2BAAiB;EAI/B,UAAU,uBAAoB;EAI9B,mBAAe;EAIf,SAAS,QAAQ;EAIjB,UAAU,QAAQ;EAIlB;EAIA,oBAAoB;EAIpB;EAIA;EAIA;EAIA;EAIA;EAIA,qBAAqB,uBAAoB;EAIzC;EAIA;EAIA,UAAM;EAIN,OAAO,MAAM;EAIb,MAAM,2BAA2B;EAIjC,kBAAkB,cAAW;EAsB7B,eAAe,oBAAiB;UAW/B;UA2CA;EAKD,YAAY,UAAU,wBAC3B,OAAO,GACP,UAAU,2BAA2B,KACpC"}
|
|
@@ -44,15 +44,23 @@ const toAppendMessage = (messages, message) => {
|
|
|
44
44
|
startRun: message.startRun
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
|
-
|
|
47
|
+
/**
|
|
48
|
+
* The canonical `isRunning` derivation. A runtime that tracks run state itself
|
|
49
|
+
* reports it directly; the rest fall back to the trailing assistant message.
|
|
50
|
+
*/
|
|
51
|
+
const getThreadRuntimeCoreIsRunning = (runtime) => {
|
|
52
|
+
if (runtime.isRunning !== void 0) return runtime.isRunning;
|
|
48
53
|
const lastMessage = runtime.messages.at(-1);
|
|
54
|
+
return lastMessage?.role === "assistant" && lastMessage.status.type === "running";
|
|
55
|
+
};
|
|
56
|
+
const getThreadState = (runtime, threadListItemState) => {
|
|
49
57
|
return Object.freeze({
|
|
50
58
|
threadId: threadListItemState.id,
|
|
51
59
|
metadata: threadListItemState,
|
|
52
60
|
capabilities: runtime.capabilities,
|
|
53
61
|
isDisabled: runtime.isDisabled,
|
|
54
62
|
isLoading: runtime.isLoading,
|
|
55
|
-
isRunning: runtime
|
|
63
|
+
isRunning: getThreadRuntimeCoreIsRunning(runtime),
|
|
56
64
|
messages: runtime.messages,
|
|
57
65
|
state: runtime.state,
|
|
58
66
|
suggestions: runtime.suggestions,
|
|
@@ -252,6 +260,6 @@ var ThreadRuntimeImpl = class {
|
|
|
252
260
|
}
|
|
253
261
|
};
|
|
254
262
|
//#endregion
|
|
255
|
-
export { ThreadRuntimeImpl, getThreadState };
|
|
263
|
+
export { ThreadRuntimeImpl, getThreadRuntimeCoreIsRunning, getThreadState };
|
|
256
264
|
|
|
257
265
|
//# sourceMappingURL=thread-runtime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-runtime.js","names":["ThreadSuggestion","RuntimeCapabilities","ThreadRuntimeCore","SpeechState","VoiceSessionState","ThreadRuntimeEventCallback","ThreadRuntimeEventType","StartRunConfig","ResumeRunConfig","ExportedMessageRepository","ThreadMessageLike","MessageRuntime","MessageRuntimeImpl","MessageState","NestedSubscriptionSubject","ShallowMemoizeSubject","SKIP_UPDATE","SubscribableWithState","ThreadComposerRuntime","ThreadComposerRuntimeImpl","MessageRuntimePath","ThreadListItemRuntimePath","ThreadRuntimePath","ThreadListItemState","AppendMessage","ThreadMessage","Unsubscribe","RunConfig","EventSubscriptionSubject","symbolInnerMessage","ModelContext","ChatModelRunOptions","ChatModelRunResult","ReadonlyJSONValue","CreateStartRunConfig","parentId","sourceId","runConfig","CreateResumeRunConfig","stream","options","AsyncGenerator","toResumeRunConfig","message","toStartRunConfig","CreateAppendMessage","role","content","attachments","metadata","createdAt","Date","startRun","toAppendMessage","messages","at","id","type","text","custom","ThreadRuntimeCoreBinding","outerSubscribe","callback","ThreadListItemRuntimeBinding","ThreadState","threadId","isDisabled","isLoading","isRunning","capabilities","state","suggestions","extras","speech","voice","getThreadState","runtime","threadListItemState","lastMessage","Object","freeze","status","ThreadRuntime","path","composer","getState","append","deleteMessage","messageId","Promise","config","resumeRun","exportExternalState","importExternalState","subscribe","cancelRun","getModelContext","export","import","repository","reset","initialMessages","getMessageByIndex","idx","getMessageById","stopSpeaking","connectVoice","disconnectVoice","getVoiceVolume","subscribeVoiceVolume","muteVoice","unmuteVoice","unstable_on","event","E","ThreadRuntimeImpl","_threadBinding","__internal_threadBinding","getStateState","constructor","threadBinding","threadListItemBinding","stateBinding","sub1","sub2","ref","composerSource","__internal_bindMethods","bind","data","Error","_getMessageRuntime","messageSelector","index","undefined","JSON","stringify","speechState","thread","branches","getBranches","isLast","branchNumber","indexOf","branchCount","length","_eventSubscriptionSubjects","Map","subject","get","binding","set","payload"],"sources":["../../../src/runtime/api/thread-runtime.ts"],"sourcesContent":["import type {\n ThreadSuggestion,\n RuntimeCapabilities,\n ThreadRuntimeCore,\n SpeechState,\n VoiceSessionState,\n ThreadRuntimeEventCallback,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../interfaces/thread-runtime-core\";\nimport type { ExportedMessageRepository } from \"../utils/message-repository\";\nimport type { ThreadMessageLike } from \"../utils/thread-message-like\";\nimport {\n type MessageRuntime,\n MessageRuntimeImpl,\n type MessageState,\n} from \"./message-runtime\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n ShallowMemoizeSubject,\n SKIP_UPDATE,\n} from \"../../subscribable/subscribable\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport {\n type ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport type {\n MessageRuntimePath,\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n} from \"./paths\";\nimport type { ThreadListItemState } from \"./bindings\";\nimport type { AppendMessage, ThreadMessage } from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport { EventSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type { ModelContext } from \"../../model-context/types\";\nimport type {\n ChatModelRunOptions,\n ChatModelRunResult,\n} from \"../utils/chat-model-adapter\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\n\nexport type CreateStartRunConfig = {\n parentId: string | null;\n sourceId?: string | null | undefined;\n runConfig?: RunConfig | undefined;\n};\n\nexport type CreateResumeRunConfig = CreateStartRunConfig & {\n stream?: (\n options: ChatModelRunOptions,\n ) => AsyncGenerator<ChatModelRunResult, void, unknown>;\n};\n\nconst toResumeRunConfig = (message: CreateResumeRunConfig): ResumeRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n ...(message.stream ? { stream: message.stream } : {}),\n };\n};\n\nconst toStartRunConfig = (message: CreateStartRunConfig): StartRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n };\n};\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n sourceId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n metadata?: AppendMessage[\"metadata\"] | undefined;\n createdAt?: Date | undefined;\n runConfig?: AppendMessage[\"runConfig\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n createdAt: new Date(),\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n metadata: { custom: {} },\n };\n }\n\n return {\n createdAt: message.createdAt ?? new Date(),\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n metadata: message.metadata ?? { custom: {} },\n runConfig: message.runConfig ?? {},\n startRun: message.startRun,\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadListItemRuntimeBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport type ThreadState = {\n /**\n * The thread ID.\n * @deprecated This field is deprecated and will be removed in 0.12.0. Use `useThreadListItem().id` instead.\n */\n readonly threadId: string;\n\n /**\n * The thread metadata.\n *\n * @deprecated Use `useThreadListItem()` instead. This field is deprecated and will be removed in 0.12.0.\n */\n readonly metadata: ThreadListItemState;\n\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n readonly isDisabled: boolean;\n\n /**\n * Whether the thread is loading its history.\n */\n readonly isLoading: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n readonly isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n readonly capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n readonly messages: readonly ThreadMessage[];\n\n /**\n * The thread state.\n *\n * @deprecated This feature is experimental\n */\n readonly state: ReadonlyJSONValue;\n\n /**\n * Follow up message suggestions to show the user.\n */\n readonly suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n readonly extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n\n readonly voice: VoiceSessionState | undefined;\n};\n\nexport const getThreadState = (\n runtime: ThreadRuntimeCore,\n threadListItemState: ThreadListItemState,\n): ThreadState => {\n const lastMessage = runtime.messages.at(-1);\n return Object.freeze({\n threadId: threadListItemState.id,\n metadata: threadListItemState,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isLoading: runtime.isLoading,\n isRunning:\n runtime.isRunning ??\n (lastMessage?.role !== \"assistant\"\n ? false\n : lastMessage.status.type === \"running\"),\n messages: runtime.messages,\n state: runtime.state,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n voice: runtime.voice,\n });\n};\n\nexport type ThreadRuntime = {\n /**\n * The selector for the thread runtime.\n */\n readonly path: ThreadRuntimePath;\n\n /**\n * The thread composer runtime.\n */\n readonly composer: ThreadComposerRuntime;\n\n /**\n * Gets a snapshot of the thread state.\n */\n getState(): ThreadState;\n\n /**\n * Append a new message to the thread.\n *\n * @example ```ts\n * // append a new user message with the text \"Hello, world!\"\n * threadRuntime.append(\"Hello, world!\");\n * ```\n *\n * @example ```ts\n * // append a new assistant message with the text \"Hello, world!\"\n * threadRuntime.append({\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hello, world!\" }],\n * });\n * ```\n */\n append(message: CreateAppendMessage): void;\n\n deleteMessage(messageId: string): void | Promise<void>;\n\n /**\n * Start a new run with the given configuration.\n * @param config The configuration for starting the run\n */\n startRun(config: CreateStartRunConfig): void;\n\n /**\n * Resume a run with the given configuration.\n * @param config The configuration for resuming the run\n **/\n resumeRun(config: CreateResumeRunConfig): void;\n\n /**\n * Export the thread state in the external store format.\n * For AI SDK runtimes, this returns the AI SDK message format.\n * For other runtimes, this may return different formats or throw an error.\n * @returns The thread state in the external format (typed as any)\n */\n exportExternalState(): any;\n\n /**\n * Import thread state from the external store format.\n * For AI SDK runtimes, this accepts AI SDK messages.\n * For other runtimes, this may accept different formats or throw an error.\n * @param state The thread state in the external format (typed as any)\n */\n importExternalState(state: any): void;\n\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelContext(): ModelContext;\n\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n\n /**\n * Reset the thread with optional initial messages.\n *\n * @param initialMessages - Optional array of initial messages to populate the thread\n */\n reset(initialMessages?: readonly ThreadMessageLike[]): void;\n\n getMessageByIndex(idx: number): MessageRuntime;\n getMessageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n\n connectVoice(): void;\n disconnectVoice(): void;\n getVoiceVolume(): number;\n subscribeVoiceVolume(callback: () => void): Unsubscribe;\n muteVoice(): void;\n unmuteVoice(): void;\n\n unstable_on<E extends ThreadRuntimeEventType>(\n event: E,\n callback: ThreadRuntimeEventCallback<E>,\n ): Unsubscribe;\n};\n\nexport class ThreadRuntimeImpl implements ThreadRuntime {\n public get path() {\n return this._threadBinding.path;\n }\n\n public get __internal_threadBinding() {\n return this._threadBinding;\n }\n\n private readonly _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(\n threadBinding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) {\n const stateBinding = new ShallowMemoizeSubject({\n path: threadBinding.path,\n getState: () =>\n getThreadState(\n threadBinding.getState(),\n threadListItemBinding.getState(),\n ),\n subscribe: (callback) => {\n const sub1 = threadBinding.subscribe(callback);\n const sub2 = threadListItemBinding.subscribe(callback);\n return () => {\n sub1();\n sub2();\n };\n },\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.append = this.append.bind(this);\n this.deleteMessage = this.deleteMessage.bind(this);\n this.resumeRun = this.resumeRun.bind(this);\n this.importExternalState = this.importExternalState.bind(this);\n this.exportExternalState = this.exportExternalState.bind(this);\n this.startRun = this.startRun.bind(this);\n this.cancelRun = this.cancelRun.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.connectVoice = this.connectVoice.bind(this);\n this.disconnectVoice = this.disconnectVoice.bind(this);\n this.muteVoice = this.muteVoice.bind(this);\n this.unmuteVoice = this.unmuteVoice.bind(this);\n this.getVoiceVolume = this.getVoiceVolume.bind(this);\n this.subscribeVoiceVolume = this.subscribeVoiceVolume.bind(this);\n this.export = this.export.bind(this);\n this.import = this.import.bind(this);\n this.reset = this.reset.bind(this);\n this.getMessageByIndex = this.getMessageByIndex.bind(this);\n this.getMessageById = this.getMessageById.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getModelContext = this.getModelContext.bind(this);\n this.getState = this.getState.bind(this);\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public deleteMessage(messageId: string) {\n return this._threadBinding.getState().deleteMessage(messageId);\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n public getModelContext() {\n return this._threadBinding.getState().getModelContext();\n }\n\n public startRun(config: CreateStartRunConfig) {\n return this._threadBinding.getState().startRun(toStartRunConfig(config));\n }\n\n public resumeRun(config: CreateResumeRunConfig) {\n return this._threadBinding.getState().resumeRun(toResumeRunConfig(config));\n }\n\n public exportExternalState() {\n return this._threadBinding.getState().exportExternalState();\n }\n\n public importExternalState(state: any) {\n this._threadBinding.getState().importExternalState(state);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public connectVoice() {\n this._threadBinding.getState().connectVoice();\n }\n\n public disconnectVoice() {\n this._threadBinding.getState().disconnectVoice();\n }\n\n public getVoiceVolume() {\n return this._threadBinding.getState().getVoiceVolume();\n }\n\n public subscribeVoiceVolume(callback: () => void) {\n return this._threadBinding.getState().subscribeVoiceVolume(callback);\n }\n\n public muteVoice() {\n this._threadBinding.getState().muteVoice();\n }\n\n public unmuteVoice() {\n this._threadBinding.getState().unmuteVoice();\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public reset(initialMessages?: readonly ThreadMessageLike[]) {\n this._threadBinding.getState().reset(initialMessages);\n }\n\n public getMessageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n index: idx,\n };\n },\n );\n }\n\n public getMessageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage; index: number }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId, index } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined || index === undefined)\n return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n\n return {\n ...message,\n ...{ [symbolInnerMessage]: (message as any)[symbolInnerMessage] },\n\n index,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ThreadRuntimeEventType>\n >();\n\n public unstable_on<E extends ThreadRuntimeEventType>(\n event: E,\n callback: ThreadRuntimeEventCallback<E>,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject<ThreadRuntimeEventType>({\n event,\n binding: this._threadBinding,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback as (payload?: unknown) => void);\n }\n}\n"],"mappings":";;;;;AA0DA,MAAM0C,qBAAqBC,YAAoD;CAC7E,OAAO;EACLR,UAAUQ,QAAQR,YAAY;EAC9BC,UAAUO,QAAQP,YAAY;EAC9BC,WAAWM,QAAQN,aAAa,CAAC;EACjC,GAAIM,QAAQJ,SAAS,EAAEA,QAAQI,QAAQJ,OAAO,IAAI,CAAC;CACrD;AACF;AAEA,MAAMK,oBAAoBD,YAAkD;CAC1E,OAAO;EACLR,UAAUQ,QAAQR,YAAY;EAC9BC,UAAUO,QAAQP,YAAY;EAC9BC,WAAWM,QAAQN,aAAa,CAAC;CACnC;AACF;AAgBA,MAAMgB,mBACJC,UACAX,YACkB;CAClB,IAAI,OAAOA,YAAY,UACrB,OAAO;EACLO,2BAAW,IAAIC,KAAK;EACpBhB,UAAUmB,SAASC,GAAG,EAAE,CAAC,EAAEC,MAAM;EACjCpB,UAAU;EACVC,WAAW,CAAC;EACZS,MAAM;EACNC,SAAS,CAAC;GAAEU,MAAM;GAAQC,MAAMf;EAAQ,CAAC;EACzCK,aAAa,CAAA;EACbC,UAAU,EAAEU,QAAQ,CAAC,EAAE;CACzB;CAGF,OAAO;EACLT,WAAWP,QAAQO,6BAAa,IAAIC,KAAK;EACzChB,UAAUQ,QAAQR,YAAYmB,SAASC,GAAG,EAAE,CAAC,EAAEC,MAAM;EACrDpB,UAAUO,QAAQP,YAAY;EAC9BU,MAAMH,QAAQG,QAAQ;EACtBC,SAASJ,QAAQI;E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C;CAClE;AACF"}
|
|
1
|
+
{"version":3,"file":"thread-runtime.js","names":["ThreadSuggestion","RuntimeCapabilities","ThreadRuntimeCore","SpeechState","VoiceSessionState","ThreadRuntimeEventCallback","ThreadRuntimeEventType","StartRunConfig","ResumeRunConfig","ExportedMessageRepository","ThreadMessageLike","MessageRuntime","MessageRuntimeImpl","MessageState","NestedSubscriptionSubject","ShallowMemoizeSubject","SKIP_UPDATE","SubscribableWithState","ThreadComposerRuntime","ThreadComposerRuntimeImpl","MessageRuntimePath","ThreadListItemRuntimePath","ThreadRuntimePath","ThreadListItemState","AppendMessage","ThreadMessage","Unsubscribe","RunConfig","EventSubscriptionSubject","symbolInnerMessage","ModelContext","ChatModelRunOptions","ChatModelRunResult","ReadonlyJSONValue","CreateStartRunConfig","parentId","sourceId","runConfig","CreateResumeRunConfig","stream","options","AsyncGenerator","toResumeRunConfig","message","toStartRunConfig","CreateAppendMessage","role","content","attachments","metadata","createdAt","Date","startRun","toAppendMessage","messages","at","id","type","text","custom","ThreadRuntimeCoreBinding","outerSubscribe","callback","ThreadListItemRuntimeBinding","ThreadState","threadId","isDisabled","isLoading","isRunning","capabilities","state","suggestions","extras","speech","voice","getThreadRuntimeCoreIsRunning","runtime","undefined","lastMessage","status","getThreadState","threadListItemState","Object","freeze","ThreadRuntime","path","composer","getState","append","deleteMessage","messageId","Promise","config","resumeRun","exportExternalState","importExternalState","subscribe","cancelRun","getModelContext","export","import","repository","reset","initialMessages","getMessageByIndex","idx","getMessageById","stopSpeaking","connectVoice","disconnectVoice","getVoiceVolume","subscribeVoiceVolume","muteVoice","unmuteVoice","unstable_on","event","E","ThreadRuntimeImpl","_threadBinding","__internal_threadBinding","getStateState","constructor","threadBinding","threadListItemBinding","stateBinding","sub1","sub2","ref","composerSource","__internal_bindMethods","bind","data","Error","_getMessageRuntime","messageSelector","index","JSON","stringify","speechState","thread","branches","getBranches","isLast","branchNumber","indexOf","branchCount","length","_eventSubscriptionSubjects","Map","subject","get","binding","set","payload"],"sources":["../../../src/runtime/api/thread-runtime.ts"],"sourcesContent":["import type {\n ThreadSuggestion,\n RuntimeCapabilities,\n ThreadRuntimeCore,\n SpeechState,\n VoiceSessionState,\n ThreadRuntimeEventCallback,\n ThreadRuntimeEventType,\n StartRunConfig,\n ResumeRunConfig,\n} from \"../interfaces/thread-runtime-core\";\nimport type { ExportedMessageRepository } from \"../utils/message-repository\";\nimport type { ThreadMessageLike } from \"../utils/thread-message-like\";\nimport {\n type MessageRuntime,\n MessageRuntimeImpl,\n type MessageState,\n} from \"./message-runtime\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n ShallowMemoizeSubject,\n SKIP_UPDATE,\n} from \"../../subscribable/subscribable\";\nimport type { SubscribableWithState } from \"../../subscribable/subscribable\";\nimport {\n type ThreadComposerRuntime,\n ThreadComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport type {\n MessageRuntimePath,\n ThreadListItemRuntimePath,\n ThreadRuntimePath,\n} from \"./paths\";\nimport type { ThreadListItemState } from \"./bindings\";\nimport type { AppendMessage, ThreadMessage } from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { RunConfig } from \"../../types/message\";\nimport { EventSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type { ModelContext } from \"../../model-context/types\";\nimport type {\n ChatModelRunOptions,\n ChatModelRunResult,\n} from \"../utils/chat-model-adapter\";\nimport type { ReadonlyJSONValue } from \"assistant-stream/utils\";\n\nexport type CreateStartRunConfig = {\n parentId: string | null;\n sourceId?: string | null | undefined;\n runConfig?: RunConfig | undefined;\n};\n\nexport type CreateResumeRunConfig = CreateStartRunConfig & {\n stream?: (\n options: ChatModelRunOptions,\n ) => AsyncGenerator<ChatModelRunResult, void, unknown>;\n};\n\nconst toResumeRunConfig = (message: CreateResumeRunConfig): ResumeRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n ...(message.stream ? { stream: message.stream } : {}),\n };\n};\n\nconst toStartRunConfig = (message: CreateStartRunConfig): StartRunConfig => {\n return {\n parentId: message.parentId ?? null,\n sourceId: message.sourceId ?? null,\n runConfig: message.runConfig ?? {},\n };\n};\n\nexport type CreateAppendMessage =\n | string\n | {\n parentId?: string | null | undefined;\n sourceId?: string | null | undefined;\n role?: AppendMessage[\"role\"] | undefined;\n content: AppendMessage[\"content\"];\n attachments?: AppendMessage[\"attachments\"] | undefined;\n metadata?: AppendMessage[\"metadata\"] | undefined;\n createdAt?: Date | undefined;\n runConfig?: AppendMessage[\"runConfig\"] | undefined;\n startRun?: boolean | undefined;\n };\n\nconst toAppendMessage = (\n messages: readonly ThreadMessage[],\n message: CreateAppendMessage,\n): AppendMessage => {\n if (typeof message === \"string\") {\n return {\n createdAt: new Date(),\n parentId: messages.at(-1)?.id ?? null,\n sourceId: null,\n runConfig: {},\n role: \"user\",\n content: [{ type: \"text\", text: message }],\n attachments: [],\n metadata: { custom: {} },\n };\n }\n\n return {\n createdAt: message.createdAt ?? new Date(),\n parentId: message.parentId ?? messages.at(-1)?.id ?? null,\n sourceId: message.sourceId ?? null,\n role: message.role ?? \"user\",\n content: message.content,\n attachments: message.attachments ?? [],\n metadata: message.metadata ?? { custom: {} },\n runConfig: message.runConfig ?? {},\n startRun: message.startRun,\n } as AppendMessage;\n};\n\nexport type ThreadRuntimeCoreBinding = SubscribableWithState<\n ThreadRuntimeCore,\n ThreadRuntimePath\n> & {\n outerSubscribe(callback: () => void): Unsubscribe;\n};\n\nexport type ThreadListItemRuntimeBinding = SubscribableWithState<\n ThreadListItemState,\n ThreadListItemRuntimePath\n>;\n\nexport type ThreadState = {\n /**\n * The thread ID.\n * @deprecated This field is deprecated and will be removed in 0.12.0. Use `useThreadListItem().id` instead.\n */\n readonly threadId: string;\n\n /**\n * The thread metadata.\n *\n * @deprecated Use `useThreadListItem()` instead. This field is deprecated and will be removed in 0.12.0.\n */\n readonly metadata: ThreadListItemState;\n\n /**\n * Whether the thread is disabled. Disabled threads cannot receive new messages.\n */\n readonly isDisabled: boolean;\n\n /**\n * Whether the thread is loading its history.\n */\n readonly isLoading: boolean;\n\n /**\n * Whether the thread is running. A thread is considered running when there is an active stream connection to the backend.\n */\n readonly isRunning: boolean;\n\n /**\n * The capabilities of the thread, such as whether the thread supports editing, branch switching, etc.\n */\n readonly capabilities: RuntimeCapabilities;\n\n /**\n * The messages in the currently selected branch of the thread.\n */\n readonly messages: readonly ThreadMessage[];\n\n /**\n * The thread state.\n *\n * @deprecated This feature is experimental\n */\n readonly state: ReadonlyJSONValue;\n\n /**\n * Follow up message suggestions to show the user.\n */\n readonly suggestions: readonly ThreadSuggestion[];\n\n /**\n * Custom extra information provided by the runtime.\n */\n readonly extras: unknown;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n\n readonly voice: VoiceSessionState | undefined;\n};\n\n/**\n * The canonical `isRunning` derivation. A runtime that tracks run state itself\n * reports it directly; the rest fall back to the trailing assistant message.\n */\nexport const getThreadRuntimeCoreIsRunning = (\n runtime: ThreadRuntimeCore,\n): boolean => {\n if (runtime.isRunning !== undefined) return runtime.isRunning;\n const lastMessage = runtime.messages.at(-1);\n return (\n lastMessage?.role === \"assistant\" && lastMessage.status.type === \"running\"\n );\n};\n\nexport const getThreadState = (\n runtime: ThreadRuntimeCore,\n threadListItemState: ThreadListItemState,\n): ThreadState => {\n return Object.freeze({\n threadId: threadListItemState.id,\n metadata: threadListItemState,\n capabilities: runtime.capabilities,\n isDisabled: runtime.isDisabled,\n isLoading: runtime.isLoading,\n isRunning: getThreadRuntimeCoreIsRunning(runtime),\n messages: runtime.messages,\n state: runtime.state,\n suggestions: runtime.suggestions,\n extras: runtime.extras,\n speech: runtime.speech,\n voice: runtime.voice,\n });\n};\n\nexport type ThreadRuntime = {\n /**\n * The selector for the thread runtime.\n */\n readonly path: ThreadRuntimePath;\n\n /**\n * The thread composer runtime.\n */\n readonly composer: ThreadComposerRuntime;\n\n /**\n * Gets a snapshot of the thread state.\n */\n getState(): ThreadState;\n\n /**\n * Append a new message to the thread.\n *\n * @example ```ts\n * // append a new user message with the text \"Hello, world!\"\n * threadRuntime.append(\"Hello, world!\");\n * ```\n *\n * @example ```ts\n * // append a new assistant message with the text \"Hello, world!\"\n * threadRuntime.append({\n * role: \"assistant\",\n * content: [{ type: \"text\", text: \"Hello, world!\" }],\n * });\n * ```\n */\n append(message: CreateAppendMessage): void;\n\n deleteMessage(messageId: string): void | Promise<void>;\n\n /**\n * Start a new run with the given configuration.\n * @param config The configuration for starting the run\n */\n startRun(config: CreateStartRunConfig): void;\n\n /**\n * Resume a run with the given configuration.\n * @param config The configuration for resuming the run\n **/\n resumeRun(config: CreateResumeRunConfig): void;\n\n /**\n * Export the thread state in the external store format.\n * For AI SDK runtimes, this returns the AI SDK message format.\n * For other runtimes, this may return different formats or throw an error.\n * @returns The thread state in the external format (typed as any)\n */\n exportExternalState(): any;\n\n /**\n * Import thread state from the external store format.\n * For AI SDK runtimes, this accepts AI SDK messages.\n * For other runtimes, this may accept different formats or throw an error.\n * @param state The thread state in the external format (typed as any)\n */\n importExternalState(state: any): void;\n\n subscribe(callback: () => void): Unsubscribe;\n cancelRun(): void;\n getModelContext(): ModelContext;\n\n export(): ExportedMessageRepository;\n import(repository: ExportedMessageRepository): void;\n\n /**\n * Reset the thread with optional initial messages.\n *\n * @param initialMessages - Optional array of initial messages to populate the thread\n */\n reset(initialMessages?: readonly ThreadMessageLike[]): void;\n\n getMessageByIndex(idx: number): MessageRuntime;\n getMessageById(messageId: string): MessageRuntime;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n\n connectVoice(): void;\n disconnectVoice(): void;\n getVoiceVolume(): number;\n subscribeVoiceVolume(callback: () => void): Unsubscribe;\n muteVoice(): void;\n unmuteVoice(): void;\n\n unstable_on<E extends ThreadRuntimeEventType>(\n event: E,\n callback: ThreadRuntimeEventCallback<E>,\n ): Unsubscribe;\n};\n\nexport class ThreadRuntimeImpl implements ThreadRuntime {\n public get path() {\n return this._threadBinding.path;\n }\n\n public get __internal_threadBinding() {\n return this._threadBinding;\n }\n\n private readonly _threadBinding: ThreadRuntimeCoreBinding & {\n getStateState(): ThreadState;\n };\n\n constructor(\n threadBinding: ThreadRuntimeCoreBinding,\n threadListItemBinding: ThreadListItemRuntimeBinding,\n ) {\n const stateBinding = new ShallowMemoizeSubject({\n path: threadBinding.path,\n getState: () =>\n getThreadState(\n threadBinding.getState(),\n threadListItemBinding.getState(),\n ),\n subscribe: (callback) => {\n const sub1 = threadBinding.subscribe(callback);\n const sub2 = threadListItemBinding.subscribe(callback);\n return () => {\n sub1();\n sub2();\n };\n },\n });\n\n this._threadBinding = {\n path: threadBinding.path,\n getState: () => threadBinding.getState(),\n getStateState: () => stateBinding.getState(),\n outerSubscribe: (callback) => threadBinding.outerSubscribe(callback),\n subscribe: (callback) => threadBinding.subscribe(callback),\n };\n\n this.composer = new ThreadComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"thread\",\n },\n getState: () => this._threadBinding.getState().composer,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.append = this.append.bind(this);\n this.deleteMessage = this.deleteMessage.bind(this);\n this.resumeRun = this.resumeRun.bind(this);\n this.importExternalState = this.importExternalState.bind(this);\n this.exportExternalState = this.exportExternalState.bind(this);\n this.startRun = this.startRun.bind(this);\n this.cancelRun = this.cancelRun.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.connectVoice = this.connectVoice.bind(this);\n this.disconnectVoice = this.disconnectVoice.bind(this);\n this.muteVoice = this.muteVoice.bind(this);\n this.unmuteVoice = this.unmuteVoice.bind(this);\n this.getVoiceVolume = this.getVoiceVolume.bind(this);\n this.subscribeVoiceVolume = this.subscribeVoiceVolume.bind(this);\n this.export = this.export.bind(this);\n this.import = this.import.bind(this);\n this.reset = this.reset.bind(this);\n this.getMessageByIndex = this.getMessageByIndex.bind(this);\n this.getMessageById = this.getMessageById.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.unstable_on = this.unstable_on.bind(this);\n this.getModelContext = this.getModelContext.bind(this);\n this.getState = this.getState.bind(this);\n }\n\n public readonly composer;\n\n public getState() {\n return this._threadBinding.getStateState();\n }\n\n public append(message: CreateAppendMessage) {\n this._threadBinding\n .getState()\n .append(\n toAppendMessage(this._threadBinding.getState().messages, message),\n );\n }\n\n public deleteMessage(messageId: string) {\n return this._threadBinding.getState().deleteMessage(messageId);\n }\n\n public subscribe(callback: () => void) {\n return this._threadBinding.subscribe(callback);\n }\n\n public getModelContext() {\n return this._threadBinding.getState().getModelContext();\n }\n\n public startRun(config: CreateStartRunConfig) {\n return this._threadBinding.getState().startRun(toStartRunConfig(config));\n }\n\n public resumeRun(config: CreateResumeRunConfig) {\n return this._threadBinding.getState().resumeRun(toResumeRunConfig(config));\n }\n\n public exportExternalState() {\n return this._threadBinding.getState().exportExternalState();\n }\n\n public importExternalState(state: any) {\n this._threadBinding.getState().importExternalState(state);\n }\n\n public cancelRun() {\n this._threadBinding.getState().cancelRun();\n }\n\n public stopSpeaking() {\n return this._threadBinding.getState().stopSpeaking();\n }\n\n public connectVoice() {\n this._threadBinding.getState().connectVoice();\n }\n\n public disconnectVoice() {\n this._threadBinding.getState().disconnectVoice();\n }\n\n public getVoiceVolume() {\n return this._threadBinding.getState().getVoiceVolume();\n }\n\n public subscribeVoiceVolume(callback: () => void) {\n return this._threadBinding.getState().subscribeVoiceVolume(callback);\n }\n\n public muteVoice() {\n this._threadBinding.getState().muteVoice();\n }\n\n public unmuteVoice() {\n this._threadBinding.getState().unmuteVoice();\n }\n\n public export() {\n return this._threadBinding.getState().export();\n }\n\n public import(data: ExportedMessageRepository) {\n this._threadBinding.getState().import(data);\n }\n\n public reset(initialMessages?: readonly ThreadMessageLike[]) {\n this._threadBinding.getState().reset(initialMessages);\n }\n\n public getMessageByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message index must be >= 0\");\n\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: `${this.path.ref}.messages[${idx}]`,\n messageSelector: { type: \"index\", index: idx },\n },\n () => {\n const messages = this._threadBinding.getState().messages;\n const message = messages[idx];\n if (!message) return undefined;\n return {\n message,\n parentId: messages[idx - 1]?.id ?? null,\n index: idx,\n };\n },\n );\n }\n\n public getMessageById(messageId: string) {\n return this._getMessageRuntime(\n {\n ...this.path,\n ref: `${this.path.ref}.messages[messageId=${JSON.stringify(messageId)}]`,\n messageSelector: { type: \"messageId\", messageId: messageId },\n },\n () => this._threadBinding.getState().getMessageById(messageId),\n );\n }\n\n private _getMessageRuntime(\n path: MessageRuntimePath,\n callback: () =>\n | { parentId: string | null; message: ThreadMessage; index: number }\n | undefined,\n ) {\n return new MessageRuntimeImpl(\n new ShallowMemoizeSubject({\n path,\n getState: () => {\n const { message, parentId, index } = callback() ?? {};\n\n const { messages, speech: speechState } =\n this._threadBinding.getState();\n\n if (!message || parentId === undefined || index === undefined)\n return SKIP_UPDATE;\n\n const thread = this._threadBinding.getState();\n\n const branches = thread.getBranches(message.id);\n\n return {\n ...message,\n ...{ [symbolInnerMessage]: (message as any)[symbolInnerMessage] },\n\n index,\n isLast: messages.at(-1)?.id === message.id,\n parentId,\n\n branchNumber: branches.indexOf(message.id) + 1,\n branchCount: branches.length,\n\n speech:\n speechState?.messageId === message.id ? speechState : undefined,\n } satisfies MessageState;\n },\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n this._threadBinding,\n );\n }\n\n private _eventSubscriptionSubjects = new Map<\n string,\n EventSubscriptionSubject<ThreadRuntimeEventType>\n >();\n\n public unstable_on<E extends ThreadRuntimeEventType>(\n event: E,\n callback: ThreadRuntimeEventCallback<E>,\n ): Unsubscribe {\n let subject = this._eventSubscriptionSubjects.get(event);\n if (!subject) {\n subject = new EventSubscriptionSubject<ThreadRuntimeEventType>({\n event,\n binding: this._threadBinding,\n });\n this._eventSubscriptionSubjects.set(event, subject);\n }\n return subject.subscribe(callback as (payload?: unknown) => void);\n }\n}\n"],"mappings":";;;;;AA0DA,MAAM0C,qBAAqBC,YAAoD;CAC7E,OAAO;EACLR,UAAUQ,QAAQR,YAAY;EAC9BC,UAAUO,QAAQP,YAAY;EAC9BC,WAAWM,QAAQN,aAAa,CAAC;EACjC,GAAIM,QAAQJ,SAAS,EAAEA,QAAQI,QAAQJ,OAAO,IAAI,CAAC;CACrD;AACF;AAEA,MAAMK,oBAAoBD,YAAkD;CAC1E,OAAO;EACLR,UAAUQ,QAAQR,YAAY;EAC9BC,UAAUO,QAAQP,YAAY;EAC9BC,WAAWM,QAAQN,aAAa,CAAC;CACnC;AACF;AAgBA,MAAMgB,mBACJC,UACAX,YACkB;CAClB,IAAI,OAAOA,YAAY,UACrB,OAAO;EACLO,2BAAW,IAAIC,KAAK;EACpBhB,UAAUmB,SAASC,GAAG,EAAE,CAAC,EAAEC,MAAM;EACjCpB,UAAU;EACVC,WAAW,CAAC;EACZS,MAAM;EACNC,SAAS,CAAC;GAAEU,MAAM;GAAQC,MAAMf;EAAQ,CAAC;EACzCK,aAAa,CAAA;EACbC,UAAU,EAAEU,QAAQ,CAAC,EAAE;CACzB;CAGF,OAAO;EACLT,WAAWP,QAAQO,6BAAa,IAAIC,KAAK;EACzChB,UAAUQ,QAAQR,YAAYmB,SAASC,GAAG,EAAE,CAAC,EAAEC,MAAM;EACrDpB,UAAUO,QAAQP,YAAY;EAC9BU,MAAMH,QAAQG,QAAQ;EACtBC,SAASJ,QAAQI;EACjBC,aAAaL,QAAQK,eAAe,CAAA;EACpCC,UAAUN,QAAQM,YAAY,EAAEU,QAAQ,CAAC,EAAE;EAC3CtB,WAAWM,QAAQN,aAAa,CAAC;EACjCe,UAAUT,QAAQS;CACpB;AACF;;;;;AAkFA,MAAauB,iCACXC,YAC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emen
|
|
|
38
38
|
protected _isSending: boolean;
|
|
39
39
|
private _removedDuringSend;
|
|
40
40
|
private _sendGeneration;
|
|
41
|
+
private _attachmentAddOperations;
|
|
42
|
+
private _cancelAttachmentAdd;
|
|
43
|
+
private _cancelAllAttachmentAdds;
|
|
41
44
|
private _emptyTextAndAttachments;
|
|
42
45
|
private _onClearAttachments;
|
|
43
46
|
reset(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"base-composer-runtime-core.d.ts","names":[],"sources":["../../../src/runtime/base/base-composer-runtime-core.ts"],"mappings":";;;;;;;;;uBAyCsB,gCACZ,4BACG;WAEK;qBAEG,wBAAwB;qBACxB,uBAAuB;YAEhC,2BACR;IAAY;MAAa,SAAS;;KAClC,SAAS,GAAG,kBAAkB,sCAAsC;MAW3D;UAIH;MACG,wBAAW;YAIZ,eAAe,gBAAgB;eAKrB;eACA;MAET;UAIH;MAEJ;UAII;MAEJ;UAII;MAEJ,aAAS;UAIL;MAEJ,SAAK;EAIF,SAAS,OAAO;EAOhB,QAAQ;EAaR,QAAQ,MAAM;EAOd,aAAa,WAAW;YAOrB;UACF;UACA;UACA;UAEA;UAQA;UAOA;UAMM;EAQD,SAAK;EA8BL,oBAAgB;EAQhB,KAAK,UAAU,cAAW;EAiFhC;MAII,kBAAkB;EAItB,eAAe;EACf,gBAAgB;qBAEJ,WACjB,SAAS,KAAK,yCACd,UAAU,qBACF;qBACS;EAEb,cAAc,kBAAkB,OAAO,mBAAgB;UAuIrD;EAqBF,iBAAiB,uBAAoB;UAmCnC;UACA;UACA;UACA;UACA;UACA;UACA;UACA;MAEG,aAAa;UAIhB;EAUD;EA6FA;UAUC;UAuBA;YAKE,wBAAwB,UAAU,0BAC1C,OAAO,GACP,SAAS,4BAA4B;EAQhC,YAAY,UAAU,0BAC3B,OAAO,GACP,UAAU,6BAA6B"}
|
|
@@ -83,6 +83,18 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
83
83
|
_isSending = false;
|
|
84
84
|
_removedDuringSend = /* @__PURE__ */ new Set();
|
|
85
85
|
_sendGeneration = 0;
|
|
86
|
+
_attachmentAddOperations = /* @__PURE__ */ new Set();
|
|
87
|
+
_cancelAttachmentAdd(attachmentId) {
|
|
88
|
+
for (const operation of [...this._attachmentAddOperations]) {
|
|
89
|
+
if (!operation.attachmentIds.has(attachmentId)) continue;
|
|
90
|
+
operation.cancelled = true;
|
|
91
|
+
this._attachmentAddOperations.delete(operation);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_cancelAllAttachmentAdds() {
|
|
95
|
+
for (const operation of this._attachmentAddOperations) operation.cancelled = true;
|
|
96
|
+
this._attachmentAddOperations.clear();
|
|
97
|
+
}
|
|
86
98
|
_emptyTextAndAttachments() {
|
|
87
99
|
this._attachments = [];
|
|
88
100
|
this._text = "";
|
|
@@ -96,6 +108,7 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
96
108
|
}
|
|
97
109
|
}
|
|
98
110
|
async reset() {
|
|
111
|
+
this._cancelAllAttachmentAdds();
|
|
99
112
|
this._sendGeneration++;
|
|
100
113
|
this._isSending = false;
|
|
101
114
|
this._removedDuringSend.clear();
|
|
@@ -108,6 +121,7 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
108
121
|
await task;
|
|
109
122
|
}
|
|
110
123
|
async clearAttachments() {
|
|
124
|
+
this._cancelAllAttachmentAdds();
|
|
111
125
|
const task = this._onClearAttachments();
|
|
112
126
|
this.setAttachments([]);
|
|
113
127
|
await task;
|
|
@@ -206,16 +220,6 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
206
220
|
this._notifyEventSubscribers("attachmentAdd", {});
|
|
207
221
|
return;
|
|
208
222
|
}
|
|
209
|
-
const upsertAttachment = (a) => {
|
|
210
|
-
const idx = this._attachments.findIndex((attachment) => attachment.id === a.id);
|
|
211
|
-
if (idx !== -1) this._attachments = [
|
|
212
|
-
...this._attachments.slice(0, idx),
|
|
213
|
-
a,
|
|
214
|
-
...this._attachments.slice(idx + 1)
|
|
215
|
-
];
|
|
216
|
-
else this._attachments = [...this._attachments, a];
|
|
217
|
-
this._notifySubscribers();
|
|
218
|
-
};
|
|
219
223
|
const adapter = this.getAttachmentAdapter();
|
|
220
224
|
if (!adapter) {
|
|
221
225
|
const message = "Attachments are not supported";
|
|
@@ -232,18 +236,38 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
232
236
|
this._safeEmitAttachmentAddError("not-accepted", message, void 0, err);
|
|
233
237
|
throw err;
|
|
234
238
|
}
|
|
239
|
+
const operation = {
|
|
240
|
+
cancelled: false,
|
|
241
|
+
attachmentIds: /* @__PURE__ */ new Set()
|
|
242
|
+
};
|
|
243
|
+
const operations = this._attachmentAddOperations;
|
|
244
|
+
operations.add(operation);
|
|
245
|
+
const upsertAttachment = (a) => {
|
|
246
|
+
if (operation.cancelled) return false;
|
|
247
|
+
operation.attachmentIds.add(a.id);
|
|
248
|
+
const idx = this._attachments.findIndex((attachment) => attachment.id === a.id);
|
|
249
|
+
if (idx !== -1) this._attachments = [
|
|
250
|
+
...this._attachments.slice(0, idx),
|
|
251
|
+
a,
|
|
252
|
+
...this._attachments.slice(idx + 1)
|
|
253
|
+
];
|
|
254
|
+
else this._attachments = [...this._attachments, a];
|
|
255
|
+
this._notifySubscribers();
|
|
256
|
+
return true;
|
|
257
|
+
};
|
|
235
258
|
let lastAttachment;
|
|
236
259
|
try {
|
|
237
260
|
const promiseOrGenerator = adapter.add({ file: fileOrAttachment });
|
|
238
261
|
if (Symbol.asyncIterator in promiseOrGenerator) for await (const r of promiseOrGenerator) {
|
|
239
262
|
lastAttachment = r;
|
|
240
|
-
upsertAttachment(r);
|
|
263
|
+
if (!upsertAttachment(r)) break;
|
|
241
264
|
}
|
|
242
265
|
else {
|
|
243
266
|
lastAttachment = await promiseOrGenerator;
|
|
244
267
|
upsertAttachment(lastAttachment);
|
|
245
268
|
}
|
|
246
269
|
} catch (e) {
|
|
270
|
+
if (operation.cancelled) return;
|
|
247
271
|
if (lastAttachment) upsertAttachment({
|
|
248
272
|
...lastAttachment,
|
|
249
273
|
status: {
|
|
@@ -254,7 +278,10 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
254
278
|
});
|
|
255
279
|
this._safeEmitAttachmentAddError("adapter-error", e instanceof Error ? e.message : String(e), lastAttachment?.id, e instanceof Error ? e : void 0);
|
|
256
280
|
throw e;
|
|
281
|
+
} finally {
|
|
282
|
+
operations.delete(operation);
|
|
257
283
|
}
|
|
284
|
+
if (operation.cancelled) return;
|
|
258
285
|
if (lastAttachment?.status.type === "incomplete" && lastAttachment.status.reason === "error") this._safeEmitAttachmentAddError("adapter-error", lastAttachment.status.message ?? "Attachment upload did not complete successfully.", lastAttachment.id);
|
|
259
286
|
else this._notifyEventSubscribers("attachmentAdd", {});
|
|
260
287
|
}
|
|
@@ -274,11 +301,26 @@ var BaseComposerRuntimeCore = class extends BaseSubscribable {
|
|
|
274
301
|
const index = this._attachments.findIndex((a) => a.id === attachmentId);
|
|
275
302
|
if (index === -1) throw new Error("Attachment not found");
|
|
276
303
|
const attachment = this._attachments[index];
|
|
304
|
+
this._cancelAttachmentAdd(attachmentId);
|
|
277
305
|
if (this._isSending) this._removedDuringSend.add(attachmentId);
|
|
278
306
|
if (!isAttachmentComplete(attachment)) {
|
|
279
307
|
const adapter = this.getAttachmentAdapter();
|
|
280
308
|
if (!adapter) throw new Error("Attachments are not supported");
|
|
281
|
-
|
|
309
|
+
try {
|
|
310
|
+
await adapter.remove(attachment);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
313
|
+
this._attachments = this._attachments.map((candidate) => candidate.id === attachmentId && !isAttachmentComplete(candidate) ? {
|
|
314
|
+
...candidate,
|
|
315
|
+
status: {
|
|
316
|
+
type: "incomplete",
|
|
317
|
+
reason: "error",
|
|
318
|
+
message
|
|
319
|
+
}
|
|
320
|
+
} : candidate);
|
|
321
|
+
this._notifySubscribers();
|
|
322
|
+
throw error;
|
|
323
|
+
}
|
|
282
324
|
}
|
|
283
325
|
this._attachments = this._attachments.filter((a) => a.id !== attachmentId);
|
|
284
326
|
this._notifySubscribers();
|