@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,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;
|