@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
|
@@ -44,17 +44,22 @@ function quoteFilterLiteral(value) {
|
|
|
44
44
|
return `"${escaped}"`;
|
|
45
45
|
}
|
|
46
46
|
__name(quoteFilterLiteral, "quoteFilterLiteral");
|
|
47
|
+
function toStateMap(state) {
|
|
48
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), state);
|
|
49
|
+
}
|
|
50
|
+
__name(toStateMap, "toStateMap");
|
|
47
51
|
let VertexAiSessionService = class extends BaseSessionService {
|
|
48
52
|
constructor(options) {
|
|
49
53
|
super();
|
|
50
54
|
this.agentEngineId = options.agentEngineId;
|
|
51
|
-
this.projectId = options.projectId;
|
|
52
|
-
this.location = options.location;
|
|
53
55
|
this.expressModeApiKey = getExpressModeApiKey(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
options.projectId,
|
|
57
|
+
options.location,
|
|
56
58
|
options.expressModeApiKey
|
|
57
59
|
);
|
|
60
|
+
const useEnvironment = !options.expressModeApiKey;
|
|
61
|
+
this.projectId = options.projectId || (useEnvironment ? process.env["GOOGLE_CLOUD_PROJECT"] : void 0);
|
|
62
|
+
this.location = options.location || (useEnvironment ? process.env["GOOGLE_CLOUD_LOCATION"] : void 0);
|
|
58
63
|
if (options.sessions) {
|
|
59
64
|
this.sessions = options.sessions;
|
|
60
65
|
} else {
|
|
@@ -140,7 +145,7 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
140
145
|
id,
|
|
141
146
|
appName,
|
|
142
147
|
userId,
|
|
143
|
-
state: getSessionResponse.sessionState,
|
|
148
|
+
state: toStateMap(getSessionResponse.sessionState),
|
|
144
149
|
events: [],
|
|
145
150
|
lastUpdateTime: getSessionResponse.updateTime ? Date.parse(getSessionResponse.updateTime) : Date.now()
|
|
146
151
|
});
|
|
@@ -155,13 +160,14 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
155
160
|
const sessionResourceName = `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`;
|
|
156
161
|
try {
|
|
157
162
|
let getSessionResponse;
|
|
158
|
-
|
|
163
|
+
const eventsIterator = [];
|
|
164
|
+
const listConfig = {};
|
|
165
|
+
let pageToken;
|
|
159
166
|
if (config && config.numRecentEvents === 0) {
|
|
160
167
|
getSessionResponse = await this.sessions.get({
|
|
161
168
|
name: sessionResourceName
|
|
162
169
|
});
|
|
163
170
|
} else {
|
|
164
|
-
const listConfig = {};
|
|
165
171
|
if (config && config.afterTimestamp) {
|
|
166
172
|
listConfig.filter = `timestamp>="${new Date(
|
|
167
173
|
config.afterTimestamp
|
|
@@ -175,7 +181,9 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
175
181
|
})
|
|
176
182
|
]);
|
|
177
183
|
getSessionResponse = sessionRes;
|
|
178
|
-
|
|
184
|
+
const firstPage = eventsRes;
|
|
185
|
+
eventsIterator.push(...firstPage.sessionEvents || []);
|
|
186
|
+
pageToken = firstPage.nextPageToken;
|
|
179
187
|
}
|
|
180
188
|
const sessionObj = getSessionResponse;
|
|
181
189
|
if (sessionObj.userId !== userId) {
|
|
@@ -183,20 +191,29 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
183
191
|
`Session ${sessionId} does not belong to user ${userId}.`
|
|
184
192
|
);
|
|
185
193
|
}
|
|
194
|
+
while (pageToken) {
|
|
195
|
+
const eventsRes = await this.sessions.events.listInternal({
|
|
196
|
+
name: sessionResourceName,
|
|
197
|
+
config: {
|
|
198
|
+
...listConfig,
|
|
199
|
+
pageToken
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
eventsIterator.push(...eventsRes.sessionEvents || []);
|
|
203
|
+
pageToken = eventsRes.nextPageToken;
|
|
204
|
+
}
|
|
186
205
|
const session = createSession({
|
|
187
206
|
id: sessionId,
|
|
188
207
|
appName,
|
|
189
208
|
userId,
|
|
190
|
-
state: sessionObj.sessionState,
|
|
209
|
+
state: toStateMap(sessionObj.sessionState),
|
|
191
210
|
events: [],
|
|
192
211
|
lastUpdateTime: sessionObj.updateTime ? Date.parse(sessionObj.updateTime) : Date.now()
|
|
193
212
|
});
|
|
194
|
-
|
|
213
|
+
const recentEvents = config && config.numRecentEvents ? eventsIterator.slice(-config.numRecentEvents) : eventsIterator;
|
|
214
|
+
for (const event of recentEvents) {
|
|
195
215
|
session.events.push(_fromApiEvent(event));
|
|
196
216
|
}
|
|
197
|
-
if (config && config.numRecentEvents) {
|
|
198
|
-
session.events = session.events.slice(-config.numRecentEvents);
|
|
199
|
-
}
|
|
200
217
|
return session;
|
|
201
218
|
} catch (error) {
|
|
202
219
|
const err = error;
|
|
@@ -235,7 +252,7 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
235
252
|
id,
|
|
236
253
|
appName,
|
|
237
254
|
userId: sessionObj.userId,
|
|
238
|
-
state: sessionObj.sessionState,
|
|
255
|
+
state: toStateMap(sessionObj.sessionState),
|
|
239
256
|
events: [],
|
|
240
257
|
lastUpdateTime: sessionObj.updateTime ? new Date(sessionObj.updateTime).getTime() : Date.now()
|
|
241
258
|
})
|
|
@@ -481,7 +498,9 @@ function _fromApiEvent(apiEventObj) {
|
|
|
481
498
|
}
|
|
482
499
|
}
|
|
483
500
|
const eventActions = {
|
|
484
|
-
stateDelta:
|
|
501
|
+
stateDelta: toStateMap(
|
|
502
|
+
actions["stateDelta"]
|
|
503
|
+
),
|
|
485
504
|
artifactDelta: actions["artifactDelta"] || {},
|
|
486
505
|
requestedAuthConfigs: actions.requestedAuthConfigs || {},
|
|
487
506
|
requestedToolConfirmations: actions["requestedToolConfirmations"] || {},
|
|
@@ -9,21 +9,46 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
9
9
|
*/
|
|
10
10
|
import { context, trace } from "@opentelemetry/api";
|
|
11
11
|
import { version } from "../version.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
var GenAiAttr = /* @__PURE__ */ ((GenAiAttr2) => {
|
|
13
|
+
GenAiAttr2["AGENT_DESCRIPTION"] = "gen_ai.agent.description";
|
|
14
|
+
GenAiAttr2["AGENT_NAME"] = "gen_ai.agent.name";
|
|
15
|
+
GenAiAttr2["CONVERSATION_ID"] = "gen_ai.conversation.id";
|
|
16
|
+
GenAiAttr2["OPERATION_NAME"] = "gen_ai.operation.name";
|
|
17
|
+
GenAiAttr2["SYSTEM"] = "gen_ai.system";
|
|
18
|
+
GenAiAttr2["TOOL_CALL_ID"] = "gen_ai.tool.call.id";
|
|
19
|
+
GenAiAttr2["TOOL_DESCRIPTION"] = "gen_ai.tool.description";
|
|
20
|
+
GenAiAttr2["TOOL_NAME"] = "gen_ai.tool.name";
|
|
21
|
+
GenAiAttr2["TOOL_TYPE"] = "gen_ai.tool.type";
|
|
22
|
+
GenAiAttr2["REQUEST_MODEL"] = "gen_ai.request.model";
|
|
23
|
+
GenAiAttr2["REQUEST_TOP_P"] = "gen_ai.request.top_p";
|
|
24
|
+
GenAiAttr2["REQUEST_MAX_TOKENS"] = "gen_ai.request.max_tokens";
|
|
25
|
+
GenAiAttr2["USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
|
|
26
|
+
GenAiAttr2["USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
|
|
27
|
+
GenAiAttr2["RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
|
|
28
|
+
return GenAiAttr2;
|
|
29
|
+
})(GenAiAttr || {});
|
|
30
|
+
var AdkAttr = /* @__PURE__ */ ((AdkAttr2) => {
|
|
31
|
+
AdkAttr2["WORKFLOW_NAME"] = "adk.workflow.name";
|
|
32
|
+
AdkAttr2["NODE_PATH"] = "adk.node.path";
|
|
33
|
+
AdkAttr2["NODE_RUN_ID"] = "adk.node.run_id";
|
|
34
|
+
AdkAttr2["NODE_ATTEMPT"] = "adk.node.attempt";
|
|
35
|
+
AdkAttr2["NODE_STATUS"] = "adk.node.status";
|
|
36
|
+
AdkAttr2["NODE_INTERRUPT_COUNT"] = "adk.node.interrupt_count";
|
|
37
|
+
return AdkAttr2;
|
|
38
|
+
})(AdkAttr || {});
|
|
39
|
+
var GcpAttr = /* @__PURE__ */ ((GcpAttr2) => {
|
|
40
|
+
GcpAttr2["INVOCATION_ID"] = "gcp.vertex.agent.invocation_id";
|
|
41
|
+
GcpAttr2["SESSION_ID"] = "gcp.vertex.agent.session_id";
|
|
42
|
+
GcpAttr2["EVENT_ID"] = "gcp.vertex.agent.event_id";
|
|
43
|
+
GcpAttr2["LLM_REQUEST"] = "gcp.vertex.agent.llm_request";
|
|
44
|
+
GcpAttr2["LLM_RESPONSE"] = "gcp.vertex.agent.llm_response";
|
|
45
|
+
GcpAttr2["TOOL_CALL_ARGS"] = "gcp.vertex.agent.tool_call_args";
|
|
46
|
+
GcpAttr2["TOOL_RESPONSE"] = "gcp.vertex.agent.tool_response";
|
|
47
|
+
GcpAttr2["DATA"] = "gcp.vertex.agent.data";
|
|
48
|
+
return GcpAttr2;
|
|
49
|
+
})(GcpAttr || {});
|
|
50
|
+
const GEN_AI_SYSTEM_VALUE = "gcp.vertex.agent";
|
|
51
|
+
const tracer = trace.getTracer(GEN_AI_SYSTEM_VALUE, version);
|
|
27
52
|
function safeJsonSerialize(obj) {
|
|
28
53
|
try {
|
|
29
54
|
return JSON.stringify(obj);
|
|
@@ -39,11 +64,11 @@ function traceAgentInvocation({
|
|
|
39
64
|
const span = trace.getActiveSpan();
|
|
40
65
|
if (!span) return;
|
|
41
66
|
span.setAttributes({
|
|
42
|
-
[
|
|
67
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_agent",
|
|
43
68
|
// Conditionally Required
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
[
|
|
69
|
+
["gen_ai.agent.description" /* AGENT_DESCRIPTION */]: agent.description,
|
|
70
|
+
["gen_ai.agent.name" /* AGENT_NAME */]: agent.name,
|
|
71
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: invocationContext.session.id
|
|
47
72
|
});
|
|
48
73
|
}
|
|
49
74
|
__name(traceAgentInvocation, "traceAgentInvocation");
|
|
@@ -55,10 +80,10 @@ function traceWorkflowInvocation({
|
|
|
55
80
|
const span = trace.getActiveSpan();
|
|
56
81
|
if (!span) return;
|
|
57
82
|
span.setAttributes({
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
83
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_workflow",
|
|
84
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: sessionId,
|
|
85
|
+
["adk.workflow.name" /* WORKFLOW_NAME */]: workflowName,
|
|
86
|
+
["adk.node.path" /* NODE_PATH */]: nodePath
|
|
62
87
|
});
|
|
63
88
|
}
|
|
64
89
|
__name(traceWorkflowInvocation, "traceWorkflowInvocation");
|
|
@@ -72,34 +97,37 @@ function traceNodeExecution({
|
|
|
72
97
|
const span = trace.getActiveSpan();
|
|
73
98
|
if (!span) return;
|
|
74
99
|
span.setAttributes({
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
100
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_node",
|
|
101
|
+
["adk.node.path" /* NODE_PATH */]: nodePath,
|
|
102
|
+
["adk.node.run_id" /* NODE_RUN_ID */]: runId,
|
|
103
|
+
["adk.node.attempt" /* NODE_ATTEMPT */]: attempt,
|
|
104
|
+
["adk.node.status" /* NODE_STATUS */]: status,
|
|
105
|
+
["adk.node.interrupt_count" /* NODE_INTERRUPT_COUNT */]: interruptCount
|
|
81
106
|
});
|
|
82
107
|
}
|
|
83
108
|
__name(traceNodeExecution, "traceNodeExecution");
|
|
84
109
|
function traceToolCall({
|
|
85
110
|
tool,
|
|
86
111
|
args,
|
|
87
|
-
functionResponseEvent
|
|
112
|
+
functionResponseEvent,
|
|
113
|
+
invocationContext
|
|
88
114
|
}) {
|
|
89
115
|
var _a, _b;
|
|
90
116
|
const span = trace.getActiveSpan();
|
|
91
117
|
if (!span) return;
|
|
92
118
|
span.setAttributes({
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
119
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
120
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
121
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: tool.description || "",
|
|
122
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: tool.name,
|
|
96
123
|
// e.g. FunctionTool
|
|
97
|
-
[
|
|
124
|
+
["gen_ai.tool.type" /* TOOL_TYPE */]: tool.constructor.name,
|
|
125
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
98
126
|
// Setting empty llm request and response (as UI expect these) while not
|
|
99
127
|
// applicable for tool_response.
|
|
100
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
101
|
-
"gcp.vertex.agent.llm_response": "{}",
|
|
102
|
-
"gcp.vertex.agent.tool_call_args": shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
128
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
129
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}",
|
|
130
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
103
131
|
});
|
|
104
132
|
let toolCallId = "<not specified>";
|
|
105
133
|
let toolResponse = "<not specified>";
|
|
@@ -117,32 +145,35 @@ function traceToolCall({
|
|
|
117
145
|
toolResponse = { result: toolResponse };
|
|
118
146
|
}
|
|
119
147
|
span.setAttributes({
|
|
120
|
-
[
|
|
121
|
-
"gcp.vertex.agent.event_id": functionResponseEvent.id,
|
|
122
|
-
"gcp.vertex.agent.tool_response": shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
148
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: toolCallId,
|
|
149
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: functionResponseEvent.id,
|
|
150
|
+
["gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
123
151
|
});
|
|
124
152
|
}
|
|
125
153
|
__name(traceToolCall, "traceToolCall");
|
|
126
154
|
function traceMergedToolCalls({
|
|
127
155
|
responseEventId,
|
|
128
|
-
functionResponseEvent
|
|
156
|
+
functionResponseEvent,
|
|
157
|
+
invocationContext
|
|
129
158
|
}) {
|
|
130
159
|
const span = trace.getActiveSpan();
|
|
131
160
|
if (!span) return;
|
|
132
161
|
span.setAttributes({
|
|
133
|
-
[
|
|
134
|
-
[
|
|
135
|
-
[
|
|
136
|
-
[
|
|
137
|
-
"
|
|
138
|
-
"gcp.vertex.agent.
|
|
162
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
163
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
164
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: "(merged tools)",
|
|
165
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: "(merged tools)",
|
|
166
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: responseEventId,
|
|
167
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
168
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: "N/A",
|
|
169
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: responseEventId,
|
|
139
170
|
// Setting empty llm request and response (as UI expect these) while not
|
|
140
171
|
// applicable for tool_response.
|
|
141
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
142
|
-
"gcp.vertex.agent.llm_response": "{}"
|
|
172
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
173
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}"
|
|
143
174
|
});
|
|
144
175
|
span.setAttribute(
|
|
145
|
-
"gcp.vertex.agent.tool_response"
|
|
176
|
+
"gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */,
|
|
146
177
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}"
|
|
147
178
|
);
|
|
148
179
|
}
|
|
@@ -157,43 +188,43 @@ function traceCallLlm({
|
|
|
157
188
|
const span = trace.getActiveSpan();
|
|
158
189
|
if (!span) return;
|
|
159
190
|
span.setAttributes({
|
|
160
|
-
"gen_ai.system":
|
|
161
|
-
"gen_ai.request.model": llmRequest.model,
|
|
162
|
-
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { [
|
|
163
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
164
|
-
"gcp.vertex.agent.session_id": invocationContext.session.id,
|
|
165
|
-
"gcp.vertex.agent.event_id": eventId,
|
|
191
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
192
|
+
["gen_ai.request.model" /* REQUEST_MODEL */]: llmRequest.model,
|
|
193
|
+
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { ["gen_ai.agent.name" /* AGENT_NAME */]: invocationContext.agent.name } : {},
|
|
194
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
195
|
+
["gcp.vertex.agent.session_id" /* SESSION_ID */]: invocationContext.session.id,
|
|
196
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId,
|
|
166
197
|
// Consider removing once GenAI SDK provides a way to record this info.
|
|
167
|
-
"gcp.vertex.agent.llm_request": shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
198
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
168
199
|
});
|
|
169
200
|
if ((_b = llmRequest.config) == null ? void 0 : _b.topP) {
|
|
170
|
-
span.setAttribute("gen_ai.request.top_p"
|
|
201
|
+
span.setAttribute("gen_ai.request.top_p" /* REQUEST_TOP_P */, llmRequest.config.topP);
|
|
171
202
|
}
|
|
172
203
|
if (((_c = llmRequest.config) == null ? void 0 : _c.maxOutputTokens) !== void 0) {
|
|
173
204
|
span.setAttribute(
|
|
174
|
-
"gen_ai.request.max_tokens"
|
|
205
|
+
"gen_ai.request.max_tokens" /* REQUEST_MAX_TOKENS */,
|
|
175
206
|
llmRequest.config.maxOutputTokens
|
|
176
207
|
);
|
|
177
208
|
}
|
|
178
209
|
span.setAttribute(
|
|
179
|
-
"gcp.vertex.agent.llm_response"
|
|
210
|
+
"gcp.vertex.agent.llm_response" /* LLM_RESPONSE */,
|
|
180
211
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}"
|
|
181
212
|
);
|
|
182
213
|
if (llmResponse.usageMetadata) {
|
|
183
214
|
span.setAttribute(
|
|
184
|
-
"gen_ai.usage.input_tokens"
|
|
215
|
+
"gen_ai.usage.input_tokens" /* USAGE_INPUT_TOKENS */,
|
|
185
216
|
llmResponse.usageMetadata.promptTokenCount || 0
|
|
186
217
|
);
|
|
187
218
|
}
|
|
188
219
|
if ((_d = llmResponse.usageMetadata) == null ? void 0 : _d.candidatesTokenCount) {
|
|
189
220
|
span.setAttribute(
|
|
190
|
-
"gen_ai.usage.output_tokens"
|
|
221
|
+
"gen_ai.usage.output_tokens" /* USAGE_OUTPUT_TOKENS */,
|
|
191
222
|
llmResponse.usageMetadata.candidatesTokenCount
|
|
192
223
|
);
|
|
193
224
|
}
|
|
194
225
|
if (llmResponse.finishReason) {
|
|
195
226
|
const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
|
|
196
|
-
span.setAttribute("gen_ai.response.finish_reasons"
|
|
227
|
+
span.setAttribute("gen_ai.response.finish_reasons" /* RESPONSE_FINISH_REASONS */, [finishReasonValue]);
|
|
197
228
|
}
|
|
198
229
|
}
|
|
199
230
|
__name(traceCallLlm, "traceCallLlm");
|
|
@@ -205,11 +236,11 @@ function traceSendData({
|
|
|
205
236
|
const span = trace.getActiveSpan();
|
|
206
237
|
if (!span) return;
|
|
207
238
|
span.setAttributes({
|
|
208
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
209
|
-
"gcp.vertex.agent.event_id": eventId
|
|
239
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
240
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId
|
|
210
241
|
});
|
|
211
242
|
span.setAttribute(
|
|
212
|
-
"gcp.vertex.agent.data"
|
|
243
|
+
"gcp.vertex.agent.data" /* DATA */,
|
|
213
244
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}"
|
|
214
245
|
);
|
|
215
246
|
}
|
|
@@ -17,6 +17,44 @@ import { GoogleLLMVariant } from "../utils/variant_utils.js";
|
|
|
17
17
|
import { State } from "../sessions/state.js";
|
|
18
18
|
import { BaseTool } from "./base_tool.js";
|
|
19
19
|
import { ForwardingArtifactService } from "./forwarding_artifact_service.js";
|
|
20
|
+
import { parseWithSchema } from "../utils/schema.js";
|
|
21
|
+
import { isZodSchema } from "../utils/simple_zod_to_json.js";
|
|
22
|
+
function excludeNone(value) {
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
return value.map((item) => excludeNone(item));
|
|
25
|
+
}
|
|
26
|
+
if (value !== null && typeof value === "object") {
|
|
27
|
+
const result = {};
|
|
28
|
+
for (const [key, val] of Object.entries(value)) {
|
|
29
|
+
if (val !== null && val !== void 0) {
|
|
30
|
+
result[key] = excludeNone(val);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
__name(excludeNone, "excludeNone");
|
|
38
|
+
function validateAndStripAgentInput(agent, args) {
|
|
39
|
+
var _a2;
|
|
40
|
+
if (typeof args !== "object" || args === null || Array.isArray(args)) {
|
|
41
|
+
throw new Error("AgentTool input args must be a plain object.");
|
|
42
|
+
}
|
|
43
|
+
const schema = isZodSchema(agent.inputSchema) ? agent.inputSchema : (_a2 = agent.inputSchemaSource) != null ? _a2 : agent.inputSchema;
|
|
44
|
+
const validated = parseWithSchema(schema, args);
|
|
45
|
+
return excludeNone(validated);
|
|
46
|
+
}
|
|
47
|
+
__name(validateAndStripAgentInput, "validateAndStripAgentInput");
|
|
48
|
+
function validateAndStripAgentOutput(agent, mergedText) {
|
|
49
|
+
var _a2;
|
|
50
|
+
const parsed = JSON.parse(mergedText);
|
|
51
|
+
const validated = typeof agent.validateOutput === "function" ? agent.validateOutput(parsed) : parseWithSchema(
|
|
52
|
+
isZodSchema(agent.outputSchema) ? agent.outputSchema : (_a2 = agent.outputSchemaSource) != null ? _a2 : agent.outputSchema,
|
|
53
|
+
parsed
|
|
54
|
+
);
|
|
55
|
+
return excludeNone(validated);
|
|
56
|
+
}
|
|
57
|
+
__name(validateAndStripAgentOutput, "validateAndStripAgentOutput");
|
|
20
58
|
const AGENT_TOOL_SIGNATURE_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.agentTool");
|
|
21
59
|
function isAgentTool(obj) {
|
|
22
60
|
return typeof obj === "object" && obj !== null && AGENT_TOOL_SIGNATURE_SYMBOL in obj && obj[AGENT_TOOL_SIGNATURE_SYMBOL] === true;
|
|
@@ -70,6 +108,9 @@ const _AgentTool = class _AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGN
|
|
|
70
108
|
}) {
|
|
71
109
|
var _a2, _b2, _c, _d, _e, _f;
|
|
72
110
|
const hasInputSchema = isLlmAgent(this.agent) && this.agent.inputSchema;
|
|
111
|
+
if (hasInputSchema && isLlmAgent(this.agent)) {
|
|
112
|
+
args = validateAndStripAgentInput(this.agent, args);
|
|
113
|
+
}
|
|
73
114
|
const content = {
|
|
74
115
|
role: "user",
|
|
75
116
|
parts: [
|
|
@@ -124,6 +165,9 @@ const _AgentTool = class _AgentTool extends (_b = BaseTool, _a = AGENT_TOOL_SIGN
|
|
|
124
165
|
}
|
|
125
166
|
const hasOutputSchema = isLlmAgent(this.agent) && this.agent.outputSchema;
|
|
126
167
|
const mergedText = lastEvent.content.parts.filter((part) => !part.thought).map((part) => part.text).filter((text) => text).join("\n");
|
|
168
|
+
if (hasOutputSchema && isLlmAgent(this.agent)) {
|
|
169
|
+
return validateAndStripAgentOutput(this.agent, mergedText);
|
|
170
|
+
}
|
|
127
171
|
return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
|
|
128
172
|
}
|
|
129
173
|
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
7
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
8
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
9
|
+
if (decorator = decorators[i])
|
|
10
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
11
|
+
if (kind && result) __defProp(target, key, result);
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @license
|
|
16
|
+
* Copyright 2026 Google LLC
|
|
17
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
*/
|
|
19
|
+
import yaml from "js-yaml";
|
|
20
|
+
import { toSnakeCaseName } from "../../utils/case_utils.js";
|
|
21
|
+
import { experimental } from "../../utils/experimental.js";
|
|
22
|
+
import { BaseToolset } from "../base_toolset.js";
|
|
23
|
+
import { OpenAPIToolset } from "../openapi_tool/openapi_toolset.js";
|
|
24
|
+
import { APIHubClient } from "./clients/apihub_client.js";
|
|
25
|
+
let APIHubToolset = class extends BaseToolset {
|
|
26
|
+
constructor(options) {
|
|
27
|
+
var _a, _b, _c, _d;
|
|
28
|
+
super([]);
|
|
29
|
+
this.name = (_a = options.name) != null ? _a : "";
|
|
30
|
+
this.description = (_b = options.description) != null ? _b : "";
|
|
31
|
+
this.apihubResourceName = options.apihubResourceName;
|
|
32
|
+
this.lazyLoadSpec = (_c = options.lazyLoadSpec) != null ? _c : false;
|
|
33
|
+
this.authScheme = options.authScheme;
|
|
34
|
+
this.authCredential = options.authCredential;
|
|
35
|
+
this.apihubClient = (_d = options.apihubClient) != null ? _d : new APIHubClient({
|
|
36
|
+
accessToken: options.accessToken,
|
|
37
|
+
serviceAccountJson: options.serviceAccountJson
|
|
38
|
+
});
|
|
39
|
+
if (!this.lazyLoadSpec) {
|
|
40
|
+
this.toolsetPromise = this.prepareTools();
|
|
41
|
+
this.toolsetPromise.catch(() => void 0);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns one tool per operation in the spec, or an empty array when the
|
|
46
|
+
* spec is empty.
|
|
47
|
+
*
|
|
48
|
+
* @throws When the spec cannot be fetched or is not valid YAML or JSON.
|
|
49
|
+
*/
|
|
50
|
+
async getTools(context) {
|
|
51
|
+
const toolset = await this.loadToolset();
|
|
52
|
+
return toolset ? toolset.getTools(context) : [];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the tool with the given name, or `undefined` when the spec
|
|
56
|
+
* produced no such tool.
|
|
57
|
+
*
|
|
58
|
+
* Unlike `OpenAPIToolset.getTool`, the result is a Promise, because the spec
|
|
59
|
+
* may still be loading.
|
|
60
|
+
*
|
|
61
|
+
* @param name The tool name, which is the operation ID in snake_case.
|
|
62
|
+
* @throws When the spec cannot be fetched or is not valid YAML or JSON.
|
|
63
|
+
*/
|
|
64
|
+
async getTool(name) {
|
|
65
|
+
const toolset = await this.loadToolset();
|
|
66
|
+
return toolset == null ? void 0 : toolset.getTool(name);
|
|
67
|
+
}
|
|
68
|
+
async close() {
|
|
69
|
+
}
|
|
70
|
+
loadToolset() {
|
|
71
|
+
if (!this.toolsetPromise) {
|
|
72
|
+
const promise = this.prepareTools();
|
|
73
|
+
this.toolsetPromise = promise;
|
|
74
|
+
promise.catch(() => {
|
|
75
|
+
if (this.toolsetPromise === promise) {
|
|
76
|
+
this.toolsetPromise = void 0;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return this.toolsetPromise;
|
|
81
|
+
}
|
|
82
|
+
async prepareTools() {
|
|
83
|
+
var _a, _b, _c, _d;
|
|
84
|
+
const spec = await this.apihubClient.getSpecContent(
|
|
85
|
+
this.apihubResourceName
|
|
86
|
+
);
|
|
87
|
+
const specDict = yaml.load(spec);
|
|
88
|
+
if (!specDict) {
|
|
89
|
+
return void 0;
|
|
90
|
+
}
|
|
91
|
+
this.name || (this.name = toSnakeCaseName((_b = (_a = specDict.info) == null ? void 0 : _a.title) != null ? _b : "unnamed"));
|
|
92
|
+
this.description || (this.description = (_d = (_c = specDict.info) == null ? void 0 : _c.description) != null ? _d : "");
|
|
93
|
+
return new OpenAPIToolset({
|
|
94
|
+
specDict,
|
|
95
|
+
authScheme: this.authScheme,
|
|
96
|
+
authCredential: this.authCredential
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
__name(APIHubToolset, "APIHubToolset");
|
|
101
|
+
APIHubToolset = __decorateClass([
|
|
102
|
+
experimental
|
|
103
|
+
], APIHubToolset);
|
|
104
|
+
export {
|
|
105
|
+
APIHubToolset
|
|
106
|
+
};
|