@google/adk 2.2.1 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/a2a_remote_agent.js +4 -1
- package/dist/cjs/a2a/agent_card.js +102 -26
- package/dist/cjs/a2a/agent_to_a2a.js +1 -1
- package/dist/cjs/agents/functions.js +199 -25
- package/dist/cjs/agents/instructions.js +4 -1
- package/dist/cjs/agents/invocation_context.js +26 -4
- package/dist/cjs/agents/langgraph_agent.js +152 -0
- package/dist/cjs/agents/llm_agent.js +175 -101
- package/dist/cjs/agents/processors/code_execution_request_processor.js +10 -6
- package/dist/cjs/agents/remote_agent.js +187 -0
- package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/cjs/auth/auth_handler.js +37 -5
- package/dist/cjs/auth/auth_schemes.js +9 -0
- package/dist/cjs/cli/cli_eval.js +532 -0
- package/dist/cjs/cli/utils/envs.js +116 -0
- package/dist/cjs/cli/utils/evals.js +137 -0
- package/dist/cjs/cli/utils/logs.js +150 -0
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/cjs/code_executors/code_execution_utils.js +48 -16
- package/dist/cjs/code_executors/code_executor_context.js +6 -2
- package/dist/cjs/common.js +72 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
- package/dist/cjs/context/token_based_context_compactor.js +2 -1
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/examples/example_util.js +23 -2
- package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
- package/dist/cjs/index.js +97 -1
- package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +16 -8
- package/dist/cjs/models/google_llm.js +13 -16
- package/dist/cjs/models/llm_response.js +9 -1
- package/dist/cjs/models/registry.js +1 -1
- package/dist/cjs/models/routed_llm.js +9 -8
- package/dist/cjs/planners/plan_re_act_planner.js +1 -1
- package/dist/cjs/runner/in_memory_runner.js +6 -11
- package/dist/cjs/runner/runner.js +105 -33
- package/dist/cjs/sessions/db/operations.js +1 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -1
- package/dist/cjs/sessions/state.js +8 -4
- package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
- package/dist/cjs/telemetry/tracing.js +97 -66
- package/dist/cjs/tools/agent_tool.js +44 -0
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +142 -0
- package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
- package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
- package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +185 -0
- package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +603 -0
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +219 -0
- package/dist/cjs/tools/crewai_tool.js +132 -0
- package/dist/cjs/tools/example_tool.js +10 -0
- package/dist/cjs/tools/function_tool.js +319 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool.js +97 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +226 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +58 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
- package/dist/cjs/tools/google_api_tool/index.js +64 -0
- package/dist/cjs/tools/langchain_tool.js +172 -0
- package/dist/cjs/tools/mcp/index.js +12 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
- package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
- package/dist/cjs/tools/toolbox_tool.js +108 -0
- package/dist/cjs/utils/env_aware_utils.js +6 -8
- package/dist/cjs/utils/error_utils.js +11 -11
- package/dist/cjs/utils/file_extension_utils.js +11 -0
- package/dist/cjs/utils/file_utils.js +2 -24
- package/dist/cjs/utils/gemini_schema_util.js +4 -1
- package/dist/cjs/utils/json_utils.js +49 -0
- package/dist/cjs/utils/live_connection_utils.js +4 -5
- package/dist/cjs/utils/logger_node.js +7 -1
- package/dist/cjs/utils/object_notation_utils.js +6 -3
- package/dist/cjs/utils/streaming_utils.js +12 -12
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +4 -1
- package/dist/esm/a2a/agent_card.js +103 -27
- package/dist/esm/a2a/agent_to_a2a.js +5 -2
- package/dist/esm/agents/functions.js +198 -25
- package/dist/esm/agents/instructions.js +4 -1
- package/dist/esm/agents/invocation_context.js +24 -4
- package/dist/esm/agents/langgraph_agent.js +123 -0
- package/dist/esm/agents/llm_agent.js +185 -104
- package/dist/esm/agents/processors/code_execution_request_processor.js +13 -8
- package/dist/esm/agents/remote_agent.js +164 -0
- package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/esm/auth/auth_handler.js +37 -5
- package/dist/esm/auth/auth_schemes.js +8 -0
- package/dist/esm/cli/cli_eval.js +510 -0
- package/dist/esm/cli/utils/envs.js +78 -0
- package/dist/esm/cli/utils/evals.js +109 -0
- package/dist/esm/cli/utils/logs.js +111 -0
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/esm/code_executors/code_execution_utils.js +46 -16
- package/dist/esm/code_executors/code_executor_context.js +5 -2
- package/dist/esm/common.js +67 -3
- package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
- package/dist/esm/context/token_based_context_compactor.js +2 -1
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/examples/example_util.js +21 -1
- package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
- package/dist/esm/index.js +99 -1
- package/dist/esm/integrations/agent_registry/helpers.js +1 -1
- package/dist/esm/models/gemini_llm_connection.js +16 -8
- package/dist/esm/models/google_llm.js +14 -17
- package/dist/esm/models/llm_response.js +9 -1
- package/dist/esm/models/registry.js +1 -1
- package/dist/esm/models/routed_llm.js +9 -8
- package/dist/esm/planners/plan_re_act_planner.js +1 -1
- package/dist/esm/runner/in_memory_runner.js +6 -11
- package/dist/esm/runner/runner.js +105 -33
- package/dist/esm/sessions/db/operations.js +1 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -1
- package/dist/esm/sessions/state.js +8 -4
- package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
- package/dist/esm/telemetry/tracing.js +97 -66
- package/dist/esm/tools/agent_tool.js +44 -0
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +106 -0
- package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
- package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
- package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +163 -0
- package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +561 -0
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +215 -0
- package/dist/esm/tools/crewai_tool.js +107 -0
- package/dist/esm/tools/example_tool.js +13 -1
- package/dist/esm/tools/function_tool.js +316 -0
- package/dist/esm/tools/google_api_tool/google_api_tool.js +70 -0
- package/dist/esm/tools/google_api_tool/google_api_tool_set.js +188 -0
- package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +24 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
- package/dist/esm/tools/google_api_tool/index.js +33 -0
- package/dist/esm/tools/langchain_tool.js +148 -0
- package/dist/esm/tools/mcp/index.js +6 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
- package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
- package/dist/esm/tools/toolbox_tool.js +80 -0
- package/dist/esm/utils/env_aware_utils.js +6 -8
- package/dist/esm/utils/error_utils.js +9 -10
- package/dist/esm/utils/file_extension_utils.js +11 -0
- package/dist/esm/utils/file_utils.js +2 -23
- package/dist/esm/utils/gemini_schema_util.js +4 -1
- package/dist/esm/utils/json_utils.js +21 -0
- package/dist/esm/utils/live_connection_utils.js +4 -5
- package/dist/esm/utils/logger_node.js +7 -1
- package/dist/esm/utils/object_notation_utils.js +4 -2
- package/dist/esm/utils/streaming_utils.js +11 -11
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
- package/dist/types/a2a/agent_card.d.ts +44 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
- package/dist/types/a2a/index.d.ts +1 -0
- package/dist/types/agents/functions.d.ts +33 -1
- package/dist/types/agents/invocation_context.d.ts +20 -1
- package/dist/types/agents/langgraph_agent.d.ts +153 -0
- package/dist/types/agents/remote_agent.d.ts +68 -0
- package/dist/types/auth/auth_handler.d.ts +28 -1
- package/dist/types/auth/auth_schemes.d.ts +13 -0
- package/dist/types/cli/cli_eval.d.ts +173 -0
- package/dist/types/cli/utils/envs.d.ts +23 -0
- package/dist/types/cli/utils/evals.d.ts +47 -0
- package/dist/types/cli/utils/logs.d.ts +38 -0
- package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
- package/dist/types/code_executors/code_executor_context.d.ts +1 -0
- package/dist/types/common.d.ts +27 -4
- package/dist/types/events/event.d.ts +4 -0
- package/dist/types/examples/example_util.d.ts +17 -0
- package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
- package/dist/types/index.d.ts +16 -1
- package/dist/types/models/gemini_llm_connection.d.ts +6 -7
- package/dist/types/models/routed_llm.d.ts +1 -1
- package/dist/types/runner/in_memory_runner.d.ts +2 -1
- package/dist/types/runner/runner.d.ts +34 -0
- package/dist/types/sessions/state.d.ts +5 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +4 -2
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +122 -0
- package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
- package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
- package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
- package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +86 -0
- package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +215 -0
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
- package/dist/types/tools/crewai_tool.d.ts +85 -0
- package/dist/types/tools/example_tool.d.ts +10 -0
- package/dist/types/tools/function_tool.d.ts +32 -0
- package/dist/types/tools/google_api_tool/google_api_tool.d.ts +30 -0
- package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +78 -0
- package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +33 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +164 -0
- package/dist/types/tools/google_api_tool/index.d.ts +11 -0
- package/dist/types/tools/langchain_tool.d.ts +103 -0
- package/dist/types/tools/mcp/index.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
- package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
- package/dist/types/tools/toolbox_tool.d.ts +73 -0
- package/dist/types/utils/env_aware_utils.d.ts +18 -2
- package/dist/types/utils/error_utils.d.ts +7 -0
- package/dist/types/utils/file_utils.d.ts +6 -1
- package/dist/types/utils/gemini_schema_util.d.ts +1 -2
- package/dist/types/utils/json_utils.d.ts +11 -0
- package/dist/types/utils/object_notation_utils.d.ts +7 -0
- package/dist/types/utils/streaming_utils.d.ts +11 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +102 -103
- package/dist/web/index_web.js.map +4 -4
- package/package.json +8 -3
- package/dist/cjs/models/gemini_continuation.js +0 -232
- package/dist/esm/models/gemini_continuation.js +0 -205
- package/dist/types/models/gemini_continuation.d.ts +0 -59
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
7
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
8
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
9
|
+
if (decorator = decorators[i])
|
|
10
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
11
|
+
if (kind && result) __defProp(target, key, result);
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @license
|
|
16
|
+
* Copyright 2026 Google LLC
|
|
17
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
*/
|
|
19
|
+
import {
|
|
20
|
+
AuthCredentialTypes
|
|
21
|
+
} from "../../auth/auth_credential.js";
|
|
22
|
+
import { experimental } from "../../utils/experimental.js";
|
|
23
|
+
import { isJsonObject } from "../../utils/json_utils.js";
|
|
24
|
+
import { BaseToolset } from "../base_toolset.js";
|
|
25
|
+
import { serviceAccountDictToSchemeCredential } from "../openapi_tool/auth/auth_helpers.js";
|
|
26
|
+
import { OpenAPIToolset } from "../openapi_tool/openapi_toolset.js";
|
|
27
|
+
import { CLOUD_PLATFORM_SCOPE } from "./clients/cloud_request.js";
|
|
28
|
+
import {
|
|
29
|
+
ConnectionsClient
|
|
30
|
+
} from "./clients/connections_client.js";
|
|
31
|
+
import { IntegrationClient } from "./clients/integration_client.js";
|
|
32
|
+
const AUTH_SCHEME = {
|
|
33
|
+
type: "http",
|
|
34
|
+
scheme: "bearer",
|
|
35
|
+
bearerFormat: "JWT"
|
|
36
|
+
};
|
|
37
|
+
let ApplicationIntegrationToolset = class extends BaseToolset {
|
|
38
|
+
/**
|
|
39
|
+
* @throws Error Unless the options name either an integration and a trigger,
|
|
40
|
+
* or a connection with at least one entity operation or action.
|
|
41
|
+
*/
|
|
42
|
+
constructor(options) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
super([]);
|
|
45
|
+
const hasIntegration = Boolean(options.integration && options.trigger);
|
|
46
|
+
const hasConnection = Boolean(
|
|
47
|
+
options.connection && (Object.keys((_a = options.entityOperations) != null ? _a : {}).length > 0 || ((_b = options.actions) != null ? _b : []).length > 0)
|
|
48
|
+
);
|
|
49
|
+
if (!hasIntegration && !hasConnection) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Either (integration and trigger) or (connection and (entityOperations or actions)) should be provided."
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
this.options = options;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Returns the generated tools.
|
|
58
|
+
*
|
|
59
|
+
* The first call fetches the spec and builds the tools. Concurrent calls
|
|
60
|
+
* share that load. When it fails, the next call tries again.
|
|
61
|
+
*/
|
|
62
|
+
async getTools() {
|
|
63
|
+
if (!this.toolsPromise) {
|
|
64
|
+
this.toolsPromise = this.loadTools();
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
return await this.toolsPromise;
|
|
68
|
+
} catch (e) {
|
|
69
|
+
this.toolsPromise = void 0;
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async close() {
|
|
74
|
+
}
|
|
75
|
+
async loadTools() {
|
|
76
|
+
var _a;
|
|
77
|
+
const {
|
|
78
|
+
project,
|
|
79
|
+
location,
|
|
80
|
+
integration,
|
|
81
|
+
trigger,
|
|
82
|
+
connection,
|
|
83
|
+
entityOperations,
|
|
84
|
+
actions,
|
|
85
|
+
toolName = "",
|
|
86
|
+
toolInstructions = "",
|
|
87
|
+
serviceAccountJson
|
|
88
|
+
} = this.options;
|
|
89
|
+
const integrationClient = new IntegrationClient({
|
|
90
|
+
project,
|
|
91
|
+
location,
|
|
92
|
+
integration,
|
|
93
|
+
trigger,
|
|
94
|
+
connection,
|
|
95
|
+
entityOperations,
|
|
96
|
+
actions,
|
|
97
|
+
serviceAccountJson
|
|
98
|
+
});
|
|
99
|
+
let specDict;
|
|
100
|
+
if (integration && trigger) {
|
|
101
|
+
specDict = await integrationClient.getOpenApiSpecForIntegration();
|
|
102
|
+
} else {
|
|
103
|
+
const connectionName = connection != null ? connection : "";
|
|
104
|
+
const { serviceName, host } = await new ConnectionsClient({
|
|
105
|
+
project,
|
|
106
|
+
location,
|
|
107
|
+
connection: connectionName,
|
|
108
|
+
serviceAccountJson
|
|
109
|
+
}).getConnectionDetails();
|
|
110
|
+
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.`;
|
|
111
|
+
specDict = await integrationClient.getOpenApiSpecForConnection(
|
|
112
|
+
toolName,
|
|
113
|
+
instructions
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
const spec = specDict;
|
|
117
|
+
const authCredential = buildAuthCredential(serviceAccountJson);
|
|
118
|
+
const toolsByName = /* @__PURE__ */ new Map();
|
|
119
|
+
for (const [path, pathItem] of Object.entries((_a = spec.paths) != null ? _a : {})) {
|
|
120
|
+
const tools = await new OpenAPIToolset({
|
|
121
|
+
specDict: { ...spec, paths: { [removeFragment(path)]: pathItem } },
|
|
122
|
+
authCredential,
|
|
123
|
+
authScheme: AUTH_SCHEME
|
|
124
|
+
}).getTools();
|
|
125
|
+
for (const tool of tools) {
|
|
126
|
+
toolsByName.set(tool.name, tool);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return [...toolsByName.values()];
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
__name(ApplicationIntegrationToolset, "ApplicationIntegrationToolset");
|
|
133
|
+
ApplicationIntegrationToolset = __decorateClass([
|
|
134
|
+
experimental
|
|
135
|
+
], ApplicationIntegrationToolset);
|
|
136
|
+
function buildAuthCredential(serviceAccountJson) {
|
|
137
|
+
if (!serviceAccountJson) {
|
|
138
|
+
return {
|
|
139
|
+
authType: AuthCredentialTypes.SERVICE_ACCOUNT,
|
|
140
|
+
serviceAccount: {
|
|
141
|
+
useDefaultCredential: true,
|
|
142
|
+
scopes: [CLOUD_PLATFORM_SCOPE]
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const key = JSON.parse(serviceAccountJson);
|
|
147
|
+
if (!isJsonObject(key)) {
|
|
148
|
+
throw new Error("serviceAccountJson must hold a JSON object.");
|
|
149
|
+
}
|
|
150
|
+
const [, authCredential] = serviceAccountDictToSchemeCredential(key, [
|
|
151
|
+
CLOUD_PLATFORM_SCOPE
|
|
152
|
+
]);
|
|
153
|
+
return authCredential;
|
|
154
|
+
}
|
|
155
|
+
__name(buildAuthCredential, "buildAuthCredential");
|
|
156
|
+
function removeFragment(path) {
|
|
157
|
+
const fragmentStart = path.indexOf("#");
|
|
158
|
+
return fragmentStart === -1 ? path : path.slice(0, fragmentStart);
|
|
159
|
+
}
|
|
160
|
+
__name(removeFragment, "removeFragment");
|
|
161
|
+
export {
|
|
162
|
+
ApplicationIntegrationToolset
|
|
163
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
/**
|
|
6
|
+
* @license
|
|
7
|
+
* Copyright 2026 Google LLC
|
|
8
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
*/
|
|
10
|
+
import { GoogleAuth } from "google-auth-library";
|
|
11
|
+
import { getErrorMessage } from "../../../utils/error_utils.js";
|
|
12
|
+
const CLOUD_PLATFORM_SCOPE = "https://www.googleapis.com/auth/cloud-platform";
|
|
13
|
+
const MISSING_CREDENTIALS_MESSAGE = "Please provide a service account that has the required permissions to access the connection.";
|
|
14
|
+
function unexpectedError(e) {
|
|
15
|
+
return new Error(`An unexpected error occurred: ${getErrorMessage(e)}`, {
|
|
16
|
+
cause: e
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
__name(unexpectedError, "unexpectedError");
|
|
20
|
+
const _CloudPlatformTokenSource = class _CloudPlatformTokenSource {
|
|
21
|
+
constructor(serviceAccountJson) {
|
|
22
|
+
this.serviceAccountJson = serviceAccountJson;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns an access token.
|
|
26
|
+
*
|
|
27
|
+
* @throws Error When no key is given and Application Default Credentials are
|
|
28
|
+
* unavailable, or when no token is issued.
|
|
29
|
+
*/
|
|
30
|
+
async getAccessToken() {
|
|
31
|
+
let token;
|
|
32
|
+
try {
|
|
33
|
+
token = await this.getAuth().getAccessToken();
|
|
34
|
+
} catch (e) {
|
|
35
|
+
if (this.serviceAccountJson) {
|
|
36
|
+
throw e;
|
|
37
|
+
}
|
|
38
|
+
throw new Error(MISSING_CREDENTIALS_MESSAGE, { cause: e });
|
|
39
|
+
}
|
|
40
|
+
if (!token) {
|
|
41
|
+
throw new Error(MISSING_CREDENTIALS_MESSAGE);
|
|
42
|
+
}
|
|
43
|
+
return token;
|
|
44
|
+
}
|
|
45
|
+
getAuth() {
|
|
46
|
+
if (!this.auth) {
|
|
47
|
+
if (this.serviceAccountJson) {
|
|
48
|
+
const credentials = JSON.parse(this.serviceAccountJson);
|
|
49
|
+
this.auth = new GoogleAuth({
|
|
50
|
+
scopes: [CLOUD_PLATFORM_SCOPE],
|
|
51
|
+
credentials
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
this.auth = new GoogleAuth({ scopes: [CLOUD_PLATFORM_SCOPE] });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return this.auth;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
__name(_CloudPlatformTokenSource, "CloudPlatformTokenSource");
|
|
61
|
+
let CloudPlatformTokenSource = _CloudPlatformTokenSource;
|
|
62
|
+
async function sendCloudRequest(options) {
|
|
63
|
+
const { url, method, body, tokenSource, invalidRequestMessage } = options;
|
|
64
|
+
let token;
|
|
65
|
+
try {
|
|
66
|
+
token = await tokenSource.getAccessToken();
|
|
67
|
+
} catch (e) {
|
|
68
|
+
throw unexpectedError(e);
|
|
69
|
+
}
|
|
70
|
+
let response;
|
|
71
|
+
try {
|
|
72
|
+
response = await fetch(url, {
|
|
73
|
+
method,
|
|
74
|
+
headers: {
|
|
75
|
+
"Content-Type": "application/json",
|
|
76
|
+
"Authorization": `Bearer ${token}`
|
|
77
|
+
},
|
|
78
|
+
body: body === void 0 ? void 0 : JSON.stringify(body)
|
|
79
|
+
});
|
|
80
|
+
} catch (e) {
|
|
81
|
+
throw new Error(`Request error: ${getErrorMessage(e)}`, { cause: e });
|
|
82
|
+
}
|
|
83
|
+
if (response.status === 400 || response.status === 404) {
|
|
84
|
+
throw new Error(invalidRequestMessage);
|
|
85
|
+
}
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Request error: HTTP ${response.status} ${response.statusText} for url: ${url}`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
return await response.json();
|
|
93
|
+
} catch (e) {
|
|
94
|
+
throw unexpectedError(e);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
__name(sendCloudRequest, "sendCloudRequest");
|
|
98
|
+
export {
|
|
99
|
+
CLOUD_PLATFORM_SCOPE,
|
|
100
|
+
CloudPlatformTokenSource,
|
|
101
|
+
sendCloudRequest,
|
|
102
|
+
unexpectedError
|
|
103
|
+
};
|