@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
|
@@ -0,0 +1,52 @@
|
|
|
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 database_session_service_exports = {};
|
|
26
|
+
__export(database_session_service_exports, {
|
|
27
|
+
DatabaseSessionService: () => DatabaseSessionService
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(database_session_service_exports);
|
|
30
|
+
var import_base_session_service = require("./base_session_service.js");
|
|
31
|
+
class DatabaseSessionService extends import_base_session_service.BaseSessionService {
|
|
32
|
+
constructor(dbUrl) {
|
|
33
|
+
super();
|
|
34
|
+
this.dbUrl = dbUrl;
|
|
35
|
+
}
|
|
36
|
+
createSession(request) {
|
|
37
|
+
throw new Error("Method not implemented.");
|
|
38
|
+
}
|
|
39
|
+
getSession(request) {
|
|
40
|
+
throw new Error("Method not implemented.");
|
|
41
|
+
}
|
|
42
|
+
listSessions(request) {
|
|
43
|
+
throw new Error("Method not implemented.");
|
|
44
|
+
}
|
|
45
|
+
deleteSession(request) {
|
|
46
|
+
throw new Error("Method not implemented.");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
DatabaseSessionService
|
|
52
|
+
});
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { createUserContent } from "@google/genai";
|
|
6
7
|
import { createEvent, getFunctionCalls } from "../events/event.js";
|
|
7
8
|
import { mergeEventActions } from "../events/event_actions.js";
|
|
8
9
|
import { ToolContext } from "../tools/tool_context.js";
|
|
@@ -126,30 +127,6 @@ async function callToolAsync(tool, args, toolContext) {
|
|
|
126
127
|
logger.debug(`callToolAsync ${tool.name}`);
|
|
127
128
|
return await tool.runAsync({ args, toolContext });
|
|
128
129
|
}
|
|
129
|
-
function buildResponseEvent(tool, functionResult, toolContext, invocationContext) {
|
|
130
|
-
let responseResult = functionResult;
|
|
131
|
-
if (typeof functionResult !== "object" || functionResult == null) {
|
|
132
|
-
responseResult = { result: functionResult };
|
|
133
|
-
}
|
|
134
|
-
const partFunctionResponse = {
|
|
135
|
-
functionResponse: {
|
|
136
|
-
name: tool.name,
|
|
137
|
-
response: responseResult,
|
|
138
|
-
id: toolContext.functionCallId
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
const content = {
|
|
142
|
-
role: "user",
|
|
143
|
-
parts: [partFunctionResponse]
|
|
144
|
-
};
|
|
145
|
-
return createEvent({
|
|
146
|
-
invocationId: invocationContext.invocationId,
|
|
147
|
-
author: invocationContext.agent.name,
|
|
148
|
-
content,
|
|
149
|
-
actions: toolContext.actions,
|
|
150
|
-
branch: invocationContext.branch
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
130
|
async function handleFunctionCallsAsync({
|
|
154
131
|
invocationContext,
|
|
155
132
|
functionCallEvent,
|
|
@@ -200,6 +177,7 @@ async function handleFunctionCallList({
|
|
|
200
177
|
logger.debug(`execute_tool ${tool.name}`);
|
|
201
178
|
const functionArgs = (_a = functionCall.args) != null ? _a : {};
|
|
202
179
|
let functionResponse = null;
|
|
180
|
+
let functionResponseError;
|
|
203
181
|
functionResponse = await invocationContext.pluginManager.runBeforeToolCallback({
|
|
204
182
|
tool,
|
|
205
183
|
toolArgs: functionArgs,
|
|
@@ -236,10 +214,11 @@ async function handleFunctionCallList({
|
|
|
236
214
|
);
|
|
237
215
|
if (onToolErrorResponse) {
|
|
238
216
|
functionResponse = onToolErrorResponse;
|
|
217
|
+
} else {
|
|
218
|
+
functionResponseError = e.message;
|
|
239
219
|
}
|
|
240
220
|
} else {
|
|
241
|
-
|
|
242
|
-
throw e;
|
|
221
|
+
functionResponseError = e;
|
|
243
222
|
}
|
|
244
223
|
}
|
|
245
224
|
}
|
|
@@ -268,12 +247,24 @@ async function handleFunctionCallList({
|
|
|
268
247
|
if (tool.isLongRunning && !functionResponse) {
|
|
269
248
|
continue;
|
|
270
249
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
250
|
+
if (functionResponseError) {
|
|
251
|
+
functionResponse = { error: functionResponseError };
|
|
252
|
+
} else if (typeof functionResponse !== "object" || functionResponse == null) {
|
|
253
|
+
functionResponse = { result: functionResponse };
|
|
254
|
+
}
|
|
255
|
+
const functionResponseEvent = createEvent({
|
|
256
|
+
invocationId: invocationContext.invocationId,
|
|
257
|
+
author: invocationContext.agent.name,
|
|
258
|
+
content: createUserContent({
|
|
259
|
+
functionResponse: {
|
|
260
|
+
id: toolContext.functionCallId,
|
|
261
|
+
name: tool.name,
|
|
262
|
+
response: functionResponse
|
|
263
|
+
}
|
|
264
|
+
}),
|
|
265
|
+
actions: toolContext.actions,
|
|
266
|
+
branch: invocationContext.branch
|
|
267
|
+
});
|
|
277
268
|
logger.debug("traceToolCall", {
|
|
278
269
|
tool: tool.name,
|
|
279
270
|
args: functionArgs,
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { Storage } from "@google-cloud/storage";
|
|
7
|
+
import { createPartFromBase64, createPartFromText } from "@google/genai";
|
|
8
|
+
class GcsArtifactService {
|
|
9
|
+
constructor(bucket) {
|
|
10
|
+
this.bucket = new Storage().bucket(bucket);
|
|
11
|
+
}
|
|
12
|
+
async saveArtifact(request) {
|
|
13
|
+
const versions = await this.listVersions(request);
|
|
14
|
+
const version = versions.length > 0 ? Math.max(...versions) + 1 : 0;
|
|
15
|
+
const file = this.bucket.file(getFileName({
|
|
16
|
+
...request,
|
|
17
|
+
version
|
|
18
|
+
}));
|
|
19
|
+
if (request.artifact.inlineData) {
|
|
20
|
+
await file.save(JSON.stringify(request.artifact.inlineData.data), {
|
|
21
|
+
contentType: request.artifact.inlineData.mimeType
|
|
22
|
+
});
|
|
23
|
+
return version;
|
|
24
|
+
}
|
|
25
|
+
if (request.artifact.text) {
|
|
26
|
+
await file.save(request.artifact.text, {
|
|
27
|
+
contentType: "text/plain"
|
|
28
|
+
});
|
|
29
|
+
return version;
|
|
30
|
+
}
|
|
31
|
+
throw new Error("Artifact must have either inlineData or text.");
|
|
32
|
+
}
|
|
33
|
+
async loadArtifact(request) {
|
|
34
|
+
let version = request.version;
|
|
35
|
+
if (version === void 0) {
|
|
36
|
+
const versions = await this.listVersions(request);
|
|
37
|
+
if (versions.length === 0) {
|
|
38
|
+
return void 0;
|
|
39
|
+
}
|
|
40
|
+
version = Math.max(...versions);
|
|
41
|
+
}
|
|
42
|
+
const file = this.bucket.file(getFileName({
|
|
43
|
+
...request,
|
|
44
|
+
version
|
|
45
|
+
}));
|
|
46
|
+
const [[metadata], [rawDataBuffer]] = await Promise.all([file.getMetadata(), file.download()]);
|
|
47
|
+
if (metadata.contentType === "text/plain") {
|
|
48
|
+
return createPartFromText(rawDataBuffer.toString("utf-8"));
|
|
49
|
+
}
|
|
50
|
+
return createPartFromBase64(
|
|
51
|
+
rawDataBuffer.toString("base64"),
|
|
52
|
+
metadata.contentType
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
async listArtifactKeys(request) {
|
|
56
|
+
const fileNames = [];
|
|
57
|
+
const sessionPrefix = `${request.appName}/${request.userId}/${request.sessionId}/`;
|
|
58
|
+
const usernamePrefix = `${request.appName}/${request.userId}/user/`;
|
|
59
|
+
const [
|
|
60
|
+
[sessionFiles],
|
|
61
|
+
[userSessionFiles]
|
|
62
|
+
] = await Promise.all([
|
|
63
|
+
this.bucket.getFiles({ prefix: sessionPrefix }),
|
|
64
|
+
this.bucket.getFiles({ prefix: usernamePrefix })
|
|
65
|
+
]);
|
|
66
|
+
for (const file of sessionFiles) {
|
|
67
|
+
fileNames.push(file.name.split("/").pop());
|
|
68
|
+
}
|
|
69
|
+
for (const file of userSessionFiles) {
|
|
70
|
+
fileNames.push(file.name.split("/").pop());
|
|
71
|
+
}
|
|
72
|
+
return fileNames.sort((a, b) => a.localeCompare(b));
|
|
73
|
+
}
|
|
74
|
+
async deleteArtifact(request) {
|
|
75
|
+
const versions = await this.listVersions(request);
|
|
76
|
+
await Promise.all(versions.map((version) => {
|
|
77
|
+
const file = this.bucket.file(getFileName({
|
|
78
|
+
...request,
|
|
79
|
+
version
|
|
80
|
+
}));
|
|
81
|
+
return file.delete();
|
|
82
|
+
}));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
async listVersions(request) {
|
|
86
|
+
const prefix = getFileName(request);
|
|
87
|
+
const [files] = await this.bucket.getFiles({ prefix });
|
|
88
|
+
const versions = [];
|
|
89
|
+
for (const file of files) {
|
|
90
|
+
const version = file.name.split("/").pop();
|
|
91
|
+
versions.push(parseInt(version, 10));
|
|
92
|
+
}
|
|
93
|
+
return versions;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function getFileName({
|
|
97
|
+
appName,
|
|
98
|
+
userId,
|
|
99
|
+
sessionId,
|
|
100
|
+
filename,
|
|
101
|
+
version
|
|
102
|
+
}) {
|
|
103
|
+
if (filename.startsWith("user:")) {
|
|
104
|
+
return `${appName}/${userId}/user/${filename}/${version}`;
|
|
105
|
+
}
|
|
106
|
+
return `${appName}/${userId}/${sessionId}/${filename}/${version}`;
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
GcsArtifactService
|
|
110
|
+
};
|
package/dist/esm/common.js
CHANGED
|
@@ -15,6 +15,7 @@ import { StreamingMode } from "./agents/run_config.js";
|
|
|
15
15
|
import { SequentialAgent } from "./agents/sequential_agent.js";
|
|
16
16
|
import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.js";
|
|
17
17
|
import { createEvent, getFunctionCalls, getFunctionResponses, hasTrailingCodeExecutionResult, isFinalResponse, stringifyContent } from "./events/event.js";
|
|
18
|
+
import { createEventActions } from "./events/event_actions.js";
|
|
18
19
|
import { InMemoryMemoryService } from "./memory/in_memory_memory_service.js";
|
|
19
20
|
import { BaseLlm } from "./models/base_llm.js";
|
|
20
21
|
import { Gemini } from "./models/google_llm.js";
|
|
@@ -74,6 +75,7 @@ export {
|
|
|
74
75
|
ToolConfirmation,
|
|
75
76
|
ToolContext,
|
|
76
77
|
createEvent,
|
|
78
|
+
createEventActions,
|
|
77
79
|
createSession,
|
|
78
80
|
functionsExportedForTestingOnly,
|
|
79
81
|
getAskUserConfirmationFunctionCalls,
|