@app-vitals/agent-admin 1.109.0 → 1.111.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 (53) hide show
  1. package/openapi.json +0 -193
  2. package/openapi.platform.json +1 -238
  3. package/package.json +2 -2
  4. package/src/admin-boot.ts +6 -5
  5. package/src/admin-ui-github-enterprise-pages.ts +13 -2
  6. package/src/admin-ui-github-enterprise.smoke.test.ts +20 -1
  7. package/src/admin-ui-github-enterprise.ts +16 -1
  8. package/src/admin-ui-github-identity-pages.ts +35 -139
  9. package/src/admin-ui-github-identity-pages.unit.test.ts +50 -173
  10. package/src/admin-ui-github-identity.smoke.test.ts +103 -63
  11. package/src/admin-ui-installation-repos-pages.ts +2 -23
  12. package/src/admin-ui-installation-repos-pages.unit.test.ts +41 -36
  13. package/src/admin-ui-installation-repos.smoke.test.ts +9 -8
  14. package/src/admin-ui-pages.ts +4 -5
  15. package/src/admin-ui-slack-config-token-pages.ts +11 -2
  16. package/src/admin-ui-slack-config-token.smoke.test.ts +39 -3
  17. package/src/admin-ui-slack-config-token.ts +51 -9
  18. package/src/admin-ui-templates-pages.ts +7 -1
  19. package/src/admin-ui-templates.smoke.test.ts +31 -5
  20. package/src/admin-ui-templates.ts +43 -8
  21. package/src/admin-ui.ts +51 -36
  22. package/src/agent-templates-api.integration.test.ts +29 -7
  23. package/src/agent-templates.ts +7 -1
  24. package/src/agents-api.smoke.test.ts +26 -315
  25. package/src/agents-api.ts +1 -107
  26. package/src/deployment-wide-settings.integration.test.ts +309 -0
  27. package/src/deployment-wide-settings.ts +42 -0
  28. package/src/github-access-preview.ts +2 -2
  29. package/src/github-agent-installation-crawler.ts +18 -1
  30. package/src/github-enterprise-api.integration.test.ts +7 -0
  31. package/src/github-enterprise-api.smoke.test.ts +26 -0
  32. package/src/github-enterprise-api.ts +24 -4
  33. package/src/github-enterprise-apps.integration.test.ts +33 -8
  34. package/src/github-enterprise-apps.ts +4 -0
  35. package/src/github-enterprise-client.integration.test.ts +0 -41
  36. package/src/github-enterprise-client.ts +0 -25
  37. package/src/github-enterprise-client.unit.test.ts +0 -18
  38. package/src/github-installation-wiring.ts +48 -13
  39. package/src/github-installation-wiring.unit.test.ts +38 -1
  40. package/src/github-sync-all-repos.unit.test.ts +116 -0
  41. package/src/github-sync-cache.integration.test.ts +9 -2
  42. package/src/github-sync-snapshot-refresh.integration.test.ts +168 -0
  43. package/src/github-sync-snapshot-refresh.unit.test.ts +144 -0
  44. package/src/github-sync.ts +103 -137
  45. package/src/github-sync.unit.test.ts +82 -1
  46. package/src/installation-ports.ts +1 -40
  47. package/src/installation-repos-service.ts +7 -4
  48. package/src/reconcile-open-work.integration.test.ts +0 -1
  49. package/src/slack-config-token.integration.test.ts +19 -2
  50. package/src/slack-config-token.ts +6 -1
  51. package/src/github-access-preview.integration.test.ts +0 -399
  52. package/src/github-sync-switch.integration.test.ts +0 -297
  53. package/src/github-sync-switch.unit.test.ts +0 -467
package/openapi.json CHANGED
@@ -2794,120 +2794,6 @@
2794
2794
  ],
2795
2795
  "additionalProperties": false
2796
2796
  },
