@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,232 @@
1
+ import { ProviderAuthRequiredError, rejectUnauthorizedResponse } from "../auth/provider-auth-error.js";
2
+ import { AuthStorage } from "../auth/storage.js";
3
+ import { runCatalogThinkingLevel } from "../thinking-catalog.js";
4
+ import "./anthropic-prompt-cache.js";
5
+ import { ANTHROPIC_THINKING_BUDGET_TOKENS, getAnthropicThinkingCapability } from "./anthropic-thinking.js";
6
+ import { wrapLanguageModel } from "ai";
7
+ import { createAnthropic } from "@ai-sdk/anthropic";
8
+ // src/providers/claude-max.ts
9
+ /**
10
+ * Claude Max OAuth Provider
11
+ *
12
+ * Uses OAuth tokens from AuthStorage to authenticate with Claude Max plan.
13
+ * The OAuth endpoint requires a specific system message to be present.
14
+ */
15
+ const PROVIDER_NAME = "Anthropic";
16
+ const claudeCodeIdentity = "You are Claude Code, Anthropic's official CLI for Claude.";
17
+ const OAUTH_REQUIRED_BETAS = [
18
+ "oauth-2025-04-20",
19
+ "claude-code-20250219",
20
+ "interleaved-thinking-2025-05-14",
21
+ "fine-grained-tool-streaming-2025-05-14"
22
+ ];
23
+ let authStorageInstance = null;
24
+ /**
25
+ * Get or create the shared AuthStorage instance
26
+ */
27
+ function getAuthStorage() {
28
+ if (!authStorageInstance) authStorageInstance = new AuthStorage();
29
+ return authStorageInstance;
30
+ }
31
+ /**
32
+ * Set a custom AuthStorage instance (useful for TUI integration)
33
+ */
34
+ function setAuthStorage(storage) {
35
+ authStorageInstance = storage ?? null;
36
+ }
37
+ /**
38
+ * Middleware that injects the Claude Code identity system message
39
+ * Required for Claude Max OAuth authentication
40
+ */
41
+ const claudeCodeMiddleware = {
42
+ specificationVersion: "v4",
43
+ transformParams: async ({ params }) => {
44
+ const systemMessage = {
45
+ role: "system",
46
+ content: claudeCodeIdentity
47
+ };
48
+ if (params.temperature) delete params.topP;
49
+ return {
50
+ ...params,
51
+ prompt: [systemMessage, ...params.prompt]
52
+ };
53
+ }
54
+ };
55
+ /**
56
+ * Prompt caching middleware for Anthropic
57
+ *
58
+ * Adds cache breakpoints at strategic locations:
59
+ * 1. Last system message (end of static instructions + dynamic memory)
60
+ * 2. Most recent user/assistant message (conversation context), `conversation` scope only
61
+ *
62
+ * This allows Anthropic to cache:
63
+ * - System prompts and instructions (rarely change)
64
+ * - Conversation history up to the last message
65
+ */
66
+ const createPromptCacheMiddleware = (scope) => ({
67
+ specificationVersion: "v4",
68
+ transformParams: async ({ params }) => {
69
+ const prompt = [...params.prompt];
70
+ const cacheControl = {
71
+ type: "ephemeral",
72
+ ttl: scope === "conversation" ? "1h" : "5m"
73
+ };
74
+ const addCacheToMessage = (msg) => {
75
+ if (typeof msg.content === "string") return {
76
+ ...msg,
77
+ providerOptions: {
78
+ ...msg.providerOptions,
79
+ anthropic: {
80
+ ...msg.providerOptions?.anthropic,
81
+ cacheControl
82
+ }
83
+ }
84
+ };
85
+ if (Array.isArray(msg.content) && msg.content.length > 0) {
86
+ const content = [...msg.content];
87
+ const lastPart = content[content.length - 1];
88
+ content[content.length - 1] = {
89
+ ...lastPart,
90
+ providerOptions: {
91
+ ...lastPart.providerOptions,
92
+ anthropic: {
93
+ ...lastPart.providerOptions?.anthropic,
94
+ cacheControl
95
+ }
96
+ }
97
+ };
98
+ return {
99
+ ...msg,
100
+ content
101
+ };
102
+ }
103
+ return msg;
104
+ };
105
+ let lastSystemIdx = -1;
106
+ for (let i = prompt.length - 1; i >= 0; i--) if (prompt[i].role === "system") {
107
+ lastSystemIdx = i;
108
+ break;
109
+ }
110
+ if (lastSystemIdx >= 0) prompt[lastSystemIdx] = addCacheToMessage(prompt[lastSystemIdx]);
111
+ const lastIdx = prompt.length - 1;
112
+ if (scope === "conversation" && lastIdx >= 0 && lastIdx !== lastSystemIdx) prompt[lastIdx] = addCacheToMessage(prompt[lastIdx]);
113
+ return {
114
+ ...params,
115
+ prompt
116
+ };
117
+ }
118
+ });
119
+ function runAnthropicRequestLevel(modelId, level) {
120
+ return runCatalogThinkingLevel(`anthropic/${modelId}`, level);
121
+ }
122
+ /**
123
+ * Middleware that maps the session thinking level onto Anthropic extended
124
+ * thinking. Returns `undefined` (no middleware) when the level is `off` or the
125
+ * model doesn't support thinking, preserving the previous request shape.
126
+ *
127
+ * - Adaptive-era models (Sonnet 4.6+/Opus 4.6+): `thinking: adaptive` plus
128
+ * `output_config.effort`, the closest effort the model accepts.
129
+ * - Budget-era models (Claude 3.7 – Opus 4.5): `thinking: enabled` with a
130
+ * `budget_tokens` value derived from the level.
131
+ */
132
+ function createAnthropicThinkingMiddleware(modelId, thinkingLevel) {
133
+ if (!thinkingLevel || thinkingLevel === "off") return void 0;
134
+ const capability = getAnthropicThinkingCapability(modelId);
135
+ const level = runAnthropicRequestLevel(modelId, thinkingLevel);
136
+ if (level === "off") return void 0;
137
+ return {
138
+ specificationVersion: "v4",
139
+ transformParams: async ({ params }) => {
140
+ const anthropicOptions = params.providerOptions?.anthropic ?? {};
141
+ if (anthropicOptions.thinking !== void 0 || anthropicOptions.effort !== void 0) return params;
142
+ delete params.temperature;
143
+ delete params.topP;
144
+ delete params.topK;
145
+ params.providerOptions = {
146
+ ...params.providerOptions,
147
+ anthropic: {
148
+ ...anthropicOptions,
149
+ ...capability === "adaptive" ? {
150
+ thinking: {
151
+ type: "adaptive",
152
+ display: "summarized"
153
+ },
154
+ effort: level
155
+ } : { thinking: {
156
+ type: "enabled",
157
+ budgetTokens: ANTHROPIC_THINKING_BUDGET_TOKENS[level]
158
+ } }
159
+ }
160
+ };
161
+ return params;
162
+ }
163
+ };
164
+ }
165
+ /**
166
+ * Build a fetch function that handles Anthropic OAuth.
167
+ * Preserves non-auth headers from init (critical for gateway auth header to survive
168
+ * when used with the gateway). Strips `authorization` and `x-api-key`.
169
+ */
170
+ function buildAnthropicOAuthFetch(opts = {}) {
171
+ return (async (url, init) => {
172
+ const storage = opts.authStorage ?? getAuthStorage();
173
+ storage.reload();
174
+ if (storage.get("anthropic")?.type === "api_key") throw new Error("Anthropic API key credential is configured, but OAuth is required.");
175
+ const accessToken = await storage.getApiKey("anthropic");
176
+ if (!accessToken) throw storage.get("anthropic")?.type === "oauth" ? ProviderAuthRequiredError.signInExpired(PROVIDER_NAME) : ProviderAuthRequiredError.notSignedIn(PROVIDER_NAME);
177
+ const headers = new Headers(url instanceof Request ? url.headers : void 0);
178
+ if (init?.headers) new Headers(init.headers).forEach((value, key) => headers.set(key, value));
179
+ headers.delete("authorization");
180
+ headers.delete("x-api-key");
181
+ headers.set("Authorization", `Bearer ${accessToken}`);
182
+ const requestBetas = (headers.get("anthropic-beta") ?? "").split(",").map((beta) => beta.trim()).filter(Boolean);
183
+ headers.set("anthropic-beta", Array.from(/* @__PURE__ */ new Set([...OAUTH_REQUIRED_BETAS, ...requestBetas])).join(","));
184
+ headers.set("anthropic-version", "2023-06-01");
185
+ const requestUrl = url instanceof URL ? url.toString() : typeof url === "string" ? url : url.url;
186
+ try {
187
+ return await rejectUnauthorizedResponse(await fetch(url, {
188
+ ...init,
189
+ headers
190
+ }), {
191
+ providerName: PROVIDER_NAME,
192
+ requestUrl
193
+ });
194
+ } catch (error) {
195
+ if (error && typeof error === "object") Object.assign(error, { requestUrl });
196
+ throw error;
197
+ }
198
+ });
199
+ }
200
+ /**
201
+ * Creates an Anthropic model using Claude Max OAuth authentication
202
+ * Uses OAuth tokens from AuthStorage (auto-refreshes when needed)
203
+ */
204
+ function opencodeClaudeMaxProvider(modelId = "claude-sonnet-5-5", options) {
205
+ const headers = options?.headers;
206
+ const thinkingMiddleware = createAnthropicThinkingMiddleware(modelId, options?.thinkingLevel);
207
+ const middleware = [
208
+ claudeCodeMiddleware,
209
+ createPromptCacheMiddleware(options?.promptCacheScope ?? "conversation"),
210
+ ...thinkingMiddleware ? [thinkingMiddleware] : []
211
+ ];
212
+ if (process.env.NODE_ENV === "test" || process.env.VITEST) {
213
+ const anthropic = createAnthropic({
214
+ apiKey: "test-api-key",
215
+ headers
216
+ });
217
+ return wrapLanguageModel({
218
+ model: anthropic(modelId),
219
+ middleware
220
+ });
221
+ }
222
+ const anthropic = createAnthropic({
223
+ apiKey: "oauth-placeholder",
224
+ headers,
225
+ fetch: buildAnthropicOAuthFetch({ authStorage: options?.authStorage })
226
+ });
227
+ return wrapLanguageModel({
228
+ model: anthropic(modelId),
229
+ middleware
230
+ });
231
+ }
232
+ export { buildAnthropicOAuthFetch, claudeCodeMiddleware, createAnthropicThinkingMiddleware, createPromptCacheMiddleware, getAuthStorage, opencodeClaudeMaxProvider, setAuthStorage };
@@ -0,0 +1,35 @@
1
+ import { MastraModelGateway } from '@mastra/core/llm';
2
+ import type { GatewayAuthRequest, GatewayAuthResult, GatewayLanguageModel, ProviderConfig } from '@mastra/core/llm';
3
+ import type { CredentialStore } from '../auth/types.js';
4
+ export declare const GITHUB_COPILOT_GATEWAY_ID = "github-copilot";
5
+ /**
6
+ * Standalone GitHub Copilot gateway.
7
+ *
8
+ * models.dev excludes Copilot from the shared registry, so Mastra Code supplies
9
+ * the provider itself. It is its own gateway so catalog ids are the canonical
10
+ * `github-copilot/<model>` rather than `mastracode/github-copilot/<model>`.
11
+ */
12
+ export declare class GitHubCopilotGateway extends MastraModelGateway {
13
+ #private;
14
+ readonly id = "github-copilot";
15
+ readonly name = "GitHub Copilot";
16
+ constructor(options?: {
17
+ credentialStore?: CredentialStore;
18
+ });
19
+ fetchProviders(): Promise<Record<string, ProviderConfig>>;
20
+ buildUrl(_modelId: string): string | undefined;
21
+ getApiKey(_modelId: string): Promise<string>;
22
+ resolveAuth(_request: GatewayAuthRequest): GatewayAuthResult | undefined;
23
+ resolveLanguageModel(args: {
24
+ modelId: string;
25
+ providerId: string;
26
+ apiKey: string;
27
+ headers?: Record<string, string>;
28
+ transport?: any;
29
+ responsesWebSocket?: any;
30
+ }): GatewayLanguageModel;
31
+ }
32
+ export declare function createGitHubCopilotGateway(options?: {
33
+ credentialStore?: CredentialStore;
34
+ }): GitHubCopilotGateway;
35
+ //# sourceMappingURL=github-copilot-gateway.d.ts.map
@@ -0,0 +1,58 @@
1
+ import { getAuthStorage, getCopilotModelCatalog, githubCopilotProvider } from "./github-copilot.js";
2
+ import { MastraModelGateway } from "@mastra/core/llm";
3
+ // src/providers/github-copilot-gateway.ts
4
+ const GITHUB_COPILOT_GATEWAY_ID = "github-copilot";
5
+ /**
6
+ * Standalone GitHub Copilot gateway.
7
+ *
8
+ * models.dev excludes Copilot from the shared registry, so Mastra Code supplies
9
+ * the provider itself. It is its own gateway so catalog ids are the canonical
10
+ * `github-copilot/<model>` rather than `mastracode/github-copilot/<model>`.
11
+ */
12
+ var GitHubCopilotGateway = class extends MastraModelGateway {
13
+ id = GITHUB_COPILOT_GATEWAY_ID;
14
+ name = "GitHub Copilot";
15
+ #credentials;
16
+ constructor(options = {}) {
17
+ super();
18
+ this.#credentials = options.credentialStore;
19
+ }
20
+ get #store() {
21
+ return this.#credentials ?? getAuthStorage();
22
+ }
23
+ async fetchProviders() {
24
+ try {
25
+ const models = await getCopilotModelCatalog({ authStorage: this.#store });
26
+ return { [GITHUB_COPILOT_GATEWAY_ID]: {
27
+ name: "GitHub Copilot",
28
+ apiKeyEnvVar: "",
29
+ apiKeyHeader: "Authorization",
30
+ gateway: this.id,
31
+ models: models.map((model) => model.id)
32
+ } };
33
+ } catch (error) {
34
+ console.warn("Failed to load GitHub Copilot model catalog:", error);
35
+ return {};
36
+ }
37
+ }
38
+ buildUrl(_modelId) {}
39
+ async getApiKey(_modelId) {
40
+ return "";
41
+ }
42
+ resolveAuth(_request) {
43
+ return this.#store.get("github-copilot")?.type === "oauth" ? {
44
+ bearerToken: "oauth",
45
+ source: "gateway"
46
+ } : void 0;
47
+ }
48
+ resolveLanguageModel(args) {
49
+ return githubCopilotProvider(args.modelId, {
50
+ headers: args.headers,
51
+ authStorage: this.#store
52
+ });
53
+ }
54
+ };
55
+ function createGitHubCopilotGateway(options) {
56
+ return new GitHubCopilotGateway(options);
57
+ }
58
+ export { GITHUB_COPILOT_GATEWAY_ID, GitHubCopilotGateway, createGitHubCopilotGateway };
@@ -0,0 +1,60 @@
1
+ /**
2
+ * GitHub Copilot OAuth Provider
3
+ *
4
+ * Uses OAuth tokens from AuthStorage to authenticate with GitHub Copilot's chat API.
5
+ * The Copilot API speaks an OpenAI-compatible chat format, so we plug
6
+ * `@ai-sdk/openai-compatible` into Copilot's API URL and use a custom fetch to inject
7
+ * the bearer token and Copilot-specific headers.
8
+ *
9
+ * Inspired by:
10
+ * - opencode: https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/plugin/github-copilot/copilot.ts
11
+ * - pi-mono: https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/utils/oauth/github-copilot.ts
12
+ */
13
+ import type { MastraModelConfig } from '@mastra/core/llm';
14
+ import type { CopilotModelEntry } from '../auth/providers/github-copilot.js';
15
+ import { AuthStorage } from '../auth/storage.js';
16
+ import type { CredentialStore } from '../auth/types.js';
17
+ /** Get or create the shared AuthStorage instance. */
18
+ export declare function getAuthStorage(): AuthStorage;
19
+ /** Set a custom AuthStorage instance (useful for tests / TUI integration). */
20
+ export declare function setAuthStorage(storage: AuthStorage | undefined): void;
21
+ /**
22
+ * Build a fetch wrapper that authenticates with GitHub Copilot OAuth.
23
+ *
24
+ * - Injects the short-lived Copilot bearer token (auto-refreshed by AuthStorage).
25
+ * - Adds the VS Code-like Copilot headers required by the API.
26
+ * - Rewrites the request URL onto the per-token API base when `rewriteUrl` is true.
27
+ */
28
+ export declare function buildGitHubCopilotOAuthFetch(opts?: {
29
+ authStorage?: CredentialStore;
30
+ rewriteUrl?: boolean;
31
+ }): typeof fetch;
32
+ /**
33
+ * Creates a model that talks to GitHub Copilot using OAuth credentials.
34
+ *
35
+ * Copilot's `/chat/completions` endpoint is OpenAI-compatible, but GitHub Copilot
36
+ * is not OpenAI. Use the generic OpenAI-compatible adapter with Copilot's base URL
37
+ * instead of the OpenAI provider plus URL rewriting.
38
+ */
39
+ export declare function githubCopilotProvider(modelId?: string, options?: {
40
+ headers?: Record<string, string>;
41
+ authStorage?: CredentialStore;
42
+ }): MastraModelConfig;
43
+ /** Reset the in-process Copilot catalog cache (test seam, also useful after logout). */
44
+ export declare function clearCopilotCatalogCache(): void;
45
+ /**
46
+ * Return the user's currently-available Copilot models.
47
+ *
48
+ * - Returns `[]` when the user is not logged in to GitHub Copilot.
49
+ * - Returns the cached list when a recent fetch succeeded.
50
+ * - On the cache-miss / expired path, fetches `/models` with a 5s timeout, filters
51
+ * to picker-enabled and non-policy-disabled models, then caches for 10 minutes.
52
+ * - On fetch failure, returns a small hard-coded fallback (so packs still work
53
+ * offline) and caches that for 1 minute to avoid hammering the API.
54
+ *
55
+ * Concurrent calls during a fetch share the inflight promise.
56
+ */
57
+ export declare function getCopilotModelCatalog(opts?: {
58
+ authStorage?: CredentialStore;
59
+ }): Promise<CopilotModelEntry[]>;
60
+ //# sourceMappingURL=github-copilot.d.ts.map