mastracode 0.22.3 → 0.23.0

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 (181) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/HarnessCompat.d.ts +2 -2
  3. package/dist/HarnessCompat.d.ts.map +1 -1
  4. package/dist/agents/mastracode-gateway.d.ts +58 -0
  5. package/dist/agents/mastracode-gateway.d.ts.map +1 -0
  6. package/dist/agents/model.d.ts +26 -28
  7. package/dist/agents/model.d.ts.map +1 -1
  8. package/dist/agents/{subagents/execute.d.ts → modes/build.d.ts} +3 -3
  9. package/dist/agents/modes/build.d.ts.map +1 -0
  10. package/dist/agents/{subagents → modes}/explore.d.ts +2 -2
  11. package/dist/agents/modes/explore.d.ts.map +1 -0
  12. package/dist/agents/modes/plan.d.ts +6 -0
  13. package/dist/agents/modes/plan.d.ts.map +1 -0
  14. package/dist/{chunk-EATS4KOR.cjs → chunk-3CO7PY6M.cjs} +1094 -239
  15. package/dist/chunk-3CO7PY6M.cjs.map +1 -0
  16. package/dist/{chunk-DJEQBK7L.cjs → chunk-CBPEMMRV.cjs} +1659 -2010
  17. package/dist/chunk-CBPEMMRV.cjs.map +1 -0
  18. package/dist/{chunk-W7Y7QIJA.js → chunk-FXYM4OEI.js} +14 -805
  19. package/dist/chunk-FXYM4OEI.js.map +1 -0
  20. package/dist/{chunk-OXYE6SUY.js → chunk-GKGPZBID.js} +836 -1187
  21. package/dist/chunk-GKGPZBID.js.map +1 -0
  22. package/dist/{chunk-FDDVVRPH.js → chunk-RDIIIT54.js} +1076 -221
  23. package/dist/chunk-RDIIIT54.js.map +1 -0
  24. package/dist/{chunk-NKTZDFIU.cjs → chunk-XPPJHUAD.cjs} +12 -809
  25. package/dist/chunk-XPPJHUAD.cjs.map +1 -0
  26. package/dist/cli.cjs +18 -18
  27. package/dist/cli.js +3 -3
  28. package/dist/index.cjs +3 -3
  29. package/dist/index.d.ts +4 -5
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/mcp/manager.d.ts.map +1 -1
  33. package/dist/onboarding/onboarding-inline.d.ts +2 -2
  34. package/dist/onboarding/onboarding-inline.d.ts.map +1 -1
  35. package/dist/onboarding/settings.d.ts.map +1 -1
  36. package/dist/providers/claude-max.d.ts.map +1 -1
  37. package/dist/tui/chat-boundary-reconciliation.d.ts +18 -1
  38. package/dist/tui/chat-boundary-reconciliation.d.ts.map +1 -1
  39. package/dist/tui/command-dispatch.d.ts.map +1 -1
  40. package/dist/tui/commands/browser.d.ts.map +1 -1
  41. package/dist/tui/commands/goal.d.ts.map +1 -1
  42. package/dist/tui/commands/mode.d.ts.map +1 -1
  43. package/dist/tui/commands/new.d.ts.map +1 -1
  44. package/dist/tui/commands/settings.d.ts.map +1 -1
  45. package/dist/tui/commands/skills.d.ts.map +1 -1
  46. package/dist/tui/components/api-key-dialog.d.ts +2 -2
  47. package/dist/tui/components/api-key-dialog.d.ts.map +1 -1
  48. package/dist/tui/components/ask-question-dialog.d.ts +2 -2
  49. package/dist/tui/components/ask-question-dialog.d.ts.map +1 -1
  50. package/dist/tui/components/ask-question-inline.d.ts +4 -2
  51. package/dist/tui/components/ask-question-inline.d.ts.map +1 -1
  52. package/dist/tui/components/assistant-message.d.ts +2 -2
  53. package/dist/tui/components/assistant-message.d.ts.map +1 -1
  54. package/dist/tui/components/chat-boundary-spacer.d.ts +9 -9
  55. package/dist/tui/components/chat-boundary-spacer.d.ts.map +1 -1
  56. package/dist/tui/components/chat-spacing.d.ts +1 -1
  57. package/dist/tui/components/chat-spacing.d.ts.map +1 -1
  58. package/dist/tui/components/collapsible.d.ts +2 -2
  59. package/dist/tui/components/collapsible.d.ts.map +1 -1
  60. package/dist/tui/components/custom-editor.d.ts +2 -2
  61. package/dist/tui/components/custom-editor.d.ts.map +1 -1
  62. package/dist/tui/components/diff-output.d.ts +3 -1
  63. package/dist/tui/components/diff-output.d.ts.map +1 -1
  64. package/dist/tui/components/error-display.d.ts +4 -2
  65. package/dist/tui/components/error-display.d.ts.map +1 -1
  66. package/dist/tui/components/goal-cycles-dialog.d.ts +2 -2
  67. package/dist/tui/components/goal-cycles-dialog.d.ts.map +1 -1
  68. package/dist/tui/components/idle-counter.d.ts +1 -1
  69. package/dist/tui/components/idle-counter.d.ts.map +1 -1
  70. package/dist/tui/components/judge-display.d.ts +14 -2
  71. package/dist/tui/components/judge-display.d.ts.map +1 -1
  72. package/dist/tui/components/login-dialog.d.ts +2 -2
  73. package/dist/tui/components/login-dialog.d.ts.map +1 -1
  74. package/dist/tui/components/login-mode-selector.d.ts +2 -2
  75. package/dist/tui/components/login-mode-selector.d.ts.map +1 -1
  76. package/dist/tui/components/login-selector.d.ts +1 -1
  77. package/dist/tui/components/login-selector.d.ts.map +1 -1
  78. package/dist/tui/components/masked-input.d.ts +1 -1
  79. package/dist/tui/components/masked-input.d.ts.map +1 -1
  80. package/dist/tui/components/mcp-selector.d.ts +2 -2
  81. package/dist/tui/components/mcp-selector.d.ts.map +1 -1
  82. package/dist/tui/components/model-selector.d.ts +2 -2
  83. package/dist/tui/components/model-selector.d.ts.map +1 -1
  84. package/dist/tui/components/multi-step-progress.d.ts +3 -1
  85. package/dist/tui/components/multi-step-progress.d.ts.map +1 -1
  86. package/dist/tui/components/multiline-input.d.ts +1 -1
  87. package/dist/tui/components/multiline-input.d.ts.map +1 -1
  88. package/dist/tui/components/notification-summary.d.ts +1 -1
  89. package/dist/tui/components/notification-summary.d.ts.map +1 -1
  90. package/dist/tui/components/notification.d.ts +1 -1
  91. package/dist/tui/components/notification.d.ts.map +1 -1
  92. package/dist/tui/components/om-marker.d.ts +3 -1
  93. package/dist/tui/components/om-marker.d.ts.map +1 -1
  94. package/dist/tui/components/om-output.d.ts +3 -1
  95. package/dist/tui/components/om-output.d.ts.map +1 -1
  96. package/dist/tui/components/om-progress.d.ts +1 -1
  97. package/dist/tui/components/om-progress.d.ts.map +1 -1
  98. package/dist/tui/components/om-settings.d.ts +2 -2
  99. package/dist/tui/components/om-settings.d.ts.map +1 -1
  100. package/dist/tui/components/plan-approval-inline.d.ts +2 -2
  101. package/dist/tui/components/plan-approval-inline.d.ts.map +1 -1
  102. package/dist/tui/components/reactive-signal.d.ts +1 -1
  103. package/dist/tui/components/reactive-signal.d.ts.map +1 -1
  104. package/dist/tui/components/settings.d.ts +2 -2
  105. package/dist/tui/components/settings.d.ts.map +1 -1
  106. package/dist/tui/components/shell-output.d.ts +3 -1
  107. package/dist/tui/components/shell-output.d.ts.map +1 -1
  108. package/dist/tui/components/simple-progress.d.ts +1 -1
  109. package/dist/tui/components/simple-progress.d.ts.map +1 -1
  110. package/dist/tui/components/slash-command.d.ts +3 -1
  111. package/dist/tui/components/slash-command.d.ts.map +1 -1
  112. package/dist/tui/components/state-signal.d.ts +1 -1
  113. package/dist/tui/components/state-signal.d.ts.map +1 -1
  114. package/dist/tui/components/subagent-execution.d.ts +2 -2
  115. package/dist/tui/components/subagent-execution.d.ts.map +1 -1
  116. package/dist/tui/components/system-reminder.d.ts +1 -1
  117. package/dist/tui/components/system-reminder.d.ts.map +1 -1
  118. package/dist/tui/components/task-progress.d.ts +1 -1
  119. package/dist/tui/components/task-progress.d.ts.map +1 -1
  120. package/dist/tui/components/temporal-gap.d.ts +3 -1
  121. package/dist/tui/components/temporal-gap.d.ts.map +1 -1
  122. package/dist/tui/components/thinking-settings.d.ts +2 -2
  123. package/dist/tui/components/thinking-settings.d.ts.map +1 -1
  124. package/dist/tui/components/thread-selector.d.ts +2 -2
  125. package/dist/tui/components/thread-selector.d.ts.map +1 -1
  126. package/dist/tui/components/tool-approval-dialog.d.ts +2 -2
  127. package/dist/tui/components/tool-approval-dialog.d.ts.map +1 -1
  128. package/dist/tui/components/tool-execution-enhanced.d.ts +2 -2
  129. package/dist/tui/components/tool-execution-enhanced.d.ts.map +1 -1
  130. package/dist/tui/components/tool-validation-error.d.ts +2 -2
  131. package/dist/tui/components/tool-validation-error.d.ts.map +1 -1
  132. package/dist/tui/components/user-message.d.ts +2 -2
  133. package/dist/tui/components/user-message.d.ts.map +1 -1
  134. package/dist/tui/components/wrapping-autocomplete-list.d.ts +1 -1
  135. package/dist/tui/components/wrapping-autocomplete-list.d.ts.map +1 -1
  136. package/dist/tui/components/wrapping-select-list.d.ts +1 -1
  137. package/dist/tui/components/wrapping-select-list.d.ts.map +1 -1
  138. package/dist/tui/display.d.ts.map +1 -1
  139. package/dist/tui/event-dispatch.d.ts.map +1 -1
  140. package/dist/tui/goal-manager.d.ts +48 -40
  141. package/dist/tui/goal-manager.d.ts.map +1 -1
  142. package/dist/tui/handlers/agent-lifecycle.d.ts +13 -0
  143. package/dist/tui/handlers/agent-lifecycle.d.ts.map +1 -1
  144. package/dist/tui/handlers/index.d.ts +1 -1
  145. package/dist/tui/handlers/index.d.ts.map +1 -1
  146. package/dist/tui/handlers/message.d.ts.map +1 -1
  147. package/dist/tui/handlers/om.d.ts.map +1 -1
  148. package/dist/tui/handlers/tool.d.ts.map +1 -1
  149. package/dist/tui/handlers/types.d.ts +1 -1
  150. package/dist/tui/handlers/types.d.ts.map +1 -1
  151. package/dist/tui/mastra-tui.d.ts.map +1 -1
  152. package/dist/tui/modal-question.d.ts +1 -1
  153. package/dist/tui/modal-question.d.ts.map +1 -1
  154. package/dist/tui/overlay.d.ts +1 -1
  155. package/dist/tui/overlay.d.ts.map +1 -1
  156. package/dist/tui/prompt-api-key.d.ts +1 -1
  157. package/dist/tui/prompt-api-key.d.ts.map +1 -1
  158. package/dist/tui/render-messages.d.ts +1 -1
  159. package/dist/tui/render-messages.d.ts.map +1 -1
  160. package/dist/tui/setup.d.ts.map +1 -1
  161. package/dist/tui/shell.d.ts.map +1 -1
  162. package/dist/tui/state.d.ts +2 -2
  163. package/dist/tui/state.d.ts.map +1 -1
  164. package/dist/tui/status-line.d.ts.map +1 -1
  165. package/dist/tui/theme.d.ts +1 -1
  166. package/dist/tui/theme.d.ts.map +1 -1
  167. package/dist/tui.cjs +19 -19
  168. package/dist/tui.js +2 -2
  169. package/package.json +20 -20
  170. package/dist/agents/coding.d.ts +0 -2
  171. package/dist/agents/coding.d.ts.map +0 -1
  172. package/dist/agents/subagents/execute.d.ts.map +0 -1
  173. package/dist/agents/subagents/explore.d.ts.map +0 -1
  174. package/dist/agents/subagents/plan.d.ts +0 -10
  175. package/dist/agents/subagents/plan.d.ts.map +0 -1
  176. package/dist/chunk-DJEQBK7L.cjs.map +0 -1
  177. package/dist/chunk-EATS4KOR.cjs.map +0 -1
  178. package/dist/chunk-FDDVVRPH.js.map +0 -1
  179. package/dist/chunk-NKTZDFIU.cjs.map +0 -1
  180. package/dist/chunk-OXYE6SUY.js.map +0 -1
  181. package/dist/chunk-W7Y7QIJA.js.map +0 -1
