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