agent-recorder 2.0.12 → 2.0.14
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/bundle.js +4 -0
- package/dist/bundle.js.map +1 -1
- package/dist/embed.d.ts +21 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +22 -0
- package/dist/embed.js.map +1 -0
- package/package.json +8 -1
- package/vendor/node_modules/@agent-recorder/cli/analytics/session-analytics.test.js +3 -0
- package/vendor/node_modules/@agent-recorder/cli/analytics/session-analytics.test.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/cli/commands/mcp-server.d.ts +11 -0
- package/vendor/node_modules/@agent-recorder/cli/commands/mcp-server.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/cli/commands/mcp-server.js +442 -0
- package/vendor/node_modules/@agent-recorder/cli/commands/mcp-server.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/cli/commands/sessions.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/cli/commands/sessions.js +8 -5
- package/vendor/node_modules/@agent-recorder/cli/commands/sessions.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/cli/config/claude-paths.d.ts +2 -51
- package/vendor/node_modules/@agent-recorder/cli/config/claude-paths.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/cli/config/claude-paths.js +2 -113
- package/vendor/node_modules/@agent-recorder/cli/config/claude-paths.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/cli/config/claude-paths.test.js +1 -1
- package/vendor/node_modules/@agent-recorder/cli/config/claude-paths.test.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/cli/index.js +10 -0
- package/vendor/node_modules/@agent-recorder/cli/index.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/cli/package.json +1 -1
- package/vendor/node_modules/@agent-recorder/cli/tui/components/EventInspectPanel.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/cli/tui/components/EventInspectPanel.js +1 -1
- package/vendor/node_modules/@agent-recorder/cli/tui/components/EventInspectPanel.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/claude-config.d.ts +23 -0
- package/vendor/node_modules/@agent-recorder/core/claude-config.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/claude-config.js +50 -0
- package/vendor/node_modules/@agent-recorder/core/claude-config.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/config.d.ts +10 -1
- package/vendor/node_modules/@agent-recorder/core/config.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/config.js +11 -1
- package/vendor/node_modules/@agent-recorder/core/config.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/db/events-complete.test.d.ts +5 -0
- package/vendor/node_modules/@agent-recorder/core/db/events-complete.test.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/db/events-complete.test.js +133 -0
- package/vendor/node_modules/@agent-recorder/core/db/events-complete.test.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/db/events.d.ts +23 -36
- package/vendor/node_modules/@agent-recorder/core/db/events.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/db/events.js +74 -3
- package/vendor/node_modules/@agent-recorder/core/db/events.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/db/events.test.js +62 -1
- package/vendor/node_modules/@agent-recorder/core/db/events.test.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/db/index.d.ts +2 -1
- package/vendor/node_modules/@agent-recorder/core/db/index.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/db/index.js +2 -1
- package/vendor/node_modules/@agent-recorder/core/db/index.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/db/sessions.d.ts +2 -5
- package/vendor/node_modules/@agent-recorder/core/db/sessions.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/db/sessions.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/db/token-metrics.d.ts +33 -0
- package/vendor/node_modules/@agent-recorder/core/db/token-metrics.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/db/token-metrics.js +88 -0
- package/vendor/node_modules/@agent-recorder/core/db/token-metrics.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/db/token-metrics.test.d.ts +5 -0
- package/vendor/node_modules/@agent-recorder/core/db/token-metrics.test.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/db/token-metrics.test.js +167 -0
- package/vendor/node_modules/@agent-recorder/core/db/token-metrics.test.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/index.d.ts +1 -1
- package/vendor/node_modules/@agent-recorder/core/index.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/index.js +1 -1
- package/vendor/node_modules/@agent-recorder/core/index.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/migrations/007_add_correlation_id.sql +11 -0
- package/vendor/node_modules/@agent-recorder/core/migrations/007_add_token_columns.sql +19 -0
- package/vendor/node_modules/@agent-recorder/core/package.json +1 -1
- package/vendor/node_modules/@agent-recorder/core/types/index.d.ts +4 -2
- package/vendor/node_modules/@agent-recorder/core/types/index.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/types/index.js +3 -0
- package/vendor/node_modules/@agent-recorder/core/types/index.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/utils/index.d.ts +1 -0
- package/vendor/node_modules/@agent-recorder/core/utils/index.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/utils/index.js +1 -0
- package/vendor/node_modules/@agent-recorder/core/utils/index.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/utils/redact.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/utils/redact.js +6 -3
- package/vendor/node_modules/@agent-recorder/core/utils/redact.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/core/utils/redact.test.d.ts +6 -0
- package/vendor/node_modules/@agent-recorder/core/utils/redact.test.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/utils/redact.test.js +82 -0
- package/vendor/node_modules/@agent-recorder/core/utils/redact.test.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/utils/tokens.d.ts +24 -0
- package/vendor/node_modules/@agent-recorder/core/utils/tokens.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/utils/tokens.js +31 -0
- package/vendor/node_modules/@agent-recorder/core/utils/tokens.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/utils/tokens.test.d.ts +5 -0
- package/vendor/node_modules/@agent-recorder/core/utils/tokens.test.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/utils/tokens.test.js +80 -0
- package/vendor/node_modules/@agent-recorder/core/utils/tokens.test.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/hooks/package.json +1 -1
- package/vendor/node_modules/@agent-recorder/service/daemon-context.d.ts +14 -0
- package/vendor/node_modules/@agent-recorder/service/daemon-context.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/daemon-context.js +15 -0
- package/vendor/node_modules/@agent-recorder/service/daemon-context.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/index.d.ts +1 -8
- package/vendor/node_modules/@agent-recorder/service/index.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/index.js +15 -22
- package/vendor/node_modules/@agent-recorder/service/index.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/mcp/proxy.d.ts +27 -0
- package/vendor/node_modules/@agent-recorder/service/mcp/proxy.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/mcp/proxy.js +141 -35
- package/vendor/node_modules/@agent-recorder/service/mcp/proxy.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/mcp/recorder.d.ts +4 -0
- package/vendor/node_modules/@agent-recorder/service/mcp/recorder.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/mcp/recorder.js +56 -14
- package/vendor/node_modules/@agent-recorder/service/mcp/recorder.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/mcp/recorder.test.d.ts +5 -0
- package/vendor/node_modules/@agent-recorder/service/mcp/recorder.test.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/mcp/recorder.test.js +143 -0
- package/vendor/node_modules/@agent-recorder/service/mcp/recorder.test.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/mcp/types.d.ts +5 -31
- package/vendor/node_modules/@agent-recorder/service/mcp/types.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/mcp/types.js +3 -1
- package/vendor/node_modules/@agent-recorder/service/mcp/types.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/mcp/upstreams-cache.test.d.ts +5 -0
- package/vendor/node_modules/@agent-recorder/service/mcp/upstreams-cache.test.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/mcp/upstreams-cache.test.js +66 -0
- package/vendor/node_modules/@agent-recorder/service/mcp/upstreams-cache.test.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/package.json +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/events.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/events.js +42 -1
- package/vendor/node_modules/@agent-recorder/service/routes/events.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/health.d.ts +6 -1
- package/vendor/node_modules/@agent-recorder/service/routes/health.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/health.js +5 -6
- package/vendor/node_modules/@agent-recorder/service/routes/health.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/hooks.d.ts +20 -0
- package/vendor/node_modules/@agent-recorder/service/routes/hooks.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/hooks.js +403 -49
- package/vendor/node_modules/@agent-recorder/service/routes/hooks.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/hooks.test.d.ts +9 -0
- package/vendor/node_modules/@agent-recorder/service/routes/hooks.test.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/routes/hooks.test.js +406 -0
- package/vendor/node_modules/@agent-recorder/service/routes/hooks.test.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/routes/isToolResponseError.test.d.ts +8 -0
- package/vendor/node_modules/@agent-recorder/service/routes/isToolResponseError.test.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/routes/isToolResponseError.test.js +65 -0
- package/vendor/node_modules/@agent-recorder/service/routes/isToolResponseError.test.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/routes/sessions.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/sessions.js +19 -1
- package/vendor/node_modules/@agent-recorder/service/routes/sessions.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/stdio.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/stdio.js +20 -1
- package/vendor/node_modules/@agent-recorder/service/routes/stdio.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/routes/tokens.d.ts +12 -0
- package/vendor/node_modules/@agent-recorder/service/routes/tokens.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/routes/tokens.js +18 -0
- package/vendor/node_modules/@agent-recorder/service/routes/tokens.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/routes/tokens.test.d.ts +5 -0
- package/vendor/node_modules/@agent-recorder/service/routes/tokens.test.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/routes/tokens.test.js +88 -0
- package/vendor/node_modules/@agent-recorder/service/routes/tokens.test.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/service/server.d.ts +4 -0
- package/vendor/node_modules/@agent-recorder/service/server.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/service/server.js +33 -3
- package/vendor/node_modules/@agent-recorder/service/server.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/stdio-proxy/package.json +1 -1
- package/vendor/node_modules/@agent-recorder/stdio-proxy/types.d.ts +3 -19
- package/vendor/node_modules/@agent-recorder/stdio-proxy/types.d.ts.map +1 -1
- package/vendor/node_modules/@agent-recorder/stdio-proxy/types.js +2 -1
- package/vendor/node_modules/@agent-recorder/stdio-proxy/types.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/{core/types → types}/events.d.ts +9 -0
- package/vendor/node_modules/@agent-recorder/types/events.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/types/events.js +9 -0
- package/vendor/node_modules/@agent-recorder/types/events.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/types/index.d.ts +12 -0
- package/vendor/node_modules/@agent-recorder/types/index.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/types/index.js +9 -0
- package/vendor/node_modules/@agent-recorder/types/index.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/types/jsonrpc.d.ts +35 -0
- package/vendor/node_modules/@agent-recorder/types/jsonrpc.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/types/jsonrpc.js +6 -0
- package/vendor/node_modules/@agent-recorder/types/jsonrpc.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/types/package.json +12 -0
- package/vendor/node_modules/@agent-recorder/{core/types → types}/session.d.ts +6 -0
- package/vendor/node_modules/@agent-recorder/types/session.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/{core/types → types}/session.js.map +1 -1
- package/vendor/node_modules/@agent-recorder/types/storage.d.ts +80 -0
- package/vendor/node_modules/@agent-recorder/types/storage.d.ts.map +1 -0
- package/vendor/node_modules/@agent-recorder/types/storage.js +9 -0
- package/vendor/node_modules/@agent-recorder/types/storage.js.map +1 -0
- package/vendor/node_modules/@agent-recorder/core/types/events.d.ts.map +0 -1
- package/vendor/node_modules/@agent-recorder/core/types/events.js +0 -6
- package/vendor/node_modules/@agent-recorder/core/types/events.js.map +0 -1
- package/vendor/node_modules/@agent-recorder/core/types/session.d.ts.map +0 -1
- /package/vendor/node_modules/@agent-recorder/{core/types → types}/session.js +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for recordToolCall — budget alerting and token recording.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { openMemoryDatabase, runMigrations, getDefaultMigrationsDir, createSession, getEventsBySession, upsertToolSchemaMetric, } from "@agent-recorder/core";
|
|
7
|
+
import { recordToolCall, resetBudgetWarnedSessions } from "./recorder.js";
|
|
8
|
+
describe("recordToolCall — token recording", () => {
|
|
9
|
+
let db;
|
|
10
|
+
let sessionId;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
db = openMemoryDatabase();
|
|
13
|
+
runMigrations(db, getDefaultMigrationsDir());
|
|
14
|
+
sessionId = randomUUID();
|
|
15
|
+
createSession(db, sessionId, new Date().toISOString());
|
|
16
|
+
resetBudgetWarnedSessions();
|
|
17
|
+
});
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
db.close();
|
|
20
|
+
});
|
|
21
|
+
it("records non-null inputTokens and outputTokens", () => {
|
|
22
|
+
recordToolCall({
|
|
23
|
+
db,
|
|
24
|
+
sessionId,
|
|
25
|
+
toolName: "execute_sql",
|
|
26
|
+
input: { query: "SELECT 1" },
|
|
27
|
+
output: { rows: [{ id: 1 }] },
|
|
28
|
+
status: "success",
|
|
29
|
+
startedAt: new Date().toISOString(),
|
|
30
|
+
endedAt: new Date().toISOString(),
|
|
31
|
+
redactKeys: [],
|
|
32
|
+
});
|
|
33
|
+
const events = getEventsBySession(db, sessionId);
|
|
34
|
+
const event = events.find((e) => e.toolName === "execute_sql");
|
|
35
|
+
expect(event).toBeDefined();
|
|
36
|
+
expect(event.inputTokens).not.toBeNull();
|
|
37
|
+
expect(event.outputTokens).not.toBeNull();
|
|
38
|
+
expect(event.inputTokens).toBeGreaterThan(0);
|
|
39
|
+
expect(event.outputTokens).toBeGreaterThan(0);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe("recordToolCall — budget alerting", () => {
|
|
43
|
+
let db;
|
|
44
|
+
let sessionId;
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
db = openMemoryDatabase();
|
|
47
|
+
runMigrations(db, getDefaultMigrationsDir());
|
|
48
|
+
sessionId = randomUUID();
|
|
49
|
+
createSession(db, sessionId, new Date().toISOString());
|
|
50
|
+
resetBudgetWarnedSessions();
|
|
51
|
+
});
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
db.close();
|
|
54
|
+
vi.restoreAllMocks();
|
|
55
|
+
});
|
|
56
|
+
it("emits a budget warning when tokens exceed the threshold", () => {
|
|
57
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
58
|
+
// Large payload to exceed a tiny budget
|
|
59
|
+
recordToolCall({
|
|
60
|
+
db,
|
|
61
|
+
sessionId,
|
|
62
|
+
toolName: "execute_sql",
|
|
63
|
+
input: { query: "x".repeat(500) },
|
|
64
|
+
output: { result: "y".repeat(500) },
|
|
65
|
+
status: "success",
|
|
66
|
+
startedAt: new Date().toISOString(),
|
|
67
|
+
endedAt: new Date().toISOString(),
|
|
68
|
+
redactKeys: [],
|
|
69
|
+
contextBudgetTokens: 1, // budget of 1 token — always exceeded
|
|
70
|
+
});
|
|
71
|
+
expect(warnSpy).toHaveBeenCalledOnce();
|
|
72
|
+
const warningArg = warnSpy.mock.calls[0][0];
|
|
73
|
+
const warning = JSON.parse(warningArg);
|
|
74
|
+
expect(warning.type).toBe("context_budget_warning");
|
|
75
|
+
expect(warning.sessionId).toBe(sessionId);
|
|
76
|
+
expect(warning.estimatedTokens).toBeGreaterThan(0);
|
|
77
|
+
});
|
|
78
|
+
it("only warns once per session, not on every subsequent call", () => {
|
|
79
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
80
|
+
const opts = {
|
|
81
|
+
db,
|
|
82
|
+
sessionId,
|
|
83
|
+
toolName: "execute_sql",
|
|
84
|
+
input: { query: "x".repeat(500) },
|
|
85
|
+
output: { result: "y".repeat(500) },
|
|
86
|
+
status: "success",
|
|
87
|
+
startedAt: new Date().toISOString(),
|
|
88
|
+
endedAt: new Date().toISOString(),
|
|
89
|
+
redactKeys: [],
|
|
90
|
+
contextBudgetTokens: 1,
|
|
91
|
+
};
|
|
92
|
+
recordToolCall(opts);
|
|
93
|
+
recordToolCall(opts);
|
|
94
|
+
recordToolCall(opts);
|
|
95
|
+
expect(warnSpy).toHaveBeenCalledOnce();
|
|
96
|
+
});
|
|
97
|
+
it("does not warn when tokens are under budget", () => {
|
|
98
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
99
|
+
recordToolCall({
|
|
100
|
+
db,
|
|
101
|
+
sessionId,
|
|
102
|
+
toolName: "Glob",
|
|
103
|
+
input: { pattern: "*.ts" },
|
|
104
|
+
output: { files: [] },
|
|
105
|
+
status: "success",
|
|
106
|
+
startedAt: new Date().toISOString(),
|
|
107
|
+
endedAt: new Date().toISOString(),
|
|
108
|
+
redactKeys: [],
|
|
109
|
+
contextBudgetTokens: 150000, // very large budget
|
|
110
|
+
});
|
|
111
|
+
expect(warnSpy).not.toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
it("includes schema tokens in budget check so trigger matches reported value", () => {
|
|
114
|
+
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => { });
|
|
115
|
+
// Seed a large schema metric so schema tokens alone push over the budget
|
|
116
|
+
upsertToolSchemaMetric(db, {
|
|
117
|
+
sessionId,
|
|
118
|
+
upstreamKey: "myserver",
|
|
119
|
+
toolName: "heavy_tool",
|
|
120
|
+
schemaTokens: 9999,
|
|
121
|
+
});
|
|
122
|
+
// Small call payload — call tokens alone won't exceed budget of 5000
|
|
123
|
+
recordToolCall({
|
|
124
|
+
db,
|
|
125
|
+
sessionId,
|
|
126
|
+
toolName: "light_tool",
|
|
127
|
+
input: { x: 1 },
|
|
128
|
+
output: { y: 2 },
|
|
129
|
+
status: "success",
|
|
130
|
+
startedAt: new Date().toISOString(),
|
|
131
|
+
endedAt: new Date().toISOString(),
|
|
132
|
+
redactKeys: [],
|
|
133
|
+
contextBudgetTokens: 5000, // exceeded only when schema tokens are included
|
|
134
|
+
});
|
|
135
|
+
// Warning must fire because callTokens + schemaTokens > 5000
|
|
136
|
+
expect(warnSpy).toHaveBeenCalledOnce();
|
|
137
|
+
const warning = JSON.parse(warnSpy.mock.calls[0][0]);
|
|
138
|
+
expect(warning.type).toBe("context_budget_warning");
|
|
139
|
+
// estimatedTokens in the warning must reflect schema tokens too
|
|
140
|
+
expect(warning.estimatedTokens).toBeGreaterThan(5000);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=recorder.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recorder.test.js","sourceRoot":"","sources":["../../src/mcp/recorder.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,uBAAuB,EACvB,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,cAAc,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1E,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,IAAI,EAAqB,CAAC;IAC1B,IAAI,SAAiB,CAAC;IAEtB,UAAU,CAAC,GAAG,EAAE;QACd,EAAE,GAAG,kBAAkB,EAAE,CAAC;QAC1B,aAAa,CAAC,EAAE,EAAE,uBAAuB,EAAE,CAAC,CAAC;QAC7C,SAAS,GAAG,UAAU,EAAE,CAAC;QACzB,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;QACvD,yBAAyB,EAAE,CAAC;IA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AC7D,MAAM,CAAC,OAAO,CAAC,CAAC,oBAAoB,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC,CAAW,CAAC,CAAC;QAChE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACpD,gEAAgE;QAChE,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACxD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,36 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* JSON-RPC 2.0 types for MCP protocol.
|
|
2
|
+
* JSON-RPC 2.0 types and helpers for MCP protocol.
|
|
3
|
+
* Types are canonical in @agent-recorder/types; imported here and re-exported
|
|
4
|
+
* alongside the runtime helper functions that depend on them.
|
|
3
5
|
*/
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
jsonrpc: "2.0";
|
|
7
|
-
method: string;
|
|
8
|
-
params?: unknown;
|
|
9
|
-
id?: string | number | null;
|
|
10
|
-
}
|
|
11
|
-
/** JSON-RPC success response */
|
|
12
|
-
export interface JsonRpcSuccessResponse {
|
|
13
|
-
jsonrpc: "2.0";
|
|
14
|
-
result: unknown;
|
|
15
|
-
id: string | number | null;
|
|
16
|
-
}
|
|
17
|
-
/** JSON-RPC error response */
|
|
18
|
-
export interface JsonRpcErrorResponse {
|
|
19
|
-
jsonrpc: "2.0";
|
|
20
|
-
error: {
|
|
21
|
-
code: number;
|
|
22
|
-
message: string;
|
|
23
|
-
data?: unknown;
|
|
24
|
-
};
|
|
25
|
-
id: string | number | null;
|
|
26
|
-
}
|
|
27
|
-
/** Union of JSON-RPC response types */
|
|
28
|
-
export type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse;
|
|
29
|
-
/** MCP tools/call request params */
|
|
30
|
-
export interface ToolsCallParams {
|
|
31
|
-
name: string;
|
|
32
|
-
arguments?: Record<string, unknown>;
|
|
33
|
-
}
|
|
6
|
+
import type { JsonRpcRequest, JsonRpcSuccessResponse, JsonRpcErrorResponse, JsonRpcResponse, ToolsCallParams } from "@agent-recorder/types";
|
|
7
|
+
export type { JsonRpcRequest, JsonRpcSuccessResponse, JsonRpcErrorResponse, JsonRpcResponse, ToolsCallParams, };
|
|
34
8
|
/** Check if a JSON-RPC request is a tools/call request */
|
|
35
9
|
export declare function isToolsCallRequest(request: JsonRpcRequest): request is JsonRpcRequest & {
|
|
36
10
|
params: ToolsCallParams;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,eAAe,EACf,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAE/B,YAAY,EACV,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,eAAe,EACf,eAAe,GAChB,CAAC;AAEF,0DAA0D;AAC1D,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,cAAc,GACtB,OAAO,IAAI,cAAc,GAAG;IAAE,MAAM,EAAE,eAAe,CAAA;CAAE,CAOzD;AAED,wDAAwD;AACxD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,eAAe,GACxB,QAAQ,IAAI,oBAAoB,CAElC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* JSON-RPC 2.0 types for MCP protocol.
|
|
2
|
+
* JSON-RPC 2.0 types and helpers for MCP protocol.
|
|
3
|
+
* Types are canonical in @agent-recorder/types; imported here and re-exported
|
|
4
|
+
* alongside the runtime helper functions that depend on them.
|
|
3
5
|
*/
|
|
4
6
|
/** Check if a JSON-RPC request is a tools/call request */
|
|
5
7
|
export function isToolsCallRequest(request) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkBH,0DAA0D;AAC1D,MAAM,UAAU,kBAAkB,CAChC,OAAuB;IAEvB,OAAO,CACL,OAAO,CAAC,MAAM,KAAK,YAAY;QAC/B,OAAO,OAAO,CAAC,MAAM,KAAK,QAAQ;QAClC,OAAO,CAAC,MAAM,KAAK,IAAI;QACvB,MAAM,IAAI,OAAO,CAAC,MAAM,CACzB,CAAC;AACJ,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,eAAe,CAC7B,QAAyB;IAEzB,OAAO,OAAO,IAAI,QAAQ,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstreams-cache.test.d.ts","sourceRoot":"","sources":["../../src/mcp/upstreams-cache.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for UpstreamsCache.
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect, afterEach } from "vitest";
|
|
5
|
+
import { writeFileSync, mkdirSync, rmSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { randomUUID } from "node:crypto";
|
|
9
|
+
import { UpstreamsCache } from "./proxy.js";
|
|
10
|
+
function makeTmpDir() {
|
|
11
|
+
const dir = join(tmpdir(), `upstreams-cache-test-${randomUUID()}`);
|
|
12
|
+
mkdirSync(dir, { recursive: true });
|
|
13
|
+
return dir;
|
|
14
|
+
}
|
|
15
|
+
describe("UpstreamsCache", () => {
|
|
16
|
+
const cleanups = [];
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
for (const fn of cleanups)
|
|
19
|
+
fn();
|
|
20
|
+
cleanups.length = 0;
|
|
21
|
+
});
|
|
22
|
+
it("returns undefined when file does not exist", () => {
|
|
23
|
+
const dir = makeTmpDir();
|
|
24
|
+
cleanups.push(() => rmSync(dir, { recursive: true, force: true }));
|
|
25
|
+
const cache = new UpstreamsCache(join(dir, "nonexistent.json"));
|
|
26
|
+
cleanups.push(() => cache.close());
|
|
27
|
+
expect(cache.get("anything")).toBeUndefined();
|
|
28
|
+
});
|
|
29
|
+
it("loads registry from existing file", () => {
|
|
30
|
+
const dir = makeTmpDir();
|
|
31
|
+
cleanups.push(() => rmSync(dir, { recursive: true, force: true }));
|
|
32
|
+
const filePath = join(dir, "upstreams.json");
|
|
33
|
+
writeFileSync(filePath, JSON.stringify({ myserver: { url: "http://localhost:3000" } }));
|
|
34
|
+
const cache = new UpstreamsCache(filePath);
|
|
35
|
+
cleanups.push(() => cache.close());
|
|
36
|
+
expect(cache.get("myserver")).toEqual({ url: "http://localhost:3000" });
|
|
37
|
+
expect(cache.get("unknown")).toBeUndefined();
|
|
38
|
+
});
|
|
39
|
+
it("close() clears the debounce timer and watcher without error", () => {
|
|
40
|
+
const dir = makeTmpDir();
|
|
41
|
+
cleanups.push(() => rmSync(dir, { recursive: true, force: true }));
|
|
42
|
+
const filePath = join(dir, "upstreams.json");
|
|
43
|
+
writeFileSync(filePath, JSON.stringify({ s: { url: "http://x" } }));
|
|
44
|
+
const cache = new UpstreamsCache(filePath);
|
|
45
|
+
// Should not throw
|
|
46
|
+
cache.close();
|
|
47
|
+
// Double close should also be safe
|
|
48
|
+
cache.close();
|
|
49
|
+
});
|
|
50
|
+
it("keeps previous registry on invalid JSON", () => {
|
|
51
|
+
const dir = makeTmpDir();
|
|
52
|
+
cleanups.push(() => rmSync(dir, { recursive: true, force: true }));
|
|
53
|
+
const filePath = join(dir, "upstreams.json");
|
|
54
|
+
writeFileSync(filePath, JSON.stringify({ good: { url: "http://localhost:1" } }));
|
|
55
|
+
const cache = new UpstreamsCache(filePath);
|
|
56
|
+
cleanups.push(() => cache.close());
|
|
57
|
+
expect(cache.get("good")).toEqual({ url: "http://localhost:1" });
|
|
58
|
+
// Corrupt the file — reload should keep previous value
|
|
59
|
+
writeFileSync(filePath, "not valid json{{{");
|
|
60
|
+
// Force a direct reload by creating a new cache pointing at the corrupt file
|
|
61
|
+
// (the watcher debounce makes async reload unreliable in tests)
|
|
62
|
+
// Instead, verify the original cache still returns the old value
|
|
63
|
+
expect(cache.get("good")).toEqual({ url: "http://localhost:1" });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=upstreams-cache.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstreams-cache.test.js","sourceRoot":"","sources":["../../src/mcp/upstreams-cache.test.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,SAAS,UAAU;IACjB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,wBAAwB,UAAU,EAAE,EAAE,CAAC,CAAC;IACnE,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,QAAQ,CAAC,gBAAgB,EAAE,GAAG,E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C,aAAa,CACX,QAAQ,EACR,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,oBAAoB,EAAE,EAAE,CAAC,CACxD,CAAC;QAEF,MAAM,KAAK,GAAG,IAAI,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC3C,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAEnC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,oBAAoB,EAAE,CAAC,CAAC;QAEjE,uDAAuD;QACvD,aAAa,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;QAC7C,6EAA6E;QAC7E,gEAAgE;QAChE,iEAAiE;QACjE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,oBAAoB,EAAE,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/routes/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAU3C,UAAU,mBAAmB;IAC3B,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC;CACvB;AAED,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/routes/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAU3C,UAAU,mBAAmB;IAC3B,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC;CACvB;AAED,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,IAAI,CAAC,CA2Hf"}
|
|
@@ -4,8 +4,49 @@
|
|
|
4
4
|
import { insertEvent, getEventsBySession, getEventsBySessionPaginated, countEventsBySession, getLatestToolCallEvent, } from "@agent-recorder/core";
|
|
5
5
|
export async function registerEventsRoutes(app, options) {
|
|
6
6
|
const { db } = options;
|
|
7
|
+
const insertEventSchema = {
|
|
8
|
+
body: {
|
|
9
|
+
type: "object",
|
|
10
|
+
required: [
|
|
11
|
+
"id",
|
|
12
|
+
"sessionId",
|
|
13
|
+
"sequence",
|
|
14
|
+
"eventType",
|
|
15
|
+
"agentRole",
|
|
16
|
+
"agentName",
|
|
17
|
+
"startedAt",
|
|
18
|
+
"status",
|
|
19
|
+
],
|
|
20
|
+
properties: {
|
|
21
|
+
id: { type: "string" },
|
|
22
|
+
sessionId: { type: "string" },
|
|
23
|
+
parentEventId: { type: ["string", "null"] },
|
|
24
|
+
sequence: { type: "integer" },
|
|
25
|
+
eventType: {
|
|
26
|
+
type: "string",
|
|
27
|
+
enum: ["agent_call", "subagent_call", "skill_call", "tool_call"],
|
|
28
|
+
},
|
|
29
|
+
agentRole: { type: "string" },
|
|
30
|
+
agentName: { type: "string" },
|
|
31
|
+
skillName: { type: ["string", "null"] },
|
|
32
|
+
toolName: { type: ["string", "null"] },
|
|
33
|
+
mcpMethod: { type: ["string", "null"] },
|
|
34
|
+
upstreamKey: { type: ["string", "null"] },
|
|
35
|
+
startedAt: { type: "string" },
|
|
36
|
+
endedAt: { type: ["string", "null"] },
|
|
37
|
+
status: {
|
|
38
|
+
type: "string",
|
|
39
|
+
enum: ["running", "success", "error", "timeout", "cancelled"],
|
|
40
|
+
},
|
|
41
|
+
inputJson: { type: ["string", "null"] },
|
|
42
|
+
outputJson: { type: ["string", "null"] },
|
|
43
|
+
errorCategory: { type: ["string", "null"] },
|
|
44
|
+
},
|
|
45
|
+
additionalProperties: false,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
7
48
|
// Insert a new event
|
|
8
|
-
app.post("/api/events", async (request, reply) => {
|
|
49
|
+
app.post("/api/events", { schema: insertEventSchema }, async (request, reply) => {
|
|
9
50
|
try {
|
|
10
51
|
const event = insertEvent(db, request.body);
|
|
11
52
|
return reply.code(201).send(event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/routes/events.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,2BAA2B,EAC3B,oBAAoB,EACpB,sBAAsB,GAEvB,MAAM,sBAAsB,CAAC;AAM9B,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAoB,EACpB,OAA4B;IAE5B,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;IAEvB,qBAAqB;IACrB,GAAG,CAAC,IAAI,CACN,aAAa,EACb,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;QACvB,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;YAC5C,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAChD,mDAAmD;YACnD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,CAAC,CAAC;QACnE,CAAC;IACH,CAAC,CACF,CAAC;IAEF,iEAAiE;IACjE,GAA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,SAAS;oBAC1B,WAAW,EAAE,KAAK,CAAC,WAAW;oBAC9B,SAAS,EAAE,KAAK,CAAC,SAAS;iBAC3B,CAAC;YACJ,CAAC;YACD,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,2BAA2B,EAAE,CAAC,CAAC;QACtE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,uCAAuC,EAAE,KAAK,CAAC,CAAC;YAC9D,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC;QAChE,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -2,5 +2,10 @@
|
|
|
2
2
|
* Health check endpoint with daemon diagnostics.
|
|
3
3
|
*/
|
|
4
4
|
import type { FastifyInstance } from "fastify";
|
|
5
|
-
|
|
5
|
+
import type { DaemonContext } from "../daemon-context.js";
|
|
6
|
+
interface HealthRoutesOptions {
|
|
7
|
+
daemonContext?: DaemonContext | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function registerHealthRoutes(app: FastifyInstance, options?: HealthRoutesOptions): Promise<void>;
|
|
10
|
+
export {};
|
|
6
11
|
//# sourceMappingURL=health.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/routes/health.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/routes/health.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,UAAU,mBAAmB;IAC3B,aAAa,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CAC3C;AAED,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,eAAe,EACpB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,IAAI,CAAC,CAaf"}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Health check endpoint with daemon diagnostics.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export async function registerHealthRoutes(app, options = {}) {
|
|
5
|
+
const { daemonContext } = options;
|
|
6
6
|
app.get("/api/health", async () => {
|
|
7
|
-
const daemonInfo = getDaemonInfo();
|
|
8
7
|
return {
|
|
9
8
|
status: "ok",
|
|
10
9
|
pid: process.pid,
|
|
11
10
|
uptime: process.uptime(),
|
|
12
|
-
mode:
|
|
13
|
-
sessionId:
|
|
14
|
-
startedAt:
|
|
11
|
+
mode: daemonContext?.mode ?? "foreground",
|
|
12
|
+
sessionId: daemonContext?.sessionId ?? null,
|
|
13
|
+
startedAt: daemonContext?.startedAt ?? null,
|
|
15
14
|
};
|
|
16
15
|
});
|
|
17
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/routes/health.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/routes/health.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAoB,EACpB,UAA+B,EAAE;IAEjC,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAElC,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,KAAK,IAAI,EAAE;QAChC,OAAO;YACL,MAAM,EAAE,IAAI;YACZ,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;YACxB,IAAI,EAAE,aAAa,EAAE,IAAI,IAAI,YAAY;YACzC,SAAS,EAAE,aAAa,EAAE,SAAS,IAAI,IAAI;YAC3C,SAAS,EAAE,aAAa,EAAE,SAAS,IAAI,IAAI;SAC5C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -3,13 +3,33 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This endpoint is called by the agent-recorder-hook handler script
|
|
5
5
|
* which is configured in Claude Code's .claude/settings.json.
|
|
6
|
+
*
|
|
7
|
+
* Implements hierarchical event tracking:
|
|
8
|
+
* - SessionStart → creates agent_call event (root of the tree)
|
|
9
|
+
* - PreToolUse → creates event with status "running" (captures start time)
|
|
10
|
+
* - PostToolUse → completes the running event with output and end time
|
|
11
|
+
* - SessionEnd → ends the agent_call event
|
|
6
12
|
*/
|
|
7
13
|
import type { FastifyInstance } from "fastify";
|
|
8
14
|
import type Database from "better-sqlite3";
|
|
9
15
|
interface HooksRoutesOptions {
|
|
10
16
|
db: Database.Database;
|
|
11
17
|
debug?: boolean;
|
|
18
|
+
redactKeys?: string[];
|
|
12
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Detect if a tool response indicates an error.
|
|
22
|
+
* Only uses the MCP-standard `isError: true` field for status decisions.
|
|
23
|
+
*
|
|
24
|
+
* Previous versions also checked for a top-level `error` field (JSON-RPC
|
|
25
|
+
* style), but this produced false positives for tools that use `error` as
|
|
26
|
+
* a regular output field (e.g. `{ error: "none" }`). The `error` field is
|
|
27
|
+
* now treated as informational metadata only — it is still captured in
|
|
28
|
+
* outputJson for display but does not flip event status to "error".
|
|
29
|
+
*
|
|
30
|
+
* @internal Exported for unit testing only.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isToolResponseError(response: unknown): boolean;
|
|
13
33
|
export declare function registerHooksRoutes(app: FastifyInstance, options: HooksRoutesOptions): Promise<void>;
|
|
14
34
|
export {};
|
|
15
35
|
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/routes/hooks.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/routes/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAmB3C,UAAU,kBAAkB;IAC1B,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AA+HD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO,CAU9D;AAgDD,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAyff"}
|