@mastra/code-sdk 1.15.1-alpha.4 → 1.15.1-alpha.5

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 (205) hide show
  1. package/dist/acp/agent.js +1 -2
  2. package/dist/acp/errors.js +1 -2
  3. package/dist/acp/event-mapper.js +1 -2
  4. package/dist/acp/index.js +1 -2
  5. package/dist/acp/runtime.js +1 -2
  6. package/dist/acp/server.js +1 -2
  7. package/dist/acp/skills.js +1 -2
  8. package/dist/agent-connections/messaging-processor.js +1 -2
  9. package/dist/agent-connections/ownership.js +1 -2
  10. package/dist/agent-connections/registry.js +1 -2
  11. package/dist/agent-connections/session-advertisement.js +1 -2
  12. package/dist/agent-connections/signal-provider.js +1 -2
  13. package/dist/agent-connections/state-processor.js +1 -2
  14. package/dist/agent-connections/thread-state.js +1 -2
  15. package/dist/agent-connections/tools.js +1 -2
  16. package/dist/agent-connections/types.js +1 -2
  17. package/dist/agent-connections/untrusted-text.js +1 -2
  18. package/dist/agents/background-completion-events.js +1 -2
  19. package/dist/agents/background-completion.js +1 -2
  20. package/dist/agents/context-audit.js +1 -2
  21. package/dist/agents/credential-resolver.js +1 -2
  22. package/dist/agents/custom-provider-source.js +1 -2
  23. package/dist/agents/instructions.js +1 -2
  24. package/dist/agents/mastracode-gateway.js +1 -2
  25. package/dist/agents/memory.js +1 -2
  26. package/dist/agents/model.js +1 -2
  27. package/dist/agents/modes/build.js +1 -2
  28. package/dist/agents/modes/explore.js +1 -2
  29. package/dist/agents/modes/plan.js +1 -2
  30. package/dist/agents/prompts/agent-instructions.js +1 -2
  31. package/dist/agents/prompts/build.js +1 -2
  32. package/dist/agents/prompts/fast.js +1 -2
  33. package/dist/agents/prompts/index.js +1 -2
  34. package/dist/agents/prompts/model.js +1 -2
  35. package/dist/agents/prompts/plan.js +1 -2
  36. package/dist/agents/prompts/tool-guidance.js +1 -2
  37. package/dist/agents/sandbox-filesystem.d.ts.map +1 -1
  38. package/dist/agents/sandbox-filesystem.js +9 -7
  39. package/dist/agents/sandbox-filesystem.js.map +1 -1
  40. package/dist/agents/subagents/execute.js +1 -2
  41. package/dist/agents/subagents/explore.js +1 -2
  42. package/dist/agents/subagents/plan.js +1 -2
  43. package/dist/agents/thread-caveman-state.js +1 -2
  44. package/dist/agents/tool-availability.js +1 -2
  45. package/dist/agents/tools.js +1 -2
  46. package/dist/agents/workflow-builder-agent.js +1 -2
  47. package/dist/agents/workspace.js +1 -2
  48. package/dist/analytics.js +1 -2
  49. package/dist/auth/account-rotation-processor.js +1 -2
  50. package/dist/auth/account-routing-context.js +1 -2
  51. package/dist/auth/authorization-input.js +1 -2
  52. package/dist/auth/device-code.js +1 -2
  53. package/dist/auth/pkce.js +1 -2
  54. package/dist/auth/provider-auth-error.d.ts +2 -0
  55. package/dist/auth/provider-auth-error.d.ts.map +1 -1
  56. package/dist/auth/provider-auth-error.js +8 -3
  57. package/dist/auth/provider-auth-error.js.map +1 -1
  58. package/dist/auth/providers/anthropic.js +1 -2
  59. package/dist/auth/providers/github-copilot.js +1 -2
  60. package/dist/auth/providers/kimi-coding.js +1 -2
  61. package/dist/auth/providers/openai-codex.js +1 -2
  62. package/dist/auth/providers/xai.js +1 -2
  63. package/dist/auth/storage.js +1 -2
  64. package/dist/clipboard/index.js +1 -2
  65. package/dist/constants.js +1 -2
  66. package/dist/error-classification.js +1 -2
  67. package/dist/evals/context-builder.js +1 -2
  68. package/dist/evals/scorers/classify-command.d.ts +1 -2
  69. package/dist/evals/scorers/classify-command.d.ts.map +1 -1
  70. package/dist/evals/scorers/classify-command.js +7 -17
  71. package/dist/evals/scorers/classify-command.js.map +1 -1
  72. package/dist/evals/scorers/efficiency.js +1 -2
  73. package/dist/evals/scorers/extract-tools.js +1 -2
  74. package/dist/evals/scorers/outcome.d.ts.map +1 -1
  75. package/dist/evals/scorers/outcome.js +36 -22
  76. package/dist/evals/scorers/outcome.js.map +1 -1
  77. package/dist/experimental-agent.js +1 -2
  78. package/dist/factory/client.js +1 -2
  79. package/dist/factory/remote-controller.js +1 -2
  80. package/dist/factory/remote-session.js +1 -2
  81. package/dist/goal-manager.js +1 -2
  82. package/dist/goal-signal.js +1 -2
  83. package/dist/headless/cli.js +1 -2
  84. package/dist/headless/flags.js +1 -2
  85. package/dist/headless/format.js +1 -2
  86. package/dist/headless/policy.js +1 -2
  87. package/dist/headless/run-mc.js +1 -2
  88. package/dist/headless/types.js +1 -2
  89. package/dist/hooks/config.js +1 -2
  90. package/dist/hooks/executor.js +1 -2
  91. package/dist/hooks/manager.js +1 -2
  92. package/dist/hooks/types.js +1 -2
  93. package/dist/index.js +1 -2
  94. package/dist/ipc/ipc-reporter.js +1 -2
  95. package/dist/knowledge-inspector.js +1 -2
  96. package/dist/knowledge-scope.js +1 -2
  97. package/dist/lsp/client.d.ts.map +1 -1
  98. package/dist/lsp/client.js +1 -2
  99. package/dist/lsp/client.js.map +1 -1
  100. package/dist/lsp/language.js +1 -2
  101. package/dist/lsp/manager.js +1 -2
  102. package/dist/lsp/server.js +1 -2
  103. package/dist/lsp/workspace.js +1 -2
  104. package/dist/mcp/config.js +1 -2
  105. package/dist/mcp/manager.js +1 -2
  106. package/dist/mcp/state.js +1 -2
  107. package/dist/onboarding/custom-packs.js +1 -2
  108. package/dist/onboarding/custom-providers.js +1 -2
  109. package/dist/onboarding/om-settings.js +1 -2
  110. package/dist/onboarding/pack-activation.js +1 -2
  111. package/dist/onboarding/packs.js +1 -2
  112. package/dist/onboarding/settings.js +1 -2
  113. package/dist/permissions.js +1 -2
  114. package/dist/platform/index.js +1 -2
  115. package/dist/plugin.js +1 -2
  116. package/dist/plugins/dependencies.js +1 -2
  117. package/dist/plugins/install.js +1 -2
  118. package/dist/plugins/loader.js +1 -2
  119. package/dist/plugins/manager.js +1 -2
  120. package/dist/plugins/manifest.js +1 -2
  121. package/dist/plugins/package-link.js +1 -2
  122. package/dist/plugins/paths.js +1 -2
  123. package/dist/plugins/registry.js +1 -2
  124. package/dist/plugins/scaffold.js +1 -2
  125. package/dist/plugins/signal-lane.js +1 -2
  126. package/dist/process-memory-diagnostics.js +1 -2
  127. package/dist/processors/plan-rejection-abort.js +1 -2
  128. package/dist/providers/amazon-bedrock-gateway.js +1 -2
  129. package/dist/providers/amazon-bedrock.js +1 -2
  130. package/dist/providers/anthropic-prompt-cache.js +1 -2
  131. package/dist/providers/anthropic-thinking.js +1 -2
  132. package/dist/providers/claude-max.d.ts.map +1 -1
  133. package/dist/providers/claude-max.js +4 -4
  134. package/dist/providers/claude-max.js.map +1 -1
  135. package/dist/providers/github-copilot-gateway.js +1 -2
  136. package/dist/providers/github-copilot.d.ts.map +1 -1
  137. package/dist/providers/github-copilot.js +5 -5
  138. package/dist/providers/github-copilot.js.map +1 -1
  139. package/dist/providers/google-thinking.js +1 -2
  140. package/dist/providers/kimi-coding.d.ts.map +1 -1
  141. package/dist/providers/kimi-coding.js +8 -7
  142. package/dist/providers/kimi-coding.js.map +1 -1
  143. package/dist/providers/model-ids.js +1 -2
  144. package/dist/providers/openai-codex.d.ts.map +1 -1
  145. package/dist/providers/openai-codex.js +7 -7
  146. package/dist/providers/openai-codex.js.map +1 -1
  147. package/dist/providers/provider-thinking.js +1 -2
  148. package/dist/providers/thinking-request.js +1 -2
  149. package/dist/providers/xai.d.ts.map +1 -1
  150. package/dist/providers/xai.js +5 -5
  151. package/dist/providers/xai.js.map +1 -1
  152. package/dist/schedules/interval.js +1 -2
  153. package/dist/schedules/prompt.js +1 -2
  154. package/dist/schedules/run-script.js +1 -2
  155. package/dist/schedules/scheduler.js +1 -2
  156. package/dist/schedules/tools.js +1 -2
  157. package/dist/schema.js +1 -2
  158. package/dist/theme-palette.js +1 -2
  159. package/dist/thinking-catalog.js +1 -2
  160. package/dist/thinking.js +1 -2
  161. package/dist/tool-names.js +1 -2
  162. package/dist/tools/request-sandbox-access.js +1 -2
  163. package/dist/tools/utils.js +1 -2
  164. package/dist/tools/web-search.js +1 -2
  165. package/dist/tools/workflows/create-workflow.js +1 -2
  166. package/dist/tools/workflows/delete-workflow.js +1 -2
  167. package/dist/tools/workflows/ephemeral-memory.js +1 -2
  168. package/dist/tools/workflows/extract-json-schema.js +1 -2
  169. package/dist/tools/workflows/get-workflow.js +1 -2
  170. package/dist/tools/workflows/list-available-agents.js +1 -2
  171. package/dist/tools/workflows/list-available-classifiers.js +1 -2
  172. package/dist/tools/workflows/list-available-tools.js +1 -2
  173. package/dist/tools/workflows/list-available-workflows.js +1 -2
  174. package/dist/tools/workflows/list-workflows.js +1 -2
  175. package/dist/tools/workflows/run-workflow.js +1 -2
  176. package/dist/tools/workflows/save-workflow.js +1 -2
  177. package/dist/tools/workflows/tool-ids.js +1 -2
  178. package/dist/utils/binaries.js +1 -2
  179. package/dist/utils/debug-log.js +1 -2
  180. package/dist/utils/discarding-scores-storage.js +1 -2
  181. package/dist/utils/errors.js +1 -2
  182. package/dist/utils/gateway-sync.js +1 -2
  183. package/dist/utils/local-observability.js +1 -2
  184. package/dist/utils/maintenance-lock.js +1 -2
  185. package/dist/utils/notification-dispatch.js +1 -2
  186. package/dist/utils/open-url.js +1 -2
  187. package/dist/utils/path-security.js +1 -2
  188. package/dist/utils/plan-diff.js +1 -2
  189. package/dist/utils/plans.js +1 -2
  190. package/dist/utils/project.js +1 -2
  191. package/dist/utils/prune-cli.js +1 -2
  192. package/dist/utils/signals-pubsub.js +1 -2
  193. package/dist/utils/slash-command-loader.js +1 -2
  194. package/dist/utils/slash-command-processor.js +1 -2
  195. package/dist/utils/stdin-pipe.js +1 -2
  196. package/dist/utils/storage-factory.js +1 -2
  197. package/dist/utils/storage-maintenance.js +1 -2
  198. package/dist/utils/thread-lock.js +1 -2
  199. package/dist/utils/token-estimator.js +1 -2
  200. package/dist/utils/update-check.js +1 -2
  201. package/dist/utils/wake-session.js +1 -2
  202. package/dist/voice/stt-registry.js +1 -2
  203. package/dist/workflows/register-primitives.js +1 -2
  204. package/dist/workflows/service.js +1 -2
  205. package/package.json +36 -32
