@mastra/ai-sdk 1.1.4 → 1.2.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 (42) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +28 -5
  3. package/dist/_types/@internal_ai-v6/dist/index.d.ts +13493 -0
  4. package/dist/chat-route.d.ts +21 -6
  5. package/dist/chat-route.d.ts.map +1 -1
  6. package/dist/chunk-HDI4ZP7N.js +79 -0
  7. package/dist/chunk-HDI4ZP7N.js.map +1 -0
  8. package/dist/chunk-IV3RKEE4.js +439 -0
  9. package/dist/chunk-IV3RKEE4.js.map +1 -0
  10. package/dist/chunk-PEZAMDZJ.cjs +84 -0
  11. package/dist/chunk-PEZAMDZJ.cjs.map +1 -0
  12. package/dist/chunk-X72VW7EY.cjs +441 -0
  13. package/dist/chunk-X72VW7EY.cjs.map +1 -0
  14. package/dist/convert-streams.d.ts +44 -71
  15. package/dist/convert-streams.d.ts.map +1 -1
  16. package/dist/helpers.d.ts +16 -0
  17. package/dist/helpers.d.ts.map +1 -1
  18. package/dist/index.cjs +6840 -381
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +6839 -381
  23. package/dist/index.js.map +1 -1
  24. package/dist/middleware.d.ts +2 -0
  25. package/dist/middleware.d.ts.map +1 -1
  26. package/dist/network-route.d.ts +19 -9
  27. package/dist/network-route.d.ts.map +1 -1
  28. package/dist/public-types.d.ts +9 -0
  29. package/dist/public-types.d.ts.map +1 -0
  30. package/dist/token-APYSY3BW-CBIBV5F2.js +61 -0
  31. package/dist/token-APYSY3BW-CBIBV5F2.js.map +1 -0
  32. package/dist/token-APYSY3BW-M2K6HVOG.cjs +63 -0
  33. package/dist/token-APYSY3BW-M2K6HVOG.cjs.map +1 -0
  34. package/dist/token-util-RMHT2CPJ-3LCBPXJ6.cjs +10 -0
  35. package/dist/token-util-RMHT2CPJ-3LCBPXJ6.cjs.map +1 -0
  36. package/dist/token-util-RMHT2CPJ-IOKQM5O3.js +8 -0
  37. package/dist/token-util-RMHT2CPJ-IOKQM5O3.js.map +1 -0
  38. package/dist/transformers.d.ts +53 -4
  39. package/dist/transformers.d.ts.map +1 -1
  40. package/dist/workflow-route.d.ts +14 -4
  41. package/dist/workflow-route.d.ts.map +1 -1
  42. package/package.json +5 -4
@@ -1,22 +1,34 @@
1
- import type { InferUIMessageChunk, UIMessage } from './_types/@internal_ai-sdk-v5/dist/index.js';
1
+ import type { UIMessageStreamOptions as UIMessageStreamOptionsV5 } from './_types/@internal_ai-sdk-v5/dist/index.js';
2
+ import type { UIMessageStreamOptions as UIMessageStreamOptionsV6 } from './_types/@internal_ai-v6/dist/index.js';
2
3
  import type { AgentExecutionOptions } from '@mastra/core/agent';
3
4
  import type { Mastra } from '@mastra/core/mastra';
4
5
  import { registerApiRoute } from '@mastra/core/server';
