@assistant-ui/react 0.8.20 → 0.9.1

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 (221) hide show
  1. package/dist/api/ThreadRuntime.d.ts.map +1 -1
  2. package/dist/api/ThreadRuntime.js +3 -1
  3. package/dist/api/ThreadRuntime.js.map +1 -1
  4. package/dist/api/ThreadRuntime.mjs +3 -1
  5. package/dist/api/ThreadRuntime.mjs.map +1 -1
  6. package/dist/cloud/AssistantCloudRuns.d.ts +2 -2
  7. package/dist/cloud/AssistantCloudRuns.d.ts.map +1 -1
  8. package/dist/cloud/AssistantCloudRuns.js.map +1 -1
  9. package/dist/cloud/AssistantCloudRuns.mjs.map +1 -1
  10. package/dist/cloud/auiV0.d.ts +1 -2
  11. package/dist/cloud/auiV0.d.ts.map +1 -1
  12. package/dist/cloud/auiV0.js.map +1 -1
  13. package/dist/cloud/auiV0.mjs.map +1 -1
  14. package/dist/context/react/AttachmentContext.d.ts +108 -108
  15. package/dist/index.d.ts +0 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +1 -4
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +1 -3
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/internal.d.ts +1 -1
  22. package/dist/internal.d.ts.map +1 -1
  23. package/dist/internal.js +4 -4
  24. package/dist/internal.js.map +1 -1
  25. package/dist/internal.mjs +3 -3
  26. package/dist/internal.mjs.map +1 -1
  27. package/dist/primitives/assistantModal/AssistantModalRoot.d.ts.map +1 -1
  28. package/dist/primitives/assistantModal/AssistantModalRoot.js +5 -2
  29. package/dist/primitives/assistantModal/AssistantModalRoot.js.map +1 -1
  30. package/dist/primitives/assistantModal/AssistantModalRoot.mjs +5 -2
  31. package/dist/primitives/assistantModal/AssistantModalRoot.mjs.map +1 -1
  32. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts +1 -1
  33. package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
  34. package/dist/runtimes/composer/BaseComposerRuntimeCore.js +3 -1
  35. package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
  36. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +3 -1
  37. package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
  38. package/dist/runtimes/external-store/ThreadMessageLike.d.ts.map +1 -1
  39. package/dist/runtimes/external-store/ThreadMessageLike.js +2 -2
  40. package/dist/runtimes/external-store/ThreadMessageLike.js.map +1 -1
  41. package/dist/runtimes/external-store/ThreadMessageLike.mjs +1 -1
  42. package/dist/runtimes/external-store/ThreadMessageLike.mjs.map +1 -1
  43. package/dist/runtimes/index.d.ts +1 -2
  44. package/dist/runtimes/index.d.ts.map +1 -1
  45. package/dist/runtimes/index.js +6 -5
  46. package/dist/runtimes/index.js.map +1 -1
  47. package/dist/runtimes/index.mjs +7 -3
  48. package/dist/runtimes/index.mjs.map +1 -1
  49. package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
  50. package/dist/runtimes/local/LocalThreadRuntimeCore.js +3 -3
  51. package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
  52. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +4 -4
  53. package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
  54. package/dist/runtimes/remote-thread-list/adapter/cloud.d.ts.map +1 -1
  55. package/dist/runtimes/remote-thread-list/adapter/cloud.js +2 -2
  56. package/dist/runtimes/remote-thread-list/adapter/cloud.js.map +1 -1
  57. package/dist/runtimes/remote-thread-list/adapter/cloud.mjs +2 -2
  58. package/dist/runtimes/remote-thread-list/adapter/cloud.mjs.map +1 -1
  59. package/dist/runtimes/{edge/streams → streams}/toolResultStream.d.ts +1 -1
  60. package/dist/runtimes/streams/toolResultStream.d.ts.map +1 -0
  61. package/dist/runtimes/{edge/streams → streams}/toolResultStream.js +1 -1
  62. package/dist/runtimes/streams/toolResultStream.js.map +1 -0
  63. package/dist/runtimes/{edge/streams → streams}/toolResultStream.mjs +1 -1
  64. package/dist/runtimes/streams/toolResultStream.mjs.map +1 -0
  65. package/dist/runtimes/utils/MessageRepository.d.ts +2 -2
  66. package/dist/runtimes/utils/MessageRepository.d.ts.map +1 -1
  67. package/dist/runtimes/utils/MessageRepository.js +1 -5
  68. package/dist/runtimes/utils/MessageRepository.js.map +1 -1
  69. package/dist/runtimes/utils/MessageRepository.mjs +1 -5
  70. package/dist/runtimes/utils/MessageRepository.mjs.map +1 -1
  71. package/dist/types/AssistantTypes.d.ts +3 -60
  72. package/dist/types/AssistantTypes.d.ts.map +1 -1
  73. package/dist/types/AssistantTypes.js.map +1 -1
  74. package/dist/types/AttachmentTypes.d.ts +3 -3
  75. package/dist/types/AttachmentTypes.d.ts.map +1 -1
  76. package/dist/types/AttachmentTypes.js.map +1 -1
  77. package/dist/types/index.d.ts +1 -1
  78. package/dist/types/index.d.ts.map +1 -1
  79. package/dist/types/index.js.map +1 -1
  80. package/package.json +11 -17
  81. package/src/api/ThreadRuntime.ts +2 -0
  82. package/src/cloud/AssistantCloudRuns.tsx +2 -2
  83. package/src/cloud/auiV0.ts +1 -2
  84. package/src/index.ts +0 -2
  85. package/src/internal.ts +1 -1
  86. package/src/primitives/assistantModal/AssistantModalRoot.tsx +6 -2
  87. package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +2 -0
  88. package/src/runtimes/external-store/ThreadMessageLike.tsx +1 -1
  89. package/src/runtimes/index.ts +4 -2
  90. package/src/runtimes/local/LocalThreadRuntimeCore.tsx +4 -4
  91. package/src/runtimes/remote-thread-list/adapter/cloud.tsx +1 -2
  92. package/src/runtimes/{edge/streams → streams}/toolResultStream.ts +1 -1
  93. package/src/runtimes/utils/MessageRepository.tsx +3 -7
  94. package/src/tests/MessageRepository.test.ts +7 -10
  95. package/src/types/AssistantTypes.ts +3 -81
  96. package/src/types/AttachmentTypes.ts +3 -3
  97. package/src/types/index.ts +0 -9
  98. package/dist/edge.d.ts +0 -2
  99. package/dist/edge.d.ts.map +0 -1
  100. package/dist/edge.js +0 -33
  101. package/dist/edge.js.map +0 -1
  102. package/dist/edge.mjs +0 -10
  103. package/dist/edge.mjs.map +0 -1
  104. package/dist/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.d.ts +0 -9
  105. package/dist/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.d.ts.map +0 -1
  106. package/dist/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.js +0 -58
  107. package/dist/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.js.map +0 -1
  108. package/dist/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.mjs +0 -35
  109. package/dist/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.mjs.map +0 -1
  110. package/dist/runtimes/dangerous-in-browser/index.d.ts +0 -2
  111. package/dist/runtimes/dangerous-in-browser/index.d.ts.map +0 -1
  112. package/dist/runtimes/dangerous-in-browser/index.js +0 -31
  113. package/dist/runtimes/dangerous-in-browser/index.js.map +0 -1
  114. package/dist/runtimes/dangerous-in-browser/index.mjs +0 -8
  115. package/dist/runtimes/dangerous-in-browser/index.mjs.map +0 -1
  116. package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.d.ts +0 -5
  117. package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.d.ts.map +0 -1
  118. package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.js +0 -40
  119. package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.js.map +0 -1
  120. package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.mjs +0 -18
  121. package/dist/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.mjs.map +0 -1
  122. package/dist/runtimes/edge/EdgeModelAdapter.d.ts +0 -48
  123. package/dist/runtimes/edge/EdgeModelAdapter.d.ts.map +0 -1
  124. package/dist/runtimes/edge/EdgeModelAdapter.js +0 -127
  125. package/dist/runtimes/edge/EdgeModelAdapter.js.map +0 -1
  126. package/dist/runtimes/edge/EdgeModelAdapter.mjs +0 -94
  127. package/dist/runtimes/edge/EdgeModelAdapter.mjs.map +0 -1
  128. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts +0 -345
  129. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.d.ts.map +0 -1
  130. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js +0 -106
  131. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.js.map +0 -1
  132. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs +0 -84
  133. package/dist/runtimes/edge/EdgeRuntimeRequestOptions.mjs.map +0 -1
  134. package/dist/runtimes/edge/converters/fromCoreMessage.d.ts +0 -8
  135. package/dist/runtimes/edge/converters/fromCoreMessage.d.ts.map +0 -1
  136. package/dist/runtimes/edge/converters/fromCoreMessage.js +0 -89
  137. package/dist/runtimes/edge/converters/fromCoreMessage.js.map +0 -1
  138. package/dist/runtimes/edge/converters/fromCoreMessage.mjs +0 -63
  139. package/dist/runtimes/edge/converters/fromCoreMessage.mjs.map +0 -1
  140. package/dist/runtimes/edge/converters/fromLanguageModelMessages.d.ts +0 -8
  141. package/dist/runtimes/edge/converters/fromLanguageModelMessages.d.ts.map +0 -1
  142. package/dist/runtimes/edge/converters/fromLanguageModelMessages.js +0 -149
  143. package/dist/runtimes/edge/converters/fromLanguageModelMessages.js.map +0 -1
  144. package/dist/runtimes/edge/converters/fromLanguageModelMessages.mjs +0 -124
  145. package/dist/runtimes/edge/converters/fromLanguageModelMessages.mjs.map +0 -1
  146. package/dist/runtimes/edge/converters/fromLanguageModelTools.d.ts +0 -4
  147. package/dist/runtimes/edge/converters/fromLanguageModelTools.d.ts.map +0 -1
  148. package/dist/runtimes/edge/converters/fromLanguageModelTools.js +0 -41
  149. package/dist/runtimes/edge/converters/fromLanguageModelTools.js.map +0 -1
  150. package/dist/runtimes/edge/converters/fromLanguageModelTools.mjs +0 -16
  151. package/dist/runtimes/edge/converters/fromLanguageModelTools.mjs.map +0 -1
  152. package/dist/runtimes/edge/converters/index.d.ts +0 -35
  153. package/dist/runtimes/edge/converters/index.d.ts.map +0 -1
  154. package/dist/runtimes/edge/converters/index.js +0 -50
  155. package/dist/runtimes/edge/converters/index.js.map +0 -1
  156. package/dist/runtimes/edge/converters/index.mjs +0 -24
  157. package/dist/runtimes/edge/converters/index.mjs.map +0 -1
  158. package/dist/runtimes/edge/converters/toCoreMessages.d.ts +0 -12
  159. package/dist/runtimes/edge/converters/toCoreMessages.d.ts.map +0 -1
  160. package/dist/runtimes/edge/converters/toCoreMessages.js +0 -74
  161. package/dist/runtimes/edge/converters/toCoreMessages.js.map +0 -1
  162. package/dist/runtimes/edge/converters/toCoreMessages.mjs +0 -48
  163. package/dist/runtimes/edge/converters/toCoreMessages.mjs.map +0 -1
  164. package/dist/runtimes/edge/converters/toLanguageModelMessages.d.ts +0 -6
  165. package/dist/runtimes/edge/converters/toLanguageModelMessages.d.ts.map +0 -1
  166. package/dist/runtimes/edge/converters/toLanguageModelMessages.js +0 -168
  167. package/dist/runtimes/edge/converters/toLanguageModelMessages.js.map +0 -1
  168. package/dist/runtimes/edge/converters/toLanguageModelMessages.mjs +0 -143
  169. package/dist/runtimes/edge/converters/toLanguageModelMessages.mjs.map +0 -1
  170. package/dist/runtimes/edge/converters/toLanguageModelTools.d.ts +0 -4
  171. package/dist/runtimes/edge/converters/toLanguageModelTools.d.ts.map +0 -1
  172. package/dist/runtimes/edge/converters/toLanguageModelTools.js +0 -50
  173. package/dist/runtimes/edge/converters/toLanguageModelTools.js.map +0 -1
  174. package/dist/runtimes/edge/converters/toLanguageModelTools.mjs +0 -15
  175. package/dist/runtimes/edge/converters/toLanguageModelTools.mjs.map +0 -1
  176. package/dist/runtimes/edge/createEdgeRuntimeAPI.d.ts +0 -36
  177. package/dist/runtimes/edge/createEdgeRuntimeAPI.d.ts.map +0 -1
  178. package/dist/runtimes/edge/createEdgeRuntimeAPI.js +0 -179
  179. package/dist/runtimes/edge/createEdgeRuntimeAPI.js.map +0 -1
  180. package/dist/runtimes/edge/createEdgeRuntimeAPI.mjs +0 -156
  181. package/dist/runtimes/edge/createEdgeRuntimeAPI.mjs.map +0 -1
  182. package/dist/runtimes/edge/index.d.ts +0 -6
  183. package/dist/runtimes/edge/index.d.ts.map +0 -1
  184. package/dist/runtimes/edge/index.js +0 -40
  185. package/dist/runtimes/edge/index.js.map +0 -1
  186. package/dist/runtimes/edge/index.mjs +0 -11
  187. package/dist/runtimes/edge/index.mjs.map +0 -1
  188. package/dist/runtimes/edge/streams/toolResultStream.d.ts.map +0 -1
  189. package/dist/runtimes/edge/streams/toolResultStream.js.map +0 -1
  190. package/dist/runtimes/edge/streams/toolResultStream.mjs.map +0 -1
  191. package/dist/runtimes/edge/useEdgeRuntime.d.ts +0 -5
  192. package/dist/runtimes/edge/useEdgeRuntime.d.ts.map +0 -1
  193. package/dist/runtimes/edge/useEdgeRuntime.js +0 -41
  194. package/dist/runtimes/edge/useEdgeRuntime.js.map +0 -1
  195. package/dist/runtimes/edge/useEdgeRuntime.mjs +0 -17
  196. package/dist/runtimes/edge/useEdgeRuntime.mjs.map +0 -1
  197. package/dist/utils/json/parse-partial-json.d.ts +0 -4
  198. package/dist/utils/json/parse-partial-json.d.ts.map +0 -1
  199. package/dist/utils/json/parse-partial-json.js +0 -90
  200. package/dist/utils/json/parse-partial-json.js.map +0 -1
  201. package/dist/utils/json/parse-partial-json.mjs +0 -54
  202. package/dist/utils/json/parse-partial-json.mjs.map +0 -1
  203. package/edge/README.md +0 -1
  204. package/edge/package.json +0 -5
  205. package/src/edge.ts +0 -4
  206. package/src/runtimes/dangerous-in-browser/DangerousInBrowserAdapter.ts +0 -42
  207. package/src/runtimes/dangerous-in-browser/index.ts +0 -4
  208. package/src/runtimes/dangerous-in-browser/useDangerousInBrowserRuntime.ts +0 -21
  209. package/src/runtimes/edge/EdgeModelAdapter.ts +0 -188
  210. package/src/runtimes/edge/EdgeRuntimeRequestOptions.ts +0 -109
  211. package/src/runtimes/edge/converters/fromCoreMessage.ts +0 -76
  212. package/src/runtimes/edge/converters/fromLanguageModelMessages.ts +0 -149
  213. package/src/runtimes/edge/converters/fromLanguageModelTools.ts +0 -16
  214. package/src/runtimes/edge/converters/index.ts +0 -41
  215. package/src/runtimes/edge/converters/toCoreMessages.ts +0 -64
  216. package/src/runtimes/edge/converters/toLanguageModelMessages.ts +0 -184
  217. package/src/runtimes/edge/converters/toLanguageModelTools.ts +0 -18
  218. package/src/runtimes/edge/createEdgeRuntimeAPI.ts +0 -234
  219. package/src/runtimes/edge/index.ts +0 -7
  220. package/src/runtimes/edge/useEdgeRuntime.ts +0 -17
  221. package/src/utils/json/parse-partial-json.ts +0 -74
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/utils/MessageRepository.tsx"],"sourcesContent":["import type { CoreMessage, ThreadMessage } from \"../../types/AssistantTypes\";\nimport { generateId, generateOptimisticId } from \"../../utils/idUtils\";\nimport { fromCoreMessage } from \"../edge/converters/fromCoreMessage\";\nimport { ThreadMessageLike } from \"../external-store\";\nimport { getAutoStatus } from \"../external-store/auto-status\";\nimport { fromThreadMessageLike } from \"../external-store/ThreadMessageLike\";\n\n/**\n * Represents a parent node in the repository tree structure.\n */\ntype RepositoryParent = {\n /** IDs of child messages */\n children: string[];\n /** Reference to the next message in the active branch */\n next: RepositoryMessage | null;\n};\n\n/**\n * Represents a message node in the repository tree structure.\n */\ntype RepositoryMessage = RepositoryParent & {\n /** Reference to the parent message */\n prev: RepositoryMessage | null;\n /** The actual message data */\n current: ThreadMessage;\n /** The depth level in the tree (0 for root messages) */\n level: number;\n};\n\n/**\n * Represents a message item that can be exported from the repository.\n */\nexport type ExportedMessageRepositoryItem = {\n /** The message data */\n message: ThreadMessage;\n /** ID of the parent message, or null for root messages */\n parentId: string | null;\n};\n\n/**\n * Represents the entire repository state for export/import.\n */\nexport type ExportedMessageRepository = {\n /** ID of the head message, or null/undefined if no head */\n headId?: string | null;\n /** Array of all messages with their parent references */\n messages: Array<{\n message: ThreadMessage;\n parentId: string | null;\n }>;\n};\n\n/**\n * Utility functions for working with exported message repositories.\n */\nexport const ExportedMessageRepository = {\n /**\n * Converts an array of messages to an ExportedMessageRepository format.\n * Creates parent-child relationships based on the order of messages in the array.\n *\n * @param messages - Array of message-like objects to convert\n * @returns ExportedMessageRepository with parent-child relationships established\n */\n fromArray: (\n messages: readonly ThreadMessageLike[],\n ): ExportedMessageRepository => {\n const conv = messages.map((m) =>\n fromThreadMessageLike(m, generateId(), getAutoStatus(false, false)),\n );\n\n return {\n messages: conv.map((m, idx) => ({\n parentId: idx > 0 ? conv[idx - 1]!.id : null,\n message: m,\n })),\n };\n },\n};\n\n/**\n * Recursively finds the head (leaf) message in a branch.\n *\n * @param message - The starting message or parent node\n * @returns The leaf message of the branch, or null if not found\n */\nconst findHead = (\n message: RepositoryMessage | RepositoryParent,\n): RepositoryMessage | null => {\n if (message.next) return findHead(message.next);\n if (\"current\" in message) return message;\n return null;\n};\n\n/**\n * A utility class for caching computed values and invalidating the cache when needed.\n */\nclass CachedValue<T> {\n private _value: T | null = null;\n\n /**\n * @param func - The function that computes the cached value\n */\n constructor(private func: () => T) {}\n\n /**\n * Gets the cached value, computing it if necessary.\n */\n get value() {\n if (this._value === null) {\n this._value = this.func();\n }\n return this._value;\n }\n\n /**\n * Invalidates the cache, forcing recomputation on next access.\n */\n dirty() {\n this._value = null;\n }\n}\n\n/**\n * A repository that manages a tree of messages with branching capabilities.\n * Supports operations like adding, updating, and deleting messages, as well as\n * managing multiple conversation branches.\n */\nexport class MessageRepository {\n /** Map of message IDs to repository message objects */\n private messages = new Map<string, RepositoryMessage>();\n /** Reference to the current head (most recent) message in the active branch */\n private head: RepositoryMessage | null = null;\n /** Root node of the tree structure */\n private root: RepositoryParent = {\n children: [],\n next: null,\n };\n\n /**\n * Performs link/unlink operations between messages in the tree.\n *\n * @param newParent - The new parent message, or null\n * @param child - The child message to operate on\n * @param operation - The type of operation to perform:\n * - \"cut\": Remove the child from its current parent\n * - \"link\": Add the child to a new parent\n * - \"relink\": Both cut and link operations\n */\n private performOp(\n newParent: RepositoryMessage | null,\n child: RepositoryMessage,\n operation: \"cut\" | \"link\" | \"relink\",\n ) {\n const parentOrRoot = child.prev ?? this.root;\n const newParentOrRoot = newParent ?? this.root;\n\n if (operation === \"relink\" && parentOrRoot === newParentOrRoot) return;\n\n // cut\n if (operation !== \"link\") {\n // remove from parentOrRoot.children\n parentOrRoot.children = parentOrRoot.children.filter(\n (m) => m !== child.current.id,\n );\n\n // update parentOrRoot.next\n if (parentOrRoot.next === child) {\n const fallbackId = parentOrRoot.children.at(-1);\n const fallback = fallbackId ? this.messages.get(fallbackId) : null;\n if (fallback === undefined) {\n throw new Error(\n \"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.\",\n );\n }\n parentOrRoot.next = fallback;\n }\n }\n\n // link\n if (operation !== \"cut\") {\n // ensure the child is not part of parent tree\n for (\n let current: RepositoryMessage | null = newParent;\n current;\n current = current.prev\n ) {\n if (current.current.id === child.current.id) {\n throw new Error(\n \"MessageRepository(performOp/link): A message with the same id already exists in the parent tree. This error occurs if the same message id is found multiple times. This is likely an internal bug in assistant-ui.\",\n );\n }\n }\n\n // add to parentOrRoot.children\n newParentOrRoot.children = [\n ...newParentOrRoot.children,\n child.current.id,\n ];\n\n // update parentOrRoot.next\n if (findHead(child) === this.head || newParentOrRoot.next === null) {\n newParentOrRoot.next = child;\n }\n\n child.prev = newParent;\n }\n }\n\n /** Cached array of messages in the current active branch, from root to head */\n private _messages = new CachedValue<readonly ThreadMessage[]>(() => {\n const messages = new Array<ThreadMessage>(this.head?.level ?? 0);\n for (let current = this.head; current; current = current.prev) {\n messages[current.level] = current.current;\n }\n return messages;\n });\n\n /**\n * Gets the ID of the current head message.\n * @returns The ID of the head message, or null if no messages exist\n */\n get headId() {\n return this.head?.current.id ?? null;\n }\n\n /**\n * Gets all messages in the current active branch, from root to head.\n * @returns Array of messages in the current branch\n */\n getMessages() {\n return this._messages.value;\n }\n\n /**\n * Adds a new message or updates an existing one in the repository.\n * If the message ID already exists, the message is updated and potentially relinked to a new parent.\n * If the message is new, it's added as a child of the specified parent.\n *\n * @param parentId - ID of the parent message, or null for root messages\n * @param message - The message to add or update\n * @throws Error if the parent message is not found\n */\n addOrUpdateMessage(parentId: string | null, message: ThreadMessage) {\n const existingItem = this.messages.get(message.id);\n const prev = parentId ? this.messages.get(parentId) : null;\n if (prev === undefined)\n throw new Error(\n \"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n // update existing message\n if (existingItem) {\n existingItem.current = message;\n this.performOp(prev, existingItem, \"relink\");\n this._messages.dirty();\n return;\n }\n\n // create a new message\n const newItem: RepositoryMessage = {\n prev,\n current: message,\n next: null,\n children: [],\n level: prev ? prev.level + 1 : 0,\n };\n\n this.messages.set(message.id, newItem);\n this.performOp(prev, newItem, \"link\");\n\n if (this.head === prev) {\n this.head = newItem;\n }\n\n this._messages.dirty();\n }\n\n /**\n * Gets a message and its parent ID by message ID.\n *\n * @param messageId - ID of the message to retrieve\n * @returns Object containing the message and its parent ID\n * @throws Error if the message is not found\n */\n getMessage(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n return {\n parentId: message.prev?.current.id ?? null,\n message: message.current,\n };\n }\n\n /**\n * Adds an optimistic message to the repository.\n * An optimistic message is a temporary placeholder that will be replaced by a real message later.\n *\n * @param parentId - ID of the parent message, or null for root messages\n * @param message - The core message to convert to an optimistic message\n * @returns The generated optimistic ID\n */\n appendOptimisticMessage(parentId: string | null, message: CoreMessage) {\n let optimisticId: string;\n do {\n optimisticId = generateOptimisticId();\n } while (this.messages.has(optimisticId));\n\n this.addOrUpdateMessage(\n parentId,\n fromCoreMessage(message, {\n id: optimisticId,\n status: { type: \"running\" },\n }),\n );\n\n return optimisticId;\n }\n\n /**\n * Deletes a message from the repository and relinks its children.\n *\n * @param messageId - ID of the message to delete\n * @param replacementId - Optional ID of the message to become the new parent of the children,\n * undefined means use the deleted message's parent,\n * null means use the root\n * @throws Error if the message or replacement is not found\n */\n deleteMessage(messageId: string, replacementId?: string | null | undefined) {\n const message = this.messages.get(messageId);\n\n if (!message)\n throw new Error(\n \"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const replacement =\n replacementId === undefined\n ? message.prev // if no replacementId is provided, use the parent\n : replacementId === null\n ? null\n : this.messages.get(replacementId);\n if (replacement === undefined)\n throw new Error(\n \"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.\",\n );\n\n for (const child of message.children) {\n const childMessage = this.messages.get(child);\n if (!childMessage)\n throw new Error(\n \"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.\",\n );\n this.performOp(replacement, childMessage, \"relink\");\n }\n\n this.performOp(null, message, \"cut\");\n this.messages.delete(messageId);\n\n if (this.head === message) {\n this.head = findHead(replacement ?? this.root);\n }\n\n this._messages.dirty();\n }\n\n /**\n * Gets all branch IDs (sibling messages) at the level of a specified message.\n *\n * @param messageId - ID of the message to find branches for\n * @returns Array of message IDs representing branches\n * @throws Error if the message is not found\n */\n getBranches(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const { children } = message.prev ?? this.root;\n return children;\n }\n\n /**\n * Switches the active branch to the one containing the specified message.\n *\n * @param messageId - ID of the message in the branch to switch to\n * @throws Error if the branch is not found\n */\n switchToBranch(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const prevOrRoot = message.prev ?? this.root;\n prevOrRoot.next = message;\n\n this.head = findHead(message);\n\n this._messages.dirty();\n }\n\n /**\n * Resets the head to a specific message or null.\n *\n * @param messageId - ID of the message to set as head, or null to clear the head\n * @throws Error if the message is not found\n */\n resetHead(messageId: string | null) {\n if (messageId === null) {\n this.head = null;\n this._messages.dirty();\n return;\n }\n\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n this.head = message;\n for (\n let current: RepositoryMessage | null = message;\n current;\n current = current.prev\n ) {\n if (current.prev) {\n current.prev.next = current;\n }\n }\n\n this._messages.dirty();\n }\n\n /**\n * Clears all messages from the repository.\n */\n clear(): void {\n this.messages.clear();\n this.head = null;\n this.root = {\n children: [],\n next: null,\n };\n this._messages.dirty();\n }\n\n /**\n * Exports the repository state for persistence.\n *\n * @returns Exportable repository state\n */\n export(): ExportedMessageRepository {\n const exportItems: ExportedMessageRepository[\"messages\"] = [];\n\n // hint: we are relying on the insertion order of the messages\n // this is important for the import function to properly link the messages\n for (const [, message] of this.messages) {\n exportItems.push({\n message: message.current,\n parentId: message.prev?.current.id ?? null,\n });\n }\n\n return {\n headId: this.head?.current.id ?? null,\n messages: exportItems,\n };\n }\n\n /**\n * Imports repository state from an exported repository.\n *\n * @param repository - The exported repository state to import\n */\n import({ headId, messages }: ExportedMessageRepository) {\n for (const { message, parentId } of messages) {\n this.addOrUpdateMessage(parentId, message);\n }\n\n // switch to the saved head id if it is not the most recent message\n this.resetHead(headId ?? messages.at(-1)?.message.id ?? null);\n }\n}\n"],"mappings":";AACA,SAAS,YAAY,4BAA4B;AACjD,SAAS,uBAAuB;AAEhC,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAkD/B,IAAM,4BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQvC,WAAW,CACT,aAC8B;AAC9B,UAAM,OAAO,SAAS;AAAA,MAAI,CAAC,MACzB,sBAAsB,GAAG,WAAW,GAAG,cAAc,OAAO,KAAK,CAAC;AAAA,IACpE;AAEA,WA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R;AAAA,MACF;AAEF,SAAK,OAAO;AACZ,aACM,UAAoC,SACxC,SACA,UAAU,QAAQ,MAClB;AACA,UAAI,QAAQ,MAAM;AAChB,gBAAQ,KAAK,OAAO;AAAA,MACtB;AAAA,IACF;AAEA,SAAK,UAAU,MAAM;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,QAAc;AACZ,SAAK,SAAS,MAAM;AACpB,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,MACV,UAAU,CAAC;AAAA,MACX,MAAM;AAAA,IACR;AACA,SAAK,UAAU,MAAM;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,SAAoC;AAClC,UAAM,cAAqD,CAAC;AAI5D,eAAW,CAAC,EAAE,OAAO,KAAK,KAAK,UAAU;AACvC,kBAAY,KAAK;AAAA,QACf,SAAS,QAAQ;AAAA,QACjB,UAAU,QAAQ,MAAM,QAAQ,MAAM;AAAA,MACxC,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,MACL,QAAQ,KAAK,MAAM,QAAQ,MAAM;AAAA,MACjC,UAAU;AAAA,IACZ;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,OAAO,EAAE,QAAQ,SAAS,GAA8B;AACtD,eAAW,EAAE,SAAS,SAAS,KAAK,UAAU;AAC5C,WAAK,mBAAmB,UAAU,OAAO;AAAA,IAC3C;AAGA,SAAK,UAAU,UAAU,SAAS,GAAG,EAAE,GAAG,QAAQ,MAAM,IAAI;AAAA,EAC9D;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/utils/MessageRepository.tsx"],"sourcesContent":["import type { ThreadMessage } from \"../../types\";\nimport { generateId, generateOptimisticId } from \"../../utils/idUtils\";\nimport { ThreadMessageLike } from \"../external-store\";\nimport { getAutoStatus } from \"../external-store/auto-status\";\nimport { fromThreadMessageLike } from \"../external-store/ThreadMessageLike\";\n\n/**\n * Represents a parent node in the repository tree structure.\n */\ntype RepositoryParent = {\n /** IDs of child messages */\n children: string[];\n /** Reference to the next message in the active branch */\n next: RepositoryMessage | null;\n};\n\n/**\n * Represents a message node in the repository tree structure.\n */\ntype RepositoryMessage = RepositoryParent & {\n /** Reference to the parent message */\n prev: RepositoryMessage | null;\n /** The actual message data */\n current: ThreadMessage;\n /** The depth level in the tree (0 for root messages) */\n level: number;\n};\n\n/**\n * Represents a message item that can be exported from the repository.\n */\nexport type ExportedMessageRepositoryItem = {\n /** The message data */\n message: ThreadMessage;\n /** ID of the parent message, or null for root messages */\n parentId: string | null;\n};\n\n/**\n * Represents the entire repository state for export/import.\n */\nexport type ExportedMessageRepository = {\n /** ID of the head message, or null/undefined if no head */\n headId?: string | null;\n /** Array of all messages with their parent references */\n messages: Array<{\n message: ThreadMessage;\n parentId: string | null;\n }>;\n};\n\n/**\n * Utility functions for working with exported message repositories.\n */\nexport const ExportedMessageRepository = {\n /**\n * Converts an array of messages to an ExportedMessageRepository format.\n * Creates parent-child relationships based on the order of messages in the array.\n *\n * @param messages - Array of message-like objects to convert\n * @returns ExportedMessageRepository with parent-child relationships established\n */\n fromArray: (\n messages: readonly ThreadMessageLike[],\n ): ExportedMessageRepository => {\n const conv = messages.map((m) =>\n fromThreadMessageLike(m, generateId(), getAutoStatus(false, false)),\n );\n\n return {\n messages: conv.map((m, idx) => ({\n parentId: idx > 0 ? conv[idx - 1]!.id : null,\n message: m,\n })),\n };\n },\n};\n\n/**\n * Recursively finds the head (leaf) message in a branch.\n *\n * @param message - The starting message or parent node\n * @returns The leaf message of the branch, or null if not found\n */\nconst findHead = (\n message: RepositoryMessage | RepositoryParent,\n): RepositoryMessage | null => {\n if (message.next) return findHead(message.next);\n if (\"current\" in message) return message;\n return null;\n};\n\n/**\n * A utility class for caching computed values and invalidating the cache when needed.\n */\nclass CachedValue<T> {\n private _value: T | null = null;\n\n /**\n * @param func - The function that computes the cached value\n */\n constructor(private func: () => T) {}\n\n /**\n * Gets the cached value, computing it if necessary.\n */\n get value() {\n if (this._value === null) {\n this._value = this.func();\n }\n return this._value;\n }\n\n /**\n * Invalidates the cache, forcing recomputation on next access.\n */\n dirty() {\n this._value = null;\n }\n}\n\n/**\n * A repository that manages a tree of messages with branching capabilities.\n * Supports operations like adding, updating, and deleting messages, as well as\n * managing multiple conversation branches.\n */\nexport class MessageRepository {\n /** Map of message IDs to repository message objects */\n private messages = new Map<string, RepositoryMessage>();\n /** Reference to the current head (most recent) message in the active branch */\n private head: RepositoryMessage | null = null;\n /** Root node of the tree structure */\n private root: RepositoryParent = {\n children: [],\n next: null,\n };\n\n /**\n * Performs link/unlink operations between messages in the tree.\n *\n * @param newParent - The new parent message, or null\n * @param child - The child message to operate on\n * @param operation - The type of operation to perform:\n * - \"cut\": Remove the child from its current parent\n * - \"link\": Add the child to a new parent\n * - \"relink\": Both cut and link operations\n */\n private performOp(\n newParent: RepositoryMessage | null,\n child: RepositoryMessage,\n operation: \"cut\" | \"link\" | \"relink\",\n ) {\n const parentOrRoot = child.prev ?? this.root;\n const newParentOrRoot = newParent ?? this.root;\n\n if (operation === \"relink\" && parentOrRoot === newParentOrRoot) return;\n\n // cut\n if (operation !== \"link\") {\n // remove from parentOrRoot.children\n parentOrRoot.children = parentOrRoot.children.filter(\n (m) => m !== child.current.id,\n );\n\n // update parentOrRoot.next\n if (parentOrRoot.next === child) {\n const fallbackId = parentOrRoot.children.at(-1);\n const fallback = fallbackId ? this.messages.get(fallbackId) : null;\n if (fallback === undefined) {\n throw new Error(\n \"MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.\",\n );\n }\n parentOrRoot.next = fallback;\n }\n }\n\n // link\n if (operation !== \"cut\") {\n // ensure the child is not part of parent tree\n for (\n let current: RepositoryMessage | null = newParent;\n current;\n current = current.prev\n ) {\n if (current.current.id === child.current.id) {\n throw new Error(\n \"MessageRepository(performOp/link): A message with the same id already exists in the parent tree. This error occurs if the same message id is found multiple times. This is likely an internal bug in assistant-ui.\",\n );\n }\n }\n\n // add to parentOrRoot.children\n newParentOrRoot.children = [\n ...newParentOrRoot.children,\n child.current.id,\n ];\n\n // update parentOrRoot.next\n if (findHead(child) === this.head || newParentOrRoot.next === null) {\n newParentOrRoot.next = child;\n }\n\n child.prev = newParent;\n }\n }\n\n /** Cached array of messages in the current active branch, from root to head */\n private _messages = new CachedValue<readonly ThreadMessage[]>(() => {\n const messages = new Array<ThreadMessage>(this.head?.level ?? 0);\n for (let current = this.head; current; current = current.prev) {\n messages[current.level] = current.current;\n }\n return messages;\n });\n\n /**\n * Gets the ID of the current head message.\n * @returns The ID of the head message, or null if no messages exist\n */\n get headId() {\n return this.head?.current.id ?? null;\n }\n\n /**\n * Gets all messages in the current active branch, from root to head.\n * @returns Array of messages in the current branch\n */\n getMessages() {\n return this._messages.value;\n }\n\n /**\n * Adds a new message or updates an existing one in the repository.\n * If the message ID already exists, the message is updated and potentially relinked to a new parent.\n * If the message is new, it's added as a child of the specified parent.\n *\n * @param parentId - ID of the parent message, or null for root messages\n * @param message - The message to add or update\n * @throws Error if the parent message is not found\n */\n addOrUpdateMessage(parentId: string | null, message: ThreadMessage) {\n const existingItem = this.messages.get(message.id);\n const prev = parentId ? this.messages.get(parentId) : null;\n if (prev === undefined)\n throw new Error(\n \"MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n // update existing message\n if (existingItem) {\n existingItem.current = message;\n this.performOp(prev, existingItem, \"relink\");\n this._messages.dirty();\n return;\n }\n\n // create a new message\n const newItem: RepositoryMessage = {\n prev,\n current: message,\n next: null,\n children: [],\n level: prev ? prev.level + 1 : 0,\n };\n\n this.messages.set(message.id, newItem);\n this.performOp(prev, newItem, \"link\");\n\n if (this.head === prev) {\n this.head = newItem;\n }\n\n this._messages.dirty();\n }\n\n /**\n * Gets a message and its parent ID by message ID.\n *\n * @param messageId - ID of the message to retrieve\n * @returns Object containing the message and its parent ID\n * @throws Error if the message is not found\n */\n getMessage(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n return {\n parentId: message.prev?.current.id ?? null,\n message: message.current,\n };\n }\n\n /**\n * Adds an optimistic message to the repository.\n * An optimistic message is a temporary placeholder that will be replaced by a real message later.\n *\n * @param parentId - ID of the parent message, or null for root messages\n * @param message - The core message to convert to an optimistic message\n * @returns The generated optimistic ID\n */\n appendOptimisticMessage(parentId: string | null, message: ThreadMessageLike) {\n let optimisticId: string;\n do {\n optimisticId = generateOptimisticId();\n } while (this.messages.has(optimisticId));\n\n this.addOrUpdateMessage(\n parentId,\n fromThreadMessageLike(message, optimisticId, { type: \"running\" }),\n );\n\n return optimisticId;\n }\n\n /**\n * Deletes a message from the repository and relinks its children.\n *\n * @param messageId - ID of the message to delete\n * @param replacementId - Optional ID of the message to become the new parent of the children,\n * undefined means use the deleted message's parent,\n * null means use the root\n * @throws Error if the message or replacement is not found\n */\n deleteMessage(messageId: string, replacementId?: string | null | undefined) {\n const message = this.messages.get(messageId);\n\n if (!message)\n throw new Error(\n \"MessageRepository(deleteMessage): Optimistic message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const replacement =\n replacementId === undefined\n ? message.prev // if no replacementId is provided, use the parent\n : replacementId === null\n ? null\n : this.messages.get(replacementId);\n if (replacement === undefined)\n throw new Error(\n \"MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.\",\n );\n\n for (const child of message.children) {\n const childMessage = this.messages.get(child);\n if (!childMessage)\n throw new Error(\n \"MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.\",\n );\n this.performOp(replacement, childMessage, \"relink\");\n }\n\n this.performOp(null, message, \"cut\");\n this.messages.delete(messageId);\n\n if (this.head === message) {\n this.head = findHead(replacement ?? this.root);\n }\n\n this._messages.dirty();\n }\n\n /**\n * Gets all branch IDs (sibling messages) at the level of a specified message.\n *\n * @param messageId - ID of the message to find branches for\n * @returns Array of message IDs representing branches\n * @throws Error if the message is not found\n */\n getBranches(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const { children } = message.prev ?? this.root;\n return children;\n }\n\n /**\n * Switches the active branch to the one containing the specified message.\n *\n * @param messageId - ID of the message in the branch to switch to\n * @throws Error if the branch is not found\n */\n switchToBranch(messageId: string) {\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n const prevOrRoot = message.prev ?? this.root;\n prevOrRoot.next = message;\n\n this.head = findHead(message);\n\n this._messages.dirty();\n }\n\n /**\n * Resets the head to a specific message or null.\n *\n * @param messageId - ID of the message to set as head, or null to clear the head\n * @throws Error if the message is not found\n */\n resetHead(messageId: string | null) {\n if (messageId === null) {\n this.head = null;\n this._messages.dirty();\n return;\n }\n\n const message = this.messages.get(messageId);\n if (!message)\n throw new Error(\n \"MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.\",\n );\n\n this.head = message;\n for (\n let current: RepositoryMessage | null = message;\n current;\n current = current.prev\n ) {\n if (current.prev) {\n current.prev.next = current;\n }\n }\n\n this._messages.dirty();\n }\n\n /**\n * Clears all messages from the repository.\n */\n clear(): void {\n this.messages.clear();\n this.head = null;\n this.root = {\n children: [],\n next: null,\n };\n this._messages.dirty();\n }\n\n /**\n * Exports the repository state for persistence.\n *\n * @returns Exportable repository state\n */\n export(): ExportedMessageRepository {\n const exportItems: ExportedMessageRepository[\"messages\"] = [];\n\n // hint: we are relying on the insertion order of the messages\n // this is important for the import function to properly link the messages\n for (const [, message] of this.messages) {\n exportItems.push({\n message: message.current,\n parentId: message.prev?.current.id ?? null,\n });\n }\n\n return {\n headId: this.head?.current.id ?? null,\n messages: exportItems,\n };\n }\n\n /**\n * Imports repository state from an exported repository.\n *\n * @param repository - The exported repository state to import\n */\n import({ headId, messages }: ExportedMessageRepository) {\n for (const { message, parentId } of messages) {\n this.addOrUpdateMessage(parentId, message);\n }\n\n // switch to the saved head id if it is not the most recent message\n this.resetHead(headId ?? messages.at(-1)?.message.id ?? null);\n }\n}\n"],"mappings":";AACA,SAAS,YAAY,4BAA4B;AAEjD,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AAkD/B,IAAM,4BAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQvC,WAAW,CACT,aAC8B;AAC9B,UAAM,OAAO,SAAS;AAAA,MAAI,CAAC,MACzB,sBAAsB,GAAG,WAAW,GAAG,cAAc,OAAO,KAAK,CAAC;AAAA,IACpE;AAEA,WAAO;AAAA,MACL,UAAU,KAAK,IAAI,CAAC,GAAG,SAAS;AAAA,QAC9B,UAAU,MAAM,IAAI,KAAK,MAAM,CAAC,EAAG,KAAK;AAAA,QACxC,SAAS;AAAA,MACX,EAAE;AAAA,IACJ;AAAA,EACF;AACF;AAQA,IAAM,WAAW,CACf,YAC6B;AAC7B,MAAI,QAAQ,KAAM,QAAO,SAAS,QAAQ,IAAI;AAC9C,MAAI,aAAa,QAAS,QAAO;AACjC,SAAO;AACT;AAKA,IAAM,cAAN,MAAqB;AAAA;AAAA;AAAA;AAAA,EAMnB,YAAoB,MAAe;AAAf;AAAA,EAAgB;AAAA,EAL5B,SAAmB;AAAA;AAAA;AAAA;AAAA,EAU3B,IAAI,QAAQ;AACV,QAAI,KAAK,WAAW,MAAM;AACxB,WAAK,SAAS,KAAK,KAAK;AAAA,IAC1B;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,QAAQ;AACN,SAAK,SAAS;AAAA,EAChB;AACF;AAOO,IAAM,oBAAN,MAAwB;AAAA;AAAA,EAErB,WAAW,oBAAI,IAA+B;AAAA;AAAA,EAE9C,OAAiC;AAAA;AAAA,EAEjC,OAAyB;AAAA,IAC/B,UAAU,CAAC;AAAA,IACX,MAAM;AAAA,EACR;AAAA;AAAA;AA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;AAAA,IAC3C;AAGA,SAAK,UAAU,UAAU,SAAS,GAAG,EAAE,GAAG,QAAQ,MAAM,IAAI;AAAA,EAC9D;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import { CompleteAttachment } from "./AttachmentTypes";
2
2
  import { ReadonlyJSONObject, ReadonlyJSONValue } from "../utils/json/json-value";
