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