@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,382 @@
1
+ import { getRequestAccountSelection, isRequestAccountRoutingExhausted } from "../auth/account-routing-context.js";
2
+ import { ProviderAuthRequiredError } from "../auth/provider-auth-error.js";
3
+ import "../constants.js";
4
+ import { toMemoryModelId } from "../onboarding/packs.js";
5
+ import { getCustomProviderId, loadSettings, resolveDefaultThinkingLevel, stripMastraCodeCustomProviderPrefix } from "../onboarding/settings.js";
6
+ import { AMAZON_BEDROCK_GATEWAY_ID, createAmazonBedrockGateway } from "../providers/amazon-bedrock-gateway.js";
7
+ import { GOOGLE_VERTEX_GATEWAY_ID, createGoogleVertexGateway } from "../providers/google-vertex-gateway.js";
8
+ import { MASTRA_GATEWAY_PREFIX, findRouteModelIndex, normalizeLegacyModelId, parseCodexModelSelection, remapOpenAIModelForCodexOAuth, stripMastraGatewayPrefix } from "../providers/model-ids.js";
9
+ import { isThinkingLevelSetting } from "../thinking.js";
10
+ import { hasCredentialStoreProvider, hasCredentialTenantResolver, prepareCredentialTenant, resolveCredentialScope, resolveCredentialStore, resolveTenantFromRequestContext, setCredentialStoreProvider } from "./credential-resolver.js";
11
+ import { hasCustomProvidersSource, resolveCustomProviders, setCustomProvidersSource } from "./custom-provider-source.js";
12
+ import { MASTRACODE_GATEWAY_ID, MastraCodeGateway, getAnthropicApiKey, getGlobalAuthStorage, getOpenAIApiKey, hasProviderEnvironmentKey, reloadAuthStorage, resolveAuth } from "./mastracode-gateway.js";
13
+ import { ModelRouterLanguageModel } from "@mastra/core/llm";
14
+ import { RequestContext } from "@mastra/core/request-context";
15
+ // src/agents/model.ts
16
+ function getAgentControllerHeaders(requestContext) {
17
+ const agentControllerContext = requestContext?.get("controller");
18
+ const headers = {
19
+ ...agentControllerContext?.threadId ? { "x-thread-id": agentControllerContext.threadId } : {},
20
+ ...agentControllerContext?.resourceId ? { "x-resource-id": agentControllerContext.resourceId } : {}
21
+ };
22
+ return Object.keys(headers).length > 0 ? headers : void 0;
23
+ }
24
+ function accountCredential(account) {
25
+ const { type: _type, id: _id, label: _label, addedAt: _addedAt, active: _active, ...credential } = account;
26
+ return {
27
+ type: "oauth",
28
+ ...credential
29
+ };
30
+ }
31
+ function createRequestScopedCredentialStore(base, requestContext) {
32
+ const selectedId = (providerId) => getRequestAccountSelection(requestContext, providerId);
33
+ const selectedAccount = (providerId) => {
34
+ const accountInstanceId = selectedId(providerId);
35
+ return accountInstanceId ? base.listAccounts?.(providerId).find((account) => account.id === accountInstanceId) : void 0;
36
+ };
37
+ const rejectAll = (providerId) => isRequestAccountRoutingExhausted(requestContext, providerId);
38
+ return {
39
+ allowEnvironmentFallback: base.allowEnvironmentFallback,
40
+ reload: () => base.reload(),
41
+ get: (providerId) => {
42
+ if (rejectAll(providerId)) return void 0;
43
+ if (selectedId(providerId) === void 0) return base.get(providerId);
44
+ const selected = selectedAccount(providerId);
45
+ return selected ? accountCredential(selected) : void 0;
46
+ },
47
+ getStoredApiKey: (providerId) => {
48
+ if (rejectAll(providerId)) return void 0;
49
+ if (selectedId(providerId) !== void 0) return void 0;
50
+ return base.getStoredApiKey(providerId);
51
+ },
52
+ getApiKey: (providerId) => rejectAll(providerId) ? Promise.resolve(void 0) : base.getApiKey(providerId, selectedId(providerId)),
53
+ getOAuthCredential: base.getOAuthCredential ? (providerId) => rejectAll(providerId) ? Promise.resolve(void 0) : base.getOAuthCredential(providerId, selectedId(providerId)) : void 0,
54
+ listAccounts: base.listAccounts ? (providerId) => base.listAccounts(providerId) : void 0,
55
+ getActiveAccount: base.getActiveAccount ? (providerId) => base.getActiveAccount(providerId) : void 0,
56
+ activateAccount: base.activateAccount ? (providerId, accountInstanceId) => base.activateAccount(providerId, accountInstanceId) : void 0,
57
+ removeAccount: base.removeAccount ? (providerId, accountInstanceId) => base.removeAccount(providerId, accountInstanceId) : void 0
58
+ };
59
+ }
60
+ function createMastraCodeGateway(options) {
61
+ return new MastraCodeGateway(options);
62
+ }
63
+ function createMastraCodeModelCatalogProvider(gateway) {
64
+ return gateway instanceof MastraCodeGateway ? gateway.createModelCatalogProvider() : MastraCodeGateway.createModelCatalogProvider(gateway);
65
+ }
66
+ /**
67
+ * Placeholder for future model ID normalization.
68
+ * Currently returns the input unchanged, but exists as a seam
69
+ * for aliasing, casing fixes, or validation in the future.
70
+ */
71
+ function resolveModelId(modelId) {
72
+ return modelId;
73
+ }
74
+ /**
75
+ * Resolve a model ID to the correct provider instance.
76
+ * Shared by the main agent, observer, and reflector.
77
+ *
78
+ * - For anthropic/* models: Uses stored OAuth credentials when present, otherwise direct API key
79
+ * - For openai/* models: Uses OAuth when configured, otherwise direct API key from AuthStorage
80
+ * - For moonshotai/* models: Uses Moonshot AI Anthropic-compatible endpoint
81
+ * - For all other providers: Uses Mastra's model router (models.dev gateway)
82
+ */
83
+ function resolveModel(modelId, options) {
84
+ if (!hasCredentialTenantResolver()) return resolveModelForRequest(modelId, options);
85
+ const createRequestModel = () => {
86
+ const requestContext = options?.requestContext ? new RequestContext(options.requestContext.entries()) : void 0;
87
+ return new ModelRouterLanguageModel({ id: `${MASTRACODE_GATEWAY_ID}/${modelId}` }, [{
88
+ id: MASTRACODE_GATEWAY_ID,
89
+ name: "Request-scoped MastraCode",
90
+ fetchProviders: async () => ({}),
91
+ buildUrl: () => void 0,
92
+ getApiKey: async () => "",
93
+ resolveAuth: () => ({ apiKey: "request-scoped" }),
94
+ resolveLanguageModel: async () => {
95
+ await prepareCredentialTenant(requestContext);
96
+ return resolveModelForRequest(modelId, {
97
+ ...options,
98
+ requestContext
99
+ });
100
+ }
101
+ }]);
102
+ };
103
+ let currentModel = createRequestModel();
104
+ return new Proxy(currentModel, { get(_target, property) {
105
+ if (property === "supportedUrls") return createRequestModel().supportedUrls;
106
+ if (property === "doStream" || property === "doGenerate") return async (...args) => {
107
+ const refreshed = createRequestModel();
108
+ currentModel = refreshed;
109
+ return Reflect.apply(Reflect.get(refreshed, property), refreshed, args);
110
+ };
111
+ const value = Reflect.get(currentModel, property, currentModel);
112
+ return typeof value === "function" ? value.bind(currentModel) : value;
113
+ } });
114
+ }
115
+ /** Whether a model id resolves to a custom provider. A `mastra/...` id never does. */
116
+ function isCustomProviderModel(modelId, customProviders) {
117
+ const input = stripMastraCodeCustomProviderPrefix(normalizeLegacyModelId(modelId), customProviders);
118
+ if (input.startsWith("mastra/")) return false;
119
+ const providerId = input.split("/", 1)[0];
120
+ return customProviders.some((provider) => getCustomProviderId(provider.name) === providerId);
121
+ }
122
+ function resolveModelForRequest(modelId, options) {
123
+ reloadAuthStorage();
124
+ const headers = getAgentControllerHeaders(options?.requestContext);
125
+ const settings = loadSettings();
126
+ const customProviders = resolveCustomProviders(options?.requestContext) ?? settings.customProviders;
127
+ const { modelId: canonicalModelId, codexServiceTier } = isCustomProviderModel(modelId, customProviders) ? { modelId } : parseCodexModelSelection(modelId);
128
+ const legacyNormalizedInput = normalizeLegacyModelId(canonicalModelId);
129
+ const normalizedInput = stripMastraCodeCustomProviderPrefix(legacyNormalizedInput, customProviders);
130
+ const isMastraGatewayModel = normalizedInput.startsWith(MASTRA_GATEWAY_PREFIX);
131
+ const normalizedModelId = stripMastraGatewayPrefix(normalizedInput);
132
+ const [providerId, ...modelParts] = normalizedModelId.split("/");
133
+ const bareModelId = modelParts.join("/");
134
+ if (!providerId || !bareModelId) throw new Error(`Invalid model id: ${modelId}`);
135
+ const tenantCredentialStore = resolveCredentialStore(options?.requestContext);
136
+ const baseCredentialStore = tenantCredentialStore ?? getGlobalAuthStorage();
137
+ if (providerId === "amazon-bedrock") {
138
+ if (tenantCredentialStore?.allowEnvironmentFallback === false && !tenantCredentialStore.allowsDeploymentCredentials?.("amazon-bedrock")) throw new ProviderAuthRequiredError("Amazon Bedrock is not enabled for this Factory deployment. The operator must provide AWS credentials to the server and set FACTORY_DEPLOYMENT_MODEL_PROVIDERS=amazon-bedrock.");
139
+ const bedrockGateway = createAmazonBedrockGateway();
140
+ const routerId = `${AMAZON_BEDROCK_GATEWAY_ID}/${bareModelId}`;
141
+ const auth = bedrockGateway.resolveAuth({
142
+ gatewayId: AMAZON_BEDROCK_GATEWAY_ID,
143
+ providerId: AMAZON_BEDROCK_GATEWAY_ID,
144
+ modelId: bareModelId,
145
+ routerId
146
+ });
147
+ return bedrockGateway.resolveLanguageModel({
148
+ providerId: AMAZON_BEDROCK_GATEWAY_ID,
149
+ modelId: bareModelId,
150
+ apiKey: auth?.apiKey ?? "",
151
+ headers
152
+ });
153
+ }
154
+ if (providerId === "google-vertex") {
155
+ if (tenantCredentialStore?.allowEnvironmentFallback === false && !tenantCredentialStore.allowsDeploymentCredentials?.("google-vertex")) throw new ProviderAuthRequiredError("Google Vertex AI is not enabled for this Factory deployment. The operator must configure Application Default Credentials, GOOGLE_VERTEX_PROJECT, GOOGLE_VERTEX_LOCATION, and FACTORY_DEPLOYMENT_MODEL_PROVIDERS=google-vertex.");
156
+ const vertexGateway = createGoogleVertexGateway();
157
+ const auth = vertexGateway.resolveAuth({
158
+ gatewayId: GOOGLE_VERTEX_GATEWAY_ID,
159
+ providerId: GOOGLE_VERTEX_GATEWAY_ID,
160
+ modelId: bareModelId,
161
+ routerId: normalizedModelId
162
+ });
163
+ if (!auth) throw new Error("Google Vertex ADC requires GOOGLE_VERTEX_PROJECT and GOOGLE_VERTEX_LOCATION. Configure Application Default Credentials in the deployment environment.");
164
+ return vertexGateway.resolveLanguageModel({
165
+ providerId: GOOGLE_VERTEX_GATEWAY_ID,
166
+ modelId: bareModelId,
167
+ apiKey: auth.apiKey ?? "",
168
+ headers
169
+ });
170
+ }
171
+ const routerId = `${MASTRACODE_GATEWAY_ID}/${normalizedModelId}`;
172
+ const mgApiKey = mastraGatewayApiKey(tenantCredentialStore);
173
+ const rawGatewayBase = settings.memoryGateway?.baseUrl ?? process.env["MASTRA_GATEWAY_URL"] ?? "https://gateway-api.mastra.ai";
174
+ const credentialStore = createRequestScopedCredentialStore(baseCredentialStore, options?.requestContext);
175
+ const gateway = createMastraCodeGateway({
176
+ mastraGatewayBaseUrl: rawGatewayBase.replace(/\/+$/, "").replace(/\/v1$/, ""),
177
+ mastraGatewayApiKey: mgApiKey,
178
+ routeThroughMastraGateway: Boolean(mgApiKey && isMastraGatewayModel),
179
+ thinkingLevel: options?.thinkingLevel,
180
+ anthropicPromptCacheScope: options?.anthropicPromptCacheScope,
181
+ customProviders: isMastraGatewayModel ? [] : customProviders,
182
+ credentialStore
183
+ });
184
+ const auth = gateway.resolveAuth({
185
+ gatewayId: MASTRACODE_GATEWAY_ID,
186
+ providerId,
187
+ modelId: bareModelId,
188
+ routerId
189
+ });
190
+ if (!auth && credentialStore?.allowEnvironmentFallback === false) throw new ProviderAuthRequiredError(resolveCredentialScope(options?.requestContext) === "factory" ? `No usable ${providerId} credential is available for ${normalizedModelId}. This Factory uses organization credentials only, so personal provider sign-ins don't apply. Add an organization credential, then try again.` : `No usable ${providerId} credential is available for ${normalizedModelId}. This Factory uses personal credentials only, so organization credentials don't apply. Connect the provider, then try again.`);
191
+ return gateway.resolveLanguageModel({
192
+ providerId,
193
+ modelId: bareModelId,
194
+ apiKey: auth?.apiKey ?? "",
195
+ headers,
196
+ codexServiceTier
197
+ });
198
+ }
199
+ /** A tenant's own gateway key wins over the server's, so each org is billed to its own Mastra account. */
200
+ function mastraGatewayApiKey(tenantCredentialStore) {
201
+ return tenantCredentialStore?.getStoredApiKey("mastra-gateway")?.trim() || MastraCodeGateway.getMastraGatewayApiKey();
202
+ }
203
+ /** Credential ids whose OAuth sign-in keeps the native provider API through the gateway. */
204
+ const NATIVE_OAUTH_CREDENTIAL_IDS = {
205
+ anthropic: "anthropic",
206
+ openai: "openai-codex"
207
+ };
208
+ /** The provider whose credentials decide a gateway alias's route, or its fixed route otherwise. */
209
+ function classifyWebSearchModel(modelId) {
210
+ if (!modelId) return { route: void 0 };
211
+ const normalizedInput = normalizeLegacyModelId(modelId);
212
+ const providerId = stripMastraGatewayPrefix(normalizedInput).split("/")[0];
213
+ if (providerId !== "anthropic" && providerId !== "openai") return { route: void 0 };
214
+ return normalizedInput.startsWith("mastra/") ? { gatewayProvider: providerId } : { route: providerId };
215
+ }
216
+ /**
217
+ * Prepares tenant credential policy when the web search route depends on it and the
218
+ * request hasn't been prepared yet. Model resolution prepares its own context only when
219
+ * the model is invoked, after tools and instructions are built. Returns undefined when
220
+ * there is nothing to prepare, so callers can stay synchronous.
221
+ */
222
+ function prepareProviderWebSearchRoute(modelId, options) {
223
+ const requestContext = options?.requestContext;
224
+ if (!hasCredentialTenantResolver() || !(requestContext instanceof RequestContext)) return void 0;
225
+ if (resolveTenantFromRequestContext(requestContext)) return void 0;
226
+ if (!("gatewayProvider" in classifyWebSearchModel(modelId))) return void 0;
227
+ return prepareCredentialTenant(requestContext);
228
+ }
229
+ function resolveProviderWebSearchRoute(modelId, options) {
230
+ const model = classifyWebSearchModel(modelId);
231
+ if (!("gatewayProvider" in model)) return model.route;
232
+ const providerId = model.gatewayProvider;
233
+ reloadAuthStorage();
234
+ const tenantCredentialStore = resolveCredentialStore(options?.requestContext);
235
+ if (createRequestScopedCredentialStore(tenantCredentialStore ?? getGlobalAuthStorage(), options?.requestContext).get(NATIVE_OAUTH_CREDENTIAL_IDS[providerId])?.type === "oauth") return providerId;
236
+ return mastraGatewayApiKey(tenantCredentialStore) ? "mastra-gateway" : providerId;
237
+ }
238
+ /**
239
+ * Whether `resolveModel` can authenticate a provider for this request, using the
240
+ * same credential lookup: the tenant store in deployed Factory (no environment
241
+ * keys), otherwise local auth and then the provider's environment keys.
242
+ */
243
+ function canUseProvider(providerId, options) {
244
+ reloadAuthStorage();
245
+ const credentialStore = createRequestScopedCredentialStore(resolveCredentialStore(options?.requestContext) ?? getGlobalAuthStorage(), options?.requestContext);
246
+ if (createMastraCodeGateway({
247
+ mastraGatewayBaseUrl: "",
248
+ routeThroughMastraGateway: false,
249
+ customProviders: resolveCustomProviders(options?.requestContext) ?? loadSettings().customProviders,
250
+ credentialStore
251
+ }).resolveAuth({
252
+ gatewayId: "mastracode",
253
+ providerId,
254
+ modelId: "",
255
+ routerId: `mastracode/${providerId}`
256
+ })) return true;
257
+ return credentialStore.allowEnvironmentFallback !== false && hasProviderEnvironmentKey(providerId);
258
+ }
259
+ /**
260
+ * Resolve the effective thinking level for the current request.
261
+ *
262
+ * Precedence:
263
+ * 1. Session override (`state.thinkingLevel`, set via /think or the session
264
+ * settings panel).
265
+ * 2. The host's default for this request (`hostDefault`), when the host
266
+ * stores thinking defaults itself (the Factory keeps one per Factory).
267
+ * 3. Per-mode default from settings (`models.modeThinkingDefaults[mode]`),
268
+ * only when the context carries a session mode.
269
+ * 4. Global default (`preferences.thinkingLevel`).
270
+ *
271
+ * Resolved per-request (not seeded at session start) so configuration changes
272
+ * apply to the next request of every session — including automated
273
+ * (rule-driven) Factory runs that nobody ever opens interactively.
274
+ */
275
+ function resolveRequestThinkingLevel(agentControllerContext, settingsPath, hostDefault) {
276
+ const override = agentControllerContext?.state?.thinkingLevel;
277
+ if (isThinkingLevelSetting(override)) return override;
278
+ if (hostDefault) return hostDefault;
279
+ const modeId = agentControllerContext?.session?.modeId;
280
+ return resolveDefaultThinkingLevel(loadSettings(settingsPath), modeId).level;
281
+ }
282
+ /**
283
+ * Dynamic model function that reads the current model and optional ordered
284
+ * fallback route from controller state. Route entry ids are opaque host-owned
285
+ * identifiers; repeated ids receive occurrence suffixes because core tracks the
286
+ * active fallback index by id across agentic steps.
287
+ */
288
+ function getDynamicModel({ requestContext }, settingsPath, { modeless = false, defaultThinkingLevel } = {}) {
289
+ const controller = requestContext.get("controller");
290
+ const state = controller?.getState?.();
291
+ const pendingState = state?.mastracodePendingModelFallback;
292
+ const pendingFallback = pendingState && (pendingState.threadId === void 0 || typeof pendingState.threadId === "string" && pendingState.threadId === controller?.threadId) ? pendingState : void 0;
293
+ const modelId = (pendingFallback && typeof pendingFallback.toModelId === "string" && pendingFallback.toModelId.length > 0 ? pendingFallback.toModelId : void 0) ?? controller?.session?.modelId;
294
+ if (!modelId) {
295
+ if (!controller) throw new Error("No model available: this run started without a controller session context, so no model selection could be resolved.");
296
+ throw new Error("No model selected. Use /models to select a model first.");
297
+ }
298
+ const resolveOptions = {
299
+ thinkingLevel: resolveRequestThinkingLevel(modeless ? { state: controller?.state } : controller, settingsPath, defaultThinkingLevel),
300
+ remapForCodexOAuth: true,
301
+ requestContext
302
+ };
303
+ const primary = identifyModel(modelId, resolveModel(modelId, resolveOptions));
304
+ const route = state?.modelRoute?.entries?.slice(0, 32);
305
+ const pendingEntryId = pendingFallback && typeof pendingFallback.toEntryId === "string" ? pendingFallback.toEntryId : void 0;
306
+ const startIndex = pendingEntryId ? route?.findIndex((entry) => entry.id === pendingEntryId) : 0;
307
+ const activeRoute = route && startIndex !== void 0 && startIndex >= 0 ? route.slice(startIndex) : void 0;
308
+ if (!activeRoute || activeRoute.length < 2 || findRouteModelIndex(activeRoute, modelId) !== 0) return primary;
309
+ const firstId = typeof activeRoute[0]?.id === "string" && activeRoute[0].id.length > 0 ? activeRoute[0].id : void 0;
310
+ if (!firstId) return primary;
311
+ const entries = [{
312
+ id: firstId,
313
+ model: primary
314
+ }];
315
+ const appearances = /* @__PURE__ */ new Map([[firstId, 1]]);
316
+ for (const routeEntry of activeRoute.slice(1)) {
317
+ if (typeof routeEntry.id !== "string" || routeEntry.id.length === 0 || typeof routeEntry.modelId !== "string" || routeEntry.modelId.length === 0) break;
318
+ let entryModel;
319
+ try {
320
+ entryModel = resolveModel(routeEntry.modelId, resolveOptions);
321
+ } catch {
322
+ break;
323
+ }
324
+ const occurrence = (appearances.get(routeEntry.id) ?? 0) + 1;
325
+ appearances.set(routeEntry.id, occurrence);
326
+ entries.push({
327
+ id: occurrence === 1 ? routeEntry.id : `${routeEntry.id}#${occurrence}`,
328
+ model: identifyModel(routeEntry.modelId, entryModel)
329
+ });
330
+ }
331
+ return entries.length < 2 ? primary : entries;
332
+ }
333
+ function identifyModel(modelId, model) {
334
+ return {
335
+ model,
336
+ id: toMemoryModelId(parseCodexModelSelection(modelId).modelId)
337
+ };
338
+ }
339
+ /**
340
+ * The active model route for memory: the session route, starting at a pending
341
+ * fallback hop captured for this thread.
342
+ */
343
+ function getActiveMemoryRoute(state, threadId) {
344
+ const pending = state?.mastracodePendingModelFallback;
345
+ const sameThreadPending = pending && (pending.threadId === void 0 || pending.threadId === threadId) ? pending : void 0;
346
+ const routeEntries = state?.modelRoute?.entries?.slice(0, 32) ?? [];
347
+ const pendingIndex = sameThreadPending ? routeEntries.findIndex((entry) => entry.id === sameThreadPending.toEntryId) : -1;
348
+ return pendingIndex >= 0 ? routeEntries.slice(pendingIndex) : routeEntries;
349
+ }
350
+ /**
351
+ * The memory model the active route applies to both OM roles: `'auto'`, the
352
+ * first concrete memory model, or `undefined` when the route sets none (both
353
+ * roles then follow their `/om` settings).
354
+ */
355
+ function getActiveRouteMemoryModelId(state, threadId) {
356
+ const route = getActiveMemoryRoute(state, threadId);
357
+ if (route[0]?.memoryModelId === "auto") return "auto";
358
+ return route.find((candidate) => typeof candidate.memoryModelId === "string" && candidate.memoryModelId && candidate.memoryModelId !== "auto")?.memoryModelId;
359
+ }
360
+ /**
361
+ * Goal judge model resolver for the agent's `goal.judge` config. Resolves the
362
+ * configured goal judge model through mastracode's gateway so provider
363
+ * credentials (stored in auth storage, not just env) are injected — a bare model
364
+ * id handed to core's default model router would fail to find the API key.
365
+ *
366
+ * Returns `undefined` when no judge model is configured, which keeps the goal
367
+ * step a complete no-op (the goal mechanism requires a judge to do anything).
368
+ *
369
+ * `settingsPath` must be the same source `createMastraCode()` reads from so the
370
+ * judge model and the goal budget (`goalMaxTurns`) come from one config — with a
371
+ * custom `settingsPath` a bare `loadSettings()` here could read a different file
372
+ * and silently turn the goal step into a no-op.
373
+ */
374
+ function getGoalJudgeModel({ requestContext }, settingsPath) {
375
+ const judgeModelId = loadSettings(settingsPath).models.goalJudgeModel;
376
+ if (!judgeModelId) return void 0;
377
+ return resolveModel(judgeModelId, {
378
+ remapForCodexOAuth: true,
379
+ requestContext
380
+ });
381
+ }
382
+ export { MASTRACODE_GATEWAY_ID, MastraCodeGateway, canUseProvider, createMastraCodeGateway, createMastraCodeModelCatalogProvider, createRequestScopedCredentialStore, getActiveMemoryRoute, getActiveRouteMemoryModelId, getAnthropicApiKey, getDynamicModel, getGoalJudgeModel, getOpenAIApiKey, hasCredentialStoreProvider, hasCustomProvidersSource, prepareProviderWebSearchRoute, remapOpenAIModelForCodexOAuth, resolveAuth, resolveCustomProviders, resolveModel, resolveModelId, resolveProviderWebSearchRoute, resolveRequestThinkingLevel, resolveTenantFromRequestContext, setCredentialStoreProvider, setCustomProvidersSource };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Build mode — interactive task execution with write capabilities.
3
+ *
4
+ * The default top-level mode for implementing features, fixing bugs, and
5
+ * making changes directly in conversation with the user. Full read/write
6
+ * access within the task's scope. (Not to be confused with the separate
7
+ * `executeSubagent`, which has its own concise, parent-reporting
8
+ * instructions for when work is delegated to a sub-agent.)
9
+ */
10
+ import type { AgentControllerMode } from '@mastra/core/agent-controller';
11
+ export declare const buildMode: AgentControllerMode;
12
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1,33 @@
1
+ // src/agents/modes/build.ts
2
+ const buildMode = {
3
+ id: "build",
4
+ name: "Build",
5
+ description: "Task execution with write capabilities. Use for 'implement feature X', 'fix bug Y', 'refactor module Z'.",
6
+ instructions: `You are a focused execution agent. Your job is to complete a specific, well-defined task by making the necessary changes to the codebase.
7
+
8
+ ## Rules
9
+ - You have FULL ACCESS to read, write, and execute within your task scope.
10
+ - Stay focused on the specific task given. Do not make unrelated changes.
11
+ - Understand the relevant code before modifying it, then use string_replace_lsp or write_file.
12
+ - Verify your changes work by running relevant tests or checking for errors.
13
+
14
+ ## Tool Strategy
15
+ - **Understand first**: Know what a file contains before editing it, however you read it
16
+ - **Edit precisely**: Use string_replace_lsp with enough context to match uniquely
17
+ - **Use specialized tools**: Prefer view/search_content/find_files over shell commands for reading
18
+ - **Parallelize**: Make independent tool calls together (e.g., view multiple files at once)
19
+
20
+ ## Workflow
21
+ . Understand the task and explore relevant code
22
+ . For complex tasks (3+ steps): track progress internally and summarize it in your final answer
23
+ . Make changes incrementally — verify each change before moving on
24
+ . Run tests or type-check to verify
25
+
26
+ ## Workflows
27
+ - To build a workflow: call \`create-workflow\` with the user's request verbatim. A focused sub-agent handles discovery, composition, and saving — don't try to do it inline.
28
+ - To run an existing workflow: call \`run-workflow\` with { workflowId, inputData }. Returns { status, result, error? }.
29
+ - To inspect or manage: \`list-workflows\`, \`get-workflow\`, \`delete-workflow\`.`,
30
+ defaultModelId: "openai/gpt-5.6-sol",
31
+ metadata: { default: true }
32
+ };
33
+ export { buildMode };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Explore mode — interactive, read-only codebase exploration.
3
+ *
4
+ * The top-level mode for questions like "find all usages of X" or "how
5
+ * does module Y work". Read-only; answers the user directly in
6
+ * conversation rather than reporting back to a parent agent.
7
+ */
8
+ import type { AgentControllerMode } from '@mastra/core/agent-controller';
9
+ export declare const fastMode: AgentControllerMode;
10
+ //# sourceMappingURL=explore.d.ts.map
@@ -0,0 +1,25 @@
1
+ import { EXPLORE_MODE_AVAILABLE_TOOLS } from "../tool-availability.js";
2
+ // src/agents/modes/explore.ts
3
+ const fastMode = {
4
+ id: "fast",
5
+ name: "Explore",
6
+ description: "Read-only codebase exploration. Use for questions like 'find all usages of X', 'how does module Y work'.",
7
+ defaultModelId: "openai/gpt-5.4-mini",
8
+ instructions: `You are an expert code explorer. Your job is to investigate a codebase and answer a specific question or gather specific information.
9
+
10
+ ## Rules
11
+ - You have READ-ONLY access. You cannot modify files or run commands.
12
+ - Be thorough — search broadly first, then drill into relevant files.
13
+ - After gathering enough information, produce a clear, concise summary of your findings.
14
+
15
+ ## Tool Strategy
16
+ - **Start broad**: Use find_files (glob) to understand project structure
17
+ - **Search smart**: Use search_content (grep) with specific patterns — avoid overly broad searches
18
+ - **Read efficiently**: Use view with view_range for large files — don't read entire files if you only need a section
19
+ - **Parallelize**: Make multiple independent tool calls in one round when exploring different areas
20
+
21
+ ## Workflows
22
+ - You can use \`list-workflows\` and \`get-workflow\` to inspect saved workflows. You cannot create, run, or delete in this mode.`,
23
+ availableTools: [...EXPLORE_MODE_AVAILABLE_TOOLS]
24
+ };
25
+ export { fastMode };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Plan mode — read-only analysis and planning.
3
+ */
4
+ import type { AgentControllerMode } from '@mastra/core/agent-controller';
5
+ /** Plan mode; pass `false` when the host removed `submit_plan` so the mode never asks for it. */
6
+ export declare function createPlanMode(submitPlanAvailable?: boolean): AgentControllerMode;
7
+ export declare const planMode: AgentControllerMode;
8
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1,43 @@
1
+ import { PLAN_MODE_AVAILABLE_TOOLS } from "../tool-availability.js";
2
+ // src/agents/modes/plan.ts
3
+ /** Plan mode; pass `false` when the host removed `submit_plan` so the mode never asks for it. */
4
+ function createPlanMode(submitPlanAvailable = true) {
5
+ return {
6
+ id: "plan",
7
+ name: "Plan",
8
+ transitionsTo: "build",
9
+ defaultModelId: "openai/gpt-5.6-sol",
10
+ description: "Read-only analysis and planning. Use for 'create an implementation plan for X', 'analyze the architecture of Y'.",
11
+ instructions: `You are an expert software architect and planner. Your job is to analyze a codebase and produce a detailed implementation plan for a given task.
12
+
13
+ ## Rules
14
+ - You have READ-ONLY access to the project. You cannot modify project files or run commands.
15
+ - The one exception is plan files: you can create and edit markdown files inside the session-specific plan directory identified in your system prompt using \`write_file\`, \`view\`, and \`string_replace_lsp\`. You may not write anywhere else.
16
+ - First, explore the codebase to understand existing patterns, architecture, and conventions.
17
+ - Produce a concrete, actionable plan — not vague suggestions.
18
+
19
+ ## Tool Strategy
20
+ - **Discover structure**: Use find_files (glob) to understand project layout and find relevant files
21
+ - **Find patterns**: Use search_content (grep) to locate existing implementations, imports, and conventions
22
+ - **Understand deeply**: Use view with view_range to read specific sections of key files
23
+ - **Parallelize**: Make multiple independent tool calls when exploring different areas
24
+
25
+ ## Plan Delivery
26
+ - Write your plan to a markdown file in the session-specific plan directory identified in your system prompt using \`write_file\`, ${submitPlanAvailable ? "then call `submit_plan({ path })` with the path to that file (never the plan body)." : "then hand off the plan file as described in your system prompt (never the plan body)."}
27
+ - Start the file with a \`# Title\` heading describing the plan.
28
+ - Reuse the same file while iterating on the same plan; only create a new file for a genuinely different plan so each plan stays available to review.
29
+ - Do NOT output the plan as text — it MUST live in the plan file.
30
+ - Be concise: reference files by path and line number, don't include raw contents.
31
+ - Focus on actionable details, not general observations.
32
+ - To revise after "Request changes", edit the same file in place with \`string_replace_lsp\`, ${submitPlanAvailable ? "and call `submit_plan` again with the same path." : "then hand off the same file again."}
33
+
34
+ ## Workflows
35
+ - You can INSPECT saved workflows via \`list-workflows\` and \`get-workflow\`.
36
+ - You CANNOT build, run, or delete workflows in this mode.
37
+ - If the user asks for a workflow design, include it in the implementation plan stored at the session-specific plan path, ${submitPlanAvailable ? "then call `submit_plan({ path })` as required above. After approval, build mode can save and run it." : "then hand off the plan file as described in your system prompt."}`,
38
+ metadata: { default: false },
39
+ availableTools: [...PLAN_MODE_AVAILABLE_TOOLS]
40
+ };
41
+ }
42
+ const planMode = createPlanMode();
43
+ export { createPlanMode, planMode };
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Load project and global agent instruction files (AGENTS.md, CLAUDE.md).
3
+ * Prefers AGENTS.md over CLAUDE.md when multiple exist at the same location.
4
+ */
5
+ export interface InstructionSource {
6
+ path: string;
7
+ content: string;
8
+ scope: 'global' | 'project';
9
+ /** Git ref the content was read from, when not read off the working tree. */
10
+ ref?: string;
11
+ }
12
+ /**
13
+ * Reads project-scope instruction files. The default implementation reads the
14
+ * working tree via `fs`; alternative readers can serve content from another
15
+ * source (e.g. a trusted git ref) while keeping working-tree paths as the
16
+ * addressing scheme.
17
+ */
18
+ export interface InstructionFileReader {
19
+ exists(path: string): boolean;
20
+ read(path: string): string;
21
+ /** Git ref backing this reader, recorded on the loaded sources. */
22
+ ref?: string;
23
+ }
24
+ /**
25
+ * Create a reader that serves instruction files from a git ref instead of the
26
+ * working tree. Paths are still addressed as working-tree paths under
27
+ * `projectPath`; content comes from the blob at `<ref>:<relpath>` so an untrusted
28
+ * checkout (e.g. a PR branch under review) cannot influence what is loaded.
29
+ * Tries `origin/<ref>` first (remote truth), then the local ref. Any git
30
+ * failure (missing ref, missing file, no repo) reports the file as absent.
31
+ */
32
+ export declare function createGitRefInstructionReader(projectPath: string, ref: string): InstructionFileReader;
33
+ /**
34
+ * Reader for the reactive reminder channel (AgentsMDInjector) that serves
35
+ * paths under `projectPath` from a trusted git ref. Paths outside the project
36
+ * fall back to the operator machine's filesystem (those are trusted); paths
37
+ * inside the project are only ever resolved against the ref, never the
38
+ * working tree, so an untrusted checkout cannot feed content in.
39
+ */
40
+ export declare function createGitRefReminderReader(projectPath: string, ref: string): {
41
+ pathExists: (path: string) => boolean;
42
+ isDirectory: (path: string) => boolean;
43
+ readFile: (path: string) => string;
44
+ getPathIdentity: (path: string) => string;
45
+ };
46
+ export declare function createGitRefInstructionReaderAsync(projectPath: string, ref: string): Promise<AsyncInstructionFileReader>;
47
+ export declare function createGitRefReminderReaderAsync(projectPath: string, ref: string): {
48
+ pathExists: (path: string) => Promise<boolean>;
49
+ isDirectory: (path: string) => Promise<boolean>;
50
+ readFile: (path: string) => Promise<string>;
51
+ getPathIdentity: (path: string) => Promise<string>;
52
+ };
53
+ export interface AsyncInstructionFileReader {
54
+ exists(path: string): Promise<boolean>;
55
+ read(path: string): Promise<string>;
56
+ ref?: string;
57
+ }
58
+ export declare function loadAgentInstructionsAsync(projectPath: string, configDirName?: string, projectReader?: AsyncInstructionFileReader, { skipGlobal }?: {
59
+ skipGlobal?: boolean;
60
+ }): Promise<InstructionSource[]>;
61
+ export declare function loadSessionInstructionsAsync({ workingDir, instructionRoots, configDir, untrustedCheckout, baseRef, skipGlobal, }: {
62
+ workingDir: string;
63
+ instructionRoots?: readonly string[];
64
+ configDir?: string;
65
+ untrustedCheckout?: boolean;
66
+ baseRef?: string;
67
+ skipGlobal?: boolean;
68
+ }): Promise<InstructionSource[]>;
69
+ /**
70
+ * Load all agent instruction files from global and project locations.
71
+ * Returns an array of instruction sources, with global ones first.
72
+ *
73
+ * `projectReader` controls where project-scope content comes from (defaults to
74
+ * the working tree). Global instructions read the operator machine's
75
+ * filesystem, unless `skipGlobal` keeps them out entirely.
76
+ */
77
+ export declare function loadAgentInstructions(projectPath: string, configDirName?: string, projectReader?: InstructionFileReader, { skipGlobal }?: {
78
+ skipGlobal?: boolean;
79
+ }): InstructionSource[];
80
+ export declare function getStaticallyLoadedInstructionPaths(projectPath: string, configDirName?: string, projectReader?: InstructionFileReader): string[];
81
+ /**
82
+ * Directories a session's project instructions load from: the host's
83
+ * `instructionRoots` (resolved against the working directory, the session's
84
+ * own checkout first) when it sets any, else the working directory itself.
85
+ */
86
+ export declare function sessionInstructionRoots(workingDir: string, instructionRoots?: readonly string[]): string[];
87
+ /**
88
+ * The instruction files a session's system prompt carries. Global files load
89
+ * once (unless `skipGlobal`), then each instruction root's project files, in
90
+ * root order. An untrusted checkout never reads project files off the working
91
+ * tree: with a `baseRef` the first root (the session's own checkout) is served
92
+ * from that ref and the other roots are skipped; without one no project files
93
+ * load.
94
+ */
95
+ export declare function loadSessionInstructions({ workingDir, instructionRoots, configDir, untrustedCheckout, baseRef, skipGlobal, }: {
96
+ workingDir: string;
97
+ instructionRoots?: readonly string[];
98
+ configDir?: string;
99
+ untrustedCheckout?: boolean;
100
+ baseRef?: string;
101
+ skipGlobal?: boolean;
102
+ }): InstructionSource[];
103
+ /**
104
+ * Paths of loaded instruction sources, each project source also under its
105
+ * root's canonical path, so reactive reminders never repeat a file the
106
+ * system prompt already carries.
107
+ */
108
+ export declare function instructionSourcePaths(sources: InstructionSource[], roots: readonly string[]): string[];
109
+ /** Heading the agent-instructions block is introduced by in the system prompt. */
110
+ export declare const AGENT_INSTRUCTIONS_HEADING = "# Agent Instructions";
111
+ /**
112
+ * Format a single instruction source as it appears in the system prompt.
113
+ *
114
+ * Exported so callers that attribute prompt cost per source (the `/context`
115
+ * audit) measure the exact block that is sent rather than reconstructing it.
116
+ */
117
+ export declare function formatInstructionSource(source: InstructionSource): string;
118
+ /**
119
+ * Format loaded instructions into a string for the system prompt.
120
+ */
121
+ export declare function formatAgentInstructions(sources: InstructionSource[]): string;
122
+ //# sourceMappingURL=agent-instructions.d.ts.map