@orgsdk/cli 2.4.0 → 2.5.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 (59) hide show
  1. package/dist/server/index.js +1454 -1229
  2. package/dist/server/out/_next/static/chunks/25c5dxwc-_9-y.css +1 -0
  3. package/dist/server/out/accounts/2fa/__next._full.txt +2 -2
  4. package/dist/server/out/accounts/2fa/__next._tree.txt +2 -2
  5. package/dist/server/out/accounts/2fa/__next.accounts.2fa.__PAGE__.txt +2 -2
  6. package/dist/server/out/accounts/2fa/index.html +1 -1
  7. package/dist/server/out/accounts/2fa/index.txt +2 -2
  8. package/dist/server/out/accounts/email/__next._full.txt +2 -2
  9. package/dist/server/out/accounts/email/__next._tree.txt +2 -2
  10. package/dist/server/out/accounts/email/__next.accounts.email.__PAGE__.txt +2 -2
  11. package/dist/server/out/accounts/email/index.html +1 -1
  12. package/dist/server/out/accounts/email/index.txt +2 -2
  13. package/dist/server/out/accounts/login/__next._full.txt +2 -2
  14. package/dist/server/out/accounts/login/__next._tree.txt +2 -2
  15. package/dist/server/out/accounts/login/__next.accounts.login.__PAGE__.txt +2 -2
  16. package/dist/server/out/accounts/login/index.html +1 -1
  17. package/dist/server/out/accounts/login/index.txt +2 -2
  18. package/dist/server/out/accounts/logout/__next._full.txt +2 -2
  19. package/dist/server/out/accounts/logout/__next._tree.txt +2 -2
  20. package/dist/server/out/accounts/logout/__next.accounts.logout.__PAGE__.txt +2 -2
  21. package/dist/server/out/accounts/logout/index.html +1 -1
  22. package/dist/server/out/accounts/logout/index.txt +2 -2
  23. package/dist/server/out/accounts/password/change/__next._full.txt +2 -2
  24. package/dist/server/out/accounts/password/change/__next._tree.txt +2 -2
  25. package/dist/server/out/accounts/password/change/__next.accounts.password.change.__PAGE__.txt +2 -2
  26. package/dist/server/out/accounts/password/change/index.html +1 -1
  27. package/dist/server/out/accounts/password/change/index.txt +2 -2
  28. package/dist/server/out/accounts/password/reset/__next._full.txt +2 -2
  29. package/dist/server/out/accounts/password/reset/__next._tree.txt +2 -2
  30. package/dist/server/out/accounts/password/reset/__next.accounts.password.reset.__PAGE__.txt +2 -2
  31. package/dist/server/out/accounts/password/reset/index.html +1 -1
  32. package/dist/server/out/accounts/password/reset/index.txt +2 -2
  33. package/dist/server/out/accounts/signup/__next._full.txt +2 -2
  34. package/dist/server/out/accounts/signup/__next._tree.txt +2 -2
  35. package/dist/server/out/accounts/signup/__next.accounts.signup.__PAGE__.txt +2 -2
  36. package/dist/server/out/accounts/signup/index.html +1 -1
  37. package/dist/server/out/accounts/signup/index.txt +2 -2
  38. package/dist/server/out/setup/__next._full.txt +2 -2
  39. package/dist/server/out/setup/__next._tree.txt +2 -2
  40. package/dist/server/out/setup/__next.setup.__PAGE__.txt +2 -2
  41. package/dist/server/out/setup/index.html +1 -1
  42. package/dist/server/out/setup/index.txt +2 -2
  43. package/dist/server/out/studio/approve/__next._full.txt +2 -2
  44. package/dist/server/out/studio/approve/__next._tree.txt +2 -2
  45. package/dist/server/out/studio/approve/__next.studio.approve.__PAGE__.txt +2 -2
  46. package/dist/server/out/studio/approve/index.html +1 -1
  47. package/dist/server/out/studio/approve/index.txt +2 -2
  48. package/dist/server/out/workspaces/invite/__next._full.txt +2 -2
  49. package/dist/server/out/workspaces/invite/__next._tree.txt +2 -2
  50. package/dist/server/out/workspaces/invite/__next.workspaces.invite.__PAGE__.txt +2 -2
  51. package/dist/server/out/workspaces/invite/index.html +1 -1
  52. package/dist/server/out/workspaces/invite/index.txt +2 -2
  53. package/docs/browser-sessions.md +9 -1
  54. package/docs/studio.md +1 -1
  55. package/package.json +1 -1
  56. package/dist/server/out/_next/static/chunks/3sosg03i0fln5.css +0 -1
  57. /package/dist/server/out/_next/static/{0NTIafP_LEunaRNPmLkWC → ZYEa1gn9Rpn2bc5hLoE4o}/_buildManifest.js +0 -0
  58. /package/dist/server/out/_next/static/{0NTIafP_LEunaRNPmLkWC → ZYEa1gn9Rpn2bc5hLoE4o}/_clientMiddlewareManifest.js +0 -0
  59. /package/dist/server/out/_next/static/{0NTIafP_LEunaRNPmLkWC → ZYEa1gn9Rpn2bc5hLoE4o}/_ssgManifest.js +0 -0
@@ -1211,10 +1211,10 @@ async function finishMcpOAuth(ctx, input2) {
1211
1211
 
1212
1212
  // server/http/api.ts
1213
1213
  import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
1214
- import { ZodError as ZodError2 } from "zod";
1214
+ import { ZodError as ZodError3 } from "zod";
1215
1215
 
1216
1216
  // server/api/mcp-dispatch.ts
1217
- import { z as z48 } from "zod";
1217
+ import { z as z50 } from "zod";
1218
1218
 
1219
1219
  // server/actions/schemas.ts
1220
1220
  import { z as z8 } from "zod";
@@ -1295,22 +1295,399 @@ async function input(request) {
1295
1295
  }
1296
1296
  }
1297
1297
 
1298
+ // server/plugins/settings.ts
1299
+ import { z as z14 } from "zod";
1300
+
1301
+ // server/credentials/schemas.ts
1302
+ import { z as z10 } from "zod";
1303
+ var credentialName = z10.string().trim().min(1).max(100).refine((value) => !value.includes("\0"));
1304
+ var credentialSecret = z10.record(z10.string(), z10.json()).refine(
1305
+ (secret) => Object.keys(secret).length > 0 && Buffer.byteLength(JSON.stringify(secret)) <= 32e3,
1306
+ "Supply a nonempty secret object under 32KB."
1307
+ );
1308
+ var credentialSchema = z10.object({
1309
+ id: z10.uuid(),
1310
+ name: z10.string(),
1311
+ provider: z10.string()
1312
+ });
1313
+ var credentialCreateSchema = z10.strictObject({
1314
+ name: credentialName,
1315
+ provider: credentialName,
1316
+ secret: credentialSecret
1317
+ });
1318
+ var updateCredentialSchema = credentialCreateSchema.partial();
1319
+ var credentialIdSchema = z10.strictObject({ id: z10.uuid() });
1320
+ var credentialChangesSchema = updateCredentialSchema.extend({
1321
+ id: z10.uuid()
1322
+ });
1323
+
1324
+ // server/domain/permissions.ts
1325
+ function workspace(ctx) {
1326
+ return requireWorkspace(ctx).id;
1327
+ }
1328
+ function scope(ctx, required) {
1329
+ if (ctx.token && (ctx.token.revoked || !ctx.token.scopes.includes(required))) {
1330
+ throw new ServiceError(
1331
+ "FORBIDDEN",
1332
+ "Client scope does not permit this operation."
1333
+ );
1334
+ }
1335
+ }
1336
+ function projectGrant(ctx, id) {
1337
+ if (ctx.token && !ctx.token.projects.includes(id)) {
1338
+ throw new ServiceError("FORBIDDEN", "Project is outside the client grant.");
1339
+ }
1340
+ }
1341
+ function authorizeVersion(ctx, action, version2, explicit) {
1342
+ if (!ctx.token) {
1343
+ return;
1344
+ }
1345
+ if (ctx.token.projects.includes(action.projectId)) {
1346
+ return;
1347
+ }
1348
+ if (explicit && ctx.token.actionVersions.includes(version2.id)) {
1349
+ return;
1350
+ }
1351
+ throw new ServiceError(
1352
+ "FORBIDDEN",
1353
+ "Client requires an explicit granted action version."
1354
+ );
1355
+ }
1356
+ function authorizeRunRead(ctx, run, requestedScope = "runs:read") {
1357
+ if (requestedScope) {
1358
+ scope(ctx, requestedScope);
1359
+ }
1360
+ if (ctx.token && (run.tokenId !== ctx.token.id || !(ctx.token.projects.includes(run.projectId) || run.actionVersionId && ctx.token.actionVersions.includes(run.actionVersionId)))) {
1361
+ throw new ServiceError("NOT_FOUND", "Not found.");
1362
+ }
1363
+ }
1364
+
1365
+ // server/repositories/plugins.ts
1366
+ import { and as and7, eq as eq7 } from "drizzle-orm";
1367
+ function pluginsRepository(context) {
1368
+ const workspaceId = requireWorkspace(context).id;
1369
+ const database = context.db;
1370
+ const scoped = (id, filter) => and7(
1371
+ eq7(plugins.workspaceId, workspaceId),
1372
+ id === void 0 ? void 0 : eq7(plugins.id, id),
1373
+ filter
1374
+ );
1375
+ return {
1376
+ find(id) {
1377
+ const row = database.select().from(plugins).where(scoped(id)).get();
1378
+ if (!row) {
1379
+ throw new ServiceError("NOT_FOUND", "Not found.");
1380
+ }
1381
+ return row;
1382
+ },
1383
+ list(filter) {
1384
+ return database.select().from(plugins).where(scoped(void 0, filter)).all();
1385
+ }
1386
+ };
1387
+ }
1388
+
1389
+ // server/plugins/shell-policy.ts
1390
+ import { and as and9, eq as eq9, gt as gt2, inArray as inArray3, sql } from "drizzle-orm";
1391
+
1392
+ // server/runs/resume-after-approval.ts
1393
+ import { and as and8, eq as eq8, notExists } from "drizzle-orm";
1394
+ function resumeAfterApproval(ctx, runId) {
1395
+ const pending = ctx.db.select({ id: approvals.id }).from(approvals).where(and8(eq8(approvals.runId, runId), eq8(approvals.status, "pending")));
1396
+ ctx.db.update(runs).set({ status: "running", updatedAt: now() }).where(
1397
+ and8(
1398
+ eq8(runs.id, runId),
1399
+ eq8(runs.status, "waiting_approval"),
1400
+ eq8(runs.cancelRequested, false),
1401
+ notExists(pending)
1402
+ )
1403
+ ).run();
1404
+ }
1405
+
1406
+ // server/plugins/shell-policy.ts
1407
+ import { z as z13 } from "zod";
1408
+
1409
+ // server/shared/contracts.ts
1410
+ import { z as z12 } from "zod";
1411
+
1412
+ // server/shared/action-tests.ts
1413
+ import { z as z11 } from "zod";
1414
+ var toolName = z11.string().max(201).regex(/^[a-z][a-zA-Z0-9]*(?:\.[a-z][a-zA-Z0-9]*)?$/);
1415
+ var mockSchema = z11.strictObject({
1416
+ tool: toolName,
1417
+ args: z11.array(z11.json()).max(30),
1418
+ result: z11.json().optional(),
1419
+ error: z11.string().optional(),
1420
+ times: z11.number().int().min(1).max(100).default(1)
1421
+ }).refine(
1422
+ (mock) => Object.hasOwn(mock, "result") !== Object.hasOwn(mock, "error"),
1423
+ "Supply a result or error."
1424
+ );
1425
+ var casesSchema = z11.array(
1426
+ z11.strictObject({
1427
+ name: z11.string().trim().min(1).max(200),
1428
+ inputs: z11.record(z11.string(), z11.json()),
1429
+ expected: z11.json(),
1430
+ mocks: z11.array(mockSchema).max(100).default([]),
1431
+ forbidden_calls: z11.array(toolName).max(100).default([])
1432
+ })
1433
+ ).min(1).max(50);
1434
+ function validateCases(version2, value) {
1435
+ const parsed = casesSchema.safeParse(value);
1436
+ if (!parsed.success || Buffer.byteLength(JSON.stringify(parsed.data)) > 2e5) {
1437
+ throw new ServiceError(
1438
+ "BAD_REQUEST",
1439
+ "Provide 1 to 50 valid bounded test cases."
1440
+ );
1441
+ }
1442
+ const names = /* @__PURE__ */ new Set();
1443
+ for (const testCase of parsed.data) {
1444
+ if (names.has(testCase.name)) {
1445
+ throw new ServiceError("BAD_REQUEST", "Test case names must be unique.");
1446
+ }
1447
+ names.add(testCase.name);
1448
+ validateContract(version2.inputSchema, testCase.inputs);
1449
+ validateContract(version2.outputSchema, testCase.expected);
1450
+ }
1451
+ return parsed.data.map((testCase) => ({
1452
+ ...testCase,
1453
+ mocks: testCase.mocks.map((mock) => ({
1454
+ tool: mock.tool,
1455
+ args: mock.args,
1456
+ times: mock.times,
1457
+ ...mock.error === void 0 ? { result: mock.result ?? null } : { error: mock.error }
1458
+ }))
1459
+ }));
1460
+ }
1461
+
1462
+ // server/shared/contracts.ts
1463
+ import Ajv from "ajv/dist/2020.js";
1464
+ var object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
1465
+ var jsonValue = (value, name) => {
1466
+ if (!object(value) || JSON.stringify(value).includes("\\u0000") || Buffer.byteLength(JSON.stringify(value)) > 2e5) {
1467
+ throw new ServiceError(
1468
+ "BAD_REQUEST",
1469
+ `${name} must be an object under 200KB.`
1470
+ );
1471
+ }
1472
+ const parsed = z12.record(z12.string(), z12.json()).safeParse(value);
1473
+ if (!parsed.success) {
1474
+ throw new ServiceError("BAD_REQUEST", `${name} must contain JSON values.`);
1475
+ }
1476
+ return parsed.data;
1477
+ };
1478
+ var sourceText = (value) => {
1479
+ if (typeof value !== "string" || !value.trim() || value.includes("\0") || Buffer.byteLength(value) > 2e5) {
1480
+ throw new ServiceError(
1481
+ "BAD_REQUEST",
1482
+ "Source must be nonblank UTF-8 text under 200KB, without NUL."
1483
+ );
1484
+ }
1485
+ return value;
1486
+ };
1487
+ function schema(value) {
1488
+ const result = jsonValue(value ?? {}, "Schema");
1489
+ let count3 = 0;
1490
+ const pending = [[result, 0]];
1491
+ while (pending.length) {
1492
+ const [node, depth] = pending.pop();
1493
+ if (++count3 > 2e3 || depth > 30) {
1494
+ throw new ServiceError("BAD_REQUEST", "JSON Schema is too complex.");
1495
+ }
1496
+ if (object(node)) {
1497
+ if (["$ref", "$dynamicRef", "$recursiveRef"].some((key) => key in node)) {
1498
+ throw new ServiceError(
1499
+ "BAD_REQUEST",
1500
+ "Use inline JSON Schemas without reference keywords."
1501
+ );
1502
+ }
1503
+ for (const value2 of Object.values(node)) {
1504
+ if (value2 && typeof value2 === "object") {
1505
+ pending.push([value2, depth + 1]);
1506
+ }
1507
+ }
1508
+ } else if (Array.isArray(node)) {
1509
+ for (const value2 of node) {
1510
+ if (value2 && typeof value2 === "object") {
1511
+ pending.push([value2, depth + 1]);
1512
+ }
1513
+ }
1514
+ }
1515
+ }
1516
+ try {
1517
+ new Ajv({ strict: false }).compile(result);
1518
+ } catch {
1519
+ throw new ServiceError("BAD_REQUEST", "Invalid JSON Schema.");
1520
+ }
1521
+ return result;
1522
+ }
1523
+ function validateContract(contract, value) {
1524
+ try {
1525
+ if (!new Ajv({ strict: false }).compile(contract)(value)) {
1526
+ throw new ServiceError(
1527
+ "BAD_REQUEST",
1528
+ "Inputs do not match the action schema."
1529
+ );
1530
+ }
1531
+ } catch (error) {
1532
+ if (error instanceof ServiceError) {
1533
+ throw error;
1534
+ }
1535
+ throw new ServiceError("BAD_REQUEST", "Invalid action schema.");
1536
+ }
1537
+ }
1538
+ function validateColumns(columns2) {
1539
+ const parsed = z12.array(
1540
+ z12.strictObject({
1541
+ key: z12.string().regex(/^[a-z][a-z0-9_]{0,47}$/),
1542
+ type: z12.enum(["text", "number", "boolean", "date"]),
1543
+ required: z12.boolean()
1544
+ })
1545
+ ).min(1).max(50).safeParse(columns2);
1546
+ if (!parsed.success || new Set(parsed.data.map((column) => column.key)).size !== parsed.data.length) {
1547
+ throw new ServiceError("BAD_REQUEST", "Invalid table columns.");
1548
+ }
1549
+ return parsed.data;
1550
+ }
1551
+ function validateValues(columns2, values2) {
1552
+ if (!object(values2) || Object.keys(values2).some(
1553
+ (key) => !columns2.some((column) => column.key === key)
1554
+ )) {
1555
+ throw new ServiceError("BAD_REQUEST", "Use only defined column keys.");
1556
+ }
1557
+ for (const column of columns2) {
1558
+ const value = values2[column.key];
1559
+ if (value == null) {
1560
+ if (column.required) {
1561
+ throw new ServiceError("BAD_REQUEST", `${column.key} is required.`);
1562
+ }
1563
+ continue;
1564
+ }
1565
+ const valid = column.type === "text" ? typeof value === "string" && value.length <= 1e4 && !value.includes("\0") && (!column.required || !!value.trim()) : column.type === "number" ? typeof value === "number" && Number.isFinite(value) && Math.abs(value) <= 1e100 : column.type === "boolean" ? typeof value === "boolean" : typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value) && !Number.isNaN(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
1566
+ if (!valid) {
1567
+ throw new ServiceError("BAD_REQUEST", `Invalid value for ${column.key}.`);
1568
+ }
1569
+ }
1570
+ jsonValue(values2, "Values");
1571
+ }
1572
+
1573
+ // server/plugins/shell-policy.ts
1574
+ var executableName = z13.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.+-]{0,127}$/);
1575
+ var ruleDecision = z13.enum(["allow", "block", "ask"]);
1576
+ function supportsShellPolicy(plugin) {
1577
+ const tools2 = plugin.releaseMetadata.tools;
1578
+ return plugin.slug === "shell" && plugin.distribution === "external" && Array.isArray(tools2) && tools2.some(
1579
+ (tool) => object(tool) && tool.name === "run" && object(tool.metadata) && tool.metadata.approval === "shell-executable"
1580
+ );
1581
+ }
1582
+ function writeShellRule(ctx, plugin, executable, decision) {
1583
+ const pluginId = plugin.id;
1584
+ if (decision === "ask") {
1585
+ ctx.db.delete(shellRules).where(
1586
+ and9(
1587
+ eq9(shellRules.pluginId, pluginId),
1588
+ eq9(shellRules.executable, executable)
1589
+ )
1590
+ ).run();
1591
+ } else {
1592
+ ctx.db.insert(shellRules).values({ pluginId, executable, decision }).onConflictDoUpdate({
1593
+ target: [shellRules.pluginId, shellRules.executable],
1594
+ set: { decision }
1595
+ }).run();
1596
+ }
1597
+ if (decision !== "ask") {
1598
+ const currentTime = now();
1599
+ const liveRunIds = ctx.db.select({ id: runs.id }).from(runs).where(
1600
+ and9(
1601
+ eq9(runs.projectId, plugin.projectId),
1602
+ eq9(runs.workspaceId, plugin.workspaceId),
1603
+ eq9(runs.cancelRequested, false),
1604
+ eq9(runs.status, "waiting_approval"),
1605
+ gt2(runs.leaseExpiresAt, currentTime),
1606
+ gt2(runs.deadline, currentTime)
1607
+ )
1608
+ );
1609
+ const changed = ctx.db.update(approvals).set({
1610
+ status: decision === "allow" ? "approved" : "denied",
1611
+ decidedBy: ctx.user?.id,
1612
+ updatedAt: currentTime
1613
+ }).where(
1614
+ and9(
1615
+ eq9(approvals.workspaceId, plugin.workspaceId),
1616
+ eq9(approvals.status, "pending"),
1617
+ inArray3(approvals.runId, liveRunIds),
1618
+ sql`json_extract(${approvals.shell}, '$.pluginId') = ${plugin.id} and json_extract(${approvals.shell}, '$.digest') = ${plugin.digest} and json_extract(${approvals.shell}, '$.executable') = ${executable}`
1619
+ )
1620
+ ).returning({ id: approvals.id, runId: approvals.runId }).all();
1621
+ for (const row of changed) {
1622
+ recordAudit(ctx, "approval", row.id, "updated");
1623
+ resumeAfterApproval(ctx, row.runId);
1624
+ }
1625
+ }
1626
+ recordAudit(ctx, "shell_rule", pluginId + "/" + executable, decision);
1627
+ }
1628
+
1629
+ // server/plugins/settings.ts
1630
+ var configurePluginSchema = z14.strictObject({
1631
+ id: z14.uuid(),
1632
+ revision: z14.string().regex(/^[a-f\d]{64}$/),
1633
+ configuration: z14.record(z14.string(), z14.json()).optional(),
1634
+ credential: credentialCreateSchema.omit({ provider: true }).nullable().optional()
1635
+ }).refine(
1636
+ (input2) => input2.configuration !== void 0 || input2.credential !== void 0,
1637
+ "Supply configuration or a credential change."
1638
+ );
1639
+ function canConfigurePlugin(plugin) {
1640
+ return plugin.distribution === "external" && !supportsShellPolicy(plugin);
1641
+ }
1642
+ function findConfigurablePlugin(context, id) {
1643
+ const plugin = pluginsRepository(context).find(id);
1644
+ projectGrant(context, plugin.projectId);
1645
+ if (!canConfigurePlugin(plugin)) {
1646
+ throw new ServiceError("BAD_REQUEST", "Configure this plugin in Studio.");
1647
+ }
1648
+ return plugin;
1649
+ }
1650
+ function pluginSettings(plugin) {
1651
+ return {
1652
+ id: plugin.id,
1653
+ project: plugin.projectId,
1654
+ slug: plugin.slug,
1655
+ version: plugin.version,
1656
+ enabled: plugin.enabled,
1657
+ configuration: plugin.configuration,
1658
+ configuration_schema: plugin.releaseMetadata.configuration_schema ?? {},
1659
+ credential_connected: plugin.credentialId !== null,
1660
+ credential_provider: plugin.releaseMetadata.auth?.provider ?? null,
1661
+ credential_auth_type: plugin.releaseMetadata.auth?.type ?? null,
1662
+ revision: digest(
1663
+ JSON.stringify([
1664
+ plugin.digest,
1665
+ plugin.version,
1666
+ plugin.configuration,
1667
+ plugin.credentialId,
1668
+ plugin.releaseMetadata.configuration_schema,
1669
+ plugin.releaseMetadata.auth
1670
+ ])
1671
+ )
1672
+ };
1673
+ }
1674
+
1298
1675
  // server/router/procedures.ts
1299
1676
  import { initTRPC, TRPCError } from "@trpc/server";
1300
1677
  import { ZodError } from "zod";
1301
1678
 
1302
1679
  // server/repositories/identity.ts
1303
- import { and as and7, eq as eq7 } from "drizzle-orm";
1680
+ import { and as and10, eq as eq10 } from "drizzle-orm";
1304
1681
 
1305
1682
  // server/tokens/access-token.ts
1306
- import { z as z10 } from "zod";
1683
+ import { z as z15 } from "zod";
1307
1684
  var mcpTokenPrefix = "orgsdk_mcp_";
