@google/adk 0.2.5 → 0.4.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/part_converter_utils.js +210 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +46 -24
- package/dist/cjs/agents/base_llm_processor.js +1 -1
- package/dist/cjs/agents/callback_context.js +5 -2
- package/dist/cjs/agents/content_processor_utils.js +16 -8
- package/dist/cjs/agents/functions.js +81 -30
- package/dist/cjs/agents/instructions.js +1 -1
- package/dist/cjs/agents/invocation_context.js +1 -1
- package/dist/cjs/agents/live_request_queue.js +1 -1
- package/dist/cjs/agents/llm_agent.js +106 -62
- package/dist/cjs/agents/loop_agent.js +3 -2
- package/dist/cjs/agents/parallel_agent.js +4 -5
- package/dist/cjs/agents/readonly_context.js +13 -1
- package/dist/cjs/agents/run_config.js +2 -1
- package/dist/cjs/agents/sequential_agent.js +1 -1
- package/dist/cjs/agents/transcription_entry.js +1 -1
- package/dist/cjs/artifacts/base_artifact_service.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +491 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +145 -58
- package/dist/cjs/artifacts/in_memory_artifact_service.js +72 -10
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +4 -2
- package/dist/cjs/auth/auth_schemes.js +1 -1
- package/dist/cjs/auth/auth_tool.js +1 -1
- package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
- package/dist/cjs/code_executors/base_code_executor.js +4 -2
- package/dist/cjs/code_executors/built_in_code_executor.js +8 -4
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +6 -6
- package/dist/cjs/common.js +18 -1
- package/dist/cjs/events/event.js +34 -7
- package/dist/cjs/events/event_actions.js +2 -2
- package/dist/cjs/events/structured_events.js +105 -0
- package/dist/cjs/examples/base_example_provider.js +1 -1
- package/dist/cjs/examples/example.js +1 -1
- package/dist/cjs/examples/example_util.js +1 -1
- package/dist/cjs/index.js +54 -83
- package/dist/cjs/index_web.js +1 -1
- package/dist/cjs/memory/base_memory_service.js +1 -1
- package/dist/cjs/memory/in_memory_memory_service.js +4 -2
- package/dist/cjs/memory/memory_entry.js +1 -1
- package/dist/cjs/models/apigee_llm.js +182 -0
- package/dist/cjs/models/base_llm.js +9 -5
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +2 -1
- package/dist/cjs/models/google_llm.js +73 -54
- package/dist/cjs/models/llm_request.js +1 -1
- package/dist/cjs/models/llm_response.js +1 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +13 -1
- package/dist/cjs/plugins/logging_plugin.js +51 -14
- package/dist/cjs/plugins/plugin_manager.js +57 -25
- package/dist/cjs/plugins/security_plugin.js +2 -2
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +142 -96
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +364 -0
- package/dist/cjs/sessions/db/operations.js +114 -0
- package/dist/cjs/sessions/db/schema.js +204 -0
- package/dist/cjs/sessions/in_memory_session_service.js +60 -34
- package/dist/cjs/sessions/registry.js +49 -0
- package/dist/cjs/sessions/session.js +1 -1
- package/dist/cjs/sessions/state.js +1 -1
- package/dist/cjs/telemetry/google_cloud.js +8 -10
- package/dist/cjs/telemetry/setup.js +16 -8
- package/dist/cjs/telemetry/tracing.js +38 -16
- package/dist/cjs/tools/agent_tool.js +9 -5
- package/dist/cjs/tools/base_tool.js +5 -3
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/forwarding_artifact_service.js +18 -2
- package/dist/cjs/tools/function_tool.js +2 -3
- package/dist/cjs/tools/google_search_tool.js +2 -3
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +17 -11
- package/dist/cjs/tools/mcp/mcp_tool.js +2 -4
- package/dist/cjs/tools/mcp/mcp_toolset.js +2 -2
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/tools/tool_context.js +1 -1
- package/dist/cjs/utils/client_labels.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +11 -2
- package/dist/cjs/utils/gemini_schema_util.js +10 -5
- package/dist/cjs/utils/logger.js +48 -4
- package/dist/cjs/utils/model_name.js +1 -1
- package/dist/cjs/utils/object_notation_utils.js +78 -0
- package/dist/cjs/utils/simple_zod_to_json.js +101 -142
- package/dist/cjs/utils/variant_utils.js +3 -9
- package/dist/cjs/version.js +2 -2
- package/dist/esm/a2a/part_converter_utils.js +171 -0
- package/dist/esm/agents/base_agent.js +50 -24
- 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 +84 -29
- package/dist/esm/agents/llm_agent.js +110 -62
- package/dist/esm/agents/loop_agent.js +2 -1
- package/dist/esm/agents/parallel_agent.js +3 -4
- package/dist/esm/agents/readonly_context.js +12 -0
- package/dist/esm/agents/run_config.js +1 -0
- package/dist/esm/artifacts/file_artifact_service.js +451 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +144 -57
- package/dist/esm/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/esm/artifacts/registry.js +28 -0
- 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 +12 -2
- package/dist/esm/events/event.js +30 -5
- package/dist/esm/events/event_actions.js +1 -1
- package/dist/esm/events/structured_events.js +74 -0
- package/dist/esm/index.js +18 -88
- package/dist/esm/memory/in_memory_memory_service.js +3 -1
- package/dist/esm/models/apigee_llm.js +152 -0
- 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 +75 -53
- package/dist/esm/models/registry.js +2 -0
- 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 +145 -96
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +350 -0
- package/dist/esm/sessions/db/operations.js +87 -0
- package/dist/esm/sessions/db/schema.js +172 -0
- package/dist/esm/sessions/in_memory_session_service.js +61 -33
- package/dist/esm/sessions/registry.js +25 -0
- 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 +17 -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 +9 -1
- package/dist/esm/utils/gemini_schema_util.js +9 -4
- package/dist/esm/utils/logger.js +43 -2
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/simple_zod_to_json.js +102 -141
- package/dist/esm/utils/variant_utils.js +1 -7
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/part_converter_utils.d.ts +47 -0
- 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 +12 -12
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/parallel_agent.d.ts +1 -1
- package/dist/types/agents/readonly_context.d.ts +8 -0
- package/dist/types/agents/run_config.d.ts +6 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
- package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +8 -5
- package/dist/types/artifacts/registry.d.ts +7 -0
- 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 +13 -3
- package/dist/types/events/event.d.ts +15 -1
- package/dist/types/events/event_actions.d.ts +1 -1
- package/dist/types/events/structured_events.d.ts +106 -0
- package/dist/types/index.d.ts +7 -3
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/base_llm_connection.d.ts +1 -1
- package/dist/types/models/google_llm.d.ts +5 -2
- 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 +16 -1
- package/dist/types/sessions/base_session_service.d.ts +20 -0
- package/dist/types/sessions/database_session_service.d.ts +31 -0
- package/dist/types/sessions/db/operations.d.ts +29 -0
- package/dist/types/sessions/db/schema.d.ts +45 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +9 -6
- package/dist/types/sessions/registry.d.ts +7 -0
- 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 +4 -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/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/gemini_schema_util.d.ts +4 -12
- package/dist/types/utils/logger.d.ts +11 -10
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/part_converter_utils.js +171 -0
- package/dist/web/agents/base_agent.js +96 -35
- 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 +84 -29
- package/dist/web/agents/llm_agent.js +166 -83
- package/dist/web/agents/loop_agent.js +2 -1
- package/dist/web/agents/parallel_agent.js +3 -4
- package/dist/web/agents/readonly_context.js +12 -0
- package/dist/web/agents/run_config.js +2 -1
- package/dist/web/artifacts/file_artifact_service.js +506 -0
- package/dist/web/artifacts/gcs_artifact_service.js +139 -54
- package/dist/web/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/web/artifacts/registry.js +28 -0
- 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 +12 -2
- package/dist/web/events/event.js +30 -5
- package/dist/web/events/event_actions.js +1 -1
- package/dist/web/events/structured_events.js +74 -0
- package/dist/web/index.js +18 -8
- package/dist/web/memory/in_memory_memory_service.js +3 -1
- package/dist/web/models/apigee_llm.js +219 -0
- 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 +75 -50
- package/dist/web/models/registry.js +2 -0
- 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 +192 -108
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +368 -0
- package/dist/web/sessions/db/operations.js +87 -0
- package/dist/web/sessions/db/schema.js +172 -0
- package/dist/web/sessions/in_memory_session_service.js +61 -33
- package/dist/web/sessions/registry.js +25 -0
- 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 +17 -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 +9 -1
- package/dist/web/utils/gemini_schema_util.js +9 -4
- package/dist/web/utils/logger.js +43 -2
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/simple_zod_to_json.js +102 -155
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +16 -5
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/web/index.js.map +0 -7
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
import { cloneDeep } from "lodash-es";
|
|
7
7
|
import { randomUUID } from "../utils/env_aware_utils.js";
|
|
8
8
|
import { logger } from "../utils/logger.js";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
BaseSessionService,
|
|
11
|
+
mergeStates
|
|
12
|
+
} from "./base_session_service.js";
|
|
10
13
|
import { createSession } from "./session.js";
|
|
11
14
|
import { State } from "./state.js";
|
|
15
|
+
function isInMemoryConnectionString(uri) {
|
|
16
|
+
return uri === "memory://";
|
|
17
|
+
}
|
|
12
18
|
class InMemorySessionService extends BaseSessionService {
|
|
13
19
|
constructor() {
|
|
14
20
|
super(...arguments);
|
|
@@ -26,7 +32,13 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
26
32
|
*/
|
|
27
33
|
this.appState = {};
|
|
28
34
|
}
|
|
29
|
-
createSession({
|
|
35
|
+
async createSession({
|
|
36
|
+
appName,
|
|
37
|
+
userId,
|
|
38
|
+
state,
|
|
39
|
+
sessionId
|
|
40
|
+
}) {
|
|
41
|
+
var _a;
|
|
30
42
|
const session = createSession({
|
|
31
43
|
id: sessionId || randomUUID(),
|
|
32
44
|
appName,
|
|
@@ -42,11 +54,21 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
42
54
|
this.sessions[appName][userId] = {};
|
|
43
55
|
}
|
|
44
56
|
this.sessions[appName][userId][session.id] = session;
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
const copiedSession = cloneDeep(session);
|
|
58
|
+
copiedSession.state = mergeStates(
|
|
59
|
+
this.appState[appName],
|
|
60
|
+
(_a = this.userState[appName]) == null ? void 0 : _a[userId],
|
|
61
|
+
copiedSession.state
|
|
47
62
|
);
|
|
63
|
+
return copiedSession;
|
|
48
64
|
}
|
|
49
|
-
getSession({
|
|
65
|
+
async getSession({
|
|
66
|
+
appName,
|
|
67
|
+
userId,
|
|
68
|
+
sessionId,
|
|
69
|
+
config
|
|
70
|
+
}) {
|
|
71
|
+
var _a;
|
|
50
72
|
if (!this.sessions[appName] || !this.sessions[appName][userId] || !this.sessions[appName][userId][sessionId]) {
|
|
51
73
|
return Promise.resolve(void 0);
|
|
52
74
|
}
|
|
@@ -54,7 +76,9 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
54
76
|
const copiedSession = cloneDeep(session);
|
|
55
77
|
if (config) {
|
|
56
78
|
if (config.numRecentEvents) {
|
|
57
|
-
copiedSession.events = copiedSession.events.slice(
|
|
79
|
+
copiedSession.events = copiedSession.events.slice(
|
|
80
|
+
-config.numRecentEvents
|
|
81
|
+
);
|
|
58
82
|
}
|
|
59
83
|
if (config.afterTimestamp) {
|
|
60
84
|
let i = copiedSession.events.length - 1;
|
|
@@ -69,33 +93,50 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
69
93
|
}
|
|
70
94
|
}
|
|
71
95
|
}
|
|
72
|
-
|
|
96
|
+
copiedSession.state = mergeStates(
|
|
97
|
+
this.appState[appName],
|
|
98
|
+
(_a = this.userState[appName]) == null ? void 0 : _a[userId],
|
|
99
|
+
copiedSession.state
|
|
100
|
+
);
|
|
101
|
+
return copiedSession;
|
|
73
102
|
}
|
|
74
|
-
listSessions({
|
|
103
|
+
listSessions({
|
|
104
|
+
appName,
|
|
105
|
+
userId
|
|
106
|
+
}) {
|
|
75
107
|
if (!this.sessions[appName] || !this.sessions[appName][userId]) {
|
|
76
108
|
return Promise.resolve({ sessions: [] });
|
|
77
109
|
}
|
|
78
110
|
const sessionsWithoutEvents = [];
|
|
79
111
|
for (const session of Object.values(this.sessions[appName][userId])) {
|
|
80
|
-
sessionsWithoutEvents.push(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
112
|
+
sessionsWithoutEvents.push(
|
|
113
|
+
createSession({
|
|
114
|
+
id: session.id,
|
|
115
|
+
appName: session.appName,
|
|
116
|
+
userId: session.userId,
|
|
117
|
+
state: {},
|
|
118
|
+
events: [],
|
|
119
|
+
lastUpdateTime: session.lastUpdateTime
|
|
120
|
+
})
|
|
121
|
+
);
|
|
88
122
|
}
|
|
89
123
|
return Promise.resolve({ sessions: sessionsWithoutEvents });
|
|
90
124
|
}
|
|
91
|
-
async deleteSession({
|
|
125
|
+
async deleteSession({
|
|
126
|
+
appName,
|
|
127
|
+
userId,
|
|
128
|
+
sessionId
|
|
129
|
+
}) {
|
|
92
130
|
const session = await this.getSession({ appName, userId, sessionId });
|
|
93
131
|
if (!session) {
|
|
94
132
|
return;
|
|
95
133
|
}
|
|
96
134
|
delete this.sessions[appName][userId][sessionId];
|
|
97
135
|
}
|
|
98
|
-
async appendEvent({
|
|
136
|
+
async appendEvent({
|
|
137
|
+
session,
|
|
138
|
+
event
|
|
139
|
+
}) {
|
|
99
140
|
await super.appendEvent({ session, event });
|
|
100
141
|
session.lastUpdateTime = event.timestamp;
|
|
101
142
|
const appName = session.appName;
|
|
@@ -134,21 +175,8 @@ class InMemorySessionService extends BaseSessionService {
|
|
|
134
175
|
storageSession.lastUpdateTime = event.timestamp;
|
|
135
176
|
return event;
|
|
136
177
|
}
|
|
137
|
-
mergeState(appName, userId, copiedSession) {
|
|
138
|
-
if (this.appState[appName]) {
|
|
139
|
-
for (const key of Object.keys(this.appState[appName])) {
|
|
140
|
-
copiedSession.state[State.APP_PREFIX + key] = this.appState[appName][key];
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (!this.userState[appName] || !this.userState[appName][userId]) {
|
|
144
|
-
return copiedSession;
|
|
145
|
-
}
|
|
146
|
-
for (const key of Object.keys(this.userState[appName][userId])) {
|
|
147
|
-
copiedSession.state[State.USER_PREFIX + key] = this.userState[appName][userId][key];
|
|
148
|
-
}
|
|
149
|
-
return copiedSession;
|
|
150
|
-
}
|
|
151
178
|
}
|
|
152
179
|
export {
|
|
153
|
-
InMemorySessionService
|
|
180
|
+
InMemorySessionService,
|
|
181
|
+
isInMemoryConnectionString
|
|
154
182
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import {
|
|
7
|
+
DatabaseSessionService,
|
|
8
|
+
isDatabaseConnectionString
|
|
9
|
+
} from "./database_session_service.js";
|
|
10
|
+
import {
|
|
11
|
+
InMemorySessionService,
|
|
12
|
+
isInMemoryConnectionString
|
|
13
|
+
} from "./in_memory_session_service.js";
|
|
14
|
+
function getSessionServiceFromUri(uri) {
|
|
15
|
+
if (isInMemoryConnectionString(uri)) {
|
|
16
|
+
return new InMemorySessionService();
|
|
17
|
+
}
|
|
18
|
+
if (isDatabaseConnectionString(uri)) {
|
|
19
|
+
return new DatabaseSessionService(uri);
|
|
20
|
+
}
|
|
21
|
+
throw new Error("Unsupported session service URI: ".concat(uri));
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
getSessionServiceFromUri
|
|
25
|
+
};
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
|
|
8
|
-
import { detectResources } from "@opentelemetry/resources";
|
|
9
|
-
import { gcpDetector } from "@opentelemetry/resource-detector-gcp";
|
|
6
|
+
import { MetricExporter } from "@google-cloud/opentelemetry-cloud-monitoring-exporter";
|
|
10
7
|
import { TraceExporter } from "@google-cloud/opentelemetry-cloud-trace-exporter";
|
|
8
|
+
import { gcpDetector } from "@opentelemetry/resource-detector-gcp";
|
|
9
|
+
import { detectResources } from "@opentelemetry/resources";
|
|
10
|
+
import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
|
|
11
11
|
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
12
|
-
import {
|
|
12
|
+
import { GoogleAuth } from "google-auth-library";
|
|
13
13
|
import { logger } from "../utils/logger.js";
|
|
14
14
|
const GCP_PROJECT_ERROR_MESSAGE = "Cannot determine GCP Project. OTel GCP Exporters cannot be set up. Please make sure to log into correct GCP Project.";
|
|
15
15
|
async function getGcpProjectId() {
|
|
@@ -17,7 +17,7 @@ async function getGcpProjectId() {
|
|
|
17
17
|
const auth = new GoogleAuth();
|
|
18
18
|
const projectId = await auth.getProjectId();
|
|
19
19
|
return projectId || void 0;
|
|
20
|
-
} catch (
|
|
20
|
+
} catch (_e) {
|
|
21
21
|
return void 0;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -33,9 +33,7 @@ async function getGcpExporters(config = {}) {
|
|
|
33
33
|
return {};
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
|
-
spanProcessors: enableTracing ? [
|
|
37
|
-
new BatchSpanProcessor(new TraceExporter({ projectId }))
|
|
38
|
-
] : [],
|
|
36
|
+
spanProcessors: enableTracing ? [new BatchSpanProcessor(new TraceExporter({ projectId }))] : [],
|
|
39
37
|
metricReaders: enableMetrics ? [
|
|
40
38
|
new PeriodicExportingMetricReader({
|
|
41
39
|
exporter: new MetricExporter({ projectId }),
|
|
@@ -3,22 +3,32 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { metrics, trace } from "@opentelemetry/api";
|
|
7
7
|
import { logs } from "@opentelemetry/api-logs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
9
|
+
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
10
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
10
11
|
import { detectResources } from "@opentelemetry/resources";
|
|
12
|
+
import {
|
|
13
|
+
BatchLogRecordProcessor,
|
|
14
|
+
LoggerProvider
|
|
15
|
+
} from "@opentelemetry/sdk-logs";
|
|
16
|
+
import {
|
|
17
|
+
MeterProvider,
|
|
18
|
+
PeriodicExportingMetricReader
|
|
19
|
+
} from "@opentelemetry/sdk-metrics";
|
|
11
20
|
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
12
21
|
import { NodeTracerProvider } from "@opentelemetry/sdk-trace-node";
|
|
13
|
-
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
14
|
-
import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
|
|
15
|
-
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
16
22
|
function maybeSetOtelProviders(otelHooksToSetup = [], otelResource) {
|
|
17
23
|
const resource = otelResource || getOtelResource();
|
|
18
24
|
const allHooks = [...otelHooksToSetup, getOtelExporters()];
|
|
19
|
-
const spanProcessors = allHooks.flatMap(
|
|
25
|
+
const spanProcessors = allHooks.flatMap(
|
|
26
|
+
(hooks) => hooks.spanProcessors || []
|
|
27
|
+
);
|
|
20
28
|
const metricReaders = allHooks.flatMap((hooks) => hooks.metricReaders || []);
|
|
21
|
-
const logRecordProcessors = allHooks.flatMap(
|
|
29
|
+
const logRecordProcessors = allHooks.flatMap(
|
|
30
|
+
(hooks) => hooks.logRecordProcessors || []
|
|
31
|
+
);
|
|
22
32
|
if (spanProcessors.length > 0) {
|
|
23
33
|
const tracerProvider = new NodeTracerProvider({
|
|
24
34
|
resource,
|
|
@@ -58,7 +68,11 @@ function getOtelExporters(config = getOtelExportersConfig()) {
|
|
|
58
68
|
const { enableTracing, enableMetrics, enableLogging } = config;
|
|
59
69
|
return {
|
|
60
70
|
spanProcessors: enableTracing ? [new BatchSpanProcessor(new OTLPTraceExporter())] : [],
|
|
61
|
-
metricReaders: enableMetrics ? [
|
|
71
|
+
metricReaders: enableMetrics ? [
|
|
72
|
+
new PeriodicExportingMetricReader({
|
|
73
|
+
exporter: new OTLPMetricExporter()
|
|
74
|
+
})
|
|
75
|
+
] : [],
|
|
62
76
|
logRecordProcessors: enableLogging ? [new BatchLogRecordProcessor(new OTLPLogExporter())] : []
|
|
63
77
|
};
|
|
64
78
|
}
|
|
@@ -18,7 +18,7 @@ var __objRest = (source, exclude) => {
|
|
|
18
18
|
* Copyright 2025 Google LLC
|
|
19
19
|
* SPDX-License-Identifier: Apache-2.0
|
|
20
20
|
*/
|
|
21
|
-
import {
|
|
21
|
+
import { context, trace } from "@opentelemetry/api";
|
|
22
22
|
import { version } from "../version.js";
|
|
23
23
|
const GEN_AI_AGENT_DESCRIPTION = "gen_ai.agent.description";
|
|
24
24
|
const GEN_AI_AGENT_NAME = "gen_ai.agent.name";
|
|
@@ -28,14 +28,11 @@ const GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
|
|
|
28
28
|
const GEN_AI_TOOL_DESCRIPTION = "gen_ai.tool.description";
|
|
29
29
|
const GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
30
30
|
const GEN_AI_TOOL_TYPE = "gen_ai.tool.type";
|
|
31
|
-
const tracer = trace.getTracer(
|
|
32
|
-
"gcp.vertex.agent",
|
|
33
|
-
version
|
|
34
|
-
);
|
|
31
|
+
const tracer = trace.getTracer("gcp.vertex.agent", version);
|
|
35
32
|
function safeJsonSerialize(obj) {
|
|
36
33
|
try {
|
|
37
34
|
return JSON.stringify(obj);
|
|
38
|
-
} catch (
|
|
35
|
+
} catch (_e) {
|
|
39
36
|
return "<not serializable>";
|
|
40
37
|
}
|
|
41
38
|
}
|
|
@@ -112,7 +109,10 @@ function traceMergedToolCalls({
|
|
|
112
109
|
"gcp.vertex.agent.llm_request": "{}",
|
|
113
110
|
"gcp.vertex.agent.llm_response": "{}"
|
|
114
111
|
});
|
|
115
|
-
span.setAttribute(
|
|
112
|
+
span.setAttribute(
|
|
113
|
+
"gcp.vertex.agent.tool_response",
|
|
114
|
+
shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}"
|
|
115
|
+
);
|
|
116
116
|
}
|
|
117
117
|
function traceCallLlm({
|
|
118
118
|
invocationContext,
|
|
@@ -136,14 +136,26 @@ function traceCallLlm({
|
|
|
136
136
|
span.setAttribute("gen_ai.request.top_p", llmRequest.config.topP);
|
|
137
137
|
}
|
|
138
138
|
if (((_b = llmRequest.config) == null ? void 0 : _b.maxOutputTokens) !== void 0) {
|
|
139
|
-
span.setAttribute(
|
|
139
|
+
span.setAttribute(
|
|
140
|
+
"gen_ai.request.max_tokens",
|
|
141
|
+
llmRequest.config.maxOutputTokens
|
|
142
|
+
);
|
|
140
143
|
}
|
|
141
|
-
span.setAttribute(
|
|
144
|
+
span.setAttribute(
|
|
145
|
+
"gcp.vertex.agent.llm_response",
|
|
146
|
+
shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}"
|
|
147
|
+
);
|
|
142
148
|
if (llmResponse.usageMetadata) {
|
|
143
|
-
span.setAttribute(
|
|
149
|
+
span.setAttribute(
|
|
150
|
+
"gen_ai.usage.input_tokens",
|
|
151
|
+
llmResponse.usageMetadata.promptTokenCount || 0
|
|
152
|
+
);
|
|
144
153
|
}
|
|
145
154
|
if ((_c = llmResponse.usageMetadata) == null ? void 0 : _c.candidatesTokenCount) {
|
|
146
|
-
span.setAttribute(
|
|
155
|
+
span.setAttribute(
|
|
156
|
+
"gen_ai.usage.output_tokens",
|
|
157
|
+
llmResponse.usageMetadata.candidatesTokenCount
|
|
158
|
+
);
|
|
147
159
|
}
|
|
148
160
|
if (llmResponse.finishReason) {
|
|
149
161
|
const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
|
|
@@ -161,7 +173,10 @@ function traceSendData({
|
|
|
161
173
|
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
162
174
|
"gcp.vertex.agent.event_id": eventId
|
|
163
175
|
});
|
|
164
|
-
span.setAttribute(
|
|
176
|
+
span.setAttribute(
|
|
177
|
+
"gcp.vertex.agent.data",
|
|
178
|
+
shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}"
|
|
179
|
+
);
|
|
165
180
|
}
|
|
166
181
|
function buildLlmRequestForTrace(llmRequest) {
|
|
167
182
|
const result = {
|
|
@@ -181,7 +196,7 @@ function buildLlmRequestForTrace(llmRequest) {
|
|
|
181
196
|
});
|
|
182
197
|
return result;
|
|
183
198
|
}
|
|
184
|
-
function
|
|
199
|
+
function bindOtelContextToAsyncGenerator(ctx, generator) {
|
|
185
200
|
return {
|
|
186
201
|
// Bind the next() method to execute within the provided context
|
|
187
202
|
next: context.bind(ctx, generator.next.bind(generator)),
|
|
@@ -191,16 +206,23 @@ function bindAsyncGenerator(ctx, generator) {
|
|
|
191
206
|
throw: context.bind(ctx, generator.throw.bind(generator)),
|
|
192
207
|
// Ensure the async iterator symbol also returns a context-bound generator
|
|
193
208
|
[Symbol.asyncIterator]() {
|
|
194
|
-
return
|
|
209
|
+
return bindOtelContextToAsyncGenerator(
|
|
210
|
+
ctx,
|
|
211
|
+
generator[Symbol.asyncIterator]()
|
|
212
|
+
);
|
|
195
213
|
}
|
|
196
214
|
};
|
|
197
215
|
}
|
|
216
|
+
function runAsyncGeneratorWithOtelContext(otelContext, generatorFnContext, generatorFn) {
|
|
217
|
+
const generator = generatorFn.call(generatorFnContext);
|
|
218
|
+
return bindOtelContextToAsyncGenerator(otelContext, generator);
|
|
219
|
+
}
|
|
198
220
|
function shouldAddRequestResponseToSpans() {
|
|
199
221
|
const envValue = process.env.ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS || "true";
|
|
200
222
|
return envValue === "true" || envValue === "1";
|
|
201
223
|
}
|
|
202
224
|
export {
|
|
203
|
-
|
|
225
|
+
runAsyncGeneratorWithOtelContext,
|
|
204
226
|
traceAgentInvocation,
|
|
205
227
|
traceCallLlm,
|
|
206
228
|
traceMergedToolCalls,
|
|
@@ -20,9 +20,10 @@ function isAgentTool(obj) {
|
|
|
20
20
|
}
|
|
21
21
|
class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
|
|
22
22
|
constructor(config) {
|
|
23
|
-
super(
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
super({
|
|
24
|
+
name: config.agent.name,
|
|
25
|
+
description: config.agent.description || ""
|
|
26
|
+
});
|
|
26
27
|
/** A unique symbol to identify ADK agent tool class. */
|
|
27
28
|
this[_a] = true;
|
|
28
29
|
this.agent = config.agent;
|
|
@@ -60,7 +61,10 @@ class AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
|
|
|
60
61
|
}
|
|
61
62
|
return declaration;
|
|
62
63
|
}
|
|
63
|
-
async runAsync({
|
|
64
|
+
async runAsync({
|
|
65
|
+
args,
|
|
66
|
+
toolContext
|
|
67
|
+
}) {
|
|
64
68
|
var _a2, _b2;
|
|
65
69
|
if (this.skipSummarization) {
|
|
66
70
|
toolContext.actions.skipSummarization = true;
|
|
@@ -49,7 +49,7 @@ class BaseTool {
|
|
|
49
49
|
*
|
|
50
50
|
* @param request The request to process the LLM request.
|
|
51
51
|
*/
|
|
52
|
-
async processLlmRequest({
|
|
52
|
+
async processLlmRequest({ llmRequest }) {
|
|
53
53
|
const functionDeclaration = this._getDeclaration();
|
|
54
54
|
if (!functionDeclaration) {
|
|
55
55
|
return;
|
|
@@ -78,7 +78,9 @@ class BaseTool {
|
|
|
78
78
|
}
|
|
79
79
|
function findToolWithFunctionDeclarations(llmRequest) {
|
|
80
80
|
var _a2;
|
|
81
|
-
return (((_a2 = llmRequest.config) == null ? void 0 : _a2.tools) || []).find(
|
|
81
|
+
return (((_a2 = llmRequest.config) == null ? void 0 : _a2.tools) || []).find(
|
|
82
|
+
(tool) => "functionDeclarations" in tool
|
|
83
|
+
);
|
|
82
84
|
}
|
|
83
85
|
export {
|
|
84
86
|
BaseTool,
|
|
@@ -16,7 +16,7 @@ class ForwardingArtifactService {
|
|
|
16
16
|
async loadArtifact(request) {
|
|
17
17
|
return this.toolContext.loadArtifact(request.filename, request.version);
|
|
18
18
|
}
|
|
19
|
-
async listArtifactKeys(
|
|
19
|
+
async listArtifactKeys() {
|
|
20
20
|
return this.toolContext.listArtifacts();
|
|
21
21
|
}
|
|
22
22
|
async deleteArtifact(request) {
|
|
@@ -35,6 +35,22 @@ class ForwardingArtifactService {
|
|
|
35
35
|
request
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
|
+
listArtifactVersions(request) {
|
|
39
|
+
if (!this.toolContext.invocationContext.artifactService) {
|
|
40
|
+
throw new Error("Artifact service is not initialized.");
|
|
41
|
+
}
|
|
42
|
+
return this.toolContext.invocationContext.artifactService.listArtifactVersions(
|
|
43
|
+
request
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
getArtifactVersion(request) {
|
|
47
|
+
if (!this.toolContext.invocationContext.artifactService) {
|
|
48
|
+
throw new Error("Artifact service is not initialized.");
|
|
49
|
+
}
|
|
50
|
+
return this.toolContext.invocationContext.artifactService.getArtifactVersion(
|
|
51
|
+
request
|
|
52
|
+
);
|
|
53
|
+
}
|
|
38
54
|
}
|
|
39
55
|
export {
|
|
40
56
|
ForwardingArtifactService
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
var _a, _b;
|
|
7
7
|
import { Type } from "@google/genai";
|
|
8
|
-
import { ZodObject } from "zod";
|
|
9
8
|
import { isZodObject, zodObjectToSchema } from "../utils/simple_zod_to_json.js";
|
|
10
9
|
import { BaseTool } from "./base_tool.js";
|
|
11
10
|
function toSchema(parameters) {
|
|
@@ -60,7 +59,7 @@ class FunctionTool extends (_b = BaseTool, _a = FUNCTION_TOOL_SIGNATURE_SYMBOL,
|
|
|
60
59
|
async runAsync(req) {
|
|
61
60
|
try {
|
|
62
61
|
let validatedArgs = req.args;
|
|
63
|
-
if (this.parameters
|
|
62
|
+
if (isZodObject(this.parameters)) {
|
|
64
63
|
validatedArgs = this.parameters.parse(req.args);
|
|
65
64
|
}
|
|
66
65
|
return await this.execute(
|
|
@@ -4,18 +4,15 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { isGemini1Model, isGeminiModel } from "../utils/model_name.js";
|
|
7
|
-
import {
|
|
8
|
-
BaseTool
|
|
9
|
-
} from "./base_tool.js";
|
|
7
|
+
import { BaseTool } from "./base_tool.js";
|
|
10
8
|
class GoogleSearchTool extends BaseTool {
|
|
11
9
|
constructor() {
|
|
12
10
|
super({ name: "google_search", description: "Google Search Tool" });
|
|
13
11
|
}
|
|
14
|
-
runAsync(
|
|
12
|
+
runAsync() {
|
|
15
13
|
return Promise.resolve();
|
|
16
14
|
}
|
|
17
15
|
async processLlmRequest({
|
|
18
|
-
toolContext,
|
|
19
16
|
llmRequest
|
|
20
17
|
}) {
|
|
21
18
|
if (!llmRequest.model) {
|
|
@@ -22,7 +22,9 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
22
22
|
* Copyright 2025 Google LLC
|
|
23
23
|
* SPDX-License-Identifier: Apache-2.0
|
|
24
24
|
*/
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
FunctionTool
|
|
27
|
+
} from "./function_tool.js";
|
|
26
28
|
const LONG_RUNNING_INSTRUCTION = "\n\nNOTE: This is a long-running operation. Do not call this tool again if it has already returned some intermediate or pending status.";
|
|
27
29
|
class LongRunningFunctionTool extends FunctionTool {
|
|
28
30
|
/**
|
|
@@ -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: ".concat(listResult.tools.length));
|
|
@@ -36,13 +36,21 @@ function base64Decode(data) {
|
|
|
36
36
|
function isBase64Encoded(data) {
|
|
37
37
|
try {
|
|
38
38
|
return base64Encode(base64Decode(data)) === data;
|
|
39
|
-
} catch (
|
|
39
|
+
} catch (_e) {
|
|
40
40
|
return false;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
function getBooleanEnvVar(envVar) {
|
|
44
|
+
if (!process.env) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
const envVarValue = (process.env[envVar] || "").toLowerCase();
|
|
48
|
+
return ["true", "1"].includes(envVarValue);
|
|
49
|
+
}
|
|
43
50
|
export {
|
|
44
51
|
base64Decode,
|
|
45
52
|
base64Encode,
|
|
53
|
+
getBooleanEnvVar,
|
|
46
54
|
isBase64Encoded,
|
|
47
55
|
isBrowser,
|
|
48
56
|
randomUUID
|
|
@@ -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;
|