@google/gemini-cli-a2a-server 0.31.0-preview.0 → 0.31.0-preview.2

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.
@@ -105516,6 +105516,150 @@ var init_open = __esm({
105516
105516
  }
105517
105517
  });
105518
105518
 
105519
+ // packages/core/dist/src/utils/googleErrors.js
105520
+ function parseGoogleApiError(error2) {
105521
+ if (!error2) {
105522
+ return null;
105523
+ }
105524
+ let errorObj = error2;
105525
+ if (typeof errorObj === "string") {
105526
+ try {
105527
+ errorObj = JSON.parse(errorObj);
105528
+ } catch (_) {
105529
+ return null;
105530
+ }
105531
+ }
105532
+ if (Array.isArray(errorObj) && errorObj.length > 0) {
105533
+ errorObj = errorObj[0];
105534
+ }
105535
+ if (typeof errorObj !== "object" || errorObj === null) {
105536
+ return null;
105537
+ }
105538
+ let currentError = fromGaxiosError(errorObj) ?? fromApiError(errorObj);
105539
+ let depth = 0;
105540
+ const maxDepth = 10;
105541
+ while (currentError && typeof currentError.message === "string" && depth < maxDepth) {
105542
+ try {
105543
+ const parsedMessage = JSON.parse(currentError.message.replace(/\u00A0/g, "").replace(/\n/g, " "));
105544
+ if (parsedMessage.error) {
105545
+ currentError = parsedMessage.error;
105546
+ depth++;
105547
+ } else {
105548
+ break;
105549
+ }
105550
+ } catch (_error) {
105551
+ break;
105552
+ }
105553
+ }
105554
+ if (!currentError) {
105555
+ return null;
105556
+ }
105557
+ const code2 = currentError.code;
105558
+ const message = currentError.message;
105559
+ const errorDetails = currentError.details;
105560
+ if (code2 && message) {
105561
+ const details = [];
105562
+ if (Array.isArray(errorDetails)) {
105563
+ for (const detail of errorDetails) {
105564
+ if (detail && typeof detail === "object") {
105565
+ const detailObj = detail;
105566
+ const typeKey = Object.keys(detailObj).find((key) => key.trim() === "@type");
105567
+ if (typeKey) {
105568
+ if (typeKey !== "@type") {
105569
+ detailObj["@type"] = detailObj[typeKey];
105570
+ delete detailObj[typeKey];
105571
+ }
105572
+ if (typeof detailObj["@type"] === "string") {
105573
+ details.push(detailObj);
105574
+ }
105575
+ }
105576
+ }
105577
+ }
105578
+ }
105579
+ return {
105580
+ code: code2,
105581
+ message,
105582
+ details
105583
+ };
105584
+ }
105585
+ return null;
105586
+ }
105587
+ function isErrorShape(obj) {
105588
+ return typeof obj === "object" && obj !== null && ("message" in obj && typeof obj.message === "string" || "code" in obj && typeof obj.code === "number");
105589
+ }
105590
+ function fromGaxiosError(errorObj) {
105591
+ const gaxiosError = errorObj;
105592
+ let outerError;
105593
+ if (gaxiosError.response?.data) {
105594
+ let data = gaxiosError.response.data;
105595
+ if (typeof data === "string") {
105596
+ try {
105597
+ data = JSON.parse(data);
105598
+ } catch (_) {
105599
+ }
105600
+ }
105601
+ if (Array.isArray(data) && data.length > 0) {
105602
+ data = data[0];
105603
+ }
105604
+ if (typeof data === "object" && data !== null) {
105605
+ if ("error" in data) {
105606
+ const potentialError = data.error;
105607
+ if (isErrorShape(potentialError)) {
105608
+ outerError = potentialError;
105609
+ }
105610
+ }
105611
+ }
105612
+ }
105613
+ if (!outerError) {
105614
+ if (gaxiosError.error) {
105615
+ outerError = gaxiosError.error;
105616
+ } else {
105617
+ return void 0;
105618
+ }
105619
+ }
105620
+ return outerError;
105621
+ }
105622
+ function fromApiError(errorObj) {
105623
+ const apiError = errorObj;
105624
+ let outerError;
105625
+ if (apiError.message) {
105626
+ let data = apiError.message;
105627
+ if (typeof data === "string") {
105628
+ try {
105629
+ data = JSON.parse(data);
105630
+ } catch (_) {
105631
+ if (typeof data === "string") {
105632
+ const firstBrace = data.indexOf("{");
105633
+ const lastBrace = data.lastIndexOf("}");
105634
+ if (firstBrace !== -1 && lastBrace !== -1 && lastBrace > firstBrace) {
105635
+ try {
105636
+ data = JSON.parse(data.substring(firstBrace, lastBrace + 1));
105637
+ } catch (__) {
105638
+ }
105639
+ }
105640
+ }
105641
+ }
105642
+ }
105643
+ if (Array.isArray(data) && data.length > 0) {
105644
+ data = data[0];
105645
+ }
105646
+ if (typeof data === "object" && data !== null) {
105647
+ if ("error" in data) {
105648
+ const potentialError = data.error;
105649
+ if (isErrorShape(potentialError)) {
105650
+ outerError = potentialError;
105651
+ }
105652
+ }
105653
+ }
105654
+ }
105655
+ return outerError;
105656
+ }
105657
+ var init_googleErrors = __esm({
105658
+ "packages/core/dist/src/utils/googleErrors.js"() {
105659
+ "use strict";
105660
+ }
105661
+ });
105662
+
105519
105663
  // packages/core/dist/src/utils/errors.js
