@qwen-code/qwen-code 0.19.0 → 0.19.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 (44) hide show
  1. package/bundled/qc-helper/docs/features/mcp.md +6 -2
  2. package/bundled/qc-helper/docs/qwen-serve.md +1 -1
  3. package/chunks/{agent-IPSDEZNB.js → agent-7CZOLKXM.js} +2 -2
  4. package/chunks/{agent-headless-ZMTUWMZJ.js → agent-headless-K37PBQK5.js} +2 -2
  5. package/chunks/{chunk-YF3ORUIU.js → chunk-2X2WXY6L.js} +309 -352
  6. package/chunks/{chunk-GAAALA2X.js → chunk-FXT37TZS.js} +3 -3
  7. package/chunks/{chunk-VRIVIYRL.js → chunk-NQDRRVJD.js} +4 -4
  8. package/chunks/{chunk-KFR4QTV3.js → chunk-OJMCOR55.js} +64 -57
  9. package/chunks/{chunk-S7ILEIB4.js → chunk-PNT7QCLK.js} +2 -3
  10. package/chunks/{chunk-CICUTYTF.js → chunk-YMBWB67C.js} +24 -31
  11. package/chunks/{computer-use-YYK42DD5.js → computer-use-AY6HODX4.js} +2 -2
  12. package/chunks/{contextCommand-BO45MUAA.js → contextCommand-KVKJ63NZ.js} +4 -4
  13. package/chunks/{cron-create-DXKAP5KN.js → cron-create-NHRAAWT5.js} +8 -5
  14. package/chunks/{edit-QERNJN7K.js → edit-OXD4P5YK.js} +2 -2
  15. package/chunks/{en-UTXMGXIR.js → en-7OGNWWME.js} +1 -0
  16. package/chunks/{enter-worktree-6ZKH5IL3.js → enter-worktree-NKNFTLNO.js} +2 -2
  17. package/chunks/{enterPlanMode-B2PBF4MA.js → enterPlanMode-7W2FCILY.js} +2 -2
  18. package/chunks/{exit-worktree-EOCMQO4I.js → exit-worktree-NCRZ52XD.js} +2 -2
  19. package/chunks/{exitPlanMode-WSRXCBRZ.js → exitPlanMode-AZIUQQHA.js} +2 -2
  20. package/chunks/{geminiContentGenerator-NTR4LTKS.js → geminiContentGenerator-5HKVP4JF.js} +1 -1
  21. package/chunks/{glob-IWDJQI2V.js → glob-VCPO3AQO.js} +2 -2
  22. package/chunks/{grep-2DV5BXMH.js → grep-R3W7SG6T.js} +2 -2
  23. package/chunks/{monitor-6HBDS2RS.js → monitor-TQCZALTB.js} +2 -2
  24. package/chunks/{notebook-edit-J5AY5BRY.js → notebook-edit-RYYGIJTA.js} +2 -2
  25. package/chunks/{openaiContentGenerator-ENABCJDM.js → openaiContentGenerator-2AUZ47JU.js} +2 -2
  26. package/chunks/{qwenContentGenerator-ISW42U7C.js → qwenContentGenerator-QM6ENWSO.js} +3 -3
  27. package/chunks/{read-file-NRX2FSSQ.js → read-file-ZSIMNYPB.js} +1 -1
  28. package/chunks/{ripGrep-WF5CKHR5.js → ripGrep-LONCTNP3.js} +2 -2
  29. package/chunks/{scheduler-PNPG5WJ3.js → scheduler-FMNCHQQH.js} +2 -2
  30. package/chunks/{serve-ZBRCIIHW.js → serve-XLPTFQOQ.js} +32 -11
  31. package/chunks/{shell-DLIL6MLU.js → shell-G2CEO7D7.js} +2 -2
  32. package/chunks/{skill-32TXHY4A.js → skill-E5YLTHY3.js} +1 -1
  33. package/chunks/{src-PDDLF5BB.js → src-GCZS2DES.js} +2 -4
  34. package/chunks/{team-create-EHLDSJGI.js → team-create-RQCITTFK.js} +2 -2
  35. package/chunks/{tool-search-FU7IZAOO.js → tool-search-2COFGD5N.js} +1 -1
  36. package/chunks/{workflow-WUDNBCGX.js → workflow-A5VAXYUS.js} +18 -10
  37. package/chunks/{write-file-NVFPX6CH.js → write-file-P2RNFLJR.js} +2 -2
  38. package/chunks/{zh-YOXVTJU5.js → zh-3RMSEO5M.js} +1 -0
  39. package/chunks/{zh-TW-J2TTW67R.js → zh-TW-R7WRLTJS.js} +1 -0
  40. package/cli.js +358 -202
  41. package/locales/en.js +1 -0
  42. package/locales/zh-TW.js +1 -0
  43. package/locales/zh.js +1 -0
  44. package/package.json +3 -3
