effect 4.1.2 → 4.1.4

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 (495) hide show
  1. package/ai-docs/package.json +1 -1
  2. package/ai-docs/tsconfig.json +2 -1
  3. package/dist/DateTime.d.ts +33 -2
  4. package/dist/DateTime.d.ts.map +1 -1
  5. package/dist/DateTime.js +16 -0
  6. package/dist/DateTime.js.map +1 -1
  7. package/dist/Match.d.ts +6 -6
  8. package/dist/Match.d.ts.map +1 -1
  9. package/dist/Match.js.map +1 -1
  10. package/dist/Queue.d.ts +2 -1
  11. package/dist/Queue.d.ts.map +1 -1
  12. package/dist/Queue.js +16 -9
  13. package/dist/Queue.js.map +1 -1
  14. package/dist/Rational.d.ts +1214 -0
  15. package/dist/Rational.d.ts.map +1 -0
  16. package/dist/Rational.js +880 -0
  17. package/dist/Rational.js.map +1 -0
  18. package/dist/RcMap.d.ts +3 -0
  19. package/dist/RcMap.d.ts.map +1 -1
  20. package/dist/RcMap.js +13 -14
  21. package/dist/RcMap.js.map +1 -1
  22. package/dist/Runtime.d.ts +75 -3
  23. package/dist/Runtime.d.ts.map +1 -1
  24. package/dist/Runtime.js +81 -4
  25. package/dist/Runtime.js.map +1 -1
  26. package/dist/Schema.d.ts +131 -29
  27. package/dist/Schema.d.ts.map +1 -1
  28. package/dist/Schema.js +128 -22
  29. package/dist/Schema.js.map +1 -1
  30. package/dist/SchemaAST.d.ts.map +1 -1
  31. package/dist/SchemaAST.js +24 -12
  32. package/dist/SchemaAST.js.map +1 -1
  33. package/dist/SchemaParser.js +2 -2
  34. package/dist/SchemaParser.js.map +1 -1
  35. package/dist/SchemaRepresentation.d.ts +26 -3
  36. package/dist/SchemaRepresentation.d.ts.map +1 -1
  37. package/dist/SchemaRepresentation.js +13 -2
  38. package/dist/SchemaRepresentation.js.map +1 -1
  39. package/dist/ScopedCache.d.ts +7 -0
  40. package/dist/ScopedCache.d.ts.map +1 -1
  41. package/dist/ScopedCache.js +18 -1
  42. package/dist/ScopedCache.js.map +1 -1
  43. package/dist/ai/AgUi.d.ts +109 -0
  44. package/dist/ai/AgUi.d.ts.map +1 -0
  45. package/dist/ai/AgUi.js +543 -0
  46. package/dist/ai/AgUi.js.map +1 -0
  47. package/dist/ai/AgUiSchema.d.ts +6965 -0
  48. package/dist/ai/AgUiSchema.d.ts.map +1 -0
  49. package/dist/ai/AgUiSchema.js +974 -0
  50. package/dist/ai/AgUiSchema.js.map +1 -0
  51. package/dist/ai/AgUiServer.d.ts +6400 -0
  52. package/dist/ai/AgUiServer.d.ts.map +1 -0
  53. package/dist/ai/AgUiServer.js +309 -0
  54. package/dist/ai/AgUiServer.js.map +1 -0
  55. package/dist/ai/Chat.d.ts +31 -5
  56. package/dist/ai/Chat.d.ts.map +1 -1
  57. package/dist/ai/Chat.js +34 -4
  58. package/dist/ai/Chat.js.map +1 -1
  59. package/dist/ai/LanguageModel.d.ts +24 -5
  60. package/dist/ai/LanguageModel.d.ts.map +1 -1
  61. package/dist/ai/LanguageModel.js +26 -12
  62. package/dist/ai/LanguageModel.js.map +1 -1
  63. package/dist/ai/McpSchema.d.ts +110 -110
  64. package/dist/ai/McpSchema.d.ts.map +1 -1
  65. package/dist/ai/McpServer.d.ts +15 -0
  66. package/dist/ai/McpServer.d.ts.map +1 -1
  67. package/dist/ai/McpServer.js +211 -33
  68. package/dist/ai/McpServer.js.map +1 -1
  69. package/dist/ai/Prompt.d.ts +6 -2
  70. package/dist/ai/Prompt.d.ts.map +1 -1
  71. package/dist/ai/Prompt.js.map +1 -1
  72. package/dist/ai/Response.d.ts +5 -2
  73. package/dist/ai/Response.d.ts.map +1 -1
  74. package/dist/ai/Response.js +5 -1
  75. package/dist/ai/Response.js.map +1 -1
  76. package/dist/ai/Tool.d.ts +265 -69
  77. package/dist/ai/Tool.d.ts.map +1 -1
  78. package/dist/ai/Tool.js +19 -2
  79. package/dist/ai/Tool.js.map +1 -1
  80. package/dist/ai/Toolkit.d.ts +32 -2
  81. package/dist/ai/Toolkit.d.ts.map +1 -1
  82. package/dist/ai/Toolkit.js +61 -8
  83. package/dist/ai/Toolkit.js.map +1 -1
  84. package/dist/ai/WorkloadIdentity.d.ts +111 -0
  85. package/dist/ai/WorkloadIdentity.d.ts.map +1 -0
  86. package/dist/ai/WorkloadIdentity.js +227 -0
  87. package/dist/ai/WorkloadIdentity.js.map +1 -0
  88. package/dist/ai/index.d.ts +20 -0
  89. package/dist/ai/index.d.ts.map +1 -1
  90. package/dist/ai/index.js +20 -0
  91. package/dist/ai/index.js.map +1 -1
  92. package/dist/ai/internal/mcpCore.d.ts +0 -2
  93. package/dist/ai/internal/mcpCore.d.ts.map +1 -1
  94. package/dist/ai/internal/mcpCore.js +2 -8
  95. package/dist/ai/internal/mcpCore.js.map +1 -1
  96. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +5 -8
  97. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  98. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +5 -8
  99. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  100. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +5 -5
  101. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  102. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +5 -5
  103. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  104. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +60 -51
  105. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  106. package/dist/ai/internal/mcpProtocol.js +11 -1
  107. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  108. package/dist/ai/internal/mcpProtocolRegistry.js +4 -0
  109. package/dist/ai/internal/mcpProtocolRegistry.js.map +1 -1
  110. package/dist/ai/internal/mcpRuntime.js +2 -0
  111. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  112. package/dist/ai/internal/mcpSchema/v2024_11_05.js +0 -2
  113. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  114. package/dist/ai/internal/mcpSchema/v2025_03_26.d.ts.map +1 -1
  115. package/dist/ai/internal/mcpSchema/v2025_03_26.js +0 -2
  116. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  117. package/dist/ai/internal/mcpSchema/v2025_06_18.d.ts.map +1 -1
  118. package/dist/ai/internal/mcpSchema/v2025_06_18.js +0 -2
  119. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  120. package/dist/ai/internal/mcpSchema/v2025_11_25.d.ts.map +1 -1
  121. package/dist/ai/internal/mcpSchema/v2025_11_25.js +0 -2
  122. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  123. package/dist/ai/internal/mcpSchema/v2026_07_28.d.ts.map +1 -1
  124. package/dist/ai/internal/mcpSchema/v2026_07_28.js +0 -2
  125. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  126. package/dist/ai/internal/mcpSkills.js +5 -17
  127. package/dist/ai/internal/mcpSkills.js.map +1 -1
  128. package/dist/ai/internal/mcpStatefulRuntime.js +0 -2
  129. package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
  130. package/dist/ai/internal/structured-output.js +5 -1
  131. package/dist/ai/internal/structured-output.js.map +1 -1
  132. package/dist/cli/Argument.d.ts +81 -0
  133. package/dist/cli/Argument.d.ts.map +1 -1
  134. package/dist/cli/Argument.js +26 -0
  135. package/dist/cli/Argument.js.map +1 -1
  136. package/dist/cli/CliError.d.ts +7 -4
  137. package/dist/cli/CliError.d.ts.map +1 -1
  138. package/dist/cli/CliError.js +7 -4
  139. package/dist/cli/CliError.js.map +1 -1
  140. package/dist/cli/Command.d.ts +241 -22
  141. package/dist/cli/Command.d.ts.map +1 -1
  142. package/dist/cli/Command.js +88 -10
  143. package/dist/cli/Command.js.map +1 -1
  144. package/dist/cli/CommandSpec.d.ts +287 -0
  145. package/dist/cli/CommandSpec.d.ts.map +1 -0
  146. package/dist/cli/CommandSpec.js +277 -0
  147. package/dist/cli/CommandSpec.js.map +1 -0
  148. package/dist/cli/Completions.d.ts +5 -0
  149. package/dist/cli/Completions.d.ts.map +1 -1
  150. package/dist/cli/Completions.js.map +1 -1
  151. package/dist/cli/Flag.d.ts +102 -0
  152. package/dist/cli/Flag.d.ts.map +1 -1
  153. package/dist/cli/Flag.js +47 -0
  154. package/dist/cli/Flag.js.map +1 -1
  155. package/dist/cli/Param.d.ts +154 -1
  156. package/dist/cli/Param.d.ts.map +1 -1
  157. package/dist/cli/Param.js +87 -29
  158. package/dist/cli/Param.js.map +1 -1
  159. package/dist/cli/index.d.ts +5 -0
  160. package/dist/cli/index.d.ts.map +1 -1
  161. package/dist/cli/index.js +5 -0
  162. package/dist/cli/index.js.map +1 -1
  163. package/dist/cli/internal/command.d.ts +2 -2
  164. package/dist/cli/internal/command.d.ts.map +1 -1
  165. package/dist/cli/internal/command.js +1 -1
  166. package/dist/cli/internal/command.js.map +1 -1
  167. package/dist/cli/internal/completions/bash.js +6 -7
  168. package/dist/cli/internal/completions/bash.js.map +1 -1
  169. package/dist/cli/internal/completions/descriptor.js +21 -7
  170. package/dist/cli/internal/completions/descriptor.js.map +1 -1
  171. package/dist/cli/internal/completions/fish.js +3 -3
  172. package/dist/cli/internal/completions/fish.js.map +1 -1
  173. package/dist/cli/internal/completions/powershell.js +2 -2
  174. package/dist/cli/internal/completions/powershell.js.map +1 -1
  175. package/dist/cli/internal/completions/zsh.js +2 -2
  176. package/dist/cli/internal/completions/zsh.js.map +1 -1
  177. package/dist/cli/internal/lexer.js +13 -0
  178. package/dist/cli/internal/lexer.js.map +1 -1
  179. package/dist/cli/internal/parser.js +23 -16
  180. package/dist/cli/internal/parser.js.map +1 -1
  181. package/dist/cli/internal/wizard.d.ts.map +1 -1
  182. package/dist/cli/internal/wizard.js +4 -0
  183. package/dist/cli/internal/wizard.js.map +1 -1
  184. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  185. package/dist/cluster/ClusterWorkflowEngine.js +15 -13
  186. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  187. package/dist/cluster/Entity.d.ts +17 -0
  188. package/dist/cluster/Entity.d.ts.map +1 -1
  189. package/dist/cluster/Entity.js +20 -0
  190. package/dist/cluster/Entity.js.map +1 -1
  191. package/dist/cluster/MessageRetention.d.ts +71 -0
  192. package/dist/cluster/MessageRetention.d.ts.map +1 -0
  193. package/dist/cluster/MessageRetention.js +100 -0
  194. package/dist/cluster/MessageRetention.js.map +1 -0
  195. package/dist/cluster/MessageStorage.d.ts +81 -0
  196. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  197. package/dist/cluster/MessageStorage.js +34 -2
  198. package/dist/cluster/MessageStorage.js.map +1 -1
  199. package/dist/cluster/ShardingConfig.d.ts +24 -2
  200. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  201. package/dist/cluster/ShardingConfig.js.map +1 -1
  202. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  203. package/dist/cluster/SqlMessageStorage.js +187 -29
  204. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  205. package/dist/cluster/index.d.ts +5 -0
  206. package/dist/cluster/index.d.ts.map +1 -1
  207. package/dist/cluster/index.js +5 -0
  208. package/dist/cluster/index.js.map +1 -1
  209. package/dist/encoding/Base64.d.ts +0 -6
  210. package/dist/encoding/Base64.d.ts.map +1 -1
  211. package/dist/encoding/Base64.js +25 -5
  212. package/dist/encoding/Base64.js.map +1 -1
  213. package/dist/encoding/Base64Url.d.ts +0 -6
  214. package/dist/encoding/Base64Url.d.ts.map +1 -1
  215. package/dist/encoding/Base64Url.js +91 -8
  216. package/dist/encoding/Base64Url.js.map +1 -1
  217. package/dist/encoding/Csv.d.ts.map +1 -1
  218. package/dist/encoding/Csv.js +11 -5
  219. package/dist/encoding/Csv.js.map +1 -1
  220. package/dist/encoding/Hex.d.ts.map +1 -1
  221. package/dist/encoding/Hex.js +51 -34
  222. package/dist/encoding/Hex.js.map +1 -1
  223. package/dist/encoding/SchemaBinary.d.ts +14 -2
  224. package/dist/encoding/SchemaBinary.d.ts.map +1 -1
  225. package/dist/encoding/SchemaBinary.js +78 -5
  226. package/dist/encoding/SchemaBinary.js.map +1 -1
  227. package/dist/encoding/Xml.d.ts +25 -0
  228. package/dist/encoding/Xml.d.ts.map +1 -1
  229. package/dist/encoding/Xml.js +44 -19
  230. package/dist/encoding/Xml.js.map +1 -1
  231. package/dist/graphql/GraphQL.d.ts.map +1 -1
  232. package/dist/graphql/GraphQL.js +4 -1
  233. package/dist/graphql/GraphQL.js.map +1 -1
  234. package/dist/http/Headers.d.ts +5 -1
  235. package/dist/http/Headers.d.ts.map +1 -1
  236. package/dist/http/Headers.js +7 -2
  237. package/dist/http/Headers.js.map +1 -1
  238. package/dist/http/HttpClient.d.ts +57 -12
  239. package/dist/http/HttpClient.d.ts.map +1 -1
  240. package/dist/http/HttpClient.js +92 -54
  241. package/dist/http/HttpClient.js.map +1 -1
  242. package/dist/http/HttpClientError.d.ts +22 -8
  243. package/dist/http/HttpClientError.d.ts.map +1 -1
  244. package/dist/http/HttpClientError.js +68 -14
  245. package/dist/http/HttpClientError.js.map +1 -1
  246. package/dist/http/HttpEffect.d.ts +63 -4
  247. package/dist/http/HttpEffect.d.ts.map +1 -1
  248. package/dist/http/HttpEffect.js +89 -9
  249. package/dist/http/HttpEffect.js.map +1 -1
  250. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  251. package/dist/http/HttpMiddleware.js +5 -3
  252. package/dist/http/HttpMiddleware.js.map +1 -1
  253. package/dist/http/HttpServer.d.ts +80 -0
  254. package/dist/http/HttpServer.d.ts.map +1 -1
  255. package/dist/http/HttpServer.js +16 -0
  256. package/dist/http/HttpServer.js.map +1 -1
  257. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  258. package/dist/http/HttpServerRequest.js +1 -14
  259. package/dist/http/HttpServerRequest.js.map +1 -1
  260. package/dist/http/HttpStaticServer.js +10 -16
  261. package/dist/http/HttpStaticServer.js.map +1 -1
  262. package/dist/http/internal/requestState.js +15 -0
  263. package/dist/http/internal/requestState.js.map +1 -1
  264. package/dist/http-api/HttpApi.d.ts +47 -0
  265. package/dist/http-api/HttpApi.d.ts.map +1 -1
  266. package/dist/http-api/HttpApi.js +66 -0
  267. package/dist/http-api/HttpApi.js.map +1 -1
  268. package/dist/http-api/HttpApiBuilder.d.ts.map +1 -1
  269. package/dist/http-api/HttpApiBuilder.js +18 -2
  270. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  271. package/dist/http-api/HttpApiClient.d.ts +1 -1
  272. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  273. package/dist/http-api/HttpApiClient.js +5 -1
  274. package/dist/http-api/HttpApiClient.js.map +1 -1
  275. package/dist/http-api/HttpApiSchema.d.ts +85 -0
  276. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  277. package/dist/http-api/HttpApiSchema.js +74 -2
  278. package/dist/http-api/HttpApiSchema.js.map +1 -1
  279. package/dist/index.d.ts +5 -0
  280. package/dist/index.d.ts.map +1 -1
  281. package/dist/index.js +5 -0
  282. package/dist/index.js.map +1 -1
  283. package/dist/internal/base64.d.ts +2 -0
  284. package/dist/internal/base64.d.ts.map +1 -0
  285. package/dist/internal/base64.js +30 -0
  286. package/dist/internal/base64.js.map +1 -0
  287. package/dist/internal/core.js +3 -4
  288. package/dist/internal/core.js.map +1 -1
  289. package/dist/internal/dateTime.js +18 -10
  290. package/dist/internal/dateTime.js.map +1 -1
  291. package/dist/internal/effect.js +41 -17
  292. package/dist/internal/effect.js.map +1 -1
  293. package/dist/internal/equal.js +7 -0
  294. package/dist/internal/equal.js.map +1 -1
  295. package/dist/internal/matcher.js +1 -1
  296. package/dist/internal/matcher.js.map +1 -1
  297. package/dist/internal/schema/codegen.js +7 -7
  298. package/dist/internal/schema/codegen.js.map +1 -1
  299. package/dist/internal/schema/fromJsonSchemaDocument.js +161 -36
  300. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  301. package/dist/internal/schema/interpreter.js +10 -10
  302. package/dist/internal/schema/interpreter.js.map +1 -1
  303. package/dist/internal/schema/parser.js +9 -4
  304. package/dist/internal/schema/parser.js.map +1 -1
  305. package/dist/internal/schema/toCodeDocument.js +3 -0
  306. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  307. package/dist/internal/schema/toEquivalence.js +6 -5
  308. package/dist/internal/schema/toEquivalence.js.map +1 -1
  309. package/dist/internal/schema/toFormatter.js +3 -2
  310. package/dist/internal/schema/toFormatter.js.map +1 -1
  311. package/dist/internal/version.js +1 -1
  312. package/dist/observability/OtlpMetrics.js +1 -1
  313. package/dist/observability/OtlpMetrics.js.map +1 -1
  314. package/dist/observability/OtlpTracer.js +2 -2
  315. package/dist/observability/OtlpTracer.js.map +1 -1
  316. package/dist/persistence/PersistedQueue.d.ts +72 -3
  317. package/dist/persistence/PersistedQueue.d.ts.map +1 -1
  318. package/dist/persistence/PersistedQueue.js +142 -29
  319. package/dist/persistence/PersistedQueue.js.map +1 -1
  320. package/dist/persistence/RateLimiter.d.ts +12 -2
  321. package/dist/persistence/RateLimiter.d.ts.map +1 -1
  322. package/dist/persistence/RateLimiter.js +11 -4
  323. package/dist/persistence/RateLimiter.js.map +1 -1
  324. package/dist/process/CommandLine.d.ts +9 -9
  325. package/dist/process/CommandLine.js +6 -6
  326. package/dist/process/index.d.ts +1 -1
  327. package/dist/process/index.js +1 -1
  328. package/dist/reactivity/Atom.d.ts.map +1 -1
  329. package/dist/reactivity/Atom.js +24 -3
  330. package/dist/reactivity/Atom.js.map +1 -1
  331. package/dist/reactivity/AtomRpc.d.ts +24 -6
  332. package/dist/reactivity/AtomRpc.d.ts.map +1 -1
  333. package/dist/reactivity/AtomRpc.js.map +1 -1
  334. package/dist/rpc/OpenRpc.d.ts +384 -0
  335. package/dist/rpc/OpenRpc.d.ts.map +1 -0
  336. package/dist/rpc/OpenRpc.js +490 -0
  337. package/dist/rpc/OpenRpc.js.map +1 -0
  338. package/dist/rpc/Rpc.d.ts +22 -3
  339. package/dist/rpc/Rpc.d.ts.map +1 -1
  340. package/dist/rpc/Rpc.js.map +1 -1
  341. package/dist/rpc/RpcClient.d.ts +20 -21
  342. package/dist/rpc/RpcClient.d.ts.map +1 -1
  343. package/dist/rpc/RpcClient.js.map +1 -1
  344. package/dist/rpc/RpcServer.d.ts +23 -2
  345. package/dist/rpc/RpcServer.d.ts.map +1 -1
  346. package/dist/rpc/RpcServer.js +67 -25
  347. package/dist/rpc/RpcServer.js.map +1 -1
  348. package/dist/rpc/index.d.ts +5 -0
  349. package/dist/rpc/index.d.ts.map +1 -1
  350. package/dist/rpc/index.js +5 -0
  351. package/dist/rpc/index.js.map +1 -1
  352. package/dist/schema/SchemaCompiler/runtime.js +3 -2
  353. package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
  354. package/dist/sql/SqlClient.d.ts +59 -6
  355. package/dist/sql/SqlClient.d.ts.map +1 -1
  356. package/dist/sql/SqlClient.js +64 -17
  357. package/dist/sql/SqlClient.js.map +1 -1
  358. package/dist/sql/Statement.d.ts +1 -1
  359. package/dist/sql/Statement.d.ts.map +1 -1
  360. package/dist/sql/Statement.js +9 -16
  361. package/dist/sql/Statement.js.map +1 -1
  362. package/dist/testing/TestClock.d.ts +2 -12
  363. package/dist/testing/TestClock.d.ts.map +1 -1
  364. package/dist/testing/TestClock.js +179 -169
  365. package/dist/testing/TestClock.js.map +1 -1
  366. package/dist/workflow/DurableClock.d.ts +27 -0
  367. package/dist/workflow/DurableClock.d.ts.map +1 -1
  368. package/dist/workflow/DurableClock.js +18 -2
  369. package/dist/workflow/DurableClock.js.map +1 -1
  370. package/dist/workflow/Workflow.d.ts.map +1 -1
  371. package/dist/workflow/Workflow.js +5 -4
  372. package/dist/workflow/Workflow.js.map +1 -1
  373. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  374. package/dist/workflow/WorkflowEngine.js +14 -3
  375. package/dist/workflow/WorkflowEngine.js.map +1 -1
  376. package/package.json +3 -3
  377. package/src/DateTime.ts +35 -2
  378. package/src/Match.ts +10 -8
  379. package/src/Queue.ts +16 -11
  380. package/src/Rational.ts +1549 -0
  381. package/src/RcMap.ts +16 -14
  382. package/src/Runtime.ts +84 -4
  383. package/src/Schema.ts +188 -29
  384. package/src/SchemaAST.ts +29 -13
  385. package/src/SchemaParser.ts +2 -2
  386. package/src/SchemaRepresentation.ts +31 -3
  387. package/src/ScopedCache.ts +18 -1
  388. package/src/ai/AgUi.ts +485 -0
  389. package/src/ai/AgUiSchema.ts +1666 -0
  390. package/src/ai/AgUiServer.ts +451 -0
  391. package/src/ai/Chat.ts +87 -19
  392. package/src/ai/LanguageModel.ts +97 -23
  393. package/src/ai/McpServer.ts +244 -49
  394. package/src/ai/Prompt.ts +6 -2
  395. package/src/ai/Response.ts +19 -3
  396. package/src/ai/Tool.ts +426 -110
  397. package/src/ai/Toolkit.ts +71 -10
  398. package/src/ai/WorkloadIdentity.ts +318 -0
  399. package/src/ai/index.ts +24 -0
  400. package/src/ai/internal/mcpCore.ts +11 -15
  401. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +8 -11
  402. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +8 -11
  403. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +8 -8
  404. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +8 -8
  405. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +76 -55
  406. package/src/ai/internal/mcpProtocol.ts +22 -3
  407. package/src/ai/internal/mcpProtocolRegistry.ts +5 -0
  408. package/src/ai/internal/mcpRuntime.ts +4 -2
  409. package/src/ai/internal/mcpSchema/v2024_11_05.ts +0 -2
  410. package/src/ai/internal/mcpSchema/v2025_03_26.ts +0 -2
  411. package/src/ai/internal/mcpSchema/v2025_06_18.ts +0 -2
  412. package/src/ai/internal/mcpSchema/v2025_11_25.ts +0 -2
  413. package/src/ai/internal/mcpSchema/v2026_07_28.ts +0 -2
  414. package/src/ai/internal/mcpSkills.ts +5 -20
  415. package/src/ai/internal/mcpStatefulRuntime.ts +0 -2
  416. package/src/ai/internal/structured-output.ts +7 -2
  417. package/src/cli/Argument.ts +86 -0
  418. package/src/cli/CliError.ts +7 -4
  419. package/src/cli/Command.ts +266 -36
  420. package/src/cli/CommandSpec.ts +508 -0
  421. package/src/cli/Completions.ts +5 -0
  422. package/src/cli/Flag.ts +106 -0
  423. package/src/cli/Param.ts +225 -23
  424. package/src/cli/index.ts +6 -0
  425. package/src/cli/internal/command.ts +3 -4
  426. package/src/cli/internal/completions/bash.ts +9 -7
  427. package/src/cli/internal/completions/descriptor.ts +37 -5
  428. package/src/cli/internal/completions/fish.ts +9 -3
  429. package/src/cli/internal/completions/powershell.ts +2 -1
  430. package/src/cli/internal/completions/zsh.ts +2 -2
  431. package/src/cli/internal/lexer.ts +14 -0
  432. package/src/cli/internal/parser.ts +28 -20
  433. package/src/cli/internal/wizard.ts +4 -0
  434. package/src/cluster/ClusterWorkflowEngine.ts +14 -15
  435. package/src/cluster/Entity.ts +24 -0
  436. package/src/cluster/MessageRetention.ts +111 -0
  437. package/src/cluster/MessageStorage.ts +73 -2
  438. package/src/cluster/ShardingConfig.ts +12 -1
  439. package/src/cluster/SqlMessageStorage.ts +271 -41
  440. package/src/cluster/index.ts +6 -0
  441. package/src/encoding/Base64.ts +26 -5
  442. package/src/encoding/Base64Url.ts +93 -10
  443. package/src/encoding/Csv.ts +11 -5
  444. package/src/encoding/Hex.ts +56 -42
  445. package/src/encoding/SchemaBinary.ts +76 -5
  446. package/src/encoding/Xml.ts +65 -16
  447. package/src/graphql/GraphQL.ts +7 -4
  448. package/src/http/Headers.ts +7 -2
  449. package/src/http/HttpClient.ts +118 -68
  450. package/src/http/HttpClientError.ts +82 -15
  451. package/src/http/HttpEffect.ts +101 -10
  452. package/src/http/HttpMiddleware.ts +15 -4
  453. package/src/http/HttpServer.ts +80 -0
  454. package/src/http/HttpServerRequest.ts +1 -19
  455. package/src/http/HttpStaticServer.ts +10 -16
  456. package/src/http/internal/requestState.ts +20 -0
  457. package/src/http-api/HttpApi.ts +80 -0
  458. package/src/http-api/HttpApiBuilder.ts +20 -2
  459. package/src/http-api/HttpApiClient.ts +13 -2
  460. package/src/http-api/HttpApiSchema.ts +90 -3
  461. package/src/index.ts +6 -0
  462. package/src/internal/base64.ts +42 -0
  463. package/src/internal/core.ts +3 -4
  464. package/src/internal/dateTime.ts +27 -13
  465. package/src/internal/effect.ts +45 -18
  466. package/src/internal/equal.ts +8 -0
  467. package/src/internal/matcher.ts +7 -3
  468. package/src/internal/schema/codegen.ts +8 -7
  469. package/src/internal/schema/fromJsonSchemaDocument.ts +175 -35
  470. package/src/internal/schema/interpreter.ts +10 -10
  471. package/src/internal/schema/parser.ts +8 -4
  472. package/src/internal/schema/toCodeDocument.ts +8 -0
  473. package/src/internal/schema/toEquivalence.ts +7 -5
  474. package/src/internal/schema/toFormatter.ts +3 -2
  475. package/src/internal/version.ts +1 -1
  476. package/src/observability/OtlpMetrics.ts +1 -1
  477. package/src/observability/OtlpTracer.ts +2 -2
  478. package/src/persistence/PersistedQueue.ts +199 -41
  479. package/src/persistence/RateLimiter.ts +17 -5
  480. package/src/process/CommandLine.ts +10 -10
  481. package/src/process/index.ts +1 -1
  482. package/src/reactivity/Atom.ts +25 -3
  483. package/src/reactivity/AtomRpc.ts +61 -45
  484. package/src/rpc/OpenRpc.ts +747 -0
  485. package/src/rpc/Rpc.ts +38 -6
  486. package/src/rpc/RpcClient.ts +45 -82
  487. package/src/rpc/RpcServer.ts +77 -28
  488. package/src/rpc/index.ts +6 -0
  489. package/src/schema/SchemaCompiler/runtime.ts +8 -3
  490. package/src/sql/SqlClient.ts +112 -26
  491. package/src/sql/Statement.ts +19 -23
  492. package/src/testing/TestClock.ts +204 -189
  493. package/src/workflow/DurableClock.ts +20 -3
  494. package/src/workflow/Workflow.ts +5 -3
  495. package/src/workflow/WorkflowEngine.ts +20 -5
