@google/adk 2.1.0 → 2.2.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/agent_card.js +8 -0
- package/dist/cjs/a2a/agent_executor.js +8 -3
- package/dist/cjs/agents/llm_agent.js +15 -1
- package/dist/cjs/agents/processors/content_processor_utils.js +10 -2
- package/dist/cjs/agents/processors/nl_planning_processor.js +114 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +13 -7
- package/dist/cjs/auth/auth_credential.js +12 -2
- package/dist/cjs/code_executors/code_execution_utils.js +3 -3
- package/dist/cjs/common.js +45 -0
- package/dist/cjs/examples/example.js +92 -0
- package/dist/cjs/examples/example_util.js +28 -4
- package/dist/cjs/examples/index.js +39 -0
- package/dist/cjs/examples/vertex_ai_example_store.js +39 -0
- package/dist/cjs/index.js +46 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +17 -5
- package/dist/cjs/models/base_llm.js +1 -6
- package/dist/cjs/models/chrome_prompt_llm.js +16 -2
- package/dist/cjs/models/chrome_prompt_utils.js +54 -2
- package/dist/cjs/models/gemini_llm_connection.js +5 -4
- package/dist/cjs/planners/base_planner.js +56 -0
- package/dist/cjs/planners/built_in_planner.js +85 -0
- package/dist/cjs/planners/plan_re_act_planner.js +172 -0
- package/dist/cjs/plugins/base_plugin.js +46 -61
- package/dist/cjs/tools/example_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +14 -8
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +281 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +70 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +120 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -10
- package/dist/cjs/tools/openapi_tool/common/common.js +139 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +73 -13
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -34
- package/dist/cjs/tools/openapi_tool/openapi_toolset.js +14 -2
- package/dist/cjs/tools/openapi_tool/rest_api_tool.js +90 -28
- package/dist/cjs/tools/skill/skill_toolset.js +2 -0
- package/dist/cjs/tools/tool_context.js +41 -0
- package/dist/cjs/tools/webmcp/index.js +37 -0
- package/dist/cjs/tools/webmcp/webmcp_tool.js +156 -0
- package/dist/cjs/tools/webmcp/webmcp_toolset.js +116 -0
- package/dist/cjs/tools/webmcp/webmcp_types.js +50 -0
- package/dist/cjs/utils/case_utils.js +52 -2
- package/dist/cjs/utils/client_labels.js +67 -0
- package/dist/cjs/utils/gemini_schema_util.js +103 -3
- package/dist/cjs/utils/hash_utils.js +73 -0
- package/dist/cjs/utils/live_connection_utils.js +10 -9
- package/dist/cjs/utils/model_name.js +17 -2
- package/dist/cjs/utils/simple_zod_to_json.js +5 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_card.js +8 -0
- package/dist/esm/a2a/agent_executor.js +8 -3
- package/dist/esm/agents/llm_agent.js +18 -1
- package/dist/esm/agents/processors/content_processor_utils.js +10 -2
- package/dist/esm/agents/processors/nl_planning_processor.js +87 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +13 -7
- package/dist/esm/auth/auth_credential.js +11 -1
- package/dist/esm/code_executors/code_execution_utils.js +3 -3
- package/dist/esm/common.js +38 -2
- package/dist/esm/examples/example.js +85 -0
- package/dist/esm/examples/example_util.js +25 -3
- package/dist/esm/examples/index.js +11 -0
- package/dist/esm/examples/vertex_ai_example_store.js +11 -0
- package/dist/esm/index.js +51 -1
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +17 -5
- package/dist/esm/models/base_llm.js +2 -7
- package/dist/esm/models/chrome_prompt_llm.js +20 -3
- package/dist/esm/models/chrome_prompt_utils.js +51 -2
- package/dist/esm/models/gemini_llm_connection.js +6 -5
- package/dist/esm/planners/base_planner.js +28 -0
- package/dist/esm/planners/built_in_planner.js +57 -0
- package/dist/esm/planners/plan_re_act_planner.js +145 -0
- package/dist/esm/plugins/base_plugin.js +46 -61
- package/dist/esm/tools/example_tool.js +1 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +14 -8
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +272 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +43 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +93 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -12
- package/dist/esm/tools/openapi_tool/common/common.js +112 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +80 -13
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -33
- package/dist/esm/tools/openapi_tool/openapi_toolset.js +14 -2
- package/dist/esm/tools/openapi_tool/rest_api_tool.js +89 -28
- package/dist/esm/tools/skill/skill_toolset.js +2 -0
- package/dist/esm/tools/tool_context.js +15 -0
- package/dist/esm/tools/webmcp/index.js +10 -0
- package/dist/esm/tools/webmcp/webmcp_tool.js +131 -0
- package/dist/esm/tools/webmcp/webmcp_toolset.js +89 -0
- package/dist/esm/tools/webmcp/webmcp_types.js +22 -0
- package/dist/esm/utils/case_utils.js +49 -1
- package/dist/esm/utils/client_labels.js +65 -0
- package/dist/esm/utils/gemini_schema_util.js +102 -3
- package/dist/esm/utils/hash_utils.js +45 -0
- package/dist/esm/utils/live_connection_utils.js +11 -10
- package/dist/esm/utils/model_name.js +15 -2
- package/dist/esm/utils/simple_zod_to_json.js +5 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/agents/llm_agent.d.ts +12 -1
- package/dist/types/agents/processors/nl_planning_processor.d.ts +30 -0
- package/dist/types/auth/auth_credential.d.ts +9 -0
- package/dist/types/common.d.ts +16 -4
- package/dist/types/examples/base_example_provider.d.ts +2 -2
- package/dist/types/examples/example.d.ts +75 -0
- package/dist/types/examples/example_util.d.ts +13 -2
- package/dist/types/examples/index.d.ts +18 -0
- package/dist/types/examples/vertex_ai_example_store.d.ts +7 -0
- package/dist/types/index.d.ts +12 -3
- package/dist/types/memory/memory_entry.d.ts +15 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +9 -0
- package/dist/types/models/chrome_prompt_utils.d.ts +29 -0
- package/dist/types/planners/base_planner.d.ts +50 -0
- package/dist/types/planners/built_in_planner.d.ts +53 -0
- package/dist/types/planners/plan_re_act_planner.d.ts +21 -0
- package/dist/types/plugins/base_plugin.d.ts +52 -52
- package/dist/types/skills/skill_registry.d.ts +8 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +110 -1
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +32 -2
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.d.ts +35 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.d.ts +54 -0
- package/dist/types/tools/openapi_tool/common/common.d.ts +60 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +7 -0
- package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +56 -2
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +73 -5
- package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +11 -0
- package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +42 -8
- package/dist/types/tools/tool_context.d.ts +19 -0
- package/dist/types/tools/webmcp/index.d.ts +12 -0
- package/dist/types/tools/webmcp/webmcp_tool.d.ts +47 -0
- package/dist/types/tools/webmcp/webmcp_toolset.d.ts +67 -0
- package/dist/types/tools/webmcp/webmcp_types.d.ts +69 -0
- package/dist/types/utils/case_utils.d.ts +36 -0
- package/dist/types/utils/client_labels.d.ts +33 -0
- package/dist/types/utils/gemini_schema_util.d.ts +13 -0
- package/dist/types/utils/hash_utils.d.ts +25 -0
- package/dist/types/utils/logger.d.ts +10 -2
- package/dist/types/utils/model_name.d.ts +30 -2
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +112 -79
- package/dist/web/index_web.js.map +4 -4
- package/package.json +8 -2
|
@@ -25,17 +25,90 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
25
25
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
26
|
var auth_helpers_exports = {};
|
|
27
27
|
__export(auth_helpers_exports, {
|
|
28
|
+
INTERNAL_AUTH_PREFIX: () => INTERNAL_AUTH_PREFIX,
|
|
28
29
|
applyCredential: () => applyCredential,
|
|
29
30
|
createApiKeyScheme: () => createApiKeyScheme,
|
|
30
|
-
createBearerScheme: () => createBearerScheme
|
|
31
|
+
createBearerScheme: () => createBearerScheme,
|
|
32
|
+
credentialToParam: () => credentialToParam,
|
|
33
|
+
dictToAuthScheme: () => dictToAuthScheme,
|
|
34
|
+
openidDictToSchemeCredential: () => openidDictToSchemeCredential,
|
|
35
|
+
openidUrlToSchemeCredential: () => openidUrlToSchemeCredential,
|
|
36
|
+
serviceAccountDictToSchemeCredential: () => serviceAccountDictToSchemeCredential,
|
|
37
|
+
serviceAccountSchemeCredential: () => serviceAccountSchemeCredential,
|
|
38
|
+
tokenToSchemeCredential: () => tokenToSchemeCredential
|
|
31
39
|
});
|
|
32
40
|
module.exports = __toCommonJS(auth_helpers_exports);
|
|
41
|
+
var import_zod = require("zod");
|
|
33
42
|
var import_auth_credential = require("../../../auth/auth_credential.js");
|
|
43
|
+
var import_case_utils = require("../../../utils/case_utils.js");
|
|
34
44
|
/**
|
|
35
45
|
* @license
|
|
36
46
|
* Copyright 2026 Google LLC
|
|
37
47
|
* SPDX-License-Identifier: Apache-2.0
|
|
38
48
|
*/
|
|
49
|
+
const INTERNAL_AUTH_PREFIX = "_auth_prefix_vaf_";
|
|
50
|
+
const API_KEY_LOCATIONS = ["header", "query", "cookie"];
|
|
51
|
+
const OPENID_FETCH_TIMEOUT_MS = 1e4;
|
|
52
|
+
const REQUIRED_CREDENTIAL_FIELDS = ["client_id", "client_secret"];
|
|
53
|
+
const scopesSchema = import_zod.z.record(import_zod.z.string(), import_zod.z.string()).default({});
|
|
54
|
+
const OAuthFlowsSchema = import_zod.z.looseObject({
|
|
55
|
+
implicit: import_zod.z.looseObject({
|
|
56
|
+
authorizationUrl: import_zod.z.string(),
|
|
57
|
+
refreshUrl: import_zod.z.string().optional(),
|
|
58
|
+
scopes: scopesSchema
|
|
59
|
+
}).optional(),
|
|
60
|
+
password: import_zod.z.looseObject({
|
|
61
|
+
tokenUrl: import_zod.z.string(),
|
|
62
|
+
refreshUrl: import_zod.z.string().optional(),
|
|
63
|
+
scopes: scopesSchema
|
|
64
|
+
}).optional(),
|
|
65
|
+
clientCredentials: import_zod.z.looseObject({
|
|
66
|
+
tokenUrl: import_zod.z.string(),
|
|
67
|
+
refreshUrl: import_zod.z.string().optional(),
|
|
68
|
+
scopes: scopesSchema
|
|
69
|
+
}).optional(),
|
|
70
|
+
authorizationCode: import_zod.z.looseObject({
|
|
71
|
+
authorizationUrl: import_zod.z.string(),
|
|
72
|
+
tokenUrl: import_zod.z.string(),
|
|
73
|
+
refreshUrl: import_zod.z.string().optional(),
|
|
74
|
+
scopes: scopesSchema
|
|
75
|
+
}).optional()
|
|
76
|
+
});
|
|
77
|
+
const ApiKeySchemeSchema = import_zod.z.looseObject({
|
|
78
|
+
type: import_zod.z.literal("apiKey"),
|
|
79
|
+
description: import_zod.z.string().optional(),
|
|
80
|
+
name: import_zod.z.string(),
|
|
81
|
+
in: import_zod.z.enum(API_KEY_LOCATIONS)
|
|
82
|
+
});
|
|
83
|
+
const HttpSchemeSchema = import_zod.z.looseObject({
|
|
84
|
+
type: import_zod.z.literal("http"),
|
|
85
|
+
description: import_zod.z.string().optional(),
|
|
86
|
+
scheme: import_zod.z.string(),
|
|
87
|
+
bearerFormat: import_zod.z.string().optional()
|
|
88
|
+
});
|
|
89
|
+
const Oauth2SchemeSchema = import_zod.z.looseObject({
|
|
90
|
+
type: import_zod.z.literal("oauth2"),
|
|
91
|
+
description: import_zod.z.string().optional(),
|
|
92
|
+
flows: OAuthFlowsSchema
|
|
93
|
+
});
|
|
94
|
+
const OpenIdConnectSchemeSchema = import_zod.z.looseObject({
|
|
95
|
+
type: import_zod.z.literal("openIdConnect"),
|
|
96
|
+
description: import_zod.z.string().optional(),
|
|
97
|
+
openIdConnectUrl: import_zod.z.string()
|
|
98
|
+
});
|
|
99
|
+
const OpenIdConnectConfigSchema = import_zod.z.looseObject({
|
|
100
|
+
type: import_zod.z.literal("openIdConnect").default("openIdConnect"),
|
|
101
|
+
description: import_zod.z.string().optional(),
|
|
102
|
+
openIdConnectUrl: import_zod.z.string().default(""),
|
|
103
|
+
authorizationEndpoint: import_zod.z.string(),
|
|
104
|
+
tokenEndpoint: import_zod.z.string(),
|
|
105
|
+
userinfoEndpoint: import_zod.z.string().optional(),
|
|
106
|
+
revocationEndpoint: import_zod.z.string().optional(),
|
|
107
|
+
tokenEndpointAuthMethodsSupported: import_zod.z.array(import_zod.z.string()).optional(),
|
|
108
|
+
grantTypesSupported: import_zod.z.array(import_zod.z.string()).optional(),
|
|
109
|
+
scopes: import_zod.z.array(import_zod.z.string()).optional()
|
|
110
|
+
});
|
|
111
|
+
const JsonObjectSchema = import_zod.z.record(import_zod.z.string(), import_zod.z.unknown());
|
|
39
112
|
function applyCredential(url, headers, credential, authScheme) {
|
|
40
113
|
var _a;
|
|
41
114
|
if (!credential) return url;
|
|
@@ -83,9 +156,215 @@ function createBearerScheme() {
|
|
|
83
156
|
};
|
|
84
157
|
}
|
|
85
158
|
__name(createBearerScheme, "createBearerScheme");
|
|
159
|
+
function isApiKeyLocation(value) {
|
|
160
|
+
return API_KEY_LOCATIONS.some((location) => location === value);
|
|
161
|
+
}
|
|
162
|
+
__name(isApiKeyLocation, "isApiKeyLocation");
|
|
163
|
+
function bearerJwtScheme() {
|
|
164
|
+
return { type: "http", scheme: "bearer", bearerFormat: "JWT" };
|
|
165
|
+
}
|
|
166
|
+
__name(bearerJwtScheme, "bearerJwtScheme");
|
|
167
|
+
function bearerTokenParam(authScheme, token) {
|
|
168
|
+
var _a;
|
|
169
|
+
const param = {
|
|
170
|
+
originalName: "Authorization",
|
|
171
|
+
paramLocation: "header",
|
|
172
|
+
paramSchema: { type: "string" },
|
|
173
|
+
description: (_a = authScheme.description) != null ? _a : "Bearer token",
|
|
174
|
+
name: `${INTERNAL_AUTH_PREFIX}Authorization`,
|
|
175
|
+
required: true
|
|
176
|
+
};
|
|
177
|
+
return [param, { [param.name]: `Bearer ${token}` }];
|
|
178
|
+
}
|
|
179
|
+
__name(bearerTokenParam, "bearerTokenParam");
|
|
180
|
+
function tokenToSchemeCredential(tokenType, location, name, credentialValue) {
|
|
181
|
+
if (tokenType === "apikey") {
|
|
182
|
+
if (!isApiKeyLocation(location)) {
|
|
183
|
+
throw new Error(`Invalid location for apiKey: ${location}`);
|
|
184
|
+
}
|
|
185
|
+
const authScheme = {
|
|
186
|
+
type: "apiKey",
|
|
187
|
+
in: location,
|
|
188
|
+
name: name != null ? name : ""
|
|
189
|
+
};
|
|
190
|
+
const authCredential = credentialValue ? { authType: import_auth_credential.AuthCredentialTypes.API_KEY, apiKey: credentialValue } : void 0;
|
|
191
|
+
return [authScheme, authCredential];
|
|
192
|
+
}
|
|
193
|
+
if (tokenType === "oauth2Token") {
|
|
194
|
+
const authCredential = credentialValue ? {
|
|
195
|
+
authType: import_auth_credential.AuthCredentialTypes.HTTP,
|
|
196
|
+
http: { scheme: "bearer", credentials: { token: credentialValue } }
|
|
197
|
+
} : void 0;
|
|
198
|
+
return [bearerJwtScheme(), authCredential];
|
|
199
|
+
}
|
|
200
|
+
throw new Error(`Invalid security scheme type: ${tokenType}`);
|
|
201
|
+
}
|
|
202
|
+
__name(tokenToSchemeCredential, "tokenToSchemeCredential");
|
|
203
|
+
function serviceAccountDictToSchemeCredential(config, scopes) {
|
|
204
|
+
const authCredential = {
|
|
205
|
+
authType: import_auth_credential.AuthCredentialTypes.SERVICE_ACCOUNT,
|
|
206
|
+
serviceAccount: {
|
|
207
|
+
// The reference calls `ServiceAccountCredential.model_construct`, which
|
|
208
|
+
// skips validation on purpose, so the port does not validate either.
|
|
209
|
+
serviceAccountCredential: (0, import_case_utils.camelCaseKeys)(
|
|
210
|
+
config
|
|
211
|
+
),
|
|
212
|
+
scopes
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
return [bearerJwtScheme(), authCredential];
|
|
216
|
+
}
|
|
217
|
+
__name(serviceAccountDictToSchemeCredential, "serviceAccountDictToSchemeCredential");
|
|
218
|
+
function serviceAccountSchemeCredential(config) {
|
|
219
|
+
const authCredential = {
|
|
220
|
+
authType: import_auth_credential.AuthCredentialTypes.SERVICE_ACCOUNT,
|
|
221
|
+
serviceAccount: config
|
|
222
|
+
};
|
|
223
|
+
return [bearerJwtScheme(), authCredential];
|
|
224
|
+
}
|
|
225
|
+
__name(serviceAccountSchemeCredential, "serviceAccountSchemeCredential");
|
|
226
|
+
function openidDictToSchemeCredential(configDict, scopes, credentialDict) {
|
|
227
|
+
const parsedConfig = OpenIdConnectConfigSchema.safeParse(
|
|
228
|
+
(0, import_case_utils.camelCaseKeys)(configDict)
|
|
229
|
+
);
|
|
230
|
+
if (!parsedConfig.success) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
`Invalid OpenID Connect configuration: ${import_zod.z.prettifyError(parsedConfig.error)}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
const openidScheme = { ...parsedConfig.data, scopes };
|
|
236
|
+
const values = Object.values(credentialDict);
|
|
237
|
+
if (values.length === 1) {
|
|
238
|
+
const wrapped = JsonObjectSchema.safeParse(values[0]);
|
|
239
|
+
if (wrapped.success && "client_id" in wrapped.data && "client_secret" in wrapped.data) {
|
|
240
|
+
credentialDict = wrapped.data;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const missingFields = REQUIRED_CREDENTIAL_FIELDS.filter(
|
|
244
|
+
(field) => !(field in credentialDict)
|
|
245
|
+
);
|
|
246
|
+
if (missingFields.length > 0) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
`Missing required fields in credential_dict: ${missingFields.join(", ")}`
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
const authCredential = {
|
|
252
|
+
authType: import_auth_credential.AuthCredentialTypes.OPEN_ID_CONNECT,
|
|
253
|
+
oauth2: {
|
|
254
|
+
clientId: String(credentialDict["client_id"]),
|
|
255
|
+
clientSecret: String(credentialDict["client_secret"]),
|
|
256
|
+
redirectUri: "redirect_uri" in credentialDict ? String(credentialDict["redirect_uri"]) : void 0
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
return [openidScheme, authCredential];
|
|
260
|
+
}
|
|
261
|
+
__name(openidDictToSchemeCredential, "openidDictToSchemeCredential");
|
|
262
|
+
async function openidUrlToSchemeCredential(openidUrl, scopes, credentialDict) {
|
|
263
|
+
let response;
|
|
264
|
+
try {
|
|
265
|
+
response = await fetch(openidUrl, {
|
|
266
|
+
signal: AbortSignal.timeout(OPENID_FETCH_TIMEOUT_MS)
|
|
267
|
+
});
|
|
268
|
+
if (!response.ok) {
|
|
269
|
+
throw new Error(`responded with status ${response.status}`);
|
|
270
|
+
}
|
|
271
|
+
} catch (e) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`Failed to fetch OpenID configuration from ${openidUrl}: ${String(e)}`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
let configDict;
|
|
277
|
+
try {
|
|
278
|
+
configDict = JsonObjectSchema.parse(await response.json());
|
|
279
|
+
} catch (e) {
|
|
280
|
+
throw new Error(
|
|
281
|
+
`Invalid JSON response from OpenID configuration endpoint ${openidUrl}: ${String(e)}`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
return openidDictToSchemeCredential(
|
|
285
|
+
{ ...configDict, openIdConnectUrl: openidUrl },
|
|
286
|
+
scopes,
|
|
287
|
+
credentialDict
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
__name(openidUrlToSchemeCredential, "openidUrlToSchemeCredential");
|
|
291
|
+
function credentialToParam(authScheme, authCredential) {
|
|
292
|
+
var _a, _b, _c, _d;
|
|
293
|
+
if (!authCredential) {
|
|
294
|
+
return [void 0, void 0];
|
|
295
|
+
}
|
|
296
|
+
if (authScheme.type === "apiKey" && authCredential.apiKey) {
|
|
297
|
+
if (!isApiKeyLocation(authScheme.in)) {
|
|
298
|
+
throw new Error(`Invalid API Key location: ${authScheme.in}`);
|
|
299
|
+
}
|
|
300
|
+
const paramName = authScheme.name || "";
|
|
301
|
+
const param = {
|
|
302
|
+
originalName: paramName,
|
|
303
|
+
paramLocation: authScheme.in,
|
|
304
|
+
paramSchema: { type: "string" },
|
|
305
|
+
description: (_a = authScheme.description) != null ? _a : "",
|
|
306
|
+
name: INTERNAL_AUTH_PREFIX + paramName,
|
|
307
|
+
required: true
|
|
308
|
+
};
|
|
309
|
+
return [param, { [param.name]: authCredential.apiKey }];
|
|
310
|
+
}
|
|
311
|
+
if (authCredential.authType === import_auth_credential.AuthCredentialTypes.HTTP) {
|
|
312
|
+
const credentials = (_b = authCredential.http) == null ? void 0 : _b.credentials;
|
|
313
|
+
if (credentials == null ? void 0 : credentials.token) {
|
|
314
|
+
return bearerTokenParam(authScheme, credentials.token);
|
|
315
|
+
}
|
|
316
|
+
if ((credentials == null ? void 0 : credentials.username) || (credentials == null ? void 0 : credentials.password)) {
|
|
317
|
+
throw new Error("Basic Authentication is not supported.");
|
|
318
|
+
}
|
|
319
|
+
throw new Error("Invalid HTTP auth credentials");
|
|
320
|
+
}
|
|
321
|
+
if (authScheme.type === "oauth2" || authScheme.type === "openIdConnect") {
|
|
322
|
+
const token = (_d = (_c = authCredential.http) == null ? void 0 : _c.credentials) == null ? void 0 : _d.token;
|
|
323
|
+
return token ? bearerTokenParam(authScheme, token) : [void 0, void 0];
|
|
324
|
+
}
|
|
325
|
+
throw new Error("Invalid security scheme and credential combination");
|
|
326
|
+
}
|
|
327
|
+
__name(credentialToParam, "credentialToParam");
|
|
328
|
+
function parseSecurityScheme(schema, data) {
|
|
329
|
+
const result = schema.safeParse(data);
|
|
330
|
+
if (!result.success) {
|
|
331
|
+
throw new Error(
|
|
332
|
+
`Invalid security scheme data: ${import_zod.z.prettifyError(result.error)}`
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
return result.data;
|
|
336
|
+
}
|
|
337
|
+
__name(parseSecurityScheme, "parseSecurityScheme");
|
|
338
|
+
function dictToAuthScheme(data) {
|
|
339
|
+
if (!("type" in data)) {
|
|
340
|
+
throw new Error("Missing 'type' field in security scheme dictionary.");
|
|
341
|
+
}
|
|
342
|
+
const securityType = data["type"];
|
|
343
|
+
switch (securityType) {
|
|
344
|
+
case "apiKey":
|
|
345
|
+
return parseSecurityScheme(ApiKeySchemeSchema, data);
|
|
346
|
+
case "http":
|
|
347
|
+
return parseSecurityScheme(HttpSchemeSchema, data);
|
|
348
|
+
case "oauth2":
|
|
349
|
+
return parseSecurityScheme(Oauth2SchemeSchema, data);
|
|
350
|
+
case "openIdConnect":
|
|
351
|
+
return parseSecurityScheme(OpenIdConnectSchemeSchema, data);
|
|
352
|
+
default:
|
|
353
|
+
throw new Error(`Invalid security scheme type: ${securityType}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
__name(dictToAuthScheme, "dictToAuthScheme");
|
|
86
357
|
// Annotate the CommonJS export names for ESM import in node:
|
|
87
358
|
0 && (module.exports = {
|
|
359
|
+
INTERNAL_AUTH_PREFIX,
|
|
88
360
|
applyCredential,
|
|
89
361
|
createApiKeyScheme,
|
|
90
|
-
createBearerScheme
|
|
362
|
+
createBearerScheme,
|
|
363
|
+
credentialToParam,
|
|
364
|
+
dictToAuthScheme,
|
|
365
|
+
openidDictToSchemeCredential,
|
|
366
|
+
openidUrlToSchemeCredential,
|
|
367
|
+
serviceAccountDictToSchemeCredential,
|
|
368
|
+
serviceAccountSchemeCredential,
|
|
369
|
+
tokenToSchemeCredential
|
|
91
370
|
});
|
package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js
CHANGED
|
@@ -46,7 +46,12 @@ var import_service_account_exchanger = require("./service_account_exchanger.js")
|
|
|
46
46
|
* SPDX-License-Identifier: Apache-2.0
|
|
47
47
|
*/
|
|
48
48
|
let AutoAuthCredentialExchanger = class {
|
|
49
|
-
|
|
49
|
+
/**
|
|
50
|
+
* @param customExchangers - Optional exchangers that add to or override the
|
|
51
|
+
* built-in ones. The key is the auth credential type; the value is the
|
|
52
|
+
* exchanger instance to use for that type.
|
|
53
|
+
*/
|
|
54
|
+
constructor(customExchangers) {
|
|
50
55
|
this.exchangers = /* @__PURE__ */ new Map();
|
|
51
56
|
this.exchangers.set(
|
|
52
57
|
import_auth_credential.AuthCredentialTypes.OAUTH2,
|
|
@@ -60,9 +65,18 @@ let AutoAuthCredentialExchanger = class {
|
|
|
60
65
|
import_auth_credential.AuthCredentialTypes.SERVICE_ACCOUNT,
|
|
61
66
|
new import_service_account_exchanger.ServiceAccountCredentialExchanger()
|
|
62
67
|
);
|
|
68
|
+
for (const authType of Object.values(import_auth_credential.AuthCredentialTypes)) {
|
|
69
|
+
const customExchanger = customExchangers == null ? void 0 : customExchangers[authType];
|
|
70
|
+
if (customExchanger) {
|
|
71
|
+
this.exchangers.set(authType, customExchanger);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
63
74
|
}
|
|
64
75
|
async exchange(params) {
|
|
65
76
|
const { authCredential, authScheme } = params;
|
|
77
|
+
if (!authCredential) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
66
80
|
const exchanger = this.exchangers.get(authCredential.authType);
|
|
67
81
|
if (!exchanger) {
|
|
68
82
|
return {
|
package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
27
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
28
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
29
|
+
if (decorator = decorators[i])
|
|
30
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
31
|
+
if (kind && result) __defProp(target, key, result);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
var base_auth_credential_exchanger_exports = {};
|
|
35
|
+
__export(base_auth_credential_exchanger_exports, {
|
|
36
|
+
AuthCredentialMissingError: () => AuthCredentialMissingError,
|
|
37
|
+
BaseAuthCredentialExchanger: () => BaseAuthCredentialExchanger
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(base_auth_credential_exchanger_exports);
|
|
40
|
+
var import_experimental = require("../../../../utils/experimental.js");
|
|
41
|
+
/**
|
|
42
|
+
* @license
|
|
43
|
+
* Copyright 2026 Google LLC
|
|
44
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
45
|
+
*/
|
|
46
|
+
const _AuthCredentialMissingError = class _AuthCredentialMissingError extends Error {
|
|
47
|
+
constructor(message) {
|
|
48
|
+
super(message);
|
|
49
|
+
this.name = "AuthCredentialMissingError";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
__name(_AuthCredentialMissingError, "AuthCredentialMissingError");
|
|
53
|
+
let AuthCredentialMissingError = _AuthCredentialMissingError;
|
|
54
|
+
let BaseAuthCredentialExchanger = class {
|
|
55
|
+
exchangeCredential(_authScheme, _authCredential) {
|
|
56
|
+
throw new Error("Subclasses must implement exchangeCredential.");
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
__name(BaseAuthCredentialExchanger, "BaseAuthCredentialExchanger");
|
|
60
|
+
__decorateClass([
|
|
61
|
+
import_experimental.experimental
|
|
62
|
+
], BaseAuthCredentialExchanger.prototype, "exchangeCredential", 1);
|
|
63
|
+
BaseAuthCredentialExchanger = __decorateClass([
|
|
64
|
+
import_experimental.experimental
|
|
65
|
+
], BaseAuthCredentialExchanger);
|
|
66
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
67
|
+
0 && (module.exports = {
|
|
68
|
+
AuthCredentialMissingError,
|
|
69
|
+
BaseAuthCredentialExchanger
|
|
70
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __defProp = Object.defineProperty;
|
|
9
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
10
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
|
+
var __export = (target, all) => {
|
|
14
|
+
for (var name in all)
|
|
15
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
27
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
28
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
29
|
+
if (decorator = decorators[i])
|
|
30
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
31
|
+
if (kind && result) __defProp(target, key, result);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
var oauth2_exchanger_exports = {};
|
|
35
|
+
__export(oauth2_exchanger_exports, {
|
|
36
|
+
OAuth2BearerExchanger: () => OAuth2BearerExchanger,
|
|
37
|
+
checkSchemeCredentialType: () => checkSchemeCredentialType,
|
|
38
|
+
exchangeCredential: () => exchangeCredential,
|
|
39
|
+
generateAuthToken: () => generateAuthToken
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(oauth2_exchanger_exports);
|
|
42
|
+
var import_auth_credential = require("../../../../auth/auth_credential.js");
|
|
43
|
+
var import_experimental = require("../../../../utils/experimental.js");
|
|
44
|
+
/**
|
|
45
|
+
* @license
|
|
46
|
+
* Copyright 2026 Google LLC
|
|
47
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
48
|
+
*/
|
|
49
|
+
function checkSchemeCredentialType(authScheme, authCredential) {
|
|
50
|
+
if (!authCredential) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
"auth_credential is empty. Please create AuthCredential using OAuth2Auth."
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
if (authScheme.type !== "openIdConnect" && authScheme.type !== "oauth2") {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Invalid security scheme, expect AuthSchemeType.openIdConnect or AuthSchemeType.oauth2 auth scheme, but got ${authScheme.type}`
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
if (!authCredential.oauth2 && !authCredential.http) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
"auth_credential is not configured with oauth2. Please create AuthCredential and set OAuth2Auth."
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
__name(checkSchemeCredentialType, "checkSchemeCredentialType");
|
|
67
|
+
function generateAuthToken(authCredential) {
|
|
68
|
+
var _a;
|
|
69
|
+
const accessToken = (_a = authCredential.oauth2) == null ? void 0 : _a.accessToken;
|
|
70
|
+
if (!accessToken) {
|
|
71
|
+
return authCredential;
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
authType: import_auth_credential.AuthCredentialTypes.HTTP,
|
|
75
|
+
http: {
|
|
76
|
+
scheme: "bearer",
|
|
77
|
+
credentials: { token: accessToken }
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
__name(generateAuthToken, "generateAuthToken");
|
|
82
|
+
function exchangeCredential(authScheme, authCredential) {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
checkSchemeCredentialType(authScheme, authCredential);
|
|
85
|
+
if (authCredential.http) {
|
|
86
|
+
return authCredential;
|
|
87
|
+
}
|
|
88
|
+
if (((_a = authCredential.oauth2) == null ? void 0 : _a.accessToken) || ((_b = authCredential.oauth2) == null ? void 0 : _b.refreshToken)) {
|
|
89
|
+
return generateAuthToken(authCredential);
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
__name(exchangeCredential, "exchangeCredential");
|
|
94
|
+
let OAuth2BearerExchanger = class {
|
|
95
|
+
async exchange(params) {
|
|
96
|
+
const { authScheme, authCredential } = params;
|
|
97
|
+
if (!authScheme) {
|
|
98
|
+
throw new Error("authScheme is required for OAuth2 credential exchange");
|
|
99
|
+
}
|
|
100
|
+
const credential = exchangeCredential(authScheme, authCredential);
|
|
101
|
+
return {
|
|
102
|
+
credential: credential != null ? credential : authCredential,
|
|
103
|
+
wasExchanged: credential !== null && credential !== authCredential
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
__name(OAuth2BearerExchanger, "OAuth2BearerExchanger");
|
|
108
|
+
__decorateClass([
|
|
109
|
+
import_experimental.experimental
|
|
110
|
+
], OAuth2BearerExchanger.prototype, "exchange", 1);
|
|
111
|
+
OAuth2BearerExchanger = __decorateClass([
|
|
112
|
+
import_experimental.experimental
|
|
113
|
+
], OAuth2BearerExchanger);
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
0 && (module.exports = {
|
|
116
|
+
OAuth2BearerExchanger,
|
|
117
|
+
checkSchemeCredentialType,
|
|
118
|
+
exchangeCredential,
|
|
119
|
+
generateAuthToken
|
|
120
|
+
});
|
|
@@ -38,21 +38,20 @@ __export(service_account_exchanger_exports, {
|
|
|
38
38
|
module.exports = __toCommonJS(service_account_exchanger_exports);
|
|
39
39
|
var import_google_auth_library = require("google-auth-library");
|
|
40
40
|
var import_auth_credential = require("../../../../auth/auth_credential.js");
|
|
41
|
-
var import_base_credential_exchanger = require("../../../../auth/exchanger/base_credential_exchanger.js");
|
|
42
41
|
var import_experimental = require("../../../../utils/experimental.js");
|
|
42
|
+
var import_base_auth_credential_exchanger = require("./base_auth_credential_exchanger.js");
|
|
43
43
|
/**
|
|
44
44
|
* @license
|
|
45
45
|
* Copyright 2026 Google LLC
|
|
46
46
|
* SPDX-License-Identifier: Apache-2.0
|
|
47
47
|
*/
|
|
48
48
|
const DEFAULT_SCOPES = ["https://www.googleapis.com/auth/cloud-platform"];
|
|
49
|
+
const MISSING_SERVICE_ACCOUNT_CREDENTIALS = "Service account credentials are missing. Please provide them, or set `useDefaultCredential: true` to use application default credentials in a hosted service like Cloud Run.";
|
|
49
50
|
let ServiceAccountCredentialExchanger = class {
|
|
50
51
|
async exchange(params) {
|
|
51
52
|
const { authCredential } = params;
|
|
52
|
-
if (
|
|
53
|
-
throw new
|
|
54
|
-
"Invalid credential type for ServiceAccountCredentialExchanger"
|
|
55
|
-
);
|
|
53
|
+
if (!authCredential.serviceAccount) {
|
|
54
|
+
throw new import_base_auth_credential_exchanger.AuthCredentialMissingError(MISSING_SERVICE_ACCOUNT_CREDENTIALS);
|
|
56
55
|
}
|
|
57
56
|
const saConfig = authCredential.serviceAccount;
|
|
58
57
|
if (saConfig.useDefaultCredential) {
|
|
@@ -82,7 +81,7 @@ let ServiceAccountCredentialExchanger = class {
|
|
|
82
81
|
wasExchanged: true
|
|
83
82
|
};
|
|
84
83
|
} catch (error) {
|
|
85
|
-
throw new
|
|
84
|
+
throw new import_base_auth_credential_exchanger.AuthCredentialMissingError(
|
|
86
85
|
`Failed to exchange default service account token: ${error.message}`
|
|
87
86
|
);
|
|
88
87
|
}
|
|
@@ -90,14 +89,15 @@ let ServiceAccountCredentialExchanger = class {
|
|
|
90
89
|
async exchangeForExplicitCredential(saConfig) {
|
|
91
90
|
const creds = saConfig.serviceAccountCredential;
|
|
92
91
|
if (!creds) {
|
|
93
|
-
throw new
|
|
94
|
-
"Service account credentials are missing."
|
|
95
|
-
);
|
|
92
|
+
throw new import_base_auth_credential_exchanger.AuthCredentialMissingError(MISSING_SERVICE_ACCOUNT_CREDENTIALS);
|
|
96
93
|
}
|
|
97
94
|
try {
|
|
98
95
|
const client = new import_google_auth_library.JWT({
|
|
99
96
|
email: creds.clientEmail,
|
|
100
97
|
key: creds.privateKey,
|
|
98
|
+
keyId: creds.privateKeyId,
|
|
99
|
+
projectId: creds.projectId,
|
|
100
|
+
universeDomain: creds.universeDomain,
|
|
101
101
|
scopes: saConfig.scopes
|
|
102
102
|
});
|
|
103
103
|
const tokens = await client.authorize();
|
|
@@ -116,7 +116,7 @@ let ServiceAccountCredentialExchanger = class {
|
|
|
116
116
|
wasExchanged: true
|
|
117
117
|
};
|
|
118
118
|
} catch (error) {
|
|
119
|
-
throw new
|
|
119
|
+
throw new import_base_auth_credential_exchanger.AuthCredentialMissingError(
|
|
120
120
|
`Failed to exchange explicit service account token: ${error.message}`
|
|
121
121
|
);
|
|
122
122
|
}
|