@google/adk 2.2.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.
- package/dist/cjs/a2a/event_converter_utils.js +5 -1
- package/dist/cjs/a2a/metadata_converter_utils.js +2 -1
- package/dist/cjs/common.js +18 -0
- package/dist/cjs/events/abort_events.js +135 -0
- package/dist/cjs/events/internal_metadata.js +131 -0
- package/dist/cjs/models/gemini_continuation.js +232 -0
- package/dist/cjs/plugins/debug_logging_plugin.js +653 -0
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/tool_call_integrity_plugin.js +364 -0
- package/dist/cjs/runner/runner.js +17 -3
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/event_converter_utils.js +5 -1
- package/dist/esm/a2a/metadata_converter_utils.js +2 -1
- package/dist/esm/common.js +20 -0
- package/dist/esm/events/abort_events.js +110 -0
- package/dist/esm/events/internal_metadata.js +97 -0
- package/dist/esm/models/gemini_continuation.js +205 -0
- package/dist/esm/plugins/debug_logging_plugin.js +615 -0
- package/dist/esm/plugins/plugin_manager.js +1 -1
- package/dist/esm/plugins/tool_call_integrity_plugin.js +339 -0
- package/dist/esm/runner/runner.js +20 -3
- package/dist/esm/version.js +1 -1
- package/dist/types/common.d.ts +3 -0
- package/dist/types/events/abort_events.d.ts +43 -0
- package/dist/types/events/internal_metadata.d.ts +78 -0
- package/dist/types/models/gemini_continuation.d.ts +59 -0
- package/dist/types/plugins/debug_logging_plugin.d.ts +157 -0
- package/dist/types/plugins/tool_call_integrity_plugin.d.ts +116 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +59 -59
- package/dist/web/index_web.js.map +4 -4
- package/package.json +1 -1
|
@@ -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;
|