@app-vitals/agent-admin 1.55.0 → 1.57.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.
@@ -5,6 +5,8 @@
5
5
 
6
6
  import { describe, expect, it } from "bun:test";
7
7
  import {
8
+ AGENT_TEMPLATE_ITEM_KINDS,
9
+ assertMarketplaceTemplateItem,
8
10
  assertTemplateEnvKeyAllowed,
9
11
  openTemplateItemPayload,
10
12
  sealTemplateItemPayload,
@@ -68,3 +70,54 @@ describe("assertTemplateEnvKeyAllowed", () => {
68
70
  expect(() => assertTemplateEnvKeyAllowed("LINEAR_API_KEY")).not.toThrow();
69
71
  });
70
72
  });
73
+
74
+ describe("marketplace template items", () => {
75
+ it("lists marketplace as an item kind and stores it unencrypted", () => {
76
+ expect(AGENT_TEMPLATE_ITEM_KINDS).toContain("marketplace");
77
+ const payload = { source: "example-org/plugins", ref: "v1" };
78
+ expect(sealTemplateItemPayload("marketplace", payload, crypto)).toBe(
79
+ payload,
80
+ );
81
+ expect(openTemplateItemPayload("marketplace", payload, crypto)).toBe(
82
+ payload,
83
+ );
84
+ });
85
+
86
+ it("accepts a valid name, source and ref (ref optional or null)", () => {
87
+ expect(() =>
88
+ assertMarketplaceTemplateItem("example-plugins", {
89
+ source: "example-org/plugins",
90
+ }),
91
+ ).not.toThrow();
92
+ expect(() =>
93
+ assertMarketplaceTemplateItem("m.1_x", {
94
+ source: "https://git.example.com/org/repo.git",
95
+ ref: null,
96
+ }),
97
+ ).not.toThrow();
98
+ expect(() =>
99
+ assertMarketplaceTemplateItem("m", { source: "o/r", ref: "main" }),
100
+ ).not.toThrow();
101
+ });
102
+
103
+ it("returns the per-agent API's 422 messages", () => {
104
+ expect(() =>
105
+ assertMarketplaceTemplateItem("m", {
106
+ source: "https://user:pw@example.com/o/r",
107
+ }),
108
+ ).toThrow(
109
+ "source must be a GitHub 'owner/repo' or an https git URL without credentials",
110
+ );
111
+ expect(() =>
112
+ assertMarketplaceTemplateItem("m", { source: "not a repo" }),
113
+ ).toThrow(UnprocessableEntityError);
114
+ expect(() =>
115
+ assertMarketplaceTemplateItem("-bad name", { source: "o/r" }),
116
+ ).toThrow(
117
+ "name must start with a letter or digit and contain only letters, digits, '.', '_' and '-'",
118
+ );
119
+ expect(() =>
120
+ assertMarketplaceTemplateItem("m", { source: "o/r", ref: "a..b" }),
121
+ ).toThrow("ref must be a plain branch, tag or sha");
122
+ });
123
+ });
@@ -74,6 +74,7 @@ export function mergeTemplateLayers(
74
74
  tool: new Map(),
75
75
  plugin: new Map(),
76
76
  cron: new Map(),
77
+ marketplace: new Map(),
77
78
  };
78
79
  const ordered = [...layers].sort(
79
80
  (a, b) =>
@@ -181,3 +181,53 @@ describe("resolveSpecialtyDefaultSet", () => {
181
181
  expect(resolveSpecialtyDefaultSet("nope", registry)).toBeUndefined();
182
182
  });
183
183
  });
