@app-vitals/agent-admin 1.110.0 → 1.112.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 (44) hide show
  1. package/openapi.json +0 -193
  2. package/openapi.platform.json +1 -238
  3. package/package.json +2 -2
  4. package/prisma/client/internal/class.ts +4 -4
  5. package/prisma/client/internal/prismaNamespace.ts +1 -0
  6. package/prisma/client/internal/prismaNamespaceBrowser.ts +1 -0
  7. package/prisma/client/models/UserNotificationPrefs.ts +29 -1
  8. package/prisma/migrations/20261201000000_rename_user_notification_prefs_to_user_prefs/migration.sql +4 -0
  9. package/prisma/schema/schema.prisma +3 -0
  10. package/src/admin-boot.ts +6 -5
  11. package/src/admin-ui-github-identity-pages.ts +35 -139
  12. package/src/admin-ui-github-identity-pages.unit.test.ts +50 -173
  13. package/src/admin-ui-github-identity.smoke.test.ts +103 -63
  14. package/src/admin-ui-installation-repos-pages.ts +2 -23
  15. package/src/admin-ui-installation-repos-pages.unit.test.ts +41 -36
  16. package/src/admin-ui-installation-repos.smoke.test.ts +9 -8
  17. package/src/admin-ui-pages.ts +4 -5
  18. package/src/admin-ui.ts +51 -36
  19. package/src/agents-api.smoke.test.ts +26 -315
  20. package/src/agents-api.ts +1 -107
  21. package/src/drop-email-key-columns-migration.integration.test.ts +0 -4
  22. package/src/github-access-preview.ts +2 -2
  23. package/src/github-enterprise-api.smoke.test.ts +26 -0
  24. package/src/github-enterprise-api.ts +18 -2
  25. package/src/github-enterprise-client.integration.test.ts +0 -41
  26. package/src/github-enterprise-client.ts +0 -25
  27. package/src/github-enterprise-client.unit.test.ts +0 -18
  28. package/src/github-installation-wiring.ts +18 -12
  29. package/src/github-sync-all-repos.unit.test.ts +116 -0
  30. package/src/github-sync-snapshot-refresh.integration.test.ts +168 -0
  31. package/src/github-sync-snapshot-refresh.unit.test.ts +144 -0
  32. package/src/github-sync.ts +103 -137
  33. package/src/github-sync.unit.test.ts +82 -1
  34. package/src/installation-ports.ts +1 -40
  35. package/src/principals-api.integration.test.ts +3 -3
  36. package/src/reconcile-open-work.integration.test.ts +0 -1
  37. package/src/user-notification-prefs.ts +10 -65
  38. package/src/user-notification-prefs.unit.test.ts +9 -0
  39. package/src/user-prefs-rename-migration.integration.test.ts +71 -0
  40. package/src/{user-notification-prefs.integration.test.ts → user-prefs.integration.test.ts} +22 -5
  41. package/src/user-prefs.ts +98 -0
  42. package/src/github-access-preview.integration.test.ts +0 -399
  43. package/src/github-sync-switch.integration.test.ts +0 -297
  44. package/src/github-sync-switch.unit.test.ts +0 -467
