@google/adk 0.3.0 → 0.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/a2a_event.js +290 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +125 -0
- package/dist/cjs/a2a/part_converter_utils.js +212 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +6 -6
- package/dist/cjs/agents/content_processor_utils.js +1 -1
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +71 -16
- package/dist/cjs/agents/functions.js +4 -3
- package/dist/cjs/agents/instructions.js +1 -1
- package/dist/cjs/agents/invocation_context.js +1 -1
- package/dist/cjs/agents/live_request_queue.js +1 -1
- package/dist/cjs/agents/llm_agent.js +76 -711
- package/dist/cjs/agents/loop_agent.js +1 -1
- package/dist/cjs/agents/parallel_agent.js +1 -1
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +1 -1
- 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/processors/content_request_processor.js +66 -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/agents/readonly_context.js +13 -1
- package/dist/cjs/agents/run_config.js +2 -1
- package/dist/cjs/agents/sequential_agent.js +1 -1
- package/dist/cjs/agents/transcription_entry.js +1 -1
- package/dist/cjs/artifacts/base_artifact_service.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +491 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +127 -48
- package/dist/cjs/artifacts/in_memory_artifact_service.js +54 -6
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +1 -1
- package/dist/cjs/auth/auth_schemes.js +1 -1
- package/dist/cjs/auth/auth_tool.js +1 -1
- package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
- package/dist/cjs/code_executors/base_code_executor.js +1 -1
- package/dist/cjs/code_executors/built_in_code_executor.js +1 -1
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +1 -1
- package/dist/cjs/common.js +25 -8
- package/dist/cjs/events/event.js +33 -4
- package/dist/cjs/events/event_actions.js +2 -2
- package/dist/cjs/events/structured_events.js +105 -0
- package/dist/cjs/examples/base_example_provider.js +1 -1
- package/dist/cjs/examples/example.js +1 -1
- package/dist/cjs/examples/example_util.js +1 -1
- package/dist/cjs/index.js +24 -17
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/index_web.js +1 -1
- package/dist/cjs/memory/base_memory_service.js +1 -1
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/memory/memory_entry.js +1 -1
- package/dist/cjs/models/apigee_llm.js +182 -0
- package/dist/cjs/models/base_llm.js +1 -1
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +1 -1
- package/dist/cjs/models/google_llm.js +70 -51
- package/dist/cjs/models/llm_request.js +1 -1
- package/dist/cjs/models/llm_response.js +3 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +2 -2
- package/dist/cjs/plugins/logging_plugin.js +1 -1
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/security_plugin.js +1 -1
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +33 -2
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +367 -0
- package/dist/cjs/sessions/db/operations.js +126 -0
- package/dist/cjs/sessions/db/schema.js +204 -0
- package/dist/cjs/sessions/in_memory_session_service.js +24 -22
- package/dist/cjs/sessions/registry.js +49 -0
- package/dist/cjs/sessions/session.js +1 -1
- package/dist/cjs/sessions/state.js +1 -1
- package/dist/cjs/telemetry/google_cloud.js +1 -1
- package/dist/cjs/telemetry/setup.js +1 -1
- package/dist/cjs/telemetry/tracing.js +1 -1
- package/dist/cjs/tools/agent_tool.js +1 -1
- package/dist/cjs/tools/base_tool.js +4 -1
- package/dist/cjs/tools/base_toolset.js +14 -4
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +17 -1
- package/dist/cjs/tools/function_tool.js +1 -1
- package/dist/cjs/tools/google_search_tool.js +1 -1
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +1 -1
- package/dist/cjs/tools/mcp/mcp_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -6
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/utils/client_labels.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/gemini_schema_util.js +1 -1
- package/dist/cjs/utils/logger.js +62 -55
- package/dist/cjs/utils/model_name.js +1 -1
- package/dist/cjs/utils/object_notation_utils.js +78 -0
- package/dist/cjs/utils/simple_zod_to_json.js +1 -1
- package/dist/cjs/utils/variant_utils.js +3 -9
- package/dist/cjs/version.js +2 -2
- package/dist/esm/a2a/a2a_event.js +243 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +90 -0
- package/dist/esm/a2a/part_converter_utils.js +175 -0
- package/dist/esm/agents/base_agent.js +5 -5
- package/dist/esm/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +3 -2
- package/dist/esm/agents/llm_agent.js +69 -720
- 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/processors/content_request_processor.js +38 -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/agents/readonly_context.js +12 -0
- package/dist/esm/agents/run_config.js +1 -0
- package/dist/esm/artifacts/file_artifact_service.js +451 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +126 -47
- package/dist/esm/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/common.js +20 -10
- package/dist/esm/events/event.js +29 -2
- package/dist/esm/events/event_actions.js +1 -1
- package/dist/esm/events/structured_events.js +74 -0
- package/dist/esm/index.js +24 -17
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/google_llm.js +67 -49
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +32 -1
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +353 -0
- package/dist/esm/sessions/db/operations.js +111 -0
- package/dist/esm/sessions/db/schema.js +172 -0
- package/dist/esm/sessions/in_memory_session_service.js +23 -21
- package/dist/esm/sessions/registry.js +25 -0
- 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/forwarding_artifact_service.js +16 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/utils/env_aware_utils.js +8 -0
- package/dist/esm/utils/logger.js +51 -54
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/variant_utils.js +1 -7
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +122 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +62 -0
- package/dist/types/a2a/part_converter_utils.d.ts +48 -0
- 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 +19 -42
- 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/processors/content_request_processor.d.ts +13 -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/agents/readonly_context.d.ts +8 -0
- package/dist/types/agents/run_config.d.ts +6 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
- package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +5 -2
- package/dist/types/artifacts/registry.d.ts +7 -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 +15 -6
- package/dist/types/events/event.d.ts +15 -1
- package/dist/types/events/event_actions.d.ts +1 -1
- package/dist/types/events/structured_events.d.ts +106 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/google_llm.d.ts +5 -2
- 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 +15 -0
- package/dist/types/sessions/base_session_service.d.ts +20 -0
- package/dist/types/sessions/database_session_service.d.ts +32 -0
- package/dist/types/sessions/db/operations.d.ts +29 -0
- package/dist/types/sessions/db/schema.d.ts +45 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +4 -1
- package/dist/types/sessions/registry.d.ts +7 -0
- 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 +5 -3
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +243 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +107 -0
- package/dist/web/a2a/part_converter_utils.js +175 -0
- package/dist/web/agents/base_agent.js +5 -5
- package/dist/web/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/web/agents/functions.js +3 -2
- package/dist/web/agents/llm_agent.js +90 -717
- 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/processors/content_request_processor.js +56 -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/agents/readonly_context.js +12 -0
- package/dist/web/agents/run_config.js +2 -1
- package/dist/web/artifacts/file_artifact_service.js +506 -0
- package/dist/web/artifacts/gcs_artifact_service.js +123 -46
- package/dist/web/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/common.js +20 -10
- package/dist/web/events/event.js +29 -2
- package/dist/web/events/event_actions.js +1 -1
- package/dist/web/events/structured_events.js +74 -0
- package/dist/web/index.js +7 -2
- package/dist/web/index.js.map +4 -4
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/google_llm.js +67 -46
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/models/registry.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +34 -1
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +371 -0
- package/dist/web/sessions/db/operations.js +111 -0
- package/dist/web/sessions/db/schema.js +172 -0
- package/dist/web/sessions/in_memory_session_service.js +23 -21
- package/dist/web/sessions/registry.js +25 -0
- 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/forwarding_artifact_service.js +16 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/utils/env_aware_utils.js +8 -0
- package/dist/web/utils/logger.js +51 -54
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +13 -3
- 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/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,212 @@
|
|
|
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 part_converter_utils_exports = {};
|
|
26
|
+
__export(part_converter_utils_exports, {
|
|
27
|
+
toA2ADataPart: () => toA2ADataPart,
|
|
28
|
+
toA2AFilePart: () => toA2AFilePart,
|
|
29
|
+
toA2APart: () => toA2APart,
|
|
30
|
+
toA2AParts: () => toA2AParts,
|
|
31
|
+
toA2ATextPart: () => toA2ATextPart,
|
|
32
|
+
toGenAIContent: () => toGenAIContent,
|
|
33
|
+
toGenAIPart: () => toGenAIPart,
|
|
34
|
+
toGenAIPartData: () => toGenAIPartData,
|
|
35
|
+
toGenAIPartFile: () => toGenAIPartFile,
|
|
36
|
+
toGenAIPartText: () => toGenAIPartText,
|
|
37
|
+
toGenAIParts: () => toGenAIParts
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(part_converter_utils_exports);
|
|
40
|
+
var import_genai = require("@google/genai");
|
|
41
|
+
var import_metadata_converter_utils = require("./metadata_converter_utils.js");
|
|
42
|
+
/**
|
|
43
|
+
* @license
|
|
44
|
+
* Copyright 2026 Google LLC
|
|
45
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
46
|
+
*/
|
|
47
|
+
var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
|
|
48
|
+
DataPartType2["FUNCTION_CALL"] = "function_call";
|
|
49
|
+
DataPartType2["FUNCTION_RESPONSE"] = "function_response";
|
|
50
|
+
DataPartType2["CODE_EXEC_RESULT"] = "code_execution_result";
|
|
51
|
+
DataPartType2["CODE_EXECUTABLE_CODE"] = "executable_code";
|
|
52
|
+
return DataPartType2;
|
|
53
|
+
})(DataPartType || {});
|
|
54
|
+
function toA2AParts(parts = [], longRunningToolIDs = []) {
|
|
55
|
+
return parts.map((part) => toA2APart(part, longRunningToolIDs));
|
|
56
|
+
}
|
|
57
|
+
function toA2APart(part, longRunningToolIDs) {
|
|
58
|
+
if (part.text !== void 0 && part.text !== null) {
|
|
59
|
+
return toA2ATextPart(part);
|
|
60
|
+
}
|
|
61
|
+
if (part.inlineData || part.fileData) {
|
|
62
|
+
return toA2AFilePart(part);
|
|
63
|
+
}
|
|
64
|
+
return toA2ADataPart(part, longRunningToolIDs);
|
|
65
|
+
}
|
|
66
|
+
function toA2ATextPart(part) {
|
|
67
|
+
const a2aPart = { kind: "text", text: part.text || "" };
|
|
68
|
+
if (part.thought) {
|
|
69
|
+
a2aPart.metadata = {
|
|
70
|
+
[import_metadata_converter_utils.A2AMetadataKeys.THOUGHT]: true
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
return a2aPart;
|
|
74
|
+
}
|
|
75
|
+
function toA2AFilePart(part) {
|
|
76
|
+
if (part.fileData) {
|
|
77
|
+
return {
|
|
78
|
+
kind: "file",
|
|
79
|
+
file: {
|
|
80
|
+
uri: part.fileData.fileUri || "",
|
|
81
|
+
mimeType: part.fileData.mimeType
|
|
82
|
+
},
|
|
83
|
+
metadata: {}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
if (part.inlineData) {
|
|
87
|
+
return {
|
|
88
|
+
kind: "file",
|
|
89
|
+
file: {
|
|
90
|
+
bytes: part.inlineData.data || "",
|
|
91
|
+
mimeType: part.inlineData.mimeType
|
|
92
|
+
},
|
|
93
|
+
metadata: {}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
throw new Error(`Not a file part: ${JSON.stringify(part)}`);
|
|
97
|
+
}
|
|
98
|
+
function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
99
|
+
let dataPartType;
|
|
100
|
+
let data;
|
|
101
|
+
if (part.functionCall) {
|
|
102
|
+
dataPartType = "function_call" /* FUNCTION_CALL */;
|
|
103
|
+
data = part.functionCall;
|
|
104
|
+
} else if (part.functionResponse) {
|
|
105
|
+
dataPartType = "function_response" /* FUNCTION_RESPONSE */;
|
|
106
|
+
data = part.functionResponse;
|
|
107
|
+
} else if (part.executableCode) {
|
|
108
|
+
dataPartType = "executable_code" /* CODE_EXECUTABLE_CODE */;
|
|
109
|
+
data = part.executableCode;
|
|
110
|
+
} else if (part.codeExecutionResult) {
|
|
111
|
+
dataPartType = "code_execution_result" /* CODE_EXEC_RESULT */;
|
|
112
|
+
data = part.codeExecutionResult;
|
|
113
|
+
} else {
|
|
114
|
+
throw new Error(`Unknown part type: ${JSON.stringify(part)}`);
|
|
115
|
+
}
|
|
116
|
+
const metadata = {
|
|
117
|
+
[import_metadata_converter_utils.A2AMetadataKeys.DATA_PART_TYPE]: dataPartType
|
|
118
|
+
};
|
|
119
|
+
if (part.functionCall && part.functionCall.id && longRunningToolIDs.includes(part.functionCall.id)) {
|
|
120
|
+
metadata[import_metadata_converter_utils.A2AMetadataKeys.IS_LONG_RUNNING] = true;
|
|
121
|
+
}
|
|
122
|
+
if (part.functionResponse && part.functionResponse.id && longRunningToolIDs.includes(part.functionResponse.id)) {
|
|
123
|
+
metadata[import_metadata_converter_utils.A2AMetadataKeys.IS_LONG_RUNNING] = true;
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
kind: "data",
|
|
127
|
+
data,
|
|
128
|
+
metadata
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function toGenAIContent(a2aMessage) {
|
|
132
|
+
const parts = toGenAIParts(a2aMessage.parts);
|
|
133
|
+
return a2aMessage.role === "user" ? (0, import_genai.createUserContent)(parts) : (0, import_genai.createModelContent)(parts);
|
|
134
|
+
}
|
|
135
|
+
function toGenAIParts(a2aParts) {
|
|
136
|
+
return a2aParts.map((a2aPart) => toGenAIPart(a2aPart));
|
|
137
|
+
}
|
|
138
|
+
function toGenAIPart(a2aPart) {
|
|
139
|
+
if (a2aPart.kind === "text") {
|
|
140
|
+
return toGenAIPartText(a2aPart);
|
|
141
|
+
}
|
|
142
|
+
if (a2aPart.kind === "file") {
|
|
143
|
+
return toGenAIPartFile(a2aPart);
|
|
144
|
+
}
|
|
145
|
+
if (a2aPart.kind === "data") {
|
|
146
|
+
return toGenAIPartData(a2aPart);
|
|
147
|
+
}
|
|
148
|
+
throw new Error(`Unknown part kind: ${JSON.stringify(a2aPart)}`);
|
|
149
|
+
}
|
|
150
|
+
function toGenAIPartText(a2aPart) {
|
|
151
|
+
var _a;
|
|
152
|
+
return {
|
|
153
|
+
text: a2aPart.text,
|
|
154
|
+
thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a[import_metadata_converter_utils.A2AMetadataKeys.THOUGHT])
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function toGenAIPartFile(a2aPart) {
|
|
158
|
+
if ("bytes" in a2aPart.file) {
|
|
159
|
+
return {
|
|
160
|
+
inlineData: {
|
|
161
|
+
data: a2aPart.file.bytes,
|
|
162
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if ("uri" in a2aPart.file) {
|
|
167
|
+
return {
|
|
168
|
+
fileData: {
|
|
169
|
+
fileUri: a2aPart.file.uri,
|
|
170
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
throw new Error(`Not a file part: ${JSON.stringify(a2aPart)}`);
|
|
175
|
+
}
|
|
176
|
+
function toGenAIPartData(a2aPart) {
|
|
177
|
+
var _a;
|
|
178
|
+
if (!a2aPart.data) {
|
|
179
|
+
throw new Error(`No data in part: ${JSON.stringify(a2aPart)}`);
|
|
180
|
+
}
|
|
181
|
+
const data = a2aPart.data;
|
|
182
|
+
const type = (_a = a2aPart.metadata) == null ? void 0 : _a[import_metadata_converter_utils.A2AMetadataKeys.DATA_PART_TYPE];
|
|
183
|
+
if (type === "function_call" /* FUNCTION_CALL */) {
|
|
184
|
+
return { functionCall: data };
|
|
185
|
+
}
|
|
186
|
+
if (type === "function_response" /* FUNCTION_RESPONSE */) {
|
|
187
|
+
return { functionResponse: data };
|
|
188
|
+
}
|
|
189
|
+
if (type === "executable_code" /* CODE_EXECUTABLE_CODE */) {
|
|
190
|
+
return { executableCode: data };
|
|
191
|
+
}
|
|
192
|
+
if (type === "code_execution_result" /* CODE_EXEC_RESULT */) {
|
|
193
|
+
return { codeExecutionResult: data };
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
text: JSON.stringify(a2aPart.data)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
200
|
+
0 && (module.exports = {
|
|
201
|
+
toA2ADataPart,
|
|
202
|
+
toA2AFilePart,
|
|
203
|
+
toA2APart,
|
|
204
|
+
toA2AParts,
|
|
205
|
+
toA2ATextPart,
|
|
206
|
+
toGenAIContent,
|
|
207
|
+
toGenAIPart,
|
|
208
|
+
toGenAIPartData,
|
|
209
|
+
toGenAIPartFile,
|
|
210
|
+
toGenAIPartText,
|
|
211
|
+
toGenAIParts
|
|
212
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -32,7 +32,7 @@ module.exports = __toCommonJS(base_agent_exports);
|
|
|
32
32
|
var import_api = require("@opentelemetry/api");
|
|
33
33
|
var import_event = require("../events/event.js");
|
|
34
34
|
var import_tracing = require("../telemetry/tracing.js");
|
|
35
|
-
var
|
|
35
|
+
var import_context = require("./context.js");
|
|
36
36
|
var import_invocation_context = require("./invocation_context.js");
|
|
37
37
|
/**
|
|
38
38
|
* @license
|
|
@@ -180,7 +180,7 @@ class BaseAgent {
|
|
|
180
180
|
if (this.beforeAgentCallback.length === 0) {
|
|
181
181
|
return void 0;
|
|
182
182
|
}
|
|
183
|
-
const callbackContext = new
|
|
183
|
+
const callbackContext = new import_context.Context({ invocationContext });
|
|
184
184
|
for (const callback of this.beforeAgentCallback) {
|
|
185
185
|
const content = await callback(callbackContext);
|
|
186
186
|
if (content) {
|
|
@@ -215,7 +215,7 @@ class BaseAgent {
|
|
|
215
215
|
if (this.afterAgentCallback.length === 0) {
|
|
216
216
|
return void 0;
|
|
217
217
|
}
|
|
218
|
-
const callbackContext = new
|
|
218
|
+
const callbackContext = new import_context.Context({ invocationContext });
|
|
219
219
|
for (const callback of this.afterAgentCallback) {
|
|
220
220
|
const content = await callback(callbackContext);
|
|
221
221
|
if (content) {
|
|
@@ -252,7 +252,7 @@ class BaseAgent {
|
|
|
252
252
|
function validateAgentName(name) {
|
|
253
253
|
if (!isIdentifier(name)) {
|
|
254
254
|
throw new Error(
|
|
255
|
-
`Found invalid agent name: "${name}". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), and
|
|
255
|
+
`Found invalid agent name: "${name}". Agent name must be a valid identifier. It should start with a letter (a-z, A-Z) or an underscore (_), and can only contain letters, digits (0-9), underscores, and hyphens.`
|
|
256
256
|
);
|
|
257
257
|
}
|
|
258
258
|
if (name === "user") {
|
|
@@ -263,7 +263,7 @@ function validateAgentName(name) {
|
|
|
263
263
|
return name;
|
|
264
264
|
}
|
|
265
265
|
function isIdentifier(str) {
|
|
266
|
-
return /^[\p{ID_Start}$_][\p{ID_Continue}$_]*$/u.test(str);
|
|
266
|
+
return /^[\p{ID_Start}$_][\p{ID_Continue}$_-]*$/u.test(str);
|
|
267
267
|
}
|
|
268
268
|
function getRootAgent(rootAgent) {
|
|
269
269
|
while (rootAgent.parentAgent) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -22,39 +22,94 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
22
22
|
return to;
|
|
23
23
|
};
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
-
var
|
|
26
|
-
__export(
|
|
27
|
-
|
|
25
|
+
var context_exports = {};
|
|
26
|
+
__export(context_exports, {
|
|
27
|
+
Context: () => Context
|
|
28
28
|
});
|
|
29
|
-
module.exports = __toCommonJS(
|
|
30
|
-
var import_callback_context = require("../agents/callback_context.js");
|
|
29
|
+
module.exports = __toCommonJS(context_exports);
|
|
31
30
|
var import_auth_handler = require("../auth/auth_handler.js");
|
|
31
|
+
var import_event_actions = require("../events/event_actions.js");
|
|
32
|
+
var import_state = require("../sessions/state.js");
|
|
32
33
|
var import_tool_confirmation = require("../tools/tool_confirmation.js");
|
|
34
|
+
var import_readonly_context = require("./readonly_context.js");
|
|
33
35
|
/**
|
|
34
36
|
* @license
|
|
35
37
|
* Copyright 2025 Google LLC
|
|
36
38
|
* SPDX-License-Identifier: Apache-2.0
|
|
37
39
|
*/
|
|
38
|
-
class
|
|
40
|
+
class Context extends import_readonly_context.ReadonlyContext {
|
|
39
41
|
/**
|
|
40
|
-
* @param
|
|
41
|
-
* @param
|
|
42
|
-
* @param
|
|
42
|
+
* @param options The configuration options for the Context.
|
|
43
|
+
* @param options.invocationContext The invocation context.
|
|
44
|
+
* @param options.eventActions The event actions of the current call.
|
|
45
|
+
* @param options.functionCallId The function call id of the current tool call.
|
|
43
46
|
* This id was returned in the function call event from LLM to identify a
|
|
44
47
|
* function call. If LLM didn't return this id, ADK will assign one to it.
|
|
45
48
|
* This id is used to map function call response to the original function
|
|
46
49
|
* call.
|
|
47
|
-
* @param
|
|
50
|
+
* @param options.toolConfirmation The tool confirmation of the current tool
|
|
48
51
|
* call.
|
|
49
52
|
*/
|
|
50
|
-
constructor(
|
|
51
|
-
super(
|
|
52
|
-
this.
|
|
53
|
-
this.
|
|
53
|
+
constructor(options) {
|
|
54
|
+
super(options.invocationContext);
|
|
55
|
+
this.eventActions = options.eventActions || (0, import_event_actions.createEventActions)();
|
|
56
|
+
this._state = new import_state.State(
|
|
57
|
+
options.invocationContext.session.state,
|
|
58
|
+
this.eventActions.stateDelta
|
|
59
|
+
);
|
|
60
|
+
this.functionCallId = options.functionCallId;
|
|
61
|
+
this.toolConfirmation = options.toolConfirmation;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The delta-aware state of the current session.
|
|
65
|
+
*/
|
|
66
|
+
get state() {
|
|
67
|
+
return this._state;
|
|
54
68
|
}
|
|
55
69
|
get actions() {
|
|
56
70
|
return this.eventActions;
|
|
57
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Loads an artifact attached to the current session.
|
|
74
|
+
*
|
|
75
|
+
* @param filename The filename of the artifact.
|
|
76
|
+
* @param version The version of the artifact. If not provided, the latest
|
|
77
|
+
* version will be used.
|
|
78
|
+
* @return A promise that resolves to the loaded artifact.
|
|
79
|
+
*/
|
|
80
|
+
loadArtifact(filename, version) {
|
|
81
|
+
if (!this.invocationContext.artifactService) {
|
|
82
|
+
throw new Error("Artifact service is not initialized.");
|
|
83
|
+
}
|
|
84
|
+
return this.invocationContext.artifactService.loadArtifact({
|
|
85
|
+
appName: this.invocationContext.appName,
|
|
86
|
+
userId: this.invocationContext.userId,
|
|
87
|
+
sessionId: this.invocationContext.session.id,
|
|
88
|
+
filename,
|
|
89
|
+
version
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Saves an artifact attached to the current session.
|
|
94
|
+
*
|
|
95
|
+
* @param filename The filename of the artifact.
|
|
96
|
+
* @param artifact The artifact to save.
|
|
97
|
+
* @return A promise that resolves to the version of the saved artifact.
|
|
98
|
+
*/
|
|
99
|
+
async saveArtifact(filename, artifact) {
|
|
100
|
+
if (!this.invocationContext.artifactService) {
|
|
101
|
+
throw new Error("Artifact service is not initialized.");
|
|
102
|
+
}
|
|
103
|
+
const version = await this.invocationContext.artifactService.saveArtifact({
|
|
104
|
+
appName: this.invocationContext.appName,
|
|
105
|
+
userId: this.invocationContext.userId,
|
|
106
|
+
sessionId: this.invocationContext.session.id,
|
|
107
|
+
filename,
|
|
108
|
+
artifact
|
|
109
|
+
});
|
|
110
|
+
this.eventActions.artifactDelta[filename] = version;
|
|
111
|
+
return version;
|
|
112
|
+
}
|
|
58
113
|
requestCredential(authConfig) {
|
|
59
114
|
if (!this.functionCallId) {
|
|
60
115
|
throw new Error("functionCallId is not set.");
|
|
@@ -120,5 +175,5 @@ class ToolContext extends import_callback_context.CallbackContext {
|
|
|
120
175
|
}
|
|
121
176
|
// Annotate the CommonJS export names for ESM import in node:
|
|
122
177
|
0 && (module.exports = {
|
|
123
|
-
|
|
178
|
+
Context
|
|
124
179
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @license
|
|
3
|
-
* Copyright
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -42,9 +42,9 @@ var import_genai = require("@google/genai");
|
|
|
42
42
|
var import_lodash_es = require("lodash-es");
|
|
43
43
|
var import_event = require("../events/event.js");
|
|
44
44
|
var import_event_actions = require("../events/event_actions.js");
|
|
45
|
-
var import_tool_context = require("../tools/tool_context.js");
|
|
46
45
|
var import_env_aware_utils = require("../utils/env_aware_utils.js");
|
|
47
46
|
var import_logger = require("../utils/logger.js");
|
|
47
|
+
var import_context = require("./context.js");
|
|
48
48
|
var import_tracing = require("../telemetry/tracing.js");
|
|
49
49
|
/**
|
|
50
50
|
* @license
|
|
@@ -164,6 +164,7 @@ function generateRequestConfirmationEvent({
|
|
|
164
164
|
parts,
|
|
165
165
|
role: functionResponseEvent.content.role
|
|
166
166
|
},
|
|
167
|
+
actions: functionResponseEvent.actions,
|
|
167
168
|
longRunningToolIds: Array.from(longRunningToolIds)
|
|
168
169
|
});
|
|
169
170
|
}
|
|
@@ -387,7 +388,7 @@ function getToolAndContext({
|
|
|
387
388
|
`Function ${functionCall.name} is not found in the toolsDict.`
|
|
388
389
|
);
|
|
389
390
|
}
|
|
390
|
-
const toolContext = new
|
|
391
|
+
const toolContext = new import_context.Context({
|
|
391
392
|
invocationContext,
|
|
392
393
|
functionCallId: functionCall.id || void 0,
|
|
393
394
|
toolConfirmation
|