@mastra/code-sdk 1.13.0 → 1.14.0-alpha.1

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 (49) hide show
  1. package/dist/agents/mastracode-gateway.d.ts.map +1 -1
  2. package/dist/agents/mastracode-gateway.js +18 -44
  3. package/dist/agents/mastracode-gateway.js.map +1 -1
  4. package/dist/agents/model.d.ts +5 -2
  5. package/dist/agents/model.d.ts.map +1 -1
  6. package/dist/agents/model.js +7 -7
  7. package/dist/agents/model.js.map +1 -1
  8. package/dist/auth/account-rotation-processor.d.ts +2 -0
  9. package/dist/auth/account-rotation-processor.d.ts.map +1 -1
  10. package/dist/auth/account-rotation-processor.js +4 -3
  11. package/dist/auth/account-rotation-processor.js.map +1 -1
  12. package/dist/auth/storage.js +1 -1
  13. package/dist/auth/storage.js.map +1 -1
  14. package/dist/index.d.ts +6 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +13 -4
  17. package/dist/index.js.map +1 -1
  18. package/dist/providers/github-copilot-gateway.d.ts +35 -0
  19. package/dist/providers/github-copilot-gateway.d.ts.map +1 -0
  20. package/dist/providers/github-copilot-gateway.js +61 -0
  21. package/dist/providers/github-copilot-gateway.js.map +1 -0
  22. package/dist/providers/kimi-coding.d.ts +0 -1
  23. package/dist/providers/kimi-coding.d.ts.map +1 -1
  24. package/dist/providers/kimi-coding.js +1 -7
  25. package/dist/providers/kimi-coding.js.map +1 -1
  26. package/dist/providers/model-ids.d.ts +18 -0
  27. package/dist/providers/model-ids.d.ts.map +1 -1
  28. package/dist/providers/model-ids.js +39 -1
  29. package/dist/providers/model-ids.js.map +1 -1
  30. package/dist/providers/provider-thinking.d.ts +5 -0
  31. package/dist/providers/provider-thinking.d.ts.map +1 -1
  32. package/dist/providers/provider-thinking.js +32 -2
  33. package/dist/providers/provider-thinking.js.map +1 -1
  34. package/dist/providers/thinking-request.d.ts +14 -0
  35. package/dist/providers/thinking-request.d.ts.map +1 -0
  36. package/dist/providers/thinking-request.js +90 -0
  37. package/dist/providers/thinking-request.js.map +1 -0
  38. package/dist/providers/xai.d.ts +2 -2
  39. package/dist/providers/xai.d.ts.map +1 -1
  40. package/dist/providers/xai.js.map +1 -1
  41. package/dist/thinking.d.ts +1 -0
  42. package/dist/thinking.d.ts.map +1 -1
  43. package/dist/thinking.js +23 -5
  44. package/dist/thinking.js.map +1 -1
  45. package/package.json +11 -11
  46. package/dist/providers/deepseek-thinking.d.ts +0 -4
  47. package/dist/providers/deepseek-thinking.d.ts.map +0 -1
  48. package/dist/providers/deepseek-thinking.js +0 -16
  49. package/dist/providers/deepseek-thinking.js.map +0 -1
@@ -0,0 +1,35 @@
1
+ import { MastraModelGateway } from '@mastra/core/llm';
2
+ import type { GatewayAuthRequest, GatewayAuthResult, GatewayLanguageModel, ProviderConfig } from '@mastra/core/llm';
3
+ import type { CredentialStore } from '../auth/types.js';
4
+ export declare const GITHUB_COPILOT_GATEWAY_ID = "github-copilot";
5
+ /**
6
+ * Standalone GitHub Copilot gateway.
7
+ *
8
+ * models.dev excludes Copilot from the shared registry, so Mastra Code supplies
9
+ * the provider itself. It is its own gateway so catalog ids are the canonical
10
+ * `github-copilot/<model>` rather than `mastracode/github-copilot/<model>`.
11
+ */
12
+ export declare class GitHubCopilotGateway extends MastraModelGateway {
13
+ #private;
14
+ readonly id = "github-copilot";
15
+ readonly name = "GitHub Copilot";
16
+ constructor(options?: {
17
+ credentialStore?: CredentialStore;
18
+ });
19
+ fetchProviders(): Promise<Record<string, ProviderConfig>>;
20
+ buildUrl(_modelId: string): string | undefined;
21
+ getApiKey(_modelId: string): Promise<string>;
22
+ resolveAuth(_request: GatewayAuthRequest): GatewayAuthResult | undefined;
23
+ resolveLanguageModel(args: {
24
+ modelId: string;
25
+ providerId: string;
26
+ apiKey: string;
27
+ headers?: Record<string, string>;
28
+ transport?: any;
29
+ responsesWebSocket?: any;
30
+ }): GatewayLanguageModel;
31
+ }
32
+ export declare function createGitHubCopilotGateway(options?: {
33
+ credentialStore?: CredentialStore;
34
+ }): GitHubCopilotGateway;
35
+ //# sourceMappingURL=github-copilot-gateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-copilot-gateway.d.ts","sourceRoot":"","sources":["../../src/providers/github-copilot-gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGxD,eAAO,MAAM,yBAAyB,mBAAmB,CAAC;AAE1D;;;;;;GAMG;AACH,qBAAa,oBAAqB,SAAQ,kBAAkB;;IAC1D,QAAQ,CAAC,EAAE,oBAA6B;IACxC,QAAQ,CAAC,IAAI,oBAAoB;gBAGrB,OAAO,GAAE;QAAE,eAAe,CAAC,EAAE,eAAe,CAAA;KAAO;IASzD,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAkB/D,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIxC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIlD,WAAW,CAAC,QAAQ,EAAE,kBAAkB,GAAG,iBAAiB,GAAG,SAAS;IAOxE,oBAAoB,CAAC,IAAI,EAAE;QACzB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,SAAS,CAAC,EAAE,GAAG,CAAC;QAChB,kBAAkB,CAAC,EAAE,GAAG,CAAC;KAC1B,GAAG,oBAAoB;CAMzB;AAED,wBAAgB,0BAA0B,CAAC,OAAO,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,eAAe,CAAA;CAAE,GAAG,oBAAoB,CAEhH"}
@@ -0,0 +1,61 @@
1
+ import { getAuthStorage, getCopilotModelCatalog, githubCopilotProvider } from "./github-copilot.js";
2
+ import { MastraModelGateway } from "@mastra/core/llm";
3
+ //#region src/providers/github-copilot-gateway.ts
4
+ const GITHUB_COPILOT_GATEWAY_ID = "github-copilot";
5
+ /**
6
+ * Standalone GitHub Copilot gateway.
7
+ *
8
+ * models.dev excludes Copilot from the shared registry, so Mastra Code supplies
9
+ * the provider itself. It is its own gateway so catalog ids are the canonical
10
+ * `github-copilot/<model>` rather than `mastracode/github-copilot/<model>`.
11
+ */
12
+ var GitHubCopilotGateway = class extends MastraModelGateway {
13
+ id = GITHUB_COPILOT_GATEWAY_ID;
14
+ name = "GitHub Copilot";
15
+ #credentials;
16
+ constructor(options = {}) {
17
+ super();
18
+ this.#credentials = options.credentialStore;
19
+ }
20
+ get #store() {
21
+ return this.#credentials ?? getAuthStorage();
22
+ }
23
+ async fetchProviders() {
24
+ try {
25
+ const models = await getCopilotModelCatalog({ authStorage: this.#store });
26
+ return { [GITHUB_COPILOT_GATEWAY_ID]: {
27
+ name: "GitHub Copilot",
28
+ apiKeyEnvVar: "",
29
+ apiKeyHeader: "Authorization",
30
+ gateway: this.id,
31
+ models: models.map((model) => model.id)
32
+ } };
33
+ } catch (error) {
34
+ console.warn("Failed to load GitHub Copilot model catalog:", error);
35
+ return {};
36
+ }
37
+ }
38
+ buildUrl(_modelId) {}
39
+ async getApiKey(_modelId) {
40
+ return "";
41
+ }
42
+ resolveAuth(_request) {
43
+ return this.#store.get("github-copilot")?.type === "oauth" ? {
44
+ bearerToken: "oauth",
45
+ source: "gateway"
46
+ } : void 0;
47
+ }
48
+ resolveLanguageModel(args) {
49
+ return githubCopilotProvider(args.modelId, {
50
+ headers: args.headers,
51
+ authStorage: this.#store
52
+ });
53
+ }
54
+ };
55
+ function createGitHubCopilotGateway(options) {
56
+ return new GitHubCopilotGateway(options);
57
+ }
58
+ //#endregion
59
+ export { GITHUB_COPILOT_GATEWAY_ID, GitHubCopilotGateway, createGitHubCopilotGateway };
60
+
61
+ //# sourceMappingURL=github-copilot-gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github-copilot-gateway.js","names":["#credentials","#store"],"sources":["../../src/providers/github-copilot-gateway.ts"],"sourcesContent":["import { MastraModelGateway } from '@mastra/core/llm';\nimport type { GatewayAuthRequest, GatewayAuthResult, GatewayLanguageModel, ProviderConfig } from '@mastra/core/llm';\nimport type { CredentialStore } from '../auth/types.js';\nimport { getAuthStorage, getCopilotModelCatalog, githubCopilotProvider } from './github-copilot.js';\n\nexport const GITHUB_COPILOT_GATEWAY_ID = 'github-copilot';\n\n/**\n * Standalone GitHub Copilot gateway.\n *\n * models.dev excludes Copilot from the shared registry, so Mastra Code supplies\n * the provider itself. It is its own gateway so catalog ids are the canonical\n * `github-copilot/<model>` rather than `mastracode/github-copilot/<model>`.\n */\nexport class GitHubCopilotGateway extends MastraModelGateway {\n readonly id = GITHUB_COPILOT_GATEWAY_ID;\n readonly name = 'GitHub Copilot';\n readonly #credentials?: CredentialStore;\n\n constructor(options: { credentialStore?: CredentialStore } = {}) {\n super();\n this.#credentials = options.credentialStore;\n }\n\n get #store(): CredentialStore {\n return this.#credentials ?? getAuthStorage();\n }\n\n async fetchProviders(): Promise<Record<string, ProviderConfig>> {\n try {\n const models = await getCopilotModelCatalog({ authStorage: this.#store });\n return {\n [GITHUB_COPILOT_GATEWAY_ID]: {\n name: 'GitHub Copilot',\n apiKeyEnvVar: '',\n apiKeyHeader: 'Authorization',\n gateway: this.id,\n models: models.map(model => model.id),\n },\n };\n } catch (error) {\n console.warn('Failed to load GitHub Copilot model catalog:', error);\n return {};\n }\n }\n\n buildUrl(_modelId: string): string | undefined {\n return undefined;\n }\n\n async getApiKey(_modelId: string): Promise<string> {\n return '';\n }\n\n resolveAuth(_request: GatewayAuthRequest): GatewayAuthResult | undefined {\n // The OAuth token is attached per request by the Copilot fetch wrapper.\n return this.#store.get(GITHUB_COPILOT_GATEWAY_ID)?.type === 'oauth'\n ? { bearerToken: 'oauth', source: 'gateway' }\n : undefined;\n }\n\n resolveLanguageModel(args: {\n modelId: string;\n providerId: string;\n apiKey: string;\n headers?: Record<string, string>;\n transport?: any;\n responsesWebSocket?: any;\n }): GatewayLanguageModel {\n return githubCopilotProvider(args.modelId, {\n headers: args.headers,\n authStorage: this.#store,\n }) as unknown as GatewayLanguageModel;\n }\n}\n\nexport function createGitHubCopilotGateway(options?: { credentialStore?: CredentialStore }): GitHubCopilotGateway {\n return new GitHubCopilotGateway(options);\n}\n"],"mappings":";;;AAKA,MAAa,4BAA4B;;;;;;;;AASzC,IAAa,uBAAb,cAA0C,mBAAmB;CAC3D,KAAc;CACd,OAAgB;CAChB;CAEA,YAAY,UAAiD,CAAC,GAAG;EAC/D,MAAM;EACN,KAAKA,eAAe,QAAQ;CAC9B;CAEA,IAAIC,SAA0B;EAC5B,OAAO,KAAKD,gBAAgB,eAAe;CAC7C;CAEA,MAAM,iBAA0D;EAC9D,IAAI;GACF,MAAM,SAAS,MAAM,uBAAuB,EAAE,aAAa,KAAKC,OAAO,CAAC;GACxE,OAAO,GACJ,4BAA4B;IAC3B,MAAM;IACN,cAAc;IACd,cAAc;IACd,SAAS,KAAK;IACd,QAAQ,OAAO,KAAI,UAAS,MAAM,EAAE;GACtC,EACF;EACF,SAAS,OAAO;GACd,QAAQ,KAAK,gDAAgD,KAAK;GAClE,OAAO,CAAC;EACV;CACF;CAEA,SAAS,UAAsC,CAE/C;CAEA,MAAM,UAAU,UAAmC;EACjD,OAAO;CACT;CAEA,YAAY,UAA6D;EAEvE,OAAO,KAAKA,OAAO,IAAA,gBAA6B,CAAC,EAAE,SAAS,UACxD;GAAE,aAAa;GAAS,QAAQ;EAAU,IAC1C,KAAA;CACN;CAEA,qBAAqB,MAOI;EACvB,OAAO,sBAAsB,KAAK,SAAS;GACzC,SAAS,KAAK;GACd,aAAa,KAAKA;EACpB,CAAC;CACH;AACF;AAEA,SAAgB,2BAA2B,SAAuE;CAChH,OAAO,IAAI,qBAAqB,OAAO;AACzC"}
@@ -1,7 +1,6 @@
1
1
  import type { MastraModelConfig } from '@mastra/core/llm';
