@adminforth/agent 1.12.0 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agent/toolCallEvents.ts +41 -1
- package/build.log +1 -1
- package/dist/agent/toolCallEvents.js +29 -1
- package/package.json +1 -1
package/agent/toolCallEvents.ts
CHANGED
|
@@ -20,6 +20,46 @@ export type ToolCallEvent =
|
|
|
20
20
|
|
|
21
21
|
export type ToolCallEventSink = (event: ToolCallEvent) => void;
|
|
22
22
|
|
|
23
|
+
const TOOL_MESSAGE_DEBUG_KEYS = new Set([
|
|
24
|
+
"metadata",
|
|
25
|
+
"additional_kwargs",
|
|
26
|
+
"response_metadata",
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
function getToolCallDebugPayload(outputRecord: Record<string, unknown>) {
|
|
30
|
+
const lcKwargs =
|
|
31
|
+
typeof outputRecord.lc_kwargs === "object" && outputRecord.lc_kwargs !== null
|
|
32
|
+
? outputRecord.lc_kwargs as Record<string, unknown>
|
|
33
|
+
: null;
|
|
34
|
+
|
|
35
|
+
if (lcKwargs && "tool_call_id" in lcKwargs) {
|
|
36
|
+
return lcKwargs;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if ("tool_call_id" in outputRecord) {
|
|
40
|
+
return outputRecord;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function sanitizeToolCallOutputForDebug(output: unknown) {
|
|
47
|
+
if (typeof output !== "object" || output === null) {
|
|
48
|
+
return output;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const outputRecord = output as Record<string, unknown>;
|
|
52
|
+
const debugPayload = getToolCallDebugPayload(outputRecord);
|
|
53
|
+
|
|
54
|
+
if (!debugPayload) {
|
|
55
|
+
return output;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return Object.fromEntries(
|
|
59
|
+
Object.entries(debugPayload).filter(([key]) => !TOOL_MESSAGE_DEBUG_KEYS.has(key)),
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
23
63
|
export function createToolCallTracker(params: {
|
|
24
64
|
emit: ToolCallEventSink;
|
|
25
65
|
toolCallId?: string;
|
|
@@ -45,7 +85,7 @@ export function createToolCallTracker(params: {
|
|
|
45
85
|
toolName: params.toolName,
|
|
46
86
|
phase: "end",
|
|
47
87
|
durationMs: Date.now() - startedAt,
|
|
48
|
-
output: YAML.stringify(output).trimEnd(),
|
|
88
|
+
output: YAML.stringify(sanitizeToolCallOutputForDebug(output)).trimEnd(),
|
|
49
89
|
error: null,
|
|
50
90
|
});
|
|
51
91
|
},
|
package/build.log
CHANGED
|
@@ -31,5 +31,5 @@ custom/skills/fetch_data/SKILL.md
|
|
|
31
31
|
custom/skills/mutate_data/
|
|
32
32
|
custom/skills/mutate_data/SKILL.md
|
|
33
33
|
|
|
34
|
-
sent 180,
|
|
34
|
+
sent 180,294 bytes received 436 bytes 361,460.00 bytes/sec
|
|
35
35
|
total size is 178,505 speedup is 0.99
|
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
2
|
import YAML from "yaml";
|
|
3
3
|
import { serializeUnknownError } from "../apiBasedTools.js";
|
|
4
|
+
const TOOL_MESSAGE_DEBUG_KEYS = new Set([
|
|
5
|
+
"metadata",
|
|
6
|
+
"additional_kwargs",
|
|
7
|
+
"response_metadata",
|
|
8
|
+
]);
|
|
9
|
+
function getToolCallDebugPayload(outputRecord) {
|
|
10
|
+
const lcKwargs = typeof outputRecord.lc_kwargs === "object" && outputRecord.lc_kwargs !== null
|
|
11
|
+
? outputRecord.lc_kwargs
|
|
12
|
+
: null;
|
|
13
|
+
if (lcKwargs && "tool_call_id" in lcKwargs) {
|
|
14
|
+
return lcKwargs;
|
|
15
|
+
}
|
|
16
|
+
if ("tool_call_id" in outputRecord) {
|
|
17
|
+
return outputRecord;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
function sanitizeToolCallOutputForDebug(output) {
|
|
22
|
+
if (typeof output !== "object" || output === null) {
|
|
23
|
+
return output;
|
|
24
|
+
}
|
|
25
|
+
const outputRecord = output;
|
|
26
|
+
const debugPayload = getToolCallDebugPayload(outputRecord);
|
|
27
|
+
if (!debugPayload) {
|
|
28
|
+
return output;
|
|
29
|
+
}
|
|
30
|
+
return Object.fromEntries(Object.entries(debugPayload).filter(([key]) => !TOOL_MESSAGE_DEBUG_KEYS.has(key)));
|
|
31
|
+
}
|
|
4
32
|
export function createToolCallTracker(params) {
|
|
5
33
|
var _a, _b;
|
|
6
34
|
const toolCallId = (_a = params.toolCallId) !== null && _a !== void 0 ? _a : randomUUID();
|
|
@@ -21,7 +49,7 @@ export function createToolCallTracker(params) {
|
|
|
21
49
|
toolName: params.toolName,
|
|
22
50
|
phase: "end",
|
|
23
51
|
durationMs: Date.now() - startedAt,
|
|
24
|
-
output: YAML.stringify(output).trimEnd(),
|
|
52
|
+
output: YAML.stringify(sanitizeToolCallOutputForDebug(output)).trimEnd(),
|
|
25
53
|
error: null,
|
|
26
54
|
});
|
|
27
55
|
},
|