@google/adk 1.2.0 → 1.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/agents/base_agent.js +19 -1
- package/dist/cjs/agents/instructions.js +81 -33
- package/dist/cjs/agents/invocation_context.js +0 -1
- package/dist/cjs/agents/llm_agent.js +52 -5
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/cjs/agents/processors/content_processor_utils.js +37 -24
- package/dist/cjs/agents/processors/content_request_processor.js +7 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/cjs/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/cjs/auth/auth_preprocessor.js +12 -10
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +7 -7
- package/dist/cjs/common.js +39 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
- package/dist/cjs/context/token_based_context_compactor.js +1 -1
- package/dist/cjs/events/event.js +1 -1
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/cjs/models/gemini_llm_connection.js +62 -19
- package/dist/cjs/models/google_llm.js +26 -8
- package/dist/cjs/plugins/security_plugin.js +16 -0
- package/dist/cjs/sessions/base_session_service.js +13 -2
- package/dist/cjs/sessions/database_session_service.js +2 -2
- package/dist/cjs/sessions/db/schema.js +45 -10
- package/dist/cjs/sessions/in_memory_session_service.js +2 -1
- package/dist/cjs/sessions/vertex_ai_session_service.js +2 -1
- package/dist/cjs/skills/gcp_skill_registry.js +104 -0
- package/dist/cjs/skills/loader.js +65 -0
- package/dist/cjs/skills/skill_registry.js +27 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +232 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +224 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +127 -0
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +133 -0
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +256 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/cjs/tools/skill/load_skill_tool.js +12 -1
- package/dist/cjs/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/cjs/tools/skill/search_skills_tool.js +108 -0
- package/dist/cjs/tools/skill/skill_toolset.js +40 -5
- package/dist/cjs/utils/async_queue.js +88 -0
- package/dist/cjs/utils/case_utils.js +53 -0
- package/dist/cjs/utils/env_aware_utils.js +4 -0
- package/dist/cjs/utils/live_connection_utils.js +284 -0
- package/dist/cjs/utils/model_name.js +9 -0
- package/dist/cjs/utils/streaming_utils.js +9 -8
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +19 -1
- package/dist/esm/agents/instructions.js +81 -33
- package/dist/esm/agents/invocation_context.js +0 -1
- package/dist/esm/agents/llm_agent.js +53 -5
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/esm/agents/processors/content_processor_utils.js +35 -23
- package/dist/esm/agents/processors/content_request_processor.js +7 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/esm/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/esm/auth/auth_preprocessor.js +12 -10
- package/dist/esm/auth/oauth2/oauth2_discovery.js +1 -1
- package/dist/esm/code_executors/code_executor_context.js +7 -7
- package/dist/esm/common.js +33 -1
- package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
- package/dist/esm/context/token_based_context_compactor.js +1 -1
- package/dist/esm/events/event.js +1 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/esm/models/gemini_llm_connection.js +62 -19
- package/dist/esm/models/google_llm.js +26 -8
- package/dist/esm/plugins/security_plugin.js +16 -0
- package/dist/esm/sessions/base_session_service.js +11 -1
- package/dist/esm/sessions/database_session_service.js +2 -2
- package/dist/esm/sessions/db/schema.js +44 -10
- package/dist/esm/sessions/in_memory_session_service.js +4 -2
- package/dist/esm/sessions/vertex_ai_session_service.js +4 -2
- package/dist/esm/skills/gcp_skill_registry.js +78 -0
- package/dist/esm/skills/loader.js +64 -0
- package/dist/esm/skills/skill_registry.js +7 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +206 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/esm/tools/skill/load_skill_tool.js +12 -1
- package/dist/esm/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/esm/tools/skill/search_skills_tool.js +82 -0
- package/dist/esm/tools/skill/skill_toolset.js +40 -5
- package/dist/esm/utils/async_queue.js +60 -0
- package/dist/esm/utils/case_utils.js +25 -0
- package/dist/esm/utils/env_aware_utils.js +4 -0
- package/dist/esm/utils/live_connection_utils.js +256 -0
- package/dist/esm/utils/model_name.js +8 -0
- package/dist/esm/utils/streaming_utils.js +9 -8
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +29 -4
- package/dist/types/a2a/event_converter_utils.d.ts +14 -1
- package/dist/types/a2a/metadata_converter_utils.d.ts +18 -0
- package/dist/types/a2a/part_converter_utils.d.ts +51 -6
- package/dist/types/agents/invocation_context.d.ts +0 -9
- package/dist/types/agents/llm_agent.d.ts +14 -0
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +14 -0
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/content_processor_utils.d.ts +26 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +12 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +7 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +9 -1
- package/dist/types/agents/processors/tool_filter_request_processor.d.ts +12 -1
- package/dist/types/common.d.ts +15 -1
- package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
- package/dist/types/events/event_actions.d.ts +1 -2
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +21 -2
- package/dist/types/models/base_llm_connection.d.ts +10 -0
- package/dist/types/models/gemini_llm_connection.d.ts +15 -4
- package/dist/types/models/llm_response.d.ts +10 -1
- package/dist/types/plugins/security_plugin.d.ts +30 -0
- package/dist/types/sessions/base_session_service.d.ts +4 -0
- package/dist/types/sessions/db/schema.d.ts +1 -0
- package/dist/types/skills/gcp_skill_registry.d.ts +24 -0
- package/dist/types/skills/loader.d.ts +7 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/skills/skill_registry.d.ts +29 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +34 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +59 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +23 -0
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +27 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +50 -0
- package/dist/types/tools/skill/load_skill_resource_tool.d.ts +1 -1
- package/dist/types/tools/skill/search_skills_tool.d.ts +14 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +5 -0
- package/dist/types/utils/async_queue.d.ts +18 -0
- package/dist/types/utils/case_utils.d.ts +12 -0
- package/dist/types/utils/live_connection_utils.d.ts +30 -0
- package/dist/types/utils/model_name.d.ts +7 -0
- package/dist/types/utils/streaming_utils.d.ts +0 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +31 -1
- package/dist/web/agents/instructions.js +81 -33
- package/dist/web/agents/invocation_context.js +0 -1
- package/dist/web/agents/llm_agent.js +53 -5
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +8 -1
- package/dist/web/agents/processors/content_processor_utils.js +53 -23
- package/dist/web/agents/processors/content_request_processor.js +7 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +12 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +7 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +5 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +9 -1
- package/dist/web/agents/processors/tool_filter_request_processor.js +7 -1
- package/dist/web/auth/auth_preprocessor.js +12 -10
- package/dist/web/auth/oauth2/oauth2_discovery.js +1 -1
- package/dist/web/code_executors/code_executor_context.js +7 -7
- package/dist/web/common.js +33 -1
- package/dist/web/context/summarizers/llm_summarizer.js +11 -0
- package/dist/web/context/token_based_context_compactor.js +1 -1
- package/dist/web/events/event.js +1 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +21 -2
- package/dist/web/models/gemini_llm_connection.js +75 -19
- package/dist/web/models/google_llm.js +26 -8
- package/dist/web/plugins/security_plugin.js +16 -0
- package/dist/web/sessions/base_session_service.js +11 -1
- package/dist/web/sessions/database_session_service.js +2 -2
- package/dist/web/sessions/db/schema.js +44 -10
- package/dist/web/sessions/in_memory_session_service.js +4 -2
- package/dist/web/sessions/vertex_ai_session_service.js +4 -2
- package/dist/web/skills/gcp_skill_registry.js +78 -0
- package/dist/web/skills/loader.js +64 -0
- package/dist/web/skills/skill_registry.js +7 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +221 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/operation_parser.js +198 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +101 -0
- package/dist/web/tools/openapi_tool/openapi_toolset.js +97 -0
- package/dist/web/tools/openapi_tool/rest_api_tool.js +229 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +25 -3
- package/dist/web/tools/skill/load_skill_tool.js +12 -1
- package/dist/web/tools/skill/run_skill_script_tool.js +12 -1
- package/dist/web/tools/skill/search_skills_tool.js +82 -0
- package/dist/web/tools/skill/skill_toolset.js +40 -5
- package/dist/web/utils/async_queue.js +60 -0
- package/dist/web/utils/case_utils.js +25 -0
- package/dist/web/utils/env_aware_utils.js +4 -0
- package/dist/web/utils/live_connection_utils.js +254 -0
- package/dist/web/utils/model_name.js +8 -0
- package/dist/web/utils/streaming_utils.js +9 -8
- package/dist/web/version.js +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,221 @@
|
|
|
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 __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
21
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
22
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
23
|
+
if (decorator = decorators[i])
|
|
24
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
25
|
+
if (kind && result) __defProp(target, key, result);
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @license
|
|
30
|
+
* Copyright 2026 Google LLC
|
|
31
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
32
|
+
*/
|
|
33
|
+
import { experimental } from "../../../utils/experimental.js";
|
|
34
|
+
import { OperationParser } from "./operation_parser.js";
|
|
35
|
+
const VALID_SCHEMA_TYPES = /* @__PURE__ */ new Set([
|
|
36
|
+
"array",
|
|
37
|
+
"boolean",
|
|
38
|
+
"integer",
|
|
39
|
+
"null",
|
|
40
|
+
"number",
|
|
41
|
+
"object",
|
|
42
|
+
"string"
|
|
43
|
+
]);
|
|
44
|
+
let OpenApiSpecParser = class {
|
|
45
|
+
constructor(options = {}) {
|
|
46
|
+
var _a;
|
|
47
|
+
this.preservePropertyNames = (_a = options.preservePropertyNames) != null ? _a : false;
|
|
48
|
+
}
|
|
49
|
+
parse(openapiSpec) {
|
|
50
|
+
const resolvedSpec = resolveReferences(openapiSpec);
|
|
51
|
+
const sanitizedSpec = sanitizeSchemaTypes(resolvedSpec);
|
|
52
|
+
return collectOperations(sanitizedSpec, {
|
|
53
|
+
preservePropertyNames: this.preservePropertyNames
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
__decorateClass([
|
|
58
|
+
experimental
|
|
59
|
+
], OpenApiSpecParser.prototype, "parse", 1);
|
|
60
|
+
OpenApiSpecParser = __decorateClass([
|
|
61
|
+
experimental
|
|
62
|
+
], OpenApiSpecParser);
|
|
63
|
+
function resolveReferences(spec) {
|
|
64
|
+
const resolvedCache = /* @__PURE__ */ new Map();
|
|
65
|
+
const specCopy = JSON.parse(JSON.stringify(spec));
|
|
66
|
+
const recursiveResolve = (obj, currentDoc, seenRefs = /* @__PURE__ */ new Set()) => {
|
|
67
|
+
if (typeof obj !== "object" || obj === null) {
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
if (Array.isArray(obj)) {
|
|
71
|
+
return obj.map((item) => recursiveResolve(item, currentDoc, seenRefs));
|
|
72
|
+
}
|
|
73
|
+
const objRecord = obj;
|
|
74
|
+
if ("$ref" in objRecord && typeof objRecord["$ref"] === "string") {
|
|
75
|
+
const refString = objRecord["$ref"];
|
|
76
|
+
if (seenRefs.has(refString) && !resolvedCache.has(refString)) {
|
|
77
|
+
const copy = __spreadValues({}, objRecord);
|
|
78
|
+
delete copy["$ref"];
|
|
79
|
+
return copy;
|
|
80
|
+
}
|
|
81
|
+
seenRefs.add(refString);
|
|
82
|
+
if (resolvedCache.has(refString)) {
|
|
83
|
+
return resolvedCache.get(refString);
|
|
84
|
+
}
|
|
85
|
+
let resolvedValue = resolveRef(refString, currentDoc);
|
|
86
|
+
if (resolvedValue !== void 0) {
|
|
87
|
+
resolvedValue = recursiveResolve(resolvedValue, currentDoc, seenRefs);
|
|
88
|
+
resolvedCache.set(refString, resolvedValue);
|
|
89
|
+
return resolvedValue;
|
|
90
|
+
} else {
|
|
91
|
+
return obj;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const newDict = {};
|
|
95
|
+
for (const [key, value] of Object.entries(objRecord)) {
|
|
96
|
+
newDict[key] = recursiveResolve(value, currentDoc, seenRefs);
|
|
97
|
+
}
|
|
98
|
+
return newDict;
|
|
99
|
+
};
|
|
100
|
+
return recursiveResolve(specCopy, specCopy);
|
|
101
|
+
}
|
|
102
|
+
function resolveRef(refString, currentDoc) {
|
|
103
|
+
const parts = refString.split("/");
|
|
104
|
+
if (parts[0] !== "#") {
|
|
105
|
+
throw new Error("External references not supported: ".concat(refString));
|
|
106
|
+
}
|
|
107
|
+
let current = currentDoc;
|
|
108
|
+
for (const part of parts.slice(1)) {
|
|
109
|
+
if (typeof current === "object" && current !== null && part in current) {
|
|
110
|
+
current = current[part];
|
|
111
|
+
} else {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return current;
|
|
116
|
+
}
|
|
117
|
+
function sanitizeSchemaTypes(openapiSpec) {
|
|
118
|
+
const specCopy = JSON.parse(JSON.stringify(openapiSpec));
|
|
119
|
+
const sanitizeTypeField = (schemaDict) => {
|
|
120
|
+
if (!("type" in schemaDict)) return;
|
|
121
|
+
const typeValue = schemaDict["type"];
|
|
122
|
+
if (typeof typeValue === "string") {
|
|
123
|
+
const normalizedType = typeValue.toLowerCase();
|
|
124
|
+
if (VALID_SCHEMA_TYPES.has(normalizedType)) {
|
|
125
|
+
schemaDict["type"] = normalizedType;
|
|
126
|
+
} else {
|
|
127
|
+
delete schemaDict["type"];
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (Array.isArray(typeValue)) {
|
|
132
|
+
const validTypes = [];
|
|
133
|
+
for (const entry of typeValue) {
|
|
134
|
+
if (typeof entry !== "string") continue;
|
|
135
|
+
const normalizedEntry = entry.toLowerCase();
|
|
136
|
+
if (VALID_SCHEMA_TYPES.has(normalizedEntry) && !validTypes.includes(normalizedEntry)) {
|
|
137
|
+
validTypes.push(normalizedEntry);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (validTypes.length > 0) {
|
|
141
|
+
schemaDict["type"] = validTypes;
|
|
142
|
+
} else {
|
|
143
|
+
delete schemaDict["type"];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const sanitizeRecursive = (obj, inSchema) => {
|
|
148
|
+
if (typeof obj !== "object" || obj === null) {
|
|
149
|
+
return obj;
|
|
150
|
+
}
|
|
151
|
+
if (Array.isArray(obj)) {
|
|
152
|
+
return obj.map((item) => sanitizeRecursive(item, inSchema));
|
|
153
|
+
}
|
|
154
|
+
const objRecord = obj;
|
|
155
|
+
if (inSchema) {
|
|
156
|
+
sanitizeTypeField(objRecord);
|
|
157
|
+
}
|
|
158
|
+
for (const [key, value] of Object.entries(objRecord)) {
|
|
159
|
+
const isSchemaContainer = key === "schema" || key === "schemas";
|
|
160
|
+
objRecord[key] = sanitizeRecursive(value, inSchema || isSchemaContainer);
|
|
161
|
+
}
|
|
162
|
+
return objRecord;
|
|
163
|
+
};
|
|
164
|
+
return sanitizeRecursive(specCopy, false);
|
|
165
|
+
}
|
|
166
|
+
function collectOperations(spec, options = {}) {
|
|
167
|
+
var _a, _b, _c, _d;
|
|
168
|
+
const preservePropertyNames = (_a = options.preservePropertyNames) != null ? _a : false;
|
|
169
|
+
const operations = [];
|
|
170
|
+
const baseUrl = ((_c = (_b = spec.servers) == null ? void 0 : _b[0]) == null ? void 0 : _c.url) || "";
|
|
171
|
+
const globalSecurity = spec.security || [];
|
|
172
|
+
let globalSchemeName;
|
|
173
|
+
if (globalSecurity.length > 0) {
|
|
174
|
+
globalSchemeName = Object.keys(globalSecurity[0])[0];
|
|
175
|
+
}
|
|
176
|
+
const authSchemes = ((_d = spec.components) == null ? void 0 : _d.securitySchemes) || {};
|
|
177
|
+
for (const [path, pathItem] of Object.entries(spec.paths || {})) {
|
|
178
|
+
if (!pathItem) continue;
|
|
179
|
+
const methods = [
|
|
180
|
+
"get",
|
|
181
|
+
"post",
|
|
182
|
+
"put",
|
|
183
|
+
"delete",
|
|
184
|
+
"patch",
|
|
185
|
+
"head",
|
|
186
|
+
"options",
|
|
187
|
+
"trace"
|
|
188
|
+
];
|
|
189
|
+
for (const method of methods) {
|
|
190
|
+
const operation = pathItem[method];
|
|
191
|
+
if (!operation) continue;
|
|
192
|
+
const pathParams = pathItem.parameters || [];
|
|
193
|
+
const opParams = operation.parameters || [];
|
|
194
|
+
operation.parameters = [...opParams, ...pathParams];
|
|
195
|
+
if (!operation.operationId) {
|
|
196
|
+
operation.operationId = "".concat(method, "_").concat(path.replace(/[^a-zA-Z0-9]/g, "_"));
|
|
197
|
+
}
|
|
198
|
+
const parser = new OperationParser(operation, {
|
|
199
|
+
preservePropertyNames
|
|
200
|
+
});
|
|
201
|
+
let authSchemeName;
|
|
202
|
+
if (operation.security && operation.security.length > 0) {
|
|
203
|
+
authSchemeName = Object.keys(operation.security[0])[0];
|
|
204
|
+
}
|
|
205
|
+
authSchemeName = authSchemeName || globalSchemeName;
|
|
206
|
+
const authScheme = authSchemeName ? authSchemes[authSchemeName] : void 0;
|
|
207
|
+
operations.push({
|
|
208
|
+
name: parser.getFunctionName(),
|
|
209
|
+
description: parser.getDescription(),
|
|
210
|
+
endpoint: { baseUrl, path, method },
|
|
211
|
+
operation,
|
|
212
|
+
parameters: parser.getParameters(),
|
|
213
|
+
authScheme
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return operations;
|
|
218
|
+
}
|
|
219
|
+
export {
|
|
220
|
+
OpenApiSpecParser
|
|
221
|
+
};
|
|
@@ -0,0 +1,198 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
6
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
7
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
if (decorator = decorators[i])
|
|
9
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
10
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2026 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
*/
|
|
18
|
+
import { experimental } from "../../../utils/experimental.js";
|
|
19
|
+
let OperationParser = class {
|
|
20
|
+
constructor(operation, options = {}) {
|
|
21
|
+
this.operation = operation;
|
|
22
|
+
this.params = [];
|
|
23
|
+
var _a;
|
|
24
|
+
this.preservePropertyNames = (_a = options.preservePropertyNames) != null ? _a : false;
|
|
25
|
+
this.processOperationParameters();
|
|
26
|
+
this.processRequestBody();
|
|
27
|
+
this.processReturnValue();
|
|
28
|
+
this.dedupeParamNames();
|
|
29
|
+
}
|
|
30
|
+
getParamName(originalName) {
|
|
31
|
+
if (this.preservePropertyNames) {
|
|
32
|
+
return originalName;
|
|
33
|
+
}
|
|
34
|
+
return originalName.replace(/[A-Z]/g, (g) => "_" + g.toLowerCase()).replace(/^_/, "");
|
|
35
|
+
}
|
|
36
|
+
processOperationParameters() {
|
|
37
|
+
const parameters = this.operation.parameters || [];
|
|
38
|
+
for (const param of parameters) {
|
|
39
|
+
if ("name" in param) {
|
|
40
|
+
const originalName = param.name;
|
|
41
|
+
const description = param.description || "";
|
|
42
|
+
const location = param.in || "";
|
|
43
|
+
const schema = param.schema || {};
|
|
44
|
+
this.params.push({
|
|
45
|
+
originalName,
|
|
46
|
+
paramLocation: location,
|
|
47
|
+
paramSchema: schema,
|
|
48
|
+
description,
|
|
49
|
+
required: param.required || false,
|
|
50
|
+
name: this.getParamName(originalName)
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
processRequestBody() {
|
|
56
|
+
const requestBody = this.operation.requestBody;
|
|
57
|
+
if (!requestBody || "$ref" in requestBody) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const content = requestBody.content || {};
|
|
61
|
+
const firstMimeType = Object.keys(content)[0];
|
|
62
|
+
if (!firstMimeType) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const mediaTypeObject = content[firstMimeType];
|
|
66
|
+
const schema = mediaTypeObject.schema;
|
|
67
|
+
const description = requestBody.description || "";
|
|
68
|
+
if (schema && !("$ref" in schema)) {
|
|
69
|
+
if (schema.type === "object") {
|
|
70
|
+
const properties = schema.properties || {};
|
|
71
|
+
if (Object.keys(properties).length > 0) {
|
|
72
|
+
for (const [propName, propDetails] of Object.entries(properties)) {
|
|
73
|
+
if (!("$ref" in propDetails)) {
|
|
74
|
+
this.params.push({
|
|
75
|
+
originalName: propName,
|
|
76
|
+
paramLocation: "body",
|
|
77
|
+
paramSchema: propDetails,
|
|
78
|
+
description: propDetails.description,
|
|
79
|
+
required: (schema.required || []).includes(propName),
|
|
80
|
+
name: this.getParamName(propName)
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
this.params.push({
|
|
86
|
+
originalName: "",
|
|
87
|
+
paramLocation: "body",
|
|
88
|
+
paramSchema: schema,
|
|
89
|
+
description,
|
|
90
|
+
required: true,
|
|
91
|
+
name: "body"
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
} else if (schema.type === "array") {
|
|
95
|
+
this.params.push({
|
|
96
|
+
originalName: "array",
|
|
97
|
+
paramLocation: "body",
|
|
98
|
+
paramSchema: schema,
|
|
99
|
+
description,
|
|
100
|
+
required: true,
|
|
101
|
+
name: "body"
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
this.params.push({
|
|
105
|
+
originalName: "body",
|
|
106
|
+
paramLocation: "body",
|
|
107
|
+
paramSchema: schema,
|
|
108
|
+
description,
|
|
109
|
+
required: true,
|
|
110
|
+
name: "body"
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
processReturnValue() {
|
|
116
|
+
const responses = this.operation.responses || {};
|
|
117
|
+
const validCodes = Object.keys(responses).filter((k) => k.startsWith("2"));
|
|
118
|
+
const min20x = validCodes.sort()[0];
|
|
119
|
+
let returnSchema = {};
|
|
120
|
+
if (min20x) {
|
|
121
|
+
const response = responses[min20x];
|
|
122
|
+
if (!("$ref" in response) && response.content) {
|
|
123
|
+
const firstMimeType = Object.keys(response.content)[0];
|
|
124
|
+
if (firstMimeType) {
|
|
125
|
+
const schema = response.content[firstMimeType].schema;
|
|
126
|
+
if (schema && !("$ref" in schema)) {
|
|
127
|
+
returnSchema = schema;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.returnValue = {
|
|
133
|
+
originalName: "",
|
|
134
|
+
paramLocation: "",
|
|
135
|
+
paramSchema: returnSchema,
|
|
136
|
+
required: true,
|
|
137
|
+
name: "return"
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
dedupeParamNames() {
|
|
141
|
+
const nameCounts = /* @__PURE__ */ new Map();
|
|
142
|
+
for (const param of this.params) {
|
|
143
|
+
const name = param.name;
|
|
144
|
+
const count = nameCounts.get(name) || 0;
|
|
145
|
+
if (count > 0) {
|
|
146
|
+
param.name = "".concat(name, "_").concat(count);
|
|
147
|
+
}
|
|
148
|
+
nameCounts.set(name, count + 1);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
getParameters() {
|
|
152
|
+
return this.params;
|
|
153
|
+
}
|
|
154
|
+
getJsonSchema() {
|
|
155
|
+
const properties = {};
|
|
156
|
+
const required = [];
|
|
157
|
+
for (const param of this.params) {
|
|
158
|
+
properties[param.name] = param.paramSchema;
|
|
159
|
+
if (param.required) {
|
|
160
|
+
required.push(param.name);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
type: "object",
|
|
165
|
+
properties,
|
|
166
|
+
required: required.length > 0 ? required : void 0,
|
|
167
|
+
title: "".concat(this.operation.operationId || "unnamed", "_Arguments")
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
getFunctionName() {
|
|
171
|
+
const operationId = this.operation.operationId;
|
|
172
|
+
if (!operationId) {
|
|
173
|
+
throw new Error("Operation ID is missing");
|
|
174
|
+
}
|
|
175
|
+
return this.getParamName(operationId).substring(0, 60);
|
|
176
|
+
}
|
|
177
|
+
getDescription() {
|
|
178
|
+
return this.operation.description || this.operation.summary || "";
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
__decorateClass([
|
|
182
|
+
experimental
|
|
183
|
+
], OperationParser.prototype, "getParameters", 1);
|
|
184
|
+
__decorateClass([
|
|
185
|
+
experimental
|
|
186
|
+
], OperationParser.prototype, "getJsonSchema", 1);
|
|
187
|
+
__decorateClass([
|
|
188
|
+
experimental
|
|
189
|
+
], OperationParser.prototype, "getFunctionName", 1);
|
|
190
|
+
__decorateClass([
|
|
191
|
+
experimental
|
|
192
|
+
], OperationParser.prototype, "getDescription", 1);
|
|
193
|
+
OperationParser = __decorateClass([
|
|
194
|
+
experimental
|
|
195
|
+
], OperationParser);
|
|
196
|
+
export {
|
|
197
|
+
OperationParser
|
|
198
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
6
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
7
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
if (decorator = decorators[i])
|
|
9
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
10
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2026 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
*/
|
|
18
|
+
import { experimental } from "../../../utils/experimental.js";
|
|
19
|
+
import { AutoAuthCredentialExchanger } from "../auth/credential_exchangers/auto_auth_credential_exchanger.js";
|
|
20
|
+
class ToolContextCredentialStore {
|
|
21
|
+
constructor(context) {
|
|
22
|
+
this.context = context;
|
|
23
|
+
}
|
|
24
|
+
getCredentialKey(authScheme) {
|
|
25
|
+
const schemeName = (authScheme == null ? void 0 : authScheme.type) || "default";
|
|
26
|
+
return "".concat(schemeName, "_existing_exchanged_credential");
|
|
27
|
+
}
|
|
28
|
+
getCredential(authScheme) {
|
|
29
|
+
const key = this.getCredentialKey(authScheme);
|
|
30
|
+
const state = this.context.state;
|
|
31
|
+
if (state) {
|
|
32
|
+
const serialized = state[key];
|
|
33
|
+
if (serialized) {
|
|
34
|
+
return serialized;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
storeCredential(key, credential) {
|
|
40
|
+
const state = this.context.state;
|
|
41
|
+
if (state) {
|
|
42
|
+
state[key] = credential;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
let ToolAuthHandler = class {
|
|
47
|
+
constructor(context, authScheme, authCredential, credentialKey) {
|
|
48
|
+
this.context = context;
|
|
49
|
+
this.authScheme = authScheme;
|
|
50
|
+
this.authCredential = authCredential;
|
|
51
|
+
this.credentialKey = credentialKey;
|
|
52
|
+
}
|
|
53
|
+
static fromToolContext(context, authScheme, authCredential, options = {}) {
|
|
54
|
+
return new ToolAuthHandler(
|
|
55
|
+
context,
|
|
56
|
+
authScheme,
|
|
57
|
+
authCredential,
|
|
58
|
+
options.credentialKey
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
async prepareAuthCredentials() {
|
|
62
|
+
if (!this.authScheme) {
|
|
63
|
+
return { state: "done" };
|
|
64
|
+
}
|
|
65
|
+
const store = new ToolContextCredentialStore(this.context);
|
|
66
|
+
const existingCredential = store.getCredential(this.authScheme);
|
|
67
|
+
if (existingCredential) {
|
|
68
|
+
return { state: "done", authCredential: existingCredential };
|
|
69
|
+
}
|
|
70
|
+
const authConfig = {
|
|
71
|
+
authScheme: this.authScheme,
|
|
72
|
+
rawAuthCredential: this.authCredential,
|
|
73
|
+
credentialKey: this.credentialKey || "default_openapi_key"
|
|
74
|
+
};
|
|
75
|
+
const credential = this.context.getAuthResponse(authConfig);
|
|
76
|
+
if (credential) {
|
|
77
|
+
const exchanger = new AutoAuthCredentialExchanger();
|
|
78
|
+
const result = await exchanger.exchange({
|
|
79
|
+
authScheme: this.authScheme,
|
|
80
|
+
authCredential: credential
|
|
81
|
+
});
|
|
82
|
+
const key = store.getCredentialKey(this.authScheme);
|
|
83
|
+
store.storeCredential(key, result.credential);
|
|
84
|
+
return { state: "done", authCredential: result.credential };
|
|
85
|
+
}
|
|
86
|
+
this.context.requestCredential(authConfig);
|
|
87
|
+
return { state: "pending" };
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
__decorateClass([
|
|
91
|
+
experimental
|
|
92
|
+
], ToolAuthHandler.prototype, "prepareAuthCredentials", 1);
|
|
93
|
+
__decorateClass([
|
|
94
|
+
experimental
|
|
95
|
+
], ToolAuthHandler, "fromToolContext", 1);
|
|
96
|
+
ToolAuthHandler = __decorateClass([
|
|
97
|
+
experimental
|
|
98
|
+
], ToolAuthHandler);
|
|
99
|
+
export {
|
|
100
|
+
ToolAuthHandler
|
|
101
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
6
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
7
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
if (decorator = decorators[i])
|
|
9
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
10
|
+
if (kind && result) __defProp(target, key, result);
|
|
11
|
+
return result;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @license
|
|
15
|
+
* Copyright 2026 Google LLC
|
|
16
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
17
|
+
*/
|
|
18
|
+
import yaml from "js-yaml";
|
|
19
|
+
import { experimental } from "../../utils/experimental.js";
|
|
20
|
+
import { BaseToolset } from "../base_toolset.js";
|
|
21
|
+
import { OpenApiSpecParser } from "./openapi_spec_parser/openapi_spec_parser.js";
|
|
22
|
+
import { createRestApiTool } from "./rest_api_tool.js";
|
|
23
|
+
let OpenAPIToolset = class extends BaseToolset {
|
|
24
|
+
constructor(options = {}) {
|
|
25
|
+
super(options.toolFilter || [], options.prefix);
|
|
26
|
+
this.tools = [];
|
|
27
|
+
let spec = options.specDict;
|
|
28
|
+
if (!spec && options.specStr) {
|
|
29
|
+
if (options.specType === "yaml" || !options.specType && options.specStr.trim().startsWith("---")) {
|
|
30
|
+
spec = yaml.load(options.specStr);
|
|
31
|
+
} else {
|
|
32
|
+
spec = JSON.parse(options.specStr);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!spec) {
|
|
36
|
+
throw new Error("Either specDict or specStr must be provided.");
|
|
37
|
+
}
|
|
38
|
+
const parser = new OpenApiSpecParser({
|
|
39
|
+
preservePropertyNames: options.preservePropertyNames
|
|
40
|
+
});
|
|
41
|
+
const parsedOperations = parser.parse(spec);
|
|
42
|
+
for (const op of parsedOperations) {
|
|
43
|
+
let toolName = op.name;
|
|
44
|
+
if (this.prefix) {
|
|
45
|
+
toolName = "".concat(this.prefix, "_").concat(toolName);
|
|
46
|
+
}
|
|
47
|
+
const tool = createRestApiTool(
|
|
48
|
+
{
|
|
49
|
+
name: toolName,
|
|
50
|
+
description: op.description,
|
|
51
|
+
endpoint: op.endpoint,
|
|
52
|
+
operation: op.operation,
|
|
53
|
+
authScheme: op.authScheme
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
preservePropertyNames: options.preservePropertyNames,
|
|
57
|
+
headerProvider: options.headerProvider,
|
|
58
|
+
credentialKey: options.credentialKey
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
this.tools.push(tool);
|
|
62
|
+
}
|
|
63
|
+
if (options.authScheme || options.authCredential) {
|
|
64
|
+
for (const tool of this.tools) {
|
|
65
|
+
if (options.authScheme) tool.configureAuthScheme(options.authScheme);
|
|
66
|
+
if (options.authCredential)
|
|
67
|
+
tool.configureAuthCredential(options.authCredential);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async getTools(context) {
|
|
72
|
+
return this.tools.filter((tool) => {
|
|
73
|
+
if (Array.isArray(this.toolFilter) && this.toolFilter.length > 0) {
|
|
74
|
+
return this.toolFilter.includes(tool.name);
|
|
75
|
+
}
|
|
76
|
+
if (context) {
|
|
77
|
+
return this.isToolSelected(tool, context);
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async close() {
|
|
83
|
+
return Promise.resolve();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
__decorateClass([
|
|
87
|
+
experimental
|
|
88
|
+
], OpenAPIToolset.prototype, "getTools", 1);
|
|
89
|
+
__decorateClass([
|
|
90
|
+
experimental
|
|
91
|
+
], OpenAPIToolset.prototype, "close", 1);
|
|
92
|
+
OpenAPIToolset = __decorateClass([
|
|
93
|
+
experimental
|
|
94
|
+
], OpenAPIToolset);
|
|
95
|
+
export {
|
|
96
|
+
OpenAPIToolset
|
|
97
|
+
};
|