@app-vitals/agent-admin 1.106.1 → 1.107.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 (40) hide show
  1. package/openapi.json +0 -280
  2. package/openapi.platform.json +0 -280
  3. package/package.json +2 -2
  4. package/prisma/client/browser.ts +0 -10
  5. package/prisma/client/client.ts +0 -10
  6. package/prisma/client/internal/class.ts +4 -24
  7. package/prisma/client/internal/prismaNamespace.ts +1 -181
  8. package/prisma/client/internal/prismaNamespaceBrowser.ts +0 -30
  9. package/prisma/client/models.ts +0 -2
  10. package/prisma/migrations/20261129000000_drop_cron_run_transcripts/migration.sql +9 -0
  11. package/prisma/schema/schema.prisma +0 -34
  12. package/src/account-member-removal.integration.test.ts +190 -0
  13. package/src/account-members.ts +7 -1
  14. package/src/admin-boot.ts +0 -11
  15. package/src/admin-ui-account-pages.ts +15 -2
  16. package/src/admin-ui-account-pages.unit.test.ts +4 -0
  17. package/src/admin-ui-accounts-pages.ts +14 -2
  18. package/src/admin-ui-accounts-pages.unit.test.ts +1 -0
  19. package/src/admin-ui.smoke.test.ts +163 -1
  20. package/src/admin-ui.ts +35 -1
  21. package/src/agents-api.ts +0 -13
  22. package/src/api.smoke.test.ts +6 -73
  23. package/src/api.ts +0 -17
  24. package/src/cron-run-now.integration.test.ts +163 -0
  25. package/src/cron-run-transcripts-removed.smoke.test.ts +82 -0
  26. package/src/drop-cron-run-transcripts-migration.integration.test.ts +114 -0
  27. package/src/member-id-stamp.ts +26 -0
  28. package/src/openapi-schemas.ts +0 -55
  29. package/src/push-service.integration.test.ts +12 -0
  30. package/src/push-service.ts +7 -4
  31. package/src/push-service.unit.test.ts +24 -0
  32. package/src/push-toggle.ts +10 -0
  33. package/src/repo-access-config.ts +1 -1
  34. package/prisma/client/models/AgentCronRunTranscript.ts +0 -1339
  35. package/prisma/client/models/AgentTranscriptRead.ts +0 -1177
  36. package/src/cron-run-transcripts.integration.test.ts +0 -220
  37. package/src/cron-run-transcripts.smoke.test.ts +0 -286
  38. package/src/cron-run-transcripts.ts +0 -314
  39. package/src/transcript-config.ts +0 -30
  40. package/src/transcript-config.unit.test.ts +0 -50
