@dudousxd/nestjs-agent-telescope 0.3.4 → 0.4.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 +580 -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 +555 -23
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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,156 @@ 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: 3,
|
|
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
|
+
{
|
|
171
|
+
kind: "distribution",
|
|
172
|
+
title: "Run duration",
|
|
173
|
+
data: {
|
|
174
|
+
provider: "agent.runs.duration"
|
|
175
|
+
},
|
|
176
|
+
markers: [
|
|
177
|
+
"p50",
|
|
178
|
+
"p95"
|
|
179
|
+
],
|
|
180
|
+
format: "duration"
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
kind: "breakdown",
|
|
184
|
+
title: "Run errors",
|
|
185
|
+
data: {
|
|
186
|
+
provider: "agent.runs.errors"
|
|
187
|
+
},
|
|
188
|
+
style: "donut"
|
|
189
|
+
}
|
|
190
|
+
]
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
title: "Runs",
|
|
194
|
+
panels: [
|
|
195
|
+
{
|
|
196
|
+
kind: "table",
|
|
197
|
+
title: "Runs by agent",
|
|
198
|
+
data: {
|
|
199
|
+
provider: "agent.runs.byAgent"
|
|
200
|
+
},
|
|
201
|
+
columns: [
|
|
202
|
+
{
|
|
203
|
+
key: "agentName",
|
|
204
|
+
label: "Agent"
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
key: "runs",
|
|
208
|
+
label: "Runs"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
key: "failed",
|
|
212
|
+
label: "Failed"
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
key: "retries",
|
|
216
|
+
label: "Retries"
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
kind: "table",
|
|
222
|
+
title: "Recent runs",
|
|
223
|
+
data: {
|
|
224
|
+
provider: "agent.runs.recent"
|
|
225
|
+
},
|
|
226
|
+
columns: [
|
|
227
|
+
{
|
|
228
|
+
key: "startedAt",
|
|
229
|
+
label: "Started"
|
|
230
|
+
},
|
|
231
|
+
col("runId", "Run", opts.runHref),
|
|
232
|
+
col("threadId", "Thread", opts.threadHref),
|
|
233
|
+
{
|
|
234
|
+
key: "actorRef",
|
|
235
|
+
label: "Actor"
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
key: "agentName",
|
|
239
|
+
label: "Agent"
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
key: "status",
|
|
243
|
+
label: "Status"
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
key: "durationMs",
|
|
247
|
+
label: "Duration (ms)"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
key: "retries",
|
|
251
|
+
label: "Retries"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
key: "errorCode",
|
|
255
|
+
label: "Error code"
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
key: "errorMessage",
|
|
259
|
+
label: "Error"
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
key: "promptHash",
|
|
263
|
+
label: "Prompt"
|
|
264
|
+
}
|
|
265
|
+
]
|
|
266
|
+
}
|
|
267
|
+
]
|
|
268
|
+
},
|
|
80
269
|
{
|
|
81
270
|
title: "Spend",
|
|
82
271
|
cols: 2,
|
|
@@ -194,6 +383,7 @@ function agentDashboard() {
|
|
|
194
383
|
},
|
|
195
384
|
{
|
|
196
385
|
title: "Threads",
|
|
386
|
+
cols: 2,
|
|
197
387
|
panels: [
|
|
198
388
|
{
|
|
199
389
|
kind: "table",
|
|
@@ -223,6 +413,79 @@ function agentDashboard() {
|
|
|
223
413
|
label: "Cost (USD)"
|
|
224
414
|
}
|
|
225
415
|
]
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
kind: "table",
|
|
419
|
+
title: "Recently active threads",
|
|
420
|
+
data: {
|
|
421
|
+
provider: "agent.threads.recent"
|
|
422
|
+
},
|
|
423
|
+
columns: [
|
|
424
|
+
col("threadId", "Thread", opts.threadHref),
|
|
425
|
+
{
|
|
426
|
+
key: "title",
|
|
427
|
+
label: "Title"
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
key: "actorRef",
|
|
431
|
+
label: "Actor"
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
key: "messageCount",
|
|
435
|
+
label: "Messages"
|
|
436
|
+
},
|
|
437
|
+
{
|
|
438
|
+
key: "totalTokens",
|
|
439
|
+
label: "Tokens"
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
key: "lastActivityAt",
|
|
443
|
+
label: "Last activity"
|
|
444
|
+
}
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
]
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
title: "Approvals",
|
|
451
|
+
cols: 3,
|
|
452
|
+
panels: [
|
|
453
|
+
{
|
|
454
|
+
kind: "stat",
|
|
455
|
+
title: "Pending approvals",
|
|
456
|
+
data: {
|
|
457
|
+
provider: "agent.approvals.pending"
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
kind: "table",
|
|
462
|
+
title: "Approvals inbox",
|
|
463
|
+
data: {
|
|
464
|
+
provider: "agent.approvals.recent"
|
|
465
|
+
},
|
|
466
|
+
columns: [
|
|
467
|
+
{
|
|
468
|
+
key: "requestedAt",
|
|
469
|
+
label: "Requested"
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
key: "toolName",
|
|
473
|
+
label: "Tool"
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
key: "threadTitle",
|
|
477
|
+
label: "Thread"
|
|
478
|
+
},
|
|
479
|
+
col("threadId", "Thread id", opts.threadHref),
|
|
480
|
+
{
|
|
481
|
+
key: "actorRef",
|
|
482
|
+
label: "Actor"
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
key: "agentName",
|
|
486
|
+
label: "Agent"
|
|
487
|
+
}
|
|
488
|
+
]
|
|
226
489
|
}
|
|
227
490
|
]
|
|
228
491
|
},
|
|
@@ -238,13 +501,50 @@ function agentDashboard() {
|
|
|
238
501
|
},
|
|
239
502
|
style: "donut"
|
|
240
503
|
},
|
|
504
|
+
{
|
|
505
|
+
kind: "table",
|
|
506
|
+
title: "Tool stats",
|
|
507
|
+
data: {
|
|
508
|
+
provider: "agent.tools.stats"
|
|
509
|
+
},
|
|
510
|
+
columns: [
|
|
511
|
+
{
|
|
512
|
+
key: "toolName",
|
|
513
|
+
label: "Tool"
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
key: "toolType",
|
|
517
|
+
label: "Type"
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
key: "calls",
|
|
521
|
+
label: "Calls"
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
key: "failed",
|
|
525
|
+
label: "Failed"
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
key: "rejected",
|
|
529
|
+
label: "Rejected"
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
key: "p95ExecutionMs",
|
|
533
|
+
label: "p95 (ms)"
|
|
534
|
+
}
|
|
535
|
+
]
|
|
536
|
+
},
|
|
241
537
|
{
|
|
242
538
|
kind: "table",
|
|
243
539
|
title: "Recent tool calls",
|
|
244
540
|
data: {
|
|
245
|
-
provider: "agent.tools"
|
|
541
|
+
provider: "agent.tools.recent"
|
|
246
542
|
},
|
|
247
543
|
columns: [
|
|
544
|
+
{
|
|
545
|
+
key: "createdAt",
|
|
546
|
+
label: "When"
|
|
547
|
+
},
|
|
248
548
|
{
|
|
249
549
|
key: "toolName",
|
|
250
550
|
label: "Tool"
|
|
@@ -257,10 +557,7 @@ function agentDashboard() {
|
|
|
257
557
|
key: "status",
|
|
258
558
|
label: "Status"
|
|
259
559
|
},
|
|
260
|
-
|
|
261
|
-
key: "runId",
|
|
262
|
-
label: "Run"
|
|
263
|
-
}
|
|
560
|
+
col("threadId", "Thread", opts.threadHref)
|
|
264
561
|
]
|
|
265
562
|
}
|
|
266
563
|
]
|
|
@@ -362,7 +659,7 @@ function isRecord(value) {
|
|
|
362
659
|
}
|
|
363
660
|
__name(isRecord, "isRecord");
|
|
364
661
|
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";
|
|
662
|
+
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
663
|
}
|
|
367
664
|
__name(isGovernanceQueries, "isGovernanceQueries");
|
|
368
665
|
function resolveGovernanceQueries(ctx) {
|
|
@@ -463,6 +760,98 @@ function toUsageTrendRows(points) {
|
|
|
463
760
|
}));
|
|
464
761
|
}
|
|
465
762
|
__name(toUsageTrendRows, "toUsageTrendRows");
|
|
763
|
+
var NO_VALUE = "\u2014";
|
|
764
|
+
function toRunAgentTableRows(rows) {
|
|
765
|
+
return rows.map((row) => ({
|
|
766
|
+
agentName: row.agentName,
|
|
767
|
+
runs: row.runs,
|
|
768
|
+
failed: row.failed,
|
|
769
|
+
retries: row.retries
|
|
770
|
+
}));
|
|
771
|
+
}
|
|
772
|
+
__name(toRunAgentTableRows, "toRunAgentTableRows");
|
|
773
|
+
function toRunErrorSegments(rows) {
|
|
774
|
+
return rows.map((row) => ({
|
|
775
|
+
label: row.errorCode,
|
|
776
|
+
value: row.count
|
|
777
|
+
}));
|
|
778
|
+
}
|
|
779
|
+
__name(toRunErrorSegments, "toRunErrorSegments");
|
|
780
|
+
function toRunTrendRows(points) {
|
|
781
|
+
return points.map((point) => ({
|
|
782
|
+
label: point.day,
|
|
783
|
+
runs: point.runs,
|
|
784
|
+
failed: point.failed
|
|
785
|
+
}));
|
|
786
|
+
}
|
|
787
|
+
__name(toRunTrendRows, "toRunTrendRows");
|
|
788
|
+
var ERROR_MESSAGE_CAP = 500;
|
|
789
|
+
function capErrorMessage(message) {
|
|
790
|
+
if (message === null) return null;
|
|
791
|
+
return message.length > ERROR_MESSAGE_CAP ? `${message.slice(0, ERROR_MESSAGE_CAP)}\u2026` : message;
|
|
792
|
+
}
|
|
793
|
+
__name(capErrorMessage, "capErrorMessage");
|
|
794
|
+
var PROMPT_HASH_CHIP_LENGTH = 10;
|
|
795
|
+
function shortPromptHash(promptHash) {
|
|
796
|
+
return promptHash === null ? null : promptHash.slice(0, PROMPT_HASH_CHIP_LENGTH);
|
|
797
|
+
}
|
|
798
|
+
__name(shortPromptHash, "shortPromptHash");
|
|
799
|
+
function toRecentRunTableRows(rows) {
|
|
800
|
+
return rows.map((row) => ({
|
|
801
|
+
startedAt: row.startedAt,
|
|
802
|
+
runId: row.runId,
|
|
803
|
+
threadId: row.threadId,
|
|
804
|
+
actorRef: row.actorRef,
|
|
805
|
+
agentName: row.agentName ?? NO_VALUE,
|
|
806
|
+
status: row.status,
|
|
807
|
+
durationMs: row.durationMs ?? NO_VALUE,
|
|
808
|
+
retries: row.retries,
|
|
809
|
+
errorCode: row.errorCode ?? NO_VALUE,
|
|
810
|
+
errorMessage: capErrorMessage(row.errorMessage) ?? NO_VALUE,
|
|
811
|
+
promptHash: shortPromptHash(row.promptHash) ?? NO_VALUE
|
|
812
|
+
}));
|
|
813
|
+
}
|
|
814
|
+
__name(toRecentRunTableRows, "toRecentRunTableRows");
|
|
815
|
+
function toRecentToolCallRows(rows) {
|
|
816
|
+
return rows;
|
|
817
|
+
}
|
|
818
|
+
__name(toRecentToolCallRows, "toRecentToolCallRows");
|
|
819
|
+
function toRecentThreadTableRows(rows) {
|
|
820
|
+
return rows;
|
|
821
|
+
}
|
|
822
|
+
__name(toRecentThreadTableRows, "toRecentThreadTableRows");
|
|
823
|
+
function toPendingApprovalTableRows(rows) {
|
|
824
|
+
return rows.map((row) => ({
|
|
825
|
+
toolCallId: row.toolCallId,
|
|
826
|
+
toolName: row.toolName,
|
|
827
|
+
threadId: row.threadId,
|
|
828
|
+
threadTitle: row.threadTitle,
|
|
829
|
+
actorRef: row.actorRef,
|
|
830
|
+
agentName: row.agentName ?? NO_VALUE,
|
|
831
|
+
requestedAt: row.requestedAt
|
|
832
|
+
}));
|
|
833
|
+
}
|
|
834
|
+
__name(toPendingApprovalTableRows, "toPendingApprovalTableRows");
|
|
835
|
+
function toToolStatTableRows(rows) {
|
|
836
|
+
return rows.map((row) => ({
|
|
837
|
+
toolName: row.toolName,
|
|
838
|
+
toolType: row.toolType,
|
|
839
|
+
calls: row.calls,
|
|
840
|
+
failed: row.failed,
|
|
841
|
+
rejected: row.rejected,
|
|
842
|
+
p95ExecutionMs: row.p95ExecutionMs ?? NO_VALUE
|
|
843
|
+
}));
|
|
844
|
+
}
|
|
845
|
+
__name(toToolStatTableRows, "toToolStatTableRows");
|
|
846
|
+
var EMPTY_RUN_METRICS = {
|
|
847
|
+
runs: 0,
|
|
848
|
+
completed: 0,
|
|
849
|
+
failed: 0,
|
|
850
|
+
successRate: 0,
|
|
851
|
+
retries: 0,
|
|
852
|
+
durationP50Ms: null,
|
|
853
|
+
durationP95Ms: null
|
|
854
|
+
};
|
|
466
855
|
function governanceStatProvider(name, fetch, format) {
|
|
467
856
|
return {
|
|
468
857
|
name,
|
|
@@ -522,25 +911,149 @@ function agentTopThreadsTableProvider() {
|
|
|
522
911
|
}));
|
|
523
912
|
}
|
|
524
913
|
__name(agentTopThreadsTableProvider, "agentTopThreadsTableProvider");
|
|
914
|
+
function governanceRunMetricsProvider(name, format) {
|
|
915
|
+
return {
|
|
916
|
+
name,
|
|
917
|
+
async resolve(query, ctx) {
|
|
918
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
919
|
+
const metrics = queries ? await queries.runMetrics(resolveRange(query)) : EMPTY_RUN_METRICS;
|
|
920
|
+
return format(metrics);
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
__name(governanceRunMetricsProvider, "governanceRunMetricsProvider");
|
|
925
|
+
function agentRunsTotalProvider() {
|
|
926
|
+
return governanceRunMetricsProvider("agent.runs.total", (metrics) => ({
|
|
927
|
+
value: metrics.runs
|
|
928
|
+
}));
|
|
929
|
+
}
|
|
930
|
+
__name(agentRunsTotalProvider, "agentRunsTotalProvider");
|
|
931
|
+
function agentRunsSuccessRateProvider() {
|
|
932
|
+
return governanceRunMetricsProvider("agent.runs.successRate", (metrics) => ({
|
|
933
|
+
value: metrics.successRate
|
|
934
|
+
}));
|
|
935
|
+
}
|
|
936
|
+
__name(agentRunsSuccessRateProvider, "agentRunsSuccessRateProvider");
|
|
937
|
+
function agentRunsFailedProvider() {
|
|
938
|
+
return governanceRunMetricsProvider("agent.runs.failed", (metrics) => ({
|
|
939
|
+
value: metrics.failed
|
|
940
|
+
}));
|
|
941
|
+
}
|
|
942
|
+
__name(agentRunsFailedProvider, "agentRunsFailedProvider");
|
|
943
|
+
function agentRunsRetriesProvider() {
|
|
944
|
+
return governanceRunMetricsProvider("agent.runs.retries", (metrics) => ({
|
|
945
|
+
value: metrics.retries
|
|
946
|
+
}));
|
|
947
|
+
}
|
|
948
|
+
__name(agentRunsRetriesProvider, "agentRunsRetriesProvider");
|
|
949
|
+
function agentRunsDurationProvider() {
|
|
950
|
+
return governanceRunMetricsProvider("agent.runs.duration", (metrics) => ({
|
|
951
|
+
buckets: [],
|
|
952
|
+
...metrics.durationP50Ms !== null ? {
|
|
953
|
+
p50: metrics.durationP50Ms
|
|
954
|
+
} : {},
|
|
955
|
+
...metrics.durationP95Ms !== null ? {
|
|
956
|
+
p95: metrics.durationP95Ms
|
|
957
|
+
} : {}
|
|
958
|
+
}));
|
|
959
|
+
}
|
|
960
|
+
__name(agentRunsDurationProvider, "agentRunsDurationProvider");
|
|
961
|
+
function agentRunsByAgentTableProvider() {
|
|
962
|
+
return governanceStatProvider("agent.runs.byAgent", (queries, range) => queries.runsByAgent(range), (rows) => ({
|
|
963
|
+
rows: toRunAgentTableRows(rows)
|
|
964
|
+
}));
|
|
965
|
+
}
|
|
966
|
+
__name(agentRunsByAgentTableProvider, "agentRunsByAgentTableProvider");
|
|
967
|
+
function agentRunErrorsProvider() {
|
|
968
|
+
return governanceStatProvider("agent.runs.errors", (queries, range) => queries.runErrors(range), (rows) => ({
|
|
969
|
+
segments: toRunErrorSegments(rows)
|
|
970
|
+
}));
|
|
971
|
+
}
|
|
972
|
+
__name(agentRunErrorsProvider, "agentRunErrorsProvider");
|
|
973
|
+
function agentRunsTrendProvider() {
|
|
974
|
+
return governanceStatProvider("agent.runs.trend", (queries, range) => queries.runTrend(range), (points) => ({
|
|
975
|
+
rows: toRunTrendRows(points)
|
|
976
|
+
}));
|
|
977
|
+
}
|
|
978
|
+
__name(agentRunsTrendProvider, "agentRunsTrendProvider");
|
|
979
|
+
var DEFAULT_RECENT_LIMIT = 50;
|
|
980
|
+
var MAX_RECENT_LIMIT = 500;
|
|
981
|
+
function resolveLimit(query, fallback) {
|
|
982
|
+
const raw = query?.limit;
|
|
983
|
+
const value = typeof raw === "number" && Number.isFinite(raw) ? raw : fallback;
|
|
984
|
+
return Math.min(MAX_RECENT_LIMIT, Math.max(1, Math.trunc(value)));
|
|
985
|
+
}
|
|
986
|
+
__name(resolveLimit, "resolveLimit");
|
|
987
|
+
function governanceLimitProvider(name, defaultLimit, fetch, format) {
|
|
988
|
+
return {
|
|
989
|
+
name,
|
|
990
|
+
async resolve(query, ctx) {
|
|
991
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
992
|
+
const rows = queries ? await fetch(queries, resolveLimit(query, defaultLimit)) : [];
|
|
993
|
+
return format(rows);
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
__name(governanceLimitProvider, "governanceLimitProvider");
|
|
998
|
+
function agentRecentRunsTableProvider() {
|
|
999
|
+
return governanceLimitProvider("agent.runs.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.recentRuns(limit), (rows) => ({
|
|
1000
|
+
rows: toRecentRunTableRows(rows)
|
|
1001
|
+
}));
|
|
1002
|
+
}
|
|
1003
|
+
__name(agentRecentRunsTableProvider, "agentRecentRunsTableProvider");
|
|
1004
|
+
function agentRecentToolCallsTableProvider() {
|
|
1005
|
+
return governanceLimitProvider("agent.tools.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.recentToolCalls(limit), (rows) => ({
|
|
1006
|
+
rows: toRecentToolCallRows(rows)
|
|
1007
|
+
}));
|
|
1008
|
+
}
|
|
1009
|
+
__name(agentRecentToolCallsTableProvider, "agentRecentToolCallsTableProvider");
|
|
1010
|
+
function agentRecentThreadsTableProvider() {
|
|
1011
|
+
return governanceLimitProvider("agent.threads.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.recentThreads(limit), (rows) => ({
|
|
1012
|
+
rows: toRecentThreadTableRows(rows)
|
|
1013
|
+
}));
|
|
1014
|
+
}
|
|
1015
|
+
__name(agentRecentThreadsTableProvider, "agentRecentThreadsTableProvider");
|
|
1016
|
+
var PENDING_APPROVALS_COUNT_LIMIT = 500;
|
|
1017
|
+
function agentPendingApprovalsCountProvider() {
|
|
1018
|
+
return {
|
|
1019
|
+
name: "agent.approvals.pending",
|
|
1020
|
+
async resolve(_query, ctx) {
|
|
1021
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
1022
|
+
const rows = queries ? await queries.pendingApprovals(PENDING_APPROVALS_COUNT_LIMIT) : [];
|
|
1023
|
+
return {
|
|
1024
|
+
value: rows.length
|
|
1025
|
+
};
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
__name(agentPendingApprovalsCountProvider, "agentPendingApprovalsCountProvider");
|
|
1030
|
+
function agentPendingApprovalsTableProvider() {
|
|
1031
|
+
return governanceLimitProvider("agent.approvals.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.pendingApprovals(limit), (rows) => ({
|
|
1032
|
+
rows: toPendingApprovalTableRows(rows)
|
|
1033
|
+
}));
|
|
1034
|
+
}
|
|
1035
|
+
__name(agentPendingApprovalsTableProvider, "agentPendingApprovalsTableProvider");
|
|
1036
|
+
function agentToolStatsTableProvider() {
|
|
1037
|
+
return governanceStatProvider("agent.tools.stats", (queries, range) => queries.toolStats(range), (rows) => ({
|
|
1038
|
+
rows: toToolStatTableRows(rows)
|
|
1039
|
+
}));
|
|
1040
|
+
}
|
|
1041
|
+
__name(agentToolStatsTableProvider, "agentToolStatsTableProvider");
|
|
525
1042
|
|
|
526
1043
|
// src/agent-telescope.watcher.ts
|
|
527
1044
|
var import_node_diagnostics_channel = require("diagnostics_channel");
|
|
1045
|
+
var import_nestjs_agent_core2 = require("@dudousxd/nestjs-agent-core");
|
|
528
1046
|
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
1047
|
var AgentTelescopeWatcher = class {
|
|
537
1048
|
static {
|
|
538
1049
|
__name(this, "AgentTelescopeWatcher");
|
|
539
1050
|
}
|
|
540
1051
|
type = "agent";
|
|
1052
|
+
disposers = [];
|
|
541
1053
|
register(ctx) {
|
|
542
|
-
for (const event of
|
|
543
|
-
|
|
1054
|
+
for (const event of import_nestjs_agent_core2.AGENT_DIAGNOSTIC_EVENTS) {
|
|
1055
|
+
const channel = (0, import_nestjs_diagnostics.channelName)("agent", event);
|
|
1056
|
+
const onMessage = /* @__PURE__ */ __name((message) => {
|
|
544
1057
|
const envelope = message;
|
|
545
1058
|
ctx.record({
|
|
546
1059
|
type: "agent",
|
|
@@ -552,13 +1065,19 @@ var AgentTelescopeWatcher = class {
|
|
|
552
1065
|
envelope.event
|
|
553
1066
|
]
|
|
554
1067
|
});
|
|
555
|
-
});
|
|
1068
|
+
}, "onMessage");
|
|
1069
|
+
(0, import_node_diagnostics_channel.subscribe)(channel, onMessage);
|
|
1070
|
+
this.disposers.push(() => (0, import_node_diagnostics_channel.unsubscribe)(channel, onMessage));
|
|
556
1071
|
}
|
|
557
1072
|
}
|
|
1073
|
+
/** Detach all channel subscriptions (e.g. on module destroy). */
|
|
1074
|
+
dispose() {
|
|
1075
|
+
while (this.disposers.length) this.disposers.pop()?.();
|
|
1076
|
+
}
|
|
558
1077
|
};
|
|
559
1078
|
|
|
560
1079
|
// src/agent-telescope.extension.ts
|
|
561
|
-
function agentTelescopeExtension() {
|
|
1080
|
+
function agentTelescopeExtension(opts = {}) {
|
|
562
1081
|
return (0, import_nestjs_telescope2.defineTelescopeExtension)({
|
|
563
1082
|
name: "agent",
|
|
564
1083
|
watchers: /* @__PURE__ */ __name(() => [
|
|
@@ -572,12 +1091,11 @@ function agentTelescopeExtension() {
|
|
|
572
1091
|
}
|
|
573
1092
|
], "entryTypes"),
|
|
574
1093
|
dashboards: /* @__PURE__ */ __name(() => [
|
|
575
|
-
agentDashboard()
|
|
1094
|
+
agentDashboard(opts)
|
|
576
1095
|
], "dashboards"),
|
|
577
1096
|
dataProviders: /* @__PURE__ */ __name(() => [
|
|
578
1097
|
agentRunsProvider(),
|
|
579
1098
|
agentTokensProvider(),
|
|
580
|
-
agentToolsProvider(),
|
|
581
1099
|
agentToolStatusProvider(),
|
|
582
1100
|
agentSpendTotalProvider(),
|
|
583
1101
|
agentTokensTotalProvider(),
|
|
@@ -586,7 +1104,21 @@ function agentTelescopeExtension() {
|
|
|
586
1104
|
agentUsageTrendProvider(),
|
|
587
1105
|
agentActorSpendTableProvider(),
|
|
588
1106
|
agentSpendByActorProvider(),
|
|
589
|
-
agentTopThreadsTableProvider()
|
|
1107
|
+
agentTopThreadsTableProvider(),
|
|
1108
|
+
agentRunsTotalProvider(),
|
|
1109
|
+
agentRunsSuccessRateProvider(),
|
|
1110
|
+
agentRunsFailedProvider(),
|
|
1111
|
+
agentRunsRetriesProvider(),
|
|
1112
|
+
agentRunsDurationProvider(),
|
|
1113
|
+
agentRunsByAgentTableProvider(),
|
|
1114
|
+
agentRunErrorsProvider(),
|
|
1115
|
+
agentRunsTrendProvider(),
|
|
1116
|
+
agentRecentRunsTableProvider(),
|
|
1117
|
+
agentRecentToolCallsTableProvider(),
|
|
1118
|
+
agentRecentThreadsTableProvider(),
|
|
1119
|
+
agentPendingApprovalsCountProvider(),
|
|
1120
|
+
agentPendingApprovalsTableProvider(),
|
|
1121
|
+
agentToolStatsTableProvider()
|
|
590
1122
|
], "dataProviders")
|
|
591
1123
|
});
|
|
592
1124
|
}
|
|
@@ -597,22 +1129,48 @@ __name(agentTelescopeExtension, "agentTelescopeExtension");
|
|
|
597
1129
|
agentActorSpendTableProvider,
|
|
598
1130
|
agentDashboard,
|
|
599
1131
|
agentModelSpendTableProvider,
|
|
1132
|
+
agentPendingApprovalsCountProvider,
|
|
1133
|
+
agentPendingApprovalsTableProvider,
|
|
1134
|
+
agentRecentRunsTableProvider,
|
|
1135
|
+
agentRecentThreadsTableProvider,
|
|
1136
|
+
agentRecentToolCallsTableProvider,
|
|
1137
|
+
agentRunErrorsProvider,
|
|
1138
|
+
agentRunsByAgentTableProvider,
|
|
1139
|
+
agentRunsDurationProvider,
|
|
1140
|
+
agentRunsFailedProvider,
|
|
600
1141
|
agentRunsProvider,
|
|
1142
|
+
agentRunsRetriesProvider,
|
|
1143
|
+
agentRunsSuccessRateProvider,
|
|
1144
|
+
agentRunsTotalProvider,
|
|
1145
|
+
agentRunsTrendProvider,
|
|
601
1146
|
agentSpendByActorProvider,
|
|
602
1147
|
agentSpendByModelProvider,
|
|
603
1148
|
agentSpendTotalProvider,
|
|
604
1149
|
agentTelescopeExtension,
|
|
605
1150
|
agentTokensProvider,
|
|
606
1151
|
agentTokensTotalProvider,
|
|
1152
|
+
agentToolStatsTableProvider,
|
|
607
1153
|
agentToolStatusProvider,
|
|
608
1154
|
agentToolsProvider,
|
|
1155
|
+
agentTopThreadsTableProvider,
|
|
609
1156
|
agentUsageTrendProvider,
|
|
1157
|
+
capErrorMessage,
|
|
610
1158
|
resolveRange,
|
|
611
1159
|
shiftUtcDay,
|
|
1160
|
+
shortPromptHash,
|
|
612
1161
|
toActorSpendRows,
|
|
613
1162
|
toActorSpendSegments,
|
|
614
1163
|
toModelSpendRows,
|
|
615
1164
|
toModelSpendSegments,
|
|
1165
|
+
toPendingApprovalTableRows,
|
|
1166
|
+
toRecentRunTableRows,
|
|
1167
|
+
toRecentThreadTableRows,
|
|
1168
|
+
toRecentToolCallRows,
|
|
1169
|
+
toRunAgentTableRows,
|
|
1170
|
+
toRunErrorSegments,
|
|
1171
|
+
toRunTrendRows,
|
|
1172
|
+
toThreadSpendRows,
|
|
1173
|
+
toToolStatTableRows,
|
|
616
1174
|
toUsageTrendRows,
|
|
617
1175
|
totalCostUsd,
|
|
618
1176
|
totalTokens
|