@trigger.dev/sdk 0.0.0-python-preview-20250226140121 → 0.0.0-rc-4-8-0-20261021151928

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 (732) hide show
  1. package/README.md +29 -9
  2. package/dist/commonjs/imports/ai-runtime-cjs.cjs.map +1 -0
  3. package/dist/commonjs/imports/ai-runtime.d.ts +1 -0
  4. package/dist/commonjs/imports/ai-runtime.js +31 -0
  5. package/dist/commonjs/imports/uncrypto.js +4 -4
  6. package/dist/commonjs/package.json +2 -1
  7. package/dist/commonjs/v3/agentSkillsRuntime.d.ts +28 -0
  8. package/dist/commonjs/v3/agentSkillsRuntime.js +173 -0
  9. package/dist/commonjs/v3/agentSkillsRuntime.js.map +1 -0
  10. package/dist/commonjs/v3/ai-shared.d.ts +156 -0
  11. package/dist/commonjs/v3/ai-shared.js +215 -0
  12. package/dist/commonjs/v3/ai-shared.js.map +1 -0
  13. package/dist/commonjs/v3/ai.d.ts +4225 -0
  14. package/dist/commonjs/v3/ai.js +11569 -0
  15. package/dist/commonjs/v3/ai.js.map +1 -0
  16. package/dist/commonjs/v3/aiAutoTelemetry.d.ts +2 -0
  17. package/dist/commonjs/v3/aiAutoTelemetry.js +81 -0
  18. package/dist/commonjs/v3/aiAutoTelemetry.js.map +1 -0
  19. package/dist/commonjs/v3/auth.d.ts +71 -10
  20. package/dist/commonjs/v3/auth.js +85 -19
  21. package/dist/commonjs/v3/auth.js.map +1 -1
  22. package/dist/commonjs/v3/batch.d.ts +3 -3
  23. package/dist/commonjs/v3/batch.js.map +1 -1
  24. package/dist/commonjs/v3/cache.js.map +1 -1
  25. package/dist/commonjs/v3/chat-client.d.ts +324 -0
  26. package/dist/commonjs/v3/chat-client.js +774 -0
  27. package/dist/commonjs/v3/chat-client.js.map +1 -0
  28. package/dist/commonjs/v3/chat-react.d.ts +244 -0
  29. package/dist/commonjs/v3/chat-react.js +463 -0
  30. package/dist/commonjs/v3/chat-react.js.map +1 -0
  31. package/dist/commonjs/v3/chat-server.d.ts +350 -0
  32. package/dist/commonjs/v3/chat-server.js +965 -0
  33. package/dist/commonjs/v3/chat-server.js.map +1 -0
  34. package/dist/commonjs/v3/chat-tab-coordinator.d.ts +65 -0
  35. package/dist/commonjs/v3/chat-tab-coordinator.js +235 -0
  36. package/dist/commonjs/v3/chat-tab-coordinator.js.map +1 -0
  37. package/dist/commonjs/v3/chat.d.ts +792 -0
  38. package/dist/commonjs/v3/chat.js +1662 -0
  39. package/dist/commonjs/v3/chat.js.map +1 -0
  40. package/dist/commonjs/v3/chatRouteWait.d.ts +21 -0
  41. package/dist/commonjs/v3/chatRouteWait.js +43 -0
  42. package/dist/commonjs/v3/chatRouteWait.js.map +1 -0
  43. package/dist/commonjs/v3/chatSnapshotIo.d.ts +2 -0
  44. package/dist/commonjs/v3/chatSnapshotIo.js +173 -0
  45. package/dist/commonjs/v3/chatSnapshotIo.js.map +1 -0
  46. package/dist/commonjs/v3/chatVersionSkew.d.ts +12 -0
  47. package/dist/commonjs/v3/chatVersionSkew.js +30 -0
  48. package/dist/commonjs/v3/chatVersionSkew.js.map +1 -0
  49. package/dist/commonjs/v3/compactionResponse.d.ts +9 -0
  50. package/dist/commonjs/v3/compactionResponse.js +37 -0
  51. package/dist/commonjs/v3/compactionResponse.js.map +1 -0
  52. package/dist/commonjs/v3/concurrency-shared.d.ts +13 -0
  53. package/dist/commonjs/v3/concurrency-shared.js +35 -0
  54. package/dist/commonjs/v3/concurrency-shared.js.map +1 -0
  55. package/dist/commonjs/v3/concurrencyLimits.d.ts +103 -0
  56. package/dist/commonjs/v3/concurrencyLimits.js +134 -0
  57. package/dist/commonjs/v3/concurrencyLimits.js.map +1 -0
  58. package/dist/commonjs/v3/config.js.map +1 -1
  59. package/dist/commonjs/v3/deployments.d.ts +25 -0
  60. package/dist/commonjs/v3/deployments.js +37 -0
  61. package/dist/commonjs/v3/deployments.js.map +1 -0
  62. package/dist/commonjs/v3/envvars.d.ts +5 -5
  63. package/dist/commonjs/v3/envvars.js.map +1 -1
  64. package/dist/commonjs/v3/externalDeploymentId.d.ts +23 -0
  65. package/dist/commonjs/v3/externalDeploymentId.js +43 -0
  66. package/dist/commonjs/v3/externalDeploymentId.js.map +1 -0
  67. package/dist/commonjs/v3/heartbeats.d.ts +37 -0
  68. package/dist/commonjs/v3/heartbeats.js +45 -0
  69. package/dist/commonjs/v3/heartbeats.js.map +1 -0
  70. package/dist/commonjs/v3/hooks.d.ts +26 -0
  71. package/dist/commonjs/v3/hooks.js +79 -0
  72. package/dist/commonjs/v3/hooks.js.map +1 -0
  73. package/dist/commonjs/v3/idempotencyKeys.d.ts +2 -1
  74. package/dist/commonjs/v3/idempotencyKeys.js +1 -0
  75. package/dist/commonjs/v3/idempotencyKeys.js.map +1 -1
  76. package/dist/commonjs/v3/index.d.ts +20 -5
  77. package/dist/commonjs/v3/index.js +56 -20
  78. package/dist/commonjs/v3/index.js.map +1 -1
  79. package/dist/commonjs/v3/locals.d.ts +3 -0
  80. package/dist/commonjs/v3/locals.js +6 -0
  81. package/dist/commonjs/v3/locals.js.map +1 -0
  82. package/dist/commonjs/v3/managedChatResponse.d.ts +44 -0
  83. package/dist/commonjs/v3/managedChatResponse.js +221 -0
  84. package/dist/commonjs/v3/managedChatResponse.js.map +1 -0
  85. package/dist/commonjs/v3/metadata.d.ts +5 -2
  86. package/dist/commonjs/v3/metadata.js +8 -1
  87. package/dist/commonjs/v3/metadata.js.map +1 -1
  88. package/dist/commonjs/v3/modelFileDownload.d.ts +10 -0
  89. package/dist/commonjs/v3/modelFileDownload.js +164 -0
  90. package/dist/commonjs/v3/modelFileDownload.js.map +1 -0
  91. package/dist/commonjs/v3/otel.d.ts +4 -0
  92. package/dist/commonjs/v3/otel.js +12 -0
  93. package/dist/commonjs/v3/otel.js.map +1 -0
  94. package/dist/commonjs/v3/prompt.d.ts +38 -0
  95. package/dist/commonjs/v3/prompt.js +146 -0
  96. package/dist/commonjs/v3/prompt.js.map +1 -0
  97. package/dist/commonjs/v3/promptManagement.d.ts +26 -0
  98. package/dist/commonjs/v3/promptManagement.js +180 -0
  99. package/dist/commonjs/v3/promptManagement.js.map +1 -0
  100. package/dist/commonjs/v3/prompts.d.ts +3 -0
  101. package/dist/commonjs/v3/prompts.js +15 -0
  102. package/dist/commonjs/v3/prompts.js.map +1 -0
  103. package/dist/commonjs/v3/query.d.ts +545 -0
  104. package/dist/commonjs/v3/query.js +163 -0
  105. package/dist/commonjs/v3/query.js.map +1 -0
  106. package/dist/commonjs/v3/queues.d.ts +107 -0
  107. package/dist/commonjs/v3/queues.js +225 -0
  108. package/dist/commonjs/v3/queues.js.map +1 -0
  109. package/dist/commonjs/v3/retry.d.ts +6 -2
  110. package/dist/commonjs/v3/retry.js +34 -23
  111. package/dist/commonjs/v3/retry.js.map +1 -1
  112. package/dist/commonjs/v3/runs.d.ts +182 -101
  113. package/dist/commonjs/v3/runs.js +99 -5
  114. package/dist/commonjs/v3/runs.js.map +1 -1
  115. package/dist/commonjs/v3/schedules/api.d.ts +8 -1
  116. package/dist/commonjs/v3/schedules/index.d.ts +29 -9
  117. package/dist/commonjs/v3/schedules/index.js +5 -1
  118. package/dist/commonjs/v3/schedules/index.js.map +1 -1
  119. package/dist/commonjs/v3/schemas.d.ts +1 -0
  120. package/dist/commonjs/{integrations.js → v3/schemas.js} +1 -1
  121. package/dist/commonjs/v3/schemas.js.map +1 -0
  122. package/dist/commonjs/v3/sessionTracing.d.ts +7 -0
  123. package/dist/commonjs/v3/sessionTracing.js +44 -0
  124. package/dist/commonjs/v3/sessionTracing.js.map +1 -0
  125. package/dist/commonjs/v3/sessions.d.ts +268 -0
  126. package/dist/commonjs/v3/sessions.js +776 -0
  127. package/dist/commonjs/v3/sessions.js.map +1 -0
  128. package/dist/commonjs/v3/shared.d.ts +129 -24
  129. package/dist/commonjs/v3/shared.js +1527 -689
  130. package/dist/commonjs/v3/shared.js.map +1 -1
  131. package/dist/commonjs/v3/skill.d.ts +99 -0
  132. package/dist/commonjs/v3/skill.js +165 -0
  133. package/dist/commonjs/v3/skill.js.map +1 -0
  134. package/dist/commonjs/v3/skills.d.ts +2 -0
  135. package/dist/commonjs/v3/skills.js +6 -0
  136. package/dist/commonjs/v3/skills.js.map +1 -0
  137. package/dist/commonjs/v3/steeringContext.d.ts +41 -0
  138. package/dist/commonjs/v3/steeringContext.js +118 -0
  139. package/dist/commonjs/v3/steeringContext.js.map +1 -0
  140. package/dist/commonjs/v3/streams.d.ts +298 -0
  141. package/dist/commonjs/v3/streams.js +584 -0
  142. package/dist/commonjs/v3/streams.js.map +1 -0
  143. package/dist/commonjs/v3/tasks.d.ts +19 -4
  144. package/dist/commonjs/v3/tasks.js +15 -1
  145. package/dist/commonjs/v3/tasks.js.map +1 -1
  146. package/dist/commonjs/v3/test/index.d.ts +5 -0
  147. package/dist/commonjs/v3/test/index.js +23 -0
  148. package/dist/commonjs/v3/test/index.js.map +1 -0
  149. package/dist/commonjs/v3/test/mock-channel-connector.d.ts +172 -0
  150. package/dist/commonjs/v3/test/mock-channel-connector.js +173 -0
  151. package/dist/commonjs/v3/test/mock-channel-connector.js.map +1 -0
  152. package/dist/commonjs/v3/test/mock-chat-agent.d.ts +388 -0
  153. package/dist/commonjs/v3/test/mock-chat-agent.js +689 -0
  154. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -0
  155. package/dist/commonjs/v3/test/setup-catalog.d.ts +1 -0
  156. package/dist/commonjs/v3/test/setup-catalog.js +18 -0
  157. package/dist/commonjs/v3/test/setup-catalog.js.map +1 -0
  158. package/dist/commonjs/v3/test/test-session-handle.d.ts +24 -0
  159. package/dist/commonjs/v3/test/test-session-handle.js +271 -0
  160. package/dist/commonjs/v3/test/test-session-handle.js.map +1 -0
  161. package/dist/commonjs/v3/test/transcript-storage-tests.d.ts +40 -0
  162. package/dist/commonjs/v3/test/transcript-storage-tests.js +258 -0
  163. package/dist/commonjs/v3/test/transcript-storage-tests.js.map +1 -0
  164. package/dist/commonjs/v3/toolResultOrder.d.ts +15 -0
  165. package/dist/commonjs/v3/toolResultOrder.js +58 -0
  166. package/dist/commonjs/v3/toolResultOrder.js.map +1 -0
  167. package/dist/commonjs/v3/transcriptStorage.d.ts +307 -0
  168. package/dist/commonjs/v3/transcriptStorage.js +445 -0
  169. package/dist/commonjs/v3/transcriptStorage.js.map +1 -0
  170. package/dist/commonjs/v3/triggerClient.d.ts +45 -0
  171. package/dist/commonjs/v3/triggerClient.js +114 -0
  172. package/dist/commonjs/v3/triggerClient.js.map +1 -0
  173. package/dist/commonjs/v3/uiMessageChunks.d.ts +1 -0
  174. package/dist/commonjs/v3/uiMessageChunks.js +119 -0
  175. package/dist/commonjs/v3/uiMessageChunks.js.map +1 -0
  176. package/dist/commonjs/v3/usage.js +7 -6
  177. package/dist/commonjs/v3/usage.js.map +1 -1
  178. package/dist/commonjs/v3/wait.d.ts +218 -3
  179. package/dist/commonjs/v3/wait.js +433 -7
  180. package/dist/commonjs/v3/wait.js.map +1 -1
  181. package/dist/commonjs/v3/waitUntil.js.map +1 -1
  182. package/dist/commonjs/v3/webhookWaiters.d.ts +80 -0
  183. package/dist/commonjs/v3/webhookWaiters.js +156 -0
  184. package/dist/commonjs/v3/webhookWaiters.js.map +1 -0
  185. package/dist/commonjs/v3/webhooks.d.ts +192 -2
  186. package/dist/commonjs/v3/webhooks.js +340 -2
  187. package/dist/commonjs/v3/webhooks.js.map +1 -1
  188. package/dist/commonjs/version.js +1 -1
  189. package/dist/esm/imports/ai-runtime.d.ts +2 -0
  190. package/dist/esm/imports/ai-runtime.js +16 -0
  191. package/dist/esm/imports/ai-runtime.js.map +1 -0
  192. package/dist/esm/package.json +2 -1
  193. package/dist/esm/v3/agentSkillsRuntime.d.ts +28 -0
  194. package/dist/esm/v3/agentSkillsRuntime.js +136 -0
  195. package/dist/esm/v3/agentSkillsRuntime.js.map +1 -0
  196. package/dist/esm/v3/ai-shared.d.ts +156 -0
  197. package/dist/esm/v3/ai-shared.js +208 -0
  198. package/dist/esm/v3/ai-shared.js.map +1 -0
  199. package/dist/esm/v3/ai.d.ts +4225 -0
  200. package/dist/esm/v3/ai.js +11550 -0
  201. package/dist/esm/v3/ai.js.map +1 -0
  202. package/dist/esm/v3/aiAutoTelemetry.d.ts +2 -0
  203. package/dist/esm/v3/aiAutoTelemetry.js +78 -0
  204. package/dist/esm/v3/aiAutoTelemetry.js.map +1 -0
  205. package/dist/esm/v3/auth.d.ts +71 -10
  206. package/dist/esm/v3/auth.js +83 -17
  207. package/dist/esm/v3/auth.js.map +1 -1
  208. package/dist/esm/v3/batch.d.ts +3 -3
  209. package/dist/esm/v3/batch.js +2 -2
  210. package/dist/esm/v3/batch.js.map +1 -1
  211. package/dist/esm/v3/chat-client.d.ts +324 -0
  212. package/dist/esm/v3/chat-client.js +769 -0
  213. package/dist/esm/v3/chat-client.js.map +1 -0
  214. package/dist/esm/v3/chat-react.d.ts +244 -0
  215. package/dist/esm/v3/chat-react.js +455 -0
  216. package/dist/esm/v3/chat-react.js.map +1 -0
  217. package/dist/esm/v3/chat-server.d.ts +350 -0
  218. package/dist/esm/v3/chat-server.js +962 -0
  219. package/dist/esm/v3/chat-server.js.map +1 -0
  220. package/dist/esm/v3/chat-tab-coordinator.d.ts +65 -0
  221. package/dist/esm/v3/chat-tab-coordinator.js +231 -0
  222. package/dist/esm/v3/chat-tab-coordinator.js.map +1 -0
  223. package/dist/esm/v3/chat.d.ts +792 -0
  224. package/dist/esm/v3/chat.js +1655 -0
  225. package/dist/esm/v3/chat.js.map +1 -0
  226. package/dist/esm/v3/chatRouteWait.d.ts +21 -0
  227. package/dist/esm/v3/chatRouteWait.js +40 -0
  228. package/dist/esm/v3/chatRouteWait.js.map +1 -0
  229. package/dist/esm/v3/chatSnapshotIo.d.ts +2 -0
  230. package/dist/esm/v3/chatSnapshotIo.js +165 -0
  231. package/dist/esm/v3/chatSnapshotIo.js.map +1 -0
  232. package/dist/esm/v3/chatVersionSkew.d.ts +12 -0
  233. package/dist/esm/v3/chatVersionSkew.js +27 -0
  234. package/dist/esm/v3/chatVersionSkew.js.map +1 -0
  235. package/dist/esm/v3/compactionResponse.d.ts +9 -0
  236. package/dist/esm/v3/compactionResponse.js +34 -0
  237. package/dist/esm/v3/compactionResponse.js.map +1 -0
  238. package/dist/esm/v3/concurrency-shared.d.ts +13 -0
  239. package/dist/esm/v3/concurrency-shared.js +31 -0
  240. package/dist/esm/v3/concurrency-shared.js.map +1 -0
  241. package/dist/esm/v3/concurrencyLimits.d.ts +103 -0
  242. package/dist/esm/v3/concurrencyLimits.js +126 -0
  243. package/dist/esm/v3/concurrencyLimits.js.map +1 -0
  244. package/dist/esm/v3/deployments.d.ts +25 -0
  245. package/dist/esm/v3/deployments.js +34 -0
  246. package/dist/esm/v3/deployments.js.map +1 -0
  247. package/dist/esm/v3/envvars.d.ts +5 -5
  248. package/dist/esm/v3/envvars.js.map +1 -1
  249. package/dist/esm/v3/externalDeploymentId.d.ts +23 -0
  250. package/dist/esm/v3/externalDeploymentId.js +38 -0
  251. package/dist/esm/v3/externalDeploymentId.js.map +1 -0
  252. package/dist/esm/v3/heartbeats.d.ts +37 -0
  253. package/dist/esm/v3/heartbeats.js +42 -0
  254. package/dist/esm/v3/heartbeats.js.map +1 -0
  255. package/dist/esm/v3/hooks.d.ts +26 -0
  256. package/dist/esm/v3/hooks.js +66 -0
  257. package/dist/esm/v3/hooks.js.map +1 -0
  258. package/dist/esm/v3/idempotencyKeys.d.ts +2 -1
  259. package/dist/esm/v3/idempotencyKeys.js +2 -1
  260. package/dist/esm/v3/idempotencyKeys.js.map +1 -1
  261. package/dist/esm/v3/index.d.ts +20 -5
  262. package/dist/esm/v3/index.js +16 -2
  263. package/dist/esm/v3/index.js.map +1 -1
  264. package/dist/esm/v3/locals.d.ts +3 -0
  265. package/dist/esm/v3/locals.js +3 -0
  266. package/dist/esm/v3/locals.js.map +1 -0
  267. package/dist/esm/v3/managedChatResponse.d.ts +44 -0
  268. package/dist/esm/v3/managedChatResponse.js +216 -0
  269. package/dist/esm/v3/managedChatResponse.js.map +1 -0
  270. package/dist/esm/v3/metadata.d.ts +5 -2
  271. package/dist/esm/v3/metadata.js +8 -1
  272. package/dist/esm/v3/metadata.js.map +1 -1
  273. package/dist/esm/v3/modelFileDownload.d.ts +10 -0
  274. package/dist/esm/v3/modelFileDownload.js +161 -0
  275. package/dist/esm/v3/modelFileDownload.js.map +1 -0
  276. package/dist/esm/v3/otel.d.ts +4 -0
  277. package/dist/esm/v3/otel.js +9 -0
  278. package/dist/esm/v3/otel.js.map +1 -0
  279. package/dist/esm/v3/prompt.d.ts +38 -0
  280. package/dist/esm/v3/prompt.js +143 -0
  281. package/dist/esm/v3/prompt.js.map +1 -0
  282. package/dist/esm/v3/promptManagement.d.ts +26 -0
  283. package/dist/esm/v3/promptManagement.js +170 -0
  284. package/dist/esm/v3/promptManagement.js.map +1 -0
  285. package/dist/esm/v3/prompts.d.ts +3 -0
  286. package/dist/esm/v3/prompts.js +3 -0
  287. package/dist/esm/v3/prompts.js.map +1 -0
  288. package/dist/esm/v3/query.d.ts +545 -0
  289. package/dist/esm/v3/query.js +160 -0
  290. package/dist/esm/v3/query.js.map +1 -0
  291. package/dist/esm/v3/queues.d.ts +107 -0
  292. package/dist/esm/v3/queues.js +217 -0
  293. package/dist/esm/v3/queues.js.map +1 -0
  294. package/dist/esm/v3/retry.d.ts +6 -2
  295. package/dist/esm/v3/retry.js +27 -19
  296. package/dist/esm/v3/retry.js.map +1 -1
  297. package/dist/esm/v3/runs.d.ts +179 -98
  298. package/dist/esm/v3/runs.js +99 -5
  299. package/dist/esm/v3/runs.js.map +1 -1
  300. package/dist/esm/v3/schedules/api.d.ts +8 -1
  301. package/dist/esm/v3/schedules/index.d.ts +29 -9
  302. package/dist/esm/v3/schedules/index.js +6 -2
  303. package/dist/esm/v3/schedules/index.js.map +1 -1
  304. package/dist/esm/v3/schemas.d.ts +1 -0
  305. package/dist/esm/v3/schemas.js +2 -0
  306. package/dist/esm/v3/schemas.js.map +1 -0
  307. package/dist/esm/v3/sessionTracing.d.ts +7 -0
  308. package/dist/esm/v3/sessionTracing.js +40 -0
  309. package/dist/esm/v3/sessionTracing.js.map +1 -0
  310. package/dist/esm/v3/sessions.d.ts +268 -0
  311. package/dist/esm/v3/sessions.js +767 -0
  312. package/dist/esm/v3/sessions.js.map +1 -0
  313. package/dist/esm/v3/shared.d.ts +129 -24
  314. package/dist/esm/v3/shared.js +1521 -688
  315. package/dist/esm/v3/shared.js.map +1 -1
  316. package/dist/esm/v3/skill.d.ts +99 -0
  317. package/dist/esm/v3/skill.js +128 -0
  318. package/dist/esm/v3/skill.js.map +1 -0
  319. package/dist/esm/v3/skills.d.ts +2 -0
  320. package/dist/esm/v3/skills.js +2 -0
  321. package/dist/esm/v3/skills.js.map +1 -0
  322. package/dist/esm/v3/steeringContext.d.ts +41 -0
  323. package/dist/esm/v3/steeringContext.js +113 -0
  324. package/dist/esm/v3/steeringContext.js.map +1 -0
  325. package/dist/esm/v3/streams.d.ts +298 -0
  326. package/dist/esm/v3/streams.js +580 -0
  327. package/dist/esm/v3/streams.js.map +1 -0
  328. package/dist/esm/v3/tasks.d.ts +19 -4
  329. package/dist/esm/v3/tasks.js +16 -2
  330. package/dist/esm/v3/tasks.js.map +1 -1
  331. package/dist/esm/v3/test/index.d.ts +5 -0
  332. package/dist/esm/v3/test/index.js +15 -0
  333. package/dist/esm/v3/test/index.js.map +1 -0
  334. package/dist/esm/v3/test/mock-channel-connector.d.ts +172 -0
  335. package/dist/esm/v3/test/mock-channel-connector.js +170 -0
  336. package/dist/esm/v3/test/mock-channel-connector.js.map +1 -0
  337. package/dist/esm/v3/test/mock-chat-agent.d.ts +388 -0
  338. package/dist/esm/v3/test/mock-chat-agent.js +685 -0
  339. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -0
  340. package/dist/esm/v3/test/setup-catalog.d.ts +1 -0
  341. package/dist/esm/v3/test/setup-catalog.js +16 -0
  342. package/dist/esm/v3/test/setup-catalog.js.map +1 -0
  343. package/dist/esm/v3/test/test-session-handle.d.ts +24 -0
  344. package/dist/esm/v3/test/test-session-handle.js +268 -0
  345. package/dist/esm/v3/test/test-session-handle.js.map +1 -0
  346. package/dist/esm/v3/test/transcript-storage-tests.d.ts +40 -0
  347. package/dist/esm/v3/test/transcript-storage-tests.js +255 -0
  348. package/dist/esm/v3/test/transcript-storage-tests.js.map +1 -0
  349. package/dist/esm/v3/toolResultOrder.d.ts +15 -0
  350. package/dist/esm/v3/toolResultOrder.js +55 -0
  351. package/dist/esm/v3/toolResultOrder.js.map +1 -0
  352. package/dist/esm/v3/transcriptStorage.d.ts +307 -0
  353. package/dist/esm/v3/transcriptStorage.js +431 -0
  354. package/dist/esm/v3/transcriptStorage.js.map +1 -0
  355. package/dist/esm/v3/triggerClient.d.ts +45 -0
  356. package/dist/esm/v3/triggerClient.js +77 -0
  357. package/dist/esm/v3/triggerClient.js.map +1 -0
  358. package/dist/esm/v3/uiMessageChunks.d.ts +1 -0
  359. package/dist/esm/v3/uiMessageChunks.js +116 -0
  360. package/dist/esm/v3/uiMessageChunks.js.map +1 -0
  361. package/dist/esm/v3/usage.js +7 -6
  362. package/dist/esm/v3/usage.js.map +1 -1
  363. package/dist/esm/v3/wait.d.ts +218 -3
  364. package/dist/esm/v3/wait.js +431 -7
  365. package/dist/esm/v3/wait.js.map +1 -1
  366. package/dist/esm/v3/webhookWaiters.d.ts +80 -0
  367. package/dist/esm/v3/webhookWaiters.js +149 -0
  368. package/dist/esm/v3/webhookWaiters.js.map +1 -0
  369. package/dist/esm/v3/webhooks.d.ts +192 -2
  370. package/dist/esm/v3/webhooks.js +336 -2
  371. package/dist/esm/v3/webhooks.js.map +1 -1
  372. package/dist/esm/version.js +1 -1
  373. package/docs/ai/observability.mdx +174 -0
  374. package/docs/ai/prompts.mdx +426 -0
  375. package/docs/ai-chat/actions.mdx +148 -0
  376. package/docs/ai-chat/anatomy.mdx +87 -0
  377. package/docs/ai-chat/backend.mdx +933 -0
  378. package/docs/ai-chat/background-injection.mdx +320 -0
  379. package/docs/ai-chat/changelog.mdx +958 -0
  380. package/docs/ai-chat/chat-local.mdx +170 -0
  381. package/docs/ai-chat/client-protocol.mdx +1091 -0
  382. package/docs/ai-chat/compaction.mdx +413 -0
  383. package/docs/ai-chat/custom-agents.mdx +545 -0
  384. package/docs/ai-chat/error-handling.mdx +379 -0
  385. package/docs/ai-chat/fast-starts.mdx +764 -0
  386. package/docs/ai-chat/frontend.mdx +634 -0
  387. package/docs/ai-chat/how-it-works.mdx +226 -0
  388. package/docs/ai-chat/lifecycle-hooks.mdx +532 -0
  389. package/docs/ai-chat/mcp.mdx +97 -0
  390. package/docs/ai-chat/migrating-from-a-route-handler.mdx +594 -0
  391. package/docs/ai-chat/migrating-from-hydrate-messages.mdx +299 -0
  392. package/docs/ai-chat/overview.mdx +86 -0
  393. package/docs/ai-chat/patterns/branching-conversations.mdx +145 -0
  394. package/docs/ai-chat/patterns/code-sandbox.mdx +122 -0
  395. package/docs/ai-chat/patterns/database-persistence.mdx +425 -0
  396. package/docs/ai-chat/patterns/human-in-the-loop.mdx +281 -0
  397. package/docs/ai-chat/patterns/large-payloads.mdx +165 -0
  398. package/docs/ai-chat/patterns/native-compaction.mdx +310 -0
  399. package/docs/ai-chat/patterns/oom-resilience.mdx +116 -0
  400. package/docs/ai-chat/patterns/persistence-and-replay.mdx +218 -0
  401. package/docs/ai-chat/patterns/recovery-boot.mdx +233 -0
  402. package/docs/ai-chat/patterns/redacting-telemetry.mdx +117 -0
  403. package/docs/ai-chat/patterns/skills.mdx +214 -0
  404. package/docs/ai-chat/patterns/sub-agents.mdx +412 -0
  405. package/docs/ai-chat/patterns/tool-result-auditing.mdx +145 -0
  406. package/docs/ai-chat/patterns/trusted-edge-signals.mdx +333 -0
  407. package/docs/ai-chat/patterns/version-upgrades.mdx +261 -0
  408. package/docs/ai-chat/pending-messages.mdx +363 -0
  409. package/docs/ai-chat/prompt-caching.mdx +204 -0
  410. package/docs/ai-chat/quick-start.mdx +163 -0
  411. package/docs/ai-chat/reference.mdx +1071 -0
  412. package/docs/ai-chat/server-chat.mdx +259 -0
  413. package/docs/ai-chat/sessions.mdx +334 -0
  414. package/docs/ai-chat/side-channels.mdx +172 -0
  415. package/docs/ai-chat/testing.mdx +691 -0
  416. package/docs/ai-chat/tools.mdx +192 -0
  417. package/docs/ai-chat/transcript-storage.mdx +247 -0
  418. package/docs/ai-chat/types.mdx +242 -0
  419. package/docs/ai-chat/upgrade-guide.mdx +511 -0
  420. package/docs/apikeys.mdx +170 -0
  421. package/docs/billing-limits.mdx +73 -0
  422. package/docs/building-with-ai.mdx +261 -0
  423. package/docs/bulk-actions.mdx +77 -0
  424. package/docs/changelog.mdx +6 -0
  425. package/docs/cli-deploy-commands.mdx +9 -0
  426. package/docs/cli-dev-commands.mdx +9 -0
  427. package/docs/cli-env-commands.mdx +115 -0
  428. package/docs/cli-init-commands.mdx +84 -0
  429. package/docs/cli-introduction.mdx +25 -0
  430. package/docs/cli-list-profiles-commands.mdx +42 -0
  431. package/docs/cli-login-commands.mdx +53 -0
  432. package/docs/cli-logout-commands.mdx +33 -0
  433. package/docs/cli-preview-archive.mdx +59 -0
  434. package/docs/cli-projects-commands.mdx +74 -0
  435. package/docs/cli-promote-commands.mdx +9 -0
  436. package/docs/cli-runs-commands.mdx +95 -0
  437. package/docs/cli-switch.mdx +43 -0
  438. package/docs/cli-tasks-commands.mdx +95 -0
  439. package/docs/cli-update-commands.mdx +48 -0
  440. package/docs/cli-whoami-commands.mdx +45 -0
  441. package/docs/community.mdx +6 -0
  442. package/docs/concurrency.mdx +416 -0
  443. package/docs/config/config-file.mdx +662 -0
  444. package/docs/config/extensions/additionalFiles.mdx +38 -0
  445. package/docs/config/extensions/additionalPackages.mdx +40 -0
  446. package/docs/config/extensions/aptGet.mdx +34 -0
  447. package/docs/config/extensions/audioWaveform.mdx +23 -0
  448. package/docs/config/extensions/custom.mdx +393 -0
  449. package/docs/config/extensions/emitDecoratorMetadata.mdx +52 -0
  450. package/docs/config/extensions/esbuildPlugin.mdx +31 -0
  451. package/docs/config/extensions/ffmpeg.mdx +45 -0
  452. package/docs/config/extensions/lightpanda.mdx +56 -0
  453. package/docs/config/extensions/overview.mdx +69 -0
  454. package/docs/config/extensions/playwright.mdx +195 -0
  455. package/docs/config/extensions/prismaExtension.mdx +1013 -0
  456. package/docs/config/extensions/puppeteer.mdx +28 -0
  457. package/docs/config/extensions/pythonExtension.mdx +190 -0
  458. package/docs/config/extensions/syncEnvVars.mdx +330 -0
  459. package/docs/context.mdx +235 -0
  460. package/docs/database-connections.mdx +213 -0
  461. package/docs/deploy-environment-variables.mdx +466 -0
  462. package/docs/deployment/atomic-deployment.mdx +470 -0
  463. package/docs/deployment/dev-branches.mdx +92 -0
  464. package/docs/deployment/overview.mdx +260 -0
  465. package/docs/deployment/preview-branches.mdx +227 -0
  466. package/docs/errors-retrying.mdx +383 -0
  467. package/docs/github-actions.mdx +260 -0
  468. package/docs/github-integration.mdx +148 -0
  469. package/docs/github-repo.mdx +8 -0
  470. package/docs/help-email.mdx +6 -0
  471. package/docs/help-slack.mdx +12 -0
  472. package/docs/hidden-tasks.mdx +56 -0
  473. package/docs/how-it-works.mdx +454 -0
  474. package/docs/how-to-reduce-your-spend.mdx +211 -0
  475. package/docs/idempotency.mdx +542 -0
  476. package/docs/introduction.mdx +135 -0
  477. package/docs/limits.mdx +284 -0
  478. package/docs/logging.mdx +195 -0
  479. package/docs/machines.mdx +952 -0
  480. package/docs/manual-setup.mdx +632 -0
  481. package/docs/mcp-agent-rules.mdx +41 -0
  482. package/docs/mcp-introduction.mdx +386 -0
  483. package/docs/mcp-tools.mdx +425 -0
  484. package/docs/migrating-from-v3.mdx +332 -0
  485. package/docs/observability/dashboards.mdx +166 -0
  486. package/docs/observability/query.mdx +614 -0
  487. package/docs/open-source-contributing.mdx +16 -0
  488. package/docs/private-networking/aws-console-setup.mdx +304 -0
  489. package/docs/private-networking/overview.mdx +144 -0
  490. package/docs/private-networking/troubleshooting.mdx +78 -0
  491. package/docs/queues.mdx +271 -0
  492. package/docs/quick-start.mdx +60 -0
  493. package/docs/realtime/auth.mdx +228 -0
  494. package/docs/realtime/backend/input-streams.mdx +159 -0
  495. package/docs/realtime/backend/overview.mdx +45 -0
  496. package/docs/realtime/backend/streams.mdx +433 -0
  497. package/docs/realtime/backend/subscribe.mdx +225 -0
  498. package/docs/realtime/how-it-works.mdx +94 -0
  499. package/docs/realtime/overview.mdx +63 -0
  500. package/docs/realtime/react-hooks/overview.mdx +73 -0
  501. package/docs/realtime/react-hooks/session-stream.mdx +126 -0
  502. package/docs/realtime/react-hooks/streams.mdx +517 -0
  503. package/docs/realtime/react-hooks/subscribe.mdx +690 -0
  504. package/docs/realtime/react-hooks/swr.mdx +87 -0
  505. package/docs/realtime/react-hooks/triggering.mdx +194 -0
  506. package/docs/realtime/react-hooks/use-wait-token.mdx +34 -0
  507. package/docs/realtime/run-object.mdx +197 -0
  508. package/docs/replaying.mdx +97 -0
  509. package/docs/reports.mdx +159 -0
  510. package/docs/request-feature.mdx +6 -0
  511. package/docs/roadmap.mdx +6 -0
  512. package/docs/run-tests.mdx +21 -0
  513. package/docs/run-usage.mdx +113 -0
  514. package/docs/runs/bulk-actions.mdx +183 -0
  515. package/docs/runs/heartbeats.mdx +38 -0
  516. package/docs/runs/list-best-practices.mdx +234 -0
  517. package/docs/runs/max-duration.mdx +143 -0
  518. package/docs/runs/metadata.mdx +731 -0
  519. package/docs/runs/priority.mdx +8 -0
  520. package/docs/runs.mdx +406 -0
  521. package/docs/self-hosting/docker.mdx +512 -0
  522. package/docs/self-hosting/env/supervisor.mdx +78 -0
  523. package/docs/self-hosting/env/webapp.mdx +305 -0
  524. package/docs/self-hosting/kubernetes.mdx +725 -0
  525. package/docs/self-hosting/overview.mdx +145 -0
  526. package/docs/self-hosting/security.mdx +67 -0
  527. package/docs/skills.mdx +85 -0
  528. package/docs/tags.mdx +126 -0
  529. package/docs/tasks/overview.mdx +695 -0
  530. package/docs/tasks/scheduled.mdx +479 -0
  531. package/docs/tasks/schemaTask.mdx +413 -0
  532. package/docs/tasks/streams.mdx +887 -0
  533. package/docs/triggering.mdx +1340 -0
  534. package/docs/troubleshooting-alerts.mdx +607 -0
  535. package/docs/troubleshooting-debugging-in-vscode.mdx +9 -0
  536. package/docs/troubleshooting-github-issues.mdx +6 -0
  537. package/docs/troubleshooting-uptime-status.mdx +7 -0
  538. package/docs/troubleshooting-zod.mdx +158 -0
  539. package/docs/troubleshooting.mdx +414 -0
  540. package/docs/upgrading-packages.mdx +80 -0
  541. package/docs/vercel-integration.mdx +250 -0
  542. package/docs/versioning.mdx +58 -0
  543. package/docs/video-walkthrough.mdx +23 -0
  544. package/docs/wait-for-token.mdx +540 -0
  545. package/docs/wait-for.mdx +42 -0
  546. package/docs/wait-until.mdx +53 -0
  547. package/docs/wait.mdx +18 -0
  548. package/docs/webhooks/channels.mdx +154 -0
  549. package/docs/webhooks/connect.mdx +91 -0
  550. package/docs/webhooks/deliveries.mdx +99 -0
  551. package/docs/webhooks/filters.mdx +146 -0
  552. package/docs/webhooks/human-in-the-loop.mdx +158 -0
  553. package/docs/webhooks/linear.mdx +186 -0
  554. package/docs/webhooks/overview.mdx +115 -0
  555. package/docs/webhooks/session-routing.mdx +141 -0
  556. package/docs/webhooks/slack.mdx +393 -0
  557. package/docs/webhooks/sources.mdx +250 -0
  558. package/docs/webhooks/waiters.mdx +190 -0
  559. package/docs/writing-tasks-introduction.mdx +34 -0
  560. package/package.json +143 -42
  561. package/skills/trigger-authoring-chat-agent/SKILL.md +308 -0
  562. package/skills/trigger-authoring-tasks/SKILL.md +254 -0
  563. package/skills/trigger-chat-agent-advanced/SKILL.md +403 -0
  564. package/skills/trigger-cost-savings/SKILL.md +116 -0
  565. package/skills/trigger-realtime-and-frontend/SKILL.md +276 -0
  566. package/dist/commonjs/apiClient.d.ts +0 -727
  567. package/dist/commonjs/apiClient.js +0 -692
  568. package/dist/commonjs/apiClient.js.map +0 -1
  569. package/dist/commonjs/concurrencyLimit.d.ts +0 -10
  570. package/dist/commonjs/concurrencyLimit.js +0 -17
  571. package/dist/commonjs/concurrencyLimit.js.map +0 -1
  572. package/dist/commonjs/errors.d.ts +0 -66
  573. package/dist/commonjs/errors.js +0 -109
  574. package/dist/commonjs/errors.js.map +0 -1
  575. package/dist/commonjs/httpEndpoint.d.ts +0 -87
  576. package/dist/commonjs/httpEndpoint.js +0 -130
  577. package/dist/commonjs/httpEndpoint.js.map +0 -1
  578. package/dist/commonjs/index.d.ts +0 -23
  579. package/dist/commonjs/index.js +0 -55
  580. package/dist/commonjs/index.js.map +0 -1
  581. package/dist/commonjs/integrations.d.ts +0 -11
  582. package/dist/commonjs/integrations.js.map +0 -1
  583. package/dist/commonjs/io.d.ts +0 -441
  584. package/dist/commonjs/io.js +0 -1165
  585. package/dist/commonjs/io.js.map +0 -1
  586. package/dist/commonjs/ioWithIntegrations.d.ts +0 -4
  587. package/dist/commonjs/ioWithIntegrations.js +0 -32
  588. package/dist/commonjs/ioWithIntegrations.js.map +0 -1
  589. package/dist/commonjs/job.d.ts +0 -96
  590. package/dist/commonjs/job.js +0 -210
  591. package/dist/commonjs/job.js.map +0 -1
  592. package/dist/commonjs/retry.d.ts +0 -20
  593. package/dist/commonjs/retry.js +0 -22
  594. package/dist/commonjs/retry.js.map +0 -1
  595. package/dist/commonjs/runLocalStorage.d.ts +0 -8
  596. package/dist/commonjs/runLocalStorage.js +0 -6
  597. package/dist/commonjs/runLocalStorage.js.map +0 -1
  598. package/dist/commonjs/security.d.ts +0 -18
  599. package/dist/commonjs/security.js +0 -41
  600. package/dist/commonjs/security.js.map +0 -1
  601. package/dist/commonjs/status.d.ts +0 -19
  602. package/dist/commonjs/status.js +0 -38
  603. package/dist/commonjs/status.js.map +0 -1
  604. package/dist/commonjs/store/keyValueStore.d.ts +0 -17
  605. package/dist/commonjs/store/keyValueStore.js +0 -138
  606. package/dist/commonjs/store/keyValueStore.js.map +0 -1
  607. package/dist/commonjs/store/keyValueStoreClient.d.ts +0 -19
  608. package/dist/commonjs/store/keyValueStoreClient.js +0 -65
  609. package/dist/commonjs/store/keyValueStoreClient.js.map +0 -1
  610. package/dist/commonjs/triggerClient.d.ts +0 -290
  611. package/dist/commonjs/triggerClient.js +0 -1366
  612. package/dist/commonjs/triggerClient.js.map +0 -1
  613. package/dist/commonjs/triggers/dynamic.d.ts +0 -56
  614. package/dist/commonjs/triggers/dynamic.js +0 -97
  615. package/dist/commonjs/triggers/dynamic.js.map +0 -1
  616. package/dist/commonjs/triggers/eventTrigger.d.ts +0 -58
  617. package/dist/commonjs/triggers/eventTrigger.js +0 -69
  618. package/dist/commonjs/triggers/eventTrigger.js.map +0 -1
  619. package/dist/commonjs/triggers/externalSource.d.ts +0 -148
  620. package/dist/commonjs/triggers/externalSource.js +0 -106
  621. package/dist/commonjs/triggers/externalSource.js.map +0 -1
  622. package/dist/commonjs/triggers/invokeTrigger.d.ts +0 -39
  623. package/dist/commonjs/triggers/invokeTrigger.js +0 -58
  624. package/dist/commonjs/triggers/invokeTrigger.js.map +0 -1
  625. package/dist/commonjs/triggers/notifications.d.ts +0 -111
  626. package/dist/commonjs/triggers/notifications.js +0 -101
  627. package/dist/commonjs/triggers/notifications.js.map +0 -1
  628. package/dist/commonjs/triggers/scheduled.d.ts +0 -145
  629. package/dist/commonjs/triggers/scheduled.js +0 -208
  630. package/dist/commonjs/triggers/scheduled.js.map +0 -1
  631. package/dist/commonjs/triggers/webhook.d.ts +0 -143
  632. package/dist/commonjs/triggers/webhook.js +0 -133
  633. package/dist/commonjs/triggers/webhook.js.map +0 -1
  634. package/dist/commonjs/typed-emitter.d.ts +0 -37
  635. package/dist/commonjs/typed-emitter.js +0 -3
  636. package/dist/commonjs/typed-emitter.js.map +0 -1
  637. package/dist/commonjs/types.d.ts +0 -204
  638. package/dist/commonjs/types.js +0 -23
  639. package/dist/commonjs/types.js.map +0 -1
  640. package/dist/commonjs/utils/formatSchemaErrors.d.ts +0 -3
  641. package/dist/commonjs/utils/formatSchemaErrors.js +0 -10
  642. package/dist/commonjs/utils/formatSchemaErrors.js.map +0 -1
  643. package/dist/commonjs/utils/typedAsyncLocalStorage.d.ts +0 -6
  644. package/dist/commonjs/utils/typedAsyncLocalStorage.js +0 -18
  645. package/dist/commonjs/utils/typedAsyncLocalStorage.js.map +0 -1
  646. package/dist/commonjs/utils.d.ts +0 -1
  647. package/dist/commonjs/utils.js +0 -11
  648. package/dist/commonjs/utils.js.map +0 -1
  649. package/dist/esm/apiClient.d.ts +0 -727
  650. package/dist/esm/apiClient.js +0 -687
  651. package/dist/esm/apiClient.js.map +0 -1
  652. package/dist/esm/concurrencyLimit.d.ts +0 -10
  653. package/dist/esm/concurrencyLimit.js +0 -13
  654. package/dist/esm/concurrencyLimit.js.map +0 -1
  655. package/dist/esm/errors.d.ts +0 -66
  656. package/dist/esm/errors.js +0 -95
  657. package/dist/esm/errors.js.map +0 -1
  658. package/dist/esm/httpEndpoint.d.ts +0 -87
  659. package/dist/esm/httpEndpoint.js +0 -125
  660. package/dist/esm/httpEndpoint.js.map +0 -1
  661. package/dist/esm/index.d.ts +0 -23
  662. package/dist/esm/index.js +0 -35
  663. package/dist/esm/index.js.map +0 -1
  664. package/dist/esm/integrations.d.ts +0 -11
  665. package/dist/esm/integrations.js +0 -2
  666. package/dist/esm/integrations.js.map +0 -1
  667. package/dist/esm/io.d.ts +0 -441
  668. package/dist/esm/io.js +0 -1159
  669. package/dist/esm/io.js.map +0 -1
  670. package/dist/esm/ioWithIntegrations.d.ts +0 -4
  671. package/dist/esm/ioWithIntegrations.js +0 -29
  672. package/dist/esm/ioWithIntegrations.js.map +0 -1
  673. package/dist/esm/job.d.ts +0 -96
  674. package/dist/esm/job.js +0 -206
  675. package/dist/esm/job.js.map +0 -1
  676. package/dist/esm/retry.d.ts +0 -20
  677. package/dist/esm/retry.js +0 -19
  678. package/dist/esm/retry.js.map +0 -1
  679. package/dist/esm/runLocalStorage.d.ts +0 -8
  680. package/dist/esm/runLocalStorage.js +0 -3
  681. package/dist/esm/runLocalStorage.js.map +0 -1
  682. package/dist/esm/security.d.ts +0 -18
  683. package/dist/esm/security.js +0 -34
  684. package/dist/esm/security.js.map +0 -1
  685. package/dist/esm/status.d.ts +0 -19
  686. package/dist/esm/status.js +0 -34
  687. package/dist/esm/status.js.map +0 -1
  688. package/dist/esm/store/keyValueStore.d.ts +0 -17
  689. package/dist/esm/store/keyValueStore.js +0 -134
  690. package/dist/esm/store/keyValueStore.js.map +0 -1
  691. package/dist/esm/store/keyValueStoreClient.d.ts +0 -19
  692. package/dist/esm/store/keyValueStoreClient.js +0 -61
  693. package/dist/esm/store/keyValueStoreClient.js.map +0 -1
  694. package/dist/esm/triggerClient.d.ts +0 -288
  695. package/dist/esm/triggerClient.js +0 -1359
  696. package/dist/esm/triggerClient.js.map +0 -1
  697. package/dist/esm/triggers/dynamic.d.ts +0 -56
  698. package/dist/esm/triggers/dynamic.js +0 -93
  699. package/dist/esm/triggers/dynamic.js.map +0 -1
  700. package/dist/esm/triggers/eventTrigger.d.ts +0 -58
  701. package/dist/esm/triggers/eventTrigger.js +0 -64
  702. package/dist/esm/triggers/eventTrigger.js.map +0 -1
  703. package/dist/esm/triggers/externalSource.d.ts +0 -148
  704. package/dist/esm/triggers/externalSource.js +0 -100
  705. package/dist/esm/triggers/externalSource.js.map +0 -1
  706. package/dist/esm/triggers/invokeTrigger.d.ts +0 -39
  707. package/dist/esm/triggers/invokeTrigger.js +0 -53
  708. package/dist/esm/triggers/invokeTrigger.js.map +0 -1
  709. package/dist/esm/triggers/notifications.d.ts +0 -111
  710. package/dist/esm/triggers/notifications.js +0 -94
  711. package/dist/esm/triggers/notifications.js.map +0 -1
  712. package/dist/esm/triggers/scheduled.d.ts +0 -145
  713. package/dist/esm/triggers/scheduled.js +0 -197
  714. package/dist/esm/triggers/scheduled.js.map +0 -1
  715. package/dist/esm/triggers/webhook.d.ts +0 -143
  716. package/dist/esm/triggers/webhook.js +0 -128
  717. package/dist/esm/triggers/webhook.js.map +0 -1
  718. package/dist/esm/typed-emitter.d.ts +0 -37
  719. package/dist/esm/typed-emitter.js +0 -2
  720. package/dist/esm/typed-emitter.js.map +0 -1
  721. package/dist/esm/types.d.ts +0 -204
  722. package/dist/esm/types.js +0 -19
  723. package/dist/esm/types.js.map +0 -1
  724. package/dist/esm/utils/formatSchemaErrors.d.ts +0 -3
  725. package/dist/esm/utils/formatSchemaErrors.js +0 -7
  726. package/dist/esm/utils/formatSchemaErrors.js.map +0 -1
  727. package/dist/esm/utils/typedAsyncLocalStorage.d.ts +0 -6
  728. package/dist/esm/utils/typedAsyncLocalStorage.js +0 -14
  729. package/dist/esm/utils/typedAsyncLocalStorage.js.map +0 -1
  730. package/dist/esm/utils.d.ts +0 -1
  731. package/dist/esm/utils.js +0 -8
  732. package/dist/esm/utils.js.map +0 -1
