@truefoundry/trueforge-core 0.0.0 → 0.1.0

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 (575) hide show
  1. package/LICENSE +21 -0
  2. package/dist/agent-session/ITurnResourceResolver.d.ts +69 -0
  3. package/dist/agent-session/ITurnResourceResolver.d.ts.map +1 -0
  4. package/dist/agent-session/ITurnResourceResolver.js +19 -0
  5. package/dist/agent-session/ITurnResourceResolver.js.map +1 -0
  6. package/dist/agent-session/ITurnResourceResolver.mjs +1 -0
  7. package/dist/agent-session/ITurnResourceResolver.mjs.map +1 -0
  8. package/dist/agent-session/SessionHandle.d.ts +81 -0
  9. package/dist/agent-session/SessionHandle.d.ts.map +1 -0
  10. package/dist/agent-session/SessionHandle.js +392 -0
  11. package/dist/agent-session/SessionHandle.js.map +1 -0
  12. package/dist/agent-session/SessionHandle.mjs +371 -0
  13. package/dist/agent-session/SessionHandle.mjs.map +1 -0
  14. package/dist/agent-session/Sessions.d.ts +25 -0
  15. package/dist/agent-session/Sessions.d.ts.map +1 -0
  16. package/dist/agent-session/Sessions.js +71 -0
  17. package/dist/agent-session/Sessions.js.map +1 -0
  18. package/dist/agent-session/Sessions.mjs +46 -0
  19. package/dist/agent-session/Sessions.mjs.map +1 -0
  20. package/dist/agent-session/TurnHandle.d.ts +88 -0
  21. package/dist/agent-session/TurnHandle.d.ts.map +1 -0
  22. package/dist/agent-session/TurnHandle.js +490 -0
  23. package/dist/agent-session/TurnHandle.js.map +1 -0
  24. package/dist/agent-session/TurnHandle.mjs +469 -0
  25. package/dist/agent-session/TurnHandle.mjs.map +1 -0
  26. package/dist/agent-session/TurnResourceResolver.d.ts +154 -0
  27. package/dist/agent-session/TurnResourceResolver.d.ts.map +1 -0
  28. package/dist/agent-session/TurnResourceResolver.js +178 -0
  29. package/dist/agent-session/TurnResourceResolver.js.map +1 -0
  30. package/dist/agent-session/TurnResourceResolver.mjs +153 -0
  31. package/dist/agent-session/TurnResourceResolver.mjs.map +1 -0
  32. package/dist/agent-session/builtinsFromSpec.d.ts +19 -0
  33. package/dist/agent-session/builtinsFromSpec.d.ts.map +1 -0
  34. package/dist/agent-session/builtinsFromSpec.js +73 -0
  35. package/dist/agent-session/builtinsFromSpec.js.map +1 -0
  36. package/dist/agent-session/builtinsFromSpec.mjs +48 -0
  37. package/dist/agent-session/builtinsFromSpec.mjs.map +1 -0
  38. package/dist/agent-session/index.d.ts +29 -0
  39. package/dist/agent-session/index.d.ts.map +1 -0
  40. package/dist/agent-session/index.js +117 -0
  41. package/dist/agent-session/index.js.map +1 -0
  42. package/dist/agent-session/index.mjs +84 -0
  43. package/dist/agent-session/index.mjs.map +1 -0
  44. package/dist/agent-session/models/SessionRecord.d.ts +34 -0
  45. package/dist/agent-session/models/SessionRecord.d.ts.map +1 -0
  46. package/dist/agent-session/models/SessionRecord.js +19 -0
  47. package/dist/agent-session/models/SessionRecord.js.map +1 -0
  48. package/dist/agent-session/models/SessionRecord.mjs +1 -0
  49. package/dist/agent-session/models/SessionRecord.mjs.map +1 -0
  50. package/dist/agent-session/models/TurnRecord.d.ts +37 -0
  51. package/dist/agent-session/models/TurnRecord.d.ts.map +1 -0
  52. package/dist/agent-session/models/TurnRecord.js +31 -0
  53. package/dist/agent-session/models/TurnRecord.js.map +1 -0
  54. package/dist/agent-session/models/TurnRecord.mjs +6 -0
  55. package/dist/agent-session/models/TurnRecord.mjs.map +1 -0
  56. package/dist/agent-session/schemas/agentSpec.d.ts +142 -0
  57. package/dist/agent-session/schemas/agentSpec.d.ts.map +1 -0
  58. package/dist/agent-session/schemas/agentSpec.js +170 -0
  59. package/dist/agent-session/schemas/agentSpec.js.map +1 -0
  60. package/dist/agent-session/schemas/agentSpec.mjs +154 -0
  61. package/dist/agent-session/schemas/agentSpec.mjs.map +1 -0
  62. package/dist/agent-session/schemas/events.d.ts +1037 -0
  63. package/dist/agent-session/schemas/events.d.ts.map +1 -0
  64. package/dist/agent-session/schemas/events.js +80 -0
  65. package/dist/agent-session/schemas/events.js.map +1 -0
  66. package/dist/agent-session/schemas/events.mjs +69 -0
  67. package/dist/agent-session/schemas/events.mjs.map +1 -0
  68. package/dist/agent-session/schemas/pagination.d.ts +9 -0
  69. package/dist/agent-session/schemas/pagination.d.ts.map +1 -0
  70. package/dist/agent-session/schemas/pagination.js +36 -0
  71. package/dist/agent-session/schemas/pagination.js.map +1 -0
  72. package/dist/agent-session/schemas/pagination.mjs +11 -0
  73. package/dist/agent-session/schemas/pagination.mjs.map +1 -0
  74. package/dist/agent-session/schemas/session.d.ts +319 -0
  75. package/dist/agent-session/schemas/session.d.ts.map +1 -0
  76. package/dist/agent-session/schemas/session.js +58 -0
  77. package/dist/agent-session/schemas/session.js.map +1 -0
  78. package/dist/agent-session/schemas/session.mjs +30 -0
  79. package/dist/agent-session/schemas/session.mjs.map +1 -0
  80. package/dist/agent-session/schemas/turn.d.ts +494 -0
  81. package/dist/agent-session/schemas/turn.d.ts.map +1 -0
  82. package/dist/agent-session/schemas/turn.js +131 -0
  83. package/dist/agent-session/schemas/turn.js.map +1 -0
  84. package/dist/agent-session/schemas/turn.mjs +102 -0
  85. package/dist/agent-session/schemas/turn.mjs.map +1 -0
  86. package/dist/agent-session/store/ISessionStore.d.ts +310 -0
  87. package/dist/agent-session/store/ISessionStore.d.ts.map +1 -0
  88. package/dist/agent-session/store/ISessionStore.js +19 -0
  89. package/dist/agent-session/store/ISessionStore.js.map +1 -0
  90. package/dist/agent-session/store/ISessionStore.mjs +1 -0
  91. package/dist/agent-session/store/ISessionStore.mjs.map +1 -0
  92. package/dist/agent-session/store/InMemorySessionStore.d.ts +55 -0
  93. package/dist/agent-session/store/InMemorySessionStore.d.ts.map +1 -0
  94. package/dist/agent-session/store/InMemorySessionStore.js +475 -0
  95. package/dist/agent-session/store/InMemorySessionStore.js.map +1 -0
  96. package/dist/agent-session/store/InMemorySessionStore.mjs +461 -0
  97. package/dist/agent-session/store/InMemorySessionStore.mjs.map +1 -0
  98. package/dist/agent-session/store/OffsetPageToken.d.ts +13 -0
  99. package/dist/agent-session/store/OffsetPageToken.d.ts.map +1 -0
  100. package/dist/agent-session/store/OffsetPageToken.js +60 -0
  101. package/dist/agent-session/store/OffsetPageToken.js.map +1 -0
  102. package/dist/agent-session/store/OffsetPageToken.mjs +32 -0
  103. package/dist/agent-session/store/OffsetPageToken.mjs.map +1 -0
  104. package/dist/agent-session/store/PageToken.d.ts +4 -0
  105. package/dist/agent-session/store/PageToken.d.ts.map +1 -0
  106. package/dist/agent-session/store/PageToken.js +45 -0
  107. package/dist/agent-session/store/PageToken.js.map +1 -0
  108. package/dist/agent-session/store/PageToken.mjs +19 -0
  109. package/dist/agent-session/store/PageToken.mjs.map +1 -0
  110. package/dist/agent-session/store/SessionEventPageToken.d.ts +14 -0
  111. package/dist/agent-session/store/SessionEventPageToken.d.ts.map +1 -0
  112. package/dist/agent-session/store/SessionEventPageToken.js +70 -0
  113. package/dist/agent-session/store/SessionEventPageToken.js.map +1 -0
  114. package/dist/agent-session/store/SessionEventPageToken.mjs +42 -0
  115. package/dist/agent-session/store/SessionEventPageToken.mjs.map +1 -0
  116. package/dist/agent-session/store/SessionListPageToken.d.ts +24 -0
  117. package/dist/agent-session/store/SessionListPageToken.d.ts.map +1 -0
  118. package/dist/agent-session/store/SessionListPageToken.js +66 -0
  119. package/dist/agent-session/store/SessionListPageToken.js.map +1 -0
  120. package/dist/agent-session/store/SessionListPageToken.mjs +38 -0
  121. package/dist/agent-session/store/SessionListPageToken.mjs.map +1 -0
  122. package/dist/agent-session/store/SessionStoreErrors.d.ts +43 -0
  123. package/dist/agent-session/store/SessionStoreErrors.d.ts.map +1 -0
  124. package/dist/agent-session/store/SessionStoreErrors.js +126 -0
  125. package/dist/agent-session/store/SessionStoreErrors.js.map +1 -0
  126. package/dist/agent-session/store/SessionStoreErrors.mjs +92 -0
  127. package/dist/agent-session/store/SessionStoreErrors.mjs.map +1 -0
  128. package/dist/agent-session/store/assertCreateTurnThreadDelta.d.ts +18 -0
  129. package/dist/agent-session/store/assertCreateTurnThreadDelta.d.ts.map +1 -0
  130. package/dist/agent-session/store/assertCreateTurnThreadDelta.js +67 -0
  131. package/dist/agent-session/store/assertCreateTurnThreadDelta.js.map +1 -0
  132. package/dist/agent-session/store/assertCreateTurnThreadDelta.mjs +42 -0
  133. package/dist/agent-session/store/assertCreateTurnThreadDelta.mjs.map +1 -0
  134. package/dist/core/InstructionBuilder.d.ts +71 -0
  135. package/dist/core/InstructionBuilder.d.ts.map +1 -0
  136. package/dist/core/InstructionBuilder.js +95 -0
  137. package/dist/core/InstructionBuilder.js.map +1 -0
  138. package/dist/core/InstructionBuilder.mjs +69 -0
  139. package/dist/core/InstructionBuilder.mjs.map +1 -0
  140. package/dist/core/capabilities/AgentCapability.d.ts +32 -0
  141. package/dist/core/capabilities/AgentCapability.d.ts.map +1 -0
  142. package/dist/core/capabilities/AgentCapability.js +19 -0
  143. package/dist/core/capabilities/AgentCapability.js.map +1 -0
  144. package/dist/core/capabilities/AgentCapability.mjs +1 -0
  145. package/dist/core/capabilities/AgentCapability.mjs.map +1 -0
  146. package/dist/core/capabilities/AgentContextProcessor.d.ts +30 -0
  147. package/dist/core/capabilities/AgentContextProcessor.d.ts.map +1 -0
  148. package/dist/core/capabilities/AgentContextProcessor.js +19 -0
  149. package/dist/core/capabilities/AgentContextProcessor.js.map +1 -0
  150. package/dist/core/capabilities/AgentContextProcessor.mjs +1 -0
  151. package/dist/core/capabilities/AgentContextProcessor.mjs.map +1 -0
  152. package/dist/core/capabilities/ToolResponseProcessor.d.ts +12 -0
  153. package/dist/core/capabilities/ToolResponseProcessor.d.ts.map +1 -0
  154. package/dist/core/capabilities/ToolResponseProcessor.js +19 -0
  155. package/dist/core/capabilities/ToolResponseProcessor.js.map +1 -0
  156. package/dist/core/capabilities/ToolResponseProcessor.mjs +1 -0
  157. package/dist/core/capabilities/ToolResponseProcessor.mjs.map +1 -0
  158. package/dist/core/capabilities/builtins/AskUserQuestion.d.ts +11 -0
  159. package/dist/core/capabilities/builtins/AskUserQuestion.d.ts.map +1 -0
  160. package/dist/core/capabilities/builtins/AskUserQuestion.js +90 -0
  161. package/dist/core/capabilities/builtins/AskUserQuestion.js.map +1 -0
  162. package/dist/core/capabilities/builtins/AskUserQuestion.mjs +64 -0
  163. package/dist/core/capabilities/builtins/AskUserQuestion.mjs.map +1 -0
  164. package/dist/core/capabilities/builtins/ContextCompaction.d.ts +23 -0
  165. package/dist/core/capabilities/builtins/ContextCompaction.d.ts.map +1 -0
  166. package/dist/core/capabilities/builtins/ContextCompaction.js +235 -0
  167. package/dist/core/capabilities/builtins/ContextCompaction.js.map +1 -0
  168. package/dist/core/capabilities/builtins/ContextCompaction.mjs +208 -0
  169. package/dist/core/capabilities/builtins/ContextCompaction.mjs.map +1 -0
  170. package/dist/core/capabilities/builtins/CurrentDateTime.d.ts +17 -0
  171. package/dist/core/capabilities/builtins/CurrentDateTime.d.ts.map +1 -0
  172. package/dist/core/capabilities/builtins/CurrentDateTime.js +75 -0
  173. package/dist/core/capabilities/builtins/CurrentDateTime.js.map +1 -0
  174. package/dist/core/capabilities/builtins/CurrentDateTime.mjs +47 -0
  175. package/dist/core/capabilities/builtins/CurrentDateTime.mjs.map +1 -0
  176. package/dist/core/capabilities/builtins/DynamicSubAgents.d.ts +39 -0
  177. package/dist/core/capabilities/builtins/DynamicSubAgents.d.ts.map +1 -0
  178. package/dist/core/capabilities/builtins/DynamicSubAgents.js +176 -0
  179. package/dist/core/capabilities/builtins/DynamicSubAgents.js.map +1 -0
  180. package/dist/core/capabilities/builtins/DynamicSubAgents.mjs +134 -0
  181. package/dist/core/capabilities/builtins/DynamicSubAgents.mjs.map +1 -0
  182. package/dist/core/capabilities/builtins/LargeToolResponse.d.ts +40 -0
  183. package/dist/core/capabilities/builtins/LargeToolResponse.d.ts.map +1 -0
  184. package/dist/core/capabilities/builtins/LargeToolResponse.js +225 -0
  185. package/dist/core/capabilities/builtins/LargeToolResponse.js.map +1 -0
  186. package/dist/core/capabilities/builtins/LargeToolResponse.mjs +186 -0
  187. package/dist/core/capabilities/builtins/LargeToolResponse.mjs.map +1 -0
  188. package/dist/core/capabilities/builtins/OpenUI.d.ts +31 -0
  189. package/dist/core/capabilities/builtins/OpenUI.d.ts.map +1 -0
  190. package/dist/core/capabilities/builtins/OpenUI.js +376 -0
  191. package/dist/core/capabilities/builtins/OpenUI.js.map +1 -0
  192. package/dist/core/capabilities/builtins/OpenUI.mjs +326 -0
  193. package/dist/core/capabilities/builtins/OpenUI.mjs.map +1 -0
  194. package/dist/core/errors.d.ts +33 -0
  195. package/dist/core/errors.d.ts.map +1 -0
  196. package/dist/core/errors.js +88 -0
  197. package/dist/core/errors.js.map +1 -0
  198. package/dist/core/errors.mjs +57 -0
  199. package/dist/core/errors.mjs.map +1 -0
  200. package/dist/core/events/PassthroughEvents.d.ts +30 -0
  201. package/dist/core/events/PassthroughEvents.d.ts.map +1 -0
  202. package/dist/core/events/PassthroughEvents.js +19 -0
  203. package/dist/core/events/PassthroughEvents.js.map +1 -0
  204. package/dist/core/events/PassthroughEvents.mjs +1 -0
  205. package/dist/core/events/PassthroughEvents.mjs.map +1 -0
  206. package/dist/core/events/schema.d.ts +1103 -0
  207. package/dist/core/events/schema.d.ts.map +1 -0
  208. package/dist/core/events/schema.js +337 -0
  209. package/dist/core/events/schema.js.map +1 -0
  210. package/dist/core/events/schema.mjs +283 -0
  211. package/dist/core/events/schema.mjs.map +1 -0
  212. package/dist/core/index.d.ts +66 -0
  213. package/dist/core/index.d.ts.map +1 -0
  214. package/dist/core/index.js +234 -0
  215. package/dist/core/index.js.map +1 -0
  216. package/dist/core/index.mjs +166 -0
  217. package/dist/core/index.mjs.map +1 -0
  218. package/dist/core/llm/ILLM.d.ts +15 -0
  219. package/dist/core/llm/ILLM.d.ts.map +1 -0
  220. package/dist/core/llm/ILLM.js +19 -0
  221. package/dist/core/llm/ILLM.js.map +1 -0
  222. package/dist/core/llm/ILLM.mjs +1 -0
  223. package/dist/core/llm/ILLM.mjs.map +1 -0
  224. package/dist/core/llm/LLMTypes.d.ts +369 -0
  225. package/dist/core/llm/LLMTypes.d.ts.map +1 -0
  226. package/dist/core/llm/LLMTypes.js +170 -0
  227. package/dist/core/llm/LLMTypes.js.map +1 -0
  228. package/dist/core/llm/LLMTypes.mjs +133 -0
  229. package/dist/core/llm/LLMTypes.mjs.map +1 -0
  230. package/dist/core/llm/VercelAILLM.d.ts +229 -0
  231. package/dist/core/llm/VercelAILLM.d.ts.map +1 -0
  232. package/dist/core/llm/VercelAILLM.js +1037 -0
  233. package/dist/core/llm/VercelAILLM.js.map +1 -0
  234. package/dist/core/llm/VercelAILLM.mjs +993 -0
  235. package/dist/core/llm/VercelAILLM.mjs.map +1 -0
  236. package/dist/core/llm/openaiSchemas.d.ts +190 -0
  237. package/dist/core/llm/openaiSchemas.d.ts.map +1 -0
  238. package/dist/core/llm/openaiSchemas.js +144 -0
  239. package/dist/core/llm/openaiSchemas.js.map +1 -0
  240. package/dist/core/llm/openaiSchemas.mjs +107 -0
  241. package/dist/core/llm/openaiSchemas.mjs.map +1 -0
  242. package/dist/core/llm/responseFormat.d.ts +25 -0
  243. package/dist/core/llm/responseFormat.d.ts.map +1 -0
  244. package/dist/core/llm/responseFormat.js +58 -0
  245. package/dist/core/llm/responseFormat.js.map +1 -0
  246. package/dist/core/llm/responseFormat.mjs +32 -0
  247. package/dist/core/llm/responseFormat.mjs.map +1 -0
  248. package/dist/core/llm/toOpenAIChatMessage.d.ts +11 -0
  249. package/dist/core/llm/toOpenAIChatMessage.d.ts.map +1 -0
  250. package/dist/core/llm/toOpenAIChatMessage.js +95 -0
  251. package/dist/core/llm/toOpenAIChatMessage.js.map +1 -0
  252. package/dist/core/llm/toOpenAIChatMessage.mjs +70 -0
  253. package/dist/core/llm/toOpenAIChatMessage.mjs.map +1 -0
  254. package/dist/core/llm/usage.d.ts +4 -0
  255. package/dist/core/llm/usage.d.ts.map +1 -0
  256. package/dist/core/llm/usage.js +52 -0
  257. package/dist/core/llm/usage.js.map +1 -0
  258. package/dist/core/llm/usage.mjs +26 -0
  259. package/dist/core/llm/usage.mjs.map +1 -0
  260. package/dist/core/mcp/ClientSideTool.d.ts +10 -0
  261. package/dist/core/mcp/ClientSideTool.d.ts.map +1 -0
  262. package/dist/core/mcp/ClientSideTool.js +56 -0
  263. package/dist/core/mcp/ClientSideTool.js.map +1 -0
  264. package/dist/core/mcp/ClientSideTool.mjs +31 -0
  265. package/dist/core/mcp/ClientSideTool.mjs.map +1 -0
  266. package/dist/core/mcp/IMCPServer.d.ts +78 -0
  267. package/dist/core/mcp/IMCPServer.d.ts.map +1 -0
  268. package/dist/core/mcp/IMCPServer.js +63 -0
  269. package/dist/core/mcp/IMCPServer.js.map +1 -0
  270. package/dist/core/mcp/IMCPServer.mjs +33 -0
  271. package/dist/core/mcp/IMCPServer.mjs.map +1 -0
  272. package/dist/core/mcp/LocalToolMCP.d.ts +39 -0
  273. package/dist/core/mcp/LocalToolMCP.d.ts.map +1 -0
  274. package/dist/core/mcp/LocalToolMCP.js +121 -0
  275. package/dist/core/mcp/LocalToolMCP.js.map +1 -0
  276. package/dist/core/mcp/LocalToolMCP.mjs +98 -0
  277. package/dist/core/mcp/LocalToolMCP.mjs.map +1 -0
  278. package/dist/core/mcp/RemoteMCP.d.ts +67 -0
  279. package/dist/core/mcp/RemoteMCP.d.ts.map +1 -0
  280. package/dist/core/mcp/RemoteMCP.js +244 -0
  281. package/dist/core/mcp/RemoteMCP.js.map +1 -0
  282. package/dist/core/mcp/RemoteMCP.mjs +222 -0
  283. package/dist/core/mcp/RemoteMCP.mjs.map +1 -0
  284. package/dist/core/mcp/ToolSelectorPolicy.d.ts +52 -0
  285. package/dist/core/mcp/ToolSelectorPolicy.d.ts.map +1 -0
  286. package/dist/core/mcp/ToolSelectorPolicy.js +108 -0
  287. package/dist/core/mcp/ToolSelectorPolicy.js.map +1 -0
  288. package/dist/core/mcp/ToolSelectorPolicy.mjs +90 -0
  289. package/dist/core/mcp/ToolSelectorPolicy.mjs.map +1 -0
  290. package/dist/core/mcp/ToolSet.d.ts +31 -0
  291. package/dist/core/mcp/ToolSet.d.ts.map +1 -0
  292. package/dist/core/mcp/ToolSet.js +119 -0
  293. package/dist/core/mcp/ToolSet.js.map +1 -0
  294. package/dist/core/mcp/ToolSet.mjs +98 -0
  295. package/dist/core/mcp/ToolSet.mjs.map +1 -0
  296. package/dist/core/mcp/convertMCPServers.d.ts +22 -0
  297. package/dist/core/mcp/convertMCPServers.d.ts.map +1 -0
  298. package/dist/core/mcp/convertMCPServers.js +89 -0
  299. package/dist/core/mcp/convertMCPServers.js.map +1 -0
  300. package/dist/core/mcp/convertMCPServers.mjs +64 -0
  301. package/dist/core/mcp/convertMCPServers.mjs.map +1 -0
  302. package/dist/core/mcp/executeToolCalls.d.ts +31 -0
  303. package/dist/core/mcp/executeToolCalls.d.ts.map +1 -0
  304. package/dist/core/mcp/executeToolCalls.js +168 -0
  305. package/dist/core/mcp/executeToolCalls.js.map +1 -0
  306. package/dist/core/mcp/executeToolCalls.mjs +149 -0
  307. package/dist/core/mcp/executeToolCalls.mjs.map +1 -0
  308. package/dist/core/mcp/pagination.d.ts +11 -0
  309. package/dist/core/mcp/pagination.d.ts.map +1 -0
  310. package/dist/core/mcp/pagination.js +49 -0
  311. package/dist/core/mcp/pagination.js.map +1 -0
  312. package/dist/core/mcp/pagination.mjs +24 -0
  313. package/dist/core/mcp/pagination.mjs.map +1 -0
  314. package/dist/core/mcp/remoteMcpClient.d.ts +36 -0
  315. package/dist/core/mcp/remoteMcpClient.d.ts.map +1 -0
  316. package/dist/core/mcp/remoteMcpClient.js +138 -0
  317. package/dist/core/mcp/remoteMcpClient.js.map +1 -0
  318. package/dist/core/mcp/remoteMcpClient.mjs +112 -0
  319. package/dist/core/mcp/remoteMcpClient.mjs.map +1 -0
  320. package/dist/core/mcp/toolNames.d.ts +6 -0
  321. package/dist/core/mcp/toolNames.d.ts.map +1 -0
  322. package/dist/core/mcp/toolNames.js +59 -0
  323. package/dist/core/mcp/toolNames.js.map +1 -0
  324. package/dist/core/mcp/toolNames.mjs +33 -0
  325. package/dist/core/mcp/toolNames.mjs.map +1 -0
  326. package/dist/core/mcp/toolSelectors.d.ts +28 -0
  327. package/dist/core/mcp/toolSelectors.d.ts.map +1 -0
  328. package/dist/core/mcp/toolSelectors.js +113 -0
  329. package/dist/core/mcp/toolSelectors.js.map +1 -0
  330. package/dist/core/mcp/toolSelectors.mjs +78 -0
  331. package/dist/core/mcp/toolSelectors.mjs.map +1 -0
  332. package/dist/core/runtime/AgentDefinition.d.ts +23 -0
  333. package/dist/core/runtime/AgentDefinition.d.ts.map +1 -0
  334. package/dist/core/runtime/AgentDefinition.js +19 -0
  335. package/dist/core/runtime/AgentDefinition.js.map +1 -0
  336. package/dist/core/runtime/AgentDefinition.mjs +1 -0
  337. package/dist/core/runtime/AgentDefinition.mjs.map +1 -0
  338. package/dist/core/runtime/AgentThread.d.ts +64 -0
  339. package/dist/core/runtime/AgentThread.d.ts.map +1 -0
  340. package/dist/core/runtime/AgentThread.js +1067 -0
  341. package/dist/core/runtime/AgentThread.js.map +1 -0
  342. package/dist/core/runtime/AgentThread.mjs +1064 -0
  343. package/dist/core/runtime/AgentThread.mjs.map +1 -0
  344. package/dist/core/runtime/AgentThread.types.d.ts +123 -0
  345. package/dist/core/runtime/AgentThread.types.d.ts.map +1 -0
  346. package/dist/core/runtime/AgentThread.types.js +46 -0
  347. package/dist/core/runtime/AgentThread.types.js.map +1 -0
  348. package/dist/core/runtime/AgentThread.types.mjs +20 -0
  349. package/dist/core/runtime/AgentThread.types.mjs.map +1 -0
  350. package/dist/core/runtime/AgentThreadOrchestrator.d.ts +35 -0
  351. package/dist/core/runtime/AgentThreadOrchestrator.d.ts.map +1 -0
  352. package/dist/core/runtime/AgentThreadOrchestrator.js +433 -0
  353. package/dist/core/runtime/AgentThreadOrchestrator.js.map +1 -0
  354. package/dist/core/runtime/AgentThreadOrchestrator.mjs +418 -0
  355. package/dist/core/runtime/AgentThreadOrchestrator.mjs.map +1 -0
  356. package/dist/core/runtime/CreateDynamicSubAgentThread.d.ts +11 -0
  357. package/dist/core/runtime/CreateDynamicSubAgentThread.d.ts.map +1 -0
  358. package/dist/core/runtime/CreateDynamicSubAgentThread.js +19 -0
  359. package/dist/core/runtime/CreateDynamicSubAgentThread.js.map +1 -0
  360. package/dist/core/runtime/CreateDynamicSubAgentThread.mjs +1 -0
  361. package/dist/core/runtime/CreateDynamicSubAgentThread.mjs.map +1 -0
  362. package/dist/core/runtime/DeferredTool.d.ts +34 -0
  363. package/dist/core/runtime/DeferredTool.d.ts.map +1 -0
  364. package/dist/core/runtime/DeferredTool.js +321 -0
  365. package/dist/core/runtime/DeferredTool.js.map +1 -0
  366. package/dist/core/runtime/DeferredTool.mjs +287 -0
  367. package/dist/core/runtime/DeferredTool.mjs.map +1 -0
  368. package/dist/core/runtime/OpenToolCallCloser.d.ts +21 -0
  369. package/dist/core/runtime/OpenToolCallCloser.d.ts.map +1 -0
  370. package/dist/core/runtime/OpenToolCallCloser.js +92 -0
  371. package/dist/core/runtime/OpenToolCallCloser.js.map +1 -0
  372. package/dist/core/runtime/OpenToolCallCloser.mjs +66 -0
  373. package/dist/core/runtime/OpenToolCallCloser.mjs.map +1 -0
  374. package/dist/core/runtime/UserInputMessage.d.ts +16 -0
  375. package/dist/core/runtime/UserInputMessage.d.ts.map +1 -0
  376. package/dist/core/runtime/UserInputMessage.js +183 -0
  377. package/dist/core/runtime/UserInputMessage.js.map +1 -0
  378. package/dist/core/runtime/UserInputMessage.mjs +157 -0
  379. package/dist/core/runtime/UserInputMessage.mjs.map +1 -0
  380. package/dist/core/runtime/contextUsage.d.ts +17 -0
  381. package/dist/core/runtime/contextUsage.d.ts.map +1 -0
  382. package/dist/core/runtime/contextUsage.js +56 -0
  383. package/dist/core/runtime/contextUsage.js.map +1 -0
  384. package/dist/core/runtime/contextUsage.mjs +28 -0
  385. package/dist/core/runtime/contextUsage.mjs.map +1 -0
  386. package/dist/core/runtime/contextUtils.d.ts +30 -0
  387. package/dist/core/runtime/contextUtils.d.ts.map +1 -0
  388. package/dist/core/runtime/contextUtils.js +198 -0
  389. package/dist/core/runtime/contextUtils.js.map +1 -0
  390. package/dist/core/runtime/contextUtils.mjs +148 -0
  391. package/dist/core/runtime/contextUtils.mjs.map +1 -0
  392. package/dist/core/runtime/metrics.d.ts +22 -0
  393. package/dist/core/runtime/metrics.d.ts.map +1 -0
  394. package/dist/core/runtime/metrics.js +89 -0
  395. package/dist/core/runtime/metrics.js.map +1 -0
  396. package/dist/core/runtime/metrics.mjs +61 -0
  397. package/dist/core/runtime/metrics.mjs.map +1 -0
  398. package/dist/core/sandbox/Sandbox.d.ts +119 -0
  399. package/dist/core/sandbox/Sandbox.d.ts.map +1 -0
  400. package/dist/core/sandbox/Sandbox.js +556 -0
  401. package/dist/core/sandbox/Sandbox.js.map +1 -0
  402. package/dist/core/sandbox/Sandbox.mjs +520 -0
  403. package/dist/core/sandbox/Sandbox.mjs.map +1 -0
  404. package/dist/core/sandbox/SandboxErrors.d.ts +30 -0
  405. package/dist/core/sandbox/SandboxErrors.d.ts.map +1 -0
  406. package/dist/core/sandbox/SandboxErrors.js +102 -0
  407. package/dist/core/sandbox/SandboxErrors.js.map +1 -0
  408. package/dist/core/sandbox/SandboxErrors.mjs +71 -0
  409. package/dist/core/sandbox/SandboxErrors.mjs.map +1 -0
  410. package/dist/core/sandbox/codeMode/CodeModeDispatcher.d.ts +29 -0
  411. package/dist/core/sandbox/codeMode/CodeModeDispatcher.d.ts.map +1 -0
  412. package/dist/core/sandbox/codeMode/CodeModeDispatcher.js +128 -0
  413. package/dist/core/sandbox/codeMode/CodeModeDispatcher.js.map +1 -0
  414. package/dist/core/sandbox/codeMode/CodeModeDispatcher.mjs +107 -0
  415. package/dist/core/sandbox/codeMode/CodeModeDispatcher.mjs.map +1 -0
  416. package/dist/core/sandbox/codeMode/CodeModeTransport.d.ts +21 -0
  417. package/dist/core/sandbox/codeMode/CodeModeTransport.d.ts.map +1 -0
  418. package/dist/core/sandbox/codeMode/CodeModeTransport.js +19 -0
  419. package/dist/core/sandbox/codeMode/CodeModeTransport.js.map +1 -0
  420. package/dist/core/sandbox/codeMode/CodeModeTransport.mjs +1 -0
  421. package/dist/core/sandbox/codeMode/CodeModeTransport.mjs.map +1 -0
  422. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.d.ts +34 -0
  423. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.d.ts.map +1 -0
  424. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.js +187 -0
  425. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.js.map +1 -0
  426. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.mjs +162 -0
  427. package/dist/core/sandbox/codeMode/nats/CodeModeNatsTransport.mjs.map +1 -0
  428. package/dist/core/sandbox/codeMode/types.d.ts +34 -0
  429. package/dist/core/sandbox/codeMode/types.d.ts.map +1 -0
  430. package/dist/core/sandbox/codeMode/types.js +59 -0
  431. package/dist/core/sandbox/codeMode/types.js.map +1 -0
  432. package/dist/core/sandbox/codeMode/types.mjs +32 -0
  433. package/dist/core/sandbox/codeMode/types.mjs.map +1 -0
  434. package/dist/core/sandbox/constants.d.ts +10 -0
  435. package/dist/core/sandbox/constants.d.ts.map +1 -0
  436. package/dist/core/sandbox/constants.js +37 -0
  437. package/dist/core/sandbox/constants.js.map +1 -0
  438. package/dist/core/sandbox/constants.mjs +10 -0
  439. package/dist/core/sandbox/constants.mjs.map +1 -0
  440. package/dist/core/sandbox/provider/DaytonaProvider.d.ts +81 -0
  441. package/dist/core/sandbox/provider/DaytonaProvider.d.ts.map +1 -0
  442. package/dist/core/sandbox/provider/DaytonaProvider.js +353 -0
  443. package/dist/core/sandbox/provider/DaytonaProvider.js.map +1 -0
  444. package/dist/core/sandbox/provider/DaytonaProvider.mjs +333 -0
  445. package/dist/core/sandbox/provider/DaytonaProvider.mjs.map +1 -0
  446. package/dist/core/sandbox/provider/Provider.d.ts +84 -0
  447. package/dist/core/sandbox/provider/Provider.d.ts.map +1 -0
  448. package/dist/core/sandbox/provider/Provider.js +43 -0
  449. package/dist/core/sandbox/provider/Provider.js.map +1 -0
  450. package/dist/core/sandbox/provider/Provider.mjs +17 -0
  451. package/dist/core/sandbox/provider/Provider.mjs.map +1 -0
  452. package/dist/core/sandbox/provider/TFYSandboxProvider.d.ts +42 -0
  453. package/dist/core/sandbox/provider/TFYSandboxProvider.d.ts.map +1 -0
  454. package/dist/core/sandbox/provider/TFYSandboxProvider.js +186 -0
  455. package/dist/core/sandbox/provider/TFYSandboxProvider.js.map +1 -0
  456. package/dist/core/sandbox/provider/TFYSandboxProvider.mjs +153 -0
  457. package/dist/core/sandbox/provider/TFYSandboxProvider.mjs.map +1 -0
  458. package/dist/core/sandbox/sandboxImage.d.ts +6 -0
  459. package/dist/core/sandbox/sandboxImage.d.ts.map +1 -0
  460. package/dist/core/sandbox/sandboxImage.js +31 -0
  461. package/dist/core/sandbox/sandboxImage.js.map +1 -0
  462. package/dist/core/sandbox/sandboxImage.mjs +6 -0
  463. package/dist/core/sandbox/sandboxImage.mjs.map +1 -0
  464. package/dist/core/sandbox/sandboxScripts.gen.d.ts +5 -0
  465. package/dist/core/sandbox/sandboxScripts.gen.d.ts.map +1 -0
  466. package/dist/core/sandbox/sandboxScripts.gen.js +343 -0
  467. package/dist/core/sandbox/sandboxScripts.gen.js.map +1 -0
  468. package/dist/core/sandbox/sandboxScripts.gen.mjs +318 -0
  469. package/dist/core/sandbox/sandboxScripts.gen.mjs.map +1 -0
  470. package/dist/core/sandbox/skills/ISkillMounter.d.ts +7 -0
  471. package/dist/core/sandbox/skills/ISkillMounter.d.ts.map +1 -0
  472. package/dist/core/sandbox/skills/ISkillMounter.js +19 -0
  473. package/dist/core/sandbox/skills/ISkillMounter.js.map +1 -0
  474. package/dist/core/sandbox/skills/ISkillMounter.mjs +1 -0
  475. package/dist/core/sandbox/skills/ISkillMounter.mjs.map +1 -0
  476. package/dist/core/sandbox/skills/SkillMounter.d.ts +17 -0
  477. package/dist/core/sandbox/skills/SkillMounter.d.ts.map +1 -0
  478. package/dist/core/sandbox/skills/SkillMounter.js +73 -0
  479. package/dist/core/sandbox/skills/SkillMounter.js.map +1 -0
  480. package/dist/core/sandbox/skills/SkillMounter.mjs +48 -0
  481. package/dist/core/sandbox/skills/SkillMounter.mjs.map +1 -0
  482. package/dist/core/sandbox/skills/constants.d.ts +10 -0
  483. package/dist/core/sandbox/skills/constants.d.ts.map +1 -0
  484. package/dist/core/sandbox/skills/constants.js +56 -0
  485. package/dist/core/sandbox/skills/constants.js.map +1 -0
  486. package/dist/core/sandbox/skills/constants.mjs +28 -0
  487. package/dist/core/sandbox/skills/constants.mjs.map +1 -0
  488. package/dist/core/sandbox/skills/index.d.ts +5 -0
  489. package/dist/core/sandbox/skills/index.d.ts.map +1 -0
  490. package/dist/core/sandbox/skills/index.js +40 -0
  491. package/dist/core/sandbox/skills/index.js.map +1 -0
  492. package/dist/core/sandbox/skills/index.mjs +11 -0
  493. package/dist/core/sandbox/skills/index.mjs.map +1 -0
  494. package/dist/core/tracing/AgentTracing.d.ts +38 -0
  495. package/dist/core/tracing/AgentTracing.d.ts.map +1 -0
  496. package/dist/core/tracing/AgentTracing.js +19 -0
  497. package/dist/core/tracing/AgentTracing.js.map +1 -0
  498. package/dist/core/tracing/AgentTracing.mjs +1 -0
  499. package/dist/core/tracing/AgentTracing.mjs.map +1 -0
  500. package/dist/core/tracing/NoopAgentTracing.d.ts +3 -0
  501. package/dist/core/tracing/NoopAgentTracing.d.ts.map +1 -0
  502. package/dist/core/tracing/NoopAgentTracing.js +79 -0
  503. package/dist/core/tracing/NoopAgentTracing.js.map +1 -0
  504. package/dist/core/tracing/NoopAgentTracing.mjs +54 -0
  505. package/dist/core/tracing/NoopAgentTracing.mjs.map +1 -0
  506. package/dist/core/util/abort.d.ts +2 -0
  507. package/dist/core/util/abort.d.ts.map +1 -0
  508. package/dist/core/util/abort.js +38 -0
  509. package/dist/core/util/abort.js.map +1 -0
  510. package/dist/core/util/abort.mjs +13 -0
  511. package/dist/core/util/abort.mjs.map +1 -0
  512. package/dist/core/util/errorLogFields.d.ts +11 -0
  513. package/dist/core/util/errorLogFields.d.ts.map +1 -0
  514. package/dist/core/util/errorLogFields.js +72 -0
  515. package/dist/core/util/errorLogFields.js.map +1 -0
  516. package/dist/core/util/errorLogFields.mjs +46 -0
  517. package/dist/core/util/errorLogFields.mjs.map +1 -0
  518. package/dist/core/util/promiseUtils.d.ts +7 -0
  519. package/dist/core/util/promiseUtils.d.ts.map +1 -0
  520. package/dist/core/util/promiseUtils.js +82 -0
  521. package/dist/core/util/promiseUtils.js.map +1 -0
  522. package/dist/core/util/promiseUtils.mjs +55 -0
  523. package/dist/core/util/promiseUtils.mjs.map +1 -0
  524. package/dist/index.d.ts +7 -0
  525. package/dist/index.d.ts.map +1 -0
  526. package/dist/index.js +44 -0
  527. package/dist/index.js.map +1 -0
  528. package/dist/index.mjs +8 -0
  529. package/dist/index.mjs.map +1 -0
  530. package/dist/package.json +3 -0
  531. package/dist/request-reply/client.d.ts +21 -0
  532. package/dist/request-reply/client.d.ts.map +1 -0
  533. package/dist/request-reply/client.js +92 -0
  534. package/dist/request-reply/client.js.map +1 -0
  535. package/dist/request-reply/client.mjs +67 -0
  536. package/dist/request-reply/client.mjs.map +1 -0
  537. package/dist/request-reply/errors.d.ts +23 -0
  538. package/dist/request-reply/errors.d.ts.map +1 -0
  539. package/dist/request-reply/errors.js +66 -0
  540. package/dist/request-reply/errors.js.map +1 -0
  541. package/dist/request-reply/errors.mjs +39 -0
  542. package/dist/request-reply/errors.mjs.map +1 -0
  543. package/dist/request-reply/executor.d.ts +70 -0
  544. package/dist/request-reply/executor.d.ts.map +1 -0
  545. package/dist/request-reply/executor.js +267 -0
  546. package/dist/request-reply/executor.js.map +1 -0
  547. package/dist/request-reply/executor.mjs +232 -0
  548. package/dist/request-reply/executor.mjs.map +1 -0
  549. package/dist/request-reply/index.d.ts +16 -0
  550. package/dist/request-reply/index.d.ts.map +1 -0
  551. package/dist/request-reply/index.js +47 -0
  552. package/dist/request-reply/index.js.map +1 -0
  553. package/dist/request-reply/index.mjs +16 -0
  554. package/dist/request-reply/index.mjs.map +1 -0
  555. package/dist/request-reply/router.d.ts +20 -0
  556. package/dist/request-reply/router.d.ts.map +1 -0
  557. package/dist/request-reply/router.js +55 -0
  558. package/dist/request-reply/router.js.map +1 -0
  559. package/dist/request-reply/router.mjs +30 -0
  560. package/dist/request-reply/router.mjs.map +1 -0
  561. package/dist/request-reply/types.d.ts +25 -0
  562. package/dist/request-reply/types.d.ts.map +1 -0
  563. package/dist/request-reply/types.js +54 -0
  564. package/dist/request-reply/types.js.map +1 -0
  565. package/dist/request-reply/types.mjs +28 -0
  566. package/dist/request-reply/types.mjs.map +1 -0
  567. package/dist/request-reply/utils.d.ts +9 -0
  568. package/dist/request-reply/utils.d.ts.map +1 -0
  569. package/dist/request-reply/utils.js +51 -0
  570. package/dist/request-reply/utils.js.map +1 -0
  571. package/dist/request-reply/utils.mjs +22 -0
  572. package/dist/request-reply/utils.mjs.map +1 -0
  573. package/package.json +127 -6
  574. package/README.md +0 -4
  575. package/index.js +0 -1
