@google/adk 1.1.0 → 1.2.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.
- package/dist/cjs/agents/functions.js +4 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/common.js +11 -0
- package/dist/cjs/events/event.js +3 -1
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
- package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
- package/dist/cjs/integrations/agent_registry/types.js +50 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
- package/dist/cjs/runner/in_memory_runner.js +10 -5
- package/dist/cjs/runner/runner.js +32 -2
- package/dist/cjs/sessions/database_session_service.js +49 -3
- package/dist/cjs/sessions/in_memory_session_service.js +70 -14
- package/dist/cjs/sessions/registry.js +4 -0
- package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
- package/dist/cjs/tools/agent_tool.js +10 -5
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- package/dist/cjs/tools/google_maps_grounding_tool.js +80 -0
- package/dist/cjs/tools/long_running_tool.js +2 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +10 -6
- package/dist/cjs/tools/mcp/mcp_toolset.js +26 -3
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
- package/dist/cjs/tools/vertex_rag_retrieval_tool.js +64 -0
- package/dist/cjs/utils/file_utils.js +28 -0
- package/dist/cjs/utils/gemini_schema_util.js +18 -0
- package/dist/cjs/utils/partial_copy.js +51 -0
- package/dist/cjs/utils/streaming_utils.js +167 -121
- package/dist/cjs/utils/vertex_ai_utils.js +50 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/functions.js +4 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/esm/code_executors/code_execution_utils.js +1 -1
- package/dist/esm/common.js +10 -0
- package/dist/esm/events/event.js +3 -1
- package/dist/esm/index.js +11 -0
- package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
- package/dist/esm/integrations/agent_registry/helpers.js +28 -0
- package/dist/esm/integrations/agent_registry/types.js +20 -0
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
- package/dist/esm/runner/in_memory_runner.js +10 -5
- package/dist/esm/runner/runner.js +32 -2
- package/dist/esm/sessions/database_session_service.js +49 -3
- package/dist/esm/sessions/in_memory_session_service.js +70 -14
- package/dist/esm/sessions/registry.js +7 -0
- package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
- package/dist/esm/tools/agent_tool.js +10 -5
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- package/dist/esm/tools/google_maps_grounding_tool.js +54 -0
- package/dist/esm/tools/long_running_tool.js +2 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/esm/tools/mcp/mcp_tool.js +10 -6
- package/dist/esm/tools/mcp/mcp_toolset.js +26 -3
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/esm/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/esm/utils/file_utils.js +26 -0
- package/dist/esm/utils/gemini_schema_util.js +18 -0
- package/dist/esm/utils/partial_copy.js +23 -0
- package/dist/esm/utils/streaming_utils.js +165 -120
- package/dist/esm/utils/vertex_ai_utils.js +22 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
- package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/run_config.d.ts +15 -0
- package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
- package/dist/types/common.d.ts +4 -0
- package/dist/types/events/event_actions.d.ts +24 -6
- package/dist/types/events/structured_events.d.ts +13 -0
- package/dist/types/examples/example_util.d.ts +25 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
- package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
- package/dist/types/integrations/agent_registry/types.d.ts +101 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
- package/dist/types/runner/in_memory_runner.d.ts +28 -1
- package/dist/types/runner/runner.d.ts +47 -0
- package/dist/types/sessions/base_session_service.d.ts +18 -0
- package/dist/types/sessions/database_session_service.d.ts +1 -1
- package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
- package/dist/types/tools/exit_loop_tool.d.ts +9 -0
- package/dist/types/tools/function_tool.d.ts +22 -2
- package/dist/types/tools/google_maps_grounding_tool.d.ts +22 -0
- package/dist/types/tools/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +2 -1
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
- package/dist/types/tools/vertex_rag_retrieval_tool.d.ts +42 -0
- package/dist/types/utils/file_utils.d.ts +2 -0
- package/dist/types/utils/partial_copy.d.ts +13 -0
- package/dist/types/utils/streaming_utils.d.ts +8 -17
- package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/functions.js +4 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/web/code_executors/code_execution_utils.js +1 -1
- package/dist/web/common.js +10 -0
- package/dist/web/events/event.js +3 -1
- package/dist/web/index.js +11 -0
- package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
- package/dist/web/integrations/agent_registry/helpers.js +28 -0
- package/dist/web/integrations/agent_registry/types.js +20 -0
- package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
- package/dist/web/runner/in_memory_runner.js +10 -5
- package/dist/web/runner/runner.js +32 -2
- package/dist/web/sessions/database_session_service.js +49 -3
- package/dist/web/sessions/in_memory_session_service.js +70 -14
- package/dist/web/sessions/registry.js +7 -0
- package/dist/web/sessions/vertex_ai_session_service.js +414 -0
- package/dist/web/tools/agent_tool.js +10 -5
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- package/dist/web/tools/google_maps_grounding_tool.js +54 -0
- package/dist/web/tools/long_running_tool.js +2 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/web/tools/mcp/mcp_tool.js +10 -6
- package/dist/web/tools/mcp/mcp_toolset.js +26 -3
- package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/web/tools/vertex_rag_retrieval_tool.js +36 -0
- package/dist/web/utils/file_utils.js +26 -0
- package/dist/web/utils/gemini_schema_util.js +18 -0
- package/dist/web/utils/partial_copy.js +23 -0
- package/dist/web/utils/streaming_utils.js +219 -121
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var partial_copy_exports = {};
|
|
26
|
+
__export(partial_copy_exports, {
|
|
27
|
+
partialCopy: () => partialCopy
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(partial_copy_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
function partialCopy(source, targetKeys) {
|
|
36
|
+
const result = {};
|
|
37
|
+
const sourceAsUnknown = source;
|
|
38
|
+
targetKeys.forEach((key) => {
|
|
39
|
+
const keyStr = key;
|
|
40
|
+
if (keyStr in source) {
|
|
41
|
+
result[key] = sourceAsUnknown[keyStr];
|
|
42
|
+
} else {
|
|
43
|
+
result[key] = void 0;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
partialCopy
|
|
51
|
+
});
|
|
@@ -24,7 +24,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var streaming_utils_exports = {};
|
|
26
26
|
__export(streaming_utils_exports, {
|
|
27
|
-
StreamingResponseAggregator: () => StreamingResponseAggregator
|
|
27
|
+
StreamingResponseAggregator: () => StreamingResponseAggregator,
|
|
28
|
+
isEmptyContentPart: () => isEmptyContentPart
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(streaming_utils_exports);
|
|
30
31
|
var import_genai = require("@google/genai");
|
|
@@ -37,15 +38,8 @@ var import_llm_response = require("../models/llm_response.js");
|
|
|
37
38
|
* Copyright 2026 Google LLC
|
|
38
39
|
* SPDX-License-Identifier: Apache-2.0
|
|
39
40
|
*/
|
|
40
|
-
class
|
|
41
|
-
constructor(
|
|
42
|
-
import_feature_registry.FeatureName.PROGRESSIVE_SSE_STREAMING
|
|
43
|
-
)) {
|
|
44
|
-
this.isProgressiveMode = isProgressiveMode;
|
|
45
|
-
// For non-progressive SSE streaming mode
|
|
46
|
-
this.text = "";
|
|
47
|
-
this.thoughtText = "";
|
|
48
|
-
// For progressive SSE streaming mode: accumulate parts in order
|
|
41
|
+
class ProgressiveStrategy {
|
|
42
|
+
constructor() {
|
|
49
43
|
this.partsSequence = [];
|
|
50
44
|
this.currentTextBuffer = "";
|
|
51
45
|
this.currentFcArgs = {};
|
|
@@ -172,11 +166,6 @@ class StreamingResponseAggregator {
|
|
|
172
166
|
if (!fc) {
|
|
173
167
|
return;
|
|
174
168
|
}
|
|
175
|
-
if (part.thoughtSignature) {
|
|
176
|
-
this.lastThoughtSignature = part.thoughtSignature;
|
|
177
|
-
} else if (this.lastThoughtSignature) {
|
|
178
|
-
part.thoughtSignature = this.lastThoughtSignature.toString();
|
|
179
|
-
}
|
|
180
169
|
if (fc.partialArgs || fc.willContinue) {
|
|
181
170
|
if (!fc.id && !this.currentFcId) {
|
|
182
171
|
fc.id = (0, import_functions.generateClientFunctionCallId)();
|
|
@@ -195,63 +184,103 @@ class StreamingResponseAggregator {
|
|
|
195
184
|
}
|
|
196
185
|
}
|
|
197
186
|
}
|
|
198
|
-
async *processResponse(
|
|
199
|
-
var _a
|
|
200
|
-
this.response = response;
|
|
201
|
-
const llmResponse = (0, import_llm_response.createLlmResponse)(response);
|
|
202
|
-
this.usageMetadata = llmResponse.usageMetadata;
|
|
203
|
-
if (llmResponse.groundingMetadata) {
|
|
204
|
-
this.groundingMetadata = llmResponse.groundingMetadata;
|
|
205
|
-
}
|
|
206
|
-
if (llmResponse.citationMetadata) {
|
|
207
|
-
this.citationMetadata = llmResponse.citationMetadata;
|
|
208
|
-
}
|
|
209
|
-
if (llmResponse.finishReason) {
|
|
210
|
-
this.finishReason = llmResponse.finishReason;
|
|
211
|
-
}
|
|
187
|
+
async *processResponse(llmResponse) {
|
|
188
|
+
var _a;
|
|
212
189
|
if (llmResponse.content && llmResponse.content.parts) {
|
|
213
190
|
for (const part of llmResponse.content.parts) {
|
|
214
|
-
if (part.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
191
|
+
if (part.text) {
|
|
192
|
+
const isThought = (_a = part.thought) != null ? _a : false;
|
|
193
|
+
if (this.currentTextBuffer && isThought !== this.currentTextIsThought) {
|
|
194
|
+
this.flushTextBufferToSequence();
|
|
195
|
+
}
|
|
196
|
+
if (!this.currentTextBuffer) {
|
|
197
|
+
this.currentTextIsThought = isThought;
|
|
198
|
+
}
|
|
199
|
+
this.currentTextBuffer += part.text;
|
|
200
|
+
} else if (part.functionCall) {
|
|
201
|
+
this.processFunctionCallPart(part);
|
|
202
|
+
} else {
|
|
203
|
+
this.flushTextBufferToSequence();
|
|
204
|
+
this.partsSequence.push(part);
|
|
218
205
|
}
|
|
219
206
|
}
|
|
220
207
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
208
|
+
llmResponse.partial = true;
|
|
209
|
+
yield llmResponse;
|
|
210
|
+
}
|
|
211
|
+
close() {
|
|
212
|
+
this.flushTextBufferToSequence();
|
|
213
|
+
this.flushFunctionCallToSequence();
|
|
214
|
+
const finalParts = this.partsSequence;
|
|
215
|
+
if (finalParts.length === 0) {
|
|
216
|
+
return void 0;
|
|
217
|
+
}
|
|
218
|
+
return finalParts;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
class NonProgressiveStrategy {
|
|
222
|
+
constructor() {
|
|
223
|
+
this.text = "";
|
|
224
|
+
this.thoughtText = "";
|
|
225
|
+
}
|
|
226
|
+
async *processResponse(llmResponse) {
|
|
227
|
+
var _a;
|
|
228
|
+
if ((_a = llmResponse.content) == null ? void 0 : _a.parts) {
|
|
229
|
+
const nonTextParts = [];
|
|
230
|
+
let sawTextPart = false;
|
|
231
|
+
for (const part of llmResponse.content.parts) {
|
|
232
|
+
if (typeof part.text === "string") {
|
|
233
|
+
sawTextPart = true;
|
|
234
|
+
if (part.thought) {
|
|
235
|
+
this.thoughtText += part.text;
|
|
235
236
|
} else {
|
|
236
|
-
this.
|
|
237
|
-
this.partsSequence.push(part);
|
|
237
|
+
this.text += part.text;
|
|
238
238
|
}
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (part.functionCall && !part.functionCall.id) {
|
|
242
|
+
part.functionCall.id = (0, import_functions.generateClientFunctionCallId)();
|
|
239
243
|
}
|
|
244
|
+
nonTextParts.push(part);
|
|
240
245
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
246
|
+
if (nonTextParts.length > 0) {
|
|
247
|
+
if (this.thoughtText || this.text) {
|
|
248
|
+
const parts = [];
|
|
249
|
+
if (this.thoughtText) {
|
|
250
|
+
parts.push({ text: this.thoughtText, thought: true });
|
|
251
|
+
}
|
|
252
|
+
if (this.text) {
|
|
253
|
+
parts.push({ text: this.text });
|
|
254
|
+
}
|
|
255
|
+
yield {
|
|
256
|
+
content: {
|
|
257
|
+
role: "model",
|
|
258
|
+
parts
|
|
259
|
+
},
|
|
260
|
+
usageMetadata: llmResponse.usageMetadata,
|
|
261
|
+
partial: false
|
|
262
|
+
};
|
|
263
|
+
this.thoughtText = "";
|
|
264
|
+
this.text = "";
|
|
265
|
+
}
|
|
266
|
+
yield {
|
|
267
|
+
...llmResponse,
|
|
268
|
+
content: {
|
|
269
|
+
role: llmResponse.content.role,
|
|
270
|
+
parts: nonTextParts
|
|
271
|
+
},
|
|
272
|
+
partial: false
|
|
273
|
+
};
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
if (sawTextPart) {
|
|
277
|
+
llmResponse.partial = true;
|
|
252
278
|
}
|
|
253
|
-
|
|
254
|
-
|
|
279
|
+
}
|
|
280
|
+
yield llmResponse;
|
|
281
|
+
}
|
|
282
|
+
close() {
|
|
283
|
+
if (this.text || this.thoughtText) {
|
|
255
284
|
const parts = [];
|
|
256
285
|
if (this.thoughtText) {
|
|
257
286
|
parts.push({ text: this.thoughtText, thought: true });
|
|
@@ -259,75 +288,92 @@ class StreamingResponseAggregator {
|
|
|
259
288
|
if (this.text) {
|
|
260
289
|
parts.push({ text: this.text });
|
|
261
290
|
}
|
|
262
|
-
|
|
263
|
-
content: {
|
|
264
|
-
role: "model",
|
|
265
|
-
parts
|
|
266
|
-
},
|
|
267
|
-
usageMetadata: llmResponse.usageMetadata,
|
|
268
|
-
partial: false
|
|
269
|
-
};
|
|
270
|
-
this.thoughtText = "";
|
|
271
|
-
this.text = "";
|
|
291
|
+
return parts;
|
|
272
292
|
}
|
|
273
|
-
|
|
293
|
+
return void 0;
|
|
274
294
|
}
|
|
275
|
-
|
|
295
|
+
}
|
|
296
|
+
class StreamingResponseAggregator {
|
|
297
|
+
constructor(isProgressiveMode = (0, import_feature_registry.isFeatureEnabled)(
|
|
298
|
+
import_feature_registry.FeatureName.PROGRESSIVE_SSE_STREAMING
|
|
299
|
+
)) {
|
|
300
|
+
this.isProgressiveMode = isProgressiveMode;
|
|
301
|
+
this.lastThoughtSignature = {};
|
|
302
|
+
this.sawFunctionCall = false;
|
|
303
|
+
this.strategy = this.isProgressiveMode ? new ProgressiveStrategy() : new NonProgressiveStrategy();
|
|
304
|
+
}
|
|
305
|
+
async *processResponse(response) {
|
|
276
306
|
var _a, _b;
|
|
277
|
-
|
|
278
|
-
|
|
307
|
+
const llmResponse = (0, import_llm_response.createLlmResponse)(response);
|
|
308
|
+
const parts = (_b = (_a = llmResponse.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
309
|
+
if (parts.some((part) => part.functionCall)) {
|
|
310
|
+
this.sawFunctionCall = true;
|
|
279
311
|
}
|
|
280
|
-
if (this.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const finalParts = this.partsSequence;
|
|
284
|
-
if (finalParts.length === 0) {
|
|
285
|
-
return;
|
|
312
|
+
if (this.sawFunctionCall && llmResponse.finishReason === import_genai.FinishReason.STOP && parts.length > 0 && parts.every(isEmptyContentPart)) {
|
|
313
|
+
if (llmResponse.usageMetadata) {
|
|
314
|
+
this.usageMetadata = llmResponse.usageMetadata;
|
|
286
315
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return {
|
|
290
|
-
content: {
|
|
291
|
-
role: "model",
|
|
292
|
-
parts: finalParts
|
|
293
|
-
},
|
|
294
|
-
groundingMetadata: this.groundingMetadata,
|
|
295
|
-
citationMetadata: this.citationMetadata,
|
|
296
|
-
errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
|
|
297
|
-
errorMessage: finishReason === import_genai.FinishReason.STOP ? void 0 : candidate.finishMessage,
|
|
298
|
-
usageMetadata: this.usageMetadata,
|
|
299
|
-
finishReason,
|
|
300
|
-
partial: false
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
if ((this.text || this.thoughtText) && this.response.candidates && this.response.candidates.length > 0) {
|
|
304
|
-
const parts = [];
|
|
305
|
-
if (this.thoughtText) {
|
|
306
|
-
parts.push({ text: this.thoughtText, thought: true });
|
|
316
|
+
if (llmResponse.groundingMetadata) {
|
|
317
|
+
this.groundingMetadata = llmResponse.groundingMetadata;
|
|
307
318
|
}
|
|
308
|
-
if (
|
|
309
|
-
|
|
319
|
+
if (llmResponse.citationMetadata) {
|
|
320
|
+
this.citationMetadata = llmResponse.citationMetadata;
|
|
310
321
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
role: "model",
|
|
316
|
-
parts
|
|
317
|
-
},
|
|
318
|
-
groundingMetadata: this.groundingMetadata,
|
|
319
|
-
citationMetadata: this.citationMetadata,
|
|
320
|
-
errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
|
|
321
|
-
errorMessage: finishReason === import_genai.FinishReason.STOP ? void 0 : candidate.finishMessage,
|
|
322
|
-
usageMetadata: this.usageMetadata,
|
|
323
|
-
finishReason,
|
|
324
|
-
partial: false
|
|
325
|
-
};
|
|
322
|
+
if (llmResponse.finishReason) {
|
|
323
|
+
this.finishReason = llmResponse.finishReason;
|
|
324
|
+
}
|
|
325
|
+
return;
|
|
326
326
|
}
|
|
327
|
-
|
|
327
|
+
this.response = response;
|
|
328
|
+
this.usageMetadata = llmResponse.usageMetadata;
|
|
329
|
+
if (llmResponse.groundingMetadata) {
|
|
330
|
+
this.groundingMetadata = llmResponse.groundingMetadata;
|
|
331
|
+
}
|
|
332
|
+
if (llmResponse.citationMetadata) {
|
|
333
|
+
this.citationMetadata = llmResponse.citationMetadata;
|
|
334
|
+
}
|
|
335
|
+
if (llmResponse.finishReason) {
|
|
336
|
+
this.finishReason = llmResponse.finishReason;
|
|
337
|
+
}
|
|
338
|
+
if (llmResponse.content && llmResponse.content.parts) {
|
|
339
|
+
for (const part of llmResponse.content.parts) {
|
|
340
|
+
if (part.thoughtSignature) {
|
|
341
|
+
this.lastThoughtSignature.value = part.thoughtSignature;
|
|
342
|
+
} else if (part.functionCall && this.lastThoughtSignature.value) {
|
|
343
|
+
part.thoughtSignature = this.lastThoughtSignature.value.toString();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
yield* this.strategy.processResponse(llmResponse);
|
|
348
|
+
}
|
|
349
|
+
close() {
|
|
350
|
+
var _a, _b, _c;
|
|
351
|
+
const finalParts = this.strategy.close();
|
|
352
|
+
if (!finalParts) {
|
|
353
|
+
return void 0;
|
|
354
|
+
}
|
|
355
|
+
const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
|
|
356
|
+
const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
|
|
357
|
+
return {
|
|
358
|
+
content: {
|
|
359
|
+
role: "model",
|
|
360
|
+
parts: finalParts
|
|
361
|
+
},
|
|
362
|
+
groundingMetadata: this.groundingMetadata,
|
|
363
|
+
citationMetadata: this.citationMetadata,
|
|
364
|
+
errorCode: finishReason === import_genai.FinishReason.STOP ? void 0 : finishReason,
|
|
365
|
+
errorMessage: finishReason === import_genai.FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
|
|
366
|
+
usageMetadata: this.usageMetadata,
|
|
367
|
+
finishReason,
|
|
368
|
+
partial: false
|
|
369
|
+
};
|
|
328
370
|
}
|
|
329
371
|
}
|
|
372
|
+
function isEmptyContentPart(part) {
|
|
373
|
+
return !part.functionCall && !part.functionResponse && !part.fileData && !part.inlineData && !part.executableCode && !part.codeExecutionResult && (!part.text || part.text === "");
|
|
374
|
+
}
|
|
330
375
|
// Annotate the CommonJS export names for ESM import in node:
|
|
331
376
|
0 && (module.exports = {
|
|
332
|
-
StreamingResponseAggregator
|
|
377
|
+
StreamingResponseAggregator,
|
|
378
|
+
isEmptyContentPart
|
|
333
379
|
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var vertex_ai_utils_exports = {};
|
|
26
|
+
__export(vertex_ai_utils_exports, {
|
|
27
|
+
getExpressModeApiKey: () => getExpressModeApiKey
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(vertex_ai_utils_exports);
|
|
30
|
+
var import_env_aware_utils = require("./env_aware_utils.js");
|
|
31
|
+
/**
|
|
32
|
+
* @license
|
|
33
|
+
* Copyright 2026 Google LLC
|
|
34
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
35
|
+
*/
|
|
36
|
+
function getExpressModeApiKey(project, location, expressModeApiKey) {
|
|
37
|
+
if ((project || location) && expressModeApiKey) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"Cannot specify project or location and expressModeApiKey. Either use project and location, or just the expressModeApiKey."
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
if ((0, import_env_aware_utils.getBooleanEnvVar)("GOOGLE_GENAI_USE_VERTEXAI")) {
|
|
43
|
+
return expressModeApiKey || process.env.GOOGLE_API_KEY;
|
|
44
|
+
}
|
|
45
|
+
return void 0;
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
getExpressModeApiKey
|
|
50
|
+
});
|
package/dist/cjs/version.js
CHANGED
|
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(version_exports);
|
|
|
32
32
|
* Copyright 2025 Google LLC
|
|
33
33
|
* SPDX-License-Identifier: Apache-2.0
|
|
34
34
|
*/
|
|
35
|
-
const version = "1.
|
|
35
|
+
const version = "1.2.0";
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
|
38
38
|
version
|
|
@@ -159,6 +159,8 @@ function buildResponseEvent(tool, functionResult, toolContext, invocationContext
|
|
|
159
159
|
let responseResult;
|
|
160
160
|
if (typeof functionResult !== "object" || functionResult == null) {
|
|
161
161
|
responseResult = { result: functionResult };
|
|
162
|
+
} else if (Array.isArray(functionResult)) {
|
|
163
|
+
responseResult = { results: functionResult };
|
|
162
164
|
} else {
|
|
163
165
|
responseResult = functionResult;
|
|
164
166
|
}
|
|
@@ -297,6 +299,8 @@ async function handleFunctionCallList({
|
|
|
297
299
|
functionResponse = { error: functionResponseError };
|
|
298
300
|
} else if (typeof functionResponse !== "object" || functionResponse == null) {
|
|
299
301
|
functionResponse = { result: functionResponse };
|
|
302
|
+
} else if (Array.isArray(functionResponse)) {
|
|
303
|
+
functionResponse = { results: functionResponse };
|
|
300
304
|
}
|
|
301
305
|
const functionResponseEvent = createEvent({
|
|
302
306
|
invocationId: invocationContext.invocationId,
|
|
@@ -123,6 +123,18 @@ class OAuth2DiscoveryManager {
|
|
|
123
123
|
return void 0;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
+
function normaliseHostname(raw) {
|
|
127
|
+
const stripped = raw.replace(/^\[|\]$/g, "");
|
|
128
|
+
const m = stripped.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i);
|
|
129
|
+
if (m) {
|
|
130
|
+
const hi = parseInt(m[1], 16);
|
|
131
|
+
const lo = parseInt(m[2], 16);
|
|
132
|
+
return [hi >> 8 & 255, hi & 255, lo >> 8 & 255, lo & 255].join(".");
|
|
133
|
+
}
|
|
134
|
+
const mDot = stripped.match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/i);
|
|
135
|
+
if (mDot) return mDot[1];
|
|
136
|
+
return raw;
|
|
137
|
+
}
|
|
126
138
|
function validateDiscoveryUrl(urlStr) {
|
|
127
139
|
try {
|
|
128
140
|
const url = new URL(urlStr);
|
|
@@ -130,8 +142,8 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
130
142
|
logger.warn(`Unsafe protocol for discovery URL: ${url.protocol}`);
|
|
131
143
|
return false;
|
|
132
144
|
}
|
|
133
|
-
const host = url.hostname.toLowerCase();
|
|
134
|
-
if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
|
|
145
|
+
const host = normaliseHostname(url.hostname.toLowerCase());
|
|
146
|
+
if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
|
|
135
147
|
logger.warn(`Unsafe host for discovery URL: ${host}`);
|
|
136
148
|
return false;
|
|
137
149
|
}
|
|
@@ -143,6 +155,18 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
143
155
|
return false;
|
|
144
156
|
}
|
|
145
157
|
}
|
|
158
|
+
const cgnatMatch = host.match(/^100\.(\d+)\./);
|
|
159
|
+
if (cgnatMatch) {
|
|
160
|
+
const secondOctet = parseInt(cgnatMatch[1], 10);
|
|
161
|
+
if (secondOctet >= 64 && secondOctet <= 127) {
|
|
162
|
+
logger.warn(`Unsafe host for discovery URL: ${host}`);
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (/^\[(f[cd][0-9a-f]{2}|fe[89ab][0-9a-f]):/i.test(url.hostname)) {
|
|
167
|
+
logger.warn(`Unsafe host for discovery URL: ${url.hostname}`);
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
146
170
|
return true;
|
|
147
171
|
} catch (e) {
|
|
148
172
|
logger.warn(`Failed to parse URL for validation ${urlStr}: ${e}`);
|