@@ -0,0 +1,962 @@
1
+ /**
2
+ * Server-side helpers for the `chat.agent` head-start flow — a
3
+ * customer's warm process (Next.js route handler, Express, etc.)
4
+ * gets the conversation moving while the heavy chat.agent run boots
5
+ * in parallel. Mid-turn, ownership of the durable stream hands over
6
+ * to the agent.
7
+ *
8
+ * The `chat.headStart({ agentId, run })` entry point returns a
9
+ * Next.js-style POST handler. Inside the customer's `run` callback
10
+ * they call `streamText` themselves, spreading
11
+ * `chat.toStreamTextOptions({ tools })` to inherit handover wiring.
12
+ * The handler runs `streamText` step 1 in the customer's process
13
+ * while the chat.agent run boots in parallel; on `tool-calls` the
14
+ * agent run picks up tool execution and continues, on pure-text the
15
+ * agent run exits clean without an LLM call.
16
+ *
17
+ * Two-layer naming: customer-facing surface is "head start"
18
+ * (describes the *benefit* — fast first-turn TTFC). The internal
19
+ * protocol still uses "handover" (describes the *mechanism* — the
20
+ * conversation hands off mid-turn from the warm process to the
21
+ * agent). Customers see `chat.headStart`, `HeadStartSession`, etc.
22
+ * The wire format and run-loop locals stay on `handover` /
23
+ * `handover-prepare` / `handover-skip`.
24
+ *
25
+ * Cooperative ordering only — handler stops writing to `session.out`
26
+ * before sending the `handover` chunk on `session.in`. No S2 fencing.
27
+ *
28
+ * ⚠️ HARD CONSTRAINT — bundle isolation
29
+ *
30
+ * This module is the customer-facing boundary for the route handler.
31
+ * The whole TTFC win comes from the customer's process being
32
+ * lightweight while the heavy agent run boots in parallel. **The
33
+ * route-handler bundle must not include heavy tool execute deps**:
34
+ * E2B, puppeteer/playwright, native bindings, the trigger SDK
35
+ * runtime, turndown, image processing libs, anything that pulls
36
+ * weight or pulls `node:` builtins.
37
+ *
38
+ * "Schema-only" tools must live in a module that imports only `ai`
39
+ * (for `tool()`) and `zod`. The agent task module imports those
40
+ * schemas and adds execute fns elsewhere — that's where the heavy
41
+ * deps live, and it's never reached by the route handler bundle.
42
+ *
43
+ * Runtime "strip executes" helpers (anything that takes a tool
44
+ * catalog with executes and removes them) DO NOT solve this. The
45
+ * import chain is resolved at bundle/build time, so importing the
46
+ * full catalog drags every dep in regardless of what the SDK does
47
+ * with the value at runtime.
48
+ *
49
+ * IMPORTANT (internal): this module must NOT import from `./ai.ts`.
50
+ * `ai.ts` statically imports `agentSkillsRuntime` (which uses `node:`
51
+ * builtins unfit for some serverless runtimes) and the heavy task
52
+ * runtime. Allowed imports: `./ai-shared.js`, `./chat-client.js`,
53
+ * `./concurrency-shared.js` (dependency-free validation helpers),
54
+ * `@trigger.dev/core/v3` (api client), `ai` (types + lightweight
55
+ * helpers like `stepCountIs` / `convertToModelMessages`).
56
+ */
57
+ import { SessionStreamInstance, TRIGGER_CONTROL_SUBTYPE, apiClientManager, } from "@trigger.dev/core/v3";
58
+ // Runtime VALUES via the ESM/CJS shim so the CJS build can `require` ESM-only
59
+ // `ai@7` (see ../imports/ai-runtime.ts).
60
+ import { convertToModelMessages, generateId as generateAssistantMessageId, stepCountIs, streamText as aiStreamText, } from "../imports/ai-runtime.js";
61
+ import { chatRunTags } from "./ai-shared.js";
62
+ import { triggerConcurrencyBody } from "./concurrency-shared.js";
63
+ import { withResolvedExternalDeploymentId } from "./externalDeploymentId.js";
64
+ /**
65
+ * The keys `buildStreamTextOptions` owns. Overriding any breaks the handover.
66
+ *
67
+ * Kept in step with the `Omit` in `HeadStartStreamTextFn`: a key the type
68
+ * rejects but this list misses reaches `streamText` anyway, and the caller gets
69
+ * the AI SDK's own error instead of one that says what to do.
70
+ */
71
+ const HEAD_START_OWNED_OPTIONS = ["messages", "prompt", "stopWhen", "abortSignal"];
72
+ function createBoundHeadStartStreamText(build) {
73
+ const bound = (options = {}) => {
74
+ const { tools, ...rest } = options;
75
+ const owned = HEAD_START_OWNED_OPTIONS.filter((key) => key in rest);
76
+ if (owned.length > 0) {
77
+ throw new Error(`chat.headStart: the \`streamText\` passed to run() owns ${owned
78
+ .map((key) => `\`${key}\``)
79
+ .join(", ")}, so it cannot be set at the call site. The handover protocol depends on ` +
80
+ "them: `messages` is the converted wire payload, `stopWhen: stepCountIs(1)` stops after " +
81
+ "step 1 so the agent run picks up tool execution, and `abortSignal` combines the request " +
82
+ "lifecycle with the idle timeout. Pass `model`, `system`, `providerOptions` and your own " +
83
+ "keys instead.");
84
+ }
85
+ return aiStreamText({ ...build({ tools }), ...rest });
86
+ };
87
+ return bound;
88
+ }
89
+ // ---------------------------------------------------------------------------
90
+ // Public API
91
+ // ---------------------------------------------------------------------------
92
+ export const chat = {
93
+ /**
94
+ * Returns a Next.js-style POST handler for the chat.agent
95
+ * head-start flow. Customer mounts it as
96
+ * `export const { POST } = chat.headStart({...})` (or
97
+ * `export const POST = chat.headStart({...})`).
98
+ *
99
+ * Pair with the browser transport's `headStart: "/api/chat"`
100
+ * option so the first message of a brand-new chat lands here
101
+ * before the agent run boots.
102
+ */
103
+ headStart(opts) {
104
+ const handler = async (req) => {
105
+ const session = await openHandoverSession({
106
+ ...(await parseHandoverRequest(req)),
107
+ agentId: opts.agentId,
108
+ idleTimeoutInSeconds: opts.idleTimeoutInSeconds,
109
+ triggerConfig: opts.triggerConfig,
110
+ tags: opts.tags,
111
+ });
112
+ const helper = {
113
+ toStreamTextOptions(spreadOpts) {
114
+ return session.buildStreamTextOptions(spreadOpts);
115
+ },
116
+ session: session.handle,
117
+ };
118
+ const result = await opts.run({
119
+ messages: session.uiMessages,
120
+ signal: session.combinedSignal,
121
+ chat: helper,
122
+ streamText: createBoundHeadStartStreamText(session.buildStreamTextOptions),
123
+ });
124
+ return session.handle.handoverResponse(result);
125
+ };
126
+ // Scope session creation + the agent trigger to `apiClient`'s env when
127
+ // provided, so the agent can live in a different project/env than the warm
128
+ // server's ambient config. The `run` callback's LLM keys are unaffected.
129
+ const { apiClient } = opts;
130
+ if (apiClient) {
131
+ return async (req) => apiClientManager.runWithConfig(apiClient, () => handler(req));
132
+ }
133
+ return handler;
134
+ },
135
+ /**
136
+ * Detached head start for backends that create the chat AND trigger the
137
+ * run in their own endpoint (e.g. a "create chat" API), then navigate the
138
+ * browser to a separate page that resumes the chat. Unlike
139
+ * `chat.headStart`, this does NOT return an SSE `Response`: it creates the
140
+ * session, triggers the `handover-prepare` run, then streams step 1 from
141
+ * your warm process straight into `session.out` and dispatches the
142
+ * handover — all as the returned `completion` promise. The destination
143
+ * page sees the whole turn (step 1 + the agent's step 2+) by resuming
144
+ * `session.out`; no `headStart` transport option is needed there.
145
+ *
146
+ * `createSession` is awaited before this resolves, so the returned
147
+ * `chatId` is immediately resumable. `completion` resolves once step 1 has
148
+ * drained and the handover is dispatched — hand it to the platform's
149
+ * "run after response" primitive (`waitUntil` / Next.js `after`) on
150
+ * serverless, or ignore it on a long-lived server.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * const { chatId, completion } = await chat.startHeadStart({
155
+ * agentId: "my-chat",
156
+ * chatId,
157
+ * messages,
158
+ * run: async ({ chat: helper }) =>
159
+ * streamText({ ...helper.toStreamTextOptions({ tools }), model, system }),
160
+ * });
161
+ * waitUntil(completion); // serverless: keep warm until step 1 + handover finish
162
+ * return Response.json({ chatId });
163
+ * ```
164
+ */
165
+ async startHeadStart(opts) {
166
+ const open = () => openHandoverSession({
167
+ chatId: opts.chatId,
168
+ uiMessages: opts.messages,
169
+ wirePayload: {
170
+ chatId: opts.chatId,
171
+ trigger: "handover-prepare",
172
+ headStartMessages: opts.messages,
173
+ ...(opts.metadata !== undefined ? { metadata: opts.metadata } : {}),
174
+ },
175
+ agentId: opts.agentId,
176
+ idleTimeoutInSeconds: opts.idleTimeoutInSeconds,
177
+ triggerConfig: opts.triggerConfig,
178
+ tags: opts.tags,
179
+ });
180
+ // Scope session creation + the agent trigger to `apiClient`'s env when
181
+ // provided (mirrors `chat.headStart`). The client captured inside
182
+ // `openHandoverSession` is reused for the drain + handover dispatch, so
183
+ // `completion` needs no further config scoping. LLM keys in `run` are
184
+ // unaffected.
185
+ const session = opts.apiClient
186
+ ? await apiClientManager.runWithConfig(opts.apiClient, open)
187
+ : await open();
188
+ const helper = {
189
+ toStreamTextOptions(spreadOpts) {
190
+ return session.buildStreamTextOptions(spreadOpts);
191
+ },
192
+ session: session.handle,
193
+ };
194
+ const completion = (async () => {
195
+ let result;
196
+ try {
197
+ result = await opts.run({
198
+ messages: session.uiMessages,
199
+ signal: session.combinedSignal,
200
+ chat: helper,
201
+ streamText: createBoundHeadStartStreamText(session.buildStreamTextOptions),
202
+ });
203
+ }
204
+ catch (err) {
205
+ // The warm step never produced a result — tell the agent run to exit
206
+ // clean instead of idle-waiting the full handover timeout.
207
+ await session.handle.handoverSkip().catch(() => { });
208
+ throw err;
209
+ }
210
+ // Stamp step 1 with the turn's stable messageId so the agent's step 2+
211
+ // merges into the same assistant message, then drain it to session.out.
212
+ const stream = result.toUIMessageStream({
213
+ generateMessageId: () => session.turnMessageId,
214
+ });
215
+ session.drainToSessionOut(stream);
216
+ // Awaits the drain, then dispatches handover / handover-skip. Owns its
217
+ // own skip-on-error and idle-timer cleanup.
218
+ await session.handle.handoverWhenDone(result);
219
+ })();
220
+ // Unhandled-rejection guard: a long-lived server that ignores `completion`
221
+ // shouldn't crash under `--unhandled-rejections=throw`. Awaiting the
222
+ // returned promise still surfaces the error.
223
+ completion.catch(() => { });
224
+ return { chatId: opts.chatId, pendingVersion: session.handle.pendingVersion, completion };
225
+ },
226
+ /**
227
+ * Lower-level primitive for power users who want to call
228
+ * `streamText` themselves outside the `run` callback shape — custom
229
+ * transforms, non-AI-SDK code paths, or manual control over the
230
+ * response. Same wiring `chat.headStart` builds on internally.
231
+ */
232
+ openSession(opts) {
233
+ return (async () => {
234
+ const session = await openHandoverSession({
235
+ ...(await parseHandoverRequest(opts.req)),
236
+ agentId: opts.agentId,
237
+ idleTimeoutInSeconds: opts.idleTimeoutInSeconds,
238
+ triggerConfig: opts.triggerConfig,
239
+ });
240
+ return session.handle;
241
+ })();
242
+ },
243
+ /**
244
+ * Wrap a Web Fetch handler — `(req: Request) => Promise<Response>` —
245
+ * as a Node `http` listener — `(req: IncomingMessage, res: ServerResponse) => Promise<void>`.
246
+ *
247
+ * Use this to mount `chat.headStart` (or any other Web Fetch
248
+ * handler) inside Node-only frameworks like Express, Fastify, Koa,
249
+ * or raw `node:http`. Web-native frameworks (Next.js App Router,
250
+ * Hono, SvelteKit, Remix, Workers, Bun, Deno, etc.) don't need
251
+ * this — they pass `Request` objects directly.
252
+ *
253
+ * Streams the response body chunk-by-chunk to the Node response,
254
+ * so the `chat.headStart` SSE chunks reach the browser as they
255
+ * arrive (no buffering). Aborts the underlying handler if the
256
+ * client closes the connection.
257
+ *
258
+ * Type-only import of `node:http` types — no runtime dep on `node:http`,
259
+ * so this stays safe to bundle into edge / Workers builds (the
260
+ * function just won't be called there).
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * import express from "express";
265
+ * import { chat } from "@trigger.dev/sdk/chat-server";
266
+ *
267
+ * const handler = chat.headStart({
268
+ * agentId: "my-chat",
269
+ * run: async ({ chat: helper }) => streamText({ ... }),
270
+ * });
271
+ *
272
+ * const app = express();
273
+ * app.post("/api/chat", chat.toNodeListener(handler));
274
+ * ```
275
+ */
276
+ toNodeListener,
277
+ };
278
+ /**
279
+ * Parse the AI SDK transport's wire payload out of the route-handler
280
+ * `Request` for `chat.headStart` / `chat.openSession`. The detached
281
+ * `chat.startHeadStart` path skips this — it's handed the chatId and
282
+ * messages directly.
283
+ */
284
+ async function parseHandoverRequest(req) {
285
+ const wirePayload = (await req.json());
286
+ const chatId = wirePayload.chatId;
287
+ if (!chatId) {
288
+ throw new Error("[chat.handover] request body missing `chatId`");
289
+ }
290
+ // Slim wire — head-start ships full history via `headStartMessages` (not
291
+ // `message`/`messages`) because the route handler runs on the customer's
292
+ // own HTTP endpoint and isn't subject to the 512 KiB `/in/append` cap.
293
+ const uiMessages = (wirePayload.headStartMessages ?? []);
294
+ return {
295
+ chatId,
296
+ uiMessages,
297
+ wirePayload,
298
+ requestSignal: req.signal,
299
+ };
300
+ }
301
+ async function openHandoverSession(opts) {
302
+ const { chatId, uiMessages, wirePayload } = opts;
303
+ if (!chatId) {
304
+ throw new Error("[chat.handover] missing `chatId`");
305
+ }
306
+ // The full UIMessage[] flows through `wirePayload` into the auto-trigger
307
+ // `basePayload` below, where the agent run boot consumes it on first turn.
308
+ // `convertToModelMessages` is async — resolve once up front so the
309
+ // synchronous `toStreamTextOptions` builder can hand back a fully
310
+ // formed object. AI SDK's `streamText` validates `messages` as a
311
+ // `ModelMessage[]` synchronously and rejects a Promise.
312
+ const modelMessages = await convertToModelMessages(uiMessages);
313
+ const apiClient = resolveApiClient();
314
+ // Top-level `idleTimeoutInSeconds` wins over the one in `triggerConfig`.
315
+ const idleTimeoutInSeconds = opts.idleTimeoutInSeconds ?? opts.triggerConfig?.idleTimeoutInSeconds ?? 60;
316
+ // Merge the customer's trigger options. `handover-prepare` and `chatId` in
317
+ // `basePayload` are ours and can't be overridden; the `chat:{chatId}` tag is
318
+ // prepended when it fits within the tag length limit (see `chatRunTags`).
319
+ const tags = chatRunTags(chatId, opts.triggerConfig?.tags);
320
+ const triggerConfig = {
321
+ basePayload: {
322
+ ...(opts.triggerConfig?.basePayload ?? {}),
323
+ ...wirePayload,
324
+ chatId,
325
+ trigger: "handover-prepare",
326
+ idleTimeoutInSeconds,
327
+ },
328
+ ...(opts.triggerConfig?.machine ? { machine: opts.triggerConfig.machine } : {}),
329
+ ...(opts.triggerConfig?.queue ? { queue: opts.triggerConfig.queue } : {}),
330
+ ...(opts.triggerConfig?.concurrency !== undefined
331
+ ? triggerConcurrencyBody(opts.triggerConfig.concurrency)
332
+ : {}),
333
+ ...(opts.triggerConfig?.concurrencyKey !== undefined
334
+ ? { concurrencyKey: opts.triggerConfig.concurrencyKey }
335
+ : {}),
336
+ tags,
337
+ ...(opts.triggerConfig?.maxAttempts !== undefined
338
+ ? { maxAttempts: opts.triggerConfig.maxAttempts }
339
+ : {}),
340
+ ...(opts.triggerConfig?.maxDuration !== undefined
341
+ ? { maxDuration: opts.triggerConfig.maxDuration }
342
+ : {}),
343
+ ...(opts.triggerConfig?.region ? { region: opts.triggerConfig.region } : {}),
344
+ ...(opts.triggerConfig?.lockToVersion
345
+ ? { lockToVersion: opts.triggerConfig.lockToVersion }
346
+ : {}),
347
+ ...(opts.triggerConfig?.ttl !== undefined ? { ttl: opts.triggerConfig.ttl } : {}),
348
+ // Not truthiness: `null` opts this chat out of pinning and must reach the resolver.
349
+ ...(opts.triggerConfig?.externalDeploymentId !== undefined
350
+ ? { externalDeploymentId: opts.triggerConfig.externalDeploymentId }
351
+ : {}),
352
+ idleTimeoutInSeconds,
353
+ };
354
+ // Create the session and trigger the chat.agent's `handover-prepare`
355
+ // run atomically. `createSession` is idempotent on `(env, externalId
356
+ // = chatId)` and the auto-triggered run uses `triggerConfig.
357
+ // basePayload` as the wire payload — so a single round-trip both
358
+ // ensures the session exists and starts the agent booting with the
359
+ // right trigger.
360
+ //
361
+ // Awaited intentionally: subsequent writes to `session.out` (the
362
+ // tee from the customer's `streamText` to S2) need the session to
363
+ // exist, and the handover signal at end-of-step-1 needs the agent
364
+ // run to be there to consume it. The added latency (~one round trip
365
+ // to the control plane) is bounded; the agent's compute boot still
366
+ // overlaps with LLM TTFB.
367
+ // Bypasses `sessions.start`, so it resolves the pin itself.
368
+ const created = await apiClient.createSession(withResolvedExternalDeploymentId({
369
+ type: "chat.agent",
370
+ externalId: chatId,
371
+ taskIdentifier: opts.agentId,
372
+ triggerConfig,
373
+ ...(opts.tags !== undefined ? { tags: opts.tags } : {}),
374
+ }));
375
+ const sessionPublicAccessToken = created.publicAccessToken;
376
+ const pendingVersion = created.pendingVersion === true;
377
+ // Combined abort signal: request lifecycle OR an internal timeout
378
+ // mirroring the agent's idle wait so a hung handler doesn't sit
379
+ // forever.
380
+ const abortController = new AbortController();
381
+ const requestAbort = opts.requestSignal;
382
+ if (requestAbort) {
383
+ if (requestAbort.aborted)
384
+ abortController.abort();
385
+ else
386
+ requestAbort.addEventListener("abort", () => abortController.abort(), { once: true });
387
+ }
388
+ const idleTimer = setTimeout(() => abortController.abort(new Error("chat.handover: idle timeout")), idleTimeoutInSeconds * 1000);
389
+ const buildStreamTextOptions = (spreadOpts) => {
390
+ // The customer spreads this object into their `streamText` call
391
+ // and then adds `model`, `system`, etc. on top. We set the four
392
+ // keys handover correctness depends on:
393
+ //
394
+ // - `messages`: the wire payload's UIMessages, converted
395
+ // (Promise resolved upfront so the spread is synchronous)
396
+ // - `tools`: customer's schema-only tool set
397
+ // - `stopWhen`: `stepCountIs(1)` — step 1 only. Agent run picks
398
+ // up tool execution and step 2+ after the handover signal.
399
+ // - `abortSignal`: combined request-lifecycle + idle timeout
400
+ //
401
+ // The customer's `StreamTextResult` exposes `finishReason` and
402
+ // `response.messages` directly, so we don't need to install an
403
+ // `onStepFinish` capture hook — we read those off the result in
404
+ // `handoverWhenDone`.
405
+ return {
406
+ messages: modelMessages,
407
+ tools: spreadOpts?.tools,
408
+ stopWhen: stepCountIs(1),
409
+ abortSignal: abortController.signal,
410
+ };
411
+ };
412
+ // Tee a UIMessage stream into session.out via S2 direct-write,
413
+ // batched. `SessionStreamInstance` calls `initializeSessionStream`
414
+ // once to fetch S2 credentials, then pipes via `StreamsWriterV2`'s
415
+ // `BatchTransform` — one S2 append per ~200ms of chunks instead of
416
+ // one HTTP round-trip per UIMessageChunk.
417
+ let sessionWriter = null;
418
+ const tee = (stream) => {
419
+ const [a, b] = stream.tee();
420
+ sessionWriter = new SessionStreamInstance({
421
+ apiClient,
422
+ baseUrl: apiClient.baseUrl,
423
+ sessionId: chatId, // Sessions are addressable by externalId (chatId).
424
+ io: "out",
425
+ source: b,
426
+ signal: abortController.signal,
427
+ });
428
+ return a;
429
+ };
430
+ // Detached drain (no HTTP response branch): hand the WHOLE stream to the S2
431
+ // writer as its source. `StreamsWriterV2` self-pumps the source to S2, so the
432
+ // stream drains to `session.out` without any reader pulling it. `handoverWhenDone`
433
+ // awaits `flushSessionWriter()` before dispatching, so step 1 lands in order
434
+ // ahead of the agent's step 2+.
435
+ const drainToSessionOut = (stream) => {
436
+ sessionWriter = new SessionStreamInstance({
437
+ apiClient,
438
+ baseUrl: apiClient.baseUrl,
439
+ sessionId: chatId,
440
+ io: "out",
441
+ source: stream,
442
+ signal: abortController.signal,
443
+ });
444
+ };
445
+ /** Wait for the teed S2 writer to drain. Called before signaling handover. */
446
+ const flushSessionWriter = async () => {
447
+ if (!sessionWriter)
448
+ return;
449
+ try {
450
+ await sessionWriter.wait();
451
+ }
452
+ catch (error) {
453
+ // Dropped, not thrown: the customer's response stream is the source of
454
+ // truth for what the user sees. Logged so the loss is diagnosable.
455
+ const { message, code, status, origin } = (error ?? {});
456
+ console.warn("[chat.handover] session.out write failed", {
457
+ chatId,
458
+ message,
459
+ code,
460
+ status,
461
+ origin,
462
+ });
463
+ }
464
+ };
465
+ const handover = async (args) => {
466
+ const chunk = {
467
+ kind: "handover",
468
+ partialAssistantMessage: args.partialAssistantMessage,
469
+ messageId: args.messageId,
470
+ isFinal: args.isFinal,
471
+ };
472
+ await apiClient.appendToSessionStream(chatId, "in", JSON.stringify(chunk));
473
+ };
474
+ /**
475
+ * Sent only on dispatch error (handler aborted before producing a
476
+ * `finishReason`). Normal pure-text and tool-call finishes go
477
+ * through `handover()` with the appropriate `isFinal` flag.
478
+ */
479
+ // Clear the idle timer on every terminal path. The detached failure path
480
+ // (run() throws -> handoverSkip) otherwise leaves it armed until the idle
481
+ // timeout elapses, since only handoverWhenDone used to clear it.
482
+ const cleanup = () => clearTimeout(idleTimer);
483
+ const handoverSkip = async () => {
484
+ try {
485
+ const chunk = { kind: "handover-skip" };
486
+ await apiClient.appendToSessionStream(chatId, "in", JSON.stringify(chunk));
487
+ }
488
+ finally {
489
+ cleanup();
490
+ }
491
+ };
492
+ // A stable assistant messageId for this turn. The customer's
493
+ // `toUIMessageStream` is configured to emit its `start` chunk with
494
+ // this id, the handover signal carries it to the agent, and the
495
+ // agent's post-handover `toUIMessageStream` reuses it — so all
496
+ // chunks (customer's step 1 + agent's step 2) merge into one
497
+ // assistant message on the browser side.
498
+ const turnMessageId = generateAssistantMessageId();
499
+ let resolveDecision;
500
+ const decisionPromise = new Promise((resolve) => {
501
+ resolveDecision = resolve;
502
+ });
503
+ const handoverWhenDone = async (result) => {
504
+ // Owns idle-timer cleanup via the finally below, so both the
505
+ // sugar (`handoverResponse`) and the escape-hatch
506
+ // (`chat.openSession()` → `handle.handoverWhenDone(...)`) clean up
507
+ // the timer the same way.
508
+ try {
509
+ // `result.finishReason` is a Promise<FinishReason> on the AI SDK
510
+ // result. Wait for the stream to settle, then dispatch.
511
+ const finishReason = await result.finishReason;
512
+ // Drain the S2 tee so any in-flight handler writes (last
513
+ // `tool-input-available` parts, the synthetic `finish-step` for
514
+ // pure-text) are visible before the agent reads from session.out
515
+ // / session.in. Cooperative ordering — agent doesn't read past
516
+ // these unless we've finished writing them.
517
+ await flushSessionWriter();
518
+ const responseMessages = (await result.response).messages;
519
+ if (finishReason === "tool-calls") {
520
+ // Reshape pending tool-calls into AI SDK's tool-approval round
521
+ // so the agent's `streamText` resumes by executing them
522
+ // before the step-2 LLM call.
523
+ const reshaped = reshapeForHandoverResume(responseMessages);
524
+ await handover({
525
+ partialAssistantMessage: reshaped,
526
+ messageId: turnMessageId,
527
+ isFinal: false,
528
+ });
529
+ }
530
+ else {
531
+ // Pure-text (or any non-tool-calls) finish — customer's step 1
532
+ // IS the final response. The agent runs the turn-loop hooks
533
+ // (`onChatStart`, `onTurnStart`, `onTurnComplete`, etc.) using
534
+ // this partial as the response, but skips the LLM call. That
535
+ // way persistence (`onTurnComplete` writing to DB), self-
536
+ // review, and any post-turn work all fire normally.
537
+ await handover({
538
+ partialAssistantMessage: responseMessages,
539
+ messageId: turnMessageId,
540
+ isFinal: true,
541
+ });
542
+ }
543
+ resolveDecision({ kind: "handover" });
544
+ }
545
+ catch (err) {
546
+ // Dispatch failed before we could send the handover signal.
547
+ // Tell the agent to exit clean (no hooks fire) and close the
548
+ // response stream so it doesn't hang waiting for agent chunks.
549
+ resolveDecision({ kind: "handover-skip" });
550
+ try {
551
+ await handoverSkip();
552
+ }
553
+ catch {
554
+ // best-effort
555
+ }
556
+ throw err;
557
+ }
558
+ finally {
559
+ cleanup();
560
+ }
561
+ };
562
+ /**
563
+ * Build a single ReadableStream that:
564
+ * 1. Forwards the customer's `streamText` chunks (step 1) directly
565
+ * to the response — same low-latency path as before.
566
+ * 2. After step 1 ends and the dispatch decision lands:
567
+ * - `handover-skip`: closes the response immediately. The agent
568
+ * run exits without writing more chunks.
569
+ * - `handover`: subscribes to `session.out` from the sequence
570
+ * ID where the customer's tee left off, forwarding the agent
571
+ * run's chunks (tool-output-available, step 2 LLM text,
572
+ * `finish-step`, etc.) until `trigger:turn-complete`.
573
+ *
574
+ * The browser sees one continuous SSE response per first turn, just
575
+ * like a normal `streamText` would produce.
576
+ */
577
+ const stitchHandoverStream = (customerBranch) => {
578
+ return new ReadableStream({
579
+ async start(controller) {
580
+ try {
581
+ // Phase 1: forward customer's chunks.
582
+ const reader = customerBranch.getReader();
583
+ try {
584
+ while (true) {
585
+ const { done, value } = await reader.read();
586
+ if (done)
587
+ break;
588
+ controller.enqueue(value);
589
+ }
590
+ }
591
+ finally {
592
+ reader.releaseLock();
593
+ }
594
+ // Phase 2a: wait for handoverWhenDone to decide.
595
+ const decision = await decisionPromise;
596
+ if (decision.kind === "handover-skip") {
597
+ controller.close();
598
+ return;
599
+ }
600
+ // Phase 2b: agent is taking over. Resume from session.out
601
+ // starting AFTER the customer tee's last write, so we don't
602
+ // re-emit chunks the browser already saw.
603
+ const writeResult = sessionWriter
604
+ ? await sessionWriter.wait().catch(() => undefined)
605
+ : undefined;
606
+ const customerLastEventId = writeResult?.lastEventId;
607
+ // Capture the latest S2 event id seen on session.out via
608
+ // `onPart`. After the stream closes we emit it to the
609
+ // browser as a `trigger:session-state` control chunk so the
610
+ // transport can hydrate `state.lastEventId` for turn 2's
611
+ // subscribe — without it, turn 2 reads session.out from the
612
+ // start and replays turn 1 to the user.
613
+ //
614
+ // The agent's `turn-complete` control record is now header-
615
+ // form on S2 (see `client-protocol.mdx`), so the
616
+ // `for await (const chunk of agentStream)` loop below NEVER
617
+ // sees it as a data chunk — `subscribeToSessionStream` routes
618
+ // it to `onControl`. Use that to know when to stop and
619
+ // synthesise the data-chunk shape the browser bridge still
620
+ // expects (this HTTP response stream is NOT S2 and keeps the
621
+ // legacy chunk shape for the customer-server-to-browser hop).
622
+ let latestEventId;
623
+ let turnComplete = false;
624
+ // Dedicated abort signal for this agent subscription. Aborted
625
+ // from `onControl` the moment turn-complete fires so the
626
+ // `for await` loop below exits immediately instead of blocking
627
+ // until S2's long-poll closes (~60s). Combined with the outer
628
+ // `abortController.signal` via `AbortSignal.any` so a request-
629
+ // wide abort still tears the subscription down.
630
+ const subscriptionAbort = new AbortController();
631
+ const agentStream = await apiClient.subscribeToSessionStream(chatId, "out", {
632
+ ...(customerLastEventId != null ? { lastEventId: customerLastEventId } : {}),
633
+ signal: AbortSignal.any([abortController.signal, subscriptionAbort.signal]),
634
+ onPart: (part) => {
635
+ if (part.id)
636
+ latestEventId = part.id;
637
+ },
638
+ onControl: (event) => {
639
+ if (event.subtype === TRIGGER_CONTROL_SUBTYPE.TURN_COMPLETE) {
640
+ turnComplete = true;
641
+ // Synthesise the data-chunk shape for the browser
642
+ // bridge. The customer-server-to-browser response is
643
+ // not S2; it keeps the legacy chunk shape so the
644
+ // browser's transport can recognise turn-complete the
645
+ // same way it always has.
646
+ controller.enqueue({
647
+ type: "trigger:turn-complete",
648
+ });
649
+ // Stop the SSE read now. Without this the `for await`
650
+ // can't see the control event (control records are
651
+ // never enqueued into the data stream) and would idle
652
+ // until S2's long-poll timeout closes the connection.
653
+ subscriptionAbort.abort();
654
+ }
655
+ },
656
+ });
657
+ try {
658
+ for await (const chunk of agentStream) {
659
+ // Data records only — control records are routed via
660
+ // `onControl` above and trigger the subscription abort.
661
+ controller.enqueue(chunk);
662
+ if (turnComplete)
663
+ break;
664
+ }
665
+ }
666
+ catch (err) {
667
+ // AbortError from `subscriptionAbort` is the expected exit
668
+ // path once turn-complete fires; surface anything else.
669
+ const isAbort = err instanceof Error && err.name === "AbortError";
670
+ if (!isAbort || !turnComplete)
671
+ throw err;
672
+ }
673
+ // Final control chunk: hand the browser transport the
674
+ // `lastEventId` it should use for the next turn's
675
+ // session.out subscribe. Filtered out before reaching the
676
+ // AI SDK on the browser side.
677
+ if (latestEventId != null) {
678
+ controller.enqueue({
679
+ type: "trigger:session-state",
680
+ lastEventId: latestEventId,
681
+ });
682
+ }
683
+ controller.close();
684
+ }
685
+ catch (err) {
686
+ controller.error(err);
687
+ }
688
+ },
689
+ cancel() {
690
+ // Browser closed the connection. Trigger the abort so any
691
+ // pending session.out subscription stops too.
692
+ abortController.abort();
693
+ },
694
+ });
695
+ };
696
+ const handoverResponse = (result) => {
697
+ // `generateMessageId` makes the customer's `start` chunk carry
698
+ // `turnMessageId`, so the browser-side AI SDK keys the assistant
699
+ // message by it. The agent's post-handover stream emits chunks
700
+ // with the same id (passed via the handover signal) — both sides
701
+ // merge into one message on the browser.
702
+ const teed = tee(result.toUIMessageStream({
703
+ generateMessageId: () => turnMessageId,
704
+ }));
705
+ // `handoverWhenDone` re-throws on dispatch failure for visibility,
706
+ // but the recovery (resolveDecision + handoverSkip) has already run
707
+ // by then and `stitchHandoverStream` closes the response cleanly via
708
+ // `decisionPromise`. The user-facing path is fine; we only suppress
709
+ // the unhandled-rejection so processes started with
710
+ // `--unhandled-rejections=throw` don't crash on what is effectively
711
+ // a logged failure with no further action to take.
712
+ // (Idle-timer cleanup lives inside `handoverWhenDone` itself.)
713
+ void handoverWhenDone(result).catch(() => { });
714
+ const stitched = stitchHandoverStream(teed);
715
+ // Encode UIMessageChunks as SSE for the AI SDK transport on the
716
+ // browser. AI SDK's `toUIMessageStreamResponse()` does this same
717
+ // thing internally; replicate the format here so we don't have
718
+ // to bridge through the SDK's response helper.
719
+ const encoder = new TextEncoder();
720
+ const sseStream = stitched.pipeThrough(new TransformStream({
721
+ transform(chunk, controller) {
722
+ controller.enqueue(encoder.encode(`data: ${JSON.stringify(chunk)}\n\n`));
723
+ },
724
+ }));
725
+ return new Response(sseStream, {
726
+ headers: {
727
+ "Content-Type": "text/event-stream",
728
+ "X-Vercel-AI-UI-Message-Stream": "v1",
729
+ "Cache-Control": "no-cache, no-transform",
730
+ Connection: "keep-alive",
731
+ // Browser transport reads these to hydrate session state
732
+ // for subsequent (non-handover) turns. Once the browser has
733
+ // the PAT it talks directly to `session.in` / `session.out`
734
+ // without going back through the handler.
735
+ "X-Trigger-Chat-Id": chatId,
736
+ "X-Trigger-Chat-Access-Token": sessionPublicAccessToken,
737
+ // Only sent when parked, so an unpinned chat's headers are unchanged.
738
+ ...(pendingVersion ? { "X-Trigger-Chat-Pending-Version": "1" } : {}),
739
+ },
740
+ });
741
+ };
742
+ const handle = {
743
+ chatId,
744
+ pendingVersion,
745
+ tee,
746
+ handoverWhenDone,
747
+ handoverResponse,
748
+ handover,
749
+ handoverSkip,
750
+ };
751
+ return {
752
+ uiMessages,
753
+ combinedSignal: abortController.signal,
754
+ handle,
755
+ buildStreamTextOptions,
756
+ turnMessageId,
757
+ drainToSessionOut,
758
+ };
759
+ }
760
+ function resolveApiClient() {
761
+ // Reuse the SDK's standard apiClientManager so customers configure
762
+ // base URL + secret key the same way as for `tasks.trigger(...)`.
763
+ const client = apiClientManager.clientOrThrow();
764
+ return client;
765
+ }
766
+ /** @internal — exposed via `chat.toNodeListener`. */
767
+ function toNodeListener(webHandler) {
768
+ return async function nodeListener(req, res) {
769
+ const abort = new AbortController();
770
+ res.on("close", () => abort.abort());
771
+ try {
772
+ const url = `http://${req.headers.host ?? "localhost"}${req.url ?? "/"}`;
773
+ const method = req.method ?? "GET";
774
+ const hasBody = method !== "GET" && method !== "HEAD";
775
+ // Read full body upfront. Chat wire payloads are small (sub-KB
776
+ // typically) so accumulating avoids the duplex-stream ceremony
777
+ // some Node versions need for streaming request bodies into
778
+ // a Web Request.
779
+ let body;
780
+ if (hasBody) {
781
+ const chunks = [];
782
+ for await (const chunk of req) {
783
+ chunks.push(chunk);
784
+ }
785
+ if (chunks.length > 0) {
786
+ let total = 0;
787
+ for (const c of chunks)
788
+ total += c.length;
789
+ const merged = new Uint8Array(total);
790
+ let offset = 0;
791
+ for (const c of chunks) {
792
+ merged.set(c, offset);
793
+ offset += c.length;
794
+ }
795
+ body = merged.buffer.slice(merged.byteOffset, merged.byteOffset + merged.byteLength);
796
+ }
797
+ }
798
+ // Flatten Node header values: arrays → comma-joined (per RFC 7230 §3.2.2).
799
+ const webHeaders = new Headers();
800
+ for (const [name, value] of Object.entries(req.headers)) {
801
+ if (value == null)
802
+ continue;
803
+ if (Array.isArray(value)) {
804
+ for (const v of value)
805
+ webHeaders.append(name, v);
806
+ }
807
+ else {
808
+ webHeaders.set(name, value);
809
+ }
810
+ }
811
+ const webReq = new Request(url, {
812
+ method,
813
+ headers: webHeaders,
814
+ body,
815
+ signal: abort.signal,
816
+ });
817
+ const webRes = await webHandler(webReq);
818
+ res.statusCode = webRes.status;
819
+ // `Headers.forEach` exposes the value comma-joined for multi-valued
820
+ // headers, which `setHeader` accepts. Set-Cookie is handled separately
821
+ // via `getSetCookie()` to preserve multiple values.
822
+ webRes.headers.forEach((value, key) => {
823
+ if (key.toLowerCase() === "set-cookie")
824
+ return;
825
+ res.setHeader(key, value);
826
+ });
827
+ const setCookies = typeof webRes.headers.getSetCookie ===
828
+ "function"
829
+ ? webRes.headers.getSetCookie()
830
+ : [];
831
+ if (setCookies.length > 0) {
832
+ res.setHeader("set-cookie", setCookies);
833
+ }
834
+ if (!webRes.body) {
835
+ res.end();
836
+ return;
837
+ }
838
+ // Pipe the Web Response body to the Node response. On client
839
+ // disconnect (`abort.signal`), cancel the reader so a pending
840
+ // `read()` rejects and we exit the loop instead of blocking on
841
+ // a stream that will never produce more chunks.
842
+ const reader = webRes.body.getReader();
843
+ const onAbort = () => {
844
+ reader.cancel(abort.signal.reason).catch(() => { });
845
+ };
846
+ if (abort.signal.aborted)
847
+ onAbort();
848
+ else
849
+ abort.signal.addEventListener("abort", onAbort, { once: true });
850
+ try {
851
+ while (true) {
852
+ const { done, value } = await reader.read();
853
+ if (done)
854
+ break;
855
+ res.write(value);
856
+ }
857
+ }
858
+ catch {
859
+ // Reader was cancelled (client disconnect). Silently end.
860
+ }
861
+ finally {
862
+ abort.signal.removeEventListener("abort", onAbort);
863
+ }
864
+ res.end();
865
+ }
866
+ catch (err) {
867
+ if (!res.headersSent) {
868
+ res.statusCode = 500;
869
+ res.setHeader("content-type", "text/plain; charset=utf-8");
870
+ res.end(err instanceof Error ? err.message : "Internal error");
871
+ }
872
+ else {
873
+ res.end();
874
+ }
875
+ }
876
+ };
877
+ }
878
+ /**
879
+ * Reshape a step-1 partial so the agent's `streamText` resumes by
880
+ * executing pending tool-calls before the next LLM call.
881
+ *
882
+ * When the customer's handler runs `streamText` with schema-only tools
883
+ * (no `execute` fns) and `stopWhen: stepCountIs(1)`, the LLM emits
884
+ * tool-calls but AI SDK can't execute them — the partial we ship is
885
+ * `[{ assistant: text + tool-call }]`. Splicing that as-is onto the
886
+ * agent's accumulator and calling `streamText` throws
887
+ * `MissingToolResultsError` synchronously inside
888
+ * `convertToLanguageModelPrompt`.
889
+ *
890
+ * AI SDK's documented escape hatch for "external party decides what
891
+ * to do with a tool-call, then SDK executes" is the tool-approval
892
+ * round. By appending a `tool-approval-request` part to the assistant
893
+ * message and a trailing `tool` message with a matching
894
+ * `tool-approval-response { approved: true }`, AI SDK:
895
+ * 1. Suppresses `MissingToolResultsError` for approved tool-calls
896
+ * (`convert-to-language-model-prompt.ts:135-144`).
897
+ * 2. Hits its initial-tool-execution branch
898
+ * (`stream-text.ts:1342-1486`) on the next `streamText` call,
899
+ * runs the agent-side `execute` fns, and synthesizes
900
+ * `tool-result` parts before the step-2 LLM call.
901
+ *
902
+ * If the customer's tools already had `execute` fns (rare for the
903
+ * handover use case but valid), the partial already contains a
904
+ * `tool-result` per tool-call — we leave those alone and only inject
905
+ * approvals for genuinely-pending calls.
906
+ *
907
+ * `collectToolApprovals` only scans the LAST message
908
+ * (`collect-tool-approvals.ts:30-37`), so the synthesized tool message
909
+ * must end up at the tail of the partial. The agent's run-loop
910
+ * splices the partial onto the end of the accumulator, which keeps
911
+ * this invariant.
912
+ */
913
+ function reshapeForHandoverResume(responseMessages) {
914
+ // First pass: gather the set of tool-call IDs that already have a
915
+ // matching tool-result. Those are "complete" — leave them alone.
916
+ const completedToolCallIds = new Set();
917
+ for (const message of responseMessages) {
918
+ if (message.role !== "tool" || typeof message.content === "string")
919
+ continue;
920
+ for (const part of message.content) {
921
+ if (part.type === "tool-result" && part.toolCallId) {
922
+ completedToolCallIds.add(part.toolCallId);
923
+ }
924
+ }
925
+ }
926
+ // Second pass: clone the messages, appending a tool-approval-request
927
+ // alongside each pending tool-call. Collect the matching responses.
928
+ const approvalResponses = [];
929
+ let approvalCounter = 0;
930
+ const reshaped = responseMessages.map((message) => {
931
+ if (message.role !== "assistant" || typeof message.content === "string") {
932
+ return message;
933
+ }
934
+ const newContent = [...message.content];
935
+ for (const part of message.content) {
936
+ if (part.type === "tool-call" &&
937
+ part.toolCallId &&
938
+ !completedToolCallIds.has(part.toolCallId)) {
939
+ const approvalId = `handover-approval-${++approvalCounter}`;
940
+ newContent.push({
941
+ type: "tool-approval-request",
942
+ approvalId,
943
+ toolCallId: part.toolCallId,
944
+ });
945
+ approvalResponses.push({
946
+ type: "tool-approval-response",
947
+ approvalId,
948
+ approved: true,
949
+ });
950
+ }
951
+ }
952
+ return { ...message, content: newContent };
953
+ });
954
+ if (approvalResponses.length > 0) {
955
+ reshaped.push({
956
+ role: "tool",
957
+ content: approvalResponses,
958
+ });
959
+ }
960
+ return reshaped;
961
+ }
962
+ //# sourceMappingURL=chat-server.js.map