5
- export type ChatStreamHandlerParams<UI_MESSAGE extends UIMessage, OUTPUT = undefined> = AgentExecutionOptions<OUTPUT> & {
6
+ import type { SupportedUIMessage, V5UIMessage, V5UIMessageStream, V6UIMessage, V6UIMessageStream } from './public-types.js';
7
+ export type ChatStreamHandlerParams<UI_MESSAGE extends SupportedUIMessage = SupportedUIMessage, OUTPUT = undefined> = AgentExecutionOptions<OUTPUT> & {
6
8
  messages: UI_MESSAGE[];
7
9
  resumeData?: Record<string, any>;
8
10
  /** The trigger for the request - sent by AI SDK's useChat hook */
9
11
  trigger?: 'submit-message' | 'regenerate-message';
10
12
  };
11
- export type ChatStreamHandlerOptions<UI_MESSAGE extends UIMessage, OUTPUT = undefined> = {
13
+ export type ChatStreamHandlerOptions<UI_MESSAGE extends SupportedUIMessage = SupportedUIMessage, OUTPUT = undefined> = {
12
14
  mastra: Mastra;
13
15
  agentId: string;
14
16
  params: ChatStreamHandlerParams<UI_MESSAGE, OUTPUT>;
15
17
  defaultOptions?: AgentExecutionOptions<OUTPUT>;
18
+ version?: 'v5' | 'v6';
16
19
  sendStart?: boolean;
17
20
  sendFinish?: boolean;
18
21
  sendReasoning?: boolean;
19
22
  sendSources?: boolean;
23
+ messageMetadata?: UI_MESSAGE extends V6UIMessage ? UIMessageStreamOptionsV6<UI_MESSAGE>['messageMetadata'] : UI_MESSAGE extends V5UIMessage ? UIMessageStreamOptionsV5<UI_MESSAGE>['messageMetadata'] : never;
24
+ };
25
+ type ChatStreamHandlerOptionsV5<UI_MESSAGE extends V5UIMessage = V5UIMessage, OUTPUT = undefined> = Omit<ChatStreamHandlerOptions<UI_MESSAGE, OUTPUT>, 'version' | 'messageMetadata'> & {
26
+ version?: 'v5';
27
+ messageMetadata?: UIMessageStreamOptionsV5<UI_MESSAGE>['messageMetadata'];
28
+ };
29
+ type ChatStreamHandlerOptionsV6<UI_MESSAGE extends V6UIMessage = V6UIMessage, OUTPUT = undefined> = Omit<ChatStreamHandlerOptions<UI_MESSAGE, OUTPUT>, 'version' | 'messageMetadata'> & {
30
+ version: 'v6';
31
+ messageMetadata?: UIMessageStreamOptionsV6<UI_MESSAGE>['messageMetadata'];
20
32
  };
21
33
  /**
22
34
  * Framework-agnostic handler for streaming agent chat in AI SDK-compatible format.
@@ -26,7 +38,7 @@ export type ChatStreamHandlerOptions<UI_MESSAGE extends UIMessage, OUTPUT = unde
26
38
  * ```ts
27
39
  * // Next.js App Router
28
40
  * import { handleChatStream } from '@mastra/ai-sdk';
29
- * import { createUIMessageStreamResponse } from '@internal/ai-sdk-v5';
41
+ * import { createUIMessageStreamResponse } from 'ai';
30
42
  * import { mastra } from '@/src/mastra';
31
43
  *
32
44
  * export async function POST(req: Request) {
@@ -40,9 +52,11 @@ export type ChatStreamHandlerOptions<UI_MESSAGE extends UIMessage, OUTPUT = unde
40
52
  * }
41
53
  * ```
42
54
  */
43
- export declare function handleChatStream<UI_MESSAGE extends UIMessage, OUTPUT = undefined>({ mastra, agentId, params, defaultOptions, sendStart, sendFinish, sendReasoning, sendSources, }: ChatStreamHandlerOptions<UI_MESSAGE, OUTPUT>): Promise<ReadableStream<InferUIMessageChunk<UI_MESSAGE>>>;
55
+ export declare function handleChatStream<UI_MESSAGE extends V5UIMessage = V5UIMessage, OUTPUT = undefined>(options: ChatStreamHandlerOptionsV5<UI_MESSAGE, OUTPUT>): Promise<V5UIMessageStream<UI_MESSAGE>>;
56
+ export declare function handleChatStream<UI_MESSAGE extends V6UIMessage = V6UIMessage, OUTPUT = undefined>(options: ChatStreamHandlerOptionsV6<UI_MESSAGE, OUTPUT>): Promise<V6UIMessageStream<UI_MESSAGE>>;
44
57
  export type chatRouteOptions<OUTPUT = undefined> = {
45
58
  defaultOptions?: AgentExecutionOptions<OUTPUT>;
59
+ version?: 'v5' | 'v6';
46
60
  } & ({
47
61
  path: `${string}:agentId${string}`;
48
62
  agent?: never;
@@ -98,5 +112,6 @@ export type chatRouteOptions<OUTPUT = undefined> = {
98
112
  * - If both `agent` and `:agentId` are present, a warning is logged and the fixed `agent` takes precedence
99
113
  * - Request context from the incoming request overrides `defaultOptions.requestContext` if both are present
100
114
  */
101
- export declare function chatRoute<OUTPUT = undefined>({ path, agent, defaultOptions, sendStart, sendFinish, sendReasoning, sendSources, }: chatRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
115
+ export declare function chatRoute<OUTPUT = undefined>({ path, agent, defaultOptions, version, sendStart, sendFinish, sendReasoning, sendSources, }: chatRouteOptions<OUTPUT>): ReturnType<typeof registerApiRoute>;
116
+ export {};
102
117
  //# sourceMappingURL=chat-route.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"chat-route.d.ts","sourceRoot":"","sources":["../src/chat-route.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,KAAK,EAAE,qBAAqB,EAA6B,MAAM,oBAAoB,CAAC;AAC3F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,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;;GA0CG;AACH,wBAAgB,SAAS,CAAC,MAAM,GAAG,SAAS,EAAE,EAC5C,IAAuB,EACvB,KAAK,EACL,cAAc,EACd,OAAc,EACd,SAAgB,EAChB,UAAiB,EACjB,aAAqB,EACrB,WAAmB,GACpB,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,gBAAgB,CAAC,CA0KhE"}
@@ -0,0 +1,79 @@
1
+ import { __require } from './chunk-DGUM43GV.js';
2
+
3
+ // ../../packages/_vendored/ai_v6/dist/chunk-7D4SUZUM.js
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __require2 = /* @__PURE__ */ ((x) => typeof __require !== "undefined" ? __require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
+ get: (a, b) => (typeof __require !== "undefined" ? __require : a)[b]
12
+ }) : x)(function(x) {
13
+ if (typeof __require !== "undefined") return __require.apply(this, arguments);
14
+ throw Error('Dynamic require of "' + x + '" is not supported');
15
+ });
16
+ var __commonJS = (cb, mod) => function __require22() {
17
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+
36
+ // ../../packages/_vendored/ai_v6/dist/chunk-QOME2VME.js
37
+ var require_token_error = __commonJS({
38
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-error.js"(exports$1, module) {
39
+ var __defProp2 = Object.defineProperty;
40
+ var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
41
+ var __getOwnPropNames2 = Object.getOwnPropertyNames;
42
+ var __hasOwnProp2 = Object.prototype.hasOwnProperty;
43
+ var __export = (target, all) => {
44
+ for (var name in all)
45
+ __defProp2(target, name, { get: all[name], enumerable: true });
46
+ };
47
+ var __copyProps2 = (to, from, except, desc) => {
48
+ if (from && typeof from === "object" || typeof from === "function") {
49
+ for (let key of __getOwnPropNames2(from))
50
+ if (!__hasOwnProp2.call(to, key) && key !== except)
51
+ __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
52
+ }
53
+ return to;
54
+ };
55
+ var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
56
+ var token_error_exports = {};
57
+ __export(token_error_exports, {
58
+ VercelOidcTokenError: () => VercelOidcTokenError
59
+ });
60
+ module.exports = __toCommonJS(token_error_exports);
61
+ var VercelOidcTokenError = class extends Error {
62
+ constructor(message, cause) {
63
+ super(message);
64
+ this.name = "VercelOidcTokenError";
65
+ this.cause = cause;
66
+ }
67
+ toString() {
68
+ if (this.cause) {
69
+ return `${this.name}: ${this.message}: ${this.cause}`;
70
+ }
71
+ return `${this.name}: ${this.message}`;
72
+ }
73
+ };
74
+ }
75
+ });
76
+
77
+ export { __commonJS, __require2 as __require, __toESM, require_token_error };
78
+ //# sourceMappingURL=chunk-HDI4ZP7N.js.map
79
+ //# sourceMappingURL=chunk-HDI4ZP7N.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../packages/_vendored/ai_v6/dist/chunk-7D4SUZUM.js","../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-error.js"],"names":["__require","__require2","exports","__defProp","__getOwnPropDesc","__getOwnPropNames","__hasOwnProp","__copyProps"],"mappings":";;;AAAA,IAAI,WAAW,MAAA,CAAO,MAAA;AACtB,IAAI,YAAY,MAAA,CAAO,cAAA;AACvB,IAAI,mBAAmB,MAAA,CAAO,wBAAA;AAC9B,IAAI,oBAAoB,MAAA,CAAO,mBAAA;AAC/B,IAAI,eAAe,MAAA,CAAO,cAAA;AAC1B,IAAI,YAAA,GAAe,OAAO,SAAA,CAAU,cAAA;AACpC,IAAIA,UAAAA,mBAA6B,CAAA,CAAC,CAAA,KAAM,OAAO,SAAA,KAAY,WAAA,GAAc,SAAA,GAAU,OAAO,KAAA,KAAU,WAAA,GAAc,IAAI,KAAA,CAAM,CAAA,EAAG;AAAA,EAC7H,GAAA,EAAK,CAAC,CAAA,EAAG,CAAA,KAAA,CAAO,OAAO,SAAA,KAAY,WAAA,GAAc,SAAA,GAAU,CAAA,EAAG,CAAC;AACjE,CAAC,CAAA,GAAI,CAAA,EAAG,SAAS,CAAA,EAAG;AAClB,EAAA,IAAI,OAAO,SAAA,KAAY,WAAA,SAAoB,SAAA,CAAQ,KAAA,CAAM,MAAM,SAAS,CAAA;AACxE,EAAA,MAAM,KAAA,CAAM,sBAAA,GAAyB,CAAA,GAAI,oBAAoB,CAAA;AAC/D,CAAC;AACD,IAAI,UAAA,GAAa,CAAC,EAAA,EAAI,GAAA,KAAQ,SAASC,WAAAA,GAAa;AAClD,EAAA,OAAO,WAAW,EAAA,CAAG,kBAAkB,EAAE,CAAA,CAAE,CAAC,CAAC,CAAA,EAAA,CAAI,GAAA,GAAM,EAAE,SAAS,EAAC,IAAK,OAAA,EAAS,GAAG,GAAG,GAAA,CAAI,OAAA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QAAA,IAAA,CAAK,IAAA,GAAO,sBAAA;AACZ,QAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACf,MAAA;MACA,QAAA,GAAW;AACT,QAAA,IAAI,KAAK,KAAA,EAAO;AACd,UAAA,OAAO,CAAA,EAAG,KAAK,IAAI,CAAA,EAAA,EAAK,KAAK,OAAO,CAAA,EAAA,EAAK,KAAK,KAAK,CAAA,CAAA;AACrD,QAAA;AACA,QAAA,OAAO,CAAA,EAAG,IAAA,CAAK,IAAI,CAAA,EAAA,EAAK,KAAK,OAAO,CAAA,CAAA;AACtC,MAAA;AAAA,KAAA;AACF,EAAA;AAAA,CAAA","file":"chunk-HDI4ZP7N.js","sourcesContent":["var __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __require = /* @__PURE__ */ ((x) => typeof require !== \"undefined\" ? require : typeof Proxy !== \"undefined\" ? new Proxy(x, {\n get: (a, b) => (typeof require !== \"undefined\" ? require : a)[b]\n}) : x)(function(x) {\n if (typeof require !== \"undefined\") return require.apply(this, arguments);\n throw Error('Dynamic require of \"' + x + '\" is not supported');\n});\nvar __commonJS = (cb, mod) => function __require2() {\n return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\n\nexport { __commonJS, __require, __toESM };\n//# sourceMappingURL=chunk-7D4SUZUM.js.map\n//# sourceMappingURL=chunk-7D4SUZUM.js.map","\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar token_error_exports = {};\n__export(token_error_exports, {\n VercelOidcTokenError: () => VercelOidcTokenError\n});\nmodule.exports = __toCommonJS(token_error_exports);\nclass VercelOidcTokenError extends Error {\n constructor(message, cause) {\n super(message);\n this.name = \"VercelOidcTokenError\";\n this.cause = cause;\n }\n toString() {\n if (this.cause) {\n return `${this.name}: ${this.message}: ${this.cause}`;\n }\n return `${this.name}: ${this.message}`;\n }\n}\n// Annotate the CommonJS export names for ESM import in node:\n0 && (module.exports = {\n VercelOidcTokenError\n});\n"]}
@@ -0,0 +1,439 @@
1
+ import { __commonJS, __require, require_token_error } from './chunk-HDI4ZP7N.js';
2
+
3
+ // ../../packages/_vendored/ai_v6/dist/chunk-QCO6BNQA.js
4
+ var require_token_io = __commonJS({
5
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-io.js"(exports$1, module) {
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
33
+ var token_io_exports = {};
34
+ __export(token_io_exports, {
35
+ findRootDir: () => findRootDir,
36
+ getUserDataDir: () => getUserDataDir
37
+ });
38
+ module.exports = __toCommonJS(token_io_exports);
39
+ var import_path = __toESM(__require("path"));
40
+ var import_fs = __toESM(__require("fs"));
41
+ var import_os = __toESM(__require("os"));
42
+ var import_token_error = require_token_error();
43
+ function findRootDir() {
44
+ try {
45
+ let dir = process.cwd();
46
+ while (dir !== import_path.default.dirname(dir)) {
47
+ const pkgPath = import_path.default.join(dir, ".vercel");
48
+ if (import_fs.default.existsSync(pkgPath)) {
49
+ return dir;
50
+ }
51
+ dir = import_path.default.dirname(dir);
52
+ }
53
+ } catch (e) {
54
+ throw new import_token_error.VercelOidcTokenError(
55
+ "Token refresh only supported in node server environments"
56
+ );
57
+ }
58
+ return null;
59
+ }
60
+ function getUserDataDir() {
61
+ if (process.env.XDG_DATA_HOME) {
62
+ return process.env.XDG_DATA_HOME;
63
+ }
64
+ switch (import_os.default.platform()) {
65
+ case "darwin":
66
+ return import_path.default.join(import_os.default.homedir(), "Library/Application Support");
67
+ case "linux":
68
+ return import_path.default.join(import_os.default.homedir(), ".local/share");
69
+ case "win32":
70
+ if (process.env.LOCALAPPDATA) {
71
+ return process.env.LOCALAPPDATA;
72
+ }
73
+ return null;
74
+ default:
75
+ return null;
76
+ }
77
+ }
78
+ }
79
+ });
80
+ var require_auth_config = __commonJS({
81
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/auth-config.js"(exports$1, module) {
82
+ var __create = Object.create;
83
+ var __defProp = Object.defineProperty;
84
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
85
+ var __getOwnPropNames = Object.getOwnPropertyNames;
86
+ var __getProtoOf = Object.getPrototypeOf;
87
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
88
+ var __export = (target, all) => {
89
+ for (var name in all)
90
+ __defProp(target, name, { get: all[name], enumerable: true });
91
+ };
92
+ var __copyProps = (to, from, except, desc) => {
93
+ if (from && typeof from === "object" || typeof from === "function") {
94
+ for (let key of __getOwnPropNames(from))
95
+ if (!__hasOwnProp.call(to, key) && key !== except)
96
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
97
+ }
98
+ return to;
99
+ };
100
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
101
+ // If the importer is in node compatibility mode or this is not an ESM
102
+ // file that has been converted to a CommonJS file using a Babel-
103
+ // compatible transform (i.e. "__esModule" has not been set), then set
104
+ // "default" to the CommonJS "module.exports" for node compatibility.
105
+ !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
106
+ mod
107
+ ));
108
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
109
+ var auth_config_exports = {};
110
+ __export(auth_config_exports, {
111
+ isValidAccessToken: () => isValidAccessToken,
112
+ readAuthConfig: () => readAuthConfig,
113
+ writeAuthConfig: () => writeAuthConfig
114
+ });
115
+ module.exports = __toCommonJS(auth_config_exports);
116
+ var fs = __toESM(__require("fs"));
117
+ var path = __toESM(__require("path"));
118
+ var import_token_util = require_token_util();
119
+ function getAuthConfigPath() {
120
+ const dataDir = (0, import_token_util.getVercelDataDir)();
121
+ if (!dataDir) {
122
+ throw new Error(
123
+ `Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`
124
+ );
125
+ }
126
+ return path.join(dataDir, "auth.json");
127
+ }
128
+ function readAuthConfig() {
129
+ try {
130
+ const authPath = getAuthConfigPath();
131
+ if (!fs.existsSync(authPath)) {
132
+ return null;
133
+ }
134
+ const content = fs.readFileSync(authPath, "utf8");
135
+ if (!content) {
136
+ return null;
137
+ }
138
+ return JSON.parse(content);
139
+ } catch (error) {
140
+ return null;
141
+ }
142
+ }
143
+ function writeAuthConfig(config) {
144
+ const authPath = getAuthConfigPath();
145
+ const authDir = path.dirname(authPath);
146
+ if (!fs.existsSync(authDir)) {
147
+ fs.mkdirSync(authDir, { mode: 504, recursive: true });
148
+ }
149
+ fs.writeFileSync(authPath, JSON.stringify(config, null, 2), { mode: 384 });
150
+ }
151
+ function isValidAccessToken(authConfig) {
152
+ if (!authConfig.token)
153
+ return false;
154
+ if (typeof authConfig.expiresAt !== "number")
155
+ return true;
156
+ const nowInSeconds = Math.floor(Date.now() / 1e3);
157
+ return authConfig.expiresAt >= nowInSeconds;
158
+ }
159
+ }
160
+ });
161
+ var require_oauth = __commonJS({
162
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/oauth.js"(exports$1, module) {
163
+ var __defProp = Object.defineProperty;
164
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
165
+ var __getOwnPropNames = Object.getOwnPropertyNames;
166
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
167
+ var __export = (target, all) => {
168
+ for (var name in all)
169
+ __defProp(target, name, { get: all[name], enumerable: true });
170
+ };
171
+ var __copyProps = (to, from, except, desc) => {
172
+ if (from && typeof from === "object" || typeof from === "function") {
173
+ for (let key of __getOwnPropNames(from))
174
+ if (!__hasOwnProp.call(to, key) && key !== except)
175
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
176
+ }
177
+ return to;
178
+ };
179
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
180
+ var oauth_exports = {};
181
+ __export(oauth_exports, {
182
+ processTokenResponse: () => processTokenResponse,
183
+ refreshTokenRequest: () => refreshTokenRequest
184
+ });
185
+ module.exports = __toCommonJS(oauth_exports);
186
+ var import_os = __require("os");
187
+ var VERCEL_ISSUER = "https://vercel.com";
188
+ var VERCEL_CLI_CLIENT_ID = "cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp";
189
+ var userAgent = `@vercel/oidc node-${process.version} ${(0, import_os.platform)()} (${(0, import_os.arch)()}) ${(0, import_os.hostname)()}`;
190
+ var _tokenEndpoint = null;
191
+ async function getTokenEndpoint() {
192
+ if (_tokenEndpoint) {
193
+ return _tokenEndpoint;
194
+ }
195
+ const discoveryUrl = `${VERCEL_ISSUER}/.well-known/openid-configuration`;
196
+ const response = await fetch(discoveryUrl, {
197
+ headers: { "user-agent": userAgent }
198
+ });
199
+ if (!response.ok) {
200
+ throw new Error("Failed to discover OAuth endpoints");
201
+ }
202
+ const metadata = await response.json();
203
+ if (!metadata || typeof metadata.token_endpoint !== "string") {
204
+ throw new Error("Invalid OAuth discovery response");
205
+ }
206
+ const endpoint = metadata.token_endpoint;
207
+ _tokenEndpoint = endpoint;
208
+ return endpoint;
209
+ }
210
+ async function refreshTokenRequest(options) {
211
+ const tokenEndpoint = await getTokenEndpoint();
212
+ return await fetch(tokenEndpoint, {
213
+ method: "POST",
214
+ headers: {
215
+ "Content-Type": "application/x-www-form-urlencoded",
216
+ "user-agent": userAgent
217
+ },
218
+ body: new URLSearchParams({
219
+ client_id: VERCEL_CLI_CLIENT_ID,
220
+ grant_type: "refresh_token",
221
+ ...options
222
+ })
223
+ });
224
+ }
225
+ async function processTokenResponse(response) {
226
+ const json = await response.json();
227
+ if (!response.ok) {
228
+ const errorMsg = typeof json === "object" && json && "error" in json ? String(json.error) : "Token refresh failed";
229
+ return [new Error(errorMsg)];
230
+ }
231
+ if (typeof json !== "object" || json === null) {
232
+ return [new Error("Invalid token response")];
233
+ }
234
+ if (typeof json.access_token !== "string") {
235
+ return [new Error("Missing access_token in response")];
236
+ }
237
+ if (json.token_type !== "Bearer") {
238
+ return [new Error("Invalid token_type in response")];
239
+ }
240
+ if (typeof json.expires_in !== "number") {
241
+ return [new Error("Missing expires_in in response")];
242
+ }
243
+ return [null, json];
244
+ }
245
+ }
246
+ });
247
+ var require_token_util = __commonJS({
248
+ "../../../node_modules/.pnpm/@vercel+oidc@3.1.0/node_modules/@vercel/oidc/dist/token-util.js"(exports$1, module) {
249
+ var __create = Object.create;
250
+ var __defProp = Object.defineProperty;
251
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
252
+ var __getOwnPropNames = Object.getOwnPropertyNames;
253
+ var __getProtoOf = Object.getPrototypeOf;
254
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
255
+ var __export = (target, all) => {
256
+ for (var name in all)
257
+ __defProp(target, name, { get: all[name], enumerable: true });
258
+ };
259
+ var __copyProps = (to, from, except, desc) => {
260
+ if (from && typeof from === "object" || typeof from === "function") {
261
+ for (let key of __getOwnPropNames(from))
262
+ if (!__hasOwnProp.call(to, key) && key !== except)
263
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
264
+ }
265
+ return to;
266
+ };
267
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
268
+ // If the importer is in node compatibility mode or this is not an ESM
269
+ // file that has been converted to a CommonJS file using a Babel-
270
+ // compatible transform (i.e. "__esModule" has not been set), then set
271
+ // "default" to the CommonJS "module.exports" for node compatibility.
272
+ !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
273
+ mod
274
+ ));
275
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
276
+ var token_util_exports = {};
277
+ __export(token_util_exports, {
278
+ assertVercelOidcTokenResponse: () => assertVercelOidcTokenResponse,
279
+ findProjectInfo: () => findProjectInfo,
280
+ getTokenPayload: () => getTokenPayload,
281
+ getVercelCliToken: () => getVercelCliToken,
282
+ getVercelDataDir: () => getVercelDataDir,
283
+ getVercelOidcToken: () => getVercelOidcToken,
284
+ isExpired: () => isExpired,
285
+ loadToken: () => loadToken,
286
+ saveToken: () => saveToken
287
+ });
288
+ module.exports = __toCommonJS(token_util_exports);
289
+ var path = __toESM(__require("path"));
290
+ var fs = __toESM(__require("fs"));
291
+ var import_token_error = require_token_error();
292
+ var import_token_io = require_token_io();
293
+ var import_auth_config = require_auth_config();
294
+ var import_oauth = require_oauth();
295
+ function getVercelDataDir() {
296
+ const vercelFolder = "com.vercel.cli";
297
+ const dataDir = (0, import_token_io.getUserDataDir)();
298
+ if (!dataDir) {
299
+ return null;
300
+ }
301
+ return path.join(dataDir, vercelFolder);
302
+ }
303
+ async function getVercelCliToken() {
304
+ const authConfig = (0, import_auth_config.readAuthConfig)();
305
+ if (!authConfig) {
306
+ return null;
307
+ }
308
+ if ((0, import_auth_config.isValidAccessToken)(authConfig)) {
309
+ return authConfig.token || null;
310
+ }
311
+ if (!authConfig.refreshToken) {
312
+ (0, import_auth_config.writeAuthConfig)({});
313
+ return null;
314
+ }
315
+ try {
316
+ const tokenResponse = await (0, import_oauth.refreshTokenRequest)({
317
+ refresh_token: authConfig.refreshToken
318
+ });
319
+ const [tokensError, tokens] = await (0, import_oauth.processTokenResponse)(tokenResponse);
320
+ if (tokensError || !tokens) {
321
+ (0, import_auth_config.writeAuthConfig)({});
322
+ return null;
323
+ }
324
+ const updatedConfig = {
325
+ token: tokens.access_token,
326
+ expiresAt: Math.floor(Date.now() / 1e3) + tokens.expires_in
327
+ };
328
+ if (tokens.refresh_token) {
329
+ updatedConfig.refreshToken = tokens.refresh_token;
330
+ }
331
+ (0, import_auth_config.writeAuthConfig)(updatedConfig);
332
+ return updatedConfig.token ?? null;
333
+ } catch (error) {
334
+ (0, import_auth_config.writeAuthConfig)({});
335
+ return null;
336
+ }
337
+ }
338
+ async function getVercelOidcToken(authToken, projectId, teamId) {
339
+ const url = `https://api.vercel.com/v1/projects/${projectId}/token?source=vercel-oidc-refresh${teamId ? `&teamId=${teamId}` : ""}`;
340
+ const res = await fetch(url, {
341
+ method: "POST",
342
+ headers: {
343
+ Authorization: `Bearer ${authToken}`
344
+ }
345
+ });
346
+ if (!res.ok) {
347
+ throw new import_token_error.VercelOidcTokenError(
348
+ `Failed to refresh OIDC token: ${res.statusText}`
349
+ );
350
+ }
351
+ const tokenRes = await res.json();
352
+ assertVercelOidcTokenResponse(tokenRes);
353
+ return tokenRes;
354
+ }
355
+ function assertVercelOidcTokenResponse(res) {
356
+ if (!res || typeof res !== "object") {
357
+ throw new TypeError(
358
+ "Vercel OIDC token is malformed. Expected an object. Please run `vc env pull` and try again"
359
+ );
360
+ }
361
+ if (!("token" in res) || typeof res.token !== "string") {
362
+ throw new TypeError(
363
+ "Vercel OIDC token is malformed. Expected a string-valued token property. Please run `vc env pull` and try again"
364
+ );
365
+ }
366
+ }
367
+ function findProjectInfo() {
368
+ const dir = (0, import_token_io.findRootDir)();
369
+ if (!dir) {
370
+ throw new import_token_error.VercelOidcTokenError(
371
+ "Unable to find project root directory. Have you linked your project with `vc link?`"
372
+ );
373
+ }
374
+ const prjPath = path.join(dir, ".vercel", "project.json");
375
+ if (!fs.existsSync(prjPath)) {
376
+ throw new import_token_error.VercelOidcTokenError(
377
+ "project.json not found, have you linked your project with `vc link?`"
378
+ );
379
+ }
380
+ const prj = JSON.parse(fs.readFileSync(prjPath, "utf8"));
381
+ if (typeof prj.projectId !== "string" && typeof prj.orgId !== "string") {
382
+ throw new TypeError(
383
+ "Expected a string-valued projectId property. Try running `vc link` to re-link your project."
384
+ );
385
+ }
386
+ return { projectId: prj.projectId, teamId: prj.orgId };
387
+ }
388
+ function saveToken(token, projectId) {
389
+ const dir = (0, import_token_io.getUserDataDir)();
390
+ if (!dir) {
391
+ throw new import_token_error.VercelOidcTokenError(
392
+ "Unable to find user data directory. Please reach out to Vercel support."
393
+ );
394
+ }
395
+ const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
396
+ const tokenJson = JSON.stringify(token);
397
+ fs.mkdirSync(path.dirname(tokenPath), { mode: 504, recursive: true });
398
+ fs.writeFileSync(tokenPath, tokenJson);
399
+ fs.chmodSync(tokenPath, 432);
400
+ return;
401
+ }
402
+ function loadToken(projectId) {
403
+ const dir = (0, import_token_io.getUserDataDir)();
404
+ if (!dir) {
405
+ throw new import_token_error.VercelOidcTokenError(
406
+ "Unable to find user data directory. Please reach out to Vercel support."
407
+ );
408
+ }
409
+ const tokenPath = path.join(dir, "com.vercel.token", `${projectId}.json`);
410
+ if (!fs.existsSync(tokenPath)) {
411
+ return null;
412
+ }
413
+ const token = JSON.parse(fs.readFileSync(tokenPath, "utf8"));
414
+ assertVercelOidcTokenResponse(token);
415
+ return token;
416
+ }
417
+ function getTokenPayload(token) {
418
+ const tokenParts = token.split(".");
419
+ if (tokenParts.length !== 3) {
420
+ throw new import_token_error.VercelOidcTokenError(
421
+ "Invalid token. Please run `vc env pull` and try again"
422
+ );
423
+ }
424
+ const base64 = tokenParts[1].replace(/-/g, "+").replace(/_/g, "/");
425
+ const padded = base64.padEnd(
426
+ base64.length + (4 - base64.length % 4) % 4,
427
+ "="
428
+ );
429
+ return JSON.parse(Buffer.from(padded, "base64").toString("utf8"));
430
+ }
431
+ function isExpired(token) {
432
+ return token.exp * 1e3 < Date.now();
433
+ }
434
+ }
435
+ });
436
+
437
+ export { require_token_util };
438
+ //# sourceMappingURL=chunk-IV3RKEE4.js.map
439
+ //# sourceMappingURL=chunk-IV3RKEE4.js.map