@langchain/core 1.0.0-alpha.5 → 1.0.0-alpha.7

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 (284) hide show
  1. package/LICENSE +6 -6
  2. package/dist/agents.d.ts.map +1 -1
  3. package/dist/caches/base.d.ts.map +1 -1
  4. package/dist/callbacks/base.d.ts.map +1 -1
  5. package/dist/callbacks/manager.cjs +9 -64
  6. package/dist/callbacks/manager.cjs.map +1 -1
  7. package/dist/callbacks/manager.d.cts +1 -23
  8. package/dist/callbacks/manager.d.cts.map +1 -1
  9. package/dist/callbacks/manager.d.ts +1 -23
  10. package/dist/callbacks/manager.d.ts.map +1 -1
  11. package/dist/callbacks/manager.js +10 -63
  12. package/dist/callbacks/manager.js.map +1 -1
  13. package/dist/chat_history.cjs +0 -4
  14. package/dist/chat_history.cjs.map +1 -1
  15. package/dist/chat_history.d.cts +1 -3
  16. package/dist/chat_history.d.cts.map +1 -1
  17. package/dist/chat_history.d.ts +1 -3
  18. package/dist/chat_history.d.ts.map +1 -1
  19. package/dist/chat_history.js +0 -4
  20. package/dist/chat_history.js.map +1 -1
  21. package/dist/document_loaders/base.cjs +1 -13
  22. package/dist/document_loaders/base.cjs.map +1 -1
  23. package/dist/document_loaders/base.d.cts +0 -9
  24. package/dist/document_loaders/base.d.cts.map +1 -1
  25. package/dist/document_loaders/base.d.ts +0 -9
  26. package/dist/document_loaders/base.d.ts.map +1 -1
  27. package/dist/document_loaders/base.js +1 -13
  28. package/dist/document_loaders/base.js.map +1 -1
  29. package/dist/document_loaders/langsmith.d.cts +1 -1
  30. package/dist/language_models/base.cjs.map +1 -1
  31. package/dist/language_models/base.d.cts +0 -16
  32. package/dist/language_models/base.d.cts.map +1 -1
  33. package/dist/language_models/base.d.ts +0 -16
  34. package/dist/language_models/base.d.ts.map +1 -1
  35. package/dist/language_models/base.js.map +1 -1
  36. package/dist/language_models/chat_models.cjs +1 -80
  37. package/dist/language_models/chat_models.cjs.map +1 -1
  38. package/dist/language_models/chat_models.d.cts +1 -53
  39. package/dist/language_models/chat_models.d.cts.map +1 -1
  40. package/dist/language_models/chat_models.d.ts +1 -53
  41. package/dist/language_models/chat_models.d.ts.map +1 -1
  42. package/dist/language_models/chat_models.js +2 -80
  43. package/dist/language_models/chat_models.js.map +1 -1
  44. package/dist/language_models/llms.cjs +0 -56
  45. package/dist/language_models/llms.cjs.map +1 -1
  46. package/dist/language_models/llms.d.cts +1 -43
  47. package/dist/language_models/llms.d.cts.map +1 -1
  48. package/dist/language_models/llms.d.ts +1 -43
  49. package/dist/language_models/llms.d.ts.map +1 -1
  50. package/dist/language_models/llms.js +0 -56
  51. package/dist/language_models/llms.js.map +1 -1
  52. package/dist/load/import_map.cjs +1 -7
  53. package/dist/load/import_map.cjs.map +1 -1
  54. package/dist/load/import_map.js +1 -7
  55. package/dist/load/import_map.js.map +1 -1
  56. package/dist/messages/ai.cjs +8 -4
  57. package/dist/messages/ai.cjs.map +1 -1
  58. package/dist/messages/ai.js +8 -4
  59. package/dist/messages/ai.js.map +1 -1
  60. package/dist/messages/base.cjs +1 -1
  61. package/dist/messages/base.cjs.map +1 -1
  62. package/dist/messages/base.d.cts +2 -2
  63. package/dist/messages/base.d.cts.map +1 -1
  64. package/dist/messages/base.d.ts +2 -2
  65. package/dist/messages/base.d.ts.map +1 -1
  66. package/dist/messages/base.js +1 -1
  67. package/dist/messages/base.js.map +1 -1
  68. package/dist/messages/block_translators/anthropic.cjs +191 -144
  69. package/dist/messages/block_translators/anthropic.cjs.map +1 -1
  70. package/dist/messages/block_translators/anthropic.js +191 -144
  71. package/dist/messages/block_translators/anthropic.js.map +1 -1
  72. package/dist/messages/block_translators/bedrock_converse.cjs +213 -0
  73. package/dist/messages/block_translators/bedrock_converse.cjs.map +1 -0
  74. package/dist/messages/block_translators/bedrock_converse.js +213 -0
  75. package/dist/messages/block_translators/bedrock_converse.js.map +1 -0
  76. package/dist/messages/block_translators/google_genai.cjs +73 -0
  77. package/dist/messages/block_translators/google_genai.cjs.map +1 -0
  78. package/dist/messages/block_translators/google_genai.js +73 -0
  79. package/dist/messages/block_translators/google_genai.js.map +1 -0
  80. package/dist/messages/block_translators/google_vertexai.cjs +74 -0
  81. package/dist/messages/block_translators/google_vertexai.cjs.map +1 -0
  82. package/dist/messages/block_translators/google_vertexai.js +74 -0
  83. package/dist/messages/block_translators/google_vertexai.js.map +1 -0
  84. package/dist/messages/block_translators/index.cjs +10 -1
  85. package/dist/messages/block_translators/index.cjs.map +1 -1
  86. package/dist/messages/block_translators/index.js +12 -3
  87. package/dist/messages/block_translators/index.js.map +1 -1
  88. package/dist/messages/block_translators/openai.cjs +78 -22
  89. package/dist/messages/block_translators/openai.cjs.map +1 -1
  90. package/dist/messages/block_translators/openai.js +78 -22
  91. package/dist/messages/block_translators/openai.js.map +1 -1
  92. package/dist/messages/block_translators/utils.cjs +4 -0
  93. package/dist/messages/block_translators/utils.cjs.map +1 -1
  94. package/dist/messages/block_translators/utils.js +4 -1
  95. package/dist/messages/block_translators/utils.js.map +1 -1
  96. package/dist/messages/content/index.cjs.map +1 -1
  97. package/dist/messages/content/index.d.cts +20 -1
  98. package/dist/messages/content/index.d.cts.map +1 -1
  99. package/dist/messages/content/index.d.ts +20 -1
  100. package/dist/messages/content/index.d.ts.map +1 -1
  101. package/dist/messages/content/index.js.map +1 -1
  102. package/dist/messages/content/tools.cjs +3 -4
  103. package/dist/messages/content/tools.cjs.map +1 -1
  104. package/dist/messages/content/tools.d.cts +22 -45
  105. package/dist/messages/content/tools.d.cts.map +1 -1
  106. package/dist/messages/content/tools.d.ts +22 -45
  107. package/dist/messages/content/tools.d.ts.map +1 -1
  108. package/dist/messages/content/tools.js +3 -4
  109. package/dist/messages/content/tools.js.map +1 -1
  110. package/dist/messages/index.cjs +4 -0
  111. package/dist/messages/index.cjs.map +1 -1
  112. package/dist/messages/index.d.cts +2 -2
  113. package/dist/messages/index.d.ts +2 -2
  114. package/dist/messages/index.js +4 -2
  115. package/dist/messages/index.js.map +1 -1
  116. package/dist/messages/message.cjs.map +1 -1
  117. package/dist/messages/message.d.cts +6 -6
  118. package/dist/messages/message.d.cts.map +1 -1
  119. package/dist/messages/message.d.ts +6 -6
  120. package/dist/messages/message.d.ts.map +1 -1
  121. package/dist/messages/message.js.map +1 -1
  122. package/dist/messages/metadata.cjs.map +1 -1
  123. package/dist/messages/metadata.d.cts +3 -0
  124. package/dist/messages/metadata.d.cts.map +1 -1
  125. package/dist/messages/metadata.d.ts +3 -0
  126. package/dist/messages/metadata.d.ts.map +1 -1
  127. package/dist/messages/metadata.js.map +1 -1
  128. package/dist/messages/tool.cjs +2 -0
  129. package/dist/messages/tool.cjs.map +1 -1
  130. package/dist/messages/tool.d.cts +5 -1
  131. package/dist/messages/tool.d.cts.map +1 -1
  132. package/dist/messages/tool.d.ts +5 -1
  133. package/dist/messages/tool.d.ts.map +1 -1
  134. package/dist/messages/tool.js +2 -0
  135. package/dist/messages/tool.js.map +1 -1
  136. package/dist/output_parsers/json.cjs +5 -0
  137. package/dist/output_parsers/json.cjs.map +1 -1
  138. package/dist/output_parsers/json.d.cts +2 -0
  139. package/dist/output_parsers/json.d.cts.map +1 -1
  140. package/dist/output_parsers/json.d.ts +2 -0
  141. package/dist/output_parsers/json.d.ts.map +1 -1
  142. package/dist/output_parsers/json.js +5 -0
  143. package/dist/output_parsers/json.js.map +1 -1
  144. package/dist/prompts/base.cjs +0 -36
  145. package/dist/prompts/base.cjs.map +1 -1
  146. package/dist/prompts/base.d.cts +0 -16
  147. package/dist/prompts/base.d.cts.map +1 -1
  148. package/dist/prompts/base.d.ts +0 -16
  149. package/dist/prompts/base.d.ts.map +1 -1
  150. package/dist/prompts/base.js +0 -36
  151. package/dist/prompts/base.js.map +1 -1
  152. package/dist/prompts/chat.cjs +1 -5
  153. package/dist/prompts/chat.cjs.map +1 -1
  154. package/dist/prompts/chat.d.cts +1 -4
  155. package/dist/prompts/chat.d.cts.map +1 -1
  156. package/dist/prompts/chat.d.ts +1 -4
  157. package/dist/prompts/chat.d.ts.map +1 -1
  158. package/dist/prompts/chat.js +1 -5
  159. package/dist/prompts/chat.js.map +1 -1
  160. package/dist/prompts/dict.d.cts +1 -1
  161. package/dist/prompts/dict.d.ts +1 -1
  162. package/dist/prompts/few_shot.d.cts +2 -2
  163. package/dist/prompts/few_shot.d.ts +2 -2
  164. package/dist/prompts/image.d.cts +1 -1
  165. package/dist/prompts/image.d.ts +1 -1
  166. package/dist/prompts/index.d.cts +2 -2
  167. package/dist/prompts/index.d.ts +2 -2
  168. package/dist/prompts/pipeline.d.cts +1 -1
  169. package/dist/prompts/pipeline.d.ts +1 -1
  170. package/dist/prompts/prompt.d.cts +2 -2
  171. package/dist/prompts/prompt.d.ts +2 -2
  172. package/dist/retrievers/index.cjs +3 -18
  173. package/dist/retrievers/index.cjs.map +1 -1
  174. package/dist/retrievers/index.d.cts +2 -27
  175. package/dist/retrievers/index.d.cts.map +1 -1
  176. package/dist/retrievers/index.d.ts +2 -27
  177. package/dist/retrievers/index.d.ts.map +1 -1
  178. package/dist/retrievers/index.js +3 -18
  179. package/dist/retrievers/index.js.map +1 -1
  180. package/dist/runnables/base.cjs +24 -63
  181. package/dist/runnables/base.cjs.map +1 -1
  182. package/dist/runnables/base.d.cts +10 -39
  183. package/dist/runnables/base.d.cts.map +1 -1
  184. package/dist/runnables/base.d.ts +10 -39
  185. package/dist/runnables/base.d.ts.map +1 -1
  186. package/dist/runnables/base.js +24 -63
  187. package/dist/runnables/base.js.map +1 -1
  188. package/dist/runnables/graph.cjs +1 -1
  189. package/dist/runnables/graph.cjs.map +1 -1
  190. package/dist/runnables/graph.js +2 -2
  191. package/dist/runnables/graph.js.map +1 -1
  192. package/dist/runnables/graph_mermaid.cjs +1 -10
  193. package/dist/runnables/graph_mermaid.cjs.map +1 -1
  194. package/dist/runnables/graph_mermaid.js +1 -10
  195. package/dist/runnables/graph_mermaid.js.map +1 -1
  196. package/dist/runnables/history.cjs +1 -1
  197. package/dist/runnables/history.cjs.map +1 -1
  198. package/dist/runnables/history.d.cts +2 -2
  199. package/dist/runnables/history.d.cts.map +1 -1
  200. package/dist/runnables/history.d.ts +2 -2
  201. package/dist/runnables/history.d.ts.map +1 -1
  202. package/dist/runnables/history.js +1 -1
  203. package/dist/runnables/history.js.map +1 -1
  204. package/dist/stores.cjs.map +1 -1
  205. package/dist/stores.d.cts +3 -29
  206. package/dist/stores.d.cts.map +1 -1
  207. package/dist/stores.d.ts +3 -29
  208. package/dist/stores.d.ts.map +1 -1
  209. package/dist/stores.js.map +1 -1
  210. package/dist/tools/index.cjs +12 -4
  211. package/dist/tools/index.cjs.map +1 -1
  212. package/dist/tools/index.js +12 -4
  213. package/dist/tools/index.js.map +1 -1
  214. package/dist/tools/types.cjs.map +1 -1
  215. package/dist/tools/types.d.cts +4 -0
  216. package/dist/tools/types.d.cts.map +1 -1
  217. package/dist/tools/types.d.ts +4 -0
  218. package/dist/tools/types.d.ts.map +1 -1
  219. package/dist/tools/types.js.map +1 -1
  220. package/dist/tracers/base.cjs +1 -1
  221. package/dist/tracers/base.cjs.map +1 -1
  222. package/dist/tracers/base.d.cts +1 -1
  223. package/dist/tracers/base.js +2 -2
  224. package/dist/tracers/base.js.map +1 -1
  225. package/dist/tracers/log_stream.d.cts +1 -1
  226. package/dist/tracers/log_stream.d.ts +1 -1
  227. package/dist/tracers/tracer_langchain.cjs +1 -0
  228. package/dist/tracers/tracer_langchain.cjs.map +1 -1
  229. package/dist/tracers/tracer_langchain.d.cts +2 -2
  230. package/dist/tracers/tracer_langchain.js +1 -0
  231. package/dist/tracers/tracer_langchain.js.map +1 -1
  232. package/dist/utils/env.cjs +1 -9
  233. package/dist/utils/env.cjs.map +1 -1
  234. package/dist/utils/env.d.cts +2 -6
  235. package/dist/utils/env.d.cts.map +1 -1
  236. package/dist/utils/env.d.ts +2 -6
  237. package/dist/utils/env.d.ts.map +1 -1
  238. package/dist/utils/env.js +2 -9
  239. package/dist/utils/env.js.map +1 -1
  240. package/dist/utils/testing/message_history.cjs +1 -1
  241. package/dist/utils/testing/message_history.cjs.map +1 -1
  242. package/dist/utils/testing/message_history.d.cts +1 -1
  243. package/dist/utils/testing/message_history.d.cts.map +1 -1
  244. package/dist/utils/testing/message_history.d.ts +1 -1
  245. package/dist/utils/testing/message_history.d.ts.map +1 -1
  246. package/dist/utils/testing/message_history.js +1 -1
  247. package/dist/utils/testing/message_history.js.map +1 -1
  248. package/dist/utils/types/index.cjs +8 -0
  249. package/dist/utils/types/index.d.cts +2 -2
  250. package/dist/utils/types/index.d.ts +2 -2
  251. package/dist/utils/types/index.js +6 -2
  252. package/dist/utils/types/zod.cjs +62 -3
  253. package/dist/utils/types/zod.cjs.map +1 -1
  254. package/dist/utils/types/zod.d.cts +28 -1
  255. package/dist/utils/types/zod.d.cts.map +1 -1
  256. package/dist/utils/types/zod.d.ts +28 -1
  257. package/dist/utils/types/zod.d.ts.map +1 -1
  258. package/dist/utils/types/zod.js +59 -4
  259. package/dist/utils/types/zod.js.map +1 -1
  260. package/package.json +1 -37
  261. package/dist/runnables/remote.cjs +0 -399
  262. package/dist/runnables/remote.cjs.map +0 -1
  263. package/dist/runnables/remote.d.cts +0 -73
  264. package/dist/runnables/remote.d.cts.map +0 -1
  265. package/dist/runnables/remote.d.ts +0 -73
  266. package/dist/runnables/remote.d.ts.map +0 -1
  267. package/dist/runnables/remote.js +0 -393
  268. package/dist/runnables/remote.js.map +0 -1
  269. package/dist/tracers/initialize.cjs +0 -46
  270. package/dist/tracers/initialize.cjs.map +0 -1
  271. package/dist/tracers/initialize.d.cts +0 -26
  272. package/dist/tracers/initialize.d.cts.map +0 -1
  273. package/dist/tracers/initialize.d.ts +0 -26
  274. package/dist/tracers/initialize.d.ts.map +0 -1
  275. package/dist/tracers/initialize.js +0 -39
  276. package/dist/tracers/initialize.js.map +0 -1
  277. package/dist/tracers/tracer_langchain_v1.cjs +0 -168
  278. package/dist/tracers/tracer_langchain_v1.cjs.map +0 -1
  279. package/dist/tracers/tracer_langchain_v1.d.cts +0 -64
  280. package/dist/tracers/tracer_langchain_v1.d.cts.map +0 -1
  281. package/dist/tracers/tracer_langchain_v1.d.ts +0 -64
  282. package/dist/tracers/tracer_langchain_v1.d.ts.map +0 -1
  283. package/dist/tracers/tracer_langchain_v1.js +0 -162
  284. package/dist/tracers/tracer_langchain_v1.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","names":["BaseContentBlock","Tools","KNOWN_BLOCK_TYPES","TName","TArgs","CodeInterpreterOutput","ToolCall","ToolCallChunk","InvalidToolCall","WebSearchCall","WebSearchResult","CodeInterpreterCall","CodeInterpreterResult"],"sources":["../../../src/messages/content/tools.d.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\nexport type Tools = never;\nexport declare const KNOWN_BLOCK_TYPES: string[];\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n interface ToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n /** Content block to represent partial data of a tool call */\n interface ToolCallChunk<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n /** Content block to represent an invalid tool call */\n interface InvalidToolCall<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n /** Content block for a built-in web search tool call. */\n interface WebSearchCall extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"web_search_call\";\n /**\n * The search query used in the web search tool call\n */\n query?: string;\n }\n /** Content block for the result of a built-in search tool call */\n interface WebSearchResult extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"web_search_result\";\n /**\n * List of URLs returned by the web search tool call\n */\n urls?: string[];\n }\n /** Content block for a built-in code interpreter tool call. */\n interface CodeInterpreterCall extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"code_interpreter_call\";\n /**\n * The language of the code executed by the code interpreter tool call\n */\n language?: string;\n /**\n * The code to be executed by the code interpreter\n */\n code?: string;\n }\n /** Content block for the output of a singular code interpreter tool call */\n interface CodeInterpreterOutput {\n readonly type: \"code_interpreter_output\";\n /**\n * The return code of the code interpreter tool call\n * Example: 0 for success, non-zero for failure\n */\n returnCode?: number;\n /**\n * Standard error output of the executed code\n */\n stderr?: string;\n /**\n * Standard output of the executed code\n */\n stdout?: string;\n /**\n * File IDs of the files created by the code interpreter tool call\n */\n fileIds?: string[];\n }\n /** Content block for the result of a code interpreter tool call */\n interface CodeInterpreterResult extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"code_interpreter_result\";\n /**\n * The result of the code interpreter tool call\n */\n output: CodeInterpreterOutput[];\n }\n type Standard = ToolCall | ToolCallChunk | InvalidToolCall | WebSearchCall | WebSearchResult | CodeInterpreterCall | CodeInterpreterResult;\n}\n"],"mappings":";;;KACYC,KAAAA;AAAZ;AAGyBA,kBAAAA,KAAAA,CAAK;EAAA;;;;;;;;;;;;;;;EA6Ic,UAAGO,QAAAA,CAAAA,cAAAA,MAAAA,GAAAA,MAAAA,EAAAA,QAAAA,OAAAA,CAAAA,SA7HgCR,gBA6HhCQ,CAAAA;IAAkBC;;;IAAwDG,SAAAA,IAAAA,EAAAA,WAAAA;IAAqB;;;UArHhIT;;;;UAIAC;;;iEAGqDJ;;;;;;;;WAQpDG;;;;;;;;;;;mEAWsDH;;;;;;;;WAQtDG;;;;;;;;;;;;;;;kCAeqBH;;;;;;;;;;;oCAWEA;;;;;;;;;;;wCAWIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0CAoCEA;;;;;;;;YAQ5BK;;kBAEIC,WAAWC,gBAAgBC,kBAAkBC,gBAAgBC,kBAAkBC,sBAAsBC"}
