@app-vitals/agent-admin 1.115.2 → 1.117.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-boot.ts +21 -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/admin-ui.ts +5 -0
- package/src/agent-cron-run-stats.smoke.test.ts +6 -4
- package/src/agent-envs.ts +16 -0
- package/src/agent-template-items.ts +1 -0
- 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/agent-tools-token.integration.test.ts +127 -0
- package/src/agent-tools-token.ts +80 -0
- package/src/agent-tools-token.unit.test.ts +95 -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 +24 -2
- package/src/agents.ts +18 -0
- 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-boot.ts
CHANGED
|
@@ -87,6 +87,7 @@ import { AgentPluginService } from "./agent-plugins.ts";
|
|
|
87
87
|
import { AgentTemplateReconcileService } from "./agent-template-reconcile.ts";
|
|
88
88
|
import { AgentTemplateService } from "./agent-templates.ts";
|
|
89
89
|
import { AgentTokenService } from "./agent-tokens.ts";
|
|
90
|
+
import { AgentToolsTokenService } from "./agent-tools-token.ts";
|
|
90
91
|
import { AgentToolService } from "./agent-tools.ts";
|
|
91
92
|
import { AgentService } from "./agents.ts";
|
|
92
93
|
import { parseAdminApiKeys } from "./agents-api.ts";
|
|
@@ -240,6 +241,10 @@ export async function startAdmin(
|
|
|
240
241
|
const agentCronRunService = new AgentCronRunService(prisma);
|
|
241
242
|
const agentToolService = new AgentToolService(prisma);
|
|
242
243
|
const agentTokenService = new AgentTokenService(prisma);
|
|
244
|
+
const toolsTokenService = new AgentToolsTokenService(
|
|
245
|
+
agentTokenService,
|
|
246
|
+
agentEnvService,
|
|
247
|
+
);
|
|
243
248
|
const agentPluginService = new AgentPluginService(prisma);
|
|
244
249
|
const agentMarketplaceService = new AgentMarketplaceService(prisma);
|
|
245
250
|
const agentMemberService = new AgentMemberService(prisma);
|
|
@@ -581,6 +586,7 @@ export async function startAdmin(
|
|
|
581
586
|
decrypt: crypto.decrypt,
|
|
582
587
|
slackConfigTokens,
|
|
583
588
|
agentTemplateReconcileService: templateReconcileService,
|
|
589
|
+
toolsTokenService,
|
|
584
590
|
sessionSecret,
|
|
585
591
|
adminApiKeys,
|
|
586
592
|
sentryClient: process.env.SENTRY_DSN ? Sentry : undefined,
|
|
@@ -699,6 +705,7 @@ export async function startAdmin(
|
|
|
699
705
|
encryptionConfigured: () => makeStrictTokenCrypto() !== null,
|
|
700
706
|
},
|
|
701
707
|
templateReconcile: templateReconcileService,
|
|
708
|
+
toolsTokenService,
|
|
702
709
|
serviceIntegrations,
|
|
703
710
|
chatService: deletionChatService,
|
|
704
711
|
slack: slackClient,
|
|
@@ -916,6 +923,20 @@ export async function startAdmin(
|
|
|
916
923
|
logger: console,
|
|
917
924
|
});
|
|
918
925
|
|
|
926
|
+
// Tools-token backfill: every non-self-hosted agent gets a tools-kind token
|
|
927
|
+
// and env row. Fire-and-forget; per-agent failures are logged, never thrown.
|
|
928
|
+
void agentService
|
|
929
|
+
.list()
|
|
930
|
+
.then((agents) =>
|
|
931
|
+
toolsTokenService.ensureAll(agents.filter((a) => !a.selfHosted)),
|
|
932
|
+
)
|
|
933
|
+
.catch((err) =>
|
|
934
|
+
console.error(
|
|
935
|
+
"[admin] tools token backfill failed:",
|
|
936
|
+
err instanceof Error ? err.message : String(err),
|
|
937
|
+
),
|
|
938
|
+
);
|
|
939
|
+
|
|
919
940
|
// Policy-only reconcile (ACP-1.3): a Claude policy change restarts admin via
|
|
920
941
|
// the chart's policy-hash env var, so rolling only the agents whose policy
|
|
921
942
|
// wiring drifted happens here. Runs even with no policy configured so agents
|
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
package/src/admin-ui.ts
CHANGED
|
@@ -128,6 +128,7 @@ import type { AgentTemplateReconcileService } from "./agent-template-reconcile.t
|
|
|
128
128
|
import type { AgentTemplateService } from "./agent-templates.ts";
|
|
129
129
|
import type { AgentTokenService } from "./agent-tokens.ts";
|
|
130
130
|
import type { AgentToolService } from "./agent-tools.ts";
|
|
131
|
+
import type { ToolsTokenEnsurer } from "./agent-tools-token.ts";
|
|
131
132
|
import type { AgentService } from "./agents.ts";
|
|
132
133
|
import {
|
|
133
134
|
ACCOUNT_REQUIRED_MESSAGE,
|
|
@@ -461,6 +462,8 @@ export interface AdminUIDeps {
|
|
|
461
462
|
specialtyDefaults?: SpecialtyDefaultsResolver;
|
|
462
463
|
/** ATP-2.2: seeds the resolved agent template inside the create transaction. */
|
|
463
464
|
templateReconcile?: Pick<AgentTemplateReconcileService, "reconcile">;
|
|
465
|
+
/** Mints the tools-kind token for a newly created agent. */
|
|
466
|
+
toolsTokenService?: ToolsTokenEnsurer;
|
|
464
467
|
/**
|
|
465
468
|
* Cleanup deps for the full delete-agent orchestration (POST
|
|
466
469
|
* /admin/agents/:id/delete → deleteAgentFully()). Matches
|
|
@@ -1022,6 +1025,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1022
1025
|
templateService,
|
|
1023
1026
|
slackConfigToken,
|
|
1024
1027
|
templateReconcile,
|
|
1028
|
+
toolsTokenService,
|
|
1025
1029
|
agentsApi,
|
|
1026
1030
|
specialtyRegistry = new SpecialtyTypes(),
|
|
1027
1031
|
specialtyDefaults,
|
|
@@ -1995,6 +1999,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1995
1999
|
specialtyDefaults,
|
|
1996
2000
|
anthropicFederationEnabled: deps.anthropicFederationEnabled,
|
|
1997
2001
|
...(templateReconcile ? { templateReconcile } : {}),
|
|
2002
|
+
...(toolsTokenService ? { toolsTokenService } : {}),
|
|
1998
2003
|
},
|
|
1999
2004
|
{
|
|
2000
2005
|
name,
|
|
@@ -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);
|
package/src/agent-envs.ts
CHANGED
|
@@ -239,6 +239,22 @@ export class AgentEnvService {
|
|
|
239
239
|
return { env, secretKeys, sources };
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Decrypted value of one enabled env key, or null when the key is absent,
|
|
244
|
+
* disabled, or cannot be decrypted. Never logs the value.
|
|
245
|
+
*/
|
|
246
|
+
async getValue(agentId: string, key: string): Promise<string | null> {
|
|
247
|
+
const row = await this.prisma.agentEnv.findUnique({
|
|
248
|
+
where: { agentId_key: { agentId, key } },
|
|
249
|
+
});
|
|
250
|
+
if (!row?.enabled) return null;
|
|
251
|
+
try {
|
|
252
|
+
return this.crypto.decrypt(row.value);
|
|
253
|
+
} catch {
|
|
254
|
+
return null;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
242
258
|
/**
|
|
243
259
|
* Returns the full env bundle for an agent — stored env vars (decrypted) plus
|
|
244
260
|
* allowed tools. Always decrypts regardless of the secret flag.
|
|
@@ -87,6 +87,7 @@ export const TEMPLATE_ENV_DENYLIST: ReadonlySet<string> = new Set([
|
|
|
87
87
|
"SLACK_SIGNING_SECRET",
|
|
88
88
|
"GH_TOKEN",
|
|
89
89
|
"SHIPWRIGHT_AGENT_API_KEY",
|
|
90
|
+
"SHIPWRIGHT_AGENT_TOOLS_API_KEY",
|
|
90
91
|
"SHIPWRIGHT_TASK_STORE_URL",
|
|
91
92
|
"SHIPWRIGHT_TASK_STORE_TOKEN",
|
|
92
93
|
...ANTHROPIC_CREDENTIAL_KEYS,
|
|
@@ -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
|
/**
|