@@ -1,14 +1,8 @@
1
- import { AuthStorage, getGitHubCopilotBaseUrl, fetchCopilotModels, getAppDataDir, COPILOT_HEADERS } from './chunk-5FT2NNFO.js';
1
+ import { getAppDataDir } from './chunk-5FT2NNFO.js';
2
2
  import * as fs from 'fs';
3
3
  import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'fs';
4
4
  import * as path from 'path';
5
5
  import { dirname, join } from 'path';
6
- import { createAnthropic } from '@ai-sdk/anthropic';
7
- import { wrapLanguageModel } from 'ai';
8
- import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
9
- import { GoogleSchemaCompatLayer, applyCompatLayer } from '@mastra/schema-compat';
10
- import { createOpenAI } from '@ai-sdk/openai';
11
- import { ModelRouterLanguageModel, MastraGateway, GATEWAY_AUTH_HEADER } from '@mastra/core/llm';
12
6
  import chalk from 'chalk';
13
7
 
14
8
  var MEMORY_GATEWAY_PROVIDER = "mastra-gateway";
@@ -504,6 +498,9 @@ function checkProfileProviderMismatch(profilePath, targetProvider) {
504
498
  }
505
499
  return void 0;
506
500
  }
501
+ function browserRecordingOptions() {
502
+ return { outputDir: join(getAppDataDir(), "browser-recordings") };
503
+ }
507
504
  async function createBrowserFromSettings(settings) {
508
505
  if (!settings.enabled) {
509
506
  return void 0;
@@ -517,807 +514,19 @@ async function createBrowserFromSettings(settings) {
517
514
  env: stagehand?.env ?? "LOCAL",
518
515
  apiKey: stagehand?.apiKey ?? process.env.BROWSERBASE_API_KEY,
519
516
  projectId: stagehand?.projectId ?? process.env.BROWSERBASE_PROJECT_ID,
520
- preserveUserDataDir: stagehand?.preserveUserDataDir
517
+ preserveUserDataDir: stagehand?.preserveUserDataDir,
518
+ recording: browserRecordingOptions()
521
519
  };
522
520
  return cdpUrl ? new StagehandBrowser({ ...launchConfig, cdpUrl, scope: "shared", ...stagehandOpts }) : new StagehandBrowser({ ...launchConfig, ...stagehandOpts });
523
521
  } else if (provider === "agent-browser") {
524
522
  const { AgentBrowser } = await import('@mastra/agent-browser');
525
- return cdpUrl ? new AgentBrowser({ ...launchConfig, cdpUrl, scope: "shared", storageState: agentBrowser?.storageState }) : new AgentBrowser({ ...launchConfig, storageState: agentBrowser?.storageState, scope });
526
- }
527
- throw new Error(`Unsupported browser provider: ${provider}`);
528
- }
529
- var claudeCodeIdentity = "You are Claude Code, Anthropic's official CLI for Claude.";
530
- var authStorageInstance = null;
531
- function getAuthStorage() {
532
- if (!authStorageInstance) {
533
- authStorageInstance = new AuthStorage();
534
- }
535
- return authStorageInstance;
536
- }
537
- function setAuthStorage(storage) {
538
- authStorageInstance = storage ?? null;
539
- }
540
- var claudeCodeMiddleware = {
541
- specificationVersion: "v3",
542
- transformParams: async ({ params }) => {
543
- const systemMessage = {
544
- role: "system",
545
- content: claudeCodeIdentity
546
- };
547
- if (params.temperature) {
548
- delete params.topP;
549
- }
550
- return {
551
- ...params,
552
- prompt: [systemMessage, ...params.prompt]
523
+ const agentBrowserOpts = {
524
+ storageState: agentBrowser?.storageState,
525
+ recording: browserRecordingOptions()
553
526
  };
527
+ return cdpUrl ? new AgentBrowser({ ...launchConfig, cdpUrl, scope: "shared", ...agentBrowserOpts }) : new AgentBrowser({ ...launchConfig, ...agentBrowserOpts, scope });
554
528
  }
555
- };
556
- var promptCacheMiddleware = {
557
- specificationVersion: "v3",
558
- transformParams: async ({ params }) => {
559
- const prompt = [...params.prompt];
560
- const cacheControl = { type: "ephemeral", ttl: "5m" };
561
- const addCacheToMessage = (msg) => {
562
- if (typeof msg.content === "string") {
563
- return {
564
- ...msg,
565
- providerOptions: {
566
- ...msg.providerOptions,
567
- anthropic: { ...msg.providerOptions?.anthropic, cacheControl }
568
- }
569
- };
570
- }
571
- if (Array.isArray(msg.content) && msg.content.length > 0) {
572
- const content = [...msg.content];
573
- const lastPart = content[content.length - 1];
574
- content[content.length - 1] = {
575
- ...lastPart,
576
- providerOptions: {
577
- ...lastPart.providerOptions,
578
- anthropic: { ...lastPart.providerOptions?.anthropic, cacheControl }
579
- }
580
- };
581
- return { ...msg, content };
582
- }
583
- return msg;
584
- };
585
- let lastSystemIdx = -1;
586
- for (let i = prompt.length - 1; i >= 0; i--) {
587
- if (prompt[i].role === "system") {
588
- lastSystemIdx = i;
589
- break;
590
- }
591
- }
592
- if (lastSystemIdx >= 0) {
593
- prompt[lastSystemIdx] = addCacheToMessage(prompt[lastSystemIdx]);
594
- }
595
- const lastIdx = prompt.length - 1;
596
- if (lastIdx >= 0 && lastIdx !== lastSystemIdx) {
597
- prompt[lastIdx] = addCacheToMessage(prompt[lastIdx]);
598
- }
599
- return { ...params, prompt };
600
- }
601
- };
602
- function buildAnthropicOAuthFetch(opts = {}) {
603
- return (async (url, init) => {
604
- const storage = opts.authStorage ?? getAuthStorage();
605
- storage.reload();
606
- const storedCred = storage.get("anthropic");
607
- if (storedCred?.type === "api_key") {
608
- throw new Error("Anthropic API key credential is configured, but OAuth is required.");
609
- }
610
- const accessToken = await storage.getApiKey("anthropic");
611
- if (!accessToken) {
612
- throw new Error("Not logged in to Anthropic. Run /login first.");
613
- }
614
- const headers = new Headers();
615
- if (init?.headers) {
616
- const source = init.headers instanceof Headers ? init.headers : Array.isArray(init.headers) ? new Headers(init.headers) : new Headers(init.headers);
617
- source.forEach((value, key) => {
618
- const lower = key.toLowerCase();
619
- if (lower !== "authorization" && lower !== "x-api-key") {
620
- headers.set(key, value);
621
- }
622
- });
623
- }
624
- headers.set("Authorization", `Bearer ${accessToken}`);
625
- headers.set(
626
- "anthropic-beta",
627
- "oauth-2025-04-20,claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14"
628
- );
629
- headers.set("anthropic-version", "2023-06-01");
630
- try {
631
- return await fetch(url, { ...init, headers });
632
- } catch (error) {
633
- if (error && typeof error === "object") {
634
- Object.assign(error, {
635
- requestUrl: url instanceof URL ? url.toString() : typeof url === "string" ? url : url.url
636
- });
637
- }
638
- throw error;
639
- }
640
- });
641
- }
642
- function opencodeClaudeMaxProvider(modelId = "claude-sonnet-4-20250514", options) {
643
- const headers = options?.headers;
644
- if (process.env.NODE_ENV === "test" || process.env.VITEST) {
645
- const anthropic2 = createAnthropic({
646
- apiKey: "test-api-key",
647
- headers
648
- });
649
- return wrapLanguageModel({
650
- model: anthropic2(modelId),
651
- middleware: [claudeCodeMiddleware, promptCacheMiddleware]
652
- });
653
- }
654
- const anthropic = createAnthropic({
655
- apiKey: "oauth-placeholder",
656
- headers,
657
- fetch: buildAnthropicOAuthFetch()
658
- });
659
- return wrapLanguageModel({
660
- model: anthropic(modelId),
661
- middleware: [claudeCodeMiddleware, promptCacheMiddleware]
662
- });
663
- }
664
- var COPILOT_PROVIDER_ID = "github-copilot";
665
- var authStorageInstance2 = null;
666
- function getAuthStorage2() {
667
- if (!authStorageInstance2) {
668
- authStorageInstance2 = new AuthStorage();
669
- }
670
- return authStorageInstance2;
671
- }
672
- function setAuthStorage2(storage) {
673
- authStorageInstance2 = storage ?? null;
674
- }
675
- function detectIsAgent(body) {
676
- if (!body || typeof body !== "object") return false;
677
- const obj = body;
678
- const messages = obj.messages;
679
- if (Array.isArray(messages) && messages.length > 0) {
680
- const last = messages[messages.length - 1];
681
- if (last?.role && last.role !== "user") return true;
682
- if (Array.isArray(last?.content)) {
683
- const hasToolResult = last.content.some(
684
- (part) => part && typeof part === "object" && part.type === "tool_result"
685
- );
686
- if (hasToolResult) return true;
687
- }
688
- }
689
- const input = obj.input;
690
- if (Array.isArray(input) && input.length > 0) {
691
- const last = input[input.length - 1];
692
- if (last?.role && last.role !== "user") return true;
693
- }
694
- return false;
695
- }
696
- function detectIsVision(body) {
697
- if (!body || typeof body !== "object") return false;
698
- const obj = body;
699
- const matchPart = (part) => {
700
- if (!part || typeof part !== "object") return false;
701
- const t = part.type;
702
- return t === "image" || t === "image_url" || t === "input_image";
703
- };
704
- const messages = obj.messages;
705
- if (Array.isArray(messages)) {
706
- return messages.some(
707
- (msg) => msg && typeof msg === "object" && Array.isArray(msg.content) && msg.content.some(matchPart)
708
- );
709
- }
710
- const input = obj.input;
711
- if (Array.isArray(input)) {
712
- return input.some(
713
- (item) => item && typeof item === "object" && Array.isArray(item.content) && item.content.some(matchPart)
714
- );
715
- }
716
- return false;
717
- }
718
- function buildGitHubCopilotOAuthFetch(opts = {}) {
719
- return (async (url, init) => {
720
- const storage = opts.authStorage ?? getAuthStorage2();
721
- storage.reload();
722
- const cred = storage.get(COPILOT_PROVIDER_ID);
723
- if (!cred || cred.type !== "oauth") {
724
- throw new Error("Not logged in to GitHub Copilot. Run /login first.");
725
- }
726
- const accessToken = await storage.getApiKey(COPILOT_PROVIDER_ID);
727
- if (!accessToken) {
728
- throw new Error("Failed to refresh GitHub Copilot token. Please /login again.");
729
- }
730
- storage.reload();
731
- const enterpriseUrl = cred.enterpriseUrl;
732
- let parsedBody;
733
- if (typeof init?.body === "string") {
734
- try {
735
- parsedBody = JSON.parse(init.body);
736
- } catch {
737
- parsedBody = void 0;
738
- }
739
- }
740
- const isAgent = detectIsAgent(parsedBody);
741
- const isVision = detectIsVision(parsedBody);
742
- const headers = new Headers();
743
- if (init?.headers) {
744
- const source = init.headers instanceof Headers ? init.headers : Array.isArray(init.headers) ? new Headers(init.headers) : new Headers(init.headers);
745
- source.forEach((value, key) => {
746
- const lower = key.toLowerCase();
747
- if (lower !== "authorization" && lower !== "x-api-key") {
748
- headers.set(key, value);
749
- }
750
- });
751
- }
752
- headers.set("Authorization", `Bearer ${accessToken}`);
753
- headers.set("x-initiator", isAgent ? "agent" : "user");
754
- headers.set("Openai-Intent", "conversation-edits");
755
- if (isVision) {
756
- headers.set("Copilot-Vision-Request", "true");
757
- }
758
- for (const [key, value] of Object.entries(COPILOT_HEADERS)) {
759
- if (!headers.has(key)) {
760
- headers.set(key, value);
761
- }
762
- }
763
- const finalUrl = opts.rewriteUrl !== false ? rewriteToCopilotBase(url, accessToken, enterpriseUrl) : url instanceof URL ? url : typeof url === "string" ? new URL(url) : new URL(url.url);
764
- try {
765
- return await fetch(finalUrl, { ...init, headers });
766
- } catch (error) {
767
- if (error && typeof error === "object") {
768
- Object.assign(error, {
769
- requestUrl: finalUrl.toString()
770
- });
771
- }
772
- throw error;
773
- }
774
- });
775
- }
776
- function rewriteToCopilotBase(url, token, enterpriseDomain) {
777
- const original = url instanceof URL ? url : new URL(typeof url === "string" ? url : url.url);
778
- const base = new URL(getGitHubCopilotBaseUrl(token, enterpriseDomain));
779
- const pathname = original.pathname.replace(/^\/v1(\/|$)/, "/");
780
- return new URL(`${pathname}${original.search}`, base);
781
- }
782
- function isGeminiModel(modelId) {
783
- return modelId.startsWith("gemini-");
784
- }
785
- function applyGeminiSchemaCompatToTools(modelId, tools) {
786
- if (!Array.isArray(tools)) {
787
- return tools;
788
- }
789
- const compatLayer = new GoogleSchemaCompatLayer({
790
- provider: COPILOT_PROVIDER_ID,
791
- modelId,
792
- supportsStructuredOutputs: false
793
- });
794
- return tools.map((tool) => {
795
- if (!tool || typeof tool !== "object" || tool.type !== "function") {
796
- return tool;
797
- }
798
- const functionTool = tool;
799
- if (!functionTool.inputSchema) {
800
- return tool;
801
- }
802
- return {
803
- ...functionTool,
804
- inputSchema: applyCompatLayer({
805
- schema: functionTool.inputSchema,
806
- compatLayers: [compatLayer],
807
- mode: "aiSdkSchema"
808
- }).jsonSchema
809
- };
810
- });
811
- }
812
- function createCopilotMiddleware(modelId) {
813
- return {
814
- specificationVersion: "v3",
815
- transformParams: async ({ params }) => {
816
- if (params.temperature !== void 0 && params.temperature !== null) {
817
- delete params.topP;
818
- }
819
- if (isGeminiModel(modelId)) {
820
- params.tools = applyGeminiSchemaCompatToTools(
821
- modelId,
822
- params.tools
823
- );
824
- }
825
- return params;
826
- }
827
- };
828
- }
829
- function githubCopilotProvider(modelId = "gpt-4.1", options) {
830
- const headers = options?.headers;
831
- const copilot = createOpenAICompatible({
832
- name: COPILOT_PROVIDER_ID,
833
- baseURL: "https://api.githubcopilot.com",
834
- apiKey: process.env.NODE_ENV === "test" || process.env.VITEST ? "test-api-key" : "oauth-placeholder",
835
- headers,
836
- fetch: process.env.NODE_ENV === "test" || process.env.VITEST ? void 0 : buildGitHubCopilotOAuthFetch({ rewriteUrl: false })
837
- });
838
- return wrapLanguageModel({
839
- model: copilot.chatModel(modelId),
840
- middleware: [createCopilotMiddleware(modelId)]
841
- });
842
- }
843
- var COPILOT_FALLBACK_MODELS = [
844
- {
845
- id: "gpt-4.1",
846
- name: "GPT-4.1",
847
- vendor: "OpenAI",
848
- supportedEndpoints: ["/chat/completions"],
849
- isAnthropicShaped: false,
850
- supportsVision: true,
851
- supportsToolCalls: true
852
- }
853
- ];
854
- var CATALOG_TTL_MS = 10 * 60 * 1e3;
855
- var CATALOG_FAILURE_TTL_MS = 60 * 1e3;
856
- var CATALOG_FETCH_TIMEOUT_MS = 5e3;
857
- var catalogCache = null;
858
- var inflightFetch = null;
859
- async function getCopilotModelCatalog(opts = {}) {
860
- const storage = opts.authStorage ?? getAuthStorage2();
861
- storage.reload();
862
- const cred = storage.get(COPILOT_PROVIDER_ID);
863
- if (!cred || cred.type !== "oauth") {
864
- return [];
865
- }
866
- const now = Date.now();
867
- if (catalogCache && now - catalogCache.fetchedAt < catalogCache.ttl) {
868
- return catalogCache.models;
869
- }
870
- if (inflightFetch) return inflightFetch;
871
- inflightFetch = (async () => {
872
- try {
873
- const accessToken = await storage.getApiKey(COPILOT_PROVIDER_ID);
874
- if (!accessToken) throw new Error("No Copilot bearer token");
875
- storage.reload();
876
- const refreshed = storage.get(COPILOT_PROVIDER_ID);
877
- const enterpriseUrl = refreshed?.enterpriseUrl;
878
- const baseUrl = getGitHubCopilotBaseUrl(accessToken, enterpriseUrl);
879
- const controller = new AbortController();
880
- const timer = setTimeout(() => controller.abort(), CATALOG_FETCH_TIMEOUT_MS);
881
- try {
882
- const models = await fetchCopilotModels({
883
- baseUrl,
884
- bearerToken: accessToken,
885
- signal: controller.signal
886
- });
887
- catalogCache = { fetchedAt: Date.now(), ttl: CATALOG_TTL_MS, models };
888
- return models;
889
- } finally {
890
- clearTimeout(timer);
891
- }
892
- } catch (error) {
893
- catalogCache = {
894
- fetchedAt: Date.now(),
895
- ttl: CATALOG_FAILURE_TTL_MS,
896
- models: COPILOT_FALLBACK_MODELS
897
- };
898
- console.warn(
899
- "Failed to fetch live GitHub Copilot models, using fallback list:",
900
- error instanceof Error ? error.message : error
901
- );
902
- return COPILOT_FALLBACK_MODELS;
903
- } finally {
904
- inflightFetch = null;
905
- }
906
- })();
907
- return inflightFetch;
908
- }
909
- var CODEX_API_ENDPOINT = "https://chatgpt.com/backend-api/codex/responses";
910
- var CODEX_ORIGINATOR = "mastracode";
911
- var CODEX_USER_AGENT = "mastracode";
912
- var authStorageInstance3 = null;
913
- function getAuthStorage3() {
914
- if (!authStorageInstance3) {
915
- authStorageInstance3 = new AuthStorage();
916
- }
917
- return authStorageInstance3;
918
- }
919
- function setAuthStorage3(storage) {
920
- authStorageInstance3 = storage ?? null;
921
- }
922
- var CODEX_INSTRUCTIONS = `You are an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
923
-
924
- IMPORTANT: You should be concise, direct, and helpful. Focus on solving the user's problem efficiently.`;
925
- var GPT5_MODEL_RE = /^gpt-5(?:\.|-|$)/;
926
- function getEffectiveThinkingLevel(modelId, level) {
927
- if (GPT5_MODEL_RE.test(modelId) && level === "off") {
928
- return "low";
929
- }
930
- return level;
931
- }
932
- var THINKING_LEVEL_TO_REASONING_EFFORT = {
933
- off: void 0,
934
- low: "low",
935
- medium: "medium",
936
- high: "high",
937
- xhigh: "xhigh"
938
- };
939
- function createCodexMiddleware(reasoningEffort) {
940
- return {
941
- specificationVersion: "v3",
942
- transformParams: async ({ params }) => {
943
- if (params.temperature !== void 0 && params.temperature !== null) {
944
- delete params.topP;
945
- }
946
- params.providerOptions = {
947
- ...params.providerOptions,
948
- openai: {
949
- ...params.providerOptions?.openai ?? {},
950
- instructions: CODEX_INSTRUCTIONS,
951
- // Codex API requires store to be false
952
- store: false,
953
- // Enable reasoning for Codex models — without this, the model
954
- // skips the reasoning/action phase and goes straight to final_answer,
955
- // resulting in narration instead of tool calls.
956
- ...reasoningEffort ? { reasoningEffort } : {}
957
- }
958
- };
959
- return params;
960
- }
961
- };
962
- }
963
- function buildOpenAICodexOAuthFetch(opts = {}) {
964
- return (async (url, init) => {
965
- const storage = opts.authStorage ?? getAuthStorage3();
966
- storage.reload();
967
- const cred = storage.get("openai-codex");
968
- if (!cred || cred.type !== "oauth") {
969
- throw new Error("Not logged in to OpenAI Codex. Run /login first.");
970
- }
971
- let accessToken = cred.access;
972
- if (Date.now() >= cred.expires) {
973
- const refreshedToken = await storage.getApiKey("openai-codex");
974
- if (!refreshedToken) {
975
- throw new Error("Failed to refresh OpenAI Codex token. Please /login again.");
976
- }
977
- accessToken = refreshedToken;
978
- storage.reload();
979
- }
980
- const accountId = cred.accountId;
981
- const headers = new Headers();
982
- if (init?.headers) {
983
- if (init.headers instanceof Headers) {
984
- init.headers.forEach((value, key) => {
985
- if (key.toLowerCase() !== "authorization") {
986
- headers.set(key, value);
987
- }
988
- });
989
- } else if (Array.isArray(init.headers)) {
990
- for (const [key, value] of init.headers) {
991
- if (key.toLowerCase() !== "authorization" && value !== void 0) {
992
- headers.set(key, String(value));
993
- }
994
- }
995
- } else {
996
- for (const [key, value] of Object.entries(init.headers)) {
997
- if (key.toLowerCase() !== "authorization" && value !== void 0) {
998
- headers.set(key, String(value));
999
- }
1000
- }
1001
- }
1002
- }
1003
- headers.set("Authorization", `Bearer ${accessToken}`);
1004
- if (!headers.has("originator")) {
1005
- headers.set("originator", CODEX_ORIGINATOR);
1006
- }
1007
- if (!headers.has("User-Agent")) {
1008
- headers.set("User-Agent", CODEX_USER_AGENT);
1009
- }
1010
- if (accountId) {
1011
- headers.set("ChatGPT-Account-ID", accountId);
1012
- }
1013
- const parsed = url instanceof URL ? url : new URL(typeof url === "string" ? url : url.url);
1014
- const shouldRewrite = opts.rewriteUrl !== false && (parsed.pathname.includes("/v1/responses") || parsed.pathname.includes("/chat/completions"));
1015
- const finalUrl = shouldRewrite ? new URL(CODEX_API_ENDPOINT) : parsed;
1016
- try {
1017
- return await fetch(finalUrl, { ...init, headers });
1018
- } catch (error) {
1019
- if (error && typeof error === "object") {
1020
- Object.assign(error, {
1021
- requestUrl: finalUrl.toString()
1022
- });
1023
- }
1024
- throw error;
1025
- }
1026
- });
1027
- }
1028
- function openaiCodexProvider(modelId = "codex-mini-latest", options) {
1029
- const requestedLevel = options?.thinkingLevel ?? "medium";
1030
- const effectiveLevel = getEffectiveThinkingLevel(modelId, requestedLevel);
1031
- const reasoningEffort = THINKING_LEVEL_TO_REASONING_EFFORT[effectiveLevel];
1032
- const middleware = createCodexMiddleware(reasoningEffort);
1033
- const headers = options?.headers;
1034
- const baseURL = process.env.OPENAI_BASE_URL;
1035
- if (process.env.NODE_ENV === "test" || process.env.VITEST) {
1036
- const openai2 = createOpenAI({
1037
- apiKey: "test-api-key",
1038
- baseURL,
1039
- headers
1040
- });
1041
- return wrapLanguageModel({
1042
- model: openai2.responses(modelId),
1043
- middleware: [middleware]
1044
- });
1045
- }
1046
- const openai = createOpenAI({
1047
- apiKey: "oauth-dummy-key",
1048
- baseURL,
1049
- headers,
1050
- fetch: buildOpenAICodexOAuthFetch()
1051
- });
1052
- return wrapLanguageModel({
1053
- model: openai.responses(modelId),
1054
- middleware: [middleware]
1055
- });
1056
- }
1057
- var authStorage = new AuthStorage();
1058
- var OPENAI_PREFIX = "openai/";
1059
- var MASTRA_GATEWAY_PREFIX = "mastra/";
1060
- var MASTRACODE_GATEWAY_ID = "mastracode";
1061
- var CODEX_OPENAI_MODEL_REMAPS = {
1062
- "gpt-5.3": "gpt-5.3-codex",
1063
- "gpt-5.2": "gpt-5.2-codex",
1064
- "gpt-5.1": "gpt-5.1-codex",
1065
- "gpt-5.1-mini": "gpt-5.1-codex-mini",
1066
- "gpt-5": "gpt-5-codex"
1067
- };
1068
- function getHarnessHeaders(requestContext) {
1069
- const harnessContext = requestContext?.get("harness");
1070
- const headers = {
1071
- ...harnessContext?.threadId ? { "x-thread-id": harnessContext.threadId } : {},
1072
- ...harnessContext?.resourceId ? { "x-resource-id": harnessContext.resourceId } : {}
1073
- };
1074
- return Object.keys(headers).length > 0 ? headers : void 0;
1075
- }
1076
- function stripMastraGatewayPrefix(modelId) {
1077
- return modelId.startsWith(MASTRA_GATEWAY_PREFIX) ? modelId.substring(MASTRA_GATEWAY_PREFIX.length) : modelId;
1078
- }
1079
- function normalizeAnthropicModelId(modelId) {
1080
- return modelId.replace(/\.(?=\d)/g, "-");
1081
- }
1082
- function remapOpenAIModelForCodexOAuth(modelId) {
1083
- const normalizedModelId = stripMastraGatewayPrefix(modelId);
1084
- if (!normalizedModelId.startsWith(OPENAI_PREFIX)) {
1085
- return modelId;
1086
- }
1087
- const openaiModelId = normalizedModelId.substring(OPENAI_PREFIX.length);
1088
- if (openaiModelId.includes("-codex")) {
1089
- return modelId;
1090
- }
1091
- const codexModelId = CODEX_OPENAI_MODEL_REMAPS[openaiModelId];
1092
- if (!codexModelId) {
1093
- return modelId;
1094
- }
1095
- const remappedModelId = `${OPENAI_PREFIX}${codexModelId}`;
1096
- return modelId.startsWith(MASTRA_GATEWAY_PREFIX) ? `${MASTRA_GATEWAY_PREFIX}${remappedModelId}` : remappedModelId;
1097
- }
1098
- function getAnthropicApiKey() {
1099
- const storedCred = authStorage.get("anthropic");
1100
- if (storedCred?.type === "api_key" && storedCred.key.trim().length > 0) {
1101
- return storedCred.key.trim();
1102
- }
1103
- const dedicatedKey = authStorage.getStoredApiKey("anthropic")?.trim();
1104
- if (dedicatedKey) return dedicatedKey;
1105
- return process.env.ANTHROPIC_API_KEY?.trim() || void 0;
1106
- }
1107
- function getOpenAIApiKey() {
1108
- const storedCred = authStorage.get("openai-codex");
1109
- if (storedCred?.type === "api_key" && storedCred.key.trim().length > 0) {
1110
- return storedCred.key.trim();
1111
- }
1112
- const dedicatedKey = authStorage.getStoredApiKey("openai-codex")?.trim();
1113
- if (dedicatedKey) return dedicatedKey;
1114
- return process.env.OPENAI_API_KEY?.trim() || void 0;
1115
- }
1116
- function anthropicApiKeyProvider(modelId, apiKey, headers) {
1117
- const anthropic = createAnthropic({ apiKey, headers });
1118
- return wrapLanguageModel({
1119
- model: anthropic(modelId),
1120
- middleware: [promptCacheMiddleware]
1121
- });
1122
- }
1123
- function openaiApiKeyProvider(modelId, apiKey, headers) {
1124
- const openai = createOpenAI({ apiKey, baseURL: process.env.OPENAI_BASE_URL, headers });
1125
- return wrapLanguageModel({
1126
- model: openai.responses(modelId),
1127
- middleware: []
1128
- });
1129
- }
1130
- function getProviderAuthKey(providerId) {
1131
- const authProviderId = providerId === "openai" ? "openai-codex" : providerId;
1132
- const storedCred = authStorage.get(authProviderId);
1133
- if (storedCred?.type === "api_key" && storedCred.key.trim().length > 0) {
1134
- return storedCred.key.trim();
1135
- }
1136
- return authStorage.getStoredApiKey(authProviderId)?.trim() || void 0;
1137
- }
1138
- function resolveAuth(request, memoryGatewayApiKey) {
1139
- const apiKey = getProviderAuthKey(request.providerId);
1140
- return apiKey ? { apiKey, source: "gateway" } : void 0;
1141
- }
1142
- function createMastraCodeGateway({
1143
- mastraGatewayBaseUrl,
1144
- mastraGatewayApiKey,
1145
- routeThroughMastraGateway,
1146
- thinkingLevel,
1147
- customProviders
1148
- }) {
1149
- const mastraGateway = new MastraGateway({ baseUrl: mastraGatewayBaseUrl });
1150
- return {
1151
- id: MASTRACODE_GATEWAY_ID,
1152
- name: "MastraCode Gateway",
1153
- async fetchProviders() {
1154
- return {};
1155
- },
1156
- buildUrl(modelId) {
1157
- return routeThroughMastraGateway ? mastraGateway.buildUrl(modelId) : modelId;
1158
- },
1159
- async getApiKey(modelId) {
1160
- const providerId = stripMastraGatewayPrefix(modelId).split("/", 1)[0];
1161
- if (routeThroughMastraGateway) return mastraGatewayApiKey ?? "";
1162
- return providerId ? getProviderAuthKey(providerId) ?? "" : "";
1163
- },
1164
- resolveAuth(request) {
1165
- if (routeThroughMastraGateway && mastraGatewayApiKey) {
1166
- return { apiKey: mastraGatewayApiKey, source: "gateway" };
1167
- }
1168
- const customProvider = customProviders.find(
1169
- (provider) => request.providerId === getCustomProviderId(provider.name)
1170
- );
1171
- if (customProvider?.apiKey) {
1172
- return { apiKey: customProvider.apiKey, source: "gateway" };
1173
- }
1174
- return resolveAuth(request);
1175
- },
1176
- resolveLanguageModel(args) {
1177
- const customProvider = customProviders.find((provider) => args.providerId === getCustomProviderId(provider.name));
1178
- if (customProvider) {
1179
- const provider = createOpenAICompatible({
1180
- name: args.providerId,
1181
- baseURL: customProvider.url,
1182
- apiKey: args.apiKey,
1183
- headers: args.headers
1184
- });
1185
- return provider.chatModel(args.modelId);
1186
- }
1187
- if (args.providerId === "github-copilot") {
1188
- return githubCopilotProvider(args.modelId, { headers: args.headers });
1189
- }
1190
- if (args.providerId === "moonshotai") {
1191
- if (!process.env.MOONSHOT_AI_API_KEY) {
1192
- throw new Error(`Need MOONSHOT_AI_API_KEY`);
1193
- }
1194
- return createAnthropic({
1195
- apiKey: process.env.MOONSHOT_AI_API_KEY,
1196
- baseURL: "https://api.moonshot.ai/anthropic/v1",
1197
- name: "moonshotai.anthropicv1",
1198
- headers: args.headers
1199
- })(args.modelId);
1200
- }
1201
- if (args.providerId === "anthropic") {
1202
- const bareModelId = normalizeAnthropicModelId(args.modelId);
1203
- const storedCred = authStorage.get("anthropic");
1204
- if (routeThroughMastraGateway) {
1205
- if (storedCred?.type === "oauth") {
1206
- const anthropic = createAnthropic({
1207
- apiKey: "oauth-gateway-placeholder",
1208
- baseURL: `${mastraGatewayBaseUrl}/v1`,
1209
- headers: {
1210
- [GATEWAY_AUTH_HEADER]: `Bearer ${args.apiKey}`,
1211
- ...args.headers
1212
- },
1213
- fetch: buildAnthropicOAuthFetch({ authStorage })
1214
- });
1215
- return wrapLanguageModel({
1216
- model: anthropic(bareModelId),
1217
- middleware: [claudeCodeMiddleware, promptCacheMiddleware]
1218
- });
1219
- }
1220
- return mastraGateway.resolveLanguageModel({ ...args, modelId: bareModelId });
1221
- }
1222
- if (storedCred?.type === "oauth") {
1223
- return opencodeClaudeMaxProvider(bareModelId, { headers: args.headers });
1224
- }
1225
- if (storedCred?.type === "api_key" && storedCred.key.trim().length > 0) {
1226
- return anthropicApiKeyProvider(
1227
- bareModelId,
1228
- storedCred.key.trim(),
1229
- args.headers
1230
- );
1231
- }
1232
- const apiKey = getAnthropicApiKey();
1233
- if (apiKey) {
1234
- return anthropicApiKeyProvider(bareModelId, apiKey, args.headers);
1235
- }
1236
- return opencodeClaudeMaxProvider(bareModelId, { headers: args.headers });
1237
- }
1238
- if (args.providerId === "openai") {
1239
- const storedCred = authStorage.get("openai-codex");
1240
- if (routeThroughMastraGateway) {
1241
- if (storedCred?.type === "oauth") {
1242
- const resolvedModelId = remapOpenAIModelForCodexOAuth(`openai/${args.modelId}`);
1243
- const resolvedBareModelId = resolvedModelId.substring(OPENAI_PREFIX.length);
1244
- const requestedLevel = thinkingLevel ?? "medium";
1245
- const effectiveLevel = getEffectiveThinkingLevel(resolvedBareModelId, requestedLevel);
1246
- const reasoningEffort = THINKING_LEVEL_TO_REASONING_EFFORT[effectiveLevel];
1247
- const middleware = createCodexMiddleware(reasoningEffort);
1248
- const openai = createOpenAI({
1249
- apiKey: "oauth-gateway-placeholder",
1250
- baseURL: `${mastraGatewayBaseUrl}/v1`,
1251
- headers: {
1252
- [GATEWAY_AUTH_HEADER]: `Bearer ${args.apiKey}`,
1253
- ...args.headers
1254
- },
1255
- fetch: buildOpenAICodexOAuthFetch({ authStorage, rewriteUrl: false })
1256
- });
1257
- return wrapLanguageModel({
1258
- model: openai.responses(resolvedBareModelId),
1259
- middleware: [middleware]
1260
- });
1261
- }
1262
- return mastraGateway.resolveLanguageModel(args);
1263
- }
1264
- if (storedCred?.type === "oauth") {
1265
- const resolvedModelId = remapOpenAIModelForCodexOAuth(`openai/${args.modelId}`);
1266
- return openaiCodexProvider(resolvedModelId.substring(OPENAI_PREFIX.length), {
1267
- thinkingLevel,
1268
- headers: args.headers
1269
- });
1270
- }
1271
- const apiKey = getOpenAIApiKey();
1272
- if (apiKey) {
1273
- return openaiApiKeyProvider(args.modelId, apiKey, args.headers);
1274
- }
1275
- }
1276
- if (routeThroughMastraGateway) {
1277
- return mastraGateway.resolveLanguageModel(args);
1278
- }
1279
- return new ModelRouterLanguageModel({
1280
- id: `${args.providerId}/${args.modelId}`,
1281
- headers: args.headers
1282
- });
1283
- },
1284
- serializeForSpan() {
1285
- return { id: MASTRACODE_GATEWAY_ID, name: "MastraCode Gateway" };
1286
- }
1287
- };
1288
- }
1289
- function resolveModelId(modelId) {
1290
- return modelId;
1291
- }
1292
- function resolveModel(modelId, options) {
1293
- authStorage.reload();
1294
- const headers = getHarnessHeaders(options?.requestContext);
1295
- const settings = loadSettings();
1296
- const resolvedRouterModelId = resolveModelId(modelId);
1297
- const isMastraGatewayModel = resolvedRouterModelId.startsWith(MASTRA_GATEWAY_PREFIX);
1298
- const normalizedModelId = stripMastraGatewayPrefix(resolvedRouterModelId);
1299
- const mgApiKey = authStorage.getStoredApiKey(MEMORY_GATEWAY_PROVIDER) ?? process.env["MASTRA_GATEWAY_API_KEY"];
1300
- const rawGatewayBase = settings.memoryGateway?.baseUrl ?? process.env["MASTRA_GATEWAY_URL"] ?? "https://gateway-api.mastra.ai";
1301
- const gateway = createMastraCodeGateway({
1302
- mastraGatewayBaseUrl: rawGatewayBase.replace(/\/+$/, "").replace(/\/v1$/, ""),
1303
- mastraGatewayApiKey: mgApiKey,
1304
- routeThroughMastraGateway: Boolean(mgApiKey && isMastraGatewayModel),
1305
- thinkingLevel: options?.thinkingLevel,
1306
- customProviders: settings.customProviders
1307
- });
1308
- return new ModelRouterLanguageModel(
1309
- { id: `${MASTRACODE_GATEWAY_ID}/${normalizedModelId}`, headers },
1310
- [gateway]
1311
- );
1312
- }
1313
- function getDynamicModel({ requestContext }) {
1314
- const harnessContext = requestContext.get("harness");
1315
- const modelId = harnessContext?.state?.currentModelId;
1316
- if (!modelId) {
1317
- throw new Error("No model selected. Use /models to select a model first.");
1318
- }
1319
- const thinkingLevel = harnessContext?.state?.thinkingLevel;
1320
- return resolveModel(modelId, { thinkingLevel, requestContext });
529
+ throw new Error(`Unsupported browser provider: ${provider}`);
1321
530
  }
1322
531
 
1323
532
  // src/onboarding/packs.ts
@@ -1961,6 +1170,6 @@ function releaseAllThreadLocks() {
1961
1170
  }
1962
1171
  }
