@google/adk 0.5.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.
Files changed (139) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/a2a/a2a_event.js +53 -26
  3. package/dist/cjs/a2a/a2a_remote_agent.js +174 -0
  4. package/dist/cjs/a2a/a2a_remote_agent_run_processor.js +198 -0
  5. package/dist/cjs/a2a/a2a_remote_agent_utils.js +165 -0
  6. package/dist/cjs/a2a/agent_card.js +380 -0
  7. package/dist/cjs/a2a/agent_executor.js +221 -0
  8. package/dist/cjs/a2a/agent_to_a2a.js +115 -0
  9. package/dist/cjs/a2a/event_processor_utils.js +180 -0
  10. package/dist/cjs/a2a/executor_context.js +1 -1
  11. package/dist/cjs/a2a/metadata_converter_utils.js +1 -0
  12. package/dist/cjs/a2a/part_converter_utils.js +24 -13
  13. package/dist/cjs/agents/llm_agent.js +17 -0
  14. package/dist/cjs/agents/{content_processor_utils.js → processors/content_processor_utils.js} +21 -2
  15. package/dist/cjs/agents/processors/content_request_processor.js +24 -3
  16. package/dist/cjs/agents/processors/context_compactor_request_processor.js +61 -0
  17. package/dist/cjs/agents/processors/instructions_llm_request_processor.js +1 -1
  18. package/dist/cjs/artifacts/file_artifact_service.js +35 -4
  19. package/dist/cjs/common.js +37 -0
  20. package/dist/cjs/context/base_context_compactor.js +27 -0
  21. package/dist/cjs/context/summarizers/base_summarizer.js +27 -0
  22. package/dist/cjs/context/summarizers/llm_summarizer.js +93 -0
  23. package/dist/cjs/context/token_based_context_compactor.js +135 -0
  24. package/dist/cjs/context/truncating_context_compactor.js +58 -0
  25. package/dist/cjs/events/compacted_event.js +53 -0
  26. package/dist/cjs/index.js +38 -14
  27. package/dist/cjs/index.js.map +4 -4
  28. package/dist/cjs/memory/in_memory_memory_service.js +1 -1
  29. package/dist/cjs/runner/runner.js +19 -10
  30. package/dist/cjs/sessions/db/operations.js +4 -14
  31. package/dist/cjs/sessions/state.js +2 -2
  32. package/dist/cjs/tools/agent_tool.js +6 -5
  33. package/dist/cjs/tools/load_artifacts_tool.js +188 -0
  34. package/dist/cjs/tools/load_memory_tool.js +107 -0
  35. package/dist/cjs/tools/preload_memory_tool.js +109 -0
  36. package/dist/cjs/utils/logger.js +1 -0
  37. package/dist/cjs/version.js +1 -1
  38. package/dist/esm/a2a/a2a_event.js +52 -26
  39. package/dist/esm/a2a/a2a_remote_agent.js +148 -0
  40. package/dist/esm/a2a/a2a_remote_agent_run_processor.js +175 -0
  41. package/dist/esm/a2a/a2a_remote_agent_utils.js +131 -0
  42. package/dist/esm/a2a/agent_card.js +340 -0
  43. package/dist/esm/a2a/agent_executor.js +202 -0
  44. package/dist/esm/a2a/agent_to_a2a.js +80 -0
  45. package/dist/esm/a2a/event_processor_utils.js +159 -0
  46. package/dist/esm/a2a/executor_context.js +1 -1
  47. package/dist/esm/a2a/metadata_converter_utils.js +1 -0
  48. package/dist/esm/a2a/part_converter_utils.js +24 -13
  49. package/dist/esm/agents/llm_agent.js +17 -0
  50. package/dist/esm/agents/{content_processor_utils.js → processors/content_processor_utils.js} +23 -2
  51. package/dist/esm/agents/processors/content_request_processor.js +25 -4
  52. package/dist/esm/agents/processors/context_compactor_request_processor.js +31 -0
  53. package/dist/esm/agents/processors/instructions_llm_request_processor.js +1 -1
  54. package/dist/esm/artifacts/file_artifact_service.js +30 -3
  55. package/dist/esm/common.js +33 -1
  56. package/dist/esm/context/base_context_compactor.js +5 -0
  57. package/dist/esm/context/summarizers/base_summarizer.js +5 -0
  58. package/dist/esm/context/summarizers/llm_summarizer.js +65 -0
  59. package/dist/esm/context/token_based_context_compactor.js +105 -0
  60. package/dist/esm/context/truncating_context_compactor.js +28 -0
  61. package/dist/esm/events/compacted_event.js +22 -0
  62. package/dist/esm/index.js +38 -14
  63. package/dist/esm/index.js.map +4 -4
  64. package/dist/esm/memory/in_memory_memory_service.js +1 -1
  65. package/dist/esm/runner/runner.js +17 -9
  66. package/dist/esm/sessions/db/operations.js +4 -14
  67. package/dist/esm/sessions/state.js +2 -2
  68. package/dist/esm/tools/agent_tool.js +6 -5
  69. package/dist/esm/tools/load_artifacts_tool.js +159 -0
  70. package/dist/esm/tools/load_memory_tool.js +78 -0
  71. package/dist/esm/tools/preload_memory_tool.js +80 -0
  72. package/dist/esm/utils/logger.js +1 -0
  73. package/dist/esm/version.js +1 -1
  74. package/dist/types/a2a/a2a_event.d.ts +23 -6
  75. package/dist/types/a2a/a2a_remote_agent.d.ts +63 -0
  76. package/dist/types/a2a/a2a_remote_agent_run_processor.d.ts +31 -0
  77. package/dist/types/a2a/a2a_remote_agent_utils.d.ts +38 -0
  78. package/dist/types/a2a/agent_card.d.ts +23 -0
  79. package/dist/types/a2a/agent_executor.d.ts +52 -0
  80. package/dist/types/a2a/agent_to_a2a.d.ts +45 -0
  81. package/dist/types/a2a/event_processor_utils.d.ts +24 -0
  82. package/dist/types/a2a/executor_context.d.ts +1 -1
  83. package/dist/types/a2a/metadata_converter_utils.d.ts +2 -1
  84. package/dist/types/agents/llm_agent.d.ts +6 -0
  85. package/dist/types/agents/loop_agent.d.ts +1 -1
  86. package/dist/types/agents/{content_processor_utils.d.ts → processors/content_processor_utils.d.ts} +1 -1
  87. package/dist/types/agents/processors/context_compactor_request_processor.d.ts +22 -0
  88. package/dist/types/artifacts/file_artifact_service.d.ts +4 -0
  89. package/dist/types/common.d.ts +16 -1
  90. package/dist/types/context/base_context_compactor.d.ts +24 -0
  91. package/dist/types/context/summarizers/base_summarizer.d.ts +19 -0
  92. package/dist/types/context/summarizers/llm_summarizer.d.ts +23 -0
  93. package/dist/types/context/token_based_context_compactor.d.ts +33 -0
  94. package/dist/types/context/truncating_context_compactor.d.ts +24 -0
  95. package/dist/types/events/compacted_event.d.ts +33 -0
  96. package/dist/types/index.d.ts +8 -0
  97. package/dist/types/runner/runner.d.ts +13 -0
  98. package/dist/types/sessions/db/operations.d.ts +2 -3
  99. package/dist/types/tools/load_artifacts_tool.d.ts +21 -0
  100. package/dist/types/tools/load_memory_tool.d.ts +22 -0
  101. package/dist/types/tools/preload_memory_tool.d.ts +23 -0
  102. package/dist/types/version.d.ts +1 -1
  103. package/dist/web/a2a/a2a_event.js +52 -26
  104. package/dist/web/a2a/a2a_remote_agent.js +193 -0
  105. package/dist/web/a2a/a2a_remote_agent_run_processor.js +175 -0
  106. package/dist/web/a2a/a2a_remote_agent_utils.js +131 -0
  107. package/dist/web/a2a/agent_card.js +340 -0
  108. package/dist/web/a2a/agent_executor.js +216 -0
  109. package/dist/web/a2a/agent_to_a2a.js +80 -0
  110. package/dist/web/a2a/event_processor_utils.js +168 -0
  111. package/dist/web/a2a/executor_context.js +1 -1
  112. package/dist/web/a2a/metadata_converter_utils.js +1 -0
  113. package/dist/web/a2a/part_converter_utils.js +24 -13
  114. package/dist/web/agents/llm_agent.js +17 -0
  115. package/dist/web/agents/{content_processor_utils.js → processors/content_processor_utils.js} +22 -2
  116. package/dist/web/agents/processors/content_request_processor.js +25 -4
  117. package/dist/web/agents/processors/context_compactor_request_processor.js +49 -0
  118. package/dist/web/agents/processors/instructions_llm_request_processor.js +1 -1
  119. package/dist/web/artifacts/file_artifact_service.js +30 -3
  120. package/dist/web/common.js +33 -1
  121. package/dist/web/context/base_context_compactor.js +5 -0
  122. package/dist/web/context/summarizers/base_summarizer.js +5 -0
  123. package/dist/web/context/summarizers/llm_summarizer.js +74 -0
  124. package/dist/web/context/token_based_context_compactor.js +105 -0
  125. package/dist/web/context/truncating_context_compactor.js +28 -0
  126. package/dist/web/events/compacted_event.js +40 -0
  127. package/dist/web/index.js +1 -1
  128. package/dist/web/index.js.map +4 -4
  129. package/dist/web/memory/in_memory_memory_service.js +1 -1
  130. package/dist/web/runner/runner.js +17 -9
  131. package/dist/web/sessions/db/operations.js +4 -14
  132. package/dist/web/sessions/state.js +2 -2
  133. package/dist/web/tools/agent_tool.js +6 -5
  134. package/dist/web/tools/load_artifacts_tool.js +150 -0
  135. package/dist/web/tools/load_memory_tool.js +77 -0
  136. package/dist/web/tools/preload_memory_tool.js +75 -0
  137. package/dist/web/utils/logger.js +1 -0
  138. package/dist/web/version.js +1 -1
  139. package/package.json +6 -4
