@google/adk 1.5.0 → 1.6.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 +12 -2
- package/dist/cjs/a2a/agent_to_a2a.js +0 -1
- package/dist/cjs/a2a/auth.js +65 -0
- package/dist/cjs/a2a/event_converter_utils.js +40 -15
- package/dist/cjs/agents/functions.js +20 -7
- package/dist/cjs/agents/llm_agent.js +2 -1
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/cjs/agents/processors/content_request_processor.js +2 -21
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/cjs/artifacts/in_memory_artifact_service.js +10 -9
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/cjs/code_executors/unsafe_local_code_executor.js +23 -12
- package/dist/cjs/common.js +6 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
- package/dist/cjs/context/compaction_utils.js +14 -2
- package/dist/cjs/context/token_based_context_compactor.js +2 -20
- package/dist/cjs/index.js +3 -0
- package/dist/cjs/memory/in_memory_memory_service.js +13 -2
- package/dist/cjs/memory/vertex_ai_memory_bank_service.js +3 -0
- package/dist/cjs/plugins/base_plugin.js +4 -2
- package/dist/cjs/runner/runner.js +18 -11
- package/dist/cjs/sessions/base_session_service.js +8 -3
- package/dist/cjs/sessions/in_memory_session_service.js +8 -8
- package/dist/cjs/sessions/vertex_ai_session_service.js +22 -10
- package/dist/cjs/skills/loader.js +40 -6
- package/dist/cjs/tools/get_user_choice_tool.js +53 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/cjs/tools/request_input_tool.js +54 -0
- package/dist/cjs/utils/crypto_shim.js +43 -0
- package/dist/cjs/utils/env_aware_utils.js +15 -13
- package/dist/cjs/utils/error_utils.js +120 -0
- package/dist/cjs/utils/file_utils.js +5 -2
- package/dist/cjs/utils/output_schema_utils.js +43 -0
- package/dist/cjs/utils/vertex_ai_utils.js +3 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +12 -2
- package/dist/esm/a2a/agent_to_a2a.js +0 -1
- package/dist/esm/a2a/auth.js +37 -0
- package/dist/esm/a2a/event_converter_utils.js +40 -15
- package/dist/esm/agents/functions.js +20 -7
- package/dist/esm/agents/llm_agent.js +2 -1
- package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/esm/agents/processors/content_request_processor.js +2 -21
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/esm/artifacts/in_memory_artifact_service.js +10 -9
- package/dist/esm/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/esm/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/esm/common.js +4 -0
- package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
- package/dist/esm/context/compaction_utils.js +12 -1
- package/dist/esm/context/token_based_context_compactor.js +6 -21
- package/dist/esm/index.js +2 -0
- package/dist/esm/memory/in_memory_memory_service.js +13 -2
- package/dist/esm/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/esm/plugins/base_plugin.js +4 -2
- package/dist/esm/runner/runner.js +18 -11
- package/dist/esm/sessions/base_session_service.js +8 -3
- package/dist/esm/sessions/in_memory_session_service.js +8 -8
- package/dist/esm/sessions/vertex_ai_session_service.js +26 -11
- package/dist/esm/skills/loader.js +40 -6
- package/dist/esm/tools/get_user_choice_tool.js +25 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/esm/tools/request_input_tool.js +26 -0
- package/dist/esm/utils/crypto_shim.js +15 -0
- package/dist/esm/utils/env_aware_utils.js +15 -13
- package/dist/esm/utils/error_utils.js +92 -0
- package/dist/esm/utils/file_utils.js +5 -2
- package/dist/esm/utils/output_schema_utils.js +15 -0
- package/dist/esm/utils/vertex_ai_utils.js +2 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/auth.d.ts +30 -0
- package/dist/types/a2a/event_converter_utils.d.ts +4 -1
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +11 -0
- package/dist/types/code_executors/unsafe_local_code_executor.d.ts +5 -1
- package/dist/types/common.d.ts +2 -0
- package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
- package/dist/types/context/compaction_utils.d.ts +8 -0
- package/dist/types/context/token_based_context_compactor.d.ts +0 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/memory/in_memory_memory_service.d.ts +11 -0
- package/dist/types/plugins/base_plugin.d.ts +4 -2
- package/dist/types/sessions/base_session_service.d.ts +8 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +9 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +19 -1
- package/dist/types/skills/loader.d.ts +5 -0
- package/dist/types/tools/get_user_choice_tool.d.ts +14 -0
- package/dist/types/tools/request_input_tool.d.ts +15 -0
- package/dist/types/utils/crypto_shim.d.ts +16 -0
- package/dist/types/utils/env_aware_utils.d.ts +23 -0
- package/dist/types/utils/error_utils.d.ts +18 -0
- package/dist/types/utils/output_schema_utils.d.ts +18 -0
- package/dist/types/utils/vertex_ai_utils.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_remote_agent.js +12 -2
- package/dist/web/a2a/agent_to_a2a.js +0 -1
- package/dist/web/a2a/auth.js +37 -0
- package/dist/web/a2a/event_converter_utils.js +40 -15
- package/dist/web/agents/functions.js +20 -7
- package/dist/web/agents/llm_agent.js +2 -1
- package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/web/agents/processors/content_request_processor.js +2 -21
- package/dist/web/agents/processors/instructions_llm_request_processor.js +3 -1
- package/dist/web/artifacts/in_memory_artifact_service.js +10 -9
- package/dist/web/auth/credential_service/in_memory_credential_service.js +14 -3
- package/dist/web/code_executors/unsafe_local_code_executor.js +22 -11
- package/dist/web/common.js +4 -0
- package/dist/web/context/agent_controlled_context_compactor.js +2 -11
- package/dist/web/context/compaction_utils.js +12 -1
- package/dist/web/context/token_based_context_compactor.js +6 -21
- package/dist/web/index.js +2 -0
- package/dist/web/memory/in_memory_memory_service.js +13 -2
- package/dist/web/memory/vertex_ai_memory_bank_service.js +7 -1
- package/dist/web/plugins/base_plugin.js +4 -2
- package/dist/web/runner/runner.js +17 -11
- package/dist/web/sessions/base_session_service.js +8 -3
- package/dist/web/sessions/in_memory_session_service.js +8 -8
- package/dist/web/sessions/vertex_ai_session_service.js +24 -11
- package/dist/web/skills/loader.js +40 -6
- package/dist/web/tools/get_user_choice_tool.js +25 -0
- package/dist/web/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/web/tools/request_input_tool.js +26 -0
- package/dist/web/utils/crypto_shim.js +15 -0
- package/dist/web/utils/env_aware_utils.js +15 -13
- package/dist/web/utils/error_utils.js +92 -0
- package/dist/web/utils/file_utils.js +5 -2
- package/dist/web/utils/output_schema_utils.js +15 -0
- package/dist/web/utils/vertex_ai_utils.js +2 -0
- package/dist/web/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
import { z } from "zod";
|
|
9
|
+
import { LongRunningFunctionTool } from "./long_running_tool.js";
|
|
10
|
+
const getUserChoiceTool = new LongRunningFunctionTool({
|
|
11
|
+
name: "get_user_choice",
|
|
12
|
+
description: "Presents a list of options to the user and awaits their selection.",
|
|
13
|
+
parameters: z.object({
|
|
14
|
+
options: z.array(z.string()).describe("List of options to present to the user.")
|
|
15
|
+
}),
|
|
16
|
+
execute: async (input, context) => {
|
|
17
|
+
if (context) {
|
|
18
|
+
context.actions.skipSummarization = true;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
export {
|
|
24
|
+
getUserChoiceTool
|
|
25
|
+
};
|
|
@@ -12,6 +12,11 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
StreamableHTTPClientTransport
|
|
14
14
|
} from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
15
|
+
import { formatError } from "../../utils/error_utils.js";
|
|
16
|
+
import { logger } from "../../utils/logger.js";
|
|
17
|
+
function logTransportError(err) {
|
|
18
|
+
logger.error("MCP transport error: " + formatError(err));
|
|
19
|
+
}
|
|
15
20
|
class MCPSessionManager {
|
|
16
21
|
constructor(connectionParams) {
|
|
17
22
|
this.activeSessions = /* @__PURE__ */ new Set();
|
|
@@ -20,31 +25,40 @@ class MCPSessionManager {
|
|
|
20
25
|
async createSession() {
|
|
21
26
|
var _a;
|
|
22
27
|
const client = new Client({ name: "MCPClient", version: "1.0.0" });
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
new StdioClientTransport(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
options.requestInit = {
|
|
33
|
-
headers: this.connectionParams.header
|
|
34
|
-
};
|
|
28
|
+
try {
|
|
29
|
+
switch (this.connectionParams.type) {
|
|
30
|
+
case "StdioConnectionParams": {
|
|
31
|
+
const transport = new StdioClientTransport(
|
|
32
|
+
this.connectionParams.serverParams
|
|
33
|
+
);
|
|
34
|
+
transport.onerror = logTransportError;
|
|
35
|
+
await client.connect(transport);
|
|
36
|
+
break;
|
|
35
37
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
case "StreamableHTTPConnectionParams": {
|
|
39
|
+
const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
|
|
40
|
+
if (!options.requestInit && this.connectionParams.header !== void 0) {
|
|
41
|
+
options.requestInit = {
|
|
42
|
+
headers: this.connectionParams.header
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const transport = new StreamableHTTPClientTransport(
|
|
38
46
|
new URL(this.connectionParams.url),
|
|
39
47
|
options
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
);
|
|
49
|
+
transport.onerror = logTransportError;
|
|
50
|
+
await client.connect(transport);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
default: {
|
|
54
|
+
const _exhaustiveCheck = this.connectionParams;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
47
57
|
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
throw new Error("Failed to create MCP session: " + formatError(err), {
|
|
60
|
+
cause: err
|
|
61
|
+
});
|
|
48
62
|
}
|
|
49
63
|
this.activeSessions.add(client);
|
|
50
64
|
return client;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
import { z } from "zod";
|
|
9
|
+
import { LongRunningFunctionTool } from "./long_running_tool.js";
|
|
10
|
+
const requestInputTool = new LongRunningFunctionTool({
|
|
11
|
+
name: "adk_request_input",
|
|
12
|
+
description: "Presents a custom message to the user and awaits unstructured or structured input.",
|
|
13
|
+
parameters: z.object({
|
|
14
|
+
message: z.string().describe("The prompt for the user."),
|
|
15
|
+
responseSchema: z.record(z.string(), z.unknown()).optional().describe("Expected schema of the response.")
|
|
16
|
+
}),
|
|
17
|
+
execute: async (input, context) => {
|
|
18
|
+
if (context) {
|
|
19
|
+
context.actions.skipSummarization = true;
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
export {
|
|
25
|
+
requestInputTool
|
|
26
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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 randomUUID() {
|
|
9
|
+
throw new Error(
|
|
10
|
+
"randomUUID: no cryptographically secure source of randomness is available. Neither crypto.randomUUID() nor crypto.getRandomValues() is present in this environment."
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
randomUUID
|
|
15
|
+
};
|
|
@@ -5,27 +5,29 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { randomUUID as nodeRandomUUID } from "node:crypto";
|
|
8
9
|
function isBrowser() {
|
|
9
10
|
return typeof window !== "undefined";
|
|
10
11
|
}
|
|
11
|
-
const UUID_MASK = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx";
|
|
12
12
|
function randomUUID() {
|
|
13
|
-
var _a;
|
|
13
|
+
var _a, _b;
|
|
14
14
|
if ((_a = globalThis.crypto) == null ? void 0 : _a.randomUUID) {
|
|
15
15
|
return globalThis.crypto.randomUUID();
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
17
|
+
if ((_b = globalThis.crypto) == null ? void 0 : _b.getRandomValues) {
|
|
18
|
+
const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
|
|
19
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
20
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
21
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
22
|
+
return [
|
|
23
|
+
hex.slice(0, 4),
|
|
24
|
+
hex.slice(4, 6),
|
|
25
|
+
hex.slice(6, 8),
|
|
26
|
+
hex.slice(8, 10),
|
|
27
|
+
hex.slice(10, 16)
|
|
28
|
+
].map((group) => group.join("")).join("-");
|
|
27
29
|
}
|
|
28
|
-
return
|
|
30
|
+
return nodeRandomUUID();
|
|
29
31
|
}
|
|
30
32
|
function base64Encode(data) {
|
|
31
33
|
if (isBrowser()) {
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
const MAX_RESPONSE_BODY_LENGTH = 1e3;
|
|
9
|
+
const TRUNCATION_MARKER = "... [truncated]";
|
|
10
|
+
const UNKNOWN_ERROR = "Unknown error";
|
|
11
|
+
const MIN_HTTP_STATUS = 100;
|
|
12
|
+
const MAX_HTTP_STATUS = 599;
|
|
13
|
+
function asRecord(value) {
|
|
14
|
+
return value !== null && typeof value === "object" ? value : void 0;
|
|
15
|
+
}
|
|
16
|
+
function firstString(...values) {
|
|
17
|
+
for (const value of values) {
|
|
18
|
+
if (typeof value === "string") {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
function truncateBody(body) {
|
|
25
|
+
return body.length > MAX_RESPONSE_BODY_LENGTH ? body.slice(0, MAX_RESPONSE_BODY_LENGTH) + TRUNCATION_MARKER : body;
|
|
26
|
+
}
|
|
27
|
+
function baseMessage(err) {
|
|
28
|
+
if (err instanceof Error) {
|
|
29
|
+
return err.message;
|
|
30
|
+
}
|
|
31
|
+
if (typeof err === "string") {
|
|
32
|
+
return err;
|
|
33
|
+
}
|
|
34
|
+
return String(err);
|
|
35
|
+
}
|
|
36
|
+
function extractHttpDetails(err) {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const record = asRecord(err);
|
|
39
|
+
if (record === void 0) {
|
|
40
|
+
return void 0;
|
|
41
|
+
}
|
|
42
|
+
const response = asRecord(record["response"]);
|
|
43
|
+
const rawStatus = (_b = (_a = record["status"]) != null ? _a : record["code"]) != null ? _b : response == null ? void 0 : response["status"];
|
|
44
|
+
const status = typeof rawStatus === "number" && rawStatus >= MIN_HTTP_STATUS && rawStatus <= MAX_HTTP_STATUS ? rawStatus : void 0;
|
|
45
|
+
const statusText = firstString(
|
|
46
|
+
record["statusText"],
|
|
47
|
+
response == null ? void 0 : response["statusText"]
|
|
48
|
+
);
|
|
49
|
+
const body = firstString(
|
|
50
|
+
response == null ? void 0 : response["data"],
|
|
51
|
+
response == null ? void 0 : response["body"],
|
|
52
|
+
response == null ? void 0 : response["text"]
|
|
53
|
+
);
|
|
54
|
+
if (status === void 0 && body === void 0) {
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
const head = status === void 0 ? "HTTP error" : `HTTP ${status}${statusText === void 0 ? "" : ` ${statusText}`}`;
|
|
58
|
+
return body === void 0 ? head : `${head}: ${truncateBody(body)}`;
|
|
59
|
+
}
|
|
60
|
+
function formatErrorRecursive(err, seen) {
|
|
61
|
+
var _a;
|
|
62
|
+
if (err === null || err === void 0) {
|
|
63
|
+
return UNKNOWN_ERROR;
|
|
64
|
+
}
|
|
65
|
+
if (typeof err === "object") {
|
|
66
|
+
if (seen.has(err)) {
|
|
67
|
+
return baseMessage(err);
|
|
68
|
+
}
|
|
69
|
+
seen.add(err);
|
|
70
|
+
}
|
|
71
|
+
if (err instanceof AggregateError && err.errors.length > 0) {
|
|
72
|
+
return err.errors.map((sub) => formatErrorRecursive(sub, seen)).join(" | ");
|
|
73
|
+
}
|
|
74
|
+
const http = extractHttpDetails(err);
|
|
75
|
+
const base = baseMessage(err);
|
|
76
|
+
const cause = (_a = asRecord(err)) == null ? void 0 : _a["cause"];
|
|
77
|
+
const causeMessage = cause !== void 0 ? formatErrorRecursive(cause, seen) : void 0;
|
|
78
|
+
let message = base.length > 0 ? base : UNKNOWN_ERROR;
|
|
79
|
+
if (http !== void 0) {
|
|
80
|
+
message = `${message} (${http})`;
|
|
81
|
+
}
|
|
82
|
+
if (causeMessage !== void 0 && http === void 0 && !message.includes(causeMessage)) {
|
|
83
|
+
message = `${message}: ${causeMessage}`;
|
|
84
|
+
}
|
|
85
|
+
return message;
|
|
86
|
+
}
|
|
87
|
+
function formatError(err) {
|
|
88
|
+
return formatErrorRecursive(err, /* @__PURE__ */ new Set());
|
|
89
|
+
}
|
|
90
|
+
export {
|
|
91
|
+
formatError
|
|
92
|
+
};
|
|
@@ -7,12 +7,15 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
7
7
|
*/
|
|
8
8
|
import * as fs from "node:fs/promises";
|
|
9
9
|
import * as path from "node:path";
|
|
10
|
+
function isInsideDir(resolvedPath, resolvedBaseDir) {
|
|
11
|
+
return resolvedPath === resolvedBaseDir || resolvedPath.startsWith(resolvedBaseDir + path.sep);
|
|
12
|
+
}
|
|
10
13
|
async function materializeFiles(files, dir = process.cwd()) {
|
|
11
14
|
const resolvedBaseDir = path.resolve(dir);
|
|
12
15
|
const createdFiles = [];
|
|
13
16
|
for (const file of files) {
|
|
14
17
|
const fullPath = path.resolve(dir, file.name);
|
|
15
|
-
if (!fullPath
|
|
18
|
+
if (!isInsideDir(fullPath, resolvedBaseDir)) {
|
|
16
19
|
throw new Error(
|
|
17
20
|
`Path traversal detected: ${file.name} resolves outside of ${dir}`
|
|
18
21
|
);
|
|
@@ -34,7 +37,7 @@ async function materializeFiles(files, dir = process.cwd()) {
|
|
|
34
37
|
break;
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
|
-
if (!finalPath
|
|
40
|
+
if (!isInsideDir(finalPath, resolvedBaseDir)) {
|
|
38
41
|
throw new Error(
|
|
39
42
|
`Path traversal detected: ${file.name} resolves outside of ${dir}`
|
|
40
43
|
);
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
import { isGemini2OrAbove } from "./model_name.js";
|
|
9
|
+
import { getGoogleLlmVariant, GoogleLLMVariant } from "./variant_utils.js";
|
|
10
|
+
function canUseOutputSchemaWithTools(modelString) {
|
|
11
|
+
return getGoogleLlmVariant() === GoogleLLMVariant.VERTEX_AI && isGemini2OrAbove(modelString);
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
canUseOutputSchemaWithTools
|
|
15
|
+
};
|
|
@@ -6,6 +6,7 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
8
|
import { getBooleanEnvVar } from "./env_aware_utils.js";
|
|
9
|
+
const EXPRESS_MODE_UNSUPPORTED_MESSAGE = "Vertex AI Express Mode (expressModeApiKey / GOOGLE_API_KEY) is not supported: the @google-cloud/vertexai Agent Engine client cannot send an API key. Provide projectId and location (with Application Default Credentials), or inject a preconfigured client.";
|
|
9
10
|
function getExpressModeApiKey(project, location, expressModeApiKey) {
|
|
10
11
|
if ((project || location) && expressModeApiKey) {
|
|
11
12
|
throw new Error(
|
|
@@ -18,5 +19,6 @@ function getExpressModeApiKey(project, location, expressModeApiKey) {
|
|
|
18
19
|
return void 0;
|
|
19
20
|
}
|
|
20
21
|
export {
|
|
22
|
+
EXPRESS_MODE_UNSUPPORTED_MESSAGE,
|
|
21
23
|
getExpressModeApiKey
|
|
22
24
|
};
|
package/dist/esm/version.js
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { A2aUserBuilder } from './agent_to_a2a.js';
|
|
7
|
+
/**
|
|
8
|
+
* Builds an {@link A2aUserBuilder} that authenticates A2A requests against a
|
|
9
|
+
* shared bearer token.
|
|
10
|
+
*
|
|
11
|
+
* Callers must send `Authorization: Bearer <token>`; the credential is
|
|
12
|
+
* compared against `token` in constant time, and a request with a missing,
|
|
13
|
+
* malformed or incorrect one is rejected before the agent or any of its tools
|
|
14
|
+
* is invoked. Serve the surface over HTTPS, or the secret travels in clear
|
|
15
|
+
* text on every call.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* toA2a(agent, {authentication: bearerTokenUserBuilder(process.env.MY_TOKEN)});
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* A rejected request surfaces as whatever the `@a2a-js/sdk` handler produces
|
|
22
|
+
* for a failing `UserBuilder`, which is an HTTP 500 rather than a 401. The
|
|
23
|
+
* guarantee here is that the agent is never reached, not that the caller gets
|
|
24
|
+
* a particular status code.
|
|
25
|
+
*
|
|
26
|
+
* @param token The shared secret callers must present; surrounding whitespace
|
|
27
|
+
* is trimmed, because HTTP strips it from header values anyway.
|
|
28
|
+
* @throws If `token` is empty or contains only whitespace.
|
|
29
|
+
*/
|
|
30
|
+
export declare function bearerTokenUserBuilder(token: string): A2aUserBuilder;
|
|
@@ -27,7 +27,10 @@ export declare function toA2AMessage(event: AdkEvent, { appName, userId, session
|
|
|
27
27
|
* status update).
|
|
28
28
|
* @param invocationId - The ADK invocation ID to attach to the resulting event.
|
|
29
29
|
* @param agentName - The name of the agent to use as the event author.
|
|
30
|
+
* @param branch - The local invocation's branch to attach to the resulting
|
|
31
|
+
* event. Must come from the caller's own `InvocationContext`, never from
|
|
32
|
+
* the A2A peer: see the comment on `createAdkEventFromMetadata` for why.
|
|
30
33
|
* @returns The converted ADK event, or `undefined` if the A2A event type
|
|
31
34
|
* produces no content.
|
|
32
35
|
*/
|
|
33
|
-
export declare function toAdkEvent(event: A2AEvent, invocationId: string, agentName: string): AdkEvent | undefined;
|
|
36
|
+
export declare function toAdkEvent(event: A2AEvent, invocationId: string, agentName: string, branch?: string): AdkEvent | undefined;
|
|
@@ -12,6 +12,17 @@ import { BaseCredentialService } from './base_credential_service.js';
|
|
|
12
12
|
* implementation of credential service
|
|
13
13
|
*/
|
|
14
14
|
export declare class InMemoryCredentialService implements BaseCredentialService {
|
|
15
|
+
/**
|
|
16
|
+
* A map from app name to a map from user ID to a map from credential key to
|
|
17
|
+
* credential.
|
|
18
|
+
*
|
|
19
|
+
* `appName`, `userId` and `credentialKey` are all attacker-influenced, so
|
|
20
|
+
* every level is created with `Object.create(null)`. On an ordinary `{}`
|
|
21
|
+
* literal a key of `__proto__` resolves to the inherited `__proto__`
|
|
22
|
+
* accessor rather than creating an own property, so nested assignment
|
|
23
|
+
* pollutes every object in the process, and a lookup of an inherited key
|
|
24
|
+
* such as `toString` returns a function instead of `undefined`.
|
|
25
|
+
*/
|
|
15
26
|
private readonly credentials;
|
|
16
27
|
loadCredential(authConfig: AuthConfig, toolContext: Context): Promise<AuthCredential | undefined>;
|
|
17
28
|
saveCredential(authConfig: AuthConfig, toolContext: Context): Promise<void>;
|
|
@@ -23,6 +23,10 @@ export interface UnsafeLocalCodeExecutorOptions {
|
|
|
23
23
|
pythonCommandPath?: string;
|
|
24
24
|
/**
|
|
25
25
|
* The command to run Shell code. Default is `bash`.
|
|
26
|
+
*
|
|
27
|
+
* When it names `powershell` or `pwsh` (with or without `.exe`) the script
|
|
28
|
+
* is written as `.ps1` and run through PowerShell rather than as a bare
|
|
29
|
+
* shell script.
|
|
26
30
|
*/
|
|
27
31
|
shellCommandPath?: string;
|
|
28
32
|
}
|
|
@@ -33,7 +37,7 @@ export interface UnsafeLocalCodeExecutorOptions {
|
|
|
33
37
|
* **Execution Details**:
|
|
34
38
|
* - **JavaScript**: Executed via `node` (defaults to `process.execPath`).
|
|
35
39
|
* - **Python**: Executed via `python3` on Unix, and `python` on Windows.
|
|
36
|
-
* - **Shell**: Executed via `bash` on Unix, and defaults to `powershell` (injecting ExecutionPolicy Bypass) or `cmd.exe` on Windows.
|
|
40
|
+
* - **Shell**: Executed via `bash` on Unix, and defaults to `powershell` (injecting `-NoProfile` and `-ExecutionPolicy Bypass`) or `cmd.exe` (injecting `/D`) on Windows.
|
|
37
41
|
*
|
|
38
42
|
* WARNING: This executor runs code in the local environment without sandboxing or security restrictions.
|
|
39
43
|
* Use with caution and only for trusted code.
|
package/dist/types/common.d.ts
CHANGED
|
@@ -124,6 +124,7 @@ export { ExampleTool } from './tools/example_tool.js';
|
|
|
124
124
|
export { EXIT_LOOP, ExitLoopTool } from './tools/exit_loop_tool.js';
|
|
125
125
|
export { FunctionTool, isFunctionTool } from './tools/function_tool.js';
|
|
126
126
|
export type { ToolExecuteArgument, ToolExecuteFunction, ToolInputParameters, ToolOptions, } from './tools/function_tool.js';
|
|
127
|
+
export { getUserChoiceTool } from './tools/get_user_choice_tool.js';
|
|
127
128
|
export { GOOGLE_MAPS_GROUNDING, GoogleMapsGroundingTool, } from './tools/google_maps_grounding_tool.js';
|
|
128
129
|
export { GOOGLE_SEARCH, GoogleSearchTool } from './tools/google_search_tool.js';
|
|
129
130
|
export { LOAD_ARTIFACTS, LoadArtifactsTool, } from './tools/load_artifacts_tool.js';
|
|
@@ -132,6 +133,7 @@ export { LOAD_WEB_PAGE, loadWebPage } from './tools/load_web_page.js';
|
|
|
132
133
|
export type { LoadWebPageOptions } from './tools/load_web_page.js';
|
|
133
134
|
export { LongRunningFunctionTool } from './tools/long_running_tool.js';
|
|
134
135
|
export { PRELOAD_MEMORY, PreloadMemoryTool, } from './tools/preload_memory_tool.js';
|
|
136
|
+
export { requestInputTool } from './tools/request_input_tool.js';
|
|
135
137
|
export { ToolConfirmation } from './tools/tool_confirmation.js';
|
|
136
138
|
export { URL_CONTEXT, UrlContextTool } from './tools/url_context_tool.js';
|
|
137
139
|
export { VertexAiSearchTool } from './tools/vertex_ai_search_tool.js';
|
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { Event } from '../events/event.js';
|
|
7
|
+
/**
|
|
8
|
+
* Filters the events to return only the active events since the latest compaction.
|
|
9
|
+
* If no compaction has occurred, returns all events.
|
|
10
|
+
*
|
|
11
|
+
* @param events The full history of events.
|
|
12
|
+
* @returns The active events, starting with the latest CompactedEvent if present.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getActiveEvents(events: Event[]): Event[];
|
|
7
15
|
/**
|
|
8
16
|
* Determines the baseline index to retain from active raw events,
|
|
9
17
|
* ensuring we don't split between a function call and its response.
|
|
@@ -32,7 +32,6 @@ export declare class TokenBasedContextCompactor implements BaseContextCompactor
|
|
|
32
32
|
private readonly eventRetentionSize;
|
|
33
33
|
private readonly summarizer;
|
|
34
34
|
constructor(options: TokenBasedContextCompactorOptions);
|
|
35
|
-
private getActiveEvents;
|
|
36
35
|
shouldCompact(invocationContext: InvocationContext): boolean | Promise<boolean>;
|
|
37
36
|
compact(invocationContext: InvocationContext): Promise<void>;
|
|
38
37
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { A2AAgentExecutor } from './a2a/agent_executor.js';
|
|
|
10
10
|
export type { AfterEventCallback, AfterExecuteCallback, AgentExecutorConfig, BeforeExecuteCallback, RunnerOrRunnerConfig, } from './a2a/agent_executor.js';
|
|
11
11
|
export { toA2a } from './a2a/agent_to_a2a.js';
|
|
12
12
|
export type { A2aUserBuilder, ToA2aOptions } from './a2a/agent_to_a2a.js';
|
|
13
|
+
export { bearerTokenUserBuilder } from './a2a/auth.js';
|
|
13
14
|
export type { ExecutorContext } from './a2a/executor_context.js';
|
|
14
15
|
export { InvocationContext } from './agents/invocation_context.js';
|
|
15
16
|
export { FileArtifactService } from './artifacts/file_artifact_service.js';
|
|
@@ -22,7 +23,7 @@ export * from './common.js';
|
|
|
22
23
|
export { DatabaseSessionService } from './sessions/database_session_service.js';
|
|
23
24
|
export { getSessionServiceFromUri } from './sessions/registry.js';
|
|
24
25
|
export { VertexAiSessionService } from './sessions/vertex_ai_session_service.js';
|
|
25
|
-
export type { VertexAiSessionServiceOptions } from './sessions/vertex_ai_session_service.js';
|
|
26
|
+
export type { VertexAiCreateSessionRequest, VertexAiSessionServiceOptions, } from './sessions/vertex_ai_session_service.js';
|
|
26
27
|
export { loadAllSkillsInDir, loadSkillFromDir, validateSkillDir, } from './skills/loader.js';
|
|
27
28
|
export { RunSkillInlineScriptErrorCode, RunSkillInlineScriptTool, } from './tools/skill/run_skill_inline_script_tool.js';
|
|
28
29
|
export { RunSkillScriptTool } from './tools/skill/run_skill_script_tool.js';
|
|
@@ -12,6 +12,17 @@ import { BaseMemoryService, SearchMemoryRequest, SearchMemoryResponse } from './
|
|
|
12
12
|
*/
|
|
13
13
|
export declare class InMemoryMemoryService implements BaseMemoryService {
|
|
14
14
|
private readonly memories;
|
|
15
|
+
/**
|
|
16
|
+
* A map from user key to a map from session ID to events.
|
|
17
|
+
*
|
|
18
|
+
* The inner map is keyed by `session.id`, which arrives off the request path
|
|
19
|
+
* and contains no `/`, so it can be exactly `__proto__`. On a plain object
|
|
20
|
+
* literal that key would reach the inherited `__proto__` setter and
|
|
21
|
+
* re-parent the map instead of creating an own property, silently dropping
|
|
22
|
+
* the session from the `Object.values` scan in `searchMemory`. The outer key
|
|
23
|
+
* always contains a `/` (see `getUserKey`) and cannot collide, but is
|
|
24
|
+
* created the same way for consistency.
|
|
25
|
+
*/
|
|
15
26
|
private readonly sessionEvents;
|
|
16
27
|
addSessionToMemory(session: Session): Promise<void>;
|
|
17
28
|
searchMemory(req: SearchMemoryRequest): Promise<SearchMemoryResponse>;
|
|
@@ -151,8 +151,10 @@ export declare abstract class BasePlugin {
|
|
|
151
151
|
* @param params.invocationContext The context for the entire invocation.
|
|
152
152
|
* @param params.event The event raised by the runner.
|
|
153
153
|
* @returns An optional value. A non-`undefined` return may be used by the
|
|
154
|
-
* framework to modify or replace the response.
|
|
155
|
-
*
|
|
154
|
+
* framework to modify or replace the response. Copy `params.event` when
|
|
155
|
+
* constructing a replacement to preserve fields that are not being
|
|
156
|
+
* modified, such as event actions. Returning `undefined` allows the
|
|
157
|
+
* original response to be used.
|
|
156
158
|
*/
|
|
157
159
|
onEventCallback(params: {
|
|
158
160
|
invocationContext: InvocationContext;
|
|
@@ -145,6 +145,14 @@ export declare abstract class BaseSessionService {
|
|
|
145
145
|
export declare function trimTempDeltaState(event: Event): Event;
|
|
146
146
|
/**
|
|
147
147
|
* Removes temporary state keys from the state.
|
|
148
|
+
*
|
|
149
|
+
* The result is a null-prototype map. `state` comes straight off the request
|
|
150
|
+
* body on a dev server (`POST /apps/:appName/users/:userId/sessions/:sessionId`),
|
|
151
|
+
* and `JSON.parse` makes `__proto__` an own key, so copying it into a plain
|
|
152
|
+
* object literal would invoke the inherited `__proto__` setter: the entry is
|
|
153
|
+
* dropped and the new state object is re-parented onto the attacker's object.
|
|
154
|
+
* `State.get`/`State.has` use the `in` operator, so every key on that object
|
|
155
|
+
* would then read back as session state.
|
|
148
156
|
*/
|
|
149
157
|
export declare function trimTempState(state: Record<string, unknown>): Record<string, unknown>;
|
|
150
158
|
/**
|
|
@@ -7,6 +7,15 @@ import { Session } from './session.js';
|
|
|
7
7
|
export declare function isInMemoryConnectionString(uri?: string): boolean;
|
|
8
8
|
/**
|
|
9
9
|
* An in-memory implementation of the session service.
|
|
10
|
+
*
|
|
11
|
+
* Every map below is keyed by untrusted input — `appName`, `userId`,
|
|
12
|
+
* `sessionId` and state keys all arrive straight off the request path or body
|
|
13
|
+
* on a dev server — so each is created with `Object.create(null)`. On an
|
|
14
|
+
* ordinary `{}` literal a key of `__proto__` resolves to the inherited
|
|
15
|
+
* `__proto__` accessor instead of creating an own property, so
|
|
16
|
+
* `map[appName][userId] = ...` writes onto `Object.prototype` and pollutes
|
|
17
|
+
* every object in the process. A null-prototype map has no such accessor, so
|
|
18
|
+
* those keys become ordinary own properties.
|
|
10
19
|
*/
|
|
11
20
|
export declare class InMemorySessionService extends BaseSessionService {
|
|
12
21
|
/**
|
|
@@ -26,6 +26,19 @@ export interface VertexAiSessionServiceOptions {
|
|
|
26
26
|
expressModeApiKey?: string;
|
|
27
27
|
sessions?: Sessions;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* The parameters for `VertexAiSessionService.createSession`.
|
|
31
|
+
*
|
|
32
|
+
* Extends the common {@link CreateSessionRequest} with the mutually exclusive
|
|
33
|
+
* session-expiration options supported by Vertex AI Agent Engine Sessions. See
|
|
34
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1beta1/projects.locations.reasoningEngines.sessions
|
|
35
|
+
*/
|
|
36
|
+
export interface VertexAiCreateSessionRequest extends CreateSessionRequest {
|
|
37
|
+
/** Lifetime relative to creation, in seconds, e.g. `'7200s'`. */
|
|
38
|
+
ttl?: string;
|
|
39
|
+
/** Absolute RFC 3339 UTC expiration, e.g. `'2025-10-01T00:00:00Z'`. */
|
|
40
|
+
expireTime?: string;
|
|
41
|
+
}
|
|
29
42
|
/**
|
|
30
43
|
* A session service implementation that integrates with Vertex AI Agent Engine Sessions.
|
|
31
44
|
*/
|
|
@@ -37,7 +50,12 @@ export declare class VertexAiSessionService extends BaseSessionService {
|
|
|
37
50
|
private location?;
|
|
38
51
|
constructor(options: VertexAiSessionServiceOptions);
|
|
39
52
|
private getReasoningEngineId;
|
|
40
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Creates a session on Vertex AI Agent Engine.
|
|
55
|
+
*
|
|
56
|
+
* @throws if both `ttl` and `expireTime` are specified.
|
|
57
|
+
*/
|
|
58
|
+
createSession({ appName, userId, state, sessionId, ttl, expireTime, }: VertexAiCreateSessionRequest): Promise<Session>;
|
|
41
59
|
getSession({ appName, userId, sessionId, config, }: GetSessionRequest): Promise<Session | undefined>;
|
|
42
60
|
listSessions({ appName, userId, limit, offset, page, order, }: ListSessionsRequest): Promise<ListSessionsResponse>;
|
|
43
61
|
deleteSession({ appName, userId, sessionId, }: DeleteSessionRequest): Promise<void>;
|
|
@@ -39,7 +39,12 @@ export declare function loadAllSkillsInDir(skillsBasePath: string): Promise<Reco
|
|
|
39
39
|
/**
|
|
40
40
|
* Loads a complete skill directly from in-memory zip file buffer.
|
|
41
41
|
*
|
|
42
|
+
* The whole archive is rejected if any member name escapes the extraction
|
|
43
|
+
* root, and the skill name must be a bare path segment.
|
|
44
|
+
*
|
|
42
45
|
* @param zipBuffer - The raw Buffer of the zip file containing the skill.
|
|
43
46
|
* @returns A Skill object with all components loaded.
|
|
47
|
+
* @throws {Error} If a member name is a traversal path, if SKILL.md is missing,
|
|
48
|
+
* or if the skill name is missing or is not a bare path segment.
|
|
44
49
|
*/
|
|
45
50
|
export declare function loadSkillFromZipBuffer(zipBuffer: Buffer): Skill;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { LongRunningFunctionTool } from './long_running_tool.js';
|
|
8
|
+
/**
|
|
9
|
+
* A long-running tool that presents a list of options to the user and awaits
|
|
10
|
+
* their selection.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getUserChoiceTool: LongRunningFunctionTool<z.ZodObject<{
|
|
13
|
+
options: z.ZodArray<z.ZodString>;
|
|
14
|
+
}, z.core.$strip>>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { LongRunningFunctionTool } from './long_running_tool.js';
|
|
8
|
+
/**
|
|
9
|
+
* A long-running tool that presents a custom message to the user and awaits
|
|
10
|
+
* unstructured or structured input.
|
|
11
|
+
*/
|
|
12
|
+
export declare const requestInputTool: LongRunningFunctionTool<z.ZodObject<{
|
|
13
|
+
message: z.ZodString;
|
|
14
|
+
responseSchema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
15
|
+
}, z.core.$strip>>;
|