@@ -0,0 +1,114 @@
1
+ /**
2
+ * admin/src/drop-cron-run-transcripts-migration.integration.test.ts
3
+ * Migration test for 20261129000000_drop_cron_run_transcripts
4
+ * (prompt-audit-removal 2.3): the cron-run transcript API is gone, so the
5
+ * migration drops "AgentCronRunTranscript" and its audit table
6
+ * "AgentTranscriptRead".
7
+ *
8
+ * Replays the real migration files, in order, inside a throwaway Postgres
9
+ * schema (same pattern as agent-specialty-backfill.integration.test.ts):
10
+ *
11
+ * - seeded: every migration up to the drop, then transcript + read rows,
12
+ * then the drop. Both tables are gone and the rest of the schema
13
+ * ("AgentCronRun" here) is untouched.
14
+ * - fresh: every migration from an empty schema, ending with no transcript
15
+ * tables.
16
+ *
17
+ * Requires DATABASE_URL_ADMIN_TEST; skips otherwise.
18
+ */
19
+
20
+ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
21
+ import { readdirSync, readFileSync } from "node:fs";
22
+ import { Client } from "pg";
23
+
24
+ const TEST_DB = process.env.DATABASE_URL_ADMIN_TEST;
25
+ const describeOrSkip = TEST_DB ? describe : describe.skip;
26
+
27
+ const MIGRATIONS_DIR = new URL("../prisma/migrations/", import.meta.url);
28
+ const DROP = "20261129000000_drop_cron_run_transcripts";
29
+ const TABLES = ["AgentCronRunTranscript", "AgentTranscriptRead"];
30
+
31
+ /** Migration directory names in apply order (Prisma sorts lexically). */
32
+ const ALL_MIGRATIONS = readdirSync(MIGRATIONS_DIR, { withFileTypes: true })
33
+ .filter((d) => d.isDirectory())
34
+ .map((d) => d.name)
35
+ .sort();
36
+
37
+ function migrationSql(dir: string): string {
38
+ return readFileSync(new URL(`${dir}/migration.sql`, MIGRATIONS_DIR), "utf8");
39
+ }
40
+
41
+ describeOrSkip("drop_cron_run_transcripts migration (2.3)", () => {
42
+ const schema = `drop_transcripts_${process.pid}_${Date.now()}`;
43
+ let client: Client;
44
+
45
+ const tables = async (): Promise<string[]> =>
46
+ (
47
+ await client.query<{ table_name: string }>(
48
+ `SELECT table_name FROM information_schema.tables
49
+ WHERE table_schema = $1`,
50
+ [schema],
51
+ )
52
+ ).rows.map((r) => r.table_name);
53
+
54
+ const apply = async (dirs: string[]): Promise<void> => {
55
+ for (const dir of dirs) await client.query(migrationSql(dir));
56
+ };
57
+
58
+ beforeEach(async () => {
59
+ client = new Client({ connectionString: TEST_DB as string });
60
+ await client.connect();
61
+ await client.query(`CREATE SCHEMA "${schema}"`);
62
+ await client.query(`SET search_path TO "${schema}"`);
63
+ });
64
+
65
+ afterEach(async () => {
66
+ await client.query(`DROP SCHEMA IF EXISTS "${schema}" CASCADE`);
67
+ await client.end();
68
+ });
69
+
70
+ it("orders the drop after the add migration", () => {
71
+ expect(ALL_MIGRATIONS).toContain(DROP);
72
+ expect(
73
+ ALL_MIGRATIONS.indexOf("20261027000000_add_cron_run_transcripts"),
74
+ ).toBeLessThan(ALL_MIGRATIONS.indexOf(DROP));
75
+ });
76
+
77
+ it("drops both tables over seeded transcript rows and leaves AgentCronRun intact", async () => {
78
+ await apply(ALL_MIGRATIONS.slice(0, ALL_MIGRATIONS.indexOf(DROP)));
79
+ expect(await tables()).toEqual(expect.arrayContaining(TABLES));
80
+
81
+ await client.query(
82
+ `INSERT INTO "AgentCronRunTranscript"
83
+ ("id","runId","agentId","cronId","sessionId","bytes","truncated","redactions","body")
84
+ VALUES ('t1','run-1','agent-1','cron-1','sess-1',5,false,0,'hello'),
85
+ ('t2','run-2','agent-1','cron-1',NULL,3,true,2,'abc')`,
86
+ );
87
+ await client.query(
88
+ `INSERT INTO "AgentTranscriptRead" ("id","runId","agentId","reader","scopeKind")
89
+ VALUES ('r1','run-1','agent-1','root','*')`,
90
+ );
91
+ const before = await tables();
92
+
93
+ await client.query(migrationSql(DROP));
94
+
95
+ const after = await tables();
96
+ for (const t of TABLES) expect(after).not.toContain(t);
97
+ expect(after).toContain("AgentCronRun");
98
+ expect(after.sort()).toEqual(
99
+ before.filter((t) => !TABLES.includes(t)).sort(),
100
+ );
101
+ });
102
+
103
+ it("applies cleanly on a fresh database and ends with no transcript tables", async () => {
104
+ await apply(ALL_MIGRATIONS);
105
+ const after = await tables();
106
+ expect(after).toContain("Agent");
107
+ for (const t of TABLES) expect(after).not.toContain(t);
108
+ });
109
+
110
+ it("is idempotent when the tables are already gone", async () => {
111
+ await expect(client.query(migrationSql(DROP))).resolves.toBeDefined();
112
+ expect(await tables()).toEqual([]);
113
+ });
114
+ });
@@ -40,3 +40,29 @@ export async function stampMemberId(
40
40
  ]);
41
41
  return results.reduce((n, r) => n + r.count, 0);
42
42
  }