2797
- "GithubAccessPreview": {
2798
- "type": "object",
2799
- "properties": {
2800
- "status": {
2801
- "type": "string",
2802
- "enum": [
2803
- "ok",
2804
- "user_not_found",
2805
- "unconfigured"
2806
- ],
2807
- "description": "`unconfigured` when the lookup App or its key is not set (no GitHub call was made). The installer App is optional."
2808
- },
2809
- "access": {
2810
- "type": "object",
2811
- "properties": {
2812
- "username": {
2813
- "type": "string"
2814
- },
2815
- "outcome": {
2816
- "type": "string",
2817
- "enum": [
2818
- "ok",
2819
- "user_not_found"
2820
- ]
2821
- },
2822
- "userVerified": {
2823
- "type": "boolean"
2824
- },
2825
- "orgs": {
2826
- "type": "array",
2827
- "items": {
2828
- "type": "object",
2829
- "properties": {
2830
- "org": {
2831
- "type": "string"
2832
- },
2833
- "status": {
2834
- "type": "string",
2835
- "enum": [
2836
- "ok",
2837
- "lookup_app_not_installed",
2838
- "rate_limited",
2839
- "partial",
2840
- "error"
2841
- ]
2842
- },
2843
- "repos": {
2844
- "type": "array",
2845
- "items": {
2846
- "type": "object",
2847
- "properties": {
2848
- "fullName": {
2849
- "type": "string"
2850
- },
2851
- "level": {
2852
- "type": "string",
2853
- "enum": [
2854
- "admin",
2855
- "maintain",
2856
- "write",
2857
- "triage",
2858
- "read",
2859
- "none"
2860
- ]
2861
- },
2862
- "canPush": {
2863
- "type": "boolean"
2864
- }
2865
- },
2866
- "required": [
2867
- "fullName",
2868
- "level",
2869
- "canPush"
2870
- ]
2871
- }
2872
- },
2873
- "unresolved": {
2874
- "type": "integer"
2875
- }
2876
- },
2877
- "required": [
2878
- "org",
2879
- "status",
2880
- "repos",
2881
- "unresolved"
2882
- ]
2883
- }
2884
- },
2885
- "unresolved": {
2886
- "type": "integer"
2887
- },
2888
- "complete": {
2889
- "type": "boolean"
2890
- },
2891
- "checkedAt": {
2892
- "type": "string"
2893
- }
2894
- },
2895
- "required": [
2896
- "username",
2897
- "outcome",
2898
- "userVerified",
2899
- "orgs",
2900
- "unresolved",
2901
- "complete",
2902
- "checkedAt"
2903
- ],
2904
- "description": "Resolver output; absent when unconfigured."
2905
- }
2906
- },
2907
- "required": [
2908
- "status"
2909
- ]
2910
- },
2911
2797
  "AgentConfigResponse": {
2912
2798
  "type": "object",
2913
2799
  "properties": {
@@ -6297,85 +6183,6 @@
6297
6183
  }
6298
6184
  }
6299
6185
  },