@@ -7,7 +7,7 @@ import { DEFAULT_STT_PROVIDER, resolveSTTModel } from "../voice/stt-registry.js"
7
7
  import { pruneUnknownModePackFallbacks, pruneUnknownPackAccountPreferences } from "./packs.js";
8
8
  import { dirname, join } from "path";
9
9
  import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
10
- //#region src/onboarding/settings.ts
10
+ // src/onboarding/settings.ts
11
11
  /**
12
12
  * Persistent global settings stored in the app data directory as settings.json.
13
13
  * This file persists onboarding state AND user preferences (model choices, yolo, etc.)
@@ -1082,7 +1082,6 @@ async function createBrowserFromSettings(settings, { chatModelId } = {}) {
1082
1082
  }
1083
1083
  throw new Error(`Unsupported browser provider: ${provider}`);
1084
1084
  }
1085
- //#endregion
1086
1085
  export { ExperimentalAgentSettingsError, GITHUB_POLL_INTERVAL_DEFAULT_MS, GITHUB_POLL_INTERVAL_MAX_MS, GITHUB_POLL_INTERVAL_MIN_MS, MASTRA_GATEWAY_DEFAULT_URL, MASTRA_GATEWAY_PROVIDER, MEMORY_GATEWAY_DEFAULT_URL, MEMORY_GATEWAY_PROVIDER, OBSERVABILITY_AUTH_PREFIX, STAGEHAND_PROVIDER_ENV_VARS, STORAGE_DEFAULTS, THINKING_LEVEL_VALUES, THREAD_ACTIVE_MODEL_PACK_ID_KEY, THREAD_FALLBACK_STATUS_KEY, VIEWPORT_PRESETS, WEB_SEARCH_PROVIDER_VALUES, checkProfileProviderMismatch, createBrowserFromSettings, defaultVoiceEngine, findModePackForModel, getCustomProviderId, getProfileProvider, getSettingsPath, isThinkingLevelSetting, loadSettings, migrateAccountPreferences, migrateLegacyVariedPack, parseCustomProviders, parseExperimentalAgentSetting, parseThreadSettings, parseViewportInput, pruneRemovedAccountPreferences, resolveDefaultThinkingLevel, resolveLspSetting, resolveModePackModels, resolveModelDefaults, resolveOmModel, resolveOmRoleModel, resolveStagehandModel, resolveThreadActiveModelPackId, saveSettings, setProfileProvider, stripMastraCodeCustomProviderPrefix, toActiveBrowserSettings, toCustomProviderModelId };
1087
1086
 
1088
1087
  //# sourceMappingURL=settings.js.map
@@ -1,5 +1,5 @@
1
1
  import { MC_TOOLS } from "./tool-names.js";
2
- //#region src/permissions.ts
2
+ // src/permissions.ts
3
3
  /**
4
4
  * Granular tool permission system.
5
5
  *
@@ -136,7 +136,6 @@ function resolveApproval(toolName, rules, sessionGrants) {
136
136
  if (categoryPolicy) return categoryPolicy;
137
137
  return DEFAULT_POLICIES[category] ?? "ask";
138
138
  }
139
- //#endregion
140
139
  export { DEFAULT_POLICIES, SessionGrants, TOOL_CATEGORIES, YOLO_POLICIES, createDefaultRules, getToolCategory, getToolsForCategory, resolveApproval };
141
140
 
142
141
  //# sourceMappingURL=permissions.js.map
@@ -3,7 +3,7 @@ import { execFile } from "child_process";
3
3
  import { homedir } from "os";
4
4
  import { chmod, mkdir, readFile, writeFile } from "fs/promises";
5
5
  import { createServer } from "http";
6
- //#region src/platform/index.ts
6
+ // src/platform/index.ts
7
7
  /**
8
8
  * Mastra Platform client for Mastra Code.
9
9
  *
@@ -196,7 +196,6 @@ function resolveFactoryUrl(env) {
196
196
  if (!env.instanceUrl) return null;
197
197
  return `https://${env.slug}.${FACTORY_DOMAIN}`;
198
198
  }
199
- //#endregion
200
199
  export { FACTORY_DOMAIN, MASTRA_PLATFORM_API_URL, fetchPlatformEnvironments, fetchPlatformOrgs, fetchPlatformProjects, getPlatformSession, loadPlatformCredentials, loginToPlatform, resolveFactoryUrl, savePlatformCredentials };
201
200
 
202
201
  //# sourceMappingURL=index.js.map
package/dist/plugin.js CHANGED
@@ -2,7 +2,7 @@ import { SignalProvider } from "@mastra/core/signals";
2
2
  import { createTool } from "@mastra/core/tools";
3
3
  import { z } from "zod";
4
4
  import { RequestContext } from "@mastra/core/di";
5
- //#region src/plugin.ts
5
+ // src/plugin.ts
6
6
  async function writeToolProgress(context, progress) {
7
7
  const toolCallId = context?.agent?.toolCallId;
8
8
  if (!toolCallId) return;
@@ -24,7 +24,6 @@ async function writeToolProgress(context, progress) {
24
24
  function defineMastraCodePlugin(plugin) {
25
25
  return plugin;
26
26
  }
27
- //#endregion
28
27
  export { RequestContext, SignalProvider, createTool, defineMastraCodePlugin, writeToolProgress, z };
29
28
 
30
29
  //# sourceMappingURL=plugin.js.map
@@ -1,7 +1,7 @@
1
1
  import path from "path";
2
2
  import fs from "fs";
3
3
  import { execa } from "execa";
4
- //#region src/plugins/dependencies.ts
4
+ // src/plugins/dependencies.ts
5
5
  async function installPluginDependencies(pluginRoot, commandRoot = pluginRoot, options = {}) {
6
6
  const packageJsonPath = path.join(pluginRoot, "package.json");
7
7
  if (!fs.existsSync(packageJsonPath)) return false;
@@ -81,7 +81,6 @@ function readPackageJson(pluginRoot) {
81
81
  function hasFile(pluginRoot, fileName) {
82
82
  return fs.existsSync(path.join(pluginRoot, fileName));
83
83
  }
84
- //#endregion
85
84
  export { getEntryPackageRoot, getPluginDependencyRoots, installPluginDependencies, installPluginDependenciesForEntry };
86
85
 
87
86
  //# sourceMappingURL=dependencies.js.map
@@ -8,7 +8,7 @@ import { ensureMastraCodePackageLink } from "./package-link.js";
8
8
  import path from "path";
9
9
  import fs from "fs";
10
10
  import { execa } from "execa";
11
- //#region src/plugins/install.ts
11
+ // src/plugins/install.ts
12
12
  const ENTRY_CANDIDATES = ["src/index.ts", "index.ts"];
13
13
  const NON_INTERACTIVE_GIT_ENV = {
14
14
  ...process.env,
@@ -184,7 +184,6 @@ function parseGithubUrl(specifier) {
184
184
  ...ref ? { ref } : {}
185
185
  };
186
186
  }
187
- //#endregion
188
187
  export { NON_INTERACTIVE_GIT_ENV, detectEntry, discoverLocalPlugins, installGithubPlugin, installLocalPlugin };
189
188
 
190
189
  //# sourceMappingURL=install.js.map
@@ -4,7 +4,7 @@ import path from "path";
4
4
  import fs from "fs";
5
5
  import { pathToFileURL } from "url";
6
6
  import { isSignalProvider } from "@mastra/core/signals";
7
- //#region src/plugins/loader.ts
7
+ // src/plugins/loader.ts
8
8
  async function loadPlugins(options) {
9
9
  const globalRegistry = options.globalRegistry ?? loadPluginRegistry(path.join(getPluginRoot("global", options), "plugins.json"));
10
10
  const projectRegistry = options.projectRegistry ?? loadPluginRegistry(path.join(getPluginRoot("project", options), "plugins.json"));
@@ -256,7 +256,6 @@ function markToolConflicts(plugins) {
256
256
  } : plugin;
257
257
  });
258
258
  }
259
- //#endregion
260
259
  export { collectActivePluginTools, isInsideDirectory, loadPluginFromEntry, loadPluginRecord, loadPlugins, resolvePluginEntryPath, resolvePluginRoot };
261
260
 
262
261
  //# sourceMappingURL=loader.js.map
@@ -7,7 +7,7 @@ import { NON_INTERACTIVE_GIT_ENV, discoverLocalPlugins, installGithubPlugin, ins
7
7
  import path from "path";
8
8
  import fs from "fs";
9
9
  import { execa } from "execa";
10
- //#region src/plugins/manager.ts
10
+ // src/plugins/manager.ts
11
11
  const GITHUB_PLUGIN_POLL_INTERVAL_MS = 6e4;
12
12
  function gitExecOptions(cwd) {
13
13
  return {
@@ -451,7 +451,6 @@ var PluginManager = class {
451
451
  await this.reload();
452
452
  }
453
453
  };
454
- //#endregion
455
454
  export { PluginManager };
456
455
 
457
456
  //# sourceMappingURL=manager.js.map
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import fs from "fs";
3
- //#region src/plugins/manifest.ts
3
+ // src/plugins/manifest.ts
4
4
  const PLUGIN_MANIFEST_FILE = ".mastracode-plugin.json";
5
5
  function loadPluginManifest(rootDir) {
6
6
  const manifestPath = path.join(rootDir, PLUGIN_MANIFEST_FILE);
@@ -44,7 +44,6 @@ function validateManifestEntry(entry, index) {
44
44
  ...candidate.name ? { name: candidate.name } : {}
45
45
  };
46
46
  }
47
- //#endregion
48
47
  export { PLUGIN_MANIFEST_FILE, getSingleManifestPlugin, loadPluginManifest, savePluginManifest, upsertPluginManifestEntry };
49
48
 
50
49
  //# sourceMappingURL=manifest.js.map
@@ -1,7 +1,7 @@
1
1
  import path from "path";
2
2
  import fs from "fs";
3
3
  import { fileURLToPath } from "url";
4
- //#region src/plugins/package-link.ts
4
+ // src/plugins/package-link.ts
5
5
  const MODULE_DIR = path.dirname(fileURLToPath(import.meta.url));
6
6
  let cachedPackageRoot;
7
7
  function mastraCodePackageRoot() {
@@ -55,7 +55,6 @@ function declaresInstallableMastraCodeDependency(pluginDir) {
55
55
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
56
56
  return Boolean(packageJson.dependencies?.mastracode ?? packageJson.devDependencies?.mastracode ?? packageJson.optionalDependencies?.mastracode);
57
57
  }
58
- //#endregion
59
58
  export { ensureMastraCodePackageLink, findMastraCodePackageRoot };
60
59
 
61
60
  //# sourceMappingURL=package-link.js.map
@@ -1,7 +1,7 @@
1
1
  import "../constants.js";
2
2
  import path from "path";
3
3
  import os from "os";
4
- //#region src/plugins/paths.ts
4
+ // src/plugins/paths.ts
5
5
  function getPluginRoot(scope, options) {
6
6
  const configDir = options.configDir ?? ".mastracode";
7
7
  const baseDir = scope === "project" ? options.projectRoot : options.homeDir ?? os.homedir();
@@ -19,7 +19,6 @@ function getPluginScopePaths(scope, options) {
19
19
  sourcesPath: path.join(root, "sources")
20
20
  };
21
21
  }
22
- //#endregion
23
22
  export { getPluginRegistryPath, getPluginRoot, getPluginScopePaths };
24
23
 
25
24
  //# sourceMappingURL=paths.js.map
@@ -1,6 +1,6 @@
1
1
  import path from "path";
2
2
  import fs from "fs";
3
- //#region src/plugins/registry.ts
3
+ // src/plugins/registry.ts
4
4
  const EMPTY_PLUGIN_REGISTRY = {
5
5
  plugins: {},
6
6
  disabledPlugins: []
@@ -106,7 +106,6 @@ function validatePluginConfigValues(raw) {
106
106
  }
107
107
  return values;
108
108
  }
109
- //#endregion
110
109
  export { EMPTY_PLUGIN_REGISTRY, loadPluginRegistry, mergePluginRegistries, removePluginRecord, savePluginRegistry, setPluginRecord };
111
110
 
112
111
  //# sourceMappingURL=registry.js.map
@@ -3,7 +3,7 @@ import { upsertPluginManifestEntry } from "./manifest.js";
3
3
  import { ensureMastraCodePackageLink } from "./package-link.js";
4
4
  import path from "path";
5
5
  import fs from "fs";
6
- //#region src/plugins/scaffold.ts
6
+ // src/plugins/scaffold.ts
7
7
  function resolveScaffoldTarget(target, options = {}) {
8
8
  if (isBarePluginName(target)) return path.join(options.projectRoot ?? process.cwd(), options.configDir ?? ".mastracode", "plugins", "sources", "local", target);
9
9
  return path.resolve(options.projectRoot ?? process.cwd(), target);
@@ -112,7 +112,6 @@ Open Mastra Code, run \`/plugins\`, and install this directory as a local plugin
112
112
  function humanizeName(value) {
113
113
  return value.split(/[-_.]+/g).filter(Boolean).map((part) => part[0]?.toUpperCase() + part.slice(1)).join(" ") || "Mastra Code Plugin";
114
114
  }
115
- //#endregion
116
115
  export { formatScaffoldSuccess, resolveScaffoldTarget, scaffoldPlugin };
117
116
 
118
117
  //# sourceMappingURL=scaffold.js.map
@@ -1,4 +1,4 @@
1
- //#region src/plugins/signal-lane.ts
1
+ // src/plugins/signal-lane.ts
2
2
  /**
3
3
  * Owns the lifecycle of signal providers contributed by plugins.
4
4
  *
@@ -160,7 +160,6 @@ var PluginSignalLane = class {
160
160
  this.#outputProcessors = output;
161
161
  }
162
162
  };
163
- //#endregion
164
163
  export { PluginSignalLane };
165
164
 
166
165
  //# sourceMappingURL=signal-lane.js.map
@@ -5,7 +5,7 @@ import { getHeapSpaceStatistics, getHeapStatistics } from "v8";
5
5
  import { Session } from "inspector/promises";
6
6
  import { PerformanceObserver } from "perf_hooks";
7
7
  import { arch as arch$1, platform as platform$1 } from "process";
8
- //#region src/process-memory-diagnostics.ts
8
+ // src/process-memory-diagnostics.ts
9
9
  const PROCESS_MEMORY_DIAGNOSTICS_DEFAULTS = {
10
10
  sampleIntervalMs: 1e4,
11
11
  captureIntervalMs: 3e5,
@@ -494,7 +494,6 @@ var ProcessMemoryDiagnostics = class {
494
494
  }
495
495
  }
496
496
  };
497
- //#endregion
498
497
  export { PROCESS_MEMORY_DIAGNOSTICS_DEFAULTS, PROCESS_MEMORY_DIAGNOSTICS_MINIMUMS, ProcessMemoryDiagnostics, ProcessMemoryDiagnosticsConfigError, createProcessMemoryDiagnosticsFromEnvironment, parseProcessMemoryDiagnosticsEnvironment, startConfiguredProcessMemoryDiagnostics, stopProcessMemoryDiagnosticsWithTimeout };
499
498
 
500
499
  //# sourceMappingURL=process-memory-diagnostics.js.map
@@ -1,4 +1,4 @@
1
- //#region src/processors/plan-rejection-abort.ts
1
+ // src/processors/plan-rejection-abort.ts
2
2
  const PLAN_REJECTED_PREFIX = "Plan was not approved";
3
3
  function resultText(result) {
4
4
  if (typeof result === "string") return result;
@@ -48,7 +48,6 @@ var PlanRejectionAbortProcessor = class {
48
48
  }
49
49
  }
50
50
  };
51
- //#endregion
52
51
  export { PlanRejectionAbortProcessor };
53
52
 
54
53
  //# sourceMappingURL=plan-rejection-abort.js.map
@@ -4,7 +4,7 @@ import { existsSync } from "fs";
4
4
  import { MastraModelGateway } from "@mastra/core/llm";
5
5
  import { createAmazonBedrock } from "@ai-sdk/amazon-bedrock";
6
6
  import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
7
- //#region src/providers/amazon-bedrock-gateway.ts
7
+ // src/providers/amazon-bedrock-gateway.ts
8
8
  const CLAUDE_3_CACHEABLE = /claude-3-7-sonnet|claude-3-5-sonnet-20241022|claude-3-5-haiku/;
9
9
  function supportsBedrockPromptCaching(modelId) {
10
10
  if (!modelId.includes("anthropic.claude")) return false;
@@ -139,7 +139,6 @@ var AmazonBedrockGateway = class extends MastraModelGateway {
139
139
  function createAmazonBedrockGateway() {
140
140
  return new AmazonBedrockGateway();
141
141
  }
142
- //#endregion
143
142
  export { AMAZON_BEDROCK_GATEWAY_ID, AmazonBedrockGateway, addBedrockCachePoints, createAmazonBedrockGateway, hasAwsCredentials, supportsBedrockPromptCaching, withBedrockCache };
144
143
 
145
144
  //# sourceMappingURL=amazon-bedrock-gateway.js.map
@@ -1,4 +1,4 @@
1
- //#region src/providers/amazon-bedrock.ts
1
+ // src/providers/amazon-bedrock.ts
2
2
  /**
3
3
  * Amazon Bedrock model catalog.
4
4
  *
@@ -96,7 +96,6 @@ async function getBedrockModelCatalog() {
96
96
  })();
97
97
  return inflightFetch;
98
98
  }
99
- //#endregion
100
99
  export { clearBedrockCatalogCache, getBedrockModelCatalog };
101
100
 
102
101
  //# sourceMappingURL=amazon-bedrock.js.map
@@ -1,11 +1,10 @@
1
- //#region src/providers/anthropic-prompt-cache.ts
1
+ // src/providers/anthropic-prompt-cache.ts
2
2
  /**
3
3
  * TTL for the main agent's Anthropic prompt-cache breakpoints.
4
4
  * Observational memory's idle activation for Anthropic is set to the same value,
5
5
  * so buffered observations don't activate while the cache is still warm.
6
6
  */