105520
105664
  function isGaxiosError(error2) {
105521
105665
  return typeof error2 === "object" && error2 !== null && "response" in error2 && typeof error2.response === "object" && error2.response !== null;
@@ -105560,6 +105704,13 @@ function isResponseData(data) {
105560
105704
  return true;
105561
105705
  }
105562
105706
  function toFriendlyError(error2) {
105707
+ const googleApiError = parseGoogleApiError(error2);
105708
+ if (googleApiError && googleApiError.code === 403) {
105709
+ const tosDetail = googleApiError.details.find((d) => d["@type"] === "type.googleapis.com/google.rpc.ErrorInfo" && "reason" in d && d.reason === "TOS_VIOLATION");
105710
+ if (tosDetail) {
105711
+ return new AccountSuspendedError(googleApiError.message, tosDetail.metadata);
105712
+ }
105713
+ }
105563
105714
  if (isGaxiosError(error2)) {
105564
105715
  const data = parseResponseData(error2);
105565
105716
  if (data && data.error && data.error.message && data.error.code) {
@@ -105609,10 +105760,11 @@ function isAuthenticationError(error2) {
105609
105760
  }
105610
105761
  return false;
105611
105762
  }
105612
- var FatalError, FatalAuthenticationError, FatalCancellationError, ForbiddenError, UnauthorizedError, BadRequestError2, ChangeAuthRequestedError;
105763
+ var FatalError, FatalAuthenticationError, FatalCancellationError, ForbiddenError, AccountSuspendedError, UnauthorizedError, BadRequestError2, ChangeAuthRequestedError;
105613
105764
  var init_errors = __esm({
105614
105765
  "packages/core/dist/src/utils/errors.js"() {
105615
105766
  "use strict";
105767
+ init_googleErrors();
105616
105768
  FatalError = class extends Error {
105617
105769
  exitCode;
105618
105770
  constructor(message, exitCode) {
@@ -105632,6 +105784,16 @@ var init_errors = __esm({
105632
105784
  };
105633
105785
  ForbiddenError = class extends Error {
105634
105786
  };
105787
+ AccountSuspendedError = class extends ForbiddenError {
105788
+ appealUrl;
105789
+ appealLinkText;
105790
+ constructor(message, metadata2) {
105791
+ super(message);
105792
+ this.name = "AccountSuspendedError";
105793
+ this.appealUrl = metadata2?.["appeal_url"];
105794
+ this.appealLinkText = metadata2?.["appeal_url_link_text"];
105795
+ }
105796
+ };
105635
105797
  UnauthorizedError = class extends Error {
105636
105798
  };
105637
105799
  BadRequestError2 = class extends Error {
@@ -141950,7 +142112,7 @@ function getVersion() {
141950
142112
  }
141951
142113
  versionPromise = (async () => {
141952
142114
  const pkgJson = await getPackageJson(__dirname3);
141953
- return "0.31.0-preview.0";
142115
+ return "0.31.0-preview.2";
141954
142116
  })();
141955
142117
  return versionPromise;
141956
142118
  }
@@ -142237,150 +142399,6 @@ var init_server = __esm({
142237
142399
  }
142238
142400
  });
142239
142401
 
142240
- // packages/core/dist/src/utils/googleErrors.js
142241
- function parseGoogleApiError(error2) {
142242
- if (!error2) {
142243
- return null;
142244
- }
142245
- let errorObj = error2;
142246
- if (typeof errorObj === "string") {
142247
- try {
142248
- errorObj = JSON.parse(errorObj);
142249
- } catch (_) {
142250
- return null;
142251
- }
142252
- }
142253
- if (Array.isArray(errorObj) && errorObj.length > 0) {
142254
- errorObj = errorObj[0];
142255
- }
142256
- if (typeof errorObj !== "object" || errorObj === null) {
142257
- return null;
142258
- }
142259
- let currentError = fromGaxiosError(errorObj) ?? fromApiError(errorObj);
142260
- let depth = 0;
142261
- const maxDepth = 10;
142262
- while (currentError && typeof currentError.message === "string" && depth < maxDepth) {
142263
- try {
142264
- const parsedMessage = JSON.parse(currentError.message.replace(/\u00A0/g, "").replace(/\n/g, " "));
142265
- if (parsedMessage.error) {
142266
- currentError = parsedMessage.error;
142267
- depth++;
142268
- } else {
142269
- break;
142270
- }
142271
- } catch (_error) {
142272
- break;
142273
- }
142274
- }
142275
- if (!currentError) {
142276
- return null;
142277
- }
142278
- const code2 = currentError.code;
142279
- const message = currentError.message;
142280
- const errorDetails = currentError.details;
142281
- if (code2 && message) {
142282
- const details = [];
142283
- if (Array.isArray(errorDetails)) {
142284
- for (const detail of errorDetails) {
142285
- if (detail && typeof detail === "object") {
142286
- const detailObj = detail;
142287
- const typeKey = Object.keys(detailObj).find((key) => key.trim() === "@type");
142288
- if (typeKey) {
142289
- if (typeKey !== "@type") {
142290
- detailObj["@type"] = detailObj[typeKey];
142291
- delete detailObj[typeKey];
142292
- }
142293
- if (typeof detailObj["@type"] === "string") {
142294
- details.push(detailObj);
142295
- }
142296
- }
142297
- }
142298
- }
142299
- }
142300
- return {
142301
- code: code2,
142302
- message,
142303
- details
142304
- };
142305
- }
142306
- return null;
142307
- }
142308
- function isErrorShape(obj) {
142309
- return typeof obj === "object" && obj !== null && ("message" in obj && typeof obj.message === "string" || "code" in obj && typeof obj.code === "number");
142310
- }
142311
- function fromGaxiosError(errorObj) {
142312
- const gaxiosError = errorObj;
142313
- let outerError;
142314
- if (gaxiosError.response?.data) {
142315
- let data = gaxiosError.response.data;
142316
- if (typeof data === "string") {
142317
- try {
142318
- data = JSON.parse(data);
142319
- } catch (_) {
142320
- }
142321
- }
142322
- if (Array.isArray(data) && data.length > 0) {
142323
- data = data[0];
142324
- }
142325
- if (typeof data === "object" && data !== null) {
142326
- if ("error" in data) {
142327
- const potentialError = data.error;
142328
- if (isErrorShape(potentialError)) {
142329
- outerError = potentialError;
142330
- }
142331
- }
142332
- }
142333
- }
142334
- if (!outerError) {
142335
- if (gaxiosError.error) {
142336
- outerError = gaxiosError.error;
142337
- } else {
142338
- return void 0;
142339
- }
142340
- }
142341
- return outerError;
142342
- }
142343
- function fromApiError(errorObj) {
142344
- const apiError = errorObj;
142345
- let outerError;
142346
- if (apiError.message) {
142347
- let data = apiError.message;
142348
- if (typeof data === "string") {
142349
- try {
142350
- data = JSON.parse(data);
142351
- } catch (_) {
142352
- if (typeof data === "string") {
142353
- const firstBrace = data.indexOf("{");
142354
- const lastBrace = data.lastIndexOf("}");
142355
- if (firstBrace !== -1 && lastBrace !== -1 && lastBrace > firstBrace) {
142356
- try {
142357
- data = JSON.parse(data.substring(firstBrace, lastBrace + 1));
142358
- } catch (__) {
142359
- }
142360
- }
142361
- }
142362
- }
142363
- }
142364
- if (Array.isArray(data) && data.length > 0) {
142365
- data = data[0];
142366
- }
142367
- if (typeof data === "object" && data !== null) {
142368
- if ("error" in data) {
142369
- const potentialError = data.error;
142370
- if (isErrorShape(potentialError)) {
142371
- outerError = potentialError;
142372
- }
142373
- }
142374
- }
142375
- }
142376
- return outerError;
142377
- }
142378
- var init_googleErrors = __esm({
142379
- "packages/core/dist/src/utils/googleErrors.js"() {
142380
- "use strict";
142381
- }
142382
- });
142383
-
142384
142402
  // packages/core/dist/src/utils/httpErrors.js
142385
142403
  function getErrorStatus(error2) {
142386
142404
  if (typeof error2 === "object" && error2 !== null) {
@@ -219396,8 +219414,8 @@ var GIT_COMMIT_INFO, CLI_VERSION;
219396
219414
  var init_git_commit = __esm({
219397
219415
  "packages/core/dist/src/generated/git-commit.js"() {
219398
219416
  "use strict";
219399
- GIT_COMMIT_INFO = "bf278ef2b";
219400
- CLI_VERSION = "0.31.0-preview.0";
219417
+ GIT_COMMIT_INFO = "3e3da76cc";
219418
+ CLI_VERSION = "0.31.0-preview.2";
219401
219419
  }
219402
219420
  });
219403
219421
 
@@ -415385,11 +415403,17 @@ async function handleAutomaticOAuth(mcpServerName, mcpServerConfig, wwwAuthentic
415385
415403
  return false;
415386
415404
  }
415387
415405
  }
415388
- function createTransportRequestInit(mcpServerConfig, headers) {
415406
+ function createTransportRequestInit(mcpServerConfig, headers, sanitizationConfig) {
415407
+ const extensionEnv = getExtensionEnvironment(mcpServerConfig.extension);
415408
+ const expansionEnv = { ...process.env, ...extensionEnv };
415409
+ const sanitizedEnv = sanitizeEnvironment(expansionEnv, {
415410
+ ...sanitizationConfig,
415411
+ enableEnvironmentVariableRedaction: true
415412
+ });
415389
415413
  const expandedHeaders = {};
415390
415414
  if (mcpServerConfig.headers) {
415391
415415
  for (const [key, value] of Object.entries(mcpServerConfig.headers)) {
415392
- expandedHeaders[key] = expandEnvVars(value, process.env);
415416
+ expandedHeaders[key] = expandEnvVars(value, sanitizedEnv);
415393
415417
  }
415394
415418
  }
415395
415419
  return {
@@ -415408,13 +415432,13 @@ function createAuthProvider(mcpServerConfig) {
415408
415432
  }
415409
415433
  return void 0;
415410
415434
  }
415411
- async function createTransportWithOAuth(mcpServerName, mcpServerConfig, accessToken) {
415435
+ async function createTransportWithOAuth(mcpServerName, mcpServerConfig, accessToken, sanitizationConfig) {
415412
415436
  try {
415413
415437
  const headers = {
415414
415438
  Authorization: `Bearer ${accessToken}`
415415
415439
  };
415416
415440
  const transportOptions = {
415417
- requestInit: createTransportRequestInit(mcpServerConfig, headers)
415441
+ requestInit: createTransportRequestInit(mcpServerConfig, headers, sanitizationConfig)
415418
415442
  };
415419
415443
  return createUrlTransport(mcpServerName, mcpServerConfig, transportOptions);
415420
415444
  } catch (error2) {
@@ -415567,7 +415591,7 @@ async function showAuthRequiredMessage(serverName) {
415567
415591
  coreEvents.emitFeedback("info", message);
415568
415592
  throw new UnauthorizedError(message);
415569
415593
  }
415570
- async function retryWithOAuth(client, serverName, config3, accessToken, httpReturned404) {
415594
+ async function retryWithOAuth(client, serverName, config3, accessToken, httpReturned404, sanitizationConfig) {
415571
415595
  if (httpReturned404) {
415572
415596
  debugLogger.log(`Retrying SSE connection to '${serverName}' with OAuth token...`);
415573
415597
  await connectWithSSETransport(client, config3, accessToken);
@@ -415575,7 +415599,7 @@ async function retryWithOAuth(client, serverName, config3, accessToken, httpRetu
415575
415599
  return;
415576
415600
  }
415577
415601
  debugLogger.log(`Retrying connection to '${serverName}' with OAuth token...`);
415578
- const httpTransport = await createTransportWithOAuth(serverName, config3, accessToken);
415602
+ const httpTransport = await createTransportWithOAuth(serverName, config3, accessToken, sanitizationConfig);
415579
415603
  if (!httpTransport) {
415580
415604
  throw new Error(`Failed to create OAuth transport for server '${serverName}'`);
415581
415605
  }
@@ -415725,7 +415749,7 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
415725
415749
  if (!accessToken) {
415726
415750
  throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
415727
415751
  }
415728
- await retryWithOAuth(mcpClient, mcpServerName, mcpServerConfig, accessToken, httpReturned404);
415752
+ await retryWithOAuth(mcpClient, mcpServerName, mcpServerConfig, accessToken, httpReturned404, sanitizationConfig);
415729
415753
  return mcpClient;
415730
415754
  } else {
415731
415755
  throw new Error(`Failed to handle automatic OAuth for server '${mcpServerName}'`);
@@ -415757,7 +415781,7 @@ async function connectToMcpServer(clientVersion, mcpServerName, mcpServerConfig,
415757
415781
  if (!accessToken) {
415758
415782
  throw new Error(`Failed to get OAuth token for server '${mcpServerName}'`);
415759
415783
  }
415760
- const oauthTransport = await createTransportWithOAuth(mcpServerName, mcpServerConfig, accessToken);
415784
+ const oauthTransport = await createTransportWithOAuth(mcpServerName, mcpServerConfig, accessToken, sanitizationConfig);
415761
415785
  if (!oauthTransport) {
415762
415786
  throw new Error(`Failed to create OAuth transport for server '${mcpServerName}'`);
415763
415787
  }
@@ -415829,18 +415853,21 @@ async function createTransport(mcpServerName, mcpServerConfig, debugMode, saniti
415829
415853
  }
415830
415854
  }
415831
415855
  const transportOptions = {
415832
- requestInit: createTransportRequestInit(mcpServerConfig, headers),
415856
+ requestInit: createTransportRequestInit(mcpServerConfig, headers, sanitizationConfig),
415833
415857
  authProvider
415834
415858
  };
415835
415859
  return createUrlTransport(mcpServerName, mcpServerConfig, transportOptions);
415836
415860
  }
415837
415861
  if (mcpServerConfig.command) {
415838
- const sanitizedEnv = sanitizeEnvironment(process.env, {
415862
+ const extensionEnv = getExtensionEnvironment(mcpServerConfig.extension);
415863
+ const expansionEnv = { ...process.env, ...extensionEnv };
415864
+ const sanitizedEnv = sanitizeEnvironment(expansionEnv, {
415839
415865
  ...sanitizationConfig,
415840
415866
  enableEnvironmentVariableRedaction: true
415841
415867
  });
415842
415868
  const finalEnv = {
415843
- [GEMINI_CLI_IDENTIFICATION_ENV_VAR]: GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE
415869
+ [GEMINI_CLI_IDENTIFICATION_ENV_VAR]: GEMINI_CLI_IDENTIFICATION_ENV_VAR_VALUE,
415870
+ ...extensionEnv
415844
415871
  };
415845
415872
  for (const [key, value] of Object.entries(sanitizedEnv)) {
415846
415873
  if (value !== void 0) {
@@ -415849,7 +415876,7 @@ async function createTransport(mcpServerName, mcpServerConfig, debugMode, saniti
415849
415876
  }
415850
415877
  if (mcpServerConfig.env) {
415851
415878
  for (const [key, value] of Object.entries(mcpServerConfig.env)) {
415852
- finalEnv[key] = expandEnvVars(value, process.env);
415879
+ finalEnv[key] = expandEnvVars(value, expansionEnv);
415853
415880
  }
415854
415881
  }
415855
415882
  let transport = new StdioClientTransport({
@@ -415878,6 +415905,17 @@ async function createTransport(mcpServerName, mcpServerConfig, debugMode, saniti
415878
415905
  }
415879
415906
  throw new Error(`Invalid configuration: missing httpUrl (for Streamable HTTP), url (for SSE), and command (for stdio).`);
415880
415907
  }
415908
+ function getExtensionEnvironment(extension) {
415909
+ const env2 = {};
415910
+ if (extension?.resolvedSettings) {
415911
+ for (const setting of extension.resolvedSettings) {
415912
+ if (setting.value !== void 0) {
415913
+ env2[setting.envVar] = setting.value;
415914
+ }
415915
+ }
415916
+ }
415917
+ return env2;
415918
+ }
415881
415919
  function isEnabled(funcDecl, mcpServerName, mcpServerConfig) {
415882
415920
  if (!funcDecl.name) {
415883
415921
  debugLogger.warn(`Discovered a function declaration without a name from MCP server '${mcpServerName}'. Skipping.`);