@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,83 @@
1
+ import { findSessionForThread } from "../agents/background-completion.js";
2
+ import { notificationDispatchLeaseKey } from "./signals-pubsub.js";
3
+ // src/utils/wake-session.ts
4
+ /** A session here serves the thread's resource, but the thread belongs to another project. */
5
+ const FOREIGN_THREAD = Symbol("foreign-thread");
6
+ /** A stable key for a session's thread scope, or `undefined` when it has none. */
7
+ function threadScopeKey(scope) {
8
+ const entries = Object.entries(scope).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
9
+ return entries.length > 0 ? JSON.stringify(entries) : void 0;
10
+ }
11
+ /**
12
+ * The session a wake for `threadId` should run as, or `FOREIGN_THREAD` when
13
+ * this process serves the resource but not the thread.
14
+ *
15
+ * A resource is not a project: processes in different directories can share
16
+ * one resource id (to share recall, say), and each then has a live session for
17
+ * it. Picking by resource alone runs the thread in whichever process asked,
18
+ * with that process's workspace, tools and cwd. The thread's scope tags (the
19
+ * ones `thread.create()` stamps, such as `projectPath`) say which session it
20
+ * belongs to. A thread with no scope tags, or with tags no session here
21
+ * contradicts, keeps going to the resource's session.
22
+ *
23
+ * A session that has the thread open always owns it. When the thread belongs to
24
+ * another project, that session delivers it under a lease for this one thread
25
+ * (`openThreadScope`), and the thread's own project yields it while another
26
+ * process holds that lease (`leases`), so only one process runs it and the
27
+ * project's other threads stay with the project.
28
+ */
29
+ async function findWakeSession(controller, liveSessions, { resourceId, threadId }, leases) {
30
+ const first = await findSessionForThread({
31
+ getSession: (sessionId) => controller.getSession(sessionId),
32
+ listLiveSessions: () => liveSessions
33
+ }, {
34
+ resourceId,
35
+ threadId
36
+ });
37
+ if (!first) return void 0;
38
+ const thread = await first.thread.getById({ threadId });
39
+ if (!thread || thread.resourceId !== resourceId) return { session: first };
40
+ const metadata = thread.metadata ?? {};
41
+ const candidates = [first, ...[...liveSessions].filter((session) => session !== first && session.identity.getResourceId() === resourceId)];
42
+ const matchesScope = (session) => Object.entries(session.getThreadScope()).every(([key, value]) => metadata[key] === void 0 || metadata[key] === value);
43
+ const open = candidates.find((session) => session.thread.getId() === threadId);
44
+ if (open) return {
45
+ session: open,
46
+ scope: matchesScope(open) ? threadLeaseScope(open, metadata) : openThreadScope(threadId)
47
+ };
48
+ const owner = candidates.find(matchesScope);
49
+ if (!owner) return FOREIGN_THREAD;
50
+ const scope = threadLeaseScope(owner, metadata);
51
+ if (scope !== void 0 && await leases?.getLeaseOwner(notificationDispatchLeaseKey(resourceId, openThreadScope(threadId)))) return FOREIGN_THREAD;
52
+ return {
53
+ session: owner,
54
+ scope
55
+ };
56
+ }
57
+ /**
58
+ * The dispatch lease scopes a session needs: its own, plus a lease for its open
59
+ * thread alone when that thread belongs to another project (`findWakeSession`).
60
+ */
61
+ async function sessionLeaseScopes(session) {
62
+ const own = threadScopeKey(session.getThreadScope());
63
+ const threadId = session.thread.getId();
64
+ if (!threadId) return [own];
65
+ const thread = await session.thread.getById({ threadId });
66
+ if (!thread || thread.resourceId !== session.identity.getResourceId()) return [own];
67
+ const metadata = thread.metadata ?? {};
68
+ return Object.entries(session.getThreadScope()).some(([key, value]) => metadata[key] !== void 0 && metadata[key] !== value) ? [own, openThreadScope(threadId)] : [own];
69
+ }
70
+ /** The lease scope for one thread a session has open from another project. */
71
+ function openThreadScope(threadId) {
72
+ return threadScopeKey({ openThread: threadId });
73
+ }
74
+ /**
75
+ * The lease scope covering a thread for `session`: the thread's own values for
76
+ * the session's scope keys, or unset when the thread lacks any of them.
77
+ */
78
+ function threadLeaseScope(session, metadata = {}) {
79
+ const keys = Object.keys(session.getThreadScope());
80
+ if (!keys.every((key) => metadata[key] !== void 0)) return void 0;
81
+ return threadScopeKey(Object.fromEntries(keys.map((key) => [key, String(metadata[key])])));
82
+ }
83
+ export { FOREIGN_THREAD, findWakeSession, sessionLeaseScopes, threadScopeKey };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Speech-to-text (STT) model registry for push-to-talk voice input.
3
+ *
4
+ * This is the single source of truth shared by the `/voice` settings picker,
5
+ * settings validation, and the cloud transcription resolver. Entries are
6
+ * derived from models.dev (https://models.dev/api.json): a model is treated as
7
+ * STT when its modalities are audio-in / text-out with no text input.
8
+ *
9
+ * Most cloud providers here speak the OpenAI `/audio/transcriptions` shape, so
10
+ * the cloud engine resolves them through Mastra's `OpenAIVoice` (`MastraVoice`)
11
+ * built on the OpenAI client — `openai` uses the default endpoint, every other
12
+ * OpenAI-compatible host supplies its `baseURL`. Deepgram is the exception: it
13
+ * is not OpenAI-compatible, so it resolves through `@mastra/voice-deepgram`
14
+ * (`DeepgramVoice`), and Mistral through `@mastra/voice-mistral`. Neither is
15
+ * in the models.dev STT snapshot, so both are added by hand.
16
+ *
17
+ * The accompanying snapshot test (`__tests__/stt-registry.test.ts`) re-derives
18
+ * the models.dev-backed entries from a checked-in snapshot so this list stays
19
+ * honest and can be refreshed deliberately rather than drifting by hand.
20
+ */
21
+ /**
22
+ * How a provider's transcription model is constructed.
23
+ * - `openai`: `OpenAIVoice` with the default OpenAI endpoint.
24
+ * - `openai-compatible`: `OpenAIVoice` pointed at the host's `baseURL`
25
+ * (its `/audio/transcriptions` endpoint follows the OpenAI shape).
26
+ * - `deepgram`: `DeepgramVoice` from `@mastra/voice-deepgram` (not
27
+ * OpenAI-compatible; uses the Deepgram SDK).
28
+ * - `mistral`: `MistralVoice` from `@mastra/voice-mistral`.
29
+ */
30
+ export type STTResolver = 'openai' | 'openai-compatible' | 'deepgram' | 'mistral';
31
+ export interface STTModel {
32
+ /** models.dev provider id (also the AuthStorage key for the API key). */
33
+ provider: string;
34
+ /** Bare model id passed to the provider's transcription factory. */
35
+ model: string;
36
+ /** Human-friendly label for the picker. */
37
+ label: string;
38
+ /** How to build the transcription model. */
39
+ resolver: STTResolver;
40
+ /** Base URL for `openai-compatible` providers (from models.dev `api`). */
41
+ baseURL?: string;
42
+ realtimeModel?: string;
43
+ }
44
+ /**
45
+ * The curated STT catalog. Order matters: the first entry for a provider is its
46
+ * default model, and the first overall entry (`openai`/`whisper-1`) is the
47
+ * global default.
48
+ */
49
+ export declare const STT_MODELS: readonly STTModel[];
50
+ /** The global default STT model (first registry entry). */
51
+ export declare const DEFAULT_STT_MODEL: STTModel;
52
+ /** The default STT provider when none is configured. */
53
+ export declare const DEFAULT_STT_PROVIDER: string;
54
+ /** Unique provider ids in registry order. */
55
+ export declare function sttProviders(): string[];
56
+ /** All models offered for a provider, in registry order. */
57
+ export declare function sttModelsForProvider(provider: string): STTModel[];
58
+ /** The default (first) model for a provider, or undefined if unknown. */
59
+ export declare function defaultModelForProvider(provider: string): STTModel | undefined;
60
+ export declare function findSTTModel(provider: string, model: string): STTModel | undefined;
61
+ /**
62
+ * Resolve a provider/model pair to a concrete registry entry.
63
+ * Falls back to the provider default (then the global default) so callers
64
+ * always get a usable entry even if settings name an unknown model.
65
+ */
66
+ export declare function resolveSTTModel(provider?: string, model?: string): STTModel;
67
+ //# sourceMappingURL=stt-registry.d.ts.map
@@ -0,0 +1,144 @@
1
+ // src/voice/stt-registry.ts
2
+ /**
3
+ * The curated STT catalog. Order matters: the first entry for a provider is its
4
+ * default model, and the first overall entry (`openai`/`whisper-1`) is the
5
+ * global default.
6
+ */
7
+ const STT_MODELS = [
8
+ {
9
+ provider: "openai",
10
+ model: "whisper-1",
11
+ label: "OpenAI Whisper",
12
+ resolver: "openai"
13
+ },
14
+ {
15
+ provider: "openai",
16
+ model: "gpt-4o-transcribe",
17
+ label: "OpenAI GPT-4o Transcribe",
18
+ resolver: "openai"
19
+ },
20
+ {
21
+ provider: "openai",
22
+ model: "gpt-4o-mini-transcribe",
23
+ label: "OpenAI GPT-4o mini Transcribe",
24
+ resolver: "openai"
25
+ },
26
+ {
27
+ provider: "groq",
28
+ model: "whisper-large-v3-turbo",
29
+ label: "Groq Whisper Large v3 Turbo",
30
+ resolver: "openai-compatible",
31
+ baseURL: "https://api.groq.com/openai/v1"
32
+ },
33
+ {
34
+ provider: "groq",
35
+ model: "whisper-large-v3",
36
+ label: "Groq Whisper Large v3",
37
+ resolver: "openai-compatible",
38
+ baseURL: "https://api.groq.com/openai/v1"
39
+ },
40
+ {
41
+ provider: "deepgram",
42
+ model: "nova-3",
43
+ label: "Deepgram Nova-3",
44
+ resolver: "deepgram"
45
+ },
46
+ {
47
+ provider: "mistral",
48
+ model: "voxtral-mini-latest",
49
+ label: "Mistral Voxtral Mini",
50
+ resolver: "mistral",
51
+ realtimeModel: "voxtral-mini-transcribe-realtime-3"
52
+ },
53
+ {
54
+ provider: "alibaba",
55
+ model: "qwen3-asr-flash",
56
+ label: "Alibaba Qwen3 ASR Flash",
57
+ resolver: "openai-compatible",
58
+ baseURL: "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"
59
+ },
60
+ {
61
+ provider: "alibaba-cn",
62
+ model: "qwen3-asr-flash",
63
+ label: "Alibaba Qwen3 ASR Flash (China)",
64
+ resolver: "openai-compatible",
65
+ baseURL: "https://dashscope.aliyuncs.com/compatible-mode/v1"
66
+ },
67
+ {
68
+ provider: "scaleway",
69
+ model: "whisper-large-v3",
70
+ label: "Scaleway Whisper Large v3",
71
+ resolver: "openai-compatible",
72
+ baseURL: "https://api.scaleway.ai/v1"
73
+ },
74
+ {
75
+ provider: "nvidia",
76
+ model: "openai/whisper-large-v3",
77
+ label: "Nvidia Whisper Large v3",
78
+ resolver: "openai-compatible",
79
+ baseURL: "https://integrate.api.nvidia.com/v1"
80
+ },
81
+ {
82
+ provider: "nearai",
83
+ model: "openai/whisper-large-v3",
84
+ label: "NEAR AI Whisper Large v3",
85
+ resolver: "openai-compatible",
86
+ baseURL: "https://cloud-api.near.ai/v1"
87
+ },
88
+ {
89
+ provider: "evroc",
90
+ model: "openai/whisper-large-v3-turbo",
91
+ label: "evroc Whisper Large v3 Turbo",
92
+ resolver: "openai-compatible",
93
+ baseURL: "https://models.think.evroc.com/v1"
94
+ },
95
+ {
96
+ provider: "evroc",
97
+ model: "openai/whisper-large-v3",
98
+ label: "evroc Whisper Large v3",
99
+ resolver: "openai-compatible",
100
+ baseURL: "https://models.think.evroc.com/v1"
101
+ },
102
+ {
103
+ provider: "evroc",
104
+ model: "KBLab/kb-whisper-large",
105
+ label: "evroc KB-Whisper Large",
106
+ resolver: "openai-compatible",
107
+ baseURL: "https://models.think.evroc.com/v1"
108
+ }
109
+ ];
110
+ /** The global default STT model (first registry entry). */
111
+ const DEFAULT_STT_MODEL = STT_MODELS[0];
112
+ /** The default STT provider when none is configured. */
113
+ const DEFAULT_STT_PROVIDER = DEFAULT_STT_MODEL.provider;
114
+ /** Unique provider ids in registry order. */
115
+ function sttProviders() {
116
+ const seen = /* @__PURE__ */ new Set();
117
+ const out = [];
118
+ for (const m of STT_MODELS) if (!seen.has(m.provider)) {
119
+ seen.add(m.provider);
120
+ out.push(m.provider);
121
+ }
122
+ return out;
123
+ }
124
+ /** All models offered for a provider, in registry order. */
125
+ function sttModelsForProvider(provider) {
126
+ return STT_MODELS.filter((m) => m.provider === provider);
127
+ }
128
+ /** The default (first) model for a provider, or undefined if unknown. */
129
+ function defaultModelForProvider(provider) {
130
+ return STT_MODELS.find((m) => m.provider === provider);
131
+ }
132
+ function findSTTModel(provider, model) {
133
+ return STT_MODELS.find((m) => m.provider === provider && m.model === model);
134
+ }
135
+ /**
136
+ * Resolve a provider/model pair to a concrete registry entry.
137
+ * Falls back to the provider default (then the global default) so callers
138
+ * always get a usable entry even if settings name an unknown model.
139
+ */
140
+ function resolveSTTModel(provider, model) {
141
+ if (!provider) return DEFAULT_STT_MODEL;
142
+ return (model ? findSTTModel(provider, model) : void 0) ?? defaultModelForProvider(provider) ?? DEFAULT_STT_MODEL;
143
+ }
144
+ export { DEFAULT_STT_MODEL, DEFAULT_STT_PROVIDER, STT_MODELS, defaultModelForProvider, findSTTModel, resolveSTTModel, sttModelsForProvider, sttProviders };
@@ -0,0 +1,10 @@
1
+ import type { AuthStorage } from '../auth/storage.js';
2
+ import type { STTModel } from './stt-registry.js';
3
+ export declare function sttApiKeyEnvVar(provider: string): string | undefined;
4
+ export declare function resolveSTTApiKey(provider: string, authStorage?: AuthStorage): string | undefined;
5
+ export interface STTTranscriber {
6
+ /** `filetype` is the extension the provider reads the format from (`wav`, `webm`, `m4a`…). */
7
+ transcribe(audio: Buffer, filetype: string): Promise<string>;
8
+ }
9
+ export declare function createSTTTranscriber(entry: STTModel, apiKey: string): Promise<STTTranscriber>;
10
+ //# sourceMappingURL=transcribe.d.ts.map
@@ -0,0 +1,75 @@
1
+ import { providerApiKeyEnvVar } from "../agents/mastracode-gateway.js";
2
+ import { Readable } from "stream";
3
+ // src/voice/transcribe.ts
4
+ const STT_ONLY_API_KEY_ENV_VARS = { deepgram: "DEEPGRAM_API_KEY" };
5
+ const STT_TIMEOUT_MS = 6e4;
6
+ const STT_MAX_RETRIES = 1;
7
+ function sttApiKeyEnvVar(provider) {
8
+ return STT_ONLY_API_KEY_ENV_VARS[provider] ?? providerApiKeyEnvVar(provider);
9
+ }
10
+ function resolveSTTApiKey(provider, authStorage) {
11
+ const envVar = sttApiKeyEnvVar(provider);
12
+ return (envVar ? process.env[envVar]?.trim() : void 0) || authStorage?.getStoredApiKey(provider);
13
+ }
14
+ function listenWithFiletype(voice) {
15
+ return (audio, filetype) => voice.listen(Readable.from(audio), { filetype });
16
+ }
17
+ function openAIClientOptions(entry, apiKey) {
18
+ return {
19
+ timeout: STT_TIMEOUT_MS,
20
+ maxRetries: STT_MAX_RETRIES,
21
+ ...apiKey === process.env.OPENAI_API_KEY?.trim() ? {} : {
22
+ organization: null,
23
+ project: null
24
+ },
25
+ ...entry.resolver === "openai-compatible" && entry.baseURL ? { baseURL: entry.baseURL } : {}
26
+ };
27
+ }
28
+ async function buildListen(entry, apiKey) {
29
+ if (entry.resolver === "deepgram") {
30
+ const { DeepgramVoice } = await import("@mastra/voice-deepgram");
31
+ const voice = new DeepgramVoice({ listeningModel: {
32
+ name: entry.model,
33
+ apiKey
34
+ } });
35
+ return (audio) => voice.listen(Readable.from(audio));
36
+ }
37
+ const speechModel = { apiKey };
38
+ if (entry.resolver === "mistral") {
39
+ const { MistralVoice } = await import("@mastra/voice-mistral");
40
+ return listenWithFiletype(new MistralVoice({
41
+ speechModel,
42
+ listeningModel: {
43
+ name: entry.model,
44
+ apiKey
45
+ }
46
+ }));
47
+ }
48
+ const { OpenAIVoice } = await import("@mastra/voice-openai");
49
+ return listenWithFiletype(new OpenAIVoice({
50
+ speechModel,
51
+ listeningModel: {
52
+ name: entry.model,
53
+ apiKey,
54
+ options: openAIClientOptions(entry, apiKey)
55
+ }
56
+ }));
57
+ }
58
+ function normalizeTranscript(result) {
59
+ return (typeof result === "string" ? result : result.transcript ?? "").trim();
60
+ }
61
+ async function createSTTTranscriber(entry, apiKey) {
62
+ const listen = await buildListen(entry, apiKey);
63
+ return { async transcribe(audio, filetype) {
64
+ let timer;
65
+ const timeout = new Promise((_, reject) => {
66
+ timer = setTimeout(() => reject(/* @__PURE__ */ new Error("Speech-to-text timed out after 1 minute.")), STT_TIMEOUT_MS);
67
+ });
68
+ try {
69
+ return normalizeTranscript(await Promise.race([listen(audio, filetype), timeout]));
70
+ } finally {
71
+ clearTimeout(timer);
72
+ }
73
+ } };
74
+ }
75
+ export { createSTTTranscriber, resolveSTTApiKey, sttApiKeyEnvVar };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Statically register workflow-related primitives on the mastracode Mastra
3
+ * instance so `mastra.listTools()` + `mastra.listAgents()` — and, therefore,
4
+ * the workflow-builder's discovery + the workflow rehydrator — see everything
5
+ * a workflow might want to compose:
6
+ *
7
+ * - workflow-builder sub-agent (so `create-workflow` can delegate)
8
+ * - code-agent (as a plain agent, callable via agent steps)
9
+ * - workspace tools (view/write/edit/find_files/execute_command/etc.)
10
+ * - configured model-independent web tools so workflows can compose search/extract steps
11
+ * - notification_inbox
12
+ * - snapshot of MCP tools from mcpManager
13
+ *
14
+ * Called after `controller.init()` but before `startWorkers()` in both boot
15
+ * paths, so `loadStoredWorkflows()` (inside startWorkers) sees the full
16
+ * registry when rehydrating previously-saved workflows.
17
+ *
18
+ * Tradeoffs:
19
+ * - MCP tools are snapshotted. Servers added after boot are invisible to
20
+ * the workflow-builder until restart.
21
+ * - Provider-native (Anthropic/OpenAI) web
22
+ * tools are skipped because they'd freeze workflows to one model provider.
23
+ * - Workflow tool steps get the closed-over workspace + auth (web provider
24
+ * key, MCP server credentials), not per-request permissions — deliberate; if
25
+ * the user built + saved the workflow they meant to run it.
26
+ */
27
+ import type { Agent } from '@mastra/core/agent';
28
+ import type { Mastra } from '@mastra/core/mastra';
29
+ import type { McpManager } from '../mcp/index.js';
30
+ export interface RegisterWorkflowBuilderPrimitivesOptions {
31
+ projectPath: string;
32
+ /**
33
+ * Extra allowed paths the workspace can read/write. Mastracode normally
34
+ * collects skill paths + sandboxAllowedPaths per-request; for the workflow
35
+ * workspace we accept anything the caller wants up-front and trust the
36
+ * worker process to honour the user's intent.
37
+ */
38
+ allowedPaths?: string[];
39
+ /**
40
+ * The code-agent Agent instance. Registered as `code-agent` so workflows
41
+ * can compose it in agent steps. It already has full dynamic tool access
42
+ * (workspace/MCP/web/etc.) via its own `tools: createDynamicTools(...)`.
43
+ */
44
+ codeAgent: Agent;
45
+ /**
46
+ * McpManager for snapshotting MCP tools at boot. Omit or pass undefined
47
+ * if MCP is disabled — workflow-builder will just see fewer tools.
48
+ */
49
+ mcpManager?: McpManager;
50
+ }
51
+ export declare function registerWorkflowBuilderPrimitives(mastra: Mastra, options: RegisterWorkflowBuilderPrimitivesOptions): Promise<void>;
52
+ //# sourceMappingURL=register-primitives.d.ts.map
@@ -0,0 +1,40 @@
1
+ import { createMastraCodeWorkspaceTools } from "../agents/tool-availability.js";
2
+ import { LazyNotificationsStorage } from "../agents/tools.js";
3
+ import { workflowBuilderAgent } from "../agents/workflow-builder-agent.js";
4
+ import { MC_TOOLS } from "../tool-names.js";
5
+ import { createConfiguredWebTools } from "../tools/web-search.js";
6
+ import { LocalFilesystem, LocalSandbox, Workspace, createWorkspaceTools } from "@mastra/core/workspace";
7
+ import { createNotificationInboxTool } from "@mastra/core/notifications";
8
+ // src/workflows/register-primitives.ts
9
+ async function registerWorkflowBuilderPrimitives(mastra, options) {
10
+ const { projectPath, allowedPaths = [], codeAgent, mcpManager } = options;
11
+ mastra.addAgent(workflowBuilderAgent, "workflow-builder");
12
+ mastra.addAgent(codeAgent, "code-agent");
13
+ const workspace = new Workspace({
14
+ id: "workflow-builder-workspace",
15
+ name: "Mastra Code Workspace (workflows)",
16
+ filesystem: new LocalFilesystem({
17
+ basePath: projectPath,
18
+ allowedPaths: [projectPath, ...allowedPaths]
19
+ }),
20
+ sandbox: new LocalSandbox({
21
+ workingDirectory: projectPath,
22
+ timeout: 3e4
23
+ }),
24
+ tools: createMastraCodeWorkspaceTools()
25
+ });
26
+ const workspaceTools = await createWorkspaceTools(workspace, { workspace });
27
+ for (const [toolId, tool] of Object.entries(workspaceTools)) mastra.addTool(tool, toolId);
28
+ const configuredWebTools = await createConfiguredWebTools();
29
+ if (configuredWebTools) {
30
+ mastra.addTool(configuredWebTools.web_search, "web-search");
31
+ mastra.addTool(configuredWebTools.web_extract, "web-extract");
32
+ }
33
+ const storage = mastra.getStorage();
34
+ if (storage) {
35
+ const notificationInbox = createNotificationInboxTool({ storage: new LazyNotificationsStorage(storage) });
36
+ mastra.addTool(notificationInbox, MC_TOOLS.NOTIFICATION_INBOX);
37
+ }
38
+ if (mcpManager) for (const [toolId, tool] of Object.entries(mcpManager.getTools())) mastra.addTool(tool, toolId);
39
+ }
40
+ export { registerWorkflowBuilderPrimitives };
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Thin wrapper around `mastra.getStorage().getStore('workflowDefinitions')` and
3
+ * `mastra.getWorkflow(id).createRun().stream(...)` so both the parent-mode
4
+ * tools and the `/workflows` slash command go through one implementation.
5
+ */
6
+ import type { Mastra } from '@mastra/core/mastra';
7
+ export interface StoredWorkflowRow {
8
+ id: string;
9
+ description?: string;
10
+ status: 'active' | 'archived';
11
+ inputSchema?: unknown;
12
+ outputSchema?: unknown;
13
+ graph?: unknown[];
14
+ createdAt?: Date;
15
+ updatedAt?: Date;
16
+ }
17
+ export interface RunResult {
18
+ status: string;
19
+ result?: unknown;
20
+ error?: unknown;
21
+ steps?: Record<string, unknown>;
22
+ tripwire?: {
23
+ reason?: string;
24
+ retry?: unknown;
25
+ metadata?: unknown;
26
+ processorId?: string;
27
+ };
28
+ }
29
+ export interface WorkflowRunEvent {
30
+ type: string;
31
+ payload?: Record<string, unknown> & {
32
+ id?: string;
33
+ };
34
+ [key: string]: unknown;
35
+ }
36
+ export type WorkflowRunEventCallback = (event: WorkflowRunEvent) => void;
37
+ export declare function listWorkflows(mastra: Mastra): Promise<{
38
+ workflows: StoredWorkflowRow[];
39
+ total: number;
40
+ }>;
41
+ export declare function getWorkflow(mastra: Mastra, id: string): Promise<StoredWorkflowRow | null>;
42
+ export declare function deleteWorkflow(mastra: Mastra, id: string): Promise<{
43
+ ok: true;
44
+ id: string;
45
+ }>;
46
+ export declare function runWorkflow(mastra: Mastra, workflowId: string, inputData: unknown,
47
+ /**
48
+ * Optional. When provided, passed through to `run.stream(...)` so agent steps
49
+ * (like `code-agent`) that depend on session state — `getDynamicModel` reads
50
+ * `controller.session.modelId` off it — can resolve correctly.
51
+ *
52
+ * Chat-driven `run-workflow` inherits its context from the parent code-agent
53
+ * turn, so this is unused there. The `/workflows run` slash handler builds a
54
+ * synthetic context from the current TUI session and passes it here.
55
+ */
56
+ requestContext?: unknown,
57
+ /**
58
+ * Optional. When provided, invoked for every `WorkflowStreamEvent` the run
59
+ * emits — used by the `/workflows run` slash handler to render live per-step
60
+ * progress in the TUI. Non-fatal: errors in the callback are swallowed so a
61
+ * misbehaving consumer can't take the workflow down.
62
+ */
63
+ onEvent?: WorkflowRunEventCallback): Promise<RunResult>;
64
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1,50 @@
1
+ // src/workflows/service.ts
2
+ async function workflowDefinitionsStore(mastra) {
3
+ const storage = mastra.getStorage();
4
+ if (!storage) throw new Error("Storage is not configured on the Mastra instance.");
5
+ const store = await storage.getStore("workflowDefinitions");
6
+ if (!store) throw new Error("workflowDefinitions storage domain is not available.");
7
+ return store;
8
+ }
9
+ async function listWorkflows(mastra) {
10
+ const result = await (await workflowDefinitionsStore(mastra)).list({ status: "active" });
11
+ return {
12
+ workflows: result.definitions,
13
+ total: result.total
14
+ };
15
+ }
16
+ async function getWorkflow(mastra, id) {
17
+ return (await workflowDefinitionsStore(mastra)).get(id);
18
+ }
19
+ async function deleteWorkflow(mastra, id) {
20
+ await (await workflowDefinitionsStore(mastra)).delete(id);
21
+ mastra.removeWorkflow(id);
22
+ return {
23
+ ok: true,
24
+ id
25
+ };
26
+ }
27
+ async function runWorkflow(mastra, workflowId, inputData, requestContext, onEvent) {
28
+ let wf;
29
+ let lookupError;
30
+ try {
31
+ wf = mastra.getWorkflow(workflowId);
32
+ } catch (error) {
33
+ lookupError = error;
34
+ }
35
+ if (!wf) throw new Error(`No workflow registered with id "${workflowId}". Was it built and saved?`, { cause: lookupError });
36
+ const run = await wf.createRun();
37
+ if (!onEvent) return await run.start({
38
+ inputData,
39
+ requestContext
40
+ });
41
+ const output = run.stream({
42
+ inputData,
43
+ requestContext
44
+ });
45
+ for await (const event of output.fullStream) try {
46
+ onEvent(event);
47
+ } catch {}
48
+ return await output.result;
49
+ }
50
+ export { deleteWorkflow, getWorkflow, listWorkflows, runWorkflow };