@google/adk 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/a2a/a2a_event.js +317 -0
- package/dist/cjs/a2a/a2a_remote_agent.js +174 -0
- package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +198 -0
- package/dist/cjs/a2a/a2a_remote_agent_utils.js +165 -0
- package/dist/cjs/a2a/agent_card.js +380 -0
- package/dist/cjs/a2a/agent_executor.js +221 -0
- package/dist/cjs/a2a/agent_to_a2a.js +115 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/event_processor_utils.js +180 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +126 -0
- package/dist/cjs/a2a/part_converter_utils.js +47 -34
- package/dist/cjs/agents/base_agent.js +3 -3
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +70 -15
- package/dist/cjs/agents/functions.js +2 -2
- package/dist/cjs/agents/llm_agent.js +38 -674
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
- package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
- package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
- package/dist/cjs/agents/processors/content_request_processor.js +87 -0
- package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
- package/dist/cjs/artifacts/file_artifact_service.js +35 -4
- package/dist/cjs/common.js +48 -7
- package/dist/cjs/context/base_context_compactor.js +27 -0
- package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
- package/dist/cjs/context/token_based_context_compactor.js +135 -0
- package/dist/cjs/context/truncating_context_compactor.js +58 -0
- package/dist/cjs/events/compacted_event.js +53 -0
- package/dist/cjs/index.js +113 -53
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/models/llm_response.js +2 -0
- package/dist/cjs/plugins/base_plugin.js +1 -1
- package/dist/cjs/runner/runner.js +20 -11
- package/dist/cjs/sessions/database_session_service.js +4 -1
- package/dist/cjs/sessions/db/operations.js +25 -23
- package/dist/cjs/sessions/state.js +2 -2
- package/dist/cjs/tools/agent_tool.js +6 -5
- package/dist/cjs/tools/base_tool.js +3 -0
- package/dist/cjs/tools/base_toolset.js +13 -3
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/load_artifacts_tool.js +188 -0
- package/dist/cjs/tools/load_memory_tool.js +107 -0
- package/dist/cjs/tools/mcp/mcp_toolset.js +9 -5
- package/dist/cjs/tools/preload_memory_tool.js +109 -0
- package/dist/cjs/utils/logger.js +62 -54
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_event.js +269 -0
- package/dist/esm/a2a/a2a_remote_agent.js +148 -0
- package/dist/esm/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/esm/a2a/agent_card.js +340 -0
- package/dist/esm/a2a/agent_executor.js +202 -0
- package/dist/esm/a2a/agent_to_a2a.js +80 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/event_processor_utils.js +159 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +91 -0
- package/dist/esm/a2a/part_converter_utils.js +49 -34
- package/dist/esm/agents/base_agent.js +3 -3
- package/dist/{web/tools/tool_context.js → esm/agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +2 -2
- package/dist/esm/agents/llm_agent.js +31 -683
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
- package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
- package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
- package/dist/esm/agents/processors/content_request_processor.js +59 -0
- package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
- package/dist/esm/artifacts/file_artifact_service.js +30 -3
- package/dist/esm/common.js +44 -10
- package/dist/esm/context/base_context_compactor.js +5 -0
- package/dist/esm/context/summarizers/base_summarizer.js +5 -0
- package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
- package/dist/esm/context/token_based_context_compactor.js +105 -0
- package/dist/esm/context/truncating_context_compactor.js +28 -0
- package/dist/esm/events/compacted_event.js +22 -0
- package/dist/esm/index.js +119 -18
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/memory/in_memory_memory_service.js +1 -1
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +18 -10
- package/dist/esm/sessions/database_session_service.js +4 -1
- package/dist/esm/sessions/db/operations.js +32 -18
- package/dist/esm/sessions/state.js +2 -2
- package/dist/esm/tools/agent_tool.js +6 -5
- package/dist/esm/tools/base_tool.js +3 -0
- package/dist/esm/tools/base_toolset.js +11 -2
- package/dist/esm/tools/exit_loop_tool.js +32 -0
- package/dist/esm/tools/load_artifacts_tool.js +159 -0
- package/dist/esm/tools/load_memory_tool.js +78 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/tools/preload_memory_tool.js +80 -0
- package/dist/esm/utils/logger.js +52 -54
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +139 -0
- package/dist/types/a2a/a2a_remote_agent.d.ts +63 -0
- package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
- package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
- package/dist/types/a2a/agent_card.d.ts +23 -0
- package/dist/types/a2a/agent_executor.d.ts +52 -0
- package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/event_processor_utils.d.ts +24 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +63 -0
- package/dist/types/a2a/part_converter_utils.d.ts +4 -3
- package/dist/types/agents/base_agent.d.ts +2 -2
- package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
- package/dist/types/agents/llm_agent.d.ts +14 -31
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
- package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
- package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
- package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
- package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
- package/dist/types/common.d.ts +20 -5
- package/dist/types/context/base_context_compactor.d.ts +24 -0
- package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
- package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
- package/dist/types/context/token_based_context_compactor.d.ts +33 -0
- package/dist/types/context/truncating_context_compactor.d.ts +24 -0
- package/dist/types/events/compacted_event.d.ts +33 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/models/llm_response.d.ts +5 -1
- package/dist/types/plugins/base_plugin.d.ts +12 -13
- package/dist/types/plugins/logging_plugin.d.ts +9 -10
- package/dist/types/plugins/plugin_manager.d.ts +9 -10
- package/dist/types/plugins/security_plugin.d.ts +2 -2
- package/dist/types/runner/runner.d.ts +13 -0
- package/dist/types/sessions/database_session_service.d.ts +2 -1
- package/dist/types/sessions/db/operations.d.ts +3 -4
- package/dist/types/tools/base_tool.d.ts +3 -3
- package/dist/types/tools/base_toolset.d.ts +12 -3
- package/dist/types/tools/exit_loop_tool.d.ts +24 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
- package/dist/types/tools/load_memory_tool.d.ts +22 -0
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/tools/preload_memory_tool.d.ts +23 -0
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +269 -0
- package/dist/web/a2a/a2a_remote_agent.js +193 -0
- package/dist/web/a2a/a2a_remote_agent_run_processor.js +175 -0
- package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
- package/dist/web/a2a/agent_card.js +340 -0
- package/dist/web/a2a/agent_executor.js +216 -0
- package/dist/web/a2a/agent_to_a2a.js +80 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/event_processor_utils.js +168 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +108 -0
- package/dist/web/a2a/part_converter_utils.js +49 -34
- package/dist/web/agents/base_agent.js +3 -3
- package/dist/{esm/tools/tool_context.js → web/agents/context.js} +66 -11
- package/dist/web/agents/functions.js +2 -2
- package/dist/web/agents/llm_agent.js +31 -661
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
- package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
- package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
- package/dist/web/agents/processors/content_request_processor.js +77 -0
- package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
- package/dist/web/artifacts/file_artifact_service.js +30 -3
- package/dist/web/common.js +44 -10
- package/dist/web/context/base_context_compactor.js +5 -0
- package/dist/web/context/summarizers/base_summarizer.js +5 -0
- package/dist/web/context/summarizers/llm_summarizer.js +74 -0
- package/dist/web/context/token_based_context_compactor.js +105 -0
- package/dist/web/context/truncating_context_compactor.js +28 -0
- package/dist/web/events/compacted_event.js +40 -0
- package/dist/web/index.js +13 -18
- package/dist/web/index.js.map +7 -0
- package/dist/web/memory/in_memory_memory_service.js +1 -1
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +18 -10
- package/dist/web/sessions/database_session_service.js +4 -1
- package/dist/web/sessions/db/operations.js +32 -18
- package/dist/web/sessions/state.js +2 -2
- package/dist/web/tools/agent_tool.js +6 -5
- package/dist/web/tools/base_tool.js +3 -0
- package/dist/web/tools/base_toolset.js +11 -2
- package/dist/web/tools/exit_loop_tool.js +32 -0
- package/dist/web/tools/load_artifacts_tool.js +150 -0
- package/dist/web/tools/load_memory_tool.js +77 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/tools/preload_memory_tool.js +75 -0
- package/dist/web/utils/logger.js +52 -54
- package/dist/web/version.js +1 -1
- package/package.json +7 -4
- package/dist/cjs/agents/callback_context.js +0 -101
- package/dist/esm/agents/callback_context.js +0 -71
- package/dist/types/agents/callback_context.d.ts +0 -42
- package/dist/web/agents/callback_context.js +0 -71
- /package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
|
@@ -0,0 +1,180 @@
|
|
|
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 event_processor_utils_exports = {};
|
|
26
|
+
__export(event_processor_utils_exports, {
|
|
27
|
+
getFinalTaskStatusUpdate: () => getFinalTaskStatusUpdate,
|
|
28
|
+
getTaskInputRequiredEvent: () => getTaskInputRequiredEvent
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(event_processor_utils_exports);
|
|
31
|
+
var import_event_actions = require("../events/event_actions.js");
|
|
32
|
+
var import_a2a_event = require("./a2a_event.js");
|
|
33
|
+
var import_metadata_converter_utils = require("./metadata_converter_utils.js");
|
|
34
|
+
var import_part_converter_utils = require("./part_converter_utils.js");
|
|
35
|
+
/**
|
|
36
|
+
* @license
|
|
37
|
+
* Copyright 2026 Google LLC
|
|
38
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
39
|
+
*/
|
|
40
|
+
function getFinalTaskStatusUpdate(adkEvents, context) {
|
|
41
|
+
var _a, _b;
|
|
42
|
+
const finalEventActions = (0, import_event_actions.createEventActions)();
|
|
43
|
+
for (const adkEvent of adkEvents) {
|
|
44
|
+
if (adkEvent.errorCode || adkEvent.errorMessage) {
|
|
45
|
+
return (0, import_a2a_event.createTaskFailedEvent)({
|
|
46
|
+
taskId: context.requestContext.taskId,
|
|
47
|
+
contextId: context.requestContext.contextId,
|
|
48
|
+
error: new Error(adkEvent.errorMessage || adkEvent.errorCode),
|
|
49
|
+
metadata: {
|
|
50
|
+
...(0, import_metadata_converter_utils.getA2AEventMetadata)(adkEvent, context),
|
|
51
|
+
...(0, import_metadata_converter_utils.getA2AEventMetadataFromActions)(finalEventActions)
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
finalEventActions.escalate = finalEventActions.escalate || ((_a = adkEvent.actions) == null ? void 0 : _a.escalate);
|
|
56
|
+
if ((_b = adkEvent.actions) == null ? void 0 : _b.transferToAgent) {
|
|
57
|
+
finalEventActions.transferToAgent = adkEvent.actions.transferToAgent;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const inputRequiredEvent = scanForInputRequiredEvents(adkEvents, context);
|
|
61
|
+
if (inputRequiredEvent) {
|
|
62
|
+
return {
|
|
63
|
+
...inputRequiredEvent,
|
|
64
|
+
metadata: {
|
|
65
|
+
...inputRequiredEvent.metadata,
|
|
66
|
+
...(0, import_metadata_converter_utils.getA2AEventMetadataFromActions)(finalEventActions)
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return (0, import_a2a_event.createTaskCompletedEvent)({
|
|
71
|
+
taskId: context.requestContext.taskId,
|
|
72
|
+
contextId: context.requestContext.contextId,
|
|
73
|
+
metadata: {
|
|
74
|
+
...(0, import_metadata_converter_utils.getA2ASessionMetadata)(context),
|
|
75
|
+
...(0, import_metadata_converter_utils.getA2AEventMetadataFromActions)(finalEventActions)
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function scanForInputRequiredEvents(adkEvents, context) {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
const inputRequiredParts = [];
|
|
82
|
+
const inputRequiredFunctionCallIds = /* @__PURE__ */ new Set();
|
|
83
|
+
for (const adkEvent of adkEvents) {
|
|
84
|
+
if (!((_b = (_a = adkEvent.content) == null ? void 0 : _a.parts) == null ? void 0 : _b.length)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
for (const genAIPart of adkEvent.content.parts) {
|
|
88
|
+
const longRunningFunctionCallId = getLongRunnningFunctionCallId(
|
|
89
|
+
genAIPart,
|
|
90
|
+
adkEvent.longRunningToolIds,
|
|
91
|
+
inputRequiredParts
|
|
92
|
+
);
|
|
93
|
+
if (!longRunningFunctionCallId) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const isAlreadyAdded = inputRequiredFunctionCallIds.has(
|
|
97
|
+
longRunningFunctionCallId
|
|
98
|
+
);
|
|
99
|
+
if (isAlreadyAdded) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
inputRequiredParts.push(genAIPart);
|
|
103
|
+
inputRequiredFunctionCallIds.add(longRunningFunctionCallId);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (inputRequiredParts.length > 0) {
|
|
107
|
+
return (0, import_a2a_event.createTaskInputRequiredEvent)({
|
|
108
|
+
taskId: context.requestContext.taskId,
|
|
109
|
+
contextId: context.requestContext.contextId,
|
|
110
|
+
parts: (0, import_part_converter_utils.toA2AParts)(inputRequiredParts, [...inputRequiredFunctionCallIds]),
|
|
111
|
+
metadata: (0, import_metadata_converter_utils.getA2ASessionMetadata)(context)
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return void 0;
|
|
115
|
+
}
|
|
116
|
+
function getLongRunnningFunctionCallId(genAIPart, longRunningToolIds = [], inputRequiredParts = []) {
|
|
117
|
+
var _a, _b, _c;
|
|
118
|
+
const functionCallId = (_a = genAIPart.functionCall) == null ? void 0 : _a.id;
|
|
119
|
+
const functionResponseId = (_b = genAIPart.functionResponse) == null ? void 0 : _b.id;
|
|
120
|
+
if (!functionCallId && !functionResponseId) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (functionCallId && longRunningToolIds.includes(functionCallId)) {
|
|
124
|
+
return functionCallId;
|
|
125
|
+
}
|
|
126
|
+
if (functionResponseId && longRunningToolIds.includes(functionResponseId)) {
|
|
127
|
+
return functionResponseId;
|
|
128
|
+
}
|
|
129
|
+
for (const part of inputRequiredParts) {
|
|
130
|
+
if (((_c = part.functionCall) == null ? void 0 : _c.id) === functionResponseId) {
|
|
131
|
+
return functionResponseId;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
function getTaskInputRequiredEvent(task, genAIContent) {
|
|
137
|
+
var _a;
|
|
138
|
+
if (!task || !(0, import_a2a_event.isInputRequiredTaskStatusUpdateEvent)(task) || !task.status.message) {
|
|
139
|
+
return void 0;
|
|
140
|
+
}
|
|
141
|
+
const statusMsg = task.status.message;
|
|
142
|
+
const taskParts = (0, import_part_converter_utils.toGenAIParts)(statusMsg.parts);
|
|
143
|
+
for (const taskPart of taskParts) {
|
|
144
|
+
const functionCallId = (_a = taskPart.functionCall) == null ? void 0 : _a.id;
|
|
145
|
+
if (!functionCallId) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const hasMatchingResponse = ((genAIContent == null ? void 0 : genAIContent.parts) || []).some(
|
|
149
|
+
(p) => {
|
|
150
|
+
var _a2;
|
|
151
|
+
return ((_a2 = p.functionResponse) == null ? void 0 : _a2.id) === functionCallId;
|
|
152
|
+
}
|
|
153
|
+
);
|
|
154
|
+
if (!hasMatchingResponse) {
|
|
155
|
+
return (0, import_a2a_event.createInputMissingErrorEvent)({
|
|
156
|
+
taskId: task.id,
|
|
157
|
+
contextId: task.contextId,
|
|
158
|
+
parts: [
|
|
159
|
+
...statusMsg.parts.filter((p) => {
|
|
160
|
+
var _a2;
|
|
161
|
+
return !((_a2 = p.metadata) == null ? void 0 : _a2.validation_error);
|
|
162
|
+
}),
|
|
163
|
+
{
|
|
164
|
+
kind: "text",
|
|
165
|
+
text: `No input provided for function call id ${functionCallId}`,
|
|
166
|
+
metadata: {
|
|
167
|
+
validation_error: true
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return void 0;
|
|
175
|
+
}
|
|
176
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
177
|
+
0 && (module.exports = {
|
|
178
|
+
getFinalTaskStatusUpdate,
|
|
179
|
+
getTaskInputRequiredEvent
|
|
180
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
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 executor_context_exports = {};
|
|
26
|
+
__export(executor_context_exports, {
|
|
27
|
+
createExecutorContext: () => createExecutorContext
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(executor_context_exports);
|
|
30
|
+
/**
|
|
31
|
+
* @license
|
|
32
|
+
* Copyright 2026 Google LLC
|
|
33
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
34
|
+
*/
|
|
35
|
+
function createExecutorContext({
|
|
36
|
+
session,
|
|
37
|
+
userContent,
|
|
38
|
+
requestContext
|
|
39
|
+
}) {
|
|
40
|
+
return {
|
|
41
|
+
userId: session.userId,
|
|
42
|
+
sessionId: session.id,
|
|
43
|
+
appName: session.appName,
|
|
44
|
+
readonlyState: session.state,
|
|
45
|
+
events: session.events,
|
|
46
|
+
userContent,
|
|
47
|
+
requestContext
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
createExecutorContext
|
|
53
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
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 metadata_converter_utils_exports = {};
|
|
26
|
+
__export(metadata_converter_utils_exports, {
|
|
27
|
+
A2AMetadataKeys: () => A2AMetadataKeys,
|
|
28
|
+
AdkMetadataKeys: () => AdkMetadataKeys,
|
|
29
|
+
getA2AEventMetadata: () => getA2AEventMetadata,
|
|
30
|
+
getA2AEventMetadataFromActions: () => getA2AEventMetadataFromActions,
|
|
31
|
+
getA2ASessionMetadata: () => getA2ASessionMetadata,
|
|
32
|
+
getAdkEventMetadata: () => getAdkEventMetadata
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(metadata_converter_utils_exports);
|
|
35
|
+
var import_a2a_event = require("./a2a_event.js");
|
|
36
|
+
/**
|
|
37
|
+
* @license
|
|
38
|
+
* Copyright 2026 Google LLC
|
|
39
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
40
|
+
*/
|
|
41
|
+
const ADK_METADATA_KEY_PREFIX = "adk_";
|
|
42
|
+
const A2A_METADATA_KEY_PREFIX = "a2a:";
|
|
43
|
+
var A2AMetadataKeys = ((A2AMetadataKeys2) => {
|
|
44
|
+
A2AMetadataKeys2["APP_NAME"] = `${ADK_METADATA_KEY_PREFIX}app_name`;
|
|
45
|
+
A2AMetadataKeys2["USER_ID"] = `${ADK_METADATA_KEY_PREFIX}user_id`;
|
|
46
|
+
A2AMetadataKeys2["SESSION_ID"] = `${ADK_METADATA_KEY_PREFIX}session_id`;
|
|
47
|
+
A2AMetadataKeys2["INVOCATION_ID"] = `${ADK_METADATA_KEY_PREFIX}invocation_id`;
|
|
48
|
+
A2AMetadataKeys2["AUTHOR"] = `${ADK_METADATA_KEY_PREFIX}author`;
|
|
49
|
+
A2AMetadataKeys2["BRANCH"] = `${ADK_METADATA_KEY_PREFIX}branch`;
|
|
50
|
+
A2AMetadataKeys2["DATA_PART_TYPE"] = `${ADK_METADATA_KEY_PREFIX}type`;
|
|
51
|
+
A2AMetadataKeys2["PARTIAL"] = `${ADK_METADATA_KEY_PREFIX}partial`;
|
|
52
|
+
A2AMetadataKeys2["ESCALATE"] = `${ADK_METADATA_KEY_PREFIX}escalate`;
|
|
53
|
+
A2AMetadataKeys2["TRANSFER_TO_AGENT"] = `${ADK_METADATA_KEY_PREFIX}transfer_to_agent`;
|
|
54
|
+
A2AMetadataKeys2["IS_LONG_RUNNING"] = `${ADK_METADATA_KEY_PREFIX}is_long_running`;
|
|
55
|
+
A2AMetadataKeys2["THOUGHT"] = `${ADK_METADATA_KEY_PREFIX}thought`;
|
|
56
|
+
A2AMetadataKeys2["ERROR_CODE"] = `${ADK_METADATA_KEY_PREFIX}error_code`;
|
|
57
|
+
A2AMetadataKeys2["ERROR_MESSAGE"] = `${ADK_METADATA_KEY_PREFIX}error_message`;
|
|
58
|
+
A2AMetadataKeys2["CITATION_METADATA"] = `${ADK_METADATA_KEY_PREFIX}citation_metadata`;
|
|
59
|
+
A2AMetadataKeys2["GROUNDING_METADATA"] = `${ADK_METADATA_KEY_PREFIX}grounding_metadata`;
|
|
60
|
+
A2AMetadataKeys2["USAGE_METADATA"] = `${ADK_METADATA_KEY_PREFIX}usage_metadata`;
|
|
61
|
+
A2AMetadataKeys2["CUSTOM_METADATA"] = `${ADK_METADATA_KEY_PREFIX}custom_metadata`;
|
|
62
|
+
A2AMetadataKeys2["VIDEO_METADATA"] = `${ADK_METADATA_KEY_PREFIX}video_metadata`;
|
|
63
|
+
return A2AMetadataKeys2;
|
|
64
|
+
})(A2AMetadataKeys || {});
|
|
65
|
+
var AdkMetadataKeys = ((AdkMetadataKeys2) => {
|
|
66
|
+
AdkMetadataKeys2["TASK_ID"] = `${A2A_METADATA_KEY_PREFIX}task_id`;
|
|
67
|
+
AdkMetadataKeys2["CONTEXT_ID"] = `${A2A_METADATA_KEY_PREFIX}context_id`;
|
|
68
|
+
return AdkMetadataKeys2;
|
|
69
|
+
})(AdkMetadataKeys || {});
|
|
70
|
+
function getAdkEventMetadata(a2aEvent) {
|
|
71
|
+
return {
|
|
72
|
+
[AdkMetadataKeys.TASK_ID]: (0, import_a2a_event.isTask)(a2aEvent) ? a2aEvent.id : a2aEvent.taskId,
|
|
73
|
+
[AdkMetadataKeys.CONTEXT_ID]: a2aEvent.contextId
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function getA2AEventMetadata(adkEvent, {
|
|
77
|
+
appName,
|
|
78
|
+
userId,
|
|
79
|
+
sessionId
|
|
80
|
+
}) {
|
|
81
|
+
return {
|
|
82
|
+
...getA2AEventMetadataFromActions(adkEvent.actions),
|
|
83
|
+
...getA2ASessionMetadata({
|
|
84
|
+
appName,
|
|
85
|
+
userId,
|
|
86
|
+
sessionId
|
|
87
|
+
}),
|
|
88
|
+
[A2AMetadataKeys.INVOCATION_ID]: adkEvent.invocationId,
|
|
89
|
+
[A2AMetadataKeys.AUTHOR]: adkEvent.author,
|
|
90
|
+
[A2AMetadataKeys.BRANCH]: adkEvent.branch,
|
|
91
|
+
[A2AMetadataKeys.ERROR_CODE]: adkEvent.errorMessage,
|
|
92
|
+
[A2AMetadataKeys.ERROR_MESSAGE]: adkEvent.errorMessage,
|
|
93
|
+
[A2AMetadataKeys.CITATION_METADATA]: adkEvent.citationMetadata,
|
|
94
|
+
[A2AMetadataKeys.GROUNDING_METADATA]: adkEvent.groundingMetadata,
|
|
95
|
+
[A2AMetadataKeys.USAGE_METADATA]: adkEvent.usageMetadata,
|
|
96
|
+
[A2AMetadataKeys.CUSTOM_METADATA]: adkEvent.customMetadata,
|
|
97
|
+
[A2AMetadataKeys.PARTIAL]: adkEvent.partial,
|
|
98
|
+
[A2AMetadataKeys.IS_LONG_RUNNING]: (adkEvent.longRunningToolIds || []).length > 0
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function getA2ASessionMetadata({
|
|
102
|
+
appName,
|
|
103
|
+
userId,
|
|
104
|
+
sessionId
|
|
105
|
+
}) {
|
|
106
|
+
return {
|
|
107
|
+
[A2AMetadataKeys.APP_NAME]: appName,
|
|
108
|
+
[A2AMetadataKeys.USER_ID]: userId,
|
|
109
|
+
[A2AMetadataKeys.SESSION_ID]: sessionId
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function getA2AEventMetadataFromActions(actions) {
|
|
113
|
+
return {
|
|
114
|
+
[A2AMetadataKeys.ESCALATE]: actions.escalate,
|
|
115
|
+
[A2AMetadataKeys.TRANSFER_TO_AGENT]: actions.transferToAgent
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
119
|
+
0 && (module.exports = {
|
|
120
|
+
A2AMetadataKeys,
|
|
121
|
+
AdkMetadataKeys,
|
|
122
|
+
getA2AEventMetadata,
|
|
123
|
+
getA2AEventMetadataFromActions,
|
|
124
|
+
getA2ASessionMetadata,
|
|
125
|
+
getAdkEventMetadata
|
|
126
|
+
});
|
|
@@ -29,6 +29,7 @@ __export(part_converter_utils_exports, {
|
|
|
29
29
|
toA2APart: () => toA2APart,
|
|
30
30
|
toA2AParts: () => toA2AParts,
|
|
31
31
|
toA2ATextPart: () => toA2ATextPart,
|
|
32
|
+
toGenAIContent: () => toGenAIContent,
|
|
32
33
|
toGenAIPart: () => toGenAIPart,
|
|
33
34
|
toGenAIPartData: () => toGenAIPartData,
|
|
34
35
|
toGenAIPartFile: () => toGenAIPartFile,
|
|
@@ -36,17 +37,13 @@ __export(part_converter_utils_exports, {
|
|
|
36
37
|
toGenAIParts: () => toGenAIParts
|
|
37
38
|
});
|
|
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");
|
|
39
42
|
/**
|
|
40
43
|
* @license
|
|
41
44
|
* Copyright 2026 Google LLC
|
|
42
45
|
* SPDX-License-Identifier: Apache-2.0
|
|
43
46
|
*/
|
|
44
|
-
var MetadataKeys = /* @__PURE__ */ ((MetadataKeys2) => {
|
|
45
|
-
MetadataKeys2["TYPE"] = "adk_type";
|
|
46
|
-
MetadataKeys2["LONG_RUNNING"] = "adk_is_long_running";
|
|
47
|
-
MetadataKeys2["THOUGHT"] = "adk_thought";
|
|
48
|
-
return MetadataKeys2;
|
|
49
|
-
})(MetadataKeys || {});
|
|
50
47
|
var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
|
|
51
48
|
DataPartType2["FUNCTION_CALL"] = "function_call";
|
|
52
49
|
DataPartType2["FUNCTION_RESPONSE"] = "function_response";
|
|
@@ -54,7 +51,7 @@ var DataPartType = /* @__PURE__ */ ((DataPartType2) => {
|
|
|
54
51
|
DataPartType2["CODE_EXECUTABLE_CODE"] = "executable_code";
|
|
55
52
|
return DataPartType2;
|
|
56
53
|
})(DataPartType || {});
|
|
57
|
-
function toA2AParts(parts, longRunningToolIDs = []) {
|
|
54
|
+
function toA2AParts(parts = [], longRunningToolIDs = []) {
|
|
58
55
|
return parts.map((part) => toA2APart(part, longRunningToolIDs));
|
|
59
56
|
}
|
|
60
57
|
function toA2APart(part, longRunningToolIDs) {
|
|
@@ -68,14 +65,18 @@ function toA2APart(part, longRunningToolIDs) {
|
|
|
68
65
|
}
|
|
69
66
|
function toA2ATextPart(part) {
|
|
70
67
|
const a2aPart = { kind: "text", text: part.text || "" };
|
|
71
|
-
if (
|
|
68
|
+
if (part.thought) {
|
|
72
69
|
a2aPart.metadata = {
|
|
73
|
-
[
|
|
70
|
+
[import_metadata_converter_utils.A2AMetadataKeys.THOUGHT]: true
|
|
74
71
|
};
|
|
75
72
|
}
|
|
76
73
|
return a2aPart;
|
|
77
74
|
}
|
|
78
75
|
function toA2AFilePart(part) {
|
|
76
|
+
const metadata = {};
|
|
77
|
+
if (part.videoMetadata) {
|
|
78
|
+
metadata[import_metadata_converter_utils.A2AMetadataKeys.VIDEO_METADATA] = part.videoMetadata;
|
|
79
|
+
}
|
|
79
80
|
if (part.fileData) {
|
|
80
81
|
return {
|
|
81
82
|
kind: "file",
|
|
@@ -83,7 +84,7 @@ function toA2AFilePart(part) {
|
|
|
83
84
|
uri: part.fileData.fileUri || "",
|
|
84
85
|
mimeType: part.fileData.mimeType
|
|
85
86
|
},
|
|
86
|
-
metadata
|
|
87
|
+
metadata
|
|
87
88
|
};
|
|
88
89
|
}
|
|
89
90
|
if (part.inlineData) {
|
|
@@ -93,37 +94,41 @@ function toA2AFilePart(part) {
|
|
|
93
94
|
bytes: part.inlineData.data || "",
|
|
94
95
|
mimeType: part.inlineData.mimeType
|
|
95
96
|
},
|
|
96
|
-
metadata
|
|
97
|
+
metadata
|
|
97
98
|
};
|
|
98
99
|
}
|
|
99
100
|
throw new Error(`Not a file part: ${JSON.stringify(part)}`);
|
|
100
101
|
}
|
|
101
102
|
function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
102
|
-
let
|
|
103
|
+
let dataPartType;
|
|
103
104
|
let data;
|
|
104
105
|
if (part.functionCall) {
|
|
105
|
-
|
|
106
|
+
dataPartType = "function_call" /* FUNCTION_CALL */;
|
|
106
107
|
data = part.functionCall;
|
|
107
108
|
} else if (part.functionResponse) {
|
|
108
|
-
|
|
109
|
+
dataPartType = "function_response" /* FUNCTION_RESPONSE */;
|
|
109
110
|
data = part.functionResponse;
|
|
110
111
|
} else if (part.executableCode) {
|
|
111
|
-
|
|
112
|
+
dataPartType = "executable_code" /* CODE_EXECUTABLE_CODE */;
|
|
112
113
|
data = part.executableCode;
|
|
113
114
|
} else if (part.codeExecutionResult) {
|
|
114
|
-
|
|
115
|
+
dataPartType = "code_execution_result" /* CODE_EXEC_RESULT */;
|
|
115
116
|
data = part.codeExecutionResult;
|
|
116
117
|
} else {
|
|
117
|
-
|
|
118
|
+
return {
|
|
119
|
+
kind: "data",
|
|
120
|
+
data: {},
|
|
121
|
+
metadata: {}
|
|
122
|
+
};
|
|
118
123
|
}
|
|
119
124
|
const metadata = {
|
|
120
|
-
[
|
|
125
|
+
[import_metadata_converter_utils.A2AMetadataKeys.DATA_PART_TYPE]: dataPartType
|
|
121
126
|
};
|
|
122
|
-
if (part.functionCall && part.functionCall.
|
|
123
|
-
metadata[
|
|
127
|
+
if (part.functionCall && part.functionCall.id && longRunningToolIDs.includes(part.functionCall.id)) {
|
|
128
|
+
metadata[import_metadata_converter_utils.A2AMetadataKeys.IS_LONG_RUNNING] = true;
|
|
124
129
|
}
|
|
125
|
-
if (part.functionResponse && part.functionResponse.
|
|
126
|
-
metadata[
|
|
130
|
+
if (part.functionResponse && part.functionResponse.id && longRunningToolIDs.includes(part.functionResponse.id)) {
|
|
131
|
+
metadata[import_metadata_converter_utils.A2AMetadataKeys.IS_LONG_RUNNING] = true;
|
|
127
132
|
}
|
|
128
133
|
return {
|
|
129
134
|
kind: "data",
|
|
@@ -131,6 +136,10 @@ function toA2ADataPart(part, longRunningToolIDs = []) {
|
|
|
131
136
|
metadata
|
|
132
137
|
};
|
|
133
138
|
}
|
|
139
|
+
function toGenAIContent(a2aMessage) {
|
|
140
|
+
const parts = toGenAIParts(a2aMessage.parts);
|
|
141
|
+
return a2aMessage.role === "user" ? (0, import_genai.createUserContent)(parts) : (0, import_genai.createModelContent)(parts);
|
|
142
|
+
}
|
|
134
143
|
function toGenAIParts(a2aParts) {
|
|
135
144
|
return a2aParts.map((a2aPart) => toGenAIPart(a2aPart));
|
|
136
145
|
}
|
|
@@ -150,25 +159,28 @@ function toGenAIPartText(a2aPart) {
|
|
|
150
159
|
var _a;
|
|
151
160
|
return {
|
|
152
161
|
text: a2aPart.text,
|
|
153
|
-
thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a[
|
|
162
|
+
thought: !!((_a = a2aPart.metadata) == null ? void 0 : _a[import_metadata_converter_utils.A2AMetadataKeys.THOUGHT])
|
|
154
163
|
};
|
|
155
164
|
}
|
|
156
165
|
function toGenAIPartFile(a2aPart) {
|
|
166
|
+
var _a;
|
|
167
|
+
const part = {};
|
|
168
|
+
if ((_a = a2aPart.metadata) == null ? void 0 : _a[import_metadata_converter_utils.A2AMetadataKeys.VIDEO_METADATA]) {
|
|
169
|
+
part.videoMetadata = a2aPart.metadata[import_metadata_converter_utils.A2AMetadataKeys.VIDEO_METADATA];
|
|
170
|
+
}
|
|
157
171
|
if ("bytes" in a2aPart.file) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
mimeType: a2aPart.file.mimeType || ""
|
|
162
|
-
}
|
|
172
|
+
part.inlineData = {
|
|
173
|
+
data: a2aPart.file.bytes,
|
|
174
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
163
175
|
};
|
|
176
|
+
return part;
|
|
164
177
|
}
|
|
165
178
|
if ("uri" in a2aPart.file) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
mimeType: a2aPart.file.mimeType || ""
|
|
170
|
-
}
|
|
179
|
+
part.fileData = {
|
|
180
|
+
fileUri: a2aPart.file.uri,
|
|
181
|
+
mimeType: a2aPart.file.mimeType || ""
|
|
171
182
|
};
|
|
183
|
+
return part;
|
|
172
184
|
}
|
|
173
185
|
throw new Error(`Not a file part: ${JSON.stringify(a2aPart)}`);
|
|
174
186
|
}
|
|
@@ -178,7 +190,7 @@ function toGenAIPartData(a2aPart) {
|
|
|
178
190
|
throw new Error(`No data in part: ${JSON.stringify(a2aPart)}`);
|
|
179
191
|
}
|
|
180
192
|
const data = a2aPart.data;
|
|
181
|
-
const type = (_a = a2aPart.metadata) == null ? void 0 : _a[
|
|
193
|
+
const type = (_a = a2aPart.metadata) == null ? void 0 : _a[import_metadata_converter_utils.A2AMetadataKeys.DATA_PART_TYPE];
|
|
182
194
|
if (type === "function_call" /* FUNCTION_CALL */) {
|
|
183
195
|
return { functionCall: data };
|
|
184
196
|
}
|
|
@@ -202,6 +214,7 @@ function toGenAIPartData(a2aPart) {
|
|
|
202
214
|
toA2APart,
|
|
203
215
|
toA2AParts,
|
|
204
216
|
toA2ATextPart,
|
|
217
|
+
toGenAIContent,
|
|
205
218
|
toGenAIPart,
|
|
206
219
|
toGenAIPartData,
|
|
207
220
|
toGenAIPartFile,
|
|
@@ -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) {
|
|
@@ -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
|
});
|