@google/adk 2.1.0 → 2.2.1

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 (166) hide show
  1. package/dist/cjs/a2a/agent_card.js +8 -0
  2. package/dist/cjs/a2a/agent_executor.js +8 -3
  3. package/dist/cjs/a2a/event_converter_utils.js +5 -1
  4. package/dist/cjs/a2a/metadata_converter_utils.js +2 -1
  5. package/dist/cjs/agents/llm_agent.js +15 -1
  6. package/dist/cjs/agents/processors/content_processor_utils.js +10 -2
  7. package/dist/cjs/agents/processors/nl_planning_processor.js +114 -0
  8. package/dist/cjs/artifacts/gcs_artifact_service.js +13 -7
  9. package/dist/cjs/auth/auth_credential.js +12 -2
  10. package/dist/cjs/code_executors/code_execution_utils.js +3 -3
  11. package/dist/cjs/common.js +63 -0
  12. package/dist/cjs/events/abort_events.js +135 -0
  13. package/dist/cjs/events/internal_metadata.js +131 -0
  14. package/dist/cjs/examples/example.js +92 -0
  15. package/dist/cjs/examples/example_util.js +28 -4
  16. package/dist/cjs/examples/index.js +39 -0
  17. package/dist/cjs/examples/vertex_ai_example_store.js +39 -0
  18. package/dist/cjs/index.js +46 -0
  19. package/dist/cjs/memory/vertex_ai_memory_bank_service.js +17 -5
  20. package/dist/cjs/models/base_llm.js +1 -6
  21. package/dist/cjs/models/chrome_prompt_llm.js +16 -2
  22. package/dist/cjs/models/chrome_prompt_utils.js +54 -2
  23. package/dist/cjs/models/gemini_continuation.js +232 -0
  24. package/dist/cjs/models/gemini_llm_connection.js +5 -4
  25. package/dist/cjs/planners/base_planner.js +56 -0
  26. package/dist/cjs/planners/built_in_planner.js +85 -0
  27. package/dist/cjs/planners/plan_re_act_planner.js +172 -0
  28. package/dist/cjs/plugins/base_plugin.js +46 -61
  29. package/dist/cjs/plugins/debug_logging_plugin.js +653 -0
  30. package/dist/cjs/plugins/plugin_manager.js +1 -1
  31. package/dist/cjs/plugins/tool_call_integrity_plugin.js +364 -0
  32. package/dist/cjs/runner/runner.js +17 -3
  33. package/dist/cjs/tools/example_tool.js +1 -1
  34. package/dist/cjs/tools/mcp/mcp_session_manager.js +14 -8
  35. package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +281 -2
  36. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
  37. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +70 -0
  38. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +120 -0
  39. package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -10
  40. package/dist/cjs/tools/openapi_tool/common/common.js +139 -0
  41. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
  42. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/operation_parser.js +73 -13
  43. package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -34
  44. package/dist/cjs/tools/openapi_tool/openapi_toolset.js +14 -2
  45. package/dist/cjs/tools/openapi_tool/rest_api_tool.js +90 -28
  46. package/dist/cjs/tools/skill/skill_toolset.js +2 -0
  47. package/dist/cjs/tools/tool_context.js +41 -0
  48. package/dist/cjs/tools/webmcp/index.js +37 -0
  49. package/dist/cjs/tools/webmcp/webmcp_tool.js +156 -0
  50. package/dist/cjs/tools/webmcp/webmcp_toolset.js +116 -0
  51. package/dist/cjs/tools/webmcp/webmcp_types.js +50 -0
  52. package/dist/cjs/utils/case_utils.js +52 -2
  53. package/dist/cjs/utils/client_labels.js +67 -0
  54. package/dist/cjs/utils/gemini_schema_util.js +103 -3
  55. package/dist/cjs/utils/hash_utils.js +73 -0
  56. package/dist/cjs/utils/live_connection_utils.js +10 -9
  57. package/dist/cjs/utils/model_name.js +17 -2
  58. package/dist/cjs/utils/simple_zod_to_json.js +5 -0
  59. package/dist/cjs/version.js +1 -1
  60. package/dist/esm/a2a/agent_card.js +8 -0
  61. package/dist/esm/a2a/agent_executor.js +8 -3
  62. package/dist/esm/a2a/event_converter_utils.js +5 -1
  63. package/dist/esm/a2a/metadata_converter_utils.js +2 -1
  64. package/dist/esm/agents/llm_agent.js +18 -1
  65. package/dist/esm/agents/processors/content_processor_utils.js +10 -2
  66. package/dist/esm/agents/processors/nl_planning_processor.js +87 -0
  67. package/dist/esm/artifacts/gcs_artifact_service.js +13 -7
  68. package/dist/esm/auth/auth_credential.js +11 -1
  69. package/dist/esm/code_executors/code_execution_utils.js +3 -3
  70. package/dist/esm/common.js +58 -2
  71. package/dist/esm/events/abort_events.js +110 -0
  72. package/dist/esm/events/internal_metadata.js +97 -0
  73. package/dist/esm/examples/example.js +85 -0
  74. package/dist/esm/examples/example_util.js +25 -3
  75. package/dist/esm/examples/index.js +11 -0
  76. package/dist/esm/examples/vertex_ai_example_store.js +11 -0
  77. package/dist/esm/index.js +51 -1
  78. package/dist/esm/memory/vertex_ai_memory_bank_service.js +17 -5
  79. package/dist/esm/models/base_llm.js +2 -7
  80. package/dist/esm/models/chrome_prompt_llm.js +20 -3
  81. package/dist/esm/models/chrome_prompt_utils.js +51 -2
  82. package/dist/esm/models/gemini_continuation.js +205 -0
  83. package/dist/esm/models/gemini_llm_connection.js +6 -5
  84. package/dist/esm/planners/base_planner.js +28 -0
  85. package/dist/esm/planners/built_in_planner.js +57 -0
  86. package/dist/esm/planners/plan_re_act_planner.js +145 -0
  87. package/dist/esm/plugins/base_plugin.js +46 -61
  88. package/dist/esm/plugins/debug_logging_plugin.js +615 -0
  89. package/dist/esm/plugins/plugin_manager.js +1 -1
  90. package/dist/esm/plugins/tool_call_integrity_plugin.js +339 -0
  91. package/dist/esm/runner/runner.js +20 -3
  92. package/dist/esm/tools/example_tool.js +1 -1
  93. package/dist/esm/tools/mcp/mcp_session_manager.js +14 -8
  94. package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +272 -1
  95. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +15 -1
  96. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.js +43 -0
  97. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +93 -0
  98. package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +10 -12
  99. package/dist/esm/tools/openapi_tool/common/common.js +112 -0
  100. package/dist/esm/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.js +11 -6
  101. package/dist/esm/tools/openapi_tool/openapi_spec_parser/operation_parser.js +80 -13
  102. package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +146 -33
  103. package/dist/esm/tools/openapi_tool/openapi_toolset.js +14 -2
  104. package/dist/esm/tools/openapi_tool/rest_api_tool.js +89 -28
  105. package/dist/esm/tools/skill/skill_toolset.js +2 -0
  106. package/dist/esm/tools/tool_context.js +15 -0
  107. package/dist/esm/tools/webmcp/index.js +10 -0
  108. package/dist/esm/tools/webmcp/webmcp_tool.js +131 -0
  109. package/dist/esm/tools/webmcp/webmcp_toolset.js +89 -0
  110. package/dist/esm/tools/webmcp/webmcp_types.js +22 -0
  111. package/dist/esm/utils/case_utils.js +49 -1
  112. package/dist/esm/utils/client_labels.js +65 -0
  113. package/dist/esm/utils/gemini_schema_util.js +102 -3
  114. package/dist/esm/utils/hash_utils.js +45 -0
  115. package/dist/esm/utils/live_connection_utils.js +11 -10
  116. package/dist/esm/utils/model_name.js +15 -2
  117. package/dist/esm/utils/simple_zod_to_json.js +5 -0
  118. package/dist/esm/version.js +1 -1
  119. package/dist/types/agents/llm_agent.d.ts +12 -1
  120. package/dist/types/agents/processors/nl_planning_processor.d.ts +30 -0
  121. package/dist/types/auth/auth_credential.d.ts +9 -0
  122. package/dist/types/common.d.ts +19 -4
  123. package/dist/types/events/abort_events.d.ts +43 -0
  124. package/dist/types/events/internal_metadata.d.ts +78 -0
  125. package/dist/types/examples/base_example_provider.d.ts +2 -2
  126. package/dist/types/examples/example.d.ts +75 -0
  127. package/dist/types/examples/example_util.d.ts +13 -2
  128. package/dist/types/examples/index.d.ts +18 -0
  129. package/dist/types/examples/vertex_ai_example_store.d.ts +7 -0
  130. package/dist/types/index.d.ts +12 -3
  131. package/dist/types/memory/memory_entry.d.ts +15 -0
  132. package/dist/types/memory/vertex_ai_memory_bank_service.d.ts +9 -0
  133. package/dist/types/models/chrome_prompt_utils.d.ts +29 -0
  134. package/dist/types/models/gemini_continuation.d.ts +59 -0
  135. package/dist/types/planners/base_planner.d.ts +50 -0
  136. package/dist/types/planners/built_in_planner.d.ts +53 -0
  137. package/dist/types/planners/plan_re_act_planner.d.ts +21 -0
  138. package/dist/types/plugins/base_plugin.d.ts +52 -52
  139. package/dist/types/plugins/debug_logging_plugin.d.ts +157 -0
  140. package/dist/types/plugins/tool_call_integrity_plugin.d.ts +116 -0
  141. package/dist/types/skills/skill_registry.d.ts +8 -0
  142. package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +110 -1
  143. package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +32 -2
  144. package/dist/types/tools/openapi_tool/auth/credential_exchangers/base_auth_credential_exchanger.d.ts +35 -0
  145. package/dist/types/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.d.ts +54 -0
  146. package/dist/types/tools/openapi_tool/common/common.d.ts +60 -0
  147. package/dist/types/tools/openapi_tool/openapi_spec_parser/openapi_spec_parser.d.ts +7 -0
  148. package/dist/types/tools/openapi_tool/openapi_spec_parser/operation_parser.d.ts +56 -2
  149. package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +73 -5
  150. package/dist/types/tools/openapi_tool/openapi_toolset.d.ts +11 -0
  151. package/dist/types/tools/openapi_tool/rest_api_tool.d.ts +42 -8
  152. package/dist/types/tools/tool_context.d.ts +19 -0
  153. package/dist/types/tools/webmcp/index.d.ts +12 -0
  154. package/dist/types/tools/webmcp/webmcp_tool.d.ts +47 -0
  155. package/dist/types/tools/webmcp/webmcp_toolset.d.ts +67 -0
  156. package/dist/types/tools/webmcp/webmcp_types.d.ts +69 -0
  157. package/dist/types/utils/case_utils.d.ts +36 -0
  158. package/dist/types/utils/client_labels.d.ts +33 -0
  159. package/dist/types/utils/gemini_schema_util.d.ts +13 -0
  160. package/dist/types/utils/hash_utils.d.ts +25 -0
  161. package/dist/types/utils/logger.d.ts +10 -2
  162. package/dist/types/utils/model_name.d.ts +30 -2
  163. package/dist/types/version.d.ts +1 -1
  164. package/dist/web/index_web.js +113 -80
  165. package/dist/web/index_web.js.map +4 -4
  166. package/package.json +8 -2
