@dudousxd/nestjs-agent-telescope 0.8.61 → 0.9.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/index.cjs +251 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +70 -3
- package/dist/index.d.ts +70 -3
- package/dist/index.js +245 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -136,8 +136,8 @@ declare class RagTelescopeWatcher implements Watcher {
|
|
|
136
136
|
* correctly is the whole bug — hence no default here. A host that has a run viewer passes its own
|
|
137
137
|
* template; one that does not gets plain text, which is honest.
|
|
138
138
|
*
|
|
139
|
-
* Layout:
|
|
140
|
-
* Retrieval; Retrieval sources), each sized so its panel count is an exact multiple of its `cols` —
|
|
139
|
+
* Layout: nine sections (Overview lean; Spend; Reliability; Run outcomes; Activity; Approvals;
|
|
140
|
+
* Tools; Retrieval; Retrieval sources), each sized so its panel count is an exact multiple of its `cols` —
|
|
141
141
|
* no half-empty row. `nestjs-telescope`'s `ExtensionDashboardPage` renders a section as a
|
|
142
142
|
* `grid-cols-N` grid with one panel per cell and no `colSpan`, so a lone table in an otherwise-empty
|
|
143
143
|
* row would leave a visible gap next to it.
|
|
@@ -286,6 +286,48 @@ declare function ragCollectionsTableProvider(): DataProvider;
|
|
|
286
286
|
/** table → the slowest retrievals in the window. */
|
|
287
287
|
declare function ragSlowestTableProvider(): DataProvider;
|
|
288
288
|
|
|
289
|
+
interface AgentEntryContent {
|
|
290
|
+
event: string;
|
|
291
|
+
runId?: string;
|
|
292
|
+
threadId?: string;
|
|
293
|
+
toolName?: string;
|
|
294
|
+
toolType?: string;
|
|
295
|
+
status?: string;
|
|
296
|
+
steps?: number;
|
|
297
|
+
inputTokens?: number;
|
|
298
|
+
outputTokens?: number;
|
|
299
|
+
/** `run.finished`: turn start to the first `text` frame. */
|
|
300
|
+
ttftMs?: number;
|
|
301
|
+
/** `run.finished`: present on a delegated sub-agent's run. */
|
|
302
|
+
parentRunId?: string;
|
|
303
|
+
/** `run.failed`: the stable stream error code. */
|
|
304
|
+
code?: string;
|
|
305
|
+
/** `tool-call`: an outcome re-published by a run replaying its journal. */
|
|
306
|
+
replayed?: boolean;
|
|
307
|
+
}
|
|
308
|
+
interface StorageEntry {
|
|
309
|
+
content?: AgentEntryContent;
|
|
310
|
+
createdAt?: Date;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Time-to-first-token histogram over the recorded `run.finished` entries, plus p50/p95 of the raw
|
|
314
|
+
* samples. Top-level runs only — a delegated sub-agent streams into its parent's turn, so its first
|
|
315
|
+
* token is not one a person waited for (the same rule `RunMetrics.ttftP50Ms` applies). A run that
|
|
316
|
+
* streamed no text carries no `ttftMs` and is left out rather than counted as `0`.
|
|
317
|
+
*/
|
|
318
|
+
declare function toTtftDistribution(entries: StorageEntry[]): {
|
|
319
|
+
buckets: {
|
|
320
|
+
label: string;
|
|
321
|
+
count: number;
|
|
322
|
+
}[];
|
|
323
|
+
p50?: number;
|
|
324
|
+
p95?: number;
|
|
325
|
+
};
|
|
326
|
+
/** Failed runs by their stable error code, over the recorded `run.failed` entries. */
|
|
327
|
+
declare function toFailureCodeSegments(entries: StorageEntry[]): {
|
|
328
|
+
label: string;
|
|
329
|
+
value: number;
|
|
330
|
+
}[];
|
|
289
331
|
/** stat → total agent runs (run.finished entries). */
|
|
290
332
|
declare function agentRunsProvider(): DataProvider;
|
|
291
333
|
/** stat → total tokens across all finished runs. */
|
|
@@ -309,6 +351,21 @@ declare function agentTokensProvider(): DataProvider;
|
|
|
309
351
|
declare function agentToolsProvider(): DataProvider;
|
|
310
352
|
/** breakdown → tool-call status distribution. */
|
|
311
353
|
declare function agentToolStatusProvider(): DataProvider;
|
|
354
|
+
/**
|
|
355
|
+
* distribution → time to first token of the recorded top-level runs, from the `run.finished`
|
|
356
|
+
* diagnostics this extension's watcher keeps. Unlike the governance duration pair, these entries
|
|
357
|
+
* carry the raw per-run figure, so there ARE samples to bucket — at the cost of covering only what
|
|
358
|
+
* Telescope's own storage still holds.
|
|
359
|
+
*/
|
|
360
|
+
declare function agentRunsTtftDistributionProvider(): DataProvider;
|
|
361
|
+
/**
|
|
362
|
+
* breakdown → failed runs by error code, from the recorded `run.failed` diagnostics. Needs no store:
|
|
363
|
+
* the governance `agent.runs.errors` donut answers the same question over the range from the run
|
|
364
|
+
* rows, and this one keeps answering it for a host that records none.
|
|
365
|
+
*/
|
|
366
|
+
declare function agentRunFailureCodesProvider(): DataProvider;
|
|
367
|
+
/** stat → runs someone stopped (`run.cancelled` entries) — kept apart from failures on purpose. */
|
|
368
|
+
declare function agentRunsCancelledProvider(): DataProvider;
|
|
312
369
|
|
|
313
370
|
/** A breakdown-panel segment (Telescope core: `{ segments: Array<{ label, value, color? }> }`). */
|
|
314
371
|
interface BreakdownSegment {
|
|
@@ -405,6 +462,9 @@ interface RecentRunTableRow {
|
|
|
405
462
|
agentName: string;
|
|
406
463
|
status: string;
|
|
407
464
|
durationMs: number | string;
|
|
465
|
+
ttftMs: number | string;
|
|
466
|
+
costUsd: number | string;
|
|
467
|
+
modelId: string;
|
|
408
468
|
retries: number;
|
|
409
469
|
errorCode: string;
|
|
410
470
|
errorMessage: string;
|
|
@@ -478,6 +538,13 @@ declare function agentRunsRetriesProvider(): DataProvider;
|
|
|
478
538
|
* `null` percentile (no settled runs in range) resolves to 0.
|
|
479
539
|
*/
|
|
480
540
|
declare function agentRunsDurationProvider(): DataProvider;
|
|
541
|
+
/**
|
|
542
|
+
* stat → time-to-first-token percentile over the range's completed top-level runs, selected by
|
|
543
|
+
* `query.metric` exactly like {@link agentRunsDurationProvider}. A `null` percentile (no run in range
|
|
544
|
+
* recorded one) resolves to 0. The histogram beside it reads the raw samples off Telescope's own
|
|
545
|
+
* `run.finished` entries — `agent.runs.ttftDistribution`.
|
|
546
|
+
*/
|
|
547
|
+
declare function agentRunsTtftProvider(): DataProvider;
|
|
481
548
|
/** table → run/failure/retry rollup per agent. */
|
|
482
549
|
declare function agentRunsByAgentTableProvider(): DataProvider;
|
|
483
550
|
/** breakdown → failed runs by error code. */
|
|
@@ -509,4 +576,4 @@ declare function agentPendingApprovalsTableProvider(): DataProvider;
|
|
|
509
576
|
/** table → per-tool call/failure/rejection/latency rollup over the range. */
|
|
510
577
|
declare function agentToolStatsTableProvider(): DataProvider;
|
|
511
578
|
|
|
512
|
-
export { type AgentTelescopeExtensionOptions, AgentTelescopeWatcher, RAG_ENTRY_TYPE, type RagRetrieval, RagTelescopeWatcher, agentActorSpendTableProvider, agentDashboard, agentModelSpendTableProvider, agentPendingApprovalsCountProvider, agentPendingApprovalsTableProvider, agentRecentRunsTableProvider, agentRecentThreadsTableProvider, agentRecentToolCallsTableProvider, agentRunErrorsProvider, agentRunsByAgentTableProvider, agentRunsDurationProvider, agentRunsFailedProvider, agentRunsProvider, agentRunsRetriesProvider, agentRunsSuccessRateProvider, agentRunsTotalProvider, agentRunsTrendProvider, agentSpendByActorProvider, agentSpendByModelProvider, agentSpendTotalProvider, agentTelescopeExtension, agentTokensProvider, agentTokensTotalProvider, agentToolStatsTableProvider, agentToolStatusProvider, agentToolsProvider, agentTopThreadsTableProvider, agentUsageTrendProvider, capErrorMessage, meanChunks, percentile, ragChunksProvider, ragCollectionsTableProvider, ragLatencyProvider, ragRetrievalsProvider, ragRetrieverBreakdownProvider, ragScoresProvider, ragSlowestTableProvider, ragStoreBreakdownProvider, ragTrendProvider, ragZeroHitRateProvider, readRetrievals, resolveRange, shiftUtcDay, shortPromptHash, toActorSpendRows, toActorSpendSegments, toCollectionRows, toLatencyDistribution, toModelSpendRows, toModelSpendSegments, toPendingApprovalTableRows, toRagRetrieval, toRecentRunTableRows, toRecentThreadTableRows, toRecentToolCallRows, toRetrievalTrendRows, toRetrieverSegments, toRunAgentTableRows, toRunErrorSegments, toRunTrendRows, toScoreDistribution, toSlowestRows, toStoreSegments, toThreadSpendRows, toToolStatTableRows, toUsageTrendRows, totalCostUsd, totalTokens, zeroHitRate };
|
|
579
|
+
export { type AgentTelescopeExtensionOptions, AgentTelescopeWatcher, RAG_ENTRY_TYPE, type RagRetrieval, RagTelescopeWatcher, agentActorSpendTableProvider, agentDashboard, agentModelSpendTableProvider, agentPendingApprovalsCountProvider, agentPendingApprovalsTableProvider, agentRecentRunsTableProvider, agentRecentThreadsTableProvider, agentRecentToolCallsTableProvider, agentRunErrorsProvider, agentRunFailureCodesProvider, agentRunsByAgentTableProvider, agentRunsCancelledProvider, agentRunsDurationProvider, agentRunsFailedProvider, agentRunsProvider, agentRunsRetriesProvider, agentRunsSuccessRateProvider, agentRunsTotalProvider, agentRunsTrendProvider, agentRunsTtftDistributionProvider, agentRunsTtftProvider, agentSpendByActorProvider, agentSpendByModelProvider, agentSpendTotalProvider, agentTelescopeExtension, agentTokensProvider, agentTokensTotalProvider, agentToolStatsTableProvider, agentToolStatusProvider, agentToolsProvider, agentTopThreadsTableProvider, agentUsageTrendProvider, capErrorMessage, meanChunks, percentile, ragChunksProvider, ragCollectionsTableProvider, ragLatencyProvider, ragRetrievalsProvider, ragRetrieverBreakdownProvider, ragScoresProvider, ragSlowestTableProvider, ragStoreBreakdownProvider, ragTrendProvider, ragZeroHitRateProvider, readRetrievals, resolveRange, shiftUtcDay, shortPromptHash, toActorSpendRows, toActorSpendSegments, toCollectionRows, toFailureCodeSegments, toLatencyDistribution, toModelSpendRows, toModelSpendSegments, toPendingApprovalTableRows, toRagRetrieval, toRecentRunTableRows, toRecentThreadTableRows, toRecentToolCallRows, toRetrievalTrendRows, toRetrieverSegments, toRunAgentTableRows, toRunErrorSegments, toRunTrendRows, toScoreDistribution, toSlowestRows, toStoreSegments, toThreadSpendRows, toToolStatTableRows, toTtftDistribution, toUsageTrendRows, totalCostUsd, totalTokens, zeroHitRate };
|
package/dist/index.d.ts
CHANGED
|
@@ -136,8 +136,8 @@ declare class RagTelescopeWatcher implements Watcher {
|
|
|
136
136
|
* correctly is the whole bug — hence no default here. A host that has a run viewer passes its own
|
|
137
137
|
* template; one that does not gets plain text, which is honest.
|
|
138
138
|
*
|
|
139
|
-
* Layout:
|
|
140
|
-
* Retrieval; Retrieval sources), each sized so its panel count is an exact multiple of its `cols` —
|
|
139
|
+
* Layout: nine sections (Overview lean; Spend; Reliability; Run outcomes; Activity; Approvals;
|
|
140
|
+
* Tools; Retrieval; Retrieval sources), each sized so its panel count is an exact multiple of its `cols` —
|
|
141
141
|
* no half-empty row. `nestjs-telescope`'s `ExtensionDashboardPage` renders a section as a
|
|
142
142
|
* `grid-cols-N` grid with one panel per cell and no `colSpan`, so a lone table in an otherwise-empty
|
|
143
143
|
* row would leave a visible gap next to it.
|
|
@@ -286,6 +286,48 @@ declare function ragCollectionsTableProvider(): DataProvider;
|
|
|
286
286
|
/** table → the slowest retrievals in the window. */
|
|
287
287
|
declare function ragSlowestTableProvider(): DataProvider;
|
|
288
288
|
|
|
289
|
+
interface AgentEntryContent {
|
|
290
|
+
event: string;
|
|
291
|
+
runId?: string;
|
|
292
|
+
threadId?: string;
|
|
293
|
+
toolName?: string;
|
|
294
|
+
toolType?: string;
|
|
295
|
+
status?: string;
|
|
296
|
+
steps?: number;
|
|
297
|
+
inputTokens?: number;
|
|
298
|
+
outputTokens?: number;
|
|
299
|
+
/** `run.finished`: turn start to the first `text` frame. */
|
|
300
|
+
ttftMs?: number;
|
|
301
|
+
/** `run.finished`: present on a delegated sub-agent's run. */
|
|
302
|
+
parentRunId?: string;
|
|
303
|
+
/** `run.failed`: the stable stream error code. */
|
|
304
|
+
code?: string;
|
|
305
|
+
/** `tool-call`: an outcome re-published by a run replaying its journal. */
|
|
306
|
+
replayed?: boolean;
|
|
307
|
+
}
|
|
308
|
+
interface StorageEntry {
|
|
309
|
+
content?: AgentEntryContent;
|
|
310
|
+
createdAt?: Date;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Time-to-first-token histogram over the recorded `run.finished` entries, plus p50/p95 of the raw
|
|
314
|
+
* samples. Top-level runs only — a delegated sub-agent streams into its parent's turn, so its first
|
|
315
|
+
* token is not one a person waited for (the same rule `RunMetrics.ttftP50Ms` applies). A run that
|
|
316
|
+
* streamed no text carries no `ttftMs` and is left out rather than counted as `0`.
|
|
317
|
+
*/
|
|
318
|
+
declare function toTtftDistribution(entries: StorageEntry[]): {
|
|
319
|
+
buckets: {
|
|
320
|
+
label: string;
|
|
321
|
+
count: number;
|
|
322
|
+
}[];
|
|
323
|
+
p50?: number;
|
|
324
|
+
p95?: number;
|
|
325
|
+
};
|
|
326
|
+
/** Failed runs by their stable error code, over the recorded `run.failed` entries. */
|
|
327
|
+
declare function toFailureCodeSegments(entries: StorageEntry[]): {
|
|
328
|
+
label: string;
|
|
329
|
+
value: number;
|
|
330
|
+
}[];
|
|
289
331
|
/** stat → total agent runs (run.finished entries). */
|
|
290
332
|
declare function agentRunsProvider(): DataProvider;
|
|
291
333
|
/** stat → total tokens across all finished runs. */
|
|
@@ -309,6 +351,21 @@ declare function agentTokensProvider(): DataProvider;
|
|
|
309
351
|
declare function agentToolsProvider(): DataProvider;
|
|
310
352
|
/** breakdown → tool-call status distribution. */
|
|
311
353
|
declare function agentToolStatusProvider(): DataProvider;
|
|
354
|
+
/**
|
|
355
|
+
* distribution → time to first token of the recorded top-level runs, from the `run.finished`
|
|
356
|
+
* diagnostics this extension's watcher keeps. Unlike the governance duration pair, these entries
|
|
357
|
+
* carry the raw per-run figure, so there ARE samples to bucket — at the cost of covering only what
|
|
358
|
+
* Telescope's own storage still holds.
|
|
359
|
+
*/
|
|
360
|
+
declare function agentRunsTtftDistributionProvider(): DataProvider;
|
|
361
|
+
/**
|
|
362
|
+
* breakdown → failed runs by error code, from the recorded `run.failed` diagnostics. Needs no store:
|
|
363
|
+
* the governance `agent.runs.errors` donut answers the same question over the range from the run
|
|
364
|
+
* rows, and this one keeps answering it for a host that records none.
|
|
365
|
+
*/
|
|
366
|
+
declare function agentRunFailureCodesProvider(): DataProvider;
|
|
367
|
+
/** stat → runs someone stopped (`run.cancelled` entries) — kept apart from failures on purpose. */
|
|
368
|
+
declare function agentRunsCancelledProvider(): DataProvider;
|
|
312
369
|
|
|
313
370
|
/** A breakdown-panel segment (Telescope core: `{ segments: Array<{ label, value, color? }> }`). */
|
|
314
371
|
interface BreakdownSegment {
|
|
@@ -405,6 +462,9 @@ interface RecentRunTableRow {
|
|
|
405
462
|
agentName: string;
|
|
406
463
|
status: string;
|
|
407
464
|
durationMs: number | string;
|
|
465
|
+
ttftMs: number | string;
|
|
466
|
+
costUsd: number | string;
|
|
467
|
+
modelId: string;
|
|
408
468
|
retries: number;
|
|
409
469
|
errorCode: string;
|
|
410
470
|
errorMessage: string;
|
|
@@ -478,6 +538,13 @@ declare function agentRunsRetriesProvider(): DataProvider;
|
|
|
478
538
|
* `null` percentile (no settled runs in range) resolves to 0.
|
|
479
539
|
*/
|
|
480
540
|
declare function agentRunsDurationProvider(): DataProvider;
|
|
541
|
+
/**
|
|
542
|
+
* stat → time-to-first-token percentile over the range's completed top-level runs, selected by
|
|
543
|
+
* `query.metric` exactly like {@link agentRunsDurationProvider}. A `null` percentile (no run in range
|
|
544
|
+
* recorded one) resolves to 0. The histogram beside it reads the raw samples off Telescope's own
|
|
545
|
+
* `run.finished` entries — `agent.runs.ttftDistribution`.
|
|
546
|
+
*/
|
|
547
|
+
declare function agentRunsTtftProvider(): DataProvider;
|
|
481
548
|
/** table → run/failure/retry rollup per agent. */
|
|
482
549
|
declare function agentRunsByAgentTableProvider(): DataProvider;
|
|
483
550
|
/** breakdown → failed runs by error code. */
|
|
@@ -509,4 +576,4 @@ declare function agentPendingApprovalsTableProvider(): DataProvider;
|
|
|
509
576
|
/** table → per-tool call/failure/rejection/latency rollup over the range. */
|
|
510
577
|
declare function agentToolStatsTableProvider(): DataProvider;
|
|
511
578
|
|
|
512
|
-
export { type AgentTelescopeExtensionOptions, AgentTelescopeWatcher, RAG_ENTRY_TYPE, type RagRetrieval, RagTelescopeWatcher, agentActorSpendTableProvider, agentDashboard, agentModelSpendTableProvider, agentPendingApprovalsCountProvider, agentPendingApprovalsTableProvider, agentRecentRunsTableProvider, agentRecentThreadsTableProvider, agentRecentToolCallsTableProvider, agentRunErrorsProvider, agentRunsByAgentTableProvider, agentRunsDurationProvider, agentRunsFailedProvider, agentRunsProvider, agentRunsRetriesProvider, agentRunsSuccessRateProvider, agentRunsTotalProvider, agentRunsTrendProvider, agentSpendByActorProvider, agentSpendByModelProvider, agentSpendTotalProvider, agentTelescopeExtension, agentTokensProvider, agentTokensTotalProvider, agentToolStatsTableProvider, agentToolStatusProvider, agentToolsProvider, agentTopThreadsTableProvider, agentUsageTrendProvider, capErrorMessage, meanChunks, percentile, ragChunksProvider, ragCollectionsTableProvider, ragLatencyProvider, ragRetrievalsProvider, ragRetrieverBreakdownProvider, ragScoresProvider, ragSlowestTableProvider, ragStoreBreakdownProvider, ragTrendProvider, ragZeroHitRateProvider, readRetrievals, resolveRange, shiftUtcDay, shortPromptHash, toActorSpendRows, toActorSpendSegments, toCollectionRows, toLatencyDistribution, toModelSpendRows, toModelSpendSegments, toPendingApprovalTableRows, toRagRetrieval, toRecentRunTableRows, toRecentThreadTableRows, toRecentToolCallRows, toRetrievalTrendRows, toRetrieverSegments, toRunAgentTableRows, toRunErrorSegments, toRunTrendRows, toScoreDistribution, toSlowestRows, toStoreSegments, toThreadSpendRows, toToolStatTableRows, toUsageTrendRows, totalCostUsd, totalTokens, zeroHitRate };
|
|
579
|
+
export { type AgentTelescopeExtensionOptions, AgentTelescopeWatcher, RAG_ENTRY_TYPE, type RagRetrieval, RagTelescopeWatcher, agentActorSpendTableProvider, agentDashboard, agentModelSpendTableProvider, agentPendingApprovalsCountProvider, agentPendingApprovalsTableProvider, agentRecentRunsTableProvider, agentRecentThreadsTableProvider, agentRecentToolCallsTableProvider, agentRunErrorsProvider, agentRunFailureCodesProvider, agentRunsByAgentTableProvider, agentRunsCancelledProvider, agentRunsDurationProvider, agentRunsFailedProvider, agentRunsProvider, agentRunsRetriesProvider, agentRunsSuccessRateProvider, agentRunsTotalProvider, agentRunsTrendProvider, agentRunsTtftDistributionProvider, agentRunsTtftProvider, agentSpendByActorProvider, agentSpendByModelProvider, agentSpendTotalProvider, agentTelescopeExtension, agentTokensProvider, agentTokensTotalProvider, agentToolStatsTableProvider, agentToolStatusProvider, agentToolsProvider, agentTopThreadsTableProvider, agentUsageTrendProvider, capErrorMessage, meanChunks, percentile, ragChunksProvider, ragCollectionsTableProvider, ragLatencyProvider, ragRetrievalsProvider, ragRetrieverBreakdownProvider, ragScoresProvider, ragSlowestTableProvider, ragStoreBreakdownProvider, ragTrendProvider, ragZeroHitRateProvider, readRetrievals, resolveRange, shiftUtcDay, shortPromptHash, toActorSpendRows, toActorSpendSegments, toCollectionRows, toFailureCodeSegments, toLatencyDistribution, toModelSpendRows, toModelSpendSegments, toPendingApprovalTableRows, toRagRetrieval, toRecentRunTableRows, toRecentThreadTableRows, toRecentToolCallRows, toRetrievalTrendRows, toRetrieverSegments, toRunAgentTableRows, toRunErrorSegments, toRunTrendRows, toScoreDistribution, toSlowestRows, toStoreSegments, toThreadSpendRows, toToolStatTableRows, toTtftDistribution, toUsageTrendRows, totalCostUsd, totalTokens, zeroHitRate };
|
package/dist/index.js
CHANGED
|
@@ -244,6 +244,43 @@ function agentDashboard(opts = {}) {
|
|
|
244
244
|
},
|
|
245
245
|
// Two duration stats above, not a `distribution` panel: RunMetrics carries only p50/p95
|
|
246
246
|
// (no raw samples to bucket), so a histogram here would be a permanently-empty box.
|
|
247
|
+
{
|
|
248
|
+
kind: "stat",
|
|
249
|
+
title: "TTFT p50",
|
|
250
|
+
data: {
|
|
251
|
+
provider: "agent.runs.ttft",
|
|
252
|
+
query: {
|
|
253
|
+
metric: "p50"
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
format: "duration"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
kind: "stat",
|
|
260
|
+
title: "TTFT p95",
|
|
261
|
+
data: {
|
|
262
|
+
provider: "agent.runs.ttft",
|
|
263
|
+
query: {
|
|
264
|
+
metric: "p95"
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
format: "duration"
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
// The one histogram in this section: `run.finished` diagnostics carry each run's own
|
|
271
|
+
// `ttftMs`, so the watcher-recorded entries DO have samples to bucket (over what
|
|
272
|
+
// Telescope's storage still holds, not the governance range).
|
|
273
|
+
kind: "distribution",
|
|
274
|
+
title: "Time to first token",
|
|
275
|
+
data: {
|
|
276
|
+
provider: "agent.runs.ttftDistribution"
|
|
277
|
+
},
|
|
278
|
+
markers: [
|
|
279
|
+
"p50",
|
|
280
|
+
"p95"
|
|
281
|
+
],
|
|
282
|
+
format: "duration"
|
|
283
|
+
},
|
|
247
284
|
{
|
|
248
285
|
kind: "timeseries",
|
|
249
286
|
title: "Runs & failures",
|
|
@@ -291,6 +328,30 @@ function agentDashboard(opts = {}) {
|
|
|
291
328
|
}
|
|
292
329
|
]
|
|
293
330
|
},
|
|
331
|
+
{
|
|
332
|
+
// Live, from the watcher-recorded diagnostics rather than the run rows: what failed and
|
|
333
|
+
// what was stopped, readable on a host that binds no governance read-model. A cancel is
|
|
334
|
+
// its own number — a user pressing Stop is the control working, not a failure.
|
|
335
|
+
title: "Run outcomes",
|
|
336
|
+
cols: 2,
|
|
337
|
+
panels: [
|
|
338
|
+
{
|
|
339
|
+
kind: "breakdown",
|
|
340
|
+
title: "Failures by code",
|
|
341
|
+
data: {
|
|
342
|
+
provider: "agent.runs.failureCodes"
|
|
343
|
+
},
|
|
344
|
+
style: "donut"
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
kind: "stat",
|
|
348
|
+
title: "Cancelled",
|
|
349
|
+
data: {
|
|
350
|
+
provider: "agent.runs.cancelled"
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
]
|
|
354
|
+
},
|
|
294
355
|
{
|
|
295
356
|
// The paged list tables: tool calls, threads, runs — each reads the paged SPI
|
|
296
357
|
// (toolCallsPage/threadsPage/runsPage via `agent.*.paged`) and opts into the renderer's
|
|
@@ -687,6 +748,82 @@ function ofEvent(entries, event) {
|
|
|
687
748
|
return entries.filter((entry) => entry.content?.event === event);
|
|
688
749
|
}
|
|
689
750
|
__name(ofEvent, "ofEvent");
|
|
751
|
+
function firstToolCalls(entries) {
|
|
752
|
+
return ofEvent(entries, "tool-call").filter((entry) => entry.content?.replayed !== true);
|
|
753
|
+
}
|
|
754
|
+
__name(firstToolCalls, "firstToolCalls");
|
|
755
|
+
function percentileOf(samples, fraction) {
|
|
756
|
+
if (samples.length === 0) {
|
|
757
|
+
return null;
|
|
758
|
+
}
|
|
759
|
+
const sorted = [
|
|
760
|
+
...samples
|
|
761
|
+
].sort((a, b) => a - b);
|
|
762
|
+
const rank = Math.ceil(fraction * sorted.length);
|
|
763
|
+
return sorted[Math.min(Math.max(rank, 1), sorted.length) - 1] ?? null;
|
|
764
|
+
}
|
|
765
|
+
__name(percentileOf, "percentileOf");
|
|
766
|
+
var TTFT_EDGES = [
|
|
767
|
+
250,
|
|
768
|
+
500,
|
|
769
|
+
1e3,
|
|
770
|
+
2e3,
|
|
771
|
+
4e3,
|
|
772
|
+
8e3,
|
|
773
|
+
16e3
|
|
774
|
+
];
|
|
775
|
+
function ttftLabel(index) {
|
|
776
|
+
const upper = TTFT_EDGES[index];
|
|
777
|
+
if (upper === void 0) {
|
|
778
|
+
return `\u2265${TTFT_EDGES[TTFT_EDGES.length - 1] ?? 0}ms`;
|
|
779
|
+
}
|
|
780
|
+
return `${index === 0 ? 0 : TTFT_EDGES[index - 1] ?? 0}\u2013${upper}ms`;
|
|
781
|
+
}
|
|
782
|
+
__name(ttftLabel, "ttftLabel");
|
|
783
|
+
function toTtftDistribution(entries) {
|
|
784
|
+
const samples = [];
|
|
785
|
+
const counts = new Array(TTFT_EDGES.length + 1).fill(0);
|
|
786
|
+
for (const entry of ofEvent(entries, "run.finished")) {
|
|
787
|
+
const ttftMs = entry.content?.ttftMs;
|
|
788
|
+
if (typeof ttftMs !== "number" || entry.content?.parentRunId !== void 0) {
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
samples.push(ttftMs);
|
|
792
|
+
const found = TTFT_EDGES.findIndex((edge) => ttftMs < edge);
|
|
793
|
+
const index = found === -1 ? TTFT_EDGES.length : found;
|
|
794
|
+
counts[index] = (counts[index] ?? 0) + 1;
|
|
795
|
+
}
|
|
796
|
+
const buckets = counts.map((count, index) => ({
|
|
797
|
+
label: ttftLabel(index),
|
|
798
|
+
count
|
|
799
|
+
}));
|
|
800
|
+
const p50 = percentileOf(samples, 0.5);
|
|
801
|
+
const p95 = percentileOf(samples, 0.95);
|
|
802
|
+
return {
|
|
803
|
+
buckets,
|
|
804
|
+
...p50 !== null ? {
|
|
805
|
+
p50
|
|
806
|
+
} : {},
|
|
807
|
+
...p95 !== null ? {
|
|
808
|
+
p95
|
|
809
|
+
} : {}
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
__name(toTtftDistribution, "toTtftDistribution");
|
|
813
|
+
function toFailureCodeSegments(entries) {
|
|
814
|
+
const counts = /* @__PURE__ */ new Map();
|
|
815
|
+
for (const entry of ofEvent(entries, "run.failed")) {
|
|
816
|
+
const code = entry.content?.code ?? "unknown";
|
|
817
|
+
counts.set(code, (counts.get(code) ?? 0) + 1);
|
|
818
|
+
}
|
|
819
|
+
return [
|
|
820
|
+
...counts.entries()
|
|
821
|
+
].map(([label, value]) => ({
|
|
822
|
+
label,
|
|
823
|
+
value
|
|
824
|
+
})).sort((a, b) => b.value - a.value);
|
|
825
|
+
}
|
|
826
|
+
__name(toFailureCodeSegments, "toFailureCodeSegments");
|
|
690
827
|
function agentRunsProvider() {
|
|
691
828
|
return {
|
|
692
829
|
name: "agent.runs",
|
|
@@ -716,7 +853,7 @@ function agentToolsProvider() {
|
|
|
716
853
|
return {
|
|
717
854
|
name: "agent.tools",
|
|
718
855
|
async resolve(_query, ctx) {
|
|
719
|
-
const calls =
|
|
856
|
+
const calls = firstToolCalls(await fetchEntries(ctx)).slice(-50).reverse().map((entry) => ({
|
|
720
857
|
toolName: entry.content?.toolName ?? "",
|
|
721
858
|
toolType: entry.content?.toolType ?? "",
|
|
722
859
|
status: entry.content?.status ?? "",
|
|
@@ -733,7 +870,7 @@ function agentToolStatusProvider() {
|
|
|
733
870
|
return {
|
|
734
871
|
name: "agent.toolStatus",
|
|
735
872
|
async resolve(_query, ctx) {
|
|
736
|
-
const calls =
|
|
873
|
+
const calls = firstToolCalls(await fetchEntries(ctx));
|
|
737
874
|
const counts = /* @__PURE__ */ new Map();
|
|
738
875
|
for (const call of calls) {
|
|
739
876
|
const status = call.content?.status ?? "unknown";
|
|
@@ -751,6 +888,37 @@ function agentToolStatusProvider() {
|
|
|
751
888
|
};
|
|
752
889
|
}
|
|
753
890
|
__name(agentToolStatusProvider, "agentToolStatusProvider");
|
|
891
|
+
function agentRunsTtftDistributionProvider() {
|
|
892
|
+
return {
|
|
893
|
+
name: "agent.runs.ttftDistribution",
|
|
894
|
+
async resolve(_query, ctx) {
|
|
895
|
+
return toTtftDistribution(await fetchEntries(ctx));
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
__name(agentRunsTtftDistributionProvider, "agentRunsTtftDistributionProvider");
|
|
900
|
+
function agentRunFailureCodesProvider() {
|
|
901
|
+
return {
|
|
902
|
+
name: "agent.runs.failureCodes",
|
|
903
|
+
async resolve(_query, ctx) {
|
|
904
|
+
return {
|
|
905
|
+
segments: toFailureCodeSegments(await fetchEntries(ctx))
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
__name(agentRunFailureCodesProvider, "agentRunFailureCodesProvider");
|
|
911
|
+
function agentRunsCancelledProvider() {
|
|
912
|
+
return {
|
|
913
|
+
name: "agent.runs.cancelled",
|
|
914
|
+
async resolve(_query, ctx) {
|
|
915
|
+
return {
|
|
916
|
+
value: ofEvent(await fetchEntries(ctx), "run.cancelled").length
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
__name(agentRunsCancelledProvider, "agentRunsCancelledProvider");
|
|
754
922
|
|
|
755
923
|
// src/agent-governance-providers.ts
|
|
756
924
|
import { AGENT_GOVERNANCE_QUERIES } from "@dudousxd/nestjs-agent-core";
|
|
@@ -908,6 +1076,9 @@ function toRecentRunTableRows(rows) {
|
|
|
908
1076
|
agentName: row.agentName ?? NO_VALUE,
|
|
909
1077
|
status: row.status,
|
|
910
1078
|
durationMs: row.durationMs ?? NO_VALUE,
|
|
1079
|
+
ttftMs: row.ttftMs ?? NO_VALUE,
|
|
1080
|
+
costUsd: row.costUsd ?? NO_VALUE,
|
|
1081
|
+
modelId: row.modelId ?? NO_VALUE,
|
|
911
1082
|
retries: row.retries,
|
|
912
1083
|
errorCode: row.errorCode ?? NO_VALUE,
|
|
913
1084
|
errorMessage: capErrorMessage(row.errorMessage) ?? NO_VALUE,
|
|
@@ -955,8 +1126,47 @@ var EMPTY_RUN_METRICS = {
|
|
|
955
1126
|
successRate: 0,
|
|
956
1127
|
retries: 0,
|
|
957
1128
|
durationP50Ms: null,
|
|
958
|
-
durationP95Ms: null
|
|
1129
|
+
durationP95Ms: null,
|
|
1130
|
+
ttftP50Ms: null,
|
|
1131
|
+
ttftP95Ms: null
|
|
959
1132
|
};
|
|
1133
|
+
var SHARED_READ_MS = 1e3;
|
|
1134
|
+
var sharedReads = /* @__PURE__ */ new WeakMap();
|
|
1135
|
+
function sharedRead(queries, key, read) {
|
|
1136
|
+
let reads = sharedReads.get(queries);
|
|
1137
|
+
if (reads === void 0) {
|
|
1138
|
+
reads = /* @__PURE__ */ new Map();
|
|
1139
|
+
sharedReads.set(queries, reads);
|
|
1140
|
+
}
|
|
1141
|
+
const pending = reads.get(key);
|
|
1142
|
+
if (pending !== void 0) {
|
|
1143
|
+
return pending;
|
|
1144
|
+
}
|
|
1145
|
+
const started = read();
|
|
1146
|
+
reads.set(key, started);
|
|
1147
|
+
const forget = /* @__PURE__ */ __name(() => {
|
|
1148
|
+
if (reads.get(key) === started) reads.delete(key);
|
|
1149
|
+
}, "forget");
|
|
1150
|
+
started.then(() => setTimeout(forget, SHARED_READ_MS).unref(), forget);
|
|
1151
|
+
return started;
|
|
1152
|
+
}
|
|
1153
|
+
__name(sharedRead, "sharedRead");
|
|
1154
|
+
function rangeKey(method, range) {
|
|
1155
|
+
return `${method}|${range.fromDay}|${range.toDay}`;
|
|
1156
|
+
}
|
|
1157
|
+
__name(rangeKey, "rangeKey");
|
|
1158
|
+
function spendByModel(queries, range) {
|
|
1159
|
+
return sharedRead(queries, rangeKey("spendByModel", range), () => queries.spendByModel(range));
|
|
1160
|
+
}
|
|
1161
|
+
__name(spendByModel, "spendByModel");
|
|
1162
|
+
function spendByActor(queries, range) {
|
|
1163
|
+
return sharedRead(queries, rangeKey("spendByActor", range), () => queries.spendByActor(range));
|
|
1164
|
+
}
|
|
1165
|
+
__name(spendByActor, "spendByActor");
|
|
1166
|
+
function runMetrics(queries, range) {
|
|
1167
|
+
return sharedRead(queries, rangeKey("runMetrics", range), () => queries.runMetrics(range));
|
|
1168
|
+
}
|
|
1169
|
+
__name(runMetrics, "runMetrics");
|
|
960
1170
|
function governanceStatProvider(name, fetch, format) {
|
|
961
1171
|
return {
|
|
962
1172
|
name,
|
|
@@ -969,25 +1179,25 @@ function governanceStatProvider(name, fetch, format) {
|
|
|
969
1179
|
}
|
|
970
1180
|
__name(governanceStatProvider, "governanceStatProvider");
|
|
971
1181
|
function agentSpendTotalProvider() {
|
|
972
|
-
return governanceStatProvider("agent.spend.totalCost", (queries, range) =>
|
|
1182
|
+
return governanceStatProvider("agent.spend.totalCost", (queries, range) => spendByModel(queries, range), (rows) => ({
|
|
973
1183
|
value: totalCostUsd(rows)
|
|
974
1184
|
}));
|
|
975
1185
|
}
|
|
976
1186
|
__name(agentSpendTotalProvider, "agentSpendTotalProvider");
|
|
977
1187
|
function agentTokensTotalProvider() {
|
|
978
|
-
return governanceStatProvider("agent.spend.totalTokens", (queries, range) =>
|
|
1188
|
+
return governanceStatProvider("agent.spend.totalTokens", (queries, range) => spendByModel(queries, range), (rows) => ({
|
|
979
1189
|
value: totalTokens(rows)
|
|
980
1190
|
}));
|
|
981
1191
|
}
|
|
982
1192
|
__name(agentTokensTotalProvider, "agentTokensTotalProvider");
|
|
983
1193
|
function agentSpendByModelProvider() {
|
|
984
|
-
return governanceStatProvider("agent.spend.byModel", (queries, range) =>
|
|
1194
|
+
return governanceStatProvider("agent.spend.byModel", (queries, range) => spendByModel(queries, range), (rows) => ({
|
|
985
1195
|
segments: toModelSpendSegments(rows)
|
|
986
1196
|
}));
|
|
987
1197
|
}
|
|
988
1198
|
__name(agentSpendByModelProvider, "agentSpendByModelProvider");
|
|
989
1199
|
function agentModelSpendTableProvider() {
|
|
990
|
-
return governanceStatProvider("agent.spend.byModelTable", (queries, range) =>
|
|
1200
|
+
return governanceStatProvider("agent.spend.byModelTable", (queries, range) => spendByModel(queries, range), (rows) => ({
|
|
991
1201
|
rows: toModelSpendRows(rows)
|
|
992
1202
|
}));
|
|
993
1203
|
}
|
|
@@ -999,13 +1209,13 @@ function agentUsageTrendProvider() {
|
|
|
999
1209
|
}
|
|
1000
1210
|
__name(agentUsageTrendProvider, "agentUsageTrendProvider");
|
|
1001
1211
|
function agentActorSpendTableProvider() {
|
|
1002
|
-
return governanceStatProvider("agent.spend.byActor", (queries, range) =>
|
|
1212
|
+
return governanceStatProvider("agent.spend.byActor", (queries, range) => spendByActor(queries, range), (rows) => ({
|
|
1003
1213
|
rows: toActorSpendRows(rows)
|
|
1004
1214
|
}));
|
|
1005
1215
|
}
|
|
1006
1216
|
__name(agentActorSpendTableProvider, "agentActorSpendTableProvider");
|
|
1007
1217
|
function agentSpendByActorProvider() {
|
|
1008
|
-
return governanceStatProvider("agent.spend.byActorShare", (queries, range) =>
|
|
1218
|
+
return governanceStatProvider("agent.spend.byActorShare", (queries, range) => spendByActor(queries, range), (rows) => ({
|
|
1009
1219
|
segments: toActorSpendSegments(rows)
|
|
1010
1220
|
}));
|
|
1011
1221
|
}
|
|
@@ -1021,7 +1231,7 @@ function governanceRunMetricsProvider(name, format) {
|
|
|
1021
1231
|
name,
|
|
1022
1232
|
async resolve(query, ctx) {
|
|
1023
1233
|
const queries = resolveGovernanceQueries(ctx);
|
|
1024
|
-
const metrics = queries ? await
|
|
1234
|
+
const metrics = queries ? await runMetrics(queries, resolveRange(query)) : EMPTY_RUN_METRICS;
|
|
1025
1235
|
return format(metrics);
|
|
1026
1236
|
}
|
|
1027
1237
|
};
|
|
@@ -1056,7 +1266,7 @@ function agentRunsDurationProvider() {
|
|
|
1056
1266
|
name: "agent.runs.duration",
|
|
1057
1267
|
async resolve(query, ctx) {
|
|
1058
1268
|
const queries = resolveGovernanceQueries(ctx);
|
|
1059
|
-
const metrics = queries ? await
|
|
1269
|
+
const metrics = queries ? await runMetrics(queries, resolveRange(query)) : EMPTY_RUN_METRICS;
|
|
1060
1270
|
const value = query?.metric === "p95" ? metrics.durationP95Ms : metrics.durationP50Ms;
|
|
1061
1271
|
return {
|
|
1062
1272
|
value: value ?? 0
|
|
@@ -1065,6 +1275,20 @@ function agentRunsDurationProvider() {
|
|
|
1065
1275
|
};
|
|
1066
1276
|
}
|
|
1067
1277
|
__name(agentRunsDurationProvider, "agentRunsDurationProvider");
|
|
1278
|
+
function agentRunsTtftProvider() {
|
|
1279
|
+
return {
|
|
1280
|
+
name: "agent.runs.ttft",
|
|
1281
|
+
async resolve(query, ctx) {
|
|
1282
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
1283
|
+
const metrics = queries ? await runMetrics(queries, resolveRange(query)) : EMPTY_RUN_METRICS;
|
|
1284
|
+
const value = query?.metric === "p95" ? metrics.ttftP95Ms : metrics.ttftP50Ms;
|
|
1285
|
+
return {
|
|
1286
|
+
value: value ?? 0
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
__name(agentRunsTtftProvider, "agentRunsTtftProvider");
|
|
1068
1292
|
function agentRunsByAgentTableProvider() {
|
|
1069
1293
|
return governanceStatProvider("agent.runs.byAgent", (queries, range) => queries.runsByAgent(range), (rows) => ({
|
|
1070
1294
|
rows: toRunAgentTableRows(rows)
|
|
@@ -1733,6 +1957,10 @@ function agentTelescopeExtension(opts = {}) {
|
|
|
1733
1957
|
agentRunsFailedProvider(),
|
|
1734
1958
|
agentRunsRetriesProvider(),
|
|
1735
1959
|
agentRunsDurationProvider(),
|
|
1960
|
+
agentRunsTtftProvider(),
|
|
1961
|
+
agentRunsTtftDistributionProvider(),
|
|
1962
|
+
agentRunFailureCodesProvider(),
|
|
1963
|
+
agentRunsCancelledProvider(),
|
|
1736
1964
|
agentRunsByAgentTableProvider(),
|
|
1737
1965
|
agentRunErrorsProvider(),
|
|
1738
1966
|
agentRunsTrendProvider(),
|
|
@@ -1773,7 +2001,9 @@ export {
|
|
|
1773
2001
|
agentRecentThreadsTableProvider,
|
|
1774
2002
|
agentRecentToolCallsTableProvider,
|
|
1775
2003
|
agentRunErrorsProvider,
|
|
2004
|
+
agentRunFailureCodesProvider,
|
|
1776
2005
|
agentRunsByAgentTableProvider,
|
|
2006
|
+
agentRunsCancelledProvider,
|
|
1777
2007
|
agentRunsDurationProvider,
|
|
1778
2008
|
agentRunsFailedProvider,
|
|
1779
2009
|
agentRunsProvider,
|
|
@@ -1781,6 +2011,8 @@ export {
|
|
|
1781
2011
|
agentRunsSuccessRateProvider,
|
|
1782
2012
|
agentRunsTotalProvider,
|
|
1783
2013
|
agentRunsTrendProvider,
|
|
2014
|
+
agentRunsTtftDistributionProvider,
|
|
2015
|
+
agentRunsTtftProvider,
|
|
1784
2016
|
agentSpendByActorProvider,
|
|
1785
2017
|
agentSpendByModelProvider,
|
|
1786
2018
|
agentSpendTotalProvider,
|
|
@@ -1812,6 +2044,7 @@ export {
|
|
|
1812
2044
|
toActorSpendRows,
|
|
1813
2045
|
toActorSpendSegments,
|
|
1814
2046
|
toCollectionRows,
|
|
2047
|
+
toFailureCodeSegments,
|
|
1815
2048
|
toLatencyDistribution,
|
|
1816
2049
|
toModelSpendRows,
|
|
1817
2050
|
toModelSpendSegments,
|
|
@@ -1830,6 +2063,7 @@ export {
|
|
|
1830
2063
|
toStoreSegments,
|
|
1831
2064
|
toThreadSpendRows,
|
|
1832
2065
|
toToolStatTableRows,
|
|
2066
|
+
toTtftDistribution,
|
|
1833
2067
|
toUsageTrendRows,
|
|
1834
2068
|
totalCostUsd,
|
|
1835
2069
|
totalTokens,
|