@google/adk 0.2.5 → 0.3.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/base_agent.js +43 -21
- package/dist/cjs/agents/callback_context.js +4 -1
- package/dist/cjs/agents/content_processor_utils.js +15 -7
- package/dist/cjs/agents/functions.js +79 -29
- package/dist/cjs/agents/llm_agent.js +59 -33
- package/dist/cjs/agents/loop_agent.js +2 -1
- package/dist/cjs/agents/parallel_agent.js +3 -4
- package/dist/cjs/artifacts/gcs_artifact_service.js +28 -20
- package/dist/cjs/artifacts/in_memory_artifact_service.js +18 -4
- package/dist/cjs/auth/auth_handler.js +3 -1
- package/dist/cjs/code_executors/base_code_executor.js +3 -1
- package/dist/cjs/code_executors/built_in_code_executor.js +7 -3
- package/dist/cjs/code_executors/code_executor_context.js +5 -5
- package/dist/cjs/common.js +4 -0
- package/dist/cjs/events/event.js +1 -3
- package/dist/cjs/index.js +19 -19
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/memory/in_memory_memory_service.js +3 -1
- package/dist/cjs/models/base_llm.js +8 -4
- package/dist/cjs/models/gemini_llm_connection.js +1 -0
- package/dist/cjs/models/google_llm.js +3 -3
- package/dist/cjs/plugins/base_plugin.js +12 -0
- package/dist/cjs/plugins/logging_plugin.js +50 -13
- package/dist/cjs/plugins/plugin_manager.js +56 -24
- package/dist/cjs/plugins/security_plugin.js +1 -1
- package/dist/cjs/runner/runner.js +110 -95
- package/dist/cjs/sessions/in_memory_session_service.js +38 -14
- package/dist/cjs/telemetry/google_cloud.js +7 -9
- package/dist/cjs/telemetry/setup.js +15 -7
- package/dist/cjs/telemetry/tracing.js +37 -15
- package/dist/cjs/tools/agent_tool.js +8 -4
- package/dist/cjs/tools/base_tool.js +4 -2
- package/dist/cjs/tools/forwarding_artifact_service.js +1 -1
- package/dist/cjs/tools/function_tool.js +1 -2
- package/dist/cjs/tools/google_search_tool.js +1 -2
- package/dist/cjs/tools/mcp/mcp_session_manager.js +16 -10
- package/dist/cjs/tools/mcp/mcp_tool.js +1 -3
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +1 -1
- package/dist/cjs/utils/gemini_schema_util.js +9 -4
- package/dist/cjs/utils/logger.js +47 -3
- package/dist/cjs/utils/simple_zod_to_json.js +100 -141
- package/dist/cjs/utils/variant_utils.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +48 -22
- package/dist/esm/agents/callback_context.js +4 -1
- package/dist/esm/agents/content_processor_utils.js +25 -9
- package/dist/esm/agents/functions.js +83 -29
- package/dist/esm/agents/llm_agent.js +63 -33
- package/dist/esm/agents/loop_agent.js +2 -1
- package/dist/esm/agents/parallel_agent.js +3 -4
- package/dist/esm/artifacts/gcs_artifact_service.js +28 -20
- package/dist/esm/artifacts/in_memory_artifact_service.js +18 -4
- package/dist/esm/auth/auth_handler.js +3 -1
- package/dist/esm/code_executors/base_code_executor.js +3 -1
- package/dist/esm/code_executors/built_in_code_executor.js +7 -3
- package/dist/esm/code_executors/code_executor_context.js +5 -5
- package/dist/esm/common.js +3 -1
- package/dist/esm/events/event.js +1 -3
- package/dist/esm/index.js +19 -19
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/memory/in_memory_memory_service.js +3 -1
- package/dist/esm/models/base_llm.js +8 -4
- package/dist/esm/models/gemini_llm_connection.js +1 -0
- package/dist/esm/models/google_llm.js +8 -4
- package/dist/esm/plugins/base_plugin.js +12 -0
- package/dist/esm/plugins/logging_plugin.js +55 -14
- package/dist/esm/plugins/plugin_manager.js +56 -24
- package/dist/esm/plugins/security_plugin.js +1 -1
- package/dist/esm/runner/runner.js +114 -96
- package/dist/esm/sessions/in_memory_session_service.js +41 -15
- package/dist/esm/telemetry/google_cloud.js +7 -9
- package/dist/esm/telemetry/setup.js +23 -9
- package/dist/esm/telemetry/tracing.js +37 -15
- package/dist/esm/tools/agent_tool.js +8 -4
- package/dist/esm/tools/base_tool.js +4 -2
- package/dist/esm/tools/forwarding_artifact_service.js +1 -1
- package/dist/esm/tools/function_tool.js +1 -2
- package/dist/esm/tools/google_search_tool.js +2 -5
- package/dist/esm/tools/long_running_tool.js +3 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/esm/tools/mcp/mcp_tool.js +1 -3
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
- package/dist/esm/utils/env_aware_utils.js +1 -1
- package/dist/esm/utils/gemini_schema_util.js +9 -4
- package/dist/esm/utils/logger.js +43 -2
- package/dist/esm/utils/simple_zod_to_json.js +102 -141
- package/dist/esm/utils/variant_utils.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/base_agent.d.ts +2 -1
- package/dist/types/agents/callback_context.d.ts +1 -1
- package/dist/types/agents/llm_agent.d.ts +1 -1
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/parallel_agent.d.ts +1 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +3 -3
- package/dist/types/code_executors/built_in_code_executor.d.ts +1 -1
- package/dist/types/code_executors/code_executor_context.d.ts +2 -4
- package/dist/types/common.d.ts +2 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/models/base_llm_connection.d.ts +1 -1
- package/dist/types/models/llm_response.d.ts +1 -1
- package/dist/types/plugins/logging_plugin.d.ts +12 -12
- package/dist/types/plugins/plugin_manager.d.ts +12 -12
- package/dist/types/plugins/security_plugin.d.ts +1 -1
- package/dist/types/runner/runner.d.ts +1 -1
- package/dist/types/sessions/in_memory_session_service.d.ts +5 -5
- package/dist/types/telemetry/setup.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +7 -6
- package/dist/types/tools/agent_tool.d.ts +1 -1
- package/dist/types/tools/base_tool.d.ts +1 -1
- package/dist/types/tools/base_toolset.d.ts +2 -1
- package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +4 -3
- package/dist/types/tools/google_search_tool.d.ts +3 -3
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
- package/dist/types/utils/gemini_schema_util.d.ts +4 -12
- package/dist/types/utils/logger.d.ts +11 -10
- package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +94 -33
- package/dist/web/agents/callback_context.js +4 -1
- package/dist/web/agents/content_processor_utils.js +25 -9
- package/dist/web/agents/functions.js +83 -29
- package/dist/web/agents/llm_agent.js +117 -54
- package/dist/web/agents/loop_agent.js +2 -1
- package/dist/web/agents/parallel_agent.js +3 -4
- package/dist/web/artifacts/gcs_artifact_service.js +25 -17
- package/dist/web/artifacts/in_memory_artifact_service.js +18 -4
- package/dist/web/auth/auth_handler.js +3 -1
- package/dist/web/code_executors/base_code_executor.js +3 -1
- package/dist/web/code_executors/built_in_code_executor.js +7 -3
- package/dist/web/code_executors/code_executor_context.js +5 -5
- package/dist/web/common.js +3 -1
- package/dist/web/events/event.js +1 -3
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/memory/in_memory_memory_service.js +3 -1
- package/dist/web/models/base_llm.js +8 -4
- package/dist/web/models/gemini_llm_connection.js +1 -0
- package/dist/web/models/google_llm.js +8 -4
- package/dist/web/plugins/base_plugin.js +12 -0
- package/dist/web/plugins/logging_plugin.js +55 -14
- package/dist/web/plugins/plugin_manager.js +56 -24
- package/dist/web/plugins/security_plugin.js +1 -1
- package/dist/web/runner/runner.js +159 -108
- package/dist/web/sessions/in_memory_session_service.js +41 -15
- package/dist/web/telemetry/google_cloud.js +7 -9
- package/dist/web/telemetry/setup.js +23 -9
- package/dist/web/telemetry/tracing.js +37 -15
- package/dist/web/tools/agent_tool.js +8 -4
- package/dist/web/tools/base_tool.js +4 -2
- package/dist/web/tools/forwarding_artifact_service.js +1 -1
- package/dist/web/tools/function_tool.js +1 -2
- package/dist/web/tools/google_search_tool.js +2 -5
- package/dist/web/tools/long_running_tool.js +3 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/web/tools/mcp/mcp_tool.js +1 -3
- package/dist/web/tools/mcp/mcp_toolset.js +1 -1
- package/dist/web/utils/env_aware_utils.js +1 -1
- package/dist/web/utils/gemini_schema_util.js +9 -4
- package/dist/web/utils/logger.js +43 -2
- package/dist/web/utils/simple_zod_to_json.js +102 -155
- package/dist/web/utils/variant_utils.js +1 -1
- package/dist/web/version.js +1 -1
- package/package.json +4 -2
|
@@ -4,13 +4,18 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
StdioClientTransport
|
|
9
|
+
} from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
10
|
+
import {
|
|
11
|
+
StreamableHTTPClientTransport
|
|
12
|
+
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
9
13
|
class MCPSessionManager {
|
|
10
14
|
constructor(connectionParams) {
|
|
11
15
|
this.connectionParams = connectionParams;
|
|
12
16
|
}
|
|
13
17
|
async createSession() {
|
|
18
|
+
var _a;
|
|
14
19
|
const client = new Client({ name: "MCPClient", version: "1.0.0" });
|
|
15
20
|
switch (this.connectionParams.type) {
|
|
16
21
|
case "StdioConnectionParams":
|
|
@@ -18,20 +23,25 @@ class MCPSessionManager {
|
|
|
18
23
|
new StdioClientTransport(this.connectionParams.serverParams)
|
|
19
24
|
);
|
|
20
25
|
break;
|
|
21
|
-
case "StreamableHTTPConnectionParams":
|
|
22
|
-
const
|
|
23
|
-
|
|
26
|
+
case "StreamableHTTPConnectionParams": {
|
|
27
|
+
const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
|
|
28
|
+
if (!options.requestInit && this.connectionParams.header !== void 0) {
|
|
29
|
+
options.requestInit = {
|
|
24
30
|
headers: this.connectionParams.header
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
await client.connect(
|
|
28
|
-
new
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
await client.connect(
|
|
34
|
+
new StreamableHTTPClientTransport(
|
|
35
|
+
new URL(this.connectionParams.url),
|
|
36
|
+
options
|
|
37
|
+
)
|
|
38
|
+
);
|
|
31
39
|
break;
|
|
32
|
-
|
|
40
|
+
}
|
|
41
|
+
default: {
|
|
33
42
|
const _exhaustiveCheck = this.connectionParams;
|
|
34
43
|
break;
|
|
44
|
+
}
|
|
35
45
|
}
|
|
36
46
|
return client;
|
|
37
47
|
}
|
|
@@ -12,8 +12,7 @@ class MCPTool extends BaseTool {
|
|
|
12
12
|
this.mcpSessionManager = mcpSessionManager;
|
|
13
13
|
}
|
|
14
14
|
_getDeclaration() {
|
|
15
|
-
|
|
16
|
-
declaration = {
|
|
15
|
+
return {
|
|
17
16
|
name: this.mcpTool.name,
|
|
18
17
|
description: this.mcpTool.description,
|
|
19
18
|
parameters: toGeminiSchema(this.mcpTool.inputSchema),
|
|
@@ -21,7 +20,6 @@ class MCPTool extends BaseTool {
|
|
|
21
20
|
// https://modelcontextprotocol.io/specification/2025-06-18/server/tools#tool-result
|
|
22
21
|
response: toGeminiSchema(this.mcpTool.outputSchema)
|
|
23
22
|
};
|
|
24
|
-
return declaration;
|
|
25
23
|
}
|
|
26
24
|
async runAsync(request) {
|
|
27
25
|
const session = await this.mcpSessionManager.createSession();
|
|
@@ -12,7 +12,7 @@ class MCPToolset extends BaseToolset {
|
|
|
12
12
|
super(toolFilter);
|
|
13
13
|
this.mcpSessionManager = new MCPSessionManager(connectionParams);
|
|
14
14
|
}
|
|
15
|
-
async getTools(
|
|
15
|
+
async getTools() {
|
|
16
16
|
const session = await this.mcpSessionManager.createSession();
|
|
17
17
|
const listResult = await session.listTools();
|
|
18
18
|
logger.debug(`number of tools: ${listResult.tools.length}`);
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Type } from "@google/genai";
|
|
7
7
|
import { z } from "zod";
|
|
8
|
-
const
|
|
8
|
+
const MCPToolSchemaObject = z.object({
|
|
9
9
|
type: z.literal("object"),
|
|
10
|
-
properties: z.record(z.unknown()).optional(),
|
|
10
|
+
properties: z.record(z.string(), z.unknown()).optional(),
|
|
11
11
|
required: z.string().array().optional()
|
|
12
12
|
});
|
|
13
13
|
function toGeminiType(mcpType) {
|
|
@@ -52,12 +52,17 @@ function toGeminiSchema(mcpSchema) {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
const geminiType = toGeminiType(mcp.type);
|
|
55
|
-
const geminiSchema = {
|
|
55
|
+
const geminiSchema = {
|
|
56
|
+
type: geminiType,
|
|
57
|
+
description: mcp.description
|
|
58
|
+
};
|
|
56
59
|
if (geminiType === Type.OBJECT) {
|
|
57
60
|
geminiSchema.properties = {};
|
|
58
61
|
if (mcp.properties) {
|
|
59
62
|
for (const name in mcp.properties) {
|
|
60
|
-
geminiSchema.properties[name] = recursiveConvert(
|
|
63
|
+
geminiSchema.properties[name] = recursiveConvert(
|
|
64
|
+
mcp.properties[name]
|
|
65
|
+
);
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
geminiSchema.required = mcp.required;
|
package/dist/esm/utils/logger.js
CHANGED
|
@@ -61,6 +61,18 @@ class SimpleLogger {
|
|
|
61
61
|
console.error(getColoredPrefix(3 /* ERROR */), ...args);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
class NoOpLogger {
|
|
65
|
+
log(_level, ..._args) {
|
|
66
|
+
}
|
|
67
|
+
debug(..._args) {
|
|
68
|
+
}
|
|
69
|
+
info(..._args) {
|
|
70
|
+
}
|
|
71
|
+
warn(..._args) {
|
|
72
|
+
}
|
|
73
|
+
error(..._args) {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
64
76
|
const LOG_LEVEL_STR = {
|
|
65
77
|
[0 /* DEBUG */]: "DEBUG",
|
|
66
78
|
[1 /* INFO */]: "INFO",
|
|
@@ -81,9 +93,38 @@ const RESET_COLOR = "\x1B[0m";
|
|
|
81
93
|
function getColoredPrefix(level) {
|
|
82
94
|
return `${CONSOLE_COLOR_MAP[level]}[ADK ${LOG_LEVEL_STR[level]}]:${RESET_COLOR}`;
|
|
83
95
|
}
|
|
84
|
-
|
|
96
|
+
let currentLogger = new SimpleLogger();
|
|
97
|
+
function setLogger(customLogger) {
|
|
98
|
+
currentLogger = customLogger != null ? customLogger : new NoOpLogger();
|
|
99
|
+
}
|
|
100
|
+
function getLogger() {
|
|
101
|
+
return currentLogger;
|
|
102
|
+
}
|
|
103
|
+
function resetLogger() {
|
|
104
|
+
currentLogger = new SimpleLogger();
|
|
105
|
+
}
|
|
106
|
+
const logger = {
|
|
107
|
+
log(level, ...args) {
|
|
108
|
+
currentLogger.log(level, ...args);
|
|
109
|
+
},
|
|
110
|
+
debug(...args) {
|
|
111
|
+
currentLogger.debug(...args);
|
|
112
|
+
},
|
|
113
|
+
info(...args) {
|
|
114
|
+
currentLogger.info(...args);
|
|
115
|
+
},
|
|
116
|
+
warn(...args) {
|
|
117
|
+
currentLogger.warn(...args);
|
|
118
|
+
},
|
|
119
|
+
error(...args) {
|
|
120
|
+
currentLogger.error(...args);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
85
123
|
export {
|
|
86
124
|
LogLevel,
|
|
125
|
+
getLogger,
|
|
87
126
|
logger,
|
|
88
|
-
|
|
127
|
+
resetLogger,
|
|
128
|
+
setLogLevel,
|
|
129
|
+
setLogger
|
|
89
130
|
};
|
|
@@ -4,155 +4,116 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Type } from "@google/genai";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
import {
|
|
8
|
+
zodToJsonSchema as toJSONSchemaV3
|
|
9
|
+
} from "zod-to-json-schema";
|
|
10
|
+
import { toJSONSchema as toJSONSchemaV4 } from "zod/v4";
|
|
11
|
+
function isZodSchema(obj) {
|
|
12
|
+
return obj !== null && typeof obj === "object" && "parse" in obj && typeof obj.parse === "function" && "safeParse" in obj && typeof obj.safeParse === "function";
|
|
13
|
+
}
|
|
14
|
+
function isZodV3Schema(obj) {
|
|
15
|
+
return isZodSchema(obj) && !("_zod" in obj);
|
|
16
|
+
}
|
|
17
|
+
function isZodV4Schema(obj) {
|
|
18
|
+
return isZodSchema(obj) && "_zod" in obj;
|
|
11
19
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
function getZodTypeName(schema) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const schemaAny = schema;
|
|
23
|
+
if ((_a = schemaAny._def) == null ? void 0 : _a.typeName) {
|
|
24
|
+
return schemaAny._def.typeName;
|
|
16
25
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const returnResult = (result2) => {
|
|
21
|
-
if (result2.description === void 0) {
|
|
22
|
-
delete result2.description;
|
|
23
|
-
}
|
|
24
|
-
return result2;
|
|
25
|
-
};
|
|
26
|
-
switch (def.typeName) {
|
|
27
|
-
case z.ZodFirstPartyTypeKind.ZodString:
|
|
28
|
-
result.type = Type.STRING;
|
|
29
|
-
for (const check of def.checks || []) {
|
|
30
|
-
if (check.kind === "min")
|
|
31
|
-
result.minLength = check.value.toString();
|
|
32
|
-
else if (check.kind === "max")
|
|
33
|
-
result.maxLength = check.value.toString();
|
|
34
|
-
else if (check.kind === "email")
|
|
35
|
-
result.format = "email";
|
|
36
|
-
else if (check.kind === "uuid")
|
|
37
|
-
result.format = "uuid";
|
|
38
|
-
else if (check.kind === "url")
|
|
39
|
-
result.format = "uri";
|
|
40
|
-
else if (check.kind === "regex")
|
|
41
|
-
result.pattern = check.regex.source;
|
|
42
|
-
}
|
|
43
|
-
return returnResult(result);
|
|
44
|
-
case z.ZodFirstPartyTypeKind.ZodNumber:
|
|
45
|
-
result.type = Type.NUMBER;
|
|
46
|
-
for (const check of def.checks || []) {
|
|
47
|
-
if (check.kind === "min")
|
|
48
|
-
result.minimum = check.value;
|
|
49
|
-
else if (check.kind === "max")
|
|
50
|
-
result.maximum = check.value;
|
|
51
|
-
else if (check.kind === "int")
|
|
52
|
-
result.type = Type.INTEGER;
|
|
53
|
-
}
|
|
54
|
-
return returnResult(result);
|
|
55
|
-
case z.ZodFirstPartyTypeKind.ZodBoolean:
|
|
56
|
-
result.type = Type.BOOLEAN;
|
|
57
|
-
return returnResult(result);
|
|
58
|
-
case z.ZodFirstPartyTypeKind.ZodArray:
|
|
59
|
-
result.type = Type.ARRAY;
|
|
60
|
-
result.items = parseZodType(def.type);
|
|
61
|
-
if (def.minLength) result.minItems = def.minLength.value.toString();
|
|
62
|
-
if (def.maxLength) result.maxItems = def.maxLength.value.toString();
|
|
63
|
-
return returnResult(result);
|
|
64
|
-
case z.ZodFirstPartyTypeKind.ZodObject: {
|
|
65
|
-
const nestedSchema = zodObjectToSchema(zodType);
|
|
66
|
-
return nestedSchema;
|
|
67
|
-
}
|
|
68
|
-
case z.ZodFirstPartyTypeKind.ZodLiteral:
|
|
69
|
-
const literalType = typeof def.value;
|
|
70
|
-
result.enum = [def.value.toString()];
|
|
71
|
-
if (literalType === "string") {
|
|
72
|
-
result.type = Type.STRING;
|
|
73
|
-
} else if (literalType === "number") {
|
|
74
|
-
result.type = Type.NUMBER;
|
|
75
|
-
} else if (literalType === "boolean") {
|
|
76
|
-
result.type = Type.BOOLEAN;
|
|
77
|
-
} else if (def.value === null) {
|
|
78
|
-
result.type = Type.NULL;
|
|
79
|
-
} else {
|
|
80
|
-
throw new Error(`Unsupported ZodLiteral value type: ${literalType}`);
|
|
81
|
-
}
|
|
82
|
-
return returnResult(result);
|
|
83
|
-
case z.ZodFirstPartyTypeKind.ZodEnum:
|
|
84
|
-
result.type = Type.STRING;
|
|
85
|
-
result.enum = def.values;
|
|
86
|
-
return returnResult(result);
|
|
87
|
-
case z.ZodFirstPartyTypeKind.ZodNativeEnum:
|
|
88
|
-
result.type = Type.STRING;
|
|
89
|
-
result.enum = Object.values(def.values);
|
|
90
|
-
return returnResult(result);
|
|
91
|
-
case z.ZodFirstPartyTypeKind.ZodUnion:
|
|
92
|
-
result.anyOf = def.options.map(parseZodType);
|
|
93
|
-
return returnResult(result);
|
|
94
|
-
case z.ZodFirstPartyTypeKind.ZodOptional:
|
|
95
|
-
return parseZodType(def.innerType);
|
|
96
|
-
case z.ZodFirstPartyTypeKind.ZodNullable:
|
|
97
|
-
const nullableInner = parseZodType(def.innerType);
|
|
98
|
-
return nullableInner ? returnResult({
|
|
99
|
-
anyOf: [nullableInner, { type: Type.NULL }],
|
|
100
|
-
...description && { description }
|
|
101
|
-
}) : returnResult({ type: Type.NULL, ...description && { description } });
|
|
102
|
-
case z.ZodFirstPartyTypeKind.ZodDefault:
|
|
103
|
-
const defaultInner = parseZodType(def.innerType);
|
|
104
|
-
if (defaultInner) defaultInner.default = def.defaultValue();
|
|
105
|
-
return defaultInner;
|
|
106
|
-
case z.ZodFirstPartyTypeKind.ZodBranded:
|
|
107
|
-
return parseZodType(def.type);
|
|
108
|
-
case z.ZodFirstPartyTypeKind.ZodReadonly:
|
|
109
|
-
return parseZodType(def.innerType);
|
|
110
|
-
case z.ZodFirstPartyTypeKind.ZodNull:
|
|
111
|
-
result.type = Type.NULL;
|
|
112
|
-
return returnResult(result);
|
|
113
|
-
case z.ZodFirstPartyTypeKind.ZodAny:
|
|
114
|
-
case z.ZodFirstPartyTypeKind.ZodUnknown:
|
|
115
|
-
return returnResult({ ...description && { description } });
|
|
116
|
-
default:
|
|
117
|
-
throw new Error(`Unsupported Zod type: ${def.typeName}`);
|
|
26
|
+
const zod4Type = (_b = schemaAny._def) == null ? void 0 : _b.type;
|
|
27
|
+
if (typeof zod4Type === "string" && zod4Type) {
|
|
28
|
+
return "Zod" + zod4Type.charAt(0).toUpperCase() + zod4Type.slice(1);
|
|
118
29
|
}
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
function isZodObject(obj) {
|
|
33
|
+
return isZodSchema(obj) && getZodTypeName(obj) === "ZodObject";
|
|
119
34
|
}
|
|
120
35
|
function zodObjectToSchema(schema) {
|
|
121
|
-
if (schema
|
|
122
|
-
throw new Error("Expected a
|
|
36
|
+
if (!isZodObject(schema)) {
|
|
37
|
+
throw new Error("Expected a Zod Object");
|
|
123
38
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
39
|
+
if (isZodV4Schema(schema)) {
|
|
40
|
+
return toJSONSchemaV4(schema, {
|
|
41
|
+
target: "openapi-3.0",
|
|
42
|
+
io: "input",
|
|
43
|
+
override: (ctx) => {
|
|
44
|
+
var _a;
|
|
45
|
+
const { jsonSchema } = ctx;
|
|
46
|
+
if (jsonSchema.additionalProperties !== void 0) {
|
|
47
|
+
delete jsonSchema.additionalProperties;
|
|
48
|
+
}
|
|
49
|
+
if (jsonSchema.readOnly !== void 0) {
|
|
50
|
+
delete jsonSchema.readOnly;
|
|
51
|
+
}
|
|
52
|
+
if (jsonSchema.maxItems !== void 0) {
|
|
53
|
+
jsonSchema.maxItems = jsonSchema.maxItems.toString();
|
|
54
|
+
}
|
|
55
|
+
if (jsonSchema.format === "email" || jsonSchema.format === "uuid") {
|
|
56
|
+
delete jsonSchema.pattern;
|
|
57
|
+
}
|
|
58
|
+
if (jsonSchema.minItems !== void 0) {
|
|
59
|
+
jsonSchema.minItems = jsonSchema.minItems.toString();
|
|
60
|
+
}
|
|
61
|
+
if (jsonSchema.minLength !== void 0) {
|
|
62
|
+
jsonSchema.minLength = jsonSchema.minLength.toString();
|
|
63
|
+
}
|
|
64
|
+
if (jsonSchema.maxLength !== void 0) {
|
|
65
|
+
jsonSchema.maxLength = jsonSchema.maxLength.toString();
|
|
66
|
+
}
|
|
67
|
+
if (((_a = jsonSchema.enum) == null ? void 0 : _a.length) === 1 && jsonSchema.enum[0] === null) {
|
|
68
|
+
jsonSchema.type = Type.NULL;
|
|
69
|
+
delete jsonSchema.enum;
|
|
70
|
+
}
|
|
71
|
+
if (jsonSchema.type !== void 0) {
|
|
72
|
+
jsonSchema.type = jsonSchema.type.toUpperCase();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
142
76
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
77
|
+
if (isZodV3Schema(schema)) {
|
|
78
|
+
return toJSONSchemaV3(schema, {
|
|
79
|
+
target: "openApi3",
|
|
80
|
+
emailStrategy: "format:email",
|
|
81
|
+
postProcess: (jsonSchema) => {
|
|
82
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
83
|
+
if (!jsonSchema) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (jsonSchema.additionalProperties !== void 0) {
|
|
87
|
+
delete jsonSchema.additionalProperties;
|
|
88
|
+
}
|
|
89
|
+
if (jsonSchema.maxItems !== void 0) {
|
|
90
|
+
jsonSchema.maxItems = (_a = jsonSchema.maxItems) == null ? void 0 : _a.toString();
|
|
91
|
+
}
|
|
92
|
+
if (jsonSchema.minItems !== void 0) {
|
|
93
|
+
jsonSchema.minItems = (_b = jsonSchema.minItems) == null ? void 0 : _b.toString();
|
|
94
|
+
}
|
|
95
|
+
if (jsonSchema.minLength !== void 0) {
|
|
96
|
+
jsonSchema.minLength = (_c = jsonSchema.minLength) == null ? void 0 : _c.toString();
|
|
97
|
+
}
|
|
98
|
+
if (jsonSchema.maxLength !== void 0) {
|
|
99
|
+
jsonSchema.maxLength = (_d = jsonSchema.maxLength) == null ? void 0 : _d.toString();
|
|
100
|
+
}
|
|
101
|
+
if (((_e = jsonSchema.enum) == null ? void 0 : _e.length) === 1 && jsonSchema.enum[0] === "null") {
|
|
102
|
+
jsonSchema.type = Type.NULL;
|
|
103
|
+
delete jsonSchema.enum;
|
|
104
|
+
}
|
|
105
|
+
if (jsonSchema.type === "integer" && jsonSchema.format !== "int64") {
|
|
106
|
+
(_f = jsonSchema.minimum) != null ? _f : jsonSchema.minimum = Number.MIN_SAFE_INTEGER;
|
|
107
|
+
(_g = jsonSchema.maximum) != null ? _g : jsonSchema.maximum = Number.MAX_SAFE_INTEGER;
|
|
108
|
+
}
|
|
109
|
+
if (jsonSchema.type !== void 0) {
|
|
110
|
+
jsonSchema.type = jsonSchema.type.toUpperCase();
|
|
111
|
+
}
|
|
112
|
+
return jsonSchema;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
149
115
|
}
|
|
150
|
-
|
|
151
|
-
type: Type.OBJECT,
|
|
152
|
-
properties,
|
|
153
|
-
required: required.length > 0 ? required : [],
|
|
154
|
-
...schema._def.description ? { description: schema._def.description } : {}
|
|
155
|
-
};
|
|
116
|
+
throw new Error("Unsupported Zod schema version.");
|
|
156
117
|
}
|
|
157
118
|
export {
|
|
158
119
|
isZodObject,
|
|
@@ -16,7 +16,7 @@ function getBooleanEnvVar(envVar) {
|
|
|
16
16
|
return false;
|
|
17
17
|
}
|
|
18
18
|
const envVarValue = (process.env[envVar] || "").toLowerCase();
|
|
19
|
-
return ["true", "1"].includes(
|
|
19
|
+
return ["true", "1"].includes(envVarValue);
|
|
20
20
|
}
|
|
21
21
|
export {
|
|
22
22
|
GoogleLLMVariant,
|
package/dist/esm/version.js
CHANGED
|
@@ -66,8 +66,9 @@ export declare abstract class BaseAgent {
|
|
|
66
66
|
readonly description?: string;
|
|
67
67
|
/**
|
|
68
68
|
* Root agent of this agent.
|
|
69
|
+
* Computed dynamically by traversing up the parent chain.
|
|
69
70
|
*/
|
|
70
|
-
|
|
71
|
+
get rootAgent(): BaseAgent;
|
|
71
72
|
/**
|
|
72
73
|
* The parent agent of this agent.
|
|
73
74
|
*
|
|
@@ -14,7 +14,7 @@ import { ReadonlyContext } from './readonly_context.js';
|
|
|
14
14
|
export declare class CallbackContext extends ReadonlyContext {
|
|
15
15
|
private readonly _state;
|
|
16
16
|
readonly eventActions: EventActions;
|
|
17
|
-
constructor({ invocationContext, eventActions }: {
|
|
17
|
+
constructor({ invocationContext, eventActions, }: {
|
|
18
18
|
invocationContext: InvocationContext;
|
|
19
19
|
eventActions?: EventActions;
|
|
20
20
|
});
|
|
@@ -207,7 +207,7 @@ export interface LlmAgentConfig extends BaseAgentConfig {
|
|
|
207
207
|
}
|
|
208
208
|
declare class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
209
209
|
/** Handles tool confirmation information to build the LLM request. */
|
|
210
|
-
runAsync(invocationContext: InvocationContext
|
|
210
|
+
runAsync(invocationContext: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
211
211
|
}
|
|
212
212
|
export declare const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: RequestConfirmationLlmRequestProcessor;
|
|
213
213
|
/**
|
|
@@ -42,6 +42,6 @@ export declare class LoopAgent extends BaseAgent {
|
|
|
42
42
|
private readonly maxIterations;
|
|
43
43
|
constructor(config: LoopAgentConfig);
|
|
44
44
|
protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
45
|
-
protected runLiveImpl(
|
|
45
|
+
protected runLiveImpl(_context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
46
46
|
}
|
|
47
47
|
export {};
|
|
@@ -32,6 +32,6 @@ export declare class ParallelAgent extends BaseAgent {
|
|
|
32
32
|
*/
|
|
33
33
|
readonly [PARALLEL_AGENT_SIGNATURE_SYMBOL] = true;
|
|
34
34
|
protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
35
|
-
protected runLiveImpl(
|
|
35
|
+
protected runLiveImpl(_context: InvocationContext): AsyncGenerator<Event, void, void>;
|
|
36
36
|
}
|
|
37
37
|
export {};
|
|
@@ -12,7 +12,7 @@ export declare class InMemoryArtifactService implements BaseArtifactService {
|
|
|
12
12
|
private readonly artifacts;
|
|
13
13
|
saveArtifact({ appName, userId, sessionId, filename, artifact, }: SaveArtifactRequest): Promise<number>;
|
|
14
14
|
loadArtifact({ appName, userId, sessionId, filename, version, }: LoadArtifactRequest): Promise<Part | undefined>;
|
|
15
|
-
listArtifactKeys({ appName, userId, sessionId }: ListArtifactKeysRequest): Promise<string[]>;
|
|
16
|
-
deleteArtifact({ appName, userId, sessionId, filename }: DeleteArtifactRequest): Promise<void>;
|
|
17
|
-
listVersions({ appName, userId, sessionId, filename }: ListVersionsRequest): Promise<number[]>;
|
|
15
|
+
listArtifactKeys({ appName, userId, sessionId, }: ListArtifactKeysRequest): Promise<string[]>;
|
|
16
|
+
deleteArtifact({ appName, userId, sessionId, filename, }: DeleteArtifactRequest): Promise<void>;
|
|
17
|
+
listVersions({ appName, userId, sessionId, filename, }: ListVersionsRequest): Promise<number[]>;
|
|
18
18
|
}
|
|
@@ -26,7 +26,7 @@ export declare function isBuiltInCodeExecutor(obj: unknown): obj is BuiltInCodeE
|
|
|
26
26
|
export declare class BuiltInCodeExecutor extends BaseCodeExecutor {
|
|
27
27
|
/** A unique symbol to identify BuiltInCodeExecutor class. */
|
|
28
28
|
readonly [BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL] = true;
|
|
29
|
-
executeCode(
|
|
29
|
+
executeCode(_params: ExecuteCodeParams): Promise<CodeExecutionResult>;
|
|
30
30
|
processLlmRequest(llmRequest: LlmRequest): void;
|
|
31
31
|
}
|
|
32
32
|
export {};
|
|
@@ -78,10 +78,8 @@ export declare class CodeExecutorContext {
|
|
|
78
78
|
*/
|
|
79
79
|
updateCodeExecutionResult({ invocationId, code, resultStdout, resultStderr, }: UpdateCodeExecutionResultParams): void;
|
|
80
80
|
/**
|
|
81
|
-
* Gets the code
|
|
82
|
-
* @param invocationId The session state to get the code executor context
|
|
83
|
-
* from.
|
|
81
|
+
* Gets the code execution context from the session state.
|
|
84
82
|
* @return The code execution context for the given invocation ID.
|
|
85
83
|
*/
|
|
86
|
-
getCodeExecutionContext(
|
|
84
|
+
getCodeExecutionContext(): Record<string, unknown>;
|
|
87
85
|
}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -73,7 +73,8 @@ export { GOOGLE_SEARCH, GoogleSearchTool } from './tools/google_search_tool.js';
|
|
|
73
73
|
export { LongRunningFunctionTool } from './tools/long_running_tool.js';
|
|
74
74
|
export { ToolConfirmation } from './tools/tool_confirmation.js';
|
|
75
75
|
export { ToolContext } from './tools/tool_context.js';
|
|
76
|
-
export { LogLevel, setLogLevel } from './utils/logger.js';
|
|
76
|
+
export { LogLevel, getLogger, setLogLevel, setLogger } from './utils/logger.js';
|
|
77
|
+
export type { Logger } from './utils/logger.js';
|
|
77
78
|
export { isGemini2OrAbove } from './utils/model_name.js';
|
|
78
79
|
export { zodObjectToSchema } from './utils/simple_zod_to_json.js';
|
|
79
80
|
export { GoogleLLMVariant } from './utils/variant_utils.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
export * from './artifacts/gcs_artifact_service.js';
|
|
6
7
|
export * from './common.js';
|
|
8
|
+
export * from './telemetry/google_cloud.js';
|
|
9
|
+
export * from './telemetry/setup.js';
|
|
7
10
|
export * from './tools/mcp/mcp_session_manager.js';
|
|
8
11
|
export * from './tools/mcp/mcp_tool.js';
|
|
9
12
|
export * from './tools/mcp/mcp_toolset.js';
|
|
10
|
-
export * from './artifacts/gcs_artifact_service.js';
|
|
11
|
-
export * from './telemetry/setup.js';
|
|
12
|
-
export * from './telemetry/google_cloud.js';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { Blob, Content } from '@google/genai';
|
|
7
7
|
import { LlmResponse } from './llm_response.js';
|
|
8
8
|
/**
|
|
9
9
|
* The base class for a live model connection.
|