@@ -0,0 +1,653 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var debug_logging_plugin_exports = {};
37
+ __export(debug_logging_plugin_exports, {
38
+ DebugLoggingPlugin: () => DebugLoggingPlugin,
39
+ isDebugLoggingPlugin: () => isDebugLoggingPlugin
40
+ });
41
+ module.exports = __toCommonJS(debug_logging_plugin_exports);
42
+ var yaml = __toESM(require("js-yaml"), 1);
43
+ var fs = __toESM(require("node:fs"), 1);
44
+ var import_auth_credential = require("../auth/auth_credential.js");
45
+ var import_event = require("../events/event.js");
46
+ var import_state = require("../sessions/state.js");
47
+ var import_logger = require("../utils/logger.js");
48
+ var import_object_notation_utils = require("../utils/object_notation_utils.js");
49
+ var import_base_plugin = require("./base_plugin.js");
50
+ /**
51
+ * @license
52
+ * Copyright 2026 Google LLC
53
+ * SPDX-License-Identifier: Apache-2.0
54
+ */
55
+ var _a, _b;
56
+ const DEBUG_LOGGING_PLUGIN_SYMBOL = /* @__PURE__ */ Symbol.for("google.adk.debugLoggingPlugin");
57
+ const REDACTED = "[REDACTED]";
58
+ const AUTH_CREDENTIAL_TYPES = /* @__PURE__ */ new Set([
59
+ import_auth_credential.AuthCredentialTypes.API_KEY,
60
+ import_auth_credential.AuthCredentialTypes.HTTP,
61
+ import_auth_credential.AuthCredentialTypes.OAUTH2,
62
+ import_auth_credential.AuthCredentialTypes.OPEN_ID_CONNECT,
63
+ import_auth_credential.AuthCredentialTypes.SERVICE_ACCOUNT
64
+ ]);
65
+ const SENSITIVE_KEYS = /* @__PURE__ */ new Set([
66
+ "access_token",
67
+ "api_key",
68
+ "auth_code",
69
+ "auth_response_uri",
70
+ "authorization",
71
+ "client_secret",
72
+ "code_verifier",
73
+ "google_access_id",
74
+ "id_token",
75
+ "password",
76
+ "private_key",
77
+ "private_key_id",
78
+ "proxy_authorization",
79
+ "refresh_token",
80
+ "secret",
81
+ "sig",
82
+ "signature",
83
+ "token",
84
+ "x_amz_credential",
85
+ "x_amz_signature",
86
+ "x_api_key",
87
+ "x_goog_credential",
88
+ "x_goog_security_token",
89
+ "x_goog_signature"
90
+ ]);
91
+ const SENSITIVE_SUBSTRINGS = [
92
+ "api_key",
93
+ "credentials",
94
+ "passwd",
95
+ "password",
96
+ "private_key",
97
+ "secret"
98
+ ];
99
+ const SENSITIVE_SUFFIXES = ["_token"];
100
+ const STATE_PREFIXES = [import_state.State.APP_PREFIX, import_state.State.USER_PREFIX];
101
+ const PRIVATE_KEY_BLOCK = /-----BEGIN [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----|$)/g;
102
+ const OUTPUT_FILE_MODE = 384;
103
+ const MAX_WALK_DEPTH = 20;
104
+ function isSensitiveKey(key) {
105
+ if (typeof key !== "string") {
106
+ return false;
107
+ }
108
+ let normalized = (0, import_object_notation_utils.toSnakeCaseKey)(key);
109
+ if (normalized.startsWith(import_state.State.TEMP_PREFIX)) {
110
+ return true;
111
+ }
112
+ for (const prefix of STATE_PREFIXES) {
113
+ if (normalized.startsWith(prefix)) {
114
+ normalized = normalized.slice(prefix.length);
115
+ break;
116
+ }
117
+ }
118
+ if (SENSITIVE_KEYS.has(normalized) || SENSITIVE_SUFFIXES.some((suffix) => normalized.endsWith(suffix))) {
119
+ return true;
120
+ }
121
+ return SENSITIVE_SUBSTRINGS.some((marker) => normalized.includes(marker));
122
+ }
123
+ __name(isSensitiveKey, "isSensitiveKey");
124
+ function redactPrivateKeys(value) {
125
+ return String(value).replace(PRIVATE_KEY_BLOCK, REDACTED);
126
+ }
127
+ __name(redactPrivateKeys, "redactPrivateKeys");
128
+ function isCredentialObject(obj) {
129
+ var _a2;
130
+ if (typeof obj !== "object" || obj === null) {
131
+ return false;
132
+ }
133
+ const record = obj;
134
+ const authType = (_a2 = record["authType"]) != null ? _a2 : record["auth_type"];
135
+ return typeof authType === "string" && AUTH_CREDENTIAL_TYPES.has(authType);
136
+ }
137
+ __name(isCredentialObject, "isCredentialObject");
138
+ function isDebugLoggingPlugin(obj) {
139
+ return typeof obj === "object" && obj !== null && DEBUG_LOGGING_PLUGIN_SYMBOL in obj && obj[DEBUG_LOGGING_PLUGIN_SYMBOL] === true;
140
+ }
141
+ __name(isDebugLoggingPlugin, "isDebugLoggingPlugin");
142
+ const _DebugLoggingPlugin = class _DebugLoggingPlugin extends (_b = import_base_plugin.BasePlugin, _a = DEBUG_LOGGING_PLUGIN_SYMBOL, _b) {
143
+ constructor(options = {}) {
144
+ var _a2, _b2, _c, _d;
145
+ super((_a2 = options.name) != null ? _a2 : "debug_logging_plugin");
146
+ this[_a] = true;
147
+ this.invocationStates = /* @__PURE__ */ new Map();
148
+ this.warnedAboutOutputMode = false;
149
+ this.outputPath = (_b2 = options.outputPath) != null ? _b2 : "adk_debug.yaml";
150
+ this.includeSessionState = (_c = options.includeSessionState) != null ? _c : true;
151
+ this.includeSystemInstruction = (_d = options.includeSystemInstruction) != null ? _d : true;
152
+ }
153
+ /**
154
+ * Exposes active invocation states for testing and inspection.
155
+ */
156
+ getInvocationState(invocationId) {
157
+ return this.invocationStates.get(invocationId);
158
+ }
159
+ getTimestamp() {
160
+ return (/* @__PURE__ */ new Date()).toISOString();
161
+ }
162
+ /**
163
+ * Serializes a Gemini `Content` object to a dictionary for YAML output.
164
+ */
165
+ serializeContent(content) {
166
+ var _a2, _b2, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
167
+ if (!content) {
168
+ return null;
169
+ }
170
+ const parts = [];
171
+ if (content.parts) {
172
+ for (const part of content.parts) {
173
+ const partData = {};
174
+ if (part.text) {
175
+ partData["text"] = part.text;
176
+ }
177
+ if (part.functionCall) {
178
+ partData["function_call"] = {
179
+ id: (_a2 = part.functionCall.id) != null ? _a2 : null,
180
+ name: (_b2 = part.functionCall.name) != null ? _b2 : null,
181
+ args: this.safeSerialize(part.functionCall.args)
182
+ };
183
+ }
184
+ if (part.functionResponse) {
185
+ partData["function_response"] = {
186
+ id: (_c = part.functionResponse.id) != null ? _c : null,
187
+ name: (_d = part.functionResponse.name) != null ? _d : null,
188
+ response: this.safeSerialize(part.functionResponse.response)
189
+ };
190
+ }
191
+ if (part.inlineData) {
192
+ partData["inline_data"] = {
193
+ mime_type: (_e = part.inlineData.mimeType) != null ? _e : null,
194
+ display_name: (_f = part.inlineData.displayName) != null ? _f : null,
195
+ _data_omitted: true
196
+ };
197
+ }
198
+ if (part.fileData) {
199
+ partData["file_data"] = {
200
+ file_uri: (_g = part.fileData.fileUri) != null ? _g : null,
201
+ mime_type: (_h = part.fileData.mimeType) != null ? _h : null
202
+ };
203
+ }
204
+ if (part.codeExecutionResult) {
205
+ partData["code_execution_result"] = {
206
+ outcome: String((_i = part.codeExecutionResult.outcome) != null ? _i : ""),
207
+ output: (_j = part.codeExecutionResult.output) != null ? _j : null
208
+ };
209
+ }
210
+ if (part.executableCode) {
211
+ partData["executable_code"] = {
212
+ language: String((_k = part.executableCode.language) != null ? _k : ""),
213
+ code: (_l = part.executableCode.code) != null ? _l : null
214
+ };
215
+ }
216
+ if (Object.keys(partData).length > 0) {
217
+ parts.push(partData);
218
+ }
219
+ }
220
+ }
221
+ return {
222
+ role: (_m = content.role) != null ? _m : null,
223
+ parts
224
+ };
225
+ }
226
+ /**
227
+ * Safely serializes an arbitrary value to a YAML/JSON-compatible format with
228
+ * credential, sensitive key, and private key redaction.
229
+ */
230
+ safeSerialize(obj, depth = 0) {
231
+ if (obj === null || obj === void 0) {
232
+ return null;
233
+ }
234
+ if (isCredentialObject(obj)) {
235
+ return REDACTED;
236
+ }
237
+ if (depth > MAX_WALK_DEPTH) {
238
+ return Array.isArray(obj) ? "<list ...>" : "<dict ...>";
239
+ }
240
+ const childDepth = depth + 1;
241
+ if (typeof obj === "string") {
242
+ return redactPrivateKeys(obj);
243
+ }
244
+ if (typeof obj === "number" || typeof obj === "boolean") {
245
+ return obj;
246
+ }
247
+ if (obj instanceof Date) {
248
+ return obj.toISOString();
249
+ }
250
+ if (Buffer.isBuffer(obj) || obj instanceof Uint8Array) {
251
+ return `<bytes: ${obj.byteLength} bytes>`;
252
+ }
253
+ if (Array.isArray(obj)) {
254
+ return obj.map((item) => this.safeSerialize(item, childDepth));
255
+ }
256
+ if (obj instanceof Set) {
257
+ return Array.from(obj).map(
258
+ (item) => this.safeSerialize(item, childDepth)
259
+ );
260
+ }
261
+ if (obj instanceof Map) {
262
+ const result = {};
263
+ for (const [k, v] of obj.entries()) {
264
+ const keyStr = String(k);
265
+ result[keyStr] = isSensitiveKey(keyStr) ? REDACTED : this.safeSerialize(v, childDepth);
266
+ }
267
+ return result;
268
+ }
269
+ if (typeof obj === "object") {
270
+ const result = {};
271
+ for (const [k, v] of Object.entries(obj)) {
272
+ if (v === void 0) {
273
+ continue;
274
+ }
275
+ result[k] = isSensitiveKey(k) ? REDACTED : this.safeSerialize(v, childDepth);
276
+ }
277
+ return result;
278
+ }
279
+ try {
280
+ return String(obj);
281
+ } catch {
282
+ return "<unserializable>";
283
+ }
284
+ }
285
+ addEntry(invocationId, entryType, agentName, data = {}) {
286
+ var _a2;
287
+ const state = this.invocationStates.get(invocationId);
288
+ if (!state) {
289
+ import_logger.logger.warn(
290
+ `No debug state for invocation ${invocationId}, skipping entry`
291
+ );
292
+ return;
293
+ }
294
+ const entry = {
295
+ timestamp: this.getTimestamp(),
296
+ entry_type: entryType,
297
+ invocation_id: invocationId,
298
+ ...agentName !== void 0 ? { agent_name: agentName } : {},
299
+ data: (_a2 = this.safeSerialize(data)) != null ? _a2 : {}
300
+ };
301
+ state.entries.push(entry);
302
+ }
303
+ async onUserMessageCallback({
304
+ invocationContext,
305
+ userMessage
306
+ }) {
307
+ this.addEntry(invocationContext.invocationId, "user_message", void 0, {
308
+ content: this.serializeContent(userMessage)
309
+ });
310
+ return void 0;
311
+ }
312
+ async beforeRunCallback({
313
+ invocationContext
314
+ }) {
315
+ var _a2, _b2;
316
+ const invocationId = invocationContext.invocationId;
317
+ const session = invocationContext.session;
318
+ const state = {
319
+ invocation_id: invocationId,
320
+ session_id: session.id,
321
+ app_name: session.appName,
322
+ ...invocationContext.userId ? { user_id: invocationContext.userId } : {},
323
+ start_time: this.getTimestamp(),
324
+ entries: []
325
+ };
326
+ this.invocationStates.set(invocationId, state);
327
+ this.addEntry(
328
+ invocationId,
329
+ "invocation_start",
330
+ (_a2 = invocationContext.agent) == null ? void 0 : _a2.name,
331
+ {
332
+ branch: (_b2 = invocationContext.branch) != null ? _b2 : null
333
+ }
334
+ );
335
+ return void 0;
336
+ }
337
+ async onEventCallback({
338
+ invocationContext,
339
+ event
340
+ }) {
341
+ var _a2, _b2, _c, _d, _e, _f, _g, _h;
342
+ const invocationId = invocationContext.invocationId;
343
+ const eventData = {
344
+ event_id: event.id,
345
+ author: (_a2 = event.author) != null ? _a2 : null,
346
+ content: this.serializeContent(event.content),
347
+ is_final_response: (0, import_event.isFinalResponse)(event),
348
+ partial: (_b2 = event.partial) != null ? _b2 : null,
349
+ turn_complete: (_c = event.turnComplete) != null ? _c : null,
350
+ branch: (_d = event.branch) != null ? _d : null
351
+ };
352
+ if (event.actions) {
353
+ const actionsData = {};
354
+ if (event.actions.stateDelta && Object.keys(event.actions.stateDelta).length > 0) {
355
+ actionsData["state_delta"] = this.safeSerialize(
356
+ event.actions.stateDelta
357
+ );
358
+ }
359
+ if (event.actions.artifactDelta && Object.keys(event.actions.artifactDelta).length > 0) {
360
+ actionsData["artifact_delta"] = { ...event.actions.artifactDelta };
361
+ }
362
+ if (event.actions.transferToAgent) {
363
+ actionsData["transfer_to_agent"] = event.actions.transferToAgent;
364
+ }
365
+ if (event.actions.escalate) {
366
+ actionsData["escalate"] = event.actions.escalate;
367
+ }
368
+ if (event.actions.requestedAuthConfigs && Object.keys(event.actions.requestedAuthConfigs).length > 0) {
369
+ actionsData["requested_auth_configs"] = Object.keys(
370
+ event.actions.requestedAuthConfigs
371
+ ).length;
372
+ }
373
+ if (Object.keys(actionsData).length > 0) {
374
+ eventData["actions"] = actionsData;
375
+ }
376
+ }
377
+ if (event.groundingMetadata) {
378
+ eventData["has_grounding_metadata"] = true;
379
+ }
380
+ if (event.usageMetadata) {
381
+ eventData["usage_metadata"] = {
382
+ prompt_token_count: (_e = event.usageMetadata.promptTokenCount) != null ? _e : null,
383
+ candidates_token_count: (_f = event.usageMetadata.candidatesTokenCount) != null ? _f : null,
384
+ total_token_count: (_g = event.usageMetadata.totalTokenCount) != null ? _g : null
385
+ };
386
+ }
387
+ if (event.errorCode) {
388
+ eventData["error_code"] = event.errorCode;
389
+ eventData["error_message"] = (_h = event.errorMessage) != null ? _h : null;
390
+ }
391
+ if (event.longRunningToolIds && event.longRunningToolIds.length > 0) {
392
+ eventData["long_running_tool_ids"] = [...event.longRunningToolIds];
393
+ }
394
+ this.addEntry(invocationId, "event", event.author, eventData);
395
+ return void 0;
396
+ }
397
+ async afterRunCallback({
398
+ invocationContext
399
+ }) {
400
+ var _a2, _b2;
401
+ const invocationId = invocationContext.invocationId;
402
+ const state = this.invocationStates.get(invocationId);
403
+ if (!state) {
404
+ import_logger.logger.warn(
405
+ `No debug state for invocation ${invocationId}, skipping write`
406
+ );
407
+ return;
408
+ }
409
+ if (this.includeSessionState) {
410
+ const session = invocationContext.session;
411
+ this.addEntry(invocationId, "session_state_snapshot", void 0, {
412
+ state: this.safeSerialize(session.state),
413
+ event_count: (_b2 = (_a2 = session.events) == null ? void 0 : _a2.length) != null ? _b2 : 0
414
+ });
415
+ }
416
+ this.addEntry(invocationId, "invocation_end");
417
+ let fd;
418
+ try {
419
+ fd = fs.openSync(
420
+ this.outputPath,
421
+ fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_APPEND,
422
+ OUTPUT_FILE_MODE
423
+ );
424
+ if (process.platform !== "win32" && !this.warnedAboutOutputMode && (fs.fstatSync(fd).mode & 63) !== 0) {
425
+ this.warnedAboutOutputMode = true;
426
+ import_logger.logger.warn(
427
+ `Debug output file ${this.outputPath} is readable beyond its owner and holds whole prompts and responses; restrict it to mode 600.`
428
+ );
429
+ }
430
+ const yamlDoc = "---\n" + yaml.dump(state, {
431
+ noRefs: true,
432
+ lineWidth: 120,
433
+ sortKeys: false
434
+ });
435
+ fs.writeFileSync(fd, yamlDoc, { encoding: "utf-8" });
436
+ import_logger.logger.debug(
437
+ `Wrote debug data for invocation ${invocationId} to ${this.outputPath}`
438
+ );
439
+ } catch (e) {
440
+ import_logger.logger.error(`Failed to write debug data: ${e}`);
441
+ } finally {
442
+ if (fd !== void 0) {
443
+ try {
444
+ fs.closeSync(fd);
445
+ } catch {
446
+ }
447
+ }
448
+ this.invocationStates.delete(invocationId);
449
+ }
450
+ }
451
+ async beforeAgentCallback({
452
+ callbackContext
453
+ }) {
454
+ var _a2, _b2;
455
+ this.addEntry(
456
+ callbackContext.invocationId,
457
+ "agent_start",
458
+ callbackContext.agentName,
459
+ {
460
+ branch: (_b2 = (_a2 = callbackContext.invocationContext) == null ? void 0 : _a2.branch) != null ? _b2 : null
461
+ }
462
+ );
463
+ return void 0;
464
+ }
465
+ async afterAgentCallback({
466
+ callbackContext
467
+ }) {
468
+ this.addEntry(
469
+ callbackContext.invocationId,
470
+ "agent_end",
471
+ callbackContext.agentName
472
+ );
473
+ return void 0;
474
+ }
475
+ async beforeModelCallback({
476
+ callbackContext,
477
+ llmRequest
478
+ }) {
479
+ var _a2, _b2, _c, _d;
480
+ const requestData = {
481
+ model: (_a2 = llmRequest.model) != null ? _a2 : null,
482
+ content_count: (_c = (_b2 = llmRequest.contents) == null ? void 0 : _b2.length) != null ? _c : 0,
483
+ contents: ((_d = llmRequest.contents) != null ? _d : []).map(
484
+ (c) => this.serializeContent(c)
485
+ )
486
+ };
487
+ if (llmRequest.toolsDict && Object.keys(llmRequest.toolsDict).length > 0) {
488
+ requestData["tools"] = Object.keys(llmRequest.toolsDict);
489
+ }
490
+ if (llmRequest.config) {
491
+ const config = llmRequest.config;
492
+ const configData = {};
493
+ if (this.includeSystemInstruction && config.systemInstruction) {
494
+ configData["system_instruction"] = config.systemInstruction;
495
+ } else if (config.systemInstruction) {
496
+ if (typeof config.systemInstruction === "string") {
497
+ configData["system_instruction_length"] = config.systemInstruction.length;
498
+ } else {
499
+ configData["has_system_instruction"] = true;
500
+ }
501
+ }
502
+ if (config.temperature !== void 0 && config.temperature !== null) {
503
+ configData["temperature"] = config.temperature;
504
+ }
505
+ if (config.topP !== void 0 && config.topP !== null) {
506
+ configData["top_p"] = config.topP;
507
+ }
508
+ if (config.topK !== void 0 && config.topK !== null) {
509
+ configData["top_k"] = config.topK;
510
+ }
511
+ if (config.maxOutputTokens !== void 0 && config.maxOutputTokens !== null) {
512
+ configData["max_output_tokens"] = config.maxOutputTokens;
513
+ }
514
+ if (config.responseMimeType) {
515
+ configData["response_mime_type"] = config.responseMimeType;
516
+ }
517
+ if (config.responseSchema) {
518
+ configData["has_response_schema"] = true;
519
+ }
520
+ if (Object.keys(configData).length > 0) {
521
+ requestData["config"] = configData;
522
+ }
523
+ }
524
+ this.addEntry(
525
+ callbackContext.invocationId,
526
+ "llm_request",
527
+ callbackContext.agentName,
528
+ requestData
529
+ );
530
+ return void 0;
531
+ }
532
+ async afterModelCallback({
533
+ callbackContext,
534
+ llmResponse
535
+ }) {
536
+ var _a2, _b2, _c, _d, _e, _f, _g;
537
+ const responseData = {
538
+ content: this.serializeContent(llmResponse.content),
539
+ partial: (_a2 = llmResponse.partial) != null ? _a2 : null,
540
+ turn_complete: (_b2 = llmResponse.turnComplete) != null ? _b2 : null
541
+ };
542
+ if (llmResponse.errorCode) {
543
+ responseData["error_code"] = llmResponse.errorCode;
544
+ responseData["error_message"] = (_c = llmResponse.errorMessage) != null ? _c : null;
545
+ }
546
+ if (llmResponse.usageMetadata) {
547
+ responseData["usage_metadata"] = {
548
+ prompt_token_count: (_d = llmResponse.usageMetadata.promptTokenCount) != null ? _d : null,
549
+ candidates_token_count: (_e = llmResponse.usageMetadata.candidatesTokenCount) != null ? _e : null,
550
+ total_token_count: (_f = llmResponse.usageMetadata.totalTokenCount) != null ? _f : null,
551
+ cached_content_token_count: (_g = llmResponse.usageMetadata.cachedContentTokenCount) != null ? _g : null
552
+ };
553
+ }
554
+ if (llmResponse.groundingMetadata) {
555
+ responseData["has_grounding_metadata"] = true;
556
+ }
557
+ if (llmResponse.finishReason) {
558
+ responseData["finish_reason"] = String(llmResponse.finishReason);
559
+ }
560
+ if (llmResponse.modelVersion) {
561
+ responseData["model_version"] = llmResponse.modelVersion;
562
+ }
563
+ this.addEntry(
564
+ callbackContext.invocationId,
565
+ "llm_response",
566
+ callbackContext.agentName,
567
+ responseData
568
+ );
569
+ return void 0;
570
+ }
571
+ async onModelErrorCallback({
572
+ callbackContext,
573
+ llmRequest,
574
+ error
575
+ }) {
576
+ var _a2;
577
+ this.addEntry(
578
+ callbackContext.invocationId,
579
+ "llm_error",
580
+ callbackContext.agentName,
581
+ {
582
+ error_type: error.name || "Error",
583
+ error_message: error.message || String(error),
584
+ model: (_a2 = llmRequest.model) != null ? _a2 : null
585
+ }
586
+ );
587
+ return void 0;
588
+ }
589
+ async beforeToolCallback({
590
+ tool,
591
+ toolArgs,
592
+ toolContext
593
+ }) {
594
+ var _a2;
595
+ this.addEntry(
596
+ toolContext.invocationId,
597
+ "tool_call",
598
+ toolContext.agentName,
599
+ {
600
+ tool_name: tool.name,
601
+ function_call_id: (_a2 = toolContext.functionCallId) != null ? _a2 : null,
602
+ args: this.safeSerialize(toolArgs)
603
+ }
604
+ );
605
+ return void 0;
606
+ }
607
+ async afterToolCallback({
608
+ tool,
609
+ toolContext,
610
+ result
611
+ }) {
612
+ var _a2;
613
+ this.addEntry(
614
+ toolContext.invocationId,
615
+ "tool_response",
616
+ toolContext.agentName,
617
+ {
618
+ tool_name: tool.name,
619
+ function_call_id: (_a2 = toolContext.functionCallId) != null ? _a2 : null,
620
+ result: this.safeSerialize(result)
621
+ }
622
+ );
623
+ return void 0;
624
+ }
625
+ async onToolErrorCallback({
626
+ tool,
627
+ toolArgs,
628
+ toolContext,
629
+ error
630
+ }) {
631
+ var _a2;
632
+ this.addEntry(
633
+ toolContext.invocationId,
634
+ "tool_error",
635
+ toolContext.agentName,
636
+ {
637
+ tool_name: tool.name,
638
+ function_call_id: (_a2 = toolContext.functionCallId) != null ? _a2 : null,
639
+ args: this.safeSerialize(toolArgs),
640
+ error_type: error.name || "Error",
641
+ error_message: error.message || String(error)
642
+ }
643
+ );
644
+ return void 0;
645
+ }
646
+ };
647
+ __name(_DebugLoggingPlugin, "DebugLoggingPlugin");
648
+ let DebugLoggingPlugin = _DebugLoggingPlugin;
649
+ // Annotate the CommonJS export names for ESM import in node:
650
+ 0 && (module.exports = {
651
+ DebugLoggingPlugin,
652
+ isDebugLoggingPlugin
653
+ });
@@ -104,7 +104,7 @@ const _PluginManager = class _PluginManager {
104
104
  } catch (e) {
105
105
  const errorMessage = `Error in plugin '${plugin.name}' during '${callbackName}' callback: ${e}`;
106
106
  import_logger.logger.error(errorMessage);
107
- throw new Error(errorMessage);
107
+ throw new Error(errorMessage, { cause: e });
108
108
  }
109
109
  }
110
110
  return void 0;