@app-vitals/agent-admin 1.127.0 → 1.129.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/src/api.ts CHANGED
@@ -22,6 +22,11 @@
22
22
  import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
23
23
  import type { AgentCronJob } from "./agent-cron-jobs.ts";
24
24
  import type { AgentEnvBundle } from "./agent-envs.ts";
25
+ import {
26
+ type AgentConfigBundleApp,
27
+ type AgentGitHubAppService,
28
+ toConfigBundleApps,
29
+ } from "./agent-github-apps.ts";
25
30
  import type { AgentTokenService } from "./agent-tokens.ts";
26
31
  import { anthropicCredentialKeysIn } from "./anthropic-credential-guard.ts";
27
32
  import {
@@ -37,6 +42,7 @@ import {
37
42
  RuntimeErrorSchema,
38
43
  } from "./openapi-schemas.ts";
39
44
  import {
45
+ blankAppsForToolsToken,
40
46
  blankEnvForToolsToken,
41
47
  type ToolsTokenPolicyRule,
42
48
  } from "./tools-token-policy.ts";
@@ -119,6 +125,11 @@ export interface AgentConfigResponse {
119
125
  features?: {
120
126
  repoAccessCheck: boolean;
121
127
  };
128
+ /**
129
+ * multi-github-apps 1.2: the agent's GitHub Apps with decrypted keys.
130
+ * Optional (additive); absent when the host did not wire the service.
131
+ */
132
+ apps?: AgentConfigBundleApp[];
122
133
  }
123
134
 
124
135
  interface AgentEnvServiceLike {
@@ -190,6 +201,11 @@ export interface AgentPhaseMethodologyServiceLike {
190
201
  }
191
202
 
192
203
  export interface AgentRuntimeDeps {
204
+ /**
205
+ * multi-github-apps 1.2: optional (additive). When supplied the config
206
+ * bundle gains an `apps` array; absent means the member is omitted.
207
+ */
208
+ agentGitHubAppService?: Pick<AgentGitHubAppService, "listCredentials">;
193
209
  agentEnvService: AgentEnvServiceLike;
194
210
  agentCronJobService: AgentCronJobServiceLike;
195
211
  agentService: AgentServiceLike;
@@ -321,13 +337,19 @@ export function createAgentRuntimeApp(deps: AgentRuntimeDeps): OpenAPIHono {
321
337
  }
322
338
 
323
339
  // Fetch env bundle, plugins, and phase-methodology overrides in parallel
324
- const [bundle, plugins, marketplaceRows, phaseMethodologyRows] =
325
- await Promise.all([
326
- agentEnvService.getConfigBundle(id),
327
- agentPluginService.listEnabled(id),
328
- deps.agentMarketplaceService?.list(id),
329
- agentPhaseMethodologyService?.list(id),
330
- ]);
340
+ const [
341
+ bundle,
342
+ plugins,
343
+ marketplaceRows,
344
+ phaseMethodologyRows,
345
+ appCredentials,
346
+ ] = await Promise.all([
347
+ agentEnvService.getConfigBundle(id),
348
+ agentPluginService.listEnabled(id),
349
+ deps.agentMarketplaceService?.list(id),
350
+ agentPhaseMethodologyService?.list(id),
351
+ deps.agentGitHubAppService?.listCredentials(id),
352
+ ]);
331
353
 
332
354
  // WIF-2.1: with federation enabled, a non-self-hosted agent must never be
333
355
  // handed Anthropic credentials, even ones already stored in its bundle
@@ -415,6 +437,17 @@ export function createAgentRuntimeApp(deps: AgentRuntimeDeps): OpenAPIHono {
415
437
  features: {
416
438
  repoAccessCheck: deps.repoAccessCheckEnabled === true,
417
439
  },
440
+ // Keys travel here only (agent-authenticated route), like
441
+ // GH_APP_PRIVATE_KEY in env; tools-kind tokens get none. Omitted when
442
+ // the service is not wired. Legacy GH_APP_* env stays in `env`.
443
+ ...(appCredentials
444
+ ? {
445
+ apps: blankAppsForToolsToken(
446
+ scope,
447
+ toConfigBundleApps(appCredentials),
448
+ ),
449
+ }
450
+ : {}),
418
451
  };
419
452
 
420
453
  // The route's Zod schema requires phaseMethodology; a platform-only admin
@@ -935,6 +935,98 @@ export const UpsertAgentMarketplaceBodySchema = z
935
935
  })
936
936
  .openapi("UpsertAgentMarketplaceBody");
937
937
 
938
+ // ─── AgentGitHubApp ───────────────────────────────────────────────────────────
939
+
940
+ /** Read shape: metadata plus key flags. Keys are write-only and never returned. */
941
+ export const AgentGitHubAppSchema = z
942
+ .object({
943
+ id: z.string().openapi({ example: "clx1234567890" }),
944
+ agentId: z.string().openapi({ example: "clx1234567890" }),
945
+ appId: z.string().openapi({ example: "12345" }),
946
+ slug: z.string().nullable().openapi({ example: "my-app" }),
947
+ clientId: z
948
+ .string()
949
+ .nullable()
950
+ .openapi({ example: "Iv1.abcdef0123456789" }),
951
+ installationId: z.string().nullable().openapi({ example: "9876543" }),
952
+ priority: z.number().int().openapi({ example: 0 }),
953
+ hasPrivateKey: z.boolean().openapi({ example: true }),
954
+ hasClientSecret: z.boolean().openapi({ example: false }),
955
+ createdAt: z
956
+ .string()
957
+ .datetime()
958
+ .openapi({ example: "2026-01-01T00:00:00.000Z" }),
959
+ updatedAt: z
960
+ .string()
961
+ .datetime()
962
+ .openapi({ example: "2026-01-01T00:00:00.000Z" }),
963
+ })
964
+ .openapi("AgentGitHubApp");
965
+
966
+ /** Field formats are validated by AgentGitHubAppService (422), not here. */
967
+ export const CreateAgentGitHubAppBodySchema = z
968
+ .object({
969
+ appId: z.string().openapi({ example: "12345" }),
970
+ slug: z.string().nullable().optional().openapi({ example: "my-app" }),
971
+ clientId: z
972
+ .string()
973
+ .nullable()
974
+ .optional()
975
+ .openapi({ example: "Iv1.abcdef0123456789" }),
976
+ privateKey: z.string().openapi({
977
+ description: "PEM private key. Write-only: never returned.",
978
+ }),
979
+ clientSecret: z.string().nullable().optional().openapi({
980
+ description: "OAuth client secret. Write-only: never returned.",
981
+ }),
982
+ installationId: z
983
+ .string()
984
+ .nullable()
985
+ .optional()
986
+ .openapi({ example: "9876543" }),
987
+ priority: z.number().int().optional().openapi({
988
+ description:
989
+ "Lowest wins when two apps are installed on the same owner. Defaults to one past the agent's highest.",
990
+ example: 0,
991
+ }),
992
+ })
993
+ .openapi("CreateAgentGitHubAppBody");
994
+
995
+ export const UpdateAgentGitHubAppBodySchema = z
996
+ .object({
997
+ slug: z.string().nullable().optional(),
998
+ clientId: z.string().nullable().optional(),
999
+ privateKey: z
1000
+ .string()
1001
+ .optional()
1002
+ .openapi({ description: "Replaces the stored key. Write-only." }),
1003
+ clientSecret: z.string().nullable().optional().openapi({
1004
+ description: "Replaces the stored secret; null clears it. Write-only.",
1005
+ }),
1006
+ installationId: z.string().nullable().optional(),
1007
+ priority: z.number().int().optional(),
1008
+ })
1009
+ .openapi("UpdateAgentGitHubAppBody");
1010
+
1011
+ export const AgentGitHubAppIdParamSchema = z.object({
1012
+ id: z.string().openapi({ example: "clx1234567890" }),
1013
+ appRowId: z.string().openapi({ example: "clx0987654321" }),
1014
+ });
1015
+
1016
+ /** One app in the config bundle. Carries keys: agent-authenticated route only. */
1017
+ export const AgentConfigGitHubAppSchema = z
1018
+ .object({
1019
+ id: z.string(),
1020
+ appId: z.string().openapi({ example: "12345" }),
1021
+ slug: z.string().nullable(),
1022
+ clientId: z.string().nullable(),
1023
+ installationId: z.string().nullable(),
1024
+ priority: z.number().int(),
1025
+ privateKey: z.string(),
1026
+ clientSecret: z.string().nullable(),
1027
+ })
1028
+ .openapi("AgentConfigGitHubApp");
1029
+
938
1030
  // ─── Pipeline phases ────────────────────────────────────────────────────────────
939
1031
  //
940
1032
  // The six pipeline phases a methodology override can target — the keys of the
@@ -1386,6 +1478,13 @@ export const AgentConfigResponseSchema = z
1386
1478
  * always populates it (empty array when the agent has none).
1387
1479
  */
1388
1480
  marketplaces: z.array(AgentConfigMarketplaceSchema).optional(),
1481
+ /**
1482
+ * multi-github-apps 1.2: the agent's GitHub Apps with decrypted keys, in
1483
+ * priority order. Additive and optional; the legacy GH_APP_* env vars stay
1484
+ * in `env` until the runtime reads this (dual-read). Empty for tools-kind
1485
+ * tokens.
1486
+ */
1487
+ apps: z.array(AgentConfigGitHubAppSchema).optional(),
1389
1488
  repos: z.array(z.string()).openapi({ example: ["org/repo1", "org/repo2"] }),
1390
1489
  reviewAuthorAllowlist: z
1391
1490
  .array(z.string())
@@ -200,6 +200,33 @@ export const TOOLS_TOKEN_POLICY: readonly ToolsTokenPolicyRule[] = [
200
200
  subpaths: true,
201
201
  note: "marketplace write",
202
202
  },
203
+ {
204
+ method: "GET",
205
+ path: "/agents/{id}/github-apps",
206
+ decision: A,
207
+ note: "masked read",
208
+ },
209
+ {
210
+ method: "POST",
211
+ path: "/agents/{id}/github-apps",
212
+ decision: D,
213
+ subpaths: true,
214
+ note: "github app write",
215
+ },
216
+ {
217
+ method: "PATCH",
218
+ path: "/agents/{id}/github-apps/{appRowId}",
219
+ decision: D,
220
+ subpaths: true,
221
+ note: "github app write",
222
+ },
223
+ {
224
+ method: "DELETE",
225
+ path: "/agents/{id}/github-apps/{appRowId}",
226
+ decision: D,
227
+ subpaths: true,
228
+ note: "github app write",
229
+ },
203
230
  // Crons: reads allowed; create/PATCH allowed with the preCheck content rule.
204
231
  {
205
232
  method: "POST",
@@ -438,6 +465,9 @@ export const RUNTIME_TOKEN_DENYLIST: readonly ToolsTokenPolicyRule[] = [
438
465
  "marketplace write",
439
466
  true,
440
467
  ),
468
+ RD("POST", "/agents/{id}/github-apps", "github app write", true),
469
+ RD("PATCH", "/agents/{id}/github-apps/{appRowId}", "github app write", true),
470
+ RD("DELETE", "/agents/{id}/github-apps/{appRowId}", "github app write", true),
441
471
  RD("POST", "/agents/{id}/crons", "cron create"),
442
472
  RD("PATCH", "/agents/{id}/crons/{cronId}", "cron update"),
443
473
  RD("DELETE", "/agents/{id}/crons/{cronId}", "cron delete"),
@@ -553,6 +583,14 @@ export function blankEnvForToolsToken(
553
583
  return isToolsKindScope(scope) ? {} : env;
554
584
  }
555
585
 
586
+ /** Config bundle GitHub App keys for the caller: `[]` for tools-kind, unchanged otherwise. */
587
+ export function blankAppsForToolsToken<T>(
588
+ scope: AdminScope | undefined,
589
+ apps: T[],
590
+ ): T[] {
591
+ return isToolsKindScope(scope) ? [] : apps;
592
+ }
593
+
556
594
  // ─── Enforcement ──────────────────────────────────────────────────────────────
557
595
 
558
596
  /**
@@ -384,3 +384,22 @@ describe("runtime-kind enforcement points", () => {
384
384
  });
385
385
  }
386
386
  });
387
+
388
+ describe("github-apps routes", () => {
389
+ const ID = "agent-1";
390
+ for (const [m, p] of [
391
+ ["POST", `/agents/${ID}/github-apps`],
392
+ ["PATCH", `/agents/${ID}/github-apps/row1`],
393
+ ["DELETE", `/agents/${ID}/github-apps/row1`],
394
+ ] as const) {
395
+ it(`denies ${m} ${p} for tools and runtime tokens`, () => {
396
+ expect(toolsTokenDecision(m, p)).toBe("deny");
397
+ expect(runtimeTokenDecision(m, p)).toBe("deny");
398
+ });
399
+ }
400
+ it("allows the masked list read for tools tokens", () => {
401
+ expect(toolsTokenDecision("GET", `/agents/${ID}/github-apps`)).toBe(
402
+ "allow",
403
+ );
404
+ });
405
+ });