@dudousxd/nestjs-agent-telescope 0.3.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +585 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +194 -14
- package/dist/index.d.ts +194 -14
- package/dist/index.js +561 -24
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -25,22 +25,48 @@ __export(index_exports, {
|
|
|
25
25
|
agentActorSpendTableProvider: () => agentActorSpendTableProvider,
|
|
26
26
|
agentDashboard: () => agentDashboard,
|
|
27
27
|
agentModelSpendTableProvider: () => agentModelSpendTableProvider,
|
|
28
|
+
agentPendingApprovalsCountProvider: () => agentPendingApprovalsCountProvider,
|
|
29
|
+
agentPendingApprovalsTableProvider: () => agentPendingApprovalsTableProvider,
|
|
30
|
+
agentRecentRunsTableProvider: () => agentRecentRunsTableProvider,
|
|
31
|
+
agentRecentThreadsTableProvider: () => agentRecentThreadsTableProvider,
|
|
32
|
+
agentRecentToolCallsTableProvider: () => agentRecentToolCallsTableProvider,
|
|
33
|
+
agentRunErrorsProvider: () => agentRunErrorsProvider,
|
|
34
|
+
agentRunsByAgentTableProvider: () => agentRunsByAgentTableProvider,
|
|
35
|
+
agentRunsDurationProvider: () => agentRunsDurationProvider,
|
|
36
|
+
agentRunsFailedProvider: () => agentRunsFailedProvider,
|
|
28
37
|
agentRunsProvider: () => agentRunsProvider,
|
|
38
|
+
agentRunsRetriesProvider: () => agentRunsRetriesProvider,
|
|
39
|
+
agentRunsSuccessRateProvider: () => agentRunsSuccessRateProvider,
|
|
40
|
+
agentRunsTotalProvider: () => agentRunsTotalProvider,
|
|
41
|
+
agentRunsTrendProvider: () => agentRunsTrendProvider,
|
|
29
42
|
agentSpendByActorProvider: () => agentSpendByActorProvider,
|
|
30
43
|
agentSpendByModelProvider: () => agentSpendByModelProvider,
|
|
31
44
|
agentSpendTotalProvider: () => agentSpendTotalProvider,
|
|
32
45
|
agentTelescopeExtension: () => agentTelescopeExtension,
|
|
33
46
|
agentTokensProvider: () => agentTokensProvider,
|
|
34
47
|
agentTokensTotalProvider: () => agentTokensTotalProvider,
|
|
48
|
+
agentToolStatsTableProvider: () => agentToolStatsTableProvider,
|
|
35
49
|
agentToolStatusProvider: () => agentToolStatusProvider,
|
|
36
50
|
agentToolsProvider: () => agentToolsProvider,
|
|
51
|
+
agentTopThreadsTableProvider: () => agentTopThreadsTableProvider,
|
|
37
52
|
agentUsageTrendProvider: () => agentUsageTrendProvider,
|
|
53
|
+
capErrorMessage: () => capErrorMessage,
|
|
38
54
|
resolveRange: () => resolveRange,
|
|
39
55
|
shiftUtcDay: () => shiftUtcDay,
|
|
56
|
+
shortPromptHash: () => shortPromptHash,
|
|
40
57
|
toActorSpendRows: () => toActorSpendRows,
|
|
41
58
|
toActorSpendSegments: () => toActorSpendSegments,
|
|
42
59
|
toModelSpendRows: () => toModelSpendRows,
|
|
43
60
|
toModelSpendSegments: () => toModelSpendSegments,
|
|
61
|
+
toPendingApprovalTableRows: () => toPendingApprovalTableRows,
|
|
62
|
+
toRecentRunTableRows: () => toRecentRunTableRows,
|
|
63
|
+
toRecentThreadTableRows: () => toRecentThreadTableRows,
|
|
64
|
+
toRecentToolCallRows: () => toRecentToolCallRows,
|
|
65
|
+
toRunAgentTableRows: () => toRunAgentTableRows,
|
|
66
|
+
toRunErrorSegments: () => toRunErrorSegments,
|
|
67
|
+
toRunTrendRows: () => toRunTrendRows,
|
|
68
|
+
toThreadSpendRows: () => toThreadSpendRows,
|
|
69
|
+
toToolStatTableRows: () => toToolStatTableRows,
|
|
44
70
|
toUsageTrendRows: () => toUsageTrendRows,
|
|
45
71
|
totalCostUsd: () => totalCostUsd,
|
|
46
72
|
totalTokens: () => totalTokens
|
|
@@ -50,8 +76,21 @@ module.exports = __toCommonJS(index_exports);
|
|
|
50
76
|
// src/agent-telescope.extension.ts
|
|
51
77
|
var import_nestjs_telescope2 = require("@dudousxd/nestjs-telescope");
|
|
52
78
|
|
|
53
|
-
// src/agent-dashboard.ts
|
|
54
|
-
function
|
|
79
|
+
// src/agent-dashboard.spec-data.ts
|
|
80
|
+
function col(key, label, href) {
|
|
81
|
+
return href !== void 0 ? {
|
|
82
|
+
key,
|
|
83
|
+
label,
|
|
84
|
+
link: {
|
|
85
|
+
href
|
|
86
|
+
}
|
|
87
|
+
} : {
|
|
88
|
+
key,
|
|
89
|
+
label
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
__name(col, "col");
|
|
93
|
+
function agentDashboard(opts = {}) {
|
|
55
94
|
return {
|
|
56
95
|
id: "agent.overview",
|
|
57
96
|
label: "Agent",
|
|
@@ -77,6 +116,158 @@ function agentDashboard() {
|
|
|
77
116
|
}
|
|
78
117
|
]
|
|
79
118
|
},
|
|
119
|
+
{
|
|
120
|
+
title: "Reliability",
|
|
121
|
+
cols: 4,
|
|
122
|
+
panels: [
|
|
123
|
+
{
|
|
124
|
+
kind: "stat",
|
|
125
|
+
title: "Runs",
|
|
126
|
+
data: {
|
|
127
|
+
provider: "agent.runs.total"
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
kind: "stat",
|
|
132
|
+
title: "Success rate",
|
|
133
|
+
data: {
|
|
134
|
+
provider: "agent.runs.successRate"
|
|
135
|
+
},
|
|
136
|
+
format: "percent"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
kind: "stat",
|
|
140
|
+
title: "Failed",
|
|
141
|
+
data: {
|
|
142
|
+
provider: "agent.runs.failed"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
kind: "stat",
|
|
147
|
+
title: "Retries",
|
|
148
|
+
data: {
|
|
149
|
+
provider: "agent.runs.retries"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
title: "Run trends",
|
|
156
|
+
cols: 4,
|
|
157
|
+
panels: [
|
|
158
|
+
{
|
|
159
|
+
kind: "timeseries",
|
|
160
|
+
title: "Runs & failures",
|
|
161
|
+
data: {
|
|
162
|
+
provider: "agent.runs.trend"
|
|
163
|
+
},
|
|
164
|
+
series: [
|
|
165
|
+
"runs",
|
|
166
|
+
"failed"
|
|
167
|
+
],
|
|
168
|
+
style: "stacked"
|
|
169
|
+
},
|
|
170
|
+
// Two duration stats, not a `distribution` panel: RunMetrics carries only p50/p95 (no
|
|
171
|
+
// raw samples to bucket), so a histogram here would be a permanently-empty box.
|
|
172
|
+
{
|
|
173
|
+
kind: "stat",
|
|
174
|
+
title: "Duration p50",
|
|
175
|
+
data: {
|
|
176
|
+
provider: "agent.runs.duration",
|
|
177
|
+
query: {
|
|
178
|
+
metric: "p50"
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
format: "duration"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
kind: "stat",
|
|
185
|
+
title: "Duration p95",
|
|
186
|
+
data: {
|
|
187
|
+
provider: "agent.runs.duration",
|
|
188
|
+
query: {
|
|
189
|
+
metric: "p95"
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
format: "duration"
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
kind: "breakdown",
|
|
196
|
+
title: "Run errors",
|
|
197
|
+
data: {
|
|
198
|
+
provider: "agent.runs.errors"
|
|
199
|
+
},
|
|
200
|
+
style: "donut"
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
title: "Runs",
|
|
206
|
+
panels: [
|
|
207
|
+
{
|
|
208
|
+
kind: "table",
|
|
209
|
+
title: "Runs by agent",
|
|
210
|
+
data: {
|
|
211
|
+
provider: "agent.runs.byAgent"
|
|
212
|
+
},
|
|
213
|
+
columns: [
|
|
214
|
+
{
|
|
215
|
+
key: "agentName",
|
|
216
|
+
label: "Agent"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
key: "runs",
|
|
220
|
+
label: "Runs"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
key: "failed",
|
|
224
|
+
label: "Failed"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
key: "retries",
|
|
228
|
+
label: "Retries"
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
kind: "table",
|
|
234
|
+
title: "Recent runs",
|
|
235
|
+
data: {
|
|
236
|
+
provider: "agent.runs.recent"
|
|
237
|
+
},
|
|
238
|
+
// A deliberate SUBSET of the provider's row shape: the full 11-field row overflows the
|
|
239
|
+
// card horizontally. Thread/actor/retries/errorCode detail lives in the standalone
|
|
240
|
+
// agent dashboard; the provider keeps returning the full row for other consumers.
|
|
241
|
+
columns: [
|
|
242
|
+
{
|
|
243
|
+
key: "startedAt",
|
|
244
|
+
label: "Started"
|
|
245
|
+
},
|
|
246
|
+
col("runId", "Run", opts.runHref),
|
|
247
|
+
{
|
|
248
|
+
key: "agentName",
|
|
249
|
+
label: "Agent"
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
key: "status",
|
|
253
|
+
label: "Status"
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
key: "durationMs",
|
|
257
|
+
label: "Duration (ms)"
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
key: "errorMessage",
|
|
261
|
+
label: "Error"
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
key: "promptHash",
|
|
265
|
+
label: "Prompt"
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
}
|
|
269
|
+
]
|
|
270
|
+
},
|
|
80
271
|
{
|
|
81
272
|
title: "Spend",
|
|
82
273
|
cols: 2,
|
|
@@ -194,6 +385,7 @@ function agentDashboard() {
|
|
|
194
385
|
},
|
|
195
386
|
{
|
|
196
387
|
title: "Threads",
|
|
388
|
+
cols: 2,
|
|
197
389
|
panels: [
|
|
198
390
|
{
|
|
199
391
|
kind: "table",
|
|
@@ -223,6 +415,79 @@ function agentDashboard() {
|
|
|
223
415
|
label: "Cost (USD)"
|
|
224
416
|
}
|
|
225
417
|
]
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
kind: "table",
|
|
421
|
+
title: "Recently active threads",
|
|
422
|
+
data: {
|
|
423
|
+
provider: "agent.threads.recent"
|
|
424
|
+
},
|
|
425
|
+
columns: [
|
|
426
|
+
col("threadId", "Thread", opts.threadHref),
|
|
427
|
+
{
|
|
428
|
+
key: "title",
|
|
429
|
+
label: "Title"
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
key: "actorRef",
|
|
433
|
+
label: "Actor"
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
key: "messageCount",
|
|
437
|
+
label: "Messages"
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
key: "totalTokens",
|
|
441
|
+
label: "Tokens"
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
key: "lastActivityAt",
|
|
445
|
+
label: "Last activity"
|
|
446
|
+
}
|
|
447
|
+
]
|
|
448
|
+
}
|
|
449
|
+
]
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
title: "Approvals",
|
|
453
|
+
cols: 3,
|
|
454
|
+
panels: [
|
|
455
|
+
{
|
|
456
|
+
kind: "stat",
|
|
457
|
+
title: "Pending approvals",
|
|
458
|
+
data: {
|
|
459
|
+
provider: "agent.approvals.pending"
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
kind: "table",
|
|
464
|
+
title: "Approvals inbox",
|
|
465
|
+
data: {
|
|
466
|
+
provider: "agent.approvals.recent"
|
|
467
|
+
},
|
|
468
|
+
columns: [
|
|
469
|
+
{
|
|
470
|
+
key: "requestedAt",
|
|
471
|
+
label: "Requested"
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
key: "toolName",
|
|
475
|
+
label: "Tool"
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
key: "threadTitle",
|
|
479
|
+
label: "Thread"
|
|
480
|
+
},
|
|
481
|
+
col("threadId", "Thread id", opts.threadHref),
|
|
482
|
+
{
|
|
483
|
+
key: "actorRef",
|
|
484
|
+
label: "Actor"
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
key: "agentName",
|
|
488
|
+
label: "Agent"
|
|
489
|
+
}
|
|
490
|
+
]
|
|
226
491
|
}
|
|
227
492
|
]
|
|
228
493
|
},
|
|
@@ -238,13 +503,50 @@ function agentDashboard() {
|
|
|
238
503
|
},
|
|
239
504
|
style: "donut"
|
|
240
505
|
},
|
|
506
|
+
{
|
|
507
|
+
kind: "table",
|
|
508
|
+
title: "Tool stats",
|
|
509
|
+
data: {
|
|
510
|
+
provider: "agent.tools.stats"
|
|
511
|
+
},
|
|
512
|
+
columns: [
|
|
513
|
+
{
|
|
514
|
+
key: "toolName",
|
|
515
|
+
label: "Tool"
|
|
516
|
+
},
|
|
517
|
+
{
|
|
518
|
+
key: "toolType",
|
|
519
|
+
label: "Type"
|
|
520
|
+
},
|
|
521
|
+
{
|
|
522
|
+
key: "calls",
|
|
523
|
+
label: "Calls"
|
|
524
|
+
},
|
|
525
|
+
{
|
|
526
|
+
key: "failed",
|
|
527
|
+
label: "Failed"
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
key: "rejected",
|
|
531
|
+
label: "Rejected"
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
key: "p95ExecutionMs",
|
|
535
|
+
label: "p95 (ms)"
|
|
536
|
+
}
|
|
537
|
+
]
|
|
538
|
+
},
|
|
241
539
|
{
|
|
242
540
|
kind: "table",
|
|
243
541
|
title: "Recent tool calls",
|
|
244
542
|
data: {
|
|
245
|
-
provider: "agent.tools"
|
|
543
|
+
provider: "agent.tools.recent"
|
|
246
544
|
},
|
|
247
545
|
columns: [
|
|
546
|
+
{
|
|
547
|
+
key: "createdAt",
|
|
548
|
+
label: "When"
|
|
549
|
+
},
|
|
248
550
|
{
|
|
249
551
|
key: "toolName",
|
|
250
552
|
label: "Tool"
|
|
@@ -257,10 +559,7 @@ function agentDashboard() {
|
|
|
257
559
|
key: "status",
|
|
258
560
|
label: "Status"
|
|
259
561
|
},
|
|
260
|
-
|
|
261
|
-
key: "runId",
|
|
262
|
-
label: "Run"
|
|
263
|
-
}
|
|
562
|
+
col("threadId", "Thread", opts.threadHref)
|
|
264
563
|
]
|
|
265
564
|
}
|
|
266
565
|
]
|
|
@@ -362,7 +661,7 @@ function isRecord(value) {
|
|
|
362
661
|
}
|
|
363
662
|
__name(isRecord, "isRecord");
|
|
364
663
|
function isGovernanceQueries(value) {
|
|
365
|
-
return isRecord(value) && typeof value.spendByModel === "function" && typeof value.spendByActor === "function" && typeof value.spendByThread === "function" && typeof value.usageTrend === "function" && typeof value.recentToolCalls === "function" && typeof value.recentThreads === "function";
|
|
664
|
+
return isRecord(value) && typeof value.spendByModel === "function" && typeof value.spendByActor === "function" && typeof value.spendByThread === "function" && typeof value.usageTrend === "function" && typeof value.recentToolCalls === "function" && typeof value.recentThreads === "function" && typeof value.runMetrics === "function" && typeof value.runsByAgent === "function" && typeof value.runErrors === "function" && typeof value.runTrend === "function" && typeof value.recentRuns === "function" && typeof value.pendingApprovals === "function" && typeof value.toolStats === "function";
|
|
366
665
|
}
|
|
367
666
|
__name(isGovernanceQueries, "isGovernanceQueries");
|
|
368
667
|
function resolveGovernanceQueries(ctx) {
|
|
@@ -463,6 +762,98 @@ function toUsageTrendRows(points) {
|
|
|
463
762
|
}));
|
|
464
763
|
}
|
|
465
764
|
__name(toUsageTrendRows, "toUsageTrendRows");
|
|
765
|
+
var NO_VALUE = "\u2014";
|
|
766
|
+
function toRunAgentTableRows(rows) {
|
|
767
|
+
return rows.map((row) => ({
|
|
768
|
+
agentName: row.agentName,
|
|
769
|
+
runs: row.runs,
|
|
770
|
+
failed: row.failed,
|
|
771
|
+
retries: row.retries
|
|
772
|
+
}));
|
|
773
|
+
}
|
|
774
|
+
__name(toRunAgentTableRows, "toRunAgentTableRows");
|
|
775
|
+
function toRunErrorSegments(rows) {
|
|
776
|
+
return rows.map((row) => ({
|
|
777
|
+
label: row.errorCode,
|
|
778
|
+
value: row.count
|
|
779
|
+
}));
|
|
780
|
+
}
|
|
781
|
+
__name(toRunErrorSegments, "toRunErrorSegments");
|
|
782
|
+
function toRunTrendRows(points) {
|
|
783
|
+
return points.map((point) => ({
|
|
784
|
+
label: point.day,
|
|
785
|
+
runs: point.runs,
|
|
786
|
+
failed: point.failed
|
|
787
|
+
}));
|
|
788
|
+
}
|
|
789
|
+
__name(toRunTrendRows, "toRunTrendRows");
|
|
790
|
+
var ERROR_MESSAGE_CAP = 500;
|
|
791
|
+
function capErrorMessage(message) {
|
|
792
|
+
if (message === null) return null;
|
|
793
|
+
return message.length > ERROR_MESSAGE_CAP ? `${message.slice(0, ERROR_MESSAGE_CAP)}\u2026` : message;
|
|
794
|
+
}
|
|
795
|
+
__name(capErrorMessage, "capErrorMessage");
|
|
796
|
+
var PROMPT_HASH_CHIP_LENGTH = 10;
|
|
797
|
+
function shortPromptHash(promptHash) {
|
|
798
|
+
return promptHash === null ? null : promptHash.slice(0, PROMPT_HASH_CHIP_LENGTH);
|
|
799
|
+
}
|
|
800
|
+
__name(shortPromptHash, "shortPromptHash");
|
|
801
|
+
function toRecentRunTableRows(rows) {
|
|
802
|
+
return rows.map((row) => ({
|
|
803
|
+
startedAt: row.startedAt,
|
|
804
|
+
runId: row.runId,
|
|
805
|
+
threadId: row.threadId,
|
|
806
|
+
actorRef: row.actorRef,
|
|
807
|
+
agentName: row.agentName ?? NO_VALUE,
|
|
808
|
+
status: row.status,
|
|
809
|
+
durationMs: row.durationMs ?? NO_VALUE,
|
|
810
|
+
retries: row.retries,
|
|
811
|
+
errorCode: row.errorCode ?? NO_VALUE,
|
|
812
|
+
errorMessage: capErrorMessage(row.errorMessage) ?? NO_VALUE,
|
|
813
|
+
promptHash: shortPromptHash(row.promptHash) ?? NO_VALUE
|
|
814
|
+
}));
|
|
815
|
+
}
|
|
816
|
+
__name(toRecentRunTableRows, "toRecentRunTableRows");
|
|
817
|
+
function toRecentToolCallRows(rows) {
|
|
818
|
+
return rows;
|
|
819
|
+
}
|
|
820
|
+
__name(toRecentToolCallRows, "toRecentToolCallRows");
|
|
821
|
+
function toRecentThreadTableRows(rows) {
|
|
822
|
+
return rows;
|
|
823
|
+
}
|
|
824
|
+
__name(toRecentThreadTableRows, "toRecentThreadTableRows");
|
|
825
|
+
function toPendingApprovalTableRows(rows) {
|
|
826
|
+
return rows.map((row) => ({
|
|
827
|
+
toolCallId: row.toolCallId,
|
|
828
|
+
toolName: row.toolName,
|
|
829
|
+
threadId: row.threadId,
|
|
830
|
+
threadTitle: row.threadTitle,
|
|
831
|
+
actorRef: row.actorRef,
|
|
832
|
+
agentName: row.agentName ?? NO_VALUE,
|
|
833
|
+
requestedAt: row.requestedAt
|
|
834
|
+
}));
|
|
835
|
+
}
|
|
836
|
+
__name(toPendingApprovalTableRows, "toPendingApprovalTableRows");
|
|
837
|
+
function toToolStatTableRows(rows) {
|
|
838
|
+
return rows.map((row) => ({
|
|
839
|
+
toolName: row.toolName,
|
|
840
|
+
toolType: row.toolType,
|
|
841
|
+
calls: row.calls,
|
|
842
|
+
failed: row.failed,
|
|
843
|
+
rejected: row.rejected,
|
|
844
|
+
p95ExecutionMs: row.p95ExecutionMs ?? NO_VALUE
|
|
845
|
+
}));
|
|
846
|
+
}
|
|
847
|
+
__name(toToolStatTableRows, "toToolStatTableRows");
|
|
848
|
+
var EMPTY_RUN_METRICS = {
|
|
849
|
+
runs: 0,
|
|
850
|
+
completed: 0,
|
|
851
|
+
failed: 0,
|
|
852
|
+
successRate: 0,
|
|
853
|
+
retries: 0,
|
|
854
|
+
durationP50Ms: null,
|
|
855
|
+
durationP95Ms: null
|
|
856
|
+
};
|
|
466
857
|
function governanceStatProvider(name, fetch, format) {
|
|
467
858
|
return {
|
|
468
859
|
name,
|
|
@@ -522,25 +913,152 @@ function agentTopThreadsTableProvider() {
|
|
|
522
913
|
}));
|
|
523
914
|
}
|
|
524
915
|
__name(agentTopThreadsTableProvider, "agentTopThreadsTableProvider");
|
|
916
|
+
function governanceRunMetricsProvider(name, format) {
|
|
917
|
+
return {
|
|
918
|
+
name,
|
|
919
|
+
async resolve(query, ctx) {
|
|
920
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
921
|
+
const metrics = queries ? await queries.runMetrics(resolveRange(query)) : EMPTY_RUN_METRICS;
|
|
922
|
+
return format(metrics);
|
|
923
|
+
}
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
__name(governanceRunMetricsProvider, "governanceRunMetricsProvider");
|
|
927
|
+
function agentRunsTotalProvider() {
|
|
928
|
+
return governanceRunMetricsProvider("agent.runs.total", (metrics) => ({
|
|
929
|
+
value: metrics.runs
|
|
930
|
+
}));
|
|
931
|
+
}
|
|
932
|
+
__name(agentRunsTotalProvider, "agentRunsTotalProvider");
|
|
933
|
+
function agentRunsSuccessRateProvider() {
|
|
934
|
+
return governanceRunMetricsProvider("agent.runs.successRate", (metrics) => ({
|
|
935
|
+
value: metrics.successRate
|
|
936
|
+
}));
|
|
937
|
+
}
|
|
938
|
+
__name(agentRunsSuccessRateProvider, "agentRunsSuccessRateProvider");
|
|
939
|
+
function agentRunsFailedProvider() {
|
|
940
|
+
return governanceRunMetricsProvider("agent.runs.failed", (metrics) => ({
|
|
941
|
+
value: metrics.failed
|
|
942
|
+
}));
|
|
943
|
+
}
|
|
944
|
+
__name(agentRunsFailedProvider, "agentRunsFailedProvider");
|
|
945
|
+
function agentRunsRetriesProvider() {
|
|
946
|
+
return governanceRunMetricsProvider("agent.runs.retries", (metrics) => ({
|
|
947
|
+
value: metrics.retries
|
|
948
|
+
}));
|
|
949
|
+
}
|
|
950
|
+
__name(agentRunsRetriesProvider, "agentRunsRetriesProvider");
|
|
951
|
+
function agentRunsDurationProvider() {
|
|
952
|
+
return {
|
|
953
|
+
name: "agent.runs.duration",
|
|
954
|
+
async resolve(query, ctx) {
|
|
955
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
956
|
+
const metrics = queries ? await queries.runMetrics(resolveRange(query)) : EMPTY_RUN_METRICS;
|
|
957
|
+
const value = query?.metric === "p95" ? metrics.durationP95Ms : metrics.durationP50Ms;
|
|
958
|
+
return {
|
|
959
|
+
value: value ?? 0
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
__name(agentRunsDurationProvider, "agentRunsDurationProvider");
|
|
965
|
+
function agentRunsByAgentTableProvider() {
|
|
966
|
+
return governanceStatProvider("agent.runs.byAgent", (queries, range) => queries.runsByAgent(range), (rows) => ({
|
|
967
|
+
rows: toRunAgentTableRows(rows)
|
|
968
|
+
}));
|
|
969
|
+
}
|
|
970
|
+
__name(agentRunsByAgentTableProvider, "agentRunsByAgentTableProvider");
|
|
971
|
+
function agentRunErrorsProvider() {
|
|
972
|
+
return governanceStatProvider("agent.runs.errors", (queries, range) => queries.runErrors(range), (rows) => ({
|
|
973
|
+
segments: toRunErrorSegments(rows)
|
|
974
|
+
}));
|
|
975
|
+
}
|
|
976
|
+
__name(agentRunErrorsProvider, "agentRunErrorsProvider");
|
|
977
|
+
function agentRunsTrendProvider() {
|
|
978
|
+
return governanceStatProvider("agent.runs.trend", (queries, range) => queries.runTrend(range), (points) => ({
|
|
979
|
+
rows: toRunTrendRows(points)
|
|
980
|
+
}));
|
|
981
|
+
}
|
|
982
|
+
__name(agentRunsTrendProvider, "agentRunsTrendProvider");
|
|
983
|
+
var DEFAULT_RECENT_LIMIT = 50;
|
|
984
|
+
var MAX_RECENT_LIMIT = 500;
|
|
985
|
+
function resolveLimit(query, fallback) {
|
|
986
|
+
const raw = query?.limit;
|
|
987
|
+
const value = typeof raw === "number" && Number.isFinite(raw) ? raw : fallback;
|
|
988
|
+
return Math.min(MAX_RECENT_LIMIT, Math.max(1, Math.trunc(value)));
|
|
989
|
+
}
|
|
990
|
+
__name(resolveLimit, "resolveLimit");
|
|
991
|
+
function governanceLimitProvider(name, defaultLimit, fetch, format) {
|
|
992
|
+
return {
|
|
993
|
+
name,
|
|
994
|
+
async resolve(query, ctx) {
|
|
995
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
996
|
+
const rows = queries ? await fetch(queries, resolveLimit(query, defaultLimit)) : [];
|
|
997
|
+
return format(rows);
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
__name(governanceLimitProvider, "governanceLimitProvider");
|
|
1002
|
+
function agentRecentRunsTableProvider() {
|
|
1003
|
+
return governanceLimitProvider("agent.runs.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.recentRuns(limit), (rows) => ({
|
|
1004
|
+
rows: toRecentRunTableRows(rows)
|
|
1005
|
+
}));
|
|
1006
|
+
}
|
|
1007
|
+
__name(agentRecentRunsTableProvider, "agentRecentRunsTableProvider");
|
|
1008
|
+
function agentRecentToolCallsTableProvider() {
|
|
1009
|
+
return governanceLimitProvider("agent.tools.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.recentToolCalls(limit), (rows) => ({
|
|
1010
|
+
rows: toRecentToolCallRows(rows)
|
|
1011
|
+
}));
|
|
1012
|
+
}
|
|
1013
|
+
__name(agentRecentToolCallsTableProvider, "agentRecentToolCallsTableProvider");
|
|
1014
|
+
function agentRecentThreadsTableProvider() {
|
|
1015
|
+
return governanceLimitProvider("agent.threads.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.recentThreads(limit), (rows) => ({
|
|
1016
|
+
rows: toRecentThreadTableRows(rows)
|
|
1017
|
+
}));
|
|
1018
|
+
}
|
|
1019
|
+
__name(agentRecentThreadsTableProvider, "agentRecentThreadsTableProvider");
|
|
1020
|
+
var PENDING_APPROVALS_COUNT_LIMIT = 500;
|
|
1021
|
+
function agentPendingApprovalsCountProvider() {
|
|
1022
|
+
return {
|
|
1023
|
+
name: "agent.approvals.pending",
|
|
1024
|
+
async resolve(_query, ctx) {
|
|
1025
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
1026
|
+
const rows = queries ? await queries.pendingApprovals(PENDING_APPROVALS_COUNT_LIMIT) : [];
|
|
1027
|
+
return {
|
|
1028
|
+
value: rows.length
|
|
1029
|
+
};
|
|
1030
|
+
}
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
__name(agentPendingApprovalsCountProvider, "agentPendingApprovalsCountProvider");
|
|
1034
|
+
function agentPendingApprovalsTableProvider() {
|
|
1035
|
+
return governanceLimitProvider("agent.approvals.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.pendingApprovals(limit), (rows) => ({
|
|
1036
|
+
rows: toPendingApprovalTableRows(rows)
|
|
1037
|
+
}));
|
|
1038
|
+
}
|
|
1039
|
+
__name(agentPendingApprovalsTableProvider, "agentPendingApprovalsTableProvider");
|
|
1040
|
+
function agentToolStatsTableProvider() {
|
|
1041
|
+
return governanceStatProvider("agent.tools.stats", (queries, range) => queries.toolStats(range), (rows) => ({
|
|
1042
|
+
rows: toToolStatTableRows(rows)
|
|
1043
|
+
}));
|
|
1044
|
+
}
|
|
1045
|
+
__name(agentToolStatsTableProvider, "agentToolStatsTableProvider");
|
|
525
1046
|
|
|
526
1047
|
// src/agent-telescope.watcher.ts
|
|
527
1048
|
var import_node_diagnostics_channel = require("diagnostics_channel");
|
|
1049
|
+
var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
|
|
528
1050
|
var import_nestjs_diagnostics = require("@dudousxd/nestjs-diagnostics");
|
|
529
|
-
var AGENT_EVENTS = [
|
|
530
|
-
"run.started",
|
|
531
|
-
"message",
|
|
532
|
-
"tool-call",
|
|
533
|
-
"quota.exceeded",
|
|
534
|
-
"run.finished"
|
|
535
|
-
];
|
|
536
1051
|
var AgentTelescopeWatcher = class {
|
|
537
1052
|
static {
|
|
538
1053
|
__name(this, "AgentTelescopeWatcher");
|
|
539
1054
|
}
|
|
540
1055
|
type = "agent";
|
|
1056
|
+
disposers = [];
|
|
541
1057
|
register(ctx) {
|
|
542
|
-
|
|
543
|
-
|
|
1058
|
+
this.disposers.push((0, import_nestjs_diagnostics.claimDiagnostics)("agent", import_nestjs_agent_core2.AGENT_DIAGNOSTIC_EVENTS));
|
|
1059
|
+
for (const event of import_nestjs_agent_core2.AGENT_DIAGNOSTIC_EVENTS) {
|
|
1060
|
+
const channel = (0, import_nestjs_diagnostics.channelName)("agent", event);
|
|
1061
|
+
const onMessage = /* @__PURE__ */ __name((message) => {
|
|
544
1062
|
const envelope = message;
|
|
545
1063
|
ctx.record({
|
|
546
1064
|
type: "agent",
|
|
@@ -552,13 +1070,19 @@ var AgentTelescopeWatcher = class {
|
|
|
552
1070
|
envelope.event
|
|
553
1071
|
]
|
|
554
1072
|
});
|
|
555
|
-
});
|
|
1073
|
+
}, "onMessage");
|
|
1074
|
+
(0, import_node_diagnostics_channel.subscribe)(channel, onMessage);
|
|
1075
|
+
this.disposers.push(() => (0, import_node_diagnostics_channel.unsubscribe)(channel, onMessage));
|
|
556
1076
|
}
|
|
557
1077
|
}
|
|
1078
|
+
/** Detach all channel subscriptions and release the diagnostics claim (e.g. on module destroy). */
|
|
1079
|
+
dispose() {
|
|
1080
|
+
while (this.disposers.length) this.disposers.pop()?.();
|
|
1081
|
+
}
|
|
558
1082
|
};
|
|
559
1083
|
|
|
560
1084
|
// src/agent-telescope.extension.ts
|
|
561
|
-
function agentTelescopeExtension() {
|
|
1085
|
+
function agentTelescopeExtension(opts = {}) {
|
|
562
1086
|
return (0, import_nestjs_telescope2.defineTelescopeExtension)({
|
|
563
1087
|
name: "agent",
|
|
564
1088
|
watchers: /* @__PURE__ */ __name(() => [
|
|
@@ -572,12 +1096,11 @@ function agentTelescopeExtension() {
|
|
|
572
1096
|
}
|
|
573
1097
|
], "entryTypes"),
|
|
574
1098
|
dashboards: /* @__PURE__ */ __name(() => [
|
|
575
|
-
agentDashboard()
|
|
1099
|
+
agentDashboard(opts)
|
|
576
1100
|
], "dashboards"),
|
|
577
1101
|
dataProviders: /* @__PURE__ */ __name(() => [
|
|
578
1102
|
agentRunsProvider(),
|
|
579
1103
|
agentTokensProvider(),
|
|
580
|
-
agentToolsProvider(),
|
|
581
1104
|
agentToolStatusProvider(),
|
|
582
1105
|
agentSpendTotalProvider(),
|
|
583
1106
|
agentTokensTotalProvider(),
|
|
@@ -586,7 +1109,21 @@ function agentTelescopeExtension() {
|
|
|
586
1109
|
agentUsageTrendProvider(),
|
|
587
1110
|
agentActorSpendTableProvider(),
|
|
588
1111
|
agentSpendByActorProvider(),
|
|
589
|
-
agentTopThreadsTableProvider()
|
|
1112
|
+
agentTopThreadsTableProvider(),
|
|
1113
|
+
agentRunsTotalProvider(),
|
|
1114
|
+
agentRunsSuccessRateProvider(),
|
|
1115
|
+
agentRunsFailedProvider(),
|
|
1116
|
+
agentRunsRetriesProvider(),
|
|
1117
|
+
agentRunsDurationProvider(),
|
|
1118
|
+
agentRunsByAgentTableProvider(),
|
|
1119
|
+
agentRunErrorsProvider(),
|
|
1120
|
+
agentRunsTrendProvider(),
|
|
1121
|
+
agentRecentRunsTableProvider(),
|
|
1122
|
+
agentRecentToolCallsTableProvider(),
|
|
1123
|
+
agentRecentThreadsTableProvider(),
|
|
1124
|
+
agentPendingApprovalsCountProvider(),
|
|
1125
|
+
agentPendingApprovalsTableProvider(),
|
|
1126
|
+
agentToolStatsTableProvider()
|
|
590
1127
|
], "dataProviders")
|
|
591
1128
|
});
|
|
592
1129
|
}
|
|
@@ -597,22 +1134,48 @@ __name(agentTelescopeExtension, "agentTelescopeExtension");
|
|
|
597
1134
|
agentActorSpendTableProvider,
|
|
598
1135
|
agentDashboard,
|
|
599
1136
|
agentModelSpendTableProvider,
|
|
1137
|
+
agentPendingApprovalsCountProvider,
|
|
1138
|
+
agentPendingApprovalsTableProvider,
|
|
1139
|
+
agentRecentRunsTableProvider,
|
|
1140
|
+
agentRecentThreadsTableProvider,
|
|
1141
|
+
agentRecentToolCallsTableProvider,
|
|
1142
|
+
agentRunErrorsProvider,
|
|
1143
|
+
agentRunsByAgentTableProvider,
|
|
1144
|
+
agentRunsDurationProvider,
|
|
1145
|
+
agentRunsFailedProvider,
|
|
600
1146
|
agentRunsProvider,
|
|
1147
|
+
agentRunsRetriesProvider,
|
|
1148
|
+
agentRunsSuccessRateProvider,
|
|
1149
|
+
agentRunsTotalProvider,
|
|
1150
|
+
agentRunsTrendProvider,
|
|
601
1151
|
agentSpendByActorProvider,
|
|
602
1152
|
agentSpendByModelProvider,
|
|
603
1153
|
agentSpendTotalProvider,
|
|
604
1154
|
agentTelescopeExtension,
|
|
605
1155
|
agentTokensProvider,
|
|
606
1156
|
agentTokensTotalProvider,
|
|
1157
|
+
agentToolStatsTableProvider,
|
|
607
1158
|
agentToolStatusProvider,
|
|
608
1159
|
agentToolsProvider,
|
|
1160
|
+
agentTopThreadsTableProvider,
|
|
609
1161
|
agentUsageTrendProvider,
|
|
1162
|
+
capErrorMessage,
|
|
610
1163
|
resolveRange,
|
|
611
1164
|
shiftUtcDay,
|
|
1165
|
+
shortPromptHash,
|
|
612
1166
|
toActorSpendRows,
|
|
613
1167
|
toActorSpendSegments,
|
|
614
1168
|
toModelSpendRows,
|
|
615
1169
|
toModelSpendSegments,
|
|
1170
|
+
toPendingApprovalTableRows,
|
|
1171
|
+
toRecentRunTableRows,
|
|
1172
|
+
toRecentThreadTableRows,
|
|
1173
|
+
toRecentToolCallRows,
|
|
1174
|
+
toRunAgentTableRows,
|
|
1175
|
+
toRunErrorSegments,
|
|
1176
|
+
toRunTrendRows,
|
|
1177
|
+
toThreadSpendRows,
|
|
1178
|
+
toToolStatTableRows,
|
|
616
1179
|
toUsageTrendRows,
|
|
617
1180
|
totalCostUsd,
|
|
618
1181
|
totalTokens
|