@assistant-ui/core 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/index.d.ts +4 -4
  2. package/dist/index.js.map +1 -1
  3. package/dist/internal.d.ts +6 -6
  4. package/dist/internal.js +5 -5
  5. package/dist/react/primitive-hooks/useActionBarCopy.js +51 -24
  6. package/dist/react/primitive-hooks/useActionBarCopy.js.map +1 -1
  7. package/dist/react/primitives/message/MessageGroupedParts.d.ts +2 -1
  8. package/dist/react/primitives/message/MessageGroupedParts.d.ts.map +1 -1
  9. package/dist/react/primitives/message/MessageGroupedParts.js +2 -2
  10. package/dist/react/primitives/message/MessageGroupedParts.js.map +1 -1
  11. package/dist/react/runtimes/cloud/auiV0.d.ts +24 -2
  12. package/dist/react/runtimes/cloud/auiV0.d.ts.map +1 -1
  13. package/dist/react/runtimes/cloud/auiV0.js +24 -5
  14. package/dist/react/runtimes/cloud/auiV0.js.map +1 -1
  15. package/dist/runtime/api/message-runtime.d.ts.map +1 -1
  16. package/dist/runtime/api/message-runtime.js +5 -1
  17. package/dist/runtime/api/message-runtime.js.map +1 -1
  18. package/dist/runtime/internal.d.ts +4 -4
  19. package/dist/runtime/internal.js +4 -4
  20. package/dist/store/clients/chain-of-thought-client.d.ts.map +1 -1
  21. package/dist/store/clients/chain-of-thought-client.js +29 -23
  22. package/dist/store/clients/chain-of-thought-client.js.map +1 -1
  23. package/dist/store/clients/thread-message-client.d.ts.map +1 -1
  24. package/dist/store/clients/thread-message-client.js +101 -89
  25. package/dist/store/clients/thread-message-client.js.map +1 -1
  26. package/dist/types/index.d.ts +2 -2
  27. package/dist/types/message.d.ts +11 -1
  28. package/dist/types/message.d.ts.map +1 -1
  29. package/dist/types/message.js.map +1 -1
  30. package/dist/utils/getGroupStatus.d.ts +9 -0
  31. package/dist/utils/getGroupStatus.d.ts.map +1 -0
  32. package/dist/utils/getGroupStatus.js +15 -0
  33. package/dist/utils/getGroupStatus.js.map +1 -0
  34. package/dist/utils/normalizePartStatus.d.ts +8 -0
  35. package/dist/utils/normalizePartStatus.d.ts.map +1 -0
  36. package/dist/utils/normalizePartStatus.js +39 -0
  37. package/dist/utils/normalizePartStatus.js.map +1 -0
  38. package/package.json +2 -2
  39. package/src/index.ts +1 -0
  40. package/src/internal.ts +1 -0
  41. package/src/react/primitive-hooks/useActionBarCopy.test.ts +109 -14
  42. package/src/react/primitive-hooks/useActionBarCopy.ts +27 -2
  43. package/src/react/primitives/message/MessageGroupedParts.tsx +4 -4
  44. package/src/react/runtimes/cloud/auiV0.ts +51 -12
  45. package/src/runtime/api/message-runtime.test.ts +140 -0
  46. package/src/runtime/api/message-runtime.ts +10 -5
  47. package/src/store/clients/chain-of-thought-client.ts +2 -7
  48. package/src/store/clients/thread-message-client.test.ts +84 -0
  49. package/src/store/clients/thread-message-client.ts +14 -4
  50. package/src/tests/auiV0Encode.test.ts +93 -0
  51. package/src/types/index.ts +1 -0
  52. package/src/types/message.ts +19 -0
  53. package/src/utils/getGroupStatus.test.ts +36 -0
  54. package/src/utils/getGroupStatus.ts +31 -0
  55. package/src/utils/normalizePartStatus.test.ts +59 -0
  56. package/src/utils/normalizePartStatus.ts +55 -0
