@paean-ai/adk 0.2.19 → 0.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/active_streaming_tool.js +44 -0
- package/dist/cjs/agents/base_agent.js +245 -0
- package/dist/cjs/agents/base_llm_processor.js +44 -0
- package/dist/cjs/agents/callback_context.js +98 -0
- package/dist/cjs/agents/content_processor_utils.js +311 -0
- package/dist/cjs/agents/functions.js +425 -0
- package/dist/cjs/agents/instructions.js +110 -0
- package/dist/cjs/agents/invocation_context.js +107 -0
- package/dist/cjs/agents/live_request_queue.js +136 -0
- package/dist/cjs/agents/llm_agent.js +1279 -0
- package/dist/cjs/agents/loop_agent.js +68 -0
- package/dist/cjs/agents/parallel_agent.js +78 -0
- package/dist/cjs/agents/readonly_context.js +68 -0
- package/dist/cjs/agents/run_config.js +70 -0
- package/dist/cjs/agents/sequential_agent.js +84 -0
- package/dist/cjs/agents/transcription_entry.js +27 -0
- package/dist/cjs/artifacts/base_artifact_service.js +27 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +140 -0
- package/dist/cjs/artifacts/in_memory_artifact_service.js +119 -0
- package/dist/cjs/auth/auth_credential.js +46 -0
- package/dist/cjs/auth/auth_handler.js +92 -0
- package/dist/cjs/auth/auth_schemes.js +62 -0
- package/dist/cjs/auth/auth_tool.js +27 -0
- package/dist/cjs/auth/credential_service/base_credential_service.js +27 -0
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +63 -0
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +40 -0
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +59 -0
- package/dist/cjs/code_executors/base_code_executor.js +76 -0
- package/dist/cjs/code_executors/built_in_code_executor.js +58 -0
- package/dist/cjs/code_executors/code_execution_utils.js +142 -0
- package/dist/cjs/code_executors/code_executor_context.js +198 -0
- package/dist/cjs/common.js +181 -0
- package/dist/cjs/events/event.js +119 -0
- package/dist/cjs/events/event_actions.js +83 -0
- package/dist/cjs/examples/base_example_provider.js +40 -0
- package/dist/cjs/examples/example.js +27 -0
- package/dist/cjs/examples/example_util.js +107 -0
- package/dist/cjs/index.js +12 -12
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/index_web.js +33 -0
- package/dist/cjs/memory/base_memory_service.js +27 -0
- package/dist/cjs/memory/in_memory_memory_service.js +97 -0
- package/dist/cjs/memory/memory_entry.js +27 -0
- package/dist/cjs/models/base_llm.js +95 -0
- package/dist/cjs/models/base_llm_connection.js +27 -0
- package/dist/cjs/models/gemini_llm_connection.js +132 -0
- package/dist/cjs/models/google_llm.js +472 -0
- package/dist/cjs/models/llm_request.js +82 -0
- package/dist/cjs/models/llm_response.js +71 -0
- package/dist/cjs/models/registry.js +121 -0
- package/dist/cjs/plugins/base_plugin.js +236 -0
- package/dist/cjs/plugins/logging_plugin.js +222 -0
- package/dist/cjs/plugins/plugin_manager.js +239 -0
- package/dist/cjs/plugins/security_plugin.js +153 -0
- package/dist/cjs/runner/in_memory_runner.js +58 -0
- package/dist/cjs/runner/runner.js +277 -0
- package/dist/cjs/sessions/base_session_service.js +71 -0
- package/dist/cjs/sessions/in_memory_session_service.js +184 -0
- package/dist/cjs/sessions/session.js +48 -0
- package/dist/cjs/sessions/state.js +101 -0
- package/dist/cjs/telemetry/google_cloud.js +85 -0
- package/dist/cjs/telemetry/setup.js +97 -0
- package/dist/cjs/telemetry/tracing.js +231 -0
- package/dist/cjs/tools/agent_tool.js +134 -0
- package/dist/cjs/tools/base_tool.js +107 -0
- package/dist/cjs/tools/base_toolset.js +76 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +71 -0
- package/dist/cjs/tools/function_tool.js +101 -0
- package/dist/cjs/tools/google_search_tool.js +77 -0
- package/dist/cjs/tools/long_running_tool.js +63 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +65 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +65 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +61 -0
- package/dist/cjs/tools/tool_confirmation.js +49 -0
- package/dist/cjs/tools/tool_context.js +129 -0
- package/dist/cjs/utils/client_labels.js +56 -0
- package/dist/cjs/utils/deep_clone.js +44 -0
- package/dist/cjs/utils/env_aware_utils.js +83 -0
- package/dist/cjs/utils/gemini_schema_util.js +88 -0
- package/dist/cjs/utils/logger.js +121 -0
- package/dist/cjs/utils/model_name.js +76 -0
- package/dist/cjs/utils/simple_zod_to_json.js +191 -0
- package/dist/cjs/utils/variant_utils.js +55 -0
- package/dist/cjs/version.js +39 -0
- package/dist/esm/agents/active_streaming_tool.js +14 -0
- package/dist/esm/agents/base_agent.js +214 -0
- package/dist/esm/agents/base_llm_processor.js +13 -0
- package/dist/esm/agents/callback_context.js +68 -0
- package/dist/esm/agents/content_processor_utils.js +280 -0
- package/dist/esm/agents/functions.js +384 -0
- package/dist/esm/agents/instructions.js +80 -0
- package/dist/esm/agents/invocation_context.js +76 -0
- package/dist/esm/agents/live_request_queue.js +106 -0
- package/dist/esm/agents/llm_agent.js +1247 -0
- package/dist/esm/agents/loop_agent.js +38 -0
- package/dist/esm/agents/parallel_agent.js +48 -0
- package/dist/esm/agents/readonly_context.js +38 -0
- package/dist/esm/agents/run_config.js +39 -0
- package/dist/esm/agents/sequential_agent.js +54 -0
- package/dist/esm/agents/transcription_entry.js +5 -0
- package/dist/esm/artifacts/base_artifact_service.js +5 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +110 -0
- package/dist/esm/artifacts/in_memory_artifact_service.js +89 -0
- package/dist/esm/auth/auth_credential.js +16 -0
- package/dist/esm/auth/auth_handler.js +62 -0
- package/dist/esm/auth/auth_schemes.js +31 -0
- package/dist/esm/auth/auth_tool.js +5 -0
- package/dist/esm/auth/credential_service/base_credential_service.js +5 -0
- package/dist/esm/auth/credential_service/in_memory_credential_service.js +33 -0
- package/dist/esm/auth/exchanger/base_credential_exchanger.js +10 -0
- package/dist/esm/auth/exchanger/credential_exchanger_registry.js +29 -0
- package/dist/esm/code_executors/base_code_executor.js +46 -0
- package/dist/esm/code_executors/built_in_code_executor.js +28 -0
- package/dist/esm/code_executors/code_execution_utils.js +108 -0
- package/dist/esm/code_executors/code_executor_context.js +168 -0
- package/dist/esm/common.js +98 -0
- package/dist/esm/events/event.js +83 -0
- package/dist/esm/events/event_actions.js +52 -0
- package/dist/esm/examples/base_example_provider.js +10 -0
- package/dist/esm/examples/example.js +5 -0
- package/dist/esm/examples/example_util.js +76 -0
- package/dist/esm/index.js +12 -12
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/index_web.js +6 -0
- package/dist/esm/memory/base_memory_service.js +5 -0
- package/dist/esm/memory/in_memory_memory_service.js +67 -0
- package/dist/esm/memory/memory_entry.js +5 -0
- package/dist/esm/models/base_llm.js +64 -0
- package/dist/esm/models/base_llm_connection.js +5 -0
- package/dist/esm/models/gemini_llm_connection.js +102 -0
- package/dist/esm/models/google_llm.js +446 -0
- package/dist/esm/models/llm_request.js +50 -0
- package/dist/esm/models/llm_response.js +41 -0
- package/dist/esm/models/registry.js +91 -0
- package/dist/esm/plugins/base_plugin.js +206 -0
- package/dist/esm/plugins/logging_plugin.js +192 -0
- package/dist/esm/plugins/plugin_manager.js +209 -0
- package/dist/esm/plugins/security_plugin.js +119 -0
- package/dist/esm/runner/in_memory_runner.js +28 -0
- package/dist/esm/runner/runner.js +247 -0
- package/dist/esm/sessions/base_session_service.js +41 -0
- package/dist/esm/sessions/in_memory_session_service.js +154 -0
- package/dist/esm/sessions/session.js +18 -0
- package/dist/esm/sessions/state.js +71 -0
- package/dist/esm/telemetry/google_cloud.js +54 -0
- package/dist/esm/telemetry/setup.js +67 -0
- package/dist/esm/telemetry/tracing.js +195 -0
- package/dist/esm/tools/agent_tool.js +104 -0
- package/dist/esm/tools/base_tool.js +77 -0
- package/dist/esm/tools/base_toolset.js +46 -0
- package/dist/esm/tools/forwarding_artifact_service.js +41 -0
- package/dist/esm/tools/function_tool.js +71 -0
- package/dist/esm/tools/google_search_tool.js +47 -0
- package/dist/esm/tools/long_running_tool.js +33 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +35 -0
- package/dist/esm/tools/mcp/mcp_tool.js +35 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +31 -0
- package/dist/esm/tools/tool_confirmation.js +19 -0
- package/dist/esm/tools/tool_context.js +99 -0
- package/dist/esm/utils/client_labels.js +26 -0
- package/dist/esm/utils/deep_clone.js +14 -0
- package/dist/esm/utils/env_aware_utils.js +49 -0
- package/dist/esm/utils/gemini_schema_util.js +58 -0
- package/dist/esm/utils/logger.js +89 -0
- package/dist/esm/utils/model_name.js +41 -0
- package/dist/esm/utils/simple_zod_to_json.js +160 -0
- package/dist/esm/utils/variant_utils.js +24 -0
- package/dist/esm/version.js +9 -0
- package/dist/types/agents/llm_agent.d.ts +1 -0
- package/dist/types/models/google_llm.d.ts +0 -7
- package/dist/web/agents/active_streaming_tool.js +14 -0
- package/dist/web/agents/base_agent.js +265 -0
- package/dist/web/agents/base_llm_processor.js +13 -0
- package/dist/web/agents/callback_context.js +68 -0
- package/dist/web/agents/content_processor_utils.js +280 -0
- package/dist/web/agents/functions.js +384 -0
- package/dist/web/agents/instructions.js +80 -0
- package/dist/web/agents/invocation_context.js +76 -0
- package/dist/web/agents/live_request_queue.js +124 -0
- package/dist/web/agents/llm_agent.js +1377 -0
- package/dist/web/agents/loop_agent.js +71 -0
- package/dist/web/agents/parallel_agent.js +83 -0
- package/dist/web/agents/readonly_context.js +38 -0
- package/dist/web/agents/run_config.js +54 -0
- package/dist/web/agents/sequential_agent.js +99 -0
- package/dist/web/agents/transcription_entry.js +5 -0
- package/dist/web/artifacts/base_artifact_service.js +5 -0
- package/dist/web/artifacts/gcs_artifact_service.js +126 -0
- package/dist/web/artifacts/in_memory_artifact_service.js +89 -0
- package/dist/web/auth/auth_credential.js +16 -0
- package/dist/web/auth/auth_handler.js +62 -0
- package/dist/web/auth/auth_schemes.js +31 -0
- package/dist/web/auth/auth_tool.js +5 -0
- package/dist/web/auth/credential_service/base_credential_service.js +5 -0
- package/dist/web/auth/credential_service/in_memory_credential_service.js +33 -0
- package/dist/web/auth/exchanger/base_credential_exchanger.js +10 -0
- package/dist/web/auth/exchanger/credential_exchanger_registry.js +29 -0
- package/dist/web/code_executors/base_code_executor.js +46 -0
- package/dist/web/code_executors/built_in_code_executor.js +28 -0
- package/dist/web/code_executors/code_execution_utils.js +105 -0
- package/dist/web/code_executors/code_executor_context.js +168 -0
- package/dist/web/common.js +98 -0
- package/dist/web/events/event.js +101 -0
- package/dist/web/events/event_actions.js +67 -0
- package/dist/web/examples/base_example_provider.js +10 -0
- package/dist/web/examples/example.js +5 -0
- package/dist/web/examples/example_util.js +75 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +3 -3
- package/dist/web/index_web.js +6 -0
- package/dist/web/memory/base_memory_service.js +5 -0
- package/dist/web/memory/in_memory_memory_service.js +67 -0
- package/dist/web/memory/memory_entry.js +5 -0
- package/dist/web/models/base_llm.js +64 -0
- package/dist/web/models/base_llm_connection.js +5 -0
- package/dist/web/models/gemini_llm_connection.js +120 -0
- package/dist/web/models/google_llm.js +487 -0
- package/dist/web/models/llm_request.js +50 -0
- package/dist/web/models/llm_response.js +41 -0
- package/dist/web/models/registry.js +91 -0
- package/dist/web/plugins/base_plugin.js +206 -0
- package/dist/web/plugins/logging_plugin.js +192 -0
- package/dist/web/plugins/plugin_manager.js +209 -0
- package/dist/web/plugins/security_plugin.js +119 -0
- package/dist/web/runner/in_memory_runner.js +28 -0
- package/dist/web/runner/runner.js +278 -0
- package/dist/web/sessions/base_session_service.js +41 -0
- package/dist/web/sessions/in_memory_session_service.js +154 -0
- package/dist/web/sessions/session.js +18 -0
- package/dist/web/sessions/state.js +87 -0
- package/dist/web/telemetry/google_cloud.js +54 -0
- package/dist/web/telemetry/setup.js +67 -0
- package/dist/web/telemetry/tracing.js +210 -0
- package/dist/web/tools/agent_tool.js +118 -0
- package/dist/web/tools/base_tool.js +77 -0
- package/dist/web/tools/base_toolset.js +46 -0
- package/dist/web/tools/forwarding_artifact_service.js +41 -0
- package/dist/web/tools/function_tool.js +71 -0
- package/dist/web/tools/google_search_tool.js +47 -0
- package/dist/web/tools/long_running_tool.js +50 -0
- package/dist/web/tools/mcp/mcp_session_manager.js +35 -0
- package/dist/web/tools/mcp/mcp_tool.js +35 -0
- package/dist/web/tools/mcp/mcp_toolset.js +31 -0
- package/dist/web/tools/tool_confirmation.js +19 -0
- package/dist/web/tools/tool_context.js +99 -0
- package/dist/web/utils/client_labels.js +26 -0
- package/dist/web/utils/deep_clone.js +14 -0
- package/dist/web/utils/env_aware_utils.js +49 -0
- package/dist/web/utils/gemini_schema_util.js +58 -0
- package/dist/web/utils/logger.js +89 -0
- package/dist/web/utils/model_name.js +41 -0
- package/dist/web/utils/simple_zod_to_json.js +174 -0
- package/dist/web/utils/variant_utils.js +24 -0
- package/dist/web/version.js +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var google_cloud_exports = {};
|
|
26
|
+
__export(google_cloud_exports, {
|
|
27
|
+
getGcpExporters: () => getGcpExporters,
|
|
28
|
+
getGcpResource: () => getGcpResource
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(google_cloud_exports);
|
|
31
|
+
var import_google_auth_library = require("google-auth-library");
|
|
32
|
+
var import_sdk_metrics = require("@opentelemetry/sdk-metrics");
|
|
33
|
+
var import_resources = require("@opentelemetry/resources");
|
|
34
|
+
var import_resource_detector_gcp = require("@opentelemetry/resource-detector-gcp");
|
|
35
|
+
var import_opentelemetry_cloud_trace_exporter = require("@google-cloud/opentelemetry-cloud-trace-exporter");
|
|
36
|
+
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
37
|
+
var import_opentelemetry_cloud_monitoring_exporter = require("@google-cloud/opentelemetry-cloud-monitoring-exporter");
|
|
38
|
+
var import_logger = require("../utils/logger.js");
|
|
39
|
+
/**
|
|
40
|
+
* @license
|
|
41
|
+
* Copyright 2025 Google LLC
|
|
42
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
43
|
+
*/
|
|
44
|
+
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.";
|
|
45
|
+
async function getGcpProjectId() {
|
|
46
|
+
try {
|
|
47
|
+
const auth = new import_google_auth_library.GoogleAuth();
|
|
48
|
+
const projectId = await auth.getProjectId();
|
|
49
|
+
return projectId || void 0;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function getGcpExporters(config = {}) {
|
|
55
|
+
const {
|
|
56
|
+
enableTracing = false,
|
|
57
|
+
enableMetrics = false
|
|
58
|
+
// enableCloudLogging = false,
|
|
59
|
+
} = config;
|
|
60
|
+
const projectId = await getGcpProjectId();
|
|
61
|
+
if (!projectId) {
|
|
62
|
+
import_logger.logger.warn(GCP_PROJECT_ERROR_MESSAGE);
|
|
63
|
+
return {};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
spanProcessors: enableTracing ? [
|
|
67
|
+
new import_sdk_trace_base.BatchSpanProcessor(new import_opentelemetry_cloud_trace_exporter.TraceExporter({ projectId }))
|
|
68
|
+
] : [],
|
|
69
|
+
metricReaders: enableMetrics ? [
|
|
70
|
+
new import_sdk_metrics.PeriodicExportingMetricReader({
|
|
71
|
+
exporter: new import_opentelemetry_cloud_monitoring_exporter.MetricExporter({ projectId }),
|
|
72
|
+
exportIntervalMillis: 5e3
|
|
73
|
+
})
|
|
74
|
+
] : [],
|
|
75
|
+
logRecordProcessors: []
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function getGcpResource() {
|
|
79
|
+
return (0, import_resources.detectResources)({ detectors: [import_resource_detector_gcp.gcpDetector] });
|
|
80
|
+
}
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
getGcpExporters,
|
|
84
|
+
getGcpResource
|
|
85
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var setup_exports = {};
|
|
26
|
+
__export(setup_exports, {
|
|
27
|
+
maybeSetOtelProviders: () => maybeSetOtelProviders
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(setup_exports);
|
|
30
|
+
var import_api = require("@opentelemetry/api");
|
|
31
|
+
var import_api_logs = require("@opentelemetry/api-logs");
|
|
32
|
+
var import_sdk_logs = require("@opentelemetry/sdk-logs");
|
|
33
|
+
var import_sdk_metrics = require("@opentelemetry/sdk-metrics");
|
|
34
|
+
var import_resources = require("@opentelemetry/resources");
|
|
35
|
+
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
36
|
+
var import_sdk_trace_node = require("@opentelemetry/sdk-trace-node");
|
|
37
|
+
var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
|
|
38
|
+
var import_exporter_metrics_otlp_http = require("@opentelemetry/exporter-metrics-otlp-http");
|
|
39
|
+
var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-http");
|
|
40
|
+
/**
|
|
41
|
+
* @license
|
|
42
|
+
* Copyright 2025 Google LLC
|
|
43
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
44
|
+
*/
|
|
45
|
+
function maybeSetOtelProviders(otelHooksToSetup = [], otelResource) {
|
|
46
|
+
const resource = otelResource || getOtelResource();
|
|
47
|
+
const allHooks = [...otelHooksToSetup, getOtelExporters()];
|
|
48
|
+
const spanProcessors = allHooks.flatMap((hooks) => hooks.spanProcessors || []);
|
|
49
|
+
const metricReaders = allHooks.flatMap((hooks) => hooks.metricReaders || []);
|
|
50
|
+
const logRecordProcessors = allHooks.flatMap((hooks) => hooks.logRecordProcessors || []);
|
|
51
|
+
if (spanProcessors.length > 0) {
|
|
52
|
+
const tracerProvider = new import_sdk_trace_node.NodeTracerProvider({
|
|
53
|
+
resource,
|
|
54
|
+
spanProcessors
|
|
55
|
+
});
|
|
56
|
+
tracerProvider.register();
|
|
57
|
+
import_api.trace.setGlobalTracerProvider(tracerProvider);
|
|
58
|
+
}
|
|
59
|
+
if (metricReaders.length > 0) {
|
|
60
|
+
const meterProvider = new import_sdk_metrics.MeterProvider({
|
|
61
|
+
readers: metricReaders,
|
|
62
|
+
resource
|
|
63
|
+
});
|
|
64
|
+
import_api.metrics.setGlobalMeterProvider(meterProvider);
|
|
65
|
+
}
|
|
66
|
+
if (logRecordProcessors.length > 0) {
|
|
67
|
+
const loggerProvider = new import_sdk_logs.LoggerProvider({
|
|
68
|
+
resource,
|
|
69
|
+
processors: logRecordProcessors
|
|
70
|
+
});
|
|
71
|
+
import_api_logs.logs.setGlobalLoggerProvider(loggerProvider);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function getOtelResource() {
|
|
75
|
+
return (0, import_resources.detectResources)({
|
|
76
|
+
detectors: []
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function getOtelExportersConfig() {
|
|
80
|
+
return {
|
|
81
|
+
enableTracing: !!(process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT),
|
|
82
|
+
enableMetrics: !!(process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT),
|
|
83
|
+
enableLogging: !!(process.env.OTEL_EXPORTER_OTLP_ENDPOINT || process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function getOtelExporters(config = getOtelExportersConfig()) {
|
|
87
|
+
const { enableTracing, enableMetrics, enableLogging } = config;
|
|
88
|
+
return {
|
|
89
|
+
spanProcessors: enableTracing ? [new import_sdk_trace_base.BatchSpanProcessor(new import_exporter_trace_otlp_http.OTLPTraceExporter())] : [],
|
|
90
|
+
metricReaders: enableMetrics ? [new import_sdk_metrics.PeriodicExportingMetricReader({ exporter: new import_exporter_metrics_otlp_http.OTLPMetricExporter() })] : [],
|
|
91
|
+
logRecordProcessors: enableLogging ? [new import_sdk_logs.BatchLogRecordProcessor(new import_exporter_logs_otlp_http.OTLPLogExporter())] : []
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
maybeSetOtelProviders
|
|
97
|
+
});
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var tracing_exports = {};
|
|
26
|
+
__export(tracing_exports, {
|
|
27
|
+
bindAsyncGenerator: () => bindAsyncGenerator,
|
|
28
|
+
traceAgentInvocation: () => traceAgentInvocation,
|
|
29
|
+
traceCallLlm: () => traceCallLlm,
|
|
30
|
+
traceMergedToolCalls: () => traceMergedToolCalls,
|
|
31
|
+
traceSendData: () => traceSendData,
|
|
32
|
+
traceToolCall: () => traceToolCall,
|
|
33
|
+
tracer: () => tracer
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(tracing_exports);
|
|
36
|
+
var import_api = require("@opentelemetry/api");
|
|
37
|
+
var import_version = require("../version.js");
|
|
38
|
+
/**
|
|
39
|
+
* @license
|
|
40
|
+
* Copyright 2025 Google LLC
|
|
41
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
42
|
+
*/
|
|
43
|
+
const GEN_AI_AGENT_DESCRIPTION = "gen_ai.agent.description";
|
|
44
|
+
const GEN_AI_AGENT_NAME = "gen_ai.agent.name";
|
|
45
|
+
const GEN_AI_CONVERSATION_ID = "gen_ai.conversation.id";
|
|
46
|
+
const GEN_AI_OPERATION_NAME = "gen_ai.operation.name";
|
|
47
|
+
const GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
|
|
48
|
+
const GEN_AI_TOOL_DESCRIPTION = "gen_ai.tool.description";
|
|
49
|
+
const GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
50
|
+
const GEN_AI_TOOL_TYPE = "gen_ai.tool.type";
|
|
51
|
+
const tracer = import_api.trace.getTracer(
|
|
52
|
+
"gcp.vertex.agent",
|
|
53
|
+
import_version.version
|
|
54
|
+
);
|
|
55
|
+
function safeJsonSerialize(obj) {
|
|
56
|
+
try {
|
|
57
|
+
return JSON.stringify(obj);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
return "<not serializable>";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function traceAgentInvocation({
|
|
63
|
+
agent,
|
|
64
|
+
invocationContext
|
|
65
|
+
}) {
|
|
66
|
+
const span = import_api.trace.getActiveSpan();
|
|
67
|
+
if (!span) return;
|
|
68
|
+
span.setAttributes({
|
|
69
|
+
[GEN_AI_OPERATION_NAME]: "invoke_agent",
|
|
70
|
+
// Conditionally Required
|
|
71
|
+
[GEN_AI_AGENT_DESCRIPTION]: agent.description,
|
|
72
|
+
[GEN_AI_AGENT_NAME]: agent.name,
|
|
73
|
+
[GEN_AI_CONVERSATION_ID]: invocationContext.session.id
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
function traceToolCall({
|
|
77
|
+
tool,
|
|
78
|
+
args,
|
|
79
|
+
functionResponseEvent
|
|
80
|
+
}) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const span = import_api.trace.getActiveSpan();
|
|
83
|
+
if (!span) return;
|
|
84
|
+
span.setAttributes({
|
|
85
|
+
[GEN_AI_OPERATION_NAME]: "execute_tool",
|
|
86
|
+
[GEN_AI_TOOL_DESCRIPTION]: tool.description || "",
|
|
87
|
+
[GEN_AI_TOOL_NAME]: tool.name,
|
|
88
|
+
// e.g. FunctionTool
|
|
89
|
+
[GEN_AI_TOOL_TYPE]: tool.constructor.name,
|
|
90
|
+
// Setting empty llm request and response (as UI expect these) while not
|
|
91
|
+
// applicable for tool_response.
|
|
92
|
+
"gcp.vertex.agent.llm_request": "{}",
|
|
93
|
+
"gcp.vertex.agent.llm_response": "{}",
|
|
94
|
+
"gcp.vertex.agent.tool_call_args": shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
95
|
+
});
|
|
96
|
+
let toolCallId = "<not specified>";
|
|
97
|
+
let toolResponse = "<not specified>";
|
|
98
|
+
if ((_a = functionResponseEvent.content) == null ? void 0 : _a.parts) {
|
|
99
|
+
const responseParts = functionResponseEvent.content.parts;
|
|
100
|
+
const functionResponse = (_b = responseParts[0]) == null ? void 0 : _b.functionResponse;
|
|
101
|
+
if (functionResponse == null ? void 0 : functionResponse.id) {
|
|
102
|
+
toolCallId = functionResponse.id;
|
|
103
|
+
}
|
|
104
|
+
if (functionResponse == null ? void 0 : functionResponse.response) {
|
|
105
|
+
toolResponse = functionResponse.response;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (typeof toolResponse !== "object" || toolResponse === null) {
|
|
109
|
+
toolResponse = { result: toolResponse };
|
|
110
|
+
}
|
|
111
|
+
span.setAttributes({
|
|
112
|
+
[GEN_AI_TOOL_CALL_ID]: toolCallId,
|
|
113
|
+
"gcp.vertex.agent.event_id": functionResponseEvent.id,
|
|
114
|
+
"gcp.vertex.agent.tool_response": shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function traceMergedToolCalls({
|
|
118
|
+
responseEventId,
|
|
119
|
+
functionResponseEvent
|
|
120
|
+
}) {
|
|
121
|
+
const span = import_api.trace.getActiveSpan();
|
|
122
|
+
if (!span) return;
|
|
123
|
+
span.setAttributes({
|
|
124
|
+
[GEN_AI_OPERATION_NAME]: "execute_tool",
|
|
125
|
+
[GEN_AI_TOOL_NAME]: "(merged tools)",
|
|
126
|
+
[GEN_AI_TOOL_DESCRIPTION]: "(merged tools)",
|
|
127
|
+
[GEN_AI_TOOL_CALL_ID]: responseEventId,
|
|
128
|
+
"gcp.vertex.agent.tool_call_args": "N/A",
|
|
129
|
+
"gcp.vertex.agent.event_id": responseEventId,
|
|
130
|
+
// Setting empty llm request and response (as UI expect these) while not
|
|
131
|
+
// applicable for tool_response.
|
|
132
|
+
"gcp.vertex.agent.llm_request": "{}",
|
|
133
|
+
"gcp.vertex.agent.llm_response": "{}"
|
|
134
|
+
});
|
|
135
|
+
span.setAttribute("gcp.vertex.agent.tool_response", shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}");
|
|
136
|
+
}
|
|
137
|
+
function traceCallLlm({
|
|
138
|
+
invocationContext,
|
|
139
|
+
eventId,
|
|
140
|
+
llmRequest,
|
|
141
|
+
llmResponse
|
|
142
|
+
}) {
|
|
143
|
+
var _a, _b, _c;
|
|
144
|
+
const span = import_api.trace.getActiveSpan();
|
|
145
|
+
if (!span) return;
|
|
146
|
+
span.setAttributes({
|
|
147
|
+
"gen_ai.system": "gcp.vertex.agent",
|
|
148
|
+
"gen_ai.request.model": llmRequest.model,
|
|
149
|
+
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
150
|
+
"gcp.vertex.agent.session_id": invocationContext.session.id,
|
|
151
|
+
"gcp.vertex.agent.event_id": eventId,
|
|
152
|
+
// Consider removing once GenAI SDK provides a way to record this info.
|
|
153
|
+
"gcp.vertex.agent.llm_request": shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
154
|
+
});
|
|
155
|
+
if ((_a = llmRequest.config) == null ? void 0 : _a.topP) {
|
|
156
|
+
span.setAttribute("gen_ai.request.top_p", llmRequest.config.topP);
|
|
157
|
+
}
|
|
158
|
+
if (((_b = llmRequest.config) == null ? void 0 : _b.maxOutputTokens) !== void 0) {
|
|
159
|
+
span.setAttribute("gen_ai.request.max_tokens", llmRequest.config.maxOutputTokens);
|
|
160
|
+
}
|
|
161
|
+
span.setAttribute("gcp.vertex.agent.llm_response", shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}");
|
|
162
|
+
if (llmResponse.usageMetadata) {
|
|
163
|
+
span.setAttribute("gen_ai.usage.input_tokens", llmResponse.usageMetadata.promptTokenCount || 0);
|
|
164
|
+
}
|
|
165
|
+
if ((_c = llmResponse.usageMetadata) == null ? void 0 : _c.candidatesTokenCount) {
|
|
166
|
+
span.setAttribute("gen_ai.usage.output_tokens", llmResponse.usageMetadata.candidatesTokenCount);
|
|
167
|
+
}
|
|
168
|
+
if (llmResponse.finishReason) {
|
|
169
|
+
const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
|
|
170
|
+
span.setAttribute("gen_ai.response.finish_reasons", [finishReasonValue]);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function traceSendData({
|
|
174
|
+
invocationContext,
|
|
175
|
+
eventId,
|
|
176
|
+
data
|
|
177
|
+
}) {
|
|
178
|
+
const span = import_api.trace.getActiveSpan();
|
|
179
|
+
if (!span) return;
|
|
180
|
+
span.setAttributes({
|
|
181
|
+
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
182
|
+
"gcp.vertex.agent.event_id": eventId
|
|
183
|
+
});
|
|
184
|
+
span.setAttribute("gcp.vertex.agent.data", shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}");
|
|
185
|
+
}
|
|
186
|
+
function buildLlmRequestForTrace(llmRequest) {
|
|
187
|
+
const result = {
|
|
188
|
+
model: llmRequest.model,
|
|
189
|
+
contents: []
|
|
190
|
+
};
|
|
191
|
+
if (llmRequest.config) {
|
|
192
|
+
const { responseSchema, ...cleanConfig } = llmRequest.config;
|
|
193
|
+
result.config = cleanConfig;
|
|
194
|
+
}
|
|
195
|
+
result.contents = llmRequest.contents.map((content) => {
|
|
196
|
+
var _a;
|
|
197
|
+
return {
|
|
198
|
+
role: content.role,
|
|
199
|
+
parts: ((_a = content.parts) == null ? void 0 : _a.filter((part) => !part.inlineData)) || []
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
function bindAsyncGenerator(ctx, generator) {
|
|
205
|
+
return {
|
|
206
|
+
// Bind the next() method to execute within the provided context
|
|
207
|
+
next: import_api.context.bind(ctx, generator.next.bind(generator)),
|
|
208
|
+
// Bind the return() method to execute within the provided context
|
|
209
|
+
return: import_api.context.bind(ctx, generator.return.bind(generator)),
|
|
210
|
+
// Bind the throw() method to execute within the provided context
|
|
211
|
+
throw: import_api.context.bind(ctx, generator.throw.bind(generator)),
|
|
212
|
+
// Ensure the async iterator symbol also returns a context-bound generator
|
|
213
|
+
[Symbol.asyncIterator]() {
|
|
214
|
+
return bindAsyncGenerator(ctx, generator[Symbol.asyncIterator]());
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function shouldAddRequestResponseToSpans() {
|
|
219
|
+
const envValue = process.env.ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS || "true";
|
|
220
|
+
return envValue === "true" || envValue === "1";
|
|
221
|
+
}
|
|
222
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
223
|
+
0 && (module.exports = {
|
|
224
|
+
bindAsyncGenerator,
|
|
225
|
+
traceAgentInvocation,
|
|
226
|
+
traceCallLlm,
|
|
227
|
+
traceMergedToolCalls,
|
|
228
|
+
traceSendData,
|
|
229
|
+
traceToolCall,
|
|
230
|
+
tracer
|
|
231
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var agent_tool_exports = {};
|
|
26
|
+
__export(agent_tool_exports, {
|
|
27
|
+
AgentTool: () => AgentTool
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(agent_tool_exports);
|
|
30
|
+
var import_genai = require("@google/genai");
|
|
31
|
+
var import_llm_agent = require("../agents/llm_agent.js");
|
|
32
|
+
var import_in_memory_memory_service = require("../memory/in_memory_memory_service.js");
|
|
33
|
+
var import_runner = require("../runner/runner.js");
|
|
34
|
+
var import_in_memory_session_service = require("../sessions/in_memory_session_service.js");
|
|
35
|
+
var import_variant_utils = require("../utils/variant_utils.js");
|
|
36
|
+
var import_base_tool = require("./base_tool.js");
|
|
37
|
+
var import_forwarding_artifact_service = require("./forwarding_artifact_service.js");
|
|
38
|
+
/**
|
|
39
|
+
* @license
|
|
40
|
+
* Copyright 2025 Google LLC
|
|
41
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
42
|
+
*/
|
|
43
|
+
class AgentTool extends import_base_tool.BaseTool {
|
|
44
|
+
constructor(config) {
|
|
45
|
+
super(
|
|
46
|
+
{ name: config.agent.name, description: config.agent.description || "" }
|
|
47
|
+
);
|
|
48
|
+
this.agent = config.agent;
|
|
49
|
+
this.skipSummarization = config.skipSummarization || false;
|
|
50
|
+
}
|
|
51
|
+
_getDeclaration() {
|
|
52
|
+
let declaration;
|
|
53
|
+
if (this.agent instanceof import_llm_agent.LlmAgent && this.agent.inputSchema) {
|
|
54
|
+
declaration = {
|
|
55
|
+
name: this.name,
|
|
56
|
+
description: this.description,
|
|
57
|
+
// TODO(b/425992518): We should not use the agent's input schema as is.
|
|
58
|
+
// It should be validated and possibly transformed. Consider similar
|
|
59
|
+
// logic to one we have in Python ADK.
|
|
60
|
+
parameters: this.agent.inputSchema
|
|
61
|
+
};
|
|
62
|
+
} else {
|
|
63
|
+
declaration = {
|
|
64
|
+
name: this.name,
|
|
65
|
+
description: this.description,
|
|
66
|
+
parameters: {
|
|
67
|
+
type: import_genai.Type.OBJECT,
|
|
68
|
+
properties: {
|
|
69
|
+
"request": {
|
|
70
|
+
type: import_genai.Type.STRING
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
required: ["request"]
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (this.apiVariant !== import_variant_utils.GoogleLLMVariant.GEMINI_API) {
|
|
78
|
+
const hasOutputSchema = this.agent instanceof import_llm_agent.LlmAgent && this.agent.outputSchema;
|
|
79
|
+
declaration.response = hasOutputSchema ? { type: import_genai.Type.OBJECT } : { type: import_genai.Type.STRING };
|
|
80
|
+
}
|
|
81
|
+
return declaration;
|
|
82
|
+
}
|
|
83
|
+
async runAsync({ args, toolContext }) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
if (this.skipSummarization) {
|
|
86
|
+
toolContext.actions.skipSummarization = true;
|
|
87
|
+
}
|
|
88
|
+
const hasInputSchema = this.agent instanceof import_llm_agent.LlmAgent && this.agent.inputSchema;
|
|
89
|
+
const content = {
|
|
90
|
+
role: "user",
|
|
91
|
+
parts: [
|
|
92
|
+
{
|
|
93
|
+
// TODO(b/425992518): Should be validated. Consider similar
|
|
94
|
+
// logic to one we have in Python ADK.
|
|
95
|
+
text: hasInputSchema ? JSON.stringify(args) : args["request"]
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
};
|
|
99
|
+
const runner = new import_runner.Runner({
|
|
100
|
+
appName: this.agent.name,
|
|
101
|
+
agent: this.agent,
|
|
102
|
+
artifactService: new import_forwarding_artifact_service.ForwardingArtifactService(toolContext),
|
|
103
|
+
sessionService: new import_in_memory_session_service.InMemorySessionService(),
|
|
104
|
+
memoryService: new import_in_memory_memory_service.InMemoryMemoryService(),
|
|
105
|
+
credentialService: toolContext.invocationContext.credentialService
|
|
106
|
+
});
|
|
107
|
+
const session = await runner.sessionService.createSession({
|
|
108
|
+
appName: this.agent.name,
|
|
109
|
+
userId: "tmp_user",
|
|
110
|
+
state: toolContext.state.toRecord()
|
|
111
|
+
});
|
|
112
|
+
let lastEvent;
|
|
113
|
+
for await (const event of runner.runAsync({
|
|
114
|
+
userId: session.userId,
|
|
115
|
+
sessionId: session.id,
|
|
116
|
+
newMessage: content
|
|
117
|
+
})) {
|
|
118
|
+
if (event.actions.stateDelta) {
|
|
119
|
+
toolContext.state.update(event.actions.stateDelta);
|
|
120
|
+
}
|
|
121
|
+
lastEvent = event;
|
|
122
|
+
}
|
|
123
|
+
if (!((_b = (_a = lastEvent == null ? void 0 : lastEvent.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.length)) {
|
|
124
|
+
return "";
|
|
125
|
+
}
|
|
126
|
+
const hasOutputSchema = this.agent instanceof import_llm_agent.LlmAgent && this.agent.outputSchema;
|
|
127
|
+
const mergetText = lastEvent.content.parts.map((part) => part.text).filter((text) => text).join("\n");
|
|
128
|
+
return hasOutputSchema ? JSON.parse(mergetText) : mergetText;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
AgentTool
|
|
134
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var base_tool_exports = {};
|
|
26
|
+
__export(base_tool_exports, {
|
|
27
|
+
BaseTool: () => BaseTool
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(base_tool_exports);
|
|
30
|
+
var import_variant_utils = require("../utils/variant_utils.js");
|
|
31
|
+
/**
|
|
32
|
+
* @license
|
|
33
|
+
* Copyright 2025 Google LLC
|
|
34
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
35
|
+
*/
|
|
36
|
+
class BaseTool {
|
|
37
|
+
/**
|
|
38
|
+
* Base constructor for a tool.
|
|
39
|
+
*
|
|
40
|
+
* @param params The parameters for `BaseTool`.
|
|
41
|
+
*/
|
|
42
|
+
constructor(params) {
|
|
43
|
+
var _a;
|
|
44
|
+
this.name = params.name;
|
|
45
|
+
this.description = params.description;
|
|
46
|
+
this.isLongRunning = (_a = params.isLongRunning) != null ? _a : false;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the OpenAPI specification of this tool in the form of a
|
|
50
|
+
* FunctionDeclaration.
|
|
51
|
+
*
|
|
52
|
+
* NOTE
|
|
53
|
+
* - Required if subclass uses the default implementation of
|
|
54
|
+
* `processLlmRequest` to add function declaration to LLM request.
|
|
55
|
+
* - Otherwise, can be skipped, e.g. for a built-in GoogleSearch tool for
|
|
56
|
+
* Gemini.
|
|
57
|
+
*
|
|
58
|
+
* @return The FunctionDeclaration of this tool, or undefined if it doesn't
|
|
59
|
+
* need to be added to LlmRequest.config.
|
|
60
|
+
*/
|
|
61
|
+
_getDeclaration() {
|
|
62
|
+
return void 0;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Processes the outgoing LLM request for this tool.
|
|
66
|
+
*
|
|
67
|
+
* Use cases:
|
|
68
|
+
* - Most common use case is adding this tool to the LLM request.
|
|
69
|
+
* - Some tools may just preprocess the LLM request before it's sent out.
|
|
70
|
+
*
|
|
71
|
+
* @param request The request to process the LLM request.
|
|
72
|
+
*/
|
|
73
|
+
async processLlmRequest({ toolContext, llmRequest }) {
|
|
74
|
+
const functionDeclaration = this._getDeclaration();
|
|
75
|
+
if (!functionDeclaration) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
llmRequest.toolsDict[this.name] = this;
|
|
79
|
+
const tool = findToolWithFunctionDeclarations(llmRequest);
|
|
80
|
+
if (tool) {
|
|
81
|
+
if (!tool.functionDeclarations) {
|
|
82
|
+
tool.functionDeclarations = [];
|
|
83
|
+
}
|
|
84
|
+
tool.functionDeclarations.push(functionDeclaration);
|
|
85
|
+
} else {
|
|
86
|
+
llmRequest.config = llmRequest.config || {};
|
|
87
|
+
llmRequest.config.tools = llmRequest.config.tools || [];
|
|
88
|
+
llmRequest.config.tools.push({
|
|
89
|
+
functionDeclarations: [functionDeclaration]
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The Google API LLM variant to use.
|
|
95
|
+
*/
|
|
96
|
+
get apiVariant() {
|
|
97
|
+
return (0, import_variant_utils.getGoogleLlmVariant)();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function findToolWithFunctionDeclarations(llmRequest) {
|
|
101
|
+
var _a;
|
|
102
|
+
return (((_a = llmRequest.config) == null ? void 0 : _a.tools) || []).find((tool) => "functionDeclarations" in tool);
|
|
103
|
+
}
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
BaseTool
|
|
107
|
+
});
|