@app-vitals/agent-admin 1.39.0 → 1.41.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.
Files changed (37) hide show
  1. package/openapi.platform.json +584 -0
  2. package/package.json +2 -2
  3. package/prisma/client/browser.ts +10 -0
  4. package/prisma/client/client.ts +10 -0
  5. package/prisma/client/internal/class.ts +24 -4
  6. package/prisma/client/internal/prismaNamespace.ts +184 -2
  7. package/prisma/client/internal/prismaNamespaceBrowser.ts +33 -1
  8. package/prisma/client/models/Account.ts +148 -0
  9. package/prisma/client/models/Agent.ts +80 -1
  10. package/prisma/client/models/AgentCronJob.ts +54 -1
  11. package/prisma/client/models/AgentEnv.ts +36 -1
  12. package/prisma/client/models/AgentPlugin.ts +36 -1
  13. package/prisma/client/models/AgentTemplate.ts +1501 -0
  14. package/prisma/client/models/AgentTemplateItem.ts +1416 -0
  15. package/prisma/client/models/AgentTool.ts +71 -1
  16. package/prisma/client/models.ts +2 -0
  17. package/prisma/migrations/20261113000000_add_agent_templates/migration.sql +71 -0
  18. package/prisma/schema/schema.prisma +61 -4
  19. package/src/admin-boot.ts +18 -0
  20. package/src/admin-local-agent.smoke.test.ts +2 -0
  21. package/src/admin-spec.ts +18 -0
  22. package/src/admin-ui.fixtures.ts +3 -0
  23. package/src/admin-ui.smoke.test.ts +2 -0
  24. package/src/agent-cron-run-stats.smoke.test.ts +10 -0
  25. package/src/agent-plugins.unit.test.ts +1 -0
  26. package/src/agent-template-items.ts +82 -0
  27. package/src/agent-template-items.unit.test.ts +70 -0
  28. package/src/agent-templates-api.integration.test.ts +428 -0
  29. package/src/agent-templates-api.smoke.test.ts +135 -0
  30. package/src/agent-templates-api.ts +293 -0
  31. package/src/agent-templates.integration.test.ts +200 -0
  32. package/src/agent-templates.ts +432 -0
  33. package/src/agents-api.smoke.test.ts +17 -0
  34. package/src/api-auth.ts +3 -0
  35. package/src/api.smoke.test.ts +13 -0
  36. package/src/chat.smoke.test.ts +2 -0
  37. package/src/openapi-schemas.ts +84 -0
@@ -29,7 +29,9 @@ export type AgentToolMinAggregateOutputType = {
29
29
  agentId: string | null
30
30
  pattern: string | null
31
31
  enabled: boolean | null
32
+ source: string | null
32
33
  createdAt: Date | null
34
+ updatedAt: Date | null
33
35
  }
34
36
 
