@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,55 @@
1
+ /**
2
+ * Granular tool permission system.
3
+ *
4
+ * Tools are classified into categories by risk level.
5
+ * Each category has a configurable policy: "allow", "ask", or "deny".
6
+ * Session-scoped grants let the user approve a category once per session.
7
+ */
8
+ export type ToolCategory = 'read' | 'edit' | 'execute' | 'mcp';
9
+ export declare const TOOL_CATEGORIES: Record<ToolCategory, {
10
+ label: string;
11
+ description: string;
12
+ }>;
13
+ /**
14
+ * Get the category for a tool, or null if the tool is always-allowed.
15
+ */
16
+ export declare function getToolCategory(toolName: string): ToolCategory | null;
17
+ /**
18
+ * Get the list of known tools for a given category.
19
+ */
20
+ export declare function getToolsForCategory(category: ToolCategory): string[];
21
+ export type PermissionPolicy = 'allow' | 'ask' | 'deny';
22
+ export interface PermissionRules {
23
+ /** Policy per category. Missing categories default to their DEFAULT_POLICIES value. */
24
+ categories: Partial<Record<ToolCategory, PermissionPolicy>>;
25
+ /** Per-tool overrides. Tool name → policy. Takes precedence over category. */
26
+ tools: Record<string, PermissionPolicy>;
27
+ }
28
+ /** Default policies when no rules are configured (YOLO=false equivalent). */
29
+ export declare const DEFAULT_POLICIES: Record<ToolCategory, PermissionPolicy>;
30
+ /** YOLO-mode policies — everything auto-allowed. */
31
+ export declare const YOLO_POLICIES: Record<ToolCategory, PermissionPolicy>;
32
+ export declare function createDefaultRules(): PermissionRules;
33
+ export declare class SessionGrants {
34
+ private grantedCategories;
35
+ private grantedTools;
36
+ allowCategory(category: ToolCategory): void;
37
+ allowTool(toolName: string): void;
38
+ isGranted(toolName: string, category: ToolCategory): boolean;
39
+ reset(): void;
40
+ getGrantedCategories(): ToolCategory[];
41
+ getGrantedTools(): string[];
42
+ }
43
+ export type ApprovalDecision = 'allow' | 'ask' | 'deny';
44
+ /**
45
+ * Determine whether a tool call should be allowed, prompted, or denied.
46
+ *
47
+ * Priority order:
48
+ * 1. Always-allowed tools (ask_user, task_write, etc.) → allow
49
+ * 2. Per-tool policy override → use that policy
50
+ * 3. Session grants (user said "always allow" during this session) → allow
51
+ * 4. Category policy → use that policy
52
+ * 5. Fallback → "ask"
53
+ */
54
+ export declare function resolveApproval(toolName: string, rules: PermissionRules, sessionGrants: SessionGrants): ApprovalDecision;
55
+ //# sourceMappingURL=permissions.d.ts.map
@@ -0,0 +1,139 @@
1
+ import { MC_TOOLS } from "./tool-names.js";
2
+ // src/permissions.ts
3
+ /**
4
+ * Granular tool permission system.
5
+ *
6
+ * Tools are classified into categories by risk level.
7
+ * Each category has a configurable policy: "allow", "ask", or "deny".
8
+ * Session-scoped grants let the user approve a category once per session.
9
+ */
10
+ const TOOL_CATEGORIES = {
11
+ read: {
12
+ label: "Read",
13
+ description: "Read files, search, list directories"
14
+ },
15
+ edit: {
16
+ label: "Edit",
17
+ description: "Create, modify, or delete files"
18
+ },
19
+ execute: {
20
+ label: "Execute",
21
+ description: "Run shell commands"
22
+ },
23
+ mcp: {
24
+ label: "MCP",
25
+ description: "External MCP server tools"
26
+ }
27
+ };
28
+ const TOOL_CATEGORY_MAP = {
29
+ [MC_TOOLS.VIEW]: "read",
30
+ [MC_TOOLS.SEARCH_CONTENT]: "read",
31
+ [MC_TOOLS.FIND_FILES]: "read",
32
+ [MC_TOOLS.LSP_INSPECT]: "read",
33
+ web_search: "read",
34
+ "web-search": "read",
35
+ web_extract: "read",
36
+ "web-extract": "read",
37
+ [MC_TOOLS.NOTIFICATION_INBOX]: "edit",
38
+ [MC_TOOLS.STRING_REPLACE_LSP]: "edit",
39
+ [MC_TOOLS.AST_SMART_EDIT]: "edit",
40
+ [MC_TOOLS.WRITE_FILE]: "edit",
41
+ subagent: "edit",
42
+ [MC_TOOLS.EXECUTE_COMMAND]: "execute",
43
+ "list-workflows": "read",
44
+ "get-workflow": "read",
45
+ "create-workflow": "edit",
46
+ "delete-workflow": "edit",
47
+ "run-workflow": "execute",
48
+ schedule_list: "read",
49
+ schedule_update: "edit",
50
+ schedule_create: "execute",
51
+ schedule_resume: "execute",
52
+ schedule_run: "execute"
53
+ };
54
+ const ALWAYS_ALLOW_TOOLS = /* @__PURE__ */ new Set([
55
+ "ask_user",
56
+ "task_write",
57
+ "task_update",
58
+ "task_complete",
59
+ "task_check",
60
+ "submit_plan",
61
+ "request_access"
62
+ ]);
63
+ /**
64
+ * Get the category for a tool, or null if the tool is always-allowed.
65
+ */
66
+ function getToolCategory(toolName) {
67
+ if (ALWAYS_ALLOW_TOOLS.has(toolName)) return null;
68
+ return TOOL_CATEGORY_MAP[toolName] ?? "mcp";
69
+ }
70
+ /**
71
+ * Get the list of known tools for a given category.
72
+ */
73
+ function getToolsForCategory(category) {
74
+ return Object.entries(TOOL_CATEGORY_MAP).filter(([, cat]) => cat === category).map(([tool]) => tool);
75
+ }
76
+ /** Default policies when no rules are configured (YOLO=false equivalent). */
77
+ const DEFAULT_POLICIES = {
78
+ read: "allow",
79
+ edit: "ask",
80
+ execute: "ask",
81
+ mcp: "ask"
82
+ };
83
+ /** YOLO-mode policies — everything auto-allowed. */
84
+ const YOLO_POLICIES = {
85
+ read: "allow",
86
+ edit: "allow",
87
+ execute: "allow",
88
+ mcp: "allow"
89
+ };
90
+ function createDefaultRules() {
91
+ return {
92
+ categories: { ...DEFAULT_POLICIES },
93
+ tools: {}
94
+ };
95
+ }
96
+ var SessionGrants = class {
97
+ grantedCategories = /* @__PURE__ */ new Set();
98
+ grantedTools = /* @__PURE__ */ new Set();
99
+ allowCategory(category) {
100
+ this.grantedCategories.add(category);
101
+ }
102
+ allowTool(toolName) {
103
+ this.grantedTools.add(toolName);
104
+ }
105
+ isGranted(toolName, category) {
106
+ return this.grantedTools.has(toolName) || this.grantedCategories.has(category);
107
+ }
108
+ reset() {
109
+ this.grantedCategories.clear();
110
+ this.grantedTools.clear();
111
+ }
112
+ getGrantedCategories() {
113
+ return [...this.grantedCategories];
114
+ }
115
+ getGrantedTools() {
116
+ return [...this.grantedTools];
117
+ }
118
+ };
119
+ /**
120
+ * Determine whether a tool call should be allowed, prompted, or denied.
121
+ *
122
+ * Priority order:
123
+ * 1. Always-allowed tools (ask_user, task_write, etc.) → allow
124
+ * 2. Per-tool policy override → use that policy
125
+ * 3. Session grants (user said "always allow" during this session) → allow
126
+ * 4. Category policy → use that policy
127
+ * 5. Fallback → "ask"
128
+ */
129
+ function resolveApproval(toolName, rules, sessionGrants) {
130
+ const category = getToolCategory(toolName);
131
+ if (category === null) return "allow";
132
+ const toolPolicy = rules.tools[toolName];
133
+ if (toolPolicy) return toolPolicy;
134
+ if (sessionGrants.isGranted(toolName, category)) return "allow";
135
+ const categoryPolicy = rules.categories[category];
136
+ if (categoryPolicy) return categoryPolicy;
137
+ return DEFAULT_POLICIES[category] ?? "ask";
138
+ }
139
+ export { DEFAULT_POLICIES, SessionGrants, TOOL_CATEGORIES, YOLO_POLICIES, createDefaultRules, getToolCategory, getToolsForCategory, resolveApproval };
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Mastra Platform client for Mastra Code.
3
+ *
4
+ * Shares `~/.mastra/credentials.json` with the `mastra` CLI so a single login
5
+ * works for both. Unlike the CLI flow, nothing here writes to stdout or reads
6
+ * stdin, so it is safe to drive from the TUI.
7
+ */
8
+ export declare const MASTRA_PLATFORM_API_URL: string;
9
+ export interface PlatformCredentials {
10
+ token: string;
11
+ refreshToken?: string;
12
+ user: {
13
+ id: string;
14
+ email: string;
15
+ firstName: string | null;
16
+ lastName: string | null;
17
+ };
18
+ organizationId: string;
19
+ currentOrgId?: string;
20
+ }
21
+ export interface PlatformOrg {
22
+ id: string;
23
+ name: string;
24
+ role?: string;
25
+ isCurrent?: boolean;
26
+ }
27
+ export interface PlatformProject {
28
+ id: string;
29
+ name: string;
30
+ slug: string | null;
31
+ organizationId: string;
32
+ }
33
+ export interface PlatformEnvironment {
34
+ id: string;
35
+ projectId: string;
36
+ name: string;
37
+ slug: string;
38
+ type: 'production' | 'staging' | 'preview';
39
+ instanceUrl: string | null;
40
+ customServerUrl: string | null;
41
+ }
42
+ export interface PlatformSession {
43
+ token: string;
44
+ orgId: string;
45
+ }
46
+ export declare function loadPlatformCredentials(filePath?: string): Promise<PlatformCredentials | null>;
47
+ export declare function savePlatformCredentials(creds: PlatformCredentials, filePath?: string): Promise<void>;
48
+ /**
49
+ * Returns a valid session from env (`MASTRA_API_TOKEN` + `MASTRA_ORG_ID`) or
50
+ * stored credentials, refreshing the token if needed. Returns null when the
51
+ * user must log in.
52
+ */
53
+ export declare function getPlatformSession(signal?: AbortSignal): Promise<PlatformSession | null>;
54
+ export interface PlatformLoginOptions {
55
+ signal?: AbortSignal;
56
+ timeoutMs?: number;
57
+ /** Called with the login URL so the UI can display it in case the browser does not open. */
58
+ onUrl?: (url: string) => void;
59
+ /** Override for tests. */
60
+ openUrl?: (url: string) => void;
61
+ credentialsPath?: string;
62
+ }
63
+ /** Browser-based Mastra Platform login using the same callback protocol as `mastra auth login`. */
64
+ export declare function loginToPlatform(options?: PlatformLoginOptions): Promise<PlatformCredentials>;
65
+ export declare function fetchPlatformOrgs(session: PlatformSession, signal?: AbortSignal): Promise<PlatformOrg[]>;
66
+ export declare function fetchPlatformProjects(session: PlatformSession, signal?: AbortSignal): Promise<PlatformProject[]>;
67
+ export declare function fetchPlatformEnvironments(session: PlatformSession, projectId: string, signal?: AbortSignal): Promise<PlatformEnvironment[]>;
68
+ export declare const FACTORY_DOMAIN = "factory.mastra.cloud";
69
+ /**
70
+ * The Factory server URL for a deployed environment: a custom server wins,
71
+ * otherwise the managed `<env slug>.factory.mastra.cloud` domain.
72
+ */
73
+ export declare function resolveFactoryUrl(env: PlatformEnvironment): string | null;
74
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,199 @@
1
+ import { join } from "path";
2
+ import { execFile } from "child_process";
3
+ import { homedir } from "os";
4
+ import { chmod, mkdir, readFile, writeFile } from "fs/promises";
5
+ import { createServer } from "http";
6
+ // src/platform/index.ts
7
+ /**
8
+ * Mastra Platform client for Mastra Code.
9
+ *
10
+ * Shares `~/.mastra/credentials.json` with the `mastra` CLI so a single login
11
+ * works for both. Unlike the CLI flow, nothing here writes to stdout or reads
12
+ * stdin, so it is safe to drive from the TUI.
13
+ */
14
+ const MASTRA_PLATFORM_API_URL = process.env.MASTRA_PLATFORM_API_URL || "https://platform.mastra.ai";
15
+ const CREDENTIALS_DIR = join(homedir(), ".mastra");
16
+ const CREDENTIALS_FILE = join(CREDENTIALS_DIR, "credentials.json");
17
+ async function loadPlatformCredentials(filePath = CREDENTIALS_FILE) {
18
+ try {
19
+ return JSON.parse(await readFile(filePath, "utf-8"));
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+ async function savePlatformCredentials(creds, filePath = CREDENTIALS_FILE) {
25
+ const dir = join(filePath, "..");
26
+ await mkdir(dir, {
27
+ recursive: true,
28
+ mode: 448
29
+ });
30
+ await writeFile(filePath, JSON.stringify(creds, null, 2), { mode: 384 });
31
+ await chmod(filePath, 384).catch(() => {});
32
+ }
33
+ async function verifyToken(token, signal) {
34
+ try {
35
+ return (await fetch(`${MASTRA_PLATFORM_API_URL}/v1/auth/verify`, {
36
+ headers: { Authorization: `Bearer ${token}` },
37
+ signal
38
+ })).ok;
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+ async function refreshToken(creds, signal) {
44
+ if (!creds.refreshToken) return null;
45
+ try {
46
+ const res = await fetch(`${MASTRA_PLATFORM_API_URL}/v1/auth/refresh-token`, {
47
+ method: "POST",
48
+ headers: { "Content-Type": "application/json" },
49
+ body: JSON.stringify({ refreshToken: creds.refreshToken }),
50
+ signal
51
+ });
52
+ if (!res.ok) return null;
53
+ const data = await res.json();
54
+ creds.token = data.accessToken;
55
+ creds.refreshToken = data.refreshToken;
56
+ await savePlatformCredentials(creds);
57
+ return data.accessToken;
58
+ } catch {
59
+ return null;
60
+ }
61
+ }
62
+ /**
63
+ * Returns a valid session from env (`MASTRA_API_TOKEN` + `MASTRA_ORG_ID`) or
64
+ * stored credentials, refreshing the token if needed. Returns null when the
65
+ * user must log in.
66
+ */
67
+ async function getPlatformSession(signal) {
68
+ const envToken = process.env.MASTRA_API_TOKEN;
69
+ const envOrg = process.env.MASTRA_ORG_ID;
70
+ if (envToken && envOrg) return {
71
+ token: envToken,
72
+ orgId: envOrg
73
+ };
74
+ const creds = await loadPlatformCredentials();
75
+ if (!creds) return null;
76
+ const orgId = envOrg ?? creds.currentOrgId ?? creds.organizationId;
77
+ if (await verifyToken(creds.token, signal)) return {
78
+ token: creds.token,
79
+ orgId
80
+ };
81
+ const refreshed = await refreshToken(creds, signal);
82
+ return refreshed ? {
83
+ token: refreshed,
84
+ orgId
85
+ } : null;
86
+ }
87
+ function openBrowser(url) {
88
+ const [cmd, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", [
89
+ "/c",
90
+ "start",
91
+ "",
92
+ url
93
+ ]] : ["xdg-open", [url]];
94
+ execFile(cmd, args, () => {});
95
+ }
96
+ const CALLBACK_HTML = (ok) => `<!doctype html><html><body style="background:#0d0d0d;color:#fff;font-family:system-ui;display:flex;align-items:center;justify-content:center;min-height:100vh"><div style="text-align:center"><h1>${ok ? "Logged in!" : "Login failed"}</h1><p>${ok ? "You can close this tab and return to Mastra Code." : "Close this tab and try again."}</p></div></body></html>`;
97
+ /** Browser-based Mastra Platform login using the same callback protocol as `mastra auth login`. */
98
+ async function loginToPlatform(options = {}) {
99
+ const { signal } = options;
100
+ signal?.throwIfAborted();
101
+ const server = createServer();
102
+ const state = Buffer.from(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16))).toString("hex");
103
+ const port = await new Promise((resolve, reject) => {
104
+ server.once("error", reject);
105
+ server.listen(0, "127.0.0.1", () => {
106
+ const addr = server.address();
107
+ if (typeof addr === "object" && addr) resolve(addr.port);
108
+ });
109
+ });
110
+ const loginUrl = `${MASTRA_PLATFORM_API_URL}/v1/auth/login?product=cli&cli_port=${port}&state=${state}`;
111
+ options.onUrl?.(loginUrl);
112
+ (options.openUrl ?? openBrowser)(loginUrl);
113
+ const creds = await new Promise((resolve, reject) => {
114
+ let settled = false;
115
+ const finish = (cb) => {
116
+ if (settled) return;
117
+ settled = true;
118
+ clearTimeout(timeout);
119
+ signal?.removeEventListener("abort", onAbort);
120
+ server.close(cb);
121
+ server.closeAllConnections();
122
+ };
123
+ const onAbort = () => finish(() => reject(/* @__PURE__ */ new Error("Login cancelled")));
124
+ const timeout = setTimeout(() => finish(() => reject(/* @__PURE__ */ new Error("Login timed out"))), options.timeoutMs ?? 3e5);
125
+ signal?.addEventListener("abort", onAbort, { once: true });
126
+ server.on("request", (req, res) => {
127
+ const url = new URL(req.url ?? "/", `http://localhost:${port}`);
128
+ if (url.pathname !== "/callback") return void res.writeHead(404).end();
129
+ const token = url.searchParams.get("token");
130
+ const userParam = url.searchParams.get("user");
131
+ const orgId = url.searchParams.get("org");
132
+ if (url.searchParams.get("state") !== state || !token || !userParam || !orgId) {
133
+ res.writeHead(400, { "Content-Type": "text/html" }).end(CALLBACK_HTML(false));
134
+ return;
135
+ }
136
+ let user;
137
+ try {
138
+ user = JSON.parse(decodeURIComponent(userParam));
139
+ } catch {
140
+ res.writeHead(400, { "Content-Type": "text/html" }).end(CALLBACK_HTML(false));
141
+ return;
142
+ }
143
+ const refresh = url.searchParams.get("refresh_token");
144
+ res.writeHead(200, {
145
+ "Content-Type": "text/html",
146
+ Connection: "close"
147
+ }).end(CALLBACK_HTML(true));
148
+ finish(() => resolve({
149
+ token,
150
+ ...refresh ? { refreshToken: refresh } : {},
151
+ user,
152
+ organizationId: orgId
153
+ }));
154
+ });
155
+ });
156
+ await savePlatformCredentials(creds, options.credentialsPath);
157
+ return creds;
158
+ }
159
+ async function platformGet(session, path, signal) {
160
+ const res = await fetch(`${MASTRA_PLATFORM_API_URL}${path}`, {
161
+ headers: {
162
+ Authorization: `Bearer ${session.token}`,
163
+ "x-organization-id": session.orgId
164
+ },
165
+ signal
166
+ });
167
+ if (!res.ok) {
168
+ const body = await res.json().catch(() => ({}));
169
+ throw new Error(`Mastra Platform request failed (${res.status}): ${body.message ?? body.error ?? path}`);
170
+ }
171
+ return await res.json();
172
+ }
173
+ async function fetchPlatformOrgs(session, signal) {
174
+ const data = await platformGet(session, "/v1/auth/orgs", signal);
175
+ return data.organizations ?? data.orgs ?? [];
176
+ }
177
+ async function fetchPlatformProjects(session, signal) {
178
+ return (await platformGet(session, "/v1/projects", signal)).projects;
179
+ }
180
+ async function fetchPlatformEnvironments(session, projectId, signal) {
181
+ return (await platformGet(session, `/v1/projects/${encodeURIComponent(projectId)}/environments`, signal)).environments;
182
+ }
183
+ const FACTORY_DOMAIN = "factory.mastra.cloud";
184
+ /**
185
+ * The Factory server URL for a deployed environment: a custom server wins,
186
+ * otherwise the managed `<env slug>.factory.mastra.cloud` domain.
187
+ */
188
+ function resolveFactoryUrl(env) {
189
+ if (env.customServerUrl) try {
190
+ const url = new URL(/^[a-z][a-z\d+.-]*:\/\//i.test(env.customServerUrl) ? env.customServerUrl : `https://${env.customServerUrl}`);
191
+ if (url.protocol !== "https:") return null;
192
+ return `${url.origin}${url.pathname}`.replace(/\/+$/, "");
193
+ } catch {
194
+ return null;
195
+ }
196
+ if (!env.instanceUrl) return null;
197
+ return `https://${env.slug}.${FACTORY_DOMAIN}`;
198
+ }
199
+ export { FACTORY_DOMAIN, MASTRA_PLATFORM_API_URL, fetchPlatformEnvironments, fetchPlatformOrgs, fetchPlatformProjects, getPlatformSession, loadPlatformCredentials, loginToPlatform, resolveFactoryUrl, savePlatformCredentials };
@@ -0,0 +1,156 @@
1
+ import type { AgentController, Session } from '@mastra/core/agent-controller';
2
+ import type { InputProcessor, OutputProcessor } from '@mastra/core/processors';
3
+ import type { SignalProvider } from '@mastra/core/signals';
4
+ import type { MastraCompositeStore } from '@mastra/core/storage';
5
+ import type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';
6
+ import type { MastraVector } from '@mastra/core/vector';
7
+ import type { MastraCodeState } from './schema.js';
8
+ export { createTool } from '@mastra/core/tools';
9
+ export { RequestContext } from '@mastra/core/di';
10
+ export type { InputProcessor, OutputProcessor } from '@mastra/core/processors';
11
+ export { SignalProvider } from '@mastra/core/signals';
12
+ export type { SignalProviderTarget, SignalSubscription } from '@mastra/core/signals';
13
+ export type { Tool, ToolAction, ToolExecutionContext } from '@mastra/core/tools';
14
+ export { z } from 'zod';
15
+ export type MastraCodeToolRenderConfig = {
16
+ type: 'subagent';
17
+ agentType?: string;
18
+ modelId?: string;
19
+ forked?: boolean;
20
+ label?: string;
21
+ maxActivityLines?: number;
22
+ collapsedLines?: number;
23
+ colors?: {
24
+ border?: string;
25
+ label?: string;
26
+ agentType?: string;
27
+ icon?: string;
28
+ };
29
+ icons?: {
30
+ running?: string;
31
+ success?: string;
32
+ error?: string;
33
+ };
34
+ };
35
+ export type MastraCodeSubagentProgress = {
36
+ event: 'text';
37
+ text: string;
38
+ } | {
39
+ event: 'tool_start';
40
+ toolName: string;
41
+ args?: unknown;
42
+ } | {
43
+ event: 'tool_end';
44
+ toolName: string;
45
+ result?: unknown;
46
+ isError?: boolean;
47
+ } | {
48
+ event: 'finish';
49
+ isError?: boolean;
50
+ durationMs?: number;
51
+ result?: string;
52
+ };
53
+ export type MastraCodeToolProgress = string | {
54
+ status?: string;
55
+ detail?: string;
56
+ } | MastraCodeSubagentProgress;
57
+ export declare function writeToolProgress(context: Pick<ToolExecutionContext, 'writer' | 'agent'> | undefined, progress: MastraCodeToolProgress): Promise<void>;
58
+ export type MastraCodePluginConfigValue = string | boolean | undefined;
59
+ export type MastraCodePluginConfigOption = {
60
+ type: 'model' | 'boolean' | 'string';
61
+ label?: string;
62
+ description?: string;
63
+ default?: string | boolean;
64
+ };
65
+ export type MastraCodePluginConfigSchema = Record<string, MastraCodePluginConfigOption>;
66
+ export type MastraCodePluginConfigValues = Record<string, MastraCodePluginConfigValue>;
67
+ /** The running Mastra Code controller, as seen by a plugin. */
68
+ export type MastraCodePluginController = AgentController<MastraCodeState>;
69
+ /** The session a plugin's contributions are running alongside. */
70
+ export type MastraCodePluginSession = Session<MastraCodeState>;
71
+ /**
72
+ * Lazy accessors for Mastra Code's runtime, handed to every plugin field resolver.
73
+ *
74
+ * Plugins are loaded before the controller and the session exist, so these are
75
+ * accessors rather than instances: call them at the moment you need the value,
76
+ * never during plugin load. Both return `undefined` until Mastra Code has
77
+ * constructed the corresponding object.
78
+ *
79
+ * @experimental This is an evolving runtime API. It currently exposes the whole
80
+ * controller so real plugins can be built against it; once we know what plugin
81
+ * authors actually reach for, it may narrow to a smaller facade in a future
82
+ * release.
83
+ */
84
+ export type MastraCodePluginRuntime = {
85
+ /**
86
+ * The running controller, or `undefined` when it does not exist yet.
87
+ * @experimental see {@link MastraCodePluginRuntime}
88
+ */
89
+ getController?: () => MastraCodePluginController | undefined;
90
+ /**
91
+ * The active session, or `undefined` before one has been created.
92
+ * @experimental see {@link MastraCodePluginRuntime}
93
+ */
94
+ getActiveSession?: () => MastraCodePluginSession | undefined;
95
+ /**
96
+ * Borrow the host's persistence when booting a nested controller. Do not close
97
+ * these instances or run storage maintenance on them; the host owns their lifetime.
98
+ * Opening the same SQLite files with a plugin-local native library is unsafe.
99
+ */
100
+ getStorage?: () => {
101
+ storage: MastraCompositeStore;
102
+ storageBackend: 'libsql' | 'pg';
103
+ vector?: MastraVector;
104
+ };
105
+ };
106
+ export type MastraCodePluginContext = MastraCodePluginRuntime & {
107
+ cwd: string;
108
+ scope: 'global' | 'project';
109
+ pluginDir: string;
110
+ config: MastraCodePluginConfigValues;
111
+ };
112
+ export type MastraCodePluginTool = Tool | ToolAction<any, any, any, any, any, any, any>;
113
+ export type MastraCodePluginToolEntry = {
114
+ tool: MastraCodePluginTool;
115
+ render?: MastraCodeToolRenderConfig;
116
+ };
117
+ export type MastraCodePluginTools = Record<string, MastraCodePluginTool>;
118
+ export type MastraCodePluginToolEntries = Record<string, MastraCodePluginToolEntry>;
119
+ export type MastraCodePluginInstructions = string | ((context: MastraCodePluginContext) => string | Promise<string>);
120
+ /**
121
+ * Processors a plugin contributes, split by lane.
122
+ *
123
+ * A bare array is shorthand for `{ input: [...] }`, since input processors are
124
+ * the common case. Plugin processors run last in Mastra Code's own configured
125
+ * processors — after the layers they customize, before the channel and memory
126
+ * layers the agent appends. That slot is fixed and not configurable.
127
+ */
128
+ export type MastraCodePluginProcessorEntries = InputProcessor[] | {
129
+ input?: InputProcessor[];
130
+ output?: OutputProcessor[];
131
+ };
132
+ /**
133
+ * Signal providers a plugin contributes.
134
+ *
135
+ * Mastra Code owns their lifecycle: it registers Mastra on them, connects them
136
+ * to the coding agent, starts them polling, and stops them when the plugin is
137
+ * updated, disabled or removed. Their `getInputProcessors()` /
138
+ * `getOutputProcessors()` feed the same lanes as {@link MastraCodePluginProcessorEntries}.
139
+ *
140
+ * Note that `getTools()` is **ignored** for plugin-provided providers — inject
141
+ * tools from inside a processor instead.
142
+ */
143
+ export type MastraCodePluginSignalProviderEntries = SignalProvider<string>[];
144
+ export type MastraCodePlugin = {
145
+ id: string;
146
+ name?: string;
147
+ version?: string;
148
+ description?: string;
149
+ config?: MastraCodePluginConfigSchema;
150
+ instructions?: MastraCodePluginInstructions;
151
+ tools?: MastraCodePluginToolEntries | ((context: MastraCodePluginContext) => MastraCodePluginToolEntries | Promise<MastraCodePluginToolEntries>);
152
+ processors?: MastraCodePluginProcessorEntries | ((context: MastraCodePluginContext) => MastraCodePluginProcessorEntries | Promise<MastraCodePluginProcessorEntries>);
153
+ signalProviders?: MastraCodePluginSignalProviderEntries | ((context: MastraCodePluginContext) => MastraCodePluginSignalProviderEntries | Promise<MastraCodePluginSignalProviderEntries>);
154
+ };
155
+ export declare function defineMastraCodePlugin<TPlugin extends MastraCodePlugin>(plugin: TPlugin): TPlugin;
156
+ //# sourceMappingURL=plugin.d.ts.map
package/dist/plugin.js ADDED
@@ -0,0 +1,27 @@
1
+ import { SignalProvider } from "@mastra/core/signals";
2
+ import { createTool } from "@mastra/core/tools";
3
+ import { z } from "zod";
4
+ import { RequestContext } from "@mastra/core/di";
5
+ // src/plugin.ts
6
+ async function writeToolProgress(context, progress) {
7
+ const toolCallId = context?.agent?.toolCallId;
8
+ if (!toolCallId) return;
9
+ const chunk = {
10
+ type: "data-mastracode-tool-progress",
11
+ data: {
12
+ toolCallId,
13
+ progress
14
+ },
15
+ transient: true
16
+ };
17
+ const outputWriter = context.agent?.outputWriter;
18
+ if (outputWriter) {
19
+ await outputWriter(chunk);
20
+ return;
21
+ }
22
+ await context.writer?.custom(chunk);
23
+ }
24
+ function defineMastraCodePlugin(plugin) {
25
+ return plugin;
26
+ }
27
+ export { RequestContext, SignalProvider, createTool, defineMastraCodePlugin, writeToolProgress, z };
@@ -0,0 +1,9 @@
1
+ export type PluginInstallExecutionOptions = {
2
+ onOutput?: (chunk: Buffer | string) => void;
3
+ signal?: AbortSignal;
4
+ };
5
+ export declare function installPluginDependencies(pluginRoot: string, commandRoot?: string, options?: PluginInstallExecutionOptions): Promise<boolean>;
6
+ export declare function installPluginDependenciesForEntry(pluginRoot: string, entry: string, options?: PluginInstallExecutionOptions): Promise<void>;
7
+ export declare function getPluginDependencyRoots(pluginRoot: string, entry: string): string[];
8
+ export declare function getEntryPackageRoot(pluginRoot: string, entry: string): string;
9
+ //# sourceMappingURL=dependencies.d.ts.map