@mastra/code-sdk 0.0.0-agent-tags-alpha-20261125185303

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 (407) hide show
  1. package/LICENSE.md +32 -0
  2. package/README.md +284 -0
  3. package/dist/acp/agent.d.ts +48 -0
  4. package/dist/acp/agent.js +414 -0
  5. package/dist/acp/errors.d.ts +3 -0
  6. package/dist/acp/errors.js +11 -0
  7. package/dist/acp/event-mapper.d.ts +28 -0
  8. package/dist/acp/event-mapper.js +274 -0
  9. package/dist/acp/index.d.ts +9 -0
  10. package/dist/acp/index.js +21 -0
  11. package/dist/acp/runtime.d.ts +5 -0
  12. package/dist/acp/runtime.js +91 -0
  13. package/dist/acp/server.d.ts +4 -0
  14. package/dist/acp/server.js +35 -0
  15. package/dist/acp/skills.d.ts +6 -0
  16. package/dist/acp/skills.js +30 -0
  17. package/dist/acp.d.ts +2 -0
  18. package/dist/acp.js +1 -0
  19. package/dist/agent-connections/messaging-processor.d.ts +17 -0
  20. package/dist/agent-connections/messaging-processor.js +131 -0
  21. package/dist/agent-connections/ownership.d.ts +24 -0
  22. package/dist/agent-connections/ownership.js +96 -0
  23. package/dist/agent-connections/registry.d.ts +20 -0
  24. package/dist/agent-connections/registry.js +167 -0
  25. package/dist/agent-connections/session-advertisement.d.ts +27 -0
  26. package/dist/agent-connections/session-advertisement.js +86 -0
  27. package/dist/agent-connections/signal-provider.d.ts +141 -0
  28. package/dist/agent-connections/signal-provider.js +35 -0
  29. package/dist/agent-connections/state-processor.d.ts +23 -0
  30. package/dist/agent-connections/state-processor.js +270 -0
  31. package/dist/agent-connections/thread-state.d.ts +41 -0
  32. package/dist/agent-connections/thread-state.js +157 -0
  33. package/dist/agent-connections/tools.d.ts +133 -0
  34. package/dist/agent-connections/tools.js +616 -0
  35. package/dist/agent-connections/types.d.ts +99 -0
  36. package/dist/agent-connections/types.js +4 -0
  37. package/dist/agent-connections/untrusted-text.d.ts +5 -0
  38. package/dist/agent-connections/untrusted-text.js +19 -0
  39. package/dist/agents/background-completion-events.d.ts +16 -0
  40. package/dist/agents/background-completion-events.js +16 -0
  41. package/dist/agents/background-completion.d.ts +22 -0
  42. package/dist/agents/background-completion.js +73 -0
  43. package/dist/agents/context-audit.d.ts +84 -0
  44. package/dist/agents/context-audit.js +115 -0
  45. package/dist/agents/credential-resolver.d.ts +74 -0
  46. package/dist/agents/credential-resolver.js +142 -0
  47. package/dist/agents/custom-provider-source.d.ts +35 -0
  48. package/dist/agents/custom-provider-source.js +22 -0
  49. package/dist/agents/fastembed-subprocess.d.ts +52 -0
  50. package/dist/agents/fastembed-subprocess.js +282 -0
  51. package/dist/agents/instructions.d.ts +42 -0
  52. package/dist/agents/instructions.js +69 -0
  53. package/dist/agents/mastracode-gateway.d.ts +85 -0
  54. package/dist/agents/mastracode-gateway.js +500 -0
  55. package/dist/agents/memory.d.ts +36 -0
  56. package/dist/agents/memory.js +248 -0
  57. package/dist/agents/model.d.ts +158 -0
  58. package/dist/agents/model.js +382 -0
  59. package/dist/agents/modes/build.d.ts +12 -0
  60. package/dist/agents/modes/build.js +33 -0
  61. package/dist/agents/modes/explore.d.ts +10 -0
  62. package/dist/agents/modes/explore.js +25 -0
  63. package/dist/agents/modes/plan.d.ts +8 -0
  64. package/dist/agents/modes/plan.js +43 -0
  65. package/dist/agents/prompts/agent-instructions.d.ts +122 -0
  66. package/dist/agents/prompts/agent-instructions.js +617 -0
  67. package/dist/agents/prompts/build.d.ts +12 -0
  68. package/dist/agents/prompts/build.js +73 -0
  69. package/dist/agents/prompts/fast.d.ts +5 -0
  70. package/dist/agents/prompts/fast.js +23 -0
  71. package/dist/agents/prompts/index.d.ts +61 -0
  72. package/dist/agents/prompts/index.js +141 -0
  73. package/dist/agents/prompts/model.d.ts +5 -0
  74. package/dist/agents/prompts/model.js +20 -0
  75. package/dist/agents/prompts/plan.d.ts +11 -0
  76. package/dist/agents/prompts/plan.js +132 -0
  77. package/dist/agents/prompts/tool-guidance.d.ts +18 -0
  78. package/dist/agents/prompts/tool-guidance.js +158 -0
  79. package/dist/agents/sandbox-filesystem.d.ts +232 -0
  80. package/dist/agents/sandbox-filesystem.js +851 -0
  81. package/dist/agents/subagents/execute.d.ts +3 -0
  82. package/dist/agents/subagents/execute.js +24 -0
  83. package/dist/agents/subagents/explore.d.ts +3 -0
  84. package/dist/agents/subagents/explore.js +15 -0
  85. package/dist/agents/subagents/index.d.ts +6 -0
  86. package/dist/agents/subagents/index.js +15 -0
  87. package/dist/agents/subagents/plan.d.ts +3 -0
  88. package/dist/agents/subagents/plan.js +15 -0
  89. package/dist/agents/thread-caveman-state.d.ts +17 -0
  90. package/dist/agents/thread-caveman-state.js +104 -0
  91. package/dist/agents/tool-availability.d.ts +17 -0
  92. package/dist/agents/tool-availability.js +134 -0
  93. package/dist/agents/tools.d.ts +37 -0
  94. package/dist/agents/tools.js +154 -0
  95. package/dist/agents/workflow-builder-agent.d.ts +2 -0
  96. package/dist/agents/workflow-builder-agent.js +79 -0
  97. package/dist/agents/workspace.d.ts +35 -0
  98. package/dist/agents/workspace.js +207 -0
  99. package/dist/analytics.d.ts +18 -0
  100. package/dist/analytics.js +159 -0
  101. package/dist/auth/account-rotation-processor.d.ts +210 -0
  102. package/dist/auth/account-rotation-processor.js +662 -0
  103. package/dist/auth/account-routing-context.d.ts +17 -0
  104. package/dist/auth/account-routing-context.js +38 -0
  105. package/dist/auth/authorization-input.d.ts +16 -0
  106. package/dist/auth/authorization-input.js +39 -0
  107. package/dist/auth/device-code.d.ts +93 -0
  108. package/dist/auth/device-code.js +126 -0
  109. package/dist/auth/index.d.ts +13 -0
  110. package/dist/auth/index.js +9 -0
  111. package/dist/auth/pkce.d.ts +13 -0
  112. package/dist/auth/pkce.js +29 -0
  113. package/dist/auth/provider-auth-error.d.ts +24 -0
  114. package/dist/auth/provider-auth-error.js +44 -0
  115. package/dist/auth/providers/anthropic.d.ts +40 -0
  116. package/dist/auth/providers/anthropic.js +117 -0
  117. package/dist/auth/providers/github-copilot.d.ts +154 -0
  118. package/dist/auth/providers/github-copilot.js +359 -0
  119. package/dist/auth/providers/kimi-coding.d.ts +38 -0
  120. package/dist/auth/providers/kimi-coding.js +225 -0
  121. package/dist/auth/providers/openai-codex.d.ts +141 -0
  122. package/dist/auth/providers/openai-codex.js +531 -0
  123. package/dist/auth/providers/xai.d.ts +64 -0
  124. package/dist/auth/providers/xai.js +223 -0
  125. package/dist/auth/storage.d.ts +222 -0
  126. package/dist/auth/storage.js +805 -0
  127. package/dist/auth/types.d.ts +164 -0
  128. package/dist/auth/types.js +1 -0
  129. package/dist/clipboard/index.d.ts +26 -0
  130. package/dist/clipboard/index.js +224 -0
  131. package/dist/constants.d.ts +29 -0
  132. package/dist/constants.js +34 -0
  133. package/dist/error-classification.d.ts +10 -0
  134. package/dist/error-classification.js +19 -0
  135. package/dist/evals/context-builder.d.ts +41 -0
  136. package/dist/evals/context-builder.js +156 -0
  137. package/dist/evals/index.d.ts +4 -0
  138. package/dist/evals/index.js +5 -0
  139. package/dist/evals/scorers/classify-command.d.ts +30 -0
  140. package/dist/evals/scorers/classify-command.js +61 -0
  141. package/dist/evals/scorers/efficiency.d.ts +44 -0
  142. package/dist/evals/scorers/efficiency.js +256 -0
  143. package/dist/evals/scorers/extract-tools.d.ts +25 -0
  144. package/dist/evals/scorers/extract-tools.js +57 -0
  145. package/dist/evals/scorers/index.d.ts +3 -0
  146. package/dist/evals/scorers/index.js +3 -0
  147. package/dist/evals/scorers/outcome.d.ts +49 -0
  148. package/dist/evals/scorers/outcome.js +360 -0
  149. package/dist/experimental-agent.d.ts +19 -0
  150. package/dist/experimental-agent.js +45 -0
  151. package/dist/factory/client.d.ts +44 -0
  152. package/dist/factory/client.js +110 -0
  153. package/dist/factory/remote-controller.d.ts +34 -0
  154. package/dist/factory/remote-controller.js +40 -0
  155. package/dist/factory/remote-session.d.ts +210 -0
  156. package/dist/factory/remote-session.js +415 -0
  157. package/dist/goal-manager.d.ts +114 -0
  158. package/dist/goal-manager.js +351 -0
  159. package/dist/goal-signal.d.ts +14 -0
  160. package/dist/goal-signal.js +14 -0
  161. package/dist/headless/cli.d.ts +55 -0
  162. package/dist/headless/cli.js +261 -0
  163. package/dist/headless/flags.d.ts +33 -0
  164. package/dist/headless/flags.js +207 -0
  165. package/dist/headless/format.d.ts +41 -0
  166. package/dist/headless/format.js +94 -0
  167. package/dist/headless/index.d.ts +25 -0
  168. package/dist/headless/index.js +6 -0
  169. package/dist/headless/policy.d.ts +17 -0
  170. package/dist/headless/policy.js +39 -0
  171. package/dist/headless/run-mc.d.ts +7 -0
  172. package/dist/headless/run-mc.js +438 -0
  173. package/dist/headless/types.d.ts +175 -0
  174. package/dist/headless/types.js +16 -0
  175. package/dist/hooks/config.d.ts +11 -0
  176. package/dist/hooks/config.js +77 -0
  177. package/dist/hooks/executor.d.ts +13 -0
  178. package/dist/hooks/executor.js +128 -0
  179. package/dist/hooks/index.d.ts +6 -0
  180. package/dist/hooks/index.js +5 -0
  181. package/dist/hooks/manager.d.ts +75 -0
  182. package/dist/hooks/manager.js +289 -0
  183. package/dist/hooks/types.d.ts +180 -0
  184. package/dist/hooks/types.js +5 -0
  185. package/dist/index.d.ts +537 -0
  186. package/dist/index.js +1399 -0
  187. package/dist/ipc/ipc-reporter.d.ts +14 -0
  188. package/dist/ipc/ipc-reporter.js +18 -0
  189. package/dist/knowledge-inspector.d.ts +139 -0
  190. package/dist/knowledge-inspector.js +533 -0
  191. package/dist/knowledge-scope-id.d.ts +7 -0
  192. package/dist/knowledge-scope-id.js +10 -0
  193. package/dist/knowledge-scope.d.ts +41 -0
  194. package/dist/knowledge-scope.js +85 -0
  195. package/dist/lsp/client.d.ts +56 -0
  196. package/dist/lsp/client.js +248 -0
  197. package/dist/lsp/index.d.ts +4 -0
  198. package/dist/lsp/index.js +4 -0
  199. package/dist/lsp/language.d.ts +9 -0
  200. package/dist/lsp/language.js +41 -0
  201. package/dist/lsp/manager.d.ts +34 -0
  202. package/dist/lsp/manager.js +79 -0
  203. package/dist/lsp/server.d.ts +27 -0
  204. package/dist/lsp/server.js +158 -0
  205. package/dist/lsp/workspace.d.ts +9 -0
  206. package/dist/lsp/workspace.js +52 -0
  207. package/dist/mcp/config.d.ts +77 -0
  208. package/dist/mcp/config.js +313 -0
  209. package/dist/mcp/index.d.ts +6 -0
  210. package/dist/mcp/index.js +3 -0
  211. package/dist/mcp/manager.d.ts +104 -0
  212. package/dist/mcp/manager.js +693 -0
  213. package/dist/mcp/state.d.ts +35 -0
  214. package/dist/mcp/state.js +94 -0
  215. package/dist/mcp/types.d.ts +139 -0
  216. package/dist/mcp/types.js +1 -0
  217. package/dist/onboarding/custom-packs.d.ts +7 -0
  218. package/dist/onboarding/custom-packs.js +17 -0
  219. package/dist/onboarding/custom-providers.d.ts +4 -0
  220. package/dist/onboarding/custom-providers.js +27 -0
  221. package/dist/onboarding/index.d.ts +5 -0
  222. package/dist/onboarding/index.js +3 -0
  223. package/dist/onboarding/om-settings.d.ts +47 -0
  224. package/dist/onboarding/om-settings.js +80 -0
  225. package/dist/onboarding/pack-activation.d.ts +43 -0
  226. package/dist/onboarding/pack-activation.js +105 -0
  227. package/dist/onboarding/packs.d.ts +106 -0
  228. package/dist/onboarding/packs.js +283 -0
  229. package/dist/onboarding/settings.d.ts +563 -0
  230. package/dist/onboarding/settings.js +1110 -0
  231. package/dist/permissions.d.ts +55 -0
  232. package/dist/permissions.js +139 -0
  233. package/dist/platform/index.d.ts +74 -0
  234. package/dist/platform/index.js +199 -0
  235. package/dist/plugin.d.ts +156 -0
  236. package/dist/plugin.js +27 -0
  237. package/dist/plugins/dependencies.d.ts +9 -0
  238. package/dist/plugins/dependencies.js +84 -0
  239. package/dist/plugins/install.d.ts +21 -0
  240. package/dist/plugins/install.js +187 -0
  241. package/dist/plugins/loader.d.ts +25 -0
  242. package/dist/plugins/loader.js +264 -0
  243. package/dist/plugins/manager.d.ts +115 -0
  244. package/dist/plugins/manager.js +507 -0
  245. package/dist/plugins/manifest.d.ts +14 -0
  246. package/dist/plugins/manifest.js +47 -0
  247. package/dist/plugins/package-link.d.ts +3 -0
  248. package/dist/plugins/package-link.js +58 -0
  249. package/dist/plugins/paths.d.ts +10 -0
  250. package/dist/plugins/paths.js +22 -0
  251. package/dist/plugins/registry.d.ts +8 -0
  252. package/dist/plugins/registry.js +109 -0
  253. package/dist/plugins/scaffold.d.ts +10 -0
  254. package/dist/plugins/scaffold.js +115 -0
  255. package/dist/plugins/signal-lane.d.ts +59 -0
  256. package/dist/plugins/signal-lane.js +163 -0
  257. package/dist/plugins/types.d.ts +95 -0
  258. package/dist/plugins/types.js +1 -0
  259. package/dist/process-memory-diagnostics.d.ts +136 -0
  260. package/dist/process-memory-diagnostics.js +497 -0
  261. package/dist/processors/plan-rejection-abort.d.ts +16 -0
  262. package/dist/processors/plan-rejection-abort.js +62 -0
  263. package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
  264. package/dist/providers/amazon-bedrock-gateway.js +142 -0
  265. package/dist/providers/amazon-bedrock.d.ts +28 -0
  266. package/dist/providers/amazon-bedrock.js +99 -0
  267. package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
  268. package/dist/providers/anthropic-prompt-cache.js +8 -0
  269. package/dist/providers/anthropic-thinking.d.ts +5 -0
  270. package/dist/providers/anthropic-thinking.js +22 -0
  271. package/dist/providers/claude-max.d.ts +67 -0
  272. package/dist/providers/claude-max.js +232 -0
  273. package/dist/providers/github-copilot-gateway.d.ts +35 -0
  274. package/dist/providers/github-copilot-gateway.js +58 -0
  275. package/dist/providers/github-copilot.d.ts +60 -0
  276. package/dist/providers/github-copilot.js +320 -0
  277. package/dist/providers/google-thinking.d.ts +31 -0
  278. package/dist/providers/google-thinking.js +64 -0
  279. package/dist/providers/google-vertex-gateway.d.ts +23 -0
  280. package/dist/providers/google-vertex-gateway.js +49 -0
  281. package/dist/providers/google-vertex.d.ts +6 -0
  282. package/dist/providers/google-vertex.js +51 -0
  283. package/dist/providers/kimi-coding.d.ts +14 -0
  284. package/dist/providers/kimi-coding.js +80 -0
  285. package/dist/providers/model-ids.d.ts +53 -0
  286. package/dist/providers/model-ids.js +132 -0
  287. package/dist/providers/openai-codex.d.ts +114 -0
  288. package/dist/providers/openai-codex.js +427 -0
  289. package/dist/providers/provider-thinking.d.ts +23 -0
  290. package/dist/providers/provider-thinking.js +61 -0
  291. package/dist/providers/thinking-request.d.ts +14 -0
  292. package/dist/providers/thinking-request.js +87 -0
  293. package/dist/providers/xai.d.ts +33 -0
  294. package/dist/providers/xai.js +72 -0
  295. package/dist/schedules/index.d.ts +10 -0
  296. package/dist/schedules/index.js +6 -0
  297. package/dist/schedules/interval.d.ts +49 -0
  298. package/dist/schedules/interval.js +212 -0
  299. package/dist/schedules/prompt.d.ts +36 -0
  300. package/dist/schedules/prompt.js +36 -0
  301. package/dist/schedules/run-script.d.ts +8 -0
  302. package/dist/schedules/run-script.js +80 -0
  303. package/dist/schedules/scheduler.d.ts +101 -0
  304. package/dist/schedules/scheduler.js +167 -0
  305. package/dist/schedules/tools.d.ts +57 -0
  306. package/dist/schedules/tools.js +217 -0
  307. package/dist/schema.d.ts +499 -0
  308. package/dist/schema.js +131 -0
  309. package/dist/theme-palette.d.ts +17 -0
  310. package/dist/theme-palette.js +18 -0
  311. package/dist/thinking-catalog.d.ts +4 -0
  312. package/dist/thinking-catalog.js +13 -0
  313. package/dist/thinking.d.ts +37 -0
  314. package/dist/thinking.js +134 -0
  315. package/dist/tool-names.d.ts +77 -0
  316. package/dist/tool-names.js +53 -0
  317. package/dist/tools/index.d.ts +6 -0
  318. package/dist/tools/index.js +3 -0
  319. package/dist/tools/request-sandbox-access.d.ts +6 -0
  320. package/dist/tools/request-sandbox-access.js +80 -0
  321. package/dist/tools/utils.d.ts +20 -0
  322. package/dist/tools/utils.js +31 -0
  323. package/dist/tools/web-search.d.ts +116 -0
  324. package/dist/tools/web-search.js +158 -0
  325. package/dist/tools/workflows/create-workflow.d.ts +7 -0
  326. package/dist/tools/workflows/create-workflow.js +82 -0
  327. package/dist/tools/workflows/delete-workflow.d.ts +7 -0
  328. package/dist/tools/workflows/delete-workflow.js +18 -0
  329. package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
  330. package/dist/tools/workflows/ephemeral-memory.js +41 -0
  331. package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
  332. package/dist/tools/workflows/extract-json-schema.js +19 -0
  333. package/dist/tools/workflows/get-workflow.d.ts +11 -0
  334. package/dist/tools/workflows/get-workflow.js +31 -0
  335. package/dist/tools/workflows/list-available-agents.d.ts +8 -0
  336. package/dist/tools/workflows/list-available-agents.js +29 -0
  337. package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
  338. package/dist/tools/workflows/list-available-classifiers.js +53 -0
  339. package/dist/tools/workflows/list-available-tools.d.ts +9 -0
  340. package/dist/tools/workflows/list-available-tools.js +37 -0
  341. package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
  342. package/dist/tools/workflows/list-available-workflows.js +29 -0
  343. package/dist/tools/workflows/list-workflows.d.ts +9 -0
  344. package/dist/tools/workflows/list-workflows.js +30 -0
  345. package/dist/tools/workflows/run-workflow.d.ts +9 -0
  346. package/dist/tools/workflows/run-workflow.js +49 -0
  347. package/dist/tools/workflows/save-workflow.d.ts +1125 -0
  348. package/dist/tools/workflows/save-workflow.js +25 -0
  349. package/dist/tools/workflows/tool-ids.d.ts +16 -0
  350. package/dist/tools/workflows/tool-ids.js +17 -0
  351. package/dist/utils/binaries.d.ts +7 -0
  352. package/dist/utils/binaries.js +97 -0
  353. package/dist/utils/debug-log.d.ts +12 -0
  354. package/dist/utils/debug-log.js +56 -0
  355. package/dist/utils/discarding-scores-storage.d.ts +33 -0
  356. package/dist/utils/discarding-scores-storage.js +51 -0
  357. package/dist/utils/errors.d.ts +36 -0
  358. package/dist/utils/errors.js +215 -0
  359. package/dist/utils/gateway-sync.d.ts +26 -0
  360. package/dist/utils/gateway-sync.js +58 -0
  361. package/dist/utils/local-observability.d.ts +19 -0
  362. package/dist/utils/local-observability.js +54 -0
  363. package/dist/utils/maintenance-lock.d.ts +42 -0
  364. package/dist/utils/maintenance-lock.js +196 -0
  365. package/dist/utils/notification-dispatch.d.ts +74 -0
  366. package/dist/utils/notification-dispatch.js +128 -0
  367. package/dist/utils/open-url.d.ts +10 -0
  368. package/dist/utils/open-url.js +27 -0
  369. package/dist/utils/path-security.d.ts +2 -0
  370. package/dist/utils/path-security.js +7 -0
  371. package/dist/utils/plan-diff.d.ts +25 -0
  372. package/dist/utils/plan-diff.js +59 -0
  373. package/dist/utils/plans.d.ts +61 -0
  374. package/dist/utils/plans.js +120 -0
  375. package/dist/utils/project.d.ts +160 -0
  376. package/dist/utils/project.js +361 -0
  377. package/dist/utils/prune-cli.d.ts +24 -0
  378. package/dist/utils/prune-cli.js +124 -0
  379. package/dist/utils/signals-pubsub.d.ts +103 -0
  380. package/dist/utils/signals-pubsub.js +409 -0
  381. package/dist/utils/slash-command-loader.d.ts +52 -0
  382. package/dist/utils/slash-command-loader.js +139 -0
  383. package/dist/utils/slash-command-processor.d.ts +14 -0
  384. package/dist/utils/slash-command-processor.js +106 -0
  385. package/dist/utils/stdin-pipe.d.ts +33 -0
  386. package/dist/utils/stdin-pipe.js +93 -0
  387. package/dist/utils/storage-factory.d.ts +50 -0
  388. package/dist/utils/storage-factory.js +118 -0
  389. package/dist/utils/storage-maintenance.d.ts +121 -0
  390. package/dist/utils/storage-maintenance.js +352 -0
  391. package/dist/utils/thread-lock.d.ts +26 -0
  392. package/dist/utils/thread-lock.js +109 -0
  393. package/dist/utils/token-estimator.d.ts +3 -0
  394. package/dist/utils/token-estimator.js +19 -0
  395. package/dist/utils/update-check.d.ts +151 -0
  396. package/dist/utils/update-check.js +430 -0
  397. package/dist/utils/wake-session.d.ts +44 -0
  398. package/dist/utils/wake-session.js +83 -0
  399. package/dist/voice/stt-registry.d.ts +67 -0
  400. package/dist/voice/stt-registry.js +144 -0
  401. package/dist/voice/transcribe.d.ts +10 -0
  402. package/dist/voice/transcribe.js +75 -0
  403. package/dist/workflows/register-primitives.d.ts +52 -0
  404. package/dist/workflows/register-primitives.js +40 -0
  405. package/dist/workflows/service.d.ts +64 -0
  406. package/dist/workflows/service.js +50 -0
  407. package/package.json +117 -0
