@google/genai 2.3.0 → 2.5.0

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.
@@ -12793,7 +12793,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
12793
12793
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
12794
12794
  const USER_AGENT_HEADER = 'User-Agent';
12795
12795
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
12796
- const SDK_VERSION = '2.3.0'; // x-release-please-version
12796
+ const SDK_VERSION = '2.5.0'; // x-release-please-version
12797
12797
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
12798
12798
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
12799
12799
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -17579,7 +17579,9 @@ class APIConnectionError extends APIError {
17579
17579
  }
17580
17580
  class APIConnectionTimeoutError extends APIConnectionError {
17581
17581
  constructor({ message } = {}) {
17582
- super({ message: message !== null && message !== void 0 ? message : 'Request timed out.' });
17582
+ super({
17583
+ message: message !== null && message !== void 0 ? message : 'Request timed out. This is a client-side timeout. You can increase the timeout by setting the `timeout` argument in your request or client http options.',
17584
+ });
17583
17585
  }
17584
17586
  }
17585
17587
  class BadRequestError extends APIError {
@@ -17946,6 +17948,126 @@ class APIResource {
17946
17948
  */
17947
17949
  APIResource._key = [];
17948
17950
 
17951
+ /**
17952
+ * @license
17953
+ * Copyright 2025 Google LLC
17954
+ * SPDX-License-Identifier: Apache-2.0
17955
+ */
17956
+ /**
17957
+ * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
17958
+ *
17959
+ * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
17960
+ * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
17961
+ * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
17962
+ * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
17963
+ */
17964
+ function encodeURIPath(str) {
17965
+ return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
17966
+ }
17967
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
17968
+ const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
17969
+ // If there are no params, no processing is needed.
17970
+ if (statics.length === 1)
17971
+ return statics[0];
17972
+ let postPath = false;
17973
+ const invalidSegments = [];
17974
+ const path = statics.reduce((previousValue, currentValue, index) => {
17975
+ var _a, _b, _c;
17976
+ if (/[?#]/.test(currentValue)) {
17977
+ postPath = true;
17978
+ }
17979
+ const value = params[index];
17980
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
17981
+ if (index !== params.length &&
17982
+ (value == null ||
17983
+ (typeof value === 'object' &&
17984
+ // handle values from other realms
17985
+ value.toString ===
17986
+ ((_c = Object.getPrototypeOf((_b = Object.getPrototypeOf((_a = value.hasOwnProperty) !== null && _a !== void 0 ? _a : EMPTY)) !== null && _b !== void 0 ? _b : EMPTY)) === null || _c === void 0 ? void 0 : _c.toString)))) {
17987
+ encoded = value + '';
17988
+ invalidSegments.push({
17989
+ start: previousValue.length + currentValue.length,
17990
+ length: encoded.length,
17991
+ error: `Value of type ${Object.prototype.toString
17992
+ .call(value)
17993
+ .slice(8, -1)} is not a valid path parameter`,
17994
+ });
17995
+ }
17996
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
17997
+ }, '');
17998
+ const pathOnly = path.split(/[?#]/, 1)[0];
17999
+ const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
18000
+ let match;
18001
+ // Find all invalid segments
18002
+ while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
18003
+ const hasLeadingSlash = match[0].startsWith('/');
18004
+ const offset = hasLeadingSlash ? 1 : 0;
18005
+ const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
18006
+ invalidSegments.push({
18007
+ start: match.index + offset,
18008
+ length: cleanMatch.length,
18009
+ error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
18010
+ });
18011
+ }
18012
+ invalidSegments.sort((a, b) => a.start - b.start);
18013
+ if (invalidSegments.length > 0) {
18014
+ let lastEnd = 0;
18015
+ const underline = invalidSegments.reduce((acc, segment) => {
18016
+ const spaces = ' '.repeat(segment.start - lastEnd);
18017
+ const arrows = '^'.repeat(segment.length);
18018
+ lastEnd = segment.start + segment.length;
18019
+ return acc + spaces + arrows;
18020
+ }, '');
18021
+ throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
18022
+ .map((e) => e.error)
18023
+ .join('\n')}\n${path}\n${underline}`);
18024
+ }
18025
+ return path;
18026
+ });
18027
+ /**
18028
+ * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
18029
+ */
18030
+ const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
18031
+
18032
+ /**
18033
+ * @license
18034
+ * Copyright 2025 Google LLC
18035
+ * SPDX-License-Identifier: Apache-2.0
18036
+ */
18037
+ class BaseAgents extends APIResource {
18038
+ /**
18039
+ * Creates a new Agent (Typed version for SDK).
18040
+ */
18041
+ create(params = {}, options) {
18042
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
18043
+ return this._client.post(path `/${api_version}/agents`, Object.assign({ body }, options));
18044
+ }
18045
+ /**
18046
+ * Lists all Agents.
18047
+ */
18048
+ list(params = {}, options) {
18049
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
18050
+ return this._client.get(path `/${api_version}/agents`, Object.assign({ query }, options));
18051
+ }
18052
+ /**
18053
+ * Deletes an Agent.
18054
+ */
18055
+ delete(id, params = {}, options) {
18056
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18057
+ return this._client.delete(path `/${api_version}/agents/${id}`, options);
18058
+ }
18059
+ /**
18060
+ * Gets a specific Agent.
18061
+ */
18062
+ get(id, params = {}, options) {
18063
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18064
+ return this._client.get(path `/${api_version}/agents/${id}`, options);
18065
+ }
18066
+ }
18067
+ BaseAgents._key = Object.freeze(['agents']);
18068
+ class Agents extends BaseAgents {
18069
+ }
18070
+
17949
18071
  /**
17950
18072
  * @license
17951
18073
  * Copyright 2025 Google LLC
@@ -18607,87 +18729,6 @@ class LegacyLyriaStream extends Stream {
18607
18729
  }
18608
18730
  }
18609
18731
 
18610
- /**
18611
- * @license
18612
- * Copyright 2025 Google LLC
18613
- * SPDX-License-Identifier: Apache-2.0
18614
- */
18615
- /**
18616
- * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
18617
- *
18618
- * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
18619
- * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
18620
- * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
18621
- * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
18622
- */
18623
- function encodeURIPath(str) {
18624
- return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
18625
- }
18626
- const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
18627
- const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
18628
- // If there are no params, no processing is needed.
18629
- if (statics.length === 1)
18630
- return statics[0];
18631
- let postPath = false;
18632
- const invalidSegments = [];
18633
- const path = statics.reduce((previousValue, currentValue, index) => {
18634
- var _a, _b, _c;
18635
- if (/[?#]/.test(currentValue)) {
18636
- postPath = true;
18637
- }
18638
- const value = params[index];
18639
- let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
18640
- if (index !== params.length &&
18641
- (value == null ||
18642
- (typeof value === 'object' &&
18643
- // handle values from other realms
18644
- value.toString ===
18645
- ((_c = Object.getPrototypeOf((_b = Object.getPrototypeOf((_a = value.hasOwnProperty) !== null && _a !== void 0 ? _a : EMPTY)) !== null && _b !== void 0 ? _b : EMPTY)) === null || _c === void 0 ? void 0 : _c.toString)))) {
18646
- encoded = value + '';
18647
- invalidSegments.push({
18648
- start: previousValue.length + currentValue.length,
18649
- length: encoded.length,
18650
- error: `Value of type ${Object.prototype.toString
18651
- .call(value)
18652
- .slice(8, -1)} is not a valid path parameter`,
18653
- });
18654
- }
18655
- return previousValue + currentValue + (index === params.length ? '' : encoded);
18656
- }, '');
18657
- const pathOnly = path.split(/[?#]/, 1)[0];
18658
- const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
18659
- let match;
18660
- // Find all invalid segments
18661
- while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
18662
- const hasLeadingSlash = match[0].startsWith('/');
18663
- const offset = hasLeadingSlash ? 1 : 0;
18664
- const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
18665
- invalidSegments.push({
18666
- start: match.index + offset,
18667
- length: cleanMatch.length,
18668
- error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
18669
- });
18670
- }
18671
- invalidSegments.sort((a, b) => a.start - b.start);
18672
- if (invalidSegments.length > 0) {
18673
- let lastEnd = 0;
18674
- const underline = invalidSegments.reduce((acc, segment) => {
18675
- const spaces = ' '.repeat(segment.start - lastEnd);
18676
- const arrows = '^'.repeat(segment.length);
18677
- lastEnd = segment.start + segment.length;
18678
- return acc + spaces + arrows;
18679
- }, '');
18680
- throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
18681
- .map((e) => e.error)
18682
- .join('\n')}\n${path}\n${underline}`);
18683
- }
18684
- return path;
18685
- });
18686
- /**
18687
- * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
18688
- */
18689
- const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
18690
-
18691
18732
  /**
18692
18733
  * @license
18693
18734
  * Copyright 2025 Google LLC
@@ -18763,18 +18804,32 @@ class Interactions extends BaseInteractions {
18763
18804
  function addOutputProperties(interaction) {
18764
18805
  var _a, _b;
18765
18806
  const steps = (_a = interaction.steps) !== null && _a !== void 0 ? _a : [];
18766
- let firstTrailing = steps.length;
18767
- while (firstTrailing > 0 && steps[firstTrailing - 1].type === 'model_output') {
18768
- firstTrailing--;
18769
- }
18770
- const modelSteps = steps.slice(firstTrailing);
18771
- const output = modelSteps.flatMap((step) => { var _a; return (_a = step.content) !== null && _a !== void 0 ? _a : []; });
18807
+ // output_text: scan backwards across all steps (stopping at user_input),
18808
+ // skip non-text content until the first text item is found, then collect
18809
+ // text until a non-text barrier is hit.
18772
18810
  const textParts = [];
18773
- for (let i = output.length - 1; i >= 0; i--) {
18774
- const content = output[i];
18775
- if (content.type !== 'text')
18811
+ let collecting = false;
18812
+ outer: for (let i = steps.length - 1; i >= 0; i--) {
18813
+ const step = steps[i];
18814
+ if (step.type === 'user_input')
18776
18815
  break;
18777
- textParts.push((_b = content.text) !== null && _b !== void 0 ? _b : '');
18816
+ if (step.type !== 'model_output' || !step.content) {
18817
+ if (collecting)
18818
+ break outer;
18819
+ continue;
18820
+ }
18821
+ const content = step.content;
18822
+ for (let j = content.length - 1; j >= 0; j--) {
18823
+ const item = content[j];
18824
+ if (item.type === 'text') {
18825
+ collecting = true;
18826
+ textParts.push((_b = item.text) !== null && _b !== void 0 ? _b : '');
18827
+ }
18828
+ else if (collecting) {
18829
+ // Hit a non-text barrier after we started collecting.
18830
+ break outer;
18831
+ }
18832
+ }
18778
18833
  }
18779
18834
  const output_text = textParts.reverse().join('');
18780
18835
  let output_image;
@@ -19517,6 +19572,7 @@ class GeminiNextGenAPIClient extends BaseGeminiNextGenAPIClient {
19517
19572
  super(...arguments);
19518
19573
  this.interactions = new Interactions(this);
19519
19574
  this.webhooks = new Webhooks(this);
19575
+ this.agents = new Agents(this);
19520
19576
  }
19521
19577
  }
19522
19578
  _a = GeminiNextGenAPIClient;
@@ -19537,6 +19593,7 @@ GeminiNextGenAPIClient.UnprocessableEntityError = UnprocessableEntityError;
19537
19593
  GeminiNextGenAPIClient.toFile = toFile;
19538
19594
  GeminiNextGenAPIClient.Interactions = Interactions;
19539
19595
  GeminiNextGenAPIClient.Webhooks = Webhooks;
19596
+ GeminiNextGenAPIClient.Agents = Agents;
19540
19597
 
19541
19598
  /**
19542
19599
  * @license
@@ -20995,6 +21052,14 @@ class GoogleGenAI {
20995
21052
  this._webhooks = this.getNextGenClient().webhooks;
20996
21053
  return this._webhooks;
20997
21054
  }
21055
+ get agents() {
21056
+ if (this._agents !== undefined) {
21057
+ return this._agents;
21058
+ }
21059
+ console.warn('GoogleGenAI.agents: Agents usage is experimental and may change in future versions.');
21060
+ this._agents = this.getNextGenClient().agents;
21061
+ return this._agents;
21062
+ }
20998
21063
  constructor(options) {
20999
21064
  var _a;
21000
21065
  if (options.apiKey == null) {