6300
- "/agents/{id}/github-access": {
6301
- "get": {
6302
- "summary": "Preview the repos the agent's bound GitHub user can reach",
6303
- "description": "Platform-admin only (session members, ops keys and agent keys get 403): the response lists repo names the bound user can reach. Read-only; nothing is stored. 404 for an unknown agent; 422 when no githubUsername is bound. Returns `status: unconfigured` (not an error, no GitHub call) when the lookup App is not configured (the installer App is optional), and `status: user_not_found` when the user does not exist on GitHub; otherwise `access` is the resolver output (per-org status, repos with level and canPush, unresolved count, complete flag).",
6304
- "parameters": [
6305
- {
6306
- "schema": {
6307
- "type": "string",
6308
- "example": "clx1234567890"
6309
- },
6310
- "required": true,
6311
- "name": "id",
6312
- "in": "path"
6313
- }
6314
- ],
6315
- "responses": {
6316
- "200": {
6317
- "description": "Access preview",
6318
- "content": {
6319
- "application/json": {
6320
- "schema": {
6321
- "$ref": "#/components/schemas/GithubAccessPreview"
6322
- }
6323
- }
6324
- }
6325
- },
6326
- "401": {
6327
- "description": "Unauthorized",
6328
- "content": {
6329
- "application/json": {
6330
- "schema": {
6331
- "$ref": "#/components/schemas/Error"
6332
- }
6333
- }
6334
- }
6335
- },
6336
- "403": {
6337
- "description": "Platform admin required",
6338
- "content": {
6339
- "application/json": {
6340
- "schema": {
6341
- "$ref": "#/components/schemas/Error"
6342
- }
6343
- }
6344
- }
6345
- },
6346
- "404": {
6347
- "description": "Agent not found",
6348
- "content": {
6349
- "application/json": {
6350
- "schema": {
6351
- "$ref": "#/components/schemas/Error"
6352
- }
6353
- }
6354
- }
6355
- },
6356
- "422": {
6357
- "description": "Agent has no githubUsername",
6358
- "content": {
6359
- "application/json": {
6360
- "schema": {
6361
- "$ref": "#/components/schemas/Error"
6362
- }
6363
- }
6364
- }
6365
- },
6366
- "502": {
6367
- "description": "GitHub unavailable or refused",
6368
- "content": {
6369
- "application/json": {
6370
- "schema": {
6371
- "$ref": "#/components/schemas/Error"
6372
- }
6373
- }
6374
- }
6375
- }
6376
- }
6377
- }
6378
- },
6379
6186
  "/agents/{id}/config": {
6380
6187
  "get": {
6381
6188
  "tags": [
@@ -3305,120 +3305,6 @@
3305
3305
  ],
3306
3306
  "additionalProperties": false
3307
3307
  },
3308
- "GithubAccessPreview": {
3309
- "type": "object",
3310
- "properties": {
3311
- "status": {
3312
- "type": "string",
3313
- "enum": [
3314
- "ok",
3315
- "user_not_found",
3316
- "unconfigured"
3317
- ],
3318
- "description": "`unconfigured` when the lookup App or its key is not set (no GitHub call was made). The installer App is optional."
3319
- },
3320
- "access": {
3321
- "type": "object",
3322
- "properties": {
3323
- "username": {
3324
- "type": "string"
3325
- },
3326
- "outcome": {
3327
- "type": "string",
3328
- "enum": [
3329
- "ok",
3330
- "user_not_found"
3331
- ]
3332
- },
3333
- "userVerified": {
3334
- "type": "boolean"
3335
- },
3336
- "orgs": {
3337
- "type": "array",
3338
- "items": {
3339
- "type": "object",
3340
- "properties": {
3341
- "org": {
3342
- "type": "string"
3343
- },
3344
- "status": {
3345
- "type": "string",
3346
- "enum": [
3347
- "ok",
3348
- "lookup_app_not_installed",
3349
- "rate_limited",
3350
- "partial",
3351
- "error"
3352
- ]
3353
- },
3354
- "repos": {
3355
- "type": "array",
3356
- "items": {
3357
- "type": "object",
3358
- "properties": {
3359
- "fullName": {
3360
- "type": "string"
3361
- },
3362
- "level": {
3363
- "type": "string",
3364
- "enum": [
3365
- "admin",
3366
- "maintain",
3367
- "write",
3368
- "triage",
3369
- "read",
3370
- "none"
3371
- ]
3372
- },
3373
- "canPush": {
3374
- "type": "boolean"
3375
- }
3376
- },
3377
- "required": [
3378
- "fullName",
3379
- "level",
3380
- "canPush"
3381
- ]
3382
- }
3383
- },
3384
- "unresolved": {
3385
- "type": "integer"
3386
- }
3387
- },
3388
- "required": [
3389
- "org",
3390
- "status",
3391
- "repos",
3392
- "unresolved"
3393
- ]
3394
- }
3395
- },
3396
- "unresolved": {
3397
- "type": "integer"
3398
- },
3399
- "complete": {
3400
- "type": "boolean"
3401
- },
3402
- "checkedAt": {
3403
- "type": "string"
3404
- }
3405
- },
3406
- "required": [
3407
- "username",
3408
- "outcome",
3409
- "userVerified",
3410
- "orgs",
3411
- "unresolved",
3412
- "complete",
3413
- "checkedAt"
3414
- ],
3415
- "description": "Resolver output; absent when unconfigured."
3416
- }
3417
- },
3418
- "required": [
3419
- "status"
3420
- ]
3421
- },
3422
3308
  "GithubInstallationReposList": {
3423
3309
  "type": "object",
3424
3310
  "properties": {
@@ -3609,28 +3495,6 @@
3609
3495
  },
3610
3496
  "description": "Configured agent repos the bound user can no longer push to. The agent's repos are never added to."
3611
3497
  },
3612
- "selectionSwitches": {
3613
- "type": "array",
3614
- "items": {
3615
- "type": "object",
3616
- "properties": {
3617
- "org": {
3618
- "type": "string"
3619
- },
3620
- "repos": {
3621
- "type": "array",
3622
- "items": {
3623
- "type": "string"
3624
- }
3625
- }
3626
- },
3627
- "required": [
3628
- "org",
3629
- "repos"
3630
- ]
3631
- },
3632
- "description": "Orgs whose agent App installation is on All repositories. Sync switches each to Selected repositories (first 50 repos in the switch, the rest added in batches) before any add or remove; `repos` is the resulting list: the installed repos minus the org's confirmed removals. An org the bound user can push to nothing in is skipped (see `skippedOrgs`) and stays on All repositories."
3633
- },
3634
3498
  "skippedOrgs": {
3635
3499
  "type": "array",
3636
3500
  "items": {
@@ -3651,7 +3515,7 @@
3651
3515
  "reason"
3652
3516
  ]
3653
3517
  },
3654
- "description": "Orgs whose access listing is missing, partial or failed, whose cached access data is incomplete or stale, or whose lookup App is not installed or installed on selected repositories only; nothing there is added or removed. `reason` says why (for stale data, when it was checked)."
3518
+ "description": "Orgs whose access listing is missing, partial or failed, whose cached access data is incomplete or stale, or whose lookup App is not installed or installed on selected repositories only, or whose agent App installation is on All repositories (uninstall and reinstall with selected repositories); nothing there is added or removed. `reason` says why (for stale data, when it was checked)."
3655
3519
  },