@@ -0,0 +1,1666 @@
1
+ /**
2
+ * Defines schemas for the Agent User Interaction (AG-UI) protocol.
3
+ *
4
+ * AG-UI connects an agent backend to a user-facing application: the
5
+ * application posts a `RunAgentInput` and the agent answers with a stream of
6
+ * events describing the run. These schemas follow the AG-UI 1.0 specification
7
+ * and describe the request body, the conversation messages it carries, and
8
+ * every event type. Converting to and from `effect/ai` values lives in `AgUi`,
9
+ * and the HTTP binding lives in `AgUiServer`.
10
+ *
11
+ * @see https://docs.ag-ui.com
12
+ *
13
+ * @stability experimental
14
+ * @since 4.1.0
15
+ */
16
+ import * as Effect from "../Effect.ts"
17
+ import { identity } from "../Function.ts"
18
+ import * as Predicate from "../Predicate.ts"
19
+ import * as Schema from "../Schema.ts"
20
+ import * as SchemaTransformation from "../SchemaTransformation.ts"
21
+
22
+ /**
23
+ * AG-UI protocol version implemented by these schemas.
24
+ *
25
+ * @stability experimental
26
+ * @category constants
27
+ * @since 4.1.0
28
+ */
29
+ export const protocolVersion = "1.0"
30
+
31
+ // =============================================================================
32
+ // Shared
33
+ // =============================================================================
34
+
35
+ /**
36
+ * Schema for open-ended metadata attached to events, messages, tools, and
37
+ * other protocol values.
38
+ *
39
+ * **Details**
40
+ *
41
+ * The `ag-ui` key is reserved for the protocol's own use.
42
+ *
43
+ * @stability experimental
44
+ * @category schemas
45
+ * @since 4.1.0
46
+ */
47
+ export const Metadata = Schema.Record(Schema.String, Schema.Unknown)
48
+
49
+ /**
50
+ * Open-ended metadata attached to events, messages, tools, and other protocol
51
+ * values.
52
+ *
53
+ * @stability experimental
54
+ * @category models
55
+ * @since 4.1.0
56
+ */
57
+ export type Metadata = typeof Metadata.Type
58
+
59
+ const baseEventFields = {
60
+ timestamp: Schema.optionalKey(Schema.Int),
61
+ rawEvent: Schema.optionalKey(Schema.Unknown),
62
+ metadata: Schema.optionalKey(Metadata)
63
+ }
64
+
65
+ const subagentEventFields = {
66
+ ...baseEventFields,
67
+ subagentRunId: Schema.optionalKey(Schema.String)
68
+ }
69
+
70
+ const TokenCount = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))
71
+
72
+ // AG-UI consumers remove list elements they do not recognise, such as union
73
+ // members or closed-set values added by a newer protocol version, instead of
74
+ // rejecting the value holding them. Recognised but malformed elements still
75
+ // fail to decode.
76
+ const withoutUnknownMembers = <S extends Schema.Constraint>(item: S, isUnknown: (value: unknown) => boolean) => {
77
+ // Accepts only unrecognised material, so it never hides a malformed item.
78
+ // JSON Schema and OpenAPI document the canonical model: a union splices in
79
+ // a member that is only an `anyOf`, so an empty one leaves just the item's
80
+ // variants and generated clients keep their discriminated types.
81
+ const Unrecognised = Schema.Any.check(Schema.makeFilter(isUnknown, {
82
+ toJsonSchema: () => ({ anyOf: [] })
83
+ }))
84
+ return Schema.Array(Schema.Union([item, Unrecognised])).pipe(
85
+ Schema.decodeTo(
86
+ Schema.Array(Schema.toType(item)),
87
+ SchemaTransformation.transform({
88
+ decode: (values) => values.filter((value) => !isUnknown(value)) as ReadonlyArray<S["Type"]>,
89
+ encode: identity
90
+ })
91
+ )
92
+ )
93
+ }
94
+
95
+ // Only a string outside the closed set is unrecognised; a missing or
96
+ // mistyped value is malformed
97
+ const hasUnknownTag = (value: unknown, key: string, tags: ReadonlySet<string>): boolean =>
98
+ Predicate.isObject(value) && typeof value[key] === "string" && !tags.has(value[key])
99
+
100
+ // =============================================================================
101
+ // Content
102
+ // =============================================================================
103
+
104
+ /**
105
+ * Schema for media bytes carried inline as base64 data.
106
+ *
107
+ * @stability experimental
108
+ * @category schemas
109
+ * @since 4.1.0
110
+ */
111
+ export const DataSource = Schema.Struct({
112
+ type: Schema.Literal("data"),
113
+ value: Schema.String,
114
+ mimeType: Schema.String
115
+ })
116
+
117
+ /**
118
+ * Media bytes carried inline as base64 data.
119
+ *
120
+ * @stability experimental
121
+ * @category models
122
+ * @since 4.1.0
123
+ */
124
+ export type DataSource = typeof DataSource.Type
125
+
126
+ /**
127
+ * Schema for media bytes referenced by URL.
128
+ *
129
+ * @stability experimental
130
+ * @category schemas
131
+ * @since 4.1.0
132
+ */
133
+ export const UrlSource = Schema.Struct({
134
+ type: Schema.Literal("url"),
135
+ value: Schema.String,
136
+ mimeType: Schema.optionalKey(Schema.String)
137
+ })
138
+
139
+ /**
140
+ * Media bytes referenced by URL.
141
+ *
142
+ * @stability experimental
143
+ * @category models
144
+ * @since 4.1.0
145
+ */
146
+ export type UrlSource = typeof UrlSource.Type
147
+
148
+ /**
149
+ * Schema for media bytes already stored at a provider and named by a handle
150
+ * that provider issued.
151
+ *
152
+ * @stability experimental
153
+ * @category schemas
154
+ * @since 4.1.0
155
+ */
156
+ export const FileSource = Schema.Struct({
157
+ type: Schema.Literal("file"),
158
+ value: Schema.String,
159
+ provider: Schema.optionalKey(Schema.String),
160
+ mimeType: Schema.optionalKey(Schema.String)
161
+ })
162
+
163
+ /**
164
+ * Media bytes already stored at a provider and named by a handle that provider
165
+ * issued.
166
+ *
167
+ * @stability experimental
168
+ * @category models
169
+ * @since 4.1.0
170
+ */
171
+ export type FileSource = typeof FileSource.Type
172
+
173
+ /**
174
+ * Schema for the source of a media content part.
175
+ *
176
+ * @stability experimental
177
+ * @category schemas
178
+ * @since 4.1.0
179
+ */
180
+ export const PartSource = Schema.Union([DataSource, UrlSource, FileSource])
181
+
182
+ /**
183
+ * Source of a media content part.
184
+ *
185
+ * @stability experimental
186
+ * @category models
187
+ * @since 4.1.0
188
+ */
189
+ export type PartSource = typeof PartSource.Type
190
+
191
+ /**
192
+ * Schema for a text content part.
193
+ *
194
+ * @stability experimental
195
+ * @category schemas
196
+ * @since 4.1.0
197
+ */
198
+ export const TextPart = Schema.Struct({
199
+ type: Schema.Literal("text"),
200
+ id: Schema.optionalKey(Schema.String),
201
+ text: Schema.String,
202
+ metadata: Schema.optionalKey(Schema.Unknown)
203
+ })
204
+
205
+ /**
206
+ * A text content part.
207
+ *
208
+ * @stability experimental
209
+ * @category models
210
+ * @since 4.1.0
211
+ */
212
+ export type TextPart = typeof TextPart.Type
213
+
214
+ const mediaPart = <Type extends string>(type: Type) =>
215
+ Schema.Struct({
216
+ type: Schema.Literal(type),
217
+ id: Schema.optionalKey(Schema.String),
218
+ source: PartSource,
219
+ metadata: Schema.optionalKey(Schema.Unknown)
220
+ })
221
+
222
+ /**
223
+ * Schema for an image content part.
224
+ *
225
+ * @stability experimental
226
+ * @category schemas
227
+ * @since 4.1.0
228
+ */
229
+ export const ImagePart = mediaPart("image")
230
+
231
+ /**
232
+ * An image content part.
233
+ *
234
+ * @stability experimental
235
+ * @category models
236
+ * @since 4.1.0
237
+ */
238
+ export type ImagePart = typeof ImagePart.Type
239
+
240
+ /**
241
+ * Schema for an audio content part.
242
+ *
243
+ * @stability experimental
244
+ * @category schemas
245
+ * @since 4.1.0
246
+ */
247
+ export const AudioPart = mediaPart("audio")
248
+
249
+ /**
250
+ * An audio content part.
251
+ *
252
+ * @stability experimental
253
+ * @category models
254
+ * @since 4.1.0
255
+ */
256
+ export type AudioPart = typeof AudioPart.Type
257
+
258
+ /**
259
+ * Schema for a video content part.
260
+ *
261
+ * @stability experimental
262
+ * @category schemas
263
+ * @since 4.1.0
264
+ */
265
+ export const VideoPart = mediaPart("video")
266
+
267
+ /**
268
+ * A video content part.
269
+ *
270
+ * @stability experimental
271
+ * @category models
272
+ * @since 4.1.0
273
+ */
274
+ export type VideoPart = typeof VideoPart.Type
275
+
276
+ /**
277
+ * Schema for a document content part.
278
+ *
279
+ * @stability experimental
280
+ * @category schemas
281
+ * @since 4.1.0
282
+ */
283
+ export const DocumentPart = mediaPart("document")
284
+
285
+ /**
286
+ * A document content part.
287
+ *
288
+ * @stability experimental
289
+ * @category models
290
+ * @since 4.1.0
291
+ */
292
+ export type DocumentPart = typeof DocumentPart.Type
293
+
294
+ /**
295
+ * Schema for any content part of a user or tool message.
296
+ *
297
+ * @stability experimental
298
+ * @category schemas
299
+ * @since 4.1.0
300
+ */
301
+ export const ContentPart = Schema.Union([TextPart, ImagePart, AudioPart, VideoPart, DocumentPart])
302
+
303
+ /**
304
+ * Any content part of a user or tool message.
305
+ *
306
+ * @stability experimental
307
+ * @category models
308
+ * @since 4.1.0
309
+ */
310
+ export type ContentPart = typeof ContentPart.Type
311
+
312
+ const contentPartTypes: ReadonlySet<string> = new Set(["text", "image", "audio", "video", "document"])
313
+ const partSourceTypes: ReadonlySet<string> = new Set(["data", "url", "file"])
314
+
315
+ const mediaPartTypes: ReadonlySet<unknown> = new Set(["image", "audio", "video", "document"])
316
+
317
+ // A recognised media part whose required source is unrecognised is removed
318
+ // with it
319
+ const isUnknownContentPart = (value: unknown): boolean =>
320
+ hasUnknownTag(value, "type", contentPartTypes) ||
321
+ (Predicate.isObject(value) && mediaPartTypes.has(value.type) &&
322
+ hasUnknownTag(value.source, "type", partSourceTypes))
323
+
324
+ const Content = Schema.Union([Schema.String, withoutUnknownMembers(ContentPart, isUnknownContentPart)])
325
+
326
+ // =============================================================================
327
+ // Messages
328
+ // =============================================================================
329
+
330
+ const messageFields = {
331
+ subagentRunId: Schema.optionalKey(Schema.String),
332
+ id: Schema.String,
333
+ metadata: Schema.optionalKey(Metadata)
334
+ }
335
+
336
+ /**
337
+ * Schema for instructions from the application developer.
338
+ *
339
+ * @stability experimental
340
+ * @category schemas
341
+ * @since 4.1.0
342
+ */
343
+ export const DeveloperMessage = Schema.Struct({
344
+ ...messageFields,
345
+ role: Schema.Literal("developer"),
346
+ name: Schema.optionalKey(Schema.String),
347
+ encryptedValue: Schema.optionalKey(Schema.String),
348
+ content: Schema.String
349
+ })
350
+
351
+ /**
352
+ * Instructions from the application developer.
353
+ *
354
+ * @stability experimental
355
+ * @category models
356
+ * @since 4.1.0
357
+ */
358
+ export type DeveloperMessage = typeof DeveloperMessage.Type
359
+
360
+ /**
361
+ * Schema for instructions from the system.
362
+ *
363
+ * @stability experimental
364
+ * @category schemas
365
+ * @since 4.1.0
366
+ */
367
+ export const SystemMessage = Schema.Struct({
368
+ ...messageFields,
369
+ role: Schema.Literal("system"),
370
+ name: Schema.optionalKey(Schema.String),
371
+ encryptedValue: Schema.optionalKey(Schema.String),
372
+ content: Schema.String
373
+ })
374
+
375
+ /**
376
+ * Instructions from the system.
377
+ *
378
+ * @stability experimental
379
+ * @category models
380
+ * @since 4.1.0
381
+ */
382
+ export type SystemMessage = typeof SystemMessage.Type
383
+
384
+ /**
385
+ * Schema for a tool call made by an assistant message.
386
+ *
387
+ * **Details**
388
+ *
389
+ * `function.arguments` is the JSON text of the call's arguments.
390
+ *
391
+ * @stability experimental
392
+ * @category schemas
393
+ * @since 4.1.0
394
+ */
395
+ export const ToolCall = Schema.Struct({
396
+ id: Schema.String,
397
+ type: Schema.Literal("function"),
398
+ function: Schema.Struct({
399
+ name: Schema.String,
400
+ arguments: Schema.String
401
+ }),
402
+ encryptedValue: Schema.optionalKey(Schema.String),
403
+ metadata: Schema.optionalKey(Metadata)
404
+ })
405
+
406
+ /**
407
+ * A tool call made by an assistant message.
408
+ *
409
+ * @stability experimental
410
+ * @category models
411
+ * @since 4.1.0
412
+ */
413
+ export type ToolCall = typeof ToolCall.Type
414
+
415
+ const toolCallTypes: ReadonlySet<string> = new Set(["function"])
416
+
417
+ /**
418
+ * Schema for a message from the agent.
419
+ *
420
+ * @stability experimental
421
+ * @category schemas
422
+ * @since 4.1.0
423
+ */
424
+ export const AssistantMessage = Schema.Struct({
425
+ ...messageFields,
426
+ role: Schema.Literal("assistant"),
427
+ name: Schema.optionalKey(Schema.String),
428
+ encryptedValue: Schema.optionalKey(Schema.String),
429
+ content: Schema.optionalKey(Schema.String),
430
+ toolCalls: Schema.optionalKey(
431
+ withoutUnknownMembers(ToolCall, (value) => hasUnknownTag(value, "type", toolCallTypes))
432
+ )
433
+ })
434
+
435
+ /**
436
+ * A message from the agent.
437
+ *
438
+ * @stability experimental
439
+ * @category models
440
+ * @since 4.1.0
441
+ */
442
+ export type AssistantMessage = typeof AssistantMessage.Type
443
+
444
+ /**
445
+ * Schema for a message from the person using the application.
446
+ *
447
+ * @stability experimental
448
+ * @category schemas
449
+ * @since 4.1.0
450
+ */
451
+ export const UserMessage = Schema.Struct({
452
+ ...messageFields,
453
+ role: Schema.Literal("user"),
454
+ name: Schema.optionalKey(Schema.String),
455
+ encryptedValue: Schema.optionalKey(Schema.String),
456
+ content: Content
457
+ })
458
+
459
+ /**
460
+ * A message from the person using the application.
461
+ *
462
+ * @stability experimental
463
+ * @category models
464
+ * @since 4.1.0
465
+ */
466
+ export type UserMessage = typeof UserMessage.Type
467
+
468
+ /**
469
+ * Schema for the result of a tool call, as a message in the conversation.
470
+ *
471
+ * **Details**
472
+ *
473
+ * `error` is present when the tool call failed.
474
+ *
475
+ * @stability experimental
476
+ * @category schemas
477
+ * @since 4.1.0
478
+ */
479
+ export const ToolMessage = Schema.Struct({
480
+ ...messageFields,
481
+ role: Schema.Literal("tool"),
482
+ content: Content,
483
+ toolCallId: Schema.String,
484
+ error: Schema.optionalKey(Schema.String),
485
+ encryptedValue: Schema.optionalKey(Schema.String)
486
+ })
487
+
488
+ /**
489
+ * The result of a tool call, as a message in the conversation.
490
+ *
491
+ * @stability experimental
492
+ * @category models
493
+ * @since 4.1.0
494
+ */
495
+ export type ToolMessage = typeof ToolMessage.Type
496
+
497
+ /**
498
+ * Schema for structured progress kept in the conversation as a message.
499
+ *
500
+ * @stability experimental
501
+ * @category schemas
502
+ * @since 4.1.0
503
+ */
504
+ export const ActivityMessage = Schema.Struct({
505
+ ...messageFields,
506
+ role: Schema.Literal("activity"),
507
+ activityType: Schema.String,
508
+ content: Schema.Record(Schema.String, Schema.Unknown)
509
+ })
510
+
511
+ /**
512
+ * Structured progress kept in the conversation as a message.
513
+ *
514
+ * @stability experimental
515
+ * @category models
516
+ * @since 4.1.0
517
+ */
518
+ export type ActivityMessage = typeof ActivityMessage.Type
519
+
520
+ /**
521
+ * Schema for a span of the agent's reasoning, kept in the conversation as a
522
+ * message.
523
+ *
524
+ * @stability experimental
525
+ * @category schemas
526
+ * @since 4.1.0
527
+ */
528
+ export const ReasoningMessage = Schema.Struct({
529
+ ...messageFields,
530
+ role: Schema.Literal("reasoning"),
531
+ content: Schema.String,
532
+ encryptedValue: Schema.optionalKey(Schema.String)
533
+ })
534
+
535
+ /**
536
+ * A span of the agent's reasoning, kept in the conversation as a message.
537
+ *
538
+ * @stability experimental
539
+ * @category models
540
+ * @since 4.1.0
541
+ */
542
+ export type ReasoningMessage = typeof ReasoningMessage.Type
543
+
544
+ /**
545
+ * Schema for any message in an AG-UI conversation, discriminated by `role`.
546
+ *
547
+ * @stability experimental
548
+ * @category schemas
549
+ * @since 4.1.0
550
+ */
551
+ export const Message = Schema.Union([
552
+ DeveloperMessage,
553
+ SystemMessage,
554
+ AssistantMessage,
555
+ UserMessage,
556
+ ToolMessage,
557
+ ActivityMessage,
558
+ ReasoningMessage
559
+ ])
560
+
561
+ /**
562
+ * Any message in an AG-UI conversation, discriminated by `role`.
563
+ *
564
+ * @stability experimental
565
+ * @category models
566
+ * @since 4.1.0
567
+ */
568
+ export type Message = typeof Message.Type
569
+
570
+ const messageRoles: ReadonlySet<string> = new Set([
571
+ "developer",
572
+ "system",
573
+ "assistant",
574
+ "user",
575
+ "tool",
576
+ "activity",
577
+ "reasoning"
578
+ ])
579
+
580
+ const Messages = withoutUnknownMembers(Message, (value) => hasUnknownTag(value, "role", messageRoles))
581
+
582
+ // =============================================================================
583
+ // Run input
584
+ // =============================================================================
585
+
586
+ /**
587
+ * Schema for a tool the application offers to the agent.
588
+ *
589
+ * **Details**
590
+ *
591
+ * `parameters` is a JSON Schema describing the tool's arguments.
592
+ *
593
+ * @stability experimental
594
+ * @category schemas
595
+ * @since 4.1.0
596
+ */
597
+ export const Tool = Schema.Struct({
598
+ name: Schema.String,
599
+ description: Schema.String,
600
+ parameters: Schema.optionalKey(Schema.Unknown),
601
+ metadata: Schema.optionalKey(Metadata)
602
+ })
603
+
604
+ /**
605
+ * A tool the application offers to the agent.
606
+ *
607
+ * @stability experimental
608
+ * @category models
609
+ * @since 4.1.0
610
+ */
611
+ export type Tool = typeof Tool.Type
612
+
613
+ /**
614
+ * Schema for a named piece of ambient information given to the agent for a
615
+ * run.
616
+ *
617
+ * @stability experimental
618
+ * @category schemas
619
+ * @since 4.1.0
620
+ */
621
+ export const Context = Schema.Struct({
622
+ description: Schema.String,
623
+ value: Schema.String
624
+ })
625
+
626
+ /**
627
+ * A named piece of ambient information given to the agent for a run.
628
+ *
629
+ * @stability experimental
630
+ * @category models
631
+ * @since 4.1.0
632
+ */
633
+ export type Context = typeof Context.Type
634
+
635
+ /**
636
+ * Schema for an answer to an interrupt, sent on the run that continues from
637
+ * it.
638
+ *
639
+ * @stability experimental
640
+ * @category schemas
641
+ * @since 4.1.0
642
+ */
643
+ export const ResumeEntry = Schema.Struct({
644
+ interruptId: Schema.String,
645
+ status: Schema.Literals(["resolved", "cancelled"]),
646
+ payload: Schema.optionalKey(Schema.Unknown),
647
+ metadata: Schema.optionalKey(Metadata)
648
+ })
649
+
650
+ /**
651
+ * An answer to an interrupt, sent on the run that continues from it.
652
+ *
653
+ * @stability experimental
654
+ * @category models
655
+ * @since 4.1.0
656
+ */
657
+ export type ResumeEntry = typeof ResumeEntry.Type
658
+
659
+ const resumeStatuses: ReadonlySet<string> = new Set(["resolved", "cancelled"])
660
+
661
+ /**
662
+ * Schema for the request body that starts an agent run.
663
+ *
664
+ * **Details**
665
+ *
666
+ * `messages` is the complete conversation so far, which lets an agent serve
667
+ * runs without keeping its own history. Missing `tools` and `context` decode
668
+ * to empty arrays. As AG-UI requires, messages, content parts, tool calls,
669
+ * and resume entries of kinds or statuses this version does not recognise are
670
+ * removed during decoding rather than rejected.
671
+ *
672
+ * **Gotchas**
673
+ *
674
+ * Every field comes from the client. Treat messages, tools, and context as
675
+ * untrusted input.
676
+ *
677
+ * @stability experimental
678
+ * @category schemas
679
+ * @since 4.1.0
680
+ */
681
+ export const RunAgentInput = Schema.Struct({
682
+ threadId: Schema.String,
683
+ runId: Schema.String,
684
+ protocolVersion: Schema.optionalKey(Schema.String),
685
+ parentRunId: Schema.optionalKey(Schema.String),
686
+ state: Schema.optionalKey(Schema.Unknown),
687
+ messages: Messages,
688
+ tools: Schema.Array(Tool).pipe(Schema.withDecodingDefaultTypeKey(Effect.succeed([]))),
689
+ context: Schema.Array(Context).pipe(Schema.withDecodingDefaultTypeKey(Effect.succeed([]))),
690
+ forwardedProps: Schema.optionalKey(Schema.Unknown),
691
+ resume: Schema.optionalKey(
692
+ withoutUnknownMembers(ResumeEntry, (value) => hasUnknownTag(value, "status", resumeStatuses))
693
+ )
694
+ })
695
+
696
+ /**
697
+ * The request body that starts an agent run.
698
+ *
699
+ * @stability experimental
700
+ * @category models
701
+ * @since 4.1.0
702
+ */
703
+ export type RunAgentInput = typeof RunAgentInput.Type
704
+
705
+ // =============================================================================
706
+ // Text message events
707
+ // =============================================================================
708
+
709
+ /**
710
+ * Schema for the role of a streamed text message.
711
+ *
712
+ * @stability experimental
713
+ * @category schemas
714
+ * @since 4.1.0
715
+ */
716
+ export const TextMessageRole = Schema.Literals(["developer", "system", "assistant", "user"])
717
+
718
+ /**
719
+ * The role of a streamed text message.
720
+ *
721
+ * @stability experimental
722
+ * @category models
723
+ * @since 4.1.0
724
+ */
725
+ export type TextMessageRole = typeof TextMessageRole.Type
726
+
727
+ /**
728
+ * Schema for the event that opens a streamed text message.
729
+ *
730
+ * @stability experimental
731
+ * @category schemas
732
+ * @since 4.1.0
733
+ */
734
+ export const TextMessageStartEvent = Schema.Struct({
735
+ type: Schema.Literal("TEXT_MESSAGE_START"),
736
+ ...subagentEventFields,
737
+ messageId: Schema.String,
738
+ role: Schema.optionalKey(TextMessageRole),
739
+ name: Schema.optionalKey(Schema.String)
740
+ })
741
+
742
+ /**
743
+ * Opens a streamed text message.
744
+ *
745
+ * @stability experimental
746
+ * @category models
747
+ * @since 4.1.0
748
+ */
749
+ export type TextMessageStartEvent = typeof TextMessageStartEvent.Type
750
+
751
+ /**
752
+ * Schema for the event that appends a fragment to a streamed text message.
753
+ *
754
+ * @stability experimental
755
+ * @category schemas
756
+ * @since 4.1.0
757
+ */
758
+ export const TextMessageContentEvent = Schema.Struct({
759
+ type: Schema.Literal("TEXT_MESSAGE_CONTENT"),
760
+ ...subagentEventFields,
761
+ messageId: Schema.String,
762
+ delta: Schema.String
763
+ })
764
+
765
+ /**
766
+ * Appends a fragment to a streamed text message.
767
+ *
768
+ * @stability experimental
769
+ * @category models
770
+ * @since 4.1.0
771
+ */
772
+ export type TextMessageContentEvent = typeof TextMessageContentEvent.Type
773
+
774
+ /**
775
+ * Schema for the event that closes a streamed text message.
776
+ *
777
+ * @stability experimental
778
+ * @category schemas
779
+ * @since 4.1.0
780
+ */
781
+ export const TextMessageEndEvent = Schema.Struct({
782
+ type: Schema.Literal("TEXT_MESSAGE_END"),
783
+ ...subagentEventFields,
784
+ messageId: Schema.String
785
+ })
786
+
787
+ /**
788
+ * Closes a streamed text message.
789
+ *
790
+ * @stability experimental
791
+ * @category models
792
+ * @since 4.1.0
793
+ */
794
+ export type TextMessageEndEvent = typeof TextMessageEndEvent.Type
795
+
796
+ /**
797
+ * Schema for the shorthand event that stands in for a text message's start,
798
+ * content, and end sequence.
799
+ *
800
+ * @stability experimental
801
+ * @category schemas
802
+ * @since 4.1.0
803
+ */
804
+ export const TextMessageChunkEvent = Schema.Struct({
805
+ type: Schema.Literal("TEXT_MESSAGE_CHUNK"),
806
+ ...subagentEventFields,
807
+ messageId: Schema.optionalKey(Schema.String),
808
+ role: Schema.optionalKey(TextMessageRole),
809
+ delta: Schema.optionalKey(Schema.String),
810
+ name: Schema.optionalKey(Schema.String)
811
+ })
812
+
813
+ /**
814
+ * Shorthand that stands in for a text message's start, content, and end
815
+ * sequence.
816
+ *
817
+ * @stability experimental
818
+ * @category models
819
+ * @since 4.1.0
820
+ */
821
+ export type TextMessageChunkEvent = typeof TextMessageChunkEvent.Type
822
+
823
+ // =============================================================================
824
+ // Tool call events
825
+ // =============================================================================
826
+
827
+ /**
828
+ * Schema for the event that opens a tool call.
829
+ *
830
+ * @stability experimental
831
+ * @category schemas
832
+ * @since 4.1.0
833
+ */
834
+ export const ToolCallStartEvent = Schema.Struct({
835
+ type: Schema.Literal("TOOL_CALL_START"),
836
+ ...subagentEventFields,
837
+ toolCallId: Schema.String,
838
+ toolCallName: Schema.String,
839
+ parentMessageId: Schema.optionalKey(Schema.String)
840
+ })
841
+
842
+ /**
843
+ * Opens a tool call.
844
+ *
845
+ * @stability experimental
846
+ * @category models
847
+ * @since 4.1.0
848
+ */
849
+ export type ToolCallStartEvent = typeof ToolCallStartEvent.Type
850
+
851
+ /**
852
+ * Schema for the event that appends a fragment of a tool call's JSON
853
+ * arguments.
854
+ *
855
+ * @stability experimental
856
+ * @category schemas
857
+ * @since 4.1.0
858
+ */
859
+ export const ToolCallArgsEvent = Schema.Struct({
860
+ type: Schema.Literal("TOOL_CALL_ARGS"),
861
+ ...subagentEventFields,
862
+ toolCallId: Schema.String,
863
+ delta: Schema.String
864
+ })
865
+
866
+ /**
867
+ * Appends a fragment of a tool call's JSON arguments.
868
+ *
869
+ * @stability experimental
870
+ * @category models
871
+ * @since 4.1.0
872
+ */
873
+ export type ToolCallArgsEvent = typeof ToolCallArgsEvent.Type
874
+
875
+ /**
876
+ * Schema for the event that closes a tool call once its arguments are
877
+ * complete.
878
+ *
879
+ * @stability experimental
880
+ * @category schemas
881
+ * @since 4.1.0
882
+ */
883
+ export const ToolCallEndEvent = Schema.Struct({
884
+ type: Schema.Literal("TOOL_CALL_END"),
885
+ ...subagentEventFields,
886
+ toolCallId: Schema.String
887
+ })
888
+
889
+ /**
890
+ * Closes a tool call once its arguments are complete.
891
+ *
892
+ * @stability experimental
893
+ * @category models
894
+ * @since 4.1.0
895
+ */
896
+ export type ToolCallEndEvent = typeof ToolCallEndEvent.Type
897
+
898
+ /**
899
+ * Schema for the shorthand event that stands in for a tool call's start,
900
+ * arguments, and end sequence.
901
+ *
902
+ * @stability experimental
903
+ * @category schemas
904
+ * @since 4.1.0
905
+ */
906
+ export const ToolCallChunkEvent = Schema.Struct({
907
+ type: Schema.Literal("TOOL_CALL_CHUNK"),
908
+ ...subagentEventFields,
909
+ toolCallId: Schema.optionalKey(Schema.String),
910
+ toolCallName: Schema.optionalKey(Schema.String),
911
+ parentMessageId: Schema.optionalKey(Schema.String),
912
+ delta: Schema.optionalKey(Schema.String)
913
+ })
914
+
915
+ /**
916
+ * Shorthand that stands in for a tool call's start, arguments, and end
917
+ * sequence.
918
+ *
919
+ * @stability experimental
920
+ * @category models
921
+ * @since 4.1.0
922
+ */
923
+ export type ToolCallChunkEvent = typeof ToolCallChunkEvent.Type
924
+
925
+ /**
926
+ * Schema for the event that delivers the result of a tool call as a new tool
927
+ * message.
928
+ *
929
+ * @stability experimental
930
+ * @category schemas
931
+ * @since 4.1.0
932
+ */
933
+ export const ToolCallResultEvent = Schema.Struct({
934
+ type: Schema.Literal("TOOL_CALL_RESULT"),
935
+ ...subagentEventFields,
936
+ messageId: Schema.String,
937
+ toolCallId: Schema.String,
938
+ content: Content,
939
+ role: Schema.optionalKey(Schema.Literal("tool"))
940
+ })
941
+
942
+ /**
943
+ * Delivers the result of a tool call as a new tool message.
944
+ *
945
+ * @stability experimental
946
+ * @category models
947
+ * @since 4.1.0
948
+ */
949
+ export type ToolCallResultEvent = typeof ToolCallResultEvent.Type
950
+
951
+ // =============================================================================
952
+ // State and activity events
953
+ // =============================================================================
954
+
955
+ /**
956
+ * Schema for one RFC 6902 JSON Patch operation.
957
+ *
958
+ * @stability experimental
959
+ * @category schemas
960
+ * @since 4.1.0
961
+ */
962
+ export const JsonPatchOperation = Schema.Union([
963
+ Schema.Struct({ op: Schema.Literal("add"), path: Schema.String, value: Schema.Unknown }),
964
+ Schema.Struct({ op: Schema.Literal("remove"), path: Schema.String }),
965
+ Schema.Struct({ op: Schema.Literal("replace"), path: Schema.String, value: Schema.Unknown }),
966
+ Schema.Struct({ op: Schema.Literal("move"), from: Schema.String, path: Schema.String }),
967
+ Schema.Struct({ op: Schema.Literal("copy"), from: Schema.String, path: Schema.String }),
968
+ Schema.Struct({ op: Schema.Literal("test"), path: Schema.String, value: Schema.Unknown })
969
+ ])
970
+
971
+ /**
972
+ * One RFC 6902 JSON Patch operation.
973
+ *
974
+ * @stability experimental
975
+ * @category models
976
+ * @since 4.1.0
977
+ */
978
+ export type JsonPatchOperation = typeof JsonPatchOperation.Type
979
+
980
+ /**
981
+ * Schema for the event that replaces the agent state.
982
+ *
983
+ * @stability experimental
984
+ * @category schemas
985
+ * @since 4.1.0
986
+ */
987
+ export const StateSnapshotEvent = Schema.Struct({
988
+ type: Schema.Literal("STATE_SNAPSHOT"),
989
+ ...subagentEventFields,
990
+ snapshot: Schema.Unknown
991
+ })
992
+
993
+ /**
994
+ * Replaces the agent state.
995
+ *
996
+ * @stability experimental
997
+ * @category models
998
+ * @since 4.1.0
999
+ */
1000
+ export type StateSnapshotEvent = typeof StateSnapshotEvent.Type
1001
+
1002
+ /**
1003
+ * Schema for the event that applies a JSON Patch to the agent state.
1004
+ *
1005
+ * @stability experimental
1006
+ * @category schemas
1007
+ * @since 4.1.0
1008
+ */
1009
+ export const StateDeltaEvent = Schema.Struct({
1010
+ type: Schema.Literal("STATE_DELTA"),
1011
+ ...subagentEventFields,
1012
+ delta: Schema.Array(JsonPatchOperation)
1013
+ })
1014
+
1015
+ /**
1016
+ * Applies a JSON Patch to the agent state.
1017
+ *
1018
+ * @stability experimental
1019
+ * @category models
1020
+ * @since 4.1.0
1021
+ */
1022
+ export type StateDeltaEvent = typeof StateDeltaEvent.Type
1023
+
1024
+ /**
1025
+ * Schema for the event that replaces the conversation the agent owns.
1026
+ *
1027
+ * @stability experimental
1028
+ * @category schemas
1029
+ * @since 4.1.0
1030
+ */
1031
+ export const MessagesSnapshotEvent = Schema.Struct({
1032
+ type: Schema.Literal("MESSAGES_SNAPSHOT"),
1033
+ ...baseEventFields,
1034
+ messages: Messages
1035
+ })
1036
+
1037
+ /**
1038
+ * Replaces the conversation the agent owns.
1039
+ *
1040
+ * @stability experimental
1041
+ * @category models
1042
+ * @since 4.1.0
1043
+ */
1044
+ export type MessagesSnapshotEvent = typeof MessagesSnapshotEvent.Type
1045
+
1046
+ /**
1047
+ * Schema for the event that sets the content of an activity message.
1048
+ *
1049
+ * @stability experimental
1050
+ * @category schemas
1051
+ * @since 4.1.0
1052
+ */
1053
+ export const ActivitySnapshotEvent = Schema.Struct({
1054
+ type: Schema.Literal("ACTIVITY_SNAPSHOT"),
1055
+ ...subagentEventFields,
1056
+ messageId: Schema.String,
1057
+ activityType: Schema.String,
1058
+ content: Schema.Record(Schema.String, Schema.Unknown),
1059
+ replace: Schema.optionalKey(Schema.Boolean)
1060
+ })
1061
+
1062
+ /**
1063
+ * Sets the content of an activity message.
1064
+ *
1065
+ * @stability experimental
1066
+ * @category models
1067
+ * @since 4.1.0
1068
+ */
1069
+ export type ActivitySnapshotEvent = typeof ActivitySnapshotEvent.Type
1070
+
1071
+ /**
1072
+ * Schema for the event that applies a JSON Patch to an activity message.
1073
+ *
1074
+ * @stability experimental
1075
+ * @category schemas
1076
+ * @since 4.1.0
1077
+ */
1078
+ export const ActivityDeltaEvent = Schema.Struct({
1079
+ type: Schema.Literal("ACTIVITY_DELTA"),
1080
+ ...subagentEventFields,
1081
+ messageId: Schema.String,
1082
+ activityType: Schema.String,
1083
+ patch: Schema.Array(JsonPatchOperation)
1084
+ })
1085
+
1086
+ /**
1087
+ * Applies a JSON Patch to an activity message.
1088
+ *
1089
+ * @stability experimental
1090
+ * @category models
1091
+ * @since 4.1.0
1092
+ */
1093
+ export type ActivityDeltaEvent = typeof ActivityDeltaEvent.Type
1094
+
1095
+ // =============================================================================
1096
+ // Special events
1097
+ // =============================================================================
1098
+
1099
+ /**
1100
+ * Schema for the event that passes through an event from an external system.
1101
+ *
1102
+ * @stability experimental
1103
+ * @category schemas
1104
+ * @since 4.1.0
1105
+ */
1106
+ export const RawEvent = Schema.Struct({
1107
+ type: Schema.Literal("RAW"),
1108
+ ...subagentEventFields,
1109
+ event: Schema.Unknown,
1110
+ source: Schema.optionalKey(Schema.String)
1111
+ })
1112
+
1113
+ /**
1114
+ * Passes through an event from an external system.
1115
+ *
1116
+ * @stability experimental
1117
+ * @category models
1118
+ * @since 4.1.0
1119
+ */
1120
+ export type RawEvent = typeof RawEvent.Type
1121
+
1122
+ /**
1123
+ * Schema for an application-defined event.
1124
+ *
1125
+ * @stability experimental
1126
+ * @category schemas
1127
+ * @since 4.1.0
1128
+ */
1129
+ export const CustomEvent = Schema.Struct({
1130
+ type: Schema.Literal("CUSTOM"),
1131
+ ...subagentEventFields,
1132
+ name: Schema.String,
1133
+ value: Schema.Unknown
1134
+ })
1135
+
1136
+ /**
1137
+ * An application-defined event.
1138
+ *
1139
+ * @stability experimental
1140
+ * @category models
1141
+ * @since 4.1.0
1142
+ */
1143
+ export type CustomEvent = typeof CustomEvent.Type
1144
+
1145
+ // =============================================================================
1146
+ // Lifecycle events
1147
+ // =============================================================================
1148
+
1149
+ /**
1150
+ * Schema for the event that opens a run.
1151
+ *
1152
+ * @stability experimental
1153
+ * @category schemas
1154
+ * @since 4.1.0
1155
+ */
1156
+ export const RunStartedEvent = Schema.Struct({
1157
+ type: Schema.Literal("RUN_STARTED"),
1158
+ ...baseEventFields,
1159
+ threadId: Schema.String,
1160
+ runId: Schema.String,
1161
+ protocolVersion: Schema.optionalKey(Schema.String),
1162
+ parentRunId: Schema.optionalKey(Schema.String),
1163
+ input: Schema.optionalKey(RunAgentInput)
1164
+ })
1165
+
1166
+ /**
1167
+ * Opens a run.
1168
+ *
1169
+ * @stability experimental
1170
+ * @category models
1171
+ * @since 4.1.0
1172
+ */
1173
+ export type RunStartedEvent = typeof RunStartedEvent.Type
1174
+
1175
+ /**
1176
+ * Schema for something a run needs from outside before it can continue, such
1177
+ * as an approval.
1178
+ *
1179
+ * @stability experimental
1180
+ * @category schemas
1181
+ * @since 4.1.0
1182
+ */
1183
+ export const Interrupt = Schema.Struct({
1184
+ subagentRunId: Schema.optionalKey(Schema.String),
1185
+ id: Schema.String,
1186
+ reason: Schema.String,
1187
+ message: Schema.optionalKey(Schema.String),
1188
+ toolCallId: Schema.optionalKey(Schema.String),
1189
+ responseSchema: Schema.optionalKey(Schema.Record(Schema.String, Schema.Unknown)),
1190
+ expiresAt: Schema.optionalKey(Schema.String),
1191
+ metadata: Schema.optionalKey(Metadata)
1192
+ })
1193
+
1194
+ /**
1195
+ * Something a run needs from outside before it can continue, such as an
1196
+ * approval.
1197
+ *
1198
+ * @stability experimental
1199
+ * @category models
1200
+ * @since 4.1.0
1201
+ */
1202
+ export type Interrupt = typeof Interrupt.Type
1203
+
1204
+ /**
1205
+ * Schema for why a run ended.
1206
+ *
1207
+ * **Details**
1208
+ *
1209
+ * A `success` outcome may name frontend tool calls the application still has
1210
+ * to answer. An `interrupt` outcome pauses the run until a later run resumes
1211
+ * it.
1212
+ *
1213
+ * @stability experimental
1214
+ * @category schemas
1215
+ * @since 4.1.0
1216
+ */
1217
+ export const RunFinishedOutcome = Schema.Union([
1218
+ Schema.Struct({
1219
+ type: Schema.Literal("success"),
1220
+ pendingToolCallIds: Schema.optionalKey(Schema.Array(Schema.String))
1221
+ }),
1222
+ Schema.Struct({
1223
+ type: Schema.Literal("interrupt"),
1224
+ interrupts: Schema.NonEmptyArray(Interrupt)
1225
+ }),
1226
+ Schema.Struct({
1227
+ type: Schema.Literal("cancelled")
1228
+ })
1229
+ ])
1230
+
1231
+ /**
1232
+ * Why a run ended.
1233
+ *
1234
+ * @stability experimental
1235
+ * @category models
1236
+ * @since 4.1.0
1237
+ */
1238
+ export type RunFinishedOutcome = typeof RunFinishedOutcome.Type
1239
+
1240
+ /**
1241
+ * Schema for token counts reported for one provider and model.
1242
+ *
1243
+ * @stability experimental
1244
+ * @category schemas
1245
+ * @since 4.1.0
1246
+ */
1247
+ export const TokenUsage = Schema.Struct({
1248
+ provider: Schema.optionalKey(Schema.String),
1249
+ model: Schema.optionalKey(Schema.String),
1250
+ inputTokens: Schema.optionalKey(TokenCount),
1251
+ outputTokens: Schema.optionalKey(TokenCount),
1252
+ totalTokens: Schema.optionalKey(TokenCount),
1253
+ reasoningTokens: Schema.optionalKey(TokenCount),
1254
+ cachedInputTokens: Schema.optionalKey(TokenCount),
1255
+ cacheWriteInputTokens: Schema.optionalKey(TokenCount)
1256
+ })
1257
+
1258
+ /**
1259
+ * Token counts reported for one provider and model.
1260
+ *
1261
+ * @stability experimental
1262
+ * @category models
1263
+ * @since 4.1.0
1264
+ */
1265
+ export type TokenUsage = typeof TokenUsage.Type
1266
+
1267
+ /**
1268
+ * Schema for the event that closes a run that did not fail.
1269
+ *
1270
+ * @stability experimental
1271
+ * @category schemas
1272
+ * @since 4.1.0
1273
+ */
1274
+ export const RunFinishedEvent = Schema.Struct({
1275
+ type: Schema.Literal("RUN_FINISHED"),
1276
+ ...baseEventFields,
1277
+ threadId: Schema.String,
1278
+ runId: Schema.String,
1279
+ result: Schema.optionalKey(Schema.Unknown),
1280
+ outcome: Schema.optionalKey(RunFinishedOutcome),
1281
+ usage: Schema.optionalKey(Schema.Array(TokenUsage))
1282
+ })
1283
+
1284
+ /**
1285
+ * Closes a run that did not fail.
1286
+ *
1287
+ * @stability experimental
1288
+ * @category models
1289
+ * @since 4.1.0
1290
+ */
1291
+ export type RunFinishedEvent = typeof RunFinishedEvent.Type
1292
+
1293
+ /**
1294
+ * Schema for the event that ends a run that failed.
1295
+ *
1296
+ * @stability experimental
1297
+ * @category schemas
1298
+ * @since 4.1.0
1299
+ */
1300
+ export const RunErrorEvent = Schema.Struct({
1301
+ type: Schema.Literal("RUN_ERROR"),
1302
+ ...baseEventFields,
1303
+ message: Schema.String,
1304
+ code: Schema.optionalKey(Schema.String),
1305
+ usage: Schema.optionalKey(Schema.Array(TokenUsage))
1306
+ })
1307
+
1308
+ /**
1309
+ * Ends a run that failed.
1310
+ *
1311
+ * @stability experimental
1312
+ * @category models
1313
+ * @since 4.1.0
1314
+ */
1315
+ export type RunErrorEvent = typeof RunErrorEvent.Type
1316
+
1317
+ /**
1318
+ * Schema for the event that opens a named step within a run.
1319
+ *
1320
+ * @stability experimental
1321
+ * @category schemas
1322
+ * @since 4.1.0
1323
+ */
1324
+ export const StepStartedEvent = Schema.Struct({
1325
+ type: Schema.Literal("STEP_STARTED"),
1326
+ ...subagentEventFields,
1327
+ stepName: Schema.String
1328
+ })
1329
+
1330
+ /**
1331
+ * Opens a named step within a run.
1332
+ *
1333
+ * @stability experimental
1334
+ * @category models
1335
+ * @since 4.1.0
1336
+ */
1337
+ export type StepStartedEvent = typeof StepStartedEvent.Type
1338
+
1339
+ /**
1340
+ * Schema for the event that closes a named step.
1341
+ *
1342
+ * @stability experimental
1343
+ * @category schemas
1344
+ * @since 4.1.0
1345
+ */
1346
+ export const StepFinishedEvent = Schema.Struct({
1347
+ type: Schema.Literal("STEP_FINISHED"),
1348
+ ...subagentEventFields,
1349
+ stepName: Schema.String
1350
+ })
1351
+
1352
+ /**
1353
+ * Closes a named step.
1354
+ *
1355
+ * @stability experimental
1356
+ * @category models
1357
+ * @since 4.1.0
1358
+ */
1359
+ export type StepFinishedEvent = typeof StepFinishedEvent.Type
1360
+
1361
+ // =============================================================================
1362
+ // Reasoning events
1363
+ // =============================================================================
1364
+
1365
+ /**
1366
+ * Schema for the event that opens a span of reasoning.
1367
+ *
1368
+ * @stability experimental
1369
+ * @category schemas
1370
+ * @since 4.1.0
1371
+ */
1372
+ export const ReasoningStartEvent = Schema.Struct({
1373
+ type: Schema.Literal("REASONING_START"),
1374
+ ...subagentEventFields,
1375
+ messageId: Schema.String
1376
+ })
1377
+
1378
+ /**
1379
+ * Opens a span of reasoning.
1380
+ *
1381
+ * @stability experimental
1382
+ * @category models
1383
+ * @since 4.1.0
1384
+ */
1385
+ export type ReasoningStartEvent = typeof ReasoningStartEvent.Type
1386
+
1387
+ /**
1388
+ * Schema for the event that opens a streamed reasoning message.
1389
+ *
1390
+ * @stability experimental
1391
+ * @category schemas
1392
+ * @since 4.1.0
1393
+ */
1394
+ export const ReasoningMessageStartEvent = Schema.Struct({
1395
+ type: Schema.Literal("REASONING_MESSAGE_START"),
1396
+ ...subagentEventFields,
1397
+ messageId: Schema.String,
1398
+ role: Schema.Literal("reasoning")
1399
+ })
1400
+
1401
+ /**
1402
+ * Opens a streamed reasoning message.
1403
+ *
1404
+ * @stability experimental
1405
+ * @category models
1406
+ * @since 4.1.0
1407
+ */
1408
+ export type ReasoningMessageStartEvent = typeof ReasoningMessageStartEvent.Type
1409
+
1410
+ /**
1411
+ * Schema for the event that appends a fragment to a streamed reasoning
1412
+ * message.
1413
+ *
1414
+ * @stability experimental
1415
+ * @category schemas
1416
+ * @since 4.1.0
1417
+ */
1418
+ export const ReasoningMessageContentEvent = Schema.Struct({
1419
+ type: Schema.Literal("REASONING_MESSAGE_CONTENT"),
1420
+ ...subagentEventFields,
1421
+ messageId: Schema.String,
1422
+ delta: Schema.String
1423
+ })
1424
+
1425
+ /**
1426
+ * Appends a fragment to a streamed reasoning message.
1427
+ *
1428
+ * @stability experimental
1429
+ * @category models
1430
+ * @since 4.1.0
1431
+ */
1432
+ export type ReasoningMessageContentEvent = typeof ReasoningMessageContentEvent.Type
1433
+
1434
+ /**
1435
+ * Schema for the event that closes a streamed reasoning message.
1436
+ *
1437
+ * @stability experimental
1438
+ * @category schemas
1439
+ * @since 4.1.0
1440
+ */
1441
+ export const ReasoningMessageEndEvent = Schema.Struct({
1442
+ type: Schema.Literal("REASONING_MESSAGE_END"),
1443
+ ...subagentEventFields,
1444
+ messageId: Schema.String
1445
+ })
1446
+
1447
+ /**
1448
+ * Closes a streamed reasoning message.
1449
+ *
1450
+ * @stability experimental
1451
+ * @category models
1452
+ * @since 4.1.0
1453
+ */
1454
+ export type ReasoningMessageEndEvent = typeof ReasoningMessageEndEvent.Type
1455
+
1456
+ /**
1457
+ * Schema for the shorthand event that stands in for a reasoning message's
1458
+ * start, content, and end sequence.
1459
+ *
1460
+ * @stability experimental
1461
+ * @category schemas
1462
+ * @since 4.1.0
1463
+ */
1464
+ export const ReasoningMessageChunkEvent = Schema.Struct({
1465
+ type: Schema.Literal("REASONING_MESSAGE_CHUNK"),
1466
+ ...subagentEventFields,
1467
+ messageId: Schema.optionalKey(Schema.String),
1468
+ delta: Schema.optionalKey(Schema.String)
1469
+ })
1470
+
1471
+ /**
1472
+ * Shorthand that stands in for a reasoning message's start, content, and end
1473
+ * sequence.
1474
+ *
1475
+ * @stability experimental
1476
+ * @category models
1477
+ * @since 4.1.0
1478
+ */
1479
+ export type ReasoningMessageChunkEvent = typeof ReasoningMessageChunkEvent.Type
1480
+
1481
+ /**
1482
+ * Schema for the event that closes a span of reasoning.
1483
+ *
1484
+ * @stability experimental
1485
+ * @category schemas
1486
+ * @since 4.1.0
1487
+ */
1488
+ export const ReasoningEndEvent = Schema.Struct({
1489
+ type: Schema.Literal("REASONING_END"),
1490
+ ...subagentEventFields,
1491
+ messageId: Schema.String
1492
+ })
1493
+
1494
+ /**
1495
+ * Closes a span of reasoning.
1496
+ *
1497
+ * @stability experimental
1498
+ * @category models
1499
+ * @since 4.1.0
1500
+ */
1501
+ export type ReasoningEndEvent = typeof ReasoningEndEvent.Type
1502
+
1503
+ /**
1504
+ * Schema for the event that attaches provider-encrypted reasoning to a message
1505
+ * or tool call.
1506
+ *
1507
+ * @stability experimental
1508
+ * @category schemas
1509
+ * @since 4.1.0
1510
+ */
1511
+ export const ReasoningEncryptedValueEvent = Schema.Struct({
1512
+ type: Schema.Literal("REASONING_ENCRYPTED_VALUE"),
1513
+ ...subagentEventFields,
1514
+ subtype: Schema.Literals(["tool-call", "message"]),
1515
+ entityId: Schema.String,
1516
+ encryptedValue: Schema.String
1517
+ })
1518
+
1519
+ /**
1520
+ * Attaches provider-encrypted reasoning to a message or tool call.
1521
+ *
1522
+ * @stability experimental
1523
+ * @category models
1524
+ * @since 4.1.0
1525
+ */
1526
+ export type ReasoningEncryptedValueEvent = typeof ReasoningEncryptedValueEvent.Type
1527
+
1528
+ // =============================================================================
1529
+ // Subagent events
1530
+ // =============================================================================
1531
+
1532
+ /**
1533
+ * Schema for the event that opens a subagent invocation within a run.
1534
+ *
1535
+ * @stability experimental
1536
+ * @category schemas
1537
+ * @since 4.1.0
1538
+ */
1539
+ export const SubagentStartedEvent = Schema.Struct({
1540
+ type: Schema.Literal("SUBAGENT_STARTED"),
1541
+ ...baseEventFields,
1542
+ subagentRunId: Schema.String,
1543
+ name: Schema.String,
1544
+ description: Schema.optionalKey(Schema.String),
1545
+ parentSubagentRunId: Schema.optionalKey(Schema.String),
1546
+ parentToolCallId: Schema.optionalKey(Schema.String),
1547
+ parentMessageId: Schema.optionalKey(Schema.String)
1548
+ })
1549
+
1550
+ /**
1551
+ * Opens a subagent invocation within a run.
1552
+ *
1553
+ * @stability experimental
1554
+ * @category models
1555
+ * @since 4.1.0
1556
+ */
1557
+ export type SubagentStartedEvent = typeof SubagentStartedEvent.Type
1558
+
1559
+ /**
1560
+ * Schema for the event that closes a subagent invocation that did not fail.
1561
+ *
1562
+ * @stability experimental
1563
+ * @category schemas
1564
+ * @since 4.1.0
1565
+ */
1566
+ export const SubagentFinishedEvent = Schema.Struct({
1567
+ type: Schema.Literal("SUBAGENT_FINISHED"),
1568
+ ...baseEventFields,
1569
+ subagentRunId: Schema.String,
1570
+ result: Schema.optionalKey(Schema.Unknown),
1571
+ outcome: Schema.optionalKey(Schema.Union([
1572
+ Schema.Struct({ type: Schema.Literal("success") }),
1573
+ Schema.Struct({
1574
+ type: Schema.Literal("suspended"),
1575
+ interruptIds: Schema.optionalKey(Schema.Array(Schema.String))
1576
+ })
1577
+ ]))
1578
+ })
1579
+
1580
+ /**
1581
+ * Closes a subagent invocation that did not fail.
1582
+ *
1583
+ * @stability experimental
1584
+ * @category models
1585
+ * @since 4.1.0
1586
+ */
1587
+ export type SubagentFinishedEvent = typeof SubagentFinishedEvent.Type
1588
+
1589
+ /**
1590
+ * Schema for the event that reports a failed subagent invocation without
1591
+ * ending the run.
1592
+ *
1593
+ * @stability experimental
1594
+ * @category schemas
1595
+ * @since 4.1.0
1596
+ */
1597
+ export const SubagentErrorEvent = Schema.Struct({
1598
+ type: Schema.Literal("SUBAGENT_ERROR"),
1599
+ ...baseEventFields,
1600
+ subagentRunId: Schema.String,
1601
+ message: Schema.String,
1602
+ code: Schema.optionalKey(Schema.String)
1603
+ })
1604
+
1605
+ /**
1606
+ * Reports a failed subagent invocation without ending the run.
1607
+ *
1608
+ * @stability experimental
1609
+ * @category models
1610
+ * @since 4.1.0
1611
+ */
1612
+ export type SubagentErrorEvent = typeof SubagentErrorEvent.Type
1613
+
1614
+ // =============================================================================
1615
+ // Events
1616
+ // =============================================================================
1617
+
1618
+ /**
1619
+ * Schema for any AG-UI event, discriminated by `type`.
1620
+ *
1621
+ * @stability experimental
1622
+ * @category schemas
1623
+ * @since 4.1.0
1624
+ */
1625
+ export const Event = Schema.Union([
1626
+ TextMessageStartEvent,
1627
+ TextMessageContentEvent,
1628
+ TextMessageEndEvent,
1629
+ TextMessageChunkEvent,
1630
+ ToolCallStartEvent,
1631
+ ToolCallArgsEvent,
1632
+ ToolCallEndEvent,
1633
+ ToolCallChunkEvent,
1634
+ ToolCallResultEvent,
1635
+ StateSnapshotEvent,
1636
+ StateDeltaEvent,
1637
+ MessagesSnapshotEvent,
1638
+ ActivitySnapshotEvent,
1639
+ ActivityDeltaEvent,
1640
+ RawEvent,
1641
+ CustomEvent,
1642
+ RunStartedEvent,
1643
+ RunFinishedEvent,
1644
+ RunErrorEvent,
1645
+ StepStartedEvent,
1646
+ StepFinishedEvent,
1647
+ ReasoningStartEvent,
1648
+ ReasoningMessageStartEvent,
1649
+ ReasoningMessageContentEvent,
1650
+ ReasoningMessageEndEvent,
1651
+ ReasoningMessageChunkEvent,
1652
+ ReasoningEndEvent,
1653
+ ReasoningEncryptedValueEvent,
1654
+ SubagentStartedEvent,
1655
+ SubagentFinishedEvent,
1656
+ SubagentErrorEvent
1657
+ ])
1658
+
1659
+ /**
1660
+ * Any AG-UI event, discriminated by `type`.
1661
+ *
1662
+ * @stability experimental
1663
+ * @category models
1664
+ * @since 4.1.0
1665
+ */
1666
+ export type Event = typeof Event.Type