@softactivate/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 +3 -0
- package/dist/cjs/events/event.js +2 -0
- 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 +17 -8
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- 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 -7
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -2
- 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/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 -118
- 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 +2 -0
- package/dist/esm/events/event.js +2 -0
- 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 +17 -8
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- 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 -7
- package/dist/esm/tools/mcp/mcp_toolset.js +10 -2
- 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/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 -117
- 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 +2 -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/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- 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/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 +2 -0
- package/dist/web/events/event.js +2 -0
- 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 +17 -8
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- 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 -7
- package/dist/web/tools/mcp/mcp_toolset.js +10 -2
- 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/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 +218 -117
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -1
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
3
9
|
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
10
|
+
var __typeError = (msg) => {
|
|
11
|
+
throw TypeError(msg);
|
|
12
|
+
};
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
4
26
|
var __await = function(promise, isYieldStar) {
|
|
5
27
|
this[0] = promise;
|
|
6
28
|
this[1] = isYieldStar;
|
|
@@ -16,6 +38,34 @@ var __asyncGenerator = (__this, __arguments, generator) => {
|
|
|
16
38
|
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
17
39
|
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
18
40
|
};
|
|
41
|
+
var __yieldStar = (value) => {
|
|
42
|
+
var obj = value[__knownSymbol("asyncIterator")], isAwait = false, method, it = {};
|
|
43
|
+
if (obj == null) {
|
|
44
|
+
obj = value[__knownSymbol("iterator")]();
|
|
45
|
+
method = (k) => it[k] = (x) => obj[k](x);
|
|
46
|
+
} else {
|
|
47
|
+
obj = obj.call(value);
|
|
48
|
+
method = (k) => it[k] = (v) => {
|
|
49
|
+
if (isAwait) {
|
|
50
|
+
isAwait = false;
|
|
51
|
+
if (k === "throw") throw v;
|
|
52
|
+
return v;
|
|
53
|
+
}
|
|
54
|
+
isAwait = true;
|
|
55
|
+
return {
|
|
56
|
+
done: false,
|
|
57
|
+
value: new __await(new Promise((resolve) => {
|
|
58
|
+
var x = obj[k](v);
|
|
59
|
+
if (!(x instanceof Object)) __typeError("Object expected");
|
|
60
|
+
resolve(x);
|
|
61
|
+
}), 1)
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
66
|
+
throw x;
|
|
67
|
+
}, "return" in obj && method("return"), it;
|
|
68
|
+
};
|
|
19
69
|
/**
|
|
20
70
|
* @license
|
|
21
71
|
* Copyright 2026 Google LLC
|
|
@@ -28,15 +78,8 @@ import { JSONPath } from "jsonpath-plus";
|
|
|
28
78
|
import { generateClientFunctionCallId } from "../agents/functions.js";
|
|
29
79
|
import { FeatureName, isFeatureEnabled } from "../features/feature_registry.js";
|
|
30
80
|
import { createLlmResponse } from "../models/llm_response.js";
|
|
31
|
-
class
|
|
32
|
-
constructor(
|
|
33
|
-
FeatureName.PROGRESSIVE_SSE_STREAMING
|
|
34
|
-
)) {
|
|
35
|
-
this.isProgressiveMode = isProgressiveMode;
|
|
36
|
-
// For non-progressive SSE streaming mode
|
|
37
|
-
this.text = "";
|
|
38
|
-
this.thoughtText = "";
|
|
39
|
-
// For progressive SSE streaming mode: accumulate parts in order
|
|
81
|
+
class ProgressiveStrategy {
|
|
82
|
+
constructor() {
|
|
40
83
|
this.partsSequence = [];
|
|
41
84
|
this.currentTextBuffer = "";
|
|
42
85
|
this.currentFcArgs = {};
|
|
@@ -163,11 +206,6 @@ class StreamingResponseAggregator {
|
|
|
163
206
|
if (!fc) {
|
|
164
207
|
return;
|
|
165
208
|
}
|
|
166
|
-
if (part.thoughtSignature) {
|
|
167
|
-
this.lastThoughtSignature = part.thoughtSignature;
|
|
168
|
-
} else if (this.lastThoughtSignature) {
|
|
169
|
-
part.thoughtSignature = this.lastThoughtSignature.toString();
|
|
170
|
-
}
|
|
171
209
|
if (fc.partialArgs || fc.willContinue) {
|
|
172
210
|
if (!fc.id && !this.currentFcId) {
|
|
173
211
|
fc.id = generateClientFunctionCallId();
|
|
@@ -186,110 +224,105 @@ class StreamingResponseAggregator {
|
|
|
186
224
|
}
|
|
187
225
|
}
|
|
188
226
|
}
|
|
189
|
-
processResponse(
|
|
227
|
+
processResponse(llmResponse) {
|
|
190
228
|
return __asyncGenerator(this, null, function* () {
|
|
191
|
-
var _a
|
|
192
|
-
this.response = response;
|
|
193
|
-
const llmResponse = createLlmResponse(response);
|
|
194
|
-
this.usageMetadata = llmResponse.usageMetadata;
|
|
195
|
-
if (llmResponse.groundingMetadata) {
|
|
196
|
-
this.groundingMetadata = llmResponse.groundingMetadata;
|
|
197
|
-
}
|
|
198
|
-
if (llmResponse.citationMetadata) {
|
|
199
|
-
this.citationMetadata = llmResponse.citationMetadata;
|
|
200
|
-
}
|
|
201
|
-
if (llmResponse.finishReason) {
|
|
202
|
-
this.finishReason = llmResponse.finishReason;
|
|
203
|
-
}
|
|
229
|
+
var _a;
|
|
204
230
|
if (llmResponse.content && llmResponse.content.parts) {
|
|
205
231
|
for (const part of llmResponse.content.parts) {
|
|
206
|
-
if (part.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
232
|
+
if (part.text) {
|
|
233
|
+
const isThought = (_a = part.thought) != null ? _a : false;
|
|
234
|
+
if (this.currentTextBuffer && isThought !== this.currentTextIsThought) {
|
|
235
|
+
this.flushTextBufferToSequence();
|
|
236
|
+
}
|
|
237
|
+
if (!this.currentTextBuffer) {
|
|
238
|
+
this.currentTextIsThought = isThought;
|
|
239
|
+
}
|
|
240
|
+
this.currentTextBuffer += part.text;
|
|
241
|
+
} else if (part.functionCall) {
|
|
242
|
+
this.processFunctionCallPart(part);
|
|
243
|
+
} else {
|
|
244
|
+
this.flushTextBufferToSequence();
|
|
245
|
+
this.partsSequence.push(part);
|
|
210
246
|
}
|
|
211
247
|
}
|
|
212
248
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
249
|
+
llmResponse.partial = true;
|
|
250
|
+
yield llmResponse;
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
close() {
|
|
254
|
+
this.flushTextBufferToSequence();
|
|
255
|
+
this.flushFunctionCallToSequence();
|
|
256
|
+
const finalParts = this.partsSequence;
|
|
257
|
+
if (finalParts.length === 0) {
|
|
258
|
+
return void 0;
|
|
259
|
+
}
|
|
260
|
+
return finalParts;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
class NonProgressiveStrategy {
|
|
264
|
+
constructor() {
|
|
265
|
+
this.text = "";
|
|
266
|
+
this.thoughtText = "";
|
|
267
|
+
}
|
|
268
|
+
processResponse(llmResponse) {
|
|
269
|
+
return __asyncGenerator(this, null, function* () {
|
|
270
|
+
var _a;
|
|
271
|
+
if ((_a = llmResponse.content) == null ? void 0 : _a.parts) {
|
|
272
|
+
const nonTextParts = [];
|
|
273
|
+
let sawTextPart = false;
|
|
274
|
+
for (const part of llmResponse.content.parts) {
|
|
275
|
+
if (typeof part.text === "string") {
|
|
276
|
+
sawTextPart = true;
|
|
277
|
+
if (part.thought) {
|
|
278
|
+
this.thoughtText += part.text;
|
|
227
279
|
} else {
|
|
228
|
-
this.
|
|
229
|
-
this.partsSequence.push(part);
|
|
280
|
+
this.text += part.text;
|
|
230
281
|
}
|
|
282
|
+
continue;
|
|
231
283
|
}
|
|
284
|
+
if (part.functionCall && !part.functionCall.id) {
|
|
285
|
+
part.functionCall.id = generateClientFunctionCallId();
|
|
286
|
+
}
|
|
287
|
+
nonTextParts.push(part);
|
|
232
288
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
289
|
+
if (nonTextParts.length > 0) {
|
|
290
|
+
if (this.thoughtText || this.text) {
|
|
291
|
+
const parts = [];
|
|
292
|
+
if (this.thoughtText) {
|
|
293
|
+
parts.push({ text: this.thoughtText, thought: true });
|
|
294
|
+
}
|
|
295
|
+
if (this.text) {
|
|
296
|
+
parts.push({ text: this.text });
|
|
297
|
+
}
|
|
298
|
+
yield {
|
|
299
|
+
content: {
|
|
300
|
+
role: "model",
|
|
301
|
+
parts
|
|
302
|
+
},
|
|
303
|
+
usageMetadata: llmResponse.usageMetadata,
|
|
304
|
+
partial: false
|
|
305
|
+
};
|
|
306
|
+
this.thoughtText = "";
|
|
307
|
+
this.text = "";
|
|
308
|
+
}
|
|
309
|
+
yield __spreadProps(__spreadValues({}, llmResponse), {
|
|
310
|
+
content: {
|
|
311
|
+
role: llmResponse.content.role,
|
|
312
|
+
parts: nonTextParts
|
|
313
|
+
},
|
|
314
|
+
partial: false
|
|
315
|
+
});
|
|
316
|
+
return;
|
|
250
317
|
}
|
|
251
|
-
if (
|
|
252
|
-
|
|
318
|
+
if (sawTextPart) {
|
|
319
|
+
llmResponse.partial = true;
|
|
253
320
|
}
|
|
254
|
-
yield {
|
|
255
|
-
content: {
|
|
256
|
-
role: "model",
|
|
257
|
-
parts
|
|
258
|
-
},
|
|
259
|
-
usageMetadata: llmResponse.usageMetadata,
|
|
260
|
-
partial: false
|
|
261
|
-
};
|
|
262
|
-
this.thoughtText = "";
|
|
263
|
-
this.text = "";
|
|
264
321
|
}
|
|
265
322
|
yield llmResponse;
|
|
266
323
|
});
|
|
267
324
|
}
|
|
268
325
|
close() {
|
|
269
|
-
var _a, _b, _c, _d, _e, _f;
|
|
270
|
-
if (this.isProgressiveMode) {
|
|
271
|
-
this.flushTextBufferToSequence();
|
|
272
|
-
this.flushFunctionCallToSequence();
|
|
273
|
-
const finalParts = this.partsSequence;
|
|
274
|
-
if (finalParts.length === 0) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
|
|
278
|
-
const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
|
|
279
|
-
return {
|
|
280
|
-
content: {
|
|
281
|
-
role: "model",
|
|
282
|
-
parts: finalParts
|
|
283
|
-
},
|
|
284
|
-
groundingMetadata: this.groundingMetadata,
|
|
285
|
-
citationMetadata: this.citationMetadata,
|
|
286
|
-
errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
|
|
287
|
-
errorMessage: finishReason === FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
|
|
288
|
-
usageMetadata: this.usageMetadata,
|
|
289
|
-
finishReason,
|
|
290
|
-
partial: false
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
326
|
if (this.text || this.thoughtText) {
|
|
294
327
|
const parts = [];
|
|
295
328
|
if (this.thoughtText) {
|
|
@@ -298,25 +331,93 @@ class StreamingResponseAggregator {
|
|
|
298
331
|
if (this.text) {
|
|
299
332
|
parts.push({ text: this.text });
|
|
300
333
|
}
|
|
301
|
-
|
|
302
|
-
const finishReason = (_f = this.finishReason) != null ? _f : candidate == null ? void 0 : candidate.finishReason;
|
|
303
|
-
return {
|
|
304
|
-
content: {
|
|
305
|
-
role: "model",
|
|
306
|
-
parts
|
|
307
|
-
},
|
|
308
|
-
groundingMetadata: this.groundingMetadata,
|
|
309
|
-
citationMetadata: this.citationMetadata,
|
|
310
|
-
errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
|
|
311
|
-
errorMessage: finishReason === FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
|
|
312
|
-
usageMetadata: this.usageMetadata,
|
|
313
|
-
finishReason,
|
|
314
|
-
partial: false
|
|
315
|
-
};
|
|
334
|
+
return parts;
|
|
316
335
|
}
|
|
317
336
|
return void 0;
|
|
318
337
|
}
|
|
319
338
|
}
|
|
339
|
+
class StreamingResponseAggregator {
|
|
340
|
+
constructor(isProgressiveMode = isFeatureEnabled(
|
|
341
|
+
FeatureName.PROGRESSIVE_SSE_STREAMING
|
|
342
|
+
)) {
|
|
343
|
+
this.isProgressiveMode = isProgressiveMode;
|
|
344
|
+
this.lastThoughtSignature = {};
|
|
345
|
+
this.sawFunctionCall = false;
|
|
346
|
+
this.strategy = this.isProgressiveMode ? new ProgressiveStrategy() : new NonProgressiveStrategy();
|
|
347
|
+
}
|
|
348
|
+
processResponse(response) {
|
|
349
|
+
return __asyncGenerator(this, null, function* () {
|
|
350
|
+
var _a, _b;
|
|
351
|
+
const llmResponse = createLlmResponse(response);
|
|
352
|
+
const parts = (_b = (_a = llmResponse.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
353
|
+
if (parts.some((part) => part.functionCall)) {
|
|
354
|
+
this.sawFunctionCall = true;
|
|
355
|
+
}
|
|
356
|
+
if (this.sawFunctionCall && llmResponse.finishReason === FinishReason.STOP && parts.length > 0 && parts.every(isEmptyContentPart)) {
|
|
357
|
+
if (llmResponse.usageMetadata) {
|
|
358
|
+
this.usageMetadata = llmResponse.usageMetadata;
|
|
359
|
+
}
|
|
360
|
+
if (llmResponse.groundingMetadata) {
|
|
361
|
+
this.groundingMetadata = llmResponse.groundingMetadata;
|
|
362
|
+
}
|
|
363
|
+
if (llmResponse.citationMetadata) {
|
|
364
|
+
this.citationMetadata = llmResponse.citationMetadata;
|
|
365
|
+
}
|
|
366
|
+
if (llmResponse.finishReason) {
|
|
367
|
+
this.finishReason = llmResponse.finishReason;
|
|
368
|
+
}
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
this.response = response;
|
|
372
|
+
this.usageMetadata = llmResponse.usageMetadata;
|
|
373
|
+
if (llmResponse.groundingMetadata) {
|
|
374
|
+
this.groundingMetadata = llmResponse.groundingMetadata;
|
|
375
|
+
}
|
|
376
|
+
if (llmResponse.citationMetadata) {
|
|
377
|
+
this.citationMetadata = llmResponse.citationMetadata;
|
|
378
|
+
}
|
|
379
|
+
if (llmResponse.finishReason) {
|
|
380
|
+
this.finishReason = llmResponse.finishReason;
|
|
381
|
+
}
|
|
382
|
+
if (llmResponse.content && llmResponse.content.parts) {
|
|
383
|
+
for (const part of llmResponse.content.parts) {
|
|
384
|
+
if (part.thoughtSignature) {
|
|
385
|
+
this.lastThoughtSignature.value = part.thoughtSignature;
|
|
386
|
+
} else if (part.functionCall && this.lastThoughtSignature.value) {
|
|
387
|
+
part.thoughtSignature = this.lastThoughtSignature.value.toString();
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
yield* __yieldStar(this.strategy.processResponse(llmResponse));
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
close() {
|
|
395
|
+
var _a, _b, _c;
|
|
396
|
+
const finalParts = this.strategy.close();
|
|
397
|
+
if (!finalParts) {
|
|
398
|
+
return void 0;
|
|
399
|
+
}
|
|
400
|
+
const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
|
|
401
|
+
const finishReason = (_c = this.finishReason) != null ? _c : candidate == null ? void 0 : candidate.finishReason;
|
|
402
|
+
return {
|
|
403
|
+
content: {
|
|
404
|
+
role: "model",
|
|
405
|
+
parts: finalParts
|
|
406
|
+
},
|
|
407
|
+
groundingMetadata: this.groundingMetadata,
|
|
408
|
+
citationMetadata: this.citationMetadata,
|
|
409
|
+
errorCode: finishReason === FinishReason.STOP ? void 0 : finishReason,
|
|
410
|
+
errorMessage: finishReason === FinishReason.STOP ? void 0 : candidate == null ? void 0 : candidate.finishMessage,
|
|
411
|
+
usageMetadata: this.usageMetadata,
|
|
412
|
+
finishReason,
|
|
413
|
+
partial: false
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
function isEmptyContentPart(part) {
|
|
418
|
+
return !part.functionCall && !part.functionResponse && !part.fileData && !part.inlineData && !part.executableCode && !part.codeExecutionResult && (!part.text || part.text === "");
|
|
419
|
+
}
|
|
320
420
|
export {
|
|
321
|
-
StreamingResponseAggregator
|
|
421
|
+
StreamingResponseAggregator,
|
|
422
|
+
isEmptyContentPart
|
|
322
423
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
import { getBooleanEnvVar } from "./env_aware_utils.js";
|
|
9
|
+
function getExpressModeApiKey(project, location, expressModeApiKey) {
|
|
10
|
+
if ((project || location) && expressModeApiKey) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"Cannot specify project or location and expressModeApiKey. Either use project and location, or just the expressModeApiKey."
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
if (getBooleanEnvVar("GOOGLE_GENAI_USE_VERTEXAI")) {
|
|
16
|
+
return expressModeApiKey || process.env.GOOGLE_API_KEY;
|
|
17
|
+
}
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
getExpressModeApiKey
|
|
22
|
+
};
|
package/dist/web/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@softactivate/adk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Google ADK JS",
|
|
5
5
|
"author": "Google",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"@google-cloud/opentelemetry-cloud-monitoring-exporter": "^0.21.0",
|
|
45
45
|
"@google-cloud/opentelemetry-cloud-trace-exporter": "^3.0.0",
|
|
46
46
|
"@google-cloud/storage": "^7.17.1",
|
|
47
|
+
"@google-cloud/vertexai": "^1.12.0",
|
|
47
48
|
"@google/genai": "^1.37.0",
|
|
48
49
|
"@mikro-orm/core": "^6.6.10",
|
|
49
50
|
"@mikro-orm/reflection": "^6.6.6",
|