@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 @@
1
+ {"version":3,"sources":["../../../src/core/runtime/UserInputMessage.ts"],"sourcesContent":["import type { ChatCompletionContentPart } from 'openai/resources/chat';\nimport { AgentSandboxRequiredError, InvalidFileInputError } from '../errors';\nimport {\n EventType,\n type AgentInputUserMessage,\n type FileContentPart,\n type TextContentPart,\n type UserContentPart,\n} from '../events/schema';\nimport type { LLMUserMessage } from '../llm/LLMTypes';\nimport type { Sandbox, SandboxInfo } from '../sandbox/Sandbox';\nimport type { AgentSendInput } from './AgentThread.types';\nimport { internalSystemTag } from './contextUtils';\n\nexport type { AgentInputUserMessage, FileContentPart, TextContentPart, UserContentPart };\n\nexport type AgentUserMessageContent = AgentInputUserMessage['content'];\nexport type AgentUserContentPart = UserContentPart;\n\nexport function isFileContentPart(part: UserContentPart): part is FileContentPart {\n return part.type === 'file';\n}\n\nexport function isAgentInputUserMessage(msg: AgentSendInput): msg is AgentInputUserMessage {\n return 'type' in msg && msg.type === EventType.USER_MESSAGE;\n}\n\nexport function isEmptyMessageContent(content: AgentUserMessageContent): boolean {\n return typeof content === 'string' ? content.trim().length === 0 : content.length === 0;\n}\n\nconst INLINE_MIME_PREFIXES = ['image/', 'application/pdf'];\n\nfunction isInlineMime(mime: string): boolean {\n return INLINE_MIME_PREFIXES.some(prefix => mime.startsWith(prefix));\n}\n\nfunction isImageMime(mime: string): boolean {\n return mime.startsWith('image/');\n}\n\nfunction parseMimeFromFileData(fileData: string): string {\n const match = /^data:([^;,]+)/.exec(fileData);\n if (!match?.[1]) {\n throw new InvalidFileInputError('File data URI is missing or has unparseable MIME type');\n }\n return match[1];\n}\n\nfunction extractBase64(dataUri: string): Buffer {\n const commaIndex = dataUri.indexOf(',');\n if (commaIndex === -1) {\n throw new InvalidFileInputError('File data URI has no base64 payload');\n }\n const raw = dataUri.substring(commaIndex + 1);\n if (!raw) {\n throw new InvalidFileInputError('File data URI has empty base64 payload');\n }\n const buffer = Buffer.from(raw, 'base64');\n if (buffer.length === 0) {\n throw new InvalidFileInputError('File data URI decoded to zero bytes');\n }\n return buffer;\n}\n\nfunction validatePublicFilename(filename: string): void {\n if (!filename.length) {\n throw new InvalidFileInputError('File name must not be empty');\n }\n const normalized = filename.replace(/\\\\/g, '/');\n const parts = normalized.split('/');\n for (const part of parts) {\n if (part === '..') {\n throw new InvalidFileInputError(`File name contains path traversal: ${filename}`);\n }\n }\n}\n\nfunction buildUploadedFilesAnnouncement(\n files: { filename: string; path: string; mime: string; size: number }[],\n): string {\n const entries = files\n .map(\n (f, i) =>\n `[file_${String(i + 1)}]\\n filename: ${f.filename}\\n path: ${f.path}\\n mime: ${f.mime}\\n size: ${String(f.size)} bytes`,\n )\n .join('\\n\\n');\n return internalSystemTag(`Uploaded files (${String(files.length)}):\\n${entries}`);\n}\n\nfunction partitionContent(parts: readonly AgentUserContentPart[]): {\n fileParts: FileContentPart[];\n textParts: TextContentPart[];\n} {\n const fileParts: FileContentPart[] = [];\n const textParts: TextContentPart[] = [];\n\n for (const part of parts) {\n if (isFileContentPart(part)) {\n fileParts.push(part);\n } else {\n textParts.push(part);\n }\n }\n\n return { fileParts, textParts };\n}\n\nexport interface ProcessAgentUserInputResult {\n message: LLMUserMessage;\n sandboxCreated?: SandboxInfo | undefined;\n}\n\nexport async function processAgentUserInput(\n msg: AgentInputUserMessage,\n sandbox: Sandbox | undefined,\n): Promise<ProcessAgentUserInputResult> {\n if (typeof msg.content === 'string') {\n return { message: { role: 'user', content: msg.content }, sandboxCreated: undefined };\n }\n\n const { fileParts, textParts } = partitionContent(msg.content);\n\n if (fileParts.length === 0) {\n return { message: { role: 'user', content: textParts }, sandboxCreated: undefined };\n }\n\n const modelParts: ChatCompletionContentPart[] = [];\n const filesToUploadToSandbox: { filename: string; buffer: Buffer; mime: string }[] = [];\n\n for (const filePart of fileParts) {\n const filename = filePart.name.replace(/^\\/+/, '');\n if (!filename.length) {\n throw new InvalidFileInputError('File name must not be empty');\n }\n validatePublicFilename(filename);\n\n const file_data = filePart.data;\n const mime = parseMimeFromFileData(file_data);\n\n if (isInlineMime(mime)) {\n modelParts.push(\n isImageMime(mime)\n ? { type: 'image_url', image_url: { url: file_data } }\n : { type: 'file', file: { filename, file_data } },\n );\n } else {\n const buffer = extractBase64(file_data);\n filesToUploadToSandbox.push({ filename, buffer, mime });\n }\n }\n\n let sandboxCreated: SandboxInfo | undefined;\n\n if (filesToUploadToSandbox.length > 0) {\n if (!sandbox) {\n throw new AgentSandboxRequiredError(\n 'File uploads requiring sandbox are not supported: no sandbox configured for this agent',\n );\n }\n\n const uploadResults = await Promise.allSettled(\n filesToUploadToSandbox.map(file =>\n sandbox.uploadUserFile({\n fileName: file.filename,\n content: file.buffer,\n mime: file.mime,\n }),\n ),\n );\n\n const uploadedFiles: { filename: string; path: string; mime: string; size: number }[] = [];\n for (let i = 0; i < uploadResults.length; i++) {\n const result = uploadResults[i];\n const file = filesToUploadToSandbox[i];\n if (result === undefined || file === undefined) {\n throw new Error('Unreachable: uploadResults/files length mismatch');\n }\n if (result.status === 'fulfilled') {\n if (result.value.sandboxCreated) {\n sandboxCreated = result.value.sandboxCreated;\n }\n uploadedFiles.push({\n filename: file.filename,\n path: result.value.filePath,\n mime: file.mime,\n size: file.buffer.length,\n });\n } else {\n throw result.reason;\n }\n }\n if (uploadedFiles.length > 0) {\n modelParts.push({ type: 'text', text: buildUploadedFilesAnnouncement(uploadedFiles) });\n }\n }\n\n modelParts.push(...textParts);\n\n return { message: { role: 'user', content: modelParts }, sandboxCreated };\n}\n"],"mappings":";AACA,SAAS,2BAA2B,6BAA6B;AACjE;AAAA,EACE;AAAA,OAKK;AAIP,SAAS,yBAAyB;AAO3B,SAAS,kBAAkB,MAAgD;AAChF,SAAO,KAAK,SAAS;AACvB;AAEO,SAAS,wBAAwB,KAAmD;AACzF,SAAO,UAAU,OAAO,IAAI,SAAS,UAAU;AACjD;AAEO,SAAS,sBAAsB,SAA2C;AAC/E,SAAO,OAAO,YAAY,WAAW,QAAQ,KAAK,EAAE,WAAW,IAAI,QAAQ,WAAW;AACxF;AAEA,IAAM,uBAAuB,CAAC,UAAU,iBAAiB;AAEzD,SAAS,a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3
+ /**
4
+ * Live context budget for the next LLM call (not billable). The legacy
5
+ * `prompt_tokens`/`completion_tokens` names are load-bearing: this shape is persisted per
6
+ * thread, so renaming them would make already-stored rows load as missing fields.
7
+ */
8
+ export declare const CurrentContextUsageSchema: z.ZodObject<{
9
+ prompt_tokens: z.ZodNumber;
10
+ completion_tokens: z.ZodNumber;
11
+ }, z.core.$strip>;
12
+ export type CurrentContextUsage = z.infer<typeof CurrentContextUsageSchema>;
13
+ export declare function getEmptyCurrentContextUsage(): CurrentContextUsage;
14
+ export declare function mergeCurrentContextUsage(a: CurrentContextUsage, b: CurrentContextUsage): CurrentContextUsage;
15
+ /** Project per-call billable usage onto the live context budget fields. */
16
+ export declare function currentContextUsageFromCompletion(usage: CompletionUsage): CurrentContextUsage;
17
+ //# sourceMappingURL=contextUsage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextUsage.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/contextUsage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;GAIG;AACH,eAAO,MAAM,yBAAyB;;;iBASL,CAAC;AAElC,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAE5E,wBAAgB,2BAA2B,IAAI,mBAAmB,CAEjE;AAED,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,mBAAmB,GAAG,mBAAmB,CAK5G;AAED,2EAA2E;AAC3E,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,eAAe,GAAG,mBAAmB,CAK7F"}
@@ -0,0 +1,56 @@
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/runtime/contextUsage.ts
21
+ var contextUsage_exports = {};
22
+ __export(contextUsage_exports, {
23
+ CurrentContextUsageSchema: () => CurrentContextUsageSchema,
24
+ currentContextUsageFromCompletion: () => currentContextUsageFromCompletion,
25
+ getEmptyCurrentContextUsage: () => getEmptyCurrentContextUsage,
26
+ mergeCurrentContextUsage: () => mergeCurrentContextUsage
27
+ });
28
+ module.exports = __toCommonJS(contextUsage_exports);
29
+ var import_zod_openapi = require("@hono/zod-openapi");
30
+ var CurrentContextUsageSchema = import_zod_openapi.z.object({
31
+ prompt_tokens: import_zod_openapi.z.number().int().nonnegative().describe("Live prompt-side context tokens for the next LLM call."),
32
+ completion_tokens: import_zod_openapi.z.number().int().nonnegative().describe("Live completion-side context tokens for the next LLM call.")
33
+ }).openapi("CurrentContextUsage");
34
+ function getEmptyCurrentContextUsage() {
35
+ return { prompt_tokens: 0, completion_tokens: 0 };
36
+ }
37
+ function mergeCurrentContextUsage(a, b) {
38
+ return {
39
+ prompt_tokens: a.prompt_tokens + b.prompt_tokens,
40
+ completion_tokens: a.completion_tokens + b.completion_tokens
41
+ };
42
+ }
43
+ function currentContextUsageFromCompletion(usage) {
44
+ return {
45
+ prompt_tokens: usage.input_tokens,
46
+ completion_tokens: usage.output_tokens
47
+ };
48
+ }
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ CurrentContextUsageSchema,
52
+ currentContextUsageFromCompletion,
53
+ getEmptyCurrentContextUsage,
54
+ mergeCurrentContextUsage
55
+ });
56
+ //# sourceMappingURL=contextUsage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/core/runtime/contextUsage.ts"],"sourcesContent":["import { z } from '@hono/zod-openapi';\nimport type { CompletionUsage } from '../llm/LLMTypes';\n\n/**\n * Live context budget for the next LLM call (not billable). The legacy\n * `prompt_tokens`/`completion_tokens` names are load-bearing: this shape is persisted per\n * thread, so renaming them would make already-stored rows load as missing fields.\n */\nexport const CurrentContextUsageSchema = z\n .object({\n prompt_tokens: z.number().int().nonnegative().describe('Live prompt-side context tokens for the next LLM call.'),\n completion_tokens: z\n .number()\n .int()\n .nonnegative()\n .describe('Live completion-side context tokens for the next LLM call.'),\n })\n .openapi('CurrentContextUsage');\n\nexport type CurrentContextUsage = z.infer<typeof CurrentContextUsageSchema>;\n\nexport function getEmptyCurrentContextUsage(): CurrentContextUsage {\n return { prompt_tokens: 0, completion_tokens: 0 };\n}\n\nexport function mergeCurrentContextUsage(a: CurrentContextUsage, b: CurrentContextUsage): CurrentContextUsage {\n return {\n prompt_tokens: a.prompt_tokens + b.prompt_tokens,\n completion_tokens: a.completion_tokens + b.completion_tokens,\n };\n}\n\n/** Project per-call billable usage onto the live context budget fields. */\nexport function currentContextUsageFromCompletion(usage: CompletionUsage): CurrentContextUsage {\n return {\n prompt_tokens: usage.input_tokens,\n completion_tokens: usage.output_tokens,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAkB;AAQX,IAAM,4BAA4B,qBACtC,OAAO;AAAA,EACN,eAAe,qBAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,wDAAwD;AAAA,EAC/G,mBAAmB,qBAChB,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,SAAS,4DAA4D;AAC1E,CAAC,EACA,QAAQ,qBAAqB;AAIzB,SAAS,8BAAmD;AACjE,SAAO,EAAE,eAAe,GAAG,mBAAmB,EAAE;AAClD;AAEO,SAAS,yBAAyB,GAAwB,GAA6C;AAC5G,SAAO;AAAA,IACL,eAAe,EAAE,gBAAgB,EAAE;AAAA,IACnC,mBAAmB,EAAE,oBAAoB,EAAE;AAAA,EAC7C;AACF;AAGO,SAAS,kCAAkC,OAA6C;AAC7F,SAAO;AAAA,IACL,eAAe,MAAM;AAAA,IACrB,mBAAmB,MAAM;AAAA,EAC3B;AACF;","names":[]}
@@ -0,0 +1,28 @@
1
+ // src/core/runtime/contextUsage.ts
2
+ import { z } from "@hono/zod-openapi";
3
+ var CurrentContextUsageSchema = z.object({
4
+ prompt_tokens: z.number().int().nonnegative().describe("Live prompt-side context tokens for the next LLM call."),
5
+ completion_tokens: z.number().int().nonnegative().describe("Live completion-side context tokens for the next LLM call.")
6
+ }).openapi("CurrentContextUsage");
7
+ function getEmptyCurrentContextUsage() {
8
+ return { prompt_tokens: 0, completion_tokens: 0 };
9
+ }
10
+ function mergeCurrentContextUsage(a, b) {
11
+ return {
12
+ prompt_tokens: a.prompt_tokens + b.prompt_tokens,
13
+ completion_tokens: a.completion_tokens + b.completion_tokens
14
+ };
15
+ }
16
+ function currentContextUsageFromCompletion(usage) {
17
+ return {
18
+ prompt_tokens: usage.input_tokens,
19
+ completion_tokens: usage.output_tokens
20
+ };
21
+ }
22
+ export {
23
+ CurrentContextUsageSchema,
24
+ currentContextUsageFromCompletion,
25
+ getEmptyCurrentContextUsage,
26
+ mergeCurrentContextUsage
27
+ };
28
+ //# sourceMappingURL=contextUsage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/core/runtime/contextUsage.ts"],"sourcesContent":["import { z } from '@hono/zod-openapi';\nimport type { CompletionUsage } from '../llm/LLMTypes';\n\n/**\n * Live context budget for the next LLM call (not billable). The legacy\n * `prompt_tokens`/`completion_tokens` names are load-bearing: this shape is persisted per\n * thread, so renaming them would make already-stored rows load as missing fields.\n */\nexport const CurrentContextUsageSchema = z\n .object({\n prompt_tokens: z.number().int().nonnegative().describe('Live prompt-side context tokens for the next LLM call.'),\n completion_tokens: z\n .number()\n .int()\n .nonnegative()\n .describe('Live completion-side context tokens for the next LLM call.'),\n })\n .openapi('CurrentContextUsage');\n\nexport type CurrentContextUsage = z.infer<typeof CurrentContextUsageSchema>;\n\nexport function getEmptyCurrentContextUsage(): CurrentContextUsage {\n return { prompt_tokens: 0, completion_tokens: 0 };\n}\n\nexport function mergeCurrentContextUsage(a: CurrentContextUsage, b: CurrentContextUsage): CurrentContextUsage {\n return {\n prompt_tokens: a.prompt_tokens + b.prompt_tokens,\n completion_tokens: a.completion_tokens + b.completion_tokens,\n };\n}\n\n/** Project per-call billable usage onto the live context budget fields. */\nexport function currentContextUsageFromCompletion(usage: CompletionUsage): CurrentContextUsage {\n return {\n prompt_tokens: usage.input_tokens,\n completion_tokens: usage.output_tokens,\n };\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAQX,IAAM,4BAA4B,EACtC,OAAO;AAAA,EACN,eAAe,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,wDAAwD;AAAA,EAC/G,mBAAmB,EAChB,OAAO,EACP,IAAI,EACJ,YAAY,EACZ,SAAS,4DAA4D;AAC1E,CAAC,EACA,QAAQ,qBAAqB;AAIzB,SAAS,8BAAmD;AACjE,SAAO,EAAE,eAAe,GAAG,mBAAmB,EAAE;AAClD;AAEO,SAAS,yBAAyB,GAAwB,GAA6C;AAC5G,SAAO;AAAA,IACL,eAAe,EAAE,gBAAgB,EAAE;AAAA,IACnC,mBAAmB,EAAE,oBAAoB,EAAE;AAAA,EAC7C;AACF;AAGO,SAAS,kCAAkC,OAA6C;AAC7F,SAAO;AAAA,IACL,eAAe,MAAM;AAAA,IACrB,mBAAmB,MAAM;AAAA,EAC3B;AACF;","names":[]}
@@ -0,0 +1,30 @@
1
+ import type { ApprovalDecision } from '../events/schema';
2
+ import { type UserToolApprovalMessage, type UserToolResponseMessage } from '../events/schema';
3
+ import type { EnrichedToolCall, InternalEnrichedToolCall, InternalToolCallInfo, LLMToolMessage, LLMUserMessage, ToolInfo } from '../llm/LLMTypes';
4
+ import type { AgentThreadRuntimeSendInput, ContextMessage, InternalThreadDoneEvent, LLMContextMessage } from './AgentThread.types';
5
+ import type { CurrentContextUsage } from './contextUsage';
6
+ import type { AgentInputUserMessage } from './UserInputMessage';
7
+ export declare const SYSTEM_TAG_START = "<tfy-internal>";
8
+ export declare const INTERNAL_SYSTEM_PROMPT: string;
9
+ export declare function internalSystemTag(m: string): string;
10
+ export declare function internalSystemMessage(m: string): LLMUserMessage;
11
+ export declare function isLLMContextMessage(msg: ContextMessage): msg is LLMContextMessage;
12
+ export declare function isInternalSystemMessage(m: ContextMessage): boolean;
13
+ export declare function isApprovalDecisionMessage(msg: AgentThreadRuntimeSendInput): msg is UserToolApprovalMessage;
14
+ export declare function isClientSideToolResponseMessage(msg: AgentThreadRuntimeSendInput): msg is UserToolResponseMessage;
15
+ export declare function isInputUserMessage(msg: AgentThreadRuntimeSendInput): msg is AgentInputUserMessage;
16
+ export declare function isLLMToolMessage(msg: AgentThreadRuntimeSendInput): msg is LLMToolMessage;
17
+ export declare function isInternalThreadDoneError(event: InternalThreadDoneEvent): event is InternalThreadDoneEvent & {
18
+ status: 'error';
19
+ };
20
+ export declare function scanApprovalDecisions(context: ContextMessage[]): Map<string, ApprovalDecision>;
21
+ export declare function makeUnknownToolInfo(toolName: string): InternalToolCallInfo;
22
+ export declare function toToolCallInfo(toolInfo: InternalToolCallInfo): ToolInfo;
23
+ export declare function toEnrichedToolCall(toolCall: InternalEnrichedToolCall): EnrichedToolCall;
24
+ export declare function assistantMessageContentToStringForSubAgent(content: string | ({
25
+ type?: string;
26
+ text?: string;
27
+ } | string)[] | null | undefined, errorMessage?: string): string;
28
+ export declare function getThreadId(): string;
29
+ export declare function estimateTokensForContextMessages(messages: ContextMessage[]): CurrentContextUsage;
30
+ //# sourceMappingURL=contextUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contextUtils.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/contextUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAGL,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,QAAQ,EACT,MAAM,iBAAiB,CAAC;AAGzB,OAAO,KAAK,EACV,2BAA2B,EAC3B,cAAc,EACd,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AAEjD,eAAO,MAAM,sBAAsB,QAIlC,CAAC;AAEF,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,MAAM,GAAG,cAAc,CAE/D;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,cAAc,GAAG,GAAG,IAAI,iBAAiB,CAEjF;AAED,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,cAAc,GAAG,OAAO,CAGlE;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,2BAA2B,GAAG,GAAG,IAAI,uBAAuB,CAE1G;AAOD,wBAAgB,+BAA+B,CAAC,GAAG,EAAE,2BAA2B,GAAG,GAAG,IAAI,uBAAuB,CAEhH;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,2BAA2B,GAAG,GAAG,IAAI,qBAAqB,CAEjG;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,2BAA2B,GAAG,GAAG,IAAI,cAAc,CAGxF;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,uBAAuB,GAC7B,KAAK,IAAI,uBAAuB,GAAG;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAExD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAQ9F;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,oBAAoB,CAS1E;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,oBAAoB,GAAG,QAAQ,CAavE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,wBAAwB,GAAG,gBAAgB,CAGvF;AAED,wBAAgB,0CAA0C,CACxD,OAAO,EAAE,MAAM,GAAG,CAAC;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,EAClF,YAAY,CAAC,EAAE,MAAM,GACpB,MAAM,CAWR;AAED,wBAAgB,WAAW,IAAI,MAAM,CAEpC;AAED,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,mBAAmB,CAgChG"}
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/core/runtime/contextUtils.ts
31
+ var contextUtils_exports = {};
32
+ __export(contextUtils_exports, {
33
+ INTERNAL_SYSTEM_PROMPT: () => INTERNAL_SYSTEM_PROMPT,
34
+ SYSTEM_TAG_START: () => SYSTEM_TAG_START,
35
+ assistantMessageContentToStringForSubAgent: () => assistantMessageContentToStringForSubAgent,
36
+ estimateTokensForContextMessages: () => estimateTokensForContextMessages,
37
+ getThreadId: () => getThreadId,
38
+ internalSystemMessage: () => internalSystemMessage,
39
+ internalSystemTag: () => internalSystemTag,
40
+ isApprovalDecisionMessage: () => isApprovalDecisionMessage,
41
+ isClientSideToolResponseMessage: () => isClientSideToolResponseMessage,
42
+ isInputUserMessage: () => isInputUserMessage,
43
+ isInternalSystemMessage: () => isInternalSystemMessage,
44
+ isInternalThreadDoneError: () => isInternalThreadDoneError,
45
+ isLLMContextMessage: () => isLLMContextMessage,
46
+ isLLMToolMessage: () => isLLMToolMessage,
47
+ makeUnknownToolInfo: () => makeUnknownToolInfo,
48
+ scanApprovalDecisions: () => scanApprovalDecisions,
49
+ toEnrichedToolCall: () => toEnrichedToolCall,
50
+ toToolCallInfo: () => toToolCallInfo
51
+ });
52
+ module.exports = __toCommonJS(contextUtils_exports);
53
+ var import_dedent = __toESM(require("dedent"), 1);
54
+ var import_schema = require("../events/schema.js");
55
+ var import_LLMTypes = require("../llm/LLMTypes.js");
56
+ var import_usage = require("../llm/usage.js");
57
+ var SYSTEM_TAG_START = "<tfy-internal>";
58
+ var SYSTEM_TAG_END = "</tfy-internal>";
59
+ var INTERNAL_SYSTEM_PROMPT = import_dedent.default`
60
+ Messages wrapped in tfy-internal tags contain information hidden from the user. The Agent must keep this information in mind when conversing with the user.
61
+ The Agent must never generate any content with tfy-internal tags.
62
+ The Agent cannot generate any content with tfy-internal tags.
63
+ `;
64
+ function internalSystemTag(m) {
65
+ return SYSTEM_TAG_START + m + SYSTEM_TAG_END;
66
+ }
67
+ function internalSystemMessage(m) {
68
+ return { role: "user", content: internalSystemTag(m) };
69
+ }
70
+ function isLLMContextMessage(msg) {
71
+ return "role" in msg;
72
+ }
73
+ function isInternalSystemMessage(m) {
74
+ if (!isLLMContextMessage(m)) return false;
75
+ return m.role === "user" && typeof m.content === "string" && m.content.startsWith(SYSTEM_TAG_START);
76
+ }
77
+ function isApprovalDecisionMessage(msg) {
78
+ return "type" in msg && msg.type === import_schema.EventType.USER_TOOL_APPROVAL;
79
+ }
80
+ function isUserToolApprovalDecisionMessage(msg) {
81
+ return "type" in msg;
82
+ }
83
+ function isClientSideToolResponseMessage(msg) {
84
+ return "type" in msg && msg.type === import_schema.EventType.USER_TOOL_RESPONSE;
85
+ }
86
+ function isInputUserMessage(msg) {
87
+ return "type" in msg && msg.type === import_schema.EventType.USER_MESSAGE;
88
+ }
89
+ function isLLMToolMessage(msg) {
90
+ return "role" in msg;
91
+ }
92
+ function isInternalThreadDoneError(event) {
93
+ return event.status === "error";
94
+ }
95
+ function scanApprovalDecisions(context) {
96
+ const decisions = /* @__PURE__ */ new Map();
97
+ for (const msg of context) {
98
+ if (isUserToolApprovalDecisionMessage(msg)) {
99
+ decisions.set(msg.tool_call_id, msg.approval);
100
+ }
101
+ }
102
+ return decisions;
103
+ }
104
+ function makeUnknownToolInfo(toolName) {
105
+ return {
106
+ type: "mcp",
107
+ mcp_server_id: import_LLMTypes.UNKNOWN_TOOL_NAME,
108
+ mcp_server_name: import_LLMTypes.UNKNOWN_TOOL_NAME,
109
+ original_tool_name: toolName,
110
+ is_approval_required: false,
111
+ is_client_side: false
112
+ };
113
+ }
114
+ function toToolCallInfo(toolInfo) {
115
+ if (toolInfo.type === "mcp") {
116
+ return {
117
+ type: toolInfo.type,
118
+ name: toolInfo.original_tool_name,
119
+ server_id: toolInfo.mcp_server_id,
120
+ server_name: toolInfo.mcp_server_name
121
+ };
122
+ }
123
+ return {
124
+ type: toolInfo.type,
125
+ name: toolInfo.original_tool_name
126
+ };
127
+ }
128
+ function toEnrichedToolCall(toolCall) {
129
+ const { tool_info, ...rest } = toolCall;
130
+ return { ...rest, tool_info: toToolCallInfo(tool_info) };
131
+ }
132
+ function assistantMessageContentToStringForSubAgent(content, errorMessage) {
133
+ let text = "";
134
+ if (typeof content === "string") {
135
+ text = content;
136
+ } else if (Array.isArray(content)) {
137
+ text = content.map((item) => typeof item === "string" ? item : JSON.stringify(item)).join("");
138
+ }
139
+ if (errorMessage) {
140
+ return text ? `${errorMessage}
141
+ ${text}` : errorMessage;
142
+ }
143
+ return text;
144
+ }
145
+ function getThreadId() {
146
+ return crypto.randomUUID();
147
+ }
148
+ function estimateTokensForContextMessages(messages) {
149
+ let tokenCount = 0;
150
+ for (const b of messages) {
151
+ if ("content" in b && b.content) {
152
+ if (typeof b.content === "string") {
153
+ tokenCount += (0, import_usage.estimateTokensForString)(b.content);
154
+ } else if (Array.isArray(b.content)) {
155
+ for (const part of b.content) {
156
+ if ("text" in part && typeof part.text === "string") {
157
+ tokenCount += (0, import_usage.estimateTokensForString)(part.text);
158
+ }
159
+ }
160
+ }
161
+ }
162
+ if ("tool_calls" in b && b.tool_calls) {
163
+ for (const toolCall of b.tool_calls) {
164
+ tokenCount += (0, import_usage.estimateTokensForString)(toolCall.function.name);
165
+ tokenCount += (0, import_usage.estimateTokensForString)(toolCall.function.arguments);
166
+ }
167
+ }
168
+ if ("tool_call_id" in b && b.tool_call_id) {
169
+ tokenCount += (0, import_usage.estimateTokensForString)(b.tool_call_id);
170
+ }
171
+ }
172
+ return {
173
+ prompt_tokens: tokenCount,
174
+ completion_tokens: 0
175
+ };
176
+ }
177
+ // Annotate the CommonJS export names for ESM import in node:
178
+ 0 && (module.exports = {
179
+ INTERNAL_SYSTEM_PROMPT,
180
+ SYSTEM_TAG_START,
181
+ assistantMessageContentToStringForSubAgent,
182
+ estimateTokensForContextMessages,
183
+ getThreadId,
184
+ internalSystemMessage,
185
+ internalSystemTag,
186
+ isApprovalDecisionMessage,
187
+ isClientSideToolResponseMessage,
188
+ isInputUserMessage,
189
+ isInternalSystemMessage,
190
+ isInternalThreadDoneError,
191
+ isLLMContextMessage,
192
+ isLLMToolMessage,
193
+ makeUnknownToolInfo,
194
+ scanApprovalDecisions,
195
+ toEnrichedToolCall,
196
+ toToolCallInfo
197
+ });
198
+ //# sourceMappingURL=contextUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/core/runtime/contextUtils.ts"],"sourcesContent":["import dedent from 'dedent';\nimport type { ApprovalDecision } from '../events/schema';\nimport {\n EventType,\n type AgentApprovalDecisionMessage,\n type UserToolApprovalMessage,\n type UserToolResponseMessage,\n} from '../events/schema';\nimport type {\n EnrichedToolCall,\n InternalEnrichedToolCall,\n InternalToolCallInfo,\n LLMToolMessage,\n LLMUserMessage,\n ToolInfo,\n} from '../llm/LLMTypes';\nimport { UNKNOWN_TOOL_NAME } from '../llm/LLMTypes';\nimport { estimateTokensForString } from '../llm/usage';\nimport type {\n AgentThreadRuntimeSendInput,\n ContextMessage,\n InternalThreadDoneEvent,\n LLMContextMessage,\n} from './AgentThread.types';\nimport type { CurrentContextUsage } from './contextUsage';\nimport type { AgentInputUserMessage } from './UserInputMessage';\n\nexport const SYSTEM_TAG_START = '<tfy-internal>';\nconst SYSTEM_TAG_END = '</tfy-internal>';\nexport const INTERNAL_SYSTEM_PROMPT = dedent`\nMessages wrapped in tfy-internal tags contain information hidden from the user. The Agent must keep this information in mind when conversing with the user.\nThe Agent must never generate any content with tfy-internal tags.\nThe Agent cannot generate any content with tfy-internal tags.\n`;\n\nexport function internalSystemTag(m: string): string {\n return SYSTEM_TAG_START + m + SYSTEM_TAG_END;\n}\n\nexport function internalSystemMessage(m: string): LLMUserMessage {\n return { role: 'user' as const, content: internalSystemTag(m) };\n}\n\nexport function isLLMContextMessage(msg: ContextMessage): msg is LLMContextMessage {\n return 'role' in msg;\n}\n\nexport function isInternalSystemMessage(m: ContextMessage): boolean {\n if (!isLLMContextMessage(m)) return false;\n return m.role === 'user' && typeof m.content === 'string' && m.content.startsWith(SYSTEM_TAG_START);\n}\n\nexport function isApprovalDecisionMessage(msg: AgentThreadRuntimeSendInput): msg is UserToolApprovalMessage {\n return 'type' in msg && msg.type === EventType.USER_TOOL_APPROVAL;\n}\n\nfunction isUserToolApprovalDecisionMessage(msg: ContextMessage): msg is AgentApprovalDecisionMessage {\n // `'type' in msg` already narrows to AgentApprovalDecisionMessage (literal type).\n return 'type' in msg;\n}\n\nexport function isClientSideToolResponseMessage(msg: AgentThreadRuntimeSendInput): msg is UserToolResponseMessage {\n return 'type' in msg && msg.type === EventType.USER_TOOL_RESPONSE;\n}\n\nexport function isInputUserMessage(msg: AgentThreadRuntimeSendInput): msg is AgentInputUserMessage {\n return 'type' in msg && msg.type === EventType.USER_MESSAGE;\n}\n\nexport function isLLMToolMessage(msg: AgentThreadRuntimeSendInput): msg is LLMToolMessage {\n // `'role' in msg` already narrows to LLMToolMessage among AgentThreadRuntimeSendInput.\n return 'role' in msg;\n}\n\nexport function isInternalThreadDoneError(\n event: InternalThreadDoneEvent,\n): event is InternalThreadDoneEvent & { status: 'error' } {\n return event.status === 'error';\n}\n\nexport function scanApprovalDecisions(context: ContextMessage[]): Map<string, ApprovalDecision> {\n const decisions = new Map<string, ApprovalDecision>();\n for (const msg of context) {\n if (isUserToolApprovalDecisionMessage(msg)) {\n decisions.set(msg.tool_call_id, msg.approval);\n }\n }\n return decisions;\n}\n\nexport function makeUnknownToolInfo(toolName: string): InternalToolCallInfo {\n return {\n type: 'mcp',\n mcp_server_id: UNKNOWN_TOOL_NAME,\n mcp_server_name: UNKNOWN_TOOL_NAME,\n original_tool_name: toolName,\n is_approval_required: false,\n is_client_side: false,\n };\n}\n\nexport function toToolCallInfo(toolInfo: InternalToolCallInfo): ToolInfo {\n if (toolInfo.type === 'mcp') {\n return {\n type: toolInfo.type,\n name: toolInfo.original_tool_name,\n server_id: toolInfo.mcp_server_id,\n server_name: toolInfo.mcp_server_name,\n };\n }\n return {\n type: toolInfo.type,\n name: toolInfo.original_tool_name,\n };\n}\n\nexport function toEnrichedToolCall(toolCall: InternalEnrichedToolCall): EnrichedToolCall {\n const { tool_info, ...rest } = toolCall;\n return { ...rest, tool_info: toToolCallInfo(tool_info) };\n}\n\nexport function assistantMessageContentToStringForSubAgent(\n content: string | ({ type?: string; text?: string } | string)[] | null | undefined,\n errorMessage?: string,\n): string {\n let text = '';\n if (typeof content === 'string') {\n text = content;\n } else if (Array.isArray(content)) {\n text = content.map(item => (typeof item === 'string' ? item : JSON.stringify(item))).join('');\n }\n if (errorMessage) {\n return text ? `${errorMessage}\\n${text}` : errorMessage;\n }\n return text;\n}\n\nexport function getThreadId(): string {\n return crypto.randomUUID();\n}\n\nexport function estimateTokensForContextMessages(messages: ContextMessage[]): CurrentContextUsage {\n let tokenCount = 0;\n\n for (const b of messages) {\n if ('content' in b && b.content) {\n if (typeof b.content === 'string') {\n tokenCount += estimateTokensForString(b.content);\n } else if (Array.isArray(b.content)) {\n for (const part of b.content) {\n if ('text' in part && typeof part.text === 'string') {\n tokenCount += estimateTokensForString(part.text);\n }\n }\n }\n }\n\n if ('tool_calls' in b && b.tool_calls) {\n for (const toolCall of b.tool_calls) {\n tokenCount += estimateTokensForString(toolCall.function.name);\n tokenCount += estimateTokensForString(toolCall.function.arguments);\n }\n }\n\n if ('tool_call_id' in b && b.tool_call_id) {\n tokenCount += estimateTokensForString(b.tool_call_id);\n }\n }\n\n return {\n prompt_tokens: tokenCount,\n completion_tokens: 0,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AAEnB,oBAKO;AASP,sBAAkC;AAClC,mBAAwC;AAUjC,IAAM,mBAAmB;AAChC,IAAM,iBAAiB;AAChB,IAAM,yBAAyB,cAAAA;AAAA;AAAA;AAAA;AAAA;AAM/B,SAAS,kBAAkB,GAAmB;AACnD,SAAO,mBAAmB,IAAI;AAChC;AAEO,SAAS,sBAAsB,GAA2B;AAC/D,SAAO,EAAE,MAAM,QAAiB,SAAS,kBAAkB,CAAC,EAAE;AAChE;AAEO,SAAS,oBAAoB,KAA+C;AACjF,SAAO,UAAU;AACnB;AAEO,SAAS,wBAAwB,GAA4B;AAClE,MAAI,CAAC,oBAAoB,CAAC,EAAG,QAAO;AACpC,SAAO,EAAE,SAAS,UAAU,OAAO,EAAE,YAAY,YAAY,EAAE,QAAQ,WAAW,gBAAgB;AACpG;AAEO,SAAS,0BAA0B,KAAkE;AAC1G,SAAO,UAAU,OAAO,IAAI,SAAS,wBAAU;AACjD;AAEA,SAAS,kCAAkC,KAA0D;AAEnG,SAAO,UAAU;AACnB;AAEO,SAAS,gCAAgC,KAAkE;AAChH,SAAO,UAAU,OAAO,IAAI,SAAS,wBAAU;AACjD;AAEO,SAAS,mBAAmB,KAAgE;AACjG,SAAO,UAAU,OAAO,IAAI,SAAS,wBAAU;AACjD;AAEO,SAAS,iBAAiB,KAAyD;AAExF,SAAO,UAAU;AACnB;AAEO,SAAS,0BACd,OACwD;AACxD,SAAO,MAAM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K,UAAU;AACxB,QAAI,aAAa,KAAK,EAAE,SAAS;AAC/B,UAAI,OAAO,EAAE,YAAY,UAAU;AACjC,0BAAc,sCAAwB,EAAE,OAAO;AAAA,MACjD,WAAW,MAAM,QAAQ,EAAE,OAAO,GAAG;AACnC,mBAAW,QAAQ,EAAE,SAAS;AAC5B,cAAI,UAAU,QAAQ,OAAO,KAAK,SAAS,UAAU;AACnD,8BAAc,sCAAwB,KAAK,IAAI;AAAA,UACjD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,QAAI,gBAAgB,KAAK,EAAE,YAAY;AACrC,iBAAW,YAAY,EAAE,YAAY;AACnC,0BAAc,sCAAwB,SAAS,SAAS,IAAI;AAC5D,0BAAc,sCAAwB,SAAS,SAAS,SAAS;AAAA,MACnE;AAAA,IACF;AAEA,QAAI,kBAAkB,KAAK,EAAE,cAAc;AACzC,wBAAc,sCAAwB,EAAE,YAAY;AAAA,IACtD;AAAA,EACF;AAEA,SAAO;AAAA,IACL,eAAe;AAAA,IACf,mBAAmB;AAAA,EACrB;AACF;","names":["dedent"]}
@@ -0,0 +1,148 @@
1
+ // src/core/runtime/contextUtils.ts
2
+ import dedent from "dedent";
3
+ import {
4
+ EventType
5
+ } from "../events/schema.mjs";
6
+ import { UNKNOWN_TOOL_NAME } from "../llm/LLMTypes.mjs";
7
+ import { estimateTokensForString } from "../llm/usage.mjs";
8
+ var SYSTEM_TAG_START = "<tfy-internal>";
9
+ var SYSTEM_TAG_END = "</tfy-internal>";
10
+ var INTERNAL_SYSTEM_PROMPT = dedent`
11
+ Messages wrapped in tfy-internal tags contain information hidden from the user. The Agent must keep this information in mind when conversing with the user.
12
+ The Agent must never generate any content with tfy-internal tags.
13
+ The Agent cannot generate any content with tfy-internal tags.
14
+ `;
15
+ function internalSystemTag(m) {
16
+ return SYSTEM_TAG_START + m + SYSTEM_TAG_END;
17
+ }
18
+ function internalSystemMessage(m) {
19
+ return { role: "user", content: internalSystemTag(m) };
20
+ }
21
+ function isLLMContextMessage(msg) {
22
+ return "role" in msg;
23
+ }
24
+ function isInternalSystemMessage(m) {
25
+ if (!isLLMContextMessage(m)) return false;
26
+ return m.role === "user" && typeof m.content === "string" && m.content.startsWith(SYSTEM_TAG_START);
27
+ }
28
+ function isApprovalDecisionMessage(msg) {
29
+ return "type" in msg && msg.type === EventType.USER_TOOL_APPROVAL;
30
+ }
31
+ function isUserToolApprovalDecisionMessage(msg) {
32
+ return "type" in msg;
33
+ }
34
+ function isClientSideToolResponseMessage(msg) {
35
+ return "type" in msg && msg.type === EventType.USER_TOOL_RESPONSE;
36
+ }
37
+ function isInputUserMessage(msg) {
38
+ return "type" in msg && msg.type === EventType.USER_MESSAGE;
39
+ }
40
+ function isLLMToolMessage(msg) {
41
+ return "role" in msg;
42
+ }
43
+ function isInternalThreadDoneError(event) {
44
+ return event.status === "error";
45
+ }
46
+ function scanApprovalDecisions(context) {
47
+ const decisions = /* @__PURE__ */ new Map();
48
+ for (const msg of context) {
49
+ if (isUserToolApprovalDecisionMessage(msg)) {
50
+ decisions.set(msg.tool_call_id, msg.approval);
51
+ }
52
+ }
53
+ return decisions;
54
+ }
55
+ function makeUnknownToolInfo(toolName) {
56
+ return {
57
+ type: "mcp",
58
+ mcp_server_id: UNKNOWN_TOOL_NAME,
59
+ mcp_server_name: UNKNOWN_TOOL_NAME,
60
+ original_tool_name: toolName,
61
+ is_approval_required: false,
62
+ is_client_side: false
63
+ };
64
+ }
65
+ function toToolCallInfo(toolInfo) {
66
+ if (toolInfo.type === "mcp") {
67
+ return {
68
+ type: toolInfo.type,
69
+ name: toolInfo.original_tool_name,
70
+ server_id: toolInfo.mcp_server_id,
71
+ server_name: toolInfo.mcp_server_name
72
+ };
73
+ }
74
+ return {
75
+ type: toolInfo.type,
76
+ name: toolInfo.original_tool_name
77
+ };
78
+ }
79
+ function toEnrichedToolCall(toolCall) {
80
+ const { tool_info, ...rest } = toolCall;
81
+ return { ...rest, tool_info: toToolCallInfo(tool_info) };
82
+ }
83
+ function assistantMessageContentToStringForSubAgent(content, errorMessage) {
84
+ let text = "";
85
+ if (typeof content === "string") {
86
+ text = content;
87
+ } else if (Array.isArray(content)) {
88
+ text = content.map((item) => typeof item === "string" ? item : JSON.stringify(item)).join("");
89
+ }
90
+ if (errorMessage) {
91
+ return text ? `${errorMessage}
92
+ ${text}` : errorMessage;
93
+ }
94
+ return text;
95
+ }
96
+ function getThreadId() {
97
+ return crypto.randomUUID();
98
+ }
99
+ function estimateTokensForContextMessages(messages) {
100
+ let tokenCount = 0;
101
+ for (const b of messages) {
102
+ if ("content" in b && b.content) {
103
+ if (typeof b.content === "string") {
104
+ tokenCount += estimateTokensForString(b.content);
105
+ } else if (Array.isArray(b.content)) {
106
+ for (const part of b.content) {
107
+ if ("text" in part && typeof part.text === "string") {
108
+ tokenCount += estimateTokensForString(part.text);
109
+ }
110
+ }
111
+ }
112
+ }
113
+ if ("tool_calls" in b && b.tool_calls) {
114
+ for (const toolCall of b.tool_calls) {
115
+ tokenCount += estimateTokensForString(toolCall.function.name);
116
+ tokenCount += estimateTokensForString(toolCall.function.arguments);
117
+ }
118
+ }
119
+ if ("tool_call_id" in b && b.tool_call_id) {
120
+ tokenCount += estimateTokensForString(b.tool_call_id);
121
+ }
122
+ }
123
+ return {
124
+ prompt_tokens: tokenCount,
125
+ completion_tokens: 0
126
+ };
127
+ }
128
+ export {
129
+ INTERNAL_SYSTEM_PROMPT,
130
+ SYSTEM_TAG_START,
131
+ assistantMessageContentToStringForSubAgent,
132
+ estimateTokensForContextMessages,
133
+ getThreadId,
134
+ internalSystemMessage,
135
+ internalSystemTag,
136
+ isApprovalDecisionMessage,
137
+ isClientSideToolResponseMessage,
138
+ isInputUserMessage,
139
+ isInternalSystemMessage,
140
+ isInternalThreadDoneError,
141
+ isLLMContextMessage,
142
+ isLLMToolMessage,
143
+ makeUnknownToolInfo,
144
+ scanApprovalDecisions,
145
+ toEnrichedToolCall,
146
+ toToolCallInfo
147
+ };
148
+ //# sourceMappingURL=contextUtils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/core/runtime/contextUtils.ts"],"sourcesContent":["import dedent from 'dedent';\nimport type { ApprovalDecision } from '../events/schema';\nimport {\n EventType,\n type AgentApprovalDecisionMessage,\n type UserToolApprovalMessage,\n type UserToolResponseMessage,\n} from '../events/schema';\nimport type {\n EnrichedToolCall,\n InternalEnrichedToolCall,\n InternalToolCallInfo,\n LLMToolMessage,\n LLMUserMessage,\n ToolInfo,\n} from '../llm/LLMTypes';\nimport { UNKNOWN_TOOL_NAME } from '../llm/LLMTypes';\nimport { estimateTokensForString } from '../llm/usage';\nimport type {\n AgentThreadRuntimeSendInput,\n ContextMessage,\n InternalThreadDoneEvent,\n LLMContextMessage,\n} from './AgentThread.types';\nimport type { CurrentContextUsage } from './contextUsage';\nimport type { AgentInputUserMessage } from './UserInputMessage';\n\nexport const SYSTEM_TAG_START = '<tfy-internal>';\nconst SYSTEM_TAG_END = '</tfy-internal>';\nexport const INTERNAL_SYSTEM_PROMPT = dedent`\nMessages wrapped in tfy-internal tags contain information hidden from the user. The Agent must keep this information in mind when conversing with the user.\nThe Agent must never generate any content with tfy-internal tags.\nThe Agent cannot generate any content with tfy-internal tags.\n`;\n\nexport function internalSystemTag(m: string): string {\n return SYSTEM_TAG_START + m + SYSTEM_TAG_END;\n}\n\nexport function internalSystemMessage(m: string): LLMUserMessage {\n return { role: 'user' as const, content: internalSystemTag(m) };\n}\n\nexport function isLLMContextMessage(msg: ContextMessage): msg is LLMContextMessage {\n return 'role' in msg;\n}\n\nexport function isInternalSystemMessage(m: ContextMessage): boolean {\n if (!isLLMContextMessage(m)) return false;\n return m.role === 'user' && typeof m.content === 'string' && m.content.startsWith(SYSTEM_TAG_START);\n}\n\nexport function isApprovalDecisionMessage(msg: AgentThreadRuntimeSendInput): msg is UserToolApprovalMessage {\n return 'type' in msg && msg.type === EventType.USER_TOOL_APPROVAL;\n}\n\nfunction isUserToolApprovalDecisionMessage(msg: ContextMessage): msg is AgentApprovalDecisionMessage {\n // `'type' in msg` already narrows to AgentApprovalDecisionMessage (literal type).\n return 'type' in msg;\n}\n\nexport function isClientSideToolResponseMessage(msg: AgentThreadRuntimeSendInput): msg is UserToolResponseMessage {\n return 'type' in msg && msg.type === EventType.USER_TOOL_RESPONSE;\n}\n\nexport function isInputUserMessage(msg: AgentThreadRuntimeSendInput): msg is AgentInputUserMessage {\n return 'type' in msg && msg.type === EventType.USER_MESSAGE;\n}\n\nexport function isLLMToolMessage(msg: AgentThreadRuntimeSendInput): msg is LLMToolMessage {\n // `'role' in msg` already narrows to LLMToolMessage among AgentThreadRuntimeSendInput.\n return 'role' in msg;\n}\n\nexport function isInternalThreadDoneError(\n event: InternalThreadDoneEvent,\n): event is InternalThreadDoneEvent & { status: 'error' } {\n return event.status === 'error';\n}\n\nexport function scanApprovalDecisions(context: ContextMessage[]): Map<string, ApprovalDecision> {\n const decisions = new Map<string, ApprovalDecision>();\n for (const msg of context) {\n if (isUserToolApprovalDecisionMessage(msg)) {\n decisions.set(msg.tool_call_id, msg.approval);\n }\n }\n return decisions;\n}\n\nexport function makeUnknownToolInfo(toolName: string): InternalToolCallInfo {\n return {\n type: 'mcp',\n mcp_server_id: UNKNOWN_TOOL_NAME,\n mcp_server_name: UNKNOWN_TOOL_NAME,\n original_tool_name: toolName,\n is_approval_required: false,\n is_client_side: false,\n };\n}\n\nexport function toToolCallInfo(toolInfo: InternalToolCallInfo): ToolInfo {\n if (toolInfo.type === 'mcp') {\n return {\n type: toolInfo.type,\n name: toolInfo.original_tool_name,\n server_id: toolInfo.mcp_server_id,\n server_name: toolInfo.mcp_server_name,\n };\n }\n return {\n type: toolInfo.type,\n name: toolInfo.original_tool_name,\n };\n}\n\nexport function toEnrichedToolCall(toolCall: InternalEnrichedToolCall): EnrichedToolCall {\n const { tool_info, ...rest } = toolCall;\n return { ...rest, tool_info: toToolCallInfo(tool_info) };\n}\n\nexport function assistantMessageContentToStringForSubAgent(\n content: string | ({ type?: string; text?: string } | string)[] | null | undefined,\n errorMessage?: string,\n): string {\n let text = '';\n if (typeof content === 'string') {\n text = content;\n } else if (Array.isArray(content)) {\n text = content.map(item => (typeof item === 'string' ? item : JSON.stringify(item))).join('');\n }\n if (errorMessage) {\n return text ? `${errorMessage}\\n${text}` : errorMessage;\n }\n return text;\n}\n\nexport function getThreadId(): string {\n return crypto.randomUUID();\n}\n\nexport function estimateTokensForContextMessages(messages: ContextMessage[]): CurrentContextUsage {\n let tokenCount = 0;\n\n for (const b of messages) {\n if ('content' in b && b.content) {\n if (typeof b.content === 'string') {\n tokenCount += estimateTokensForString(b.content);\n } else if (Array.isArray(b.content)) {\n for (const part of b.content) {\n if ('text' in part && typeof part.text === 'string') {\n tokenCount += estimateTokensForString(part.text);\n }\n }\n }\n }\n\n if ('tool_calls' in b && b.tool_calls) {\n for (const toolCall of b.tool_calls) {\n tokenCount += estimateTokensForString(toolCall.function.name);\n tokenCount += estimateTokensForString(toolCall.function.arguments);\n }\n }\n\n if ('tool_call_id' in b && b.tool_call_id) {\n tokenCount += estimateTokensForString(b.tool_call_id);\n }\n }\n\n return {\n prompt_tokens: tokenCount,\n completion_tokens: 0,\n };\n}\n"],"mappings":";AAAA,OAAO,YAAY;AAEnB;AAAA,EACE;AAAA,OAIK;AASP,SAAS,yBAAyB;AAClC,SAAS,+BAA+B;AAUjC,IAAM,mBAAmB;AAChC,IAAM,iBAAiB;AAChB,IAAM,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAM/B,SAAS,kBAAkB,GAAmB;AACnD,SAAO,mBAAmB,IAAI;AAChC;AAEO,SAAS,sBAAsB,GAA2B;AAC/D,SAAO,EAAE,MAAM,QAAiB,SAAS,kBAAkB,CAAC,EAAE;AAChE;AAEO,SAAS,oBAAoB,KAA+C;AACjF,SAAO,UAAU;AACnB;AAEO,SAAS,wBAAwB,GAA4B;AAClE,MAAI,CAAC,oBAAoB,CAAC,EAAG,QAAO;AACpC,SAAO,EAAE,SAAS,UAAU,OAAO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;AACR,MAAI,OAAO;AACX,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT,WAAW,MAAM,QAAQ,OAAO,GAAG;AACjC,WAAO,QAAQ,IAAI,UAAS,OAAO,SAAS,WAAW,OAAO,KAAK,UAAU,IAAI,CAAE,EAAE,KAAK,EAAE;AAAA,EAC9F;AACA,MAAI,cAAc;AAChB,WAAO,OAAO,GAAG,YAAY;AAAA,EAAK,IAAI,KAAK;AAAA,EAC7C;AACA,SAAO;AACT;AAEO,SAAS,cAAsB;AACpC,SAAO,OAAO,WAAW;AAC3B;AAEO,SAAS,iCAAiC,UAAiD;AAChG,MAAI,aAAa;AAEjB,aAAW,KAAK,UAAU;AACxB,QAAI,aAAa,KAAK,EAAE,SAAS;AAC/B,UAAI,OAAO,EAAE,YAAY,UAAU;AACjC,sBAAc,wBAAwB,EAAE,OAAO;AAAA,MACjD,WAAW,MAAM,QAAQ,EAAE,OAAO,GAAG;AACnC,mBAAW,QAAQ,EAAE,SAAS;AAC5B,cAAI,UAAU,QAAQ,OAAO,KAAK,SAAS,UAAU;AACnD,0BAAc,wBAAwB,KAAK,IAAI;AAAA,UACjD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,QAAI,gBAAgB,KAAK,EAAE,YAAY;AACrC,iBAAW,YAAY,EAAE,YAAY;AACnC,sBAAc,wBAAwB,SAAS,SAAS,IAAI;AAC5D,sBAAc,wBAAwB,SAAS,SAAS,SAAS;AAAA,MACnE;AAAA,IACF;AAEA,QAAI,kBAAkB,KAAK,EAAE,cAAc;AACzC,oBAAc,wBAAwB,EAAE,YAAY;AAAA,IACtD;AAAA,EACF;AAEA,SAAO;AAAA,IACL,eAAe;AAAA,IACf,mBAAmB;AAAA,EACrB;AACF;","names":[]}
@@ -0,0 +1,22 @@
1
+ import { z } from '@hono/zod-openapi';
2
+ import type { CompletionUsage } from '../llm/LLMTypes';
3
+ /** Billable aggregate — thread/orchestrator totals (`total_*`). */
4
+ export declare const AgentThreadMetricsSchema: z.ZodObject<{
5
+ total_input_tokens: z.ZodNumber;
6
+ total_output_tokens: z.ZodNumber;
7
+ total_tokens: z.ZodNumber;
8
+ total_cache_read_tokens: z.ZodOptional<z.ZodNumber>;
9
+ total_cache_write_tokens: z.ZodOptional<z.ZodNumber>;
10
+ total_reasoning_tokens: z.ZodOptional<z.ZodNumber>;
11
+ total_cost_in_usd: z.ZodOptional<z.ZodNumber>;
12
+ iterations: z.ZodNumber;
13
+ total_tool_calls: z.ZodNumber;
14
+ total_summarizations: z.ZodNumber;
15
+ total_sub_agents: z.ZodNumber;
16
+ }, z.core.$strip>;
17
+ export type AgentThreadMetrics = z.infer<typeof AgentThreadMetricsSchema>;
18
+ export declare function createEmptyAgentThreadMetrics(): AgentThreadMetrics;
19
+ /** Fold one per-call completion usage into aggregated thread metrics. */
20
+ export declare function updateMetricsFromUsage(target: AgentThreadMetrics, usage: CompletionUsage): void;
21
+ export declare function addAgentThreadMetrics(target: AgentThreadMetrics, source: AgentThreadMetrics): void;
22
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/core/runtime/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD,mEAAmE;AACnE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;iBAcL,CAAC;AAEjC,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAS1E,wBAAgB,6BAA6B,IAAI,kBAAkB,CAUlE;AAED,yEAAyE;AACzE,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,eAAe,GAAG,IAAI,CAQ/F;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAYlG"}