@google/adk 0.4.0 → 0.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/README.md +1 -1
- package/dist/cjs/a2a/a2a_event.js +317 -0
- package/dist/cjs/a2a/a2a_remote_agent.js +174 -0
- package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +198 -0
- package/dist/cjs/a2a/a2a_remote_agent_utils.js +165 -0
- package/dist/cjs/a2a/agent_card.js +380 -0
- package/dist/cjs/a2a/agent_executor.js +221 -0
- package/dist/cjs/a2a/agent_to_a2a.js +115 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/event_processor_utils.js +180 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +126 -0
- package/dist/cjs/a2a/part_converter_utils.js +47 -34
- package/dist/cjs/agents/base_agent.js +3 -3
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +70 -15
- package/dist/cjs/agents/functions.js +2 -2
- package/dist/cjs/agents/llm_agent.js +38 -674
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
- package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
- package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
- package/dist/cjs/agents/processors/content_request_processor.js +87 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
- package/dist/cjs/artifacts/file_artifact_service.js +35 -4
- package/dist/cjs/common.js +48 -7
- package/dist/cjs/context/base_context_compactor.js +27 -0
- package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
- package/dist/cjs/context/token_based_context_compactor.js +135 -0
- package/dist/cjs/context/truncating_context_compactor.js +58 -0
- package/dist/cjs/events/compacted_event.js +53 -0
- package/dist/cjs/index.js +113 -53
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/models/llm_response.js +2 -0
- package/dist/cjs/plugins/base_plugin.js +1 -1
- package/dist/cjs/runner/runner.js +20 -11
- package/dist/cjs/sessions/database_session_service.js +4 -1
- package/dist/cjs/sessions/db/operations.js +25 -23
- package/dist/cjs/sessions/state.js +2 -2
- package/dist/cjs/tools/agent_tool.js +6 -5
- package/dist/cjs/tools/base_tool.js +3 -0
- package/dist/cjs/tools/base_toolset.js +13 -3
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/load_artifacts_tool.js +188 -0
- package/dist/cjs/tools/load_memory_tool.js +107 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +9 -5
- package/dist/cjs/tools/preload_memory_tool.js +109 -0
- package/dist/cjs/utils/logger.js +62 -54
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_event.js +269 -0
- package/dist/esm/a2a/a2a_remote_agent.js +148 -0
- package/dist/esm/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/esm/a2a/agent_card.js +340 -0
- package/dist/esm/a2a/agent_executor.js +202 -0
- package/dist/esm/a2a/agent_to_a2a.js +80 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/event_processor_utils.js +159 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +91 -0
- package/dist/esm/a2a/part_converter_utils.js +49 -34
- package/dist/esm/agents/base_agent.js +3 -3
- package/dist/{web/tools/tool_context.js → esm/agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +2 -2
- package/dist/esm/agents/llm_agent.js +31 -683
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
- package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
- package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
- package/dist/esm/agents/processors/content_request_processor.js +59 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
- package/dist/esm/artifacts/file_artifact_service.js +30 -3
- package/dist/esm/common.js +44 -10
- package/dist/esm/context/base_context_compactor.js +5 -0
- package/dist/esm/context/summarizers/base_summarizer.js +5 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
- package/dist/esm/context/token_based_context_compactor.js +105 -0
- package/dist/esm/context/truncating_context_compactor.js +28 -0
- package/dist/esm/events/compacted_event.js +22 -0
- package/dist/esm/index.js +119 -18
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/memory/in_memory_memory_service.js +1 -1
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +18 -10
- package/dist/esm/sessions/database_session_service.js +4 -1
- package/dist/esm/sessions/db/operations.js +32 -18
- package/dist/esm/sessions/state.js +2 -2
- package/dist/esm/tools/agent_tool.js +6 -5
- package/dist/esm/tools/base_tool.js +3 -0
- package/dist/esm/tools/base_toolset.js +11 -2
- package/dist/esm/tools/exit_loop_tool.js +32 -0
- package/dist/esm/tools/load_artifacts_tool.js +159 -0
- package/dist/esm/tools/load_memory_tool.js +78 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/tools/preload_memory_tool.js +80 -0
- package/dist/esm/utils/logger.js +52 -54
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +139 -0
- package/dist/types/a2a/a2a_remote_agent.d.ts +63 -0
- package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
- package/dist/types/a2a/agent_card.d.ts +23 -0
- package/dist/types/a2a/agent_executor.d.ts +52 -0
- package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/event_processor_utils.d.ts +24 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +63 -0
- package/dist/types/a2a/part_converter_utils.d.ts +4 -3
- package/dist/types/agents/base_agent.d.ts +2 -2
- package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
- package/dist/types/agents/llm_agent.d.ts +14 -31
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
- package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
- package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
- package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
- package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
- package/dist/types/common.d.ts +20 -5
- package/dist/types/context/base_context_compactor.d.ts +24 -0
- package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +33 -0
- package/dist/types/context/truncating_context_compactor.d.ts +24 -0
- package/dist/types/events/compacted_event.d.ts +33 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/models/llm_response.d.ts +5 -1
- package/dist/types/plugins/base_plugin.d.ts +12 -13
- package/dist/types/plugins/logging_plugin.d.ts +9 -10
- package/dist/types/plugins/plugin_manager.d.ts +9 -10
- package/dist/types/plugins/security_plugin.d.ts +2 -2
- package/dist/types/runner/runner.d.ts +13 -0
- package/dist/types/sessions/database_session_service.d.ts +2 -1
- package/dist/types/sessions/db/operations.d.ts +3 -4
- package/dist/types/tools/base_tool.d.ts +3 -3
- package/dist/types/tools/base_toolset.d.ts +12 -3
- package/dist/types/tools/exit_loop_tool.d.ts +24 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
- package/dist/types/tools/load_memory_tool.d.ts +22 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/tools/preload_memory_tool.d.ts +23 -0
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +269 -0
- package/dist/web/a2a/a2a_remote_agent.js +193 -0
- package/dist/web/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/web/a2a/agent_card.js +340 -0
- package/dist/web/a2a/agent_executor.js +216 -0
- package/dist/web/a2a/agent_to_a2a.js +80 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/event_processor_utils.js +168 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +108 -0
- package/dist/web/a2a/part_converter_utils.js +49 -34
- package/dist/web/agents/base_agent.js +3 -3
- package/dist/{esm/tools/tool_context.js → web/agents/context.js} +66 -11
- package/dist/web/agents/functions.js +2 -2
- package/dist/web/agents/llm_agent.js +31 -661
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
- package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
- package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
- package/dist/web/agents/processors/content_request_processor.js +77 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
- package/dist/web/artifacts/file_artifact_service.js +30 -3
- package/dist/web/common.js +44 -10
- package/dist/web/context/base_context_compactor.js +5 -0
- package/dist/web/context/summarizers/base_summarizer.js +5 -0
- package/dist/web/context/summarizers/llm_summarizer.js +74 -0
- package/dist/web/context/token_based_context_compactor.js +105 -0
- package/dist/web/context/truncating_context_compactor.js +28 -0
- package/dist/web/events/compacted_event.js +40 -0
- package/dist/web/index.js +13 -18
- package/dist/web/index.js.map +7 -0
- package/dist/web/memory/in_memory_memory_service.js +1 -1
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +18 -10
- package/dist/web/sessions/database_session_service.js +4 -1
- package/dist/web/sessions/db/operations.js +32 -18
- package/dist/web/sessions/state.js +2 -2
- package/dist/web/tools/agent_tool.js +6 -5
- package/dist/web/tools/base_tool.js +3 -0
- package/dist/web/tools/base_toolset.js +11 -2
- package/dist/web/tools/exit_loop_tool.js +32 -0
- package/dist/web/tools/load_artifacts_tool.js +150 -0
- package/dist/web/tools/load_memory_tool.js +77 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/tools/preload_memory_tool.js +75 -0
- package/dist/web/utils/logger.js +52 -54
- package/dist/web/version.js +1 -1
- package/package.json +7 -4
- package/dist/cjs/agents/callback_context.js +0 -101
- package/dist/esm/agents/callback_context.js +0 -71
- package/dist/types/agents/callback_context.d.ts +0 -42
- package/dist/web/agents/callback_context.js +0 -71
- /package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
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 __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var content_request_processor_exports = {};
|
|
26
|
+
__export(content_request_processor_exports, {
|
|
27
|
+
CONTENT_REQUEST_PROCESSOR: () => CONTENT_REQUEST_PROCESSOR,
|
|
28
|
+
ContentRequestProcessor: () => ContentRequestProcessor
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(content_request_processor_exports);
|
|
31
|
+
var import_compacted_event = require("../../events/compacted_event.js");
|
|
32
|
+
var import_llm_agent = require("../llm_agent.js");
|
|
33
|
+
var import_content_processor_utils = require("./content_processor_utils.js");
|
|
34
|
+
/**
|
|
35
|
+
* @license
|
|
36
|
+
* Copyright 2025 Google LLC
|
|
37
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
38
|
+
*/
|
|
39
|
+
class ContentRequestProcessor {
|
|
40
|
+
// eslint-disable-next-line require-yield
|
|
41
|
+
async *runAsync(invocationContext, llmRequest) {
|
|
42
|
+
const agent = invocationContext.agent;
|
|
43
|
+
if (!agent || !(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let events = invocationContext.session.events;
|
|
47
|
+
const compactedEvents = events.filter(import_compacted_event.isCompactedEvent);
|
|
48
|
+
const latestCompactedEvent = compactedEvents.length > 0 ? compactedEvents.reduce(
|
|
49
|
+
(latest, current) => current.endTime > latest.endTime ? current : latest
|
|
50
|
+
) : void 0;
|
|
51
|
+
if (latestCompactedEvent) {
|
|
52
|
+
const remainingEvents = events.filter((event) => {
|
|
53
|
+
if (event === latestCompactedEvent) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
if ((0, import_compacted_event.isCompactedEvent)(event)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (event.timestamp <= latestCompactedEvent.endTime) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
});
|
|
64
|
+
events = [latestCompactedEvent, ...remainingEvents];
|
|
65
|
+
}
|
|
66
|
+
if (agent.includeContents === "default") {
|
|
67
|
+
llmRequest.contents = (0, import_content_processor_utils.getContents)(
|
|
68
|
+
events,
|
|
69
|
+
agent.name,
|
|
70
|
+
invocationContext.branch
|
|
71
|
+
);
|
|
72
|
+
} else {
|
|
73
|
+
llmRequest.contents = (0, import_content_processor_utils.getCurrentTurnContents)(
|
|
74
|
+
events,
|
|
75
|
+
agent.name,
|
|
76
|
+
invocationContext.branch
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const CONTENT_REQUEST_PROCESSOR = new ContentRequestProcessor();
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
CONTENT_REQUEST_PROCESSOR,
|
|
86
|
+
ContentRequestProcessor
|
|
87
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
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 __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var context_compactor_request_processor_exports = {};
|
|
26
|
+
__export(context_compactor_request_processor_exports, {
|
|
27
|
+
ContextCompactorRequestProcessor: () => ContextCompactorRequestProcessor
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(context_compactor_request_processor_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
class ContextCompactorRequestProcessor {
|
|
36
|
+
constructor(compactors) {
|
|
37
|
+
this.compactors = compactors;
|
|
38
|
+
}
|
|
39
|
+
async *runAsync(invocationContext, _llmRequest) {
|
|
40
|
+
for (const compactor of this.compactors) {
|
|
41
|
+
const shouldCompact = await Promise.resolve(
|
|
42
|
+
compactor.shouldCompact(invocationContext)
|
|
43
|
+
);
|
|
44
|
+
if (shouldCompact) {
|
|
45
|
+
const oldEvents = new Set(invocationContext.session.events);
|
|
46
|
+
await Promise.resolve(compactor.compact(invocationContext));
|
|
47
|
+
const newEvents = invocationContext.session.events.filter(
|
|
48
|
+
(e) => !oldEvents.has(e)
|
|
49
|
+
);
|
|
50
|
+
for (const e of newEvents) {
|
|
51
|
+
yield e;
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
ContextCompactorRequestProcessor
|
|
61
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
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 __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var identity_llm_request_processor_exports = {};
|
|
26
|
+
__export(identity_llm_request_processor_exports, {
|
|
27
|
+
IDENTITY_LLM_REQUEST_PROCESSOR: () => IDENTITY_LLM_REQUEST_PROCESSOR,
|
|
28
|
+
IdentityLlmRequestProcessor: () => IdentityLlmRequestProcessor
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(identity_llm_request_processor_exports);
|
|
31
|
+
var import_llm_request = require("../../models/llm_request.js");
|
|
32
|
+
var import_base_llm_processor = require("./base_llm_processor.js");
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2025 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/
|
|
38
|
+
class IdentityLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
39
|
+
// eslint-disable-next-line require-yield
|
|
40
|
+
async *runAsync(invocationContext, llmRequest) {
|
|
41
|
+
const agent = invocationContext.agent;
|
|
42
|
+
const si = [`You are an agent. Your internal name is "${agent.name}".`];
|
|
43
|
+
if (agent.description) {
|
|
44
|
+
si.push(`The description about you is "${agent.description}"`);
|
|
45
|
+
}
|
|
46
|
+
(0, import_llm_request.appendInstructions)(llmRequest, si);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const IDENTITY_LLM_REQUEST_PROCESSOR = new IdentityLlmRequestProcessor();
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
IDENTITY_LLM_REQUEST_PROCESSOR,
|
|
53
|
+
IdentityLlmRequestProcessor
|
|
54
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
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 __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var instructions_llm_request_processor_exports = {};
|
|
26
|
+
__export(instructions_llm_request_processor_exports, {
|
|
27
|
+
INSTRUCTIONS_LLM_REQUEST_PROCESSOR: () => INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
|
|
28
|
+
InstructionsLlmRequestProcessor: () => InstructionsLlmRequestProcessor
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(instructions_llm_request_processor_exports);
|
|
31
|
+
var import_llm_request = require("../../models/llm_request.js");
|
|
32
|
+
var import_instructions = require("../instructions.js");
|
|
33
|
+
var import_llm_agent = require("../llm_agent.js");
|
|
34
|
+
var import_readonly_context = require("../readonly_context.js");
|
|
35
|
+
var import_base_llm_processor = require("./base_llm_processor.js");
|
|
36
|
+
/**
|
|
37
|
+
* @license
|
|
38
|
+
* Copyright 2025 Google LLC
|
|
39
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
40
|
+
*/
|
|
41
|
+
class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
42
|
+
/**
|
|
43
|
+
* Handles instructions and global instructions for LLM flow.
|
|
44
|
+
*/
|
|
45
|
+
// eslint-disable-next-line require-yield
|
|
46
|
+
async *runAsync(invocationContext, llmRequest) {
|
|
47
|
+
const agent = invocationContext.agent;
|
|
48
|
+
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const rootAgent = agent.rootAgent;
|
|
52
|
+
if ((0, import_llm_agent.isLlmAgent)(rootAgent) && rootAgent.globalInstruction) {
|
|
53
|
+
const { instruction, requireStateInjection } = await rootAgent.canonicalGlobalInstruction(
|
|
54
|
+
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
55
|
+
);
|
|
56
|
+
let instructionWithState = instruction;
|
|
57
|
+
if (requireStateInjection) {
|
|
58
|
+
instructionWithState = await (0, import_instructions.injectSessionState)(
|
|
59
|
+
instruction,
|
|
60
|
+
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
(0, import_llm_request.appendInstructions)(llmRequest, [instructionWithState]);
|
|
64
|
+
}
|
|
65
|
+
if (agent.instruction) {
|
|
66
|
+
const { instruction, requireStateInjection } = await agent.canonicalInstruction(
|
|
67
|
+
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
68
|
+
);
|
|
69
|
+
let instructionWithState = instruction;
|
|
70
|
+
if (requireStateInjection) {
|
|
71
|
+
instructionWithState = await (0, import_instructions.injectSessionState)(
|
|
72
|
+
instruction,
|
|
73
|
+
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
(0, import_llm_request.appendInstructions)(llmRequest, [instructionWithState]);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor();
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
|
|
84
|
+
InstructionsLlmRequestProcessor
|
|
85
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
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 __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var request_confirmation_llm_request_processor_exports = {};
|
|
26
|
+
__export(request_confirmation_llm_request_processor_exports, {
|
|
27
|
+
REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: () => REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
|
|
28
|
+
RequestConfirmationLlmRequestProcessor: () => RequestConfirmationLlmRequestProcessor
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(request_confirmation_llm_request_processor_exports);
|
|
31
|
+
var import_event = require("../../events/event.js");
|
|
32
|
+
var import_tool_confirmation = require("../../tools/tool_confirmation.js");
|
|
33
|
+
var import_functions = require("../functions.js");
|
|
34
|
+
var import_llm_agent = require("../llm_agent.js");
|
|
35
|
+
var import_readonly_context = require("../readonly_context.js");
|
|
36
|
+
var import_base_llm_processor = require("./base_llm_processor.js");
|
|
37
|
+
/**
|
|
38
|
+
* @license
|
|
39
|
+
* Copyright 2025 Google LLC
|
|
40
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
41
|
+
*/
|
|
42
|
+
class RequestConfirmationLlmRequestProcessor extends import_base_llm_processor.BaseLlmRequestProcessor {
|
|
43
|
+
/** Handles tool confirmation information to build the LLM request. */
|
|
44
|
+
async *runAsync(invocationContext) {
|
|
45
|
+
const agent = invocationContext.agent;
|
|
46
|
+
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const events = invocationContext.session.events;
|
|
50
|
+
if (!events || events.length === 0) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const requestConfirmationFunctionResponses = {};
|
|
54
|
+
let confirmationEventIndex = -1;
|
|
55
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
56
|
+
const event = events[i];
|
|
57
|
+
if (event.author !== "user") {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const responses = (0, import_event.getFunctionResponses)(event);
|
|
61
|
+
if (!responses) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
let foundConfirmation = false;
|
|
65
|
+
for (const functionResponse of responses) {
|
|
66
|
+
if (functionResponse.name !== import_functions.REQUEST_CONFIRMATION_FUNCTION_CALL_NAME) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
foundConfirmation = true;
|
|
70
|
+
let toolConfirmation = null;
|
|
71
|
+
if (functionResponse.response && Object.keys(functionResponse.response).length === 1 && "response" in functionResponse.response) {
|
|
72
|
+
toolConfirmation = JSON.parse(
|
|
73
|
+
functionResponse.response["response"]
|
|
74
|
+
);
|
|
75
|
+
} else if (functionResponse.response) {
|
|
76
|
+
toolConfirmation = new import_tool_confirmation.ToolConfirmation({
|
|
77
|
+
hint: functionResponse.response["hint"],
|
|
78
|
+
payload: functionResponse.response["payload"],
|
|
79
|
+
confirmed: functionResponse.response["confirmed"]
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (functionResponse.id && toolConfirmation) {
|
|
83
|
+
requestConfirmationFunctionResponses[functionResponse.id] = toolConfirmation;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (foundConfirmation) {
|
|
87
|
+
confirmationEventIndex = i;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (Object.keys(requestConfirmationFunctionResponses).length === 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
for (let i = confirmationEventIndex - 1; i >= 0; i--) {
|
|
95
|
+
const event = events[i];
|
|
96
|
+
const functionCalls = (0, import_event.getFunctionCalls)(event);
|
|
97
|
+
if (!functionCalls) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const toolsToResumeWithConfirmation = {};
|
|
101
|
+
const toolsToResumeWithArgs = {};
|
|
102
|
+
for (const functionCall of functionCalls) {
|
|
103
|
+
if (!functionCall.id || !(functionCall.id in requestConfirmationFunctionResponses)) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const args = functionCall.args;
|
|
107
|
+
if (!args || !("originalFunctionCall" in args)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const originalFunctionCall = args["originalFunctionCall"];
|
|
111
|
+
if (originalFunctionCall.id) {
|
|
112
|
+
toolsToResumeWithConfirmation[originalFunctionCall.id] = requestConfirmationFunctionResponses[functionCall.id];
|
|
113
|
+
toolsToResumeWithArgs[originalFunctionCall.id] = originalFunctionCall;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
for (let j = events.length - 1; j > confirmationEventIndex; j--) {
|
|
120
|
+
const eventToCheck = events[j];
|
|
121
|
+
const functionResponses = (0, import_event.getFunctionResponses)(eventToCheck);
|
|
122
|
+
if (!functionResponses) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
for (const fr of functionResponses) {
|
|
126
|
+
if (fr.id && fr.id in toolsToResumeWithConfirmation) {
|
|
127
|
+
delete toolsToResumeWithConfirmation[fr.id];
|
|
128
|
+
delete toolsToResumeWithArgs[fr.id];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const toolsList = await agent.canonicalTools(
|
|
139
|
+
new import_readonly_context.ReadonlyContext(invocationContext)
|
|
140
|
+
);
|
|
141
|
+
const toolsDict = Object.fromEntries(
|
|
142
|
+
toolsList.map((tool) => [tool.name, tool])
|
|
143
|
+
);
|
|
144
|
+
const functionResponseEvent = await (0, import_functions.handleFunctionCallList)({
|
|
145
|
+
invocationContext,
|
|
146
|
+
functionCalls: Object.values(toolsToResumeWithArgs),
|
|
147
|
+
toolsDict,
|
|
148
|
+
beforeToolCallbacks: agent.canonicalBeforeToolCallbacks,
|
|
149
|
+
afterToolCallbacks: agent.canonicalAfterToolCallbacks,
|
|
150
|
+
filters: new Set(Object.keys(toolsToResumeWithConfirmation)),
|
|
151
|
+
toolConfirmationDict: toolsToResumeWithConfirmation
|
|
152
|
+
});
|
|
153
|
+
if (functionResponseEvent) {
|
|
154
|
+
yield functionResponseEvent;
|
|
155
|
+
}
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR = new RequestConfirmationLlmRequestProcessor();
|
|
161
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
162
|
+
0 && (module.exports = {
|
|
163
|
+
REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
|
|
164
|
+
RequestConfirmationLlmRequestProcessor
|
|
165
|
+
});
|
|
@@ -34,7 +34,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
35
|
var file_artifact_service_exports = {};
|
|
36
36
|
__export(file_artifact_service_exports, {
|
|
37
|
-
FileArtifactService: () => FileArtifactService
|
|
37
|
+
FileArtifactService: () => FileArtifactService,
|
|
38
|
+
assertInsideRoot: () => assertInsideRoot,
|
|
39
|
+
assertSafeSegment: () => assertSafeSegment,
|
|
40
|
+
getSessionArtifactsDir: () => getSessionArtifactsDir,
|
|
41
|
+
getUserRoot: () => getUserRoot
|
|
38
42
|
});
|
|
39
43
|
module.exports = __toCommonJS(file_artifact_service_exports);
|
|
40
44
|
var fs = __toESM(require("fs/promises"), 1);
|
|
@@ -346,8 +350,28 @@ class FileArtifactService {
|
|
|
346
350
|
}
|
|
347
351
|
}
|
|
348
352
|
}
|
|
353
|
+
const SAFE_SEGMENT_RE = /^[a-zA-Z0-9_@-][a-zA-Z0-9_.@-]{0,255}$/;
|
|
354
|
+
function assertSafeSegment(value, label) {
|
|
355
|
+
if (!value || !SAFE_SEGMENT_RE.test(value)) {
|
|
356
|
+
throw new Error(
|
|
357
|
+
`[FileArtifactService] Invalid ${label}: value contains disallowed characters.`
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function assertInsideRoot(resolvedPath, rootDir, label) {
|
|
362
|
+
const root = path.resolve(rootDir);
|
|
363
|
+
const resolved = path.resolve(resolvedPath);
|
|
364
|
+
if (!resolved.startsWith(root + path.sep) && resolved !== root) {
|
|
365
|
+
throw new Error(
|
|
366
|
+
`[FileArtifactService] ${label} escapes storage root. Resolved: ${resolved}, Root: ${root}`
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
349
370
|
function getUserRoot(rootDir, userId) {
|
|
350
|
-
|
|
371
|
+
assertSafeSegment(userId, "userId");
|
|
372
|
+
const result = path.join(rootDir, "users", userId);
|
|
373
|
+
assertInsideRoot(result, rootDir, "userRoot");
|
|
374
|
+
return result;
|
|
351
375
|
}
|
|
352
376
|
function isUserScoped(sessionId, filename) {
|
|
353
377
|
return !sessionId || filename.startsWith(USER_NAMESPACE_PREFIX);
|
|
@@ -356,7 +380,10 @@ function getUserArtifactsDir(userRoot) {
|
|
|
356
380
|
return path.join(userRoot, "artifacts");
|
|
357
381
|
}
|
|
358
382
|
function getSessionArtifactsDir(baseRoot, sessionId) {
|
|
359
|
-
|
|
383
|
+
assertSafeSegment(sessionId, "sessionId");
|
|
384
|
+
const result = path.join(baseRoot, "sessions", sessionId, "artifacts");
|
|
385
|
+
assertInsideRoot(result, baseRoot, "sessionArtifactsDir");
|
|
386
|
+
return result;
|
|
360
387
|
}
|
|
361
388
|
function getVersionsDir(artifactDir) {
|
|
362
389
|
return path.join(artifactDir, "versions");
|
|
@@ -487,5 +514,9 @@ function asPosixPath(p) {
|
|
|
487
514
|
}
|
|
488
515
|
// Annotate the CommonJS export names for ESM import in node:
|
|
489
516
|
0 && (module.exports = {
|
|
490
|
-
FileArtifactService
|
|
517
|
+
FileArtifactService,
|
|
518
|
+
assertInsideRoot,
|
|
519
|
+
assertSafeSegment,
|
|
520
|
+
getSessionArtifactsDir,
|
|
521
|
+
getUserRoot
|
|
491
522
|
});
|