@app-vitals/agent-admin 1.40.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.
@@ -4062,6 +4062,159 @@
4062
4062
  "required": [
4063
4063
  "agentId"
4064
4064
  ]
4065
+ },
4066
+ "AgentTemplatesList": {
4067
+ "type": "object",
4068
+ "properties": {
4069
+ "templates": {
4070
+ "type": "array",
4071
+ "items": {
4072
+ "$ref": "#/components/schemas/AgentTemplate"
4073
+ }
4074
+ }
4075
+ },
4076
+ "required": [
4077
+ "templates"
4078
+ ]
4079
+ },
4080
+ "AgentTemplate": {
4081
+ "type": "object",
4082
+ "properties": {
4083
+ "id": {
4084
+ "type": "string",
4085
+ "example": "clx1234567890"
4086
+ },
4087
+ "accountId": {
4088
+ "type": [
4089
+ "string",
4090
+ "null"
4091
+ ],
4092
+ "example": null
4093
+ },
4094
+ "specialty": {
4095
+ "type": [
4096
+ "string",
4097
+ "null"
4098
+ ],
4099
+ "example": "specialist"
4100
+ },
4101
+ "items": {
4102
+ "type": "array",
4103
+ "items": {
4104
+ "$ref": "#/components/schemas/TemplateItem"
4105
+ }
4106
+ },
4107
+ "createdAt": {
4108
+ "type": "string",
4109
+ "format": "date-time",
4110
+ "example": "2026-01-01T00:00:00.000Z"
4111
+ },
4112
+ "updatedAt": {
4113
+ "type": "string",
4114
+ "format": "date-time",
4115
+ "example": "2026-01-01T00:00:00.000Z"
4116
+ }
4117
+ },
4118
+ "required": [
4119
+ "id",
4120
+ "accountId",
4121
+ "specialty",
4122
+ "items",
4123
+ "createdAt",
4124
+ "updatedAt"
4125
+ ]
4126
+ },
4127
+ "TemplateItem": {
4128
+ "type": "object",
4129
+ "properties": {
4130
+ "kind": {
4131
+ "$ref": "#/components/schemas/TemplateItemKind"
4132
+ },
4133
+ "key": {
4134
+ "type": "string",
4135
+ "description": "Env var name, tool pattern, plugin name or cron name (cron items need a stable, non-empty name).",
4136
+ "example": "LINEAR_API_KEY"
4137
+ },
4138
+ "payload": {
4139
+ "type": "object",
4140
+ "additionalProperties": {},
4141
+ "description": "Secret env values are returned masked as \"***\"."
4142
+ },
4143
+ "updatedAt": {
4144
+ "type": "string",
4145
+ "format": "date-time",
4146
+ "example": "2026-01-01T00:00:00.000Z"
4147
+ }
4148
+ },
4149
+ "required": [
4150
+ "kind",
4151
+ "key",
4152
+ "payload",
4153
+ "updatedAt"
4154
+ ]
4155
+ },
4156
+ "TemplateItemKind": {
4157
+ "type": "string",
4158
+ "enum": [
4159
+ "env",
4160
+ "tool",
4161
+ "plugin",
4162
+ "cron"
4163
+ ]
4164
+ },
4165
+ "PutTemplateBody": {
4166
+ "type": "object",
4167
+ "properties": {
4168
+ "accountId": {
4169
+ "type": [
4170
+ "string",
4171
+ "null"
4172
+ ],
4173
+ "description": "Owning account; null or omitted = deployment-wide (platform admins only). Account callers may omit it or send their own account."
4174
+ },
4175
+ "specialty": {
4176
+ "type": [
4177
+ "string",
4178
+ "null"
4179
+ ],
4180
+ "description": "Specialty the template applies to; null = every specialty."
4181
+ },
4182
+ "items": {
4183
+ "type": "array",
4184
+ "items": {
4185
+ "$ref": "#/components/schemas/TemplateItemInput"
4186
+ }
4187
+ }
4188
+ },
4189
+ "required": [
4190
+ "items"
4191
+ ]
4192
+ },
4193
+ "TemplateItemInput": {
4194
+ "type": "object",
4195
+ "properties": {
4196
+ "kind": {
4197
+ "$ref": "#/components/schemas/TemplateItemKind"
4198
+ },
4199
+ "key": {
4200
+ "type": "string",
4201
+ "description": "Env var name, tool pattern, plugin name or cron name (cron items need a stable, non-empty name).",
4202
+ "example": "LINEAR_API_KEY"
4203
+ },
4204
+ "payload": {
4205
+ "type": "object",
4206
+ "additionalProperties": {},
4207
+ "description": "Kind-specific fields. env: {value, secret?}; tool: {enabled?}; plugin: {version?, enabled?}; cron: {schedule, prompt, channel?, user?, silent?, enabled?, preCheck?}.",
4208
+ "example": {
4209
+ "value": "lin_abc",
4210
+ "secret": true
4211
+ }
4212
+ }
4213
+ },
4214
+ "required": [
4215
+ "kind",
4216
+ "key"
4217
+ ]
4065
4218
  }