35
37
  export type AgentToolMaxAggregateOutputType = {
@@ -37,7 +39,9 @@ export type AgentToolMaxAggregateOutputType = {
37
39
  agentId: string | null
38
40
  pattern: string | null
39
41
  enabled: boolean | null
42
+ source: string | null
40
43
  createdAt: Date | null
44
+ updatedAt: Date | null
41
45
  }
42
46
 
43
47
  export type AgentToolCountAggregateOutputType = {
@@ -45,7 +49,9 @@ export type AgentToolCountAggregateOutputType = {
45
49
  agentId: number
46
50
  pattern: number
47
51
  enabled: number
52
+ source: number
48
53
  createdAt: number
54
+ updatedAt: number
49
55
  _all: number
50
56
  }
51
57
 
@@ -55,7 +61,9 @@ export type AgentToolMinAggregateInputType = {
55
61
  agentId?: true
56
62
  pattern?: true
57
63
  enabled?: true
64
+ source?: true
58
65
  createdAt?: true
66
+ updatedAt?: true
59
67
  }
60
68
 
61
69
  export type AgentToolMaxAggregateInputType = {
@@ -63,7 +71,9 @@ export type AgentToolMaxAggregateInputType = {
63
71
  agentId?: true
64
72
  pattern?: true
65
73
  enabled?: true
74
+ source?: true
66
75
  createdAt?: true
76
+ updatedAt?: true
67
77
  }
68
78
 
69
79
  export type AgentToolCountAggregateInputType = {
@@ -71,7 +81,9 @@ export type AgentToolCountAggregateInputType = {
71
81
  agentId?: true
72
82
  pattern?: true
73
83
  enabled?: true
84
+ source?: true
74
85
  createdAt?: true
86
+ updatedAt?: true
75
87
  _all?: true
76
88
  }
77
89
 
@@ -152,7 +164,9 @@ export type AgentToolGroupByOutputType = {
152
164
  agentId: string
153
165
  pattern: string
154
166
  enabled: boolean
167
+ source: string
155
168
  createdAt: Date
169
+ updatedAt: Date
156
170
  _count: AgentToolCountAggregateOutputType | null
157
171
  _min: AgentToolMinAggregateOutputType | null
158
172
  _max: AgentToolMaxAggregateOutputType | null
@@ -181,7 +195,9 @@ export type AgentToolWhereInput = {
181
195
  agentId?: Prisma.StringFilter<"AgentTool"> | string
182
196
  pattern?: Prisma.StringFilter<"AgentTool"> | string
183
197
  enabled?: Prisma.BoolFilter<"AgentTool"> | boolean
198
+ source?: Prisma.StringFilter<"AgentTool"> | string
184
199
  createdAt?: Prisma.DateTimeFilter<"AgentTool"> | Date | string
200
+ updatedAt?: Prisma.DateTimeFilter<"AgentTool"> | Date | string
185
201
  agent?: Prisma.XOR<Prisma.AgentScalarRelationFilter, Prisma.AgentWhereInput>
186
202
  }
187
203
 
@@ -190,7 +206,9 @@ export type AgentToolOrderByWithRelationInput = {
190
206
  agentId?: Prisma.SortOrder
191
207
  pattern?: Prisma.SortOrder
192
208
  enabled?: Prisma.SortOrder
209
+ source?: Prisma.SortOrder
193
210
  createdAt?: Prisma.SortOrder
211
+ updatedAt?: Prisma.SortOrder
194
212
  agent?: Prisma.AgentOrderByWithRelationInput
195
213
  }
196
214
 
@@ -203,7 +221,9 @@ export type AgentToolWhereUniqueInput = Prisma.AtLeast<{
203
221
  agentId?: Prisma.StringFilter<"AgentTool"> | string
204
222
  pattern?: Prisma.StringFilter<"AgentTool"> | string
205
223
  enabled?: Prisma.BoolFilter<"AgentTool"> | boolean
224
+ source?: Prisma.StringFilter<"AgentTool"> | string
206
225
  createdAt?: Prisma.DateTimeFilter<"AgentTool"> | Date | string
226
+ updatedAt?: Prisma.DateTimeFilter<"AgentTool"> | Date | string
207
227
  agent?: Prisma.XOR<Prisma.AgentScalarRelationFilter, Prisma.AgentWhereInput>
208
228
  }, "id" | "agentId_pattern">
209
229
 
@@ -212,7 +232,9 @@ export type AgentToolOrderByWithAggregationInput = {
212
232
  agentId?: Prisma.SortOrder
213
233
  pattern?: Prisma.SortOrder
214
234
  enabled?: Prisma.SortOrder
235
+ source?: Prisma.SortOrder
215
236
  createdAt?: Prisma.SortOrder
237
+ updatedAt?: Prisma.SortOrder
216
238
  _count?: Prisma.AgentToolCountOrderByAggregateInput
217
239
  _max?: Prisma.AgentToolMaxOrderByAggregateInput
218
240
  _min?: Prisma.AgentToolMinOrderByAggregateInput
@@ -226,14 +248,18 @@ export type AgentToolScalarWhereWithAggregatesInput = {
226
248
  agentId?: Prisma.StringWithAggregatesFilter<"AgentTool"> | string
227
249
  pattern?: Prisma.StringWithAggregatesFilter<"AgentTool"> | string
228
250
  enabled?: Prisma.BoolWithAggregatesFilter<"AgentTool"> | boolean
251
+ source?: Prisma.StringWithAggregatesFilter<"AgentTool"> | string
229
252
  createdAt?: Prisma.DateTimeWithAggregatesFilter<"AgentTool"> | Date | string
253
+ updatedAt?: Prisma.DateTimeWithAggregatesFilter<"AgentTool"> | Date | string
230
254
  }
231
255
 
232
256
  export type AgentToolCreateInput = {
233
257
  id?: string
234
258
  pattern: string
235
259
  enabled?: boolean
260
+ source?: string
236
261
  createdAt?: Date | string
262
+ updatedAt?: Date | string
237
263
  agent: Prisma.AgentCreateNestedOneWithoutToolsInput
238
264
  }
239
265
 
@@ -242,14 +268,18 @@ export type AgentToolUncheckedCreateInput = {
242
268
  agentId: string
243
269
  pattern: string
244
270
  enabled?: boolean
271
+ source?: string
245
272
  createdAt?: Date | string
273
+ updatedAt?: Date | string
246
274
  }
247
275
 
248
276
  export type AgentToolUpdateInput = {
249
277
  id?: Prisma.StringFieldUpdateOperationsInput | string
250
278
  pattern?: Prisma.StringFieldUpdateOperationsInput | string
251
279
  enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
280
+ source?: Prisma.StringFieldUpdateOperationsInput | string
252
281
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
282
+ updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
253
283
  agent?: Prisma.AgentUpdateOneRequiredWithoutToolsNestedInput
254
284
  }
255
285
 
@@ -258,7 +288,9 @@ export type AgentToolUncheckedUpdateInput = {
258
288
  agentId?: Prisma.StringFieldUpdateOperationsInput | string
259
289
  pattern?: Prisma.StringFieldUpdateOperationsInput | string
260
290
  enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
291
+ source?: Prisma.StringFieldUpdateOperationsInput | string
261
292
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
293
+ updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
262
294
  }
263
295
 
264
296
  export type AgentToolCreateManyInput = {
@@ -266,14 +298,18 @@ export type AgentToolCreateManyInput = {
266
298
  agentId: string
267
299
  pattern: string
268
300
  enabled?: boolean
301
+ source?: string
269
302
  createdAt?: Date | string
303
+ updatedAt?: Date | string
270
304
  }
271
305
 
272
306
  export type AgentToolUpdateManyMutationInput = {
273
307
  id?: Prisma.StringFieldUpdateOperationsInput | string
274
308
  pattern?: Prisma.StringFieldUpdateOperationsInput | string
275
309
  enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
310
+ source?: Prisma.StringFieldUpdateOperationsInput | string
276
311
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
312
+ updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
277
313
  }
278
314
 
279
315
  export type AgentToolUncheckedUpdateManyInput = {
@@ -281,7 +317,9 @@ export type AgentToolUncheckedUpdateManyInput = {
281
317
  agentId?: Prisma.StringFieldUpdateOperationsInput | string
282
318
  pattern?: Prisma.StringFieldUpdateOperationsInput | string
283
319
  enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
320
+ source?: Prisma.StringFieldUpdateOperationsInput | string
284
321
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
322
+ updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
285
323
  }
286
324
 
287
325
  export type AgentToolListRelationFilter = {
@@ -304,7 +342,9 @@ export type AgentToolCountOrderByAggregateInput = {
304
342
  agentId?: Prisma.SortOrder
305
343
  pattern?: Prisma.SortOrder
306
344
  enabled?: Prisma.SortOrder
345
+ source?: Prisma.SortOrder
307
346
  createdAt?: Prisma.SortOrder
347
+ updatedAt?: Prisma.SortOrder
308
348
  }
309
349
 
310
350
  export type AgentToolMaxOrderByAggregateInput = {
@@ -312,7 +352,9 @@ export type AgentToolMaxOrderByAggregateInput = {
312
352
  agentId?: Prisma.SortOrder
313
353
  pattern?: Prisma.SortOrder
314
354
  enabled?: Prisma.SortOrder
355
+ source?: Prisma.SortOrder
315
356
  createdAt?: Prisma.SortOrder
357
+ updatedAt?: Prisma.SortOrder
316
358
  }
317
359
 
318
360
  export type AgentToolMinOrderByAggregateInput = {
@@ -320,7 +362,9 @@ export type AgentToolMinOrderByAggregateInput = {
320
362
  agentId?: Prisma.SortOrder
321
363
  pattern?: Prisma.SortOrder
322
364
  enabled?: Prisma.SortOrder
365
+ source?: Prisma.SortOrder
323
366
  createdAt?: Prisma.SortOrder
367
+ updatedAt?: Prisma.SortOrder
324
368
  }
325
369
 
326
370
  export type AgentToolCreateNestedManyWithoutAgentInput = {
@@ -369,14 +413,18 @@ export type AgentToolCreateWithoutAgentInput = {
369
413
  id?: string
370
414
  pattern: string
371
415
  enabled?: boolean
416
+ source?: string
372
417
  createdAt?: Date | string
418
+ updatedAt?: Date | string
373
419
  }
374
420
 
375
421
  export type AgentToolUncheckedCreateWithoutAgentInput = {
376
422
  id?: string
377
423
  pattern: string
378
424
  enabled?: boolean
425
+ source?: string
379
426
  createdAt?: Date | string
427
+ updatedAt?: Date | string
380
428
  }
381
429
 
382
430
  export type AgentToolCreateOrConnectWithoutAgentInput = {
@@ -413,35 +461,45 @@ export type AgentToolScalarWhereInput = {
413
461
  agentId?: Prisma.StringFilter<"AgentTool"> | string
414
462
  pattern?: Prisma.StringFilter<"AgentTool"> | string
415
463
  enabled?: Prisma.BoolFilter<"AgentTool"> | boolean
464
+ source?: Prisma.StringFilter<"AgentTool"> | string
416
465
  createdAt?: Prisma.DateTimeFilter<"AgentTool"> | Date | string
466
+ updatedAt?: Prisma.DateTimeFilter<"AgentTool"> | Date | string
417
467
  }
418
468
 
419
469
  export type AgentToolCreateManyAgentInput = {
420
470
  id?: string
421
471
  pattern: string
422
472
  enabled?: boolean
473
+ source?: string
423
474
  createdAt?: Date | string
475
+ updatedAt?: Date | string
424
476
  }
425
477
 
426
478
  export type AgentToolUpdateWithoutAgentInput = {
427
479
  id?: Prisma.StringFieldUpdateOperationsInput | string
428
480
  pattern?: Prisma.StringFieldUpdateOperationsInput | string
429
481
  enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
482
+ source?: Prisma.StringFieldUpdateOperationsInput | string
430
483
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
484
+ updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
431
485
  }
432
486
 
433
487
  export type AgentToolUncheckedUpdateWithoutAgentInput = {
434
488
  id?: Prisma.StringFieldUpdateOperationsInput | string
435
489
  pattern?: Prisma.StringFieldUpdateOperationsInput | string
436
490
  enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
491
+ source?: Prisma.StringFieldUpdateOperationsInput | string
437
492
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
493
+ updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
438
494
  }
439
495
 
440
496
  export type AgentToolUncheckedUpdateManyWithoutAgentInput = {
441
497
  id?: Prisma.StringFieldUpdateOperationsInput | string
442
498
  pattern?: Prisma.StringFieldUpdateOperationsInput | string
443
499
  enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
500
+ source?: Prisma.StringFieldUpdateOperationsInput | string
444
501
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
502
+ updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
445
503
  }
446
504
 
447
505
 
@@ -451,7 +509,9 @@ export type AgentToolSelect<ExtArgs extends runtime.Types.Extensions.InternalArg
451
509
  agentId?: boolean
452
510
  pattern?: boolean
453
511
  enabled?: boolean
512
+ source?: boolean
454
513
  createdAt?: boolean
514
+ updatedAt?: boolean
455
515
  agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
456
516
  }, ExtArgs["result"]["agentTool"]>
457
517
 
@@ -460,7 +520,9 @@ export type AgentToolSelectCreateManyAndReturn<ExtArgs extends runtime.Types.Ext
460
520
  agentId?: boolean
461
521
  pattern?: boolean
462
522
  enabled?: boolean
523
+ source?: boolean
463
524
  createdAt?: boolean
525
+ updatedAt?: boolean
464
526
  agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
465
527
  }, ExtArgs["result"]["agentTool"]>
466
528
 
@@ -469,7 +531,9 @@ export type AgentToolSelectUpdateManyAndReturn<ExtArgs extends runtime.Types.Ext
469
531
  agentId?: boolean
470
532
  pattern?: boolean
471
533
  enabled?: boolean
534
+ source?: boolean
472
535
  createdAt?: boolean
536
+ updatedAt?: boolean
473
537
  agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
474
538
  }, ExtArgs["result"]["agentTool"]>
475
539
 
@@ -478,10 +542,12 @@ export type AgentToolSelectScalar = {
478
542
  agentId?: boolean
479
543
  pattern?: boolean
480
544
  enabled?: boolean
545
+ source?: boolean
481
546
  createdAt?: boolean
547
+ updatedAt?: boolean
482
548
  }
483
549
 
484
- export type AgentToolOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "agentId" | "pattern" | "enabled" | "createdAt", ExtArgs["result"]["agentTool"]>
550
+ export type AgentToolOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "agentId" | "pattern" | "enabled" | "source" | "createdAt" | "updatedAt", ExtArgs["result"]["agentTool"]>
485
551
  export type AgentToolInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
486
552
  agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
487
553
  }
@@ -502,7 +568,9 @@ export type $AgentToolPayload<ExtArgs extends runtime.Types.Extensions.InternalA
502
568
  agentId: string
503
569
  pattern: string
504
570
  enabled: boolean
571
+ source: string
505
572
  createdAt: Date
573
+ updatedAt: Date
506
574
  }, ExtArgs["result"]["agentTool"]>
507
575
  composites: {}
508
576
  }
@@ -931,7 +999,9 @@ export interface AgentToolFieldRefs {
931
999
  readonly agentId: Prisma.FieldRef<"AgentTool", 'String'>
932
1000
  readonly pattern: Prisma.FieldRef<"AgentTool", 'String'>
933
1001
  readonly enabled: Prisma.FieldRef<"AgentTool", 'Boolean'>
1002
+ readonly source: Prisma.FieldRef<"AgentTool", 'String'>
934
1003
  readonly createdAt: Prisma.FieldRef<"AgentTool", 'DateTime'>
1004
+ readonly updatedAt: Prisma.FieldRef<"AgentTool", 'DateTime'>
935
1005
  }
936
1006
 
937
1007
 
@@ -21,6 +21,8 @@ export type * from './models/AgentToken.ts'
21
21
  export type * from './models/AgentPlugin.ts'
22
22
  export type * from './models/AgentMember.ts'
23
23
  export type * from './models/Account.ts'
24
+ export type * from './models/AgentTemplate.ts'
25
+ export type * from './models/AgentTemplateItem.ts'
24
26
  export type * from './models/AccountMember.ts'
25
27
  export type * from './models/AccountInvite.ts'
26
28
  export type * from './models/AgentCronRun.ts'
@@ -0,0 +1,71 @@
1
+ -- ATP-1.1: agent templates and row source markers. Additive only: two new
2
+ -- tables, plus new columns with defaults on existing tables (existing rows get
3
+ -- source = 'custom', templateDetached = false, AgentTool.updatedAt = now).
4
+ -- AlterTable
5
+ ALTER TABLE "Agent" ADD COLUMN "templateDetached" BOOLEAN NOT NULL DEFAULT false;
6
+
7
+ -- AlterTable
8
+ ALTER TABLE "AgentCronJob" ADD COLUMN "source" TEXT NOT NULL DEFAULT 'custom';
9
+
10
+ -- AlterTable
11
+ ALTER TABLE "AgentEnv" ADD COLUMN "source" TEXT NOT NULL DEFAULT 'custom';
12
+
13
+ -- AlterTable
14
+ ALTER TABLE "AgentPlugin" ADD COLUMN "source" TEXT NOT NULL DEFAULT 'custom';
15
+
16
+ -- AlterTable
17
+ ALTER TABLE "AgentTool" ADD COLUMN "source" TEXT NOT NULL DEFAULT 'custom',
18
+ ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
19
+
20
+ -- CreateTable
21
+ CREATE TABLE "AgentTemplate" (
22
+ "id" TEXT NOT NULL,
23
+ "accountId" TEXT,
24
+ "specialty" TEXT,
25
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
26
+ "updatedAt" TIMESTAMP(3) NOT NULL,
27
+
28
+ CONSTRAINT "AgentTemplate_pkey" PRIMARY KEY ("id")
29
+ );
30
+
31
+ -- CreateTable
32
+ CREATE TABLE "AgentTemplateItem" (
33
+ "id" TEXT NOT NULL,
34
+ "templateId" TEXT NOT NULL,
35
+ "kind" TEXT NOT NULL,
36
+ "key" TEXT NOT NULL,
37
+ "payload" JSONB NOT NULL DEFAULT '{}',
38
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
39
+ "updatedAt" TIMESTAMP(3) NOT NULL,
40
+
41
+ CONSTRAINT "AgentTemplateItem_pkey" PRIMARY KEY ("id")
42
+ );
43
+
44
+ -- CreateIndex
45
+ CREATE INDEX "AgentTemplate_accountId_idx" ON "AgentTemplate"("accountId");
46
+
47
+ -- CreateIndex
48
+ CREATE UNIQUE INDEX "AgentTemplateItem_templateId_kind_key_key" ON "AgentTemplateItem"("templateId", "kind", "key");
49
+
50
+ -- AddForeignKey
51
+ ALTER TABLE "AgentTemplate" ADD CONSTRAINT "AgentTemplate_accountId_fkey" FOREIGN KEY ("accountId") REFERENCES "Account"("id") ON DELETE CASCADE ON UPDATE CASCADE;
52
+
53
+ -- AddForeignKey
54
+ ALTER TABLE "AgentTemplateItem" ADD CONSTRAINT "AgentTemplateItem_templateId_fkey" FOREIGN KEY ("templateId") REFERENCES "AgentTemplate"("id") ON DELETE CASCADE ON UPDATE CASCADE;
55
+
56
+
57
+ -- Partial unique indexes (not expressible in Prisma; see the AgentTemplate
58
+ -- comment in schema.prisma). Together they allow at most one template per
59
+ -- (accountId, specialty) pair with NULL treated as a value, which a plain
60
+ -- UNIQUE index would not do since NULLs compare distinct.
61
+ -- CreateIndex
62
+ CREATE UNIQUE INDEX "AgentTemplate_accountId_specialty_key" ON "AgentTemplate"("accountId", "specialty") WHERE "accountId" IS NOT NULL AND "specialty" IS NOT NULL;
63
+
64
+ -- CreateIndex
65
+ CREATE UNIQUE INDEX "AgentTemplate_specialty_global_key" ON "AgentTemplate"("specialty") WHERE "accountId" IS NULL AND "specialty" IS NOT NULL;
66
+
67
+ -- CreateIndex
68
+ CREATE UNIQUE INDEX "AgentTemplate_accountId_any_key" ON "AgentTemplate"("accountId") WHERE "accountId" IS NOT NULL AND "specialty" IS NULL;
69
+
70
+ -- CreateIndex
71
+ CREATE UNIQUE INDEX "AgentTemplate_global_any_key" ON "AgentTemplate"((1)) WHERE "accountId" IS NULL AND "specialty" IS NULL;
@@ -1,6 +1,6 @@
1
1
  // Shipwright — Admin Service Schema
2
2
  // Owns: Agent, AgentEnv, AgentCronJob, AgentTool, AgentToken, AgentPlugin,
3
- // AgentMarketplace,
3
+ // AgentMarketplace, AgentTemplate, AgentTemplateItem,
4
4
  // plus the coding-owned models in coding.prisma (AgentWorkQueueSnapshot,
5
5
  // AgentPhaseMethodology, SessionFollow, SessionAlertState).
6
6
  // Agent is a first-class model (standalone, not embedded in a User model).
@@ -89,6 +89,9 @@ model Agent {
89
89
  // reported by the runtime at boot (overwritten each report). Written ONLY by
90
90
  // PUT /agents/:id/baked-marketplaces; never by PATCH or any UI.
91
91
  bakedMarketplaces String[] @default([])
92
+ // ATP-1.1: true once the agent stops following its template (template
93
+ // changes no longer reach its source="template" rows). Additive, default false.
94
+ templateDetached Boolean @default(false)
92
95
  createdAt DateTime @default(now())
93
96
  updatedAt DateTime @updatedAt
94
97
 
@@ -118,6 +121,7 @@ model AgentEnv {
118
121
  key String // env var name
119
122
  value String // AES-256-GCM encrypted
120
123
  secret Boolean @default(false) // when true, GET /agents/:id/envs masks the value as ***
124
+ source String @default("custom") // ATP-1.1: 'template' | 'custom'; which rows a template sync owns
121
125
  createdAt DateTime @default(now())
122
126
  updatedAt DateTime @updatedAt
123
127
 
@@ -160,6 +164,7 @@ model AgentCronJob {
160
164
  preCheck String? // optional pre-check script e.g. "shipwright:check-docs-freshness.ts"
161
165
  name String? // stable key for system crons; null for user-created crons
162
166
  system Boolean @default(false)
167
+ source String @default("custom") // ATP-1.1: 'template' | 'custom'; which rows a template sync owns
163
168
  // Set when the trial-expiry lockdown (not the user) disabled this cron, so
164
169
  // restoreLockdownDisabled() can re-enable exactly those crons. Null for
165
170
  // enabled crons and for crons the user disabled manually.
@@ -196,7 +201,9 @@ model AgentTool {
196
201
  agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
197
202
  pattern String
198
203
  enabled Boolean @default(true)
204
+ source String @default("custom") // ATP-1.1: 'template' | 'custom'; which rows a template sync owns
199
205
  createdAt DateTime @default(now())
206
+ updatedAt DateTime @default(now()) @updatedAt // ATP-1.1; existing rows backfilled to the migration time
200
207
 
201
208
  @@unique([agentId, pattern])
202
209
  }
@@ -227,6 +234,7 @@ model AgentPlugin {
227
234
  name String // plugin package name e.g. "@shipwright/plugin"
228
235
  version String? // pinned version; null = latest
229
236
  enabled Boolean @default(true)
237
+ source String @default("custom") // ATP-1.1: 'template' | 'custom'; which rows a template sync owns
230
238
  createdAt DateTime @default(now())
231
239
  updatedAt DateTime @updatedAt
232
240
 
@@ -266,9 +274,58 @@ model Account {
266
274
  createdAt DateTime @default(now())
267
275
  updatedAt DateTime @updatedAt
268
276
 
269
- agents Agent[]
270
- members AccountMember[]
271
- invites AccountInvite[]
277
+ agents Agent[]
278
+ members AccountMember[]
279
+ invites AccountInvite[]
280
+ templates AgentTemplate[]
281
+ }
282
+
283
+ // ─── Agent Templates ──────────────────────────────────────────────────────────
284
+ // ATP-1.1: a template is the default env/tool/plugin/cron set for agents of a
285
+ // given scope. accountId null = deployment-wide; specialty null = every
286
+ // specialty. Rows copied from a template onto an agent carry source="template"
287
+ // on AgentEnv/AgentTool/AgentPlugin/AgentCronJob; hand-made rows are "custom".
288
+ //
289
+ // UNIQUENESS: at most one template per (accountId, specialty), with NULL
290
+ // treated as a value. Prisma cannot express partial unique indexes, so they
291
+ // are hand-written in 20261113000000_add_agent_templates/migration.sql:
292
+ // AgentTemplate_accountId_specialty_key (both set)
293
+ // AgentTemplate_specialty_global_key (accountId NULL)
294
+ // AgentTemplate_accountId_any_key (specialty NULL)
295
+ // AgentTemplate_global_any_key (both NULL)
296
+ // Prisma's schema diff does not see them, so keep them when editing this
297
+ // model and re-create them by hand if the table is ever rebuilt.
298
+
299
+ model AgentTemplate {
300
+ id String @id @default(cuid())
301
+ accountId String?
302
+ account Account? @relation(fields: [accountId], references: [id], onDelete: Cascade)
303
+ specialty String? // Specialty name (manifest key); null = any specialty
304
+ createdAt DateTime @default(now())
305
+ updatedAt DateTime @updatedAt
306
+
307
+ items AgentTemplateItem[]
308
+
309
+ @@index([accountId])
310
+ }
311
+
312
+ // One entry of a template. kind is 'env' | 'tool' | 'plugin' | 'cron'
313
+ // (validated in the service layer); key is the env var name, tool pattern,
314
+ // plugin spec or cron name. payload holds the kind-specific fields; an env
315
+ // item's payload.value is AES-256-GCM encrypted (see
316
+ // admin/src/agent-template-items.ts).
317
+
318
+ model AgentTemplateItem {
319
+ id String @id @default(cuid())
320
+ templateId String
321
+ template AgentTemplate @relation(fields: [templateId], references: [id], onDelete: Cascade)
322
+ kind String
323
+ key String
324
+ payload Json @default("{}")
325
+ createdAt DateTime @default(now())
326
+ updatedAt DateTime @updatedAt
327
+
328
+ @@unique([templateId, kind, key])
272
329
  }
273
330
 
274
331
  model AccountMember {
package/src/admin-boot.ts CHANGED
@@ -83,6 +83,8 @@ import { AgentGitHubInstallationsService } from "./agent-github-installations.ts
83
83
  import { AgentMarketplaceService } from "./agent-marketplaces.ts";
84
84
  import { AgentMemberService } from "./agent-members.ts";
85
85
  import { AgentPluginService } from "./agent-plugins.ts";
86
+ import { AgentTemplateService } from "./agent-templates.ts";
87
+ import { createAgentTemplatesApp } from "./agent-templates-api.ts";
86
88
  import { AgentTokenService } from "./agent-tokens.ts";
87
89
  import { AgentToolService } from "./agent-tools.ts";
88
90
  import { AgentService } from "./agents.ts";
@@ -575,6 +577,22 @@ export async function startAdmin(
575
577
  }),
576
578
  );
577
579
 
580
+ // 3b''. Agent templates API — /templates/* — admin or account-scoped (ATP-1.3)
581
+ root.route(
582
+ "/",
583
+ createAgentTemplatesApp({
584
+ templateService: new AgentTemplateService(
585
+ prisma,
586
+ crypto,
587
+ specialtyRegistry,
588
+ ),
589
+ callerScopeResolver,
590
+ sessionSecret,
591
+ adminApiKeys,
592
+ agentTokenService,
593
+ }),
594
+ );
595
+
578
596
  // 3b'. GitHub Enterprise Apps API — /github-enterprise/* — admin-only,
579
597
  // optional (GHE-1.3). With no rows configured it reports unconfigured
580
598
  // and does nothing else. Strict crypto: no plain-text key storage.
@@ -185,6 +185,7 @@ function makeMockDeps(overrides?: Partial<AdminUIDeps>): AdminUIDeps {
185
185
  add: async (agentId: string, pattern: string) => ({
186
186
  id: "tool1",
187
187
  agentId,
188
+ source: "custom",
188
189
  pattern,
189
190
  enabled: true,
190
191
  createdAt: new Date(),
@@ -217,6 +218,7 @@ function makeMockDeps(overrides?: Partial<AdminUIDeps>): AdminUIDeps {
217
218
  add: async (agentId: string, name: string) => ({
218
219
  id: "plugin1",
219
220
  agentId,
221
+ source: "custom",
220
222
  name,
221
223
  version: null,
222
224
  enabled: true,
package/src/admin-spec.ts CHANGED
@@ -18,6 +18,7 @@
18
18
  */
19
19
 
20
20
  import { NoopAgentProvisioner } from "./agent-provisioner.ts";
21
+ import { createAgentTemplatesApp } from "./agent-templates-api.ts";
21
22
  import {
22
23
  type AdminDeps,
23
24
  createAdminApp,
@@ -190,6 +191,22 @@ export function buildPlatformAdminSpec(): AdminOpenApiDocument {
190
191
  mergedPaths[path] = def as Record<string, unknown>;
191
192
  }
192
193
 
194
+ // ATP-1.3: the /templates routes live in their own app (mounted at the root
195
+ // in admin-boot.ts); fold their paths and schemas in.
196
+ const templatesSpec = createAgentTemplatesApp({
197
+ templateService: {} as never,
198
+ callerScopeResolver: async () => ({ kind: "all" }),
199
+ sessionSecret: SESSION_SECRET,
200
+ adminApiKeys,
201
+ agentTokenService: { validate: async () => null },
202
+ }).getOpenAPI31Document({
203
+ openapi: "3.1.0",
204
+ info: { title: "templates (internal)", version: "0.1.0" },
205
+ });
206
+ for (const [path, def] of Object.entries(templatesSpec.paths ?? {})) {
207
+ mergedPaths[path] = def as Record<string, unknown>;
208
+ }
209
+
193
210
  return {
194
211
  ...adminSpec,
195
212
  paths: mergedPaths,
@@ -199,6 +216,7 @@ export function buildPlatformAdminSpec(): AdminOpenApiDocument {
199
216
  ...(adminSpec.components?.schemas ?? {}),
200
217
  ...(runtimeSpec.components?.schemas ?? {}),
201
218
  ...(gheSpec.components?.schemas ?? {}),
219
+ ...(templatesSpec.components?.schemas ?? {}),
202
220
  },
203
221
  },
204
222
  };
@@ -42,6 +42,7 @@ export const TOKEN_ID = "token-test-abc";
42
42
  export const MOCK_CRON = {
43
43
  id: CRON_ID,
44
44
  agentId: AGENT_ID,
45
+ source: "custom",
45
46
  schedule: "0 * * * *",
46
47
  prompt: "check status",
47
48
  channel: "C123456",
@@ -62,6 +63,7 @@ export const MOCK_CRON = {
62
63
  export const MOCK_TOOL = {
63
64
  id: TOOL_ID,
64
65
  agentId: AGENT_ID,
66
+ source: "custom",
65
67
  pattern: "Bash(git:*)",
66
68
  enabled: true,
67
69
  createdAt: new Date("2024-01-01"),
@@ -310,6 +312,7 @@ export function makeMockDeps(
310
312
  add: async (agentId: string, name: string) => ({
311
313
  id: "p1",
312
314
  agentId,
315
+ source: "custom",
313
316
  name,
314
317
  version: null,
315
318
  enabled: true,
@@ -5849,6 +5849,7 @@ describe("admin UI — create agent seeds type tools and extension plugins", ()
5849
5849
  return {
5850
5850
  id: "p1",
5851
5851
  agentId,
5852
+ source: "custom",
5852
5853
  name,
5853
5854
  version: null,
5854
5855
  enabled: true,
@@ -5894,6 +5895,7 @@ describe("admin UI — create agent seeds type tools and extension plugins", ()
5894
5895
  return {
5895
5896
  id: "p1",
5896
5897
  agentId,
5898
+ source: "custom",
5897
5899
  name,
5898
5900
  version: null,
5899
5901
  enabled: true,