@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.
@@ -12823,7 +12823,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
12823
12823
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
12824
12824
  const USER_AGENT_HEADER = 'User-Agent';
12825
12825
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
12826
- const SDK_VERSION = '2.3.0'; // x-release-please-version
12826
+ const SDK_VERSION = '2.5.0'; // x-release-please-version
12827
12827
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
12828
12828
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
12829
12829
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -17609,7 +17609,9 @@ class APIConnectionError extends APIError {
17609
17609
  }
17610
17610
  class APIConnectionTimeoutError extends APIConnectionError {
17611
17611
  constructor({ message } = {}) {
17612
- super({ message: message !== null && message !== void 0 ? message : 'Request timed out.' });
17612
+ super({
17613
+ 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.',
17614
+ });
17613
17615
  }
17614
17616
  }
17615
17617
  class BadRequestError extends APIError {
@@ -17976,6 +17978,126 @@ class APIResource {
17976
17978
  */
17977
17979
  APIResource._key = [];
17978
17980
 
17981
+ /**
17982
+ * @license
17983
+ * Copyright 2025 Google LLC
17984
+ * SPDX-License-Identifier: Apache-2.0
17985
+ */
17986
+ /**
17987
+ * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
17988
+ *
17989
+ * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
17990
+ * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
17991
+ * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
17992
+ * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
17993
+ */
17994
+ function encodeURIPath(str) {
17995
+ return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
17996
+ }
17997
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
17998
+ const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
17999
+ // If there are no params, no processing is needed.
18000
+ if (statics.length === 1)
18001
+ return statics[0];
18002
+ let postPath = false;
18003
+ const invalidSegments = [];
18004
+ const path = statics.reduce((previousValue, currentValue, index) => {
18005
+ var _a, _b, _c;
18006
+ if (/[?#]/.test(currentValue)) {
18007
+ postPath = true;
18008
+ }
18009
+ const value = params[index];
18010
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
18011
+ if (index !== params.length &&
18012
+ (value == null ||
18013
+ (typeof value === 'object' &&
18014
+ // handle values from other realms
18015
+ value.toString ===
18016
+ ((_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)))) {
18017
+ encoded = value + '';
18018
+ invalidSegments.push({
18019
+ start: previousValue.length + currentValue.length,
18020
+ length: encoded.length,
18021
+ error: `Value of type ${Object.prototype.toString
18022
+ .call(value)
18023
+ .slice(8, -1)} is not a valid path parameter`,
18024
+ });
18025
+ }
18026
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
18027
+ }, '');
18028
+ const pathOnly = path.split(/[?#]/, 1)[0];
18029
+ const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
18030
+ let match;
18031
+ // Find all invalid segments
18032
+ while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
18033
+ const hasLeadingSlash = match[0].startsWith('/');
18034
+ const offset = hasLeadingSlash ? 1 : 0;
18035
+ const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
18036
+ invalidSegments.push({
18037
+ start: match.index + offset,
18038
+ length: cleanMatch.length,
18039
+ error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
18040
+ });
18041
+ }
18042
+ invalidSegments.sort((a, b) => a.start - b.start);
18043
+ if (invalidSegments.length > 0) {
18044
+ let lastEnd = 0;
18045
+ const underline = invalidSegments.reduce((acc, segment) => {
18046
+ const spaces = ' '.repeat(segment.start - lastEnd);
18047
+ const arrows = '^'.repeat(segment.length);
18048
+ lastEnd = segment.start + segment.length;
18049
+ return acc + spaces + arrows;
18050
+ }, '');
18051
+ throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
18052
+ .map((e) => e.error)
18053
+ .join('\n')}\n${path}\n${underline}`);
18054
+ }
18055
+ return path;
18056
+ });
18057
+ /**
18058
+ * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
18059
+ */
18060
+ const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
18061
+
18062
+ /**
18063
+ * @license
18064
+ * Copyright 2025 Google LLC
18065
+ * SPDX-License-Identifier: Apache-2.0
18066
+ */
18067
+ class BaseAgents extends APIResource {
18068
+ /**
18069
+ * Creates a new Agent (Typed version for SDK).
18070
+ */
18071
+ create(params = {}, options) {
18072
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
18073
+ return this._client.post(path `/${api_version}/agents`, Object.assign({ body }, options));
18074
+ }
18075
+ /**
18076
+ * Lists all Agents.
18077
+ */
18078
+ list(params = {}, options) {
18079
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
18080
+ return this._client.get(path `/${api_version}/agents`, Object.assign({ query }, options));
18081
+ }
18082
+ /**
18083
+ * Deletes an Agent.
18084
+ */
18085
+ delete(id, params = {}, options) {
18086
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18087
+ return this._client.delete(path `/${api_version}/agents/${id}`, options);
18088
+ }
18089
+ /**
18090
+ * Gets a specific Agent.
18091
+ */
18092
+ get(id, params = {}, options) {
18093
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18094
+ return this._client.get(path `/${api_version}/agents/${id}`, options);
18095
+ }
18096
+ }
18097
+ BaseAgents._key = Object.freeze(['agents']);
18098
+ class Agents extends BaseAgents {
18099
+ }
18100
+
17979
18101
  /**
17980
18102
  * @license
17981
18103
  * Copyright 2025 Google LLC
@@ -18637,87 +18759,6 @@ class LegacyLyriaStream extends Stream {
18637
18759
  }
18638
18760
  }
18639
18761
 
18640
- /**
18641
- * @license
18642
- * Copyright 2025 Google LLC
18643
- * SPDX-License-Identifier: Apache-2.0
18644
- */
18645
- /**
18646
- * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
18647
- *
18648
- * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
18649
- * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
18650
- * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
18651
- * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
18652
- */
18653
- function encodeURIPath(str) {
18654
- return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
18655
- }
18656
- const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
18657
- const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
18658
- // If there are no params, no processing is needed.
18659
- if (statics.length === 1)
18660
- return statics[0];
18661
- let postPath = false;
18662
- const invalidSegments = [];
18663
- const path = statics.reduce((previousValue, currentValue, index) => {
18664
- var _a, _b, _c;
18665
- if (/[?#]/.test(currentValue)) {
18666
- postPath = true;
18667
- }
18668
- const value = params[index];
18669
- let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
18670
- if (index !== params.length &&
18671
- (value == null ||
18672
- (typeof value === 'object' &&
18673
- // handle values from other realms
18674
- value.toString ===
18675
- ((_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)))) {
18676
- encoded = value + '';
18677
- invalidSegments.push({
18678
- start: previousValue.length + currentValue.length,
18679
- length: encoded.length,
18680
- error: `Value of type ${Object.prototype.toString
18681
- .call(value)
18682
- .slice(8, -1)} is not a valid path parameter`,
18683
- });
18684
- }
18685
- return previousValue + currentValue + (index === params.length ? '' : encoded);
18686
- }, '');
18687
- const pathOnly = path.split(/[?#]/, 1)[0];
18688
- const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
18689
- let match;
18690
- // Find all invalid segments
18691
- while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
18692
- const hasLeadingSlash = match[0].startsWith('/');
18693
- const offset = hasLeadingSlash ? 1 : 0;
18694
- const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
18695
- invalidSegments.push({
18696
- start: match.index + offset,
18697
- length: cleanMatch.length,
18698
- error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
18699
- });
18700
- }
18701
- invalidSegments.sort((a, b) => a.start - b.start);
18702
- if (invalidSegments.length > 0) {
18703
- let lastEnd = 0;
18704
- const underline = invalidSegments.reduce((acc, segment) => {
18705
- const spaces = ' '.repeat(segment.start - lastEnd);
18706
- const arrows = '^'.repeat(segment.length);
18707
- lastEnd = segment.start + segment.length;
18708
- return acc + spaces + arrows;
18709
- }, '');
18710
- throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
18711
- .map((e) => e.error)
18712
- .join('\n')}\n${path}\n${underline}`);
18713
- }
18714
- return path;
18715
- });
18716
- /**
18717
- * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
18718
- */
18719
- const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
18720
-
18721
18762
  /**
18722
18763
  * @license
18723
18764
  * Copyright 2025 Google LLC
@@ -18793,18 +18834,32 @@ class Interactions extends BaseInteractions {
18793
18834
  function addOutputProperties(interaction) {
18794
18835
  var _a, _b;
18795
18836
  const steps = (_a = interaction.steps) !== null && _a !== void 0 ? _a : [];
18796
- let firstTrailing = steps.length;
18797
- while (firstTrailing > 0 && steps[firstTrailing - 1].type === 'model_output') {
18798
- firstTrailing--;
18799
- }
18800
- const modelSteps = steps.slice(firstTrailing);
18801
- const output = modelSteps.flatMap((step) => { var _a; return (_a = step.content) !== null && _a !== void 0 ? _a : []; });
18837
+ // output_text: scan backwards across all steps (stopping at user_input),
18838
+ // skip non-text content until the first text item is found, then collect
18839
+ // text until a non-text barrier is hit.
18802
18840
  const textParts = [];
18803
- for (let i = output.length - 1; i >= 0; i--) {
18804
- const content = output[i];
18805
- if (content.type !== 'text')
18841
+ let collecting = false;
18842
+ outer: for (let i = steps.length - 1; i >= 0; i--) {
18843
+ const step = steps[i];
18844
+ if (step.type === 'user_input')
18806
18845
  break;
18807
- textParts.push((_b = content.text) !== null && _b !== void 0 ? _b : '');
18846
+ if (step.type !== 'model_output' || !step.content) {
18847
+ if (collecting)
18848
+ break outer;
18849
+ continue;
18850
+ }
18851
+ const content = step.content;
18852
+ for (let j = content.length - 1; j >= 0; j--) {
18853
+ const item = content[j];
18854
+ if (item.type === 'text') {
18855
+ collecting = true;
18856
+ textParts.push((_b = item.text) !== null && _b !== void 0 ? _b : '');
18857
+ }
18858
+ else if (collecting) {
18859
+ // Hit a non-text barrier after we started collecting.
18860
+ break outer;
18861
+ }
18862
+ }
18808
18863
  }
18809
18864
  const output_text = textParts.reverse().join('');
18810
18865
  let output_image;
@@ -19547,6 +19602,7 @@ class GeminiNextGenAPIClient extends BaseGeminiNextGenAPIClient {
19547
19602
  super(...arguments);
19548
19603
  this.interactions = new Interactions(this);
19549
19604
  this.webhooks = new Webhooks(this);
19605
+ this.agents = new Agents(this);
19550
19606
  }
19551
19607
  }
19552
19608
  _a = GeminiNextGenAPIClient;
@@ -19567,6 +19623,7 @@ GeminiNextGenAPIClient.UnprocessableEntityError = UnprocessableEntityError;
19567
19623
  GeminiNextGenAPIClient.toFile = toFile;
19568
19624
  GeminiNextGenAPIClient.Interactions = Interactions;
19569
19625
  GeminiNextGenAPIClient.Webhooks = Webhooks;
19626
+ GeminiNextGenAPIClient.Agents = Agents;
19570
19627
 
19571
19628
  /**
19572
19629
  * @license
@@ -21396,6 +21453,14 @@ class GoogleGenAI {
21396
21453
  this._webhooks = this.getNextGenClient().webhooks;
21397
21454
  return this._webhooks;
21398
21455
  }
21456
+ get agents() {
21457
+ if (this._agents !== undefined) {
21458
+ return this._agents;
21459
+ }
21460
+ console.warn('GoogleGenAI.agents: Agents usage is experimental and may change in future versions.');
21461
+ this._agents = this.getNextGenClient().agents;
21462
+ return this._agents;
21463
+ }
21399
21464
  constructor(options) {
21400
21465
  var _a, _b, _c, _d;
21401
21466
  // Validate explicitly set initializer values.
@@ -12801,7 +12801,7 @@ const CONTENT_TYPE_HEADER = 'Content-Type';
12801
12801
  const SERVER_TIMEOUT_HEADER = 'X-Server-Timeout';
12802
12802
  const USER_AGENT_HEADER = 'User-Agent';
12803
12803
  const GOOGLE_API_CLIENT_HEADER = 'x-goog-api-client';
12804
- const SDK_VERSION = '2.3.0'; // x-release-please-version
12804
+ const SDK_VERSION = '2.5.0'; // x-release-please-version
12805
12805
  const LIBRARY_LABEL = `google-genai-sdk/${SDK_VERSION}`;
12806
12806
  const VERTEX_AI_API_DEFAULT_VERSION = 'v1beta1';
12807
12807
  const GOOGLE_AI_API_DEFAULT_VERSION = 'v1beta';
@@ -17587,7 +17587,9 @@ class APIConnectionError extends APIError {
17587
17587
  }
17588
17588
  class APIConnectionTimeoutError extends APIConnectionError {
17589
17589
  constructor({ message } = {}) {
17590
- super({ message: message !== null && message !== void 0 ? message : 'Request timed out.' });
17590
+ super({
17591
+ 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.',
17592
+ });
17591
17593
  }
17592
17594
  }
17593
17595
  class BadRequestError extends APIError {
@@ -17954,6 +17956,126 @@ class APIResource {
17954
17956
  */
17955
17957
  APIResource._key = [];
17956
17958
 
17959
+ /**
17960
+ * @license
17961
+ * Copyright 2025 Google LLC
17962
+ * SPDX-License-Identifier: Apache-2.0
17963
+ */
17964
+ /**
17965
+ * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
17966
+ *
17967
+ * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
17968
+ * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
17969
+ * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
17970
+ * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
17971
+ */
17972
+ function encodeURIPath(str) {
17973
+ return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
17974
+ }
17975
+ const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
17976
+ const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
17977
+ // If there are no params, no processing is needed.
17978
+ if (statics.length === 1)
17979
+ return statics[0];
17980
+ let postPath = false;
17981
+ const invalidSegments = [];
17982
+ const path = statics.reduce((previousValue, currentValue, index) => {
17983
+ var _a, _b, _c;
17984
+ if (/[?#]/.test(currentValue)) {
17985
+ postPath = true;
17986
+ }
17987
+ const value = params[index];
17988
+ let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
17989
+ if (index !== params.length &&
17990
+ (value == null ||
17991
+ (typeof value === 'object' &&
17992
+ // handle values from other realms
17993
+ value.toString ===
17994
+ ((_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)))) {
17995
+ encoded = value + '';
17996
+ invalidSegments.push({
17997
+ start: previousValue.length + currentValue.length,
17998
+ length: encoded.length,
17999
+ error: `Value of type ${Object.prototype.toString
18000
+ .call(value)
18001
+ .slice(8, -1)} is not a valid path parameter`,
18002
+ });
18003
+ }
18004
+ return previousValue + currentValue + (index === params.length ? '' : encoded);
18005
+ }, '');
18006
+ const pathOnly = path.split(/[?#]/, 1)[0];
18007
+ const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
18008
+ let match;
18009
+ // Find all invalid segments
18010
+ while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
18011
+ const hasLeadingSlash = match[0].startsWith('/');
18012
+ const offset = hasLeadingSlash ? 1 : 0;
18013
+ const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
18014
+ invalidSegments.push({
18015
+ start: match.index + offset,
18016
+ length: cleanMatch.length,
18017
+ error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
18018
+ });
18019
+ }
18020
+ invalidSegments.sort((a, b) => a.start - b.start);
18021
+ if (invalidSegments.length > 0) {
18022
+ let lastEnd = 0;
18023
+ const underline = invalidSegments.reduce((acc, segment) => {
18024
+ const spaces = ' '.repeat(segment.start - lastEnd);
18025
+ const arrows = '^'.repeat(segment.length);
18026
+ lastEnd = segment.start + segment.length;
18027
+ return acc + spaces + arrows;
18028
+ }, '');
18029
+ throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
18030
+ .map((e) => e.error)
18031
+ .join('\n')}\n${path}\n${underline}`);
18032
+ }
18033
+ return path;
18034
+ });
18035
+ /**
18036
+ * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
18037
+ */
18038
+ const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
18039
+
18040
+ /**
18041
+ * @license
18042
+ * Copyright 2025 Google LLC
18043
+ * SPDX-License-Identifier: Apache-2.0
18044
+ */
18045
+ class BaseAgents extends APIResource {
18046
+ /**
18047
+ * Creates a new Agent (Typed version for SDK).
18048
+ */
18049
+ create(params = {}, options) {
18050
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, body = __rest(_a, ["api_version"]);
18051
+ return this._client.post(path `/${api_version}/agents`, Object.assign({ body }, options));
18052
+ }
18053
+ /**
18054
+ * Lists all Agents.
18055
+ */
18056
+ list(params = {}, options) {
18057
+ const _a = params !== null && params !== void 0 ? params : {}, { api_version = this._client.apiVersion } = _a, query = __rest(_a, ["api_version"]);
18058
+ return this._client.get(path `/${api_version}/agents`, Object.assign({ query }, options));
18059
+ }
18060
+ /**
18061
+ * Deletes an Agent.
18062
+ */
18063
+ delete(id, params = {}, options) {
18064
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18065
+ return this._client.delete(path `/${api_version}/agents/${id}`, options);
18066
+ }
18067
+ /**
18068
+ * Gets a specific Agent.
18069
+ */
18070
+ get(id, params = {}, options) {
18071
+ const { api_version = this._client.apiVersion } = params !== null && params !== void 0 ? params : {};
18072
+ return this._client.get(path `/${api_version}/agents/${id}`, options);
18073
+ }
18074
+ }
18075
+ BaseAgents._key = Object.freeze(['agents']);
18076
+ class Agents extends BaseAgents {
18077
+ }
18078
+
17957
18079
  /**
17958
18080
  * @license
17959
18081
  * Copyright 2025 Google LLC
@@ -18615,87 +18737,6 @@ class LegacyLyriaStream extends Stream {
18615
18737
  }
18616
18738
  }
18617
18739
 
18618
- /**
18619
- * @license
18620
- * Copyright 2025 Google LLC
18621
- * SPDX-License-Identifier: Apache-2.0
18622
- */
18623
- /**
18624
- * Percent-encode everything that isn't safe to have in a path without encoding safe chars.
18625
- *
18626
- * Taken from https://datatracker.ietf.org/doc/html/rfc3986#section-3.3:
18627
- * > unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
18628
- * > sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
18629
- * > pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
18630
- */
18631
- function encodeURIPath(str) {
18632
- return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
18633
- }
18634
- const EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
18635
- const createPathTagFunction = (pathEncoder = encodeURIPath) => (function path(statics, ...params) {
18636
- // If there are no params, no processing is needed.
18637
- if (statics.length === 1)
18638
- return statics[0];
18639
- let postPath = false;
18640
- const invalidSegments = [];
18641
- const path = statics.reduce((previousValue, currentValue, index) => {
18642
- var _a, _b, _c;
18643
- if (/[?#]/.test(currentValue)) {
18644
- postPath = true;
18645
- }
18646
- const value = params[index];
18647
- let encoded = (postPath ? encodeURIComponent : pathEncoder)('' + value);
18648
- if (index !== params.length &&
18649
- (value == null ||
18650
- (typeof value === 'object' &&
18651
- // handle values from other realms
18652
- value.toString ===
18653
- ((_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)))) {
18654
- encoded = value + '';
18655
- invalidSegments.push({
18656
- start: previousValue.length + currentValue.length,
18657
- length: encoded.length,
18658
- error: `Value of type ${Object.prototype.toString
18659
- .call(value)
18660
- .slice(8, -1)} is not a valid path parameter`,
18661
- });
18662
- }
18663
- return previousValue + currentValue + (index === params.length ? '' : encoded);
18664
- }, '');
18665
- const pathOnly = path.split(/[?#]/, 1)[0];
18666
- const invalidSegmentPattern = /(^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
18667
- let match;
18668
- // Find all invalid segments
18669
- while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
18670
- const hasLeadingSlash = match[0].startsWith('/');
18671
- const offset = hasLeadingSlash ? 1 : 0;
18672
- const cleanMatch = hasLeadingSlash ? match[0].slice(1) : match[0];
18673
- invalidSegments.push({
18674
- start: match.index + offset,
18675
- length: cleanMatch.length,
18676
- error: `Value "${cleanMatch}" can\'t be safely passed as a path parameter`,
18677
- });
18678
- }
18679
- invalidSegments.sort((a, b) => a.start - b.start);
18680
- if (invalidSegments.length > 0) {
18681
- let lastEnd = 0;
18682
- const underline = invalidSegments.reduce((acc, segment) => {
18683
- const spaces = ' '.repeat(segment.start - lastEnd);
18684
- const arrows = '^'.repeat(segment.length);
18685
- lastEnd = segment.start + segment.length;
18686
- return acc + spaces + arrows;
18687
- }, '');
18688
- throw new GeminiNextGenAPIClientError(`Path parameters result in path with invalid segments:\n${invalidSegments
18689
- .map((e) => e.error)
18690
- .join('\n')}\n${path}\n${underline}`);
18691
- }
18692
- return path;
18693
- });
18694
- /**
18695
- * URI-encodes path params and ensures no unsafe /./ or /../ path segments are introduced.
18696
- */
18697
- const path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
18698
-
18699
18740
  /**
18700
18741
  * @license
18701
18742
  * Copyright 2025 Google LLC
@@ -18771,18 +18812,32 @@ class Interactions extends BaseInteractions {
18771
18812
  function addOutputProperties(interaction) {
18772
18813
  var _a, _b;
18773
18814
  const steps = (_a = interaction.steps) !== null && _a !== void 0 ? _a : [];
18774
- let firstTrailing = steps.length;
18775
- while (firstTrailing > 0 && steps[firstTrailing - 1].type === 'model_output') {
18776
- firstTrailing--;
18777
- }
18778
- const modelSteps = steps.slice(firstTrailing);
18779
- const output = modelSteps.flatMap((step) => { var _a; return (_a = step.content) !== null && _a !== void 0 ? _a : []; });
18815
+ // output_text: scan backwards across all steps (stopping at user_input),
18816
+ // skip non-text content until the first text item is found, then collect
18817
+ // text until a non-text barrier is hit.
18780
18818
  const textParts = [];
18781
- for (let i = output.length - 1; i >= 0; i--) {
18782
- const content = output[i];
18783
- if (content.type !== 'text')
18819
+ let collecting = false;
18820
+ outer: for (let i = steps.length - 1; i >= 0; i--) {
18821
+ const step = steps[i];
18822
+ if (step.type === 'user_input')
18784
18823
  break;
18785
- textParts.push((_b = content.text) !== null && _b !== void 0 ? _b : '');
18824
+ if (step.type !== 'model_output' || !step.content) {
18825
+ if (collecting)
18826
+ break outer;
18827
+ continue;
18828
+ }
18829
+ const content = step.content;
18830
+ for (let j = content.length - 1; j >= 0; j--) {
18831
+ const item = content[j];
18832
+ if (item.type === 'text') {
18833
+ collecting = true;
18834
+ textParts.push((_b = item.text) !== null && _b !== void 0 ? _b : '');
18835
+ }
18836
+ else if (collecting) {
18837
+ // Hit a non-text barrier after we started collecting.
18838
+ break outer;
18839
+ }
18840
+ }
18786
18841
  }
18787
18842
  const output_text = textParts.reverse().join('');
18788
18843
  let output_image;
@@ -19525,6 +19580,7 @@ class GeminiNextGenAPIClient extends BaseGeminiNextGenAPIClient {
19525
19580
  super(...arguments);
19526
19581
  this.interactions = new Interactions(this);
19527
19582
  this.webhooks = new Webhooks(this);
19583
+ this.agents = new Agents(this);
19528
19584
  }
19529
19585
  }
19530
19586
  _a = GeminiNextGenAPIClient;
@@ -19545,6 +19601,7 @@ GeminiNextGenAPIClient.UnprocessableEntityError = UnprocessableEntityError;
19545
19601
  GeminiNextGenAPIClient.toFile = toFile;
19546
19602
  GeminiNextGenAPIClient.Interactions = Interactions;
19547
19603
  GeminiNextGenAPIClient.Webhooks = Webhooks;
19604
+ GeminiNextGenAPIClient.Agents = Agents;
19548
19605
 
19549
19606
  /**
19550
19607
  * @license
@@ -21374,6 +21431,14 @@ class GoogleGenAI {
21374
21431
  this._webhooks = this.getNextGenClient().webhooks;
21375
21432
  return this._webhooks;
21376
21433
  }
21434
+ get agents() {
21435
+ if (this._agents !== undefined) {
21436
+ return this._agents;
21437
+ }
21438
+ console.warn('GoogleGenAI.agents: Agents usage is experimental and may change in future versions.');
21439
+ this._agents = this.getNextGenClient().agents;
21440
+ return this._agents;
21441
+ }
21377
21442
  constructor(options) {
21378
21443
  var _a, _b, _c, _d;
21379
21444
  // Validate explicitly set initializer values.