@@ -0,0 +1,993 @@
1
+ // src/core/llm/VercelAILLM.ts
2
+ import { createAlibaba } from "@ai-sdk/alibaba";
3
+ import { createAnthropic } from "@ai-sdk/anthropic";
4
+ import { createGoogle } from "@ai-sdk/google";
5
+ import { createMoonshotAI } from "@ai-sdk/moonshotai";
6
+ import { createOpenAI } from "@ai-sdk/openai";
7
+ import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
8
+ import { APICallError, jsonSchema, Output, streamText } from "ai";
9
+ import { describeUnknownError, extractErrorLogFields } from "../util/errorLogFields.mjs";
10
+ import {
11
+ getEmptyUsage
12
+ } from "./LLMTypes.mjs";
13
+ var VERCEL_AI_PROVIDER_NAMES = [
14
+ "openai",
15
+ "anthropic",
16
+ "google-gemini",
17
+ "fireworks",
18
+ "zai",
19
+ "moonshot",
20
+ "alibaba",
21
+ "together",
22
+ "custom"
23
+ ];
24
+ function isPlainObject(v) {
25
+ return typeof v === "object" && v !== null && !Array.isArray(v);
26
+ }
27
+ function isFunctionTool(tool) {
28
+ return tool.type === "function";
29
+ }
30
+ function isFunctionToolCall(toolCall) {
31
+ return toolCall.type === "function";
32
+ }
33
+ function compatibleModel(config) {
34
+ const { provider, model, apiKey, headers, baseUrl } = config;
35
+ if (baseUrl === void 0) {
36
+ throw new Error(`Provider "${provider.type}" requires a baseUrl`);
37
+ }
38
+ const client = createOpenAICompatible({
39
+ name: provider.type,
40
+ baseURL: baseUrl,
41
+ apiKey,
42
+ // Without this the adapter silently downgrades json_schema to a schema-less json_object.
43
+ supportsStructuredOutputs: true,
44
+ // These endpoints omit token counts from streamed responses unless asked.
45
+ includeUsage: true,
46
+ ...Object.keys(headers).length > 0 ? { headers } : {}
47
+ });
48
+ return client(model.id);
49
+ }
50
+ function buildLanguageModel(config) {
51
+ const { provider, model, baseUrl, apiKey, headers } = config;
52
+ const extraHeaders = Object.keys(headers).length > 0 ? headers : void 0;
53
+ switch (provider.type) {
54
+ case "openai": {
55
+ const client = createOpenAI({
56
+ apiKey,
57
+ ...baseUrl !== void 0 ? { baseURL: baseUrl } : {},
58
+ ...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
59
+ });
60
+ return client.responses(model.id);
61
+ }
62
+ case "anthropic": {
63
+ const client = createAnthropic({
64
+ apiKey,
65
+ ...baseUrl !== void 0 ? { baseURL: baseUrl } : {},
66
+ ...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
67
+ });
68
+ return client(model.id);
69
+ }
70
+ case "google-gemini": {
71
+ const client = createGoogle({
72
+ apiKey,
73
+ ...baseUrl !== void 0 ? { baseURL: baseUrl } : {},
74
+ ...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
75
+ });
76
+ return client(model.id);
77
+ }
78
+ case "moonshot": {
79
+ const client = createMoonshotAI({
80
+ apiKey,
81
+ ...baseUrl !== void 0 ? { baseURL: baseUrl } : {},
82
+ ...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
83
+ });
84
+ return client(model.id);
85
+ }
86
+ case "alibaba": {
87
+ if (baseUrl === void 0) {
88
+ throw new Error(`Provider "alibaba" requires a baseUrl`);
89
+ }
90
+ const client = createAlibaba({
91
+ apiKey,
92
+ baseURL: baseUrl,
93
+ ...extraHeaders !== void 0 ? { headers: extraHeaders } : {}
94
+ });
95
+ return client(model.id);
96
+ }
97
+ case "fireworks":
98
+ case "zai":
99
+ case "together":
100
+ case "custom": {
101
+ return compatibleModel(config);
102
+ }
103
+ default: {
104
+ const _exhaustive = provider.type;
105
+ throw new Error(`Unknown provider "${String(_exhaustive)}"`);
106
+ }
107
+ }
108
+ }
109
+ var COMMON_REASONING_LEVELS = [
110
+ "none",
111
+ "minimal",
112
+ "low",
113
+ "medium",
114
+ "high",
115
+ "xhigh"
116
+ ];
117
+ var VERCEL_AI_REASONING_LEVELS = [
118
+ "provider-default",
119
+ ...COMMON_REASONING_LEVELS
120
+ ];
121
+ function isReasoningLevel(v) {
122
+ return VERCEL_AI_REASONING_LEVELS.some((level) => level === v);
123
+ }
124
+ var EFFORT_ALIASES = { max: "xhigh" };
125
+ var SUPPORTED_REASONING_EFFORTS = [...COMMON_REASONING_LEVELS, "max"];
126
+ function toReasoningLevel(reasoningEffort) {
127
+ if (reasoningEffort === void 0) {
128
+ return void 0;
129
+ }
130
+ const aliased = EFFORT_ALIASES[reasoningEffort];
131
+ if (aliased !== void 0) {
132
+ return aliased;
133
+ }
134
+ return isReasoningLevel(reasoningEffort) ? reasoningEffort : void 0;
135
+ }
136
+ function maxEffortOption(reasoningEffort) {
137
+ return reasoningEffort === "max" ? { reasoningEffort: "max" } : {};
138
+ }
139
+ function toStructuredOutputSpec(responseFormat) {
140
+ if (responseFormat === void 0 || responseFormat.type === "text") {
141
+ return { mode: "text" };
142
+ }
143
+ if (responseFormat.type === "json_object") {
144
+ return { mode: "json" };
145
+ }
146
+ const { json_schema } = responseFormat;
147
+ return {
148
+ mode: "json_schema",
149
+ schema: json_schema.schema ?? { type: "object", properties: {} },
150
+ name: json_schema.name,
151
+ description: json_schema.description,
152
+ strict: json_schema.strict ?? void 0
153
+ };
154
+ }
155
+ function buildOutput(spec) {
156
+ switch (spec.mode) {
157
+ case "text":
158
+ return void 0;
159
+ case "json":
160
+ return Output.json();
161
+ case "json_schema":
162
+ return Output.object({
163
+ schema: jsonSchema(spec.schema),
164
+ name: spec.name,
165
+ ...spec.description !== void 0 ? { description: spec.description } : {}
166
+ });
167
+ default: {
168
+ const _exhaustive = spec;
169
+ throw new Error(`Unknown structured output mode: ${JSON.stringify(_exhaustive)}`);
170
+ }
171
+ }
172
+ }
173
+ function readBodyField({ rawBody, key }) {
174
+ const val = Reflect.get(Object(rawBody), key);
175
+ return val !== void 0 ? val : void 0;
176
+ }
177
+ function openaiProviderOptions({
178
+ rawBody,
179
+ strictJsonSchema,
180
+ reasoningEffort
181
+ }) {
182
+ const serviceTier = readBodyField({ rawBody, key: "service_tier" });
183
+ const user = readBodyField({ rawBody, key: "user" });
184
+ const promptCacheKey = readBodyField({ rawBody, key: "prompt_cache_key" });
185
+ const parallelToolCalls = readBodyField({ rawBody, key: "parallel_tool_calls" });
186
+ const reasoningSummary = readBodyField({ rawBody, key: "reasoning_summary" });
187
+ return {
188
+ store: false,
189
+ include: ["reasoning.encrypted_content"],
190
+ reasoningSummary: "auto",
191
+ // gpt-5.6 serves both xhigh and max, so the aliased top-level level asks for one rung less.
192
+ ...maxEffortOption(reasoningEffort),
193
+ ...reasoningSummary !== void 0 ? { reasoningSummary } : {},
194
+ ...strictJsonSchema !== void 0 ? { strictJsonSchema } : {},
195
+ ...serviceTier !== void 0 ? { serviceTier } : {},
196
+ ...user !== void 0 ? { user } : {},
197
+ ...promptCacheKey !== void 0 ? { promptCacheKey } : {},
198
+ ...parallelToolCalls !== void 0 ? { parallelToolCalls } : {}
199
+ };
200
+ }
201
+ function anthropicProviderOptions(rawBody) {
202
+ const cacheControl = readBodyField({ rawBody, key: "cache_control" }) ?? { type: "ephemeral" };
203
+ const disableParallelToolUse = readBodyField({ rawBody, key: "disable_parallel_tool_use" });
204
+ const thinking = readBodyField({ rawBody, key: "thinking" });
205
+ const effort = readBodyField({ rawBody, key: "effort" });
206
+ const opts = {
207
+ cacheControl,
208
+ ...disableParallelToolUse !== void 0 ? { disableParallelToolUse } : {},
209
+ ...thinking !== void 0 ? { thinking } : {},
210
+ ...effort !== void 0 ? { effort } : {}
211
+ };
212
+ return opts;
213
+ }
214
+ function googleGeminiThinkingConfig({
215
+ rawBody,
216
+ reasoningRequested
217
+ }) {
218
+ const fromBody = readBodyField({ rawBody, key: "thinking_config" });
219
+ if (!reasoningRequested) {
220
+ return fromBody;
221
+ }
222
+ if (typeof fromBody === "object" && fromBody !== null && !Array.isArray(fromBody)) {
223
+ return { includeThoughts: true, ...fromBody };
224
+ }
225
+ return { includeThoughts: true };
226
+ }
227
+ function googleGeminiProviderOptions({
228
+ rawBody,
229
+ reasoningRequested
230
+ }) {
231
+ const safetySettings = readBodyField({ rawBody, key: "safety_settings" });
232
+ const thinkingConfig = googleGeminiThinkingConfig({ rawBody, reasoningRequested });
233
+ const cachedContent = readBodyField({ rawBody, key: "cached_content" });
234
+ const opts = {
235
+ ...safetySettings !== void 0 ? { safetySettings } : {},
236
+ ...thinkingConfig !== void 0 ? { thinkingConfig } : {},
237
+ ...cachedContent !== void 0 ? { cachedContent } : {}
238
+ };
239
+ return Object.keys(opts).length > 0 ? opts : void 0;
240
+ }
241
+ function moonshotProviderOptions({
242
+ rawBody,
243
+ reasoningEffort
244
+ }) {
245
+ const thinking = readBodyField({ rawBody, key: "thinking" });
246
+ const reasoningHistory = readBodyField({ rawBody, key: "reasoning_history" });
247
+ const opts = {
248
+ // Moonshot's own ceiling is `max`; the aliased `xhigh` is not one of its levels.
249
+ ...maxEffortOption(reasoningEffort),
250
+ ...thinking !== void 0 ? { thinking } : {},
251
+ ...reasoningHistory !== void 0 ? { reasoningHistory } : {}
252
+ };
253
+ return Object.keys(opts).length > 0 ? opts : void 0;
254
+ }
255
+ function alibabaProviderOptions(rawBody) {
256
+ const enableThinking = readBodyField({ rawBody, key: "enable_thinking" });
257
+ const thinkingBudget = readBodyField({ rawBody, key: "thinking_budget" });
258
+ const parallelToolCalls = readBodyField({ rawBody, key: "parallel_tool_calls" });
259
+ const opts = {
260
+ ...enableThinking !== void 0 ? { enableThinking } : {},
261
+ ...thinkingBudget !== void 0 ? { thinkingBudget } : {},
262
+ ...parallelToolCalls !== void 0 ? { parallelToolCalls } : {}
263
+ };
264
+ return Object.keys(opts).length > 0 ? opts : void 0;
265
+ }
266
+ var COMPATIBLE_BODY_FIELDS = [
267
+ "service_tier",
268
+ "user",
269
+ "prompt_cache_key",
270
+ "parallel_tool_calls",
271
+ "thinking",
272
+ "thinking_budget",
273
+ "enable_thinking",
274
+ "reasoning_history"
275
+ ];
276
+ function compatibleProviderOptions({
277
+ strictJsonSchema,
278
+ reasoningEffort,
279
+ rawBody
280
+ }) {
281
+ const forwarded = Object.fromEntries(
282
+ COMPATIBLE_BODY_FIELDS.flatMap((key) => {
283
+ const value = readBodyField({ rawBody, key });
284
+ return value === void 0 ? [] : [[key, value]];
285
+ })
286
+ );
287
+ const opts = {
288
+ // These endpoints discard an effort they do not recognise, and `xhigh` is one of those.
289
+ ...maxEffortOption(reasoningEffort),
290
+ ...forwarded,
291
+ ...strictJsonSchema !== void 0 ? { strictJsonSchema } : {}
292
+ };
293
+ return Object.keys(opts).length > 0 ? opts : void 0;
294
+ }
295
+ function buildProviderOptions({
296
+ config,
297
+ reasoningEffort,
298
+ structuredOutputSpec,
299
+ rawBody
300
+ }) {
301
+ const strictJsonSchema = structuredOutputSpec.mode === "json_schema" ? structuredOutputSpec.strict : void 0;
302
+ if (config.provider.type === "openai") {
303
+ return { openai: openaiProviderOptions({ rawBody, strictJsonSchema, reasoningEffort }) };
304
+ } else if (config.provider.type === "anthropic") {
305
+ const anthropic = anthropicProviderOptions(rawBody);
306
+ return anthropic !== void 0 ? { anthropic } : {};
307
+ } else if (config.provider.type === "google-gemini") {
308
+ const google = googleGeminiProviderOptions({ rawBody, reasoningRequested: reasoningEffort !== void 0 });
309
+ return google !== void 0 ? { google } : {};
310
+ } else if (config.provider.type === "moonshot") {
311
+ const moonshotai = moonshotProviderOptions({ rawBody, reasoningEffort });
312
+ return moonshotai !== void 0 ? { moonshotai } : {};
313
+ } else if (config.provider.type === "alibaba") {
314
+ const alibaba = alibabaProviderOptions(rawBody);
315
+ return alibaba !== void 0 ? { alibaba } : {};
316
+ } else {
317
+ const compatible = compatibleProviderOptions({ strictJsonSchema, reasoningEffort, rawBody });
318
+ return compatible !== void 0 ? { [config.provider.type]: compatible } : {};
319
+ }
320
+ }
321
+ function resolveMaxOutputTokens(body) {
322
+ const limit = body.max_completion_tokens ?? Reflect.get(body, "max_tokens");
323
+ return typeof limit === "number" ? limit : void 0;
324
+ }
325
+ function parseMimeFromDataUri(uri) {
326
+ const match = /^data:([^;,]+)/.exec(uri);
327
+ return match?.[1];
328
+ }
329
+ function toFilePart(file) {
330
+ const { file_data, filename } = file;
331
+ if (!file_data) return void 0;
332
+ const mediaType = parseMimeFromDataUri(file_data) ?? "application/octet-stream";
333
+ return {
334
+ type: "file",
335
+ data: file_data,
336
+ mediaType,
337
+ ...filename !== void 0 ? { filename } : {}
338
+ };
339
+ }
340
+ function toUserContent(content) {
341
+ if (typeof content === "string") {
342
+ return content;
343
+ }
344
+ const parts = [];
345
+ for (const part of content) {
346
+ if (part.type === "text") {
347
+ parts.push({ type: "text", text: part.text });
348
+ continue;
349
+ }
350
+ if (part.type === "image_url") {
351
+ const url = part.image_url.url;
352
+ const mediaType = parseMimeFromDataUri(url) ?? "image/*";
353
+ parts.push({ type: "file", data: url, mediaType });
354
+ continue;
355
+ }
356
+ if (part.type === "file") {
357
+ const filePart = toFilePart(part.file);
358
+ if (filePart !== void 0) {
359
+ parts.push(filePart);
360
+ }
361
+ continue;
362
+ }
363
+ }
364
+ return parts;
365
+ }
366
+ function toAssistantModelMessage({
367
+ msg,
368
+ provider,
369
+ providerName,
370
+ logger
371
+ }) {
372
+ const parts = [];
373
+ const rawThinking = Reflect.get(msg, "thinking_blocks");
374
+ const attachSignature = shouldAttachReasoningSignature({
375
+ source: Reflect.get(msg, "source"),
376
+ provider,
377
+ providerName,
378
+ logger
379
+ });
380
+ if (Array.isArray(rawThinking) && provider !== "alibaba") {
381
+ const blocks = rawThinking;
382
+ for (const tb of blocks) {
383
+ if (typeof tb === "object" && tb !== null && "type" in tb && "thinking" in tb && tb.type === "thinking" && typeof tb.thinking === "string") {
384
+ const signature = "signature" in tb && typeof tb.signature === "string" ? tb.signature : void 0;
385
+ let reasoningProviderOptions;
386
+ if (signature !== void 0 && attachSignature) {
387
+ if (provider === "openai") {
388
+ reasoningProviderOptions = { openai: { reasoningEncryptedContent: signature } };
389
+ } else if (provider === "anthropic") {
390
+ reasoningProviderOptions = { anthropic: { signature } };
391
+ }
392
+ }
393
+ const reasoningPart = {
394
+ type: "reasoning",
395
+ text: tb.thinking,
396
+ ...reasoningProviderOptions !== void 0 ? { providerOptions: reasoningProviderOptions } : {}
397
+ };
398
+ parts.push(reasoningPart);
399
+ }
400
+ }
401
+ }
402
+ const rawContent = msg.content;
403
+ if (rawContent) {
404
+ const text = typeof rawContent === "string" ? rawContent : rawContent.filter((p) => p.type === "text").map((p) => p.text).join("");
405
+ if (text) {
406
+ const textPart = { type: "text", text };
407
+ parts.push(textPart);
408
+ }
409
+ }
410
+ if (msg.tool_calls?.length) {
411
+ for (const tc of msg.tool_calls) {
412
+ if (!isFunctionToolCall(tc)) {
413
+ continue;
414
+ }
415
+ let input = {};
416
+ try {
417
+ const parsed = JSON.parse(tc.function.arguments);
418
+ if (isPlainObject(parsed)) {
419
+ input = parsed;
420
+ }
421
+ } catch {
422
+ }
423
+ const rawProviderFields = Reflect.get(tc, "provider_specific_fields");
424
+ const thoughtSignature = isPlainObject(rawProviderFields) && typeof rawProviderFields["thought_signature"] === "string" ? rawProviderFields["thought_signature"] : void 0;
425
+ const toolCallPart = {
426
+ type: "tool-call",
427
+ toolCallId: tc.id,
428
+ toolName: tc.function.name,
429
+ input,
430
+ ...thoughtSignature !== void 0 ? { providerOptions: { google: { thoughtSignature } } } : {}
431
+ };
432
+ parts.push(toolCallPart);
433
+ }
434
+ }
435
+ return {
436
+ role: "assistant",
437
+ content: parts.length > 0 ? parts : [{ type: "text", text: "" }]
438
+ };
439
+ }
440
+ function parseAssistantMessageSource(source) {
441
+ const [providerType, providerName, modelName, ...rest] = source.split("/");
442
+ if (rest.length > 0 || !providerType || !providerName || !modelName) {
443
+ return void 0;
444
+ }
445
+ return { providerType, providerName, modelName };
446
+ }
447
+ function shouldAttachReasoningSignature({
448
+ source,
449
+ provider,
450
+ providerName,
451
+ logger
452
+ }) {
453
+ if (source === void 0) {
454
+ return false;
455
+ }
456
+ if (typeof source !== "string") {
457
+ logger?.warn("Ignoring non-string assistant message source; skipping reasoning signature replay", { source });
458
+ return false;
459
+ }
460
+ const parsed = parseAssistantMessageSource(source);
461
+ if (parsed === void 0) {
462
+ logger?.warn("Ignoring malformed assistant message source; skipping reasoning signature replay", { source });
463
+ return false;
464
+ }
465
+ return parsed.providerType === provider && parsed.providerName === providerName;
466
+ }
467
+ function convertMessages({
468
+ messages,
469
+ provider,
470
+ providerName,
471
+ logger
472
+ }) {
473
+ const toolNameById = /* @__PURE__ */ new Map();
474
+ for (const msg of messages) {
475
+ if (msg.role === "assistant" && msg.tool_calls) {
476
+ for (const tc of msg.tool_calls) {
477
+ if (!isFunctionToolCall(tc)) {
478
+ continue;
479
+ }
480
+ toolNameById.set(tc.id, tc.function.name);
481
+ }
482
+ }
483
+ }
484
+ const systemParts = [];
485
+ const result = [];
486
+ for (const msg of messages) {
487
+ if (msg.role === "system") {
488
+ const content = typeof msg.content === "string" ? msg.content : msg.content.map((p) => p.text).join("");
489
+ systemParts.push(content);
490
+ continue;
491
+ }
492
+ if (msg.role === "user") {
493
+ result.push({ role: "user", content: toUserContent(msg.content) });
494
+ continue;
495
+ }
496
+ if (msg.role === "assistant") {
497
+ result.push(toAssistantModelMessage({ msg, provider, providerName, logger }));
498
+ continue;
499
+ }
500
+ if (msg.role === "tool") {
501
+ const toolName = toolNameById.get(msg.tool_call_id) ?? "";
502
+ const toolContent = [
503
+ {
504
+ type: "tool-result",
505
+ toolCallId: msg.tool_call_id,
506
+ toolName,
507
+ output: {
508
+ type: "text",
509
+ value: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
510
+ }
511
+ }
512
+ ];
513
+ result.push({ role: "tool", content: toolContent });
514
+ continue;
515
+ }
516
+ }
517
+ return { instructions: systemParts.length > 0 ? systemParts.join("\n\n") : void 0, messages: result };
518
+ }
519
+ function convertTools(tools) {
520
+ if (!tools?.length) {
521
+ return void 0;
522
+ }
523
+ const toolSet = {};
524
+ for (const t of tools) {
525
+ if (!isFunctionTool(t)) {
526
+ continue;
527
+ }
528
+ toolSet[t.function.name] = {
529
+ inputSchema: jsonSchema(t.function.parameters ?? { type: "object", properties: {} }),
530
+ ...t.function.description !== void 0 ? { description: t.function.description } : {}
531
+ };
532
+ }
533
+ return Object.keys(toolSet).length > 0 ? toolSet : void 0;
534
+ }
535
+ function buildStreamTextArgs(input) {
536
+ const {
537
+ model,
538
+ instructions,
539
+ messages,
540
+ tools,
541
+ reasoning,
542
+ providerOptions,
543
+ maxOutputTokens,
544
+ temperature,
545
+ topP,
546
+ topK,
547
+ presencePenalty,
548
+ frequencyPenalty,
549
+ stopSequences,
550
+ seed,
551
+ abortSignal
552
+ } = input;
553
+ return {
554
+ model,
555
+ ...instructions !== void 0 ? { instructions } : {},
556
+ messages,
557
+ ...tools !== void 0 ? { tools } : {},
558
+ ...reasoning !== void 0 ? { reasoning } : {},
559
+ ...maxOutputTokens !== void 0 ? { maxOutputTokens } : {},
560
+ ...temperature != null ? { temperature } : {},
561
+ ...topP != null ? { topP } : {},
562
+ ...topK != null ? { topK } : {},
563
+ ...presencePenalty != null ? { presencePenalty } : {},
564
+ ...frequencyPenalty != null ? { frequencyPenalty } : {},
565
+ ...stopSequences != null ? { stopSequences } : {},
566
+ ...seed != null ? { seed } : {},
567
+ ...Object.keys(providerOptions).length > 0 ? { providerOptions } : {},
568
+ ...abortSignal !== void 0 ? { abortSignal } : {},
569
+ maxRetries: 0
570
+ };
571
+ }
572
+ function normalizeUsage(usage) {
573
+ const input = usage.inputTokens ?? 0;
574
+ const output = usage.outputTokens ?? 0;
575
+ const costInUsd = usage.raw?.["costInUSD"];
576
+ return {
577
+ input_tokens: input,
578
+ output_tokens: output,
579
+ total_tokens: input + output,
580
+ cache_read_tokens: usage.inputTokenDetails.cacheReadTokens ?? void 0,
581
+ cache_write_tokens: usage.inputTokenDetails.cacheWriteTokens ?? void 0,
582
+ reasoning_tokens: usage.outputTokenDetails.reasoningTokens ?? void 0,
583
+ cost_in_usd: typeof costInUsd === "number" && costInUsd >= 0 ? costInUsd : void 0
584
+ };
585
+ }
586
+ function describeStreamError(raw) {
587
+ if (APICallError.isInstance(raw)) {
588
+ if (raw.statusCode != null) {
589
+ return `Request failed (${String(raw.statusCode)}): ${raw.message}`;
590
+ }
591
+ return raw.message;
592
+ }
593
+ return describeUnknownError(raw);
594
+ }
595
+ function toStreamError(raw) {
596
+ if (raw instanceof Error) return raw;
597
+ return new Error(describeStreamError(raw), { cause: raw });
598
+ }
599
+ function mapFinishReason(reason) {
600
+ switch (reason) {
601
+ case "stop":
602
+ return "stop";
603
+ case "length":
604
+ return "length";
605
+ case "tool-calls":
606
+ return "tool_calls";
607
+ case "content-filter":
608
+ return "content_filter";
609
+ // No harness equivalent for these — fall back to 'stop'.
610
+ case "error":
611
+ case "other":
612
+ return "stop";
613
+ default: {
614
+ const _exhaustive = reason;
615
+ throw new Error(`Unknown finish reason: ${String(_exhaustive)}`);
616
+ }
617
+ }
618
+ }
619
+ function applyReasoningSignature({
620
+ block,
621
+ providerMetadata
622
+ }) {
623
+ if (providerMetadata === void 0) {
624
+ return;
625
+ }
626
+ for (const meta of Object.values(providerMetadata)) {
627
+ if ("reasoningEncryptedContent" in meta && typeof meta["reasoningEncryptedContent"] === "string") {
628
+ block.signature = meta["reasoningEncryptedContent"];
629
+ return;
630
+ }
631
+ if ("signature" in meta && typeof meta["signature"] === "string") {
632
+ block.signature = meta["signature"];
633
+ return;
634
+ }
635
+ }
636
+ }
637
+ function reasoningItemId(providerMetadata) {
638
+ if (providerMetadata === void 0) {
639
+ return void 0;
640
+ }
641
+ for (const meta of Object.values(providerMetadata)) {
642
+ if ("itemId" in meta && typeof meta["itemId"] === "string") {
643
+ return meta["itemId"];
644
+ }
645
+ }
646
+ return void 0;
647
+ }
648
+ function describeCallWarning(warning) {
649
+ switch (warning.type) {
650
+ case "unsupported":
651
+ case "compatibility":
652
+ return warning.details !== void 0 ? `${warning.type}: ${warning.feature} (${warning.details})` : `${warning.type}: ${warning.feature}`;
653
+ case "deprecated":
654
+ return `deprecated: ${warning.setting} - ${warning.message}`;
655
+ case "other":
656
+ return `other: ${warning.message}`;
657
+ default: {
658
+ const _exhaustive = warning;
659
+ throw new Error(`Unknown call warning: ${JSON.stringify(_exhaustive)}`);
660
+ }
661
+ }
662
+ }
663
+ async function* mapStreamToChunks({
664
+ stream,
665
+ chunkMeta
666
+ }) {
667
+ const makeBase = () => ({
668
+ id: chunkMeta.id,
669
+ object: "chat.completion.chunk",
670
+ created: chunkMeta.created,
671
+ model: chunkMeta.model
672
+ });
673
+ const toolCallStates = /* @__PURE__ */ new Map();
674
+ let nextToolIndex = 0;
675
+ let accumulatedText = "";
676
+ const accumulatedThinking = [];
677
+ const thinkingByReasoningItem = /* @__PURE__ */ new Map();
678
+ let currentThinkingBlock = null;
679
+ const openThinkingBlock = (providerMetadata) => {
680
+ const itemId = reasoningItemId(providerMetadata);
681
+ const started = itemId !== void 0 ? thinkingByReasoningItem.get(itemId) : void 0;
682
+ if (started !== void 0) {
683
+ if (started.thinking.length > 0) {
684
+ started.thinking += "\n\n";
685
+ }
686
+ return started;
687
+ }
688
+ const block = { type: "thinking", thinking: "" };
689
+ accumulatedThinking.push(block);
690
+ if (itemId !== void 0) {
691
+ thinkingByReasoningItem.set(itemId, block);
692
+ }
693
+ return block;
694
+ };
695
+ let finalUsage = getEmptyUsage();
696
+ let finalFinishReason = "stop";
697
+ for await (const part of stream) {
698
+ switch (part.type) {
699
+ case "text-delta": {
700
+ accumulatedText += part.text;
701
+ yield {
702
+ ...makeBase(),
703
+ choices: [
704
+ {
705
+ index: 0,
706
+ delta: { content: part.text, role: "assistant" },
707
+ finish_reason: null,
708
+ logprobs: null
709
+ }
710
+ ]
711
+ };
712
+ break;
713
+ }
714
+ case "reasoning-start": {
715
+ currentThinkingBlock = openThinkingBlock(part.providerMetadata);
716
+ break;
717
+ }
718
+ case "reasoning-delta": {
719
+ currentThinkingBlock ??= openThinkingBlock(part.providerMetadata);
720
+ currentThinkingBlock.thinking += part.text;
721
+ applyReasoningSignature({ block: currentThinkingBlock, providerMetadata: part.providerMetadata });
722
+ yield {
723
+ ...makeBase(),
724
+ choices: [
725
+ {
726
+ index: 0,
727
+ delta: {
728
+ thinking_blocks: [{ type: "thinking", thinking: part.text }],
729
+ reasoning_content: part.text
730
+ },
731
+ finish_reason: null,
732
+ logprobs: null
733
+ }
734
+ ]
735
+ };
736
+ break;
737
+ }
738
+ case "reasoning-end": {
739
+ if (currentThinkingBlock !== null) {
740
+ applyReasoningSignature({ block: currentThinkingBlock, providerMetadata: part.providerMetadata });
741
+ }
742
+ currentThinkingBlock = null;
743
+ break;
744
+ }
745
+ case "tool-input-start": {
746
+ const idx = nextToolIndex++;
747
+ const googleMeta = part.providerMetadata?.["google"];
748
+ const thoughtSignature = googleMeta !== void 0 && typeof googleMeta["thoughtSignature"] === "string" ? googleMeta["thoughtSignature"] : void 0;
749
+ toolCallStates.set(part.id, {
750
+ index: idx,
751
+ id: part.id,
752
+ name: part.toolName,
753
+ arguments: "",
754
+ thoughtSignature
755
+ });
756
+ yield {
757
+ ...makeBase(),
758
+ choices: [
759
+ {
760
+ index: 0,
761
+ delta: {
762
+ tool_calls: [
763
+ {
764
+ index: idx,
765
+ id: part.id,
766
+ type: "function",
767
+ function: { name: part.toolName, arguments: "" }
768
+ }
769
+ ]
770
+ },
771
+ finish_reason: null,
772
+ logprobs: null
773
+ }
774
+ ]
775
+ };
776
+ break;
777
+ }
778
+ case "tool-input-delta": {
779
+ const state = toolCallStates.get(part.id);
780
+ if (state === void 0) {
781
+ break;
782
+ }
783
+ state.arguments += part.delta;
784
+ yield {
785
+ ...makeBase(),
786
+ choices: [
787
+ {
788
+ index: 0,
789
+ delta: {
790
+ tool_calls: [{ index: state.index, function: { arguments: part.delta } }]
791
+ },
792
+ finish_reason: null,
793
+ logprobs: null
794
+ }
795
+ ]
796
+ };
797
+ break;
798
+ }
799
+ case "finish-step": {
800
+ finalUsage = normalizeUsage(part.usage);
801
+ finalFinishReason = mapFinishReason(part.finishReason);
802
+ yield {
803
+ ...makeBase(),
804
+ choices: [
805
+ {
806
+ index: 0,
807
+ delta: {},
808
+ finish_reason: finalFinishReason,
809
+ logprobs: null
810
+ }
811
+ ],
812
+ usage: finalUsage
813
+ };
814
+ break;
815
+ }
816
+ case "error": {
817
+ const raw = part.error;
818
+ const message = describeStreamError(raw);
819
+ const cause = raw instanceof Error ? raw : new Error(message);
820
+ throw new Error(message, { cause });
821
+ }
822
+ case "abort": {
823
+ const aborted = new Error("LLM stream aborted");
824
+ aborted.name = "AbortError";
825
+ throw aborted;
826
+ }
827
+ case "start":
828
+ case "text-start":
829
+ case "text-end":
830
+ case "custom":
831
+ case "tool-input-end":
832
+ case "source":
833
+ case "file":
834
+ case "reasoning-file":
835
+ case "tool-call":
836
+ case "tool-result":
837
+ case "tool-error":
838
+ case "tool-output-denied":
839
+ case "tool-approval-request":
840
+ case "tool-approval-response":
841
+ case "start-step":
842
+ case "finish":
843
+ case "raw":
844
+ break;
845
+ default: {
846
+ const _exhaustive = part;
847
+ throw new Error(`Unknown stream part type: ${JSON.stringify(_exhaustive)}`);
848
+ }
849
+ }
850
+ }
851
+ const toolCalls = [...toolCallStates.values()].sort((a, b) => a.index - b.index).map((tc) => ({
852
+ id: tc.id,
853
+ type: "function",
854
+ function: { name: tc.name, arguments: tc.arguments },
855
+ ...tc.thoughtSignature !== void 0 ? { provider_specific_fields: { thought_signature: tc.thoughtSignature } } : {}
856
+ }));
857
+ const output = {
858
+ role: "assistant",
859
+ content: accumulatedText || null,
860
+ ...accumulatedThinking.length > 0 ? { thinking_blocks: accumulatedThinking } : {},
861
+ ...toolCalls.length > 0 ? { tool_calls: toolCalls } : {}
862
+ };
863
+ return { usage: finalUsage, output, finish_reason: finalFinishReason };
864
+ }
865
+ var VercelAILLM = class {
866
+ config;
867
+ logger;
868
+ signal;
869
+ constructor(config) {
870
+ this.config = config;
871
+ this.logger = config.logger;
872
+ this.signal = config.signal;
873
+ }
874
+ async *create(body) {
875
+ const { providerConfig } = this.config;
876
+ const languageModel = buildLanguageModel(providerConfig);
877
+ const { provider, model } = providerConfig;
878
+ const { instructions, messages } = convertMessages({
879
+ messages: body.messages,
880
+ provider: provider.type,
881
+ providerName: provider.name,
882
+ logger: this.logger
883
+ });
884
+ const tools = convertTools(body.tools ?? void 0);
885
+ const structuredOutputSpec = toStructuredOutputSpec(body.response_format);
886
+ const output = buildOutput(structuredOutputSpec);
887
+ const rawReasoningEffort = Reflect.get(body, "reasoning_effort");
888
+ const reasoningEffort = typeof rawReasoningEffort === "string" ? rawReasoningEffort : void 0;
889
+ const providerOptions = buildProviderOptions({
890
+ config: providerConfig,
891
+ reasoningEffort,
892
+ structuredOutputSpec,
893
+ rawBody: body
894
+ });
895
+ const reasoning = toReasoningLevel(reasoningEffort);
896
+ const rawTopK = Reflect.get(body, "top_k");
897
+ const rawSeed = Reflect.get(body, "seed");
898
+ const streamTextArgs = buildStreamTextArgs({
899
+ model: languageModel,
900
+ instructions,
901
+ messages,
902
+ tools,
903
+ reasoning,
904
+ providerOptions,
905
+ maxOutputTokens: resolveMaxOutputTokens(body),
906
+ temperature: body.temperature,
907
+ topP: body.top_p,
908
+ topK: typeof rawTopK === "number" ? rawTopK : null,
909
+ presencePenalty: body.presence_penalty,
910
+ frequencyPenalty: body.frequency_penalty,
911
+ stopSequences: typeof body.stop === "string" ? [body.stop] : body.stop ?? null,
912
+ seed: typeof rawSeed === "number" ? rawSeed : null,
913
+ abortSignal: this.signal
914
+ });
915
+ let streamResult;
916
+ try {
917
+ streamResult = streamText({
918
+ ...streamTextArgs,
919
+ ...output !== void 0 ? { output } : {}
920
+ });
921
+ } catch (error) {
922
+ if (this.signal?.aborted) {
923
+ this.logger.debug("LLM call aborted", extractErrorLogFields(error));
924
+ } else {
925
+ this.logger.error("Error creating streaming chat completion", extractErrorLogFields(error));
926
+ }
927
+ throw toStreamError(error);
928
+ }
929
+ void streamResult.warnings.then(
930
+ (warnings) => {
931
+ if (warnings !== void 0 && warnings.length > 0) {
932
+ this.logger.warn("Provider adjusted the request", {
933
+ model: providerConfig.name,
934
+ warnings: warnings.map(describeCallWarning)
935
+ });
936
+ }
937
+ },
938
+ (reason) => {
939
+ this.logger.debug("Provider warnings unavailable", extractErrorLogFields(reason));
940
+ }
941
+ );
942
+ const chunkMeta = {
943
+ id: `vc-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
944
+ created: Math.floor(Date.now() / 1e3),
945
+ model: providerConfig.name
946
+ };
947
+ try {
948
+ const result = yield* mapStreamToChunks({ stream: streamResult.stream, chunkMeta });
949
+ result.output.source = `${provider.type}/${provider.name}/${model.name}`;
950
+ return result;
951
+ } catch (error) {
952
+ if (this.signal?.aborted) {
953
+ this.logger.debug("LLM stream aborted", extractErrorLogFields(error));
954
+ } else {
955
+ this.logger.error("Error reading LLM stream", extractErrorLogFields(error));
956
+ }
957
+ throw toStreamError(error);
958
+ }
959
+ }
960
+ async createNonStream(body) {
961
+ const llmStream = this.create({ ...body, stream: true });
962
+ let result = await llmStream.next();
963
+ while (!result.done) {
964
+ result = await llmStream.next();
965
+ }
966
+ return result.value;
967
+ }
968
+ };
969
+ export {
970
+ SUPPORTED_REASONING_EFFORTS,
971
+ VERCEL_AI_PROVIDER_NAMES,
972
+ VercelAILLM,
973
+ buildLanguageModel,
974
+ buildProviderOptions,
975
+ buildStreamTextArgs,
976
+ convertMessages,
977
+ convertTools,
978
+ describeCallWarning,
979
+ describeStreamError,
980
+ mapFinishReason,
981
+ mapStreamToChunks,
982
+ normalizeUsage,
983
+ parseMimeFromDataUri,
984
+ resolveMaxOutputTokens,
985
+ shouldAttachReasoningSignature,
986
+ toAssistantModelMessage,
987
+ toFilePart,
988
+ toReasoningLevel,
989
+ toStreamError,
990
+ toStructuredOutputSpec,
991
+ toUserContent
992
+ };
993
+ //# sourceMappingURL=VercelAILLM.mjs.map