43
+
44
+ /**
45
+ * Deletes the member's rows in all four tables: those with this memberId, plus
46
+ * those matching the email whose memberId is still null. Rows stamped with a
47
+ * different memberId are left alone. Returns the rows deleted.
48
+ */
49
+ export async function deleteMemberRows(
50
+ client: PrismaTransactionClient,
51
+ rawEmail: string,
52
+ memberId: string,
53
+ ): Promise<number> {
54
+ const email = {
55
+ equals: normalizeEmail(rawEmail),
56
+ mode: "insensitive",
57
+ } as const;
58
+ const match = (emailField: "email" | "userEmail") => ({
59
+ OR: [{ memberId }, { [emailField]: email, memberId: null }],
60
+ });
61
+ const results = await Promise.all([
62
+ client.agentMember.deleteMany({ where: match("email") }),
63
+ client.chatThreadWatch.deleteMany({ where: match("userEmail") }),
64
+ client.pushSubscription.deleteMany({ where: match("userEmail") }),
65
+ client.userNotificationPrefs.deleteMany({ where: match("userEmail") }),
66
+ ]);
67
+ return results.reduce((n, r) => n + r.count, 0);
68
+ }
@@ -749,51 +749,6 @@ export const ChatCredentialsWrapperSchema = z
749
749
  .object({ credentials: z.array(ChatCredentialSchema) })
750
750
  .openapi("ChatCredentialsWrapper");
751
751
 
752
- // ─── Cron-run transcripts (COS-43.1) ─────────────────────────────────────────
753
-
754
- export const UploadCronRunTranscriptBodySchema = z
755
- .object({
756
- sessionId: z.string().min(1).optional().openapi({
757
- description: "Claude session id the transcript was read from.",
758
- example: "7c1c8d1e-0000-4000-8000-000000000000",
759
- }),
760
- body: z.string().openapi({
761
- description:
762
- "The already-redacted transcript (JSONL text). Over 1 MiB (UTF-8 bytes) is a 413. Never logged.",
763
- }),
764
- truncated: z.boolean().openapi({
765
- description: "True when the runtime dropped earlier lines to fit.",
766
- example: false,
767
- }),
768
- redactions: z.number().int().min(0).openapi({
769
- description: "How many secrets the runtime redacted.",
770
- example: 0,
771
- }),
772
- })
773
- .openapi("UploadCronRunTranscriptBody");
774
-
775
- export const CronRunTranscriptUploadResultSchema = z
776
- .object({
777
- runId: z.string().openapi({ example: "clx1111111111" }),
778
- bytes: z.number().int().openapi({ example: 2048 }),
779
- truncated: z.boolean().openapi({ example: false }),
780
- redactions: z.number().int().openapi({ example: 0 }),
781
- })
782
- .openapi("CronRunTranscriptUploadResult");
783
-
784
- export const CronRunTranscriptSchema = z
785
- .object({
786
- runId: z.string().openapi({ example: "clx1111111111" }),
787
- cronId: z.string().openapi({ example: "clx0987654321" }),
788
- sessionId: z.string().nullable().openapi({ example: null }),
789
- bytes: z.number().int().openapi({ example: 2048 }),
790
- truncated: z.boolean().openapi({ example: false }),
791
- redactions: z.number().int().openapi({ example: 0 }),
792
- createdAt: z.string().openapi({ example: "2026-10-26T12:00:00.000Z" }),
793
- body: z.string().openapi({ description: "Redacted JSONL transcript." }),
794
- })
795
- .openapi("CronRunTranscript");
796
-
797
752
  // ─── Agent ask (COS-31.1) ─────────────────────────────────────────────────────
798
753
 
799
754
  export const AgentAskBodySchema = z
@@ -1489,20 +1444,10 @@ export const AgentConfigResponseSchema = z
1489
1444
  */
1490
1445
  features: z
1491
1446
  .object({
1492
- transcriptUpload: z.boolean().openapi({
1493
- description:
1494
- "True when SHIPWRIGHT_TRANSCRIPT_API_ENABLED is on: the runtime uploads a redacted transcript after each cron run.",
1495
- example: false,
1496
- }),
1497
1447
  repoAccessCheck: z.boolean().openapi({
1498
1448
  description: "Reserved for the repo-access check (COS-44.1).",
1499
1449
  example: false,
1500
1450
  }),
1501
- loopTranscriptUpload: z.boolean().optional().openapi({
1502
- description:
1503
- "True when SHIPWRIGHT_TRANSCRIPT_API_ENABLED is on and this agent is listed in SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS: coding-loop runs may upload a redacted transcript through the extension capability.",
1504
- example: false,
1505
- }),
1506
1451
  })
1507
1452
  .optional()
1508
1453
  .openapi("AgentConfigFeatures"),
@@ -120,6 +120,18 @@ describeOrSkip("PushService by memberId (integration)", () => {
120
120
  expect(row.memberId).toBe(bobId);
121
121
  });
122
122
 