1308
- var mcpAccessTokenSchema = z10.templateLiteral([
1685
+ var mcpAccessTokenSchema = z15.templateLiteral([
1309
1686
  mcpTokenPrefix,
1310
- z10.string().regex(/[A-Za-z0-9_-]{43}/)
1687
+ z15.string().regex(/[A-Za-z0-9_-]{43}/)
1311
1688
  ]);
1312
- var issuedMcpAccessTokenSchema = z10.object({
1313
- id: z10.uuid(),
1689
+ var issuedMcpAccessTokenSchema = z15.object({
1690
+ id: z15.uuid(),
1314
1691
  token: mcpAccessTokenSchema
1315
1692
  });
1316
1693
  function issueMcpAccessToken() {
@@ -1324,35 +1701,35 @@ function mcpAccessTokenDigest(token) {
1324
1701
  function identityRepository(database) {
1325
1702
  return {
1326
1703
  workspaceForHost(host) {
1327
- return database.select().from(workspaces).where(eq7(workspaces.host, host)).get();
1704
+ return database.select().from(workspaces).where(eq10(workspaces.host, host)).get();
1328
1705
  },
1329
1706
  anyWorkspace() {
1330
1707
  return database.select().from(workspaces).get();
1331
1708
  },
1332
1709
  user(id) {
1333
- return database.select().from(users).where(eq7(users.id, id)).get();
1710
+ return database.select().from(users).where(eq10(users.id, id)).get();
1334
1711
  },
1335
1712
  userByEmail(email) {
1336
- return database.select().from(users).where(eq7(users.email, email)).get();
1713
+ return database.select().from(users).where(eq10(users.email, email)).get();
1337
1714
  },
1338
1715
  session(id) {
1339
- return database.select().from(sessions).where(eq7(sessions.id, id)).get();
1716
+ return database.select().from(sessions).where(eq10(sessions.id, id)).get();
1340
1717
  },
1341
1718
  activeClientToken(workspaceId, token) {
1342
1719
  const tokenDigest = mcpAccessTokenDigest(token);
1343
1720
  return database.select().from(accessTokens).where(
1344
- and7(
1345
- eq7(accessTokens.digest, tokenDigest),
1346
- eq7(accessTokens.workspaceId, workspaceId),
1347
- eq7(accessTokens.revoked, false)
1721
+ and10(
1722
+ eq10(accessTokens.digest, tokenDigest),
1723
+ eq10(accessTokens.workspaceId, workspaceId),
1724
+ eq10(accessTokens.revoked, false)
1348
1725
  )
1349
1726
  ).get();
1350
1727
  },
1351
1728
  membership(workspaceId, userId) {
1352
1729
  return database.select().from(memberships).where(
1353
- and7(
1354
- eq7(memberships.workspaceId, workspaceId),
1355
- eq7(memberships.userId, userId)
1730
+ and10(
1731
+ eq10(memberships.workspaceId, workspaceId),
1732
+ eq10(memberships.userId, userId)
1356
1733
  )
1357
1734
  ).get();
1358
1735
  }
@@ -1469,7 +1846,7 @@ function checkClientRequest(ctx, operationType = ctx.operationType) {
1469
1846
  }
1470
1847
 
1471
1848
  // server/auth/sessions.ts
1472
- import { eq as eq8 } from "drizzle-orm";
1849
+ import { eq as eq11 } from "drizzle-orm";
1473
1850
  function rotateSession(ctx, userId, pendingUserId = null, guard, mutation) {
1474
1851
  const secret = randomSecret();
1475
1852
  const id = ctx.studioOrigin ? studioLoginSessionId(ctx.origin, ctx.studioOrigin, secret) : digest(secret);
@@ -1485,7 +1862,7 @@ function rotateSession(ctx, userId, pendingUserId = null, guard, mutation) {
1485
1862
  }
1486
1863
  mutation?.(ctx2);
1487
1864
  if (ctx2.sessionId) {
1488
- ctx2.db.delete(sessions).where(eq8(sessions.id, ctx2.sessionId)).run();
1865
+ ctx2.db.delete(sessions).where(eq11(sessions.id, ctx2.sessionId)).run();
1489
1866
  }
1490
1867
  ctx2.db.insert(sessions).values({
1491
1868
  id,
@@ -1521,67 +1898,26 @@ function assertCurrentUser(ctx, user, withSession = true) {
1521
1898
  "Your account changed. Sign in again."
1522
1899
  );
1523
1900
  }
1524
- if (withSession) {
1525
- requireCurrentSession(ctx, user.id);
1526
- }
1527
- }
1528
- function requireCurrentSession(ctx, userId) {
1529
- const session = ctx.sessionId ? identityRepository(ctx.db).session(ctx.sessionId) : void 0;
1530
- if (!session || session.userId !== userId || session.expiresAt <= Date.now()) {
1531
- throw new ServiceError(
1532
- "UNAUTHORIZED",
1533
- "Your session has expired. Sign in again."
1534
- );
1535
- }
1536
- return session;
1537
- }
1538
- function markFresh(ctx, user) {
1539
- inTransaction(ctx, (ctx2) => {
1540
- assertCurrentUser(ctx2, user, false);
1541
- const session = requireCurrentSession(ctx2, user.id);
1542
- ctx2.db.update(sessions).set({ reauthenticatedAt: Date.now() }).where(eq8(sessions.id, session.id)).run();
1543
- });
1544
- }
1545
-
1546
- // server/domain/permissions.ts
1547
- function workspace(ctx) {
1548
- return requireWorkspace(ctx).id;
1549
- }
1550
- function scope(ctx, required) {
1551
- if (ctx.token && (ctx.token.revoked || !ctx.token.scopes.includes(required))) {
1552
- throw new ServiceError(
1553
- "FORBIDDEN",
1554
- "Client scope does not permit this operation."
1555
- );
1556
- }
1557
- }
1558
- function projectGrant(ctx, id) {
1559
- if (ctx.token && !ctx.token.projects.includes(id)) {
1560
- throw new ServiceError("FORBIDDEN", "Project is outside the client grant.");
1561
- }
1562
- }
1563
- function authorizeVersion(ctx, action, version2, explicit) {
1564
- if (!ctx.token) {
1565
- return;
1566
- }
1567
- if (ctx.token.projects.includes(action.projectId)) {
1568
- return;
1569
- }
1570
- if (explicit && ctx.token.actionVersions.includes(version2.id)) {
1571
- return;
1572
- }
1573
- throw new ServiceError(
1574
- "FORBIDDEN",
1575
- "Client requires an explicit granted action version."
1576
- );
1577
- }
1578
- function authorizeRunRead(ctx, run, requestedScope = "runs:read") {
1579
- if (requestedScope) {
1580
- scope(ctx, requestedScope);
1901
+ if (withSession) {
1902
+ requireCurrentSession(ctx, user.id);
1581
1903
  }
1582
- if (ctx.token && (run.tokenId !== ctx.token.id || !(ctx.token.projects.includes(run.projectId) || run.actionVersionId && ctx.token.actionVersions.includes(run.actionVersionId)))) {
1583
- throw new ServiceError("NOT_FOUND", "Not found.");
1904
+ }
1905
+ function requireCurrentSession(ctx, userId) {
1906
+ const session = ctx.sessionId ? identityRepository(ctx.db).session(ctx.sessionId) : void 0;
1907
+ if (!session || session.userId !== userId || session.expiresAt <= Date.now()) {
1908
+ throw new ServiceError(
1909
+ "UNAUTHORIZED",
1910
+ "Your session has expired. Sign in again."
1911
+ );
1584
1912
  }
1913
+ return session;
1914
+ }
1915
+ function markFresh(ctx, user) {
1916
+ inTransaction(ctx, (ctx2) => {
1917
+ assertCurrentUser(ctx2, user, false);
1918
+ const session = requireCurrentSession(ctx2, user.id);
1919
+ ctx2.db.update(sessions).set({ reauthenticatedAt: Date.now() }).where(eq11(sessions.id, session.id)).run();
1920
+ });
1585
1921
  }
1586
1922
 
1587
1923
  // server/router/procedures.ts
@@ -1710,26 +2046,32 @@ function scopedProcedure(required) {
1710
2046
  return next();
1711
2047
  });
1712
2048
  }
2049
+ function scopedManagerProcedure(required) {
2050
+ return scopedProcedure(required).use(({ ctx, next }) => {
2051
+ requireManager(ctx);
2052
+ return next();
2053
+ });
2054
+ }
1713
2055
 
1714
2056
  // server/router/actions/list.ts
1715
- import { and as and9, eq as eq10 } from "drizzle-orm";
2057
+ import { and as and12, eq as eq13 } from "drizzle-orm";
1716
2058
 
1717
2059
  // server/actions/queries.ts
1718
- import { and as and8, eq as eq9, inArray as inArray3, or } from "drizzle-orm";
2060
+ import { and as and11, eq as eq12, inArray as inArray4, or } from "drizzle-orm";
1719
2061
  function actionGrant(ctx) {
1720
2062
  const token = ctx.token;
1721
2063
  if (!token) {
1722
2064
  return void 0;
1723
2065
  }
1724
2066
  const grantedActions = ctx.db.select({ id: actionVersions.actionId }).from(actionVersions).where(
1725
- and8(
1726
- eq9(actionVersions.workspaceId, workspace(ctx)),
1727
- inArray3(actionVersions.id, token.actionVersions)
2067
+ and11(
2068
+ eq12(actionVersions.workspaceId, workspace(ctx)),
2069
+ inArray4(actionVersions.id, token.actionVersions)
1728
2070
  )
1729
2071
  );
1730
2072
  return or(
1731
- inArray3(actions.projectId, token.projects),
1732
- inArray3(actions.id, grantedActions)
2073
+ inArray4(actions.projectId, token.projects),
2074
+ inArray4(actions.id, grantedActions)
1733
2075
  );
1734
2076
  }
1735
2077
 
@@ -1740,295 +2082,131 @@ function serializeAction(row) {
1740
2082
  project: row.projectId,
1741
2083
  name: row.name,
1742
2084
  description: row.description,
1743
- enabled: row.enabled
1744
- };
1745
- }
1746
- function serializeVersion(row) {
1747
- return {
1748
- id: row.id,
1749
- number: row.number,
1750
- source: row.source,
1751
- input_schema: row.inputSchema,
1752
- output_schema: row.outputSchema,
1753
- validation_mode: row.validationMode,
1754
- sdk_contract: row.sdkContract,
1755
- promoted_from: row.promotedFrom,
1756
- created_at: row.createdAt
1757
- };
1758
- }
1759
- function suiteView(suite) {
1760
- return {
1761
- id: suite.id,
1762
- version: suite.versionId,
1763
- revision: suite.number,
1764
- digest: suite.digest,
1765
- cases: suite.cases,
1766
- created_at: suite.createdAt
1767
- };
1768
- }
1769
-
1770
- // server/shared/pagination.ts
1771
- function page(results) {
1772
- return { count: results.length, next: null, previous: null, results };
1773
- }
1774
-
1775
- // server/router/actions/list.ts
1776
- var listProcedure = scopedProcedure("catalog:read").query(
1777
- ({ ctx }) => {
1778
- const visibleActions = ctx.db.select().from(actions).where(and9(eq10(actions.workspaceId, ctx.workspace.id), actionGrant(ctx))).all();
1779
- return page(visibleActions.map(serializeAction));
1780
- }
1781
- );
1782
-
1783
- // server/router/actions/get.ts
1784
- import { and as and10, eq as eq11 } from "drizzle-orm";
1785
- var getProcedure = scopedProcedure("catalog:read").input(actionIdSchema).query(({ ctx, input: input2 }) => {
1786
- const action = ctx.db.select().from(actions).where(
1787
- and10(
1788
- eq11(actions.workspaceId, ctx.workspace.id),
1789
- eq11(actions.id, input2.id),
1790
- actionGrant(ctx)
1791
- )
1792
- ).get();
1793
- if (!action) {
1794
- throw new ServiceError("NOT_FOUND", "Not found.");
1795
- }
1796
- return serializeAction(action);
1797
- });
1798
-
1799
- // server/router/actions/versions.ts
1800
- import { and as and12, desc, eq as eq13, inArray as inArray4 } from "drizzle-orm";
1801
-
1802
- // server/repositories/actions.ts
1803
- import { and as and11, eq as eq12 } from "drizzle-orm";
1804
- function actionsRepository(context) {
1805
- const workspaceId = requireWorkspace(context).id;
1806
- const database = context.db;
1807
- const scoped = (id) => and11(eq12(actions.workspaceId, workspaceId), eq12(actions.id, id));
1808
- return {
1809
- find(id) {
1810
- const row = database.select().from(actions).where(scoped(id)).get();
1811
- if (!row) {
1812
- throw new ServiceError("NOT_FOUND", "Not found.");
1813
- }
1814
- return row;
1815
- },
1816
- create(data) {
1817
- return inTransaction(context, (context2) => {
1818
- const database2 = context2.db;
1819
- const row = database2.insert(actions).values({ ...data, ...base(workspaceId) }).returning().get();
1820
- recordAudit(context2, "action", row.id, "created");
1821
- return row;
1822
- });
1823
- }
1824
- };
1825
- }
1826
-
1827
- // server/router/actions/versions.ts
1828
- var versionsProcedure = scopedProcedure("catalog:read").input(actionIdSchema).query(({ ctx, input: input2 }) => {
1829
- const action = actionsRepository(ctx).find(input2.id);
1830
- const token = ctx.token;
1831
- const versionGrant = token && !token.projects.includes(action.projectId) ? inArray4(actionVersions.id, token.actionVersions) : void 0;
1832
- const versions = ctx.db.select().from(actionVersions).where(
1833
- and12(
1834
- eq13(actionVersions.workspaceId, ctx.workspace.id),
1835
- eq13(actionVersions.actionId, action.id),
1836
- versionGrant
1837
- )
1838
- ).orderBy(desc(actionVersions.number)).all();
1839
- return versions.map(serializeVersion);
1840
- });
1841
-
1842
- // server/actions/versions.ts
1843
- import { and as and15, eq as eq16 } from "drizzle-orm";
1844
-
1845
- // server/repositories/action-versions.ts
1846
- import { and as and13, eq as eq14 } from "drizzle-orm";
1847
- function actionVersionsRepository(context) {
1848
- const workspaceId = requireWorkspace(context).id;
1849
- const database = context.db;
1850
- const scoped = (id) => and13(eq14(actionVersions.workspaceId, workspaceId), eq14(actionVersions.id, id));
1851
- return {
1852
- find(id) {
1853
- const row = database.select().from(actionVersions).where(scoped(id)).get();
1854
- if (!row) {
1855
- throw new ServiceError("NOT_FOUND", "Not found.");
1856
- }
1857
- return row;
1858
- },
1859
- create(data) {
1860
- return inTransaction(context, (context2) => {
1861
- const database2 = context2.db;
1862
- const row = database2.insert(actionVersions).values({ ...data, ...base(workspaceId) }).returning().get();
1863
- recordAudit(context2, "action.version", row.id, "created");
1864
- return row;
1865
- });
1866
- }
1867
- };
1868
- }
1869
-
1870
- // server/shared/contracts.ts
1871
- import { z as z12 } from "zod";
1872
-
1873
- // server/shared/action-tests.ts
1874
- import { z as z11 } from "zod";
1875
- var toolName = z11.string().max(201).regex(/^[a-z][a-zA-Z0-9]*(?:\.[a-z][a-zA-Z0-9]*)?$/);
1876
- var mockSchema = z11.strictObject({
1877
- tool: toolName,
1878
- args: z11.array(z11.json()).max(30),
1879
- result: z11.json().optional(),
1880
- error: z11.string().optional(),
1881
- times: z11.number().int().min(1).max(100).default(1)
1882
- }).refine(
1883
- (mock) => Object.hasOwn(mock, "result") !== Object.hasOwn(mock, "error"),
1884
- "Supply a result or error."
1885
- );
1886
- var casesSchema = z11.array(
1887
- z11.strictObject({
1888
- name: z11.string().trim().min(1).max(200),
1889
- inputs: z11.record(z11.string(), z11.json()),
1890
- expected: z11.json(),
1891
- mocks: z11.array(mockSchema).max(100).default([]),
1892
- forbidden_calls: z11.array(toolName).max(100).default([])
1893
- })
1894
- ).min(1).max(50);
1895
- function validateCases(version2, value) {
1896
- const parsed = casesSchema.safeParse(value);
1897
- if (!parsed.success || Buffer.byteLength(JSON.stringify(parsed.data)) > 2e5) {
1898
- throw new ServiceError(
1899
- "BAD_REQUEST",
1900
- "Provide 1 to 50 valid bounded test cases."
1901
- );
1902
- }
1903
- const names = /* @__PURE__ */ new Set();
1904
- for (const testCase of parsed.data) {
1905
- if (names.has(testCase.name)) {
1906
- throw new ServiceError("BAD_REQUEST", "Test case names must be unique.");
1907
- }
1908
- names.add(testCase.name);
1909
- validateContract(version2.inputSchema, testCase.inputs);
1910
- validateContract(version2.outputSchema, testCase.expected);
1911
- }
1912
- return parsed.data.map((testCase) => ({
1913
- ...testCase,
1914
- mocks: testCase.mocks.map((mock) => ({
1915
- tool: mock.tool,
1916
- args: mock.args,
1917
- times: mock.times,
1918
- ...mock.error === void 0 ? { result: mock.result ?? null } : { error: mock.error }
1919
- }))
1920
- }));
1921
- }
1922
-
1923
- // server/shared/contracts.ts
1924
- import Ajv from "ajv/dist/2020.js";
1925
- var object = (value) => !!value && typeof value === "object" && !Array.isArray(value);
1926
- var jsonValue = (value, name) => {
1927
- if (!object(value) || JSON.stringify(value).includes("\\u0000") || Buffer.byteLength(JSON.stringify(value)) > 2e5) {
1928
- throw new ServiceError(
1929
- "BAD_REQUEST",
1930
- `${name} must be an object under 200KB.`
1931
- );
1932
- }
1933
- const parsed = z12.record(z12.string(), z12.json()).safeParse(value);
1934
- if (!parsed.success) {
1935
- throw new ServiceError("BAD_REQUEST", `${name} must contain JSON values.`);
1936
- }
1937
- return parsed.data;
1938
- };
1939
- var sourceText = (value) => {
1940
- if (typeof value !== "string" || !value.trim() || value.includes("\0") || Buffer.byteLength(value) > 2e5) {
1941
- throw new ServiceError(
1942
- "BAD_REQUEST",
1943
- "Source must be nonblank UTF-8 text under 200KB, without NUL."
1944
- );
1945
- }
1946
- return value;
1947
- };
1948
- function schema(value) {
1949
- const result = jsonValue(value ?? {}, "Schema");
1950
- let count2 = 0;
1951
- const pending = [[result, 0]];
1952
- while (pending.length) {
1953
- const [node, depth] = pending.pop();
1954
- if (++count2 > 2e3 || depth > 30) {
1955
- throw new ServiceError("BAD_REQUEST", "JSON Schema is too complex.");
1956
- }
1957
- if (object(node)) {
1958
- if (["$ref", "$dynamicRef", "$recursiveRef"].some((key) => key in node)) {
1959
- throw new ServiceError(
1960
- "BAD_REQUEST",
1961
- "Use inline JSON Schemas without reference keywords."
1962
- );
1963
- }
1964
- for (const value2 of Object.values(node)) {
1965
- if (value2 && typeof value2 === "object") {
1966
- pending.push([value2, depth + 1]);
1967
- }
1968
- }
1969
- } else if (Array.isArray(node)) {
1970
- for (const value2 of node) {
1971
- if (value2 && typeof value2 === "object") {
1972
- pending.push([value2, depth + 1]);
1973
- }
1974
- }
1975
- }
1976
- }
1977
- try {
1978
- new Ajv({ strict: false }).compile(result);
1979
- } catch {
1980
- throw new ServiceError("BAD_REQUEST", "Invalid JSON Schema.");
1981
- }
1982
- return result;
2085
+ enabled: row.enabled
2086
+ };
1983
2087
  }
1984
- function validateContract(contract, value) {
1985
- try {
1986
- if (!new Ajv({ strict: false }).compile(contract)(value)) {
1987
- throw new ServiceError(
1988
- "BAD_REQUEST",
1989
- "Inputs do not match the action schema."
1990
- );
1991
- }
1992
- } catch (error) {
1993
- if (error instanceof ServiceError) {
1994
- throw error;
1995
- }
1996
- throw new ServiceError("BAD_REQUEST", "Invalid action schema.");
1997
- }
2088
+ function serializeVersion(row) {
2089
+ return {
2090
+ id: row.id,
2091
+ number: row.number,
2092
+ source: row.source,
2093
+ input_schema: row.inputSchema,
2094
+ output_schema: row.outputSchema,
2095
+ validation_mode: row.validationMode,
2096
+ sdk_contract: row.sdkContract,
2097
+ promoted_from: row.promotedFrom,
2098
+ created_at: row.createdAt
2099
+ };
1998
2100
  }
1999
- function validateColumns(columns2) {
2000
- const parsed = z12.array(
2001
- z12.strictObject({
2002
- key: z12.string().regex(/^[a-z][a-z0-9_]{0,47}$/),
2003
- type: z12.enum(["text", "number", "boolean", "date"]),
2004
- required: z12.boolean()
2005
- })
2006
- ).min(1).max(50).safeParse(columns2);
2007
- if (!parsed.success || new Set(parsed.data.map((column) => column.key)).size !== parsed.data.length) {
2008
- throw new ServiceError("BAD_REQUEST", "Invalid table columns.");
2009
- }
2010
- return parsed.data;
2101
+ function suiteView(suite) {
2102
+ return {
2103
+ id: suite.id,
2104
+ version: suite.versionId,
2105
+ revision: suite.number,
2106
+ digest: suite.digest,
2107
+ cases: suite.cases,
2108
+ created_at: suite.createdAt
2109
+ };
2011
2110
  }
2012
- function validateValues(columns2, values2) {
2013
- if (!object(values2) || Object.keys(values2).some(
2014
- (key) => !columns2.some((column) => column.key === key)
2015
- )) {
2016
- throw new ServiceError("BAD_REQUEST", "Use only defined column keys.");
2111
+
2112
+ // server/shared/pagination.ts
2113
+ function page(results) {
2114
+ return { count: results.length, next: null, previous: null, results };
2115
+ }
2116
+
2117
+ // server/router/actions/list.ts
2118
+ var listProcedure = scopedProcedure("catalog:read").query(
2119
+ ({ ctx }) => {
2120
+ const visibleActions = ctx.db.select().from(actions).where(and12(eq13(actions.workspaceId, ctx.workspace.id), actionGrant(ctx))).all();
2121
+ return page(visibleActions.map(serializeAction));
2017
2122
  }
2018
- for (const column of columns2) {
2019
- const value = values2[column.key];
2020
- if (value == null) {
2021
- if (column.required) {
2022
- throw new ServiceError("BAD_REQUEST", `${column.key} is required.`);
2123
+ );
2124
+
2125
+ // server/router/actions/get.ts
2126
+ import { and as and13, eq as eq14 } from "drizzle-orm";
2127
+ var getProcedure = scopedProcedure("catalog:read").input(actionIdSchema).query(({ ctx, input: input2 }) => {
2128
+ const action = ctx.db.select().from(actions).where(
2129
+ and13(
2130
+ eq14(actions.workspaceId, ctx.workspace.id),
2131
+ eq14(actions.id, input2.id),
2132
+ actionGrant(ctx)
2133
+ )
2134
+ ).get();
2135
+ if (!action) {
2136
+ throw new ServiceError("NOT_FOUND", "Not found.");
2137
+ }
2138
+ return serializeAction(action);
2139
+ });
2140
+
2141
+ // server/router/actions/versions.ts
2142
+ import { and as and15, desc, eq as eq16, inArray as inArray5 } from "drizzle-orm";
2143
+
2144
+ // server/repositories/actions.ts
2145
+ import { and as and14, eq as eq15 } from "drizzle-orm";
2146
+ function actionsRepository(context) {
2147
+ const workspaceId = requireWorkspace(context).id;
2148
+ const database = context.db;
2149
+ const scoped = (id) => and14(eq15(actions.workspaceId, workspaceId), eq15(actions.id, id));
2150
+ return {
2151
+ find(id) {
2152
+ const row = database.select().from(actions).where(scoped(id)).get();
2153
+ if (!row) {
2154
+ throw new ServiceError("NOT_FOUND", "Not found.");
2023
2155
  }
2024
- continue;
2156
+ return row;
2157
+ },
2158
+ create(data) {
2159
+ return inTransaction(context, (context2) => {
2160
+ const database2 = context2.db;
2161
+ const row = database2.insert(actions).values({ ...data, ...base(workspaceId) }).returning().get();
2162
+ recordAudit(context2, "action", row.id, "created");
2163
+ return row;
2164
+ });
2025
2165
  }
2026
- const valid = column.type === "text" ? typeof value === "string" && value.length <= 1e4 && !value.includes("\0") && (!column.required || !!value.trim()) : column.type === "number" ? typeof value === "number" && Number.isFinite(value) && Math.abs(value) <= 1e100 : column.type === "boolean" ? typeof value === "boolean" : typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value) && !Number.isNaN(Date.parse(value)) && new Date(value).toISOString().slice(0, 10) === value;
2027
- if (!valid) {
2028
- throw new ServiceError("BAD_REQUEST", `Invalid value for ${column.key}.`);
2166
+ };
2167
+ }
2168
+
2169
+ // server/router/actions/versions.ts
2170
+ var versionsProcedure = scopedProcedure("catalog:read").input(actionIdSchema).query(({ ctx, input: input2 }) => {
2171
+ const action = actionsRepository(ctx).find(input2.id);
2172
+ const token = ctx.token;
2173
+ const versionGrant = token && !token.projects.includes(action.projectId) ? inArray5(actionVersions.id, token.actionVersions) : void 0;
2174
+ const versions = ctx.db.select().from(actionVersions).where(
2175
+ and15(
2176
+ eq16(actionVersions.workspaceId, ctx.workspace.id),
2177
+ eq16(actionVersions.actionId, action.id),
2178
+ versionGrant
2179
+ )
2180
+ ).orderBy(desc(actionVersions.number)).all();
2181
+ return versions.map(serializeVersion);
2182
+ });
2183
+
2184
+ // server/actions/versions.ts
2185
+ import { and as and18, eq as eq19 } from "drizzle-orm";
2186
+
2187
+ // server/repositories/action-versions.ts
2188
+ import { and as and16, eq as eq17 } from "drizzle-orm";
2189
+ function actionVersionsRepository(context) {
2190
+ const workspaceId = requireWorkspace(context).id;
2191
+ const database = context.db;
2192
+ const scoped = (id) => and16(eq17(actionVersions.workspaceId, workspaceId), eq17(actionVersions.id, id));
2193
+ return {
2194
+ find(id) {
2195
+ const row = database.select().from(actionVersions).where(scoped(id)).get();
2196
+ if (!row) {
2197
+ throw new ServiceError("NOT_FOUND", "Not found.");
2198
+ }
2199
+ return row;
2200
+ },
2201
+ create(data) {
2202
+ return inTransaction(context, (context2) => {
2203
+ const database2 = context2.db;
2204
+ const row = database2.insert(actionVersions).values({ ...data, ...base(workspaceId) }).returning().get();
2205
+ recordAudit(context2, "action.version", row.id, "created");
2206
+ return row;
2207
+ });
2029
2208
  }
2030
- }
2031
- jsonValue(values2, "Values");
2209
+ };
2032
2210
  }
2033
2211
 
2034
2212
  // server/shared/validation.ts
@@ -2084,13 +2262,13 @@ function stringList(value, name) {
2084
2262
  }
2085
2263
 
2086
2264
  // server/actions/version-queries.ts
2087
- import { and as and14, desc as desc2, eq as eq15 } from "drizzle-orm";
2265
+ import { and as and17, desc as desc2, eq as eq18 } from "drizzle-orm";
2088
2266
  function findVersion(context, actionId, number) {
2089
2267
  return context.db.select().from(actionVersions).where(
2090
- and14(
2091
- eq15(actionVersions.workspaceId, workspace(context)),
2092
- eq15(actionVersions.actionId, actionId),
2093
- number === void 0 ? void 0 : eq15(actionVersions.number, number)
2268
+ and17(
2269
+ eq18(actionVersions.workspaceId, workspace(context)),
2270
+ eq18(actionVersions.actionId, actionId),
2271
+ number === void 0 ? void 0 : eq18(actionVersions.number, number)
2094
2272
  )
2095
2273
  ).orderBy(desc2(actionVersions.number)).limit(1).get();
2096
2274
  }
@@ -2103,10 +2281,10 @@ function requireVersion(context, actionId, number) {
2103
2281
  }
2104
2282
  function findTestSuite(context, versionId, revision3) {
2105
2283
  return context.db.select().from(actionTestSuites).where(
2106
- and14(
2107
- eq15(actionTestSuites.workspaceId, workspace(context)),
2108
- eq15(actionTestSuites.versionId, versionId),
2109
- revision3 === void 0 ? void 0 : eq15(actionTestSuites.number, revision3)
2284
+ and17(
2285
+ eq18(actionTestSuites.workspaceId, workspace(context)),
2286
+ eq18(actionTestSuites.versionId, versionId),
2287
+ revision3 === void 0 ? void 0 : eq18(actionTestSuites.number, revision3)
2110
2288
  )
2111
2289
  ).orderBy(desc2(actionTestSuites.number)).limit(1).get();
2112
2290
  }
@@ -2130,10 +2308,10 @@ function resolveActionForSave(ctx, projectId, name, id) {
2130
2308
  return action;
2131
2309
  }
2132
2310
  const matches = ctx.db.select().from(actions).where(
2133
- and15(
2134
- eq16(actions.workspaceId, workspace(ctx)),
2135
- eq16(actions.projectId, projectId),
2136
- eq16(actions.name, actionName)
2311
+ and18(
2312
+ eq19(actions.workspaceId, workspace(ctx)),
2313
+ eq19(actions.projectId, projectId),
2314
+ eq19(actions.name, actionName)
2137
2315
  )
2138
2316
  ).limit(2).all();
2139
2317
  if (matches.length > 1) {
@@ -2256,7 +2434,7 @@ var createProcedure = scopedProcedure("actions:write").input(createActionSchema)
2256
2434
  });
2257
2435
 
2258
2436
  // server/router/actions/update.ts
2259
- import { and as and16, eq as eq17 } from "drizzle-orm";
2437
+ import { and as and19, eq as eq20 } from "drizzle-orm";
2260
2438
  var updateProcedure = scopedProcedure("actions:write").input(updateActionSchema).mutation(({ ctx, input: body }) => {
2261
2439
  return inTransaction(ctx, (ctx2) => {
2262
2440
  const action = actionsRepository(ctx2).find(body.id);
@@ -2273,9 +2451,9 @@ var updateProcedure = scopedProcedure("actions:write").input(updateActionSchema)
2273
2451
  enabled: booleanValue(body.enabled, action.enabled),
2274
2452
  updatedAt: now()
2275
2453
  }).where(
2276
- and16(
2277
- eq17(actions.workspaceId, ctx2.workspace.id),
2278
- eq17(actions.id, body.id)
2454
+ and19(
2455
+ eq20(actions.workspaceId, ctx2.workspace.id),
2456
+ eq20(actions.id, body.id)
2279
2457
  )
2280
2458
  ).returning().get();
2281
2459
  if (!updatedAction) {
@@ -2296,47 +2474,47 @@ var createVersionProcedure = scopedProcedure("actions:write").input(createVersio
2296
2474
  });
2297
2475
 
2298
2476
  // server/runs/schemas.ts
2299
- import { z as z14 } from "zod";
2477
+ import { z as z17 } from "zod";
2300
2478
 
2301
2479
  // runtime/src/session-job-contract.ts
2302
- import { z as z13 } from "zod";
2303
- var sessionScopeSchema = z13.object({
2304
- workspaceId: z13.string().min(1).max(256),
2305
- projectId: z13.uuid(),
2306
- ownerId: z13.string().min(1).max(256)
2307
- });
2308
- var sessionCommandSchema = z13.discriminatedUnion("operation", [
2309
- z13.strictObject({ operation: z13.literal("open") }),
2310
- z13.strictObject({
2311
- operation: z13.literal("execute"),
2312
- id: z13.uuid(),
2313
- cellId: z13.uuid(),
2314
- generation: z13.number().int().positive(),
2315
- expectedSequence: z13.number().int().nonnegative(),
2316
- after: z13.number().int().nonnegative().optional()
2480
+ import { z as z16 } from "zod";
2481
+ var sessionScopeSchema = z16.object({
2482
+ workspaceId: z16.string().min(1).max(256),
2483
+ projectId: z16.uuid(),
2484
+ ownerId: z16.string().min(1).max(256)
2485
+ });
2486
+ var sessionCommandSchema = z16.discriminatedUnion("operation", [
2487
+ z16.strictObject({ operation: z16.literal("open") }),
2488
+ z16.strictObject({
2489
+ operation: z16.literal("execute"),
2490
+ id: z16.uuid(),
2491
+ cellId: z16.uuid(),
2492
+ generation: z16.number().int().positive(),
2493
+ expectedSequence: z16.number().int().nonnegative(),
2494
+ after: z16.number().int().nonnegative().optional()
2317
2495
  }),
2318
- z13.strictObject({ operation: z13.literal("close"), id: z13.uuid() }),
2319
- z13.strictObject({
2320
- operation: z13.literal("read"),
2321
- id: z13.uuid(),
2322
- after: z13.number().int().nonnegative().optional(),
2323
- limit: z13.number().int().positive().max(10).optional()
2496
+ z16.strictObject({ operation: z16.literal("close"), id: z16.uuid() }),
2497
+ z16.strictObject({
2498
+ operation: z16.literal("read"),
2499
+ id: z16.uuid(),
2500
+ after: z16.number().int().nonnegative().optional(),
2501
+ limit: z16.number().int().positive().max(10).optional()
2324
2502
  })
2325
2503
  ]);
2326
2504
 
2327
2505
  // server/runs/schemas.ts
2328
- var identifier2 = z14.uuid();
2329
- var jsonObject3 = z14.record(z14.string(), z14.json());
2330
- var runIdSchema = z14.strictObject({ id: identifier2 });
2331
- var createRunSchema = z14.strictObject({
2506
+ var identifier2 = z17.uuid();
2507
+ var jsonObject3 = z17.record(z17.string(), z17.json());
2508
+ var runIdSchema = z17.strictObject({ id: identifier2 });
2509
+ var createRunSchema = z17.strictObject({
2332
2510
  project: identifier2,
2333
- operation: z14.enum(["action", "code", "validate", "test"]),
2334
- idempotency_key: z14.string(),
2335
- source: z14.string().optional(),
2511
+ operation: z17.enum(["action", "code", "validate", "test"]),
2512
+ idempotency_key: z17.string(),
2513
+ source: z17.string().optional(),
2336
2514
  inputs: jsonObject3.optional(),
2337
2515
  action: identifier2.optional(),
2338
- version: z14.number().int().positive().optional(),
2339
- suite_revision: z14.number().int().positive().optional(),
2516
+ version: z17.number().int().positive().optional(),
2517
+ suite_revision: z17.number().int().positive().optional(),
2340
2518
  conversation: identifier2.optional(),
2341
2519
  input_schema: jsonObject3.optional(),
2342
2520
  output_schema: jsonObject3.optional()
@@ -2348,110 +2526,36 @@ var sessionRunSchema = createRunSchema.pick({
2348
2526
  inputs: true
2349
2527
  }).extend({ session: sessionCommandSchema });
2350
2528
  var validateCodeSchema = createRunSchema.omit({ operation: true });
2351
- var retryRunSchema = z14.strictObject({
2529
+ var retryRunSchema = z17.strictObject({
2352
2530
  id: identifier2,
2353
- idempotency_key: z14.string()
2531
+ idempotency_key: z17.string()
2354
2532
  });
2355
- var promoteRunSchema = z14.strictObject({
2533
+ var promoteRunSchema = z17.strictObject({
2356
2534
  id: identifier2,
2357
- name: z14.string(),
2535
+ name: z17.string(),
2358
2536
  action: identifier2.optional(),
2359
2537
  input_schema: jsonObject3.optional(),
2360
2538
  output_schema: jsonObject3.optional()
2361
2539
  });
2362
- var streamRunSchema = z14.strictObject({
2540
+ var streamRunSchema = z17.strictObject({
2363
2541
  id: identifier2,
2364
- after: z14.number().int().nonnegative().default(0)
2542
+ after: z17.number().int().nonnegative().default(0)
2365
2543
  });
2366
2544
 
2367
2545
  // server/runs/queries.ts
2368
- import { and as and17, eq as eq18 } from "drizzle-orm";
2546
+ import { and as and20, eq as eq21 } from "drizzle-orm";
2369
2547
  function findIdempotentRun(ctx, namespace, key) {
2370
2548
  return ctx.db.select().from(runs).where(
2371
- and17(
2372
- eq18(runs.workspaceId, workspace(ctx)),
2373
- eq18(runs.idempotencyNamespace, namespace),
2374
- eq18(runs.idempotencyKey, key)
2549
+ and20(
2550
+ eq21(runs.workspaceId, workspace(ctx)),
2551
+ eq21(runs.idempotencyNamespace, namespace),
2552
+ eq21(runs.idempotencyKey, key)
2375
2553
  )
2376
2554
  ).get();
2377
2555
  }
2378
2556
 
2379
2557
  // server/runs/create.ts
2380
- import { z as z16 } from "zod";
2381
-
2382
- // server/plugins/shell-policy.ts
2383
- import { and as and19, eq as eq20, gt as gt2, inArray as inArray5, sql } from "drizzle-orm";
2384
-
2385
- // server/runs/resume-after-approval.ts
2386
- import { and as and18, eq as eq19, notExists } from "drizzle-orm";
2387
- function resumeAfterApproval(ctx, runId) {
2388
- const pending = ctx.db.select({ id: approvals.id }).from(approvals).where(and18(eq19(approvals.runId, runId), eq19(approvals.status, "pending")));
2389
- ctx.db.update(runs).set({ status: "running", updatedAt: now() }).where(
2390
- and18(
2391
- eq19(runs.id, runId),
2392
- eq19(runs.status, "waiting_approval"),
2393
- eq19(runs.cancelRequested, false),
2394
- notExists(pending)
2395
- )
2396
- ).run();
2397
- }
2398
-
2399
- // server/plugins/shell-policy.ts
2400
- import { z as z15 } from "zod";
2401
- var executableName = z15.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.+-]{0,127}$/);
2402
- var ruleDecision = z15.enum(["allow", "block", "ask"]);
2403
- function supportsShellPolicy(plugin) {
2404
- const tools2 = plugin.releaseMetadata.tools;
2405
- return plugin.slug === "shell" && plugin.distribution === "external" && Array.isArray(tools2) && tools2.some(
2406
- (tool) => object(tool) && tool.name === "run" && object(tool.metadata) && tool.metadata.approval === "shell-executable"
2407
- );
2408
- }
2409
- function writeShellRule(ctx, plugin, executable, decision) {
2410
- const pluginId = plugin.id;
2411
- if (decision === "ask") {
2412
- ctx.db.delete(shellRules).where(
2413
- and19(
2414
- eq20(shellRules.pluginId, pluginId),
2415
- eq20(shellRules.executable, executable)
2416
- )
2417
- ).run();
2418
- } else {
2419
- ctx.db.insert(shellRules).values({ pluginId, executable, decision }).onConflictDoUpdate({
2420
- target: [shellRules.pluginId, shellRules.executable],
2421
- set: { decision }
2422
- }).run();
2423
- }
2424
- if (decision !== "ask") {
2425
- const currentTime = now();
2426
- const liveRunIds = ctx.db.select({ id: runs.id }).from(runs).where(
2427
- and19(
2428
- eq20(runs.projectId, plugin.projectId),
2429
- eq20(runs.workspaceId, plugin.workspaceId),
2430
- eq20(runs.cancelRequested, false),
2431
- eq20(runs.status, "waiting_approval"),
2432
- gt2(runs.leaseExpiresAt, currentTime),
2433
- gt2(runs.deadline, currentTime)
2434
- )
2435
- );
2436
- const changed = ctx.db.update(approvals).set({
2437
- status: decision === "allow" ? "approved" : "denied",
2438
- decidedBy: ctx.user?.id,
2439
- updatedAt: currentTime
2440
- }).where(
2441
- and19(
2442
- eq20(approvals.workspaceId, plugin.workspaceId),
2443
- eq20(approvals.status, "pending"),
2444
- inArray5(approvals.runId, liveRunIds),
2445
- sql`json_extract(${approvals.shell}, '$.pluginId') = ${plugin.id} and json_extract(${approvals.shell}, '$.digest') = ${plugin.digest} and json_extract(${approvals.shell}, '$.executable') = ${executable}`
2446
- )
2447
- ).returning({ id: approvals.id, runId: approvals.runId }).all();
2448
- for (const row of changed) {
2449
- recordAudit(ctx, "approval", row.id, "updated");
2450
- resumeAfterApproval(ctx, row.runId);
2451
- }
2452
- }
2453
- recordAudit(ctx, "shell_rule", pluginId + "/" + executable, decision);
2454
- }
2558
+ import { z as z18 } from "zod";
2455
2559
 
2456
2560
  // server/projects/plugin-namespace.ts
2457
2561
  function pluginNamespace(slug2) {
@@ -2678,11 +2782,11 @@ function projectSnapshot(ctx, projectId, operation = "code") {
2678
2782
  }
2679
2783
 
2680
2784
  // server/repositories/runs.ts
2681
- import { and as and20, eq as eq21 } from "drizzle-orm";
2785
+ import { and as and21, eq as eq22 } from "drizzle-orm";
2682
2786
  function runsRepository(context) {
2683
2787
  const workspaceId = requireWorkspace(context).id;
2684
2788
  const database = context.db;
2685
- const scoped = (id) => and20(eq21(runs.workspaceId, workspaceId), eq21(runs.id, id));
2789
+ const scoped = (id) => and21(eq22(runs.workspaceId, workspaceId), eq22(runs.id, id));
2686
2790
  return {
2687
2791
  find(id) {
2688
2792
  const row = database.select().from(runs).where(scoped(id)).get();
@@ -2714,22 +2818,22 @@ function runsRepository(context) {
2714
2818
  }
2715
2819
 
2716
2820
  // server/repositories/workspace-settings.ts
2717
- import { eq as eq22 } from "drizzle-orm";
2821
+ import { eq as eq23 } from "drizzle-orm";
2718
2822
  function workspaceSettingsForWorkspace(database, workspaceId) {
2719
- return database.select().from(workspaceSettings).where(eq22(workspaceSettings.workspaceId, workspaceId)).get();
2823
+ return database.select().from(workspaceSettings).where(eq23(workspaceSettings.workspaceId, workspaceId)).get();
2720
2824
  }
2721
2825
 
2722
2826
  // server/runs/sessions.ts
2723
- import { eq as eq24 } from "drizzle-orm";
2827
+ import { eq as eq25 } from "drizzle-orm";
2724
2828
 
2725
2829
  // server/repositories/executors.ts
2726
- import { and as and21, eq as eq23 } from "drizzle-orm";
2830
+ import { and as and22, eq as eq24 } from "drizzle-orm";
2727
2831
  function executorsRepository(context) {
2728
2832
  const workspaceId = requireWorkspace(context).id;
2729
2833
  const database = context.db;
2730
- const scoped = (id, filter) => and21(
2731
- eq23(executors.workspaceId, workspaceId),
2732
- id === void 0 ? void 0 : eq23(executors.id, id),
2834
+ const scoped = (id, filter) => and22(
2835
+ eq24(executors.workspaceId, workspaceId),
2836
+ id === void 0 ? void 0 : eq24(executors.id, id),
2733
2837
  filter
2734
2838
  );
2735
2839
  return {
@@ -2764,7 +2868,7 @@ function sessionSource(command2, input2) {
2764
2868
  }
2765
2869
  function requireSessionRunner(ctx, project, executionPool) {
2766
2870
  const [runner] = executorsRepository(ctx).list(
2767
- eq24(executors.projectId, project)
2871
+ eq25(executors.projectId, project)
2768
2872
  );
2769
2873
  if (!runner?.enabled || executionPool !== void 0 && runner.pool !== executionPool || !runner.lastSeenAt || Date.parse(runner.lastSeenAt) < Date.now() - 6e4 || runner.protocolVersion < 4 || !runner.capabilities.includes("session")) {
2770
2874
  throw new ServiceError(
@@ -2855,7 +2959,7 @@ function createRunInTransaction(ctx, body) {
2855
2959
  "Schemas are only accepted for validation jobs."
2856
2960
  );
2857
2961
  }
2858
- const snapshot = z16.record(z16.string(), z16.json()).parse(projectSnapshot(ctx, project.id, operation));
2962
+ const snapshot = z18.record(z18.string(), z18.json()).parse(projectSnapshot(ctx, project.id, operation));
2859
2963
  const source = version2?.source ?? (session ? sessionSource(session, body) : sourceText(body.source));
2860
2964
  if (session) {
2861
2965
  Object.assign(snapshot, {
@@ -3006,14 +3110,14 @@ var actionsRouter = router({
3006
3110
  });
3007
3111
 
3008
3112
  // server/router/approvals/list.ts
3009
- import { eq as eq25 } from "drizzle-orm";
3113
+ import { eq as eq26 } from "drizzle-orm";
3010
3114
 
3011
3115
  // server/runs/approvals.ts
3012
- import { z as z17 } from "zod";
3013
- var approvalIdSchema = z17.strictObject({ id: z17.uuid() });
3014
- var decideApprovalSchema = z17.strictObject({
3015
- id: z17.uuid(),
3016
- decision: z17.enum(["approved", "denied", "always_allow", "block"])
3116
+ import { z as z19 } from "zod";
3117
+ var approvalIdSchema = z19.strictObject({ id: z19.uuid() });
3118
+ var decideApprovalSchema = z19.strictObject({
3119
+ id: z19.uuid(),
3120
+ decision: z19.enum(["approved", "denied", "always_allow", "block"])
3017
3121
  });
3018
3122
  function approvalView(row) {
3019
3123
  return {
@@ -3028,16 +3132,16 @@ function approvalView(row) {
3028
3132
 
3029
3133
  // server/router/approvals/list.ts
3030
3134
  var listProcedure2 = browserWorkspaceProcedure.query(({ ctx }) => {
3031
- const workspaceApprovals = ctx.db.select().from(approvals).where(eq25(approvals.workspaceId, ctx.workspace.id)).all();
3135
+ const workspaceApprovals = ctx.db.select().from(approvals).where(eq26(approvals.workspaceId, ctx.workspace.id)).all();
3032
3136
  return page(workspaceApprovals.map(approvalView));
3033
3137
  });
3034
3138
 
3035
3139
  // server/repositories/approvals.ts
3036
- import { and as and22, eq as eq26 } from "drizzle-orm";
3140
+ import { and as and23, eq as eq27 } from "drizzle-orm";
3037
3141
  function approvalsRepository(context) {
3038
3142
  const workspaceId = requireWorkspace(context).id;
3039
3143
  const database = context.db;
3040
- const scoped = (id) => and22(eq26(approvals.workspaceId, workspaceId), eq26(approvals.id, id));
3144
+ const scoped = (id) => and23(eq27(approvals.workspaceId, workspaceId), eq27(approvals.id, id));
3041
3145
  return {
3042
3146
  find(id) {
3043
3147
  const row = database.select().from(approvals).where(scoped(id)).get();
@@ -3066,30 +3170,6 @@ var getProcedure2 = browserWorkspaceProcedure.input(approvalIdSchema).query(({ c
3066
3170
  return approvalView(approvalsRepository(ctx).find(id));
3067
3171
  });
3068
3172
 
3069
- // server/repositories/plugins.ts
3070
- import { and as and23, eq as eq27 } from "drizzle-orm";
3071
- function pluginsRepository(context) {
3072
- const workspaceId = requireWorkspace(context).id;
3073
- const database = context.db;
3074
- const scoped = (id, filter) => and23(
3075
- eq27(plugins.workspaceId, workspaceId),
3076
- id === void 0 ? void 0 : eq27(plugins.id, id),
3077
- filter
3078
- );
3079
- return {
3080
- find(id) {
3081
- const row = database.select().from(plugins).where(scoped(id)).get();
3082
- if (!row) {
3083
- throw new ServiceError("NOT_FOUND", "Not found.");
3084
- }
3085
- return row;
3086
- },
3087
- list(filter) {
3088
- return database.select().from(plugins).where(scoped(void 0, filter)).all();
3089
- }
3090
- };
3091
- }
3092
-
3093
3173
  // server/router/approvals/decide.ts
3094
3174
  var decideProcedure = browserManagerProcedure.input(decideApprovalSchema).mutation(
3095
3175
  ({ ctx, input: input2 }) => inTransaction(ctx, (ctx2) => {
@@ -3146,8 +3226,8 @@ var approvalsRouter = router({
3146
3226
  import { eq as eq28 } from "drizzle-orm";
3147
3227
 
3148
3228
  // server/runs/artifacts.ts
3149
- import { z as z18 } from "zod";
3150
- var artifactIdSchema = z18.strictObject({ id: z18.uuid() });
3229
+ import { z as z20 } from "zod";
3230
+ var artifactIdSchema = z20.strictObject({ id: z20.uuid() });
3151
3231
  function artifactView(row) {
3152
3232
  return {
3153
3233
  id: row.id,
@@ -3212,13 +3292,13 @@ function auditQueries(database, workspaceId) {
3212
3292
  }
3213
3293
 
3214
3294
  // server/audit/schemas.ts
3215
- import { z as z19 } from "zod";
3216
- var auditFiltersSchema = z19.object({
3217
- actor: z19.number().int().positive().optional(),
3218
- kind: z19.string().optional(),
3219
- object_id: z19.string().optional(),
3220
- since: z19.iso.datetime().optional(),
3221
- before: z19.iso.datetime().optional()
3295
+ import { z as z21 } from "zod";
3296
+ var auditFiltersSchema = z21.object({
3297
+ actor: z21.number().int().positive().optional(),
3298
+ kind: z21.string().optional(),
3299
+ object_id: z21.string().optional(),
3300
+ since: z21.iso.datetime().optional(),
3301
+ before: z21.iso.datetime().optional()
3222
3302
  }).strict().refine(
3223
3303
  (input2) => !input2.since || !input2.before || Date.parse(input2.since) < Date.parse(input2.before),
3224
3304
  "Invalid date range."
@@ -3256,8 +3336,8 @@ var listProcedure4 = browserManagerProcedure.input(auditFiltersSchema.optional()
3256
3336
 
3257
3337
  // server/router/audit/get.ts
3258
3338
  import { and as and27, eq as eq32 } from "drizzle-orm";
3259
- import { z as z20 } from "zod";
3260
- var getProcedure4 = browserManagerProcedure.input(z20.strictObject({ id: z20.uuid() })).query(({ ctx, input: input2 }) => {
3339
+ import { z as z22 } from "zod";
3340
+ var getProcedure4 = browserManagerProcedure.input(z22.strictObject({ id: z22.uuid() })).query(({ ctx, input: input2 }) => {
3261
3341
  const record = ctx.db.select().from(auditRecords).where(
3262
3342
  and27(
3263
3343
  eq32(auditRecords.workspaceId, ctx.workspace.id),
@@ -3362,7 +3442,7 @@ function updateInvitation(database, workspaceId, id, changes) {
3362
3442
  }
3363
3443
 
3364
3444
  // server/auth/schemas.ts
3365
- import { z as z21 } from "zod";
3445
+ import { z as z23 } from "zod";
3366
3446
 
3367
3447
  // server/auth/validation.ts
3368
3448
  function strongPassword(value) {
@@ -3373,38 +3453,38 @@ function validEmail(value) {
3373
3453
  }
3374
3454
 
3375
3455
  // server/auth/schemas.ts
3376
- var emailSchema = z21.string().refine(validEmail, "Enter a valid email address.");
3377
- var passwordSchema = z21.string().refine(strongPassword, "Choose a stronger password.");
3378
- var loginSchema = z21.strictObject({
3379
- email: z21.string(),
3380
- password: z21.string().max(1024)
3381
- });
3382
- var codeSchema = z21.strictObject({ code: z21.string() });
3383
- var signupSchema = z21.strictObject({
3456
+ var emailSchema = z23.string().refine(validEmail, "Enter a valid email address.");
3457
+ var passwordSchema = z23.string().refine(strongPassword, "Choose a stronger password.");
3458
+ var loginSchema = z23.strictObject({
3459
+ email: z23.string(),
3460
+ password: z23.string().max(1024)
3461
+ });
3462
+ var codeSchema = z23.strictObject({ code: z23.string() });
3463
+ var signupSchema = z23.strictObject({
3384
3464
  email: emailSchema,
3385
- username: z21.string().trim().min(1).max(150),
3465
+ username: z23.string().trim().min(1).max(150),
3386
3466
  password: passwordSchema
3387
3467
  });
3388
- var setupSchema = z21.strictObject({
3389
- domain: z21.string(),
3390
- workspace_name: z21.string().trim().min(1),
3391
- username: z21.string().trim().min(1),
3468
+ var setupSchema = z23.strictObject({
3469
+ domain: z23.string(),
3470
+ workspace_name: z23.string().trim().min(1),
3471
+ username: z23.string().trim().min(1),
3392
3472
  email: emailSchema,
3393
3473
  password1: passwordSchema,
3394
- password2: z21.string(),
3395
- project_name: z21.string().optional()
3474
+ password2: z23.string(),
3475
+ project_name: z23.string().optional()
3396
3476
  }).refine((body) => body.password1 === body.password2, "Passwords must match.");
3397
- var passwordChangeSchema = z21.strictObject({
3398
- current_password: z21.string().max(1024),
3477
+ var passwordChangeSchema = z23.strictObject({
3478
+ current_password: z23.string().max(1024),
3399
3479
  new_password: passwordSchema
3400
3480
  });
3401
- var emailChangeSchema = z21.strictObject({ email: emailSchema });
3402
- var reauthenticationSchema = z21.strictObject({
3403
- password: z21.string().max(1024)
3481
+ var emailChangeSchema = z23.strictObject({ email: emailSchema });
3482
+ var reauthenticationSchema = z23.strictObject({
3483
+ password: z23.string().max(1024)
3404
3484
  });
3405
- var profileSchema = z21.strictObject({
3406
- first_name: z21.string().optional(),
3407
- last_name: z21.string().optional()
3485
+ var profileSchema = z23.strictObject({
3486
+ first_name: z23.string().optional(),
3487
+ last_name: z23.string().optional()
3408
3488
  });
3409
3489
 
3410
3490
  // server/router/auth/setup.ts
@@ -3657,7 +3737,7 @@ var signupProcedure = browserProcedure.input(signupSchema).mutation(async ({ ctx
3657
3737
  });
3658
3738
 
3659
3739
  // server/auth/totp.ts
3660
- import { z as z22 } from "zod";
3740
+ import { z as z24 } from "zod";
3661
3741
  import { eq as eq37 } from "drizzle-orm";
3662
3742
  import { createHmac, timingSafeEqual } from "node:crypto";
3663
3743
  var base32Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
@@ -3720,7 +3800,7 @@ function consumeCode(ctx, user, code) {
3720
3800
  ctx2.db.update(users).set({ totpLastCounter: step }).where(eq37(users.id, current.id)).run();
3721
3801
  return true;
3722
3802
  }
3723
- const hashes = z22.array(z22.string()).parse(JSON.parse(current.recoveryCodes));
3803
+ const hashes = z24.array(z24.string()).parse(JSON.parse(current.recoveryCodes));
3724
3804
  const index = hashes.indexOf(digest(code));
3725
3805
  if (index < 0) {
3726
3806
  return false;
@@ -3990,19 +4070,19 @@ var listProcedure5 = browserWorkspaceProcedure.query(({ ctx }) => {
3990
4070
  import { and as and29, eq as eq40 } from "drizzle-orm";
3991
4071
 
3992
4072
  // server/projects/schemas.ts
3993
- import { z as z23 } from "zod";
3994
- var projectIdSchema = z23.strictObject({ id: z23.uuid() });
3995
- var projectCreateSchema = z23.strictObject({
3996
- name: z23.string().min(1).max(100),
3997
- enabled: z23.boolean().optional(),
3998
- readable_tables: z23.array(z23.uuid()).optional(),
3999
- writable_tables: z23.array(z23.uuid()).optional(),
4000
- readable_documents: z23.array(z23.uuid()).optional(),
4001
- writable_documents: z23.array(z23.uuid()).optional()
4002
- });
4003
- var projectChangesSchema = projectCreateSchema.partial().extend({ id: z23.uuid() });
4073
+ import { z as z25 } from "zod";
4074
+ var projectIdSchema = z25.strictObject({ id: z25.uuid() });
4075
+ var projectCreateSchema = z25.strictObject({
4076
+ name: z25.string().min(1).max(100),
4077
+ enabled: z25.boolean().optional(),
4078
+ readable_tables: z25.array(z25.uuid()).optional(),
4079
+ writable_tables: z25.array(z25.uuid()).optional(),
4080
+ readable_documents: z25.array(z25.uuid()).optional(),
4081
+ writable_documents: z25.array(z25.uuid()).optional()
4082
+ });
4083
+ var projectChangesSchema = projectCreateSchema.partial().extend({ id: z25.uuid() });
4004
4084
  var projectExecutorSchema = projectIdSchema.extend({
4005
- locally_managed: z23.boolean().default(false)
4085
+ locally_managed: z25.boolean().default(false)
4006
4086
  });
4007
4087
 
4008
4088
  // server/router/conversations/get.ts
@@ -4030,17 +4110,17 @@ import { and as and31, eq as eq42, lt as lt2 } from "drizzle-orm";
4030
4110
  import { createHash as createHash2 } from "node:crypto";
4031
4111
 
4032
4112
  // server/oauth/schemas.ts
4033
- import { z as z24 } from "zod";
4034
- var oauthConnectSchema = z24.strictObject({
4035
- plugin: z24.uuid(),
4036
- name: z24.string().trim().min(1).max(100),
4037
- client_id: z24.string().trim().min(1).max(500),
4038
- client_secret: z24.string().trim().min(1).max(2e3)
4113
+ import { z as z26 } from "zod";
4114
+ var oauthConnectSchema = z26.strictObject({
4115
+ plugin: z26.uuid(),
4116
+ name: z26.string().trim().min(1).max(100),
4117
+ client_id: z26.string().trim().min(1).max(500),
4118
+ client_secret: z26.string().trim().min(1).max(2e3)
4039
4119
  });
4040
- var oauthCallbackSchema = z24.object({
4041
- state: z24.string().optional(),
4042
- code: z24.string().optional(),
4043
- error: z24.string().optional()
4120
+ var oauthCallbackSchema = z26.object({
4121
+ state: z26.string().optional(),
4122
+ code: z26.string().optional(),
4123
+ error: z26.string().optional()
4044
4124
  });
4045
4125
 
4046
4126
  // server/oauth/providers.ts
@@ -4226,29 +4306,6 @@ var listProcedure6 = browserWorkspaceProcedure.query(({ ctx }) => {
4226
4306
  return page(records);
4227
4307
  });
4228
4308
 
4229
- // server/credentials/schemas.ts
4230
- import { z as z25 } from "zod";
4231
- var credentialName = z25.string().trim().min(1).max(100).refine((value) => !value.includes("\0"));
4232
- var credentialSecret = z25.record(z25.string(), z25.json()).refine(
4233
- (secret) => Object.keys(secret).length > 0 && Buffer.byteLength(JSON.stringify(secret)) <= 32e3,
4234
- "Supply a nonempty secret object under 32KB."
4235
- );
4236
- var credentialSchema = z25.object({
4237
- id: z25.uuid(),
4238
- name: z25.string(),
4239
- provider: z25.string()
4240
- });
4241
- var credentialCreateSchema = z25.strictObject({
4242
- name: credentialName,
4243
- provider: credentialName,
4244
- secret: credentialSecret
4245
- });
4246
- var updateCredentialSchema = credentialCreateSchema.partial();
4247
- var credentialIdSchema = z25.strictObject({ id: z25.uuid() });
4248
- var credentialChangesSchema = updateCredentialSchema.extend({
4249
- id: z25.uuid()
4250
- });
4251
-
4252
4309
  // server/router/credentials/get.ts
4253
4310
  var getProcedure6 = browserWorkspaceProcedure.input(credentialIdSchema).query(({ ctx, input: input2 }) => {
4254
4311
  const credential = findCredential(ctx.db, ctx.workspace.id, input2.id);
@@ -4258,26 +4315,28 @@ var getProcedure6 = browserWorkspaceProcedure.input(credentialIdSchema).query(({
4258
4315
  return credential;
4259
4316
  });
4260
4317
 
4261
- // server/router/credentials/create.ts
4262
- var createProcedure2 = browserManagerProcedure.input(credentialCreateSchema).mutation(({ ctx, input: input2 }) => {
4318
+ // server/credentials/create.ts
4319
+ function insertCredential(context, input2) {
4263
4320
  if (input2.provider.startsWith("mcp-")) {
4264
4321
  throw new ServiceError(
4265
4322
  "BAD_REQUEST",
4266
4323
  "Manage MCP credentials from project plugins."
4267
4324
  );
4268
4325
  }
4269
- const encryptedSecret = ctx.secrets.encrypt(JSON.stringify(input2.secret));
4270
- return inTransaction(ctx, (transaction) => {
4271
- const credential = transaction.db.insert(credentials).values({
4272
- ...base(ctx.workspace.id),
4273
- name: input2.name,
4274
- provider: input2.provider,
4275
- encryptedSecret
4276
- }).returning(credentialPublicFields).get();
4277
- recordAudit(transaction, "credential", credential.id, "created");
4278
- return credential;
4279
- });
4280
- });
4326
+ const credential = context.db.insert(credentials).values({
4327
+ ...base(requireWorkspace(context).id),
4328
+ name: input2.name,
4329
+ provider: input2.provider,
4330
+ encryptedSecret: context.secrets.encrypt(JSON.stringify(input2.secret))
4331
+ }).returning(credentialPublicFields).get();
4332
+ recordAudit(context, "credential", credential.id, "created");
4333
+ return credential;
4334
+ }
4335
+
4336
+ // server/router/credentials/create.ts
4337
+ var createProcedure2 = browserManagerProcedure.input(credentialCreateSchema).mutation(
4338
+ ({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => insertCredential(transaction, input2))
4339
+ );
4281
4340
 
4282
4341
  // server/router/credentials/update.ts
4283
4342
  import { and as and32, eq as eq44 } from "drizzle-orm";
@@ -4377,18 +4436,18 @@ function findDocument(database, workspaceId, id) {
4377
4436
  }
4378
4437
 
4379
4438
  // server/documents/schemas.ts
4380
- import { z as z26 } from "zod";
4381
- var identifier3 = z26.uuid();
4439
+ import { z as z27 } from "zod";
4440
+ var identifier3 = z27.uuid();
4382
4441
  var documentFields = {
4383
- kind: z26.enum(["memory", "document"]),
4384
- title: z26.string(),
4385
- content: z26.string().max(2e5).refine((value) => !value.includes("\0"), "Invalid document.")
4442
+ kind: z27.enum(["memory", "document"]),
4443
+ title: z27.string(),
4444
+ content: z27.string().max(2e5).refine((value) => !value.includes("\0"), "Invalid document.")
4386
4445
  };
4387
- var documentIdSchema = z26.strictObject({ id: identifier3 });
4388
- var createDocumentSchema = z26.strictObject(documentFields);
4389
- var updateDocumentSchema = z26.strictObject({
4446
+ var documentIdSchema = z27.strictObject({ id: identifier3 });
4447
+ var createDocumentSchema = z27.strictObject(documentFields);
4448
+ var updateDocumentSchema = z27.strictObject({
4390
4449
  id: identifier3,
4391
- ...z26.object(documentFields).partial().shape
4450
+ ...z27.object(documentFields).partial().shape
4392
4451
  });
4393
4452
 
4394
4453
  // server/router/documents/get.ts
@@ -4470,10 +4529,78 @@ var documentsRouter = router({
4470
4529
  delete: deleteProcedure2
4471
4530
  });
4472
4531
 
4532
+ // server/router/plugins/configure.ts
4533
+ import { isDeepStrictEqual } from "node:util";
4534
+ import { and as and37, eq as eq50 } from "drizzle-orm";
4535
+ var configureProcedure = scopedManagerProcedure("plugins:configure").input(configurePluginSchema).mutation(
4536
+ ({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
4537
+ assertCurrentPluginManager(transaction);
4538
+ const plugin = findConfigurablePlugin(transaction, input2.id);
4539
+ if (input2.revision !== pluginSettings(plugin).revision) {
4540
+ throw new ServiceError(
4541
+ "CONFLICT",
4542
+ "Plugin settings changed. List them again before retrying."
4543
+ );
4544
+ }
4545
+ const configuration2 = jsonValue(
4546
+ input2.configuration ?? plugin.configuration,
4547
+ "Configuration"
4548
+ );
4549
+ validateContract(
4550
+ jsonValue(
4551
+ plugin.releaseMetadata.configuration_schema ?? {},
4552
+ "Configuration schema"
4553
+ ),
4554
+ configuration2
4555
+ );
4556
+ if (plugin.credentialId && input2.credential === void 0 && !isDeepStrictEqual(configuration2, plugin.configuration)) {
4557
+ throw new ServiceError(
4558
+ "BAD_REQUEST",
4559
+ "Supply a replacement credential or explicitly disconnect it when changing these settings."
4560
+ );
4561
+ }
4562
+ let credentialId = input2.credential === null ? null : plugin.credentialId;
4563
+ if (input2.credential) {
4564
+ const auth4 = plugin.releaseMetadata.auth;
4565
+ const provider2 = auth4?.provider;
4566
+ if (!provider2 || auth4?.type === "oauth2") {
4567
+ throw new ServiceError(
4568
+ "BAD_REQUEST",
4569
+ "This plugin does not accept an API credential through MCP."
4570
+ );
4571
+ }
4572
+ credentialId = insertCredential(transaction, {
4573
+ ...input2.credential,
4574
+ provider: provider2
4575
+ }).id;
4576
+ }
4577
+ const updatedPlugin = transaction.db.update(plugins).set({ configuration: configuration2, credentialId, updatedAt: now() }).where(
4578
+ and37(
4579
+ eq50(plugins.workspaceId, ctx.workspace.id),
4580
+ eq50(plugins.id, plugin.id)
4581
+ )
4582
+ ).returning().get();
4583
+ if (!updatedPlugin) {
4584
+ throw new ServiceError("NOT_FOUND", "Plugin not found.");
4585
+ }
4586
+ recordAudit(transaction, "plugin", plugin.id, "updated");
4587
+ return pluginSettings(updatedPlugin);
4588
+ })
4589
+ );
4590
+
4591
+ // server/router/plugins/settings.ts
4592
+ import { eq as eq51 } from "drizzle-orm";
4593
+ import { z as z28 } from "zod";
4594
+ var settingsProcedure = scopedManagerProcedure("plugins:configure").input(z28.strictObject({ project: z28.uuid() })).query(({ ctx, input: input2 }) => {
4595
+ projectGrant(ctx, input2.project);
4596
+ projectsRepository(ctx).find(input2.project);
4597
+ return pluginsRepository(ctx).list(eq51(plugins.projectId, input2.project)).filter(canConfigurePlugin).map(pluginSettings);
4598
+ });
4599
+
4473
4600
  // server/router/plugins/shell-rules.ts
4474
- import { asc as asc3, eq as eq50 } from "drizzle-orm";
4475
- import { z as z27 } from "zod";
4476
- var shellRulesProcedure = browserWorkspaceProcedure.input(z27.strictObject({ id: z27.uuid() })).query(({ ctx, input: input2 }) => {
4601
+ import { asc as asc3, eq as eq52 } from "drizzle-orm";
4602
+ import { z as z29 } from "zod";
4603
+ var shellRulesProcedure = browserWorkspaceProcedure.input(z29.strictObject({ id: z29.uuid() })).query(({ ctx, input: input2 }) => {
4477
4604
  const plugin = pluginsRepository(ctx).find(input2.id);
4478
4605
  if (!supportsShellPolicy(plugin)) {
4479
4606
  throw new ServiceError(
@@ -4484,14 +4611,14 @@ var shellRulesProcedure = browserWorkspaceProcedure.input(z27.strictObject({ id:
4484
4611
  return ctx.db.select({
4485
4612
  executable: shellRules.executable,
4486
4613
  decision: shellRules.decision
4487
- }).from(shellRules).where(eq50(shellRules.pluginId, plugin.id)).orderBy(asc3(shellRules.executable)).all();
4614
+ }).from(shellRules).where(eq52(shellRules.pluginId, plugin.id)).orderBy(asc3(shellRules.executable)).all();
4488
4615
  });
4489
4616
 
4490
4617
  // server/router/plugins/set-shell-rule.ts
4491
- import { z as z28 } from "zod";
4618
+ import { z as z30 } from "zod";
4492
4619
  var setShellRuleProcedure = browserManagerProcedure.input(
4493
- z28.strictObject({
4494
- id: z28.uuid(),
4620
+ z30.strictObject({
4621
+ id: z30.uuid(),
4495
4622
  executable: executableName,
4496
4623
  decision: ruleDecision
4497
4624
  })
@@ -4514,32 +4641,32 @@ var setShellRuleProcedure = browserManagerProcedure.input(
4514
4641
  import { auth as auth2, discoverOAuthServerInfo } from "@modelcontextprotocol/client";
4515
4642
 
4516
4643
  // server/mcp/schemas.ts
4517
- import { z as z29 } from "zod";
4518
- var connectionInputSchema = z29.strictObject({
4519
- project: z29.uuid(),
4520
- slug: z29.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/).max(50),
4644
+ import { z as z31 } from "zod";
4645
+ var connectionInputSchema = z31.strictObject({
4646
+ project: z31.uuid(),
4647
+ slug: z31.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/).max(50),
4521
4648
  endpoint: endpointSchema,
4522
4649
  transport: transportSchema.default("auto"),
4523
- auth_mode: z29.enum(["none", "headers", "oauth"]).default("none"),
4650
+ auth_mode: z31.enum(["none", "headers", "oauth"]).default("none"),
4524
4651
  headers: headerSchema.optional()
4525
4652
  });
4526
- var connectionUpdateSchema = z29.strictObject({
4527
- id: z29.uuid(),
4653
+ var connectionUpdateSchema = z31.strictObject({
4654
+ id: z31.uuid(),
4528
4655
  endpoint: endpointSchema.optional(),
4529
4656
  transport: transportSchema.optional(),
4530
- auth_mode: z29.enum(["none", "headers", "oauth"]).optional(),
4657
+ auth_mode: z31.enum(["none", "headers", "oauth"]).optional(),
4531
4658
  headers: headerSchema.optional()
4532
4659
  });
4533
- var catalogueAcceptSchema = z29.strictObject({
4534
- id: z29.uuid(),
4535
- run: z29.uuid(),
4536
- tools: z29.array(z29.string()).max(1e3)
4660
+ var catalogueAcceptSchema = z31.strictObject({
4661
+ id: z31.uuid(),
4662
+ run: z31.uuid(),
4663
+ tools: z31.array(z31.string()).max(1e3)
4537
4664
  });
4538
- var oauthBeginSchema = z29.strictObject({
4539
- id: z29.uuid(),
4540
- client_id: z29.string().max(2e3).optional(),
4541
- client_secret: z29.string().max(4e3).optional(),
4542
- client_metadata_url: z29.string().url().optional()
4665
+ var oauthBeginSchema = z31.strictObject({
4666
+ id: z31.uuid(),
4667
+ client_id: z31.string().max(2e3).optional(),
4668
+ client_secret: z31.string().max(4e3).optional(),
4669
+ client_metadata_url: z31.string().url().optional()
4543
4670
  });
4544
4671
 
4545
4672
  // server/router/plugins/mcp/begin-oauth.ts
@@ -4663,7 +4790,7 @@ var createProcedure4 = browserManagerProcedure.input(connectionInputSchema).muta
4663
4790
  );
4664
4791
 
4665
4792
  // server/router/plugins/mcp/update.ts
4666
- import { eq as eq51 } from "drizzle-orm";
4793
+ import { eq as eq53 } from "drizzle-orm";
4667
4794
  var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mutation(
4668
4795
  ({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
4669
4796
  assertCurrentPluginManager(transaction);
@@ -4691,12 +4818,12 @@ var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mut
4691
4818
  discoveryRunId: null,
4692
4819
  catalogue: [],
4693
4820
  enabledTools: []
4694
- }).where(eq51(mcpConnections.pluginId, input2.id)).run();
4821
+ }).where(eq53(mcpConnections.pluginId, input2.id)).run();
4695
4822
  transaction.db.update(plugins).set({
4696
4823
  enabled: false,
4697
4824
  ...credentialId ? { credentialId } : resetAuth ? { credentialId: null } : {},
4698
4825
  updatedAt: now()
4699
- }).where(eq51(plugins.id, input2.id)).run();
4826
+ }).where(eq53(plugins.id, input2.id)).run();
4700
4827
  discardMcpCredential(transaction, replacedCredential);
4701
4828
  recordAudit(transaction, "plugin", input2.id, "connection.updated");
4702
4829
  return { id: input2.id };
@@ -4704,31 +4831,31 @@ var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mut
4704
4831
  );
4705
4832
 
4706
4833
  // server/plugins/schemas.ts
4707
- import { z as z30 } from "zod";
4708
- var pluginIdSchema = z30.strictObject({ id: z30.uuid() });
4709
- var pluginCreateSchema = z30.strictObject({
4710
- project: z30.uuid(),
4711
- slug: z30.string(),
4712
- version: z30.string(),
4713
- description: z30.string().optional(),
4714
- source: z30.string().optional(),
4715
- distribution: z30.enum(["inline", "external"]).optional(),
4716
- credential: z30.uuid().nullable().optional(),
4717
- configuration: z30.json().optional(),
4718
- enabled: z30.boolean().optional()
4719
- });
4720
- var pluginChangesSchema = pluginCreateSchema.omit({ slug: true }).partial().extend({ id: z30.uuid(), refresh_bundle: z30.boolean().optional() });
4834
+ import { z as z32 } from "zod";
4835
+ var pluginIdSchema = z32.strictObject({ id: z32.uuid() });
4836
+ var pluginCreateSchema = z32.strictObject({
4837
+ project: z32.uuid(),
4838
+ slug: z32.string(),
4839
+ version: z32.string(),
4840
+ description: z32.string().optional(),
4841
+ source: z32.string().optional(),
4842
+ distribution: z32.enum(["inline", "external"]).optional(),
4843
+ credential: z32.uuid().nullable().optional(),
4844
+ configuration: z32.json().optional(),
4845
+ enabled: z32.boolean().optional()
4846
+ });
4847
+ var pluginChangesSchema = pluginCreateSchema.omit({ slug: true }).partial().extend({ id: z32.uuid(), refresh_bundle: z32.boolean().optional() });
4721
4848
 
4722
4849
  // server/router/plugins/mcp/get.ts
4723
- import { and as and37, eq as eq52, gt as gt3 } from "drizzle-orm";
4850
+ import { and as and38, eq as eq54, gt as gt3 } from "drizzle-orm";
4724
4851
  var getProcedure8 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx, input: input2 }) => {
4725
4852
  const connection = mcpConnection(ctx, input2.id);
4726
- const plugin = ctx.db.select().from(plugins).where(eq52(plugins.id, connection.pluginId)).get();
4853
+ const plugin = ctx.db.select().from(plugins).where(eq54(plugins.id, connection.pluginId)).get();
4727
4854
  const runner = plugin ? ctx.db.select({ protocolVersion: executors.protocolVersion }).from(executors).where(
4728
- and37(
4729
- eq52(executors.workspaceId, ctx.workspace.id),
4730
- eq52(executors.projectId, plugin.projectId),
4731
- eq52(executors.enabled, true),
4855
+ and38(
4856
+ eq54(executors.workspaceId, ctx.workspace.id),
4857
+ eq54(executors.projectId, plugin.projectId),
4858
+ eq54(executors.enabled, true),
4732
4859
  gt3(
4733
4860
  executors.lastSeenAt,
4734
4861
  new Date(Date.now() - 6e4).toISOString()
@@ -4736,9 +4863,9 @@ var getProcedure8 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx
4736
4863
  )
4737
4864
  ).all() : [];
4738
4865
  const run = connection.discoveryRunId ? ctx.db.select({ status: runs.status, error: runs.error }).from(runs).where(
4739
- and37(
4740
- eq52(runs.id, connection.discoveryRunId),
4741
- eq52(runs.workspaceId, ctx.workspace.id)
4866
+ and38(
4867
+ eq54(runs.id, connection.discoveryRunId),
4868
+ eq54(runs.workspaceId, ctx.workspace.id)
4742
4869
  )
4743
4870
  ).get() : void 0;
4744
4871
  return {
@@ -4751,17 +4878,17 @@ var getProcedure8 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx
4751
4878
  });
4752
4879
 
4753
4880
  // server/router/plugins/mcp/discover.ts
4754
- import { and as and38, eq as eq53, gt as gt4 } from "drizzle-orm";
4881
+ import { and as and39, eq as eq55, gt as gt4 } from "drizzle-orm";
4755
4882
  var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
4756
4883
  ({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
4757
4884
  assertCurrentPluginManager(transaction);
4758
4885
  const plugin = pluginsRepository(transaction).find(input2.id);
4759
4886
  const connection = mcpConnection(transaction, input2.id);
4760
4887
  const workers = transaction.db.select().from(executors).where(
4761
- and38(
4762
- eq53(executors.workspaceId, ctx.workspace.id),
4763
- eq53(executors.projectId, plugin.projectId),
4764
- eq53(executors.enabled, true),
4888
+ and39(
4889
+ eq55(executors.workspaceId, ctx.workspace.id),
4890
+ eq55(executors.projectId, plugin.projectId),
4891
+ eq55(executors.enabled, true),
4765
4892
  gt4(
4766
4893
  executors.lastSeenAt,
4767
4894
  new Date(Date.now() - 6e4).toISOString()
@@ -4784,16 +4911,16 @@ var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
4784
4911
  }
4785
4912
  if (connection.discoveryRunId) {
4786
4913
  const previous = transaction.db.select().from(runs).where(
4787
- and38(
4788
- eq53(runs.id, connection.discoveryRunId),
4789
- eq53(runs.workspaceId, ctx.workspace.id)
4914
+ and39(
4915
+ eq55(runs.id, connection.discoveryRunId),
4916
+ eq55(runs.workspaceId, ctx.workspace.id)
4790
4917
  )
4791
4918
  ).get();
4792
4919
  if (previous && ["queued", "running"].includes(previous.status)) {
4793
4920
  transaction.db.update(runs).set({
4794
4921
  cancelRequested: true,
4795
4922
  ...previous.status === "queued" ? { status: "cancelled" } : {}
4796
- }).where(eq53(runs.id, previous.id)).run();
4923
+ }).where(eq55(runs.id, previous.id)).run();
4797
4924
  }
4798
4925
  }
4799
4926
  const target = { ...mcpSnapshot(transaction, input2.id), tools: [] };
@@ -4825,14 +4952,14 @@ var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
4825
4952
  ]
4826
4953
  }
4827
4954
  }).returning().get();
4828
- transaction.db.update(mcpConnections).set({ discoveryRunId: run.id, status: "checking", candidate: null }).where(eq53(mcpConnections.pluginId, input2.id)).run();
4955
+ transaction.db.update(mcpConnections).set({ discoveryRunId: run.id, status: "checking", candidate: null }).where(eq55(mcpConnections.pluginId, input2.id)).run();
4829
4956
  recordAudit(transaction, "plugin", input2.id, "discovery.requested");
4830
4957
  return { run: run.id };
4831
4958
  })
4832
4959
  );
4833
4960
 
4834
4961
  // server/router/plugins/mcp/accept.ts
4835
- import { eq as eq54 } from "drizzle-orm";
4962
+ import { eq as eq56 } from "drizzle-orm";
4836
4963
 
4837
4964
  // runtime/src/mcp/aliases.ts
4838
4965
  import { createHash as createHash3 } from "node:crypto";
@@ -4915,13 +5042,13 @@ var acceptProcedure = browserManagerProcedure.input(catalogueAcceptSchema).mutat
4915
5042
  candidate: null,
4916
5043
  revision: revision3,
4917
5044
  status: "ready"
4918
- }).where(eq54(mcpConnections.pluginId, input2.id)).run();
5045
+ }).where(eq56(mcpConnections.pluginId, input2.id)).run();
4919
5046
  transaction.db.update(plugins).set({
4920
5047
  version: String(revision3),
4921
5048
  digest: digest(JSON.stringify(catalogue)),
4922
5049
  enabled: selected.size > 0,
4923
5050
  updatedAt: now()
4924
- }).where(eq54(plugins.id, input2.id)).run();
5051
+ }).where(eq56(plugins.id, input2.id)).run();
4925
5052
  recordAudit(transaction, "plugin", input2.id, "catalogue.accepted");
4926
5053
  return { id: input2.id, revision: revision3 };
4927
5054
  })
@@ -4974,54 +5101,54 @@ var getProcedure9 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx
4974
5101
  });
4975
5102
 
4976
5103
  // server/router/plugins/create.ts
4977
- import { and as and39, eq as eq55 } from "drizzle-orm";
5104
+ import { and as and40, eq as eq57 } from "drizzle-orm";
4978
5105
 
4979
5106
  // server/plugins/catalog.ts
4980
- import { z as z32 } from "zod";
5107
+ import { z as z34 } from "zod";
4981
5108
 
4982
5109
  // server/plugins/catalog-schemas.ts
4983
- import { z as z31 } from "zod";
4984
- var jsonObject4 = z31.record(z31.string(), z31.json());
4985
- var slug = z31.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/);
4986
- var releaseSchema = z31.object({
5110
+ import { z as z33 } from "zod";
5111
+ var jsonObject4 = z33.record(z33.string(), z33.json());
5112
+ var slug = z33.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/);
5113
+ var releaseSchema = z33.object({
4987
5114
  slug,
4988
- version: z31.string().min(1).max(100),
4989
- digest: z31.string().regex(/^[a-f0-9]{64}$/),
4990
- package_url: z31.string(),
4991
- display_name: z31.string(),
4992
- description: z31.string(),
4993
- category: z31.string(),
4994
- documentation: z31.string(),
4995
- distribution: z31.literal("external"),
4996
- contract_version: z31.literal(1),
4997
- auth: z31.object({
4998
- type: z31.string().optional(),
4999
- provider: z31.string().optional(),
5000
- label: z31.string().optional(),
5001
- hint: z31.string().optional(),
5002
- scopes: z31.array(z31.string()).optional()
5003
- }).catchall(z31.json()),
5115
+ version: z33.string().min(1).max(100),
5116
+ digest: z33.string().regex(/^[a-f0-9]{64}$/),
5117
+ package_url: z33.string(),
5118
+ display_name: z33.string(),
5119
+ description: z33.string(),
5120
+ category: z33.string(),
5121
+ documentation: z33.string(),
5122
+ distribution: z33.literal("external"),
5123
+ contract_version: z33.literal(1),
5124
+ auth: z33.object({
5125
+ type: z33.string().optional(),
5126
+ provider: z33.string().optional(),
5127
+ label: z33.string().optional(),
5128
+ hint: z33.string().optional(),
5129
+ scopes: z33.array(z33.string()).optional()
5130
+ }).catchall(z33.json()),
5004
5131
  marketplace: jsonObject4,
5005
5132
  configuration_schema: jsonObject4,
5006
- tools: z31.array(jsonObject4)
5007
- }).catchall(z31.json());
5008
- var marketplaceSchema = z31.object({
5009
- schema_version: z31.literal(1),
5010
- plugins: z31.array(
5011
- z31.object({
5133
+ tools: z33.array(jsonObject4)
5134
+ }).catchall(z33.json());
5135
+ var marketplaceSchema = z33.object({
5136
+ schema_version: z33.literal(1),
5137
+ plugins: z33.array(
5138
+ z33.object({
5012
5139
  slug,
5013
- display_name: z31.string(),
5014
- description: z31.string(),
5015
- category: z31.string(),
5016
- permissions: z31.string(),
5017
- source_version: z31.string(),
5018
- source_url: z31.string(),
5019
- url: z31.string(),
5020
- release_status: z31.enum(["unreleased", "available"]),
5021
- auth_type: z31.enum(["none", "token", "oauth2"]),
5022
- tags: z31.array(z31.string()),
5023
- use_cases: z31.array(z31.string())
5024
- }).catchall(z31.json())
5140
+ display_name: z33.string(),
5141
+ description: z33.string(),
5142
+ category: z33.string(),
5143
+ permissions: z33.string(),
5144
+ source_version: z33.string(),
5145
+ source_url: z33.string(),
5146
+ url: z33.string(),
5147
+ release_status: z33.enum(["unreleased", "available"]),
5148
+ auth_type: z33.enum(["none", "token", "oauth2"]),
5149
+ tags: z33.array(z33.string()),
5150
+ use_cases: z33.array(z33.string())
5151
+ }).catchall(z33.json())
5025
5152
  )
5026
5153
  });
5027
5154
 
@@ -5087,7 +5214,7 @@ async function catalogEntries() {
5087
5214
  "Cannot read the configured plugin catalog."
5088
5215
  );
5089
5216
  }
5090
- const result = z32.array(releaseSchema).safeParse(entries);
5217
+ const result = z34.array(releaseSchema).safeParse(entries);
5091
5218
  if (!result.success) {
5092
5219
  throw new ServiceError(
5093
5220
  "PRECONDITION_FAILED",
@@ -5181,10 +5308,10 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
5181
5308
  metadata2
5182
5309
  );
5183
5310
  const installedPlugin = transaction.db.select({ id: plugins.id }).from(plugins).where(
5184
- and39(
5185
- eq55(plugins.workspaceId, context.workspace.id),
5186
- eq55(plugins.projectId, projectId),
5187
- eq55(plugins.slug, slug2)
5311
+ and40(
5312
+ eq57(plugins.workspaceId, context.workspace.id),
5313
+ eq57(plugins.projectId, projectId),
5314
+ eq57(plugins.slug, slug2)
5188
5315
  )
5189
5316
  ).limit(1).get();
5190
5317
  if (installedPlugin) {
@@ -5200,8 +5327,8 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
5200
5327
  });
5201
5328
 
5202
5329
  // server/router/plugins/update.ts
5203
- import { isDeepStrictEqual } from "node:util";
5204
- import { and as and40, eq as eq56 } from "drizzle-orm";
5330
+ import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
5331
+ import { and as and41, eq as eq58 } from "drizzle-orm";
5205
5332
  var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutation(async ({ ctx: context, input: input2 }) => {
5206
5333
  const { id, ...changes } = input2;
5207
5334
  const originalPlugin = pluginsRepository(context).find(id);
@@ -5240,7 +5367,7 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
5240
5367
  return inTransaction(context, (transaction) => {
5241
5368
  assertCurrentPluginManager(transaction);
5242
5369
  const plugin = pluginsRepository(transaction).find(id);
5243
- if (!isDeepStrictEqual(plugin, originalPlugin)) {
5370
+ if (!isDeepStrictEqual2(plugin, originalPlugin)) {
5244
5371
  throw new ServiceError(
5245
5372
  "CONFLICT",
5246
5373
  "The plugin changed while loading its release. Reload and retry."
@@ -5289,9 +5416,9 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
5289
5416
  releaseMetadata: metadata2,
5290
5417
  updatedAt: now()
5291
5418
  }).where(
5292
- and40(
5293
- eq56(plugins.workspaceId, context.workspace.id),
5294
- eq56(plugins.id, id)
5419
+ and41(
5420
+ eq58(plugins.workspaceId, context.workspace.id),
5421
+ eq58(plugins.id, id)
5295
5422
  )
5296
5423
  ).returning().get();
5297
5424
  if (!updatedPlugin) {
@@ -5303,15 +5430,15 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
5303
5430
  });
5304
5431
 
5305
5432
  // server/router/plugins/delete.ts
5306
- import { and as and41, eq as eq57 } from "drizzle-orm";
5433
+ import { and as and42, eq as eq59 } from "drizzle-orm";
5307
5434
  var deleteProcedure3 = browserManagerProcedure.input(pluginIdSchema).mutation(({ ctx, input: input2 }) => {
5308
5435
  inTransaction(ctx, (transaction) => {
5309
5436
  assertCurrentPluginManager(transaction);
5310
5437
  cancelConnectionRuns(transaction, input2.id);
5311
5438
  const deletedPlugin = transaction.db.delete(plugins).where(
5312
- and41(
5313
- eq57(plugins.workspaceId, ctx.workspace.id),
5314
- eq57(plugins.id, input2.id)
5439
+ and42(
5440
+ eq59(plugins.workspaceId, ctx.workspace.id),
5441
+ eq59(plugins.id, input2.id)
5315
5442
  )
5316
5443
  ).returning({ id: plugins.id, credentialId: plugins.credentialId }).get();
5317
5444
  if (!deletedPlugin) {
@@ -5361,6 +5488,8 @@ var pluginsRouter = router({
5361
5488
  shellRules: shellRulesProcedure,
5362
5489
  setShellRule: setShellRuleProcedure,
5363
5490
  list: listProcedure8,
5491
+ settings: settingsProcedure,
5492
+ configure: configureProcedure,
5364
5493
  get: getProcedure9,
5365
5494
  create: createProcedure5,
5366
5495
  update: updateProcedure5,
@@ -5370,23 +5499,23 @@ var pluginsRouter = router({
5370
5499
  });
5371
5500
 
5372
5501
  // server/router/projects/list.ts
5373
- import { and as and43, eq as eq60 } from "drizzle-orm";
5502
+ import { and as and44, eq as eq62 } from "drizzle-orm";
5374
5503
 
5375
5504
  // server/projects/queries.ts
5376
- import { and as and42, eq as eq58, inArray as inArray6, or as or3 } from "drizzle-orm";
5505
+ import { and as and43, eq as eq60, inArray as inArray6, or as or3 } from "drizzle-orm";
5377
5506
  function projectVisibility(database, workspaceId, grants2) {
5378
5507
  if (!grants2) {
5379
5508
  return void 0;
5380
5509
  }
5381
5510
  const grantedActionProjects = database.select({ projectId: actions.projectId }).from(actions).innerJoin(
5382
5511
  actionVersions,
5383
- and42(
5384
- eq58(actionVersions.actionId, actions.id),
5385
- eq58(actionVersions.workspaceId, workspaceId)
5512
+ and43(
5513
+ eq60(actionVersions.actionId, actions.id),
5514
+ eq60(actionVersions.workspaceId, workspaceId)
5386
5515
  )
5387
5516
  ).where(
5388
- and42(
5389
- eq58(actions.workspaceId, workspaceId),
5517
+ and43(
5518
+ eq60(actions.workspaceId, workspaceId),
5390
5519
  inArray6(actionVersions.id, grants2.actionVersions)
5391
5520
  )
5392
5521
  );
@@ -5397,12 +5526,12 @@ function projectVisibility(database, workspaceId, grants2) {
5397
5526
  }
5398
5527
 
5399
5528
  // server/projects/views.ts
5400
- import { eq as eq59 } from "drizzle-orm";
5529
+ import { eq as eq61 } from "drizzle-orm";
5401
5530
  function serializeProject(ctx, row) {
5402
5531
  const executor2 = executorsRepository(ctx).list(
5403
- eq59(executors.projectId, row.id)
5532
+ eq61(executors.projectId, row.id)
5404
5533
  )[0];
5405
- const pluginIds = pluginsRepository(ctx).list(eq59(plugins.projectId, row.id)).map((plugin) => plugin.id);
5534
+ const pluginIds = pluginsRepository(ctx).list(eq61(plugins.projectId, row.id)).map((plugin) => plugin.id);
5406
5535
  const minimal = {
5407
5536
  id: row.id,
5408
5537
  name: row.name,
@@ -5433,8 +5562,8 @@ function serializeProject(ctx, row) {
5433
5562
  var listProcedure9 = scopedProcedure("catalog:read").query(
5434
5563
  ({ ctx }) => {
5435
5564
  const projects2 = ctx.db.select().from(projects).where(
5436
- and43(
5437
- eq60(projects.workspaceId, ctx.workspace.id),
5565
+ and44(
5566
+ eq62(projects.workspaceId, ctx.workspace.id),
5438
5567
  projectVisibility(ctx.db, ctx.workspace.id, ctx.token)
5439
5568
  )
5440
5569
  ).all();
@@ -5443,12 +5572,12 @@ var listProcedure9 = scopedProcedure("catalog:read").query(
5443
5572
  );
5444
5573
 
5445
5574
  // server/router/projects/get.ts
5446
- import { and as and44, eq as eq61 } from "drizzle-orm";
5575
+ import { and as and45, eq as eq63 } from "drizzle-orm";
5447
5576
  var getProcedure10 = scopedProcedure("catalog:read").input(projectIdSchema).query(({ ctx, input: input2 }) => {
5448
5577
  const project = ctx.db.select().from(projects).where(
5449
- and44(
5450
- eq61(projects.workspaceId, ctx.workspace.id),
5451
- eq61(projects.id, input2.id),
5578
+ and45(
5579
+ eq63(projects.workspaceId, ctx.workspace.id),
5580
+ eq63(projects.id, input2.id),
5452
5581
  projectVisibility(ctx.db, ctx.workspace.id, ctx.token)
5453
5582
  )
5454
5583
  ).get();
@@ -5459,12 +5588,12 @@ var getProcedure10 = scopedProcedure("catalog:read").input(projectIdSchema).quer
5459
5588
  });
5460
5589
 
5461
5590
  // server/repositories/workspace-tables.ts
5462
- import { and as and45, eq as eq62 } from "drizzle-orm";
5591
+ import { and as and46, eq as eq64 } from "drizzle-orm";
5463
5592
  function findWorkspaceTable(database, workspaceId, id) {
5464
5593
  const record = database.select().from(workspaceTables).where(
5465
- and45(
5466
- eq62(workspaceTables.workspaceId, workspaceId),
5467
- eq62(workspaceTables.id, id)
5594
+ and46(
5595
+ eq64(workspaceTables.workspaceId, workspaceId),
5596
+ eq64(workspaceTables.id, id)
5468
5597
  )
5469
5598
  ).get();
5470
5599
  if (!record) {
@@ -5536,21 +5665,21 @@ var updateProcedure6 = browserManagerProcedure.input(projectChangesSchema).mutat
5536
5665
  });
5537
5666
 
5538
5667
  // server/router/projects/delete.ts
5539
- import { and as and46, eq as eq63 } from "drizzle-orm";
5668
+ import { and as and47, eq as eq65 } from "drizzle-orm";
5540
5669
  var deleteProcedure4 = browserManagerProcedure.input(projectIdSchema).mutation(({ ctx, input: input2 }) => {
5541
5670
  inTransaction(ctx, (transaction) => {
5542
5671
  const projects2 = projectsRepository(transaction);
5543
5672
  projects2.find(input2.id);
5544
5673
  const retainedRun = transaction.db.select({ id: runs.id }).from(runs).where(
5545
- and46(
5546
- eq63(runs.workspaceId, ctx.workspace.id),
5547
- eq63(runs.projectId, input2.id)
5674
+ and47(
5675
+ eq65(runs.workspaceId, ctx.workspace.id),
5676
+ eq65(runs.projectId, input2.id)
5548
5677
  )
5549
5678
  ).limit(1).get();
5550
5679
  const retainedAction = transaction.db.select({ id: actions.id }).from(actions).where(
5551
- and46(
5552
- eq63(actions.workspaceId, ctx.workspace.id),
5553
- eq63(actions.projectId, input2.id)
5680
+ and47(
5681
+ eq65(actions.workspaceId, ctx.workspace.id),
5682
+ eq65(actions.projectId, input2.id)
5554
5683
  )
5555
5684
  ).limit(1).get();
5556
5685
  if (retainedRun || retainedAction) {
@@ -5560,9 +5689,9 @@ var deleteProcedure4 = browserManagerProcedure.input(projectIdSchema).mutation((
5560
5689
  );
5561
5690
  }
5562
5691
  const deleted = transaction.db.delete(projects).where(
5563
- and46(
5564
- eq63(projects.workspaceId, ctx.workspace.id),
5565
- eq63(projects.id, input2.id)
5692
+ and47(
5693
+ eq65(projects.workspaceId, ctx.workspace.id),
5694
+ eq65(projects.id, input2.id)
5566
5695
  )
5567
5696
  ).returning({ id: projects.id }).get();
5568
5697
  if (deleted) {
@@ -5582,19 +5711,19 @@ import { createHmac as createHmac2, randomUUID as randomUUID4 } from "node:crypt
5582
5711
 
5583
5712
  // server/projects/executor.ts
5584
5713
  import { randomUUID as randomUUID3 } from "node:crypto";
5585
- import { and as and47, eq as eq64, inArray as inArray7 } from "drizzle-orm";
5714
+ import { and as and48, eq as eq66, inArray as inArray7 } from "drizzle-orm";
5586
5715
  function revokeExecutor(ctx, id) {
5587
5716
  const workspaceId = requireWorkspace(ctx).id;
5588
5717
  const worker = ctx.db.select().from(executors).where(
5589
- and47(eq64(executors.workspaceId, workspaceId), eq64(executors.projectId, id))
5718
+ and48(eq66(executors.workspaceId, workspaceId), eq66(executors.projectId, id))
5590
5719
  ).get();
5591
5720
  if (!worker) {
5592
5721
  return;
5593
5722
  }
5594
5723
  const activeRuns = ctx.db.select().from(runs).where(
5595
- and47(
5596
- eq64(runs.workspaceId, workspaceId),
5597
- eq64(runs.executorId, worker.id),
5724
+ and48(
5725
+ eq66(runs.workspaceId, workspaceId),
5726
+ eq66(runs.executorId, worker.id),
5598
5727
  inArray7(runs.status, ["running", "waiting_approval"])
5599
5728
  )
5600
5729
  ).all();
@@ -5607,10 +5736,10 @@ function revokeExecutor(ctx, id) {
5607
5736
  leaseExpiresAt: null
5608
5737
  });
5609
5738
  const pendingApprovals = ctx.db.select().from(approvals).where(
5610
- and47(
5611
- eq64(approvals.workspaceId, workspaceId),
5612
- eq64(approvals.runId, run.id),
5613
- eq64(approvals.status, "pending")
5739
+ and48(
5740
+ eq66(approvals.workspaceId, workspaceId),
5741
+ eq66(approvals.runId, run.id),
5742
+ eq66(approvals.status, "pending")
5614
5743
  )
5615
5744
  ).all();
5616
5745
  for (const approval of pendingApprovals) {
@@ -5699,17 +5828,17 @@ var projectsRouter = router({
5699
5828
  });
5700
5829
 
5701
5830
  // server/router/runs/list.ts
5702
- import { and as and48, desc as desc4, eq as eq65, inArray as inArray8, or as or4 } from "drizzle-orm";
5831
+ import { and as and49, desc as desc4, eq as eq67, inArray as inArray8, or as or4 } from "drizzle-orm";
5703
5832
  var listProcedure10 = scopedProcedure("runs:read").query(({ ctx }) => {
5704
5833
  const token = ctx.token;
5705
- const grant = token ? and48(
5706
- eq65(runs.tokenId, token.id),
5834
+ const grant = token ? and49(
5835
+ eq67(runs.tokenId, token.id),
5707
5836
  or4(
5708
5837
  inArray8(runs.projectId, token.projects),
5709
5838
  inArray8(runs.actionVersionId, token.actionVersions)
5710
5839
  )
5711
5840
  ) : void 0;
5712
- const visibleRuns = ctx.db.select().from(runs).where(and48(eq65(runs.workspaceId, ctx.workspace.id), grant)).orderBy(desc4(runs.createdAt)).all();
5841
+ const visibleRuns = ctx.db.select().from(runs).where(and49(eq67(runs.workspaceId, ctx.workspace.id), grant)).orderBy(desc4(runs.createdAt)).all();
5713
5842
  return page(visibleRuns.map(serializeRun));
5714
5843
  });
5715
5844
 
@@ -5727,14 +5856,14 @@ var createProcedure7 = protectedProcedure.input(createRunSchema).mutation(({ ctx
5727
5856
  });
5728
5857
 
5729
5858
  // server/router/runs/events.ts
5730
- import { and as and49, asc as asc4, eq as eq66 } from "drizzle-orm";
5859
+ import { and as and50, asc as asc4, eq as eq68 } from "drizzle-orm";
5731
5860
  var eventsProcedure = scopedProcedure("runs:read").input(runIdSchema).query(({ ctx, input: input2 }) => {
5732
5861
  const run = runsRepository(ctx).find(input2.id);
5733
5862
  authorizeRunRead(ctx, run, null);
5734
5863
  const events = ctx.db.select().from(runEvents).where(
5735
- and49(
5736
- eq66(runEvents.workspaceId, ctx.workspace.id),
5737
- eq66(runEvents.runId, input2.id)
5864
+ and50(
5865
+ eq68(runEvents.workspaceId, ctx.workspace.id),
5866
+ eq68(runEvents.runId, input2.id)
5738
5867
  )
5739
5868
  ).orderBy(asc4(runEvents.sequence)).all();
5740
5869
  return events.map((event) => ({
@@ -5819,7 +5948,7 @@ var retryProcedure = protectedProcedure.input(retryRunSchema).mutation(
5819
5948
  );
5820
5949
 
5821
5950
  // server/router/runs/cancel.ts
5822
- import { and as and50, eq as eq67 } from "drizzle-orm";
5951
+ import { and as and51, eq as eq69 } from "drizzle-orm";
5823
5952
  var cancelProcedure = scopedProcedure("runs:cancel").input(runIdSchema).mutation(({ ctx, input: input2 }) => {
5824
5953
  const id = input2.id;
5825
5954
  const updated = inTransaction(ctx, (ctx2) => {
@@ -5833,10 +5962,10 @@ var cancelProcedure = scopedProcedure("runs:cancel").input(runIdSchema).mutation
5833
5962
  cancelRequested: true
5834
5963
  });
5835
5964
  const pendingApprovals = ctx2.db.select().from(approvals).where(
5836
- and50(
5837
- eq67(approvals.workspaceId, ctx2.workspace.id),
5838
- eq67(approvals.runId, id),
5839
- eq67(approvals.status, "pending")
5965
+ and51(
5966
+ eq69(approvals.workspaceId, ctx2.workspace.id),
5967
+ eq69(approvals.runId, id),
5968
+ eq69(approvals.status, "pending")
5840
5969
  )
5841
5970
  ).all();
5842
5971
  for (const approval of pendingApprovals) {
@@ -5892,7 +6021,7 @@ var promoteProcedure = scopedProcedure(["runs:read", "actions:write"]).input(pro
5892
6021
 
5893
6022
  // server/router/runs/stream.ts
5894
6023
  import { setTimeout } from "node:timers/promises";
5895
- import { and as and51, asc as asc5, eq as eq68, gt as gt5 } from "drizzle-orm";
6024
+ import { and as and52, asc as asc5, eq as eq70, gt as gt5 } from "drizzle-orm";
5896
6025
  var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscription(async function* ({ ctx, input: input2, signal }) {
5897
6026
  const run = runsRepository(ctx).find(input2.id);
5898
6027
  authorizeRunRead(ctx, run, null);
@@ -5902,9 +6031,9 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
5902
6031
  return;
5903
6032
  }
5904
6033
  const membership = ctx.db.select().from(memberships).where(
5905
- and51(
5906
- eq68(memberships.workspaceId, ctx.workspace.id),
5907
- eq68(memberships.userId, ctx.userId)
6034
+ and52(
6035
+ eq70(memberships.workspaceId, ctx.workspace.id),
6036
+ eq70(memberships.userId, ctx.userId)
5908
6037
  )
5909
6038
  ).get();
5910
6039
  if (!membership) {
@@ -5913,9 +6042,9 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
5913
6042
  let currentContext = ctx;
5914
6043
  if (ctx.token) {
5915
6044
  const token = ctx.db.select().from(accessTokens).where(
5916
- and51(
5917
- eq68(accessTokens.id, ctx.token.id),
5918
- eq68(accessTokens.workspaceId, ctx.workspace.id)
6045
+ and52(
6046
+ eq70(accessTokens.id, ctx.token.id),
6047
+ eq70(accessTokens.workspaceId, ctx.workspace.id)
5919
6048
  )
5920
6049
  ).get();
5921
6050
  if (!token || token.revoked) {
@@ -5935,9 +6064,9 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
5935
6064
  }
5936
6065
  const current = runsRepository(currentContext).find(input2.id);
5937
6066
  const batch = currentContext.db.select().from(runEvents).where(
5938
- and51(
5939
- eq68(runEvents.workspaceId, ctx.workspace.id),
5940
- eq68(runEvents.runId, input2.id),
6067
+ and52(
6068
+ eq70(runEvents.workspaceId, ctx.workspace.id),
6069
+ eq70(runEvents.runId, input2.id),
5941
6070
  gt5(runEvents.sequence, after)
5942
6071
  )
5943
6072
  ).orderBy(asc5(runEvents.sequence)).limit(100).all();
@@ -5978,7 +6107,7 @@ var runsRouter = router({
5978
6107
  });
5979
6108
 
5980
6109
  // server/router/schedules/list.ts
5981
- import { eq as eq69 } from "drizzle-orm";
6110
+ import { eq as eq71 } from "drizzle-orm";
5982
6111
 
5983
6112
  // server/automations/schedule-view.ts
5984
6113
  function scheduleView(schedule) {
@@ -5994,21 +6123,21 @@ function scheduleView(schedule) {
5994
6123
 
5995
6124
  // server/router/schedules/list.ts
5996
6125
  var listProcedure11 = browserWorkspaceProcedure.query(({ ctx }) => {
5997
- const records = ctx.db.select().from(schedules).where(eq69(schedules.workspaceId, ctx.workspace.id)).all();
6126
+ const records = ctx.db.select().from(schedules).where(eq71(schedules.workspaceId, ctx.workspace.id)).all();
5998
6127
  return page(records.map((record) => scheduleView(record)));
5999
6128
  });
6000
6129
 
6001
6130
  // server/router/schedules/get.ts
6002
- import { z as z33 } from "zod";
6131
+ import { z as z35 } from "zod";
6003
6132
 
6004
6133
  // server/repositories/schedules.ts
6005
- import { and as and52, eq as eq70 } from "drizzle-orm";
6134
+ import { and as and53, eq as eq72 } from "drizzle-orm";
6006
6135
  function schedulesRepository(context) {
6007
6136
  const workspaceId = requireWorkspace(context).id;
6008
6137
  return {
6009
6138
  find(id) {
6010
6139
  const record = context.db.select().from(schedules).where(
6011
- and52(eq70(schedules.workspaceId, workspaceId), eq70(schedules.id, id))
6140
+ and53(eq72(schedules.workspaceId, workspaceId), eq72(schedules.id, id))
6012
6141
  ).get();
6013
6142
  if (!record) {
6014
6143
  throw new ServiceError("NOT_FOUND", "Not found.");
@@ -6019,21 +6148,21 @@ function schedulesRepository(context) {
6019
6148
  }
6020
6149
 
6021
6150
  // server/router/schedules/get.ts
6022
- var getProcedure12 = browserWorkspaceProcedure.input(z33.object({ id: z33.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
6151
+ var getProcedure12 = browserWorkspaceProcedure.input(z35.object({ id: z35.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
6023
6152
  const id = input2.id;
6024
6153
  return scheduleView(schedulesRepository(context).find(id));
6025
6154
  });
6026
6155
 
6027
6156
  // server/automations/schedule-schemas.ts
6028
- import { z as z34 } from "zod";
6029
- var scheduleFields = z34.object({
6030
- action: z34.uuid(),
6031
- cron: z34.string().trim().min(1).max(100),
6032
- inputs: z34.json().optional(),
6033
- enabled: z34.boolean().optional()
6157
+ import { z as z36 } from "zod";
6158
+ var scheduleFields = z36.object({
6159
+ action: z36.uuid(),
6160
+ cron: z36.string().trim().min(1).max(100),
6161
+ inputs: z36.json().optional(),
6162
+ enabled: z36.boolean().optional()
6034
6163
  });
6035
6164
  var scheduleCreateSchema = scheduleFields.strict();
6036
- var scheduleUpdateSchema = scheduleFields.partial().extend({ id: z34.uuid() }).strict();
6165
+ var scheduleUpdateSchema = scheduleFields.partial().extend({ id: z36.uuid() }).strict();
6037
6166
 
6038
6167
  // server/automations/cron.ts
6039
6168
  import { CronExpressionParser } from "cron-parser";
@@ -6084,7 +6213,7 @@ var createProcedure8 = browserWorkspaceProcedure.input(scheduleCreateSchema).mut
6084
6213
  });
6085
6214
 
6086
6215
  // server/router/schedules/update.ts
6087
- import { and as and53, eq as eq71 } from "drizzle-orm";
6216
+ import { and as and54, eq as eq73 } from "drizzle-orm";
6088
6217
  var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mutation(({ ctx: context, input: input2 }) => {
6089
6218
  return inTransaction(context, (context2) => {
6090
6219
  const previous = schedulesRepository(context2).find(input2.id);
@@ -6107,9 +6236,9 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
6107
6236
  nextRunAt,
6108
6237
  updatedAt: now()
6109
6238
  }).where(
6110
- and53(
6111
- eq71(schedules.workspaceId, context2.workspace.id),
6112
- eq71(schedules.id, input2.id)
6239
+ and54(
6240
+ eq73(schedules.workspaceId, context2.workspace.id),
6241
+ eq73(schedules.id, input2.id)
6113
6242
  )
6114
6243
  ).returning().get();
6115
6244
  if (!schedule) {
@@ -6121,15 +6250,15 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
6121
6250
  });
6122
6251
 
6123
6252
  // server/router/schedules/delete.ts
6124
- import { and as and54, eq as eq72 } from "drizzle-orm";
6125
- import { z as z35 } from "zod";
6126
- var deleteProcedure5 = browserWorkspaceProcedure.input(z35.object({ id: z35.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
6253
+ import { and as and55, eq as eq74 } from "drizzle-orm";
6254
+ import { z as z37 } from "zod";
6255
+ var deleteProcedure5 = browserWorkspaceProcedure.input(z37.object({ id: z37.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
6127
6256
  const id = input2.id;
6128
6257
  return inTransaction(context, (context2) => {
6129
6258
  const deleted = context2.db.delete(schedules).where(
6130
- and54(
6131
- eq72(schedules.workspaceId, context2.workspace.id),
6132
- eq72(schedules.id, id)
6259
+ and55(
6260
+ eq74(schedules.workspaceId, context2.workspace.id),
6261
+ eq74(schedules.id, id)
6133
6262
  )
6134
6263
  ).returning({ id: schedules.id }).get();
6135
6264
  if (!deleted) {
@@ -6149,8 +6278,8 @@ var schedulesRouter = router({
6149
6278
  });
6150
6279
 
6151
6280
  // server/router/studio/approve.ts
6152
- import { z as z36 } from "zod";
6153
- var approve = browserWorkspaceProcedure.input(z36.object({ challenge: z36.string().regex(/^[0-9a-f]{64}$/) }).strict()).mutation(({ ctx, input: input2 }) => {
6281
+ import { z as z38 } from "zod";
6282
+ var approve = browserWorkspaceProcedure.input(z38.object({ challenge: z38.string().regex(/^[0-9a-f]{64}$/) }).strict()).mutation(({ ctx, input: input2 }) => {
6154
6283
  if (ctx.studioOrigin || !ctx.sessionId || ctx.request.headers.get("origin") !== ctx.origin) {
6155
6284
  throw new ServiceError(
6156
6285
  "FORBIDDEN",
@@ -6178,9 +6307,9 @@ var discover = publicProcedure.query(({ ctx }) => {
6178
6307
  });
6179
6308
 
6180
6309
  // server/router/studio/exchange.ts
6181
- import { z as z37 } from "zod";
6310
+ import { z as z39 } from "zod";
6182
6311
  var exchange = publicProcedure.input(
6183
- z37.object({ code: z37.string().length(43), verifier: z37.string().length(64) }).strict()
6312
+ z39.object({ code: z39.string().length(43), verifier: z39.string().length(64) }).strict()
6184
6313
  ).mutation(({ ctx, input: input2 }) => {
6185
6314
  if (!ctx.studioOrigin) {
6186
6315
  throw new ServiceError("FORBIDDEN", "Open the configured dashboard.");
@@ -6198,19 +6327,32 @@ var exchange = publicProcedure.input(
6198
6327
  var studioRouter = router({ approve, discover, exchange });
6199
6328
 
6200
6329
  // server/platform/installation-update.ts
6201
- import { inArray as inArray9 } from "drizzle-orm";
6330
+ import { and as and56, count, eq as eq75, inArray as inArray9 } from "drizzle-orm";
6202
6331
  var managerHeartbeat = /* @__PURE__ */ new WeakMap();
6203
6332
  var requested = /* @__PURE__ */ new WeakMap();
6333
+ var blockingRunStatuses = ["running", "waiting_approval"];
6204
6334
  function canManageUpdate(ctx) {
6205
6335
  return ctx.role === "owner" && !!ctx.sessionId && !ctx.token && process.env.ORGSDK_MANAGED_UPDATES === "1" && !!process.connected && isLoopbackInstallation(ctx.origin) && ctx.db.select({ id: workspaces.id }).from(workspaces).limit(2).all().length === 1;
6206
6336
  }
6207
6337
  function pendingUpdate(db) {
6208
6338
  return requested.get(db) ?? null;
6209
6339
  }
6340
+ function updateBlockers(db, workspaceId) {
6341
+ const blockers = db.select({ status: runs.status, total: count() }).from(runs).where(
6342
+ and56(
6343
+ eq75(runs.workspaceId, workspaceId),
6344
+ inArray9(runs.status, blockingRunStatuses)
6345
+ )
6346
+ ).groupBy(runs.status).all();
6347
+ return {
6348
+ running: blockers.find(({ status }) => status === "running")?.total ?? 0,
6349
+ awaitingApproval: blockers.find(({ status }) => status === "waiting_approval")?.total ?? 0
6350
+ };
6351
+ }
6210
6352
  function drainForUpdate(db, version2) {
6211
6353
  requested.set(db, version2);
6212
6354
  const timer = setInterval(() => {
6213
- const busy = db.select({ id: runs.id }).from(runs).where(inArray9(runs.status, ["running", "waiting_approval"])).limit(1).get();
6355
+ const busy = db.select({ id: runs.id }).from(runs).where(inArray9(runs.status, blockingRunStatuses)).limit(1).get();
6214
6356
  if (busy) {
6215
6357
  return;
6216
6358
  }
@@ -6229,8 +6371,8 @@ function drainForUpdate(db, version2) {
6229
6371
  }
6230
6372
 
6231
6373
  // server/platform/stable-release.ts
6232
- import { z as z38 } from "zod";
6233
- var stableVersion = z38.string().max(32).regex(/^(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})$/);
6374
+ import { z as z40 } from "zod";
6375
+ var stableVersion = z40.string().max(32).regex(/^(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})$/);
6234
6376
  function newerStable(candidate, installed) {
6235
6377
  if (!stableVersion.safeParse(candidate).success || !stableVersion.safeParse(installed).success) {
6236
6378
  return false;
@@ -6244,8 +6386,8 @@ function newerStable(candidate, installed) {
6244
6386
  }
6245
6387
  return false;
6246
6388
  }
6247
- var release = z38.object({
6248
- name: z38.literal("@orgsdk/cli"),
6389
+ var release = z40.object({
6390
+ name: z40.literal("@orgsdk/cli"),
6249
6391
  version: stableVersion
6250
6392
  });
6251
6393
  var cached;
@@ -6271,25 +6413,27 @@ function latestStable() {
6271
6413
  }
6272
6414
 
6273
6415
  // package.json
6274
- var version = "2.4.0";
6416
+ var version = "2.5.0";
6275
6417
 
6276
6418
  // server/router/system/update-status.ts
6277
6419
  var updateStatus = browserWorkspaceProcedure.query(async ({ ctx }) => {
6278
6420
  const latest = await latestStable();
6421
+ const pending = pendingUpdate(ctx.db);
6279
6422
  return {
6280
6423
  installed: version,
6281
6424
  available: latest && newerStable(latest, version) ? latest : null,
6282
6425
  executorReady: Date.now() - (managerHeartbeat.get(ctx.secrets) ?? 0) < 3e4,
6283
6426
  checked: latest !== null,
6284
6427
  automatic: canManageUpdate(ctx),
6285
- pending: pendingUpdate(ctx.db),
6428
+ pending,
6429
+ blockers: pending ? updateBlockers(ctx.db, ctx.workspace.id) : null,
6286
6430
  failed: process.env.ORGSDK_FAILED_UPDATE ?? null
6287
6431
  };
6288
6432
  });
6289
6433
 
6290
6434
  // server/router/system/request-update.ts
6291
- import { z as z39 } from "zod";
6292
- var requestUpdate = browserOwnerProcedure.input(z39.object({ version: stableVersion }).strict()).mutation(async ({ ctx, input: input2 }) => {
6435
+ import { z as z41 } from "zod";
6436
+ var requestUpdate = browserOwnerProcedure.input(z41.object({ version: stableVersion }).strict()).mutation(async ({ ctx, input: input2 }) => {
6293
6437
  if (!canManageUpdate(ctx)) {
6294
6438
  throw new ServiceError(
6295
6439
  "FORBIDDEN",
@@ -6333,7 +6477,7 @@ var systemRouter = router({
6333
6477
  });
6334
6478
 
6335
6479
  // server/router/tables/list.ts
6336
- import { eq as eq73 } from "drizzle-orm";
6480
+ import { eq as eq76 } from "drizzle-orm";
6337
6481
 
6338
6482
  // server/tables/views.ts
6339
6483
  function standard(row) {
@@ -6358,48 +6502,48 @@ function rowView(row) {
6358
6502
 
6359
6503
  // server/router/tables/list.ts
6360
6504
  var listProcedure12 = browserWorkspaceProcedure.query(({ ctx }) => {
6361
- const records = ctx.db.select().from(workspaceTables).where(eq73(workspaceTables.workspaceId, ctx.workspace.id)).all();
6505
+ const records = ctx.db.select().from(workspaceTables).where(eq76(workspaceTables.workspaceId, ctx.workspace.id)).all();
6362
6506
  return page(records.map((record) => standard(record)));
6363
6507
  });
6364
6508
 
6365
6509
  // server/tables/schemas.ts
6366
- import { z as z40 } from "zod";
6367
- var identifier4 = z40.uuid();
6368
- var revision = z40.number().int().positive();
6369
- var columns = z40.array(
6370
- z40.strictObject({
6371
- key: z40.string(),
6372
- type: z40.enum(["text", "number", "boolean", "date"]),
6373
- required: z40.boolean()
6510
+ import { z as z42 } from "zod";
6511
+ var identifier4 = z42.uuid();
6512
+ var revision = z42.number().int().positive();
6513
+ var columns = z42.array(
6514
+ z42.strictObject({
6515
+ key: z42.string(),
6516
+ type: z42.enum(["text", "number", "boolean", "date"]),
6517
+ required: z42.boolean()
6374
6518
  })
6375
6519
  );
6376
- var values = z40.record(z40.string(), z40.json());
6377
- var tableIdSchema = z40.strictObject({ id: identifier4 });
6378
- var createTableSchema = z40.strictObject({ name: z40.string(), columns });
6379
- var updateTableSchema = z40.strictObject({
6520
+ var values = z42.record(z42.string(), z42.json());
6521
+ var tableIdSchema = z42.strictObject({ id: identifier4 });
6522
+ var createTableSchema = z42.strictObject({ name: z42.string(), columns });
6523
+ var updateTableSchema = z42.strictObject({
6380
6524
  id: identifier4,
6381
6525
  revision,
6382
- name: z40.string().optional(),
6526
+ name: z42.string().optional(),
6383
6527
  columns: columns.optional()
6384
6528
  });
6385
- var deleteTableSchema = z40.strictObject({ id: identifier4, revision });
6386
- var tableRowSchema = z40.strictObject({
6529
+ var deleteTableSchema = z42.strictObject({ id: identifier4, revision });
6530
+ var tableRowSchema = z42.strictObject({
6387
6531
  id: identifier4,
6388
6532
  rowId: identifier4
6389
6533
  });
6390
- var createRowSchema = z40.strictObject({
6534
+ var createRowSchema = z42.strictObject({
6391
6535
  id: identifier4,
6392
6536
  table_revision: revision,
6393
6537
  values
6394
6538
  });
6395
- var updateRowSchema = z40.strictObject({
6539
+ var updateRowSchema = z42.strictObject({
6396
6540
  id: identifier4,
6397
6541
  rowId: identifier4,
6398
6542
  table_revision: revision,
6399
6543
  revision,
6400
6544
  values
6401
6545
  });
6402
- var deleteRowSchema = z40.strictObject({
6546
+ var deleteRowSchema = z42.strictObject({
6403
6547
  id: identifier4,
6404
6548
  rowId: identifier4,
6405
6549
  revision
@@ -6425,15 +6569,15 @@ var createProcedure9 = browserManagerProcedure.input(createTableSchema).mutation
6425
6569
  );
6426
6570
 
6427
6571
  // server/router/tables/update.ts
6428
- import { and as and56, eq as eq75 } from "drizzle-orm";
6572
+ import { and as and58, eq as eq78 } from "drizzle-orm";
6429
6573
 
6430
6574
  // server/tables/queries.ts
6431
- import { and as and55, eq as eq74 } from "drizzle-orm";
6575
+ import { and as and57, eq as eq77 } from "drizzle-orm";
6432
6576
  function rowsForTable(database, workspaceId, tableId2) {
6433
6577
  return database.select().from(tableRows).where(
6434
- and55(
6435
- eq74(tableRows.workspaceId, workspaceId),
6436
- eq74(tableRows.tableId, tableId2)
6578
+ and57(
6579
+ eq77(tableRows.workspaceId, workspaceId),
6580
+ eq77(tableRows.tableId, tableId2)
6437
6581
  )
6438
6582
  ).all();
6439
6583
  }
@@ -6454,9 +6598,9 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
6454
6598
  revision: current.revision + 1,
6455
6599
  updatedAt: now()
6456
6600
  }).where(
6457
- and56(
6458
- eq75(workspaceTables.workspaceId, ctx2.workspace.id),
6459
- eq75(workspaceTables.id, input2.id)
6601
+ and58(
6602
+ eq78(workspaceTables.workspaceId, ctx2.workspace.id),
6603
+ eq78(workspaceTables.id, input2.id)
6460
6604
  )
6461
6605
  ).returning().get();
6462
6606
  if (!table) {
@@ -6469,14 +6613,14 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
6469
6613
  });
6470
6614
 
6471
6615
  // server/router/tables/delete.ts
6472
- import { and as and58, eq as eq77 } from "drizzle-orm";
6616
+ import { and as and60, eq as eq80 } from "drizzle-orm";
6473
6617
 
6474
6618
  // server/repositories/table-rows.ts
6475
- import { and as and57, eq as eq76 } from "drizzle-orm";
6619
+ import { and as and59, eq as eq79 } from "drizzle-orm";
6476
6620
  function removeTableRow(context, id) {
6477
6621
  const workspaceId = requireWorkspace(context).id;
6478
6622
  inTransaction(context, (transaction) => {
6479
- const deleted = transaction.db.delete(tableRows).where(and57(eq76(tableRows.workspaceId, workspaceId), eq76(tableRows.id, id))).returning({ id: tableRows.id }).get();
6623
+ const deleted = transaction.db.delete(tableRows).where(and59(eq79(tableRows.workspaceId, workspaceId), eq79(tableRows.id, id))).returning({ id: tableRows.id }).get();
6480
6624
  if (deleted) {
6481
6625
  recordAudit(transaction, "row", id, "deleted");
6482
6626
  }
@@ -6504,9 +6648,9 @@ var deleteProcedure6 = browserManagerProcedure.input(deleteTableSchema).mutation
6504
6648
  });
6505
6649
  }
6506
6650
  const deleted = ctx2.db.delete(workspaceTables).where(
6507
- and58(
6508
- eq77(workspaceTables.workspaceId, ctx2.workspace.id),
6509
- eq77(workspaceTables.id, input2.id)
6651
+ and60(
6652
+ eq80(workspaceTables.workspaceId, ctx2.workspace.id),
6653
+ eq80(workspaceTables.id, input2.id)
6510
6654
  )
6511
6655
  ).returning({ id: workspaceTables.id }).get();
6512
6656
  if (deleted) {
@@ -6523,13 +6667,13 @@ var listRowsProcedure = browserWorkspaceProcedure.input(tableIdSchema).query(({
6523
6667
  });
6524
6668
 
6525
6669
  // server/tables/access.ts
6526
- import { and as and59, eq as eq78 } from "drizzle-orm";
6670
+ import { and as and61, eq as eq81 } from "drizzle-orm";
6527
6671
  function rowInTable(database, workspaceId, tableId2, rowId) {
6528
6672
  const row = database.select().from(tableRows).where(
6529
- and59(
6530
- eq78(tableRows.workspaceId, workspaceId),
6531
- eq78(tableRows.tableId, tableId2),
6532
- eq78(tableRows.id, rowId)
6673
+ and61(
6674
+ eq81(tableRows.workspaceId, workspaceId),
6675
+ eq81(tableRows.tableId, tableId2),
6676
+ eq81(tableRows.id, rowId)
6533
6677
  )
6534
6678
  ).get();
6535
6679
  if (!row) {
@@ -6564,7 +6708,7 @@ var createRowProcedure = browserWorkspaceProcedure.input(createRowSchema).mutati
6564
6708
  });
6565
6709
 
6566
6710
  // server/router/tables/update-row.ts
6567
- import { and as and60, eq as eq79 } from "drizzle-orm";
6711
+ import { and as and62, eq as eq82 } from "drizzle-orm";
6568
6712
  var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutation(({ ctx, input: input2 }) => {
6569
6713
  return rowView(
6570
6714
  inTransaction(ctx, (ctx2) => {
@@ -6578,9 +6722,9 @@ var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutati
6578
6722
  revision: row.revision + 1,
6579
6723
  updatedAt: now()
6580
6724
  }).where(
6581
- and60(
6582
- eq79(tableRows.workspaceId, ctx2.workspace.id),
6583
- eq79(tableRows.id, input2.rowId)
6725
+ and62(
6726
+ eq82(tableRows.workspaceId, ctx2.workspace.id),
6727
+ eq82(tableRows.id, input2.rowId)
6584
6728
  )
6585
6729
  ).returning().get();
6586
6730
  if (!updatedRow) {
@@ -6620,7 +6764,7 @@ var tablesRouter = router({
6620
6764
  });
6621
6765
 
6622
6766
  // server/router/tokens/list.ts
6623
- import { eq as eq80 } from "drizzle-orm";
6767
+ import { eq as eq83 } from "drizzle-orm";
6624
6768
 
6625
6769
  // server/tokens/views.ts
6626
6770
  function tokenView(row) {
@@ -6648,18 +6792,18 @@ function tokenView(row) {
6648
6792
 
6649
6793
  // server/router/tokens/list.ts
6650
6794
  var listProcedure13 = browserManagerProcedure.query(({ ctx }) => {
6651
- const records = ctx.db.select().from(accessTokens).where(eq80(accessTokens.workspaceId, ctx.workspace.id)).all();
6795
+ const records = ctx.db.select().from(accessTokens).where(eq83(accessTokens.workspaceId, ctx.workspace.id)).all();
6652
6796
  return page(records.map((record) => tokenView(record)));
6653
6797
  });
6654
6798
 
6655
6799
  // server/router/tokens/get.ts
6656
- import { and as and61, eq as eq81 } from "drizzle-orm";
6657
- import { z as z41 } from "zod";
6658
- var getProcedure14 = browserManagerProcedure.input(z41.strictObject({ id: z41.uuid() })).query(({ ctx, input: input2 }) => {
6800
+ import { and as and63, eq as eq84 } from "drizzle-orm";
6801
+ import { z as z43 } from "zod";
6802
+ var getProcedure14 = browserManagerProcedure.input(z43.strictObject({ id: z43.uuid() })).query(({ ctx, input: input2 }) => {
6659
6803
  const token = ctx.db.select().from(accessTokens).where(
6660
- and61(
6661
- eq81(accessTokens.workspaceId, ctx.workspace.id),
6662
- eq81(accessTokens.id, input2.id)
6804
+ and63(
6805
+ eq84(accessTokens.workspaceId, ctx.workspace.id),
6806
+ eq84(accessTokens.id, input2.id)
6663
6807
  )
6664
6808
  ).get();
6665
6809
  if (!token) {
@@ -6669,21 +6813,22 @@ var getProcedure14 = browserManagerProcedure.input(z41.strictObject({ id: z41.uu
6669
6813
  });
6670
6814
 
6671
6815
  // server/tokens/schemas.ts
6672
- import { z as z42 } from "zod";
6673
- var clientScopes = z42.enum([
6816
+ import { z as z44 } from "zod";
6817
+ var clientScopes = z44.enum([
6674
6818
  "catalog:read",
6675
6819
  "code:execute",
6676
6820
  "actions:write",
6677
6821
  "actions:run",
6678
6822
  "actions:test",
6679
6823
  "runs:read",
6680
- "runs:cancel"
6824
+ "runs:cancel",
6825
+ "plugins:configure"
6681
6826
  ]);
6682
- var tokenCreateSchema = z42.object({
6683
- name: z42.string().trim().min(1).max(100),
6684
- scopes: z42.array(clientScopes).min(1),
6685
- projects: z42.array(z42.uuid()).default([]),
6686
- action_versions: z42.array(z42.uuid()).default([])
6827
+ var tokenCreateSchema = z44.object({
6828
+ name: z44.string().trim().min(1).max(100),
6829
+ scopes: z44.array(clientScopes).min(1),
6830
+ projects: z44.array(z44.uuid()).default([]),
6831
+ action_versions: z44.array(z44.uuid()).default([])
6687
6832
  }).strict();
6688
6833
 
6689
6834
  // server/router/tokens/create.ts
@@ -6722,14 +6867,14 @@ var createProcedure10 = browserManagerProcedure.input(tokenCreateSchema).output(
6722
6867
  });
6723
6868
 
6724
6869
  // server/router/tokens/revoke.ts
6725
- import { and as and62, eq as eq82 } from "drizzle-orm";
6726
- import { z as z43 } from "zod";
6727
- var revokeProcedure = browserManagerProcedure.input(z43.strictObject({ id: z43.uuid() })).mutation(({ ctx, input: input2 }) => {
6870
+ import { and as and64, eq as eq85 } from "drizzle-orm";
6871
+ import { z as z45 } from "zod";
6872
+ var revokeProcedure = browserManagerProcedure.input(z45.strictObject({ id: z45.uuid() })).mutation(({ ctx, input: input2 }) => {
6728
6873
  return inTransaction(ctx, (ctx2) => {
6729
6874
  const token = ctx2.db.update(accessTokens).set({ revoked: true, updatedAt: now() }).where(
6730
- and62(
6731
- eq82(accessTokens.workspaceId, ctx2.workspace.id),
6732
- eq82(accessTokens.id, input2.id)
6875
+ and64(
6876
+ eq85(accessTokens.workspaceId, ctx2.workspace.id),
6877
+ eq85(accessTokens.id, input2.id)
6733
6878
  )
6734
6879
  ).returning().get();
6735
6880
  if (!token) {
@@ -6772,20 +6917,20 @@ var usersRouter = router({
6772
6917
  });
6773
6918
 
6774
6919
  // server/router/webhooks/list.ts
6775
- import { eq as eq84 } from "drizzle-orm";
6920
+ import { eq as eq87 } from "drizzle-orm";
6776
6921
 
6777
6922
  // server/automations/webhook-view.ts
6778
- import { desc as desc5, eq as eq83 } from "drizzle-orm";
6779
- import { and as and63 } from "drizzle-orm";
6923
+ import { desc as desc5, eq as eq86 } from "drizzle-orm";
6924
+ import { and as and65 } from "drizzle-orm";
6780
6925
  function webhookView(context, webhook) {
6781
6926
  const version2 = actionVersionsRepository(context).find(
6782
6927
  webhook.actionVersionId
6783
6928
  );
6784
6929
  const action = actionsRepository(context).find(version2.actionId);
6785
6930
  const deliveries = context.db.select().from(webhookDeliveries).where(
6786
- and63(
6787
- eq83(webhookDeliveries.workspaceId, workspace(context)),
6788
- eq83(webhookDeliveries.webhookId, webhook.id)
6931
+ and65(
6932
+ eq86(webhookDeliveries.workspaceId, workspace(context)),
6933
+ eq86(webhookDeliveries.webhookId, webhook.id)
6789
6934
  )
6790
6935
  ).orderBy(desc5(webhookDeliveries.createdAt)).limit(20).all();
6791
6936
  return {
@@ -6814,19 +6959,19 @@ function webhookView(context, webhook) {
6814
6959
 
6815
6960
  // server/router/webhooks/list.ts
6816
6961
  var listProcedure14 = browserWorkspaceProcedure.query(({ ctx }) => {
6817
- const records = ctx.db.select().from(webhooks).where(eq84(webhooks.workspaceId, ctx.workspace.id)).all();
6962
+ const records = ctx.db.select().from(webhooks).where(eq87(webhooks.workspaceId, ctx.workspace.id)).all();
6818
6963
  return page(records.map((record) => webhookView(ctx, record)));
6819
6964
  });
6820
6965
 
6821
6966
  // server/router/webhooks/get.ts
6822
- import { z as z44 } from "zod";
6967
+ import { z as z46 } from "zod";
6823
6968
 
6824
6969
  // server/repositories/webhooks.ts
6825
- import { and as and64, eq as eq85 } from "drizzle-orm";
6970
+ import { and as and66, eq as eq88 } from "drizzle-orm";
6826
6971
  function webhooksRepository(context) {
6827
6972
  const workspaceId = requireWorkspace(context).id;
6828
6973
  const database = context.db;
6829
- const scoped = (id) => and64(eq85(webhooks.workspaceId, workspaceId), eq85(webhooks.id, id));
6974
+ const scoped = (id) => and66(eq88(webhooks.workspaceId, workspaceId), eq88(webhooks.id, id));
6830
6975
  return {
6831
6976
  find(id) {
6832
6977
  const row = database.select().from(webhooks).where(scoped(id)).get();
@@ -6850,22 +6995,22 @@ function webhooksRepository(context) {
6850
6995
  }
6851
6996
 
6852
6997
  // server/router/webhooks/get.ts
6853
- var getProcedure15 = browserWorkspaceProcedure.input(z44.object({ id: z44.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
6998
+ var getProcedure15 = browserWorkspaceProcedure.input(z46.object({ id: z46.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
6854
6999
  const id = input2.id;
6855
7000
  return webhookView(context, webhooksRepository(context).find(id));
6856
7001
  });
6857
7002
 
6858
7003
  // server/automations/webhook-schemas.ts
6859
- import { z as z45 } from "zod";
6860
- var webhookCreateSchema = z45.object({
6861
- name: z45.string().trim().min(1).max(100),
6862
- action: z45.uuid(),
6863
- enabled: z45.boolean().optional()
7004
+ import { z as z47 } from "zod";
7005
+ var webhookCreateSchema = z47.object({
7006
+ name: z47.string().trim().min(1).max(100),
7007
+ action: z47.uuid(),
7008
+ enabled: z47.boolean().optional()
6864
7009
  }).strict();
6865
- var webhookUpdateSchema = z45.object({
6866
- id: z45.uuid(),
6867
- name: z45.string().trim().min(1).max(100).optional(),
6868
- enabled: z45.boolean().optional()
7010
+ var webhookUpdateSchema = z47.object({
7011
+ id: z47.uuid(),
7012
+ name: z47.string().trim().min(1).max(100).optional(),
7013
+ enabled: z47.boolean().optional()
6869
7014
  }).strict();
6870
7015
 
6871
7016
  // server/router/webhooks/create.ts
@@ -6910,8 +7055,8 @@ var updateProcedure9 = browserManagerProcedure.input(webhookUpdateSchema).mutati
6910
7055
  });
6911
7056
 
6912
7057
  // server/router/webhooks/rotate.ts
6913
- import { z as z46 } from "zod";
6914
- var rotateProcedure = browserManagerProcedure.input(z46.object({ id: z46.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
7058
+ import { z as z48 } from "zod";
7059
+ var rotateProcedure = browserManagerProcedure.input(z48.object({ id: z48.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
6915
7060
  const id = input2.id;
6916
7061
  return inTransaction(context, (context2) => {
6917
7062
  const secret = randomSecret();
@@ -6941,7 +7086,7 @@ var listProcedure15 = browserWorkspaceProcedure.query(({ ctx }) => {
6941
7086
  });
6942
7087
 
6943
7088
  // server/router/workspace/current.ts
6944
- import { eq as eq86 } from "drizzle-orm";
7089
+ import { eq as eq89 } from "drizzle-orm";
6945
7090
 
6946
7091
  // server/workspaces/views.ts
6947
7092
  var serializeInvite = (invitation) => ({
@@ -6960,34 +7105,34 @@ var currentProcedure = browserWorkspaceProcedure.query(({ ctx }) => {
6960
7105
  workspace: { id: workspace2.id, name: workspace2.name },
6961
7106
  role: ctx.role,
6962
7107
  members: memberQuery(ctx.db, workspace2.id).all(),
6963
- invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(eq86(invitations.workspaceId, workspace2.id)).all().map(serializeInvite) : []
7108
+ invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(eq89(invitations.workspaceId, workspace2.id)).all().map(serializeInvite) : []
6964
7109
  };
6965
7110
  });
6966
7111
 
6967
7112
  // server/router/workspace/update.ts
6968
- import { eq as eq87 } from "drizzle-orm";
7113
+ import { eq as eq90 } from "drizzle-orm";
6969
7114
 
6970
7115
  // server/workspaces/schemas.ts
6971
- import { z as z47 } from "zod";
6972
- var membershipIdSchema = z47.strictObject({
6973
- id: z47.number().int().positive()
7116
+ import { z as z49 } from "zod";
7117
+ var membershipIdSchema = z49.strictObject({
7118
+ id: z49.number().int().positive()
6974
7119
  });
6975
- var workspaceNameSchema = z47.strictObject({
6976
- name: z47.string().trim().min(1).max(100)
7120
+ var workspaceNameSchema = z49.strictObject({
7121
+ name: z49.string().trim().min(1).max(100)
6977
7122
  });
6978
- var roleSchema = z47.enum(["admin", "member"]);
7123
+ var roleSchema = z49.enum(["admin", "member"]);
6979
7124
  var memberUpdateSchema = membershipIdSchema.extend({
6980
7125
  role: roleSchema
6981
7126
  });
6982
- var ownershipSchema = z47.strictObject({
6983
- membership_id: z47.number().int().positive()
7127
+ var ownershipSchema = z49.strictObject({
7128
+ membership_id: z49.number().int().positive()
6984
7129
  });
6985
- var invitationSchema = z47.strictObject({
7130
+ var invitationSchema = z49.strictObject({
6986
7131
  email: emailSchema,
6987
7132
  role: roleSchema
6988
7133
  });
6989
- var invitationTokenSchema = z47.strictObject({
6990
- token: z47.string().min(1)
7134
+ var invitationTokenSchema = z49.strictObject({
7135
+ token: z49.string().min(1)
6991
7136
  });
6992
7137
 
6993
7138
  // server/router/workspace/update.ts
@@ -7004,7 +7149,7 @@ var updateProcedure10 = browserManagerProcedure.input(workspaceNameSchema).mutat
7004
7149
  "Only workspace owners and admins can manage this workspace."
7005
7150
  );
7006
7151
  }
7007
- const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(eq87(workspaces.id, workspace2.id)).returning().get();
7152
+ const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(eq90(workspaces.id, workspace2.id)).returning().get();
7008
7153
  return { id: updated.id, name: updated.name };
7009
7154
  });
7010
7155
  });
@@ -7032,13 +7177,13 @@ import { randomUUID as randomUUID5 } from "node:crypto";
7032
7177
  import nodemailer from "nodemailer";
7033
7178
 
7034
7179
  // server/repositories/mail-outbox.ts
7035
- import { and as and65, asc as asc6, eq as eq88, isNull, lt as lt3, lte, or as or5 } from "drizzle-orm";
7180
+ import { and as and67, asc as asc6, eq as eq91, isNull, lt as lt3, lte, or as or5 } from "drizzle-orm";
7036
7181
  function enqueueMail(store, message) {
7037
7182
  store.db.insert(mailOutbox).values({ ...message, nextAttempt: Date.now() }).run();
7038
7183
  }
7039
7184
  function revokeUnsentMail(store, id) {
7040
- const unsent = and65(
7041
- eq88(mailOutbox.id, id),
7185
+ const unsent = and67(
7186
+ eq91(mailOutbox.id, id),
7042
7187
  isNull(mailOutbox.sentAt),
7043
7188
  isNull(mailOutbox.leaseUntil)
7044
7189
  );
@@ -7050,7 +7195,7 @@ function claimMail(store, time) {
7050
7195
  isNull(mailOutbox.leaseUntil),
7051
7196
  lt3(mailOutbox.leaseUntil, time)
7052
7197
  );
7053
- const due = and65(
7198
+ const due = and67(
7054
7199
  isNull(mailOutbox.sentAt),
7055
7200
  lte(mailOutbox.nextAttempt, time),
7056
7201
  availableLease
@@ -7061,18 +7206,18 @@ function claimMail(store, time) {
7061
7206
  }
7062
7207
  if (row.id.startsWith("invitation:")) {
7063
7208
  const id = Number(row.id.slice("invitation:".length));
7064
- const invitation = store2.db.select().from(invitations).where(eq88(invitations.id, id)).get();
7209
+ const invitation = store2.db.select().from(invitations).where(eq91(invitations.id, id)).get();
7065
7210
  if (!invitation || invitation.acceptedAt || invitation.revokedAt || invitation.expiresAt <= new Date(time).toISOString()) {
7066
- store2.db.delete(mailOutbox).where(eq88(mailOutbox.id, row.id)).run();
7211
+ store2.db.delete(mailOutbox).where(eq91(mailOutbox.id, row.id)).run();
7067
7212
  return;
7068
7213
  }
7069
7214
  }
7070
- store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(eq88(mailOutbox.id, row.id)).run();
7215
+ store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(eq91(mailOutbox.id, row.id)).run();
7071
7216
  return row;
7072
7217
  });
7073
7218
  }
7074
7219
  function markMailSent(store, id) {
7075
- store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(eq88(mailOutbox.id, id)).run();
7220
+ store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(eq91(mailOutbox.id, id)).run();
7076
7221
  }
7077
7222
  function retryMail(store, job) {
7078
7223
  const attempts = job.attempts + 1;
@@ -7082,7 +7227,7 @@ function retryMail(store, job) {
7082
7227
  nextAttempt: Date.now() + delay,
7083
7228
  leaseUntil: null,
7084
7229
  lastError: "Delivery failed"
7085
- }).where(eq88(mailOutbox.id, job.id)).run();
7230
+ }).where(eq91(mailOutbox.id, job.id)).run();
7086
7231
  }
7087
7232
 
7088
7233
  // server/mail/outbox.ts
@@ -7136,7 +7281,7 @@ async function flushOutbox(store, send) {
7136
7281
  }
7137
7282
 
7138
7283
  // server/router/workspace/invite.ts
7139
- import { and as and66, eq as eq89, isNull as isNull2, sql as sql3 } from "drizzle-orm";
7284
+ import { and as and68, eq as eq92, isNull as isNull2, sql as sql3 } from "drizzle-orm";
7140
7285
  var inviteProcedure = browserManagerProcedure.input(invitationSchema).mutation(({ ctx, input: input2 }) => {
7141
7286
  const user = ctx.user;
7142
7287
  const workspace2 = ctx.workspace;
@@ -7174,9 +7319,9 @@ This invitation expires in seven days.`
7174
7319
  "Only the owner can invite admins."
7175
7320
  );
7176
7321
  }
7177
- const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users, eq89(users.id, memberships.userId)).where(
7178
- and66(
7179
- eq89(memberships.workspaceId, workspace2.id),
7322
+ const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users, eq92(users.id, memberships.userId)).where(
7323
+ and68(
7324
+ eq92(memberships.workspaceId, workspace2.id),
7180
7325
  sql3`lower(${users.email}) = ${email}`
7181
7326
  )
7182
7327
  ).get();
@@ -7187,8 +7332,8 @@ This invitation expires in seven days.`
7187
7332
  );
7188
7333
  }
7189
7334
  const prior = db.select({ id: invitations.id, expiresAt: invitations.expiresAt }).from(invitations).where(
7190
- and66(
7191
- eq89(invitations.workspaceId, workspace2.id),
7335
+ and68(
7336
+ eq92(invitations.workspaceId, workspace2.id),
7192
7337
  sql3`lower(${invitations.email}) = ${email}`,
7193
7338
  isNull2(invitations.acceptedAt),
7194
7339
  isNull2(invitations.revokedAt)
@@ -7223,7 +7368,7 @@ This invitation expires in seven days.`
7223
7368
  });
7224
7369
 
7225
7370
  // server/router/workspace/revoke-invitation.ts
7226
- import { and as and67, eq as eq90 } from "drizzle-orm";
7371
+ import { and as and69, eq as eq93 } from "drizzle-orm";
7227
7372
  var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
7228
7373
  const id = input2.id;
7229
7374
  const user = ctx.user;
@@ -7238,9 +7383,9 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
7238
7383
  );
7239
7384
  }
7240
7385
  const invitation = ctx2.db.select().from(invitations).where(
7241
- and67(
7242
- eq90(invitations.workspaceId, workspace2.id),
7243
- eq90(invitations.id, id)
7386
+ and69(
7387
+ eq93(invitations.workspaceId, workspace2.id),
7388
+ eq93(invitations.id, id)
7244
7389
  )
7245
7390
  ).get();
7246
7391
  if (!invitation) {
@@ -7261,7 +7406,7 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
7261
7406
  });
7262
7407
 
7263
7408
  // server/router/workspace/accept-invitation.ts
7264
- import { and as and68, eq as eq91 } from "drizzle-orm";
7409
+ import { and as and70, eq as eq94 } from "drizzle-orm";
7265
7410
  var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTokenSchema).mutation(({ ctx, input: input2 }) => {
7266
7411
  const token = input2.token;
7267
7412
  const user = ctx.user;
@@ -7273,9 +7418,9 @@ var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTo
7273
7418
  throw new ServiceError("NOT_FOUND", "Invitation not found.");
7274
7419
  }
7275
7420
  const invite = db.select().from(invitations).where(
7276
- and68(
7277
- eq91(invitations.workspaceId, workspace2.id),
7278
- eq91(invitations.tokenDigest, digest(token))
7421
+ and70(
7422
+ eq94(invitations.workspaceId, workspace2.id),
7423
+ eq94(invitations.tokenDigest, digest(token))
7279
7424
  )
7280
7425
  ).get();
7281
7426
  if (!invite) {
@@ -7356,7 +7501,7 @@ var updateMemberProcedure = browserOwnerProcedure.input(memberUpdateSchema).muta
7356
7501
  });
7357
7502
 
7358
7503
  // server/router/workspace/remove-member.ts
7359
- import { and as and69, eq as eq92 } from "drizzle-orm";
7504
+ import { and as and71, eq as eq95 } from "drizzle-orm";
7360
7505
  var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
7361
7506
  const id = input2.id;
7362
7507
  inTransaction(ctx, (ctx2) => {
@@ -7369,9 +7514,9 @@ var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).
7369
7514
  );
7370
7515
  }
7371
7516
  ctx2.db.delete(memberships).where(
7372
- and69(
7373
- eq92(memberships.workspaceId, target.workspaceId),
7374
- eq92(memberships.id, id)
7517
+ and71(
7518
+ eq95(memberships.workspaceId, target.workspaceId),
7519
+ eq95(memberships.id, id)
7375
7520
  )
7376
7521
  ).run();
7377
7522
  });
@@ -7442,8 +7587,8 @@ var appRouter = router({
7442
7587
  // server/api/mcp-dispatch.ts
7443
7588
  async function dispatchTool(context, name, toolInput) {
7444
7589
  const caller = appRouter.createCaller(context);
7445
- const id = () => z48.string().parse(toolInput.id);
7446
- const actionId = () => z48.string().parse(toolInput.action);
7590
+ const id = () => z50.string().parse(toolInput.id);
7591
+ const actionId = () => z50.string().parse(toolInput.action);
7447
7592
  const queueSession = (session) => caller.runs.session(
7448
7593
  sessionRunSchema.parse({
7449
7594
  project: toolInput.project,
@@ -7464,7 +7609,7 @@ async function dispatchTool(context, name, toolInput) {
7464
7609
  };
7465
7610
  }
7466
7611
  case "get_project_sdk":
7467
- return caller.projects.sdk({ id: z48.string().parse(toolInput.project) });
7612
+ return caller.projects.sdk({ id: z50.string().parse(toolInput.project) });
7468
7613
  case "execute_code":
7469
7614
  return caller.runs.create(
7470
7615
  createRunSchema.strip().parse({ ...toolInput, operation: "code" })
@@ -7474,23 +7619,23 @@ async function dispatchTool(context, name, toolInput) {
7474
7619
  case "execute_cell":
7475
7620
  return queueSession({
7476
7621
  operation: "execute",
7477
- id: z48.uuid().parse(toolInput.session_id),
7478
- cellId: z48.uuid().parse(toolInput.cell_id),
7479
- generation: z48.number().parse(toolInput.generation),
7480
- expectedSequence: z48.number().parse(toolInput.expected_sequence),
7622
+ id: z50.uuid().parse(toolInput.session_id),
7623
+ cellId: z50.uuid().parse(toolInput.cell_id),
7624
+ generation: z50.number().parse(toolInput.generation),
7625
+ expectedSequence: z50.number().parse(toolInput.expected_sequence),
7481
7626
  after: toolInput.after
7482
7627
  });
7483
7628
  case "read_session":
7484
7629
  return queueSession({
7485
7630
  operation: "read",
7486
- id: z48.uuid().parse(toolInput.session_id),
7631
+ id: z50.uuid().parse(toolInput.session_id),
7487
7632
  after: toolInput.after,
7488
7633
  limit: toolInput.limit
7489
7634
  });
7490
7635
  case "close_session":
7491
7636
  return queueSession({
7492
7637
  operation: "close",
7493
- id: z48.uuid().parse(toolInput.session_id)
7638
+ id: z50.uuid().parse(toolInput.session_id)
7494
7639
  });
7495
7640
  case "get_run_events": {
7496
7641
  const all = await caller.runs.events({ id: id() });
@@ -7552,6 +7697,12 @@ async function dispatchTool(context, name, toolInput) {
7552
7697
  return (await caller.approvals.list()).results.filter(
7553
7698
  (entry) => entry.status === "pending"
7554
7699
  );
7700
+ case "list_project_plugins":
7701
+ return caller.plugins.settings({
7702
+ project: z50.uuid().parse(toolInput.project)
7703
+ });
7704
+ case "configure_plugin":
7705
+ return caller.plugins.configure(configurePluginSchema.parse(toolInput));
7555
7706
  case "list_plugins":
7556
7707
  return (await caller.plugins.list()).results.map((entry) => ({
7557
7708
  slug: entry.slug,
@@ -7567,20 +7718,21 @@ async function dispatchTool(context, name, toolInput) {
7567
7718
  }
7568
7719
 
7569
7720
  // server/api/mcp-schemas.ts
7570
- import { z as z49 } from "zod";
7571
- var mcpArgumentsSchema = z49.object({
7572
- action: z49.string().optional(),
7573
- project: z49.string().optional(),
7574
- id: z49.string().optional(),
7575
- version: z49.number().optional(),
7576
- suite_revision: z49.number().optional(),
7577
- after: z49.number().optional(),
7578
- offset: z49.number().optional(),
7579
- limit: z49.number().optional()
7580
- }).catchall(z49.json());
7721
+ import { z as z51 } from "zod";
7722
+ var mcpArgumentsSchema = z51.object({
7723
+ action: z51.string().optional(),
7724
+ project: z51.string().optional(),
7725
+ id: z51.string().optional(),
7726
+ version: z51.number().optional(),
7727
+ suite_revision: z51.number().optional(),
7728
+ after: z51.number().optional(),
7729
+ offset: z51.number().optional(),
7730
+ limit: z51.number().optional()
7731
+ }).catchall(z51.json());
7581
7732
 
7582
7733
  // server/api/mcp.ts
7583
7734
  import Ajv2 from "ajv";
7735
+ import { ZodError as ZodError2 } from "zod";
7584
7736
  import { TRPCError as TRPCError2 } from "@trpc/server";
7585
7737
 
7586
7738
  // server/api/mcp-tools.json
@@ -8162,6 +8314,71 @@ var mcp_tools_default = [
8162
8314
  },
8163
8315
  mutates: false
8164
8316
  },
8317
+ {
8318
+ name: "list_project_plugins",
8319
+ description: "List configurable installed package plugins for a granted project. Returns the current configuration, schema, credential status and revision needed to configure a plugin. Credential values are private.",
8320
+ inputSchema: {
8321
+ type: "object",
8322
+ properties: {
8323
+ project: {
8324
+ type: "string",
8325
+ format: "uuid"
8326
+ }
8327
+ },
8328
+ required: ["project"],
8329
+ additionalProperties: false
8330
+ },
8331
+ mutates: false
8332
+ },
8333
+ {
8334
+ name: "configure_plugin",
8335
+ description: "Replace an installed package plugin's configuration, attach a new API credential, or disconnect the credential. Use the ID and revision from list_project_plugins. Supply a replacement credential or null when changing configuration with a credential already attached. Omitted fields stay as saved.",
8336
+ inputSchema: {
8337
+ type: "object",
8338
+ properties: {
8339
+ id: {
8340
+ type: "string",
8341
+ format: "uuid"
8342
+ },
8343
+ revision: {
8344
+ type: "string",
8345
+ pattern: "^[a-f0-9]{64}$"
8346
+ },
8347
+ configuration: {
8348
+ type: "object",
8349
+ description: "Complete plugin configuration. Put secret values in credential.secret."
8350
+ },
8351
+ credential: {
8352
+ type: ["object", "null"],
8353
+ description: "New API credential, or null to disconnect.",
8354
+ properties: {
8355
+ name: {
8356
+ type: "string",
8357
+ minLength: 1,
8358
+ maxLength: 100
8359
+ },
8360
+ secret: {
8361
+ type: "object",
8362
+ minProperties: 1
8363
+ }
8364
+ },
8365
+ required: ["name", "secret"],
8366
+ additionalProperties: false
8367
+ }
8368
+ },
8369
+ required: ["id", "revision"],
8370
+ anyOf: [
8371
+ {
8372
+ required: ["configuration"]
8373
+ },
8374
+ {
8375
+ required: ["credential"]
8376
+ }
8377
+ ],
8378
+ additionalProperties: false
8379
+ },
8380
+ mutates: true
8381
+ },
8165
8382
  {
8166
8383
  name: "list_plugins",
8167
8384
  description: "Read installed plugin capability metadata.",
@@ -8188,6 +8405,8 @@ var mcp_tools_default = [
8188
8405
 
8189
8406
  // server/api/mcp.ts
8190
8407
  var scopes = {
8408
+ list_project_plugins: "plugins:configure",
8409
+ configure_plugin: "plugins:configure",
8191
8410
  list_projects: "catalog:read",
8192
8411
  get_project_sdk: "catalog:read",
8193
8412
  execute_code: "code:execute",
@@ -8303,6 +8522,12 @@ async function handleMcp(ctx) {
8303
8522
  isError: false
8304
8523
  };
8305
8524
  } catch (cause) {
8525
+ if (cause instanceof ZodError2) {
8526
+ return error(
8527
+ -32602,
8528
+ "Invalid tool arguments. Check fields, types and limits."
8529
+ );
8530
+ }
8306
8531
  if (!(cause instanceof HttpError) && !(cause instanceof TRPCError2)) {
8307
8532
  throw cause;
8308
8533
  }
@@ -8310,12 +8535,12 @@ async function handleMcp(ctx) {
8310
8535
  content: [
8311
8536
  {
8312
8537
  type: "text",
8313
- text: (cause instanceof HttpError ? cause.status === 403 : cause.code === "FORBIDDEN") ? "Permission denied. Check client scopes and project grants." : cause instanceof TRPCError2 && cause.code === "PRECONDITION_FAILED" && [
8538
+ text: (cause instanceof HttpError ? cause.status === 403 : cause.code === "FORBIDDEN") ? "Permission denied. Check client scopes and project grants." : cause instanceof TRPCError2 && (cause.code === "PRECONDITION_FAILED" && [
8314
8539
  "open_session",
8315
8540
  "execute_cell",
8316
8541
  "read_session",
8317
8542
  "close_session"
8318
- ].includes(tool.name) ? cause.message : "Request rejected. Check resource IDs, input fields and execution limits."
8543
+ ].includes(tool.name) || tool.name === "configure_plugin" && ["BAD_REQUEST", "CONFLICT"].includes(cause.code)) ? cause.message : "Request rejected. Check resource IDs, input fields and execution limits."
8319
8544
  }
8320
8545
  ],
8321
8546
  isError: true
@@ -8328,18 +8553,18 @@ async function handleMcp(ctx) {
8328
8553
  }
8329
8554
 
8330
8555
  // server/automations/ingress.ts
8331
- import { z as z50 } from "zod";
8332
- import { and as and71, eq as eq94 } from "drizzle-orm";
8556
+ import { z as z52 } from "zod";
8557
+ import { and as and73, eq as eq97 } from "drizzle-orm";
8333
8558
  import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
8334
8559
 
8335
8560
  // server/repositories/webhook-deliveries.ts
8336
- import { and as and70, eq as eq93 } from "drizzle-orm";
8561
+ import { and as and72, eq as eq96 } from "drizzle-orm";
8337
8562
  function webhookDeliveriesRepository(context) {
8338
8563
  const workspaceId = requireWorkspace(context).id;
8339
8564
  const database = context.db;
8340
- const scoped = (id, filter) => and70(
8341
- eq93(webhookDeliveries.workspaceId, workspaceId),
8342
- id === void 0 ? void 0 : eq93(webhookDeliveries.id, id),
8565
+ const scoped = (id, filter) => and72(
8566
+ eq96(webhookDeliveries.workspaceId, workspaceId),
8567
+ id === void 0 ? void 0 : eq96(webhookDeliveries.id, id),
8343
8568
  filter
8344
8569
  );
8345
8570
  return {
@@ -8367,7 +8592,7 @@ async function handleWebhookIngress(ctx) {
8367
8592
  if (ctx.request.method !== "POST") {
8368
8593
  throw new HttpError(405, "Method not allowed.");
8369
8594
  }
8370
- const hook = ctx.db.select().from(webhooks).where(eq94(webhooks.id, match[1])).get();
8595
+ const hook = ctx.db.select().from(webhooks).where(eq97(webhooks.id, match[1])).get();
8371
8596
  if (!hook || !ctx.workspace || hook.workspaceId !== ctx.workspace.id) {
8372
8597
  throw new HttpError(404, "Webhook not found.");
8373
8598
  }
@@ -8402,9 +8627,9 @@ async function handleWebhookIngress(ctx) {
8402
8627
  jsonValue(payload.inputs, "Inputs");
8403
8628
  const actor = identityRepository(ctx.db).user(hook.actorId);
8404
8629
  const member = ctx.db.select().from(memberships).where(
8405
- and71(
8406
- eq94(memberships.userId, hook.actorId),
8407
- eq94(memberships.workspaceId, hook.workspaceId)
8630
+ and73(
8631
+ eq97(memberships.userId, hook.actorId),
8632
+ eq97(memberships.workspaceId, hook.workspaceId)
8408
8633
  )
8409
8634
  ).get();
8410
8635
  if (!hook.enabled || !actor || !member) {
@@ -8425,9 +8650,9 @@ async function handleWebhookIngress(ctx) {
8425
8650
  throw new HttpError(403, "Webhook is unavailable.");
8426
8651
  }
8427
8652
  const old = webhookDeliveriesRepository(actorCtx2).list(
8428
- and71(
8429
- eq94(webhookDeliveries.webhookId, hook.id),
8430
- eq94(webhookDeliveries.deliveryId, delivery)
8653
+ and73(
8654
+ eq97(webhookDeliveries.webhookId, hook.id),
8655
+ eq97(webhookDeliveries.deliveryId, delivery)
8431
8656
  )
8432
8657
  )[0];
8433
8658
  if (old) {
@@ -8447,7 +8672,7 @@ async function handleWebhookIngress(ctx) {
8447
8672
  operation: "action",
8448
8673
  action: action.id,
8449
8674
  version: version2.number,
8450
- inputs: z50.record(z50.string(), z50.json()).parse(payload.inputs),
8675
+ inputs: z52.record(z52.string(), z52.json()).parse(payload.inputs),
8451
8676
  idempotency_key: `webhook:${hook.id}:${delivery}`
8452
8677
  });
8453
8678
  runsRepository(actorCtx2).update(run.id, {
@@ -8470,7 +8695,7 @@ async function handleWebhookIngress(ctx) {
8470
8695
  }
8471
8696
 
8472
8697
  // server/execution/authority.ts
8473
- import { and as and72, eq as eq95 } from "drizzle-orm";
8698
+ import { and as and74, eq as eq98 } from "drizzle-orm";
8474
8699
  import { timingSafeEqual as timingSafeEqual3 } from "node:crypto";
8475
8700
  var terminal = /* @__PURE__ */ new Set([
8476
8701
  "succeeded",
@@ -8488,15 +8713,15 @@ function bearer(ctx) {
8488
8713
  }
8489
8714
  function executor(ctx) {
8490
8715
  const row = ctx.db.select().from(executors).where(
8491
- and72(
8492
- eq95(executors.tokenHash, digest(bearer(ctx))),
8493
- eq95(executors.enabled, true)
8716
+ and74(
8717
+ eq98(executors.tokenHash, digest(bearer(ctx))),
8718
+ eq98(executors.enabled, true)
8494
8719
  )
8495
8720
  ).get();
8496
8721
  const project = row && ctx.db.select().from(projects).where(
8497
- and72(
8498
- eq95(projects.id, row.projectId),
8499
- eq95(projects.workspaceId, row.workspaceId)
8722
+ and74(
8723
+ eq98(projects.id, row.projectId),
8724
+ eq98(projects.workspaceId, row.workspaceId)
8500
8725
  )
8501
8726
  ).get();
8502
8727
  if (!row || !project?.enabled) {
@@ -8505,17 +8730,17 @@ function executor(ctx) {
8505
8730
  return row;
8506
8731
  }
8507
8732
  function runCapability(ctx, expectedId) {
8508
- const run = ctx.db.select().from(runs).where(eq95(runs.capabilityHash, digest(bearer(ctx)))).get();
8733
+ const run = ctx.db.select().from(runs).where(eq98(runs.capabilityHash, digest(bearer(ctx)))).get();
8509
8734
  const currentTime = now();
8510
8735
  if (!run || expectedId && run.id !== expectedId || !run.deadline || run.deadline <= currentTime || !run.leaseExpiresAt || run.leaseExpiresAt <= currentTime) {
8511
8736
  throw new HttpError(401, "Invalid or expired run capability.");
8512
8737
  }
8513
- const worker = run.executorId && ctx.db.select().from(executors).where(eq95(executors.id, run.executorId)).get();
8514
- const project = ctx.db.select().from(projects).where(eq95(projects.id, run.projectId)).get();
8738
+ const worker = run.executorId && ctx.db.select().from(executors).where(eq98(executors.id, run.executorId)).get();
8739
+ const project = ctx.db.select().from(projects).where(eq98(projects.id, run.projectId)).get();
8515
8740
  const member = ctx.db.select().from(memberships).where(
8516
- and72(
8517
- eq95(memberships.workspaceId, run.workspaceId),
8518
- eq95(memberships.userId, run.actorId)
8741
+ and74(
8742
+ eq98(memberships.workspaceId, run.workspaceId),
8743
+ eq98(memberships.userId, run.actorId)
8519
8744
  )
8520
8745
  ).get();
8521
8746
  if (!worker || !worker.enabled || worker.projectId !== run.projectId || !project?.enabled || !member) {
@@ -8535,9 +8760,9 @@ function runCapability(ctx, expectedId) {
8535
8760
  if (!terminal.has(run.status) && !run.cancelRequested) {
8536
8761
  const operation = object(command2) ? command2.operation : void 0;
8537
8762
  const token = run.tokenId ? ctx.db.select().from(accessTokens).where(
8538
- and72(
8539
- eq95(accessTokens.workspaceId, run.workspaceId),
8540
- eq95(accessTokens.id, run.tokenId)
8763
+ and74(
8764
+ eq98(accessTokens.workspaceId, run.workspaceId),
8765
+ eq98(accessTokens.id, run.tokenId)
8541
8766
  )
8542
8767
  ).get() : void 0;
8543
8768
  const tokenRevoked = run.tokenId && (!token || token.revoked || !token.projects.includes(run.projectId) || !token.scopes.includes("code:execute") || operation === "read" && !token.scopes.includes("runs:read"));
@@ -8578,11 +8803,11 @@ function live(run) {
8578
8803
  }
8579
8804
  function actorContext(ctx, run) {
8580
8805
  const user = identityRepository(ctx.db).user(run.actorId) ?? null;
8581
- const workspace2 = ctx.db.select().from(workspaces).where(eq95(workspaces.id, run.workspaceId)).get() ?? null;
8806
+ const workspace2 = ctx.db.select().from(workspaces).where(eq98(workspaces.id, run.workspaceId)).get() ?? null;
8582
8807
  const membership = ctx.db.select().from(memberships).where(
8583
- and72(
8584
- eq95(memberships.workspaceId, run.workspaceId),
8585
- eq95(memberships.userId, run.actorId)
8808
+ and74(
8809
+ eq98(memberships.workspaceId, run.workspaceId),
8810
+ eq98(memberships.userId, run.actorId)
8586
8811
  )
8587
8812
  ).get();
8588
8813
  if (!user || !workspace2 || !membership) {
@@ -8599,7 +8824,7 @@ function actorContext(ctx, run) {
8599
8824
  }
8600
8825
 
8601
8826
  // server/execution/bootstrap.ts
8602
- import { eq as eq96 } from "drizzle-orm";
8827
+ import { eq as eq99 } from "drizzle-orm";
8603
8828
  import { createHmac as createHmac3, randomUUID as randomUUID6 } from "node:crypto";
8604
8829
  function bootstrap(ctx) {
8605
8830
  const configured = process.env.LOCAL_EXECUTOR_BOOTSTRAP_TOKEN;
@@ -8607,8 +8832,8 @@ function bootstrap(ctx) {
8607
8832
  throw new HttpError(403, "Invalid local bootstrap credential.");
8608
8833
  }
8609
8834
  const registrations = [];
8610
- for (const project of ctx.db.select().from(projects).where(eq96(projects.enabled, true)).all()) {
8611
- let worker = ctx.db.select().from(executors).where(eq96(executors.projectId, project.id)).get();
8835
+ for (const project of ctx.db.select().from(projects).where(eq99(projects.enabled, true)).all()) {
8836
+ let worker = ctx.db.select().from(executors).where(eq99(executors.projectId, project.id)).get();
8612
8837
  if (worker && (!worker.locallyManaged || !worker.enabled)) {
8613
8838
  continue;
8614
8839
  }
@@ -8628,7 +8853,7 @@ function bootstrap(ctx) {
8628
8853
  }).returning().get();
8629
8854
  }
8630
8855
  const token = createHmac3("sha256", configured).update(`${worker.id}:${worker.registrationNonce}`).digest("hex");
8631
- ctx.db.update(executors).set({ tokenHash: digest(token) }).where(eq96(executors.id, worker.id)).run();
8856
+ ctx.db.update(executors).set({ tokenHash: digest(token) }).where(eq99(executors.id, worker.id)).run();
8632
8857
  registrations.push({
8633
8858
  agent_id: project.id,
8634
8859
  executor_id: worker.id,
@@ -8640,21 +8865,21 @@ function bootstrap(ctx) {
8640
8865
  }
8641
8866
 
8642
8867
  // server/execution/claim.ts
8643
- import { and as and73, asc as asc7, eq as eq97, inArray as inArray10 } from "drizzle-orm";
8868
+ import { and as and75, asc as asc7, eq as eq100, inArray as inArray10 } from "drizzle-orm";
8644
8869
  function claim(ctx, worker) {
8645
8870
  ctx.db.update(executors).set({ lastSeenAt: now() }).where(
8646
- and73(
8647
- eq97(executors.id, worker.id),
8648
- eq97(executors.workspaceId, worker.workspaceId)
8871
+ and75(
8872
+ eq100(executors.id, worker.id),
8873
+ eq100(executors.workspaceId, worker.workspaceId)
8649
8874
  )
8650
8875
  ).run();
8651
- const setting = ctx.db.select().from(workspaceSettings).where(eq97(workspaceSettings.workspaceId, worker.workspaceId)).get();
8876
+ const setting = ctx.db.select().from(workspaceSettings).where(eq100(workspaceSettings.workspaceId, worker.workspaceId)).get();
8652
8877
  if (setting && (!setting.enabled || setting.executionPool !== worker.pool)) {
8653
8878
  return new Response(null, { status: 204 });
8654
8879
  }
8655
8880
  const active = ctx.db.select().from(runs).where(
8656
- and73(
8657
- eq97(runs.workspaceId, worker.workspaceId),
8881
+ and75(
8882
+ eq100(runs.workspaceId, worker.workspaceId),
8658
8883
  inArray10(runs.status, ["running", "waiting_approval"])
8659
8884
  )
8660
8885
  ).all();
@@ -8662,10 +8887,10 @@ function claim(ctx, worker) {
8662
8887
  return new Response(null, { status: 204 });
8663
8888
  }
8664
8889
  const candidates = ctx.db.select().from(runs).where(
8665
- and73(
8666
- eq97(runs.projectId, worker.projectId),
8667
- eq97(runs.workspaceId, worker.workspaceId),
8668
- eq97(runs.status, "queued")
8890
+ and75(
8891
+ eq100(runs.projectId, worker.projectId),
8892
+ eq100(runs.workspaceId, worker.workspaceId),
8893
+ eq100(runs.status, "queued")
8669
8894
  )
8670
8895
  ).orderBy(asc7(runs.createdAt)).all();
8671
8896
  for (const run of candidates) {
@@ -8677,18 +8902,18 @@ function claim(ctx, worker) {
8677
8902
  continue;
8678
8903
  }
8679
8904
  const member = ctx.db.select().from(memberships).where(
8680
- and73(
8681
- eq97(memberships.userId, run.actorId),
8682
- eq97(memberships.workspaceId, run.workspaceId)
8905
+ and75(
8906
+ eq100(memberships.userId, run.actorId),
8907
+ eq100(memberships.workspaceId, run.workspaceId)
8683
8908
  )
8684
8909
  ).get();
8685
- const token = run.tokenId ? ctx.db.select().from(accessTokens).where(eq97(accessTokens.id, run.tokenId)).get() : null;
8910
+ const token = run.tokenId ? ctx.db.select().from(accessTokens).where(eq100(accessTokens.id, run.tokenId)).get() : null;
8686
8911
  if (!member || run.cancelRequested || run.tokenId && (!token || token.revoked)) {
8687
8912
  ctx.db.update(runs).set({
8688
8913
  status: "cancelled",
8689
8914
  cancelRequested: true,
8690
8915
  updatedAt: now()
8691
- }).where(eq97(runs.id, run.id)).run();
8916
+ }).where(eq100(runs.id, run.id)).run();
8692
8917
  continue;
8693
8918
  }
8694
8919
  const capability = randomSecret();
@@ -8700,7 +8925,7 @@ function claim(ctx, worker) {
8700
8925
  deadline,
8701
8926
  leaseExpiresAt: new Date(Date.now() + 6e4).toISOString(),
8702
8927
  updatedAt: now()
8703
- }).where(eq97(runs.id, run.id)).run();
8928
+ }).where(eq100(runs.id, run.id)).run();
8704
8929
  return json({
8705
8930
  protocol_version: protocol,
8706
8931
  run_id: run.id,
@@ -8718,13 +8943,13 @@ function claim(ctx, worker) {
8718
8943
  }
8719
8944
 
8720
8945
  // server/execution/configuration.ts
8721
- import { and as and74, eq as eq98 } from "drizzle-orm";
8946
+ import { and as and76, eq as eq101 } from "drizzle-orm";
8722
8947
  function pluginsFor(ctx, worker) {
8723
8948
  return ctx.db.select().from(plugins).where(
8724
- and74(
8725
- eq98(plugins.workspaceId, worker.workspaceId),
8726
- eq98(plugins.projectId, worker.projectId),
8727
- eq98(plugins.enabled, true)
8949
+ and76(
8950
+ eq101(plugins.workspaceId, worker.workspaceId),
8951
+ eq101(plugins.projectId, worker.projectId),
8952
+ eq101(plugins.enabled, true)
8728
8953
  )
8729
8954
  ).all().filter(
8730
8955
  (plugin) => plugin.distribution !== "mcp" || worker.protocolVersion >= 4
@@ -8752,11 +8977,11 @@ function configuration(ctx, worker) {
8752
8977
  }
8753
8978
 
8754
8979
  // server/execution/credentials.ts
8755
- import { and as and77, eq as eq101 } from "drizzle-orm";
8980
+ import { and as and79, eq as eq104 } from "drizzle-orm";
8756
8981
 
8757
8982
  // server/mcp/oauth-refresh.ts
8758
8983
  import { auth as auth3 } from "@modelcontextprotocol/client";
8759
- import { and as and75, eq as eq99 } from "drizzle-orm";
8984
+ import { and as and77, eq as eq102 } from "drizzle-orm";
8760
8985
  var refreshes = /* @__PURE__ */ new WeakMap();
8761
8986
  async function mcpExecutionSecret(ctx, credential) {
8762
8987
  let pending = refreshes.get(ctx.db);
@@ -8778,9 +9003,9 @@ async function mcpExecutionSecret(ctx, credential) {
8778
9003
  }
8779
9004
  async function refresh(ctx, initial) {
8780
9005
  const credential = ctx.db.select().from(credentials).where(
8781
- and75(
8782
- eq99(credentials.id, initial.id),
8783
- eq99(credentials.workspaceId, initial.workspaceId)
9006
+ and77(
9007
+ eq102(credentials.id, initial.id),
9008
+ eq102(credentials.workspaceId, initial.workspaceId)
8784
9009
  )
8785
9010
  ).get();
8786
9011
  if (!credential) {
@@ -8811,9 +9036,9 @@ async function refresh(ctx, initial) {
8811
9036
  encryptedSecret: encrypt(ctx, JSON.stringify(state)),
8812
9037
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
8813
9038
  }).where(
8814
- and75(
8815
- eq99(credentials.id, credential.id),
8816
- eq99(credentials.encryptedSecret, credential.encryptedSecret)
9039
+ and77(
9040
+ eq102(credentials.id, credential.id),
9041
+ eq102(credentials.encryptedSecret, credential.encryptedSecret)
8817
9042
  )
8818
9043
  ).returning().get();
8819
9044
  if (!updated) {
@@ -8837,11 +9062,11 @@ async function refresh(ctx, initial) {
8837
9062
  }
8838
9063
 
8839
9064
  // server/oauth/refresh.ts
8840
- import { z as z52 } from "zod";
8841
- import { and as and76, eq as eq100 } from "drizzle-orm";
9065
+ import { z as z54 } from "zod";
9066
+ import { and as and78, eq as eq103 } from "drizzle-orm";
8842
9067
 
8843
9068
  // server/oauth/tokens.ts
8844
- import { z as z51 } from "zod";
9069
+ import { z as z53 } from "zod";
8845
9070
  async function tokenExchange(providerName, clientId, clientSecret, params, fetcher) {
8846
9071
  const fields = new URLSearchParams({ ...params, client_id: clientId });
8847
9072
  const headers = new Headers({
@@ -8882,7 +9107,7 @@ async function tokenExchange(providerName, clientId, clientSecret, params, fetch
8882
9107
  }
8883
9108
  chunks.push(item.value);
8884
9109
  }
8885
- const value = z51.record(z51.string(), z51.unknown()).parse(JSON.parse(Buffer.concat(chunks).toString("utf8")));
9110
+ const value = z53.record(z53.string(), z53.unknown()).parse(JSON.parse(Buffer.concat(chunks).toString("utf8")));
8886
9111
  if (typeof value.access_token !== "string" || !value.access_token || value.access_token.length > 32e3 || value.refresh_token !== void 0 && (typeof value.refresh_token !== "string" || value.refresh_token.length > 32e3) || value.scope !== void 0 && (typeof value.scope !== "string" || value.scope.length > 1e4)) {
8887
9112
  throw new Error();
8888
9113
  }
@@ -8930,9 +9155,9 @@ function recordSecretVersion(secret, credential) {
8930
9155
  function assertExecutionSecretCurrent(store, credential, secret) {
8931
9156
  const version2 = secretVersions.get(secret);
8932
9157
  const current = store.db.select().from(credentials).where(
8933
- and76(
8934
- eq100(credentials.id, credential.id),
8935
- eq100(credentials.workspaceId, credential.workspaceId)
9158
+ and78(
9159
+ eq103(credentials.id, credential.id),
9160
+ eq103(credentials.workspaceId, credential.workspaceId)
8936
9161
  )
8937
9162
  ).get();
8938
9163
  if (!version2 || !current || version2.id !== current.id || version2.workspaceId !== current.workspaceId || version2.provider !== current.provider || version2.encryptedSecret !== current.encryptedSecret) {
@@ -8948,7 +9173,7 @@ async function executionSecret(store, credential, fetcher = fetch) {
8948
9173
  }
8949
9174
  if (!provider(credential.provider)) {
8950
9175
  return recordSecretVersion(
8951
- z52.record(z52.string(), z52.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret))),
9176
+ z54.record(z54.string(), z54.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret))),
8952
9177
  credential
8953
9178
  );
8954
9179
  }
@@ -8974,15 +9199,15 @@ async function executionSecret(store, credential, fetcher = fetch) {
8974
9199
  }
8975
9200
  async function resolveExecutionSecret(store, initial, fetcher) {
8976
9201
  const credential = store.db.select().from(credentials).where(
8977
- and76(
8978
- eq100(credentials.id, initial.id),
8979
- eq100(credentials.workspaceId, initial.workspaceId)
9202
+ and78(
9203
+ eq103(credentials.id, initial.id),
9204
+ eq103(credentials.workspaceId, initial.workspaceId)
8980
9205
  )
8981
9206
  ).get();
8982
9207
  if (!credential || !provider(credential.provider)) {
8983
9208
  throw new ServiceError("BAD_REQUEST", "Reconnect this credential.");
8984
9209
  }
8985
- const payload = z52.record(z52.string(), z52.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret)));
9210
+ const payload = z54.record(z54.string(), z54.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret)));
8986
9211
  if (credential.provider === "xero-oauth" && Object.keys(payload).length === 1 && typeof payload.secret_accessToken === "string" && payload.secret_accessToken) {
8987
9212
  return recordSecretVersion(
8988
9213
  { secret_accessToken: payload.secret_accessToken },
@@ -9018,9 +9243,9 @@ async function resolveExecutionSecret(store, initial, fetcher) {
9018
9243
  JSON.stringify(applyTokens(payload, tokens2))
9019
9244
  );
9020
9245
  const result = store.db.update(credentials).set({ encryptedSecret: updated, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(
9021
- and76(
9022
- eq100(credentials.id, credential.id),
9023
- eq100(credentials.encryptedSecret, credential.encryptedSecret)
9246
+ and78(
9247
+ eq103(credentials.id, credential.id),
9248
+ eq103(credentials.encryptedSecret, credential.encryptedSecret)
9024
9249
  )
9025
9250
  ).returning().get();
9026
9251
  if (!result) {
@@ -9052,9 +9277,9 @@ async function serveCredential(ctx, credentialId) {
9052
9277
  throw new HttpError(403, "Credential is outside this run capability.");
9053
9278
  }
9054
9279
  const credential2 = ctx.db.select().from(credentials).where(
9055
- and77(
9056
- eq101(credentials.id, credentialId),
9057
- eq101(credentials.workspaceId, run.workspaceId)
9280
+ and79(
9281
+ eq104(credentials.id, credentialId),
9282
+ eq104(credentials.workspaceId, run.workspaceId)
9058
9283
  )
9059
9284
  ).get();
9060
9285
  if (!credential2) {
@@ -9082,12 +9307,12 @@ async function serveCredential(ctx, credentialId) {
9082
9307
  }
9083
9308
 
9084
9309
  // server/execution/shell-policy.ts
9085
- import { and as and78, asc as asc8, eq as eq103 } from "drizzle-orm";
9086
- import { z as z54 } from "zod";
9310
+ import { and as and80, asc as asc8, eq as eq106 } from "drizzle-orm";
9311
+ import { z as z56 } from "zod";
9087
9312
 
9088
9313
  // server/execution/redaction.ts
9089
- import { z as z53 } from "zod";
9090
- import { eq as eq102 } from "drizzle-orm";
9314
+ import { z as z55 } from "zod";
9315
+ import { eq as eq105 } from "drizzle-orm";
9091
9316
  function redact(ctx, workspaceId, value) {
9092
9317
  const secrets = [];
9093
9318
  const collect = (entry) => {
@@ -9099,7 +9324,7 @@ function redact(ctx, workspaceId, value) {
9099
9324
  Object.values(entry).forEach(collect);
9100
9325
  }
9101
9326
  };
9102
- for (const credential of ctx.db.select().from(credentials).where(eq102(credentials.workspaceId, workspaceId)).all()) {
9327
+ for (const credential of ctx.db.select().from(credentials).where(eq105(credentials.workspaceId, workspaceId)).all()) {
9103
9328
  collect(JSON.parse(decrypt(ctx, credential.encryptedSecret)));
9104
9329
  }
9105
9330
  secrets.sort((a, b) => b.length - a.length);
@@ -9126,7 +9351,7 @@ function redact(ctx, workspaceId, value) {
9126
9351
  }
9127
9352
  return entry;
9128
9353
  };
9129
- return mask(z53.json().parse(value));
9354
+ return mask(z55.json().parse(value));
9130
9355
  }
9131
9356
  function bounded(value, limit = 2e5) {
9132
9357
  if (Buffer.byteLength(JSON.stringify(value)) > limit) {
@@ -9136,19 +9361,19 @@ function bounded(value, limit = 2e5) {
9136
9361
  }
9137
9362
 
9138
9363
  // server/execution/shell-policy.ts
9139
- var invocation = z54.strictObject({
9364
+ var invocation = z56.strictObject({
9140
9365
  executable: executableName,
9141
- args: z54.array(
9142
- z54.string().max(4096).refine((arg) => !arg.includes("\0"))
9366
+ args: z56.array(
9367
+ z56.string().max(4096).refine((arg) => !arg.includes("\0"))
9143
9368
  ).max(64)
9144
9369
  });
9145
9370
  function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
9146
9371
  const plugin = ctx.db.select().from(plugins).where(
9147
- and78(
9148
- eq103(plugins.id, pluginId),
9149
- eq103(plugins.projectId, run.projectId),
9150
- eq103(plugins.workspaceId, run.workspaceId),
9151
- eq103(plugins.enabled, true)
9372
+ and80(
9373
+ eq106(plugins.id, pluginId),
9374
+ eq106(plugins.projectId, run.projectId),
9375
+ eq106(plugins.workspaceId, run.workspaceId),
9376
+ eq106(plugins.enabled, true)
9152
9377
  )
9153
9378
  ).get();
9154
9379
  const agent = snapshotAgents(run.snapshot).find(
@@ -9165,29 +9390,29 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
9165
9390
  if (!approvalId && method === "GET") {
9166
9391
  return json(
9167
9392
  ctx.db.select({ name: shellRules.executable }).from(shellRules).where(
9168
- and78(
9169
- eq103(shellRules.pluginId, pluginId),
9170
- eq103(shellRules.decision, "allow")
9393
+ and80(
9394
+ eq106(shellRules.pluginId, pluginId),
9395
+ eq106(shellRules.decision, "allow")
9171
9396
  )
9172
9397
  ).orderBy(asc8(shellRules.executable)).all().map((rule2) => rule2.name)
9173
9398
  );
9174
9399
  }
9175
9400
  if (approvalId && method === "GET") {
9176
9401
  const row2 = ctx.db.select().from(approvals).where(
9177
- and78(
9178
- eq103(approvals.id, approvalId),
9179
- eq103(approvals.workspaceId, run.workspaceId),
9180
- eq103(approvals.runId, run.id)
9402
+ and80(
9403
+ eq106(approvals.id, approvalId),
9404
+ eq106(approvals.workspaceId, run.workspaceId),
9405
+ eq106(approvals.runId, run.id)
9181
9406
  )
9182
9407
  ).get();
9183
9408
  if (row2?.shell?.pluginId !== plugin.id || row2.shell.digest !== plugin.digest) {
9184
9409
  throw new HttpError(404, "Shell approval not found.");
9185
9410
  }
9186
9411
  const blocked = ctx.db.select().from(shellRules).where(
9187
- and78(
9188
- eq103(shellRules.pluginId, pluginId),
9189
- eq103(shellRules.executable, row2.shell.executable),
9190
- eq103(shellRules.decision, "block")
9412
+ and80(
9413
+ eq106(shellRules.pluginId, pluginId),
9414
+ eq106(shellRules.executable, row2.shell.executable),
9415
+ eq106(shellRules.decision, "block")
9191
9416
  )
9192
9417
  ).get();
9193
9418
  return json({
@@ -9204,9 +9429,9 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
9204
9429
  }
9205
9430
  const { executable, args } = parsed.data;
9206
9431
  const rule = ctx.db.select().from(shellRules).where(
9207
- and78(
9208
- eq103(shellRules.pluginId, pluginId),
9209
- eq103(shellRules.executable, executable)
9432
+ and80(
9433
+ eq106(shellRules.pluginId, pluginId),
9434
+ eq106(shellRules.executable, executable)
9210
9435
  )
9211
9436
  ).get();
9212
9437
  if (rule) {
@@ -9230,15 +9455,15 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
9230
9455
  },
9231
9456
  status: "pending"
9232
9457
  }).returning().get();
9233
- ctx.db.update(runs).set({ status: "waiting_approval", updatedAt: now() }).where(eq103(runs.id, run.id)).run();
9458
+ ctx.db.update(runs).set({ status: "waiting_approval", updatedAt: now() }).where(eq106(runs.id, run.id)).run();
9234
9459
  return json({ id: row.id, status: row.status }, 201);
9235
9460
  }
9236
9461
 
9237
9462
  // server/execution/product.ts
9238
- import { and as and81, eq as eq106 } from "drizzle-orm";
9463
+ import { and as and83, eq as eq109 } from "drizzle-orm";
9239
9464
 
9240
9465
  // server/execution/project-data.ts
9241
- import { and as and80, asc as asc9, eq as eq105, inArray as inArray11 } from "drizzle-orm";
9466
+ import { and as and82, asc as asc9, eq as eq108, inArray as inArray11 } from "drizzle-orm";
9242
9467
 
9243
9468
  // server/execution/data-pagination.ts
9244
9469
  function paginateData(items, offset, limit) {
@@ -9265,56 +9490,56 @@ function paginateData(items, offset, limit) {
9265
9490
  }
9266
9491
 
9267
9492
  // server/execution/data-schemas.ts
9268
- import { z as z55 } from "zod";
9493
+ import { z as z57 } from "zod";
9269
9494
  var pagination = {
9270
- offset: z55.number().int().min(0).max(1e6).default(0),
9271
- limit: z55.number().int().min(1).max(100).default(100)
9495
+ offset: z57.number().int().min(0).max(1e6).default(0),
9496
+ limit: z57.number().int().min(1).max(100).default(100)
9272
9497
  };
9273
- var tableId = { table_id: z55.string().uuid() };
9274
- var revision2 = z55.number().int().positive();
9275
- var content = z55.string().refine(
9498
+ var tableId = { table_id: z57.string().uuid() };
9499
+ var revision2 = z57.number().int().positive();
9500
+ var content = z57.string().refine(
9276
9501
  (value) => !value.includes("\0") && Buffer.byteLength(value) <= 2e5
9277
9502
  );
9278
- var dataOperationSchema = z55.discriminatedUnion("operation", [
9279
- z55.strictObject({ operation: z55.literal("list_tables"), ...pagination }),
9280
- z55.strictObject({ operation: z55.literal("get_table"), ...tableId }),
9281
- z55.strictObject({
9282
- operation: z55.literal("list_rows"),
9503
+ var dataOperationSchema = z57.discriminatedUnion("operation", [
9504
+ z57.strictObject({ operation: z57.literal("list_tables"), ...pagination }),
9505
+ z57.strictObject({ operation: z57.literal("get_table"), ...tableId }),
9506
+ z57.strictObject({
9507
+ operation: z57.literal("list_rows"),
9283
9508
  ...tableId,
9284
9509
  ...pagination
9285
9510
  }),
9286
- z55.strictObject({
9287
- operation: z55.literal("write_row"),
9511
+ z57.strictObject({
9512
+ operation: z57.literal("write_row"),
9288
9513
  ...tableId,
9289
9514
  table_revision: revision2,
9290
- values: z55.record(z55.string(), z55.json()),
9291
- row_id: z55.string().uuid().optional(),
9515
+ values: z57.record(z57.string(), z57.json()),
9516
+ row_id: z57.string().uuid().optional(),
9292
9517
  revision: revision2.optional()
9293
9518
  }).refine(
9294
9519
  (input2) => input2.row_id === void 0 === (input2.revision === void 0),
9295
9520
  "Row updates require both row ID and revision."
9296
9521
  ),
9297
- z55.strictObject({
9298
- operation: z55.literal("delete_row"),
9522
+ z57.strictObject({
9523
+ operation: z57.literal("delete_row"),
9299
9524
  ...tableId,
9300
- row_id: z55.string().uuid(),
9525
+ row_id: z57.string().uuid(),
9301
9526
  revision: revision2
9302
9527
  }),
9303
- z55.strictObject({ operation: z55.literal("list_documents"), ...pagination }),
9304
- z55.strictObject({
9305
- operation: z55.literal("get_document"),
9306
- document_id: z55.string().uuid()
9528
+ z57.strictObject({ operation: z57.literal("list_documents"), ...pagination }),
9529
+ z57.strictObject({
9530
+ operation: z57.literal("get_document"),
9531
+ document_id: z57.string().uuid()
9307
9532
  }),
9308
- z55.strictObject({
9309
- operation: z55.literal("write_document"),
9310
- document_id: z55.string().uuid(),
9311
- title: z55.string().trim().min(1).max(200).refine((value) => !value.includes("\0")).optional(),
9533
+ z57.strictObject({
9534
+ operation: z57.literal("write_document"),
9535
+ document_id: z57.string().uuid(),
9536
+ title: z57.string().trim().min(1).max(200).refine((value) => !value.includes("\0")).optional(),
9312
9537
  content: content.optional()
9313
9538
  })
9314
9539
  ]);
9315
9540
 
9316
9541
  // server/execution/run-grants.ts
9317
- import { and as and79, eq as eq104 } from "drizzle-orm";
9542
+ import { and as and81, eq as eq107 } from "drizzle-orm";
9318
9543
  function grantIds(context, run, kind, write = false) {
9319
9544
  const root2 = snapshotAgents(run.snapshot).find(
9320
9545
  (agent) => agent.id === run.projectId
@@ -9325,9 +9550,9 @@ function grantIds(context, run, kind, write = false) {
9325
9550
  ...write ? [] : grants2?.read ?? []
9326
9551
  ];
9327
9552
  const project = context.db.select().from(projects).where(
9328
- and79(
9329
- eq104(projects.id, run.projectId),
9330
- eq104(projects.workspaceId, run.workspaceId)
9553
+ and81(
9554
+ eq107(projects.id, run.projectId),
9555
+ eq107(projects.workspaceId, run.workspaceId)
9331
9556
  )
9332
9557
  ).get();
9333
9558
  if (!project) {
@@ -9353,8 +9578,8 @@ function projectData(context, run, body) {
9353
9578
  const documentOperation = input2.operation === "list_documents" || input2.operation === "get_document" || input2.operation === "write_document";
9354
9579
  if (documentOperation) {
9355
9580
  const accessibleDocuments = context.db.select().from(documents).where(
9356
- and80(
9357
- eq105(documents.workspaceId, run.workspaceId),
9581
+ and82(
9582
+ eq108(documents.workspaceId, run.workspaceId),
9358
9583
  inArray11(documents.id, grantIds(context, run, "documents"))
9359
9584
  )
9360
9585
  ).orderBy(asc9(documents.id)).all();
@@ -9382,9 +9607,9 @@ function projectData(context, run, body) {
9382
9607
  content: input2.content ?? document.content,
9383
9608
  updatedAt: now()
9384
9609
  }).where(
9385
- and80(
9386
- eq105(documents.id, document.id),
9387
- eq105(documents.workspaceId, run.workspaceId)
9610
+ and82(
9611
+ eq108(documents.id, document.id),
9612
+ eq108(documents.workspaceId, run.workspaceId)
9388
9613
  )
9389
9614
  ).returning().get();
9390
9615
  if (!updated) {
@@ -9393,8 +9618,8 @@ function projectData(context, run, body) {
9393
9618
  return bounded(documentView2(updated));
9394
9619
  }
9395
9620
  const tables = context.db.select().from(workspaceTables).where(
9396
- and80(
9397
- eq105(workspaceTables.workspaceId, run.workspaceId),
9621
+ and82(
9622
+ eq108(workspaceTables.workspaceId, run.workspaceId),
9398
9623
  inArray11(workspaceTables.id, grantIds(context, run, "tables"))
9399
9624
  )
9400
9625
  ).orderBy(asc9(workspaceTables.id)).all();
@@ -9411,15 +9636,15 @@ function projectData(context, run, body) {
9411
9636
  if (input2.operation !== "list_rows" && !grantIds(context, run, "tables", true).includes(table.id)) {
9412
9637
  throw new HttpError(403, "Resource is read only.");
9413
9638
  }
9414
- const matchesTable = and80(
9415
- eq105(tableRows.workspaceId, run.workspaceId),
9416
- eq105(tableRows.tableId, table.id)
9639
+ const matchesTable = and82(
9640
+ eq108(tableRows.workspaceId, run.workspaceId),
9641
+ eq108(tableRows.tableId, table.id)
9417
9642
  );
9418
9643
  if (input2.operation === "list_rows") {
9419
9644
  const rows = context.db.select().from(tableRows).where(matchesTable).orderBy(asc9(tableRows.id)).all();
9420
9645
  return paginateData(rows.map(rowView), input2.offset, input2.limit);
9421
9646
  }
9422
- const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(and80(matchesTable, eq105(tableRows.id, input2.row_id))).get();
9647
+ const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(and82(matchesTable, eq108(tableRows.id, input2.row_id))).get();
9423
9648
  if (input2.row_id !== void 0 && !row) {
9424
9649
  throw new HttpError(404, "Row not found.");
9425
9650
  }
@@ -9427,7 +9652,7 @@ function projectData(context, run, body) {
9427
9652
  throw new HttpError(409, "Row changed. Reload before saving.");
9428
9653
  }
9429
9654
  if (input2.operation === "delete_row") {
9430
- context.db.delete(tableRows).where(and80(matchesTable, eq105(tableRows.id, input2.row_id))).run();
9655
+ context.db.delete(tableRows).where(and82(matchesTable, eq108(tableRows.id, input2.row_id))).run();
9431
9656
  return { deleted: true };
9432
9657
  }
9433
9658
  if (table.revision !== input2.table_revision) {
@@ -9439,7 +9664,7 @@ function projectData(context, run, body) {
9439
9664
  values: input2.values,
9440
9665
  revision: row.revision + 1,
9441
9666
  updatedAt: now()
9442
- }).where(and80(matchesTable, eq105(tableRows.id, row.id))).returning().get();
9667
+ }).where(and82(matchesTable, eq108(tableRows.id, row.id))).returning().get();
9443
9668
  if (!updated) {
9444
9669
  throw new HttpError(404, "Row not found.");
9445
9670
  }
@@ -9483,7 +9708,7 @@ function handleProduct(ctx, run, route, method, body) {
9483
9708
  }
9484
9709
  if (method === "GET") {
9485
9710
  const items = ctx.db.select().from(table).where(
9486
- and81(eq106(table.workspaceId, run.workspaceId), eq106(table.runId, run.id))
9711
+ and83(eq109(table.workspaceId, run.workspaceId), eq109(table.runId, run.id))
9487
9712
  ).all();
9488
9713
  const view = (entry) => "prompt" in entry ? {
9489
9714
  id: entry.id,
@@ -9522,7 +9747,7 @@ function handleProduct(ctx, run, route, method, body) {
9522
9747
  status: "pending",
9523
9748
  decidedBy: null
9524
9749
  }).returning().get();
9525
- ctx.db.update(runs).set({ status: "waiting_approval" }).where(eq106(runs.id, run.id)).run();
9750
+ ctx.db.update(runs).set({ status: "waiting_approval" }).where(eq109(runs.id, run.id)).run();
9526
9751
  return json(
9527
9752
  {
9528
9753
  id: approval.id,
@@ -9560,7 +9785,7 @@ function handleProduct(ctx, run, route, method, body) {
9560
9785
  }
9561
9786
 
9562
9787
  // server/execution/register.ts
9563
- import { eq as eq107 } from "drizzle-orm";
9788
+ import { eq as eq110 } from "drizzle-orm";
9564
9789
  function register(ctx, worker, body) {
9565
9790
  const version2 = body.protocol_version;
9566
9791
  const capabilities = body.capabilities;
@@ -9584,20 +9809,20 @@ function register(ctx, worker, body) {
9584
9809
  capabilities: validatedCapabilities,
9585
9810
  lastSeenAt: now(),
9586
9811
  updatedAt: now()
9587
- }).where(eq107(executors.id, worker.id)).returning().get();
9812
+ }).where(eq110(executors.id, worker.id)).returning().get();
9588
9813
  return json(configuration(ctx, registered));
9589
9814
  }
9590
9815
 
9591
9816
  // server/execution/run-update.ts
9592
- import { and as and82, eq as eq108 } from "drizzle-orm";
9817
+ import { and as and84, eq as eq111 } from "drizzle-orm";
9593
9818
  function handleRunUpdate(ctx, run, action, body) {
9594
9819
  if (action === "heartbeat") {
9595
9820
  if (!terminal.has(run.status)) {
9596
9821
  if (run.executorId) {
9597
9822
  ctx.db.update(executors).set({ lastSeenAt: now() }).where(
9598
- and82(
9599
- eq108(executors.id, run.executorId),
9600
- eq108(executors.workspaceId, run.workspaceId)
9823
+ and84(
9824
+ eq111(executors.id, run.executorId),
9825
+ eq111(executors.workspaceId, run.workspaceId)
9601
9826
  )
9602
9827
  ).run();
9603
9828
  }
@@ -9606,7 +9831,7 @@ function handleRunUpdate(ctx, run, action, body) {
9606
9831
  leaseExpiresAt: new Date(
9607
9832
  Math.min(Date.now() + 6e4, Date.parse(run.deadline))
9608
9833
  ).toISOString()
9609
- }).where(eq108(runs.id, run.id)).run();
9834
+ }).where(eq111(runs.id, run.id)).run();
9610
9835
  }
9611
9836
  return json({
9612
9837
  status: run.status,
@@ -9624,9 +9849,9 @@ function handleRunUpdate(ctx, run, action, body) {
9624
9849
  "Event data"
9625
9850
  );
9626
9851
  const existing = ctx.db.select().from(runEvents).where(
9627
- and82(
9628
- eq108(runEvents.runId, run.id),
9629
- eq108(runEvents.sequence, body.sequence)
9852
+ and84(
9853
+ eq111(runEvents.runId, run.id),
9854
+ eq111(runEvents.sequence, body.sequence)
9630
9855
  )
9631
9856
  ).get();
9632
9857
  if (existing && (existing.kind !== body.kind || JSON.stringify(existing.data) !== JSON.stringify(data))) {
@@ -9680,13 +9905,13 @@ function handleRunUpdate(ctx, run, action, body) {
9680
9905
  );
9681
9906
  }
9682
9907
  const pending = ctx.db.select().from(approvals).where(
9683
- and82(eq108(approvals.runId, run.id), eq108(approvals.status, "pending"))
9908
+ and84(eq111(approvals.runId, run.id), eq111(approvals.status, "pending"))
9684
9909
  ).all();
9685
9910
  if (pending.length && status === "succeeded") {
9686
9911
  throw new HttpError(400, "Resolve pending approvals before completing.");
9687
9912
  }
9688
9913
  ctx.db.update(approvals).set({ status: "interrupted" }).where(
9689
- and82(eq108(approvals.runId, run.id), eq108(approvals.status, "pending"))
9914
+ and84(eq111(approvals.runId, run.id), eq111(approvals.status, "pending"))
9690
9915
  ).run();
9691
9916
  ctx.db.update(runs).set({
9692
9917
  status,
@@ -9694,7 +9919,7 @@ function handleRunUpdate(ctx, run, action, body) {
9694
9919
  error,
9695
9920
  cancelRequested: run.cancelRequested,
9696
9921
  updatedAt: now()
9697
- }).where(eq108(runs.id, run.id)).run();
9922
+ }).where(eq111(runs.id, run.id)).run();
9698
9923
  return new Response(null, { status: 204 });
9699
9924
  }
9700
9925
 
@@ -9748,7 +9973,7 @@ function handleWorker(ctx, route, method, body) {
9748
9973
  }
9749
9974
 
9750
9975
  // server/oauth/callback.ts
9751
- import { and as and83, eq as eq109 } from "drizzle-orm";
9976
+ import { and as and85, eq as eq112 } from "drizzle-orm";
9752
9977
  import { randomUUID as randomUUID7 } from "node:crypto";
9753
9978
  async function finishOAuth(ctx, input2, fetcher = fetch) {
9754
9979
  const workspace2 = authorize(ctx);
@@ -9762,14 +9987,14 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
9762
9987
  const state = field(input2.state, 500);
9763
9988
  const code = field(input2.code, 4e3);
9764
9989
  const attempt = inTransaction(ctx, (ctx2) => {
9765
- const record = ctx2.db.select().from(oauthAttempts).where(eq109(oauthAttempts.stateDigest, digest(state))).get();
9990
+ const record = ctx2.db.select().from(oauthAttempts).where(eq112(oauthAttempts.stateDigest, digest(state))).get();
9766
9991
  if (!record || record.userId !== user.id || record.workspaceId !== workspace2.id || record.sessionId !== ctx2.sessionId || record.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
9767
9992
  throw new ServiceError(
9768
9993
  "BAD_REQUEST",
9769
9994
  "This connection request has expired or belongs to another session."
9770
9995
  );
9771
9996
  }
9772
- ctx2.db.delete(oauthAttempts).where(eq109(oauthAttempts.stateDigest, record.stateDigest)).run();
9997
+ ctx2.db.delete(oauthAttempts).where(eq112(oauthAttempts.stateDigest, record.stateDigest)).run();
9773
9998
  return record;
9774
9999
  });
9775
10000
  const payload = JSON.parse(decrypt(ctx, attempt.encryptedPayload));
@@ -9794,9 +10019,9 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
9794
10019
  inTransaction(ctx, (ctx2) => {
9795
10020
  const session = identityRepository(ctx2.db).session(ctx2.sessionId);
9796
10021
  const plugin = ctx2.db.select().from(plugins).where(
9797
- and83(
9798
- eq109(plugins.id, attempt.pluginId),
9799
- eq109(plugins.workspaceId, workspace2.id)
10022
+ and85(
10023
+ eq112(plugins.id, attempt.pluginId),
10024
+ eq112(plugins.workspaceId, workspace2.id)
9800
10025
  )
9801
10026
  ).get();
9802
10027
  if (!session || session.userId !== user.id || session.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
@@ -9838,7 +10063,7 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
9838
10063
  createdAt: timestamp,
9839
10064
  updatedAt: timestamp
9840
10065
  }).run();
9841
- ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(eq109(plugins.id, plugin.id)).run();
10066
+ ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(eq112(plugins.id, plugin.id)).run();
9842
10067
  ctx2.db.insert(auditRecords).values({
9843
10068
  id: randomUUID7(),
9844
10069
  workspaceId: workspace2.id,
@@ -9896,7 +10121,7 @@ function publicRequest(request) {
9896
10121
  }
9897
10122
 
9898
10123
  // server/repositories/token-activity.ts
9899
- import { and as and84, eq as eq110, sql as sql4 } from "drizzle-orm";
10124
+ import { and as and86, eq as eq113, sql as sql4 } from "drizzle-orm";
9900
10125
  function recordTokenActivity(store, token, status, isMcp, hasFailed) {
9901
10126
  const time = (/* @__PURE__ */ new Date()).toISOString();
9902
10127
  store.db.update(accessTokens).set({
@@ -9909,9 +10134,9 @@ function recordTokenActivity(store, token, status, isMcp, hasFailed) {
9909
10134
  lastOutcome: hasFailed ? "error" : "success",
9910
10135
  lastStatusCode: status
9911
10136
  }).where(
9912
- and84(
9913
- eq110(accessTokens.id, token.id),
9914
- eq110(accessTokens.workspaceId, token.workspaceId)
10137
+ and86(
10138
+ eq113(accessTokens.id, token.id),
10139
+ eq113(accessTokens.workspaceId, token.workspaceId)
9915
10140
  )
9916
10141
  ).run();
9917
10142
  }
@@ -10012,7 +10237,7 @@ function errorResponse(error) {
10012
10237
  if (error instanceof ServiceError) {
10013
10238
  return json({ detail: error.message }, serviceErrorStatus[error.code]);
10014
10239
  }
10015
- if (error instanceof ZodError2) {
10240
+ if (error instanceof ZodError3) {
10016
10241
  return json({ detail: "Invalid input." }, 400);
10017
10242
  }
10018
10243
  if (error instanceof HttpError) {
@@ -10186,7 +10411,7 @@ function createApp(dependencies) {
10186
10411
  }
10187
10412
 
10188
10413
  // server/cli/accounts.ts
10189
- import { eq as eq111, or as or6 } from "drizzle-orm";
10414
+ import { eq as eq114, or as or6 } from "drizzle-orm";
10190
10415
  import { createInterface } from "node:readline/promises";
10191
10416
  import { Writable } from "node:stream";
10192
10417
  async function resetPassword(store, email) {
@@ -10227,9 +10452,9 @@ async function resetPassword(store, email) {
10227
10452
  }
10228
10453
  const passwordHash = await password.hash(password2);
10229
10454
  inTransaction(store, (store2) => {
10230
- store2.db.update(users).set({ passwordHash }).where(eq111(users.id, user.id)).run();
10455
+ store2.db.update(users).set({ passwordHash }).where(eq114(users.id, user.id)).run();
10231
10456
  store2.db.delete(sessions).where(
10232
- or6(eq111(sessions.userId, user.id), eq111(sessions.pendingUserId, user.id))
10457
+ or6(eq114(sessions.userId, user.id), eq114(sessions.pendingUserId, user.id))
10233
10458
  ).run();
10234
10459
  });
10235
10460
  console.log("Password changed. Existing sign-in sessions were revoked.");
@@ -10239,7 +10464,7 @@ async function resetPassword(store, email) {
10239
10464
  }
10240
10465
 
10241
10466
  // server/cli/database.ts
10242
- import { z as z56 } from "zod";
10467
+ import { z as z58 } from "zod";
10243
10468
 
10244
10469
  // server/db/connection.ts
10245
10470
  var driver = typeof Bun === "undefined" ? await import("./node-driver-75PFAG2L.js") : await import("./bun-driver-UOZIWBHK.js");
@@ -10249,7 +10474,7 @@ var openDatabase = driver.openDatabase;
10249
10474
  import { chmodSync, constants, copyFileSync, existsSync as existsSync4 } from "node:fs";
10250
10475
  import { join as join4 } from "node:path";
10251
10476
  function verifySnapshot(sqlite) {
10252
- const integrity = z56.array(z56.object({ integrity_check: z56.string() })).parse(sqlite.query("PRAGMA integrity_check").all());
10477
+ const integrity = z58.array(z58.object({ integrity_check: z58.string() })).parse(sqlite.query("PRAGMA integrity_check").all());
10253
10478
  if (integrity.length !== 1 || integrity[0]?.integrity_check !== "ok") {
10254
10479
  throw new Error("Backup integrity check failed.");
10255
10480
  }
@@ -10307,7 +10532,7 @@ function restoreDatabase(dataDir2, source) {
10307
10532
  }
10308
10533
 
10309
10534
  // server/db/index.ts
10310
- import { count, isNotNull, isNull as isNull3, or as or7 } from "drizzle-orm";
10535
+ import { count as count2, isNotNull, isNull as isNull3, or as or7 } from "drizzle-orm";
10311
10536
  import { chmodSync as chmodSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readdirSync } from "node:fs";
10312
10537
  import { join as join5 } from "node:path";
10313
10538
 
@@ -10372,15 +10597,15 @@ function openStore(dataDir2) {
10372
10597
  connection.migrate(migrationsFolder);
10373
10598
  if (!existsSync5(join5(dataDir2, "encryption.key"))) {
10374
10599
  const protectedRows = [
10375
- db.select({ count: count() }).from(credentials).get()?.count ?? 0,
10376
- db.select({ count: count() }).from(users).where(
10600
+ db.select({ count: count2() }).from(credentials).get()?.count ?? 0,
10601
+ db.select({ count: count2() }).from(users).where(
10377
10602
  or7(
10378
10603
  isNotNull(users.totpSecret),
10379
10604
  isNotNull(users.pendingTotpSecret)
10380
10605
  )
10381
10606
  ).get()?.count ?? 0,
10382
- db.select({ count: count() }).from(mailOutbox).where(isNull3(mailOutbox.sentAt)).get()?.count ?? 0,
10383
- db.select({ count: count() }).from(oauthAttempts).get()?.count ?? 0
10607
+ db.select({ count: count2() }).from(mailOutbox).where(isNull3(mailOutbox.sentAt)).get()?.count ?? 0,
10608
+ db.select({ count: count2() }).from(oauthAttempts).get()?.count ?? 0
10384
10609
  ];
10385
10610
  if (protectedRows.some((total) => total > 0)) {
10386
10611
  throw new Error(
@@ -10397,9 +10622,9 @@ function openStore(dataDir2) {
10397
10622
  }
10398
10623
 
10399
10624
  // server/execution/maintenance.ts
10400
- import { z as z57 } from "zod";
10625
+ import { z as z59 } from "zod";
10401
10626
  import { CronExpressionParser as CronExpressionParser2 } from "cron-parser";
10402
- import { and as and85, eq as eq112, inArray as inArray12 } from "drizzle-orm";
10627
+ import { and as and87, eq as eq115, inArray as inArray12 } from "drizzle-orm";
10403
10628
  function maintenance(store) {
10404
10629
  const currentTime = now();
10405
10630
  inTransaction(store, (store2) => {
@@ -10411,22 +10636,22 @@ function maintenance(store) {
10411
10636
  error: "Execution stopped responding. Review side effects before retrying.",
10412
10637
  capabilityHash: "",
10413
10638
  updatedAt: currentTime
10414
- }).where(eq112(runs.id, run.id)).run();
10639
+ }).where(eq115(runs.id, run.id)).run();
10415
10640
  store2.db.update(approvals).set({ status: "interrupted" }).where(
10416
- and85(
10417
- eq112(approvals.runId, run.id),
10418
- eq112(approvals.status, "pending")
10641
+ and87(
10642
+ eq115(approvals.runId, run.id),
10643
+ eq115(approvals.status, "pending")
10419
10644
  )
10420
10645
  ).run();
10421
10646
  }
10422
10647
  }
10423
- for (const schedule of store2.db.select().from(schedules).where(eq112(schedules.enabled, true)).all()) {
10648
+ for (const schedule of store2.db.select().from(schedules).where(eq115(schedules.enabled, true)).all()) {
10424
10649
  if (schedule.nextRunAt > currentTime) {
10425
10650
  continue;
10426
10651
  }
10427
- const action = store2.db.select().from(actions).where(eq112(actions.id, schedule.actionId)).get();
10652
+ const action = store2.db.select().from(actions).where(eq115(actions.id, schedule.actionId)).get();
10428
10653
  if (!action) {
10429
- store2.db.update(schedules).set({ enabled: false }).where(eq112(schedules.id, schedule.id)).run();
10654
+ store2.db.update(schedules).set({ enabled: false }).where(eq115(schedules.id, schedule.id)).run();
10430
10655
  continue;
10431
10656
  }
10432
10657
  const nextRunAt = CronExpressionParser2.parse(schedule.cron, {
@@ -10457,16 +10682,16 @@ function maintenance(store) {
10457
10682
  project: action.projectId,
10458
10683
  operation: "action",
10459
10684
  action: action.id,
10460
- inputs: z57.record(z57.string(), z57.json()).parse(schedule.inputs),
10685
+ inputs: z59.record(z59.string(), z59.json()).parse(schedule.inputs),
10461
10686
  idempotency_key: `schedule:${schedule.id}:${schedule.nextRunAt}`
10462
10687
  });
10463
- store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq112(runs.id, run.id)).run();
10688
+ store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq115(runs.id, run.id)).run();
10464
10689
  } catch (error) {
10465
10690
  if (!(error instanceof ServiceError)) {
10466
10691
  throw error;
10467
10692
  }
10468
10693
  }
10469
- store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(eq112(schedules.id, schedule.id)).run();
10694
+ store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(eq115(schedules.id, schedule.id)).run();
10470
10695
  }
10471
10696
  });
10472
10697
  }