@google/gemini-cli-a2a-server 0.21.0 → 0.21.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.
- package/dist/a2a-server.mjs +506 -509
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/a2a-server.mjs
CHANGED
|
@@ -311081,28 +311081,6 @@ var ApiResponseEvent = class {
|
|
|
311081
311081
|
return logRecord;
|
|
311082
311082
|
}
|
|
311083
311083
|
};
|
|
311084
|
-
var EVENT_FLASH_FALLBACK = "gemini_cli.flash_fallback";
|
|
311085
|
-
var FlashFallbackEvent = class {
|
|
311086
|
-
"event.name";
|
|
311087
|
-
"event.timestamp";
|
|
311088
|
-
auth_type;
|
|
311089
|
-
constructor(auth_type) {
|
|
311090
|
-
this["event.name"] = "flash_fallback";
|
|
311091
|
-
this["event.timestamp"] = (/* @__PURE__ */ new Date()).toISOString();
|
|
311092
|
-
this.auth_type = auth_type;
|
|
311093
|
-
}
|
|
311094
|
-
toOpenTelemetryAttributes(config3) {
|
|
311095
|
-
return {
|
|
311096
|
-
...getCommonAttributes(config3),
|
|
311097
|
-
"event.name": EVENT_FLASH_FALLBACK,
|
|
311098
|
-
"event.timestamp": this["event.timestamp"],
|
|
311099
|
-
auth_type: this.auth_type
|
|
311100
|
-
};
|
|
311101
|
-
}
|
|
311102
|
-
toLogBody() {
|
|
311103
|
-
return `Switching to flash as Fallback.`;
|
|
311104
|
-
}
|
|
311105
|
-
};
|
|
311106
311084
|
var EVENT_RIPGREP_FALLBACK = "gemini_cli.ripgrep_fallback";
|
|
311107
311085
|
var RipgrepFallbackEvent = class {
|
|
311108
311086
|
error;
|
|
@@ -311908,8 +311886,8 @@ var Float64Vector = import_vector.default.Float64Vector;
|
|
|
311908
311886
|
var PointerVector = import_vector.default.PointerVector;
|
|
311909
311887
|
|
|
311910
311888
|
// packages/core/dist/src/generated/git-commit.js
|
|
311911
|
-
var GIT_COMMIT_INFO = "
|
|
311912
|
-
var CLI_VERSION = "0.21.
|
|
311889
|
+
var GIT_COMMIT_INFO = "4bdf85f30";
|
|
311890
|
+
var CLI_VERSION = "0.21.1";
|
|
311913
311891
|
|
|
311914
311892
|
// packages/core/dist/src/ide/detect-ide.js
|
|
311915
311893
|
var IDE_DEFINITIONS = {
|
|
@@ -314445,17 +314423,6 @@ function logApiRequest(config3, event) {
|
|
|
314445
314423
|
logger6.emit(event.toSemanticLogRecord(config3));
|
|
314446
314424
|
});
|
|
314447
314425
|
}
|
|
314448
|
-
function logFlashFallback(config3, event) {
|
|
314449
|
-
ClearcutLogger.getInstance(config3)?.logFlashFallbackEvent();
|
|
314450
|
-
bufferTelemetryEvent(() => {
|
|
314451
|
-
const logger6 = import_api_logs.logs.getLogger(SERVICE_NAME);
|
|
314452
|
-
const logRecord = {
|
|
314453
|
-
body: event.toLogBody(),
|
|
314454
|
-
attributes: event.toOpenTelemetryAttributes(config3)
|
|
314455
|
-
};
|
|
314456
|
-
logger6.emit(logRecord);
|
|
314457
|
-
});
|
|
314458
|
-
}
|
|
314459
314426
|
function logRipgrepFallback(config3, event) {
|
|
314460
314427
|
ClearcutLogger.getInstance(config3)?.logRipgrepFallbackEvent();
|
|
314461
314428
|
bufferTelemetryEvent(() => {
|
|
@@ -315094,7 +315061,7 @@ async function createContentGenerator(config3, gcConfig, sessionId2) {
|
|
|
315094
315061
|
if (gcConfig.fakeResponses) {
|
|
315095
315062
|
return FakeContentGenerator.fromFile(gcConfig.fakeResponses);
|
|
315096
315063
|
}
|
|
315097
|
-
const version4 = "0.21.
|
|
315064
|
+
const version4 = "0.21.1";
|
|
315098
315065
|
const customHeadersEnv = process.env["GEMINI_CLI_CUSTOM_HEADERS"] || void 0;
|
|
315099
315066
|
const userAgent = `GeminiCLI/${version4} (${process.platform}; ${process.arch})`;
|
|
315100
315067
|
const customHeadersMap = parseCustomHeaders(customHeadersEnv);
|
|
@@ -352605,114 +352572,88 @@ async function modifyWithEditor(originalParams, modifyContext, editorType, _abor
|
|
|
352605
352572
|
// packages/core/dist/src/utils/llm-edit-fixer.js
|
|
352606
352573
|
import { createHash as createHash8 } from "node:crypto";
|
|
352607
352574
|
|
|
352608
|
-
// packages/core/dist/src/utils/
|
|
352609
|
-
|
|
352610
|
-
|
|
352611
|
-
|
|
352612
|
-
|
|
352613
|
-
|
|
352614
|
-
|
|
352615
|
-
|
|
352616
|
-
|
|
352617
|
-
|
|
352575
|
+
// packages/core/dist/src/utils/secure-browser-launcher.js
|
|
352576
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
352577
|
+
import { promisify as promisify13 } from "node:util";
|
|
352578
|
+
import { platform as platform10 } from "node:os";
|
|
352579
|
+
import { URL as URL6 } from "node:url";
|
|
352580
|
+
var execFileAsync5 = promisify13(execFile6);
|
|
352581
|
+
function validateUrl(url5) {
|
|
352582
|
+
let parsedUrl;
|
|
352583
|
+
try {
|
|
352584
|
+
parsedUrl = new URL6(url5);
|
|
352585
|
+
} catch (_error) {
|
|
352586
|
+
throw new Error(`Invalid URL: ${url5}`);
|
|
352618
352587
|
}
|
|
352619
|
-
|
|
352620
|
-
|
|
352621
|
-
if (part.videoMetadata !== void 0) {
|
|
352622
|
-
return `[Video Metadata]`;
|
|
352623
|
-
}
|
|
352624
|
-
if (part.thought !== void 0) {
|
|
352625
|
-
return `[Thought: ${part.thought}]`;
|
|
352626
|
-
}
|
|
352627
|
-
if (part.codeExecutionResult !== void 0) {
|
|
352628
|
-
return `[Code Execution Result]`;
|
|
352629
|
-
}
|
|
352630
|
-
if (part.executableCode !== void 0) {
|
|
352631
|
-
return `[Executable Code]`;
|
|
352632
|
-
}
|
|
352633
|
-
if (part.fileData !== void 0) {
|
|
352634
|
-
return `[File Data]`;
|
|
352635
|
-
}
|
|
352636
|
-
if (part.functionCall !== void 0) {
|
|
352637
|
-
return `[Function Call: ${part.functionCall.name}]`;
|
|
352638
|
-
}
|
|
352639
|
-
if (part.functionResponse !== void 0) {
|
|
352640
|
-
return `[Function Response: ${part.functionResponse.name}]`;
|
|
352641
|
-
}
|
|
352642
|
-
if (part.inlineData !== void 0) {
|
|
352643
|
-
return `<${part.inlineData.mimeType}>`;
|
|
352644
|
-
}
|
|
352588
|
+
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
|
352589
|
+
throw new Error(`Unsafe protocol: ${parsedUrl.protocol}. Only HTTP and HTTPS are allowed.`);
|
|
352645
352590
|
}
|
|
352646
|
-
|
|
352647
|
-
|
|
352648
|
-
function getResponseText(response) {
|
|
352649
|
-
if (response.candidates && response.candidates.length > 0) {
|
|
352650
|
-
const candidate = response.candidates[0];
|
|
352651
|
-
if (candidate.content && candidate.content.parts && candidate.content.parts.length > 0) {
|
|
352652
|
-
return candidate.content.parts.filter((part) => part.text).map((part) => part.text).join("");
|
|
352653
|
-
}
|
|
352591
|
+
if (/[\r\n\x00-\x1f]/.test(url5)) {
|
|
352592
|
+
throw new Error("URL contains invalid characters");
|
|
352654
352593
|
}
|
|
352655
|
-
return null;
|
|
352656
352594
|
}
|
|
352657
|
-
|
|
352658
|
-
|
|
352659
|
-
|
|
352660
|
-
|
|
352661
|
-
|
|
352662
|
-
|
|
352663
|
-
|
|
352664
|
-
|
|
352665
|
-
|
|
352666
|
-
|
|
352667
|
-
|
|
352668
|
-
|
|
352669
|
-
|
|
352670
|
-
|
|
352671
|
-
|
|
352672
|
-
|
|
352673
|
-
|
|
352674
|
-
|
|
352675
|
-
|
|
352676
|
-
|
|
352677
|
-
|
|
352678
|
-
|
|
352679
|
-
|
|
352680
|
-
|
|
352681
|
-
|
|
352682
|
-
|
|
352683
|
-
|
|
352684
|
-
|
|
352685
|
-
|
|
352686
|
-
if (context2) {
|
|
352687
|
-
console.error("Original context could not be stringified or included in report.");
|
|
352688
|
-
}
|
|
352689
|
-
try {
|
|
352690
|
-
const minimalReportContent = { error: errorToReport };
|
|
352691
|
-
stringifiedReportContent = JSON.stringify(minimalReportContent, null, 2);
|
|
352692
|
-
await fs40.writeFile(reportPath, stringifiedReportContent);
|
|
352693
|
-
console.error(`${baseMessage} Partial report (excluding context) available at: ${reportPath}`);
|
|
352694
|
-
} catch (minimalWriteError) {
|
|
352695
|
-
console.error(`${baseMessage} Failed to write even a minimal error report:`, minimalWriteError);
|
|
352696
|
-
}
|
|
352697
|
-
return;
|
|
352595
|
+
async function openBrowserSecurely(url5) {
|
|
352596
|
+
validateUrl(url5);
|
|
352597
|
+
const platformName = platform10();
|
|
352598
|
+
let command;
|
|
352599
|
+
let args2;
|
|
352600
|
+
switch (platformName) {
|
|
352601
|
+
case "darwin":
|
|
352602
|
+
command = "open";
|
|
352603
|
+
args2 = [url5];
|
|
352604
|
+
break;
|
|
352605
|
+
case "win32":
|
|
352606
|
+
command = "powershell.exe";
|
|
352607
|
+
args2 = [
|
|
352608
|
+
"-NoProfile",
|
|
352609
|
+
"-NonInteractive",
|
|
352610
|
+
"-WindowStyle",
|
|
352611
|
+
"Hidden",
|
|
352612
|
+
"-Command",
|
|
352613
|
+
`Start-Process '${url5.replace(/'/g, "''")}'`
|
|
352614
|
+
];
|
|
352615
|
+
break;
|
|
352616
|
+
case "linux":
|
|
352617
|
+
case "freebsd":
|
|
352618
|
+
case "openbsd":
|
|
352619
|
+
command = "xdg-open";
|
|
352620
|
+
args2 = [url5];
|
|
352621
|
+
break;
|
|
352622
|
+
default:
|
|
352623
|
+
throw new Error(`Unsupported platform: ${platformName}`);
|
|
352698
352624
|
}
|
|
352625
|
+
const options2 = {
|
|
352626
|
+
// Don't inherit parent's environment to avoid potential issues
|
|
352627
|
+
env: {
|
|
352628
|
+
...process.env,
|
|
352629
|
+
// Ensure we're not in a shell that might interpret special characters
|
|
352630
|
+
SHELL: void 0
|
|
352631
|
+
},
|
|
352632
|
+
// Detach the browser process so it doesn't block
|
|
352633
|
+
detached: true,
|
|
352634
|
+
stdio: "ignore"
|
|
352635
|
+
};
|
|
352699
352636
|
try {
|
|
352700
|
-
await
|
|
352701
|
-
|
|
352702
|
-
|
|
352703
|
-
|
|
352704
|
-
|
|
352705
|
-
|
|
352706
|
-
|
|
352707
|
-
|
|
352708
|
-
|
|
352637
|
+
await execFileAsync5(command, args2, options2);
|
|
352638
|
+
} catch (error2) {
|
|
352639
|
+
if ((platformName === "linux" || platformName === "freebsd" || platformName === "openbsd") && command === "xdg-open") {
|
|
352640
|
+
const fallbackCommands = [
|
|
352641
|
+
"gnome-open",
|
|
352642
|
+
"kde-open",
|
|
352643
|
+
"firefox",
|
|
352644
|
+
"chromium",
|
|
352645
|
+
"google-chrome"
|
|
352646
|
+
];
|
|
352647
|
+
for (const fallbackCommand of fallbackCommands) {
|
|
352709
352648
|
try {
|
|
352710
|
-
|
|
352649
|
+
await execFileAsync5(fallbackCommand, [url5], options2);
|
|
352650
|
+
return;
|
|
352711
352651
|
} catch {
|
|
352712
|
-
|
|
352652
|
+
continue;
|
|
352713
352653
|
}
|
|
352714
352654
|
}
|
|
352715
352655
|
}
|
|
352656
|
+
throw new Error(`Failed to open browser: ${error2 instanceof Error ? error2.message : "Unknown error"}`);
|
|
352716
352657
|
}
|
|
352717
352658
|
}
|
|
352718
352659
|
|
|
@@ -352757,28 +352698,28 @@ function parseGoogleApiError(error2) {
|
|
|
352757
352698
|
const code2 = currentError.code;
|
|
352758
352699
|
const message = currentError.message;
|
|
352759
352700
|
const errorDetails = currentError.details;
|
|
352760
|
-
if (
|
|
352701
|
+
if (code2 && message) {
|
|
352761
352702
|
const details = [];
|
|
352762
|
-
|
|
352763
|
-
|
|
352764
|
-
|
|
352765
|
-
|
|
352766
|
-
|
|
352767
|
-
if (typeKey
|
|
352768
|
-
|
|
352769
|
-
|
|
352703
|
+
if (Array.isArray(errorDetails)) {
|
|
352704
|
+
for (const detail of errorDetails) {
|
|
352705
|
+
if (detail && typeof detail === "object") {
|
|
352706
|
+
const detailObj = detail;
|
|
352707
|
+
const typeKey = Object.keys(detailObj).find((key) => key.trim() === "@type");
|
|
352708
|
+
if (typeKey) {
|
|
352709
|
+
if (typeKey !== "@type") {
|
|
352710
|
+
detailObj["@type"] = detailObj[typeKey];
|
|
352711
|
+
delete detailObj[typeKey];
|
|
352712
|
+
}
|
|
352713
|
+
details.push(detailObj);
|
|
352770
352714
|
}
|
|
352771
|
-
details.push(detailObj);
|
|
352772
352715
|
}
|
|
352773
352716
|
}
|
|
352774
352717
|
}
|
|
352775
|
-
|
|
352776
|
-
|
|
352777
|
-
|
|
352778
|
-
|
|
352779
|
-
|
|
352780
|
-
};
|
|
352781
|
-
}
|
|
352718
|
+
return {
|
|
352719
|
+
code: code2,
|
|
352720
|
+
message,
|
|
352721
|
+
details
|
|
352722
|
+
};
|
|
352782
352723
|
}
|
|
352783
352724
|
return null;
|
|
352784
352725
|
}
|
|
@@ -352820,6 +352761,16 @@ function fromApiError(errorObj) {
|
|
|
352820
352761
|
try {
|
|
352821
352762
|
data = JSON.parse(data);
|
|
352822
352763
|
} catch (_) {
|
|
352764
|
+
if (typeof data === "string") {
|
|
352765
|
+
const firstBrace = data.indexOf("{");
|
|
352766
|
+
const lastBrace = data.lastIndexOf("}");
|
|
352767
|
+
if (firstBrace !== -1 && lastBrace !== -1 && lastBrace > firstBrace) {
|
|
352768
|
+
try {
|
|
352769
|
+
data = JSON.parse(data.substring(firstBrace, lastBrace + 1));
|
|
352770
|
+
} catch (__) {
|
|
352771
|
+
}
|
|
352772
|
+
}
|
|
352773
|
+
}
|
|
352823
352774
|
}
|
|
352824
352775
|
}
|
|
352825
352776
|
if (Array.isArray(data) && data.length > 0) {
|
|
@@ -352897,8 +352848,8 @@ function classifyGoogleError(error2) {
|
|
|
352897
352848
|
const message = googleApiError?.message || (error2 instanceof Error ? error2.message : "Model not found");
|
|
352898
352849
|
return new ModelNotFoundError(message, status);
|
|
352899
352850
|
}
|
|
352900
|
-
if (!googleApiError || googleApiError.code !== 429) {
|
|
352901
|
-
const errorMessage = error2 instanceof Error ? error2.message : String(error2);
|
|
352851
|
+
if (!googleApiError || googleApiError.code !== 429 || googleApiError.details.length === 0) {
|
|
352852
|
+
const errorMessage = googleApiError?.message || (error2 instanceof Error ? error2.message : String(error2));
|
|
352902
352853
|
const match2 = errorMessage.match(/Please retry in ([0-9.]+(?:ms|s))/);
|
|
352903
352854
|
if (match2?.[1]) {
|
|
352904
352855
|
const retryDelaySeconds = parseDurationInSeconds(match2[1]);
|
|
@@ -352980,33 +352931,6 @@ Suggested retry after 60s.`, googleApiError, 60);
|
|
|
352980
352931
|
return error2;
|
|
352981
352932
|
}
|
|
352982
352933
|
|
|
352983
|
-
// packages/core/dist/src/utils/delay.js
|
|
352984
|
-
function createAbortError() {
|
|
352985
|
-
const abortError = new Error("Aborted");
|
|
352986
|
-
abortError.name = "AbortError";
|
|
352987
|
-
return abortError;
|
|
352988
|
-
}
|
|
352989
|
-
function delay2(ms, signal) {
|
|
352990
|
-
if (!signal) {
|
|
352991
|
-
return new Promise((resolve14) => setTimeout(resolve14, ms));
|
|
352992
|
-
}
|
|
352993
|
-
if (signal.aborted) {
|
|
352994
|
-
return Promise.reject(createAbortError());
|
|
352995
|
-
}
|
|
352996
|
-
return new Promise((resolve14, reject) => {
|
|
352997
|
-
const onAbort = () => {
|
|
352998
|
-
clearTimeout(timeoutId);
|
|
352999
|
-
signal.removeEventListener("abort", onAbort);
|
|
353000
|
-
reject(createAbortError());
|
|
353001
|
-
};
|
|
353002
|
-
const timeoutId = setTimeout(() => {
|
|
353003
|
-
signal.removeEventListener("abort", onAbort);
|
|
353004
|
-
resolve14();
|
|
353005
|
-
}, ms);
|
|
353006
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
353007
|
-
});
|
|
353008
|
-
}
|
|
353009
|
-
|
|
353010
352934
|
// packages/core/dist/src/availability/errorClassification.js
|
|
353011
352935
|
function classifyFailureKind(error2) {
|
|
353012
352936
|
if (error2 instanceof TerminalQuotaError) {
|
|
@@ -353023,23 +352947,31 @@ function classifyFailureKind(error2) {
|
|
|
353023
352947
|
|
|
353024
352948
|
// packages/core/dist/src/config/models.js
|
|
353025
352949
|
var PREVIEW_GEMINI_MODEL = "gemini-3-pro-preview";
|
|
352950
|
+
var PREVIEW_GEMINI_FLASH_MODEL = "gemini-3-flash-preview";
|
|
353026
352951
|
var DEFAULT_GEMINI_MODEL = "gemini-2.5-pro";
|
|
353027
352952
|
var DEFAULT_GEMINI_FLASH_MODEL = "gemini-2.5-flash";
|
|
353028
352953
|
var DEFAULT_GEMINI_FLASH_LITE_MODEL = "gemini-2.5-flash-lite";
|
|
353029
|
-
var
|
|
352954
|
+
var PREVIEW_GEMINI_MODEL_AUTO = "auto-gemini-3";
|
|
352955
|
+
var DEFAULT_GEMINI_MODEL_AUTO = "auto-gemini-2.5";
|
|
352956
|
+
var GEMINI_MODEL_ALIAS_AUTO = "auto";
|
|
353030
352957
|
var GEMINI_MODEL_ALIAS_PRO = "pro";
|
|
353031
352958
|
var GEMINI_MODEL_ALIAS_FLASH = "flash";
|
|
353032
352959
|
var GEMINI_MODEL_ALIAS_FLASH_LITE = "flash-lite";
|
|
353033
352960
|
var DEFAULT_GEMINI_EMBEDDING_MODEL = "gemini-embedding-001";
|
|
353034
352961
|
var DEFAULT_THINKING_MODE = 8192;
|
|
353035
|
-
function resolveModel(requestedModel, previewFeaturesEnabled) {
|
|
352962
|
+
function resolveModel(requestedModel, previewFeaturesEnabled = false) {
|
|
353036
352963
|
switch (requestedModel) {
|
|
353037
|
-
case
|
|
352964
|
+
case PREVIEW_GEMINI_MODEL_AUTO: {
|
|
352965
|
+
return PREVIEW_GEMINI_MODEL;
|
|
352966
|
+
}
|
|
352967
|
+
case DEFAULT_GEMINI_MODEL_AUTO: {
|
|
352968
|
+
return DEFAULT_GEMINI_MODEL;
|
|
352969
|
+
}
|
|
353038
352970
|
case GEMINI_MODEL_ALIAS_PRO: {
|
|
353039
352971
|
return previewFeaturesEnabled ? PREVIEW_GEMINI_MODEL : DEFAULT_GEMINI_MODEL;
|
|
353040
352972
|
}
|
|
353041
352973
|
case GEMINI_MODEL_ALIAS_FLASH: {
|
|
353042
|
-
return DEFAULT_GEMINI_FLASH_MODEL;
|
|
352974
|
+
return previewFeaturesEnabled ? PREVIEW_GEMINI_FLASH_MODEL : DEFAULT_GEMINI_FLASH_MODEL;
|
|
353043
352975
|
}
|
|
353044
352976
|
case GEMINI_MODEL_ALIAS_FLASH_LITE: {
|
|
353045
352977
|
return DEFAULT_GEMINI_FLASH_LITE_MODEL;
|
|
@@ -353049,15 +352981,23 @@ function resolveModel(requestedModel, previewFeaturesEnabled) {
|
|
|
353049
352981
|
}
|
|
353050
352982
|
}
|
|
353051
352983
|
}
|
|
353052
|
-
function
|
|
353053
|
-
|
|
353054
|
-
|
|
353055
|
-
|
|
353056
|
-
|
|
353057
|
-
|
|
353058
|
-
|
|
352984
|
+
function resolveClassifierModel(requestedModel, modelAlias, previewFeaturesEnabled = false) {
|
|
352985
|
+
if (modelAlias === GEMINI_MODEL_ALIAS_FLASH) {
|
|
352986
|
+
if (requestedModel === DEFAULT_GEMINI_MODEL_AUTO || requestedModel === DEFAULT_GEMINI_MODEL) {
|
|
352987
|
+
return DEFAULT_GEMINI_FLASH_MODEL;
|
|
352988
|
+
}
|
|
352989
|
+
if (requestedModel === PREVIEW_GEMINI_MODEL_AUTO || requestedModel === PREVIEW_GEMINI_MODEL) {
|
|
352990
|
+
return PREVIEW_GEMINI_FLASH_MODEL;
|
|
352991
|
+
}
|
|
352992
|
+
return resolveModel(GEMINI_MODEL_ALIAS_FLASH, previewFeaturesEnabled);
|
|
353059
352993
|
}
|
|
353060
|
-
return
|
|
352994
|
+
return resolveModel(requestedModel, previewFeaturesEnabled);
|
|
352995
|
+
}
|
|
352996
|
+
function getEffectiveModel(requestedModel, previewFeaturesEnabled) {
|
|
352997
|
+
return resolveModel(requestedModel, previewFeaturesEnabled);
|
|
352998
|
+
}
|
|
352999
|
+
function isPreviewModel(model) {
|
|
353000
|
+
return model === PREVIEW_GEMINI_MODEL || model === PREVIEW_GEMINI_FLASH_MODEL || model === PREVIEW_GEMINI_MODEL_AUTO;
|
|
353061
353001
|
}
|
|
353062
353002
|
function isGemini2Model(model) {
|
|
353063
353003
|
return /^gemini-2(\.|$)/.test(model);
|
|
@@ -353081,13 +353021,8 @@ var DEFAULT_CHAIN = [
|
|
|
353081
353021
|
definePolicy({ model: DEFAULT_GEMINI_FLASH_MODEL, isLastResort: true })
|
|
353082
353022
|
];
|
|
353083
353023
|
var PREVIEW_CHAIN = [
|
|
353084
|
-
definePolicy({
|
|
353085
|
-
|
|
353086
|
-
stateTransitions: { transient: "sticky_retry" },
|
|
353087
|
-
actions: { transient: "silent" }
|
|
353088
|
-
}),
|
|
353089
|
-
definePolicy({ model: DEFAULT_GEMINI_MODEL }),
|
|
353090
|
-
definePolicy({ model: DEFAULT_GEMINI_FLASH_MODEL, isLastResort: true })
|
|
353024
|
+
definePolicy({ model: PREVIEW_GEMINI_MODEL }),
|
|
353025
|
+
definePolicy({ model: PREVIEW_GEMINI_FLASH_MODEL, isLastResort: true })
|
|
353091
353026
|
];
|
|
353092
353027
|
function getModelPolicyChain(options2) {
|
|
353093
353028
|
if (options2.previewEnabled) {
|
|
@@ -353095,6 +353030,9 @@ function getModelPolicyChain(options2) {
|
|
|
353095
353030
|
}
|
|
353096
353031
|
return cloneChain(DEFAULT_CHAIN);
|
|
353097
353032
|
}
|
|
353033
|
+
function createSingleModelChain(model) {
|
|
353034
|
+
return [definePolicy({ model, isLastResort: true })];
|
|
353035
|
+
}
|
|
353098
353036
|
function createDefaultPolicy(model, options2) {
|
|
353099
353037
|
return definePolicy({ model, isLastResort: options2?.isLastResort });
|
|
353100
353038
|
}
|
|
@@ -353121,28 +353059,33 @@ function cloneChain(chain2) {
|
|
|
353121
353059
|
}
|
|
353122
353060
|
|
|
353123
353061
|
// packages/core/dist/src/availability/policyHelpers.js
|
|
353124
|
-
function resolvePolicyChain(config3, preferredModel) {
|
|
353125
|
-
const
|
|
353126
|
-
|
|
353127
|
-
|
|
353128
|
-
|
|
353129
|
-
|
|
353130
|
-
|
|
353131
|
-
|
|
353062
|
+
function resolvePolicyChain(config3, preferredModel, wrapsAround = false) {
|
|
353063
|
+
const modelFromConfig = preferredModel ?? config3.getActiveModel?.() ?? config3.getModel();
|
|
353064
|
+
let chain2;
|
|
353065
|
+
if (config3.getModel() === PREVIEW_GEMINI_MODEL_AUTO || config3.getModel() === DEFAULT_GEMINI_MODEL_AUTO) {
|
|
353066
|
+
chain2 = getModelPolicyChain({
|
|
353067
|
+
previewEnabled: config3.getModel() === PREVIEW_GEMINI_MODEL_AUTO,
|
|
353068
|
+
userTier: config3.getUserTier()
|
|
353069
|
+
});
|
|
353070
|
+
} else {
|
|
353071
|
+
chain2 = createSingleModelChain(modelFromConfig);
|
|
353132
353072
|
}
|
|
353133
|
-
|
|
353134
|
-
|
|
353073
|
+
const activeModel = resolveModel(modelFromConfig);
|
|
353074
|
+
const activeIndex = chain2.findIndex((policy) => policy.model === activeModel);
|
|
353075
|
+
if (activeIndex !== -1) {
|
|
353076
|
+
return wrapsAround ? [...chain2.slice(activeIndex), ...chain2.slice(0, activeIndex)] : [...chain2.slice(activeIndex)];
|
|
353135
353077
|
}
|
|
353136
353078
|
return [createDefaultPolicy(activeModel, { isLastResort: true })];
|
|
353137
353079
|
}
|
|
353138
|
-
function buildFallbackPolicyContext(chain2, failedModel) {
|
|
353080
|
+
function buildFallbackPolicyContext(chain2, failedModel, wrapsAround = false) {
|
|
353139
353081
|
const index = chain2.findIndex((policy) => policy.model === failedModel);
|
|
353140
353082
|
if (index === -1) {
|
|
353141
353083
|
return { failedPolicy: void 0, candidates: chain2 };
|
|
353142
353084
|
}
|
|
353085
|
+
const candidates = wrapsAround ? [...chain2.slice(index + 1), ...chain2.slice(0, index)] : [...chain2.slice(index + 1)];
|
|
353143
353086
|
return {
|
|
353144
353087
|
failedPolicy: chain2[index],
|
|
353145
|
-
candidates
|
|
353088
|
+
candidates
|
|
353146
353089
|
};
|
|
353147
353090
|
}
|
|
353148
353091
|
function resolvePolicyAction(failureKind, policy) {
|
|
@@ -353209,6 +353152,230 @@ function applyAvailabilityTransition(getContext, failureKind) {
|
|
|
353209
353152
|
}
|
|
353210
353153
|
}
|
|
353211
353154
|
|
|
353155
|
+
// packages/core/dist/src/fallback/handler.js
|
|
353156
|
+
var UPGRADE_URL_PAGE = "https://goo.gle/set-up-gemini-code-assist";
|
|
353157
|
+
async function handleFallback(config3, failedModel, authType, error2) {
|
|
353158
|
+
return handlePolicyDrivenFallback(config3, failedModel, authType, error2);
|
|
353159
|
+
}
|
|
353160
|
+
async function handlePolicyDrivenFallback(config3, failedModel, authType, error2) {
|
|
353161
|
+
if (authType !== AuthType2.LOGIN_WITH_GOOGLE) {
|
|
353162
|
+
return null;
|
|
353163
|
+
}
|
|
353164
|
+
const chain2 = resolvePolicyChain(config3);
|
|
353165
|
+
const { failedPolicy, candidates } = buildFallbackPolicyContext(chain2, failedModel);
|
|
353166
|
+
const failureKind = classifyFailureKind(error2);
|
|
353167
|
+
const availability = config3.getModelAvailabilityService();
|
|
353168
|
+
const getAvailabilityContext = () => {
|
|
353169
|
+
if (!failedPolicy)
|
|
353170
|
+
return void 0;
|
|
353171
|
+
return { service: availability, policy: failedPolicy };
|
|
353172
|
+
};
|
|
353173
|
+
let fallbackModel;
|
|
353174
|
+
if (!candidates.length) {
|
|
353175
|
+
fallbackModel = failedModel;
|
|
353176
|
+
} else {
|
|
353177
|
+
const selection = availability.selectFirstAvailable(candidates.map((policy) => policy.model));
|
|
353178
|
+
const lastResortPolicy = candidates.find((policy) => policy.isLastResort);
|
|
353179
|
+
const selectedFallbackModel = selection.selectedModel ?? lastResortPolicy?.model;
|
|
353180
|
+
const selectedPolicy = candidates.find((policy) => policy.model === selectedFallbackModel);
|
|
353181
|
+
if (!selectedFallbackModel || selectedFallbackModel === failedModel || !selectedPolicy) {
|
|
353182
|
+
return null;
|
|
353183
|
+
}
|
|
353184
|
+
fallbackModel = selectedFallbackModel;
|
|
353185
|
+
const action = resolvePolicyAction(failureKind, selectedPolicy);
|
|
353186
|
+
if (action === "silent") {
|
|
353187
|
+
applyAvailabilityTransition(getAvailabilityContext, failureKind);
|
|
353188
|
+
return processIntent(config3, "retry_always", fallbackModel);
|
|
353189
|
+
}
|
|
353190
|
+
const recommendation = {
|
|
353191
|
+
...selection,
|
|
353192
|
+
selectedModel: fallbackModel,
|
|
353193
|
+
action,
|
|
353194
|
+
failureKind,
|
|
353195
|
+
failedPolicy,
|
|
353196
|
+
selectedPolicy
|
|
353197
|
+
};
|
|
353198
|
+
void recommendation;
|
|
353199
|
+
}
|
|
353200
|
+
const handler = config3.getFallbackModelHandler();
|
|
353201
|
+
if (typeof handler !== "function") {
|
|
353202
|
+
return null;
|
|
353203
|
+
}
|
|
353204
|
+
try {
|
|
353205
|
+
const intent = await handler(failedModel, fallbackModel, error2);
|
|
353206
|
+
if (intent === "retry_always" || intent === "retry_once") {
|
|
353207
|
+
applyAvailabilityTransition(getAvailabilityContext, failureKind);
|
|
353208
|
+
}
|
|
353209
|
+
return await processIntent(config3, intent, fallbackModel);
|
|
353210
|
+
} catch (handlerError) {
|
|
353211
|
+
debugLogger.error("Fallback handler failed:", handlerError);
|
|
353212
|
+
return null;
|
|
353213
|
+
}
|
|
353214
|
+
}
|
|
353215
|
+
async function handleUpgrade() {
|
|
353216
|
+
try {
|
|
353217
|
+
await openBrowserSecurely(UPGRADE_URL_PAGE);
|
|
353218
|
+
} catch (error2) {
|
|
353219
|
+
debugLogger.warn("Failed to open browser automatically:", getErrorMessage(error2));
|
|
353220
|
+
}
|
|
353221
|
+
}
|
|
353222
|
+
async function processIntent(config3, intent, fallbackModel) {
|
|
353223
|
+
switch (intent) {
|
|
353224
|
+
case "retry_always":
|
|
353225
|
+
config3.setActiveModel(fallbackModel);
|
|
353226
|
+
return true;
|
|
353227
|
+
case "retry_once":
|
|
353228
|
+
return true;
|
|
353229
|
+
case "stop":
|
|
353230
|
+
return false;
|
|
353231
|
+
case "retry_later":
|
|
353232
|
+
return false;
|
|
353233
|
+
case "upgrade":
|
|
353234
|
+
await handleUpgrade();
|
|
353235
|
+
return false;
|
|
353236
|
+
default:
|
|
353237
|
+
throw new Error(`Unexpected fallback intent received from fallbackModelHandler: "${intent}"`);
|
|
353238
|
+
}
|
|
353239
|
+
}
|
|
353240
|
+
|
|
353241
|
+
// packages/core/dist/src/utils/partUtils.js
|
|
353242
|
+
function partToString(value, options2) {
|
|
353243
|
+
if (!value) {
|
|
353244
|
+
return "";
|
|
353245
|
+
}
|
|
353246
|
+
if (typeof value === "string") {
|
|
353247
|
+
return value;
|
|
353248
|
+
}
|
|
353249
|
+
if (Array.isArray(value)) {
|
|
353250
|
+
return value.map((part2) => partToString(part2, options2)).join("");
|
|
353251
|
+
}
|
|
353252
|
+
const part = value;
|
|
353253
|
+
if (options2?.verbose) {
|
|
353254
|
+
if (part.videoMetadata !== void 0) {
|
|
353255
|
+
return `[Video Metadata]`;
|
|
353256
|
+
}
|
|
353257
|
+
if (part.thought !== void 0) {
|
|
353258
|
+
return `[Thought: ${part.thought}]`;
|
|
353259
|
+
}
|
|
353260
|
+
if (part.codeExecutionResult !== void 0) {
|
|
353261
|
+
return `[Code Execution Result]`;
|
|
353262
|
+
}
|
|
353263
|
+
if (part.executableCode !== void 0) {
|
|
353264
|
+
return `[Executable Code]`;
|
|
353265
|
+
}
|
|
353266
|
+
if (part.fileData !== void 0) {
|
|
353267
|
+
return `[File Data]`;
|
|
353268
|
+
}
|
|
353269
|
+
if (part.functionCall !== void 0) {
|
|
353270
|
+
return `[Function Call: ${part.functionCall.name}]`;
|
|
353271
|
+
}
|
|
353272
|
+
if (part.functionResponse !== void 0) {
|
|
353273
|
+
return `[Function Response: ${part.functionResponse.name}]`;
|
|
353274
|
+
}
|
|
353275
|
+
if (part.inlineData !== void 0) {
|
|
353276
|
+
return `<${part.inlineData.mimeType}>`;
|
|
353277
|
+
}
|
|
353278
|
+
}
|
|
353279
|
+
return part.text ?? "";
|
|
353280
|
+
}
|
|
353281
|
+
function getResponseText(response) {
|
|
353282
|
+
if (response.candidates && response.candidates.length > 0) {
|
|
353283
|
+
const candidate = response.candidates[0];
|
|
353284
|
+
if (candidate.content && candidate.content.parts && candidate.content.parts.length > 0) {
|
|
353285
|
+
return candidate.content.parts.filter((part) => part.text).map((part) => part.text).join("");
|
|
353286
|
+
}
|
|
353287
|
+
}
|
|
353288
|
+
return null;
|
|
353289
|
+
}
|
|
353290
|
+
|
|
353291
|
+
// packages/core/dist/src/utils/errorReporting.js
|
|
353292
|
+
import fs40 from "node:fs/promises";
|
|
353293
|
+
import os13 from "node:os";
|
|
353294
|
+
import path40 from "node:path";
|
|
353295
|
+
async function reportError(error2, baseMessage, context2, type = "general", reportingDir = os13.tmpdir()) {
|
|
353296
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
353297
|
+
const reportFileName = `gemini-client-error-${type}-${timestamp}.json`;
|
|
353298
|
+
const reportPath = path40.join(reportingDir, reportFileName);
|
|
353299
|
+
let errorToReport;
|
|
353300
|
+
if (error2 instanceof Error) {
|
|
353301
|
+
errorToReport = { message: error2.message, stack: error2.stack };
|
|
353302
|
+
} else if (typeof error2 === "object" && error2 !== null && "message" in error2) {
|
|
353303
|
+
errorToReport = {
|
|
353304
|
+
message: String(error2.message)
|
|
353305
|
+
};
|
|
353306
|
+
} else {
|
|
353307
|
+
errorToReport = { message: String(error2) };
|
|
353308
|
+
}
|
|
353309
|
+
const reportContent = { error: errorToReport };
|
|
353310
|
+
if (context2) {
|
|
353311
|
+
reportContent.context = context2;
|
|
353312
|
+
}
|
|
353313
|
+
let stringifiedReportContent;
|
|
353314
|
+
try {
|
|
353315
|
+
stringifiedReportContent = JSON.stringify(reportContent, null, 2);
|
|
353316
|
+
} catch (stringifyError) {
|
|
353317
|
+
console.error(`${baseMessage} Could not stringify report content (likely due to context):`, stringifyError);
|
|
353318
|
+
console.error("Original error that triggered report generation:", error2);
|
|
353319
|
+
if (context2) {
|
|
353320
|
+
console.error("Original context could not be stringified or included in report.");
|
|
353321
|
+
}
|
|
353322
|
+
try {
|
|
353323
|
+
const minimalReportContent = { error: errorToReport };
|
|
353324
|
+
stringifiedReportContent = JSON.stringify(minimalReportContent, null, 2);
|
|
353325
|
+
await fs40.writeFile(reportPath, stringifiedReportContent);
|
|
353326
|
+
console.error(`${baseMessage} Partial report (excluding context) available at: ${reportPath}`);
|
|
353327
|
+
} catch (minimalWriteError) {
|
|
353328
|
+
console.error(`${baseMessage} Failed to write even a minimal error report:`, minimalWriteError);
|
|
353329
|
+
}
|
|
353330
|
+
return;
|
|
353331
|
+
}
|
|
353332
|
+
try {
|
|
353333
|
+
await fs40.writeFile(reportPath, stringifiedReportContent);
|
|
353334
|
+
console.error(`${baseMessage} Full report available at: ${reportPath}`);
|
|
353335
|
+
} catch (writeError) {
|
|
353336
|
+
console.error(`${baseMessage} Additionally, failed to write detailed error report:`, writeError);
|
|
353337
|
+
console.error("Original error that triggered report generation:", error2);
|
|
353338
|
+
if (context2) {
|
|
353339
|
+
try {
|
|
353340
|
+
console.error("Original context:", context2);
|
|
353341
|
+
} catch {
|
|
353342
|
+
try {
|
|
353343
|
+
console.error("Original context (stringified, truncated):", JSON.stringify(context2).substring(0, 1e3));
|
|
353344
|
+
} catch {
|
|
353345
|
+
console.error("Original context could not be logged or stringified.");
|
|
353346
|
+
}
|
|
353347
|
+
}
|
|
353348
|
+
}
|
|
353349
|
+
}
|
|
353350
|
+
}
|
|
353351
|
+
|
|
353352
|
+
// packages/core/dist/src/utils/delay.js
|
|
353353
|
+
function createAbortError() {
|
|
353354
|
+
const abortError = new Error("Aborted");
|
|
353355
|
+
abortError.name = "AbortError";
|
|
353356
|
+
return abortError;
|
|
353357
|
+
}
|
|
353358
|
+
function delay2(ms, signal) {
|
|
353359
|
+
if (!signal) {
|
|
353360
|
+
return new Promise((resolve14) => setTimeout(resolve14, ms));
|
|
353361
|
+
}
|
|
353362
|
+
if (signal.aborted) {
|
|
353363
|
+
return Promise.reject(createAbortError());
|
|
353364
|
+
}
|
|
353365
|
+
return new Promise((resolve14, reject) => {
|
|
353366
|
+
const onAbort = () => {
|
|
353367
|
+
clearTimeout(timeoutId);
|
|
353368
|
+
signal.removeEventListener("abort", onAbort);
|
|
353369
|
+
reject(createAbortError());
|
|
353370
|
+
};
|
|
353371
|
+
const timeoutId = setTimeout(() => {
|
|
353372
|
+
signal.removeEventListener("abort", onAbort);
|
|
353373
|
+
resolve14();
|
|
353374
|
+
}, ms);
|
|
353375
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
353376
|
+
});
|
|
353377
|
+
}
|
|
353378
|
+
|
|
353212
353379
|
// packages/core/dist/src/utils/retry.js
|
|
353213
353380
|
var DEFAULT_RETRY_OPTIONS = {
|
|
353214
353381
|
maxAttempts: 3,
|
|
@@ -353305,14 +353472,9 @@ async function retryWithBackoff(fn, options2) {
|
|
|
353305
353472
|
throw error2;
|
|
353306
353473
|
}
|
|
353307
353474
|
const classifiedError = classifyGoogleError(error2);
|
|
353308
|
-
const failureKind = classifyFailureKind(classifiedError);
|
|
353309
|
-
const appliedImmediate = failureKind === "terminal" || failureKind === "not_found";
|
|
353310
|
-
if (appliedImmediate) {
|
|
353311
|
-
applyAvailabilityTransition(getAvailabilityContext, failureKind);
|
|
353312
|
-
}
|
|
353313
353475
|
const errorCode = getErrorStatus(error2);
|
|
353314
353476
|
if (classifiedError instanceof TerminalQuotaError || classifiedError instanceof ModelNotFoundError) {
|
|
353315
|
-
if (onPersistent429
|
|
353477
|
+
if (onPersistent429) {
|
|
353316
353478
|
try {
|
|
353317
353479
|
const fallbackModel = await onPersistent429(authType, classifiedError);
|
|
353318
353480
|
if (fallbackModel) {
|
|
@@ -353329,7 +353491,7 @@ async function retryWithBackoff(fn, options2) {
|
|
|
353329
353491
|
const is500 = errorCode !== void 0 && errorCode >= 500 && errorCode < 600;
|
|
353330
353492
|
if (classifiedError instanceof RetryableQuotaError || is500) {
|
|
353331
353493
|
if (attempt >= maxAttempts) {
|
|
353332
|
-
if (onPersistent429
|
|
353494
|
+
if (onPersistent429) {
|
|
353333
353495
|
try {
|
|
353334
353496
|
const fallbackModel = await onPersistent429(authType, classifiedError);
|
|
353335
353497
|
if (fallbackModel) {
|
|
@@ -353341,9 +353503,6 @@ async function retryWithBackoff(fn, options2) {
|
|
|
353341
353503
|
console.warn("Model fallback failed:", fallbackError);
|
|
353342
353504
|
}
|
|
353343
353505
|
}
|
|
353344
|
-
if (!appliedImmediate) {
|
|
353345
|
-
applyAvailabilityTransition(getAvailabilityContext, failureKind);
|
|
353346
|
-
}
|
|
353347
353506
|
throw classifiedError instanceof RetryableQuotaError ? classifiedError : error2;
|
|
353348
353507
|
}
|
|
353349
353508
|
if (classifiedError instanceof RetryableQuotaError) {
|
|
@@ -353361,9 +353520,6 @@ async function retryWithBackoff(fn, options2) {
|
|
|
353361
353520
|
}
|
|
353362
353521
|
}
|
|
353363
353522
|
if (attempt >= maxAttempts || !shouldRetryOnError(error2, retryFetchErrors)) {
|
|
353364
|
-
if (!appliedImmediate) {
|
|
353365
|
-
applyAvailabilityTransition(getAvailabilityContext, failureKind);
|
|
353366
|
-
}
|
|
353367
353523
|
throw error2;
|
|
353368
353524
|
}
|
|
353369
353525
|
const errorStatus = getErrorStatus(error2);
|
|
@@ -353403,9 +353559,11 @@ var DEFAULT_MAX_ATTEMPTS = 5;
|
|
|
353403
353559
|
var BaseLlmClient = class {
|
|
353404
353560
|
contentGenerator;
|
|
353405
353561
|
config;
|
|
353406
|
-
|
|
353562
|
+
authType;
|
|
353563
|
+
constructor(contentGenerator, config3, authType) {
|
|
353407
353564
|
this.contentGenerator = contentGenerator;
|
|
353408
353565
|
this.config = config3;
|
|
353566
|
+
this.authType = authType;
|
|
353409
353567
|
}
|
|
353410
353568
|
async generateJson(options2) {
|
|
353411
353569
|
const { schema, modelConfigKey, contents, systemInstruction, abortSignal, promptId, maxAttempts } = options2;
|
|
@@ -353515,7 +353673,9 @@ var BaseLlmClient = class {
|
|
|
353515
353673
|
return await retryWithBackoff(apiCall, {
|
|
353516
353674
|
shouldRetryOnContent,
|
|
353517
353675
|
maxAttempts: availabilityMaxAttempts ?? maxAttempts ?? DEFAULT_MAX_ATTEMPTS,
|
|
353518
|
-
getAvailabilityContext
|
|
353676
|
+
getAvailabilityContext,
|
|
353677
|
+
onPersistent429: this.config.isInteractive() ? (authType, error2) => handleFallback(this.config, requestParams.model, authType, error2) : void 0,
|
|
353678
|
+
authType: this.authType ?? this.config.getContentGeneratorConfig()?.authType
|
|
353519
353679
|
});
|
|
353520
353680
|
} catch (error2) {
|
|
353521
353681
|
if (abortSignal?.aborted) {
|
|
@@ -360572,7 +360732,7 @@ var WriteFileTool = class _WriteFileTool extends BaseDeclarativeTool {
|
|
|
360572
360732
|
|
|
360573
360733
|
// packages/core/dist/src/utils/fetch.js
|
|
360574
360734
|
var import_undici2 = __toESM(require_undici(), 1);
|
|
360575
|
-
import { URL as
|
|
360735
|
+
import { URL as URL7 } from "node:url";
|
|
360576
360736
|
var PRIVATE_IP_RANGES = [
|
|
360577
360737
|
/^10\./,
|
|
360578
360738
|
/^127\./,
|
|
@@ -360592,7 +360752,7 @@ var FetchError2 = class extends Error {
|
|
|
360592
360752
|
};
|
|
360593
360753
|
function isPrivateIp(url5) {
|
|
360594
360754
|
try {
|
|
360595
|
-
const hostname3 = new
|
|
360755
|
+
const hostname3 = new URL7(url5).hostname;
|
|
360596
360756
|
return PRIVATE_IP_RANGES.some((range2) => range2.test(hostname3));
|
|
360597
360757
|
} catch (_e) {
|
|
360598
360758
|
return false;
|
|
@@ -367831,225 +367991,6 @@ var ChatRecordingService = class {
|
|
|
367831
367991
|
}
|
|
367832
367992
|
};
|
|
367833
367993
|
|
|
367834
|
-
// packages/core/dist/src/utils/secure-browser-launcher.js
|
|
367835
|
-
import { execFile as execFile6 } from "node:child_process";
|
|
367836
|
-
import { promisify as promisify13 } from "node:util";
|
|
367837
|
-
import { platform as platform10 } from "node:os";
|
|
367838
|
-
import { URL as URL7 } from "node:url";
|
|
367839
|
-
var execFileAsync5 = promisify13(execFile6);
|
|
367840
|
-
function validateUrl(url5) {
|
|
367841
|
-
let parsedUrl;
|
|
367842
|
-
try {
|
|
367843
|
-
parsedUrl = new URL7(url5);
|
|
367844
|
-
} catch (_error) {
|
|
367845
|
-
throw new Error(`Invalid URL: ${url5}`);
|
|
367846
|
-
}
|
|
367847
|
-
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
|
367848
|
-
throw new Error(`Unsafe protocol: ${parsedUrl.protocol}. Only HTTP and HTTPS are allowed.`);
|
|
367849
|
-
}
|
|
367850
|
-
if (/[\r\n\x00-\x1f]/.test(url5)) {
|
|
367851
|
-
throw new Error("URL contains invalid characters");
|
|
367852
|
-
}
|
|
367853
|
-
}
|
|
367854
|
-
async function openBrowserSecurely(url5) {
|
|
367855
|
-
validateUrl(url5);
|
|
367856
|
-
const platformName = platform10();
|
|
367857
|
-
let command;
|
|
367858
|
-
let args2;
|
|
367859
|
-
switch (platformName) {
|
|
367860
|
-
case "darwin":
|
|
367861
|
-
command = "open";
|
|
367862
|
-
args2 = [url5];
|
|
367863
|
-
break;
|
|
367864
|
-
case "win32":
|
|
367865
|
-
command = "powershell.exe";
|
|
367866
|
-
args2 = [
|
|
367867
|
-
"-NoProfile",
|
|
367868
|
-
"-NonInteractive",
|
|
367869
|
-
"-WindowStyle",
|
|
367870
|
-
"Hidden",
|
|
367871
|
-
"-Command",
|
|
367872
|
-
`Start-Process '${url5.replace(/'/g, "''")}'`
|
|
367873
|
-
];
|
|
367874
|
-
break;
|
|
367875
|
-
case "linux":
|
|
367876
|
-
case "freebsd":
|
|
367877
|
-
case "openbsd":
|
|
367878
|
-
command = "xdg-open";
|
|
367879
|
-
args2 = [url5];
|
|
367880
|
-
break;
|
|
367881
|
-
default:
|
|
367882
|
-
throw new Error(`Unsupported platform: ${platformName}`);
|
|
367883
|
-
}
|
|
367884
|
-
const options2 = {
|
|
367885
|
-
// Don't inherit parent's environment to avoid potential issues
|
|
367886
|
-
env: {
|
|
367887
|
-
...process.env,
|
|
367888
|
-
// Ensure we're not in a shell that might interpret special characters
|
|
367889
|
-
SHELL: void 0
|
|
367890
|
-
},
|
|
367891
|
-
// Detach the browser process so it doesn't block
|
|
367892
|
-
detached: true,
|
|
367893
|
-
stdio: "ignore"
|
|
367894
|
-
};
|
|
367895
|
-
try {
|
|
367896
|
-
await execFileAsync5(command, args2, options2);
|
|
367897
|
-
} catch (error2) {
|
|
367898
|
-
if ((platformName === "linux" || platformName === "freebsd" || platformName === "openbsd") && command === "xdg-open") {
|
|
367899
|
-
const fallbackCommands = [
|
|
367900
|
-
"gnome-open",
|
|
367901
|
-
"kde-open",
|
|
367902
|
-
"firefox",
|
|
367903
|
-
"chromium",
|
|
367904
|
-
"google-chrome"
|
|
367905
|
-
];
|
|
367906
|
-
for (const fallbackCommand of fallbackCommands) {
|
|
367907
|
-
try {
|
|
367908
|
-
await execFileAsync5(fallbackCommand, [url5], options2);
|
|
367909
|
-
return;
|
|
367910
|
-
} catch {
|
|
367911
|
-
continue;
|
|
367912
|
-
}
|
|
367913
|
-
}
|
|
367914
|
-
}
|
|
367915
|
-
throw new Error(`Failed to open browser: ${error2 instanceof Error ? error2.message : "Unknown error"}`);
|
|
367916
|
-
}
|
|
367917
|
-
}
|
|
367918
|
-
|
|
367919
|
-
// packages/core/dist/src/fallback/handler.js
|
|
367920
|
-
init_events();
|
|
367921
|
-
var UPGRADE_URL_PAGE = "https://goo.gle/set-up-gemini-code-assist";
|
|
367922
|
-
async function handleFallback(config3, failedModel, authType, error2) {
|
|
367923
|
-
if (config3.isModelAvailabilityServiceEnabled()) {
|
|
367924
|
-
return handlePolicyDrivenFallback(config3, failedModel, authType, error2);
|
|
367925
|
-
}
|
|
367926
|
-
return legacyHandleFallback(config3, failedModel, authType, error2);
|
|
367927
|
-
}
|
|
367928
|
-
async function legacyHandleFallback(config3, failedModel, authType, error2) {
|
|
367929
|
-
if (authType !== AuthType2.LOGIN_WITH_GOOGLE)
|
|
367930
|
-
return null;
|
|
367931
|
-
if (error2 instanceof ModelNotFoundError && failedModel !== PREVIEW_GEMINI_MODEL) {
|
|
367932
|
-
return null;
|
|
367933
|
-
}
|
|
367934
|
-
const shouldActivatePreviewFallback = failedModel === PREVIEW_GEMINI_MODEL && !(error2 instanceof TerminalQuotaError);
|
|
367935
|
-
if (shouldActivatePreviewFallback) {
|
|
367936
|
-
config3.setPreviewModelBypassMode(true);
|
|
367937
|
-
if (config3.isPreviewModelFallbackMode()) {
|
|
367938
|
-
return true;
|
|
367939
|
-
}
|
|
367940
|
-
}
|
|
367941
|
-
const fallbackModel = shouldActivatePreviewFallback ? DEFAULT_GEMINI_MODEL : DEFAULT_GEMINI_FLASH_MODEL;
|
|
367942
|
-
const fallbackModelHandler = config3.fallbackModelHandler;
|
|
367943
|
-
if (typeof fallbackModelHandler !== "function")
|
|
367944
|
-
return null;
|
|
367945
|
-
try {
|
|
367946
|
-
const intent = await fallbackModelHandler(failedModel, fallbackModel, error2);
|
|
367947
|
-
return await processIntent(config3, intent, failedModel, fallbackModel, authType, error2);
|
|
367948
|
-
} catch (handlerError) {
|
|
367949
|
-
console.error("Fallback UI handler failed:", handlerError);
|
|
367950
|
-
return null;
|
|
367951
|
-
}
|
|
367952
|
-
}
|
|
367953
|
-
async function handlePolicyDrivenFallback(config3, failedModel, authType, error2) {
|
|
367954
|
-
if (authType !== AuthType2.LOGIN_WITH_GOOGLE) {
|
|
367955
|
-
return null;
|
|
367956
|
-
}
|
|
367957
|
-
const chain2 = resolvePolicyChain(config3);
|
|
367958
|
-
const { failedPolicy, candidates } = buildFallbackPolicyContext(chain2, failedModel);
|
|
367959
|
-
const failureKind = classifyFailureKind(error2);
|
|
367960
|
-
if (!candidates.length) {
|
|
367961
|
-
return null;
|
|
367962
|
-
}
|
|
367963
|
-
const availability = config3.getModelAvailabilityService();
|
|
367964
|
-
const selection = availability.selectFirstAvailable(candidates.map((policy) => policy.model));
|
|
367965
|
-
const lastResortPolicy = candidates.find((policy) => policy.isLastResort);
|
|
367966
|
-
const fallbackModel = selection.selectedModel ?? lastResortPolicy?.model;
|
|
367967
|
-
const selectedPolicy = candidates.find((policy) => policy.model === fallbackModel);
|
|
367968
|
-
if (!fallbackModel || fallbackModel === failedModel || !selectedPolicy) {
|
|
367969
|
-
return null;
|
|
367970
|
-
}
|
|
367971
|
-
const action = resolvePolicyAction(failureKind, selectedPolicy);
|
|
367972
|
-
if (action === "silent") {
|
|
367973
|
-
return processIntent(config3, "retry_always", failedModel, fallbackModel, authType, error2);
|
|
367974
|
-
}
|
|
367975
|
-
const recommendation = {
|
|
367976
|
-
...selection,
|
|
367977
|
-
selectedModel: fallbackModel,
|
|
367978
|
-
action,
|
|
367979
|
-
failureKind,
|
|
367980
|
-
failedPolicy,
|
|
367981
|
-
selectedPolicy
|
|
367982
|
-
};
|
|
367983
|
-
void recommendation;
|
|
367984
|
-
const handler = config3.getFallbackModelHandler();
|
|
367985
|
-
if (typeof handler !== "function") {
|
|
367986
|
-
return null;
|
|
367987
|
-
}
|
|
367988
|
-
try {
|
|
367989
|
-
const intent = await handler(failedModel, fallbackModel, error2);
|
|
367990
|
-
return await processIntent(config3, intent, failedModel, fallbackModel, authType, error2);
|
|
367991
|
-
} catch (handlerError) {
|
|
367992
|
-
debugLogger.error("Fallback handler failed:", handlerError);
|
|
367993
|
-
return null;
|
|
367994
|
-
}
|
|
367995
|
-
}
|
|
367996
|
-
async function handleUpgrade() {
|
|
367997
|
-
try {
|
|
367998
|
-
await openBrowserSecurely(UPGRADE_URL_PAGE);
|
|
367999
|
-
} catch (error2) {
|
|
368000
|
-
debugLogger.warn("Failed to open browser automatically:", getErrorMessage(error2));
|
|
368001
|
-
}
|
|
368002
|
-
}
|
|
368003
|
-
async function processIntent(config3, intent, failedModel, fallbackModel, authType, error2) {
|
|
368004
|
-
const isAvailabilityEnabled = config3.isModelAvailabilityServiceEnabled();
|
|
368005
|
-
switch (intent) {
|
|
368006
|
-
case "retry_always":
|
|
368007
|
-
if (isAvailabilityEnabled) {
|
|
368008
|
-
config3.setActiveModel(fallbackModel);
|
|
368009
|
-
} else {
|
|
368010
|
-
if (failedModel === PREVIEW_GEMINI_MODEL && !(error2 instanceof TerminalQuotaError)) {
|
|
368011
|
-
activatePreviewModelFallbackMode(config3);
|
|
368012
|
-
} else {
|
|
368013
|
-
activateFallbackMode(config3, authType);
|
|
368014
|
-
}
|
|
368015
|
-
}
|
|
368016
|
-
return true;
|
|
368017
|
-
case "retry_once":
|
|
368018
|
-
if (isAvailabilityEnabled) {
|
|
368019
|
-
config3.setActiveModel(fallbackModel);
|
|
368020
|
-
}
|
|
368021
|
-
return true;
|
|
368022
|
-
case "stop":
|
|
368023
|
-
if (isAvailabilityEnabled) {
|
|
368024
|
-
config3.setActiveModel(fallbackModel);
|
|
368025
|
-
} else {
|
|
368026
|
-
activateFallbackMode(config3, authType);
|
|
368027
|
-
}
|
|
368028
|
-
return false;
|
|
368029
|
-
case "retry_later":
|
|
368030
|
-
return false;
|
|
368031
|
-
case "upgrade":
|
|
368032
|
-
await handleUpgrade();
|
|
368033
|
-
return false;
|
|
368034
|
-
default:
|
|
368035
|
-
throw new Error(`Unexpected fallback intent received from fallbackModelHandler: "${intent}"`);
|
|
368036
|
-
}
|
|
368037
|
-
}
|
|
368038
|
-
function activateFallbackMode(config3, authType) {
|
|
368039
|
-
if (!config3.isInFallbackMode()) {
|
|
368040
|
-
config3.setFallbackMode(true);
|
|
368041
|
-
coreEvents.emitFallbackModeChanged(true);
|
|
368042
|
-
if (authType) {
|
|
368043
|
-
logFlashFallback(config3, new FlashFallbackEvent(authType));
|
|
368044
|
-
}
|
|
368045
|
-
}
|
|
368046
|
-
}
|
|
368047
|
-
function activatePreviewModelFallbackMode(config3) {
|
|
368048
|
-
if (!config3.isPreviewModelFallbackMode()) {
|
|
368049
|
-
config3.setPreviewModelFallbackMode(true);
|
|
368050
|
-
}
|
|
368051
|
-
}
|
|
368052
|
-
|
|
368053
367994
|
// packages/core/dist/src/core/geminiRequest.js
|
|
368054
367995
|
function partListUnionToString(value) {
|
|
368055
367996
|
return partToString(value, { verbose: true });
|
|
@@ -368343,7 +368284,7 @@ var GeminiChat = class {
|
|
|
368343
368284
|
try {
|
|
368344
368285
|
let lastError = new Error("Request failed after all retries.");
|
|
368345
368286
|
let maxAttempts = INVALID_CONTENT_RETRY_OPTIONS.maxAttempts;
|
|
368346
|
-
if (this.config.isPreviewModelFallbackMode() && model
|
|
368287
|
+
if (this.config.isPreviewModelFallbackMode() && isPreviewModel(model)) {
|
|
368347
368288
|
maxAttempts = 1;
|
|
368348
368289
|
}
|
|
368349
368290
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
@@ -368388,7 +368329,7 @@ var GeminiChat = class {
|
|
|
368388
368329
|
}
|
|
368389
368330
|
throw lastError;
|
|
368390
368331
|
} else {
|
|
368391
|
-
if (model
|
|
368332
|
+
if (isPreviewModel(model) && !this.config.isPreviewModelBypassMode()) {
|
|
368392
368333
|
this.config.setPreviewModelFallbackMode(false);
|
|
368393
368334
|
}
|
|
368394
368335
|
}
|
|
@@ -368413,10 +368354,11 @@ var GeminiChat = class {
|
|
|
368413
368354
|
let lastConfig = currentGenerateContentConfig;
|
|
368414
368355
|
let lastContentsToUse = requestContents;
|
|
368415
368356
|
const getAvailabilityContext = createAvailabilityContextProvider(this.config, () => lastModelToUse);
|
|
368357
|
+
const initialActiveModel = this.config.getActiveModel();
|
|
368416
368358
|
const apiCall = async () => {
|
|
368417
|
-
let modelToUse;
|
|
368418
|
-
if (this.config.
|
|
368419
|
-
modelToUse = this.config.getActiveModel();
|
|
368359
|
+
let modelToUse = resolveModel(lastModelToUse, this.config.getPreviewFeatures());
|
|
368360
|
+
if (this.config.getActiveModel() !== initialActiveModel) {
|
|
368361
|
+
modelToUse = resolveModel(this.config.getActiveModel(), this.config.getPreviewFeatures());
|
|
368420
368362
|
if (modelToUse !== lastModelToUse) {
|
|
368421
368363
|
const { generateContentConfig: newConfig } = this.config.modelConfigService.getResolvedConfig({
|
|
368422
368364
|
model: modelToUse
|
|
@@ -368429,11 +368371,6 @@ var GeminiChat = class {
|
|
|
368429
368371
|
currentGenerateContentConfig.abortSignal = abortSignal;
|
|
368430
368372
|
}
|
|
368431
368373
|
}
|
|
368432
|
-
} else {
|
|
368433
|
-
modelToUse = getEffectiveModel(this.config.isInFallbackMode(), model, this.config.getPreviewFeatures());
|
|
368434
|
-
if (this.config.isPreviewModelBypassMode() && modelToUse === PREVIEW_GEMINI_MODEL) {
|
|
368435
|
-
modelToUse = DEFAULT_GEMINI_MODEL;
|
|
368436
|
-
}
|
|
368437
368374
|
}
|
|
368438
368375
|
lastModelToUse = modelToUse;
|
|
368439
368376
|
const config3 = {
|
|
@@ -368456,7 +368393,7 @@ var GeminiChat = class {
|
|
|
368456
368393
|
};
|
|
368457
368394
|
delete config3.thinkingConfig?.thinkingLevel;
|
|
368458
368395
|
}
|
|
368459
|
-
let contentsToUse = modelToUse
|
|
368396
|
+
let contentsToUse = isPreviewModel(modelToUse) ? contentsForPreviewModel : requestContents;
|
|
368460
368397
|
const hooksEnabled = this.config.getEnableHooks();
|
|
368461
368398
|
const messageBus = this.config.getMessageBus();
|
|
368462
368399
|
if (hooksEnabled && messageBus) {
|
|
@@ -368508,7 +368445,7 @@ var GeminiChat = class {
|
|
|
368508
368445
|
authType: this.config.getContentGeneratorConfig()?.authType,
|
|
368509
368446
|
retryFetchErrors: this.config.getRetryFetchErrors(),
|
|
368510
368447
|
signal: generateContentConfig.abortSignal,
|
|
368511
|
-
maxAttempts: availabilityMaxAttempts ?? (this.config.isPreviewModelFallbackMode() && model
|
|
368448
|
+
maxAttempts: availabilityMaxAttempts ?? (this.config.isPreviewModelFallbackMode() && isPreviewModel(model) ? 1 : void 0),
|
|
368512
368449
|
getAvailabilityContext
|
|
368513
368450
|
});
|
|
368514
368451
|
const originalRequest = {
|
|
@@ -369274,8 +369211,8 @@ function getCoreSystemPrompt(config3, userMemory) {
|
|
|
369274
369211
|
throw new Error(`missing system prompt file '${systemMdPath}'`);
|
|
369275
369212
|
}
|
|
369276
369213
|
}
|
|
369277
|
-
const desiredModel =
|
|
369278
|
-
const isGemini3 = desiredModel
|
|
369214
|
+
const desiredModel = resolveModel(config3.getActiveModel(), config3.getPreviewFeatures());
|
|
369215
|
+
const isGemini3 = isPreviewModel(desiredModel);
|
|
369279
369216
|
const mandatesVariant = isGemini3 ? `
|
|
369280
369217
|
- **Do not call tools in silence:** You must provide to the user very short and concise natural explanation (one sentence) before calling tools.` : ``;
|
|
369281
369218
|
const enableCodebaseInvestigator = config3.getToolRegistry().getAllToolNames().includes(CodebaseInvestigatorAgent.name);
|
|
@@ -369305,7 +369242,7 @@ function getCoreSystemPrompt(config3, userMemory) {
|
|
|
369305
369242
|
|
|
369306
369243
|
## Software Engineering Tasks
|
|
369307
369244
|
When requested to perform tasks like fixing bugs, adding features, refactoring, or explaining code, follow this sequence:
|
|
369308
|
-
1. **Understand:** Think about the user's request and the relevant codebase context. Use '${GREP_TOOL_NAME}' and '${GLOB_TOOL_NAME}' search tools extensively (in parallel if independent) to understand file structures, existing code patterns, and conventions.
|
|
369245
|
+
1. **Understand:** Think about the user's request and the relevant codebase context. Use '${GREP_TOOL_NAME}' and '${GLOB_TOOL_NAME}' search tools extensively (in parallel if independent) to understand file structures, existing code patterns, and conventions.
|
|
369309
369246
|
Use '${READ_FILE_TOOL_NAME}' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to '${READ_FILE_TOOL_NAME}'.
|
|
369310
369247
|
2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution.`,
|
|
369311
369248
|
primaryWorkflows_prefix_ci: `
|
|
@@ -369329,8 +369266,7 @@ When requested to perform tasks like fixing bugs, adding features, refactoring,
|
|
|
369329
369266
|
When requested to perform tasks like fixing bugs, adding features, refactoring, or explaining code, follow this sequence:
|
|
369330
369267
|
1. **Understand:** Think about the user's request and the relevant codebase context. Use '${GREP_TOOL_NAME}' and '${GLOB_TOOL_NAME}' search tools extensively (in parallel if independent) to understand file structures, existing code patterns, and conventions. Use '${READ_FILE_TOOL_NAME}' to understand context and validate any assumptions you may have. If you need to read multiple files, you should make multiple parallel calls to '${READ_FILE_TOOL_NAME}'.
|
|
369331
369268
|
2. **Plan:** Build a coherent and grounded (based on the understanding in step 1) plan for how you intend to resolve the user's task. For complex tasks, break them down into smaller, manageable subtasks and use the \`${WRITE_TODOS_TOOL_NAME}\` tool to track your progress. Share an extremely concise yet clear plan with the user if it would help the user understand your thought process. As part of the plan, you should use an iterative development process that includes writing unit tests to verify your changes. Use output logs or debug statements as part of this process to arrive at a solution.`,
|
|
369332
|
-
primaryWorkflows_suffix: `3. **Implement:** Use the available tools (e.g., '${EDIT_TOOL_NAME}', '${WRITE_FILE_TOOL_NAME}' '${SHELL_TOOL_NAME}' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core
|
|
369333
|
-
Mandates').
|
|
369269
|
+
primaryWorkflows_suffix: `3. **Implement:** Use the available tools (e.g., '${EDIT_TOOL_NAME}', '${WRITE_FILE_TOOL_NAME}' '${SHELL_TOOL_NAME}' ...) to act on the plan, strictly adhering to the project's established conventions (detailed under 'Core Mandates').
|
|
369334
369270
|
4. **Verify (Tests):** If applicable and feasible, verify the changes using the project's testing procedures. Identify the correct test commands and frameworks by examining 'README' files, build/package configuration (e.g., 'package.json'), or existing test execution patterns. NEVER assume standard test commands.
|
|
369335
369271
|
5. **Verify (Standards):** VERY IMPORTANT: After making code changes, execute the project-specific build, linting and type-checking commands (e.g., 'tsc', 'npm run lint', 'ruff check .') that you have identified for this project (or obtained from the user). This ensures code quality and adherence to standards.${interactiveMode ? " If unsure about these commands, you can ask the user if they'd like you to run them and if so how to." : ""}
|
|
369336
369272
|
6. **Finalize:** After all verification passes, consider the task complete. Do not remove or revert any changes or created files (like tests). Await the user's next instruction.
|
|
@@ -369522,7 +369458,7 @@ The structure MUST be as follows:
|
|
|
369522
369458
|
- Build Command: \`npm run build\`
|
|
369523
369459
|
- Testing: Tests are run with \`npm test\`. Test files must end in \`.test.ts\`.
|
|
369524
369460
|
- API Endpoint: The primary API endpoint is \`https://api.example.com/v2\`.
|
|
369525
|
-
|
|
369461
|
+
|
|
369526
369462
|
-->
|
|
369527
369463
|
</key_knowledge>
|
|
369528
369464
|
|
|
@@ -370054,6 +369990,8 @@ function modelStringToModelConfigAlias(model) {
|
|
|
370054
369990
|
switch (model) {
|
|
370055
369991
|
case PREVIEW_GEMINI_MODEL:
|
|
370056
369992
|
return "chat-compression-3-pro";
|
|
369993
|
+
case PREVIEW_GEMINI_FLASH_MODEL:
|
|
369994
|
+
return "chat-compression-3-flash";
|
|
370057
369995
|
case DEFAULT_GEMINI_MODEL:
|
|
370058
369996
|
return "chat-compression-2.5-pro";
|
|
370059
369997
|
case DEFAULT_GEMINI_FLASH_MODEL:
|
|
@@ -370448,8 +370386,7 @@ var GeminiClient = class {
|
|
|
370448
370386
|
if (this.currentSequenceModel) {
|
|
370449
370387
|
return this.currentSequenceModel;
|
|
370450
370388
|
}
|
|
370451
|
-
|
|
370452
|
-
return getEffectiveModel(this.config.isInFallbackMode(), configModel, this.config.getPreviewFeatures());
|
|
370389
|
+
return this.config.getActiveModel();
|
|
370453
370390
|
}
|
|
370454
370391
|
async *sendMessageStream(request3, signal, prompt_id, turns = MAX_TURNS, isInvalidStreamRetry = false) {
|
|
370455
370392
|
if (!isInvalidStreamRetry) {
|
|
@@ -375653,6 +375590,9 @@ var ModelAvailabilityService = class {
|
|
|
375653
375590
|
}
|
|
375654
375591
|
}
|
|
375655
375592
|
}
|
|
375593
|
+
reset() {
|
|
375594
|
+
this.health.clear();
|
|
375595
|
+
}
|
|
375656
375596
|
setState(model, nextState) {
|
|
375657
375597
|
this.health.set(model, nextState);
|
|
375658
375598
|
}
|
|
@@ -375796,25 +375736,15 @@ var ClassifierStrategy = class {
|
|
|
375796
375736
|
const routerResponse = ClassifierResponseSchema.parse(jsonResponse);
|
|
375797
375737
|
const reasoning = routerResponse.reasoning;
|
|
375798
375738
|
const latencyMs = Date.now() - startTime;
|
|
375799
|
-
|
|
375800
|
-
|
|
375801
|
-
|
|
375802
|
-
|
|
375803
|
-
|
|
375804
|
-
|
|
375805
|
-
|
|
375806
|
-
|
|
375807
|
-
|
|
375808
|
-
} else {
|
|
375809
|
-
return {
|
|
375810
|
-
model: resolveModel(GEMINI_MODEL_ALIAS_PRO, config3.getPreviewFeatures()),
|
|
375811
|
-
metadata: {
|
|
375812
|
-
source: "Classifier",
|
|
375813
|
-
reasoning,
|
|
375814
|
-
latencyMs
|
|
375815
|
-
}
|
|
375816
|
-
};
|
|
375817
|
-
}
|
|
375739
|
+
const selectedModel = resolveClassifierModel(config3.getModel(), routerResponse.model_choice, config3.getPreviewFeatures());
|
|
375740
|
+
return {
|
|
375741
|
+
model: selectedModel,
|
|
375742
|
+
metadata: {
|
|
375743
|
+
source: "Classifier",
|
|
375744
|
+
latencyMs,
|
|
375745
|
+
reasoning
|
|
375746
|
+
}
|
|
375747
|
+
};
|
|
375818
375748
|
} catch (error2) {
|
|
375819
375749
|
debugLogger.warn(`[Routing] ClassifierStrategy failed:`, error2);
|
|
375820
375750
|
return null;
|
|
@@ -375880,19 +375810,28 @@ var CompositeStrategy = class {
|
|
|
375880
375810
|
var FallbackStrategy = class {
|
|
375881
375811
|
name = "fallback";
|
|
375882
375812
|
async route(_context, config3, _baseLlmClient) {
|
|
375883
|
-
|
|
375884
|
-
if (!isInFallbackMode) {
|
|
375813
|
+
if (!config3.isModelAvailabilityServiceEnabled()) {
|
|
375885
375814
|
return null;
|
|
375886
375815
|
}
|
|
375887
|
-
const
|
|
375888
|
-
|
|
375889
|
-
|
|
375890
|
-
|
|
375891
|
-
|
|
375892
|
-
|
|
375893
|
-
|
|
375894
|
-
|
|
375895
|
-
|
|
375816
|
+
const requestedModel = config3.getModel();
|
|
375817
|
+
const resolvedModel = resolveModel(requestedModel, config3.getPreviewFeatures());
|
|
375818
|
+
const service = config3.getModelAvailabilityService();
|
|
375819
|
+
const snapshot = service.snapshot(resolvedModel);
|
|
375820
|
+
if (snapshot.available) {
|
|
375821
|
+
return null;
|
|
375822
|
+
}
|
|
375823
|
+
const selection = selectModelForAvailability(config3, requestedModel);
|
|
375824
|
+
if (selection?.selectedModel && selection.selectedModel !== requestedModel) {
|
|
375825
|
+
return {
|
|
375826
|
+
model: selection.selectedModel,
|
|
375827
|
+
metadata: {
|
|
375828
|
+
source: this.name,
|
|
375829
|
+
latencyMs: 0,
|
|
375830
|
+
reasoning: `Model ${requestedModel} is unavailable (${snapshot.reason}). Using fallback: ${selection.selectedModel}`
|
|
375831
|
+
}
|
|
375832
|
+
};
|
|
375833
|
+
}
|
|
375834
|
+
return null;
|
|
375896
375835
|
}
|
|
375897
375836
|
};
|
|
375898
375837
|
|
|
@@ -375901,10 +375840,10 @@ var OverrideStrategy = class {
|
|
|
375901
375840
|
name = "override";
|
|
375902
375841
|
async route(_context, config3, _baseLlmClient) {
|
|
375903
375842
|
const overrideModel = config3.getModel();
|
|
375904
|
-
if (overrideModel === DEFAULT_GEMINI_MODEL_AUTO)
|
|
375843
|
+
if (overrideModel === DEFAULT_GEMINI_MODEL_AUTO || overrideModel === PREVIEW_GEMINI_MODEL_AUTO)
|
|
375905
375844
|
return null;
|
|
375906
375845
|
return {
|
|
375907
|
-
model:
|
|
375846
|
+
model: getEffectiveModel(overrideModel, config3.getPreviewFeatures()),
|
|
375908
375847
|
metadata: {
|
|
375909
375848
|
source: this.name,
|
|
375910
375849
|
latencyMs: 0,
|
|
@@ -375941,11 +375880,6 @@ var ModelRouterService = class {
|
|
|
375941
375880
|
let decision;
|
|
375942
375881
|
try {
|
|
375943
375882
|
decision = await this.strategy.route(context2, this.config, this.config.getBaseLlmClient());
|
|
375944
|
-
if (decision.model === DEFAULT_GEMINI_MODEL && this.config.getPreviewFeatures() && !decision.metadata.source.includes("override")) {
|
|
375945
|
-
decision.model = PREVIEW_GEMINI_MODEL;
|
|
375946
|
-
decision.metadata.source += " (Preview Model)";
|
|
375947
|
-
decision.metadata.reasoning += " (Upgraded to Preview Model)";
|
|
375948
|
-
}
|
|
375949
375883
|
const event = new ModelRoutingEvent(
|
|
375950
375884
|
decision.model,
|
|
375951
375885
|
decision.metadata.source,
|
|
@@ -376176,6 +376110,12 @@ var DEFAULT_MODEL_CONFIGS = {
|
|
|
376176
376110
|
model: "gemini-3-pro-preview"
|
|
376177
376111
|
}
|
|
376178
376112
|
},
|
|
376113
|
+
"gemini-3-flash-preview": {
|
|
376114
|
+
extends: "chat-base-3",
|
|
376115
|
+
modelConfig: {
|
|
376116
|
+
model: "gemini-3-flash-preview"
|
|
376117
|
+
}
|
|
376118
|
+
},
|
|
376179
376119
|
"gemini-2.5-pro": {
|
|
376180
376120
|
extends: "chat-base-2.5",
|
|
376181
376121
|
modelConfig: {
|
|
@@ -376299,6 +376239,11 @@ var DEFAULT_MODEL_CONFIGS = {
|
|
|
376299
376239
|
model: "gemini-3-pro-preview"
|
|
376300
376240
|
}
|
|
376301
376241
|
},
|
|
376242
|
+
"chat-compression-3-flash": {
|
|
376243
|
+
modelConfig: {
|
|
376244
|
+
model: "gemini-3-flash-preview"
|
|
376245
|
+
}
|
|
376246
|
+
},
|
|
376302
376247
|
"chat-compression-2.5-pro": {
|
|
376303
376248
|
modelConfig: {
|
|
376304
376249
|
model: "gemini-2.5-pro"
|
|
@@ -380939,6 +380884,7 @@ var HookSystem = class {
|
|
|
380939
380884
|
};
|
|
380940
380885
|
|
|
380941
380886
|
// packages/core/dist/src/agents/registry.js
|
|
380887
|
+
init_events();
|
|
380942
380888
|
function getModelConfigAlias(definition) {
|
|
380943
380889
|
return `${definition.name}-config`;
|
|
380944
380890
|
}
|
|
@@ -380954,6 +380900,9 @@ var AgentRegistry = class {
|
|
|
380954
380900
|
*/
|
|
380955
380901
|
async initialize() {
|
|
380956
380902
|
this.loadBuiltInAgents();
|
|
380903
|
+
coreEvents.on(CoreEvent.ModelChanged, () => {
|
|
380904
|
+
this.loadBuiltInAgents();
|
|
380905
|
+
});
|
|
380957
380906
|
if (this.config.getDebugMode()) {
|
|
380958
380907
|
debugLogger.log(`[AgentRegistry] Initialized with ${this.agents.size} agents.`);
|
|
380959
380908
|
}
|
|
@@ -380961,11 +380910,18 @@ var AgentRegistry = class {
|
|
|
380961
380910
|
loadBuiltInAgents() {
|
|
380962
380911
|
const investigatorSettings = this.config.getCodebaseInvestigatorSettings();
|
|
380963
380912
|
if (investigatorSettings?.enabled) {
|
|
380913
|
+
let model;
|
|
380914
|
+
const settingsModel = investigatorSettings.model;
|
|
380915
|
+
if (settingsModel && settingsModel !== GEMINI_MODEL_ALIAS_AUTO) {
|
|
380916
|
+
model = settingsModel;
|
|
380917
|
+
} else {
|
|
380918
|
+
model = isPreviewModel(this.config.getModel()) ? PREVIEW_GEMINI_FLASH_MODEL : DEFAULT_GEMINI_MODEL;
|
|
380919
|
+
}
|
|
380964
380920
|
const agentDef = {
|
|
380965
380921
|
...CodebaseInvestigatorAgent,
|
|
380966
380922
|
modelConfig: {
|
|
380967
380923
|
...CodebaseInvestigatorAgent.modelConfig,
|
|
380968
|
-
model
|
|
380924
|
+
model,
|
|
380969
380925
|
thinkingBudget: investigatorSettings.thinkingBudget ?? CodebaseInvestigatorAgent.modelConfig.thinkingBudget
|
|
380970
380926
|
},
|
|
380971
380927
|
runConfig: {
|
|
@@ -382142,7 +382098,7 @@ async function getClientMetadata() {
|
|
|
382142
382098
|
clientMetadataPromise = (async () => ({
|
|
382143
382099
|
ideName: "IDE_UNSPECIFIED",
|
|
382144
382100
|
pluginType: "GEMINI",
|
|
382145
|
-
ideVersion: "0.21.
|
|
382101
|
+
ideVersion: "0.21.1",
|
|
382146
382102
|
platform: getPlatform(),
|
|
382147
382103
|
updateChannel: await getReleaseChannel(__dirname5)
|
|
382148
382104
|
}))();
|
|
@@ -385212,6 +385168,7 @@ var Config = class {
|
|
|
385212
385168
|
bugCommand;
|
|
385213
385169
|
model;
|
|
385214
385170
|
previewFeatures;
|
|
385171
|
+
hasAccessToPreviewModel = false;
|
|
385215
385172
|
noBrowser;
|
|
385216
385173
|
folderTrust;
|
|
385217
385174
|
ideMode;
|
|
@@ -385325,7 +385282,7 @@ var Config = class {
|
|
|
385325
385282
|
this.bugCommand = params.bugCommand;
|
|
385326
385283
|
this.model = params.model;
|
|
385327
385284
|
this._activeModel = params.model;
|
|
385328
|
-
this.enableModelAvailabilityService =
|
|
385285
|
+
this.enableModelAvailabilityService = true;
|
|
385329
385286
|
this.enableAgents = params.enableAgents ?? false;
|
|
385330
385287
|
this.experimentalJitContext = params.experimentalJitContext ?? false;
|
|
385331
385288
|
this.modelAvailabilityService = new ModelAvailabilityService();
|
|
@@ -385361,7 +385318,7 @@ var Config = class {
|
|
|
385361
385318
|
this.truncateToolOutputLines = params.truncateToolOutputLines ?? DEFAULT_TRUNCATE_TOOL_OUTPUT_LINES;
|
|
385362
385319
|
this.enableToolOutputTruncation = params.enableToolOutputTruncation ?? true;
|
|
385363
385320
|
this.useSmartEdit = params.useSmartEdit ?? true;
|
|
385364
|
-
this.useWriteTodos = params.useWriteTodos ?? true;
|
|
385321
|
+
this.useWriteTodos = isPreviewModel(this.model) ? false : params.useWriteTodos ?? true;
|
|
385365
385322
|
this.enableHooks = params.enableHooks ?? false;
|
|
385366
385323
|
this.disabledHooks = (params.hooks && "disabled" in params.hooks ? params.hooks.disabled : void 0) ?? [];
|
|
385367
385324
|
const hasHooks = params.hooks && Object.keys(params.hooks).length > 0;
|
|
@@ -385372,7 +385329,7 @@ var Config = class {
|
|
|
385372
385329
|
maxNumTurns: params.codebaseInvestigatorSettings?.maxNumTurns ?? 10,
|
|
385373
385330
|
maxTimeMinutes: params.codebaseInvestigatorSettings?.maxTimeMinutes ?? 3,
|
|
385374
385331
|
thinkingBudget: params.codebaseInvestigatorSettings?.thinkingBudget ?? DEFAULT_THINKING_MODE,
|
|
385375
|
-
model: params.codebaseInvestigatorSettings?.model
|
|
385332
|
+
model: params.codebaseInvestigatorSettings?.model
|
|
385376
385333
|
};
|
|
385377
385334
|
this.continueOnFailedApiCall = params.continueOnFailedApiCall ?? true;
|
|
385378
385335
|
this.enableShellOutputEfficiency = params.enableShellOutputEfficiency ?? true;
|
|
@@ -385458,9 +385415,11 @@ var Config = class {
|
|
|
385458
385415
|
return this.contentGenerator;
|
|
385459
385416
|
}
|
|
385460
385417
|
async refreshAuth(authMethod) {
|
|
385418
|
+
this.modelAvailabilityService.reset();
|
|
385461
385419
|
if (this.contentGeneratorConfig?.authType === AuthType2.USE_GEMINI && authMethod !== AuthType2.USE_GEMINI) {
|
|
385462
385420
|
this.geminiClient.stripThoughtsFromHistory();
|
|
385463
385421
|
}
|
|
385422
|
+
this.modelAvailabilityService.reset();
|
|
385464
385423
|
const newContentGeneratorConfig = await createContentGeneratorConfig(this, authMethod);
|
|
385465
385424
|
this.contentGenerator = await createContentGenerator(newContentGeneratorConfig, this, this.getSessionId());
|
|
385466
385425
|
this.contentGeneratorConfig = newContentGeneratorConfig;
|
|
@@ -385468,6 +385427,9 @@ var Config = class {
|
|
|
385468
385427
|
const previewFeatures = this.getPreviewFeatures();
|
|
385469
385428
|
const codeAssistServer = getCodeAssistServer(this);
|
|
385470
385429
|
if (codeAssistServer) {
|
|
385430
|
+
if (codeAssistServer.projectId) {
|
|
385431
|
+
await this.refreshUserQuota();
|
|
385432
|
+
}
|
|
385471
385433
|
this.experimentsPromise = getExperiments(codeAssistServer).then((experiments) => {
|
|
385472
385434
|
this.setExperiments(experiments);
|
|
385473
385435
|
if (previewFeatures === void 0) {
|
|
@@ -385483,7 +385445,14 @@ var Config = class {
|
|
|
385483
385445
|
this.experiments = void 0;
|
|
385484
385446
|
this.experimentsPromise = void 0;
|
|
385485
385447
|
}
|
|
385448
|
+
const authType = this.contentGeneratorConfig.authType;
|
|
385449
|
+
if (authType === AuthType2.USE_GEMINI || authType === AuthType2.USE_VERTEX_AI) {
|
|
385450
|
+
this.setHasAccessToPreviewModel(true);
|
|
385451
|
+
}
|
|
385486
385452
|
this.inFallbackMode = false;
|
|
385453
|
+
if (!this.hasAccessToPreviewModel && isPreviewModel(this.model)) {
|
|
385454
|
+
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
|
|
385455
|
+
}
|
|
385487
385456
|
}
|
|
385488
385457
|
async getExperimentsAsync() {
|
|
385489
385458
|
if (this.experiments) {
|
|
@@ -385539,6 +385508,7 @@ var Config = class {
|
|
|
385539
385508
|
coreEvents.emitModelChanged(newModel);
|
|
385540
385509
|
}
|
|
385541
385510
|
this.setFallbackMode(false);
|
|
385511
|
+
this.modelAvailabilityService.reset();
|
|
385542
385512
|
}
|
|
385543
385513
|
getActiveModel() {
|
|
385544
385514
|
return this._activeModel ?? this.model;
|
|
@@ -385546,7 +385516,6 @@ var Config = class {
|
|
|
385546
385516
|
setActiveModel(model) {
|
|
385547
385517
|
if (this._activeModel !== model) {
|
|
385548
385518
|
this._activeModel = model;
|
|
385549
|
-
coreEvents.emitModelChanged(model);
|
|
385550
385519
|
}
|
|
385551
385520
|
}
|
|
385552
385521
|
resetTurn() {
|
|
@@ -385627,8 +385596,36 @@ var Config = class {
|
|
|
385627
385596
|
return this.previewFeatures;
|
|
385628
385597
|
}
|
|
385629
385598
|
setPreviewFeatures(previewFeatures) {
|
|
385599
|
+
if (this.previewFeatures && !previewFeatures) {
|
|
385600
|
+
if (isPreviewModel(this.getModel())) {
|
|
385601
|
+
this.setModel(DEFAULT_GEMINI_MODEL_AUTO);
|
|
385602
|
+
}
|
|
385603
|
+
}
|
|
385630
385604
|
this.previewFeatures = previewFeatures;
|
|
385631
385605
|
}
|
|
385606
|
+
getHasAccessToPreviewModel() {
|
|
385607
|
+
return this.hasAccessToPreviewModel;
|
|
385608
|
+
}
|
|
385609
|
+
setHasAccessToPreviewModel(hasAccess) {
|
|
385610
|
+
this.hasAccessToPreviewModel = hasAccess;
|
|
385611
|
+
}
|
|
385612
|
+
async refreshUserQuota() {
|
|
385613
|
+
const codeAssistServer = getCodeAssistServer(this);
|
|
385614
|
+
if (!codeAssistServer || !codeAssistServer.projectId) {
|
|
385615
|
+
return void 0;
|
|
385616
|
+
}
|
|
385617
|
+
try {
|
|
385618
|
+
const quota = await codeAssistServer.retrieveUserQuota({
|
|
385619
|
+
project: codeAssistServer.projectId
|
|
385620
|
+
});
|
|
385621
|
+
const hasAccess = quota.buckets?.some((b) => b.modelId === PREVIEW_GEMINI_MODEL) ?? false;
|
|
385622
|
+
this.setHasAccessToPreviewModel(hasAccess);
|
|
385623
|
+
return quota;
|
|
385624
|
+
} catch (e3) {
|
|
385625
|
+
debugLogger.debug("Failed to retrieve user quota", e3);
|
|
385626
|
+
return void 0;
|
|
385627
|
+
}
|
|
385628
|
+
}
|
|
385632
385629
|
getCoreTools() {
|
|
385633
385630
|
return this.coreTools;
|
|
385634
385631
|
}
|