@@ -0,0 +1,25 @@
1
+ import { createTool } from "@mastra/core/tools";
2
+ import { z } from "zod";
3
+ import { WORKFLOW_BUILDER_MAPPING_CONFIG_DESCRIPTION as MAPPING_CONFIG_DESCRIPTION, normalizeWorkflowBuilderDefinition, workflowBuilderDefinitionSchema } from "@mastra/core/workflows/builder";
4
+ // src/tools/workflows/save-workflow.ts
5
+ const workflowDefinitionInputSchema = z.preprocess(normalizeWorkflowBuilderDefinition, workflowBuilderDefinitionSchema);
6
+ const saveWorkflowTool = createTool({
7
+ id: "save-workflow",
8
+ description: "Persist a Dynamic Workflow definition and live-register it on the running Mastra instance. Supports all ten persisted graph families: agent, tool, mapping, nested workflow, parallel, foreach, sleep, sleepUntil, conditional, and loop. Conditional and loop entries require declarative predicates; JS closures cannot round-trip through storage. After this returns, the workflow is immediately runnable. Call it exactly once with the complete definition; there is no incremental save API.",
9
+ inputSchema: workflowDefinitionInputSchema,
10
+ outputSchema: z.object({
11
+ ok: z.literal(true),
12
+ id: z.string()
13
+ }),
14
+ execute: async (def, { mastra }) => {
15
+ if (!mastra) throw new Error("save-workflow requires a Mastra context.");
16
+ const m = mastra;
17
+ const normalizedDefinition = normalizeWorkflowBuilderDefinition(def);
18
+ await m.addDynamicWorkflow(normalizedDefinition);
19
+ return {
20
+ ok: true,
21
+ id: normalizedDefinition.id
22
+ };
23
+ }
24
+ });
25
+ export { MAPPING_CONFIG_DESCRIPTION, saveWorkflowTool, workflowDefinitionInputSchema };
@@ -0,0 +1,16 @@
1
+ export declare const WORKFLOW_AUTHORING_TOOL_IDS: {
2
+ readonly listAgents: 'list-available-agents';
3
+ readonly listClassifiers: 'list-available-classifiers';
4
+ readonly listTools: 'list-available-tools';
5
+ readonly listWorkflows: 'list-available-workflows';
6
+ readonly saveWorkflow: 'save-workflow';
7
+ };
8
+ export declare const WORKFLOW_MANAGEMENT_TOOL_IDS: {
9
+ readonly createWorkflow: 'create-workflow';
10
+ readonly listWorkflows: 'list-workflows';
11
+ readonly getWorkflow: 'get-workflow';
12
+ readonly runWorkflow: 'run-workflow';
13
+ readonly deleteWorkflow: 'delete-workflow';
14
+ };
15
+ export declare const WORKFLOW_BUILDER_NOISE_TOOL_IDS: readonly ("create-workflow" | "delete-workflow" | "get-workflow" | "list-available-agents" | "list-available-classifiers" | "list-available-tools" | "list-available-workflows" | "list-workflows" | "run-workflow" | "save-workflow")[];
16
+ //# sourceMappingURL=tool-ids.d.ts.map
@@ -0,0 +1,17 @@
1
+ // src/tools/workflows/tool-ids.ts
2
+ const WORKFLOW_AUTHORING_TOOL_IDS = {
3
+ listAgents: "list-available-agents",
4
+ listClassifiers: "list-available-classifiers",
5
+ listTools: "list-available-tools",
6
+ listWorkflows: "list-available-workflows",
7
+ saveWorkflow: "save-workflow"
8
+ };
9
+ const WORKFLOW_MANAGEMENT_TOOL_IDS = {
10
+ createWorkflow: "create-workflow",
11
+ listWorkflows: "list-workflows",
12
+ getWorkflow: "get-workflow",
13
+ runWorkflow: "run-workflow",
14
+ deleteWorkflow: "delete-workflow"
15
+ };
16
+ const WORKFLOW_BUILDER_NOISE_TOOL_IDS = [...Object.values(WORKFLOW_AUTHORING_TOOL_IDS), ...Object.values(WORKFLOW_MANAGEMENT_TOOL_IDS)];
17
+ export { WORKFLOW_AUTHORING_TOOL_IDS, WORKFLOW_BUILDER_NOISE_TOOL_IDS, WORKFLOW_MANAGEMENT_TOOL_IDS };
@@ -0,0 +1,7 @@
1
+ export interface CommonBinary {
2
+ name: string;
3
+ path: string | null;
4
+ }
5
+ export declare function detectCommonBinaries(): CommonBinary[];
6
+ export declare function detectCommonBinariesAsync(): Promise<CommonBinary[]>;
7
+ //# sourceMappingURL=binaries.d.ts.map
@@ -0,0 +1,97 @@
1
+ import { basename, dirname, join } from "path";
2
+ import { realpathSync } from "fs";
3
+ import { execFile, execFileSync } from "child_process";
4
+ // src/utils/binaries.ts
5
+ const COMMON_BINARIES = [
6
+ "python",
7
+ "python3",
8
+ "node",
9
+ "npm",
10
+ "pnpm",
11
+ "yarn",
12
+ "bun",
13
+ "git",
14
+ "rg",
15
+ "fd",
16
+ "fdfind",
17
+ "curl",
18
+ "wget",
19
+ "docker",
20
+ "make",
21
+ "gcc",
22
+ "g++",
23
+ "go",
24
+ "rustc",
25
+ "cargo"
26
+ ];
27
+ /**
28
+ * The directory the tool lives in, with the name `which` reported still on the end.
29
+ *
30
+ * Version managers can put a directory first on PATH whose name changes on every shell (`fnm` builds one per
31
+ * shell, `fnm_multishells/<pid>_<epoch-ms>`). These paths are part of the system prompt, so a directory that
32
+ * changes from launch to launch changes that text even when the tools have not. Resolving the whole
33
+ * file instead would name the program behind a shim - `mise` points every tool at itself, BusyBox and
34
+ * OrbStack do the same for some tools, and a Homebrew link names `Cellar/<version>` - which either does not
35
+ * run the tool or changes on every upgrade. Resolving only the directory gives the stable installation and
36
+ * keeps a name that runs the tool.
37
+ */
38
+ function stablePath(path) {
39
+ if (!path) return path;
40
+ try {
41
+ return join(realpathSync(dirname(path)), basename(path));
42
+ } catch {
43
+ return path;
44
+ }
45
+ }
46
+ let cachedBinaries = null;
47
+ let inFlightPromise = null;
48
+ function whichCommand() {
49
+ return process.platform === "win32" ? "where" : "which";
50
+ }
51
+ function reportedBinary(name) {
52
+ try {
53
+ return execFileSync(whichCommand(), [name], {
54
+ encoding: "utf-8",
55
+ stdio: [
56
+ "pipe",
57
+ "pipe",
58
+ "pipe"
59
+ ]
60
+ }).trim().split(/\r?\n/)[0] || null;
61
+ } catch {
62
+ return null;
63
+ }
64
+ }
65
+ function reportedBinaryAsync(name) {
66
+ return new Promise((resolve) => {
67
+ execFile(whichCommand(), [name], { encoding: "utf-8" }, (err, stdout) => {
68
+ if (err) {
69
+ resolve(null);
70
+ return;
71
+ }
72
+ resolve(stdout.trim().split(/\r?\n/)[0] || null);
73
+ });
74
+ });
75
+ }
76
+ function detectCommonBinaries() {
77
+ cachedBinaries ??= COMMON_BINARIES.map((name) => ({
78
+ name,
79
+ path: stablePath(reportedBinary(name))
80
+ }));
81
+ return cachedBinaries;
82
+ }
83
+ async function detectCommonBinariesAsync() {
84
+ if (cachedBinaries) return cachedBinaries;
85
+ if (inFlightPromise) return inFlightPromise;
86
+ inFlightPromise = Promise.all(COMMON_BINARIES.map(async (name) => ({
87
+ name,
88
+ path: stablePath(await reportedBinaryAsync(name))
89
+ })));
90
+ try {
91
+ cachedBinaries = await inFlightPromise;
92
+ return cachedBinaries;
93
+ } finally {
94
+ inFlightPromise = null;
95
+ }
96
+ }
97
+ export { detectCommonBinaries, detectCommonBinariesAsync };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Truncate a log file to roughly {@link KEEP_SIZE} bytes if it exceeds
3
+ * {@link MAX_LOG_SIZE}, cutting at the first newline so we don't start mid-line.
4
+ */
5
+ export declare function truncateLogFile(logFile: string): void;
6
+ /**
7
+ * Set up debug logging. When {@link MASTRA_DEBUG} is `"true"`, redirects
8
+ * `console.error` and `console.warn` to a log file (truncating it first if
9
+ * oversized). Otherwise silences them to avoid corrupting the TUI.
10
+ */
11
+ export declare function setupDebugLogging(): void;
12
+ //# sourceMappingURL=debug-log.d.ts.map
@@ -0,0 +1,56 @@
1
+ import { getAppDataDir } from "./project.js";
2
+ import * as path$1 from "path";
3
+ import * as fs$1 from "fs";
4
+ // src/utils/debug-log.ts
5
+ const MAX_LOG_SIZE = 5242880;
6
+ const KEEP_SIZE = 4194304;
7
+ /**
8
+ * Truncate a log file to roughly {@link KEEP_SIZE} bytes if it exceeds
9
+ * {@link MAX_LOG_SIZE}, cutting at the first newline so we don't start mid-line.
10
+ */
11
+ function truncateLogFile(logFile) {
12
+ try {
13
+ const stat = fs$1.statSync(logFile);
14
+ if (stat.size > MAX_LOG_SIZE) {
15
+ const buf = Buffer.alloc(KEEP_SIZE);
16
+ const fd = fs$1.openSync(logFile, "r");
17
+ fs$1.readSync(fd, buf, 0, KEEP_SIZE, stat.size - KEEP_SIZE);
18
+ fs$1.closeSync(fd);
19
+ const firstNewline = buf.indexOf(10);
20
+ const trimmed = firstNewline >= 0 ? buf.subarray(firstNewline + 1) : buf;
21
+ fs$1.writeFileSync(logFile, trimmed);
22
+ }
23
+ } catch {}
24
+ }
25
+ /**
26
+ * Set up debug logging. When {@link MASTRA_DEBUG} is `"true"`, redirects
27
+ * `console.error` and `console.warn` to a log file (truncating it first if
28
+ * oversized). Otherwise silences them to avoid corrupting the TUI.
29
+ */
30
+ function setupDebugLogging() {
31
+ if (["true", "1"].includes(process.env.MASTRA_DEBUG ?? "")) {
32
+ const logFile = path$1.join(getAppDataDir(), "debug.log");
33
+ truncateLogFile(logFile);
34
+ const logStream = fs$1.createWriteStream(logFile, { flags: "a" });
35
+ const fmt = (a) => {
36
+ if (typeof a === "string") return a;
37
+ if (a instanceof Error) return a.stack ?? `${a.name}: ${a.message}`;
38
+ try {
39
+ return JSON.stringify(a);
40
+ } catch {
41
+ return String(a);
42
+ }
43
+ };
44
+ console.error = (...args) => {
45
+ logStream.write(`[ERROR] ${(/* @__PURE__ */ new Date()).toISOString()} ${args.map(fmt).join(" ")}\n`);
46
+ };
47
+ console.warn = (...args) => {
48
+ logStream.write(`[WARN] ${(/* @__PURE__ */ new Date()).toISOString()} ${args.map(fmt).join(" ")}\n`);
49
+ };
50
+ } else {
51
+ const noop = () => {};
52
+ console.error = noop;
53
+ console.warn = noop;
54
+ }
55
+ }
56
+ export { setupDebugLogging, truncateLogFile };
@@ -0,0 +1,33 @@
1
+ import type { ListScoresResponse, SaveScorePayload, ScoreRowData } from '@mastra/core/evals';
2
+ import { ScoresStorage } from '@mastra/core/storage';
3
+ import type { StoragePagination } from '@mastra/core/storage';
4
+ /**
5
+ * A scores domain that accepts writes and keeps nothing.
6
+ *
7
+ * mastracode's `outcome` and `efficiency` scorers persist every result through
8
+ * the scores domain (`validateAndSaveScore` → `getStore('scores')`), but nothing
9
+ * in mastracode reads scores back. Writing them to libsql grew mastra.db without
10
+ * bound, and an in-memory store would grow the heap for the life of the process
11
+ * instead (each payload carries the system prompt, messages, input and output).
12
+ * Disabling the domain is not an option: core throws
13
+ * MASTRA_SCORES_STORAGE_NOT_AVAILABLE on every scorer run when it is missing.
14
+ */
15
+ export declare class DiscardingScoresStorage extends ScoresStorage {
16
+ getScoreById(): Promise<ScoreRowData | null>;
17
+ saveScore(score: SaveScorePayload): Promise<{
18
+ score: ScoreRowData;
19
+ }>;
20
+ listScoresByScorerId({ pagination }: {
21
+ pagination: StoragePagination;
22
+ }): Promise<ListScoresResponse>;
23
+ listScoresByRunId({ pagination }: {
24
+ pagination: StoragePagination;
25
+ }): Promise<ListScoresResponse>;
26
+ listScoresByEntityId({ pagination }: {
27
+ pagination: StoragePagination;
28
+ }): Promise<ListScoresResponse>;
29
+ listScoresBySpan({ pagination }: {
30
+ pagination: StoragePagination;
31
+ }): Promise<ListScoresResponse>;
32
+ }
33
+ //# sourceMappingURL=discarding-scores-storage.d.ts.map
@@ -0,0 +1,51 @@
1
+ import { ScoresStorage } from "@mastra/core/storage";
2
+ // src/utils/discarding-scores-storage.ts
3
+ /**
4
+ * A scores domain that accepts writes and keeps nothing.
5
+ *
6
+ * mastracode's `outcome` and `efficiency` scorers persist every result through
7
+ * the scores domain (`validateAndSaveScore` → `getStore('scores')`), but nothing
8
+ * in mastracode reads scores back. Writing them to libsql grew mastra.db without
9
+ * bound, and an in-memory store would grow the heap for the life of the process
10
+ * instead (each payload carries the system prompt, messages, input and output).
11
+ * Disabling the domain is not an option: core throws
12
+ * MASTRA_SCORES_STORAGE_NOT_AVAILABLE on every scorer run when it is missing.
13
+ */
14
+ var DiscardingScoresStorage = class extends ScoresStorage {
15
+ async getScoreById() {
16
+ return null;
17
+ }
18
+ async saveScore(score) {
19
+ const now = /* @__PURE__ */ new Date();
20
+ return { score: {
21
+ ...score,
22
+ id: score.id ?? crypto.randomUUID(),
23
+ createdAt: now,
24
+ updatedAt: now
25
+ } };
26
+ }
27
+ async listScoresByScorerId({ pagination }) {
28
+ return empty(pagination);
29
+ }
30
+ async listScoresByRunId({ pagination }) {
31
+ return empty(pagination);
32
+ }
33
+ async listScoresByEntityId({ pagination }) {
34
+ return empty(pagination);
35
+ }
36
+ async listScoresBySpan({ pagination }) {
37
+ return empty(pagination);
38
+ }
39
+ };
40
+ function empty(pagination) {
41
+ return {
42
+ pagination: {
43
+ total: 0,
44
+ page: pagination.page,
45
+ perPage: pagination.perPage,
46
+ hasMore: false
47
+ },
48
+ scores: []
49
+ };
50
+ }
51
+ export { DiscardingScoresStorage };
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Error handling utilities for the Mastra Code TUI.
3
+ * Parses API errors and provides user-friendly messages.
4
+ */
5
+ export interface ParsedError {
6
+ /** User-friendly error message */
7
+ message: string;
8
+ /** Extra diagnostic detail to surface to the user */
9
+ detail?: string;
10
+ /** Request URL involved in the failure, when available */
11
+ requestUrl?: string;
12
+ /** Error type for categorization */
13
+ type: ErrorType;
14
+ /** Whether this error is retryable */
15
+ retryable: boolean;
16
+ /** Suggested retry delay in ms (if retryable) */
17
+ retryDelay?: number;
18
+ /** Original error for debugging */
19
+ originalError: Error;
20
+ }
21
+ export type ErrorType = 'rate_limit' | 'quota' | 'auth' | 'network' | 'timeout' | 'invalid_request' | 'server_error' | 'model_not_found' | 'context_length' | 'content_filter' | 'unknown';
22
+ export declare function parseError(error: unknown): ParsedError;
23
+ /**
24
+ * Sleep for a given number of milliseconds.
25
+ */
26
+ export declare function sleep(ms: number): Promise<void>;
27
+ /**
28
+ * Retry a function with exponential backoff.
29
+ */
30
+ export declare function withRetry<T>(fn: () => Promise<T>, options?: {
31
+ maxRetries?: number;
32
+ initialDelay?: number;
33
+ maxDelay?: number;
34
+ onRetry?: (error: ParsedError, attempt: number) => void;
35
+ }): Promise<T>;
36
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1,215 @@
1
+ import "../auth/provider-auth-error.js";
2
+ import { classifyProviderError } from "@mastra/core/error";
3
+ // src/utils/errors.ts
4
+ /**
5
+ * Error handling utilities for the Mastra Code TUI.
6
+ * Parses API errors and provides user-friendly messages.
7
+ */
8
+ /**
9
+ * Parse an error and return a user-friendly representation.
10
+ */
11
+ function summarizeErrorDetail(error) {
12
+ if (error instanceof Error) {
13
+ if (error.cause instanceof Error && error.cause.message) return error.cause.message;
14
+ if (typeof error.cause === "string" && error.cause.trim().length > 0) return error.cause;
15
+ if (error.message.trim().length > 0) return error.message;
16
+ }
17
+ if (typeof error === "string" && error.trim().length > 0) return error;
18
+ if (error && typeof error === "object") {
19
+ const errorObj = error;
20
+ const candidates = [
21
+ errorObj["message"],
22
+ errorObj["cause"],
23
+ errorObj["code"],
24
+ errorObj["statusText"]
25
+ ];
26
+ for (const candidate of candidates) if (typeof candidate === "string" && candidate.trim().length > 0) return candidate;
27
+ }
28
+ }
29
+ function extractRequestUrl(error) {
30
+ if (!error || typeof error !== "object") return;
31
+ const candidates = [];
32
+ const errorObj = error;
33
+ candidates.push(errorObj["requestUrl"], errorObj["url"]);
34
+ if (errorObj["cause"] && typeof errorObj["cause"] === "object") {
35
+ const causeObj = errorObj["cause"];
36
+ candidates.push(causeObj["requestUrl"], causeObj["url"]);
37
+ }
38
+ for (const candidate of candidates) if (typeof candidate === "string" && candidate.trim().length > 0) return candidate;
39
+ }
40
+ /** A flattened error crossing the wire: the server sends `{ name, message }`, not an `Error`. */
41
+ function isSerializedError(value) {
42
+ return typeof value === "object" && value !== null && "name" in value && typeof value.name === "string" && "message" in value && typeof value.message === "string";
43
+ }
44
+ function toError(error) {
45
+ if (error instanceof Error) return error;
46
+ if (!isSerializedError(error)) return new Error(String(error));
47
+ const rebuilt = new Error(error.message);
48
+ rebuilt.name = error.name;
49
+ return rebuilt;
50
+ }
51
+ function errorTypeOf(error, message, status) {
52
+ const kind = classifyProviderError(typeof status === "number" ? {
53
+ statusCode: status,
54
+ cause: error
55
+ } : error);
56
+ if (kind === "quota") return "quota";
57
+ if (kind === "rate_limited" || status === 429 || message.includes("429")) return "rate_limit";
58
+ if (kind === "auth" || status === 401 || status === 403 || kind !== "unavailable" && (message.includes("unauthorized") || message.includes("authentication") || message.includes("api key"))) return "auth";
59
+ if (message.includes("network") || message.includes("econnrefused") || message.includes("enotfound") || message.includes("fetch failed") || message.includes("connection")) return "network";
60
+ if (kind === "timeout") return "timeout";
61
+ if (kind === "model_rejected" || message.includes("does not exist")) return "model_not_found";
62
+ if (kind === "context_overflow" || message.includes("context length") || message.includes("too many tokens") || message.includes("token limit")) return "context_length";
63
+ if (message.includes("content filter") || message.includes("content_filter") || message.includes("content policy") || message.includes("safety") || message.includes("prohibited")) return "content_filter";
64
+ if (kind === "unavailable" || typeof status === "number" && status >= 500 && status < 600) return "server_error";
65
+ if (kind === "invalid_request" || kind === "tool_history_rejected" || status === 400 || message.includes("invalid request") || message.includes("bad request")) return "invalid_request";
66
+ return "unknown";
67
+ }
68
+ function parseError(error) {
69
+ const err = toError(error);
70
+ const errorObj = typeof error === "object" && error !== null ? error : {};
71
+ const detail = summarizeErrorDetail(error);
72
+ const requestUrl = extractRequestUrl(error);
73
+ if (err.name === "ProviderAuthRequiredError") return {
74
+ message: err.message,
75
+ detail,
76
+ requestUrl,
77
+ type: "auth",
78
+ retryable: false,
79
+ originalError: err
80
+ };
81
+ const type = errorTypeOf(error, err.message.toLowerCase(), errorObj.statusCode ?? errorObj.status);
82
+ switch (type) {
83
+ case "quota": return {
84
+ message: "Usage quota exhausted for this provider account.",
85
+ detail,
86
+ requestUrl,
87
+ type,
88
+ retryable: false,
89
+ originalError: err
90
+ };
91
+ case "rate_limit": return {
92
+ message: "Rate limited. Please wait a moment before trying again.",
93
+ type,
94
+ retryable: true,
95
+ retryDelay: extractRetryAfter(errorObj) || 5e3,
96
+ originalError: err
97
+ };
98
+ case "auth": return {
99
+ message: (errorObj.statusCode ?? errorObj.status) === 403 ? "Access denied. You may not have permission to use this model." : "Authentication failed. Check the credential configured for this provider.",
100
+ detail,
101
+ requestUrl,
102
+ type,
103
+ retryable: false,
104
+ originalError: err
105
+ };
106
+ case "network": return {
107
+ message: "Network error while contacting the provider or gateway.",
108
+ detail,
109
+ requestUrl,
110
+ type,
111
+ retryable: true,
112
+ retryDelay: 2e3,
113
+ originalError: err
114
+ };
115
+ case "timeout": return {
116
+ message: "Request timed out. The server may be overloaded.",
117
+ type,
118
+ retryable: true,
119
+ retryDelay: 3e3,
120
+ originalError: err
121
+ };
122
+ case "model_not_found": return {
123
+ message: "Model not found. Please select a different model with /models.",
124
+ type,
125
+ retryable: false,
126
+ originalError: err
127
+ };
128
+ case "context_length": return {
129
+ message: "Message too long. Try starting a new thread with /new.",
130
+ type,
131
+ retryable: false,
132
+ originalError: err
133
+ };
134
+ case "content_filter": return {
135
+ message: "The provider's safety system blocked this request. This is often a false positive on code, security, or credential-like text.",
136
+ detail: err.message.trim() ? err.message : detail,
137
+ requestUrl,
138
+ type,
139
+ retryable: false,
140
+ originalError: err
141
+ };
142
+ case "server_error": return {
143
+ message: "Server error. The API may be experiencing issues.",
144
+ type,
145
+ retryable: true,
146
+ retryDelay: 5e3,
147
+ originalError: err
148
+ };
149
+ case "invalid_request": return {
150
+ message: `Invalid request: ${extractErrorDetail(err)}`,
151
+ type,
152
+ retryable: false,
153
+ originalError: err
154
+ };
155
+ case "unknown": return {
156
+ message: extractErrorDetail(err),
157
+ type,
158
+ retryable: false,
159
+ originalError: err
160
+ };
161
+ }
162
+ }
163
+ /**
164
+ * Extract retry-after header value from error.
165
+ */
166
+ function extractRetryAfter(error) {
167
+ const headers = error.headers;
168
+ const retryAfter = error.retryAfter || headers?.["retry-after"];
169
+ if (typeof retryAfter === "number") return retryAfter * 1e3;
170
+ if (typeof retryAfter === "string") {
171
+ const seconds = parseInt(retryAfter, 10);
172
+ if (!isNaN(seconds)) return seconds * 1e3;
173
+ }
174
+ }
175
+ /**
176
+ * Extract a useful error detail from an error object.
177
+ */
178
+ function extractErrorDetail(error) {
179
+ const errorObj = error;
180
+ if (errorObj.error && typeof errorObj.error === "object") {
181
+ const apiError = errorObj.error;
182
+ if (apiError.message) return String(apiError.message);
183
+ }
184
+ if (errorObj.message) return String(errorObj.message);
185
+ if (errorObj.detail) return String(errorObj.detail);
186
+ if (errorObj.reason) return String(errorObj.reason);
187
+ let message = error.message;
188
+ message = message.replace(/^(error|exception|failed):\s*/i, "");
189
+ if (message.length > 200) message = message.substring(0, 200) + "...";
190
+ return message || "An unknown error occurred";
191
+ }
192
+ /**
193
+ * Sleep for a given number of milliseconds.
194
+ */
195
+ function sleep(ms) {
196
+ return new Promise((resolve) => setTimeout(resolve, ms));
197
+ }
198
+ /**
199
+ * Retry a function with exponential backoff.
200
+ */
201
+ async function withRetry(fn, options = {}) {
202
+ const { maxRetries = 3, initialDelay = 1e3, maxDelay = 3e4, onRetry } = options;
203
+ let lastError;
204
+ for (let attempt = 0; attempt <= maxRetries; attempt++) try {
205
+ return await fn();
206
+ } catch (error) {
207
+ lastError = parseError(error);
208
+ if (!lastError.retryable || attempt === maxRetries) throw lastError.originalError;
209
+ const delay = Math.min(lastError.retryDelay || initialDelay * Math.pow(2, attempt), maxDelay);
210
+ if (onRetry) onRetry(lastError, attempt + 1);
211
+ await sleep(delay);
212
+ }
213
+ throw lastError?.originalError || /* @__PURE__ */ new Error("Retry failed");
214
+ }
215
+ export { parseError, sleep, withRetry };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Gateway sync utility for keeping the model registry up to date.
3
+ *
4
+ * This is a thin wrapper around `@mastra/core/llm`'s `GatewayRegistry` so
5
+ * mastracode and `mastra dev` share a single implementation for fetching
6
+ * providers, generating types, and writing to the global cache. Keep this
7
+ * file small — provider/registry logic belongs in `@mastra/core`.
8
+ */
9
+ /**
10
+ * Sync gateways and update the global cache via `@mastra/core`'s registry.
11
+ *
12
+ * Skips the sync if the global cache was refreshed within the last
13
+ * `DEFAULT_SYNC_INTERVAL_MS`, unless `force` is set. Multiple calls in
14
+ * the same process coalesce while a sync is in flight.
15
+ */
16
+ export declare function syncGateways(force?: boolean): Promise<void>;
17
+ /**
18
+ * Start periodic gateway sync.
19
+ * @param intervalMs Sync interval in milliseconds (default: 5 minutes)
20
+ */
21
+ export declare function startGatewaySync(intervalMs?: number): void;
22
+ /**
23
+ * Stop periodic gateway sync.
24
+ */
25
+ export declare function stopGatewaySync(): void;
26
+ //# sourceMappingURL=gateway-sync.d.ts.map
@@ -0,0 +1,58 @@
1
+ import { GatewayRegistry } from "@mastra/core/llm";
2
+ // src/utils/gateway-sync.ts
3
+ /**
4
+ * Gateway sync utility for keeping the model registry up to date.
5
+ *
6
+ * This is a thin wrapper around `@mastra/core/llm`'s `GatewayRegistry` so
7
+ * mastracode and `mastra dev` share a single implementation for fetching
8
+ * providers, generating types, and writing to the global cache. Keep this
9
+ * file small — provider/registry logic belongs in `@mastra/core`.
10
+ */
11
+ const DEFAULT_SYNC_INTERVAL_MS = 3e5;
12
+ let syncInterval = null;
13
+ let isSyncing = false;
14
+ function getRegistry() {
15
+ return GatewayRegistry.getInstance({ useDynamicLoading: true });
16
+ }
17
+ /**
18
+ * Sync gateways and update the global cache via `@mastra/core`'s registry.
19
+ *
20
+ * Skips the sync if the global cache was refreshed within the last
21
+ * `DEFAULT_SYNC_INTERVAL_MS`, unless `force` is set. Multiple calls in
22
+ * the same process coalesce while a sync is in flight.
23
+ */
24
+ async function syncGateways(force = false) {
25
+ if (isSyncing && !force) return;
26
+ if (!force) {
27
+ const lastSync = getRegistry().getLastRefreshTime();
28
+ if (lastSync && Date.now() - lastSync.getTime() < DEFAULT_SYNC_INTERVAL_MS) return;
29
+ }
30
+ isSyncing = true;
31
+ try {
32
+ await getRegistry().syncGateways(true);
33
+ } catch {} finally {
34
+ isSyncing = false;
35
+ }
36
+ }
37
+ /**
38
+ * Start periodic gateway sync.
39
+ * @param intervalMs Sync interval in milliseconds (default: 5 minutes)
40
+ */
41
+ function startGatewaySync(intervalMs = DEFAULT_SYNC_INTERVAL_MS) {
42
+ if (syncInterval) return;
43
+ syncGateways().catch(() => {});
44
+ syncInterval = setInterval(() => {
45
+ syncGateways().catch(() => {});
46
+ }, intervalMs);
47
+ syncInterval.unref();
48
+ }
49
+ /**
50
+ * Stop periodic gateway sync.
51
+ */
52
+ function stopGatewaySync() {
53
+ if (syncInterval) {
54
+ clearInterval(syncInterval);
55
+ syncInterval = null;
56
+ }
57
+ }
58
+ export { startGatewaySync, stopGatewaySync, syncGateways };
@@ -0,0 +1,19 @@
1
+ import type { PruneResult, RetentionConfig } from '@mastra/core/storage';
2
+ import type { DuckDBStore } from '@mastra/duckdb';
3
+ /**
4
+ * Age limits for the local trace store: 14 days for spans, metrics and logs,
5
+ * 30 days for scores and feedback. Spans, logs and scores use the same windows
6
+ * as libsql's `DEFAULT_RETENTION`, which has no metrics or feedback entries.
7
+ */
8
+ export declare const LOCAL_OBSERVABILITY_RETENTION: RetentionConfig;
9
+ /**
10
+ * Open the local observability DuckDB file used when `/observability local on`.
11
+ * Connects eagerly so a lock error surfaces now, not mid-session, then prunes
12
+ * aged events in the background so the file cannot grow without bound.
13
+ * `pruned` never rejects; anything left over is pruned on the next open.
14
+ */
15
+ export declare function openLocalObservabilityStore(path: string): Promise<{
16
+ store: DuckDBStore;
17
+ pruned: Promise<PruneResult[]>;
18
+ }>;
19
+ //# sourceMappingURL=local-observability.d.ts.map