@google/adk 0.1.2 → 0.1.3
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 +23 -32
- package/dist/cjs/artifacts/gcs_artifact_service.js +140 -0
- package/dist/cjs/common.js +3 -0
- package/dist/cjs/index.js +5 -5
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/sessions/database_session_service.js +52 -0
- package/dist/esm/agents/functions.js +23 -32
- package/dist/esm/artifacts/gcs_artifact_service.js +110 -0
- package/dist/esm/common.js +2 -0
- package/dist/esm/index.js +5 -5
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/sessions/database_session_service.js +22 -0
- package/dist/types/artifacts/gcs_artifact_service.d.ts +16 -0
- package/dist/types/common.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/models/base_llm.d.ts +5 -3
- package/dist/types/models/google_llm.d.ts +1 -1
- package/dist/types/models/registry.d.ts +6 -2
- package/dist/types/sessions/database_session_service.d.ts +10 -0
- package/dist/web/agents/functions.js +23 -32
- package/dist/web/artifacts/gcs_artifact_service.js +126 -0
- package/dist/web/common.js +2 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/sessions/database_session_service.js +22 -0
- package/package.json +2 -1
|
@@ -38,6 +38,7 @@ __export(functions_exports, {
|
|
|
38
38
|
removeClientFunctionCallId: () => removeClientFunctionCallId
|
|
39
39
|
});
|
|
40
40
|
module.exports = __toCommonJS(functions_exports);
|
|
41
|
+
var import_genai = require("@google/genai");
|
|
41
42
|
var import_event = require("../events/event.js");
|
|
42
43
|
var import_event_actions = require("../events/event_actions.js");
|
|
43
44
|
var import_tool_context = require("../tools/tool_context.js");
|
|
@@ -166,30 +167,6 @@ async function callToolAsync(tool, args, toolContext) {
|
|
|
166
167
|
import_logger.logger.debug(`callToolAsync ${tool.name}`);
|
|
167
168
|
return await tool.runAsync({ args, toolContext });
|
|
168
169
|
}
|
|
169
|
-
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
170
|
-
let responseResult = functionResult;
|
|
171
|
-
if (typeof functionResult !== "object" || functionResult == null) {
|
|
172
|
-
responseResult = { result: functionResult };
|
|
173
|
-
}
|
|
174
|
-
const partFunctionResponse = {
|
|
175
|
-
functionResponse: {
|
|
176
|
-
name: tool.name,
|
|
177
|
-
response: responseResult,
|
|
178
|
-
id: toolContext.functionCallId
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
const content = {
|
|
182
|
-
role: "user",
|
|
183
|
-
parts: [partFunctionResponse]
|
|
184
|
-
};
|
|
185
|
-
return (0, import_event.createEvent)({
|
|
186
|
-
invocationId: invocationContext.invocationId,
|
|
187
|
-
author: invocationContext.agent.name,
|
|
188
|
-
content,
|
|
189
|
-
actions: toolContext.actions,
|
|
190
|
-
branch: invocationContext.branch
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
170
|
async function handleFunctionCallsAsync({
|
|
194
171
|
invocationContext,
|
|
195
172
|
functionCallEvent,
|
|
@@ -240,6 +217,7 @@ async function handleFunctionCallList({
|
|
|
240
217
|
import_logger.logger.debug(`execute_tool ${tool.name}`);
|
|
241
218
|
const functionArgs = (_a = functionCall.args) != null ? _a : {};
|
|
242
219
|
let functionResponse = null;
|
|
220
|
+
let functionResponseError;
|
|
243
221
|
functionResponse = await invocationContext.pluginManager.runBeforeToolCallback({
|
|
244
222
|
tool,
|
|
245
223
|
toolArgs: functionArgs,
|
|
@@ -276,10 +254,11 @@ async function handleFunctionCallList({
|
|
|
276
254
|
);
|
|
277
255
|
if (onToolErrorResponse) {
|
|
278
256
|
functionResponse = onToolErrorResponse;
|
|
257
|
+
} else {
|
|
258
|
+
functionResponseError = e.message;
|
|
279
259
|
}
|
|
280
260
|
} else {
|
|
281
|
-
|
|
282
|
-
throw e;
|
|
261
|
+
functionResponseError = e;
|
|
283
262
|
}
|
|
284
263
|
}
|
|
285
264
|
}
|
|
@@ -308,12 +287,24 @@ async function handleFunctionCallList({
|
|
|
308
287
|
if (tool.isLongRunning && !functionResponse) {
|
|
309
288
|
continue;
|
|
310
289
|
}
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
)
|
|
290
|
+
if (functionResponseError) {
|
|
291
|
+
functionResponse = { error: functionResponseError };
|
|
292
|
+
} else if (typeof functionResponse !== "object" || functionResponse == null) {
|
|
293
|
+
functionResponse = { result: functionResponse };
|
|
294
|
+
}
|
|
295
|
+
const functionResponseEvent = (0, import_event.createEvent)({
|
|
296
|
+
invocationId: invocationContext.invocationId,
|
|
297
|
+
author: invocationContext.agent.name,
|
|
298
|
+
content: (0, import_genai.createUserContent)({
|
|
299
|
+
functionResponse: {
|
|
300
|
+
id: toolContext.functionCallId,
|
|
301
|
+
name: tool.name,
|
|
302
|
+
response: functionResponse
|
|
303
|
+
}
|
|
304
|
+
}),
|
|
305
|
+
actions: toolContext.actions,
|
|
306
|
+
branch: invocationContext.branch
|
|
307
|
+
});
|
|
317
308
|
import_logger.logger.debug("traceToolCall", {
|
|
318
309
|
tool: tool.name,
|
|
319
310
|
args: functionArgs,
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 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 gcs_artifact_service_exports = {};
|
|
26
|
+
__export(gcs_artifact_service_exports, {
|
|
27
|
+
GcsArtifactService: () => GcsArtifactService
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(gcs_artifact_service_exports);
|
|
30
|
+
var import_storage = require("@google-cloud/storage");
|
|
31
|
+
var import_genai = require("@google/genai");
|
|
32
|
+
/**
|
|
33
|
+
* @license
|
|
34
|
+
* Copyright 2025 Google LLC
|
|
35
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
36
|
+
*/
|
|
37
|
+
class GcsArtifactService {
|
|
38
|
+
constructor(bucket) {
|
|
39
|
+
this.bucket = new import_storage.Storage().bucket(bucket);
|
|
40
|
+
}
|
|
41
|
+
async saveArtifact(request) {
|
|
42
|
+
const versions = await this.listVersions(request);
|
|
43
|
+
const version = versions.length > 0 ? Math.max(...versions) + 1 : 0;
|
|
44
|
+
const file = this.bucket.file(getFileName({
|
|
45
|
+
...request,
|
|
46
|
+
version
|
|
47
|
+
}));
|
|
48
|
+
if (request.artifact.inlineData) {
|
|
49
|
+
await file.save(JSON.stringify(request.artifact.inlineData.data), {
|
|
50
|
+
contentType: request.artifact.inlineData.mimeType
|
|
51
|
+
});
|
|
52
|
+
return version;
|
|
53
|
+
}
|
|
54
|
+
if (request.artifact.text) {
|
|
55
|
+
await file.save(request.artifact.text, {
|
|
56
|
+
contentType: "text/plain"
|
|
57
|
+
});
|
|
58
|
+
return version;
|
|
59
|
+
}
|
|
60
|
+
throw new Error("Artifact must have either inlineData or text.");
|
|
61
|
+
}
|
|
62
|
+
async loadArtifact(request) {
|
|
63
|
+
let version = request.version;
|
|
64
|
+
if (version === void 0) {
|
|
65
|
+
const versions = await this.listVersions(request);
|
|
66
|
+
if (versions.length === 0) {
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
69
|
+
version = Math.max(...versions);
|
|
70
|
+
}
|
|
71
|
+
const file = this.bucket.file(getFileName({
|
|
72
|
+
...request,
|
|
73
|
+
version
|
|
74
|
+
}));
|
|
75
|
+
const [[metadata], [rawDataBuffer]] = await Promise.all([file.getMetadata(), file.download()]);
|
|
76
|
+
if (metadata.contentType === "text/plain") {
|
|
77
|
+
return (0, import_genai.createPartFromText)(rawDataBuffer.toString("utf-8"));
|
|
78
|
+
}
|
|
79
|
+
return (0, import_genai.createPartFromBase64)(
|
|
80
|
+
rawDataBuffer.toString("base64"),
|
|
81
|
+
metadata.contentType
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
async listArtifactKeys(request) {
|
|
85
|
+
const fileNames = [];
|
|
86
|
+
const sessionPrefix = `${request.appName}/${request.userId}/${request.sessionId}/`;
|
|
87
|
+
const usernamePrefix = `${request.appName}/${request.userId}/user/`;
|
|
88
|
+
const [
|
|
89
|
+
[sessionFiles],
|
|
90
|
+
[userSessionFiles]
|
|
91
|
+
] = await Promise.all([
|
|
92
|
+
this.bucket.getFiles({ prefix: sessionPrefix }),
|
|
93
|
+
this.bucket.getFiles({ prefix: usernamePrefix })
|
|
94
|
+
]);
|
|
95
|
+
for (const file of sessionFiles) {
|
|
96
|
+
fileNames.push(file.name.split("/").pop());
|
|
97
|
+
}
|
|
98
|
+
for (const file of userSessionFiles) {
|
|
99
|
+
fileNames.push(file.name.split("/").pop());
|
|
100
|
+
}
|
|
101
|
+
return fileNames.sort((a, b) => a.localeCompare(b));
|
|
102
|
+
}
|
|
103
|
+
async deleteArtifact(request) {
|
|
104
|
+
const versions = await this.listVersions(request);
|
|
105
|
+
await Promise.all(versions.map((version) => {
|
|
106
|
+
const file = this.bucket.file(getFileName({
|
|
107
|
+
...request,
|
|
108
|
+
version
|
|
109
|
+
}));
|
|
110
|
+
return file.delete();
|
|
111
|
+
}));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
async listVersions(request) {
|
|
115
|
+
const prefix = getFileName(request);
|
|
116
|
+
const [files] = await this.bucket.getFiles({ prefix });
|
|
117
|
+
const versions = [];
|
|
118
|
+
for (const file of files) {
|
|
119
|
+
const version = file.name.split("/").pop();
|
|
120
|
+
versions.push(parseInt(version, 10));
|
|
121
|
+
}
|
|
122
|
+
return versions;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function getFileName({
|
|
126
|
+
appName,
|
|
127
|
+
userId,
|
|
128
|
+
sessionId,
|
|
129
|
+
filename,
|
|
130
|
+
version
|
|
131
|
+
}) {
|
|
132
|
+
if (filename.startsWith("user:")) {
|
|
133
|
+
return `${appName}/${userId}/user/${filename}/${version}`;
|
|
134
|
+
}
|
|
135
|
+
return `${appName}/${userId}/${sessionId}/${filename}/${version}`;
|
|
136
|
+
}
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
GcsArtifactService
|
|
140
|
+
});
|
package/dist/cjs/common.js
CHANGED
|
@@ -58,6 +58,7 @@ __export(common_exports, {
|
|
|
58
58
|
ToolConfirmation: () => import_tool_confirmation.ToolConfirmation,
|
|
59
59
|
ToolContext: () => import_tool_context.ToolContext,
|
|
60
60
|
createEvent: () => import_event.createEvent,
|
|
61
|
+
createEventActions: () => import_event_actions.createEventActions,
|
|
61
62
|
createSession: () => import_session.createSession,
|
|
62
63
|
functionsExportedForTestingOnly: () => import_functions.functionsExportedForTestingOnly,
|
|
63
64
|
getAskUserConfirmationFunctionCalls: () => import_security_plugin.getAskUserConfirmationFunctionCalls,
|
|
@@ -82,6 +83,7 @@ var import_run_config = require("./agents/run_config.js");
|
|
|
82
83
|
var import_sequential_agent = require("./agents/sequential_agent.js");
|
|
83
84
|
var import_in_memory_artifact_service = require("./artifacts/in_memory_artifact_service.js");
|
|
84
85
|
var import_event = require("./events/event.js");
|
|
86
|
+
var import_event_actions = require("./events/event_actions.js");
|
|
85
87
|
var import_in_memory_memory_service = require("./memory/in_memory_memory_service.js");
|
|
86
88
|
var import_base_llm = require("./models/base_llm.js");
|
|
87
89
|
var import_google_llm = require("./models/google_llm.js");
|
|
@@ -147,6 +149,7 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
147
149
|
ToolConfirmation,
|
|
148
150
|
ToolContext,
|
|
149
151
|
createEvent,
|
|
152
|
+
createEventActions,
|
|
150
153
|
createSession,
|
|
151
154
|
functionsExportedForTestingOnly,
|
|
152
155
|
getAskUserConfirmationFunctionCalls,
|