@mastra/core 1.87.0-alpha.17 → 1.87.0-alpha.19

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 (486) hide show
  1. package/dist/_types/@internal_ai-v6@0.0.99/dist/index.d.ts +2075 -123
  2. package/dist/_types/@internal_core@0.1.4/dist/knowledge-compat/index.d.ts +30 -3
  3. package/dist/agent/agent.d.ts +2 -4
  4. package/dist/agent/agent.types.d.ts +1 -0
  5. package/dist/agent/durable/index.cjs +86 -86
  6. package/dist/agent/durable/index.js +2 -2
  7. package/dist/agent/durable/run-registry.d.ts +54 -25
  8. package/dist/agent/index.cjs +16 -16
  9. package/dist/agent/index.d.ts +1 -0
  10. package/dist/agent/index.js +3 -3
  11. package/dist/agent/scopes.d.ts +8 -0
  12. package/dist/agent/types.d.ts +1 -0
  13. package/dist/agent-builder/ee/index.cjs +1 -1
  14. package/dist/agent-builder/ee/index.js +1 -1
  15. package/dist/agent-controller/agent-controller.d.ts +8 -1
  16. package/dist/agent-controller/index.cjs +3 -3
  17. package/dist/agent-controller/index.js +3 -3
  18. package/dist/agent-controller/session.d.ts +16 -0
  19. package/dist/{agent-controller-cqcUP-xy.cjs → agent-controller-DzOEhUjR.cjs} +55 -35
  20. package/dist/{agent-controller-ChZ3qcXE.js → agent-controller-lBdNfcFi.js} +31 -11
  21. package/dist/{agent-skills-resolver-BMoCDoaK.cjs → agent-skills-resolver-2d8k7ioj.cjs} +134 -109
  22. package/dist/{agent-skills-resolver-CUEIMDbx.js → agent-skills-resolver-D2HktP6Y.js} +134 -109
  23. package/dist/background-tasks/index.cjs +1 -1
  24. package/dist/background-tasks/index.js +1 -1
  25. package/dist/{background-tasks-CH_gzJwc.js → background-tasks-DAu4WaCb.js} +1 -1
  26. package/dist/{background-tasks-BIk1TRPw.cjs → background-tasks-DOmQdBVn.cjs} +1 -1
  27. package/dist/browser/index.cjs +4 -4
  28. package/dist/browser/index.js +4 -4
  29. package/dist/{builder-ZAUhFqtD.cjs → builder-BFcVEbX0.cjs} +3 -3
  30. package/dist/{builder-v01k8_0x.js → builder-DHFtMW8D.js} +2 -2
  31. package/dist/capabilities/302ai.json +198 -198
  32. package/dist/capabilities/abacus.json +2 -96
  33. package/dist/capabilities/abliteratedllm.json +36 -36
  34. package/dist/capabilities/abliteration-ai.json +11 -11
  35. package/dist/capabilities/above.json +19 -19
  36. package/dist/capabilities/adaption.json +11 -11
  37. package/dist/capabilities/adzuki.json +32 -32
  38. package/dist/capabilities/agentrouter.json +12 -12
  39. package/dist/capabilities/agnes.json +4 -4
  40. package/dist/capabilities/ai-router.json +5 -5
  41. package/dist/capabilities/aiand.json +25 -25
  42. package/dist/capabilities/aigrow.json +13 -13
  43. package/dist/capabilities/aimlapi.json +144 -144
  44. package/dist/capabilities/aipg.json +2 -2
  45. package/dist/capabilities/aixy.json +24 -24
  46. package/dist/capabilities/aki-io.json +12 -12
  47. package/dist/capabilities/alibaba-cn.json +81 -126
  48. package/dist/capabilities/alibaba-coding-plan-cn.json +4 -4
  49. package/dist/capabilities/alibaba-coding-plan.json +4 -4
  50. package/dist/capabilities/alibaba-token-plan-cn.json +57 -53
  51. package/dist/capabilities/alibaba-token-plan.json +57 -53
  52. package/dist/capabilities/alibaba.json +76 -71
  53. package/dist/capabilities/ambient.json +14 -32
  54. package/dist/capabilities/amd-tokenlab.json +41 -0
  55. package/dist/capabilities/amd.json +8 -8
  56. package/dist/capabilities/anthropic.json +32 -56
  57. package/dist/capabilities/anyapi.json +47 -47
  58. package/dist/capabilities/apiko.json +5 -5
  59. package/dist/capabilities/arcee.json +5 -5
  60. package/dist/capabilities/augure.json +4 -4
  61. package/dist/capabilities/auriko.json +15 -15
  62. package/dist/capabilities/bailing.json +3 -3
  63. package/dist/capabilities/baseten.json +35 -35
  64. package/dist/capabilities/bee.json +5 -5
  65. package/dist/capabilities/berget.json +2 -35
  66. package/dist/capabilities/bothub.json +14 -14
  67. package/dist/capabilities/boundless.json +39 -39
  68. package/dist/capabilities/bumo.json +40 -40
  69. package/dist/capabilities/byteplus.json +28 -28
  70. package/dist/capabilities/cheapest-token.json +31 -31
  71. package/dist/capabilities/chutes.json +48 -17
  72. package/dist/capabilities/cline-pass.json +32 -45
  73. package/dist/capabilities/cloudcode.json +8 -8
  74. package/dist/capabilities/cloudferro-sherlock.json +4 -4
  75. package/dist/capabilities/cloudflare-workers-ai.json +17 -17
  76. package/dist/capabilities/commandcode.json +141 -156
  77. package/dist/capabilities/concentrate.json +289 -289
  78. package/dist/capabilities/cortecs.json +103 -103
  79. package/dist/capabilities/crossmodel.json +194 -194
  80. package/dist/capabilities/crusoe.json +18 -18
  81. package/dist/capabilities/daoxe.json +9 -9
  82. package/dist/capabilities/databricks.json +128 -128
  83. package/dist/capabilities/deepinfra.json +98 -94
  84. package/dist/capabilities/deepseek.json +4 -4
  85. package/dist/capabilities/digitalocean.json +114 -114
  86. package/dist/capabilities/dinference.json +1 -2
  87. package/dist/capabilities/dothoosh.json +26 -26
  88. package/dist/capabilities/doubleword.json +23 -23
  89. package/dist/capabilities/edenai.json +285 -285
  90. package/dist/capabilities/empiriolabs.json +176 -167
  91. package/dist/capabilities/engy.json +16 -16
  92. package/dist/capabilities/entrim.json +8 -8
  93. package/dist/capabilities/evroc.json +15 -15
  94. package/dist/capabilities/ezkielyna.json +10 -10
  95. package/dist/capabilities/fastrouter.json +93 -97
  96. package/dist/capabilities/fireworks-ai.json +85 -85
  97. package/dist/capabilities/fortytwo.json +4 -4
  98. package/dist/capabilities/freemodel.json +7 -51
  99. package/dist/capabilities/friendli.json +8 -8
  100. package/dist/capabilities/frogbot.json +95 -103
  101. package/dist/capabilities/gisoo.json +15 -15
  102. package/dist/capabilities/gmicloud.json +21 -21
  103. package/dist/capabilities/google.json +55 -55
  104. package/dist/capabilities/graphn.json +10 -10
  105. package/dist/capabilities/greenpt.json +35 -35
  106. package/dist/capabilities/groq.json +7 -20
  107. package/dist/capabilities/helicone.json +84 -86
  108. package/dist/capabilities/hetzner.json +4 -4
  109. package/dist/capabilities/hopper.json +2 -2
  110. package/dist/capabilities/hostinger-router.json +5 -5
  111. package/dist/capabilities/hpc-ai.json +8 -24
  112. package/dist/capabilities/huawei-maas.json +13 -13
  113. package/dist/capabilities/hubris.json +30 -30
  114. package/dist/capabilities/huggingface.json +86 -101
  115. package/dist/capabilities/hyper.json +24 -24
  116. package/dist/capabilities/impossibl.json +152 -199
  117. package/dist/capabilities/inceptron.json +8 -8
  118. package/dist/capabilities/inco.json +4 -21
  119. package/dist/capabilities/infer.json +16 -16
  120. package/dist/capabilities/inferall.json +2 -18
  121. package/dist/capabilities/inference-coop.json +6 -6
  122. package/dist/capabilities/inference.json +2 -11
  123. package/dist/capabilities/inferenceapis.json +24 -24
  124. package/dist/capabilities/infersia.json +13 -13
  125. package/dist/capabilities/inferx.json +3 -3
  126. package/dist/capabilities/infomaniak.json +3 -3
  127. package/dist/capabilities/io-net.json +6 -16
  128. package/dist/capabilities/isoquant.json +4 -4
  129. package/dist/capabilities/iteracompute.json +42 -80
  130. package/dist/capabilities/jalapeno.json +11 -11
  131. package/dist/capabilities/jiekou.json +19 -167
  132. package/dist/capabilities/joingonka.json +4 -4
  133. package/dist/capabilities/jzstoken.json +54 -54
  134. package/dist/capabilities/keln.json +23 -23
  135. package/dist/capabilities/kenari.json +122 -130
  136. package/dist/capabilities/kilo.json +649 -647
  137. package/dist/capabilities/kimi-code-plan-cn.json +7 -7
  138. package/dist/capabilities/kimi-code-plan-global.json +7 -7
  139. package/dist/capabilities/kitani.json +4 -4
  140. package/dist/capabilities/klavo.json +24 -24
  141. package/dist/capabilities/korouter.json +32 -32
  142. package/dist/capabilities/kunavo.json +7 -7
  143. package/dist/capabilities/liquid.json +8 -8
  144. package/dist/capabilities/lithosai.json +3 -3
  145. package/dist/capabilities/llmgateway-providers.json +885 -893
  146. package/dist/capabilities/llmgateway.json +340 -340
  147. package/dist/capabilities/llmtr.json +16 -54
  148. package/dist/capabilities/lowrouter.json +61 -61
  149. package/dist/capabilities/lyceum.json +14 -14
  150. package/dist/capabilities/meganova.json +0 -1
  151. package/dist/capabilities/melious.json +14 -14
  152. package/dist/capabilities/merge-gateway.json +292 -292
  153. package/dist/capabilities/meta.json +11 -11
  154. package/dist/capabilities/minimax-cn-coding-plan.json +2 -2
  155. package/dist/capabilities/minimax-cn.json +5 -5
  156. package/dist/capabilities/minimax-coding-plan.json +2 -2
  157. package/dist/capabilities/minimax.json +5 -5
  158. package/dist/capabilities/mistral.json +15 -31
  159. package/dist/capabilities/mixlayer.json +5 -5
  160. package/dist/capabilities/moark.json +0 -2
  161. package/dist/capabilities/modal.json +8 -8
  162. package/dist/capabilities/model-oracle-ai.json +19 -27
  163. package/dist/capabilities/modelis.json +14 -14
  164. package/dist/capabilities/modelscope.json +2 -2
  165. package/dist/capabilities/modular.json +11 -11
  166. package/dist/capabilities/moneo.json +7 -38
  167. package/dist/capabilities/moonshotai-cn.json +7 -7
  168. package/dist/capabilities/moonshotai.json +7 -7
  169. package/dist/capabilities/morph.json +13 -13
  170. package/dist/capabilities/munito-eu.json +8 -8
  171. package/dist/capabilities/munito.json +10 -10
  172. package/dist/capabilities/nan.json +31 -31
  173. package/dist/capabilities/nano-gpt.json +581 -603
  174. package/dist/capabilities/nearai.json +119 -119
  175. package/dist/capabilities/nebius.json +30 -31
  176. package/dist/capabilities/neon.json +132 -132
  177. package/dist/capabilities/neuralwatt.json +41 -41
  178. package/dist/capabilities/nokeep.json +5 -5
  179. package/dist/capabilities/novita-ai.json +113 -227
  180. package/dist/capabilities/nvidia.json +14 -82
  181. package/dist/capabilities/oathbreaker.json +2 -2
  182. package/dist/capabilities/obscurify.json +28 -28
  183. package/dist/capabilities/oci.json +4 -4
  184. package/dist/capabilities/ofox.json +270 -270
  185. package/dist/capabilities/ollama-cloud.json +53 -53
  186. package/dist/capabilities/openai.json +57 -57
  187. package/dist/capabilities/opencode-go.json +88 -90
  188. package/dist/capabilities/openreason.json +5 -5
  189. package/dist/capabilities/openrouter.json +574 -563
  190. package/dist/capabilities/opper.json +29 -34
  191. package/dist/capabilities/orcarouter.json +307 -367
  192. package/dist/capabilities/outerlabs.json +30 -30
  193. package/dist/capabilities/ovhcloud.json +19 -19
  194. package/dist/capabilities/pareto.json +2 -7
  195. package/dist/capabilities/perplexity-agent.json +47 -102
  196. package/dist/capabilities/perplexity.json +2 -2
  197. package/dist/capabilities/phala.json +35 -35
  198. package/dist/capabilities/pioneer.json +5 -122
  199. package/dist/capabilities/poe.json +130 -130
  200. package/dist/capabilities/poolside.json +2 -2
  201. package/dist/capabilities/powerspring.json +14 -14
  202. package/dist/capabilities/primalabs.json +12 -12
  203. package/dist/capabilities/prime.json +123 -115
  204. package/dist/capabilities/privatemode-ai.json +8 -36
  205. package/dist/capabilities/proxystacks.json +5 -5
  206. package/dist/capabilities/qihang-ai.json +3 -15
  207. package/dist/capabilities/qiniu-ai.json +13 -87
  208. package/dist/capabilities/refuseless.json +7 -14
  209. package/dist/capabilities/regolo-ai.json +9 -13
  210. package/dist/capabilities/requesty.json +202 -202
  211. package/dist/capabilities/routing-run.json +3 -40
  212. package/dist/capabilities/ruapi.json +21 -21
  213. package/dist/capabilities/runcrate.json +10 -10
  214. package/dist/capabilities/runinfra.json +16 -16
  215. package/dist/capabilities/sakana.json +3 -3
  216. package/dist/capabilities/sambanova.json +9 -9
  217. package/dist/capabilities/sandbase.json +20 -20
  218. package/dist/capabilities/sarvam.json +22 -13
  219. package/dist/capabilities/scaleway.json +18 -18
  220. package/dist/capabilities/scnet-token-plan.json +7 -7
  221. package/dist/capabilities/scx-ai.json +16 -32
  222. package/dist/capabilities/sensenova.json +12 -12
  223. package/dist/capabilities/siliconflow-cn.json +45 -97
  224. package/dist/capabilities/siliconflow.json +53 -53
  225. package/dist/capabilities/snowflake-cortex.json +26 -26
  226. package/dist/capabilities/sokkan.json +8 -20
  227. package/dist/capabilities/sparrowcodes.json +21 -21
  228. package/dist/capabilities/stackit.json +1 -2
  229. package/dist/capabilities/standardcompute.json +84 -120
  230. package/dist/capabilities/steadyrouter.json +41 -41
  231. package/dist/capabilities/stepfun-ai-step-plan.json +8 -8
  232. package/dist/capabilities/stepfun-ai.json +8 -8
  233. package/dist/capabilities/stepfun-step-plan.json +8 -8
  234. package/dist/capabilities/stepfun.json +8 -8
  235. package/dist/capabilities/stepping-stone.json +15 -15
  236. package/dist/capabilities/subconscious.json +2 -2
  237. package/dist/capabilities/superbot-gg.json +4 -4
  238. package/dist/capabilities/synthetic.json +8 -17
  239. package/dist/capabilities/synthorai.json +21 -21
  240. package/dist/capabilities/teamorouter.json +23 -23
  241. package/dist/capabilities/teapot-router.json +10 -10
  242. package/dist/capabilities/tencent-token-plan-intl.json +25 -25
  243. package/dist/capabilities/tencent-token-plan.json +38 -38
  244. package/dist/capabilities/tencent-tokenhub.json +46 -46
  245. package/dist/capabilities/tensorx.json +48 -48
  246. package/dist/capabilities/tenstorrent.json +4 -4
  247. package/dist/capabilities/the-grid-ai.json +29 -29
  248. package/dist/capabilities/thinkingmachines.json +71 -71
  249. package/dist/capabilities/tinfoil.json +8 -8
  250. package/dist/capabilities/toapis.json +3 -3
  251. package/dist/capabilities/togetherai.json +42 -42
  252. package/dist/capabilities/tokengo.json +21 -21
  253. package/dist/capabilities/tokenify.json +2 -2
  254. package/dist/capabilities/trustedrouter.json +5 -5
  255. package/dist/capabilities/trustedtokens.json +15 -15
  256. package/dist/capabilities/umans-ai-coding-plan.json +16 -16
  257. package/dist/capabilities/umans-ai.json +13 -13
  258. package/dist/capabilities/uncensuredai.json +4 -4
  259. package/dist/capabilities/unorouter.json +1 -22
  260. package/dist/capabilities/unrestricted.json +4 -20
  261. package/dist/capabilities/uplinkswitch.json +21 -21
  262. package/dist/capabilities/upstage.json +3 -15
  263. package/dist/capabilities/vancine.json +20 -20
  264. package/dist/capabilities/vercel.json +551 -551
  265. package/dist/capabilities/vivgrid.json +51 -131
  266. package/dist/capabilities/volcengine-coding-plan.json +29 -29
  267. package/dist/capabilities/volcengine.json +27 -27
  268. package/dist/capabilities/vultr.json +14 -67
  269. package/dist/capabilities/wafer.ai.json +17 -17
  270. package/dist/capabilities/wallaby.json +2 -2
  271. package/dist/capabilities/wally.json +12 -12
  272. package/dist/capabilities/wandb.json +21 -21
  273. package/dist/capabilities/watt.json +22 -22
  274. package/dist/capabilities/xai.json +5 -5
  275. package/dist/capabilities/xiaomi-token-plan-ams.json +2 -2
  276. package/dist/capabilities/xiaomi-token-plan-cn.json +2 -2
  277. package/dist/capabilities/xiaomi-token-plan-sgp.json +2 -2
  278. package/dist/capabilities/xiaomi.json +2 -2
  279. package/dist/capabilities/xpersona.json +13 -13
  280. package/dist/capabilities/xxapi.json +30 -30
  281. package/dist/capabilities/zai-coding-plan.json +17 -17
  282. package/dist/capabilities/zai.json +31 -31
  283. package/dist/capabilities/zenifra.json +26 -26
  284. package/dist/capabilities/zenmux.json +190 -233
  285. package/dist/capabilities/zerogpu.json +8 -8
  286. package/dist/capabilities/zhipuai-coding-plan.json +3 -14
  287. package/dist/capabilities/zhipuai.json +30 -30
  288. package/dist/capabilities/zro.json +6 -6
  289. package/dist/channels/index.cjs +24 -24
  290. package/dist/channels/index.js +2 -2
  291. package/dist/{channels-B7lf5BnT.js → channels-BBwgs50q.js} +2 -2
  292. package/dist/{channels-CAA8MkDQ.cjs → channels-CbhgGgQD.cjs} +6 -6
  293. package/dist/coding-agent/index.cjs +7 -7
  294. package/dist/coding-agent/index.js +4 -4
  295. package/dist/{constants-CFO8w780.cjs → constants-B2FVV_2e.cjs} +1 -1
  296. package/dist/{constants-CUv0mU2y.js → constants-Dro9fuhk.js} +1 -1
  297. package/dist/datasets/index.cjs +9 -9
  298. package/dist/datasets/index.js +2 -2
  299. package/dist/docs/SKILL.md +1 -1
  300. package/dist/docs/assets/SOURCE_MAP.json +1147 -1142
  301. package/dist/docs/references/docs-agents-overview.md +9 -0
  302. package/dist/docs/references/docs-deployment-workers.md +1 -1
  303. package/dist/docs/references/docs-harness-background-tasks.md +8 -5
  304. package/dist/docs/references/docs-harness-durable-agents.md +1 -0
  305. package/dist/docs/references/docs-knowledge-search.md +1 -1
  306. package/dist/docs/references/docs-server-pubsub.md +1 -1
  307. package/dist/docs/references/docs-skills.md +4 -1
  308. package/dist/docs/references/docs-workflows-overview.md +2 -0
  309. package/dist/docs/references/reference-agent-controller-session.md +19 -0
  310. package/dist/docs/references/reference-agents-createSkill.md +20 -1
  311. package/dist/docs/references/reference-knowledge-knowledge-tools.md +1 -2
  312. package/dist/docs/references/reference-observability-metrics-metrics-context.md +63 -3
  313. package/dist/docs/references/reference-pubsub-base.md +1 -1
  314. package/dist/docs/references/reference-pubsub-redis-streams.md +3 -5
  315. package/dist/docs/references/reference-pubsub-valkey-streams.md +2 -2
  316. package/dist/docs/references/reference-templates-overview.md +31 -1
  317. package/dist/docs/references/reference-workflows-run-methods-restart.md +2 -0
  318. package/dist/evals/index.cjs +13 -13
  319. package/dist/evals/index.js +2 -2
  320. package/dist/evals/scoreTraces/index.cjs +4 -4
  321. package/dist/evals/scoreTraces/index.js +2 -2
  322. package/dist/events/index.cjs +1 -1
  323. package/dist/events/index.js +1 -1
  324. package/dist/events/pubsub.d.ts +1 -3
  325. package/dist/{run-registry-bm6b6mwQ.js → execution-fence-B8yV_n51.js} +62508 -62052
  326. package/dist/{run-registry-BaVTwGKh.cjs → execution-fence-fqV6FGdV.cjs} +63621 -63153
  327. package/dist/harness/index.cjs +3 -3
  328. package/dist/harness/index.js +3 -3
  329. package/dist/index.cjs +1 -1
  330. package/dist/index.d.ts +1 -0
  331. package/dist/index.js +1 -1
  332. package/dist/integration/index.cjs +1 -1
  333. package/dist/integration/index.js +1 -1
  334. package/dist/knowledge/index.cjs +163 -153
  335. package/dist/knowledge/index.js +18 -8
  336. package/dist/llm/index.cjs +3 -3
  337. package/dist/llm/index.js +3 -3
  338. package/dist/llm/model/gateways/opencode-session-header.d.ts +28 -0
  339. package/dist/llm/model/provider-types.generated.d.ts +7412 -7795
  340. package/dist/llm/model/resolve-model.d.ts +1 -0
  341. package/dist/llm/model/shared.types.d.ts +1 -0
  342. package/dist/{llm-CGl_FZsb.cjs → llm-B7ul27Ay.cjs} +32 -14
  343. package/dist/{llm-B5OxUmL4.js → llm-Cy3WZXgA.js} +32 -14
  344. package/dist/loop/index.cjs +15 -15
  345. package/dist/loop/index.js +2 -2
  346. package/dist/loop/server.cjs +1 -1
  347. package/dist/loop/server.js +1 -1
  348. package/dist/{manager-BuPZ97U6.cjs → manager-CY-RzZJL.cjs} +21 -19
  349. package/dist/{manager-R_QVoiy9.js → manager-Dsub5fyz.js} +9 -7
  350. package/dist/mastra/index.cjs +1 -1
  351. package/dist/mastra/index.d.ts +33 -4
  352. package/dist/mastra/index.js +1 -1
  353. package/dist/{mastra-CHYi4Woq.cjs → mastra-DXQUuwFl.cjs} +116 -67
  354. package/dist/{mastra-Cl5EC-jR.js → mastra-yjoYfTS5.js} +76 -27
  355. package/dist/memory/index.cjs +24 -24
  356. package/dist/memory/index.js +2 -2
  357. package/dist/memory/mock.d.ts +2 -3
  358. package/dist/{model-WmKuSHa8.cjs → model-BARBpXDN.cjs} +2 -2
  359. package/dist/{model-BNIR9RSw.js → model-DauH8JTo.js} +2 -2
  360. package/dist/{netlify-D4orVt-5.js → netlify-BNBtKR4Q.js} +86 -4
  361. package/dist/{netlify-C_6KLad8.cjs → netlify-DGsETiFB.cjs} +97 -3
  362. package/dist/notifications/index.cjs +18 -18
  363. package/dist/notifications/index.js +2 -2
  364. package/dist/observability/index.cjs +1 -1
  365. package/dist/observability/index.js +1 -1
  366. package/dist/{observability-D7RNOAPx.js → observability-DPDWibyH.js} +648 -648
  367. package/dist/{output-helpers-DgsH4aTb.cjs → output-helpers-By5FbLpp.cjs} +71 -73
  368. package/dist/{output-helpers-CVzhy1Y0.js → output-helpers-k2-48ssH.js} +72 -74
  369. package/dist/processor-provider/index.cjs +10 -10
  370. package/dist/processor-provider/index.js +1 -1
  371. package/dist/processors/index.cjs +65 -65
  372. package/dist/processors/index.js +2 -2
  373. package/dist/{provider-registry-CkHZ7heH.js → provider-registry-CfHy4Zhw.js} +21401 -22401
  374. package/dist/{provider-registry-DH7XbpHT.cjs → provider-registry-Y6tbfFhH.cjs} +21401 -22401
  375. package/dist/provider-registry.json +21940 -22961
  376. package/dist/{registry-generator-Dn8HU1Jz.cjs → registry-generator-BEJ0APNc.cjs} +1 -1
  377. package/dist/{registry-generator-CAXpGkmM.js → registry-generator-DJiQAI8V.js} +1 -1
  378. package/dist/{rehydrate-DZyZNbaq.cjs → rehydrate-4Sl7D3kO.cjs} +14 -14
  379. package/dist/{rehydrate-Cy7-QPU-.js → rehydrate-Da4_E_N8.js} +2 -2
  380. package/dist/relevance/index.cjs +3 -3
  381. package/dist/relevance/index.js +2 -2
  382. package/dist/{signal-provider-BslnAjWG.js → signal-provider-B_mfW-J4.js} +1 -1
  383. package/dist/{signal-provider-BFAvh_AJ.cjs → signal-provider-D9gbevHN.cjs} +1 -1
  384. package/dist/signals/index.cjs +3 -3
  385. package/dist/signals/index.js +3 -3
  386. package/dist/{signals-CbmgVwL-.cjs → signals-BwDXGqxc.cjs} +2 -2
  387. package/dist/{signals-Clupx3jz.js → signals-TznxWfM3.js} +2 -2
  388. package/dist/skills/create-skill.d.ts +3 -0
  389. package/dist/skills/index.cjs +1 -1
  390. package/dist/skills/index.js +1 -1
  391. package/dist/skills/inline-skill-source.d.ts +5 -1
  392. package/dist/skills/types.d.ts +16 -1
  393. package/dist/{source-DYZMfjv3.js → source-B3He4_mz.js} +1 -1
  394. package/dist/{source-BC8Et5qZ.cjs → source-C_nWbqI0.cjs} +1 -1
  395. package/dist/{state-processor-B9kxpM53.js → state-processor-B_KsS82m.js} +1 -1
  396. package/dist/{state-processor-kRNZ38Nf.cjs → state-processor-DaSmhVUX.cjs} +1 -1
  397. package/dist/storage/constants.cjs +1 -1
  398. package/dist/storage/constants.js +1 -1
  399. package/dist/storage/domains/agents/index.cjs +1 -1
  400. package/dist/storage/domains/agents/index.js +1 -1
  401. package/dist/storage/domains/inmemory-db.d.ts +1 -1
  402. package/dist/storage/domains/knowledge/pages.d.ts +8 -1
  403. package/dist/storage/domains/memory/base.d.ts +19 -9
  404. package/dist/storage/domains/memory/inmemory.d.ts +4 -1
  405. package/dist/storage/domains/memory/queue-thread.d.ts +7 -1
  406. package/dist/storage/domains/workflows/base.d.ts +18 -5
  407. package/dist/storage/domains/workflows/inmemory.d.ts +3 -5
  408. package/dist/storage/domains/workflows/journal.d.ts +16 -1
  409. package/dist/storage/index.cjs +187 -186
  410. package/dist/storage/index.js +6 -6
  411. package/dist/storage/workflow-snapshot.d.ts +4 -0
  412. package/dist/storage/workflow-step-guard.d.ts +5 -0
  413. package/dist/stream/base/output.d.ts +1 -0
  414. package/dist/stream/index.cjs +2 -2
  415. package/dist/stream/index.js +2 -2
  416. package/dist/{stream-B9dswdIM.js → stream-BFhCDJvz.js} +18 -8
  417. package/dist/{stream-CbG7k93m.cjs → stream-CZy8XA_q.cjs} +23 -7
  418. package/dist/telemetry/index.cjs +1 -1
  419. package/dist/telemetry/index.js +1 -1
  420. package/dist/test-utils/llm-mock.cjs +1 -1
  421. package/dist/test-utils/llm-mock.js +1 -1
  422. package/dist/{tool-Z3bykc1m.js → tool-DIFduuTw.js} +2 -5
  423. package/dist/{tool-CYlT2UA-.cjs → tool-Dn9WSDVn.cjs} +2 -5
  424. package/dist/tool-loop-agent/index.cjs +1 -1
  425. package/dist/tool-loop-agent/index.js +1 -1
  426. package/dist/{tool-loop-agent-BnlPROel.cjs → tool-loop-agent-DifR6VLI.cjs} +4 -4
  427. package/dist/{tool-loop-agent-BmlzhMxc.js → tool-loop-agent-SOpIJRws.js} +3 -3
  428. package/dist/{toolchecks-DrsZdc3S.js → toolchecks-CRAfUe9H.js} +1 -1
  429. package/dist/{toolchecks-MFU48cit.cjs → toolchecks-DbBsQGHW.cjs} +1 -1
  430. package/dist/tools/index.cjs +5 -5
  431. package/dist/tools/index.d.ts +1 -0
  432. package/dist/tools/index.js +5 -5
  433. package/dist/tools/is-vercel-tool.cjs +1 -1
  434. package/dist/tools/is-vercel-tool.js +1 -1
  435. package/dist/tools/tool.d.ts +2 -4
  436. package/dist/tools/types.d.ts +1 -0
  437. package/dist/{tools-BEYxowf0.cjs → tools-C2q0ougI.cjs} +1 -1
  438. package/dist/{tools-tPy2FwMI.js → tools-ybbz1YKg.js} +1 -1
  439. package/dist/{utils-N_OPw-9g.cjs → utils-BjFntMW_.cjs} +6 -5
  440. package/dist/{utils-BU8lpEZ4.js → utils-DN_kWhH6.js} +6 -5
  441. package/dist/utils.cjs +3 -3
  442. package/dist/utils.js +3 -3
  443. package/dist/{validate-BvxwUPNa.cjs → validate-CBQ0dMBb.cjs} +1 -1
  444. package/dist/{validate-BANPY3pi.js → validate-KIBMWuyc.js} +1 -1
  445. package/dist/vector/index.cjs +8 -8
  446. package/dist/vector/index.js +1 -1
  447. package/dist/worker/index.cjs +1 -1
  448. package/dist/worker/index.js +1 -1
  449. package/dist/{worker-BpVWGM6Q.js → worker-Bqg7bsxX.js} +8 -3
  450. package/dist/{worker-E2MdhICW.cjs → worker-CJ_JYSy0.cjs} +3 -3
  451. package/dist/{worker-B3s2DjXP.cjs → worker-Ct6E5_2p.cjs} +16 -11
  452. package/dist/{worker-CZ_07SOb.js → worker-DVM_pvH7.js} +2 -2
  453. package/dist/{workflow-BrcVks0j.js → workflow-BmShpn3p.js} +4 -4
  454. package/dist/{workflow-BuPW86ke.cjs → workflow-DEAvg0pI.cjs} +8 -8
  455. package/dist/workflows/builder/index.cjs +1 -1
  456. package/dist/workflows/builder/index.js +1 -1
  457. package/dist/workflows/evented/index.cjs +10 -10
  458. package/dist/workflows/evented/index.js +1 -1
  459. package/dist/workflows/evented/workflow-event-processor/index.d.ts +0 -2
  460. package/dist/workflows/evented/workflow.d.ts +2 -1
  461. package/dist/workflows/index.cjs +54 -54
  462. package/dist/workflows/index.js +4 -4
  463. package/dist/workflows/run-storage.d.ts +16 -1
  464. package/dist/workflows/types.d.ts +10 -0
  465. package/dist/workflows/workflow.d.ts +3 -1
  466. package/dist/workspace/index.cjs +1 -1
  467. package/dist/workspace/index.js +1 -1
  468. package/dist/{workspace-CzzrnE6Q.cjs → workspace-BQD4tcQi.cjs} +3 -3
  469. package/dist/{workspace-Ct2kAiDv.js → workspace-sqcfdZRR.js} +2 -2
  470. package/package.json +7 -6
  471. package/skills/mastra/SKILL.md +171 -0
  472. package/skills/mastra/references/common-errors.md +557 -0
  473. package/skills/mastra/references/core-concepts.md +21 -0
  474. package/skills/mastra/references/create-mastra.md +233 -0
  475. package/skills/mastra/references/embedded-docs.md +103 -0
  476. package/skills/mastra/references/feedback.md +69 -0
  477. package/skills/mastra/references/gateway.md +66 -0
  478. package/skills/mastra/references/mastra-api.md +222 -0
  479. package/skills/mastra/references/migration-guide.md +185 -0
  480. package/skills/mastra/references/model-selection.md +29 -0
  481. package/skills/mastra/references/platform.md +164 -0
  482. package/skills/mastra/references/remote-docs.md +193 -0
  483. package/skills/mastra/references/trace-query.md +150 -0
  484. package/skills/mastra/scripts/provider-registry.mjs +271 -0
  485. package/src/llm/model/provider-types.generated.d.ts +7412 -7795
  486. package/dist/{observability-B0R_D1PZ.cjs → observability-VaoaeadK.cjs} +647 -647