7
7
  const ANTHROPIC_PROMPT_CACHE_TTL = "1h";
8
- //#endregion
9
8
  export { ANTHROPIC_PROMPT_CACHE_TTL };
10
9
 
11
10
  //# sourceMappingURL=anthropic-prompt-cache.js.map
@@ -1,4 +1,4 @@
1
- //#region src/providers/anthropic-thinking.ts
1
+ // src/providers/anthropic-thinking.ts
2
2
  const ANTHROPIC_THINKING_BUDGET_TOKENS = {
3
3
  low: 4096,
4
4
  medium: 8192,
@@ -19,7 +19,6 @@ function getAnthropicThinkingCapability(modelId) {
19
19
  function supportsAnthropicXhighEffort(modelId) {
20
20
  return ANTHROPIC_XHIGH_EFFORT_RE.test(modelId);
21
21
  }
22
- //#endregion
23
22
  export { ANTHROPIC_THINKING_BUDGET_TOKENS, getAnthropicThinkingCapability, supportsAnthropicXhighEffort };
24
23
 
25
24
  //# sourceMappingURL=anthropic-thinking.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"claude-max.d.ts","sourceRoot":"","sources":["../../src/providers/claude-max.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,IAAI,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,O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AAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGxD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAE7E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAsBvD;;GAEG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAErE;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,uBAkBlC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,2BAA2B,GAAI,OAAO,yBAAyB,KAAG,uBA8D7E,CAAC;AAMH;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,aAAa,GAC5B,uBAAuB,GAAG,SAAS,CAiCrC;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAO,GAAG,OAAO,KAAK,CA2CnG;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,GAAE,MAA4B,EACrC,OAAO,CAAC,EAAE;IACR,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,gBAAgB,CAAC,EAAE,yBAAyB,CAAC;CAC9C,GACA,iBAAiB,CAgCnB"}
@@ -5,13 +5,14 @@ import { ProviderAuthRequiredError, rejectUnauthorizedResponse } from "../auth/p
5
5
  import "./anthropic-prompt-cache.js";
6
6
  import { wrapLanguageModel } from "ai";
7
7
  import { createAnthropic } from "@ai-sdk/anthropic";
8
- //#region src/providers/claude-max.ts
8
+ // src/providers/claude-max.ts
9
9
  /**
10
10
  * Claude Max OAuth Provider
11
11
  *
12
12
  * Uses OAuth tokens from AuthStorage to authenticate with Claude Max plan.
13
13
  * The OAuth endpoint requires a specific system message to be present.
14
14
  */
15
+ const PROVIDER_NAME = "Anthropic";
15
16
  const claudeCodeIdentity = "You are Claude Code, Anthropic's official CLI for Claude.";
16
17
  const OAUTH_REQUIRED_BETAS = [
17
18
  "oauth-2025-04-20",
@@ -172,7 +173,7 @@ function buildAnthropicOAuthFetch(opts = {}) {
172
173
  storage.reload();
173
174
  if (storage.get("anthropic")?.type === "api_key") throw new Error("Anthropic API key credential is configured, but OAuth is required.");
174
175
  const accessToken = await storage.getApiKey("anthropic");
175
- if (!accessToken) throw new ProviderAuthRequiredError("Not logged in to Anthropic.");
176
+ if (!accessToken) throw storage.get("anthropic")?.type === "oauth" ? ProviderAuthRequiredError.signInExpired(PROVIDER_NAME) : ProviderAuthRequiredError.notSignedIn(PROVIDER_NAME);
176
177
  const headers = new Headers(url instanceof Request ? url.headers : void 0);
177
178
  if (init?.headers) new Headers(init.headers).forEach((value, key) => headers.set(key, value));
178
179
  headers.delete("authorization");
@@ -187,7 +188,7 @@ function buildAnthropicOAuthFetch(opts = {}) {
187
188
  ...init,
188
189
  headers
189
190
  }), {
190
- providerName: "Anthropic",
191
+ providerName: PROVIDER_NAME,
191
192
  requestUrl
192
193
  });
193
194
  } catch (error) {
@@ -228,7 +229,6 @@ function opencodeClaudeMaxProvider(modelId = "claude-sonnet-5-5", options) {
228
229
  middleware
229
230
  });
230
231
  }
