@google/adk 0.3.0 → 0.5.0

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