1
+ {"version":3,"file":"tools.d.ts","names":["BaseContentBlock","Tools","KNOWN_BLOCK_TYPES","TName","TArgs","Record","TOutput","ToolCall","ToolCallChunk","InvalidToolCall","ServerToolCall","ServerToolCallChunk","ServerToolCallResult"],"sources":["../../../src/messages/content/tools.d.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\nexport type Tools = never;\nexport declare const KNOWN_BLOCK_TYPES: string[];\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n interface ToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n /** Content block to represent partial data of a tool call */\n interface ToolCallChunk<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n /** Content block to represent an invalid tool call */\n interface InvalidToolCall<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n interface ServerToolCall<TName extends string = string, TArgs = unknown> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n interface ServerToolCallChunk<TName extends string = string> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n }\n interface ServerToolCallResult<TOutput = Record<string, unknown>> extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_result\";\n /**\n * The unique identifier of the tool call that this result corresponds to\n */\n toolCallId: string;\n /**\n * The status of the server tool call\n */\n status: \"success\" | \"error\";\n /**\n * The output of the server tool call\n */\n output: TOutput;\n }\n type Standard = ToolCall | ToolCallChunk | InvalidToolCall | ServerToolCall | ServerToolCallChunk | ServerToolCallResult;\n}\n"],"mappings":";;;KACYC,KAAAA;AAAZ;AAGyBA,kBAAAA,KAAAA,CAAK;EAAA;;;;;;;;;;;;;;;EAoHP,UAhBuDD,QAAAA,CAAAA,cAAAA,MAAAA,GAAAA,MAAAA,EAAAA,QAAAA,OAAAA,CAAAA,SApFCA,gBAoFDA,CAAAA;IAkB1DO;;;IAA6CG,SAAAA,IAAAA,EAAAA,WAAAA;IAAiBC;;AAA0C;UA9F9GR;;;;UAIAC;;;iEAGqDJ;;;;;;;;WAQpDG;;;;;;;;;;;mEAWsDH;;;;;;;;WAQtDG;;;;;;;;;;;;;;mFAcsEH;;;;;;;;UAQvEG;;;;UAIAC;;uEAE2DJ;;;;;;;;WAQ1DG;;;;;;2CAM8BE,iCAAiCL;;;;;;;;;;;;;;;;YAgB9DM;;kBAEIC,WAAWC,gBAAgBC,kBAAkBC,iBAAiBC,sBAAsBC"}
@@ -3,10 +3,9 @@ const KNOWN_BLOCK_TYPES = [
3
3
  "tool_call",
4
4
  "tool_call_chunk",
5
5
  "invalid_tool_call",
6
- "web_search_call",
7
- "web_search_result",
8
- "code_interpreter",
9
- "code_interpreter_result"
6
+ "server_tool_call",
7
+ "server_tool_call_chunk",
8
+ "server_tool_call_result"
10
9
  ];
11
10
 
12
11
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","names":[],"sources":["../../../src/messages/content/tools.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\n\nexport type Tools = never;\n\nexport const KNOWN_BLOCK_TYPES = [\n \"tool_call\",\n \"tool_call_chunk\",\n \"invalid_tool_call\",\n \"web_search_call\",\n \"web_search_result\",\n \"code_interpreter\",\n \"code_interpreter_result\",\n];\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n export interface ToolCall<TName extends string = string, TArgs = unknown>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n\n /** Content block to represent partial data of a tool call */\n export interface ToolCallChunk<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n\n /** Content block to represent an invalid tool call */\n export interface InvalidToolCall<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n\n /** Content block for a built-in web search tool call. */\n export interface WebSearchCall extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"web_search_call\";\n /**\n * The search query used in the web search tool call\n */\n query?: string;\n }\n\n /** Content block for the result of a built-in search tool call */\n export interface WebSearchResult extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"web_search_result\";\n /**\n * List of URLs returned by the web search tool call\n */\n urls?: string[];\n }\n\n /** Content block for a built-in code interpreter tool call. */\n export interface CodeInterpreterCall extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"code_interpreter_call\";\n /**\n * The language of the code executed by the code interpreter tool call\n */\n language?: string;\n /**\n * The code to be executed by the code interpreter\n */\n code?: string;\n }\n\n /** Content block for the output of a singular code interpreter tool call */\n export interface CodeInterpreterOutput {\n readonly type: \"code_interpreter_output\";\n /**\n * The return code of the code interpreter tool call\n * Example: 0 for success, non-zero for failure\n */\n returnCode?: number;\n /**\n * Standard error output of the executed code\n */\n stderr?: string;\n /**\n * Standard output of the executed code\n */\n stdout?: string;\n /**\n * File IDs of the files created by the code interpreter tool call\n */\n fileIds?: string[];\n }\n\n /** Content block for the result of a code interpreter tool call */\n export interface CodeInterpreterResult extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"code_interpreter_result\";\n /**\n * The result of the code interpreter tool call\n */\n output: CodeInterpreterOutput[];\n }\n\n export type Standard =\n | ToolCall\n | ToolCallChunk\n | InvalidToolCall\n | WebSearchCall\n | WebSearchResult\n | CodeInterpreterCall\n | CodeInterpreterResult;\n}\n"],"mappings":";AAIA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;AACD"}
1
+ {"version":3,"file":"tools.js","names":[],"sources":["../../../src/messages/content/tools.ts"],"sourcesContent":["import { BaseContentBlock } from \"./base.js\";\n\nexport type Tools = never;\n\nexport const KNOWN_BLOCK_TYPES = [\n \"tool_call\",\n \"tool_call_chunk\",\n \"invalid_tool_call\",\n \"server_tool_call\",\n \"server_tool_call_chunk\",\n \"server_tool_call_result\",\n];\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport declare namespace Tools {\n /**\n * Represents a request to call a tool.\n *\n * @example\n * ```ts\n * const toolCall: ToolCall = {\n * type: \"tool_call\",\n * name: \"foo\",\n * args: { a: 1 },\n * callId: \"123\"\n * };\n * ```\n * This represents a request to call the tool named \"foo\" with arguments {\"a\": 1}\n * and an identifier of \"123\".\n */\n export interface ToolCall<TName extends string = string, TArgs = unknown>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n\n /** Content block to represent partial data of a tool call */\n export interface ToolCallChunk<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * The index of the tool call chunk\n */\n index?: number;\n }\n\n /** Content block to represent an invalid tool call */\n export interface InvalidToolCall<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"invalid_tool_call\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n /**\n * An error message associated with the tool call\n */\n error?: string;\n /**\n * Index of block in aggregate response\n */\n index?: string | number;\n }\n\n export interface ServerToolCall<\n TName extends string = string,\n TArgs = unknown\n > extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call\";\n /**\n * The name of the tool being called\n */\n name: TName;\n /**\n * The arguments to the tool call\n */\n args: TArgs;\n }\n\n export interface ServerToolCallChunk<TName extends string = string>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_chunk\";\n /**\n * The name of the tool being called\n */\n name?: TName;\n /**\n * The arguments to the tool call\n */\n args?: string;\n }\n\n export interface ServerToolCallResult<TOutput = Record<string, unknown>>\n extends BaseContentBlock {\n /**\n * Type of the content block\n */\n readonly type: \"server_tool_call_result\";\n /**\n * The unique identifier of the tool call that this result corresponds to\n */\n toolCallId: string;\n /**\n * The status of the server tool call\n */\n status: \"success\" | \"error\";\n /**\n * The output of the server tool call\n */\n output: TOutput;\n }\n\n export type Standard =\n | ToolCall\n | ToolCallChunk\n | InvalidToolCall\n | ServerToolCall\n | ServerToolCallChunk\n | ServerToolCallResult;\n}\n"],"mappings":";AAIA,MAAa,oBAAoB;CAC/B;CACA;CACA;CACA;CACA;CACA;AACD"}
@@ -43,6 +43,7 @@ require_rolldown_runtime.__export(messages_exports, {
43
43
  convertToOpenAIImageBlock: () => require_data.convertToOpenAIImageBlock,
44
44
  convertToProviderContentBlock: () => require_data.convertToProviderContentBlock,
45
45
  defaultTextSplitter: () => require_transformers.defaultTextSplitter,
46
+ defaultToolCallParser: () => require_messages_tool.defaultToolCallParser,
46
47
  filterMessages: () => require_transformers.filterMessages,
47
48
  getBufferString: () => require_utils.getBufferString,
48
49
  iife: () => require_utils.iife,
@@ -54,6 +55,7 @@ require_rolldown_runtime.__export(messages_exports, {
54
55
  isChatMessage: () => require_chat.isChatMessage,
55
56
  isChatMessageChunk: () => require_chat.isChatMessageChunk,
56
57
  isDataContentBlock: () => require_data.isDataContentBlock,
58
+ isDirectToolOutput: () => require_messages_tool.isDirectToolOutput,
57
59
  isFunctionMessage: () => require_function.isFunctionMessage,
58
60
  isFunctionMessageChunk: () => require_function.isFunctionMessageChunk,
59
61
  isHumanMessage: () => require_human.isHumanMessage,
@@ -106,6 +108,7 @@ exports.convertToChunk = require_utils.convertToChunk;
106
108
  exports.convertToOpenAIImageBlock = require_data.convertToOpenAIImageBlock;
107
109
  exports.convertToProviderContentBlock = require_data.convertToProviderContentBlock;
108
110
  exports.defaultTextSplitter = require_transformers.defaultTextSplitter;
111
+ exports.defaultToolCallParser = require_messages_tool.defaultToolCallParser;
109
112
  exports.filterMessages = require_transformers.filterMessages;
110
113
  exports.getBufferString = require_utils.getBufferString;
111
114
  exports.iife = require_utils.iife;
@@ -117,6 +120,7 @@ exports.isBaseMessageChunk = require_base.isBaseMessageChunk;
117
120
  exports.isChatMessage = require_chat.isChatMessage;
118
121
  exports.isChatMessageChunk = require_chat.isChatMessageChunk;
119
122
  exports.isDataContentBlock = require_data.isDataContentBlock;
123
+ exports.isDirectToolOutput = require_messages_tool.isDirectToolOutput;
120
124
  exports.isFunctionMessage = require_function.isFunctionMessage;
121
125
  exports.isFunctionMessageChunk = require_function.isFunctionMessageChunk;
122
126
  exports.isHumanMessage = require_human.isHumanMessage;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/messages/index.ts"],"sourcesContent":["export * from \"./ai.js\";\nexport * from \"./base.js\";\nexport * from \"./chat.js\";\nexport * from \"./function.js\";\nexport * from \"./human.js\";\nexport * from \"./system.js\";\nexport * from \"./utils.js\";\nexport * from \"./transformers.js\";\nexport * from \"./metadata.js\";\nexport * from \"./message.js\";\nexport * from \"./modifier.js\";\n// TODO: Use a star export when we deprecate the\n// existing \"ToolCall\" type in \"base.js\".\nexport {\n type ToolMessageFields,\n ToolMessage,\n ToolMessageChunk,\n type InvalidToolCall,\n isToolMessage,\n isToolMessageChunk,\n} from \"./tool.js\";\n\n// This is an old export for backwards compatibility with existing multimodal content blocks\n// TODO: remove this in v2\nexport * from \"./content/data.js\";\nexport * from \"./content/index.js\";\n"],"mappings":""}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/messages/index.ts"],"sourcesContent":["export * from \"./ai.js\";\nexport * from \"./base.js\";\nexport * from \"./chat.js\";\nexport * from \"./function.js\";\nexport * from \"./human.js\";\nexport * from \"./system.js\";\nexport * from \"./utils.js\";\nexport * from \"./transformers.js\";\nexport * from \"./metadata.js\";\nexport * from \"./message.js\";\nexport * from \"./modifier.js\";\nexport * from \"./tool.js\";\n\n// This is an old export for backwards compatibility with existing multimodal content blocks\n// TODO: remove this in v2\nexport * from \"./content/data.js\";\nexport * from \"./content/index.js\";\n"],"mappings":""}
