@softactivate/adk 1.1.0 → 1.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/agents/functions.js +4 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +305 -0
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/common.js +3 -0
- package/dist/cjs/events/event.js +2 -0
- package/dist/cjs/index.js +14 -0
- package/dist/cjs/integrations/agent_registry/agent_registry.js +362 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +103 -0
- package/dist/cjs/integrations/agent_registry/helpers.js +57 -0
- package/dist/cjs/integrations/agent_registry/types.js +50 -0
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +496 -0
- package/dist/cjs/runner/in_memory_runner.js +10 -5
- package/dist/cjs/runner/runner.js +32 -2
- package/dist/cjs/sessions/database_session_service.js +49 -3
- package/dist/cjs/sessions/in_memory_session_service.js +70 -14
- package/dist/cjs/sessions/registry.js +4 -0
- package/dist/cjs/sessions/vertex_ai_session_service.js +428 -0
- package/dist/cjs/tools/agent_tool.js +17 -8
- package/dist/cjs/tools/exit_loop_tool.js +9 -0
- package/dist/cjs/tools/function_tool.js +7 -2
- package/dist/cjs/tools/long_running_tool.js +2 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/cjs/tools/mcp/mcp_tool.js +10 -7
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -2
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +78 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +84 -0
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +133 -0
- package/dist/cjs/tools/skill/load_skill_resource_tool.js +2 -25
- package/dist/cjs/utils/file_utils.js +28 -0
- package/dist/cjs/utils/gemini_schema_util.js +18 -0
- package/dist/cjs/utils/partial_copy.js +51 -0
- package/dist/cjs/utils/streaming_utils.js +167 -118
- package/dist/cjs/utils/vertex_ai_utils.js +50 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/functions.js +4 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/esm/code_executors/code_execution_utils.js +1 -1
- package/dist/esm/common.js +2 -0
- package/dist/esm/events/event.js +2 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +77 -0
- package/dist/esm/integrations/agent_registry/helpers.js +28 -0
- package/dist/esm/integrations/agent_registry/types.js +20 -0
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +468 -0
- package/dist/esm/runner/in_memory_runner.js +10 -5
- package/dist/esm/runner/runner.js +32 -2
- package/dist/esm/sessions/database_session_service.js +49 -3
- package/dist/esm/sessions/in_memory_session_service.js +70 -14
- package/dist/esm/sessions/registry.js +7 -0
- package/dist/esm/sessions/vertex_ai_session_service.js +403 -0
- package/dist/esm/tools/agent_tool.js +17 -8
- package/dist/esm/tools/exit_loop_tool.js +9 -0
- package/dist/esm/tools/function_tool.js +7 -2
- package/dist/esm/tools/long_running_tool.js +2 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/esm/tools/mcp/mcp_tool.js +10 -7
- package/dist/esm/tools/mcp/mcp_toolset.js +10 -2
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/esm/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/esm/utils/file_utils.js +26 -0
- package/dist/esm/utils/gemini_schema_util.js +18 -0
- package/dist/esm/utils/partial_copy.js +23 -0
- package/dist/esm/utils/streaming_utils.js +165 -117
- package/dist/esm/utils/vertex_ai_utils.js +22 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +14 -0
- package/dist/types/agents/processors/base_llm_processor.d.ts +12 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +4 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +5 -0
- package/dist/types/agents/run_config.d.ts +15 -0
- package/dist/types/code_executors/agent_engine_sandbox_code_executor.d.ts +51 -0
- package/dist/types/common.d.ts +2 -0
- package/dist/types/events/event_actions.d.ts +24 -6
- package/dist/types/events/structured_events.d.ts +13 -0
- package/dist/types/examples/example_util.d.ts +25 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/integrations/agent_registry/agent_registry.d.ts +94 -0
- package/dist/types/integrations/agent_registry/agent_registry_mcp_toolset.d.ts +43 -0
- package/dist/types/integrations/agent_registry/helpers.d.ts +7 -0
- package/dist/types/integrations/agent_registry/types.d.ts +101 -0
- package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +52 -0
- package/dist/types/runner/in_memory_runner.d.ts +28 -1
- package/dist/types/runner/runner.d.ts +47 -0
- package/dist/types/sessions/base_session_service.d.ts +18 -0
- package/dist/types/sessions/database_session_service.d.ts +1 -1
- package/dist/types/sessions/in_memory_session_service.d.ts +1 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +37 -0
- package/dist/types/tools/exit_loop_tool.d.ts +9 -0
- package/dist/types/tools/function_tool.d.ts +22 -2
- package/dist/types/tools/long_running_tool.d.ts +11 -1
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +3 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +25 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +20 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.d.ts +20 -0
- package/dist/types/utils/file_utils.d.ts +2 -0
- package/dist/types/utils/partial_copy.d.ts +13 -0
- package/dist/types/utils/streaming_utils.d.ts +8 -17
- package/dist/types/utils/vertex_ai_utils.d.ts +14 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/functions.js +4 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +26 -2
- package/dist/web/code_executors/agent_engine_sandbox_code_executor.js +281 -0
- package/dist/web/code_executors/code_execution_utils.js +1 -1
- package/dist/web/common.js +2 -0
- package/dist/web/events/event.js +2 -0
- package/dist/web/index.js +11 -0
- package/dist/web/integrations/agent_registry/agent_registry.js +333 -0
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +90 -0
- package/dist/web/integrations/agent_registry/helpers.js +28 -0
- package/dist/web/integrations/agent_registry/types.js +20 -0
- package/dist/web/memory/vertex_ai_memory_bank_service.js +475 -0
- package/dist/web/runner/in_memory_runner.js +10 -5
- package/dist/web/runner/runner.js +32 -2
- package/dist/web/sessions/database_session_service.js +49 -3
- package/dist/web/sessions/in_memory_session_service.js +70 -14
- package/dist/web/sessions/registry.js +7 -0
- package/dist/web/sessions/vertex_ai_session_service.js +414 -0
- package/dist/web/tools/agent_tool.js +17 -8
- package/dist/web/tools/exit_loop_tool.js +9 -0
- package/dist/web/tools/function_tool.js +7 -2
- package/dist/web/tools/long_running_tool.js +2 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +11 -0
- package/dist/web/tools/mcp/mcp_tool.js +10 -7
- package/dist/web/tools/mcp/mcp_toolset.js +10 -2
- package/dist/web/tools/openapi_tool/auth/auth_helpers.js +48 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +60 -0
- package/dist/web/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +111 -0
- package/dist/web/tools/skill/load_skill_resource_tool.js +1 -24
- package/dist/web/utils/file_utils.js +26 -0
- package/dist/web/utils/gemini_schema_util.js +18 -0
- package/dist/web/utils/partial_copy.js +23 -0
- package/dist/web/utils/streaming_utils.js +218 -117
- package/dist/web/utils/vertex_ai_utils.js +22 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -1
|
@@ -26,13 +26,16 @@ class MCPTool extends BaseTool {
|
|
|
26
26
|
}
|
|
27
27
|
async runAsync(request) {
|
|
28
28
|
const session = await this.mcpSessionManager.createSession();
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
try {
|
|
30
|
+
const callRequest = {};
|
|
31
|
+
callRequest.params = { name: this.originalName, arguments: request.args };
|
|
32
|
+
const result = await session.callTool(callRequest.params, void 0, {
|
|
33
|
+
signal: request.toolContext.abortSignal
|
|
34
|
+
});
|
|
35
|
+
return result;
|
|
36
|
+
} finally {
|
|
37
|
+
await this.mcpSessionManager.closeSession(session);
|
|
38
|
+
}
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
export {
|
|
@@ -35,8 +35,12 @@ class MCPToolset extends BaseToolset {
|
|
|
35
35
|
}
|
|
36
36
|
async getTools(context) {
|
|
37
37
|
const session = await this.mcpSessionManager.createSession();
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
let listResult;
|
|
39
|
+
try {
|
|
40
|
+
listResult = await session.listTools();
|
|
41
|
+
} finally {
|
|
42
|
+
await this.mcpSessionManager.closeSession(session);
|
|
43
|
+
}
|
|
40
44
|
logger.debug("number of tools: ".concat(listResult.tools.length));
|
|
41
45
|
for (const tool of listResult.tools) {
|
|
42
46
|
logger.debug("tool: ".concat(tool.name));
|
|
@@ -63,6 +67,10 @@ class MCPToolset extends BaseToolset {
|
|
|
63
67
|
return tools;
|
|
64
68
|
}
|
|
65
69
|
async close() {
|
|
70
|
+
const sessions = this.mcpSessionManager.getActiveSessions();
|
|
71
|
+
await Promise.allSettled(
|
|
72
|
+
sessions.map((session) => this.mcpSessionManager.closeSession(session))
|
|
73
|
+
);
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
export {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
function applyCredential(url, headers, credential, authScheme) {
|
|
9
|
+
if (!credential) return url;
|
|
10
|
+
if (credential.apiKey) {
|
|
11
|
+
let inLocation;
|
|
12
|
+
let name = "key";
|
|
13
|
+
if (authScheme && authScheme.type === "apiKey") {
|
|
14
|
+
const apiKeyScheme = authScheme;
|
|
15
|
+
inLocation = apiKeyScheme.in;
|
|
16
|
+
name = apiKeyScheme.name;
|
|
17
|
+
}
|
|
18
|
+
if (inLocation === "header") {
|
|
19
|
+
headers[name] = credential.apiKey;
|
|
20
|
+
} else if (inLocation === "query") {
|
|
21
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
22
|
+
url += "".concat(separator).concat(name, "=").concat(encodeURIComponent(credential.apiKey));
|
|
23
|
+
} else {
|
|
24
|
+
headers["Authorization"] = credential.apiKey;
|
|
25
|
+
}
|
|
26
|
+
} else if (credential.http && credential.http.credentials && credential.http.credentials.token) {
|
|
27
|
+
headers["Authorization"] = "Bearer ".concat(credential.http.credentials.token);
|
|
28
|
+
}
|
|
29
|
+
return url;
|
|
30
|
+
}
|
|
31
|
+
function createApiKeyScheme(name, inLocation) {
|
|
32
|
+
return {
|
|
33
|
+
type: "apiKey",
|
|
34
|
+
name,
|
|
35
|
+
in: inLocation
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function createBearerScheme() {
|
|
39
|
+
return {
|
|
40
|
+
type: "http",
|
|
41
|
+
scheme: "bearer"
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
applyCredential,
|
|
46
|
+
createApiKeyScheme,
|
|
47
|
+
createBearerScheme
|
|
48
|
+
};
|
package/dist/web/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
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 {
|
|
19
|
+
AuthCredentialTypes
|
|
20
|
+
} from "../../../../auth/auth_credential.js";
|
|
21
|
+
import { OAuth2CredentialExchanger } from "../../../../auth/oauth2/oauth2_credential_exchanger.js";
|
|
22
|
+
import { experimental } from "../../../../utils/experimental.js";
|
|
23
|
+
import { ServiceAccountCredentialExchanger } from "./service_account_exchanger.js";
|
|
24
|
+
let AutoAuthCredentialExchanger = class {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.exchangers = /* @__PURE__ */ new Map();
|
|
27
|
+
this.exchangers.set(
|
|
28
|
+
AuthCredentialTypes.OAUTH2,
|
|
29
|
+
new OAuth2CredentialExchanger()
|
|
30
|
+
);
|
|
31
|
+
this.exchangers.set(
|
|
32
|
+
AuthCredentialTypes.OPEN_ID_CONNECT,
|
|
33
|
+
new OAuth2CredentialExchanger()
|
|
34
|
+
);
|
|
35
|
+
this.exchangers.set(
|
|
36
|
+
AuthCredentialTypes.SERVICE_ACCOUNT,
|
|
37
|
+
new ServiceAccountCredentialExchanger()
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
async exchange(params) {
|
|
41
|
+
const { authCredential, authScheme } = params;
|
|
42
|
+
const exchanger = this.exchangers.get(authCredential.authType);
|
|
43
|
+
if (!exchanger) {
|
|
44
|
+
return {
|
|
45
|
+
credential: authCredential,
|
|
46
|
+
wasExchanged: false
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return exchanger.exchange({ authScheme, authCredential });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
__decorateClass([
|
|
53
|
+
experimental
|
|
54
|
+
], AutoAuthCredentialExchanger.prototype, "exchange", 1);
|
|
55
|
+
AutoAuthCredentialExchanger = __decorateClass([
|
|
56
|
+
experimental
|
|
57
|
+
], AutoAuthCredentialExchanger);
|
|
58
|
+
export {
|
|
59
|
+
AutoAuthCredentialExchanger
|
|
60
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
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 { GoogleAuth, JWT } from "google-auth-library";
|
|
19
|
+
import {
|
|
20
|
+
AuthCredentialTypes
|
|
21
|
+
} from "../../../../auth/auth_credential.js";
|
|
22
|
+
import {
|
|
23
|
+
CredentialExchangeError
|
|
24
|
+
} from "../../../../auth/exchanger/base_credential_exchanger.js";
|
|
25
|
+
import { experimental } from "../../../../utils/experimental.js";
|
|
26
|
+
const DEFAULT_SCOPES = ["https://www.googleapis.com/auth/cloud-platform"];
|
|
27
|
+
let ServiceAccountCredentialExchanger = class {
|
|
28
|
+
async exchange(params) {
|
|
29
|
+
const { authCredential } = params;
|
|
30
|
+
if (authCredential.authType !== AuthCredentialTypes.SERVICE_ACCOUNT || !authCredential.serviceAccount) {
|
|
31
|
+
throw new CredentialExchangeError(
|
|
32
|
+
"Invalid credential type for ServiceAccountCredentialExchanger"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
const saConfig = authCredential.serviceAccount;
|
|
36
|
+
if (saConfig.useDefaultCredential) {
|
|
37
|
+
return this.exchangeForDefaultCredential(saConfig);
|
|
38
|
+
}
|
|
39
|
+
return this.exchangeForExplicitCredential(saConfig);
|
|
40
|
+
}
|
|
41
|
+
async exchangeForDefaultCredential(saConfig) {
|
|
42
|
+
try {
|
|
43
|
+
const auth = new GoogleAuth({
|
|
44
|
+
scopes: saConfig.scopes || DEFAULT_SCOPES
|
|
45
|
+
});
|
|
46
|
+
const client = await auth.getClient();
|
|
47
|
+
const tokenResponse = await client.getAccessToken();
|
|
48
|
+
const token = tokenResponse.token;
|
|
49
|
+
if (!token) {
|
|
50
|
+
throw new Error("Failed to get access token from default credentials");
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
credential: {
|
|
54
|
+
authType: AuthCredentialTypes.HTTP,
|
|
55
|
+
http: {
|
|
56
|
+
scheme: "bearer",
|
|
57
|
+
credentials: { token }
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
wasExchanged: true
|
|
61
|
+
};
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw new CredentialExchangeError(
|
|
64
|
+
"Failed to exchange default service account token: ".concat(error.message)
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async exchangeForExplicitCredential(saConfig) {
|
|
69
|
+
const creds = saConfig.serviceAccountCredential;
|
|
70
|
+
if (!creds) {
|
|
71
|
+
throw new CredentialExchangeError(
|
|
72
|
+
"Service account credentials are missing."
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const client = new JWT({
|
|
77
|
+
email: creds.clientEmail,
|
|
78
|
+
key: creds.privateKey,
|
|
79
|
+
scopes: saConfig.scopes
|
|
80
|
+
});
|
|
81
|
+
const tokens = await client.authorize();
|
|
82
|
+
const token = tokens.access_token;
|
|
83
|
+
if (!token) {
|
|
84
|
+
throw new Error("Failed to get access token from explicit credentials");
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
credential: {
|
|
88
|
+
authType: AuthCredentialTypes.HTTP,
|
|
89
|
+
http: {
|
|
90
|
+
scheme: "bearer",
|
|
91
|
+
credentials: { token }
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
wasExchanged: true
|
|
95
|
+
};
|
|
96
|
+
} catch (error) {
|
|
97
|
+
throw new CredentialExchangeError(
|
|
98
|
+
"Failed to exchange explicit service account token: ".concat(error.message)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
__decorateClass([
|
|
104
|
+
experimental
|
|
105
|
+
], ServiceAccountCredentialExchanger.prototype, "exchange", 1);
|
|
106
|
+
ServiceAccountCredentialExchanger = __decorateClass([
|
|
107
|
+
experimental
|
|
108
|
+
], ServiceAccountCredentialExchanger);
|
|
109
|
+
export {
|
|
110
|
+
ServiceAccountCredentialExchanger
|
|
111
|
+
};
|
|
@@ -18,34 +18,11 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
18
18
|
import { Type } from "@google/genai";
|
|
19
19
|
import path from "node:path";
|
|
20
20
|
import { experimental } from "../../utils/experimental.js";
|
|
21
|
+
import { guessMimeType } from "../../utils/file_utils.js";
|
|
21
22
|
import {
|
|
22
23
|
BaseTool
|
|
23
24
|
} from "../base_tool.js";
|
|
24
25
|
const BINARY_FILE_DETECTED_MSG = "Binary file detected. The content has been injected into the conversation history for you to analyze.";
|
|
25
|
-
const EXTENSION_TO_MIME_TYPE = {
|
|
26
|
-
"pdf": "application/pdf",
|
|
27
|
-
"jpg": "image/jpeg",
|
|
28
|
-
"jpeg": "image/jpeg",
|
|
29
|
-
"png": "image/png",
|
|
30
|
-
"gif": "image/gif",
|
|
31
|
-
"csv": "text/csv",
|
|
32
|
-
"json": "application/json",
|
|
33
|
-
"xml": "application/xml",
|
|
34
|
-
"sh": "text/x-shellscript",
|
|
35
|
-
"bash": "text/x-shellscript",
|
|
36
|
-
"py": "text/x-python",
|
|
37
|
-
"js": "text/javascript",
|
|
38
|
-
"cjs": "text/javascript",
|
|
39
|
-
"mjs": "text/javascript",
|
|
40
|
-
"ts": "text/javascript",
|
|
41
|
-
"cts": "text/javascript",
|
|
42
|
-
"mts": "text/javascript"
|
|
43
|
-
};
|
|
44
|
-
function guessMimeType(filePath) {
|
|
45
|
-
var _a;
|
|
46
|
-
const ext = ((_a = filePath.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
47
|
-
return EXTENSION_TO_MIME_TYPE[ext] || "application/octet-stream";
|
|
48
|
-
}
|
|
49
26
|
let LoadSkillResourceTool = class extends BaseTool {
|
|
50
27
|
constructor(toolset) {
|
|
51
28
|
super({
|
|
@@ -69,6 +69,32 @@ async function materializeFiles(files, dir = process.cwd()) {
|
|
|
69
69
|
}
|
|
70
70
|
return createdFiles;
|
|
71
71
|
}
|
|
72
|
+
const EXTENSION_TO_MIME_TYPE = {
|
|
73
|
+
"pdf": "application/pdf",
|
|
74
|
+
"jpg": "image/jpeg",
|
|
75
|
+
"jpeg": "image/jpeg",
|
|
76
|
+
"png": "image/png",
|
|
77
|
+
"gif": "image/gif",
|
|
78
|
+
"csv": "text/csv",
|
|
79
|
+
"json": "application/json",
|
|
80
|
+
"xml": "application/xml",
|
|
81
|
+
"sh": "text/x-shellscript",
|
|
82
|
+
"bash": "text/x-shellscript",
|
|
83
|
+
"py": "text/x-python",
|
|
84
|
+
"js": "text/javascript",
|
|
85
|
+
"cjs": "text/javascript",
|
|
86
|
+
"mjs": "text/javascript",
|
|
87
|
+
"ts": "text/javascript",
|
|
88
|
+
"cts": "text/javascript",
|
|
89
|
+
"mts": "text/javascript"
|
|
90
|
+
};
|
|
91
|
+
function guessMimeType(filePath) {
|
|
92
|
+
var _a;
|
|
93
|
+
const ext = ((_a = filePath.split(".").pop()) == null ? void 0 : _a.toLowerCase()) || "";
|
|
94
|
+
return EXTENSION_TO_MIME_TYPE[ext] || "application/octet-stream";
|
|
95
|
+
}
|
|
72
96
|
export {
|
|
97
|
+
EXTENSION_TO_MIME_TYPE,
|
|
98
|
+
guessMimeType,
|
|
73
99
|
materializeFiles
|
|
74
100
|
};
|
|
@@ -112,6 +112,21 @@ function toGeminiSchema(mcpSchema) {
|
|
|
112
112
|
mcp.type = "array";
|
|
113
113
|
} else if (isNullable) {
|
|
114
114
|
mcp.type = "null";
|
|
115
|
+
} else if (mcp.enum) {
|
|
116
|
+
const enumTypes = new Set(mcp.enum.map((v) => typeof v));
|
|
117
|
+
if (enumTypes.size === 1) {
|
|
118
|
+
const jsType = [...enumTypes][0];
|
|
119
|
+
if (jsType === "string") mcp.type = "string";
|
|
120
|
+
else if (jsType === "number") mcp.type = "number";
|
|
121
|
+
else if (jsType === "boolean") mcp.type = "boolean";
|
|
122
|
+
}
|
|
123
|
+
} else if (mcp.const !== void 0) {
|
|
124
|
+
const jsType = typeof mcp.const;
|
|
125
|
+
let inferredType;
|
|
126
|
+
if (jsType === "string") inferredType = "string";
|
|
127
|
+
else if (jsType === "number") inferredType = "number";
|
|
128
|
+
else if (jsType === "boolean") inferredType = "boolean";
|
|
129
|
+
mcp = __spreadProps(__spreadValues({}, mcp), { type: inferredType, enum: [mcp.const] });
|
|
115
130
|
}
|
|
116
131
|
}
|
|
117
132
|
const geminiType = toGeminiType(mcp.type);
|
|
@@ -126,6 +141,9 @@ function toGeminiSchema(mcpSchema) {
|
|
|
126
141
|
if (mcp.description) {
|
|
127
142
|
geminiSchema.description = mcp.description;
|
|
128
143
|
}
|
|
144
|
+
if (mcp.enum) {
|
|
145
|
+
geminiSchema.enum = mcp.enum.map(String);
|
|
146
|
+
}
|
|
129
147
|
if (isNullable && mcp.type !== "null") {
|
|
130
148
|
geminiSchema.nullable = true;
|
|
131
149
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {createRequire as topLevelCreateRequire} from 'module';
|
|
2
|
+
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Google LLC
|
|
6
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
*/
|
|
8
|
+
function partialCopy(source, targetKeys) {
|
|
9
|
+
const result = {};
|
|
10
|
+
const sourceAsUnknown = source;
|
|
11
|
+
targetKeys.forEach((key) => {
|
|
12
|
+
const keyStr = key;
|
|
13
|
+
if (keyStr in source) {
|
|
14
|
+
result[key] = sourceAsUnknown[keyStr];
|
|
15
|
+
} else {
|
|
16
|
+
result[key] = void 0;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
partialCopy
|
|
23
|
+
};
|