@app-vitals/agent-admin 1.41.0 → 1.42.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/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/AgentEnv.ts +36 -1
- package/prisma/migrations/20261114000000_add_agent_env_enabled/migration.sql +3 -0
- package/prisma/schema/schema.prisma +1 -0
- package/src/agent-cron-jobs.integration.test.ts +77 -0
- package/src/agent-cron-jobs.ts +66 -10
- package/src/agent-deletion.ts +2 -2
- package/src/agent-envs.integration.test.ts +108 -0
- package/src/agent-envs.ts +95 -19
- package/src/agent-plugins.integration.test.ts +52 -0
- package/src/agent-plugins.ts +51 -4
- package/src/agent-tools.integration.test.ts +55 -0
- package/src/agent-tools.ts +35 -4
- package/src/agents-api.smoke.test.ts +1 -0
- package/src/agents.ts +1 -1
|
@@ -30,6 +30,7 @@ export type AgentEnvMinAggregateOutputType = {
|
|
|
30
30
|
key: string | null
|
|
31
31
|
value: string | null
|
|
32
32
|
secret: boolean | null
|
|
33
|
+
enabled: boolean | null
|
|
33
34
|
source: string | null
|
|
34
35
|
createdAt: Date | null
|
|
35
36
|
updatedAt: Date | null
|
|
@@ -41,6 +42,7 @@ export type AgentEnvMaxAggregateOutputType = {
|
|
|
41
42
|
key: string | null
|
|
42
43
|
value: string | null
|
|
43
44
|
secret: boolean | null
|
|
45
|
+
enabled: boolean | null
|
|
44
46
|
source: string | null
|
|
45
47
|
createdAt: Date | null
|
|
46
48
|
updatedAt: Date | null
|
|
@@ -52,6 +54,7 @@ export type AgentEnvCountAggregateOutputType = {
|
|
|
52
54
|
key: number
|
|
53
55
|
value: number
|
|
54
56
|
secret: number
|
|
57
|
+
enabled: number
|
|
55
58
|
source: number
|
|
56
59
|
createdAt: number
|
|
57
60
|
updatedAt: number
|
|
@@ -65,6 +68,7 @@ export type AgentEnvMinAggregateInputType = {
|
|
|
65
68
|
key?: true
|
|
66
69
|
value?: true
|
|
67
70
|
secret?: true
|
|
71
|
+
enabled?: true
|
|
68
72
|
source?: true
|
|
69
73
|
createdAt?: true
|
|
70
74
|
updatedAt?: true
|
|
@@ -76,6 +80,7 @@ export type AgentEnvMaxAggregateInputType = {
|
|
|
76
80
|
key?: true
|
|
77
81
|
value?: true
|
|
78
82
|
secret?: true
|
|
83
|
+
enabled?: true
|
|
79
84
|
source?: true
|
|
80
85
|
createdAt?: true
|
|
81
86
|
updatedAt?: true
|
|
@@ -87,6 +92,7 @@ export type AgentEnvCountAggregateInputType = {
|
|
|
87
92
|
key?: true
|
|
88
93
|
value?: true
|
|
89
94
|
secret?: true
|
|
95
|
+
enabled?: true
|
|
90
96
|
source?: true
|
|
91
97
|
createdAt?: true
|
|
92
98
|
updatedAt?: true
|
|
@@ -171,6 +177,7 @@ export type AgentEnvGroupByOutputType = {
|
|
|
171
177
|
key: string
|
|
172
178
|
value: string
|
|
173
179
|
secret: boolean
|
|
180
|
+
enabled: boolean
|
|
174
181
|
source: string
|
|
175
182
|
createdAt: Date
|
|
176
183
|
updatedAt: Date
|
|
@@ -203,6 +210,7 @@ export type AgentEnvWhereInput = {
|
|
|
203
210
|
key?: Prisma.StringFilter<"AgentEnv"> | string
|
|
204
211
|
value?: Prisma.StringFilter<"AgentEnv"> | string
|
|
205
212
|
secret?: Prisma.BoolFilter<"AgentEnv"> | boolean
|
|
213
|
+
enabled?: Prisma.BoolFilter<"AgentEnv"> | boolean
|
|
206
214
|
source?: Prisma.StringFilter<"AgentEnv"> | string
|
|
207
215
|
createdAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
|
|
208
216
|
updatedAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
|
|
@@ -215,6 +223,7 @@ export type AgentEnvOrderByWithRelationInput = {
|
|
|
215
223
|
key?: Prisma.SortOrder
|
|
216
224
|
value?: Prisma.SortOrder
|
|
217
225
|
secret?: Prisma.SortOrder
|
|
226
|
+
enabled?: Prisma.SortOrder
|
|
218
227
|
source?: Prisma.SortOrder
|
|
219
228
|
createdAt?: Prisma.SortOrder
|
|
220
229
|
updatedAt?: Prisma.SortOrder
|
|
@@ -231,6 +240,7 @@ export type AgentEnvWhereUniqueInput = Prisma.AtLeast<{
|
|
|
231
240
|
key?: Prisma.StringFilter<"AgentEnv"> | string
|
|
232
241
|
value?: Prisma.StringFilter<"AgentEnv"> | string
|
|
233
242
|
secret?: Prisma.BoolFilter<"AgentEnv"> | boolean
|
|
243
|
+
enabled?: Prisma.BoolFilter<"AgentEnv"> | boolean
|
|
234
244
|
source?: Prisma.StringFilter<"AgentEnv"> | string
|
|
235
245
|
createdAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
|
|
236
246
|
updatedAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
|
|
@@ -243,6 +253,7 @@ export type AgentEnvOrderByWithAggregationInput = {
|
|
|
243
253
|
key?: Prisma.SortOrder
|
|
244
254
|
value?: Prisma.SortOrder
|
|
245
255
|
secret?: Prisma.SortOrder
|
|
256
|
+
enabled?: Prisma.SortOrder
|
|
246
257
|
source?: Prisma.SortOrder
|
|
247
258
|
createdAt?: Prisma.SortOrder
|
|
248
259
|
updatedAt?: Prisma.SortOrder
|
|
@@ -260,6 +271,7 @@ export type AgentEnvScalarWhereWithAggregatesInput = {
|
|
|
260
271
|
key?: Prisma.StringWithAggregatesFilter<"AgentEnv"> | string
|
|
261
272
|
value?: Prisma.StringWithAggregatesFilter<"AgentEnv"> | string
|
|
262
273
|
secret?: Prisma.BoolWithAggregatesFilter<"AgentEnv"> | boolean
|
|
274
|
+
enabled?: Prisma.BoolWithAggregatesFilter<"AgentEnv"> | boolean
|
|
263
275
|
source?: Prisma.StringWithAggregatesFilter<"AgentEnv"> | string
|
|
264
276
|
createdAt?: Prisma.DateTimeWithAggregatesFilter<"AgentEnv"> | Date | string
|
|
265
277
|
updatedAt?: Prisma.DateTimeWithAggregatesFilter<"AgentEnv"> | Date | string
|
|
@@ -270,6 +282,7 @@ export type AgentEnvCreateInput = {
|
|
|
270
282
|
key: string
|
|
271
283
|
value: string
|
|
272
284
|
secret?: boolean
|
|
285
|
+
enabled?: boolean
|
|
273
286
|
source?: string
|
|
274
287
|
createdAt?: Date | string
|
|
275
288
|
updatedAt?: Date | string
|
|
@@ -282,6 +295,7 @@ export type AgentEnvUncheckedCreateInput = {
|
|
|
282
295
|
key: string
|
|
283
296
|
value: string
|
|
284
297
|
secret?: boolean
|
|
298
|
+
enabled?: boolean
|
|
285
299
|
source?: string
|
|
286
300
|
createdAt?: Date | string
|
|
287
301
|
updatedAt?: Date | string
|
|
@@ -292,6 +306,7 @@ export type AgentEnvUpdateInput = {
|
|
|
292
306
|
key?: Prisma.StringFieldUpdateOperationsInput | string
|
|
293
307
|
value?: Prisma.StringFieldUpdateOperationsInput | string
|
|
294
308
|
secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
309
|
+
enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
295
310
|
source?: Prisma.StringFieldUpdateOperationsInput | string
|
|
296
311
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
297
312
|
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
@@ -304,6 +319,7 @@ export type AgentEnvUncheckedUpdateInput = {
|
|
|
304
319
|
key?: Prisma.StringFieldUpdateOperationsInput | string
|
|
305
320
|
value?: Prisma.StringFieldUpdateOperationsInput | string
|
|
306
321
|
secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
322
|
+
enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
307
323
|
source?: Prisma.StringFieldUpdateOperationsInput | string
|
|
308
324
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
309
325
|
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
@@ -315,6 +331,7 @@ export type AgentEnvCreateManyInput = {
|
|
|
315
331
|
key: string
|
|
316
332
|
value: string
|
|
317
333
|
secret?: boolean
|
|
334
|
+
enabled?: boolean
|
|
318
335
|
source?: string
|
|
319
336
|
createdAt?: Date | string
|
|
320
337
|
updatedAt?: Date | string
|
|
@@ -325,6 +342,7 @@ export type AgentEnvUpdateManyMutationInput = {
|
|
|
325
342
|
key?: Prisma.StringFieldUpdateOperationsInput | string
|
|
326
343
|
value?: Prisma.StringFieldUpdateOperationsInput | string
|
|
327
344
|
secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
345
|
+
enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
328
346
|
source?: Prisma.StringFieldUpdateOperationsInput | string
|
|
329
347
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
330
348
|
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
@@ -336,6 +354,7 @@ export type AgentEnvUncheckedUpdateManyInput = {
|
|
|
336
354
|
key?: Prisma.StringFieldUpdateOperationsInput | string
|
|
337
355
|
value?: Prisma.StringFieldUpdateOperationsInput | string
|
|
338
356
|
secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
357
|
+
enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
339
358
|
source?: Prisma.StringFieldUpdateOperationsInput | string
|
|
340
359
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
341
360
|
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
@@ -362,6 +381,7 @@ export type AgentEnvCountOrderByAggregateInput = {
|
|
|
362
381
|
key?: Prisma.SortOrder
|
|
363
382
|
value?: Prisma.SortOrder
|
|
364
383
|
secret?: Prisma.SortOrder
|
|
384
|
+
enabled?: Prisma.SortOrder
|
|
365
385
|
source?: Prisma.SortOrder
|
|
366
386
|
createdAt?: Prisma.SortOrder
|
|
367
387
|
updatedAt?: Prisma.SortOrder
|
|
@@ -373,6 +393,7 @@ export type AgentEnvMaxOrderByAggregateInput = {
|
|
|
373
393
|
key?: Prisma.SortOrder
|
|
374
394
|
value?: Prisma.SortOrder
|
|
375
395
|
secret?: Prisma.SortOrder
|
|
396
|
+
enabled?: Prisma.SortOrder
|
|
376
397
|
source?: Prisma.SortOrder
|
|
377
398
|
createdAt?: Prisma.SortOrder
|
|
378
399
|
updatedAt?: Prisma.SortOrder
|
|
@@ -384,6 +405,7 @@ export type AgentEnvMinOrderByAggregateInput = {
|
|
|
384
405
|
key?: Prisma.SortOrder
|
|
385
406
|
value?: Prisma.SortOrder
|
|
386
407
|
secret?: Prisma.SortOrder
|
|
408
|
+
enabled?: Prisma.SortOrder
|
|
387
409
|
source?: Prisma.SortOrder
|
|
388
410
|
createdAt?: Prisma.SortOrder
|
|
389
411
|
updatedAt?: Prisma.SortOrder
|
|
@@ -436,6 +458,7 @@ export type AgentEnvCreateWithoutAgentInput = {
|
|
|
436
458
|
key: string
|
|
437
459
|
value: string
|
|
438
460
|
secret?: boolean
|
|
461
|
+
enabled?: boolean
|
|
439
462
|
source?: string
|
|
440
463
|
createdAt?: Date | string
|
|
441
464
|
updatedAt?: Date | string
|
|
@@ -446,6 +469,7 @@ export type AgentEnvUncheckedCreateWithoutAgentInput = {
|
|
|
446
469
|
key: string
|
|
447
470
|
value: string
|
|
448
471
|
secret?: boolean
|
|
472
|
+
enabled?: boolean
|
|
449
473
|
source?: string
|
|
450
474
|
createdAt?: Date | string
|
|
451
475
|
updatedAt?: Date | string
|
|
@@ -486,6 +510,7 @@ export type AgentEnvScalarWhereInput = {
|
|
|
486
510
|
key?: Prisma.StringFilter<"AgentEnv"> | string
|
|
487
511
|
value?: Prisma.StringFilter<"AgentEnv"> | string
|
|
488
512
|
secret?: Prisma.BoolFilter<"AgentEnv"> | boolean
|
|
513
|
+
enabled?: Prisma.BoolFilter<"AgentEnv"> | boolean
|
|
489
514
|
source?: Prisma.StringFilter<"AgentEnv"> | string
|
|
490
515
|
createdAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
|
|
491
516
|
updatedAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
|
|
@@ -496,6 +521,7 @@ export type AgentEnvCreateManyAgentInput = {
|
|
|
496
521
|
key: string
|
|
497
522
|
value: string
|
|
498
523
|
secret?: boolean
|
|
524
|
+
enabled?: boolean
|
|
499
525
|
source?: string
|
|
500
526
|
createdAt?: Date | string
|
|
501
527
|
updatedAt?: Date | string
|
|
@@ -506,6 +532,7 @@ export type AgentEnvUpdateWithoutAgentInput = {
|
|
|
506
532
|
key?: Prisma.StringFieldUpdateOperationsInput | string
|
|
507
533
|
value?: Prisma.StringFieldUpdateOperationsInput | string
|
|
508
534
|
secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
535
|
+
enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
509
536
|
source?: Prisma.StringFieldUpdateOperationsInput | string
|
|
510
537
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
511
538
|
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
@@ -516,6 +543,7 @@ export type AgentEnvUncheckedUpdateWithoutAgentInput = {
|
|
|
516
543
|
key?: Prisma.StringFieldUpdateOperationsInput | string
|
|
517
544
|
value?: Prisma.StringFieldUpdateOperationsInput | string
|
|
518
545
|
secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
546
|
+
enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
519
547
|
source?: Prisma.StringFieldUpdateOperationsInput | string
|
|
520
548
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
521
549
|
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
@@ -526,6 +554,7 @@ export type AgentEnvUncheckedUpdateManyWithoutAgentInput = {
|
|
|
526
554
|
key?: Prisma.StringFieldUpdateOperationsInput | string
|
|
527
555
|
value?: Prisma.StringFieldUpdateOperationsInput | string
|
|
528
556
|
secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
557
|
+
enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
|
|
529
558
|
source?: Prisma.StringFieldUpdateOperationsInput | string
|
|
530
559
|
createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
531
560
|
updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
|
|
@@ -539,6 +568,7 @@ export type AgentEnvSelect<ExtArgs extends runtime.Types.Extensions.InternalArgs
|
|
|
539
568
|
key?: boolean
|
|
540
569
|
value?: boolean
|
|
541
570
|
secret?: boolean
|
|
571
|
+
enabled?: boolean
|
|
542
572
|
source?: boolean
|
|
543
573
|
createdAt?: boolean
|
|
544
574
|
updatedAt?: boolean
|
|
@@ -551,6 +581,7 @@ export type AgentEnvSelectCreateManyAndReturn<ExtArgs extends runtime.Types.Exte
|
|
|
551
581
|
key?: boolean
|
|
552
582
|
value?: boolean
|
|
553
583
|
secret?: boolean
|
|
584
|
+
enabled?: boolean
|
|
554
585
|
source?: boolean
|
|
555
586
|
createdAt?: boolean
|
|
556
587
|
updatedAt?: boolean
|
|
@@ -563,6 +594,7 @@ export type AgentEnvSelectUpdateManyAndReturn<ExtArgs extends runtime.Types.Exte
|
|
|
563
594
|
key?: boolean
|
|
564
595
|
value?: boolean
|
|
565
596
|
secret?: boolean
|
|
597
|
+
enabled?: boolean
|
|
566
598
|
source?: boolean
|
|
567
599
|
createdAt?: boolean
|
|
568
600
|
updatedAt?: boolean
|
|
@@ -575,12 +607,13 @@ export type AgentEnvSelectScalar = {
|
|
|
575
607
|
key?: boolean
|
|
576
608
|
value?: boolean
|
|
577
609
|
secret?: boolean
|
|
610
|
+
enabled?: boolean
|
|
578
611
|
source?: boolean
|
|
579
612
|
createdAt?: boolean
|
|
580
613
|
updatedAt?: boolean
|
|
581
614
|
}
|
|
582
615
|
|
|
583
|
-
export type AgentEnvOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "agentId" | "key" | "value" | "secret" | "source" | "createdAt" | "updatedAt", ExtArgs["result"]["agentEnv"]>
|
|
616
|
+
export type AgentEnvOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "agentId" | "key" | "value" | "secret" | "enabled" | "source" | "createdAt" | "updatedAt", ExtArgs["result"]["agentEnv"]>
|
|
584
617
|
export type AgentEnvInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
|
|
585
618
|
agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
|
|
586
619
|
}
|
|
@@ -602,6 +635,7 @@ export type $AgentEnvPayload<ExtArgs extends runtime.Types.Extensions.InternalAr
|
|
|
602
635
|
key: string
|
|
603
636
|
value: string
|
|
604
637
|
secret: boolean
|
|
638
|
+
enabled: boolean
|
|
605
639
|
source: string
|
|
606
640
|
createdAt: Date
|
|
607
641
|
updatedAt: Date
|
|
@@ -1034,6 +1068,7 @@ export interface AgentEnvFieldRefs {
|
|
|
1034
1068
|
readonly key: Prisma.FieldRef<"AgentEnv", 'String'>
|
|
1035
1069
|
readonly value: Prisma.FieldRef<"AgentEnv", 'String'>
|
|
1036
1070
|
readonly secret: Prisma.FieldRef<"AgentEnv", 'Boolean'>
|
|
1071
|
+
readonly enabled: Prisma.FieldRef<"AgentEnv", 'Boolean'>
|
|
1037
1072
|
readonly source: Prisma.FieldRef<"AgentEnv", 'String'>
|
|
1038
1073
|
readonly createdAt: Prisma.FieldRef<"AgentEnv", 'DateTime'>
|
|
1039
1074
|
readonly updatedAt: Prisma.FieldRef<"AgentEnv", 'DateTime'>
|
|
@@ -121,6 +121,7 @@ model AgentEnv {
|
|
|
121
121
|
key String // env var name
|
|
122
122
|
value String // AES-256-GCM encrypted
|
|
123
123
|
secret Boolean @default(false) // when true, GET /agents/:id/envs masks the value as ***
|
|
124
|
+
enabled Boolean @default(true) // ATP-1.2: false = tombstone of a deleted template row; hidden from every read
|
|
124
125
|
source String @default("custom") // ATP-1.1: 'template' | 'custom'; which rows a template sync owns
|
|
125
126
|
createdAt DateTime @default(now())
|
|
126
127
|
updatedAt DateTime @updatedAt
|
|
@@ -676,4 +676,81 @@ describeOrSkip("AgentCronJobService specialtyDefaults (integration)", () => {
|
|
|
676
676
|
expect(loopAfter?.enabled).toBe(false);
|
|
677
677
|
expect(after.some((j) => j.name === "stale-system")).toBe(false);
|
|
678
678
|
});
|
|
679
|
+
|
|
680
|
+
// ─── ATP-1.2: source / tombstones ──────────────────────────────────────────
|
|
681
|
+
|
|
682
|
+
const BASE = { schedule: "0 9 * * *", prompt: "hi", channel: "C1" };
|
|
683
|
+
|
|
684
|
+
it("create() stamps source=custom; createFromTemplate() stamps template", async () => {
|
|
685
|
+
const agentId = await createAgent(prisma);
|
|
686
|
+
expect((await service.create(agentId, BASE)).source).toBe("custom");
|
|
687
|
+
const t = await service.createFromTemplate(agentId, {
|
|
688
|
+
...BASE,
|
|
689
|
+
name: "tpl",
|
|
690
|
+
});
|
|
691
|
+
expect(t.source).toBe("template");
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
it("update(), updatePreCheck(), updateDelivery() and setEnabled() turn a template row custom", async () => {
|
|
695
|
+
const agentId = await createAgent(prisma);
|
|
696
|
+
const mk = () =>
|
|
697
|
+
service.createFromTemplate(agentId, {
|
|
698
|
+
...BASE,
|
|
699
|
+
name: `t${Math.random()}`,
|
|
700
|
+
});
|
|
701
|
+
const a = await mk();
|
|
702
|
+
expect((await service.update(agentId, a.id, BASE)).source).toBe("custom");
|
|
703
|
+
const b = await mk();
|
|
704
|
+
expect((await service.updatePreCheck(agentId, b.id, "x.ts")).source).toBe(
|
|
705
|
+
"custom",
|
|
706
|
+
);
|
|
707
|
+
const c = await mk();
|
|
708
|
+
expect(
|
|
709
|
+
(await service.updateDelivery(agentId, c.id, { channel: "C2" })).source,
|
|
710
|
+
).toBe("custom");
|
|
711
|
+
const d = await mk();
|
|
712
|
+
expect((await service.setEnabled(agentId, d.id, false)).source).toBe(
|
|
713
|
+
"custom",
|
|
714
|
+
);
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
it("a trial lockdown disable does not flip source", async () => {
|
|
718
|
+
const agentId = await createAgent(prisma);
|
|
719
|
+
const a = await service.createFromTemplate(agentId, BASE);
|
|
720
|
+
const off = await service.setEnabled(agentId, a.id, false, {
|
|
721
|
+
lockdown: true,
|
|
722
|
+
});
|
|
723
|
+
expect(off.source).toBe("template");
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
it("updateFromTemplate() edits a row without flipping source", async () => {
|
|
727
|
+
const agentId = await createAgent(prisma);
|
|
728
|
+
const a = await service.createFromTemplate(agentId, BASE);
|
|
729
|
+
const up = await service.updateFromTemplate(agentId, a.id, {
|
|
730
|
+
...BASE,
|
|
731
|
+
prompt: "new",
|
|
732
|
+
});
|
|
733
|
+
expect(up.prompt).toBe("new");
|
|
734
|
+
expect(up.source).toBe("template");
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
it("delete() of a template row leaves a disabled custom tombstone", async () => {
|
|
738
|
+
const agentId = await createAgent(prisma);
|
|
739
|
+
const a = await service.createFromTemplate(agentId, BASE);
|
|
740
|
+
await service.delete(agentId, a.id);
|
|
741
|
+
const rows = await prisma.agentCronJob.findMany({ where: { agentId } });
|
|
742
|
+
expect(rows).toHaveLength(1);
|
|
743
|
+
expect(rows[0]?.enabled).toBe(false);
|
|
744
|
+
expect(rows[0]?.source).toBe("custom");
|
|
745
|
+
expect(await service.listEnabled()).toEqual([]);
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
it("delete() of a custom row removes it", async () => {
|
|
749
|
+
const agentId = await createAgent(prisma);
|
|
750
|
+
const a = await service.create(agentId, BASE);
|
|
751
|
+
await service.delete(agentId, a.id);
|
|
752
|
+
expect(await prisma.agentCronJob.findMany({ where: { agentId } })).toEqual(
|
|
753
|
+
[],
|
|
754
|
+
);
|
|
755
|
+
});
|
|
679
756
|
});
|
package/src/agent-cron-jobs.ts
CHANGED
|
@@ -51,6 +51,16 @@ export interface CreateAgentCronJobInput {
|
|
|
51
51
|
* Each field may contain digits, *, /, -, and comma (e.g. a minute field of
|
|
52
52
|
* "0,30" for a twice-hourly, staggered schedule is valid).
|
|
53
53
|
*/
|
|
54
|
+
export interface UpdateAgentCronJobInput {
|
|
55
|
+
schedule: string;
|
|
56
|
+
prompt: string;
|
|
57
|
+
channel?: string | null;
|
|
58
|
+
user?: string | null;
|
|
59
|
+
silent?: boolean;
|
|
60
|
+
preCheck?: string | null;
|
|
61
|
+
enabled?: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
54
64
|
export function isValidCron(schedule: string): boolean {
|
|
55
65
|
const fields = schedule.trim().split(/\s+/);
|
|
56
66
|
if (fields.length !== 5) return false;
|
|
@@ -248,6 +258,25 @@ export class AgentCronJobService {
|
|
|
248
258
|
async create(
|
|
249
259
|
agentId: string,
|
|
250
260
|
input: CreateAgentCronJobInput,
|
|
261
|
+
): Promise<AgentCronJob> {
|
|
262
|
+
return this.createWithSource(agentId, input, "custom");
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Internal reconcile write path (ATP-1.2); never exposed over HTTP.
|
|
267
|
+
* Same validation as create() but stamps source="template".
|
|
268
|
+
*/
|
|
269
|
+
async createFromTemplate(
|
|
270
|
+
agentId: string,
|
|
271
|
+
input: CreateAgentCronJobInput,
|
|
272
|
+
): Promise<AgentCronJob> {
|
|
273
|
+
return this.createWithSource(agentId, input, "template");
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
private async createWithSource(
|
|
277
|
+
agentId: string,
|
|
278
|
+
input: CreateAgentCronJobInput,
|
|
279
|
+
source: "template" | "custom",
|
|
251
280
|
): Promise<AgentCronJob> {
|
|
252
281
|
if (!isValidCron(input.schedule)) {
|
|
253
282
|
throw new UnprocessableEntityError(
|
|
@@ -273,6 +302,7 @@ export class AgentCronJobService {
|
|
|
273
302
|
preCheck: input.preCheck ?? null,
|
|
274
303
|
name: input.name ?? null,
|
|
275
304
|
system: input.system ?? false,
|
|
305
|
+
source,
|
|
276
306
|
},
|
|
277
307
|
});
|
|
278
308
|
}
|
|
@@ -290,6 +320,15 @@ export class AgentCronJobService {
|
|
|
290
320
|
throw new NotFoundError(`cron job ${cronId} not found`);
|
|
291
321
|
}
|
|
292
322
|
|
|
323
|
+
// ATP-1.2: deleting a template row writes a tombstone so a later
|
|
324
|
+
// reconcile does not re-add it.
|
|
325
|
+
if (existing.source === "template") {
|
|
326
|
+
await this.prisma.agentCronJob.update({
|
|
327
|
+
where: { id: cronId },
|
|
328
|
+
data: { enabled: false, source: "custom", lockdownDisabledAt: null },
|
|
329
|
+
});
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
293
332
|
await this.prisma.agentCronJob.delete({ where: { id: cronId } });
|
|
294
333
|
}
|
|
295
334
|
|
|
@@ -305,15 +344,28 @@ export class AgentCronJobService {
|
|
|
305
344
|
async update(
|
|
306
345
|
agentId: string,
|
|
307
346
|
cronId: string,
|
|
308
|
-
input:
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
347
|
+
input: UpdateAgentCronJobInput,
|
|
348
|
+
): Promise<AgentCronJob> {
|
|
349
|
+
return this.updateWithSource(agentId, cronId, input, "custom");
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Internal reconcile write path (ATP-1.2); never exposed over HTTP.
|
|
354
|
+
* Same validation as update() but leaves `source` untouched.
|
|
355
|
+
*/
|
|
356
|
+
async updateFromTemplate(
|
|
357
|
+
agentId: string,
|
|
358
|
+
cronId: string,
|
|
359
|
+
input: UpdateAgentCronJobInput,
|
|
360
|
+
): Promise<AgentCronJob> {
|
|
361
|
+
return this.updateWithSource(agentId, cronId, input, undefined);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
private async updateWithSource(
|
|
365
|
+
agentId: string,
|
|
366
|
+
cronId: string,
|
|
367
|
+
input: UpdateAgentCronJobInput,
|
|
368
|
+
source: "custom" | undefined,
|
|
317
369
|
): Promise<AgentCronJob> {
|
|
318
370
|
await this.get(agentId, cronId);
|
|
319
371
|
|
|
@@ -337,6 +389,7 @@ export class AgentCronJobService {
|
|
|
337
389
|
channel,
|
|
338
390
|
user,
|
|
339
391
|
silent,
|
|
392
|
+
...(source && { source }),
|
|
340
393
|
...(input.preCheck !== undefined && { preCheck: input.preCheck }),
|
|
341
394
|
// Any explicit enabled change is a user decision — clear the lockdown
|
|
342
395
|
// marker so restoreLockdownDisabled() never overrides it.
|
|
@@ -361,7 +414,7 @@ export class AgentCronJobService {
|
|
|
361
414
|
await this.get(agentId, cronId);
|
|
362
415
|
return this.prisma.agentCronJob.update({
|
|
363
416
|
where: { id: cronId },
|
|
364
|
-
data: { preCheck },
|
|
417
|
+
data: { preCheck, source: "custom" },
|
|
365
418
|
});
|
|
366
419
|
}
|
|
367
420
|
|
|
@@ -384,6 +437,7 @@ export class AgentCronJobService {
|
|
|
384
437
|
return this.prisma.agentCronJob.update({
|
|
385
438
|
where: { id: cronId },
|
|
386
439
|
data: {
|
|
440
|
+
source: "custom",
|
|
387
441
|
...(input.channel !== undefined && { channel: input.channel }),
|
|
388
442
|
...(input.user !== undefined && { user: input.user }),
|
|
389
443
|
...(input.silent !== undefined && { silent: input.silent }),
|
|
@@ -413,6 +467,8 @@ export class AgentCronJobService {
|
|
|
413
467
|
data: {
|
|
414
468
|
enabled,
|
|
415
469
|
lockdownDisabledAt: !enabled && opts?.lockdown ? new Date() : null,
|
|
470
|
+
// A lockdown disable is system-driven, not an admin edit.
|
|
471
|
+
...(!opts?.lockdown && { source: "custom" }),
|
|
416
472
|
},
|
|
417
473
|
});
|
|
418
474
|
}
|
package/src/agent-deletion.ts
CHANGED
|
@@ -119,7 +119,7 @@ interface DeleteAgentPrisma {
|
|
|
119
119
|
};
|
|
120
120
|
agentEnv: {
|
|
121
121
|
findMany(args: {
|
|
122
|
-
where: { agentId: string };
|
|
122
|
+
where: { agentId: string; enabled: true };
|
|
123
123
|
select: { key: true; value: true; secret: true };
|
|
124
124
|
}): Promise<{ key: string; value: string; secret: boolean }[]>;
|
|
125
125
|
};
|
|
@@ -199,7 +199,7 @@ export async function deleteAgentFully(
|
|
|
199
199
|
throw new NotFoundError(`agent ${agentId} not found`);
|
|
200
200
|
}
|
|
201
201
|
const envRows = await deps.prisma.agentEnv.findMany({
|
|
202
|
-
where: { agentId },
|
|
202
|
+
where: { agentId, enabled: true },
|
|
203
203
|
select: { key: true, value: true, secret: true },
|
|
204
204
|
});
|
|
205
205
|
|
|
@@ -321,3 +321,111 @@ describeOrSkip(
|
|
|
321
321
|
});
|
|
322
322
|
},
|
|
323
323
|
);
|
|
324
|
+
|
|
325
|
+
describeOrSkip("AgentEnvService source and tombstones (integration)", () => {
|
|
326
|
+
let prisma: PrismaClient;
|
|
327
|
+
let service: AgentEnvService;
|
|
328
|
+
|
|
329
|
+
beforeEach(async () => {
|
|
330
|
+
prisma = makePrisma();
|
|
331
|
+
await prisma.agentToken.deleteMany();
|
|
332
|
+
await prisma.agentCronJob.deleteMany();
|
|
333
|
+
await prisma.agentTool.deleteMany();
|
|
334
|
+
await prisma.agentEnv.deleteMany();
|
|
335
|
+
await prisma.agent.deleteMany();
|
|
336
|
+
service = new AgentEnvService(prisma, identityCrypto);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
afterEach(async () => {
|
|
340
|
+
await prisma.$disconnect();
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
const rowsOf = (agentId: string) =>
|
|
344
|
+
prisma.agentEnv.findMany({ where: { agentId }, orderBy: { key: "asc" } });
|
|
345
|
+
|
|
346
|
+
it("patch() and upsert() stamp source=custom", async () => {
|
|
347
|
+
const agentId = await createAgent(prisma);
|
|
348
|
+
await service.patch(agentId, { A: "1" });
|
|
349
|
+
expect((await rowsOf(agentId)).map((r) => r.source)).toEqual(["custom"]);
|
|
350
|
+
await service.upsert(agentId, { B: "2" });
|
|
351
|
+
expect((await rowsOf(agentId)).map((r) => r.source)).toEqual(["custom"]);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("patchFromTemplate() writes source=template", async () => {
|
|
355
|
+
const agentId = await createAgent(prisma);
|
|
356
|
+
await service.patchFromTemplate(agentId, { A: "1" });
|
|
357
|
+
const rows = await rowsOf(agentId);
|
|
358
|
+
expect(rows[0]?.source).toBe("template");
|
|
359
|
+
expect(rows[0]?.enabled).toBe(true);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it("patch() of a template-sourced key turns it custom", async () => {
|
|
363
|
+
const agentId = await createAgent(prisma);
|
|
364
|
+
await service.patchFromTemplate(agentId, { A: "1" });
|
|
365
|
+
await service.patch(agentId, { A: "2" });
|
|
366
|
+
const rows = await rowsOf(agentId);
|
|
367
|
+
expect(rows[0]?.source).toBe("custom");
|
|
368
|
+
expect((await service.getByAgentId(agentId))?.env).toEqual({ A: "2" });
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("patchFromTemplate() does not overwrite a custom or tombstoned key", async () => {
|
|
372
|
+
const agentId = await createAgent(prisma);
|
|
373
|
+
await service.patch(agentId, { C: "mine" });
|
|
374
|
+
await service.patchFromTemplate(agentId, { C: "tpl" });
|
|
375
|
+
expect((await service.getByAgentId(agentId))?.env).toEqual({ C: "mine" });
|
|
376
|
+
await service.patchFromTemplate(agentId, { T: "tpl" });
|
|
377
|
+
await service.deleteKey(agentId, "T");
|
|
378
|
+
await service.patchFromTemplate(agentId, { T: "tpl" });
|
|
379
|
+
const t = (await rowsOf(agentId)).find((r) => r.key === "T");
|
|
380
|
+
expect(t?.enabled).toBe(false);
|
|
381
|
+
expect(t?.source).toBe("custom");
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it("deleteKey() of a template key leaves a tombstone that no read injects", async () => {
|
|
385
|
+
const agentId = await createAgent(prisma);
|
|
386
|
+
await service.patchFromTemplate(agentId, { T: "tpl" });
|
|
387
|
+
await service.patch(agentId, { K: "keep" });
|
|
388
|
+
await service.deleteKey(agentId, "T");
|
|
389
|
+
const t = (await rowsOf(agentId)).find((r) => r.key === "T");
|
|
390
|
+
expect(t?.enabled).toBe(false);
|
|
391
|
+
expect(t?.source).toBe("custom");
|
|
392
|
+
expect((await service.getByAgentId(agentId))?.env).toEqual({ K: "keep" });
|
|
393
|
+
expect((await service.getConfigBundle(agentId))?.env).toEqual({
|
|
394
|
+
K: "keep",
|
|
395
|
+
});
|
|
396
|
+
expect((await service.listAll())[0]?.env).toEqual({ K: "keep" });
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("a tombstone-only agent reads as having no env", async () => {
|
|
400
|
+
const agentId = await createAgent(prisma);
|
|
401
|
+
await service.patchFromTemplate(agentId, { T: "tpl" });
|
|
402
|
+
await service.deleteKey(agentId, "T");
|
|
403
|
+
expect(await service.getByAgentId(agentId)).toBeNull();
|
|
404
|
+
expect(await service.getConfigBundle(agentId)).toBeNull();
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
it("deleteKey() of a custom key removes the row", async () => {
|
|
408
|
+
const agentId = await createAgent(prisma);
|
|
409
|
+
await service.patch(agentId, { K: "v" });
|
|
410
|
+
await service.deleteKey(agentId, "K");
|
|
411
|
+
expect(await rowsOf(agentId)).toEqual([]);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("patch() re-enables a tombstoned key", async () => {
|
|
415
|
+
const agentId = await createAgent(prisma);
|
|
416
|
+
await service.patchFromTemplate(agentId, { T: "tpl" });
|
|
417
|
+
await service.deleteKey(agentId, "T");
|
|
418
|
+
await service.patch(agentId, { T: "again" });
|
|
419
|
+
expect((await service.getByAgentId(agentId))?.env).toEqual({ T: "again" });
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
it("upsert() tombstones template keys it omits", async () => {
|
|
423
|
+
const agentId = await createAgent(prisma);
|
|
424
|
+
await service.patchFromTemplate(agentId, { T: "tpl" });
|
|
425
|
+
await service.upsert(agentId, { K: "v" });
|
|
426
|
+
const t = (await rowsOf(agentId)).find((r) => r.key === "T");
|
|
427
|
+
expect(t?.enabled).toBe(false);
|
|
428
|
+
expect(t?.source).toBe("custom");
|
|
429
|
+
expect((await service.getByAgentId(agentId))?.env).toEqual({ K: "v" });
|
|
430
|
+
});
|
|
431
|
+
});
|