1963
1172
 
1964
- export { BOX_INDENT, BOX_INDENT_STR, CHAT_INDENT, MEMORY_GATEWAY_DEFAULT_URL, MEMORY_GATEWAY_PROVIDER, OBSERVABILITY_AUTH_PREFIX, ONBOARDING_VERSION, TERM_WIDTH_BUFFER, THREAD_ACTIVE_MODEL_PACK_ID_KEY, ThreadLockError, acquireThreadLock, applyThemeMode, checkProfileProviderMismatch, createBrowserFromSettings, ensureTerminalGlyphContrast, extendedColors, getAvailableModePacks, getAvailableOmPacks, getCopilotModelCatalog, getCustomProviderId, getDynamicModel, getEditorTheme, getMarkdownTheme, getSelectListTheme, getSettingsListTheme, getTermWidth, getThemeMode, loadSettings, luminance, mastra, mastraBrand, releaseAllThreadLocks, releaseThreadLock, resolveModel, resolveModelDefaults, resolveOmRoleModel, resolveThreadActiveModelPackId, restoreTerminalForeground, saveSettings, setAuthStorage, setAuthStorage2, setAuthStorage3, setProfileProvider, theme, tintHex, toCustomProviderModelId };
1965
- //# sourceMappingURL=chunk-W7Y7QIJA.js.map
1966
- //# sourceMappingURL=chunk-W7Y7QIJA.js.map
1173
+ export { BOX_INDENT, BOX_INDENT_STR, CHAT_INDENT, MEMORY_GATEWAY_DEFAULT_URL, MEMORY_GATEWAY_PROVIDER, OBSERVABILITY_AUTH_PREFIX, ONBOARDING_VERSION, TERM_WIDTH_BUFFER, THREAD_ACTIVE_MODEL_PACK_ID_KEY, ThreadLockError, acquireThreadLock, applyThemeMode, checkProfileProviderMismatch, createBrowserFromSettings, ensureTerminalGlyphContrast, extendedColors, getAvailableModePacks, getAvailableOmPacks, getCustomProviderId, getEditorTheme, getMarkdownTheme, getSelectListTheme, getSettingsListTheme, getTermWidth, getThemeMode, loadSettings, luminance, mastra, mastraBrand, releaseAllThreadLocks, releaseThreadLock, resolveModelDefaults, resolveOmRoleModel, resolveThreadActiveModelPackId, restoreTerminalForeground, saveSettings, setProfileProvider, theme, tintHex, toCustomProviderModelId };
1174
+ //# sourceMappingURL=chunk-FXYM4OEI.js.map
1175
+ //# sourceMappingURL=chunk-FXYM4OEI.js.map