@@ -3351,6 +3351,7 @@ export type ChatThreadWatchScalarFieldEnum = (typeof ChatThreadWatchScalarFieldE
3351
3351
 
3352
3352
  export const UserNotificationPrefsScalarFieldEnum = {
3353
3353
  memberId: 'memberId',
3354
+ timezone: 'timezone',
3354
3355
  autoFollowSessions: 'autoFollowSessions',
3355
3356
  reminderHourLocal: 'reminderHourLocal',
3356
3357
  autoFollowSince: 'autoFollowSince',
@@ -523,6 +523,7 @@ export type ChatThreadWatchScalarFieldEnum = (typeof ChatThreadWatchScalarFieldE
523
523
 
524
524
  export const UserNotificationPrefsScalarFieldEnum = {
525
525
  memberId: 'memberId',
526
+ timezone: 'timezone',
526
527
  autoFollowSessions: 'autoFollowSessions',
527
528
  reminderHourLocal: 'reminderHourLocal',
528
529
  autoFollowSince: 'autoFollowSince',
@@ -36,6 +36,7 @@ export type UserNotificationPrefsSumAggregateOutputType = {
36
36
 
37
37
  export type UserNotificationPrefsMinAggregateOutputType = {
38
38
  memberId: string | null
39
+ timezone: string | null
39
40
  autoFollowSessions: boolean | null
40
41
  reminderHourLocal: number | null
41
42
  autoFollowSince: Date | null
@@ -45,6 +46,7 @@ export type UserNotificationPrefsMinAggregateOutputType = {
45
46
 
46
47
  export type UserNotificationPrefsMaxAggregateOutputType = {
47
48
  memberId: string | null
49
+ timezone: string | null
48
50
  autoFollowSessions: boolean | null
49
51
  reminderHourLocal: number | null
50
52
  autoFollowSince: Date | null
@@ -54,6 +56,7 @@ export type UserNotificationPrefsMaxAggregateOutputType = {
54
56
 
55
57
  export type UserNotificationPrefsCountAggregateOutputType = {
56
58
  memberId: number
59
+ timezone: number
57
60
  autoFollowSessions: number
58
61
  reminderHourLocal: number
59
62
  autoFollowSince: number
@@ -73,6 +76,7 @@ export type UserNotificationPrefsSumAggregateInputType = {
73
76
 
74
77
  export type UserNotificationPrefsMinAggregateInputType = {
75
78
  memberId?: true
79
+ timezone?: true
76
80
  autoFollowSessions?: true
77
81
  reminderHourLocal?: true
78
82
  autoFollowSince?: true
@@ -82,6 +86,7 @@ export type UserNotificationPrefsMinAggregateInputType = {
82
86
 
83
87
  export type UserNotificationPrefsMaxAggregateInputType = {
84
88
  memberId?: true
89
+ timezone?: true
85
90
  autoFollowSessions?: true
86
91
  reminderHourLocal?: true
87
92
  autoFollowSince?: true
@@ -91,6 +96,7 @@ export type UserNotificationPrefsMaxAggregateInputType = {
91
96
 
92
97
  export type UserNotificationPrefsCountAggregateInputType = {
93
98
  memberId?: true
99
+ timezone?: true
94
100
  autoFollowSessions?: true
95
101
  reminderHourLocal?: true
96
102
  autoFollowSince?: true
@@ -187,6 +193,7 @@ export type UserNotificationPrefsGroupByArgs<ExtArgs extends runtime.Types.Exten
187
193
 
188
194
  export type UserNotificationPrefsGroupByOutputType = {
189
195
  memberId: string
196
+ timezone: string | null
190
197
  autoFollowSessions: boolean
191
198
  reminderHourLocal: number
192
199
  autoFollowSince: Date | null
@@ -219,6 +226,7 @@ export type UserNotificationPrefsWhereInput = {
219
226
  OR?: Prisma.UserNotificationPrefsWhereInput[]
220
227
  NOT?: Prisma.UserNotificationPrefsWhereInput | Prisma.UserNotificationPrefsWhereInput[]
221
228
  memberId?: Prisma.StringFilter<"UserNotificationPrefs"> | string
229
+ timezone?: Prisma.StringNullableFilter<"UserNotificationPrefs"> | string | null
222
230
  autoFollowSessions?: Prisma.BoolFilter<"UserNotificationPrefs"> | boolean
223
231
  reminderHourLocal?: Prisma.IntFilter<"UserNotificationPrefs"> | number
224
232
  autoFollowSince?: Prisma.DateTimeNullableFilter<"UserNotificationPrefs"> | Date | string | null
@@ -228,6 +236,7 @@ export type UserNotificationPrefsWhereInput = {
228
236
 
229
237
  export type UserNotificationPrefsOrderByWithRelationInput = {
230
238
  memberId?: Prisma.SortOrder
239
+ timezone?: Prisma.SortOrderInput | Prisma.SortOrder
231
240
  autoFollowSessions?: Prisma.SortOrder
232
241
  reminderHourLocal?: Prisma.SortOrder
233
242
  autoFollowSince?: Prisma.SortOrderInput | Prisma.SortOrder
@@ -240,6 +249,7 @@ export type UserNotificationPrefsWhereUniqueInput = Prisma.AtLeast<{
240
249
  AND?: Prisma.UserNotificationPrefsWhereInput | Prisma.UserNotificationPrefsWhereInput[]
241
250
  OR?: Prisma.UserNotificationPrefsWhereInput[]
242
251
  NOT?: Prisma.UserNotificationPrefsWhereInput | Prisma.UserNotificationPrefsWhereInput[]
252
+ timezone?: Prisma.StringNullableFilter<"UserNotificationPrefs"> | string | null
243
253
  autoFollowSessions?: Prisma.BoolFilter<"UserNotificationPrefs"> | boolean
244
254
  reminderHourLocal?: Prisma.IntFilter<"UserNotificationPrefs"> | number
245
255
  autoFollowSince?: Prisma.DateTimeNullableFilter<"UserNotificationPrefs"> | Date | string | null
@@ -249,6 +259,7 @@ export type UserNotificationPrefsWhereUniqueInput = Prisma.AtLeast<{
249
259
 
250
260
  export type UserNotificationPrefsOrderByWithAggregationInput = {
251
261
  memberId?: Prisma.SortOrder
262
+ timezone?: Prisma.SortOrderInput | Prisma.SortOrder
252
263
  autoFollowSessions?: Prisma.SortOrder
253
264
  reminderHourLocal?: Prisma.SortOrder
254
265
  autoFollowSince?: Prisma.SortOrderInput | Prisma.SortOrder
@@ -266,6 +277,7 @@ export type UserNotificationPrefsScalarWhereWithAggregatesInput = {
266
277
  OR?: Prisma.UserNotificationPrefsScalarWhereWithAggregatesInput[]
267
278
  NOT?: Prisma.UserNotificationPrefsScalarWhereWithAggregatesInput | Prisma.UserNotificationPrefsScalarWhereWithAggregatesInput[]
268
279
  memberId?: Prisma.StringWithAggregatesFilter<"UserNotificationPrefs"> | string
280
+ timezone?: Prisma.StringNullableWithAggregatesFilter<"UserNotificationPrefs"> | string | null
269
281
  autoFollowSessions?: Prisma.BoolWithAggregatesFilter<"UserNotificationPrefs"> | boolean
270
282
  reminderHourLocal?: Prisma.IntWithAggregatesFilter<"UserNotificationPrefs"> | number
271
283
  autoFollowSince?: Prisma.DateTimeNullableWithAggregatesFilter<"UserNotificationPrefs"> | Date | string | null
@@ -275,6 +287,7 @@ export type UserNotificationPrefsScalarWhereWithAggregatesInput = {
275
287
 
276
288
  export type UserNotificationPrefsCreateInput = {
277
289
  memberId: string
290
+ timezone?: string | null
278
291
  autoFollowSessions?: boolean
279
292
  reminderHourLocal?: number
280
293
  autoFollowSince?: Date | string | null
@@ -284,6 +297,7 @@ export type UserNotificationPrefsCreateInput = {
284
297
 
285
298
  export type UserNotificationPrefsUncheckedCreateInput = {
286
299
  memberId: string
300
+ timezone?: string | null
287
301
  autoFollowSessions?: boolean
288
302
  reminderHourLocal?: number
289
303
  autoFollowSince?: Date | string | null
@@ -293,6 +307,7 @@ export type UserNotificationPrefsUncheckedCreateInput = {
293
307
 
294
308
  export type UserNotificationPrefsUpdateInput = {
295
309
  memberId?: Prisma.StringFieldUpdateOperationsInput | string
310
+ timezone?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
296
311
  autoFollowSessions?: Prisma.BoolFieldUpdateOperationsInput | boolean
297
312
  reminderHourLocal?: Prisma.IntFieldUpdateOperationsInput | number
298
313
  autoFollowSince?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -302,6 +317,7 @@ export type UserNotificationPrefsUpdateInput = {
302
317
 
303
318
  export type UserNotificationPrefsUncheckedUpdateInput = {
304
319
  memberId?: Prisma.StringFieldUpdateOperationsInput | string
320
+ timezone?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
305
321
  autoFollowSessions?: Prisma.BoolFieldUpdateOperationsInput | boolean
306
322
  reminderHourLocal?: Prisma.IntFieldUpdateOperationsInput | number
307
323
  autoFollowSince?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -311,6 +327,7 @@ export type UserNotificationPrefsUncheckedUpdateInput = {
311
327
 
312
328
  export type UserNotificationPrefsCreateManyInput = {
313
329
  memberId: string
330
+ timezone?: string | null
314
331
  autoFollowSessions?: boolean
315
332
  reminderHourLocal?: number
316
333
  autoFollowSince?: Date | string | null
@@ -320,6 +337,7 @@ export type UserNotificationPrefsCreateManyInput = {
320
337
 
321
338
  export type UserNotificationPrefsUpdateManyMutationInput = {
322
339
  memberId?: Prisma.StringFieldUpdateOperationsInput | string
340
+ timezone?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
323
341
  autoFollowSessions?: Prisma.BoolFieldUpdateOperationsInput | boolean
324
342
  reminderHourLocal?: Prisma.IntFieldUpdateOperationsInput | number
325
343
  autoFollowSince?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -329,6 +347,7 @@ export type UserNotificationPrefsUpdateManyMutationInput = {
329
347
 
330
348
  export type UserNotificationPrefsUncheckedUpdateManyInput = {
331
349
  memberId?: Prisma.StringFieldUpdateOperationsInput | string
350
+ timezone?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
332
351
  autoFollowSessions?: Prisma.BoolFieldUpdateOperationsInput | boolean
333
352
  reminderHourLocal?: Prisma.IntFieldUpdateOperationsInput | number
334
353
  autoFollowSince?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -338,6 +357,7 @@ export type UserNotificationPrefsUncheckedUpdateManyInput = {
338
357
 
339
358
  export type UserNotificationPrefsCountOrderByAggregateInput = {
340
359
  memberId?: Prisma.SortOrder
360
+ timezone?: Prisma.SortOrder
341
361
  autoFollowSessions?: Prisma.SortOrder
342
362
  reminderHourLocal?: Prisma.SortOrder
343
363
  autoFollowSince?: Prisma.SortOrder
@@ -351,6 +371,7 @@ export type UserNotificationPrefsAvgOrderByAggregateInput = {
351
371
 
352
372
  export type UserNotificationPrefsMaxOrderByAggregateInput = {
353
373
  memberId?: Prisma.SortOrder
374
+ timezone?: Prisma.SortOrder
354
375
  autoFollowSessions?: Prisma.SortOrder
355
376
  reminderHourLocal?: Prisma.SortOrder
356
377
  autoFollowSince?: Prisma.SortOrder
@@ -360,6 +381,7 @@ export type UserNotificationPrefsMaxOrderByAggregateInput = {
360
381
 
361
382
  export type UserNotificationPrefsMinOrderByAggregateInput = {
362
383
  memberId?: Prisma.SortOrder
384
+ timezone?: Prisma.SortOrder
363
385
  autoFollowSessions?: Prisma.SortOrder
364
386
  reminderHourLocal?: Prisma.SortOrder
365
387
  autoFollowSince?: Prisma.SortOrder
@@ -375,6 +397,7 @@ export type UserNotificationPrefsSumOrderByAggregateInput = {
375
397
 
376
398
  export type UserNotificationPrefsSelect<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetSelect<{
377
399
  memberId?: boolean
400
+ timezone?: boolean
378
401
  autoFollowSessions?: boolean
379
402
  reminderHourLocal?: boolean
380
403
  autoFollowSince?: boolean
@@ -384,6 +407,7 @@ export type UserNotificationPrefsSelect<ExtArgs extends runtime.Types.Extensions
384
407
 
385
408
  export type UserNotificationPrefsSelectCreateManyAndReturn<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetSelect<{
386
409
  memberId?: boolean
410
+ timezone?: boolean
387
411
  autoFollowSessions?: boolean
388
412
  reminderHourLocal?: boolean
389
413
  autoFollowSince?: boolean
@@ -393,6 +417,7 @@ export type UserNotificationPrefsSelectCreateManyAndReturn<ExtArgs extends runti
393
417
 
394
418
  export type UserNotificationPrefsSelectUpdateManyAndReturn<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetSelect<{
395
419
  memberId?: boolean
420
+ timezone?: boolean
396
421
  autoFollowSessions?: boolean
397
422
  reminderHourLocal?: boolean
398
423
  autoFollowSince?: boolean
@@ -402,6 +427,7 @@ export type UserNotificationPrefsSelectUpdateManyAndReturn<ExtArgs extends runti
402
427
 
403
428
  export type UserNotificationPrefsSelectScalar = {
404
429
  memberId?: boolean
430
+ timezone?: boolean
405
431
  autoFollowSessions?: boolean
406
432
  reminderHourLocal?: boolean
407
433
  autoFollowSince?: boolean
@@ -409,13 +435,14 @@ export type UserNotificationPrefsSelectScalar = {
409
435
  updatedAt?: boolean
410
436
  }
411
437
 
412
- export type UserNotificationPrefsOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"memberId" | "autoFollowSessions" | "reminderHourLocal" | "autoFollowSince" | "createdAt" | "updatedAt", ExtArgs["result"]["userNotificationPrefs"]>
438
+ export type UserNotificationPrefsOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"memberId" | "timezone" | "autoFollowSessions" | "reminderHourLocal" | "autoFollowSince" | "createdAt" | "updatedAt", ExtArgs["result"]["userNotificationPrefs"]>
413
439
 
414
440
  export type $UserNotificationPrefsPayload<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
415
441
  name: "UserNotificationPrefs"
416
442
  objects: {}
417
443
  scalars: runtime.Types.Extensions.GetPayloadResult<{
418
444
  memberId: string
445
+ timezone: string | null
419
446
  autoFollowSessions: boolean
420
447
  reminderHourLocal: number
421
448
  autoFollowSince: Date | null
@@ -845,6 +872,7 @@ export interface Prisma__UserNotificationPrefsClient<T, Null = never, ExtArgs ex
845
872
  */
846
873
  export interface UserNotificationPrefsFieldRefs {
847
874
  readonly memberId: Prisma.FieldRef<"UserNotificationPrefs", 'String'>
875
+ readonly timezone: Prisma.FieldRef<"UserNotificationPrefs", 'String'>
848
876
  readonly autoFollowSessions: Prisma.FieldRef<"UserNotificationPrefs", 'Boolean'>
849
877
  readonly reminderHourLocal: Prisma.FieldRef<"UserNotificationPrefs", 'Int'>
850
878
  readonly autoFollowSince: Prisma.FieldRef<"UserNotificationPrefs", 'DateTime'>
@@ -0,0 +1,4 @@
1
+ -- Rename in place (no data copy) and add a nullable IANA timezone column.
2
+ ALTER TABLE "UserNotificationPrefs" RENAME TO "UserPrefs";
3
+ ALTER TABLE "UserPrefs" RENAME CONSTRAINT "UserNotificationPrefs_pkey" TO "UserPrefs_pkey";
4
+ ALTER TABLE "UserPrefs" ADD COLUMN "timezone" TEXT;
@@ -665,11 +665,14 @@ model ChatThreadWatch {
665
665
  // has no native CHECK constraint support in this schema style.
666
666
  model UserNotificationPrefs {
667
667
  memberId String @id // AccountMember.id
668
+ timezone String? // IANA zone name, validated in UserPrefsService
668
669
  autoFollowSessions Boolean @default(true)
669
670
  reminderHourLocal Int @default(9)
670
671
  autoFollowSince DateTime?
671
672
  createdAt DateTime @default(now())
672
673
  updatedAt DateTime @updatedAt
674
+
675
+ @@map("UserPrefs") // model rename to UserPrefs is deferred to ACM 4.1
673
676
  }
674
677
 
675
678
 
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)),
@@ -1,72 +1,18 @@
1
1
  /**
2
2
  * admin/src/admin-ui-github-identity-pages.ts
3
- * Pure renderers for the agent detail page's GitHub identity row and access
4
- * preview (GHE-2.5). Both are platform-admin only and shown only when the
5
- * enterprise GitHub apps are configured; the caller decides that. Every
6
- * dynamic value is escaped. The input is the GHE-2.4 preview, which carries
7
- * repo names and levels only (no token or key ever reaches this module).
3
+ * Pure renderers for the agent detail page's GitHub identity row and install
4
+ * blocks (GHE-2.5). Platform-admin only and shown only when the enterprise
5
+ * GitHub apps are configured; the caller decides that. Every dynamic value is
6
+ * escaped.
8
7
  */
9
8
 
10
9
  import {
11
10
  type GithubAppsState,
12
- LOOKUP_MISSING_REASON,
13
11
  LOOKUP_ONLY_REASON,
14
12
  } from "./github-apps-state.ts";
15
13
  import type { GheOrgs } from "./admin-ui-github-enterprise-pages.ts";
16
14
  import { escapeHtml } from "./admin-ui-styles.ts";
17
15
 
18
- export interface GithubAccessRepo {
19
- fullName: string;
20
- level: string;
21
- canPush: boolean;
22
- }
23
-
24
- export type GithubAccessOrgStatus =
25
- | "ok"
26
- | "lookup_app_not_installed"
27
- | "rate_limited"
28
- | "partial"
29
- | "error";
30
-
31
- export interface GithubAccessOrg {
32
- org: string;
33
- status: GithubAccessOrgStatus;
34
- repos: GithubAccessRepo[];
35
- unresolved: number;
36
- /** Optional cause shown in the partial-results banner. */
37
- reason?: string;
38
- }
39
-
40
- /** JSON body of GET /agents/:id/github-access. */
41
- export interface GithubAccessPreviewView {
42
- status: "ok" | "user_not_found" | "unconfigured";
43
- access?: {
44
- username: string;
45
- outcome: "ok" | "user_not_found";
46
- userVerified: boolean;
47
- orgs: GithubAccessOrg[];
48
- unresolved: number;
49
- complete: boolean;
50
- checkedAt: string;
51
- };
52
- }
53
-
54
- const STATUS_BADGES: Record<GithubAccessOrgStatus, [string, string]> = {
55
- ok: ["badge-green", "ok"],
56
- lookup_app_not_installed: ["badge-gray", "lookup app not installed"],
57
- rate_limited: ["badge-warning", "rate-limited"],
58
- partial: ["badge-warning", "partial"],
59
- error: ["badge-warning", "error"],
60
- };
61
-
62
- function statusBadge(status: string): string {
63
- const [cls, label] = STATUS_BADGES[status as GithubAccessOrgStatus] ?? [
64
- "badge-warning",
65
- status,
66
- ];
67
- return `<span class="badge ${cls}">${escapeHtml(label)}</span>`;
68
- }
69
-
70
16
  /** The GitHub username `<tr>` for the "Owner & identities" card. */
71
17
  export function renderGithubUsernameRow(
72
18
  agentId: string,
@@ -90,86 +36,6 @@ export function renderGithubUsernameRow(
90
36
  </td></tr>`;
91
37
  }
92
38
 
93
- /** The "Preview access" fragment (rendered inside the GitHub card); the button loads the fragment from the UI route. */
94
- export function renderGithubAccessCard(agentId: string): string {
95
- const url = `/admin/agents/${escapeHtml(agentId)}/github-access`;
96
- return `<div id="github-access-card" style="margin-top:20px">
97
- <div class="form-label" style="font-weight:600;margin-bottom:6px">Preview access</div>
98
- <p style="color:var(--vos-text-muted);font-size:12px;margin:0 0 12px">Shows the repos this agent's GitHub user can reach. Read-only; nothing is stored.</p>
99
- <button type="button" class="btn btn-primary" id="github-access-btn" data-url="${url}">Preview access</button>
100
- <div id="github-access-result" style="margin-top:12px"></div>
101
- <script>
102
- (function() {
103
- var btn = document.getElementById('github-access-btn');
104
- var out = document.getElementById('github-access-result');
105
- if (!btn || !out) return;
106
- btn.addEventListener('click', function() {
107
- btn.disabled = true;
108
- out.textContent = 'Loading...';
109
- fetch(btn.getAttribute('data-url'), { credentials: 'same-origin' })
110
- .then(function(r) { return r.text(); })
111
- .then(function(t) { out.innerHTML = t; })
112
- .catch(function() { out.textContent = 'The request failed.'; })
113
- .then(function() { btn.disabled = false; });
114
- });
115
- })();
116
- </script>
117
- </div>`;
118
- }
119
-
120
- /** Fragment rendered into the preview card; also the body of the UI route. */
121
- export function renderGithubAccessResult(
122
- preview: GithubAccessPreviewView,
123
- ): string {
124
- if (preview.status === "unconfigured") {
125
- return `<div class="alert alert-warning" data-reason="lookup-missing">${escapeHtml(LOOKUP_MISSING_REASON)}</div>`;
126
- }
127
- const access = preview.access;
128
- if (
129
- preview.status === "user_not_found" ||
130
- access?.outcome === "user_not_found"
131
- ) {
132
- const who = access?.username ? ` "${escapeHtml(access.username)}"` : "";
133
- return `<div class="alert alert-warning">GitHub user${who} was not found.</div>`;
134
- }
135
- if (!access) return renderGithubAccessError("No preview was returned.");
136
-
137
- const orgs = access.orgs;
138
- const reasons = orgs
139
- .filter((o) => o.reason)
140
- .map((o) => `${escapeHtml(o.org)}: ${escapeHtml(o.reason ?? "")}`)
141
- .join("; ");
142
- const warn =
143
- !access.complete || orgs.some((o) => o.status !== "ok")
144
- ? `<div class="alert alert-warning">Partial results: some organizations or repos could not be checked${access.unresolved > 0 ? ` (${access.unresolved} unresolved)` : ""}. Repos that are not listed are unknown, not necessarily inaccessible.${reasons ? ` ${reasons}.` : ""}</div>`
145
- : "";
146
- if (orgs.length === 0) {
147
- return `${warn}<p class="empty-state">No organizations to check.</p>`;
148
- }
149
- const groups = orgs
150
- .map((o) => {
151
- const rows =
152
- o.repos.length === 0
153
- ? `<tr><td colspan="3" class="empty-state">No repos.</td></tr>`
154
- : o.repos
155
- .map(
156
- (r) =>
157
- `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${escapeHtml(r.level)}</td><td>${r.canPush ? '<span class="badge badge-green" title="Can push">push</span>' : ""}</td></tr>`,
158
- )
159
- .join("");
160
- const unresolved =
161
- o.unresolved > 0
162
- ? ` <span style="color:var(--vos-text-muted);font-size:12px">${o.unresolved} unresolved</span>`
163
- : "";
164
- return `<div class="github-access-org" style="margin-bottom:16px">
165
- <div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)} ${statusBadge(o.status)}${unresolved}</div>
166
- <table class="detail-table"><thead><tr><th>Repo</th><th>Level</th><th>Push</th></tr></thead><tbody>${rows}</tbody></table>
167
- </div>`;
168
- })
169
- .join("");
170
- return `${warn}${groups}`;
171
- }
172
-
173
39
  export function renderGithubAccessError(message: string): string {
174
40
  return `<div class="alert alert-error">${escapeHtml(message)}</div>`;
175
41
  }
@@ -214,10 +80,40 @@ function installedBadge(v: boolean | null): string {
214
80
  : `<span class="badge badge-gray">Not installed</span>`;
215
81
  }
216
82
 
83
+ /** Most repositories one install can select (mirrors the API and GitHub). */
84
+ export const MAX_INSTALL_REPOSITORIES = 50;
85
+
86
+ // Recomputes the Selected checklist state on any change: shows the list and
87
+ // count only for Selected, and blocks submit for 0 or more than the cap.
88
+ const INSTALL_FORM_JS = `var f=this,s=f.querySelector('input[name=repositorySelection]:checked').value==='selected',n=f.querySelectorAll('input[name=repositories]:checked').length,b=f.querySelector('button[type=submit]'),c=f.querySelector('[data-count]'),bad=s&&(n<1||n>${MAX_INSTALL_REPOSITORIES});f.querySelector('[data-selected-panel]').style.display=s?'block':'none';c.textContent=n+' of ${MAX_INSTALL_REPOSITORIES} selected';c.style.color=bad?'#b91c1c':'';b.disabled=bad||b.hasAttribute('data-locked')`;
89
+
90
+ /** The Install form for one not-installed org: All or Selected (capped checklist). */
91
+ function installForm(
92
+ base: string,
93
+ repos: readonly string[],
94
+ disabled: string,
95
+ ): string {
96
+ const known = repos.length > 0;
97
+ const initial = repos.slice(0, MAX_INSTALL_REPOSITORIES);
98
+ const items = repos
99
+ .map((r, i) => {
100
+ const checked = i < MAX_INSTALL_REPOSITORIES ? " checked" : "";
101
+ return `<label style="display:block;font-size:12px"><input type="checkbox" name="repositories" value="${escapeHtml(r)}"${checked}> ${escapeHtml(r)}</label>`;
102
+ })
103
+ .join("");
104
+ const panel = known
105
+ ? `<div style="max-height:160px;overflow:auto;border:1px solid #ddd;padding:4px 8px;margin:4px 0">${items}</div>`
106
+ : `<p style="font-size:12px;margin:4px 0">No cached repositories for this organization yet. Refresh the GitHub cache to choose repositories, or install on All.</p>`;
107
+ const locked = disabled ? " data-locked" : "";
108
+ return `<form method="POST" action="${base}/install" style="display:inline-block;margin:0;text-align:left" onchange="${escapeHtml(INSTALL_FORM_JS)}"><label style="font-size:12px"><input type="radio" name="repositorySelection" value="all"${known ? "" : " checked"}> All repositories</label> <label style="font-size:12px"><input type="radio" name="repositorySelection" value="selected"${known ? " checked" : ""}> Selected (max ${MAX_INSTALL_REPOSITORIES})</label><div data-selected-panel style="display:${known ? "block" : "none"}">${panel}<span data-count style="font-size:12px">${initial.length} of ${MAX_INSTALL_REPOSITORIES} selected</span></div><button type="submit" class="btn btn-primary" style="font-size:12px;padding:4px 10px"${locked}${disabled}>Install</button></form>`;
109
+ }
110
+
217
111
  /** Fragment for the Install on org block: org list with app status and Install buttons. */
218
112
  export function renderGithubOrgsFragment(
219
113
  agentId: string,
220
114
  data: GheOrgs,
115
+ /** Cached pushable repo names per org (never a live GitHub read). Absent/empty = no pre-fill. */
116
+ repoChoices: Record<string, readonly string[]> = {},
221
117
  ): string {
222
118
  if (!data.configured) {
223
119
  return `<div class="alert alert-warning" data-reason="installer-unconfigured">The installer GitHub App is not configured. Installing the agent App on an organization needs an enterprise installer App (GitHub Enterprise Cloud).</div>`;
@@ -234,7 +130,7 @@ export function renderGithubOrgsFragment(
234
130
  const base = `/admin/agents/${escapeHtml(agentId)}/github-orgs/${escapeHtml(encodeURIComponent(o.login))}`;
235
131
  const action = o.agentAppInstalled
236
132
  ? `<button type="button" class="btn btn-danger" style="font-size:12px;padding:4px 10px" data-url="${base}/uninstall-confirm" onclick="var b=this,t=document.getElementById('uninstall-confirm-'+b.getAttribute('data-org'));b.disabled=true;fetch(b.getAttribute('data-url'),{credentials:'same-origin'}).then(function(r){return r.text()}).then(function(h){t.innerHTML=h}).catch(function(){t.textContent='The request failed.'}).then(function(){b.disabled=false})" data-org="${escapeHtml(o.login)}"${disabled}>Uninstall</button>`
237
- : `<form method="POST" action="${base}/install" style="display:inline;margin:0"><button type="submit" class="btn btn-primary" style="font-size:12px;padding:4px 10px"${disabled}>Install</button></form>`;
133
+ : installForm(base, repoChoices[o.login] ?? [], disabled);
238
134
  const confirmRow = o.agentAppInstalled
239
135
  ? `<tr><td colspan="4" id="uninstall-confirm-${escapeHtml(o.login)}" style="padding:0"></td></tr>`
240
136
  : "";