@google/adk 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/a2a/agent_to_a2a.js +18 -2
- package/dist/cjs/a2a/event_converter_utils.js +8 -4
- package/dist/cjs/a2a/metadata_converter_utils.js +1 -1
- package/dist/cjs/agents/active_streaming_tool.js +6 -1
- package/dist/cjs/agents/base_agent.js +39 -0
- package/dist/cjs/agents/context.js +1 -11
- package/dist/cjs/agents/functions.js +39 -35
- package/dist/cjs/agents/instructions.js +23 -5
- package/dist/cjs/agents/invocation_context.js +2 -5
- package/dist/cjs/agents/llm_agent.js +10 -7
- package/dist/cjs/agents/loop_agent.js +15 -3
- package/dist/cjs/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/cjs/agents/processors/content_processor_utils.js +18 -4
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/cjs/agents/processors/interactions_request_processor.js +63 -0
- package/dist/cjs/agents/routed_agent.js +31 -0
- package/dist/cjs/agents/run_config.js +3 -2
- package/dist/cjs/apps/app.js +79 -0
- package/dist/cjs/apps/resumability_config.js +44 -0
- package/dist/cjs/artifacts/file_artifact_service.js +14 -1
- package/dist/cjs/artifacts/gcs_artifact_service.js +57 -15
- package/dist/cjs/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/cjs/artifacts/scoped_artifact_service.js +101 -0
- package/dist/cjs/artifacts/session_artifact_service.js +27 -0
- package/dist/cjs/auth/oauth2/oauth2_discovery.js +17 -5
- package/dist/cjs/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/cjs/common.js +76 -0
- package/dist/cjs/context/agent_controlled_context_compactor.js +109 -0
- package/dist/cjs/context/anchored_context_compactor.js +127 -0
- package/dist/cjs/context/compaction_utils.js +52 -0
- package/dist/cjs/context/token_based_context_compactor.js +52 -33
- package/dist/cjs/context/trajectory_thought_pruning_compactor.js +71 -0
- package/dist/cjs/events/compacted_event.js +9 -3
- package/dist/cjs/events/event.js +52 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/cjs/models/google_llm.js +25 -10
- package/dist/cjs/models/interactions_utils.js +732 -0
- package/dist/cjs/plugins/base_plugin.js +1 -0
- package/dist/cjs/plugins/global_instruction_plugin.js +97 -0
- package/dist/cjs/runner/in_memory_runner.js +13 -2
- package/dist/cjs/runner/runner.js +143 -83
- package/dist/cjs/sessions/base_session_service.js +6 -1
- package/dist/cjs/sessions/database_session_service.js +24 -7
- package/dist/cjs/sessions/vertex_ai_session_service.js +19 -4
- package/dist/cjs/skills/loader.js +2 -2
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/consolidate_context_tool.js +79 -0
- package/dist/cjs/tools/enterprise_web_search_tool.js +81 -0
- package/dist/cjs/tools/example_tool.js +68 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +16 -28
- 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_toolset.js +63 -0
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- 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/async_hooks_shim.js +52 -0
- package/dist/cjs/utils/branch_trie.js +41 -0
- package/dist/cjs/utils/client_labels.js +41 -3
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/streaming_utils.js +15 -9
- package/dist/cjs/utils/task.js +62 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/agent_to_a2a.js +18 -2
- package/dist/esm/a2a/event_converter_utils.js +8 -4
- package/dist/esm/a2a/metadata_converter_utils.js +1 -1
- package/dist/esm/agents/active_streaming_tool.js +6 -1
- package/dist/esm/agents/base_agent.js +39 -0
- package/dist/esm/agents/context.js +1 -11
- package/dist/esm/agents/functions.js +43 -32
- package/dist/esm/agents/instructions.js +23 -5
- package/dist/esm/agents/invocation_context.js +2 -5
- package/dist/esm/agents/llm_agent.js +12 -9
- package/dist/esm/agents/loop_agent.js +15 -3
- package/dist/esm/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/esm/agents/processors/content_processor_utils.js +16 -3
- package/dist/esm/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/esm/agents/processors/interactions_request_processor.js +34 -0
- package/dist/esm/agents/routed_agent.js +31 -0
- package/dist/esm/agents/run_config.js +3 -2
- package/dist/esm/apps/app.js +49 -0
- package/dist/esm/apps/resumability_config.js +16 -0
- package/dist/esm/artifacts/file_artifact_service.js +14 -1
- package/dist/esm/artifacts/gcs_artifact_service.js +57 -15
- package/dist/esm/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/esm/artifacts/scoped_artifact_service.js +73 -0
- package/dist/esm/artifacts/session_artifact_service.js +7 -0
- package/dist/esm/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/esm/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/esm/common.js +67 -3
- package/dist/esm/context/agent_controlled_context_compactor.js +81 -0
- package/dist/esm/context/anchored_context_compactor.js +99 -0
- package/dist/esm/context/compaction_utils.js +27 -0
- package/dist/esm/context/token_based_context_compactor.js +52 -33
- package/dist/esm/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/esm/events/compacted_event.js +7 -2
- package/dist/esm/events/event.js +46 -0
- package/dist/esm/index.js +6 -1
- package/dist/esm/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/esm/models/google_llm.js +23 -9
- package/dist/esm/models/interactions_utils.js +697 -0
- package/dist/esm/plugins/base_plugin.js +1 -0
- package/dist/esm/plugins/global_instruction_plugin.js +69 -0
- package/dist/esm/runner/in_memory_runner.js +13 -2
- package/dist/esm/runner/runner.js +141 -84
- package/dist/esm/sessions/base_session_service.js +6 -1
- package/dist/esm/sessions/database_session_service.js +24 -7
- package/dist/esm/sessions/vertex_ai_session_service.js +17 -3
- package/dist/esm/skills/loader.js +2 -2
- package/dist/esm/tools/base_toolset.js +1 -1
- package/dist/esm/tools/consolidate_context_tool.js +51 -0
- package/dist/esm/tools/enterprise_web_search_tool.js +55 -0
- package/dist/esm/tools/example_tool.js +42 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -28
- 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_toolset.js +63 -0
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- 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/async_hooks_shim.js +24 -0
- package/dist/esm/utils/branch_trie.js +13 -0
- package/dist/esm/utils/client_labels.js +38 -2
- package/dist/esm/utils/env_aware_utils.js +10 -1
- package/dist/esm/utils/streaming_utils.js +11 -5
- package/dist/esm/utils/task.js +34 -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/agents/active_streaming_tool.d.ts +3 -4
- package/dist/types/agents/base_agent.d.ts +29 -1
- package/dist/types/agents/functions.d.ts +12 -17
- package/dist/types/agents/invocation_context.d.ts +7 -3
- package/dist/types/agents/llm_agent.d.ts +5 -1
- package/dist/types/agents/loop_agent.d.ts +2 -2
- package/dist/types/agents/processors/content_processor_utils.d.ts +8 -0
- package/dist/types/agents/processors/interactions_request_processor.d.ts +17 -0
- package/dist/types/agents/routed_agent.d.ts +24 -1
- package/dist/types/agents/run_config.d.ts +1 -1
- package/dist/types/apps/app.d.ts +52 -0
- package/dist/types/apps/resumability_config.d.ts +27 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +6 -36
- package/dist/types/artifacts/gcs_artifact_service.d.ts +2 -1
- package/dist/types/artifacts/scoped_artifact_service.d.ts +25 -0
- package/dist/types/artifacts/session_artifact_service.d.ts +25 -0
- package/dist/types/auth/oauth2/oauth2_discovery.d.ts +11 -0
- package/dist/types/common.d.ts +29 -5
- package/dist/types/context/agent_controlled_context_compactor.d.ts +24 -0
- package/dist/types/context/anchored_context_compactor.d.ts +35 -0
- package/dist/types/context/base_context_compactor.d.ts +3 -0
- package/dist/types/context/compaction_utils.d.ts +15 -0
- package/dist/types/context/token_based_context_compactor.d.ts +6 -1
- package/dist/types/context/trajectory_thought_pruning_compactor.d.ts +27 -0
- package/dist/types/events/compacted_event.d.ts +10 -0
- package/dist/types/events/event.d.ts +21 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/models/google_llm.d.ts +15 -1
- package/dist/types/models/interactions_utils.d.ts +92 -0
- package/dist/types/models/llm_request.d.ts +4 -0
- package/dist/types/models/llm_response.d.ts +4 -0
- package/dist/types/plugins/base_plugin.d.ts +2 -1
- package/dist/types/plugins/global_instruction_plugin.d.ts +38 -0
- package/dist/types/runner/in_memory_runner.d.ts +7 -1
- package/dist/types/runner/runner.d.ts +44 -10
- package/dist/types/sessions/base_session_service.d.ts +3 -16
- package/dist/types/sessions/session.d.ts +11 -0
- package/dist/types/sessions/vertex_ai_session_service.d.ts +9 -1
- package/dist/types/tools/consolidate_context_tool.d.ts +19 -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/forwarding_artifact_service.d.ts +3 -2
- 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/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/async_hooks_shim.d.ts +10 -0
- package/dist/types/utils/branch_trie.d.ts +14 -0
- package/dist/types/utils/client_labels.d.ts +10 -0
- package/dist/types/utils/env_aware_utils.d.ts +3 -3
- package/dist/types/utils/task.d.ts +24 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/agent_to_a2a.js +18 -2
- package/dist/web/a2a/event_converter_utils.js +8 -4
- package/dist/web/a2a/metadata_converter_utils.js +1 -1
- package/dist/web/agents/active_streaming_tool.js +6 -1
- package/dist/web/agents/base_agent.js +39 -0
- package/dist/web/agents/context.js +1 -11
- package/dist/web/agents/functions.js +43 -32
- package/dist/web/agents/instructions.js +23 -5
- package/dist/web/agents/invocation_context.js +2 -5
- package/dist/web/agents/llm_agent.js +12 -9
- package/dist/web/agents/loop_agent.js +27 -3
- package/dist/web/agents/processors/code_execution_request_processor.js +0 -3
- package/dist/web/agents/processors/content_processor_utils.js +16 -3
- package/dist/web/agents/processors/context_compactor_request_processor.js +4 -2
- package/dist/web/agents/processors/interactions_request_processor.js +52 -0
- package/dist/web/agents/routed_agent.js +31 -0
- package/dist/web/agents/run_config.js +8 -3
- package/dist/web/apps/app.js +49 -0
- package/dist/web/apps/resumability_config.js +31 -0
- package/dist/web/artifacts/file_artifact_service.js +14 -1
- package/dist/web/artifacts/gcs_artifact_service.js +55 -15
- package/dist/web/artifacts/in_memory_artifact_service.js +12 -1
- package/dist/web/artifacts/scoped_artifact_service.js +86 -0
- package/dist/web/artifacts/session_artifact_service.js +7 -0
- package/dist/web/auth/oauth2/oauth2_discovery.js +14 -4
- package/dist/web/auth/oauth2/oauth2_utils.js +12 -1
- package/dist/web/common.js +67 -3
- package/dist/web/context/agent_controlled_context_compactor.js +81 -0
- package/dist/web/context/anchored_context_compactor.js +117 -0
- package/dist/web/context/compaction_utils.js +27 -0
- package/dist/web/context/token_based_context_compactor.js +52 -33
- package/dist/web/context/trajectory_thought_pruning_compactor.js +43 -0
- package/dist/web/events/compacted_event.js +7 -2
- package/dist/web/events/event.js +44 -0
- package/dist/web/index.js +6 -1
- package/dist/web/integrations/agent_registry/agent_registry_mcp_toolset.js +9 -1
- package/dist/web/models/google_llm.js +54 -9
- package/dist/web/models/interactions_utils.js +728 -0
- package/dist/web/plugins/base_plugin.js +1 -0
- package/dist/web/plugins/global_instruction_plugin.js +67 -0
- package/dist/web/runner/in_memory_runner.js +13 -2
- package/dist/web/runner/runner.js +157 -84
- package/dist/web/sessions/base_session_service.js +6 -1
- package/dist/web/sessions/database_session_service.js +24 -7
- package/dist/web/sessions/vertex_ai_session_service.js +17 -3
- package/dist/web/skills/loader.js +2 -2
- package/dist/web/tools/base_toolset.js +1 -1
- package/dist/web/tools/consolidate_context_tool.js +51 -0
- package/dist/web/tools/enterprise_web_search_tool.js +55 -0
- package/dist/web/tools/example_tool.js +42 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -28
- 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_toolset.js +63 -0
- package/dist/web/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -22
- 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/async_hooks_shim.js +24 -0
- package/dist/web/utils/branch_trie.js +13 -0
- package/dist/web/utils/client_labels.js +38 -2
- package/dist/web/utils/env_aware_utils.js +10 -1
- package/dist/web/utils/streaming_utils.js +11 -5
- package/dist/web/utils/task.js +34 -0
- package/dist/web/version.js +1 -1
- package/package.json +2 -2
|
@@ -26,7 +26,7 @@ class FileArtifactService {
|
|
|
26
26
|
artifact,
|
|
27
27
|
customMetadata
|
|
28
28
|
}) {
|
|
29
|
-
if (!artifact.inlineData && !artifact.text) {
|
|
29
|
+
if (!artifact.inlineData && !artifact.text && !artifact.fileData) {
|
|
30
30
|
throw new Error("Artifact must have either inlineData or text content.");
|
|
31
31
|
}
|
|
32
32
|
const artifactDir = getArtifactDir(
|
|
@@ -44,12 +44,19 @@ class FileArtifactService {
|
|
|
44
44
|
const storedFilename = path.basename(artifactDir);
|
|
45
45
|
const contentPath = path.join(versionDir, storedFilename);
|
|
46
46
|
let mimeType;
|
|
47
|
+
let fileUri;
|
|
47
48
|
if (artifact.inlineData) {
|
|
48
49
|
const data = artifact.inlineData.data || "";
|
|
49
50
|
await fs.writeFile(contentPath, Buffer.from(data, "base64"));
|
|
50
51
|
mimeType = artifact.inlineData.mimeType || "application/octet-stream";
|
|
51
52
|
} else if (artifact.text !== void 0) {
|
|
52
53
|
await fs.writeFile(contentPath, artifact.text, "utf-8");
|
|
54
|
+
} else {
|
|
55
|
+
fileUri = artifact.fileData.fileUri;
|
|
56
|
+
if (!fileUri) {
|
|
57
|
+
throw new Error("Artifact fileData must have a fileUri.");
|
|
58
|
+
}
|
|
59
|
+
mimeType = artifact.fileData.mimeType;
|
|
53
60
|
}
|
|
54
61
|
const canonicalUri = await getCanonicalUri(
|
|
55
62
|
this.rootDir,
|
|
@@ -61,6 +68,7 @@ class FileArtifactService {
|
|
|
61
68
|
const metadata = {
|
|
62
69
|
fileName: filename,
|
|
63
70
|
mimeType,
|
|
71
|
+
fileUri,
|
|
64
72
|
version: nextVersion,
|
|
65
73
|
canonicalUri,
|
|
66
74
|
customMetadata
|
|
@@ -112,6 +120,11 @@ class FileArtifactService {
|
|
|
112
120
|
);
|
|
113
121
|
const metadataPath = path.join(versionDir, "metadata.json");
|
|
114
122
|
const metadata = await readMetadata(metadataPath);
|
|
123
|
+
if (metadata.fileUri) {
|
|
124
|
+
return {
|
|
125
|
+
fileData: { fileUri: metadata.fileUri, mimeType: metadata.mimeType }
|
|
126
|
+
};
|
|
127
|
+
}
|
|
115
128
|
const storedFilename = path.basename(artifactDir);
|
|
116
129
|
let contentPath = path.join(versionDir, storedFilename);
|
|
117
130
|
if (metadata.canonicalUri) {
|
|
@@ -8,12 +8,16 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
8
8
|
import { Storage } from "@google-cloud/storage";
|
|
9
9
|
import { createPartFromBase64, createPartFromText } from "@google/genai";
|
|
10
10
|
import { logger } from "../utils/logger.js";
|
|
11
|
+
const GCS_FILE_URI_METADATA_KEY = "adkFileUri";
|
|
12
|
+
const GCS_FILE_MIME_TYPE_METADATA_KEY = "adkFileMimeType";
|
|
13
|
+
const GCS_DISPLAY_NAME_METADATA_KEY = "adkDisplayName";
|
|
14
|
+
const GCS_IS_TEXT_METADATA_KEY = "adkIsText";
|
|
11
15
|
class GcsArtifactService {
|
|
12
|
-
constructor(bucket) {
|
|
13
|
-
this.bucket = new Storage().bucket(bucket);
|
|
16
|
+
constructor(bucket, options) {
|
|
17
|
+
this.bucket = new Storage(options).bucket(bucket);
|
|
14
18
|
}
|
|
15
19
|
async saveArtifact(request) {
|
|
16
|
-
if (!request.artifact.inlineData && !request.artifact.text) {
|
|
20
|
+
if (!request.artifact.inlineData && !request.artifact.text && !request.artifact.fileData) {
|
|
17
21
|
throw new Error("Artifact must have either inlineData or text content.");
|
|
18
22
|
}
|
|
19
23
|
const versions = await this.listVersions(request);
|
|
@@ -24,24 +28,48 @@ class GcsArtifactService {
|
|
|
24
28
|
version
|
|
25
29
|
})
|
|
26
30
|
);
|
|
27
|
-
const
|
|
31
|
+
const customMetadata = {
|
|
32
|
+
...request.customMetadata
|
|
33
|
+
};
|
|
28
34
|
if (request.artifact.inlineData) {
|
|
35
|
+
if (request.artifact.inlineData.displayName) {
|
|
36
|
+
customMetadata[GCS_DISPLAY_NAME_METADATA_KEY] = request.artifact.inlineData.displayName;
|
|
37
|
+
}
|
|
29
38
|
await file.save(
|
|
30
39
|
Buffer.from(request.artifact.inlineData.data || "", "base64"),
|
|
31
40
|
{
|
|
32
41
|
contentType: request.artifact.inlineData.mimeType,
|
|
33
|
-
metadata
|
|
42
|
+
metadata: { metadata: customMetadata }
|
|
34
43
|
}
|
|
35
44
|
);
|
|
36
45
|
return version;
|
|
46
|
+
} else if (request.artifact.text !== void 0) {
|
|
47
|
+
await file.save(request.artifact.text, {
|
|
48
|
+
contentType: "text/plain",
|
|
49
|
+
metadata: {
|
|
50
|
+
metadata: { ...customMetadata, [GCS_IS_TEXT_METADATA_KEY]: "true" }
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return version;
|
|
54
|
+
} else {
|
|
55
|
+
const fileData = request.artifact.fileData;
|
|
56
|
+
const fileUri = fileData == null ? void 0 : fileData.fileUri;
|
|
57
|
+
if (!fileUri) {
|
|
58
|
+
throw new Error("Artifact fileData must have a fileUri.");
|
|
59
|
+
}
|
|
60
|
+
customMetadata[GCS_FILE_URI_METADATA_KEY] = fileUri;
|
|
61
|
+
if (fileData.mimeType) {
|
|
62
|
+
customMetadata[GCS_FILE_MIME_TYPE_METADATA_KEY] = fileData.mimeType;
|
|
63
|
+
}
|
|
64
|
+
await file.save("", {
|
|
65
|
+
contentType: fileData.mimeType || void 0,
|
|
66
|
+
metadata: { metadata: customMetadata }
|
|
67
|
+
});
|
|
68
|
+
return version;
|
|
37
69
|
}
|
|
38
|
-
await file.save(request.artifact.text, {
|
|
39
|
-
contentType: "text/plain",
|
|
40
|
-
metadata
|
|
41
|
-
});
|
|
42
|
-
return version;
|
|
43
70
|
}
|
|
44
71
|
async loadArtifact(request) {
|
|
72
|
+
var _a, _b, _c;
|
|
45
73
|
try {
|
|
46
74
|
let version = request.version;
|
|
47
75
|
if (version === void 0) {
|
|
@@ -57,11 +85,25 @@ class GcsArtifactService {
|
|
|
57
85
|
version
|
|
58
86
|
})
|
|
59
87
|
);
|
|
60
|
-
const [
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
88
|
+
const [metadata] = await file.getMetadata();
|
|
89
|
+
const customMeta = (_a = metadata.metadata) != null ? _a : {};
|
|
90
|
+
const fileUri = customMeta[GCS_FILE_URI_METADATA_KEY];
|
|
91
|
+
if (fileUri) {
|
|
92
|
+
const mimeType = (_c = (_b = customMeta[GCS_FILE_MIME_TYPE_METADATA_KEY]) != null ? _b : metadata.contentType) != null ? _c : void 0;
|
|
93
|
+
return { fileData: { fileUri, mimeType } };
|
|
94
|
+
}
|
|
95
|
+
const [rawDataBuffer] = await file.download();
|
|
96
|
+
const displayName = customMeta[GCS_DISPLAY_NAME_METADATA_KEY];
|
|
97
|
+
if (displayName) {
|
|
98
|
+
return {
|
|
99
|
+
inlineData: {
|
|
100
|
+
data: rawDataBuffer.toString("base64"),
|
|
101
|
+
mimeType: metadata.contentType,
|
|
102
|
+
displayName
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (customMeta[GCS_IS_TEXT_METADATA_KEY] === "true" || metadata.contentType === "text/plain") {
|
|
65
107
|
return createPartFromText(rawDataBuffer.toString("utf-8"));
|
|
66
108
|
}
|
|
67
109
|
return createPartFromBase64(
|
|
@@ -5,6 +5,7 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
5
5
|
* Copyright 2025 Google LLC
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
|
+
import { logger } from "../utils/logger.js";
|
|
8
9
|
function isInMemoryConnectionString(uri) {
|
|
9
10
|
return uri === "memory://";
|
|
10
11
|
}
|
|
@@ -20,7 +21,7 @@ class InMemoryArtifactService {
|
|
|
20
21
|
artifact,
|
|
21
22
|
customMetadata
|
|
22
23
|
}) {
|
|
23
|
-
if (!artifact.inlineData && !artifact.text) {
|
|
24
|
+
if (!artifact.inlineData && !artifact.text && !artifact.fileData) {
|
|
24
25
|
return Promise.reject(
|
|
25
26
|
new Error("Artifact must have either inlineData or text content.")
|
|
26
27
|
);
|
|
@@ -34,6 +35,10 @@ class InMemoryArtifactService {
|
|
|
34
35
|
version,
|
|
35
36
|
customMetadata
|
|
36
37
|
};
|
|
38
|
+
if (!artifact.inlineData && artifact.text === void 0) {
|
|
39
|
+
const fileData = artifact.fileData;
|
|
40
|
+
metadata.mimeType = fileData.mimeType;
|
|
41
|
+
}
|
|
37
42
|
this.artifacts[path].push({ part: artifact, metadata });
|
|
38
43
|
return Promise.resolve(version);
|
|
39
44
|
}
|
|
@@ -52,6 +57,12 @@ class InMemoryArtifactService {
|
|
|
52
57
|
if (version === void 0) {
|
|
53
58
|
version = versions.length - 1;
|
|
54
59
|
}
|
|
60
|
+
if (!versions[version]) {
|
|
61
|
+
logger.warn(
|
|
62
|
+
`[InMemoryArtifactService] loadArtifact: Artifact ${filename} version ${version} not found`
|
|
63
|
+
);
|
|
64
|
+
return Promise.resolve(void 0);
|
|
65
|
+
}
|
|
55
66
|
return Promise.resolve(versions[version].part);
|
|
56
67
|
}
|
|
57
68
|
listArtifactKeys({
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
class ScopedArtifactService {
|
|
9
|
+
constructor(delegate, appName, userId, sessionId) {
|
|
10
|
+
this.delegate = delegate;
|
|
11
|
+
this.appName = appName;
|
|
12
|
+
this.userId = userId;
|
|
13
|
+
this.sessionId = sessionId;
|
|
14
|
+
}
|
|
15
|
+
async saveArtifact(request) {
|
|
16
|
+
return this.delegate.saveArtifact({
|
|
17
|
+
appName: this.appName,
|
|
18
|
+
userId: this.userId,
|
|
19
|
+
sessionId: this.sessionId,
|
|
20
|
+
...request
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
async loadArtifact(request) {
|
|
24
|
+
return this.delegate.loadArtifact({
|
|
25
|
+
appName: this.appName,
|
|
26
|
+
userId: this.userId,
|
|
27
|
+
sessionId: this.sessionId,
|
|
28
|
+
...request
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async listArtifactKeys() {
|
|
32
|
+
return this.delegate.listArtifactKeys({
|
|
33
|
+
appName: this.appName,
|
|
34
|
+
userId: this.userId,
|
|
35
|
+
sessionId: this.sessionId
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async deleteArtifact(filename) {
|
|
39
|
+
return this.delegate.deleteArtifact({
|
|
40
|
+
appName: this.appName,
|
|
41
|
+
userId: this.userId,
|
|
42
|
+
sessionId: this.sessionId,
|
|
43
|
+
filename
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async listVersions(filename) {
|
|
47
|
+
return this.delegate.listVersions({
|
|
48
|
+
appName: this.appName,
|
|
49
|
+
userId: this.userId,
|
|
50
|
+
sessionId: this.sessionId,
|
|
51
|
+
filename
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async listArtifactVersions(filename) {
|
|
55
|
+
return this.delegate.listArtifactVersions({
|
|
56
|
+
appName: this.appName,
|
|
57
|
+
userId: this.userId,
|
|
58
|
+
sessionId: this.sessionId,
|
|
59
|
+
filename
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async getArtifactVersion(request) {
|
|
63
|
+
return this.delegate.getArtifactVersion({
|
|
64
|
+
appName: this.appName,
|
|
65
|
+
userId: this.userId,
|
|
66
|
+
sessionId: this.sessionId,
|
|
67
|
+
...request
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
ScopedArtifactService
|
|
73
|
+
};
|
|
@@ -55,7 +55,11 @@ class OAuth2DiscoveryManager {
|
|
|
55
55
|
method: "GET",
|
|
56
56
|
headers: {
|
|
57
57
|
Accept: "application/json"
|
|
58
|
-
}
|
|
58
|
+
},
|
|
59
|
+
// Never follow redirects: validateDiscoveryUrl only checks the
|
|
60
|
+
// initial URL, so following a 3xx would let a validated host
|
|
61
|
+
// redirect discovery to a private/cloud-metadata address (CWE-918).
|
|
62
|
+
redirect: "error"
|
|
59
63
|
});
|
|
60
64
|
if (!response.ok) {
|
|
61
65
|
continue;
|
|
@@ -103,7 +107,11 @@ class OAuth2DiscoveryManager {
|
|
|
103
107
|
method: "GET",
|
|
104
108
|
headers: {
|
|
105
109
|
Accept: "application/json"
|
|
106
|
-
}
|
|
110
|
+
},
|
|
111
|
+
// Never follow redirects: validateDiscoveryUrl only checks the
|
|
112
|
+
// initial URL, so following a 3xx would let a validated host
|
|
113
|
+
// redirect discovery to a private/cloud-metadata address (CWE-918).
|
|
114
|
+
redirect: "error"
|
|
107
115
|
});
|
|
108
116
|
if (!response.ok) {
|
|
109
117
|
return void 0;
|
|
@@ -143,7 +151,7 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
143
151
|
return false;
|
|
144
152
|
}
|
|
145
153
|
const host = normaliseHostname(url.hostname.toLowerCase());
|
|
146
|
-
if (host === "localhost" || host === "metadata.google.internal" || host === "metadata.goog" || host.startsWith("127.") || host === "[::1]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
|
|
154
|
+
if (host === "localhost" || host === "metadata.google.internal" || host === "metadata.goog" || host.startsWith("127.") || host === "[::1]" || host === "[::]" || host === "0.0.0.0" || host.startsWith("10.") || host.startsWith("192.168.") || host.startsWith("169.254.")) {
|
|
147
155
|
logger.warn(`Unsafe host for discovery URL: ${host}`);
|
|
148
156
|
return false;
|
|
149
157
|
}
|
|
@@ -176,5 +184,7 @@ function validateDiscoveryUrl(urlStr) {
|
|
|
176
184
|
export {
|
|
177
185
|
AuthorizationServerMetadataSchema,
|
|
178
186
|
OAuth2DiscoveryManager,
|
|
179
|
-
ProtectedResourceMetadataSchema
|
|
187
|
+
ProtectedResourceMetadataSchema,
|
|
188
|
+
normaliseHostname,
|
|
189
|
+
validateDiscoveryUrl
|
|
180
190
|
};
|
|
@@ -6,6 +6,7 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
6
6
|
* SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
*/
|
|
8
8
|
import { logger } from "../../utils/logger.js";
|
|
9
|
+
import { validateDiscoveryUrl } from "./oauth2_discovery.js";
|
|
9
10
|
function getTokenEndpoint(authScheme) {
|
|
10
11
|
if (authScheme.type === "openIdConnect" && authScheme.tokenEndpoint) {
|
|
11
12
|
return authScheme.tokenEndpoint;
|
|
@@ -20,13 +21,23 @@ function getTokenEndpoint(authScheme) {
|
|
|
20
21
|
return void 0;
|
|
21
22
|
}
|
|
22
23
|
async function fetchOAuth2Tokens(endpoint, body) {
|
|
24
|
+
if (!validateDiscoveryUrl(endpoint)) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`SSRF protection: OAuth2 token endpoint '${endpoint}' is not allowed. Must use HTTPS and must not target private/loopback/cloud-metadata addresses.`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
23
29
|
try {
|
|
24
30
|
const response = await fetch(endpoint, {
|
|
25
31
|
method: "POST",
|
|
26
32
|
headers: {
|
|
27
33
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
28
34
|
},
|
|
29
|
-
body: body.toString()
|
|
35
|
+
body: body.toString(),
|
|
36
|
+
// Never follow redirects: the SSRF blocklist only validates `endpoint`,
|
|
37
|
+
// so a validated host that responds with a 3xx could otherwise redirect
|
|
38
|
+
// this credential-bearing POST (client_secret/refresh_token) to a
|
|
39
|
+
// private/cloud-metadata address (CWE-918).
|
|
40
|
+
redirect: "error"
|
|
30
41
|
});
|
|
31
42
|
if (!response.ok) {
|
|
32
43
|
throw new Error(`Token request failed with status ${response.status}`);
|
package/dist/esm/common.js
CHANGED
|
@@ -8,7 +8,11 @@ const require = topLevelCreateRequire(import.meta.url);
|
|
|
8
8
|
import { ActiveStreamingTool } from "./agents/active_streaming_tool.js";
|
|
9
9
|
import { BaseAgent, isBaseAgent } from "./agents/base_agent.js";
|
|
10
10
|
import { Context } from "./agents/context.js";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
findEventByFunctionCallId,
|
|
13
|
+
findMatchingFunctionCall,
|
|
14
|
+
functionsExportedForTestingOnly
|
|
15
|
+
} from "./agents/functions.js";
|
|
12
16
|
import { InvocationContext } from "./agents/invocation_context.js";
|
|
13
17
|
import { LiveRequestQueue } from "./agents/live_request_queue.js";
|
|
14
18
|
import { LlmAgent, LlmAgent as LlmAgent2, isLlmAgent } from "./agents/llm_agent.js";
|
|
@@ -24,10 +28,15 @@ import {
|
|
|
24
28
|
ContentRequestProcessor
|
|
25
29
|
} from "./agents/processors/content_request_processor.js";
|
|
26
30
|
import { ContextCompactorRequestProcessor } from "./agents/processors/context_compactor_request_processor.js";
|
|
31
|
+
import {
|
|
32
|
+
INTERACTIONS_REQUEST_PROCESSOR,
|
|
33
|
+
InteractionsRequestProcessor
|
|
34
|
+
} from "./agents/processors/interactions_request_processor.js";
|
|
27
35
|
import { ReadonlyContext } from "./agents/readonly_context.js";
|
|
28
36
|
import { RoutedAgent, isRoutedAgent } from "./agents/routed_agent.js";
|
|
29
37
|
import { StreamingMode } from "./agents/run_config.js";
|
|
30
38
|
import { SequentialAgent, isSequentialAgent } from "./agents/sequential_agent.js";
|
|
39
|
+
import { createResumabilityConfig } from "./apps/resumability_config.js";
|
|
31
40
|
import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.js";
|
|
32
41
|
import { AuthCredentialTypes } from "./auth/auth_credential.js";
|
|
33
42
|
import { AuthHandler } from "./auth/auth_handler.js";
|
|
@@ -46,16 +55,23 @@ import {
|
|
|
46
55
|
CodeExecutionLanguage,
|
|
47
56
|
FileContentEncoding
|
|
48
57
|
} from "./code_executors/code_execution_utils.js";
|
|
58
|
+
import { AgentControlledContextCompactor } from "./context/agent_controlled_context_compactor.js";
|
|
59
|
+
import { AnchoredContextCompactor } from "./context/anchored_context_compactor.js";
|
|
49
60
|
import { LlmSummarizer } from "./context/summarizers/llm_summarizer.js";
|
|
50
61
|
import { TokenBasedContextCompactor } from "./context/token_based_context_compactor.js";
|
|
62
|
+
import { TrajectoryThoughtPruningCompactor } from "./context/trajectory_thought_pruning_compactor.js";
|
|
51
63
|
import { TruncatingContextCompactor } from "./context/truncating_context_compactor.js";
|
|
52
|
-
import { isCompactedEvent } from "./events/compacted_event.js";
|
|
64
|
+
import { isCompactedEvent, isScratchpadEvent } from "./events/compacted_event.js";
|
|
53
65
|
import {
|
|
54
66
|
createEvent,
|
|
67
|
+
generateClientFunctionCallId,
|
|
55
68
|
getFunctionCalls,
|
|
56
69
|
getFunctionResponses,
|
|
70
|
+
hasThoughts,
|
|
57
71
|
hasTrailingCodeExecutionResult,
|
|
58
72
|
isFinalResponse,
|
|
73
|
+
populateClientFunctionCallId,
|
|
74
|
+
pruneThoughts,
|
|
59
75
|
stringifyContent
|
|
60
76
|
} from "./events/event.js";
|
|
61
77
|
import { createEventActions } from "./events/event_actions.js";
|
|
@@ -72,6 +88,7 @@ import { Gemini, geminiInitParams } from "./models/google_llm.js";
|
|
|
72
88
|
import { LLMRegistry } from "./models/registry.js";
|
|
73
89
|
import { RoutedLlm } from "./models/routed_llm.js";
|
|
74
90
|
import { BasePlugin, ContextCompactionTrigger } from "./plugins/base_plugin.js";
|
|
91
|
+
import { GlobalInstructionPlugin } from "./plugins/global_instruction_plugin.js";
|
|
75
92
|
import { LoggingPlugin } from "./plugins/logging_plugin.js";
|
|
76
93
|
import { PluginManager } from "./plugins/plugin_manager.js";
|
|
77
94
|
import {
|
|
@@ -82,7 +99,13 @@ import {
|
|
|
82
99
|
getAskUserConfirmationFunctionCalls
|
|
83
100
|
} from "./plugins/security_plugin.js";
|
|
84
101
|
import { InMemoryRunner } from "./runner/in_memory_runner.js";
|
|
85
|
-
import {
|
|
102
|
+
import {
|
|
103
|
+
Runner,
|
|
104
|
+
determineAgentForResumption,
|
|
105
|
+
findEventByLastFunctionResponseId,
|
|
106
|
+
isRoutableLlmAgent,
|
|
107
|
+
isRunner
|
|
108
|
+
} from "./runner/runner.js";
|
|
86
109
|
import { BaseSessionService } from "./sessions/base_session_service.js";
|
|
87
110
|
import { InMemorySessionService } from "./sessions/in_memory_session_service.js";
|
|
88
111
|
import { createSession } from "./sessions/session.js";
|
|
@@ -90,6 +113,12 @@ import { State } from "./sessions/state.js";
|
|
|
90
113
|
import { AgentTool, isAgentTool } from "./tools/agent_tool.js";
|
|
91
114
|
import { BaseTool, isBaseTool } from "./tools/base_tool.js";
|
|
92
115
|
import { BaseToolset, isBaseToolset } from "./tools/base_toolset.js";
|
|
116
|
+
import { ConsolidateContextTool } from "./tools/consolidate_context_tool.js";
|
|
117
|
+
import {
|
|
118
|
+
ENTERPRISE_WEB_SEARCH,
|
|
119
|
+
EnterpriseWebSearchTool
|
|
120
|
+
} from "./tools/enterprise_web_search_tool.js";
|
|
121
|
+
import { ExampleTool } from "./tools/example_tool.js";
|
|
93
122
|
import { EXIT_LOOP, ExitLoopTool } from "./tools/exit_loop_tool.js";
|
|
94
123
|
import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
|
|
95
124
|
import {
|
|
@@ -102,6 +131,7 @@ import {
|
|
|
102
131
|
LoadArtifactsTool
|
|
103
132
|
} from "./tools/load_artifacts_tool.js";
|
|
104
133
|
import { LOAD_MEMORY, LoadMemoryTool } from "./tools/load_memory_tool.js";
|
|
134
|
+
import { LOAD_WEB_PAGE, loadWebPage } from "./tools/load_web_page.js";
|
|
105
135
|
import { LongRunningFunctionTool } from "./tools/long_running_tool.js";
|
|
106
136
|
import {
|
|
107
137
|
PRELOAD_MEMORY,
|
|
@@ -111,9 +141,11 @@ import { ToolConfirmation } from "./tools/tool_confirmation.js";
|
|
|
111
141
|
import { URL_CONTEXT, UrlContextTool } from "./tools/url_context_tool.js";
|
|
112
142
|
import { VertexAiSearchTool } from "./tools/vertex_ai_search_tool.js";
|
|
113
143
|
import { VertexRagRetrievalTool } from "./tools/vertex_rag_retrieval_tool.js";
|
|
144
|
+
import { getClientLabels, runWithClientLabel } from "./utils/client_labels.js";
|
|
114
145
|
import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
|
|
115
146
|
import { isGemini2OrAbove, isGemini3xFlashLive } from "./utils/model_name.js";
|
|
116
147
|
import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
|
|
148
|
+
import { Task } from "./utils/task.js";
|
|
117
149
|
import { GoogleLLMVariant } from "./utils/variant_utils.js";
|
|
118
150
|
import { version } from "./version.js";
|
|
119
151
|
import { GCPSkillRegistry } from "./skills/gcp_skill_registry.js";
|
|
@@ -128,6 +160,11 @@ import { LoadSkillResourceTool } from "./tools/skill/load_skill_resource_tool.js
|
|
|
128
160
|
import { LoadSkillTool } from "./tools/skill/load_skill_tool.js";
|
|
129
161
|
import { SearchSkillsTool } from "./tools/skill/search_skills_tool.js";
|
|
130
162
|
import { SkillToolset } from "./tools/skill/skill_toolset.js";
|
|
163
|
+
export * from "./artifacts/base_artifact_service.js";
|
|
164
|
+
export * from "./features/feature_registry.js";
|
|
165
|
+
export * from "./memory/base_memory_service.js";
|
|
166
|
+
export * from "./sessions/base_session_service.js";
|
|
167
|
+
export * from "./tools/base_tool.js";
|
|
131
168
|
import { OpenApiSpecParser } from "./tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js";
|
|
132
169
|
import { OperationParser } from "./tools/openapi_tool/openapi_spec_parser/operation_parser.js";
|
|
133
170
|
import { ToolAuthHandler } from "./tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js";
|
|
@@ -136,6 +173,7 @@ import {
|
|
|
136
173
|
RestApiTool,
|
|
137
174
|
createRestApiTool
|
|
138
175
|
} from "./tools/openapi_tool/rest_api_tool.js";
|
|
176
|
+
export * from "./apps/app.js";
|
|
139
177
|
export * from "./artifacts/base_artifact_service.js";
|
|
140
178
|
export * from "./features/feature_registry.js";
|
|
141
179
|
export * from "./memory/base_memory_service.js";
|
|
@@ -145,8 +183,10 @@ export {
|
|
|
145
183
|
AUTH_PREPROCESSOR,
|
|
146
184
|
ActiveStreamingTool,
|
|
147
185
|
LlmAgent as Agent,
|
|
186
|
+
AgentControlledContextCompactor,
|
|
148
187
|
AgentTool,
|
|
149
188
|
AgentTransferLlmRequestProcessor,
|
|
189
|
+
AnchoredContextCompactor,
|
|
150
190
|
ApigeeLlm,
|
|
151
191
|
AuthCredentialTypes,
|
|
152
192
|
AuthHandler,
|
|
@@ -165,14 +205,18 @@ export {
|
|
|
165
205
|
BuiltInCodeExecutor,
|
|
166
206
|
CONTENT_REQUEST_PROCESSOR,
|
|
167
207
|
CodeExecutionLanguage,
|
|
208
|
+
ConsolidateContextTool,
|
|
168
209
|
ContentRequestProcessor,
|
|
169
210
|
Context,
|
|
170
211
|
ContextCompactionTrigger,
|
|
171
212
|
ContextCompactorRequestProcessor,
|
|
172
213
|
CredentialExchangeError,
|
|
173
214
|
CredentialRefresherRegistry,
|
|
215
|
+
ENTERPRISE_WEB_SEARCH,
|
|
174
216
|
EXIT_LOOP,
|
|
217
|
+
EnterpriseWebSearchTool,
|
|
175
218
|
EventType,
|
|
219
|
+
ExampleTool,
|
|
176
220
|
ExitLoopTool,
|
|
177
221
|
FileContentEncoding,
|
|
178
222
|
FunctionTool,
|
|
@@ -180,19 +224,23 @@ export {
|
|
|
180
224
|
GOOGLE_MAPS_GROUNDING,
|
|
181
225
|
GOOGLE_SEARCH,
|
|
182
226
|
Gemini,
|
|
227
|
+
GlobalInstructionPlugin,
|
|
183
228
|
GoogleLLMVariant,
|
|
184
229
|
GoogleMapsGroundingTool,
|
|
185
230
|
GoogleSearchTool,
|
|
231
|
+
INTERACTIONS_REQUEST_PROCESSOR,
|
|
186
232
|
InMemoryArtifactService,
|
|
187
233
|
InMemoryCredentialService,
|
|
188
234
|
InMemoryMemoryService,
|
|
189
235
|
InMemoryPolicyEngine,
|
|
190
236
|
InMemoryRunner,
|
|
191
237
|
InMemorySessionService,
|
|
238
|
+
InteractionsRequestProcessor,
|
|
192
239
|
InvocationContext,
|
|
193
240
|
LLMRegistry,
|
|
194
241
|
LOAD_ARTIFACTS,
|
|
195
242
|
LOAD_MEMORY,
|
|
243
|
+
LOAD_WEB_PAGE,
|
|
196
244
|
ListSkillsTool,
|
|
197
245
|
LiveRequestQueue,
|
|
198
246
|
LlmAgent2 as LlmAgent,
|
|
@@ -229,9 +277,11 @@ export {
|
|
|
229
277
|
SkillToolset,
|
|
230
278
|
State,
|
|
231
279
|
StreamingMode,
|
|
280
|
+
Task,
|
|
232
281
|
TokenBasedContextCompactor,
|
|
233
282
|
ToolAuthHandler,
|
|
234
283
|
ToolConfirmation,
|
|
284
|
+
TrajectoryThoughtPruningCompactor,
|
|
235
285
|
TruncatingContextCompactor,
|
|
236
286
|
URL_CONTEXT,
|
|
237
287
|
UrlContextTool,
|
|
@@ -241,13 +291,21 @@ export {
|
|
|
241
291
|
createEvent,
|
|
242
292
|
createEventActions,
|
|
243
293
|
createRestApiTool,
|
|
294
|
+
createResumabilityConfig,
|
|
244
295
|
createSession,
|
|
296
|
+
determineAgentForResumption,
|
|
297
|
+
findEventByFunctionCallId,
|
|
298
|
+
findEventByLastFunctionResponseId,
|
|
299
|
+
findMatchingFunctionCall,
|
|
245
300
|
functionsExportedForTestingOnly,
|
|
246
301
|
geminiInitParams,
|
|
302
|
+
generateClientFunctionCallId,
|
|
247
303
|
getAskUserConfirmationFunctionCalls,
|
|
304
|
+
getClientLabels,
|
|
248
305
|
getFunctionCalls,
|
|
249
306
|
getFunctionResponses,
|
|
250
307
|
getLogger,
|
|
308
|
+
hasThoughts,
|
|
251
309
|
hasTrailingCodeExecutionResult,
|
|
252
310
|
isAgentTool,
|
|
253
311
|
isBaseAgent,
|
|
@@ -263,12 +321,18 @@ export {
|
|
|
263
321
|
isLlmAgent,
|
|
264
322
|
isLoopAgent,
|
|
265
323
|
isParallelAgent,
|
|
324
|
+
isRoutableLlmAgent,
|
|
266
325
|
isRoutedAgent,
|
|
267
326
|
isRunner,
|
|
327
|
+
isScratchpadEvent,
|
|
268
328
|
isSequentialAgent,
|
|
269
329
|
loadAllSkillsInDir,
|
|
270
330
|
loadSkillFromDir,
|
|
271
331
|
loadSkillFromZipBuffer,
|
|
332
|
+
loadWebPage,
|
|
333
|
+
populateClientFunctionCallId,
|
|
334
|
+
pruneThoughts,
|
|
335
|
+
runWithClientLabel,
|
|
272
336
|
setLogLevel,
|
|
273
337
|
setLogger,
|
|
274
338
|
stringifyContent,
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { isCompactedEvent } from "../events/compacted_event.js";
|
|
9
|
+
import { createEvent } from "../events/event.js";
|
|
10
|
+
import { ContextCompactionTrigger } from "../plugins/base_plugin.js";
|
|
11
|
+
class AgentControlledContextCompactor {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.trigger = ContextCompactionTrigger.AgentControlled;
|
|
14
|
+
this.summarizer = options.summarizer;
|
|
15
|
+
}
|
|
16
|
+
shouldCompact(invocationContext) {
|
|
17
|
+
return invocationContext.session.state["temp:consolidate_context"] === true;
|
|
18
|
+
}
|
|
19
|
+
async compact(invocationContext) {
|
|
20
|
+
const events = invocationContext.session.events;
|
|
21
|
+
const activeEvents = this.getActiveEvents(events);
|
|
22
|
+
const consolidateToolCallIndex = activeEvents.reduce(
|
|
23
|
+
(acc, e, idx) => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
return ((_b = (_a = e.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.some(
|
|
26
|
+
(p) => {
|
|
27
|
+
var _a2;
|
|
28
|
+
return ((_a2 = p.functionCall) == null ? void 0 : _a2.name) === "consolidate_context";
|
|
29
|
+
}
|
|
30
|
+
)) ? idx : acc;
|
|
31
|
+
},
|
|
32
|
+
-1
|
|
33
|
+
);
|
|
34
|
+
if (consolidateToolCallIndex <= 0) {
|
|
35
|
+
this.clearFlags(invocationContext);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const eventsToCompact = activeEvents.slice(0, consolidateToolCallIndex);
|
|
39
|
+
const detail = invocationContext.session.state["temp:consolidate_context_detail"];
|
|
40
|
+
if (detail) {
|
|
41
|
+
eventsToCompact.push(
|
|
42
|
+
createEvent({
|
|
43
|
+
author: "system",
|
|
44
|
+
timestamp: eventsToCompact[eventsToCompact.length - 1].timestamp,
|
|
45
|
+
content: {
|
|
46
|
+
role: "user",
|
|
47
|
+
parts: [
|
|
48
|
+
{
|
|
49
|
+
text: `CRITICAL INSTRUCTION FOR SUMMARY: Please summarize the history. Focus especially on: ${detail}`
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const compactedEvent = await this.summarizer.summarize(eventsToCompact);
|
|
58
|
+
invocationContext.session.events.push(compactedEvent);
|
|
59
|
+
} catch (error) {
|
|
60
|
+
console.error("Compaction failed:", error);
|
|
61
|
+
} finally {
|
|
62
|
+
this.clearFlags(invocationContext);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
clearFlags(invocationContext) {
|
|
66
|
+
delete invocationContext.session.state["temp:consolidate_context"];
|
|
67
|
+
delete invocationContext.session.state["temp:consolidate_context_detail"];
|
|
68
|
+
}
|
|
69
|
+
getActiveEvents(events) {
|
|
70
|
+
const latest = events.filter(isCompactedEvent).pop();
|
|
71
|
+
return latest ? [
|
|
72
|
+
latest,
|
|
73
|
+
...events.filter(
|
|
74
|
+
(e) => !isCompactedEvent(e) && e.timestamp > latest.endTime
|
|
75
|
+
)
|
|
76
|
+
] : events;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export {
|
|
80
|
+
AgentControlledContextCompactor
|
|
81
|
+
};
|