@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.js
CHANGED
|
@@ -4,8 +4,21 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/agent-telescope.extension.ts
|
|
5
5
|
import { defineTelescopeExtension } from "@dudousxd/nestjs-telescope";
|
|
6
6
|
|
|
7
|
-
// src/agent-dashboard.ts
|
|
8
|
-
function
|
|
7
|
+
// src/agent-dashboard.spec-data.ts
|
|
8
|
+
function col(key, label, href) {
|
|
9
|
+
return href !== void 0 ? {
|
|
10
|
+
key,
|
|
11
|
+
label,
|
|
12
|
+
link: {
|
|
13
|
+
href
|
|
14
|
+
}
|
|
15
|
+
} : {
|
|
16
|
+
key,
|
|
17
|
+
label
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
__name(col, "col");
|
|
21
|
+
function agentDashboard(opts = {}) {
|
|
9
22
|
return {
|
|
10
23
|
id: "agent.overview",
|
|
11
24
|
label: "Agent",
|
|
@@ -31,6 +44,158 @@ function agentDashboard() {
|
|
|
31
44
|
}
|
|
32
45
|
]
|
|
33
46
|
},
|
|
47
|
+
{
|
|
48
|
+
title: "Reliability",
|
|
49
|
+
cols: 4,
|
|
50
|
+
panels: [
|
|
51
|
+
{
|
|
52
|
+
kind: "stat",
|
|
53
|
+
title: "Runs",
|
|
54
|
+
data: {
|
|
55
|
+
provider: "agent.runs.total"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
kind: "stat",
|
|
60
|
+
title: "Success rate",
|
|
61
|
+
data: {
|
|
62
|
+
provider: "agent.runs.successRate"
|
|
63
|
+
},
|
|
64
|
+
format: "percent"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
kind: "stat",
|
|
68
|
+
title: "Failed",
|
|
69
|
+
data: {
|
|
70
|
+
provider: "agent.runs.failed"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
kind: "stat",
|
|
75
|
+
title: "Retries",
|
|
76
|
+
data: {
|
|
77
|
+
provider: "agent.runs.retries"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
title: "Run trends",
|
|
84
|
+
cols: 4,
|
|
85
|
+
panels: [
|
|
86
|
+
{
|
|
87
|
+
kind: "timeseries",
|
|
88
|
+
title: "Runs & failures",
|
|
89
|
+
data: {
|
|
90
|
+
provider: "agent.runs.trend"
|
|
91
|
+
},
|
|
92
|
+
series: [
|
|
93
|
+
"runs",
|
|
94
|
+
"failed"
|
|
95
|
+
],
|
|
96
|
+
style: "stacked"
|
|
97
|
+
},
|
|
98
|
+
// Two duration stats, not a `distribution` panel: RunMetrics carries only p50/p95 (no
|
|
99
|
+
// raw samples to bucket), so a histogram here would be a permanently-empty box.
|
|
100
|
+
{
|
|
101
|
+
kind: "stat",
|
|
102
|
+
title: "Duration p50",
|
|
103
|
+
data: {
|
|
104
|
+
provider: "agent.runs.duration",
|
|
105
|
+
query: {
|
|
106
|
+
metric: "p50"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
format: "duration"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
kind: "stat",
|
|
113
|
+
title: "Duration p95",
|
|
114
|
+
data: {
|
|
115
|
+
provider: "agent.runs.duration",
|
|
116
|
+
query: {
|
|
117
|
+
metric: "p95"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
format: "duration"
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
kind: "breakdown",
|
|
124
|
+
title: "Run errors",
|
|
125
|
+
data: {
|
|
126
|
+
provider: "agent.runs.errors"
|
|
127
|
+
},
|
|
128
|
+
style: "donut"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
title: "Runs",
|
|
134
|
+
panels: [
|
|
135
|
+
{
|
|
136
|
+
kind: "table",
|
|
137
|
+
title: "Runs by agent",
|
|
138
|
+
data: {
|
|
139
|
+
provider: "agent.runs.byAgent"
|
|
140
|
+
},
|
|
141
|
+
columns: [
|
|
142
|
+
{
|
|
143
|
+
key: "agentName",
|
|
144
|
+
label: "Agent"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
key: "runs",
|
|
148
|
+
label: "Runs"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
key: "failed",
|
|
152
|
+
label: "Failed"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
key: "retries",
|
|
156
|
+
label: "Retries"
|
|
157
|
+
}
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
kind: "table",
|
|
162
|
+
title: "Recent runs",
|
|
163
|
+
data: {
|
|
164
|
+
provider: "agent.runs.recent"
|
|
165
|
+
},
|
|
166
|
+
// A deliberate SUBSET of the provider's row shape: the full 11-field row overflows the
|
|
167
|
+
// card horizontally. Thread/actor/retries/errorCode detail lives in the standalone
|
|
168
|
+
// agent dashboard; the provider keeps returning the full row for other consumers.
|
|
169
|
+
columns: [
|
|
170
|
+
{
|
|
171
|
+
key: "startedAt",
|
|
172
|
+
label: "Started"
|
|
173
|
+
},
|
|
174
|
+
col("runId", "Run", opts.runHref),
|
|
175
|
+
{
|
|
176
|
+
key: "agentName",
|
|
177
|
+
label: "Agent"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
key: "status",
|
|
181
|
+
label: "Status"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
key: "durationMs",
|
|
185
|
+
label: "Duration (ms)"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
key: "errorMessage",
|
|
189
|
+
label: "Error"
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
key: "promptHash",
|
|
193
|
+
label: "Prompt"
|
|
194
|
+
}
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
},
|
|
34
199
|
{
|
|
35
200
|
title: "Spend",
|
|
36
201
|
cols: 2,
|
|
@@ -148,6 +313,7 @@ function agentDashboard() {
|
|
|
148
313
|
},
|
|
149
314
|
{
|
|
150
315
|
title: "Threads",
|
|
316
|
+
cols: 2,
|
|
151
317
|
panels: [
|
|
152
318
|
{
|
|
153
319
|
kind: "table",
|
|
@@ -177,6 +343,79 @@ function agentDashboard() {
|
|
|
177
343
|
label: "Cost (USD)"
|
|
178
344
|
}
|
|
179
345
|
]
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
kind: "table",
|
|
349
|
+
title: "Recently active threads",
|
|
350
|
+
data: {
|
|
351
|
+
provider: "agent.threads.recent"
|
|
352
|
+
},
|
|
353
|
+
columns: [
|
|
354
|
+
col("threadId", "Thread", opts.threadHref),
|
|
355
|
+
{
|
|
356
|
+
key: "title",
|
|
357
|
+
label: "Title"
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
key: "actorRef",
|
|
361
|
+
label: "Actor"
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
key: "messageCount",
|
|
365
|
+
label: "Messages"
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
key: "totalTokens",
|
|
369
|
+
label: "Tokens"
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
key: "lastActivityAt",
|
|
373
|
+
label: "Last activity"
|
|
374
|
+
}
|
|
375
|
+
]
|
|
376
|
+
}
|
|
377
|
+
]
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
title: "Approvals",
|
|
381
|
+
cols: 3,
|
|
382
|
+
panels: [
|
|
383
|
+
{
|
|
384
|
+
kind: "stat",
|
|
385
|
+
title: "Pending approvals",
|
|
386
|
+
data: {
|
|
387
|
+
provider: "agent.approvals.pending"
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
kind: "table",
|
|
392
|
+
title: "Approvals inbox",
|
|
393
|
+
data: {
|
|
394
|
+
provider: "agent.approvals.recent"
|
|
395
|
+
},
|
|
396
|
+
columns: [
|
|
397
|
+
{
|
|
398
|
+
key: "requestedAt",
|
|
399
|
+
label: "Requested"
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
key: "toolName",
|
|
403
|
+
label: "Tool"
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
key: "threadTitle",
|
|
407
|
+
label: "Thread"
|
|
408
|
+
},
|
|
409
|
+
col("threadId", "Thread id", opts.threadHref),
|
|
410
|
+
{
|
|
411
|
+
key: "actorRef",
|
|
412
|
+
label: "Actor"
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
key: "agentName",
|
|
416
|
+
label: "Agent"
|
|
417
|
+
}
|
|
418
|
+
]
|
|
180
419
|
}
|
|
181
420
|
]
|
|
182
421
|
},
|
|
@@ -192,13 +431,50 @@ function agentDashboard() {
|
|
|
192
431
|
},
|
|
193
432
|
style: "donut"
|
|
194
433
|
},
|
|
434
|
+
{
|
|
435
|
+
kind: "table",
|
|
436
|
+
title: "Tool stats",
|
|
437
|
+
data: {
|
|
438
|
+
provider: "agent.tools.stats"
|
|
439
|
+
},
|
|
440
|
+
columns: [
|
|
441
|
+
{
|
|
442
|
+
key: "toolName",
|
|
443
|
+
label: "Tool"
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
key: "toolType",
|
|
447
|
+
label: "Type"
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
key: "calls",
|
|
451
|
+
label: "Calls"
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
key: "failed",
|
|
455
|
+
label: "Failed"
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
key: "rejected",
|
|
459
|
+
label: "Rejected"
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
key: "p95ExecutionMs",
|
|
463
|
+
label: "p95 (ms)"
|
|
464
|
+
}
|
|
465
|
+
]
|
|
466
|
+
},
|
|
195
467
|
{
|
|
196
468
|
kind: "table",
|
|
197
469
|
title: "Recent tool calls",
|
|
198
470
|
data: {
|
|
199
|
-
provider: "agent.tools"
|
|
471
|
+
provider: "agent.tools.recent"
|
|
200
472
|
},
|
|
201
473
|
columns: [
|
|
474
|
+
{
|
|
475
|
+
key: "createdAt",
|
|
476
|
+
label: "When"
|
|
477
|
+
},
|
|
202
478
|
{
|
|
203
479
|
key: "toolName",
|
|
204
480
|
label: "Tool"
|
|
@@ -211,10 +487,7 @@ function agentDashboard() {
|
|
|
211
487
|
key: "status",
|
|
212
488
|
label: "Status"
|
|
213
489
|
},
|
|
214
|
-
|
|
215
|
-
key: "runId",
|
|
216
|
-
label: "Run"
|
|
217
|
-
}
|
|
490
|
+
col("threadId", "Thread", opts.threadHref)
|
|
218
491
|
]
|
|
219
492
|
}
|
|
220
493
|
]
|
|
@@ -316,7 +589,7 @@ function isRecord(value) {
|
|
|
316
589
|
}
|
|
317
590
|
__name(isRecord, "isRecord");
|
|
318
591
|
function isGovernanceQueries(value) {
|
|
319
|
-
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";
|
|
592
|
+
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";
|
|
320
593
|
}
|
|
321
594
|
__name(isGovernanceQueries, "isGovernanceQueries");
|
|
322
595
|
function resolveGovernanceQueries(ctx) {
|
|
@@ -417,6 +690,98 @@ function toUsageTrendRows(points) {
|
|
|
417
690
|
}));
|
|
418
691
|
}
|
|
419
692
|
__name(toUsageTrendRows, "toUsageTrendRows");
|
|
693
|
+
var NO_VALUE = "\u2014";
|
|
694
|
+
function toRunAgentTableRows(rows) {
|
|
695
|
+
return rows.map((row) => ({
|
|
696
|
+
agentName: row.agentName,
|
|
697
|
+
runs: row.runs,
|
|
698
|
+
failed: row.failed,
|
|
699
|
+
retries: row.retries
|
|
700
|
+
}));
|
|
701
|
+
}
|
|
702
|
+
__name(toRunAgentTableRows, "toRunAgentTableRows");
|
|
703
|
+
function toRunErrorSegments(rows) {
|
|
704
|
+
return rows.map((row) => ({
|
|
705
|
+
label: row.errorCode,
|
|
706
|
+
value: row.count
|
|
707
|
+
}));
|
|
708
|
+
}
|
|
709
|
+
__name(toRunErrorSegments, "toRunErrorSegments");
|
|
710
|
+
function toRunTrendRows(points) {
|
|
711
|
+
return points.map((point) => ({
|
|
712
|
+
label: point.day,
|
|
713
|
+
runs: point.runs,
|
|
714
|
+
failed: point.failed
|
|
715
|
+
}));
|
|
716
|
+
}
|
|
717
|
+
__name(toRunTrendRows, "toRunTrendRows");
|
|
718
|
+
var ERROR_MESSAGE_CAP = 500;
|
|
719
|
+
function capErrorMessage(message) {
|
|
720
|
+
if (message === null) return null;
|
|
721
|
+
return message.length > ERROR_MESSAGE_CAP ? `${message.slice(0, ERROR_MESSAGE_CAP)}\u2026` : message;
|
|
722
|
+
}
|
|
723
|
+
__name(capErrorMessage, "capErrorMessage");
|
|
724
|
+
var PROMPT_HASH_CHIP_LENGTH = 10;
|
|
725
|
+
function shortPromptHash(promptHash) {
|
|
726
|
+
return promptHash === null ? null : promptHash.slice(0, PROMPT_HASH_CHIP_LENGTH);
|
|
727
|
+
}
|
|
728
|
+
__name(shortPromptHash, "shortPromptHash");
|
|
729
|
+
function toRecentRunTableRows(rows) {
|
|
730
|
+
return rows.map((row) => ({
|
|
731
|
+
startedAt: row.startedAt,
|
|
732
|
+
runId: row.runId,
|
|
733
|
+
threadId: row.threadId,
|
|
734
|
+
actorRef: row.actorRef,
|
|
735
|
+
agentName: row.agentName ?? NO_VALUE,
|
|
736
|
+
status: row.status,
|
|
737
|
+
durationMs: row.durationMs ?? NO_VALUE,
|
|
738
|
+
retries: row.retries,
|
|
739
|
+
errorCode: row.errorCode ?? NO_VALUE,
|
|
740
|
+
errorMessage: capErrorMessage(row.errorMessage) ?? NO_VALUE,
|
|
741
|
+
promptHash: shortPromptHash(row.promptHash) ?? NO_VALUE
|
|
742
|
+
}));
|
|
743
|
+
}
|
|
744
|
+
__name(toRecentRunTableRows, "toRecentRunTableRows");
|
|
745
|
+
function toRecentToolCallRows(rows) {
|
|
746
|
+
return rows;
|
|
747
|
+
}
|
|
748
|
+
__name(toRecentToolCallRows, "toRecentToolCallRows");
|
|
749
|
+
function toRecentThreadTableRows(rows) {
|
|
750
|
+
return rows;
|
|
751
|
+
}
|
|
752
|
+
__name(toRecentThreadTableRows, "toRecentThreadTableRows");
|
|
753
|
+
function toPendingApprovalTableRows(rows) {
|
|
754
|
+
return rows.map((row) => ({
|
|
755
|
+
toolCallId: row.toolCallId,
|
|
756
|
+
toolName: row.toolName,
|
|
757
|
+
threadId: row.threadId,
|
|
758
|
+
threadTitle: row.threadTitle,
|
|
759
|
+
actorRef: row.actorRef,
|
|
760
|
+
agentName: row.agentName ?? NO_VALUE,
|
|
761
|
+
requestedAt: row.requestedAt
|
|
762
|
+
}));
|
|
763
|
+
}
|
|
764
|
+
__name(toPendingApprovalTableRows, "toPendingApprovalTableRows");
|
|
765
|
+
function toToolStatTableRows(rows) {
|
|
766
|
+
return rows.map((row) => ({
|
|
767
|
+
toolName: row.toolName,
|
|
768
|
+
toolType: row.toolType,
|
|
769
|
+
calls: row.calls,
|
|
770
|
+
failed: row.failed,
|
|
771
|
+
rejected: row.rejected,
|
|
772
|
+
p95ExecutionMs: row.p95ExecutionMs ?? NO_VALUE
|
|
773
|
+
}));
|
|
774
|
+
}
|
|
775
|
+
__name(toToolStatTableRows, "toToolStatTableRows");
|
|
776
|
+
var EMPTY_RUN_METRICS = {
|
|
777
|
+
runs: 0,
|
|
778
|
+
completed: 0,
|
|
779
|
+
failed: 0,
|
|
780
|
+
successRate: 0,
|
|
781
|
+
retries: 0,
|
|
782
|
+
durationP50Ms: null,
|
|
783
|
+
durationP95Ms: null
|
|
784
|
+
};
|
|
420
785
|
function governanceStatProvider(name, fetch, format) {
|
|
421
786
|
return {
|
|
422
787
|
name,
|
|
@@ -476,25 +841,152 @@ function agentTopThreadsTableProvider() {
|
|
|
476
841
|
}));
|
|
477
842
|
}
|
|
478
843
|
__name(agentTopThreadsTableProvider, "agentTopThreadsTableProvider");
|
|
844
|
+
function governanceRunMetricsProvider(name, format) {
|
|
845
|
+
return {
|
|
846
|
+
name,
|
|
847
|
+
async resolve(query, ctx) {
|
|
848
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
849
|
+
const metrics = queries ? await queries.runMetrics(resolveRange(query)) : EMPTY_RUN_METRICS;
|
|
850
|
+
return format(metrics);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
__name(governanceRunMetricsProvider, "governanceRunMetricsProvider");
|
|
855
|
+
function agentRunsTotalProvider() {
|
|
856
|
+
return governanceRunMetricsProvider("agent.runs.total", (metrics) => ({
|
|
857
|
+
value: metrics.runs
|
|
858
|
+
}));
|
|
859
|
+
}
|
|
860
|
+
__name(agentRunsTotalProvider, "agentRunsTotalProvider");
|
|
861
|
+
function agentRunsSuccessRateProvider() {
|
|
862
|
+
return governanceRunMetricsProvider("agent.runs.successRate", (metrics) => ({
|
|
863
|
+
value: metrics.successRate
|
|
864
|
+
}));
|
|
865
|
+
}
|
|
866
|
+
__name(agentRunsSuccessRateProvider, "agentRunsSuccessRateProvider");
|
|
867
|
+
function agentRunsFailedProvider() {
|
|
868
|
+
return governanceRunMetricsProvider("agent.runs.failed", (metrics) => ({
|
|
869
|
+
value: metrics.failed
|
|
870
|
+
}));
|
|
871
|
+
}
|
|
872
|
+
__name(agentRunsFailedProvider, "agentRunsFailedProvider");
|
|
873
|
+
function agentRunsRetriesProvider() {
|
|
874
|
+
return governanceRunMetricsProvider("agent.runs.retries", (metrics) => ({
|
|
875
|
+
value: metrics.retries
|
|
876
|
+
}));
|
|
877
|
+
}
|
|
878
|
+
__name(agentRunsRetriesProvider, "agentRunsRetriesProvider");
|
|
879
|
+
function agentRunsDurationProvider() {
|
|
880
|
+
return {
|
|
881
|
+
name: "agent.runs.duration",
|
|
882
|
+
async resolve(query, ctx) {
|
|
883
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
884
|
+
const metrics = queries ? await queries.runMetrics(resolveRange(query)) : EMPTY_RUN_METRICS;
|
|
885
|
+
const value = query?.metric === "p95" ? metrics.durationP95Ms : metrics.durationP50Ms;
|
|
886
|
+
return {
|
|
887
|
+
value: value ?? 0
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
__name(agentRunsDurationProvider, "agentRunsDurationProvider");
|
|
893
|
+
function agentRunsByAgentTableProvider() {
|
|
894
|
+
return governanceStatProvider("agent.runs.byAgent", (queries, range) => queries.runsByAgent(range), (rows) => ({
|
|
895
|
+
rows: toRunAgentTableRows(rows)
|
|
896
|
+
}));
|
|
897
|
+
}
|
|
898
|
+
__name(agentRunsByAgentTableProvider, "agentRunsByAgentTableProvider");
|
|
899
|
+
function agentRunErrorsProvider() {
|
|
900
|
+
return governanceStatProvider("agent.runs.errors", (queries, range) => queries.runErrors(range), (rows) => ({
|
|
901
|
+
segments: toRunErrorSegments(rows)
|
|
902
|
+
}));
|
|
903
|
+
}
|
|
904
|
+
__name(agentRunErrorsProvider, "agentRunErrorsProvider");
|
|
905
|
+
function agentRunsTrendProvider() {
|
|
906
|
+
return governanceStatProvider("agent.runs.trend", (queries, range) => queries.runTrend(range), (points) => ({
|
|
907
|
+
rows: toRunTrendRows(points)
|
|
908
|
+
}));
|
|
909
|
+
}
|
|
910
|
+
__name(agentRunsTrendProvider, "agentRunsTrendProvider");
|
|
911
|
+
var DEFAULT_RECENT_LIMIT = 50;
|
|
912
|
+
var MAX_RECENT_LIMIT = 500;
|
|
913
|
+
function resolveLimit(query, fallback) {
|
|
914
|
+
const raw = query?.limit;
|
|
915
|
+
const value = typeof raw === "number" && Number.isFinite(raw) ? raw : fallback;
|
|
916
|
+
return Math.min(MAX_RECENT_LIMIT, Math.max(1, Math.trunc(value)));
|
|
917
|
+
}
|
|
918
|
+
__name(resolveLimit, "resolveLimit");
|
|
919
|
+
function governanceLimitProvider(name, defaultLimit, fetch, format) {
|
|
920
|
+
return {
|
|
921
|
+
name,
|
|
922
|
+
async resolve(query, ctx) {
|
|
923
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
924
|
+
const rows = queries ? await fetch(queries, resolveLimit(query, defaultLimit)) : [];
|
|
925
|
+
return format(rows);
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
__name(governanceLimitProvider, "governanceLimitProvider");
|
|
930
|
+
function agentRecentRunsTableProvider() {
|
|
931
|
+
return governanceLimitProvider("agent.runs.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.recentRuns(limit), (rows) => ({
|
|
932
|
+
rows: toRecentRunTableRows(rows)
|
|
933
|
+
}));
|
|
934
|
+
}
|
|
935
|
+
__name(agentRecentRunsTableProvider, "agentRecentRunsTableProvider");
|
|
936
|
+
function agentRecentToolCallsTableProvider() {
|
|
937
|
+
return governanceLimitProvider("agent.tools.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.recentToolCalls(limit), (rows) => ({
|
|
938
|
+
rows: toRecentToolCallRows(rows)
|
|
939
|
+
}));
|
|
940
|
+
}
|
|
941
|
+
__name(agentRecentToolCallsTableProvider, "agentRecentToolCallsTableProvider");
|
|
942
|
+
function agentRecentThreadsTableProvider() {
|
|
943
|
+
return governanceLimitProvider("agent.threads.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.recentThreads(limit), (rows) => ({
|
|
944
|
+
rows: toRecentThreadTableRows(rows)
|
|
945
|
+
}));
|
|
946
|
+
}
|
|
947
|
+
__name(agentRecentThreadsTableProvider, "agentRecentThreadsTableProvider");
|
|
948
|
+
var PENDING_APPROVALS_COUNT_LIMIT = 500;
|
|
949
|
+
function agentPendingApprovalsCountProvider() {
|
|
950
|
+
return {
|
|
951
|
+
name: "agent.approvals.pending",
|
|
952
|
+
async resolve(_query, ctx) {
|
|
953
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
954
|
+
const rows = queries ? await queries.pendingApprovals(PENDING_APPROVALS_COUNT_LIMIT) : [];
|
|
955
|
+
return {
|
|
956
|
+
value: rows.length
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
__name(agentPendingApprovalsCountProvider, "agentPendingApprovalsCountProvider");
|
|
962
|
+
function agentPendingApprovalsTableProvider() {
|
|
963
|
+
return governanceLimitProvider("agent.approvals.recent", DEFAULT_RECENT_LIMIT, (queries, limit) => queries.pendingApprovals(limit), (rows) => ({
|
|
964
|
+
rows: toPendingApprovalTableRows(rows)
|
|
965
|
+
}));
|
|
966
|
+
}
|
|
967
|
+
__name(agentPendingApprovalsTableProvider, "agentPendingApprovalsTableProvider");
|
|
968
|
+
function agentToolStatsTableProvider() {
|
|
969
|
+
return governanceStatProvider("agent.tools.stats", (queries, range) => queries.toolStats(range), (rows) => ({
|
|
970
|
+
rows: toToolStatTableRows(rows)
|
|
971
|
+
}));
|
|
972
|
+
}
|
|
973
|
+
__name(agentToolStatsTableProvider, "agentToolStatsTableProvider");
|
|
479
974
|
|
|
480
975
|
// src/agent-telescope.watcher.ts
|
|
481
|
-
import { subscribe } from "node:diagnostics_channel";
|
|
482
|
-
import {
|
|
483
|
-
|
|
484
|
-
"run.started",
|
|
485
|
-
"message",
|
|
486
|
-
"tool-call",
|
|
487
|
-
"quota.exceeded",
|
|
488
|
-
"run.finished"
|
|
489
|
-
];
|
|
976
|
+
import { subscribe, unsubscribe } from "node:diagnostics_channel";
|
|
977
|
+
import { AGENT_DIAGNOSTIC_EVENTS } from "@dudousxd/nestjs-agent-core";
|
|
978
|
+
import { channelName, claimDiagnostics } from "@dudousxd/nestjs-diagnostics";
|
|
490
979
|
var AgentTelescopeWatcher = class {
|
|
491
980
|
static {
|
|
492
981
|
__name(this, "AgentTelescopeWatcher");
|
|
493
982
|
}
|
|
494
983
|
type = "agent";
|
|
984
|
+
disposers = [];
|
|
495
985
|
register(ctx) {
|
|
496
|
-
|
|
497
|
-
|
|
986
|
+
this.disposers.push(claimDiagnostics("agent", AGENT_DIAGNOSTIC_EVENTS));
|
|
987
|
+
for (const event of AGENT_DIAGNOSTIC_EVENTS) {
|
|
988
|
+
const channel = channelName("agent", event);
|
|
989
|
+
const onMessage = /* @__PURE__ */ __name((message) => {
|
|
498
990
|
const envelope = message;
|
|
499
991
|
ctx.record({
|
|
500
992
|
type: "agent",
|
|
@@ -506,13 +998,19 @@ var AgentTelescopeWatcher = class {
|
|
|
506
998
|
envelope.event
|
|
507
999
|
]
|
|
508
1000
|
});
|
|
509
|
-
});
|
|
1001
|
+
}, "onMessage");
|
|
1002
|
+
subscribe(channel, onMessage);
|
|
1003
|
+
this.disposers.push(() => unsubscribe(channel, onMessage));
|
|
510
1004
|
}
|
|
511
1005
|
}
|
|
1006
|
+
/** Detach all channel subscriptions and release the diagnostics claim (e.g. on module destroy). */
|
|
1007
|
+
dispose() {
|
|
1008
|
+
while (this.disposers.length) this.disposers.pop()?.();
|
|
1009
|
+
}
|
|
512
1010
|
};
|
|
513
1011
|
|
|
514
1012
|
// src/agent-telescope.extension.ts
|
|
515
|
-
function agentTelescopeExtension() {
|
|
1013
|
+
function agentTelescopeExtension(opts = {}) {
|
|
516
1014
|
return defineTelescopeExtension({
|
|
517
1015
|
name: "agent",
|
|
518
1016
|
watchers: /* @__PURE__ */ __name(() => [
|
|
@@ -526,12 +1024,11 @@ function agentTelescopeExtension() {
|
|
|
526
1024
|
}
|
|
527
1025
|
], "entryTypes"),
|
|
528
1026
|
dashboards: /* @__PURE__ */ __name(() => [
|
|
529
|
-
agentDashboard()
|
|
1027
|
+
agentDashboard(opts)
|
|
530
1028
|
], "dashboards"),
|
|
531
1029
|
dataProviders: /* @__PURE__ */ __name(() => [
|
|
532
1030
|
agentRunsProvider(),
|
|
533
1031
|
agentTokensProvider(),
|
|
534
|
-
agentToolsProvider(),
|
|
535
1032
|
agentToolStatusProvider(),
|
|
536
1033
|
agentSpendTotalProvider(),
|
|
537
1034
|
agentTokensTotalProvider(),
|
|
@@ -540,7 +1037,21 @@ function agentTelescopeExtension() {
|
|
|
540
1037
|
agentUsageTrendProvider(),
|
|
541
1038
|
agentActorSpendTableProvider(),
|
|
542
1039
|
agentSpendByActorProvider(),
|
|
543
|
-
agentTopThreadsTableProvider()
|
|
1040
|
+
agentTopThreadsTableProvider(),
|
|
1041
|
+
agentRunsTotalProvider(),
|
|
1042
|
+
agentRunsSuccessRateProvider(),
|
|
1043
|
+
agentRunsFailedProvider(),
|
|
1044
|
+
agentRunsRetriesProvider(),
|
|
1045
|
+
agentRunsDurationProvider(),
|
|
1046
|
+
agentRunsByAgentTableProvider(),
|
|
1047
|
+
agentRunErrorsProvider(),
|
|
1048
|
+
agentRunsTrendProvider(),
|
|
1049
|
+
agentRecentRunsTableProvider(),
|
|
1050
|
+
agentRecentToolCallsTableProvider(),
|
|
1051
|
+
agentRecentThreadsTableProvider(),
|
|
1052
|
+
agentPendingApprovalsCountProvider(),
|
|
1053
|
+
agentPendingApprovalsTableProvider(),
|
|
1054
|
+
agentToolStatsTableProvider()
|
|
544
1055
|
], "dataProviders")
|
|
545
1056
|
});
|
|
546
1057
|
}
|
|
@@ -550,22 +1061,48 @@ export {
|
|
|
550
1061
|
agentActorSpendTableProvider,
|
|
551
1062
|
agentDashboard,
|
|
552
1063
|
agentModelSpendTableProvider,
|
|
1064
|
+
agentPendingApprovalsCountProvider,
|
|
1065
|
+
agentPendingApprovalsTableProvider,
|
|
1066
|
+
agentRecentRunsTableProvider,
|
|
1067
|
+
agentRecentThreadsTableProvider,
|
|
1068
|
+
agentRecentToolCallsTableProvider,
|
|
1069
|
+
agentRunErrorsProvider,
|
|
1070
|
+
agentRunsByAgentTableProvider,
|
|
1071
|
+
agentRunsDurationProvider,
|
|
1072
|
+
agentRunsFailedProvider,
|
|
553
1073
|
agentRunsProvider,
|
|
1074
|
+
agentRunsRetriesProvider,
|
|
1075
|
+
agentRunsSuccessRateProvider,
|
|
1076
|
+
agentRunsTotalProvider,
|
|
1077
|
+
agentRunsTrendProvider,
|
|
554
1078
|
agentSpendByActorProvider,
|
|
555
1079
|
agentSpendByModelProvider,
|
|
556
1080
|
agentSpendTotalProvider,
|
|
557
1081
|
agentTelescopeExtension,
|
|
558
1082
|
agentTokensProvider,
|
|
559
1083
|
agentTokensTotalProvider,
|
|
1084
|
+
agentToolStatsTableProvider,
|
|
560
1085
|
agentToolStatusProvider,
|
|
561
1086
|
agentToolsProvider,
|
|
1087
|
+
agentTopThreadsTableProvider,
|
|
562
1088
|
agentUsageTrendProvider,
|
|
1089
|
+
capErrorMessage,
|
|
563
1090
|
resolveRange,
|
|
564
1091
|
shiftUtcDay,
|
|
1092
|
+
shortPromptHash,
|
|
565
1093
|
toActorSpendRows,
|
|
566
1094
|
toActorSpendSegments,
|
|
567
1095
|
toModelSpendRows,
|
|
568
1096
|
toModelSpendSegments,
|
|
1097
|
+
toPendingApprovalTableRows,
|
|
1098
|
+
toRecentRunTableRows,
|
|
1099
|
+
toRecentThreadTableRows,
|
|
1100
|
+
toRecentToolCallRows,
|
|
1101
|
+
toRunAgentTableRows,
|
|
1102
|
+
toRunErrorSegments,
|
|
1103
|
+
toRunTrendRows,
|
|
1104
|
+
toThreadSpendRows,
|
|
1105
|
+
toToolStatTableRows,
|
|
569
1106
|
toUsageTrendRows,
|
|
570
1107
|
totalCostUsd,
|
|
571
1108
|
totalTokens
|