@@ -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,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
+ });
@@ -40,7 +40,7 @@ function createExecutorContext({
40
40
  return {
41
41
  userId: session.userId,
42
42
  sessionId: session.id,
43
- agentName: session.appName,
43
+ appName: session.appName,
44
44
  readonlyState: session.state,
45
45
  events: session.events,
46
46
  userContent,
@@ -59,6 +59,7 @@ var A2AMetadataKeys = ((A2AMetadataKeys2) => {
59
59
  A2AMetadataKeys2["GROUNDING_METADATA"] = `${ADK_METADATA_KEY_PREFIX}grounding_metadata`;
60
60
  A2AMetadataKeys2["USAGE_METADATA"] = `${ADK_METADATA_KEY_PREFIX}usage_metadata`;
61
61
  A2AMetadataKeys2["CUSTOM_METADATA"] = `${ADK_METADATA_KEY_PREFIX}custom_metadata`;
62
+ A2AMetadataKeys2["VIDEO_METADATA"] = `${ADK_METADATA_KEY_PREFIX}video_metadata`;
62
63
  return A2AMetadataKeys2;
63
64
  })(A2AMetadataKeys || {});
64
65
  var AdkMetadataKeys = ((AdkMetadataKeys2) => {
@@ -73,6 +73,10 @@ function toA2ATextPart(part) {
73
73
  return a2aPart;
74
74
  }
75
75
  function toA2AFilePart(part) {
76
+ const metadata = {};
77
+ if (part.videoMetadata) {
78
+ metadata[import_metadata_converter_utils.A2AMetadataKeys.VIDEO_METADATA] = part.videoMetadata;
79
+ }
76
80
  if (part.fileData) {
77
81
  return {
78
82
  kind: "file",
@@ -80,7 +84,7 @@ function toA2AFilePart(part) {
80
84
  uri: part.fileData.fileUri || "",
81
85
  mimeType: part.fileData.mimeType
82
86
  },
83
- metadata: {}
87
+ metadata
84
88
  };
85
89
  }
86
90
  if (part.inlineData) {
@@ -90,7 +94,7 @@ function toA2AFilePart(part) {
90
94
  bytes: part.inlineData.data || "",
91
95
  mimeType: part.inlineData.mimeType
92
96
  },
93
- metadata: {}
97
+ metadata
94
98
  };
95
99
  }
96
100
  throw new Error(`Not a file part: ${JSON.stringify(part)}`);
@@ -111,7 +115,11 @@ function toA2ADataPart(part, longRunningToolIDs = []) {
111
115
  dataPartType = "code_execution_result" /* CODE_EXEC_RESULT */;
112
116
  data = part.codeExecutionResult;
113
117
  } else {
114
- throw new Error(`Unknown part type: ${JSON.stringify(part)}`);
118
+ return {
119
+ kind: "data",
120
+ data: {},
121
+ metadata: {}
122
+ };
115
123
  }
116
124
  const metadata = {
117
125
  [import_metadata_converter_utils.A2AMetadataKeys.DATA_PART_TYPE]: dataPartType
@@ -155,21 +163,24 @@ function toGenAIPartText(a2aPart) {
155
163
  };
156
164
  }
157
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
+ }
158
171
  if ("bytes" in a2aPart.file) {
159
- return {
160
- inlineData: {
161
- data: a2aPart.file.bytes,
162
- mimeType: a2aPart.file.mimeType || ""
163
- }
172
+ part.inlineData = {
173
+ data: a2aPart.file.bytes,
174
+ mimeType: a2aPart.file.mimeType || ""
164
175
  };
176
+ return part;
165
177
  }
166
178
  if ("uri" in a2aPart.file) {
167
- return {
168
- fileData: {
169
- fileUri: a2aPart.file.uri,
170
- mimeType: a2aPart.file.mimeType || ""
171
- }
179
+ part.fileData = {
180
+ fileUri: a2aPart.file.uri,
181
+ mimeType: a2aPart.file.mimeType || ""
172
182
  };
183
+ return part;
173
184
  }
174
185
  throw new Error(`Not a file part: ${JSON.stringify(a2aPart)}`);
175
186
  }
@@ -43,6 +43,7 @@ var import_agent_transfer_llm_request_processor = require("./processors/agent_tr
43
43
  var import_basic_llm_request_processor = require("./processors/basic_llm_request_processor.js");
44
44
  var import_code_execution_request_processor = require("./processors/code_execution_request_processor.js");
45
45
  var import_content_request_processor = require("./processors/content_request_processor.js");
46
+ var import_context_compactor_request_processor = require("./processors/context_compactor_request_processor.js");
46
47
  var import_identity_llm_request_processor = require("./processors/identity_llm_request_processor.js");
47
48
  var import_instructions_llm_request_processor = require("./processors/instructions_llm_request_processor.js");
48
49
  var import_request_confirmation_llm_request_processor = require("./processors/request_confirmation_llm_request_processor.js");
@@ -95,6 +96,22 @@ class LlmAgent extends (_b = import_base_agent.BaseAgent, _a = LLM_AGENT_SIGNATU
95
96
  import_content_request_processor.CONTENT_REQUEST_PROCESSOR,
96
97
  import_code_execution_request_processor.CODE_EXECUTION_REQUEST_PROCESSOR
97
98
  ];
99
+ if (!config.requestProcessors && config.contextCompactors && config.contextCompactors.length > 0) {
100
+ const contentIndex = this.requestProcessors.indexOf(
101
+ import_content_request_processor.CONTENT_REQUEST_PROCESSOR
102
+ );
103
+ if (contentIndex !== -1) {
104
+ this.requestProcessors.splice(
105
+ contentIndex,
106
+ 0,
107
+ new import_context_compactor_request_processor.ContextCompactorRequestProcessor(config.contextCompactors)
108
+ );
109
+ } else {
110
+ this.requestProcessors.push(
111
+ new import_context_compactor_request_processor.ContextCompactorRequestProcessor(config.contextCompactors)
112
+ );
113
+ }
114
+ }
98
115
  this.responseProcessors = (_h = config.responseProcessors) != null ? _h : [];
99
116
  const agentTransferDisabled = this.disallowTransferToParent && this.disallowTransferToPeers && !((_i = this.subAgents) == null ? void 0 : _i.length);
100
117
  if (!agentTransferDisabled) {
@@ -28,9 +28,11 @@ __export(content_processor_utils_exports, {
28
28
  getCurrentTurnContents: () => getCurrentTurnContents
29
29
  });
30
30
  module.exports = __toCommonJS(content_processor_utils_exports);
31
+ var import_genai = require("@google/genai");
31
32
  var import_lodash_es = require("lodash-es");
32
- var import_event = require("../events/event.js");
33
- var import_functions = require("./functions.js");
33
+ var import_compacted_event = require("../../events/compacted_event.js");
34
+ var import_event = require("../../events/event.js");
35
+ var import_functions = require("../functions.js");
34
36
  /**
35
37
  * @license
36
38
  * Copyright 2025 Google LLC
@@ -40,6 +42,10 @@ function getContents(events, agentName, currentBranch) {
40
42
  var _a, _b, _c;
41
43
  const filteredEvents = [];
42
44
  for (const event of events) {
45
+ if ((0, import_compacted_event.isCompactedEvent)(event)) {
46
+ filteredEvents.push(convertCompactedEvent(event));
47
+ continue;
48
+ }
43
49
  if (!((_a = event.content) == null ? void 0 : _a.role) || ((_c = (_b = event.content.parts) == null ? void 0 : _b[0]) == null ? void 0 : _c.text) === "") {
44
50
  continue;
45
51
  }
@@ -312,6 +318,19 @@ function safeStringify(obj) {
312
318
  return String(obj);
313
319
  }
314
320
  }
321
+ function convertCompactedEvent(event) {
322
+ const content = (0, import_genai.createUserContent)(
323
+ `[Previous Context Summary]:
324
+ ${event.compactedContent}`
325
+ );
326
+ return (0, import_event.createEvent)({
327
+ invocationId: event.invocationId,
328
+ author: "user",
329
+ content,
330
+ branch: event.branch,
331
+ timestamp: event.timestamp
332
+ });
333
+ }
315
334
  // Annotate the CommonJS export names for ESM import in node:
316
335
  0 && (module.exports = {
317
336
  getContents,