@dudousxd/nestjs-agent-telescope 0.1.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/LICENSE +21 -0
- package/README.md +61 -0
- package/dist/index.cjs +641 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +103 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +594 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
AgentTelescopeWatcher: () => AgentTelescopeWatcher,
|
|
25
|
+
agentActorSpendTableProvider: () => agentActorSpendTableProvider,
|
|
26
|
+
agentDashboard: () => agentDashboard,
|
|
27
|
+
agentModelSpendTableProvider: () => agentModelSpendTableProvider,
|
|
28
|
+
agentRunsProvider: () => agentRunsProvider,
|
|
29
|
+
agentSpendByActorProvider: () => agentSpendByActorProvider,
|
|
30
|
+
agentSpendByModelProvider: () => agentSpendByModelProvider,
|
|
31
|
+
agentSpendTotalProvider: () => agentSpendTotalProvider,
|
|
32
|
+
agentTelescopeExtension: () => agentTelescopeExtension,
|
|
33
|
+
agentTokensProvider: () => agentTokensProvider,
|
|
34
|
+
agentTokensTotalProvider: () => agentTokensTotalProvider,
|
|
35
|
+
agentToolStatusProvider: () => agentToolStatusProvider,
|
|
36
|
+
agentToolsProvider: () => agentToolsProvider,
|
|
37
|
+
agentUsageTrendProvider: () => agentUsageTrendProvider,
|
|
38
|
+
resolveRange: () => resolveRange,
|
|
39
|
+
shiftUtcDay: () => shiftUtcDay,
|
|
40
|
+
toActorSpendRows: () => toActorSpendRows,
|
|
41
|
+
toActorSpendSegments: () => toActorSpendSegments,
|
|
42
|
+
toModelSpendRows: () => toModelSpendRows,
|
|
43
|
+
toModelSpendSegments: () => toModelSpendSegments,
|
|
44
|
+
toUsageTrendRows: () => toUsageTrendRows,
|
|
45
|
+
totalCostUsd: () => totalCostUsd,
|
|
46
|
+
totalTokens: () => totalTokens
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(index_exports);
|
|
49
|
+
|
|
50
|
+
// src/agent-telescope.extension.ts
|
|
51
|
+
var import_nestjs_telescope2 = require("@dudousxd/nestjs-telescope");
|
|
52
|
+
|
|
53
|
+
// src/agent-dashboard.ts
|
|
54
|
+
function agentDashboard() {
|
|
55
|
+
return {
|
|
56
|
+
id: "agent.overview",
|
|
57
|
+
label: "Agent",
|
|
58
|
+
panels: [],
|
|
59
|
+
sections: [
|
|
60
|
+
{
|
|
61
|
+
title: "Overview",
|
|
62
|
+
cols: 2,
|
|
63
|
+
panels: [
|
|
64
|
+
{
|
|
65
|
+
kind: "stat",
|
|
66
|
+
title: "Runs",
|
|
67
|
+
data: {
|
|
68
|
+
provider: "agent.runs"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
kind: "stat",
|
|
73
|
+
title: "Tokens",
|
|
74
|
+
data: {
|
|
75
|
+
provider: "agent.tokens"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
title: "Spend",
|
|
82
|
+
cols: 2,
|
|
83
|
+
panels: [
|
|
84
|
+
{
|
|
85
|
+
kind: "stat",
|
|
86
|
+
title: "Total spend (USD)",
|
|
87
|
+
data: {
|
|
88
|
+
provider: "agent.spend.totalCost"
|
|
89
|
+
},
|
|
90
|
+
format: "number"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
kind: "stat",
|
|
94
|
+
title: "Total tokens",
|
|
95
|
+
data: {
|
|
96
|
+
provider: "agent.spend.totalTokens"
|
|
97
|
+
},
|
|
98
|
+
format: "number"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
kind: "breakdown",
|
|
102
|
+
title: "Spend by model",
|
|
103
|
+
data: {
|
|
104
|
+
provider: "agent.spend.byModel"
|
|
105
|
+
},
|
|
106
|
+
style: "donut"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
kind: "timeseries",
|
|
110
|
+
title: "Daily spend & tokens",
|
|
111
|
+
data: {
|
|
112
|
+
provider: "agent.usage.trend"
|
|
113
|
+
},
|
|
114
|
+
series: [
|
|
115
|
+
"costUsd",
|
|
116
|
+
"totalTokens"
|
|
117
|
+
],
|
|
118
|
+
style: "area"
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
title: "Models",
|
|
124
|
+
panels: [
|
|
125
|
+
{
|
|
126
|
+
kind: "table",
|
|
127
|
+
title: "Usage & cost by model",
|
|
128
|
+
data: {
|
|
129
|
+
provider: "agent.spend.byModelTable"
|
|
130
|
+
},
|
|
131
|
+
columns: [
|
|
132
|
+
{
|
|
133
|
+
key: "modelId",
|
|
134
|
+
label: "Model"
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
key: "requests",
|
|
138
|
+
label: "Requests"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
key: "inputTokens",
|
|
142
|
+
label: "Input tokens"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
key: "outputTokens",
|
|
146
|
+
label: "Output tokens"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
key: "costUsd",
|
|
150
|
+
label: "Cost (USD)"
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
title: "Actors",
|
|
158
|
+
cols: 2,
|
|
159
|
+
panels: [
|
|
160
|
+
{
|
|
161
|
+
kind: "breakdown",
|
|
162
|
+
title: "Spend share by actor",
|
|
163
|
+
data: {
|
|
164
|
+
provider: "agent.spend.byActorShare"
|
|
165
|
+
},
|
|
166
|
+
style: "bar"
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
kind: "table",
|
|
170
|
+
title: "Spend by actor",
|
|
171
|
+
data: {
|
|
172
|
+
provider: "agent.spend.byActor"
|
|
173
|
+
},
|
|
174
|
+
columns: [
|
|
175
|
+
{
|
|
176
|
+
key: "actorRef",
|
|
177
|
+
label: "Actor"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
key: "requests",
|
|
181
|
+
label: "Requests"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
key: "totalTokens",
|
|
185
|
+
label: "Tokens"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
key: "costUsd",
|
|
189
|
+
label: "Cost (USD)"
|
|
190
|
+
}
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
]
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
title: "Tools",
|
|
197
|
+
cols: 2,
|
|
198
|
+
panels: [
|
|
199
|
+
{
|
|
200
|
+
kind: "breakdown",
|
|
201
|
+
title: "Tool-call status",
|
|
202
|
+
data: {
|
|
203
|
+
provider: "agent.toolStatus"
|
|
204
|
+
},
|
|
205
|
+
style: "donut"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
kind: "table",
|
|
209
|
+
title: "Recent tool calls",
|
|
210
|
+
data: {
|
|
211
|
+
provider: "agent.tools"
|
|
212
|
+
},
|
|
213
|
+
columns: [
|
|
214
|
+
{
|
|
215
|
+
key: "toolName",
|
|
216
|
+
label: "Tool"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
key: "toolType",
|
|
220
|
+
label: "Type"
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
key: "status",
|
|
224
|
+
label: "Status"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
key: "runId",
|
|
228
|
+
label: "Run"
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
]
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
__name(agentDashboard, "agentDashboard");
|
|
238
|
+
|
|
239
|
+
// src/agent-data-providers.ts
|
|
240
|
+
var import_nestjs_telescope = require("@dudousxd/nestjs-telescope");
|
|
241
|
+
async function fetchEntries(ctx) {
|
|
242
|
+
const storage = ctx.moduleRef.get(import_nestjs_telescope.TELESCOPE_STORAGE, {
|
|
243
|
+
strict: false
|
|
244
|
+
});
|
|
245
|
+
const page = await storage.get({
|
|
246
|
+
type: "agent",
|
|
247
|
+
limit: 5e3
|
|
248
|
+
});
|
|
249
|
+
return page.data;
|
|
250
|
+
}
|
|
251
|
+
__name(fetchEntries, "fetchEntries");
|
|
252
|
+
function ofEvent(entries, event) {
|
|
253
|
+
return entries.filter((entry) => entry.content?.event === event);
|
|
254
|
+
}
|
|
255
|
+
__name(ofEvent, "ofEvent");
|
|
256
|
+
function agentRunsProvider() {
|
|
257
|
+
return {
|
|
258
|
+
name: "agent.runs",
|
|
259
|
+
async resolve(_query, ctx) {
|
|
260
|
+
const finished = ofEvent(await fetchEntries(ctx), "run.finished");
|
|
261
|
+
return {
|
|
262
|
+
value: finished.length
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
__name(agentRunsProvider, "agentRunsProvider");
|
|
268
|
+
function agentTokensProvider() {
|
|
269
|
+
return {
|
|
270
|
+
name: "agent.tokens",
|
|
271
|
+
async resolve(_query, ctx) {
|
|
272
|
+
const finished = ofEvent(await fetchEntries(ctx), "run.finished");
|
|
273
|
+
const value = finished.reduce((sum, entry) => sum + (entry.content?.inputTokens ?? 0) + (entry.content?.outputTokens ?? 0), 0);
|
|
274
|
+
return {
|
|
275
|
+
value
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
__name(agentTokensProvider, "agentTokensProvider");
|
|
281
|
+
function agentToolsProvider() {
|
|
282
|
+
return {
|
|
283
|
+
name: "agent.tools",
|
|
284
|
+
async resolve(_query, ctx) {
|
|
285
|
+
const calls = ofEvent(await fetchEntries(ctx), "tool-call").slice(-50).reverse().map((entry) => ({
|
|
286
|
+
toolName: entry.content?.toolName ?? "",
|
|
287
|
+
toolType: entry.content?.toolType ?? "",
|
|
288
|
+
status: entry.content?.status ?? "",
|
|
289
|
+
runId: entry.content?.runId ?? ""
|
|
290
|
+
}));
|
|
291
|
+
return {
|
|
292
|
+
rows: calls
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
__name(agentToolsProvider, "agentToolsProvider");
|
|
298
|
+
function agentToolStatusProvider() {
|
|
299
|
+
return {
|
|
300
|
+
name: "agent.toolStatus",
|
|
301
|
+
async resolve(_query, ctx) {
|
|
302
|
+
const calls = ofEvent(await fetchEntries(ctx), "tool-call");
|
|
303
|
+
const counts = /* @__PURE__ */ new Map();
|
|
304
|
+
for (const call of calls) {
|
|
305
|
+
const status = call.content?.status ?? "unknown";
|
|
306
|
+
counts.set(status, (counts.get(status) ?? 0) + 1);
|
|
307
|
+
}
|
|
308
|
+
return {
|
|
309
|
+
segments: [
|
|
310
|
+
...counts.entries()
|
|
311
|
+
].map(([label, value]) => ({
|
|
312
|
+
label,
|
|
313
|
+
value
|
|
314
|
+
}))
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
__name(agentToolStatusProvider, "agentToolStatusProvider");
|
|
320
|
+
|
|
321
|
+
// src/agent-governance-providers.ts
|
|
322
|
+
var import_nestjs_agent_core = require("@dudousxd/nestjs-agent-core");
|
|
323
|
+
var DEFAULT_TREND_WINDOW_DAYS = 30;
|
|
324
|
+
var ISO_DAY_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
|
|
325
|
+
function isRecord(value) {
|
|
326
|
+
return typeof value === "object" && value !== null;
|
|
327
|
+
}
|
|
328
|
+
__name(isRecord, "isRecord");
|
|
329
|
+
function isGovernanceQueries(value) {
|
|
330
|
+
return isRecord(value) && typeof value.spendByModel === "function" && typeof value.spendByActor === "function" && typeof value.usageTrend === "function" && typeof value.recentToolCalls === "function" && typeof value.recentThreads === "function";
|
|
331
|
+
}
|
|
332
|
+
__name(isGovernanceQueries, "isGovernanceQueries");
|
|
333
|
+
function resolveGovernanceQueries(ctx) {
|
|
334
|
+
let resolved;
|
|
335
|
+
try {
|
|
336
|
+
resolved = ctx.moduleRef.get(import_nestjs_agent_core.AGENT_GOVERNANCE_QUERIES, {
|
|
337
|
+
strict: false
|
|
338
|
+
});
|
|
339
|
+
} catch {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
return isGovernanceQueries(resolved) ? resolved : null;
|
|
343
|
+
}
|
|
344
|
+
__name(resolveGovernanceQueries, "resolveGovernanceQueries");
|
|
345
|
+
function isIsoDay(value) {
|
|
346
|
+
return typeof value === "string" && ISO_DAY_PATTERN.test(value);
|
|
347
|
+
}
|
|
348
|
+
__name(isIsoDay, "isIsoDay");
|
|
349
|
+
function todayUtcDay() {
|
|
350
|
+
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
351
|
+
}
|
|
352
|
+
__name(todayUtcDay, "todayUtcDay");
|
|
353
|
+
function shiftUtcDay(day, deltaDays) {
|
|
354
|
+
const shifted = /* @__PURE__ */ new Date(`${day}T00:00:00.000Z`);
|
|
355
|
+
shifted.setUTCDate(shifted.getUTCDate() + deltaDays);
|
|
356
|
+
return shifted.toISOString().slice(0, 10);
|
|
357
|
+
}
|
|
358
|
+
__name(shiftUtcDay, "shiftUtcDay");
|
|
359
|
+
function resolveRange(query) {
|
|
360
|
+
const toDay = query && isIsoDay(query.toDay) ? query.toDay : todayUtcDay();
|
|
361
|
+
const fromDay = query && isIsoDay(query.fromDay) ? query.fromDay : shiftUtcDay(toDay, -(DEFAULT_TREND_WINDOW_DAYS - 1));
|
|
362
|
+
return {
|
|
363
|
+
fromDay,
|
|
364
|
+
toDay
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
__name(resolveRange, "resolveRange");
|
|
368
|
+
function roundCents(value) {
|
|
369
|
+
return Math.round(value * 100) / 100;
|
|
370
|
+
}
|
|
371
|
+
__name(roundCents, "roundCents");
|
|
372
|
+
function totalCostUsd(rows) {
|
|
373
|
+
return roundCents(rows.reduce((sum, row) => sum + row.costUsd, 0));
|
|
374
|
+
}
|
|
375
|
+
__name(totalCostUsd, "totalCostUsd");
|
|
376
|
+
function totalTokens(rows) {
|
|
377
|
+
return rows.reduce((sum, row) => sum + row.inputTokens + row.outputTokens, 0);
|
|
378
|
+
}
|
|
379
|
+
__name(totalTokens, "totalTokens");
|
|
380
|
+
function toModelSpendSegments(rows) {
|
|
381
|
+
return rows.filter((row) => row.costUsd > 0).map((row) => ({
|
|
382
|
+
label: row.modelId,
|
|
383
|
+
value: roundCents(row.costUsd)
|
|
384
|
+
}));
|
|
385
|
+
}
|
|
386
|
+
__name(toModelSpendSegments, "toModelSpendSegments");
|
|
387
|
+
function toModelSpendRows(rows) {
|
|
388
|
+
return rows.map((row) => ({
|
|
389
|
+
modelId: row.modelId,
|
|
390
|
+
requests: row.requests,
|
|
391
|
+
inputTokens: row.inputTokens,
|
|
392
|
+
outputTokens: row.outputTokens,
|
|
393
|
+
costUsd: roundCents(row.costUsd)
|
|
394
|
+
}));
|
|
395
|
+
}
|
|
396
|
+
__name(toModelSpendRows, "toModelSpendRows");
|
|
397
|
+
function toActorSpendRows(rows) {
|
|
398
|
+
return rows.map((row) => ({
|
|
399
|
+
actorRef: row.actorRef,
|
|
400
|
+
requests: row.requests,
|
|
401
|
+
totalTokens: row.totalTokens,
|
|
402
|
+
costUsd: roundCents(row.costUsd)
|
|
403
|
+
}));
|
|
404
|
+
}
|
|
405
|
+
__name(toActorSpendRows, "toActorSpendRows");
|
|
406
|
+
function toActorSpendSegments(rows) {
|
|
407
|
+
return rows.filter((row) => row.costUsd > 0).map((row) => ({
|
|
408
|
+
label: row.actorRef,
|
|
409
|
+
value: roundCents(row.costUsd)
|
|
410
|
+
}));
|
|
411
|
+
}
|
|
412
|
+
__name(toActorSpendSegments, "toActorSpendSegments");
|
|
413
|
+
function toUsageTrendRows(points) {
|
|
414
|
+
return points.map((point) => ({
|
|
415
|
+
label: point.day,
|
|
416
|
+
costUsd: roundCents(point.costUsd),
|
|
417
|
+
totalTokens: point.totalTokens
|
|
418
|
+
}));
|
|
419
|
+
}
|
|
420
|
+
__name(toUsageTrendRows, "toUsageTrendRows");
|
|
421
|
+
function agentSpendTotalProvider() {
|
|
422
|
+
return {
|
|
423
|
+
name: "agent.spend.totalCost",
|
|
424
|
+
async resolve(query, ctx) {
|
|
425
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
426
|
+
if (!queries) {
|
|
427
|
+
return {
|
|
428
|
+
value: 0
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
const byModel = await queries.spendByModel(resolveRange(query));
|
|
432
|
+
return {
|
|
433
|
+
value: totalCostUsd(byModel)
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
__name(agentSpendTotalProvider, "agentSpendTotalProvider");
|
|
439
|
+
function agentTokensTotalProvider() {
|
|
440
|
+
return {
|
|
441
|
+
name: "agent.spend.totalTokens",
|
|
442
|
+
async resolve(query, ctx) {
|
|
443
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
444
|
+
if (!queries) {
|
|
445
|
+
return {
|
|
446
|
+
value: 0
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
const byModel = await queries.spendByModel(resolveRange(query));
|
|
450
|
+
return {
|
|
451
|
+
value: totalTokens(byModel)
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
__name(agentTokensTotalProvider, "agentTokensTotalProvider");
|
|
457
|
+
function agentSpendByModelProvider() {
|
|
458
|
+
return {
|
|
459
|
+
name: "agent.spend.byModel",
|
|
460
|
+
async resolve(query, ctx) {
|
|
461
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
462
|
+
if (!queries) {
|
|
463
|
+
return {
|
|
464
|
+
segments: []
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
const byModel = await queries.spendByModel(resolveRange(query));
|
|
468
|
+
return {
|
|
469
|
+
segments: toModelSpendSegments(byModel)
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
__name(agentSpendByModelProvider, "agentSpendByModelProvider");
|
|
475
|
+
function agentModelSpendTableProvider() {
|
|
476
|
+
return {
|
|
477
|
+
name: "agent.spend.byModelTable",
|
|
478
|
+
async resolve(query, ctx) {
|
|
479
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
480
|
+
if (!queries) {
|
|
481
|
+
return {
|
|
482
|
+
rows: []
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
const byModel = await queries.spendByModel(resolveRange(query));
|
|
486
|
+
return {
|
|
487
|
+
rows: toModelSpendRows(byModel)
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
__name(agentModelSpendTableProvider, "agentModelSpendTableProvider");
|
|
493
|
+
function agentUsageTrendProvider() {
|
|
494
|
+
return {
|
|
495
|
+
name: "agent.usage.trend",
|
|
496
|
+
async resolve(query, ctx) {
|
|
497
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
498
|
+
if (!queries) {
|
|
499
|
+
return {
|
|
500
|
+
rows: []
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
const trend = await queries.usageTrend(resolveRange(query));
|
|
504
|
+
return {
|
|
505
|
+
rows: toUsageTrendRows(trend)
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
__name(agentUsageTrendProvider, "agentUsageTrendProvider");
|
|
511
|
+
function agentActorSpendTableProvider() {
|
|
512
|
+
return {
|
|
513
|
+
name: "agent.spend.byActor",
|
|
514
|
+
async resolve(query, ctx) {
|
|
515
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
516
|
+
if (!queries) {
|
|
517
|
+
return {
|
|
518
|
+
rows: []
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
const byActor = await queries.spendByActor(resolveRange(query));
|
|
522
|
+
return {
|
|
523
|
+
rows: toActorSpendRows(byActor)
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
__name(agentActorSpendTableProvider, "agentActorSpendTableProvider");
|
|
529
|
+
function agentSpendByActorProvider() {
|
|
530
|
+
return {
|
|
531
|
+
name: "agent.spend.byActorShare",
|
|
532
|
+
async resolve(query, ctx) {
|
|
533
|
+
const queries = resolveGovernanceQueries(ctx);
|
|
534
|
+
if (!queries) {
|
|
535
|
+
return {
|
|
536
|
+
segments: []
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
const byActor = await queries.spendByActor(resolveRange(query));
|
|
540
|
+
return {
|
|
541
|
+
segments: toActorSpendSegments(byActor)
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
__name(agentSpendByActorProvider, "agentSpendByActorProvider");
|
|
547
|
+
|
|
548
|
+
// src/agent-telescope.watcher.ts
|
|
549
|
+
var import_node_diagnostics_channel = require("diagnostics_channel");
|
|
550
|
+
var import_nestjs_diagnostics = require("@dudousxd/nestjs-diagnostics");
|
|
551
|
+
var AGENT_EVENTS = [
|
|
552
|
+
"run.started",
|
|
553
|
+
"message",
|
|
554
|
+
"tool-call",
|
|
555
|
+
"quota.exceeded",
|
|
556
|
+
"run.finished"
|
|
557
|
+
];
|
|
558
|
+
var AgentTelescopeWatcher = class {
|
|
559
|
+
static {
|
|
560
|
+
__name(this, "AgentTelescopeWatcher");
|
|
561
|
+
}
|
|
562
|
+
type = "agent";
|
|
563
|
+
register(ctx) {
|
|
564
|
+
for (const event of AGENT_EVENTS) {
|
|
565
|
+
(0, import_node_diagnostics_channel.subscribe)((0, import_nestjs_diagnostics.channelName)("agent", event), (message) => {
|
|
566
|
+
const envelope = message;
|
|
567
|
+
ctx.record({
|
|
568
|
+
type: "agent",
|
|
569
|
+
content: {
|
|
570
|
+
event: envelope.event,
|
|
571
|
+
...envelope.payload
|
|
572
|
+
},
|
|
573
|
+
tags: [
|
|
574
|
+
envelope.event
|
|
575
|
+
]
|
|
576
|
+
});
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
// src/agent-telescope.extension.ts
|
|
583
|
+
function agentTelescopeExtension() {
|
|
584
|
+
return (0, import_nestjs_telescope2.defineTelescopeExtension)({
|
|
585
|
+
name: "agent",
|
|
586
|
+
watchers: /* @__PURE__ */ __name(() => [
|
|
587
|
+
new AgentTelescopeWatcher()
|
|
588
|
+
], "watchers"),
|
|
589
|
+
entryTypes: /* @__PURE__ */ __name(() => [
|
|
590
|
+
{
|
|
591
|
+
id: "agent",
|
|
592
|
+
label: "Agent",
|
|
593
|
+
dot: "bg-violet-400"
|
|
594
|
+
}
|
|
595
|
+
], "entryTypes"),
|
|
596
|
+
dashboards: /* @__PURE__ */ __name(() => [
|
|
597
|
+
agentDashboard()
|
|
598
|
+
], "dashboards"),
|
|
599
|
+
dataProviders: /* @__PURE__ */ __name(() => [
|
|
600
|
+
agentRunsProvider(),
|
|
601
|
+
agentTokensProvider(),
|
|
602
|
+
agentToolsProvider(),
|
|
603
|
+
agentToolStatusProvider(),
|
|
604
|
+
agentSpendTotalProvider(),
|
|
605
|
+
agentTokensTotalProvider(),
|
|
606
|
+
agentSpendByModelProvider(),
|
|
607
|
+
agentModelSpendTableProvider(),
|
|
608
|
+
agentUsageTrendProvider(),
|
|
609
|
+
agentActorSpendTableProvider(),
|
|
610
|
+
agentSpendByActorProvider()
|
|
611
|
+
], "dataProviders")
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
__name(agentTelescopeExtension, "agentTelescopeExtension");
|
|
615
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
616
|
+
0 && (module.exports = {
|
|
617
|
+
AgentTelescopeWatcher,
|
|
618
|
+
agentActorSpendTableProvider,
|
|
619
|
+
agentDashboard,
|
|
620
|
+
agentModelSpendTableProvider,
|
|
621
|
+
agentRunsProvider,
|
|
622
|
+
agentSpendByActorProvider,
|
|
623
|
+
agentSpendByModelProvider,
|
|
624
|
+
agentSpendTotalProvider,
|
|
625
|
+
agentTelescopeExtension,
|
|
626
|
+
agentTokensProvider,
|
|
627
|
+
agentTokensTotalProvider,
|
|
628
|
+
agentToolStatusProvider,
|
|
629
|
+
agentToolsProvider,
|
|
630
|
+
agentUsageTrendProvider,
|
|
631
|
+
resolveRange,
|
|
632
|
+
shiftUtcDay,
|
|
633
|
+
toActorSpendRows,
|
|
634
|
+
toActorSpendSegments,
|
|
635
|
+
toModelSpendRows,
|
|
636
|
+
toModelSpendSegments,
|
|
637
|
+
toUsageTrendRows,
|
|
638
|
+
totalCostUsd,
|
|
639
|
+
totalTokens
|
|
640
|
+
});
|
|
641
|
+
//# sourceMappingURL=index.cjs.map
|