3
- export type MessageRole = "user" | "assistant" | "system";
3
+ export type MessageRole = ThreadMessage["role"];
4
4
  export type TextContentPart = {
5
5
  readonly type: "text";
6
6
  readonly text: string;
@@ -32,53 +32,13 @@ export type Unstable_AudioContentPart = {
32
32
  readonly format: "mp3" | "wav";
33
33
  };
34
34
  };
35
- /**
36
- * @deprecated UI content parts are deprecated and will be removed in v0.8.0.
37
- * Migration guide for external-store users using UI content parts:
38
- * If you must, store UI elements on your external store messages, update your
39
- * external store converter:
40
- * ```ts
41
- * const UI_PLACEHOLDER = Object.freeze({ type: "text", text: "UI content placeholder" });
42
- * const convertMessage = (message: TMessage): ThreadMessageLike => ({
43
- * content: [
44
- * // other content parts,
45
- * UI_PLACEHOLDER
46
- * ],
47
- * });
48
- * ```
49
- *
50
- * Then, define a custom `TextContentPartComponent`:
51
- *
52
- * ```tsx
53
- * const MyText: FC = () => {
54
- * const isUIPlaceholder = useContentPart(p => p === UI_PLACEHOLDER);
55
- *
56
- * // this assumes that you have a `display` field on your original message objects before conversion.
57
- * const ui = useMessage(m => isUIPlaceholder ? getExternalStoreMessage(m).display : undefined);
58
- * if (ui) {
59
- * return ui;
60
- * }
61
- *
62
- * return <MarkdownText />; // your default text component
63
- * }
64
- * ```
65
- *
66
- * Pass this component to your Thread:
67
- *
68
- * ```tsx
69
- * <Thread assistantMessage={{ components: { Text: MyText } }} userMessage={{ components: { Text: MyText } }} />
70
- * ```
71
- */
72
- export type UIContentPart = never;
73
- export type CoreToolCallContentPart<TArgs = ReadonlyJSONObject, TResult = unknown> = {
35
+ export type ToolCallContentPart<TArgs = ReadonlyJSONObject, TResult = unknown> = {
74
36
  readonly type: "tool-call";
75
37
  readonly toolCallId: string;
76
38
  readonly toolName: string;
77
39
  readonly args: TArgs;
78
40
  readonly result?: TResult | undefined;
79
41
  readonly isError?: boolean | undefined;
80
- };
81
- export type ToolCallContentPart<TArgs = ReadonlyJSONObject, TResult = unknown> = CoreToolCallContentPart<TArgs, TResult> & {
82
42
  readonly argsText: string;
83
43
  readonly artifact?: unknown;
84
44
  };
@@ -150,12 +110,11 @@ export type ThreadAssistantMessage = MessageCommonProps & {
150
110
  export type RunConfig = {
151
111
  readonly custom?: Record<string, unknown>;
152
112
  };
153
- export type AppendMessage = CoreMessage & {
113
+ export type AppendMessage = Omit<ThreadMessage, "id"> & {
154
114
  parentId: string | null;
155
115
  /** The ID of the message that was edited or undefined. */
156
116
  sourceId: string | null;
157
117
  runConfig: RunConfig | undefined;
158
- attachments: readonly CompleteAttachment[];
159
118
  startRun?: boolean | undefined;
160
119
  };
161
120
  type BaseThreadMessage = {
@@ -169,21 +128,5 @@ type BaseThreadMessage = {
169
128
  readonly attachments?: ThreadUserMessage["attachments"];
170
129
  };
171
130
  export type ThreadMessage = BaseThreadMessage & (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);
172
- /** Core Message Types (without UI content parts) */
173
- export type CoreUserContentPart = TextContentPart | ImageContentPart | FileContentPart | Unstable_AudioContentPart;
174
- export type CoreAssistantContentPart = TextContentPart | CoreToolCallContentPart;
175
- export type CoreSystemMessage = {
176
- role: "system";
177
- content: readonly [TextContentPart];
178
- };
179
- export type CoreUserMessage = {
180
- role: "user";
181
- content: readonly CoreUserContentPart[];
182
- };
183
- export type CoreAssistantMessage = {
184
- role: "assistant";
185
- content: readonly CoreAssistantContentPart[];
186
- };
187
- export type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage;
188
131
  export {};
189
132
  //# sourceMappingURL=AssistantTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AssistantTypes.d.ts","sourceRoot":"","sources":["../../src/types/AssistantTypes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ACjC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACnD,QAAQ,CAAC,QAAQ,EAAE;QACjB,QAAQ,CAAC,oBAAoB,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;QAC7D,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;QACtD,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;QACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC1C,CAAC;IACF,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;CACzD,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,iBAAiB,GAC3C,CAAC,mBAAmB,GAAG,iBAAiB,GAAG,sBAAsB,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/AssistantTypes.ts"],"sourcesContent":["import { CompleteAttachment } from \"./AttachmentTypes\";\nimport {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"../utils/json/json-value\";\n\nexport type MessageRole = \"user\" | \"assistant\" | \"system\";\n\nexport type TextContentPart = {\n readonly type: \"text\";\n readonly text: string;\n};\n\nexport type ReasoningContentPart = {\n readonly type: \"reasoning\";\n readonly text: string;\n};\n\nexport type SourceContentPart = {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n};\n\nexport type ImageContentPart = {\n readonly type: \"image\";\n readonly image: string;\n};\n\nexport type FileContentPart = {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n};\n\nexport type Unstable_AudioContentPart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\n/**\n * @deprecated UI content parts are deprecated and will be removed in v0.8.0.\n * Migration guide for external-store users using UI content parts:\n * If you must, store UI elements on your external store messages, update your\n * external store converter:\n * ```ts\n * const UI_PLACEHOLDER = Object.freeze({ type: \"text\", text: \"UI content placeholder\" });\n * const convertMessage = (message: TMessage): ThreadMessageLike => ({\n * content: [\n * // other content parts,\n * UI_PLACEHOLDER\n * ],\n * });\n * ```\n *\n * Then, define a custom `TextContentPartComponent`:\n *\n * ```tsx\n * const MyText: FC = () => {\n * const isUIPlaceholder = useContentPart(p => p === UI_PLACEHOLDER);\n *\n * // this assumes that you have a `display` field on your original message objects before conversion.\n * const ui = useMessage(m => isUIPlaceholder ? getExternalStoreMessage(m).display : undefined);\n * if (ui) {\n * return ui;\n * }\n *\n * return <MarkdownText />; // your default text component\n * }\n * ```\n *\n * Pass this component to your Thread:\n *\n * ```tsx\n * <Thread assistantMessage={{ components: { Text: MyText } }} userMessage={{ components: { Text: MyText } }} />\n * ```\n */\nexport type UIContentPart = never;\n\nexport type CoreToolCallContentPart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: TArgs;\n readonly result?: TResult | undefined;\n readonly isError?: boolean | undefined;\n};\n\nexport type ToolCallContentPart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = CoreToolCallContentPart<TArgs, TResult> & {\n readonly argsText: string;\n readonly artifact?: unknown;\n};\n\nexport type ThreadUserContentPart =\n | TextContentPart\n | ImageContentPart\n | FileContentPart\n | Unstable_AudioContentPart;\n\nexport type ThreadAssistantContentPart =\n | TextContentPart\n | ReasoningContentPart\n | ToolCallContentPart\n | SourceContentPart\n | FileContentPart;\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly promptTokens: number;\n readonly completionTokens: number;\n }\n | undefined;\n};\n\nexport type ContentPartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ToolCallContentPartStatus =\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | ContentPartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextContentPart];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserContentPart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantContentPart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type RunConfig = {\n // TODO allow user customization via global type overrides\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = CoreMessage & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n\n attachments: readonly CompleteAttachment[];\n startRun?: boolean | undefined;\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n\n/** Core Message Types (without UI content parts) */\n\nexport type CoreUserContentPart =\n | TextContentPart\n | ImageContentPart\n | FileContentPart\n | Unstable_AudioContentPart;\nexport type CoreAssistantContentPart =\n | TextContentPart\n | CoreToolCallContentPart;\n\nexport type CoreSystemMessage = {\n role: \"system\";\n content: readonly [TextContentPart];\n};\n\nexport type CoreUserMessage = {\n role: \"user\";\n content: readonly CoreUserContentPart[];\n};\n\nexport type CoreAssistantMessage = {\n role: \"assistant\";\n content: readonly CoreAssistantContentPart[];\n};\n\nexport type CoreMessage =\n | CoreSystemMessage\n | CoreUserMessage\n | CoreAssistantMessage;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/AssistantTypes.ts"],"sourcesContent":["import { CompleteAttachment } from \"./AttachmentTypes\";\nimport {\n ReadonlyJSONObject,\n ReadonlyJSONValue,\n} from \"../utils/json/json-value\";\n\nexport type MessageRole = ThreadMessage[\"role\"];\n\nexport type TextContentPart = {\n readonly type: \"text\";\n readonly text: string;\n};\n\nexport type ReasoningContentPart = {\n readonly type: \"reasoning\";\n readonly text: string;\n};\n\nexport type SourceContentPart = {\n readonly type: \"source\";\n readonly sourceType: \"url\";\n readonly id: string;\n readonly url: string;\n readonly title?: string;\n};\n\nexport type ImageContentPart = {\n readonly type: \"image\";\n readonly image: string;\n};\n\nexport type FileContentPart = {\n readonly type: \"file\";\n readonly data: string;\n readonly mimeType: string;\n};\n\nexport type Unstable_AudioContentPart = {\n readonly type: \"audio\";\n readonly audio: {\n readonly data: string;\n readonly format: \"mp3\" | \"wav\";\n };\n};\n\nexport type ToolCallContentPart<\n TArgs = ReadonlyJSONObject,\n TResult = unknown,\n> = {\n readonly type: \"tool-call\";\n readonly toolCallId: string;\n readonly toolName: string;\n readonly args: TArgs;\n readonly result?: TResult | undefined;\n readonly isError?: boolean | undefined;\n readonly argsText: string;\n readonly artifact?: unknown;\n};\n\nexport type ThreadUserContentPart =\n | TextContentPart\n | ImageContentPart\n | FileContentPart\n | Unstable_AudioContentPart;\n\nexport type ThreadAssistantContentPart =\n | TextContentPart\n | ReasoningContentPart\n | ToolCallContentPart\n | SourceContentPart\n | FileContentPart;\n\ntype MessageCommonProps = {\n readonly id: string;\n readonly createdAt: Date;\n};\n\nexport type ThreadStep = {\n readonly messageId?: string;\n readonly usage?:\n | {\n readonly promptTokens: number;\n readonly completionTokens: number;\n }\n | undefined;\n};\n\nexport type ContentPartStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"complete\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: unknown;\n };\n\nexport type ToolCallContentPartStatus =\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | ContentPartStatus;\n\nexport type MessageStatus =\n | {\n readonly type: \"running\";\n }\n | {\n readonly type: \"requires-action\";\n readonly reason: \"tool-calls\";\n }\n | {\n readonly type: \"complete\";\n readonly reason: \"stop\" | \"unknown\";\n }\n | {\n readonly type: \"incomplete\";\n readonly reason:\n | \"cancelled\"\n | \"tool-calls\"\n | \"length\"\n | \"content-filter\"\n | \"other\"\n | \"error\";\n readonly error?: ReadonlyJSONValue;\n };\n\nexport type ThreadSystemMessage = MessageCommonProps & {\n readonly role: \"system\";\n readonly content: readonly [TextContentPart];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadUserMessage = MessageCommonProps & {\n readonly role: \"user\";\n readonly content: readonly ThreadUserContentPart[];\n readonly attachments: readonly CompleteAttachment[];\n readonly metadata: {\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type ThreadAssistantMessage = MessageCommonProps & {\n readonly role: \"assistant\";\n readonly content: readonly ThreadAssistantContentPart[];\n readonly status: MessageStatus;\n readonly metadata: {\n readonly unstable_annotations: readonly ReadonlyJSONValue[];\n readonly unstable_data: readonly ReadonlyJSONValue[];\n readonly steps: readonly ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n};\n\nexport type RunConfig = {\n // TODO allow user customization via global type overrides\n readonly custom?: Record<string, unknown>;\n};\n\nexport type AppendMessage = Omit<ThreadMessage, \"id\"> & {\n parentId: string | null;\n\n /** The ID of the message that was edited or undefined. */\n sourceId: string | null;\n runConfig: RunConfig | undefined;\n startRun?: boolean | undefined;\n};\n\ntype BaseThreadMessage = {\n readonly status?: ThreadAssistantMessage[\"status\"];\n readonly metadata: {\n readonly unstable_annotations?: readonly ReadonlyJSONValue[];\n readonly unstable_data?: readonly ReadonlyJSONValue[];\n readonly steps?: readonly ThreadStep[];\n readonly custom: Record<string, unknown>;\n };\n readonly attachments?: ThreadUserMessage[\"attachments\"];\n};\n\nexport type ThreadMessage = BaseThreadMessage &\n (ThreadSystemMessage | ThreadUserMessage | ThreadAssistantMessage);\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,4 +1,4 @@
1
- import { CoreUserContentPart } from "./AssistantTypes";
1
+ import { ThreadUserContentPart } from "./AssistantTypes";
2
2
  export type PendingAttachmentStatus = {
3
3
  type: "running";
4
4
  reason: "uploading";
@@ -20,7 +20,7 @@ type BaseAttachment = {
20
20
  name: string;
21
21
  contentType: string;
22
22
  file?: File;
23
- content?: CoreUserContentPart[];
23
+ content?: ThreadUserContentPart[];
24
24
  };
25
25
  export type PendingAttachment = BaseAttachment & {
26
26
  status: PendingAttachmentStatus;
@@ -28,7 +28,7 @@ export type PendingAttachment = BaseAttachment & {
28
28
  };
29
29
  export type CompleteAttachment = BaseAttachment & {
30
30
  status: CompleteAttachmentStatus;
31
- content: CoreUserContentPart[];
31
+ content: ThreadUserContentPart[];
32
32
  };
33
33
  export type Attachment = PendingAttachment | CompleteAttachment;
34
34
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"AttachmentTypes.d.ts","sourceRoot":"","sources":["../../src/types/AttachmentTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD,MAAM,MAAM,uBAAuB,GAC/B;IACE,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,GACD;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,MAAM,EAAE,eAAe,CAAC;CACzB,GACD;IACE,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,EAAE,OAAO,GAAG,eAAe,CAAC;CACnC,CAAC;AAEN,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACxB,uBAAuB,GACvB,wBAAwB,CAAC;AAE7B,KAAK,cAAc,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,MAAM,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,mBAAmB,EAAE,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG;IAC/C,MAAM,EAAE,uBAAuB,CAAC;IAChC,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAAG;IAChD,MAAM,EAAE,wBAAwB,CAAC;IACjC,OAAO,EAAE,mBAAmB,EAAE,C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"version":3,"sources":["../../src/types/AttachmentTypes.ts"],"sourcesContent":["import { CoreUserContentPart } from \"./AssistantTypes\";\n\nexport type PendingAttachmentStatus =\n | {\n type: \"running\";\n reason: \"uploading\";\n progress: number;\n }\n | {\n type: \"requires-action\";\n reason: \"composer-send\";\n }\n | {\n type: \"incomplete\";\n reason: \"error\" | \"upload-paused\";\n };\n\nexport type CompleteAttachmentStatus = {\n type: \"complete\";\n};\n\nexport type AttachmentStatus =\n | PendingAttachmentStatus\n | CompleteAttachmentStatus;\n\ntype BaseAttachment = {\n id: string;\n type: \"image\" | \"document\" | \"file\";\n name: string;\n contentType: string;\n file?: File;\n content?: CoreUserContentPart[];\n};\n\nexport type PendingAttachment = BaseAttachment & {\n status: PendingAttachmentStatus;\n file: File;\n};\n\nexport type CompleteAttachment = BaseAttachment & {\n status: CompleteAttachmentStatus;\n content: CoreUserContentPart[];\n};\n\nexport type Attachment = PendingAttachment | CompleteAttachment;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/AttachmentTypes.ts"],"sourcesContent":["import { ThreadUserContentPart } from \"./AssistantTypes\";\n\nexport type PendingAttachmentStatus =\n | {\n type: \"running\";\n reason: \"uploading\";\n progress: number;\n }\n | {\n type: \"requires-action\";\n reason: \"composer-send\";\n }\n | {\n type: \"incomplete\";\n reason: \"error\" | \"upload-paused\";\n };\n\nexport type CompleteAttachmentStatus = {\n type: \"complete\";\n};\n\nexport type AttachmentStatus =\n | PendingAttachmentStatus\n | CompleteAttachmentStatus;\n\ntype BaseAttachment = {\n id: string;\n type: \"image\" | \"document\" | \"file\";\n name: string;\n contentType: string;\n file?: File;\n content?: ThreadUserContentPart[];\n};\n\nexport type PendingAttachment = BaseAttachment & {\n status: PendingAttachmentStatus;\n file: File;\n};\n\nexport type CompleteAttachment = BaseAttachment & {\n status: CompleteAttachmentStatus;\n content: ThreadUserContentPart[];\n};\n\nexport type Attachment = PendingAttachment | CompleteAttachment;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,5 +1,5 @@
1
1
  export type { Attachment, PendingAttachment, CompleteAttachment, AttachmentStatus, } from "./AttachmentTypes";
2
- export type { AppendMessage, TextContentPart, ReasoningContentPart, SourceContentPart, ImageContentPart, FileContentPart, Unstable_AudioContentPart, ToolCallContentPart, UIContentPart, MessageStatus, ThreadUserContentPart, ThreadAssistantContentPart, ThreadSystemMessage, ThreadAssistantMessage, ThreadUserMessage, ThreadMessage, CoreUserContentPart, CoreAssistantContentPart, CoreSystemMessage, CoreUserMessage, CoreAssistantMessage, CoreMessage, } from "./AssistantTypes";
2
+ export type { AppendMessage, TextContentPart, ReasoningContentPart, SourceContentPart, ImageContentPart, FileContentPart, Unstable_AudioContentPart, ToolCallContentPart, MessageStatus, ThreadUserContentPart, ThreadAssistantContentPart, ThreadSystemMessage, ThreadAssistantMessage, ThreadUserMessage, ThreadMessage, } from "./AssistantTypes";
3
3
  export type { EmptyContentPartProps, EmptyContentPartComponent, TextContentPartProps, TextContentPartComponent, ReasoningContentPartProps, ReasoningContentPartComponent, SourceContentPartProps, SourceContentPartComponent, ImageContentPartProps, ImageContentPartComponent, FileContentPartProps, FileContentPartComponent, Unstable_AudioContentPartProps, Unstable_AudioContentPartComponent, ToolCallContentPartProps, ToolCallContentPartComponent, } from "./ContentPartComponentTypes";
4
4
  export type { Unsubscribe } from "./Unsubscribe";
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EACb,aAAa,EAGb,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EAGb,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,6BAA6B,EAC7B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,8BAA8B,EAC9B,kCAAkC,EAClC,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AAErC,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,yBAAyB,EACzB,mBAAmB,EACnB,aAAa,EAGb,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,GACd,MAAM,kBAAkB,CAAC;AAE1B,YAAY,EACV,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,EACzB,6BAA6B,EAC7B,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,wBAAwB,EACxB,8BAA8B,EAC9B,kCAAkC,EAClC,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AAErC,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export type {\n Attachment,\n PendingAttachment,\n CompleteAttachment,\n AttachmentStatus,\n} from \"./AttachmentTypes\";\n\nexport type {\n AppendMessage,\n TextContentPart,\n ReasoningContentPart,\n SourceContentPart,\n ImageContentPart,\n FileContentPart,\n Unstable_AudioContentPart,\n ToolCallContentPart,\n UIContentPart,\n MessageStatus,\n\n // thread message types\n ThreadUserContentPart,\n ThreadAssistantContentPart,\n ThreadSystemMessage,\n ThreadAssistantMessage,\n ThreadUserMessage,\n ThreadMessage,\n\n // core message types\n CoreUserContentPart,\n CoreAssistantContentPart,\n CoreSystemMessage,\n CoreUserMessage,\n CoreAssistantMessage,\n CoreMessage,\n} from \"./AssistantTypes\";\n\nexport type {\n EmptyContentPartProps,\n EmptyContentPartComponent,\n TextContentPartProps,\n TextContentPartComponent,\n ReasoningContentPartProps,\n ReasoningContentPartComponent,\n SourceContentPartProps,\n SourceContentPartComponent,\n ImageContentPartProps,\n ImageContentPartComponent,\n FileContentPartProps,\n FileContentPartComponent,\n Unstable_AudioContentPartProps,\n Unstable_AudioContentPartComponent,\n ToolCallContentPartProps,\n ToolCallContentPartComponent,\n} from \"./ContentPartComponentTypes\";\n\nexport type { Unsubscribe } from \"./Unsubscribe\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../src/types/index.ts"],"sourcesContent":["export type {\n Attachment,\n PendingAttachment,\n CompleteAttachment,\n AttachmentStatus,\n} from \"./AttachmentTypes\";\n\nexport type {\n AppendMessage,\n TextContentPart,\n ReasoningContentPart,\n SourceContentPart,\n ImageContentPart,\n FileContentPart,\n Unstable_AudioContentPart,\n ToolCallContentPart,\n MessageStatus,\n\n // thread message types\n ThreadUserContentPart,\n ThreadAssistantContentPart,\n ThreadSystemMessage,\n ThreadAssistantMessage,\n ThreadUserMessage,\n ThreadMessage,\n} from \"./AssistantTypes\";\n\nexport type {\n EmptyContentPartProps,\n EmptyContentPartComponent,\n TextContentPartProps,\n TextContentPartComponent,\n ReasoningContentPartProps,\n ReasoningContentPartComponent,\n SourceContentPartProps,\n SourceContentPartComponent,\n ImageContentPartProps,\n ImageContentPartComponent,\n FileContentPartProps,\n FileContentPartComponent,\n Unstable_AudioContentPartProps,\n Unstable_AudioContentPartComponent,\n ToolCallContentPartProps,\n ToolCallContentPartComponent,\n} from \"./ContentPartComponentTypes\";\n\nexport type { Unsubscribe } from \"./Unsubscribe\";\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
package/package.json CHANGED
@@ -18,7 +18,6 @@
18
18
  "chat",
19
19
  "chatbot",
20
20
  "copilot",
21
- "assistant",
22
21
  "ai-chat",
23
22
  "ai-chatbot",
24
23
  "ai-assistant",
@@ -29,7 +28,7 @@
29
28
  "conversational-ui",
30
29
  "conversational-ai"
31
30
  ],
32
- "version": "0.8.20",
31
+ "version": "0.9.1",
33
32
  "license": "MIT",
34
33
  "exports": {
35
34
  ".": {
@@ -50,28 +49,23 @@
50
49
  "files": [
51
50
  "dist",
52
51
  "generated",
53
- "edge",
54
52
  "src",
55
53
  "README.md"
56
54
  ],
57
55
  "sideEffects": false,
58
56
  "dependencies": {
59
- "@ai-sdk/provider": "^1.1.0",
60
- "@radix-ui/primitive": "^1.1.1",
61
- "@radix-ui/react-compose-refs": "^1.1.1",
62
- "@radix-ui/react-context": "^1.1.1",
63
- "@radix-ui/react-popover": "^1.1.6",
64
- "@radix-ui/react-primitive": "^2.0.2",
65
- "@radix-ui/react-slot": "^1.1.2",
66
- "@radix-ui/react-use-callback-ref": "^1.1.0",
67
- "@radix-ui/react-use-escape-keydown": "^1.1.0",
68
- "assistant-stream": "^0.0.32",
69
- "json-schema": "^0.4.0",
57
+ "@radix-ui/primitive": "^1.1.2",
58
+ "@radix-ui/react-compose-refs": "^1.1.2",
59
+ "@radix-ui/react-context": "^1.1.2",
60
+ "@radix-ui/react-popover": "^1.1.7",
61
+ "@radix-ui/react-primitive": "^2.0.3",
62
+ "@radix-ui/react-slot": "^1.2.0",
63
+ "@radix-ui/react-use-callback-ref": "^1.1.1",
64
+ "@radix-ui/react-use-escape-keydown": "^1.1.1",
65
+ "assistant-stream": "^0.1.1",
70
66
  "nanoid": "5.1.5",
71
67
  "react-textarea-autosize": "^8.5.9",
72
- "secure-json-parse": "^4.0.0",
73
68
  "zod": "^3.24.2",
74
- "zod-to-json-schema": "^3.24.5",
75
69
  "zustand": "^5.0.3"
76
70
  },
77
71
  "peerDependencies": {
@@ -94,7 +88,7 @@
94
88
  "@types/json-schema": "^7.0.15",
95
89
  "@types/node": "^22.14.0",
96
90
  "eslint": "^9",
97
- "eslint-config-next": "15.2.4",
91
+ "eslint-config-next": "15.3.0",
98
92
  "tsx": "^4.19.3",
99
93
  "vitest": "^3.1.1",
100
94
  "@assistant-ui/tsbuildutils": "^0.0.1",
@@ -80,12 +80,14 @@ const toAppendMessage = (
80
80
  ): AppendMessage => {
81
81
  if (typeof message === "string") {
82
82
  return {
83
+ createdAt: new Date(),
83
84
  parentId: messages.at(-1)?.id ?? null,
84
85
  sourceId: null,
85
86
  runConfig: {},
86
87
  role: "user",
87
88
  content: [{ type: "text", text: message }],
88
89
  attachments: [],
90
+ metadata: { custom: {} },
89
91
  };
90
92
  }
91
93
 
@@ -1,11 +1,11 @@
1
- import { CoreMessage } from "../types";
1
+ import { ThreadMessage } from "../types";
2
2
  import { AssistantCloudAPI } from "./AssistantCloudAPI";
3
3
  import { AssistantStream, PlainTextDecoder } from "assistant-stream";
4
4
 
5
5
  type AssistantCloudRunsStreamBody = {
6
6
  thread_id: string;
7
7
  assistant_id: "system/thread_title";
8
- messages: CoreMessage[];
8
+ messages: readonly ThreadMessage[];
9
9
  };
10
10
 
11
11
  export class AssistantCloudRuns {
@@ -1,4 +1,3 @@
1
- import { JSONObject } from "@ai-sdk/provider";
2
1
  import { ThreadMessage } from "../types";
3
2
  import { MessageStatus } from "../types/AssistantTypes";
4
3
  import { fromThreadMessageLike } from "../runtimes/external-store/ThreadMessageLike";
@@ -56,7 +55,7 @@ type AuiV0Message = {
56
55
  readonly completionTokens: number;
57
56
  };
58
57
  }[];
59
- readonly custom: Readonly<JSONObject>;
58
+ readonly custom: ReadonlyJSONObject;
60
59
  };
61
60
  };
62
61
 
package/src/index.ts CHANGED
@@ -6,6 +6,4 @@ export * from "./primitives";
6
6
  export * from "./runtimes";
7
7
  export * from "./types";
8
8
 
9
- export { useToolArgsFieldStatus as unstable_useToolArgsFieldStatus } from "./utils/json/parse-partial-json";
10
-
11
9
  export * as INTERNAL from "./internal";
package/src/internal.ts CHANGED
@@ -13,6 +13,6 @@ export {
13
13
  } from "./api/ThreadRuntime";
14
14
  export { fromThreadMessageLike } from "./runtimes/external-store/ThreadMessageLike";
15
15
  export { getAutoStatus } from "./runtimes/external-store/auto-status";
16
- export { EdgeRuntimeRequestOptionsSchema } from "./runtimes/edge/EdgeRuntimeRequestOptions";
16
+ export { splitLocalRuntimeOptions } from "./runtimes/local/LocalRuntimeOptions";
17
17
 
18
18
  export * from "./utils/smooth";
@@ -2,7 +2,6 @@
2
2
 
3
3
  import { FC, useEffect, useState } from "react";
4
4
  import * as PopoverPrimitive from "@radix-ui/react-popover";
5
- import { composeEventHandlers } from "@radix-ui/primitive";
6
5
  import { ScopedProps, usePopoverScope } from "./scope";
7
6
  import { useThreadRuntime } from "../../context";
8
7
 
@@ -56,11 +55,16 @@ export const AssistantModalPrimitiveRoot: FC<
56
55
  unstable_openOnRunStart,
57
56
  });
58
57
 
58
+ const openChangeHandler = (open: boolean) => {
59
+ onOpenChange?.(open);
60
+ setOpen(open);
61
+ };
62
+
59
63
  return (
60
64
  <PopoverPrimitive.Root
61
65
  {...scope}
62
66
  open={open === undefined ? modalOpen : open}
63
- onOpenChange={composeEventHandlers(onOpenChange, setOpen)}
67
+ onOpenChange={openChangeHandler}
64
68
  {...rest}
65
69
  />
66
70
  );
@@ -134,10 +134,12 @@ export abstract class BaseComposerRuntimeCore
134
134
  : [];
135
135
 
136
136
  const message: Omit<AppendMessage, "parentId" | "sourceId"> = {
137
+ createdAt: new Date(),
137
138
  role: this.role,
138
139
  content: this.text ? [{ type: "text", text: this.text }] : [],
139
140
  attachments,
140
141
  runConfig: this.runConfig,
142
+ metadata: { custom: {} },
141
143
  };
142
144
  this._emptyTextAndAttachments();
143
145
 
@@ -1,3 +1,4 @@
1
+ import { parsePartialJson } from "assistant-stream/utils";
1
2
  import { generateId } from "../../internal";
2
3
  import {
3
4
  MessageStatus,
@@ -22,7 +23,6 @@ import {
22
23
  ReadonlyJSONObject,
23
24
  ReadonlyJSONValue,
24
25
  } from "../../utils/json/json-value";
25
- import { parsePartialJson } from "../../utils/json/parse-partial-json";
26
26
 
27
27
  export type ThreadMessageLike = {
28
28
  readonly role: "assistant" | "user" | "system";
@@ -1,9 +1,11 @@
1
1
  export * from "./adapters";
2
2
  export * from "./core";
3
- export * from "./dangerous-in-browser";
4
- export * from "./edge";
5
3
  export * from "./external-store";
6
4
  export * from "./local";
7
5
  export * from "./remote-thread-list";
8
6
 
7
+ export {
8
+ toolResultStream as unstable_toolResultStream,
9
+ unstable_runPendingTools,
10
+ } from "./streams/toolResultStream";
9
11
  export { ExportedMessageRepository } from "./utils/MessageRepository";
@@ -1,6 +1,5 @@
1
- import { generateId } from "../../internal";
1
+ import { fromThreadMessageLike, generateId } from "../../internal";
2
2
  import type { AppendMessage, ThreadAssistantMessage } from "../../types";
3
- import { fromCoreMessage } from "../edge";
4
3
  import type { ChatModelAdapter, ChatModelRunResult } from "./ChatModelAdapter";
5
4
  import { shouldContinue } from "./shouldContinue";
6
5
  import { LocalRuntimeOptionsBase } from "./LocalRuntimeOptions";
@@ -118,8 +117,9 @@ export class LocalThreadRuntimeCore
118
117
  public async append(message: AppendMessage): Promise<void> {
119
118
  this.ensureInitialized();
120
119
 
121
- const newMessage = fromCoreMessage(message, {
122
- attachments: message.attachments,
120
+ const newMessage = fromThreadMessageLike(message, generateId(), {
121
+ type: "complete",
122
+ reason: "unknown",
123
123
  });
124
124
  this.repository.addOrUpdateMessage(message.parentId, newMessage);
125
125
  this._options.adapters.history?.append({
@@ -10,7 +10,6 @@ import { AssistantCloud } from "../../../cloud";
10
10
  import { RemoteThreadListAdapter } from "../types";
11
11
  import { useAssistantCloudThreadHistoryAdapter } from "../../../cloud/AssistantCloudThreadHistoryAdapter";
12
12
  import { RuntimeAdapterProvider } from "../../adapters/RuntimeAdapterProvider";
13
- import { toCoreMessages } from "../../edge";
14
13
  import { InMemoryThreadListAdapter } from "./in-memory";
15
14
 
16
15
  type ThreadData = {
@@ -103,7 +102,7 @@ export const useCloudThreadListAdapter = (
103
102
  return cloud.runs.stream({
104
103
  thread_id: threadId,
105
104
  assistant_id: "system/thread_title",
106
- messages: toCoreMessages(messages),
105
+ messages: messages, // TODO serialize these to a more efficient format
107
106
  });
108
107
  },
109
108
 
@@ -1,4 +1,4 @@
1
- import { Tool } from "../../../model-context/ModelContextTypes";
1
+ import { Tool } from "../../model-context/ModelContextTypes";
2
2
  import { z } from "zod";
3
3
  import { AssistantMessage, ToolExecutionStream } from "assistant-stream";
4
4
  import { ToolResponse } from "assistant-stream";
@@ -1,6 +1,5 @@
1
- import type { CoreMessage, ThreadMessage } from "../../types/AssistantTypes";
1
+ import type { ThreadMessage } from "../../types";
2
2
  import { generateId, generateOptimisticId } from "../../utils/idUtils";
3
- import { fromCoreMessage } from "../edge/converters/fromCoreMessage";
4
3
  import { ThreadMessageLike } from "../external-store";
5
4
  import { getAutoStatus } from "../external-store/auto-status";
6
5
  import { fromThreadMessageLike } from "../external-store/ThreadMessageLike";
@@ -303,7 +302,7 @@ export class MessageRepository {
303
302
  * @param message - The core message to convert to an optimistic message
304
303
  * @returns The generated optimistic ID
305
304
  */
306
- appendOptimisticMessage(parentId: string | null, message: CoreMessage) {
305
+ appendOptimisticMessage(parentId: string | null, message: ThreadMessageLike) {
307
306
  let optimisticId: string;
308
307
  do {
309
308
  optimisticId = generateOptimisticId();
@@ -311,10 +310,7 @@ export class MessageRepository {
311
310
 
312
311
  this.addOrUpdateMessage(
313
312
  parentId,
314
- fromCoreMessage(message, {
315
- id: optimisticId,
316
- status: { type: "running" },
317
- }),
313
+ fromThreadMessageLike(message, optimisticId, { type: "running" }),
318
314
  );
319
315
 
320
316
  return optimisticId;