@@ -1 +1 @@
1
- {"version":3,"file":"auiV0.js","names":["DataMessagePart","FileMessagePart","ImageMessagePart","MessageStatus","SourceProviderMetadata","ThreadMessage","TextMessagePart","ToolApprovalOption","Unstable_AudioMessagePart","CompleteAttachment","fromThreadMessageLike","CloudMessage","isJSONValue","ReadonlyJSONObject","ReadonlyJSONValue","ExportedMessageRepositoryItem","AuiV0ToolApproval","id","approved","reason","isAutomatic","options","optionId","resolution","AuiV0MessagePart","type","text","sourceType","url","title","providerMetadata","mediaType","filename","toolCallId","toolName","args","result","isError","approval","argsText","image","data","mimeType","AuiV0AttachmentPart","AuiV0Attachment","name","contentType","status","content","AuiV0Message","role","attachments","metadata","unstable_state","unstable_annotations","unstable_data","steps","usage","inputTokens","outputTokens","custom","encodeAttachmentPart","part","console","warn","JSON","stringify","unhandledType","Error","encodeAttachments","message","length","undefined","map","auiV0Encode","auiV0Decode","cloudMessage","format","payload","createdAt","created_at","parentId","parent_id"],"sources":["../../../../src/react/runtimes/cloud/auiV0.ts"],"sourcesContent":["import type {\n DataMessagePart,\n FileMessagePart,\n ImageMessagePart,\n MessageStatus,\n SourceProviderMetadata,\n ThreadMessage,\n TextMessagePart,\n ToolApprovalOption,\n Unstable_AudioMessagePart,\n} from \"../../../types/message\";\nimport type { CompleteAttachment } from \"../../../types/attachment\";\nimport { fromThreadMessageLike } from \"../../../runtime/utils/thread-message-like\";\nimport type { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"../../../utils/json/is-json\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ExportedMessageRepositoryItem } from \"../../../runtime/utils/message-repository\";\n\ntype AuiV0ToolApproval = {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n readonly options?: readonly ToolApprovalOption[];\n readonly optionId?: string;\n readonly resolution?: \"cancelled\" | \"expired\";\n};\n\ntype AuiV0MessagePart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: ReadonlyJSONObject;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly argsText: string;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n };\n\ntype AuiV0AttachmentPart =\n | TextMessagePart\n | ImageMessagePart\n | FileMessagePart\n | Unstable_AudioMessagePart\n | DataMessagePart<ReadonlyJSONValue>;\n\ntype AuiV0Attachment = {\n readonly id: string;\n readonly type: CompleteAttachment[\"type\"];\n readonly name: string;\n readonly contentType?: string;\n readonly status: CompleteAttachment[\"status\"];\n readonly content: readonly AuiV0AttachmentPart[];\n};\n\ntype AuiV0Message = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly status?: MessageStatus;\n readonly content: readonly AuiV0MessagePart[];\n readonly attachments?: readonly AuiV0Attachment[];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly {\n readonly usage?: {\n readonly inputTokens: number;\n readonly outputTokens: number;\n };\n }[];\n readonly custom: ReadonlyJSONObject;\n };\n};\n\nconst encodeAttachmentPart = (\n part: CompleteAttachment[\"content\"][number],\n): AuiV0AttachmentPart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n case \"image\":\n case \"file\":\n case \"audio\":\n return part;\n\n case \"data\": {\n if (!isJSONValue(part.data)) {\n console.warn(`attachment data is not JSON! ${JSON.stringify(part)}`);\n }\n return { ...part, data: part.data as ReadonlyJSONValue };\n }\n\n default: {\n const unhandledType: never = type;\n throw new Error(\n `Attachment part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n};\n\nconst encodeAttachments = (\n message: ThreadMessage,\n): readonly AuiV0Attachment[] | undefined => {\n if (message.role !== \"user\" || message.attachments.length === 0) {\n return undefined;\n }\n\n return message.attachments.map(\n ({ id, type, name, contentType, status, content }) => ({\n id,\n type,\n name,\n status,\n ...(contentType != null ? { contentType } : undefined),\n content: content.map(encodeAttachmentPart),\n }),\n );\n};\n\nexport function auiV0Encode(message: ThreadMessage): AuiV0Message {\n // info: ID and createdAt are ignored (we use the server value instead)\n const status: MessageStatus | undefined =\n message.status?.type === \"running\"\n ? { type: \"incomplete\", reason: \"cancelled\" }\n : message.status;\n const attachments = encodeAttachments(message);\n\n return {\n role: message.role,\n content: message.content.map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"reasoning\":\n return { type: \"reasoning\", text: part.text };\n\n case \"source\":\n if (part.sourceType === \"url\") {\n return {\n type: \"source\",\n sourceType: \"url\",\n id: part.id,\n url: part.url,\n ...(part.title != null ? { title: part.title } : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n }\n\n return {\n type: \"source\",\n sourceType: \"document\",\n id: part.id,\n title: part.title,\n mediaType: part.mediaType,\n ...(part.filename != null\n ? { filename: part.filename }\n : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n\n case \"tool-call\": {\n if (!isJSONValue(part.result)) {\n console.warn(\n `tool-call result is not JSON! ${JSON.stringify(part)}`,\n );\n }\n return {\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n ...(JSON.stringify(part.args) === part.argsText\n ? { args: part.args }\n : { argsText: part.argsText }),\n ...(part.result\n ? { result: part.result as ReadonlyJSONValue }\n : undefined),\n ...(part.isError ? { isError: true } : undefined),\n ...(part.approval ? { approval: part.approval } : undefined),\n };\n }\n\n case \"image\":\n return { type: \"image\", image: part.image };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename ? { filename: part.filename } : undefined),\n };\n\n default: {\n const unhandledType: \"audio\" | \"data\" | \"generative-ui\" = type;\n throw new Error(\n `Message part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n }),\n metadata: message.metadata as AuiV0Message[\"metadata\"],\n ...(status ? { status } : undefined),\n ...(attachments ? { attachments } : undefined),\n };\n}\n\nexport function auiV0Decode(\n cloudMessage: CloudMessage & { format: \"aui/v0\" },\n): ExportedMessageRepositoryItem {\n const payload = cloudMessage.content as unknown as AuiV0Message;\n const message = fromThreadMessageLike(\n {\n id: cloudMessage.id,\n createdAt: cloudMessage.created_at,\n ...payload,\n },\n cloudMessage.id,\n { type: \"complete\", reason: \"unknown\" },\n );\n\n return {\n parentId: cloudMessage.parent_id,\n message,\n };\n}\n"],"mappings":";;;AAyHA,MAAM6D,wBACJC,SACwB;CACxB,MAAMrC,OAAOqC,KAAKrC;CAClB,QAAQA,MAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,OAAOqC;EAET,KAAK;GACH,IAAI,CAAClD,YAAYkD,KAAKrB,IAAI,GACxBsB,QAAQC,KAAK,gCAAgCC,KAAKC,UAAUJ,IAAI,GAAG;GAErE,OAAO;IAAE,GAAGA;IAAMrB,MAAMqB,KAAKrB;GAA0B;EAGzD,SAEE,MAAM,IAAI2B,MACR,iDAAiDD,MACnD;CAEJ;AACF;AAEA,MAAME,qBACJC,YAC2C;CAC3C,IAAIA,QAAQpB,SAAS,UAAUoB,QAAQnB,YAAYoB,WAAW,GAC5D;CAGF,OAAOD,QAAQnB,YAAYsB,KACxB,EAAExD,IAAIQ,MAAMoB,MAAMC,aAAaC,QAAQC,eAAe;EACrD/B;EACAQ;EACAoB;EACAE;EACA,GAAID,eAAe,OAAO,EAAEA,YAAY,IAAI0B,KAAAA;EAC5CxB,SAASA,QAAQyB,IAAIZ,oBAAoB;CAC3C,EACF;AACF;AAEA,SAAgBa,YAAYJ,SAAsC;CAEhE,MAAMvB,SACJuB,QAAQvB,QAAQtB,SAAS,YACrB;EAAEA,MAAM;EAAcN,QAAQ;CAAY,IAC1CmD,QAAQvB;CACd,MAAMI,cAAckB,kBAAkBC,OA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KAAAA;MACJ,GAAIV,KAAKzB,UAAU,EAAEA,SAAS,KAAK,IAAImC,KAAAA;MACvC,GAAIV,KAAKxB,WAAW,EAAEA,UAAUwB,KAAKxB,SAAS,IAAIkC,KAAAA;KACpD;IAGF,KAAK,SACH,OAAO;KAAE/C,MAAM;KAASe,OAAOsB,KAAKtB;IAAM;IAE5C,KAAK,QACH,OAAO;KACLf,MAAM;KACNgB,MAAMqB,KAAKrB;KACXC,UAAUoB,KAAKpB;KACf,GAAIoB,KAAK9B,WAAW,EAAEA,UAAU8B,KAAK9B,SAAS,IAAIwC,KAAAA;IACpD;IAEF,SAEE,MAAM,IAAIJ,MACR,8CAA8CD,MAChD;GAEJ;EACF,CAAC;EACDf,UAAUkB,QAAQlB;EAClB,GAAIL,SAAS,EAAEA,OAAO,IAAIyB,KAAAA;EAC1B,GAAIrB,cAAc,EAAEA,YAAY,IAAIqB,KAAAA;CACtC;AACF;AAEA,SAAgBG,YACdC,cAC+B;CAC/B,MAAME,UAAUF,aAAa5B;CAC7B,MAAMsB,UAAU5D,sBACd;EACEO,IAAI2D,aAAa3D;EACjB8D,WAAWH,aAAaI;EACxB,GAAGF;CACL,GACAF,aAAa3D,IACb;EAAEQ,MAAM;EAAYN,QAAQ;CAAU,CACxC;CAEA,OAAO;EACL8D,UAAUL,aAAaM;EACvBZ;CACF;AACF"}
1
+ {"version":3,"file":"auiV0.js","names":["MessageStatus","SourceProviderMetadata","ThreadMessage","ToolApprovalOption","CompleteAttachment","fromThreadMessageLike","CloudMessage","isJSONValue","ReadonlyJSONObject","ReadonlyJSONValue","ExportedMessageRepositoryItem","AuiV0ToolApproval","id","approved","reason","isAutomatic","options","optionId","resolution","AuiV0MessagePart","type","text","sourceType","url","title","providerMetadata","mediaType","filename","toolCallId","toolName","args","result","isError","approval","argsText","image","data","mimeType","AuiV0AttachmentPart","audio","format","name","AuiV0Attachment","contentType","status","content","AuiV0Message","role","attachments","metadata","unstable_state","unstable_annotations","unstable_data","steps","usage","inputTokens","outputTokens","custom","encodeAttachmentPart","part","undefined","console","warn","JSON","stringify","unhandledType","Error","encodeAttachments","message","length","map","auiV0Encode","auiV0Decode","cloudMessage","payload","createdAt","created_at","parentId","parent_id"],"sources":["../../../../src/react/runtimes/cloud/auiV0.ts"],"sourcesContent":["import type {\n MessageStatus,\n SourceProviderMetadata,\n ThreadMessage,\n ToolApprovalOption,\n} from \"../../../types/message\";\nimport type { CompleteAttachment } from \"../../../types/attachment\";\nimport { fromThreadMessageLike } from \"../../../runtime/utils/thread-message-like\";\nimport type { CloudMessage } from \"assistant-cloud\";\nimport { isJSONValue } from \"../../../utils/json/is-json\";\nimport type {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"assistant-stream/utils\";\nimport type { ExportedMessageRepositoryItem } from \"../../../runtime/utils/message-repository\";\n\ntype AuiV0ToolApproval = {\n readonly id: string;\n readonly approved?: boolean;\n readonly reason?: string;\n readonly isAutomatic?: boolean;\n readonly options?: readonly ToolApprovalOption[];\n readonly optionId?: string;\n readonly resolution?: \"cancelled\" | \"expired\";\n};\n\ntype AuiV0MessagePart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"source\";\n readonly sourceType: \"document\";\n readonly id: string;\n readonly title: string;\n readonly mediaType: string;\n readonly filename?: string;\n readonly providerMetadata?: SourceProviderMetadata;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: ReadonlyJSONObject;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly argsText: string;\n readonly result?: ReadonlyJSONValue;\n readonly isError?: true;\n readonly approval?: AuiV0ToolApproval;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n };\n\ntype AuiV0AttachmentPart =\n | {\n readonly type: \"text\";\n readonly text: string;\n }\n | {\n readonly type: \"image\";\n readonly image: string;\n readonly filename?: string;\n }\n | {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n readonly filename?: string;\n }\n | {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n }\n | {\n readonly type: \"data\";\n readonly name: string;\n readonly data: ReadonlyJSONValue;\n };\n\ntype AuiV0Attachment = {\n readonly id: string;\n readonly type: CompleteAttachment[\"type\"];\n readonly name: string;\n readonly contentType?: string;\n readonly status: CompleteAttachment[\"status\"];\n readonly content: readonly AuiV0AttachmentPart[];\n};\n\ntype AuiV0Message = {\n readonly role: \"assistant\" | \"user\" | \"system\";\n readonly status?: MessageStatus;\n readonly content: readonly AuiV0MessagePart[];\n readonly attachments?: readonly AuiV0Attachment[];\n readonly metadata: {\n readonly unstable_state?: ReadonlyJSONValue;\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly {\n readonly usage?: {\n readonly inputTokens: number;\n readonly outputTokens: number;\n };\n }[];\n readonly custom: ReadonlyJSONObject;\n };\n};\n\nconst encodeAttachmentPart = (\n part: CompleteAttachment[\"content\"][number],\n): AuiV0AttachmentPart => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"image\":\n return {\n type: \"image\",\n image: part.image,\n ...(part.filename != null ? { filename: part.filename } : undefined),\n };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename != null ? { filename: part.filename } : undefined),\n };\n\n case \"audio\":\n return {\n type: \"audio\",\n audio: { data: part.audio.data, format: part.audio.format },\n };\n\n case \"data\": {\n if (!isJSONValue(part.data)) {\n console.warn(`attachment data is not JSON! ${JSON.stringify(part)}`);\n }\n return {\n type: \"data\",\n name: part.name,\n data: part.data as ReadonlyJSONValue,\n };\n }\n\n default: {\n const unhandledType: never = type;\n throw new Error(\n `Attachment part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n};\n\nconst encodeAttachments = (\n message: ThreadMessage,\n): readonly AuiV0Attachment[] | undefined => {\n if (message.role !== \"user\" || message.attachments.length === 0) {\n return undefined;\n }\n\n return message.attachments.map(\n ({ id, type, name, contentType, status, content }) => ({\n id,\n type,\n name,\n status,\n ...(contentType != null ? { contentType } : undefined),\n content: content.map(encodeAttachmentPart),\n }),\n );\n};\n\nexport function auiV0Encode(message: ThreadMessage): AuiV0Message {\n // info: ID and createdAt are ignored (we use the server value instead)\n const status: MessageStatus | undefined =\n message.status?.type === \"running\"\n ? { type: \"incomplete\", reason: \"cancelled\" }\n : message.status;\n const attachments = encodeAttachments(message);\n\n return {\n role: message.role,\n content: message.content.map((part) => {\n const type = part.type;\n switch (type) {\n case \"text\":\n return { type: \"text\", text: part.text };\n\n case \"reasoning\":\n return { type: \"reasoning\", text: part.text };\n\n case \"source\":\n if (part.sourceType === \"url\") {\n return {\n type: \"source\",\n sourceType: \"url\",\n id: part.id,\n url: part.url,\n ...(part.title != null ? { title: part.title } : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n }\n\n return {\n type: \"source\",\n sourceType: \"document\",\n id: part.id,\n title: part.title,\n mediaType: part.mediaType,\n ...(part.filename != null\n ? { filename: part.filename }\n : undefined),\n ...(part.providerMetadata != null\n ? { providerMetadata: part.providerMetadata }\n : undefined),\n };\n\n case \"tool-call\": {\n if (!isJSONValue(part.result)) {\n console.warn(\n `tool-call result is not JSON! ${JSON.stringify(part)}`,\n );\n }\n return {\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n ...(JSON.stringify(part.args) === part.argsText\n ? { args: part.args }\n : { argsText: part.argsText }),\n ...(part.result\n ? { result: part.result as ReadonlyJSONValue }\n : undefined),\n ...(part.isError ? { isError: true } : undefined),\n ...(part.approval ? { approval: part.approval } : undefined),\n };\n }\n\n case \"image\":\n return { type: \"image\", image: part.image };\n\n case \"file\":\n return {\n type: \"file\",\n data: part.data,\n mimeType: part.mimeType,\n ...(part.filename ? { filename: part.filename } : undefined),\n };\n\n default: {\n const unhandledType: \"audio\" | \"data\" | \"generative-ui\" = type;\n throw new Error(\n `Message part type not supported by aui/v0: ${unhandledType}`,\n );\n }\n }\n }),\n metadata: message.metadata as AuiV0Message[\"metadata\"],\n ...(status ? { status } : undefined),\n ...(attachments ? { attachments } : undefined),\n };\n}\n\nexport function auiV0Decode(\n cloudMessage: CloudMessage & { format: \"aui/v0\" },\n): ExportedMessageRepositoryItem {\n const payload = cloudMessage.content as unknown as AuiV0Message;\n const message = fromThreadMessageLike(\n {\n id: cloudMessage.id,\n createdAt: cloudMessage.created_at,\n ...payload,\n },\n cloudMessage.id,\n { type: \"complete\", reason: \"unknown\" },\n );\n\n return {\n parentId: cloudMessage.parent_id,\n message,\n };\n}\n"],"mappings":";;;AA0IA,MAAM0D,wBACJC,SACwB;CACxB,MAAMvC,OAAOuC,KAAKvC;CAClB,QAAQA,MAAR;EACE,KAAK,QACH,OAAO;GAAEA,MAAM;GAAQC,MAAMsC,KAAKtC;EAAK;EAEzC,KAAK,SACH,OAAO;GACLD,MAAM;GACNe,OAAOwB,KAAKxB;GACZ,GAAIwB,KAAKhC,YAAY,OAAO,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;EAC5D;EAEF,KAAK,QACH,OAAO;GACLxC,MAAM;GACNgB,MAAMuB,KAAKvB;GACXC,UAAUsB,KAAKtB;GACf,GAAIsB,KAAKhC,YAAY,OAAO,EAAEA,UAAUgC,KAAKhC,SAAS,IAAIiC,KAAAA;EAC5D;EAEF,KAAK,SACH,OAAO;GACLxC,MAAM;GACNmB,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;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 +1 @@
1
- {"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;cAsCa,sBACX,SAAS,eACT,mBACA,MAAM,wBAAwB,+BAC7B;KAkCS,eAAe;WAChB;;WAEA;WACA;WAEA;WACA;;;;WAKA,QAAQ;;KAKd;EACH,YAAY;;KAGF;WACD,MAAM;WAEN,UAAU;EAEnB,YAAY;EACZ,iBAAiB;EACjB,OAAO,SAAS;;;;EAIhB;;;;EAIA;EACA,iBAAiB;IAAU;;EAC3B,iBACE,UACA;IAEA;IACA;;EAEF;EAEA,UAAU,uBAAuB;EAEjC,sBAAsB,cAAc;EACpC,2BAA2B,qBAAqB;EAEhD,qBAAqB,cAAc;IAAsB;;;cAG9C,8BAA8B;MAC9B,QAAI;UAIP;UACA;EAGN,YAAA,OAAO,qBACP,gBAAgB;YAoBR;WAgBM,UAAQ;UAEhB;EAMD,YAAQ;;;;;;;;EAIR,iBAAM;EAKN,OAAO,eAAc;EAkBrB;EAKA;EAUA,iBAAiB;IAAU;;EAQ3B,iBACL,UACA;IAEA;IACA;;EAsBK;EAIA,UAAU,uBAAoB;EAI9B,sBAAsB,cAAW;EAmBjC,2BAA2B,qBAAkB;EAwB7C,qBAAqB,cAAW"}
1
+ {"version":3,"file":"message-runtime.d.ts","names":[],"sources":["../../../src/runtime/api/message-runtime.ts"],"mappings":";;;;;;;;;;cAsCa,sBACX,SAAS,eACT,mBACA,MAAM,wBAAwB,+BAC7B;KAuCS,eAAe;WAChB;;WAEA;WACA;WAEA;WACA;;;;WAKA,QAAQ;;KAKd;EACH,YAAY;;KAGF;WACD,MAAM;WAEN,UAAU;EAEnB,YAAY;EACZ,iBAAiB;EACjB,OAAO,SAAS;;;;EAIhB;;;;EAIA;EACA,iBAAiB;IAAU;;EAC3B,iBACE,UACA;IAEA;IACA;;EAEF;EAEA,UAAU,uBAAuB;EAEjC,sBAAsB,cAAc;EACpC,2BAA2B,qBAAqB;EAEhD,qBAAqB,cAAc;IAAsB;;;cAG9C,8BAA8B;MAC9B,QAAI;UAIP;UACA;EAGN,YAAA,OAAO,qBACP,gBAAgB;YAoBR;WAgBM,UAAQ;UAEhB;EAMD,YAAQ;;;;;;;;EAIR,iBAAM;EAKN,OAAO,eAAc;EAkBrB;EAKA;EAUA,iBAAiB;IAAU;;EAQ3B,iBACL,UACA;IAEA;IACA;;EAsBK;EAIA,UAAU,uBAAoB;EAI9B,sBAAsB,cAAW;EAmBjC,2BAA2B,qBAAkB;EAwB7C,qBAAqB,cAAW"}
@@ -1,15 +1,19 @@
1
1
  import { getThreadMessageText } from "../../utils/text.js";
2
2
  import { symbolInnerMessage } from "../utils/external-store-message.js";
3
3
  import { NestedSubscriptionSubject, SKIP_UPDATE, ShallowMemoizeSubject } from "../../subscribable/subscribable.js";
4
+ import { COMPLETE_STATUS, normalizePartStatus } from "../../utils/normalizePartStatus.js";
4
5
  import { MessageAttachmentRuntimeImpl } from "./attachment-runtime.js";
5
6
  import { EditComposerRuntimeImpl } from "./composer-runtime.js";
6
7
  import { MessagePartRuntimeImpl } from "./message-part-runtime.js";
7
8
  //#region src/runtime/api/message-runtime.ts
8
- const COMPLETE_STATUS = Object.freeze({ type: "complete" });
9
9
  const toMessagePartStatus = (message, partIndex, part) => {
10
10
  if (message.role !== "assistant") return COMPLETE_STATUS;
11
11
  if (part.type === "tool-call") if (!part.result) return message.status;
12
12
  else return COMPLETE_STATUS;
13
+ if (message.status.type === "running") {
14
+ const status = normalizePartStatus(part);
15
+ if (status) return status;
16
+ }
13
17
  const isLastPart = partIndex === Math.max(0, message.content.length - 1);
14
18
  if (message.status.type === "requires-action") return COMPLETE_STATUS;
15
19
  return isLastPart ? message.status : COMPLETE_STATUS;
@@ -1 +1 @@
1
- {"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ToolCallMessagePartStatus","ThreadMessage","ThreadAssistantMessagePart","ThreadUserMessagePart","Unsubscribe","MessagePartStatus","RunConfig","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","COMPLETE_STATUS","Object","freeze","type","toMessagePartStatus","message","partIndex","part","role","result","status","isLastPart","Math","max","content","length","getMessagePartState","MessageState","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","_threadBinding","constructor","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type {\n ToolCallMessagePartStatus,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallMessagePartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n /** The position of this message in the thread (0 for first message) */\n readonly index: number;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport type { MessageStateBinding } from \"./bindings\";\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n delete(): void | Promise<void>;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n private _core: MessageStateBinding;\n private _threadBinding: ThreadRuntimeCoreBinding;\n\n constructor(\n _core: MessageStateBinding,\n _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadBinding = _threadBinding;\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getMessagePartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;AAkCA,MAAMwB,kBAAqCC,OAAOC,OAAO,EACvDC,MAAM,WACR,CAAC;AAED,MAAaC,uBACXC,SACAC,WACAC,SAC8B;CAC9B,IAAIF,QAAQG,SAAS,aAAa,OAAOR;CAEzC,IAAIO,KAAKJ,SAAS,aAChB,IAAI,CAACI,KAAKE,QACR,OAAOJ,QAAQK;MAEf,OAAOV;CAIX,MAAMW,aAAaL,cAAcM,KAAKC,IAAI,GAAGR,QAAQS,QAAQC,SAAS,CAAC;CACvE,IAAIV,QAAQK,OAAOP,SAAS,mBAAmB,OAAOH;CACtD,OAAOW,aAAcN,QAAQK,SAA+BV;AAC9D;AAEA,MAAMgB,uBACJX,SACAC,cACmC;CACnC,MAAMC,OAAOF,QAAQS,QAAQR;CAC7B,IAAI,CAACC,MACH,OAAOpB;CAIT,MAAMuB,SAASN,oBAAoBC,SAASC,WAAWC,IAAI;CAC3D,OAAON,OAAOC,OAAO;EACnB,GAAGK;GACG9B,qBAAsB8B,KAAa9B;EACzCiC;CACF,CAAC;AACH;AAyDA,IAAauC,qBAAb,MAA0D;CACxD,IAAWtB,OAAO;EAChB,OAAO,KAAKuB,MAAMvB;CACpB;CAEA;CACA;CAEAyB,YACEF,OACAC,gBACA;EACA,KAAKD,QAAQA;EACb,KAAKC,iBAAiBA;EACtB,KAAKvB,WAAW,IAAInC,wBAClB,IAAIP,0BAA0B;GAC5ByC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG;IACrBC,gBAAgB;GAClB;GACAzB,UAAU,KAAK0B;GACfd,YAAYC,aAAa,KAAKS,eAAeV,UAAUC,QAAQ;EACjE,CAAC,SACK,KAAKS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sB;GACxBuC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG,eAAgBT,IAAG;IACxCkC,kBAAkB;IAClBC,oBAAoB;KAAE5E,MAAM;KAASgB,OAAOyB;IAAI;GAClD;GACAf,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACmD,cACHpC;IACjC,IAAI,CAACqC,YAAY,OAAO9F;IAExB,OAAO;KACL,GAAG8F;KACHjC,QAAQ;IACV;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
1
+ {"version":3,"file":"message-runtime.js","names":["SpeechState","symbolInnerMessage","ToolCallMessagePartStatus","ThreadMessage","ThreadAssistantMessagePart","ThreadUserMessagePart","Unsubscribe","MessagePartStatus","RunConfig","COMPLETE_STATUS","normalizePartStatus","getThreadMessageText","NestedSubscriptionSubject","SKIP_UPDATE","ShallowMemoizeSubject","AttachmentRuntime","AttachmentState","MessageAttachmentRuntimeImpl","EditComposerRuntime","EditComposerRuntimeImpl","MessagePartRuntime","MessagePartRuntimeImpl","MessagePartState","MessageRuntimePath","ThreadRuntimeCoreBinding","MessageStateBinding","toMessagePartStatus","message","partIndex","part","role","type","result","status","isLastPart","Math","max","content","length","getMessagePartState","MessageState","Object","freeze","parentId","index","isLast","branchNumber","branchCount","speech","ReloadConfig","runConfig","MessageRuntime","path","composer","getState","delete","Promise","reload","config","speak","stopSpeaking","submitFeedback","switchToBranch","position","branchId","unstable_getCopyText","subscribe","callback","getMessagePartByIndex","idx","getMessagePartByToolCallId","toolCallId","getAttachmentByIndex","source","MessageRuntimeImpl","_core","_threadBinding","constructor","ref","composerSource","_getEditComposerRuntimeCore","beginEdit","id","__internal_bindMethods","bind","getEditComposer","state","deleteMessage","reloadConfig","editComposerRuntimeCore","composerRuntimeCore","Error","startRun","sourceId","thread","messageId","branches","getBranches","targetBranch","messagePartSelector","JSON","stringify","findIndex","attachmentSource","attachmentSelector","attachments","attachment"],"sources":["../../../src/runtime/api/message-runtime.ts"],"sourcesContent":["import type { SpeechState } from \"../interfaces/thread-runtime-core\";\nimport { symbolInnerMessage } from \"../utils/external-store-message\";\nimport type {\n ToolCallMessagePartStatus,\n ThreadMessage,\n ThreadAssistantMessagePart,\n ThreadUserMessagePart,\n} from \"../../types/message\";\nimport type { Unsubscribe } from \"../../types/unsubscribe\";\nimport type { MessagePartStatus, RunConfig } from \"../../types/message\";\nimport {\n COMPLETE_STATUS,\n normalizePartStatus,\n} from \"../../utils/normalizePartStatus\";\nimport { getThreadMessageText } from \"../../utils/text\";\nimport { NestedSubscriptionSubject } from \"../../subscribable/subscribable\";\nimport {\n SKIP_UPDATE,\n ShallowMemoizeSubject,\n} from \"../../subscribable/subscribable\";\nimport {\n type AttachmentRuntime,\n type AttachmentState,\n MessageAttachmentRuntimeImpl,\n} from \"./attachment-runtime\";\nimport {\n type EditComposerRuntime,\n EditComposerRuntimeImpl,\n} from \"./composer-runtime\";\nimport {\n type MessagePartRuntime,\n MessagePartRuntimeImpl,\n type MessagePartState,\n} from \"./message-part-runtime\";\nimport type { MessageRuntimePath } from \"./paths\";\nimport type { ThreadRuntimeCoreBinding } from \"./thread-runtime\";\nimport type { MessageStateBinding } from \"./bindings\";\n\nexport const toMessagePartStatus = (\n message: ThreadMessage,\n partIndex: number,\n part: ThreadUserMessagePart | ThreadAssistantMessagePart,\n): ToolCallMessagePartStatus => {\n if (message.role !== \"assistant\") return COMPLETE_STATUS;\n\n if (part.type === \"tool-call\") {\n if (!part.result) {\n return message.status as ToolCallMessagePartStatus;\n } else {\n return COMPLETE_STATUS;\n }\n }\n\n if (message.status.type === \"running\") {\n const status = normalizePartStatus(part);\n if (status) return status;\n }\n\n const isLastPart = partIndex === Math.max(0, message.content.length - 1);\n if (message.status.type === \"requires-action\") return COMPLETE_STATUS;\n return isLastPart ? (message.status as MessagePartStatus) : COMPLETE_STATUS;\n};\n\nconst getMessagePartState = (\n message: MessageState,\n partIndex: number,\n): MessagePartState | SKIP_UPDATE => {\n const part = message.content[partIndex];\n if (!part) {\n return SKIP_UPDATE;\n }\n\n // if the message part is the same, don't update\n const status = toMessagePartStatus(message, partIndex, part);\n return Object.freeze({\n ...part,\n ...{ [symbolInnerMessage]: (part as any)[symbolInnerMessage] },\n status: status as MessagePartStatus,\n });\n};\n\nexport type MessageState = ThreadMessage & {\n readonly parentId: string | null;\n /** The position of this message in the thread (0 for first message) */\n readonly index: number;\n readonly isLast: boolean;\n\n readonly branchNumber: number;\n readonly branchCount: number;\n\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n readonly speech: SpeechState | undefined;\n};\n\nexport type { MessageStateBinding } from \"./bindings\";\n\ntype ReloadConfig = {\n runConfig?: RunConfig;\n};\n\nexport type MessageRuntime = {\n readonly path: MessageRuntimePath;\n\n readonly composer: EditComposerRuntime;\n\n getState(): MessageState;\n delete(): void | Promise<void>;\n reload(config?: ReloadConfig): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n speak(): void;\n /**\n * @deprecated This API is still under active development and might change without notice.\n */\n stopSpeaking(): void;\n submitFeedback({ type }: { type: \"positive\" | \"negative\" }): void;\n switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }): void;\n unstable_getCopyText(): string;\n\n subscribe(callback: () => void): Unsubscribe;\n\n getMessagePartByIndex(idx: number): MessagePartRuntime;\n getMessagePartByToolCallId(toolCallId: string): MessagePartRuntime;\n\n getAttachmentByIndex(idx: number): AttachmentRuntime & { source: \"message\" };\n};\n\nexport class MessageRuntimeImpl implements MessageRuntime {\n public get path() {\n return this._core.path;\n }\n\n private _core: MessageStateBinding;\n private _threadBinding: ThreadRuntimeCoreBinding;\n\n constructor(\n _core: MessageStateBinding,\n _threadBinding: ThreadRuntimeCoreBinding,\n ) {\n this._core = _core;\n this._threadBinding = _threadBinding;\n this.composer = new EditComposerRuntimeImpl(\n new NestedSubscriptionSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.composer`,\n composerSource: \"edit\",\n },\n getState: this._getEditComposerRuntimeCore,\n subscribe: (callback) => this._threadBinding.subscribe(callback),\n }),\n () => this._threadBinding.getState().beginEdit(this._core.getState().id),\n );\n\n this.__internal_bindMethods();\n }\n\n protected __internal_bindMethods() {\n this.reload = this.reload.bind(this);\n this.delete = this.delete.bind(this);\n this.getState = this.getState.bind(this);\n this.subscribe = this.subscribe.bind(this);\n this.getMessagePartByIndex = this.getMessagePartByIndex.bind(this);\n this.getMessagePartByToolCallId =\n this.getMessagePartByToolCallId.bind(this);\n this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);\n this.unstable_getCopyText = this.unstable_getCopyText.bind(this);\n this.speak = this.speak.bind(this);\n this.stopSpeaking = this.stopSpeaking.bind(this);\n this.submitFeedback = this.submitFeedback.bind(this);\n this.switchToBranch = this.switchToBranch.bind(this);\n }\n\n public readonly composer;\n\n private _getEditComposerRuntimeCore = () => {\n return this._threadBinding\n .getState()\n .getEditComposer(this._core.getState().id);\n };\n\n public getState() {\n return this._core.getState();\n }\n\n public delete() {\n const state = this._core.getState();\n return this._threadBinding.getState().deleteMessage(state.id);\n }\n\n public reload(reloadConfig: ReloadConfig = {}) {\n const editComposerRuntimeCore = this._getEditComposerRuntimeCore();\n const composerRuntimeCore =\n editComposerRuntimeCore ?? this._threadBinding.getState().composer;\n const composer = editComposerRuntimeCore ?? composerRuntimeCore;\n\n const { runConfig = composer.runConfig } = reloadConfig;\n const state = this._core.getState();\n if (state.role !== \"assistant\")\n throw new Error(\"Can only reload assistant messages\");\n\n this._threadBinding.getState().startRun({\n parentId: state.parentId,\n sourceId: state.id,\n runConfig,\n });\n }\n\n public speak() {\n const state = this._core.getState();\n return this._threadBinding.getState().speak(state.id);\n }\n\n public stopSpeaking() {\n const state = this._core.getState();\n const thread = this._threadBinding.getState();\n if (thread.speech?.messageId === state.id) {\n this._threadBinding.getState().stopSpeaking();\n } else {\n throw new Error(\"Message is not being spoken\");\n }\n }\n\n public submitFeedback({ type }: { type: \"positive\" | \"negative\" }) {\n const state = this._core.getState();\n this._threadBinding.getState().submitFeedback({\n messageId: state.id,\n type,\n });\n }\n\n public switchToBranch({\n position,\n branchId,\n }: {\n position?: \"previous\" | \"next\" | undefined;\n branchId?: string | undefined;\n }) {\n const state = this._core.getState();\n if (branchId && position) {\n throw new Error(\"May not specify both branchId and position\");\n } else if (!branchId && !position) {\n throw new Error(\"Must specify either branchId or position\");\n }\n\n const thread = this._threadBinding.getState();\n const branches = thread.getBranches(state.id);\n let targetBranch = branchId;\n if (position === \"previous\") {\n targetBranch = branches[state.branchNumber - 2];\n } else if (position === \"next\") {\n targetBranch = branches[state.branchNumber];\n }\n if (!targetBranch) throw new Error(\"Branch not found\");\n\n this._threadBinding.getState().switchToBranch(targetBranch);\n }\n\n public unstable_getCopyText() {\n return getThreadMessageText(this.getState());\n }\n\n public subscribe(callback: () => void) {\n return this._core.subscribe(callback);\n }\n\n public getMessagePartByIndex(idx: number) {\n if (idx < 0) throw new Error(\"Message part index must be >= 0\");\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[${idx}]`,\n messagePartSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n return getMessagePartState(this.getState(), idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getMessagePartByToolCallId(toolCallId: string) {\n return new MessagePartRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.content[toolCallId=${JSON.stringify(toolCallId)}]`,\n messagePartSelector: { type: \"toolCallId\", toolCallId },\n },\n getState: () => {\n const state = this._core.getState();\n const idx = state.content.findIndex(\n (part) =>\n part.type === \"tool-call\" && part.toolCallId === toolCallId,\n );\n if (idx === -1) return SKIP_UPDATE;\n return getMessagePartState(state, idx);\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n this._core,\n this._threadBinding,\n );\n }\n\n public getAttachmentByIndex(idx: number) {\n return new MessageAttachmentRuntimeImpl(\n new ShallowMemoizeSubject({\n path: {\n ...this.path,\n ref: `${this.path.ref}.attachments[${idx}]`,\n attachmentSource: \"message\",\n attachmentSelector: { type: \"index\", index: idx },\n },\n getState: () => {\n const attachments = this.getState().attachments;\n const attachment = attachments?.[idx];\n if (!attachment) return SKIP_UPDATE;\n\n return {\n ...attachment,\n source: \"message\",\n } satisfies AttachmentState & { source: \"message\" };\n },\n subscribe: (callback) => this._core.subscribe(callback),\n }),\n );\n }\n}\n"],"mappings":";;;;;;;;AAsCA,MAAa0B,uBACXC,SACAC,WACAC,SAC8B;CAC9B,IAAIF,QAAQG,SAAS,aAAa,OAAOrB;CAEzC,IAAIoB,KAAKE,SAAS,aAChB,IAAI,CAACF,KAAKG,QACR,OAAOL,QAAQM;MAEf,OAAOxB;CAIX,IAAIkB,QAAQM,OAAOF,SAAS,WAAW;EACrC,MAAME,SAASvB,oBAAoBmB,IAAI;EACvC,IAAII,QAAQ,OAAOA;CACrB;CAEA,MAAMC,aAAaN,cAAcO,KAAKC,IAAI,GAAGT,QAAQU,QAAQC,SAAS,CAAC;CACvE,IAAIX,QAAQM,OAAOF,SAAS,mBAAmB,OAAOtB;CACtD,OAAOyB,aAAcP,QAAQM,SAA+BxB;AAC9D;AAEA,MAAM8B,uBACJZ,SACAC,cACmC;CACnC,MAAMC,OAAOF,QAAQU,QAAQT;CAC7B,IAAI,CAACC,MACH,OAAOhB;CAIT,MAAMoB,SAASP,oBAAoBC,SAASC,WAAWC,IAAI;CAC3D,OAAOY,OAAOC,OAAO;EACnB,GAAGb;GACG5B,qBAAsB4B,KAAa5B;EACjCgC;CACV,CAAC;AACH;AAyDA,IAAayC,qBAAb,MAA0D;CACxD,IAAWtB,OAAO;EAChB,OAAO,KAAKuB,MAAMvB;CACpB;CAEA;CACA;CAEAyB,YACEF,OACAC,gBACA;EACA,KAAKD,QA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,eAAeF,KAAK0C,eAAeA,UACrD;IACA,IAAIF,QAAQ,IAAI,OAAOxD;IACvB,OAAO0B,oBAAoB+C,OAAOjB,GAAG;GACvC;GACAH,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,GACD,KAAKQ,OACL,KAAKC,cACP;CACF;CAEA,qBAA4BP,KAAa;EACvC,OAAO,IAAIpD,6BACT,IAAIH,sBAAsB;GACxBsC,MAAM;IACJ,GAAG,KAAKA;IACR0B,KAAK,GAAG,KAAK1B,KAAK0B,IAAG,eAAgBT,IAAG;IACxCkC,kBAAkB;IAClBC,oBAAoB;KAAEzE,MAAM;KAASa,OAAOyB;IAAI;GAClD;GACAf,gBAAgB;IAEd,MAAMoD,aADc,KAAKpD,SAAS,CAAC,CAACmD,cACHpC;IACjC,IAAI,CAACqC,YAAY,OAAO7F;IAExB,OAAO;KACL,GAAG6F;KACHjC,QAAQ;IACV;GACF;GACAP,YAAYC,aAAa,KAAKQ,MAAMT,UAAUC,QAAQ;EACxD,CAAC,CACH;CACF;AACF"}
@@ -1,6 +1,10 @@
1
1
  import { fromThreadMessageLike } from "./utils/thread-message-like.js";
2
2
  import { ExportedMessageRepository, ExportedMessageRepositoryItem, MessageRepository } from "./utils/message-repository.js";
3
3
  import { ComposerRuntimeCoreBinding, EditComposerRuntimeCoreBinding, MessageStateBinding, ThreadComposerRuntimeCoreBinding } from "./api/bindings.js";
4
+ import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
5
+ import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
6
+ import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
7
+ import { MessageRuntimeImpl } from "./api/message-runtime.js";
4
8
  import { BaseAssistantRuntimeCore } from "./base/base-assistant-runtime-core.js";
5
9
  import { BaseComposerRuntimeCore } from "./base/base-composer-runtime-core.js";
6
10
  import { DefaultThreadComposerRuntimeCore } from "./base/default-thread-composer-runtime-core.js";
@@ -8,10 +12,6 @@ import { DefaultEditComposerRuntimeCore } from "./base/default-edit-composer-run
8
12
  import { BaseThreadRuntimeCore } from "./base/base-thread-runtime-core.js";
9
13
  import { ThreadListItemRuntimeImpl, ThreadListItemStateBinding } from "./api/thread-list-item-runtime.js";
10
14
  import { ThreadListRuntimeCoreBinding, ThreadListRuntimeImpl } from "./api/thread-list-runtime.js";
11
- import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
12
- import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
13
- import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
14
- import { MessageRuntimeImpl } from "./api/message-runtime.js";
15
15
  import { symbolInnerMessage } from "./utils/external-store-message.js";
16
16
  import { getAutoStatus, isAutoStatus } from "./utils/auto-status.js";
17
17
  import { ThreadListItemRuntimeBinding, ThreadRuntimeCoreBinding, ThreadRuntimeImpl, getThreadState } from "./api/thread-runtime.js";
@@ -2,16 +2,16 @@ import { fromThreadMessageLike } from "./utils/thread-message-like.js";
2
2
  import { symbolInnerMessage } from "./utils/external-store-message.js";
3
3
  import { getAutoStatus, isAutoStatus } from "./utils/auto-status.js";
4
4
  import { ExportedMessageRepository, MessageRepository } from "./utils/message-repository.js";
5
+ import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
6
+ import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
7
+ import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
8
+ import { MessageRuntimeImpl } from "./api/message-runtime.js";
5
9
  import { BaseAssistantRuntimeCore } from "./base/base-assistant-runtime-core.js";
6
10
  import { BaseComposerRuntimeCore } from "./base/base-composer-runtime-core.js";
7
11
  import { DefaultThreadComposerRuntimeCore } from "./base/default-thread-composer-runtime-core.js";
8
12
  import { DefaultEditComposerRuntimeCore } from "./base/default-edit-composer-runtime-core.js";
9
13
  import { BaseThreadRuntimeCore } from "./base/base-thread-runtime-core.js";
10
14
  import { ThreadListItemRuntimeImpl } from "./api/thread-list-item-runtime.js";
11
- import { AttachmentRuntimeImpl, EditComposerAttachmentRuntimeImpl, MessageAttachmentRuntimeImpl, ThreadComposerAttachmentRuntimeImpl } from "./api/attachment-runtime.js";
12
- import { ComposerRuntimeImpl, EditComposerRuntimeImpl, ThreadComposerRuntimeImpl } from "./api/composer-runtime.js";
13
- import { MessagePartRuntimeImpl } from "./api/message-part-runtime.js";
14
- import { MessageRuntimeImpl } from "./api/message-runtime.js";
15
15
  import { ThreadRuntimeImpl, getThreadState } from "./api/thread-runtime.js";
16
16
  import { ThreadListRuntimeImpl } from "./api/thread-list-runtime.js";
17
17
  import { AssistantRuntimeImpl } from "./api/assistant-runtime.js";
@@ -1 +1 @@
1
- {"version":3,"file":"chain-of-thought-client.d.ts","names":[],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"mappings":";;;;cAwCa,kDAAoB,SAAA;EAtBxB,gBAAS;EACA,iBAAC;IAAY;QAAoB"}
1
+ {"version":3,"file":"chain-of-thought-client.d.ts","names":[],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"mappings":";;;;cAmCa,kDAAoB,SAAA;EArBxB,gBAAS;EACA,iBAAC;IAAY;QAAoB"}
@@ -1,44 +1,50 @@
1
+ import { getGroupStatus } from "../../utils/getGroupStatus.js";
1
2
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
2
3
  import { useState } from "@assistant-ui/tap/react-shim";
3
4
  import { resource } from "@assistant-ui/tap";
4
5
  //#region src/store/clients/chain-of-thought-client.ts
5
- const COMPLETE_STATUS = Object.freeze({ type: "complete" });
6
6
  const useChainOfThoughtClient = (t0) => {
7
- const $ = c(9);
7
+ const $ = c(11);
8
8
  const { parts, getMessagePart } = t0;
9
9
  const [collapsed, setCollapsed] = useState(true);
10
- const status = parts[parts.length - 1]?.status ?? COMPLETE_STATUS;
11
10
  let t1;
12
- if ($[0] !== collapsed || $[1] !== parts || $[2] !== status) {
13
- t1 = {
11
+ if ($[0] !== parts) {
12
+ t1 = getGroupStatus(parts);
13
+ $[0] = parts;
14
+ $[1] = t1;
15
+ } else t1 = $[1];
16
+ const status = t1;
17
+ let t2;
18
+ if ($[2] !== collapsed || $[3] !== parts || $[4] !== status) {
19
+ t2 = {
14
20
  parts,
15
21
  collapsed,
16
22
  status
17
23
  };
18
- $[0] = collapsed;
19
- $[1] = parts;
20
- $[2] = status;
21
- $[3] = t1;
22
- } else t1 = $[3];
23
- const state = t1;
24
- let t2;
25
- if ($[4] !== state) {
26
- t2 = () => state;
27
- $[4] = state;
24
+ $[2] = collapsed;
25
+ $[3] = parts;
26
+ $[4] = status;
28
27
  $[5] = t2;
29
28
  } else t2 = $[5];
29
+ const state = t2;
30
30
  let t3;
31
- if ($[6] !== getMessagePart || $[7] !== t2) {
32
- t3 = {
33
- getState: t2,
31
+ if ($[6] !== state) {
32
+ t3 = () => state;
33
+ $[6] = state;
34
+ $[7] = t3;
35
+ } else t3 = $[7];
36
+ let t4;
37
+ if ($[8] !== getMessagePart || $[9] !== t3) {
38
+ t4 = {
39
+ getState: t3,
34
40
  setCollapsed,
35
41
  part: getMessagePart
36
42
  };
37
- $[6] = getMessagePart;
38
- $[7] = t2;
39
- $[8] = t3;
40
- } else t3 = $[8];
41
- return t3;
43
+ $[8] = getMessagePart;
44
+ $[9] = t3;
45
+ $[10] = t4;
46
+ } else t4 = $[10];
47
+ return t4;
42
48
  };
43
49
  const ChainOfThoughtClient = resource(useChainOfThoughtClient);
44
50
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"chain-of-thought-client.js","names":["useMemo","useState","resource","ClientOutput","ChainOfThoughtState","ChainOfThoughtPart","MessagePartStatus","PartMethods","COMPLETE_STATUS","Object","freeze","type","useChainOfThoughtClient","t0","$","_c","parts","getMessagePart","collapsed","setCollapsed","lastPart","length","status","t1","state","t2","t3","getState","part","ChainOfThoughtClient"],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"sourcesContent":["import { useMemo, useState } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type {\n ChainOfThoughtState,\n ChainOfThoughtPart,\n} from \"../scopes/chain-of-thought\";\nimport type { MessagePartStatus } from \"../../types/message\";\nimport type { PartMethods } from \"../scopes/part\";\n\nconst COMPLETE_STATUS: MessagePartStatus = Object.freeze({\n type: \"complete\",\n});\n\nconst useChainOfThoughtClient = ({\n parts,\n getMessagePart,\n}: {\n parts: readonly ChainOfThoughtPart[];\n getMessagePart: (selector: { index: number }) => PartMethods;\n}): ClientOutput<\"chainOfThought\"> => {\n const [collapsed, setCollapsed] = useState(true);\n\n const status = useMemo(() => {\n const lastPart = parts[parts.length - 1];\n return lastPart?.status ?? COMPLETE_STATUS;\n }, [parts]);\n\n const state = useMemo<ChainOfThoughtState>(\n () => ({ parts, collapsed, status }),\n [parts, collapsed, status],\n );\n\n return {\n getState: () => state,\n setCollapsed,\n part: getMessagePart,\n };\n};\n\nexport const ChainOfThoughtClient = resource(useChainOfThoughtClient);\n"],"mappings":";;;;AAUA,MAAMQ,kBAAqCC,OAAOC,OAAO,EACvDC,MAAM,WACR,CAAC;AAED,MAAMC,2BAA0BC,OAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAC,MAAA,EAAAC,OAAAC,mBAAAJ;CAO/B,MAAA,CAAAK,WAAAC,gBAAkClB,SAAS,IAAI;CAE/C,MAAAqB,SACmBN,MAAMA,MAAKK,SAAU,EACvB,EAAAC,UAARd;CACG,IAAAe;CAAA,IAAAT,EAAA,OAAAI,aAAAJ,EAAA,OAAAE,SAAAF,EAAA,OAAAQ,QAAA;EAGHC,KAAA;GAAAP;GAAAE;GAAAI;EAA2B;EAACR,EAAA,KAAAI;EAAAJ,EAAA,KAAAE;EAAAF,EAAA,KAAAQ;EAAAR,EAAA,KAAAS;CAAA,OAAAA,KAAAT,EAAA;CADrC,MAAAU,QACSD;CAEP,IAAAE;CAAA,IAAAX,EAAA,OAAAU,OAAA;EAGUC,WAAMD;EAAKV,EAAA,KAAAU;EAAAV,EAAA,KAAAW;CAAA,OAAAA,KAAAX,EAAA;CAAA,IAAAY;CAAA,IAAAZ,EAAA,OAAAG,kBAAAH,EAAA,OAAAW,IAAA;EADhBC,KAAA;GAAAC,UACKF;GAAWN;GAAAS,MAEfX;EACR;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAW;EAAAX,EAAA,KAAAY;CAAA,OAAAA,KAAAZ,EAAA;CAAA,OAJMY;AAIN;AAGH,MAAaG,uBAAuB3B,SAASU,uBAAuB"}
1
+ {"version":3,"file":"chain-of-thought-client.js","names":["useMemo","useState","resource","ClientOutput","ChainOfThoughtState","ChainOfThoughtPart","PartMethods","getGroupStatus","useChainOfThoughtClient","t0","$","_c","parts","getMessagePart","collapsed","setCollapsed","t1","status","t2","state","t3","t4","getState","part","ChainOfThoughtClient"],"sources":["../../../src/store/clients/chain-of-thought-client.ts"],"sourcesContent":["import { useMemo, useState } from \"react\";\nimport { resource } from \"@assistant-ui/tap\";\nimport type { ClientOutput } from \"@assistant-ui/store\";\nimport type {\n ChainOfThoughtState,\n ChainOfThoughtPart,\n} from \"../scopes/chain-of-thought\";\nimport type { PartMethods } from \"../scopes/part\";\nimport { getGroupStatus } from \"../../utils/getGroupStatus\";\n\nconst useChainOfThoughtClient = ({\n parts,\n getMessagePart,\n}: {\n parts: readonly ChainOfThoughtPart[];\n getMessagePart: (selector: { index: number }) => PartMethods;\n}): ClientOutput<\"chainOfThought\"> => {\n const [collapsed, setCollapsed] = useState(true);\n\n const status = useMemo(() => {\n return getGroupStatus(parts);\n }, [parts]);\n\n const state = useMemo<ChainOfThoughtState>(\n () => ({ parts, collapsed, status }),\n [parts, collapsed, status],\n );\n\n return {\n getState: () => state,\n setCollapsed,\n part: getMessagePart,\n };\n};\n\nexport const ChainOfThoughtClient = resource(useChainOfThoughtClient);\n"],"mappings":";;;;;AAUA,MAAMQ,2BAA0BC,OAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAC,MAAA,EAAAC,OAAAC,mBAAAJ;CAO/B,MAAA,CAAAK,WAAAC,gBAAkCd,SAAS,IAAI;CAAE,IAAAe;CAAA,IAAAN,EAAA,OAAAE,OAAA;EAGxCI,KAAAT,eAAeK,KAAK;EAACF,EAAA,KAAAE;EAAAF,EAAA,KAAAM;CAAA,OAAAA,KAAAN,EAAA;CAD9B,MAAAO,SACED;CACU,IAAAE;CAAA,IAAAR,EAAA,OAAAI,aAAAJ,EAAA,OAAAE,SAAAF,EAAA,OAAAO,QAAA;EAGHC,KAAA;GAAAN;GAAAE;GAAAG;EAA2B;EAACP,EAAA,KAAAI;EAAAJ,EAAA,KAAAE;EAAAF,EAAA,KAAAO;EAAAP,EAAA,KAAAQ;CAAA,OAAAA,KAAAR,EAAA;CADrC,MAAAS,QACSD;CAEP,IAAAE;CAAA,IAAAV,EAAA,OAAAS,OAAA;EAGUC,WAAMD;EAAKT,EAAA,KAAAS;EAAAT,EAAA,KAAAU;CAAA,OAAAA,KAAAV,EAAA;CAAA,IAAAW;CAAA,IAAAX,EAAA,OAAAG,kBAAAH,EAAA,OAAAU,IAAA;EADhBC,KAAA;GAAAC,UACKF;GAAWL;GAAAQ,MAEfV;EACR;EAACH,EAAA,KAAAG;EAAAH,EAAA,KAAAU;EAAAV,EAAA,MAAAW;CAAA,OAAAA,KAAAX,EAAA;CAAA,OAJMW;AAIN;AAGH,MAAaG,uBAAuBtB,SAASM,uBAAuB"}
@@ -1 +1 @@
1
- {"version":3,"file":"thread-message-client.d.ts","names":[],"sources":["../../../src/store/clients/thread-message-client.ts"],"mappings":";;;KA2DY;EACV,SAAS;EACT;EACA;EACA;EACA;;cAyGW,iDAAmB,SAAA,0BAAA"}
1
+ {"version":3,"file":"thread-message-client.d.ts","names":[],"sources":["../../../src/store/clients/thread-message-client.ts"],"mappings":";;;KAmEY;EACV,SAAS;EACT;EACA;EACA;EACA;;cA2GW,iDAAmB,SAAA,0BAAA"}
@@ -1,4 +1,5 @@
1
1
  import { getThreadMessageText } from "../../utils/text.js";
2
+ import { COMPLETE_STATUS, normalizePartStatus } from "../../utils/normalizePartStatus.js";
2
3
  import { NoOpComposerClient } from "./no-op-composer-client.js";
3
4
  import { c } from "@assistant-ui/tap/react-shim/compiler-runtime";
4
5
  import { useState } from "@assistant-ui/tap/react-shim";
@@ -6,34 +7,37 @@ import { useClientLookup } from "@assistant-ui/store";
6
7
  import { resource, useResource, withKey } from "@assistant-ui/tap";
7
8
  //#region src/store/clients/thread-message-client.ts
8
9
  const useThreadMessagePartClient = (t0) => {
9
- const $ = c(5);
10
- const { part } = t0;
10
+ const $ = c(8);
11
+ const { part, isMessageRunning } = t0;
11
12
  let t1;
12
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
13
- t1 = { type: "complete" };
14
- $[0] = t1;
15
- } else t1 = $[0];
13
+ if ($[0] !== isMessageRunning || $[1] !== part) {
14
+ t1 = isMessageRunning ? normalizePartStatus(part) ?? COMPLETE_STATUS : COMPLETE_STATUS;
15
+ $[0] = isMessageRunning;
16
+ $[1] = part;
17
+ $[2] = t1;
18
+ } else t1 = $[2];
16
19
  let t2;
17
- if ($[1] !== part) {
20
+ if ($[3] !== part || $[4] !== t1) {
18
21
  t2 = {
19
22
  ...part,
20
23
  status: t1
21
24
  };
22
- $[1] = part;
23
- $[2] = t2;
24
- } else t2 = $[2];
25
+ $[3] = part;
26
+ $[4] = t1;
27
+ $[5] = t2;
28
+ } else t2 = $[5];
25
29
  const state = t2;
26
30
  let t3;
27
- if ($[3] !== state) {
31
+ if ($[6] !== state) {
28
32
  t3 = {
29
33
  getState: () => state,
30
34
  addToolResult: _temp,
31
35
  resumeToolCall: _temp2,
32
36
  respondToToolApproval: _temp3
33
37
  };
34
- $[3] = state;
35
- $[4] = t3;
36
- } else t3 = $[4];
38
+ $[6] = state;
39
+ $[7] = t3;
40
+ } else t3 = $[7];
37
41
  return t3;
38
42
  };
39
43
  const ThreadMessagePartClient = resource(useThreadMessagePartClient);
@@ -47,48 +51,59 @@ const useThreadMessageAttachmentClient = ({ attachment }) => {
47
51
  };
48
52
  const ThreadMessageAttachmentClient = resource(useThreadMessageAttachmentClient);
49
53
  const useThreadMessageClient = (t0) => {
50
- const $ = c(35);
54
+ const $ = c(38);
51
55
  const { message, index, isLast: t1, branchNumber: t2, branchCount: t3 } = t0;
52
56
  const isLast = t1 === void 0 ? true : t1;
53
57
  const branchNumber = t2 === void 0 ? 1 : t2;
54
58
  const branchCount = t3 === void 0 ? 1 : t3;
55
59
  const [isCopiedState, setIsCopied] = useState(false);
56
60
  const [isHoveringState, setIsHovering] = useState(false);
61
+ const isMessageRunning = message.role === "assistant" && message.status.type === "running";
57
62
  let t4;
58
- if ($[0] !== message.content) {
59
- t4 = message.content.map(_temp4);
60
- $[0] = message.content;
61
- $[1] = t4;
62
- } else t4 = $[1];
63
+ if ($[0] !== isMessageRunning || $[1] !== message.content) {
64
+ let t5;
65
+ if ($[3] !== isMessageRunning) {
66
+ t5 = (part, idx) => withKey("toolCallId" in part && part.toolCallId != null ? `toolCallId-${part.toolCallId}` : `index-${idx}`, ThreadMessagePartClient({
67
+ part,
68
+ isMessageRunning
69
+ }), [part, isMessageRunning]);
70
+ $[3] = isMessageRunning;
71
+ $[4] = t5;
72
+ } else t5 = $[4];
73
+ t4 = message.content.map(t5);
74
+ $[0] = isMessageRunning;
75
+ $[1] = message.content;
76
+ $[2] = t4;
77
+ } else t4 = $[2];
63
78
  const parts = useClientLookup(t4);
64
79
  let t5;
65
- if ($[2] !== message.attachments) {
80
+ if ($[5] !== message.attachments) {
66
81
  t5 = message.attachments ?? [];
67
- $[2] = message.attachments;
68
- $[3] = t5;
69
- } else t5 = $[3];
82
+ $[5] = message.attachments;
83
+ $[6] = t5;
84
+ } else t5 = $[6];
70
85
  let t6;
71
- if ($[4] !== t5) {
72
- t6 = t5.map(_temp5);
73
- $[4] = t5;
74
- $[5] = t6;
75
- } else t6 = $[5];
86
+ if ($[7] !== t5) {
87
+ t6 = t5.map(_temp4);
88
+ $[7] = t5;
89
+ $[8] = t6;
90
+ } else t6 = $[8];
76
91
  const attachments = useClientLookup(t6);
77
92
  let t7;
78
- if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
93
+ if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
79
94
  t7 = NoOpComposerClient({ type: "edit" });
80
- $[6] = t7;
81
- } else t7 = $[6];
95
+ $[9] = t7;
96
+ } else t7 = $[9];
82
97
  const composer = useResource(t7);
83
98
  let t8;
84
- if ($[7] !== composer) {
99
+ if ($[10] !== composer) {
85
100
  t8 = composer.getState();
86
- $[7] = composer;
87
- $[8] = t8;
88
- } else t8 = $[8];
101
+ $[10] = composer;
102
+ $[11] = t8;
103
+ } else t8 = $[11];
89
104
  const composerState = t8;
90
105
  let t9;
91
- if ($[9] !== branchCount || $[10] !== branchNumber || $[11] !== composerState || $[12] !== index || $[13] !== isCopiedState || $[14] !== isHoveringState || $[15] !== isLast || $[16] !== message || $[17] !== parts.state) {
106
+ if ($[12] !== branchCount || $[13] !== branchNumber || $[14] !== composerState || $[15] !== index || $[16] !== isCopiedState || $[17] !== isHoveringState || $[18] !== isLast || $[19] !== message || $[20] !== parts.state) {
92
107
  t9 = {
93
108
  ...message,
94
109
  parts: parts.state,
@@ -102,78 +117,78 @@ const useThreadMessageClient = (t0) => {
102
117
  isCopied: isCopiedState,
103
118
  isHovering: isHoveringState
104
119
  };
105
- $[9] = branchCount;
106
- $[10] = branchNumber;
107
- $[11] = composerState;
108
- $[12] = index;
109
- $[13] = isCopiedState;
110
- $[14] = isHoveringState;
111
- $[15] = isLast;
112
- $[16] = message;
113
- $[17] = parts.state;
114
- $[18] = t9;
115
- } else t9 = $[18];
120
+ $[12] = branchCount;
121
+ $[13] = branchNumber;
122
+ $[14] = composerState;
123
+ $[15] = index;
124
+ $[16] = isCopiedState;
125
+ $[17] = isHoveringState;
126
+ $[18] = isLast;
127
+ $[19] = message;
128
+ $[20] = parts.state;
129
+ $[21] = t9;
130
+ } else t9 = $[21];
116
131
  const state = t9;
117
132
  let t10;
118
- if ($[19] !== state) {
133
+ if ($[22] !== state) {
119
134
  t10 = () => state;
120
- $[19] = state;
121
- $[20] = t10;
122
- } else t10 = $[20];
135
+ $[22] = state;
136
+ $[23] = t10;
137
+ } else t10 = $[23];
123
138
  let t11;
124
- if ($[21] !== composer) {
139
+ if ($[24] !== composer) {
125
140
  t11 = () => composer;
126
- $[21] = composer;
127
- $[22] = t11;
128
- } else t11 = $[22];
141
+ $[24] = composer;
142
+ $[25] = t11;
143
+ } else t11 = $[25];
129
144
  let t12;
130
- if ($[23] !== parts) {
145
+ if ($[26] !== parts) {
131
146
  t12 = (selector) => {
132
147
  if ("index" in selector) return parts.get({ index: selector.index });
133
148
  else return parts.get({ key: `toolCallId-${selector.toolCallId}` });
134
149
  };
135
- $[23] = parts;
136
- $[24] = t12;
137
- } else t12 = $[24];
150
+ $[26] = parts;
151
+ $[27] = t12;
152
+ } else t12 = $[27];
138
153
  let t13;
139
- if ($[25] !== attachments) {
154
+ if ($[28] !== attachments) {
140
155
  t13 = (selector_0) => {
141
156
  if ("id" in selector_0) return attachments.get({ key: selector_0.id });
142
157
  else return attachments.get(selector_0);
143
158
  };
144
- $[25] = attachments;
145
- $[26] = t13;
146
- } else t13 = $[26];
159
+ $[28] = attachments;
160
+ $[29] = t13;
161
+ } else t13 = $[29];
147
162
  let t14;
148
- if ($[27] !== message) {
163
+ if ($[30] !== message) {
149
164
  t14 = () => getThreadMessageText(message);
150
- $[27] = message;
151
- $[28] = t14;
152
- } else t14 = $[28];
165
+ $[30] = message;
166
+ $[31] = t14;
167
+ } else t14 = $[31];
153
168
  let t15;
154
- if ($[29] !== t10 || $[30] !== t11 || $[31] !== t12 || $[32] !== t13 || $[33] !== t14) {
169
+ if ($[32] !== t10 || $[33] !== t11 || $[34] !== t12 || $[35] !== t13 || $[36] !== t14) {
155
170
  t15 = {
156
171
  getState: t10,
157
172
  composer: t11,
158
173
  part: t12,
159
174
  attachment: t13,
160
- delete: _temp6,
161
- reload: _temp7,
162
- speak: _temp8,
163
- stopSpeaking: _temp9,
164
- submitFeedback: _temp0,
165
- switchToBranch: _temp1,
175
+ delete: _temp5,
176
+ reload: _temp6,
177
+ speak: _temp7,
178
+ stopSpeaking: _temp8,
179
+ submitFeedback: _temp9,
180
+ switchToBranch: _temp0,
166
181
  getCopyText: t14,
167
182
  setIsCopied,
168
183
  setIsHovering
169
184
  };
170
- $[29] = t10;
171
- $[30] = t11;
172
- $[31] = t12;
173
- $[32] = t13;
174
- $[33] = t14;
175
- $[34] = t15;
176
- } else t15 = $[34];
185
+ $[32] = t10;
186
+ $[33] = t11;
187
+ $[34] = t12;
188
+ $[35] = t13;
189
+ $[36] = t14;
190
+ $[37] = t15;
191
+ } else t15 = $[37];
177
192
  return t15;
178
193
  };
179
194
  const ThreadMessageClient = resource(useThreadMessageClient);
@@ -186,12 +201,12 @@ function _temp2() {
186
201
  function _temp3() {
187
202
  throw new Error("Not supported");
188
203
  }
189
- function _temp4(part, idx) {
190
- return withKey("toolCallId" in part && part.toolCallId != null ? `toolCallId-${part.toolCallId}` : `index-${idx}`, ThreadMessagePartClient({ part }), [part]);
191
- }
192
- function _temp5(attachment) {
204
+ function _temp4(attachment) {
193
205
  return withKey(attachment.id, ThreadMessageAttachmentClient({ attachment }), [attachment]);
194
206
  }
207
+ function _temp5() {
208
+ throw new Error("Not supported in ThreadMessageProvider");
209
+ }
195
210
  function _temp6() {
196
211
  throw new Error("Not supported in ThreadMessageProvider");
197
212
  }
@@ -207,9 +222,6 @@ function _temp9() {
207
222
  function _temp0() {
208
223
  throw new Error("Not supported in ThreadMessageProvider");
209
224
  }
210
- function _temp1() {
211
- throw new Error("Not supported in ThreadMessageProvider");
212
- }
213
225
  //#endregion
214
226
  export { ThreadMessageClient };
215
227