@agentuity/runtime 2.0.11 → 3.0.0-alpha.1

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 (415) hide show
  1. package/dist/index.d.ts +37 -65
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +59 -61
  4. package/dist/index.js.map +1 -1
  5. package/package.json +9 -38
  6. package/src/index.ts +58 -259
  7. package/AGENTS.md +0 -116
  8. package/dist/_config.d.ts +0 -100
  9. package/dist/_config.d.ts.map +0 -1
  10. package/dist/_config.js +0 -147
  11. package/dist/_config.js.map +0 -1
  12. package/dist/_context.d.ts +0 -80
  13. package/dist/_context.d.ts.map +0 -1
  14. package/dist/_context.js +0 -160
  15. package/dist/_context.js.map +0 -1
  16. package/dist/_events.d.ts +0 -64
  17. package/dist/_events.d.ts.map +0 -1
  18. package/dist/_events.js +0 -92
  19. package/dist/_events.js.map +0 -1
  20. package/dist/_globals.d.ts +0 -58
  21. package/dist/_globals.d.ts.map +0 -1
  22. package/dist/_globals.js +0 -71
  23. package/dist/_globals.js.map +0 -1
  24. package/dist/_idle.d.ts +0 -7
  25. package/dist/_idle.d.ts.map +0 -1
  26. package/dist/_idle.js +0 -10
  27. package/dist/_idle.js.map +0 -1
  28. package/dist/_metadata.d.ts +0 -117
  29. package/dist/_metadata.d.ts.map +0 -1
  30. package/dist/_metadata.js +0 -268
  31. package/dist/_metadata.js.map +0 -1
  32. package/dist/_process-protection.d.ts +0 -27
  33. package/dist/_process-protection.d.ts.map +0 -1
  34. package/dist/_process-protection.js +0 -56
  35. package/dist/_process-protection.js.map +0 -1
  36. package/dist/_server.d.ts +0 -50
  37. package/dist/_server.d.ts.map +0 -1
  38. package/dist/_server.js +0 -89
  39. package/dist/_server.js.map +0 -1
  40. package/dist/_services.d.ts +0 -25
  41. package/dist/_services.d.ts.map +0 -1
  42. package/dist/_services.js +0 -286
  43. package/dist/_services.js.map +0 -1
  44. package/dist/_standalone.d.ts +0 -212
  45. package/dist/_standalone.d.ts.map +0 -1
  46. package/dist/_standalone.js +0 -556
  47. package/dist/_standalone.js.map +0 -1
  48. package/dist/_tokens.d.ts +0 -12
  49. package/dist/_tokens.d.ts.map +0 -1
  50. package/dist/_tokens.js +0 -97
  51. package/dist/_tokens.js.map +0 -1
  52. package/dist/_util.d.ts +0 -16
  53. package/dist/_util.d.ts.map +0 -1
  54. package/dist/_util.js +0 -54
  55. package/dist/_util.js.map +0 -1
  56. package/dist/_validation.d.ts +0 -89
  57. package/dist/_validation.d.ts.map +0 -1
  58. package/dist/_validation.js +0 -29
  59. package/dist/_validation.js.map +0 -1
  60. package/dist/_waituntil.d.ts +0 -32
  61. package/dist/_waituntil.d.ts.map +0 -1
  62. package/dist/_waituntil.js +0 -156
  63. package/dist/_waituntil.js.map +0 -1
  64. package/dist/agent.d.ts +0 -1262
  65. package/dist/agent.d.ts.map +0 -1
  66. package/dist/agent.js +0 -981
  67. package/dist/agent.js.map +0 -1
  68. package/dist/app.d.ts +0 -514
  69. package/dist/app.d.ts.map +0 -1
  70. package/dist/app.js +0 -228
  71. package/dist/app.js.map +0 -1
  72. package/dist/bootstrap.d.ts +0 -44
  73. package/dist/bootstrap.d.ts.map +0 -1
  74. package/dist/bootstrap.js +0 -259
  75. package/dist/bootstrap.js.map +0 -1
  76. package/dist/bun-s3-patch.d.ts +0 -37
  77. package/dist/bun-s3-patch.d.ts.map +0 -1
  78. package/dist/bun-s3-patch.js +0 -142
  79. package/dist/bun-s3-patch.js.map +0 -1
  80. package/dist/cors.d.ts +0 -42
  81. package/dist/cors.d.ts.map +0 -1
  82. package/dist/cors.js +0 -117
  83. package/dist/cors.js.map +0 -1
  84. package/dist/dev-patches/aisdk.d.ts +0 -17
  85. package/dist/dev-patches/aisdk.d.ts.map +0 -1
  86. package/dist/dev-patches/aisdk.js +0 -160
  87. package/dist/dev-patches/aisdk.js.map +0 -1
  88. package/dist/dev-patches/gateway.d.ts +0 -16
  89. package/dist/dev-patches/gateway.d.ts.map +0 -1
  90. package/dist/dev-patches/gateway.js +0 -54
  91. package/dist/dev-patches/gateway.js.map +0 -1
  92. package/dist/dev-patches/index.d.ts +0 -21
  93. package/dist/dev-patches/index.d.ts.map +0 -1
  94. package/dist/dev-patches/index.js +0 -33
  95. package/dist/dev-patches/index.js.map +0 -1
  96. package/dist/dev-patches/otel-llm.d.ts +0 -12
  97. package/dist/dev-patches/otel-llm.d.ts.map +0 -1
  98. package/dist/dev-patches/otel-llm.js +0 -352
  99. package/dist/dev-patches/otel-llm.js.map +0 -1
  100. package/dist/devmode.d.ts +0 -3
  101. package/dist/devmode.d.ts.map +0 -1
  102. package/dist/devmode.js +0 -167
  103. package/dist/devmode.js.map +0 -1
  104. package/dist/eval.d.ts +0 -91
  105. package/dist/eval.d.ts.map +0 -1
  106. package/dist/eval.js +0 -16
  107. package/dist/eval.js.map +0 -1
  108. package/dist/handlers/_route-meta.d.ts +0 -22
  109. package/dist/handlers/_route-meta.d.ts.map +0 -1
  110. package/dist/handlers/_route-meta.js +0 -25
  111. package/dist/handlers/_route-meta.js.map +0 -1
  112. package/dist/handlers/cron.d.ts +0 -73
  113. package/dist/handlers/cron.d.ts.map +0 -1
  114. package/dist/handlers/cron.js +0 -43
  115. package/dist/handlers/cron.js.map +0 -1
  116. package/dist/handlers/index.d.ts +0 -6
  117. package/dist/handlers/index.d.ts.map +0 -1
  118. package/dist/handlers/index.js +0 -6
  119. package/dist/handlers/index.js.map +0 -1
  120. package/dist/handlers/sse.d.ts +0 -163
  121. package/dist/handlers/sse.d.ts.map +0 -1
  122. package/dist/handlers/sse.js +0 -175
  123. package/dist/handlers/sse.js.map +0 -1
  124. package/dist/handlers/stream.d.ts +0 -52
  125. package/dist/handlers/stream.d.ts.map +0 -1
  126. package/dist/handlers/stream.js +0 -108
  127. package/dist/handlers/stream.js.map +0 -1
  128. package/dist/handlers/webrtc.d.ts +0 -49
  129. package/dist/handlers/webrtc.d.ts.map +0 -1
  130. package/dist/handlers/webrtc.js +0 -109
  131. package/dist/handlers/webrtc.js.map +0 -1
  132. package/dist/handlers/websocket.d.ts +0 -88
  133. package/dist/handlers/websocket.d.ts.map +0 -1
  134. package/dist/handlers/websocket.js +0 -161
  135. package/dist/handlers/websocket.js.map +0 -1
  136. package/dist/logger/console.d.ts +0 -70
  137. package/dist/logger/console.d.ts.map +0 -1
  138. package/dist/logger/console.js +0 -278
  139. package/dist/logger/console.js.map +0 -1
  140. package/dist/logger/index.d.ts +0 -3
  141. package/dist/logger/index.d.ts.map +0 -1
  142. package/dist/logger/index.js +0 -3
  143. package/dist/logger/index.js.map +0 -1
  144. package/dist/logger/internal.d.ts +0 -79
  145. package/dist/logger/internal.d.ts.map +0 -1
  146. package/dist/logger/internal.js +0 -133
  147. package/dist/logger/internal.js.map +0 -1
  148. package/dist/logger/logger.d.ts +0 -41
  149. package/dist/logger/logger.d.ts.map +0 -1
  150. package/dist/logger/logger.js +0 -2
  151. package/dist/logger/logger.js.map +0 -1
  152. package/dist/logger/user.d.ts +0 -8
  153. package/dist/logger/user.d.ts.map +0 -1
  154. package/dist/logger/user.js +0 -7
  155. package/dist/logger/user.js.map +0 -1
  156. package/dist/logger/util.d.ts +0 -11
  157. package/dist/logger/util.d.ts.map +0 -1
  158. package/dist/logger/util.js +0 -77
  159. package/dist/logger/util.js.map +0 -1
  160. package/dist/middleware.d.ts +0 -105
  161. package/dist/middleware.d.ts.map +0 -1
  162. package/dist/middleware.js +0 -763
  163. package/dist/middleware.js.map +0 -1
  164. package/dist/otel/config.d.ts +0 -19
  165. package/dist/otel/config.d.ts.map +0 -1
  166. package/dist/otel/config.js +0 -26
  167. package/dist/otel/config.js.map +0 -1
  168. package/dist/otel/console.d.ts +0 -33
  169. package/dist/otel/console.d.ts.map +0 -1
  170. package/dist/otel/console.js +0 -86
  171. package/dist/otel/console.js.map +0 -1
  172. package/dist/otel/exporters/index.d.ts +0 -4
  173. package/dist/otel/exporters/index.d.ts.map +0 -1
  174. package/dist/otel/exporters/index.js +0 -4
  175. package/dist/otel/exporters/index.js.map +0 -1
  176. package/dist/otel/exporters/jsonl-log-exporter.d.ts +0 -36
  177. package/dist/otel/exporters/jsonl-log-exporter.d.ts.map +0 -1
  178. package/dist/otel/exporters/jsonl-log-exporter.js +0 -103
  179. package/dist/otel/exporters/jsonl-log-exporter.js.map +0 -1
  180. package/dist/otel/exporters/jsonl-metric-exporter.d.ts +0 -40
  181. package/dist/otel/exporters/jsonl-metric-exporter.d.ts.map +0 -1
  182. package/dist/otel/exporters/jsonl-metric-exporter.js +0 -104
  183. package/dist/otel/exporters/jsonl-metric-exporter.js.map +0 -1
  184. package/dist/otel/exporters/jsonl-trace-exporter.d.ts +0 -36
  185. package/dist/otel/exporters/jsonl-trace-exporter.d.ts.map +0 -1
  186. package/dist/otel/exporters/jsonl-trace-exporter.js +0 -111
  187. package/dist/otel/exporters/jsonl-trace-exporter.js.map +0 -1
  188. package/dist/otel/fetch.d.ts +0 -12
  189. package/dist/otel/fetch.d.ts.map +0 -1
  190. package/dist/otel/fetch.js +0 -82
  191. package/dist/otel/fetch.js.map +0 -1
  192. package/dist/otel/http.d.ts +0 -16
  193. package/dist/otel/http.d.ts.map +0 -1
  194. package/dist/otel/http.js +0 -44
  195. package/dist/otel/http.js.map +0 -1
  196. package/dist/otel/logger.d.ts +0 -37
  197. package/dist/otel/logger.d.ts.map +0 -1
  198. package/dist/otel/logger.js +0 -265
  199. package/dist/otel/logger.js.map +0 -1
  200. package/dist/otel/otel.d.ts +0 -68
  201. package/dist/otel/otel.d.ts.map +0 -1
  202. package/dist/otel/otel.js +0 -245
  203. package/dist/otel/otel.js.map +0 -1
  204. package/dist/otel/tracestate.d.ts +0 -44
  205. package/dist/otel/tracestate.d.ts.map +0 -1
  206. package/dist/otel/tracestate.js +0 -84
  207. package/dist/otel/tracestate.js.map +0 -1
  208. package/dist/router.d.ts +0 -66
  209. package/dist/router.d.ts.map +0 -1
  210. package/dist/router.js +0 -44
  211. package/dist/router.js.map +0 -1
  212. package/dist/services/evalrun/composite.d.ts +0 -21
  213. package/dist/services/evalrun/composite.d.ts.map +0 -1
  214. package/dist/services/evalrun/composite.js +0 -26
  215. package/dist/services/evalrun/composite.js.map +0 -1
  216. package/dist/services/evalrun/http.d.ts +0 -24
  217. package/dist/services/evalrun/http.d.ts.map +0 -1
  218. package/dist/services/evalrun/http.js +0 -115
  219. package/dist/services/evalrun/http.js.map +0 -1
  220. package/dist/services/evalrun/index.d.ts +0 -5
  221. package/dist/services/evalrun/index.d.ts.map +0 -1
  222. package/dist/services/evalrun/index.js +0 -5
  223. package/dist/services/evalrun/index.js.map +0 -1
  224. package/dist/services/evalrun/json.d.ts +0 -21
  225. package/dist/services/evalrun/json.d.ts.map +0 -1
  226. package/dist/services/evalrun/json.js +0 -38
  227. package/dist/services/evalrun/json.js.map +0 -1
  228. package/dist/services/evalrun/local.d.ts +0 -19
  229. package/dist/services/evalrun/local.d.ts.map +0 -1
  230. package/dist/services/evalrun/local.js +0 -22
  231. package/dist/services/evalrun/local.js.map +0 -1
  232. package/dist/services/local/_db.d.ts +0 -4
  233. package/dist/services/local/_db.d.ts.map +0 -1
  234. package/dist/services/local/_db.js +0 -281
  235. package/dist/services/local/_db.js.map +0 -1
  236. package/dist/services/local/_router.d.ts +0 -3
  237. package/dist/services/local/_router.d.ts.map +0 -1
  238. package/dist/services/local/_router.js +0 -28
  239. package/dist/services/local/_router.js.map +0 -1
  240. package/dist/services/local/_util.d.ts +0 -18
  241. package/dist/services/local/_util.d.ts.map +0 -1
  242. package/dist/services/local/_util.js +0 -44
  243. package/dist/services/local/_util.js.map +0 -1
  244. package/dist/services/local/email.d.ts +0 -24
  245. package/dist/services/local/email.d.ts.map +0 -1
  246. package/dist/services/local/email.js +0 -58
  247. package/dist/services/local/email.js.map +0 -1
  248. package/dist/services/local/index.d.ts +0 -10
  249. package/dist/services/local/index.d.ts.map +0 -1
  250. package/dist/services/local/index.js +0 -10
  251. package/dist/services/local/index.js.map +0 -1
  252. package/dist/services/local/keyvalue.d.ts +0 -17
  253. package/dist/services/local/keyvalue.d.ts.map +0 -1
  254. package/dist/services/local/keyvalue.js +0 -133
  255. package/dist/services/local/keyvalue.js.map +0 -1
  256. package/dist/services/local/queue.d.ts +0 -10
  257. package/dist/services/local/queue.d.ts.map +0 -1
  258. package/dist/services/local/queue.js +0 -96
  259. package/dist/services/local/queue.js.map +0 -1
  260. package/dist/services/local/stream.d.ts +0 -12
  261. package/dist/services/local/stream.d.ts.map +0 -1
  262. package/dist/services/local/stream.js +0 -266
  263. package/dist/services/local/stream.js.map +0 -1
  264. package/dist/services/local/task.d.ts +0 -55
  265. package/dist/services/local/task.d.ts.map +0 -1
  266. package/dist/services/local/task.js +0 -1248
  267. package/dist/services/local/task.js.map +0 -1
  268. package/dist/services/local/vector.d.ts +0 -17
  269. package/dist/services/local/vector.d.ts.map +0 -1
  270. package/dist/services/local/vector.js +0 -303
  271. package/dist/services/local/vector.js.map +0 -1
  272. package/dist/services/sandbox/http.d.ts +0 -23
  273. package/dist/services/sandbox/http.d.ts.map +0 -1
  274. package/dist/services/sandbox/http.js +0 -327
  275. package/dist/services/sandbox/http.js.map +0 -1
  276. package/dist/services/sandbox/index.d.ts +0 -2
  277. package/dist/services/sandbox/index.d.ts.map +0 -1
  278. package/dist/services/sandbox/index.js +0 -2
  279. package/dist/services/sandbox/index.js.map +0 -1
  280. package/dist/services/session/composite.d.ts +0 -21
  281. package/dist/services/session/composite.d.ts.map +0 -1
  282. package/dist/services/session/composite.js +0 -26
  283. package/dist/services/session/composite.js.map +0 -1
  284. package/dist/services/session/http.d.ts +0 -34
  285. package/dist/services/session/http.d.ts.map +0 -1
  286. package/dist/services/session/http.js +0 -124
  287. package/dist/services/session/http.js.map +0 -1
  288. package/dist/services/session/index.d.ts +0 -5
  289. package/dist/services/session/index.d.ts.map +0 -1
  290. package/dist/services/session/index.js +0 -5
  291. package/dist/services/session/index.js.map +0 -1
  292. package/dist/services/session/json.d.ts +0 -22
  293. package/dist/services/session/json.d.ts.map +0 -1
  294. package/dist/services/session/json.js +0 -35
  295. package/dist/services/session/json.js.map +0 -1
  296. package/dist/services/session/local.d.ts +0 -19
  297. package/dist/services/session/local.d.ts.map +0 -1
  298. package/dist/services/session/local.js +0 -23
  299. package/dist/services/session/local.js.map +0 -1
  300. package/dist/services/thread/local.d.ts +0 -20
  301. package/dist/services/thread/local.d.ts.map +0 -1
  302. package/dist/services/thread/local.js +0 -158
  303. package/dist/services/thread/local.js.map +0 -1
  304. package/dist/session.d.ts +0 -734
  305. package/dist/session.d.ts.map +0 -1
  306. package/dist/session.js +0 -1140
  307. package/dist/session.js.map +0 -1
  308. package/dist/signature.d.ts +0 -22
  309. package/dist/signature.d.ts.map +0 -1
  310. package/dist/signature.js +0 -63
  311. package/dist/signature.js.map +0 -1
  312. package/dist/validator.d.ts +0 -142
  313. package/dist/validator.d.ts.map +0 -1
  314. package/dist/validator.js +0 -149
  315. package/dist/validator.js.map +0 -1
  316. package/dist/version-check.d.ts +0 -20
  317. package/dist/version-check.d.ts.map +0 -1
  318. package/dist/version-check.js +0 -157
  319. package/dist/version-check.js.map +0 -1
  320. package/dist/web.d.ts +0 -8
  321. package/dist/web.d.ts.map +0 -1
  322. package/dist/web.js +0 -67
  323. package/dist/web.js.map +0 -1
  324. package/dist/webrtc-signaling.d.ts +0 -80
  325. package/dist/webrtc-signaling.d.ts.map +0 -1
  326. package/dist/webrtc-signaling.js +0 -237
  327. package/dist/webrtc-signaling.js.map +0 -1
  328. package/dist/workbench.d.ts +0 -17
  329. package/dist/workbench.d.ts.map +0 -1
  330. package/dist/workbench.js +0 -605
  331. package/dist/workbench.js.map +0 -1
  332. package/src/_config.ts +0 -163
  333. package/src/_context.ts +0 -240
  334. package/src/_events.ts +0 -142
  335. package/src/_globals.ts +0 -92
  336. package/src/_idle.ts +0 -10
  337. package/src/_metadata.ts +0 -407
  338. package/src/_process-protection.ts +0 -71
  339. package/src/_server.ts +0 -109
  340. package/src/_services.ts +0 -379
  341. package/src/_standalone.ts +0 -710
  342. package/src/_tokens.ts +0 -114
  343. package/src/_util.ts +0 -62
  344. package/src/_validation.ts +0 -119
  345. package/src/_waituntil.ts +0 -188
  346. package/src/agent.ts +0 -2739
  347. package/src/app.ts +0 -769
  348. package/src/bootstrap.ts +0 -321
  349. package/src/bun-s3-patch.ts +0 -224
  350. package/src/cors.ts +0 -137
  351. package/src/dev-patches/aisdk.ts +0 -169
  352. package/src/dev-patches/gateway.ts +0 -68
  353. package/src/dev-patches/index.ts +0 -37
  354. package/src/dev-patches/otel-llm.ts +0 -405
  355. package/src/devmode.ts +0 -171
  356. package/src/eval.ts +0 -109
  357. package/src/globals.d.ts +0 -28
  358. package/src/handlers/_route-meta.ts +0 -33
  359. package/src/handlers/cron.ts +0 -141
  360. package/src/handlers/index.ts +0 -18
  361. package/src/handlers/sse.ts +0 -358
  362. package/src/handlers/stream.ts +0 -121
  363. package/src/handlers/webrtc.ts +0 -125
  364. package/src/handlers/websocket.ts +0 -203
  365. package/src/logger/console.ts +0 -323
  366. package/src/logger/index.ts +0 -2
  367. package/src/logger/internal.ts +0 -165
  368. package/src/logger/logger.ts +0 -44
  369. package/src/logger/user.ts +0 -15
  370. package/src/logger/util.ts +0 -80
  371. package/src/middleware.ts +0 -1095
  372. package/src/otel/config.ts +0 -47
  373. package/src/otel/console.ts +0 -91
  374. package/src/otel/exporters/README.md +0 -217
  375. package/src/otel/exporters/index.ts +0 -3
  376. package/src/otel/exporters/jsonl-log-exporter.ts +0 -113
  377. package/src/otel/exporters/jsonl-metric-exporter.ts +0 -120
  378. package/src/otel/exporters/jsonl-trace-exporter.ts +0 -121
  379. package/src/otel/fetch.ts +0 -105
  380. package/src/otel/http.ts +0 -53
  381. package/src/otel/logger.ts +0 -293
  382. package/src/otel/otel.ts +0 -354
  383. package/src/otel/tracestate.ts +0 -108
  384. package/src/router.ts +0 -75
  385. package/src/services/evalrun/composite.ts +0 -34
  386. package/src/services/evalrun/http.ts +0 -167
  387. package/src/services/evalrun/index.ts +0 -4
  388. package/src/services/evalrun/json.ts +0 -46
  389. package/src/services/evalrun/local.ts +0 -28
  390. package/src/services/local/README.md +0 -1576
  391. package/src/services/local/_db.ts +0 -353
  392. package/src/services/local/_router.ts +0 -40
  393. package/src/services/local/_util.ts +0 -55
  394. package/src/services/local/email.ts +0 -91
  395. package/src/services/local/index.ts +0 -9
  396. package/src/services/local/keyvalue.ts +0 -174
  397. package/src/services/local/queue.ts +0 -145
  398. package/src/services/local/stream.ts +0 -358
  399. package/src/services/local/task.ts +0 -1711
  400. package/src/services/local/vector.ts +0 -438
  401. package/src/services/sandbox/http.ts +0 -522
  402. package/src/services/sandbox/index.ts +0 -1
  403. package/src/services/session/composite.ts +0 -33
  404. package/src/services/session/http.ts +0 -167
  405. package/src/services/session/index.ts +0 -4
  406. package/src/services/session/json.ts +0 -42
  407. package/src/services/session/local.ts +0 -33
  408. package/src/services/thread/local.ts +0 -199
  409. package/src/session.ts +0 -1960
  410. package/src/signature.ts +0 -82
  411. package/src/validator.ts +0 -283
  412. package/src/version-check.ts +0 -184
  413. package/src/web.ts +0 -76
  414. package/src/webrtc-signaling.ts +0 -288
  415. package/src/workbench.ts +0 -725