2
2
  import { AuthStorage } from '../auth/storage.js';
3
3
  import type { CredentialStore } from '../auth/types.js';
4
- export declare const KIMI_CODING_MODELS: readonly ["k3", "k3-256k", "kimi-for-coding", "kimi-for-coding-highspeed"];
5
4
  export declare function setAuthStorage(storage: AuthStorage | undefined): void;
6
5
  export declare function buildKimiCodingOAuthFetch(options?: {
7
6
  credentialStore?: CredentialStore;
@@ -1 +1 @@
1
- {"version":3,"file":"kimi-coding.d.ts","sourceRoot":"","sources":["../../src/providers/kimi-coding.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,kBAAkB,CAAC;AAOzE,eAAO,MAAM,kBAAkB,4EAA6E,CAAC;AAI7G,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAErE;AAOD,wBAAgB,yBAAyB,CAAC,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,eAAe,CAAA;CAAO,GAAG,OAAO,KAAK,CAoC3G;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,KAAK,CASvE;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,eAAe,CAAC,EAAE,eAAe,CAAA;CAAE,GAC/F,iBAAiB,CAYnB"}
1
+ {"version":3,"file":"kimi-coding.d.ts","sourceRoot":"","sources":["../../src/providers/kimi-coding.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAG1D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,kBAAkB,CAAC;AASzE,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAErE;AAOD,wBAAgB,yBAAyB,CAAC,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,eAAe,CAAA;CAAO,GAAG,OAAO,KAAK,CAoC3G;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,KAAK,CASvE;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,eAAe,CAAC,EAAE,eAAe,CAAA;CAAE,GAC/F,iBAAiB,CAYnB"}
@@ -5,12 +5,6 @@ import { createAnthropic } from "@ai-sdk/anthropic";
5
5
  //#region src/providers/kimi-coding.ts
6
6
  const PROVIDER_ID = "kimi-for-coding";
7
7
  const BASE_URL = "https://api.kimi.com/coding/v1";
8
- const KIMI_CODING_MODELS = [
9
- "k3",
10
- "k3-256k",
11
- "kimi-for-coding",
12
- "kimi-for-coding-highspeed"
13
- ];
14
8
  let authStorageInstance = null;
15
9
  function setAuthStorage(storage) {
16
10
  authStorageInstance = storage ?? null;
@@ -79,6 +73,6 @@ function kimiCodingProvider(modelId, options) {
79
73
  })(modelId);
80
74
  }
81
75
  //#endregion
82
- export { KIMI_CODING_MODELS, buildKimiCodingApiKeyFetch, buildKimiCodingOAuthFetch, kimiCodingProvider, setAuthStorage };
76
+ export { buildKimiCodingApiKeyFetch, buildKimiCodingOAuthFetch, kimiCodingProvider, setAuthStorage };
83
77
 
84
78
  //# sourceMappingURL=kimi-coding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kimi-coding.js","names":[],"sources":["../../src/providers/kimi-coding.ts"],"sourcesContent":["import { createAnthropic } from '@ai-sdk/anthropic';\nimport type { MastraModelConfig } from '@mastra/core/llm';\nimport { ProviderAuthRequiredError } from '../auth/provider-auth-error.js';\nimport { getKimiCodingDeviceHeaders, isKimiCodingDeviceId } from '../auth/providers/kimi-coding.js';\nimport { AuthStorage } from '../auth/storage.js';\nimport type { CredentialStore, OAuthCredential } from '../auth/types.js';\n\nconst PROVIDER_ID = 'kimi-for-coding';\n// Pi's provider root is https://api.kimi.com/coding. The AI SDK expects the\n// versioned Anthropic base URL and appends /messages itself.\nconst BASE_URL = 'https://api.kimi.com/coding/v1';\n\nexport const KIMI_CODING_MODELS = ['k3', 'k3-256k', 'kimi-for-coding', 'kimi-for-coding-highspeed'] as const;\n\nlet authStorageInstance: AuthStorage | null = null;\n\nexport function setAuthStorage(storage: AuthStorage | undefined): void {\n authStorageInstance = storage ?? null;\n}\n\nfunction getAuthStorage(): AuthStorage {\n if (!authStorageInstance) authStorageInstance = new AuthStorage();\n return authStorageInstance;\n}\n\nexport function buildKimiCodingOAuthFetch(options: { credentialStore?: CredentialStore } = {}): typeof fetch {\n return (async (input: string | URL | Request, init?: Parameters<typeof fetch>[1]) => {\n const store = options.credentialStore ?? getAuthStorage();\n store.reload();\n const credential = store.get(PROVIDER_ID);\n if (!credential || credential.type !== 'oauth') {\n throw new ProviderAuthRequiredError('Not logged in to Kimi For Coding.');\n }\n if (!isKimiCodingDeviceId(credential.deviceId)) {\n throw new ProviderAuthRequiredError('Kimi For Coding credentials are invalid. Please reconnect the account.');\n }\n let token: string | undefined;\n let activeCredential: OAuthCredential | undefined = credential;\n if (store.getOAuthCredential) {\n activeCredential = await store.getOAuthCredential(PROVIDER_ID);\n token = activeCredential?.access;\n } else {\n token = await store.getApiKey(PROVIDER_ID);\n store.reload();\n const reloaded = store.get(PROVIDER_ID);\n activeCredential = reloaded?.type === 'oauth' ? { ...reloaded, access: token ?? reloaded.access } : undefined;\n }\n if (!token) throw new ProviderAuthRequiredError('Failed to refresh the Kimi For Coding token.');\n if (!activeCredential || !isKimiCodingDeviceId(activeCredential.deviceId)) {\n throw new ProviderAuthRequiredError('Kimi For Coding credentials are invalid. Please reconnect the account.');\n }\n const deviceHeaders = getKimiCodingDeviceHeaders(activeCredential.deviceId);\n\n const headers = new Headers(input instanceof Request ? input.headers : undefined);\n if (init?.headers) new Headers(init.headers).forEach((value, key) => headers.set(key, value));\n for (const [key, value] of Object.entries(deviceHeaders)) headers.set(key, value);\n headers.delete('authorization');\n headers.delete('x-api-key');\n headers.set('Authorization', `Bearer ${token}`);\n return fetch(input, { ...init, headers });\n }) as typeof fetch;\n}\n\nexport function buildKimiCodingApiKeyFetch(apiKey: string): typeof fetch {\n return (async (input: string | URL | Request, init?: Parameters<typeof fetch>[1]) => {\n const headers = new Headers(input instanceof Request ? input.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 ${apiKey}`);\n return fetch(input, { ...init, headers });\n }) as typeof fetch;\n}\n\nexport function kimiCodingProvider(\n modelId: string,\n options: { apiKey: string; headers?: Record<string, string>; credentialStore?: CredentialStore },\n): MastraModelConfig {\n const usesOAuth = options.credentialStore?.get(PROVIDER_ID)?.type === 'oauth';\n const provider = createAnthropic({\n name: PROVIDER_ID,\n apiKey: 'auth-placeholder',\n baseURL: BASE_URL,\n headers: options.headers,\n fetch: usesOAuth\n ? (buildKimiCodingOAuthFetch({ credentialStore: options.credentialStore }) as any)\n : (buildKimiCodingApiKeyFetch(options.apiKey) as any),\n });\n return provider(modelId) as unknown as MastraModelConfig;\n}\n"],"mappings":";;;;;AAOA,MAAM,cAAc;AAGpB,MAAM,WAAW;AAEjB,MAAa,qBAAqB;CAAC;CA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,OAAO,QAAQ,aAAa,GAAG,QAAQ,IAAI,KAAK,KAAK;EAChF,QAAQ,OAAO,eAAe;EAC9B,QAAQ,OAAO,WAAW;EAC1B,QAAQ,IAAI,iBAAiB,UAAU,OAAO;EAC9C,OAAO,MAAM,OAAO;GAAE,GAAG;GAAM;EAAQ,CAAC;CAC1C;AACF;AAEA,SAAgB,2BAA2B,QAA8B;CACvE,QAAQ,OAAO,OAA+B,SAAuC;EACnF,MAAM,UAAU,IAAI,QAAQ,iBAAiB,UAAU,MAAM,UAAU,KAAA,CAAS;EAChF,IAAI,MAAM,SAAS,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,OAAO,QAAQ,QAAQ,IAAI,KAAK,KAAK,CAAC;EAC5F,QAAQ,OAAO,eAAe;EAC9B,QAAQ,OAAO,WAAW;EAC1B,QAAQ,IAAI,iBAAiB,UAAU,QAAQ;EAC/C,OAAO,MAAM,OAAO;GAAE,GAAG;GAAM;EAAQ,CAAC;CAC1C;AACF;AAEA,SAAgB,mBACd,SACA,SACmB;CACnB,MAAM,YAAY,QAAQ,iBAAiB,IAAI,WAAW,CAAC,EAAE,SAAS;CAUtE,OATiB,gBAAgB;EAC/B,MAAM;EACN,QAAQ;EACR,SAAS;EACT,SAAS,QAAQ;EACjB,OAAO,YACF,0BAA0B,EAAE,iBAAiB,QAAQ,gBAAgB,CAAC,IACtE,2BAA2B,QAAQ,MAAM;CAChD,CACc,CAAC,CAAC,OAAO;AACzB"}
1
+ {"version":3,"file":"kimi-coding.js","names":[],"sources":["../../src/providers/kimi-coding.ts"],"sourcesContent":["import { createAnthropic } from '@ai-sdk/anthropic';\nimport type { MastraModelConfig } from '@mastra/core/llm';\nimport { ProviderAuthRequiredError } from '../auth/provider-auth-error.js';\nimport { getKimiCodingDeviceHeaders, isKimiCodingDeviceId } from '../auth/providers/kimi-coding.js';\nimport { AuthStorage } from '../auth/storage.js';\nimport type { CredentialStore, OAuthCredential } from '../auth/types.js';\n\nconst PROVIDER_ID = 'kimi-for-coding';\n// Pi's provider root is https://api.kimi.com/coding. The AI SDK expects the\n// versioned Anthropic base URL and appends /messages itself.\nconst BASE_URL = 'https://api.kimi.com/coding/v1';\n\nlet authStorageInstance: AuthStorage | null = null;\n\nexport function setAuthStorage(storage: AuthStorage | undefined): void {\n authStorageInstance = storage ?? null;\n}\n\nfunction getAuthStorage(): AuthStorage {\n if (!authStorageInstance) authStorageInstance = new AuthStorage();\n return authStorageInstance;\n}\n\nexport function buildKimiCodingOAuthFetch(options: { credentialStore?: CredentialStore } = {}): typeof fetch {\n return (async (input: string | URL | Request, init?: Parameters<typeof fetch>[1]) => {\n const store = options.credentialStore ?? getAuthStorage();\n store.reload();\n const credential = store.get(PROVIDER_ID);\n if (!credential || credential.type !== 'oauth') {\n throw new ProviderAuthRequiredError('Not logged in to Kimi For Coding.');\n }\n if (!isKimiCodingDeviceId(credential.deviceId)) {\n throw new ProviderAuthRequiredError('Kimi For Coding credentials are invalid. Please reconnect the account.');\n }\n let token: string | undefined;\n let activeCredential: OAuthCredential | undefined = credential;\n if (store.getOAuthCredential) {\n activeCredential = await store.getOAuthCredential(PROVIDER_ID);\n token = activeCredential?.access;\n } else {\n token = await store.getApiKey(PROVIDER_ID);\n store.reload();\n const reloaded = store.get(PROVIDER_ID);\n activeCredential = reloaded?.type === 'oauth' ? { ...reloaded, access: token ?? reloaded.access } : undefined;\n }\n if (!token) throw new ProviderAuthRequiredError('Failed to refresh the Kimi For Coding token.');\n if (!activeCredential || !isKimiCodingDeviceId(activeCredential.deviceId)) {\n throw new ProviderAuthRequiredError('Kimi For Coding credentials are invalid. Please reconnect the account.');\n }\n const deviceHeaders = getKimiCodingDeviceHeaders(activeCredential.deviceId);\n\n const headers = new Headers(input instanceof Request ? input.headers : undefined);\n if (init?.headers) new Headers(init.headers).forEach((value, key) => headers.set(key, value));\n for (const [key, value] of Object.entries(deviceHeaders)) headers.set(key, value);\n headers.delete('authorization');\n headers.delete('x-api-key');\n headers.set('Authorization', `Bearer ${token}`);\n return fetch(input, { ...init, headers });\n }) as typeof fetch;\n}\n\nexport function buildKimiCodingApiKeyFetch(apiKey: string): typeof fetch {\n return (async (input: string | URL | Request, init?: Parameters<typeof fetch>[1]) => {\n const headers = new Headers(input instanceof Request ? input.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 ${apiKey}`);\n return fetch(input, { ...init, headers });\n }) as typeof fetch;\n}\n\nexport function kimiCodingProvider(\n modelId: string,\n options: { apiKey: string; headers?: Record<string, string>; credentialStore?: CredentialStore },\n): MastraModelConfig {\n const usesOAuth = options.credentialStore?.get(PROVIDER_ID)?.type === 'oauth';\n const provider = createAnthropic({\n name: PROVIDER_ID,\n apiKey: 'auth-placeholder',\n baseURL: BASE_URL,\n headers: options.headers,\n fetch: usesOAuth\n ? (buildKimiCodingOAuthFetch({ credentialStore: options.credentialStore }) as any)\n : (buildKimiCodingApiKeyFetch(options.apiKey) as any),\n });\n return provider(modelId) as unknown as MastraModelConfig;\n}\n"],"mappings":";;;;;AAOA,MAAM,cAAc;AAGpB,MAAM,WAAW;AAEjB,IAAI,sBAA0C;AAE9C,SAAgB,eAAe,SAAwC;CACrE,sBAAsB,WAAW;AACnC;AAEA,SAAS,iBAA8B;CACrC,IAAI,CAAC,qBAAqB,sBAAsB,IAAI,YAAY;CAChE,OAAO;AACT;AAEA,SAAgB,0BAA0B,UAAiD,CAAC,GAAiB;CAC3G,QAAQ,OAAO,OAA+B,SAAuC;EACnF,MAAM,QAAQ,QAAQ,mBAAmB,eAAe;EACxD,MAAM,OAAO;EACb,MAAM,aAAa,MAAM,IAAI,WAAW;EACxC,IAAI,CAAC,cAAc,WAAW,SAAS,SACrC,MAAM,IAAI,0BAA0B,mCAAmC;EAEzE,IAAI,CAAC,qBAAqB,WAAW,QAAQ,GAC3C,MAAM,IAAI,0BAA0B,wEAAwE;EAE9G,IAAI;EACJ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AQ,IAAI,iBAAiB,UAAU,QAAQ;EAC/C,OAAO,MAAM,OAAO;GAAE,GAAG;GAAM;EAAQ,CAAC;CAC1C;AACF;AAEA,SAAgB,mBACd,SACA,SACmB;CACnB,MAAM,YAAY,QAAQ,iBAAiB,IAAI,WAAW,CAAC,EAAE,SAAS;CAUtE,OATiB,gBAAgB;EAC/B,MAAM;EACN,QAAQ;EACR,SAAS;EACT,SAAS,QAAQ;EACjB,OAAO,YACF,0BAA0B,EAAE,iBAAiB,QAAQ,gBAAgB,CAAC,IACtE,2BAA2B,QAAQ,MAAM;CAChD,CACc,CAAC,CAAC,OAAO;AACzB"}
@@ -8,5 +8,23 @@ export declare const MASTRA_GATEWAY_PREFIX = "mastra/";
8
8
  /** Anthropic's API only accepts dashed ids (`claude-opus-4-6`), but catalogs may list dotted ones. */
9
9
  export declare function normalizeAnthropicModelId(modelId: string): string;
10
10
  export declare function stripMastraGatewayPrefix(modelId: string): string;
11
+ /**
12
+ * Kimi For Coding subscriptions are served from `api.kimi.com`, which models.dev
13
+ * lists as `kimi-code-plan-cn`. Mastra Code augments that provider with the
14
+ * Kimi OAuth/API-key credential instead of defining its own.
15
+ */
16
+ export declare const KIMI_CODING_PROVIDER_ID = "kimi-code-plan-cn";
17
+ /** Credential id the Kimi login stores accounts under. */
18
+ export declare const KIMI_CODING_CREDENTIAL_ID = "kimi-for-coding";
19
+ /**
20
+ * Map model ids saved by older Mastra Code versions (packs, OM settings,
21
+ * thread metadata) to the current catalog id:
22
+ * `mastracode/kimi-for-coding/k3` and `kimi-for-coding/k3` → `kimi-code-plan-cn/k3`,
23
+ * `mastracode/github-copilot/<m>` → `github-copilot/<m>`,
24
+ * `mastracode/amazon-bedrock/<m>` → `amazon-bedrock/<m>`.
25
+ */
26
+ export declare function normalizeLegacyModelId(modelId: string): string;
27
+ /** Credential-store id that authenticates a catalog provider id. */
28
+ export declare function getCredentialProviderId(providerId: string): string;
11
29
  export declare function remapOpenAIModelForCodexOAuth(modelId: string): string;
12
30
  //# sourceMappingURL=model-ids.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-ids.d.ts","sourceRoot":"","sources":["../../src/providers/model-ids.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,qBAAqB,YAAY,CAAC;AAE/C,sGAAsG;AACtG,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjE;AAeD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAoBrE"}
1
+ {"version":3,"file":"model-ids.d.ts","sourceRoot":"","sources":["../../src/providers/model-ids.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,aAAa,YAAY,CAAC;AACvC,eAAO,MAAM,gBAAgB,eAAe,CAAC;AAC7C,eAAO,MAAM,qBAAqB,YAAY,CAAC;AAE/C,sGAAsG;AACtG,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjE;AAeD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhE;AAED;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,sBAAsB,CAAC;AAC3D,0DAA0D;AAC1D,eAAO,MAAM,yBAAyB,oBAAoB,CAAC;AAS3D;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAU9D;AAED,oEAAoE;AACpE,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAIlE;AAED,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAoBrE"}
@@ -25,6 +25,44 @@ const CODEX_OPENAI_MODEL_REMAPS = {
25
25
  function stripMastraGatewayPrefix(modelId) {
26
26
  return modelId.startsWith("mastra/") ? modelId.substring(7) : modelId;
27
27
  }
28
+ /**
29
+ * Kimi For Coding subscriptions are served from `api.kimi.com`, which models.dev
30
+ * lists as `kimi-code-plan-cn`. Mastra Code augments that provider with the
31
+ * Kimi OAuth/API-key credential instead of defining its own.
32
+ */
33
+ const KIMI_CODING_PROVIDER_ID = "kimi-code-plan-cn";
34
+ /** Credential id the Kimi login stores accounts under. */
35
+ const KIMI_CODING_CREDENTIAL_ID = "kimi-for-coding";
36
+ /** Providers Mastra Code used to catalog as `mastracode/<provider>/<model>`. */
37
+ const LEGACY_MASTRACODE_NAMESPACED_PROVIDERS = /* @__PURE__ */ new Set([
38
+ "amazon-bedrock",
39
+ "github-copilot",
40
+ KIMI_CODING_CREDENTIAL_ID
41
+ ]);
42
+ /** Provider ids Mastra Code defined itself before augmenting the models.dev provider. */
43
+ const LEGACY_PROVIDER_IDS = { [KIMI_CODING_CREDENTIAL_ID]: KIMI_CODING_PROVIDER_ID };
44
+ /**
45
+ * Map model ids saved by older Mastra Code versions (packs, OM settings,
46
+ * thread metadata) to the current catalog id:
47
+ * `mastracode/kimi-for-coding/k3` and `kimi-for-coding/k3` → `kimi-code-plan-cn/k3`,
48
+ * `mastracode/github-copilot/<m>` → `github-copilot/<m>`,
49
+ * `mastracode/amazon-bedrock/<m>` → `amazon-bedrock/<m>`.
50
+ */
51
+ function normalizeLegacyModelId(modelId) {
52
+ let normalized = modelId;
53
+ const namespacedProvider = normalized.startsWith("mastracode/") ? normalized.split("/", 3)[1] : void 0;
54
+ if (namespacedProvider && LEGACY_MASTRACODE_NAMESPACED_PROVIDERS.has(namespacedProvider)) normalized = normalized.slice(11);
55
+ const slash = normalized.indexOf("/");
56
+ const providerId = slash > 0 ? normalized.slice(0, slash) : void 0;
57
+ const replacement = providerId ? LEGACY_PROVIDER_IDS[providerId] : void 0;
58
+ return replacement ? `${replacement}${normalized.slice(slash)}` : normalized;
59
+ }
60
+ /** Credential-store id that authenticates a catalog provider id. */
61
+ function getCredentialProviderId(providerId) {
62
+ if (providerId === "openai") return "openai-codex";
63
+ if (providerId === "kimi-code-plan-cn") return KIMI_CODING_CREDENTIAL_ID;
64
+ return providerId;
65
+ }
28
66
  function remapOpenAIModelForCodexOAuth(modelId) {
29
67
  const normalizedModelId = stripMastraGatewayPrefix(modelId);
30
68
  if (!normalizedModelId.startsWith("openai/")) return modelId;
@@ -36,6 +74,6 @@ function remapOpenAIModelForCodexOAuth(modelId) {
36
74
  return modelId.startsWith("mastra/") ? `${MASTRA_GATEWAY_PREFIX}${remappedModelId}` : remappedModelId;
37
75
  }
38
76
  //#endregion
39
- export { ANTHROPIC_PREFIX, MASTRA_GATEWAY_PREFIX, OPENAI_PREFIX, normalizeAnthropicModelId, remapOpenAIModelForCodexOAuth, stripMastraGatewayPrefix };
77
+ export { ANTHROPIC_PREFIX, KIMI_CODING_CREDENTIAL_ID, KIMI_CODING_PROVIDER_ID, MASTRA_GATEWAY_PREFIX, OPENAI_PREFIX, getCredentialProviderId, normalizeAnthropicModelId, normalizeLegacyModelId, remapOpenAIModelForCodexOAuth, stripMastraGatewayPrefix };
40
78
 
41
79
  //# sourceMappingURL=model-ids.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-ids.js","names":[],"sources":["../../src/providers/model-ids.ts"],"sourcesContent":["/**\n * Model-id helpers shared by the model gateway and the browser settings\n * module. Kept dependency-free so neither side has to import the other.\n */\n\nexport const OPENAI_PREFIX = 'openai/';\nexport const ANTHROPIC_PREFIX = 'anthropic/';\nexport const MASTRA_GATEWAY_PREFIX = 'mastra/';\n\n/** Anthropic's API only accepts dashed ids (`claude-opus-4-6`), but catalogs may list dotted ones. */\nexport function normalizeAnthropicModelId(modelId: string): string {\n return modelId.replace(/\\.(?=\\d)/g, '-');\n}\n\n/**\n * The Codex ChatGPT-account endpoint serves some OpenAI models only under a\n * `-codex` id. Applied wherever a model id is sent over Codex OAuth (chat\n * agents and Stagehand alike) so both paths hit the same upstream model.\n */\nconst CODEX_OPENAI_MODEL_REMAPS: Record<string, string> = {\n 'gpt-5.3': 'gpt-5.3-codex',\n 'gpt-5.2': 'gpt-5.2-codex',\n 'gpt-5.1': 'gpt-5.1-codex',\n 'gpt-5.1-mini': 'gpt-5.1-codex-mini',\n 'gpt-5': 'gpt-5-codex',\n};\n\nexport function stripMastraGatewayPrefix(modelId: string): string {\n return modelId.startsWith(MASTRA_GATEWAY_PREFIX) ? modelId.substring(MASTRA_GATEWAY_PREFIX.length) : modelId;\n}\n\nexport function remapOpenAIModelForCodexOAuth(modelId: string): string {\n const normalizedModelId = stripMastraGatewayPrefix(modelId);\n\n if (!normalizedModelId.startsWith(OPENAI_PREFIX)) {\n return modelId;\n }\n\n const openaiModelId = normalizedModelId.substring(OPENAI_PREFIX.length);\n\n if (openaiModelId.includes('-codex')) {\n return modelId;\n }\n\n const codexModelId = CODEX_OPENAI_MODEL_REMAPS[openaiModelId];\n if (!codexModelId) {\n return modelId;\n }\n\n const remappedModelId = `${OPENAI_PREFIX}${codexModelId}`;\n return modelId.startsWith(MASTRA_GATEWAY_PREFIX) ? `${MASTRA_GATEWAY_PREFIX}${remappedModelId}` : remappedModelId;\n}\n"],"mappings":";;;;;AAKA,MAAa,gBAAgB;AAC7B,MAAa,mBAAmB;AAChC,MAAa,wBAAwB;;AAGrC,SAAgB,0BAA0B,SAAyB;CACjE,OAAO,QAAQ,QAAQ,aAAa,GAAG;AACzC;;;;;;AAOA,MAAM,4BAAoD;CACxD,WAAW;CACX,WAAW;CACX,WAAW;CACX,gBAAgB;CAChB,SAAS;AACX;AAEA,SAAgB,yBAAyB,SAAyB;CAChE,OAAO,QAAQ,WAAA,SAAgC,IAAI,QAAQ,UAAU,CAA4B,IAAI;AACvG;AAEA,SAAgB,8BAA8B,SAAyB;CACrE,MAAM,oBAAoB,yBAAyB,OAAO;CAE1D,IAAI,CAAC,kBAAkB,WAAA,SAAwB,GAC7C,OAAO;CAGT,MAAM,gBAAgB,kBAAkB,UAAU,CAAoB;CAEtE,IAAI,cAAc,SAAS,QAAQ,GACjC,OAAO;CAGT,MAAM,eAAe,0BAA0B;CAC/C,IAAI,CAAC,cACH,OAAO;CAGT,MAAM,kBAAkB,GAAG,gBAAgB;CAC3C,OAAO,QAAQ,WAAA,SAAgC,IAAI,GAAG,wBAAwB,oBAAoB;AACpG"}
1
+ {"version":3,"file":"model-ids.js","names":[],"sources":["../../src/providers/model-ids.ts"],"sourcesContent":["/**\n * Model-id helpers shared by the model gateway and the browser settings\n * module. Kept dependency-free so neither side has to import the other.\n */\n\nexport const OPENAI_PREFIX = 'openai/';\nexport const ANTHROPIC_PREFIX = 'anthropic/';\nexport const MASTRA_GATEWAY_PREFIX = 'mastra/';\n\n/** Anthropic's API only accepts dashed ids (`claude-opus-4-6`), but catalogs may list dotted ones. */\nexport function normalizeAnthropicModelId(modelId: string): string {\n return modelId.replace(/\\.(?=\\d)/g, '-');\n}\n\n/**\n * The Codex ChatGPT-account endpoint serves some OpenAI models only under a\n * `-codex` id. Applied wherever a model id is sent over Codex OAuth (chat\n * agents and Stagehand alike) so both paths hit the same upstream model.\n */\nconst CODEX_OPENAI_MODEL_REMAPS: Record<string, string> = {\n 'gpt-5.3': 'gpt-5.3-codex',\n 'gpt-5.2': 'gpt-5.2-codex',\n 'gpt-5.1': 'gpt-5.1-codex',\n 'gpt-5.1-mini': 'gpt-5.1-codex-mini',\n 'gpt-5': 'gpt-5-codex',\n};\n\nexport function stripMastraGatewayPrefix(modelId: string): string {\n return modelId.startsWith(MASTRA_GATEWAY_PREFIX) ? modelId.substring(MASTRA_GATEWAY_PREFIX.length) : modelId;\n}\n\n/**\n * Kimi For Coding subscriptions are served from `api.kimi.com`, which models.dev\n * lists as `kimi-code-plan-cn`. Mastra Code augments that provider with the\n * Kimi OAuth/API-key credential instead of defining its own.\n */\nexport const KIMI_CODING_PROVIDER_ID = 'kimi-code-plan-cn';\n/** Credential id the Kimi login stores accounts under. */\nexport const KIMI_CODING_CREDENTIAL_ID = 'kimi-for-coding';\n\n/** Providers Mastra Code used to catalog as `mastracode/<provider>/<model>`. */\nconst LEGACY_MASTRACODE_NAMESPACED_PROVIDERS = new Set(['amazon-bedrock', 'github-copilot', KIMI_CODING_CREDENTIAL_ID]);\n/** Provider ids Mastra Code defined itself before augmenting the models.dev provider. */\nconst LEGACY_PROVIDER_IDS: Record<string, string> = {\n [KIMI_CODING_CREDENTIAL_ID]: KIMI_CODING_PROVIDER_ID,\n};\n\n/**\n * Map model ids saved by older Mastra Code versions (packs, OM settings,\n * thread metadata) to the current catalog id:\n * `mastracode/kimi-for-coding/k3` and `kimi-for-coding/k3` → `kimi-code-plan-cn/k3`,\n * `mastracode/github-copilot/<m>` → `github-copilot/<m>`,\n * `mastracode/amazon-bedrock/<m>` → `amazon-bedrock/<m>`.\n */\nexport function normalizeLegacyModelId(modelId: string): string {\n let normalized = modelId;\n const namespacedProvider = normalized.startsWith('mastracode/') ? normalized.split('/', 3)[1] : undefined;\n if (namespacedProvider && LEGACY_MASTRACODE_NAMESPACED_PROVIDERS.has(namespacedProvider)) {\n normalized = normalized.slice('mastracode/'.length);\n }\n const slash = normalized.indexOf('/');\n const providerId = slash > 0 ? normalized.slice(0, slash) : undefined;\n const replacement = providerId ? LEGACY_PROVIDER_IDS[providerId] : undefined;\n return replacement ? `${replacement}${normalized.slice(slash)}` : normalized;\n}\n\n/** Credential-store id that authenticates a catalog provider id. */\nexport function getCredentialProviderId(providerId: string): string {\n if (providerId === 'openai') return 'openai-codex';\n if (providerId === KIMI_CODING_PROVIDER_ID) return KIMI_CODING_CREDENTIAL_ID;\n return providerId;\n}\n\nexport function remapOpenAIModelForCodexOAuth(modelId: string): string {\n const normalizedModelId = stripMastraGatewayPrefix(modelId);\n\n if (!normalizedModelId.startsWith(OPENAI_PREFIX)) {\n return modelId;\n }\n\n const openaiModelId = normalizedModelId.substring(OPENAI_PREFIX.length);\n\n if (openaiModelId.includes('-codex')) {\n return modelId;\n }\n\n const codexModelId = CODEX_OPENAI_MODEL_REMAPS[openaiModelId];\n if (!codexModelId) {\n return modelId;\n }\n\n const remappedModelId = `${OPENAI_PREFIX}${codexModelId}`;\n return modelId.startsWith(MASTRA_GATEWAY_PREFIX) ? `${MASTRA_GATEWAY_PREFIX}${remappedModelId}` : remappedModelId;\n}\n"],"mappings":";;;;;AAKA,MAAa,gBAAgB;AAC7B,MAAa,mBAAmB;AAChC,MAAa,wBAAwB;;AAGrC,SAAgB,0BAA0B,SAAyB;CACjE,OAAO,QAAQ,QAAQ,aAAa,GAAG;AACzC;;;;;;AAOA,MAAM,4BAAoD;CACxD,WAAW;CACX,WAAW;CACX,WAAW;CACX,gBAAgB;CAChB,SAAS;AACX;AAEA,SAAgB,yBAAyB,SAAyB;CAChE,OAAO,QAAQ,WAAA,SAAgC,IAAI,QAAQ,UAAU,CAA4B,IAAI;AACvG;;;;;;AAOA,MAAa,0BAA0B;;AAEvC,MAAa,4BAA4B;;AAGzC,MAAM,yDAAyC,IAAI,IAAI;CAAC;CAAkB;CAAkB;AAAyB,CAAC;;AAEtH,MAAM,sBAA8C,GACjD,4BAA4B,wBAC/B;;;;;;;;AASA,SAAgB,uBAAuB,SAAyB;CAC9D,IAAI,aAAa;CACjB,MAAM,qBAAqB,WAAW,WAAW,aAAa,IAAI,WAAW,MAAM,KAAK,CAAC,CAAC,CAAC,KAAK,KAAA;CAChG,IAAI,sBAAsB,uCAAuC,IAAI,kBAAkB,GACrF,aAAa,WAAW,MAAM,EAAoB;CAEpD,MAAM,QAAQ,WAAW,QAAQ,GAAG;CACpC,MAAM,aAAa,QAAQ,IAAI,WAAW,MAAM,GAAG,KAAK,IAAI,KAAA;CAC5D,MAAM,cAAc,aAAa,oBAAoB,cAAc,KAAA;CACnE,OAAO,cAAc,GAAG,cAAc,WAAW,MAAM,KAAK,MAAM;AACpE;;AAGA,SAAgB,wBAAwB,YAA4B;CAClE,IAAI,eAAe,UAAU,OAAO;CACpC,IAAI,eAAA,qBAAwC,OAAO;CACnD,OAAO;AACT;AAEA,SAAgB,8BAA8B,SAAyB;CACrE,MAAM,oBAAoB,yBAAyB,OAAO;CAE1D,IAAI,CAAC,kBAAkB,WAAA,SAAwB,GAC7C,OAAO;CAGT,MAAM,gBAAgB,kBAAkB,UAAU,CAAoB;CAEtE,IAAI,cAAc,SAAS,QAAQ,GACjC,OAAO;CAGT,MAAM,eAAe,0BAA0B;CAC/C,IAAI,CAAC,cACH,OAAO;CAGT,MAAM,kBAAkB,GAAG,gBAAgB;CAC3C,OAAO,QAAQ,WAAA,SAAgC,IAAI,GAAG,wBAAwB,oBAAoB;AACpG"}
@@ -1,10 +1,15 @@
1
1
  import { ModelRouterLanguageModel } from '@mastra/core/llm';
2
+ import { wrapLanguageModel } from 'ai';
2
3
  import type { JSONValue } from 'ai';
4
+ import type { ThinkingLevelSetting } from '../thinking.js';
3
5
  export interface ProviderThinkingOptions {
4
6
  optionsKey: string;
5
7
  options: Record<string, JSONValue>;
6
8
  controlKeys: ReadonlySet<string>;
7
9
  }
10
+ export declare function providerThinkingOptions(routedModelId: string, level: ThinkingLevelSetting | undefined): ProviderThinkingOptions | undefined;
11
+ type AiSdkLanguageModel = Parameters<typeof wrapLanguageModel>[0]['model'];
12
+ export declare function withThinkingOptionsModel(model: AiSdkLanguageModel, thinking: ProviderThinkingOptions | undefined): AiSdkLanguageModel;
8
13
  type RouterConfig = ConstructorParameters<typeof ModelRouterLanguageModel>[0];
9
14
  type RouterCallOptions = Parameters<ModelRouterLanguageModel['doStream']>[0];
10
15
  type RouterCallResult = ReturnType<ModelRouterLanguageModel['doStream']>;
@@ -1 +1 @@
1
- {"version":3,"file":"provider-thinking.d.ts","sourceRoot":"","sources":["../../src/providers/provider-thinking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAIpC,MAAM,WAAW,uBAAuB;IACtC,UAAU,EAA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AU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AAE3E,wBAAgB,wBAAwB,CACtC,KAAK,EAAE,kBAAkB,EACzB,QAAQ,EAAE,uBAAuB,GAAG,SAAS,GAC5C,kBAAkB,CASpB;AAED,KAAK,YAAY,GAAG,qBAAqB,CAAC,OAAO,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E,KAAK,iBAAiB,GAAG,UAAU,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7E,KAAK,gBAAgB,GAAG,UAAU,CAAC,wBAAwB,CAAC,UAAU,CAAC,CAAC,CAAC;AAEzE,qBAAa,oCAAqC,SAAQ,wBAAwB;;gBAGpE,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,uBAAuB,GAAG,SAAS;IAKtE,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB;IAIxD,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB;CAGhE"}
@@ -1,5 +1,25 @@
1
- import { ModelRouterLanguageModel } from "@mastra/core/llm";
1
+ import { thinkingRequestFormatFor } from "./thinking-request.js";
2
+ import { requestableReasoningOptions, runThinkingLevel } from "../thinking.js";
3
+ import { ModelRouterLanguageModel, getModelReasoningOptions } from "@mastra/core/llm";
4
+ import { wrapLanguageModel } from "ai";
2
5
  //#region src/providers/provider-thinking.ts
6
+ function providerThinkingOptions(routedModelId, level) {
7
+ const format = thinkingRequestFormatFor(routedModelId);
8
+ if (!format || !level) return void 0;
9
+ const catalogOptions = getModelReasoningOptions(routedModelId);
10
+ const requestable = requestableReasoningOptions(routedModelId, catalogOptions);
11
+ const runLevel = runThinkingLevel(routedModelId, level, catalogOptions);
12
+ if (!requestable?.length || runLevel === "off") return void 0;
13
+ const effortOptions = format.sendEffort?.(runLevel);
14
+ const options = requestable.some((option) => option.type === "effort") ? effortOptions : format.enableThinking;
15
+ if (!options) return void 0;
16
+ const controlKeys = /* @__PURE__ */ new Set([...Object.keys(effortOptions ?? {}), ...Object.keys(format.enableThinking ?? {})]);
17
+ return {
18
+ optionsKey: format.optionsKey,
19
+ options,
20
+ controlKeys
21
+ };
22
+ }
3
23
  function withThinkingOptions(callOptions, thinking) {
4
24
  if (!thinking) return callOptions;
5
25
  const callerOptions = callOptions.providerOptions?.[thinking.optionsKey] ?? {};
@@ -15,6 +35,16 @@ function withThinkingOptions(callOptions, thinking) {
15
35
  }
16
36
  };
17
37
  }
38
+ function withThinkingOptionsModel(model, thinking) {
39
+ if (!thinking) return model;
40
+ return wrapLanguageModel({
41
+ model,
42
+ middleware: {
43
+ specificationVersion: "v3",
44
+ transformParams: async ({ params }) => withThinkingOptions(params, thinking)
45
+ }
46
+ });
47
+ }
18
48
  var ModelRouterLanguageModelWithThinking = class extends ModelRouterLanguageModel {
19
49
  #thinking;
20
50
  constructor(config, thinking) {
@@ -29,6 +59,6 @@ var ModelRouterLanguageModelWithThinking = class extends ModelRouterLanguageMode
29
59
  }
30
60
  };
31
61
  //#endregion
32
- export { ModelRouterLanguageModelWithThinking };
62
+ export { ModelRouterLanguageModelWithThinking, providerThinkingOptions, withThinkingOptionsModel };
33
63
 
34
64
  //# sourceMappingURL=provider-thinking.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider-thinking.js","names":["#thinking"],"sources":["../../src/providers/provider-thinking.ts"],"sourcesContent":["import { ModelRouterLanguageModel } from '@mastra/core/llm';\nimport type { JSONValue } from 'ai';\n\ntype ProviderOptions = Record<string, Record<string, JSONValue | undefined>>;\n\nexport interface ProviderThinkingOptions {\n optionsKey: string;\n options: Record<string, JSONValue>;\n controlKeys: ReadonlySet<string>;\n}\n\nfunction withThinkingOptions<CallOptions extends { providerOptions?: ProviderOptions }>(\n callOptions: CallOptions,\n thinking: ProviderThinkingOptions | undefined,\n): CallOptions {\n if (!thinking) return callOptions;\n const callerOptions = callOptions.providerOptions?.[thinking.optionsKey] ?? {};\n const callerSetThinking = Object.keys(callerOptions).some(key => thinking.controlKeys.has(key));\n if (callerSetThinking) return callOptions;\n return {\n ...callOptions,\n providerOptions: {\n ...callOptions.providerOptions,\n [thinking.optionsKey]: { ...callerOptions, ...thinking.options },\n },\n };\n}\n\ntype RouterConfig = ConstructorParameters<typeof ModelRouterLanguageModel>[0];\ntype RouterCallOptions = Parameters<ModelRouterLanguageModel['doStream']>[0];\ntype RouterCallResult = ReturnType<ModelRouterLanguageModel['doStream']>;\n\nexport class ModelRouterLanguageModelWithThinking extends ModelRouterLanguageModel {\n readonly #thinking: ProviderThinkingOptions | undefined;\n\n constructor(config: RouterConfig, thinking: ProviderThinkingOptions | undefined) {\n super(config);\n this.#thinking = thinking;\n }\n\n override doGenerate(options: RouterCallOptions): RouterCallResult {\n return super.doGenerate(withThinkingOptions(options, this.#thinking));\n }\n\n override doStream(options: RouterCallOptions): RouterCallResult {\n return super.doStream(withThinkingOptions(options, this.#thinking));\n }\n}\n"],"mappings":";;AAWA,SAAS,oBACP,aACA,UACa;CACb,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,gBAAgB,YAAY,kBAAkB,SAAS,eAAe,CAAC;CAE7E,IAD0B,OAAO,KAAK,aAAa,CAAC,CAAC,MAAK,QAAO,SAAS,YAAY,IAAI,GAAG,CACzE,GAAG,OAAO;CAC9B,OAAO;EACL,GAAG;EACH,iBAAiB;GACf,GAAG,YAAY;IACd,SAAS,aAAa;IAAE,GAAG;IAAe,GAAG,SAAS;GAAQ;EACjE;CACF;AACF;AAMA,IAAa,uCAAb,cAA0D,yBAAyB;CACjF;CAEA,YAAY,QAAsB,UAA+C;EAC/E,MAAM,MAAM;EACZ,KAAKA,YAAY;CACnB;CAEA,WAAoB,SAA8C;EAChE,OAAO,MAAM,WAAW,oBAAoB,SAAS,KAAKA,SAAS,CAAC;CACtE;CAEA,SAAkB,SAA8C;EAC9D,OAAO,MAAM,SAAS,oBAAoB,SAAS,KAAKA,SAAS,CAAC;CACpE;AACF"}
1
+ {"version":3,"file":"provider-thinking.js","names":["#thinking"],"sources":["../../src/providers/provider-thinking.ts"],"sourcesContent":["import { getModelReasoningOptions, ModelRouterLanguageModel } from '@mastra/core/llm';\nimport { wrapLanguageModel } from 'ai';\nimport type { JSONValue } from 'ai';\nimport { requestableReasoningOptions, runThinkingLevel } from '../thinking.js';\nimport type { ThinkingLevelSetting } from '../thinking.js';\nimport { thinkingRequestFormatFor } from './thinking-request.js';\n\ntype ProviderOptions = Record<string, Record<string, JSONValue | undefined>>;\n\nexport interface ProviderThinkingOptions {\n optionsKey: string;\n options: Record<string, JSONValue>;\n controlKeys: ReadonlySet<string>;\n}\n\nexport function providerThinkingOptions(\n routedModelId: string,\n level: ThinkingLevelSetting | undefined,\n): ProviderThinkingOptions | undefined {\n const format = thinkingRequestFormatFor(routedModelId);\n if (!format || !level) return undefined;\n const catalogOptions = getModelReasoningOptions(routedModelId);\n const requestable = requestableReasoningOptions(routedModelId, catalogOptions);\n const runLevel = runThinkingLevel(routedModelId, level, catalogOptions);\n if (!requestable?.length || runLevel === 'off') return undefined;\n const effortOptions = format.sendEffort?.(runLevel);\n const sendsEffort = requestable.some(option => option.type === 'effort');\n const options = sendsEffort ? effortOptions : format.enableThinking;\n if (!options) return undefined;\n const controlKeys = new Set([...Object.keys(effortOptions ?? {}), ...Object.keys(format.enableThinking ?? {})]);\n return { optionsKey: format.optionsKey, options, controlKeys };\n}\n\nfunction withThinkingOptions<CallOptions extends { providerOptions?: ProviderOptions }>(\n callOptions: CallOptions,\n thinking: ProviderThinkingOptions | undefined,\n): CallOptions {\n if (!thinking) return callOptions;\n const callerOptions = callOptions.providerOptions?.[thinking.optionsKey] ?? {};\n const callerSetThinking = Object.keys(callerOptions).some(key => thinking.controlKeys.has(key));\n if (callerSetThinking) return callOptions;\n return {\n ...callOptions,\n providerOptions: {\n ...callOptions.providerOptions,\n [thinking.optionsKey]: { ...callerOptions, ...thinking.options },\n },\n };\n}\n\ntype AiSdkLanguageModel = Parameters<typeof wrapLanguageModel>[0]['model'];\n\nexport function withThinkingOptionsModel(\n model: AiSdkLanguageModel,\n thinking: ProviderThinkingOptions | undefined,\n): AiSdkLanguageModel {\n if (!thinking) return model;\n return wrapLanguageModel({\n model,\n middleware: {\n specificationVersion: 'v3',\n transformParams: async ({ params }) => withThinkingOptions(params, thinking),\n },\n });\n}\n\ntype RouterConfig = ConstructorParameters<typeof ModelRouterLanguageModel>[0];\ntype RouterCallOptions = Parameters<ModelRouterLanguageModel['doStream']>[0];\ntype RouterCallResult = ReturnType<ModelRouterLanguageModel['doStream']>;\n\nexport class ModelRouterLanguageModelWithThinking extends ModelRouterLanguageModel {\n readonly #thinking: ProviderThinkingOptions | undefined;\n\n constructor(config: RouterConfig, thinking: ProviderThinkingOptions | undefined) {\n super(config);\n this.#thinking = thinking;\n }\n\n override doGenerate(options: RouterCallOptions): RouterCallResult {\n return super.doGenerate(withThinkingOptions(options, this.#thinking));\n }\n\n override doStream(options: RouterCallOptions): RouterCallResult {\n return super.doStream(withThinkingOptions(options, this.#thinking));\n }\n}\n"],"mappings":";;;;;AAeA,SAAgB,wBACd,eACA,OACqC;CACrC,MAAM,SAAS,yBAAyB,aAAa;CACrD,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,KAAA;CAC9B,MAAM,iBAAiB,yBAAyB,aAAa;CAC7D,MAAM,cAAc,4BAA4B,eAAe,cAAc;CAC7E,MAAM,WAAW,iBAAiB,eAAe,OAAO,cAAc;CACtE,IAAI,CAAC,aAAa,UAAU,aAAa,OAAO,OAAO,KAAA;CACvD,MAAM,gBAAgB,OAAO,aAAa,QAAQ;CAElD,MAAM,UADc,YAAY,MAAK,WAAU,OAAO,SAAS,QACrC,IAAI,gBAAgB,OAAO;CACrD,IAAI,CAAC,SAAS,OAAO,KAAA;CACrB,MAAM,8BAAc,IAAI,IAAI,CAAC,GAAG,OAAO,KAAK,iBAAiB,CAAC,CAAC,GAAG,GAAG,OAAO,KAAK,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC;CAC9G,OAAO;EAAE,YAAY,OAAO;EAAY;EAAS;CAAY;AAC/D;AAEA,SAAS,oBACP,aACA,UACa;CACb,IAAI,CAAC,UAAU,OAAO;CACtB,MAAM,gBAAgB,YAAY,kBAAkB,SAAS,eAAe,CAAC;CAE7E,IAD0B,OAAO,KAAK,aAAa,CAAC,CAAC,MAAK,QAAO,SAAS,YAAY,IAAI,GAAG,CACzE,GAAG,OAAO;CAC9B,OAAO;EACL,GAAG;EACH,iBAAiB;GACf,GAAG,YAAY;IACd,SAAS,aAAa;IAAE,GAAG;IAAe,GAAG,SAAS;GAAQ;EACjE;CACF;AACF;AAIA,SAAgB,yBACd,OACA,UACoB;CACpB,IAAI,CAAC,UAAU,OAAO;CACtB,OAAO,kBAAkB;EACvB;EACA,YAAY;GACV,sBAAsB;GACtB,iBAAiB,OAAO,EAAE,aAAa,oBAAoB,QAAQ,QAAQ;EAC7E;CACF,CAAC;AACH;AAMA,IAAa,uCAAb,cAA0D,yBAAyB;CACjF;CAEA,YAAY,QAAsB,UAA+C;EAC/E,MAAM,MAAM;EACZ,KAAKA,YAAY;CACnB;CAEA,WAAoB,SAA8C;EAChE,OAAO,MAAM,WAAW,oBAAoB,SAAS,KAAKA,SAAS,CAAC;CACtE;CAEA,SAAkB,SAA8C;EAC9D,OAAO,MAAM,SAAS,oBAAoB,SAAS,KAAKA,SAAS,CAAC;CACpE;AACF"}
@@ -0,0 +1,14 @@
1
+ import type { JSONValue } from 'ai';
2
+ import type { ActiveThinkingLevel } from '../thinking.js';
3
+ type ThinkingProviderOptions = Record<string, JSONValue>;
4
+ export interface ThinkingRequestFormat {
5
+ optionsKey: string;
6
+ sendEffort?: (effort: ActiveThinkingLevel) => ThinkingProviderOptions;
7
+ acceptedEfforts?: readonly ActiveThinkingLevel[];
8
+ enableThinking?: ThinkingProviderOptions;
9
+ }
10
+ export declare function isThinkingAdapterProvider(provider: string): boolean;
11
+ export declare function isRoutedWithoutThinking(modelId: string): boolean;
12
+ export declare function thinkingRequestFormatFor(modelId: string): ThinkingRequestFormat | undefined;
13
+ export {};
14
+ //# sourceMappingURL=thinking-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking-request.d.ts","sourceRoot":"","sources":["../../src/providers/thinking-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D,KAAK,uBAAuB,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAEzD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,uBAAuB,CAAC;IACtE,eAAe,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IACjD,cAAc,CAAC,EAAE,uBAAuB,CAAC;CAC1C;AAyCD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEnE;AASD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAGhE;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAM3F"}
@@ -0,0 +1,90 @@
1
+ import { MASTRA_GATEWAY_PREFIX, stripMastraGatewayPrefix } from "./model-ids.js";
2
+ //#region src/providers/thinking-request.ts
3
+ const LOW_TO_HIGH = [
4
+ "low",
5
+ "medium",
6
+ "high"
7
+ ];
8
+ const sendReasoningEffort = (reasoningEffort) => ({ reasoningEffort });
9
+ const ENABLE_REASONING = { reasoning: { enabled: true } };
10
+ const OPENROUTER_FORMAT = {
11
+ optionsKey: "openrouter",
12
+ sendEffort: (effort) => ({ reasoning: { effort } }),
13
+ enableThinking: ENABLE_REASONING
14
+ };
15
+ const REQUEST_FORMATS_BY_PROVIDER = {
16
+ deepseek: {
17
+ optionsKey: "deepseek",
18
+ sendEffort: sendReasoningEffort,
19
+ enableThinking: { thinking: { type: "enabled" } }
20
+ },
21
+ openrouter: OPENROUTER_FORMAT,
22
+ alibaba: {
23
+ optionsKey: "alibaba",
24
+ enableThinking: { enableThinking: true }
25
+ },
26
+ groq: {
27
+ optionsKey: "groq",
28
+ sendEffort: sendReasoningEffort,
29
+ acceptedEfforts: LOW_TO_HIGH
30
+ },
31
+ mistral: {
32
+ optionsKey: "mistral",
33
+ sendEffort: sendReasoningEffort,
34
+ acceptedEfforts: ["high"]
35
+ },
36
+ xai: {
37
+ optionsKey: "xai",
38
+ sendEffort: sendReasoningEffort,
39
+ acceptedEfforts: LOW_TO_HIGH
40
+ },
41
+ togetherai: {
42
+ optionsKey: "togetherai",
43
+ sendEffort: sendReasoningEffort,
44
+ acceptedEfforts: LOW_TO_HIGH,
45
+ enableThinking: ENABLE_REASONING
46
+ },
47
+ deepinfra: {
48
+ optionsKey: "deepinfra",
49
+ sendEffort: sendReasoningEffort,
50
+ acceptedEfforts: LOW_TO_HIGH,
51
+ enableThinking: ENABLE_REASONING
52
+ },
53
+ cerebras: {
54
+ optionsKey: "cerebras",
55
+ sendEffort: sendReasoningEffort
56
+ },
57
+ perplexity: {
58
+ optionsKey: "perplexity",
59
+ sendEffort: (effort) => ({ reasoning_effort: effort })
60
+ }
61
+ };
62
+ const THINKING_ADAPTER_PROVIDERS = /* @__PURE__ */ new Set([
63
+ "anthropic",
64
+ "openai",
65
+ "google"
66
+ ]);
67
+ function isThinkingAdapterProvider(provider) {
68
+ return THINKING_ADAPTER_PROVIDERS.has(provider);
69
+ }
70
+ const PROVIDERS_ROUTED_WITHOUT_THINKING = /* @__PURE__ */ new Set([
71
+ "github-copilot",
72
+ "kimi-for-coding",
73
+ "moonshotai",
74
+ "amazon-bedrock"
75
+ ]);
76
+ function isRoutedWithoutThinking(modelId) {
77
+ const [provider = ""] = stripMastraGatewayPrefix(modelId).split("/");
78
+ return PROVIDERS_ROUTED_WITHOUT_THINKING.has(provider);
79
+ }
80
+ function thinkingRequestFormatFor(modelId) {
81
+ const routedThroughMastraGateway = modelId.startsWith(MASTRA_GATEWAY_PREFIX);
82
+ const [provider = ""] = stripMastraGatewayPrefix(modelId).split("/");
83
+ if (isThinkingAdapterProvider(provider)) return void 0;
84
+ if (routedThroughMastraGateway) return OPENROUTER_FORMAT;
85
+ return REQUEST_FORMATS_BY_PROVIDER[provider.includes("alibaba") ? "alibaba" : provider];
86
+ }
87
+ //#endregion
88
+ export { isRoutedWithoutThinking, isThinkingAdapterProvider, thinkingRequestFormatFor };
89
+
90
+ //# sourceMappingURL=thinking-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thinking-request.js","names":[],"sources":["../../src/providers/thinking-request.ts"],"sourcesContent":["import type { JSONValue } from 'ai';\nimport type { ActiveThinkingLevel } from '../thinking.js';\nimport { MASTRA_GATEWAY_PREFIX, stripMastraGatewayPrefix } from './model-ids.js';\n\ntype ThinkingProviderOptions = Record<string, JSONValue>;\n\nexport interface ThinkingRequestFormat {\n optionsKey: string;\n sendEffort?: (effort: ActiveThinkingLevel) => ThinkingProviderOptions;\n acceptedEfforts?: readonly ActiveThinkingLevel[];\n enableThinking?: ThinkingProviderOptions;\n}\n\nconst LOW_TO_HIGH: readonly ActiveThinkingLevel[] = ['low', 'medium', 'high'];\nconst sendReasoningEffort = (reasoningEffort: ActiveThinkingLevel): ThinkingProviderOptions => ({ reasoningEffort });\nconst ENABLE_REASONING: ThinkingProviderOptions = { reasoning: { enabled: true } };\n\nconst OPENROUTER_FORMAT: ThinkingRequestFormat = {\n optionsKey: 'openrouter',\n sendEffort: effort => ({ reasoning: { effort } }),\n enableThinking: ENABLE_REASONING,\n};\n\nconst REQUEST_FORMATS_BY_PROVIDER: Partial<Record<string, ThinkingRequestFormat>> = {\n deepseek: {\n optionsKey: 'deepseek',\n sendEffort: sendReasoningEffort,\n enableThinking: { thinking: { type: 'enabled' } },\n },\n openrouter: OPENROUTER_FORMAT,\n alibaba: { optionsKey: 'alibaba', enableThinking: { enableThinking: true } },\n groq: { optionsKey: 'groq', sendEffort: sendReasoningEffort, acceptedEfforts: LOW_TO_HIGH },\n mistral: { optionsKey: 'mistral', sendEffort: sendReasoningEffort, acceptedEfforts: ['high'] },\n xai: { optionsKey: 'xai', sendEffort: sendReasoningEffort, acceptedEfforts: LOW_TO_HIGH },\n togetherai: {\n optionsKey: 'togetherai',\n sendEffort: sendReasoningEffort,\n acceptedEfforts: LOW_TO_HIGH,\n enableThinking: ENABLE_REASONING,\n },\n deepinfra: {\n optionsKey: 'deepinfra',\n sendEffort: sendReasoningEffort,\n acceptedEfforts: LOW_TO_HIGH,\n enableThinking: ENABLE_REASONING,\n },\n cerebras: { optionsKey: 'cerebras', sendEffort: sendReasoningEffort },\n perplexity: { optionsKey: 'perplexity', sendEffort: effort => ({ reasoning_effort: effort }) },\n};\n\nconst THINKING_ADAPTER_PROVIDERS: ReadonlySet<string> = new Set(['anthropic', 'openai', 'google']);\n\nexport function isThinkingAdapterProvider(provider: string): boolean {\n return THINKING_ADAPTER_PROVIDERS.has(provider);\n}\n\nconst PROVIDERS_ROUTED_WITHOUT_THINKING: ReadonlySet<string> = new Set([\n 'github-copilot',\n 'kimi-for-coding',\n 'moonshotai',\n 'amazon-bedrock',\n]);\n\nexport function isRoutedWithoutThinking(modelId: string): boolean {\n const [provider = ''] = stripMastraGatewayPrefix(modelId).split('/');\n return PROVIDERS_ROUTED_WITHOUT_THINKING.has(provider);\n}\n\nexport function thinkingRequestFormatFor(modelId: string): ThinkingRequestFormat | undefined {\n const routedThroughMastraGateway = modelId.startsWith(MASTRA_GATEWAY_PREFIX);\n const [provider = ''] = stripMastraGatewayPrefix(modelId).split('/');\n if (isThinkingAdapterProvider(provider)) return undefined;\n if (routedThroughMastraGateway) return OPENROUTER_FORMAT;\n return REQUEST_FORMATS_BY_PROVIDER[provider.includes('alibaba') ? 'alibaba' : provider];\n}\n"],"mappings":";;AAaA,M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AAoD;CAC3F,MAAM,6BAA6B,QAAQ,WAAW,qBAAqB;CAC3E,MAAM,CAAC,WAAW,MAAM,yBAAyB,OAAO,CAAC,CAAC,MAAM,GAAG;CACnE,IAAI,0BAA0B,QAAQ,GAAG,OAAO,KAAA;CAChD,IAAI,4BAA4B,OAAO;CACvC,OAAO,4BAA4B,SAAS,SAAS,SAAS,IAAI,YAAY;AAChF"}
@@ -7,7 +7,7 @@
7
7
  * into `https://api.x.ai/v1` with a custom fetch that injects the (auto-refreshed)
8
8
  * access token.
9
9
  */
10
- import type { MastraModelConfig } from '@mastra/core/llm';
10
+ import type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
11
11
  import { AuthStorage } from '../auth/storage.js';
12
12
  import type { CredentialStore } from '../auth/types.js';
13
13
  /** Get or create the shared AuthStorage instance. */
@@ -29,5 +29,5 @@ export declare function buildXAIOAuthFetch(opts?: {
29
29
  export declare function xaiProvider(modelId: string, options?: {
30
30
  headers?: Record<string, string>;
31
31
  authStorage?: CredentialStore;
32
- }): MastraModelConfig;
32
+ }): ReturnType<OpenAICompatibleProvider['chatModel']>;
33
33
  //# sourceMappingURL=xai.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAE1D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAQxD,qDAAqD;AACrD,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAErE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAO,GAAG,OAAO,KAAK,CAsC7F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,WAAW,CAAC,EAAE,eAAe,CAAA;CAAE,GAC5E,iBAAiB,CASnB"}
1
+ {"version":3,"file":"xai.d.ts","sourceRoot":"","sources":["../../src/providers/xai.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAQxD,qDAAqD;AACrD,wBAAgB,cAAc,IAAI,WAAW,CAK5C;AAED,8EAA8E;AAC9E,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAErE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,GAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAO,GAAG,OAAO,KAAK,CAsC7F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,WAAW,CAAC,EAAE,eAAe,CAAA;CAAE,GAC5E,UAAU,CAAC,wBAAwB,CAAC,WAAW,CAAC,CAAC,CASnD"}
@@ -1 +1 @@
1
- {"version":3,"file":"xai.js","names":[],"sources":["../../src/providers/xai.ts"],"sourcesContent":["/**\n * xAI (Grok) OAuth Provider\n *\n * Uses OAuth tokens from AuthStorage to authenticate with the xAI API.\n * The xAI API speaks an OpenAI-compatible chat format, and the OAuth access\n * token is accepted as a bearer API key, so we plug `@ai-sdk/openai-compatible`\n * into `https://api.x.ai/v1` with a custom fetch that injects the (auto-refreshed)\n * access token.\n */\n\nimport { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { MastraModelConfig } from '@mastra/core/llm';\nimport { ProviderAuthRequiredError } from '../auth/provider-auth-error.js';\nimport { AuthStorage } from '../auth/storage.js';\nimport type { CredentialStore } from '../auth/types.js';\n\nconst XAI_PROVIDER_ID = 'xai';\nconst XAI_BASE_URL = 'https://api.x.ai/v1';\n\n// Singleton auth storage instance (shared with claude-max.ts / github-copilot.ts when not overridden).\nlet authStorageInstance: AuthStorage | null = null;\n\n/** Get or create the shared AuthStorage instance. */\nexport function getAuthStorage(): AuthStorage {\n if (!authStorageInstance) {\n authStorageInstance = new AuthStorage();\n }\n return authStorageInstance;\n}\n\n/** Set a custom AuthStorage instance (useful for tests / TUI integration). */\nexport function setAuthStorage(storage: AuthStorage | undefined): void {\n authStorageInstance = storage ?? null;\n}\n\n/**\n * Build a fetch wrapper that authenticates with xAI OAuth.\n * Injects the access token (auto-refreshed by AuthStorage) as a bearer token,\n * preserving non-auth headers from the caller.\n */\nexport function buildXAIOAuthFetch(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 cred = storage.get(XAI_PROVIDER_ID);\n if (!cred || cred.type !== 'oauth') {\n throw new ProviderAuthRequiredError('Not logged in to xAI.');\n }\n\n // getApiKey() refreshes the access token if it has expired.\n const accessToken = await storage.getApiKey(XAI_PROVIDER_ID);\n if (!accessToken) {\n throw new ProviderAuthRequiredError('Failed to refresh the xAI token.');\n }\n\n // Preserve existing headers, strip auth-related ones. Explicit init\n // headers override headers carried by an incoming Request.\n const headers = new Headers(url instanceof Request ? url.headers : undefined);\n if (init?.headers) {\n new Headers(init.headers).forEach((value, key) => headers.set(key, value));\n }\n headers.delete('authorization');\n headers.delete('x-api-key');\n\n headers.set('Authorization', `Bearer ${accessToken}`);\n\n try {\n return await fetch(url, { ...init, headers });\n } catch (error) {\n if (error && typeof error === 'object') {\n Object.assign(error as Record<string, unknown>, {\n requestUrl: url instanceof URL ? url.toString() : typeof url === 'string' ? url : (url as Request).url,\n });\n }\n throw error;\n }\n }) as typeof fetch;\n}\n\n/**\n * Creates an xAI model using OAuth authentication.\n * Uses OAuth tokens from AuthStorage (auto-refreshes when needed).\n */\nexport function xaiProvider(\n modelId: string,\n options?: { headers?: Record<string, string>; authStorage?: CredentialStore },\n): MastraModelConfig {\n const provider = createOpenAICompatible({\n name: XAI_PROVIDER_ID,\n baseURL: XAI_BASE_URL,\n apiKey: 'oauth-placeholder', // real auth injected by the custom fetch\n headers: options?.headers,\n fetch: buildXAIOAuthFetch({ authStorage: options?.authStorage }),\n });\n return provider.chatModel(modelId);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,kBAAkB;AACxB,MAAM,eAAe;AAGrB,IAAI,sBAA0C;;AAG9C,SAAgB,iBAA8B;CAC5C,IAAI,CAAC,qBACH,sBAAsB,IAAI,YAAY;CAExC,OAAO;AACT;;AAGA,SAAgB,eAAe,SAAwC;CACrE,sBAAsB,WAAW;AACnC;;;;;;AAOA,SAAgB,mBAAmB,OAA0C,CAAC,GAAiB;CAC7F,QAAQ,OAAO,KAA6B,SAAuC;EACjF,MAAM,UAAU,KAAK,eAAe,eAAe;EACnD,QAAQ,OAAO;EAEf,MAAM,OAAO,QAAQ,IAAI,eAAe;EACxC,IAAI,CAAC,QAAQ,KAAK,SAAS,SACzB,MAAM,IAAI,0BAA0B,uBAAuB;EAI7D,MAAM,cAAc,MAAM,QAAQ,UAAU,eAAe;EAC3D,IAAI,CAAC,aACH,MAAM,IAAI,0BAA0B,kCAAkC;EAKxE,MAAM,UAAU,IAAI,QAAQ,eAAe,UAAU,IAAI,UAAU,KAAA,CAAS;EAC5E,IAAI,MAAM,SACR,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,OAAO,QAAQ,QAAQ,IAAI,KAAK,KAAK,CAAC;EAE3E,QAAQ,OAAO,eAAe;EAC9B,QAAQ,OAAO,WAAW;EAE1B,QAAQ,IAAI,iBAAiB,UAAU,aAAa;EAEpD,IAAI;GACF,OAAO,MAAM,MAAM,KAAK;IAAE,GAAG;IAAM;GAAQ,CAAC;EAC9C,SAAS,OAAO;GACd,IAAI,SAAS,OAAO,UAAU,UAC5B,OAAO,OAAO,OAAkC,EAC9C,YAAY,eAAe,MAAM,IAAI,SAAS,IAAI,OAAO,QAAQ,WAAW,MAAO,IAAgB,IACrG,CAAC;GAEH,MAAM;EACR;CACF;AACF;;;;;AAMA,SAAgB,YACd,SACA,SACmB;CAQnB,OAPiB,uBAAuB;EACtC,MAAM;EACN,SAAS;EACT,QAAQ;EACR,SAAS,SAAS;EAClB,OAAO,mBAAmB,EAAE,aAAa,SAAS,YAAY,CAAC;CACjE,CACc,CAAC,CAAC,UAAU,OAAO;AACnC"}
1
+ {"version":3,"file":"xai.js","names":[],"sources":["../../src/providers/xai.ts"],"sourcesContent":["/**\n * xAI (Grok) OAuth Provider\n *\n * Uses OAuth tokens from AuthStorage to authenticate with the xAI API.\n * The xAI API speaks an OpenAI-compatible chat format, and the OAuth access\n * token is accepted as a bearer API key, so we plug `@ai-sdk/openai-compatible`\n * into `https://api.x.ai/v1` with a custom fetch that injects the (auto-refreshed)\n * access token.\n */\n\nimport { createOpenAICompatible } from '@ai-sdk/openai-compatible';\nimport type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';\nimport { ProviderAuthRequiredError } from '../auth/provider-auth-error.js';\nimport { AuthStorage } from '../auth/storage.js';\nimport type { CredentialStore } from '../auth/types.js';\n\nconst XAI_PROVIDER_ID = 'xai';\nconst XAI_BASE_URL = 'https://api.x.ai/v1';\n\n// Singleton auth storage instance (shared with claude-max.ts / github-copilot.ts when not overridden).\nlet authStorageInstance: AuthStorage | null = null;\n\n/** Get or create the shared AuthStorage instance. */\nexport function getAuthStorage(): AuthStorage {\n if (!authStorageInstance) {\n authStorageInstance = new AuthStorage();\n }\n return authStorageInstance;\n}\n\n/** Set a custom AuthStorage instance (useful for tests / TUI integration). */\nexport function setAuthStorage(storage: AuthStorage | undefined): void {\n authStorageInstance = storage ?? null;\n}\n\n/**\n * Build a fetch wrapper that authenticates with xAI OAuth.\n * Injects the access token (auto-refreshed by AuthStorage) as a bearer token,\n * preserving non-auth headers from the caller.\n */\nexport function buildXAIOAuthFetch(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 cred = storage.get(XAI_PROVIDER_ID);\n if (!cred || cred.type !== 'oauth') {\n throw new ProviderAuthRequiredError('Not logged in to xAI.');\n }\n\n // getApiKey() refreshes the access token if it has expired.\n const accessToken = await storage.getApiKey(XAI_PROVIDER_ID);\n if (!accessToken) {\n throw new ProviderAuthRequiredError('Failed to refresh the xAI token.');\n }\n\n // Preserve existing headers, strip auth-related ones. Explicit init\n // headers override headers carried by an incoming Request.\n const headers = new Headers(url instanceof Request ? url.headers : undefined);\n if (init?.headers) {\n new Headers(init.headers).forEach((value, key) => headers.set(key, value));\n }\n headers.delete('authorization');\n headers.delete('x-api-key');\n\n headers.set('Authorization', `Bearer ${accessToken}`);\n\n try {\n return await fetch(url, { ...init, headers });\n } catch (error) {\n if (error && typeof error === 'object') {\n Object.assign(error as Record<string, unknown>, {\n requestUrl: url instanceof URL ? url.toString() : typeof url === 'string' ? url : (url as Request).url,\n });\n }\n throw error;\n }\n }) as typeof fetch;\n}\n\n/**\n * Creates an xAI model using OAuth authentication.\n * Uses OAuth tokens from AuthStorage (auto-refreshes when needed).\n */\nexport function xaiProvider(\n modelId: string,\n options?: { headers?: Record<string, string>; authStorage?: CredentialStore },\n): ReturnType<OpenAICompatibleProvider['chatModel']> {\n const provider = createOpenAICompatible({\n name: XAI_PROVIDER_ID,\n baseURL: XAI_BASE_URL,\n apiKey: 'oauth-placeholder', // real auth injected by the custom fetch\n headers: options?.headers,\n fetch: buildXAIOAuthFetch({ authStorage: options?.authStorage }),\n });\n return provider.chatModel(modelId);\n}\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAM,kBAAkB;AACxB,MAAM,eAAe;AAGrB,IAAI,sBAA0C;;AAG9C,SAAgB,iBAA8B;CAC5C,IAAI,CAAC,qBACH,sBAAsB,IAAI,YAAY;CAExC,OAAO;AACT;;AAGA,SAAgB,eAAe,SAAwC;CACrE,sBAAsB,WAAW;AACnC;;;;;;AAOA,SAAgB,mBAAmB,OAA0C,CAAC,GAAiB;CAC7F,QAAQ,OAAO,KAA6B,SAAuC;EACjF,MAAM,UAAU,KAAK,eAAe,eAAe;EACnD,QAAQ,OAAO;EAEf,MAAM,OAAO,QAAQ,IAAI,eAAe;EACxC,IAAI,CAAC,QAAQ,KAAK,SAAS,SACzB,MAAM,IAAI,0BAA0B,uBAAuB;EAI7D,MAAM,cAAc,MAAM,QAAQ,UAAU,eAAe;EAC3D,IAAI,CAAC,aACH,MAAM,IAAI,0BAA0B,kCAAkC;EAKxE,MAAM,UAAU,IAAI,QAAQ,eAAe,UAAU,IAAI,UAAU,KAAA,CAAS;EAC5E,IAAI,MAAM,SACR,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,SAAS,OAAO,QAAQ,QAAQ,IAAI,KAAK,KAAK,CAAC;EAE3E,QAAQ,OAAO,eAAe;EAC9B,QAAQ,OAAO,WAAW;EAE1B,QAAQ,IAAI,iBAAiB,UAAU,aAAa;EAEpD,IAAI;GACF,OAAO,MAAM,MAAM,KAAK;IAAE,GAAG;IAAM;GAAQ,CAAC;EAC9C,SAAS,OAAO;GACd,IAAI,SAAS,OAAO,UAAU,UAC5B,OAAO,OAAO,OAAkC,EAC9C,YAAY,eAAe,MAAM,IAAI,SAAS,IAAI,OAAO,QAAQ,WAAW,MAAO,IAAgB,IACrG,CAAC;GAEH,MAAM;EACR;CACF;AACF;;;;;AAMA,SAAgB,YACd,SACA,SACmD;CAQnD,OAPiB,uBAAuB;EACtC,MAAM;EACN,SAAS;EACT,QAAQ;EACR,SAAS,SAAS;EAClB,OAAO,mBAAmB,EAAE,aAAa,SAAS,YAAY,CAAC;CACjE,CACc,CAAC,CAAC,UAAU,OAAO;AACnC"}
@@ -26,6 +26,7 @@ export type ThinkCommandAction = {
26
26
  };
27
27
  export declare function isThinkingLevelSetting(value: unknown): value is ThinkingLevelSetting;
28
28
  export declare function supportsMaxReasoningEffort(modelId: string): boolean;
29
+ export declare function requestableReasoningOptions(modelId: string, reasoningOptions: readonly ModelReasoningOption[] | undefined): readonly ModelReasoningOption[] | undefined;
29
30
  export declare function runThinkingLevel(modelId: string, level: ThinkingLevelSetting, reasoningOptions: readonly ModelReasoningOption[] | undefined): ThinkingLevelSetting;
30
31
  export declare function getAvailableThinkingLevelsForModel(modelId: string, reasoningOptions?: readonly ModelReasoningOption[]): ThinkingLevelSetting[];
31
32
  export declare function parseThinkCommand(input: string, levels?: readonly ThinkingLevelSetting[]): ThinkCommandAction;
@@ -1 +1 @@
1
- {"version":3,"file":"thinking.d.ts","sourceRoot":"","sources":["../src/thinking.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAS7D,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAEvF,MAAM,MAAM,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;AAEvE,MAAM,MAAM,mBAAmB,GAAG,cAAc,GAAG,QAAQ,CAAC;AAE5D,MAAM,WAAW,gBAAgB;IAC/B,aAAa,EAAE,oBAAoB,CAAC;IACpC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC;CAC9D;AAED,eAAO,MAAM,qBA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