@levelcode/sdk 0.0.2 → 0.0.4
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.
- package/CHANGELOG.md +1 -1
- package/README.md +4 -4
- package/dist/index.cjs +1658 -192
- package/dist/index.cjs.map +30 -17
- package/dist/index.d.ts +3443 -0
- package/dist/index.mjs +1658 -192
- package/dist/index.mjs.map +30 -17
- package/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/arm64-linux/rg +0 -0
- package/dist/vendor/ripgrep/x64-darwin/rg +0 -0
- package/dist/vendor/ripgrep/x64-linux/rg +0 -0
- package/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/dist/wasm/tree-sitter-c-sharp.wasm +0 -0
- package/dist/wasm/tree-sitter-cpp.wasm +0 -0
- package/dist/wasm/tree-sitter-go.wasm +0 -0
- package/dist/wasm/tree-sitter-java.wasm +0 -0
- package/dist/wasm/tree-sitter-javascript.wasm +0 -0
- package/dist/wasm/tree-sitter-python.wasm +0 -0
- package/dist/wasm/tree-sitter-ruby.wasm +0 -0
- package/dist/wasm/tree-sitter-rust.wasm +0 -0
- package/dist/wasm/tree-sitter-tsx.wasm +0 -0
- package/dist/wasm/tree-sitter-typescript.wasm +0 -0
- package/dist/wasm/tree-sitter.wasm +0 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -13109,6 +13109,7 @@ __export(exports_src, {
|
|
|
13109
13109
|
loadMCPConfigSync: () => loadMCPConfigSync,
|
|
13110
13110
|
loadMCPConfig: () => loadMCPConfig,
|
|
13111
13111
|
loadLocalAgents: () => loadLocalAgents,
|
|
13112
|
+
isStandaloneMode: () => isStandaloneMode,
|
|
13112
13113
|
isRetryableStatusCode: () => isRetryableStatusCode,
|
|
13113
13114
|
isKnowledgeFile: () => isKnowledgeFile,
|
|
13114
13115
|
isClaudeOAuthValid: () => isClaudeOAuthValid,
|
|
@@ -13116,6 +13117,7 @@ __export(exports_src, {
|
|
|
13116
13117
|
getValidClaudeOAuthCredentials: () => getValidClaudeOAuthCredentials,
|
|
13117
13118
|
getUserInfoFromApiKey: () => getUserInfoFromApiKey,
|
|
13118
13119
|
getUserCredentials: () => getUserCredentials,
|
|
13120
|
+
getOpenRouterApiKeyFromEnv: () => getOpenRouterApiKeyFromEnv,
|
|
13119
13121
|
getFiles: () => getFiles,
|
|
13120
13122
|
getFileTokenScores: () => getFileTokenScores,
|
|
13121
13123
|
getErrorStatusCode: () => getErrorStatusCode,
|
|
@@ -13159,15 +13161,15 @@ var import_path12 = __toESM(require("path"));
|
|
|
13159
13161
|
// ../common/src/env-schema.ts
|
|
13160
13162
|
var import_v4 = __toESM(require("zod/v4"));
|
|
13161
13163
|
var clientEnvSchema = import_v4.default.object({
|
|
13162
|
-
NEXT_PUBLIC_CB_ENVIRONMENT: import_v4.default.enum(["dev", "test", "prod"]),
|
|
13163
|
-
NEXT_PUBLIC_LEVELCODE_APP_URL: import_v4.default.
|
|
13164
|
-
NEXT_PUBLIC_SUPPORT_EMAIL: import_v4.default.
|
|
13165
|
-
NEXT_PUBLIC_POSTHOG_API_KEY: import_v4.default.string().
|
|
13166
|
-
NEXT_PUBLIC_POSTHOG_HOST_URL: import_v4.default.
|
|
13167
|
-
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: import_v4.default.string().
|
|
13168
|
-
NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL: import_v4.default.
|
|
13164
|
+
NEXT_PUBLIC_CB_ENVIRONMENT: import_v4.default.enum(["dev", "test", "prod"]).default("prod"),
|
|
13165
|
+
NEXT_PUBLIC_LEVELCODE_APP_URL: import_v4.default.string().default("https://levelcode.vercel.app"),
|
|
13166
|
+
NEXT_PUBLIC_SUPPORT_EMAIL: import_v4.default.string().default("support@levelcode.ai"),
|
|
13167
|
+
NEXT_PUBLIC_POSTHOG_API_KEY: import_v4.default.string().default(""),
|
|
13168
|
+
NEXT_PUBLIC_POSTHOG_HOST_URL: import_v4.default.string().default("https://app.posthog.com"),
|
|
13169
|
+
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: import_v4.default.string().default(""),
|
|
13170
|
+
NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL: import_v4.default.string().default("https://billing.stripe.com"),
|
|
13169
13171
|
NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION_ID: import_v4.default.string().optional(),
|
|
13170
|
-
NEXT_PUBLIC_WEB_PORT: import_v4.default.coerce.number().
|
|
13172
|
+
NEXT_PUBLIC_WEB_PORT: import_v4.default.coerce.number().default(3000)
|
|
13171
13173
|
});
|
|
13172
13174
|
var clientEnvVars = clientEnvSchema.keyof().options;
|
|
13173
13175
|
var clientProcessEnv = {
|
|
@@ -13184,10 +13186,18 @@ var clientProcessEnv = {
|
|
|
13184
13186
|
|
|
13185
13187
|
// ../common/src/env.ts
|
|
13186
13188
|
var parsedEnv = clientEnvSchema.safeParse(clientProcessEnv);
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
|
|
13189
|
+
var fallbackEnv = {
|
|
13190
|
+
NEXT_PUBLIC_CB_ENVIRONMENT: "prod",
|
|
13191
|
+
NEXT_PUBLIC_LEVELCODE_APP_URL: "https://levelcode.vercel.app",
|
|
13192
|
+
NEXT_PUBLIC_SUPPORT_EMAIL: "support@levelcode.ai",
|
|
13193
|
+
NEXT_PUBLIC_POSTHOG_API_KEY: "",
|
|
13194
|
+
NEXT_PUBLIC_POSTHOG_HOST_URL: "https://app.posthog.com",
|
|
13195
|
+
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: "",
|
|
13196
|
+
NEXT_PUBLIC_STRIPE_CUSTOMER_PORTAL: "https://billing.stripe.com",
|
|
13197
|
+
NEXT_PUBLIC_GOOGLE_SITE_VERIFICATION_ID: undefined,
|
|
13198
|
+
NEXT_PUBLIC_WEB_PORT: 3000
|
|
13199
|
+
};
|
|
13200
|
+
var env = parsedEnv.success ? parsedEnv.data : fallbackEnv;
|
|
13191
13201
|
if (env.NEXT_PUBLIC_CB_ENVIRONMENT !== "prod") {
|
|
13192
13202
|
console.log("Using environment:", env.NEXT_PUBLIC_CB_ENVIRONMENT);
|
|
13193
13203
|
}
|
|
@@ -19677,7 +19687,7 @@ When the user requests a new git commit, please follow these steps closely:
|
|
|
19677
19687
|
4. **Create the commit, ending with this specific footer:**
|
|
19678
19688
|
\`\`\`
|
|
19679
19689
|
Generated with LevelCode \uD83E\uDD16
|
|
19680
|
-
Co-Authored-By: LevelCode <noreply@levelcode.
|
|
19690
|
+
Co-Authored-By: LevelCode <noreply@levelcode.vercel.app>
|
|
19681
19691
|
\`\`\`
|
|
19682
19692
|
To maintain proper formatting, use cross-platform compatible commit messages:
|
|
19683
19693
|
|
|
@@ -19687,7 +19697,7 @@ When the user requests a new git commit, please follow these steps closely:
|
|
|
19687
19697
|
Your commit message here.
|
|
19688
19698
|
|
|
19689
19699
|
\uD83E\uDD16 Generated with LevelCode
|
|
19690
|
-
Co-Authored-By: LevelCode <noreply@levelcode.
|
|
19700
|
+
Co-Authored-By: LevelCode <noreply@levelcode.vercel.app>
|
|
19691
19701
|
EOF
|
|
19692
19702
|
)"
|
|
19693
19703
|
\`\`\`
|
|
@@ -19697,7 +19707,7 @@ When the user requests a new git commit, please follow these steps closely:
|
|
|
19697
19707
|
git commit -m "Your commit message here.
|
|
19698
19708
|
|
|
19699
19709
|
\uD83E\uDD16 Generated with LevelCode
|
|
19700
|
-
Co-Authored-By: LevelCode <noreply@levelcode.
|
|
19710
|
+
Co-Authored-By: LevelCode <noreply@levelcode.vercel.app>"
|
|
19701
19711
|
\`\`\`
|
|
19702
19712
|
|
|
19703
19713
|
Always detect the platform and use the appropriate syntax. HEREDOC syntax (\`<<'EOF'\`) only works in bash/Unix shells and will fail on Windows Command Prompt.
|
|
@@ -19764,7 +19774,7 @@ ${$getNativeToolCallExampleString({
|
|
|
19764
19774
|
command: `git commit -m "Your commit message here.
|
|
19765
19775
|
|
|
19766
19776
|
\uD83E\uDD16 Generated with LevelCode
|
|
19767
|
-
Co-Authored-By: LevelCode <noreply@levelcode.
|
|
19777
|
+
Co-Authored-By: LevelCode <noreply@levelcode.vercel.app>"`
|
|
19768
19778
|
},
|
|
19769
19779
|
endsAgentStep: endsAgentStep18
|
|
19770
19780
|
})}
|
|
@@ -35220,7 +35230,158 @@ var import_v461 = __toESM(require("zod/v4"));
|
|
|
35220
35230
|
|
|
35221
35231
|
// src/constants.ts
|
|
35222
35232
|
var LEVELCODE_BINARY = "levelcode";
|
|
35223
|
-
var WEBSITE_URL = env.NEXT_PUBLIC_LEVELCODE_APP_URL;
|
|
35233
|
+
var WEBSITE_URL = env.NEXT_PUBLIC_LEVELCODE_APP_URL || "";
|
|
35234
|
+
|
|
35235
|
+
// ../common/src/constants/byok.ts
|
|
35236
|
+
var BYOK_OPENROUTER_HEADER = "x-openrouter-api-key";
|
|
35237
|
+
var BYOK_OPENROUTER_ENV_VAR = "LEVELCODE_BYOK_OPENROUTER";
|
|
35238
|
+
|
|
35239
|
+
// ../common/src/constants/claude-oauth.ts
|
|
35240
|
+
var CLAUDE_OAUTH_CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
|
|
35241
|
+
var CLAUDE_OAUTH_TOKEN_ENV_VAR = "LEVELCODE_CLAUDE_OAUTH_TOKEN";
|
|
35242
|
+
var CLAUDE_OAUTH_BETA_HEADERS = [
|
|
35243
|
+
"oauth-2025-04-20",
|
|
35244
|
+
"claude-code-20250219",
|
|
35245
|
+
"interleaved-thinking-2025-05-14",
|
|
35246
|
+
"fine-grained-tool-streaming-2025-05-14"
|
|
35247
|
+
];
|
|
35248
|
+
var CLAUDE_CODE_SYSTEM_PROMPT_PREFIX = "You are Claude Code, Anthropic's official CLI for Claude.";
|
|
35249
|
+
var OPENROUTER_TO_ANTHROPIC_MODEL_MAP = {
|
|
35250
|
+
"anthropic/claude-3.5-haiku-20241022": "claude-3-5-haiku-20241022",
|
|
35251
|
+
"anthropic/claude-3.5-haiku": "claude-3-5-haiku-20241022",
|
|
35252
|
+
"anthropic/claude-3-5-haiku": "claude-3-5-haiku-20241022",
|
|
35253
|
+
"anthropic/claude-3-5-haiku-20241022": "claude-3-5-haiku-20241022",
|
|
35254
|
+
"anthropic/claude-3-haiku": "claude-3-haiku-20240307",
|
|
35255
|
+
"anthropic/claude-3.5-sonnet": "claude-3-5-sonnet-20241022",
|
|
35256
|
+
"anthropic/claude-3-5-sonnet": "claude-3-5-sonnet-20241022",
|
|
35257
|
+
"anthropic/claude-3-5-sonnet-20241022": "claude-3-5-sonnet-20241022",
|
|
35258
|
+
"anthropic/claude-3-5-sonnet-20240620": "claude-3-5-sonnet-20240620",
|
|
35259
|
+
"anthropic/claude-3-sonnet": "claude-3-sonnet-20240229",
|
|
35260
|
+
"anthropic/claude-3-opus": "claude-3-opus-20240229",
|
|
35261
|
+
"anthropic/claude-3-opus-20240229": "claude-3-opus-20240229",
|
|
35262
|
+
"anthropic/claude-haiku-4.5": "claude-haiku-4-5-20251001",
|
|
35263
|
+
"anthropic/claude-haiku-4": "claude-haiku-4-20250514",
|
|
35264
|
+
"anthropic/claude-sonnet-4.5": "claude-sonnet-4-5-20250929",
|
|
35265
|
+
"anthropic/claude-sonnet-4": "claude-sonnet-4-20250514",
|
|
35266
|
+
"anthropic/claude-4-sonnet-20250522": "claude-sonnet-4-20250514",
|
|
35267
|
+
"anthropic/claude-4-sonnet": "claude-sonnet-4-20250514",
|
|
35268
|
+
"anthropic/claude-opus-4.5": "claude-opus-4-5-20251101",
|
|
35269
|
+
"anthropic/claude-opus-4.1": "claude-opus-4-1-20250805",
|
|
35270
|
+
"anthropic/claude-opus-4": "claude-opus-4-1-20250805"
|
|
35271
|
+
};
|
|
35272
|
+
function isClaudeModel(model) {
|
|
35273
|
+
return model.startsWith("anthropic/") || model.startsWith("claude-");
|
|
35274
|
+
}
|
|
35275
|
+
function toAnthropicModelId(openrouterModel) {
|
|
35276
|
+
if (!openrouterModel.includes("/")) {
|
|
35277
|
+
return openrouterModel;
|
|
35278
|
+
}
|
|
35279
|
+
if (!openrouterModel.startsWith("anthropic/")) {
|
|
35280
|
+
throw new Error(`Cannot convert non-Anthropic model to Anthropic model ID: ${openrouterModel}`);
|
|
35281
|
+
}
|
|
35282
|
+
const mapped = OPENROUTER_TO_ANTHROPIC_MODEL_MAP[openrouterModel];
|
|
35283
|
+
if (mapped) {
|
|
35284
|
+
return mapped;
|
|
35285
|
+
}
|
|
35286
|
+
return openrouterModel.replace("anthropic/", "");
|
|
35287
|
+
}
|
|
35288
|
+
|
|
35289
|
+
// src/env.ts
|
|
35290
|
+
init_paths();
|
|
35291
|
+
|
|
35292
|
+
// ../common/src/env-process.ts
|
|
35293
|
+
var getBaseEnv = () => ({
|
|
35294
|
+
SHELL: process.env.SHELL,
|
|
35295
|
+
COMSPEC: process.env.COMSPEC,
|
|
35296
|
+
HOME: process.env.HOME,
|
|
35297
|
+
USERPROFILE: process.env.USERPROFILE,
|
|
35298
|
+
APPDATA: process.env.APPDATA,
|
|
35299
|
+
XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME,
|
|
35300
|
+
TERM: process.env.TERM,
|
|
35301
|
+
TERM_PROGRAM: process.env.TERM_PROGRAM,
|
|
35302
|
+
TERM_BACKGROUND: process.env.TERM_BACKGROUND,
|
|
35303
|
+
TERMINAL_EMULATOR: process.env.TERMINAL_EMULATOR,
|
|
35304
|
+
COLORFGBG: process.env.COLORFGBG,
|
|
35305
|
+
NODE_ENV: "development",
|
|
35306
|
+
NODE_PATH: process.env.NODE_PATH,
|
|
35307
|
+
PATH: process.env.PATH
|
|
35308
|
+
});
|
|
35309
|
+
var getProcessEnv = () => ({
|
|
35310
|
+
...getBaseEnv(),
|
|
35311
|
+
KITTY_WINDOW_ID: process.env.KITTY_WINDOW_ID,
|
|
35312
|
+
SIXEL_SUPPORT: process.env.SIXEL_SUPPORT,
|
|
35313
|
+
ZED_NODE_ENV: process.env.ZED_NODE_ENV,
|
|
35314
|
+
VSCODE_THEME_KIND: process.env.VSCODE_THEME_KIND,
|
|
35315
|
+
VSCODE_COLOR_THEME_KIND: process.env.VSCODE_COLOR_THEME_KIND,
|
|
35316
|
+
VSCODE_GIT_IPC_HANDLE: process.env.VSCODE_GIT_IPC_HANDLE,
|
|
35317
|
+
VSCODE_PID: process.env.VSCODE_PID,
|
|
35318
|
+
VSCODE_CWD: process.env.VSCODE_CWD,
|
|
35319
|
+
VSCODE_NLS_CONFIG: process.env.VSCODE_NLS_CONFIG,
|
|
35320
|
+
CURSOR_PORT: process.env.CURSOR_PORT,
|
|
35321
|
+
CURSOR: process.env.CURSOR,
|
|
35322
|
+
JETBRAINS_REMOTE_RUN: process.env.JETBRAINS_REMOTE_RUN,
|
|
35323
|
+
IDEA_INITIAL_DIRECTORY: process.env.IDEA_INITIAL_DIRECTORY,
|
|
35324
|
+
IDE_CONFIG_DIR: process.env.IDE_CONFIG_DIR,
|
|
35325
|
+
JB_IDE_CONFIG_DIR: process.env.JB_IDE_CONFIG_DIR,
|
|
35326
|
+
VISUAL: process.env.VISUAL,
|
|
35327
|
+
EDITOR: process.env.EDITOR,
|
|
35328
|
+
LEVELCODE_CLI_EDITOR: process.env.LEVELCODE_CLI_EDITOR,
|
|
35329
|
+
LEVELCODE_EDITOR: process.env.LEVELCODE_EDITOR,
|
|
35330
|
+
OPEN_TUI_THEME: process.env.OPEN_TUI_THEME,
|
|
35331
|
+
OPENTUI_THEME: process.env.OPENTUI_THEME,
|
|
35332
|
+
LEVELCODE_IS_BINARY: process.env.LEVELCODE_IS_BINARY,
|
|
35333
|
+
LEVELCODE_CLI_VERSION: process.env.LEVELCODE_CLI_VERSION,
|
|
35334
|
+
LEVELCODE_CLI_TARGET: process.env.LEVELCODE_CLI_TARGET,
|
|
35335
|
+
LEVELCODE_RG_PATH: process.env.LEVELCODE_RG_PATH,
|
|
35336
|
+
LEVELCODE_WASM_DIR: process.env.LEVELCODE_WASM_DIR,
|
|
35337
|
+
VERBOSE: process.env.VERBOSE,
|
|
35338
|
+
OVERRIDE_TARGET: process.env.OVERRIDE_TARGET,
|
|
35339
|
+
OVERRIDE_PLATFORM: process.env.OVERRIDE_PLATFORM,
|
|
35340
|
+
OVERRIDE_ARCH: process.env.OVERRIDE_ARCH
|
|
35341
|
+
});
|
|
35342
|
+
var processEnv = getProcessEnv();
|
|
35343
|
+
|
|
35344
|
+
// src/env.ts
|
|
35345
|
+
var getSdkEnv = () => ({
|
|
35346
|
+
...getBaseEnv(),
|
|
35347
|
+
LEVELCODE_RG_PATH: process.env.LEVELCODE_RG_PATH,
|
|
35348
|
+
LEVELCODE_WASM_DIR: process.env.LEVELCODE_WASM_DIR,
|
|
35349
|
+
VERBOSE: process.env.VERBOSE,
|
|
35350
|
+
OVERRIDE_TARGET: process.env.OVERRIDE_TARGET,
|
|
35351
|
+
OVERRIDE_PLATFORM: process.env.OVERRIDE_PLATFORM,
|
|
35352
|
+
OVERRIDE_ARCH: process.env.OVERRIDE_ARCH
|
|
35353
|
+
});
|
|
35354
|
+
var getLevelCodeApiKeyFromEnv = () => {
|
|
35355
|
+
return process.env[API_KEY_ENV_VAR];
|
|
35356
|
+
};
|
|
35357
|
+
var getSystemProcessEnv = () => {
|
|
35358
|
+
return process.env;
|
|
35359
|
+
};
|
|
35360
|
+
var getByokOpenrouterApiKeyFromEnv = () => {
|
|
35361
|
+
return process.env[BYOK_OPENROUTER_ENV_VAR];
|
|
35362
|
+
};
|
|
35363
|
+
var getClaudeOAuthTokenFromEnv = () => {
|
|
35364
|
+
return process.env[CLAUDE_OAUTH_TOKEN_ENV_VAR];
|
|
35365
|
+
};
|
|
35366
|
+
var getOpenRouterApiKeyFromEnv = () => {
|
|
35367
|
+
return process.env.OPENROUTER_API_KEY;
|
|
35368
|
+
};
|
|
35369
|
+
var getOpenRouterBaseUrlFromEnv = () => {
|
|
35370
|
+
return process.env.OPENROUTER_BASE_URL;
|
|
35371
|
+
};
|
|
35372
|
+
var getAnthropicApiKeyFromEnv = () => {
|
|
35373
|
+
return process.env.ANTHROPIC_API_KEY;
|
|
35374
|
+
};
|
|
35375
|
+
var getAnthropicBaseUrlFromEnv = () => {
|
|
35376
|
+
return process.env.ANTHROPIC_BASE_URL;
|
|
35377
|
+
};
|
|
35378
|
+
var isStandaloneMode = () => {
|
|
35379
|
+
const appUrl = process.env.NEXT_PUBLIC_LEVELCODE_APP_URL;
|
|
35380
|
+
if (!appUrl)
|
|
35381
|
+
return true;
|
|
35382
|
+
const hasDirectKey = !!getOpenRouterApiKeyFromEnv() || !!getAnthropicApiKeyFromEnv();
|
|
35383
|
+
return hasDirectKey && !getLevelCodeApiKeyFromEnv();
|
|
35384
|
+
};
|
|
35224
35385
|
|
|
35225
35386
|
// src/retry-config.ts
|
|
35226
35387
|
var MAX_RETRIES_PER_MESSAGE = 3;
|
|
@@ -35263,6 +35424,10 @@ async function fetchWithRetry(url, options, logger2) {
|
|
|
35263
35424
|
throw lastError ?? new Error("Request failed after retries");
|
|
35264
35425
|
}
|
|
35265
35426
|
async function getUserInfoFromApiKey(params2) {
|
|
35427
|
+
if (isStandaloneMode()) {
|
|
35428
|
+
const standaloneUser = { id: "standalone-user", email: "standalone@local" };
|
|
35429
|
+
return Object.fromEntries(params2.fields.map((field) => [field, standaloneUser[field] ?? null]));
|
|
35430
|
+
}
|
|
35266
35431
|
const { apiKey, fields, logger: logger2 } = params2;
|
|
35267
35432
|
const cached = userInfoCache[apiKey];
|
|
35268
35433
|
if (cached === null) {
|
|
@@ -35325,6 +35490,9 @@ async function getUserInfoFromApiKey(params2) {
|
|
|
35325
35490
|
return Object.fromEntries(fields.map((field) => [field, userInfo[field]]));
|
|
35326
35491
|
}
|
|
35327
35492
|
async function fetchAgentFromDatabase(params2) {
|
|
35493
|
+
if (isStandaloneMode()) {
|
|
35494
|
+
return null;
|
|
35495
|
+
}
|
|
35328
35496
|
const { apiKey, parsedAgentId, logger: logger2 } = params2;
|
|
35329
35497
|
const { publisherId, agentId, version: version2 } = parsedAgentId;
|
|
35330
35498
|
const url = new URL(`/api/v1/agents/${publisherId}/${agentId}/${version2 ? version2 : "latest"}`, WEBSITE_URL);
|
|
@@ -35378,6 +35546,9 @@ async function fetchAgentFromDatabase(params2) {
|
|
|
35378
35546
|
}
|
|
35379
35547
|
}
|
|
35380
35548
|
async function startAgentRun(params2) {
|
|
35549
|
+
if (isStandaloneMode()) {
|
|
35550
|
+
return crypto.randomUUID();
|
|
35551
|
+
}
|
|
35381
35552
|
const { apiKey, agentId, ancestorRunIds, logger: logger2 } = params2;
|
|
35382
35553
|
const url = new URL(`/api/v1/agent-runs`, WEBSITE_URL);
|
|
35383
35554
|
try {
|
|
@@ -35407,6 +35578,9 @@ async function startAgentRun(params2) {
|
|
|
35407
35578
|
}
|
|
35408
35579
|
}
|
|
35409
35580
|
async function finishAgentRun(params2) {
|
|
35581
|
+
if (isStandaloneMode()) {
|
|
35582
|
+
return;
|
|
35583
|
+
}
|
|
35410
35584
|
const {
|
|
35411
35585
|
apiKey,
|
|
35412
35586
|
runId,
|
|
@@ -35441,6 +35615,9 @@ async function finishAgentRun(params2) {
|
|
|
35441
35615
|
}
|
|
35442
35616
|
}
|
|
35443
35617
|
async function addAgentStep2(params2) {
|
|
35618
|
+
if (isStandaloneMode()) {
|
|
35619
|
+
return crypto.randomUUID();
|
|
35620
|
+
}
|
|
35444
35621
|
const {
|
|
35445
35622
|
apiKey,
|
|
35446
35623
|
agentRunId,
|
|
@@ -35553,60 +35730,6 @@ var import_ai3 = require("ai");
|
|
|
35553
35730
|
var import_path5 = __toESM(require("path"));
|
|
35554
35731
|
var import_anthropic = require("@ai-sdk/anthropic");
|
|
35555
35732
|
|
|
35556
|
-
// ../common/src/constants/byok.ts
|
|
35557
|
-
var BYOK_OPENROUTER_HEADER = "x-openrouter-api-key";
|
|
35558
|
-
var BYOK_OPENROUTER_ENV_VAR = "LEVELCODE_BYOK_OPENROUTER";
|
|
35559
|
-
|
|
35560
|
-
// ../common/src/constants/claude-oauth.ts
|
|
35561
|
-
var CLAUDE_OAUTH_CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
|
|
35562
|
-
var CLAUDE_OAUTH_TOKEN_ENV_VAR = "LEVELCODE_CLAUDE_OAUTH_TOKEN";
|
|
35563
|
-
var CLAUDE_OAUTH_BETA_HEADERS = [
|
|
35564
|
-
"oauth-2025-04-20",
|
|
35565
|
-
"claude-code-20250219",
|
|
35566
|
-
"interleaved-thinking-2025-05-14",
|
|
35567
|
-
"fine-grained-tool-streaming-2025-05-14"
|
|
35568
|
-
];
|
|
35569
|
-
var CLAUDE_CODE_SYSTEM_PROMPT_PREFIX = "You are Claude Code, Anthropic's official CLI for Claude.";
|
|
35570
|
-
var OPENROUTER_TO_ANTHROPIC_MODEL_MAP = {
|
|
35571
|
-
"anthropic/claude-3.5-haiku-20241022": "claude-3-5-haiku-20241022",
|
|
35572
|
-
"anthropic/claude-3.5-haiku": "claude-3-5-haiku-20241022",
|
|
35573
|
-
"anthropic/claude-3-5-haiku": "claude-3-5-haiku-20241022",
|
|
35574
|
-
"anthropic/claude-3-5-haiku-20241022": "claude-3-5-haiku-20241022",
|
|
35575
|
-
"anthropic/claude-3-haiku": "claude-3-haiku-20240307",
|
|
35576
|
-
"anthropic/claude-3.5-sonnet": "claude-3-5-sonnet-20241022",
|
|
35577
|
-
"anthropic/claude-3-5-sonnet": "claude-3-5-sonnet-20241022",
|
|
35578
|
-
"anthropic/claude-3-5-sonnet-20241022": "claude-3-5-sonnet-20241022",
|
|
35579
|
-
"anthropic/claude-3-5-sonnet-20240620": "claude-3-5-sonnet-20240620",
|
|
35580
|
-
"anthropic/claude-3-sonnet": "claude-3-sonnet-20240229",
|
|
35581
|
-
"anthropic/claude-3-opus": "claude-3-opus-20240229",
|
|
35582
|
-
"anthropic/claude-3-opus-20240229": "claude-3-opus-20240229",
|
|
35583
|
-
"anthropic/claude-haiku-4.5": "claude-haiku-4-5-20251001",
|
|
35584
|
-
"anthropic/claude-haiku-4": "claude-haiku-4-20250514",
|
|
35585
|
-
"anthropic/claude-sonnet-4.5": "claude-sonnet-4-5-20250929",
|
|
35586
|
-
"anthropic/claude-sonnet-4": "claude-sonnet-4-20250514",
|
|
35587
|
-
"anthropic/claude-4-sonnet-20250522": "claude-sonnet-4-20250514",
|
|
35588
|
-
"anthropic/claude-4-sonnet": "claude-sonnet-4-20250514",
|
|
35589
|
-
"anthropic/claude-opus-4.5": "claude-opus-4-5-20251101",
|
|
35590
|
-
"anthropic/claude-opus-4.1": "claude-opus-4-1-20250805",
|
|
35591
|
-
"anthropic/claude-opus-4": "claude-opus-4-1-20250805"
|
|
35592
|
-
};
|
|
35593
|
-
function isClaudeModel(model) {
|
|
35594
|
-
return model.startsWith("anthropic/") || model.startsWith("claude-");
|
|
35595
|
-
}
|
|
35596
|
-
function toAnthropicModelId(openrouterModel) {
|
|
35597
|
-
if (!openrouterModel.includes("/")) {
|
|
35598
|
-
return openrouterModel;
|
|
35599
|
-
}
|
|
35600
|
-
if (!openrouterModel.startsWith("anthropic/")) {
|
|
35601
|
-
throw new Error(`Cannot convert non-Anthropic model to Anthropic model ID: ${openrouterModel}`);
|
|
35602
|
-
}
|
|
35603
|
-
const mapped = OPENROUTER_TO_ANTHROPIC_MODEL_MAP[openrouterModel];
|
|
35604
|
-
if (mapped) {
|
|
35605
|
-
return mapped;
|
|
35606
|
-
}
|
|
35607
|
-
return openrouterModel.replace("anthropic/", "");
|
|
35608
|
-
}
|
|
35609
|
-
|
|
35610
35733
|
// ../node_modules/@ai-sdk/provider/dist/index.mjs
|
|
35611
35734
|
var marker = "vercel.ai.error";
|
|
35612
35735
|
var symbol = Symbol.for(marker);
|
|
@@ -36005,6 +36128,38 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
36005
36128
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
36006
36129
|
}
|
|
36007
36130
|
var VERSION = "3.0.20";
|
|
36131
|
+
function loadApiKey({
|
|
36132
|
+
apiKey,
|
|
36133
|
+
environmentVariableName,
|
|
36134
|
+
apiKeyParameterName = "apiKey",
|
|
36135
|
+
description: description31
|
|
36136
|
+
}) {
|
|
36137
|
+
if (typeof apiKey === "string") {
|
|
36138
|
+
return apiKey;
|
|
36139
|
+
}
|
|
36140
|
+
if (apiKey != null) {
|
|
36141
|
+
throw new LoadAPIKeyError({
|
|
36142
|
+
message: `${description31} API key must be a string.`
|
|
36143
|
+
});
|
|
36144
|
+
}
|
|
36145
|
+
if (typeof process === "undefined") {
|
|
36146
|
+
throw new LoadAPIKeyError({
|
|
36147
|
+
message: `${description31} API key is missing. Pass it using the '${apiKeyParameterName}' parameter. Environment variables is not supported in this environment.`
|
|
36148
|
+
});
|
|
36149
|
+
}
|
|
36150
|
+
apiKey = process.env[environmentVariableName];
|
|
36151
|
+
if (apiKey == null) {
|
|
36152
|
+
throw new LoadAPIKeyError({
|
|
36153
|
+
message: `${description31} API key is missing. Pass it using the '${apiKeyParameterName}' parameter or the ${environmentVariableName} environment variable.`
|
|
36154
|
+
});
|
|
36155
|
+
}
|
|
36156
|
+
if (typeof apiKey !== "string") {
|
|
36157
|
+
throw new LoadAPIKeyError({
|
|
36158
|
+
message: `${description31} API key must be a string. The value of the ${environmentVariableName} environment variable is not a string.`
|
|
36159
|
+
});
|
|
36160
|
+
}
|
|
36161
|
+
return apiKey;
|
|
36162
|
+
}
|
|
36008
36163
|
var suspectProtoRx = /"__proto__"\s*:/;
|
|
36009
36164
|
var suspectConstructorRx = /"constructor"\s*:/;
|
|
36010
36165
|
function _parse(text) {
|
|
@@ -36381,6 +36536,9 @@ function convertUint8ArrayToBase64(array) {
|
|
|
36381
36536
|
function convertToBase64(value) {
|
|
36382
36537
|
return value instanceof Uint8Array ? convertUint8ArrayToBase64(value) : value;
|
|
36383
36538
|
}
|
|
36539
|
+
function withoutTrailingSlash(url) {
|
|
36540
|
+
return url == null ? undefined : url.replace(/\/$/, "");
|
|
36541
|
+
}
|
|
36384
36542
|
|
|
36385
36543
|
// ../packages/internal/src/openai-compatible/chat/openai-compatible-chat-language-model.ts
|
|
36386
36544
|
var import_v464 = require("zod/v4");
|
|
@@ -37089,111 +37247,1395 @@ var createOpenAICompatibleChatChunkSchema = (errorSchema) => import_v464.z.union
|
|
|
37089
37247
|
]);
|
|
37090
37248
|
// ../packages/internal/src/openai-compatible/version.ts
|
|
37091
37249
|
var VERSION2 = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
|
|
37092
|
-
// src/
|
|
37093
|
-
|
|
37094
|
-
|
|
37095
|
-
|
|
37250
|
+
// ../packages/internal/src/openrouter-ai-sdk/chat/is-url.ts
|
|
37251
|
+
function isUrl({
|
|
37252
|
+
url,
|
|
37253
|
+
protocols
|
|
37254
|
+
}) {
|
|
37255
|
+
try {
|
|
37256
|
+
const urlObj = new URL(url);
|
|
37257
|
+
return protocols.has(urlObj.protocol);
|
|
37258
|
+
} catch (_) {
|
|
37259
|
+
return false;
|
|
37260
|
+
}
|
|
37261
|
+
}
|
|
37096
37262
|
|
|
37097
|
-
// ../
|
|
37263
|
+
// ../packages/internal/src/openrouter-ai-sdk/chat/file-url-utils.ts
|
|
37264
|
+
function getFileUrl({
|
|
37265
|
+
part,
|
|
37266
|
+
defaultMediaType
|
|
37267
|
+
}) {
|
|
37268
|
+
if (part.data instanceof Uint8Array) {
|
|
37269
|
+
const base64 = convertUint8ArrayToBase64(part.data);
|
|
37270
|
+
return `data:${part.mediaType ?? defaultMediaType};base64,${base64}`;
|
|
37271
|
+
}
|
|
37272
|
+
const stringUrl = part.data.toString();
|
|
37273
|
+
if (isUrl({
|
|
37274
|
+
url: stringUrl,
|
|
37275
|
+
protocols: new Set(["http:", "https:"])
|
|
37276
|
+
})) {
|
|
37277
|
+
return stringUrl;
|
|
37278
|
+
}
|
|
37279
|
+
return stringUrl.startsWith("data:") ? stringUrl : `data:${part.mediaType ?? defaultMediaType};base64,${stringUrl}`;
|
|
37280
|
+
}
|
|
37281
|
+
|
|
37282
|
+
// ../packages/internal/src/openrouter-ai-sdk/schemas/reasoning-details.ts
|
|
37098
37283
|
var import_v465 = require("zod/v4");
|
|
37099
|
-
var
|
|
37100
|
-
|
|
37101
|
-
|
|
37102
|
-
name: import_v465.z.string().nullable(),
|
|
37103
|
-
authToken: import_v465.z.string(),
|
|
37104
|
-
fingerprintId: import_v465.z.string(),
|
|
37105
|
-
fingerprintHash: import_v465.z.string()
|
|
37284
|
+
var ReasoningDetailSummarySchema = import_v465.z.object({
|
|
37285
|
+
type: import_v465.z.literal("reasoning.summary" /* Summary */),
|
|
37286
|
+
summary: import_v465.z.string()
|
|
37106
37287
|
});
|
|
37107
|
-
|
|
37108
|
-
|
|
37109
|
-
|
|
37110
|
-
|
|
37111
|
-
// src/env.ts
|
|
37112
|
-
init_paths();
|
|
37113
|
-
|
|
37114
|
-
// ../common/src/env-process.ts
|
|
37115
|
-
var getBaseEnv = () => ({
|
|
37116
|
-
SHELL: process.env.SHELL,
|
|
37117
|
-
COMSPEC: process.env.COMSPEC,
|
|
37118
|
-
HOME: process.env.HOME,
|
|
37119
|
-
USERPROFILE: process.env.USERPROFILE,
|
|
37120
|
-
APPDATA: process.env.APPDATA,
|
|
37121
|
-
XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME,
|
|
37122
|
-
TERM: process.env.TERM,
|
|
37123
|
-
TERM_PROGRAM: process.env.TERM_PROGRAM,
|
|
37124
|
-
TERM_BACKGROUND: process.env.TERM_BACKGROUND,
|
|
37125
|
-
TERMINAL_EMULATOR: process.env.TERMINAL_EMULATOR,
|
|
37126
|
-
COLORFGBG: process.env.COLORFGBG,
|
|
37127
|
-
NODE_ENV: "development",
|
|
37128
|
-
NODE_PATH: process.env.NODE_PATH,
|
|
37129
|
-
PATH: process.env.PATH
|
|
37288
|
+
var ReasoningDetailEncryptedSchema = import_v465.z.object({
|
|
37289
|
+
type: import_v465.z.literal("reasoning.encrypted" /* Encrypted */),
|
|
37290
|
+
data: import_v465.z.string()
|
|
37130
37291
|
});
|
|
37131
|
-
var
|
|
37132
|
-
|
|
37133
|
-
|
|
37134
|
-
|
|
37135
|
-
|
|
37136
|
-
|
|
37137
|
-
|
|
37138
|
-
|
|
37139
|
-
|
|
37140
|
-
|
|
37141
|
-
|
|
37142
|
-
|
|
37143
|
-
|
|
37144
|
-
|
|
37145
|
-
|
|
37146
|
-
|
|
37147
|
-
|
|
37148
|
-
|
|
37149
|
-
|
|
37150
|
-
|
|
37151
|
-
|
|
37152
|
-
|
|
37153
|
-
|
|
37154
|
-
|
|
37155
|
-
|
|
37156
|
-
|
|
37157
|
-
|
|
37158
|
-
|
|
37159
|
-
|
|
37160
|
-
|
|
37161
|
-
|
|
37162
|
-
|
|
37292
|
+
var ReasoningDetailTextSchema = import_v465.z.object({
|
|
37293
|
+
type: import_v465.z.literal("reasoning.text" /* Text */),
|
|
37294
|
+
text: import_v465.z.string().nullish(),
|
|
37295
|
+
signature: import_v465.z.string().nullish()
|
|
37296
|
+
});
|
|
37297
|
+
var ReasoningDetailUnionSchema = import_v465.z.union([
|
|
37298
|
+
ReasoningDetailSummarySchema,
|
|
37299
|
+
ReasoningDetailEncryptedSchema,
|
|
37300
|
+
ReasoningDetailTextSchema
|
|
37301
|
+
]);
|
|
37302
|
+
var ReasoningDetailsWithUnknownSchema = import_v465.z.union([
|
|
37303
|
+
ReasoningDetailUnionSchema,
|
|
37304
|
+
import_v465.z.unknown().transform(() => null)
|
|
37305
|
+
]);
|
|
37306
|
+
var ReasoningDetailArraySchema = import_v465.z.array(ReasoningDetailsWithUnknownSchema).transform((d) => d.filter((d2) => !!d2));
|
|
37307
|
+
|
|
37308
|
+
// ../packages/internal/src/openrouter-ai-sdk/chat/convert-to-openrouter-chat-messages.ts
|
|
37309
|
+
function getCacheControl(providerMetadata) {
|
|
37310
|
+
const anthropic = providerMetadata?.anthropic;
|
|
37311
|
+
const openrouter = providerMetadata?.openrouter;
|
|
37312
|
+
return openrouter?.cacheControl ?? openrouter?.cache_control ?? anthropic?.cacheControl ?? anthropic?.cache_control;
|
|
37313
|
+
}
|
|
37314
|
+
function convertToOpenRouterChatMessages(prompt2) {
|
|
37315
|
+
const messages = [];
|
|
37316
|
+
for (const { role, content, providerOptions } of prompt2) {
|
|
37317
|
+
switch (role) {
|
|
37318
|
+
case "system": {
|
|
37319
|
+
messages.push({
|
|
37320
|
+
role: "system",
|
|
37321
|
+
content,
|
|
37322
|
+
cache_control: getCacheControl(providerOptions)
|
|
37323
|
+
});
|
|
37324
|
+
break;
|
|
37325
|
+
}
|
|
37326
|
+
case "user": {
|
|
37327
|
+
const messageCacheControl = getCacheControl(providerOptions);
|
|
37328
|
+
const contentParts = content.map((part) => {
|
|
37329
|
+
const cacheControl = getCacheControl(part.providerOptions) ?? messageCacheControl;
|
|
37330
|
+
switch (part.type) {
|
|
37331
|
+
case "text":
|
|
37332
|
+
return {
|
|
37333
|
+
type: "text",
|
|
37334
|
+
text: part.text,
|
|
37335
|
+
cache_control: cacheControl
|
|
37336
|
+
};
|
|
37337
|
+
case "file": {
|
|
37338
|
+
if (part.mediaType?.startsWith("image/")) {
|
|
37339
|
+
const url = getFileUrl({
|
|
37340
|
+
part,
|
|
37341
|
+
defaultMediaType: "image/jpeg"
|
|
37342
|
+
});
|
|
37343
|
+
return {
|
|
37344
|
+
type: "image_url",
|
|
37345
|
+
image_url: {
|
|
37346
|
+
url
|
|
37347
|
+
},
|
|
37348
|
+
cache_control: cacheControl
|
|
37349
|
+
};
|
|
37350
|
+
}
|
|
37351
|
+
const fileName = String(part.providerOptions?.openrouter?.filename ?? part.filename ?? "");
|
|
37352
|
+
const fileData = getFileUrl({
|
|
37353
|
+
part,
|
|
37354
|
+
defaultMediaType: "application/pdf"
|
|
37355
|
+
});
|
|
37356
|
+
if (isUrl({
|
|
37357
|
+
url: fileData,
|
|
37358
|
+
protocols: new Set(["http:", "https:"])
|
|
37359
|
+
})) {
|
|
37360
|
+
return {
|
|
37361
|
+
type: "file",
|
|
37362
|
+
file: {
|
|
37363
|
+
filename: fileName,
|
|
37364
|
+
file_data: fileData
|
|
37365
|
+
}
|
|
37366
|
+
};
|
|
37367
|
+
}
|
|
37368
|
+
return {
|
|
37369
|
+
type: "file",
|
|
37370
|
+
file: {
|
|
37371
|
+
filename: fileName,
|
|
37372
|
+
file_data: fileData
|
|
37373
|
+
},
|
|
37374
|
+
cache_control: cacheControl
|
|
37375
|
+
};
|
|
37376
|
+
}
|
|
37377
|
+
default: {
|
|
37378
|
+
return {
|
|
37379
|
+
type: "text",
|
|
37380
|
+
text: "",
|
|
37381
|
+
cache_control: cacheControl
|
|
37382
|
+
};
|
|
37383
|
+
}
|
|
37384
|
+
}
|
|
37385
|
+
});
|
|
37386
|
+
messages.push({
|
|
37387
|
+
role: "user",
|
|
37388
|
+
content: contentParts
|
|
37389
|
+
});
|
|
37390
|
+
break;
|
|
37391
|
+
}
|
|
37392
|
+
case "assistant": {
|
|
37393
|
+
let text = "";
|
|
37394
|
+
let reasoning = "";
|
|
37395
|
+
const reasoningDetails = [];
|
|
37396
|
+
const toolCalls2 = [];
|
|
37397
|
+
for (const part of content) {
|
|
37398
|
+
switch (part.type) {
|
|
37399
|
+
case "text": {
|
|
37400
|
+
text += part.text;
|
|
37401
|
+
break;
|
|
37402
|
+
}
|
|
37403
|
+
case "tool-call": {
|
|
37404
|
+
toolCalls2.push({
|
|
37405
|
+
id: part.toolCallId,
|
|
37406
|
+
type: "function",
|
|
37407
|
+
function: {
|
|
37408
|
+
name: part.toolName,
|
|
37409
|
+
arguments: JSON.stringify(part.input)
|
|
37410
|
+
}
|
|
37411
|
+
});
|
|
37412
|
+
break;
|
|
37413
|
+
}
|
|
37414
|
+
case "reasoning": {
|
|
37415
|
+
reasoning += part.text;
|
|
37416
|
+
reasoningDetails.push({
|
|
37417
|
+
type: "reasoning.text" /* Text */,
|
|
37418
|
+
text: part.text
|
|
37419
|
+
});
|
|
37420
|
+
break;
|
|
37421
|
+
}
|
|
37422
|
+
case "file":
|
|
37423
|
+
break;
|
|
37424
|
+
default: {
|
|
37425
|
+
break;
|
|
37426
|
+
}
|
|
37427
|
+
}
|
|
37428
|
+
}
|
|
37429
|
+
messages.push({
|
|
37430
|
+
role: "assistant",
|
|
37431
|
+
content: text,
|
|
37432
|
+
tool_calls: toolCalls2.length > 0 ? toolCalls2 : undefined,
|
|
37433
|
+
reasoning: reasoning || undefined,
|
|
37434
|
+
reasoning_details: reasoningDetails.length > 0 ? reasoningDetails : undefined,
|
|
37435
|
+
cache_control: getCacheControl(providerOptions)
|
|
37436
|
+
});
|
|
37437
|
+
break;
|
|
37438
|
+
}
|
|
37439
|
+
case "tool": {
|
|
37440
|
+
for (const toolResponse of content) {
|
|
37441
|
+
const content2 = getToolResultContent(toolResponse);
|
|
37442
|
+
messages.push({
|
|
37443
|
+
role: "tool",
|
|
37444
|
+
tool_call_id: toolResponse.toolCallId,
|
|
37445
|
+
content: content2,
|
|
37446
|
+
cache_control: getCacheControl(providerOptions) ?? getCacheControl(toolResponse.providerOptions)
|
|
37447
|
+
});
|
|
37448
|
+
}
|
|
37449
|
+
break;
|
|
37450
|
+
}
|
|
37451
|
+
default: {
|
|
37452
|
+
break;
|
|
37453
|
+
}
|
|
37454
|
+
}
|
|
37455
|
+
}
|
|
37456
|
+
return messages;
|
|
37457
|
+
}
|
|
37458
|
+
function getToolResultContent(input) {
|
|
37459
|
+
return input.output.type === "text" ? input.output.value : JSON.stringify(input.output.value);
|
|
37460
|
+
}
|
|
37461
|
+
|
|
37462
|
+
// ../packages/internal/src/openrouter-ai-sdk/chat/get-tool-choice.ts
|
|
37463
|
+
var import_v466 = require("zod/v4");
|
|
37464
|
+
var ChatCompletionToolChoiceSchema = import_v466.z.union([
|
|
37465
|
+
import_v466.z.literal("auto"),
|
|
37466
|
+
import_v466.z.literal("none"),
|
|
37467
|
+
import_v466.z.literal("required"),
|
|
37468
|
+
import_v466.z.object({
|
|
37469
|
+
type: import_v466.z.literal("function"),
|
|
37470
|
+
function: import_v466.z.object({
|
|
37471
|
+
name: import_v466.z.string()
|
|
37472
|
+
})
|
|
37473
|
+
})
|
|
37474
|
+
]);
|
|
37475
|
+
function getChatCompletionToolChoice(toolChoice) {
|
|
37476
|
+
switch (toolChoice.type) {
|
|
37477
|
+
case "auto":
|
|
37478
|
+
case "none":
|
|
37479
|
+
case "required":
|
|
37480
|
+
return toolChoice.type;
|
|
37481
|
+
case "tool": {
|
|
37482
|
+
return {
|
|
37483
|
+
type: "function",
|
|
37484
|
+
function: { name: toolChoice.toolName }
|
|
37485
|
+
};
|
|
37486
|
+
}
|
|
37487
|
+
default: {
|
|
37488
|
+
throw new Error(`Invalid tool choice type: ${toolChoice}`);
|
|
37489
|
+
}
|
|
37490
|
+
}
|
|
37491
|
+
}
|
|
37492
|
+
|
|
37493
|
+
// ../packages/internal/src/openrouter-ai-sdk/chat/schemas.ts
|
|
37494
|
+
var import_v468 = require("zod/v4");
|
|
37495
|
+
|
|
37496
|
+
// ../packages/internal/src/openrouter-ai-sdk/schemas/error-response.ts
|
|
37497
|
+
var import_v467 = require("zod/v4");
|
|
37498
|
+
var OpenRouterErrorResponseSchema = import_v467.z.object({
|
|
37499
|
+
error: import_v467.z.object({
|
|
37500
|
+
code: import_v467.z.union([import_v467.z.string(), import_v467.z.number()]).nullable().optional().default(null),
|
|
37501
|
+
message: import_v467.z.string(),
|
|
37502
|
+
type: import_v467.z.string().nullable().optional().default(null),
|
|
37503
|
+
param: import_v467.z.any().nullable().optional().default(null)
|
|
37504
|
+
})
|
|
37505
|
+
});
|
|
37506
|
+
var openrouterFailedResponseHandler = createJsonErrorResponseHandler({
|
|
37507
|
+
errorSchema: OpenRouterErrorResponseSchema,
|
|
37508
|
+
errorToMessage: (data) => data.error.message
|
|
37509
|
+
});
|
|
37510
|
+
|
|
37511
|
+
// ../packages/internal/src/openrouter-ai-sdk/chat/schemas.ts
|
|
37512
|
+
var OpenRouterChatCompletionBaseResponseSchema = import_v468.z.object({
|
|
37513
|
+
id: import_v468.z.string().optional(),
|
|
37514
|
+
model: import_v468.z.string().optional(),
|
|
37515
|
+
provider: import_v468.z.string().optional(),
|
|
37516
|
+
usage: import_v468.z.object({
|
|
37517
|
+
prompt_tokens: import_v468.z.number(),
|
|
37518
|
+
prompt_tokens_details: import_v468.z.object({
|
|
37519
|
+
cached_tokens: import_v468.z.number()
|
|
37520
|
+
}).nullish(),
|
|
37521
|
+
completion_tokens: import_v468.z.number(),
|
|
37522
|
+
completion_tokens_details: import_v468.z.object({
|
|
37523
|
+
reasoning_tokens: import_v468.z.number()
|
|
37524
|
+
}).nullish(),
|
|
37525
|
+
total_tokens: import_v468.z.number(),
|
|
37526
|
+
cost: import_v468.z.number().optional(),
|
|
37527
|
+
cost_details: import_v468.z.object({
|
|
37528
|
+
upstream_inference_cost: import_v468.z.number().nullish()
|
|
37529
|
+
}).nullish()
|
|
37530
|
+
}).nullish()
|
|
37531
|
+
});
|
|
37532
|
+
var OpenRouterNonStreamChatCompletionResponseSchema = OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
37533
|
+
choices: import_v468.z.array(import_v468.z.object({
|
|
37534
|
+
message: import_v468.z.object({
|
|
37535
|
+
role: import_v468.z.literal("assistant"),
|
|
37536
|
+
content: import_v468.z.string().nullable().optional(),
|
|
37537
|
+
reasoning: import_v468.z.string().nullable().optional(),
|
|
37538
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
37539
|
+
tool_calls: import_v468.z.array(import_v468.z.object({
|
|
37540
|
+
id: import_v468.z.string().optional().nullable(),
|
|
37541
|
+
type: import_v468.z.literal("function"),
|
|
37542
|
+
function: import_v468.z.object({
|
|
37543
|
+
name: import_v468.z.string(),
|
|
37544
|
+
arguments: import_v468.z.string()
|
|
37545
|
+
})
|
|
37546
|
+
})).optional(),
|
|
37547
|
+
annotations: import_v468.z.array(import_v468.z.object({
|
|
37548
|
+
type: import_v468.z.enum(["url_citation"]),
|
|
37549
|
+
url_citation: import_v468.z.object({
|
|
37550
|
+
end_index: import_v468.z.number(),
|
|
37551
|
+
start_index: import_v468.z.number(),
|
|
37552
|
+
title: import_v468.z.string(),
|
|
37553
|
+
url: import_v468.z.string(),
|
|
37554
|
+
content: import_v468.z.string().optional()
|
|
37555
|
+
})
|
|
37556
|
+
})).nullish()
|
|
37557
|
+
}),
|
|
37558
|
+
index: import_v468.z.number().nullish(),
|
|
37559
|
+
logprobs: import_v468.z.object({
|
|
37560
|
+
content: import_v468.z.array(import_v468.z.object({
|
|
37561
|
+
token: import_v468.z.string(),
|
|
37562
|
+
logprob: import_v468.z.number(),
|
|
37563
|
+
top_logprobs: import_v468.z.array(import_v468.z.object({
|
|
37564
|
+
token: import_v468.z.string(),
|
|
37565
|
+
logprob: import_v468.z.number()
|
|
37566
|
+
}))
|
|
37567
|
+
})).nullable()
|
|
37568
|
+
}).nullable().optional(),
|
|
37569
|
+
finish_reason: import_v468.z.string().optional().nullable()
|
|
37570
|
+
}))
|
|
37571
|
+
});
|
|
37572
|
+
var OpenRouterStreamChatCompletionChunkSchema = import_v468.z.union([
|
|
37573
|
+
OpenRouterChatCompletionBaseResponseSchema.extend({
|
|
37574
|
+
choices: import_v468.z.array(import_v468.z.object({
|
|
37575
|
+
delta: import_v468.z.object({
|
|
37576
|
+
role: import_v468.z.enum(["assistant"]).optional(),
|
|
37577
|
+
content: import_v468.z.string().nullish(),
|
|
37578
|
+
reasoning: import_v468.z.string().nullish().optional(),
|
|
37579
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
37580
|
+
tool_calls: import_v468.z.array(import_v468.z.object({
|
|
37581
|
+
index: import_v468.z.number().nullish(),
|
|
37582
|
+
id: import_v468.z.string().nullish(),
|
|
37583
|
+
type: import_v468.z.literal("function").optional(),
|
|
37584
|
+
function: import_v468.z.object({
|
|
37585
|
+
name: import_v468.z.string().nullish(),
|
|
37586
|
+
arguments: import_v468.z.string().nullish()
|
|
37587
|
+
})
|
|
37588
|
+
})).nullish(),
|
|
37589
|
+
annotations: import_v468.z.array(import_v468.z.object({
|
|
37590
|
+
type: import_v468.z.enum(["url_citation"]),
|
|
37591
|
+
url_citation: import_v468.z.object({
|
|
37592
|
+
end_index: import_v468.z.number(),
|
|
37593
|
+
start_index: import_v468.z.number(),
|
|
37594
|
+
title: import_v468.z.string(),
|
|
37595
|
+
url: import_v468.z.string(),
|
|
37596
|
+
content: import_v468.z.string().optional()
|
|
37597
|
+
})
|
|
37598
|
+
})).nullish()
|
|
37599
|
+
}).nullish(),
|
|
37600
|
+
logprobs: import_v468.z.object({
|
|
37601
|
+
content: import_v468.z.array(import_v468.z.object({
|
|
37602
|
+
token: import_v468.z.string(),
|
|
37603
|
+
logprob: import_v468.z.number(),
|
|
37604
|
+
top_logprobs: import_v468.z.array(import_v468.z.object({
|
|
37605
|
+
token: import_v468.z.string(),
|
|
37606
|
+
logprob: import_v468.z.number()
|
|
37607
|
+
}))
|
|
37608
|
+
})).nullable()
|
|
37609
|
+
}).nullish(),
|
|
37610
|
+
finish_reason: import_v468.z.string().nullable().optional(),
|
|
37611
|
+
index: import_v468.z.number().nullish()
|
|
37612
|
+
}))
|
|
37613
|
+
}),
|
|
37614
|
+
OpenRouterErrorResponseSchema
|
|
37615
|
+
]);
|
|
37616
|
+
|
|
37617
|
+
// ../packages/internal/src/openrouter-ai-sdk/utils/map-finish-reason.ts
|
|
37618
|
+
function mapOpenRouterFinishReason(finishReason) {
|
|
37619
|
+
switch (finishReason) {
|
|
37620
|
+
case "stop":
|
|
37621
|
+
return "stop";
|
|
37622
|
+
case "length":
|
|
37623
|
+
return "length";
|
|
37624
|
+
case "content_filter":
|
|
37625
|
+
return "content-filter";
|
|
37626
|
+
case "function_call":
|
|
37627
|
+
case "tool_calls":
|
|
37628
|
+
return "tool-calls";
|
|
37629
|
+
default:
|
|
37630
|
+
return "unknown";
|
|
37631
|
+
}
|
|
37632
|
+
}
|
|
37633
|
+
|
|
37634
|
+
// ../packages/internal/src/openrouter-ai-sdk/chat/index.ts
|
|
37635
|
+
class OpenRouterChatLanguageModel {
|
|
37636
|
+
specificationVersion = "v2";
|
|
37637
|
+
provider = "openrouter";
|
|
37638
|
+
defaultObjectGenerationMode = "tool";
|
|
37639
|
+
modelId;
|
|
37640
|
+
supportedUrls = {
|
|
37641
|
+
"image/*": [
|
|
37642
|
+
/^data:image\/[a-zA-Z]+;base64,/,
|
|
37643
|
+
/^https?:\/\/.+\.(jpg|jpeg|png|gif|webp)$/i
|
|
37644
|
+
],
|
|
37645
|
+
"application/*": [/^data:application\//, /^https?:\/\/.+$/]
|
|
37646
|
+
};
|
|
37647
|
+
settings;
|
|
37648
|
+
config;
|
|
37649
|
+
constructor(modelId, settings, config) {
|
|
37650
|
+
this.modelId = modelId;
|
|
37651
|
+
this.settings = settings;
|
|
37652
|
+
this.config = config;
|
|
37653
|
+
}
|
|
37654
|
+
getArgs({
|
|
37655
|
+
prompt: prompt2,
|
|
37656
|
+
maxOutputTokens,
|
|
37657
|
+
temperature,
|
|
37658
|
+
topP,
|
|
37659
|
+
frequencyPenalty,
|
|
37660
|
+
presencePenalty,
|
|
37661
|
+
seed,
|
|
37662
|
+
stopSequences,
|
|
37663
|
+
responseFormat,
|
|
37664
|
+
topK,
|
|
37665
|
+
tools,
|
|
37666
|
+
toolChoice
|
|
37667
|
+
}) {
|
|
37668
|
+
const baseArgs = {
|
|
37669
|
+
model: this.modelId,
|
|
37670
|
+
models: this.settings.models,
|
|
37671
|
+
logit_bias: this.settings.logitBias,
|
|
37672
|
+
logprobs: this.settings.logprobs === true || typeof this.settings.logprobs === "number" ? true : undefined,
|
|
37673
|
+
top_logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : undefined : undefined,
|
|
37674
|
+
user: this.settings.user,
|
|
37675
|
+
parallel_tool_calls: this.settings.parallelToolCalls,
|
|
37676
|
+
max_tokens: maxOutputTokens,
|
|
37677
|
+
temperature,
|
|
37678
|
+
top_p: topP,
|
|
37679
|
+
frequency_penalty: frequencyPenalty,
|
|
37680
|
+
presence_penalty: presencePenalty,
|
|
37681
|
+
seed,
|
|
37682
|
+
...this.modelId === "x-ai/grok-code-fast-1" ? {} : { stop: stopSequences },
|
|
37683
|
+
response_format: responseFormat,
|
|
37684
|
+
top_k: topK,
|
|
37685
|
+
messages: convertToOpenRouterChatMessages(prompt2),
|
|
37686
|
+
include_reasoning: this.settings.includeReasoning,
|
|
37687
|
+
reasoning: this.settings.reasoning,
|
|
37688
|
+
usage: this.settings.usage,
|
|
37689
|
+
plugins: this.settings.plugins,
|
|
37690
|
+
web_search_options: this.settings.web_search_options,
|
|
37691
|
+
provider: this.settings.provider,
|
|
37692
|
+
...this.config.extraBody,
|
|
37693
|
+
...this.settings.extraBody
|
|
37694
|
+
};
|
|
37695
|
+
if (responseFormat?.type === "json" && responseFormat.schema != null) {
|
|
37696
|
+
return {
|
|
37697
|
+
...baseArgs,
|
|
37698
|
+
response_format: {
|
|
37699
|
+
type: "json_schema",
|
|
37700
|
+
json_schema: {
|
|
37701
|
+
schema: responseFormat.schema,
|
|
37702
|
+
strict: true,
|
|
37703
|
+
name: responseFormat.name ?? "response",
|
|
37704
|
+
...responseFormat.description && {
|
|
37705
|
+
description: responseFormat.description
|
|
37706
|
+
}
|
|
37707
|
+
}
|
|
37708
|
+
}
|
|
37709
|
+
};
|
|
37710
|
+
}
|
|
37711
|
+
if (tools && tools.length > 0) {
|
|
37712
|
+
const mappedTools = tools.filter((tool) => tool.type === "function").map((tool) => ({
|
|
37713
|
+
type: "function",
|
|
37714
|
+
function: {
|
|
37715
|
+
name: tool.name,
|
|
37716
|
+
description: tool.description,
|
|
37717
|
+
parameters: tool.inputSchema
|
|
37718
|
+
}
|
|
37719
|
+
}));
|
|
37720
|
+
return {
|
|
37721
|
+
...baseArgs,
|
|
37722
|
+
tools: mappedTools,
|
|
37723
|
+
tool_choice: toolChoice ? getChatCompletionToolChoice(toolChoice) : undefined
|
|
37724
|
+
};
|
|
37725
|
+
}
|
|
37726
|
+
return baseArgs;
|
|
37727
|
+
}
|
|
37728
|
+
async doGenerate(options) {
|
|
37729
|
+
const providerOptions = options.providerOptions || {};
|
|
37730
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
37731
|
+
const args = {
|
|
37732
|
+
...this.getArgs(options),
|
|
37733
|
+
...openrouterOptions
|
|
37734
|
+
};
|
|
37735
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
37736
|
+
url: this.config.url({
|
|
37737
|
+
path: "/chat/completions",
|
|
37738
|
+
modelId: this.modelId
|
|
37739
|
+
}),
|
|
37740
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
37741
|
+
body: args,
|
|
37742
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
37743
|
+
successfulResponseHandler: createJsonResponseHandler(OpenRouterNonStreamChatCompletionResponseSchema),
|
|
37744
|
+
abortSignal: options.abortSignal,
|
|
37745
|
+
fetch: this.config.fetch
|
|
37746
|
+
});
|
|
37747
|
+
const choice = response.choices[0];
|
|
37748
|
+
if (!choice) {
|
|
37749
|
+
throw new Error("No choice in response");
|
|
37750
|
+
}
|
|
37751
|
+
const usageInfo = response.usage ? {
|
|
37752
|
+
inputTokens: response.usage.prompt_tokens ?? 0,
|
|
37753
|
+
outputTokens: response.usage.completion_tokens ?? 0,
|
|
37754
|
+
totalTokens: (response.usage.prompt_tokens ?? 0) + (response.usage.completion_tokens ?? 0),
|
|
37755
|
+
reasoningTokens: response.usage.completion_tokens_details?.reasoning_tokens ?? 0,
|
|
37756
|
+
cachedInputTokens: response.usage.prompt_tokens_details?.cached_tokens ?? 0
|
|
37757
|
+
} : {
|
|
37758
|
+
inputTokens: 0,
|
|
37759
|
+
outputTokens: 0,
|
|
37760
|
+
totalTokens: 0,
|
|
37761
|
+
reasoningTokens: 0,
|
|
37762
|
+
cachedInputTokens: 0
|
|
37763
|
+
};
|
|
37764
|
+
const reasoningDetails = choice.message.reasoning_details ?? [];
|
|
37765
|
+
const reasoning = reasoningDetails.length > 0 ? reasoningDetails.map((detail) => {
|
|
37766
|
+
switch (detail.type) {
|
|
37767
|
+
case "reasoning.text" /* Text */: {
|
|
37768
|
+
if (detail.text) {
|
|
37769
|
+
return {
|
|
37770
|
+
type: "reasoning",
|
|
37771
|
+
text: detail.text
|
|
37772
|
+
};
|
|
37773
|
+
}
|
|
37774
|
+
break;
|
|
37775
|
+
}
|
|
37776
|
+
case "reasoning.summary" /* Summary */: {
|
|
37777
|
+
if (detail.summary) {
|
|
37778
|
+
return {
|
|
37779
|
+
type: "reasoning",
|
|
37780
|
+
text: detail.summary
|
|
37781
|
+
};
|
|
37782
|
+
}
|
|
37783
|
+
break;
|
|
37784
|
+
}
|
|
37785
|
+
case "reasoning.encrypted" /* Encrypted */: {
|
|
37786
|
+
if (detail.data) {
|
|
37787
|
+
return {
|
|
37788
|
+
type: "reasoning",
|
|
37789
|
+
text: "[REDACTED]"
|
|
37790
|
+
};
|
|
37791
|
+
}
|
|
37792
|
+
break;
|
|
37793
|
+
}
|
|
37794
|
+
default: {}
|
|
37795
|
+
}
|
|
37796
|
+
return null;
|
|
37797
|
+
}).filter((p) => p !== null) : choice.message.reasoning ? [
|
|
37798
|
+
{
|
|
37799
|
+
type: "reasoning",
|
|
37800
|
+
text: choice.message.reasoning
|
|
37801
|
+
}
|
|
37802
|
+
] : [];
|
|
37803
|
+
const content = [];
|
|
37804
|
+
content.push(...reasoning);
|
|
37805
|
+
if (choice.message.content) {
|
|
37806
|
+
content.push({
|
|
37807
|
+
type: "text",
|
|
37808
|
+
text: choice.message.content
|
|
37809
|
+
});
|
|
37810
|
+
}
|
|
37811
|
+
if (choice.message.tool_calls) {
|
|
37812
|
+
for (const toolCall of choice.message.tool_calls) {
|
|
37813
|
+
content.push({
|
|
37814
|
+
type: "tool-call",
|
|
37815
|
+
toolCallId: toolCall.id ?? generateId(),
|
|
37816
|
+
toolName: toolCall.function.name,
|
|
37817
|
+
input: toolCall.function.arguments
|
|
37818
|
+
});
|
|
37819
|
+
}
|
|
37820
|
+
}
|
|
37821
|
+
if (choice.message.annotations) {
|
|
37822
|
+
for (const annotation of choice.message.annotations) {
|
|
37823
|
+
if (annotation.type === "url_citation") {
|
|
37824
|
+
content.push({
|
|
37825
|
+
type: "source",
|
|
37826
|
+
sourceType: "url",
|
|
37827
|
+
id: annotation.url_citation.url,
|
|
37828
|
+
url: annotation.url_citation.url,
|
|
37829
|
+
title: annotation.url_citation.title,
|
|
37830
|
+
providerMetadata: {
|
|
37831
|
+
openrouter: {
|
|
37832
|
+
content: annotation.url_citation.content || ""
|
|
37833
|
+
}
|
|
37834
|
+
}
|
|
37835
|
+
});
|
|
37836
|
+
}
|
|
37837
|
+
}
|
|
37838
|
+
}
|
|
37839
|
+
return {
|
|
37840
|
+
content,
|
|
37841
|
+
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
37842
|
+
usage: usageInfo,
|
|
37843
|
+
warnings: [],
|
|
37844
|
+
providerMetadata: {
|
|
37845
|
+
openrouter: {
|
|
37846
|
+
provider: response.provider ?? "",
|
|
37847
|
+
usage: {
|
|
37848
|
+
promptTokens: usageInfo.inputTokens ?? 0,
|
|
37849
|
+
completionTokens: usageInfo.outputTokens ?? 0,
|
|
37850
|
+
totalTokens: usageInfo.totalTokens ?? 0,
|
|
37851
|
+
cost: response.usage?.cost,
|
|
37852
|
+
promptTokensDetails: {
|
|
37853
|
+
cachedTokens: response.usage?.prompt_tokens_details?.cached_tokens ?? 0
|
|
37854
|
+
},
|
|
37855
|
+
completionTokensDetails: {
|
|
37856
|
+
reasoningTokens: response.usage?.completion_tokens_details?.reasoning_tokens ?? 0
|
|
37857
|
+
},
|
|
37858
|
+
costDetails: {
|
|
37859
|
+
upstreamInferenceCost: response.usage?.cost_details?.upstream_inference_cost ?? 0
|
|
37860
|
+
}
|
|
37861
|
+
}
|
|
37862
|
+
}
|
|
37863
|
+
},
|
|
37864
|
+
request: { body: args },
|
|
37865
|
+
response: {
|
|
37866
|
+
id: response.id,
|
|
37867
|
+
modelId: response.model,
|
|
37868
|
+
headers: responseHeaders
|
|
37869
|
+
}
|
|
37870
|
+
};
|
|
37871
|
+
}
|
|
37872
|
+
async doStream(options) {
|
|
37873
|
+
const providerOptions = options.providerOptions || {};
|
|
37874
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
37875
|
+
const args = {
|
|
37876
|
+
...this.getArgs(options),
|
|
37877
|
+
...openrouterOptions
|
|
37878
|
+
};
|
|
37879
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
37880
|
+
url: this.config.url({
|
|
37881
|
+
path: "/chat/completions",
|
|
37882
|
+
modelId: this.modelId
|
|
37883
|
+
}),
|
|
37884
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
37885
|
+
body: {
|
|
37886
|
+
...args,
|
|
37887
|
+
stream: true,
|
|
37888
|
+
stream_options: this.config.compatibility === "strict" ? {
|
|
37889
|
+
include_usage: true,
|
|
37890
|
+
...this.settings.usage?.include ? { include_usage: true } : {}
|
|
37891
|
+
} : undefined
|
|
37892
|
+
},
|
|
37893
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
37894
|
+
successfulResponseHandler: createEventSourceResponseHandler(OpenRouterStreamChatCompletionChunkSchema),
|
|
37895
|
+
abortSignal: options.abortSignal,
|
|
37896
|
+
fetch: this.config.fetch
|
|
37897
|
+
});
|
|
37898
|
+
const toolCalls2 = [];
|
|
37899
|
+
let finishReason = "other";
|
|
37900
|
+
const usage = {
|
|
37901
|
+
inputTokens: Number.NaN,
|
|
37902
|
+
outputTokens: Number.NaN,
|
|
37903
|
+
totalTokens: Number.NaN,
|
|
37904
|
+
reasoningTokens: Number.NaN,
|
|
37905
|
+
cachedInputTokens: Number.NaN
|
|
37906
|
+
};
|
|
37907
|
+
const openrouterUsage = {};
|
|
37908
|
+
let textStarted = false;
|
|
37909
|
+
let reasoningStarted = false;
|
|
37910
|
+
let textId;
|
|
37911
|
+
let reasoningId;
|
|
37912
|
+
let openrouterResponseId;
|
|
37913
|
+
let provider;
|
|
37914
|
+
return {
|
|
37915
|
+
stream: response.pipeThrough(new TransformStream({
|
|
37916
|
+
transform(chunk, controller) {
|
|
37917
|
+
if (!chunk.success) {
|
|
37918
|
+
finishReason = "error";
|
|
37919
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
37920
|
+
return;
|
|
37921
|
+
}
|
|
37922
|
+
const value = chunk.value;
|
|
37923
|
+
if ("error" in value) {
|
|
37924
|
+
finishReason = "error";
|
|
37925
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
37926
|
+
return;
|
|
37927
|
+
}
|
|
37928
|
+
if (value.provider) {
|
|
37929
|
+
provider = value.provider;
|
|
37930
|
+
}
|
|
37931
|
+
if (value.id) {
|
|
37932
|
+
openrouterResponseId = value.id;
|
|
37933
|
+
controller.enqueue({
|
|
37934
|
+
type: "response-metadata",
|
|
37935
|
+
id: value.id
|
|
37936
|
+
});
|
|
37937
|
+
}
|
|
37938
|
+
if (value.model) {
|
|
37939
|
+
controller.enqueue({
|
|
37940
|
+
type: "response-metadata",
|
|
37941
|
+
modelId: value.model
|
|
37942
|
+
});
|
|
37943
|
+
}
|
|
37944
|
+
if (value.usage != null) {
|
|
37945
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
37946
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
37947
|
+
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
37948
|
+
openrouterUsage.promptTokens = value.usage.prompt_tokens;
|
|
37949
|
+
if (value.usage.prompt_tokens_details) {
|
|
37950
|
+
const cachedInputTokens = value.usage.prompt_tokens_details.cached_tokens ?? 0;
|
|
37951
|
+
usage.cachedInputTokens = cachedInputTokens;
|
|
37952
|
+
openrouterUsage.promptTokensDetails = {
|
|
37953
|
+
cachedTokens: cachedInputTokens
|
|
37954
|
+
};
|
|
37955
|
+
}
|
|
37956
|
+
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
37957
|
+
if (value.usage.completion_tokens_details) {
|
|
37958
|
+
const reasoningTokens = value.usage.completion_tokens_details.reasoning_tokens ?? 0;
|
|
37959
|
+
usage.reasoningTokens = reasoningTokens;
|
|
37960
|
+
openrouterUsage.completionTokensDetails = {
|
|
37961
|
+
reasoningTokens
|
|
37962
|
+
};
|
|
37963
|
+
}
|
|
37964
|
+
const upstreamInferenceCost = value.usage.cost_details?.upstream_inference_cost;
|
|
37965
|
+
if (upstreamInferenceCost != null && upstreamInferenceCost !== undefined) {
|
|
37966
|
+
openrouterUsage.costDetails = {
|
|
37967
|
+
upstreamInferenceCost
|
|
37968
|
+
};
|
|
37969
|
+
}
|
|
37970
|
+
if (value.usage.cost !== undefined) {
|
|
37971
|
+
openrouterUsage.cost = value.usage.cost;
|
|
37972
|
+
}
|
|
37973
|
+
openrouterUsage.totalTokens = value.usage.total_tokens;
|
|
37974
|
+
}
|
|
37975
|
+
const choice = value.choices[0];
|
|
37976
|
+
if (choice?.finish_reason != null) {
|
|
37977
|
+
finishReason = mapOpenRouterFinishReason(choice.finish_reason);
|
|
37978
|
+
}
|
|
37979
|
+
if (choice?.delta == null) {
|
|
37980
|
+
return;
|
|
37981
|
+
}
|
|
37982
|
+
const delta = choice.delta;
|
|
37983
|
+
const emitReasoningChunk = (chunkText) => {
|
|
37984
|
+
if (!reasoningStarted) {
|
|
37985
|
+
reasoningId = openrouterResponseId || generateId();
|
|
37986
|
+
controller.enqueue({
|
|
37987
|
+
type: "reasoning-start",
|
|
37988
|
+
id: reasoningId
|
|
37989
|
+
});
|
|
37990
|
+
reasoningStarted = true;
|
|
37991
|
+
}
|
|
37992
|
+
controller.enqueue({
|
|
37993
|
+
type: "reasoning-delta",
|
|
37994
|
+
delta: chunkText,
|
|
37995
|
+
id: reasoningId || generateId()
|
|
37996
|
+
});
|
|
37997
|
+
};
|
|
37998
|
+
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
37999
|
+
for (const detail of delta.reasoning_details) {
|
|
38000
|
+
switch (detail.type) {
|
|
38001
|
+
case "reasoning.text" /* Text */: {
|
|
38002
|
+
if (detail.text) {
|
|
38003
|
+
emitReasoningChunk(detail.text);
|
|
38004
|
+
}
|
|
38005
|
+
break;
|
|
38006
|
+
}
|
|
38007
|
+
case "reasoning.encrypted" /* Encrypted */: {
|
|
38008
|
+
if (detail.data) {
|
|
38009
|
+
emitReasoningChunk("[REDACTED]");
|
|
38010
|
+
}
|
|
38011
|
+
break;
|
|
38012
|
+
}
|
|
38013
|
+
case "reasoning.summary" /* Summary */: {
|
|
38014
|
+
if (detail.summary) {
|
|
38015
|
+
emitReasoningChunk(detail.summary);
|
|
38016
|
+
}
|
|
38017
|
+
break;
|
|
38018
|
+
}
|
|
38019
|
+
default: {
|
|
38020
|
+
break;
|
|
38021
|
+
}
|
|
38022
|
+
}
|
|
38023
|
+
}
|
|
38024
|
+
} else if (delta.reasoning) {
|
|
38025
|
+
emitReasoningChunk(delta.reasoning);
|
|
38026
|
+
}
|
|
38027
|
+
if (delta.content) {
|
|
38028
|
+
if (reasoningStarted && !textStarted) {
|
|
38029
|
+
controller.enqueue({
|
|
38030
|
+
type: "reasoning-end",
|
|
38031
|
+
id: reasoningId || generateId()
|
|
38032
|
+
});
|
|
38033
|
+
reasoningStarted = false;
|
|
38034
|
+
}
|
|
38035
|
+
if (!textStarted) {
|
|
38036
|
+
textId = openrouterResponseId || generateId();
|
|
38037
|
+
controller.enqueue({
|
|
38038
|
+
type: "text-start",
|
|
38039
|
+
id: textId
|
|
38040
|
+
});
|
|
38041
|
+
textStarted = true;
|
|
38042
|
+
}
|
|
38043
|
+
controller.enqueue({
|
|
38044
|
+
type: "text-delta",
|
|
38045
|
+
delta: delta.content,
|
|
38046
|
+
id: textId || generateId()
|
|
38047
|
+
});
|
|
38048
|
+
}
|
|
38049
|
+
if (delta.annotations) {
|
|
38050
|
+
for (const annotation of delta.annotations) {
|
|
38051
|
+
if (annotation.type === "url_citation") {
|
|
38052
|
+
controller.enqueue({
|
|
38053
|
+
type: "source",
|
|
38054
|
+
sourceType: "url",
|
|
38055
|
+
id: annotation.url_citation.url,
|
|
38056
|
+
url: annotation.url_citation.url,
|
|
38057
|
+
title: annotation.url_citation.title,
|
|
38058
|
+
providerMetadata: {
|
|
38059
|
+
openrouter: {
|
|
38060
|
+
content: annotation.url_citation.content || ""
|
|
38061
|
+
}
|
|
38062
|
+
}
|
|
38063
|
+
});
|
|
38064
|
+
}
|
|
38065
|
+
}
|
|
38066
|
+
}
|
|
38067
|
+
if (delta.tool_calls != null) {
|
|
38068
|
+
for (const toolCallDelta of delta.tool_calls) {
|
|
38069
|
+
const index = toolCallDelta.index ?? toolCalls2.length - 1;
|
|
38070
|
+
if (toolCalls2[index] == null) {
|
|
38071
|
+
if (toolCallDelta.type !== "function") {
|
|
38072
|
+
throw new InvalidResponseDataError({
|
|
38073
|
+
data: toolCallDelta,
|
|
38074
|
+
message: `Expected 'function' type.`
|
|
38075
|
+
});
|
|
38076
|
+
}
|
|
38077
|
+
if (toolCallDelta.id == null) {
|
|
38078
|
+
throw new InvalidResponseDataError({
|
|
38079
|
+
data: toolCallDelta,
|
|
38080
|
+
message: `Expected 'id' to be a string.`
|
|
38081
|
+
});
|
|
38082
|
+
}
|
|
38083
|
+
if (toolCallDelta.function?.name == null) {
|
|
38084
|
+
throw new InvalidResponseDataError({
|
|
38085
|
+
data: toolCallDelta,
|
|
38086
|
+
message: `Expected 'function.name' to be a string.`
|
|
38087
|
+
});
|
|
38088
|
+
}
|
|
38089
|
+
toolCalls2[index] = {
|
|
38090
|
+
id: toolCallDelta.id,
|
|
38091
|
+
type: "function",
|
|
38092
|
+
function: {
|
|
38093
|
+
name: toolCallDelta.function.name,
|
|
38094
|
+
arguments: toolCallDelta.function.arguments ?? ""
|
|
38095
|
+
},
|
|
38096
|
+
inputStarted: false,
|
|
38097
|
+
sent: false
|
|
38098
|
+
};
|
|
38099
|
+
const toolCall2 = toolCalls2[index];
|
|
38100
|
+
if (toolCall2 == null) {
|
|
38101
|
+
throw new Error("Tool call is missing");
|
|
38102
|
+
}
|
|
38103
|
+
if (toolCall2.function?.name != null && toolCall2.function?.arguments != null && isParsableJson(toolCall2.function.arguments)) {
|
|
38104
|
+
toolCall2.inputStarted = true;
|
|
38105
|
+
controller.enqueue({
|
|
38106
|
+
type: "tool-input-start",
|
|
38107
|
+
id: toolCall2.id,
|
|
38108
|
+
toolName: toolCall2.function.name
|
|
38109
|
+
});
|
|
38110
|
+
controller.enqueue({
|
|
38111
|
+
type: "tool-input-delta",
|
|
38112
|
+
id: toolCall2.id,
|
|
38113
|
+
delta: toolCall2.function.arguments
|
|
38114
|
+
});
|
|
38115
|
+
controller.enqueue({
|
|
38116
|
+
type: "tool-input-end",
|
|
38117
|
+
id: toolCall2.id
|
|
38118
|
+
});
|
|
38119
|
+
controller.enqueue({
|
|
38120
|
+
type: "tool-call",
|
|
38121
|
+
toolCallId: toolCall2.id,
|
|
38122
|
+
toolName: toolCall2.function.name,
|
|
38123
|
+
input: toolCall2.function.arguments
|
|
38124
|
+
});
|
|
38125
|
+
toolCall2.sent = true;
|
|
38126
|
+
}
|
|
38127
|
+
continue;
|
|
38128
|
+
}
|
|
38129
|
+
const toolCall = toolCalls2[index];
|
|
38130
|
+
if (toolCall == null) {
|
|
38131
|
+
throw new Error("Tool call is missing");
|
|
38132
|
+
}
|
|
38133
|
+
if (!toolCall.inputStarted) {
|
|
38134
|
+
toolCall.inputStarted = true;
|
|
38135
|
+
controller.enqueue({
|
|
38136
|
+
type: "tool-input-start",
|
|
38137
|
+
id: toolCall.id,
|
|
38138
|
+
toolName: toolCall.function.name
|
|
38139
|
+
});
|
|
38140
|
+
}
|
|
38141
|
+
if (toolCallDelta.function?.arguments != null) {
|
|
38142
|
+
toolCall.function.arguments += toolCallDelta.function?.arguments ?? "";
|
|
38143
|
+
}
|
|
38144
|
+
controller.enqueue({
|
|
38145
|
+
type: "tool-input-delta",
|
|
38146
|
+
id: toolCall.id,
|
|
38147
|
+
delta: toolCallDelta.function.arguments ?? ""
|
|
38148
|
+
});
|
|
38149
|
+
if (toolCall.function?.name != null && toolCall.function?.arguments != null && isParsableJson(toolCall.function.arguments)) {
|
|
38150
|
+
controller.enqueue({
|
|
38151
|
+
type: "tool-call",
|
|
38152
|
+
toolCallId: toolCall.id ?? generateId(),
|
|
38153
|
+
toolName: toolCall.function.name,
|
|
38154
|
+
input: toolCall.function.arguments
|
|
38155
|
+
});
|
|
38156
|
+
toolCall.sent = true;
|
|
38157
|
+
}
|
|
38158
|
+
}
|
|
38159
|
+
}
|
|
38160
|
+
},
|
|
38161
|
+
flush(controller) {
|
|
38162
|
+
if (finishReason === "tool-calls") {
|
|
38163
|
+
for (const toolCall of toolCalls2) {
|
|
38164
|
+
if (toolCall && !toolCall.sent) {
|
|
38165
|
+
controller.enqueue({
|
|
38166
|
+
type: "tool-call",
|
|
38167
|
+
toolCallId: toolCall.id ?? generateId(),
|
|
38168
|
+
toolName: toolCall.function.name,
|
|
38169
|
+
input: isParsableJson(toolCall.function.arguments) ? toolCall.function.arguments : "{}"
|
|
38170
|
+
});
|
|
38171
|
+
toolCall.sent = true;
|
|
38172
|
+
}
|
|
38173
|
+
}
|
|
38174
|
+
}
|
|
38175
|
+
if (reasoningStarted) {
|
|
38176
|
+
controller.enqueue({
|
|
38177
|
+
type: "reasoning-end",
|
|
38178
|
+
id: reasoningId || generateId()
|
|
38179
|
+
});
|
|
38180
|
+
}
|
|
38181
|
+
if (textStarted) {
|
|
38182
|
+
controller.enqueue({
|
|
38183
|
+
type: "text-end",
|
|
38184
|
+
id: textId || generateId()
|
|
38185
|
+
});
|
|
38186
|
+
}
|
|
38187
|
+
const openrouterMetadata = {
|
|
38188
|
+
usage: openrouterUsage
|
|
38189
|
+
};
|
|
38190
|
+
if (provider !== undefined) {
|
|
38191
|
+
openrouterMetadata.provider = provider;
|
|
38192
|
+
}
|
|
38193
|
+
controller.enqueue({
|
|
38194
|
+
type: "finish",
|
|
38195
|
+
finishReason,
|
|
38196
|
+
usage,
|
|
38197
|
+
providerMetadata: {
|
|
38198
|
+
openrouter: openrouterMetadata
|
|
38199
|
+
}
|
|
38200
|
+
});
|
|
38201
|
+
}
|
|
38202
|
+
})),
|
|
38203
|
+
warnings: [],
|
|
38204
|
+
request: { body: args },
|
|
38205
|
+
response: { headers: responseHeaders }
|
|
38206
|
+
};
|
|
38207
|
+
}
|
|
38208
|
+
}
|
|
38209
|
+
|
|
38210
|
+
// ../packages/internal/src/openrouter-ai-sdk/completion/convert-to-openrouter-completion-prompt.ts
|
|
38211
|
+
function convertToOpenRouterCompletionPrompt({
|
|
38212
|
+
prompt: prompt2,
|
|
38213
|
+
inputFormat,
|
|
38214
|
+
user = "user",
|
|
38215
|
+
assistant = "assistant"
|
|
38216
|
+
}) {
|
|
38217
|
+
if (inputFormat === "prompt" && prompt2.length === 1 && prompt2[0] && prompt2[0].role === "user" && prompt2[0].content.length === 1 && prompt2[0].content[0] && prompt2[0].content[0].type === "text") {
|
|
38218
|
+
return { prompt: prompt2[0].content[0].text };
|
|
38219
|
+
}
|
|
38220
|
+
let text = "";
|
|
38221
|
+
if (prompt2[0] && prompt2[0].role === "system") {
|
|
38222
|
+
text += `${prompt2[0].content}
|
|
38223
|
+
|
|
38224
|
+
`;
|
|
38225
|
+
prompt2 = prompt2.slice(1);
|
|
38226
|
+
}
|
|
38227
|
+
for (const { role, content } of prompt2) {
|
|
38228
|
+
switch (role) {
|
|
38229
|
+
case "system": {
|
|
38230
|
+
throw new InvalidPromptError({
|
|
38231
|
+
message: `Unexpected system message in prompt: ${content}`,
|
|
38232
|
+
prompt: prompt2
|
|
38233
|
+
});
|
|
38234
|
+
}
|
|
38235
|
+
case "user": {
|
|
38236
|
+
const userMessage2 = content.map((part) => {
|
|
38237
|
+
switch (part.type) {
|
|
38238
|
+
case "text": {
|
|
38239
|
+
return part.text;
|
|
38240
|
+
}
|
|
38241
|
+
case "file": {
|
|
38242
|
+
throw new UnsupportedFunctionalityError({
|
|
38243
|
+
functionality: "file attachments"
|
|
38244
|
+
});
|
|
38245
|
+
}
|
|
38246
|
+
default: {
|
|
38247
|
+
return "";
|
|
38248
|
+
}
|
|
38249
|
+
}
|
|
38250
|
+
}).join("");
|
|
38251
|
+
text += `${user}:
|
|
38252
|
+
${userMessage2}
|
|
38253
|
+
|
|
38254
|
+
`;
|
|
38255
|
+
break;
|
|
38256
|
+
}
|
|
38257
|
+
case "assistant": {
|
|
38258
|
+
const assistantMessage2 = content.map((part) => {
|
|
38259
|
+
switch (part.type) {
|
|
38260
|
+
case "text": {
|
|
38261
|
+
return part.text;
|
|
38262
|
+
}
|
|
38263
|
+
case "tool-call": {
|
|
38264
|
+
throw new UnsupportedFunctionalityError({
|
|
38265
|
+
functionality: "tool-call messages"
|
|
38266
|
+
});
|
|
38267
|
+
}
|
|
38268
|
+
case "tool-result": {
|
|
38269
|
+
throw new UnsupportedFunctionalityError({
|
|
38270
|
+
functionality: "tool-result messages"
|
|
38271
|
+
});
|
|
38272
|
+
}
|
|
38273
|
+
case "reasoning": {
|
|
38274
|
+
throw new UnsupportedFunctionalityError({
|
|
38275
|
+
functionality: "reasoning messages"
|
|
38276
|
+
});
|
|
38277
|
+
}
|
|
38278
|
+
case "file": {
|
|
38279
|
+
throw new UnsupportedFunctionalityError({
|
|
38280
|
+
functionality: "file attachments"
|
|
38281
|
+
});
|
|
38282
|
+
}
|
|
38283
|
+
default: {
|
|
38284
|
+
return "";
|
|
38285
|
+
}
|
|
38286
|
+
}
|
|
38287
|
+
}).join("");
|
|
38288
|
+
text += `${assistant}:
|
|
38289
|
+
${assistantMessage2}
|
|
38290
|
+
|
|
38291
|
+
`;
|
|
38292
|
+
break;
|
|
38293
|
+
}
|
|
38294
|
+
case "tool": {
|
|
38295
|
+
throw new UnsupportedFunctionalityError({
|
|
38296
|
+
functionality: "tool messages"
|
|
38297
|
+
});
|
|
38298
|
+
}
|
|
38299
|
+
default: {
|
|
38300
|
+
break;
|
|
38301
|
+
}
|
|
38302
|
+
}
|
|
38303
|
+
}
|
|
38304
|
+
text += `${assistant}:
|
|
38305
|
+
`;
|
|
38306
|
+
return {
|
|
38307
|
+
prompt: text
|
|
38308
|
+
};
|
|
38309
|
+
}
|
|
38310
|
+
|
|
38311
|
+
// ../packages/internal/src/openrouter-ai-sdk/completion/schemas.ts
|
|
38312
|
+
var import_v469 = require("zod/v4");
|
|
38313
|
+
var OpenRouterCompletionChunkSchema = import_v469.z.union([
|
|
38314
|
+
import_v469.z.object({
|
|
38315
|
+
id: import_v469.z.string().optional(),
|
|
38316
|
+
model: import_v469.z.string().optional(),
|
|
38317
|
+
choices: import_v469.z.array(import_v469.z.object({
|
|
38318
|
+
text: import_v469.z.string(),
|
|
38319
|
+
reasoning: import_v469.z.string().nullish().optional(),
|
|
38320
|
+
reasoning_details: ReasoningDetailArraySchema.nullish(),
|
|
38321
|
+
finish_reason: import_v469.z.string().nullish(),
|
|
38322
|
+
index: import_v469.z.number().nullish(),
|
|
38323
|
+
logprobs: import_v469.z.object({
|
|
38324
|
+
tokens: import_v469.z.array(import_v469.z.string()),
|
|
38325
|
+
token_logprobs: import_v469.z.array(import_v469.z.number()),
|
|
38326
|
+
top_logprobs: import_v469.z.array(import_v469.z.record(import_v469.z.string(), import_v469.z.number())).nullable()
|
|
38327
|
+
}).nullable().optional()
|
|
38328
|
+
})),
|
|
38329
|
+
usage: import_v469.z.object({
|
|
38330
|
+
prompt_tokens: import_v469.z.number(),
|
|
38331
|
+
prompt_tokens_details: import_v469.z.object({
|
|
38332
|
+
cached_tokens: import_v469.z.number()
|
|
38333
|
+
}).nullish(),
|
|
38334
|
+
completion_tokens: import_v469.z.number(),
|
|
38335
|
+
completion_tokens_details: import_v469.z.object({
|
|
38336
|
+
reasoning_tokens: import_v469.z.number()
|
|
38337
|
+
}).nullish(),
|
|
38338
|
+
total_tokens: import_v469.z.number(),
|
|
38339
|
+
cost: import_v469.z.number().optional()
|
|
38340
|
+
}).nullish()
|
|
38341
|
+
}),
|
|
38342
|
+
OpenRouterErrorResponseSchema
|
|
38343
|
+
]);
|
|
38344
|
+
|
|
38345
|
+
// ../packages/internal/src/openrouter-ai-sdk/completion/index.ts
|
|
38346
|
+
class OpenRouterCompletionLanguageModel {
|
|
38347
|
+
specificationVersion = "v2";
|
|
38348
|
+
provider = "openrouter";
|
|
38349
|
+
modelId;
|
|
38350
|
+
supportedUrls = {
|
|
38351
|
+
"image/*": [
|
|
38352
|
+
/^data:image\/[a-zA-Z]+;base64,/,
|
|
38353
|
+
/^https?:\/\/.+\.(jpg|jpeg|png|gif|webp)$/i
|
|
38354
|
+
],
|
|
38355
|
+
"text/*": [/^data:text\//, /^https?:\/\/.+$/],
|
|
38356
|
+
"application/*": [/^data:application\//, /^https?:\/\/.+$/]
|
|
38357
|
+
};
|
|
38358
|
+
defaultObjectGenerationMode = undefined;
|
|
38359
|
+
settings;
|
|
38360
|
+
config;
|
|
38361
|
+
constructor(modelId, settings, config) {
|
|
38362
|
+
this.modelId = modelId;
|
|
38363
|
+
this.settings = settings;
|
|
38364
|
+
this.config = config;
|
|
38365
|
+
}
|
|
38366
|
+
getArgs({
|
|
38367
|
+
prompt: prompt2,
|
|
38368
|
+
maxOutputTokens,
|
|
38369
|
+
temperature,
|
|
38370
|
+
topP,
|
|
38371
|
+
frequencyPenalty,
|
|
38372
|
+
presencePenalty,
|
|
38373
|
+
seed,
|
|
38374
|
+
responseFormat,
|
|
38375
|
+
topK,
|
|
38376
|
+
stopSequences,
|
|
38377
|
+
tools,
|
|
38378
|
+
toolChoice
|
|
38379
|
+
}) {
|
|
38380
|
+
const { prompt: completionPrompt } = convertToOpenRouterCompletionPrompt({
|
|
38381
|
+
prompt: prompt2,
|
|
38382
|
+
inputFormat: "prompt"
|
|
38383
|
+
});
|
|
38384
|
+
if (tools?.length) {
|
|
38385
|
+
throw new UnsupportedFunctionalityError({
|
|
38386
|
+
functionality: "tools"
|
|
38387
|
+
});
|
|
38388
|
+
}
|
|
38389
|
+
if (toolChoice) {
|
|
38390
|
+
throw new UnsupportedFunctionalityError({
|
|
38391
|
+
functionality: "toolChoice"
|
|
38392
|
+
});
|
|
38393
|
+
}
|
|
38394
|
+
return {
|
|
38395
|
+
model: this.modelId,
|
|
38396
|
+
models: this.settings.models,
|
|
38397
|
+
logit_bias: this.settings.logitBias,
|
|
38398
|
+
logprobs: typeof this.settings.logprobs === "number" ? this.settings.logprobs : typeof this.settings.logprobs === "boolean" ? this.settings.logprobs ? 0 : undefined : undefined,
|
|
38399
|
+
suffix: this.settings.suffix,
|
|
38400
|
+
user: this.settings.user,
|
|
38401
|
+
max_tokens: maxOutputTokens,
|
|
38402
|
+
temperature,
|
|
38403
|
+
top_p: topP,
|
|
38404
|
+
frequency_penalty: frequencyPenalty,
|
|
38405
|
+
presence_penalty: presencePenalty,
|
|
38406
|
+
seed,
|
|
38407
|
+
...this.modelId === "x-ai/grok-code-fast-1" ? {} : { stop: stopSequences },
|
|
38408
|
+
response_format: responseFormat,
|
|
38409
|
+
top_k: topK,
|
|
38410
|
+
prompt: completionPrompt,
|
|
38411
|
+
include_reasoning: this.settings.includeReasoning,
|
|
38412
|
+
reasoning: this.settings.reasoning,
|
|
38413
|
+
...this.config.extraBody,
|
|
38414
|
+
...this.settings.extraBody
|
|
38415
|
+
};
|
|
38416
|
+
}
|
|
38417
|
+
async doGenerate(options) {
|
|
38418
|
+
const providerOptions = options.providerOptions || {};
|
|
38419
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
38420
|
+
const args = {
|
|
38421
|
+
...this.getArgs(options),
|
|
38422
|
+
...openrouterOptions
|
|
38423
|
+
};
|
|
38424
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
38425
|
+
url: this.config.url({
|
|
38426
|
+
path: "/completions",
|
|
38427
|
+
modelId: this.modelId
|
|
38428
|
+
}),
|
|
38429
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
38430
|
+
body: args,
|
|
38431
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
38432
|
+
successfulResponseHandler: createJsonResponseHandler(OpenRouterCompletionChunkSchema),
|
|
38433
|
+
abortSignal: options.abortSignal,
|
|
38434
|
+
fetch: this.config.fetch
|
|
38435
|
+
});
|
|
38436
|
+
if ("error" in response) {
|
|
38437
|
+
throw new Error(`${response.error.message}`);
|
|
38438
|
+
}
|
|
38439
|
+
const choice = response.choices[0];
|
|
38440
|
+
if (!choice) {
|
|
38441
|
+
throw new Error("No choice in OpenRouter completion response");
|
|
38442
|
+
}
|
|
38443
|
+
return {
|
|
38444
|
+
content: [
|
|
38445
|
+
{
|
|
38446
|
+
type: "text",
|
|
38447
|
+
text: choice.text ?? ""
|
|
38448
|
+
}
|
|
38449
|
+
],
|
|
38450
|
+
finishReason: mapOpenRouterFinishReason(choice.finish_reason),
|
|
38451
|
+
usage: {
|
|
38452
|
+
inputTokens: response.usage?.prompt_tokens ?? 0,
|
|
38453
|
+
outputTokens: response.usage?.completion_tokens ?? 0,
|
|
38454
|
+
totalTokens: (response.usage?.prompt_tokens ?? 0) + (response.usage?.completion_tokens ?? 0),
|
|
38455
|
+
reasoningTokens: response.usage?.completion_tokens_details?.reasoning_tokens ?? 0,
|
|
38456
|
+
cachedInputTokens: response.usage?.prompt_tokens_details?.cached_tokens ?? 0
|
|
38457
|
+
},
|
|
38458
|
+
warnings: [],
|
|
38459
|
+
response: {
|
|
38460
|
+
headers: responseHeaders
|
|
38461
|
+
}
|
|
38462
|
+
};
|
|
38463
|
+
}
|
|
38464
|
+
async doStream(options) {
|
|
38465
|
+
const providerOptions = options.providerOptions || {};
|
|
38466
|
+
const openrouterOptions = providerOptions.openrouter || {};
|
|
38467
|
+
const args = {
|
|
38468
|
+
...this.getArgs(options),
|
|
38469
|
+
...openrouterOptions
|
|
38470
|
+
};
|
|
38471
|
+
const { value: response, responseHeaders } = await postJsonToApi({
|
|
38472
|
+
url: this.config.url({
|
|
38473
|
+
path: "/completions",
|
|
38474
|
+
modelId: this.modelId
|
|
38475
|
+
}),
|
|
38476
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
38477
|
+
body: {
|
|
38478
|
+
...args,
|
|
38479
|
+
stream: true,
|
|
38480
|
+
stream_options: this.config.compatibility === "strict" ? { include_usage: true } : undefined
|
|
38481
|
+
},
|
|
38482
|
+
failedResponseHandler: openrouterFailedResponseHandler,
|
|
38483
|
+
successfulResponseHandler: createEventSourceResponseHandler(OpenRouterCompletionChunkSchema),
|
|
38484
|
+
abortSignal: options.abortSignal,
|
|
38485
|
+
fetch: this.config.fetch
|
|
38486
|
+
});
|
|
38487
|
+
let finishReason = "other";
|
|
38488
|
+
const usage = {
|
|
38489
|
+
inputTokens: Number.NaN,
|
|
38490
|
+
outputTokens: Number.NaN,
|
|
38491
|
+
totalTokens: Number.NaN,
|
|
38492
|
+
reasoningTokens: Number.NaN,
|
|
38493
|
+
cachedInputTokens: Number.NaN
|
|
38494
|
+
};
|
|
38495
|
+
const openrouterUsage = {};
|
|
38496
|
+
return {
|
|
38497
|
+
stream: response.pipeThrough(new TransformStream({
|
|
38498
|
+
transform(chunk, controller) {
|
|
38499
|
+
if (!chunk.success) {
|
|
38500
|
+
finishReason = "error";
|
|
38501
|
+
controller.enqueue({ type: "error", error: chunk.error });
|
|
38502
|
+
return;
|
|
38503
|
+
}
|
|
38504
|
+
const value = chunk.value;
|
|
38505
|
+
if ("error" in value) {
|
|
38506
|
+
finishReason = "error";
|
|
38507
|
+
controller.enqueue({ type: "error", error: value.error });
|
|
38508
|
+
return;
|
|
38509
|
+
}
|
|
38510
|
+
if (value.usage != null) {
|
|
38511
|
+
usage.inputTokens = value.usage.prompt_tokens;
|
|
38512
|
+
usage.outputTokens = value.usage.completion_tokens;
|
|
38513
|
+
usage.totalTokens = value.usage.prompt_tokens + value.usage.completion_tokens;
|
|
38514
|
+
openrouterUsage.promptTokens = value.usage.prompt_tokens;
|
|
38515
|
+
if (value.usage.prompt_tokens_details) {
|
|
38516
|
+
const cachedInputTokens = value.usage.prompt_tokens_details.cached_tokens ?? 0;
|
|
38517
|
+
usage.cachedInputTokens = cachedInputTokens;
|
|
38518
|
+
openrouterUsage.promptTokensDetails = {
|
|
38519
|
+
cachedTokens: cachedInputTokens
|
|
38520
|
+
};
|
|
38521
|
+
}
|
|
38522
|
+
openrouterUsage.completionTokens = value.usage.completion_tokens;
|
|
38523
|
+
if (value.usage.completion_tokens_details) {
|
|
38524
|
+
const reasoningTokens = value.usage.completion_tokens_details.reasoning_tokens ?? 0;
|
|
38525
|
+
usage.reasoningTokens = reasoningTokens;
|
|
38526
|
+
openrouterUsage.completionTokensDetails = {
|
|
38527
|
+
reasoningTokens
|
|
38528
|
+
};
|
|
38529
|
+
}
|
|
38530
|
+
if (value.usage.cost !== undefined) {
|
|
38531
|
+
openrouterUsage.cost = value.usage.cost;
|
|
38532
|
+
}
|
|
38533
|
+
openrouterUsage.totalTokens = value.usage.total_tokens;
|
|
38534
|
+
}
|
|
38535
|
+
const choice = value.choices[0];
|
|
38536
|
+
if (choice?.finish_reason != null) {
|
|
38537
|
+
finishReason = mapOpenRouterFinishReason(choice.finish_reason);
|
|
38538
|
+
}
|
|
38539
|
+
if (choice?.text != null) {
|
|
38540
|
+
controller.enqueue({
|
|
38541
|
+
type: "text-delta",
|
|
38542
|
+
delta: choice.text,
|
|
38543
|
+
id: generateId()
|
|
38544
|
+
});
|
|
38545
|
+
}
|
|
38546
|
+
},
|
|
38547
|
+
flush(controller) {
|
|
38548
|
+
controller.enqueue({
|
|
38549
|
+
type: "finish",
|
|
38550
|
+
finishReason,
|
|
38551
|
+
usage,
|
|
38552
|
+
providerMetadata: {
|
|
38553
|
+
openrouter: {
|
|
38554
|
+
usage: openrouterUsage
|
|
38555
|
+
}
|
|
38556
|
+
}
|
|
38557
|
+
});
|
|
38558
|
+
}
|
|
38559
|
+
})),
|
|
38560
|
+
response: {
|
|
38561
|
+
headers: responseHeaders
|
|
38562
|
+
}
|
|
38563
|
+
};
|
|
38564
|
+
}
|
|
38565
|
+
}
|
|
38566
|
+
|
|
38567
|
+
// ../packages/internal/src/openrouter-ai-sdk/provider.ts
|
|
38568
|
+
function createOpenRouter(options = {}) {
|
|
38569
|
+
const baseURL = withoutTrailingSlash(options.baseURL ?? options.baseUrl) ?? "https://openrouter.ai/api/v1";
|
|
38570
|
+
const compatibility = options.compatibility ?? "compatible";
|
|
38571
|
+
const getHeaders = () => ({
|
|
38572
|
+
Authorization: `Bearer ${loadApiKey({
|
|
38573
|
+
apiKey: options.apiKey,
|
|
38574
|
+
environmentVariableName: "OPENROUTER_API_KEY",
|
|
38575
|
+
description: "OpenRouter"
|
|
38576
|
+
})}`,
|
|
38577
|
+
...options.headers
|
|
38578
|
+
});
|
|
38579
|
+
const createChatModel = (modelId, settings = {}) => new OpenRouterChatLanguageModel(modelId, settings, {
|
|
38580
|
+
provider: "openrouter.chat",
|
|
38581
|
+
url: ({ path: path4 }) => `${baseURL}${path4}`,
|
|
38582
|
+
headers: getHeaders,
|
|
38583
|
+
compatibility,
|
|
38584
|
+
fetch: options.fetch,
|
|
38585
|
+
extraBody: options.extraBody
|
|
38586
|
+
});
|
|
38587
|
+
const createCompletionModel = (modelId, settings = {}) => new OpenRouterCompletionLanguageModel(modelId, settings, {
|
|
38588
|
+
provider: "openrouter.completion",
|
|
38589
|
+
url: ({ path: path4 }) => `${baseURL}${path4}`,
|
|
38590
|
+
headers: getHeaders,
|
|
38591
|
+
compatibility,
|
|
38592
|
+
fetch: options.fetch,
|
|
38593
|
+
extraBody: options.extraBody
|
|
38594
|
+
});
|
|
38595
|
+
const createLanguageModel = (modelId, settings) => {
|
|
38596
|
+
if (new.target) {
|
|
38597
|
+
throw new Error("The OpenRouter model function cannot be called with the new keyword.");
|
|
38598
|
+
}
|
|
38599
|
+
if (modelId === "openai/gpt-3.5-turbo-instruct") {
|
|
38600
|
+
return createCompletionModel(modelId, settings);
|
|
38601
|
+
}
|
|
38602
|
+
return createChatModel(modelId, settings);
|
|
38603
|
+
};
|
|
38604
|
+
const provider = (modelId, settings) => createLanguageModel(modelId, settings);
|
|
38605
|
+
provider.languageModel = createLanguageModel;
|
|
38606
|
+
provider.chat = createChatModel;
|
|
38607
|
+
provider.completion = createCompletionModel;
|
|
38608
|
+
return provider;
|
|
38609
|
+
}
|
|
38610
|
+
var openrouter = createOpenRouter({
|
|
38611
|
+
compatibility: "strict"
|
|
37163
38612
|
});
|
|
37164
|
-
var processEnv = getProcessEnv();
|
|
37165
38613
|
|
|
37166
|
-
// src/
|
|
37167
|
-
var
|
|
37168
|
-
|
|
37169
|
-
|
|
37170
|
-
|
|
37171
|
-
|
|
37172
|
-
|
|
37173
|
-
|
|
37174
|
-
|
|
38614
|
+
// src/credentials.ts
|
|
38615
|
+
var import_fs = __toESM(require("fs"));
|
|
38616
|
+
var import_node_path = __toESM(require("node:path"));
|
|
38617
|
+
var import_os = __toESM(require("os"));
|
|
38618
|
+
|
|
38619
|
+
// ../common/src/util/credentials.ts
|
|
38620
|
+
var import_v470 = require("zod/v4");
|
|
38621
|
+
var userSchema = import_v470.z.object({
|
|
38622
|
+
id: import_v470.z.string(),
|
|
38623
|
+
email: import_v470.z.string(),
|
|
38624
|
+
name: import_v470.z.string().nullable(),
|
|
38625
|
+
authToken: import_v470.z.string(),
|
|
38626
|
+
fingerprintId: import_v470.z.string(),
|
|
38627
|
+
fingerprintHash: import_v470.z.string()
|
|
37175
38628
|
});
|
|
37176
|
-
var getLevelCodeApiKeyFromEnv = () => {
|
|
37177
|
-
return process.env[API_KEY_ENV_VAR];
|
|
37178
|
-
};
|
|
37179
|
-
var getSystemProcessEnv = () => {
|
|
37180
|
-
return process.env;
|
|
37181
|
-
};
|
|
37182
|
-
var getByokOpenrouterApiKeyFromEnv = () => {
|
|
37183
|
-
return process.env[BYOK_OPENROUTER_ENV_VAR];
|
|
37184
|
-
};
|
|
37185
|
-
var getClaudeOAuthTokenFromEnv = () => {
|
|
37186
|
-
return process.env[CLAUDE_OAUTH_TOKEN_ENV_VAR];
|
|
37187
|
-
};
|
|
37188
38629
|
|
|
37189
38630
|
// src/credentials.ts
|
|
37190
|
-
var
|
|
37191
|
-
|
|
37192
|
-
|
|
37193
|
-
|
|
37194
|
-
|
|
38631
|
+
var import_v471 = require("zod/v4");
|
|
38632
|
+
var claudeOAuthSchema = import_v471.z.object({
|
|
38633
|
+
accessToken: import_v471.z.string(),
|
|
38634
|
+
refreshToken: import_v471.z.string(),
|
|
38635
|
+
expiresAt: import_v471.z.number(),
|
|
38636
|
+
connectedAt: import_v471.z.number()
|
|
37195
38637
|
});
|
|
37196
|
-
var credentialsFileSchema =
|
|
38638
|
+
var credentialsFileSchema = import_v471.z.object({
|
|
37197
38639
|
default: userSchema.optional(),
|
|
37198
38640
|
claudeOAuth: claudeOAuthSchema.optional()
|
|
37199
38641
|
});
|
|
@@ -37212,7 +38654,7 @@ var userFromJson = (json) => {
|
|
|
37212
38654
|
};
|
|
37213
38655
|
var getConfigDir = (clientEnv = env) => {
|
|
37214
38656
|
const envSuffix = clientEnv.NEXT_PUBLIC_CB_ENVIRONMENT && clientEnv.NEXT_PUBLIC_CB_ENVIRONMENT !== "prod" ? `-${clientEnv.NEXT_PUBLIC_CB_ENVIRONMENT}` : "";
|
|
37215
|
-
return import_node_path.default.join(import_os.default.homedir(), ".config", `
|
|
38657
|
+
return import_node_path.default.join(import_os.default.homedir(), ".config", `levelcode${envSuffix}`);
|
|
37216
38658
|
};
|
|
37217
38659
|
var getCredentialsPath = (clientEnv = env) => {
|
|
37218
38660
|
return import_node_path.default.join(getConfigDir(clientEnv), "credentials.json");
|
|
@@ -37401,6 +38843,17 @@ async function fetchClaudeOAuthResetTime(accessToken) {
|
|
|
37401
38843
|
return null;
|
|
37402
38844
|
}
|
|
37403
38845
|
}
|
|
38846
|
+
function createDirectOpenRouterModel(openRouterApiKey, model) {
|
|
38847
|
+
const baseURL = getOpenRouterBaseUrlFromEnv();
|
|
38848
|
+
const provider = createOpenRouter({ apiKey: openRouterApiKey, compatibility: "strict", ...baseURL && { baseURL } });
|
|
38849
|
+
return provider.chat(model);
|
|
38850
|
+
}
|
|
38851
|
+
function createDirectAnthropicModel(anthropicApiKey, model) {
|
|
38852
|
+
const anthropicModelId = toAnthropicModelId(model);
|
|
38853
|
+
const baseURL = getAnthropicBaseUrlFromEnv();
|
|
38854
|
+
const anthropic = import_anthropic.createAnthropic({ apiKey: anthropicApiKey, ...baseURL && { baseURL } });
|
|
38855
|
+
return anthropic(anthropicModelId);
|
|
38856
|
+
}
|
|
37404
38857
|
async function getModelForRequest(params2) {
|
|
37405
38858
|
const { apiKey, model, skipClaudeOAuth } = params2;
|
|
37406
38859
|
if (!skipClaudeOAuth && !isClaudeOAuthRateLimited() && isClaudeModel(model)) {
|
|
@@ -37412,6 +38865,16 @@ async function getModelForRequest(params2) {
|
|
|
37412
38865
|
};
|
|
37413
38866
|
}
|
|
37414
38867
|
}
|
|
38868
|
+
if (isStandaloneMode()) {
|
|
38869
|
+
const openRouterKey = getOpenRouterApiKeyFromEnv();
|
|
38870
|
+
if (openRouterKey) {
|
|
38871
|
+
return { model: createDirectOpenRouterModel(openRouterKey, model), isClaudeOAuth: false };
|
|
38872
|
+
}
|
|
38873
|
+
const anthropicKey = getAnthropicApiKeyFromEnv();
|
|
38874
|
+
if (anthropicKey) {
|
|
38875
|
+
return { model: createDirectAnthropicModel(anthropicKey, model), isClaudeOAuth: false };
|
|
38876
|
+
}
|
|
38877
|
+
}
|
|
37415
38878
|
return {
|
|
37416
38879
|
model: createLevelCodeBackendModel(apiKey, model),
|
|
37417
38880
|
isClaudeOAuth: false
|
|
@@ -38602,7 +40065,7 @@ function parseFile(parser, query, sourceCode) {
|
|
|
38602
40065
|
|
|
38603
40066
|
// src/run-state.ts
|
|
38604
40067
|
var import_lodash17 = __toESM(require_lodash());
|
|
38605
|
-
var
|
|
40068
|
+
var import_v473 = __toESM(require("zod/v4"));
|
|
38606
40069
|
|
|
38607
40070
|
// src/agents/load-agents.ts
|
|
38608
40071
|
var import_fs2 = __toESM(require("fs"));
|
|
@@ -38844,21 +40307,21 @@ function isValidSkillName(name14) {
|
|
|
38844
40307
|
}
|
|
38845
40308
|
|
|
38846
40309
|
// ../common/src/types/skill.ts
|
|
38847
|
-
var
|
|
38848
|
-
var SkillMetadataSchema =
|
|
38849
|
-
var SkillFrontmatterSchema =
|
|
38850
|
-
name:
|
|
38851
|
-
description:
|
|
38852
|
-
license:
|
|
40310
|
+
var import_v472 = require("zod/v4");
|
|
40311
|
+
var SkillMetadataSchema = import_v472.z.record(import_v472.z.string(), import_v472.z.string());
|
|
40312
|
+
var SkillFrontmatterSchema = import_v472.z.object({
|
|
40313
|
+
name: import_v472.z.string().min(1).max(SKILL_NAME_MAX_LENGTH).regex(SKILL_NAME_REGEX, "Name must be lowercase alphanumeric with single hyphen separators"),
|
|
40314
|
+
description: import_v472.z.string().min(1).max(SKILL_DESCRIPTION_MAX_LENGTH),
|
|
40315
|
+
license: import_v472.z.string().optional(),
|
|
38853
40316
|
metadata: SkillMetadataSchema.optional()
|
|
38854
40317
|
});
|
|
38855
|
-
var SkillDefinitionSchema =
|
|
38856
|
-
name:
|
|
38857
|
-
description:
|
|
38858
|
-
license:
|
|
40318
|
+
var SkillDefinitionSchema = import_v472.z.object({
|
|
40319
|
+
name: import_v472.z.string(),
|
|
40320
|
+
description: import_v472.z.string(),
|
|
40321
|
+
license: import_v472.z.string().optional(),
|
|
38859
40322
|
metadata: SkillMetadataSchema.optional(),
|
|
38860
|
-
content:
|
|
38861
|
-
filePath:
|
|
40323
|
+
content: import_v472.z.string(),
|
|
40324
|
+
filePath: import_v472.z.string()
|
|
38862
40325
|
});
|
|
38863
40326
|
|
|
38864
40327
|
// src/skills/load-skills.ts
|
|
@@ -38998,7 +40461,7 @@ function processAgentDefinitions(agentDefinitions) {
|
|
|
38998
40461
|
}
|
|
38999
40462
|
function processCustomToolDefinitions(customToolDefinitions) {
|
|
39000
40463
|
return Object.fromEntries(customToolDefinitions.map((toolDefinition) => {
|
|
39001
|
-
const jsonSchema =
|
|
40464
|
+
const jsonSchema = import_v473.default.toJSONSchema(toolDefinition.inputSchema, {
|
|
39002
40465
|
io: "input"
|
|
39003
40466
|
});
|
|
39004
40467
|
delete jsonSchema["$schema"];
|
|
@@ -39396,11 +40859,11 @@ function buildFileTree(filePaths) {
|
|
|
39396
40859
|
// src/tools/change-file.ts
|
|
39397
40860
|
var import_path9 = __toESM(require("path"));
|
|
39398
40861
|
var import_diff4 = require("diff");
|
|
39399
|
-
var
|
|
39400
|
-
var FileChangeSchema2 =
|
|
39401
|
-
type:
|
|
39402
|
-
path:
|
|
39403
|
-
content:
|
|
40862
|
+
var import_v474 = __toESM(require("zod/v4"));
|
|
40863
|
+
var FileChangeSchema2 = import_v474.default.object({
|
|
40864
|
+
type: import_v474.default.enum(["patch", "file"]),
|
|
40865
|
+
path: import_v474.default.string(),
|
|
40866
|
+
content: import_v474.default.string()
|
|
39404
40867
|
});
|
|
39405
40868
|
function containsUpwardTraversal(dirPath) {
|
|
39406
40869
|
const normalized = import_path9.default.normalize(dirPath);
|
|
@@ -40749,7 +42212,7 @@ async function handlePromptResponse({
|
|
|
40749
42212
|
const message = [
|
|
40750
42213
|
"Received invalid prompt response from server:",
|
|
40751
42214
|
JSON.stringify(parsedOutput.error.issues),
|
|
40752
|
-
"If this issues persists, please contact support@levelcode.
|
|
42215
|
+
"If this issues persists, please contact support@levelcode.vercel.app"
|
|
40753
42216
|
].join(`
|
|
40754
42217
|
`);
|
|
40755
42218
|
onError({ message });
|
|
@@ -40793,7 +42256,7 @@ init_paths();
|
|
|
40793
42256
|
class LevelCodeClient {
|
|
40794
42257
|
options;
|
|
40795
42258
|
constructor(options) {
|
|
40796
|
-
const foundApiKey = options.apiKey ?? getLevelCodeApiKeyFromEnv();
|
|
42259
|
+
const foundApiKey = options.apiKey ?? getLevelCodeApiKeyFromEnv() ?? (isStandaloneMode() ? "standalone-mode" : undefined);
|
|
40797
42260
|
if (!foundApiKey) {
|
|
40798
42261
|
throw new Error(`LevelCode API key not found. Please provide an apiKey in the constructor of LevelCodeClient or set the ${API_KEY_ENV_VAR} environment variable.`);
|
|
40799
42262
|
}
|
|
@@ -40814,6 +42277,9 @@ Provide a handleEvent function to handle this error.`);
|
|
|
40814
42277
|
return run({ ...this.options, ...options });
|
|
40815
42278
|
}
|
|
40816
42279
|
async checkConnection() {
|
|
42280
|
+
if (isStandaloneMode()) {
|
|
42281
|
+
return true;
|
|
42282
|
+
}
|
|
40817
42283
|
try {
|
|
40818
42284
|
const response = await fetch(`${WEBSITE_URL}/api/healthz`, {
|
|
40819
42285
|
method: "GET",
|
|
@@ -40879,9 +42345,9 @@ var import_fs5 = __toESM(require("fs"));
|
|
|
40879
42345
|
var import_promises = __toESM(require("fs/promises"));
|
|
40880
42346
|
var import_os4 = __toESM(require("os"));
|
|
40881
42347
|
var import_path13 = __toESM(require("path"));
|
|
40882
|
-
var
|
|
40883
|
-
var mcpFileSchema =
|
|
40884
|
-
mcpServers:
|
|
42348
|
+
var import_v475 = require("zod/v4");
|
|
42349
|
+
var mcpFileSchema = import_v475.z.object({
|
|
42350
|
+
mcpServers: import_v475.z.record(import_v475.z.string(), mcpConfigSchema).default(() => ({}))
|
|
40885
42351
|
});
|
|
40886
42352
|
var envKey = "env";
|
|
40887
42353
|
var processEnv2 = process[envKey];
|
|
@@ -41010,5 +42476,5 @@ function loadMCPConfigSync(options) {
|
|
|
41010
42476
|
return mergedConfig;
|
|
41011
42477
|
}
|
|
41012
42478
|
|
|
41013
|
-
//# debugId=
|
|
42479
|
+
//# debugId=099CD01FFE2E727364756E2164756E21
|
|
41014
42480
|
//# sourceMappingURL=index.cjs.map
|