@@ -222,7 +222,7 @@ import {
222
222
  updateMCPServerStatus,
223
223
  writeLine,
224
224
  writeLineSync
225
- } from "./chunk-CICUTYTF.js";
225
+ } from "./chunk-YMBWB67C.js";
226
226
  import {
227
227
  DEFAULT_QWEN_EMBEDDING_MODEL,
228
228
  DEFAULT_QWEN_MODEL
@@ -34437,7 +34437,6 @@ function buildAgentContentGeneratorConfig(base, modelId, authOverrides) {
34437
34437
  for (const field of MODEL_GENERATION_CONFIG_FIELDS) {
34438
34438
  nextConfig[field] = void 0;
34439
34439
  }
34440
- nextConfig.protocol = modelsConfig.getProtocol(authOverrides.authType);
34441
34440
  }
34442
34441
  if (resolvedModel) {
34443
34442
  applyResolvedModelConfig(
@@ -34505,7 +34504,7 @@ __name(applyResolvedModelConfig, "applyResolvedModelConfig");
34505
34504
  function resolveCredentialField(explicitValue, inheritedValue, authType, field) {
34506
34505
  if (explicitValue) return explicitValue;
34507
34506
  if (inheritedValue) return inheritedValue;
34508
- const envMapping = Object.hasOwn(AUTH_ENV_MAPPINGS, authType) ? AUTH_ENV_MAPPINGS[authType] : void 0;
34507
+ const envMapping = AUTH_ENV_MAPPINGS[authType];
34509
34508
  if (!envMapping) return void 0;
34510
34509
  for (const envKey of envMapping[field]) {
34511
34510
  const value = process.env[envKey];
@@ -34944,7 +34943,7 @@ function classifyRetryError(error, context2 = {}) {
34944
34943
  ...providerMessage !== void 0 ? { providerMessage } : {},
34945
34944
  ...requestId !== void 0 ? { requestId } : {}
34946
34945
  };
34947
- if (context2.authType === AuthType.QWEN_OAUTH && isQwenQuotaExceededError(error)) {
34946
+ if (context2.authType === "qwen-oauth" /* QWEN_OAUTH */ && isQwenQuotaExceededError(error)) {
34948
34947
  return {
34949
34948
  kind: "provider-business",
34950
34949
  diagnosis: "fail-fast",
@@ -35246,7 +35245,7 @@ async function retryWithBackoff(fn, options2) {
35246
35245
  if (retryDiagnostics.kind === "abort") {
35247
35246
  throw error;
35248
35247
  }
35249
- if (authType === AuthType.QWEN_OAUTH && isQwenQuotaExceededError(error)) {
35248
+ if (authType === "qwen-oauth" /* QWEN_OAUTH */ && isQwenQuotaExceededError(error)) {
35250
35249
  debugLogger3.error(
35251
35250
  "Qwen OAuth quota exceeded, fast-failing",
35252
35251
  retryDiagnostics,
@@ -35892,7 +35891,7 @@ var BaseLlmClient = class {
35892
35891
  selector
35893
35892
  );
35894
35893
  const resolvedModel = this.resolveModelAcrossAuthTypes(model, selector);
35895
- const retryAuthType = resolvedModel?.authType ?? mainAuthType ?? AuthType.USE_OPENAI;
35894
+ const retryAuthType = resolvedModel?.authType ?? mainAuthType ?? "openai" /* USE_OPENAI */;
35896
35895
  const retryErrorCodes = resolvedModel?.generationConfig?.retryErrorCodes ?? mainRetryErrorCodes;
35897
35896
  return {
35898
35897
  contentGenerator,
@@ -35922,11 +35921,11 @@ var BaseLlmClient = class {
35922
35921
  return modelsConfig.getResolvedModel(selector.authType, modelId);
35923
35922
  }
35924
35923
  const allAuthTypes = [
35925
- AuthType.QWEN_OAUTH,
35926
- AuthType.USE_OPENAI,
35927
- AuthType.USE_VERTEX_AI,
35928
- AuthType.USE_ANTHROPIC,
35929
- AuthType.USE_GEMINI
35924
+ "qwen-oauth" /* QWEN_OAUTH */,
35925
+ "openai" /* USE_OPENAI */,
35926
+ "vertex-ai" /* USE_VERTEX_AI */,
35927
+ "anthropic" /* USE_ANTHROPIC */,
35928
+ "gemini" /* USE_GEMINI */
35930
35929
  ];
35931
35930
  const mainAuthType = this.config.getContentGeneratorConfig()?.authType;
35932
35931
  if (mainAuthType) {
@@ -36125,14 +36124,22 @@ function resolveSlimmingConfig(settings) {
36125
36124
  };
36126
36125
  }
36127
36126
  __name(resolveSlimmingConfig, "resolveSlimmingConfig");
36128
- function resolveNumber(envValue, settingsValue, defaultValue, { minInclusive }) {
36127
+ function resolveNumber(envValue, settingsValue, defaultValue, {
36128
+ integer = false,
36129
+ minInclusive
36130
+ }) {
36131
+ const isValid = /* @__PURE__ */ __name((value) => Number.isFinite(value) && (!integer || Number.isSafeInteger(value)) && value >= minInclusive, "isValid");
36129
36132
  if (envValue !== void 0 && envValue !== "") {
36130
- const parsed = Number(envValue);
36131
- if (Number.isFinite(parsed) && parsed >= minInclusive) {
36133
+ const trimmed2 = envValue.trim();
36134
+ if (integer && !/^\d+$/.test(trimmed2)) {
36135
+ return settingsValue !== void 0 && isValid(settingsValue) ? settingsValue : defaultValue;
36136
+ }
36137
+ const parsed = Number(trimmed2);
36138
+ if (isValid(parsed)) {
36132
36139
  return parsed;
36133
36140
  }
36134
36141
  }
36135
- if (settingsValue !== void 0 && Number.isFinite(settingsValue) && settingsValue >= minInclusive) {
36142
+ if (settingsValue !== void 0 && isValid(settingsValue)) {
36136
36143
  return settingsValue;
36137
36144
  }
36138
36145
  return defaultValue;
@@ -36148,13 +36155,13 @@ function resolveCompactionTuning(settings) {
36148
36155
  process.env["QWEN_COMPACT_MAX_RECENT_FILES"],
36149
36156
  settings?.maxRecentFilesToRetain,
36150
36157
  DEFAULT_MAX_RECENT_FILES,
36151
- { minInclusive: 0 }
36158
+ { integer: true, minInclusive: 0 }
36152
36159
  ),
36153
36160
  maxRecentImages: resolveNumber(
36154
36161
  process.env["QWEN_COMPACT_MAX_RECENT_IMAGES"],
36155
36162
  settings?.maxRecentImagesToRetain,
36156
36163
  DEFAULT_MAX_RECENT_IMAGES,
36157
- { minInclusive: 0 }
36164
+ { integer: true, minInclusive: 0 }
36158
36165
  ),
36159
36166
  enableScreenshotTrigger: resolveBoolean(
36160
36167
  process.env["QWEN_COMPACT_SCREENSHOT_TRIGGER"],
@@ -36165,7 +36172,7 @@ function resolveCompactionTuning(settings) {
36165
36172
  process.env["QWEN_COMPACT_SCREENSHOT_THRESHOLD"],
36166
36173
  settings?.screenshotTriggerThreshold,
36167
36174
  DEFAULT_SCREENSHOT_TRIGGER_THRESHOLD,
36168
- { minInclusive: 1 }
36175
+ { integer: true, minInclusive: 1 }
36169
36176
  )
36170
36177
  };
36171
36178
  }
@@ -37272,17 +37279,17 @@ init_esbuild_shims();
37272
37279
  // packages/core/src/utils/errorParsing.ts
37273
37280
  init_esbuild_shims();
37274
37281
  var RATE_LIMIT_MESSAGE_BY_AUTH = {
37275
- [AuthType.USE_GEMINI]: "\nPlease wait and try again later. To increase your limits, request a quota increase through AI Studio, or switch to another /auth method",
37276
- [AuthType.USE_VERTEX_AI]: "\nPlease wait and try again later. To increase your limits, request a quota increase through Vertex, or switch to another /auth method",
37282
+ ["gemini" /* USE_GEMINI */]: "\nPlease wait and try again later. To increase your limits, request a quota increase through AI Studio, or switch to another /auth method",
37283
+ ["vertex-ai" /* USE_VERTEX_AI */]: "\nPlease wait and try again later. To increase your limits, request a quota increase through Vertex, or switch to another /auth method",
37277
37284
  default: "\nPossible quota limitations in place or slow response times detected. Please wait and try again later."
37278
37285
  };
37279
37286
  var RATE_LIMIT_SUFFIXES = Object.values(RATE_LIMIT_MESSAGE_BY_AUTH);
37280
37287
  function getRateLimitMessage(authType) {
37281
- if (authType === AuthType.USE_GEMINI) {
37282
- return RATE_LIMIT_MESSAGE_BY_AUTH[AuthType.USE_GEMINI];
37288
+ if (authType === "gemini" /* USE_GEMINI */) {
37289
+ return RATE_LIMIT_MESSAGE_BY_AUTH["gemini" /* USE_GEMINI */];
37283
37290
  }
37284
- if (authType === AuthType.USE_VERTEX_AI) {
37285
- return RATE_LIMIT_MESSAGE_BY_AUTH[AuthType.USE_VERTEX_AI];
37291
+ if (authType === "vertex-ai" /* USE_VERTEX_AI */) {
37292
+ return RATE_LIMIT_MESSAGE_BY_AUTH["vertex-ai" /* USE_VERTEX_AI */];
37286
37293
  }
37287
37294
  return RATE_LIMIT_MESSAGE_BY_AUTH.default;
37288
37295
  }
@@ -55191,7 +55198,7 @@ __name(defaultModalities, "defaultModalities");
55191
55198
  // packages/core/src/models/modelRegistry.ts
55192
55199
  var debugLogger25 = createDebugLogger("MODEL_REGISTRY");
55193
55200
  function validateAuthTypeKey(key) {
55194
- if (key && key.trim().length > 0) {
55201
+ if (Object.values(AuthType).includes(key)) {
55195
55202
  return key;
55196
55203
  }
55197
55204
  return void 0;
@@ -55210,12 +55217,11 @@ var ModelRegistry = class {
55210
55217
  __name(this, "ModelRegistry");
55211
55218
  }
55212
55219
  modelsByAuthType;
55213
- protocolByAuthType = /* @__PURE__ */ new Map();
55214
55220
  getDefaultBaseUrl(authType) {
55215
55221
  switch (authType) {
55216
- case AuthType.QWEN_OAUTH:
55222
+ case "qwen-oauth" /* QWEN_OAUTH */:
55217
55223
  return "DYNAMIC_QWEN_OAUTH_BASE_URL";
55218
- case AuthType.USE_OPENAI:
55224
+ case "openai" /* USE_OPENAI */:
55219
55225
  return DEFAULT_OPENAI_BASE_URL;
55220
55226
  default:
55221
55227
  return "";
@@ -55223,24 +55229,20 @@ var ModelRegistry = class {
55223
55229
  }
55224
55230
  constructor(modelProvidersConfig) {
55225
55231
  this.modelsByAuthType = /* @__PURE__ */ new Map();
55226
- this.protocolByAuthType.set(AuthType.QWEN_OAUTH, "qwen-oauth" /* QWEN_OAUTH */);
55227
- this.registerAuthTypeModels(AuthType.QWEN_OAUTH, QWEN_OAUTH_MODELS);
55232
+ this.registerAuthTypeModels("qwen-oauth" /* QWEN_OAUTH */, QWEN_OAUTH_MODELS);
55228
55233
  if (modelProvidersConfig) {
55229
- for (const [rawKey, providerConfig] of Object.entries(
55230
- modelProvidersConfig
55231
- )) {
55234
+ for (const [rawKey, models] of Object.entries(modelProvidersConfig)) {
55232
55235
  const authType = validateAuthTypeKey(rawKey);
55233
55236
  if (!authType) {
55234
55237
  debugLogger25.warn(
55235
- `Invalid authType key "${rawKey}" in modelProviders config. Skipping.`
55238
+ `Invalid authType key "${rawKey}" in modelProviders config. Expected one of: ${Object.values(AuthType).join(", ")}. Skipping.`
55236
55239
  );
55237
55240
  continue;
55238
55241
  }
55239
- if (authType === AuthType.QWEN_OAUTH) {
55242
+ if (authType === "qwen-oauth" /* QWEN_OAUTH */) {
55240
55243
  continue;
55241
55244
  }
55242
- this.protocolByAuthType.set(authType, providerConfig.protocol);
55243
- this.registerAuthTypeModels(authType, providerConfig.models);
55245
+ this.registerAuthTypeModels(authType, models);
55244
55246
  }
55245
55247
  }
55246
55248
  }
@@ -55251,6 +55253,12 @@ var ModelRegistry = class {
55251
55253
  * If multiple models share both id and baseUrl, the first one takes precedence.
55252
55254
  */
55253
55255
  registerAuthTypeModels(authType, models) {
55256
+ if (!Array.isArray(models)) {
55257
+ debugLogger25.warn(
55258
+ `modelProviders for authType "${authType}" is not an array; skipping. Expected ModelConfig[]; legacy { protocol, models } entries are normally rewritten by the v5->v4 settings migration.`
55259
+ );
55260
+ return;
55261
+ }
55254
55262
  const modelMap = /* @__PURE__ */ new Map();
55255
55263
  for (const config of models) {
55256
55264
  const key = modelRegistryKey(config.id, config.baseUrl);
@@ -55289,13 +55297,6 @@ var ModelRegistry = class {
55289
55297
  voiceOnly: model.voiceOnly
55290
55298
  }));
55291
55299
  }
55292
- /**
55293
- * Get all registered authTypes.
55294
- * Used by getAllConfiguredModels to include custom providers.
55295
- */
55296
- getAuthTypes() {
55297
- return Array.from(this.modelsByAuthType.keys());
55298
- }
55299
55300
  /**
55300
55301
  * Get model configuration by authType and modelId.
55301
55302
  * When baseUrl is provided, looks up by the exact composite key (id+baseUrl).
@@ -55329,20 +55330,13 @@ var ModelRegistry = class {
55329
55330
  * For others, returns the first configured model.
55330
55331
  */
55331
55332
  getDefaultModelForAuthType(authType) {
55332
- if (authType === AuthType.QWEN_OAUTH) {
55333
+ if (authType === "qwen-oauth" /* QWEN_OAUTH */) {
55333
55334
  return this.getModel(authType, DEFAULT_QWEN_MODEL);
55334
55335
  }
55335
55336
  const models = this.modelsByAuthType.get(authType);
55336
55337
  if (!models || models.size === 0) return void 0;
55337
55338
  return Array.from(models.values())[0];
55338
55339
  }
55339
- /**
55340
- * Get the protocol for an authType.
55341
- * Returns undefined if the authType is not registered.
55342
- */
55343
- getProtocolForAuthType(authType) {
55344
- return this.protocolByAuthType.get(authType);
55345
- }
55346
55340
  /**
55347
55341
  * Resolve model config by applying defaults
55348
55342
  */
@@ -55383,31 +55377,23 @@ var ModelRegistry = class {
55383
55377
  */
55384
55378
  reloadModels(modelProvidersConfig) {
55385
55379
  for (const authType of this.modelsByAuthType.keys()) {
55386
- if (authType !== AuthType.QWEN_OAUTH) {
55380
+ if (authType !== "qwen-oauth" /* QWEN_OAUTH */) {
55387
55381
  this.modelsByAuthType.delete(authType);
55388
55382
  }
55389
55383
  }
55390
- for (const authType of this.protocolByAuthType.keys()) {
55391
- if (authType !== AuthType.QWEN_OAUTH) {
55392
- this.protocolByAuthType.delete(authType);
55393
- }
55394
- }
55395
55384
  if (modelProvidersConfig) {
55396
- for (const [rawKey, providerConfig] of Object.entries(
55397
- modelProvidersConfig
55398
- )) {
55385
+ for (const [rawKey, models] of Object.entries(modelProvidersConfig)) {
55399
55386
  const authType = validateAuthTypeKey(rawKey);
55400
55387
  if (!authType) {
55401
55388
  debugLogger25.warn(
55402
- `Invalid authType key "${rawKey}" in modelProviders config. Skipping.`
55389
+ `Invalid authType key "${rawKey}" in modelProviders config. Expected one of: ${Object.values(AuthType).join(", ")}. Skipping.`
55403
55390
  );
55404
55391
  continue;
55405
55392
  }
55406
- if (authType === AuthType.QWEN_OAUTH) {
55393
+ if (authType === "qwen-oauth" /* QWEN_OAUTH */) {
55407
55394
  continue;
55408
55395
  }
55409
- this.protocolByAuthType.set(authType, providerConfig.protocol);
55410
- this.registerAuthTypeModels(authType, providerConfig.models);
55396
+ this.registerAuthTypeModels(authType, models);
55411
55397
  }
55412
55398
  }
55413
55399
  }
@@ -55416,206 +55402,6 @@ var ModelRegistry = class {
55416
55402
  // packages/core/src/models/modelsConfig.ts
55417
55403
  init_esbuild_shims();
55418
55404
  import process3 from "node:process";
55419
-
55420
- // packages/core/src/providers/install.ts
55421
- init_esbuild_shims();
55422
- var AUTH_TYPE_TO_PROTOCOL = {
55423
- openai: "openai" /* OPENAI */,
55424
- "qwen-oauth": "qwen-oauth" /* QWEN_OAUTH */,
55425
- gemini: "gemini" /* GEMINI */,
55426
- "vertex-ai": "gemini" /* GEMINI */,
55427
- anthropic: "anthropic" /* ANTHROPIC */
55428
- };
55429
- function authTypeToProtocol(authType) {
55430
- return Object.hasOwn(AUTH_TYPE_TO_PROTOCOL, authType) ? AUTH_TYPE_TO_PROTOCOL[authType] : "openai" /* OPENAI */;
55431
- }
55432
- __name(authTypeToProtocol, "authTypeToProtocol");
55433
- var DENY_ENV_KEYS = /* @__PURE__ */ new Set([
55434
- "NODE_OPTIONS",
55435
- "NODE_PATH",
55436
- "LD_PRELOAD",
55437
- "LD_LIBRARY_PATH",
55438
- "DYLD_INSERT_LIBRARIES",
55439
- "DYLD_LIBRARY_PATH",
55440
- "PATH",
55441
- "HOME",
55442
- "TMPDIR",
55443
- "TMP",
55444
- // Windows temp redirect
55445
- "TEMP"
55446
- // Windows temp redirect
55447
- ]);
55448
- function isSameModelIdentity(a, b) {
55449
- return a.id === b.id && (a.baseUrl ?? "") === (b.baseUrl ?? "");
55450
- }
55451
- __name(isSameModelIdentity, "isSameModelIdentity");
55452
- function applyModelProvidersPatch(existingModelProviders, patch) {
55453
- const existingProvider = existingModelProviders[patch.authType];
55454
- const existingModels = Array.isArray(existingProvider) ? existingProvider : existingProvider?.models ?? [];
55455
- let updatedModels = patch.models;
55456
- if (patch.mergeStrategy === "append") {
55457
- updatedModels = [...existingModels, ...patch.models];
55458
- } else {
55459
- const ownsModel = patch.ownsModel;
55460
- const preservedModels = existingModels.filter((model) => {
55461
- if (ownsModel) {
55462
- return !ownsModel(model);
55463
- }
55464
- return !patch.models.some(
55465
- (newModel) => isSameModelIdentity(newModel, model)
55466
- );
55467
- });
55468
- updatedModels = patch.mergeStrategy === "replace-owned" ? [...preservedModels, ...patch.models] : [...patch.models, ...preservedModels];
55469
- }
55470
- const updatedProvider = {
55471
- protocol: existingProvider?.protocol ?? authTypeToProtocol(patch.authType),
55472
- models: updatedModels,
55473
- ...existingProvider?.baseUrl ? { baseUrl: existingProvider.baseUrl } : {},
55474
- ...existingProvider?.envKey ? { envKey: existingProvider.envKey } : {}
55475
- };
55476
- return {
55477
- ...existingModelProviders,
55478
- [patch.authType]: updatedProvider
55479
- };
55480
- }
55481
- __name(applyModelProvidersPatch, "applyModelProvidersPatch");
55482
- var ProviderInstallError = class extends Error {
55483
- static {
55484
- __name(this, "ProviderInstallError");
55485
- }
55486
- step;
55487
- authType;
55488
- constructor(message, step, authType, options2) {
55489
- super(message, options2);
55490
- this.name = "ProviderInstallError";
55491
- this.step = step;
55492
- this.authType = authType;
55493
- }
55494
- };
55495
- async function applyProviderInstallPlan(plan, options2) {
55496
- const {
55497
- settings,
55498
- reloadModelProviders,
55499
- syncAuthState,
55500
- refreshAuth,
55501
- doRefreshAuth = true
55502
- } = options2;
55503
- const previousEnvValues = /* @__PURE__ */ new Map();
55504
- const previousRuntimeProviders = {
55505
- ...settings.getModelProviders()
55506
- };
55507
- let currentStep = "init";
55508
- try {
55509
- currentStep = "backup";
55510
- settings.backup?.();
55511
- currentStep = "env";
55512
- for (const [key, value] of Object.entries(plan.env ?? {})) {
55513
- if (DENY_ENV_KEYS.has(key.toUpperCase())) {
55514
- throw new Error(
55515
- `Install plan must not set reserved environment variable: ${key}`
55516
- );
55517
- }
55518
- previousEnvValues.set(key, process.env[key]);
55519
- settings.setValue(`env.${key}`, value);
55520
- process.env[key] = value;
55521
- }
55522
- currentStep = "modelProviders";
55523
- let updatedModelProviders = {
55524
- ...previousRuntimeProviders
55525
- };
55526
- for (const patch of plan.modelProviders ?? []) {
55527
- updatedModelProviders = applyModelProvidersPatch(
55528
- updatedModelProviders,
55529
- patch
55530
- );
55531
- settings.setValue(
55532
- `modelProviders.${patch.authType}`,
55533
- updatedModelProviders[patch.authType]
55534
- );
55535
- }
55536
- currentStep = "authType";
55537
- settings.setValue("security.auth.selectedType", plan.authType);
55538
- currentStep = "legacyCredentials";
55539
- if (plan.legacyCredentials?.apiKey != null) {
55540
- settings.setValue("security.auth.apiKey", plan.legacyCredentials.apiKey);
55541
- }
55542
- if (plan.legacyCredentials?.baseUrl != null) {
55543
- settings.setValue(
55544
- "security.auth.baseUrl",
55545
- plan.legacyCredentials.baseUrl
55546
- );
55547
- }
55548
- currentStep = "modelSelection";
55549
- if (plan.modelSelection?.modelId) {
55550
- settings.setValue("model.name", plan.modelSelection.modelId);
55551
- if (plan.modelSelection.baseUrl) {
55552
- settings.setValue("model.baseUrl", plan.modelSelection.baseUrl);
55553
- } else {
55554
- settings.setValue("model.baseUrl", "");
55555
- }
55556
- }
55557
- currentStep = "providerState";
55558
- for (const [key, entries] of Object.entries(plan.providerState ?? {})) {
55559
- for (const [field, value] of Object.entries(entries)) {
55560
- settings.setValue(`${key}.${field}`, value);
55561
- }
55562
- }
55563
- currentStep = "persist";
55564
- settings.persist();
55565
- currentStep = "reloadModelProviders";
55566
- reloadModelProviders?.(updatedModelProviders);
55567
- if (plan.modelSelection?.modelId) {
55568
- currentStep = "syncAuthState";
55569
- syncAuthState?.(
55570
- plan.authType,
55571
- plan.modelSelection.modelId,
55572
- plan.modelSelection.baseUrl
55573
- );
55574
- }
55575
- if (doRefreshAuth && refreshAuth) {
55576
- currentStep = "refreshAuth";
55577
- await refreshAuth(plan.authType);
55578
- }
55579
- currentStep = "cleanupBackup";
55580
- settings.cleanupBackup?.();
55581
- return { updatedModelProviders };
55582
- } catch (error) {
55583
- try {
55584
- settings.restore?.();
55585
- } catch (restoreErr) {
55586
- console.error(
55587
- "[applyProviderInstallPlan] settings.restore failed during rollback:",
55588
- restoreErr
55589
- );
55590
- }
55591
- try {
55592
- for (const [key, prev] of previousEnvValues) {
55593
- if (prev === void 0) {
55594
- delete process.env[key];
55595
- } else {
55596
- process.env[key] = prev;
55597
- }
55598
- }
55599
- } catch (envErr) {
55600
- console.error("[applyProviderInstallPlan] env rollback failed:", envErr);
55601
- }
55602
- try {
55603
- reloadModelProviders?.(previousRuntimeProviders);
55604
- } catch (reloadErr) {
55605
- console.error(
55606
- "[applyProviderInstallPlan] reloadModelProviders failed during rollback:",
55607
- reloadErr
55608
- );
55609
- }
55610
- const errMsg = error instanceof Error ? error.message : String(error);
55611
- throw new ProviderInstallError(errMsg, currentStep, plan.authType, {
55612
- cause: error instanceof Error ? error : void 0
55613
- });
55614
- }
55615
- }
55616
- __name(applyProviderInstallPlan, "applyProviderInstallPlan");
55617
-
55618
- // packages/core/src/models/modelsConfig.ts
55619
55405
  var ModelsConfig = class _ModelsConfig {
55620
55406
  static {
55621
55407
  __name(this, "ModelsConfig");
@@ -55765,9 +55551,7 @@ var ModelsConfig = class _ModelsConfig {
55765
55551
  * - Runtime model option (if active) is included before registry models of the same authType.
55766
55552
  */
55767
55553
  getAllConfiguredModels(authTypes) {
55768
- const hasExplicitAuthTypes = !!authTypes && authTypes.length > 0;
55769
- const inputAuthTypes = hasExplicitAuthTypes ? authTypes : this.modelRegistry.getAuthTypes();
55770
- const runtimeOption = this.getRuntimeModelOption();
55554
+ const inputAuthTypes = authTypes && authTypes.length > 0 ? authTypes : Object.values(AuthType);
55771
55555
  const seen = /* @__PURE__ */ new Set();
55772
55556
  const uniqueAuthTypes = [];
55773
55557
  for (const authType of inputAuthTypes) {
@@ -55776,19 +55560,16 @@ var ModelsConfig = class _ModelsConfig {
55776
55560
  uniqueAuthTypes.push(authType);
55777
55561
  }
55778
55562
  }
55779
- if (!hasExplicitAuthTypes && runtimeOption && !seen.has(runtimeOption.authType)) {
55780
- seen.add(runtimeOption.authType);
55781
- uniqueAuthTypes.push(runtimeOption.authType);
55782
- }
55783
55563
  const orderedAuthTypes = [];
55784
- if (uniqueAuthTypes.includes(AuthType.QWEN_OAUTH)) {
55785
- orderedAuthTypes.push(AuthType.QWEN_OAUTH);
55564
+ if (uniqueAuthTypes.includes("qwen-oauth" /* QWEN_OAUTH */)) {
55565
+ orderedAuthTypes.push("qwen-oauth" /* QWEN_OAUTH */);
55786
55566
  }
55787
55567
  for (const authType of uniqueAuthTypes) {
55788
- if (authType !== AuthType.QWEN_OAUTH) {
55568
+ if (authType !== "qwen-oauth" /* QWEN_OAUTH */) {
55789
55569
  orderedAuthTypes.push(authType);
55790
55570
  }
55791
55571
  }
55572
+ const runtimeOption = this.getRuntimeModelOption();
55792
55573
  const allModels = [];
55793
55574
  for (const authType of orderedAuthTypes) {
55794
55575
  if (runtimeOption && runtimeOption.authType === authType) {
@@ -55827,7 +55608,7 @@ var ModelsConfig = class _ModelsConfig {
55827
55608
  * Supports both registry models and raw model IDs.
55828
55609
  */
55829
55610
  async setModel(newModel, metadata2) {
55830
- if (this.currentAuthType === AuthType.QWEN_OAUTH && newModel === DEFAULT_QWEN_MODEL) {
55611
+ if (this.currentAuthType === "qwen-oauth" /* QWEN_OAUTH */ && newModel === DEFAULT_QWEN_MODEL) {
55831
55612
  this.strictModelProviderSelection = false;
55832
55613
  this._generationConfig.model = newModel;
55833
55614
  this.generationConfigSources["model"] = {
@@ -55835,7 +55616,7 @@ var ModelsConfig = class _ModelsConfig {
55835
55616
  detail: metadata2?.reason || "setModel"
55836
55617
  };
55837
55618
  if (this.onModelChange) {
55838
- await this.onModelChange(AuthType.QWEN_OAUTH, false);
55619
+ await this.onModelChange("qwen-oauth" /* QWEN_OAUTH */, false);
55839
55620
  }
55840
55621
  return;
55841
55622
  }
@@ -55904,7 +55685,7 @@ var ModelsConfig = class _ModelsConfig {
55904
55685
  return;
55905
55686
  }
55906
55687
  const rollbackSnapshot = this.createStateSnapshotForRollback();
55907
- if (authType === AuthType.QWEN_OAUTH && options2?.requireCachedCredentials) {
55688
+ if (authType === "qwen-oauth" /* QWEN_OAUTH */ && options2?.requireCachedCredentials) {
55908
55689
  this.requireCachedQwenCredentialsOnce = true;
55909
55690
  }
55910
55691
  try {
@@ -55926,7 +55707,7 @@ var ModelsConfig = class _ModelsConfig {
55926
55707
  previousModelId,
55927
55708
  rollbackSnapshot.generationConfig.baseUrl
55928
55709
  ) ?? this.modelRegistry.getModel(authType, previousModelId) : void 0;
55929
- const canReusePreviousApiKey = authType !== AuthType.QWEN_OAUTH && !isAuthTypeChange && !!rollbackSnapshot.generationConfig.apiKey && !!model.envKey && previousModel?.envKey === model.envKey && previousModel.baseUrl === model.baseUrl;
55710
+ const canReusePreviousApiKey = authType !== "qwen-oauth" /* QWEN_OAUTH */ && !isAuthTypeChange && !!rollbackSnapshot.generationConfig.apiKey && !!model.envKey && previousModel?.envKey === model.envKey && previousModel.baseUrl === model.baseUrl;
55930
55711
  const previousApiKey = canReusePreviousApiKey ? rollbackSnapshot.generationConfig.apiKey : void 0;
55931
55712
  const previousApiKeySource = canReusePreviousApiKey ? rollbackSnapshot.generationConfigSources["apiKey"] : void 0;
55932
55713
  this.applyResolvedModelDefaults(model);
@@ -55990,18 +55771,7 @@ var ModelsConfig = class _ModelsConfig {
55990
55771
  * Get generation config for ContentGenerator creation
55991
55772
  */
55992
55773
  getGenerationConfig() {
55993
- if (!this.currentAuthType) return this._generationConfig;
55994
- return {
55995
- ...this._generationConfig,
55996
- protocol: this.getProtocol(this.currentAuthType)
55997
- };
55998
- }
55999
- /**
56000
- * Resolve the Protocol for a given authType.
56001
- * Two-tier lookup: ModelRegistry first, static fallback second.
56002
- */
56003
- getProtocol(authType) {
56004
- return this.modelRegistry.getProtocolForAuthType(authType) ?? authTypeToProtocol(authType);
55774
+ return this._generationConfig;
56005
55775
  }
56006
55776
  /**
56007
55777
  * Get generation config sources for debugging/UI
@@ -56164,7 +55934,7 @@ var ModelsConfig = class _ModelsConfig {
56164
55934
  modelId: model.id,
56165
55935
  detail: "model.id"
56166
55936
  };
56167
- if (this.currentAuthType === AuthType.QWEN_OAUTH) {
55937
+ if (this.currentAuthType === "qwen-oauth" /* QWEN_OAUTH */) {
56168
55938
  this._generationConfig.apiKey = "QWEN_OAUTH_DYNAMIC_TOKEN";
56169
55939
  this.generationConfigSources["apiKey"] = {
56170
55940
  kind: "computed",
@@ -56255,7 +56025,7 @@ var ModelsConfig = class _ModelsConfig {
56255
56025
  if (!authType) {
56256
56026
  return true;
56257
56027
  }
56258
- if (authType === AuthType.QWEN_OAUTH) {
56028
+ if (authType === "qwen-oauth" /* QWEN_OAUTH */) {
56259
56029
  return false;
56260
56030
  }
56261
56031
  const currentModel = this.modelRegistry.getModel(
@@ -56668,10 +56438,10 @@ function resolveModelConfig(input) {
56668
56438
  const { authType, cli, settings, env: env2, modelProvider, proxy: proxy2 } = input;
56669
56439
  const warnings = [];
56670
56440
  const sources = {};
56671
- if (authType === AuthType.QWEN_OAUTH) {
56441
+ if (authType === "qwen-oauth" /* QWEN_OAUTH */) {
56672
56442
  return resolveQwenOAuthConfig(input, warnings);
56673
56443
  }
56674
- const envMapping = authType && Object.hasOwn(AUTH_ENV_MAPPINGS, authType) ? AUTH_ENV_MAPPINGS[authType] : { model: [], apiKey: [], baseUrl: [] };
56444
+ const envMapping = authType ? AUTH_ENV_MAPPINGS[authType] : { model: [], apiKey: [], baseUrl: [] };
56675
56445
  const modelLayers = [];
56676
56446
  if (authType && modelProvider) {
56677
56447
  modelLayers.push(
@@ -56772,8 +56542,7 @@ function resolveModelConfig(input) {
56772
56542
  apiKeyEnvKey,
56773
56543
  baseUrl: baseUrlResult?.value,
56774
56544
  proxy: proxy2,
56775
- ...generationConfig,
56776
- protocol: authType ? authTypeToProtocol(authType) : void 0
56545
+ ...generationConfig
56777
56546
  };
56778
56547
  if (proxy2) {
56779
56548
  sources["proxy"] = computedSource("Config.getProxy()");
@@ -56812,18 +56581,17 @@ function resolveQwenOAuthConfig(input, warnings) {
56812
56581
  const generationConfig = resolveGenerationConfig(
56813
56582
  settings?.generationConfig,
56814
56583
  modelProvider?.generationConfig,
56815
- AuthType.QWEN_OAUTH,
56584
+ "qwen-oauth" /* QWEN_OAUTH */,
56816
56585
  resolvedModel,
56817
56586
  sources
56818
56587
  );
56819
56588
  applyTimeoutEnvOverride(input.env, generationConfig, sources, modelProvider);
56820
56589
  const config = {
56821
- authType: AuthType.QWEN_OAUTH,
56590
+ authType: "qwen-oauth" /* QWEN_OAUTH */,
56822
56591
  model: resolvedModel,
56823
56592
  apiKey: "QWEN_OAUTH_DYNAMIC_TOKEN",
56824
56593
  proxy: proxy2,
56825
- ...generationConfig,
56826
- protocol: authTypeToProtocol(AuthType.QWEN_OAUTH)
56594
+ ...generationConfig
56827
56595
  };
56828
56596
  return { config, sources, warnings };
56829
56597
  }
@@ -57035,7 +56803,7 @@ function getMaxInlineMediaBytes() {
57035
56803
  return DEFAULT_MAX_INLINE_MEDIA_BYTES;
57036
56804
  }
57037
56805
  const parsed = Number(raw2);
57038
- return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : DEFAULT_MAX_INLINE_MEDIA_BYTES;
56806
+ return Number.isInteger(parsed) && parsed > 0 ? parsed : DEFAULT_MAX_INLINE_MEDIA_BYTES;
57039
56807
  }
57040
56808
  __name(getMaxInlineMediaBytes, "getMaxInlineMediaBytes");
57041
56809
  function approxBase64Bytes(base64) {
@@ -59414,7 +59182,7 @@ __name(parseWithCompat, "parseWithCompat");
59414
59182
 
59415
59183
  // node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
59416
59184
  var DEFAULT_REQUEST_TIMEOUT_MSEC = 6e4;
59417
- var Protocol2 = class {
59185
+ var Protocol = class {
59418
59186
  static {
59419
59187
  __name(this, "Protocol");
59420
59188
  }
@@ -60684,7 +60452,7 @@ function getSupportedElicitationModes(capabilities) {
60684
60452
  return { supportsFormMode, supportsUrlMode };
60685
60453
  }
60686
60454
  __name(getSupportedElicitationModes, "getSupportedElicitationModes");
60687
- var Client = class extends Protocol2 {
60455
+ var Client = class extends Protocol {
60688
60456
  static {
60689
60457
  __name(this, "Client");
60690
60458
  }
@@ -72559,9 +72327,9 @@ function computeModelListVersion(models) {
72559
72327
  }
72560
72328
  __name(computeModelListVersion, "computeModelListVersion");
72561
72329
  var DEFAULT_BASE_URLS = {
72562
- ["openai" /* OPENAI */]: "https://api.openai.com/v1",
72563
- ["anthropic" /* ANTHROPIC */]: "https://api.anthropic.com/v1",
72564
- ["gemini" /* GEMINI */]: "https://generativelanguage.googleapis.com"
72330
+ ["openai" /* USE_OPENAI */]: "https://api.openai.com/v1",
72331
+ ["anthropic" /* USE_ANTHROPIC */]: "https://api.anthropic.com/v1",
72332
+ ["gemini" /* USE_GEMINI */]: "https://generativelanguage.googleapis.com"
72565
72333
  };
72566
72334
  function getDefaultBaseUrlForProtocol(protocol) {
72567
72335
  if (protocol === void 0) return "";
@@ -72708,7 +72476,7 @@ var codingPlanProvider = {
72708
72476
  id: "coding-plan",
72709
72477
  label: "Coding Plan",
72710
72478
  description: "For individual developers \xB7 Weekly quota included",
72711
- protocol: "openai" /* OPENAI */,
72479
+ protocol: "openai" /* USE_OPENAI */,
72712
72480
  baseUrl: [
72713
72481
  {
72714
72482
  id: "aliyun",
@@ -72786,7 +72554,7 @@ var tokenPlanProvider = {
72786
72554
  id: "token-plan",
72787
72555
  label: "Token Plan",
72788
72556
  description: "For teams and companies \xB7 Usage-based billing with dedicated endpoint",
72789
- protocol: "openai" /* OPENAI */,
72557
+ protocol: "openai" /* USE_OPENAI */,
72790
72558
  baseUrl: TOKEN_PLAN_BASE_URL,
72791
72559
  envKey: TOKEN_PLAN_ENV_KEY,
72792
72560
  models: TOKEN_PLAN_MODELS,
@@ -72802,7 +72570,7 @@ var alibabaStandardProvider = {
72802
72570
  id: "alibabaStandard",
72803
72571
  label: "Standard API Key",
72804
72572
  description: "Connect with an existing ModelStudio API key",
72805
- protocol: "openai" /* OPENAI */,
72573
+ protocol: "openai" /* USE_OPENAI */,
72806
72574
  baseUrl: [
72807
72575
  {
72808
72576
  id: "cn-beijing",
@@ -72856,7 +72624,7 @@ var openRouterProvider = {
72856
72624
  id: "openrouter",
72857
72625
  label: "OpenRouter",
72858
72626
  description: "Connect with an OpenRouter API key (get one from openrouter.ai/keys)",
72859
- protocol: "openai" /* OPENAI */,
72627
+ protocol: "openai" /* USE_OPENAI */,
72860
72628
  baseUrl: OPENROUTER_BASE_URL,
72861
72629
  envKey: OPENROUTER_ENV_KEY,
72862
72630
  models: [
@@ -72890,7 +72658,7 @@ var requestyProvider = {
72890
72658
  id: "requesty",
72891
72659
  label: "Requesty",
72892
72660
  description: "Connect with a Requesty API key (get one from app.requesty.ai/api-keys)",
72893
- protocol: "openai" /* OPENAI */,
72661
+ protocol: "openai" /* USE_OPENAI */,
72894
72662
  baseUrl: REQUESTY_BASE_URL,
72895
72663
  envKey: REQUESTY_ENV_KEY,
72896
72664
  models: [
@@ -72922,7 +72690,7 @@ var deepseekProvider = {
72922
72690
  id: "deepseek",
72923
72691
  label: "DeepSeek API Key",
72924
72692
  description: "Quick setup for DeepSeek (deepseek-v4-flash, deepseek-v4-pro)",
72925
- protocol: "openai" /* OPENAI */,
72693
+ protocol: "openai" /* USE_OPENAI */,
72926
72694
  baseUrl: "https://api.deepseek.com",
72927
72695
  envKey: "DEEPSEEK_API_KEY",
72928
72696
  models: [
@@ -72945,7 +72713,7 @@ var minimaxProvider = {
72945
72713
  id: "minimax",
72946
72714
  label: "MiniMax API Key",
72947
72715
  description: "Quick setup for MiniMax models",
72948
- protocol: "openai" /* OPENAI */,
72716
+ protocol: "openai" /* USE_OPENAI */,
72949
72717
  baseUrl: [
72950
72718
  {
72951
72719
  id: "international",
@@ -72983,7 +72751,7 @@ var zaiProvider = {
72983
72751
  id: "zai",
72984
72752
  label: "Z.AI API Key",
72985
72753
  description: "Quick setup for Z.AI models",
72986
- protocol: "openai" /* OPENAI */,
72754
+ protocol: "openai" /* USE_OPENAI */,
72987
72755
  baseUrl: [
72988
72756
  {
72989
72757
  id: "standard-api-key",
@@ -73016,7 +72784,7 @@ var idealabProvider = {
73016
72784
  id: "idealab",
73017
72785
  label: "Idealab API Key",
73018
72786
  description: "Alibaba internal LLM service (Qwen3.6-Plus-DogFooding, DeepSeek V4, Kimi K2.6)",
73019
- protocol: "openai" /* OPENAI */,
72787
+ protocol: "openai" /* USE_OPENAI */,
73020
72788
  baseUrl: "https://idealab.alibaba-inc.com/api/openai/v1",
73021
72789
  envKey: "IDEALAB_API_KEY",
73022
72790
  models: [
@@ -73053,7 +72821,7 @@ var modelscopeProvider = {
73053
72821
  id: "modelscope",
73054
72822
  label: "ModelScope API Key",
73055
72823
  description: "Quick setup for ModelScope API Inference",
73056
- protocol: "openai" /* OPENAI */,
72824
+ protocol: "openai" /* USE_OPENAI */,
73057
72825
  baseUrl: "https://api-inference.modelscope.cn/v1",
73058
72826
  envKey: "MODELSCOPE_API_KEY",
73059
72827
  models: [
@@ -73123,8 +72891,12 @@ var customProvider = {
73123
72891
  id: "custom-openai-compatible",
73124
72892
  label: "Custom Provider",
73125
72893
  description: "Manually connect a local server, proxy, or unsupported provider",
73126
- protocol: "openai" /* OPENAI */,
73127
- protocolOptions: ["openai" /* OPENAI */, "anthropic" /* ANTHROPIC */, "gemini" /* GEMINI */],
72894
+ protocol: "openai" /* USE_OPENAI */,
72895
+ protocolOptions: [
72896
+ "openai" /* USE_OPENAI */,
72897
+ "anthropic" /* USE_ANTHROPIC */,
72898
+ "gemini" /* USE_GEMINI */
72899
+ ],
73128
72900
  baseUrl: void 0,
73129
72901
  envKey: generateCustomEnvKey,
73130
72902
  models: void 0,
@@ -73179,6 +72951,186 @@ function getAllProviderBaseUrls() {
73179
72951
  }
73180
72952
  __name(getAllProviderBaseUrls, "getAllProviderBaseUrls");
73181
72953
 
72954
+ // packages/core/src/providers/install.ts
72955
+ init_esbuild_shims();
72956
+ var DENY_ENV_KEYS = /* @__PURE__ */ new Set([
72957
+ "NODE_OPTIONS",
72958
+ "NODE_PATH",
72959
+ "LD_PRELOAD",
72960
+ "LD_LIBRARY_PATH",
72961
+ "DYLD_INSERT_LIBRARIES",
72962
+ "DYLD_LIBRARY_PATH",
72963
+ "PATH",
72964
+ "HOME",
72965
+ "TMPDIR",
72966
+ "TMP",
72967
+ // Windows temp redirect
72968
+ "TEMP"
72969
+ // Windows temp redirect
72970
+ ]);
72971
+ function isSameModelIdentity(a, b) {
72972
+ return a.id === b.id && (a.baseUrl ?? "") === (b.baseUrl ?? "");
72973
+ }
72974
+ __name(isSameModelIdentity, "isSameModelIdentity");
72975
+ function applyModelProvidersPatch(existingModelProviders, patch) {
72976
+ const existingModels = existingModelProviders[patch.authType] ?? [];
72977
+ let updatedModels = patch.models;
72978
+ if (patch.mergeStrategy === "append") {
72979
+ updatedModels = [...existingModels, ...patch.models];
72980
+ } else {
72981
+ const ownsModel = patch.ownsModel;
72982
+ const preservedModels = existingModels.filter((model) => {
72983
+ if (ownsModel) {
72984
+ return !ownsModel(model);
72985
+ }
72986
+ return !patch.models.some(
72987
+ (newModel) => isSameModelIdentity(newModel, model)
72988
+ );
72989
+ });
72990
+ updatedModels = patch.mergeStrategy === "replace-owned" ? [...preservedModels, ...patch.models] : [...patch.models, ...preservedModels];
72991
+ }
72992
+ return {
72993
+ ...existingModelProviders,
72994
+ [patch.authType]: updatedModels
72995
+ };
72996
+ }
72997
+ __name(applyModelProvidersPatch, "applyModelProvidersPatch");
72998
+ var ProviderInstallError = class extends Error {
72999
+ static {
73000
+ __name(this, "ProviderInstallError");
73001
+ }
73002
+ step;
73003
+ authType;
73004
+ constructor(message, step, authType, options2) {
73005
+ super(message, options2);
73006
+ this.name = "ProviderInstallError";
73007
+ this.step = step;
73008
+ this.authType = authType;
73009
+ }
73010
+ };
73011
+ async function applyProviderInstallPlan(plan, options2) {
73012
+ const {
73013
+ settings,
73014
+ reloadModelProviders,
73015
+ syncAuthState,
73016
+ refreshAuth,
73017
+ doRefreshAuth = true
73018
+ } = options2;
73019
+ const previousEnvValues = /* @__PURE__ */ new Map();
73020
+ const previousRuntimeProviders = {
73021
+ ...settings.getModelProviders()
73022
+ };
73023
+ let currentStep = "init";
73024
+ try {
73025
+ currentStep = "backup";
73026
+ settings.backup?.();
73027
+ currentStep = "env";
73028
+ for (const [key, value] of Object.entries(plan.env ?? {})) {
73029
+ if (DENY_ENV_KEYS.has(key.toUpperCase())) {
73030
+ throw new Error(
73031
+ `Install plan must not set reserved environment variable: ${key}`
73032
+ );
73033
+ }
73034
+ previousEnvValues.set(key, process.env[key]);
73035
+ settings.setValue(`env.${key}`, value);
73036
+ process.env[key] = value;
73037
+ }
73038
+ currentStep = "modelProviders";
73039
+ let updatedModelProviders = {
73040
+ ...previousRuntimeProviders
73041
+ };
73042
+ for (const patch of plan.modelProviders ?? []) {
73043
+ updatedModelProviders = applyModelProvidersPatch(
73044
+ updatedModelProviders,
73045
+ patch
73046
+ );
73047
+ settings.setValue(
73048
+ `modelProviders.${patch.authType}`,
73049
+ updatedModelProviders[patch.authType] ?? []
73050
+ );
73051
+ }
73052
+ currentStep = "authType";
73053
+ settings.setValue("security.auth.selectedType", plan.authType);
73054
+ currentStep = "legacyCredentials";
73055
+ if (plan.legacyCredentials?.apiKey != null) {
73056
+ settings.setValue("security.auth.apiKey", plan.legacyCredentials.apiKey);
73057
+ }
73058
+ if (plan.legacyCredentials?.baseUrl != null) {
73059
+ settings.setValue(
73060
+ "security.auth.baseUrl",
73061
+ plan.legacyCredentials.baseUrl
73062
+ );
73063
+ }
73064
+ currentStep = "modelSelection";
73065
+ if (plan.modelSelection?.modelId) {
73066
+ settings.setValue("model.name", plan.modelSelection.modelId);
73067
+ if (plan.modelSelection.baseUrl) {
73068
+ settings.setValue("model.baseUrl", plan.modelSelection.baseUrl);
73069
+ } else {
73070
+ settings.setValue("model.baseUrl", "");
73071
+ }
73072
+ }
73073
+ currentStep = "providerState";
73074
+ for (const [key, entries] of Object.entries(plan.providerState ?? {})) {
73075
+ for (const [field, value] of Object.entries(entries)) {
73076
+ settings.setValue(`${key}.${field}`, value);
73077
+ }
73078
+ }
73079
+ currentStep = "persist";
73080
+ settings.persist();
73081
+ currentStep = "reloadModelProviders";
73082
+ reloadModelProviders?.(updatedModelProviders);
73083
+ if (plan.modelSelection?.modelId) {
73084
+ currentStep = "syncAuthState";
73085
+ syncAuthState?.(
73086
+ plan.authType,
73087
+ plan.modelSelection.modelId,
73088
+ plan.modelSelection.baseUrl
73089
+ );
73090
+ }
73091
+ if (doRefreshAuth && refreshAuth) {
73092
+ currentStep = "refreshAuth";
73093
+ await refreshAuth(plan.authType);
73094
+ }
73095
+ currentStep = "cleanupBackup";
73096
+ settings.cleanupBackup?.();
73097
+ return { updatedModelProviders };
73098
+ } catch (error) {
73099
+ try {
73100
+ settings.restore?.();
73101
+ } catch (restoreErr) {
73102
+ console.error(
73103
+ "[applyProviderInstallPlan] settings.restore failed during rollback:",
73104
+ restoreErr
73105
+ );
73106
+ }
73107
+ try {
73108
+ for (const [key, prev] of previousEnvValues) {
73109
+ if (prev === void 0) {
73110
+ delete process.env[key];
73111
+ } else {
73112
+ process.env[key] = prev;
73113
+ }
73114
+ }
73115
+ } catch (envErr) {
73116
+ console.error("[applyProviderInstallPlan] env rollback failed:", envErr);
73117
+ }
73118
+ try {
73119
+ reloadModelProviders?.(previousRuntimeProviders);
73120
+ } catch (reloadErr) {
73121
+ console.error(
73122
+ "[applyProviderInstallPlan] reloadModelProviders failed during rollback:",
73123
+ reloadErr
73124
+ );
73125
+ }
73126
+ const errMsg = error instanceof Error ? error.message : String(error);
73127
+ throw new ProviderInstallError(errMsg, currentStep, plan.authType, {
73128
+ cause: error instanceof Error ? error : void 0
73129
+ });
73130
+ }
73131
+ }
73132
+ __name(applyProviderInstallPlan, "applyProviderInstallPlan");
73133
+
73182
73134
  // packages/core/src/services/fileDiscoveryService.ts
73183
73135
  init_esbuild_shims();
73184
73136
 
@@ -90191,13 +90143,18 @@ async function pruneSnapshots(dir) {
90191
90143
  await Promise.all(
90192
90144
  toPrune.map((s) => {
90193
90145
  const runId = s.f.replace(/\.json$/, "");
90146
+ const isRunDir = /^wf_[0-9a-f]+$/.test(runId);
90194
90147
  return Promise.all([
90195
90148
  fs26.unlink(`${dir}/${s.f}`).catch(
90196
90149
  (e) => debugLogger52.warn(`prune unlink failed for ${s.f}: ${e}`)
90197
90150
  ),
90198
- fs26.rm(`${dir}/${runId}`, { recursive: true, force: true }).catch(
90199
- (e) => debugLogger52.warn(`prune journal dir failed for ${runId}: ${e}`)
90200
- )
90151
+ ...isRunDir ? [
90152
+ fs26.rm(`${dir}/${runId}`, { recursive: true, force: true }).catch(
90153
+ (e) => debugLogger52.warn(
90154
+ `prune journal dir failed for ${runId}: ${e}`
90155
+ )
90156
+ )
90157
+ ] : []
90201
90158
  ]);
90202
90159
  })
90203
90160
  );
@@ -114666,8 +114623,8 @@ function resolveMaxConcurrentBackgroundAgents(env2 = process.env) {
114666
114623
  if (raw2 === void 0 || raw2.trim() === "") {
114667
114624
  return DEFAULT_MAX_CONCURRENT_BACKGROUND_AGENTS;
114668
114625
  }
114669
- const parsed = Number(raw2);
114670
- if (!Number.isInteger(parsed) || parsed < 1) {
114626
+ const parsed = parsePositiveIntegerEnv(raw2, 0);
114627
+ if (parsed < 1) {
114671
114628
  debugLogger85.warn(
114672
114629
  `Invalid ${BACKGROUND_AGENT_CONCURRENCY_ENV}=${JSON.stringify(raw2)}, using default (${DEFAULT_MAX_CONCURRENT_BACKGROUND_AGENTS})`
114673
114630
  );
@@ -141943,7 +141900,7 @@ var Config = class {
141943
141900
  if (!this.contentGeneratorConfig) {
141944
141901
  return;
141945
141902
  }
141946
- if (authType === AuthType.QWEN_OAUTH && !requiresRefresh) {
141903
+ if (authType === "qwen-oauth" /* QWEN_OAUTH */ && !requiresRefresh) {
141947
141904
  const { config, sources } = resolveContentGeneratorConfigWithSources(
141948
141905
  this,
141949
141906
  authType,
@@ -143666,19 +143623,19 @@ var Config = class {
143666
143623
  }, "registerStructuredOutputIfRequested");
143667
143624
  if (this.getBareMode()) {
143668
143625
  await registerLazy(ToolNames.READ_FILE, async () => {
143669
- const { ReadFileTool } = await import("./read-file-NRX2FSSQ.js");
143626
+ const { ReadFileTool } = await import("./read-file-ZSIMNYPB.js");
143670
143627
  return new ReadFileTool(this);
143671
143628
  });
143672
143629
  await registerLazy(ToolNames.EDIT, async () => {
143673
- const { EditTool } = await import("./edit-QERNJN7K.js");
143630
+ const { EditTool } = await import("./edit-OXD4P5YK.js");
143674
143631
  return new EditTool(this);
143675
143632
  });
143676
143633
  await registerLazy(ToolNames.NOTEBOOK_EDIT, async () => {
143677
- const { NotebookEditTool } = await import("./notebook-edit-J5AY5BRY.js");
143634
+ const { NotebookEditTool } = await import("./notebook-edit-RYYGIJTA.js");
143678
143635
  return new NotebookEditTool(this);
143679
143636
  });
143680
143637
  await registerLazy(ToolNames.SHELL, async () => {
143681
- const { ShellTool: ShellTool2 } = await import("./shell-DLIL6MLU.js");
143638
+ const { ShellTool: ShellTool2 } = await import("./shell-G2CEO7D7.js");
143682
143639
  return new ShellTool2(this);
143683
143640
  });
143684
143641
  await registerStructuredOutputIfRequested();
@@ -143688,11 +143645,11 @@ var Config = class {
143688
143645
  return registry;
143689
143646
  }
143690
143647
  await registerLazy(ToolNames.TOOL_SEARCH, async () => {
143691
- const { ToolSearchTool } = await import("./tool-search-FU7IZAOO.js");
143648
+ const { ToolSearchTool } = await import("./tool-search-2COFGD5N.js");
143692
143649
  return new ToolSearchTool(this);
143693
143650
  });
143694
143651
  await registerLazy(ToolNames.AGENT, async () => {
143695
- const { AgentTool: AgentTool2 } = await import("./agent-IPSDEZNB.js");
143652
+ const { AgentTool: AgentTool2 } = await import("./agent-7CZOLKXM.js");
143696
143653
  return new AgentTool2(this);
143697
143654
  });
143698
143655
  await registerLazy(ToolNames.TASK_STOP, async () => {
@@ -143704,7 +143661,7 @@ var Config = class {
143704
143661
  return new SendMessageTool(this);
143705
143662
  });
143706
143663
  await registerLazy(ToolNames.SKILL, async () => {
143707
- const { SkillTool } = await import("./skill-32TXHY4A.js");
143664
+ const { SkillTool } = await import("./skill-E5YLTHY3.js");
143708
143665
  return new SkillTool(this);
143709
143666
  });
143710
143667
  await registerLazy(ToolNames.LS, async () => {
@@ -143712,7 +143669,7 @@ var Config = class {
143712
143669
  return new LSTool(this);
143713
143670
  });
143714
143671
  await registerLazy(ToolNames.READ_FILE, async () => {
143715
- const { ReadFileTool } = await import("./read-file-NRX2FSSQ.js");
143672
+ const { ReadFileTool } = await import("./read-file-ZSIMNYPB.js");
143716
143673
  return new ReadFileTool(this);
143717
143674
  });
143718
143675
  if (this.getUseRipgrep()) {
@@ -143725,7 +143682,7 @@ var Config = class {
143725
143682
  }
143726
143683
  if (useRipgrep) {
143727
143684
  await registerLazy(ToolNames.GREP, async () => {
143728
- const { RipGrepTool: RipGrepTool2 } = await import("./ripGrep-WF5CKHR5.js");
143685
+ const { RipGrepTool: RipGrepTool2 } = await import("./ripGrep-LONCTNP3.js");
143729
143686
  return new RipGrepTool2(this);
143730
143687
  });
143731
143688
  } else {
@@ -143738,34 +143695,34 @@ var Config = class {
143738
143695
  )
143739
143696
  );
143740
143697
  await registerLazy(ToolNames.GREP, async () => {
143741
- const { GrepTool } = await import("./grep-2DV5BXMH.js");
143698
+ const { GrepTool } = await import("./grep-R3W7SG6T.js");
143742
143699
  return new GrepTool(this);
143743
143700
  });
143744
143701
  }
143745
143702
  } else {
143746
143703
  await registerLazy(ToolNames.GREP, async () => {
143747
- const { GrepTool } = await import("./grep-2DV5BXMH.js");
143704
+ const { GrepTool } = await import("./grep-R3W7SG6T.js");
143748
143705
  return new GrepTool(this);
143749
143706
  });
143750
143707
  }
143751
143708
  await registerLazy(ToolNames.GLOB, async () => {
143752
- const { GlobTool } = await import("./glob-IWDJQI2V.js");
143709
+ const { GlobTool } = await import("./glob-VCPO3AQO.js");
143753
143710
  return new GlobTool(this);
143754
143711
  });
143755
143712
  await registerLazy(ToolNames.EDIT, async () => {
143756
- const { EditTool } = await import("./edit-QERNJN7K.js");
143713
+ const { EditTool } = await import("./edit-OXD4P5YK.js");
143757
143714
  return new EditTool(this);
143758
143715
  });
143759
143716
  await registerLazy(ToolNames.NOTEBOOK_EDIT, async () => {
143760
- const { NotebookEditTool } = await import("./notebook-edit-J5AY5BRY.js");
143717
+ const { NotebookEditTool } = await import("./notebook-edit-RYYGIJTA.js");
143761
143718
  return new NotebookEditTool(this);
143762
143719
  });
143763
143720
  await registerLazy(ToolNames.WRITE_FILE, async () => {
143764
- const { WriteFileTool } = await import("./write-file-NVFPX6CH.js");
143721
+ const { WriteFileTool } = await import("./write-file-P2RNFLJR.js");
143765
143722
  return new WriteFileTool(this);
143766
143723
  });
143767
143724
  await registerLazy(ToolNames.SHELL, async () => {
143768
- const { ShellTool: ShellTool2 } = await import("./shell-DLIL6MLU.js");
143725
+ const { ShellTool: ShellTool2 } = await import("./shell-G2CEO7D7.js");
143769
143726
  return new ShellTool2(this);
143770
143727
  });
143771
143728
  await registerLazy(ToolNames.TODO_WRITE, async () => {
@@ -143778,20 +143735,20 @@ var Config = class {
143778
143735
  });
143779
143736
  if (!this.sdkMode) {
143780
143737
  await registerLazy(ToolNames.EXIT_PLAN_MODE, async () => {
143781
- const { ExitPlanModeTool } = await import("./exitPlanMode-WSRXCBRZ.js");
143738
+ const { ExitPlanModeTool } = await import("./exitPlanMode-AZIUQQHA.js");
143782
143739
  return new ExitPlanModeTool(this);
143783
143740
  });
143784
143741
  await registerLazy(ToolNames.ENTER_PLAN_MODE, async () => {
143785
- const { EnterPlanModeTool } = await import("./enterPlanMode-B2PBF4MA.js");
143742
+ const { EnterPlanModeTool } = await import("./enterPlanMode-7W2FCILY.js");
143786
143743
  return new EnterPlanModeTool(this);
143787
143744
  });
143788
143745
  }
143789
143746
  await registerLazy(ToolNames.ENTER_WORKTREE, async () => {
143790
- const { EnterWorktreeTool } = await import("./enter-worktree-6ZKH5IL3.js");
143747
+ const { EnterWorktreeTool } = await import("./enter-worktree-NKNFTLNO.js");
143791
143748
  return new EnterWorktreeTool(this);
143792
143749
  });
143793
143750
  await registerLazy(ToolNames.EXIT_WORKTREE, async () => {
143794
- const { ExitWorktreeTool } = await import("./exit-worktree-EOCMQO4I.js");
143751
+ const { ExitWorktreeTool } = await import("./exit-worktree-NCRZ52XD.js");
143795
143752
  return new ExitWorktreeTool(this);
143796
143753
  });
143797
143754
  await registerLazy(ToolNames.WEB_FETCH, async () => {
@@ -143813,7 +143770,7 @@ var Config = class {
143813
143770
  await registerStructuredOutputIfRequested();
143814
143771
  if (this.isCronEnabled()) {
143815
143772
  await registerLazy(ToolNames.CRON_CREATE, async () => {
143816
- const { CronCreateTool } = await import("./cron-create-DXKAP5KN.js");
143773
+ const { CronCreateTool } = await import("./cron-create-NHRAAWT5.js");
143817
143774
  return new CronCreateTool(this);
143818
143775
  });
143819
143776
  await registerLazy(ToolNames.CRON_LIST, async () => {
@@ -143831,7 +143788,7 @@ var Config = class {
143831
143788
  }
143832
143789
  if (this.isAgentTeamEnabled()) {
143833
143790
  await registerLazy(ToolNames.TEAM_CREATE, async () => {
143834
- const { TeamCreateTool } = await import("./team-create-EHLDSJGI.js");
143791
+ const { TeamCreateTool } = await import("./team-create-RQCITTFK.js");
143835
143792
  return new TeamCreateTool(this);
143836
143793
  });
143837
143794
  await registerLazy(ToolNames.TEAM_DELETE, async () => {
@@ -143853,16 +143810,16 @@ var Config = class {
143853
143810
  }
143854
143811
  if (this.isWorkflowsEnabled()) {
143855
143812
  await registerLazy(ToolNames.WORKFLOW, async () => {
143856
- const { WorkflowTool } = await import("./workflow-WUDNBCGX.js");
143813
+ const { WorkflowTool } = await import("./workflow-A5VAXYUS.js");
143857
143814
  return new WorkflowTool(this);
143858
143815
  });
143859
143816
  }
143860
143817
  if (this.isComputerUseEnabled()) {
143861
- const { registerComputerUseTools } = await import("./computer-use-YYK42DD5.js");
143818
+ const { registerComputerUseTools } = await import("./computer-use-AY6HODX4.js");
143862
143819
  await registerComputerUseTools(registerLazy, this);
143863
143820
  }
143864
143821
  await registerLazy(ToolNames.MONITOR, async () => {
143865
- const { MonitorTool } = await import("./monitor-6HBDS2RS.js");
143822
+ const { MonitorTool } = await import("./monitor-TQCZALTB.js");
143866
143823
  return new MonitorTool(this);
143867
143824
  });
143868
143825
  if (this.pendingMcpBudgetCallback) {
@@ -147832,8 +147789,6 @@ export {
147832
147789
  loadServerHierarchicalMemory,
147833
147790
  modelRegistryKey,
147834
147791
  ModelRegistry,
147835
- ProviderInstallError,
147836
- applyProviderInstallPlan,
147837
147792
  ModelsConfig,
147838
147793
  resolveField,
147839
147794
  resolveOptionalField,
@@ -147932,6 +147887,8 @@ export {
147932
147887
  findProviderById,
147933
147888
  findProviderByCredentials,
147934
147889
  getAllProviderBaseUrls,
147890
+ ProviderInstallError,
147891
+ applyProviderInstallPlan,
147935
147892
  generateSessionRecap,
147936
147893
  createToolUseSummaryMessage,
147937
147894
  TOOL_USE_SUMMARY_SYSTEM_PROMPT,