@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
|
@@ -16,15 +16,20 @@ var __asyncGenerator = (__this, __arguments, generator) => {
|
|
|
16
16
|
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
17
17
|
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
18
18
|
};
|
|
19
|
+
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
19
20
|
/**
|
|
20
21
|
* @license
|
|
21
|
-
* Copyright
|
|
22
|
+
* Copyright 2026 Google LLC
|
|
22
23
|
* SPDX-License-Identifier: Apache-2.0
|
|
23
24
|
*/
|
|
25
|
+
import { LiveResponseAggregator } from "../utils/live_connection_utils.js";
|
|
24
26
|
import { logger } from "../utils/logger.js";
|
|
27
|
+
import { isGemini3xFlashLive } from "../utils/model_name.js";
|
|
25
28
|
class GeminiLlmConnection {
|
|
26
|
-
constructor(geminiSession) {
|
|
29
|
+
constructor(geminiSession, modelVersion, messageQueue) {
|
|
27
30
|
this.geminiSession = geminiSession;
|
|
31
|
+
this.modelVersion = modelVersion;
|
|
32
|
+
this.messageQueue = messageQueue;
|
|
28
33
|
}
|
|
29
34
|
/**
|
|
30
35
|
* Sends the conversation history to the gemini model.
|
|
@@ -43,9 +48,10 @@ class GeminiLlmConnection {
|
|
|
43
48
|
}
|
|
44
49
|
);
|
|
45
50
|
if (contents.length > 0) {
|
|
51
|
+
const isGemini3x = isGemini3xFlashLive(this.modelVersion);
|
|
46
52
|
this.geminiSession.sendClientContent({
|
|
47
53
|
turns: contents,
|
|
48
|
-
turnComplete: contents[contents.length - 1].role === "user"
|
|
54
|
+
turnComplete: isGemini3x ? true : contents[contents.length - 1].role === "user"
|
|
49
55
|
});
|
|
50
56
|
} else {
|
|
51
57
|
logger.info("no content is sent");
|
|
@@ -72,10 +78,16 @@ class GeminiLlmConnection {
|
|
|
72
78
|
});
|
|
73
79
|
} else {
|
|
74
80
|
logger.debug("Sending LLM new content", content);
|
|
75
|
-
this.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
const isGemini3x = isGemini3xFlashLive(this.modelVersion);
|
|
82
|
+
if (isGemini3x && content.parts.length === 1 && content.parts[0].text) {
|
|
83
|
+
logger.debug("Using sendRealtimeInput for Gemini 3.x text input");
|
|
84
|
+
this.geminiSession.sendRealtimeInput({ text: content.parts[0].text });
|
|
85
|
+
} else {
|
|
86
|
+
this.geminiSession.sendClientContent({
|
|
87
|
+
turns: [content],
|
|
88
|
+
turnComplete: true
|
|
89
|
+
});
|
|
90
|
+
}
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
93
|
/**
|
|
@@ -84,8 +96,36 @@ class GeminiLlmConnection {
|
|
|
84
96
|
* @param blob The blob to send to the model.
|
|
85
97
|
*/
|
|
86
98
|
async sendRealtime(blob) {
|
|
99
|
+
var _a, _b, _c;
|
|
87
100
|
logger.debug("Sending LLM Blob:", blob);
|
|
88
|
-
|
|
101
|
+
const isGemini3x = isGemini3xFlashLive(this.modelVersion);
|
|
102
|
+
const isNativeAudio = (_a = this.modelVersion) == null ? void 0 : _a.includes("native-audio");
|
|
103
|
+
if (isGemini3x || isNativeAudio) {
|
|
104
|
+
if ((_b = blob.mimeType) == null ? void 0 : _b.startsWith("audio/")) {
|
|
105
|
+
this.geminiSession.sendRealtimeInput({ audio: blob });
|
|
106
|
+
} else if ((_c = blob.mimeType) == null ? void 0 : _c.startsWith("image/")) {
|
|
107
|
+
this.geminiSession.sendRealtimeInput({ video: blob });
|
|
108
|
+
} else {
|
|
109
|
+
logger.warn(
|
|
110
|
+
"Blob not sent. Unknown or empty mime type for sendRealtimeInput:",
|
|
111
|
+
blob.mimeType
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
this.geminiSession.sendRealtimeInput({ media: blob });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Sends an activity start signal to the model.
|
|
120
|
+
*/
|
|
121
|
+
async sendActivityStart() {
|
|
122
|
+
this.geminiSession.sendRealtimeInput({ activityStart: {} });
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Sends an activity end signal to the model.
|
|
126
|
+
*/
|
|
127
|
+
async sendActivityEnd() {
|
|
128
|
+
this.geminiSession.sendRealtimeInput({ activityEnd: {} });
|
|
89
129
|
}
|
|
90
130
|
/**
|
|
91
131
|
* Builds a full text response.
|
|
@@ -94,21 +134,37 @@ class GeminiLlmConnection {
|
|
|
94
134
|
* partial.
|
|
95
135
|
*
|
|
96
136
|
* @param text The text to be included in the response.
|
|
137
|
+
* @param isThought Whether the text is a thought.
|
|
138
|
+
* @param groundingMetadata The grounding metadata to include.
|
|
97
139
|
* @returns An LlmResponse containing the full text.
|
|
98
140
|
*/
|
|
99
|
-
buildFullTextResponse(text) {
|
|
100
|
-
return {
|
|
101
|
-
content: {
|
|
102
|
-
role: "model",
|
|
103
|
-
parts: [{ text }]
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
// TODO(b/425992518): GenAI SDK inconsistent API, missing methods.
|
|
108
|
-
// eslint-disable-next-line require-yield
|
|
109
141
|
receive() {
|
|
110
142
|
return __asyncGenerator(this, null, function* () {
|
|
111
|
-
|
|
143
|
+
if (!this.messageQueue) {
|
|
144
|
+
throw new Error("Message queue is not initialized.");
|
|
145
|
+
}
|
|
146
|
+
const aggregator = new LiveResponseAggregator(this.modelVersion);
|
|
147
|
+
try {
|
|
148
|
+
for (var iter = __forAwait(this.messageQueue), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
149
|
+
const message = temp.value;
|
|
150
|
+
logger.debug("Got LLM Live message:", message);
|
|
151
|
+
for (const response of aggregator.processMessage(message)) {
|
|
152
|
+
yield response;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} catch (temp) {
|
|
156
|
+
error = [temp];
|
|
157
|
+
} finally {
|
|
158
|
+
try {
|
|
159
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
160
|
+
} finally {
|
|
161
|
+
if (error)
|
|
162
|
+
throw error[0];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
for (const response of aggregator.close()) {
|
|
166
|
+
yield response;
|
|
167
|
+
}
|
|
112
168
|
});
|
|
113
169
|
}
|
|
114
170
|
/**
|
|
@@ -45,6 +45,7 @@ import {
|
|
|
45
45
|
import { getBooleanEnvVar, isBrowser } from "../utils/env_aware_utils.js";
|
|
46
46
|
import { logger } from "../utils/logger.js";
|
|
47
47
|
import { GoogleLLMVariant } from "../utils/variant_utils.js";
|
|
48
|
+
import { AsyncQueue } from "../utils/async_queue.js";
|
|
48
49
|
import { StreamingResponseAggregator } from "../utils/streaming_utils.js";
|
|
49
50
|
import { BaseLlm } from "./base_llm.js";
|
|
50
51
|
import { GeminiLlmConnection } from "./gemini_llm_connection.js";
|
|
@@ -199,10 +200,19 @@ class Gemini extends BaseLlm {
|
|
|
199
200
|
}
|
|
200
201
|
get liveApiClient() {
|
|
201
202
|
if (!this._liveApiClient) {
|
|
202
|
-
this.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
if (this.vertexai) {
|
|
204
|
+
this._liveApiClient = new GoogleGenAI({
|
|
205
|
+
vertexai: this.vertexai,
|
|
206
|
+
project: this.project,
|
|
207
|
+
location: this.location || "global",
|
|
208
|
+
httpOptions: this.getLiveHttpOptions()
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
this._liveApiClient = new GoogleGenAI({
|
|
212
|
+
apiKey: this.apiKey,
|
|
213
|
+
httpOptions: this.getLiveHttpOptions()
|
|
214
|
+
});
|
|
215
|
+
}
|
|
206
216
|
}
|
|
207
217
|
return this._liveApiClient;
|
|
208
218
|
}
|
|
@@ -234,16 +244,24 @@ class Gemini extends BaseLlm {
|
|
|
234
244
|
};
|
|
235
245
|
}
|
|
236
246
|
llmRequest.liveConnectConfig.tools = (_c = llmRequest.config) == null ? void 0 : _c.tools;
|
|
247
|
+
const modelVersion = (_d = llmRequest.model) != null ? _d : this.model;
|
|
248
|
+
const messageQueue = new AsyncQueue();
|
|
237
249
|
const liveSession = await this.liveApiClient.live.connect({
|
|
238
|
-
model:
|
|
250
|
+
model: modelVersion,
|
|
239
251
|
config: llmRequest.liveConnectConfig,
|
|
240
252
|
callbacks: {
|
|
241
|
-
|
|
242
|
-
|
|
253
|
+
onmessage: (message) => {
|
|
254
|
+
messageQueue.push(message);
|
|
255
|
+
},
|
|
256
|
+
onerror: (error) => {
|
|
257
|
+
messageQueue.error(error);
|
|
258
|
+
},
|
|
259
|
+
onclose: () => {
|
|
260
|
+
messageQueue.close();
|
|
243
261
|
}
|
|
244
262
|
}
|
|
245
263
|
});
|
|
246
|
-
return new GeminiLlmConnection(liveSession);
|
|
264
|
+
return new GeminiLlmConnection(liveSession, modelVersion, messageQueue);
|
|
247
265
|
}
|
|
248
266
|
preprocessRequest(llmRequest) {
|
|
249
267
|
if (this.apiBackend === GoogleLLMVariant.GEMINI_API) {
|
|
@@ -16,6 +16,11 @@ var PolicyOutcome = /* @__PURE__ */ ((PolicyOutcome2) => {
|
|
|
16
16
|
return PolicyOutcome2;
|
|
17
17
|
})(PolicyOutcome || {});
|
|
18
18
|
class InMemoryPolicyEngine {
|
|
19
|
+
/**
|
|
20
|
+
* Always returns {@link PolicyOutcome.ALLOW} for every tool call.
|
|
21
|
+
*
|
|
22
|
+
* @returns A promise resolving to an ALLOW result.
|
|
23
|
+
*/
|
|
19
24
|
async evaluate() {
|
|
20
25
|
return Promise.resolve({
|
|
21
26
|
outcome: "ALLOW" /* ALLOW */,
|
|
@@ -24,11 +29,22 @@ class InMemoryPolicyEngine {
|
|
|
24
29
|
}
|
|
25
30
|
}
|
|
26
31
|
class SecurityPlugin extends BasePlugin {
|
|
32
|
+
/**
|
|
33
|
+
* @param params - Optional configuration. Defaults to {@link InMemoryPolicyEngine}
|
|
34
|
+
* when no policy engine is provided.
|
|
35
|
+
*/
|
|
27
36
|
constructor(params) {
|
|
28
37
|
var _a;
|
|
29
38
|
super("security_plugin");
|
|
30
39
|
this.policyEngine = (_a = params == null ? void 0 : params.policyEngine) != null ? _a : new InMemoryPolicyEngine();
|
|
31
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Intercepts tool calls, evaluating them against the policy engine before
|
|
43
|
+
* execution and handling confirmation flows for calls that require it.
|
|
44
|
+
*
|
|
45
|
+
* @returns A partial or error response object if the call is blocked or
|
|
46
|
+
* awaiting confirmation, or `undefined` to allow execution to proceed.
|
|
47
|
+
*/
|
|
32
48
|
async beforeToolCallback({
|
|
33
49
|
tool,
|
|
34
50
|
toolArgs,
|
|
@@ -74,6 +74,15 @@ function trimTempDeltaState(event) {
|
|
|
74
74
|
event.actions.stateDelta = filteredStateDelta;
|
|
75
75
|
return event;
|
|
76
76
|
}
|
|
77
|
+
function trimTempState(state) {
|
|
78
|
+
const filteredState = {};
|
|
79
|
+
for (const [key, value] of Object.entries(state)) {
|
|
80
|
+
if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
81
|
+
filteredState[key] = value;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return filteredState;
|
|
85
|
+
}
|
|
77
86
|
function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
78
87
|
const merged = cloneDeep(sessionState);
|
|
79
88
|
for (const [k, v] of Object.entries(appState)) {
|
|
@@ -87,5 +96,6 @@ function mergeStates(appState = {}, userState = {}, sessionState = {}) {
|
|
|
87
96
|
export {
|
|
88
97
|
BaseSessionService,
|
|
89
98
|
mergeStates,
|
|
90
|
-
trimTempDeltaState
|
|
99
|
+
trimTempDeltaState,
|
|
100
|
+
trimTempState
|
|
91
101
|
};
|
|
@@ -126,7 +126,7 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
126
126
|
appStateDelta[key.replace(State.APP_PREFIX, "")] = value;
|
|
127
127
|
} else if (key.startsWith(State.USER_PREFIX)) {
|
|
128
128
|
userStateDelta[key.replace(State.USER_PREFIX, "")] = value;
|
|
129
|
-
} else {
|
|
129
|
+
} else if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
130
130
|
sessionState[key] = value;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -375,7 +375,7 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
375
375
|
appDelta[key.replace(State.APP_PREFIX, "")] = value;
|
|
376
376
|
} else if (key.startsWith(State.USER_PREFIX)) {
|
|
377
377
|
userDelta[key.replace(State.USER_PREFIX, "")] = value;
|
|
378
|
-
} else {
|
|
378
|
+
} else if (!key.startsWith(State.TEMP_PREFIX)) {
|
|
379
379
|
sessionDelta[key] = value;
|
|
380
380
|
}
|
|
381
381
|
}
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
} from "../../events/event.js";
|
|
23
23
|
const SCHEMA_VERSION_KEY = "schema_version";
|
|
24
24
|
const SCHEMA_VERSION_1_JSON = "1";
|
|
25
|
+
const STORAGE_KEY_COLUMN_LENGTH = 191;
|
|
25
26
|
class CamelCaseToSnakeCaseJsonType extends JsonType {
|
|
26
27
|
convertToDatabaseValue(value) {
|
|
27
28
|
return JSON.stringify(transformToSnakeCaseEvent(value));
|
|
@@ -50,7 +51,11 @@ let StorageAppState = class {
|
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
53
|
__decorateClass([
|
|
53
|
-
PrimaryKey({
|
|
54
|
+
PrimaryKey({
|
|
55
|
+
type: "string",
|
|
56
|
+
fieldName: "app_name",
|
|
57
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
58
|
+
})
|
|
54
59
|
], StorageAppState.prototype, "appName", 2);
|
|
55
60
|
__decorateClass([
|
|
56
61
|
Property({ type: "json" })
|
|
@@ -73,10 +78,18 @@ let StorageUserState = class {
|
|
|
73
78
|
}
|
|
74
79
|
};
|
|
75
80
|
__decorateClass([
|
|
76
|
-
PrimaryKey({
|
|
81
|
+
PrimaryKey({
|
|
82
|
+
type: "string",
|
|
83
|
+
fieldName: "app_name",
|
|
84
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
85
|
+
})
|
|
77
86
|
], StorageUserState.prototype, "appName", 2);
|
|
78
87
|
__decorateClass([
|
|
79
|
-
PrimaryKey({
|
|
88
|
+
PrimaryKey({
|
|
89
|
+
type: "string",
|
|
90
|
+
fieldName: "user_id",
|
|
91
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
92
|
+
})
|
|
80
93
|
], StorageUserState.prototype, "userId", 2);
|
|
81
94
|
__decorateClass([
|
|
82
95
|
Property({ type: "json" })
|
|
@@ -100,13 +113,21 @@ let StorageSession = class {
|
|
|
100
113
|
}
|
|
101
114
|
};
|
|
102
115
|
__decorateClass([
|
|
103
|
-
PrimaryKey({ type: "string" })
|
|
116
|
+
PrimaryKey({ type: "string", length: STORAGE_KEY_COLUMN_LENGTH })
|
|
104
117
|
], StorageSession.prototype, "id", 2);
|
|
105
118
|
__decorateClass([
|
|
106
|
-
PrimaryKey({
|
|
119
|
+
PrimaryKey({
|
|
120
|
+
type: "string",
|
|
121
|
+
fieldName: "app_name",
|
|
122
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
123
|
+
})
|
|
107
124
|
], StorageSession.prototype, "appName", 2);
|
|
108
125
|
__decorateClass([
|
|
109
|
-
PrimaryKey({
|
|
126
|
+
PrimaryKey({
|
|
127
|
+
type: "string",
|
|
128
|
+
fieldName: "user_id",
|
|
129
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
130
|
+
})
|
|
110
131
|
], StorageSession.prototype, "userId", 2);
|
|
111
132
|
__decorateClass([
|
|
112
133
|
Property({ type: "json" })
|
|
@@ -132,16 +153,28 @@ PrimaryKey.name;
|
|
|
132
153
|
let StorageEvent = class {
|
|
133
154
|
};
|
|
134
155
|
__decorateClass([
|
|
135
|
-
PrimaryKey({ type: "string" })
|
|
156
|
+
PrimaryKey({ type: "string", length: STORAGE_KEY_COLUMN_LENGTH })
|
|
136
157
|
], StorageEvent.prototype, "id", 2);
|
|
137
158
|
__decorateClass([
|
|
138
|
-
PrimaryKey({
|
|
159
|
+
PrimaryKey({
|
|
160
|
+
type: "string",
|
|
161
|
+
fieldName: "app_name",
|
|
162
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
163
|
+
})
|
|
139
164
|
], StorageEvent.prototype, "appName", 2);
|
|
140
165
|
__decorateClass([
|
|
141
|
-
PrimaryKey({
|
|
166
|
+
PrimaryKey({
|
|
167
|
+
type: "string",
|
|
168
|
+
fieldName: "user_id",
|
|
169
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
170
|
+
})
|
|
142
171
|
], StorageEvent.prototype, "userId", 2);
|
|
143
172
|
__decorateClass([
|
|
144
|
-
PrimaryKey({
|
|
173
|
+
PrimaryKey({
|
|
174
|
+
type: "string",
|
|
175
|
+
fieldName: "session_id",
|
|
176
|
+
length: STORAGE_KEY_COLUMN_LENGTH
|
|
177
|
+
})
|
|
145
178
|
], StorageEvent.prototype, "sessionId", 2);
|
|
146
179
|
__decorateClass([
|
|
147
180
|
Property({ type: "string", fieldName: "invocation_id" })
|
|
@@ -166,6 +199,7 @@ export {
|
|
|
166
199
|
ENTITIES,
|
|
167
200
|
SCHEMA_VERSION_1_JSON,
|
|
168
201
|
SCHEMA_VERSION_KEY,
|
|
202
|
+
STORAGE_KEY_COLUMN_LENGTH,
|
|
169
203
|
StorageAppState,
|
|
170
204
|
StorageEvent,
|
|
171
205
|
StorageMetadata,
|
|
@@ -10,7 +10,8 @@ import { randomUUID } from "../utils/env_aware_utils.js";
|
|
|
10
10
|
import { logger } from "../utils/logger.js";
|
|
11
11
|
import {
|
|
12
12
|
BaseSessionService,
|
|
13
|
-
mergeStates
|
|
13
|
+
mergeStates,
|
|
14
|
+
trimTempState
|
|
14
15
|
} from "./base_session_service.js";
|
|
15
16
|
import { createSession } from "./session.js";
|
|
16
17
|
import { State } from "./state.js";
|
|
@@ -41,11 +42,12 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
41
42
|
sessionId
|
|
42
43
|
}) {
|
|
43
44
|
var _a;
|
|
45
|
+
const filteredState = state ? trimTempState(state) : void 0;
|
|
44
46
|
const session = createSession({
|
|
45
47
|
id: sessionId || randomUUID(),
|
|
46
48
|
appName,
|
|
47
49
|
userId,
|
|
48
|
-
state,
|
|
50
|
+
state: filteredState,
|
|
49
51
|
events: [],
|
|
50
52
|
lastUpdateTime: Date.now()
|
|
51
53
|
});
|
|
@@ -40,7 +40,8 @@ import { logger } from "../utils/logger.js";
|
|
|
40
40
|
import { getExpressModeApiKey } from "../utils/vertex_ai_utils.js";
|
|
41
41
|
import { partialCopy } from "../utils/partial_copy.js";
|
|
42
42
|
import {
|
|
43
|
-
BaseSessionService
|
|
43
|
+
BaseSessionService,
|
|
44
|
+
trimTempState
|
|
44
45
|
} from "./base_session_service.js";
|
|
45
46
|
import { createSession } from "./session.js";
|
|
46
47
|
const DEFAULT_MAX_ATTEMPTS = 30;
|
|
@@ -101,10 +102,11 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
101
102
|
}) {
|
|
102
103
|
var _a;
|
|
103
104
|
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
105
|
+
const filteredState = state ? trimTempState(state) : void 0;
|
|
104
106
|
let apiResponse = await this.sessions.createInternal({
|
|
105
107
|
name: "reasoningEngines/".concat(reasoningEngineId),
|
|
106
108
|
userId,
|
|
107
|
-
config: __spreadValues(__spreadValues({},
|
|
109
|
+
config: __spreadValues(__spreadValues({}, filteredState ? { sessionState: filteredState } : {}), sessionId ? { sessionId } : {})
|
|
108
110
|
});
|
|
109
111
|
const operationName = apiResponse.name;
|
|
110
112
|
let attempts = 0;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
6
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
7
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
if (decorator = decorators[i])
|
|
9
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
10
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2026 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
*/
|
|
18
|
+
import { Client } from "@google-cloud/vertexai";
|
|
19
|
+
import { experimental } from "../utils/experimental.js";
|
|
20
|
+
import { loadSkillFromZipBuffer } from "./loader.js";
|
|
21
|
+
let GCPSkillRegistry = class {
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
this.projectId = options.projectId || process.env.GOOGLE_CLOUD_PROJECT;
|
|
24
|
+
this.location = options.location || process.env.GOOGLE_CLOUD_LOCATION;
|
|
25
|
+
this.client = options.client || new Client({
|
|
26
|
+
project: this.projectId,
|
|
27
|
+
location: this.location
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async getSkill(name) {
|
|
31
|
+
const apiClient = this.client.apiClient;
|
|
32
|
+
const httpResponse = await apiClient.request({
|
|
33
|
+
path: "skills/".concat(name),
|
|
34
|
+
httpMethod: "GET",
|
|
35
|
+
httpOptions: { apiVersion: "v1beta1" }
|
|
36
|
+
});
|
|
37
|
+
const response = await httpResponse.json();
|
|
38
|
+
const zippedFilesystem = response.zippedFilesystem || response.zipped_filesystem;
|
|
39
|
+
if (!zippedFilesystem) {
|
|
40
|
+
throw new Error("Skill '".concat(name, "' does not contain zipped filesystem."));
|
|
41
|
+
}
|
|
42
|
+
const zipBuffer = Buffer.from(zippedFilesystem, "base64");
|
|
43
|
+
return loadSkillFromZipBuffer(zipBuffer);
|
|
44
|
+
}
|
|
45
|
+
async searchSkills(query) {
|
|
46
|
+
const apiClient = this.client.apiClient;
|
|
47
|
+
const trimmedQuery = query.trim();
|
|
48
|
+
const isSearch = trimmedQuery.length > 0;
|
|
49
|
+
const path = isSearch ? "skills:retrieve?query=".concat(encodeURIComponent(trimmedQuery)) : "skills";
|
|
50
|
+
const httpResponse = await apiClient.request({
|
|
51
|
+
path,
|
|
52
|
+
httpMethod: "GET",
|
|
53
|
+
httpOptions: { apiVersion: "v1beta1" }
|
|
54
|
+
});
|
|
55
|
+
const response = await httpResponse.json();
|
|
56
|
+
const skillsList = isSearch ? response.retrievedSkills || response.retrieved_skills : response.skills;
|
|
57
|
+
const results = [];
|
|
58
|
+
if (skillsList && Array.isArray(skillsList)) {
|
|
59
|
+
for (const s of skillsList) {
|
|
60
|
+
const skillNameStr = s.skillName || s.skill_name || s.name || "";
|
|
61
|
+
const descriptionStr = s.description || "";
|
|
62
|
+
const parts = skillNameStr.split("/");
|
|
63
|
+
const name = skillNameStr ? parts[parts.length - 1] : "";
|
|
64
|
+
results.push({
|
|
65
|
+
name,
|
|
66
|
+
description: descriptionStr
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return results;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
GCPSkillRegistry = __decorateClass([
|
|
74
|
+
experimental
|
|
75
|
+
], GCPSkillRegistry);
|
|
76
|
+
export {
|
|
77
|
+
GCPSkillRegistry
|
|
78
|
+
};
|
|
@@ -24,6 +24,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
24
24
|
* Copyright 2026 Google LLC
|
|
25
25
|
* SPDX-License-Identifier: Apache-2.0
|
|
26
26
|
*/
|
|
27
|
+
import AdmZip from "adm-zip";
|
|
27
28
|
import yaml from "js-yaml";
|
|
28
29
|
import * as fs from "node:fs/promises";
|
|
29
30
|
import * as path from "node:path";
|
|
@@ -254,9 +255,72 @@ async function loadAllSkillsInDir(skillsBasePath) {
|
|
|
254
255
|
}
|
|
255
256
|
return skills;
|
|
256
257
|
}
|
|
258
|
+
function loadSkillFromZipBuffer(zipBuffer) {
|
|
259
|
+
const zip = new AdmZip(zipBuffer);
|
|
260
|
+
const entries = zip.getEntries();
|
|
261
|
+
let skillMdContent = "";
|
|
262
|
+
for (const entry of entries) {
|
|
263
|
+
if (entry.isDirectory) continue;
|
|
264
|
+
if (entry.entryName.toLowerCase() === "skill.md") {
|
|
265
|
+
skillMdContent = entry.getData().toString("utf-8");
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (!skillMdContent) {
|
|
270
|
+
throw new Error("SKILL.md not found in zipped filesystem.");
|
|
271
|
+
}
|
|
272
|
+
const { frontmatter: parsed, body } = parseSkillMdContent(skillMdContent);
|
|
273
|
+
const frontmatter = FrontmatterSchema.parse(parsed);
|
|
274
|
+
const references = {};
|
|
275
|
+
const assets = {};
|
|
276
|
+
const scripts = {};
|
|
277
|
+
function loadZipDir(prefix) {
|
|
278
|
+
const res = {};
|
|
279
|
+
const normPrefix = prefix.endsWith("/") ? prefix : "".concat(prefix, "/");
|
|
280
|
+
for (const entry of entries) {
|
|
281
|
+
if (entry.isDirectory) continue;
|
|
282
|
+
if (entry.entryName.startsWith(normPrefix)) {
|
|
283
|
+
if (entry.entryName.includes("__pycache__")) continue;
|
|
284
|
+
const relativePath = entry.entryName.substring(normPrefix.length);
|
|
285
|
+
if (!relativePath) continue;
|
|
286
|
+
const data = entry.getData();
|
|
287
|
+
try {
|
|
288
|
+
res[relativePath] = data.toString("utf-8");
|
|
289
|
+
} catch (_e) {
|
|
290
|
+
res[relativePath] = data;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return res;
|
|
295
|
+
}
|
|
296
|
+
const refFiles = loadZipDir("references");
|
|
297
|
+
for (const [key, val] of Object.entries(refFiles)) {
|
|
298
|
+
references[key] = val;
|
|
299
|
+
}
|
|
300
|
+
const assetFiles = loadZipDir("assets");
|
|
301
|
+
for (const [key, val] of Object.entries(assetFiles)) {
|
|
302
|
+
assets[key] = val;
|
|
303
|
+
}
|
|
304
|
+
const rawScripts = loadZipDir("scripts");
|
|
305
|
+
for (const [key, val] of Object.entries(rawScripts)) {
|
|
306
|
+
if (typeof val === "string") {
|
|
307
|
+
scripts[key] = { src: val };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
frontmatter,
|
|
312
|
+
instructions: body,
|
|
313
|
+
resources: {
|
|
314
|
+
references,
|
|
315
|
+
assets,
|
|
316
|
+
scripts
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
257
320
|
export {
|
|
258
321
|
loadAllSkillsInDir,
|
|
259
322
|
loadSkillFromDir,
|
|
323
|
+
loadSkillFromZipBuffer,
|
|
260
324
|
parseSkillMdContent,
|
|
261
325
|
validateSkillDir
|
|
262
326
|
};
|