@softactivate/adk 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/functions.js +4 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/common.js +3 -0
- package/dist/cjs/events/event.js +2 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
- package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
- package/dist/cjs/integrations/agent_registry/types.js +50 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
- package/dist/cjs/runner/in_memory_runner.js +10 -5
- package/dist/cjs/runner/runner.js +32 -2
- package/dist/cjs/sessions/database_session_service.js +49 -3
- package/dist/cjs/sessions/in_memory_session_service.js +70 -14
- package/dist/cjs/sessions/registry.js +4 -0
- package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
- package/dist/cjs/tools/agent_tool.js +17 -8
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- package/dist/cjs/tools/long_running_tool.js +2 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +10 -7
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -2
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
- package/dist/cjs/utils/file_utils.js +28 -0
- package/dist/cjs/utils/gemini_schema_util.js +18 -0
- package/dist/cjs/utils/partial_copy.js +51 -0
- package/dist/cjs/utils/streaming_utils.js +167 -118
- package/dist/cjs/utils/vertex_ai_utils.js +50 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/functions.js +4 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/esm/code_executors/code_execution_utils.js +1 -1
- package/dist/esm/common.js +2 -0
- package/dist/esm/events/event.js +2 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
- package/dist/esm/integrations/agent_registry/helpers.js +28 -0
- package/dist/esm/integrations/agent_registry/types.js +20 -0
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
- package/dist/esm/runner/in_memory_runner.js +10 -5
- package/dist/esm/runner/runner.js +32 -2
- package/dist/esm/sessions/database_session_service.js +49 -3
- package/dist/esm/sessions/in_memory_session_service.js +70 -14
- package/dist/esm/sessions/registry.js +7 -0
- package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
- package/dist/esm/tools/agent_tool.js +17 -8
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- package/dist/esm/tools/long_running_tool.js +2 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/esm/tools/mcp/mcp_tool.js +10 -7
- package/dist/esm/tools/mcp/mcp_toolset.js +10 -2
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/esm/utils/file_utils.js +26 -0
- package/dist/esm/utils/gemini_schema_util.js +18 -0
- package/dist/esm/utils/partial_copy.js +23 -0
- package/dist/esm/utils/streaming_utils.js +165 -117
- package/dist/esm/utils/vertex_ai_utils.js +22 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
- package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/run_config.d.ts +15 -0
- package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
- package/dist/types/common.d.ts +2 -0
- package/dist/types/events/event_actions.d.ts +24 -6
- package/dist/types/events/structured_events.d.ts +13 -0
- package/dist/types/examples/example_util.d.ts +25 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
- package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
- package/dist/types/integrations/agent_registry/types.d.ts +101 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
- package/dist/types/runner/in_memory_runner.d.ts +28 -1
- package/dist/types/runner/runner.d.ts +47 -0
- package/dist/types/sessions/base_session_service.d.ts +18 -0
- package/dist/types/sessions/database_session_service.d.ts +1 -1
- package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
- package/dist/types/tools/exit_loop_tool.d.ts +9 -0
- package/dist/types/tools/function_tool.d.ts +22 -2
- package/dist/types/tools/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
- package/dist/types/utils/file_utils.d.ts +2 -0
- package/dist/types/utils/partial_copy.d.ts +13 -0
- package/dist/types/utils/streaming_utils.d.ts +8 -17
- package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/functions.js +4 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/web/code_executors/code_execution_utils.js +1 -1
- package/dist/web/common.js +2 -0
- package/dist/web/events/event.js +2 -0
- package/dist/web/index.js +11 -0
- package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
- package/dist/web/integrations/agent_registry/helpers.js +28 -0
- package/dist/web/integrations/agent_registry/types.js +20 -0
- package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
- package/dist/web/runner/in_memory_runner.js +10 -5
- package/dist/web/runner/runner.js +32 -2
- package/dist/web/sessions/database_session_service.js +49 -3
- package/dist/web/sessions/in_memory_session_service.js +70 -14
- package/dist/web/sessions/registry.js +7 -0
- package/dist/web/sessions/vertex_ai_session_service.js +414 -0
- package/dist/web/tools/agent_tool.js +17 -8
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- package/dist/web/tools/long_running_tool.js +2 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/web/tools/mcp/mcp_tool.js +10 -7
- package/dist/web/tools/mcp/mcp_toolset.js +10 -2
- package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/web/utils/file_utils.js +26 -0
- package/dist/web/utils/gemini_schema_util.js +18 -0
- package/dist/web/utils/partial_copy.js +23 -0
- package/dist/web/utils/streaming_utils.js +218 -117
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -1
|
@@ -129,25 +129,81 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
129
129
|
}
|
|
130
130
|
listSessions({
|
|
131
131
|
appName,
|
|
132
|
-
userId
|
|
132
|
+
userId,
|
|
133
|
+
limit,
|
|
134
|
+
offset,
|
|
135
|
+
page,
|
|
136
|
+
order
|
|
133
137
|
}) {
|
|
134
138
|
if (!this.sessions[appName] || !this.sessions[appName][userId]) {
|
|
135
|
-
|
|
139
|
+
if (limit !== void 0) {
|
|
140
|
+
const effectiveOffset2 = page !== void 0 ? (page - 1) * limit : offset != null ? offset : 0;
|
|
141
|
+
const effectivePage2 = page !== void 0 ? page : limit === 0 ? 1 : Math.floor(effectiveOffset2 / limit) + 1;
|
|
142
|
+
return Promise.resolve({
|
|
143
|
+
sessions: [],
|
|
144
|
+
page: effectivePage2,
|
|
145
|
+
limit,
|
|
146
|
+
totalItems: 0,
|
|
147
|
+
totalPages: 0
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return Promise.resolve({
|
|
151
|
+
sessions: [],
|
|
152
|
+
page: 1,
|
|
153
|
+
limit: 0,
|
|
154
|
+
totalItems: 0,
|
|
155
|
+
totalPages: 0
|
|
156
|
+
});
|
|
136
157
|
}
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
158
|
+
const all = Object.values(this.sessions[appName][userId]).map(
|
|
159
|
+
(session) => (0, import_session.createSession)({
|
|
160
|
+
id: session.id,
|
|
161
|
+
appName: session.appName,
|
|
162
|
+
userId: session.userId,
|
|
163
|
+
state: {},
|
|
164
|
+
events: [],
|
|
165
|
+
lastUpdateTime: session.lastUpdateTime
|
|
166
|
+
})
|
|
167
|
+
);
|
|
168
|
+
if (order === "asc") {
|
|
169
|
+
all.sort(
|
|
170
|
+
(a, b) => a.lastUpdateTime - b.lastUpdateTime || a.id.localeCompare(b.id)
|
|
171
|
+
);
|
|
172
|
+
} else if (order === "desc") {
|
|
173
|
+
all.sort(
|
|
174
|
+
(a, b) => b.lastUpdateTime - a.lastUpdateTime || a.id.localeCompare(b.id)
|
|
148
175
|
);
|
|
149
176
|
}
|
|
150
|
-
|
|
177
|
+
if (limit === void 0) {
|
|
178
|
+
const totalItems2 = all.length;
|
|
179
|
+
const sliced = offset ? all.slice(offset) : all;
|
|
180
|
+
return Promise.resolve({
|
|
181
|
+
sessions: sliced,
|
|
182
|
+
page: 1,
|
|
183
|
+
limit: totalItems2,
|
|
184
|
+
totalItems: totalItems2,
|
|
185
|
+
totalPages: totalItems2 === 0 ? 0 : 1
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
const totalItems = all.length;
|
|
189
|
+
const totalPages = limit === 0 ? 0 : Math.ceil(totalItems / limit);
|
|
190
|
+
let effectiveOffset;
|
|
191
|
+
let effectivePage;
|
|
192
|
+
if (page !== void 0) {
|
|
193
|
+
effectiveOffset = (page - 1) * limit;
|
|
194
|
+
effectivePage = page;
|
|
195
|
+
} else {
|
|
196
|
+
effectiveOffset = offset != null ? offset : 0;
|
|
197
|
+
effectivePage = limit === 0 ? 1 : Math.floor(effectiveOffset / limit) + 1;
|
|
198
|
+
}
|
|
199
|
+
const paginated = all.slice(effectiveOffset, effectiveOffset + limit);
|
|
200
|
+
return Promise.resolve({
|
|
201
|
+
sessions: paginated,
|
|
202
|
+
page: effectivePage,
|
|
203
|
+
limit,
|
|
204
|
+
totalItems,
|
|
205
|
+
totalPages
|
|
206
|
+
});
|
|
151
207
|
}
|
|
152
208
|
async deleteSession({
|
|
153
209
|
appName,
|
|
@@ -29,6 +29,7 @@ __export(registry_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(registry_exports);
|
|
30
30
|
var import_database_session_service = require("./database_session_service.js");
|
|
31
31
|
var import_in_memory_session_service = require("./in_memory_session_service.js");
|
|
32
|
+
var import_vertex_ai_session_service = require("./vertex_ai_session_service.js");
|
|
32
33
|
/**
|
|
33
34
|
* @license
|
|
34
35
|
* Copyright 2026 Google LLC
|
|
@@ -41,6 +42,9 @@ function getSessionServiceFromUri(uri) {
|
|
|
41
42
|
if ((0, import_database_session_service.isDatabaseConnectionString)(uri)) {
|
|
42
43
|
return new import_database_session_service.DatabaseSessionService(uri);
|
|
43
44
|
}
|
|
45
|
+
if ((0, import_vertex_ai_session_service.isVertexAiConnectionString)(uri)) {
|
|
46
|
+
return new import_vertex_ai_session_service.VertexAiSessionService({});
|
|
47
|
+
}
|
|
44
48
|
throw new Error(`Unsupported session service URI: ${uri}`);
|
|
45
49
|
}
|
|
46
50
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -0,0 +1,428 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
26
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
27
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
28
|
+
if (decorator = decorators[i])
|
|
29
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
30
|
+
if (kind && result) __defProp(target, key, result);
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
var vertex_ai_session_service_exports = {};
|
|
34
|
+
__export(vertex_ai_session_service_exports, {
|
|
35
|
+
VertexAiSessionService: () => VertexAiSessionService,
|
|
36
|
+
isVertexAiConnectionString: () => isVertexAiConnectionString
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(vertex_ai_session_service_exports);
|
|
39
|
+
var import_client = require("@google-cloud/vertexai/build/src/genai/client.js");
|
|
40
|
+
var import_compacted_event = require("../events/compacted_event.js");
|
|
41
|
+
var import_experimental = require("../utils/experimental.js");
|
|
42
|
+
var import_logger = require("../utils/logger.js");
|
|
43
|
+
var import_vertex_ai_utils = require("../utils/vertex_ai_utils.js");
|
|
44
|
+
var import_partial_copy = require("../utils/partial_copy.js");
|
|
45
|
+
var import_base_session_service = require("./base_session_service.js");
|
|
46
|
+
var import_session = require("./session.js");
|
|
47
|
+
/**
|
|
48
|
+
* @license
|
|
49
|
+
* Copyright 2026 Google LLC
|
|
50
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
51
|
+
*/
|
|
52
|
+
const DEFAULT_MAX_ATTEMPTS = 30;
|
|
53
|
+
const GRPC_NOT_FOUND = 5;
|
|
54
|
+
const HTTP_NOT_FOUND = 404;
|
|
55
|
+
function isVertexAiConnectionString(uri) {
|
|
56
|
+
return (uri == null ? void 0 : uri.startsWith("vertexai://")) || false;
|
|
57
|
+
}
|
|
58
|
+
let VertexAiSessionService = class extends import_base_session_service.BaseSessionService {
|
|
59
|
+
constructor(options) {
|
|
60
|
+
super();
|
|
61
|
+
this.agentEngineId = options.agentEngineId;
|
|
62
|
+
this.projectId = options.projectId;
|
|
63
|
+
this.location = options.location;
|
|
64
|
+
this.expressModeApiKey = (0, import_vertex_ai_utils.getExpressModeApiKey)(
|
|
65
|
+
this.projectId,
|
|
66
|
+
this.location,
|
|
67
|
+
options.expressModeApiKey
|
|
68
|
+
);
|
|
69
|
+
if (!options.sessions) {
|
|
70
|
+
if (!this.expressModeApiKey && (!this.projectId || !this.location)) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"Either (Project ID and Location) or an expressModeApiKey is required."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (options.sessions) {
|
|
77
|
+
this.sessions = options.sessions;
|
|
78
|
+
} else {
|
|
79
|
+
const client = new import_client.Client({
|
|
80
|
+
project: this.projectId,
|
|
81
|
+
location: this.location
|
|
82
|
+
});
|
|
83
|
+
this.sessions = client.agentEnginesInternal.sessions;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
getReasoningEngineId(appName) {
|
|
87
|
+
if (this.agentEngineId) {
|
|
88
|
+
return this.agentEngineId;
|
|
89
|
+
}
|
|
90
|
+
if (/^\d+$/.test(appName)) {
|
|
91
|
+
return appName;
|
|
92
|
+
}
|
|
93
|
+
const pattern = /^projects\/([a-zA-Z0-9-_]+)\/locations\/([a-zA-Z0-9-_]+)\/reasoningEngines\/(\d+)$/;
|
|
94
|
+
const match = appName.match(pattern);
|
|
95
|
+
if (!match) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`App name ${appName} is not valid. It should either be the full ReasoningEngine resource name, or the reasoning engine id.`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return match[3];
|
|
101
|
+
}
|
|
102
|
+
async createSession({
|
|
103
|
+
appName,
|
|
104
|
+
userId,
|
|
105
|
+
state,
|
|
106
|
+
sessionId
|
|
107
|
+
}) {
|
|
108
|
+
var _a;
|
|
109
|
+
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
110
|
+
let apiResponse = await this.sessions.createInternal({
|
|
111
|
+
name: `reasoningEngines/${reasoningEngineId}`,
|
|
112
|
+
userId,
|
|
113
|
+
config: {
|
|
114
|
+
...state ? { sessionState: state } : {},
|
|
115
|
+
...sessionId ? { sessionId } : {}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
const operationName = apiResponse.name;
|
|
119
|
+
let attempts = 0;
|
|
120
|
+
while (!apiResponse.done && attempts < DEFAULT_MAX_ATTEMPTS) {
|
|
121
|
+
const [nextResponse] = await Promise.all([
|
|
122
|
+
this.sessions.getSessionOperationInternal({
|
|
123
|
+
operationName
|
|
124
|
+
}),
|
|
125
|
+
new Promise((resolve) => setTimeout(resolve, 1e3))
|
|
126
|
+
]);
|
|
127
|
+
apiResponse = nextResponse;
|
|
128
|
+
attempts++;
|
|
129
|
+
}
|
|
130
|
+
if (!apiResponse.done) {
|
|
131
|
+
throw new Error(
|
|
132
|
+
`Session creation operation ${operationName} did not complete in time.`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
const getSessionResponse = apiResponse.response;
|
|
136
|
+
const id = ((_a = getSessionResponse.name) == null ? void 0 : _a.split("/").pop()) || "";
|
|
137
|
+
return (0, import_session.createSession)({
|
|
138
|
+
id,
|
|
139
|
+
appName,
|
|
140
|
+
userId,
|
|
141
|
+
state: getSessionResponse.sessionState,
|
|
142
|
+
events: [],
|
|
143
|
+
lastUpdateTime: getSessionResponse.updateTime ? Date.parse(getSessionResponse.updateTime) : Date.now()
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async getSession({
|
|
147
|
+
appName,
|
|
148
|
+
userId,
|
|
149
|
+
sessionId,
|
|
150
|
+
config
|
|
151
|
+
}) {
|
|
152
|
+
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
153
|
+
const sessionResourceName = `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`;
|
|
154
|
+
try {
|
|
155
|
+
let getSessionResponse;
|
|
156
|
+
let eventsIterator = [];
|
|
157
|
+
if (config && config.numRecentEvents === 0) {
|
|
158
|
+
getSessionResponse = await this.sessions.get({
|
|
159
|
+
name: sessionResourceName
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
const listConfig = {};
|
|
163
|
+
if (config && config.afterTimestamp) {
|
|
164
|
+
listConfig.filter = `timestamp>="${new Date(
|
|
165
|
+
config.afterTimestamp
|
|
166
|
+
).toISOString()}"`;
|
|
167
|
+
}
|
|
168
|
+
const [sessionRes, eventsRes] = await Promise.all([
|
|
169
|
+
this.sessions.get({ name: sessionResourceName }),
|
|
170
|
+
this.sessions.events.listInternal({
|
|
171
|
+
name: sessionResourceName,
|
|
172
|
+
config: listConfig
|
|
173
|
+
})
|
|
174
|
+
]);
|
|
175
|
+
getSessionResponse = sessionRes;
|
|
176
|
+
eventsIterator = eventsRes.sessionEvents || [];
|
|
177
|
+
}
|
|
178
|
+
const sessionObj = getSessionResponse;
|
|
179
|
+
if (sessionObj.userId !== userId) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
`Session ${sessionId} does not belong to user ${userId}.`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
const session = (0, import_session.createSession)({
|
|
185
|
+
id: sessionId,
|
|
186
|
+
appName,
|
|
187
|
+
userId,
|
|
188
|
+
state: sessionObj.sessionState,
|
|
189
|
+
events: [],
|
|
190
|
+
lastUpdateTime: sessionObj.updateTime ? Date.parse(sessionObj.updateTime) : Date.now()
|
|
191
|
+
});
|
|
192
|
+
for (const event of eventsIterator) {
|
|
193
|
+
session.events.push(_fromApiEvent(event));
|
|
194
|
+
}
|
|
195
|
+
if (config && config.numRecentEvents) {
|
|
196
|
+
session.events = session.events.slice(-config.numRecentEvents);
|
|
197
|
+
}
|
|
198
|
+
return session;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
const err = error;
|
|
201
|
+
if (err.code === GRPC_NOT_FOUND || err.code === HTTP_NOT_FOUND) {
|
|
202
|
+
return void 0;
|
|
203
|
+
}
|
|
204
|
+
import_logger.logger.error(`Error getting session from Vertex AI: ${err.message}`);
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async listSessions({
|
|
209
|
+
appName,
|
|
210
|
+
userId,
|
|
211
|
+
limit,
|
|
212
|
+
offset,
|
|
213
|
+
page,
|
|
214
|
+
order
|
|
215
|
+
}) {
|
|
216
|
+
var _a;
|
|
217
|
+
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
218
|
+
const adkSessions = [];
|
|
219
|
+
let pageToken = void 0;
|
|
220
|
+
do {
|
|
221
|
+
const response = await this.sessions.listInternal({
|
|
222
|
+
name: `reasoningEngines/${reasoningEngineId}`,
|
|
223
|
+
config: {
|
|
224
|
+
...userId ? { filter: `user_id="${userId}"` } : {},
|
|
225
|
+
...pageToken ? { pageToken } : {}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
const sessions = response.sessions || [];
|
|
229
|
+
for (const sessionObj of sessions) {
|
|
230
|
+
const id = ((_a = sessionObj.name) == null ? void 0 : _a.split("/").pop()) || "";
|
|
231
|
+
adkSessions.push(
|
|
232
|
+
(0, import_session.createSession)({
|
|
233
|
+
id,
|
|
234
|
+
appName,
|
|
235
|
+
userId: sessionObj.userId,
|
|
236
|
+
state: sessionObj.sessionState,
|
|
237
|
+
events: [],
|
|
238
|
+
lastUpdateTime: sessionObj.updateTime ? new Date(sessionObj.updateTime).getTime() : Date.now()
|
|
239
|
+
})
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
pageToken = response.nextPageToken;
|
|
243
|
+
} while (pageToken);
|
|
244
|
+
if (order === "asc") {
|
|
245
|
+
adkSessions.sort(
|
|
246
|
+
(a, b) => a.lastUpdateTime - b.lastUpdateTime || a.id.localeCompare(b.id)
|
|
247
|
+
);
|
|
248
|
+
} else if (order === "desc") {
|
|
249
|
+
adkSessions.sort(
|
|
250
|
+
(a, b) => b.lastUpdateTime - a.lastUpdateTime || a.id.localeCompare(b.id)
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
if (limit === void 0) {
|
|
254
|
+
const totalItems2 = adkSessions.length;
|
|
255
|
+
const sliced = offset ? adkSessions.slice(offset) : adkSessions;
|
|
256
|
+
return {
|
|
257
|
+
sessions: sliced,
|
|
258
|
+
page: 1,
|
|
259
|
+
limit: totalItems2,
|
|
260
|
+
totalItems: totalItems2,
|
|
261
|
+
totalPages: totalItems2 === 0 ? 0 : 1
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const totalItems = adkSessions.length;
|
|
265
|
+
const totalPages = limit === 0 ? 0 : Math.ceil(totalItems / limit);
|
|
266
|
+
let effectiveOffset;
|
|
267
|
+
let effectivePage;
|
|
268
|
+
if (page !== void 0) {
|
|
269
|
+
effectiveOffset = (page - 1) * limit;
|
|
270
|
+
effectivePage = page;
|
|
271
|
+
} else {
|
|
272
|
+
effectiveOffset = offset != null ? offset : 0;
|
|
273
|
+
effectivePage = limit === 0 ? 1 : Math.floor(effectiveOffset / limit) + 1;
|
|
274
|
+
}
|
|
275
|
+
return {
|
|
276
|
+
sessions: adkSessions.slice(effectiveOffset, effectiveOffset + limit),
|
|
277
|
+
page: effectivePage,
|
|
278
|
+
limit,
|
|
279
|
+
totalItems,
|
|
280
|
+
totalPages
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
async deleteSession({
|
|
284
|
+
appName,
|
|
285
|
+
userId: _userId,
|
|
286
|
+
sessionId
|
|
287
|
+
}) {
|
|
288
|
+
const reasoningEngineId = this.getReasoningEngineId(appName);
|
|
289
|
+
await this.sessions.delete({
|
|
290
|
+
name: `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async appendEvent({
|
|
294
|
+
session,
|
|
295
|
+
event
|
|
296
|
+
}) {
|
|
297
|
+
await super.appendEvent({ session, event });
|
|
298
|
+
session.lastUpdateTime = event.timestamp;
|
|
299
|
+
const reasoningEngineId = this.getReasoningEngineId(session.appName);
|
|
300
|
+
const customMetadata = { ...event.customMetadata };
|
|
301
|
+
if ((0, import_compacted_event.isCompactedEvent)(event)) {
|
|
302
|
+
customMetadata._compaction = {
|
|
303
|
+
startTime: event.startTime,
|
|
304
|
+
endTime: event.endTime,
|
|
305
|
+
compactedContent: event.compactedContent
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
if (event.usageMetadata) {
|
|
309
|
+
customMetadata._usage_metadata = event.usageMetadata;
|
|
310
|
+
}
|
|
311
|
+
const config = (0, import_partial_copy.partialCopy)(event, [
|
|
312
|
+
"content",
|
|
313
|
+
"actions",
|
|
314
|
+
"errorCode",
|
|
315
|
+
"errorMessage"
|
|
316
|
+
]);
|
|
317
|
+
config.eventMetadata = {
|
|
318
|
+
...(0, import_partial_copy.partialCopy)(event, [
|
|
319
|
+
"partial",
|
|
320
|
+
"turnComplete",
|
|
321
|
+
"interrupted",
|
|
322
|
+
"branch",
|
|
323
|
+
"longRunningToolIds",
|
|
324
|
+
"groundingMetadata"
|
|
325
|
+
]),
|
|
326
|
+
customMetadata: Object.keys(customMetadata).length > 0 ? customMetadata : void 0
|
|
327
|
+
};
|
|
328
|
+
config.rawEvent = JSON.parse(JSON.stringify(event));
|
|
329
|
+
const params = {
|
|
330
|
+
name: `reasoningEngines/${reasoningEngineId}/sessions/${session.id}`,
|
|
331
|
+
author: event.author || "user",
|
|
332
|
+
invocationId: event.invocationId || `inv-${Date.now()}`,
|
|
333
|
+
timestamp: new Date(event.timestamp).toISOString(),
|
|
334
|
+
config
|
|
335
|
+
};
|
|
336
|
+
try {
|
|
337
|
+
await this.sessions.events.append(params);
|
|
338
|
+
} catch (error) {
|
|
339
|
+
import_logger.logger.warn(
|
|
340
|
+
"Failed to append event with rawEvent, falling back...",
|
|
341
|
+
error
|
|
342
|
+
);
|
|
343
|
+
delete config.rawEvent;
|
|
344
|
+
await this.sessions.events.append({
|
|
345
|
+
name: `reasoningEngines/${reasoningEngineId}/sessions/${session.id}`,
|
|
346
|
+
author: event.author || "user",
|
|
347
|
+
invocationId: event.invocationId || `inv-${Date.now()}`,
|
|
348
|
+
timestamp: new Date(event.timestamp).toISOString(),
|
|
349
|
+
config
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return event;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
VertexAiSessionService = __decorateClass([
|
|
356
|
+
import_experimental.experimental
|
|
357
|
+
], VertexAiSessionService);
|
|
358
|
+
function _fromApiEvent(apiEventObj) {
|
|
359
|
+
var _a, _b, _c;
|
|
360
|
+
const rawEvent = apiEventObj.rawEvent;
|
|
361
|
+
if (rawEvent) {
|
|
362
|
+
const event2 = JSON.parse(JSON.stringify(rawEvent));
|
|
363
|
+
event2.id = ((_a = apiEventObj.name) == null ? void 0 : _a.split("/").pop()) || "";
|
|
364
|
+
event2.invocationId = apiEventObj.invocationId || "";
|
|
365
|
+
event2.author = apiEventObj.author;
|
|
366
|
+
if (apiEventObj.timestamp) {
|
|
367
|
+
event2.timestamp = new Date(apiEventObj.timestamp).getTime();
|
|
368
|
+
}
|
|
369
|
+
return event2;
|
|
370
|
+
}
|
|
371
|
+
const actions = apiEventObj.actions || {};
|
|
372
|
+
const eventMetadata = apiEventObj.eventMetadata || {};
|
|
373
|
+
let customMetadata = eventMetadata.customMetadata;
|
|
374
|
+
let compactionData = null;
|
|
375
|
+
let usageMetadataData = null;
|
|
376
|
+
if (customMetadata) {
|
|
377
|
+
if (customMetadata._compaction) {
|
|
378
|
+
compactionData = customMetadata._compaction;
|
|
379
|
+
delete customMetadata._compaction;
|
|
380
|
+
}
|
|
381
|
+
if (customMetadata._usage_metadata) {
|
|
382
|
+
usageMetadataData = customMetadata._usage_metadata;
|
|
383
|
+
delete customMetadata._usage_metadata;
|
|
384
|
+
}
|
|
385
|
+
if (Object.keys(customMetadata).length === 0) {
|
|
386
|
+
customMetadata = void 0;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
const eventActions = {
|
|
390
|
+
stateDelta: actions["stateDelta"] || {},
|
|
391
|
+
artifactDelta: actions["artifactDelta"] || {},
|
|
392
|
+
requestedAuthConfigs: actions.requestedAuthConfigs || {},
|
|
393
|
+
requestedToolConfirmations: actions["requestedToolConfirmations"] || {},
|
|
394
|
+
skipSummarization: actions["skipSummarization"],
|
|
395
|
+
transferToAgent: actions["transferAgent"],
|
|
396
|
+
escalate: actions["escalate"],
|
|
397
|
+
compaction: compactionData || void 0
|
|
398
|
+
};
|
|
399
|
+
const event = {
|
|
400
|
+
id: ((_b = apiEventObj.name) == null ? void 0 : _b.split("/").pop()) || "",
|
|
401
|
+
invocationId: apiEventObj.invocationId || "",
|
|
402
|
+
author: apiEventObj.author,
|
|
403
|
+
actions: eventActions,
|
|
404
|
+
content: apiEventObj.content,
|
|
405
|
+
timestamp: apiEventObj.timestamp ? new Date(apiEventObj.timestamp).getTime() : Date.now(),
|
|
406
|
+
errorCode: (_c = apiEventObj.errorCode) == null ? void 0 : _c.toString(),
|
|
407
|
+
errorMessage: apiEventObj.errorMessage,
|
|
408
|
+
partial: eventMetadata["partial"],
|
|
409
|
+
turnComplete: eventMetadata["turnComplete"],
|
|
410
|
+
interrupted: eventMetadata["interrupted"],
|
|
411
|
+
branch: eventMetadata["branch"],
|
|
412
|
+
customMetadata,
|
|
413
|
+
longRunningToolIds: eventMetadata["longRunningToolIds"],
|
|
414
|
+
usageMetadata: usageMetadataData
|
|
415
|
+
};
|
|
416
|
+
if (compactionData) {
|
|
417
|
+
event.isCompacted = true;
|
|
418
|
+
event.startTime = compactionData.startTime;
|
|
419
|
+
event.endTime = compactionData.endTime;
|
|
420
|
+
event.compactedContent = compactionData.compactedContent;
|
|
421
|
+
}
|
|
422
|
+
return event;
|
|
423
|
+
}
|
|
424
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
425
|
+
0 && (module.exports = {
|
|
426
|
+
VertexAiSessionService,
|
|
427
|
+
isVertexAiConnectionString
|
|
428
|
+
});
|
|
@@ -34,6 +34,7 @@ var import_in_memory_memory_service = require("../memory/in_memory_memory_servic
|
|
|
34
34
|
var import_runner = require("../runner/runner.js");
|
|
35
35
|
var import_in_memory_session_service = require("../sessions/in_memory_session_service.js");
|
|
36
36
|
var import_variant_utils = require("../utils/variant_utils.js");
|
|
37
|
+
var import_state = require("../sessions/state.js");
|
|
37
38
|
var import_base_tool = require("./base_tool.js");
|
|
38
39
|
var import_forwarding_artifact_service = require("./forwarding_artifact_service.js");
|
|
39
40
|
/**
|
|
@@ -150,9 +151,6 @@ class AgentTool extends (_b = import_base_tool.BaseTool, _a = AGENT_TOOL_SIGNATU
|
|
|
150
151
|
toolContext
|
|
151
152
|
}) {
|
|
152
153
|
var _a2, _b2;
|
|
153
|
-
if (this.skipSummarization) {
|
|
154
|
-
toolContext.actions.skipSummarization = true;
|
|
155
|
-
}
|
|
156
154
|
const { runner, content, sessionUserId, sessionId } = await this.setupRunnerAndSession({ args, toolContext });
|
|
157
155
|
if ((_a2 = toolContext.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
158
156
|
return "";
|
|
@@ -169,7 +167,14 @@ class AgentTool extends (_b = import_base_tool.BaseTool, _a = AGENT_TOOL_SIGNATU
|
|
|
169
167
|
return;
|
|
170
168
|
}
|
|
171
169
|
if (event.actions.stateDelta) {
|
|
172
|
-
|
|
170
|
+
const filteredDelta = Object.fromEntries(
|
|
171
|
+
Object.entries(event.actions.stateDelta).filter(
|
|
172
|
+
([key]) => !key.startsWith(import_state.State.TEMP_PREFIX)
|
|
173
|
+
)
|
|
174
|
+
);
|
|
175
|
+
if (Object.keys(filteredDelta).length > 0) {
|
|
176
|
+
toolContext.state.update(filteredDelta);
|
|
177
|
+
}
|
|
173
178
|
}
|
|
174
179
|
lastEvent = event;
|
|
175
180
|
}
|
|
@@ -188,9 +193,6 @@ class AgentTool extends (_b = import_base_tool.BaseTool, _a = AGENT_TOOL_SIGNATU
|
|
|
188
193
|
toolContext
|
|
189
194
|
}) {
|
|
190
195
|
var _a2, _b2;
|
|
191
|
-
if (this.skipSummarization) {
|
|
192
|
-
toolContext.actions.skipSummarization = true;
|
|
193
|
-
}
|
|
194
196
|
const { runner, content, sessionUserId, sessionId } = await this.setupRunnerAndSession({ args, toolContext });
|
|
195
197
|
if ((_a2 = toolContext.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
196
198
|
return;
|
|
@@ -206,7 +208,14 @@ class AgentTool extends (_b = import_base_tool.BaseTool, _a = AGENT_TOOL_SIGNATU
|
|
|
206
208
|
return;
|
|
207
209
|
}
|
|
208
210
|
if (event.actions.stateDelta) {
|
|
209
|
-
|
|
211
|
+
const filteredDelta = Object.fromEntries(
|
|
212
|
+
Object.entries(event.actions.stateDelta).filter(
|
|
213
|
+
([key]) => !key.startsWith(import_state.State.TEMP_PREFIX)
|
|
214
|
+
)
|
|
215
|
+
);
|
|
216
|
+
if (Object.keys(filteredDelta).length > 0) {
|
|
217
|
+
toolContext.state.update(filteredDelta);
|
|
218
|
+
}
|
|
210
219
|
}
|
|
211
220
|
yield event;
|
|
212
221
|
}
|
|
@@ -35,18 +35,27 @@ var import_base_tool = require("./base_tool.js");
|
|
|
35
35
|
* SPDX-License-Identifier: Apache-2.0
|
|
36
36
|
*/
|
|
37
37
|
class ExitLoopTool extends import_base_tool.BaseTool {
|
|
38
|
+
/** Creates an ExitLoopTool with its fixed name and description. */
|
|
38
39
|
constructor() {
|
|
39
40
|
super({
|
|
40
41
|
name: "exit_loop",
|
|
41
42
|
description: "Exits the loop.\n\nCall this function only when you are instructed to do so."
|
|
42
43
|
});
|
|
43
44
|
}
|
|
45
|
+
/** Returns the function declaration for this tool. */
|
|
44
46
|
_getDeclaration() {
|
|
45
47
|
return {
|
|
46
48
|
name: this.name,
|
|
47
49
|
description: this.description
|
|
48
50
|
};
|
|
49
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Sets `escalate` and `skipSummarization` on the event actions, signalling
|
|
54
|
+
* the {@link LoopAgent} to stop iterating.
|
|
55
|
+
*
|
|
56
|
+
* @param request The tool request containing the current tool context.
|
|
57
|
+
* @returns An empty string response.
|
|
58
|
+
*/
|
|
50
59
|
async runAsync({
|
|
51
60
|
toolContext
|
|
52
61
|
}) {
|
|
@@ -74,7 +74,8 @@ class FunctionTool extends (_b = import_base_tool.BaseTool, _a = FUNCTION_TOOL_S
|
|
|
74
74
|
this.parameters = options.parameters;
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Returns the function declaration derived from the tool's name, description,
|
|
78
|
+
* and parameter schema.
|
|
78
79
|
*/
|
|
79
80
|
_getDeclaration() {
|
|
80
81
|
return {
|
|
@@ -84,7 +85,11 @@ class FunctionTool extends (_b = import_base_tool.BaseTool, _a = FUNCTION_TOOL_S
|
|
|
84
85
|
};
|
|
85
86
|
}
|
|
86
87
|
/**
|
|
87
|
-
*
|
|
88
|
+
* Validates the model-provided arguments against the parameter schema and
|
|
89
|
+
* invokes the user-defined `execute` function.
|
|
90
|
+
*
|
|
91
|
+
* @param req The tool request containing arguments and tool context.
|
|
92
|
+
* @returns A promise resolving to the function's return value.
|
|
88
93
|
*/
|
|
89
94
|
async runAsync(req) {
|
|
90
95
|
try {
|
|
@@ -45,7 +45,8 @@ class LongRunningFunctionTool extends import_function_tool.FunctionTool {
|
|
|
45
45
|
super({ ...options, isLongRunning: true });
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
48
|
+
* Returns the function declaration with an appended instruction warning the
|
|
49
|
+
* model not to re-invoke the tool while it is still running.
|
|
49
50
|
*/
|
|
50
51
|
_getDeclaration() {
|
|
51
52
|
const declaration = super._getDeclaration();
|
|
@@ -37,6 +37,7 @@ var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamable
|
|
|
37
37
|
*/
|
|
38
38
|
class MCPSessionManager {
|
|
39
39
|
constructor(connectionParams) {
|
|
40
|
+
this.activeSessions = /* @__PURE__ */ new Set();
|
|
40
41
|
this.connectionParams = connectionParams;
|
|
41
42
|
}
|
|
42
43
|
async createSession() {
|
|
@@ -68,8 +69,18 @@ class MCPSessionManager {
|
|
|
68
69
|
break;
|
|
69
70
|
}
|
|
70
71
|
}
|
|
72
|
+
this.activeSessions.add(client);
|
|
71
73
|
return client;
|
|
72
74
|
}
|
|
75
|
+
async closeSession(client) {
|
|
76
|
+
if (this.activeSessions.has(client)) {
|
|
77
|
+
this.activeSessions.delete(client);
|
|
78
|
+
await client.close();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
getActiveSessions() {
|
|
82
|
+
return Array.from(this.activeSessions);
|
|
83
|
+
}
|
|
73
84
|
}
|
|
74
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
75
86
|
0 && (module.exports = {
|