184
+
185
+ describe("mergeTemplateLayers: marketplace items", () => {
186
+ const mk = (source: string) => ({
187
+ kind: "marketplace" as const,
188
+ key: "example-plugins",
189
+ payload: { source },
190
+ });
191
+ const winner = (layers: TemplateLayerInput[]) =>
192
+ mergeTemplateLayers(layers).marketplace.get("example-plugins");
193
+
194
+ it("applies the plugin layer precedence, narrowest layer wins", () => {
195
+ const layers: TemplateLayerInput[] = [
196
+ { layer: "account", items: [mk("o/3")] },
197
+ { layer: "account-specialty", items: [mk("o/4")] },
198
+ { layer: "deployment", items: [mk("o/1")] },
199
+ { layer: "specialty-default", items: [mk("o/0")] },
200
+ { layer: "deployment-specialty", items: [mk("o/2")] },
201
+ ];
202
+ expect(winner(layers)).toEqual({
203
+ kind: "marketplace",
204
+ key: "example-plugins",
205
+ payload: { source: "o/4" },
206
+ layer: "account-specialty",
207
+ });
208
+ const without = (...drop: string[]) =>
209
+ layers.filter((l) => !drop.includes(l.layer));
210
+ expect(winner(without("account-specialty"))?.payload.source).toBe("o/3");
211
+ expect(
212
+ winner(without("account-specialty", "account"))?.payload.source,
213
+ ).toBe("o/2");
214
+ expect(
215
+ winner(without("account-specialty", "account", "deployment-specialty"))
216
+ ?.payload.source,
217
+ ).toBe("o/1");
218
+ });
219
+
220
+ it("keeps marketplaces separate from plugins of the same key", () => {
221
+ const merged = mergeTemplateLayers([
222
+ {
223
+ layer: "deployment",
224
+ items: [
225
+ mk("o/1"),
226
+ { kind: "plugin", key: "example-plugins", payload: {} },
227
+ ],
228
+ },
229
+ ]);
230
+ expect(merged.marketplace.size).toBe(1);
231
+ expect(merged.plugin.size).toBe(1);
232
+ });
233
+ });
@@ -84,7 +84,13 @@ export interface TemplateReconcileResult {
84
84
  /** "detached" / "unknown_specialty": nothing was written. */
85
85
  status: "reconciled" | "detached" | "unknown_specialty";
86
86
  /** Template-tracked rows (system crons are counted in `systemCrons`). */
87
- counts: Record<AgentTemplateItemKind, TemplateReconcileCounts>;
87
+ counts: Record<
88
+ Exclude<AgentTemplateItemKind, "marketplace">,
89
+ TemplateReconcileCounts
90
+ > & {
91
+ /** TMK-2.3: present once the marketplace reconcile lands (additive). */
92
+ marketplace?: TemplateReconcileCounts;
93
+ };
88
94
  systemCrons: { created: number; updated: number; deleted: number };
89
95
  /** Template items deliberately not applied. */
90
96
  conflicts: TemplateReconcileConflict[];
@@ -175,6 +175,86 @@ describeOrSkip("/templates (integration)", () => {
175
175
  });
176
176
  });
177
177
 
