@orgsdk/cli 2.4.1 → 2.5.1

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 (58) hide show
  1. package/dist/server/index.js +1614 -1404
  2. package/dist/server/out/_next/static/chunks/09z0b8hcy8mgc.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/package.json +1 -1
  55. package/dist/server/out/_next/static/chunks/25_4kq7-d_fl-.css +0 -1
  56. /package/dist/server/out/_next/static/{6djYNpWGX3-5YRZkUZLdy → uIdH9uHNGbXDqAUfYTkDm}/_buildManifest.js +0 -0
  57. /package/dist/server/out/_next/static/{6djYNpWGX3-5YRZkUZLdy → uIdH9uHNGbXDqAUfYTkDm}/_clientMiddlewareManifest.js +0 -0
  58. /package/dist/server/out/_next/static/{6djYNpWGX3-5YRZkUZLdy → uIdH9uHNGbXDqAUfYTkDm}/_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,253 +1295,31 @@ async function input(request) {
1295
1295
  }
1296
1296
  }
1297
1297
 
1298
- // server/router/procedures.ts
1299
- import { initTRPC, TRPCError } from "@trpc/server";
1300
- import { ZodError } from "zod";
1301
-
1302
- // server/repositories/identity.ts
1303
- import { and as and7, eq as eq7 } from "drizzle-orm";
1298
+ // server/plugins/settings.ts
1299
+ import { z as z14 } from "zod";
1304
1300
 
1305
- // server/tokens/access-token.ts
1301
+ // server/credentials/schemas.ts
1306
1302
  import { z as z10 } from "zod";
1307
- var mcpTokenPrefix = "orgsdk_mcp_";
1308
- var mcpAccessTokenSchema = z10.templateLiteral([
1309
- mcpTokenPrefix,
1310
- z10.string().regex(/[A-Za-z0-9_-]{43}/)
1311
- ]);
1312
- var issuedMcpAccessTokenSchema = z10.object({
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({
1313
1309
  id: z10.uuid(),
1314
- token: mcpAccessTokenSchema
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()
1315
1322
  });
1316
- function issueMcpAccessToken() {
1317
- return `${mcpTokenPrefix}${randomSecret()}`;
1318
- }
1319
- function mcpAccessTokenDigest(token) {
1320
- return digest(token.slice(mcpTokenPrefix.length));
1321
- }
1322
-
1323
- // server/repositories/identity.ts
1324
- function identityRepository(database) {
1325
- return {
1326
- workspaceForHost(host) {
1327
- return database.select().from(workspaces).where(eq7(workspaces.host, host)).get();
1328
- },
1329
- anyWorkspace() {
1330
- return database.select().from(workspaces).get();
1331
- },
1332
- user(id) {
1333
- return database.select().from(users).where(eq7(users.id, id)).get();
1334
- },
1335
- userByEmail(email) {
1336
- return database.select().from(users).where(eq7(users.email, email)).get();
1337
- },
1338
- session(id) {
1339
- return database.select().from(sessions).where(eq7(sessions.id, id)).get();
1340
- },
1341
- activeClientToken(workspaceId, token) {
1342
- const tokenDigest = mcpAccessTokenDigest(token);
1343
- return database.select().from(accessTokens).where(
1344
- and7(
1345
- eq7(accessTokens.digest, tokenDigest),
1346
- eq7(accessTokens.workspaceId, workspaceId),
1347
- eq7(accessTokens.revoked, false)
1348
- )
1349
- ).get();
1350
- },
1351
- membership(workspaceId, userId) {
1352
- return database.select().from(memberships).where(
1353
- and7(
1354
- eq7(memberships.workspaceId, workspaceId),
1355
- eq7(memberships.userId, userId)
1356
- )
1357
- ).get();
1358
- }
1359
- };
1360
- }
1361
-
1362
- // server/http/context.ts
1363
- function cookies(request) {
1364
- return new Map(
1365
- (request.headers.get("cookie") ?? "").split(";").map((part) => {
1366
- const index = part.indexOf("=");
1367
- return index < 0 ? ["", ""] : [part.slice(0, index).trim(), part.slice(index + 1).trim()];
1368
- })
1369
- );
1370
- }
1371
- function setCookie(ctx, name, value, httpOnly = false, maxAge = 86400 * 14) {
1372
- if (ctx.studioOrigin) {
1373
- return;
1374
- }
1375
- const secure = new URL(ctx.request.url).protocol === "https:" ? "; Secure" : "";
1376
- ctx.responseHeaders.append(
1377
- "Set-Cookie",
1378
- `${name}=${value}; Path=/; SameSite=Lax; Max-Age=${maxAge}${httpOnly ? "; HttpOnly" : ""}${secure}`
1379
- );
1380
- }
1381
- function authenticateClientBearer(authorization, identities, workspaceId) {
1382
- const bearer2 = authorization?.match(/^Bearer(?:[ \t]+(.*))?$/i);
1383
- if (!bearer2) {
1384
- return { token: null, clientTokenError: null };
1385
- }
1386
- const supplied = mcpAccessTokenSchema.safeParse(bearer2[1]);
1387
- if (!supplied.success) {
1388
- return {
1389
- token: null,
1390
- clientTokenError: `Expected an OrgSDK access token beginning with ${mcpTokenPrefix} followed by its 43-character secret.`
1391
- };
1392
- }
1393
- const token = workspaceId === void 0 ? null : identities.activeClientToken(workspaceId, supplied.data) ?? null;
1394
- return {
1395
- token,
1396
- clientTokenError: token ? null : "Invalid OrgSDK access token."
1397
- };
1398
- }
1399
- function createContext(request, store) {
1400
- const url = new URL(request.url);
1401
- const hostname2 = url.hostname.toLowerCase();
1402
- const identities = identityRepository(store.db);
1403
- const workspace2 = identities.workspaceForHost(hostname2) ?? null;
1404
- const origin = request.headers.get("origin");
1405
- const studioOrigin = origin && url.pathname.startsWith("/trpc/") && origin === studioAudience(url.origin) ? origin : void 0;
1406
- const studioToken = request.headers.get("x-orgsdk-studio-session");
1407
- const grant = studioOrigin ? studioSession(store.db, url.origin, studioOrigin, studioToken) : void 0;
1408
- if (studioOrigin && (request.headers.has("cookie") || request.headers.has("authorization"))) {
1409
- throw new ServiceError(
1410
- "FORBIDDEN",
1411
- "Dashboard requests must use a paired session."
1412
- );
1413
- }
1414
- const values2 = cookies(request);
1415
- const secret = values2.get("sessionid");
1416
- const localStudioId = studioOrigin && studioToken && isLoopbackInstallation(url.origin) ? studioLoginSessionId(url.origin, studioOrigin, studioToken) : void 0;
1417
- const sessionId = grant?.sessionId ?? localStudioId ?? (secret ? digest(secret) : void 0);
1418
- const session = sessionId ? identities.session(sessionId) : void 0;
1419
- const validSession = session && session.expiresAt > Date.now() ? session : void 0;
1420
- const authorization = request.headers.get("authorization");
1421
- const { token, clientTokenError } = authenticateClientBearer(
1422
- url.pathname.startsWith("/internal/") ? null : authorization,
1423
- identities,
1424
- workspace2?.id
1425
- );
1426
- const userId = authorization === null ? validSession?.userId : token?.actorId;
1427
- const user = userId ? identities.user(userId) ?? null : null;
1428
- const membership = user && workspace2 ? identities.membership(workspace2.id, user.id) : void 0;
1429
- const responseHeaders = new Headers({ "Cache-Control": "no-store" });
1430
- const ctx = {
1431
- request,
1432
- userId: user?.id ?? null,
1433
- operationType: ["GET", "HEAD", "OPTIONS"].includes(request.method) ? "query" : "mutation",
1434
- origin: url.origin,
1435
- hostname: hostname2,
1436
- db: store.db,
1437
- secrets: store.secrets,
1438
- user,
1439
- workspace: workspace2,
1440
- role: membership?.role ?? null,
1441
- token,
1442
- clientTokenError,
1443
- responseHeaders,
1444
- studioOrigin,
1445
- studioExpiresAt: grant?.expiresAt ?? (localStudioId ? validSession?.expiresAt : void 0),
1446
- sessionId: validSession?.id ?? null
1447
- };
1448
- if (!studioOrigin && !values2.get("csrftoken")) {
1449
- setCookie(ctx, "csrftoken", randomSecret());
1450
- }
1451
- return ctx;
1452
- }
1453
- function checkClientRequest(ctx, operationType = ctx.operationType) {
1454
- if (ctx.clientTokenError) {
1455
- throw new ServiceError("UNAUTHORIZED", ctx.clientTokenError);
1456
- }
1457
- if (operationType !== "mutation" || ctx.token) {
1458
- return;
1459
- }
1460
- const origin = ctx.request.headers.get("origin");
1461
- if (origin && origin !== new URL(ctx.request.url).origin) {
1462
- throw new ServiceError("FORBIDDEN", "Invalid origin.");
1463
- }
1464
- const cookie = cookies(ctx.request).get("csrftoken");
1465
- const header = ctx.request.headers.get("x-csrftoken");
1466
- if (!cookie || !header || cookie !== header) {
1467
- throw new ServiceError("FORBIDDEN", "CSRF verification failed.");
1468
- }
1469
- }
1470
-
1471
- // server/auth/sessions.ts
1472
- import { eq as eq8 } from "drizzle-orm";
1473
- function rotateSession(ctx, userId, pendingUserId = null, guard, mutation) {
1474
- const secret = randomSecret();
1475
- const id = ctx.studioOrigin ? studioLoginSessionId(ctx.origin, ctx.studioOrigin, secret) : digest(secret);
1476
- const time = Date.now();
1477
- const expiresAt = time + (pendingUserId ? 5 * 6e4 : 14 * 864e5);
1478
- inTransaction(ctx, (ctx2) => {
1479
- guard?.(ctx2);
1480
- if (ctx2.studioOrigin && userId && (!ctx2.workspace || !identityRepository(ctx2.db).membership(ctx2.workspace.id, userId))) {
1481
- throw new ServiceError(
1482
- "FORBIDDEN",
1483
- "You are not a member of this workspace."
1484
- );
1485
- }
1486
- mutation?.(ctx2);
1487
- if (ctx2.sessionId) {
1488
- ctx2.db.delete(sessions).where(eq8(sessions.id, ctx2.sessionId)).run();
1489
- }
1490
- ctx2.db.insert(sessions).values({
1491
- id,
1492
- userId,
1493
- pendingUserId,
1494
- workspaceId: ctx2.workspace?.id ?? null,
1495
- expiresAt,
1496
- reauthenticatedAt: userId ? time : null
1497
- }).run();
1498
- });
1499
- ctx.sessionId = id;
1500
- ctx.sessionChanged(secret);
1501
- if (ctx.studioOrigin) {
1502
- return { token: secret, expiresAt };
1503
- }
1504
- return null;
1505
- }
1506
- function requireFresh(ctx) {
1507
- requireUser(ctx);
1508
- const session = ctx.sessionId ? identityRepository(ctx.db).session(ctx.sessionId) : void 0;
1509
- if (!session?.reauthenticatedAt || session.userId !== ctx.user?.id || session.expiresAt <= Date.now() || session.reauthenticatedAt < Date.now() - 3e5) {
1510
- throw new ServiceError(
1511
- "UNAUTHORIZED",
1512
- "Confirm your identity to continue."
1513
- );
1514
- }
1515
- }
1516
- function assertCurrentUser(ctx, user, withSession = true) {
1517
- const current = identityRepository(ctx.db).user(user.id);
1518
- if (!current || current.passwordHash !== user.passwordHash || current.email !== user.email || current.totpSecret !== user.totpSecret) {
1519
- throw new ServiceError(
1520
- "UNAUTHORIZED",
1521
- "Your account changed. Sign in again."
1522
- );
1523
- }
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
1323
 
1546
1324
  // server/domain/permissions.ts
1547
1325
  function workspace(ctx) {
@@ -1584,289 +1362,50 @@ function authorizeRunRead(ctx, run, requestedScope = "runs:read") {
1584
1362
  }
1585
1363
  }
1586
1364
 
1587
- // server/router/procedures.ts
1588
- var rpc = initTRPC.context().create({
1589
- isDev: false,
1590
- errorFormatter({ shape, error }) {
1591
- return {
1592
- ...shape,
1593
- message: error.code === "INTERNAL_SERVER_ERROR" ? "Unable to complete this request." : shape.message
1594
- };
1595
- }
1596
- });
1597
- var router = rpc.router;
1598
- function procedureError(error) {
1599
- const cause = error instanceof TRPCError ? error.cause : error;
1600
- if (cause instanceof ServiceError) {
1601
- return new TRPCError({ code: cause.code, message: cause.message });
1602
- }
1603
- if (cause instanceof ZodError) {
1604
- return new TRPCError({ code: "BAD_REQUEST", message: "Invalid input." });
1605
- }
1606
- return error;
1607
- }
1608
- var publicProcedure = rpc.procedure.use(
1609
- async ({ ctx, type, path, next }) => {
1610
- try {
1611
- if (ctx.studioOrigin) {
1612
- const localSignIn = isLoopbackInstallation(ctx.origin) && [
1613
- "auth.setup",
1614
- "auth.setupStatus",
1615
- "auth.login",
1616
- "auth.mfaAuthenticate"
1617
- ].includes(path);
1618
- const bootstrap2 = localSignIn || path === "studio.discover" || path === "studio.exchange";
1619
- if (!bootstrap2 && (!ctx.studioExpiresAt || !ctx.sessionId || !ctx.user)) {
1620
- throw new ServiceError(
1621
- "UNAUTHORIZED",
1622
- "Reconnect to your OrgSDK installation."
1623
- );
1624
- }
1625
- if (!localSignIn && path.startsWith("auth.") && !["auth.session", "auth.browserSession", "auth.logout"].includes(path)) {
1626
- throw new ServiceError(
1627
- "FORBIDDEN",
1628
- "Manage your account on the installation."
1629
- );
1630
- }
1631
- } else {
1632
- checkClientRequest(ctx, type);
1633
- }
1634
- const result = await next({
1635
- ctx: { ...ctx, operationType: type, userId: ctx.user?.id ?? null }
1636
- });
1637
- if (!result.ok) {
1638
- throw result.error;
1639
- }
1640
- return result;
1641
- } catch (error) {
1642
- throw procedureError(error);
1643
- }
1644
- }
1645
- );
1646
- var workspaceAccess = rpc.middleware(({ ctx, next }) => {
1647
- const workspace2 = requireWorkspace(ctx);
1648
- const user = requireUser(ctx);
1649
- return next({
1650
- ctx: { ...ctx, workspace: workspace2, user, userId: user.id }
1651
- });
1652
- });
1653
- var protectedProcedure = publicProcedure.use(workspaceAccess);
1654
- var browserProcedure = publicProcedure.use(({ ctx, next }) => {
1655
- if (ctx.token || ctx.request.headers.has("authorization")) {
1656
- throw new TRPCError({
1657
- code: "FORBIDDEN",
1658
- message: "This operation requires a browser session."
1659
- });
1660
- }
1661
- return next();
1662
- });
1663
- var authenticatedBrowserProcedure = browserProcedure.use(
1664
- ({ ctx, next }) => {
1665
- const user = requireUser(ctx);
1666
- return next({ ctx: { ...ctx, user, userId: user.id } });
1667
- }
1668
- );
1669
- var freshBrowserProcedure = authenticatedBrowserProcedure.use(
1670
- ({ ctx, next }) => {
1671
- requireFresh(ctx);
1672
- return next();
1673
- }
1674
- );
1675
- var browserWorkspaceProcedure = browserProcedure.use(workspaceAccess);
1676
- var browserManagerProcedure = browserWorkspaceProcedure.use(
1677
- ({ ctx, next }) => {
1678
- requireManager(ctx);
1679
- return next();
1680
- }
1681
- );
1682
- var browserOwnerProcedure = browserWorkspaceProcedure.use(
1683
- ({ ctx, next }) => {
1684
- if (ctx.role !== "owner") {
1685
- throw new ServiceError(
1686
- "FORBIDDEN",
1687
- "Only the workspace owner can perform this operation."
1688
- );
1689
- }
1690
- return next({ ctx: { ...ctx, role: ctx.role } });
1691
- }
1692
- );
1693
- var browserSessionManagerProcedure = browserManagerProcedure.use(
1694
- ({ ctx, next }) => {
1695
- if (!ctx.sessionId) {
1696
- throw new ServiceError(
1697
- "FORBIDDEN",
1698
- "This operation requires a browser session."
1699
- );
1700
- }
1701
- return next({ ctx: { ...ctx, sessionId: ctx.sessionId } });
1702
- }
1703
- );
1704
- function scopedProcedure(required) {
1705
- const requiredScopes = typeof required === "string" ? [required] : [...required];
1706
- return protectedProcedure.use(({ ctx, next }) => {
1707
- for (const requiredScope of requiredScopes) {
1708
- scope(ctx, requiredScope);
1709
- }
1710
- return next();
1711
- });
1712
- }
1713
-
1714
- // server/router/actions/list.ts
1715
- import { and as and9, eq as eq10 } from "drizzle-orm";
1716
-
1717
- // server/actions/queries.ts
1718
- import { and as and8, eq as eq9, inArray as inArray3, or } from "drizzle-orm";
1719
- function actionGrant(ctx) {
1720
- const token = ctx.token;
1721
- if (!token) {
1722
- return void 0;
1723
- }
1724
- 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)
1728
- )
1729
- );
1730
- return or(
1731
- inArray3(actions.projectId, token.projects),
1732
- inArray3(actions.id, grantedActions)
1733
- );
1734
- }
1735
-
1736
- // server/actions/views.ts
1737
- function serializeAction(row) {
1738
- return {
1739
- id: row.id,
1740
- project: row.projectId,
1741
- name: row.name,
1742
- 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) {
1365
+ // server/repositories/plugins.ts
1366
+ import { and as and7, eq as eq7 } from "drizzle-orm";
1367
+ function pluginsRepository(context) {
1805
1368
  const workspaceId = requireWorkspace(context).id;
1806
1369
  const database = context.db;
1807
- const scoped = (id) => and11(eq12(actions.workspaceId, workspaceId), eq12(actions.id, id));
1370
+ const scoped = (id, filter) => and7(
1371
+ eq7(plugins.workspaceId, workspaceId),
1372
+ id === void 0 ? void 0 : eq7(plugins.id, id),
1373
+ filter
1374
+ );
1808
1375
  return {
1809
1376
  find(id) {
1810
- const row = database.select().from(actions).where(scoped(id)).get();
1377
+ const row = database.select().from(plugins).where(scoped(id)).get();
1811
1378
  if (!row) {
1812
1379
  throw new ServiceError("NOT_FOUND", "Not found.");
1813
1380
  }
1814
1381
  return row;
1815
1382
  },
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
- });
1383
+ list(filter) {
1384
+ return database.select().from(plugins).where(scoped(void 0, filter)).all();
1823
1385
  }
1824
1386
  };
1825
1387
  }
