@google/adk 1.2.0 → 1.3.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/base_agent.js +19 -1
- package/dist/cjs/agents/instructions.js +81 -33
- package/dist/cjs/agents/invocation_context.js +0 -1
- package/dist/cjs/agents/llm_agent.js +52 -5
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
- package/dist/cjs/agents/processors/content_request_processor.js +7 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/cjs/auth/auth_preprocessor.js +12 -10
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +7 -7
- package/dist/cjs/common.js +39 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
- package/dist/cjs/context/token_based_context_compactor.js +1 -1
- package/dist/cjs/events/event.js +1 -1
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/cjs/models/gemini_llm_connection.js +62 -19
- package/dist/cjs/models/google_llm.js +26 -8
- package/dist/cjs/plugins/security_plugin.js +16 -0
- package/dist/cjs/sessions/base_session_service.js +13 -2
- package/dist/cjs/sessions/database_session_service.js +2 -2
- package/dist/cjs/sessions/db/schema.js +45 -10
- package/dist/cjs/sessions/in_memory_session_service.js +2 -1
- package/dist/cjs/sessions/vertex_ai_session_service.js +2 -1
- package/dist/cjs/skills/gcp_skill_registry.js +104 -0
- package/dist/cjs/skills/loader.js +65 -0
- package/dist/cjs/skills/skill_registry.js +27 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
- package/dist/cjs/tools/skill/skill_toolset.js +40 -5
- package/dist/cjs/utils/async_queue.js +88 -0
- package/dist/cjs/utils/case_utils.js +53 -0
- package/dist/cjs/utils/env_aware_utils.js +4 -0
- package/dist/cjs/utils/live_connection_utils.js +284 -0
- package/dist/cjs/utils/model_name.js +9 -0
- package/dist/cjs/utils/streaming_utils.js +9 -8
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +19 -1
- package/dist/esm/agents/instructions.js +81 -33
- package/dist/esm/agents/invocation_context.js +0 -1
- package/dist/esm/agents/llm_agent.js +53 -5
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/esm/agents/processors/content_processor_utils.js +35 -23
- package/dist/esm/agents/processors/content_request_processor.js +7 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/esm/auth/auth_preprocessor.js +12 -10
- package/dist/esm/auth/oauth2/oauth2_discovery.js +1 -1
- package/dist/esm/code_executors/code_executor_context.js +7 -7
- package/dist/esm/common.js +33 -1
- package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
- package/dist/esm/context/token_based_context_compactor.js +1 -1
- package/dist/esm/events/event.js +1 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/esm/models/gemini_llm_connection.js +62 -19
- package/dist/esm/models/google_llm.js +26 -8
- package/dist/esm/plugins/security_plugin.js +16 -0
- package/dist/esm/sessions/base_session_service.js +11 -1
- package/dist/esm/sessions/database_session_service.js +2 -2
- package/dist/esm/sessions/db/schema.js +44 -10
- package/dist/esm/sessions/in_memory_session_service.js +4 -2
- package/dist/esm/sessions/vertex_ai_session_service.js +4 -2
- package/dist/esm/skills/gcp_skill_registry.js +78 -0
- package/dist/esm/skills/loader.js +64 -0
- package/dist/esm/skills/skill_registry.js +7 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/esm/tools/skill/load_skill_tool.js +12 -1
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/esm/tools/skill/search_skills_tool.js +82 -0
- package/dist/esm/tools/skill/skill_toolset.js +40 -5
- package/dist/esm/utils/async_queue.js +60 -0
- package/dist/esm/utils/case_utils.js +25 -0
- package/dist/esm/utils/env_aware_utils.js +4 -0
- package/dist/esm/utils/live_connection_utils.js +256 -0
- package/dist/esm/utils/model_name.js +8 -0
- package/dist/esm/utils/streaming_utils.js +9 -8
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
- package/dist/types/a2a/event_converter_utils.d.ts +14 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
- package/dist/types/a2a/part_converter_utils.d.ts +51 -6
- package/dist/types/agents/invocation_context.d.ts +0 -9
- package/dist/types/agents/llm_agent.d.ts +14 -0
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
- package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
- package/dist/types/common.d.ts +15 -1
- package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
- package/dist/types/events/event_actions.d.ts +1 -2
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
- package/dist/types/models/base_llm_connection.d.ts +10 -0
- package/dist/types/models/gemini_llm_connection.d.ts +15 -4
- package/dist/types/models/llm_response.d.ts +10 -1
- package/dist/types/plugins/security_plugin.d.ts +30 -0
- package/dist/types/sessions/base_session_service.d.ts +4 -0
- package/dist/types/sessions/db/schema.d.ts +1 -0
- package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
- package/dist/types/skills/loader.d.ts +7 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/skills/skill_registry.d.ts +29 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
- package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
- package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
- package/dist/types/utils/async_queue.d.ts +18 -0
- package/dist/types/utils/case_utils.d.ts +12 -0
- package/dist/types/utils/live_connection_utils.d.ts +30 -0
- package/dist/types/utils/model_name.d.ts +7 -0
- package/dist/types/utils/streaming_utils.d.ts +0 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +31 -1
- package/dist/web/agents/instructions.js +81 -33
- package/dist/web/agents/invocation_context.js +0 -1
- package/dist/web/agents/llm_agent.js +53 -5
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/web/agents/processors/content_processor_utils.js +53 -23
- package/dist/web/agents/processors/content_request_processor.js +7 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/web/auth/auth_preprocessor.js +12 -10
- package/dist/web/auth/oauth2/oauth2_discovery.js +1 -1
- package/dist/web/code_executors/code_executor_context.js +7 -7
- package/dist/web/common.js +33 -1
- package/dist/web/context/summarizers/llm_summarizer.js +11 -0
- package/dist/web/context/token_based_context_compactor.js +1 -1
- package/dist/web/events/event.js +1 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/web/models/gemini_llm_connection.js +75 -19
- package/dist/web/models/google_llm.js +26 -8
- package/dist/web/plugins/security_plugin.js +16 -0
- package/dist/web/sessions/base_session_service.js +11 -1
- package/dist/web/sessions/database_session_service.js +2 -2
- package/dist/web/sessions/db/schema.js +44 -10
- package/dist/web/sessions/in_memory_session_service.js +4 -2
- package/dist/web/sessions/vertex_ai_session_service.js +4 -2
- package/dist/web/skills/gcp_skill_registry.js +78 -0
- package/dist/web/skills/loader.js +64 -0
- package/dist/web/skills/skill_registry.js +7 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/web/tools/skill/load_skill_tool.js +12 -1
- package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/web/tools/skill/search_skills_tool.js +82 -0
- package/dist/web/tools/skill/skill_toolset.js +40 -5
- package/dist/web/utils/async_queue.js +60 -0
- package/dist/web/utils/case_utils.js +25 -0
- package/dist/web/utils/env_aware_utils.js +4 -0
- package/dist/web/utils/live_connection_utils.js +254 -0
- package/dist/web/utils/model_name.js +8 -0
- package/dist/web/utils/streaming_utils.js +9 -8
- package/dist/web/version.js +1 -1
- package/package.json +3 -1
|
@@ -42,6 +42,10 @@ function isBrowser() {
|
|
|
42
42
|
}
|
|
43
43
|
const UUID_MASK = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
|
44
44
|
function randomUUID() {
|
|
45
|
+
var _a;
|
|
46
|
+
if ((_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) {
|
|
47
|
+
return globalThis.crypto.randomUUID();
|
|
48
|
+
}
|
|
45
49
|
let uuid = "";
|
|
46
50
|
for (let i = 0; i < UUID_MASK.length; i++) {
|
|
47
51
|
const randomValue = Math.random() * 16 | 0;
|
|
@@ -0,0 +1,284 @@
|
|
|
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 live_connection_utils_exports = {};
|
|
26
|
+
__export(live_connection_utils_exports, {
|
|
27
|
+
LiveResponseAggregator: () => LiveResponseAggregator
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(live_connection_utils_exports);
|
|
30
|
+
var import_model_name = require("./model_name.js");
|
|
31
|
+
/**
|
|
32
|
+
* @license
|
|
33
|
+
* Copyright 2026 Google LLC
|
|
34
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
35
|
+
*/
|
|
36
|
+
class LiveResponseAggregator {
|
|
37
|
+
constructor(modelVersion) {
|
|
38
|
+
this.modelVersion = modelVersion;
|
|
39
|
+
this.text = "";
|
|
40
|
+
this.isThought = false;
|
|
41
|
+
this.toolCallParts = [];
|
|
42
|
+
this.pendingGroundingMetadata = void 0;
|
|
43
|
+
this.inputTranscriptionText = "";
|
|
44
|
+
this.outputTranscriptionText = "";
|
|
45
|
+
}
|
|
46
|
+
*processMessage(message) {
|
|
47
|
+
if (message.usageMetadata) {
|
|
48
|
+
yield {
|
|
49
|
+
usageMetadata: message.usageMetadata,
|
|
50
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
if (message.serverContent) {
|
|
54
|
+
const serverContent = message.serverContent;
|
|
55
|
+
const content = serverContent.modelTurn;
|
|
56
|
+
if (serverContent.groundingMetadata) {
|
|
57
|
+
this.pendingGroundingMetadata = serverContent.groundingMetadata;
|
|
58
|
+
}
|
|
59
|
+
if (!(content && content.parts) && serverContent.groundingMetadata && !serverContent.turnComplete) {
|
|
60
|
+
yield {
|
|
61
|
+
groundingMetadata: serverContent.groundingMetadata,
|
|
62
|
+
...serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {},
|
|
63
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (content && content.parts) {
|
|
67
|
+
const llmResponse = {
|
|
68
|
+
content,
|
|
69
|
+
...serverContent.interrupted !== void 0 ? { interrupted: serverContent.interrupted } : {},
|
|
70
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
71
|
+
};
|
|
72
|
+
if (!serverContent.turnComplete && serverContent.groundingMetadata) {
|
|
73
|
+
llmResponse.groundingMetadata = serverContent.groundingMetadata;
|
|
74
|
+
}
|
|
75
|
+
const hasInlineData = content.parts.some((p) => p.inlineData);
|
|
76
|
+
for (const part of content.parts) {
|
|
77
|
+
if (part.text) {
|
|
78
|
+
const currentIsThought = !!part.thought;
|
|
79
|
+
if (this.text && currentIsThought !== this.isThought) {
|
|
80
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
81
|
+
this.text = "";
|
|
82
|
+
this.isThought = false;
|
|
83
|
+
}
|
|
84
|
+
this.text += part.text;
|
|
85
|
+
this.isThought = currentIsThought;
|
|
86
|
+
llmResponse.partial = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (this.text && !content.parts.some((p) => p.text) && !hasInlineData) {
|
|
90
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
91
|
+
this.text = "";
|
|
92
|
+
this.isThought = false;
|
|
93
|
+
}
|
|
94
|
+
yield llmResponse;
|
|
95
|
+
}
|
|
96
|
+
if (serverContent.inputTranscription) {
|
|
97
|
+
if (serverContent.inputTranscription.text) {
|
|
98
|
+
this.inputTranscriptionText += serverContent.inputTranscription.text;
|
|
99
|
+
yield {
|
|
100
|
+
inputTranscription: {
|
|
101
|
+
text: serverContent.inputTranscription.text,
|
|
102
|
+
finished: false
|
|
103
|
+
},
|
|
104
|
+
partial: true,
|
|
105
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
if (serverContent.inputTranscription.finished) {
|
|
109
|
+
yield {
|
|
110
|
+
inputTranscription: {
|
|
111
|
+
text: this.inputTranscriptionText,
|
|
112
|
+
finished: true
|
|
113
|
+
},
|
|
114
|
+
partial: false,
|
|
115
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
116
|
+
};
|
|
117
|
+
this.inputTranscriptionText = "";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (serverContent.outputTranscription) {
|
|
121
|
+
if (serverContent.outputTranscription.text) {
|
|
122
|
+
this.outputTranscriptionText += serverContent.outputTranscription.text;
|
|
123
|
+
yield {
|
|
124
|
+
outputTranscription: {
|
|
125
|
+
text: serverContent.outputTranscription.text,
|
|
126
|
+
finished: false
|
|
127
|
+
},
|
|
128
|
+
partial: true,
|
|
129
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (serverContent.outputTranscription.finished) {
|
|
133
|
+
yield {
|
|
134
|
+
outputTranscription: {
|
|
135
|
+
text: this.outputTranscriptionText,
|
|
136
|
+
finished: true
|
|
137
|
+
},
|
|
138
|
+
partial: false,
|
|
139
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
140
|
+
};
|
|
141
|
+
this.outputTranscriptionText = "";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (serverContent.interrupted || serverContent.turnComplete || serverContent.generationComplete) {
|
|
145
|
+
if (this.inputTranscriptionText) {
|
|
146
|
+
yield {
|
|
147
|
+
inputTranscription: {
|
|
148
|
+
text: this.inputTranscriptionText,
|
|
149
|
+
finished: true
|
|
150
|
+
},
|
|
151
|
+
partial: false,
|
|
152
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
153
|
+
};
|
|
154
|
+
this.inputTranscriptionText = "";
|
|
155
|
+
}
|
|
156
|
+
if (this.outputTranscriptionText) {
|
|
157
|
+
yield {
|
|
158
|
+
outputTranscription: {
|
|
159
|
+
text: this.outputTranscriptionText,
|
|
160
|
+
finished: true
|
|
161
|
+
},
|
|
162
|
+
partial: false,
|
|
163
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
164
|
+
};
|
|
165
|
+
this.outputTranscriptionText = "";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (serverContent.turnComplete) {
|
|
169
|
+
let gMetadataToYield = this.pendingGroundingMetadata;
|
|
170
|
+
if (this.text) {
|
|
171
|
+
yield this.buildFullTextResponse(
|
|
172
|
+
this.text,
|
|
173
|
+
this.isThought,
|
|
174
|
+
gMetadataToYield
|
|
175
|
+
);
|
|
176
|
+
this.text = "";
|
|
177
|
+
this.isThought = false;
|
|
178
|
+
gMetadataToYield = void 0;
|
|
179
|
+
}
|
|
180
|
+
if (this.toolCallParts.length > 0) {
|
|
181
|
+
yield {
|
|
182
|
+
content: { role: "model", parts: this.toolCallParts },
|
|
183
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
184
|
+
};
|
|
185
|
+
this.toolCallParts = [];
|
|
186
|
+
}
|
|
187
|
+
const finalResponse = {
|
|
188
|
+
turnComplete: true,
|
|
189
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
190
|
+
};
|
|
191
|
+
if (serverContent.interrupted !== void 0) {
|
|
192
|
+
finalResponse.interrupted = serverContent.interrupted;
|
|
193
|
+
}
|
|
194
|
+
const finalGrounding = serverContent.groundingMetadata || gMetadataToYield;
|
|
195
|
+
if (finalGrounding !== void 0 && finalGrounding !== null) {
|
|
196
|
+
finalResponse.groundingMetadata = finalGrounding;
|
|
197
|
+
}
|
|
198
|
+
yield finalResponse;
|
|
199
|
+
}
|
|
200
|
+
if (serverContent.interrupted) {
|
|
201
|
+
if (this.text) {
|
|
202
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
203
|
+
this.text = "";
|
|
204
|
+
this.isThought = false;
|
|
205
|
+
} else {
|
|
206
|
+
yield {
|
|
207
|
+
interrupted: serverContent.interrupted,
|
|
208
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (message.toolCall) {
|
|
214
|
+
if (this.text) {
|
|
215
|
+
yield this.buildFullTextResponse(this.text, this.isThought);
|
|
216
|
+
this.text = "";
|
|
217
|
+
this.isThought = false;
|
|
218
|
+
}
|
|
219
|
+
if (message.toolCall.functionCalls) {
|
|
220
|
+
this.toolCallParts.push(
|
|
221
|
+
...message.toolCall.functionCalls.map((fc) => ({
|
|
222
|
+
functionCall: fc
|
|
223
|
+
}))
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
const isGemini3x = (0, import_model_name.isGemini3xFlashLive)(this.modelVersion);
|
|
227
|
+
if (isGemini3x && this.toolCallParts.length > 0) {
|
|
228
|
+
yield {
|
|
229
|
+
content: { role: "model", parts: this.toolCallParts },
|
|
230
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
231
|
+
};
|
|
232
|
+
this.toolCallParts = [];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (message.sessionResumptionUpdate) {
|
|
236
|
+
yield {
|
|
237
|
+
liveSessionResumptionUpdate: message.sessionResumptionUpdate,
|
|
238
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
if (message.goAway) {
|
|
242
|
+
yield {
|
|
243
|
+
goAway: message.goAway,
|
|
244
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Flushes any remaining aggregated components when the connection is closed.
|
|
250
|
+
*/
|
|
251
|
+
*close() {
|
|
252
|
+
if (this.toolCallParts.length > 0) {
|
|
253
|
+
yield {
|
|
254
|
+
content: { role: "model", parts: this.toolCallParts },
|
|
255
|
+
...this.modelVersion ? { modelVersion: this.modelVersion } : {}
|
|
256
|
+
};
|
|
257
|
+
this.toolCallParts = [];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
buildFullTextResponse(text, isThought, groundingMetadata) {
|
|
261
|
+
const part = { text };
|
|
262
|
+
if (isThought) {
|
|
263
|
+
part.thought = true;
|
|
264
|
+
}
|
|
265
|
+
const response = {
|
|
266
|
+
content: {
|
|
267
|
+
role: "model",
|
|
268
|
+
parts: [part]
|
|
269
|
+
},
|
|
270
|
+
partial: false
|
|
271
|
+
};
|
|
272
|
+
if (groundingMetadata !== void 0 && groundingMetadata !== null) {
|
|
273
|
+
response.groundingMetadata = groundingMetadata;
|
|
274
|
+
}
|
|
275
|
+
if (this.modelVersion) {
|
|
276
|
+
response.modelVersion = this.modelVersion;
|
|
277
|
+
}
|
|
278
|
+
return response;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
282
|
+
0 && (module.exports = {
|
|
283
|
+
LiveResponseAggregator
|
|
284
|
+
});
|
|
@@ -27,6 +27,7 @@ __export(model_name_exports, {
|
|
|
27
27
|
extractModelName: () => extractModelName,
|
|
28
28
|
isGemini1Model: () => isGemini1Model,
|
|
29
29
|
isGemini2OrAbove: () => isGemini2OrAbove,
|
|
30
|
+
isGemini3xFlashLive: () => isGemini3xFlashLive,
|
|
30
31
|
isGeminiModel: () => isGeminiModel,
|
|
31
32
|
isGeminiModelIdCheckDisabled: () => isGeminiModelIdCheckDisabled
|
|
32
33
|
});
|
|
@@ -77,6 +78,13 @@ function isGemini2OrAbove(modelString) {
|
|
|
77
78
|
const parsedVersion = parseVersion(versionString);
|
|
78
79
|
return parsedVersion.valid && parsedVersion.major >= 2;
|
|
79
80
|
}
|
|
81
|
+
function isGemini3xFlashLive(modelString) {
|
|
82
|
+
if (!modelString) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
const modelName = extractModelName(modelString);
|
|
86
|
+
return modelName.startsWith("gemini-3.") && modelName.includes("-flash-live");
|
|
87
|
+
}
|
|
80
88
|
function isGeminiModelIdCheckDisabled() {
|
|
81
89
|
return (0, import_env_aware_utils.getBooleanEnvVar)("ADK_DISABLE_GEMINI_MODEL_ID_CHECK");
|
|
82
90
|
}
|
|
@@ -85,6 +93,7 @@ function isGeminiModelIdCheckDisabled() {
|
|
|
85
93
|
extractModelName,
|
|
86
94
|
isGemini1Model,
|
|
87
95
|
isGemini2OrAbove,
|
|
96
|
+
isGemini3xFlashLive,
|
|
88
97
|
isGeminiModel,
|
|
89
98
|
isGeminiModelIdCheckDisabled
|
|
90
99
|
});
|
|
@@ -38,6 +38,7 @@ var import_llm_response = require("../models/llm_response.js");
|
|
|
38
38
|
* Copyright 2026 Google LLC
|
|
39
39
|
* SPDX-License-Identifier: Apache-2.0
|
|
40
40
|
*/
|
|
41
|
+
const UNSAFE_PROPERTY_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
|
|
41
42
|
class ProgressiveStrategy {
|
|
42
43
|
constructor() {
|
|
43
44
|
this.partsSequence = [];
|
|
@@ -104,10 +105,13 @@ class ProgressiveStrategy {
|
|
|
104
105
|
const pathParts = import_jsonpath_plus.JSONPath.toPathArray(jsonPath).filter(
|
|
105
106
|
(p) => p !== "$" && p !== "$["
|
|
106
107
|
);
|
|
108
|
+
if (pathParts.some((part) => UNSAFE_PROPERTY_KEYS.has(String(part)))) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
107
111
|
let current = this.currentFcArgs;
|
|
108
112
|
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
109
113
|
const part = pathParts[i];
|
|
110
|
-
if (!(part
|
|
114
|
+
if (!Object.prototype.hasOwnProperty.call(current, part)) {
|
|
111
115
|
current[part] = {};
|
|
112
116
|
}
|
|
113
117
|
current = current[part];
|
|
@@ -299,17 +303,13 @@ class StreamingResponseAggregator {
|
|
|
299
303
|
)) {
|
|
300
304
|
this.isProgressiveMode = isProgressiveMode;
|
|
301
305
|
this.lastThoughtSignature = {};
|
|
302
|
-
this.sawFunctionCall = false;
|
|
303
306
|
this.strategy = this.isProgressiveMode ? new ProgressiveStrategy() : new NonProgressiveStrategy();
|
|
304
307
|
}
|
|
305
308
|
async *processResponse(response) {
|
|
306
309
|
var _a, _b;
|
|
307
310
|
const llmResponse = (0, import_llm_response.createLlmResponse)(response);
|
|
308
311
|
const parts = (_b = (_a = llmResponse.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
|
309
|
-
if (parts.
|
|
310
|
-
this.sawFunctionCall = true;
|
|
311
|
-
}
|
|
312
|
-
if (this.sawFunctionCall && llmResponse.finishReason === import_genai.FinishReason.STOP && parts.length > 0 && parts.every(isEmptyContentPart)) {
|
|
312
|
+
if (parts.every(isEmptyContentPart) && (llmResponse.finishReason === void 0 || llmResponse.finishReason === import_genai.FinishReason.STOP)) {
|
|
313
313
|
if (llmResponse.usageMetadata) {
|
|
314
314
|
this.usageMetadata = llmResponse.usageMetadata;
|
|
315
315
|
}
|
|
@@ -349,7 +349,8 @@ class StreamingResponseAggregator {
|
|
|
349
349
|
close() {
|
|
350
350
|
var _a, _b, _c;
|
|
351
351
|
const finalParts = this.strategy.close();
|
|
352
|
-
|
|
352
|
+
const hasMetadata = this.usageMetadata !== void 0 || this.groundingMetadata !== void 0 || this.citationMetadata !== void 0;
|
|
353
|
+
if (!finalParts && !hasMetadata) {
|
|
353
354
|
return void 0;
|
|
354
355
|
}
|
|
355
356
|
const candidate = (_b = (_a = this.response) == null ? void 0 : _a.candidates) == null ? void 0 : _b[0];
|
|
@@ -357,7 +358,7 @@ class StreamingResponseAggregator {
|
|
|
357
358
|
return {
|
|
358
359
|
content: {
|
|
359
360
|
role: "model",
|
|
360
|
-
parts: finalParts
|
|
361
|
+
parts: finalParts != null ? finalParts : []
|
|
361
362
|
},
|
|
362
363
|
groundingMetadata: this.groundingMetadata,
|
|
363
364
|
citationMetadata: this.citationMetadata,
|
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.3.0";
|
|
36
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
37
37
|
0 && (module.exports = {
|
|
38
38
|
version
|
|
@@ -99,9 +99,27 @@ class BaseAgent {
|
|
|
99
99
|
ctx,
|
|
100
100
|
this,
|
|
101
101
|
async function* () {
|
|
102
|
+
var _a2, _b;
|
|
103
|
+
const context2 = this.createInvocationContext(parentContext);
|
|
104
|
+
const beforeAgentCallbackEvent = await this.handleBeforeAgentCallback(context2);
|
|
105
|
+
if (beforeAgentCallbackEvent) {
|
|
106
|
+
yield beforeAgentCallbackEvent;
|
|
107
|
+
}
|
|
108
|
+
if (context2.endInvocation || ((_a2 = parentContext.abortSignal) == null ? void 0 : _a2.aborted)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
for await (const event of this.runLiveImpl(context2)) {
|
|
112
|
+
yield event;
|
|
113
|
+
}
|
|
114
|
+
if (context2.endInvocation || ((_b = parentContext.abortSignal) == null ? void 0 : _b.aborted)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const afterAgentCallbackEvent = await this.handleAfterAgentCallback(context2);
|
|
118
|
+
if (afterAgentCallbackEvent) {
|
|
119
|
+
yield afterAgentCallbackEvent;
|
|
120
|
+
}
|
|
102
121
|
}
|
|
103
122
|
);
|
|
104
|
-
throw new Error("Live mode is not implemented yet.");
|
|
105
123
|
} finally {
|
|
106
124
|
span.end();
|
|
107
125
|
}
|
|
@@ -6,50 +6,98 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
8
|
import { State } from "../sessions/state.js";
|
|
9
|
-
|
|
9
|
+
const ARTIFACT_PREFIX = "artifact.";
|
|
10
|
+
async function resolveKey(key, isOptional, rawMatch, readonlyContext) {
|
|
10
11
|
const invocationContext = readonlyContext.invocationContext;
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
if (key.startsWith(ARTIFACT_PREFIX)) {
|
|
13
|
+
const fileName = key.substring(ARTIFACT_PREFIX.length);
|
|
14
|
+
if (invocationContext.artifactService === void 0) {
|
|
15
|
+
throw new Error("Artifact service is not initialized.");
|
|
16
|
+
}
|
|
17
|
+
const artifact = await invocationContext.artifactService.loadArtifact({
|
|
18
|
+
appName: invocationContext.session.appName,
|
|
19
|
+
userId: invocationContext.session.userId,
|
|
20
|
+
sessionId: invocationContext.session.id,
|
|
21
|
+
filename: fileName
|
|
22
|
+
});
|
|
23
|
+
if (!artifact) {
|
|
24
|
+
if (isOptional) {
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Artifact ${fileName} not found.`);
|
|
28
|
+
}
|
|
29
|
+
return String(artifact);
|
|
30
|
+
}
|
|
31
|
+
if (!isValidStateName(key)) {
|
|
32
|
+
return rawMatch;
|
|
33
|
+
}
|
|
34
|
+
if (key in invocationContext.session.state) {
|
|
35
|
+
return String(invocationContext.session.state[key]);
|
|
36
|
+
}
|
|
37
|
+
if (isOptional) {
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`Context variable not found: \`${key}\`.`);
|
|
41
|
+
}
|
|
42
|
+
async function injectSessionState(template, readonlyContext) {
|
|
43
|
+
const pattern = /\{+[^{}]*}+/g;
|
|
44
|
+
const matches = Array.from(template.matchAll(pattern));
|
|
45
|
+
if (matches.length === 0) {
|
|
46
|
+
return template;
|
|
47
|
+
}
|
|
48
|
+
const parsedMatches = matches.map((match) => {
|
|
49
|
+
const raw = match[0];
|
|
50
|
+
let key = raw.replace(/^\{+/, "").replace(/\}+$/, "").trim();
|
|
13
51
|
const isOptional = key.endsWith("?");
|
|
14
52
|
if (isOptional) {
|
|
15
53
|
key = key.slice(0, -1);
|
|
16
54
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
55
|
+
const isValid = key.startsWith(ARTIFACT_PREFIX) || isValidStateName(key);
|
|
56
|
+
return {
|
|
57
|
+
raw,
|
|
58
|
+
key,
|
|
59
|
+
isOptional,
|
|
60
|
+
isValid,
|
|
61
|
+
index: match.index
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
const uniqueKeys = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const pm of parsedMatches) {
|
|
66
|
+
if (!pm.isValid) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const existing = uniqueKeys.get(pm.key);
|
|
70
|
+
if (existing) {
|
|
71
|
+
if (existing.isOptional && !pm.isOptional) {
|
|
72
|
+
existing.isOptional = false;
|
|
21
73
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
74
|
+
} else {
|
|
75
|
+
uniqueKeys.set(pm.key, {
|
|
76
|
+
key: pm.key,
|
|
77
|
+
isOptional: pm.isOptional,
|
|
78
|
+
raw: pm.raw
|
|
27
79
|
});
|
|
28
|
-
if (!artifact) {
|
|
29
|
-
throw new Error(`Artifact ${fileName} not found.`);
|
|
30
|
-
}
|
|
31
|
-
return String(artifact);
|
|
32
|
-
}
|
|
33
|
-
if (!isValidStateName(key)) {
|
|
34
|
-
return match[0];
|
|
35
|
-
}
|
|
36
|
-
if (key in invocationContext.session.state) {
|
|
37
|
-
return String(invocationContext.session.state[key]);
|
|
38
80
|
}
|
|
39
|
-
if (isOptional) {
|
|
40
|
-
return "";
|
|
41
|
-
}
|
|
42
|
-
throw new Error(`Context variable not found: \`${key}\`.`);
|
|
43
81
|
}
|
|
44
|
-
const
|
|
82
|
+
const resolutions = /* @__PURE__ */ new Map();
|
|
83
|
+
for (const info of uniqueKeys.values()) {
|
|
84
|
+
resolutions.set(
|
|
85
|
+
info.key,
|
|
86
|
+
resolveKey(info.key, info.isOptional, info.raw, readonlyContext)
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
await Promise.all(resolutions.values());
|
|
45
90
|
const result = [];
|
|
46
91
|
let lastEnd = 0;
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
92
|
+
for (const pm of parsedMatches) {
|
|
93
|
+
result.push(template.slice(lastEnd, pm.index));
|
|
94
|
+
if (pm.isValid) {
|
|
95
|
+
const replacement = await resolutions.get(pm.key);
|
|
96
|
+
result.push(replacement);
|
|
97
|
+
} else {
|
|
98
|
+
result.push(pm.raw);
|
|
99
|
+
}
|
|
100
|
+
lastEnd = pm.index + pm.raw.length;
|
|
53
101
|
}
|
|
54
102
|
result.push(template.slice(lastEnd));
|
|
55
103
|
return result.join("");
|
|
@@ -46,7 +46,6 @@ class InvocationContext {
|
|
|
46
46
|
this.endInvocation = params.endInvocation || false;
|
|
47
47
|
this.transcriptionCache = params.transcriptionCache;
|
|
48
48
|
this.runConfig = params.runConfig;
|
|
49
|
-
this.liveRequestQueue = params.liveRequestQueue;
|
|
50
49
|
this.activeStreamingTools = params.activeStreamingTools;
|
|
51
50
|
this.pluginManager = params.pluginManager;
|
|
52
51
|
this.abortSignal = params.abortSignal;
|