123
+ it("subscribe for an email with no member record stores nothing", async () => {
124
+ expect(
125
+ await service.subscribe(
126
+ "ghost@nowhere.com",
127
+ "https://p/g",
128
+ P256DH,
129
+ AUTH,
130
+ ),
131
+ ).toEqual({ ok: false, reason: "no_member" });
132
+ expect(await prisma.pushSubscription.count()).toBe(0);
133
+ });
134
+
123
135
  it("sendToUsers resolves emails to members and skips null-memberId subscriptions", async () => {
124
136
  await service.subscribe(
125
137
  "alice@acme.com",
@@ -84,12 +84,12 @@ interface PushPrismaLike {
84
84
  };
85
85
  }
86
86
 
87
- /** Outcome of PushService.subscribe — distinguishes the three response shapes
88
- * the route handler maps to HTTP status (503 unavailable / 500 store_failed /
89
- * 200 ok). */
87
+ /** Outcome of PushService.subscribe — distinguishes the response shapes the
88
+ * route handler maps to HTTP status (503 unavailable / 409 no_member /
89
+ * 500 store_failed / 200 ok). */
90
90
  type PushSubscribeResult =
91
91
  | { ok: true }
92
- | { ok: false; reason: "unavailable" | "store_failed" };
92
+ | { ok: false; reason: "unavailable" | "store_failed" | "no_member" };
93
93
 
94
94
  /** Outcome of PushService.unsubscribe — delete failures are swallowed/logged
95
95
  * inside the service (best-effort), so only "unavailable" (model missing) is
@@ -344,6 +344,9 @@ export class PushService {
344
344
  return { ok: false, reason: "unavailable" };
345
345
  try {
346
346
  const memberId = await this.memberIdForEmail(userEmail);
347
+ // No account member record: nothing to attach the subscription to, so
348
+ // store nothing and let the caller say why.
349
+ if (!memberId) return { ok: false, reason: "no_member" };
347
350
  await this.prisma.pushSubscription.upsert({
348
351
  where: { endpoint },
349
352
  create: { userEmail, memberId, endpoint, p256dh, auth },
@@ -597,6 +597,30 @@ describe("PushService.subscribe", () => {
597
597
  ]);
598
598
  });
599
599
 
600
+ it("returns reason:no_member and stores nothing when the email has no member record", async () => {
601
+ const calls: unknown[] = [];
602
+ const prisma = {
603
+ chatThreadWatch: { findMany: async () => [] },
604
+ pushSubscription: {
605
+ findMany: async () => [],
606
+ deleteMany: async () => ({ count: 0 }),
607
+ upsert: async (args: unknown) => {
608
+ calls.push(args);
609
+ return { id: "sub_1" };
610
+ },
611
+ },
612
+ };
613
+ const service = makeService(prisma as never, vapid, unusedFetch, "title");
614
+ const result = await service.subscribe(
615
+ "nobody@x.com",
616
+ "https://push/ok",
617
+ P256DH,
618
+ AUTH,
619
+ );
620
+ expect(result).toEqual({ ok: false, reason: "no_member" });
621
+ expect(calls).toEqual([]);
622
+ });
623
+
600
624
  it("returns reason:unavailable when the pushSubscription model is absent", async () => {
601
625
  const prisma = {
602
626
  chatThreadWatch: { findMany: async () => [] },
@@ -126,6 +126,16 @@ export function renderPushToggle(args: PushToggleArgs): string {
126
126
  window.location.href = '/admin/login?returnTo=' + encodeURIComponent(location.pathname + location.search);
127
127
  return;
128
128
  }
129
+ if (res && res.status === 409) {
130
+ btn.disabled = false;
131
+ setStatus("Notifications can't be enabled: your account has no member record. Ask an owner or admin to add you.");
132
+ return;
133
+ }
134
+ if (res && !res.ok) {
135
+ btn.disabled = false;
136
+ setStatus("Notifications couldn't be enabled. Please try again.");
137
+ return;
138
+ }
129
139
  setStatus('Notifications enabled.');
130
140
  btn.textContent = 'Notifications on';
131
141
  });
@@ -5,7 +5,7 @@
5
5
  * injected env object (no process.env reads) so it is deterministically
6
6
  * unit-testable; admin-boot reads it once at startup and feeds it into the
7
7
  * config bundle as `features.repoAccessCheck`. Same "enabled" convention as
8
- * transcript-config.ts.
8
+ * the other platform feature flags.
9
9
  */
10
10
 
11
11
  type RepoAccessEnv = Readonly<Record<string, string | undefined>>;