@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
|
@@ -0,0 +1,496 @@
|
|
|
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 vertex_ai_memory_bank_service_exports = {};
|
|
26
|
+
__export(vertex_ai_memory_bank_service_exports, {
|
|
27
|
+
VertexAiMemoryBankService: () => VertexAiMemoryBankService
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(vertex_ai_memory_bank_service_exports);
|
|
30
|
+
var import_vertexai = require("@google-cloud/vertexai");
|
|
31
|
+
var import_genai = require("@google/genai");
|
|
32
|
+
var import_logger = require("../utils/logger.js");
|
|
33
|
+
var import_vertex_ai_utils = require("../utils/vertex_ai_utils.js");
|
|
34
|
+
/**
|
|
35
|
+
* @license
|
|
36
|
+
* Copyright 2026 Google LLC
|
|
37
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
38
|
+
*/
|
|
39
|
+
const GENERATE_MEMORIES_KNOWN_FIELDS = [
|
|
40
|
+
"disableConsolidation",
|
|
41
|
+
"waitForCompletion",
|
|
42
|
+
"revisionLabels",
|
|
43
|
+
"revisionExpireTime",
|
|
44
|
+
"revisionTtl",
|
|
45
|
+
"disableMemoryRevisions",
|
|
46
|
+
"metadataMergeStrategy",
|
|
47
|
+
"allowedTopics"
|
|
48
|
+
];
|
|
49
|
+
const CREATE_MEMORY_KNOWN_FIELDS = [
|
|
50
|
+
"displayName",
|
|
51
|
+
"description",
|
|
52
|
+
"waitForCompletion",
|
|
53
|
+
"ttl",
|
|
54
|
+
"expireTime",
|
|
55
|
+
"revisionExpireTime",
|
|
56
|
+
"revisionTtl",
|
|
57
|
+
"disableMemoryRevisions",
|
|
58
|
+
"topics",
|
|
59
|
+
"memoryId"
|
|
60
|
+
];
|
|
61
|
+
const ENABLE_CONSOLIDATION_KEY = "enable_consolidation";
|
|
62
|
+
const MAX_DIRECT_MEMORIES_PER_GENERATE_CALL = 5;
|
|
63
|
+
function shouldFilterOutEvent(content) {
|
|
64
|
+
return !((content == null ? void 0 : content.parts) || []).some(
|
|
65
|
+
(p) => p.text || p.inlineData || p.fileData
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function toVertexMetadataValue(key, value) {
|
|
69
|
+
if (typeof value === "boolean") {
|
|
70
|
+
return { boolValue: value };
|
|
71
|
+
}
|
|
72
|
+
if (typeof value === "number") {
|
|
73
|
+
return { doubleValue: value };
|
|
74
|
+
}
|
|
75
|
+
if (typeof value === "string") {
|
|
76
|
+
return { stringValue: value };
|
|
77
|
+
}
|
|
78
|
+
if (value instanceof Date) {
|
|
79
|
+
return { timestampValue: value.toISOString() };
|
|
80
|
+
}
|
|
81
|
+
if (typeof value === "object" && value !== null) {
|
|
82
|
+
const v = value;
|
|
83
|
+
if (v.boolValue !== void 0 || v.doubleValue !== void 0 || v.stringValue !== void 0 || v.timestampValue !== void 0) {
|
|
84
|
+
return v;
|
|
85
|
+
}
|
|
86
|
+
return { stringValue: JSON.stringify(value) };
|
|
87
|
+
}
|
|
88
|
+
if (value === null || value === void 0) {
|
|
89
|
+
import_logger.logger.warn(
|
|
90
|
+
`Ignoring custom metadata key ${key} because its value is null or undefined.`
|
|
91
|
+
);
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
return { stringValue: String(value) };
|
|
95
|
+
}
|
|
96
|
+
class VertexAiMemoryBankService {
|
|
97
|
+
constructor(options) {
|
|
98
|
+
if (!options.agentEngineId) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
"agentEngineId is required for VertexAiMemoryBankService."
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
this.projectId = options.projectId;
|
|
104
|
+
this.location = options.location;
|
|
105
|
+
this.agentEngineId = options.agentEngineId;
|
|
106
|
+
this.expressModeApiKey = (0, import_vertex_ai_utils.getExpressModeApiKey)(
|
|
107
|
+
options.projectId,
|
|
108
|
+
options.location,
|
|
109
|
+
options.expressModeApiKey
|
|
110
|
+
);
|
|
111
|
+
if (options.agentEngineId.includes("/")) {
|
|
112
|
+
import_logger.logger.warn(
|
|
113
|
+
`agentEngineId appears to be a full resource path: '${options.agentEngineId}'. Expected just the ID (e.g., '456'). Extract the ID using: agentEngine.apiResource.name.split('/').pop()`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (options.client) {
|
|
117
|
+
this.memories = options.client.agentEnginesInternal.memories;
|
|
118
|
+
} else {
|
|
119
|
+
const client = new import_vertexai.Client({
|
|
120
|
+
project: this.projectId,
|
|
121
|
+
location: this.location
|
|
122
|
+
});
|
|
123
|
+
this.memories = client.agentEnginesInternal.memories;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
async addSessionToMemory(session) {
|
|
127
|
+
await this.addEventsToMemoryFromEvents({
|
|
128
|
+
appName: session.appName,
|
|
129
|
+
userId: session.userId,
|
|
130
|
+
eventsToProcess: session.events
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Adds events to Vertex AI Memory Bank via memories.generate.
|
|
135
|
+
*/
|
|
136
|
+
async addEventsToMemory(request) {
|
|
137
|
+
await this.addEventsToMemoryFromEvents({
|
|
138
|
+
appName: request.appName,
|
|
139
|
+
userId: request.userId,
|
|
140
|
+
eventsToProcess: request.events,
|
|
141
|
+
customMetadata: request.customMetadata
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Adds explicit memory items using Vertex Memory Bank.
|
|
146
|
+
*/
|
|
147
|
+
async addMemory(request) {
|
|
148
|
+
if (isConsolidationEnabled(request.customMetadata)) {
|
|
149
|
+
return this.addMemoriesViaGenerateDirectMemoriesSource(request);
|
|
150
|
+
}
|
|
151
|
+
await this.addMemoriesViaCreate(request);
|
|
152
|
+
}
|
|
153
|
+
async searchMemory(request) {
|
|
154
|
+
const params = {
|
|
155
|
+
name: `reasoningEngines/${this.agentEngineId}`,
|
|
156
|
+
scope: {
|
|
157
|
+
app_name: request.appName,
|
|
158
|
+
user_id: request.userId
|
|
159
|
+
},
|
|
160
|
+
similaritySearchParams: {
|
|
161
|
+
searchQuery: request.query
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const retrievedMemoriesResponse = await this.memories.retrieveInternal(params);
|
|
165
|
+
import_logger.logger.debug("Search memory response received.");
|
|
166
|
+
const memoryEvents = [];
|
|
167
|
+
const retrievedMemories = retrievedMemoriesResponse.retrievedMemories || [];
|
|
168
|
+
for (const retrievedMemory of retrievedMemories) {
|
|
169
|
+
import_logger.logger.debug(`Retrieved memory: ${JSON.stringify(retrievedMemory)}`);
|
|
170
|
+
if (retrievedMemory.memory && retrievedMemory.memory.fact) {
|
|
171
|
+
const content = (0, import_genai.createUserContent)(retrievedMemory.memory.fact);
|
|
172
|
+
memoryEvents.push({
|
|
173
|
+
author: "user",
|
|
174
|
+
content,
|
|
175
|
+
timestamp: retrievedMemory.memory.updateTime
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return { memories: memoryEvents };
|
|
180
|
+
}
|
|
181
|
+
async addEventsToMemoryFromEvents(request) {
|
|
182
|
+
const directEvents = [];
|
|
183
|
+
for (const event of request.eventsToProcess) {
|
|
184
|
+
if (shouldFilterOutEvent(event.content)) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
directEvents.push({
|
|
188
|
+
content: JSON.parse(JSON.stringify(event.content))
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (directEvents.length > 0) {
|
|
192
|
+
const config = buildGenerateMemoriesConfig(request.customMetadata);
|
|
193
|
+
const params = {
|
|
194
|
+
name: `reasoningEngines/${this.agentEngineId}`,
|
|
195
|
+
directContentsSource: { events: directEvents },
|
|
196
|
+
scope: {
|
|
197
|
+
app_name: request.appName,
|
|
198
|
+
user_id: request.userId
|
|
199
|
+
},
|
|
200
|
+
config
|
|
201
|
+
};
|
|
202
|
+
const operation = await this.memories.generateInternal(params);
|
|
203
|
+
import_logger.logger.debug("Generate memory response received.");
|
|
204
|
+
import_logger.logger.debug(`Generate memory response: ${JSON.stringify(operation)}`);
|
|
205
|
+
} else {
|
|
206
|
+
import_logger.logger.info("No events to add to memory.");
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
async addMemoriesViaCreate(request) {
|
|
210
|
+
const validatedMemories = normalizeMemoriesForCreate(request.memories);
|
|
211
|
+
for (let index = 0; index < validatedMemories.length; index++) {
|
|
212
|
+
const memory = validatedMemories[index];
|
|
213
|
+
const memoryFact = memoryEntryToFact(memory, index);
|
|
214
|
+
const memoryMetadata = mergeCustomMetadataForMemory({
|
|
215
|
+
customMetadata: request.customMetadata,
|
|
216
|
+
memory
|
|
217
|
+
});
|
|
218
|
+
const memoryRevisionLabels = revisionLabelsForMemory(memory);
|
|
219
|
+
const config = buildCreateMemoryConfig({
|
|
220
|
+
customMetadata: memoryMetadata,
|
|
221
|
+
memoryRevisionLabels
|
|
222
|
+
});
|
|
223
|
+
const params = {
|
|
224
|
+
name: `reasoningEngines/${this.agentEngineId}`,
|
|
225
|
+
fact: memoryFact,
|
|
226
|
+
scope: {
|
|
227
|
+
app_name: request.appName,
|
|
228
|
+
user_id: request.userId
|
|
229
|
+
},
|
|
230
|
+
config
|
|
231
|
+
};
|
|
232
|
+
const operation = await this.memories.createInternal(params);
|
|
233
|
+
import_logger.logger.info("Create memory response received.");
|
|
234
|
+
import_logger.logger.debug(`Create memory response: ${JSON.stringify(operation)}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async addMemoriesViaGenerateDirectMemoriesSource(request) {
|
|
238
|
+
const validatedMemories = normalizeMemoriesForCreate(request.memories);
|
|
239
|
+
const memoryTexts = validatedMemories.map(
|
|
240
|
+
(m, i) => memoryEntryToFact(m, i)
|
|
241
|
+
);
|
|
242
|
+
const config = buildGenerateMemoriesConfig(request.customMetadata);
|
|
243
|
+
const memoryBatches = iterMemoryBatches(memoryTexts);
|
|
244
|
+
for (const memoryBatch of memoryBatches) {
|
|
245
|
+
const params = {
|
|
246
|
+
name: `reasoningEngines/${this.agentEngineId}`,
|
|
247
|
+
directMemoriesSource: {
|
|
248
|
+
directMemories: memoryBatch.map((fact) => ({ fact }))
|
|
249
|
+
},
|
|
250
|
+
scope: {
|
|
251
|
+
app_name: request.appName,
|
|
252
|
+
user_id: request.userId
|
|
253
|
+
},
|
|
254
|
+
config
|
|
255
|
+
};
|
|
256
|
+
const operation = await this.memories.generateInternal(params);
|
|
257
|
+
import_logger.logger.info("Generate direct memory response received.");
|
|
258
|
+
import_logger.logger.debug(
|
|
259
|
+
`Generate direct memory response: ${JSON.stringify(operation)}`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function buildCreateMemoryConfig(params) {
|
|
265
|
+
const config = { waitForCompletion: false };
|
|
266
|
+
if (params.customMetadata) {
|
|
267
|
+
import_logger.logger.debug(
|
|
268
|
+
`Memory creation metadata: ${JSON.stringify(params.customMetadata)}`
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
const metadataByKey = {};
|
|
272
|
+
const customRevisionLabels = {};
|
|
273
|
+
for (const [key, value] of Object.entries(params.customMetadata || {})) {
|
|
274
|
+
if (key === ENABLE_CONSOLIDATION_KEY) {
|
|
275
|
+
continue;
|
|
276
|
+
}
|
|
277
|
+
if (key === "metadata") {
|
|
278
|
+
if (value === null || value === void 0) continue;
|
|
279
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
280
|
+
config["metadata"] = buildVertexMetadata(
|
|
281
|
+
value
|
|
282
|
+
);
|
|
283
|
+
} else {
|
|
284
|
+
import_logger.logger.warn(
|
|
285
|
+
'Ignoring metadata because customMetadata["metadata"] is not an object.'
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (key === "revisionLabels") {
|
|
291
|
+
if (value === null || value === void 0) continue;
|
|
292
|
+
const extractedLabels = extractRevisionLabels(
|
|
293
|
+
value,
|
|
294
|
+
'customMetadata["revisionLabels"]'
|
|
295
|
+
);
|
|
296
|
+
if (extractedLabels) {
|
|
297
|
+
Object.assign(customRevisionLabels, extractedLabels);
|
|
298
|
+
}
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
if (CREATE_MEMORY_KNOWN_FIELDS.includes(key)) {
|
|
302
|
+
if (value !== null && value !== void 0) {
|
|
303
|
+
config[key] = value;
|
|
304
|
+
}
|
|
305
|
+
} else {
|
|
306
|
+
metadataByKey[key] = value;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
if (Object.keys(metadataByKey).length > 0) {
|
|
310
|
+
const existingMetadata = config["metadata"];
|
|
311
|
+
if (!existingMetadata) {
|
|
312
|
+
config["metadata"] = buildVertexMetadata(metadataByKey);
|
|
313
|
+
} else {
|
|
314
|
+
config["metadata"] = {
|
|
315
|
+
...existingMetadata,
|
|
316
|
+
...buildVertexMetadata(metadataByKey)
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const revisionLabels = {
|
|
321
|
+
...customRevisionLabels,
|
|
322
|
+
...params.memoryRevisionLabels
|
|
323
|
+
};
|
|
324
|
+
if (Object.keys(revisionLabels).length > 0) {
|
|
325
|
+
config["revisionLabels"] = revisionLabels;
|
|
326
|
+
}
|
|
327
|
+
return config;
|
|
328
|
+
}
|
|
329
|
+
function extractRevisionLabels(value, source) {
|
|
330
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
331
|
+
import_logger.logger.warn(`Ignoring ${source} because it is not an object.`);
|
|
332
|
+
return void 0;
|
|
333
|
+
}
|
|
334
|
+
const revisionLabels = {};
|
|
335
|
+
for (const [key, labelValue] of Object.entries(value)) {
|
|
336
|
+
if (typeof labelValue !== "string") {
|
|
337
|
+
import_logger.logger.warn(
|
|
338
|
+
`Ignoring revision label ${key} from ${source} because its value is not a string.`
|
|
339
|
+
);
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
revisionLabels[key] = labelValue;
|
|
343
|
+
}
|
|
344
|
+
if (Object.keys(revisionLabels).length === 0) {
|
|
345
|
+
return void 0;
|
|
346
|
+
}
|
|
347
|
+
return revisionLabels;
|
|
348
|
+
}
|
|
349
|
+
function buildVertexMetadata(metadataByKey) {
|
|
350
|
+
const vertexMetadata = {};
|
|
351
|
+
for (const [key, value] of Object.entries(metadataByKey)) {
|
|
352
|
+
const convertedValue = toVertexMetadataValue(key, value);
|
|
353
|
+
if (convertedValue !== void 0) {
|
|
354
|
+
vertexMetadata[key] = convertedValue;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return vertexMetadata;
|
|
358
|
+
}
|
|
359
|
+
function buildGenerateMemoriesConfig(customMetadata) {
|
|
360
|
+
const config = { waitForCompletion: false };
|
|
361
|
+
if (!customMetadata) {
|
|
362
|
+
return config;
|
|
363
|
+
}
|
|
364
|
+
import_logger.logger.debug(`Memory generation metadata: ${JSON.stringify(customMetadata)}`);
|
|
365
|
+
const metadataByKey = {};
|
|
366
|
+
for (const [key, value] of Object.entries(customMetadata)) {
|
|
367
|
+
if (key === ENABLE_CONSOLIDATION_KEY) {
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (key === "ttl") {
|
|
371
|
+
if (value === null || value === void 0) continue;
|
|
372
|
+
if (customMetadata["revisionTtl"] === void 0) {
|
|
373
|
+
config["revisionTtl"] = value;
|
|
374
|
+
}
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (key === "metadata") {
|
|
378
|
+
if (value === null || value === void 0) continue;
|
|
379
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
380
|
+
config["metadata"] = buildVertexMetadata(
|
|
381
|
+
value
|
|
382
|
+
);
|
|
383
|
+
} else {
|
|
384
|
+
import_logger.logger.warn(
|
|
385
|
+
'Ignoring metadata because customMetadata["metadata"] is not an object.'
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (GENERATE_MEMORIES_KNOWN_FIELDS.includes(key)) {
|
|
391
|
+
if (value !== null && value !== void 0) {
|
|
392
|
+
config[key] = value;
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
metadataByKey[key] = value;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (Object.keys(metadataByKey).length > 0) {
|
|
399
|
+
const existingMetadata = config["metadata"];
|
|
400
|
+
if (!existingMetadata) {
|
|
401
|
+
config["metadata"] = buildVertexMetadata(metadataByKey);
|
|
402
|
+
} else {
|
|
403
|
+
config["metadata"] = {
|
|
404
|
+
...existingMetadata,
|
|
405
|
+
...buildVertexMetadata(metadataByKey)
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return config;
|
|
410
|
+
}
|
|
411
|
+
function normalizeMemoriesForCreate(memories) {
|
|
412
|
+
if (!Array.isArray(memories)) {
|
|
413
|
+
throw new TypeError("memories must be a sequence of memory items.");
|
|
414
|
+
}
|
|
415
|
+
if (memories.length === 0) {
|
|
416
|
+
throw new Error("memories must contain at least one entry.");
|
|
417
|
+
}
|
|
418
|
+
return memories;
|
|
419
|
+
}
|
|
420
|
+
function memoryEntryToFact(memory, index) {
|
|
421
|
+
const textParts = [];
|
|
422
|
+
if (memory.content && memory.content.parts) {
|
|
423
|
+
for (const part of memory.content.parts) {
|
|
424
|
+
if (part.inlineData || part.fileData) {
|
|
425
|
+
throw new Error(
|
|
426
|
+
`memories[${index}] must include text only; inlineData and fileData are not supported.`
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
if (part.text) {
|
|
430
|
+
const strippedText = part.text.trim();
|
|
431
|
+
if (strippedText) {
|
|
432
|
+
textParts.push(strippedText);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
if (textParts.length === 0) {
|
|
438
|
+
throw new Error(`memories[${index}] must include non-whitespace text.`);
|
|
439
|
+
}
|
|
440
|
+
return textParts.join("\n");
|
|
441
|
+
}
|
|
442
|
+
function mergeCustomMetadataForMemory(params) {
|
|
443
|
+
const mergedMetadata = {};
|
|
444
|
+
if (params.customMetadata) {
|
|
445
|
+
Object.assign(mergedMetadata, params.customMetadata);
|
|
446
|
+
}
|
|
447
|
+
const memoryWithMetadata = params.memory;
|
|
448
|
+
if (memoryWithMetadata.customMetadata) {
|
|
449
|
+
Object.assign(mergedMetadata, memoryWithMetadata.customMetadata);
|
|
450
|
+
}
|
|
451
|
+
if (Object.keys(mergedMetadata).length === 0) {
|
|
452
|
+
return void 0;
|
|
453
|
+
}
|
|
454
|
+
return mergedMetadata;
|
|
455
|
+
}
|
|
456
|
+
function revisionLabelsForMemory(memory) {
|
|
457
|
+
const revisionLabels = {};
|
|
458
|
+
if (memory.author) {
|
|
459
|
+
revisionLabels["author"] = memory.author;
|
|
460
|
+
}
|
|
461
|
+
if (memory.timestamp) {
|
|
462
|
+
revisionLabels["timestamp"] = memory.timestamp;
|
|
463
|
+
}
|
|
464
|
+
if (Object.keys(revisionLabels).length === 0) {
|
|
465
|
+
return void 0;
|
|
466
|
+
}
|
|
467
|
+
return revisionLabels;
|
|
468
|
+
}
|
|
469
|
+
function isConsolidationEnabled(customMetadata) {
|
|
470
|
+
if (!customMetadata) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
const enableConsolidation = customMetadata[ENABLE_CONSOLIDATION_KEY];
|
|
474
|
+
if (enableConsolidation === void 0) {
|
|
475
|
+
return false;
|
|
476
|
+
}
|
|
477
|
+
if (typeof enableConsolidation !== "boolean") {
|
|
478
|
+
throw new TypeError(
|
|
479
|
+
`customMetadata["${ENABLE_CONSOLIDATION_KEY}"] must be a bool.`
|
|
480
|
+
);
|
|
481
|
+
}
|
|
482
|
+
return enableConsolidation;
|
|
483
|
+
}
|
|
484
|
+
function iterMemoryBatches(memories) {
|
|
485
|
+
const memoryBatches = [];
|
|
486
|
+
for (let index = 0; index < memories.length; index += MAX_DIRECT_MEMORIES_PER_GENERATE_CALL) {
|
|
487
|
+
memoryBatches.push(
|
|
488
|
+
memories.slice(index, index + MAX_DIRECT_MEMORIES_PER_GENERATE_CALL)
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
return memoryBatches;
|
|
492
|
+
}
|
|
493
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
494
|
+
0 && (module.exports = {
|
|
495
|
+
VertexAiMemoryBankService
|
|
496
|
+
});
|
|
@@ -37,11 +37,16 @@ var import_runner = require("./runner.js");
|
|
|
37
37
|
* SPDX-License-Identifier: Apache-2.0
|
|
38
38
|
*/
|
|
39
39
|
class InMemoryRunner extends import_runner.Runner {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new InMemoryRunner instance.
|
|
42
|
+
*
|
|
43
|
+
* @param params The configuration for the runner.
|
|
44
|
+
* @param params.agent The root agent to run.
|
|
45
|
+
* @param params.appName The application name. Defaults to `'InMemoryRunner'`.
|
|
46
|
+
* @param params.plugins An optional list of plugins.
|
|
47
|
+
*/
|
|
48
|
+
constructor(params) {
|
|
49
|
+
const { agent, appName = "InMemoryRunner", plugins = [] } = params;
|
|
45
50
|
super({
|
|
46
51
|
appName,
|
|
47
52
|
agent,
|
|
@@ -38,6 +38,7 @@ var import_event = require("../events/event.js");
|
|
|
38
38
|
var import_event_actions = require("../events/event_actions.js");
|
|
39
39
|
var import_plugin_manager = require("../plugins/plugin_manager.js");
|
|
40
40
|
var import_tracing = require("../telemetry/tracing.js");
|
|
41
|
+
var import_base_toolset = require("../tools/base_toolset.js");
|
|
41
42
|
var import_logger = require("../utils/logger.js");
|
|
42
43
|
var import_model_name = require("../utils/model_name.js");
|
|
43
44
|
/**
|
|
@@ -52,6 +53,11 @@ function isRunner(obj) {
|
|
|
52
53
|
}
|
|
53
54
|
_a = RUNNER_SIGNATURE_SYMBOL;
|
|
54
55
|
class Runner {
|
|
56
|
+
/**
|
|
57
|
+
* Creates a new Runner instance.
|
|
58
|
+
*
|
|
59
|
+
* @param input The configuration for the runner.
|
|
60
|
+
*/
|
|
55
61
|
constructor(input) {
|
|
56
62
|
this[_a] = true;
|
|
57
63
|
var _a2;
|
|
@@ -84,7 +90,8 @@ class Runner {
|
|
|
84
90
|
sessionId,
|
|
85
91
|
newMessage: params.newMessage,
|
|
86
92
|
stateDelta: params.stateDelta,
|
|
87
|
-
runConfig: params.runConfig
|
|
93
|
+
runConfig: params.runConfig,
|
|
94
|
+
customMetadata: params.customMetadata
|
|
88
95
|
});
|
|
89
96
|
} finally {
|
|
90
97
|
await this.sessionService.deleteSession({
|
|
@@ -189,7 +196,8 @@ class Runner {
|
|
|
189
196
|
invocationId: invocationContext.invocationId,
|
|
190
197
|
author: "user",
|
|
191
198
|
actions: stateDelta ? (0, import_event_actions.createEventActions)({ stateDelta }) : void 0,
|
|
192
|
-
content: newMessage
|
|
199
|
+
content: newMessage,
|
|
200
|
+
customMetadata: params.customMetadata
|
|
193
201
|
})
|
|
194
202
|
});
|
|
195
203
|
if ((_e = params.abortSignal) == null ? void 0 : _e.aborted) {
|
|
@@ -254,6 +262,8 @@ class Runner {
|
|
|
254
262
|
);
|
|
255
263
|
} finally {
|
|
256
264
|
span.end();
|
|
265
|
+
const toolsets = getAllToolsets(this.agent);
|
|
266
|
+
await Promise.allSettled(toolsets.map((t) => t.close()));
|
|
257
267
|
}
|
|
258
268
|
}
|
|
259
269
|
/**
|
|
@@ -373,6 +383,26 @@ function findEventByLastFunctionResponseId(events) {
|
|
|
373
383
|
}
|
|
374
384
|
return null;
|
|
375
385
|
}
|
|
386
|
+
function getAllToolsets(agent) {
|
|
387
|
+
const toolsets = [];
|
|
388
|
+
const visited = /* @__PURE__ */ new Set();
|
|
389
|
+
function traverse(curr) {
|
|
390
|
+
if (visited.has(curr)) return;
|
|
391
|
+
visited.add(curr);
|
|
392
|
+
if ((0, import_llm_agent.isLlmAgent)(curr)) {
|
|
393
|
+
for (const tool of curr.tools) {
|
|
394
|
+
if ((0, import_base_toolset.isBaseToolset)(tool)) {
|
|
395
|
+
toolsets.push(tool);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
for (const sub of curr.subAgents) {
|
|
400
|
+
traverse(sub);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
traverse(agent);
|
|
404
|
+
return toolsets;
|
|
405
|
+
}
|
|
376
406
|
// Annotate the CommonJS export names for ESM import in node:
|
|
377
407
|
0 && (module.exports = {
|
|
378
408
|
Runner,
|
|
@@ -204,7 +204,11 @@ class DatabaseSessionService extends import_base_session_service.BaseSessionServ
|
|
|
204
204
|
}
|
|
205
205
|
async listSessions({
|
|
206
206
|
appName,
|
|
207
|
-
userId
|
|
207
|
+
userId,
|
|
208
|
+
limit,
|
|
209
|
+
offset,
|
|
210
|
+
page,
|
|
211
|
+
order
|
|
208
212
|
}) {
|
|
209
213
|
await this.init();
|
|
210
214
|
const em = this.orm.em.fork();
|
|
@@ -212,7 +216,49 @@ class DatabaseSessionService extends import_base_session_service.BaseSessionServ
|
|
|
212
216
|
if (userId) {
|
|
213
217
|
where.userId = userId;
|
|
214
218
|
}
|
|
215
|
-
const
|
|
219
|
+
const orderBy = order === "asc" ? { updateTime: "ASC", id: "ASC" } : order === "desc" ? { updateTime: "DESC", id: "ASC" } : void 0;
|
|
220
|
+
let storageSessions;
|
|
221
|
+
let paginationMeta;
|
|
222
|
+
if (limit !== void 0) {
|
|
223
|
+
const totalItems = await em.count(import_schema.StorageSession, where);
|
|
224
|
+
const totalPages = limit === 0 ? 0 : Math.ceil(totalItems / limit);
|
|
225
|
+
let effectiveOffset;
|
|
226
|
+
let effectivePage;
|
|
227
|
+
if (page !== void 0) {
|
|
228
|
+
effectiveOffset = (page - 1) * limit;
|
|
229
|
+
effectivePage = page;
|
|
230
|
+
} else {
|
|
231
|
+
effectiveOffset = offset != null ? offset : 0;
|
|
232
|
+
effectivePage = limit === 0 ? 1 : Math.floor(effectiveOffset / limit) + 1;
|
|
233
|
+
}
|
|
234
|
+
storageSessions = await em.find(import_schema.StorageSession, where, {
|
|
235
|
+
orderBy,
|
|
236
|
+
limit,
|
|
237
|
+
offset: effectiveOffset
|
|
238
|
+
});
|
|
239
|
+
paginationMeta = { page: effectivePage, limit, totalItems, totalPages };
|
|
240
|
+
} else if (offset) {
|
|
241
|
+
const totalItems = await em.count(import_schema.StorageSession, where);
|
|
242
|
+
storageSessions = await em.find(import_schema.StorageSession, where, {
|
|
243
|
+
orderBy,
|
|
244
|
+
offset
|
|
245
|
+
});
|
|
246
|
+
paginationMeta = {
|
|
247
|
+
page: 1,
|
|
248
|
+
limit: totalItems,
|
|
249
|
+
totalItems,
|
|
250
|
+
totalPages: totalItems === 0 ? 0 : 1
|
|
251
|
+
};
|
|
252
|
+
} else {
|
|
253
|
+
storageSessions = await em.find(import_schema.StorageSession, where, { orderBy });
|
|
254
|
+
const totalItems = storageSessions.length;
|
|
255
|
+
paginationMeta = {
|
|
256
|
+
page: 1,
|
|
257
|
+
limit: totalItems,
|
|
258
|
+
totalItems,
|
|
259
|
+
totalPages: totalItems === 0 ? 0 : 1
|
|
260
|
+
};
|
|
261
|
+
}
|
|
216
262
|
const appStateModel = await em.findOne(import_schema.StorageAppState, { appName });
|
|
217
263
|
const appState = (appStateModel == null ? void 0 : appStateModel.state) || {};
|
|
218
264
|
const userStateMap = {};
|
|
@@ -237,7 +283,7 @@ class DatabaseSessionService extends import_base_session_service.BaseSessionServ
|
|
|
237
283
|
lastUpdateTime: ss.updateTime.getTime()
|
|
238
284
|
});
|
|
239
285
|
});
|
|
240
|
-
return { sessions };
|
|
286
|
+
return { sessions, ...paginationMeta };
|
|
241
287
|
}
|
|
242
288
|
async deleteSession({
|
|
243
289
|
appName,
|