@google/adk 1.5.0 → 1.6.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/a2a/a2a_remote_agent.js +12 -2
- package/dist/cjs/a2a/agent_to_a2a.js +0 -1
- package/dist/cjs/a2a/auth.js +65 -0
- package/dist/cjs/a2a/event_converter_utils.js +40 -15
- package/dist/cjs/agents/functions.js +20 -7
- package/dist/cjs/agents/llm_agent.js +2 -1
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/cjs/agents/processors/content_request_processor.js +2 -21
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/cjs/artifacts/in_memory_artifact_service.js +10 -9
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +23 -12
- package/dist/cjs/common.js +6 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
- package/dist/cjs/context/compaction_utils.js +14 -2
- package/dist/cjs/context/token_based_context_compactor.js +2 -20
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/memory/in_memory_memory_service.js +13 -2
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +3 -0
- package/dist/cjs/plugins/base_plugin.js +4 -2
- package/dist/cjs/runner/runner.js +18 -11
- package/dist/cjs/sessions/base_session_service.js +8 -3
- package/dist/cjs/sessions/in_memory_session_service.js +8 -8
- package/dist/cjs/sessions/vertex_ai_session_service.js +22 -10
- package/dist/cjs/skills/loader.js +40 -6
- package/dist/cjs/tools/get_user_choice_tool.js +53 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/cjs/tools/request_input_tool.js +54 -0
- package/dist/cjs/utils/crypto_shim.js +43 -0
- package/dist/cjs/utils/env_aware_utils.js +15 -13
- package/dist/cjs/utils/error_utils.js +120 -0
- package/dist/cjs/utils/file_utils.js +5 -2
- package/dist/cjs/utils/output_schema_utils.js +43 -0
- package/dist/cjs/utils/vertex_ai_utils.js +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +12 -2
- package/dist/esm/a2a/agent_to_a2a.js +0 -1
- package/dist/esm/a2a/auth.js +37 -0
- package/dist/esm/a2a/event_converter_utils.js +40 -15
- package/dist/esm/agents/functions.js +20 -7
- package/dist/esm/agents/llm_agent.js +2 -1
- package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/esm/agents/processors/content_request_processor.js +2 -21
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/esm/artifacts/in_memory_artifact_service.js +10 -9
- package/dist/esm/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/esm/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/esm/common.js +4 -0
- package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
- package/dist/esm/context/compaction_utils.js +12 -1
- package/dist/esm/context/token_based_context_compactor.js +6 -21
- package/dist/esm/index.js +2 -0
- package/dist/esm/memory/in_memory_memory_service.js +13 -2
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/esm/plugins/base_plugin.js +4 -2
- package/dist/esm/runner/runner.js +18 -11
- package/dist/esm/sessions/base_session_service.js +8 -3
- package/dist/esm/sessions/in_memory_session_service.js +8 -8
- package/dist/esm/sessions/vertex_ai_session_service.js +26 -11
- package/dist/esm/skills/loader.js +40 -6
- package/dist/esm/tools/get_user_choice_tool.js +25 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/esm/tools/request_input_tool.js +26 -0
- package/dist/esm/utils/crypto_shim.js +15 -0
- package/dist/esm/utils/env_aware_utils.js +15 -13
- package/dist/esm/utils/error_utils.js +92 -0
- package/dist/esm/utils/file_utils.js +5 -2
- package/dist/esm/utils/output_schema_utils.js +15 -0
- package/dist/esm/utils/vertex_ai_utils.js +2 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/auth.d.ts +30 -0
- package/dist/types/a2a/event_converter_utils.d.ts +4 -1
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +11 -0
- package/dist/types/code_executors/unsafe_local_code_executor.d.ts +5 -1
- package/dist/types/common.d.ts +2 -0
- package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
- package/dist/types/context/compaction_utils.d.ts +8 -0
- package/dist/types/context/token_based_context_compactor.d.ts +0 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/memory/in_memory_memory_service.d.ts +11 -0
- package/dist/types/plugins/base_plugin.d.ts +4 -2
- package/dist/types/sessions/base_session_service.d.ts +8 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +9 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +19 -1
- package/dist/types/skills/loader.d.ts +5 -0
- package/dist/types/tools/get_user_choice_tool.d.ts +14 -0
- package/dist/types/tools/request_input_tool.d.ts +15 -0
- package/dist/types/utils/crypto_shim.d.ts +16 -0
- package/dist/types/utils/env_aware_utils.d.ts +23 -0
- package/dist/types/utils/error_utils.d.ts +18 -0
- package/dist/types/utils/output_schema_utils.d.ts +18 -0
- package/dist/types/utils/vertex_ai_utils.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_remote_agent.js +12 -2
- package/dist/web/a2a/agent_to_a2a.js +0 -1
- package/dist/web/a2a/auth.js +37 -0
- package/dist/web/a2a/event_converter_utils.js +40 -15
- package/dist/web/agents/functions.js +20 -7
- package/dist/web/agents/llm_agent.js +2 -1
- package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/web/agents/processors/content_request_processor.js +2 -21
- package/dist/web/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/web/artifacts/in_memory_artifact_service.js +10 -9
- package/dist/web/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/web/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/web/common.js +4 -0
- package/dist/web/context/agent_controlled_context_compactor.js +2 -11
- package/dist/web/context/compaction_utils.js +12 -1
- package/dist/web/context/token_based_context_compactor.js +6 -21
- package/dist/web/index.js +2 -0
- package/dist/web/memory/in_memory_memory_service.js +13 -2
- package/dist/web/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/web/plugins/base_plugin.js +4 -2
- package/dist/web/runner/runner.js +17 -11
- package/dist/web/sessions/base_session_service.js +8 -3
- package/dist/web/sessions/in_memory_session_service.js +8 -8
- package/dist/web/sessions/vertex_ai_session_service.js +24 -11
- package/dist/web/skills/loader.js +40 -6
- package/dist/web/tools/get_user_choice_tool.js +25 -0
- package/dist/web/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/web/tools/request_input_tool.js +26 -0
- package/dist/web/utils/crypto_shim.js +15 -0
- package/dist/web/utils/env_aware_utils.js +15 -13
- package/dist/web/utils/error_utils.js +92 -0
- package/dist/web/utils/file_utils.js +5 -2
- package/dist/web/utils/output_schema_utils.js +15 -0
- package/dist/web/utils/vertex_ai_utils.js +2 -0
- package/dist/web/version.js +1 -1
- package/package.json +1 -1
|
@@ -24,15 +24,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var compaction_utils_exports = {};
|
|
26
26
|
__export(compaction_utils_exports, {
|
|
27
|
-
calculateRetainStartIndex: () => calculateRetainStartIndex
|
|
27
|
+
calculateRetainStartIndex: () => calculateRetainStartIndex,
|
|
28
|
+
getActiveEvents: () => getActiveEvents
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(compaction_utils_exports);
|
|
31
|
+
var import_compacted_event = require("../events/compacted_event.js");
|
|
30
32
|
var import_event = require("../events/event.js");
|
|
31
33
|
/**
|
|
32
34
|
* @license
|
|
33
35
|
* Copyright 2026 Google LLC
|
|
34
36
|
* SPDX-License-Identifier: Apache-2.0
|
|
35
37
|
*/
|
|
38
|
+
function getActiveEvents(events) {
|
|
39
|
+
const latest = events.filter(import_compacted_event.isCompactedEvent).pop();
|
|
40
|
+
return latest ? [
|
|
41
|
+
latest,
|
|
42
|
+
...events.filter(
|
|
43
|
+
(e) => !(0, import_compacted_event.isCompactedEvent)(e) && e.timestamp > latest.endTime
|
|
44
|
+
)
|
|
45
|
+
] : events;
|
|
46
|
+
}
|
|
36
47
|
function calculateRetainStartIndex(rawEvents, eventRetentionSize) {
|
|
37
48
|
let retainStartIndex = Math.max(0, rawEvents.length - eventRetentionSize);
|
|
38
49
|
while (retainStartIndex > 0) {
|
|
@@ -48,5 +59,6 @@ function calculateRetainStartIndex(rawEvents, eventRetentionSize) {
|
|
|
48
59
|
}
|
|
49
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
61
|
0 && (module.exports = {
|
|
51
|
-
calculateRetainStartIndex
|
|
62
|
+
calculateRetainStartIndex,
|
|
63
|
+
getActiveEvents
|
|
52
64
|
});
|
|
@@ -42,27 +42,9 @@ class TokenBasedContextCompactor {
|
|
|
42
42
|
this.eventRetentionSize = options.eventRetentionSize;
|
|
43
43
|
this.summarizer = options.summarizer;
|
|
44
44
|
}
|
|
45
|
-
getActiveEvents(events) {
|
|
46
|
-
let latestCompactedEvent = void 0;
|
|
47
|
-
for (let i = events.length - 1; i >= 0; i--) {
|
|
48
|
-
const e = events[i];
|
|
49
|
-
if ((0, import_compacted_event.isCompactedEvent)(e)) {
|
|
50
|
-
if (!latestCompactedEvent || e.endTime > latestCompactedEvent.endTime) {
|
|
51
|
-
latestCompactedEvent = e;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (!latestCompactedEvent) {
|
|
56
|
-
return events;
|
|
57
|
-
}
|
|
58
|
-
const activeRawEvents = events.filter(
|
|
59
|
-
(e) => !(0, import_compacted_event.isCompactedEvent)(e) && e.timestamp > latestCompactedEvent.endTime
|
|
60
|
-
);
|
|
61
|
-
return [latestCompactedEvent, ...activeRawEvents];
|
|
62
|
-
}
|
|
63
45
|
shouldCompact(invocationContext) {
|
|
64
46
|
const events = invocationContext.session.events;
|
|
65
|
-
const activeEvents =
|
|
47
|
+
const activeEvents = (0, import_compaction_utils.getActiveEvents)(events);
|
|
66
48
|
const rawEvents = activeEvents.filter((e) => !(0, import_compacted_event.isCompactedEvent)(e));
|
|
67
49
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
68
50
|
return false;
|
|
@@ -85,7 +67,7 @@ class TokenBasedContextCompactor {
|
|
|
85
67
|
}
|
|
86
68
|
async compact(invocationContext) {
|
|
87
69
|
const events = invocationContext.session.events;
|
|
88
|
-
const activeEvents =
|
|
70
|
+
const activeEvents = (0, import_compaction_utils.getActiveEvents)(events);
|
|
89
71
|
const rawEvents = activeEvents.filter((e) => !(0, import_compacted_event.isCompactedEvent)(e));
|
|
90
72
|
if (rawEvents.length <= this.eventRetentionSize) {
|
|
91
73
|
return;
|
package/dist/cjs/index.js
CHANGED
|
@@ -39,6 +39,7 @@ __export(index_exports, {
|
|
|
39
39
|
RunSkillScriptTool: () => import_run_skill_script_tool.RunSkillScriptTool,
|
|
40
40
|
UnsafeLocalCodeExecutor: () => import_unsafe_local_code_executor.UnsafeLocalCodeExecutor,
|
|
41
41
|
VertexAiSessionService: () => import_vertex_ai_session_service.VertexAiSessionService,
|
|
42
|
+
bearerTokenUserBuilder: () => import_auth.bearerTokenUserBuilder,
|
|
42
43
|
getA2AAgentCard: () => import_agent_card.getA2AAgentCard,
|
|
43
44
|
getArtifactServiceFromUri: () => import_registry.getArtifactServiceFromUri,
|
|
44
45
|
getSessionServiceFromUri: () => import_registry2.getSessionServiceFromUri,
|
|
@@ -52,6 +53,7 @@ var import_a2a_remote_agent = require("./a2a/a2a_remote_agent.js");
|
|
|
52
53
|
var import_agent_card = require("./a2a/agent_card.js");
|
|
53
54
|
var import_agent_executor = require("./a2a/agent_executor.js");
|
|
54
55
|
var import_agent_to_a2a = require("./a2a/agent_to_a2a.js");
|
|
56
|
+
var import_auth = require("./a2a/auth.js");
|
|
55
57
|
var import_invocation_context = require("./agents/invocation_context.js");
|
|
56
58
|
var import_file_artifact_service = require("./artifacts/file_artifact_service.js");
|
|
57
59
|
var import_gcs_artifact_service = require("./artifacts/gcs_artifact_service.js");
|
|
@@ -94,6 +96,7 @@ __reExport(index_exports, require("./tools/mcp/mcp_toolset.js"), module.exports)
|
|
|
94
96
|
RunSkillScriptTool,
|
|
95
97
|
UnsafeLocalCodeExecutor,
|
|
96
98
|
VertexAiSessionService,
|
|
99
|
+
bearerTokenUserBuilder,
|
|
97
100
|
getA2AAgentCard,
|
|
98
101
|
getArtifactServiceFromUri,
|
|
99
102
|
getSessionServiceFromUri,
|
|
@@ -35,12 +35,23 @@ module.exports = __toCommonJS(in_memory_memory_service_exports);
|
|
|
35
35
|
class InMemoryMemoryService {
|
|
36
36
|
constructor() {
|
|
37
37
|
this.memories = [];
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* A map from user key to a map from session ID to events.
|
|
40
|
+
*
|
|
41
|
+
* The inner map is keyed by `session.id`, which arrives off the request path
|
|
42
|
+
* and contains no `/`, so it can be exactly `__proto__`. On a plain object
|
|
43
|
+
* literal that key would reach the inherited `__proto__` setter and
|
|
44
|
+
* re-parent the map instead of creating an own property, silently dropping
|
|
45
|
+
* the session from the `Object.values` scan in `searchMemory`. The outer key
|
|
46
|
+
* always contains a `/` (see `getUserKey`) and cannot collide, but is
|
|
47
|
+
* created the same way for consistency.
|
|
48
|
+
*/
|
|
49
|
+
this.sessionEvents = /* @__PURE__ */ Object.create(null);
|
|
39
50
|
}
|
|
40
51
|
async addSessionToMemory(session) {
|
|
41
52
|
const userKey = getUserKey(session.appName, session.userId);
|
|
42
53
|
if (!this.sessionEvents[userKey]) {
|
|
43
|
-
this.sessionEvents[userKey] =
|
|
54
|
+
this.sessionEvents[userKey] = /* @__PURE__ */ Object.create(null);
|
|
44
55
|
}
|
|
45
56
|
this.sessionEvents[userKey][session.id] = session.events.filter(
|
|
46
57
|
(event) => {
|
|
@@ -116,6 +116,9 @@ class VertexAiMemoryBankService {
|
|
|
116
116
|
if (options.client) {
|
|
117
117
|
this.memories = options.client.agentEnginesInternal.memories;
|
|
118
118
|
} else {
|
|
119
|
+
if (this.expressModeApiKey && (!this.projectId || !this.location)) {
|
|
120
|
+
throw new Error(import_vertex_ai_utils.EXPRESS_MODE_UNSUPPORTED_MESSAGE);
|
|
121
|
+
}
|
|
119
122
|
const client = new import_vertexai.Client({
|
|
120
123
|
project: this.projectId,
|
|
121
124
|
location: this.location
|
|
@@ -99,8 +99,10 @@ class BasePlugin {
|
|
|
99
99
|
* @param params.invocationContext The context for the entire invocation.
|
|
100
100
|
* @param params.event The event raised by the runner.
|
|
101
101
|
* @returns An optional value. A non-`undefined` return may be used by the
|
|
102
|
-
* framework to modify or replace the response.
|
|
103
|
-
*
|
|
102
|
+
* framework to modify or replace the response. Copy `params.event` when
|
|
103
|
+
* constructing a replacement to preserve fields that are not being
|
|
104
|
+
* modified, such as event actions. Returning `undefined` allows the
|
|
105
|
+
* original response to be used.
|
|
104
106
|
*/
|
|
105
107
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
106
108
|
async onEventCallback(params) {
|
|
@@ -142,7 +142,7 @@ class Runner {
|
|
|
142
142
|
ctx,
|
|
143
143
|
this,
|
|
144
144
|
async function* () {
|
|
145
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
145
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
146
146
|
const session = await this.sessionService.getSession({
|
|
147
147
|
appName: this.appName,
|
|
148
148
|
userId,
|
|
@@ -259,24 +259,31 @@ class Runner {
|
|
|
259
259
|
if ((_h = params.abortSignal) == null ? void 0 : _h.aborted) {
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
262
|
-
if (!event.partial) {
|
|
263
|
-
await this.sessionService.appendEvent({ session, event });
|
|
264
|
-
}
|
|
265
262
|
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
266
263
|
invocationContext,
|
|
267
264
|
event
|
|
268
265
|
});
|
|
269
|
-
|
|
270
|
-
|
|
266
|
+
const outputEvent = modifiedEvent ? {
|
|
267
|
+
...modifiedEvent,
|
|
268
|
+
id: event.id,
|
|
269
|
+
invocationId: event.invocationId,
|
|
270
|
+
timestamp: event.timestamp,
|
|
271
|
+
author: modifiedEvent.author || event.author,
|
|
272
|
+
branch: (_i = modifiedEvent.branch) != null ? _i : event.branch
|
|
273
|
+
} : event;
|
|
274
|
+
if (!event.partial) {
|
|
275
|
+
await this.sessionService.appendEvent({
|
|
276
|
+
session,
|
|
277
|
+
event: outputEvent
|
|
278
|
+
});
|
|
271
279
|
}
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
-
} else {
|
|
275
|
-
yield event;
|
|
280
|
+
if ((_j = params.abortSignal) == null ? void 0 : _j.aborted) {
|
|
281
|
+
return;
|
|
276
282
|
}
|
|
283
|
+
yield outputEvent;
|
|
277
284
|
}
|
|
278
285
|
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
279
|
-
if ((
|
|
286
|
+
if ((_k = params.abortSignal) == null ? void 0 : _k.aborted) {
|
|
280
287
|
return;
|
|
281
288
|
}
|
|
282
289
|
}
|
|
@@ -91,7 +91,12 @@ class BaseSessionService {
|
|
|
91
91
|
if (key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
92
92
|
continue;
|
|
93
93
|
}
|
|
94
|
-
session.state
|
|
94
|
+
Object.defineProperty(session.state, key, {
|
|
95
|
+
value,
|
|
96
|
+
writable: true,
|
|
97
|
+
enumerable: true,
|
|
98
|
+
configurable: true
|
|
99
|
+
});
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
}
|
|
@@ -100,7 +105,7 @@ function trimTempDeltaState(event) {
|
|
|
100
105
|
return event;
|
|
101
106
|
}
|
|
102
107
|
const stateDelta = event.actions.stateDelta;
|
|
103
|
-
const filteredStateDelta =
|
|
108
|
+
const filteredStateDelta = /* @__PURE__ */ Object.create(null);
|
|
104
109
|
for (const [key, value] of Object.entries(stateDelta)) {
|
|
105
110
|
if (!key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
106
111
|
filteredStateDelta[key] = value;
|
|
@@ -110,7 +115,7 @@ function trimTempDeltaState(event) {
|
|
|
110
115
|
return event;
|
|
111
116
|
}
|
|
112
117
|
function trimTempState(state) {
|
|
113
|
-
const filteredState =
|
|
118
|
+
const filteredState = /* @__PURE__ */ Object.create(null);
|
|
114
119
|
for (const [key, value] of Object.entries(state)) {
|
|
115
120
|
if (!key.startsWith(import_state.State.TEMP_PREFIX)) {
|
|
116
121
|
filteredState[key] = value;
|
|
@@ -49,15 +49,15 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
49
49
|
* A map from app name to a map from user ID to a map from session ID to
|
|
50
50
|
* session.
|
|
51
51
|
*/
|
|
52
|
-
this.sessions =
|
|
52
|
+
this.sessions = /* @__PURE__ */ Object.create(null);
|
|
53
53
|
/**
|
|
54
54
|
* A map from app name to a map from user ID to a map from key to the value.
|
|
55
55
|
*/
|
|
56
|
-
this.userState =
|
|
56
|
+
this.userState = /* @__PURE__ */ Object.create(null);
|
|
57
57
|
/**
|
|
58
58
|
* A map from app name to a map from key to the value.
|
|
59
59
|
*/
|
|
60
|
-
this.appState =
|
|
60
|
+
this.appState = /* @__PURE__ */ Object.create(null);
|
|
61
61
|
}
|
|
62
62
|
async createSession({
|
|
63
63
|
appName,
|
|
@@ -76,10 +76,10 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
76
76
|
lastUpdateTime: Date.now()
|
|
77
77
|
});
|
|
78
78
|
if (!this.sessions[appName]) {
|
|
79
|
-
this.sessions[appName] =
|
|
79
|
+
this.sessions[appName] = /* @__PURE__ */ Object.create(null);
|
|
80
80
|
}
|
|
81
81
|
if (!this.sessions[appName][userId]) {
|
|
82
|
-
this.sessions[appName][userId] =
|
|
82
|
+
this.sessions[appName][userId] = /* @__PURE__ */ Object.create(null);
|
|
83
83
|
}
|
|
84
84
|
this.sessions[appName][userId][session.id] = session;
|
|
85
85
|
const copiedSession = (0, import_lodash_es.cloneDeep)(session);
|
|
@@ -244,12 +244,12 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
244
244
|
if (event.actions && event.actions.stateDelta) {
|
|
245
245
|
for (const key of Object.keys(event.actions.stateDelta)) {
|
|
246
246
|
if (key.startsWith(import_state.State.APP_PREFIX)) {
|
|
247
|
-
this.appState[appName] = this.appState[appName] ||
|
|
247
|
+
this.appState[appName] = this.appState[appName] || /* @__PURE__ */ Object.create(null);
|
|
248
248
|
this.appState[appName][key.replace(import_state.State.APP_PREFIX, "")] = event.actions.stateDelta[key];
|
|
249
249
|
}
|
|
250
250
|
if (key.startsWith(import_state.State.USER_PREFIX)) {
|
|
251
|
-
this.userState[appName] = this.userState[appName] ||
|
|
252
|
-
this.userState[appName][userId] = this.userState[appName][userId] ||
|
|
251
|
+
this.userState[appName] = this.userState[appName] || /* @__PURE__ */ Object.create(null);
|
|
252
|
+
this.userState[appName][userId] = this.userState[appName][userId] || /* @__PURE__ */ Object.create(null);
|
|
253
253
|
this.userState[appName][userId][key.replace(import_state.State.USER_PREFIX, "")] = event.actions.stateDelta[key];
|
|
254
254
|
}
|
|
255
255
|
}
|
|
@@ -71,16 +71,14 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
71
71
|
this.location,
|
|
72
72
|
options.expressModeApiKey
|
|
73
73
|
);
|
|
74
|
-
if (!options.sessions) {
|
|
75
|
-
if (!this.expressModeApiKey && (!this.projectId || !this.location)) {
|
|
76
|
-
throw new Error(
|
|
77
|
-
"Either (Project ID and Location) or an expressModeApiKey is required."
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
74
|
if (options.sessions) {
|
|
82
75
|
this.sessions = options.sessions;
|
|
83
76
|
} else {
|
|
77
|
+
if (!this.projectId || !this.location) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
this.expressModeApiKey ? import_vertex_ai_utils.EXPRESS_MODE_UNSUPPORTED_MESSAGE : "Project ID and Location are required."
|
|
80
|
+
);
|
|
81
|
+
}
|
|
84
82
|
const client = new import_client.Client({
|
|
85
83
|
project: this.projectId,
|
|
86
84
|
location: this.location
|
|
@@ -104,13 +102,25 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
104
102
|
}
|
|
105
103
|
return match[3];
|
|
106
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Creates a session on Vertex AI Agent Engine.
|
|
107
|
+
*
|
|
108
|
+
* @throws if both `ttl` and `expireTime` are specified.
|
|
109
|
+
*/
|
|
107
110
|
async createSession({
|
|
108
111
|
appName,
|
|
109
112
|
userId,
|
|
110
113
|
state,
|
|
111
|
-
sessionId
|
|
114
|
+
sessionId,
|
|
115
|
+
ttl,
|
|
116
|
+
expireTime
|
|
112
117
|
}) {
|
|
113
118
|
var _a;
|
|
119
|
+
if (ttl != null && expireTime != null) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
"Cannot specify both 'ttl' and 'expireTime' simultaneously."
|
|
122
|
+
);
|
|
123
|
+
}
|
|
114
124
|
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
115
125
|
const filteredState = state ? (0, import_base_session_service.trimTempState)(state) : void 0;
|
|
116
126
|
let apiResponse = await this.sessions.createInternal({
|
|
@@ -118,7 +128,9 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
118
128
|
userId,
|
|
119
129
|
config: {
|
|
120
130
|
...filteredState ? { sessionState: filteredState } : {},
|
|
121
|
-
...sessionId ? { sessionId } : {}
|
|
131
|
+
...sessionId ? { sessionId } : {},
|
|
132
|
+
...ttl != null ? { ttl } : {},
|
|
133
|
+
...expireTime != null ? { expireTime } : {}
|
|
122
134
|
}
|
|
123
135
|
});
|
|
124
136
|
const operationName = apiResponse.name;
|
|
@@ -204,7 +216,7 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
204
216
|
return session;
|
|
205
217
|
} catch (error) {
|
|
206
218
|
const err = error;
|
|
207
|
-
if (err.code === GRPC_NOT_FOUND || err.code === HTTP_NOT_FOUND) {
|
|
219
|
+
if (err.code === GRPC_NOT_FOUND || err.code === HTTP_NOT_FOUND || err.status === HTTP_NOT_FOUND) {
|
|
208
220
|
return void 0;
|
|
209
221
|
}
|
|
210
222
|
import_logger.logger.error(`Error getting session from Vertex AI: ${err.message}`);
|
|
@@ -57,6 +57,9 @@ const ALLOWED_FRONTMATTER_KEYS = /* @__PURE__ */ new Set([
|
|
|
57
57
|
"description",
|
|
58
58
|
"license",
|
|
59
59
|
"allowed-tools",
|
|
60
|
+
// Camel-case alias: FrontmatterSchema's preprocessor derives `allowedTools`
|
|
61
|
+
// from `allowed-tools`, and `.loose()` passes either spelling through.
|
|
62
|
+
"allowedTools",
|
|
60
63
|
"metadata",
|
|
61
64
|
"compatibility"
|
|
62
65
|
]);
|
|
@@ -119,7 +122,7 @@ async function loadDir(directoryPath) {
|
|
|
119
122
|
}
|
|
120
123
|
return files;
|
|
121
124
|
}
|
|
122
|
-
function
|
|
125
|
+
function parseFrontmatterYaml(content) {
|
|
123
126
|
if (!content.startsWith("---")) {
|
|
124
127
|
throw new Error("SKILL.md must start with YAML frontmatter (---)");
|
|
125
128
|
}
|
|
@@ -131,15 +134,34 @@ function parseSkillMdContent(content) {
|
|
|
131
134
|
const body = parts.filter((_, i) => i >= 2).join("---").trim();
|
|
132
135
|
try {
|
|
133
136
|
const parsed = import_js_yaml.default.load(frontmatterStr);
|
|
134
|
-
if (typeof parsed !== "object" || parsed === null) {
|
|
137
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
135
138
|
throw new Error("SKILL.md frontmatter must be a YAML mapping");
|
|
136
139
|
}
|
|
137
|
-
|
|
138
|
-
return { frontmatter, body };
|
|
140
|
+
return { raw: parsed, body };
|
|
139
141
|
} catch (e) {
|
|
140
142
|
throw new Error(`Invalid YAML in frontmatter: ${e.message}`);
|
|
141
143
|
}
|
|
142
144
|
}
|
|
145
|
+
function validateFrontmatter(raw) {
|
|
146
|
+
try {
|
|
147
|
+
return import_skill.FrontmatterSchema.parse(raw);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
throw new Error(`Invalid YAML in frontmatter: ${e.message}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function parseSkillMdContent(content) {
|
|
153
|
+
const { raw, body } = parseFrontmatterYaml(content);
|
|
154
|
+
return { frontmatter: validateFrontmatter(raw), body };
|
|
155
|
+
}
|
|
156
|
+
function isDangerousZipEntryName(entryName) {
|
|
157
|
+
if (path.posix.isAbsolute(entryName) || path.win32.isAbsolute(entryName)) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
return entryName.split(/[/\\]/).some((segment) => segment === "..");
|
|
161
|
+
}
|
|
162
|
+
function isBareSkillName(name) {
|
|
163
|
+
return name !== "." && name !== ".." && path.basename(name) === name;
|
|
164
|
+
}
|
|
143
165
|
async function loadSkillFromDir(skillDir) {
|
|
144
166
|
const resolvedDir = path.resolve(skillDir);
|
|
145
167
|
const skill = await loadSkillFile(skillDir);
|
|
@@ -279,6 +301,11 @@ async function loadAllSkillsInDir(skillsBasePath) {
|
|
|
279
301
|
function loadSkillFromZipBuffer(zipBuffer) {
|
|
280
302
|
const zip = new import_adm_zip.default(zipBuffer);
|
|
281
303
|
const entries = zip.getEntries();
|
|
304
|
+
for (const entry of entries) {
|
|
305
|
+
if (isDangerousZipEntryName(entry.entryName)) {
|
|
306
|
+
throw new Error(`Dangerous zip entry ignored: ${entry.entryName}`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
282
309
|
let skillMdContent = "";
|
|
283
310
|
for (const entry of entries) {
|
|
284
311
|
if (entry.isDirectory) continue;
|
|
@@ -290,8 +317,15 @@ function loadSkillFromZipBuffer(zipBuffer) {
|
|
|
290
317
|
if (!skillMdContent) {
|
|
291
318
|
throw new Error("SKILL.md not found in zipped filesystem.");
|
|
292
319
|
}
|
|
293
|
-
const {
|
|
294
|
-
const
|
|
320
|
+
const { raw, body } = parseFrontmatterYaml(skillMdContent);
|
|
321
|
+
const skillName = raw["name"];
|
|
322
|
+
if (!skillName) {
|
|
323
|
+
throw new Error("SKILL.md frontmatter must contain 'name'");
|
|
324
|
+
}
|
|
325
|
+
if (typeof skillName !== "string" || !isBareSkillName(skillName)) {
|
|
326
|
+
throw new Error(`Invalid skill name in SKILL.md: ${String(skillName)}`);
|
|
327
|
+
}
|
|
328
|
+
const frontmatter = validateFrontmatter(raw);
|
|
295
329
|
const references = {};
|
|
296
330
|
const assets = {};
|
|
297
331
|
const scripts = {};
|
|
@@ -0,0 +1,53 @@
|
|
|
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 get_user_choice_tool_exports = {};
|
|
26
|
+
__export(get_user_choice_tool_exports, {
|
|
27
|
+
getUserChoiceTool: () => getUserChoiceTool
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(get_user_choice_tool_exports);
|
|
30
|
+
var import_zod = require("zod");
|
|
31
|
+
var import_long_running_tool = require("./long_running_tool.js");
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2026 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
const getUserChoiceTool = new import_long_running_tool.LongRunningFunctionTool({
|
|
38
|
+
name: "get_user_choice",
|
|
39
|
+
description: "Presents a list of options to the user and awaits their selection.",
|
|
40
|
+
parameters: import_zod.z.object({
|
|
41
|
+
options: import_zod.z.array(import_zod.z.string()).describe("List of options to present to the user.")
|
|
42
|
+
}),
|
|
43
|
+
execute: async (input, context) => {
|
|
44
|
+
if (context) {
|
|
45
|
+
context.actions.skipSummarization = true;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
getUserChoiceTool
|
|
53
|
+
});
|
|
@@ -30,11 +30,16 @@ module.exports = __toCommonJS(mcp_session_manager_exports);
|
|
|
30
30
|
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
|
31
31
|
var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
32
32
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
33
|
+
var import_error_utils = require("../../utils/error_utils.js");
|
|
34
|
+
var import_logger = require("../../utils/logger.js");
|
|
33
35
|
/**
|
|
34
36
|
* @license
|
|
35
37
|
* Copyright 2025 Google LLC
|
|
36
38
|
* SPDX-License-Identifier: Apache-2.0
|
|
37
39
|
*/
|
|
40
|
+
function logTransportError(err) {
|
|
41
|
+
import_logger.logger.error("MCP transport error: " + (0, import_error_utils.formatError)(err));
|
|
42
|
+
}
|
|
38
43
|
class MCPSessionManager {
|
|
39
44
|
constructor(connectionParams) {
|
|
40
45
|
this.activeSessions = /* @__PURE__ */ new Set();
|
|
@@ -43,31 +48,40 @@ class MCPSessionManager {
|
|
|
43
48
|
async createSession() {
|
|
44
49
|
var _a;
|
|
45
50
|
const client = new import_client.Client({ name: "MCPClient", version: "1.0.0" });
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
new import_stdio.StdioClientTransport(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
options.requestInit = {
|
|
56
|
-
headers: this.connectionParams.header
|
|
57
|
-
};
|
|
51
|
+
try {
|
|
52
|
+
switch (this.connectionParams.type) {
|
|
53
|
+
case "StdioConnectionParams": {
|
|
54
|
+
const transport = new import_stdio.StdioClientTransport(
|
|
55
|
+
this.connectionParams.serverParams
|
|
56
|
+
);
|
|
57
|
+
transport.onerror = logTransportError;
|
|
58
|
+
await client.connect(transport);
|
|
59
|
+
break;
|
|
58
60
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
case "StreamableHTTPConnectionParams": {
|
|
62
|
+
const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
|
|
63
|
+
if (!options.requestInit && this.connectionParams.header !== void 0) {
|
|
64
|
+
options.requestInit = {
|
|
65
|
+
headers: this.connectionParams.header
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const transport = new import_streamableHttp.StreamableHTTPClientTransport(
|
|
61
69
|
new URL(this.connectionParams.url),
|
|
62
70
|
options
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
);
|
|
72
|
+
transport.onerror = logTransportError;
|
|
73
|
+
await client.connect(transport);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
default: {
|
|
77
|
+
const _exhaustiveCheck = this.connectionParams;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
70
80
|
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
throw new Error("Failed to create MCP session: " + (0, import_error_utils.formatError)(err), {
|
|
83
|
+
cause: err
|
|
84
|
+
});
|
|
71
85
|
}
|
|
72
86
|
this.activeSessions.add(client);
|
|
73
87
|
return client;
|
|
@@ -0,0 +1,54 @@
|
|
|
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 request_input_tool_exports = {};
|
|
26
|
+
__export(request_input_tool_exports, {
|
|
27
|
+
requestInputTool: () => requestInputTool
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(request_input_tool_exports);
|
|
30
|
+
var import_zod = require("zod");
|
|
31
|
+
var import_long_running_tool = require("./long_running_tool.js");
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2026 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
const requestInputTool = new import_long_running_tool.LongRunningFunctionTool({
|
|
38
|
+
name: "adk_request_input",
|
|
39
|
+
description: "Presents a custom message to the user and awaits unstructured or structured input.",
|
|
40
|
+
parameters: import_zod.z.object({
|
|
41
|
+
message: import_zod.z.string().describe("The prompt for the user."),
|
|
42
|
+
responseSchema: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional().describe("Expected schema of the response.")
|
|
43
|
+
}),
|
|
44
|
+
execute: async (input, context) => {
|
|
45
|
+
if (context) {
|
|
46
|
+
context.actions.skipSummarization = true;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
requestInputTool
|
|
54
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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 crypto_shim_exports = {};
|
|
26
|
+
__export(crypto_shim_exports, {
|
|
27
|
+
randomUUID: () => randomUUID
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(crypto_shim_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
function randomUUID() {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"randomUUID: no cryptographically secure source of randomness is available. Neither crypto.randomUUID() nor crypto.getRandomValues() is present in this environment."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
randomUUID
|
|
43
|
+
});
|