@google/adk 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/agents/agent_engine_client.js +172 -0
- package/dist/cjs/agents/base_agent.js +20 -4
- package/dist/cjs/agents/functions.js +28 -0
- package/dist/cjs/agents/instructions.js +2 -1
- package/dist/cjs/agents/llm_agent.js +19 -6
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/code_execution_request_processor.js +8 -0
- package/dist/cjs/agents/processors/content_processor_utils.js +38 -10
- package/dist/cjs/agents/processors/content_request_processor.js +34 -2
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/cjs/agents/processors/nl_planning_processor.js +12 -3
- package/dist/cjs/cli/utils/logs.js +6 -6
- package/dist/cjs/code_executors/container_code_executor.js +27 -16
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/cjs/common.js +9 -20
- package/dist/cjs/errors/input_validation_error.js +3 -2
- package/dist/cjs/index.js +9 -2
- package/dist/cjs/plugins/base_plugin.js +13 -23
- package/dist/cjs/sessions/base_session_service.js +14 -8
- package/dist/cjs/sessions/database_session_service.js +50 -28
- package/dist/cjs/sessions/stale_session_error.js +59 -0
- package/dist/cjs/skills/loader.js +52 -18
- package/dist/cjs/telemetry/setup.js +0 -1
- package/dist/cjs/telemetry/tracing.js +53 -10
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +18 -23
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +120 -42
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +163 -95
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +13 -9
- package/dist/cjs/tools/application_integration_tool/integration_connector_tool.js +184 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool.js +4 -1
- package/dist/cjs/tools/google_api_tool/google_api_toolset.js +173 -0
- package/dist/cjs/tools/google_api_tool/google_api_toolsets.js +124 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +2 -2
- package/dist/cjs/tools/google_api_tool/index.js +20 -23
- package/dist/cjs/tools/load_artifacts_tool.js +12 -6
- package/dist/cjs/tools/load_memory_tool.js +12 -10
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -14
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +7 -13
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/cjs/tools/toolbox_toolset.js +174 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/cjs/utils/client_labels.js +19 -2
- package/dist/cjs/utils/failover_utils.js +1 -1
- package/dist/cjs/utils/gemini_schema_util.js +24 -6
- package/dist/cjs/utils/logger_node.js +4 -0
- package/dist/cjs/utils/output_schema_utils.js +5 -2
- package/dist/cjs/utils/task.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/agent_engine_client.js +144 -0
- package/dist/esm/agents/base_agent.js +20 -4
- package/dist/esm/agents/functions.js +28 -0
- package/dist/esm/agents/instructions.js +2 -1
- package/dist/esm/agents/llm_agent.js +19 -6
- package/dist/esm/agents/processors/basic_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/code_execution_request_processor.js +8 -0
- package/dist/esm/agents/processors/content_processor_utils.js +38 -10
- package/dist/esm/agents/processors/content_request_processor.js +34 -2
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
- package/dist/esm/agents/processors/nl_planning_processor.js +12 -3
- package/dist/esm/cli/utils/logs.js +4 -4
- package/dist/esm/code_executors/container_code_executor.js +27 -16
- package/dist/esm/code_executors/unsafe_local_code_executor.js +6 -1
- package/dist/esm/common.js +10 -13
- package/dist/esm/errors/input_validation_error.js +3 -2
- package/dist/esm/index.js +17 -3
- package/dist/esm/plugins/base_plugin.js +13 -23
- package/dist/esm/sessions/base_session_service.js +12 -7
- package/dist/esm/sessions/database_session_service.js +49 -28
- package/dist/esm/sessions/stale_session_error.js +31 -0
- package/dist/esm/skills/loader.js +51 -17
- package/dist/esm/telemetry/setup.js +1 -2
- package/dist/esm/telemetry/tracing.js +57 -11
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +17 -22
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +124 -42
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +163 -95
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +13 -9
- package/dist/esm/tools/application_integration_tool/integration_connector_tool.js +158 -0
- package/dist/esm/tools/google_api_tool/google_api_tool.js +4 -1
- package/dist/esm/tools/google_api_tool/google_api_toolset.js +146 -0
- package/dist/esm/tools/google_api_tool/google_api_toolsets.js +94 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +2 -2
- package/dist/esm/tools/google_api_tool/index.js +18 -20
- package/dist/esm/tools/load_artifacts_tool.js +10 -5
- package/dist/esm/tools/load_memory_tool.js +12 -10
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -14
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -2
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +20 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +17 -6
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +6 -12
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +17 -1
- package/dist/esm/tools/toolbox_toolset.js +148 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +1 -14
- package/dist/esm/utils/client_labels.js +19 -2
- package/dist/esm/utils/failover_utils.js +1 -1
- package/dist/esm/utils/gemini_schema_util.js +23 -6
- package/dist/esm/utils/logger_node.js +4 -0
- package/dist/esm/utils/output_schema_utils.js +5 -2
- package/dist/esm/utils/task.js +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/agent_engine_client.d.ts +37 -0
- package/dist/types/agents/base_agent.d.ts +12 -0
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/processors/content_processor_utils.d.ts +4 -2
- package/dist/types/agents/processors/nl_planning_processor.d.ts +2 -1
- package/dist/types/cli/utils/logs.d.ts +1 -1
- package/dist/types/code_executors/container_code_executor.d.ts +17 -5
- package/dist/types/common.d.ts +5 -9
- package/dist/types/errors/input_validation_error.d.ts +2 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/plugins/base_plugin.d.ts +0 -10
- package/dist/types/sessions/base_session_service.d.ts +5 -0
- package/dist/types/sessions/database_session_service.d.ts +17 -1
- package/dist/types/sessions/stale_session_error.d.ts +21 -0
- package/dist/types/skills/loader.d.ts +3 -2
- package/dist/types/telemetry/tracing.d.ts +17 -3
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +14 -21
- package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +32 -9
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +22 -8
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +3 -3
- package/dist/types/tools/application_integration_tool/integration_connector_tool.d.ts +70 -0
- package/dist/types/tools/base_toolset.d.ts +6 -5
- package/dist/types/tools/google_api_tool/google_api_tool.d.ts +10 -3
- package/dist/types/tools/google_api_tool/google_api_toolset.d.ts +55 -0
- package/dist/types/tools/google_api_tool/google_api_toolsets.d.ts +48 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +5 -4
- package/dist/types/tools/google_api_tool/index.d.ts +4 -5
- package/dist/types/tools/load_artifacts_tool.d.ts +14 -1
- package/dist/types/tools/load_memory_tool.d.ts +23 -1
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +12 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +8 -0
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +5 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +10 -0
- package/dist/types/tools/toolbox_toolset.d.ts +159 -0
- package/dist/types/utils/client_labels.d.ts +2 -1
- package/dist/types/utils/gemini_schema_util.d.ts +8 -0
- package/dist/types/utils/output_schema_utils.d.ts +3 -2
- package/dist/types/utils/simple_zod_to_json.d.ts +1 -2
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +74 -66
- package/dist/web/index_web.js.map +4 -4
- package/package.json +34 -27
- package/dist/cjs/agents/remote_agent.js +0 -187
- package/dist/cjs/tools/crewai_tool.js +0 -132
- package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +0 -226
- package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +0 -58
- package/dist/cjs/tools/langchain_tool.js +0 -172
- package/dist/cjs/tools/toolbox_tool.js +0 -108
- package/dist/esm/agents/remote_agent.js +0 -164
- package/dist/esm/tools/crewai_tool.js +0 -107
- package/dist/esm/tools/google_api_tool/google_api_tool_set.js +0 -188
- package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +0 -24
- package/dist/esm/tools/langchain_tool.js +0 -148
- package/dist/esm/tools/toolbox_tool.js +0 -80
- package/dist/types/agents/remote_agent.d.ts +0 -68
- package/dist/types/tools/crewai_tool.d.ts +0 -85
- package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +0 -78
- package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +0 -33
- package/dist/types/tools/langchain_tool.d.ts +0 -103
- package/dist/types/tools/toolbox_tool.d.ts +0 -73
|
@@ -43,10 +43,12 @@ __export(loader_exports, {
|
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(loader_exports);
|
|
45
45
|
var import_adm_zip = __toESM(require("adm-zip"), 1);
|
|
46
|
-
var
|
|
46
|
+
var yaml = __toESM(require("js-yaml"), 1);
|
|
47
47
|
var import_node_buffer = require("node:buffer");
|
|
48
48
|
var fs = __toESM(require("node:fs/promises"), 1);
|
|
49
49
|
var path = __toESM(require("node:path"), 1);
|
|
50
|
+
var import_input_validation_error = require("../errors/input_validation_error.js");
|
|
51
|
+
var import_not_found_error = require("../errors/not_found_error.js");
|
|
50
52
|
var import_logger = require("../utils/logger.js");
|
|
51
53
|
var import_skill = require("./skill.js");
|
|
52
54
|
/**
|
|
@@ -126,24 +128,37 @@ async function loadDir(directoryPath) {
|
|
|
126
128
|
return files;
|
|
127
129
|
}
|
|
128
130
|
__name(loadDir, "loadDir");
|
|
131
|
+
const FRONTMATTER_BOM = "\uFEFF";
|
|
132
|
+
const FRONTMATTER_PATTERN = /^---[ \t]*\r?\n(?:([\s\S]*?)\r?\n)??---[ \t]*(?:\r?\n|$)/;
|
|
129
133
|
function parseFrontmatterYaml(content) {
|
|
130
|
-
|
|
131
|
-
|
|
134
|
+
var _a;
|
|
135
|
+
const text = content.startsWith(FRONTMATTER_BOM) ? content.slice(FRONTMATTER_BOM.length) : content;
|
|
136
|
+
if (!text.startsWith("---")) {
|
|
137
|
+
throw new import_input_validation_error.InputValidationError(
|
|
138
|
+
"SKILL.md must start with YAML frontmatter (---)"
|
|
139
|
+
);
|
|
132
140
|
}
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
throw new
|
|
141
|
+
const match = FRONTMATTER_PATTERN.exec(text);
|
|
142
|
+
if (!match) {
|
|
143
|
+
throw new import_input_validation_error.InputValidationError(
|
|
144
|
+
"SKILL.md frontmatter not properly closed with ---"
|
|
145
|
+
);
|
|
136
146
|
}
|
|
137
|
-
const frontmatterStr =
|
|
138
|
-
const body =
|
|
147
|
+
const frontmatterStr = (_a = match[1]) != null ? _a : "";
|
|
148
|
+
const body = text.slice(match[0].length).trim();
|
|
139
149
|
try {
|
|
140
|
-
const parsed =
|
|
150
|
+
const parsed = yaml.load(frontmatterStr);
|
|
141
151
|
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
142
|
-
throw new
|
|
152
|
+
throw new import_input_validation_error.InputValidationError(
|
|
153
|
+
"SKILL.md frontmatter must be a YAML mapping"
|
|
154
|
+
);
|
|
143
155
|
}
|
|
144
156
|
return { raw: parsed, body };
|
|
145
157
|
} catch (e) {
|
|
146
|
-
throw new
|
|
158
|
+
throw new import_input_validation_error.InputValidationError(
|
|
159
|
+
`Invalid YAML in frontmatter: ${e.message}`,
|
|
160
|
+
{ cause: e }
|
|
161
|
+
);
|
|
147
162
|
}
|
|
148
163
|
}
|
|
149
164
|
__name(parseFrontmatterYaml, "parseFrontmatterYaml");
|
|
@@ -151,7 +166,10 @@ function validateFrontmatter(raw) {
|
|
|
151
166
|
try {
|
|
152
167
|
return import_skill.FrontmatterSchema.parse(raw);
|
|
153
168
|
} catch (e) {
|
|
154
|
-
throw new
|
|
169
|
+
throw new import_input_validation_error.InputValidationError(
|
|
170
|
+
`Invalid YAML in frontmatter: ${e.message}`,
|
|
171
|
+
{ cause: e }
|
|
172
|
+
);
|
|
155
173
|
}
|
|
156
174
|
}
|
|
157
175
|
__name(validateFrontmatter, "validateFrontmatter");
|
|
@@ -198,6 +216,18 @@ __name(loadSkillFromDir, "loadSkillFromDir");
|
|
|
198
216
|
async function validateSkillDir(skillDir) {
|
|
199
217
|
const problems = [];
|
|
200
218
|
const resolvedDir = path.resolve(skillDir);
|
|
219
|
+
try {
|
|
220
|
+
const stats = await fs.stat(resolvedDir);
|
|
221
|
+
if (!stats.isDirectory()) {
|
|
222
|
+
return [`'${resolvedDir}' is not a directory.`];
|
|
223
|
+
}
|
|
224
|
+
} catch (e) {
|
|
225
|
+
const code = e.code;
|
|
226
|
+
if (code === "ENOENT" || code === "ENOTDIR") {
|
|
227
|
+
return [`Directory '${resolvedDir}' does not exist.`];
|
|
228
|
+
}
|
|
229
|
+
return [`Failed to access '${resolvedDir}': ${e.message}`];
|
|
230
|
+
}
|
|
201
231
|
let skill;
|
|
202
232
|
try {
|
|
203
233
|
skill = await loadSkillFile(resolvedDir);
|
|
@@ -247,7 +277,7 @@ async function loadSkillFile(skillDir) {
|
|
|
247
277
|
);
|
|
248
278
|
}
|
|
249
279
|
if (!skillMdPath) {
|
|
250
|
-
throw new
|
|
280
|
+
throw new import_not_found_error.NotFoundError(
|
|
251
281
|
`SKILL.md (or any case variation like skill.md) not found in '${skillDir}'.`
|
|
252
282
|
);
|
|
253
283
|
}
|
|
@@ -255,7 +285,7 @@ async function loadSkillFile(skillDir) {
|
|
|
255
285
|
const frontmatter = import_skill.FrontmatterSchema.parse(parsed);
|
|
256
286
|
const dirName = path.basename(resolvedDir);
|
|
257
287
|
if (dirName !== frontmatter.name) {
|
|
258
|
-
throw new
|
|
288
|
+
throw new import_input_validation_error.InputValidationError(
|
|
259
289
|
`Skill name '${frontmatter.name}' does not match directory name '${dirName}'.`
|
|
260
290
|
);
|
|
261
291
|
}
|
|
@@ -317,7 +347,9 @@ function loadSkillFromZipBuffer(zipBuffer) {
|
|
|
317
347
|
const entries = zip.getEntries();
|
|
318
348
|
for (const entry of entries) {
|
|
319
349
|
if (isDangerousZipEntryName(entry.entryName)) {
|
|
320
|
-
throw new
|
|
350
|
+
throw new import_input_validation_error.InputValidationError(
|
|
351
|
+
`Dangerous zip entry ignored: ${entry.entryName}`
|
|
352
|
+
);
|
|
321
353
|
}
|
|
322
354
|
}
|
|
323
355
|
let skillMdContent = "";
|
|
@@ -329,15 +361,17 @@ function loadSkillFromZipBuffer(zipBuffer) {
|
|
|
329
361
|
}
|
|
330
362
|
}
|
|
331
363
|
if (!skillMdContent) {
|
|
332
|
-
throw new
|
|
364
|
+
throw new import_not_found_error.NotFoundError("SKILL.md not found in zipped filesystem.");
|
|
333
365
|
}
|
|
334
366
|
const { raw, body } = parseFrontmatterYaml(skillMdContent);
|
|
335
367
|
const skillName = raw["name"];
|
|
336
368
|
if (!skillName) {
|
|
337
|
-
throw new
|
|
369
|
+
throw new import_input_validation_error.InputValidationError("SKILL.md frontmatter must contain 'name'");
|
|
338
370
|
}
|
|
339
371
|
if (typeof skillName !== "string" || !isBareSkillName(skillName)) {
|
|
340
|
-
throw new
|
|
372
|
+
throw new import_input_validation_error.InputValidationError(
|
|
373
|
+
`Invalid skill name in SKILL.md: ${String(skillName)}`
|
|
374
|
+
);
|
|
341
375
|
}
|
|
342
376
|
const frontmatter = validateFrontmatter(raw);
|
|
343
377
|
const references = {};
|
|
@@ -59,7 +59,6 @@ function maybeSetOtelProviders(otelHooksToSetup = [], otelResource) {
|
|
|
59
59
|
spanProcessors
|
|
60
60
|
});
|
|
61
61
|
tracerProvider.register();
|
|
62
|
-
import_api.trace.setGlobalTracerProvider(tracerProvider);
|
|
63
62
|
}
|
|
64
63
|
if (metricReaders.length > 0) {
|
|
65
64
|
const meterProvider = new import_sdk_metrics.MeterProvider({
|
|
@@ -25,6 +25,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
26
|
var tracing_exports = {};
|
|
27
27
|
__export(tracing_exports, {
|
|
28
|
+
resolveErrorType: () => resolveErrorType,
|
|
28
29
|
runAsyncGeneratorWithOtelContext: () => runAsyncGeneratorWithOtelContext,
|
|
29
30
|
traceAgentInvocation: () => traceAgentInvocation,
|
|
30
31
|
traceCallLlm: () => traceCallLlm,
|
|
@@ -36,6 +37,7 @@ __export(tracing_exports, {
|
|
|
36
37
|
tracer: () => tracer
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(tracing_exports);
|
|
40
|
+
var import_genai = require("@google/genai");
|
|
39
41
|
var import_api = require("@opentelemetry/api");
|
|
40
42
|
var import_version = require("../version.js");
|
|
41
43
|
/**
|
|
@@ -140,15 +142,55 @@ function traceNodeExecution({
|
|
|
140
142
|
});
|
|
141
143
|
}
|
|
142
144
|
__name(traceNodeExecution, "traceNodeExecution");
|
|
143
|
-
function
|
|
144
|
-
tool,
|
|
145
|
-
args,
|
|
146
|
-
functionResponseEvent,
|
|
147
|
-
invocationContext
|
|
148
|
-
}) {
|
|
145
|
+
function resolveErrorType(error) {
|
|
149
146
|
var _a, _b;
|
|
150
|
-
|
|
147
|
+
if (error !== null && (typeof error === "object" || typeof error === "function")) {
|
|
148
|
+
try {
|
|
149
|
+
const errorObject = error;
|
|
150
|
+
const customErrorType = (_a = errorObject.errorType) != null ? _a : errorObject.error_type;
|
|
151
|
+
if (typeof customErrorType === "string" || typeof customErrorType === "number") {
|
|
152
|
+
return String(customErrorType);
|
|
153
|
+
}
|
|
154
|
+
if (error instanceof import_genai.ApiError) {
|
|
155
|
+
return String(error.status);
|
|
156
|
+
}
|
|
157
|
+
const constructorName = (_b = errorObject.constructor) == null ? void 0 : _b.name;
|
|
158
|
+
if (typeof constructorName === "string" && constructorName.length > 0) {
|
|
159
|
+
return constructorName;
|
|
160
|
+
}
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return typeof error;
|
|
165
|
+
}
|
|
166
|
+
__name(resolveErrorType, "resolveErrorType");
|
|
167
|
+
function traceToolCall(params) {
|
|
168
|
+
var _a, _b, _c;
|
|
169
|
+
const {
|
|
170
|
+
tool,
|
|
171
|
+
args,
|
|
172
|
+
functionResponseEvent,
|
|
173
|
+
invocationContext,
|
|
174
|
+
error,
|
|
175
|
+
errorType
|
|
176
|
+
} = params;
|
|
177
|
+
const span = (_a = params.span) != null ? _a : import_api.trace.getActiveSpan();
|
|
151
178
|
if (!span) return;
|
|
179
|
+
const hasError = Object.hasOwn(params, "error");
|
|
180
|
+
const failureType = hasError ? resolveErrorType(error) : errorType;
|
|
181
|
+
if (hasError) {
|
|
182
|
+
let exception;
|
|
183
|
+
try {
|
|
184
|
+
exception = error instanceof Error ? error : resolveErrorType(error);
|
|
185
|
+
} catch {
|
|
186
|
+
exception = resolveErrorType(error);
|
|
187
|
+
}
|
|
188
|
+
span.recordException(exception);
|
|
189
|
+
}
|
|
190
|
+
if (failureType !== void 0) {
|
|
191
|
+
span.setAttribute("error.type", failureType);
|
|
192
|
+
span.setStatus({ code: import_api.SpanStatusCode.ERROR, message: failureType });
|
|
193
|
+
}
|
|
152
194
|
span.setAttributes({
|
|
153
195
|
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
154
196
|
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
@@ -165,9 +207,9 @@ function traceToolCall({
|
|
|
165
207
|
});
|
|
166
208
|
let toolCallId = "<not specified>";
|
|
167
209
|
let toolResponse = "<not specified>";
|
|
168
|
-
if ((
|
|
210
|
+
if ((_b = functionResponseEvent == null ? void 0 : functionResponseEvent.content) == null ? void 0 : _b.parts) {
|
|
169
211
|
const responseParts = functionResponseEvent.content.parts;
|
|
170
|
-
const functionResponse = (
|
|
212
|
+
const functionResponse = (_c = responseParts[0]) == null ? void 0 : _c.functionResponse;
|
|
171
213
|
if (functionResponse == null ? void 0 : functionResponse.id) {
|
|
172
214
|
toolCallId = functionResponse.id;
|
|
173
215
|
}
|
|
@@ -180,7 +222,7 @@ function traceToolCall({
|
|
|
180
222
|
}
|
|
181
223
|
span.setAttributes({
|
|
182
224
|
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: toolCallId,
|
|
183
|
-
["gcp.vertex.agent.event_id" /* EVENT_ID */]: functionResponseEvent.id,
|
|
225
|
+
...functionResponseEvent ? { ["gcp.vertex.agent.event_id" /* EVENT_ID */]: functionResponseEvent.id } : {},
|
|
184
226
|
["gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
185
227
|
});
|
|
186
228
|
}
|
|
@@ -338,6 +380,7 @@ function shouldAddRequestResponseToSpans() {
|
|
|
338
380
|
__name(shouldAddRequestResponseToSpans, "shouldAddRequestResponseToSpans");
|
|
339
381
|
// Annotate the CommonJS export names for ESM import in node:
|
|
340
382
|
0 && (module.exports = {
|
|
383
|
+
resolveErrorType,
|
|
341
384
|
runAsyncGeneratorWithOtelContext,
|
|
342
385
|
traceAgentInvocation,
|
|
343
386
|
traceCallLlm,
|
|
@@ -46,7 +46,7 @@ __export(apihub_toolset_exports, {
|
|
|
46
46
|
APIHubToolset: () => APIHubToolset
|
|
47
47
|
});
|
|
48
48
|
module.exports = __toCommonJS(apihub_toolset_exports);
|
|
49
|
-
var
|
|
49
|
+
var yaml = __toESM(require("js-yaml"), 1);
|
|
50
50
|
var import_case_utils = require("../../utils/case_utils.js");
|
|
51
51
|
var import_experimental = require("../../utils/experimental.js");
|
|
52
52
|
var import_base_toolset = require("../base_toolset.js");
|
|
@@ -59,15 +59,15 @@ var import_apihub_client = require("./clients/apihub_client.js");
|
|
|
59
59
|
*/
|
|
60
60
|
let APIHubToolset = class extends import_base_toolset.BaseToolset {
|
|
61
61
|
constructor(options) {
|
|
62
|
-
var _a, _b, _c, _d;
|
|
63
|
-
super([]);
|
|
64
|
-
this.name = (
|
|
65
|
-
this.description = (
|
|
62
|
+
var _a, _b, _c, _d, _e;
|
|
63
|
+
super((_a = options.toolFilter) != null ? _a : []);
|
|
64
|
+
this.name = (_b = options.name) != null ? _b : "";
|
|
65
|
+
this.description = (_c = options.description) != null ? _c : "";
|
|
66
66
|
this.apihubResourceName = options.apihubResourceName;
|
|
67
|
-
this.lazyLoadSpec = (
|
|
67
|
+
this.lazyLoadSpec = (_d = options.lazyLoadSpec) != null ? _d : false;
|
|
68
68
|
this.authScheme = options.authScheme;
|
|
69
69
|
this.authCredential = options.authCredential;
|
|
70
|
-
this.apihubClient = (
|
|
70
|
+
this.apihubClient = (_e = options.apihubClient) != null ? _e : new import_apihub_client.APIHubClient({
|
|
71
71
|
accessToken: options.accessToken,
|
|
72
72
|
serviceAccountJson: options.serviceAccountJson
|
|
73
73
|
});
|
|
@@ -86,21 +86,12 @@ let APIHubToolset = class extends import_base_toolset.BaseToolset {
|
|
|
86
86
|
const toolset = await this.loadToolset();
|
|
87
87
|
return toolset ? toolset.getTools(context) : [];
|
|
88
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
89
|
async close() {
|
|
90
|
+
if (!this.toolsetPromise) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const toolset = await this.toolsetPromise.catch(() => void 0);
|
|
94
|
+
await (toolset == null ? void 0 : toolset.close());
|
|
104
95
|
}
|
|
105
96
|
loadToolset() {
|
|
106
97
|
if (!this.toolsetPromise) {
|
|
@@ -119,7 +110,10 @@ let APIHubToolset = class extends import_base_toolset.BaseToolset {
|
|
|
119
110
|
const spec = await this.apihubClient.getSpecContent(
|
|
120
111
|
this.apihubResourceName
|
|
121
112
|
);
|
|
122
|
-
|
|
113
|
+
if (!spec.trim()) {
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
116
|
+
const specDict = yaml.load(spec);
|
|
123
117
|
if (!specDict) {
|
|
124
118
|
return void 0;
|
|
125
119
|
}
|
|
@@ -128,7 +122,8 @@ let APIHubToolset = class extends import_base_toolset.BaseToolset {
|
|
|
128
122
|
return new import_openapi_toolset.OpenAPIToolset({
|
|
129
123
|
specDict,
|
|
130
124
|
authScheme: this.authScheme,
|
|
131
|
-
authCredential: this.authCredential
|
|
125
|
+
authCredential: this.authCredential,
|
|
126
|
+
toolFilter: this.toolFilter
|
|
132
127
|
});
|
|
133
128
|
}
|
|
134
129
|
};
|
|
@@ -33,18 +33,23 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
33
33
|
};
|
|
34
34
|
var application_integration_toolset_exports = {};
|
|
35
35
|
__export(application_integration_toolset_exports, {
|
|
36
|
-
ApplicationIntegrationToolset: () => ApplicationIntegrationToolset
|
|
36
|
+
ApplicationIntegrationToolset: () => ApplicationIntegrationToolset,
|
|
37
|
+
IntegrationConnectorTool: () => import_integration_connector_tool.IntegrationConnectorTool
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(application_integration_toolset_exports);
|
|
39
40
|
var import_auth_credential = require("../../auth/auth_credential.js");
|
|
40
41
|
var import_experimental = require("../../utils/experimental.js");
|
|
41
42
|
var import_json_utils = require("../../utils/json_utils.js");
|
|
43
|
+
var import_logger = require("../../utils/logger.js");
|
|
42
44
|
var import_base_toolset = require("../base_toolset.js");
|
|
43
45
|
var import_auth_helpers = require("../openapi_tool/auth/auth_helpers.js");
|
|
46
|
+
var import_openapi_spec_parser = require("../openapi_tool/openapi_spec_parser/openapi_spec_parser.js");
|
|
44
47
|
var import_openapi_toolset = require("../openapi_tool/openapi_toolset.js");
|
|
48
|
+
var import_rest_api_tool = require("../openapi_tool/rest_api_tool.js");
|
|
45
49
|
var import_cloud_request = require("./clients/cloud_request.js");
|
|
46
50
|
var import_connections_client = require("./clients/connections_client.js");
|
|
47
51
|
var import_integration_client = require("./clients/integration_client.js");
|
|
52
|
+
var import_integration_connector_tool = require("./integration_connector_tool.js");
|
|
48
53
|
/**
|
|
49
54
|
* @license
|
|
50
55
|
* Copyright 2026 Google LLC
|
|
@@ -57,19 +62,20 @@ const AUTH_SCHEME = {
|
|
|
57
62
|
};
|
|
58
63
|
let ApplicationIntegrationToolset = class extends import_base_toolset.BaseToolset {
|
|
59
64
|
/**
|
|
60
|
-
* @throws Error Unless the options name either an integration
|
|
61
|
-
*
|
|
65
|
+
* @throws Error Unless the options name either an integration, or a
|
|
66
|
+
* connection with at least one entity operation or action.
|
|
62
67
|
*/
|
|
63
68
|
constructor(options) {
|
|
64
|
-
var _a, _b;
|
|
65
|
-
super([]);
|
|
66
|
-
|
|
69
|
+
var _a, _b, _c;
|
|
70
|
+
super((_a = options.toolFilter) != null ? _a : []);
|
|
71
|
+
this.openApiToolsets = [];
|
|
72
|
+
const hasIntegration = Boolean(options.integration);
|
|
67
73
|
const hasConnection = Boolean(
|
|
68
|
-
options.connection && (Object.keys((
|
|
74
|
+
options.connection && (Object.keys((_b = options.entityOperations) != null ? _b : {}).length > 0 || ((_c = options.actions) != null ? _c : []).length > 0)
|
|
69
75
|
);
|
|
70
76
|
if (!hasIntegration && !hasConnection) {
|
|
71
77
|
throw new Error(
|
|
72
|
-
"Either
|
|
78
|
+
"Either integration or (connection and (entityOperations or actions)) should be provided."
|
|
73
79
|
);
|
|
74
80
|
}
|
|
75
81
|
this.options = options;
|
|
@@ -80,72 +86,117 @@ let ApplicationIntegrationToolset = class extends import_base_toolset.BaseToolse
|
|
|
80
86
|
* The first call fetches the spec and builds the tools. Concurrent calls
|
|
81
87
|
* share that load. When it fails, the next call tries again.
|
|
82
88
|
*/
|
|
83
|
-
async getTools() {
|
|
89
|
+
async getTools(context) {
|
|
84
90
|
if (!this.toolsPromise) {
|
|
85
91
|
this.toolsPromise = this.loadTools();
|
|
86
92
|
}
|
|
87
93
|
try {
|
|
88
|
-
|
|
94
|
+
const tools = await this.toolsPromise;
|
|
95
|
+
return tools.filter((tool) => this.isToolSelected(tool, context));
|
|
89
96
|
} catch (e) {
|
|
90
97
|
this.toolsPromise = void 0;
|
|
91
98
|
throw e;
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
101
|
async close() {
|
|
102
|
+
for (const openApiToolset of this.openApiToolsets) {
|
|
103
|
+
await openApiToolset.close();
|
|
104
|
+
}
|
|
95
105
|
}
|
|
96
106
|
async loadTools() {
|
|
97
|
-
var _a;
|
|
107
|
+
var _a, _b;
|
|
98
108
|
const {
|
|
99
109
|
project,
|
|
100
110
|
location,
|
|
101
111
|
integration,
|
|
102
|
-
|
|
112
|
+
triggers,
|
|
103
113
|
connection,
|
|
104
114
|
entityOperations,
|
|
105
115
|
actions,
|
|
106
|
-
|
|
116
|
+
toolNamePrefix,
|
|
107
117
|
toolInstructions = "",
|
|
108
|
-
serviceAccountJson
|
|
118
|
+
serviceAccountJson,
|
|
119
|
+
authScheme,
|
|
120
|
+
authCredential: dynamicAuthCredential
|
|
109
121
|
} = this.options;
|
|
122
|
+
const resolvedToolName = toolNamePrefix != null ? toolNamePrefix : "";
|
|
123
|
+
this.openApiToolsets = [];
|
|
110
124
|
const integrationClient = new import_integration_client.IntegrationClient({
|
|
111
125
|
project,
|
|
112
126
|
location,
|
|
113
127
|
integration,
|
|
114
|
-
|
|
128
|
+
triggers,
|
|
115
129
|
connection,
|
|
116
130
|
entityOperations,
|
|
117
131
|
actions,
|
|
118
132
|
serviceAccountJson
|
|
119
133
|
});
|
|
120
|
-
let specDict;
|
|
121
|
-
if (integration && trigger) {
|
|
122
|
-
specDict = await integrationClient.getOpenApiSpecForIntegration();
|
|
123
|
-
} else {
|
|
124
|
-
const connectionName = connection != null ? connection : "";
|
|
125
|
-
const { serviceName, host } = await new import_connections_client.ConnectionsClient({
|
|
126
|
-
project,
|
|
127
|
-
location,
|
|
128
|
-
connection: connectionName,
|
|
129
|
-
serviceAccountJson
|
|
130
|
-
}).getConnectionDetails();
|
|
131
|
-
const instructions = `${toolInstructions}ALWAYS use serviceName = ${serviceName}, host = ${host} and the connection name = projects/${project}/locations/${location}/connections/${connectionName} when using this tool. DO NOT ask the user for these values as you already have those.`;
|
|
132
|
-
specDict = await integrationClient.getOpenApiSpecForConnection(
|
|
133
|
-
toolName,
|
|
134
|
-
instructions
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
const spec = specDict;
|
|
138
134
|
const authCredential = buildAuthCredential(serviceAccountJson);
|
|
139
135
|
const toolsByName = /* @__PURE__ */ new Map();
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
136
|
+
if (integration) {
|
|
137
|
+
const specDict2 = await integrationClient.getOpenApiSpecForIntegration();
|
|
138
|
+
const spec2 = toOpenApiDocument(specDict2);
|
|
139
|
+
for (const [path, pathItem] of Object.entries((_a = spec2.paths) != null ? _a : {})) {
|
|
140
|
+
const openApiToolset = new import_openapi_toolset.OpenAPIToolset({
|
|
141
|
+
specDict: { ...spec2, paths: { [removeFragment(path)]: pathItem } },
|
|
142
|
+
authCredential,
|
|
143
|
+
authScheme: AUTH_SCHEME
|
|
144
|
+
});
|
|
145
|
+
this.openApiToolsets.push(openApiToolset);
|
|
146
|
+
const tools = await openApiToolset.getTools();
|
|
147
|
+
for (const tool of tools) {
|
|
148
|
+
toolsByName.set(tool.name, tool);
|
|
149
|
+
}
|
|
148
150
|
}
|
|
151
|
+
return [...toolsByName.values()];
|
|
152
|
+
}
|
|
153
|
+
const connectionName = connection != null ? connection : "";
|
|
154
|
+
const connectionDetails = await new import_connections_client.ConnectionsClient({
|
|
155
|
+
project,
|
|
156
|
+
location,
|
|
157
|
+
connection: connectionName,
|
|
158
|
+
serviceAccountJson
|
|
159
|
+
}).getConnectionDetails();
|
|
160
|
+
if (authScheme && dynamicAuthCredential && !connectionDetails.authOverrideEnabled) {
|
|
161
|
+
import_logger.logger.warn(
|
|
162
|
+
"Authentication schema and credentials are not used because authOverrideEnabled is not enabled in the connection."
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
const specDict = await integrationClient.getOpenApiSpecForConnection(
|
|
166
|
+
resolvedToolName,
|
|
167
|
+
toolInstructions
|
|
168
|
+
);
|
|
169
|
+
const spec = toOpenApiDocument(specDict);
|
|
170
|
+
addDynamicAuthConfigToConnectionSchemas(spec);
|
|
171
|
+
const operations = new import_openapi_spec_parser.OpenApiSpecParser().parse(spec);
|
|
172
|
+
for (const openApiOperation of operations) {
|
|
173
|
+
const operationObject = (0, import_json_utils.toJsonObject)(openApiOperation.operation);
|
|
174
|
+
const operation = toStringValue(operationObject["x-operation"]);
|
|
175
|
+
const entity = toStringValue(operationObject["x-entity"]);
|
|
176
|
+
const action = toStringValue(operationObject["x-action"]);
|
|
177
|
+
const restApiTool = (0, import_rest_api_tool.createRestApiTool)({
|
|
178
|
+
...openApiOperation,
|
|
179
|
+
endpoint: {
|
|
180
|
+
...openApiOperation.endpoint,
|
|
181
|
+
path: removeFragment(openApiOperation.endpoint.path)
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
restApiTool.configureAuthScheme(AUTH_SCHEME);
|
|
185
|
+
restApiTool.configureAuthCredential(authCredential);
|
|
186
|
+
const tool = new import_integration_connector_tool.IntegrationConnectorTool({
|
|
187
|
+
name: restApiTool.name,
|
|
188
|
+
description: restApiTool.description,
|
|
189
|
+
connectionName: (_b = connectionDetails.name) != null ? _b : "",
|
|
190
|
+
connectionHost: connectionDetails.host,
|
|
191
|
+
connectionServiceName: connectionDetails.serviceName,
|
|
192
|
+
entity,
|
|
193
|
+
action,
|
|
194
|
+
operation,
|
|
195
|
+
restApiTool,
|
|
196
|
+
authScheme: connectionDetails.authOverrideEnabled ? authScheme : void 0,
|
|
197
|
+
authCredential: connectionDetails.authOverrideEnabled ? dynamicAuthCredential : void 0
|
|
198
|
+
});
|
|
199
|
+
toolsByName.set(tool.name, tool);
|
|
149
200
|
}
|
|
150
201
|
return [...toolsByName.values()];
|
|
151
202
|
}
|
|
@@ -154,6 +205,32 @@ __name(ApplicationIntegrationToolset, "ApplicationIntegrationToolset");
|
|
|
154
205
|
ApplicationIntegrationToolset = __decorateClass([
|
|
155
206
|
import_experimental.experimental
|
|
156
207
|
], ApplicationIntegrationToolset);
|
|
208
|
+
function addDynamicAuthConfigToConnectionSchemas(spec) {
|
|
209
|
+
var _a;
|
|
210
|
+
const schemas = (_a = spec.components) == null ? void 0 : _a.schemas;
|
|
211
|
+
if (!schemas) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
for (const [schemaName, schema] of Object.entries(schemas)) {
|
|
215
|
+
if (schemaName.endsWith("_Request") && (0, import_json_utils.isJsonObject)(schema) && (0, import_json_utils.isJsonObject)(schema.properties) && !("query" in schema.properties) && !("dynamicAuthConfig" in schema.properties)) {
|
|
216
|
+
schema.properties = {
|
|
217
|
+
...schema.properties,
|
|
218
|
+
dynamicAuthConfig: {
|
|
219
|
+
$ref: "#/components/schemas/dynamicAuthConfig"
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
__name(addDynamicAuthConfigToConnectionSchemas, "addDynamicAuthConfigToConnectionSchemas");
|
|
226
|
+
function toOpenApiDocument(specDict) {
|
|
227
|
+
return specDict;
|
|
228
|
+
}
|
|
229
|
+
__name(toOpenApiDocument, "toOpenApiDocument");
|
|
230
|
+
function toStringValue(value) {
|
|
231
|
+
return typeof value === "string" ? value : "";
|
|
232
|
+
}
|
|
233
|
+
__name(toStringValue, "toStringValue");
|
|
157
234
|
function buildAuthCredential(serviceAccountJson) {
|
|
158
235
|
if (!serviceAccountJson) {
|
|
159
236
|
return {
|
|
@@ -181,5 +258,6 @@ function removeFragment(path) {
|
|
|
181
258
|
__name(removeFragment, "removeFragment");
|
|
182
259
|
// Annotate the CommonJS export names for ESM import in node:
|
|
183
260
|
0 && (module.exports = {
|
|
184
|
-
ApplicationIntegrationToolset
|
|
261
|
+
ApplicationIntegrationToolset,
|
|
262
|
+
IntegrationConnectorTool
|
|
185
263
|
});
|