@@ -2,7 +2,7 @@ import { Data, ImageDetail, MessageContentComplex, MessageContentImageUrl, Messa
2
2
  import { ContentBlock, KNOWN_BLOCK_TYPES } from "./content/index.cjs";
3
3
  import { InputTokenDetails, ModalitiesTokenDetails, OutputTokenDetails, ResponseMetadata, UsageMetadata, mergeResponseMetadata, mergeUsageMetadata } from "./metadata.cjs";
4
4
  import { BaseMessage, BaseMessageChunk, BaseMessageFields, BaseMessageLike, FunctionCall, MessageContent, MessageFieldWithRole, OpenAIToolCall, StoredGeneration, StoredMessage, StoredMessageData, StoredMessageV1, _isMessageFieldWithRole, _mergeDicts, _mergeLists, _mergeObj, _mergeStatus, isBaseMessage, isBaseMessageChunk, isOpenAIToolCallArray, mergeContent } from "./base.cjs";
5
- import { InvalidToolCall, ToolMessage, ToolMessageChunk, ToolMessageFields, isToolMessage, isToolMessageChunk } from "./tool.cjs";
5
+ import { DirectToolOutput, InvalidToolCall, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields, defaultToolCallParser, isDirectToolOutput, isToolMessage, isToolMessageChunk } from "./tool.cjs";
6
6
  import { AIMessage, AIMessageChunk, AIMessageChunkFields, AIMessageFields, isAIMessage, isAIMessageChunk } from "./ai.cjs";
7
7
  import { ChatMessage, ChatMessageChunk, ChatMessageFields, isChatMessage, isChatMessageChunk } from "./chat.cjs";
8
8
  import { FunctionMessage, FunctionMessageChunk, FunctionMessageFields, isFunctionMessage, isFunctionMessageChunk } from "./function.cjs";
@@ -12,4 +12,4 @@ import { $Expand, $MergeDiscriminatedUnion, $MergeObjects, Constructor, coerceMe
12
12
  import { $InferMessageContent, $InferMessageContentBlocks, $InferMessageProperties, $InferMessageProperty, $InferResponseMetadata, $MergeContentDefinition, $MergeMessageStructure, $MergeOutputVersion, $MessageToolCallBlock, $NormalizedMessageStructure, Message, MessageOutputVersion, MessageStructure, MessageToolDefinition, MessageToolSet, MessageType, StandardMessageStructure, isMessage } from "./message.cjs";
13
13
  import { RemoveMessage, RemoveMessageFields } from "./modifier.cjs";
14
14
  import { FilterMessagesFields, MessageChunkUnion, MessageTypeOrClass, MessageUnion, TrimMessagesFields, defaultTextSplitter, filterMessages, mergeMessageRuns, trimMessages } from "./transformers.cjs";
15
- export { $Expand, $InferMessageContent, $InferMessageContentBlocks, $InferMessageProperties, $InferMessageProperty, $InferResponseMetadata, $MergeContentDefinition, $MergeDiscriminatedUnion, $MergeMessageStructure, $MergeObjects, $MergeOutputVersion, $MessageToolCallBlock, $NormalizedMessageStructure, AIMessage, AIMessageChunk, AIMessageChunkFields, AIMessageFields, BaseMessage, BaseMessageChunk, BaseMessageFields, BaseMessageLike, ChatMessage, ChatMessageChunk, ChatMessageFields, Constructor, ContentBlock, Data, FilterMessagesFields, FunctionCall, FunctionMessage, FunctionMessageChunk, FunctionMessageFields, HumanMessage, HumanMessageChunk, HumanMessageFields, ImageDetail, InputTokenDetails, type InvalidToolCall, KNOWN_BLOCK_TYPES, Message, MessageChunkUnion, MessageContent, MessageContentComplex, MessageContentImageUrl, MessageContentText, MessageFieldWithRole, MessageOutputVersion, MessageStructure, MessageToolDefinition, MessageToolSet, MessageType, MessageTypeOrClass, MessageUnion, ModalitiesTokenDetails, OpenAIToolCall, OutputTokenDetails, ProviderFormatTypes, RemoveMessage, RemoveMessageFields, ResponseMetadata, StandardContentBlockConverter, StandardMessageStructure, StoredGeneration, StoredMessage, StoredMessageData, StoredMessageV1, SystemMessage, SystemMessageChunk, SystemMessageFields, ToolMessage, ToolMessageChunk, type ToolMessageFields, TrimMessagesFields, UsageMetadata, _isMessageFieldWithRole, _mergeDicts, _mergeLists, _mergeObj, _mergeStatus, coerceMessageLikeToMessage, convertToChunk, convertToOpenAIImageBlock, convertToProviderContentBlock, defaultTextSplitter, filterMessages, getBufferString, iife, isAIMessage, isAIMessageChunk, isBase64ContentBlock, isBaseMessage, isBaseMessageChunk, isChatMessage, isChatMessageChunk, isDataContentBlock, isFunctionMessage, isFunctionMessageChunk, isHumanMessage, isHumanMessageChunk, isIDContentBlock, isMessage, isOpenAIToolCallArray, isPlainTextContentBlock, isSystemMessage, isSystemMessageChunk, isToolMessage, isToolMessageChunk, isURLContentBlock, mapChatMessagesToStoredMessages, mapStoredMessageToChatMessage, mapStoredMessagesToChatMessages, mergeContent, mergeMessageRuns, mergeResponseMetadata, mergeUsageMetadata, parseBase64DataUrl, parseMimeType, trimMessages };
15
+ export { $Expand, $InferMessageContent, $InferMessageContentBlocks, $InferMessageProperties, $InferMessageProperty, $InferResponseMetadata, $MergeContentDefinition, $MergeDiscriminatedUnion, $MergeMessageStructure, $MergeObjects, $MergeOutputVersion, $MessageToolCallBlock, $NormalizedMessageStructure, AIMessage, AIMessageChunk, AIMessageChunkFields, AIMessageFields, BaseMessage, BaseMessageChunk, BaseMessageFields, BaseMessageLike, ChatMessage, ChatMessageChunk, ChatMessageFields, Constructor, ContentBlock, Data, DirectToolOutput, FilterMessagesFields, FunctionCall, FunctionMessage, FunctionMessageChunk, FunctionMessageFields, HumanMessage, HumanMessageChunk, HumanMessageFields, ImageDetail, InputTokenDetails, InvalidToolCall, KNOWN_BLOCK_TYPES, Message, MessageChunkUnion, MessageContent, MessageContentComplex, MessageContentImageUrl, MessageContentText, MessageFieldWithRole, MessageOutputVersion, MessageStructure, MessageToolDefinition, MessageToolSet, MessageType, MessageTypeOrClass, MessageUnion, ModalitiesTokenDetails, OpenAIToolCall, OutputTokenDetails, ProviderFormatTypes, RemoveMessage, RemoveMessageFields, ResponseMetadata, StandardContentBlockConverter, StandardMessageStructure, StoredGeneration, StoredMessage, StoredMessageData, StoredMessageV1, SystemMessage, SystemMessageChunk, SystemMessageFields, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields, TrimMessagesFields, UsageMetadata, _isMessageFieldWithRole, _mergeDicts, _mergeLists, _mergeObj, _mergeStatus, coerceMessageLikeToMessage, convertToChunk, convertToOpenAIImageBlock, convertToProviderContentBlock, defaultTextSplitter, defaultToolCallParser, filterMessages, getBufferString, iife, isAIMessage, isAIMessageChunk, isBase64ContentBlock, isBaseMessage, isBaseMessageChunk, isChatMessage, isChatMessageChunk, isDataContentBlock, isDirectToolOutput, isFunctionMessage, isFunctionMessageChunk, isHumanMessage, isHumanMessageChunk, isIDContentBlock, isMessage, isOpenAIToolCallArray, isPlainTextContentBlock, isSystemMessage, isSystemMessageChunk, isToolMessage, isToolMessageChunk, isURLContentBlock, mapChatMessagesToStoredMessages, mapStoredMessageToChatMessage, mapStoredMessagesToChatMessages, mergeContent, mergeMessageRuns, mergeResponseMetadata, mergeUsageMetadata, parseBase64DataUrl, parseMimeType, trimMessages };
@@ -2,7 +2,7 @@ import { Data, ImageDetail, MessageContentComplex, MessageContentImageUrl, Messa
2
2
  import { ContentBlock, KNOWN_BLOCK_TYPES } from "./content/index.js";
3
3
  import { InputTokenDetails, ModalitiesTokenDetails, OutputTokenDetails, ResponseMetadata, UsageMetadata, mergeResponseMetadata, mergeUsageMetadata } from "./metadata.js";
4
4
  import { BaseMessage, BaseMessageChunk, BaseMessageFields, BaseMessageLike, FunctionCall, MessageContent, MessageFieldWithRole, OpenAIToolCall, StoredGeneration, StoredMessage, StoredMessageData, StoredMessageV1, _isMessageFieldWithRole, _mergeDicts, _mergeLists, _mergeObj, _mergeStatus, isBaseMessage, isBaseMessageChunk, isOpenAIToolCallArray, mergeContent } from "./base.js";
5
- import { InvalidToolCall, ToolMessage, ToolMessageChunk, ToolMessageFields, isToolMessage, isToolMessageChunk } from "./tool.js";
5
+ import { DirectToolOutput, InvalidToolCall, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields, defaultToolCallParser, isDirectToolOutput, isToolMessage, isToolMessageChunk } from "./tool.js";
6
6
  import { AIMessage, AIMessageChunk, AIMessageChunkFields, AIMessageFields, isAIMessage, isAIMessageChunk } from "./ai.js";
7
7
  import { ChatMessage, ChatMessageChunk, ChatMessageFields, isChatMessage, isChatMessageChunk } from "./chat.js";
8
8
  import { FunctionMessage, FunctionMessageChunk, FunctionMessageFields, isFunctionMessage, isFunctionMessageChunk } from "./function.js";
@@ -12,4 +12,4 @@ import { $Expand, $MergeDiscriminatedUnion, $MergeObjects, Constructor, coerceMe
12
12
  import { $InferMessageContent, $InferMessageContentBlocks, $InferMessageProperties, $InferMessageProperty, $InferResponseMetadata, $MergeContentDefinition, $MergeMessageStructure, $MergeOutputVersion, $MessageToolCallBlock, $NormalizedMessageStructure, Message, MessageOutputVersion, MessageStructure, MessageToolDefinition, MessageToolSet, MessageType, StandardMessageStructure, isMessage } from "./message.js";
13
13
  import { RemoveMessage, RemoveMessageFields } from "./modifier.js";
14
14
  import { FilterMessagesFields, MessageChunkUnion, MessageTypeOrClass, MessageUnion, TrimMessagesFields, defaultTextSplitter, filterMessages, mergeMessageRuns, trimMessages } from "./transformers.js";
15
- export { $Expand, $InferMessageContent, $InferMessageContentBlocks, $InferMessageProperties, $InferMessageProperty, $InferResponseMetadata, $MergeContentDefinition, $MergeDiscriminatedUnion, $MergeMessageStructure, $MergeObjects, $MergeOutputVersion, $MessageToolCallBlock, $NormalizedMessageStructure, AIMessage, AIMessageChunk, AIMessageChunkFields, AIMessageFields, BaseMessage, BaseMessageChunk, BaseMessageFields, BaseMessageLike, ChatMessage, ChatMessageChunk, ChatMessageFields, Constructor, ContentBlock, Data, FilterMessagesFields, FunctionCall, FunctionMessage, FunctionMessageChunk, FunctionMessageFields, HumanMessage, HumanMessageChunk, HumanMessageFields, ImageDetail, InputTokenDetails, type InvalidToolCall, KNOWN_BLOCK_TYPES, Message, MessageChunkUnion, MessageContent, MessageContentComplex, MessageContentImageUrl, MessageContentText, MessageFieldWithRole, MessageOutputVersion, MessageStructure, MessageToolDefinition, MessageToolSet, MessageType, MessageTypeOrClass, MessageUnion, ModalitiesTokenDetails, OpenAIToolCall, OutputTokenDetails, ProviderFormatTypes, RemoveMessage, RemoveMessageFields, ResponseMetadata, StandardContentBlockConverter, StandardMessageStructure, StoredGeneration, StoredMessage, StoredMessageData, StoredMessageV1, SystemMessage, SystemMessageChunk, SystemMessageFields, ToolMessage, ToolMessageChunk, type ToolMessageFields, TrimMessagesFields, UsageMetadata, _isMessageFieldWithRole, _mergeDicts, _mergeLists, _mergeObj, _mergeStatus, coerceMessageLikeToMessage, convertToChunk, convertToOpenAIImageBlock, convertToProviderContentBlock, defaultTextSplitter, filterMessages, getBufferString, iife, isAIMessage, isAIMessageChunk, isBase64ContentBlock, isBaseMessage, isBaseMessageChunk, isChatMessage, isChatMessageChunk, isDataContentBlock, isFunctionMessage, isFunctionMessageChunk, isHumanMessage, isHumanMessageChunk, isIDContentBlock, isMessage, isOpenAIToolCallArray, isPlainTextContentBlock, isSystemMessage, isSystemMessageChunk, isToolMessage, isToolMessageChunk, isURLContentBlock, mapChatMessagesToStoredMessages, mapStoredMessageToChatMessage, mapStoredMessagesToChatMessages, mergeContent, mergeMessageRuns, mergeResponseMetadata, mergeUsageMetadata, parseBase64DataUrl, parseMimeType, trimMessages };
15
+ export { $Expand, $InferMessageContent, $InferMessageContentBlocks, $InferMessageProperties, $InferMessageProperty, $InferResponseMetadata, $MergeContentDefinition, $MergeDiscriminatedUnion, $MergeMessageStructure, $MergeObjects, $MergeOutputVersion, $MessageToolCallBlock, $NormalizedMessageStructure, AIMessage, AIMessageChunk, AIMessageChunkFields, AIMessageFields, BaseMessage, BaseMessageChunk, BaseMessageFields, BaseMessageLike, ChatMessage, ChatMessageChunk, ChatMessageFields, Constructor, ContentBlock, Data, DirectToolOutput, FilterMessagesFields, FunctionCall, FunctionMessage, FunctionMessageChunk, FunctionMessageFields, HumanMessage, HumanMessageChunk, HumanMessageFields, ImageDetail, InputTokenDetails, InvalidToolCall, KNOWN_BLOCK_TYPES, Message, MessageChunkUnion, MessageContent, MessageContentComplex, MessageContentImageUrl, MessageContentText, MessageFieldWithRole, MessageOutputVersion, MessageStructure, MessageToolDefinition, MessageToolSet, MessageType, MessageTypeOrClass, MessageUnion, ModalitiesTokenDetails, OpenAIToolCall, OutputTokenDetails, ProviderFormatTypes, RemoveMessage, RemoveMessageFields, ResponseMetadata, StandardContentBlockConverter, StandardMessageStructure, StoredGeneration, StoredMessage, StoredMessageData, StoredMessageV1, SystemMessage, SystemMessageChunk, SystemMessageFields, ToolCall, ToolCallChunk, ToolMessage, ToolMessageChunk, ToolMessageFields, TrimMessagesFields, UsageMetadata, _isMessageFieldWithRole, _mergeDicts, _mergeLists, _mergeObj, _mergeStatus, coerceMessageLikeToMessage, convertToChunk, convertToOpenAIImageBlock, convertToProviderContentBlock, defaultTextSplitter, defaultToolCallParser, filterMessages, getBufferString, iife, isAIMessage, isAIMessageChunk, isBase64ContentBlock, isBaseMessage, isBaseMessageChunk, isChatMessage, isChatMessageChunk, isDataContentBlock, isDirectToolOutput, isFunctionMessage, isFunctionMessageChunk, isHumanMessage, isHumanMessageChunk, isIDContentBlock, isMessage, isOpenAIToolCallArray, isPlainTextContentBlock, isSystemMessage, isSystemMessageChunk, isToolMessage, isToolMessageChunk, isURLContentBlock, mapChatMessagesToStoredMessages, mapStoredMessageToChatMessage, mapStoredMessagesToChatMessages, mergeContent, mergeMessageRuns, mergeResponseMetadata, mergeUsageMetadata, parseBase64DataUrl, parseMimeType, trimMessages };
@@ -3,7 +3,7 @@ import { convertToOpenAIImageBlock, convertToProviderContentBlock, isBase64Conte
3
3
  import { isMessage } from "./message.js";
4
4
  import { BaseMessage, BaseMessageChunk, _isMessageFieldWithRole, _mergeDicts, _mergeLists, _mergeObj, _mergeStatus, isBaseMessage, isBaseMessageChunk, isOpenAIToolCallArray, mergeContent } from "./base.js";
5
5
  import { mergeResponseMetadata, mergeUsageMetadata } from "./metadata.js";
6
- import { ToolMessage, ToolMessageChunk, isToolMessage, isToolMessageChunk } from "./tool.js";
6
+ import { ToolMessage, ToolMessageChunk, defaultToolCallParser, isDirectToolOutput, isToolMessage, isToolMessageChunk } from "./tool.js";
7
7
  import { AIMessage, AIMessageChunk, isAIMessage, isAIMessageChunk } from "./ai.js";
8
8
  import { ChatMessage, ChatMessageChunk, isChatMessage, isChatMessageChunk } from "./chat.js";
9
9
  import { FunctionMessage, FunctionMessageChunk, isFunctionMessage, isFunctionMessageChunk } from "./function.js";
@@ -43,6 +43,7 @@ __export(messages_exports, {
43
43
  convertToOpenAIImageBlock: () => convertToOpenAIImageBlock,
44
44
  convertToProviderContentBlock: () => convertToProviderContentBlock,
45
45
  defaultTextSplitter: () => defaultTextSplitter,
46
+ defaultToolCallParser: () => defaultToolCallParser,
46
47
  filterMessages: () => filterMessages,
47
48
  getBufferString: () => getBufferString,
48
49
  iife: () => iife,
@@ -54,6 +55,7 @@ __export(messages_exports, {
54
55
  isChatMessage: () => isChatMessage,
55
56
  isChatMessageChunk: () => isChatMessageChunk,
56
57
  isDataContentBlock: () => isDataContentBlock,
58
+ isDirectToolOutput: () => isDirectToolOutput,
57
59
  isFunctionMessage: () => isFunctionMessage,
58
60
  isFunctionMessageChunk: () => isFunctionMessageChunk,
59
61
  isHumanMessage: () => isHumanMessage,
@@ -80,5 +82,5 @@ __export(messages_exports, {
80
82
  });
81
83
 
82
84
  //#endregion
83
- export { AIMessage, AIMessageChunk, BaseMessage, BaseMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, KNOWN_BLOCK_TYPES, RemoveMessage, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk, _isMessageFieldWithRole, _mergeDicts, _mergeLists, _mergeObj, _mergeStatus, coerceMessageLikeToMessage, convertToChunk, convertToOpenAIImageBlock, convertToProviderContentBlock, defaultTextSplitter, filterMessages, getBufferString, iife, isAIMessage, isAIMessageChunk, isBase64ContentBlock, isBaseMessage, isBaseMessageChunk, isChatMessage, isChatMessageChunk, isDataContentBlock, isFunctionMessage, isFunctionMessageChunk, isHumanMessage, isHumanMessageChunk, isIDContentBlock, isMessage, isOpenAIToolCallArray, isPlainTextContentBlock, isSystemMessage, isSystemMessageChunk, isToolMessage, isToolMessageChunk, isURLContentBlock, mapChatMessagesToStoredMessages, mapStoredMessageToChatMessage, mapStoredMessagesToChatMessages, mergeContent, mergeMessageRuns, mergeResponseMetadata, mergeUsageMetadata, messages_exports, parseBase64DataUrl, parseMimeType, trimMessages };
85
+ export { AIMessage, AIMessageChunk, BaseMessage, BaseMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, KNOWN_BLOCK_TYPES, RemoveMessage, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk, _isMessageFieldWithRole, _mergeDicts, _mergeLists, _mergeObj, _mergeStatus, coerceMessageLikeToMessage, convertToChunk, convertToOpenAIImageBlock, convertToProviderContentBlock, defaultTextSplitter, defaultToolCallParser, filterMessages, getBufferString, iife, isAIMessage, isAIMessageChunk, isBase64ContentBlock, isBaseMessage, isBaseMessageChunk, isChatMessage, isChatMessageChunk, isDataContentBlock, isDirectToolOutput, isFunctionMessage, isFunctionMessageChunk, isHumanMessage, isHumanMessageChunk, isIDContentBlock, isMessage, isOpenAIToolCallArray, isPlainTextContentBlock, isSystemMessage, isSystemMessageChunk, isToolMessage, isToolMessageChunk, isURLContentBlock, mapChatMessagesToStoredMessages, mapStoredMessageToChatMessage, mapStoredMessagesToChatMessages, mergeContent, mergeMessageRuns, mergeResponseMetadata, mergeUsageMetadata, messages_exports, parseBase64DataUrl, parseMimeType, trimMessages };
84
86
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/messages/index.ts"],"sourcesContent":["export * from \"./ai.js\";\nexport * from \"./base.js\";\nexport * from \"./chat.js\";\nexport * from \"./function.js\";\nexport * from \"./human.js\";\nexport * from \"./system.js\";\nexport * from \"./utils.js\";\nexport * from \"./transformers.js\";\nexport * from \"./metadata.js\";\nexport * from \"./message.js\";\nexport * from \"./modifier.js\";\n// TODO: Use a star export when we deprecate the\n// existing \"ToolCall\" type in \"base.js\".\nexport {\n type ToolMessageFields,\n ToolMessage,\n ToolMessageChunk,\n type InvalidToolCall,\n isToolMessage,\n isToolMessageChunk,\n} from \"./tool.js\";\n\n// This is an old export for backwards compatibility with existing multimodal content blocks\n// TODO: remove this in v2\nexport * from \"./content/data.js\";\nexport * from \"./content/index.js\";\n"],"mappings":""}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/messages/index.ts"],"sourcesContent":["export * from \"./ai.js\";\nexport * from \"./base.js\";\nexport * from \"./chat.js\";\nexport * from \"./function.js\";\nexport * from \"./human.js\";\nexport * from \"./system.js\";\nexport * from \"./utils.js\";\nexport * from \"./transformers.js\";\nexport * from \"./metadata.js\";\nexport * from \"./message.js\";\nexport * from \"./modifier.js\";\nexport * from \"./tool.js\";\n\n// This is an old export for backwards compatibility with existing multimodal content blocks\n// TODO: remove this in v2\nexport * from \"./content/data.js\";\nexport * from \"./content/index.js\";\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"message.cjs","names":["message: unknown"],"sources":["../../src/messages/message.ts"],"sourcesContent":["import type { ContentBlock } from \"./content/index.js\";\nimport type { ResponseMetadata, UsageMetadata } from \"./metadata.js\";\nimport type { $MergeDiscriminatedUnion, $MergeObjects } from \"./utils.js\";\n\n/**\n * Represents the possible types of messages in the system.\n * Includes standard message types (\"ai\", \"human\", \"tool\", \"system\")\n * and allows for custom string types that are non-null.\n *\n * @example\n * ```ts\n * // Standard message types\n * const messageType1: MessageType = \"ai\";\n * const messageType2: MessageType = \"human\";\n *\n * // Custom message type\n * const messageType3: MessageType = \"custom_type\";\n * ```\n */\nexport type MessageType =\n | \"ai\"\n | \"human\"\n | \"tool\"\n | \"system\"\n | (string & NonNullable<unknown>);\n\n/**\n * Represents the output version format for message content.\n *\n * This type determines how the content field is structured in a message:\n * - \"v0\": Content is represented as a simple string or array of content blocks\n * - provides backward compatibility with simpler content representations\n * - \"v1\": Content follows the structured ContentBlock format with typed discriminated unions\n * - enables full type safety and structured content block handling\n *\n * @example\n * ```ts\n * // v0 format - simple content representation\n * const v0Message: Message<{ outputVersion: \"v0\", content: ... }> = {\n * type: \"human\",\n * content: \"Hello world\" // string | Array<ContentBlock | ContentBlock.Text>\n * };\n *\n * // v1 format - structured content blocks\n * const v1Message: Message<{ outputVersion: \"v1\", content: ... }> = {\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image\", image_url: \"...\" }\n * ] // Array<ContentBlock | ...> (determined by the structure)\n * };\n * ```\n */\nexport type MessageOutputVersion = \"v0\" | \"v1\";\n\n/**\n * Represents the input and output types of a tool that can be used in messages.\n *\n * @template TInput - The type of input the tool accepts.\n * @template TOutput - The type of output the tool produces.\n *\n * @example\n * ```ts\n * // Tool that takes a string input and returns a number\n * interface StringToNumberTool extends MessageToolDefinition<string, number> {\n * input: string;\n * output: number;\n * }\n * ```\n */\nexport interface MessageToolDefinition<TInput = unknown, TOutput = unknown> {\n input: TInput;\n output: TOutput;\n}\n\n/**\n * Represents a structured set of tools by mapping tool names to definitions\n * that can be used in messages.\n *\n * @example\n * ```ts\n * interface MyToolSet extends MessageToolSet {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * translator: MessageToolDefinition<\n * { text: string; targetLanguage: string },\n * string\n * >;\n * }\n * ```\n */\nexport interface MessageToolSet {\n [key: string]: MessageToolDefinition;\n}\n\n/**\n * Represents a tool call block within a message structure by mapping tool names to their\n * corresponding tool call formats, including the input arguments and an optional identifier.\n *\n * @template TStructure - A message structure type that may contain tool definitions\n *\n * @example\n * ```ts\n * // Given a message structure with a calculator tool:\n * interface MyStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<{ operation: string, numbers: number[] }, number>\n * }\n * }\n *\n * // The tool call block would be:\n * type CalcToolCall = $MessageToolCallBlock<MyStructure>;\n * // Resolves to:\n * // {\n * // type: \"tool_call\";\n * // name: \"calculator\";\n * // args: { operation: string, numbers: number[] };\n * // id?: string;\n * // }\n * ```\n */\nexport type $MessageToolCallBlock<TStructure extends MessageStructure> =\n TStructure[\"tools\"] extends MessageToolSet\n ? {\n [K in keyof TStructure[\"tools\"]]: K extends string\n ? TStructure[\"tools\"][K] extends MessageToolDefinition\n ? ContentBlock.Tools.ToolCall<K, TStructure[\"tools\"][K][\"input\"]>\n : never\n : never;\n }[keyof TStructure[\"tools\"]]\n : never;\n\n/**\n * Core interface that defines the structure of messages.\n *\n * @example\n * ```ts\n * // Basic message structure with just content blocks\n * interface SimpleMessageStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * // allows for text + reasoning blocks in ai messages\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * }\n * }\n *\n * // Message structure with tools and properties\n * interface AdvancedMessageStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * };\n * content: {\n * // allows for text + image blocks in human messages\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // only allows for text blocks in ai messages\n * ai: ContentBlock.Text;\n * };\n * properties: {\n * // pins properties to ai messages\n * ai: {\n * response_metadata: {\n * confidence: number;\n * model: string;\n * };\n * };\n * }\n * }\n *\n * // Using with $MergeMessageStructure to combine structures\n * // The resulting type when passed into BaseMessage will have a calculator tool,\n * // allow for text + image blocks in human messages,\n * // and text + reasoning blocks + additional arbitrary properties in ai messages.\n * type CombinedStructure = $MergeMessageStructure<\n * SimpleMessageStructure,\n * AdvancedMessageStructure\n * >;\n *\n * // Using in a Message object\n * const message: Message<CombinedStructure> = {\n * id: \"msg-123\",\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello!\" }\n * { type: \"image\", mimeType: \"image/jpeg\", url: \"https://example.com/image.jpg\" }\n * // this block will throw an error because it's not defined in the structure\n * { type: \"reasoning\", reasoning: \"The answer is 42\" }\n * ]\n * };\n * ```\n */\nexport interface MessageStructure {\n /**\n * Optional output version for the message structure.\n * If not provided, defaults to \"v0\".\n */\n readonly outputVersion?: MessageOutputVersion;\n /**\n * Optional set of tool definitions that can be used in messages.\n * Each tool is defined with input/output types and can be referenced in tool messages.\n */\n readonly tools?: MessageToolSet;\n /**\n * Optional mapping of message types to their allowed content blocks.\n * Each message type can specify what content block types it supports (text, images, etc).\n */\n readonly content?: Partial<{\n [key in MessageType]: ContentBlock;\n }>;\n /**\n * Optional mapping of message types to arbitrary property objects.\n * Allows attaching custom metadata or other information to specific message types.\n */\n readonly properties?: Partial<{\n [key in MessageType]: Record<string, unknown>;\n }>;\n}\n\n/**\n * Normalizes an arbitrary type to a message output version or undefined.\n * Accepts unknown and narrows to a valid MessageOutputVersion if present.\n */\ntype $NormalizeMessageOutputVersion<T> =\n | Extract<T, MessageOutputVersion>\n | undefined;\n\n/**\n * Merges two output version types from message structures.\n *\n * This utility type determines the resulting output version when combining two message structures.\n * The merge logic follows these rules:\n *\n * - If both T and U are undefined, defaults to \"v0\" for backwards compatibility\n * - If T is undefined but U is defined, uses U's version\n * - If U is undefined but T is defined, uses T's version\n * - If both T and U are defined, U takes precedence (later structure wins)\n *\n * @template T - The output version from the first message structure\n * @template U - The output version from the second message structure\n *\n * @example\n * ```ts\n * // Both undefined - defaults to \"v0\"\n * type Result1 = $MergeOutputVersion<undefined, undefined>; // \"v0\"\n *\n * // One defined - uses the defined version\n * type Result2 = $MergeOutputVersion<undefined, \"v1\">; // \"v1\"\n * type Result3 = $MergeOutputVersion<\"v0\", undefined>; // \"v0\"\n *\n * // Both defined - second takes precedence\n * type Result4 = $MergeOutputVersion<\"v0\", \"v1\">; // \"v1\"\n * ```\n */\nexport type $MergeOutputVersion<T, U> =\n $NormalizeMessageOutputVersion<T> extends infer TV\n ? $NormalizeMessageOutputVersion<U> extends infer UV\n ? [TV, UV] extends [undefined, undefined]\n ? \"v0\"\n : [TV] extends [undefined]\n ? Exclude<UV, undefined>\n : [UV] extends [undefined]\n ? Exclude<TV, undefined>\n : UV\n : never\n : never;\n\n/**\n * Merges two content definition objects from message structures.\n *\n * This utility type combines content definitions from two message structures, handling\n * the merging of content block types for each message type. The merge logic follows\n * these rules:\n *\n * - For keys that exist in both T and U: Merges the content blocks using discriminated\n * union merging based on the \"type\" property. This allows combining different content\n * block types (e.g., text + image) for the same message type.\n * - For keys that exist only in T: Uses T's content definition as-is\n * - For keys that exist only in U: Uses U's content definition as-is\n *\n * @template T - The content definition from the first message structure\n * @template U - The content definition from the second message structure\n *\n * @example\n * ```ts\n * // T allows text content for human messages\n * type ContentA = {\n * human: ContentBlock.Text;\n * };\n *\n * // U allows image content for human messages and text for AI messages\n * type ContentB = {\n * human: ContentBlock.Multimodal.Image;\n * ai: ContentBlock.Text;\n * };\n *\n * // Merged result allows both text and images for human messages, text for AI\n * type Merged = $MergeContentDefinition<ContentA, ContentB>;\n * // Result: {\n * // human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // ai: ContentBlock.Text;\n * // }\n * ```\n */\nexport type $MergeContentDefinition<T, U> = {\n [K in keyof T | keyof U as Extract<\n (K extends keyof T ? T[K] : never) | (K extends keyof U ? U[K] : never),\n ContentBlock\n > extends never\n ? never\n : K]: K extends keyof T\n ? K extends keyof U\n ? $MergeDiscriminatedUnion<\n Extract<T[K], ContentBlock>,\n Extract<U[K], ContentBlock>,\n \"type\"\n >\n : Extract<T[K], ContentBlock>\n : K extends keyof U\n ? Extract<U[K], ContentBlock>\n : never;\n};\n\n/**\n * Merges two message structures A and B into a combined structure.\n * This is a type utility that handles merging of tools, content blocks, and properties\n * from two message structures. The resulting type is usable as its own message structure.\n *\n * @example\n * ```ts\n * // Structure A allows text in human messages and has a confidence property on AI messages\n * interface StructureA extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * };\n * properties: {\n * ai: { confidence: number };\n * }\n * }\n *\n * // Structure B allows images in human messages and has a model property on AI messages\n * interface StructureB extends MessageStructure {\n * content: {\n * human: ContentBlock.Multimodal.Image;\n * };\n * properties: {\n * ai: { model: string };\n * }\n * }\n *\n * // Merged structure allows both text and images in human messages\n * // AI messages have both confidence and model properties\n * type Merged = $MergeMessageStructure<StructureA, StructureB>;\n * ```\n *\n * @template A - First message structure to merge\n * @template B - Second message structure to merge (takes precedence over A)\n */\nexport type $MergeMessageStructure<\n T extends MessageStructure,\n U extends MessageStructure\n> = {\n outputVersion: $MergeOutputVersion<T[\"outputVersion\"], U[\"outputVersion\"]>;\n tools: $MergeObjects<T[\"tools\"], U[\"tools\"]>;\n content: $MergeContentDefinition<T[\"content\"], U[\"content\"]>;\n properties: $MergeObjects<T[\"properties\"], U[\"properties\"]>;\n};\n\n/**\n * Standard message structured used to define the most basic message structure that's\n * used throughout the library.\n *\n * This is also the message structure that's used when a message structure is not provided.\n */\nexport interface StandardMessageStructure extends MessageStructure {\n content: {\n /** Text content for AI messages */\n ai: ContentBlock.Text;\n /** Text content for human messages */\n human: ContentBlock.Text;\n /** Text content for system messages */\n system: ContentBlock.Text;\n /** Text content for tool messages */\n tool: ContentBlock.Text;\n };\n properties: {\n /** Properties specific to AI messages */\n ai: {\n /** Metadata about the AI model response */\n response_metadata?: ResponseMetadata;\n /** Usage statistics for the AI response */\n usage_metadata?: UsageMetadata;\n };\n human: {\n /** Metadata about the human message */\n response_metadata?: Record<string, unknown>;\n };\n system: {\n /** Metadata about the system message */\n response_metadata?: Record<string, unknown>;\n };\n tool: {\n /** Metadata about the tool message */\n response_metadata?: Record<string, unknown>;\n };\n };\n}\n\n/**\n * Takes a message structure type T and normalizes it by merging it with the standard message structure.\n * If T is already a standard message structure, returns T unchanged.\n *\n * This ensures that any custom message structure includes all the standard message structure fields\n * by default while allowing overrides and extensions.\n *\n * @template T - The message structure type to normalize, must extend MessageStructure\n * @returns Either T if it's already a standard structure, or the merged result of T with standard structure\n */\nexport type $NormalizedMessageStructure<T extends MessageStructure> =\n T extends StandardMessageStructure\n ? T\n : $MergeMessageStructure<StandardMessageStructure, T>;\n\n/**\n * Infers the content blocks for a specific message type in a message structure.\n *\n * This utility type extracts the content block type that corresponds to a given message type\n * from the message structure's content definition.\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content block type for the specified type, or never if its not defined in the structure\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContent = $InferMessageContentBlocks<MyStructure, \"human\">;\n * // HumanContent = ContentBlock.Text\n *\n * type AIContent = $InferMessageContentBlocks<MyStructure, \"ai\">;\n * // AIContent = ContentBlock.Text | ContentBlock.ToolCall\n * ```\n */\nexport type $InferMessageContentBlocks<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = $NormalizedMessageStructure<TStructure> extends infer S\n ? S extends MessageStructure\n ? S[\"content\"] extends infer C\n ? C extends Record<PropertyKey, ContentBlock>\n ? TRole extends keyof C\n ? [$MessageToolCallBlock<TStructure>] extends [never]\n ? C[TRole]\n : $MergeDiscriminatedUnion<\n NonNullable<C[TRole]>,\n $MessageToolCallBlock<TStructure>,\n \"type\"\n >\n : never\n : never\n : never\n : never\n : never;\n\n/**\n * Infers the content type for a specific message type from a message structure.\n *\n * This utility type determines the appropriate content type based on the message structure's\n * output version and the specified message type. The content type varies depending on the\n * output version (see {@link MessageOutputVersion})\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content type for the specified role based on the output version\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * outputVersion: \"v0\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContentV0 = $InferMessageContent<MyStructure, \"human\">;\n * // HumanContentV0 = string | Array<ContentBlock | ContentBlock.Text>\n *\n * interface MyStructureV1 extends MessageStructure {\n * outputVersion: \"v1\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * };\n * }\n *\n * type HumanContentV1 = $InferMessageContent<MyStructureV1, \"human\">;\n * // HumanContentV1 = ContentBlock.Text\n *\n * type AIContentV1 = $InferMessageContent<MyStructureV1, \"ai\">;\n * // AIContentV1 = ContentBlock.Text | ContentBlock.Reasoning\n * ```\n */\nexport type $InferMessageContent<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = TStructure[\"outputVersion\"] extends \"v1\"\n ? Array<$InferMessageContentBlocks<TStructure, TRole>>\n : string | Array<ContentBlock | ContentBlock.Text>;\n\n/**\n * Infers the properties for a specific message type from a message structure.\n *\n * This utility type extracts the properties object that corresponds to a given message type\n * from the message structure's properties definition, and excludes the reserved\n * \"content\" and \"type\" properties to avoid conflicts with the core message structure.\n *\n * If the specified type is not defined in the message structure's properties, it returns\n * a generic Record<string, unknown> type to allow for arbitrary properties.\n *\n * @template TStructure - The message structure to infer properties from\n * @template TRole - The message type/role to get properties for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The properties object type for the specified type, excluding \"content\" and \"type\"\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string };\n * usage_metadata: { tokens: number };\n * content: string; // This will be omitted\n * type: string; // This will be omitted\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIProperties = $InferMessageProperties<MyStructure, \"ai\">;\n * // AIProperties = { response_metadata: { model: string }; usage_metadata: { tokens: number } }\n *\n * type HumanProperties = $InferMessageProperties<MyStructure, \"human\">;\n * // HumanProperties = { metadata: Record<string, unknown> }\n *\n * type SystemProperties = $InferMessageProperties<MyStructure, \"system\">;\n * // SystemProperties = Record<string, unknown> (fallback for undefined role)\n * ```\n */\nexport type $InferMessageProperties<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = $NormalizedMessageStructure<TStructure> extends infer S\n ? S extends MessageStructure\n ? S[\"properties\"] extends infer P | undefined\n ? P extends Record<PropertyKey, unknown>\n ? TRole extends keyof P\n ? Omit<P[TRole], \"content\" | \"type\">\n : Record<string, unknown>\n : Record<string, unknown>\n : Record<string, unknown>\n : never\n : never;\n\n/**\n * Infers the type of a specific property for a message type from a message structure.\n *\n * This utility type extracts the type of a single property by name from the properties\n * object that corresponds to a given message type. If the specified property key does\n * not exist in the type's properties, it returns `never`.\n *\n * @template TStructure - The message structure to infer the property from\n * @template TRole - The message type/role to get the property for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @template K - The property key to extract the type for\n * @returns The type of the specified property, or `never` if the property doesn't exist\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number };\n * usage_metadata: { input_tokens: number; output_tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type ResponseMetadata = $InferMessageProperty<MyStructure, \"ai\", \"response_metadata\">;\n * // ResponseMetadata = { model: string; temperature: number }\n *\n * type UsageMetadata = $InferMessageProperty<MyStructure, \"ai\", \"usage_metadata\">;\n * // UsageMetadata = { input_tokens: number; output_tokens: number }\n *\n * type NonExistentProperty = $InferMessageProperty<MyStructure, \"ai\", \"nonExistent\">;\n * // NonExistentProperty = Record<string, unknown>\n *\n * type HumanMetadata = $InferMessageProperty<MyStructure, \"human\", \"metadata\">;\n * // HumanMetadata = Record<string, unknown>\n * ```\n */\nexport type $InferMessageProperty<\n TStructure extends MessageStructure,\n TRole extends MessageType,\n K extends string\n> = K extends keyof $InferMessageProperties<TStructure, TRole>\n ? $InferMessageProperties<TStructure, TRole>[K]\n : never;\n\n/**\n * Infers the response metadata type for a specific message type from a message structure.\n *\n * This utility type extracts the `response_metadata` property type for a given message type.\n *\n * @template TStructure - The message structure to infer the response metadata from\n * @template TRole - The message type/role to get the response metadata for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The type of the response_metadata property, or `Record<string, unknown>` as fallback\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number; tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIResponseMetadata = $InferResponseMetadata<MyStructure, \"ai\">;\n * // AIResponseMetadata = { model: string; temperature: number; tokens: number }\n *\n * type HumanResponseMetadata = $InferResponseMetadata<MyStructure, \"human\">;\n * // HumanResponseMetadata = Record<string, unknown> (fallback since not defined)\n * ```\n */\nexport type $InferResponseMetadata<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = $InferMessageProperty<\n TStructure,\n TRole,\n \"response_metadata\"\n> extends infer P\n ? [P] extends [unknown]\n ? Record<string, unknown>\n : P\n : never;\n\n/**\n * Represents a message object that organizes context for an LLM.\n *\n * @example\n * ```ts\n * // Basic message with text content\n * const message: Message = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"human\",\n * content: [{ type: \"text\", text: \"Hello!\" }]\n * };\n *\n * // Basic ai message interface extension\n * interface MyMessage extends Message<StandardMessageStructure, \"ai\"> {\n * // Additional AI-specific properties can be added here\n * }\n *`\n * // Custom message structure\n * interface CustomStructure extends MessageStructure {\n * content: {\n * ai: ContentBlock.Text | ContentBlock.ToolCall<\"search\", { query: string }>;\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * };\n * }\n *\n * // Create a message with custom structure\n * const message: Message<CustomStructure> = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"ai\",\n * content: [\n * { type: \"text\", text: \"Hello!\" },\n * {\n * type: \"tool_call\",\n * name: \"search\",\n * args: { query: \"What is the capital of France?\" }\n * }\n * ]\n * };\n * ```\n */\nexport interface Message<\n TStructure extends MessageStructure = StandardMessageStructure,\n TRole extends MessageType = MessageType\n> {\n /** The message type/role */\n readonly type: TRole;\n /** Unique identifier for this message */\n id?: string;\n /** Optional name/identifier for the entity that created this message */\n name?: string;\n /** Array of content blocks that make up the message content */\n content: $InferMessageContent<TStructure, TRole>;\n /** Metadata about the message */\n response_metadata?: Partial<$InferResponseMetadata<TStructure, TRole>>;\n}\n\n/**\n * Type guard to check if a value is a valid Message object.\n *\n * @param message - The value to check\n * @returns true if the value is a valid Message object, false otherwise\n */\nexport function isMessage(message: unknown): message is Message {\n return (\n typeof message === \"object\" &&\n message !== null &&\n \"type\" in message &&\n \"content\" in message &&\n (typeof message.content === \"string\" || Array.isArray(message.content))\n );\n}\n"],"mappings":";;;;;;;;AAitBA,SAAgB,UAAUA,SAAsC;AAC9D,QACE,OAAO,YAAY,YACnB,YAAY,QACZ,UAAU,WACV,aAAa,YACZ,OAAO,QAAQ,YAAY,YAAY,MAAM,QAAQ,QAAQ,QAAQ;AAEzE"}
1
+ {"version":3,"file":"message.cjs","names":["message: unknown"],"sources":["../../src/messages/message.ts"],"sourcesContent":["import type { ContentBlock } from \"./content/index.js\";\nimport type { ResponseMetadata, UsageMetadata } from \"./metadata.js\";\nimport type { $MergeDiscriminatedUnion, $MergeObjects } from \"./utils.js\";\n\n/**\n * Represents the possible types of messages in the system.\n * Includes standard message types (\"ai\", \"human\", \"tool\", \"system\")\n * and allows for custom string types that are non-null.\n *\n * @example\n * ```ts\n * // Standard message types\n * const messageType1: MessageType = \"ai\";\n * const messageType2: MessageType = \"human\";\n *\n * // Custom message type\n * const messageType3: MessageType = \"custom_type\";\n * ```\n */\nexport type MessageType =\n | \"ai\"\n | \"human\"\n | \"tool\"\n | \"system\"\n | (string & NonNullable<unknown>);\n\n/**\n * Represents the output version format for message content.\n *\n * This type determines how the content field is structured in a message:\n * - \"v0\": Content is represented as a simple string or array of content blocks\n * - provides backward compatibility with simpler content representations\n * - \"v1\": Content follows the structured ContentBlock format with typed discriminated unions\n * - enables full type safety and structured content block handling\n *\n * @example\n * ```ts\n * // v0 format - simple content representation\n * const v0Message: Message<{ outputVersion: \"v0\", content: ... }> = {\n * type: \"human\",\n * content: \"Hello world\" // string | Array<ContentBlock | ContentBlock.Text>\n * };\n *\n * // v1 format - structured content blocks\n * const v1Message: Message<{ outputVersion: \"v1\", content: ... }> = {\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image\", image_url: \"...\" }\n * ] // Array<ContentBlock | ...> (determined by the structure)\n * };\n * ```\n */\nexport type MessageOutputVersion = \"v0\" | \"v1\";\n\n/**\n * Represents the input and output types of a tool that can be used in messages.\n *\n * @template TInput - The type of input the tool accepts.\n * @template TOutput - The type of output the tool produces.\n *\n * @example\n * ```ts\n * // Tool that takes a string input and returns a number\n * interface StringToNumberTool extends MessageToolDefinition<string, number> {\n * input: string;\n * output: number;\n * }\n * ```\n */\nexport interface MessageToolDefinition<TInput = unknown, TOutput = unknown> {\n input: TInput;\n output: TOutput;\n}\n\n/**\n * Represents a structured set of tools by mapping tool names to definitions\n * that can be used in messages.\n *\n * @example\n * ```ts\n * interface MyToolSet extends MessageToolSet {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * translator: MessageToolDefinition<\n * { text: string; targetLanguage: string },\n * string\n * >;\n * }\n * ```\n */\nexport interface MessageToolSet {\n [key: string]: MessageToolDefinition;\n}\n\n/**\n * Represents a tool call block within a message structure by mapping tool names to their\n * corresponding tool call formats, including the input arguments and an optional identifier.\n *\n * @template TStructure - A message structure type that may contain tool definitions\n *\n * @example\n * ```ts\n * // Given a message structure with a calculator tool:\n * interface MyStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<{ operation: string, numbers: number[] }, number>\n * }\n * }\n *\n * // The tool call block would be:\n * type CalcToolCall = $MessageToolCallBlock<MyStructure>;\n * // Resolves to:\n * // {\n * // type: \"tool_call\";\n * // name: \"calculator\";\n * // args: { operation: string, numbers: number[] };\n * // id?: string;\n * // }\n * ```\n */\nexport type $MessageToolCallBlock<TStructure extends MessageStructure> =\n TStructure[\"tools\"] extends MessageToolSet\n ? {\n [K in keyof TStructure[\"tools\"]]: K extends string\n ? TStructure[\"tools\"][K] extends MessageToolDefinition\n ? ContentBlock.Tools.ToolCall<K, TStructure[\"tools\"][K][\"input\"]>\n : never\n : never;\n }[keyof TStructure[\"tools\"]]\n : never;\n\n/**\n * Core interface that defines the structure of messages.\n *\n * @example\n * ```ts\n * // Basic message structure with just content blocks\n * interface SimpleMessageStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * // allows for text + reasoning blocks in ai messages\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * }\n * }\n *\n * // Message structure with tools and properties\n * interface AdvancedMessageStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * };\n * content: {\n * // allows for text + image blocks in human messages\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // only allows for text blocks in ai messages\n * ai: ContentBlock.Text;\n * };\n * properties: {\n * // pins properties to ai messages\n * ai: {\n * response_metadata: {\n * confidence: number;\n * model: string;\n * };\n * };\n * }\n * }\n *\n * // Using with $MergeMessageStructure to combine structures\n * // The resulting type when passed into BaseMessage will have a calculator tool,\n * // allow for text + image blocks in human messages,\n * // and text + reasoning blocks + additional arbitrary properties in ai messages.\n * type CombinedStructure = $MergeMessageStructure<\n * SimpleMessageStructure,\n * AdvancedMessageStructure\n * >;\n *\n * // Using in a Message object\n * const message: Message<CombinedStructure> = {\n * id: \"msg-123\",\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello!\" }\n * { type: \"image\", mimeType: \"image/jpeg\", url: \"https://example.com/image.jpg\" }\n * // this block will throw an error because it's not defined in the structure\n * { type: \"reasoning\", reasoning: \"The answer is 42\" }\n * ]\n * };\n * ```\n */\nexport interface MessageStructure {\n /**\n * Optional output version for the message structure.\n * If not provided, defaults to \"v0\".\n */\n readonly outputVersion?: MessageOutputVersion;\n /**\n * Optional set of tool definitions that can be used in messages.\n * Each tool is defined with input/output types and can be referenced in tool messages.\n */\n readonly tools?: MessageToolSet;\n /**\n * Optional mapping of message types to their allowed content blocks.\n * Each message type can specify what content block types it supports (text, images, etc).\n */\n readonly content?: Partial<{\n [key in MessageType]: ContentBlock;\n }>;\n /**\n * Optional mapping of message types to arbitrary property objects.\n * Allows attaching custom metadata or other information to specific message types.\n */\n readonly properties?: Partial<{\n [key in MessageType]: Record<string, unknown>;\n }>;\n}\n\n/**\n * Normalizes an arbitrary type to a message output version or undefined.\n * Accepts unknown and narrows to a valid MessageOutputVersion if present.\n */\ntype $NormalizeMessageOutputVersion<T> =\n | Extract<T, MessageOutputVersion>\n | undefined;\n\n/**\n * Merges two output version types from message structures.\n *\n * This utility type determines the resulting output version when combining two message structures.\n * The merge logic follows these rules:\n *\n * - If both T and U are undefined, defaults to \"v0\" for backwards compatibility\n * - If T is undefined but U is defined, uses U's version\n * - If U is undefined but T is defined, uses T's version\n * - If both T and U are defined, U takes precedence (later structure wins)\n *\n * @template T - The output version from the first message structure\n * @template U - The output version from the second message structure\n *\n * @example\n * ```ts\n * // Both undefined - defaults to \"v0\"\n * type Result1 = $MergeOutputVersion<undefined, undefined>; // \"v0\"\n *\n * // One defined - uses the defined version\n * type Result2 = $MergeOutputVersion<undefined, \"v1\">; // \"v1\"\n * type Result3 = $MergeOutputVersion<\"v0\", undefined>; // \"v0\"\n *\n * // Both defined - second takes precedence\n * type Result4 = $MergeOutputVersion<\"v0\", \"v1\">; // \"v1\"\n * ```\n */\nexport type $MergeOutputVersion<T, U> =\n $NormalizeMessageOutputVersion<T> extends infer TV\n ? $NormalizeMessageOutputVersion<U> extends infer UV\n ? [TV, UV] extends [undefined, undefined]\n ? \"v0\"\n : [TV] extends [undefined]\n ? Exclude<UV, undefined>\n : [UV] extends [undefined]\n ? Exclude<TV, undefined>\n : UV\n : never\n : never;\n\n/**\n * Merges two content definition objects from message structures.\n *\n * This utility type combines content definitions from two message structures, handling\n * the merging of content block types for each message type. The merge logic follows\n * these rules:\n *\n * - For keys that exist in both T and U: Merges the content blocks using discriminated\n * union merging based on the \"type\" property. This allows combining different content\n * block types (e.g., text + image) for the same message type.\n * - For keys that exist only in T: Uses T's content definition as-is\n * - For keys that exist only in U: Uses U's content definition as-is\n *\n * @template T - The content definition from the first message structure\n * @template U - The content definition from the second message structure\n *\n * @example\n * ```ts\n * // T allows text content for human messages\n * type ContentA = {\n * human: ContentBlock.Text;\n * };\n *\n * // U allows image content for human messages and text for AI messages\n * type ContentB = {\n * human: ContentBlock.Multimodal.Image;\n * ai: ContentBlock.Text;\n * };\n *\n * // Merged result allows both text and images for human messages, text for AI\n * type Merged = $MergeContentDefinition<ContentA, ContentB>;\n * // Result: {\n * // human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // ai: ContentBlock.Text;\n * // }\n * ```\n */\nexport type $MergeContentDefinition<T, U> = {\n [K in keyof T | keyof U as Extract<\n (K extends keyof T ? T[K] : never) | (K extends keyof U ? U[K] : never),\n ContentBlock\n > extends never\n ? never\n : K]: K extends keyof T\n ? K extends keyof U\n ? $MergeDiscriminatedUnion<\n Extract<T[K], ContentBlock>,\n Extract<U[K], ContentBlock>,\n \"type\"\n >\n : Extract<T[K], ContentBlock>\n : K extends keyof U\n ? Extract<U[K], ContentBlock>\n : never;\n};\n\n/**\n * Merges two message structures A and B into a combined structure.\n * This is a type utility that handles merging of tools, content blocks, and properties\n * from two message structures. The resulting type is usable as its own message structure.\n *\n * @example\n * ```ts\n * // Structure A allows text in human messages and has a confidence property on AI messages\n * interface StructureA extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * };\n * properties: {\n * ai: { confidence: number };\n * }\n * }\n *\n * // Structure B allows images in human messages and has a model property on AI messages\n * interface StructureB extends MessageStructure {\n * content: {\n * human: ContentBlock.Multimodal.Image;\n * };\n * properties: {\n * ai: { model: string };\n * }\n * }\n *\n * // Merged structure allows both text and images in human messages\n * // AI messages have both confidence and model properties\n * type Merged = $MergeMessageStructure<StructureA, StructureB>;\n * ```\n *\n * @template A - First message structure to merge\n * @template B - Second message structure to merge (takes precedence over A)\n */\nexport type $MergeMessageStructure<\n T extends MessageStructure,\n U extends MessageStructure\n> = {\n outputVersion: $MergeOutputVersion<T[\"outputVersion\"], U[\"outputVersion\"]>;\n tools: $MergeObjects<T[\"tools\"], U[\"tools\"]>;\n content: $MergeContentDefinition<T[\"content\"], U[\"content\"]>;\n properties: $MergeObjects<T[\"properties\"], U[\"properties\"]>;\n};\n\n/**\n * Standard message structured used to define the most basic message structure that's\n * used throughout the library.\n *\n * This is also the message structure that's used when a message structure is not provided.\n */\nexport interface StandardMessageStructure extends MessageStructure {\n content: {\n /** Text content for AI messages */\n ai: ContentBlock.Text;\n /** Text content for human messages */\n human: ContentBlock.Text;\n /** Text content for system messages */\n system: ContentBlock.Text;\n /** Text content for tool messages */\n tool: ContentBlock.Text;\n };\n properties: {\n /** Properties specific to AI messages */\n ai: {\n /** Metadata about the AI model response */\n response_metadata: ResponseMetadata;\n /** Usage statistics for the AI response */\n usage_metadata: UsageMetadata;\n };\n human: {\n /** Metadata about the human message */\n response_metadata: Record<string, unknown>;\n };\n system: {\n /** Metadata about the system message */\n response_metadata: Record<string, unknown>;\n };\n tool: {\n /** Metadata about the tool message */\n response_metadata: Record<string, unknown>;\n };\n };\n}\n\n/**\n * Takes a message structure type T and normalizes it by merging it with the standard message structure.\n * If T is already a standard message structure, returns T unchanged.\n *\n * This ensures that any custom message structure includes all the standard message structure fields\n * by default while allowing overrides and extensions.\n *\n * @template T - The message structure type to normalize, must extend MessageStructure\n * @returns Either T if it's already a standard structure, or the merged result of T with standard structure\n */\nexport type $NormalizedMessageStructure<T extends MessageStructure> =\n T extends StandardMessageStructure\n ? T\n : $MergeMessageStructure<StandardMessageStructure, T>;\n\n/**\n * Infers the content blocks for a specific message type in a message structure.\n *\n * This utility type extracts the content block type that corresponds to a given message type\n * from the message structure's content definition.\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content block type for the specified type, or never if its not defined in the structure\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContent = $InferMessageContentBlocks<MyStructure, \"human\">;\n * // HumanContent = ContentBlock.Text\n *\n * type AIContent = $InferMessageContentBlocks<MyStructure, \"ai\">;\n * // AIContent = ContentBlock.Text | ContentBlock.ToolCall\n * ```\n */\nexport type $InferMessageContentBlocks<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = $NormalizedMessageStructure<TStructure> extends infer S\n ? S extends MessageStructure\n ? S[\"content\"] extends infer C\n ? C extends Record<PropertyKey, ContentBlock>\n ? TRole extends keyof C\n ? [$MessageToolCallBlock<TStructure>] extends [never]\n ? C[TRole]\n : $MergeDiscriminatedUnion<\n NonNullable<C[TRole]>,\n $MessageToolCallBlock<TStructure>,\n \"type\"\n >\n : never\n : never\n : never\n : never\n : never;\n\n/**\n * Infers the content type for a specific message type from a message structure.\n *\n * This utility type determines the appropriate content type based on the message structure's\n * output version and the specified message type. The content type varies depending on the\n * output version (see {@link MessageOutputVersion})\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content type for the specified role based on the output version\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * outputVersion: \"v0\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContentV0 = $InferMessageContent<MyStructure, \"human\">;\n * // HumanContentV0 = string | Array<ContentBlock | ContentBlock.Text>\n *\n * interface MyStructureV1 extends MessageStructure {\n * outputVersion: \"v1\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * };\n * }\n *\n * type HumanContentV1 = $InferMessageContent<MyStructureV1, \"human\">;\n * // HumanContentV1 = ContentBlock.Text\n *\n * type AIContentV1 = $InferMessageContent<MyStructureV1, \"ai\">;\n * // AIContentV1 = ContentBlock.Text | ContentBlock.Reasoning\n * ```\n */\nexport type $InferMessageContent<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = TStructure[\"outputVersion\"] extends \"v1\"\n ? Array<$InferMessageContentBlocks<TStructure, TRole>>\n : string | Array<ContentBlock | ContentBlock.Text>;\n\n/**\n * Infers the properties for a specific message type from a message structure.\n *\n * This utility type extracts the properties object that corresponds to a given message type\n * from the message structure's properties definition, and excludes the reserved\n * \"content\" and \"type\" properties to avoid conflicts with the core message structure.\n *\n * If the specified type is not defined in the message structure's properties, it returns\n * a generic Record<string, unknown> type to allow for arbitrary properties.\n *\n * @template TStructure - The message structure to infer properties from\n * @template TRole - The message type/role to get properties for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The properties object type for the specified type, excluding \"content\" and \"type\"\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string };\n * usage_metadata: { tokens: number };\n * content: string; // This will be omitted\n * type: string; // This will be omitted\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIProperties = $InferMessageProperties<MyStructure, \"ai\">;\n * // AIProperties = { response_metadata: { model: string }; usage_metadata: { tokens: number } }\n *\n * type HumanProperties = $InferMessageProperties<MyStructure, \"human\">;\n * // HumanProperties = { metadata: Record<string, unknown> }\n *\n * type SystemProperties = $InferMessageProperties<MyStructure, \"system\">;\n * // SystemProperties = Record<string, unknown> (fallback for undefined role)\n * ```\n */\nexport type $InferMessageProperties<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = $NormalizedMessageStructure<TStructure> extends infer S\n ? S extends MessageStructure\n ? S[\"properties\"] extends infer P | undefined\n ? P extends Record<PropertyKey, unknown>\n ? TRole extends keyof P\n ? Omit<P[TRole], \"content\" | \"type\">\n : Record<string, unknown>\n : Record<string, unknown>\n : Record<string, unknown>\n : never\n : never;\n\n/**\n * Infers the type of a specific property for a message type from a message structure.\n *\n * This utility type extracts the type of a single property by name from the properties\n * object that corresponds to a given message type. If the specified property key does\n * not exist in the type's properties, it returns `never`.\n *\n * @template TStructure - The message structure to infer the property from\n * @template TRole - The message type/role to get the property for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @template K - The property key to extract the type for\n * @returns The type of the specified property, or `never` if the property doesn't exist\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number };\n * usage_metadata: { input_tokens: number; output_tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type ResponseMetadata = $InferMessageProperty<MyStructure, \"ai\", \"response_metadata\">;\n * // ResponseMetadata = { model: string; temperature: number }\n *\n * type UsageMetadata = $InferMessageProperty<MyStructure, \"ai\", \"usage_metadata\">;\n * // UsageMetadata = { input_tokens: number; output_tokens: number }\n *\n * type NonExistentProperty = $InferMessageProperty<MyStructure, \"ai\", \"nonExistent\">;\n * // NonExistentProperty = Record<string, unknown>\n *\n * type HumanMetadata = $InferMessageProperty<MyStructure, \"human\", \"metadata\">;\n * // HumanMetadata = Record<string, unknown>\n * ```\n */\nexport type $InferMessageProperty<\n TStructure extends MessageStructure,\n TRole extends MessageType,\n K extends string\n> = K extends keyof $InferMessageProperties<TStructure, TRole>\n ? $InferMessageProperties<TStructure, TRole>[K]\n : never;\n\n/**\n * Infers the response metadata type for a specific message type from a message structure.\n *\n * This utility type extracts the `response_metadata` property type for a given message type.\n *\n * @template TStructure - The message structure to infer the response metadata from\n * @template TRole - The message type/role to get the response metadata for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The type of the response_metadata property, or `Record<string, unknown>` as fallback\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number; tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIResponseMetadata = $InferResponseMetadata<MyStructure, \"ai\">;\n * // AIResponseMetadata = { model: string; temperature: number; tokens: number }\n *\n * type HumanResponseMetadata = $InferResponseMetadata<MyStructure, \"human\">;\n * // HumanResponseMetadata = Record<string, unknown> (fallback since not defined)\n * ```\n */\nexport type $InferResponseMetadata<\n TStructure extends MessageStructure,\n TRole extends MessageType\n> = $InferMessageProperty<\n TStructure,\n TRole,\n \"response_metadata\"\n> extends infer P\n ? [P] extends [never]\n ? Record<string, unknown>\n : P\n : never;\n\n/**\n * Represents a message object that organizes context for an LLM.\n *\n * @example\n * ```ts\n * // Basic message with text content\n * const message: Message = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"human\",\n * content: [{ type: \"text\", text: \"Hello!\" }]\n * };\n *\n * // Basic ai message interface extension\n * interface MyMessage extends Message<StandardMessageStructure, \"ai\"> {\n * // Additional AI-specific properties can be added here\n * }\n *`\n * // Custom message structure\n * interface CustomStructure extends MessageStructure {\n * content: {\n * ai: ContentBlock.Text | ContentBlock.ToolCall<\"search\", { query: string }>;\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * };\n * }\n *\n * // Create a message with custom structure\n * const message: Message<CustomStructure> = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"ai\",\n * content: [\n * { type: \"text\", text: \"Hello!\" },\n * {\n * type: \"tool_call\",\n * name: \"search\",\n * args: { query: \"What is the capital of France?\" }\n * }\n * ]\n * };\n * ```\n */\nexport interface Message<\n TStructure extends MessageStructure = StandardMessageStructure,\n TRole extends MessageType = MessageType\n> {\n /** The message type/role */\n readonly type: TRole;\n /** Unique identifier for this message */\n id?: string;\n /** Optional name/identifier for the entity that created this message */\n name?: string;\n /** Array of content blocks that make up the message content */\n content: $InferMessageContent<TStructure, TRole>;\n /** Metadata about the message */\n response_metadata?: Partial<$InferResponseMetadata<TStructure, TRole>>;\n}\n\n/**\n * Type guard to check if a value is a valid Message object.\n *\n * @param message - The value to check\n * @returns true if the value is a valid Message object, false otherwise\n */\nexport function isMessage(message: unknown): message is Message {\n return (\n typeof message === \"object\" &&\n message !== null &&\n \"type\" in message &&\n \"content\" in message &&\n (typeof message.content === \"string\" || Array.isArray(message.content))\n );\n}\n"],"mappings":";;;;;;;;AAitBA,SAAgB,UAAUA,SAAsC;AAC9D,QACE,OAAO,YAAY,YACnB,YAAY,QACZ,UAAU,WACV,aAAa,YACZ,OAAO,QAAQ,YAAY,YAAY,MAAM,QAAQ,QAAQ,QAAQ;AAEzE"}
@@ -331,21 +331,21 @@ interface StandardMessageStructure extends MessageStructure {
331
331
  /** Properties specific to AI messages */
332
332
  ai: {
333
333
  /** Metadata about the AI model response */
334
- response_metadata?: ResponseMetadata;
334
+ response_metadata: ResponseMetadata;
335
335
  /** Usage statistics for the AI response */
336
- usage_metadata?: UsageMetadata;
336
+ usage_metadata: UsageMetadata;
337
337
  };
338
338
  human: {
339
339
  /** Metadata about the human message */
340
- response_metadata?: Record<string, unknown>;
340
+ response_metadata: Record<string, unknown>;
341
341
  };
342
342
  system: {
343
343
  /** Metadata about the system message */
344
- response_metadata?: Record<string, unknown>;
344
+ response_metadata: Record<string, unknown>;
345
345
  };
346
346
  tool: {
347
347
  /** Metadata about the tool message */
348
- response_metadata?: Record<string, unknown>;
348
+ response_metadata: Record<string, unknown>;
349
349
  };
350
350
  };
351
351
  }
@@ -531,7 +531,7 @@ type $InferMessageProperty<TStructure extends MessageStructure, TRole extends Me
531
531
  * // HumanResponseMetadata = Record<string, unknown> (fallback since not defined)
532
532
  * ```
533
533
  */
534
- type $InferResponseMetadata<TStructure extends MessageStructure, TRole extends MessageType> = $InferMessageProperty<TStructure, TRole, "response_metadata"> extends infer P ? [P] extends [unknown] ? Record<string, unknown> : P : never;
534
+ type $InferResponseMetadata<TStructure extends MessageStructure, TRole extends MessageType> = $InferMessageProperty<TStructure, TRole, "response_metadata"> extends infer P ? [P] extends [never] ? Record<string, unknown> : P : never;
535
535
  /**
536
536
  * Represents a message object that organizes context for an LLM.
537
537
  *
@@ -1 +1 @@
1
- {"version":3,"file":"message.d.cts","names":["ContentBlock","ResponseMetadata","UsageMetadata","$MergeDiscriminatedUnion","$MergeObjects","MessageType","NonNullable","MessageOutputVersion","MessageToolDefinition","TInput","TOutput","MessageToolSet","$MessageToolCallBlock","MessageStructure","TStructure","K","Tools","ToolCall","Partial","Record","$NormalizeMessageOutputVersion","T","Extract","$MergeOutputVersion","U","TV","UV","Exclude","$MergeContentDefinition","$MergeMessageStructure","StandardMessageStructure","Text","$NormalizedMessageStructure","$InferMessageContentBlocks","S","C","PropertyKey","TRole","$InferMessageContent","Array","$InferMessageProperties","P","Omit","$InferMessageProperty","$InferResponseMetadata","Message","isMessage"],"sources":["../../src/messages/message.d.ts"],"sourcesContent":["import type { ContentBlock } from \"./content/index.js\";\nimport type { ResponseMetadata, UsageMetadata } from \"./metadata.js\";\nimport type { $MergeDiscriminatedUnion, $MergeObjects } from \"./utils.js\";\n/**\n * Represents the possible types of messages in the system.\n * Includes standard message types (\"ai\", \"human\", \"tool\", \"system\")\n * and allows for custom string types that are non-null.\n *\n * @example\n * ```ts\n * // Standard message types\n * const messageType1: MessageType = \"ai\";\n * const messageType2: MessageType = \"human\";\n *\n * // Custom message type\n * const messageType3: MessageType = \"custom_type\";\n * ```\n */\nexport type MessageType = \"ai\" | \"human\" | \"tool\" | \"system\" | (string & NonNullable<unknown>);\n/**\n * Represents the output version format for message content.\n *\n * This type determines how the content field is structured in a message:\n * - \"v0\": Content is represented as a simple string or array of content blocks\n * - provides backward compatibility with simpler content representations\n * - \"v1\": Content follows the structured ContentBlock format with typed discriminated unions\n * - enables full type safety and structured content block handling\n *\n * @example\n * ```ts\n * // v0 format - simple content representation\n * const v0Message: Message<{ outputVersion: \"v0\", content: ... }> = {\n * type: \"human\",\n * content: \"Hello world\" // string | Array<ContentBlock | ContentBlock.Text>\n * };\n *\n * // v1 format - structured content blocks\n * const v1Message: Message<{ outputVersion: \"v1\", content: ... }> = {\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image\", image_url: \"...\" }\n * ] // Array<ContentBlock | ...> (determined by the structure)\n * };\n * ```\n */\nexport type MessageOutputVersion = \"v0\" | \"v1\";\n/**\n * Represents the input and output types of a tool that can be used in messages.\n *\n * @template TInput - The type of input the tool accepts.\n * @template TOutput - The type of output the tool produces.\n *\n * @example\n * ```ts\n * // Tool that takes a string input and returns a number\n * interface StringToNumberTool extends MessageToolDefinition<string, number> {\n * input: string;\n * output: number;\n * }\n * ```\n */\nexport interface MessageToolDefinition<TInput = unknown, TOutput = unknown> {\n input: TInput;\n output: TOutput;\n}\n/**\n * Represents a structured set of tools by mapping tool names to definitions\n * that can be used in messages.\n *\n * @example\n * ```ts\n * interface MyToolSet extends MessageToolSet {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * translator: MessageToolDefinition<\n * { text: string; targetLanguage: string },\n * string\n * >;\n * }\n * ```\n */\nexport interface MessageToolSet {\n [key: string]: MessageToolDefinition;\n}\n/**\n * Represents a tool call block within a message structure by mapping tool names to their\n * corresponding tool call formats, including the input arguments and an optional identifier.\n *\n * @template TStructure - A message structure type that may contain tool definitions\n *\n * @example\n * ```ts\n * // Given a message structure with a calculator tool:\n * interface MyStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<{ operation: string, numbers: number[] }, number>\n * }\n * }\n *\n * // The tool call block would be:\n * type CalcToolCall = $MessageToolCallBlock<MyStructure>;\n * // Resolves to:\n * // {\n * // type: \"tool_call\";\n * // name: \"calculator\";\n * // args: { operation: string, numbers: number[] };\n * // id?: string;\n * // }\n * ```\n */\nexport type $MessageToolCallBlock<TStructure extends MessageStructure> = TStructure[\"tools\"] extends MessageToolSet ? {\n [K in keyof TStructure[\"tools\"]]: K extends string ? TStructure[\"tools\"][K] extends MessageToolDefinition ? ContentBlock.Tools.ToolCall<K, TStructure[\"tools\"][K][\"input\"]> : never : never;\n}[keyof TStructure[\"tools\"]] : never;\n/**\n * Core interface that defines the structure of messages.\n *\n * @example\n * ```ts\n * // Basic message structure with just content blocks\n * interface SimpleMessageStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * // allows for text + reasoning blocks in ai messages\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * }\n * }\n *\n * // Message structure with tools and properties\n * interface AdvancedMessageStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * };\n * content: {\n * // allows for text + image blocks in human messages\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // only allows for text blocks in ai messages\n * ai: ContentBlock.Text;\n * };\n * properties: {\n * // pins properties to ai messages\n * ai: {\n * response_metadata: {\n * confidence: number;\n * model: string;\n * };\n * };\n * }\n * }\n *\n * // Using with $MergeMessageStructure to combine structures\n * // The resulting type when passed into BaseMessage will have a calculator tool,\n * // allow for text + image blocks in human messages,\n * // and text + reasoning blocks + additional arbitrary properties in ai messages.\n * type CombinedStructure = $MergeMessageStructure<\n * SimpleMessageStructure,\n * AdvancedMessageStructure\n * >;\n *\n * // Using in a Message object\n * const message: Message<CombinedStructure> = {\n * id: \"msg-123\",\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello!\" }\n * { type: \"image\", mimeType: \"image/jpeg\", url: \"https://example.com/image.jpg\" }\n * // this block will throw an error because it's not defined in the structure\n * { type: \"reasoning\", reasoning: \"The answer is 42\" }\n * ]\n * };\n * ```\n */\nexport interface MessageStructure {\n /**\n * Optional output version for the message structure.\n * If not provided, defaults to \"v0\".\n */\n readonly outputVersion?: MessageOutputVersion;\n /**\n * Optional set of tool definitions that can be used in messages.\n * Each tool is defined with input/output types and can be referenced in tool messages.\n */\n readonly tools?: MessageToolSet;\n /**\n * Optional mapping of message types to their allowed content blocks.\n * Each message type can specify what content block types it supports (text, images, etc).\n */\n readonly content?: Partial<{\n [key in MessageType]: ContentBlock;\n }>;\n /**\n * Optional mapping of message types to arbitrary property objects.\n * Allows attaching custom metadata or other information to specific message types.\n */\n readonly properties?: Partial<{\n [key in MessageType]: Record<string, unknown>;\n }>;\n}\n/**\n * Normalizes an arbitrary type to a message output version or undefined.\n * Accepts unknown and narrows to a valid MessageOutputVersion if present.\n */\ntype $NormalizeMessageOutputVersion<T> = Extract<T, MessageOutputVersion> | undefined;\n/**\n * Merges two output version types from message structures.\n *\n * This utility type determines the resulting output version when combining two message structures.\n * The merge logic follows these rules:\n *\n * - If both T and U are undefined, defaults to \"v0\" for backwards compatibility\n * - If T is undefined but U is defined, uses U's version\n * - If U is undefined but T is defined, uses T's version\n * - If both T and U are defined, U takes precedence (later structure wins)\n *\n * @template T - The output version from the first message structure\n * @template U - The output version from the second message structure\n *\n * @example\n * ```ts\n * // Both undefined - defaults to \"v0\"\n * type Result1 = $MergeOutputVersion<undefined, undefined>; // \"v0\"\n *\n * // One defined - uses the defined version\n * type Result2 = $MergeOutputVersion<undefined, \"v1\">; // \"v1\"\n * type Result3 = $MergeOutputVersion<\"v0\", undefined>; // \"v0\"\n *\n * // Both defined - second takes precedence\n * type Result4 = $MergeOutputVersion<\"v0\", \"v1\">; // \"v1\"\n * ```\n */\nexport type $MergeOutputVersion<T, U> = $NormalizeMessageOutputVersion<T> extends infer TV ? $NormalizeMessageOutputVersion<U> extends infer UV ? [TV, UV] extends [undefined, undefined] ? \"v0\" : [TV] extends [undefined] ? Exclude<UV, undefined> : [UV] extends [undefined] ? Exclude<TV, undefined> : UV : never : never;\n/**\n * Merges two content definition objects from message structures.\n *\n * This utility type combines content definitions from two message structures, handling\n * the merging of content block types for each message type. The merge logic follows\n * these rules:\n *\n * - For keys that exist in both T and U: Merges the content blocks using discriminated\n * union merging based on the \"type\" property. This allows combining different content\n * block types (e.g., text + image) for the same message type.\n * - For keys that exist only in T: Uses T's content definition as-is\n * - For keys that exist only in U: Uses U's content definition as-is\n *\n * @template T - The content definition from the first message structure\n * @template U - The content definition from the second message structure\n *\n * @example\n * ```ts\n * // T allows text content for human messages\n * type ContentA = {\n * human: ContentBlock.Text;\n * };\n *\n * // U allows image content for human messages and text for AI messages\n * type ContentB = {\n * human: ContentBlock.Multimodal.Image;\n * ai: ContentBlock.Text;\n * };\n *\n * // Merged result allows both text and images for human messages, text for AI\n * type Merged = $MergeContentDefinition<ContentA, ContentB>;\n * // Result: {\n * // human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // ai: ContentBlock.Text;\n * // }\n * ```\n */\nexport type $MergeContentDefinition<T, U> = {\n [K in keyof T | keyof U as Extract<(K extends keyof T ? T[K] : never) | (K extends keyof U ? U[K] : never), ContentBlock> extends never ? never : K]: K extends keyof T ? K extends keyof U ? $MergeDiscriminatedUnion<Extract<T[K], ContentBlock>, Extract<U[K], ContentBlock>, \"type\"> : Extract<T[K], ContentBlock> : K extends keyof U ? Extract<U[K], ContentBlock> : never;\n};\n/**\n * Merges two message structures A and B into a combined structure.\n * This is a type utility that handles merging of tools, content blocks, and properties\n * from two message structures. The resulting type is usable as its own message structure.\n *\n * @example\n * ```ts\n * // Structure A allows text in human messages and has a confidence property on AI messages\n * interface StructureA extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * };\n * properties: {\n * ai: { confidence: number };\n * }\n * }\n *\n * // Structure B allows images in human messages and has a model property on AI messages\n * interface StructureB extends MessageStructure {\n * content: {\n * human: ContentBlock.Multimodal.Image;\n * };\n * properties: {\n * ai: { model: string };\n * }\n * }\n *\n * // Merged structure allows both text and images in human messages\n * // AI messages have both confidence and model properties\n * type Merged = $MergeMessageStructure<StructureA, StructureB>;\n * ```\n *\n * @template A - First message structure to merge\n * @template B - Second message structure to merge (takes precedence over A)\n */\nexport type $MergeMessageStructure<T extends MessageStructure, U extends MessageStructure> = {\n outputVersion: $MergeOutputVersion<T[\"outputVersion\"], U[\"outputVersion\"]>;\n tools: $MergeObjects<T[\"tools\"], U[\"tools\"]>;\n content: $MergeContentDefinition<T[\"content\"], U[\"content\"]>;\n properties: $MergeObjects<T[\"properties\"], U[\"properties\"]>;\n};\n/**\n * Standard message structured used to define the most basic message structure that's\n * used throughout the library.\n *\n * This is also the message structure that's used when a message structure is not provided.\n */\nexport interface StandardMessageStructure extends MessageStructure {\n content: {\n /** Text content for AI messages */\n ai: ContentBlock.Text;\n /** Text content for human messages */\n human: ContentBlock.Text;\n /** Text content for system messages */\n system: ContentBlock.Text;\n /** Text content for tool messages */\n tool: ContentBlock.Text;\n };\n properties: {\n /** Properties specific to AI messages */\n ai: {\n /** Metadata about the AI model response */\n response_metadata?: ResponseMetadata;\n /** Usage statistics for the AI response */\n usage_metadata?: UsageMetadata;\n };\n human: {\n /** Metadata about the human message */\n response_metadata?: Record<string, unknown>;\n };\n system: {\n /** Metadata about the system message */\n response_metadata?: Record<string, unknown>;\n };\n tool: {\n /** Metadata about the tool message */\n response_metadata?: Record<string, unknown>;\n };\n };\n}\n/**\n * Takes a message structure type T and normalizes it by merging it with the standard message structure.\n * If T is already a standard message structure, returns T unchanged.\n *\n * This ensures that any custom message structure includes all the standard message structure fields\n * by default while allowing overrides and extensions.\n *\n * @template T - The message structure type to normalize, must extend MessageStructure\n * @returns Either T if it's already a standard structure, or the merged result of T with standard structure\n */\nexport type $NormalizedMessageStructure<T extends MessageStructure> = T extends StandardMessageStructure ? T : $MergeMessageStructure<StandardMessageStructure, T>;\n/**\n * Infers the content blocks for a specific message type in a message structure.\n *\n * This utility type extracts the content block type that corresponds to a given message type\n * from the message structure's content definition.\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content block type for the specified type, or never if its not defined in the structure\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContent = $InferMessageContentBlocks<MyStructure, \"human\">;\n * // HumanContent = ContentBlock.Text\n *\n * type AIContent = $InferMessageContentBlocks<MyStructure, \"ai\">;\n * // AIContent = ContentBlock.Text | ContentBlock.ToolCall\n * ```\n */\nexport type $InferMessageContentBlocks<TStructure extends MessageStructure, TRole extends MessageType> = $NormalizedMessageStructure<TStructure> extends infer S ? S extends MessageStructure ? S[\"content\"] extends infer C ? C extends Record<PropertyKey, ContentBlock> ? TRole extends keyof C ? [$MessageToolCallBlock<TStructure>] extends [never] ? C[TRole] : $MergeDiscriminatedUnion<NonNullable<C[TRole]>, $MessageToolCallBlock<TStructure>, \"type\"> : never : never : never : never : never;\n/**\n * Infers the content type for a specific message type from a message structure.\n *\n * This utility type determines the appropriate content type based on the message structure's\n * output version and the specified message type. The content type varies depending on the\n * output version (see {@link MessageOutputVersion})\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content type for the specified role based on the output version\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * outputVersion: \"v0\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContentV0 = $InferMessageContent<MyStructure, \"human\">;\n * // HumanContentV0 = string | Array<ContentBlock | ContentBlock.Text>\n *\n * interface MyStructureV1 extends MessageStructure {\n * outputVersion: \"v1\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * };\n * }\n *\n * type HumanContentV1 = $InferMessageContent<MyStructureV1, \"human\">;\n * // HumanContentV1 = ContentBlock.Text\n *\n * type AIContentV1 = $InferMessageContent<MyStructureV1, \"ai\">;\n * // AIContentV1 = ContentBlock.Text | ContentBlock.Reasoning\n * ```\n */\nexport type $InferMessageContent<TStructure extends MessageStructure, TRole extends MessageType> = TStructure[\"outputVersion\"] extends \"v1\" ? Array<$InferMessageContentBlocks<TStructure, TRole>> : string | Array<ContentBlock | ContentBlock.Text>;\n/**\n * Infers the properties for a specific message type from a message structure.\n *\n * This utility type extracts the properties object that corresponds to a given message type\n * from the message structure's properties definition, and excludes the reserved\n * \"content\" and \"type\" properties to avoid conflicts with the core message structure.\n *\n * If the specified type is not defined in the message structure's properties, it returns\n * a generic Record<string, unknown> type to allow for arbitrary properties.\n *\n * @template TStructure - The message structure to infer properties from\n * @template TRole - The message type/role to get properties for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The properties object type for the specified type, excluding \"content\" and \"type\"\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string };\n * usage_metadata: { tokens: number };\n * content: string; // This will be omitted\n * type: string; // This will be omitted\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIProperties = $InferMessageProperties<MyStructure, \"ai\">;\n * // AIProperties = { response_metadata: { model: string }; usage_metadata: { tokens: number } }\n *\n * type HumanProperties = $InferMessageProperties<MyStructure, \"human\">;\n * // HumanProperties = { metadata: Record<string, unknown> }\n *\n * type SystemProperties = $InferMessageProperties<MyStructure, \"system\">;\n * // SystemProperties = Record<string, unknown> (fallback for undefined role)\n * ```\n */\nexport type $InferMessageProperties<TStructure extends MessageStructure, TRole extends MessageType> = $NormalizedMessageStructure<TStructure> extends infer S ? S extends MessageStructure ? S[\"properties\"] extends infer P | undefined ? P extends Record<PropertyKey, unknown> ? TRole extends keyof P ? Omit<P[TRole], \"content\" | \"type\"> : Record<string, unknown> : Record<string, unknown> : Record<string, unknown> : never : never;\n/**\n * Infers the type of a specific property for a message type from a message structure.\n *\n * This utility type extracts the type of a single property by name from the properties\n * object that corresponds to a given message type. If the specified property key does\n * not exist in the type's properties, it returns `never`.\n *\n * @template TStructure - The message structure to infer the property from\n * @template TRole - The message type/role to get the property for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @template K - The property key to extract the type for\n * @returns The type of the specified property, or `never` if the property doesn't exist\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number };\n * usage_metadata: { input_tokens: number; output_tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type ResponseMetadata = $InferMessageProperty<MyStructure, \"ai\", \"response_metadata\">;\n * // ResponseMetadata = { model: string; temperature: number }\n *\n * type UsageMetadata = $InferMessageProperty<MyStructure, \"ai\", \"usage_metadata\">;\n * // UsageMetadata = { input_tokens: number; output_tokens: number }\n *\n * type NonExistentProperty = $InferMessageProperty<MyStructure, \"ai\", \"nonExistent\">;\n * // NonExistentProperty = Record<string, unknown>\n *\n * type HumanMetadata = $InferMessageProperty<MyStructure, \"human\", \"metadata\">;\n * // HumanMetadata = Record<string, unknown>\n * ```\n */\nexport type $InferMessageProperty<TStructure extends MessageStructure, TRole extends MessageType, K extends string> = K extends keyof $InferMessageProperties<TStructure, TRole> ? $InferMessageProperties<TStructure, TRole>[K] : never;\n/**\n * Infers the response metadata type for a specific message type from a message structure.\n *\n * This utility type extracts the `response_metadata` property type for a given message type.\n *\n * @template TStructure - The message structure to infer the response metadata from\n * @template TRole - The message type/role to get the response metadata for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The type of the response_metadata property, or `Record<string, unknown>` as fallback\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number; tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIResponseMetadata = $InferResponseMetadata<MyStructure, \"ai\">;\n * // AIResponseMetadata = { model: string; temperature: number; tokens: number }\n *\n * type HumanResponseMetadata = $InferResponseMetadata<MyStructure, \"human\">;\n * // HumanResponseMetadata = Record<string, unknown> (fallback since not defined)\n * ```\n */\nexport type $InferResponseMetadata<TStructure extends MessageStructure, TRole extends MessageType> = $InferMessageProperty<TStructure, TRole, \"response_metadata\"> extends infer P ? [P] extends [unknown] ? Record<string, unknown> : P : never;\n/**\n * Represents a message object that organizes context for an LLM.\n *\n * @example\n * ```ts\n * // Basic message with text content\n * const message: Message = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"human\",\n * content: [{ type: \"text\", text: \"Hello!\" }]\n * };\n *\n * // Basic ai message interface extension\n * interface MyMessage extends Message<StandardMessageStructure, \"ai\"> {\n * // Additional AI-specific properties can be added here\n * }\n *`\n * // Custom message structure\n * interface CustomStructure extends MessageStructure {\n * content: {\n * ai: ContentBlock.Text | ContentBlock.ToolCall<\"search\", { query: string }>;\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * };\n * }\n *\n * // Create a message with custom structure\n * const message: Message<CustomStructure> = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"ai\",\n * content: [\n * { type: \"text\", text: \"Hello!\" },\n * {\n * type: \"tool_call\",\n * name: \"search\",\n * args: { query: \"What is the capital of France?\" }\n * }\n * ]\n * };\n * ```\n */\nexport interface Message<TStructure extends MessageStructure = StandardMessageStructure, TRole extends MessageType = MessageType> {\n /** The message type/role */\n readonly type: TRole;\n /** Unique identifier for this message */\n id?: string;\n /** Optional name/identifier for the entity that created this message */\n name?: string;\n /** Array of content blocks that make up the message content */\n content: $InferMessageContent<TStructure, TRole>;\n /** Metadata about the message */\n response_metadata?: Partial<$InferResponseMetadata<TStructure, TRole>>;\n}\n/**\n * Type guard to check if a value is a valid Message object.\n *\n * @param message - The value to check\n * @returns true if the value is a valid Message object, false otherwise\n */\nexport declare function isMessage(message: unknown): message is Message;\nexport {};\n"],"mappings":"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"}
1
+ {"version":3,"file":"message.d.cts","names":["ContentBlock","ResponseMetadata","UsageMetadata","$MergeDiscriminatedUnion","$MergeObjects","MessageType","NonNullable","MessageOutputVersion","MessageToolDefinition","TInput","TOutput","MessageToolSet","$MessageToolCallBlock","MessageStructure","TStructure","K","Tools","ToolCall","Partial","Record","$NormalizeMessageOutputVersion","T","Extract","$MergeOutputVersion","U","TV","UV","Exclude","$MergeContentDefinition","$MergeMessageStructure","StandardMessageStructure","Text","$NormalizedMessageStructure","$InferMessageContentBlocks","S","C","PropertyKey","TRole","$InferMessageContent","Array","$InferMessageProperties","P","Omit","$InferMessageProperty","$InferResponseMetadata","Message","isMessage"],"sources":["../../src/messages/message.d.ts"],"sourcesContent":["import type { ContentBlock } from \"./content/index.js\";\nimport type { ResponseMetadata, UsageMetadata } from \"./metadata.js\";\nimport type { $MergeDiscriminatedUnion, $MergeObjects } from \"./utils.js\";\n/**\n * Represents the possible types of messages in the system.\n * Includes standard message types (\"ai\", \"human\", \"tool\", \"system\")\n * and allows for custom string types that are non-null.\n *\n * @example\n * ```ts\n * // Standard message types\n * const messageType1: MessageType = \"ai\";\n * const messageType2: MessageType = \"human\";\n *\n * // Custom message type\n * const messageType3: MessageType = \"custom_type\";\n * ```\n */\nexport type MessageType = \"ai\" | \"human\" | \"tool\" | \"system\" | (string & NonNullable<unknown>);\n/**\n * Represents the output version format for message content.\n *\n * This type determines how the content field is structured in a message:\n * - \"v0\": Content is represented as a simple string or array of content blocks\n * - provides backward compatibility with simpler content representations\n * - \"v1\": Content follows the structured ContentBlock format with typed discriminated unions\n * - enables full type safety and structured content block handling\n *\n * @example\n * ```ts\n * // v0 format - simple content representation\n * const v0Message: Message<{ outputVersion: \"v0\", content: ... }> = {\n * type: \"human\",\n * content: \"Hello world\" // string | Array<ContentBlock | ContentBlock.Text>\n * };\n *\n * // v1 format - structured content blocks\n * const v1Message: Message<{ outputVersion: \"v1\", content: ... }> = {\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello world\" },\n * { type: \"image\", image_url: \"...\" }\n * ] // Array<ContentBlock | ...> (determined by the structure)\n * };\n * ```\n */\nexport type MessageOutputVersion = \"v0\" | \"v1\";\n/**\n * Represents the input and output types of a tool that can be used in messages.\n *\n * @template TInput - The type of input the tool accepts.\n * @template TOutput - The type of output the tool produces.\n *\n * @example\n * ```ts\n * // Tool that takes a string input and returns a number\n * interface StringToNumberTool extends MessageToolDefinition<string, number> {\n * input: string;\n * output: number;\n * }\n * ```\n */\nexport interface MessageToolDefinition<TInput = unknown, TOutput = unknown> {\n input: TInput;\n output: TOutput;\n}\n/**\n * Represents a structured set of tools by mapping tool names to definitions\n * that can be used in messages.\n *\n * @example\n * ```ts\n * interface MyToolSet extends MessageToolSet {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * translator: MessageToolDefinition<\n * { text: string; targetLanguage: string },\n * string\n * >;\n * }\n * ```\n */\nexport interface MessageToolSet {\n [key: string]: MessageToolDefinition;\n}\n/**\n * Represents a tool call block within a message structure by mapping tool names to their\n * corresponding tool call formats, including the input arguments and an optional identifier.\n *\n * @template TStructure - A message structure type that may contain tool definitions\n *\n * @example\n * ```ts\n * // Given a message structure with a calculator tool:\n * interface MyStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<{ operation: string, numbers: number[] }, number>\n * }\n * }\n *\n * // The tool call block would be:\n * type CalcToolCall = $MessageToolCallBlock<MyStructure>;\n * // Resolves to:\n * // {\n * // type: \"tool_call\";\n * // name: \"calculator\";\n * // args: { operation: string, numbers: number[] };\n * // id?: string;\n * // }\n * ```\n */\nexport type $MessageToolCallBlock<TStructure extends MessageStructure> = TStructure[\"tools\"] extends MessageToolSet ? {\n [K in keyof TStructure[\"tools\"]]: K extends string ? TStructure[\"tools\"][K] extends MessageToolDefinition ? ContentBlock.Tools.ToolCall<K, TStructure[\"tools\"][K][\"input\"]> : never : never;\n}[keyof TStructure[\"tools\"]] : never;\n/**\n * Core interface that defines the structure of messages.\n *\n * @example\n * ```ts\n * // Basic message structure with just content blocks\n * interface SimpleMessageStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * // allows for text + reasoning blocks in ai messages\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * }\n * }\n *\n * // Message structure with tools and properties\n * interface AdvancedMessageStructure extends MessageStructure {\n * tools: {\n * calculator: MessageToolDefinition<\n * { operation: string; numbers: number[] },\n * number\n * >;\n * };\n * content: {\n * // allows for text + image blocks in human messages\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // only allows for text blocks in ai messages\n * ai: ContentBlock.Text;\n * };\n * properties: {\n * // pins properties to ai messages\n * ai: {\n * response_metadata: {\n * confidence: number;\n * model: string;\n * };\n * };\n * }\n * }\n *\n * // Using with $MergeMessageStructure to combine structures\n * // The resulting type when passed into BaseMessage will have a calculator tool,\n * // allow for text + image blocks in human messages,\n * // and text + reasoning blocks + additional arbitrary properties in ai messages.\n * type CombinedStructure = $MergeMessageStructure<\n * SimpleMessageStructure,\n * AdvancedMessageStructure\n * >;\n *\n * // Using in a Message object\n * const message: Message<CombinedStructure> = {\n * id: \"msg-123\",\n * type: \"human\",\n * content: [\n * { type: \"text\", text: \"Hello!\" }\n * { type: \"image\", mimeType: \"image/jpeg\", url: \"https://example.com/image.jpg\" }\n * // this block will throw an error because it's not defined in the structure\n * { type: \"reasoning\", reasoning: \"The answer is 42\" }\n * ]\n * };\n * ```\n */\nexport interface MessageStructure {\n /**\n * Optional output version for the message structure.\n * If not provided, defaults to \"v0\".\n */\n readonly outputVersion?: MessageOutputVersion;\n /**\n * Optional set of tool definitions that can be used in messages.\n * Each tool is defined with input/output types and can be referenced in tool messages.\n */\n readonly tools?: MessageToolSet;\n /**\n * Optional mapping of message types to their allowed content blocks.\n * Each message type can specify what content block types it supports (text, images, etc).\n */\n readonly content?: Partial<{\n [key in MessageType]: ContentBlock;\n }>;\n /**\n * Optional mapping of message types to arbitrary property objects.\n * Allows attaching custom metadata or other information to specific message types.\n */\n readonly properties?: Partial<{\n [key in MessageType]: Record<string, unknown>;\n }>;\n}\n/**\n * Normalizes an arbitrary type to a message output version or undefined.\n * Accepts unknown and narrows to a valid MessageOutputVersion if present.\n */\ntype $NormalizeMessageOutputVersion<T> = Extract<T, MessageOutputVersion> | undefined;\n/**\n * Merges two output version types from message structures.\n *\n * This utility type determines the resulting output version when combining two message structures.\n * The merge logic follows these rules:\n *\n * - If both T and U are undefined, defaults to \"v0\" for backwards compatibility\n * - If T is undefined but U is defined, uses U's version\n * - If U is undefined but T is defined, uses T's version\n * - If both T and U are defined, U takes precedence (later structure wins)\n *\n * @template T - The output version from the first message structure\n * @template U - The output version from the second message structure\n *\n * @example\n * ```ts\n * // Both undefined - defaults to \"v0\"\n * type Result1 = $MergeOutputVersion<undefined, undefined>; // \"v0\"\n *\n * // One defined - uses the defined version\n * type Result2 = $MergeOutputVersion<undefined, \"v1\">; // \"v1\"\n * type Result3 = $MergeOutputVersion<\"v0\", undefined>; // \"v0\"\n *\n * // Both defined - second takes precedence\n * type Result4 = $MergeOutputVersion<\"v0\", \"v1\">; // \"v1\"\n * ```\n */\nexport type $MergeOutputVersion<T, U> = $NormalizeMessageOutputVersion<T> extends infer TV ? $NormalizeMessageOutputVersion<U> extends infer UV ? [TV, UV] extends [undefined, undefined] ? \"v0\" : [TV] extends [undefined] ? Exclude<UV, undefined> : [UV] extends [undefined] ? Exclude<TV, undefined> : UV : never : never;\n/**\n * Merges two content definition objects from message structures.\n *\n * This utility type combines content definitions from two message structures, handling\n * the merging of content block types for each message type. The merge logic follows\n * these rules:\n *\n * - For keys that exist in both T and U: Merges the content blocks using discriminated\n * union merging based on the \"type\" property. This allows combining different content\n * block types (e.g., text + image) for the same message type.\n * - For keys that exist only in T: Uses T's content definition as-is\n * - For keys that exist only in U: Uses U's content definition as-is\n *\n * @template T - The content definition from the first message structure\n * @template U - The content definition from the second message structure\n *\n * @example\n * ```ts\n * // T allows text content for human messages\n * type ContentA = {\n * human: ContentBlock.Text;\n * };\n *\n * // U allows image content for human messages and text for AI messages\n * type ContentB = {\n * human: ContentBlock.Multimodal.Image;\n * ai: ContentBlock.Text;\n * };\n *\n * // Merged result allows both text and images for human messages, text for AI\n * type Merged = $MergeContentDefinition<ContentA, ContentB>;\n * // Result: {\n * // human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * // ai: ContentBlock.Text;\n * // }\n * ```\n */\nexport type $MergeContentDefinition<T, U> = {\n [K in keyof T | keyof U as Extract<(K extends keyof T ? T[K] : never) | (K extends keyof U ? U[K] : never), ContentBlock> extends never ? never : K]: K extends keyof T ? K extends keyof U ? $MergeDiscriminatedUnion<Extract<T[K], ContentBlock>, Extract<U[K], ContentBlock>, \"type\"> : Extract<T[K], ContentBlock> : K extends keyof U ? Extract<U[K], ContentBlock> : never;\n};\n/**\n * Merges two message structures A and B into a combined structure.\n * This is a type utility that handles merging of tools, content blocks, and properties\n * from two message structures. The resulting type is usable as its own message structure.\n *\n * @example\n * ```ts\n * // Structure A allows text in human messages and has a confidence property on AI messages\n * interface StructureA extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * };\n * properties: {\n * ai: { confidence: number };\n * }\n * }\n *\n * // Structure B allows images in human messages and has a model property on AI messages\n * interface StructureB extends MessageStructure {\n * content: {\n * human: ContentBlock.Multimodal.Image;\n * };\n * properties: {\n * ai: { model: string };\n * }\n * }\n *\n * // Merged structure allows both text and images in human messages\n * // AI messages have both confidence and model properties\n * type Merged = $MergeMessageStructure<StructureA, StructureB>;\n * ```\n *\n * @template A - First message structure to merge\n * @template B - Second message structure to merge (takes precedence over A)\n */\nexport type $MergeMessageStructure<T extends MessageStructure, U extends MessageStructure> = {\n outputVersion: $MergeOutputVersion<T[\"outputVersion\"], U[\"outputVersion\"]>;\n tools: $MergeObjects<T[\"tools\"], U[\"tools\"]>;\n content: $MergeContentDefinition<T[\"content\"], U[\"content\"]>;\n properties: $MergeObjects<T[\"properties\"], U[\"properties\"]>;\n};\n/**\n * Standard message structured used to define the most basic message structure that's\n * used throughout the library.\n *\n * This is also the message structure that's used when a message structure is not provided.\n */\nexport interface StandardMessageStructure extends MessageStructure {\n content: {\n /** Text content for AI messages */\n ai: ContentBlock.Text;\n /** Text content for human messages */\n human: ContentBlock.Text;\n /** Text content for system messages */\n system: ContentBlock.Text;\n /** Text content for tool messages */\n tool: ContentBlock.Text;\n };\n properties: {\n /** Properties specific to AI messages */\n ai: {\n /** Metadata about the AI model response */\n response_metadata: ResponseMetadata;\n /** Usage statistics for the AI response */\n usage_metadata: UsageMetadata;\n };\n human: {\n /** Metadata about the human message */\n response_metadata: Record<string, unknown>;\n };\n system: {\n /** Metadata about the system message */\n response_metadata: Record<string, unknown>;\n };\n tool: {\n /** Metadata about the tool message */\n response_metadata: Record<string, unknown>;\n };\n };\n}\n/**\n * Takes a message structure type T and normalizes it by merging it with the standard message structure.\n * If T is already a standard message structure, returns T unchanged.\n *\n * This ensures that any custom message structure includes all the standard message structure fields\n * by default while allowing overrides and extensions.\n *\n * @template T - The message structure type to normalize, must extend MessageStructure\n * @returns Either T if it's already a standard structure, or the merged result of T with standard structure\n */\nexport type $NormalizedMessageStructure<T extends MessageStructure> = T extends StandardMessageStructure ? T : $MergeMessageStructure<StandardMessageStructure, T>;\n/**\n * Infers the content blocks for a specific message type in a message structure.\n *\n * This utility type extracts the content block type that corresponds to a given message type\n * from the message structure's content definition.\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content block type for the specified type, or never if its not defined in the structure\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContent = $InferMessageContentBlocks<MyStructure, \"human\">;\n * // HumanContent = ContentBlock.Text\n *\n * type AIContent = $InferMessageContentBlocks<MyStructure, \"ai\">;\n * // AIContent = ContentBlock.Text | ContentBlock.ToolCall\n * ```\n */\nexport type $InferMessageContentBlocks<TStructure extends MessageStructure, TRole extends MessageType> = $NormalizedMessageStructure<TStructure> extends infer S ? S extends MessageStructure ? S[\"content\"] extends infer C ? C extends Record<PropertyKey, ContentBlock> ? TRole extends keyof C ? [$MessageToolCallBlock<TStructure>] extends [never] ? C[TRole] : $MergeDiscriminatedUnion<NonNullable<C[TRole]>, $MessageToolCallBlock<TStructure>, \"type\"> : never : never : never : never : never;\n/**\n * Infers the content type for a specific message type from a message structure.\n *\n * This utility type determines the appropriate content type based on the message structure's\n * output version and the specified message type. The content type varies depending on the\n * output version (see {@link MessageOutputVersion})\n *\n * @template TStructure - The message structure to infer content from\n * @template TRole - The message role/type to get content for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The content type for the specified role based on the output version\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * outputVersion: \"v0\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.ToolCall;\n * };\n * }\n *\n * type HumanContentV0 = $InferMessageContent<MyStructure, \"human\">;\n * // HumanContentV0 = string | Array<ContentBlock | ContentBlock.Text>\n *\n * interface MyStructureV1 extends MessageStructure {\n * outputVersion: \"v1\";\n * content: {\n * human: ContentBlock.Text;\n * ai: ContentBlock.Text | ContentBlock.Reasoning;\n * };\n * }\n *\n * type HumanContentV1 = $InferMessageContent<MyStructureV1, \"human\">;\n * // HumanContentV1 = ContentBlock.Text\n *\n * type AIContentV1 = $InferMessageContent<MyStructureV1, \"ai\">;\n * // AIContentV1 = ContentBlock.Text | ContentBlock.Reasoning\n * ```\n */\nexport type $InferMessageContent<TStructure extends MessageStructure, TRole extends MessageType> = TStructure[\"outputVersion\"] extends \"v1\" ? Array<$InferMessageContentBlocks<TStructure, TRole>> : string | Array<ContentBlock | ContentBlock.Text>;\n/**\n * Infers the properties for a specific message type from a message structure.\n *\n * This utility type extracts the properties object that corresponds to a given message type\n * from the message structure's properties definition, and excludes the reserved\n * \"content\" and \"type\" properties to avoid conflicts with the core message structure.\n *\n * If the specified type is not defined in the message structure's properties, it returns\n * a generic Record<string, unknown> type to allow for arbitrary properties.\n *\n * @template TStructure - The message structure to infer properties from\n * @template TRole - The message type/role to get properties for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The properties object type for the specified type, excluding \"content\" and \"type\"\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string };\n * usage_metadata: { tokens: number };\n * content: string; // This will be omitted\n * type: string; // This will be omitted\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIProperties = $InferMessageProperties<MyStructure, \"ai\">;\n * // AIProperties = { response_metadata: { model: string }; usage_metadata: { tokens: number } }\n *\n * type HumanProperties = $InferMessageProperties<MyStructure, \"human\">;\n * // HumanProperties = { metadata: Record<string, unknown> }\n *\n * type SystemProperties = $InferMessageProperties<MyStructure, \"system\">;\n * // SystemProperties = Record<string, unknown> (fallback for undefined role)\n * ```\n */\nexport type $InferMessageProperties<TStructure extends MessageStructure, TRole extends MessageType> = $NormalizedMessageStructure<TStructure> extends infer S ? S extends MessageStructure ? S[\"properties\"] extends infer P | undefined ? P extends Record<PropertyKey, unknown> ? TRole extends keyof P ? Omit<P[TRole], \"content\" | \"type\"> : Record<string, unknown> : Record<string, unknown> : Record<string, unknown> : never : never;\n/**\n * Infers the type of a specific property for a message type from a message structure.\n *\n * This utility type extracts the type of a single property by name from the properties\n * object that corresponds to a given message type. If the specified property key does\n * not exist in the type's properties, it returns `never`.\n *\n * @template TStructure - The message structure to infer the property from\n * @template TRole - The message type/role to get the property for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @template K - The property key to extract the type for\n * @returns The type of the specified property, or `never` if the property doesn't exist\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number };\n * usage_metadata: { input_tokens: number; output_tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type ResponseMetadata = $InferMessageProperty<MyStructure, \"ai\", \"response_metadata\">;\n * // ResponseMetadata = { model: string; temperature: number }\n *\n * type UsageMetadata = $InferMessageProperty<MyStructure, \"ai\", \"usage_metadata\">;\n * // UsageMetadata = { input_tokens: number; output_tokens: number }\n *\n * type NonExistentProperty = $InferMessageProperty<MyStructure, \"ai\", \"nonExistent\">;\n * // NonExistentProperty = Record<string, unknown>\n *\n * type HumanMetadata = $InferMessageProperty<MyStructure, \"human\", \"metadata\">;\n * // HumanMetadata = Record<string, unknown>\n * ```\n */\nexport type $InferMessageProperty<TStructure extends MessageStructure, TRole extends MessageType, K extends string> = K extends keyof $InferMessageProperties<TStructure, TRole> ? $InferMessageProperties<TStructure, TRole>[K] : never;\n/**\n * Infers the response metadata type for a specific message type from a message structure.\n *\n * This utility type extracts the `response_metadata` property type for a given message type.\n *\n * @template TStructure - The message structure to infer the response metadata from\n * @template TRole - The message type/role to get the response metadata for (e.g., \"ai\", \"human\", \"system\", \"tool\")\n * @returns The type of the response_metadata property, or `Record<string, unknown>` as fallback\n *\n * @example\n * ```ts\n * interface MyStructure extends MessageStructure {\n * properties: {\n * ai: {\n * response_metadata: { model: string; temperature: number; tokens: number };\n * };\n * human: { metadata: Record<string, unknown> };\n * };\n * }\n *\n * type AIResponseMetadata = $InferResponseMetadata<MyStructure, \"ai\">;\n * // AIResponseMetadata = { model: string; temperature: number; tokens: number }\n *\n * type HumanResponseMetadata = $InferResponseMetadata<MyStructure, \"human\">;\n * // HumanResponseMetadata = Record<string, unknown> (fallback since not defined)\n * ```\n */\nexport type $InferResponseMetadata<TStructure extends MessageStructure, TRole extends MessageType> = $InferMessageProperty<TStructure, TRole, \"response_metadata\"> extends infer P ? [P] extends [never] ? Record<string, unknown> : P : never;\n/**\n * Represents a message object that organizes context for an LLM.\n *\n * @example\n * ```ts\n * // Basic message with text content\n * const message: Message = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"human\",\n * content: [{ type: \"text\", text: \"Hello!\" }]\n * };\n *\n * // Basic ai message interface extension\n * interface MyMessage extends Message<StandardMessageStructure, \"ai\"> {\n * // Additional AI-specific properties can be added here\n * }\n *`\n * // Custom message structure\n * interface CustomStructure extends MessageStructure {\n * content: {\n * ai: ContentBlock.Text | ContentBlock.ToolCall<\"search\", { query: string }>;\n * human: ContentBlock.Text | ContentBlock.Multimodal.Image;\n * };\n * }\n *\n * // Create a message with custom structure\n * const message: Message<CustomStructure> = {\n * id: \"msg-123\",\n * name: \"user\",\n * type: \"ai\",\n * content: [\n * { type: \"text\", text: \"Hello!\" },\n * {\n * type: \"tool_call\",\n * name: \"search\",\n * args: { query: \"What is the capital of France?\" }\n * }\n * ]\n * };\n * ```\n */\nexport interface Message<TStructure extends MessageStructure = StandardMessageStructure, TRole extends MessageType = MessageType> {\n /** The message type/role */\n readonly type: TRole;\n /** Unique identifier for this message */\n id?: string;\n /** Optional name/identifier for the entity that created this message */\n name?: string;\n /** Array of content blocks that make up the message content */\n content: $InferMessageContent<TStructure, TRole>;\n /** Metadata about the message */\n response_metadata?: Partial<$InferResponseMetadata<TStructure, TRole>>;\n}\n/**\n * Type guard to check if a value is a valid Message object.\n *\n * @param message - The value to check\n * @returns true if the value is a valid Message object, false otherwise\n */\nexport declare function isMessage(message: unknown): message is Message;\nexport {};\n"],"mappings":"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"}
@@ -331,21 +331,21 @@ interface StandardMessageStructure extends MessageStructure {
331
331
  /** Properties specific to AI messages */
332
332
  ai: {
333
333
  /** Metadata about the AI model response */
334
- response_metadata?: ResponseMetadata;
334
+ response_metadata: ResponseMetadata;
335
335
  /** Usage statistics for the AI response */
336
- usage_metadata?: UsageMetadata;
336
+ usage_metadata: UsageMetadata;
337
337
  };
338
338
  human: {
339
339
  /** Metadata about the human message */
340
- response_metadata?: Record<string, unknown>;
340
+ response_metadata: Record<string, unknown>;
341
341
  };
342
342
  system: {
343
343
  /** Metadata about the system message */
344
- response_metadata?: Record<string, unknown>;
344
+ response_metadata: Record<string, unknown>;
345
345
  };
346
346
  tool: {
347
347
  /** Metadata about the tool message */
348
- response_metadata?: Record<string, unknown>;
348
+ response_metadata: Record<string, unknown>;
349
349
  };
350
350
  };
351
351
  }
@@ -531,7 +531,7 @@ type $InferMessageProperty<TStructure extends MessageStructure, TRole extends Me
531
531
  * // HumanResponseMetadata = Record<string, unknown> (fallback since not defined)
532
532
  * ```
533
533
  */
534
- type $InferResponseMetadata<TStructure extends MessageStructure, TRole extends MessageType> = $InferMessageProperty<TStructure, TRole, "response_metadata"> extends infer P ? [P] extends [unknown] ? Record<string, unknown> : P : never;
534
+ type $InferResponseMetadata<TStructure extends MessageStructure, TRole extends MessageType> = $InferMessageProperty<TStructure, TRole, "response_metadata"> extends infer P ? [P] extends [never] ? Record<string, unknown> : P : never;
535
535
  /**
536
536
  * Represents a message object that organizes context for an LLM.
537
537
  *