@@ -1,6 +1,17 @@
1
1
  const require_storage = require("./storage-CfG0I2aF.cjs");
2
2
  const require_utils = require("./utils-D-eNsgDM.cjs");
3
3
  let zod_v4 = require("zod/v4");
4
+ // src/observability/types/core.ts
5
+ /**
6
+ * Sampling strategy types
7
+ */
8
+ let SamplingStrategyType = /* @__PURE__ */ function(SamplingStrategyType) {
9
+ SamplingStrategyType["ALWAYS"] = "always";
10
+ SamplingStrategyType["NEVER"] = "never";
11
+ SamplingStrategyType["RATIO"] = "ratio";
12
+ SamplingStrategyType["CUSTOM"] = "custom";
13
+ return SamplingStrategyType;
14
+ }({});
4
15
  // src/observability/types/outcome.ts
5
16
  /** An individual execution's result, reported by its runtime (OBS-724). */
6
17
  const SPAN_OUTCOMES = [
@@ -33,671 +44,134 @@ const SPAN_STOP_REASONS = {
33
44
  authentication: true,
34
45
  authorization: true
35
46
  };
36
- // src/observability/outcome-schema.ts
37
- const label = zod_v4.z.string().max(128).optional();
38
- const reason = zod_v4.z.enum(Object.keys(SPAN_STOP_REASONS));
39
- const failure = {
40
- provider: label,
41
- errorCode: label,
42
- retryable: zod_v4.z.boolean().optional()
43
- };
44
- const cause = {
45
- causeOutcome: zod_v4.z.enum(SPAN_OUTCOMES).optional(),
46
- causeStopReason: reason.optional()
47
+ // src/observability/no-op.ts
48
+ const noOpCounter = { add() {} };
49
+ const noOpGauge = { set() {} };
50
+ const noOpHistogram = { record() {} };
51
+ /**
52
+ * No-op tracing context used when observability is not configured.
53
+ */
54
+ const noOpTracingContext = { currentSpan: void 0 };
55
+ /**
56
+ * No-op logger context that silently discards all log calls.
57
+ * Used when observability is not configured.
58
+ */
59
+ const noOpLoggerContext = {
60
+ debug() {},
61
+ info() {},
62
+ warn() {},
63
+ error() {},
64
+ fatal() {}
47
65
  };
48
- const contexts = {
49
- max_steps: zod_v4.z.strictObject({
50
- maxSteps: zod_v4.z.number().optional(),
51
- completedSteps: zod_v4.z.number().optional()
52
- }),
53
- max_tokens: zod_v4.z.strictObject({ maxTokens: zod_v4.z.number().optional() }),
54
- timeout: zod_v4.z.strictObject({
55
- timeoutMs: zod_v4.z.number().optional(),
56
- timeoutType: zod_v4.z.enum([
57
- "step",
58
- "total",
59
- "firstChunk"
60
- ]).optional()
61
- }),
62
- runtime_error: zod_v4.z.strictObject(failure),
63
- model_error: zod_v4.z.strictObject(failure),
64
- caller_cancelled: zod_v4.z.strictObject({}),
65
- observer_failed: zod_v4.z.strictObject({
66
- observerSpanId: label,
67
- ...cause
68
- }),
69
- context_window_exceeded: zod_v4.z.strictObject({
70
- provider: label,
71
- errorCode: label,
72
- contextWindow: zod_v4.z.number().optional()
73
- }),
74
- guardrail: zod_v4.z.strictObject({ processorId: label }),
75
- content_filter: zod_v4.z.strictObject({ provider: label }),
76
- approval_required: zod_v4.z.strictObject({
77
- toolCallId: label,
78
- toolName: label
79
- }),
80
- signal_received: zod_v4.z.strictObject({
81
- signalId: label,
82
- signalType: zod_v4.z.enum([
83
- "user",
84
- "state",
85
- "reactive",
86
- "notification"
87
- ]).optional()
88
- }),
89
- stop_condition: zod_v4.z.strictObject({}),
90
- iteration_hook: zod_v4.z.strictObject({ feedbackCompleted: zod_v4.z.boolean().optional() }),
91
- delegation_bail: zod_v4.z.strictObject(cause),
92
- authentication: zod_v4.z.strictObject(failure),
93
- authorization: zod_v4.z.strictObject(failure)
66
+ /**
67
+ * No-op metrics context that silently discards all metric operations.
68
+ * Used when observability is not configured.
69
+ */
70
+ const noOpMetricsContext = {
71
+ emit() {},
72
+ counter() {
73
+ return noOpCounter;
74
+ },
75
+ gauge() {
76
+ return noOpGauge;
77
+ },
78
+ histogram() {
79
+ return noOpHistogram;
80
+ }
94
81
  };
95
- /** @internal Allowlist tooltip facts for framework producers, including untyped runtime inputs. */
96
- function compactStopReasonContext(stopReason, context) {
97
- if (!stopReason || !Object.hasOwn(contexts, stopReason) || !context || typeof context !== "object") return null;
98
- try {
99
- const result = {};
100
- for (const [key, schema] of Object.entries(contexts[stopReason].shape)) {
101
- const value = context[key];
102
- const parsed = schema.safeParse(value);
103
- if (parsed.success && parsed.data !== void 0) result[key] = parsed.data;
104
- }
105
- return Object.keys(result).length ? result : null;
106
- } catch {
82
+ /** No-op observability entrypoint that silently discards all operations. */
83
+ var NoOpObservability = class {
84
+ setMastraContext(_options) {}
85
+ setLogger(_options) {}
86
+ getSelectedInstance(_options) {}
87
+ async getRecordedTrace(_args) {
107
88
  return null;
108
89
  }
109
- }
110
- function termination(stopReason) {
111
- return zod_v4.z.object({
112
- outcome: zod_v4.z.enum(SPAN_OUTCOMES),
113
- stopReason: zod_v4.z.literal(stopReason),
114
- stopReasonContext: contexts[stopReason].nullish()
115
- });
116
- }
117
- zod_v4.z.union([...Object.keys(SPAN_STOP_REASONS).map(termination), zod_v4.z.object({
118
- outcome: zod_v4.z.enum(SPAN_OUTCOMES),
119
- stopReason: zod_v4.z.null().optional(),
120
- stopReasonContext: zod_v4.z.null().optional()
121
- })]);
122
- // src/observability/execution-outcome.ts
123
- /** Read a provider's structured code without inferring a cause from diagnostic text. */
124
- function providerFailureCode(value) {
125
- if (typeof value.code === "string") return value.code;
126
- let data = value.data;
127
- if (data == null && typeof value.responseBody === "string") try {
128
- data = JSON.parse(value.responseBody);
129
- } catch {
130
- return;
90
+ async addScore(_args) {}
91
+ async addFeedback(_args) {}
92
+ registerInstance(_name, _instance, _isDefault = false) {}
93
+ getInstance(_name) {}
94
+ getDefaultInstance() {}
95
+ listInstances() {
96
+ return /* @__PURE__ */ new Map();
131
97
  }
132
- if (!data || typeof data !== "object") return void 0;
133
- const record = data;
134
- const error = record.error && typeof record.error === "object" ? record.error : record;
135
- return typeof error.code === "string" ? error.code : void 0;
136
- }
137
- /** @internal Classify explicit failure facts, including wrapped/serialized causes. Never match error-message text. */
138
- function executionFailureTermination(error, layer = "runtime_error") {
139
- try {
140
- const termination = classifyExecutionFailure(error, layer);
141
- return {
142
- ...termination,
143
- stopReasonContext: compactStopReasonContext(termination.stopReason, termination.stopReasonContext)
144
- };
145
- } catch {
146
- return {
147
- outcome: "error",
148
- stopReason: layer
149
- };
98
+ unregisterInstance(_name) {
99
+ return false;
150
100
  }
151
- }
152
- function classifyExecutionFailure(error, layer) {
153
- const seen = /* @__PURE__ */ new Set();
154
- let current = error;
155
- let failure;
156
- let modelFailure = layer === "model_error";
157
- while (current && typeof current === "object" && !seen.has(current)) {
158
- seen.add(current);
159
- const value = current;
160
- if (value.status === "failed" && value.error && typeof value.error === "object") {
161
- current = value.error;
162
- continue;
163
- }
164
- if (value.name === "TripWire" && (value.processorId === void 0 || typeof value.processorId === "string") && value.options && typeof value.options === "object" && typeof value.message === "string") {
165
- const options = value.options;
166
- return tripwireTermination({
167
- processorId: value.processorId,
168
- reason: value.message,
169
- ...options
170
- });
171
- }
172
- failure = value;
173
- if (value.name === "MastraTimeoutError" && typeof value.timeoutMs === "number") return {
174
- outcome: "limit",
175
- stopReason: "timeout",
176
- stopReasonContext: {
177
- timeoutMs: value.timeoutMs,
178
- ...value.timeoutType === "step" || value.timeoutType === "total" || value.timeoutType === "firstChunk" ? { timeoutType: value.timeoutType } : {}
179
- }
180
- };
181
- if (value.name === "FGADeniedError") return {
182
- outcome: "blocked",
183
- stopReason: "authorization"
184
- };
185
- const apiError = value[Symbol.for("vercel.ai.error.AI_APICallError")] === true || value.name === "AI_APICallError";
186
- if (apiError) modelFailure = true;
187
- if (apiError && (value.statusCode === 401 || value.statusCode === 403)) return {
188
- outcome: "blocked",
189
- stopReason: value.statusCode === 401 ? "authentication" : "authorization",
190
- stopReasonContext: {
191
- errorCode: String(value.statusCode),
192
- provider: typeof value.provider === "string" ? value.provider : void 0
193
- }
194
- };
195
- if (apiError) {
196
- const errorCode = providerFailureCode(value);
197
- if (errorCode === "content_filter") return {
198
- outcome: "blocked",
199
- stopReason: "content_filter",
200
- stopReasonContext: { provider: typeof value.provider === "string" ? value.provider : void 0 }
201
- };
202
- if (errorCode === "context_length_exceeded" || errorCode === "context_window_exceeded") return {
203
- outcome: "limit",
204
- stopReason: "context_window_exceeded",
205
- stopReasonContext: { errorCode }
206
- };
207
- }
208
- current = value.cause;
101
+ hasInstance(_name) {
102
+ return false;
209
103
  }
104
+ setConfigSelector(_selector) {}
105
+ clear() {}
106
+ async flush() {}
107
+ async shutdown() {}
108
+ };
109
+ // src/observability/w3c.ts
110
+ /**
111
+ * W3C Trace Context `traceparent` parsing and formatting.
112
+ * @see https://www.w3.org/TR/trace-context/#traceparent-header
113
+ */
114
+ const TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
115
+ /** Parses a W3C `traceparent`. Values that aren't strings, are malformed, or use all-zero IDs yield `null`. */
116
+ function parseTraceparent(value) {
117
+ if (typeof value !== "string") return null;
118
+ const match = TRACEPARENT_RE.exec(value.trim());
119
+ if (!match) return null;
120
+ const [, version, traceId, spanId, flags] = match;
121
+ if (version === "ff" || /^0+$/.test(traceId) || /^0+$/.test(spanId)) return null;
210
122
  return {
211
- outcome: "error",
212
- stopReason: modelFailure ? "model_error" : "runtime_error",
213
- stopReasonContext: {
214
- provider: typeof failure?.provider === "string" ? failure.provider : void 0,
215
- errorCode: typeof failure?.code === "string" ? failure.code : typeof failure?.id === "string" ? failure.id : void 0,
216
- retryable: typeof failure?.isRetryable === "boolean" ? failure.isRetryable : void 0
217
- }
218
- };
219
- }
220
- /** Link to the observer's diagnostics without copying its payload into the interrupted span. */
221
- function tripwireTermination(tripwire) {
222
- try {
223
- const metadata = tripwire?.metadata;
224
- const observer = metadata && typeof metadata === "object" && "observerFailure" in metadata ? metadata.observerFailure : void 0;
225
- if (observer && typeof observer === "object" && "cause" in observer && observer.cause && typeof observer.cause === "object") {
226
- const cause = observer.cause;
227
- if (SPAN_OUTCOMES.includes(cause.outcome) && cause.outcome !== "success" && cause.outcome !== "suspend") return {
228
- outcome: "interrupted",
229
- stopReason: "observer_failed",
230
- stopReasonContext: compactStopReasonContext("observer_failed", {
231
- observerSpanId: "observerSpanId" in observer ? observer.observerSpanId : void 0,
232
- causeOutcome: cause.outcome,
233
- causeStopReason: typeof cause.stopReason === "string" && Object.hasOwn(SPAN_STOP_REASONS, cause.stopReason) ? cause.stopReason : void 0
234
- })
235
- };
236
- }
237
- return {
238
- outcome: "blocked",
239
- stopReason: "guardrail",
240
- stopReasonContext: compactStopReasonContext("guardrail", { processorId: tripwire?.processorId })
241
- };
242
- } catch {
243
- return {
244
- outcome: "blocked",
245
- stopReason: "guardrail"
246
- };
247
- }
248
- }
249
- // src/loop/shared/execution-outcome.ts
250
- /**
251
- * @internal
252
- * Classify a settled agent loop using its runtime stop boundary. A provider
253
- * finish reason refines the result; it cannot establish successful execution
254
- * without a continuation decision. Call only after finish-time work succeeds.
255
- */
256
- function agentLoopTermination(input) {
257
- const { stopCause, finishReason, maxSteps, tripwire } = input;
258
- if (tripwire || finishReason === "tripwire") return tripwireTermination(tripwire);
259
- if (finishReason === "suspended") {
260
- const suspension = input.suspension;
261
- if (suspension?.approvalRequired) return {
262
- outcome: "suspend",
263
- stopReason: "approval_required",
264
- stopReasonContext: compactStopReasonContext("approval_required", {
265
- toolCallId: suspension.toolCallId,
266
- toolName: suspension.toolName
267
- })
268
- };
269
- return {
270
- outcome: "suspend",
271
- stopReason: null,
272
- stopReasonContext: null
273
- };
274
- }
275
- if (finishReason === "length") return {
276
- outcome: "limit",
277
- stopReason: "max_tokens"
278
- };
279
- if (finishReason === "content-filter") return {
280
- outcome: "blocked",
281
- stopReason: "content_filter"
282
- };
283
- if (finishReason === "abort" || finishReason === "aborted") return {
284
- outcome: "abort",
285
- stopReason: "caller_cancelled"
286
- };
287
- if (finishReason === "error") return {
288
- outcome: "error",
289
- stopReason: "model_error"
290
- };
291
- switch (stopCause) {
292
- case "max_steps": return {
293
- outcome: "limit",
294
- stopReason: "max_steps",
295
- stopReasonContext: { maxSteps }
296
- };
297
- case "stop_condition": return {
298
- outcome: "success",
299
- stopReason: "stop_condition"
300
- };
301
- case "iteration_hook":
302
- case "feedback_complete": return {
303
- outcome: "success",
304
- stopReason: "iteration_hook",
305
- stopReasonContext: { feedbackCompleted: stopCause === "feedback_complete" }
306
- };
307
- case "delegation":
308
- if (input.delegationFailure) return {
309
- outcome: "interrupted",
310
- stopReason: "delegation_bail",
311
- stopReasonContext: {
312
- causeOutcome: input.delegationFailure.outcome,
313
- causeStopReason: input.delegationFailure.stopReason ?? void 0
314
- }
315
- };
316
- return {
317
- outcome: "success",
318
- stopReason: "delegation_bail"
319
- };
320
- case "model_finished": if (finishReason === "stop" || finishReason === "tool-calls") return {
321
- outcome: "success",
322
- stopReason: null,
323
- stopReasonContext: null
324
- };
325
- }
326
- return {
327
- outcome: "unknown",
328
- stopReason: null,
329
- stopReasonContext: null
123
+ version,
124
+ traceId,
125
+ spanId,
126
+ flags
330
127
  };
331
128
  }
332
- // src/observability/no-op.ts
333
- const noOpCounter = { add() {} };
334
- const noOpGauge = { set() {} };
335
- const noOpHistogram = { record() {} };
336
- /**
337
- * No-op tracing context used when observability is not configured.
338
- */
339
- const noOpTracingContext = { currentSpan: void 0 };
340
- /**
341
- * No-op logger context that silently discards all log calls.
342
- * Used when observability is not configured.
343
- */
344
- const noOpLoggerContext = {
345
- debug() {},
346
- info() {},
347
- warn() {},
348
- error() {},
349
- fatal() {}
350
- };
351
- /**
352
- * No-op metrics context that silently discards all metric operations.
353
- * Used when observability is not configured.
354
- */
355
- const noOpMetricsContext = {
356
- emit() {},
357
- counter() {
358
- return noOpCounter;
359
- },
360
- gauge() {
361
- return noOpGauge;
362
- },
363
- histogram() {
364
- return noOpHistogram;
365
- }
366
- };
367
- /** No-op observability entrypoint that silently discards all operations. */
368
- var NoOpObservability = class {
369
- setMastraContext(_options) {}
370
- setLogger(_options) {}
371
- getSelectedInstance(_options) {}
372
- async getRecordedTrace(_args) {
373
- return null;
374
- }
375
- async addScore(_args) {}
376
- async addFeedback(_args) {}
377
- registerInstance(_name, _instance, _isDefault = false) {}
378
- getInstance(_name) {}
379
- getDefaultInstance() {}
380
- listInstances() {
381
- return /* @__PURE__ */ new Map();
382
- }
383
- unregisterInstance(_name) {
384
- return false;
385
- }
386
- hasInstance(_name) {
387
- return false;
388
- }
389
- setConfigSelector(_selector) {}
390
- clear() {}
391
- async flush() {}
392
- async shutdown() {}
393
- };
394
- // src/observability/context-factory.ts
395
- /**
396
- * Derives a LoggerContext from the current span's ObservabilityInstance.
397
- * Falls back to no-op when there is no span or the instance doesn't support logging.
398
- */
399
- function deriveLoggerContext(tracing) {
400
- const span = tracing.currentSpan;
401
- return span?.observabilityInstance?.getLoggerContext?.(span) ?? noOpLoggerContext;
129
+ /** Formats a W3C `traceparent` for a span. */
130
+ function formatTraceparent(traceId, spanId, sampled) {
131
+ return `00-${traceId}-${spanId}-${sampled ? "01" : "00"}`;
402
132
  }
133
+ // src/observability/processor-span-record.ts
134
+ /** Phase names as they are shown to a reader. */
135
+ const PROCESSOR_PHASE_LABELS = {
136
+ input: "Input",
137
+ inputStep: "Input step",
138
+ llmRequest: "LLM request",
139
+ llmResponse: "LLM response",
140
+ outputStream: "Output stream",
141
+ outputResult: "Output result",
142
+ outputStep: "Output step",
143
+ toolResult: "Tool result",
144
+ requestError: "Request error"
145
+ };
403
146
  /**
404
- * Derives a MetricsContext from the current span's ObservabilityInstance.
405
- * Falls back to no-op when there is no span or the instance doesn't support metrics.
147
+ * The phase a processor span recorded, or `undefined` when it recorded none.
148
+ *
149
+ * Read from `attributes` rather than `spanType`, so a processor that retyped
150
+ * its span (`Processor.spanType`) still describes its payloads — the runner
151
+ * writes the same shapes either way. Spans stored before the attribute existed,
152
+ * and spans a newer version wrote with a phase this one does not know, return
153
+ * `undefined` and fall back to JSON.
406
154
  */
407
- function deriveMetricsContext(tracing) {
408
- const span = tracing.currentSpan;
409
- return span?.observabilityInstance?.getMetricsContext?.(span) ?? noOpMetricsContext;
155
+ function describeProcessorPhase(span) {
156
+ const phase = span.attributes?.processorPhase;
157
+ return typeof phase === "string" && Object.hasOwn(PROCESSOR_PHASE_LABELS, phase) ? phase : void 0;
410
158
  }
411
159
  /**
412
- * Creates an observability context with real or no-op implementations for
413
- * tracing, logging, and metrics.
414
- *
415
- * When a TracingContext with a current span is provided, the logger and metrics
416
- * contexts are derived from the span's ObservabilityInstance so that log entries
417
- * and metric data points are automatically correlated to the active trace.
160
+ * Tags a processor payload with the phase that recorded it.
418
161
  *
419
- * @param tracingContext - TracingContext with current span, or undefined for no-op
420
- * @returns ObservabilityContext with all three signals (tracing, logger, metrics)
162
+ * The payload itself is not validated, matching what `isSpanRecordOfType` and
163
+ * the other `describeSpan*` helpers already do: the typed view trusts that the
164
+ * producer for a phase wrote the shape core declares. Renderers guard each
165
+ * field they read, so a partially populated span shows what it has rather than
166
+ * losing the whole view to one unexpected value.
421
167
  */
422
- function createObservabilityContext(tracingContext) {
423
- const tracing = tracingContext ?? noOpTracingContext;
168
+ function describeProcessorPayload(span, data) {
169
+ const phase = describeProcessorPhase(span);
170
+ if (!phase || Object.keys(data).length === 0) return void 0;
424
171
  return {
425
- tracing,
426
- loggerVNext: deriveLoggerContext(tracing),
427
- metrics: deriveMetricsContext(tracing),
428
- tracingContext: tracing
429
- };
430
- }
431
- /**
432
- * Resolves a partial observability context (from execute params) into a
433
- * complete ObservabilityContext with no-op defaults for any missing fields.
434
- *
435
- * Explicitly provided logger/metrics contexts are preserved (e.g. when set
436
- * upstream). When missing, they are derived from the tracing context's span,
437
- * following the same derivation logic as createObservabilityContext().
438
- *
439
- * @param partial - Partial context from ExecuteFunctionParams
440
- * @returns Complete ObservabilityContext
441
- */
442
- function resolveObservabilityContext(partial) {
443
- const tracing = partial.tracing ?? partial.tracingContext ?? noOpTracingContext;
444
- return {
445
- tracing,
446
- loggerVNext: partial.loggerVNext ?? deriveLoggerContext(tracing),
447
- metrics: partial.metrics ?? deriveMetricsContext(tracing),
448
- tracingContext: tracing
449
- };
450
- }
451
- // src/observability/context.ts
452
- const AGENT_GETTERS = ["getAgent", "getAgentById"];
453
- const AGENT_METHODS_TO_WRAP = [
454
- "generate",
455
- "stream",
456
- "generateLegacy",
457
- "streamLegacy"
458
- ];
459
- const WORKFLOW_GETTERS = ["getWorkflow", "getWorkflowById"];
460
- const WORKFLOW_METHODS_TO_WRAP = [
461
- "execute",
462
- "createRun",
463
- "createRun"
464
- ];
465
- /**
466
- * Maps a tracing proxy back to the instance it wraps. `wrapMastra` returns a
467
- * Proxy that forwards property reads but is a distinct object identity from its
468
- * target, so identity-sensitive lookups keyed on the Mastra instance would treat
469
- * the proxy as a different Mastra. Cycles are impossible: a proxy's recorded
470
- * target always existed before the proxy was created.
471
- */
472
- const tracingProxyTargets = /* @__PURE__ */ new WeakMap();
473
- /**
474
- * Helper function to detect NoOp spans to avoid unnecessary wrapping
475
- */
476
- function isNoOpSpan(span) {
477
- return span.constructor.name === "NoOpSpan" || span.__isNoOp === true;
478
- }
479
- /**
480
- * Checks to see if a passed object is an actual instance of Mastra
481
- * (for the purposes of wrapping it for Tracing)
482
- */
483
- function isMastra(mastra) {
484
- const hasAgentGetters = AGENT_GETTERS.every((method) => typeof mastra?.[method] === "function");
485
- const hasWorkflowGetters = WORKFLOW_GETTERS.every((method) => typeof mastra?.[method] === "function");
486
- return hasAgentGetters && hasWorkflowGetters;
487
- }
488
- /**
489
- * Creates a tracing-aware Mastra proxy that automatically injects
490
- * tracing context into agent and workflow method calls
491
- */
492
- function wrapMastra(mastra, tracingContext) {
493
- if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) return mastra;
494
- if (!isMastra(mastra)) return mastra;
495
- try {
496
- const proxy = new Proxy(mastra, { get(target, prop) {
497
- try {
498
- if (AGENT_GETTERS.includes(prop)) return (...args) => {
499
- return wrapAgent(target[prop](...args), tracingContext);
500
- };
501
- if (WORKFLOW_GETTERS.includes(prop)) return (...args) => {
502
- return wrapWorkflow(target[prop](...args), tracingContext);
503
- };
504
- const value = target[prop];
505
- return typeof value === "function" ? value.bind(target) : value;
506
- } catch (error) {
507
- console.warn("Tracing: Failed to wrap method, falling back to original", error);
508
- const value = target[prop];
509
- return typeof value === "function" ? value.bind(target) : value;
510
- }
511
- } });
512
- tracingProxyTargets.set(proxy, mastra);
513
- return proxy;
514
- } catch (error) {
515
- console.warn("Tracing: Failed to create proxy, using original Mastra instance", error);
516
- return mastra;
517
- }
518
- }
519
- /**
520
- * Resolve a tracing proxy back to the underlying instance. Returns the argument
521
- * unchanged when it is not a proxy this module created. Transitive: a tool
522
- * executed inside a traced workflow step receives an already-wrapped mastra and
523
- * `tools/tool-builder/builder.ts` wraps it again, so nesting is real.
524
- */
525
- function unwrapMastraTracingProxy(mastra) {
526
- let current = mastra;
527
- let target = tracingProxyTargets.get(current);
528
- while (target) {
529
- current = target;
530
- target = tracingProxyTargets.get(current);
531
- }
532
- return current;
533
- }
534
- /**
535
- * Creates a tracing-aware Agent proxy that automatically injects
536
- * tracing context into generation method calls
537
- */
538
- function wrapAgent(agent, tracingContext) {
539
- if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) return agent;
540
- try {
541
- return new Proxy(agent, { get(target, prop) {
542
- try {
543
- if (AGENT_METHODS_TO_WRAP.includes(prop)) return (input, options = {}) => {
544
- return target[prop](input, {
545
- ...options,
546
- ...createObservabilityContext(tracingContext)
547
- });
548
- };
549
- const value = target[prop];
550
- return typeof value === "function" ? value.bind(target) : value;
551
- } catch (error) {
552
- console.warn("Tracing: Failed to wrap agent method, falling back to original", error);
553
- const value = target[prop];
554
- return typeof value === "function" ? value.bind(target) : value;
555
- }
556
- } });
557
- } catch (error) {
558
- console.warn("Tracing: Failed to create agent proxy, using original instance", error);
559
- return agent;
560
- }
561
- }
562
- /**
563
- * Creates a tracing-aware Workflow proxy that automatically injects
564
- * tracing context into execution method calls
565
- */
566
- function wrapWorkflow(workflow, tracingContext) {
567
- if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) return workflow;
568
- try {
569
- return new Proxy(workflow, { get(target, prop) {
570
- try {
571
- if (WORKFLOW_METHODS_TO_WRAP.includes(prop)) {
572
- if (prop === "createRun" || prop === "createRun") return async (options = {}) => {
573
- const run = await target[prop](options);
574
- return run ? wrapRun(run, tracingContext) : run;
575
- };
576
- return (input, options = {}) => {
577
- return target[prop](input, {
578
- ...options,
579
- ...createObservabilityContext(tracingContext)
580
- });
581
- };
582
- }
583
- const value = target[prop];
584
- return typeof value === "function" ? value.bind(target) : value;
585
- } catch (error) {
586
- console.warn("Tracing: Failed to wrap workflow method, falling back to original", error);
587
- const value = target[prop];
588
- return typeof value === "function" ? value.bind(target) : value;
589
- }
590
- } });
591
- } catch (error) {
592
- console.warn("Tracing: Failed to create workflow proxy, using original instance", error);
593
- return workflow;
594
- }
595
- }
596
- /**
597
- * Creates a tracing-aware Run proxy that automatically injects
598
- * tracing context into start method calls
599
- */
600
- function wrapRun(run, tracingContext) {
601
- if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) return run;
602
- try {
603
- return new Proxy(run, { get(target, prop) {
604
- try {
605
- if (prop === "start") return (startOptions = {}) => {
606
- return target.start({
607
- ...startOptions,
608
- ...createObservabilityContext(startOptions.tracingContext ?? tracingContext)
609
- });
610
- };
611
- const value = target[prop];
612
- return typeof value === "function" ? value.bind(target) : value;
613
- } catch (error) {
614
- console.warn("Tracing: Failed to wrap run method, falling back to original", error);
615
- const value = target[prop];
616
- return typeof value === "function" ? value.bind(target) : value;
617
- }
618
- } });
619
- } catch (error) {
620
- console.warn("Tracing: Failed to create run proxy, using original instance", error);
621
- return run;
622
- }
623
- }
624
- // src/observability/types/core.ts
625
- /**
626
- * Sampling strategy types
627
- */
628
- let SamplingStrategyType = /* @__PURE__ */ function(SamplingStrategyType) {
629
- SamplingStrategyType["ALWAYS"] = "always";
630
- SamplingStrategyType["NEVER"] = "never";
631
- SamplingStrategyType["RATIO"] = "ratio";
632
- SamplingStrategyType["CUSTOM"] = "custom";
633
- return SamplingStrategyType;
634
- }({});
635
- // src/observability/w3c.ts
636
- /**
637
- * W3C Trace Context `traceparent` parsing and formatting.
638
- * @see https://www.w3.org/TR/trace-context/#traceparent-header
639
- */
640
- const TRACEPARENT_RE = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/;
641
- /** Parses a W3C `traceparent`. Values that aren't strings, are malformed, or use all-zero IDs yield `null`. */
642
- function parseTraceparent(value) {
643
- if (typeof value !== "string") return null;
644
- const match = TRACEPARENT_RE.exec(value.trim());
645
- if (!match) return null;
646
- const [, version, traceId, spanId, flags] = match;
647
- if (version === "ff" || /^0+$/.test(traceId) || /^0+$/.test(spanId)) return null;
648
- return {
649
- version,
650
- traceId,
651
- spanId,
652
- flags
653
- };
654
- }
655
- /** Formats a W3C `traceparent` for a span. */
656
- function formatTraceparent(traceId, spanId, sampled) {
657
- return `00-${traceId}-${spanId}-${sampled ? "01" : "00"}`;
658
- }
659
- // src/observability/processor-span-record.ts
660
- /** Phase names as they are shown to a reader. */
661
- const PROCESSOR_PHASE_LABELS = {
662
- input: "Input",
663
- inputStep: "Input step",
664
- llmRequest: "LLM request",
665
- llmResponse: "LLM response",
666
- outputStream: "Output stream",
667
- outputResult: "Output result",
668
- outputStep: "Output step",
669
- toolResult: "Tool result",
670
- requestError: "Request error"
671
- };
672
- /**
673
- * The phase a processor span recorded, or `undefined` when it recorded none.
674
- *
675
- * Read from `attributes` rather than `spanType`, so a processor that retyped
676
- * its span (`Processor.spanType`) still describes its payloads — the runner
677
- * writes the same shapes either way. Spans stored before the attribute existed,
678
- * and spans a newer version wrote with a phase this one does not know, return
679
- * `undefined` and fall back to JSON.
680
- */
681
- function describeProcessorPhase(span) {
682
- const phase = span.attributes?.processorPhase;
683
- return typeof phase === "string" && Object.hasOwn(PROCESSOR_PHASE_LABELS, phase) ? phase : void 0;
684
- }
685
- /**
686
- * Tags a processor payload with the phase that recorded it.
687
- *
688
- * The payload itself is not validated, matching what `isSpanRecordOfType` and
689
- * the other `describeSpan*` helpers already do: the typed view trusts that the
690
- * producer for a phase wrote the shape core declares. Renderers guard each
691
- * field they read, so a partially populated span shows what it has rather than
692
- * losing the whole view to one unexpected value.
693
- */
694
- function describeProcessorPayload(span, data) {
695
- const phase = describeProcessorPhase(span);
696
- if (!phase || Object.keys(data).length === 0) return void 0;
697
- return {
698
- phase,
699
- phaseLabel: PROCESSOR_PHASE_LABELS[phase],
700
- data
172
+ phase,
173
+ phaseLabel: PROCESSOR_PHASE_LABELS[phase],
174
+ data
701
175
  };
702
176
  }
703
177
  /** The `input` a processor span recorded, tagged by the phase that produced it. */
@@ -915,6 +389,236 @@ const isSpanErrorInfo = (value) => isRecord(value) && typeof value.message === "
915
389
  function describeSpanError(span) {
916
390
  return isSpanErrorInfo(span.error) ? span.error : void 0;
917
391
  }
392
+ // src/observability/context-factory.ts
393
+ /**
394
+ * Derives a LoggerContext from the current span's ObservabilityInstance.
395
+ * Falls back to no-op when there is no span or the instance doesn't support logging.
396
+ */
397
+ function deriveLoggerContext(tracing) {
398
+ const span = tracing.currentSpan;
399
+ return span?.observabilityInstance?.getLoggerContext?.(span) ?? noOpLoggerContext;
400
+ }
401
+ /**
402
+ * Derives a MetricsContext from the current span's ObservabilityInstance.
403
+ * Falls back to no-op when there is no span or the instance doesn't support metrics.
404
+ */
405
+ function deriveMetricsContext(tracing) {
406
+ const span = tracing.currentSpan;
407
+ return span?.observabilityInstance?.getMetricsContext?.(span) ?? noOpMetricsContext;
408
+ }
409
+ /**
410
+ * Creates an observability context with real or no-op implementations for
411
+ * tracing, logging, and metrics.
412
+ *
413
+ * When a TracingContext with a current span is provided, the logger and metrics
414
+ * contexts are derived from the span's ObservabilityInstance so that log entries
415
+ * and metric data points are automatically correlated to the active trace.
416
+ *
417
+ * @param tracingContext - TracingContext with current span, or undefined for no-op
418
+ * @returns ObservabilityContext with all three signals (tracing, logger, metrics)
419
+ */
420
+ function createObservabilityContext(tracingContext) {
421
+ const tracing = tracingContext ?? noOpTracingContext;
422
+ return {
423
+ tracing,
424
+ loggerVNext: deriveLoggerContext(tracing),
425
+ metrics: deriveMetricsContext(tracing),
426
+ tracingContext: tracing
427
+ };
428
+ }
429
+ /**
430
+ * Resolves a partial observability context (from execute params) into a
431
+ * complete ObservabilityContext with no-op defaults for any missing fields.
432
+ *
433
+ * Explicitly provided logger/metrics contexts are preserved (e.g. when set
434
+ * upstream). When missing, they are derived from the tracing context's span,
435
+ * following the same derivation logic as createObservabilityContext().
436
+ *
437
+ * @param partial - Partial context from ExecuteFunctionParams
438
+ * @returns Complete ObservabilityContext
439
+ */
440
+ function resolveObservabilityContext(partial) {
441
+ const tracing = partial.tracing ?? partial.tracingContext ?? noOpTracingContext;
442
+ return {
443
+ tracing,
444
+ loggerVNext: partial.loggerVNext ?? deriveLoggerContext(tracing),
445
+ metrics: partial.metrics ?? deriveMetricsContext(tracing),
446
+ tracingContext: tracing
447
+ };
448
+ }
449
+ // src/observability/context.ts
450
+ const AGENT_GETTERS = ["getAgent", "getAgentById"];
451
+ const AGENT_METHODS_TO_WRAP = [
452
+ "generate",
453
+ "stream",
454
+ "generateLegacy",
455
+ "streamLegacy"
456
+ ];
457
+ const WORKFLOW_GETTERS = ["getWorkflow", "getWorkflowById"];
458
+ const WORKFLOW_METHODS_TO_WRAP = [
459
+ "execute",
460
+ "createRun",
461
+ "createRun"
462
+ ];
463
+ /**
464
+ * Maps a tracing proxy back to the instance it wraps. `wrapMastra` returns a
465
+ * Proxy that forwards property reads but is a distinct object identity from its
466
+ * target, so identity-sensitive lookups keyed on the Mastra instance would treat
467
+ * the proxy as a different Mastra. Cycles are impossible: a proxy's recorded
468
+ * target always existed before the proxy was created.
469
+ */
470
+ const tracingProxyTargets = /* @__PURE__ */ new WeakMap();
471
+ /**
472
+ * Helper function to detect NoOp spans to avoid unnecessary wrapping
473
+ */
474
+ function isNoOpSpan(span) {
475
+ return span.constructor.name === "NoOpSpan" || span.__isNoOp === true;
476
+ }
477
+ /**
478
+ * Checks to see if a passed object is an actual instance of Mastra
479
+ * (for the purposes of wrapping it for Tracing)
480
+ */
481
+ function isMastra(mastra) {
482
+ const hasAgentGetters = AGENT_GETTERS.every((method) => typeof mastra?.[method] === "function");
483
+ const hasWorkflowGetters = WORKFLOW_GETTERS.every((method) => typeof mastra?.[method] === "function");
484
+ return hasAgentGetters && hasWorkflowGetters;
485
+ }
486
+ /**
487
+ * Creates a tracing-aware Mastra proxy that automatically injects
488
+ * tracing context into agent and workflow method calls
489
+ */
490
+ function wrapMastra(mastra, tracingContext) {
491
+ if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) return mastra;
492
+ if (!isMastra(mastra)) return mastra;
493
+ try {
494
+ const proxy = new Proxy(mastra, { get(target, prop) {
495
+ try {
496
+ if (AGENT_GETTERS.includes(prop)) return (...args) => {
497
+ return wrapAgent(target[prop](...args), tracingContext);
498
+ };
499
+ if (WORKFLOW_GETTERS.includes(prop)) return (...args) => {
500
+ return wrapWorkflow(target[prop](...args), tracingContext);
501
+ };
502
+ const value = target[prop];
503
+ return typeof value === "function" ? value.bind(target) : value;
504
+ } catch (error) {
505
+ console.warn("Tracing: Failed to wrap method, falling back to original", error);
506
+ const value = target[prop];
507
+ return typeof value === "function" ? value.bind(target) : value;
508
+ }
509
+ } });
510
+ tracingProxyTargets.set(proxy, mastra);
511
+ return proxy;
512
+ } catch (error) {
513
+ console.warn("Tracing: Failed to create proxy, using original Mastra instance", error);
514
+ return mastra;
515
+ }
516
+ }
517
+ /**
518
+ * Resolve a tracing proxy back to the underlying instance. Returns the argument
519
+ * unchanged when it is not a proxy this module created. Transitive: a tool
520
+ * executed inside a traced workflow step receives an already-wrapped mastra and
521
+ * `tools/tool-builder/builder.ts` wraps it again, so nesting is real.
522
+ */
523
+ function unwrapMastraTracingProxy(mastra) {
524
+ let current = mastra;
525
+ let target = tracingProxyTargets.get(current);
526
+ while (target) {
527
+ current = target;
528
+ target = tracingProxyTargets.get(current);
529
+ }
530
+ return current;
531
+ }
532
+ /**
533
+ * Creates a tracing-aware Agent proxy that automatically injects
534
+ * tracing context into generation method calls
535
+ */
536
+ function wrapAgent(agent, tracingContext) {
537
+ if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) return agent;
538
+ try {
539
+ return new Proxy(agent, { get(target, prop) {
540
+ try {
541
+ if (AGENT_METHODS_TO_WRAP.includes(prop)) return (input, options = {}) => {
542
+ return target[prop](input, {
543
+ ...options,
544
+ ...createObservabilityContext(tracingContext)
545
+ });
546
+ };
547
+ const value = target[prop];
548
+ return typeof value === "function" ? value.bind(target) : value;
549
+ } catch (error) {
550
+ console.warn("Tracing: Failed to wrap agent method, falling back to original", error);
551
+ const value = target[prop];
552
+ return typeof value === "function" ? value.bind(target) : value;
553
+ }
554
+ } });
555
+ } catch (error) {
556
+ console.warn("Tracing: Failed to create agent proxy, using original instance", error);
557
+ return agent;
558
+ }
559
+ }
560
+ /**
561
+ * Creates a tracing-aware Workflow proxy that automatically injects
562
+ * tracing context into execution method calls
563
+ */
564
+ function wrapWorkflow(workflow, tracingContext) {
565
+ if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) return workflow;
566
+ try {
567
+ return new Proxy(workflow, { get(target, prop) {
568
+ try {
569
+ if (WORKFLOW_METHODS_TO_WRAP.includes(prop)) {
570
+ if (prop === "createRun" || prop === "createRun") return async (options = {}) => {
571
+ const run = await target[prop](options);
572
+ return run ? wrapRun(run, tracingContext) : run;
573
+ };
574
+ return (input, options = {}) => {
575
+ return target[prop](input, {
576
+ ...options,
577
+ ...createObservabilityContext(tracingContext)
578
+ });
579
+ };
580
+ }
581
+ const value = target[prop];
582
+ return typeof value === "function" ? value.bind(target) : value;
583
+ } catch (error) {
584
+ console.warn("Tracing: Failed to wrap workflow method, falling back to original", error);
585
+ const value = target[prop];
586
+ return typeof value === "function" ? value.bind(target) : value;
587
+ }
588
+ } });
589
+ } catch (error) {
590
+ console.warn("Tracing: Failed to create workflow proxy, using original instance", error);
591
+ return workflow;
592
+ }
593
+ }
594
+ /**
595
+ * Creates a tracing-aware Run proxy that automatically injects
596
+ * tracing context into start method calls
597
+ */
598
+ function wrapRun(run, tracingContext) {
599
+ if (!tracingContext.currentSpan || isNoOpSpan(tracingContext.currentSpan)) return run;
600
+ try {
601
+ return new Proxy(run, { get(target, prop) {
602
+ try {
603
+ if (prop === "start") return (startOptions = {}) => {
604
+ return target.start({
605
+ ...startOptions,
606
+ ...createObservabilityContext(startOptions.tracingContext ?? tracingContext)
607
+ });
608
+ };
609
+ const value = target[prop];
610
+ return typeof value === "function" ? value.bind(target) : value;
611
+ } catch (error) {
612
+ console.warn("Tracing: Failed to wrap run method, falling back to original", error);
613
+ const value = target[prop];
614
+ return typeof value === "function" ? value.bind(target) : value;
615
+ }
616
+ } });
617
+ } catch (error) {
618
+ console.warn("Tracing: Failed to create run proxy, using original instance", error);
619
+ return run;
620
+ }
621
+ }
918
622
  // src/observability/rag-ingestion.ts
919
623
  /**
920
624
  * RAG ingestion helpers.
@@ -1342,6 +1046,302 @@ function buildSpanPreviews(span) {
1342
1046
  errorPreview: error
1343
1047
  };
1344
1048
  }
1049
+ // src/observability/outcome-schema.ts
1050
+ const label = zod_v4.z.string().max(128).optional();
1051
+ const reason = zod_v4.z.enum(Object.keys(SPAN_STOP_REASONS));
1052
+ const failure = {
1053
+ provider: label,
1054
+ errorCode: label,
1055
+ retryable: zod_v4.z.boolean().optional()
1056
+ };
1057
+ const cause = {
1058
+ causeOutcome: zod_v4.z.enum(SPAN_OUTCOMES).optional(),
1059
+ causeStopReason: reason.optional()
1060
+ };
1061
+ const contexts = {
1062
+ max_steps: zod_v4.z.strictObject({
1063
+ maxSteps: zod_v4.z.number().optional(),
1064
+ completedSteps: zod_v4.z.number().optional()
1065
+ }),
1066
+ max_tokens: zod_v4.z.strictObject({ maxTokens: zod_v4.z.number().optional() }),
1067
+ timeout: zod_v4.z.strictObject({
1068
+ timeoutMs: zod_v4.z.number().optional(),
1069
+ timeoutType: zod_v4.z.enum([
1070
+ "step",
1071
+ "total",
1072
+ "firstChunk"
1073
+ ]).optional()
1074
+ }),
1075
+ runtime_error: zod_v4.z.strictObject(failure),
1076
+ model_error: zod_v4.z.strictObject(failure),
1077
+ caller_cancelled: zod_v4.z.strictObject({}),
1078
+ observer_failed: zod_v4.z.strictObject({
1079
+ observerSpanId: label,
1080
+ ...cause
1081
+ }),
1082
+ context_window_exceeded: zod_v4.z.strictObject({
1083
+ provider: label,
1084
+ errorCode: label,
1085
+ contextWindow: zod_v4.z.number().optional()
1086
+ }),
1087
+ guardrail: zod_v4.z.strictObject({ processorId: label }),
1088
+ content_filter: zod_v4.z.strictObject({ provider: label }),
1089
+ approval_required: zod_v4.z.strictObject({
1090
+ toolCallId: label,
1091
+ toolName: label
1092
+ }),
1093
+ signal_received: zod_v4.z.strictObject({
1094
+ signalId: label,
1095
+ signalType: zod_v4.z.enum([
1096
+ "user",
1097
+ "state",
1098
+ "reactive",
1099
+ "notification"
1100
+ ]).optional()
1101
+ }),
1102
+ stop_condition: zod_v4.z.strictObject({}),
1103
+ iteration_hook: zod_v4.z.strictObject({ feedbackCompleted: zod_v4.z.boolean().optional() }),
1104
+ delegation_bail: zod_v4.z.strictObject(cause),
1105
+ authentication: zod_v4.z.strictObject(failure),
1106
+ authorization: zod_v4.z.strictObject(failure)
1107
+ };
1108
+ /** @internal Allowlist tooltip facts for framework producers, including untyped runtime inputs. */
1109
+ function compactStopReasonContext(stopReason, context) {
1110
+ if (!stopReason || !Object.hasOwn(contexts, stopReason) || !context || typeof context !== "object") return null;
1111
+ try {
1112
+ const result = {};
1113
+ for (const [key, schema] of Object.entries(contexts[stopReason].shape)) {
1114
+ const value = context[key];
1115
+ const parsed = schema.safeParse(value);
1116
+ if (parsed.success && parsed.data !== void 0) result[key] = parsed.data;
1117
+ }
1118
+ return Object.keys(result).length ? result : null;
1119
+ } catch {
1120
+ return null;
1121
+ }
1122
+ }
1123
+ function termination(stopReason) {
1124
+ return zod_v4.z.object({
1125
+ outcome: zod_v4.z.enum(SPAN_OUTCOMES),
1126
+ stopReason: zod_v4.z.literal(stopReason),
1127
+ stopReasonContext: contexts[stopReason].nullish()
1128
+ });
1129
+ }
1130
+ zod_v4.z.union([...Object.keys(SPAN_STOP_REASONS).map(termination), zod_v4.z.object({
1131
+ outcome: zod_v4.z.enum(SPAN_OUTCOMES),
1132
+ stopReason: zod_v4.z.null().optional(),
1133
+ stopReasonContext: zod_v4.z.null().optional()
1134
+ })]);
1135
+ // src/observability/execution-outcome.ts
1136
+ /** Read a provider's structured code without inferring a cause from diagnostic text. */
1137
+ function providerFailureCode(value) {
1138
+ if (typeof value.code === "string") return value.code;
1139
+ let data = value.data;
1140
+ if (data == null && typeof value.responseBody === "string") try {
1141
+ data = JSON.parse(value.responseBody);
1142
+ } catch {
1143
+ return;
1144
+ }
1145
+ if (!data || typeof data !== "object") return void 0;
1146
+ const record = data;
1147
+ const error = record.error && typeof record.error === "object" ? record.error : record;
1148
+ return typeof error.code === "string" ? error.code : void 0;
1149
+ }
1150
+ /** @internal Classify explicit failure facts, including wrapped/serialized causes. Never match error-message text. */
1151
+ function executionFailureTermination(error, layer = "runtime_error") {
1152
+ try {
1153
+ const termination = classifyExecutionFailure(error, layer);
1154
+ return {
1155
+ ...termination,
1156
+ stopReasonContext: compactStopReasonContext(termination.stopReason, termination.stopReasonContext)
1157
+ };
1158
+ } catch {
1159
+ return {
1160
+ outcome: "error",
1161
+ stopReason: layer
1162
+ };
1163
+ }
1164
+ }
1165
+ function classifyExecutionFailure(error, layer) {
1166
+ const seen = /* @__PURE__ */ new Set();
1167
+ let current = error;
1168
+ let failure;
1169
+ let modelFailure = layer === "model_error";
1170
+ while (current && typeof current === "object" && !seen.has(current)) {
1171
+ seen.add(current);
1172
+ const value = current;
1173
+ if (value.status === "failed" && value.error && typeof value.error === "object") {
1174
+ current = value.error;
1175
+ continue;
1176
+ }
1177
+ if (value.name === "TripWire" && (value.processorId === void 0 || typeof value.processorId === "string") && value.options && typeof value.options === "object" && typeof value.message === "string") {
1178
+ const options = value.options;
1179
+ return tripwireTermination({
1180
+ processorId: value.processorId,
1181
+ reason: value.message,
1182
+ ...options
1183
+ });
1184
+ }
1185
+ failure = value;
1186
+ if (value.name === "MastraTimeoutError" && typeof value.timeoutMs === "number") return {
1187
+ outcome: "limit",
1188
+ stopReason: "timeout",
1189
+ stopReasonContext: {
1190
+ timeoutMs: value.timeoutMs,
1191
+ ...value.timeoutType === "step" || value.timeoutType === "total" || value.timeoutType === "firstChunk" ? { timeoutType: value.timeoutType } : {}
1192
+ }
1193
+ };
1194
+ if (value.name === "FGADeniedError") return {
1195
+ outcome: "blocked",
1196
+ stopReason: "authorization"
1197
+ };
1198
+ const apiError = value[Symbol.for("vercel.ai.error.AI_APICallError")] === true || value.name === "AI_APICallError";
1199
+ if (apiError) modelFailure = true;
1200
+ if (apiError && (value.statusCode === 401 || value.statusCode === 403)) return {
1201
+ outcome: "blocked",
1202
+ stopReason: value.statusCode === 401 ? "authentication" : "authorization",
1203
+ stopReasonContext: {
1204
+ errorCode: String(value.statusCode),
1205
+ provider: typeof value.provider === "string" ? value.provider : void 0
1206
+ }
1207
+ };
1208
+ if (apiError) {
1209
+ const errorCode = providerFailureCode(value);
1210
+ if (errorCode === "content_filter") return {
1211
+ outcome: "blocked",
1212
+ stopReason: "content_filter",
1213
+ stopReasonContext: { provider: typeof value.provider === "string" ? value.provider : void 0 }
1214
+ };
1215
+ if (errorCode === "context_length_exceeded" || errorCode === "context_window_exceeded") return {
1216
+ outcome: "limit",
1217
+ stopReason: "context_window_exceeded",
1218
+ stopReasonContext: { errorCode }
1219
+ };
1220
+ }
1221
+ current = value.cause;
1222
+ }
1223
+ return {
1224
+ outcome: "error",
1225
+ stopReason: modelFailure ? "model_error" : "runtime_error",
1226
+ stopReasonContext: {
1227
+ provider: typeof failure?.provider === "string" ? failure.provider : void 0,
1228
+ errorCode: typeof failure?.code === "string" ? failure.code : typeof failure?.id === "string" ? failure.id : void 0,
1229
+ retryable: typeof failure?.isRetryable === "boolean" ? failure.isRetryable : void 0
1230
+ }
1231
+ };
1232
+ }
1233
+ /** Link to the observer's diagnostics without copying its payload into the interrupted span. */
1234
+ function tripwireTermination(tripwire) {
1235
+ try {
1236
+ const metadata = tripwire?.metadata;
1237
+ const observer = metadata && typeof metadata === "object" && "observerFailure" in metadata ? metadata.observerFailure : void 0;
1238
+ if (observer && typeof observer === "object" && "cause" in observer && observer.cause && typeof observer.cause === "object") {
1239
+ const cause = observer.cause;
1240
+ if (SPAN_OUTCOMES.includes(cause.outcome) && cause.outcome !== "success" && cause.outcome !== "suspend") return {
1241
+ outcome: "interrupted",
1242
+ stopReason: "observer_failed",
1243
+ stopReasonContext: compactStopReasonContext("observer_failed", {
1244
+ observerSpanId: "observerSpanId" in observer ? observer.observerSpanId : void 0,
1245
+ causeOutcome: cause.outcome,
1246
+ causeStopReason: typeof cause.stopReason === "string" && Object.hasOwn(SPAN_STOP_REASONS, cause.stopReason) ? cause.stopReason : void 0
1247
+ })
1248
+ };
1249
+ }
1250
+ return {
1251
+ outcome: "blocked",
1252
+ stopReason: "guardrail",
1253
+ stopReasonContext: compactStopReasonContext("guardrail", { processorId: tripwire?.processorId })
1254
+ };
1255
+ } catch {
1256
+ return {
1257
+ outcome: "blocked",
1258
+ stopReason: "guardrail"
1259
+ };
1260
+ }
1261
+ }
1262
+ // src/loop/shared/execution-outcome.ts
1263
+ /**
1264
+ * @internal
1265
+ * Classify a settled agent loop using its runtime stop boundary. A provider
1266
+ * finish reason refines the result; it cannot establish successful execution
1267
+ * without a continuation decision. Call only after finish-time work succeeds.
1268
+ */
1269
+ function agentLoopTermination(input) {
1270
+ const { stopCause, finishReason, maxSteps, tripwire } = input;
1271
+ if (tripwire || finishReason === "tripwire") return tripwireTermination(tripwire);
1272
+ if (finishReason === "suspended") {
1273
+ const suspension = input.suspension;
1274
+ if (suspension?.approvalRequired) return {
1275
+ outcome: "suspend",
1276
+ stopReason: "approval_required",
1277
+ stopReasonContext: compactStopReasonContext("approval_required", {
1278
+ toolCallId: suspension.toolCallId,
1279
+ toolName: suspension.toolName
1280
+ })
1281
+ };
1282
+ return {
1283
+ outcome: "suspend",
1284
+ stopReason: null,
1285
+ stopReasonContext: null
1286
+ };
1287
+ }
1288
+ if (finishReason === "length") return {
1289
+ outcome: "limit",
1290
+ stopReason: "max_tokens"
1291
+ };
1292
+ if (finishReason === "content-filter") return {
1293
+ outcome: "blocked",
1294
+ stopReason: "content_filter"
1295
+ };
1296
+ if (finishReason === "abort" || finishReason === "aborted") return {
1297
+ outcome: "abort",
1298
+ stopReason: "caller_cancelled"
1299
+ };
1300
+ if (finishReason === "error") return {
1301
+ outcome: "error",
1302
+ stopReason: "model_error"
1303
+ };
1304
+ switch (stopCause) {
1305
+ case "max_steps": return {
1306
+ outcome: "limit",
1307
+ stopReason: "max_steps",
1308
+ stopReasonContext: { maxSteps }
1309
+ };
1310
+ case "stop_condition": return {
1311
+ outcome: "success",
1312
+ stopReason: "stop_condition"
1313
+ };
1314
+ case "iteration_hook":
1315
+ case "feedback_complete": return {
1316
+ outcome: "success",
1317
+ stopReason: "iteration_hook",
1318
+ stopReasonContext: { feedbackCompleted: stopCause === "feedback_complete" }
1319
+ };
1320
+ case "delegation":
1321
+ if (input.delegationFailure) return {
1322
+ outcome: "interrupted",
1323
+ stopReason: "delegation_bail",
1324
+ stopReasonContext: {
1325
+ causeOutcome: input.delegationFailure.outcome,
1326
+ causeStopReason: input.delegationFailure.stopReason ?? void 0
1327
+ }
1328
+ };
1329
+ return {
1330
+ outcome: "success",
1331
+ stopReason: "delegation_bail"
1332
+ };
1333
+ case "model_finished": if (finishReason === "stop" || finishReason === "tool-calls") return {
1334
+ outcome: "success",
1335
+ stopReason: null,
1336
+ stopReasonContext: null
1337
+ };
1338
+ }
1339
+ return {
1340
+ outcome: "unknown",
1341
+ stopReason: null,
1342
+ stopReasonContext: null
1343
+ };
1344
+ }
1345
1345
  // src/observability/usage.ts
1346
1346
  const usageCountKeys = [
1347
1347
  "inputTokens",