1826
1388
 
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";
1389
+ // server/plugins/shell-policy.ts
1390
+ import { and as and9, eq as eq9, gt as gt2, inArray as inArray3, sql } from "drizzle-orm";
1844
1391
 
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
- };
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();
1868
1404
  }
1869
1405
 
1406
+ // server/plugins/shell-policy.ts
1407
+ import { z as z13 } from "zod";
1408
+
1870
1409
  // server/shared/contracts.ts
1871
1410
  import { z as z12 } from "zod";
1872
1411
 
@@ -1996,39 +1535,678 @@ function validateContract(contract, value) {
1996
1535
  throw new ServiceError("BAD_REQUEST", "Invalid action schema.");
1997
1536
  }
1998
1537
  }
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;
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
+
1675
+ // server/router/procedures.ts
1676
+ import { initTRPC, TRPCError } from "@trpc/server";
1677
+ import { ZodError } from "zod";
1678
+
1679
+ // server/repositories/identity.ts
1680
+ import { and as and10, eq as eq10 } from "drizzle-orm";
1681
+
1682
+ // server/tokens/access-token.ts
1683
+ import { z as z15 } from "zod";
1684
+ var mcpTokenPrefix = "orgsdk_mcp_";
1685
+ var mcpAccessTokenSchema = z15.templateLiteral([
1686
+ mcpTokenPrefix,
1687
+ z15.string().regex(/[A-Za-z0-9_-]{43}/)
1688
+ ]);
1689
+ var issuedMcpAccessTokenSchema = z15.object({
1690
+ id: z15.uuid(),
1691
+ token: mcpAccessTokenSchema
1692
+ });
1693
+ function issueMcpAccessToken() {
1694
+ return `${mcpTokenPrefix}${randomSecret()}`;
1695
+ }
1696
+ function mcpAccessTokenDigest(token) {
1697
+ return digest(token.slice(mcpTokenPrefix.length));
1698
+ }
1699
+
1700
+ // server/repositories/identity.ts
1701
+ function identityRepository(database) {
1702
+ return {
1703
+ workspaceForHost(host) {
1704
+ return database.select().from(workspaces).where(eq10(workspaces.host, host)).get();
1705
+ },
1706
+ anyWorkspace() {
1707
+ return database.select().from(workspaces).get();
1708
+ },
1709
+ user(id) {
1710
+ return database.select().from(users).where(eq10(users.id, id)).get();
1711
+ },
1712
+ userByEmail(email) {
1713
+ return database.select().from(users).where(eq10(users.email, email)).get();
1714
+ },
1715
+ session(id) {
1716
+ return database.select().from(sessions).where(eq10(sessions.id, id)).get();
1717
+ },
1718
+ activeClientToken(workspaceId, token) {
1719
+ const tokenDigest = mcpAccessTokenDigest(token);
1720
+ return database.select().from(accessTokens).where(
1721
+ and10(
1722
+ eq10(accessTokens.digest, tokenDigest),
1723
+ eq10(accessTokens.workspaceId, workspaceId),
1724
+ eq10(accessTokens.revoked, false)
1725
+ )
1726
+ ).get();
1727
+ },
1728
+ membership(workspaceId, userId) {
1729
+ return database.select().from(memberships).where(
1730
+ and10(
1731
+ eq10(memberships.workspaceId, workspaceId),
1732
+ eq10(memberships.userId, userId)
1733
+ )
1734
+ ).get();
1735
+ }
1736
+ };
1737
+ }
1738
+
1739
+ // server/http/context.ts
1740
+ function cookies(request) {
1741
+ return new Map(
1742
+ (request.headers.get("cookie") ?? "").split(";").map((part) => {
1743
+ const index = part.indexOf("=");
1744
+ return index < 0 ? ["", ""] : [part.slice(0, index).trim(), part.slice(index + 1).trim()];
1745
+ })
1746
+ );
1747
+ }
1748
+ function setCookie(ctx, name, value, httpOnly = false, maxAge = 86400 * 14) {
1749
+ if (ctx.studioOrigin) {
1750
+ return;
1751
+ }
1752
+ const secure = new URL(ctx.request.url).protocol === "https:" ? "; Secure" : "";
1753
+ ctx.responseHeaders.append(
1754
+ "Set-Cookie",
1755
+ `${name}=${value}; Path=/; SameSite=Lax; Max-Age=${maxAge}${httpOnly ? "; HttpOnly" : ""}${secure}`
1756
+ );
1757
+ }
1758
+ function authenticateClientBearer(authorization, identities, workspaceId) {
1759
+ const bearer2 = authorization?.match(/^Bearer(?:[ \t]+(.*))?$/i);
1760
+ if (!bearer2) {
1761
+ return { token: null, clientTokenError: null };
1762
+ }
1763
+ const supplied = mcpAccessTokenSchema.safeParse(bearer2[1]);
1764
+ if (!supplied.success) {
1765
+ return {
1766
+ token: null,
1767
+ clientTokenError: `Expected an OrgSDK access token beginning with ${mcpTokenPrefix} followed by its 43-character secret.`
1768
+ };
1769
+ }
1770
+ const token = workspaceId === void 0 ? null : identities.activeClientToken(workspaceId, supplied.data) ?? null;
1771
+ return {
1772
+ token,
1773
+ clientTokenError: token ? null : "Invalid OrgSDK access token."
1774
+ };
1775
+ }
1776
+ function createContext(request, store) {
1777
+ const url = new URL(request.url);
1778
+ const hostname2 = url.hostname.toLowerCase();
1779
+ const identities = identityRepository(store.db);
1780
+ const workspace2 = identities.workspaceForHost(hostname2) ?? null;
1781
+ const origin = request.headers.get("origin");
1782
+ const studioOrigin = origin && url.pathname.startsWith("/trpc/") && origin === studioAudience(url.origin) ? origin : void 0;
1783
+ const studioToken = request.headers.get("x-orgsdk-studio-session");
1784
+ const grant = studioOrigin ? studioSession(store.db, url.origin, studioOrigin, studioToken) : void 0;
1785
+ if (studioOrigin && (request.headers.has("cookie") || request.headers.has("authorization"))) {
1786
+ throw new ServiceError(
1787
+ "FORBIDDEN",
1788
+ "Dashboard requests must use a paired session."
1789
+ );
1790
+ }
1791
+ const values2 = cookies(request);
1792
+ const secret = values2.get("sessionid");
1793
+ const localStudioId = studioOrigin && studioToken && isLoopbackInstallation(url.origin) ? studioLoginSessionId(url.origin, studioOrigin, studioToken) : void 0;
1794
+ const sessionId = grant?.sessionId ?? localStudioId ?? (secret ? digest(secret) : void 0);
1795
+ const session = sessionId ? identities.session(sessionId) : void 0;
1796
+ const validSession = session && session.expiresAt > Date.now() ? session : void 0;
1797
+ const authorization = request.headers.get("authorization");
1798
+ const { token, clientTokenError } = authenticateClientBearer(
1799
+ url.pathname.startsWith("/internal/") ? null : authorization,
1800
+ identities,
1801
+ workspace2?.id
1802
+ );
1803
+ const userId = authorization === null ? validSession?.userId : token?.actorId;
1804
+ const user = userId ? identities.user(userId) ?? null : null;
1805
+ const membership = user && workspace2 ? identities.membership(workspace2.id, user.id) : void 0;
1806
+ const responseHeaders = new Headers({ "Cache-Control": "no-store" });
1807
+ const ctx = {
1808
+ request,
1809
+ userId: user?.id ?? null,
1810
+ operationType: ["GET", "HEAD", "OPTIONS"].includes(request.method) ? "query" : "mutation",
1811
+ origin: url.origin,
1812
+ hostname: hostname2,
1813
+ db: store.db,
1814
+ secrets: store.secrets,
1815
+ user,
1816
+ workspace: workspace2,
1817
+ role: membership?.role ?? null,
1818
+ token,
1819
+ clientTokenError,
1820
+ responseHeaders,
1821
+ studioOrigin,
1822
+ studioExpiresAt: grant?.expiresAt ?? (localStudioId ? validSession?.expiresAt : void 0),
1823
+ sessionId: validSession?.id ?? null
1824
+ };
1825
+ if (!studioOrigin && !values2.get("csrftoken")) {
1826
+ setCookie(ctx, "csrftoken", randomSecret());
1827
+ }
1828
+ return ctx;
1829
+ }
1830
+ function checkClientRequest(ctx, operationType = ctx.operationType) {
1831
+ if (ctx.clientTokenError) {
1832
+ throw new ServiceError("UNAUTHORIZED", ctx.clientTokenError);
1833
+ }
1834
+ if (operationType !== "mutation" || ctx.token) {
1835
+ return;
1836
+ }
1837
+ const origin = ctx.request.headers.get("origin");
1838
+ if (origin && origin !== new URL(ctx.request.url).origin) {
1839
+ throw new ServiceError("FORBIDDEN", "Invalid origin.");
1840
+ }
1841
+ const cookie = cookies(ctx.request).get("csrftoken");
1842
+ const header = ctx.request.headers.get("x-csrftoken");
1843
+ if (!cookie || !header || cookie !== header) {
1844
+ throw new ServiceError("FORBIDDEN", "CSRF verification failed.");
1845
+ }
1846
+ }
1847
+
1848
+ // server/auth/sessions.ts
1849
+ import { eq as eq11 } from "drizzle-orm";
1850
+ function rotateSession(ctx, userId, pendingUserId = null, guard, mutation) {
1851
+ const secret = randomSecret();
1852
+ const id = ctx.studioOrigin ? studioLoginSessionId(ctx.origin, ctx.studioOrigin, secret) : digest(secret);
1853
+ const time = Date.now();
1854
+ const expiresAt = time + (pendingUserId ? 5 * 6e4 : 14 * 864e5);
1855
+ inTransaction(ctx, (ctx2) => {
1856
+ guard?.(ctx2);
1857
+ if (ctx2.studioOrigin && userId && (!ctx2.workspace || !identityRepository(ctx2.db).membership(ctx2.workspace.id, userId))) {
1858
+ throw new ServiceError(
1859
+ "FORBIDDEN",
1860
+ "You are not a member of this workspace."
1861
+ );
1862
+ }
1863
+ mutation?.(ctx2);
1864
+ if (ctx2.sessionId) {
1865
+ ctx2.db.delete(sessions).where(eq11(sessions.id, ctx2.sessionId)).run();
1866
+ }
1867
+ ctx2.db.insert(sessions).values({
1868
+ id,
1869
+ userId,
1870
+ pendingUserId,
1871
+ workspaceId: ctx2.workspace?.id ?? null,
1872
+ expiresAt,
1873
+ reauthenticatedAt: userId ? time : null
1874
+ }).run();
1875
+ });
1876
+ ctx.sessionId = id;
1877
+ ctx.sessionChanged(secret);
1878
+ if (ctx.studioOrigin) {
1879
+ return { token: secret, expiresAt };
1880
+ }
1881
+ return null;
1882
+ }
1883
+ function requireFresh(ctx) {
1884
+ requireUser(ctx);
1885
+ const session = ctx.sessionId ? identityRepository(ctx.db).session(ctx.sessionId) : void 0;
1886
+ if (!session?.reauthenticatedAt || session.userId !== ctx.user?.id || session.expiresAt <= Date.now() || session.reauthenticatedAt < Date.now() - 3e5) {
1887
+ throw new ServiceError(
1888
+ "UNAUTHORIZED",
1889
+ "Confirm your identity to continue."
1890
+ );
1891
+ }
1892
+ }
1893
+ function assertCurrentUser(ctx, user, withSession = true) {
1894
+ const current = identityRepository(ctx.db).user(user.id);
1895
+ if (!current || current.passwordHash !== user.passwordHash || current.email !== user.email || current.totpSecret !== user.totpSecret) {
1896
+ throw new ServiceError(
1897
+ "UNAUTHORIZED",
1898
+ "Your account changed. Sign in again."
1899
+ );
1900
+ }
1901
+ if (withSession) {
1902
+ requireCurrentSession(ctx, user.id);
1903
+ }
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
+ );
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
+ });
1921
+ }
1922
+
1923
+ // server/router/procedures.ts
1924
+ var rpc = initTRPC.context().create({
1925
+ isDev: false,
1926
+ errorFormatter({ shape, error }) {
1927
+ return {
1928
+ ...shape,
1929
+ message: error.code === "INTERNAL_SERVER_ERROR" ? "Unable to complete this request." : shape.message
1930
+ };
1931
+ }
1932
+ });
1933
+ var router = rpc.router;
1934
+ function procedureError(error) {
1935
+ const cause = error instanceof TRPCError ? error.cause : error;
1936
+ if (cause instanceof ServiceError) {
1937
+ return new TRPCError({ code: cause.code, message: cause.message });
1938
+ }
1939
+ if (cause instanceof ZodError) {
1940
+ return new TRPCError({ code: "BAD_REQUEST", message: "Invalid input." });
1941
+ }
1942
+ return error;
1943
+ }
1944
+ var publicProcedure = rpc.procedure.use(
1945
+ async ({ ctx, type, path, next }) => {
1946
+ try {
1947
+ if (ctx.studioOrigin) {
1948
+ const localSignIn = isLoopbackInstallation(ctx.origin) && [
1949
+ "auth.setup",
1950
+ "auth.setupStatus",
1951
+ "auth.login",
1952
+ "auth.mfaAuthenticate"
1953
+ ].includes(path);
1954
+ const bootstrap2 = localSignIn || path === "studio.discover" || path === "studio.exchange";
1955
+ if (!bootstrap2 && (!ctx.studioExpiresAt || !ctx.sessionId || !ctx.user)) {
1956
+ throw new ServiceError(
1957
+ "UNAUTHORIZED",
1958
+ "Reconnect to your OrgSDK installation."
1959
+ );
1960
+ }
1961
+ if (!localSignIn && path.startsWith("auth.") && !["auth.session", "auth.browserSession", "auth.logout"].includes(path)) {
1962
+ throw new ServiceError(
1963
+ "FORBIDDEN",
1964
+ "Manage your account on the installation."
1965
+ );
1966
+ }
1967
+ } else {
1968
+ checkClientRequest(ctx, type);
1969
+ }
1970
+ const result = await next({
1971
+ ctx: { ...ctx, operationType: type, userId: ctx.user?.id ?? null }
1972
+ });
1973
+ if (!result.ok) {
1974
+ throw result.error;
1975
+ }
1976
+ return result;
1977
+ } catch (error) {
1978
+ throw procedureError(error);
1979
+ }
1980
+ }
1981
+ );
1982
+ var workspaceAccess = rpc.middleware(({ ctx, next }) => {
1983
+ const workspace2 = requireWorkspace(ctx);
1984
+ const user = requireUser(ctx);
1985
+ return next({
1986
+ ctx: { ...ctx, workspace: workspace2, user, userId: user.id }
1987
+ });
1988
+ });
1989
+ var protectedProcedure = publicProcedure.use(workspaceAccess);
1990
+ var browserProcedure = publicProcedure.use(({ ctx, next }) => {
1991
+ if (ctx.token || ctx.request.headers.has("authorization")) {
1992
+ throw new TRPCError({
1993
+ code: "FORBIDDEN",
1994
+ message: "This operation requires a browser session."
1995
+ });
1996
+ }
1997
+ return next();
1998
+ });
1999
+ var authenticatedBrowserProcedure = browserProcedure.use(
2000
+ ({ ctx, next }) => {
2001
+ const user = requireUser(ctx);
2002
+ return next({ ctx: { ...ctx, user, userId: user.id } });
2003
+ }
2004
+ );
2005
+ var freshBrowserProcedure = authenticatedBrowserProcedure.use(
2006
+ ({ ctx, next }) => {
2007
+ requireFresh(ctx);
2008
+ return next();
2009
+ }
2010
+ );
2011
+ var browserWorkspaceProcedure = browserProcedure.use(workspaceAccess);
2012
+ var browserManagerProcedure = browserWorkspaceProcedure.use(
2013
+ ({ ctx, next }) => {
2014
+ requireManager(ctx);
2015
+ return next();
2016
+ }
2017
+ );
2018
+ var browserOwnerProcedure = browserWorkspaceProcedure.use(
2019
+ ({ ctx, next }) => {
2020
+ if (ctx.role !== "owner") {
2021
+ throw new ServiceError(
2022
+ "FORBIDDEN",
2023
+ "Only the workspace owner can perform this operation."
2024
+ );
2025
+ }
2026
+ return next({ ctx: { ...ctx, role: ctx.role } });
2027
+ }
2028
+ );
2029
+ var browserSessionManagerProcedure = browserManagerProcedure.use(
2030
+ ({ ctx, next }) => {
2031
+ if (!ctx.sessionId) {
2032
+ throw new ServiceError(
2033
+ "FORBIDDEN",
2034
+ "This operation requires a browser session."
2035
+ );
2036
+ }
2037
+ return next({ ctx: { ...ctx, sessionId: ctx.sessionId } });
2038
+ }
2039
+ );
2040
+ function scopedProcedure(required) {
2041
+ const requiredScopes = typeof required === "string" ? [required] : [...required];
2042
+ return protectedProcedure.use(({ ctx, next }) => {
2043
+ for (const requiredScope of requiredScopes) {
2044
+ scope(ctx, requiredScope);
2045
+ }
2046
+ return next();
2047
+ });
2048
+ }
2049
+ function scopedManagerProcedure(required) {
2050
+ return scopedProcedure(required).use(({ ctx, next }) => {
2051
+ requireManager(ctx);
2052
+ return next();
2053
+ });
2054
+ }
2055
+
2056
+ // server/router/actions/list.ts
2057
+ import { and as and12, eq as eq13 } from "drizzle-orm";
2058
+
2059
+ // server/actions/queries.ts
2060
+ import { and as and11, eq as eq12, inArray as inArray4, or } from "drizzle-orm";
2061
+ function actionGrant(ctx) {
2062
+ const token = ctx.token;
2063
+ if (!token) {
2064
+ return void 0;
2065
+ }
2066
+ const grantedActions = ctx.db.select({ id: actionVersions.actionId }).from(actionVersions).where(
2067
+ and11(
2068
+ eq12(actionVersions.workspaceId, workspace(ctx)),
2069
+ inArray4(actionVersions.id, token.actionVersions)
2070
+ )
2071
+ );
2072
+ return or(
2073
+ inArray4(actions.projectId, token.projects),
2074
+ inArray4(actions.id, grantedActions)
2075
+ );
2076
+ }
2077
+
2078
+ // server/actions/views.ts
2079
+ function serializeAction(row) {
2080
+ return {
2081
+ id: row.id,
2082
+ project: row.projectId,
2083
+ name: row.name,
2084
+ description: row.description,
2085
+ enabled: row.enabled
2086
+ };
2011
2087
  }
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.");
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
+ };
2100
+ }
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
+ };
2110
+ }
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();
@@ -3053,43 +3157,19 @@ function approvalsRepository(context) {
3053
3157
  if (!row) {
3054
3158
  throw new ServiceError("NOT_FOUND", "Not found.");
3055
3159
  }
3056
- recordAudit(context2, "approval", id, "updated");
3057
- return row;
3058
- });
3059
- }
3060
- };
3061
- }
3062
-
3063
- // server/router/approvals/get.ts
3064
- var getProcedure2 = browserWorkspaceProcedure.input(approvalIdSchema).query(({ ctx, input: input2 }) => {
3065
- const id = input2.id;
3066
- return approvalView(approvalsRepository(ctx).find(id));
3067
- });
3068
-
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();
3160
+ recordAudit(context2, "approval", id, "updated");
3161
+ return row;
3162
+ });
3089
3163
  }