231
- //#endregion
232
232
  export { buildAnthropicOAuthFetch, claudeCodeMiddleware, createAnthropicThinkingMiddleware, createPromptCacheMiddleware, getAuthStorage, opencodeClaudeMaxProvider, setAuthStorage };
233
233
 
234
234
  //# sourceMappingURL=claude-max.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"claude-max.js","names":[],"sources":["../../src/providers/claude-max.ts"],"sourcesContent":["/**\n * Claude Max OAuth Provider\n *\n * Uses OAuth tokens from AuthStorage to authenticate with Claude Max plan.\n * The OAuth endpoint requires a specific system message to be present.\n */\n\nimport { createAnthropic } from '@ai-sdk/anthropic';\nimport type { MastraModelConfig } from '@mastra/core/llm';\nimport { wrapLanguageModel } from 'ai';\nimport type { LanguageModelMiddleware } from 'ai';\nimport { ProviderAuthRequiredError, rejectUnauthorizedResponse } from '../auth/provider-auth-error.js';\nimport { AuthStorage } from '../auth/storage.js';\nimport type { CredentialStore } from '../auth/types.js';\nimport { runCatalogThinkingLevel } from '../thinking-catalog.js';\nimport { ANTHROPIC_PROMPT_CACHE_TTL } from './anthropic-prompt-cache.js';\nimport type { AnthropicPromptCacheScope } from './anthropic-prompt-cache.js';\nimport { ANTHROPIC_THINKING_BUDGET_TOKENS, getAnthropicThinkingCapability } from './anthropic-thinking.js';\nimport type { ThinkingLevel } from './openai-codex.js';\n\n// Required for Claude Max plan OAuth - the endpoint checks for this system message\nconst claudeCodeIdentity = \"You are Claude Code, Anthropic's official CLI for Claude.\";\n\n// Betas required for Claude Max plan OAuth. Merged with (not replacing) any\n// betas the AI SDK already set on the request — e.g. the SDK adds\n// `server-side-fallback-2026-06-01` when `providerOptions.anthropic.fallbacks`\n// is configured; dropping it makes the API reject the `fallbacks` body field\n// with \"Extra inputs are not permitted\".\nconst OAUTH_REQUIRED_BETAS = [\n 'oauth-2025-04-20',\n 'claude-code-20250219',\n 'interleaved-thinking-2025-05-14',\n 'fine-grained-tool-streaming-2025-05-14',\n];\n\n// Singleton auth storage instance\nlet authStorageInstance: AuthStorage | null = null;\n\n/**\n * Get or create the shared AuthStorage instance\n */\nexport function getAuthStorage(): AuthStorage {\n if (!authStorageInstance) {\n authStorageInstance = new AuthStorage();\n }\n return authStorageInstance;\n}\n\n/**\n * Set a custom AuthStorage instance (useful for TUI integration)\n */\nexport function setAuthStorage(storage: AuthStorage | undefined): void {\n authStorageInstance = storage ?? null;\n}\n\n/**\n * Middleware that injects the Claude Code identity system message\n * Required for Claude Max OAuth authentication\n */\nexport const claudeCodeMiddleware: LanguageModelMiddleware = {\n specificationVersion: 'v3',\n transformParams: async ({ params }) => {\n // Prepend the Claude Code identity as the first system message\n const systemMessage = {\n role: 'system' as const,\n content: claudeCodeIdentity,\n };\n\n if (params.temperature) {\n delete params.topP;\n }\n\n return {\n ...params,\n prompt: [systemMessage, ...params.prompt],\n };\n },\n};\n\n/**\n * Prompt caching middleware for Anthropic\n *\n * Adds cache breakpoints at strategic locations:\n * 1. Last system message (end of static instructions + dynamic memory)\n * 2. Most recent user/assistant message (conversation context), `conversation` scope only\n *\n * This allows Anthropic to cache:\n * - System prompts and instructions (rarely change)\n * - Conversation history up to the last message\n */\nexport const createPromptCacheMiddleware = (scope: AnthropicPromptCacheScope): LanguageModelMiddleware => ({\n specificationVersion: 'v3',\n transformParams: async ({ params }) => {\n const prompt = [...params.prompt];\n\n const cacheControl = {\n type: 'ephemeral' as const,\n ttl: scope === 'conversation' ? ANTHROPIC_PROMPT_CACHE_TTL : ('5m' as const),\n };\n\n // Helper to add cache control to a message's last content part\n const addCacheToMessage = (msg: any) => {\n // For system messages with string content\n if (typeof msg.content === 'string') {\n return {\n ...msg,\n providerOptions: {\n ...msg.providerOptions,\n anthropic: { ...msg.providerOptions?.anthropic, cacheControl },\n },\n };\n }\n\n // For messages with array content, add to last part\n if (Array.isArray(msg.content) && msg.content.length > 0) {\n const content = [...msg.content];\n const lastPart = content[content.length - 1];\n content[content.length - 1] = {\n ...lastPart,\n providerOptions: {\n ...lastPart.providerOptions,\n anthropic: { ...lastPart.providerOptions?.anthropic, cacheControl },\n },\n };\n return { ...msg, content };\n }\n\n return msg;\n };\n\n // Find the last system message index\n let lastSystemIdx = -1;\n for (let i = prompt.length - 1; i >= 0; i--) {\n if ((prompt[i] as any).role === 'system') {\n lastSystemIdx = i;\n break;\n }\n }\n\n // Add cache breakpoint to last system message\n if (lastSystemIdx >= 0) {\n prompt[lastSystemIdx] = addCacheToMessage(prompt[lastSystemIdx]);\n }\n\n // Add cache breakpoint to the most recent message (last in array)\n const lastIdx = prompt.length - 1;\n if (scope === 'conversation' && lastIdx >= 0 && lastIdx !== lastSystemIdx) {\n prompt[lastIdx] = addCacheToMessage(prompt[lastIdx]);\n }\n\n return { ...params, prompt };\n },\n});\n\nfunction runAnthropicRequestLevel(modelId: string, level: ThinkingLevel): ThinkingLevel {\n return runCatalogThinkingLevel(`anthropic/${modelId}`, level);\n}\n\n/**\n * Middleware that maps the session thinking level onto Anthropic extended\n * thinking. Returns `undefined` (no middleware) when the level is `off` or the\n * model doesn't support thinking, preserving the previous request shape.\n *\n * - Adaptive-era models (Sonnet 4.6+/Opus 4.6+): `thinking: adaptive` plus\n * `output_config.effort`, the closest effort the model accepts.\n * - Budget-era models (Claude 3.7 – Opus 4.5): `thinking: enabled` with a\n * `budget_tokens` value derived from the level.\n */\nexport function createAnthropicThinkingMiddleware(\n modelId: string,\n thinkingLevel?: ThinkingLevel,\n): LanguageModelMiddleware | undefined {\n if (!thinkingLevel || thinkingLevel === 'off') return undefined;\n const capability = getAnthropicThinkingCapability(modelId);\n const level = runAnthropicRequestLevel(modelId, thinkingLevel);\n if (level === 'off') return undefined;\n\n return {\n specificationVersion: 'v3',\n transformParams: async ({ params }) => {\n const anthropicOptions = (params.providerOptions?.anthropic ?? {}) as Record<string, unknown>;\n // Don't override explicit per-request thinking configuration.\n if (anthropicOptions.thinking !== undefined || anthropicOptions.effort !== undefined) {\n return params;\n }\n\n // Anthropic rejects sampling parameters when thinking is enabled.\n delete params.temperature;\n delete params.topP;\n delete params.topK;\n\n params.providerOptions = {\n ...params.providerOptions,\n anthropic: {\n ...anthropicOptions,\n ...(capability === 'adaptive'\n ? { thinking: { type: 'adaptive', display: 'summarized' }, effort: level }\n : { thinking: { type: 'enabled', budgetTokens: ANTHROPIC_THINKING_BUDGET_TOKENS[level] } }),\n },\n } as typeof params.providerOptions;\n\n return params;\n },\n };\n}\n\n/**\n * Build a fetch function that handles Anthropic OAuth.\n * Preserves non-auth headers from init (critical for gateway auth header to survive\n * when used with the gateway). Strips `authorization` and `x-api-key`.\n */\nexport function buildAnthropicOAuthFetch(opts: { authStorage?: CredentialStore } = {}): typeof fetch {\n return (async (url: string | URL | Request, init?: Parameters<typeof fetch>[1]) => {\n const storage = opts.authStorage ?? getAuthStorage();\n storage.reload();\n\n const storedCred = storage.get('anthropic');\n if (storedCred?.type === 'api_key') {\n throw new Error('Anthropic API key credential is configured, but OAuth is required.');\n }\n\n const accessToken = await storage.getApiKey('anthropic');\n if (!accessToken) {\n throw new ProviderAuthRequiredError('Not logged in to Anthropic.');\n }\n\n // Preserve Request headers and let explicit init headers override them.\n const headers = new Headers(url instanceof Request ? url.headers : undefined);\n if (init?.headers) new Headers(init.headers).forEach((value, key) => headers.set(key, value));\n headers.delete('authorization');\n headers.delete('x-api-key');\n headers.set('Authorization', `Bearer ${accessToken}`);\n const requestBetas = (headers.get('anthropic-beta') ?? '')\n .split(',')\n .map(beta => beta.trim())\n .filter(Boolean);\n headers.set('anthropic-beta', Array.from(new Set([...OAUTH_REQUIRED_BETAS, ...requestBetas])).join(','));\n headers.set('anthropic-version', '2023-06-01');\n\n const requestUrl = url instanceof URL ? url.toString() : typeof url === 'string' ? url : url.url;\n try {\n return await rejectUnauthorizedResponse(await fetch(url, { ...init, headers }), {\n providerName: 'Anthropic',\n requestUrl,\n });\n } catch (error) {\n if (error && typeof error === 'object') {\n Object.assign(error as Record<string, unknown>, { requestUrl });\n }\n throw error;\n }\n }) as typeof fetch;\n}\n\n/**\n * Creates an Anthropic model using Claude Max OAuth authentication\n * Uses OAuth tokens from AuthStorage (auto-refreshes when needed)\n */\nexport function opencodeClaudeMaxProvider(\n modelId: string = 'claude-sonnet-5-5',\n options?: {\n headers?: Record<string, string>;\n authStorage?: CredentialStore;\n thinkingLevel?: ThinkingLevel;\n promptCacheScope?: AnthropicPromptCacheScope;\n },\n): MastraModelConfig {\n const headers = options?.headers;\n const thinkingMiddleware = createAnthropicThinkingMiddleware(modelId, options?.thinkingLevel);\n const middleware = [\n claudeCodeMiddleware,\n createPromptCacheMiddleware(options?.promptCacheScope ?? 'conversation'),\n ...(thinkingMiddleware ? [thinkingMiddleware] : []),\n ];\n\n // Test environment: use API key\n if (process.env.NODE_ENV === 'test' || process.env.VITEST) {\n const anthropic = createAnthropic({\n apiKey: 'test-api-key',\n headers,\n });\n return wrapLanguageModel({\n model: anthropic(modelId),\n middleware,\n });\n }\n\n const anthropic = createAnthropic({\n apiKey: 'oauth-placeholder',\n headers,\n fetch: buildAnthropicOAuthFetch({ authStorage: options?.authStorage }) as any,\n });\n\n // Wrap with middleware to inject Claude Code identity and enable prompt caching\n return wrapLanguageModel({\n model: anthropic(modelId),\n middleware,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAM,qBAAqB;AAO3B,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;AACF;AAGA,IAAI,sBAA0C;;;;AAK9C,SAAgB,iBAA8B;CAC5C,IAAI,CAAC,qBACH,sBAAsB,IAAI,YAAY;CAExC,OAAO;AACT;;;;AAKA,SAAgB,eAAe,SAAwC;CACrE,sBAAsB,WAAW;AACnC;;;;;AAMA,MAAa,uBAAgD;CAC3D,sBAAsB;CACtB,iBAAiB,OAAO,EAAE,aAAa;EAErC,MAAM,gBAAgB;GACpB,MAAM;GACN,SAAS;EACX;EAEA,IAAI,OAAO,aACT,OAAO,OAAO;EAGhB,OAAO;GACL,GAAG;GACH,QAAQ,CAAC,eAAe,GAAG,OAAO,MAAM;EAC1C;CACF;AACF;;;;;;;;;;;;AAaA,MAAa,+BAA+B,WAA+D;CACzG,sBAAsB;CACtB,iBAAiB,OAAO,EAAE,aAAa;EACrC,MAAM,SAAS,CAAC,GAAG,OAAO,MAAM;EAEhC,MAAM,eAAe;GACnB,MAAM;GACN,KAAK,UAAU,iBAAA,OAA+C;EAChE;EAGA,MAAM,qBAAqB,QAAa;GAEtC,IAAI,OAAO,IAAI,YAAY,UACzB,OAAO;IACL,GAAG;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C,MAAM,aAAa,eAAe,MAAM,IAAI,SAAS,IAAI,OAAO,QAAQ,WAAW,MAAM,IAAI;EAC7F,IAAI;GACF,OAAO,MAAM,2BAA2B,MAAM,MAAM,KAAK;IAAE,GAAG;IAAM;GAAQ,CAAC,GAAG;IAC9E,cAAc;IACd;GACF,CAAC;EACH,SAAS,OAAO;GACd,IAAI,SAAS,OAAO,UAAU,UAC5B,OAAO,OAAO,OAAkC,EAAE,WAAW,CAAC;GAEhE,MAAM;EACR;CACF;AACF;;;;;AAMA,SAAgB,0BACd,UAAkB,qBAClB,SAMmB;CACnB,MAAM,UAAU,SAAS;CACzB,MAAM,qBAAqB,kCAAkC,SAAS,SAAS,aAAa;CAC5F,MAAM,aAAa;EACjB;EACA,4BAA4B,SAAS,oBAAoB,cAAc;EACvE,GAAI,qBAAqB,CAAC,kBAAkB,IAAI,CAAC;CACnD;CAGA,IAAI,QAAQ,IAAI,aAAa,UAAU,QAAQ,IAAI,QAAQ;EACzD,MAAM,YAAY,gBAAgB;GAChC,QAAQ;GACR;EACF,CAAC;EACD,OAAO,kBAAkB;GACvB,OAAO,UAAU,OAAO;GACxB;EACF,CAAC;CACH;CAEA,MAAM,YAAY,gBAAgB;EAChC,QAAQ;EACR;EACA,OAAO,yBAAyB,EAAE,aAAa,SAAS,YAAY,CAAC;CACvE,CAAC;CAGD,OAAO,kBAAkB;EACvB,OAAO,UAAU,OAAO;EACxB;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"claude-max.js","names":[],"sources":["../../src/providers/claude-max.ts"],"sourcesContent":["/**\n * Claude Max OAuth Provider\n *\n * Uses OAuth tokens from AuthStorage to authenticate with Claude Max plan.\n * The OAuth endpoint requires a specific system message to be present.\n */\n\nimport { createAnthropic } from '@ai-sdk/anthropic';\nimport type { MastraModelConfig } from '@mastra/core/llm';\nimport { wrapLanguageModel } from 'ai';\nimport type { LanguageModelMiddleware } from 'ai';\nimport { ProviderAuthRequiredError, rejectUnauthorizedResponse } from '../auth/provider-auth-error.js';\nimport { AuthStorage } from '../auth/storage.js';\nimport type { CredentialStore } from '../auth/types.js';\nimport { runCatalogThinkingLevel } from '../thinking-catalog.js';\nimport { ANTHROPIC_PROMPT_CACHE_TTL } from './anthropic-prompt-cache.js';\nimport type { AnthropicPromptCacheScope } from './anthropic-prompt-cache.js';\nimport { ANTHROPIC_THINKING_BUDGET_TOKENS, getAnthropicThinkingCapability } from './anthropic-thinking.js';\nimport type { ThinkingLevel } from './openai-codex.js';\n\nconst PROVIDER_NAME = 'Anthropic';\n\n// Required for Claude Max plan OAuth - the endpoint checks for this system message\nconst claudeCodeIdentity = \"You are Claude Code, Anthropic's official CLI for Claude.\";\n\n// Betas required for Claude Max plan OAuth. Merged with (not replacing) any\n// betas the AI SDK already set on the request — e.g. the SDK adds\n// `server-side-fallback-2026-06-01` when `providerOptions.anthropic.fallbacks`\n// is configured; dropping it makes the API reject the `fallbacks` body field\n// with \"Extra inputs are not permitted\".\nconst OAUTH_REQUIRED_BETAS = [\n 'oauth-2025-04-20',\n 'claude-code-20250219',\n 'interleaved-thinking-2025-05-14',\n 'fine-grained-tool-streaming-2025-05-14',\n];\n\n// Singleton auth storage instance\nlet authStorageInstance: AuthStorage | null = null;\n\n/**\n * Get or create the shared AuthStorage instance\n */\nexport function getAuthStorage(): AuthStorage {\n if (!authStorageInstance) {\n authStorageInstance = new AuthStorage();\n }\n return authStorageInstance;\n}\n\n/**\n * Set a custom AuthStorage instance (useful for TUI integration)\n */\nexport function setAuthStorage(storage: AuthStorage | undefined): void {\n authStorageInstance = storage ?? null;\n}\n\n/**\n * Middleware that injects the Claude Code identity system message\n * Required for Claude Max OAuth authentication\n */\nexport const claudeCodeMiddleware: LanguageModelMiddleware = {\n specificationVersion: 'v3',\n transformParams: async ({ params }) => {\n // Prepend the Claude Code identity as the first system message\n const systemMessage = {\n role: 'system' as const,\n content: claudeCodeIdentity,\n };\n\n if (params.temperature) {\n delete params.topP;\n }\n\n return {\n ...params,\n prompt: [systemMessage, ...params.prompt],\n };\n },\n};\n\n/**\n * Prompt caching middleware for Anthropic\n *\n * Adds cache breakpoints at strategic locations:\n * 1. Last system message (end of static instructions + dynamic memory)\n * 2. Most recent user/assistant message (conversation context), `conversation` scope only\n *\n * This allows Anthropic to cache:\n * - System prompts and instructions (rarely change)\n * - Conversation history up to the last message\n */\nexport const createPromptCacheMiddleware = (scope: AnthropicPromptCacheScope): LanguageModelMiddleware => ({\n specificationVersion: 'v3',\n transformParams: async ({ params }) => {\n const prompt = [...params.prompt];\n\n const cacheControl = {\n type: 'ephemeral' as const,\n ttl: scope === 'conversation' ? ANTHROPIC_PROMPT_CACHE_TTL : ('5m' as const),\n };\n\n // Helper to add cache control to a message's last content part\n const addCacheToMessage = (msg: any) => {\n // For system messages with string content\n if (typeof msg.content === 'string') {\n return {\n ...msg,\n providerOptions: {\n ...msg.providerOptions,\n anthropic: { ...msg.providerOptions?.anthropic, cacheControl },\n },\n };\n }\n\n // For messages with array content, add to last part\n if (Array.isArray(msg.content) && msg.content.length > 0) {\n const content = [...msg.content];\n const lastPart = content[content.length - 1];\n content[content.length - 1] = {\n ...lastPart,\n providerOptions: {\n ...lastPart.providerOptions,\n anthropic: { ...lastPart.providerOptions?.anthropic, cacheControl },\n },\n };\n return { ...msg, content };\n }\n\n return msg;\n };\n\n // Find the last system message index\n let lastSystemIdx = -1;\n for (let i = prompt.length - 1; i >= 0; i--) {\n if ((prompt[i] as any).role === 'system') {\n lastSystemIdx = i;\n break;\n }\n }\n\n // Add cache breakpoint to last system message\n if (lastSystemIdx >= 0) {\n prompt[lastSystemIdx] = addCacheToMessage(prompt[lastSystemIdx]);\n }\n\n // Add cache breakpoint to the most recent message (last in array)\n const lastIdx = prompt.length - 1;\n if (scope === 'conversation' && lastIdx >= 0 && lastIdx !== lastSystemIdx) {\n prompt[lastIdx] = addCacheToMessage(prompt[lastIdx]);\n }\n\n return { ...params, prompt };\n },\n});\n\nfunction runAnthropicRequestLevel(modelId: string, level: ThinkingLevel): ThinkingLevel {\n return runCatalogThinkingLevel(`anthropic/${modelId}`, level);\n}\n\n/**\n * Middleware that maps the session thinking level onto Anthropic extended\n * thinking. Returns `undefined` (no middleware) when the level is `off` or the\n * model doesn't support thinking, preserving the previous request shape.\n *\n * - Adaptive-era models (Sonnet 4.6+/Opus 4.6+): `thinking: adaptive` plus\n * `output_config.effort`, the closest effort the model accepts.\n * - Budget-era models (Claude 3.7 – Opus 4.5): `thinking: enabled` with a\n * `budget_tokens` value derived from the level.\n */\nexport function createAnthropicThinkingMiddleware(\n modelId: string,\n thinkingLevel?: ThinkingLevel,\n): LanguageModelMiddleware | undefined {\n if (!thinkingLevel || thinkingLevel === 'off') return undefined;\n const capability = getAnthropicThinkingCapability(modelId);\n const level = runAnthropicRequestLevel(modelId, thinkingLevel);\n if (level === 'off') return undefined;\n\n return {\n specificationVersion: 'v3',\n transformParams: async ({ params }) => {\n const anthropicOptions = (params.providerOptions?.anthropic ?? {}) as Record<string, unknown>;\n // Don't override explicit per-request thinking configuration.\n if (anthropicOptions.thinking !== undefined || anthropicOptions.effort !== undefined) {\n return params;\n }\n\n // Anthropic rejects sampling parameters when thinking is enabled.\n delete params.temperature;\n delete params.topP;\n delete params.topK;\n\n params.providerOptions = {\n ...params.providerOptions,\n anthropic: {\n ...anthropicOptions,\n ...(capability === 'adaptive'\n ? { thinking: { type: 'adaptive', display: 'summarized' }, effort: level }\n : { thinking: { type: 'enabled', budgetTokens: ANTHROPIC_THINKING_BUDGET_TOKENS[level] } }),\n },\n } as typeof params.providerOptions;\n\n return params;\n },\n };\n}\n\n/**\n * Build a fetch function that handles Anthropic OAuth.\n * Preserves non-auth headers from init (critical for gateway auth header to survive\n * when used with the gateway). Strips `authorization` and `x-api-key`.\n */\nexport function buildAnthropicOAuthFetch(opts: { authStorage?: CredentialStore } = {}): typeof fetch {\n return (async (url: string | URL | Request, init?: Parameters<typeof fetch>[1]) => {\n const storage = opts.authStorage ?? getAuthStorage();\n storage.reload();\n\n const storedCred = storage.get('anthropic');\n if (storedCred?.type === 'api_key') {\n throw new Error('Anthropic API key credential is configured, but OAuth is required.');\n }\n\n const accessToken = await storage.getApiKey('anthropic');\n if (!accessToken) {\n throw storage.get('anthropic')?.type === 'oauth'\n ? ProviderAuthRequiredError.signInExpired(PROVIDER_NAME)\n : ProviderAuthRequiredError.notSignedIn(PROVIDER_NAME);\n }\n\n // Preserve Request headers and let explicit init headers override them.\n const headers = new Headers(url instanceof Request ? url.headers : undefined);\n if (init?.headers) new Headers(init.headers).forEach((value, key) => headers.set(key, value));\n headers.delete('authorization');\n headers.delete('x-api-key');\n headers.set('Authorization', `Bearer ${accessToken}`);\n const requestBetas = (headers.get('anthropic-beta') ?? '')\n .split(',')\n .map(beta => beta.trim())\n .filter(Boolean);\n headers.set('anthropic-beta', Array.from(new Set([...OAUTH_REQUIRED_BETAS, ...requestBetas])).join(','));\n headers.set('anthropic-version', '2023-06-01');\n\n const requestUrl = url instanceof URL ? url.toString() : typeof url === 'string' ? url : url.url;\n try {\n return await rejectUnauthorizedResponse(await fetch(url, { ...init, headers }), {\n providerName: PROVIDER_NAME,\n requestUrl,\n });\n } catch (error) {\n if (error && typeof error === 'object') {\n Object.assign(error as Record<string, unknown>, { requestUrl });\n }\n throw error;\n }\n }) as typeof fetch;\n}\n\n/**\n * Creates an Anthropic model using Claude Max OAuth authentication\n * Uses OAuth tokens from AuthStorage (auto-refreshes when needed)\n */\nexport function opencodeClaudeMaxProvider(\n modelId: string = 'claude-sonnet-5-5',\n options?: {\n headers?: Record<string, string>;\n authStorage?: CredentialStore;\n thinkingLevel?: ThinkingLevel;\n promptCacheScope?: AnthropicPromptCacheScope;\n },\n): MastraModelConfig {\n const headers = options?.headers;\n const thinkingMiddleware = createAnthropicThinkingMiddleware(modelId, options?.thinkingLevel);\n const middleware = [\n claudeCodeMiddleware,\n createPromptCacheMiddleware(options?.promptCacheScope ?? 'conversation'),\n ...(thinkingMiddleware ? [thinkingMiddleware] : []),\n ];\n\n // Test environment: use API key\n if (process.env.NODE_ENV === 'test' || process.env.VITEST) {\n const anthropic = createAnthropic({\n apiKey: 'test-api-key',\n headers,\n });\n return wrapLanguageModel({\n model: anthropic(modelId),\n middleware,\n });\n }\n\n const anthropic = createAnthropic({\n apiKey: 'oauth-placeholder',\n headers,\n fetch: buildAnthropicOAuthFetch({ authStorage: options?.authStorage }) as any,\n });\n\n // Wrap with middleware to inject Claude Code identity and enable prompt caching\n return wrapLanguageModel({\n model: anthropic(modelId),\n middleware,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAM,gBAAgB;AAGtB,MAAM,qBAAqB;AAO3B,MAAM,uBAAuB;CAC3B;CACA;CACA;CACA;AACF;AAGA,IAAI,sBAA0C;;;;AAK9C,SAAgB,iBAA8B;CAC5C,IAAI,CAAC,qBACH,sBAAsB,IAAI,YAAY;CAExC,OAAO;AACT;;;;AAKA,SAAgB,eAAe,SAAwC;CACrE,sBAAsB,WAAW;AACnC;;;;;AAMA,MAAa,uBAAgD;CAC3D,sBAAsB;CACtB,iBAAiB,OAAO,EAAE,aAAa;EAErC,MAAM,gBAAgB;GACpB,MAAM;GACN,SAAS;EACX;EAEA,IAAI,OAAO,aACT,OAAO,OAAO;EAGhB,OAAO;GACL,GAAG;GACH,QAAQ,CAAC,eAAe,GAAG,OAAO,MAAM;EAC1C;CACF;AACF;;;;;;;;;;;;AAaA,MAAa,+BAA+B,WAA+D;CACzG,sBAAsB;CACtB,iBAAiB,OAAO,EAAE,aAAa;EACrC,MAAM,SAAS,CAAC,GAAG,OAAO,MAAM;EAEhC,MAAM,eAAe;GACnB,MAAM;GACN,KAAK,UAAU,iBAAA,OAA+C;EAChE;EAGA,MAAM,qBAAqB,QAAa;GAEtC,IAAI,OAAO,IAAI,YAAY,UACzB,OAAO;IACL,GAAG;IACH,iBAAiB;KACf,GAAG,IAAI;KACP,WAAW;MAAE,GAAG,IAAI,iBAAiB;MAAW;KAAa;IAC/D;GACF;GAIF,IAAI,MAAM,QAAQ,IAA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AAQ,WAAW,MAAM,IAAI;EAC7F,IAAI;GACF,OAAO,MAAM,2BAA2B,MAAM,MAAM,KAAK;IAAE,GAAG;IAAM;GAAQ,CAAC,GAAG;IAC9E,cAAc;IACd;GACF,CAAC;EACH,SAAS,OAAO;GACd,IAAI,SAAS,OAAO,UAAU,UAC5B,OAAO,OAAO,OAAkC,EAAE,WAAW,CAAC;GAEhE,MAAM;EACR;CACF;AACF;;;;;AAMA,SAAgB,0BACd,UAAkB,qBAClB,SAMmB;CACnB,MAAM,UAAU,SAAS;CACzB,MAAM,qBAAqB,kCAAkC,SAAS,SAAS,aAAa;CAC5F,MAAM,aAAa;EACjB;EACA,4BAA4B,SAAS,oBAAoB,cAAc;EACvE,GAAI,qBAAqB,CAAC,kBAAkB,IAAI,CAAC;CACnD;CAGA,IAAI,QAAQ,IAAI,aAAa,UAAU,QAAQ,IAAI,QAAQ;EACzD,MAAM,YAAY,gBAAgB;GAChC,QAAQ;GACR;EACF,CAAC;EACD,OAAO,kBAAkB;GACvB,OAAO,UAAU,OAAO;GACxB;EACF,CAAC;CACH;CAEA,MAAM,YAAY,gBAAgB;EAChC,QAAQ;EACR;EACA,OAAO,yBAAyB,EAAE,aAAa,SAAS,YAAY,CAAC;CACvE,CAAC;CAGD,OAAO,kBAAkB;EACvB,OAAO,UAAU,OAAO;EACxB;CACF,CAAC;AACH"}
