@google/adk 1.2.0 → 1.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/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +19 -1
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +35 -16
- package/dist/cjs/agents/instructions.js +99 -33
- package/dist/cjs/agents/invocation_context.js +2 -6
- package/dist/cjs/agents/llm_agent.js +60 -11
- 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/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +51 -25
- package/dist/cjs/agents/processors/content_request_processor.js +7 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +16 -2
- 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/interactions_request_processor.js +63 -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/apps/app.js +79 -0
- package/dist/cjs/apps/resumability_config.js +44 -0
- package/dist/cjs/artifacts/file_artifact_service.js +14 -1
- package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
- package/dist/cjs/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
- package/dist/cjs/artifacts/session_artifact_service.js +27 -0
- package/dist/cjs/auth/auth_preprocessor.js +12 -10
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/code_executors/code_executor_context.js +7 -7
- package/dist/cjs/common.js +86 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +11 -0
- package/dist/cjs/context/token_based_context_compactor.js +43 -11
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/event.js +25 -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 +51 -18
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/plugins/security_plugin.js +16 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +93 -72
- package/dist/cjs/sessions/base_session_service.js +19 -3
- package/dist/cjs/sessions/database_session_service.js +26 -9
- 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 +21 -5
- package/dist/cjs/skills/gcp_skill_registry.js +104 -0
- package/dist/cjs/skills/loader.js +67 -2
- package/dist/cjs/skills/skill_registry.js +27 -0
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- 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 +117 -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_hooks_shim.js +52 -0
- package/dist/cjs/utils/async_queue.js +88 -0
- package/dist/cjs/utils/case_utils.js +53 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +14 -1
- 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 +18 -11
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +19 -1
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +36 -15
- package/dist/esm/agents/instructions.js +99 -33
- package/dist/esm/agents/invocation_context.js +2 -6
- package/dist/esm/agents/llm_agent.js +61 -11
- 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/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +48 -24
- package/dist/esm/agents/processors/content_request_processor.js +7 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +16 -2
- 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/interactions_request_processor.js +34 -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/apps/app.js +49 -0
- package/dist/esm/apps/resumability_config.js +16 -0
- package/dist/esm/artifacts/file_artifact_service.js +14 -1
- package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
- package/dist/esm/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
- package/dist/esm/artifacts/session_artifact_service.js +7 -0
- package/dist/esm/auth/auth_preprocessor.js +12 -10
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/code_executors/code_executor_context.js +7 -7
- package/dist/esm/common.js +75 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +11 -0
- package/dist/esm/context/token_based_context_compactor.js +43 -11
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/event.js +23 -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 +49 -17
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/plugins/security_plugin.js +16 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +91 -73
- package/dist/esm/sessions/base_session_service.js +17 -2
- package/dist/esm/sessions/database_session_service.js +26 -9
- 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 +21 -5
- package/dist/esm/skills/gcp_skill_registry.js +78 -0
- package/dist/esm/skills/loader.js +66 -2
- package/dist/esm/skills/skill_registry.js +7 -0
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- 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 +91 -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_hooks_shim.js +24 -0
- package/dist/esm/utils/async_queue.js +60 -0
- package/dist/esm/utils/case_utils.js +25 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +14 -1
- 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 +18 -11
- package/dist/esm/utils/task.js +34 -0
- 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/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/functions.d.ts +12 -9
- package/dist/types/agents/invocation_context.d.ts +7 -12
- 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 +34 -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/interactions_request_processor.d.ts +17 -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/apps/app.d.ts +52 -0
- package/dist/types/apps/resumability_config.d.ts +27 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
- package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
- package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
- package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
- package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
- package/dist/types/common.d.ts +35 -4
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +17 -0
- package/dist/types/context/token_based_context_compactor.d.ts +6 -1
- package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
- package/dist/types/events/event.d.ts +8 -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/google_llm.d.ts +15 -1
- package/dist/types/models/interactions_utils.d.ts +92 -0
- package/dist/types/models/llm_request.d.ts +4 -0
- package/dist/types/models/llm_response.d.ts +14 -1
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/plugins/security_plugin.d.ts +30 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +43 -9
- package/dist/types/sessions/base_session_service.d.ts +7 -16
- package/dist/types/sessions/db/schema.d.ts +1 -0
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- 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/consolidate_context_tool.d.ts +19 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +3 -2
- 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_hooks_shim.d.ts +10 -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/client_labels.d.ts +10 -0
- package/dist/types/utils/env_aware_utils.d.ts +3 -3
- 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/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +31 -1
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +36 -15
- package/dist/web/agents/instructions.js +99 -33
- package/dist/web/agents/invocation_context.js +2 -6
- package/dist/web/agents/llm_agent.js +61 -11
- 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/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +66 -24
- package/dist/web/agents/processors/content_request_processor.js +7 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +16 -2
- 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/interactions_request_processor.js +52 -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/apps/app.js +49 -0
- package/dist/web/apps/resumability_config.js +31 -0
- package/dist/web/artifacts/file_artifact_service.js +14 -1
- package/dist/web/artifacts/gcs_artifact_service.js +55 -15
- package/dist/web/artifacts/in_memory_artifact_service.js +5 -1
- package/dist/web/artifacts/scoped_artifact_service.js +86 -0
- package/dist/web/artifacts/session_artifact_service.js +7 -0
- package/dist/web/auth/auth_preprocessor.js +12 -10
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/code_executors/code_executor_context.js +7 -7
- package/dist/web/common.js +75 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/summarizers/llm_summarizer.js +11 -0
- package/dist/web/context/token_based_context_compactor.js +43 -11
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/event.js +21 -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 +80 -17
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/plugins/security_plugin.js +16 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +111 -75
- package/dist/web/sessions/base_session_service.js +17 -2
- package/dist/web/sessions/database_session_service.js +26 -9
- 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 +21 -5
- package/dist/web/skills/gcp_skill_registry.js +78 -0
- package/dist/web/skills/loader.js +66 -2
- package/dist/web/skills/skill_registry.js +7 -0
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- 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 +91 -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_hooks_shim.js +24 -0
- package/dist/web/utils/async_queue.js +60 -0
- package/dist/web/utils/case_utils.js +25 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +14 -1
- 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 +18 -11
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +4 -2
|
@@ -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 = `${name}_${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: `${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,91 @@
|
|
|
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 `${schemeName}_existing_exchanged_credential`;
|
|
27
|
+
}
|
|
28
|
+
getCredential(authScheme) {
|
|
29
|
+
const key = this.getCredentialKey(authScheme);
|
|
30
|
+
return this.context.state.get(key);
|
|
31
|
+
}
|
|
32
|
+
storeCredential(key, credential) {
|
|
33
|
+
this.context.state.set(key, credential);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let ToolAuthHandler = class {
|
|
37
|
+
constructor(context, authScheme, authCredential, credentialKey) {
|
|
38
|
+
this.context = context;
|
|
39
|
+
this.authScheme = authScheme;
|
|
40
|
+
this.authCredential = authCredential;
|
|
41
|
+
this.credentialKey = credentialKey;
|
|
42
|
+
}
|
|
43
|
+
static fromToolContext(context, authScheme, authCredential, options = {}) {
|
|
44
|
+
return new ToolAuthHandler(
|
|
45
|
+
context,
|
|
46
|
+
authScheme,
|
|
47
|
+
authCredential,
|
|
48
|
+
options.credentialKey
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
async prepareAuthCredentials() {
|
|
52
|
+
if (!this.authScheme) {
|
|
53
|
+
return { state: "done" };
|
|
54
|
+
}
|
|
55
|
+
const store = new ToolContextCredentialStore(this.context);
|
|
56
|
+
const existingCredential = store.getCredential(this.authScheme);
|
|
57
|
+
if (existingCredential) {
|
|
58
|
+
return { state: "done", authCredential: existingCredential };
|
|
59
|
+
}
|
|
60
|
+
const authConfig = {
|
|
61
|
+
authScheme: this.authScheme,
|
|
62
|
+
rawAuthCredential: this.authCredential,
|
|
63
|
+
credentialKey: this.credentialKey || "default_openapi_key"
|
|
64
|
+
};
|
|
65
|
+
const credential = this.context.getAuthResponse(authConfig);
|
|
66
|
+
if (credential) {
|
|
67
|
+
const exchanger = new AutoAuthCredentialExchanger();
|
|
68
|
+
const result = await exchanger.exchange({
|
|
69
|
+
authScheme: this.authScheme,
|
|
70
|
+
authCredential: credential
|
|
71
|
+
});
|
|
72
|
+
const key = store.getCredentialKey(this.authScheme);
|
|
73
|
+
store.storeCredential(key, result.credential);
|
|
74
|
+
return { state: "done", authCredential: result.credential };
|
|
75
|
+
}
|
|
76
|
+
this.context.requestCredential(authConfig);
|
|
77
|
+
return { state: "pending" };
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
__decorateClass([
|
|
81
|
+
experimental
|
|
82
|
+
], ToolAuthHandler.prototype, "prepareAuthCredentials", 1);
|
|
83
|
+
__decorateClass([
|
|
84
|
+
experimental
|
|
85
|
+
], ToolAuthHandler, "fromToolContext", 1);
|
|
86
|
+
ToolAuthHandler = __decorateClass([
|
|
87
|
+
experimental
|
|
88
|
+
], ToolAuthHandler);
|
|
89
|
+
export {
|
|
90
|
+
ToolAuthHandler
|
|
91
|
+
};
|
|
@@ -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 = `${this.prefix}_${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
|
+
};
|
|
@@ -0,0 +1,229 @@
|
|
|
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 { BaseTool } from "../base_tool.js";
|
|
20
|
+
import { applyCredential } from "./auth/auth_helpers.js";
|
|
21
|
+
import {
|
|
22
|
+
OperationParser
|
|
23
|
+
} from "./openapi_spec_parser/operation_parser.js";
|
|
24
|
+
import { ToolAuthHandler } from "./openapi_spec_parser/tool_auth_handler.js";
|
|
25
|
+
let RestApiTool = class extends BaseTool {
|
|
26
|
+
constructor(name, description, endpoint, operation, authScheme, authCredential, options = {}) {
|
|
27
|
+
super({ name, description });
|
|
28
|
+
this.endpoint = endpoint;
|
|
29
|
+
this.operation = operation;
|
|
30
|
+
this.authScheme = authScheme;
|
|
31
|
+
this.authCredential = authCredential;
|
|
32
|
+
this.authScheme = authScheme;
|
|
33
|
+
this.authCredential = authCredential;
|
|
34
|
+
this.headerProvider = options.headerProvider;
|
|
35
|
+
this.credentialKey = options.credentialKey;
|
|
36
|
+
this.operationParser = new OperationParser(operation, options);
|
|
37
|
+
}
|
|
38
|
+
configureAuthScheme(authScheme) {
|
|
39
|
+
this.authScheme = authScheme;
|
|
40
|
+
}
|
|
41
|
+
configureAuthCredential(authCredential) {
|
|
42
|
+
this.authCredential = authCredential;
|
|
43
|
+
}
|
|
44
|
+
configureCredentialKey(credentialKey) {
|
|
45
|
+
this.credentialKey = credentialKey;
|
|
46
|
+
}
|
|
47
|
+
_getDeclaration() {
|
|
48
|
+
const schema = this.operationParser.getJsonSchema();
|
|
49
|
+
return {
|
|
50
|
+
name: this.name,
|
|
51
|
+
description: this.description,
|
|
52
|
+
parameters: schema
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async runAsync(request) {
|
|
56
|
+
const context = request.toolContext;
|
|
57
|
+
const args = request.args;
|
|
58
|
+
const authHandler = ToolAuthHandler.fromToolContext(
|
|
59
|
+
context,
|
|
60
|
+
this.authScheme,
|
|
61
|
+
this.authCredential,
|
|
62
|
+
{ credentialKey: this.credentialKey }
|
|
63
|
+
);
|
|
64
|
+
const authResult = await authHandler.prepareAuthCredentials();
|
|
65
|
+
if (authResult.state === "pending") {
|
|
66
|
+
return {
|
|
67
|
+
pending: true,
|
|
68
|
+
message: "Needs your authorization to access your data."
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const credential = authResult.authCredential;
|
|
72
|
+
const method = this.endpoint.method.toUpperCase();
|
|
73
|
+
const {
|
|
74
|
+
url: initialUrl,
|
|
75
|
+
headers,
|
|
76
|
+
body: parsedBody,
|
|
77
|
+
bodyData
|
|
78
|
+
} = prepareRequestParams(
|
|
79
|
+
this.endpoint,
|
|
80
|
+
this.operationParser.getParameters(),
|
|
81
|
+
args
|
|
82
|
+
);
|
|
83
|
+
const body = prepareRequestBody(
|
|
84
|
+
this.operation.requestBody,
|
|
85
|
+
parsedBody,
|
|
86
|
+
bodyData,
|
|
87
|
+
headers
|
|
88
|
+
);
|
|
89
|
+
const url = applyCredential(
|
|
90
|
+
initialUrl,
|
|
91
|
+
headers,
|
|
92
|
+
credential,
|
|
93
|
+
this.authScheme
|
|
94
|
+
);
|
|
95
|
+
if (this.headerProvider) {
|
|
96
|
+
const providerHeaders = this.headerProvider(context);
|
|
97
|
+
Object.assign(headers, providerHeaders);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const response = await globalThis.fetch(url, {
|
|
101
|
+
method,
|
|
102
|
+
headers,
|
|
103
|
+
// eslint-disable-next-line no-undef
|
|
104
|
+
body
|
|
105
|
+
});
|
|
106
|
+
const contentType = response.headers.get("content-type");
|
|
107
|
+
if (contentType && contentType.includes("application/json")) {
|
|
108
|
+
return await response.json();
|
|
109
|
+
} else {
|
|
110
|
+
return await response.text();
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
return {
|
|
114
|
+
error: `Failed to execute API call: ${error.message}`
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
__decorateClass([
|
|
120
|
+
experimental
|
|
121
|
+
], RestApiTool.prototype, "configureAuthScheme", 1);
|
|
122
|
+
__decorateClass([
|
|
123
|
+
experimental
|
|
124
|
+
], RestApiTool.prototype, "configureAuthCredential", 1);
|
|
125
|
+
__decorateClass([
|
|
126
|
+
experimental
|
|
127
|
+
], RestApiTool.prototype, "configureCredentialKey", 1);
|
|
128
|
+
__decorateClass([
|
|
129
|
+
experimental
|
|
130
|
+
], RestApiTool.prototype, "_getDeclaration", 1);
|
|
131
|
+
__decorateClass([
|
|
132
|
+
experimental
|
|
133
|
+
], RestApiTool.prototype, "runAsync", 1);
|
|
134
|
+
RestApiTool = __decorateClass([
|
|
135
|
+
experimental
|
|
136
|
+
], RestApiTool);
|
|
137
|
+
function prepareRequestParams(endpoint, parameters, args) {
|
|
138
|
+
const headers = {};
|
|
139
|
+
const queryParams = new URLSearchParams();
|
|
140
|
+
let body = void 0;
|
|
141
|
+
const paramsMap = new Map(parameters.map((p) => [p.name, p]));
|
|
142
|
+
const pathParams = {};
|
|
143
|
+
const bodyData = {};
|
|
144
|
+
for (const [argName, argValue] of Object.entries(args)) {
|
|
145
|
+
const param = paramsMap.get(argName);
|
|
146
|
+
if (!param) continue;
|
|
147
|
+
const originalName = param.originalName;
|
|
148
|
+
const location = param.paramLocation;
|
|
149
|
+
if (location === "path") {
|
|
150
|
+
pathParams[originalName] = String(argValue);
|
|
151
|
+
} else if (location === "query") {
|
|
152
|
+
queryParams.append(originalName, String(argValue));
|
|
153
|
+
} else if (location === "header") {
|
|
154
|
+
headers[originalName] = String(argValue);
|
|
155
|
+
} else if (location === "body") {
|
|
156
|
+
if (originalName === "body" || originalName === "array" || originalName === "") {
|
|
157
|
+
body = argValue;
|
|
158
|
+
} else {
|
|
159
|
+
bodyData[originalName] = argValue;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let url = `${endpoint.baseUrl}${endpoint.path}`;
|
|
164
|
+
for (const [key, value] of Object.entries(pathParams)) {
|
|
165
|
+
url = url.replace(`{${key}}`, value);
|
|
166
|
+
}
|
|
167
|
+
const urlParts = url.split("?");
|
|
168
|
+
if (urlParts.length > 1) {
|
|
169
|
+
const pathQueryParams = new URLSearchParams(urlParts[1]);
|
|
170
|
+
for (const [key, value] of pathQueryParams.entries()) {
|
|
171
|
+
queryParams.append(key, value);
|
|
172
|
+
}
|
|
173
|
+
url = urlParts[0];
|
|
174
|
+
}
|
|
175
|
+
const queryString = queryParams.toString();
|
|
176
|
+
if (queryString) {
|
|
177
|
+
url += `?${queryString}`;
|
|
178
|
+
}
|
|
179
|
+
return { url, headers, body, bodyData };
|
|
180
|
+
}
|
|
181
|
+
function prepareRequestBody(requestBody, body, bodyData, headers) {
|
|
182
|
+
const finalData = body !== void 0 ? body : Object.keys(bodyData).length > 0 ? bodyData : void 0;
|
|
183
|
+
if (requestBody && "content" in requestBody) {
|
|
184
|
+
const content = requestBody.content;
|
|
185
|
+
for (const [mimeType, _mediaTypeObject] of Object.entries(content)) {
|
|
186
|
+
if (finalData !== void 0) {
|
|
187
|
+
if (mimeType === "application/json" || mimeType.endsWith("+json")) {
|
|
188
|
+
headers["Content-Type"] = mimeType;
|
|
189
|
+
return typeof finalData === "string" ? finalData : JSON.stringify(finalData);
|
|
190
|
+
} else if (mimeType === "application/x-www-form-urlencoded") {
|
|
191
|
+
return new URLSearchParams(finalData);
|
|
192
|
+
} else if (mimeType === "multipart/form-data") {
|
|
193
|
+
const formData = new FormData();
|
|
194
|
+
if (typeof finalData === "object" && finalData !== null) {
|
|
195
|
+
for (const [key, value] of Object.entries(finalData)) {
|
|
196
|
+
formData.append(key, String(value));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return formData;
|
|
200
|
+
} else if (mimeType === "text/plain") {
|
|
201
|
+
headers["Content-Type"] = mimeType;
|
|
202
|
+
return String(finalData);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
} else if (finalData !== void 0) {
|
|
208
|
+
headers["Content-Type"] = "application/json";
|
|
209
|
+
return typeof finalData === "string" ? finalData : JSON.stringify(finalData);
|
|
210
|
+
}
|
|
211
|
+
return void 0;
|
|
212
|
+
}
|
|
213
|
+
function createRestApiTool(parsed, options = {}) {
|
|
214
|
+
return new RestApiTool(
|
|
215
|
+
parsed.name,
|
|
216
|
+
parsed.description,
|
|
217
|
+
parsed.endpoint,
|
|
218
|
+
parsed.operation,
|
|
219
|
+
parsed.authScheme,
|
|
220
|
+
void 0,
|
|
221
|
+
options
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
export {
|
|
225
|
+
RestApiTool,
|
|
226
|
+
createRestApiTool,
|
|
227
|
+
prepareRequestBody,
|
|
228
|
+
prepareRequestParams
|
|
229
|
+
};
|
|
@@ -51,7 +51,10 @@ let LoadSkillResourceTool = class extends BaseTool {
|
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
|
-
async runAsync({
|
|
54
|
+
async runAsync({
|
|
55
|
+
args,
|
|
56
|
+
toolContext
|
|
57
|
+
}) {
|
|
55
58
|
var _a, _b, _c;
|
|
56
59
|
const skillName = args["skill_name"];
|
|
57
60
|
let resourcePath = args["path"];
|
|
@@ -68,7 +71,18 @@ let LoadSkillResourceTool = class extends BaseTool {
|
|
|
68
71
|
};
|
|
69
72
|
}
|
|
70
73
|
resourcePath = path.posix.normalize(resourcePath);
|
|
71
|
-
|
|
74
|
+
let skill;
|
|
75
|
+
try {
|
|
76
|
+
skill = await this.toolset.getOrFetchSkill(
|
|
77
|
+
skillName,
|
|
78
|
+
toolContext.invocationId
|
|
79
|
+
);
|
|
80
|
+
} catch (e) {
|
|
81
|
+
return {
|
|
82
|
+
error: `Failed to fetch skill '${skillName}' from registry: ${e.message || e}`,
|
|
83
|
+
error_code: "REGISTRY_ERROR"
|
|
84
|
+
};
|
|
85
|
+
}
|
|
72
86
|
if (!skill) {
|
|
73
87
|
return {
|
|
74
88
|
error: `Skill '${skillName}' not found.`,
|
|
@@ -131,7 +145,15 @@ let LoadSkillResourceTool = class extends BaseTool {
|
|
|
131
145
|
if (response["status"] === BINARY_FILE_DETECTED_MSG) {
|
|
132
146
|
const skillName = response["skill_name"];
|
|
133
147
|
const resourcePath = response["path"];
|
|
134
|
-
|
|
148
|
+
let skill;
|
|
149
|
+
try {
|
|
150
|
+
skill = await this.toolset.getOrFetchSkill(
|
|
151
|
+
skillName,
|
|
152
|
+
request.toolContext.invocationId
|
|
153
|
+
);
|
|
154
|
+
} catch (_e) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
135
157
|
if (!skill) continue;
|
|
136
158
|
const skillResources = skill.resources || {};
|
|
137
159
|
let content;
|
|
@@ -53,7 +53,18 @@ let LoadSkillTool = class extends BaseTool {
|
|
|
53
53
|
error_code: "MISSING_SKILL_NAME"
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
let skill;
|
|
57
|
+
try {
|
|
58
|
+
skill = await this.toolset.getOrFetchSkill(
|
|
59
|
+
skillName,
|
|
60
|
+
toolContext.invocationId
|
|
61
|
+
);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return {
|
|
64
|
+
error: `Failed to fetch skill '${skillName}' from registry: ${e.message || e}`,
|
|
65
|
+
error_code: "REGISTRY_ERROR"
|
|
66
|
+
};
|
|
67
|
+
}
|
|
57
68
|
if (!skill) {
|
|
58
69
|
return {
|
|
59
70
|
error: `Skill '${skillName}' not found.`,
|
|
@@ -80,7 +80,18 @@ let RunSkillScriptTool = class extends BaseTool {
|
|
|
80
80
|
errorCode: "MISSING_SCRIPT_PATH"
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
let skill;
|
|
84
|
+
try {
|
|
85
|
+
skill = await this.toolset.getOrFetchSkill(
|
|
86
|
+
skillName,
|
|
87
|
+
toolContext.invocationId
|
|
88
|
+
);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return {
|
|
91
|
+
error: `Failed to fetch skill '${skillName}' from registry: ${e.message || e}`,
|
|
92
|
+
errorCode: "REGISTRY_ERROR"
|
|
93
|
+
};
|
|
94
|
+
}
|
|
84
95
|
if (!skill) {
|
|
85
96
|
return {
|
|
86
97
|
error: `Skill '${skillName}' not found.`,
|