4066
4219
  },
4067
4220
  "parameters": {}
@@ -8072,6 +8225,437 @@
8072
8225
  }
8073
8226
  }
8074
8227
  }
8228
+ },
8229
+ "/templates": {
8230
+ "get": {
8231
+ "tags": [
8232
+ "templates"
8233
+ ],
8234
+ "summary": "List agent templates",
8235
+ "description": "Platform admins see every template (optionally narrowed by `accountId` / `specialty`); account callers see only their account's. Secret env values are masked as `***`.",
8236
+ "parameters": [
8237
+ {
8238
+ "schema": {
8239
+ "type": "string",
8240
+ "example": "clx1234567890"
8241
+ },
8242
+ "required": false,
8243
+ "name": "accountId",
8244
+ "in": "query"
8245
+ },
8246
+ {
8247
+ "schema": {
8248
+ "type": "string",
8249
+ "example": "specialist"
8250
+ },
8251
+ "required": false,
8252
+ "name": "specialty",
8253
+ "in": "query"
8254
+ }
8255
+ ],
8256
+ "responses": {
8257
+ "200": {
8258
+ "description": "Templates",
8259
+ "content": {
8260
+ "application/json": {
8261
+ "schema": {
8262
+ "$ref": "#/components/schemas/AgentTemplatesList"
8263
+ }
8264
+ }
8265
+ }
8266
+ },
8267
+ "401": {
8268
+ "description": "Unauthorized",
8269
+ "content": {
8270
+ "application/json": {
8271
+ "schema": {
8272
+ "$ref": "#/components/schemas/Error"
8273
+ }
8274
+ }
8275
+ }
8276
+ },
8277
+ "403": {
8278
+ "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
8279
+ "content": {
8280
+ "application/json": {
8281
+ "schema": {
8282
+ "$ref": "#/components/schemas/Error"
8283
+ }
8284
+ }
8285
+ }
8286
+ },
8287
+ "404": {
8288
+ "description": "Template not found (or not in the caller's account)",
8289
+ "content": {
8290
+ "application/json": {
8291
+ "schema": {
8292
+ "$ref": "#/components/schemas/Error"
8293
+ }
8294
+ }
8295
+ }
8296
+ }
8297
+ }
8298
+ },
8299
+ "put": {
8300
+ "tags": [
8301
+ "templates"
8302
+ ],
8303
+ "summary": "Create or replace an agent template",
8304
+ "description": "Creates the template for the (accountId, specialty) scope, or replaces the items of the existing one (201 / 200). Account callers may only write their own account (403 otherwise); only platform admins write deployment-wide templates. 422 for an unknown specialty, a denylisted env key (per-agent credentials: Slack tokens, GH_TOKEN, Anthropic credentials, task-store URL/token), an invalid item payload, a cron item without a name key, or a duplicate (kind, key). Env values are encrypted at rest; a secret env item sent as `\"***\"` keeps its stored value.",
8305
+ "requestBody": {
8306
+ "content": {
8307
+ "application/json": {
8308
+ "schema": {
8309
+ "$ref": "#/components/schemas/PutTemplateBody"
8310
+ }
8311
+ }
8312
+ }
8313
+ },
8314
+ "responses": {
8315
+ "200": {
8316
+ "description": "Template replaced",
8317
+ "content": {
8318
+ "application/json": {
8319
+ "schema": {
8320
+ "$ref": "#/components/schemas/AgentTemplate"
8321
+ }
8322
+ }
8323
+ }
8324
+ },
8325
+ "201": {
8326
+ "description": "Template created",
8327
+ "content": {
8328
+ "application/json": {
8329
+ "schema": {
8330
+ "$ref": "#/components/schemas/AgentTemplate"
8331
+ }
8332
+ }
8333
+ }
8334
+ },
8335
+ "400": {
8336
+ "description": "Bad request",
8337
+ "content": {
8338
+ "application/json": {
8339
+ "schema": {
8340
+ "$ref": "#/components/schemas/Error"
8341
+ }
8342
+ }
8343
+ }
8344
+ },
8345
+ "401": {
8346
+ "description": "Unauthorized",
8347
+ "content": {
8348
+ "application/json": {
8349
+ "schema": {
8350
+ "$ref": "#/components/schemas/Error"
8351
+ }
8352
+ }
8353
+ }
8354
+ },
8355
+ "403": {
8356
+ "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
8357
+ "content": {
8358
+ "application/json": {
8359
+ "schema": {
8360
+ "$ref": "#/components/schemas/Error"
8361
+ }
8362
+ }
8363
+ }
8364
+ },
8365
+ "404": {
8366
+ "description": "Template not found (or not in the caller's account)",
8367
+ "content": {
8368
+ "application/json": {
8369
+ "schema": {
8370
+ "$ref": "#/components/schemas/Error"
8371
+ }
8372
+ }
8373
+ }
8374
+ },
8375
+ "422": {
8376
+ "description": "Validation failed",
8377
+ "content": {
8378
+ "application/json": {
8379
+ "schema": {
8380
+ "$ref": "#/components/schemas/Error"
8381
+ }
8382
+ }
8383
+ }
8384
+ }
8385
+ }
8386
+ }
8387
+ },
8388
+ "/templates/{id}": {
8389
+ "get": {
8390
+ "tags": [
8391
+ "templates"
8392
+ ],
8393
+ "summary": "Get an agent template",
8394
+ "description": "Returns the template with its items. Secret env values are masked as `***`; non-secret ones are returned in clear.",
8395
+ "parameters": [
8396
+ {
8397
+ "schema": {
8398
+ "type": "string"
8399
+ },
8400
+ "required": true,
8401
+ "name": "id",
8402
+ "in": "path"
8403
+ }
8404
+ ],
8405
+ "responses": {
8406
+ "200": {
8407
+ "description": "Template",
8408
+ "content": {
8409
+ "application/json": {
8410
+ "schema": {
8411
+ "$ref": "#/components/schemas/AgentTemplate"
8412
+ }
8413
+ }
8414
+ }
8415
+ },
8416
+ "401": {
8417
+ "description": "Unauthorized",
8418
+ "content": {
8419
+ "application/json": {
8420
+ "schema": {
8421
+ "$ref": "#/components/schemas/Error"
8422
+ }
8423
+ }
8424
+ }
8425
+ },
8426
+ "403": {
8427
+ "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
8428
+ "content": {
8429
+ "application/json": {
8430
+ "schema": {
8431
+ "$ref": "#/components/schemas/Error"
8432
+ }
8433
+ }
8434
+ }
8435
+ },
8436
+ "404": {
8437
+ "description": "Template not found (or not in the caller's account)",
8438
+ "content": {
8439
+ "application/json": {
8440
+ "schema": {
8441
+ "$ref": "#/components/schemas/Error"
8442
+ }
8443
+ }
8444
+ }
8445
+ }
8446
+ }
8447
+ },
8448
+ "delete": {
8449
+ "tags": [
8450
+ "templates"
8451
+ ],
8452
+ "summary": "Delete an agent template",
8453
+ "description": "Deletes the template and all of its items.",
8454
+ "parameters": [
8455
+ {
8456
+ "schema": {
8457
+ "type": "string"
8458
+ },
8459
+ "required": true,
8460
+ "name": "id",
8461
+ "in": "path"
8462
+ }
8463
+ ],
8464
+ "responses": {
8465
+ "204": {
8466
+ "description": "Template deleted"
8467
+ },
8468
+ "401": {
8469
+ "description": "Unauthorized",
8470
+ "content": {
8471
+ "application/json": {
8472
+ "schema": {
8473
+ "$ref": "#/components/schemas/Error"
8474
+ }
8475
+ }
8476
+ }
8477
+ },
8478
+ "403": {
8479
+ "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
8480
+ "content": {
8481
+ "application/json": {
8482
+ "schema": {
8483
+ "$ref": "#/components/schemas/Error"
8484
+ }
8485
+ }
8486
+ }
8487
+ },
8488
+ "404": {
8489
+ "description": "Template not found (or not in the caller's account)",
8490
+ "content": {
8491
+ "application/json": {
8492
+ "schema": {
8493
+ "$ref": "#/components/schemas/Error"
8494
+ }
8495
+ }
8496
+ }
8497
+ }
8498
+ }
8499
+ }
8500
+ },
8501
+ "/templates/{id}/items": {
8502
+ "put": {
8503
+ "tags": [
8504
+ "templates"
8505
+ ],
8506
+ "summary": "Add or replace a template item",
8507
+ "description": "Upserts one item by (kind, key) without touching the others. Same validation as PUT /templates (422).",
8508
+ "parameters": [
8509
+ {
8510
+ "schema": {
8511
+ "type": "string"
8512
+ },
8513
+ "required": true,
8514
+ "name": "id",
8515
+ "in": "path"
8516
+ }
8517
+ ],
8518
+ "requestBody": {
8519
+ "content": {
8520
+ "application/json": {
8521
+ "schema": {
8522
+ "$ref": "#/components/schemas/TemplateItemInput"
8523
+ }
8524
+ }
8525
+ }
8526
+ },
8527
+ "responses": {
8528
+ "200": {
8529
+ "description": "Template with the item applied",
8530
+ "content": {
8531
+ "application/json": {
8532
+ "schema": {
8533
+ "$ref": "#/components/schemas/AgentTemplate"
8534
+ }
8535
+ }
8536
+ }
8537
+ },
8538
+ "400": {
8539
+ "description": "Bad request",
8540
+ "content": {
8541
+ "application/json": {
8542
+ "schema": {
8543
+ "$ref": "#/components/schemas/Error"
8544
+ }
8545
+ }
8546
+ }
8547
+ },
8548
+ "401": {
8549
+ "description": "Unauthorized",
8550
+ "content": {
8551
+ "application/json": {
8552
+ "schema": {
8553
+ "$ref": "#/components/schemas/Error"
8554
+ }
8555
+ }
8556
+ }
8557
+ },
8558
+ "403": {
8559
+ "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
8560
+ "content": {
8561
+ "application/json": {
8562
+ "schema": {
8563
+ "$ref": "#/components/schemas/Error"
8564
+ }
8565
+ }
8566
+ }
8567
+ },
8568
+ "404": {
8569
+ "description": "Template not found (or not in the caller's account)",
8570
+ "content": {
8571
+ "application/json": {
8572
+ "schema": {
8573
+ "$ref": "#/components/schemas/Error"
8574
+ }
8575
+ }
8576
+ }
8577
+ },
8578
+ "422": {
8579
+ "description": "Validation failed",
8580
+ "content": {
8581
+ "application/json": {
8582
+ "schema": {
8583
+ "$ref": "#/components/schemas/Error"
8584
+ }
8585
+ }
8586
+ }
8587
+ }
8588
+ }
8589
+ },
8590
+ "delete": {
8591
+ "tags": [
8592
+ "templates"
8593
+ ],
8594
+ "summary": "Remove a template item",
8595
+ "description": "Removes the item identified by the `kind` and `key` query params (a query rather than a path segment because plugin and tool keys can contain `/`). 404 when it does not exist.",
8596
+ "parameters": [
8597
+ {
8598
+ "schema": {
8599
+ "type": "string"
8600
+ },
8601
+ "required": true,
8602
+ "name": "id",
8603
+ "in": "path"
8604
+ },
8605
+ {
8606
+ "schema": {
8607
+ "$ref": "#/components/schemas/TemplateItemKind"
8608
+ },
8609
+ "required": true,
8610
+ "name": "kind",
8611
+ "in": "query"
8612
+ },
8613
+ {
8614
+ "schema": {
8615
+ "type": "string",
8616
+ "minLength": 1
8617
+ },
8618
+ "required": true,
8619
+ "name": "key",
8620
+ "in": "query"
8621
+ }
8622
+ ],
8623
+ "responses": {
8624
+ "204": {
8625
+ "description": "Item removed"
8626
+ },
8627
+ "401": {
8628
+ "description": "Unauthorized",
8629
+ "content": {
8630
+ "application/json": {
8631
+ "schema": {
8632
+ "$ref": "#/components/schemas/Error"
8633
+ }
8634
+ }
8635
+ }
8636
+ },
8637
+ "403": {
8638
+ "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
8639
+ "content": {
8640
+ "application/json": {
8641
+ "schema": {
8642
+ "$ref": "#/components/schemas/Error"
8643
+ }
8644
+ }
8645
+ }
8646
+ },
8647
+ "404": {
8648
+ "description": "Template not found (or not in the caller's account)",
8649
+ "content": {
8650
+ "application/json": {
8651
+ "schema": {
8652
+ "$ref": "#/components/schemas/Error"
8653
+ }
8654
+ }
8655
+ }
8656
+ }
8657
+ }
8658
+ }
8075
8659
  }
8076
8660
  },
8077
8661
  "webhooks": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.40.0",
3
+ "version": "1.41.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@anthropic-ai/sdk": "0.135.0",
45
- "@app-vitals/agent-lib": "1.40.0",
45
+ "@app-vitals/agent-lib": "1.41.0",
46
46
  "@hono/zod-openapi": "^1.0.0",
47
47
  "@prisma/adapter-pg": "^7.10.0",
48
48
  "@prisma/client": "^7.10.0",
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.
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
  };