@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,221 @@
|
|
|
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 agent_executor_exports = {};
|
|
26
|
+
__export(agent_executor_exports, {
|
|
27
|
+
A2AAgentExecutor: () => A2AAgentExecutor
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(agent_executor_exports);
|
|
30
|
+
var import_runner = require("../runner/runner.js");
|
|
31
|
+
var import_env_aware_utils = require("../utils/env_aware_utils.js");
|
|
32
|
+
var import_logger = require("../utils/logger.js");
|
|
33
|
+
var import_a2a_event = require("./a2a_event.js");
|
|
34
|
+
var import_event_processor_utils = require("./event_processor_utils.js");
|
|
35
|
+
var import_executor_context = require("./executor_context.js");
|
|
36
|
+
var import_metadata_converter_utils = require("./metadata_converter_utils.js");
|
|
37
|
+
var import_part_converter_utils = require("./part_converter_utils.js");
|
|
38
|
+
/**
|
|
39
|
+
* @license
|
|
40
|
+
* Copyright 2026 Google LLC
|
|
41
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
42
|
+
*/
|
|
43
|
+
class A2AAgentExecutor {
|
|
44
|
+
constructor(config) {
|
|
45
|
+
this.config = config;
|
|
46
|
+
this.agentPartialArtifactIdsMap = {};
|
|
47
|
+
}
|
|
48
|
+
async execute(ctx, eventBus) {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
const a2aUserMessage = ctx.userMessage;
|
|
51
|
+
if (!a2aUserMessage) {
|
|
52
|
+
throw new Error("message not provided");
|
|
53
|
+
}
|
|
54
|
+
const userId = `A2A_USER_${ctx.contextId}`;
|
|
55
|
+
const sessionId = ctx.contextId;
|
|
56
|
+
const genAIUserMessage = (0, import_part_converter_utils.toGenAIContent)(a2aUserMessage);
|
|
57
|
+
const adkRunner = await getAdkRunner(this.config.runner);
|
|
58
|
+
const session = await getAdkSession(
|
|
59
|
+
userId,
|
|
60
|
+
sessionId,
|
|
61
|
+
adkRunner.sessionService,
|
|
62
|
+
adkRunner.appName
|
|
63
|
+
);
|
|
64
|
+
const executorContext = (0, import_executor_context.createExecutorContext)({
|
|
65
|
+
session,
|
|
66
|
+
userContent: genAIUserMessage,
|
|
67
|
+
requestContext: ctx
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
if (this.config.beforeExecuteCallback) {
|
|
71
|
+
await this.config.beforeExecuteCallback(ctx);
|
|
72
|
+
}
|
|
73
|
+
if (ctx.task) {
|
|
74
|
+
const inputRequiredEvent = (0, import_event_processor_utils.getTaskInputRequiredEvent)(
|
|
75
|
+
ctx.task,
|
|
76
|
+
genAIUserMessage
|
|
77
|
+
);
|
|
78
|
+
if (inputRequiredEvent) {
|
|
79
|
+
await this.publishFinalTaskStatus({
|
|
80
|
+
executorContext,
|
|
81
|
+
eventBus,
|
|
82
|
+
event: inputRequiredEvent
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (!ctx.task) {
|
|
88
|
+
eventBus.publish(
|
|
89
|
+
(0, import_a2a_event.createTask)({
|
|
90
|
+
taskId: ctx.taskId,
|
|
91
|
+
contextId: ctx.contextId,
|
|
92
|
+
message: a2aUserMessage
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
eventBus.publish(
|
|
97
|
+
(0, import_a2a_event.createTaskWorkingEvent)({
|
|
98
|
+
taskId: ctx.taskId,
|
|
99
|
+
contextId: ctx.contextId
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
const adkEvents = [];
|
|
103
|
+
for await (const adkEvent of adkRunner.runAsync({
|
|
104
|
+
userId,
|
|
105
|
+
sessionId,
|
|
106
|
+
newMessage: genAIUserMessage,
|
|
107
|
+
runConfig: this.config.runConfig
|
|
108
|
+
})) {
|
|
109
|
+
adkEvents.push(adkEvent);
|
|
110
|
+
const a2aEvent = this.convertAdkEventToA2AEvent(
|
|
111
|
+
adkEvent,
|
|
112
|
+
executorContext
|
|
113
|
+
);
|
|
114
|
+
if (!a2aEvent) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
await ((_b = (_a = this.config).afterEventCallback) == null ? void 0 : _b.call(
|
|
118
|
+
_a,
|
|
119
|
+
executorContext,
|
|
120
|
+
adkEvent,
|
|
121
|
+
a2aEvent
|
|
122
|
+
));
|
|
123
|
+
eventBus.publish(a2aEvent);
|
|
124
|
+
}
|
|
125
|
+
await this.publishFinalTaskStatus({
|
|
126
|
+
executorContext,
|
|
127
|
+
eventBus,
|
|
128
|
+
event: (0, import_event_processor_utils.getFinalTaskStatusUpdate)(adkEvents, executorContext)
|
|
129
|
+
});
|
|
130
|
+
} catch (e) {
|
|
131
|
+
const error = e;
|
|
132
|
+
await this.publishFinalTaskStatus({
|
|
133
|
+
executorContext,
|
|
134
|
+
eventBus,
|
|
135
|
+
error,
|
|
136
|
+
event: (0, import_a2a_event.createTaskFailedEvent)({
|
|
137
|
+
taskId: ctx.taskId,
|
|
138
|
+
contextId: ctx.contextId,
|
|
139
|
+
error: new Error(`Agent run failed: ${error.message}`),
|
|
140
|
+
metadata: (0, import_metadata_converter_utils.getA2ASessionMetadata)(executorContext)
|
|
141
|
+
})
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Task cancellation is not supported in this implementation yet.
|
|
146
|
+
async cancelTask(_taskId) {
|
|
147
|
+
throw new Error("Task cancellation is not supported yet.");
|
|
148
|
+
}
|
|
149
|
+
convertAdkEventToA2AEvent(adkEvent, executorContext) {
|
|
150
|
+
var _a;
|
|
151
|
+
const a2aParts = (0, import_part_converter_utils.toA2AParts)(
|
|
152
|
+
(_a = adkEvent.content) == null ? void 0 : _a.parts,
|
|
153
|
+
adkEvent.longRunningToolIds
|
|
154
|
+
);
|
|
155
|
+
if (a2aParts.length === 0) {
|
|
156
|
+
return void 0;
|
|
157
|
+
}
|
|
158
|
+
const artifactId = this.agentPartialArtifactIdsMap[adkEvent.author] || (0, import_env_aware_utils.randomUUID)();
|
|
159
|
+
const a2aEvent = (0, import_a2a_event.createTaskArtifactUpdateEvent)({
|
|
160
|
+
taskId: executorContext.requestContext.taskId,
|
|
161
|
+
contextId: executorContext.requestContext.contextId,
|
|
162
|
+
artifactId,
|
|
163
|
+
parts: a2aParts,
|
|
164
|
+
metadata: (0, import_metadata_converter_utils.getA2AEventMetadata)(adkEvent, executorContext),
|
|
165
|
+
append: adkEvent.partial,
|
|
166
|
+
lastChunk: !adkEvent.partial
|
|
167
|
+
});
|
|
168
|
+
if (adkEvent.partial) {
|
|
169
|
+
this.agentPartialArtifactIdsMap[adkEvent.author] = artifactId;
|
|
170
|
+
} else {
|
|
171
|
+
delete this.agentPartialArtifactIdsMap[adkEvent.author];
|
|
172
|
+
}
|
|
173
|
+
return a2aEvent;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Writes the final status event to the queue.
|
|
177
|
+
*/
|
|
178
|
+
async publishFinalTaskStatus({
|
|
179
|
+
executorContext,
|
|
180
|
+
eventBus,
|
|
181
|
+
event,
|
|
182
|
+
error
|
|
183
|
+
}) {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
try {
|
|
186
|
+
await ((_b = (_a = this.config).afterExecuteCallback) == null ? void 0 : _b.call(_a, executorContext, event, error));
|
|
187
|
+
} catch (e) {
|
|
188
|
+
import_logger.logger.error("Error in afterExecuteCallback:", e);
|
|
189
|
+
}
|
|
190
|
+
eventBus.publish(event);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async function getAdkSession(userId, sessionId, sessionService, appName) {
|
|
194
|
+
const session = await sessionService.getSession({
|
|
195
|
+
appName,
|
|
196
|
+
userId,
|
|
197
|
+
sessionId
|
|
198
|
+
});
|
|
199
|
+
if (session) {
|
|
200
|
+
return session;
|
|
201
|
+
}
|
|
202
|
+
return sessionService.createSession({
|
|
203
|
+
appName,
|
|
204
|
+
userId,
|
|
205
|
+
sessionId
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
async function getAdkRunner(runnerOrConfig) {
|
|
209
|
+
if (typeof runnerOrConfig === "function") {
|
|
210
|
+
const result = await runnerOrConfig();
|
|
211
|
+
return getAdkRunner(result);
|
|
212
|
+
}
|
|
213
|
+
if ((0, import_runner.isRunner)(runnerOrConfig)) {
|
|
214
|
+
return runnerOrConfig;
|
|
215
|
+
}
|
|
216
|
+
return new import_runner.Runner(runnerOrConfig);
|
|
217
|
+
}
|
|
218
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
219
|
+
0 && (module.exports = {
|
|
220
|
+
A2AAgentExecutor
|
|
221
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
var __create = Object.create;
|
|
9
|
+
var __defProp = Object.defineProperty;
|
|
10
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
12
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
27
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
28
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
29
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
30
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
31
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
32
|
+
mod
|
|
33
|
+
));
|
|
34
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
35
|
+
var agent_to_a2a_exports = {};
|
|
36
|
+
__export(agent_to_a2a_exports, {
|
|
37
|
+
toA2a: () => toA2a
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(agent_to_a2a_exports);
|
|
40
|
+
var import_sdk = require("@a2a-js/sdk");
|
|
41
|
+
var import_server = require("@a2a-js/sdk/server");
|
|
42
|
+
var import_express = require("@a2a-js/sdk/server/express");
|
|
43
|
+
var import_express2 = __toESM(require("express"), 1);
|
|
44
|
+
var import_run_config = require("../agents/run_config.js");
|
|
45
|
+
var import_in_memory_session_service = require("../sessions/in_memory_session_service.js");
|
|
46
|
+
var import_agent_card = require("./agent_card.js");
|
|
47
|
+
var import_agent_executor = require("./agent_executor.js");
|
|
48
|
+
/**
|
|
49
|
+
* @license
|
|
50
|
+
* Copyright 2026 Google LLC
|
|
51
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
52
|
+
*/
|
|
53
|
+
async function toA2a(agent, options = {}) {
|
|
54
|
+
var _a, _b, _c, _d;
|
|
55
|
+
const host = (_a = options.host) != null ? _a : "localhost";
|
|
56
|
+
const port = (_b = options.port) != null ? _b : 8e3;
|
|
57
|
+
const protocol = (_c = options.protocol) != null ? _c : "http";
|
|
58
|
+
const basePath = options.basePath || "";
|
|
59
|
+
const rpcUrl = `${protocol}://${host}:${port}${basePath}`;
|
|
60
|
+
const agentCard = options.agentCard ? await (0, import_agent_card.resolveAgentCard)(options.agentCard) : await (0, import_agent_card.getA2AAgentCard)(agent, [
|
|
61
|
+
{
|
|
62
|
+
url: `${rpcUrl}/jsonrpc`,
|
|
63
|
+
transport: "JSONRPC"
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
url: `${rpcUrl}/rest`,
|
|
67
|
+
transport: "HTTP+JSON"
|
|
68
|
+
}
|
|
69
|
+
]);
|
|
70
|
+
const agentExecutor = new import_agent_executor.A2AAgentExecutor({
|
|
71
|
+
runner: options.runner || {
|
|
72
|
+
agent,
|
|
73
|
+
appName: agent.name,
|
|
74
|
+
sessionService: options.sessionService || new import_in_memory_session_service.InMemorySessionService(),
|
|
75
|
+
memoryService: options.memoryService,
|
|
76
|
+
artifactService: options.artifactService
|
|
77
|
+
},
|
|
78
|
+
runConfig: {
|
|
79
|
+
streamingMode: import_run_config.StreamingMode.SSE
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const requestHandler = new import_server.DefaultRequestHandler(
|
|
83
|
+
agentCard,
|
|
84
|
+
new import_server.InMemoryTaskStore(),
|
|
85
|
+
agentExecutor
|
|
86
|
+
);
|
|
87
|
+
const app = (_d = options.app) != null ? _d : (0, import_express2.default)();
|
|
88
|
+
if (!options.app) {
|
|
89
|
+
app.use(import_express2.default.urlencoded({ limit: "50mb", extended: true }));
|
|
90
|
+
app.use(import_express2.default.json({ limit: "50mb" }));
|
|
91
|
+
}
|
|
92
|
+
app.use(
|
|
93
|
+
`${basePath}/${import_sdk.AGENT_CARD_PATH}`,
|
|
94
|
+
(0, import_express.agentCardHandler)({ agentCardProvider: requestHandler })
|
|
95
|
+
);
|
|
96
|
+
app.use(
|
|
97
|
+
`${basePath}/rest`,
|
|
98
|
+
(0, import_express.restHandler)({
|
|
99
|
+
requestHandler,
|
|
100
|
+
userBuilder: import_express.UserBuilder.noAuthentication
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
app.use(
|
|
104
|
+
`${basePath}/jsonrpc`,
|
|
105
|
+
(0, import_express.jsonRpcHandler)({
|
|
106
|
+
requestHandler,
|
|
107
|
+
userBuilder: import_express.UserBuilder.noAuthentication
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
return app;
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
toA2a
|
|
115
|
+
});
|
|
@@ -0,0 +1,201 @@
|
|
|
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_converter_utils_exports = {};
|
|
26
|
+
__export(event_converter_utils_exports, {
|
|
27
|
+
toA2AMessage: () => toA2AMessage,
|
|
28
|
+
toAdkEvent: () => toAdkEvent
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(event_converter_utils_exports);
|
|
31
|
+
var import_genai = require("@google/genai");
|
|
32
|
+
var import_event = require("../events/event.js");
|
|
33
|
+
var import_event_actions = require("../events/event_actions.js");
|
|
34
|
+
var import_env_aware_utils = require("../utils/env_aware_utils.js");
|
|
35
|
+
var import_a2a_event = require("./a2a_event.js");
|
|
36
|
+
var import_metadata_converter_utils = require("./metadata_converter_utils.js");
|
|
37
|
+
var import_part_converter_utils = require("./part_converter_utils.js");
|
|
38
|
+
/**
|
|
39
|
+
* @license
|
|
40
|
+
* Copyright 2026 Google LLC
|
|
41
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
42
|
+
*/
|
|
43
|
+
function toA2AMessage(event, {
|
|
44
|
+
appName,
|
|
45
|
+
userId,
|
|
46
|
+
sessionId
|
|
47
|
+
}) {
|
|
48
|
+
var _a;
|
|
49
|
+
return {
|
|
50
|
+
kind: "message",
|
|
51
|
+
messageId: (0, import_env_aware_utils.randomUUID)(),
|
|
52
|
+
role: event.author === import_a2a_event.MessageRole.USER ? import_a2a_event.MessageRole.USER : import_a2a_event.MessageRole.AGENT,
|
|
53
|
+
parts: (0, import_part_converter_utils.toA2AParts)(((_a = event.content) == null ? void 0 : _a.parts) || [], event.longRunningToolIds),
|
|
54
|
+
metadata: (0, import_metadata_converter_utils.getA2AEventMetadata)(event, { appName, userId, sessionId })
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function toAdkEvent(event, invocationId, agentName) {
|
|
58
|
+
if ((0, import_a2a_event.isMessage)(event)) {
|
|
59
|
+
return messageToAdkEvent(event, invocationId, agentName);
|
|
60
|
+
}
|
|
61
|
+
if ((0, import_a2a_event.isTask)(event)) {
|
|
62
|
+
return taskToAdkEvent(event, invocationId, agentName);
|
|
63
|
+
}
|
|
64
|
+
if ((0, import_a2a_event.isTaskArtifactUpdateEvent)(event)) {
|
|
65
|
+
return artifactUpdateToAdkEvent(event, invocationId, agentName);
|
|
66
|
+
}
|
|
67
|
+
if ((0, import_a2a_event.isTaskStatusUpdateEvent)(event)) {
|
|
68
|
+
return event.final ? finalTaskStatusUpdateToAdkEvent(event, invocationId, agentName) : taskStatusUpdateToAdkEvent(event, invocationId, agentName);
|
|
69
|
+
}
|
|
70
|
+
return void 0;
|
|
71
|
+
}
|
|
72
|
+
function messageToAdkEvent(msg, invocationId, agentName, parentEvent) {
|
|
73
|
+
const parts = (0, import_part_converter_utils.toGenAIParts)(msg.parts);
|
|
74
|
+
return {
|
|
75
|
+
...createAdkEventFromMetadata(parentEvent || msg),
|
|
76
|
+
invocationId,
|
|
77
|
+
author: msg.role === import_a2a_event.MessageRole.USER ? import_a2a_event.MessageRole.USER : agentName,
|
|
78
|
+
content: msg.role === import_a2a_event.MessageRole.USER ? (0, import_genai.createUserContent)(parts) : (0, import_genai.createModelContent)(parts),
|
|
79
|
+
turnComplete: true,
|
|
80
|
+
partial: false
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function artifactUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
84
|
+
var _a;
|
|
85
|
+
const partsToConvert = ((_a = a2aEvent.artifact) == null ? void 0 : _a.parts) || [];
|
|
86
|
+
if (partsToConvert.length === 0) {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
const partial = !!(0, import_a2a_event.getEventMetadata)(a2aEvent)[import_metadata_converter_utils.A2AMetadataKeys.PARTIAL] || a2aEvent.append || !a2aEvent.lastChunk;
|
|
90
|
+
return {
|
|
91
|
+
...createAdkEventFromMetadata(a2aEvent),
|
|
92
|
+
invocationId,
|
|
93
|
+
author: agentName,
|
|
94
|
+
content: (0, import_genai.createModelContent)((0, import_part_converter_utils.toGenAIParts)(partsToConvert)),
|
|
95
|
+
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
96
|
+
partial
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function finalTaskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
100
|
+
var _a;
|
|
101
|
+
const partsToConvert = ((_a = a2aEvent.status.message) == null ? void 0 : _a.parts) || [];
|
|
102
|
+
if (partsToConvert.length === 0) {
|
|
103
|
+
return void 0;
|
|
104
|
+
}
|
|
105
|
+
const parts = (0, import_part_converter_utils.toGenAIParts)(partsToConvert);
|
|
106
|
+
const isFailedTask = (0, import_a2a_event.isFailedTaskStatusUpdateEvent)(a2aEvent);
|
|
107
|
+
const hasContent = !isFailedTask && parts.length > 0;
|
|
108
|
+
return {
|
|
109
|
+
...createAdkEventFromMetadata(a2aEvent),
|
|
110
|
+
invocationId,
|
|
111
|
+
author: agentName,
|
|
112
|
+
errorMessage: isFailedTask ? (0, import_a2a_event.getFailedTaskStatusUpdateEventError)(a2aEvent) : void 0,
|
|
113
|
+
content: hasContent ? (0, import_genai.createModelContent)(parts) : void 0,
|
|
114
|
+
longRunningToolIds: getLongRunningToolIDs(partsToConvert),
|
|
115
|
+
turnComplete: true
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function taskStatusUpdateToAdkEvent(a2aEvent, invocationId, agentName) {
|
|
119
|
+
const msg = a2aEvent.status.message;
|
|
120
|
+
if (!msg) {
|
|
121
|
+
return void 0;
|
|
122
|
+
}
|
|
123
|
+
const parts = (0, import_part_converter_utils.toGenAIParts)(msg.parts);
|
|
124
|
+
return {
|
|
125
|
+
...createAdkEventFromMetadata(a2aEvent),
|
|
126
|
+
invocationId,
|
|
127
|
+
author: agentName,
|
|
128
|
+
content: (0, import_genai.createModelContent)(parts),
|
|
129
|
+
turnComplete: false,
|
|
130
|
+
partial: true
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function taskToAdkEvent(a2aTask, invocationId, agentName) {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
const parts = [];
|
|
136
|
+
const longRunningToolIds = [];
|
|
137
|
+
if (a2aTask.artifacts) {
|
|
138
|
+
for (const artifact of a2aTask.artifacts) {
|
|
139
|
+
if (((_a = artifact.parts) == null ? void 0 : _a.length) > 0) {
|
|
140
|
+
const artifactParts = (0, import_part_converter_utils.toGenAIParts)(artifact.parts);
|
|
141
|
+
parts.push(...artifactParts);
|
|
142
|
+
longRunningToolIds.push(...getLongRunningToolIDs(artifact.parts));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if ((_b = a2aTask.status) == null ? void 0 : _b.message) {
|
|
147
|
+
const a2aParts = a2aTask.status.message.parts;
|
|
148
|
+
const genAIParts = (0, import_part_converter_utils.toGenAIParts)(a2aParts);
|
|
149
|
+
parts.push(...genAIParts);
|
|
150
|
+
longRunningToolIds.push(...getLongRunningToolIDs(a2aParts));
|
|
151
|
+
}
|
|
152
|
+
const isTerminal = (0, import_a2a_event.isTerminalTaskStatusUpdateEvent)(a2aTask) || (0, import_a2a_event.isInputRequiredTaskStatusUpdateEvent)(a2aTask);
|
|
153
|
+
const isFailed = (0, import_a2a_event.isFailedTaskStatusUpdateEvent)(a2aTask);
|
|
154
|
+
if (parts.length === 0 && !isTerminal) {
|
|
155
|
+
return void 0;
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
...createAdkEventFromMetadata(a2aTask),
|
|
159
|
+
invocationId,
|
|
160
|
+
author: agentName,
|
|
161
|
+
content: isFailed ? void 0 : (0, import_genai.createModelContent)(parts),
|
|
162
|
+
errorMessage: isFailed ? (0, import_a2a_event.getFailedTaskStatusUpdateEventError)(a2aTask) : void 0,
|
|
163
|
+
longRunningToolIds,
|
|
164
|
+
turnComplete: isTerminal
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function createAdkEventFromMetadata(a2aEvent) {
|
|
168
|
+
const metadata = a2aEvent.metadata || {};
|
|
169
|
+
return (0, import_event.createEvent)({
|
|
170
|
+
branch: metadata[import_metadata_converter_utils.A2AMetadataKeys.BRANCH],
|
|
171
|
+
author: metadata[import_metadata_converter_utils.A2AMetadataKeys.AUTHOR],
|
|
172
|
+
partial: metadata[import_metadata_converter_utils.A2AMetadataKeys.PARTIAL],
|
|
173
|
+
errorCode: metadata[import_metadata_converter_utils.A2AMetadataKeys.ERROR_CODE],
|
|
174
|
+
errorMessage: metadata[import_metadata_converter_utils.A2AMetadataKeys.ERROR_MESSAGE],
|
|
175
|
+
citationMetadata: metadata[import_metadata_converter_utils.A2AMetadataKeys.CITATION_METADATA],
|
|
176
|
+
groundingMetadata: metadata[import_metadata_converter_utils.A2AMetadataKeys.GROUNDING_METADATA],
|
|
177
|
+
usageMetadata: metadata[import_metadata_converter_utils.A2AMetadataKeys.USAGE_METADATA],
|
|
178
|
+
customMetadata: metadata[import_metadata_converter_utils.A2AMetadataKeys.CUSTOM_METADATA],
|
|
179
|
+
actions: (0, import_event_actions.createEventActions)({
|
|
180
|
+
escalate: !!metadata[import_metadata_converter_utils.A2AMetadataKeys.ESCALATE],
|
|
181
|
+
transferToAgent: metadata[import_metadata_converter_utils.A2AMetadataKeys.TRANSFER_TO_AGENT]
|
|
182
|
+
})
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
function getLongRunningToolIDs(parts) {
|
|
186
|
+
const ids = [];
|
|
187
|
+
for (const a2aPart of parts) {
|
|
188
|
+
if (a2aPart.metadata && a2aPart.metadata[import_metadata_converter_utils.A2AMetadataKeys.IS_LONG_RUNNING]) {
|
|
189
|
+
const genAIPart = (0, import_part_converter_utils.toGenAIPart)(a2aPart);
|
|
190
|
+
if (genAIPart.functionCall && genAIPart.functionCall.id) {
|
|
191
|
+
ids.push(genAIPart.functionCall.id);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return ids;
|
|
196
|
+
}
|
|
197
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
198
|
+
0 && (module.exports = {
|
|
199
|
+
toA2AMessage,
|
|
200
|
+
toAdkEvent
|
|
201
|
+
});
|