@app-vitals/agent-admin 1.115.2 → 1.116.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/openapi.platform.json +22 -0
- package/package.json +2 -2
- package/prisma/client/internal/class.ts +3 -3
- package/prisma/client/internal/prismaNamespace.ts +1 -0
- package/prisma/client/internal/prismaNamespaceBrowser.ts +1 -0
- package/prisma/client/models/AgentToken.ts +36 -1
- package/prisma/migrations/20261202000000_add_agent_token_kind/migration.sql +4 -0
- package/prisma/schema/schema.prisma +5 -0
- package/src/admin-local-agent.smoke.test.ts +1 -0
- package/src/admin-ui-pages.ts +8 -1
- package/src/admin-ui-pages.unit.test.ts +10 -0
- package/src/admin-ui.fixtures.ts +1 -0
- package/src/agent-cron-run-stats.smoke.test.ts +6 -4
- package/src/agent-tokens.integration.test.ts +23 -0
- package/src/agent-tokens.ts +39 -5
- package/src/agent-tokens.unit.test.ts +127 -0
- package/src/agents-api.sentry.smoke.test.ts +3 -1
- package/src/agents-api.smoke.test.ts +111 -10
- package/src/agents-api.ts +4 -1
- package/src/api-auth.ts +11 -2
- package/src/api-auth.unit.test.ts +82 -12
- package/src/api.smoke.test.ts +2 -0
- package/src/chat.smoke.test.ts +1 -0
- package/src/openapi-schemas.ts +11 -0
- package/src/openapi-schemas.unit.test.ts +1 -0
|
@@ -29,6 +29,7 @@ export type AgentTokenMinAggregateOutputType = {
|
|
|
29
29
|
agentId: string | null
|
|
30
30
|
token: string | null
|
|
31
31
|
label: string | null
|
|
32
|
+
kind: string | null
|
|
32
33
|
createdAt: Date | null
|
|
33
34
|
revokedAt: Date | null
|
|
34
35
|
}
|
|
@@ -38,6 +39,7 @@ export type AgentTokenMaxAggregateOutputType = {
|
|
|
38
39
|
agentId: string | null
|
|
39
40
|
token: string | null
|
|
40
41
|
label: string | null
|
|
42
|
+
kind: string | null
|
|
41
43
|
createdAt: Date | null
|
|
42
44
|
revokedAt: Date | null
|
|
43
45
|
}
|
|
@@ -47,6 +49,7 @@ export type AgentTokenCountAggregateOutputType = {
|
|
|
47
49
|
agentId: number
|
|
48
50
|
token: number
|
|
49
51
|
label: number
|
|
52
|
+
kind: number
|
|
50
53
|
createdAt: number
|
|
51
54
|
revokedAt: number
|
|
52
55
|
_all: number
|
|
@@ -58,6 +61,7 @@ export type AgentTokenMinAggregateInputType = {
|
|
|
58
61
|
agentId?: true
|
|
59
62
|
token?: true
|
|
60
63
|
label?: true
|
|
64
|
+
kind?: true
|
|
61
65
|
createdAt?: true
|
|
62
66
|
revokedAt?: true
|
|
63
67
|
}
|
|
@@ -67,6 +71,7 @@ export type AgentTokenMaxAggregateInputType = {
|
|
|
67
71
|
agentId?: true
|
|
68
72
|
token?: true
|
|
69
73
|
label?: true
|
|
74
|
+
kind?: true
|
|
70
75
|
createdAt?: true
|
|
71
76
|
revokedAt?: true
|
|
72
77
|
}
|
|
@@ -76,6 +81,7 @@ export type AgentTokenCountAggregateInputType = {
|
|
|
76
81
|
agentId?: true
|
|
77
82
|
token?: true
|
|
78
83
|
label?: true
|
|
84
|
+
kind?: true
|
|
79
85
|
createdAt?: true
|
|
80
86
|
revokedAt?: true
|
|
81
87
|
_all?: true
|
|
@@ -158,6 +164,7 @@ export type AgentTokenGroupByOutputType = {
|
|
|
158
164
|
agentId: string
|
|
159
165
|
token: string
|
|
160
166
|
label: string | null
|
|
167
|
+
kind: string
|
|
161
168
|
createdAt: Date
|
|
162
169
|
revokedAt: Date | null
|
|
163
170
|
_count: AgentTokenCountAggregateOutputType | null
|
|
@@ -188,6 +195,7 @@ export type AgentTokenWhereInput = {
|
|
|
188
195
|
agentId?: Prisma.StringFilter<"AgentToken"> | string
|
|
189
196
|
token?: Prisma.StringFilter<"AgentToken"> | string
|
|
190
197
|
label?: Prisma.StringNullableFilter<"AgentToken"> | string | null
|
|
198
|
+
kind?: Prisma.StringFilter<"AgentToken"> | string
|
|
191
199
|
createdAt?: Prisma.DateTimeFilter<"AgentToken"> | Date | string
|
|
192
200
|
revokedAt?: Prisma.DateTimeNullableFilter<"AgentToken"> | Date | string | null
|
|
193
201
|
agent?: Prisma.XOR<Prisma.AgentScalarRelationFilter, Prisma.AgentWhereInput>
|
|
@@ -198,6 +206,7 @@ export type AgentTokenOrderByWithRelationInput = {
|
|
|
198
206
|
agentId?: Prisma.SortOrder
|
|
199
207
|
token?: Prisma.SortOrder
|
|
200
208
|
label?: Prisma.SortOrderInput | Prisma.SortOrder
|
|
209
|
+
kind?: Prisma.SortOrder
|
|
201
210
|
createdAt?: Prisma.SortOrder
|
|
202
211
|
revokedAt?: Prisma.SortOrderInput | Prisma.SortOrder
|
|
203
212
|
agent?: Prisma.AgentOrderByWithRelationInput
|
|
@@ -211,6 +220,7 @@ export type AgentTokenWhereUniqueInput = Prisma.AtLeast<{
|
|
|
211
220
|
NOT?: Prisma.AgentTokenWhereInput | Prisma.AgentTokenWhereInput[]
|
|
212
221
|
agentId?: Prisma.StringFilter<"AgentToken"> | string
|
|
213
222
|
label?: Prisma.StringNullableFilter<"AgentToken"> | string | null
|
|
223
|
+
kind?: Prisma.StringFilter<"AgentToken"> | string
|
|
214
224
|
createdAt?: Prisma.DateTimeFilter<"AgentToken"> | Date | string
|
|
215
225
|
revokedAt?: Prisma.DateTimeNullableFilter<"AgentToken"> | Date | string | null
|
|
216
226
|
agent?: Prisma.XOR<Prisma.AgentScalarRelationFilter, Prisma.AgentWhereInput>
|
|
@@ -221,6 +231,7 @@ export type AgentTokenOrderByWithAggregationInput = {
|
|
|
221
231
|
agentId?: Prisma.SortOrder
|
|
222
232
|
token?: Prisma.SortOrder
|
|
223
233
|
label?: Prisma.SortOrderInput | Prisma.SortOrder
|
|
234
|
+
kind?: Prisma.SortOrder
|
|
224
235
|
createdAt?: Prisma.SortOrder
|
|
225
236
|
revokedAt?: Prisma.SortOrderInput | Prisma.SortOrder
|
|
226
237
|
_count?: Prisma.AgentTokenCountOrderByAggregateInput
|
|
@@ -236,6 +247,7 @@ export type AgentTokenScalarWhereWithAggregatesInput = {
|
|
|
236
247
|
agentId?: Prisma.StringWithAggregatesFilter<"AgentToken"> | string
|
|
237
248
|
token?: Prisma.StringWithAggregatesFilter<"AgentToken"> | string
|
|
238
249
|
label?: Prisma.StringNullableWithAggregatesFilter<"AgentToken"> | string | null
|
|
250
|
+
kind?: Prisma.StringWithAggregatesFilter<"AgentToken"> | string
|
|
239
251
|
createdAt?: Prisma.DateTimeWithAggregatesFilter<"AgentToken"> | Date | string
|
|
240
252
|
revokedAt?: Prisma.DateTimeNullableWithAggregatesFilter<"AgentToken"> | Date | string | null
|
|
241
253
|
}
|
|
@@ -244,6 +256,7 @@ export type AgentTokenCreateInput = {
|
|
|
244
256
|
id?: string
|
|
245
257
|
token: string
|
|
246
258
|
label?: string | null
|
|
259
|
+
kind?: string
|
|
247
260
|
createdAt?: Date | string
|
|
248
261
|
revokedAt?: Date | string | null
|
|
249
262
|
agent: Prisma.AgentCreateNestedOneWithoutTokensInput
|
|
@@ -254,6 +267,7 @@ export type AgentTokenUncheckedCreateInput = {
|
|
|
254
267
|
agentId: string
|
|
255
268
|
token: string
|
|
256
269
|
label?: string | null
|
|
270
|
+
kind?: string
|
|
257
271
|
createdAt?: Date | string
|
|
258
272
|
revokedAt?: Date | string | null
|
|
259
273
|
}
|
|
@@ -262,6 +276,7 @@ export type AgentTokenUpdateInput = {
|
|
|
262
276
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
|
263
277
|
token?: Prisma.StringFieldUpdateOperationsInput | string
|
|
264
278
|
label?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
279
|
+
kind?: Prisma.StringFieldUpdateOperationsInput | string
|
|
265
280
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
266
281
|
revokedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
|
267
282
|
agent?: Prisma.AgentUpdateOneRequiredWithoutTokensNestedInput
|
|
@@ -272,6 +287,7 @@ export type AgentTokenUncheckedUpdateInput = {
|
|
|
272
287
|
agentId?: Prisma.StringFieldUpdateOperationsInput | string
|
|
273
288
|
token?: Prisma.StringFieldUpdateOperationsInput | string
|
|
274
289
|
label?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
290
|
+
kind?: Prisma.StringFieldUpdateOperationsInput | string
|
|
275
291
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
276
292
|
revokedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
|
277
293
|
}
|
|
@@ -281,6 +297,7 @@ export type AgentTokenCreateManyInput = {
|
|
|
281
297
|
agentId: string
|
|
282
298
|
token: string
|
|
283
299
|
label?: string | null
|
|
300
|
+
kind?: string
|
|
284
301
|
createdAt?: Date | string
|
|
285
302
|
revokedAt?: Date | string | null
|
|
286
303
|
}
|
|
@@ -289,6 +306,7 @@ export type AgentTokenUpdateManyMutationInput = {
|
|
|
289
306
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
|
290
307
|
token?: Prisma.StringFieldUpdateOperationsInput | string
|
|
291
308
|
label?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
309
|
+
kind?: Prisma.StringFieldUpdateOperationsInput | string
|
|
292
310
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
293
311
|
revokedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
|
294
312
|
}
|
|
@@ -298,6 +316,7 @@ export type AgentTokenUncheckedUpdateManyInput = {
|
|
|
298
316
|
agentId?: Prisma.StringFieldUpdateOperationsInput | string
|
|
299
317
|
token?: Prisma.StringFieldUpdateOperationsInput | string
|
|
300
318
|
label?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
319
|
+
kind?: Prisma.StringFieldUpdateOperationsInput | string
|
|
301
320
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
302
321
|
revokedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
|
303
322
|
}
|
|
@@ -317,6 +336,7 @@ export type AgentTokenCountOrderByAggregateInput = {
|
|
|
317
336
|
agentId?: Prisma.SortOrder
|
|
318
337
|
token?: Prisma.SortOrder
|
|
319
338
|
label?: Prisma.SortOrder
|
|
339
|
+
kind?: Prisma.SortOrder
|
|
320
340
|
createdAt?: Prisma.SortOrder
|
|
321
341
|
revokedAt?: Prisma.SortOrder
|
|
322
342
|
}
|
|
@@ -326,6 +346,7 @@ export type AgentTokenMaxOrderByAggregateInput = {
|
|
|
326
346
|
agentId?: Prisma.SortOrder
|
|
327
347
|
token?: Prisma.SortOrder
|
|
328
348
|
label?: Prisma.SortOrder
|
|
349
|
+
kind?: Prisma.SortOrder
|
|
329
350
|
createdAt?: Prisma.SortOrder
|
|
330
351
|
revokedAt?: Prisma.SortOrder
|
|
331
352
|
}
|
|
@@ -335,6 +356,7 @@ export type AgentTokenMinOrderByAggregateInput = {
|
|
|
335
356
|
agentId?: Prisma.SortOrder
|
|
336
357
|
token?: Prisma.SortOrder
|
|
337
358
|
label?: Prisma.SortOrder
|
|
359
|
+
kind?: Prisma.SortOrder
|
|
338
360
|
createdAt?: Prisma.SortOrder
|
|
339
361
|
revokedAt?: Prisma.SortOrder
|
|
340
362
|
}
|
|
@@ -385,6 +407,7 @@ export type AgentTokenCreateWithoutAgentInput = {
|
|
|
385
407
|
id?: string
|
|
386
408
|
token: string
|
|
387
409
|
label?: string | null
|
|
410
|
+
kind?: string
|
|
388
411
|
createdAt?: Date | string
|
|
389
412
|
revokedAt?: Date | string | null
|
|
390
413
|
}
|
|
@@ -393,6 +416,7 @@ export type AgentTokenUncheckedCreateWithoutAgentInput = {
|
|
|
393
416
|
id?: string
|
|
394
417
|
token: string
|
|
395
418
|
label?: string | null
|
|
419
|
+
kind?: string
|
|
396
420
|
createdAt?: Date | string
|
|
397
421
|
revokedAt?: Date | string | null
|
|
398
422
|
}
|
|
@@ -431,6 +455,7 @@ export type AgentTokenScalarWhereInput = {
|
|
|
431
455
|
agentId?: Prisma.StringFilter<"AgentToken"> | string
|
|
432
456
|
token?: Prisma.StringFilter<"AgentToken"> | string
|
|
433
457
|
label?: Prisma.StringNullableFilter<"AgentToken"> | string | null
|
|
458
|
+
kind?: Prisma.StringFilter<"AgentToken"> | string
|
|
434
459
|
createdAt?: Prisma.DateTimeFilter<"AgentToken"> | Date | string
|
|
435
460
|
revokedAt?: Prisma.DateTimeNullableFilter<"AgentToken"> | Date | string | null
|
|
436
461
|
}
|
|
@@ -439,6 +464,7 @@ export type AgentTokenCreateManyAgentInput = {
|
|
|
439
464
|
id?: string
|
|
440
465
|
token: string
|
|
441
466
|
label?: string | null
|
|
467
|
+
kind?: string
|
|
442
468
|
createdAt?: Date | string
|
|
443
469
|
revokedAt?: Date | string | null
|
|
444
470
|
}
|
|
@@ -447,6 +473,7 @@ export type AgentTokenUpdateWithoutAgentInput = {
|
|
|
447
473
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
|
448
474
|
token?: Prisma.StringFieldUpdateOperationsInput | string
|
|
449
475
|
label?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
476
|
+
kind?: Prisma.StringFieldUpdateOperationsInput | string
|
|
450
477
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
451
478
|
revokedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
|
452
479
|
}
|
|
@@ -455,6 +482,7 @@ export type AgentTokenUncheckedUpdateWithoutAgentInput = {
|
|
|
455
482
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
|
456
483
|
token?: Prisma.StringFieldUpdateOperationsInput | string
|
|
457
484
|
label?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
485
|
+
kind?: Prisma.StringFieldUpdateOperationsInput | string
|
|
458
486
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
459
487
|
revokedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
|
460
488
|
}
|
|
@@ -463,6 +491,7 @@ export type AgentTokenUncheckedUpdateManyWithoutAgentInput = {
|
|
|
463
491
|
id?: Prisma.StringFieldUpdateOperationsInput | string
|
|
464
492
|
token?: Prisma.StringFieldUpdateOperationsInput | string
|
|
465
493
|
label?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
|
|
494
|
+
kind?: Prisma.StringFieldUpdateOperationsInput | string
|
|
466
495
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
467
496
|
revokedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
|
|
468
497
|
}
|
|
@@ -474,6 +503,7 @@ export type AgentTokenSelect<ExtArgs extends runtime.Types.Extensions.InternalAr
|
|
|
474
503
|
agentId?: boolean
|
|
475
504
|
token?: boolean
|
|
476
505
|
label?: boolean
|
|
506
|
+
kind?: boolean
|
|
477
507
|
createdAt?: boolean
|
|
478
508
|
revokedAt?: boolean
|
|
479
509
|
agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
|
|
@@ -484,6 +514,7 @@ export type AgentTokenSelectCreateManyAndReturn<ExtArgs extends runtime.Types.Ex
|
|
|
484
514
|
agentId?: boolean
|
|
485
515
|
token?: boolean
|
|
486
516
|
label?: boolean
|
|
517
|
+
kind?: boolean
|
|
487
518
|
createdAt?: boolean
|
|
488
519
|
revokedAt?: boolean
|
|
489
520
|
agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
|
|
@@ -494,6 +525,7 @@ export type AgentTokenSelectUpdateManyAndReturn<ExtArgs extends runtime.Types.Ex
|
|
|
494
525
|
agentId?: boolean
|
|
495
526
|
token?: boolean
|
|
496
527
|
label?: boolean
|
|
528
|
+
kind?: boolean
|
|
497
529
|
createdAt?: boolean
|
|
498
530
|
revokedAt?: boolean
|
|
499
531
|
agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
|
|
@@ -504,11 +536,12 @@ export type AgentTokenSelectScalar = {
|
|
|
504
536
|
agentId?: boolean
|
|
505
537
|
token?: boolean
|
|
506
538
|
label?: boolean
|
|
539
|
+
kind?: boolean
|
|
507
540
|
createdAt?: boolean
|
|
508
541
|
revokedAt?: boolean
|
|
509
542
|
}
|
|
510
543
|
|
|
511
|
-
export type AgentTokenOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "agentId" | "token" | "label" | "createdAt" | "revokedAt", ExtArgs["result"]["agentToken"]>
|
|
544
|
+
export type AgentTokenOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "agentId" | "token" | "label" | "kind" | "createdAt" | "revokedAt", ExtArgs["result"]["agentToken"]>
|
|
512
545
|
export type AgentTokenInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
|
|
513
546
|
agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
|
|
514
547
|
}
|
|
@@ -529,6 +562,7 @@ export type $AgentTokenPayload<ExtArgs extends runtime.Types.Extensions.Internal
|
|
|
529
562
|
agentId: string
|
|
530
563
|
token: string
|
|
531
564
|
label: string | null
|
|
565
|
+
kind: string
|
|
532
566
|
createdAt: Date
|
|
533
567
|
revokedAt: Date | null
|
|
534
568
|
}, ExtArgs["result"]["agentToken"]>
|
|
@@ -959,6 +993,7 @@ export interface AgentTokenFieldRefs {
|
|
|
959
993
|
readonly agentId: Prisma.FieldRef<"AgentToken", 'String'>
|
|
960
994
|
readonly token: Prisma.FieldRef<"AgentToken", 'String'>
|
|
961
995
|
readonly label: Prisma.FieldRef<"AgentToken", 'String'>
|
|
996
|
+
readonly kind: Prisma.FieldRef<"AgentToken", 'String'>
|
|
962
997
|
readonly createdAt: Prisma.FieldRef<"AgentToken", 'DateTime'>
|
|
963
998
|
readonly revokedAt: Prisma.FieldRef<"AgentToken", 'DateTime'>
|
|
964
999
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
-- AlterTable: every existing row takes the default, so existing tokens are runtime.
|
|
2
|
+
-- TEXT + CHECK rather than a native enum: consumers' additive-migration guards
|
|
3
|
+
-- accept only CREATE TABLE/INDEX and ADD COLUMN, not CREATE TYPE.
|
|
4
|
+
ALTER TABLE "AgentToken" ADD COLUMN "kind" TEXT NOT NULL DEFAULT 'runtime' CONSTRAINT "AgentToken_kind_check" CHECK ("kind" IN ('runtime', 'tools'));
|
|
@@ -234,6 +234,11 @@ model AgentToken {
|
|
|
234
234
|
agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
|
|
235
235
|
token String @unique // SHA-256 hash of the raw token (hex)
|
|
236
236
|
label String?
|
|
237
|
+
// What the token is for: "runtime" (the agent process) or "tools" (the
|
|
238
|
+
// model's own process). Existing rows are "runtime". A TEXT column with a
|
|
239
|
+
// DB CHECK constraint (not a native enum) so the migration stays additive;
|
|
240
|
+
// values are validated in code by AgentTokenService (agent-tokens.ts).
|
|
241
|
+
kind String @default("runtime")
|
|
237
242
|
createdAt DateTime @default(now())
|
|
238
243
|
revokedAt DateTime?
|
|
239
244
|
}
|
package/src/admin-ui-pages.ts
CHANGED
|
@@ -196,6 +196,11 @@ export interface ToolItem {
|
|
|
196
196
|
export interface TokenItem {
|
|
197
197
|
id: string;
|
|
198
198
|
label: string | null;
|
|
199
|
+
/**
|
|
200
|
+
* Stored token kind ("runtime" | "tools"; a TEXT column). Optional so older
|
|
201
|
+
* callers that omit it still compile; shown as runtime.
|
|
202
|
+
*/
|
|
203
|
+
kind?: string;
|
|
199
204
|
createdAt: Date;
|
|
200
205
|
revokedAt: Date | null;
|
|
201
206
|
}
|
|
@@ -1656,11 +1661,12 @@ export function renderAgentDetailPage(
|
|
|
1656
1661
|
|
|
1657
1662
|
const tokenRows =
|
|
1658
1663
|
tokens.length === 0
|
|
1659
|
-
? `<tr><td colspan="
|
|
1664
|
+
? `<tr><td colspan="5" class="empty-state">No tokens created.</td></tr>`
|
|
1660
1665
|
: tokens
|
|
1661
1666
|
.map(
|
|
1662
1667
|
(t) => `<tr>
|
|
1663
1668
|
<td>${t.label ? escapeHtml(t.label) : '<span style="color:var(--vos-text-faint)">—</span>'}</td>
|
|
1669
|
+
<td>${escapeHtml(t.kind ?? "runtime")}</td>
|
|
1664
1670
|
<td>${escapeHtml(new Date(t.createdAt).toLocaleDateString("en-US", { timeZone: timezone }))}</td>
|
|
1665
1671
|
<td>${t.revokedAt ? `<span class="badge badge-gray">Revoked ${escapeHtml(new Date(t.revokedAt).toLocaleDateString("en-US", { timeZone: timezone }))}</span>` : '<span class="badge badge-green">Active</span>'}</td>
|
|
1666
1672
|
<td>${
|
|
@@ -2166,6 +2172,7 @@ export function renderAgentDetailPage(
|
|
|
2166
2172
|
<thead>
|
|
2167
2173
|
<tr>
|
|
2168
2174
|
<th>Label</th>
|
|
2175
|
+
<th>Kind</th>
|
|
2169
2176
|
<th>Created</th>
|
|
2170
2177
|
<th>Status</th>
|
|
2171
2178
|
<th></th>
|
|
@@ -1908,6 +1908,16 @@ describe("renderAgentDetailPage — tokens", () => {
|
|
|
1908
1908
|
expect(html).toContain(">Active<");
|
|
1909
1909
|
});
|
|
1910
1910
|
|
|
1911
|
+
test("token list shows each token's kind (runtime when unset)", () => {
|
|
1912
|
+
const html = render([
|
|
1913
|
+
{ ...TOKEN_ACTIVE, kind: "tools" },
|
|
1914
|
+
{ ...TOKEN_REVOKED, kind: undefined },
|
|
1915
|
+
]);
|
|
1916
|
+
expect(html).toContain("<th>Kind</th>");
|
|
1917
|
+
expect(html).toContain("<td>tools</td>");
|
|
1918
|
+
expect(html).toContain("<td>runtime</td>");
|
|
1919
|
+
});
|
|
1920
|
+
|
|
1911
1921
|
test("active token: Revoke form present", () => {
|
|
1912
1922
|
const html = render([TOKEN_ACTIVE]);
|
|
1913
1923
|
expect(html).toContain(
|
package/src/admin-ui.fixtures.ts
CHANGED
|
@@ -397,6 +397,7 @@ function makeMockDeps(): AdminDeps {
|
|
|
397
397
|
id: "token-id",
|
|
398
398
|
agentId: AGENT_ID,
|
|
399
399
|
token: "sha256hash",
|
|
400
|
+
kind: "runtime" as const,
|
|
400
401
|
label: null,
|
|
401
402
|
createdAt: new Date(),
|
|
402
403
|
revokedAt: null,
|
|
@@ -409,6 +410,7 @@ function makeMockDeps(): AdminDeps {
|
|
|
409
410
|
id: "token-id",
|
|
410
411
|
agentId: AGENT_ID,
|
|
411
412
|
token: "sha256hash",
|
|
413
|
+
kind: "runtime" as const,
|
|
412
414
|
label: null,
|
|
413
415
|
createdAt: new Date(),
|
|
414
416
|
revokedAt: new Date(),
|
|
@@ -778,7 +780,7 @@ describe("admin API — GET /agents/all/cron-runs/stats", () => {
|
|
|
778
780
|
agentTokenService: {
|
|
779
781
|
...makeMockDeps().agentTokenService,
|
|
780
782
|
// Returns a per-agent token (not admin)
|
|
781
|
-
validate: async () => ({ agentId: AGENT_ID }),
|
|
783
|
+
validate: async () => ({ agentId: AGENT_ID, kind: "runtime" as const }),
|
|
782
784
|
},
|
|
783
785
|
};
|
|
784
786
|
const app = createAdminApp(deps);
|
|
@@ -803,7 +805,7 @@ describe("admin API — GET /agents/:id/cron-runs/stats", () => {
|
|
|
803
805
|
},
|
|
804
806
|
agentTokenService: {
|
|
805
807
|
...base.agentTokenService,
|
|
806
|
-
validate: async () => ({ agentId: AGENT_ID }),
|
|
808
|
+
validate: async () => ({ agentId: AGENT_ID, kind: "runtime" as const }),
|
|
807
809
|
},
|
|
808
810
|
};
|
|
809
811
|
}
|
|
@@ -859,7 +861,7 @@ describe("admin API — GET /agents/:id/cron-runs/outcomes", () => {
|
|
|
859
861
|
},
|
|
860
862
|
agentTokenService: {
|
|
861
863
|
...base.agentTokenService,
|
|
862
|
-
validate: async () => ({ agentId: AGENT_ID }),
|
|
864
|
+
validate: async () => ({ agentId: AGENT_ID, kind: "runtime" as const }),
|
|
863
865
|
},
|
|
864
866
|
};
|
|
865
867
|
}
|
|
@@ -962,7 +964,7 @@ describe("admin API — GET /agents/all/cron-runs/outcomes", () => {
|
|
|
962
964
|
...makeMockDeps(),
|
|
963
965
|
agentTokenService: {
|
|
964
966
|
...makeMockDeps().agentTokenService,
|
|
965
|
-
validate: async () => ({ agentId: AGENT_ID }),
|
|
967
|
+
validate: async () => ({ agentId: AGENT_ID, kind: "runtime" as const }),
|
|
966
968
|
},
|
|
967
969
|
};
|
|
968
970
|
const app = createAdminApp(deps);
|
|
@@ -88,6 +88,29 @@ describeOrSkip("AgentTokenService (integration)", () => {
|
|
|
88
88
|
expect(result?.agentId).toBe(agentId);
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
+
it("validate() returns the kind (runtime by default, tools when set)", async () => {
|
|
92
|
+
const agentId = await createAgent(prisma);
|
|
93
|
+
const rt = await service.create(agentId);
|
|
94
|
+
const tools = await service.create(agentId, "t", "tools");
|
|
95
|
+
expect(await service.validate(rt.rawToken)).toEqual({
|
|
96
|
+
agentId,
|
|
97
|
+
kind: "runtime",
|
|
98
|
+
});
|
|
99
|
+
expect(await service.validate(tools.rawToken)).toEqual({
|
|
100
|
+
agentId,
|
|
101
|
+
kind: "tools",
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("rows inserted without a kind column value validate as runtime", async () => {
|
|
106
|
+
const agentId = await createAgent(prisma);
|
|
107
|
+
const raw = "a".repeat(64);
|
|
108
|
+
const hashed = new Bun.CryptoHasher("sha256").update(raw).digest("hex");
|
|
109
|
+
// Raw SQL omitting `kind`, as a pre-migration row would.
|
|
110
|
+
await prisma.$executeRaw`INSERT INTO "AgentToken" ("id", "agentId", "token") VALUES (${"legacy-token-1"}, ${agentId}, ${hashed})`;
|
|
111
|
+
expect(await service.validate(raw)).toEqual({ agentId, kind: "runtime" });
|
|
112
|
+
});
|
|
113
|
+
|
|
91
114
|
it("validate() returns null for unknown token", async () => {
|
|
92
115
|
const result = await service.validate("0".repeat(64));
|
|
93
116
|
expect(result).toBeNull();
|
package/src/agent-tokens.ts
CHANGED
|
@@ -13,8 +13,35 @@ import { UnprocessableEntityError } from "./errors.ts";
|
|
|
13
13
|
|
|
14
14
|
export type { AgentToken };
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* What an agent API token is for: `runtime` (the agent process) or `tools`
|
|
18
|
+
* (the model's own process). Stored as a TEXT column (with a DB CHECK), so the
|
|
19
|
+
* allowed values live here and are validated in code.
|
|
20
|
+
*/
|
|
21
|
+
export const AGENT_TOKEN_KINDS = ["runtime", "tools"] as const;
|
|
22
|
+
export type AgentTokenKind = (typeof AGENT_TOKEN_KINDS)[number];
|
|
23
|
+
|
|
24
|
+
export function isAgentTokenKind(value: unknown): value is AgentTokenKind {
|
|
25
|
+
return (
|
|
26
|
+
typeof value === "string" &&
|
|
27
|
+
(AGENT_TOKEN_KINDS as readonly string[]).includes(value)
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Narrow a stored kind for display/API output. The DB CHECK constraint makes
|
|
33
|
+
* an unknown value unreachable; if one ever appears it is reported as
|
|
34
|
+
* `runtime` (the column default). Auth never uses this: validate() rejects
|
|
35
|
+
* unknown kinds instead.
|
|
36
|
+
*/
|
|
37
|
+
export function agentTokenKindOf(value: string): AgentTokenKind {
|
|
38
|
+
return isAgentTokenKind(value) ? value : "runtime";
|
|
39
|
+
}
|
|
40
|
+
|
|
16
41
|
export interface AgentTokenValidated {
|
|
17
42
|
agentId: string;
|
|
43
|
+
/** Optional so exported-type consumers that stub validate() keep compiling. */
|
|
44
|
+
kind?: AgentTokenKind;
|
|
18
45
|
}
|
|
19
46
|
|
|
20
47
|
function hashToken(raw: string): string {
|
|
@@ -34,12 +61,17 @@ export class AgentTokenService {
|
|
|
34
61
|
/**
|
|
35
62
|
* Create a new token for an agent.
|
|
36
63
|
* Returns the token record plus the raw token — only opportunity to read it.
|
|
37
|
-
* Throws UnprocessableEntityError if agentId doesn't reference an existing
|
|
64
|
+
* Throws UnprocessableEntityError if agentId doesn't reference an existing
|
|
65
|
+
* Agent or kind is not a known AgentTokenKind.
|
|
38
66
|
*/
|
|
39
67
|
async create(
|
|
40
68
|
agentId: string,
|
|
41
69
|
label?: string,
|
|
70
|
+
kind: AgentTokenKind = "runtime",
|
|
42
71
|
): Promise<{ token: AgentToken; rawToken: string }> {
|
|
72
|
+
if (!isAgentTokenKind(kind)) {
|
|
73
|
+
throw new UnprocessableEntityError("kind must be runtime or tools");
|
|
74
|
+
}
|
|
43
75
|
const agent = await this.prisma.agent.findUnique({
|
|
44
76
|
where: { id: agentId },
|
|
45
77
|
});
|
|
@@ -51,15 +83,16 @@ export class AgentTokenService {
|
|
|
51
83
|
const hashed = hashToken(rawToken);
|
|
52
84
|
|
|
53
85
|
const token = await this.prisma.agentToken.create({
|
|
54
|
-
data: { agentId, token: hashed, label },
|
|
86
|
+
data: { agentId, token: hashed, label, kind },
|
|
55
87
|
});
|
|
56
88
|
|
|
57
89
|
return { token, rawToken };
|
|
58
90
|
}
|
|
59
91
|
|
|
60
92
|
/**
|
|
61
|
-
* Validate a raw token. Returns { agentId } if valid and not revoked,
|
|
62
|
-
* or null if the token is unknown or
|
|
93
|
+
* Validate a raw token. Returns { agentId, kind } if valid and not revoked,
|
|
94
|
+
* or null if the token is unknown, revoked, or carries an unrecognized kind
|
|
95
|
+
* (fails closed rather than guessing a capability).
|
|
63
96
|
*/
|
|
64
97
|
async validate(raw: string): Promise<AgentTokenValidated | null> {
|
|
65
98
|
const hashed = hashToken(raw);
|
|
@@ -67,7 +100,8 @@ export class AgentTokenService {
|
|
|
67
100
|
where: { token: hashed },
|
|
68
101
|
});
|
|
69
102
|
if (!record || record.revokedAt !== null) return null;
|
|
70
|
-
|
|
103
|
+
if (!isAgentTokenKind(record.kind)) return null;
|
|
104
|
+
return { agentId: record.agentId, kind: record.kind };
|
|
71
105
|
}
|
|
72
106
|
|
|
73
107
|
/**
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/agent-tokens.unit.test.ts
|
|
3
|
+
* Unit tests for AgentTokenService kind handling (runtime | tools) against a
|
|
4
|
+
* minimal in-memory Prisma stand-in.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, expect, it } from "bun:test";
|
|
8
|
+
import type { PrismaClient } from "../prisma/client/client.ts";
|
|
9
|
+
import {
|
|
10
|
+
type AgentTokenKind,
|
|
11
|
+
AgentTokenService,
|
|
12
|
+
agentTokenKindOf,
|
|
13
|
+
isAgentTokenKind,
|
|
14
|
+
} from "./agent-tokens.ts";
|
|
15
|
+
|
|
16
|
+
interface Row {
|
|
17
|
+
id: string;
|
|
18
|
+
agentId: string;
|
|
19
|
+
token: string;
|
|
20
|
+
label: string | null;
|
|
21
|
+
kind: string;
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
revokedAt: Date | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function makeService() {
|
|
27
|
+
const rows: Row[] = [];
|
|
28
|
+
const prisma = {
|
|
29
|
+
agent: { findUnique: async () => ({ id: "agent-1" }) },
|
|
30
|
+
agentToken: {
|
|
31
|
+
create: async ({
|
|
32
|
+
data,
|
|
33
|
+
}: {
|
|
34
|
+
data: {
|
|
35
|
+
agentId: string;
|
|
36
|
+
token: string;
|
|
37
|
+
label?: string;
|
|
38
|
+
kind?: string;
|
|
39
|
+
};
|
|
40
|
+
}) => {
|
|
41
|
+
const row: Row = {
|
|
42
|
+
id: `t${rows.length + 1}`,
|
|
43
|
+
agentId: data.agentId,
|
|
44
|
+
token: data.token,
|
|
45
|
+
label: data.label ?? null,
|
|
46
|
+
// Mirrors the column default when kind is omitted.
|
|
47
|
+
kind: data.kind ?? "runtime",
|
|
48
|
+
createdAt: new Date(),
|
|
49
|
+
revokedAt: null,
|
|
50
|
+
};
|
|
51
|
+
rows.push(row);
|
|
52
|
+
return row;
|
|
53
|
+
},
|
|
54
|
+
findUnique: async ({ where }: { where: { token: string } }) =>
|
|
55
|
+
rows.find((r) => r.token === where.token) ?? null,
|
|
56
|
+
},
|
|
57
|
+
} as unknown as PrismaClient;
|
|
58
|
+
return { service: new AgentTokenService(prisma), rows };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe("AgentTokenService kind", () => {
|
|
62
|
+
it("create() defaults to the runtime kind", async () => {
|
|
63
|
+
const { service } = makeService();
|
|
64
|
+
const { token } = await service.create("agent-1", "label");
|
|
65
|
+
expect(token.kind).toBe("runtime");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("create() stores an explicit tools kind", async () => {
|
|
69
|
+
const { service } = makeService();
|
|
70
|
+
const { token } = await service.create("agent-1", undefined, "tools");
|
|
71
|
+
expect(token.kind).toBe("tools");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("validate() returns the runtime kind for a default token", async () => {
|
|
75
|
+
const { service } = makeService();
|
|
76
|
+
const { rawToken } = await service.create("agent-1");
|
|
77
|
+
expect(await service.validate(rawToken)).toEqual({
|
|
78
|
+
agentId: "agent-1",
|
|
79
|
+
kind: "runtime",
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("validate() returns the tools kind for a tools token", async () => {
|
|
84
|
+
const { service } = makeService();
|
|
85
|
+
const { rawToken } = await service.create("agent-1", "t", "tools");
|
|
86
|
+
expect(await service.validate(rawToken)).toEqual({
|
|
87
|
+
agentId: "agent-1",
|
|
88
|
+
kind: "tools",
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("validate() returns null for an unknown token", async () => {
|
|
93
|
+
const { service } = makeService();
|
|
94
|
+
expect(await service.validate("nope")).toBeNull();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("create() rejects an unknown kind before writing a row", async () => {
|
|
98
|
+
const { service, rows } = makeService();
|
|
99
|
+
await expect(
|
|
100
|
+
service.create("agent-1", "x", "admin" as AgentTokenKind),
|
|
101
|
+
).rejects.toThrow("kind must be runtime or tools");
|
|
102
|
+
expect(rows).toHaveLength(0);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("validate() fails closed on a stored kind it does not recognize", async () => {
|
|
106
|
+
const { service, rows } = makeService();
|
|
107
|
+
const { rawToken } = await service.create("agent-1");
|
|
108
|
+
(rows[0] as Row).kind = "admin";
|
|
109
|
+
expect(await service.validate(rawToken)).toBeNull();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("AgentTokenKind helpers", () => {
|
|
114
|
+
it("isAgentTokenKind() accepts only runtime and tools", () => {
|
|
115
|
+
expect(isAgentTokenKind("runtime")).toBe(true);
|
|
116
|
+
expect(isAgentTokenKind("tools")).toBe(true);
|
|
117
|
+
expect(isAgentTokenKind("admin")).toBe(false);
|
|
118
|
+
expect(isAgentTokenKind("")).toBe(false);
|
|
119
|
+
expect(isAgentTokenKind(undefined)).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("agentTokenKindOf() keeps known kinds and reports unknown as runtime", () => {
|
|
123
|
+
expect(agentTokenKindOf("tools")).toBe("tools");
|
|
124
|
+
expect(agentTokenKindOf("runtime")).toBe("runtime");
|
|
125
|
+
expect(agentTokenKindOf("bogus")).toBe("runtime");
|
|
126
|
+
});
|
|
127
|
+
});
|