3090
3164
  };
3091
3165
  }
3092
3166
 
3167
+ // server/router/approvals/get.ts
3168
+ var getProcedure2 = browserWorkspaceProcedure.input(approvalIdSchema).query(({ ctx, input: input2 }) => {
3169
+ const id = input2.id;
3170
+ return approvalView(approvalsRepository(ctx).find(id));
3171
+ });
3172
+
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,7 +6327,7 @@ var exchange = publicProcedure.input(
6198
6327
  var studioRouter = router({ approve, discover, exchange });
6199
6328
 
6200
6329
  // server/platform/installation-update.ts
6201
- import { and as and55, count, eq as eq73, 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();
6204
6333
  var blockingRunStatuses = ["running", "waiting_approval"];
@@ -6210,8 +6339,8 @@ function pendingUpdate(db) {
6210
6339
  }
6211
6340
  function updateBlockers(db, workspaceId) {
6212
6341
  const blockers = db.select({ status: runs.status, total: count() }).from(runs).where(
6213
- and55(
6214
- eq73(runs.workspaceId, workspaceId),
6342
+ and56(
6343
+ eq75(runs.workspaceId, workspaceId),
6215
6344
  inArray9(runs.status, blockingRunStatuses)
6216
6345
  )
6217
6346
  ).groupBy(runs.status).all();
@@ -6242,8 +6371,8 @@ function drainForUpdate(db, version2) {
6242
6371
  }
6243
6372
 
6244
6373
  // server/platform/stable-release.ts
6245
- import { z as z38 } from "zod";
6246
- 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})$/);
6247
6376
  function newerStable(candidate, installed) {
6248
6377
  if (!stableVersion.safeParse(candidate).success || !stableVersion.safeParse(installed).success) {
6249
6378
  return false;
@@ -6257,8 +6386,8 @@ function newerStable(candidate, installed) {
6257
6386
  }
6258
6387
  return false;
6259
6388
  }
6260
- var release = z38.object({
6261
- name: z38.literal("@orgsdk/cli"),
6389
+ var release = z40.object({
6390
+ name: z40.literal("@orgsdk/cli"),
6262
6391
  version: stableVersion
6263
6392
  });
6264
6393
  var cached;
@@ -6284,7 +6413,7 @@ function latestStable() {
6284
6413
  }
6285
6414
 
6286
6415
  // package.json
6287
- var version = "2.4.1";
6416
+ var version = "2.5.1";
6288
6417
 
6289
6418
  // server/router/system/update-status.ts
6290
6419
  var updateStatus = browserWorkspaceProcedure.query(async ({ ctx }) => {
@@ -6303,8 +6432,8 @@ var updateStatus = browserWorkspaceProcedure.query(async ({ ctx }) => {
6303
6432
  });
6304
6433
 
6305
6434
  // server/router/system/request-update.ts
6306
- import { z as z39 } from "zod";
6307
- 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 }) => {
6308
6437
  if (!canManageUpdate(ctx)) {
6309
6438
  throw new ServiceError(
6310
6439
  "FORBIDDEN",
@@ -6348,7 +6477,7 @@ var systemRouter = router({
6348
6477
  });
6349
6478
 
6350
6479
  // server/router/tables/list.ts
6351
- import { eq as eq74 } from "drizzle-orm";
6480
+ import { eq as eq76 } from "drizzle-orm";
6352
6481
 
6353
6482
  // server/tables/views.ts
6354
6483
  function standard(row) {
@@ -6373,48 +6502,48 @@ function rowView(row) {
6373
6502
 
6374
6503
  // server/router/tables/list.ts
6375
6504
  var listProcedure12 = browserWorkspaceProcedure.query(({ ctx }) => {
6376
- const records = ctx.db.select().from(workspaceTables).where(eq74(workspaceTables.workspaceId, ctx.workspace.id)).all();
6505
+ const records = ctx.db.select().from(workspaceTables).where(eq76(workspaceTables.workspaceId, ctx.workspace.id)).all();
6377
6506
  return page(records.map((record) => standard(record)));
6378
6507
  });
6379
6508
 
6380
6509
  // server/tables/schemas.ts
6381
- import { z as z40 } from "zod";
6382
- var identifier4 = z40.uuid();
6383
- var revision = z40.number().int().positive();
6384
- var columns = z40.array(
6385
- z40.strictObject({
6386
- key: z40.string(),
6387
- type: z40.enum(["text", "number", "boolean", "date"]),
6388
- 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()
6389
6518
  })
6390
6519
  );
6391
- var values = z40.record(z40.string(), z40.json());
6392
- var tableIdSchema = z40.strictObject({ id: identifier4 });
6393
- var createTableSchema = z40.strictObject({ name: z40.string(), columns });
6394
- 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({
6395
6524
  id: identifier4,
6396
6525
  revision,
6397
- name: z40.string().optional(),
6526
+ name: z42.string().optional(),
6398
6527
  columns: columns.optional()
6399
6528
  });
6400
- var deleteTableSchema = z40.strictObject({ id: identifier4, revision });
6401
- var tableRowSchema = z40.strictObject({
6529
+ var deleteTableSchema = z42.strictObject({ id: identifier4, revision });
6530
+ var tableRowSchema = z42.strictObject({
6402
6531
  id: identifier4,
6403
6532
  rowId: identifier4
6404
6533
  });
6405
- var createRowSchema = z40.strictObject({
6534
+ var createRowSchema = z42.strictObject({
6406
6535
  id: identifier4,
6407
6536
  table_revision: revision,
6408
6537
  values
6409
6538
  });
6410
- var updateRowSchema = z40.strictObject({
6539
+ var updateRowSchema = z42.strictObject({
6411
6540
  id: identifier4,
6412
6541
  rowId: identifier4,
6413
6542
  table_revision: revision,
6414
6543
  revision,
6415
6544
  values
6416
6545
  });
6417
- var deleteRowSchema = z40.strictObject({
6546
+ var deleteRowSchema = z42.strictObject({
6418
6547
  id: identifier4,
6419
6548
  rowId: identifier4,
6420
6549
  revision
@@ -6440,15 +6569,15 @@ var createProcedure9 = browserManagerProcedure.input(createTableSchema).mutation
6440
6569
  );
6441
6570
 
6442
6571
  // server/router/tables/update.ts
6443
- import { and as and57, eq as eq76 } from "drizzle-orm";
6572
+ import { and as and58, eq as eq78 } from "drizzle-orm";
6444
6573
 
6445
6574
  // server/tables/queries.ts
6446
- import { and as and56, eq as eq75 } from "drizzle-orm";
6575
+ import { and as and57, eq as eq77 } from "drizzle-orm";
6447
6576
  function rowsForTable(database, workspaceId, tableId2) {
6448
6577
  return database.select().from(tableRows).where(
6449
- and56(
6450
- eq75(tableRows.workspaceId, workspaceId),
6451
- eq75(tableRows.tableId, tableId2)
6578
+ and57(
6579
+ eq77(tableRows.workspaceId, workspaceId),
6580
+ eq77(tableRows.tableId, tableId2)
6452
6581
  )
6453
6582
  ).all();
6454
6583
  }
@@ -6469,9 +6598,9 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
6469
6598
  revision: current.revision + 1,
6470
6599
  updatedAt: now()
6471
6600
  }).where(
6472
- and57(
6473
- eq76(workspaceTables.workspaceId, ctx2.workspace.id),
6474
- eq76(workspaceTables.id, input2.id)
6601
+ and58(
6602
+ eq78(workspaceTables.workspaceId, ctx2.workspace.id),
6603
+ eq78(workspaceTables.id, input2.id)
6475
6604
  )
6476
6605
  ).returning().get();
6477
6606
  if (!table) {
@@ -6484,14 +6613,14 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
6484
6613
  });
6485
6614
 
6486
6615
  // server/router/tables/delete.ts
6487
- import { and as and59, eq as eq78 } from "drizzle-orm";
6616
+ import { and as and60, eq as eq80 } from "drizzle-orm";
6488
6617
 
6489
6618
  // server/repositories/table-rows.ts
6490
- import { and as and58, eq as eq77 } from "drizzle-orm";
6619
+ import { and as and59, eq as eq79 } from "drizzle-orm";
6491
6620
  function removeTableRow(context, id) {
6492
6621
  const workspaceId = requireWorkspace(context).id;
6493
6622
  inTransaction(context, (transaction) => {
6494
- const deleted = transaction.db.delete(tableRows).where(and58(eq77(tableRows.workspaceId, workspaceId), eq77(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();
6495
6624
  if (deleted) {
6496
6625
  recordAudit(transaction, "row", id, "deleted");
6497
6626
  }
@@ -6519,9 +6648,9 @@ var deleteProcedure6 = browserManagerProcedure.input(deleteTableSchema).mutation
6519
6648
  });
6520
6649
  }
6521
6650
  const deleted = ctx2.db.delete(workspaceTables).where(
6522
- and59(
6523
- eq78(workspaceTables.workspaceId, ctx2.workspace.id),
6524
- eq78(workspaceTables.id, input2.id)
6651
+ and60(
6652
+ eq80(workspaceTables.workspaceId, ctx2.workspace.id),
6653
+ eq80(workspaceTables.id, input2.id)
6525
6654
  )
6526
6655
  ).returning({ id: workspaceTables.id }).get();
6527
6656
  if (deleted) {
@@ -6538,13 +6667,13 @@ var listRowsProcedure = browserWorkspaceProcedure.input(tableIdSchema).query(({
6538
6667
  });
6539
6668
 
6540
6669
  // server/tables/access.ts
6541
- import { and as and60, eq as eq79 } from "drizzle-orm";
6670
+ import { and as and61, eq as eq81 } from "drizzle-orm";
6542
6671
  function rowInTable(database, workspaceId, tableId2, rowId) {
6543
6672
  const row = database.select().from(tableRows).where(
6544
- and60(
6545
- eq79(tableRows.workspaceId, workspaceId),
6546
- eq79(tableRows.tableId, tableId2),
6547
- eq79(tableRows.id, rowId)
6673
+ and61(
6674
+ eq81(tableRows.workspaceId, workspaceId),
6675
+ eq81(tableRows.tableId, tableId2),
6676
+ eq81(tableRows.id, rowId)
6548
6677
  )
6549
6678
  ).get();
6550
6679
  if (!row) {
@@ -6579,7 +6708,7 @@ var createRowProcedure = browserWorkspaceProcedure.input(createRowSchema).mutati
6579
6708
  });
6580
6709
 
6581
6710
  // server/router/tables/update-row.ts
6582
- import { and as and61, eq as eq80 } from "drizzle-orm";
6711
+ import { and as and62, eq as eq82 } from "drizzle-orm";
6583
6712
  var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutation(({ ctx, input: input2 }) => {
6584
6713
  return rowView(
6585
6714
  inTransaction(ctx, (ctx2) => {
@@ -6593,9 +6722,9 @@ var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutati
6593
6722
  revision: row.revision + 1,
6594
6723
  updatedAt: now()
6595
6724
  }).where(
6596
- and61(
6597
- eq80(tableRows.workspaceId, ctx2.workspace.id),
6598
- eq80(tableRows.id, input2.rowId)
6725
+ and62(
6726
+ eq82(tableRows.workspaceId, ctx2.workspace.id),
6727
+ eq82(tableRows.id, input2.rowId)
6599
6728
  )
6600
6729
  ).returning().get();
6601
6730
  if (!updatedRow) {
@@ -6635,7 +6764,7 @@ var tablesRouter = router({
6635
6764
  });
6636
6765
 
6637
6766
  // server/router/tokens/list.ts
6638
- import { eq as eq81 } from "drizzle-orm";
6767
+ import { eq as eq83 } from "drizzle-orm";
6639
6768
 
6640
6769
  // server/tokens/views.ts
6641
6770
  function tokenView(row) {
@@ -6663,18 +6792,18 @@ function tokenView(row) {
6663
6792
 
6664
6793
  // server/router/tokens/list.ts
6665
6794
  var listProcedure13 = browserManagerProcedure.query(({ ctx }) => {
6666
- const records = ctx.db.select().from(accessTokens).where(eq81(accessTokens.workspaceId, ctx.workspace.id)).all();
6795
+ const records = ctx.db.select().from(accessTokens).where(eq83(accessTokens.workspaceId, ctx.workspace.id)).all();
6667
6796
  return page(records.map((record) => tokenView(record)));
6668
6797
  });
6669
6798
 
6670
6799
  // server/router/tokens/get.ts
6671
- import { and as and62, eq as eq82 } from "drizzle-orm";
6672
- import { z as z41 } from "zod";
6673
- 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 }) => {
6674
6803
  const token = ctx.db.select().from(accessTokens).where(
6675
- and62(
6676
- eq82(accessTokens.workspaceId, ctx.workspace.id),
6677
- eq82(accessTokens.id, input2.id)
6804
+ and63(
6805
+ eq84(accessTokens.workspaceId, ctx.workspace.id),
6806
+ eq84(accessTokens.id, input2.id)
6678
6807
  )
6679
6808
  ).get();
6680
6809
  if (!token) {
@@ -6684,21 +6813,22 @@ var getProcedure14 = browserManagerProcedure.input(z41.strictObject({ id: z41.uu
6684
6813
  });
6685
6814
 
6686
6815
  // server/tokens/schemas.ts
6687
- import { z as z42 } from "zod";
6688
- var clientScopes = z42.enum([
6816
+ import { z as z44 } from "zod";
6817
+ var clientScopes = z44.enum([
6689
6818
  "catalog:read",
6690
6819
  "code:execute",
6691
6820
  "actions:write",
6692
6821
  "actions:run",
6693
6822
  "actions:test",
6694
6823
  "runs:read",
6695
- "runs:cancel"
6824
+ "runs:cancel",
6825
+ "plugins:configure"
6696
6826
  ]);
6697
- var tokenCreateSchema = z42.object({
6698
- name: z42.string().trim().min(1).max(100),
6699
- scopes: z42.array(clientScopes).min(1),
6700
- projects: z42.array(z42.uuid()).default([]),
6701
- 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([])
6702
6832
  }).strict();
6703
6833
 
6704
6834
  // server/router/tokens/create.ts
@@ -6737,14 +6867,14 @@ var createProcedure10 = browserManagerProcedure.input(tokenCreateSchema).output(
6737
6867
  });
6738
6868
 
6739
6869
  // server/router/tokens/revoke.ts
6740
- import { and as and63, eq as eq83 } from "drizzle-orm";
6741
- import { z as z43 } from "zod";
6742
- 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 }) => {
6743
6873
  return inTransaction(ctx, (ctx2) => {
6744
6874
  const token = ctx2.db.update(accessTokens).set({ revoked: true, updatedAt: now() }).where(
6745
- and63(
6746
- eq83(accessTokens.workspaceId, ctx2.workspace.id),
6747
- eq83(accessTokens.id, input2.id)
6875
+ and64(
6876
+ eq85(accessTokens.workspaceId, ctx2.workspace.id),
6877
+ eq85(accessTokens.id, input2.id)
6748
6878
  )
6749
6879
  ).returning().get();
6750
6880
  if (!token) {
@@ -6787,20 +6917,20 @@ var usersRouter = router({
6787
6917
  });
6788
6918
 
6789
6919
  // server/router/webhooks/list.ts
6790
- import { eq as eq85 } from "drizzle-orm";
6920
+ import { eq as eq87 } from "drizzle-orm";
6791
6921
 
6792
6922
  // server/automations/webhook-view.ts
6793
- import { desc as desc5, eq as eq84 } from "drizzle-orm";
6794
- import { and as and64 } from "drizzle-orm";
6923
+ import { desc as desc5, eq as eq86 } from "drizzle-orm";
6924
+ import { and as and65 } from "drizzle-orm";
6795
6925
  function webhookView(context, webhook) {
6796
6926
  const version2 = actionVersionsRepository(context).find(
6797
6927
  webhook.actionVersionId
6798
6928
  );
6799
6929
  const action = actionsRepository(context).find(version2.actionId);
6800
6930
  const deliveries = context.db.select().from(webhookDeliveries).where(
6801
- and64(
6802
- eq84(webhookDeliveries.workspaceId, workspace(context)),
6803
- eq84(webhookDeliveries.webhookId, webhook.id)
6931
+ and65(
6932
+ eq86(webhookDeliveries.workspaceId, workspace(context)),
6933
+ eq86(webhookDeliveries.webhookId, webhook.id)
6804
6934
  )
6805
6935
  ).orderBy(desc5(webhookDeliveries.createdAt)).limit(20).all();
6806
6936
  return {
@@ -6829,19 +6959,19 @@ function webhookView(context, webhook) {
6829
6959
 
6830
6960
  // server/router/webhooks/list.ts
6831
6961
  var listProcedure14 = browserWorkspaceProcedure.query(({ ctx }) => {
6832
- const records = ctx.db.select().from(webhooks).where(eq85(webhooks.workspaceId, ctx.workspace.id)).all();
6962
+ const records = ctx.db.select().from(webhooks).where(eq87(webhooks.workspaceId, ctx.workspace.id)).all();
6833
6963
  return page(records.map((record) => webhookView(ctx, record)));
6834
6964
  });
6835
6965
 
6836
6966
  // server/router/webhooks/get.ts
6837
- import { z as z44 } from "zod";
6967
+ import { z as z46 } from "zod";
6838
6968
 
6839
6969
  // server/repositories/webhooks.ts
6840
- import { and as and65, eq as eq86 } from "drizzle-orm";
6970
+ import { and as and66, eq as eq88 } from "drizzle-orm";
6841
6971
  function webhooksRepository(context) {
6842
6972
  const workspaceId = requireWorkspace(context).id;
6843
6973
  const database = context.db;
6844
- const scoped = (id) => and65(eq86(webhooks.workspaceId, workspaceId), eq86(webhooks.id, id));
6974
+ const scoped = (id) => and66(eq88(webhooks.workspaceId, workspaceId), eq88(webhooks.id, id));
6845
6975
  return {
6846
6976
  find(id) {
6847
6977
  const row = database.select().from(webhooks).where(scoped(id)).get();
@@ -6865,22 +6995,22 @@ function webhooksRepository(context) {
6865
6995
  }
6866
6996
 
6867
6997
  // server/router/webhooks/get.ts
6868
- 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 }) => {
6869
6999
  const id = input2.id;
6870
7000
  return webhookView(context, webhooksRepository(context).find(id));
6871
7001
  });
6872
7002
 
6873
7003
  // server/automations/webhook-schemas.ts
6874
- import { z as z45 } from "zod";
6875
- var webhookCreateSchema = z45.object({
6876
- name: z45.string().trim().min(1).max(100),
6877
- action: z45.uuid(),
6878
- 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()
6879
7009
  }).strict();
6880
- var webhookUpdateSchema = z45.object({
6881
- id: z45.uuid(),
6882
- name: z45.string().trim().min(1).max(100).optional(),
6883
- 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()
6884
7014
  }).strict();
6885
7015
 
6886
7016
  // server/router/webhooks/create.ts
@@ -6925,8 +7055,8 @@ var updateProcedure9 = browserManagerProcedure.input(webhookUpdateSchema).mutati
6925
7055
  });
6926
7056
 
6927
7057
  // server/router/webhooks/rotate.ts
6928
- import { z as z46 } from "zod";
6929
- 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 }) => {
6930
7060
  const id = input2.id;
6931
7061
  return inTransaction(context, (context2) => {
6932
7062
  const secret = randomSecret();
@@ -6956,7 +7086,7 @@ var listProcedure15 = browserWorkspaceProcedure.query(({ ctx }) => {
6956
7086
  });
6957
7087
 
6958
7088
  // server/router/workspace/current.ts
6959
- import { eq as eq87 } from "drizzle-orm";
7089
+ import { eq as eq89 } from "drizzle-orm";
6960
7090
 
6961
7091
  // server/workspaces/views.ts
6962
7092
  var serializeInvite = (invitation) => ({
@@ -6975,34 +7105,34 @@ var currentProcedure = browserWorkspaceProcedure.query(({ ctx }) => {
6975
7105
  workspace: { id: workspace2.id, name: workspace2.name },
6976
7106
  role: ctx.role,
6977
7107
  members: memberQuery(ctx.db, workspace2.id).all(),
6978
- invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(eq87(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) : []
6979
7109
  };
6980
7110
  });
6981
7111
 
6982
7112
  // server/router/workspace/update.ts
6983
- import { eq as eq88 } from "drizzle-orm";
7113
+ import { eq as eq90 } from "drizzle-orm";
6984
7114
 
6985
7115
  // server/workspaces/schemas.ts
6986
- import { z as z47 } from "zod";
6987
- var membershipIdSchema = z47.strictObject({
6988
- id: z47.number().int().positive()
7116
+ import { z as z49 } from "zod";
7117
+ var membershipIdSchema = z49.strictObject({
7118
+ id: z49.number().int().positive()
6989
7119
  });
6990
- var workspaceNameSchema = z47.strictObject({
6991
- name: z47.string().trim().min(1).max(100)
7120
+ var workspaceNameSchema = z49.strictObject({
7121
+ name: z49.string().trim().min(1).max(100)
6992
7122
  });
6993
- var roleSchema = z47.enum(["admin", "member"]);
7123
+ var roleSchema = z49.enum(["admin", "member"]);
6994
7124
  var memberUpdateSchema = membershipIdSchema.extend({
6995
7125
  role: roleSchema
6996
7126
  });
6997
- var ownershipSchema = z47.strictObject({
6998
- membership_id: z47.number().int().positive()
7127
+ var ownershipSchema = z49.strictObject({
7128
+ membership_id: z49.number().int().positive()
6999
7129
  });
7000
- var invitationSchema = z47.strictObject({
7130
+ var invitationSchema = z49.strictObject({
7001
7131
  email: emailSchema,
7002
7132
  role: roleSchema
7003
7133
  });
7004
- var invitationTokenSchema = z47.strictObject({
7005
- token: z47.string().min(1)
7134
+ var invitationTokenSchema = z49.strictObject({
7135
+ token: z49.string().min(1)
7006
7136
  });
7007
7137
 
7008
7138
  // server/router/workspace/update.ts
@@ -7019,7 +7149,7 @@ var updateProcedure10 = browserManagerProcedure.input(workspaceNameSchema).mutat
7019
7149
  "Only workspace owners and admins can manage this workspace."
7020
7150
  );
7021
7151
  }
7022
- const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(eq88(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();
7023
7153
  return { id: updated.id, name: updated.name };
7024
7154
  });
7025
7155
  });
@@ -7047,13 +7177,13 @@ import { randomUUID as randomUUID5 } from "node:crypto";
7047
7177
  import nodemailer from "nodemailer";
7048
7178
 
7049
7179
  // server/repositories/mail-outbox.ts
7050
- import { and as and66, asc as asc6, eq as eq89, 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";
7051
7181
  function enqueueMail(store, message) {
7052
7182
  store.db.insert(mailOutbox).values({ ...message, nextAttempt: Date.now() }).run();
7053
7183
  }
7054
7184
  function revokeUnsentMail(store, id) {
7055
- const unsent = and66(
7056
- eq89(mailOutbox.id, id),
7185
+ const unsent = and67(
7186
+ eq91(mailOutbox.id, id),
7057
7187
  isNull(mailOutbox.sentAt),
7058
7188
  isNull(mailOutbox.leaseUntil)
7059
7189
  );
@@ -7065,7 +7195,7 @@ function claimMail(store, time) {
7065
7195
  isNull(mailOutbox.leaseUntil),
7066
7196
  lt3(mailOutbox.leaseUntil, time)
7067
7197
  );
7068
- const due = and66(
7198
+ const due = and67(
7069
7199
  isNull(mailOutbox.sentAt),
7070
7200
  lte(mailOutbox.nextAttempt, time),
7071
7201
  availableLease
@@ -7076,18 +7206,18 @@ function claimMail(store, time) {
7076
7206
  }
7077
7207
  if (row.id.startsWith("invitation:")) {
7078
7208
  const id = Number(row.id.slice("invitation:".length));
7079
- const invitation = store2.db.select().from(invitations).where(eq89(invitations.id, id)).get();
7209
+ const invitation = store2.db.select().from(invitations).where(eq91(invitations.id, id)).get();
7080
7210
  if (!invitation || invitation.acceptedAt || invitation.revokedAt || invitation.expiresAt <= new Date(time).toISOString()) {
7081
- store2.db.delete(mailOutbox).where(eq89(mailOutbox.id, row.id)).run();
7211
+ store2.db.delete(mailOutbox).where(eq91(mailOutbox.id, row.id)).run();
7082
7212
  return;
7083
7213
  }
7084
7214
  }
7085
- store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(eq89(mailOutbox.id, row.id)).run();
7215
+ store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(eq91(mailOutbox.id, row.id)).run();
7086
7216
  return row;
7087
7217
  });
7088
7218
  }
7089
7219
  function markMailSent(store, id) {
7090
- store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(eq89(mailOutbox.id, id)).run();
7220
+ store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(eq91(mailOutbox.id, id)).run();
7091
7221
  }
7092
7222
  function retryMail(store, job) {
7093
7223
  const attempts = job.attempts + 1;
@@ -7097,7 +7227,7 @@ function retryMail(store, job) {
7097
7227
  nextAttempt: Date.now() + delay,
7098
7228
  leaseUntil: null,
7099
7229
  lastError: "Delivery failed"
7100
- }).where(eq89(mailOutbox.id, job.id)).run();
7230
+ }).where(eq91(mailOutbox.id, job.id)).run();
7101
7231
  }
7102
7232
 
7103
7233
  // server/mail/outbox.ts
@@ -7151,7 +7281,7 @@ async function flushOutbox(store, send) {
7151
7281
  }
7152
7282
 
7153
7283
  // server/router/workspace/invite.ts
7154
- import { and as and67, eq as eq90, 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";
7155
7285
  var inviteProcedure = browserManagerProcedure.input(invitationSchema).mutation(({ ctx, input: input2 }) => {
7156
7286
  const user = ctx.user;
7157
7287
  const workspace2 = ctx.workspace;
@@ -7189,9 +7319,9 @@ This invitation expires in seven days.`
7189
7319
  "Only the owner can invite admins."
7190
7320
  );
7191
7321
  }
7192
- const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users, eq90(users.id, memberships.userId)).where(
7193
- and67(
7194
- eq90(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),
7195
7325
  sql3`lower(${users.email}) = ${email}`
7196
7326
  )
7197
7327
  ).get();
@@ -7202,8 +7332,8 @@ This invitation expires in seven days.`
7202
7332
  );
7203
7333
  }
7204
7334
  const prior = db.select({ id: invitations.id, expiresAt: invitations.expiresAt }).from(invitations).where(
7205
- and67(
7206
- eq90(invitations.workspaceId, workspace2.id),
7335
+ and68(
7336
+ eq92(invitations.workspaceId, workspace2.id),
7207
7337
  sql3`lower(${invitations.email}) = ${email}`,
7208
7338
  isNull2(invitations.acceptedAt),
7209
7339
  isNull2(invitations.revokedAt)
@@ -7238,7 +7368,7 @@ This invitation expires in seven days.`
7238
7368
  });
7239
7369
 
7240
7370
  // server/router/workspace/revoke-invitation.ts
7241
- import { and as and68, eq as eq91 } from "drizzle-orm";
7371
+ import { and as and69, eq as eq93 } from "drizzle-orm";
7242
7372
  var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
7243
7373
  const id = input2.id;
7244
7374
  const user = ctx.user;
@@ -7253,9 +7383,9 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
7253
7383
  );
7254
7384
  }
7255
7385
  const invitation = ctx2.db.select().from(invitations).where(
7256
- and68(
7257
- eq91(invitations.workspaceId, workspace2.id),
7258
- eq91(invitations.id, id)
7386
+ and69(
7387
+ eq93(invitations.workspaceId, workspace2.id),
7388
+ eq93(invitations.id, id)
7259
7389
  )
7260
7390
  ).get();
7261
7391
  if (!invitation) {
@@ -7276,7 +7406,7 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
7276
7406
  });
7277
7407
 
7278
7408
  // server/router/workspace/accept-invitation.ts
7279
- import { and as and69, eq as eq92 } from "drizzle-orm";
7409
+ import { and as and70, eq as eq94 } from "drizzle-orm";
7280
7410
  var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTokenSchema).mutation(({ ctx, input: input2 }) => {
7281
7411
  const token = input2.token;
7282
7412
  const user = ctx.user;
@@ -7288,9 +7418,9 @@ var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTo
7288
7418
  throw new ServiceError("NOT_FOUND", "Invitation not found.");
7289
7419
  }
7290
7420
  const invite = db.select().from(invitations).where(
7291
- and69(
7292
- eq92(invitations.workspaceId, workspace2.id),
7293
- eq92(invitations.tokenDigest, digest(token))
7421
+ and70(
7422
+ eq94(invitations.workspaceId, workspace2.id),
7423
+ eq94(invitations.tokenDigest, digest(token))
7294
7424
  )
7295
7425
  ).get();
7296
7426
  if (!invite) {
@@ -7371,7 +7501,7 @@ var updateMemberProcedure = browserOwnerProcedure.input(memberUpdateSchema).muta
7371
7501
  });
7372
7502
 
7373
7503
  // server/router/workspace/remove-member.ts
7374
- import { and as and70, eq as eq93 } from "drizzle-orm";
7504
+ import { and as and71, eq as eq95 } from "drizzle-orm";
7375
7505
  var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
7376
7506
  const id = input2.id;
7377
7507
  inTransaction(ctx, (ctx2) => {
@@ -7384,9 +7514,9 @@ var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).
7384
7514
  );
7385
7515
  }
7386
7516
  ctx2.db.delete(memberships).where(
7387
- and70(
7388
- eq93(memberships.workspaceId, target.workspaceId),
7389
- eq93(memberships.id, id)
7517
+ and71(
7518
+ eq95(memberships.workspaceId, target.workspaceId),
7519
+ eq95(memberships.id, id)
7390
7520
  )
7391
7521
  ).run();
7392
7522
  });
@@ -7457,8 +7587,8 @@ var appRouter = router({
7457
7587
  // server/api/mcp-dispatch.ts
7458
7588
  async function dispatchTool(context, name, toolInput) {
7459
7589
  const caller = appRouter.createCaller(context);
7460
- const id = () => z48.string().parse(toolInput.id);
7461
- const actionId = () => z48.string().parse(toolInput.action);
7590
+ const id = () => z50.string().parse(toolInput.id);
7591
+ const actionId = () => z50.string().parse(toolInput.action);
7462
7592
  const queueSession = (session) => caller.runs.session(
7463
7593
  sessionRunSchema.parse({
7464
7594
  project: toolInput.project,
@@ -7479,7 +7609,7 @@ async function dispatchTool(context, name, toolInput) {
7479
7609
  };
7480
7610
  }
7481
7611
  case "get_project_sdk":
7482
- return caller.projects.sdk({ id: z48.string().parse(toolInput.project) });
7612
+ return caller.projects.sdk({ id: z50.string().parse(toolInput.project) });
7483
7613
  case "execute_code":
7484
7614
  return caller.runs.create(
7485
7615
  createRunSchema.strip().parse({ ...toolInput, operation: "code" })
@@ -7489,23 +7619,23 @@ async function dispatchTool(context, name, toolInput) {
7489
7619
  case "execute_cell":
7490
7620
  return queueSession({
7491
7621
  operation: "execute",
7492
- id: z48.uuid().parse(toolInput.session_id),
7493
- cellId: z48.uuid().parse(toolInput.cell_id),
7494
- generation: z48.number().parse(toolInput.generation),
7495
- 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),
7496
7626
  after: toolInput.after
7497
7627
  });
7498
7628
  case "read_session":
7499
7629
  return queueSession({
7500
7630
  operation: "read",
7501
- id: z48.uuid().parse(toolInput.session_id),
7631
+ id: z50.uuid().parse(toolInput.session_id),
7502
7632
  after: toolInput.after,
7503
7633
  limit: toolInput.limit
7504
7634
  });
7505
7635
  case "close_session":
7506
7636
  return queueSession({
7507
7637
  operation: "close",
7508
- id: z48.uuid().parse(toolInput.session_id)
7638
+ id: z50.uuid().parse(toolInput.session_id)
7509
7639
  });
7510
7640
  case "get_run_events": {
7511
7641
  const all = await caller.runs.events({ id: id() });
@@ -7567,6 +7697,12 @@ async function dispatchTool(context, name, toolInput) {
7567
7697
  return (await caller.approvals.list()).results.filter(
7568
7698
  (entry) => entry.status === "pending"
7569
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));
7570
7706
  case "list_plugins":
7571
7707
  return (await caller.plugins.list()).results.map((entry) => ({
7572
7708
  slug: entry.slug,
@@ -7582,20 +7718,21 @@ async function dispatchTool(context, name, toolInput) {
7582
7718
  }
7583
7719
 
7584
7720
  // server/api/mcp-schemas.ts
7585
- import { z as z49 } from "zod";
7586
- var mcpArgumentsSchema = z49.object({
7587
- action: z49.string().optional(),
7588
- project: z49.string().optional(),
7589
- id: z49.string().optional(),
7590
- version: z49.number().optional(),
7591
- suite_revision: z49.number().optional(),
7592
- after: z49.number().optional(),
7593
- offset: z49.number().optional(),
7594
- limit: z49.number().optional()
7595
- }).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());
7596
7732
 
7597
7733
  // server/api/mcp.ts
7598
7734
  import Ajv2 from "ajv";
7735
+ import { ZodError as ZodError2 } from "zod";
7599
7736
  import { TRPCError as TRPCError2 } from "@trpc/server";
7600
7737
 
7601
7738
  // server/api/mcp-tools.json
@@ -8177,6 +8314,71 @@ var mcp_tools_default = [
8177
8314
  },
8178
8315
  mutates: false
8179
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
+ },
8180
8382
  {
8181
8383
  name: "list_plugins",
8182
8384
  description: "Read installed plugin capability metadata.",
@@ -8203,6 +8405,8 @@ var mcp_tools_default = [
8203
8405
 
8204
8406
  // server/api/mcp.ts
8205
8407
  var scopes = {
8408
+ list_project_plugins: "plugins:configure",
8409
+ configure_plugin: "plugins:configure",
8206
8410
  list_projects: "catalog:read",
8207
8411
  get_project_sdk: "catalog:read",
8208
8412
  execute_code: "code:execute",
@@ -8318,6 +8522,12 @@ async function handleMcp(ctx) {
8318
8522
  isError: false
8319
8523
  };
8320
8524
  } catch (cause) {
8525
+ if (cause instanceof ZodError2) {
8526
+ return error(
8527
+ -32602,
8528
+ "Invalid tool arguments. Check fields, types and limits."
8529
+ );
8530
+ }
8321
8531
  if (!(cause instanceof HttpError) && !(cause instanceof TRPCError2)) {
8322
8532
  throw cause;
8323
8533
  }
@@ -8325,12 +8535,12 @@ async function handleMcp(ctx) {
8325
8535
  content: [
8326
8536
  {
8327
8537
  type: "text",
8328
- 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" && [
8329
8539
  "open_session",
8330
8540
  "execute_cell",
8331
8541
  "read_session",
8332
8542
  "close_session"
8333
- ].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."
8334
8544
  }
8335
8545
  ],
8336
8546
  isError: true
@@ -8343,18 +8553,18 @@ async function handleMcp(ctx) {
8343
8553
  }
8344
8554
 
8345
8555
  // server/automations/ingress.ts
8346
- import { z as z50 } from "zod";
8347
- import { and as and72, eq as eq95 } from "drizzle-orm";
8556
+ import { z as z52 } from "zod";
8557
+ import { and as and73, eq as eq97 } from "drizzle-orm";
8348
8558
  import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
8349
8559
 
8350
8560
  // server/repositories/webhook-deliveries.ts
8351
- import { and as and71, eq as eq94 } from "drizzle-orm";
8561
+ import { and as and72, eq as eq96 } from "drizzle-orm";
8352
8562
  function webhookDeliveriesRepository(context) {
8353
8563
  const workspaceId = requireWorkspace(context).id;
8354
8564
  const database = context.db;
8355
- const scoped = (id, filter) => and71(
8356
- eq94(webhookDeliveries.workspaceId, workspaceId),
8357
- id === void 0 ? void 0 : eq94(webhookDeliveries.id, id),
8565
+ const scoped = (id, filter) => and72(
8566
+ eq96(webhookDeliveries.workspaceId, workspaceId),
8567
+ id === void 0 ? void 0 : eq96(webhookDeliveries.id, id),
8358
8568
  filter
8359
8569
  );
8360
8570
  return {
@@ -8382,7 +8592,7 @@ async function handleWebhookIngress(ctx) {
8382
8592
  if (ctx.request.method !== "POST") {
8383
8593
  throw new HttpError(405, "Method not allowed.");
8384
8594
  }
8385
- const hook = ctx.db.select().from(webhooks).where(eq95(webhooks.id, match[1])).get();
8595
+ const hook = ctx.db.select().from(webhooks).where(eq97(webhooks.id, match[1])).get();
8386
8596
  if (!hook || !ctx.workspace || hook.workspaceId !== ctx.workspace.id) {
8387
8597
  throw new HttpError(404, "Webhook not found.");
8388
8598
  }
@@ -8417,9 +8627,9 @@ async function handleWebhookIngress(ctx) {
8417
8627
  jsonValue(payload.inputs, "Inputs");
8418
8628
  const actor = identityRepository(ctx.db).user(hook.actorId);
8419
8629
  const member = ctx.db.select().from(memberships).where(
8420
- and72(
8421
- eq95(memberships.userId, hook.actorId),
8422
- eq95(memberships.workspaceId, hook.workspaceId)
8630
+ and73(
8631
+ eq97(memberships.userId, hook.actorId),
8632
+ eq97(memberships.workspaceId, hook.workspaceId)
8423
8633
  )
8424
8634
  ).get();
8425
8635
  if (!hook.enabled || !actor || !member) {
@@ -8440,9 +8650,9 @@ async function handleWebhookIngress(ctx) {
8440
8650
  throw new HttpError(403, "Webhook is unavailable.");
8441
8651
  }
8442
8652
  const old = webhookDeliveriesRepository(actorCtx2).list(
8443
- and72(
8444
- eq95(webhookDeliveries.webhookId, hook.id),
8445
- eq95(webhookDeliveries.deliveryId, delivery)
8653
+ and73(
8654
+ eq97(webhookDeliveries.webhookId, hook.id),
8655
+ eq97(webhookDeliveries.deliveryId, delivery)
8446
8656
  )
8447
8657
  )[0];
8448
8658
  if (old) {
@@ -8462,7 +8672,7 @@ async function handleWebhookIngress(ctx) {
8462
8672
  operation: "action",
8463
8673
  action: action.id,
8464
8674
  version: version2.number,
8465
- inputs: z50.record(z50.string(), z50.json()).parse(payload.inputs),
8675
+ inputs: z52.record(z52.string(), z52.json()).parse(payload.inputs),
8466
8676
  idempotency_key: `webhook:${hook.id}:${delivery}`
8467
8677
  });
8468
8678
  runsRepository(actorCtx2).update(run.id, {
@@ -8485,7 +8695,7 @@ async function handleWebhookIngress(ctx) {
8485
8695
  }
8486
8696
 
8487
8697
  // server/execution/authority.ts
8488
- import { and as and73, eq as eq96 } from "drizzle-orm";
8698
+ import { and as and74, eq as eq98 } from "drizzle-orm";
8489
8699
  import { timingSafeEqual as timingSafeEqual3 } from "node:crypto";
8490
8700
  var terminal = /* @__PURE__ */ new Set([
8491
8701
  "succeeded",
@@ -8503,15 +8713,15 @@ function bearer(ctx) {
8503
8713
  }
8504
8714
  function executor(ctx) {
8505
8715
  const row = ctx.db.select().from(executors).where(
8506
- and73(
8507
- eq96(executors.tokenHash, digest(bearer(ctx))),
8508
- eq96(executors.enabled, true)
8716
+ and74(
8717
+ eq98(executors.tokenHash, digest(bearer(ctx))),
8718
+ eq98(executors.enabled, true)
8509
8719
  )
8510
8720
  ).get();
8511
8721
  const project = row && ctx.db.select().from(projects).where(
8512
- and73(
8513
- eq96(projects.id, row.projectId),
8514
- eq96(projects.workspaceId, row.workspaceId)
8722
+ and74(
8723
+ eq98(projects.id, row.projectId),
8724
+ eq98(projects.workspaceId, row.workspaceId)
8515
8725
  )
8516
8726
  ).get();
8517
8727
  if (!row || !project?.enabled) {
@@ -8520,17 +8730,17 @@ function executor(ctx) {
8520
8730
  return row;
8521
8731
  }
8522
8732
  function runCapability(ctx, expectedId) {
8523
- const run = ctx.db.select().from(runs).where(eq96(runs.capabilityHash, digest(bearer(ctx)))).get();
8733
+ const run = ctx.db.select().from(runs).where(eq98(runs.capabilityHash, digest(bearer(ctx)))).get();
8524
8734
  const currentTime = now();
8525
8735
  if (!run || expectedId && run.id !== expectedId || !run.deadline || run.deadline <= currentTime || !run.leaseExpiresAt || run.leaseExpiresAt <= currentTime) {
8526
8736
  throw new HttpError(401, "Invalid or expired run capability.");
8527
8737
  }
8528
- const worker = run.executorId && ctx.db.select().from(executors).where(eq96(executors.id, run.executorId)).get();
8529
- const project = ctx.db.select().from(projects).where(eq96(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();
8530
8740
  const member = ctx.db.select().from(memberships).where(
8531
- and73(
8532
- eq96(memberships.workspaceId, run.workspaceId),
8533
- eq96(memberships.userId, run.actorId)
8741
+ and74(
8742
+ eq98(memberships.workspaceId, run.workspaceId),
8743
+ eq98(memberships.userId, run.actorId)
8534
8744
  )
8535
8745
  ).get();
8536
8746
  if (!worker || !worker.enabled || worker.projectId !== run.projectId || !project?.enabled || !member) {
@@ -8550,9 +8760,9 @@ function runCapability(ctx, expectedId) {
8550
8760
  if (!terminal.has(run.status) && !run.cancelRequested) {
8551
8761
  const operation = object(command2) ? command2.operation : void 0;
8552
8762
  const token = run.tokenId ? ctx.db.select().from(accessTokens).where(
8553
- and73(
8554
- eq96(accessTokens.workspaceId, run.workspaceId),
8555
- eq96(accessTokens.id, run.tokenId)
8763
+ and74(
8764
+ eq98(accessTokens.workspaceId, run.workspaceId),
8765
+ eq98(accessTokens.id, run.tokenId)
8556
8766
  )
8557
8767
  ).get() : void 0;
8558
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"));
@@ -8593,11 +8803,11 @@ function live(run) {
8593
8803
  }
8594
8804
  function actorContext(ctx, run) {
8595
8805
  const user = identityRepository(ctx.db).user(run.actorId) ?? null;
8596
- const workspace2 = ctx.db.select().from(workspaces).where(eq96(workspaces.id, run.workspaceId)).get() ?? null;
8806
+ const workspace2 = ctx.db.select().from(workspaces).where(eq98(workspaces.id, run.workspaceId)).get() ?? null;
8597
8807
  const membership = ctx.db.select().from(memberships).where(
8598
- and73(
8599
- eq96(memberships.workspaceId, run.workspaceId),
8600
- eq96(memberships.userId, run.actorId)
8808
+ and74(
8809
+ eq98(memberships.workspaceId, run.workspaceId),
8810
+ eq98(memberships.userId, run.actorId)
8601
8811
  )
8602
8812
  ).get();
8603
8813
  if (!user || !workspace2 || !membership) {
@@ -8614,7 +8824,7 @@ function actorContext(ctx, run) {
8614
8824
  }
8615
8825
 
8616
8826
  // server/execution/bootstrap.ts
8617
- import { eq as eq97 } from "drizzle-orm";
8827
+ import { eq as eq99 } from "drizzle-orm";
8618
8828
  import { createHmac as createHmac3, randomUUID as randomUUID6 } from "node:crypto";
8619
8829
  function bootstrap(ctx) {
8620
8830
  const configured = process.env.LOCAL_EXECUTOR_BOOTSTRAP_TOKEN;
@@ -8622,8 +8832,8 @@ function bootstrap(ctx) {
8622
8832
  throw new HttpError(403, "Invalid local bootstrap credential.");
8623
8833
  }
8624
8834
  const registrations = [];
8625
- for (const project of ctx.db.select().from(projects).where(eq97(projects.enabled, true)).all()) {
8626
- let worker = ctx.db.select().from(executors).where(eq97(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();
8627
8837
  if (worker && (!worker.locallyManaged || !worker.enabled)) {
8628
8838
  continue;
8629
8839
  }
@@ -8643,7 +8853,7 @@ function bootstrap(ctx) {
8643
8853
  }).returning().get();
8644
8854
  }
8645
8855
  const token = createHmac3("sha256", configured).update(`${worker.id}:${worker.registrationNonce}`).digest("hex");
8646
- ctx.db.update(executors).set({ tokenHash: digest(token) }).where(eq97(executors.id, worker.id)).run();
8856
+ ctx.db.update(executors).set({ tokenHash: digest(token) }).where(eq99(executors.id, worker.id)).run();
8647
8857
  registrations.push({
8648
8858
  agent_id: project.id,
8649
8859
  executor_id: worker.id,
@@ -8655,21 +8865,21 @@ function bootstrap(ctx) {
8655
8865
  }
8656
8866
 
8657
8867
  // server/execution/claim.ts
8658
- import { and as and74, asc as asc7, eq as eq98, inArray as inArray10 } from "drizzle-orm";
8868
+ import { and as and75, asc as asc7, eq as eq100, inArray as inArray10 } from "drizzle-orm";
8659
8869
  function claim(ctx, worker) {
8660
8870
  ctx.db.update(executors).set({ lastSeenAt: now() }).where(
8661
- and74(
8662
- eq98(executors.id, worker.id),
8663
- eq98(executors.workspaceId, worker.workspaceId)
8871
+ and75(
8872
+ eq100(executors.id, worker.id),
8873
+ eq100(executors.workspaceId, worker.workspaceId)
8664
8874
  )
8665
8875
  ).run();
8666
- const setting = ctx.db.select().from(workspaceSettings).where(eq98(workspaceSettings.workspaceId, worker.workspaceId)).get();
8876
+ const setting = ctx.db.select().from(workspaceSettings).where(eq100(workspaceSettings.workspaceId, worker.workspaceId)).get();
8667
8877
  if (setting && (!setting.enabled || setting.executionPool !== worker.pool)) {
8668
8878
  return new Response(null, { status: 204 });
8669
8879
  }
8670
8880
  const active = ctx.db.select().from(runs).where(
8671
- and74(
8672
- eq98(runs.workspaceId, worker.workspaceId),
8881
+ and75(
8882
+ eq100(runs.workspaceId, worker.workspaceId),
8673
8883
  inArray10(runs.status, ["running", "waiting_approval"])
8674
8884
  )
8675
8885
  ).all();
@@ -8677,10 +8887,10 @@ function claim(ctx, worker) {
8677
8887
  return new Response(null, { status: 204 });
8678
8888
  }
8679
8889
  const candidates = ctx.db.select().from(runs).where(
8680
- and74(
8681
- eq98(runs.projectId, worker.projectId),
8682
- eq98(runs.workspaceId, worker.workspaceId),
8683
- eq98(runs.status, "queued")
8890
+ and75(
8891
+ eq100(runs.projectId, worker.projectId),
8892
+ eq100(runs.workspaceId, worker.workspaceId),
8893
+ eq100(runs.status, "queued")
8684
8894
  )
8685
8895
  ).orderBy(asc7(runs.createdAt)).all();
8686
8896
  for (const run of candidates) {
@@ -8692,18 +8902,18 @@ function claim(ctx, worker) {
8692
8902
  continue;
8693
8903
  }
8694
8904
  const member = ctx.db.select().from(memberships).where(
8695
- and74(
8696
- eq98(memberships.userId, run.actorId),
8697
- eq98(memberships.workspaceId, run.workspaceId)
8905
+ and75(
8906
+ eq100(memberships.userId, run.actorId),
8907
+ eq100(memberships.workspaceId, run.workspaceId)
8698
8908
  )
8699
8909
  ).get();
8700
- const token = run.tokenId ? ctx.db.select().from(accessTokens).where(eq98(accessTokens.id, run.tokenId)).get() : null;
8910
+ const token = run.tokenId ? ctx.db.select().from(accessTokens).where(eq100(accessTokens.id, run.tokenId)).get() : null;
8701
8911
  if (!member || run.cancelRequested || run.tokenId && (!token || token.revoked)) {
8702
8912
  ctx.db.update(runs).set({
8703
8913
  status: "cancelled",
8704
8914
  cancelRequested: true,
8705
8915
  updatedAt: now()
8706
- }).where(eq98(runs.id, run.id)).run();
8916
+ }).where(eq100(runs.id, run.id)).run();
8707
8917
  continue;
8708
8918
  }
8709
8919
  const capability = randomSecret();
@@ -8715,7 +8925,7 @@ function claim(ctx, worker) {
8715
8925
  deadline,
8716
8926
  leaseExpiresAt: new Date(Date.now() + 6e4).toISOString(),
8717
8927
  updatedAt: now()
8718
- }).where(eq98(runs.id, run.id)).run();
8928
+ }).where(eq100(runs.id, run.id)).run();
8719
8929
  return json({
8720
8930
  protocol_version: protocol,
8721
8931
  run_id: run.id,
@@ -8733,13 +8943,13 @@ function claim(ctx, worker) {
8733
8943
  }
8734
8944
 
8735
8945
  // server/execution/configuration.ts
8736
- import { and as and75, eq as eq99 } from "drizzle-orm";
8946
+ import { and as and76, eq as eq101 } from "drizzle-orm";
8737
8947
  function pluginsFor(ctx, worker) {
8738
8948
  return ctx.db.select().from(plugins).where(
8739
- and75(
8740
- eq99(plugins.workspaceId, worker.workspaceId),
8741
- eq99(plugins.projectId, worker.projectId),
8742
- eq99(plugins.enabled, true)
8949
+ and76(
8950
+ eq101(plugins.workspaceId, worker.workspaceId),
8951
+ eq101(plugins.projectId, worker.projectId),
8952
+ eq101(plugins.enabled, true)
8743
8953
  )
8744
8954
  ).all().filter(
8745
8955
  (plugin) => plugin.distribution !== "mcp" || worker.protocolVersion >= 4
@@ -8767,11 +8977,11 @@ function configuration(ctx, worker) {
8767
8977
  }
8768
8978
 
8769
8979
  // server/execution/credentials.ts
8770
- import { and as and78, eq as eq102 } from "drizzle-orm";
8980
+ import { and as and79, eq as eq104 } from "drizzle-orm";
8771
8981
 
8772
8982
  // server/mcp/oauth-refresh.ts
8773
8983
  import { auth as auth3 } from "@modelcontextprotocol/client";
8774
- import { and as and76, eq as eq100 } from "drizzle-orm";
8984
+ import { and as and77, eq as eq102 } from "drizzle-orm";
8775
8985
  var refreshes = /* @__PURE__ */ new WeakMap();
8776
8986
  async function mcpExecutionSecret(ctx, credential) {
8777
8987
  let pending = refreshes.get(ctx.db);
@@ -8793,9 +9003,9 @@ async function mcpExecutionSecret(ctx, credential) {
8793
9003
  }
8794
9004
  async function refresh(ctx, initial) {
8795
9005
  const credential = ctx.db.select().from(credentials).where(
8796
- and76(
8797
- eq100(credentials.id, initial.id),
8798
- eq100(credentials.workspaceId, initial.workspaceId)
9006
+ and77(
9007
+ eq102(credentials.id, initial.id),
9008
+ eq102(credentials.workspaceId, initial.workspaceId)
8799
9009
  )
8800
9010
  ).get();
8801
9011
  if (!credential) {
@@ -8826,9 +9036,9 @@ async function refresh(ctx, initial) {
8826
9036
  encryptedSecret: encrypt(ctx, JSON.stringify(state)),
8827
9037
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
8828
9038
  }).where(
8829
- and76(
8830
- eq100(credentials.id, credential.id),
8831
- eq100(credentials.encryptedSecret, credential.encryptedSecret)
9039
+ and77(
9040
+ eq102(credentials.id, credential.id),
9041
+ eq102(credentials.encryptedSecret, credential.encryptedSecret)
8832
9042
  )
8833
9043
  ).returning().get();
8834
9044
  if (!updated) {
@@ -8852,11 +9062,11 @@ async function refresh(ctx, initial) {
8852
9062
  }
8853
9063
 
8854
9064
  // server/oauth/refresh.ts
8855
- import { z as z52 } from "zod";
8856
- import { and as and77, eq as eq101 } from "drizzle-orm";
9065
+ import { z as z54 } from "zod";
9066
+ import { and as and78, eq as eq103 } from "drizzle-orm";
8857
9067
 
8858
9068
  // server/oauth/tokens.ts
8859
- import { z as z51 } from "zod";
9069
+ import { z as z53 } from "zod";
8860
9070
  async function tokenExchange(providerName, clientId, clientSecret, params, fetcher) {
8861
9071
  const fields = new URLSearchParams({ ...params, client_id: clientId });
8862
9072
  const headers = new Headers({
@@ -8897,7 +9107,7 @@ async function tokenExchange(providerName, clientId, clientSecret, params, fetch
8897
9107
  }
8898
9108
  chunks.push(item.value);
8899
9109
  }
8900
- 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")));
8901
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)) {
8902
9112
  throw new Error();
8903
9113
  }
@@ -8945,9 +9155,9 @@ function recordSecretVersion(secret, credential) {
8945
9155
  function assertExecutionSecretCurrent(store, credential, secret) {
8946
9156
  const version2 = secretVersions.get(secret);
8947
9157
  const current = store.db.select().from(credentials).where(
8948
- and77(
8949
- eq101(credentials.id, credential.id),
8950
- eq101(credentials.workspaceId, credential.workspaceId)
9158
+ and78(
9159
+ eq103(credentials.id, credential.id),
9160
+ eq103(credentials.workspaceId, credential.workspaceId)
8951
9161
  )
8952
9162
  ).get();
8953
9163
  if (!version2 || !current || version2.id !== current.id || version2.workspaceId !== current.workspaceId || version2.provider !== current.provider || version2.encryptedSecret !== current.encryptedSecret) {
@@ -8963,7 +9173,7 @@ async function executionSecret(store, credential, fetcher = fetch) {
8963
9173
  }
8964
9174
  if (!provider(credential.provider)) {
8965
9175
  return recordSecretVersion(
8966
- 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))),
8967
9177
  credential
8968
9178
  );
8969
9179
  }
@@ -8989,15 +9199,15 @@ async function executionSecret(store, credential, fetcher = fetch) {
8989
9199
  }
8990
9200
  async function resolveExecutionSecret(store, initial, fetcher) {
8991
9201
  const credential = store.db.select().from(credentials).where(
8992
- and77(
8993
- eq101(credentials.id, initial.id),
8994
- eq101(credentials.workspaceId, initial.workspaceId)
9202
+ and78(
9203
+ eq103(credentials.id, initial.id),
9204
+ eq103(credentials.workspaceId, initial.workspaceId)
8995
9205
  )
8996
9206
  ).get();
8997
9207
  if (!credential || !provider(credential.provider)) {
8998
9208
  throw new ServiceError("BAD_REQUEST", "Reconnect this credential.");
8999
9209
  }
9000
- 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)));
9001
9211
  if (credential.provider === "xero-oauth" && Object.keys(payload).length === 1 && typeof payload.secret_accessToken === "string" && payload.secret_accessToken) {
9002
9212
  return recordSecretVersion(
9003
9213
  { secret_accessToken: payload.secret_accessToken },
@@ -9033,9 +9243,9 @@ async function resolveExecutionSecret(store, initial, fetcher) {
9033
9243
  JSON.stringify(applyTokens(payload, tokens2))
9034
9244
  );
9035
9245
  const result = store.db.update(credentials).set({ encryptedSecret: updated, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(
9036
- and77(
9037
- eq101(credentials.id, credential.id),
9038
- eq101(credentials.encryptedSecret, credential.encryptedSecret)
9246
+ and78(
9247
+ eq103(credentials.id, credential.id),
9248
+ eq103(credentials.encryptedSecret, credential.encryptedSecret)
9039
9249
  )
9040
9250
  ).returning().get();
9041
9251
  if (!result) {
@@ -9067,9 +9277,9 @@ async function serveCredential(ctx, credentialId) {
9067
9277
  throw new HttpError(403, "Credential is outside this run capability.");
9068
9278
  }
9069
9279
  const credential2 = ctx.db.select().from(credentials).where(
9070
- and78(
9071
- eq102(credentials.id, credentialId),
9072
- eq102(credentials.workspaceId, run.workspaceId)
9280
+ and79(
9281
+ eq104(credentials.id, credentialId),
9282
+ eq104(credentials.workspaceId, run.workspaceId)
9073
9283
  )
9074
9284
  ).get();
9075
9285
  if (!credential2) {
@@ -9097,12 +9307,12 @@ async function serveCredential(ctx, credentialId) {
9097
9307
  }
9098
9308
 
9099
9309
  // server/execution/shell-policy.ts
9100
- import { and as and79, asc as asc8, eq as eq104 } from "drizzle-orm";
9101
- 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";
9102
9312
 
9103
9313
  // server/execution/redaction.ts
9104
- import { z as z53 } from "zod";
9105
- import { eq as eq103 } from "drizzle-orm";
9314
+ import { z as z55 } from "zod";
9315
+ import { eq as eq105 } from "drizzle-orm";
9106
9316
  function redact(ctx, workspaceId, value) {
9107
9317
  const secrets = [];
9108
9318
  const collect = (entry) => {
@@ -9114,7 +9324,7 @@ function redact(ctx, workspaceId, value) {
9114
9324
  Object.values(entry).forEach(collect);
9115
9325
  }
9116
9326
  };
9117
- for (const credential of ctx.db.select().from(credentials).where(eq103(credentials.workspaceId, workspaceId)).all()) {
9327
+ for (const credential of ctx.db.select().from(credentials).where(eq105(credentials.workspaceId, workspaceId)).all()) {
9118
9328
  collect(JSON.parse(decrypt(ctx, credential.encryptedSecret)));
9119
9329
  }
9120
9330
  secrets.sort((a, b) => b.length - a.length);
@@ -9141,7 +9351,7 @@ function redact(ctx, workspaceId, value) {
9141
9351
  }
9142
9352
  return entry;
9143
9353
  };
9144
- return mask(z53.json().parse(value));
9354
+ return mask(z55.json().parse(value));
9145
9355
  }
9146
9356
  function bounded(value, limit = 2e5) {
9147
9357
  if (Buffer.byteLength(JSON.stringify(value)) > limit) {
@@ -9151,19 +9361,19 @@ function bounded(value, limit = 2e5) {
9151
9361
  }
9152
9362
 
9153
9363
  // server/execution/shell-policy.ts
9154
- var invocation = z54.strictObject({
9364
+ var invocation = z56.strictObject({
9155
9365
  executable: executableName,
9156
- args: z54.array(
9157
- z54.string().max(4096).refine((arg) => !arg.includes("\0"))
9366
+ args: z56.array(
9367
+ z56.string().max(4096).refine((arg) => !arg.includes("\0"))
9158
9368
  ).max(64)
9159
9369
  });
9160
9370
  function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
9161
9371
  const plugin = ctx.db.select().from(plugins).where(
9162
- and79(
9163
- eq104(plugins.id, pluginId),
9164
- eq104(plugins.projectId, run.projectId),
9165
- eq104(plugins.workspaceId, run.workspaceId),
9166
- eq104(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)
9167
9377
  )
9168
9378
  ).get();
9169
9379
  const agent = snapshotAgents(run.snapshot).find(
@@ -9180,29 +9390,29 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
9180
9390
  if (!approvalId && method === "GET") {
9181
9391
  return json(
9182
9392
  ctx.db.select({ name: shellRules.executable }).from(shellRules).where(
9183
- and79(
9184
- eq104(shellRules.pluginId, pluginId),
9185
- eq104(shellRules.decision, "allow")
9393
+ and80(
9394
+ eq106(shellRules.pluginId, pluginId),
9395
+ eq106(shellRules.decision, "allow")
9186
9396
  )
9187
9397
  ).orderBy(asc8(shellRules.executable)).all().map((rule2) => rule2.name)
9188
9398
  );
9189
9399
  }
9190
9400
  if (approvalId && method === "GET") {
9191
9401
  const row2 = ctx.db.select().from(approvals).where(
9192
- and79(
9193
- eq104(approvals.id, approvalId),
9194
- eq104(approvals.workspaceId, run.workspaceId),
9195
- eq104(approvals.runId, run.id)
9402
+ and80(
9403
+ eq106(approvals.id, approvalId),
9404
+ eq106(approvals.workspaceId, run.workspaceId),
9405
+ eq106(approvals.runId, run.id)
9196
9406
  )
9197
9407
  ).get();
9198
9408
  if (row2?.shell?.pluginId !== plugin.id || row2.shell.digest !== plugin.digest) {
9199
9409
  throw new HttpError(404, "Shell approval not found.");
9200
9410
  }
9201
9411
  const blocked = ctx.db.select().from(shellRules).where(
9202
- and79(
9203
- eq104(shellRules.pluginId, pluginId),
9204
- eq104(shellRules.executable, row2.shell.executable),
9205
- eq104(shellRules.decision, "block")
9412
+ and80(
9413
+ eq106(shellRules.pluginId, pluginId),
9414
+ eq106(shellRules.executable, row2.shell.executable),
9415
+ eq106(shellRules.decision, "block")
9206
9416
  )
9207
9417
  ).get();
9208
9418
  return json({
@@ -9219,9 +9429,9 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
9219
9429
  }
9220
9430
  const { executable, args } = parsed.data;
9221
9431
  const rule = ctx.db.select().from(shellRules).where(
9222
- and79(
9223
- eq104(shellRules.pluginId, pluginId),
9224
- eq104(shellRules.executable, executable)
9432
+ and80(
9433
+ eq106(shellRules.pluginId, pluginId),
9434
+ eq106(shellRules.executable, executable)
9225
9435
  )
9226
9436
  ).get();
9227
9437
  if (rule) {
@@ -9245,15 +9455,15 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
9245
9455
  },
9246
9456
  status: "pending"
9247
9457
  }).returning().get();
9248
- ctx.db.update(runs).set({ status: "waiting_approval", updatedAt: now() }).where(eq104(runs.id, run.id)).run();
9458
+ ctx.db.update(runs).set({ status: "waiting_approval", updatedAt: now() }).where(eq106(runs.id, run.id)).run();
9249
9459
  return json({ id: row.id, status: row.status }, 201);
9250
9460
  }
9251
9461
 
9252
9462
  // server/execution/product.ts
9253
- import { and as and82, eq as eq107 } from "drizzle-orm";
9463
+ import { and as and83, eq as eq109 } from "drizzle-orm";
9254
9464
 
9255
9465
  // server/execution/project-data.ts
9256
- import { and as and81, asc as asc9, eq as eq106, inArray as inArray11 } from "drizzle-orm";
9466
+ import { and as and82, asc as asc9, eq as eq108, inArray as inArray11 } from "drizzle-orm";
9257
9467
 
9258
9468
  // server/execution/data-pagination.ts
9259
9469
  function paginateData(items, offset, limit) {
@@ -9280,56 +9490,56 @@ function paginateData(items, offset, limit) {
9280
9490
  }
9281
9491
 
9282
9492
  // server/execution/data-schemas.ts
9283
- import { z as z55 } from "zod";
9493
+ import { z as z57 } from "zod";
9284
9494
  var pagination = {
9285
- offset: z55.number().int().min(0).max(1e6).default(0),
9286
- 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)
9287
9497
  };
9288
- var tableId = { table_id: z55.string().uuid() };
9289
- var revision2 = z55.number().int().positive();
9290
- 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(
9291
9501
  (value) => !value.includes("\0") && Buffer.byteLength(value) <= 2e5
9292
9502
  );
9293
- var dataOperationSchema = z55.discriminatedUnion("operation", [
9294
- z55.strictObject({ operation: z55.literal("list_tables"), ...pagination }),
9295
- z55.strictObject({ operation: z55.literal("get_table"), ...tableId }),
9296
- z55.strictObject({
9297
- 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"),
9298
9508
  ...tableId,
9299
9509
  ...pagination
9300
9510
  }),
9301
- z55.strictObject({
9302
- operation: z55.literal("write_row"),
9511
+ z57.strictObject({
9512
+ operation: z57.literal("write_row"),
9303
9513
  ...tableId,
9304
9514
  table_revision: revision2,
9305
- values: z55.record(z55.string(), z55.json()),
9306
- row_id: z55.string().uuid().optional(),
9515
+ values: z57.record(z57.string(), z57.json()),
9516
+ row_id: z57.string().uuid().optional(),
9307
9517
  revision: revision2.optional()
9308
9518
  }).refine(
9309
9519
  (input2) => input2.row_id === void 0 === (input2.revision === void 0),
9310
9520
  "Row updates require both row ID and revision."
9311
9521
  ),
9312
- z55.strictObject({
9313
- operation: z55.literal("delete_row"),
9522
+ z57.strictObject({
9523
+ operation: z57.literal("delete_row"),
9314
9524
  ...tableId,
9315
- row_id: z55.string().uuid(),
9525
+ row_id: z57.string().uuid(),
9316
9526
  revision: revision2
9317
9527
  }),
9318
- z55.strictObject({ operation: z55.literal("list_documents"), ...pagination }),
9319
- z55.strictObject({
9320
- operation: z55.literal("get_document"),
9321
- 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()
9322
9532
  }),
9323
- z55.strictObject({
9324
- operation: z55.literal("write_document"),
9325
- document_id: z55.string().uuid(),
9326
- 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(),
9327
9537
  content: content.optional()
9328
9538
  })
9329
9539
  ]);
9330
9540
 
9331
9541
  // server/execution/run-grants.ts
9332
- import { and as and80, eq as eq105 } from "drizzle-orm";
9542
+ import { and as and81, eq as eq107 } from "drizzle-orm";
9333
9543
  function grantIds(context, run, kind, write = false) {
9334
9544
  const root2 = snapshotAgents(run.snapshot).find(
9335
9545
  (agent) => agent.id === run.projectId
@@ -9340,9 +9550,9 @@ function grantIds(context, run, kind, write = false) {
9340
9550
  ...write ? [] : grants2?.read ?? []
9341
9551
  ];
9342
9552
  const project = context.db.select().from(projects).where(
9343
- and80(
9344
- eq105(projects.id, run.projectId),
9345
- eq105(projects.workspaceId, run.workspaceId)
9553
+ and81(
9554
+ eq107(projects.id, run.projectId),
9555
+ eq107(projects.workspaceId, run.workspaceId)
9346
9556
  )
9347
9557
  ).get();
9348
9558
  if (!project) {
@@ -9368,8 +9578,8 @@ function projectData(context, run, body) {
9368
9578
  const documentOperation = input2.operation === "list_documents" || input2.operation === "get_document" || input2.operation === "write_document";
9369
9579
  if (documentOperation) {
9370
9580
  const accessibleDocuments = context.db.select().from(documents).where(
9371
- and81(
9372
- eq106(documents.workspaceId, run.workspaceId),
9581
+ and82(
9582
+ eq108(documents.workspaceId, run.workspaceId),
9373
9583
  inArray11(documents.id, grantIds(context, run, "documents"))
9374
9584
  )
9375
9585
  ).orderBy(asc9(documents.id)).all();
@@ -9397,9 +9607,9 @@ function projectData(context, run, body) {
9397
9607
  content: input2.content ?? document.content,
9398
9608
  updatedAt: now()
9399
9609
  }).where(
9400
- and81(
9401
- eq106(documents.id, document.id),
9402
- eq106(documents.workspaceId, run.workspaceId)
9610
+ and82(
9611
+ eq108(documents.id, document.id),
9612
+ eq108(documents.workspaceId, run.workspaceId)
9403
9613
  )
9404
9614
  ).returning().get();
9405
9615
  if (!updated) {
@@ -9408,8 +9618,8 @@ function projectData(context, run, body) {
9408
9618
  return bounded(documentView2(updated));
9409
9619
  }
9410
9620
  const tables = context.db.select().from(workspaceTables).where(
9411
- and81(
9412
- eq106(workspaceTables.workspaceId, run.workspaceId),
9621
+ and82(
9622
+ eq108(workspaceTables.workspaceId, run.workspaceId),
9413
9623
  inArray11(workspaceTables.id, grantIds(context, run, "tables"))
9414
9624
  )
9415
9625
  ).orderBy(asc9(workspaceTables.id)).all();
@@ -9426,15 +9636,15 @@ function projectData(context, run, body) {
9426
9636
  if (input2.operation !== "list_rows" && !grantIds(context, run, "tables", true).includes(table.id)) {
9427
9637
  throw new HttpError(403, "Resource is read only.");
9428
9638
  }
9429
- const matchesTable = and81(
9430
- eq106(tableRows.workspaceId, run.workspaceId),
9431
- eq106(tableRows.tableId, table.id)
9639
+ const matchesTable = and82(
9640
+ eq108(tableRows.workspaceId, run.workspaceId),
9641
+ eq108(tableRows.tableId, table.id)
9432
9642
  );
9433
9643
  if (input2.operation === "list_rows") {
9434
9644
  const rows = context.db.select().from(tableRows).where(matchesTable).orderBy(asc9(tableRows.id)).all();
9435
9645
  return paginateData(rows.map(rowView), input2.offset, input2.limit);
9436
9646
  }
9437
- const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(and81(matchesTable, eq106(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();
9438
9648
  if (input2.row_id !== void 0 && !row) {
9439
9649
  throw new HttpError(404, "Row not found.");
9440
9650
  }
@@ -9442,7 +9652,7 @@ function projectData(context, run, body) {
9442
9652
  throw new HttpError(409, "Row changed. Reload before saving.");
9443
9653
  }
9444
9654
  if (input2.operation === "delete_row") {
9445
- context.db.delete(tableRows).where(and81(matchesTable, eq106(tableRows.id, input2.row_id))).run();
9655
+ context.db.delete(tableRows).where(and82(matchesTable, eq108(tableRows.id, input2.row_id))).run();
9446
9656
  return { deleted: true };
9447
9657
  }
9448
9658
  if (table.revision !== input2.table_revision) {
@@ -9454,7 +9664,7 @@ function projectData(context, run, body) {
9454
9664
  values: input2.values,
9455
9665
  revision: row.revision + 1,
9456
9666
  updatedAt: now()
9457
- }).where(and81(matchesTable, eq106(tableRows.id, row.id))).returning().get();
9667
+ }).where(and82(matchesTable, eq108(tableRows.id, row.id))).returning().get();
9458
9668
  if (!updated) {
9459
9669
  throw new HttpError(404, "Row not found.");
9460
9670
  }
@@ -9498,7 +9708,7 @@ function handleProduct(ctx, run, route, method, body) {
9498
9708
  }
9499
9709
  if (method === "GET") {
9500
9710
  const items = ctx.db.select().from(table).where(
9501
- and82(eq107(table.workspaceId, run.workspaceId), eq107(table.runId, run.id))
9711
+ and83(eq109(table.workspaceId, run.workspaceId), eq109(table.runId, run.id))
9502
9712
  ).all();
9503
9713
  const view = (entry) => "prompt" in entry ? {
9504
9714
  id: entry.id,
@@ -9537,7 +9747,7 @@ function handleProduct(ctx, run, route, method, body) {
9537
9747
  status: "pending",
9538
9748
  decidedBy: null
9539
9749
  }).returning().get();
9540
- ctx.db.update(runs).set({ status: "waiting_approval" }).where(eq107(runs.id, run.id)).run();
9750
+ ctx.db.update(runs).set({ status: "waiting_approval" }).where(eq109(runs.id, run.id)).run();
9541
9751
  return json(
9542
9752
  {
9543
9753
  id: approval.id,
@@ -9575,7 +9785,7 @@ function handleProduct(ctx, run, route, method, body) {
9575
9785
  }
9576
9786
 
9577
9787
  // server/execution/register.ts
9578
- import { eq as eq108 } from "drizzle-orm";
9788
+ import { eq as eq110 } from "drizzle-orm";
9579
9789
  function register(ctx, worker, body) {
9580
9790
  const version2 = body.protocol_version;
9581
9791
  const capabilities = body.capabilities;
@@ -9599,20 +9809,20 @@ function register(ctx, worker, body) {
9599
9809
  capabilities: validatedCapabilities,
9600
9810
  lastSeenAt: now(),
9601
9811
  updatedAt: now()
9602
- }).where(eq108(executors.id, worker.id)).returning().get();
9812
+ }).where(eq110(executors.id, worker.id)).returning().get();
9603
9813
  return json(configuration(ctx, registered));
9604
9814
  }
9605
9815
 
9606
9816
  // server/execution/run-update.ts
9607
- import { and as and83, eq as eq109 } from "drizzle-orm";
9817
+ import { and as and84, eq as eq111 } from "drizzle-orm";
9608
9818
  function handleRunUpdate(ctx, run, action, body) {
9609
9819
  if (action === "heartbeat") {
9610
9820
  if (!terminal.has(run.status)) {
9611
9821
  if (run.executorId) {
9612
9822
  ctx.db.update(executors).set({ lastSeenAt: now() }).where(
9613
- and83(
9614
- eq109(executors.id, run.executorId),
9615
- eq109(executors.workspaceId, run.workspaceId)
9823
+ and84(
9824
+ eq111(executors.id, run.executorId),
9825
+ eq111(executors.workspaceId, run.workspaceId)
9616
9826
  )
9617
9827
  ).run();
9618
9828
  }
@@ -9621,7 +9831,7 @@ function handleRunUpdate(ctx, run, action, body) {
9621
9831
  leaseExpiresAt: new Date(
9622
9832
  Math.min(Date.now() + 6e4, Date.parse(run.deadline))
9623
9833
  ).toISOString()
9624
- }).where(eq109(runs.id, run.id)).run();
9834
+ }).where(eq111(runs.id, run.id)).run();
9625
9835
  }
9626
9836
  return json({
9627
9837
  status: run.status,
@@ -9639,9 +9849,9 @@ function handleRunUpdate(ctx, run, action, body) {
9639
9849
  "Event data"
9640
9850
  );
9641
9851
  const existing = ctx.db.select().from(runEvents).where(
9642
- and83(
9643
- eq109(runEvents.runId, run.id),
9644
- eq109(runEvents.sequence, body.sequence)
9852
+ and84(
9853
+ eq111(runEvents.runId, run.id),
9854
+ eq111(runEvents.sequence, body.sequence)
9645
9855
  )
9646
9856
  ).get();
9647
9857
  if (existing && (existing.kind !== body.kind || JSON.stringify(existing.data) !== JSON.stringify(data))) {
@@ -9695,13 +9905,13 @@ function handleRunUpdate(ctx, run, action, body) {
9695
9905
  );
9696
9906
  }
9697
9907
  const pending = ctx.db.select().from(approvals).where(
9698
- and83(eq109(approvals.runId, run.id), eq109(approvals.status, "pending"))
9908
+ and84(eq111(approvals.runId, run.id), eq111(approvals.status, "pending"))
9699
9909
  ).all();
9700
9910
  if (pending.length && status === "succeeded") {
9701
9911
  throw new HttpError(400, "Resolve pending approvals before completing.");
9702
9912
  }
9703
9913
  ctx.db.update(approvals).set({ status: "interrupted" }).where(
9704
- and83(eq109(approvals.runId, run.id), eq109(approvals.status, "pending"))
9914
+ and84(eq111(approvals.runId, run.id), eq111(approvals.status, "pending"))
9705
9915
  ).run();
9706
9916
  ctx.db.update(runs).set({
9707
9917
  status,
@@ -9709,7 +9919,7 @@ function handleRunUpdate(ctx, run, action, body) {
9709
9919
  error,
9710
9920
  cancelRequested: run.cancelRequested,
9711
9921
  updatedAt: now()
9712
- }).where(eq109(runs.id, run.id)).run();
9922
+ }).where(eq111(runs.id, run.id)).run();
9713
9923
  return new Response(null, { status: 204 });
9714
9924
  }
9715
9925
 
@@ -9763,7 +9973,7 @@ function handleWorker(ctx, route, method, body) {
9763
9973
  }
9764
9974
 
9765
9975
  // server/oauth/callback.ts
9766
- import { and as and84, eq as eq110 } from "drizzle-orm";
9976
+ import { and as and85, eq as eq112 } from "drizzle-orm";
9767
9977
  import { randomUUID as randomUUID7 } from "node:crypto";
9768
9978
  async function finishOAuth(ctx, input2, fetcher = fetch) {
9769
9979
  const workspace2 = authorize(ctx);
@@ -9777,14 +9987,14 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
9777
9987
  const state = field(input2.state, 500);
9778
9988
  const code = field(input2.code, 4e3);
9779
9989
  const attempt = inTransaction(ctx, (ctx2) => {
9780
- const record = ctx2.db.select().from(oauthAttempts).where(eq110(oauthAttempts.stateDigest, digest(state))).get();
9990
+ const record = ctx2.db.select().from(oauthAttempts).where(eq112(oauthAttempts.stateDigest, digest(state))).get();
9781
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)) {
9782
9992
  throw new ServiceError(
9783
9993
  "BAD_REQUEST",
9784
9994
  "This connection request has expired or belongs to another session."
9785
9995
  );
9786
9996
  }
9787
- ctx2.db.delete(oauthAttempts).where(eq110(oauthAttempts.stateDigest, record.stateDigest)).run();
9997
+ ctx2.db.delete(oauthAttempts).where(eq112(oauthAttempts.stateDigest, record.stateDigest)).run();
9788
9998
  return record;
9789
9999
  });
9790
10000
  const payload = JSON.parse(decrypt(ctx, attempt.encryptedPayload));
@@ -9809,9 +10019,9 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
9809
10019
  inTransaction(ctx, (ctx2) => {
9810
10020
  const session = identityRepository(ctx2.db).session(ctx2.sessionId);
9811
10021
  const plugin = ctx2.db.select().from(plugins).where(
9812
- and84(
9813
- eq110(plugins.id, attempt.pluginId),
9814
- eq110(plugins.workspaceId, workspace2.id)
10022
+ and85(
10023
+ eq112(plugins.id, attempt.pluginId),
10024
+ eq112(plugins.workspaceId, workspace2.id)
9815
10025
  )
9816
10026
  ).get();
9817
10027
  if (!session || session.userId !== user.id || session.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
@@ -9853,7 +10063,7 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
9853
10063
  createdAt: timestamp,
9854
10064
  updatedAt: timestamp
9855
10065
  }).run();
9856
- ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(eq110(plugins.id, plugin.id)).run();
10066
+ ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(eq112(plugins.id, plugin.id)).run();
9857
10067
  ctx2.db.insert(auditRecords).values({
9858
10068
  id: randomUUID7(),
9859
10069
  workspaceId: workspace2.id,
@@ -9911,7 +10121,7 @@ function publicRequest(request) {
9911
10121
  }
9912
10122
 
9913
10123
  // server/repositories/token-activity.ts
9914
- import { and as and85, eq as eq111, sql as sql4 } from "drizzle-orm";
10124
+ import { and as and86, eq as eq113, sql as sql4 } from "drizzle-orm";
9915
10125
  function recordTokenActivity(store, token, status, isMcp, hasFailed) {
9916
10126
  const time = (/* @__PURE__ */ new Date()).toISOString();
9917
10127
  store.db.update(accessTokens).set({
@@ -9924,9 +10134,9 @@ function recordTokenActivity(store, token, status, isMcp, hasFailed) {
9924
10134
  lastOutcome: hasFailed ? "error" : "success",
9925
10135
  lastStatusCode: status
9926
10136
  }).where(
9927
- and85(
9928
- eq111(accessTokens.id, token.id),
9929
- eq111(accessTokens.workspaceId, token.workspaceId)
10137
+ and86(
10138
+ eq113(accessTokens.id, token.id),
10139
+ eq113(accessTokens.workspaceId, token.workspaceId)
9930
10140
  )
9931
10141
  ).run();
9932
10142
  }
@@ -10027,7 +10237,7 @@ function errorResponse(error) {
10027
10237
  if (error instanceof ServiceError) {
10028
10238
  return json({ detail: error.message }, serviceErrorStatus[error.code]);
10029
10239
  }
10030
- if (error instanceof ZodError2) {
10240
+ if (error instanceof ZodError3) {
10031
10241
  return json({ detail: "Invalid input." }, 400);
10032
10242
  }
10033
10243
  if (error instanceof HttpError) {
@@ -10201,7 +10411,7 @@ function createApp(dependencies) {
10201
10411
  }
10202
10412
 
10203
10413
  // server/cli/accounts.ts
10204
- import { eq as eq112, or as or6 } from "drizzle-orm";
10414
+ import { eq as eq114, or as or6 } from "drizzle-orm";
10205
10415
  import { createInterface } from "node:readline/promises";
10206
10416
  import { Writable } from "node:stream";
10207
10417
  async function resetPassword(store, email) {
@@ -10242,9 +10452,9 @@ async function resetPassword(store, email) {
10242
10452
  }
10243
10453
  const passwordHash = await password.hash(password2);
10244
10454
  inTransaction(store, (store2) => {
10245
- store2.db.update(users).set({ passwordHash }).where(eq112(users.id, user.id)).run();
10455
+ store2.db.update(users).set({ passwordHash }).where(eq114(users.id, user.id)).run();
10246
10456
  store2.db.delete(sessions).where(
10247
- or6(eq112(sessions.userId, user.id), eq112(sessions.pendingUserId, user.id))
10457
+ or6(eq114(sessions.userId, user.id), eq114(sessions.pendingUserId, user.id))
10248
10458
  ).run();
10249
10459
  });
10250
10460
  console.log("Password changed. Existing sign-in sessions were revoked.");
@@ -10254,7 +10464,7 @@ async function resetPassword(store, email) {
10254
10464
  }
10255
10465
 
10256
10466
  // server/cli/database.ts
10257
- import { z as z56 } from "zod";
10467
+ import { z as z58 } from "zod";
10258
10468
 
10259
10469
  // server/db/connection.ts
10260
10470
  var driver = typeof Bun === "undefined" ? await import("./node-driver-75PFAG2L.js") : await import("./bun-driver-UOZIWBHK.js");
@@ -10264,7 +10474,7 @@ var openDatabase = driver.openDatabase;
10264
10474
  import { chmodSync, constants, copyFileSync, existsSync as existsSync4 } from "node:fs";
10265
10475
  import { join as join4 } from "node:path";
10266
10476
  function verifySnapshot(sqlite) {
10267
- 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());
10268
10478
  if (integrity.length !== 1 || integrity[0]?.integrity_check !== "ok") {
10269
10479
  throw new Error("Backup integrity check failed.");
10270
10480
  }
@@ -10412,9 +10622,9 @@ function openStore(dataDir2) {
10412
10622
  }
10413
10623
 
10414
10624
  // server/execution/maintenance.ts
10415
- import { z as z57 } from "zod";
10625
+ import { z as z59 } from "zod";
10416
10626
  import { CronExpressionParser as CronExpressionParser2 } from "cron-parser";
10417
- import { and as and86, eq as eq113, inArray as inArray12 } from "drizzle-orm";
10627
+ import { and as and87, eq as eq115, inArray as inArray12 } from "drizzle-orm";
10418
10628
  function maintenance(store) {
10419
10629
  const currentTime = now();
10420
10630
  inTransaction(store, (store2) => {
@@ -10426,22 +10636,22 @@ function maintenance(store) {
10426
10636
  error: "Execution stopped responding. Review side effects before retrying.",
10427
10637
  capabilityHash: "",
10428
10638
  updatedAt: currentTime
10429
- }).where(eq113(runs.id, run.id)).run();
10639
+ }).where(eq115(runs.id, run.id)).run();
10430
10640
  store2.db.update(approvals).set({ status: "interrupted" }).where(
10431
- and86(
10432
- eq113(approvals.runId, run.id),
10433
- eq113(approvals.status, "pending")
10641
+ and87(
10642
+ eq115(approvals.runId, run.id),
10643
+ eq115(approvals.status, "pending")
10434
10644
  )
10435
10645
  ).run();
10436
10646
  }
10437
10647
  }
10438
- for (const schedule of store2.db.select().from(schedules).where(eq113(schedules.enabled, true)).all()) {
10648
+ for (const schedule of store2.db.select().from(schedules).where(eq115(schedules.enabled, true)).all()) {
10439
10649
  if (schedule.nextRunAt > currentTime) {
10440
10650
  continue;
10441
10651
  }
10442
- const action = store2.db.select().from(actions).where(eq113(actions.id, schedule.actionId)).get();
10652
+ const action = store2.db.select().from(actions).where(eq115(actions.id, schedule.actionId)).get();
10443
10653
  if (!action) {
10444
- store2.db.update(schedules).set({ enabled: false }).where(eq113(schedules.id, schedule.id)).run();
10654
+ store2.db.update(schedules).set({ enabled: false }).where(eq115(schedules.id, schedule.id)).run();
10445
10655
  continue;
10446
10656
  }
10447
10657
  const nextRunAt = CronExpressionParser2.parse(schedule.cron, {
@@ -10472,16 +10682,16 @@ function maintenance(store) {
10472
10682
  project: action.projectId,
10473
10683
  operation: "action",
10474
10684
  action: action.id,
10475
- inputs: z57.record(z57.string(), z57.json()).parse(schedule.inputs),
10685
+ inputs: z59.record(z59.string(), z59.json()).parse(schedule.inputs),
10476
10686
  idempotency_key: `schedule:${schedule.id}:${schedule.nextRunAt}`
10477
10687
  });
10478
- store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq113(runs.id, run.id)).run();
10688
+ store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq115(runs.id, run.id)).run();
10479
10689
  } catch (error) {
10480
10690
  if (!(error instanceof ServiceError)) {
10481
10691
  throw error;
10482
10692
  }
10483
10693
  }
10484
- store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(eq113(schedules.id, schedule.id)).run();
10694
+ store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(eq115(schedules.id, schedule.id)).run();
10485
10695
  }
10486
10696
  });
10487
10697
  }