3656
3520
  "openWork": {
3657
3521
  "type": "array",
@@ -3794,28 +3658,6 @@
3794
3658
  "type": "string"
3795
3659
  }
3796
3660
  },
3797
- "selectionSwitches": {
3798
- "type": "array",
3799
- "items": {
3800
- "type": "object",
3801
- "properties": {
3802
- "org": {
3803
- "type": "string"
3804
- },
3805
- "repos": {
3806
- "type": "array",
3807
- "items": {
3808
- "type": "string"
3809
- }
3810
- }
3811
- },
3812
- "required": [
3813
- "org",
3814
- "repos"
3815
- ]
3816
- },
3817
- "description": "Orgs whose agent App installation is on All repositories. Sync switches each to Selected repositories (first 50 repos in the switch, the rest added in batches) before any add or remove; `repos` is the resulting list: the installed repos minus the org's confirmed removals. An org the bound user can push to nothing in is skipped (see `skippedOrgs`) and stays on All repositories."
3818
- },
3819
3661
  "notApplied": {
3820
3662
  "type": "array",
3821
3663
  "items": {
@@ -7879,85 +7721,6 @@
7879
7721
  }
7880
7722
  }
7881
7723
  },
7882
- "/agents/{id}/github-access": {
7883
- "get": {
7884
- "summary": "Preview the repos the agent's bound GitHub user can reach",
7885
- "description": "Platform-admin only (session members, ops keys and agent keys get 403): the response lists repo names the bound user can reach. Read-only; nothing is stored. 404 for an unknown agent; 422 when no githubUsername is bound. Returns `status: unconfigured` (not an error, no GitHub call) when the lookup App is not configured (the installer App is optional), and `status: user_not_found` when the user does not exist on GitHub; otherwise `access` is the resolver output (per-org status, repos with level and canPush, unresolved count, complete flag).",
7886
- "parameters": [
7887
- {
7888
- "schema": {
7889
- "type": "string",
7890
- "example": "clx1234567890"
7891
- },
7892
- "required": true,
7893
- "name": "id",
7894
- "in": "path"
7895
- }
7896
- ],
7897
- "responses": {
7898
- "200": {
7899
- "description": "Access preview",
7900
- "content": {
7901
- "application/json": {
7902
- "schema": {
7903
- "$ref": "#/components/schemas/GithubAccessPreview"
7904
- }
7905
- }
7906
- }
7907
- },
7908
- "401": {
7909
- "description": "Unauthorized",
7910
- "content": {
7911
- "application/json": {
7912
- "schema": {
7913
- "$ref": "#/components/schemas/Error"
7914
- }
7915
- }
7916
- }
7917
- },
7918
- "403": {
7919
- "description": "Platform admin required",
7920
- "content": {
7921
- "application/json": {
7922
- "schema": {
7923
- "$ref": "#/components/schemas/Error"
7924
- }
7925
- }
7926
- }
7927
- },
7928
- "404": {
7929
- "description": "Agent not found",
7930
- "content": {
7931
- "application/json": {
7932
- "schema": {
7933
- "$ref": "#/components/schemas/Error"
7934
- }
7935
- }
7936
- }
7937
- },
7938
- "422": {
7939
- "description": "Agent has no githubUsername",
7940
- "content": {
7941
- "application/json": {
7942
- "schema": {
7943
- "$ref": "#/components/schemas/Error"
7944
- }
7945
- }
7946
- }
7947
- },
7948
- "502": {
7949
- "description": "GitHub unavailable or refused",
7950
- "content": {
7951
- "application/json": {
7952
- "schema": {
7953
- "$ref": "#/components/schemas/Error"
7954
- }
7955
- }
7956
- }
7957
- }
7958
- }
7959
- }
7960
- },
7961
7724
  "/agents/{id}/github-installation/repos": {
7962
7725
  "get": {
7963
7726
  "summary": "List the repos on the agent App's installation",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.109.0",
3
+ "version": "1.111.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@anthropic-ai/sdk": "0.137.0",
47
- "@app-vitals/agent-lib": "1.109.0",
47
+ "@app-vitals/agent-lib": "1.111.0",
48
48
  "@hono/zod-openapi": "^1.0.0",
49
49
  "@prisma/adapter-pg": "^7.10.0",
50
50
  "@prisma/client": "^7.10.0",
package/src/admin-boot.ts CHANGED
@@ -491,21 +491,21 @@ export async function startAdmin(
491
491
  // GET /agents/:id/config and GET /agents/:id/crons from root.
492
492
  // Admin CRUD API (/agents/:id/*) MUST be mounted before admin-ui (/admin/*)
493
493
  // to avoid shadowing.
494
- // Built before the admin API: GHE-2.4's access preview reads the same Apps.
494
+ // Built before the admin API: the installation-repos service and Sync read the same Apps.
495
495
  // Strict crypto: no plain-text key storage.
496
- const githubAccessPreview = createGithubAccessPreview({
496
+ const githubAccess = createGithubAccessPreview({
497
497
  appService: githubEnterpriseAppService,
498
498
  });
499
499
  const githubInstallationRepos = createGithubInstallationRepos({
500
500
  prisma,
501
501
  appService: githubEnterpriseAppService,
502
- access: githubAccessPreview,
502
+ access: githubAccess,
503
503
  agentEnv: agentEnvService,
504
504
  });
505
505
  const githubSync = createGithubSync({
506
506
  prisma,
507
507
  appService: githubEnterpriseAppService,
508
- access: githubAccessPreview,
508
+ access: githubAccess,
509
509
  agentEnv: agentEnvService,
510
510
  openWork: resolvedExtensions.openWork,
511
511
  });
@@ -545,7 +545,6 @@ export async function startAdmin(
545
545
  repoAccessCheckEnabled: repoAccessConfig.enabled,
546
546
  },
547
547
  adminApi: {
548
- githubAccessPreview,
549
548
  ...(resolvedExtensions.openWork
550
549
  ? { openWork: resolvedExtensions.openWork }
551
550
  : {}),
@@ -726,6 +725,8 @@ export async function startAdmin(
726
725
  })(),
727
726
  githubEnterpriseApi: (path, init) =>
728
727
  githubEnterpriseApp.request(path, init),
728
+ installRepoChoices: (agentId, orgs) =>
729
+ githubSync.installRepoChoices(agentId, orgs),
729
730
  agentsApi: (path, init) => adminApiApp.request(path, init),
730
731
  ensureAccountMember: (input) =>
731
732
  prisma.$transaction((tx) => ensureAccountMember(tx, input)),
@@ -192,8 +192,15 @@ function scopeQuery(accountId: string | undefined): string {
192
192
 
193
193
  function accountSelector(opts: GithubEnterpriseSettingsPageOpts): string {
194
194
  if (!opts.accounts) return "";
195
+ // With several accounts a deployment-wide pair cannot be created or
196
+ // changed, so the option is offered only while it is the open scope.
197
+ const showDeployment = opts.accounts.length <= 1 || !opts.accountId;
195
198
  const options = [
196
- `<option value=""${opts.accountId ? "" : " selected"}>Deployment-wide default</option>`,
199
+ ...(showDeployment
200
+ ? [
201
+ `<option value=""${opts.accountId ? "" : " selected"}>Deployment-wide default</option>`,
202
+ ]
203
+ : []),
197
204
  ...opts.accounts.map(
198
205
  (a) =>
199
206
  `<option value="${escapeHtml(a.id)}"${a.id === opts.accountId ? " selected" : ""}>${escapeHtml(a.name)}</option>`,
@@ -211,7 +218,11 @@ function scopeNote(
211
218
  opts: GithubEnterpriseSettingsPageOpts,
212
219
  own: GheApp | null,
213
220
  ): string {
214
- if (!opts.accountId) return "";
221
+ if (!opts.accountId) {
222
+ return opts.accounts && opts.accounts.length > 1
223
+ ? `<p class="help-text gh-ent-scope" style="font-size:12px;margin:8px 0"><span class="badge badge-gray">Several accounts</span> A deployment-wide ${role} App cannot be created or replaced while there is more than one account; choose an account. An existing one can still be deleted.</p>`
224
+ : "";
225
+ }
215
226
  if (own)
216
227
  return `<p class="help-text gh-ent-scope" style="font-size:12px;margin:8px 0"><span class="badge badge-green">Account's own App</span> This account uses its own ${role} App.</p>`;
217
228
  const fallback = opts.defaultStatus?.[role];
@@ -242,11 +242,30 @@ describe("account selector", () => {
242
242
  const { app } = setup({ accounts: true });
243
243
  const html = await (await app.request(`${BASE}?accountId=acct-2`)).text();
244
244
  expect(html.match(/gh-ent-account-selector/g)?.length).toBe(2);
245
- expect(html).toContain("Deployment-wide default");
245
+ // With several accounts the deployment-wide scope is not offered.
246
+ expect(html).not.toContain("Deployment-wide default");
246
247
  expect(html).toContain('<option value="acct-1">Acme</option>');
247
248
  expect(html).toContain('<option value="acct-2" selected>Globex</option>');
248
249
  });
249
250
 
251
+ it("defaults to the first account when several exist and none is named", async () => {
252
+ const { app } = setup({ accounts: true });
253
+ const res = await app.request(`${BASE}?notice=saved`);
254
+ expect(res.status).toBe(302);
255
+ expect(res.headers.get("location")).toBe(
256
+ `${BASE}?notice=saved&accountId=acct-1`,
257
+ );
258
+ });
259
+
260
+ it("still opens the deployment-wide pair when asked for it explicitly", async () => {
261
+ const { app } = setup({ accounts: true });
262
+ const res = await app.request(`${BASE}?accountId=`);
263
+ expect(res.status).toBe(200);
264
+ const html = await res.text();
265
+ expect(html).toContain("Deployment-wide default");
266
+ expect(html).toContain("cannot be created or replaced");
267
+ });
268
+
250
269
  it("saves under the chosen account and marks own vs fallback", async () => {
251
270
  const { app, appService } = setup({ accounts: true });
252
271
  await app.request(`${BASE}/apps/lookup`, saveForm("7", "shared-lookup"));
@@ -182,7 +182,22 @@ export function registerAdminGithubEnterpriseRoutes(
182
182
  const fail = (c: Context<AdminUIEnv>, r: ApiResult<unknown>) =>
183
183
  renderPage(c, { error: r.error, status: r.status >= 400 ? r.status : 400 });
184
184
 
185
- app.get(BASE, deps.requireAuth, requireAdmin, (c) => renderPage(c));
185
+ // With several accounts a deployment-wide pair cannot be created or
186
+ // changed, so a request that names no account lands on the first one. An
187
+ // explicit empty accountId still opens the deployment-wide pair (it stays
188
+ // readable and removable).
189
+ app.get(BASE, deps.requireAuth, requireAdmin, async (c) => {
190
+ if (c.req.query("accountId") === undefined && deps.accounts) {
191
+ const accounts = await deps.accounts.listWithCounts().catch(() => []);
192
+ const first = accounts[0];
193
+ if (accounts.length > 1 && first) {
194
+ const url = new URL(c.req.url);
195
+ url.searchParams.set("accountId", first.id);
196
+ return c.redirect(`${BASE}${url.search}`, 302);
197
+ }
198
+ }
199
+ return renderPage(c);
200
+ });
186
201
 
187
202
  app.post(`${BASE}/apps/:role`, deps.requireAuth, requireAdmin, async (c) => {
188
203
  const role = c.req.param("role");