@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,85 @@
1
+ import type { CustomModelCatalogProvider } from '@mastra/core/agent-controller';
2
+ import { MastraModelGateway } from '@mastra/core/llm';
3
+ import type { GatewayAuthRequest, GatewayAuthResult, GatewayLanguageModel, MastraModelGatewayInterface, ProviderConfig } from '@mastra/core/llm';
4
+ import { AuthStorage } from '../auth/storage.js';
5
+ import type { CredentialStore } from '../auth/types.js';
6
+ import type { AnthropicPromptCacheScope } from '../providers/anthropic-prompt-cache.js';
7
+ import type { CodexServiceTier } from '../providers/model-ids.js';
8
+ import type { ThinkingLevel } from '../providers/openai-codex.js';
9
+ export { MASTRA_GATEWAY_PREFIX, OPENAI_PREFIX, remapOpenAIModelForCodexOAuth, stripMastraGatewayPrefix, } from '../providers/model-ids.js';
10
+ export declare const MASTRACODE_GATEWAY_ID = "mastracode";
11
+ export type MastraCodeCustomProvider = {
12
+ name: string;
13
+ url: string;
14
+ apiKey?: string;
15
+ models?: string[];
16
+ };
17
+ export type MastraCodeGatewayOptions = {
18
+ mastraGatewayBaseUrl: string;
19
+ mastraGatewayApiKey?: string;
20
+ routeThroughMastraGateway: boolean;
21
+ thinkingLevel?: ThinkingLevel;
22
+ /** Anthropic prompt-cache breakpoints to write. Defaults to `conversation`. */
23
+ anthropicPromptCacheScope?: AnthropicPromptCacheScope;
24
+ customProviders?: MastraCodeCustomProvider[];
25
+ settingsPath?: string;
26
+ /**
27
+ * Per-tenant credential source for this gateway instance. Defaults to the
28
+ * server-global file-backed `AuthStorage`; deployed web passes the calling
29
+ * tenant's store so model calls use the caller's own credentials.
30
+ */
31
+ credentialStore?: CredentialStore;
32
+ };
33
+ export declare function getGlobalAuthStorage(): AuthStorage;
34
+ export declare function reloadAuthStorage(): void;
35
+ /**
36
+ * Resolve the Anthropic API key.
37
+ * Main slot → dedicated apikey: slot → env var.
38
+ */
39
+ export declare function getAnthropicApiKey(credentials?: CredentialStore): string | undefined;
40
+ /**
41
+ * Resolve the OpenAI API key.
42
+ * Main slot → dedicated apikey: slot → env var.
43
+ */
44
+ export declare function getOpenAIApiKey(credentials?: CredentialStore): string | undefined;
45
+ export declare function resolveAuth(request: GatewayAuthRequest, mastraGatewayApiKey?: string): GatewayAuthResult | undefined;
46
+ export declare function providerApiKeyEnvVar(providerId: string): string | undefined;
47
+ /**
48
+ * Whether the process environment has a key for a models.dev provider. Checks every
49
+ * env var the registry lists, as the models.dev gateway does when `resolveModel`
50
+ * gets no gateway credential (e.g. `GOOGLE_API_KEY` or `GOOGLE_GENERATIVE_AI_API_KEY`).
51
+ */
52
+ export declare function hasProviderEnvironmentKey(providerId: string): boolean;
53
+ export declare class MastraCodeGateway extends MastraModelGateway {
54
+ #private;
55
+ readonly id = "mastracode";
56
+ readonly name = "MastraCode Gateway";
57
+ constructor({ mastraGatewayBaseUrl, mastraGatewayApiKey, routeThroughMastraGateway, thinkingLevel, anthropicPromptCacheScope, customProviders, settingsPath, credentialStore, }: MastraCodeGatewayOptions);
58
+ static getMastraGatewayApiKey(): string | undefined;
59
+ /** @deprecated Renamed to {@link MastraCodeGateway.getMastraGatewayApiKey}. */
60
+ static getMemoryGatewayApiKey(): string | undefined;
61
+ /**
62
+ * Claim an unprefixed model id (e.g. a bare `anthropic/...`) when this gateway
63
+ * can authenticate it via OAuth or a stored/env credential. This lets the
64
+ * shared gateway router select MastraCode for auth resolution, so the status
65
+ * bar and `/api-keys` reflect OAuth logins instead of only checking env vars.
66
+ */
67
+ handlesModel(selectionId: string): boolean;
68
+ static resolveProviderAuth(request: GatewayAuthRequest, mastraGatewayApiKey?: string, credentials?: CredentialStore): GatewayAuthResult | undefined;
69
+ static createModelCatalogProvider(gateway: MastraModelGatewayInterface): CustomModelCatalogProvider;
70
+ createModelCatalogProvider(): CustomModelCatalogProvider;
71
+ fetchProviders(): Promise<Record<string, ProviderConfig>>;
72
+ buildUrl(modelId: string): string | undefined | Promise<string | undefined>;
73
+ getApiKey(modelId: string): Promise<string>;
74
+ resolveAuth(request: GatewayAuthRequest): GatewayAuthResult | undefined;
75
+ resolveLanguageModel(args: {
76
+ modelId: string;
77
+ providerId: string;
78
+ apiKey: string;
79
+ headers?: Record<string, string>;
80
+ transport?: any;
81
+ responsesWebSocket?: any;
82
+ codexServiceTier?: CodexServiceTier;
83
+ }): GatewayLanguageModel;
84
+ }
85
+ //# sourceMappingURL=mastracode-gateway.d.ts.map
@@ -0,0 +1,500 @@
1
+ import { AuthStorage } from "../auth/storage.js";
2
+ import { getCustomProviderId, loadSettings } from "../onboarding/settings.js";
3
+ import { buildAnthropicOAuthFetch, claudeCodeMiddleware, createAnthropicThinkingMiddleware, createPromptCacheMiddleware, opencodeClaudeMaxProvider } from "../providers/claude-max.js";
4
+ import { githubCopilotProvider } from "../providers/github-copilot.js";
5
+ import { createGoogleThinkingMiddleware } from "../providers/google-thinking.js";
6
+ import { kimiCodingProvider } from "../providers/kimi-coding.js";
7
+ import { MASTRA_GATEWAY_PREFIX, OPENAI_PREFIX, getCredentialProviderId, normalizeAnthropicModelId, parseCodexModelSelection, remapOpenAIModelForCodexOAuth, stripMastraGatewayPrefix } from "../providers/model-ids.js";
8
+ import { THINKING_LEVEL_TO_REASONING_EFFORT, buildOpenAICodexOAuthFetch, createCodexMiddleware, createPromptCacheKeyMiddleware, createReasoningEffortMiddleware, getEffectiveThinkingLevel, getRequestThreadId, openaiCodexProvider } from "../providers/openai-codex.js";
9
+ import { ModelRouterLanguageModelWithThinking, providerThinkingOptions, withThinkingOptionsModel } from "../providers/provider-thinking.js";
10
+ import { xaiProvider } from "../providers/xai.js";
11
+ import { getAppDataDir } from "../utils/project.js";
12
+ import { resolveCustomProviders } from "./custom-provider-source.js";
13
+ import { GATEWAY_AUTH_HEADER, MastraGateway, MastraModelGateway, ModelRouterLanguageModel, PROVIDER_REGISTRY } from "@mastra/core/llm";
14
+ import { createOpenAI } from "@ai-sdk/openai";
15
+ import { wrapLanguageModel } from "ai";
16
+ import { createAnthropic } from "@ai-sdk/anthropic";
17
+ import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
18
+ // src/agents/mastracode-gateway.ts
19
+ const PROVIDERS = PROVIDER_REGISTRY;
20
+ const MASTRACODE_GATEWAY_ID = "mastracode";
21
+ /** Gateway request header. `false` lets the gateway drop prompt cache controls no route can serve instead of refusing the request. */
22
+ const GATEWAY_STRICT_CAPABILITIES_HEADER = "x-gateway-strict-capabilities";
23
+ /** Organization keys reach the gateway that leaves memory, and so the prompt, to the client. */
24
+ function isOrganizationGatewayKey(apiKey) {
25
+ return apiKey.startsWith("msk-gateway-") || apiKey.startsWith("mskv2_");
26
+ }
27
+ /**
28
+ * Global file-backed credential store for local (TUI) model resolution.
29
+ *
30
+ * Constructed lazily, NOT at module scope: `AuthStorage`'s default path is
31
+ * resolved from `MASTRA_APP_DATA_DIR` at construction, and this module is
32
+ * routinely imported before test harnesses / embedders point that variable at
33
+ * an isolated directory — an import-time construction would permanently pin
34
+ * the developer's real app-data dir for every credential read.
35
+ */
36
+ let authStorageSingleton;
37
+ let authStorageSingletonDir;
38
+ function getGlobalAuthStorage() {
39
+ const dir = getAppDataDir();
40
+ if (!authStorageSingleton || authStorageSingletonDir !== dir) {
41
+ authStorageSingleton = new AuthStorage();
42
+ authStorageSingletonDir = dir;
43
+ }
44
+ return authStorageSingleton;
45
+ }
46
+ function reloadAuthStorage() {
47
+ getGlobalAuthStorage().reload();
48
+ }
49
+ /**
50
+ * Resolve the Anthropic API key.
51
+ * Main slot → dedicated apikey: slot → env var.
52
+ */
53
+ function getAnthropicApiKey(credentials = getGlobalAuthStorage()) {
54
+ const storedCred = credentials.get("anthropic");
55
+ if (storedCred?.type === "api_key" && storedCred.key.trim().length > 0) return storedCred.key.trim();
56
+ const dedicatedKey = credentials.getStoredApiKey("anthropic")?.trim();
57
+ if (dedicatedKey) return dedicatedKey;
58
+ return credentials.allowEnvironmentFallback === false ? void 0 : process.env.ANTHROPIC_API_KEY?.trim() || void 0;
59
+ }
60
+ /**
61
+ * Resolve the OpenAI API key.
62
+ * Main slot → dedicated apikey: slot → env var.
63
+ */
64
+ function getOpenAIApiKey(credentials = getGlobalAuthStorage()) {
65
+ const storedCred = credentials.get("openai-codex");
66
+ if (storedCred?.type === "api_key" && storedCred.key.trim().length > 0) return storedCred.key.trim();
67
+ const dedicatedKey = credentials.getStoredApiKey("openai-codex")?.trim();
68
+ if (dedicatedKey) return dedicatedKey;
69
+ return credentials.allowEnvironmentFallback === false ? void 0 : process.env.OPENAI_API_KEY?.trim() || void 0;
70
+ }
71
+ function anthropicApiKeyProvider(modelId, apiKey, headers, thinkingLevel, promptCacheScope) {
72
+ const anthropic = createAnthropic({
73
+ apiKey,
74
+ headers
75
+ });
76
+ const thinkingMiddleware = createAnthropicThinkingMiddleware(modelId, thinkingLevel);
77
+ return wrapLanguageModel({
78
+ model: anthropic(modelId),
79
+ middleware: [createPromptCacheMiddleware(promptCacheScope), ...thinkingMiddleware ? [thinkingMiddleware] : []]
80
+ });
81
+ }
82
+ function openaiApiKeyProvider(modelId, apiKey, headers, thinkingLevel) {
83
+ const openai = createOpenAI({
84
+ apiKey,
85
+ baseURL: process.env.OPENAI_BASE_URL,
86
+ headers
87
+ });
88
+ const middleware = thinkingLevel && thinkingLevel !== "off" ? createReasoningEffortMiddleware("openai", THINKING_LEVEL_TO_REASONING_EFFORT[getEffectiveThinkingLevel(modelId, thinkingLevel)]) : void 0;
89
+ const promptCacheKeyMiddleware = createPromptCacheKeyMiddleware(getRequestThreadId(headers));
90
+ return wrapLanguageModel({
91
+ model: openai.responses(modelId),
92
+ middleware: [...middleware ? [middleware] : [], ...promptCacheKeyMiddleware ? [promptCacheKeyMiddleware] : []]
93
+ });
94
+ }
95
+ function getProviderAuthKey(providerId, credentials = getGlobalAuthStorage()) {
96
+ const authProviderId = getCredentialProviderId(providerId);
97
+ const storedCred = credentials.get(authProviderId);
98
+ if (storedCred?.type === "api_key" && storedCred.key.trim().length > 0) return storedCred.key.trim();
99
+ const dedicatedKey = credentials.getStoredApiKey(authProviderId)?.trim();
100
+ if (dedicatedKey) return dedicatedKey;
101
+ const catalogKey = authProviderId !== providerId ? credentials.getStoredApiKey(providerId)?.trim() : void 0;
102
+ if (catalogKey) return catalogKey;
103
+ if (credentials.allowEnvironmentFallback === false) return void 0;
104
+ return authProviderId === "kimi-for-coding" ? process.env.KIMI_API_KEY?.trim() || void 0 : void 0;
105
+ }
106
+ function resolveAuth(request, mastraGatewayApiKey) {
107
+ return MastraCodeGateway.resolveProviderAuth(request, mastraGatewayApiKey);
108
+ }
109
+ function getGatewayProviderKey(gatewayId, providerId) {
110
+ if (gatewayId === "models.dev") return providerId;
111
+ return providerId === gatewayId ? gatewayId : `${gatewayId}/${providerId}`;
112
+ }
113
+ function parseGatewayRouterId(routerId, gateway) {
114
+ const [firstPart = "", secondPart = "", ...restParts] = routerId.split("/");
115
+ const gatewayId = gateway.id;
116
+ if (firstPart === gatewayId && secondPart) return {
117
+ gatewayId,
118
+ providerId: secondPart,
119
+ modelId: restParts.join("/")
120
+ };
121
+ return {
122
+ gatewayId,
123
+ providerId: firstPart,
124
+ modelId: [secondPart, ...restParts].filter(Boolean).join("/")
125
+ };
126
+ }
127
+ function hasResolvedAuth(auth) {
128
+ if (!auth) return false;
129
+ if (auth.apiKey || auth.bearerToken) return true;
130
+ return auth.headers ? Object.keys(auth.headers).length > 0 : false;
131
+ }
132
+ async function resolveGatewayProviderAuth(gateway, routerId) {
133
+ if (!gateway.resolveAuth) return void 0;
134
+ const parsed = parseGatewayRouterId(routerId, gateway);
135
+ try {
136
+ const result = await gateway.resolveAuth({
137
+ gatewayId: parsed.gatewayId,
138
+ providerId: parsed.providerId,
139
+ modelId: parsed.modelId,
140
+ routerId
141
+ });
142
+ return hasResolvedAuth(result) ? result : void 0;
143
+ } catch {
144
+ return;
145
+ }
146
+ }
147
+ async function getMastraCodeProviderConfigs(gateway) {
148
+ const providers = { ...PROVIDERS };
149
+ try {
150
+ const gatewayProviders = await gateway.fetchProviders();
151
+ for (const [providerId, config] of Object.entries(gatewayProviders)) providers[getGatewayProviderKey(gateway.id, providerId)] = {
152
+ ...config,
153
+ gateway: gateway.id
154
+ };
155
+ } catch (error) {
156
+ console.warn(`Failed to load providers from gateway ${gateway.id}:`, error);
157
+ }
158
+ return providers;
159
+ }
160
+ function getApiKeyEnvVar(providerConfig) {
161
+ const envVars = providerConfig?.apiKeyEnvVar;
162
+ return Array.isArray(envVars) ? envVars[0] : envVars;
163
+ }
164
+ function providerApiKeyEnvVar(providerId) {
165
+ return getApiKeyEnvVar(PROVIDERS[providerId]);
166
+ }
167
+ /**
168
+ * Whether the process environment has a key for a models.dev provider. Checks every
169
+ * env var the registry lists, as the models.dev gateway does when `resolveModel`
170
+ * gets no gateway credential (e.g. `GOOGLE_API_KEY` or `GOOGLE_GENERATIVE_AI_API_KEY`).
171
+ */
172
+ function hasProviderEnvironmentKey(providerId) {
173
+ const envVars = PROVIDERS[providerId]?.apiKeyEnvVar;
174
+ if (!envVars) return false;
175
+ return (Array.isArray(envVars) ? envVars : [envVars]).some((envVar) => Boolean(process.env[envVar]?.trim()));
176
+ }
177
+ /** Servers call custom endpoints too: a redirect could aim that call at an address the saved URL never named. */
178
+ const fetchWithoutRedirects = (input, init) => fetch(input, {
179
+ ...init,
180
+ redirect: "error"
181
+ });
182
+ var MastraCodeGateway = class MastraCodeGateway extends MastraModelGateway {
183
+ id = MASTRACODE_GATEWAY_ID;
184
+ name = "MastraCode Gateway";
185
+ #mastraGateway;
186
+ #mastraGatewayBaseUrl;
187
+ #mastraGatewayApiKey;
188
+ #routeThroughMastraGateway;
189
+ #thinkingLevel;
190
+ #anthropicPromptCacheScope;
191
+ #customProviders;
192
+ #settingsPath;
193
+ #credentials;
194
+ constructor({ mastraGatewayBaseUrl, mastraGatewayApiKey, routeThroughMastraGateway, thinkingLevel, anthropicPromptCacheScope, customProviders, settingsPath, credentialStore }) {
195
+ super();
196
+ this.#mastraGateway = new MastraGateway({ baseUrl: mastraGatewayBaseUrl });
197
+ this.#mastraGatewayBaseUrl = mastraGatewayBaseUrl;
198
+ this.#mastraGatewayApiKey = mastraGatewayApiKey;
199
+ this.#routeThroughMastraGateway = routeThroughMastraGateway;
200
+ this.#thinkingLevel = thinkingLevel;
201
+ this.#anthropicPromptCacheScope = anthropicPromptCacheScope ?? "conversation";
202
+ this.#customProviders = customProviders;
203
+ this.#settingsPath = settingsPath;
204
+ this.#credentials = credentialStore ?? getGlobalAuthStorage();
205
+ }
206
+ static getMastraGatewayApiKey() {
207
+ return getGlobalAuthStorage().getStoredApiKey("mastra-gateway") ?? process.env["MASTRA_GATEWAY_API_KEY"];
208
+ }
209
+ /** @deprecated Renamed to {@link MastraCodeGateway.getMastraGatewayApiKey}. */
210
+ static getMemoryGatewayApiKey() {
211
+ return MastraCodeGateway.getMastraGatewayApiKey();
212
+ }
213
+ /**
214
+ * Claim an unprefixed model id (e.g. a bare `anthropic/...`) when this gateway
215
+ * can authenticate it via OAuth or a stored/env credential. This lets the
216
+ * shared gateway router select MastraCode for auth resolution, so the status
217
+ * bar and `/api-keys` reflect OAuth logins instead of only checking env vars.
218
+ */
219
+ handlesModel(selectionId) {
220
+ const { modelId } = parseCodexModelSelection(selectionId);
221
+ const parsed = parseGatewayRouterId(modelId, this);
222
+ if (!parsed.providerId || !parsed.modelId) return false;
223
+ if (this.#routeThroughMastraGateway && this.#mastraGatewayApiKey) return true;
224
+ if (this.#customProvider(parsed.providerId)) return true;
225
+ return hasResolvedAuth(MastraCodeGateway.resolveProviderAuth({
226
+ gatewayId: this.id,
227
+ providerId: parsed.providerId,
228
+ modelId: parsed.modelId,
229
+ routerId: modelId
230
+ }, void 0, this.#credentials));
231
+ }
232
+ static resolveProviderAuth(request, mastraGatewayApiKey, credentials = getGlobalAuthStorage()) {
233
+ if (request.gatewayId === "mastra" && mastraGatewayApiKey) return {
234
+ apiKey: mastraGatewayApiKey,
235
+ source: "gateway"
236
+ };
237
+ const authProviderId = getCredentialProviderId(request.providerId);
238
+ if (credentials.get(authProviderId)?.type === "oauth") return {
239
+ bearerToken: "oauth",
240
+ source: "gateway"
241
+ };
242
+ const apiKey = getProviderAuthKey(request.providerId, credentials);
243
+ return apiKey ? {
244
+ apiKey,
245
+ source: "gateway"
246
+ } : void 0;
247
+ }
248
+ static createModelCatalogProvider(gateway) {
249
+ return async () => {
250
+ const registry = await getMastraCodeProviderConfigs(gateway);
251
+ const models = [];
252
+ for (const [provider, providerConfig] of Object.entries(registry)) {
253
+ const apiKeyEnvVar = getApiKeyEnvVar(providerConfig);
254
+ const hasEnvKey = apiKeyEnvVar ? Boolean(process.env[apiKeyEnvVar]) : false;
255
+ const modelNames = providerConfig.models;
256
+ if (!Array.isArray(modelNames)) continue;
257
+ const gatewayAuth = modelNames[0] ? await resolveGatewayProviderAuth(gateway, `${provider}/${modelNames[0]}`) : void 0;
258
+ for (const modelName of modelNames) {
259
+ const id = `${provider}/${modelName}`;
260
+ models.push({
261
+ id,
262
+ provider,
263
+ modelName,
264
+ hasApiKey: hasEnvKey || Boolean(gatewayAuth),
265
+ apiKeyEnvVar: apiKeyEnvVar || void 0
266
+ });
267
+ }
268
+ }
269
+ return models;
270
+ };
271
+ }
272
+ createModelCatalogProvider() {
273
+ return MastraCodeGateway.createModelCatalogProvider(this);
274
+ }
275
+ #getCustomProviders() {
276
+ return this.#customProviders ?? resolveCustomProviders() ?? loadSettings(this.#settingsPath).customProviders;
277
+ }
278
+ /**
279
+ * The custom provider a provider id refers to, if any. Every method that
280
+ * resolves a model or its credentials goes through this lookup, so a custom
281
+ * endpoint only ever authenticates with its own key: it is never handed a
282
+ * credential saved for another provider, even when the ids collide. A model
283
+ * routed through the Mastra gateway is never a custom provider.
284
+ */
285
+ #customProvider(providerId) {
286
+ if (this.#routeThroughMastraGateway) return void 0;
287
+ return this.#getCustomProviders().find((provider) => providerId === getCustomProviderId(provider.name));
288
+ }
289
+ async fetchProviders() {
290
+ this.#credentials.reload();
291
+ const providers = {};
292
+ for (const provider of this.#getCustomProviders()) {
293
+ const models = provider.models ?? [];
294
+ if (!models.length) continue;
295
+ providers[getCustomProviderId(provider.name)] = {
296
+ name: provider.name,
297
+ url: provider.url,
298
+ apiKeyEnvVar: "",
299
+ apiKeyHeader: "Authorization",
300
+ gateway: this.id,
301
+ models
302
+ };
303
+ }
304
+ return providers;
305
+ }
306
+ buildUrl(modelId) {
307
+ return this.#routeThroughMastraGateway ? this.#mastraGateway.buildUrl(modelId) : modelId;
308
+ }
309
+ async getApiKey(modelId) {
310
+ const { providerId } = parseGatewayRouterId(stripMastraGatewayPrefix(modelId), this);
311
+ if (this.#routeThroughMastraGateway) return this.#mastraGatewayApiKey ?? "";
312
+ if (!providerId) return "";
313
+ const customProvider = this.#customProvider(providerId);
314
+ if (customProvider) return customProvider.apiKey ?? "";
315
+ return getProviderAuthKey(providerId, this.#credentials) ?? "";
316
+ }
317
+ resolveAuth(request) {
318
+ if (this.#routeThroughMastraGateway && this.#mastraGatewayApiKey) return {
319
+ apiKey: this.#mastraGatewayApiKey,
320
+ source: "gateway"
321
+ };
322
+ const customProvider = this.#customProvider(request.providerId);
323
+ if (customProvider) return customProvider.apiKey ? {
324
+ apiKey: customProvider.apiKey,
325
+ source: "gateway"
326
+ } : { source: "gateway" };
327
+ return MastraCodeGateway.resolveProviderAuth(request, void 0, this.#credentials);
328
+ }
329
+ resolveLanguageModel(args) {
330
+ const customProvider = this.#customProvider(args.providerId);
331
+ const selection = customProvider ? void 0 : parseCodexModelSelection(`${args.providerId}/${args.modelId}`);
332
+ if (selection && selection.modelId !== `${args.providerId}/${args.modelId}`) args = {
333
+ ...args,
334
+ modelId: selection.modelId.slice(OPENAI_PREFIX.length),
335
+ ...selection.codexServiceTier ? { codexServiceTier: selection.codexServiceTier } : {}
336
+ };
337
+ if (customProvider) {
338
+ const provider = createOpenAICompatible({
339
+ name: args.providerId,
340
+ baseURL: customProvider.url,
341
+ apiKey: args.apiKey,
342
+ headers: args.headers,
343
+ fetch: fetchWithoutRedirects
344
+ });
345
+ const reasoningEffort = this.#thinkingLevel ? THINKING_LEVEL_TO_REASONING_EFFORT[this.#thinkingLevel] : void 0;
346
+ const middleware = createReasoningEffortMiddleware(args.providerId, reasoningEffort);
347
+ if (!middleware) return provider.chatModel(args.modelId);
348
+ return wrapLanguageModel({
349
+ model: provider.chatModel(args.modelId),
350
+ middleware: [middleware]
351
+ });
352
+ }
353
+ if (args.providerId === "github-copilot") return githubCopilotProvider(args.modelId, {
354
+ headers: args.headers,
355
+ authStorage: this.#credentials
356
+ });
357
+ if (args.providerId === "moonshotai" && !this.#routeThroughMastraGateway) {
358
+ const apiKey = args.apiKey?.trim() || process.env.MOONSHOT_API_KEY?.trim() || process.env.MOONSHOT_AI_API_KEY?.trim();
359
+ if (!apiKey) throw new Error("Need MOONSHOT_API_KEY");
360
+ return createAnthropic({
361
+ apiKey,
362
+ baseURL: "https://api.moonshot.ai/anthropic/v1",
363
+ name: "moonshotai.anthropicv1",
364
+ headers: args.headers
365
+ })(args.modelId);
366
+ }
367
+ if (args.providerId === "anthropic") return this.#resolveAnthropicModel(args);
368
+ if (args.providerId === "openai") {
369
+ const openaiModel = this.#resolveOpenAIModel(args);
370
+ if (openaiModel) return openaiModel;
371
+ }
372
+ if (args.providerId === "xai" && this.#credentials.get("xai")?.type === "oauth") return withThinkingOptionsModel(xaiProvider(args.modelId, {
373
+ headers: args.headers,
374
+ authStorage: this.#credentials
375
+ }), providerThinkingOptions(`xai/${args.modelId}`, this.#thinkingLevel));
376
+ if (this.#routeThroughMastraGateway) return this.#mastraGateway.resolveLanguageModel(args);
377
+ if (args.providerId === "google") return this.#resolveGoogleModel(args);
378
+ if (args.providerId === "kimi-code-plan-cn" || args.providerId === "kimi-for-coding") return kimiCodingProvider(args.modelId, {
379
+ apiKey: args.apiKey,
380
+ headers: args.headers,
381
+ credentialStore: this.#credentials
382
+ });
383
+ const routedModelId = `${args.providerId}/${args.modelId}`;
384
+ return new ModelRouterLanguageModelWithThinking({
385
+ id: routedModelId,
386
+ apiKey: args.apiKey,
387
+ headers: args.headers
388
+ }, providerThinkingOptions(routedModelId, this.#thinkingLevel));
389
+ }
390
+ #resolveAnthropicModel(args) {
391
+ const bareModelId = normalizeAnthropicModelId(args.modelId);
392
+ const storedCred = this.#credentials.get("anthropic");
393
+ const thinkingMiddleware = createAnthropicThinkingMiddleware(bareModelId, this.#thinkingLevel);
394
+ if (this.#routeThroughMastraGateway) {
395
+ if (storedCred?.type === "oauth") {
396
+ const anthropic = createAnthropic({
397
+ apiKey: "oauth-gateway-placeholder",
398
+ baseURL: `${this.#mastraGatewayBaseUrl}/v1`,
399
+ headers: {
400
+ [GATEWAY_AUTH_HEADER]: `Bearer ${args.apiKey}`,
401
+ ...args.headers
402
+ },
403
+ fetch: buildAnthropicOAuthFetch({ authStorage: this.#credentials })
404
+ });
405
+ return wrapLanguageModel({
406
+ model: anthropic(bareModelId),
407
+ middleware: [
408
+ claudeCodeMiddleware,
409
+ createPromptCacheMiddleware(this.#anthropicPromptCacheScope),
410
+ ...thinkingMiddleware ? [thinkingMiddleware] : []
411
+ ]
412
+ });
413
+ }
414
+ if (!isOrganizationGatewayKey(args.apiKey)) return this.#mastraGateway.resolveLanguageModel({
415
+ ...args,
416
+ modelId: bareModelId
417
+ });
418
+ return wrapLanguageModel({
419
+ model: this.#mastraGateway.resolveLanguageModel({
420
+ ...args,
421
+ modelId: bareModelId,
422
+ headers: {
423
+ ...args.headers,
424
+ [GATEWAY_STRICT_CAPABILITIES_HEADER]: "false"
425
+ }
426
+ }),
427
+ middleware: [createPromptCacheMiddleware(this.#anthropicPromptCacheScope)]
428
+ });
429
+ }
430
+ if (storedCred?.type === "oauth") return opencodeClaudeMaxProvider(bareModelId, {
431
+ headers: args.headers,
432
+ authStorage: this.#credentials,
433
+ thinkingLevel: this.#thinkingLevel,
434
+ promptCacheScope: this.#anthropicPromptCacheScope
435
+ });
436
+ if (storedCred?.type === "api_key" && storedCred.key.trim().length > 0) return anthropicApiKeyProvider(bareModelId, storedCred.key.trim(), args.headers, this.#thinkingLevel, this.#anthropicPromptCacheScope);
437
+ const apiKey = getAnthropicApiKey(this.#credentials);
438
+ if (apiKey) return anthropicApiKeyProvider(bareModelId, apiKey, args.headers, this.#thinkingLevel, this.#anthropicPromptCacheScope);
439
+ return opencodeClaudeMaxProvider(bareModelId, {
440
+ headers: args.headers,
441
+ authStorage: this.#credentials,
442
+ thinkingLevel: this.#thinkingLevel,
443
+ promptCacheScope: this.#anthropicPromptCacheScope
444
+ });
445
+ }
446
+ #resolveOpenAIModel(args) {
447
+ const storedCred = this.#credentials.get("openai-codex");
448
+ if (this.#routeThroughMastraGateway) {
449
+ if (storedCred?.type === "oauth") {
450
+ const resolvedBareModelId = remapOpenAIModelForCodexOAuth(`openai/${args.modelId}`).substring(OPENAI_PREFIX.length);
451
+ const effectiveLevel = getEffectiveThinkingLevel(args.modelId, this.#thinkingLevel ?? "medium");
452
+ const reasoningEffort = THINKING_LEVEL_TO_REASONING_EFFORT[effectiveLevel];
453
+ const middleware = createCodexMiddleware(reasoningEffort, { serviceTier: args.codexServiceTier });
454
+ const promptCacheKeyMiddleware = createPromptCacheKeyMiddleware(getRequestThreadId(args.headers));
455
+ const openai = createOpenAI({
456
+ apiKey: "oauth-gateway-placeholder",
457
+ baseURL: `${this.#mastraGatewayBaseUrl}/v1`,
458
+ headers: {
459
+ [GATEWAY_AUTH_HEADER]: `Bearer ${args.apiKey}`,
460
+ ...args.headers
461
+ },
462
+ fetch: buildOpenAICodexOAuthFetch({
463
+ authStorage: this.#credentials,
464
+ rewriteUrl: false
465
+ })
466
+ });
467
+ return wrapLanguageModel({
468
+ model: openai.responses(resolvedBareModelId),
469
+ middleware: [middleware, ...promptCacheKeyMiddleware ? [promptCacheKeyMiddleware] : []]
470
+ });
471
+ }
472
+ return this.#mastraGateway.resolveLanguageModel(args);
473
+ }
474
+ if (storedCred?.type === "oauth") {
475
+ const resolvedModelId = remapOpenAIModelForCodexOAuth(`openai/${args.modelId}`);
476
+ return openaiCodexProvider(resolvedModelId.substring(OPENAI_PREFIX.length), {
477
+ thinkingLevel: this.#thinkingLevel && getEffectiveThinkingLevel(args.modelId, this.#thinkingLevel),
478
+ serviceTier: args.codexServiceTier,
479
+ headers: args.headers,
480
+ authStorage: this.#credentials
481
+ });
482
+ }
483
+ const apiKey = getOpenAIApiKey(this.#credentials);
484
+ if (apiKey) return openaiApiKeyProvider(args.modelId, apiKey, args.headers, this.#thinkingLevel);
485
+ }
486
+ #resolveGoogleModel(args) {
487
+ const routerModel = new ModelRouterLanguageModel({
488
+ id: `${args.providerId}/${args.modelId}`,
489
+ apiKey: args.apiKey,
490
+ headers: args.headers
491
+ });
492
+ const thinkingMiddleware = createGoogleThinkingMiddleware(args.modelId, this.#thinkingLevel);
493
+ if (!thinkingMiddleware) return routerModel;
494
+ return wrapLanguageModel({
495
+ model: routerModel,
496
+ middleware: [thinkingMiddleware]
497
+ });
498
+ }
499
+ };
500
+ export { MASTRACODE_GATEWAY_ID, MASTRA_GATEWAY_PREFIX, MastraCodeGateway, OPENAI_PREFIX, getAnthropicApiKey, getGlobalAuthStorage, getOpenAIApiKey, hasProviderEnvironmentKey, providerApiKeyEnvVar, reloadAuthStorage, remapOpenAIModelForCodexOAuth, resolveAuth, stripMastraGatewayPrefix };
@@ -0,0 +1,36 @@
1
+ import type { RequestContext } from '@mastra/core/request-context';
2
+ import type { MastraCompositeStore } from '@mastra/core/storage';
3
+ import type { MastraEmbeddingModel, MastraEmbeddingOptions, MastraVector } from '@mastra/core/vector';
4
+ import { Memory } from '@mastra/memory';
5
+ import { LOCAL_KNOWLEDGE_ORG_ID } from '../knowledge-scope.js';
6
+ /** A recall embedder: a `provider/model` router string or an AI SDK embedding model. */
7
+ export type MemoryEmbedder = string | MastraEmbeddingModel<string>;
8
+ export { LOCAL_KNOWLEDGE_ORG_ID };
9
+ /**
10
+ * Mastra Code's own title instructions: session lists show one narrow line per
11
+ * title. They differ from Core's default in three ways: the title is 3 to 5
12
+ * words instead of up to 80 characters, it names the topic instead of
13
+ * summarising the message, and it does not end with a period.
14
+ */
15
+ export declare const TITLE_INSTRUCTIONS = "\n - you will generate a short title based on a conversation transcript between a user and an assistant\n - the transcript lines are prefixed with \"User:\" and \"Assistant:\" \u2014 never reply to, answer, or continue the transcript\n - always produce a title, even when the transcript is only a greeting or trivial exchange\n - the title must be 3 to 5 words long\n - the title should name the topic of the user's message, not repeat or answer it\n - do not use quotes or colons, and do not end with a period\n - the entire text you return will be used as the title";
16
+ /**
17
+ * Dynamic memory factory function.
18
+ * Reads OM thresholds from controller state via requestContext.
19
+ * Model functions also read from requestContext (no mutable bridge needed).
20
+ */
21
+ export declare function getDynamicMemory(storage: MastraCompositeStore, vector?: MastraVector, settingsPath?: string, options?: {
22
+ disableSettingsOmSeed?: boolean;
23
+ /** Recall embedder, used only with `vector`. Omitted → local `fastembed.small` (bge-small, 384 dimensions). */
24
+ embedder?: MemoryEmbedder;
25
+ /** Options passed to every embedding call, e.g. provider options or headers. */
26
+ embedderOptions?: MastraEmbeddingOptions;
27
+ }): (({ requestContext }: {
28
+ requestContext: RequestContext;
29
+ }) => Memory) & {
30
+ /**
31
+ * Wait for background memory work (buffered observations, reflections, indexing) in every
32
+ * instance this factory created. Await before closing storage.
33
+ */
34
+ settled(): Promise<void>;
35
+ };
36
+ //# sourceMappingURL=memory.d.ts.map