@vellumai/assistant 0.10.7-dev.202607100720.fba456e → 0.10.7-dev.202607101106.c87f4e3
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/openapi.yaml +0 -4
- package/package.json +1 -1
- package/src/__tests__/compaction-trail-store.test.ts +2 -1
- package/src/__tests__/conversation-app-control-instantiation.test.ts +20 -3
- package/src/__tests__/conversation-runtime-assembly.test.ts +2 -0
- package/src/__tests__/conversation-skill-tools.test.ts +31 -6
- package/src/__tests__/list-messages-queued.test.ts +9 -3
- package/src/__tests__/llm-request-log-agent-loop-exit-reason.test.ts +9 -9
- package/src/__tests__/llm-request-log-call-site.test.ts +5 -5
- package/src/__tests__/llm-request-log-disabled-writes.test.ts +91 -0
- package/src/__tests__/media-generate-image.test.ts +20 -7
- package/src/__tests__/platform-bash-auto-approve.test.ts +19 -2
- package/src/__tests__/registry.test.ts +18 -0
- package/src/__tests__/require-fresh-approval.test.ts +15 -0
- package/src/__tests__/skill-projection-feature-flag.test.ts +35 -8
- package/src/__tests__/skill-projection.benchmark.test.ts +7 -2
- package/src/__tests__/subagent-detail.test.ts +1 -0
- package/src/__tests__/summarize-boundary.test.ts +1 -0
- package/src/__tests__/tool-approval-handler.test.ts +1 -0
- package/src/__tests__/tool-execution-pipeline.benchmark.test.ts +1 -0
- package/src/__tests__/tool-executor-lifecycle-events.test.ts +21 -17
- package/src/__tests__/tool-executor.test.ts +36 -18
- package/src/__tests__/tool-grant-request-escalation.test.ts +1 -0
- package/src/__tests__/trusted-contact-inline-approval-integration.test.ts +1 -0
- package/src/__tests__/verification-control-plane-policy.test.ts +13 -0
- package/src/api/responses/conversation-message.ts +0 -15
- package/src/config/schemas/__tests__/llm-request-logs.test.ts +33 -5
- package/src/config/schemas/llm-request-logs.ts +78 -27
- package/src/daemon/conversation-skill-tools.ts +27 -9
- package/src/export/__tests__/transcript-formatter.test.ts +5 -0
- package/src/permissions/checker.test.ts +3 -6
- package/src/permissions/checker.ts +2 -2
- package/src/persistence/__tests__/message-content-file.test.ts +150 -0
- package/src/persistence/__tests__/slow-query-log.test.ts +125 -0
- package/src/persistence/conversation-crud.ts +11 -1
- package/src/persistence/llm-request-log-store.ts +36 -2
- package/src/persistence/message-content-file.ts +190 -0
- package/src/persistence/migrations/324-message-finalized-column.ts +26 -0
- package/src/persistence/migrations/__tests__/297-move-llm-request-logs.test.ts +2 -2
- package/src/persistence/schema/conversations.ts +15 -0
- package/src/persistence/slow-query-log.ts +58 -21
- package/src/persistence/steps.ts +2 -0
- package/src/runtime/routes/__tests__/conversation-compaction-routes.test.ts +31 -2
- package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +67 -1
- package/src/runtime/routes/conversation-compaction-routes.ts +5 -0
- package/src/runtime/routes/conversation-query-routes.ts +5 -0
- package/src/runtime/routes/conversation-routes.ts +2 -8
- package/src/runtime/routes/errors.ts +17 -0
- package/src/runtime/routes/llm-request-logs-access.ts +19 -0
- package/src/tasks/tool-sanitizer.ts +3 -1
- package/src/telemetry/turn-trace-store.test.ts +4 -0
- package/src/telemetry/turn-trace-store.ts +1 -4
- package/src/tools/registry.ts +89 -11
- package/src/tools/run-standalone.ts +5 -13
- package/src/tools/workspace-tools/loader.ts +24 -8
- package/src/util/sqlite-query-label.ts +51 -0
- package/src/util/sqlite-retry.ts +14 -2
- package/src/workflows/capabilities.ts +12 -4
|
@@ -19,11 +19,16 @@
|
|
|
19
19
|
* Drizzle or {@link ./raw-query}.
|
|
20
20
|
*
|
|
21
21
|
* Attribution: raw-query callers attach a curated `.label()` (e.g.
|
|
22
|
-
* `"schedule:claimDue"`).
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
22
|
+
* `"schedule:claimDue"`). Wrappers that know the operation they run publish an
|
|
23
|
+
* ambient label ({@link ../util/sqlite-query-label} — e.g. `withSqliteRetry`
|
|
24
|
+
* publishes its `op`), picked up here when no statement label is set. Drizzle's
|
|
25
|
+
* fluent API has no chokepoint to label, so for any query without a label the
|
|
26
|
+
* reporter derives a `caller` from the stack — `path:function:line` of the
|
|
27
|
+
* nearest *named* application frame, so a query issued inside an anonymous
|
|
28
|
+
* transaction callback is attributed to the enclosing function rather than
|
|
29
|
+
* `<anonymous>` — captured only on the slow path. Between the three, every
|
|
30
|
+
* slow query is attributable to its call site with no per-query annotation of
|
|
31
|
+
* Drizzle code.
|
|
27
32
|
*
|
|
28
33
|
* The same per-statement chokepoint also surfaces *failed* executions: when a
|
|
29
34
|
* statement throws, the error is handed to {@link observeSqliteStatementError}
|
|
@@ -42,6 +47,7 @@ import type { Database, Statement } from "bun:sqlite";
|
|
|
42
47
|
|
|
43
48
|
import { observeSqliteStatementError } from "../daemon/sqlite-corruption-watchdog.js";
|
|
44
49
|
import { getLogger } from "../util/logger.js";
|
|
50
|
+
import { getAmbientSqliteQueryLabel } from "../util/sqlite-query-label.js";
|
|
45
51
|
|
|
46
52
|
const log = getLogger("slow-query");
|
|
47
53
|
|
|
@@ -75,12 +81,19 @@ export interface SlowQueryEvent {
|
|
|
75
81
|
sql: string;
|
|
76
82
|
/** Number of rows returned, when the execution produced an array result. */
|
|
77
83
|
rowCount?: number;
|
|
78
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* Caller-supplied attribution tag: the statement's `.label()` when set,
|
|
86
|
+
* otherwise the ambient label published by an enclosing wrapper (e.g.
|
|
87
|
+
* `withSqliteRetry`'s `op` — see {@link ../util/sqlite-query-label}).
|
|
88
|
+
*/
|
|
79
89
|
label?: string;
|
|
80
90
|
/**
|
|
81
|
-
* Auto-derived call site (`path:function:line`
|
|
82
|
-
* `.label()` — notably every
|
|
83
|
-
*
|
|
91
|
+
* Auto-derived call site (`path:function:line` of the nearest named
|
|
92
|
+
* application frame) for queries with no explicit `.label()` — notably every
|
|
93
|
+
* Drizzle query, which has no chokepoint to attach a label to. Captured from
|
|
94
|
+
* the stack only on the slow path. Present alongside an *ambient* label
|
|
95
|
+
* (which marks an outer boundary, not the statement's own call site) but
|
|
96
|
+
* suppressed by an explicit `.label()`.
|
|
84
97
|
*/
|
|
85
98
|
caller?: string;
|
|
86
99
|
}
|
|
@@ -127,13 +140,26 @@ function shortenStackFile(file: string): string {
|
|
|
127
140
|
return file.split("/").pop() ?? file;
|
|
128
141
|
}
|
|
129
142
|
|
|
143
|
+
/** Function names Bun uses for frames with no name of their own. */
|
|
144
|
+
function isAnonymousFunctionName(name: string): boolean {
|
|
145
|
+
return name === "<anonymous>" || name === "anonymous";
|
|
146
|
+
}
|
|
147
|
+
|
|
130
148
|
/**
|
|
131
|
-
* Best-effort attribution for a query with no explicit label: the
|
|
132
|
-
* frame outside this module, dependencies, and the runtime —
|
|
133
|
-
* application
|
|
134
|
-
* `persistence/conversation-crud.ts:insertMessageCore:474`.
|
|
135
|
-
*
|
|
136
|
-
*
|
|
149
|
+
* Best-effort attribution for a query with no explicit label: the nearest
|
|
150
|
+
* *named* stack frame outside this module, dependencies, and the runtime —
|
|
151
|
+
* i.e. the application function accountable for the query. Returns e.g.
|
|
152
|
+
* `persistence/conversation-crud.ts:insertMessageCore:474`.
|
|
153
|
+
*
|
|
154
|
+
* Anonymous application frames are skipped in favor of a named frame further
|
|
155
|
+
* up: a statement run inside `db.transaction((tx) => …)` sits in an anonymous
|
|
156
|
+
* callback, and attributing it there (`file:<anonymous>:line`) hides which
|
|
157
|
+
* operation issued it. The innermost anonymous frame is kept as a fallback for
|
|
158
|
+
* stacks with no named application frame at all.
|
|
159
|
+
*
|
|
160
|
+
* Only called on the slow path (a query already past the threshold), so the
|
|
161
|
+
* `Error().stack` cost is incurred rarely. Accepts an explicit `stack` for
|
|
162
|
+
* testing.
|
|
137
163
|
*
|
|
138
164
|
* @internal exported only for unit tests.
|
|
139
165
|
*/
|
|
@@ -142,6 +168,7 @@ export function callerFromStack(
|
|
|
142
168
|
): string | undefined {
|
|
143
169
|
if (!stack) return undefined;
|
|
144
170
|
const lines = stack.split("\n");
|
|
171
|
+
let anonymousFallback: string | undefined;
|
|
145
172
|
for (let i = 1; i < lines.length; i++) {
|
|
146
173
|
const line = lines[i];
|
|
147
174
|
if (!line.includes("at ")) continue;
|
|
@@ -152,14 +179,19 @@ export function callerFromStack(
|
|
|
152
179
|
/at (?:async )?([^\s(]+) \((.+?):(\d+)(?::\d+)?\)/,
|
|
153
180
|
);
|
|
154
181
|
if (withFn) {
|
|
155
|
-
|
|
182
|
+
const caller = `${shortenStackFile(withFn[2])}:${withFn[1]}:${withFn[3]}`;
|
|
183
|
+
if (isAnonymousFunctionName(withFn[1])) {
|
|
184
|
+
anonymousFallback ??= caller;
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
return caller;
|
|
156
188
|
}
|
|
157
189
|
const noFn = line.match(/at (?:async )?(.+?):(\d+)(?::\d+)?$/);
|
|
158
190
|
if (noFn) {
|
|
159
|
-
|
|
191
|
+
anonymousFallback ??= `${shortenStackFile(noFn[1])}:${noFn[2]}`;
|
|
160
192
|
}
|
|
161
193
|
}
|
|
162
|
-
return
|
|
194
|
+
return anonymousFallback;
|
|
163
195
|
}
|
|
164
196
|
|
|
165
197
|
/** Log a slow statement execution at WARN with its SQL and duration. */
|
|
@@ -251,14 +283,19 @@ export function wrapSqliteForSlowQueryLogging(
|
|
|
251
283
|
durationMs: number,
|
|
252
284
|
result: unknown,
|
|
253
285
|
): void => {
|
|
254
|
-
// Only ever called on the slow path, so building the payload — including
|
|
255
|
-
// stack walk for unlabeled (Drizzle)
|
|
286
|
+
// Only ever called on the slow path, so building the payload — including
|
|
287
|
+
// the ambient-label read and the stack walk for unlabeled (Drizzle)
|
|
288
|
+
// queries — is fine. An explicit `.label()` marks the statement's own
|
|
289
|
+
// call site, so the stack adds nothing; an ambient label marks an outer
|
|
290
|
+
// boundary (e.g. a `withSqliteRetry` op), so the call site is still
|
|
291
|
+
// derived alongside it.
|
|
292
|
+
const effectiveLabel = label ?? getAmbientSqliteQueryLabel();
|
|
256
293
|
const caller = label === undefined ? callerFromStack() : undefined;
|
|
257
294
|
onSlowQuery({
|
|
258
295
|
durationMs,
|
|
259
296
|
sql: sql.slice(0, SQL_PREVIEW_MAX),
|
|
260
297
|
...(Array.isArray(result) ? { rowCount: result.length } : {}),
|
|
261
|
-
...(
|
|
298
|
+
...(effectiveLabel === undefined ? {} : { label: effectiveLabel }),
|
|
262
299
|
...(caller === undefined ? {} : { caller }),
|
|
263
300
|
});
|
|
264
301
|
};
|
package/src/persistence/steps.ts
CHANGED
|
@@ -431,6 +431,7 @@ import { migrateDropTraceEventsTable } from "./migrations/320-drop-trace-events-
|
|
|
431
431
|
import { migrateCanonicalGuardianRequestTrigger } from "./migrations/321-canonical-guardian-request-trigger.js";
|
|
432
432
|
import { migrateAddProcessingResumeAttempts } from "./migrations/322-add-processing-resume-attempts.js";
|
|
433
433
|
import { migrateDeleteNonDefaultMemoryScopes } from "./migrations/323-delete-non-default-memory-scopes.js";
|
|
434
|
+
import { migrateMessageFinalizedColumn } from "./migrations/324-message-finalized-column.js";
|
|
434
435
|
import type { MigrationStep } from "./migrations/run-migrations.js";
|
|
435
436
|
|
|
436
437
|
export const migrationSteps: MigrationStep[] = [
|
|
@@ -1333,4 +1334,5 @@ export const migrationSteps: MigrationStep[] = [
|
|
|
1333
1334
|
migrateCanonicalGuardianRequestTrigger,
|
|
1334
1335
|
migrateAddProcessingResumeAttempts,
|
|
1335
1336
|
migrateDeleteNonDefaultMemoryScopes,
|
|
1337
|
+
migrateMessageFinalizedColumn,
|
|
1336
1338
|
];
|
|
@@ -18,6 +18,8 @@ mock.module("../../../util/logger.js", () => ({
|
|
|
18
18
|
}),
|
|
19
19
|
}));
|
|
20
20
|
|
|
21
|
+
// Mutable so a test can flip the master switch off and assert the guard.
|
|
22
|
+
let llmRequestLoggingEnabled = true;
|
|
21
23
|
mock.module("../../../config/loader.js", () => ({
|
|
22
24
|
getConfig: () => ({
|
|
23
25
|
ui: {},
|
|
@@ -26,7 +28,10 @@ mock.module("../../../config/loader.js", () => ({
|
|
|
26
28
|
memory: { enabled: false },
|
|
27
29
|
rateLimit: { maxRequestsPerMinute: 0 },
|
|
28
30
|
secretDetection: { enabled: false },
|
|
29
|
-
llmRequestLogs: {
|
|
31
|
+
llmRequestLogs: {
|
|
32
|
+
readSource: "local" as const,
|
|
33
|
+
enabled: llmRequestLoggingEnabled,
|
|
34
|
+
},
|
|
30
35
|
}),
|
|
31
36
|
}));
|
|
32
37
|
|
|
@@ -149,7 +154,11 @@ import {
|
|
|
149
154
|
projectLogRowToCompactionTrailEvent,
|
|
150
155
|
ROUTES,
|
|
151
156
|
} from "../conversation-compaction-routes.js";
|
|
152
|
-
import {
|
|
157
|
+
import {
|
|
158
|
+
BadRequestError,
|
|
159
|
+
LlmRequestLogsDisabledError,
|
|
160
|
+
NotFoundError,
|
|
161
|
+
} from "../errors.js";
|
|
153
162
|
|
|
154
163
|
const route = ROUTES.find(
|
|
155
164
|
(r) => r.operationId === "conversations_compaction_trail_get",
|
|
@@ -218,6 +227,7 @@ function fakeCompactionLogEvent(
|
|
|
218
227
|
}
|
|
219
228
|
|
|
220
229
|
beforeEach(() => {
|
|
230
|
+
llmRequestLoggingEnabled = true;
|
|
221
231
|
state.conversation = null;
|
|
222
232
|
state.selectedCall = null;
|
|
223
233
|
state.previousNonCompactionCallCreatedAt = null;
|
|
@@ -261,6 +271,25 @@ describe("handleGetCompactionTrail — request-shape errors", () => {
|
|
|
261
271
|
).rejects.toThrow(BadRequestError);
|
|
262
272
|
});
|
|
263
273
|
|
|
274
|
+
test("throws LlmRequestLogsDisabledError when logging is disabled", async () => {
|
|
275
|
+
// Even with a valid conversation + call, the guard short-circuits before
|
|
276
|
+
// any log source read — the compaction trail is inspector-only LLM data.
|
|
277
|
+
llmRequestLoggingEnabled = false;
|
|
278
|
+
state.conversation = { id: "conv-1" };
|
|
279
|
+
state.selectedCall = fakeLogMetaRow({
|
|
280
|
+
id: "call-1",
|
|
281
|
+
conversationId: "conv-1",
|
|
282
|
+
});
|
|
283
|
+
await expect(
|
|
284
|
+
handler({
|
|
285
|
+
pathParams: { id: "conv-1" },
|
|
286
|
+
queryParams: { callId: "call-1" },
|
|
287
|
+
}),
|
|
288
|
+
).rejects.toThrow(LlmRequestLogsDisabledError);
|
|
289
|
+
// The guard runs first: no metadata lookup happened.
|
|
290
|
+
expect(sourceCalls.getRequestLogMetaByIdArgs).toEqual([]);
|
|
291
|
+
});
|
|
292
|
+
|
|
264
293
|
test("throws NotFoundError when the conversation does not exist", async () => {
|
|
265
294
|
state.conversation = null;
|
|
266
295
|
await expect(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
2
|
|
|
3
3
|
mock.module("../../../util/logger.js", () => ({
|
|
4
4
|
getLogger: () =>
|
|
@@ -295,6 +295,72 @@ describe("GET /v1/conversations/llm-context", () => {
|
|
|
295
295
|
});
|
|
296
296
|
});
|
|
297
297
|
|
|
298
|
+
describe("inspector reads when llmRequestLogs.enabled is false", () => {
|
|
299
|
+
const payloadRoute = ROUTES.find(
|
|
300
|
+
(r) => r.operationId === "llm_request_logs_payload_get",
|
|
301
|
+
)!;
|
|
302
|
+
const contextRoute = ROUTES.find(
|
|
303
|
+
(r) => r.operationId === "llm_request_logs_context_get",
|
|
304
|
+
)!;
|
|
305
|
+
|
|
306
|
+
beforeEach(() => {
|
|
307
|
+
clearTables();
|
|
308
|
+
rawConfigFixture = {
|
|
309
|
+
llmRequestLogs: { readSource: "local", enabled: false },
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
afterEach(() => {
|
|
314
|
+
// Restore the neutral default so read blocks that rely on it (and don't
|
|
315
|
+
// reset the fixture themselves) aren't polluted by the disabled state.
|
|
316
|
+
rawConfigFixture = {};
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
async function expectDisabled(promise: unknown): Promise<void> {
|
|
320
|
+
// The handler throws a RouteError; assert on its wire-facing fields so the
|
|
321
|
+
// client can key on the stable code / 403 status.
|
|
322
|
+
let thrown: unknown;
|
|
323
|
+
try {
|
|
324
|
+
await promise;
|
|
325
|
+
} catch (err) {
|
|
326
|
+
thrown = err;
|
|
327
|
+
}
|
|
328
|
+
expect(thrown).toBeDefined();
|
|
329
|
+
expect((thrown as { code: string }).code).toBe("LLM_REQUEST_LOGS_DISABLED");
|
|
330
|
+
expect((thrown as { statusCode: number }).statusCode).toBe(403);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
test("message llm-context is rejected", async () => {
|
|
334
|
+
await expectDisabled(dispatchLlmContext("msg-1"));
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("conversation llm-context is rejected", async () => {
|
|
338
|
+
await expectDisabled(
|
|
339
|
+
dispatchConversationLlmContext({ conversationId: "conv-1" }),
|
|
340
|
+
);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("single-log payload is rejected", async () => {
|
|
344
|
+
await expectDisabled(payloadRoute.handler({ pathParams: { id: "log-a" } }));
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test("single-log context is rejected", async () => {
|
|
348
|
+
await expectDisabled(contextRoute.handler({ pathParams: { id: "log-a" } }));
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
test("reads succeed again once logging is re-enabled", async () => {
|
|
352
|
+
rawConfigFixture = {
|
|
353
|
+
llmRequestLogs: { readSource: "local", enabled: true },
|
|
354
|
+
};
|
|
355
|
+
// An unresolved conversation key returns an empty inspector response
|
|
356
|
+
// (no throw), proving the disabled guard no longer short-circuits.
|
|
357
|
+
const body = (await dispatchConversationLlmContext({
|
|
358
|
+
conversationKey: "missing-key",
|
|
359
|
+
})) as { logs: unknown[] };
|
|
360
|
+
expect(body.logs).toEqual([]);
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
|
|
298
364
|
describe("llm-context view=summary", () => {
|
|
299
365
|
beforeEach(() => {
|
|
300
366
|
clearTables();
|
|
@@ -62,6 +62,7 @@ import {
|
|
|
62
62
|
type LlmContextSummary,
|
|
63
63
|
normalizeLlmContextPayloads,
|
|
64
64
|
} from "./llm-context-normalization.js";
|
|
65
|
+
import { assertLlmRequestLoggingEnabled } from "./llm-request-logs-access.js";
|
|
65
66
|
import type { RouteDefinition, RouteHandlerArgs } from "./types.js";
|
|
66
67
|
|
|
67
68
|
const log = getLogger("conversation-compaction-routes");
|
|
@@ -256,6 +257,10 @@ async function handleGetCompactionTrail({
|
|
|
256
257
|
pathParams = {},
|
|
257
258
|
queryParams = {},
|
|
258
259
|
}: RouteHandlerArgs): Promise<CompactionTrailResponse> {
|
|
260
|
+
// The compaction trail reads LLM-derived log data (metadata + the
|
|
261
|
+
// compactionAgent projection over `llm_request_logs`), so it honours the
|
|
262
|
+
// same opt-out as the other inspector reads.
|
|
263
|
+
assertLlmRequestLoggingEnabled();
|
|
259
264
|
const conversationId = pathParams.id;
|
|
260
265
|
const callId = queryParams.callId;
|
|
261
266
|
|
|
@@ -110,6 +110,7 @@ import {
|
|
|
110
110
|
type LlmContextSummary,
|
|
111
111
|
normalizeLlmContextPayloads,
|
|
112
112
|
} from "./llm-context-normalization.js";
|
|
113
|
+
import { assertLlmRequestLoggingEnabled } from "./llm-request-logs-access.js";
|
|
113
114
|
import type { RouteDefinition, RouteHandlerArgs } from "./types.js";
|
|
114
115
|
|
|
115
116
|
const validEmbeddingProviderSet = new Set<string>(
|
|
@@ -1778,6 +1779,7 @@ async function handleGetLlmContext({
|
|
|
1778
1779
|
pathParams = {},
|
|
1779
1780
|
queryParams = {},
|
|
1780
1781
|
}: RouteHandlerArgs) {
|
|
1782
|
+
assertLlmRequestLoggingEnabled();
|
|
1781
1783
|
const messageId = pathParams.id;
|
|
1782
1784
|
if (!messageId) {
|
|
1783
1785
|
throw new BadRequestError("message id is required");
|
|
@@ -1821,6 +1823,7 @@ async function handleGetLlmContext({
|
|
|
1821
1823
|
async function handleGetConversationLlmContext({
|
|
1822
1824
|
queryParams = {},
|
|
1823
1825
|
}: RouteHandlerArgs) {
|
|
1826
|
+
assertLlmRequestLoggingEnabled();
|
|
1824
1827
|
const conversationKey = queryParams.conversationKey;
|
|
1825
1828
|
const requestedConversationId = queryParams.conversationId;
|
|
1826
1829
|
const view = resolveLlmContextView(queryParams.view);
|
|
@@ -1890,6 +1893,7 @@ async function handleGetConversationLlmContext({
|
|
|
1890
1893
|
async function handleGetLlmRequestLogPayload({
|
|
1891
1894
|
pathParams = {},
|
|
1892
1895
|
}: RouteHandlerArgs) {
|
|
1896
|
+
assertLlmRequestLoggingEnabled();
|
|
1893
1897
|
const logId = pathParams.id;
|
|
1894
1898
|
if (!logId) {
|
|
1895
1899
|
throw new BadRequestError("log id is required");
|
|
@@ -1917,6 +1921,7 @@ async function handleGetLlmRequestLogPayload({
|
|
|
1917
1921
|
async function handleGetLlmRequestLogContext({
|
|
1918
1922
|
pathParams = {},
|
|
1919
1923
|
}: RouteHandlerArgs) {
|
|
1924
|
+
assertLlmRequestLoggingEnabled();
|
|
1920
1925
|
const logId = pathParams.id;
|
|
1921
1926
|
if (!logId) {
|
|
1922
1927
|
throw new BadRequestError("log id is required");
|
|
@@ -658,7 +658,6 @@ function buildQueuedMessagePayloads(
|
|
|
658
658
|
// identifier the queued-message delete/steer endpoints key on.
|
|
659
659
|
id: item.requestId,
|
|
660
660
|
role: "user" as const,
|
|
661
|
-
content: text,
|
|
662
661
|
timestamp: new Date(item.sentAt).toISOString(),
|
|
663
662
|
attachments,
|
|
664
663
|
...(contentBlocks.length > 0 ? { contentBlocks } : {}),
|
|
@@ -1018,10 +1017,9 @@ export function handleListMessages({
|
|
|
1018
1017
|
|
|
1019
1018
|
// Strip <no_response/> markers from assistant messages so web/API clients
|
|
1020
1019
|
// never see the raw sentinel. Only assistant messages produce it; user
|
|
1021
|
-
// messages are untouched. The filter is applied consistently to the
|
|
1022
|
-
//
|
|
1020
|
+
// messages are untouched. The filter is applied consistently to the
|
|
1021
|
+
// segments, the contentOrder text refs, and the text blocks of
|
|
1023
1022
|
// contentBlocks.
|
|
1024
|
-
let text = rendered.text;
|
|
1025
1023
|
let textSegments = rendered.textSegments;
|
|
1026
1024
|
let contentOrder = rendered.contentOrder;
|
|
1027
1025
|
let contentBlocks = rendered.contentBlocks;
|
|
@@ -1048,7 +1046,6 @@ export function handleListMessages({
|
|
|
1048
1046
|
})
|
|
1049
1047
|
.filter((e): e is string => e !== undefined);
|
|
1050
1048
|
textSegments = filteredSegments;
|
|
1051
|
-
text = rendered.text.replace(NO_RESPONSE_INLINE_RE, "").trim();
|
|
1052
1049
|
contentBlocks = rendered.contentBlocks
|
|
1053
1050
|
.map((block) =>
|
|
1054
1051
|
block.type === "text"
|
|
@@ -1096,9 +1093,6 @@ export function handleListMessages({
|
|
|
1096
1093
|
...(mergedMessageIds.length > 0 ? { mergedMessageIds } : {}),
|
|
1097
1094
|
...(m.clientMessageId ? { clientMessageId: m.clientMessageId } : {}),
|
|
1098
1095
|
role: m.role,
|
|
1099
|
-
// Flat plain-text body; see the `content` field on
|
|
1100
|
-
// ConversationMessageSchema for why this must stay.
|
|
1101
|
-
content: text,
|
|
1102
1096
|
timestamp: new Date(displayTimestamp).toISOString(),
|
|
1103
1097
|
attachments: msgAttachments,
|
|
1104
1098
|
...(toolCalls.length > 0 ? { toolCalls } : {}),
|
|
@@ -145,3 +145,20 @@ export class InternalError extends RouteError {
|
|
|
145
145
|
this.name = "InternalError";
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* LLM request logging is turned off via `llmRequestLogs.disabled`, so the
|
|
151
|
+
* inspector read routes have nothing to serve. Carries a distinct, stable
|
|
152
|
+
* `code` (`LLM_REQUEST_LOGS_DISABLED`) so clients can branch on it — the web
|
|
153
|
+
* inspector renders a "logging is off" state with an enable toggle rather than
|
|
154
|
+
* a generic failure. 403 (rather than 404) so the condition reads as
|
|
155
|
+
* "deliberately withheld", not "missing".
|
|
156
|
+
*/
|
|
157
|
+
export class LlmRequestLogsDisabledError extends RouteError {
|
|
158
|
+
constructor(
|
|
159
|
+
message = "LLM request logging is disabled. Enable it to view request logs.",
|
|
160
|
+
) {
|
|
161
|
+
super(message, "LLM_REQUEST_LOGS_DISABLED", 403);
|
|
162
|
+
this.name = "LlmRequestLogsDisabledError";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared access guard for the inspector's LLM-request-log read routes.
|
|
3
|
+
*
|
|
4
|
+
* When `llmRequestLogs.enabled` is `false` there is nothing to serve (and any
|
|
5
|
+
* rows that predate the opt-out are intentionally withheld), so every route
|
|
6
|
+
* that surfaces LLM-derived log data — the message/conversation `llm-context`
|
|
7
|
+
* routes, the single-log payload/context routes, and the compaction trail
|
|
8
|
+
* route — calls this first to fail fast with the distinct
|
|
9
|
+
* `LLM_REQUEST_LOGS_DISABLED` code the client keys on to render an
|
|
10
|
+
* enable-logging affordance instead of a generic error.
|
|
11
|
+
*/
|
|
12
|
+
import { getConfig } from "../../config/loader.js";
|
|
13
|
+
import { LlmRequestLogsDisabledError } from "./errors.js";
|
|
14
|
+
|
|
15
|
+
export function assertLlmRequestLoggingEnabled(): void {
|
|
16
|
+
if (getConfig().llmRequestLogs?.enabled === false) {
|
|
17
|
+
throw new LlmRequestLogsDisabledError();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -11,7 +11,9 @@ export function sanitizeToolList(tools: string[]): string[] {
|
|
|
11
11
|
const seen = new Set<string>();
|
|
12
12
|
|
|
13
13
|
for (const tool of tools) {
|
|
14
|
-
if (!tool || typeof tool !== "string")
|
|
14
|
+
if (!tool || typeof tool !== "string") {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
15
17
|
seen.add(tool);
|
|
16
18
|
}
|
|
17
19
|
|
|
@@ -42,6 +42,10 @@ mock.module("../tools/registry.js", () => ({
|
|
|
42
42
|
mockToolDescriptions[name]
|
|
43
43
|
? { description: mockToolDescriptions[name], input_schema: {} }
|
|
44
44
|
: undefined,
|
|
45
|
+
resolveTool: (name: string) =>
|
|
46
|
+
mockToolDescriptions[name]
|
|
47
|
+
? { description: mockToolDescriptions[name], input_schema: {} }
|
|
48
|
+
: undefined,
|
|
45
49
|
}));
|
|
46
50
|
|
|
47
51
|
import { createConversation } from "../persistence/conversation-crud.js";
|
|
@@ -322,10 +322,7 @@ export function assembleTurnTrace(boundary: TurnTraceBoundary): TurnTrace {
|
|
|
322
322
|
return {
|
|
323
323
|
name,
|
|
324
324
|
description: tool?.description ?? "",
|
|
325
|
-
input_schema: (tool?.input_schema ?? {}) as Record<
|
|
326
|
-
string,
|
|
327
|
-
unknown
|
|
328
|
-
>,
|
|
325
|
+
input_schema: (tool?.input_schema ?? {}) as Record<string, unknown>,
|
|
329
326
|
};
|
|
330
327
|
})
|
|
331
328
|
: [];
|
package/src/tools/registry.ts
CHANGED
|
@@ -99,6 +99,12 @@ function getExternalTools(): Array<{ owner: OwnerInfo; tool: Tool }> {
|
|
|
99
99
|
let coreToolsSnapshot: Map<string, { tool: Tool; owner: OwnerInfo }> | null =
|
|
100
100
|
null;
|
|
101
101
|
|
|
102
|
+
// Cached promise for the one-time tool-registry initialization. `initializeTools`
|
|
103
|
+
// returns this so repeated calls (across entry points, or an eventual
|
|
104
|
+
// getter-triggered ensure) run the underlying work exactly once. Cleared by the
|
|
105
|
+
// test-reset helpers so each test can re-initialize from a clean baseline.
|
|
106
|
+
let toolsInitPromise: Promise<void> | null = null;
|
|
107
|
+
|
|
102
108
|
// Tracks how many sessions are currently using each skill's tools.
|
|
103
109
|
// Tools are only removed from the global registry when this drops to 0.
|
|
104
110
|
const skillRefCount = new Map<string, number>();
|
|
@@ -117,7 +123,9 @@ const pluginRefCount = new Map<string, number>();
|
|
|
117
123
|
* string so log/error sites never produce `undefined` interpolations.
|
|
118
124
|
*/
|
|
119
125
|
function describeOwner(owner: OwnerInfo | undefined): string {
|
|
120
|
-
if (!owner)
|
|
126
|
+
if (!owner) {
|
|
127
|
+
return "core tool";
|
|
128
|
+
}
|
|
121
129
|
switch (owner.kind) {
|
|
122
130
|
case "skill":
|
|
123
131
|
return `skill "${owner.id}"`;
|
|
@@ -200,7 +208,9 @@ export function registerTool(definition: ToolDefinition): void {
|
|
|
200
208
|
}
|
|
201
209
|
const existing = tools.get(name);
|
|
202
210
|
if (existing) {
|
|
203
|
-
if (existing === tool)
|
|
211
|
+
if (existing === tool) {
|
|
212
|
+
return;
|
|
213
|
+
} // same definition re-registered, skip
|
|
204
214
|
log.warn({ name }, "Tool already registered, overwriting");
|
|
205
215
|
}
|
|
206
216
|
tools.set(name, tool);
|
|
@@ -212,6 +222,29 @@ export function registerTool(definition: ToolDefinition): void {
|
|
|
212
222
|
log.info({ name, category: tool.category }, "Tool registered");
|
|
213
223
|
}
|
|
214
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Resolve a registered tool by name, ensuring the registry has been
|
|
227
|
+
* initialized first. Mirrors `getHooksFor`, which awaits its reconcile before
|
|
228
|
+
* reading — so a caller on a cold registry gets a populated result instead of
|
|
229
|
+
* a spurious `undefined`. Prefer this in any async context.
|
|
230
|
+
*
|
|
231
|
+
* `initializeTools()` is idempotent: the first call does the work and caches
|
|
232
|
+
* its promise, so every later `resolveTool` just awaits the already-settled
|
|
233
|
+
* promise (an `await` on a resolved value — no re-initialization). The per-call
|
|
234
|
+
* cost past init is a single map lookup.
|
|
235
|
+
*/
|
|
236
|
+
export async function resolveTool(name: string): Promise<Tool | undefined> {
|
|
237
|
+
await initializeTools();
|
|
238
|
+
return tools.get(name);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Synchronous read that does NOT trigger initialization. For hot-path callers
|
|
243
|
+
* that run only after the registry is known to be populated — e.g. the agent
|
|
244
|
+
* loop's exclusive-tool predicate, invoked mid-turn once tools are resolved.
|
|
245
|
+
* Returns `undefined` if the tool is absent or the registry is not yet
|
|
246
|
+
* initialized; use {@link resolveTool} when readiness is not already guaranteed.
|
|
247
|
+
*/
|
|
215
248
|
export function getTool(name: string): Tool | undefined {
|
|
216
249
|
return tools.get(name);
|
|
217
250
|
}
|
|
@@ -603,7 +636,9 @@ export function getMcpToolDefinitions(): Tool[] {
|
|
|
603
636
|
export function getPluginToolDefinitions(): Tool[] {
|
|
604
637
|
return Array.from(tools.values()).filter((t) => {
|
|
605
638
|
const owner = ownersByName.get(t.name);
|
|
606
|
-
if (owner?.kind !== "plugin")
|
|
639
|
+
if (owner?.kind !== "plugin") {
|
|
640
|
+
return false;
|
|
641
|
+
}
|
|
607
642
|
// Filter out tools contributed by disabled plugins at read time so
|
|
608
643
|
// `assistant plugins disable <name>` takes effect on the next turn
|
|
609
644
|
// without a daemon restart. Mirrors the `.disabled` sentinel filtering
|
|
@@ -619,9 +654,13 @@ export function getPluginToolDefinitions(): Tool[] {
|
|
|
619
654
|
export function getMcpToolsByServer(): Map<string, Tool[]> {
|
|
620
655
|
const byServer = new Map<string, Tool[]>();
|
|
621
656
|
for (const [name, owner] of ownersByName) {
|
|
622
|
-
if (owner.kind !== "mcp")
|
|
657
|
+
if (owner.kind !== "mcp") {
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
623
660
|
const tool = tools.get(name);
|
|
624
|
-
if (!tool)
|
|
661
|
+
if (!tool) {
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
625
664
|
let list = byServer.get(owner.id);
|
|
626
665
|
if (!list) {
|
|
627
666
|
list = [];
|
|
@@ -700,7 +739,9 @@ export function registerWorkspaceTools(
|
|
|
700
739
|
seenInBatch.add(tool.name);
|
|
701
740
|
|
|
702
741
|
const existing = tools.get(tool.name);
|
|
703
|
-
if (!existing)
|
|
742
|
+
if (!existing) {
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
704
745
|
|
|
705
746
|
const existingOwner = ownersByName.get(tool.name);
|
|
706
747
|
if (existingOwner?.kind === "workspace") {
|
|
@@ -712,7 +753,9 @@ export function registerWorkspaceTools(
|
|
|
712
753
|
// Built-in (default) tool — override allowed, handled in the mutation
|
|
713
754
|
// phase below. `undefined` shouldn't occur (every registered tool has an
|
|
714
755
|
// owner) but is treated the same as a built-in for safety.
|
|
715
|
-
if (!existingOwner || existingOwner.kind === "default")
|
|
756
|
+
if (!existingOwner || existingOwner.kind === "default") {
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
716
759
|
|
|
717
760
|
throw new Error(
|
|
718
761
|
`Workspace tool "${tool.name}" conflicts with an existing ${describeOwner(existingOwner)}. Workspace tools must register before other extension categories.`,
|
|
@@ -923,7 +966,9 @@ export function getWorkspaceToolDefinitions(): Tool[] {
|
|
|
923
966
|
export function getStrippedCoreToolNames(): string[] {
|
|
924
967
|
const stripped: string[] = [];
|
|
925
968
|
for (const name of coreToolOverrides.keys()) {
|
|
926
|
-
if (!tools.has(name))
|
|
969
|
+
if (!tools.has(name)) {
|
|
970
|
+
stripped.push(name);
|
|
971
|
+
}
|
|
927
972
|
}
|
|
928
973
|
return stripped;
|
|
929
974
|
}
|
|
@@ -968,7 +1013,32 @@ export function getAllToolDefinitions(): Tool[] {
|
|
|
968
1013
|
);
|
|
969
1014
|
}
|
|
970
1015
|
|
|
971
|
-
|
|
1016
|
+
/**
|
|
1017
|
+
* Idempotent, cached tool-registry initialization: resolve the tool manifest,
|
|
1018
|
+
* register the built-in (default) tools, and load workspace overrides. The
|
|
1019
|
+
* first call runs the work; every later call returns the same settled promise
|
|
1020
|
+
* without repeating it, so it is safe to call from multiple entry points or
|
|
1021
|
+
* lazily on demand.
|
|
1022
|
+
*
|
|
1023
|
+
* This is the tool-registry analogue of the hook registry's
|
|
1024
|
+
* `maybeReconcileFromSentinel()` — the lazy "make sure the registry is
|
|
1025
|
+
* populated" step. As the registry read getters migrate to async (mirroring
|
|
1026
|
+
* `getHooksFor`), they will `await` this before reading the map, so a read can
|
|
1027
|
+
* no longer observe an un-initialized registry.
|
|
1028
|
+
*/
|
|
1029
|
+
export function initializeTools(): Promise<void> {
|
|
1030
|
+
if (!toolsInitPromise) {
|
|
1031
|
+
toolsInitPromise = runToolInitialization().catch((err) => {
|
|
1032
|
+
// Don't cache a failed init: clear the slot so a later call retries
|
|
1033
|
+
// rather than returning the same rejected promise forever.
|
|
1034
|
+
toolsInitPromise = null;
|
|
1035
|
+
throw err;
|
|
1036
|
+
});
|
|
1037
|
+
}
|
|
1038
|
+
return toolsInitPromise;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
async function runToolInitialization(): Promise<void> {
|
|
972
1042
|
const { explicitTools } = await import("./tool-manifest.js");
|
|
973
1043
|
|
|
974
1044
|
// Capture tool names already in the registry before any manifest
|
|
@@ -1032,9 +1102,13 @@ export async function initializeTools(): Promise<void> {
|
|
|
1032
1102
|
coreToolsSnapshot = new Map<string, { tool: Tool; owner: OwnerInfo }>();
|
|
1033
1103
|
for (const [name, tool] of tools) {
|
|
1034
1104
|
const owner = ownersByName.get(name);
|
|
1035
|
-
if (owner?.kind === "skill" || owner?.kind === "plugin")
|
|
1105
|
+
if (owner?.kind === "skill" || owner?.kind === "plugin") {
|
|
1106
|
+
continue;
|
|
1107
|
+
}
|
|
1036
1108
|
// Exclude pre-existing tools not declared in the manifest
|
|
1037
|
-
if (preExisting.has(name) && !manifestToolNames.has(name))
|
|
1109
|
+
if (preExisting.has(name) && !manifestToolNames.has(name)) {
|
|
1110
|
+
continue;
|
|
1111
|
+
}
|
|
1038
1112
|
// Every registered tool carries an owner (built-ins get DEFAULT_TOOL_OWNER
|
|
1039
1113
|
// stamped by registerTool), so `owner` is defined here.
|
|
1040
1114
|
coreToolsSnapshot.set(name, { tool, owner: owner! });
|
|
@@ -1081,6 +1155,9 @@ export function __resetRegistryForTesting(): void {
|
|
|
1081
1155
|
// later registerWorkspaceTools() falsely report "overridesCore: true"
|
|
1082
1156
|
// against a fresh registry.
|
|
1083
1157
|
coreToolOverrides.clear();
|
|
1158
|
+
// Clear the cached init promise so a later initializeTools() re-runs against
|
|
1159
|
+
// the freshly reset registry rather than returning the previous settled run.
|
|
1160
|
+
toolsInitPromise = null;
|
|
1084
1161
|
|
|
1085
1162
|
if (coreToolsSnapshot) {
|
|
1086
1163
|
for (const [name, { tool, owner }] of coreToolsSnapshot) {
|
|
@@ -1101,6 +1178,7 @@ export function __clearRegistryForTesting(): void {
|
|
|
1101
1178
|
skillRefCount.clear();
|
|
1102
1179
|
pluginRefCount.clear();
|
|
1103
1180
|
coreToolOverrides.clear();
|
|
1181
|
+
toolsInitPromise = null;
|
|
1104
1182
|
}
|
|
1105
1183
|
|
|
1106
1184
|
/**
|