@google/adk 2.2.0 → 2.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/a2a/a2a_remote_agent.js +4 -1
- package/dist/cjs/a2a/agent_card.js +102 -26
- package/dist/cjs/a2a/agent_to_a2a.js +1 -1
- package/dist/cjs/a2a/event_converter_utils.js +5 -1
- package/dist/cjs/a2a/metadata_converter_utils.js +2 -1
- package/dist/cjs/agents/functions.js +199 -25
- package/dist/cjs/agents/instructions.js +4 -1
- package/dist/cjs/agents/invocation_context.js +26 -4
- package/dist/cjs/agents/langgraph_agent.js +152 -0
- package/dist/cjs/agents/llm_agent.js +175 -101
- package/dist/cjs/agents/processors/code_execution_request_processor.js +10 -6
- package/dist/cjs/agents/remote_agent.js +187 -0
- package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/cjs/auth/auth_handler.js +37 -5
- package/dist/cjs/auth/auth_schemes.js +9 -0
- package/dist/cjs/cli/cli_eval.js +532 -0
- package/dist/cjs/cli/utils/envs.js +116 -0
- package/dist/cjs/cli/utils/evals.js +137 -0
- package/dist/cjs/cli/utils/logs.js +150 -0
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/cjs/code_executors/code_execution_utils.js +48 -16
- package/dist/cjs/code_executors/code_executor_context.js +6 -2
- package/dist/cjs/common.js +90 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
- package/dist/cjs/context/token_based_context_compactor.js +2 -1
- package/dist/cjs/events/abort_events.js +135 -0
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/events/internal_metadata.js +131 -0
- package/dist/cjs/examples/example_util.js +23 -2
- package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
- package/dist/cjs/index.js +97 -1
- package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +16 -8
- package/dist/cjs/models/google_llm.js +13 -16
- package/dist/cjs/models/llm_response.js +9 -1
- package/dist/cjs/models/registry.js +1 -1
- package/dist/cjs/models/routed_llm.js +9 -8
- package/dist/cjs/planners/plan_re_act_planner.js +1 -1
- package/dist/cjs/plugins/debug_logging_plugin.js +653 -0
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/tool_call_integrity_plugin.js +364 -0
- package/dist/cjs/runner/in_memory_runner.js +6 -11
- package/dist/cjs/runner/runner.js +121 -35
- package/dist/cjs/sessions/db/operations.js +1 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -1
- package/dist/cjs/sessions/state.js +8 -4
- package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
- package/dist/cjs/telemetry/tracing.js +97 -66
- package/dist/cjs/tools/agent_tool.js +44 -0
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +142 -0
- package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
- package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
- package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +185 -0
- package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +603 -0
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +219 -0
- package/dist/cjs/tools/crewai_tool.js +132 -0
- package/dist/cjs/tools/example_tool.js +10 -0
- package/dist/cjs/tools/function_tool.js +319 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool.js +97 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +226 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +58 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
- package/dist/cjs/tools/google_api_tool/index.js +64 -0
- package/dist/cjs/tools/langchain_tool.js +172 -0
- package/dist/cjs/tools/mcp/index.js +12 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
- package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
- package/dist/cjs/tools/toolbox_tool.js +108 -0
- package/dist/cjs/utils/env_aware_utils.js +6 -8
- package/dist/cjs/utils/error_utils.js +11 -11
- package/dist/cjs/utils/file_extension_utils.js +11 -0
- package/dist/cjs/utils/file_utils.js +2 -24
- package/dist/cjs/utils/gemini_schema_util.js +4 -1
- package/dist/cjs/utils/json_utils.js +49 -0
- package/dist/cjs/utils/live_connection_utils.js +4 -5
- package/dist/cjs/utils/logger_node.js +7 -1
- package/dist/cjs/utils/object_notation_utils.js +6 -3
- package/dist/cjs/utils/streaming_utils.js +12 -12
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +4 -1
- package/dist/esm/a2a/agent_card.js +103 -27
- package/dist/esm/a2a/agent_to_a2a.js +5 -2
- package/dist/esm/a2a/event_converter_utils.js +5 -1
- package/dist/esm/a2a/metadata_converter_utils.js +2 -1
- package/dist/esm/agents/functions.js +198 -25
- package/dist/esm/agents/instructions.js +4 -1
- package/dist/esm/agents/invocation_context.js +24 -4
- package/dist/esm/agents/langgraph_agent.js +123 -0
- package/dist/esm/agents/llm_agent.js +185 -104
- package/dist/esm/agents/processors/code_execution_request_processor.js +13 -8
- package/dist/esm/agents/remote_agent.js +164 -0
- package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/esm/auth/auth_handler.js +37 -5
- package/dist/esm/auth/auth_schemes.js +8 -0
- package/dist/esm/cli/cli_eval.js +510 -0
- package/dist/esm/cli/utils/envs.js +78 -0
- package/dist/esm/cli/utils/evals.js +109 -0
- package/dist/esm/cli/utils/logs.js +111 -0
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/esm/code_executors/code_execution_utils.js +46 -16
- package/dist/esm/code_executors/code_executor_context.js +5 -2
- package/dist/esm/common.js +87 -3
- package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
- package/dist/esm/context/token_based_context_compactor.js +2 -1
- package/dist/esm/events/abort_events.js +110 -0
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/events/internal_metadata.js +97 -0
- package/dist/esm/examples/example_util.js +21 -1
- package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
- package/dist/esm/index.js +99 -1
- package/dist/esm/integrations/agent_registry/helpers.js +1 -1
- package/dist/esm/models/gemini_llm_connection.js +16 -8
- package/dist/esm/models/google_llm.js +14 -17
- package/dist/esm/models/llm_response.js +9 -1
- package/dist/esm/models/registry.js +1 -1
- package/dist/esm/models/routed_llm.js +9 -8
- package/dist/esm/planners/plan_re_act_planner.js +1 -1
- package/dist/esm/plugins/debug_logging_plugin.js +615 -0
- package/dist/esm/plugins/plugin_manager.js +1 -1
- package/dist/esm/plugins/tool_call_integrity_plugin.js +339 -0
- package/dist/esm/runner/in_memory_runner.js +6 -11
- package/dist/esm/runner/runner.js +124 -35
- package/dist/esm/sessions/db/operations.js +1 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -1
- package/dist/esm/sessions/state.js +8 -4
- package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
- package/dist/esm/telemetry/tracing.js +97 -66
- package/dist/esm/tools/agent_tool.js +44 -0
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +106 -0
- package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
- package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
- package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +163 -0
- package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +561 -0
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +215 -0
- package/dist/esm/tools/crewai_tool.js +107 -0
- package/dist/esm/tools/example_tool.js +13 -1
- package/dist/esm/tools/function_tool.js +316 -0
- package/dist/esm/tools/google_api_tool/google_api_tool.js +70 -0
- package/dist/esm/tools/google_api_tool/google_api_tool_set.js +188 -0
- package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +24 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
- package/dist/esm/tools/google_api_tool/index.js +33 -0
- package/dist/esm/tools/langchain_tool.js +148 -0
- package/dist/esm/tools/mcp/index.js +6 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
- package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
- package/dist/esm/tools/toolbox_tool.js +80 -0
- package/dist/esm/utils/env_aware_utils.js +6 -8
- package/dist/esm/utils/error_utils.js +9 -10
- package/dist/esm/utils/file_extension_utils.js +11 -0
- package/dist/esm/utils/file_utils.js +2 -23
- package/dist/esm/utils/gemini_schema_util.js +4 -1
- package/dist/esm/utils/json_utils.js +21 -0
- package/dist/esm/utils/live_connection_utils.js +4 -5
- package/dist/esm/utils/logger_node.js +7 -1
- package/dist/esm/utils/object_notation_utils.js +4 -2
- package/dist/esm/utils/streaming_utils.js +11 -11
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
- package/dist/types/a2a/agent_card.d.ts +44 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
- package/dist/types/a2a/index.d.ts +1 -0
- package/dist/types/agents/functions.d.ts +33 -1
- package/dist/types/agents/invocation_context.d.ts +20 -1
- package/dist/types/agents/langgraph_agent.d.ts +153 -0
- package/dist/types/agents/remote_agent.d.ts +68 -0
- package/dist/types/auth/auth_handler.d.ts +28 -1
- package/dist/types/auth/auth_schemes.d.ts +13 -0
- package/dist/types/cli/cli_eval.d.ts +173 -0
- package/dist/types/cli/utils/envs.d.ts +23 -0
- package/dist/types/cli/utils/evals.d.ts +47 -0
- package/dist/types/cli/utils/logs.d.ts +38 -0
- package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
- package/dist/types/code_executors/code_executor_context.d.ts +1 -0
- package/dist/types/common.d.ts +30 -4
- package/dist/types/events/abort_events.d.ts +43 -0
- package/dist/types/events/event.d.ts +4 -0
- package/dist/types/events/internal_metadata.d.ts +78 -0
- package/dist/types/examples/example_util.d.ts +17 -0
- package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
- package/dist/types/index.d.ts +16 -1
- package/dist/types/models/gemini_llm_connection.d.ts +6 -7
- package/dist/types/models/routed_llm.d.ts +1 -1
- package/dist/types/plugins/debug_logging_plugin.d.ts +157 -0
- package/dist/types/plugins/tool_call_integrity_plugin.d.ts +116 -0
- package/dist/types/runner/in_memory_runner.d.ts +2 -1
- package/dist/types/runner/runner.d.ts +34 -0
- package/dist/types/sessions/state.d.ts +5 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +4 -2
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +122 -0
- package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
- package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
- package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
- package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +86 -0
- package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +215 -0
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
- package/dist/types/tools/crewai_tool.d.ts +85 -0
- package/dist/types/tools/example_tool.d.ts +10 -0
- package/dist/types/tools/function_tool.d.ts +32 -0
- package/dist/types/tools/google_api_tool/google_api_tool.d.ts +30 -0
- package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +78 -0
- package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +33 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +164 -0
- package/dist/types/tools/google_api_tool/index.d.ts +11 -0
- package/dist/types/tools/langchain_tool.d.ts +103 -0
- package/dist/types/tools/mcp/index.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
- package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
- package/dist/types/tools/toolbox_tool.d.ts +73 -0
- package/dist/types/utils/env_aware_utils.d.ts +18 -2
- package/dist/types/utils/error_utils.d.ts +7 -0
- package/dist/types/utils/file_utils.d.ts +6 -1
- package/dist/types/utils/gemini_schema_util.d.ts +1 -2
- package/dist/types/utils/json_utils.d.ts +11 -0
- package/dist/types/utils/object_notation_utils.d.ts +7 -0
- package/dist/types/utils/streaming_utils.d.ts +11 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +105 -106
- package/dist/web/index_web.js.map +4 -4
- package/package.json +8 -3
|
@@ -102,16 +102,19 @@ const _State = class _State {
|
|
|
102
102
|
/**
|
|
103
103
|
* Returns the value of the state dict for the given key.
|
|
104
104
|
*
|
|
105
|
+
* Only keys the state holds itself are found. Names inherited from
|
|
106
|
+
* `Object.prototype`, such as `toString`, are treated as missing.
|
|
107
|
+
*
|
|
105
108
|
* @param key The key to get the value for.
|
|
106
109
|
* @param defaultValue The default value to return if the key is not found.
|
|
107
110
|
* @return The value of the state for the given key, or the default value if
|
|
108
111
|
* not found.
|
|
109
112
|
*/
|
|
110
113
|
get(key, defaultValue) {
|
|
111
|
-
if (
|
|
114
|
+
if (Object.hasOwn(this.delta, key)) {
|
|
112
115
|
return this.delta[key];
|
|
113
116
|
}
|
|
114
|
-
if (
|
|
117
|
+
if (Object.hasOwn(this.value, key)) {
|
|
115
118
|
return this.value[key];
|
|
116
119
|
}
|
|
117
120
|
return defaultValue;
|
|
@@ -129,10 +132,11 @@ const _State = class _State {
|
|
|
129
132
|
(0, import_state_write_order.recordStateWrite)(this.value, this.delta, key);
|
|
130
133
|
}
|
|
131
134
|
/**
|
|
132
|
-
* Whether the state
|
|
135
|
+
* Whether the state holds the given key, either as a stored value or as a
|
|
136
|
+
* pending delta. Names inherited from `Object.prototype` are not keys.
|
|
133
137
|
*/
|
|
134
138
|
has(key) {
|
|
135
|
-
return
|
|
139
|
+
return Object.hasOwn(this.value, key) || Object.hasOwn(this.delta, key);
|
|
136
140
|
}
|
|
137
141
|
/**
|
|
138
142
|
* Whether the state has pending delta.
|
|
@@ -65,17 +65,22 @@ function quoteFilterLiteral(value) {
|
|
|
65
65
|
return `"${escaped}"`;
|
|
66
66
|
}
|
|
67
67
|
__name(quoteFilterLiteral, "quoteFilterLiteral");
|
|
68
|
+
function toStateMap(state) {
|
|
69
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), state);
|
|
70
|
+
}
|
|
71
|
+
__name(toStateMap, "toStateMap");
|
|
68
72
|
let VertexAiSessionService = class extends import_base_session_service.BaseSessionService {
|
|
69
73
|
constructor(options) {
|
|
70
74
|
super();
|
|
71
75
|
this.agentEngineId = options.agentEngineId;
|
|
72
|
-
this.projectId = options.projectId;
|
|
73
|
-
this.location = options.location;
|
|
74
76
|
this.expressModeApiKey = (0, import_vertex_ai_utils.getExpressModeApiKey)(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
options.projectId,
|
|
78
|
+
options.location,
|
|
77
79
|
options.expressModeApiKey
|
|
78
80
|
);
|
|
81
|
+
const useEnvironment = !options.expressModeApiKey;
|
|
82
|
+
this.projectId = options.projectId || (useEnvironment ? process.env["GOOGLE_CLOUD_PROJECT"] : void 0);
|
|
83
|
+
this.location = options.location || (useEnvironment ? process.env["GOOGLE_CLOUD_LOCATION"] : void 0);
|
|
79
84
|
if (options.sessions) {
|
|
80
85
|
this.sessions = options.sessions;
|
|
81
86
|
} else {
|
|
@@ -161,7 +166,7 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
161
166
|
id,
|
|
162
167
|
appName,
|
|
163
168
|
userId,
|
|
164
|
-
state: getSessionResponse.sessionState,
|
|
169
|
+
state: toStateMap(getSessionResponse.sessionState),
|
|
165
170
|
events: [],
|
|
166
171
|
lastUpdateTime: getSessionResponse.updateTime ? Date.parse(getSessionResponse.updateTime) : Date.now()
|
|
167
172
|
});
|
|
@@ -176,13 +181,14 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
176
181
|
const sessionResourceName = `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`;
|
|
177
182
|
try {
|
|
178
183
|
let getSessionResponse;
|
|
179
|
-
|
|
184
|
+
const eventsIterator = [];
|
|
185
|
+
const listConfig = {};
|
|
186
|
+
let pageToken;
|
|
180
187
|
if (config && config.numRecentEvents === 0) {
|
|
181
188
|
getSessionResponse = await this.sessions.get({
|
|
182
189
|
name: sessionResourceName
|
|
183
190
|
});
|
|
184
191
|
} else {
|
|
185
|
-
const listConfig = {};
|
|
186
192
|
if (config && config.afterTimestamp) {
|
|
187
193
|
listConfig.filter = `timestamp>="${new Date(
|
|
188
194
|
config.afterTimestamp
|
|
@@ -196,7 +202,9 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
196
202
|
})
|
|
197
203
|
]);
|
|
198
204
|
getSessionResponse = sessionRes;
|
|
199
|
-
|
|
205
|
+
const firstPage = eventsRes;
|
|
206
|
+
eventsIterator.push(...firstPage.sessionEvents || []);
|
|
207
|
+
pageToken = firstPage.nextPageToken;
|
|
200
208
|
}
|
|
201
209
|
const sessionObj = getSessionResponse;
|
|
202
210
|
if (sessionObj.userId !== userId) {
|
|
@@ -204,20 +212,29 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
204
212
|
`Session ${sessionId} does not belong to user ${userId}.`
|
|
205
213
|
);
|
|
206
214
|
}
|
|
215
|
+
while (pageToken) {
|
|
216
|
+
const eventsRes = await this.sessions.events.listInternal({
|
|
217
|
+
name: sessionResourceName,
|
|
218
|
+
config: {
|
|
219
|
+
...listConfig,
|
|
220
|
+
pageToken
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
eventsIterator.push(...eventsRes.sessionEvents || []);
|
|
224
|
+
pageToken = eventsRes.nextPageToken;
|
|
225
|
+
}
|
|
207
226
|
const session = (0, import_session.createSession)({
|
|
208
227
|
id: sessionId,
|
|
209
228
|
appName,
|
|
210
229
|
userId,
|
|
211
|
-
state: sessionObj.sessionState,
|
|
230
|
+
state: toStateMap(sessionObj.sessionState),
|
|
212
231
|
events: [],
|
|
213
232
|
lastUpdateTime: sessionObj.updateTime ? Date.parse(sessionObj.updateTime) : Date.now()
|
|
214
233
|
});
|
|
215
|
-
|
|
234
|
+
const recentEvents = config && config.numRecentEvents ? eventsIterator.slice(-config.numRecentEvents) : eventsIterator;
|
|
235
|
+
for (const event of recentEvents) {
|
|
216
236
|
session.events.push(_fromApiEvent(event));
|
|
217
237
|
}
|
|
218
|
-
if (config && config.numRecentEvents) {
|
|
219
|
-
session.events = session.events.slice(-config.numRecentEvents);
|
|
220
|
-
}
|
|
221
238
|
return session;
|
|
222
239
|
} catch (error) {
|
|
223
240
|
const err = error;
|
|
@@ -256,7 +273,7 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
256
273
|
id,
|
|
257
274
|
appName,
|
|
258
275
|
userId: sessionObj.userId,
|
|
259
|
-
state: sessionObj.sessionState,
|
|
276
|
+
state: toStateMap(sessionObj.sessionState),
|
|
260
277
|
events: [],
|
|
261
278
|
lastUpdateTime: sessionObj.updateTime ? new Date(sessionObj.updateTime).getTime() : Date.now()
|
|
262
279
|
})
|
|
@@ -502,7 +519,9 @@ function _fromApiEvent(apiEventObj) {
|
|
|
502
519
|
}
|
|
503
520
|
}
|
|
504
521
|
const eventActions = {
|
|
505
|
-
stateDelta:
|
|
522
|
+
stateDelta: toStateMap(
|
|
523
|
+
actions["stateDelta"]
|
|
524
|
+
),
|
|
506
525
|
artifactDelta: actions["artifactDelta"] || {},
|
|
507
526
|
requestedAuthConfigs: actions.requestedAuthConfigs || {},
|
|
508
527
|
requestedToolConfirmations: actions["requestedToolConfirmations"] || {},
|
|
@@ -43,21 +43,46 @@ var import_version = require("../version.js");
|
|
|
43
43
|
* Copyright 2025 Google LLC
|
|
44
44
|
* SPDX-License-Identifier: Apache-2.0
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
var GenAiAttr = /* @__PURE__ */ ((GenAiAttr2) => {
|
|
47
|
+
GenAiAttr2["AGENT_DESCRIPTION"] = "gen_ai.agent.description";
|
|
48
|
+
GenAiAttr2["AGENT_NAME"] = "gen_ai.agent.name";
|
|
49
|
+
GenAiAttr2["CONVERSATION_ID"] = "gen_ai.conversation.id";
|
|
50
|
+
GenAiAttr2["OPERATION_NAME"] = "gen_ai.operation.name";
|
|
51
|
+
GenAiAttr2["SYSTEM"] = "gen_ai.system";
|
|
52
|
+
GenAiAttr2["TOOL_CALL_ID"] = "gen_ai.tool.call.id";
|
|
53
|
+
GenAiAttr2["TOOL_DESCRIPTION"] = "gen_ai.tool.description";
|
|
54
|
+
GenAiAttr2["TOOL_NAME"] = "gen_ai.tool.name";
|
|
55
|
+
GenAiAttr2["TOOL_TYPE"] = "gen_ai.tool.type";
|
|
56
|
+
GenAiAttr2["REQUEST_MODEL"] = "gen_ai.request.model";
|
|
57
|
+
GenAiAttr2["REQUEST_TOP_P"] = "gen_ai.request.top_p";
|
|
58
|
+
GenAiAttr2["REQUEST_MAX_TOKENS"] = "gen_ai.request.max_tokens";
|
|
59
|
+
GenAiAttr2["USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
|
|
60
|
+
GenAiAttr2["USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
|
|
61
|
+
GenAiAttr2["RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
|
|
62
|
+
return GenAiAttr2;
|
|
63
|
+
})(GenAiAttr || {});
|
|
64
|
+
var AdkAttr = /* @__PURE__ */ ((AdkAttr2) => {
|
|
65
|
+
AdkAttr2["WORKFLOW_NAME"] = "adk.workflow.name";
|
|
66
|
+
AdkAttr2["NODE_PATH"] = "adk.node.path";
|
|
67
|
+
AdkAttr2["NODE_RUN_ID"] = "adk.node.run_id";
|
|
68
|
+
AdkAttr2["NODE_ATTEMPT"] = "adk.node.attempt";
|
|
69
|
+
AdkAttr2["NODE_STATUS"] = "adk.node.status";
|
|
70
|
+
AdkAttr2["NODE_INTERRUPT_COUNT"] = "adk.node.interrupt_count";
|
|
71
|
+
return AdkAttr2;
|
|
72
|
+
})(AdkAttr || {});
|
|
73
|
+
var GcpAttr = /* @__PURE__ */ ((GcpAttr2) => {
|
|
74
|
+
GcpAttr2["INVOCATION_ID"] = "gcp.vertex.agent.invocation_id";
|
|
75
|
+
GcpAttr2["SESSION_ID"] = "gcp.vertex.agent.session_id";
|
|
76
|
+
GcpAttr2["EVENT_ID"] = "gcp.vertex.agent.event_id";
|
|
77
|
+
GcpAttr2["LLM_REQUEST"] = "gcp.vertex.agent.llm_request";
|
|
78
|
+
GcpAttr2["LLM_RESPONSE"] = "gcp.vertex.agent.llm_response";
|
|
79
|
+
GcpAttr2["TOOL_CALL_ARGS"] = "gcp.vertex.agent.tool_call_args";
|
|
80
|
+
GcpAttr2["TOOL_RESPONSE"] = "gcp.vertex.agent.tool_response";
|
|
81
|
+
GcpAttr2["DATA"] = "gcp.vertex.agent.data";
|
|
82
|
+
return GcpAttr2;
|
|
83
|
+
})(GcpAttr || {});
|
|
84
|
+
const GEN_AI_SYSTEM_VALUE = "gcp.vertex.agent";
|
|
85
|
+
const tracer = import_api.trace.getTracer(GEN_AI_SYSTEM_VALUE, import_version.version);
|
|
61
86
|
function safeJsonSerialize(obj) {
|
|
62
87
|
try {
|
|
63
88
|
return JSON.stringify(obj);
|
|
@@ -73,11 +98,11 @@ function traceAgentInvocation({
|
|
|
73
98
|
const span = import_api.trace.getActiveSpan();
|
|
74
99
|
if (!span) return;
|
|
75
100
|
span.setAttributes({
|
|
76
|
-
[
|
|
101
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_agent",
|
|
77
102
|
// Conditionally Required
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
103
|
+
["gen_ai.agent.description" /* AGENT_DESCRIPTION */]: agent.description,
|
|
104
|
+
["gen_ai.agent.name" /* AGENT_NAME */]: agent.name,
|
|
105
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: invocationContext.session.id
|
|
81
106
|
});
|
|
82
107
|
}
|
|
83
108
|
__name(traceAgentInvocation, "traceAgentInvocation");
|
|
@@ -89,10 +114,10 @@ function traceWorkflowInvocation({
|
|
|
89
114
|
const span = import_api.trace.getActiveSpan();
|
|
90
115
|
if (!span) return;
|
|
91
116
|
span.setAttributes({
|
|
92
|
-
[
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
117
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_workflow",
|
|
118
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: sessionId,
|
|
119
|
+
["adk.workflow.name" /* WORKFLOW_NAME */]: workflowName,
|
|
120
|
+
["adk.node.path" /* NODE_PATH */]: nodePath
|
|
96
121
|
});
|
|
97
122
|
}
|
|
98
123
|
__name(traceWorkflowInvocation, "traceWorkflowInvocation");
|
|
@@ -106,34 +131,37 @@ function traceNodeExecution({
|
|
|
106
131
|
const span = import_api.trace.getActiveSpan();
|
|
107
132
|
if (!span) return;
|
|
108
133
|
span.setAttributes({
|
|
109
|
-
[
|
|
110
|
-
[
|
|
111
|
-
[
|
|
112
|
-
[
|
|
113
|
-
[
|
|
114
|
-
[
|
|
134
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_node",
|
|
135
|
+
["adk.node.path" /* NODE_PATH */]: nodePath,
|
|
136
|
+
["adk.node.run_id" /* NODE_RUN_ID */]: runId,
|
|
137
|
+
["adk.node.attempt" /* NODE_ATTEMPT */]: attempt,
|
|
138
|
+
["adk.node.status" /* NODE_STATUS */]: status,
|
|
139
|
+
["adk.node.interrupt_count" /* NODE_INTERRUPT_COUNT */]: interruptCount
|
|
115
140
|
});
|
|
116
141
|
}
|
|
117
142
|
__name(traceNodeExecution, "traceNodeExecution");
|
|
118
143
|
function traceToolCall({
|
|
119
144
|
tool,
|
|
120
145
|
args,
|
|
121
|
-
functionResponseEvent
|
|
146
|
+
functionResponseEvent,
|
|
147
|
+
invocationContext
|
|
122
148
|
}) {
|
|
123
149
|
var _a, _b;
|
|
124
150
|
const span = import_api.trace.getActiveSpan();
|
|
125
151
|
if (!span) return;
|
|
126
152
|
span.setAttributes({
|
|
127
|
-
[
|
|
128
|
-
[
|
|
129
|
-
[
|
|
153
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
154
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
155
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: tool.description || "",
|
|
156
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: tool.name,
|
|
130
157
|
// e.g. FunctionTool
|
|
131
|
-
[
|
|
158
|
+
["gen_ai.tool.type" /* TOOL_TYPE */]: tool.constructor.name,
|
|
159
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
132
160
|
// Setting empty llm request and response (as UI expect these) while not
|
|
133
161
|
// applicable for tool_response.
|
|
134
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
135
|
-
"gcp.vertex.agent.llm_response": "{}",
|
|
136
|
-
"gcp.vertex.agent.tool_call_args": shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
162
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
163
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}",
|
|
164
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
137
165
|
});
|
|
138
166
|
let toolCallId = "<not specified>";
|
|
139
167
|
let toolResponse = "<not specified>";
|
|
@@ -151,32 +179,35 @@ function traceToolCall({
|
|
|
151
179
|
toolResponse = { result: toolResponse };
|
|
152
180
|
}
|
|
153
181
|
span.setAttributes({
|
|
154
|
-
[
|
|
155
|
-
"gcp.vertex.agent.event_id": functionResponseEvent.id,
|
|
156
|
-
"gcp.vertex.agent.tool_response": shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
182
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: toolCallId,
|
|
183
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: functionResponseEvent.id,
|
|
184
|
+
["gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
157
185
|
});
|
|
158
186
|
}
|
|
159
187
|
__name(traceToolCall, "traceToolCall");
|
|
160
188
|
function traceMergedToolCalls({
|
|
161
189
|
responseEventId,
|
|
162
|
-
functionResponseEvent
|
|
190
|
+
functionResponseEvent,
|
|
191
|
+
invocationContext
|
|
163
192
|
}) {
|
|
164
193
|
const span = import_api.trace.getActiveSpan();
|
|
165
194
|
if (!span) return;
|
|
166
195
|
span.setAttributes({
|
|
167
|
-
[
|
|
168
|
-
[
|
|
169
|
-
[
|
|
170
|
-
[
|
|
171
|
-
"
|
|
172
|
-
"gcp.vertex.agent.
|
|
196
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
197
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
198
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: "(merged tools)",
|
|
199
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: "(merged tools)",
|
|
200
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: responseEventId,
|
|
201
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
202
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: "N/A",
|
|
203
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: responseEventId,
|
|
173
204
|
// Setting empty llm request and response (as UI expect these) while not
|
|
174
205
|
// applicable for tool_response.
|
|
175
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
176
|
-
"gcp.vertex.agent.llm_response": "{}"
|
|
206
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
207
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}"
|
|
177
208
|
});
|
|
178
209
|
span.setAttribute(
|
|
179
|
-
"gcp.vertex.agent.tool_response"
|
|
210
|
+
"gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */,
|
|
180
211
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}"
|
|
181
212
|
);
|
|
182
213
|
}
|
|
@@ -191,43 +222,43 @@ function traceCallLlm({
|
|
|
191
222
|
const span = import_api.trace.getActiveSpan();
|
|
192
223
|
if (!span) return;
|
|
193
224
|
span.setAttributes({
|
|
194
|
-
"gen_ai.system":
|
|
195
|
-
"gen_ai.request.model": llmRequest.model,
|
|
196
|
-
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { [
|
|
197
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
198
|
-
"gcp.vertex.agent.session_id": invocationContext.session.id,
|
|
199
|
-
"gcp.vertex.agent.event_id": eventId,
|
|
225
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
226
|
+
["gen_ai.request.model" /* REQUEST_MODEL */]: llmRequest.model,
|
|
227
|
+
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { ["gen_ai.agent.name" /* AGENT_NAME */]: invocationContext.agent.name } : {},
|
|
228
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
229
|
+
["gcp.vertex.agent.session_id" /* SESSION_ID */]: invocationContext.session.id,
|
|
230
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId,
|
|
200
231
|
// Consider removing once GenAI SDK provides a way to record this info.
|
|
201
|
-
"gcp.vertex.agent.llm_request": shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
232
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
202
233
|
});
|
|
203
234
|
if ((_b = llmRequest.config) == null ? void 0 : _b.topP) {
|
|
204
|
-
span.setAttribute("gen_ai.request.top_p"
|
|
235
|
+
span.setAttribute("gen_ai.request.top_p" /* REQUEST_TOP_P */, llmRequest.config.topP);
|
|
205
236
|
}
|
|
206
237
|
if (((_c = llmRequest.config) == null ? void 0 : _c.maxOutputTokens) !== void 0) {
|
|
207
238
|
span.setAttribute(
|
|
208
|
-
"gen_ai.request.max_tokens"
|
|
239
|
+
"gen_ai.request.max_tokens" /* REQUEST_MAX_TOKENS */,
|
|
209
240
|
llmRequest.config.maxOutputTokens
|
|
210
241
|
);
|
|
211
242
|
}
|
|
212
243
|
span.setAttribute(
|
|
213
|
-
"gcp.vertex.agent.llm_response"
|
|
244
|
+
"gcp.vertex.agent.llm_response" /* LLM_RESPONSE */,
|
|
214
245
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}"
|
|
215
246
|
);
|
|
216
247
|
if (llmResponse.usageMetadata) {
|
|
217
248
|
span.setAttribute(
|
|
218
|
-
"gen_ai.usage.input_tokens"
|
|
249
|
+
"gen_ai.usage.input_tokens" /* USAGE_INPUT_TOKENS */,
|
|
219
250
|
llmResponse.usageMetadata.promptTokenCount || 0
|
|
220
251
|
);
|
|
221
252
|
}
|
|
222
253
|
if ((_d = llmResponse.usageMetadata) == null ? void 0 : _d.candidatesTokenCount) {
|
|
223
254
|
span.setAttribute(
|
|
224
|
-
"gen_ai.usage.output_tokens"
|
|
255
|
+
"gen_ai.usage.output_tokens" /* USAGE_OUTPUT_TOKENS */,
|
|
225
256
|
llmResponse.usageMetadata.candidatesTokenCount
|
|
226
257
|
);
|
|
227
258
|
}
|
|
228
259
|
if (llmResponse.finishReason) {
|
|
229
260
|
const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
|
|
230
|
-
span.setAttribute("gen_ai.response.finish_reasons"
|
|
261
|
+
span.setAttribute("gen_ai.response.finish_reasons" /* RESPONSE_FINISH_REASONS */, [finishReasonValue]);
|
|
231
262
|
}
|
|
232
263
|
}
|
|
233
264
|
__name(traceCallLlm, "traceCallLlm");
|
|
@@ -239,11 +270,11 @@ function traceSendData({
|
|
|
239
270
|
const span = import_api.trace.getActiveSpan();
|
|
240
271
|
if (!span) return;
|
|
241
272
|
span.setAttributes({
|
|
242
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
243
|
-
"gcp.vertex.agent.event_id": eventId
|
|
273
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
274
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId
|
|
244
275
|
});
|
|
245
276
|
span.setAttribute(
|
|
246
|
-
"gcp.vertex.agent.data"
|
|
277
|
+
"gcp.vertex.agent.data" /* DATA */,
|
|
247
278
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}"
|
|
248
279
|
);
|
|
249
280
|
}
|
|
@@ -38,12 +38,50 @@ var import_variant_utils = require("../utils/variant_utils.js");
|
|
|
38
38
|
var import_state = require("../sessions/state.js");
|
|
39
39
|
var import_base_tool = require("./base_tool.js");
|
|
40
40
|
var import_forwarding_artifact_service = require("./forwarding_artifact_service.js");
|
|
41
|
+
var import_schema = require("../utils/schema.js");
|
|
42
|
+
var import_simple_zod_to_json = require("../utils/simple_zod_to_json.js");
|
|
41
43
|
/**
|
|
42
44
|
* @license
|
|
43
45
|
* Copyright 2025 Google LLC
|
|
44
46
|
* SPDX-License-Identifier: Apache-2.0
|
|
45
47
|
*/
|
|
46
48
|
var _a, _b;
|
|
49
|
+
function excludeNone(value) {
|
|
50
|
+
if (Array.isArray(value)) {
|
|
51
|
+
return value.map((item) => excludeNone(item));
|
|
52
|
+
}
|
|
53
|
+
if (value !== null && typeof value === "object") {
|
|
54
|
+
const result = {};
|
|
55
|
+
for (const [key, val] of Object.entries(value)) {
|
|
56
|
+
if (val !== null && val !== void 0) {
|
|
57
|
+
result[key] = excludeNone(val);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
__name(excludeNone, "excludeNone");
|
|
65
|
+
function validateAndStripAgentInput(agent, args) {
|
|
66
|
+
var _a2;
|
|
67
|
+
if (typeof args !== "object" || args === null || Array.isArray(args)) {
|
|
68
|
+
throw new Error("AgentTool input args must be a plain object.");
|
|
69
|
+
}
|
|
70
|
+
const schema = (0, import_simple_zod_to_json.isZodSchema)(agent.inputSchema) ? agent.inputSchema : (_a2 = agent.inputSchemaSource) != null ? _a2 : agent.inputSchema;
|
|
71
|
+
const validated = (0, import_schema.parseWithSchema)(schema, args);
|
|
72
|
+
return excludeNone(validated);
|
|
73
|
+
}
|
|
74
|
+
__name(validateAndStripAgentInput, "validateAndStripAgentInput");
|
|
75
|
+
function validateAndStripAgentOutput(agent, mergedText) {
|
|
76
|
+
var _a2;
|
|
77
|
+
const parsed = JSON.parse(mergedText);
|
|
78
|
+
const validated = typeof agent.validateOutput === "function" ? agent.validateOutput(parsed) : (0, import_schema.parseWithSchema)(
|
|
79
|
+
(0, import_simple_zod_to_json.isZodSchema)(agent.outputSchema) ? agent.outputSchema : (_a2 = agent.outputSchemaSource) != null ? _a2 : agent.outputSchema,
|
|
80
|
+
parsed
|
|
81
|
+
);
|
|
82
|
+
return excludeNone(validated);
|
|
83
|
+
}
|
|
84
|
+
__name(validateAndStripAgentOutput, "validateAndStripAgentOutput");
|
|
47
85
|
const AGENT_TOOL_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.agentTool");
|
|
48
86
|
function isAgentTool(obj) {
|
|
49
87
|
return typeof obj === "object" && obj !== null && AGENT_TOOL_SIGNATURE_SYMBOL in obj && obj[AGENT_TOOL_SIGNATURE_SYMBOL] === true;
|
|
@@ -97,6 +135,9 @@ const _AgentTool = class _AgentTool extends (_b = import_base_tool.BaseTool, _a
|
|
|
97
135
|
}) {
|
|
98
136
|
var _a2, _b2, _c, _d, _e, _f;
|
|
99
137
|
const hasInputSchema = (0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.inputSchema;
|
|
138
|
+
if (hasInputSchema && (0, import_llm_agent.isLlmAgent)(this.agent)) {
|
|
139
|
+
args = validateAndStripAgentInput(this.agent, args);
|
|
140
|
+
}
|
|
100
141
|
const content = {
|
|
101
142
|
role: "user",
|
|
102
143
|
parts: [
|
|
@@ -151,6 +192,9 @@ const _AgentTool = class _AgentTool extends (_b = import_base_tool.BaseTool, _a
|
|
|
151
192
|
}
|
|
152
193
|
const hasOutputSchema = (0, import_llm_agent.isLlmAgent)(this.agent) && this.agent.outputSchema;
|
|
153
194
|
const mergedText = lastEvent.content.parts.filter((part) => !part.thought).map((part) => part.text).filter((text) => text).join("\n");
|
|
195
|
+
if (hasOutputSchema && (0, import_llm_agent.isLlmAgent)(this.agent)) {
|
|
196
|
+
return validateAndStripAgentOutput(this.agent, mergedText);
|
|
197
|
+
}
|
|
154
198
|
return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
|
|
155
199
|
}
|
|
156
200
|
};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
+
mod
|
|
34
|
+
));
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
37
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
38
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
39
|
+
if (decorator = decorators[i])
|
|
40
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
41
|
+
if (kind && result) __defProp(target, key, result);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
var apihub_toolset_exports = {};
|
|
45
|
+
__export(apihub_toolset_exports, {
|
|
46
|
+
APIHubToolset: () => APIHubToolset
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(apihub_toolset_exports);
|
|
49
|
+
var import_js_yaml = __toESM(require("js-yaml"), 1);
|
|
50
|
+
var import_case_utils = require("../../utils/case_utils.js");
|
|
51
|
+
var import_experimental = require("../../utils/experimental.js");
|
|
52
|
+
var import_base_toolset = require("../base_toolset.js");
|
|
53
|
+
var import_openapi_toolset = require("../openapi_tool/openapi_toolset.js");
|
|
54
|
+
var import_apihub_client = require("./clients/apihub_client.js");
|
|
55
|
+
/**
|
|
56
|
+
* @license
|
|
57
|
+
* Copyright 2026 Google LLC
|
|
58
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
59
|
+
*/
|
|
60
|
+
let APIHubToolset = class extends import_base_toolset.BaseToolset {
|
|
61
|
+
constructor(options) {
|
|
62
|
+
var _a, _b, _c, _d;
|
|
63
|
+
super([]);
|
|
64
|
+
this.name = (_a = options.name) != null ? _a : "";
|
|
65
|
+
this.description = (_b = options.description) != null ? _b : "";
|
|
66
|
+
this.apihubResourceName = options.apihubResourceName;
|
|
67
|
+
this.lazyLoadSpec = (_c = options.lazyLoadSpec) != null ? _c : false;
|
|
68
|
+
this.authScheme = options.authScheme;
|
|
69
|
+
this.authCredential = options.authCredential;
|
|
70
|
+
this.apihubClient = (_d = options.apihubClient) != null ? _d : new import_apihub_client.APIHubClient({
|
|
71
|
+
accessToken: options.accessToken,
|
|
72
|
+
serviceAccountJson: options.serviceAccountJson
|
|
73
|
+
});
|
|
74
|
+
if (!this.lazyLoadSpec) {
|
|
75
|
+
this.toolsetPromise = this.prepareTools();
|
|
76
|
+
this.toolsetPromise.catch(() => void 0);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Returns one tool per operation in the spec, or an empty array when the
|
|
81
|
+
* spec is empty.
|
|
82
|
+
*
|
|
83
|
+
* @throws When the spec cannot be fetched or is not valid YAML or JSON.
|
|
84
|
+
*/
|
|
85
|
+
async getTools(context) {
|
|
86
|
+
const toolset = await this.loadToolset();
|
|
87
|
+
return toolset ? toolset.getTools(context) : [];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns the tool with the given name, or `undefined` when the spec
|
|
91
|
+
* produced no such tool.
|
|
92
|
+
*
|
|
93
|
+
* Unlike `OpenAPIToolset.getTool`, the result is a Promise, because the spec
|
|
94
|
+
* may still be loading.
|
|
95
|
+
*
|
|
96
|
+
* @param name The tool name, which is the operation ID in snake_case.
|
|
97
|
+
* @throws When the spec cannot be fetched or is not valid YAML or JSON.
|
|
98
|
+
*/
|
|
99
|
+
async getTool(name) {
|
|
100
|
+
const toolset = await this.loadToolset();
|
|
101
|
+
return toolset == null ? void 0 : toolset.getTool(name);
|
|
102
|
+
}
|
|
103
|
+
async close() {
|
|
104
|
+
}
|
|
105
|
+
loadToolset() {
|
|
106
|
+
if (!this.toolsetPromise) {
|
|
107
|
+
const promise = this.prepareTools();
|
|
108
|
+
this.toolsetPromise = promise;
|
|
109
|
+
promise.catch(() => {
|
|
110
|
+
if (this.toolsetPromise === promise) {
|
|
111
|
+
this.toolsetPromise = void 0;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return this.toolsetPromise;
|
|
116
|
+
}
|
|
117
|
+
async prepareTools() {
|
|
118
|
+
var _a, _b, _c, _d;
|
|
119
|
+
const spec = await this.apihubClient.getSpecContent(
|
|
120
|
+
this.apihubResourceName
|
|
121
|
+
);
|
|
122
|
+
const specDict = import_js_yaml.default.load(spec);
|
|
123
|
+
if (!specDict) {
|
|
124
|
+
return void 0;
|
|
125
|
+
}
|
|
126
|
+
this.name || (this.name = (0, import_case_utils.toSnakeCaseName)((_b = (_a = specDict.info) == null ? void 0 : _a.title) != null ? _b : "unnamed"));
|
|
127
|
+
this.description || (this.description = (_d = (_c = specDict.info) == null ? void 0 : _c.description) != null ? _d : "");
|
|
128
|
+
return new import_openapi_toolset.OpenAPIToolset({
|
|
129
|
+
specDict,
|
|
130
|
+
authScheme: this.authScheme,
|
|
131
|
+
authCredential: this.authCredential
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
__name(APIHubToolset, "APIHubToolset");
|
|
136
|
+
APIHubToolset = __decorateClass([
|
|
137
|
+
import_experimental.experimental
|
|
138
|
+
], APIHubToolset);
|
|
139
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
+
0 && (module.exports = {
|
|
141
|
+
APIHubToolset
|
|
142
|
+
});
|