package/dist/agent.d.ts DELETED
@@ -1,1262 +0,0 @@
1
- import { type KeyValueStorage, type StandardSchemaV1, type StreamStorage, type VectorStorage, type SandboxService, type QueueService, type EmailService, type ScheduleService, type TaskStorage, type InferInput, type InferOutput } from '@agentuity/core';
2
- import { type Tracer } from '@opentelemetry/api';
3
- import type { Context, MiddlewareHandler } from 'hono';
4
- import type { Handler } from 'hono/types';
5
- import { AGENT_RUNTIME } from './_config';
6
- import type { Logger } from './logger';
7
- import type { Eval, EvalFunction } from './eval';
8
- import type { Thread, Session } from './session';
9
- import type { AppState } from './index';
10
- export type AgentEventName = 'started' | 'completed' | 'errored';
11
- export type AgentEventCallback<TAgent extends Agent<any, any, any>> = ((eventName: 'started', agent: TAgent, context: AgentContext<any, any, any>) => Promise<void> | void) | ((eventName: 'completed', agent: TAgent, context: AgentContext<any, any, any>) => Promise<void> | void) | ((eventName: 'errored', agent: TAgent, context: AgentContext<any, any, any>, data: Error) => Promise<void> | void);
12
- /**
13
- * Runtime state container for agents and event listeners.
14
- * Isolates global state into context for better testing.
15
- */
16
- export interface AgentRuntimeState {
17
- agents: Map<string, Agent<any, any, any, any, any>>;
18
- agentConfigs: Map<string, unknown>;
19
- agentEventListeners: WeakMap<Agent<any, any, any, any, any>, Map<AgentEventName, Set<AgentEventCallback<any>>>>;
20
- }
21
- /**
22
- * Context object passed to every agent handler providing access to runtime services and state.
23
- *
24
- * @template TAgentRegistry - Registry of all available agents (auto-generated, strongly-typed)
25
- * @template TConfig - Agent-specific configuration type from setup function
26
- * @template TAppState - Application-wide state type from createApp
27
- *
28
- * @example
29
- * ```typescript
30
- * const agent = createAgent('my-agent', {
31
- * handler: async (ctx, input) => {
32
- * // Logging
33
- * ctx.logger.info('Processing request', { input });
34
- *
35
- * // Call another agent (import it directly)
36
- * import otherAgent from './other-agent';
37
- * const result = await otherAgent.run({ data: input });
38
- *
39
- * // Store data
40
- * await ctx.kv.set('key', { value: result });
41
- *
42
- * // Access config from setup
43
- * const cache = ctx.config.cache;
44
- *
45
- * // Background task
46
- * ctx.waitUntil(async () => {
47
- * await ctx.logger.info('Cleanup complete');
48
- * });
49
- *
50
- * return result;
51
- * }
52
- * });
53
- * ```
54
- */
55
- export interface AgentContext<_TAgentRegistry extends AgentRegistry = AgentRegistry, TConfig = unknown, TAppState = Record<string, never>> {
56
- /**
57
- * Internal runtime state (agents, configs, event listeners).
58
- * Stored with Symbol key to prevent accidental access.
59
- * Use getAgentRuntime(ctx) to access.
60
- * @internal
61
- */
62
- [AGENT_RUNTIME]: AgentRuntimeState;
63
- /**
64
- * Schedule a background task that continues after the response is sent.
65
- * Useful for cleanup, logging, or async operations that don't block the response.
66
- *
67
- * @param promise - Promise or function that returns void or Promise<void>
68
- *
69
- * @example
70
- * ```typescript
71
- * ctx.waitUntil(async () => {
72
- * await ctx.kv.set('processed', Date.now());
73
- * ctx.logger.info('Background task complete');
74
- * });
75
- * ```
76
- */
77
- waitUntil: (promise: Promise<void> | (() => void | Promise<void>)) => void;
78
- /**
79
- * Structured logger with OpenTelemetry integration.
80
- * Logs are automatically correlated with traces.
81
- *
82
- * @example
83
- * ```typescript
84
- * ctx.logger.info('Processing started', { userId: input.id });
85
- * ctx.logger.warn('Rate limit approaching', { remaining: 10 });
86
- * ctx.logger.error('Operation failed', { error: err.message });
87
- * ```
88
- */
89
- logger: Logger;
90
- /**
91
- * Unique session identifier for this request. Consistent across agent calls in the same session.
92
- */
93
- sessionId: string;
94
- /**
95
- * OpenTelemetry tracer for creating custom spans and tracking performance.
96
- *
97
- * @example
98
- * ```typescript
99
- * const span = ctx.tracer.startSpan('database-query');
100
- * try {
101
- * const result = await database.query();
102
- * span.setStatus({ code: SpanStatusCode.OK });
103
- * return result;
104
- * } finally {
105
- * span.end();
106
- * }
107
- * ```
108
- */
109
- tracer: Tracer;
110
- /**
111
- * Key-value storage for simple data persistence.
112
- *
113
- * @example
114
- * ```typescript
115
- * await ctx.kv.set('user:123', { name: 'Alice', age: 30 });
116
- * const user = await ctx.kv.get('user:123');
117
- * await ctx.kv.delete('user:123');
118
- * const keys = await ctx.kv.list('user:*');
119
- * ```
120
- */
121
- kv: KeyValueStorage;
122
- /**
123
- * Stream storage for real-time data streams and logs.
124
- *
125
- * @example
126
- * ```typescript
127
- * const stream = await ctx.stream.create('agent-logs');
128
- * await ctx.stream.write(stream.id, 'Processing step 1');
129
- * await ctx.stream.write(stream.id, 'Processing step 2');
130
- * ```
131
- */
132
- stream: StreamStorage;
133
- /**
134
- * Vector storage for embeddings and similarity search.
135
- *
136
- * @example
137
- * ```typescript
138
- * await ctx.vector.upsert('docs', [
139
- * { id: '1', values: [0.1, 0.2, 0.3], metadata: { text: 'Hello' } }
140
- * ]);
141
- * const results = await ctx.vector.query('docs', [0.1, 0.2, 0.3], { topK: 5 });
142
- * ```
143
- */
144
- vector: VectorStorage;
145
- /**
146
- * Sandbox service for creating and running isolated code execution environments.
147
- *
148
- * @example
149
- * ```typescript
150
- * // One-shot execution
151
- * const result = await ctx.sandbox.run({
152
- * command: {
153
- * exec: ['bun', 'run', 'index.ts'],
154
- * files: [{ path: 'index.ts', content: Buffer.from('console.log("hello")') }]
155
- * }
156
- * });
157
- * console.log('Exit:', result.exitCode);
158
- *
159
- * // Interactive sandbox
160
- * const sandbox = await ctx.sandbox.create({
161
- * resources: { memory: '1Gi', cpu: '1000m' }
162
- * });
163
- * await sandbox.execute({ command: ['bun', 'init'] });
164
- * await sandbox.execute({ command: ['bun', 'add', 'zod'] });
165
- * await sandbox.destroy();
166
- * ```
167
- */
168
- sandbox: SandboxService;
169
- /**
170
- * Queue service for publishing messages to queues.
171
- *
172
- * @example
173
- * ```typescript
174
- * const result = await ctx.queue.publish('my-queue', { event: 'user.created', userId: '123' });
175
- * console.log('Message ID:', result.id);
176
- * ```
177
- */
178
- queue: QueueService;
179
- /**
180
- * Email service for managing email addresses, destinations, and sending/receiving emails.
181
- *
182
- * @example
183
- * ```typescript
184
- * // Create an email address
185
- * const address = await ctx.email.createAddress('support');
186
- *
187
- * // Send an email
188
- * const result = await ctx.email.send({
189
- * from: address.email,
190
- * to: ['user@example.com'],
191
- * subject: 'Hello!',
192
- * text: 'Welcome to our platform.',
193
- * });
194
- *
195
- * // List inbound emails
196
- * const inbound = await ctx.email.listInbound(address.id);
197
- * ```
198
- */
199
- email: EmailService;
200
- /**
201
- * Schedule service for managing cron-based scheduled tasks with
202
- * destinations and delivery tracking.
203
- *
204
- * @see https://agentuity.dev/services/schedule
205
- */
206
- schedule: ScheduleService;
207
- /**
208
- * Task service for agent-driven issue tracking.
209
- *
210
- * @example
211
- * ```typescript
212
- * const task = await ctx.task.create({
213
- * title: 'Investigate API error',
214
- * type: 'bug',
215
- * created_id: ctx.current.id,
216
- * });
217
- * await ctx.task.update(task.id, { status: 'in_progress' });
218
- * ```
219
- */
220
- task: TaskStorage;
221
- /**
222
- * In-memory state storage scoped to the current request.
223
- * Use for passing data between middleware and handlers.
224
- *
225
- * @example
226
- * ```typescript
227
- * ctx.state.set('startTime', Date.now());
228
- * const duration = Date.now() - (ctx.state.get('startTime') as number);
229
- * ```
230
- */
231
- state: Map<string, unknown>;
232
- /**
233
- * Thread information for multi-turn conversations.
234
- */
235
- thread: Thread;
236
- /**
237
- * Session information for the current request.
238
- */
239
- session: Session;
240
- /**
241
- * Agent-specific configuration returned from the setup function.
242
- * Type is inferred from your setup function's return value.
243
- *
244
- * @example
245
- * ```typescript
246
- * createAgent({
247
- * setup: async () => ({ cache: new Map(), db: await connectDB() }),
248
- * handler: async (ctx, input) => {
249
- * ctx.config.cache.set('key', 'value'); // Strongly typed!
250
- * await ctx.config.db.query('SELECT * FROM users');
251
- * }
252
- * });
253
- * ```
254
- */
255
- config: TConfig;
256
- /**
257
- * Application-wide state returned from createApp setup function.
258
- * Shared across all agents in the application.
259
- *
260
- * @example
261
- * ```typescript
262
- * const app = createApp({
263
- * setup: async () => ({ db: await connectDB(), redis: await connectRedis() })
264
- * });
265
- *
266
- * // Later in any agent:
267
- * handler: async (ctx, input) => {
268
- * await ctx.app.db.query('SELECT 1');
269
- * await ctx.app.redis.set('key', 'value');
270
- * }
271
- * ```
272
- */
273
- app: TAppState;
274
- /**
275
- * Metadata about the currently executing agent.
276
- * Provides access to the agent's id, name, and other properties.
277
- *
278
- * @example
279
- * ```typescript
280
- * handler: async (ctx, input) => {
281
- * // Use agent ID for namespaced state keys
282
- * const stateKey = `${ctx.current.id}_counter`;
283
- * await ctx.thread.state.set(stateKey, value);
284
- *
285
- * // Log agent info
286
- * ctx.logger.info('Running agent', { name: ctx.current.name });
287
- * }
288
- * ```
289
- */
290
- current: AgentMetadata;
291
- /**
292
- * Authentication context when request is authenticated.
293
- * Available when auth middleware is configured on the Hono app.
294
- *
295
- * Will be `null` for:
296
- * - Unauthenticated requests
297
- * - Cron jobs
298
- * - Agent-to-agent calls without auth propagation
299
- *
300
- * @example
301
- * ```typescript
302
- * handler: async (ctx, input) => {
303
- * if (!ctx.auth) {
304
- * return { error: 'Please sign in' };
305
- * }
306
- *
307
- * // Access user info
308
- * const user = await ctx.auth.getUser();
309
- * ctx.logger.info(`Request from ${user.email}`);
310
- *
311
- * // Check organization role
312
- * if (await ctx.auth.hasOrgRole('admin')) {
313
- * // Admin-only logic
314
- * }
315
- *
316
- * return { userId: user.id };
317
- * }
318
- * ```
319
- */
320
- auth: import('@agentuity/core').AuthInterface | null;
321
- }
322
- type InternalAgentMetadata = {
323
- /**
324
- * the unique name for the agent (user-provided).
325
- */
326
- name: string;
327
- /**
328
- * the unique identifier for this project, agent and deployment.
329
- */
330
- id: string;
331
- /**
332
- * the unique identifier for this agent across multiple deployments
333
- */
334
- agentId: string;
335
- /**
336
- * the relative path to the agent from the root project directory.
337
- */
338
- filename: string;
339
- /**
340
- * a unique version for the agent. computed as the SHA256 contents of the file.
341
- */
342
- version: string;
343
- /**
344
- * the source code for the input schema.
345
- */
346
- inputSchemaCode?: string;
347
- /**
348
- * the source code for the output schema.
349
- */
350
- outputSchemaCode?: string;
351
- };
352
- type ExternalAgentMetadata = {
353
- /**
354
- * the human readable description for the agent
355
- */
356
- description?: string;
357
- };
358
- export type AgentMetadata = InternalAgentMetadata & ExternalAgentMetadata;
359
- /**
360
- * Configuration object for creating an agent evaluation function.
361
- *
362
- * @template TInput - Input schema type from the agent
363
- * @template TOutput - Output schema type from the agent
364
- */
365
- export interface CreateEvalConfig<TInput extends StandardSchemaV1 | undefined = any, TOutput extends StandardSchemaV1 | undefined = any> {
366
- /**
367
- * Optional description of what this evaluation does.
368
- *
369
- * @example
370
- * ```typescript
371
- * description: 'Ensures output is greater than zero'
372
- * ```
373
- */
374
- description?: string;
375
- /**
376
- * Evaluation handler function that tests the agent's behavior.
377
- * Return true if the evaluation passes, false if it fails.
378
- *
379
- * @param run - Evaluation run context containing input and metadata
380
- * @param result - The output from the agent handler
381
- * @returns Boolean indicating pass/fail, or evaluation result object
382
- *
383
- * @example
384
- * ```typescript
385
- * handler: async (run, result) => {
386
- * // Assert that output is positive
387
- * if (result <= 0) {
388
- * return false; // Evaluation failed
389
- * }
390
- * return true; // Evaluation passed
391
- * }
392
- * ```
393
- *
394
- * @example
395
- * ```typescript
396
- * // With detailed result
397
- * handler: async (run, result) => {
398
- * const passed = result.length > 5;
399
- * return {
400
- * passed,
401
- * score: passed ? 1.0 : 0.0,
402
- * message: passed ? 'Output length is valid' : 'Output too short'
403
- * };
404
- * }
405
- * ```
406
- */
407
- handler: EvalFunction<TInput extends StandardSchemaV1 ? InferOutput<TInput> : undefined, TOutput extends StandardSchemaV1 ? InferOutput<TOutput> : undefined>;
408
- }
409
- export type PresetEvalConfig<TInput extends StandardSchemaV1 | undefined = any, TOutput extends StandardSchemaV1 | undefined = any> = CreateEvalConfig<TInput, TOutput> & {
410
- name: string;
411
- };
412
- type CreateEvalMethod<TInput extends StandardSchemaV1 | undefined = any, TOutput extends StandardSchemaV1 | undefined = any> = {
413
- (config: PresetEvalConfig<TInput, TOutput>): Eval<TInput, TOutput>;
414
- (name: string, config: CreateEvalConfig<TInput, TOutput>): Eval<TInput, TOutput>;
415
- };
416
- /**
417
- * Validator function type with method overloads for different validation scenarios.
418
- * Provides type-safe validation middleware that integrates with Hono's type system.
419
- *
420
- * This validator automatically validates incoming JSON request bodies using StandardSchema-compatible
421
- * schemas (Zod, Valibot, ArkType, etc.) and provides full TypeScript type inference for validated data
422
- * accessible via `c.req.valid('json')`.
423
- *
424
- * The validator returns 400 Bad Request with validation error details if validation fails.
425
- *
426
- * @template TInput - Agent's input schema type (StandardSchemaV1 or undefined)
427
- * @template _TOutput - Agent's output schema type (reserved for future output validation)
428
- *
429
- * @example Basic usage with agent's schema
430
- * ```typescript
431
- * router.post('/', agent.validator(), async (c) => {
432
- * const data = c.req.valid('json'); // Fully typed from agent's input schema
433
- * return c.json(data);
434
- * });
435
- * ```
436
- *
437
- * @example Override with custom input schema
438
- * ```typescript
439
- * router.post('/custom', agent.validator({ input: z.object({ id: z.string() }) }), async (c) => {
440
- * const data = c.req.valid('json'); // Typed as { id: string }
441
- * return c.json(data);
442
- * });
443
- * ```
444
- */
445
- export interface AgentValidator<TInput extends StandardSchemaV1 | undefined, _TOutput extends StandardSchemaV1 | undefined> {
446
- /**
447
- * Validates using the agent's input schema (no override).
448
- * Returns Hono middleware handler that validates JSON request body.
449
- *
450
- * @returns Middleware handler with type inference for validated data
451
- *
452
- * @example
453
- * ```typescript
454
- * // Agent has schema: { input: z.object({ name: z.string() }) }
455
- * router.post('/', agent.validator(), async (c) => {
456
- * const data = c.req.valid('json'); // { name: string }
457
- * return c.json({ received: data.name });
458
- * });
459
- * ```
460
- */
461
- (): TInput extends StandardSchemaV1 ? Handler<any, any, {
462
- in: {};
463
- out: {
464
- json: InferInput<TInput>;
465
- };
466
- }> : Handler<any, any, any>;
467
- /**
468
- * Output-only validation override.
469
- * Validates only the response body (no input validation).
470
- *
471
- * Useful for GET routes or routes where input validation is handled elsewhere.
472
- * The middleware validates the JSON response body and throws 500 Internal Server Error
473
- * if validation fails.
474
- *
475
- * @template TOverrideOutput - Custom output schema type
476
- * @param override - Object containing output schema
477
- * @returns Middleware handler that validates response output
478
- *
479
- * @example GET route with output validation
480
- * ```typescript
481
- * router.get('/', agent.validator({ output: z.array(z.object({ id: z.string() })) }), async (c) => {
482
- * // Returns array of objects - validated against schema
483
- * return c.json([{ id: '123' }, { id: '456' }]);
484
- * });
485
- * ```
486
- */
487
- <TOverrideOutput extends StandardSchemaV1>(override: {
488
- output: TOverrideOutput;
489
- }): Handler<any, any, {
490
- in: {};
491
- out: {
492
- json: InferOutput<TOverrideOutput>;
493
- };
494
- }>;
495
- /**
496
- * Validates with custom input and optional output schemas (POST/PUT/PATCH/DELETE).
497
- * Overrides the agent's schema for this specific route.
498
- *
499
- * @template TOverrideInput - Custom input schema type
500
- * @template TOverrideOutput - Optional custom output schema type
501
- * @param override - Object containing input (required) and output (optional) schemas
502
- * @returns Middleware handler with type inference from custom schemas
503
- *
504
- * @example Custom input schema
505
- * ```typescript
506
- * router.post('/users', agent.validator({
507
- * input: z.object({ email: z.string().email(), name: z.string() })
508
- * }), async (c) => {
509
- * const data = c.req.valid('json'); // { email: string, name: string }
510
- * return c.json({ id: '123', ...data });
511
- * });
512
- * ```
513
- *
514
- * @example Custom input and output schemas
515
- * ```typescript
516
- * router.post('/convert', agent.validator({
517
- * input: z.string(),
518
- * output: z.number()
519
- * }), async (c) => {
520
- * const data = c.req.valid('json'); // string
521
- * return c.json(123);
522
- * });
523
- * ```
524
- */
525
- <TOverrideInput extends StandardSchemaV1, TOverrideOutput extends StandardSchemaV1 | undefined = undefined>(override: {
526
- input: TOverrideInput;
527
- output?: TOverrideOutput;
528
- }): Handler<any, any, {
529
- in: {};
530
- out: {
531
- json: InferInput<TOverrideInput>;
532
- };
533
- }>;
534
- }
535
- /**
536
- * Agent instance type returned by createAgent().
537
- * Represents a fully configured agent with metadata, handler, lifecycle hooks, and event listeners.
538
- *
539
- * @template TInput - Input schema type (StandardSchemaV1 or undefined)
540
- * @template TOutput - Output schema type (StandardSchemaV1 or undefined)
541
- * @template TStream - Whether the agent returns a stream (true/false)
542
- * @template TConfig - Agent-specific configuration type from setup function
543
- * @template TAppState - Application state type from createApp
544
- *
545
- * @example
546
- * ```typescript
547
- * const agent = createAgent({
548
- * metadata: { name: 'My Agent' },
549
- * schema: { input: z.string(), output: z.number() },
550
- * handler: async (ctx, input) => input.length
551
- * });
552
- *
553
- * // Access agent properties
554
- * console.log(agent.metadata.name); // "My Agent"
555
- *
556
- * // Add event listeners
557
- * agent.addEventListener('started', (eventName, agent, ctx) => {
558
- * console.log('Agent started:', ctx.sessionId);
559
- * });
560
- *
561
- * // Create evals for testing
562
- * const eval1 = agent.createEval('check-positive', {
563
- * description: 'Ensures result is greater than 5',
564
- * handler: async (run, result) => {
565
- * return result > 5; // Assert output is greater than 5
566
- * }
567
- * });
568
- * ```
569
- */
570
- export type Agent<TInput extends StandardSchemaV1 | undefined = any, TOutput extends StandardSchemaV1 | undefined = any, TStream extends boolean = false, TConfig = unknown, TAppState = Record<string, never>> = {
571
- /**
572
- * Agent metadata including name, description, id, version, and filename.
573
- */
574
- metadata: AgentMetadata;
575
- /**
576
- * The main handler function that processes agent requests.
577
- * Gets AgentContext from AsyncLocalStorage, receives validated input, returns output or stream.
578
- */
579
- handler: (...args: any[]) => any | Promise<any>;
580
- /**
581
- * Creates a type-safe validation middleware for routes using StandardSchema validation.
582
- *
583
- * This method validates incoming JSON request bodies against the agent's **input schema**
584
- * and optionally validates outgoing JSON responses against the **output schema**.
585
- * Provides full TypeScript type inference for validated input data accessible via `c.req.valid('json')`.
586
- *
587
- * **Validation behavior:**
588
- * - **Input**: Validates request JSON body, returns 400 Bad Request on failure
589
- * - **Output**: Validates response JSON body (if output schema provided), throws 500 on failure
590
- * - Passes validated input data to handler via `c.req.valid('json')`
591
- * - Full TypeScript type inference for validated input data
592
- *
593
- * **Supported schema libraries:**
594
- * - Zod (z.object, z.string, etc.)
595
- * - Valibot (v.object, v.string, etc.)
596
- * - ArkType (type({ ... }))
597
- * - Any StandardSchema-compatible library
598
- *
599
- * **Method overloads:**
600
- * - `agent.validator()` - Validates using agent's input/output schemas
601
- * - `agent.validator({ output: schema })` - Output-only validation (no input validation)
602
- * - `agent.validator({ input: schema })` - Custom input schema override (skips agent's output validation)
603
- * - `agent.validator({ input: schema, output: schema })` - Both input and output validated
604
- *
605
- * @returns Hono middleware handler with proper type inference
606
- *
607
- * @example Automatic validation using agent's schema
608
- * ```typescript
609
- * // Agent defined with: schema: { input: z.object({ name: z.string(), age: z.number() }) }
610
- * router.post('/', agent.validator(), async (c) => {
611
- * const data = c.req.valid('json'); // Fully typed: { name: string, age: number }
612
- * return c.json({ greeting: `Hello ${data.name}, age ${data.age}` });
613
- * });
614
- * ```
615
- *
616
- * @example Override with custom schema per-route
617
- * ```typescript
618
- * router.post('/email', agent.validator({
619
- * input: z.object({ email: z.string().email() })
620
- * }), async (c) => {
621
- * const data = c.req.valid('json'); // Typed as { email: string }
622
- * return c.json({ sent: data.email });
623
- * });
624
- * ```
625
- *
626
- * @example Works with any StandardSchema library
627
- * ```typescript
628
- * import * as v from 'valibot';
629
- *
630
- * router.post('/valibot', agent.validator({
631
- * input: v.object({ count: v.number() })
632
- * }), async (c) => {
633
- * const data = c.req.valid('json'); // Typed correctly
634
- * return c.json({ count: data.count });
635
- * });
636
- * ```
637
- *
638
- * @example Validation error response (400)
639
- * ```typescript
640
- * // Request: { "name": "Bob" } (missing 'age')
641
- * // Response: {
642
- * // "error": "Validation failed",
643
- * // "message": "age: Invalid input: expected number, received undefined",
644
- * // "issues": [{ "message": "...", "path": ["age"] }]
645
- * // }
646
- * ```
647
- */
648
- validator: AgentValidator<TInput, TOutput>;
649
- /**
650
- * Array of evaluation functions created via agent.createEval().
651
- * Used for testing and validating agent behavior.
652
- */
653
- evals?: Eval[];
654
- /**
655
- * Create an evaluation function for testing this agent.
656
- * Evals can assert correctness of agent input/output during test runs.
657
- *
658
- * @param config - Eval configuration
659
- * @param config.metadata - Optional eval metadata (name, description)
660
- * @param config.handler - Eval handler function receiving run context and result
661
- *
662
- * @example
663
- * ```typescript
664
- * const agent = createAgent({
665
- * schema: { input: z.string(), output: z.number() },
666
- * handler: async (ctx, input) => input.length
667
- * });
668
- *
669
- * // Create eval to validate output
670
- * agent.createEval('check-positive', {
671
- * description: 'Ensures output is a positive number',
672
- * handler: async (run, result) => {
673
- * return result > 0; // Assert output is positive
674
- * }
675
- * });
676
- * ```
677
- */
678
- createEval: CreateEvalMethod<TInput, TOutput>;
679
- /**
680
- * Optional setup function called once when app starts.
681
- * Returns agent-specific configuration available via ctx.config.
682
- */
683
- setup?: (app: TAppState) => Promise<TConfig> | TConfig;
684
- /**
685
- * Optional shutdown function called when app stops.
686
- * Receives app state and agent config for cleanup.
687
- */
688
- shutdown?: (app: TAppState, config: TConfig) => Promise<void> | void;
689
- /**
690
- * Register an event listener for when the agent starts execution.
691
- *
692
- * @param eventName - Must be 'started'
693
- * @param callback - Function called when agent execution begins
694
- *
695
- * @example
696
- * ```typescript
697
- * agent.addEventListener('started', (eventName, agent, ctx) => {
698
- * console.log(`${agent.metadata.name} started at ${new Date()}`);
699
- * });
700
- * ```
701
- */
702
- addEventListener(eventName: 'started', callback: (eventName: 'started', agent: Agent<TInput, TOutput, TStream, TConfig, TAppState>, context: AgentContext<any, TConfig, TAppState>) => Promise<void> | void): void;
703
- /**
704
- * Register an event listener for when the agent completes successfully.
705
- *
706
- * @param eventName - Must be 'completed'
707
- * @param callback - Function called when agent execution completes
708
- *
709
- * @example
710
- * ```typescript
711
- * agent.addEventListener('completed', (eventName, agent, ctx) => {
712
- * console.log(`${agent.metadata.name} completed successfully`);
713
- * });
714
- * ```
715
- */
716
- addEventListener(eventName: 'completed', callback: (eventName: 'completed', agent: Agent<TInput, TOutput, TStream, TConfig, TAppState>, context: AgentContext<any, TConfig, TAppState>) => Promise<void> | void): void;
717
- /**
718
- * Register an event listener for when the agent throws an error.
719
- *
720
- * @param eventName - Must be 'errored'
721
- * @param callback - Function called when agent execution fails
722
- *
723
- * @example
724
- * ```typescript
725
- * agent.addEventListener('errored', (eventName, agent, ctx, error) => {
726
- * console.error(`${agent.metadata.name} failed:`, error.message);
727
- * });
728
- * ```
729
- */
730
- addEventListener(eventName: 'errored', callback: (eventName: 'errored', agent: Agent<TInput, TOutput, TStream, TConfig, TAppState>, context: AgentContext<any, TConfig, TAppState>, data: Error) => Promise<void> | void): void;
731
- /**
732
- * Remove a previously registered 'started' event listener.
733
- *
734
- * @param eventName - Must be 'started'
735
- * @param callback - The callback function to remove
736
- */
737
- removeEventListener(eventName: 'started', callback: (eventName: 'started', agent: Agent<TInput, TOutput, TStream, TConfig, TAppState>, context: AgentContext<any, TConfig, TAppState>) => Promise<void> | void): void;
738
- /**
739
- * Remove a previously registered 'completed' event listener.
740
- *
741
- * @param eventName - Must be 'completed'
742
- * @param callback - The callback function to remove
743
- */
744
- removeEventListener(eventName: 'completed', callback: (eventName: 'completed', agent: Agent<TInput, TOutput, TStream, TConfig, TAppState>, context: AgentContext<any, TConfig, TAppState>) => Promise<void> | void): void;
745
- /**
746
- * Remove a previously registered 'errored' event listener.
747
- *
748
- * @param eventName - Must be 'errored'
749
- * @param callback - The callback function to remove
750
- */
751
- removeEventListener(eventName: 'errored', callback: (eventName: 'errored', agent: Agent<TInput, TOutput, TStream, TConfig, TAppState>, context: AgentContext<any, TConfig, TAppState>, data: Error) => Promise<void> | void): void;
752
- } & (TInput extends StandardSchemaV1 ? {
753
- inputSchema: TInput;
754
- } : {
755
- inputSchema?: never;
756
- }) & (TOutput extends StandardSchemaV1 ? {
757
- outputSchema: TOutput;
758
- } : {
759
- outputSchema?: never;
760
- }) & (TStream extends true ? {
761
- stream: true;
762
- } : {
763
- stream?: false;
764
- });
765
- type InferSchemaInput<T> = T extends StandardSchemaV1 ? InferOutput<T> : never;
766
- type InferStreamOutput<TOutput, TStream extends boolean> = TStream extends true ? TOutput extends StandardSchemaV1 ? ReadableStream<InferOutput<TOutput>> : ReadableStream<unknown> : TOutput extends StandardSchemaV1 ? InferOutput<TOutput> : void;
767
- type SchemaInput<TSchema> = TSchema extends {
768
- input: infer I;
769
- } ? I : undefined;
770
- type SchemaOutput<TSchema> = TSchema extends {
771
- output: infer O;
772
- } ? O : undefined;
773
- type SchemaStream<TSchema> = TSchema extends {
774
- stream: infer S;
775
- } ? S extends boolean ? S : false : false;
776
- type SchemaHandlerReturn<TSchema> = SchemaStream<TSchema> extends true ? SchemaOutput<TSchema> extends StandardSchemaV1 ? ReadableStream<InferOutput<SchemaOutput<TSchema>>> : ReadableStream<unknown> : SchemaOutput<TSchema> extends StandardSchemaV1 ? InferOutput<SchemaOutput<TSchema>> : void;
777
- type AgentHandlerFromConfig<TSchema, TSetupReturn, TAppState = AppState> = SchemaInput<TSchema> extends infer I ? I extends StandardSchemaV1 ? (ctx: AgentContext<any, TSetupReturn, TAppState>, input: InferOutput<I>) => Promise<SchemaHandlerReturn<TSchema>> | SchemaHandlerReturn<TSchema> : (ctx: AgentContext<any, TSetupReturn, TAppState>) => Promise<SchemaHandlerReturn<TSchema>> | SchemaHandlerReturn<TSchema> : (ctx: AgentContext<any, TSetupReturn, TAppState>) => Promise<SchemaHandlerReturn<TSchema>> | SchemaHandlerReturn<TSchema>;
778
- /**
779
- * Configuration object for creating an agent with automatic type inference.
780
- *
781
- * Passed as the second parameter to createAgent(name, config).
782
- *
783
- * @template TSchema - Schema definition object containing optional input, output, and stream properties
784
- * @template TConfig - Function type that returns agent-specific configuration from setup
785
- *
786
- * @example
787
- * ```typescript
788
- * const agent = createAgent('greeting', {
789
- * description: 'Generates personalized greetings',
790
- * schema: {
791
- * input: z.object({ name: z.string(), age: z.number() }),
792
- * output: z.string()
793
- * },
794
- * handler: async (ctx, { name, age }) => {
795
- * return `Hello, ${name}! You are ${age} years old.`;
796
- * }
797
- * });
798
- * ```
799
- */
800
- export interface CreateAgentConfig<TSchema extends {
801
- input?: StandardSchemaV1;
802
- output?: StandardSchemaV1;
803
- stream?: boolean;
804
- } | undefined = undefined, TConfig extends (app: AppState) => any = any> {
805
- /**
806
- * Optional schema validation using Zod or any StandardSchemaV1 compatible library.
807
- *
808
- * @example
809
- * ```typescript
810
- * schema: {
811
- * input: z.object({ name: z.string(), age: z.number() }),
812
- * output: z.string(),
813
- * stream: false
814
- * }
815
- * ```
816
- */
817
- schema?: TSchema;
818
- /**
819
- * Optional description of what this agent does, visible in the Agentuity platform.
820
- *
821
- * @example
822
- * ```typescript
823
- * description: 'Returns personalized greetings'
824
- * ```
825
- */
826
- description?: string;
827
- /**
828
- * Optional metadata object (typically injected by build plugin during compilation).
829
- * Contains agent identification and versioning information.
830
- *
831
- * @internal - Usually populated by build tooling, not manually set
832
- */
833
- metadata?: Partial<AgentMetadata>;
834
- /**
835
- * Optional async function called once on app startup to initialize agent-specific resources.
836
- * The returned value is available in the handler via `ctx.config`.
837
- *
838
- * @param app - Application state from createApp setup function
839
- * @returns Agent-specific configuration object
840
- *
841
- * @example
842
- * ```typescript
843
- * setup: async (app) => {
844
- * const cache = new Map();
845
- * const db = await connectDB();
846
- * return { cache, db };
847
- * }
848
- * ```
849
- */
850
- setup?: TConfig;
851
- /**
852
- * The main agent logic that processes requests.
853
- * Receives AgentContext and validated input (if schema.input is defined), returns output or stream.
854
- *
855
- * @param ctx - Agent context with logger, storage, and other runtime services
856
- * @param input - Validated input (only present if schema.input is defined)
857
- * @returns Output matching schema.output type, or ReadableStream if schema.stream is true
858
- *
859
- * @example
860
- * ```typescript
861
- * handler: async (ctx, { name, age }) => {
862
- * ctx.logger.info(`Processing for ${name}`);
863
- * await ctx.kv.set('lastUser', name);
864
- * return `Hello, ${name}! You are ${age} years old.`;
865
- * }
866
- * ```
867
- */
868
- handler: AgentHandlerFromConfig<TSchema, TConfig extends (app: AppState) => infer R ? Awaited<R> : undefined, AppState>;
869
- /**
870
- * Optional async cleanup function called on app shutdown.
871
- * Use this to close connections, flush buffers, etc.
872
- *
873
- * @param app - Application state from createApp
874
- * @param config - Agent config returned from setup function
875
- *
876
- * @example
877
- * ```typescript
878
- * shutdown: async (app, config) => {
879
- * await config.db.close();
880
- * config.cache.clear();
881
- * }
882
- * ```
883
- */
884
- shutdown?: (app: AppState, config: TConfig extends (app: AppState) => infer R ? Awaited<R> : undefined) => Promise<void> | void;
885
- }
886
- /**
887
- * The public interface returned by createAgent().
888
- * Provides methods to run the agent, create evaluations, and manage event listeners.
889
- *
890
- * @template TInput - Input schema type (StandardSchemaV1 or undefined if no input)
891
- * @template TOutput - Output schema type (StandardSchemaV1 or undefined if no output)
892
- * @template TStream - Whether the agent returns a stream (true/false)
893
- *
894
- * @example
895
- * ```typescript
896
- * const agent = createAgent('greeting', {
897
- * schema: {
898
- * input: z.object({ name: z.string() }),
899
- * output: z.string()
900
- * },
901
- * handler: async (ctx, { name }) => `Hello, ${name}!`
902
- * });
903
- *
904
- * // Run the agent
905
- * const result = await agent.run({ name: 'Alice' });
906
- *
907
- * // Create evaluation
908
- * const evalDef = agent.createEval('greeting-accuracy', {
909
- * description: 'Checks if greeting includes the user name',
910
- * handler: async (ctx, input, output) => {
911
- * return { score: output.includes(input.name) ? 1 : 0 };
912
- * }
913
- * });
914
- *
915
- * // Listen to events
916
- * agent.addEventListener('completed', async (eventName, agent, context) => {
917
- * console.log('Agent completed successfully');
918
- * });
919
- * ```
920
- */
921
- export interface AgentRunner<TInput extends StandardSchemaV1 | undefined = any, TOutput extends StandardSchemaV1 | undefined = any, TStream extends boolean = false> {
922
- /** Agent metadata (id, name, description, etc.) */
923
- metadata: AgentMetadata;
924
- /**
925
- * Execute the agent with validated input.
926
- * If agent has no input schema, call with no arguments.
927
- * If agent has input schema, pass validated input object.
928
- *
929
- * @example
930
- * ```typescript
931
- * // Agent with input
932
- * const result = await agent.run({ name: 'Alice' });
933
- *
934
- * // Agent without input
935
- * const result = await agent.run();
936
- * ```
937
- */
938
- run: undefined extends TInput ? () => Promise<InferStreamOutput<Exclude<TOutput, undefined>, TStream>> : (input: InferSchemaInput<Exclude<TInput, undefined>>) => Promise<InferStreamOutput<Exclude<TOutput, undefined>, TStream>>;
939
- /**
940
- * Create Hono validator middleware for this agent.
941
- * Automatically validates request input against the agent's schema.
942
- *
943
- * @example
944
- * ```typescript
945
- * import myAgent from './my-agent';
946
- * router.post('/', myAgent.validator(), async (c) => {
947
- * const data = c.req.valid('json'); // Fully typed!
948
- * return c.json(await myAgent.run(data));
949
- * });
950
- * ```
951
- */
952
- validator: AgentValidator<TInput, TOutput>;
953
- /** Input schema (if defined) */
954
- inputSchema?: TInput;
955
- /** Output schema (if defined) */
956
- outputSchema?: TOutput;
957
- /** Whether agent returns a stream */
958
- stream?: TStream;
959
- /**
960
- * Create an evaluation for this agent.
961
- * Evaluations run automatically after the agent completes.
962
- *
963
- * @example
964
- * ```typescript
965
- * const accuracyEval = agent.createEval('accuracy', {
966
- * description: 'Validates output length is non-zero',
967
- * handler: async (ctx, input, output) => ({
968
- * score: output.length > 0 ? 1 : 0,
969
- * metadata: { outputLength: output.length }
970
- * })
971
- * });
972
- * ```
973
- */
974
- createEval: CreateEvalMethod<TInput, TOutput>;
975
- /**
976
- * Add event listener for 'started' or 'completed' events.
977
- * Listeners fire sequentially in the order they were added.
978
- *
979
- * @param eventName - 'started' or 'completed'
980
- * @param callback - Function to call when event fires
981
- *
982
- * @example
983
- * ```typescript
984
- * agent.addEventListener('started', async (eventName, agent, context) => {
985
- * context.logger.info('Agent execution started');
986
- * });
987
- * ```
988
- */
989
- addEventListener(eventName: 'started' | 'completed', callback: (eventName: 'started' | 'completed', agent: Agent<TInput, TOutput, TStream, any, any>, context: AgentContext<any, any, any>) => Promise<void> | void): void;
990
- /**
991
- * Add event listener for 'errored' event.
992
- * Fires when agent handler throws an error.
993
- *
994
- * @param eventName - 'errored'
995
- * @param callback - Function to call when error occurs
996
- *
997
- * @example
998
- * ```typescript
999
- * agent.addEventListener('errored', async (eventName, agent, context, error) => {
1000
- * context.logger.error('Agent failed', { error: error.message });
1001
- * });
1002
- * ```
1003
- */
1004
- addEventListener(eventName: 'errored', callback: (eventName: 'errored', agent: Agent<TInput, TOutput, TStream, any, any>, context: AgentContext<any, any, any>, error: Error) => Promise<void> | void): void;
1005
- /**
1006
- * Remove event listener for 'started' or 'completed' events.
1007
- *
1008
- * @param eventName - 'started' or 'completed'
1009
- * @param callback - The same callback function that was added
1010
- */
1011
- removeEventListener(eventName: 'started' | 'completed', callback: (eventName: 'started' | 'completed', agent: Agent<TInput, TOutput, TStream, any, any>, context: AgentContext<any, any, any>) => Promise<void> | void): void;
1012
- /**
1013
- * Remove event listener for 'errored' event.
1014
- *
1015
- * @param eventName - 'errored'
1016
- * @param callback - The same callback function that was added
1017
- */
1018
- removeEventListener(eventName: 'errored', callback: (eventName: 'errored', agent: Agent<TInput, TOutput, TStream, any, any>, context: AgentContext<any, any, any>, error: Error) => Promise<void> | void): void;
1019
- }
1020
- /**
1021
- * Get the global runtime state (for production use).
1022
- * In tests, use TestAgentContext which has isolated runtime state.
1023
- */
1024
- export declare function getGlobalRuntimeState(): AgentRuntimeState;
1025
- /**
1026
- * Get the runtime state from an AgentContext.
1027
- * @internal
1028
- */
1029
- export declare function getAgentRuntime(ctx: AgentContext<any, any, any>): AgentRuntimeState;
1030
- /**
1031
- * Union type of all registered agent names.
1032
- * Falls back to `string` when no agents are registered (before augmentation).
1033
- * After augmentation, this becomes a strict union of agent names for full type safety.
1034
- */
1035
- export type AgentName = keyof AgentRegistry extends never ? string : keyof AgentRegistry;
1036
- /**
1037
- * Agent registry interface.
1038
- * This interface is augmented by generated code to provide strongly-typed agent access.
1039
- */
1040
- export interface AgentRegistry {
1041
- }
1042
- export declare const registerAgent: (name: AgentName, agent: Agent<any, any, any, any, any>) => void;
1043
- export declare const setAgentConfig: (name: AgentName, config: unknown) => void;
1044
- export declare const getAgentConfig: (name: AgentName) => unknown;
1045
- /**
1046
- * Configuration object for creating an agent with explicit type parameters.
1047
- *
1048
- * @template TInput - Input schema type (StandardSchemaV1 or undefined)
1049
- * @template TOutput - Output schema type (StandardSchemaV1 or undefined)
1050
- * @template TStream - Whether agent returns a stream (true/false)
1051
- * @template TConfig - Type returned by setup function
1052
- * @template TAppState - Custom app state type from createApp
1053
- */
1054
- export interface CreateAgentConfigExplicit<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TStream extends boolean = false, TConfig = unknown, TAppState = AppState> {
1055
- /**
1056
- * Optional schema validation.
1057
- *
1058
- * @example
1059
- * ```typescript
1060
- * schema: {
1061
- * input: z.object({ name: z.string() }),
1062
- * output: z.string(),
1063
- * stream: false,
1064
- * }
1065
- * ```
1066
- */
1067
- schema?: {
1068
- /** Input validation schema */
1069
- input?: TInput;
1070
- /** Output validation schema */
1071
- output?: TOutput;
1072
- /** Whether the agent returns a ReadableStream */
1073
- stream?: TStream;
1074
- };
1075
- /**
1076
- * Optional description of what this agent does.
1077
- *
1078
- * @example
1079
- * ```typescript
1080
- * description: 'Does something useful'
1081
- * ```
1082
- */
1083
- description?: string;
1084
- /**
1085
- * Optional metadata object (typically injected by build plugin during compilation).
1086
- * Contains agent identification and versioning information.
1087
- *
1088
- * @internal - Usually populated by build tooling, not manually set
1089
- */
1090
- metadata?: Partial<AgentMetadata>;
1091
- /**
1092
- * Optional setup function receiving app state, returns agent config.
1093
- * The returned value is available in the handler via `ctx.config`.
1094
- *
1095
- * @param app - Application state from createApp
1096
- * @returns Agent-specific configuration
1097
- *
1098
- * @example
1099
- * ```typescript
1100
- * setup: async (app) => ({ cache: new Map() })
1101
- * ```
1102
- */
1103
- setup?: (app: TAppState) => Promise<TConfig> | TConfig;
1104
- /**
1105
- * Optional cleanup function called on app shutdown.
1106
- *
1107
- * @param app - Application state from createApp
1108
- * @param config - Agent config returned from setup
1109
- *
1110
- * @example
1111
- * ```typescript
1112
- * shutdown: async (app, config) => {
1113
- * config.cache.clear();
1114
- * }
1115
- * ```
1116
- */
1117
- shutdown?: (app: TAppState, config: TConfig) => Promise<void> | void;
1118
- /**
1119
- * Agent handler function.
1120
- * Type is automatically inferred based on schema definitions.
1121
- *
1122
- * @param ctx - Agent context
1123
- * @param input - Validated input (only present if schema.input is defined)
1124
- * @returns Output or ReadableStream based on schema
1125
- *
1126
- * @example
1127
- * ```typescript
1128
- * handler: async (ctx, input) => {
1129
- * return `Hello, ${input.name}!`;
1130
- * }
1131
- * ```
1132
- */
1133
- handler: TInput extends StandardSchemaV1 ? TStream extends true ? TOutput extends StandardSchemaV1 ? (c: AgentContext<any, TConfig, TAppState>, input: InferOutput<TInput>) => Promise<ReadableStream<InferOutput<TOutput>>> | ReadableStream<InferOutput<TOutput>> : (c: AgentContext<any, TConfig, TAppState>, input: InferOutput<TInput>) => Promise<ReadableStream<unknown>> | ReadableStream<unknown> : TOutput extends StandardSchemaV1 ? (c: AgentContext<any, TConfig, TAppState>, input: InferOutput<TInput>) => Promise<InferOutput<TOutput>> | InferOutput<TOutput> : (c: AgentContext<any, TConfig, TAppState>, input: InferOutput<TInput>) => Promise<void> | void : TStream extends true ? TOutput extends StandardSchemaV1 ? (c: AgentContext<any, TConfig, TAppState>) => Promise<ReadableStream<InferOutput<TOutput>>> | ReadableStream<InferOutput<TOutput>> : (c: AgentContext<any, TConfig, TAppState>) => Promise<ReadableStream<unknown>> | ReadableStream<unknown> : TOutput extends StandardSchemaV1 ? (c: AgentContext<any, TConfig, TAppState>) => Promise<InferOutput<TOutput>> | InferOutput<TOutput> : (c: AgentContext<any, TConfig, TAppState>) => Promise<void> | void;
1134
- }
1135
- /**
1136
- * Creates an agent with schema validation and lifecycle hooks.
1137
- *
1138
- * This is the recommended way to create agents with automatic type inference from schemas.
1139
- *
1140
- * @template TSchema - Schema definition object containing optional input, output, and stream properties
1141
- * @template TConfig - Function type that returns agent-specific configuration from setup
1142
- *
1143
- * @param name - Unique agent name (must be unique within the project)
1144
- * @param config - Agent configuration object
1145
- *
1146
- * @returns AgentRunner with a run method for executing the agent
1147
- *
1148
- * @example
1149
- * ```typescript
1150
- * const agent = createAgent('greeting-agent', {
1151
- * description: 'Returns personalized greetings',
1152
- * schema: {
1153
- * input: z.object({ name: z.string(), age: z.number() }),
1154
- * output: z.string()
1155
- * },
1156
- * handler: async (ctx, { name, age }) => {
1157
- * ctx.logger.info(`Processing greeting for ${name}`);
1158
- * return `Hello, ${name}! You are ${age} years old.`;
1159
- * }
1160
- * });
1161
- *
1162
- * // Call the agent directly
1163
- * const result = await agent.run({ name: 'Alice', age: 30 });
1164
- * ```
1165
- */
1166
- export declare function createAgent<TSchema extends {
1167
- input?: StandardSchemaV1;
1168
- output?: StandardSchemaV1;
1169
- stream?: boolean;
1170
- } | undefined = undefined, TConfig extends (app: AppState) => any = any>(name: string, config: CreateAgentConfig<TSchema, TConfig>): AgentRunner<SchemaInput<TSchema>, SchemaOutput<TSchema>, SchemaStream<TSchema>>;
1171
- /**
1172
- * Creates an agent with explicit generic type parameters.
1173
- *
1174
- * Use this overload when you need explicit control over types or working with custom app state.
1175
- *
1176
- * @template TInput - Input schema type (StandardSchemaV1 or undefined)
1177
- * @template TOutput - Output schema type (StandardSchemaV1 or undefined)
1178
- * @template TStream - Whether agent returns a stream (true/false)
1179
- * @template TConfig - Type returned by setup function
1180
- * @template TAppState - Custom app state type from createApp
1181
- *
1182
- * @param name - Unique agent name (must be unique within the project)
1183
- * @param config - Agent configuration object
1184
- *
1185
- * @returns AgentRunner with explicit types and a run method
1186
- *
1187
- * @example
1188
- * ```typescript
1189
- * interface MyAppState { db: Database }
1190
- * interface MyConfig { cache: Map<string, any> }
1191
- *
1192
- * const agent = createAgent<
1193
- * z.ZodObject<any>, // TInput
1194
- * z.ZodString, // TOutput
1195
- * false // TStream
1196
- * >('custom-agent', {
1197
- * setup: async (app) => ({ cache: new Map() }),
1198
- * handler: async (ctx, input) => {
1199
- * const db = ctx.app.db;
1200
- * const cache = ctx.config.cache;
1201
- * return 'result';
1202
- * }
1203
- * });
1204
- * ```
1205
- */
1206
- export declare function createAgent<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TStream extends boolean = false, TConfig = unknown, TAppState = AppState>(name: string, config: CreateAgentConfigExplicit<TInput, TOutput, TStream, TConfig, TAppState>): AgentRunner<TInput, TOutput, TStream>;
1207
- /**
1208
- * Populate the agents object with all registered agents
1209
- * Keys are converted to camelCase to match the generated TypeScript types
1210
- */
1211
- export declare const populateAgentsRegistry: (ctx: Context) => any;
1212
- export declare const createAgentMiddleware: (agentName: AgentName | "") => MiddlewareHandler;
1213
- export declare const getAgents: () => Map<string, Agent<any, any, any, any, any>>;
1214
- export declare const runAgentSetups: (appState: AppState) => Promise<void>;
1215
- export declare const runAgentShutdowns: (appState: AppState) => Promise<void>;
1216
- /**
1217
- * Run an agent within a specific AgentContext.
1218
- * Sets up AsyncLocalStorage with the provided context and executes the agent.
1219
- *
1220
- * This is the recommended way to test agents in unit tests. It automatically:
1221
- * - Registers the agent in the runtime state so event listeners fire
1222
- * - Sets up AsyncLocalStorage so getAgentContext() works inside the agent
1223
- * - Handles both agents with input and agents without input
1224
- *
1225
- * **Use cases:**
1226
- * - Unit testing agents with TestAgentContext
1227
- * - Running agents outside HTTP request flow
1228
- * - Custom agent execution environments
1229
- * - Testing event listeners and evaluations
1230
- *
1231
- * @template TInput - Type of the input parameter
1232
- * @template TOutput - Type of the return value
1233
- *
1234
- * @param ctx - The AgentContext to use (typically TestAgentContext in tests)
1235
- * @param agent - The AgentRunner to execute (returned from createAgent)
1236
- * @param input - Input data (required if agent has input schema, omit otherwise)
1237
- *
1238
- * @returns Promise resolving to the agent's output
1239
- *
1240
- * @example
1241
- * ```typescript
1242
- * import { runInAgentContext, TestAgentContext } from '@agentuity/runtime/test';
1243
- *
1244
- * test('greeting agent', async () => {
1245
- * const ctx = new TestAgentContext();
1246
- * const result = await runInAgentContext(ctx, greetingAgent, {
1247
- * name: 'Alice',
1248
- * age: 30
1249
- * });
1250
- * expect(result).toBe('Hello, Alice! You are 30 years old.');
1251
- * });
1252
- *
1253
- * test('no-input agent', async () => {
1254
- * const ctx = new TestAgentContext();
1255
- * const result = await runInAgentContext(ctx, statusAgent);
1256
- * expect(result).toEqual({ status: 'ok' });
1257
- * });
1258
- * ```
1259
- */
1260
- export declare function runInAgentContext<TInput, TOutput>(ctx: AgentContext<any, any, any>, agent: AgentRunner<any, any, any>, input?: TInput): Promise<TOutput>;
1261
- export {};
1262
- //# sourceMappingURL=agent.d.ts.map