@orgsdk/cli 2.3.0 → 2.4.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.
- package/dist/server/index.js +261 -246
- package/dist/server/out/_next/static/chunks/{0tlox6w8yf345.css → 25_4kq7-d_fl-.css} +1 -1
- package/dist/server/out/accounts/2fa/__next._full.txt +2 -2
- package/dist/server/out/accounts/2fa/__next._tree.txt +2 -2
- package/dist/server/out/accounts/2fa/__next.accounts.2fa.__PAGE__.txt +2 -2
- package/dist/server/out/accounts/2fa/index.html +1 -1
- package/dist/server/out/accounts/2fa/index.txt +2 -2
- package/dist/server/out/accounts/email/__next._full.txt +2 -2
- package/dist/server/out/accounts/email/__next._tree.txt +2 -2
- package/dist/server/out/accounts/email/__next.accounts.email.__PAGE__.txt +2 -2
- package/dist/server/out/accounts/email/index.html +1 -1
- package/dist/server/out/accounts/email/index.txt +2 -2
- package/dist/server/out/accounts/login/__next._full.txt +2 -2
- package/dist/server/out/accounts/login/__next._tree.txt +2 -2
- package/dist/server/out/accounts/login/__next.accounts.login.__PAGE__.txt +2 -2
- package/dist/server/out/accounts/login/index.html +1 -1
- package/dist/server/out/accounts/login/index.txt +2 -2
- package/dist/server/out/accounts/logout/__next._full.txt +2 -2
- package/dist/server/out/accounts/logout/__next._tree.txt +2 -2
- package/dist/server/out/accounts/logout/__next.accounts.logout.__PAGE__.txt +2 -2
- package/dist/server/out/accounts/logout/index.html +1 -1
- package/dist/server/out/accounts/logout/index.txt +2 -2
- package/dist/server/out/accounts/password/change/__next._full.txt +2 -2
- package/dist/server/out/accounts/password/change/__next._tree.txt +2 -2
- package/dist/server/out/accounts/password/change/__next.accounts.password.change.__PAGE__.txt +2 -2
- package/dist/server/out/accounts/password/change/index.html +1 -1
- package/dist/server/out/accounts/password/change/index.txt +2 -2
- package/dist/server/out/accounts/password/reset/__next._full.txt +2 -2
- package/dist/server/out/accounts/password/reset/__next._tree.txt +2 -2
- package/dist/server/out/accounts/password/reset/__next.accounts.password.reset.__PAGE__.txt +2 -2
- package/dist/server/out/accounts/password/reset/index.html +1 -1
- package/dist/server/out/accounts/password/reset/index.txt +2 -2
- package/dist/server/out/accounts/signup/__next._full.txt +2 -2
- package/dist/server/out/accounts/signup/__next._tree.txt +2 -2
- package/dist/server/out/accounts/signup/__next.accounts.signup.__PAGE__.txt +2 -2
- package/dist/server/out/accounts/signup/index.html +1 -1
- package/dist/server/out/accounts/signup/index.txt +2 -2
- package/dist/server/out/setup/__next._full.txt +2 -2
- package/dist/server/out/setup/__next._tree.txt +2 -2
- package/dist/server/out/setup/__next.setup.__PAGE__.txt +2 -2
- package/dist/server/out/setup/index.html +1 -1
- package/dist/server/out/setup/index.txt +2 -2
- package/dist/server/out/studio/approve/__next._full.txt +2 -2
- package/dist/server/out/studio/approve/__next._tree.txt +2 -2
- package/dist/server/out/studio/approve/__next.studio.approve.__PAGE__.txt +2 -2
- package/dist/server/out/studio/approve/index.html +1 -1
- package/dist/server/out/studio/approve/index.txt +2 -2
- package/dist/server/out/workspaces/invite/__next._full.txt +2 -2
- package/dist/server/out/workspaces/invite/__next._tree.txt +2 -2
- package/dist/server/out/workspaces/invite/__next.workspaces.invite.__PAGE__.txt +2 -2
- package/dist/server/out/workspaces/invite/index.html +1 -1
- package/dist/server/out/workspaces/invite/index.txt +2 -2
- package/docs/studio.md +5 -3
- package/package.json +1 -1
- /package/dist/server/out/_next/static/{LKRuw_R6wl92CsuMfKtPZ → 6djYNpWGX3-5YRZkUZLdy}/_buildManifest.js +0 -0
- /package/dist/server/out/_next/static/{LKRuw_R6wl92CsuMfKtPZ → 6djYNpWGX3-5YRZkUZLdy}/_clientMiddlewareManifest.js +0 -0
- /package/dist/server/out/_next/static/{LKRuw_R6wl92CsuMfKtPZ → 6djYNpWGX3-5YRZkUZLdy}/_ssgManifest.js +0 -0
package/dist/server/index.js
CHANGED
|
@@ -1947,11 +1947,11 @@ var sourceText = (value) => {
|
|
|
1947
1947
|
};
|
|
1948
1948
|
function schema(value) {
|
|
1949
1949
|
const result = jsonValue(value ?? {}, "Schema");
|
|
1950
|
-
let
|
|
1950
|
+
let count3 = 0;
|
|
1951
1951
|
const pending = [[result, 0]];
|
|
1952
1952
|
while (pending.length) {
|
|
1953
1953
|
const [node, depth] = pending.pop();
|
|
1954
|
-
if (++
|
|
1954
|
+
if (++count3 > 2e3 || depth > 30) {
|
|
1955
1955
|
throw new ServiceError("BAD_REQUEST", "JSON Schema is too complex.");
|
|
1956
1956
|
}
|
|
1957
1957
|
if (object(node)) {
|
|
@@ -6198,19 +6198,32 @@ var exchange = publicProcedure.input(
|
|
|
6198
6198
|
var studioRouter = router({ approve, discover, exchange });
|
|
6199
6199
|
|
|
6200
6200
|
// server/platform/installation-update.ts
|
|
6201
|
-
import { inArray as inArray9 } from "drizzle-orm";
|
|
6201
|
+
import { and as and55, count, eq as eq73, inArray as inArray9 } from "drizzle-orm";
|
|
6202
6202
|
var managerHeartbeat = /* @__PURE__ */ new WeakMap();
|
|
6203
6203
|
var requested = /* @__PURE__ */ new WeakMap();
|
|
6204
|
+
var blockingRunStatuses = ["running", "waiting_approval"];
|
|
6204
6205
|
function canManageUpdate(ctx) {
|
|
6205
6206
|
return ctx.role === "owner" && !!ctx.sessionId && !ctx.token && process.env.ORGSDK_MANAGED_UPDATES === "1" && !!process.connected && isLoopbackInstallation(ctx.origin) && ctx.db.select({ id: workspaces.id }).from(workspaces).limit(2).all().length === 1;
|
|
6206
6207
|
}
|
|
6207
6208
|
function pendingUpdate(db) {
|
|
6208
6209
|
return requested.get(db) ?? null;
|
|
6209
6210
|
}
|
|
6211
|
+
function updateBlockers(db, workspaceId) {
|
|
6212
|
+
const blockers = db.select({ status: runs.status, total: count() }).from(runs).where(
|
|
6213
|
+
and55(
|
|
6214
|
+
eq73(runs.workspaceId, workspaceId),
|
|
6215
|
+
inArray9(runs.status, blockingRunStatuses)
|
|
6216
|
+
)
|
|
6217
|
+
).groupBy(runs.status).all();
|
|
6218
|
+
return {
|
|
6219
|
+
running: blockers.find(({ status }) => status === "running")?.total ?? 0,
|
|
6220
|
+
awaitingApproval: blockers.find(({ status }) => status === "waiting_approval")?.total ?? 0
|
|
6221
|
+
};
|
|
6222
|
+
}
|
|
6210
6223
|
function drainForUpdate(db, version2) {
|
|
6211
6224
|
requested.set(db, version2);
|
|
6212
6225
|
const timer = setInterval(() => {
|
|
6213
|
-
const busy = db.select({ id: runs.id }).from(runs).where(inArray9(runs.status,
|
|
6226
|
+
const busy = db.select({ id: runs.id }).from(runs).where(inArray9(runs.status, blockingRunStatuses)).limit(1).get();
|
|
6214
6227
|
if (busy) {
|
|
6215
6228
|
return;
|
|
6216
6229
|
}
|
|
@@ -6271,18 +6284,20 @@ function latestStable() {
|
|
|
6271
6284
|
}
|
|
6272
6285
|
|
|
6273
6286
|
// package.json
|
|
6274
|
-
var version = "2.
|
|
6287
|
+
var version = "2.4.1";
|
|
6275
6288
|
|
|
6276
6289
|
// server/router/system/update-status.ts
|
|
6277
6290
|
var updateStatus = browserWorkspaceProcedure.query(async ({ ctx }) => {
|
|
6278
6291
|
const latest = await latestStable();
|
|
6292
|
+
const pending = pendingUpdate(ctx.db);
|
|
6279
6293
|
return {
|
|
6280
6294
|
installed: version,
|
|
6281
6295
|
available: latest && newerStable(latest, version) ? latest : null,
|
|
6282
6296
|
executorReady: Date.now() - (managerHeartbeat.get(ctx.secrets) ?? 0) < 3e4,
|
|
6283
6297
|
checked: latest !== null,
|
|
6284
6298
|
automatic: canManageUpdate(ctx),
|
|
6285
|
-
pending
|
|
6299
|
+
pending,
|
|
6300
|
+
blockers: pending ? updateBlockers(ctx.db, ctx.workspace.id) : null,
|
|
6286
6301
|
failed: process.env.ORGSDK_FAILED_UPDATE ?? null
|
|
6287
6302
|
};
|
|
6288
6303
|
});
|
|
@@ -6333,7 +6348,7 @@ var systemRouter = router({
|
|
|
6333
6348
|
});
|
|
6334
6349
|
|
|
6335
6350
|
// server/router/tables/list.ts
|
|
6336
|
-
import { eq as
|
|
6351
|
+
import { eq as eq74 } from "drizzle-orm";
|
|
6337
6352
|
|
|
6338
6353
|
// server/tables/views.ts
|
|
6339
6354
|
function standard(row) {
|
|
@@ -6358,7 +6373,7 @@ function rowView(row) {
|
|
|
6358
6373
|
|
|
6359
6374
|
// server/router/tables/list.ts
|
|
6360
6375
|
var listProcedure12 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
6361
|
-
const records = ctx.db.select().from(workspaceTables).where(
|
|
6376
|
+
const records = ctx.db.select().from(workspaceTables).where(eq74(workspaceTables.workspaceId, ctx.workspace.id)).all();
|
|
6362
6377
|
return page(records.map((record) => standard(record)));
|
|
6363
6378
|
});
|
|
6364
6379
|
|
|
@@ -6425,15 +6440,15 @@ var createProcedure9 = browserManagerProcedure.input(createTableSchema).mutation
|
|
|
6425
6440
|
);
|
|
6426
6441
|
|
|
6427
6442
|
// server/router/tables/update.ts
|
|
6428
|
-
import { and as
|
|
6443
|
+
import { and as and57, eq as eq76 } from "drizzle-orm";
|
|
6429
6444
|
|
|
6430
6445
|
// server/tables/queries.ts
|
|
6431
|
-
import { and as
|
|
6446
|
+
import { and as and56, eq as eq75 } from "drizzle-orm";
|
|
6432
6447
|
function rowsForTable(database, workspaceId, tableId2) {
|
|
6433
6448
|
return database.select().from(tableRows).where(
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
|
|
6449
|
+
and56(
|
|
6450
|
+
eq75(tableRows.workspaceId, workspaceId),
|
|
6451
|
+
eq75(tableRows.tableId, tableId2)
|
|
6437
6452
|
)
|
|
6438
6453
|
).all();
|
|
6439
6454
|
}
|
|
@@ -6454,9 +6469,9 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
|
|
|
6454
6469
|
revision: current.revision + 1,
|
|
6455
6470
|
updatedAt: now()
|
|
6456
6471
|
}).where(
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6472
|
+
and57(
|
|
6473
|
+
eq76(workspaceTables.workspaceId, ctx2.workspace.id),
|
|
6474
|
+
eq76(workspaceTables.id, input2.id)
|
|
6460
6475
|
)
|
|
6461
6476
|
).returning().get();
|
|
6462
6477
|
if (!table) {
|
|
@@ -6469,14 +6484,14 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
|
|
|
6469
6484
|
});
|
|
6470
6485
|
|
|
6471
6486
|
// server/router/tables/delete.ts
|
|
6472
|
-
import { and as
|
|
6487
|
+
import { and as and59, eq as eq78 } from "drizzle-orm";
|
|
6473
6488
|
|
|
6474
6489
|
// server/repositories/table-rows.ts
|
|
6475
|
-
import { and as
|
|
6490
|
+
import { and as and58, eq as eq77 } from "drizzle-orm";
|
|
6476
6491
|
function removeTableRow(context, id) {
|
|
6477
6492
|
const workspaceId = requireWorkspace(context).id;
|
|
6478
6493
|
inTransaction(context, (transaction) => {
|
|
6479
|
-
const deleted = transaction.db.delete(tableRows).where(
|
|
6494
|
+
const deleted = transaction.db.delete(tableRows).where(and58(eq77(tableRows.workspaceId, workspaceId), eq77(tableRows.id, id))).returning({ id: tableRows.id }).get();
|
|
6480
6495
|
if (deleted) {
|
|
6481
6496
|
recordAudit(transaction, "row", id, "deleted");
|
|
6482
6497
|
}
|
|
@@ -6504,9 +6519,9 @@ var deleteProcedure6 = browserManagerProcedure.input(deleteTableSchema).mutation
|
|
|
6504
6519
|
});
|
|
6505
6520
|
}
|
|
6506
6521
|
const deleted = ctx2.db.delete(workspaceTables).where(
|
|
6507
|
-
|
|
6508
|
-
|
|
6509
|
-
|
|
6522
|
+
and59(
|
|
6523
|
+
eq78(workspaceTables.workspaceId, ctx2.workspace.id),
|
|
6524
|
+
eq78(workspaceTables.id, input2.id)
|
|
6510
6525
|
)
|
|
6511
6526
|
).returning({ id: workspaceTables.id }).get();
|
|
6512
6527
|
if (deleted) {
|
|
@@ -6523,13 +6538,13 @@ var listRowsProcedure = browserWorkspaceProcedure.input(tableIdSchema).query(({
|
|
|
6523
6538
|
});
|
|
6524
6539
|
|
|
6525
6540
|
// server/tables/access.ts
|
|
6526
|
-
import { and as
|
|
6541
|
+
import { and as and60, eq as eq79 } from "drizzle-orm";
|
|
6527
6542
|
function rowInTable(database, workspaceId, tableId2, rowId) {
|
|
6528
6543
|
const row = database.select().from(tableRows).where(
|
|
6529
|
-
|
|
6530
|
-
|
|
6531
|
-
|
|
6532
|
-
|
|
6544
|
+
and60(
|
|
6545
|
+
eq79(tableRows.workspaceId, workspaceId),
|
|
6546
|
+
eq79(tableRows.tableId, tableId2),
|
|
6547
|
+
eq79(tableRows.id, rowId)
|
|
6533
6548
|
)
|
|
6534
6549
|
).get();
|
|
6535
6550
|
if (!row) {
|
|
@@ -6564,7 +6579,7 @@ var createRowProcedure = browserWorkspaceProcedure.input(createRowSchema).mutati
|
|
|
6564
6579
|
});
|
|
6565
6580
|
|
|
6566
6581
|
// server/router/tables/update-row.ts
|
|
6567
|
-
import { and as
|
|
6582
|
+
import { and as and61, eq as eq80 } from "drizzle-orm";
|
|
6568
6583
|
var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutation(({ ctx, input: input2 }) => {
|
|
6569
6584
|
return rowView(
|
|
6570
6585
|
inTransaction(ctx, (ctx2) => {
|
|
@@ -6578,9 +6593,9 @@ var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutati
|
|
|
6578
6593
|
revision: row.revision + 1,
|
|
6579
6594
|
updatedAt: now()
|
|
6580
6595
|
}).where(
|
|
6581
|
-
|
|
6582
|
-
|
|
6583
|
-
|
|
6596
|
+
and61(
|
|
6597
|
+
eq80(tableRows.workspaceId, ctx2.workspace.id),
|
|
6598
|
+
eq80(tableRows.id, input2.rowId)
|
|
6584
6599
|
)
|
|
6585
6600
|
).returning().get();
|
|
6586
6601
|
if (!updatedRow) {
|
|
@@ -6620,7 +6635,7 @@ var tablesRouter = router({
|
|
|
6620
6635
|
});
|
|
6621
6636
|
|
|
6622
6637
|
// server/router/tokens/list.ts
|
|
6623
|
-
import { eq as
|
|
6638
|
+
import { eq as eq81 } from "drizzle-orm";
|
|
6624
6639
|
|
|
6625
6640
|
// server/tokens/views.ts
|
|
6626
6641
|
function tokenView(row) {
|
|
@@ -6648,18 +6663,18 @@ function tokenView(row) {
|
|
|
6648
6663
|
|
|
6649
6664
|
// server/router/tokens/list.ts
|
|
6650
6665
|
var listProcedure13 = browserManagerProcedure.query(({ ctx }) => {
|
|
6651
|
-
const records = ctx.db.select().from(accessTokens).where(
|
|
6666
|
+
const records = ctx.db.select().from(accessTokens).where(eq81(accessTokens.workspaceId, ctx.workspace.id)).all();
|
|
6652
6667
|
return page(records.map((record) => tokenView(record)));
|
|
6653
6668
|
});
|
|
6654
6669
|
|
|
6655
6670
|
// server/router/tokens/get.ts
|
|
6656
|
-
import { and as
|
|
6671
|
+
import { and as and62, eq as eq82 } from "drizzle-orm";
|
|
6657
6672
|
import { z as z41 } from "zod";
|
|
6658
6673
|
var getProcedure14 = browserManagerProcedure.input(z41.strictObject({ id: z41.uuid() })).query(({ ctx, input: input2 }) => {
|
|
6659
6674
|
const token = ctx.db.select().from(accessTokens).where(
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6675
|
+
and62(
|
|
6676
|
+
eq82(accessTokens.workspaceId, ctx.workspace.id),
|
|
6677
|
+
eq82(accessTokens.id, input2.id)
|
|
6663
6678
|
)
|
|
6664
6679
|
).get();
|
|
6665
6680
|
if (!token) {
|
|
@@ -6722,14 +6737,14 @@ var createProcedure10 = browserManagerProcedure.input(tokenCreateSchema).output(
|
|
|
6722
6737
|
});
|
|
6723
6738
|
|
|
6724
6739
|
// server/router/tokens/revoke.ts
|
|
6725
|
-
import { and as
|
|
6740
|
+
import { and as and63, eq as eq83 } from "drizzle-orm";
|
|
6726
6741
|
import { z as z43 } from "zod";
|
|
6727
6742
|
var revokeProcedure = browserManagerProcedure.input(z43.strictObject({ id: z43.uuid() })).mutation(({ ctx, input: input2 }) => {
|
|
6728
6743
|
return inTransaction(ctx, (ctx2) => {
|
|
6729
6744
|
const token = ctx2.db.update(accessTokens).set({ revoked: true, updatedAt: now() }).where(
|
|
6730
|
-
|
|
6731
|
-
|
|
6732
|
-
|
|
6745
|
+
and63(
|
|
6746
|
+
eq83(accessTokens.workspaceId, ctx2.workspace.id),
|
|
6747
|
+
eq83(accessTokens.id, input2.id)
|
|
6733
6748
|
)
|
|
6734
6749
|
).returning().get();
|
|
6735
6750
|
if (!token) {
|
|
@@ -6772,20 +6787,20 @@ var usersRouter = router({
|
|
|
6772
6787
|
});
|
|
6773
6788
|
|
|
6774
6789
|
// server/router/webhooks/list.ts
|
|
6775
|
-
import { eq as
|
|
6790
|
+
import { eq as eq85 } from "drizzle-orm";
|
|
6776
6791
|
|
|
6777
6792
|
// server/automations/webhook-view.ts
|
|
6778
|
-
import { desc as desc5, eq as
|
|
6779
|
-
import { and as
|
|
6793
|
+
import { desc as desc5, eq as eq84 } from "drizzle-orm";
|
|
6794
|
+
import { and as and64 } from "drizzle-orm";
|
|
6780
6795
|
function webhookView(context, webhook) {
|
|
6781
6796
|
const version2 = actionVersionsRepository(context).find(
|
|
6782
6797
|
webhook.actionVersionId
|
|
6783
6798
|
);
|
|
6784
6799
|
const action = actionsRepository(context).find(version2.actionId);
|
|
6785
6800
|
const deliveries = context.db.select().from(webhookDeliveries).where(
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6801
|
+
and64(
|
|
6802
|
+
eq84(webhookDeliveries.workspaceId, workspace(context)),
|
|
6803
|
+
eq84(webhookDeliveries.webhookId, webhook.id)
|
|
6789
6804
|
)
|
|
6790
6805
|
).orderBy(desc5(webhookDeliveries.createdAt)).limit(20).all();
|
|
6791
6806
|
return {
|
|
@@ -6814,7 +6829,7 @@ function webhookView(context, webhook) {
|
|
|
6814
6829
|
|
|
6815
6830
|
// server/router/webhooks/list.ts
|
|
6816
6831
|
var listProcedure14 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
6817
|
-
const records = ctx.db.select().from(webhooks).where(
|
|
6832
|
+
const records = ctx.db.select().from(webhooks).where(eq85(webhooks.workspaceId, ctx.workspace.id)).all();
|
|
6818
6833
|
return page(records.map((record) => webhookView(ctx, record)));
|
|
6819
6834
|
});
|
|
6820
6835
|
|
|
@@ -6822,11 +6837,11 @@ var listProcedure14 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6822
6837
|
import { z as z44 } from "zod";
|
|
6823
6838
|
|
|
6824
6839
|
// server/repositories/webhooks.ts
|
|
6825
|
-
import { and as
|
|
6840
|
+
import { and as and65, eq as eq86 } from "drizzle-orm";
|
|
6826
6841
|
function webhooksRepository(context) {
|
|
6827
6842
|
const workspaceId = requireWorkspace(context).id;
|
|
6828
6843
|
const database = context.db;
|
|
6829
|
-
const scoped = (id) =>
|
|
6844
|
+
const scoped = (id) => and65(eq86(webhooks.workspaceId, workspaceId), eq86(webhooks.id, id));
|
|
6830
6845
|
return {
|
|
6831
6846
|
find(id) {
|
|
6832
6847
|
const row = database.select().from(webhooks).where(scoped(id)).get();
|
|
@@ -6941,7 +6956,7 @@ var listProcedure15 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6941
6956
|
});
|
|
6942
6957
|
|
|
6943
6958
|
// server/router/workspace/current.ts
|
|
6944
|
-
import { eq as
|
|
6959
|
+
import { eq as eq87 } from "drizzle-orm";
|
|
6945
6960
|
|
|
6946
6961
|
// server/workspaces/views.ts
|
|
6947
6962
|
var serializeInvite = (invitation) => ({
|
|
@@ -6960,12 +6975,12 @@ var currentProcedure = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6960
6975
|
workspace: { id: workspace2.id, name: workspace2.name },
|
|
6961
6976
|
role: ctx.role,
|
|
6962
6977
|
members: memberQuery(ctx.db, workspace2.id).all(),
|
|
6963
|
-
invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(
|
|
6978
|
+
invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(eq87(invitations.workspaceId, workspace2.id)).all().map(serializeInvite) : []
|
|
6964
6979
|
};
|
|
6965
6980
|
});
|
|
6966
6981
|
|
|
6967
6982
|
// server/router/workspace/update.ts
|
|
6968
|
-
import { eq as
|
|
6983
|
+
import { eq as eq88 } from "drizzle-orm";
|
|
6969
6984
|
|
|
6970
6985
|
// server/workspaces/schemas.ts
|
|
6971
6986
|
import { z as z47 } from "zod";
|
|
@@ -7004,7 +7019,7 @@ var updateProcedure10 = browserManagerProcedure.input(workspaceNameSchema).mutat
|
|
|
7004
7019
|
"Only workspace owners and admins can manage this workspace."
|
|
7005
7020
|
);
|
|
7006
7021
|
}
|
|
7007
|
-
const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(
|
|
7022
|
+
const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(eq88(workspaces.id, workspace2.id)).returning().get();
|
|
7008
7023
|
return { id: updated.id, name: updated.name };
|
|
7009
7024
|
});
|
|
7010
7025
|
});
|
|
@@ -7032,13 +7047,13 @@ import { randomUUID as randomUUID5 } from "node:crypto";
|
|
|
7032
7047
|
import nodemailer from "nodemailer";
|
|
7033
7048
|
|
|
7034
7049
|
// server/repositories/mail-outbox.ts
|
|
7035
|
-
import { and as
|
|
7050
|
+
import { and as and66, asc as asc6, eq as eq89, isNull, lt as lt3, lte, or as or5 } from "drizzle-orm";
|
|
7036
7051
|
function enqueueMail(store, message) {
|
|
7037
7052
|
store.db.insert(mailOutbox).values({ ...message, nextAttempt: Date.now() }).run();
|
|
7038
7053
|
}
|
|
7039
7054
|
function revokeUnsentMail(store, id) {
|
|
7040
|
-
const unsent =
|
|
7041
|
-
|
|
7055
|
+
const unsent = and66(
|
|
7056
|
+
eq89(mailOutbox.id, id),
|
|
7042
7057
|
isNull(mailOutbox.sentAt),
|
|
7043
7058
|
isNull(mailOutbox.leaseUntil)
|
|
7044
7059
|
);
|
|
@@ -7050,7 +7065,7 @@ function claimMail(store, time) {
|
|
|
7050
7065
|
isNull(mailOutbox.leaseUntil),
|
|
7051
7066
|
lt3(mailOutbox.leaseUntil, time)
|
|
7052
7067
|
);
|
|
7053
|
-
const due =
|
|
7068
|
+
const due = and66(
|
|
7054
7069
|
isNull(mailOutbox.sentAt),
|
|
7055
7070
|
lte(mailOutbox.nextAttempt, time),
|
|
7056
7071
|
availableLease
|
|
@@ -7061,18 +7076,18 @@ function claimMail(store, time) {
|
|
|
7061
7076
|
}
|
|
7062
7077
|
if (row.id.startsWith("invitation:")) {
|
|
7063
7078
|
const id = Number(row.id.slice("invitation:".length));
|
|
7064
|
-
const invitation = store2.db.select().from(invitations).where(
|
|
7079
|
+
const invitation = store2.db.select().from(invitations).where(eq89(invitations.id, id)).get();
|
|
7065
7080
|
if (!invitation || invitation.acceptedAt || invitation.revokedAt || invitation.expiresAt <= new Date(time).toISOString()) {
|
|
7066
|
-
store2.db.delete(mailOutbox).where(
|
|
7081
|
+
store2.db.delete(mailOutbox).where(eq89(mailOutbox.id, row.id)).run();
|
|
7067
7082
|
return;
|
|
7068
7083
|
}
|
|
7069
7084
|
}
|
|
7070
|
-
store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(
|
|
7085
|
+
store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(eq89(mailOutbox.id, row.id)).run();
|
|
7071
7086
|
return row;
|
|
7072
7087
|
});
|
|
7073
7088
|
}
|
|
7074
7089
|
function markMailSent(store, id) {
|
|
7075
|
-
store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(
|
|
7090
|
+
store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(eq89(mailOutbox.id, id)).run();
|
|
7076
7091
|
}
|
|
7077
7092
|
function retryMail(store, job) {
|
|
7078
7093
|
const attempts = job.attempts + 1;
|
|
@@ -7082,7 +7097,7 @@ function retryMail(store, job) {
|
|
|
7082
7097
|
nextAttempt: Date.now() + delay,
|
|
7083
7098
|
leaseUntil: null,
|
|
7084
7099
|
lastError: "Delivery failed"
|
|
7085
|
-
}).where(
|
|
7100
|
+
}).where(eq89(mailOutbox.id, job.id)).run();
|
|
7086
7101
|
}
|
|
7087
7102
|
|
|
7088
7103
|
// server/mail/outbox.ts
|
|
@@ -7136,7 +7151,7 @@ async function flushOutbox(store, send) {
|
|
|
7136
7151
|
}
|
|
7137
7152
|
|
|
7138
7153
|
// server/router/workspace/invite.ts
|
|
7139
|
-
import { and as
|
|
7154
|
+
import { and as and67, eq as eq90, isNull as isNull2, sql as sql3 } from "drizzle-orm";
|
|
7140
7155
|
var inviteProcedure = browserManagerProcedure.input(invitationSchema).mutation(({ ctx, input: input2 }) => {
|
|
7141
7156
|
const user = ctx.user;
|
|
7142
7157
|
const workspace2 = ctx.workspace;
|
|
@@ -7174,9 +7189,9 @@ This invitation expires in seven days.`
|
|
|
7174
7189
|
"Only the owner can invite admins."
|
|
7175
7190
|
);
|
|
7176
7191
|
}
|
|
7177
|
-
const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users,
|
|
7178
|
-
|
|
7179
|
-
|
|
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),
|
|
7180
7195
|
sql3`lower(${users.email}) = ${email}`
|
|
7181
7196
|
)
|
|
7182
7197
|
).get();
|
|
@@ -7187,8 +7202,8 @@ This invitation expires in seven days.`
|
|
|
7187
7202
|
);
|
|
7188
7203
|
}
|
|
7189
7204
|
const prior = db.select({ id: invitations.id, expiresAt: invitations.expiresAt }).from(invitations).where(
|
|
7190
|
-
|
|
7191
|
-
|
|
7205
|
+
and67(
|
|
7206
|
+
eq90(invitations.workspaceId, workspace2.id),
|
|
7192
7207
|
sql3`lower(${invitations.email}) = ${email}`,
|
|
7193
7208
|
isNull2(invitations.acceptedAt),
|
|
7194
7209
|
isNull2(invitations.revokedAt)
|
|
@@ -7223,7 +7238,7 @@ This invitation expires in seven days.`
|
|
|
7223
7238
|
});
|
|
7224
7239
|
|
|
7225
7240
|
// server/router/workspace/revoke-invitation.ts
|
|
7226
|
-
import { and as
|
|
7241
|
+
import { and as and68, eq as eq91 } from "drizzle-orm";
|
|
7227
7242
|
var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
7228
7243
|
const id = input2.id;
|
|
7229
7244
|
const user = ctx.user;
|
|
@@ -7238,9 +7253,9 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
|
|
|
7238
7253
|
);
|
|
7239
7254
|
}
|
|
7240
7255
|
const invitation = ctx2.db.select().from(invitations).where(
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
|
|
7256
|
+
and68(
|
|
7257
|
+
eq91(invitations.workspaceId, workspace2.id),
|
|
7258
|
+
eq91(invitations.id, id)
|
|
7244
7259
|
)
|
|
7245
7260
|
).get();
|
|
7246
7261
|
if (!invitation) {
|
|
@@ -7261,7 +7276,7 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
|
|
|
7261
7276
|
});
|
|
7262
7277
|
|
|
7263
7278
|
// server/router/workspace/accept-invitation.ts
|
|
7264
|
-
import { and as
|
|
7279
|
+
import { and as and69, eq as eq92 } from "drizzle-orm";
|
|
7265
7280
|
var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTokenSchema).mutation(({ ctx, input: input2 }) => {
|
|
7266
7281
|
const token = input2.token;
|
|
7267
7282
|
const user = ctx.user;
|
|
@@ -7273,9 +7288,9 @@ var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTo
|
|
|
7273
7288
|
throw new ServiceError("NOT_FOUND", "Invitation not found.");
|
|
7274
7289
|
}
|
|
7275
7290
|
const invite = db.select().from(invitations).where(
|
|
7276
|
-
|
|
7277
|
-
|
|
7278
|
-
|
|
7291
|
+
and69(
|
|
7292
|
+
eq92(invitations.workspaceId, workspace2.id),
|
|
7293
|
+
eq92(invitations.tokenDigest, digest(token))
|
|
7279
7294
|
)
|
|
7280
7295
|
).get();
|
|
7281
7296
|
if (!invite) {
|
|
@@ -7356,7 +7371,7 @@ var updateMemberProcedure = browserOwnerProcedure.input(memberUpdateSchema).muta
|
|
|
7356
7371
|
});
|
|
7357
7372
|
|
|
7358
7373
|
// server/router/workspace/remove-member.ts
|
|
7359
|
-
import { and as
|
|
7374
|
+
import { and as and70, eq as eq93 } from "drizzle-orm";
|
|
7360
7375
|
var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
7361
7376
|
const id = input2.id;
|
|
7362
7377
|
inTransaction(ctx, (ctx2) => {
|
|
@@ -7369,9 +7384,9 @@ var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).
|
|
|
7369
7384
|
);
|
|
7370
7385
|
}
|
|
7371
7386
|
ctx2.db.delete(memberships).where(
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7387
|
+
and70(
|
|
7388
|
+
eq93(memberships.workspaceId, target.workspaceId),
|
|
7389
|
+
eq93(memberships.id, id)
|
|
7375
7390
|
)
|
|
7376
7391
|
).run();
|
|
7377
7392
|
});
|
|
@@ -8329,17 +8344,17 @@ async function handleMcp(ctx) {
|
|
|
8329
8344
|
|
|
8330
8345
|
// server/automations/ingress.ts
|
|
8331
8346
|
import { z as z50 } from "zod";
|
|
8332
|
-
import { and as
|
|
8347
|
+
import { and as and72, eq as eq95 } from "drizzle-orm";
|
|
8333
8348
|
import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
8334
8349
|
|
|
8335
8350
|
// server/repositories/webhook-deliveries.ts
|
|
8336
|
-
import { and as
|
|
8351
|
+
import { and as and71, eq as eq94 } from "drizzle-orm";
|
|
8337
8352
|
function webhookDeliveriesRepository(context) {
|
|
8338
8353
|
const workspaceId = requireWorkspace(context).id;
|
|
8339
8354
|
const database = context.db;
|
|
8340
|
-
const scoped = (id, filter) =>
|
|
8341
|
-
|
|
8342
|
-
id === void 0 ? void 0 :
|
|
8355
|
+
const scoped = (id, filter) => and71(
|
|
8356
|
+
eq94(webhookDeliveries.workspaceId, workspaceId),
|
|
8357
|
+
id === void 0 ? void 0 : eq94(webhookDeliveries.id, id),
|
|
8343
8358
|
filter
|
|
8344
8359
|
);
|
|
8345
8360
|
return {
|
|
@@ -8367,7 +8382,7 @@ async function handleWebhookIngress(ctx) {
|
|
|
8367
8382
|
if (ctx.request.method !== "POST") {
|
|
8368
8383
|
throw new HttpError(405, "Method not allowed.");
|
|
8369
8384
|
}
|
|
8370
|
-
const hook = ctx.db.select().from(webhooks).where(
|
|
8385
|
+
const hook = ctx.db.select().from(webhooks).where(eq95(webhooks.id, match[1])).get();
|
|
8371
8386
|
if (!hook || !ctx.workspace || hook.workspaceId !== ctx.workspace.id) {
|
|
8372
8387
|
throw new HttpError(404, "Webhook not found.");
|
|
8373
8388
|
}
|
|
@@ -8402,9 +8417,9 @@ async function handleWebhookIngress(ctx) {
|
|
|
8402
8417
|
jsonValue(payload.inputs, "Inputs");
|
|
8403
8418
|
const actor = identityRepository(ctx.db).user(hook.actorId);
|
|
8404
8419
|
const member = ctx.db.select().from(memberships).where(
|
|
8405
|
-
|
|
8406
|
-
|
|
8407
|
-
|
|
8420
|
+
and72(
|
|
8421
|
+
eq95(memberships.userId, hook.actorId),
|
|
8422
|
+
eq95(memberships.workspaceId, hook.workspaceId)
|
|
8408
8423
|
)
|
|
8409
8424
|
).get();
|
|
8410
8425
|
if (!hook.enabled || !actor || !member) {
|
|
@@ -8425,9 +8440,9 @@ async function handleWebhookIngress(ctx) {
|
|
|
8425
8440
|
throw new HttpError(403, "Webhook is unavailable.");
|
|
8426
8441
|
}
|
|
8427
8442
|
const old = webhookDeliveriesRepository(actorCtx2).list(
|
|
8428
|
-
|
|
8429
|
-
|
|
8430
|
-
|
|
8443
|
+
and72(
|
|
8444
|
+
eq95(webhookDeliveries.webhookId, hook.id),
|
|
8445
|
+
eq95(webhookDeliveries.deliveryId, delivery)
|
|
8431
8446
|
)
|
|
8432
8447
|
)[0];
|
|
8433
8448
|
if (old) {
|
|
@@ -8470,7 +8485,7 @@ async function handleWebhookIngress(ctx) {
|
|
|
8470
8485
|
}
|
|
8471
8486
|
|
|
8472
8487
|
// server/execution/authority.ts
|
|
8473
|
-
import { and as
|
|
8488
|
+
import { and as and73, eq as eq96 } from "drizzle-orm";
|
|
8474
8489
|
import { timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
8475
8490
|
var terminal = /* @__PURE__ */ new Set([
|
|
8476
8491
|
"succeeded",
|
|
@@ -8488,15 +8503,15 @@ function bearer(ctx) {
|
|
|
8488
8503
|
}
|
|
8489
8504
|
function executor(ctx) {
|
|
8490
8505
|
const row = ctx.db.select().from(executors).where(
|
|
8491
|
-
|
|
8492
|
-
|
|
8493
|
-
|
|
8506
|
+
and73(
|
|
8507
|
+
eq96(executors.tokenHash, digest(bearer(ctx))),
|
|
8508
|
+
eq96(executors.enabled, true)
|
|
8494
8509
|
)
|
|
8495
8510
|
).get();
|
|
8496
8511
|
const project = row && ctx.db.select().from(projects).where(
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8512
|
+
and73(
|
|
8513
|
+
eq96(projects.id, row.projectId),
|
|
8514
|
+
eq96(projects.workspaceId, row.workspaceId)
|
|
8500
8515
|
)
|
|
8501
8516
|
).get();
|
|
8502
8517
|
if (!row || !project?.enabled) {
|
|
@@ -8505,17 +8520,17 @@ function executor(ctx) {
|
|
|
8505
8520
|
return row;
|
|
8506
8521
|
}
|
|
8507
8522
|
function runCapability(ctx, expectedId) {
|
|
8508
|
-
const run = ctx.db.select().from(runs).where(
|
|
8523
|
+
const run = ctx.db.select().from(runs).where(eq96(runs.capabilityHash, digest(bearer(ctx)))).get();
|
|
8509
8524
|
const currentTime = now();
|
|
8510
8525
|
if (!run || expectedId && run.id !== expectedId || !run.deadline || run.deadline <= currentTime || !run.leaseExpiresAt || run.leaseExpiresAt <= currentTime) {
|
|
8511
8526
|
throw new HttpError(401, "Invalid or expired run capability.");
|
|
8512
8527
|
}
|
|
8513
|
-
const worker = run.executorId && ctx.db.select().from(executors).where(
|
|
8514
|
-
const project = ctx.db.select().from(projects).where(
|
|
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();
|
|
8515
8530
|
const member = ctx.db.select().from(memberships).where(
|
|
8516
|
-
|
|
8517
|
-
|
|
8518
|
-
|
|
8531
|
+
and73(
|
|
8532
|
+
eq96(memberships.workspaceId, run.workspaceId),
|
|
8533
|
+
eq96(memberships.userId, run.actorId)
|
|
8519
8534
|
)
|
|
8520
8535
|
).get();
|
|
8521
8536
|
if (!worker || !worker.enabled || worker.projectId !== run.projectId || !project?.enabled || !member) {
|
|
@@ -8535,9 +8550,9 @@ function runCapability(ctx, expectedId) {
|
|
|
8535
8550
|
if (!terminal.has(run.status) && !run.cancelRequested) {
|
|
8536
8551
|
const operation = object(command2) ? command2.operation : void 0;
|
|
8537
8552
|
const token = run.tokenId ? ctx.db.select().from(accessTokens).where(
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
|
|
8553
|
+
and73(
|
|
8554
|
+
eq96(accessTokens.workspaceId, run.workspaceId),
|
|
8555
|
+
eq96(accessTokens.id, run.tokenId)
|
|
8541
8556
|
)
|
|
8542
8557
|
).get() : void 0;
|
|
8543
8558
|
const tokenRevoked = run.tokenId && (!token || token.revoked || !token.projects.includes(run.projectId) || !token.scopes.includes("code:execute") || operation === "read" && !token.scopes.includes("runs:read"));
|
|
@@ -8578,11 +8593,11 @@ function live(run) {
|
|
|
8578
8593
|
}
|
|
8579
8594
|
function actorContext(ctx, run) {
|
|
8580
8595
|
const user = identityRepository(ctx.db).user(run.actorId) ?? null;
|
|
8581
|
-
const workspace2 = ctx.db.select().from(workspaces).where(
|
|
8596
|
+
const workspace2 = ctx.db.select().from(workspaces).where(eq96(workspaces.id, run.workspaceId)).get() ?? null;
|
|
8582
8597
|
const membership = ctx.db.select().from(memberships).where(
|
|
8583
|
-
|
|
8584
|
-
|
|
8585
|
-
|
|
8598
|
+
and73(
|
|
8599
|
+
eq96(memberships.workspaceId, run.workspaceId),
|
|
8600
|
+
eq96(memberships.userId, run.actorId)
|
|
8586
8601
|
)
|
|
8587
8602
|
).get();
|
|
8588
8603
|
if (!user || !workspace2 || !membership) {
|
|
@@ -8599,7 +8614,7 @@ function actorContext(ctx, run) {
|
|
|
8599
8614
|
}
|
|
8600
8615
|
|
|
8601
8616
|
// server/execution/bootstrap.ts
|
|
8602
|
-
import { eq as
|
|
8617
|
+
import { eq as eq97 } from "drizzle-orm";
|
|
8603
8618
|
import { createHmac as createHmac3, randomUUID as randomUUID6 } from "node:crypto";
|
|
8604
8619
|
function bootstrap(ctx) {
|
|
8605
8620
|
const configured = process.env.LOCAL_EXECUTOR_BOOTSTRAP_TOKEN;
|
|
@@ -8607,8 +8622,8 @@ function bootstrap(ctx) {
|
|
|
8607
8622
|
throw new HttpError(403, "Invalid local bootstrap credential.");
|
|
8608
8623
|
}
|
|
8609
8624
|
const registrations = [];
|
|
8610
|
-
for (const project of ctx.db.select().from(projects).where(
|
|
8611
|
-
let worker = ctx.db.select().from(executors).where(
|
|
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();
|
|
8612
8627
|
if (worker && (!worker.locallyManaged || !worker.enabled)) {
|
|
8613
8628
|
continue;
|
|
8614
8629
|
}
|
|
@@ -8628,7 +8643,7 @@ function bootstrap(ctx) {
|
|
|
8628
8643
|
}).returning().get();
|
|
8629
8644
|
}
|
|
8630
8645
|
const token = createHmac3("sha256", configured).update(`${worker.id}:${worker.registrationNonce}`).digest("hex");
|
|
8631
|
-
ctx.db.update(executors).set({ tokenHash: digest(token) }).where(
|
|
8646
|
+
ctx.db.update(executors).set({ tokenHash: digest(token) }).where(eq97(executors.id, worker.id)).run();
|
|
8632
8647
|
registrations.push({
|
|
8633
8648
|
agent_id: project.id,
|
|
8634
8649
|
executor_id: worker.id,
|
|
@@ -8640,21 +8655,21 @@ function bootstrap(ctx) {
|
|
|
8640
8655
|
}
|
|
8641
8656
|
|
|
8642
8657
|
// server/execution/claim.ts
|
|
8643
|
-
import { and as
|
|
8658
|
+
import { and as and74, asc as asc7, eq as eq98, inArray as inArray10 } from "drizzle-orm";
|
|
8644
8659
|
function claim(ctx, worker) {
|
|
8645
8660
|
ctx.db.update(executors).set({ lastSeenAt: now() }).where(
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
|
|
8661
|
+
and74(
|
|
8662
|
+
eq98(executors.id, worker.id),
|
|
8663
|
+
eq98(executors.workspaceId, worker.workspaceId)
|
|
8649
8664
|
)
|
|
8650
8665
|
).run();
|
|
8651
|
-
const setting = ctx.db.select().from(workspaceSettings).where(
|
|
8666
|
+
const setting = ctx.db.select().from(workspaceSettings).where(eq98(workspaceSettings.workspaceId, worker.workspaceId)).get();
|
|
8652
8667
|
if (setting && (!setting.enabled || setting.executionPool !== worker.pool)) {
|
|
8653
8668
|
return new Response(null, { status: 204 });
|
|
8654
8669
|
}
|
|
8655
8670
|
const active = ctx.db.select().from(runs).where(
|
|
8656
|
-
|
|
8657
|
-
|
|
8671
|
+
and74(
|
|
8672
|
+
eq98(runs.workspaceId, worker.workspaceId),
|
|
8658
8673
|
inArray10(runs.status, ["running", "waiting_approval"])
|
|
8659
8674
|
)
|
|
8660
8675
|
).all();
|
|
@@ -8662,10 +8677,10 @@ function claim(ctx, worker) {
|
|
|
8662
8677
|
return new Response(null, { status: 204 });
|
|
8663
8678
|
}
|
|
8664
8679
|
const candidates = ctx.db.select().from(runs).where(
|
|
8665
|
-
|
|
8666
|
-
|
|
8667
|
-
|
|
8668
|
-
|
|
8680
|
+
and74(
|
|
8681
|
+
eq98(runs.projectId, worker.projectId),
|
|
8682
|
+
eq98(runs.workspaceId, worker.workspaceId),
|
|
8683
|
+
eq98(runs.status, "queued")
|
|
8669
8684
|
)
|
|
8670
8685
|
).orderBy(asc7(runs.createdAt)).all();
|
|
8671
8686
|
for (const run of candidates) {
|
|
@@ -8677,18 +8692,18 @@ function claim(ctx, worker) {
|
|
|
8677
8692
|
continue;
|
|
8678
8693
|
}
|
|
8679
8694
|
const member = ctx.db.select().from(memberships).where(
|
|
8680
|
-
|
|
8681
|
-
|
|
8682
|
-
|
|
8695
|
+
and74(
|
|
8696
|
+
eq98(memberships.userId, run.actorId),
|
|
8697
|
+
eq98(memberships.workspaceId, run.workspaceId)
|
|
8683
8698
|
)
|
|
8684
8699
|
).get();
|
|
8685
|
-
const token = run.tokenId ? ctx.db.select().from(accessTokens).where(
|
|
8700
|
+
const token = run.tokenId ? ctx.db.select().from(accessTokens).where(eq98(accessTokens.id, run.tokenId)).get() : null;
|
|
8686
8701
|
if (!member || run.cancelRequested || run.tokenId && (!token || token.revoked)) {
|
|
8687
8702
|
ctx.db.update(runs).set({
|
|
8688
8703
|
status: "cancelled",
|
|
8689
8704
|
cancelRequested: true,
|
|
8690
8705
|
updatedAt: now()
|
|
8691
|
-
}).where(
|
|
8706
|
+
}).where(eq98(runs.id, run.id)).run();
|
|
8692
8707
|
continue;
|
|
8693
8708
|
}
|
|
8694
8709
|
const capability = randomSecret();
|
|
@@ -8700,7 +8715,7 @@ function claim(ctx, worker) {
|
|
|
8700
8715
|
deadline,
|
|
8701
8716
|
leaseExpiresAt: new Date(Date.now() + 6e4).toISOString(),
|
|
8702
8717
|
updatedAt: now()
|
|
8703
|
-
}).where(
|
|
8718
|
+
}).where(eq98(runs.id, run.id)).run();
|
|
8704
8719
|
return json({
|
|
8705
8720
|
protocol_version: protocol,
|
|
8706
8721
|
run_id: run.id,
|
|
@@ -8718,13 +8733,13 @@ function claim(ctx, worker) {
|
|
|
8718
8733
|
}
|
|
8719
8734
|
|
|
8720
8735
|
// server/execution/configuration.ts
|
|
8721
|
-
import { and as
|
|
8736
|
+
import { and as and75, eq as eq99 } from "drizzle-orm";
|
|
8722
8737
|
function pluginsFor(ctx, worker) {
|
|
8723
8738
|
return ctx.db.select().from(plugins).where(
|
|
8724
|
-
|
|
8725
|
-
|
|
8726
|
-
|
|
8727
|
-
|
|
8739
|
+
and75(
|
|
8740
|
+
eq99(plugins.workspaceId, worker.workspaceId),
|
|
8741
|
+
eq99(plugins.projectId, worker.projectId),
|
|
8742
|
+
eq99(plugins.enabled, true)
|
|
8728
8743
|
)
|
|
8729
8744
|
).all().filter(
|
|
8730
8745
|
(plugin) => plugin.distribution !== "mcp" || worker.protocolVersion >= 4
|
|
@@ -8752,11 +8767,11 @@ function configuration(ctx, worker) {
|
|
|
8752
8767
|
}
|
|
8753
8768
|
|
|
8754
8769
|
// server/execution/credentials.ts
|
|
8755
|
-
import { and as
|
|
8770
|
+
import { and as and78, eq as eq102 } from "drizzle-orm";
|
|
8756
8771
|
|
|
8757
8772
|
// server/mcp/oauth-refresh.ts
|
|
8758
8773
|
import { auth as auth3 } from "@modelcontextprotocol/client";
|
|
8759
|
-
import { and as
|
|
8774
|
+
import { and as and76, eq as eq100 } from "drizzle-orm";
|
|
8760
8775
|
var refreshes = /* @__PURE__ */ new WeakMap();
|
|
8761
8776
|
async function mcpExecutionSecret(ctx, credential) {
|
|
8762
8777
|
let pending = refreshes.get(ctx.db);
|
|
@@ -8778,9 +8793,9 @@ async function mcpExecutionSecret(ctx, credential) {
|
|
|
8778
8793
|
}
|
|
8779
8794
|
async function refresh(ctx, initial) {
|
|
8780
8795
|
const credential = ctx.db.select().from(credentials).where(
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8796
|
+
and76(
|
|
8797
|
+
eq100(credentials.id, initial.id),
|
|
8798
|
+
eq100(credentials.workspaceId, initial.workspaceId)
|
|
8784
8799
|
)
|
|
8785
8800
|
).get();
|
|
8786
8801
|
if (!credential) {
|
|
@@ -8811,9 +8826,9 @@ async function refresh(ctx, initial) {
|
|
|
8811
8826
|
encryptedSecret: encrypt(ctx, JSON.stringify(state)),
|
|
8812
8827
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
8813
8828
|
}).where(
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8829
|
+
and76(
|
|
8830
|
+
eq100(credentials.id, credential.id),
|
|
8831
|
+
eq100(credentials.encryptedSecret, credential.encryptedSecret)
|
|
8817
8832
|
)
|
|
8818
8833
|
).returning().get();
|
|
8819
8834
|
if (!updated) {
|
|
@@ -8838,7 +8853,7 @@ async function refresh(ctx, initial) {
|
|
|
8838
8853
|
|
|
8839
8854
|
// server/oauth/refresh.ts
|
|
8840
8855
|
import { z as z52 } from "zod";
|
|
8841
|
-
import { and as
|
|
8856
|
+
import { and as and77, eq as eq101 } from "drizzle-orm";
|
|
8842
8857
|
|
|
8843
8858
|
// server/oauth/tokens.ts
|
|
8844
8859
|
import { z as z51 } from "zod";
|
|
@@ -8930,9 +8945,9 @@ function recordSecretVersion(secret, credential) {
|
|
|
8930
8945
|
function assertExecutionSecretCurrent(store, credential, secret) {
|
|
8931
8946
|
const version2 = secretVersions.get(secret);
|
|
8932
8947
|
const current = store.db.select().from(credentials).where(
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8948
|
+
and77(
|
|
8949
|
+
eq101(credentials.id, credential.id),
|
|
8950
|
+
eq101(credentials.workspaceId, credential.workspaceId)
|
|
8936
8951
|
)
|
|
8937
8952
|
).get();
|
|
8938
8953
|
if (!version2 || !current || version2.id !== current.id || version2.workspaceId !== current.workspaceId || version2.provider !== current.provider || version2.encryptedSecret !== current.encryptedSecret) {
|
|
@@ -8974,9 +8989,9 @@ async function executionSecret(store, credential, fetcher = fetch) {
|
|
|
8974
8989
|
}
|
|
8975
8990
|
async function resolveExecutionSecret(store, initial, fetcher) {
|
|
8976
8991
|
const credential = store.db.select().from(credentials).where(
|
|
8977
|
-
|
|
8978
|
-
|
|
8979
|
-
|
|
8992
|
+
and77(
|
|
8993
|
+
eq101(credentials.id, initial.id),
|
|
8994
|
+
eq101(credentials.workspaceId, initial.workspaceId)
|
|
8980
8995
|
)
|
|
8981
8996
|
).get();
|
|
8982
8997
|
if (!credential || !provider(credential.provider)) {
|
|
@@ -9018,9 +9033,9 @@ async function resolveExecutionSecret(store, initial, fetcher) {
|
|
|
9018
9033
|
JSON.stringify(applyTokens(payload, tokens2))
|
|
9019
9034
|
);
|
|
9020
9035
|
const result = store.db.update(credentials).set({ encryptedSecret: updated, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(
|
|
9021
|
-
|
|
9022
|
-
|
|
9023
|
-
|
|
9036
|
+
and77(
|
|
9037
|
+
eq101(credentials.id, credential.id),
|
|
9038
|
+
eq101(credentials.encryptedSecret, credential.encryptedSecret)
|
|
9024
9039
|
)
|
|
9025
9040
|
).returning().get();
|
|
9026
9041
|
if (!result) {
|
|
@@ -9052,9 +9067,9 @@ async function serveCredential(ctx, credentialId) {
|
|
|
9052
9067
|
throw new HttpError(403, "Credential is outside this run capability.");
|
|
9053
9068
|
}
|
|
9054
9069
|
const credential2 = ctx.db.select().from(credentials).where(
|
|
9055
|
-
|
|
9056
|
-
|
|
9057
|
-
|
|
9070
|
+
and78(
|
|
9071
|
+
eq102(credentials.id, credentialId),
|
|
9072
|
+
eq102(credentials.workspaceId, run.workspaceId)
|
|
9058
9073
|
)
|
|
9059
9074
|
).get();
|
|
9060
9075
|
if (!credential2) {
|
|
@@ -9082,12 +9097,12 @@ async function serveCredential(ctx, credentialId) {
|
|
|
9082
9097
|
}
|
|
9083
9098
|
|
|
9084
9099
|
// server/execution/shell-policy.ts
|
|
9085
|
-
import { and as
|
|
9100
|
+
import { and as and79, asc as asc8, eq as eq104 } from "drizzle-orm";
|
|
9086
9101
|
import { z as z54 } from "zod";
|
|
9087
9102
|
|
|
9088
9103
|
// server/execution/redaction.ts
|
|
9089
9104
|
import { z as z53 } from "zod";
|
|
9090
|
-
import { eq as
|
|
9105
|
+
import { eq as eq103 } from "drizzle-orm";
|
|
9091
9106
|
function redact(ctx, workspaceId, value) {
|
|
9092
9107
|
const secrets = [];
|
|
9093
9108
|
const collect = (entry) => {
|
|
@@ -9099,7 +9114,7 @@ function redact(ctx, workspaceId, value) {
|
|
|
9099
9114
|
Object.values(entry).forEach(collect);
|
|
9100
9115
|
}
|
|
9101
9116
|
};
|
|
9102
|
-
for (const credential of ctx.db.select().from(credentials).where(
|
|
9117
|
+
for (const credential of ctx.db.select().from(credentials).where(eq103(credentials.workspaceId, workspaceId)).all()) {
|
|
9103
9118
|
collect(JSON.parse(decrypt(ctx, credential.encryptedSecret)));
|
|
9104
9119
|
}
|
|
9105
9120
|
secrets.sort((a, b) => b.length - a.length);
|
|
@@ -9144,11 +9159,11 @@ var invocation = z54.strictObject({
|
|
|
9144
9159
|
});
|
|
9145
9160
|
function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
|
|
9146
9161
|
const plugin = ctx.db.select().from(plugins).where(
|
|
9147
|
-
|
|
9148
|
-
|
|
9149
|
-
|
|
9150
|
-
|
|
9151
|
-
|
|
9162
|
+
and79(
|
|
9163
|
+
eq104(plugins.id, pluginId),
|
|
9164
|
+
eq104(plugins.projectId, run.projectId),
|
|
9165
|
+
eq104(plugins.workspaceId, run.workspaceId),
|
|
9166
|
+
eq104(plugins.enabled, true)
|
|
9152
9167
|
)
|
|
9153
9168
|
).get();
|
|
9154
9169
|
const agent = snapshotAgents(run.snapshot).find(
|
|
@@ -9165,29 +9180,29 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
|
|
|
9165
9180
|
if (!approvalId && method === "GET") {
|
|
9166
9181
|
return json(
|
|
9167
9182
|
ctx.db.select({ name: shellRules.executable }).from(shellRules).where(
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9183
|
+
and79(
|
|
9184
|
+
eq104(shellRules.pluginId, pluginId),
|
|
9185
|
+
eq104(shellRules.decision, "allow")
|
|
9171
9186
|
)
|
|
9172
9187
|
).orderBy(asc8(shellRules.executable)).all().map((rule2) => rule2.name)
|
|
9173
9188
|
);
|
|
9174
9189
|
}
|
|
9175
9190
|
if (approvalId && method === "GET") {
|
|
9176
9191
|
const row2 = ctx.db.select().from(approvals).where(
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
|
|
9192
|
+
and79(
|
|
9193
|
+
eq104(approvals.id, approvalId),
|
|
9194
|
+
eq104(approvals.workspaceId, run.workspaceId),
|
|
9195
|
+
eq104(approvals.runId, run.id)
|
|
9181
9196
|
)
|
|
9182
9197
|
).get();
|
|
9183
9198
|
if (row2?.shell?.pluginId !== plugin.id || row2.shell.digest !== plugin.digest) {
|
|
9184
9199
|
throw new HttpError(404, "Shell approval not found.");
|
|
9185
9200
|
}
|
|
9186
9201
|
const blocked = ctx.db.select().from(shellRules).where(
|
|
9187
|
-
|
|
9188
|
-
|
|
9189
|
-
|
|
9190
|
-
|
|
9202
|
+
and79(
|
|
9203
|
+
eq104(shellRules.pluginId, pluginId),
|
|
9204
|
+
eq104(shellRules.executable, row2.shell.executable),
|
|
9205
|
+
eq104(shellRules.decision, "block")
|
|
9191
9206
|
)
|
|
9192
9207
|
).get();
|
|
9193
9208
|
return json({
|
|
@@ -9204,9 +9219,9 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
|
|
|
9204
9219
|
}
|
|
9205
9220
|
const { executable, args } = parsed.data;
|
|
9206
9221
|
const rule = ctx.db.select().from(shellRules).where(
|
|
9207
|
-
|
|
9208
|
-
|
|
9209
|
-
|
|
9222
|
+
and79(
|
|
9223
|
+
eq104(shellRules.pluginId, pluginId),
|
|
9224
|
+
eq104(shellRules.executable, executable)
|
|
9210
9225
|
)
|
|
9211
9226
|
).get();
|
|
9212
9227
|
if (rule) {
|
|
@@ -9230,15 +9245,15 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
|
|
|
9230
9245
|
},
|
|
9231
9246
|
status: "pending"
|
|
9232
9247
|
}).returning().get();
|
|
9233
|
-
ctx.db.update(runs).set({ status: "waiting_approval", updatedAt: now() }).where(
|
|
9248
|
+
ctx.db.update(runs).set({ status: "waiting_approval", updatedAt: now() }).where(eq104(runs.id, run.id)).run();
|
|
9234
9249
|
return json({ id: row.id, status: row.status }, 201);
|
|
9235
9250
|
}
|
|
9236
9251
|
|
|
9237
9252
|
// server/execution/product.ts
|
|
9238
|
-
import { and as
|
|
9253
|
+
import { and as and82, eq as eq107 } from "drizzle-orm";
|
|
9239
9254
|
|
|
9240
9255
|
// server/execution/project-data.ts
|
|
9241
|
-
import { and as
|
|
9256
|
+
import { and as and81, asc as asc9, eq as eq106, inArray as inArray11 } from "drizzle-orm";
|
|
9242
9257
|
|
|
9243
9258
|
// server/execution/data-pagination.ts
|
|
9244
9259
|
function paginateData(items, offset, limit) {
|
|
@@ -9314,7 +9329,7 @@ var dataOperationSchema = z55.discriminatedUnion("operation", [
|
|
|
9314
9329
|
]);
|
|
9315
9330
|
|
|
9316
9331
|
// server/execution/run-grants.ts
|
|
9317
|
-
import { and as
|
|
9332
|
+
import { and as and80, eq as eq105 } from "drizzle-orm";
|
|
9318
9333
|
function grantIds(context, run, kind, write = false) {
|
|
9319
9334
|
const root2 = snapshotAgents(run.snapshot).find(
|
|
9320
9335
|
(agent) => agent.id === run.projectId
|
|
@@ -9325,9 +9340,9 @@ function grantIds(context, run, kind, write = false) {
|
|
|
9325
9340
|
...write ? [] : grants2?.read ?? []
|
|
9326
9341
|
];
|
|
9327
9342
|
const project = context.db.select().from(projects).where(
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9343
|
+
and80(
|
|
9344
|
+
eq105(projects.id, run.projectId),
|
|
9345
|
+
eq105(projects.workspaceId, run.workspaceId)
|
|
9331
9346
|
)
|
|
9332
9347
|
).get();
|
|
9333
9348
|
if (!project) {
|
|
@@ -9353,8 +9368,8 @@ function projectData(context, run, body) {
|
|
|
9353
9368
|
const documentOperation = input2.operation === "list_documents" || input2.operation === "get_document" || input2.operation === "write_document";
|
|
9354
9369
|
if (documentOperation) {
|
|
9355
9370
|
const accessibleDocuments = context.db.select().from(documents).where(
|
|
9356
|
-
|
|
9357
|
-
|
|
9371
|
+
and81(
|
|
9372
|
+
eq106(documents.workspaceId, run.workspaceId),
|
|
9358
9373
|
inArray11(documents.id, grantIds(context, run, "documents"))
|
|
9359
9374
|
)
|
|
9360
9375
|
).orderBy(asc9(documents.id)).all();
|
|
@@ -9382,9 +9397,9 @@ function projectData(context, run, body) {
|
|
|
9382
9397
|
content: input2.content ?? document.content,
|
|
9383
9398
|
updatedAt: now()
|
|
9384
9399
|
}).where(
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9400
|
+
and81(
|
|
9401
|
+
eq106(documents.id, document.id),
|
|
9402
|
+
eq106(documents.workspaceId, run.workspaceId)
|
|
9388
9403
|
)
|
|
9389
9404
|
).returning().get();
|
|
9390
9405
|
if (!updated) {
|
|
@@ -9393,8 +9408,8 @@ function projectData(context, run, body) {
|
|
|
9393
9408
|
return bounded(documentView2(updated));
|
|
9394
9409
|
}
|
|
9395
9410
|
const tables = context.db.select().from(workspaceTables).where(
|
|
9396
|
-
|
|
9397
|
-
|
|
9411
|
+
and81(
|
|
9412
|
+
eq106(workspaceTables.workspaceId, run.workspaceId),
|
|
9398
9413
|
inArray11(workspaceTables.id, grantIds(context, run, "tables"))
|
|
9399
9414
|
)
|
|
9400
9415
|
).orderBy(asc9(workspaceTables.id)).all();
|
|
@@ -9411,15 +9426,15 @@ function projectData(context, run, body) {
|
|
|
9411
9426
|
if (input2.operation !== "list_rows" && !grantIds(context, run, "tables", true).includes(table.id)) {
|
|
9412
9427
|
throw new HttpError(403, "Resource is read only.");
|
|
9413
9428
|
}
|
|
9414
|
-
const matchesTable =
|
|
9415
|
-
|
|
9416
|
-
|
|
9429
|
+
const matchesTable = and81(
|
|
9430
|
+
eq106(tableRows.workspaceId, run.workspaceId),
|
|
9431
|
+
eq106(tableRows.tableId, table.id)
|
|
9417
9432
|
);
|
|
9418
9433
|
if (input2.operation === "list_rows") {
|
|
9419
9434
|
const rows = context.db.select().from(tableRows).where(matchesTable).orderBy(asc9(tableRows.id)).all();
|
|
9420
9435
|
return paginateData(rows.map(rowView), input2.offset, input2.limit);
|
|
9421
9436
|
}
|
|
9422
|
-
const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(
|
|
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();
|
|
9423
9438
|
if (input2.row_id !== void 0 && !row) {
|
|
9424
9439
|
throw new HttpError(404, "Row not found.");
|
|
9425
9440
|
}
|
|
@@ -9427,7 +9442,7 @@ function projectData(context, run, body) {
|
|
|
9427
9442
|
throw new HttpError(409, "Row changed. Reload before saving.");
|
|
9428
9443
|
}
|
|
9429
9444
|
if (input2.operation === "delete_row") {
|
|
9430
|
-
context.db.delete(tableRows).where(
|
|
9445
|
+
context.db.delete(tableRows).where(and81(matchesTable, eq106(tableRows.id, input2.row_id))).run();
|
|
9431
9446
|
return { deleted: true };
|
|
9432
9447
|
}
|
|
9433
9448
|
if (table.revision !== input2.table_revision) {
|
|
@@ -9439,7 +9454,7 @@ function projectData(context, run, body) {
|
|
|
9439
9454
|
values: input2.values,
|
|
9440
9455
|
revision: row.revision + 1,
|
|
9441
9456
|
updatedAt: now()
|
|
9442
|
-
}).where(
|
|
9457
|
+
}).where(and81(matchesTable, eq106(tableRows.id, row.id))).returning().get();
|
|
9443
9458
|
if (!updated) {
|
|
9444
9459
|
throw new HttpError(404, "Row not found.");
|
|
9445
9460
|
}
|
|
@@ -9483,7 +9498,7 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9483
9498
|
}
|
|
9484
9499
|
if (method === "GET") {
|
|
9485
9500
|
const items = ctx.db.select().from(table).where(
|
|
9486
|
-
|
|
9501
|
+
and82(eq107(table.workspaceId, run.workspaceId), eq107(table.runId, run.id))
|
|
9487
9502
|
).all();
|
|
9488
9503
|
const view = (entry) => "prompt" in entry ? {
|
|
9489
9504
|
id: entry.id,
|
|
@@ -9522,7 +9537,7 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9522
9537
|
status: "pending",
|
|
9523
9538
|
decidedBy: null
|
|
9524
9539
|
}).returning().get();
|
|
9525
|
-
ctx.db.update(runs).set({ status: "waiting_approval" }).where(
|
|
9540
|
+
ctx.db.update(runs).set({ status: "waiting_approval" }).where(eq107(runs.id, run.id)).run();
|
|
9526
9541
|
return json(
|
|
9527
9542
|
{
|
|
9528
9543
|
id: approval.id,
|
|
@@ -9560,7 +9575,7 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9560
9575
|
}
|
|
9561
9576
|
|
|
9562
9577
|
// server/execution/register.ts
|
|
9563
|
-
import { eq as
|
|
9578
|
+
import { eq as eq108 } from "drizzle-orm";
|
|
9564
9579
|
function register(ctx, worker, body) {
|
|
9565
9580
|
const version2 = body.protocol_version;
|
|
9566
9581
|
const capabilities = body.capabilities;
|
|
@@ -9584,20 +9599,20 @@ function register(ctx, worker, body) {
|
|
|
9584
9599
|
capabilities: validatedCapabilities,
|
|
9585
9600
|
lastSeenAt: now(),
|
|
9586
9601
|
updatedAt: now()
|
|
9587
|
-
}).where(
|
|
9602
|
+
}).where(eq108(executors.id, worker.id)).returning().get();
|
|
9588
9603
|
return json(configuration(ctx, registered));
|
|
9589
9604
|
}
|
|
9590
9605
|
|
|
9591
9606
|
// server/execution/run-update.ts
|
|
9592
|
-
import { and as
|
|
9607
|
+
import { and as and83, eq as eq109 } from "drizzle-orm";
|
|
9593
9608
|
function handleRunUpdate(ctx, run, action, body) {
|
|
9594
9609
|
if (action === "heartbeat") {
|
|
9595
9610
|
if (!terminal.has(run.status)) {
|
|
9596
9611
|
if (run.executorId) {
|
|
9597
9612
|
ctx.db.update(executors).set({ lastSeenAt: now() }).where(
|
|
9598
|
-
|
|
9599
|
-
|
|
9600
|
-
|
|
9613
|
+
and83(
|
|
9614
|
+
eq109(executors.id, run.executorId),
|
|
9615
|
+
eq109(executors.workspaceId, run.workspaceId)
|
|
9601
9616
|
)
|
|
9602
9617
|
).run();
|
|
9603
9618
|
}
|
|
@@ -9606,7 +9621,7 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9606
9621
|
leaseExpiresAt: new Date(
|
|
9607
9622
|
Math.min(Date.now() + 6e4, Date.parse(run.deadline))
|
|
9608
9623
|
).toISOString()
|
|
9609
|
-
}).where(
|
|
9624
|
+
}).where(eq109(runs.id, run.id)).run();
|
|
9610
9625
|
}
|
|
9611
9626
|
return json({
|
|
9612
9627
|
status: run.status,
|
|
@@ -9624,9 +9639,9 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9624
9639
|
"Event data"
|
|
9625
9640
|
);
|
|
9626
9641
|
const existing = ctx.db.select().from(runEvents).where(
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9642
|
+
and83(
|
|
9643
|
+
eq109(runEvents.runId, run.id),
|
|
9644
|
+
eq109(runEvents.sequence, body.sequence)
|
|
9630
9645
|
)
|
|
9631
9646
|
).get();
|
|
9632
9647
|
if (existing && (existing.kind !== body.kind || JSON.stringify(existing.data) !== JSON.stringify(data))) {
|
|
@@ -9680,13 +9695,13 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9680
9695
|
);
|
|
9681
9696
|
}
|
|
9682
9697
|
const pending = ctx.db.select().from(approvals).where(
|
|
9683
|
-
|
|
9698
|
+
and83(eq109(approvals.runId, run.id), eq109(approvals.status, "pending"))
|
|
9684
9699
|
).all();
|
|
9685
9700
|
if (pending.length && status === "succeeded") {
|
|
9686
9701
|
throw new HttpError(400, "Resolve pending approvals before completing.");
|
|
9687
9702
|
}
|
|
9688
9703
|
ctx.db.update(approvals).set({ status: "interrupted" }).where(
|
|
9689
|
-
|
|
9704
|
+
and83(eq109(approvals.runId, run.id), eq109(approvals.status, "pending"))
|
|
9690
9705
|
).run();
|
|
9691
9706
|
ctx.db.update(runs).set({
|
|
9692
9707
|
status,
|
|
@@ -9694,7 +9709,7 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9694
9709
|
error,
|
|
9695
9710
|
cancelRequested: run.cancelRequested,
|
|
9696
9711
|
updatedAt: now()
|
|
9697
|
-
}).where(
|
|
9712
|
+
}).where(eq109(runs.id, run.id)).run();
|
|
9698
9713
|
return new Response(null, { status: 204 });
|
|
9699
9714
|
}
|
|
9700
9715
|
|
|
@@ -9748,7 +9763,7 @@ function handleWorker(ctx, route, method, body) {
|
|
|
9748
9763
|
}
|
|
9749
9764
|
|
|
9750
9765
|
// server/oauth/callback.ts
|
|
9751
|
-
import { and as
|
|
9766
|
+
import { and as and84, eq as eq110 } from "drizzle-orm";
|
|
9752
9767
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
9753
9768
|
async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
9754
9769
|
const workspace2 = authorize(ctx);
|
|
@@ -9762,14 +9777,14 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
|
9762
9777
|
const state = field(input2.state, 500);
|
|
9763
9778
|
const code = field(input2.code, 4e3);
|
|
9764
9779
|
const attempt = inTransaction(ctx, (ctx2) => {
|
|
9765
|
-
const record = ctx2.db.select().from(oauthAttempts).where(
|
|
9780
|
+
const record = ctx2.db.select().from(oauthAttempts).where(eq110(oauthAttempts.stateDigest, digest(state))).get();
|
|
9766
9781
|
if (!record || record.userId !== user.id || record.workspaceId !== workspace2.id || record.sessionId !== ctx2.sessionId || record.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
|
|
9767
9782
|
throw new ServiceError(
|
|
9768
9783
|
"BAD_REQUEST",
|
|
9769
9784
|
"This connection request has expired or belongs to another session."
|
|
9770
9785
|
);
|
|
9771
9786
|
}
|
|
9772
|
-
ctx2.db.delete(oauthAttempts).where(
|
|
9787
|
+
ctx2.db.delete(oauthAttempts).where(eq110(oauthAttempts.stateDigest, record.stateDigest)).run();
|
|
9773
9788
|
return record;
|
|
9774
9789
|
});
|
|
9775
9790
|
const payload = JSON.parse(decrypt(ctx, attempt.encryptedPayload));
|
|
@@ -9794,9 +9809,9 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
|
9794
9809
|
inTransaction(ctx, (ctx2) => {
|
|
9795
9810
|
const session = identityRepository(ctx2.db).session(ctx2.sessionId);
|
|
9796
9811
|
const plugin = ctx2.db.select().from(plugins).where(
|
|
9797
|
-
|
|
9798
|
-
|
|
9799
|
-
|
|
9812
|
+
and84(
|
|
9813
|
+
eq110(plugins.id, attempt.pluginId),
|
|
9814
|
+
eq110(plugins.workspaceId, workspace2.id)
|
|
9800
9815
|
)
|
|
9801
9816
|
).get();
|
|
9802
9817
|
if (!session || session.userId !== user.id || session.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
|
|
@@ -9838,7 +9853,7 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
|
9838
9853
|
createdAt: timestamp,
|
|
9839
9854
|
updatedAt: timestamp
|
|
9840
9855
|
}).run();
|
|
9841
|
-
ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(
|
|
9856
|
+
ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(eq110(plugins.id, plugin.id)).run();
|
|
9842
9857
|
ctx2.db.insert(auditRecords).values({
|
|
9843
9858
|
id: randomUUID7(),
|
|
9844
9859
|
workspaceId: workspace2.id,
|
|
@@ -9896,7 +9911,7 @@ function publicRequest(request) {
|
|
|
9896
9911
|
}
|
|
9897
9912
|
|
|
9898
9913
|
// server/repositories/token-activity.ts
|
|
9899
|
-
import { and as
|
|
9914
|
+
import { and as and85, eq as eq111, sql as sql4 } from "drizzle-orm";
|
|
9900
9915
|
function recordTokenActivity(store, token, status, isMcp, hasFailed) {
|
|
9901
9916
|
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
9902
9917
|
store.db.update(accessTokens).set({
|
|
@@ -9909,9 +9924,9 @@ function recordTokenActivity(store, token, status, isMcp, hasFailed) {
|
|
|
9909
9924
|
lastOutcome: hasFailed ? "error" : "success",
|
|
9910
9925
|
lastStatusCode: status
|
|
9911
9926
|
}).where(
|
|
9912
|
-
|
|
9913
|
-
|
|
9914
|
-
|
|
9927
|
+
and85(
|
|
9928
|
+
eq111(accessTokens.id, token.id),
|
|
9929
|
+
eq111(accessTokens.workspaceId, token.workspaceId)
|
|
9915
9930
|
)
|
|
9916
9931
|
).run();
|
|
9917
9932
|
}
|
|
@@ -10186,7 +10201,7 @@ function createApp(dependencies) {
|
|
|
10186
10201
|
}
|
|
10187
10202
|
|
|
10188
10203
|
// server/cli/accounts.ts
|
|
10189
|
-
import { eq as
|
|
10204
|
+
import { eq as eq112, or as or6 } from "drizzle-orm";
|
|
10190
10205
|
import { createInterface } from "node:readline/promises";
|
|
10191
10206
|
import { Writable } from "node:stream";
|
|
10192
10207
|
async function resetPassword(store, email) {
|
|
@@ -10227,9 +10242,9 @@ async function resetPassword(store, email) {
|
|
|
10227
10242
|
}
|
|
10228
10243
|
const passwordHash = await password.hash(password2);
|
|
10229
10244
|
inTransaction(store, (store2) => {
|
|
10230
|
-
store2.db.update(users).set({ passwordHash }).where(
|
|
10245
|
+
store2.db.update(users).set({ passwordHash }).where(eq112(users.id, user.id)).run();
|
|
10231
10246
|
store2.db.delete(sessions).where(
|
|
10232
|
-
or6(
|
|
10247
|
+
or6(eq112(sessions.userId, user.id), eq112(sessions.pendingUserId, user.id))
|
|
10233
10248
|
).run();
|
|
10234
10249
|
});
|
|
10235
10250
|
console.log("Password changed. Existing sign-in sessions were revoked.");
|
|
@@ -10307,7 +10322,7 @@ function restoreDatabase(dataDir2, source) {
|
|
|
10307
10322
|
}
|
|
10308
10323
|
|
|
10309
10324
|
// server/db/index.ts
|
|
10310
|
-
import { count, isNotNull, isNull as isNull3, or as or7 } from "drizzle-orm";
|
|
10325
|
+
import { count as count2, isNotNull, isNull as isNull3, or as or7 } from "drizzle-orm";
|
|
10311
10326
|
import { chmodSync as chmodSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readdirSync } from "node:fs";
|
|
10312
10327
|
import { join as join5 } from "node:path";
|
|
10313
10328
|
|
|
@@ -10372,15 +10387,15 @@ function openStore(dataDir2) {
|
|
|
10372
10387
|
connection.migrate(migrationsFolder);
|
|
10373
10388
|
if (!existsSync5(join5(dataDir2, "encryption.key"))) {
|
|
10374
10389
|
const protectedRows = [
|
|
10375
|
-
db.select({ count:
|
|
10376
|
-
db.select({ count:
|
|
10390
|
+
db.select({ count: count2() }).from(credentials).get()?.count ?? 0,
|
|
10391
|
+
db.select({ count: count2() }).from(users).where(
|
|
10377
10392
|
or7(
|
|
10378
10393
|
isNotNull(users.totpSecret),
|
|
10379
10394
|
isNotNull(users.pendingTotpSecret)
|
|
10380
10395
|
)
|
|
10381
10396
|
).get()?.count ?? 0,
|
|
10382
|
-
db.select({ count:
|
|
10383
|
-
db.select({ count:
|
|
10397
|
+
db.select({ count: count2() }).from(mailOutbox).where(isNull3(mailOutbox.sentAt)).get()?.count ?? 0,
|
|
10398
|
+
db.select({ count: count2() }).from(oauthAttempts).get()?.count ?? 0
|
|
10384
10399
|
];
|
|
10385
10400
|
if (protectedRows.some((total) => total > 0)) {
|
|
10386
10401
|
throw new Error(
|
|
@@ -10399,7 +10414,7 @@ function openStore(dataDir2) {
|
|
|
10399
10414
|
// server/execution/maintenance.ts
|
|
10400
10415
|
import { z as z57 } from "zod";
|
|
10401
10416
|
import { CronExpressionParser as CronExpressionParser2 } from "cron-parser";
|
|
10402
|
-
import { and as
|
|
10417
|
+
import { and as and86, eq as eq113, inArray as inArray12 } from "drizzle-orm";
|
|
10403
10418
|
function maintenance(store) {
|
|
10404
10419
|
const currentTime = now();
|
|
10405
10420
|
inTransaction(store, (store2) => {
|
|
@@ -10411,22 +10426,22 @@ function maintenance(store) {
|
|
|
10411
10426
|
error: "Execution stopped responding. Review side effects before retrying.",
|
|
10412
10427
|
capabilityHash: "",
|
|
10413
10428
|
updatedAt: currentTime
|
|
10414
|
-
}).where(
|
|
10429
|
+
}).where(eq113(runs.id, run.id)).run();
|
|
10415
10430
|
store2.db.update(approvals).set({ status: "interrupted" }).where(
|
|
10416
|
-
|
|
10417
|
-
|
|
10418
|
-
|
|
10431
|
+
and86(
|
|
10432
|
+
eq113(approvals.runId, run.id),
|
|
10433
|
+
eq113(approvals.status, "pending")
|
|
10419
10434
|
)
|
|
10420
10435
|
).run();
|
|
10421
10436
|
}
|
|
10422
10437
|
}
|
|
10423
|
-
for (const schedule of store2.db.select().from(schedules).where(
|
|
10438
|
+
for (const schedule of store2.db.select().from(schedules).where(eq113(schedules.enabled, true)).all()) {
|
|
10424
10439
|
if (schedule.nextRunAt > currentTime) {
|
|
10425
10440
|
continue;
|
|
10426
10441
|
}
|
|
10427
|
-
const action = store2.db.select().from(actions).where(
|
|
10442
|
+
const action = store2.db.select().from(actions).where(eq113(actions.id, schedule.actionId)).get();
|
|
10428
10443
|
if (!action) {
|
|
10429
|
-
store2.db.update(schedules).set({ enabled: false }).where(
|
|
10444
|
+
store2.db.update(schedules).set({ enabled: false }).where(eq113(schedules.id, schedule.id)).run();
|
|
10430
10445
|
continue;
|
|
10431
10446
|
}
|
|
10432
10447
|
const nextRunAt = CronExpressionParser2.parse(schedule.cron, {
|
|
@@ -10460,13 +10475,13 @@ function maintenance(store) {
|
|
|
10460
10475
|
inputs: z57.record(z57.string(), z57.json()).parse(schedule.inputs),
|
|
10461
10476
|
idempotency_key: `schedule:${schedule.id}:${schedule.nextRunAt}`
|
|
10462
10477
|
});
|
|
10463
|
-
store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(
|
|
10478
|
+
store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq113(runs.id, run.id)).run();
|
|
10464
10479
|
} catch (error) {
|
|
10465
10480
|
if (!(error instanceof ServiceError)) {
|
|
10466
10481
|
throw error;
|
|
10467
10482
|
}
|
|
10468
10483
|
}
|
|
10469
|
-
store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(
|
|
10484
|
+
store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(eq113(schedules.id, schedule.id)).run();
|
|
10470
10485
|
}
|
|
10471
10486
|
});
|
|
10472
10487
|
}
|