@@ -1,6 +1,6 @@
1
1
  import { getAuthStorage, getCopilotModelCatalog, githubCopilotProvider } from "./github-copilot.js";
2
2
  import { MastraModelGateway } from "@mastra/core/llm";
3
- //#region src/providers/github-copilot-gateway.ts
3
+ // src/providers/github-copilot-gateway.ts
4
4
  const GITHUB_COPILOT_GATEWAY_ID = "github-copilot";
5
5
  /**
6
6
  * Standalone GitHub Copilot gateway.
@@ -55,7 +55,6 @@ var GitHubCopilotGateway = class extends MastraModelGateway {
55
55
  function createGitHubCopilotGateway(options) {
56
56
  return new GitHubCopilotGateway(options);
57
57
  }
58
- //#endregion
59
58
  export { GITHUB_COPILOT_GATEWAY_ID, GitHubCopilotGateway, createGitHubCopilotGateway };
60
59
 
61
60
  //# sourceMappingURL=github-copilot-gateway.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"github-copilot.d.ts","sourceRoot":"","sources":["../../src/providers/github-copilot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAO1D,OAAO,KAAK,EAAE,iBAAiB,EAA4B,MAAM,qCAAqC,CAAC;AACvG,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,kBAAkB,CAAC;AAOzE,qDAAqD;AACrD,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAErE;AAqED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACjE,OAAO,KAAK,CAkFd;AAwED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,MAAkB,EAC3B,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,WAAW,CAAC,EAAE,eAAe,CAAA;CAAE,GAC5E,iBAAiB,CAiBnB;AAsDD,wFAAwF;AACxF,wBAAgB,wBAAwB,IAAI,IAAI,CAG/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAO,GAC3C,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA2F9B"}
1
+ {"version":3,"file":"github-copilot.d.ts","sourceRoot":"","sources":["../../src/providers/github-copilot.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAO1D,OAAO,KAAK,EAAE,iBAAiB,EAA4B,MAAM,qCAAqC,CAAC;AACvG,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,kBAAkB,CAAC;AAQzE,qDAAqD;AACrD,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAErE;AAqED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAC1C,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAO,GACjE,OAAO,KAAK,CAgFd;AAwED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,MAAkB,EAC3B,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,WAAW,CAAC,EAAE,eAAe,CAAA;CAAE,GAC5E,iBAAiB,CAiBnB;AAsDD,wFAAwF;AACxF,wBAAgB,wBAAwB,IAAI,IAAI,CAG/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAO,GAC3C,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA2F9B"}
@@ -4,7 +4,7 @@ import { ProviderAuthRequiredError, rejectUnauthorizedResponse } from "../auth/p
4
4
  import { wrapLanguageModel } from "ai";
5
5
  import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
6
6
  import { GoogleSchemaCompatLayer, applyCompatLayer } from "@mastra/schema-compat";
7
- //#region src/providers/github-copilot.ts
7
+ // src/providers/github-copilot.ts
8
8
  /**
9
9
  * GitHub Copilot OAuth Provider
10
10
  *
@@ -18,6 +18,7 @@ import { GoogleSchemaCompatLayer, applyCompatLayer } from "@mastra/schema-compat
18
18
  * - pi-mono: https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/utils/oauth/github-copilot.ts
19
19
  */
