@google/adk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/a2a_event.js +290 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +125 -0
- package/dist/cjs/a2a/part_converter_utils.js +23 -21
- package/dist/cjs/agents/base_agent.js +3 -3
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +70 -15
- package/dist/cjs/agents/functions.js +2 -2
- package/dist/cjs/agents/llm_agent.js +21 -674
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
- package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
- package/dist/cjs/agents/processors/content_request_processor.js +66 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
- package/dist/cjs/common.js +11 -7
- package/dist/cjs/index.js +89 -53
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/models/llm_response.js +2 -0
- package/dist/cjs/plugins/base_plugin.js +1 -1
- package/dist/cjs/runner/runner.js +1 -1
- package/dist/cjs/sessions/database_session_service.js +4 -1
- package/dist/cjs/sessions/db/operations.js +24 -12
- package/dist/cjs/tools/base_tool.js +3 -0
- package/dist/cjs/tools/base_toolset.js +13 -3
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +9 -5
- package/dist/cjs/utils/logger.js +61 -54
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_event.js +243 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +90 -0
- package/dist/esm/a2a/part_converter_utils.js +25 -21
- package/dist/esm/agents/base_agent.js +3 -3
- package/dist/esm/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +2 -2
- package/dist/esm/agents/llm_agent.js +14 -683
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
- package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
- package/dist/esm/agents/processors/content_request_processor.js +38 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
- package/dist/esm/common.js +11 -9
- package/dist/esm/index.js +95 -18
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +1 -1
- package/dist/esm/sessions/database_session_service.js +4 -1
- package/dist/esm/sessions/db/operations.js +31 -7
- package/dist/esm/tools/base_tool.js +3 -0
- package/dist/esm/tools/base_toolset.js +11 -2
- package/dist/esm/tools/exit_loop_tool.js +32 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/utils/logger.js +51 -54
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +122 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +62 -0
- package/dist/types/a2a/part_converter_utils.d.ts +4 -3
- package/dist/types/agents/base_agent.d.ts +2 -2
- package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
- package/dist/types/agents/llm_agent.d.ts +8 -31
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
- package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
- package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
- package/dist/types/common.d.ts +4 -4
- package/dist/types/models/llm_response.d.ts +5 -1
- package/dist/types/plugins/base_plugin.d.ts +12 -13
- package/dist/types/plugins/logging_plugin.d.ts +9 -10
- package/dist/types/plugins/plugin_manager.d.ts +9 -10
- package/dist/types/plugins/security_plugin.d.ts +2 -2
- package/dist/types/sessions/database_session_service.d.ts +2 -1
- package/dist/types/sessions/db/operations.d.ts +1 -1
- package/dist/types/tools/base_tool.d.ts +3 -3
- package/dist/types/tools/base_toolset.d.ts +12 -3
- package/dist/types/tools/exit_loop_tool.d.ts +24 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +243 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +107 -0
- package/dist/web/a2a/part_converter_utils.js +25 -21
- package/dist/web/agents/base_agent.js +3 -3
- package/dist/web/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/web/agents/functions.js +2 -2
- package/dist/web/agents/llm_agent.js +14 -661
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
- package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
- package/dist/web/agents/processors/content_request_processor.js +56 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
- package/dist/web/common.js +11 -9
- package/dist/web/index.js +13 -18
- package/dist/web/index.js.map +7 -0
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +1 -1
- package/dist/web/sessions/database_session_service.js +4 -1
- package/dist/web/sessions/db/operations.js +31 -7
- package/dist/web/tools/base_tool.js +3 -0
- package/dist/web/tools/base_toolset.js +11 -2
- package/dist/web/tools/exit_loop_tool.js +32 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/utils/logger.js +51 -54
- package/dist/web/version.js +1 -1
- package/package.json +3 -2
- package/dist/cjs/agents/callback_context.js +0 -101
- package/dist/esm/agents/callback_context.js +0 -71
- package/dist/types/agents/callback_context.d.ts +0 -42
- package/dist/web/agents/callback_context.js +0 -71
- /package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
|
@@ -12,6 +12,7 @@ function createLlmResponse(response) {
|
|
|
12
12
|
return {
|
|
13
13
|
content: candidate.content,
|
|
14
14
|
groundingMetadata: candidate.groundingMetadata,
|
|
15
|
+
citationMetadata: candidate.citationMetadata,
|
|
15
16
|
usageMetadata,
|
|
16
17
|
finishReason: candidate.finishReason
|
|
17
18
|
};
|
|
@@ -20,6 +21,7 @@ function createLlmResponse(response) {
|
|
|
20
21
|
errorCode: candidate.finishReason,
|
|
21
22
|
errorMessage: candidate.finishMessage,
|
|
22
23
|
usageMetadata,
|
|
24
|
+
citationMetadata: candidate.citationMetadata,
|
|
23
25
|
finishReason: candidate.finishReason
|
|
24
26
|
};
|
|
25
27
|
}
|
|
@@ -198,7 +198,7 @@ class BasePlugin {
|
|
|
198
198
|
* Callback executed when a tool call encounters an error.
|
|
199
199
|
tool: BaseTool;
|
|
200
200
|
toolArgs: Record<string, unknown>;
|
|
201
|
-
toolContext:
|
|
201
|
+
toolContext: Context;
|
|
202
202
|
result: Record<string, unknown>;
|
|
203
203
|
}): Promise<Record<string, unknown> | undefined> {
|
|
204
204
|
return;
|
|
@@ -310,7 +310,7 @@ class Runner {
|
|
|
310
310
|
return rootAgent.findAgent(event.author) || rootAgent;
|
|
311
311
|
}
|
|
312
312
|
for (let i = session.events.length - 1; i >= 0; i--) {
|
|
313
|
-
logger.info("event:
|
|
313
|
+
logger.info("event:", JSON.stringify(session.events[i]));
|
|
314
314
|
const event2 = session.events[i];
|
|
315
315
|
if (event2.author === "user" || !event2.author) {
|
|
316
316
|
continue;
|
|
@@ -57,7 +57,7 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
57
57
|
super();
|
|
58
58
|
this.initialized = false;
|
|
59
59
|
if (typeof connectionStringOrOptions === "string") {
|
|
60
|
-
this.
|
|
60
|
+
this.connectionString = connectionStringOrOptions;
|
|
61
61
|
} else {
|
|
62
62
|
if (!connectionStringOrOptions.driver) {
|
|
63
63
|
throw new Error("Driver is required when passing options object.");
|
|
@@ -71,6 +71,9 @@ class DatabaseSessionService extends BaseSessionService {
|
|
|
71
71
|
if (this.initialized) {
|
|
72
72
|
return;
|
|
73
73
|
}
|
|
74
|
+
if (this.connectionString && (!this.options || !this.options.driver)) {
|
|
75
|
+
this.options = await getConnectionOptionsFromUri(this.connectionString);
|
|
76
|
+
}
|
|
74
77
|
this.orm = await MikroORM.init(this.options);
|
|
75
78
|
await ensureDatabaseCreated(this.orm);
|
|
76
79
|
await validateDatabaseSchemaVersion(this.orm);
|
|
@@ -1,31 +1,53 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
1
23
|
/**
|
|
2
24
|
* @license
|
|
3
25
|
* Copyright 2026 Google LLC
|
|
4
26
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
27
|
*/
|
|
6
28
|
import { MikroORM } from "@mikro-orm/core";
|
|
7
|
-
import { MariaDbDriver } from "@mikro-orm/mariadb";
|
|
8
|
-
import { MsSqlDriver } from "@mikro-orm/mssql";
|
|
9
|
-
import { MySqlDriver } from "@mikro-orm/mysql";
|
|
10
|
-
import { PostgreSqlDriver } from "@mikro-orm/postgresql";
|
|
11
|
-
import { SqliteDriver } from "@mikro-orm/sqlite";
|
|
12
29
|
import {
|
|
13
30
|
ENTITIES,
|
|
14
31
|
SCHEMA_VERSION_1_JSON,
|
|
15
32
|
SCHEMA_VERSION_KEY,
|
|
16
33
|
StorageMetadata
|
|
17
34
|
} from "./schema.js";
|
|
18
|
-
function getConnectionOptionsFromUri(uri) {
|
|
35
|
+
async function getConnectionOptionsFromUri(uri) {
|
|
19
36
|
let driver;
|
|
20
37
|
if (uri.startsWith("postgres://") || uri.startsWith("postgresql://")) {
|
|
38
|
+
const { PostgreSqlDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/postgresql"), 1));
|
|
21
39
|
driver = PostgreSqlDriver;
|
|
22
40
|
} else if (uri.startsWith("mysql://")) {
|
|
41
|
+
const { MySqlDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/mysql"), 1));
|
|
23
42
|
driver = MySqlDriver;
|
|
24
43
|
} else if (uri.startsWith("mariadb://")) {
|
|
44
|
+
const { MariaDbDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/mariadb"), 1));
|
|
25
45
|
driver = MariaDbDriver;
|
|
26
46
|
} else if (uri.startsWith("sqlite://")) {
|
|
47
|
+
const { SqliteDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/sqlite"), 1));
|
|
27
48
|
driver = SqliteDriver;
|
|
28
49
|
} else if (uri.startsWith("mssql://")) {
|
|
50
|
+
const { MsSqlDriver } = await Promise.resolve().then(() => __toESM(require("@mikro-orm/mssql"), 1));
|
|
29
51
|
driver = MsSqlDriver;
|
|
30
52
|
} else {
|
|
31
53
|
throw new Error("Unsupported database URI: ".concat(uri));
|
|
@@ -54,7 +76,9 @@ async function ensureDatabaseCreated(ormOrUrlOrOptions) {
|
|
|
54
76
|
if (ormOrUrlOrOptions instanceof MikroORM) {
|
|
55
77
|
orm = ormOrUrlOrOptions;
|
|
56
78
|
} else if (typeof ormOrUrlOrOptions === "string") {
|
|
57
|
-
orm = await MikroORM.init(
|
|
79
|
+
orm = await MikroORM.init(
|
|
80
|
+
await getConnectionOptionsFromUri(ormOrUrlOrOptions)
|
|
81
|
+
);
|
|
58
82
|
} else {
|
|
59
83
|
orm = await MikroORM.init(ormOrUrlOrOptions);
|
|
60
84
|
}
|
|
@@ -54,6 +54,9 @@ class BaseTool {
|
|
|
54
54
|
if (!functionDeclaration) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
+
if (this.name in llmRequest.toolsDict) {
|
|
58
|
+
throw new Error("Duplicate tool name: ".concat(this.name));
|
|
59
|
+
}
|
|
57
60
|
llmRequest.toolsDict[this.name] = this;
|
|
58
61
|
const tool = findToolWithFunctionDeclarations(llmRequest);
|
|
59
62
|
if (tool) {
|
|
@@ -3,9 +3,17 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
var _a;
|
|
7
|
+
const BASE_TOOLSET_SIGNATURE_SYMBOL = Symbol.for("google.adk.baseToolset");
|
|
8
|
+
function isBaseToolset(obj) {
|
|
9
|
+
return typeof obj === "object" && obj !== null && BASE_TOOLSET_SIGNATURE_SYMBOL in obj && obj[BASE_TOOLSET_SIGNATURE_SYMBOL] === true;
|
|
10
|
+
}
|
|
11
|
+
_a = BASE_TOOLSET_SIGNATURE_SYMBOL;
|
|
6
12
|
class BaseToolset {
|
|
7
|
-
constructor(toolFilter) {
|
|
13
|
+
constructor(toolFilter, prefix) {
|
|
8
14
|
this.toolFilter = toolFilter;
|
|
15
|
+
this.prefix = prefix;
|
|
16
|
+
this[_a] = true;
|
|
9
17
|
}
|
|
10
18
|
/**
|
|
11
19
|
* Returns whether the tool should be exposed to LLM.
|
|
@@ -42,5 +50,6 @@ class BaseToolset {
|
|
|
42
50
|
}
|
|
43
51
|
}
|
|
44
52
|
export {
|
|
45
|
-
BaseToolset
|
|
53
|
+
BaseToolset,
|
|
54
|
+
isBaseToolset
|
|
46
55
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseTool } from "./base_tool.js";
|
|
7
|
+
class ExitLoopTool extends BaseTool {
|
|
8
|
+
constructor() {
|
|
9
|
+
super({
|
|
10
|
+
name: "exit_loop",
|
|
11
|
+
description: "Exits the loop.\n\nCall this function only when you are instructed to do so."
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
_getDeclaration() {
|
|
15
|
+
return {
|
|
16
|
+
name: this.name,
|
|
17
|
+
description: this.description
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
async runAsync({
|
|
21
|
+
toolContext
|
|
22
|
+
}) {
|
|
23
|
+
toolContext.actions.escalate = true;
|
|
24
|
+
toolContext.actions.skipSummarization = true;
|
|
25
|
+
return "";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const EXIT_LOOP = new ExitLoopTool();
|
|
29
|
+
export {
|
|
30
|
+
EXIT_LOOP,
|
|
31
|
+
ExitLoopTool
|
|
32
|
+
};
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1
20
|
/**
|
|
2
21
|
* @license
|
|
3
22
|
* Copyright 2025 Google LLC
|
|
@@ -8,8 +27,8 @@ import { BaseToolset } from "../base_toolset.js";
|
|
|
8
27
|
import { MCPSessionManager } from "./mcp_session_manager.js";
|
|
9
28
|
import { MCPTool } from "./mcp_tool.js";
|
|
10
29
|
class MCPToolset extends BaseToolset {
|
|
11
|
-
constructor(connectionParams, toolFilter = []) {
|
|
12
|
-
super(toolFilter);
|
|
30
|
+
constructor(connectionParams, toolFilter = [], prefix) {
|
|
31
|
+
super(toolFilter, prefix);
|
|
13
32
|
this.mcpSessionManager = new MCPSessionManager(connectionParams);
|
|
14
33
|
}
|
|
15
34
|
async getTools() {
|
|
@@ -19,9 +38,12 @@ class MCPToolset extends BaseToolset {
|
|
|
19
38
|
for (const tool of listResult.tools) {
|
|
20
39
|
logger.debug("tool: ".concat(tool.name));
|
|
21
40
|
}
|
|
22
|
-
return listResult.tools.map(
|
|
23
|
-
|
|
24
|
-
|
|
41
|
+
return listResult.tools.map((tool) => {
|
|
42
|
+
const toolWithPrefix = __spreadProps(__spreadValues({}, tool), {
|
|
43
|
+
name: this.prefix ? "".concat(this.prefix, "_").concat(tool.name) : tool.name
|
|
44
|
+
});
|
|
45
|
+
return new MCPTool(toolWithPrefix, this.mcpSessionManager);
|
|
46
|
+
});
|
|
25
47
|
}
|
|
26
48
|
async close() {
|
|
27
49
|
}
|
package/dist/web/utils/logger.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import * as winston from "winston";
|
|
6
7
|
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
7
8
|
LogLevel2[LogLevel2["DEBUG"] = 0] = "DEBUG";
|
|
8
9
|
LogLevel2[LogLevel2["INFO"] = 1] = "INFO";
|
|
@@ -10,58 +11,68 @@ var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
|
10
11
|
LogLevel2[LogLevel2["ERROR"] = 3] = "ERROR";
|
|
11
12
|
return LogLevel2;
|
|
12
13
|
})(LogLevel || {});
|
|
13
|
-
let logLevel = 1 /* INFO */;
|
|
14
|
-
function setLogLevel(level) {
|
|
15
|
-
logLevel = level;
|
|
16
|
-
}
|
|
17
14
|
class SimpleLogger {
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
constructor() {
|
|
16
|
+
this.logLevel = 1 /* INFO */;
|
|
17
|
+
this.logger = winston.createLogger({
|
|
18
|
+
levels: {
|
|
19
|
+
"debug": 0 /* DEBUG */,
|
|
20
|
+
"info": 1 /* INFO */,
|
|
21
|
+
"warn": 2 /* WARN */,
|
|
22
|
+
"error": 3 /* ERROR */
|
|
23
|
+
},
|
|
24
|
+
format: winston.format.combine(
|
|
25
|
+
winston.format.label({ label: "ADK" }),
|
|
26
|
+
winston.format((info) => {
|
|
27
|
+
info.level = info.level.toUpperCase();
|
|
28
|
+
return info;
|
|
29
|
+
})(),
|
|
30
|
+
winston.format.colorize(),
|
|
31
|
+
winston.format.timestamp(),
|
|
32
|
+
winston.format.printf((info) => {
|
|
33
|
+
return "".concat(info.level, ": [").concat(info.label, "] ").concat(info.timestamp, " ").concat(info.message);
|
|
34
|
+
})
|
|
35
|
+
),
|
|
36
|
+
transports: [new winston.transports.Console()]
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
setLogLevel(level) {
|
|
40
|
+
this.logLevel = level;
|
|
41
|
+
}
|
|
42
|
+
log(level, ...messages) {
|
|
43
|
+
if (this.logLevel > level) {
|
|
20
44
|
return;
|
|
21
45
|
}
|
|
22
|
-
|
|
23
|
-
case 0 /* DEBUG */:
|
|
24
|
-
this.debug(...args);
|
|
25
|
-
break;
|
|
26
|
-
case 1 /* INFO */:
|
|
27
|
-
this.info(...args);
|
|
28
|
-
break;
|
|
29
|
-
case 2 /* WARN */:
|
|
30
|
-
this.warn(...args);
|
|
31
|
-
break;
|
|
32
|
-
case 3 /* ERROR */:
|
|
33
|
-
this.error(...args);
|
|
34
|
-
break;
|
|
35
|
-
default:
|
|
36
|
-
throw new Error("Unsupported log level: ".concat(level));
|
|
37
|
-
}
|
|
46
|
+
this.logger.log(level.toString(), messages.join(" "));
|
|
38
47
|
}
|
|
39
|
-
debug(...
|
|
40
|
-
if (logLevel > 0 /* DEBUG */) {
|
|
48
|
+
debug(...messages) {
|
|
49
|
+
if (this.logLevel > 0 /* DEBUG */) {
|
|
41
50
|
return;
|
|
42
51
|
}
|
|
43
|
-
|
|
52
|
+
this.logger.debug(messages.join(" "));
|
|
44
53
|
}
|
|
45
|
-
info(...
|
|
46
|
-
if (logLevel > 1 /* INFO */) {
|
|
54
|
+
info(...messages) {
|
|
55
|
+
if (this.logLevel > 1 /* INFO */) {
|
|
47
56
|
return;
|
|
48
57
|
}
|
|
49
|
-
|
|
58
|
+
this.logger.info(messages.join(" "));
|
|
50
59
|
}
|
|
51
|
-
warn(...
|
|
52
|
-
if (logLevel > 2 /* WARN */) {
|
|
60
|
+
warn(...messages) {
|
|
61
|
+
if (this.logLevel > 2 /* WARN */) {
|
|
53
62
|
return;
|
|
54
63
|
}
|
|
55
|
-
|
|
64
|
+
this.logger.warn(messages.join(" "));
|
|
56
65
|
}
|
|
57
|
-
error(...
|
|
58
|
-
if (logLevel > 3 /* ERROR */) {
|
|
66
|
+
error(...messages) {
|
|
67
|
+
if (this.logLevel > 3 /* ERROR */) {
|
|
59
68
|
return;
|
|
60
69
|
}
|
|
61
|
-
|
|
70
|
+
this.logger.error(messages.join(" "));
|
|
62
71
|
}
|
|
63
72
|
}
|
|
64
73
|
class NoOpLogger {
|
|
74
|
+
setLogLevel(_level) {
|
|
75
|
+
}
|
|
65
76
|
log(_level, ..._args) {
|
|
66
77
|
}
|
|
67
78
|
debug(..._args) {
|
|
@@ -73,26 +84,6 @@ class NoOpLogger {
|
|
|
73
84
|
error(..._args) {
|
|
74
85
|
}
|
|
75
86
|
}
|
|
76
|
-
const LOG_LEVEL_STR = {
|
|
77
|
-
[0 /* DEBUG */]: "DEBUG",
|
|
78
|
-
[1 /* INFO */]: "INFO",
|
|
79
|
-
[2 /* WARN */]: "WARN",
|
|
80
|
-
[3 /* ERROR */]: "ERROR"
|
|
81
|
-
};
|
|
82
|
-
const CONSOLE_COLOR_MAP = {
|
|
83
|
-
[0 /* DEBUG */]: "\x1B[34m",
|
|
84
|
-
// Blue
|
|
85
|
-
[1 /* INFO */]: "\x1B[32m",
|
|
86
|
-
// Green
|
|
87
|
-
[2 /* WARN */]: "\x1B[33m",
|
|
88
|
-
// Yellow
|
|
89
|
-
[3 /* ERROR */]: "\x1B[31m"
|
|
90
|
-
// Red
|
|
91
|
-
};
|
|
92
|
-
const RESET_COLOR = "\x1B[0m";
|
|
93
|
-
function getColoredPrefix(level) {
|
|
94
|
-
return "".concat(CONSOLE_COLOR_MAP[level], "[ADK ").concat(LOG_LEVEL_STR[level], "]:").concat(RESET_COLOR);
|
|
95
|
-
}
|
|
96
87
|
let currentLogger = new SimpleLogger();
|
|
97
88
|
function setLogger(customLogger) {
|
|
98
89
|
currentLogger = customLogger != null ? customLogger : new NoOpLogger();
|
|
@@ -103,7 +94,13 @@ function getLogger() {
|
|
|
103
94
|
function resetLogger() {
|
|
104
95
|
currentLogger = new SimpleLogger();
|
|
105
96
|
}
|
|
97
|
+
function setLogLevel(level) {
|
|
98
|
+
logger.setLogLevel(level);
|
|
99
|
+
}
|
|
106
100
|
const logger = {
|
|
101
|
+
setLogLevel(level) {
|
|
102
|
+
currentLogger.setLogLevel(level);
|
|
103
|
+
},
|
|
107
104
|
log(level, ...args) {
|
|
108
105
|
currentLogger.log(level, ...args);
|
|
109
106
|
},
|
package/dist/web/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@google/adk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Google ADK JS",
|
|
5
5
|
"author": "Google",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -37,10 +37,11 @@
|
|
|
37
37
|
"test": "vitest",
|
|
38
38
|
"lint": "eslint 'src/**/*.ts'",
|
|
39
39
|
"format": "prettier --write 'src/**/*.ts'",
|
|
40
|
-
"prepublishOnly": "npm run build"
|
|
40
|
+
"prepublishOnly": "npm run build:bundle"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@a2a-js/sdk": "^0.3.10",
|
|
44
|
+
"winston": "^3.19.0",
|
|
44
45
|
"@google/genai": "^1.37.0",
|
|
45
46
|
"@mikro-orm/core": "^6.6.6",
|
|
46
47
|
"@mikro-orm/reflection": "^6.6.6",
|
|
@@ -1,101 +0,0 @@
|
|
|
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 callback_context_exports = {};
|
|
26
|
-
__export(callback_context_exports, {
|
|
27
|
-
CallbackContext: () => CallbackContext
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(callback_context_exports);
|
|
30
|
-
var import_event_actions = require("../events/event_actions.js");
|
|
31
|
-
var import_state = require("../sessions/state.js");
|
|
32
|
-
var import_readonly_context = require("./readonly_context.js");
|
|
33
|
-
/**
|
|
34
|
-
* @license
|
|
35
|
-
* Copyright 2025 Google LLC
|
|
36
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
-
*/
|
|
38
|
-
class CallbackContext extends import_readonly_context.ReadonlyContext {
|
|
39
|
-
constructor({
|
|
40
|
-
invocationContext,
|
|
41
|
-
eventActions
|
|
42
|
-
}) {
|
|
43
|
-
super(invocationContext);
|
|
44
|
-
this.eventActions = eventActions || (0, import_event_actions.createEventActions)();
|
|
45
|
-
this._state = new import_state.State(
|
|
46
|
-
invocationContext.session.state,
|
|
47
|
-
this.eventActions.stateDelta
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* The delta-aware state of the current session.
|
|
52
|
-
*/
|
|
53
|
-
get state() {
|
|
54
|
-
return this._state;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Loads an artifact attached to the current session.
|
|
58
|
-
*
|
|
59
|
-
* @param filename The filename of the artifact.
|
|
60
|
-
* @param version The version of the artifact. If not provided, the latest
|
|
61
|
-
* version will be used.
|
|
62
|
-
* @return A promise that resolves to the loaded artifact.
|
|
63
|
-
*/
|
|
64
|
-
loadArtifact(filename, version) {
|
|
65
|
-
if (!this.invocationContext.artifactService) {
|
|
66
|
-
throw new Error("Artifact service is not initialized.");
|
|
67
|
-
}
|
|
68
|
-
return this.invocationContext.artifactService.loadArtifact({
|
|
69
|
-
appName: this.invocationContext.appName,
|
|
70
|
-
userId: this.invocationContext.userId,
|
|
71
|
-
sessionId: this.invocationContext.session.id,
|
|
72
|
-
filename,
|
|
73
|
-
version
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Saves an artifact attached to the current session.
|
|
78
|
-
*
|
|
79
|
-
* @param filename The filename of the artifact.
|
|
80
|
-
* @param artifact The artifact to save.
|
|
81
|
-
* @return A promise that resolves to the version of the saved artifact.
|
|
82
|
-
*/
|
|
83
|
-
async saveArtifact(filename, artifact) {
|
|
84
|
-
if (!this.invocationContext.artifactService) {
|
|
85
|
-
throw new Error("Artifact service is not initialized.");
|
|
86
|
-
}
|
|
87
|
-
const version = await this.invocationContext.artifactService.saveArtifact({
|
|
88
|
-
appName: this.invocationContext.appName,
|
|
89
|
-
userId: this.invocationContext.userId,
|
|
90
|
-
sessionId: this.invocationContext.session.id,
|
|
91
|
-
filename,
|
|
92
|
-
artifact
|
|
93
|
-
});
|
|
94
|
-
this.eventActions.artifactDelta[filename] = version;
|
|
95
|
-
return version;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
-
0 && (module.exports = {
|
|
100
|
-
CallbackContext
|
|
101
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
import { createEventActions } from "../events/event_actions.js";
|
|
7
|
-
import { State } from "../sessions/state.js";
|
|
8
|
-
import { ReadonlyContext } from "./readonly_context.js";
|
|
9
|
-
class CallbackContext extends ReadonlyContext {
|
|
10
|
-
constructor({
|
|
11
|
-
invocationContext,
|
|
12
|
-
eventActions
|
|
13
|
-
}) {
|
|
14
|
-
super(invocationContext);
|
|
15
|
-
this.eventActions = eventActions || createEventActions();
|
|
16
|
-
this._state = new State(
|
|
17
|
-
invocationContext.session.state,
|
|
18
|
-
this.eventActions.stateDelta
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* The delta-aware state of the current session.
|
|
23
|
-
*/
|
|
24
|
-
get state() {
|
|
25
|
-
return this._state;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Loads an artifact attached to the current session.
|
|
29
|
-
*
|
|
30
|
-
* @param filename The filename of the artifact.
|
|
31
|
-
* @param version The version of the artifact. If not provided, the latest
|
|
32
|
-
* version will be used.
|
|
33
|
-
* @return A promise that resolves to the loaded artifact.
|
|
34
|
-
*/
|
|
35
|
-
loadArtifact(filename, version) {
|
|
36
|
-
if (!this.invocationContext.artifactService) {
|
|
37
|
-
throw new Error("Artifact service is not initialized.");
|
|
38
|
-
}
|
|
39
|
-
return this.invocationContext.artifactService.loadArtifact({
|
|
40
|
-
appName: this.invocationContext.appName,
|
|
41
|
-
userId: this.invocationContext.userId,
|
|
42
|
-
sessionId: this.invocationContext.session.id,
|
|
43
|
-
filename,
|
|
44
|
-
version
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Saves an artifact attached to the current session.
|
|
49
|
-
*
|
|
50
|
-
* @param filename The filename of the artifact.
|
|
51
|
-
* @param artifact The artifact to save.
|
|
52
|
-
* @return A promise that resolves to the version of the saved artifact.
|
|
53
|
-
*/
|
|
54
|
-
async saveArtifact(filename, artifact) {
|
|
55
|
-
if (!this.invocationContext.artifactService) {
|
|
56
|
-
throw new Error("Artifact service is not initialized.");
|
|
57
|
-
}
|
|
58
|
-
const version = await this.invocationContext.artifactService.saveArtifact({
|
|
59
|
-
appName: this.invocationContext.appName,
|
|
60
|
-
userId: this.invocationContext.userId,
|
|
61
|
-
sessionId: this.invocationContext.session.id,
|
|
62
|
-
filename,
|
|
63
|
-
artifact
|
|
64
|
-
});
|
|
65
|
-
this.eventActions.artifactDelta[filename] = version;
|
|
66
|
-
return version;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
export {
|
|
70
|
-
CallbackContext
|
|
71
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
import { Part } from '@google/genai';
|
|
7
|
-
import { EventActions } from '../events/event_actions.js';
|
|
8
|
-
import { State } from '../sessions/state.js';
|
|
9
|
-
import { InvocationContext } from './invocation_context.js';
|
|
10
|
-
import { ReadonlyContext } from './readonly_context.js';
|
|
11
|
-
/**
|
|
12
|
-
* The context of various callbacks within an agent run.
|
|
13
|
-
*/
|
|
14
|
-
export declare class CallbackContext extends ReadonlyContext {
|
|
15
|
-
private readonly _state;
|
|
16
|
-
readonly eventActions: EventActions;
|
|
17
|
-
constructor({ invocationContext, eventActions, }: {
|
|
18
|
-
invocationContext: InvocationContext;
|
|
19
|
-
eventActions?: EventActions;
|
|
20
|
-
});
|
|
21
|
-
/**
|
|
22
|
-
* The delta-aware state of the current session.
|
|
23
|
-
*/
|
|
24
|
-
get state(): State;
|
|
25
|
-
/**
|
|
26
|
-
* Loads an artifact attached to the current session.
|
|
27
|
-
*
|
|
28
|
-
* @param filename The filename of the artifact.
|
|
29
|
-
* @param version The version of the artifact. If not provided, the latest
|
|
30
|
-
* version will be used.
|
|
31
|
-
* @return A promise that resolves to the loaded artifact.
|
|
32
|
-
*/
|
|
33
|
-
loadArtifact(filename: string, version?: number): Promise<Part | undefined>;
|
|
34
|
-
/**
|
|
35
|
-
* Saves an artifact attached to the current session.
|
|
36
|
-
*
|
|
37
|
-
* @param filename The filename of the artifact.
|
|
38
|
-
* @param artifact The artifact to save.
|
|
39
|
-
* @return A promise that resolves to the version of the saved artifact.
|
|
40
|
-
*/
|
|
41
|
-
saveArtifact(filename: string, artifact: Part): Promise<number>;
|
|
42
|
-
}
|