178
+ describe("marketplace items", () => {
179
+ const mkt = (key: string, payload: Record<string, unknown>) => ({
180
+ kind: "marketplace",
181
+ key,
182
+ payload,
183
+ });
184
+
185
+ it("round-trips a marketplace item unchanged", async () => {
186
+ const item = mkt("example-plugins", { source: "example-org/plugins" });
187
+ const put = await call("PUT", "/templates", admin, { items: [item] });
188
+ expect([200, 201]).toContain(put.status);
189
+ const list = (await (await call("GET", "/templates", admin)).json()) as {
190
+ templates: {
191
+ items: { kind: string; key: string; payload: unknown }[];
192
+ }[];
193
+ };
194
+ const got = list.templates[0]?.items.find(
195
+ (i) => i.kind === "marketplace",
196
+ );
197
+ expect(got).toMatchObject(item);
198
+ const { id } = (await put.json()) as { id: string };
199
+ const row = await prisma.agentTemplateItem.findFirstOrThrow({
200
+ where: { templateId: id, kind: "marketplace" },
201
+ });
202
+ expect(row.payload).toEqual({ source: "example-org/plugins" });
203
+ });
204
+
205
+ it("supports item upsert and delete", async () => {
206
+ const put = await call("PUT", "/templates", admin, { items: [] });
207
+ const { id } = (await put.json()) as { id: string };
208
+ const up = await call(
209
+ "PUT",
210
+ `/templates/${id}/items`,
211
+ admin,
212
+ mkt("m1", { source: "o/r", ref: "v1" }),
213
+ );
214
+ expect(up.status).toBe(200);
215
+ const del = await call(
216
+ "DELETE",
217
+ `/templates/${id}/items?kind=marketplace&key=m1`,
218
+ admin,
219
+ );
220
+ expect(del.status).toBeLessThan(300);
221
+ expect(await prisma.agentTemplateItem.count()).toBe(0);
222
+ });
223
+
224
+ it.each([
225
+ ["credentials in source", "m", { source: "https://u:p@example.com/o/r" }],
226
+ ["malformed owner/repo", "m", { source: "not a repo" }],
227
+ ["invalid name", "-bad name", { source: "o/r" }],
228
+ ["invalid ref", "m", { source: "o/r", ref: "a..b" }],
229
+ ])("422 for %s", async (_label, key, payload) => {
230
+ const res = await call("PUT", "/templates", admin, {
231
+ items: [mkt(key, payload)],
232
+ });
233
+ expect(res.status).toBe(422);
234
+ expect(await prisma.agentTemplate.count()).toBe(0);
235
+ });
236
+
237
+ it("422 for a duplicate marketplace key in one body", async () => {
238
+ const item = mkt("m", { source: "o/r" });
239
+ const res = await call("PUT", "/templates", admin, {
240
+ items: [item, item],
241
+ });
242
+ expect(res.status).toBe(422);
243
+ });
244
+
245
+ it("403 for an account caller writing another account or the deployment template", async () => {
246
+ const b = await cookie("b@example.com");
247
+ const items = [mkt("m", { source: "o/r" })];
248
+ expect(
249
+ (await call("PUT", "/templates", b, { accountId: accountA, items }))
250
+ .status,
251
+ ).toBe(403);
252
+ expect(
253
+ (await call("PUT", "/templates", b, { accountId: null, items })).status,
254
+ ).toBe(403);
255
+ });
256
+ });
257
+
178
258
  describe("crypto and masking", () => {
179
259
  it("encrypts env values at rest and masks secrets on GET", async () => {
180
260
  const put = await call("PUT", "/templates", admin, {
@@ -102,7 +102,7 @@ const putTemplateRoute = createRoute({
102
102
  tags: ["templates"],
103
103
  summary: "Create or replace an agent template",
104
104
  description:
105
- '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.',
105
+ '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, a marketplace item with an invalid name, source or ref (same messages as POST /agents/:id/marketplaces), or a duplicate (kind, key). Env values are encrypted at rest; a secret env item sent as `"***"` keeps its stored value.',
106
106
  request: {
107
107
  body: {
108
108
  content: { "application/json": { schema: PutTemplateBodySchema } },
@@ -21,6 +21,7 @@ import { z } from "zod";
21
21
  import type { PrismaClient } from "../prisma/client/client.ts";
22
22
  import {
23
23
  AGENT_TEMPLATE_ITEM_KINDS,
24
+ assertMarketplaceTemplateItem,
24
25
  type AgentTemplateItemKind,
25
26
  assertTemplateEnvKeyAllowed,
26
27
  openTemplateItemPayload,
@@ -92,6 +93,10 @@ const PAYLOAD_SCHEMAS = {
92
93
  enabled: z.boolean().optional(),
93
94
  preCheck: z.string().nullable().optional(),
94
95
  }),
96
+ marketplace: z.object({
97
+ source: z.string(),
98
+ ref: z.string().nullable().optional(),
99
+ }),
95
100
  } satisfies Record<AgentTemplateItemKind, z.ZodType>;
96
101
 
97
102
  /** Validates one item and returns its normalized (still plaintext) payload. */
@@ -129,6 +134,12 @@ export function normalizeTemplateItem(
129
134
  `invalid ${item.kind} item ${key}: ${detail}`,
130
135
  );
131
136
  }
137
+ if (item.kind === "marketplace") {
138
+ assertMarketplaceTemplateItem(
139
+ key,
140
+ parsed.data as { source: string; ref?: string | null },
141
+ );
142
+ }
132
143
  return { kind: item.kind, key, payload: parsed.data };
133
144
  }
134
145
 
package/src/agents-api.ts CHANGED
@@ -61,6 +61,7 @@ import { deleteAgentFully } from "./agent-deletion.ts";
61
61
  import type { AgentEnvService } from "./agent-envs.ts";
62
62
  import type { AgentGitHubInstallationsService } from "./agent-github-installations.ts";
63
63
  import { AgentMarketplaceService } from "./agent-marketplaces.ts";
64
+ import { AGENT_TEMPLATE_ITEM_KINDS } from "./agent-template-items.ts";
64
65
  import type { AgentMemberService } from "./agent-members.ts";
65
66
  import type { AgentPluginService } from "./agent-plugins.ts";
66
67
  import {
@@ -1091,7 +1092,7 @@ const TemplateReconcileResultSchema = z
1091
1092
  }),
1092
1093
  conflicts: z.array(
1093
1094
  z.object({
1094
- kind: z.enum(["env", "tool", "plugin", "cron"]),
1095
+ kind: z.enum(AGENT_TEMPLATE_ITEM_KINDS),
1095
1096
  key: z.string(),
1096
1097
  reason: z.enum([
1097
1098
  "cron_name_conflict",
@@ -1110,7 +1111,7 @@ const TemplateDetachResultSchema = z
1110
1111
 
1111
1112
  const ResetTemplateBodySchema = z
1112
1113
  .object({
1113
- kind: z.enum(["env", "tool", "plugin", "cron"]).optional(),
1114
+ kind: z.enum(AGENT_TEMPLATE_ITEM_KINDS).optional(),
1114
1115
  key: z.string().min(1).optional(),
1115
1116
  })
1116
1117
  .refine((b) => (b.kind === undefined) === (b.key === undefined), {
@@ -3741,11 +3742,14 @@ function serializeMarketplace(row: {
3741
3742
  name: string;
3742
3743
  source: string;
3743
3744
  ref: string | null;
3745
+ rowSource?: string;
3746
+ enabled?: boolean;
3744
3747
  createdAt: Date;
3745
3748
  updatedAt: Date;
3746
3749
  }): z.infer<typeof AgentMarketplaceSchema> {
3747
3750
  return {
3748
3751
  ...row,
3752
+ rowSource: row.rowSource === "template" ? "template" : "custom",
3749
3753
  createdAt: row.createdAt.toISOString(),
3750
3754
  updatedAt: row.updatedAt.toISOString(),
3751
3755
  };
package/src/api.ts CHANGED
@@ -166,9 +166,15 @@ interface AgentPluginServiceLike {
166
166
  }
167
167
 
168
168
  interface AgentMarketplaceServiceLike {
169
- list(
170
- agentId: string,
171
- ): Promise<Array<{ name: string; source: string; ref: string | null }>>;
169
+ list(agentId: string): Promise<
170
+ Array<{
171
+ name: string;
172
+ source: string;
173
+ ref: string | null;
174
+ /** TMK-2.1: false marks a tombstone, which the config bundle omits. */
175
+ enabled?: boolean;
176
+ }>
177
+ >;
172
178
  }
173
179
 
174
180
  export interface AgentPhaseMethodologyServiceLike {
@@ -370,11 +376,13 @@ export function createAgentRuntimeApp(deps: AgentRuntimeDeps): OpenAPIHono {
370
376
  ? { marketplace: "shipwright", plugin: p.name }
371
377
  : { plugin: p.name.slice(0, at), marketplace: p.name.slice(at + 1) };
372
378
  }),
373
- marketplaces: (marketplaceRows ?? []).map((m) => ({
374
- name: m.name,
375
- source: m.source,
376
- ref: m.ref,
377
- })),
379
+ marketplaces: (marketplaceRows ?? [])
380
+ .filter((m) => m.enabled !== false)
381
+ .map((m) => ({
382
+ name: m.name,
383
+ source: m.source,
384
+ ref: m.ref,
385
+ })),
378
386
  repos: agent.repos,
379
387
  reviewAuthorAllowlist: agent.reviewAuthorAllowlist,
380
388
  patchAuthorAllowlist: agent.patchAuthorAllowlist,
@@ -9,6 +9,7 @@
9
9
  import { isGithubLogin } from "@app-vitals/agent-lib/github-login";
10
10
  import { isOrgRepo } from "@app-vitals/agent-lib/org-repo";
11
11
  import { z } from "@hono/zod-openapi";
12
+ import { AGENT_TEMPLATE_ITEM_KINDS } from "./agent-template-items.ts";
12
13
 
13
14
  // ─── Common ───────────────────────────────────────────────────────────────────
14
15
 
@@ -927,6 +928,11 @@ export const AgentMarketplaceSchema = z
927
928
  name: z.string().openapi({ example: "shipwright" }),
928
929
  source: z.string().openapi({ example: "app-vitals/shipwright" }),
929
930
  ref: z.string().nullable().openapi({ example: "main" }),
931
+ rowSource: z
932
+ .enum(["template", "custom"])
933
+ .optional()
934
+ .openapi({ example: "custom" }),
935
+ enabled: z.boolean().optional().openapi({ example: true }),
930
936
  createdAt: z
931
937
  .string()
932
938
  .datetime()
@@ -1561,7 +1567,7 @@ export const PatchAccountBodySchema = z
1561
1567
  // ─── Agent templates (ATP-1.3) ────────────────────────────────────────────────
1562
1568
 
1563
1569
  export const TemplateItemKindSchema = z
1564
- .enum(["env", "tool", "plugin", "cron"])
1570
+ .enum(AGENT_TEMPLATE_ITEM_KINDS)
1565
1571
  .openapi("TemplateItemKind");
1566
1572
 
1567
1573
  const TemplateItemBaseSchema = z.object({
@@ -1576,7 +1582,7 @@ const TemplateItemBaseSchema = z.object({
1576
1582
  .optional()
1577
1583
  .openapi({
1578
1584
  description:
1579
- "Kind-specific fields. env: {value, secret?}; tool: {enabled?}; plugin: {version?, enabled?}; cron: {schedule, prompt, channel?, user?, silent?, enabled?, preCheck?}.",
1585
+ "Kind-specific fields. env: {value, secret?}; tool: {enabled?}; plugin: {version?, enabled?}; cron: {schedule, prompt, channel?, user?, silent?, enabled?, preCheck?}; marketplace: {source, ref?} (key = marketplace name).",
1580
1586
  example: { value: "lin_abc", secret: true },
1581
1587
  }),
1582
1588
  });