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