20
20
  const COPILOT_PROVIDER_ID = "github-copilot";
21
+ const COPILOT_PROVIDER_NAME = "GitHub Copilot";
21
22
  let authStorageInstance = null;
22
23
  /** Get or create the shared AuthStorage instance. */
23
24
  function getAuthStorage() {
@@ -80,7 +81,7 @@ function buildGitHubCopilotOAuthFetch(opts = {}) {
80
81
  const storage = opts.authStorage ?? getAuthStorage();
81
82
  storage.reload();
82
83
  const cred = storage.get(COPILOT_PROVIDER_ID);
83
- if (!cred || cred.type !== "oauth") throw new ProviderAuthRequiredError("Not logged in to GitHub Copilot.");
84
+ if (!cred || cred.type !== "oauth") throw ProviderAuthRequiredError.notSignedIn(COPILOT_PROVIDER_NAME);
84
85
  let accessToken;
85
86
  let activeCred;
86
87
  if (storage.getOAuthCredential) {
@@ -95,7 +96,7 @@ function buildGitHubCopilotOAuthFetch(opts = {}) {
95
96
  access: accessToken ?? reloaded.access
96
97
  } : void 0;
97
98
  }
98
- if (!accessToken || !activeCred) throw new ProviderAuthRequiredError("Failed to refresh the GitHub Copilot token.");
99
+ if (!accessToken || !activeCred) throw ProviderAuthRequiredError.signInExpired(COPILOT_PROVIDER_NAME);
99
100
  const enterpriseUrl = activeCred.enterpriseUrl;
100
101
  let parsedBody;
101
102
  try {
@@ -128,7 +129,7 @@ function buildGitHubCopilotOAuthFetch(opts = {}) {
128
129
  });
129
130
  try {
130
131
  return await rejectUnauthorizedResponse(await fetch(finalRequest), {
131
- providerName: "GitHub Copilot",
132
+ providerName: COPILOT_PROVIDER_NAME,
132
133
  requestUrl: finalUrl.toString()
133
134
  });
134
135
  } catch (error) {
@@ -316,7 +317,6 @@ async function getCopilotModelCatalog(opts = {}) {
316
317
  if (dedupeKey !== void 0) inflightFetches.set(dedupeKey, fetchPromise);
317
318
  return fetchPromise;
318
319
  }
319
- //#endregion
320
320
  export { buildGitHubCopilotOAuthFetch, clearCopilotCatalogCache, getAuthStorage, getCopilotModelCatalog, githubCopilotProvider, setAuthStorage };
321
321
 
322
322
  //# sourceMappingURL=github-copilot.js.map