@google/adk 1.4.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 +18 -3
- package/dist/cjs/a2a/auth.js +65 -0
- package/dist/cjs/a2a/event_converter_utils.js +47 -18
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/functions.js +26 -28
- package/dist/cjs/agents/llm_agent.js +4 -2
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/cjs/agents/processors/content_processor_utils.js +2 -1
- 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/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- package/dist/cjs/artifacts/in_memory_artifact_service.js +17 -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 +35 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +2 -11
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +64 -0
- package/dist/cjs/context/token_based_context_compactor.js +13 -44
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +28 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- 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/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/runner.js +69 -23
- 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/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/get_user_choice_tool.js +53 -0
- package/dist/cjs/tools/load_web_page.js +250 -0
- package/dist/cjs/tools/mcp/load_mcp_resource_tool.js +140 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/cjs/tools/mcp/mcp_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/cjs/tools/request_input_tool.js +54 -0
- package/dist/cjs/tools/skill/run_skill_inline_script_tool.js +54 -4
- package/dist/cjs/tools/skill/skill_toolset.js +4 -2
- package/dist/cjs/utils/branch_trie.js +41 -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/streaming_utils.js +5 -5
- 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 +18 -3
- package/dist/esm/a2a/auth.js +37 -0
- package/dist/esm/a2a/event_converter_utils.js +47 -18
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/functions.js +27 -24
- package/dist/esm/agents/llm_agent.js +6 -4
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/esm/agents/processors/content_processor_utils.js +2 -1
- 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/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- package/dist/esm/artifacts/in_memory_artifact_service.js +17 -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 +29 -1
- package/dist/esm/context/agent_controlled_context_compactor.js +2 -11
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +38 -0
- package/dist/esm/context/token_based_context_compactor.js +16 -44
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +24 -0
- package/dist/esm/index.js +8 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- 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/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/runner.js +69 -23
- 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/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/get_user_choice_tool.js +25 -0
- package/dist/esm/tools/load_web_page.js +221 -0
- package/dist/esm/tools/mcp/load_mcp_resource_tool.js +114 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/esm/tools/mcp/mcp_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/esm/tools/request_input_tool.js +26 -0
- package/dist/esm/tools/skill/run_skill_inline_script_tool.js +53 -4
- package/dist/esm/tools/skill/skill_toolset.js +4 -2
- package/dist/esm/utils/branch_trie.js +13 -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/streaming_utils.js +1 -1
- package/dist/esm/utils/vertex_ai_utils.js +2 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +5 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +38 -0
- package/dist/types/a2a/auth.d.ts +30 -0
- package/dist/types/a2a/event_converter_utils.d.ts +4 -1
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +1 -9
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- package/dist/types/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -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 +11 -2
- package/dist/types/context/agent_controlled_context_compactor.d.ts +0 -1
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/compaction_utils.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +0 -1
- package/dist/types/events/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +13 -0
- package/dist/types/index.d.ts +5 -3
- 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/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/runner.d.ts +1 -1
- 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/enterprise_web_search_tool.d.ts +26 -0
- package/dist/types/tools/example_tool.d.ts +21 -0
- package/dist/types/tools/get_user_choice_tool.d.ts +14 -0
- package/dist/types/tools/load_web_page.d.ts +33 -0
- package/dist/types/tools/mcp/load_mcp_resource_tool.d.ts +26 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +27 -0
- package/dist/types/tools/request_input_tool.d.ts +15 -0
- package/dist/types/tools/skill/run_skill_inline_script_tool.d.ts +25 -0
- package/dist/types/tools/skill/skill_toolset.d.ts +9 -0
- package/dist/types/utils/branch_trie.d.ts +14 -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 +18 -3
- package/dist/web/a2a/auth.js +37 -0
- package/dist/web/a2a/event_converter_utils.js +47 -18
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/functions.js +27 -24
- package/dist/web/agents/llm_agent.js +6 -4
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/basic_llm_request_processor.js +3 -2
- package/dist/web/agents/processors/content_processor_utils.js +2 -1
- 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/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- package/dist/web/artifacts/in_memory_artifact_service.js +17 -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 +29 -1
- package/dist/web/context/agent_controlled_context_compactor.js +2 -11
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +38 -0
- package/dist/web/context/token_based_context_compactor.js +16 -44
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +24 -0
- package/dist/web/index.js +8 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- 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/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/runner.js +65 -22
- 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/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/get_user_choice_tool.js +25 -0
- package/dist/web/tools/load_web_page.js +221 -0
- package/dist/web/tools/mcp/load_mcp_resource_tool.js +107 -0
- package/dist/web/tools/mcp/mcp_session_manager.js +35 -21
- package/dist/web/tools/mcp/mcp_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +13 -10
- package/dist/web/tools/request_input_tool.js +26 -0
- package/dist/web/tools/skill/run_skill_inline_script_tool.js +51 -4
- package/dist/web/tools/skill/skill_toolset.js +4 -2
- package/dist/web/utils/branch_trie.js +13 -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/streaming_utils.js +1 -1
- package/dist/web/utils/vertex_ai_utils.js +2 -0
- package/dist/web/version.js +1 -1
- package/package.json +1 -1
|
@@ -29,6 +29,7 @@ __export(instructions_llm_request_processor_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(instructions_llm_request_processor_exports);
|
|
31
31
|
var import_llm_request = require("../../models/llm_request.js");
|
|
32
|
+
var import_output_schema_utils = require("../../utils/output_schema_utils.js");
|
|
32
33
|
var import_instructions = require("../instructions.js");
|
|
33
34
|
var import_llm_agent = require("../llm_agent.js");
|
|
34
35
|
var import_readonly_context = require("../readonly_context.js");
|
|
@@ -44,6 +45,7 @@ class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmR
|
|
|
44
45
|
*/
|
|
45
46
|
// eslint-disable-next-line require-yield
|
|
46
47
|
async *runAsync(invocationContext, llmRequest) {
|
|
48
|
+
var _a;
|
|
47
49
|
const agent = invocationContext.agent;
|
|
48
50
|
if (!(0, import_llm_agent.isLlmAgent)(agent)) {
|
|
49
51
|
return;
|
|
@@ -75,7 +77,7 @@ class InstructionsLlmRequestProcessor extends import_base_llm_processor.BaseLlmR
|
|
|
75
77
|
}
|
|
76
78
|
(0, import_llm_request.appendInstructions)(llmRequest, [instructionWithState]);
|
|
77
79
|
}
|
|
78
|
-
if (agent.outputSchema && agent.tools
|
|
80
|
+
if (agent.outputSchema && ((_a = agent.tools) == null ? void 0 : _a.length) && !(0, import_output_schema_utils.canUseOutputSchemaWithTools)(agent.canonicalModel.model)) {
|
|
79
81
|
(0, import_llm_request.appendInstructions)(llmRequest, [
|
|
80
82
|
'To output the final result, you must call the "set_model_response" function with the appropriate values. Do not output anything else.'
|
|
81
83
|
]);
|
|
@@ -64,6 +64,29 @@ let RoutedAgent = class extends (_b = import_base_agent.BaseAgent, _a = ROUTED_A
|
|
|
64
64
|
}
|
|
65
65
|
this.router = config.router;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a detached copy of this routed agent.
|
|
69
|
+
*
|
|
70
|
+
* The inherited {@link BaseAgent.clone} only deep-clones `subAgents`, but a
|
|
71
|
+
* `RoutedAgent` derives its routing targets from `config.agents`. Rebuilding
|
|
72
|
+
* through the base clone alone would re-read the already-parented original
|
|
73
|
+
* agents and throw "already has a parent agent". This override deep-clones the
|
|
74
|
+
* routing targets (unless the caller overrides `agents`) so the rebuilt
|
|
75
|
+
* constructor re-parents fresh, detached copies. The array-vs-record shape
|
|
76
|
+
* and, for records, the keys are preserved so the router keeps selecting the
|
|
77
|
+
* same targets.
|
|
78
|
+
*
|
|
79
|
+
* @param overrides Config fields to override on the clone. Overriding
|
|
80
|
+
* `parentAgent` is rejected by the base implementation.
|
|
81
|
+
* @returns A new detached `RoutedAgent` of the same concrete class.
|
|
82
|
+
*/
|
|
83
|
+
clone(overrides) {
|
|
84
|
+
const nextOverrides = { ...overrides };
|
|
85
|
+
if (!("agents" in nextOverrides)) {
|
|
86
|
+
nextOverrides.agents = cloneRoutingTargets(this.config.agents);
|
|
87
|
+
}
|
|
88
|
+
return super.clone(nextOverrides);
|
|
89
|
+
}
|
|
67
90
|
/**
|
|
68
91
|
* Runs the selected agent via text-based conversation.
|
|
69
92
|
*/
|
|
@@ -90,6 +113,14 @@ let RoutedAgent = class extends (_b = import_base_agent.BaseAgent, _a = ROUTED_A
|
|
|
90
113
|
RoutedAgent = __decorateClass([
|
|
91
114
|
import_experimental.experimental
|
|
92
115
|
], RoutedAgent);
|
|
116
|
+
function cloneRoutingTargets(agents) {
|
|
117
|
+
if (Array.isArray(agents)) {
|
|
118
|
+
return agents.map((agent) => agent.clone());
|
|
119
|
+
}
|
|
120
|
+
return Object.fromEntries(
|
|
121
|
+
Object.entries(agents).map(([key, agent]) => [key, agent.clone()])
|
|
122
|
+
);
|
|
123
|
+
}
|
|
93
124
|
// Annotate the CommonJS export names for ESM import in node:
|
|
94
125
|
0 && (module.exports = {
|
|
95
126
|
RoutedAgent,
|
|
@@ -41,14 +41,15 @@ var StreamingMode = /* @__PURE__ */ ((StreamingMode2) => {
|
|
|
41
41
|
return StreamingMode2;
|
|
42
42
|
})(StreamingMode || {});
|
|
43
43
|
function createRunConfig(params = {}) {
|
|
44
|
+
var _a;
|
|
44
45
|
return {
|
|
45
46
|
saveInputBlobsAsArtifacts: false,
|
|
46
47
|
supportCfc: false,
|
|
47
48
|
enableAffectiveDialog: false,
|
|
48
49
|
streamingMode: "none" /* NONE */,
|
|
49
|
-
maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500),
|
|
50
50
|
pauseOnToolCalls: false,
|
|
51
|
-
...params
|
|
51
|
+
...params,
|
|
52
|
+
maxLlmCalls: validateMaxLlmCalls((_a = params.maxLlmCalls) != null ? _a : 500)
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
function validateMaxLlmCalls(value) {
|
|
@@ -28,6 +28,7 @@ __export(in_memory_artifact_service_exports, {
|
|
|
28
28
|
isInMemoryConnectionString: () => isInMemoryConnectionString
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(in_memory_artifact_service_exports);
|
|
31
|
+
var import_logger = require("../utils/logger.js");
|
|
31
32
|
/**
|
|
32
33
|
* @license
|
|
33
34
|
* Copyright 2025 Google LLC
|
|
@@ -84,6 +85,12 @@ class InMemoryArtifactService {
|
|
|
84
85
|
if (version === void 0) {
|
|
85
86
|
version = versions.length - 1;
|
|
86
87
|
}
|
|
88
|
+
if (!versions[version]) {
|
|
89
|
+
import_logger.logger.warn(
|
|
90
|
+
`[InMemoryArtifactService] loadArtifact: Artifact ${filename} version ${version} not found`
|
|
91
|
+
);
|
|
92
|
+
return Promise.resolve(void 0);
|
|
93
|
+
}
|
|
87
94
|
return Promise.resolve(versions[version].part);
|
|
88
95
|
}
|
|
89
96
|
listArtifactKeys({
|
|
@@ -91,16 +98,14 @@ class InMemoryArtifactService {
|
|
|
91
98
|
userId,
|
|
92
99
|
sessionId
|
|
93
100
|
}) {
|
|
94
|
-
const sessionPrefix =
|
|
95
|
-
const
|
|
101
|
+
const sessionPrefix = artifactPrefix("session", appName, userId, sessionId);
|
|
102
|
+
const userPrefix = artifactPrefix("user", appName, userId);
|
|
96
103
|
const filenames = [];
|
|
97
104
|
for (const path in this.artifacts) {
|
|
98
105
|
if (path.startsWith(sessionPrefix)) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const filename = path.replace(usernamespacePrefix, "");
|
|
103
|
-
filenames.push(filename);
|
|
106
|
+
filenames.push(decodeURIComponent(path.slice(sessionPrefix.length)));
|
|
107
|
+
} else if (path.startsWith(userPrefix)) {
|
|
108
|
+
filenames.push(decodeURIComponent(path.slice(userPrefix.length)));
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
return Promise.resolve(filenames.sort());
|
|
@@ -171,9 +176,12 @@ class InMemoryArtifactService {
|
|
|
171
176
|
}
|
|
172
177
|
function artifactPath(appName, userId, sessionId, filename) {
|
|
173
178
|
if (fileHasUserNamespace(filename)) {
|
|
174
|
-
return `${appName
|
|
179
|
+
return `${artifactPrefix("user", appName, userId)}${encodeURIComponent(filename)}`;
|
|
175
180
|
}
|
|
176
|
-
return `${appName
|
|
181
|
+
return `${artifactPrefix("session", appName, userId, sessionId)}${encodeURIComponent(filename)}`;
|
|
182
|
+
}
|
|
183
|
+
function artifactPrefix(scope, ...parts) {
|
|
184
|
+
return `${[scope, ...parts].map(encodeURIComponent).join("/")}/`;
|
|
177
185
|
}
|
|
178
186
|
function fileHasUserNamespace(filename) {
|
|
179
187
|
return filename.startsWith("user:");
|
|
@@ -34,7 +34,18 @@ module.exports = __toCommonJS(in_memory_credential_service_exports);
|
|
|
34
34
|
*/
|
|
35
35
|
class InMemoryCredentialService {
|
|
36
36
|
constructor() {
|
|
37
|
-
|
|
37
|
+
/**
|
|
38
|
+
* A map from app name to a map from user ID to a map from credential key to
|
|
39
|
+
* credential.
|
|
40
|
+
*
|
|
41
|
+
* `appName`, `userId` and `credentialKey` are all attacker-influenced, so
|
|
42
|
+
* every level is created with `Object.create(null)`. On an ordinary `{}`
|
|
43
|
+
* literal a key of `__proto__` resolves to the inherited `__proto__`
|
|
44
|
+
* accessor rather than creating an own property, so nested assignment
|
|
45
|
+
* pollutes every object in the process, and a lookup of an inherited key
|
|
46
|
+
* such as `toString` returns a function instead of `undefined`.
|
|
47
|
+
*/
|
|
48
|
+
this.credentials = /* @__PURE__ */ Object.create(null);
|
|
38
49
|
}
|
|
39
50
|
loadCredential(authConfig, toolContext) {
|
|
40
51
|
const credentialBucket = this.getBucketForCurrentContext(toolContext);
|
|
@@ -49,10 +60,10 @@ class InMemoryCredentialService {
|
|
|
49
60
|
getBucketForCurrentContext(toolContext) {
|
|
50
61
|
const { appName, userId } = toolContext.invocationContext.session;
|
|
51
62
|
if (!this.credentials[appName]) {
|
|
52
|
-
this.credentials[appName] =
|
|
63
|
+
this.credentials[appName] = /* @__PURE__ */ Object.create(null);
|
|
53
64
|
}
|
|
54
65
|
if (!this.credentials[appName][userId]) {
|
|
55
|
-
this.credentials[appName][userId] =
|
|
66
|
+
this.credentials[appName][userId] = /* @__PURE__ */ Object.create(null);
|
|
56
67
|
}
|
|
57
68
|
return this.credentials[appName][userId];
|
|
58
69
|
}
|
|
@@ -37,7 +37,7 @@ __export(unsafe_local_code_executor_exports, {
|
|
|
37
37
|
UnsafeLocalCodeExecutor: () => UnsafeLocalCodeExecutor
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(unsafe_local_code_executor_exports);
|
|
40
|
-
var
|
|
40
|
+
var import_node_child_process = require("node:child_process");
|
|
41
41
|
var fs = __toESM(require("node:fs/promises"), 1);
|
|
42
42
|
var os = __toESM(require("node:os"), 1);
|
|
43
43
|
var path = __toESM(require("node:path"), 1);
|
|
@@ -52,13 +52,21 @@ var import_code_execution_utils = require("./code_execution_utils.js");
|
|
|
52
52
|
* SPDX-License-Identifier: Apache-2.0
|
|
53
53
|
*/
|
|
54
54
|
const IS_WINDOWS = os.platform() === "win32";
|
|
55
|
+
const POWERSHELL_BASE_ARGS = [
|
|
56
|
+
"-NoLogo",
|
|
57
|
+
"-NoProfile",
|
|
58
|
+
"-ExecutionPolicy",
|
|
59
|
+
"Bypass",
|
|
60
|
+
"-File"
|
|
61
|
+
];
|
|
62
|
+
const CMD_BASE_ARGS = ["/D", "/c"];
|
|
63
|
+
function isPowerShellCommand(commandPath) {
|
|
64
|
+
return /^(powershell|pwsh)(\.exe)?$/i.test(path.win32.basename(commandPath));
|
|
65
|
+
}
|
|
55
66
|
async function createTempScriptFile(code, language, shellCommandPath) {
|
|
56
|
-
const tempDir =
|
|
57
|
-
os.tmpdir(),
|
|
58
|
-
"adk_js_unsafe_code_executor",
|
|
59
|
-
Date.now().toString() + "_" + Math.random().toString(36).slice(2)
|
|
67
|
+
const tempDir = await fs.mkdtemp(
|
|
68
|
+
path.join(os.tmpdir(), "adk_js_unsafe_code_executor_")
|
|
60
69
|
);
|
|
61
|
-
await fs.mkdir(tempDir, { recursive: true });
|
|
62
70
|
const ext = getExtensionForLanguage(language, shellCommandPath) || ".js";
|
|
63
71
|
const filePath = path.join(tempDir, `script${ext}`);
|
|
64
72
|
await fs.writeFile(filePath, code);
|
|
@@ -78,6 +86,9 @@ function getExtensionForLanguage(language, shellCommandPath) {
|
|
|
78
86
|
return ".bat";
|
|
79
87
|
}
|
|
80
88
|
if (language === import_code_execution_utils.CodeExecutionLanguage.SHELL) {
|
|
89
|
+
if (shellCommandPath && isPowerShellCommand(shellCommandPath)) {
|
|
90
|
+
return ".ps1";
|
|
91
|
+
}
|
|
81
92
|
if (IS_WINDOWS) {
|
|
82
93
|
if (shellCommandPath && shellCommandPath.toLowerCase().includes("cmd")) {
|
|
83
94
|
return ".bat";
|
|
@@ -136,17 +147,17 @@ class UnsafeLocalCodeExecutor extends import_base_code_executor.BaseCodeExecutor
|
|
|
136
147
|
command = this.pythonCommandPath;
|
|
137
148
|
} else if (language === import_code_execution_utils.CodeExecutionLanguage.SHELL) {
|
|
138
149
|
command = this.shellCommandPath;
|
|
139
|
-
if (this.shellCommandPath
|
|
140
|
-
args = [
|
|
150
|
+
if (isPowerShellCommand(this.shellCommandPath)) {
|
|
151
|
+
args = [...POWERSHELL_BASE_ARGS, filePath];
|
|
141
152
|
} else if (this.shellCommandPath.toLowerCase().includes("cmd")) {
|
|
142
|
-
args = [
|
|
153
|
+
args = [...CMD_BASE_ARGS, filePath];
|
|
143
154
|
}
|
|
144
155
|
} else if (language === import_code_execution_utils.CodeExecutionLanguage.POWERSHELL) {
|
|
145
156
|
command = IS_WINDOWS ? "powershell" : "pwsh";
|
|
146
|
-
args = [
|
|
157
|
+
args = [...POWERSHELL_BASE_ARGS, filePath];
|
|
147
158
|
} else if (language === import_code_execution_utils.CodeExecutionLanguage.WINDOWS_CMD) {
|
|
148
159
|
command = "cmd.exe";
|
|
149
|
-
args = [
|
|
160
|
+
args = [...CMD_BASE_ARGS, filePath];
|
|
150
161
|
}
|
|
151
162
|
if (params.codeExecutionInput.args) {
|
|
152
163
|
if (Array.isArray(params.codeExecutionInput.args)) {
|
|
@@ -158,7 +169,7 @@ class UnsafeLocalCodeExecutor extends import_base_code_executor.BaseCodeExecutor
|
|
|
158
169
|
}
|
|
159
170
|
}
|
|
160
171
|
const executionResult = await new Promise((resolve) => {
|
|
161
|
-
const child = (0,
|
|
172
|
+
const child = (0, import_node_child_process.spawn)(command, args, {
|
|
162
173
|
timeout: this.timeoutSeconds * 1e3,
|
|
163
174
|
killSignal: "SIGKILL",
|
|
164
175
|
cwd: tempDir
|
package/dist/cjs/common.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(common_exports, {
|
|
|
31
31
|
AgentControlledContextCompactor: () => import_agent_controlled_context_compactor.AgentControlledContextCompactor,
|
|
32
32
|
AgentTool: () => import_agent_tool.AgentTool,
|
|
33
33
|
AgentTransferLlmRequestProcessor: () => import_agent_transfer_llm_request_processor.AgentTransferLlmRequestProcessor,
|
|
34
|
+
AnchoredContextCompactor: () => import_anchored_context_compactor.AnchoredContextCompactor,
|
|
34
35
|
ApigeeLlm: () => import_apigee_llm.ApigeeLlm,
|
|
35
36
|
AuthCredentialTypes: () => import_auth_credential.AuthCredentialTypes,
|
|
36
37
|
AuthHandler: () => import_auth_handler.AuthHandler,
|
|
@@ -56,8 +57,11 @@ __export(common_exports, {
|
|
|
56
57
|
ContextCompactorRequestProcessor: () => import_context_compactor_request_processor.ContextCompactorRequestProcessor,
|
|
57
58
|
CredentialExchangeError: () => import_base_credential_exchanger.CredentialExchangeError,
|
|
58
59
|
CredentialRefresherRegistry: () => import_credential_refresher_registry.CredentialRefresherRegistry,
|
|
60
|
+
ENTERPRISE_WEB_SEARCH: () => import_enterprise_web_search_tool.ENTERPRISE_WEB_SEARCH,
|
|
59
61
|
EXIT_LOOP: () => import_exit_loop_tool.EXIT_LOOP,
|
|
62
|
+
EnterpriseWebSearchTool: () => import_enterprise_web_search_tool.EnterpriseWebSearchTool,
|
|
60
63
|
EventType: () => import_structured_events.EventType,
|
|
64
|
+
ExampleTool: () => import_example_tool.ExampleTool,
|
|
61
65
|
ExitLoopTool: () => import_exit_loop_tool.ExitLoopTool,
|
|
62
66
|
FileContentEncoding: () => import_code_execution_utils.FileContentEncoding,
|
|
63
67
|
FunctionTool: () => import_function_tool.FunctionTool,
|
|
@@ -65,6 +69,7 @@ __export(common_exports, {
|
|
|
65
69
|
GOOGLE_MAPS_GROUNDING: () => import_google_maps_grounding_tool.GOOGLE_MAPS_GROUNDING,
|
|
66
70
|
GOOGLE_SEARCH: () => import_google_search_tool.GOOGLE_SEARCH,
|
|
67
71
|
Gemini: () => import_google_llm.Gemini,
|
|
72
|
+
GlobalInstructionPlugin: () => import_global_instruction_plugin.GlobalInstructionPlugin,
|
|
68
73
|
GoogleLLMVariant: () => import_variant_utils.GoogleLLMVariant,
|
|
69
74
|
GoogleMapsGroundingTool: () => import_google_maps_grounding_tool.GoogleMapsGroundingTool,
|
|
70
75
|
GoogleSearchTool: () => import_google_search_tool.GoogleSearchTool,
|
|
@@ -80,6 +85,7 @@ __export(common_exports, {
|
|
|
80
85
|
LLMRegistry: () => import_registry.LLMRegistry,
|
|
81
86
|
LOAD_ARTIFACTS: () => import_load_artifacts_tool.LOAD_ARTIFACTS,
|
|
82
87
|
LOAD_MEMORY: () => import_load_memory_tool.LOAD_MEMORY,
|
|
88
|
+
LOAD_WEB_PAGE: () => import_load_web_page.LOAD_WEB_PAGE,
|
|
83
89
|
ListSkillsTool: () => import_list_skills_tool.ListSkillsTool,
|
|
84
90
|
LiveRequestQueue: () => import_live_request_queue.LiveRequestQueue,
|
|
85
91
|
LlmAgent: () => import_llm_agent.LlmAgent,
|
|
@@ -138,11 +144,14 @@ __export(common_exports, {
|
|
|
138
144
|
findMatchingFunctionCall: () => import_functions.findMatchingFunctionCall,
|
|
139
145
|
functionsExportedForTestingOnly: () => import_functions.functionsExportedForTestingOnly,
|
|
140
146
|
geminiInitParams: () => import_google_llm.geminiInitParams,
|
|
147
|
+
generateClientFunctionCallId: () => import_event.generateClientFunctionCallId,
|
|
141
148
|
getAskUserConfirmationFunctionCalls: () => import_security_plugin.getAskUserConfirmationFunctionCalls,
|
|
142
149
|
getClientLabels: () => import_client_labels.getClientLabels,
|
|
143
150
|
getFunctionCalls: () => import_event.getFunctionCalls,
|
|
144
151
|
getFunctionResponses: () => import_event.getFunctionResponses,
|
|
145
152
|
getLogger: () => import_logger.getLogger,
|
|
153
|
+
getUserChoiceTool: () => import_get_user_choice_tool.getUserChoiceTool,
|
|
154
|
+
hasThoughts: () => import_event.hasThoughts,
|
|
146
155
|
hasTrailingCodeExecutionResult: () => import_event.hasTrailingCodeExecutionResult,
|
|
147
156
|
isAgentTool: () => import_agent_tool.isAgentTool,
|
|
148
157
|
isBaseAgent: () => import_base_agent.isBaseAgent,
|
|
@@ -161,10 +170,15 @@ __export(common_exports, {
|
|
|
161
170
|
isRoutableLlmAgent: () => import_runner.isRoutableLlmAgent,
|
|
162
171
|
isRoutedAgent: () => import_routed_agent.isRoutedAgent,
|
|
163
172
|
isRunner: () => import_runner.isRunner,
|
|
173
|
+
isScratchpadEvent: () => import_compacted_event.isScratchpadEvent,
|
|
164
174
|
isSequentialAgent: () => import_sequential_agent.isSequentialAgent,
|
|
165
175
|
loadAllSkillsInDir: () => import_loader.loadAllSkillsInDir,
|
|
166
176
|
loadSkillFromDir: () => import_loader.loadSkillFromDir,
|
|
167
177
|
loadSkillFromZipBuffer: () => import_loader.loadSkillFromZipBuffer,
|
|
178
|
+
loadWebPage: () => import_load_web_page.loadWebPage,
|
|
179
|
+
populateClientFunctionCallId: () => import_event.populateClientFunctionCallId,
|
|
180
|
+
pruneThoughts: () => import_event.pruneThoughts,
|
|
181
|
+
requestInputTool: () => import_request_input_tool.requestInputTool,
|
|
168
182
|
runWithClientLabel: () => import_client_labels.runWithClientLabel,
|
|
169
183
|
setLogLevel: () => import_logger.setLogLevel,
|
|
170
184
|
setLogger: () => import_logger.setLogger,
|
|
@@ -210,6 +224,7 @@ var import_base_code_executor = require("./code_executors/base_code_executor.js"
|
|
|
210
224
|
var import_built_in_code_executor = require("./code_executors/built_in_code_executor.js");
|
|
211
225
|
var import_code_execution_utils = require("./code_executors/code_execution_utils.js");
|
|
212
226
|
var import_agent_controlled_context_compactor = require("./context/agent_controlled_context_compactor.js");
|
|
227
|
+
var import_anchored_context_compactor = require("./context/anchored_context_compactor.js");
|
|
213
228
|
var import_llm_summarizer = require("./context/summarizers/llm_summarizer.js");
|
|
214
229
|
var import_token_based_context_compactor = require("./context/token_based_context_compactor.js");
|
|
215
230
|
var import_trajectory_thought_pruning_compactor = require("./context/trajectory_thought_pruning_compactor.js");
|
|
@@ -227,6 +242,7 @@ var import_google_llm = require("./models/google_llm.js");
|
|
|
227
242
|
var import_registry = require("./models/registry.js");
|
|
228
243
|
var import_routed_llm = require("./models/routed_llm.js");
|
|
229
244
|
var import_base_plugin = require("./plugins/base_plugin.js");
|
|
245
|
+
var import_global_instruction_plugin = require("./plugins/global_instruction_plugin.js");
|
|
230
246
|
var import_logging_plugin = require("./plugins/logging_plugin.js");
|
|
231
247
|
var import_plugin_manager = require("./plugins/plugin_manager.js");
|
|
232
248
|
var import_security_plugin = require("./plugins/security_plugin.js");
|
|
@@ -240,14 +256,19 @@ var import_agent_tool = require("./tools/agent_tool.js");
|
|
|
240
256
|
var import_base_tool = require("./tools/base_tool.js");
|
|
241
257
|
var import_base_toolset = require("./tools/base_toolset.js");
|
|
242
258
|
var import_consolidate_context_tool = require("./tools/consolidate_context_tool.js");
|
|
259
|
+
var import_enterprise_web_search_tool = require("./tools/enterprise_web_search_tool.js");
|
|
260
|
+
var import_example_tool = require("./tools/example_tool.js");
|
|
243
261
|
var import_exit_loop_tool = require("./tools/exit_loop_tool.js");
|
|
244
262
|
var import_function_tool = require("./tools/function_tool.js");
|
|
263
|
+
var import_get_user_choice_tool = require("./tools/get_user_choice_tool.js");
|
|
245
264
|
var import_google_maps_grounding_tool = require("./tools/google_maps_grounding_tool.js");
|
|
246
265
|
var import_google_search_tool = require("./tools/google_search_tool.js");
|
|
247
266
|
var import_load_artifacts_tool = require("./tools/load_artifacts_tool.js");
|
|
248
267
|
var import_load_memory_tool = require("./tools/load_memory_tool.js");
|
|
268
|
+
var import_load_web_page = require("./tools/load_web_page.js");
|
|
249
269
|
var import_long_running_tool = require("./tools/long_running_tool.js");
|
|
250
270
|
var import_preload_memory_tool = require("./tools/preload_memory_tool.js");
|
|
271
|
+
var import_request_input_tool = require("./tools/request_input_tool.js");
|
|
251
272
|
var import_tool_confirmation = require("./tools/tool_confirmation.js");
|
|
252
273
|
var import_url_context_tool = require("./tools/url_context_tool.js");
|
|
253
274
|
var import_vertex_ai_search_tool = require("./tools/vertex_ai_search_tool.js");
|
|
@@ -295,6 +316,7 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
295
316
|
AgentControlledContextCompactor,
|
|
296
317
|
AgentTool,
|
|
297
318
|
AgentTransferLlmRequestProcessor,
|
|
319
|
+
AnchoredContextCompactor,
|
|
298
320
|
ApigeeLlm,
|
|
299
321
|
AuthCredentialTypes,
|
|
300
322
|
AuthHandler,
|
|
@@ -320,8 +342,11 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
320
342
|
ContextCompactorRequestProcessor,
|
|
321
343
|
CredentialExchangeError,
|
|
322
344
|
CredentialRefresherRegistry,
|
|
345
|
+
ENTERPRISE_WEB_SEARCH,
|
|
323
346
|
EXIT_LOOP,
|
|
347
|
+
EnterpriseWebSearchTool,
|
|
324
348
|
EventType,
|
|
349
|
+
ExampleTool,
|
|
325
350
|
ExitLoopTool,
|
|
326
351
|
FileContentEncoding,
|
|
327
352
|
FunctionTool,
|
|
@@ -329,6 +354,7 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
329
354
|
GOOGLE_MAPS_GROUNDING,
|
|
330
355
|
GOOGLE_SEARCH,
|
|
331
356
|
Gemini,
|
|
357
|
+
GlobalInstructionPlugin,
|
|
332
358
|
GoogleLLMVariant,
|
|
333
359
|
GoogleMapsGroundingTool,
|
|
334
360
|
GoogleSearchTool,
|
|
@@ -344,6 +370,7 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
344
370
|
LLMRegistry,
|
|
345
371
|
LOAD_ARTIFACTS,
|
|
346
372
|
LOAD_MEMORY,
|
|
373
|
+
LOAD_WEB_PAGE,
|
|
347
374
|
ListSkillsTool,
|
|
348
375
|
LiveRequestQueue,
|
|
349
376
|
LlmAgent,
|
|
@@ -402,11 +429,14 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
402
429
|
findMatchingFunctionCall,
|
|
403
430
|
functionsExportedForTestingOnly,
|
|
404
431
|
geminiInitParams,
|
|
432
|
+
generateClientFunctionCallId,
|
|
405
433
|
getAskUserConfirmationFunctionCalls,
|
|
406
434
|
getClientLabels,
|
|
407
435
|
getFunctionCalls,
|
|
408
436
|
getFunctionResponses,
|
|
409
437
|
getLogger,
|
|
438
|
+
getUserChoiceTool,
|
|
439
|
+
hasThoughts,
|
|
410
440
|
hasTrailingCodeExecutionResult,
|
|
411
441
|
isAgentTool,
|
|
412
442
|
isBaseAgent,
|
|
@@ -425,10 +455,15 @@ __reExport(common_exports, require("./tools/base_tool.js"), module.exports);
|
|
|
425
455
|
isRoutableLlmAgent,
|
|
426
456
|
isRoutedAgent,
|
|
427
457
|
isRunner,
|
|
458
|
+
isScratchpadEvent,
|
|
428
459
|
isSequentialAgent,
|
|
429
460
|
loadAllSkillsInDir,
|
|
430
461
|
loadSkillFromDir,
|
|
431
462
|
loadSkillFromZipBuffer,
|
|
463
|
+
loadWebPage,
|
|
464
|
+
populateClientFunctionCallId,
|
|
465
|
+
pruneThoughts,
|
|
466
|
+
requestInputTool,
|
|
432
467
|
runWithClientLabel,
|
|
433
468
|
setLogLevel,
|
|
434
469
|
setLogger,
|
|
@@ -27,9 +27,9 @@ __export(agent_controlled_context_compactor_exports, {
|
|
|
27
27
|
AgentControlledContextCompactor: () => AgentControlledContextCompactor
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(agent_controlled_context_compactor_exports);
|
|
30
|
-
var import_compacted_event = require("../events/compacted_event.js");
|
|
31
30
|
var import_event = require("../events/event.js");
|
|
32
31
|
var import_base_plugin = require("../plugins/base_plugin.js");
|
|
32
|
+
var import_compaction_utils = require("./compaction_utils.js");
|
|
33
33
|
/**
|
|
34
34
|
* @license
|
|
35
35
|
* Copyright 2026 Google LLC
|
|
@@ -45,7 +45,7 @@ class AgentControlledContextCompactor {
|
|
|
45
45
|
}
|
|
46
46
|
async compact(invocationContext) {
|
|
47
47
|
const events = invocationContext.session.events;
|
|
48
|
-
const activeEvents =
|
|
48
|
+
const activeEvents = (0, import_compaction_utils.getActiveEvents)(events);
|
|
49
49
|
const consolidateToolCallIndex = activeEvents.reduce(
|
|
50
50
|
(acc, e, idx) => {
|
|
51
51
|
var _a, _b;
|
|
@@ -93,15 +93,6 @@ class AgentControlledContextCompactor {
|
|
|
93
93
|
delete invocationContext.session.state["temp:consolidate_context"];
|
|
94
94
|
delete invocationContext.session.state["temp:consolidate_context_detail"];
|
|
95
95
|
}
|
|
96
|
-
getActiveEvents(events) {
|
|
97
|
-
const latest = events.filter(import_compacted_event.isCompactedEvent).pop();
|
|
98
|
-
return latest ? [
|
|
99
|
-
latest,
|
|
100
|
-
...events.filter(
|
|
101
|
-
(e) => !(0, import_compacted_event.isCompactedEvent)(e) && e.timestamp > latest.endTime
|
|
102
|
-
)
|
|
103
|
-
] : events;
|
|
104
|
-
}
|
|
105
96
|
}
|
|
106
97
|
// Annotate the CommonJS export names for ESM import in node:
|
|
107
98
|
0 && (module.exports = {
|
|
@@ -0,0 +1,127 @@
|
|
|
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 anchored_context_compactor_exports = {};
|
|
26
|
+
__export(anchored_context_compactor_exports, {
|
|
27
|
+
AnchoredContextCompactor: () => AnchoredContextCompactor
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(anchored_context_compactor_exports);
|
|
30
|
+
var import_compacted_event = require("../events/compacted_event.js");
|
|
31
|
+
var import_event = require("../events/event.js");
|
|
32
|
+
var import_compaction_utils = require("./compaction_utils.js");
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2026 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/
|
|
38
|
+
class AnchoredContextCompactor {
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.tokenThreshold = options.tokenThreshold;
|
|
41
|
+
this.eventRetentionSize = options.eventRetentionSize;
|
|
42
|
+
this.summarizer = options.summarizer;
|
|
43
|
+
}
|
|
44
|
+
getActiveEvents(events) {
|
|
45
|
+
let latestScratchpad = void 0;
|
|
46
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
47
|
+
const e = events[i];
|
|
48
|
+
if ((0, import_compacted_event.isScratchpadEvent)(e)) {
|
|
49
|
+
latestScratchpad = e;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (!latestScratchpad) {
|
|
54
|
+
return events;
|
|
55
|
+
}
|
|
56
|
+
const activeRawEvents = events.filter(
|
|
57
|
+
(e) => e.timestamp > latestScratchpad.endTime && !(0, import_compacted_event.isScratchpadEvent)(e)
|
|
58
|
+
);
|
|
59
|
+
return [latestScratchpad, ...activeRawEvents];
|
|
60
|
+
}
|
|
61
|
+
shouldCompact(invocationContext) {
|
|
62
|
+
const events = invocationContext.session.events;
|
|
63
|
+
const activeEvents = this.getActiveEvents(events);
|
|
64
|
+
const hasScratchpad = activeEvents.length > 0 && (0, import_compacted_event.isScratchpadEvent)(activeEvents[0]);
|
|
65
|
+
const rawEvents = hasScratchpad ? activeEvents.slice(1) : activeEvents;
|
|
66
|
+
if (rawEvents.length <= this.eventRetentionSize) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const retainStartIndex = (0, import_compaction_utils.calculateRetainStartIndex)(
|
|
70
|
+
rawEvents,
|
|
71
|
+
this.eventRetentionSize
|
|
72
|
+
);
|
|
73
|
+
if (retainStartIndex === 0) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const totalTokens = activeEvents.reduce(
|
|
77
|
+
(sum, event) => sum + (0, import_event.getEventTokens)(event),
|
|
78
|
+
0
|
|
79
|
+
);
|
|
80
|
+
return totalTokens > this.tokenThreshold;
|
|
81
|
+
}
|
|
82
|
+
async compact(invocationContext) {
|
|
83
|
+
const events = invocationContext.session.events;
|
|
84
|
+
const activeEvents = this.getActiveEvents(events);
|
|
85
|
+
const hasScratchpad = activeEvents.length > 0 && (0, import_compacted_event.isScratchpadEvent)(activeEvents[0]);
|
|
86
|
+
const rawEvents = hasScratchpad ? activeEvents.slice(1) : activeEvents;
|
|
87
|
+
if (rawEvents.length <= this.eventRetentionSize) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const retainStartIndex = (0, import_compaction_utils.calculateRetainStartIndex)(
|
|
91
|
+
rawEvents,
|
|
92
|
+
this.eventRetentionSize
|
|
93
|
+
);
|
|
94
|
+
if (retainStartIndex === 0) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const rawEventsToCompact = rawEvents.slice(0, retainStartIndex);
|
|
98
|
+
let scratchpadEvent;
|
|
99
|
+
if (hasScratchpad) {
|
|
100
|
+
const existingScratchpad = activeEvents[0];
|
|
101
|
+
scratchpadEvent = await this.summarizer.summarize([
|
|
102
|
+
existingScratchpad,
|
|
103
|
+
...rawEventsToCompact
|
|
104
|
+
]);
|
|
105
|
+
} else {
|
|
106
|
+
scratchpadEvent = await this.summarizer.summarize(rawEventsToCompact);
|
|
107
|
+
}
|
|
108
|
+
const updatedScratchpad = {
|
|
109
|
+
...scratchpadEvent,
|
|
110
|
+
isScratchpad: true,
|
|
111
|
+
author: "system"
|
|
112
|
+
};
|
|
113
|
+
const inactiveEvents = events.slice(0, events.indexOf(activeEvents[0]));
|
|
114
|
+
const retainedRawEvents = rawEvents.slice(retainStartIndex);
|
|
115
|
+
const newEventsList = [
|
|
116
|
+
...inactiveEvents,
|
|
117
|
+
updatedScratchpad,
|
|
118
|
+
...retainedRawEvents
|
|
119
|
+
];
|
|
120
|
+
events.length = 0;
|
|
121
|
+
events.push(...newEventsList);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
125
|
+
0 && (module.exports = {
|
|
126
|
+
AnchoredContextCompactor
|
|
127
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
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 compaction_utils_exports = {};
|
|
26
|
+
__export(compaction_utils_exports, {
|
|
27
|
+
calculateRetainStartIndex: () => calculateRetainStartIndex,
|
|
28
|
+
getActiveEvents: () => getActiveEvents
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(compaction_utils_exports);
|
|
31
|
+
var import_compacted_event = require("../events/compacted_event.js");
|
|
32
|
+
var import_event = require("../events/event.js");
|
|
33
|
+
/**
|
|
34
|
+
* @license
|
|
35
|
+
* Copyright 2026 Google LLC
|
|
36
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
37
|
+
*/
|
|
38
|
+
function getActiveEvents(events) {
|
|
39
|
+
const latest = events.filter(import_compacted_event.isCompactedEvent).pop();
|
|
40
|
+
return latest ? [
|
|
41
|
+
latest,
|
|
42
|
+
...events.filter(
|
|
43
|
+
(e) => !(0, import_compacted_event.isCompactedEvent)(e) && e.timestamp > latest.endTime
|
|
44
|
+
)
|
|
45
|
+
] : events;
|
|
46
|
+
}
|
|
47
|
+
function calculateRetainStartIndex(rawEvents, eventRetentionSize) {
|
|
48
|
+
let retainStartIndex = Math.max(0, rawEvents.length - eventRetentionSize);
|
|
49
|
+
while (retainStartIndex > 0) {
|
|
50
|
+
const eventToRetain = rawEvents[retainStartIndex];
|
|
51
|
+
const previousEvent = rawEvents[retainStartIndex - 1];
|
|
52
|
+
if ((0, import_event.getFunctionResponses)(eventToRetain).length > 0 && (0, import_event.getFunctionCalls)(previousEvent).length > 0) {
|
|
53
|
+
retainStartIndex--;
|
|
54
|
+
} else {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return retainStartIndex;
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
calculateRetainStartIndex,
|
|
63
|
+
getActiveEvents
|
|
64
|
+
});
|