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