@orgsdk/cli 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/runtime/client.js +19 -0
- package/dist/runtime/contract.js +1 -0
- package/dist/runtime/plugins.js +16 -4
- package/dist/runtime/runner.js +16 -13
- package/dist/runtime/shell-policy.js +31 -0
- package/dist/server/{bun-driver-DTZUUCI3.js → bun-driver-UOZIWBHK.js} +1 -1
- package/dist/server/{chunk-S5SFX3JM.js → chunk-EXZNZYIJ.js} +13 -0
- package/dist/server/index.js +1075 -822
- package/dist/server/migrations/0004_shell_executable_policy.sql +9 -0
- package/dist/server/migrations/meta/0004_snapshot.json +3455 -0
- package/dist/server/migrations/meta/_journal.json +7 -0
- package/dist/server/{node-driver-HDJKKWXQ.js → node-driver-75PFAG2L.js} +1 -1
- package/dist/server/out/_next/static/chunks/0tlox6w8yf345.css +1 -0
- 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 +6 -0
- package/package.json +1 -1
- package/dist/server/out/_next/static/chunks/22w_ipn94al45.css +0 -1
- /package/dist/server/out/_next/static/{CkCrHy-m0W4Wo6_2T25_g → m1cOvyKRNnDjsWBMfcCJt}/_buildManifest.js +0 -0
- /package/dist/server/out/_next/static/{CkCrHy-m0W4Wo6_2T25_g → m1cOvyKRNnDjsWBMfcCJt}/_clientMiddlewareManifest.js +0 -0
- /package/dist/server/out/_next/static/{CkCrHy-m0W4Wo6_2T25_g → m1cOvyKRNnDjsWBMfcCJt}/_ssgManifest.js +0 -0
package/dist/server/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
runs,
|
|
23
23
|
schedules,
|
|
24
24
|
sessions,
|
|
25
|
+
shellRules,
|
|
25
26
|
tableRows,
|
|
26
27
|
users,
|
|
27
28
|
webhookDeliveries,
|
|
@@ -29,7 +30,7 @@ import {
|
|
|
29
30
|
workspaceSettings,
|
|
30
31
|
workspaceTables,
|
|
31
32
|
workspaces
|
|
32
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-EXZNZYIJ.js";
|
|
33
34
|
|
|
34
35
|
// server/platform/health.ts
|
|
35
36
|
import { get } from "node:http";
|
|
@@ -732,6 +733,8 @@ var agentsSchema = z4.array(
|
|
|
732
733
|
resources: z4.object({ tables: resourceGrant, documents: resourceGrant }).optional(),
|
|
733
734
|
plugins: z4.array(
|
|
734
735
|
z4.object({
|
|
736
|
+
shell_policy_id: z4.uuid().optional(),
|
|
737
|
+
digest: z4.string().optional(),
|
|
735
738
|
credential_id: z4.string().nullable().optional(),
|
|
736
739
|
distribution: z4.string().optional(),
|
|
737
740
|
mcp: z4.object({ id: z4.uuid() }).optional()
|
|
@@ -1176,7 +1179,7 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
|
1176
1179
|
import { ZodError as ZodError2 } from "zod";
|
|
1177
1180
|
|
|
1178
1181
|
// server/api/mcp-dispatch.ts
|
|
1179
|
-
import { z as
|
|
1182
|
+
import { z as z46 } from "zod";
|
|
1180
1183
|
|
|
1181
1184
|
// server/actions/schemas.ts
|
|
1182
1185
|
import { z as z8 } from "zod";
|
|
@@ -2339,7 +2342,81 @@ function findIdempotentRun(ctx, namespace, key) {
|
|
|
2339
2342
|
}
|
|
2340
2343
|
|
|
2341
2344
|
// server/runs/create.ts
|
|
2345
|
+
import { z as z16 } from "zod";
|
|
2346
|
+
|
|
2347
|
+
// server/plugins/shell-policy.ts
|
|
2348
|
+
import { and as and19, eq as eq20, gt as gt2, inArray as inArray5, sql } from "drizzle-orm";
|
|
2349
|
+
|
|
2350
|
+
// server/runs/resume-after-approval.ts
|
|
2351
|
+
import { and as and18, eq as eq19, notExists } from "drizzle-orm";
|
|
2352
|
+
function resumeAfterApproval(ctx, runId) {
|
|
2353
|
+
const pending = ctx.db.select({ id: approvals.id }).from(approvals).where(and18(eq19(approvals.runId, runId), eq19(approvals.status, "pending")));
|
|
2354
|
+
ctx.db.update(runs).set({ status: "running", updatedAt: now() }).where(
|
|
2355
|
+
and18(
|
|
2356
|
+
eq19(runs.id, runId),
|
|
2357
|
+
eq19(runs.status, "waiting_approval"),
|
|
2358
|
+
eq19(runs.cancelRequested, false),
|
|
2359
|
+
notExists(pending)
|
|
2360
|
+
)
|
|
2361
|
+
).run();
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
// server/plugins/shell-policy.ts
|
|
2342
2365
|
import { z as z15 } from "zod";
|
|
2366
|
+
var executableName = z15.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.+-]{0,127}$/);
|
|
2367
|
+
var ruleDecision = z15.enum(["allow", "block", "ask"]);
|
|
2368
|
+
function supportsShellPolicy(plugin) {
|
|
2369
|
+
const tools2 = plugin.releaseMetadata.tools;
|
|
2370
|
+
return plugin.slug === "shell" && plugin.distribution === "external" && Array.isArray(tools2) && tools2.some(
|
|
2371
|
+
(tool) => object(tool) && tool.name === "run" && object(tool.metadata) && tool.metadata.approval === "shell-executable"
|
|
2372
|
+
);
|
|
2373
|
+
}
|
|
2374
|
+
function writeShellRule(ctx, plugin, executable, decision) {
|
|
2375
|
+
const pluginId = plugin.id;
|
|
2376
|
+
if (decision === "ask") {
|
|
2377
|
+
ctx.db.delete(shellRules).where(
|
|
2378
|
+
and19(
|
|
2379
|
+
eq20(shellRules.pluginId, pluginId),
|
|
2380
|
+
eq20(shellRules.executable, executable)
|
|
2381
|
+
)
|
|
2382
|
+
).run();
|
|
2383
|
+
} else {
|
|
2384
|
+
ctx.db.insert(shellRules).values({ pluginId, executable, decision }).onConflictDoUpdate({
|
|
2385
|
+
target: [shellRules.pluginId, shellRules.executable],
|
|
2386
|
+
set: { decision }
|
|
2387
|
+
}).run();
|
|
2388
|
+
}
|
|
2389
|
+
if (decision !== "ask") {
|
|
2390
|
+
const currentTime = now();
|
|
2391
|
+
const liveRunIds = ctx.db.select({ id: runs.id }).from(runs).where(
|
|
2392
|
+
and19(
|
|
2393
|
+
eq20(runs.projectId, plugin.projectId),
|
|
2394
|
+
eq20(runs.workspaceId, plugin.workspaceId),
|
|
2395
|
+
eq20(runs.cancelRequested, false),
|
|
2396
|
+
eq20(runs.status, "waiting_approval"),
|
|
2397
|
+
gt2(runs.leaseExpiresAt, currentTime),
|
|
2398
|
+
gt2(runs.deadline, currentTime)
|
|
2399
|
+
)
|
|
2400
|
+
);
|
|
2401
|
+
const changed = ctx.db.update(approvals).set({
|
|
2402
|
+
status: decision === "allow" ? "approved" : "denied",
|
|
2403
|
+
decidedBy: ctx.user?.id,
|
|
2404
|
+
updatedAt: currentTime
|
|
2405
|
+
}).where(
|
|
2406
|
+
and19(
|
|
2407
|
+
eq20(approvals.workspaceId, plugin.workspaceId),
|
|
2408
|
+
eq20(approvals.status, "pending"),
|
|
2409
|
+
inArray5(approvals.runId, liveRunIds),
|
|
2410
|
+
sql`json_extract(${approvals.shell}, '$.pluginId') = ${plugin.id} and json_extract(${approvals.shell}, '$.digest') = ${plugin.digest} and json_extract(${approvals.shell}, '$.executable') = ${executable}`
|
|
2411
|
+
)
|
|
2412
|
+
).returning({ id: approvals.id, runId: approvals.runId }).all();
|
|
2413
|
+
for (const row of changed) {
|
|
2414
|
+
recordAudit(ctx, "approval", row.id, "updated");
|
|
2415
|
+
resumeAfterApproval(ctx, row.runId);
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
recordAudit(ctx, "shell_rule", pluginId + "/" + executable, decision);
|
|
2419
|
+
}
|
|
2343
2420
|
|
|
2344
2421
|
// server/projects/plugin-namespace.ts
|
|
2345
2422
|
function pluginNamespace(slug2) {
|
|
@@ -2429,6 +2506,7 @@ function projectConfiguration(ctx, projectId) {
|
|
|
2429
2506
|
configuration: plugin.configuration,
|
|
2430
2507
|
package_url: plugin.packageUrl,
|
|
2431
2508
|
contract_version: 1,
|
|
2509
|
+
...supportsShellPolicy(plugin) ? { shell_policy_id: plugin.id } : {},
|
|
2432
2510
|
...plugin.distribution === "mcp" ? { mcp: mcpSnapshot(ctx, plugin.id) } : {}
|
|
2433
2511
|
}));
|
|
2434
2512
|
const revision3 = digest(
|
|
@@ -2565,11 +2643,11 @@ function projectSnapshot(ctx, projectId, operation = "code") {
|
|
|
2565
2643
|
}
|
|
2566
2644
|
|
|
2567
2645
|
// server/repositories/runs.ts
|
|
2568
|
-
import { and as
|
|
2646
|
+
import { and as and20, eq as eq21 } from "drizzle-orm";
|
|
2569
2647
|
function runsRepository(context) {
|
|
2570
2648
|
const workspaceId = requireWorkspace(context).id;
|
|
2571
2649
|
const database = context.db;
|
|
2572
|
-
const scoped = (id) =>
|
|
2650
|
+
const scoped = (id) => and20(eq21(runs.workspaceId, workspaceId), eq21(runs.id, id));
|
|
2573
2651
|
return {
|
|
2574
2652
|
find(id) {
|
|
2575
2653
|
const row = database.select().from(runs).where(scoped(id)).get();
|
|
@@ -2601,22 +2679,22 @@ function runsRepository(context) {
|
|
|
2601
2679
|
}
|
|
2602
2680
|
|
|
2603
2681
|
// server/repositories/workspace-settings.ts
|
|
2604
|
-
import { eq as
|
|
2682
|
+
import { eq as eq22 } from "drizzle-orm";
|
|
2605
2683
|
function workspaceSettingsForWorkspace(database, workspaceId) {
|
|
2606
|
-
return database.select().from(workspaceSettings).where(
|
|
2684
|
+
return database.select().from(workspaceSettings).where(eq22(workspaceSettings.workspaceId, workspaceId)).get();
|
|
2607
2685
|
}
|
|
2608
2686
|
|
|
2609
2687
|
// server/runs/sessions.ts
|
|
2610
|
-
import { eq as
|
|
2688
|
+
import { eq as eq24 } from "drizzle-orm";
|
|
2611
2689
|
|
|
2612
2690
|
// server/repositories/executors.ts
|
|
2613
|
-
import { and as
|
|
2691
|
+
import { and as and21, eq as eq23 } from "drizzle-orm";
|
|
2614
2692
|
function executorsRepository(context) {
|
|
2615
2693
|
const workspaceId = requireWorkspace(context).id;
|
|
2616
2694
|
const database = context.db;
|
|
2617
|
-
const scoped = (id, filter) =>
|
|
2618
|
-
|
|
2619
|
-
id === void 0 ? void 0 :
|
|
2695
|
+
const scoped = (id, filter) => and21(
|
|
2696
|
+
eq23(executors.workspaceId, workspaceId),
|
|
2697
|
+
id === void 0 ? void 0 : eq23(executors.id, id),
|
|
2620
2698
|
filter
|
|
2621
2699
|
);
|
|
2622
2700
|
return {
|
|
@@ -2651,7 +2729,7 @@ function sessionSource(command2, input2) {
|
|
|
2651
2729
|
}
|
|
2652
2730
|
function requireSessionRunner(ctx, project, executionPool) {
|
|
2653
2731
|
const [runner] = executorsRepository(ctx).list(
|
|
2654
|
-
|
|
2732
|
+
eq24(executors.projectId, project)
|
|
2655
2733
|
);
|
|
2656
2734
|
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")) {
|
|
2657
2735
|
throw new ServiceError(
|
|
@@ -2742,7 +2820,7 @@ function createRunInTransaction(ctx, body) {
|
|
|
2742
2820
|
"Schemas are only accepted for validation jobs."
|
|
2743
2821
|
);
|
|
2744
2822
|
}
|
|
2745
|
-
const snapshot =
|
|
2823
|
+
const snapshot = z16.record(z16.string(), z16.json()).parse(projectSnapshot(ctx, project.id, operation));
|
|
2746
2824
|
const source = version?.source ?? (session ? sessionSource(session, body) : sourceText(body.source));
|
|
2747
2825
|
if (session) {
|
|
2748
2826
|
Object.assign(snapshot, {
|
|
@@ -2893,20 +2971,21 @@ var actionsRouter = router({
|
|
|
2893
2971
|
});
|
|
2894
2972
|
|
|
2895
2973
|
// server/router/approvals/list.ts
|
|
2896
|
-
import { eq as
|
|
2974
|
+
import { eq as eq25 } from "drizzle-orm";
|
|
2897
2975
|
|
|
2898
2976
|
// server/runs/approvals.ts
|
|
2899
|
-
import { z as
|
|
2900
|
-
var approvalIdSchema =
|
|
2901
|
-
var decideApprovalSchema =
|
|
2902
|
-
id:
|
|
2903
|
-
decision:
|
|
2977
|
+
import { z as z17 } from "zod";
|
|
2978
|
+
var approvalIdSchema = z17.strictObject({ id: z17.uuid() });
|
|
2979
|
+
var decideApprovalSchema = z17.strictObject({
|
|
2980
|
+
id: z17.uuid(),
|
|
2981
|
+
decision: z17.enum(["approved", "denied", "always_allow", "block"])
|
|
2904
2982
|
});
|
|
2905
2983
|
function approvalView(row) {
|
|
2906
2984
|
return {
|
|
2907
2985
|
id: row.id,
|
|
2908
2986
|
run: row.runId,
|
|
2909
2987
|
prompt: row.prompt,
|
|
2988
|
+
shell: row.shell ? { executable: row.shell.executable, project: row.shell.projectId } : null,
|
|
2910
2989
|
status: row.status,
|
|
2911
2990
|
decided_by: row.decidedBy
|
|
2912
2991
|
};
|
|
@@ -2914,16 +2993,16 @@ function approvalView(row) {
|
|
|
2914
2993
|
|
|
2915
2994
|
// server/router/approvals/list.ts
|
|
2916
2995
|
var listProcedure2 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
2917
|
-
const workspaceApprovals = ctx.db.select().from(approvals).where(
|
|
2996
|
+
const workspaceApprovals = ctx.db.select().from(approvals).where(eq25(approvals.workspaceId, ctx.workspace.id)).all();
|
|
2918
2997
|
return page(workspaceApprovals.map(approvalView));
|
|
2919
2998
|
});
|
|
2920
2999
|
|
|
2921
3000
|
// server/repositories/approvals.ts
|
|
2922
|
-
import { and as
|
|
3001
|
+
import { and as and22, eq as eq26 } from "drizzle-orm";
|
|
2923
3002
|
function approvalsRepository(context) {
|
|
2924
3003
|
const workspaceId = requireWorkspace(context).id;
|
|
2925
3004
|
const database = context.db;
|
|
2926
|
-
const scoped = (id) =>
|
|
3005
|
+
const scoped = (id) => and22(eq26(approvals.workspaceId, workspaceId), eq26(approvals.id, id));
|
|
2927
3006
|
return {
|
|
2928
3007
|
find(id) {
|
|
2929
3008
|
const row = database.select().from(approvals).where(scoped(id)).get();
|
|
@@ -2952,26 +3031,74 @@ var getProcedure2 = browserWorkspaceProcedure.input(approvalIdSchema).query(({ c
|
|
|
2952
3031
|
return approvalView(approvalsRepository(ctx).find(id));
|
|
2953
3032
|
});
|
|
2954
3033
|
|
|
3034
|
+
// server/repositories/plugins.ts
|
|
3035
|
+
import { and as and23, eq as eq27 } from "drizzle-orm";
|
|
3036
|
+
function pluginsRepository(context) {
|
|
3037
|
+
const workspaceId = requireWorkspace(context).id;
|
|
3038
|
+
const database = context.db;
|
|
3039
|
+
const scoped = (id, filter) => and23(
|
|
3040
|
+
eq27(plugins.workspaceId, workspaceId),
|
|
3041
|
+
id === void 0 ? void 0 : eq27(plugins.id, id),
|
|
3042
|
+
filter
|
|
3043
|
+
);
|
|
3044
|
+
return {
|
|
3045
|
+
find(id) {
|
|
3046
|
+
const row = database.select().from(plugins).where(scoped(id)).get();
|
|
3047
|
+
if (!row) {
|
|
3048
|
+
throw new ServiceError("NOT_FOUND", "Not found.");
|
|
3049
|
+
}
|
|
3050
|
+
return row;
|
|
3051
|
+
},
|
|
3052
|
+
list(filter) {
|
|
3053
|
+
return database.select().from(plugins).where(scoped(void 0, filter)).all();
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
|
|
2955
3058
|
// server/router/approvals/decide.ts
|
|
2956
|
-
var decideProcedure = browserManagerProcedure.input(decideApprovalSchema).mutation(
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
3059
|
+
var decideProcedure = browserManagerProcedure.input(decideApprovalSchema).mutation(
|
|
3060
|
+
({ ctx, input: input2 }) => inTransaction(ctx, (ctx2) => {
|
|
3061
|
+
assertCurrentPluginManager(ctx2);
|
|
3062
|
+
const approval = approvalsRepository(ctx2).find(input2.id);
|
|
3063
|
+
const run = runsRepository(ctx2).find(approval.runId);
|
|
3064
|
+
const currentTime = now();
|
|
3065
|
+
if (approval.status !== "pending" || run.cancelRequested || !["running", "waiting_approval"].includes(run.status) || run.deadline && run.deadline <= currentTime || run.leaseExpiresAt && run.leaseExpiresAt <= currentTime) {
|
|
3066
|
+
throw new ServiceError("CONFLICT", "Approval is no longer actionable.");
|
|
3067
|
+
}
|
|
3068
|
+
const persistent = input2.decision === "always_allow" || input2.decision === "block";
|
|
3069
|
+
if (persistent && !approval.shell) {
|
|
3070
|
+
throw new ServiceError(
|
|
3071
|
+
"BAD_REQUEST",
|
|
3072
|
+
"Persistent decisions require a Shell executable request."
|
|
3073
|
+
);
|
|
3074
|
+
}
|
|
3075
|
+
if (approval.shell) {
|
|
3076
|
+
const plugin = pluginsRepository(ctx2).find(approval.shell.pluginId);
|
|
3077
|
+
if (!plugin.enabled || !supportsShellPolicy(plugin) || plugin.projectId !== run.projectId || plugin.digest !== approval.shell.digest) {
|
|
2963
3078
|
throw new ServiceError(
|
|
2964
3079
|
"CONFLICT",
|
|
2965
|
-
"
|
|
3080
|
+
"The Shell installation changed since this request."
|
|
2966
3081
|
);
|
|
2967
3082
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
3083
|
+
if (persistent) {
|
|
3084
|
+
writeShellRule(
|
|
3085
|
+
ctx2,
|
|
3086
|
+
plugin,
|
|
3087
|
+
approval.shell.executable,
|
|
3088
|
+
input2.decision === "block" ? "block" : "allow"
|
|
3089
|
+
);
|
|
3090
|
+
return approvalView(approvalsRepository(ctx2).find(input2.id));
|
|
3091
|
+
}
|
|
3092
|
+
}
|
|
3093
|
+
const status = input2.decision === "denied" || input2.decision === "block" ? "denied" : "approved";
|
|
3094
|
+
const updated = approvalsRepository(ctx2).update(input2.id, {
|
|
3095
|
+
status,
|
|
3096
|
+
decidedBy: ctx2.user.id
|
|
3097
|
+
});
|
|
3098
|
+
resumeAfterApproval(ctx2, run.id);
|
|
3099
|
+
return approvalView(updated);
|
|
3100
|
+
})
|
|
3101
|
+
);
|
|
2975
3102
|
|
|
2976
3103
|
// server/router/approvals/index.ts
|
|
2977
3104
|
var approvalsRouter = router({
|
|
@@ -2981,11 +3108,11 @@ var approvalsRouter = router({
|
|
|
2981
3108
|
});
|
|
2982
3109
|
|
|
2983
3110
|
// server/router/artifacts/list.ts
|
|
2984
|
-
import { eq as
|
|
3111
|
+
import { eq as eq28 } from "drizzle-orm";
|
|
2985
3112
|
|
|
2986
3113
|
// server/runs/artifacts.ts
|
|
2987
|
-
import { z as
|
|
2988
|
-
var artifactIdSchema =
|
|
3114
|
+
import { z as z18 } from "zod";
|
|
3115
|
+
var artifactIdSchema = z18.strictObject({ id: z18.uuid() });
|
|
2989
3116
|
function artifactView(row) {
|
|
2990
3117
|
return {
|
|
2991
3118
|
id: row.id,
|
|
@@ -2998,17 +3125,17 @@ function artifactView(row) {
|
|
|
2998
3125
|
|
|
2999
3126
|
// server/router/artifacts/list.ts
|
|
3000
3127
|
var listProcedure3 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
3001
|
-
const workspaceArtifacts = ctx.db.select().from(artifacts).where(
|
|
3128
|
+
const workspaceArtifacts = ctx.db.select().from(artifacts).where(eq28(artifacts.workspaceId, ctx.workspace.id)).all();
|
|
3002
3129
|
return page(workspaceArtifacts.map(artifactView));
|
|
3003
3130
|
});
|
|
3004
3131
|
|
|
3005
3132
|
// server/router/artifacts/get.ts
|
|
3006
|
-
import { and as
|
|
3133
|
+
import { and as and24, eq as eq29 } from "drizzle-orm";
|
|
3007
3134
|
var getProcedure3 = browserWorkspaceProcedure.input(artifactIdSchema).query(({ ctx, input: input2 }) => {
|
|
3008
3135
|
const artifact = ctx.db.select().from(artifacts).where(
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3136
|
+
and24(
|
|
3137
|
+
eq29(artifacts.workspaceId, ctx.workspace.id),
|
|
3138
|
+
eq29(artifacts.id, input2.id)
|
|
3012
3139
|
)
|
|
3013
3140
|
).get();
|
|
3014
3141
|
if (!artifact) {
|
|
@@ -3024,10 +3151,10 @@ var artifactsRouter = router({
|
|
|
3024
3151
|
});
|
|
3025
3152
|
|
|
3026
3153
|
// server/router/audit/list.ts
|
|
3027
|
-
import { and as
|
|
3154
|
+
import { and as and26, desc as desc3, eq as eq31, gte, lt } from "drizzle-orm";
|
|
3028
3155
|
|
|
3029
3156
|
// server/audit/queries.ts
|
|
3030
|
-
import { and as
|
|
3157
|
+
import { and as and25, eq as eq30 } from "drizzle-orm";
|
|
3031
3158
|
function auditQueries(database, workspaceId) {
|
|
3032
3159
|
return {
|
|
3033
3160
|
actor(userId) {
|
|
@@ -3039,10 +3166,10 @@ function auditQueries(database, workspaceId) {
|
|
|
3039
3166
|
firstName: users.firstName,
|
|
3040
3167
|
lastName: users.lastName,
|
|
3041
3168
|
username: users.username
|
|
3042
|
-
}).from(memberships).innerJoin(users,
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3169
|
+
}).from(memberships).innerJoin(users, eq30(users.id, memberships.userId)).where(
|
|
3170
|
+
and25(
|
|
3171
|
+
eq30(memberships.workspaceId, workspaceId),
|
|
3172
|
+
eq30(memberships.userId, userId)
|
|
3046
3173
|
)
|
|
3047
3174
|
).get();
|
|
3048
3175
|
}
|
|
@@ -3050,13 +3177,13 @@ function auditQueries(database, workspaceId) {
|
|
|
3050
3177
|
}
|
|
3051
3178
|
|
|
3052
3179
|
// server/audit/schemas.ts
|
|
3053
|
-
import { z as
|
|
3054
|
-
var auditFiltersSchema =
|
|
3055
|
-
actor:
|
|
3056
|
-
kind:
|
|
3057
|
-
object_id:
|
|
3058
|
-
since:
|
|
3059
|
-
before:
|
|
3180
|
+
import { z as z19 } from "zod";
|
|
3181
|
+
var auditFiltersSchema = z19.object({
|
|
3182
|
+
actor: z19.number().int().positive().optional(),
|
|
3183
|
+
kind: z19.string().optional(),
|
|
3184
|
+
object_id: z19.string().optional(),
|
|
3185
|
+
since: z19.iso.datetime().optional(),
|
|
3186
|
+
before: z19.iso.datetime().optional()
|
|
3060
3187
|
}).strict().refine(
|
|
3061
3188
|
(input2) => !input2.since || !input2.before || Date.parse(input2.since) < Date.parse(input2.before),
|
|
3062
3189
|
"Invalid date range."
|
|
@@ -3078,11 +3205,11 @@ function auditView(record, actor) {
|
|
|
3078
3205
|
var listProcedure4 = browserManagerProcedure.input(auditFiltersSchema.optional().default({})).query(({ ctx, input: input2 }) => {
|
|
3079
3206
|
const queries = auditQueries(ctx.db, ctx.workspace.id);
|
|
3080
3207
|
const records = ctx.db.select().from(auditRecords).where(
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
input2.actor === void 0 ? void 0 :
|
|
3084
|
-
input2.kind === void 0 ? void 0 :
|
|
3085
|
-
input2.object_id === void 0 ? void 0 :
|
|
3208
|
+
and26(
|
|
3209
|
+
eq31(auditRecords.workspaceId, ctx.workspace.id),
|
|
3210
|
+
input2.actor === void 0 ? void 0 : eq31(auditRecords.actorId, input2.actor),
|
|
3211
|
+
input2.kind === void 0 ? void 0 : eq31(auditRecords.action, input2.kind),
|
|
3212
|
+
input2.object_id === void 0 ? void 0 : eq31(auditRecords.resource, input2.object_id),
|
|
3086
3213
|
input2.since === void 0 ? void 0 : gte(auditRecords.createdAt, input2.since),
|
|
3087
3214
|
input2.before === void 0 ? void 0 : lt(auditRecords.createdAt, input2.before)
|
|
3088
3215
|
)
|
|
@@ -3093,13 +3220,13 @@ var listProcedure4 = browserManagerProcedure.input(auditFiltersSchema.optional()
|
|
|
3093
3220
|
});
|
|
3094
3221
|
|
|
3095
3222
|
// server/router/audit/get.ts
|
|
3096
|
-
import { and as
|
|
3097
|
-
import { z as
|
|
3098
|
-
var getProcedure4 = browserManagerProcedure.input(
|
|
3223
|
+
import { and as and27, eq as eq32 } from "drizzle-orm";
|
|
3224
|
+
import { z as z20 } from "zod";
|
|
3225
|
+
var getProcedure4 = browserManagerProcedure.input(z20.strictObject({ id: z20.uuid() })).query(({ ctx, input: input2 }) => {
|
|
3099
3226
|
const record = ctx.db.select().from(auditRecords).where(
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3227
|
+
and27(
|
|
3228
|
+
eq32(auditRecords.workspaceId, ctx.workspace.id),
|
|
3229
|
+
eq32(auditRecords.id, input2.id)
|
|
3103
3230
|
)
|
|
3104
3231
|
).get();
|
|
3105
3232
|
if (!record) {
|
|
@@ -3148,16 +3275,16 @@ var password = {
|
|
|
3148
3275
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3149
3276
|
|
|
3150
3277
|
// server/auth/queries.ts
|
|
3151
|
-
import { eq as
|
|
3278
|
+
import { eq as eq33 } from "drizzle-orm";
|
|
3152
3279
|
function createAccount(database, values2) {
|
|
3153
3280
|
return database.insert(users).values(values2).returning().get();
|
|
3154
3281
|
}
|
|
3155
3282
|
function updateAccount(database, userId, changes) {
|
|
3156
|
-
return database.update(users).set(changes).where(
|
|
3283
|
+
return database.update(users).set(changes).where(eq33(users.id, userId)).returning().get();
|
|
3157
3284
|
}
|
|
3158
3285
|
|
|
3159
3286
|
// server/workspaces/queries.ts
|
|
3160
|
-
import { and as
|
|
3287
|
+
import { and as and28, eq as eq34 } from "drizzle-orm";
|
|
3161
3288
|
function memberQuery(database, workspaceId, id) {
|
|
3162
3289
|
return database.select({
|
|
3163
3290
|
id: memberships.id,
|
|
@@ -3165,24 +3292,24 @@ function memberQuery(database, workspaceId, id) {
|
|
|
3165
3292
|
email: users.email,
|
|
3166
3293
|
username: users.username,
|
|
3167
3294
|
role: memberships.role
|
|
3168
|
-
}).from(memberships).innerJoin(users,
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
id === void 0 ? void 0 :
|
|
3295
|
+
}).from(memberships).innerJoin(users, eq34(users.id, memberships.userId)).where(
|
|
3296
|
+
and28(
|
|
3297
|
+
eq34(memberships.workspaceId, workspaceId),
|
|
3298
|
+
id === void 0 ? void 0 : eq34(memberships.id, id)
|
|
3172
3299
|
)
|
|
3173
3300
|
);
|
|
3174
3301
|
}
|
|
3175
3302
|
function membershipForUser(database, workspaceId, userId) {
|
|
3176
3303
|
return database.select().from(memberships).where(
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3304
|
+
and28(
|
|
3305
|
+
eq34(memberships.workspaceId, workspaceId),
|
|
3306
|
+
eq34(memberships.userId, userId)
|
|
3180
3307
|
)
|
|
3181
3308
|
).get();
|
|
3182
3309
|
}
|
|
3183
3310
|
function membershipById(database, workspaceId, id) {
|
|
3184
3311
|
return database.select().from(memberships).where(
|
|
3185
|
-
|
|
3312
|
+
and28(eq34(memberships.workspaceId, workspaceId), eq34(memberships.id, id))
|
|
3186
3313
|
).get();
|
|
3187
3314
|
}
|
|
3188
3315
|
function createMembership(database, values2) {
|
|
@@ -3190,17 +3317,17 @@ function createMembership(database, values2) {
|
|
|
3190
3317
|
}
|
|
3191
3318
|
function setMembershipRole(database, workspaceId, id, role) {
|
|
3192
3319
|
database.update(memberships).set({ role }).where(
|
|
3193
|
-
|
|
3320
|
+
and28(eq34(memberships.workspaceId, workspaceId), eq34(memberships.id, id))
|
|
3194
3321
|
).run();
|
|
3195
3322
|
}
|
|
3196
3323
|
function updateInvitation(database, workspaceId, id, changes) {
|
|
3197
3324
|
database.update(invitations).set(changes).where(
|
|
3198
|
-
|
|
3325
|
+
and28(eq34(invitations.workspaceId, workspaceId), eq34(invitations.id, id))
|
|
3199
3326
|
).run();
|
|
3200
3327
|
}
|
|
3201
3328
|
|
|
3202
3329
|
// server/auth/schemas.ts
|
|
3203
|
-
import { z as
|
|
3330
|
+
import { z as z21 } from "zod";
|
|
3204
3331
|
|
|
3205
3332
|
// server/auth/validation.ts
|
|
3206
3333
|
function strongPassword(value) {
|
|
@@ -3211,38 +3338,38 @@ function validEmail(value) {
|
|
|
3211
3338
|
}
|
|
3212
3339
|
|
|
3213
3340
|
// server/auth/schemas.ts
|
|
3214
|
-
var emailSchema =
|
|
3215
|
-
var passwordSchema =
|
|
3216
|
-
var loginSchema =
|
|
3217
|
-
email:
|
|
3218
|
-
password:
|
|
3219
|
-
});
|
|
3220
|
-
var codeSchema =
|
|
3221
|
-
var signupSchema =
|
|
3341
|
+
var emailSchema = z21.string().refine(validEmail, "Enter a valid email address.");
|
|
3342
|
+
var passwordSchema = z21.string().refine(strongPassword, "Choose a stronger password.");
|
|
3343
|
+
var loginSchema = z21.strictObject({
|
|
3344
|
+
email: z21.string(),
|
|
3345
|
+
password: z21.string().max(1024)
|
|
3346
|
+
});
|
|
3347
|
+
var codeSchema = z21.strictObject({ code: z21.string() });
|
|
3348
|
+
var signupSchema = z21.strictObject({
|
|
3222
3349
|
email: emailSchema,
|
|
3223
|
-
username:
|
|
3350
|
+
username: z21.string().trim().min(1).max(150),
|
|
3224
3351
|
password: passwordSchema
|
|
3225
3352
|
});
|
|
3226
|
-
var setupSchema =
|
|
3227
|
-
domain:
|
|
3228
|
-
workspace_name:
|
|
3229
|
-
username:
|
|
3353
|
+
var setupSchema = z21.strictObject({
|
|
3354
|
+
domain: z21.string(),
|
|
3355
|
+
workspace_name: z21.string().trim().min(1),
|
|
3356
|
+
username: z21.string().trim().min(1),
|
|
3230
3357
|
email: emailSchema,
|
|
3231
3358
|
password1: passwordSchema,
|
|
3232
|
-
password2:
|
|
3233
|
-
project_name:
|
|
3359
|
+
password2: z21.string(),
|
|
3360
|
+
project_name: z21.string().optional()
|
|
3234
3361
|
}).refine((body) => body.password1 === body.password2, "Passwords must match.");
|
|
3235
|
-
var passwordChangeSchema =
|
|
3236
|
-
current_password:
|
|
3362
|
+
var passwordChangeSchema = z21.strictObject({
|
|
3363
|
+
current_password: z21.string().max(1024),
|
|
3237
3364
|
new_password: passwordSchema
|
|
3238
3365
|
});
|
|
3239
|
-
var emailChangeSchema =
|
|
3240
|
-
var reauthenticationSchema =
|
|
3241
|
-
password:
|
|
3366
|
+
var emailChangeSchema = z21.strictObject({ email: emailSchema });
|
|
3367
|
+
var reauthenticationSchema = z21.strictObject({
|
|
3368
|
+
password: z21.string().max(1024)
|
|
3242
3369
|
});
|
|
3243
|
-
var profileSchema =
|
|
3244
|
-
first_name:
|
|
3245
|
-
last_name:
|
|
3370
|
+
var profileSchema = z21.strictObject({
|
|
3371
|
+
first_name: z21.string().optional(),
|
|
3372
|
+
last_name: z21.string().optional()
|
|
3246
3373
|
});
|
|
3247
3374
|
|
|
3248
3375
|
// server/router/auth/setup.ts
|
|
@@ -3386,10 +3513,10 @@ function identityContext(ctx) {
|
|
|
3386
3513
|
}
|
|
3387
3514
|
|
|
3388
3515
|
// server/repositories/auth-attempts.ts
|
|
3389
|
-
import { eq as
|
|
3516
|
+
import { eq as eq35, sql as sql2 } from "drizzle-orm";
|
|
3390
3517
|
function recordAuthAttempt(store, key, time) {
|
|
3391
3518
|
inTransaction(store, (store2) => {
|
|
3392
|
-
const current = store2.db.select().from(authAttempts).where(
|
|
3519
|
+
const current = store2.db.select().from(authAttempts).where(eq35(authAttempts.key, key)).get();
|
|
3393
3520
|
if (current && current.expiresAt > time && current.count >= 10) {
|
|
3394
3521
|
throw new ServiceError(
|
|
3395
3522
|
"TOO_MANY_REQUESTS",
|
|
@@ -3403,7 +3530,7 @@ function recordAuthAttempt(store, key, time) {
|
|
|
3403
3530
|
}).run();
|
|
3404
3531
|
return;
|
|
3405
3532
|
}
|
|
3406
|
-
store2.db.update(authAttempts).set({ count:
|
|
3533
|
+
store2.db.update(authAttempts).set({ count: sql2`${authAttempts.count} + 1` }).where(eq35(authAttempts.key, key)).run();
|
|
3407
3534
|
});
|
|
3408
3535
|
}
|
|
3409
3536
|
|
|
@@ -3448,12 +3575,12 @@ var loginProcedure = browserProcedure.input(loginSchema).mutation(async ({ ctx:
|
|
|
3448
3575
|
});
|
|
3449
3576
|
|
|
3450
3577
|
// server/router/auth/logout.ts
|
|
3451
|
-
import { eq as
|
|
3578
|
+
import { eq as eq36 } from "drizzle-orm";
|
|
3452
3579
|
var logoutProcedure = browserProcedure.mutation(
|
|
3453
3580
|
({ ctx: requestContext }) => {
|
|
3454
3581
|
const ctx = identityContext(requestContext);
|
|
3455
3582
|
if (ctx.sessionId) {
|
|
3456
|
-
ctx.db.delete(sessions).where(
|
|
3583
|
+
ctx.db.delete(sessions).where(eq36(sessions.id, ctx.sessionId)).run();
|
|
3457
3584
|
}
|
|
3458
3585
|
ctx.sessionId = null;
|
|
3459
3586
|
ctx.user = null;
|
|
@@ -3495,8 +3622,8 @@ var signupProcedure = browserProcedure.input(signupSchema).mutation(async ({ ctx
|
|
|
3495
3622
|
});
|
|
3496
3623
|
|
|
3497
3624
|
// server/auth/totp.ts
|
|
3498
|
-
import { z as
|
|
3499
|
-
import { eq as
|
|
3625
|
+
import { z as z22 } from "zod";
|
|
3626
|
+
import { eq as eq37 } from "drizzle-orm";
|
|
3500
3627
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
3501
3628
|
var base32Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
3502
3629
|
function base32(bytes) {
|
|
@@ -3555,16 +3682,16 @@ function consumeCode(ctx, user, code) {
|
|
|
3555
3682
|
}
|
|
3556
3683
|
const step = totpCounter(decrypt(ctx2, current.totpSecret), code);
|
|
3557
3684
|
if (step !== null && (current.totpLastCounter === null || step > current.totpLastCounter)) {
|
|
3558
|
-
ctx2.db.update(users).set({ totpLastCounter: step }).where(
|
|
3685
|
+
ctx2.db.update(users).set({ totpLastCounter: step }).where(eq37(users.id, current.id)).run();
|
|
3559
3686
|
return true;
|
|
3560
3687
|
}
|
|
3561
|
-
const hashes =
|
|
3688
|
+
const hashes = z22.array(z22.string()).parse(JSON.parse(current.recoveryCodes));
|
|
3562
3689
|
const index = hashes.indexOf(digest(code));
|
|
3563
3690
|
if (index < 0) {
|
|
3564
3691
|
return false;
|
|
3565
3692
|
}
|
|
3566
3693
|
hashes.splice(index, 1);
|
|
3567
|
-
ctx2.db.update(users).set({ recoveryCodes: JSON.stringify(hashes) }).where(
|
|
3694
|
+
ctx2.db.update(users).set({ recoveryCodes: JSON.stringify(hashes) }).where(eq37(users.id, current.id)).run();
|
|
3568
3695
|
return true;
|
|
3569
3696
|
});
|
|
3570
3697
|
}
|
|
@@ -3633,7 +3760,7 @@ var mfaReauthenticateProcedure = authenticatedBrowserProcedure.input(codeSchema)
|
|
|
3633
3760
|
});
|
|
3634
3761
|
|
|
3635
3762
|
// server/router/auth/change-password.ts
|
|
3636
|
-
import { eq as
|
|
3763
|
+
import { eq as eq38, or as or2 } from "drizzle-orm";
|
|
3637
3764
|
var changePasswordProcedure = freshBrowserProcedure.input(passwordChangeSchema).mutation(async ({ ctx: requestContext, input: input2 }) => {
|
|
3638
3765
|
const ctx = identityContext(requestContext);
|
|
3639
3766
|
const user = requestContext.user;
|
|
@@ -3654,8 +3781,8 @@ var changePasswordProcedure = freshBrowserProcedure.input(passwordChangeSchema).
|
|
|
3654
3781
|
updateAccount(ctx2.db, user.id, { passwordHash });
|
|
3655
3782
|
ctx2.db.delete(sessions).where(
|
|
3656
3783
|
or2(
|
|
3657
|
-
|
|
3658
|
-
|
|
3784
|
+
eq38(sessions.userId, user.id),
|
|
3785
|
+
eq38(sessions.pendingUserId, user.id)
|
|
3659
3786
|
)
|
|
3660
3787
|
).run();
|
|
3661
3788
|
}
|
|
@@ -3805,7 +3932,7 @@ var authRouter = router({
|
|
|
3805
3932
|
});
|
|
3806
3933
|
|
|
3807
3934
|
// server/router/conversations/list.ts
|
|
3808
|
-
import { eq as
|
|
3935
|
+
import { eq as eq39 } from "drizzle-orm";
|
|
3809
3936
|
|
|
3810
3937
|
// server/projects/conversations.ts
|
|
3811
3938
|
var conversationView = (conversation) => {
|
|
@@ -3820,35 +3947,35 @@ var conversationView = (conversation) => {
|
|
|
3820
3947
|
|
|
3821
3948
|
// server/router/conversations/list.ts
|
|
3822
3949
|
var listProcedure5 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
3823
|
-
const records = ctx.db.select().from(conversations).where(
|
|
3950
|
+
const records = ctx.db.select().from(conversations).where(eq39(conversations.workspaceId, ctx.workspace.id)).all();
|
|
3824
3951
|
return page(records.map((record) => conversationView(record)));
|
|
3825
3952
|
});
|
|
3826
3953
|
|
|
3827
3954
|
// server/router/conversations/get.ts
|
|
3828
|
-
import { and as
|
|
3955
|
+
import { and as and29, eq as eq40 } from "drizzle-orm";
|
|
3829
3956
|
|
|
3830
3957
|
// server/projects/schemas.ts
|
|
3831
|
-
import { z as
|
|
3832
|
-
var projectIdSchema =
|
|
3833
|
-
var projectCreateSchema =
|
|
3834
|
-
name:
|
|
3835
|
-
enabled:
|
|
3836
|
-
readable_tables:
|
|
3837
|
-
writable_tables:
|
|
3838
|
-
readable_documents:
|
|
3839
|
-
writable_documents:
|
|
3840
|
-
});
|
|
3841
|
-
var projectChangesSchema = projectCreateSchema.partial().extend({ id:
|
|
3958
|
+
import { z as z23 } from "zod";
|
|
3959
|
+
var projectIdSchema = z23.strictObject({ id: z23.uuid() });
|
|
3960
|
+
var projectCreateSchema = z23.strictObject({
|
|
3961
|
+
name: z23.string().min(1).max(100),
|
|
3962
|
+
enabled: z23.boolean().optional(),
|
|
3963
|
+
readable_tables: z23.array(z23.uuid()).optional(),
|
|
3964
|
+
writable_tables: z23.array(z23.uuid()).optional(),
|
|
3965
|
+
readable_documents: z23.array(z23.uuid()).optional(),
|
|
3966
|
+
writable_documents: z23.array(z23.uuid()).optional()
|
|
3967
|
+
});
|
|
3968
|
+
var projectChangesSchema = projectCreateSchema.partial().extend({ id: z23.uuid() });
|
|
3842
3969
|
var projectExecutorSchema = projectIdSchema.extend({
|
|
3843
|
-
locally_managed:
|
|
3970
|
+
locally_managed: z23.boolean().default(false)
|
|
3844
3971
|
});
|
|
3845
3972
|
|
|
3846
3973
|
// server/router/conversations/get.ts
|
|
3847
3974
|
var getProcedure5 = browserWorkspaceProcedure.input(projectIdSchema).query(({ ctx, input: input2 }) => {
|
|
3848
3975
|
const conversation = ctx.db.select().from(conversations).where(
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
3976
|
+
and29(
|
|
3977
|
+
eq40(conversations.workspaceId, ctx.workspace.id),
|
|
3978
|
+
eq40(conversations.id, input2.id)
|
|
3852
3979
|
)
|
|
3853
3980
|
).get();
|
|
3854
3981
|
if (!conversation) {
|
|
@@ -3864,25 +3991,25 @@ var conversationsRouter = router({
|
|
|
3864
3991
|
});
|
|
3865
3992
|
|
|
3866
3993
|
// server/router/credentials/begin-oauth.ts
|
|
3867
|
-
import { and as
|
|
3994
|
+
import { and as and31, eq as eq42, lt as lt2 } from "drizzle-orm";
|
|
3868
3995
|
import { createHash as createHash2 } from "node:crypto";
|
|
3869
3996
|
|
|
3870
3997
|
// server/oauth/schemas.ts
|
|
3871
|
-
import { z as
|
|
3872
|
-
var oauthConnectSchema =
|
|
3873
|
-
plugin:
|
|
3874
|
-
name:
|
|
3875
|
-
client_id:
|
|
3876
|
-
client_secret:
|
|
3998
|
+
import { z as z24 } from "zod";
|
|
3999
|
+
var oauthConnectSchema = z24.strictObject({
|
|
4000
|
+
plugin: z24.uuid(),
|
|
4001
|
+
name: z24.string().trim().min(1).max(100),
|
|
4002
|
+
client_id: z24.string().trim().min(1).max(500),
|
|
4003
|
+
client_secret: z24.string().trim().min(1).max(2e3)
|
|
3877
4004
|
});
|
|
3878
|
-
var oauthCallbackSchema =
|
|
3879
|
-
state:
|
|
3880
|
-
code:
|
|
3881
|
-
error:
|
|
4005
|
+
var oauthCallbackSchema = z24.object({
|
|
4006
|
+
state: z24.string().optional(),
|
|
4007
|
+
code: z24.string().optional(),
|
|
4008
|
+
error: z24.string().optional()
|
|
3882
4009
|
});
|
|
3883
4010
|
|
|
3884
4011
|
// server/oauth/providers.ts
|
|
3885
|
-
import { and as
|
|
4012
|
+
import { and as and30, eq as eq41 } from "drizzle-orm";
|
|
3886
4013
|
var providers = {
|
|
3887
4014
|
"xero-oauth": {
|
|
3888
4015
|
authorization: "https://login.xero.com/identity/connect/authorize",
|
|
@@ -3972,9 +4099,9 @@ function checkedMetadata(plugin) {
|
|
|
3972
4099
|
}
|
|
3973
4100
|
function isCurrentManager(ctx, workspaceId, userId) {
|
|
3974
4101
|
const member = ctx.db.select().from(memberships).where(
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
4102
|
+
and30(
|
|
4103
|
+
eq41(memberships.workspaceId, workspaceId),
|
|
4104
|
+
eq41(memberships.userId, userId)
|
|
3978
4105
|
)
|
|
3979
4106
|
).get();
|
|
3980
4107
|
return member && ["owner", "admin"].includes(member.role);
|
|
@@ -3989,7 +4116,7 @@ var beginOAuthProcedure = browserSessionManagerProcedure.input(oauthConnectSchem
|
|
|
3989
4116
|
const clientId = field(input2.client_id, 500);
|
|
3990
4117
|
const clientSecret = field(input2.client_secret, 2e3);
|
|
3991
4118
|
const plugin = ctx.db.select().from(plugins).where(
|
|
3992
|
-
|
|
4119
|
+
and31(eq42(plugins.id, pluginId), eq42(plugins.workspaceId, workspace2.id))
|
|
3993
4120
|
).get();
|
|
3994
4121
|
if (!plugin) {
|
|
3995
4122
|
throw new ServiceError(
|
|
@@ -4021,8 +4148,8 @@ var beginOAuthProcedure = browserSessionManagerProcedure.input(oauthConnectSchem
|
|
|
4021
4148
|
);
|
|
4022
4149
|
}
|
|
4023
4150
|
ctx2.db.delete(oauthAttempts).where(
|
|
4024
|
-
|
|
4025
|
-
|
|
4151
|
+
and31(
|
|
4152
|
+
eq42(oauthAttempts.workspaceId, workspace2.id),
|
|
4026
4153
|
lt2(oauthAttempts.expiresAt, Date.now())
|
|
4027
4154
|
)
|
|
4028
4155
|
).run();
|
|
@@ -4058,33 +4185,33 @@ var beginOAuthProcedure = browserSessionManagerProcedure.input(oauthConnectSchem
|
|
|
4058
4185
|
});
|
|
4059
4186
|
|
|
4060
4187
|
// server/router/credentials/list.ts
|
|
4061
|
-
import { asc as asc2, eq as
|
|
4188
|
+
import { asc as asc2, eq as eq43 } from "drizzle-orm";
|
|
4062
4189
|
var listProcedure6 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
4063
|
-
const records = ctx.db.select(credentialPublicFields).from(credentials).where(
|
|
4190
|
+
const records = ctx.db.select(credentialPublicFields).from(credentials).where(eq43(credentials.workspaceId, ctx.workspace.id)).orderBy(asc2(credentials.name), asc2(credentials.id)).all();
|
|
4064
4191
|
return page(records);
|
|
4065
4192
|
});
|
|
4066
4193
|
|
|
4067
4194
|
// server/credentials/schemas.ts
|
|
4068
|
-
import { z as
|
|
4069
|
-
var credentialName =
|
|
4070
|
-
var credentialSecret =
|
|
4195
|
+
import { z as z25 } from "zod";
|
|
4196
|
+
var credentialName = z25.string().trim().min(1).max(100).refine((value) => !value.includes("\0"));
|
|
4197
|
+
var credentialSecret = z25.record(z25.string(), z25.json()).refine(
|
|
4071
4198
|
(secret) => Object.keys(secret).length > 0 && Buffer.byteLength(JSON.stringify(secret)) <= 32e3,
|
|
4072
4199
|
"Supply a nonempty secret object under 32KB."
|
|
4073
4200
|
);
|
|
4074
|
-
var credentialSchema =
|
|
4075
|
-
id:
|
|
4076
|
-
name:
|
|
4077
|
-
provider:
|
|
4201
|
+
var credentialSchema = z25.object({
|
|
4202
|
+
id: z25.uuid(),
|
|
4203
|
+
name: z25.string(),
|
|
4204
|
+
provider: z25.string()
|
|
4078
4205
|
});
|
|
4079
|
-
var credentialCreateSchema =
|
|
4206
|
+
var credentialCreateSchema = z25.strictObject({
|
|
4080
4207
|
name: credentialName,
|
|
4081
4208
|
provider: credentialName,
|
|
4082
4209
|
secret: credentialSecret
|
|
4083
4210
|
});
|
|
4084
4211
|
var updateCredentialSchema = credentialCreateSchema.partial();
|
|
4085
|
-
var credentialIdSchema =
|
|
4212
|
+
var credentialIdSchema = z25.strictObject({ id: z25.uuid() });
|
|
4086
4213
|
var credentialChangesSchema = updateCredentialSchema.extend({
|
|
4087
|
-
id:
|
|
4214
|
+
id: z25.uuid()
|
|
4088
4215
|
});
|
|
4089
4216
|
|
|
4090
4217
|
// server/router/credentials/get.ts
|
|
@@ -4118,7 +4245,7 @@ var createProcedure2 = browserManagerProcedure.input(credentialCreateSchema).mut
|
|
|
4118
4245
|
});
|
|
4119
4246
|
|
|
4120
4247
|
// server/router/credentials/update.ts
|
|
4121
|
-
import { and as
|
|
4248
|
+
import { and as and32, eq as eq44 } from "drizzle-orm";
|
|
4122
4249
|
var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mutation(({ ctx, input: input2 }) => {
|
|
4123
4250
|
const changes = {
|
|
4124
4251
|
...input2.name === void 0 ? {} : { name: input2.name },
|
|
@@ -4129,9 +4256,9 @@ var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mu
|
|
|
4129
4256
|
};
|
|
4130
4257
|
return inTransaction(ctx, (transaction) => {
|
|
4131
4258
|
const existing = transaction.db.select({ provider: credentials.provider }).from(credentials).where(
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4259
|
+
and32(
|
|
4260
|
+
eq44(credentials.workspaceId, ctx.workspace.id),
|
|
4261
|
+
eq44(credentials.id, input2.id)
|
|
4135
4262
|
)
|
|
4136
4263
|
).get();
|
|
4137
4264
|
if (input2.provider?.startsWith("mcp-") || existing?.provider.startsWith("mcp-") && (input2.provider !== void 0 || input2.secret !== void 0)) {
|
|
@@ -4141,9 +4268,9 @@ var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mu
|
|
|
4141
4268
|
);
|
|
4142
4269
|
}
|
|
4143
4270
|
const credential = transaction.db.update(credentials).set({ ...changes, updatedAt: now() }).where(
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4271
|
+
and32(
|
|
4272
|
+
eq44(credentials.workspaceId, ctx.workspace.id),
|
|
4273
|
+
eq44(credentials.id, input2.id)
|
|
4147
4274
|
)
|
|
4148
4275
|
).returning(credentialPublicFields).get();
|
|
4149
4276
|
if (!credential) {
|
|
@@ -4155,25 +4282,25 @@ var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mu
|
|
|
4155
4282
|
});
|
|
4156
4283
|
|
|
4157
4284
|
// server/router/credentials/delete.ts
|
|
4158
|
-
import { and as
|
|
4285
|
+
import { and as and33, eq as eq45 } from "drizzle-orm";
|
|
4159
4286
|
var deleteProcedure = browserManagerProcedure.input(credentialIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
4160
4287
|
inTransaction(ctx, (transaction) => {
|
|
4161
4288
|
if (!findCredential(transaction.db, ctx.workspace.id, input2.id)) {
|
|
4162
4289
|
throw new ServiceError("NOT_FOUND", "Credential not found.");
|
|
4163
4290
|
}
|
|
4164
4291
|
const dependentPlugin = transaction.db.select({ id: plugins.id }).from(plugins).where(
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4292
|
+
and33(
|
|
4293
|
+
eq45(plugins.workspaceId, ctx.workspace.id),
|
|
4294
|
+
eq45(plugins.credentialId, input2.id)
|
|
4168
4295
|
)
|
|
4169
4296
|
).limit(1).get();
|
|
4170
4297
|
if (dependentPlugin) {
|
|
4171
4298
|
throw new ServiceError("CONFLICT", "Credential is used by a plugin.");
|
|
4172
4299
|
}
|
|
4173
4300
|
transaction.db.delete(credentials).where(
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4301
|
+
and33(
|
|
4302
|
+
eq45(credentials.workspaceId, ctx.workspace.id),
|
|
4303
|
+
eq45(credentials.id, input2.id)
|
|
4177
4304
|
)
|
|
4178
4305
|
).run();
|
|
4179
4306
|
recordAudit(transaction, "credential", input2.id, "deleted");
|
|
@@ -4191,7 +4318,7 @@ var credentialsRouter = router({
|
|
|
4191
4318
|
});
|
|
4192
4319
|
|
|
4193
4320
|
// server/router/documents/list.ts
|
|
4194
|
-
import { eq as
|
|
4321
|
+
import { eq as eq46 } from "drizzle-orm";
|
|
4195
4322
|
|
|
4196
4323
|
// server/documents/views.ts
|
|
4197
4324
|
function documentView(row) {
|
|
@@ -4200,14 +4327,14 @@ function documentView(row) {
|
|
|
4200
4327
|
|
|
4201
4328
|
// server/router/documents/list.ts
|
|
4202
4329
|
var listProcedure7 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
4203
|
-
const records = ctx.db.select().from(documents).where(
|
|
4330
|
+
const records = ctx.db.select().from(documents).where(eq46(documents.workspaceId, ctx.workspace.id)).all();
|
|
4204
4331
|
return page(records.map((record) => documentView(record)));
|
|
4205
4332
|
});
|
|
4206
4333
|
|
|
4207
4334
|
// server/repositories/documents.ts
|
|
4208
|
-
import { and as
|
|
4335
|
+
import { and as and34, eq as eq47 } from "drizzle-orm";
|
|
4209
4336
|
function findDocument(database, workspaceId, id) {
|
|
4210
|
-
const record = database.select().from(documents).where(
|
|
4337
|
+
const record = database.select().from(documents).where(and34(eq47(documents.workspaceId, workspaceId), eq47(documents.id, id))).get();
|
|
4211
4338
|
if (!record) {
|
|
4212
4339
|
throw new ServiceError("NOT_FOUND", "Not found.");
|
|
4213
4340
|
}
|
|
@@ -4215,18 +4342,18 @@ function findDocument(database, workspaceId, id) {
|
|
|
4215
4342
|
}
|
|
4216
4343
|
|
|
4217
4344
|
// server/documents/schemas.ts
|
|
4218
|
-
import { z as
|
|
4219
|
-
var identifier3 =
|
|
4345
|
+
import { z as z26 } from "zod";
|
|
4346
|
+
var identifier3 = z26.uuid();
|
|
4220
4347
|
var documentFields = {
|
|
4221
|
-
kind:
|
|
4222
|
-
title:
|
|
4223
|
-
content:
|
|
4348
|
+
kind: z26.enum(["memory", "document"]),
|
|
4349
|
+
title: z26.string(),
|
|
4350
|
+
content: z26.string().max(2e5).refine((value) => !value.includes("\0"), "Invalid document.")
|
|
4224
4351
|
};
|
|
4225
|
-
var documentIdSchema =
|
|
4226
|
-
var createDocumentSchema =
|
|
4227
|
-
var updateDocumentSchema =
|
|
4352
|
+
var documentIdSchema = z26.strictObject({ id: identifier3 });
|
|
4353
|
+
var createDocumentSchema = z26.strictObject(documentFields);
|
|
4354
|
+
var updateDocumentSchema = z26.strictObject({
|
|
4228
4355
|
id: identifier3,
|
|
4229
|
-
...
|
|
4356
|
+
...z26.object(documentFields).partial().shape
|
|
4230
4357
|
});
|
|
4231
4358
|
|
|
4232
4359
|
// server/router/documents/get.ts
|
|
@@ -4248,7 +4375,7 @@ var createProcedure3 = browserWorkspaceProcedure.input(createDocumentSchema).mut
|
|
|
4248
4375
|
);
|
|
4249
4376
|
|
|
4250
4377
|
// server/router/documents/update.ts
|
|
4251
|
-
import { and as
|
|
4378
|
+
import { and as and35, eq as eq48 } from "drizzle-orm";
|
|
4252
4379
|
var updateProcedure3 = browserWorkspaceProcedure.input(updateDocumentSchema).mutation(({ ctx, input: input2 }) => {
|
|
4253
4380
|
return inTransaction(ctx, (ctx2) => {
|
|
4254
4381
|
const current = findDocument(ctx2.db, ctx2.workspace.id, input2.id);
|
|
@@ -4258,9 +4385,9 @@ var updateProcedure3 = browserWorkspaceProcedure.input(updateDocumentSchema).mut
|
|
|
4258
4385
|
content: input2.content ?? current.content,
|
|
4259
4386
|
updatedAt: now()
|
|
4260
4387
|
}).where(
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4388
|
+
and35(
|
|
4389
|
+
eq48(documents.workspaceId, ctx2.workspace.id),
|
|
4390
|
+
eq48(documents.id, input2.id)
|
|
4264
4391
|
)
|
|
4265
4392
|
).returning().get();
|
|
4266
4393
|
if (!document) {
|
|
@@ -4272,7 +4399,7 @@ var updateProcedure3 = browserWorkspaceProcedure.input(updateDocumentSchema).mut
|
|
|
4272
4399
|
});
|
|
4273
4400
|
|
|
4274
4401
|
// server/router/documents/delete.ts
|
|
4275
|
-
import { and as
|
|
4402
|
+
import { and as and36, eq as eq49 } from "drizzle-orm";
|
|
4276
4403
|
var deleteProcedure2 = browserWorkspaceProcedure.input(documentIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
4277
4404
|
return inTransaction(ctx, (ctx2) => {
|
|
4278
4405
|
findDocument(ctx2.db, ctx2.workspace.id, input2.id);
|
|
@@ -4287,9 +4414,9 @@ var deleteProcedure2 = browserWorkspaceProcedure.input(documentIdSchema).mutatio
|
|
|
4287
4414
|
});
|
|
4288
4415
|
}
|
|
4289
4416
|
const deleted = ctx2.db.delete(documents).where(
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4417
|
+
and36(
|
|
4418
|
+
eq49(documents.workspaceId, ctx2.workspace.id),
|
|
4419
|
+
eq49(documents.id, input2.id)
|
|
4293
4420
|
)
|
|
4294
4421
|
).returning({ id: documents.id }).get();
|
|
4295
4422
|
if (deleted) {
|
|
@@ -4308,36 +4435,76 @@ var documentsRouter = router({
|
|
|
4308
4435
|
delete: deleteProcedure2
|
|
4309
4436
|
});
|
|
4310
4437
|
|
|
4438
|
+
// server/router/plugins/shell-rules.ts
|
|
4439
|
+
import { asc as asc3, eq as eq50 } from "drizzle-orm";
|
|
4440
|
+
import { z as z27 } from "zod";
|
|
4441
|
+
var shellRulesProcedure = browserWorkspaceProcedure.input(z27.strictObject({ id: z27.uuid() })).query(({ ctx, input: input2 }) => {
|
|
4442
|
+
const plugin = pluginsRepository(ctx).find(input2.id);
|
|
4443
|
+
if (!supportsShellPolicy(plugin)) {
|
|
4444
|
+
throw new ServiceError(
|
|
4445
|
+
"BAD_REQUEST",
|
|
4446
|
+
"This plugin version does not support executable policies."
|
|
4447
|
+
);
|
|
4448
|
+
}
|
|
4449
|
+
return ctx.db.select({
|
|
4450
|
+
executable: shellRules.executable,
|
|
4451
|
+
decision: shellRules.decision
|
|
4452
|
+
}).from(shellRules).where(eq50(shellRules.pluginId, plugin.id)).orderBy(asc3(shellRules.executable)).all();
|
|
4453
|
+
});
|
|
4454
|
+
|
|
4455
|
+
// server/router/plugins/set-shell-rule.ts
|
|
4456
|
+
import { z as z28 } from "zod";
|
|
4457
|
+
var setShellRuleProcedure = browserManagerProcedure.input(
|
|
4458
|
+
z28.strictObject({
|
|
4459
|
+
id: z28.uuid(),
|
|
4460
|
+
executable: executableName,
|
|
4461
|
+
decision: ruleDecision
|
|
4462
|
+
})
|
|
4463
|
+
).mutation(
|
|
4464
|
+
({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
|
|
4465
|
+
assertCurrentPluginManager(transaction);
|
|
4466
|
+
const plugin = pluginsRepository(transaction).find(input2.id);
|
|
4467
|
+
if (!supportsShellPolicy(plugin)) {
|
|
4468
|
+
throw new ServiceError(
|
|
4469
|
+
"BAD_REQUEST",
|
|
4470
|
+
"This plugin version does not support executable policies."
|
|
4471
|
+
);
|
|
4472
|
+
}
|
|
4473
|
+
writeShellRule(transaction, plugin, input2.executable, input2.decision);
|
|
4474
|
+
return { saved: true };
|
|
4475
|
+
})
|
|
4476
|
+
);
|
|
4477
|
+
|
|
4311
4478
|
// server/router/plugins/mcp/begin-oauth.ts
|
|
4312
4479
|
import { auth as auth2, discoverOAuthServerInfo } from "@modelcontextprotocol/client";
|
|
4313
4480
|
|
|
4314
4481
|
// server/mcp/schemas.ts
|
|
4315
|
-
import { z as
|
|
4316
|
-
var connectionInputSchema =
|
|
4317
|
-
project:
|
|
4318
|
-
slug:
|
|
4482
|
+
import { z as z29 } from "zod";
|
|
4483
|
+
var connectionInputSchema = z29.strictObject({
|
|
4484
|
+
project: z29.uuid(),
|
|
4485
|
+
slug: z29.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/).max(50),
|
|
4319
4486
|
endpoint: endpointSchema,
|
|
4320
4487
|
transport: transportSchema.default("auto"),
|
|
4321
|
-
auth_mode:
|
|
4488
|
+
auth_mode: z29.enum(["none", "headers", "oauth"]).default("none"),
|
|
4322
4489
|
headers: headerSchema.optional()
|
|
4323
4490
|
});
|
|
4324
|
-
var connectionUpdateSchema =
|
|
4325
|
-
id:
|
|
4491
|
+
var connectionUpdateSchema = z29.strictObject({
|
|
4492
|
+
id: z29.uuid(),
|
|
4326
4493
|
endpoint: endpointSchema.optional(),
|
|
4327
4494
|
transport: transportSchema.optional(),
|
|
4328
|
-
auth_mode:
|
|
4495
|
+
auth_mode: z29.enum(["none", "headers", "oauth"]).optional(),
|
|
4329
4496
|
headers: headerSchema.optional()
|
|
4330
4497
|
});
|
|
4331
|
-
var catalogueAcceptSchema =
|
|
4332
|
-
id:
|
|
4333
|
-
run:
|
|
4334
|
-
tools:
|
|
4498
|
+
var catalogueAcceptSchema = z29.strictObject({
|
|
4499
|
+
id: z29.uuid(),
|
|
4500
|
+
run: z29.uuid(),
|
|
4501
|
+
tools: z29.array(z29.string()).max(1e3)
|
|
4335
4502
|
});
|
|
4336
|
-
var oauthBeginSchema =
|
|
4337
|
-
id:
|
|
4338
|
-
client_id:
|
|
4339
|
-
client_secret:
|
|
4340
|
-
client_metadata_url:
|
|
4503
|
+
var oauthBeginSchema = z29.strictObject({
|
|
4504
|
+
id: z29.uuid(),
|
|
4505
|
+
client_id: z29.string().max(2e3).optional(),
|
|
4506
|
+
client_secret: z29.string().max(4e3).optional(),
|
|
4507
|
+
client_metadata_url: z29.string().url().optional()
|
|
4341
4508
|
});
|
|
4342
4509
|
|
|
4343
4510
|
// server/router/plugins/mcp/begin-oauth.ts
|
|
@@ -4423,30 +4590,6 @@ function createHeaderCredential(ctx, name, headers) {
|
|
|
4423
4590
|
}).returning().get().id;
|
|
4424
4591
|
}
|
|
4425
4592
|
|
|
4426
|
-
// server/repositories/plugins.ts
|
|
4427
|
-
import { and as and34, eq as eq47 } from "drizzle-orm";
|
|
4428
|
-
function pluginsRepository(context) {
|
|
4429
|
-
const workspaceId = requireWorkspace(context).id;
|
|
4430
|
-
const database = context.db;
|
|
4431
|
-
const scoped = (id, filter) => and34(
|
|
4432
|
-
eq47(plugins.workspaceId, workspaceId),
|
|
4433
|
-
id === void 0 ? void 0 : eq47(plugins.id, id),
|
|
4434
|
-
filter
|
|
4435
|
-
);
|
|
4436
|
-
return {
|
|
4437
|
-
find(id) {
|
|
4438
|
-
const row = database.select().from(plugins).where(scoped(id)).get();
|
|
4439
|
-
if (!row) {
|
|
4440
|
-
throw new ServiceError("NOT_FOUND", "Not found.");
|
|
4441
|
-
}
|
|
4442
|
-
return row;
|
|
4443
|
-
},
|
|
4444
|
-
list(filter) {
|
|
4445
|
-
return database.select().from(plugins).where(scoped(void 0, filter)).all();
|
|
4446
|
-
}
|
|
4447
|
-
};
|
|
4448
|
-
}
|
|
4449
|
-
|
|
4450
4593
|
// server/router/plugins/mcp/create.ts
|
|
4451
4594
|
var createProcedure4 = browserManagerProcedure.input(connectionInputSchema).mutation(
|
|
4452
4595
|
({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
|
|
@@ -4485,7 +4628,7 @@ var createProcedure4 = browserManagerProcedure.input(connectionInputSchema).muta
|
|
|
4485
4628
|
);
|
|
4486
4629
|
|
|
4487
4630
|
// server/router/plugins/mcp/update.ts
|
|
4488
|
-
import { eq as
|
|
4631
|
+
import { eq as eq51 } from "drizzle-orm";
|
|
4489
4632
|
var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mutation(
|
|
4490
4633
|
({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
|
|
4491
4634
|
assertCurrentPluginManager(transaction);
|
|
@@ -4513,12 +4656,12 @@ var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mut
|
|
|
4513
4656
|
discoveryRunId: null,
|
|
4514
4657
|
catalogue: [],
|
|
4515
4658
|
enabledTools: []
|
|
4516
|
-
}).where(
|
|
4659
|
+
}).where(eq51(mcpConnections.pluginId, input2.id)).run();
|
|
4517
4660
|
transaction.db.update(plugins).set({
|
|
4518
4661
|
enabled: false,
|
|
4519
4662
|
...credentialId ? { credentialId } : resetAuth ? { credentialId: null } : {},
|
|
4520
4663
|
updatedAt: now()
|
|
4521
|
-
}).where(
|
|
4664
|
+
}).where(eq51(plugins.id, input2.id)).run();
|
|
4522
4665
|
discardMcpCredential(transaction, replacedCredential);
|
|
4523
4666
|
recordAudit(transaction, "plugin", input2.id, "connection.updated");
|
|
4524
4667
|
return { id: input2.id };
|
|
@@ -4526,41 +4669,41 @@ var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mut
|
|
|
4526
4669
|
);
|
|
4527
4670
|
|
|
4528
4671
|
// server/plugins/schemas.ts
|
|
4529
|
-
import { z as
|
|
4530
|
-
var pluginIdSchema =
|
|
4531
|
-
var pluginCreateSchema =
|
|
4532
|
-
project:
|
|
4533
|
-
slug:
|
|
4534
|
-
version:
|
|
4535
|
-
description:
|
|
4536
|
-
source:
|
|
4537
|
-
distribution:
|
|
4538
|
-
credential:
|
|
4539
|
-
configuration:
|
|
4540
|
-
enabled:
|
|
4541
|
-
});
|
|
4542
|
-
var pluginChangesSchema = pluginCreateSchema.omit({ slug: true }).partial().extend({ id:
|
|
4672
|
+
import { z as z30 } from "zod";
|
|
4673
|
+
var pluginIdSchema = z30.strictObject({ id: z30.uuid() });
|
|
4674
|
+
var pluginCreateSchema = z30.strictObject({
|
|
4675
|
+
project: z30.uuid(),
|
|
4676
|
+
slug: z30.string(),
|
|
4677
|
+
version: z30.string(),
|
|
4678
|
+
description: z30.string().optional(),
|
|
4679
|
+
source: z30.string().optional(),
|
|
4680
|
+
distribution: z30.enum(["inline", "external"]).optional(),
|
|
4681
|
+
credential: z30.uuid().nullable().optional(),
|
|
4682
|
+
configuration: z30.json().optional(),
|
|
4683
|
+
enabled: z30.boolean().optional()
|
|
4684
|
+
});
|
|
4685
|
+
var pluginChangesSchema = pluginCreateSchema.omit({ slug: true }).partial().extend({ id: z30.uuid(), refresh_bundle: z30.boolean().optional() });
|
|
4543
4686
|
|
|
4544
4687
|
// server/router/plugins/mcp/get.ts
|
|
4545
|
-
import { and as
|
|
4688
|
+
import { and as and37, eq as eq52, gt as gt3 } from "drizzle-orm";
|
|
4546
4689
|
var getProcedure8 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx, input: input2 }) => {
|
|
4547
4690
|
const connection = mcpConnection(ctx, input2.id);
|
|
4548
|
-
const plugin = ctx.db.select().from(plugins).where(
|
|
4691
|
+
const plugin = ctx.db.select().from(plugins).where(eq52(plugins.id, connection.pluginId)).get();
|
|
4549
4692
|
const runner = plugin ? ctx.db.select({ protocolVersion: executors.protocolVersion }).from(executors).where(
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4693
|
+
and37(
|
|
4694
|
+
eq52(executors.workspaceId, ctx.workspace.id),
|
|
4695
|
+
eq52(executors.projectId, plugin.projectId),
|
|
4696
|
+
eq52(executors.enabled, true),
|
|
4697
|
+
gt3(
|
|
4555
4698
|
executors.lastSeenAt,
|
|
4556
4699
|
new Date(Date.now() - 6e4).toISOString()
|
|
4557
4700
|
)
|
|
4558
4701
|
)
|
|
4559
4702
|
).all() : [];
|
|
4560
4703
|
const run = connection.discoveryRunId ? ctx.db.select({ status: runs.status, error: runs.error }).from(runs).where(
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4704
|
+
and37(
|
|
4705
|
+
eq52(runs.id, connection.discoveryRunId),
|
|
4706
|
+
eq52(runs.workspaceId, ctx.workspace.id)
|
|
4564
4707
|
)
|
|
4565
4708
|
).get() : void 0;
|
|
4566
4709
|
return {
|
|
@@ -4573,18 +4716,18 @@ var getProcedure8 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx
|
|
|
4573
4716
|
});
|
|
4574
4717
|
|
|
4575
4718
|
// server/router/plugins/mcp/discover.ts
|
|
4576
|
-
import { and as
|
|
4719
|
+
import { and as and38, eq as eq53, gt as gt4 } from "drizzle-orm";
|
|
4577
4720
|
var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
|
|
4578
4721
|
({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
|
|
4579
4722
|
assertCurrentPluginManager(transaction);
|
|
4580
4723
|
const plugin = pluginsRepository(transaction).find(input2.id);
|
|
4581
4724
|
const connection = mcpConnection(transaction, input2.id);
|
|
4582
4725
|
const workers = transaction.db.select().from(executors).where(
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4726
|
+
and38(
|
|
4727
|
+
eq53(executors.workspaceId, ctx.workspace.id),
|
|
4728
|
+
eq53(executors.projectId, plugin.projectId),
|
|
4729
|
+
eq53(executors.enabled, true),
|
|
4730
|
+
gt4(
|
|
4588
4731
|
executors.lastSeenAt,
|
|
4589
4732
|
new Date(Date.now() - 6e4).toISOString()
|
|
4590
4733
|
)
|
|
@@ -4606,16 +4749,16 @@ var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
|
|
|
4606
4749
|
}
|
|
4607
4750
|
if (connection.discoveryRunId) {
|
|
4608
4751
|
const previous = transaction.db.select().from(runs).where(
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4752
|
+
and38(
|
|
4753
|
+
eq53(runs.id, connection.discoveryRunId),
|
|
4754
|
+
eq53(runs.workspaceId, ctx.workspace.id)
|
|
4612
4755
|
)
|
|
4613
4756
|
).get();
|
|
4614
4757
|
if (previous && ["queued", "running"].includes(previous.status)) {
|
|
4615
4758
|
transaction.db.update(runs).set({
|
|
4616
4759
|
cancelRequested: true,
|
|
4617
4760
|
...previous.status === "queued" ? { status: "cancelled" } : {}
|
|
4618
|
-
}).where(
|
|
4761
|
+
}).where(eq53(runs.id, previous.id)).run();
|
|
4619
4762
|
}
|
|
4620
4763
|
}
|
|
4621
4764
|
const target = { ...mcpSnapshot(transaction, input2.id), tools: [] };
|
|
@@ -4647,14 +4790,14 @@ var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
|
|
|
4647
4790
|
]
|
|
4648
4791
|
}
|
|
4649
4792
|
}).returning().get();
|
|
4650
|
-
transaction.db.update(mcpConnections).set({ discoveryRunId: run.id, status: "checking", candidate: null }).where(
|
|
4793
|
+
transaction.db.update(mcpConnections).set({ discoveryRunId: run.id, status: "checking", candidate: null }).where(eq53(mcpConnections.pluginId, input2.id)).run();
|
|
4651
4794
|
recordAudit(transaction, "plugin", input2.id, "discovery.requested");
|
|
4652
4795
|
return { run: run.id };
|
|
4653
4796
|
})
|
|
4654
4797
|
);
|
|
4655
4798
|
|
|
4656
4799
|
// server/router/plugins/mcp/accept.ts
|
|
4657
|
-
import { eq as
|
|
4800
|
+
import { eq as eq54 } from "drizzle-orm";
|
|
4658
4801
|
|
|
4659
4802
|
// runtime/src/mcp/aliases.ts
|
|
4660
4803
|
import { createHash as createHash3 } from "node:crypto";
|
|
@@ -4737,13 +4880,13 @@ var acceptProcedure = browserManagerProcedure.input(catalogueAcceptSchema).mutat
|
|
|
4737
4880
|
candidate: null,
|
|
4738
4881
|
revision: revision3,
|
|
4739
4882
|
status: "ready"
|
|
4740
|
-
}).where(
|
|
4883
|
+
}).where(eq54(mcpConnections.pluginId, input2.id)).run();
|
|
4741
4884
|
transaction.db.update(plugins).set({
|
|
4742
4885
|
version: String(revision3),
|
|
4743
4886
|
digest: digest(JSON.stringify(catalogue)),
|
|
4744
4887
|
enabled: selected.size > 0,
|
|
4745
4888
|
updatedAt: now()
|
|
4746
|
-
}).where(
|
|
4889
|
+
}).where(eq54(plugins.id, input2.id)).run();
|
|
4747
4890
|
recordAudit(transaction, "plugin", input2.id, "catalogue.accepted");
|
|
4748
4891
|
return { id: input2.id, revision: revision3 };
|
|
4749
4892
|
})
|
|
@@ -4772,6 +4915,7 @@ var pluginView = (plugin) => {
|
|
|
4772
4915
|
enabled: plugin.enabled,
|
|
4773
4916
|
credential: plugin.credentialId,
|
|
4774
4917
|
distribution: plugin.distribution,
|
|
4918
|
+
shell_policy: supportsShellPolicy(plugin),
|
|
4775
4919
|
configuration: plugin.configuration,
|
|
4776
4920
|
package_url: plugin.packageUrl,
|
|
4777
4921
|
tools: plugin.releaseMetadata?.tools ?? null,
|
|
@@ -4795,54 +4939,54 @@ var getProcedure9 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx
|
|
|
4795
4939
|
});
|
|
4796
4940
|
|
|
4797
4941
|
// server/router/plugins/create.ts
|
|
4798
|
-
import { and as
|
|
4942
|
+
import { and as and39, eq as eq55 } from "drizzle-orm";
|
|
4799
4943
|
|
|
4800
4944
|
// server/plugins/catalog.ts
|
|
4801
|
-
import { z as
|
|
4945
|
+
import { z as z32 } from "zod";
|
|
4802
4946
|
|
|
4803
4947
|
// server/plugins/catalog-schemas.ts
|
|
4804
|
-
import { z as
|
|
4805
|
-
var jsonObject4 =
|
|
4806
|
-
var slug =
|
|
4807
|
-
var releaseSchema =
|
|
4948
|
+
import { z as z31 } from "zod";
|
|
4949
|
+
var jsonObject4 = z31.record(z31.string(), z31.json());
|
|
4950
|
+
var slug = z31.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/);
|
|
4951
|
+
var releaseSchema = z31.object({
|
|
4808
4952
|
slug,
|
|
4809
|
-
version:
|
|
4810
|
-
digest:
|
|
4811
|
-
package_url:
|
|
4812
|
-
display_name:
|
|
4813
|
-
description:
|
|
4814
|
-
category:
|
|
4815
|
-
documentation:
|
|
4816
|
-
distribution:
|
|
4817
|
-
contract_version:
|
|
4818
|
-
auth:
|
|
4819
|
-
type:
|
|
4820
|
-
provider:
|
|
4821
|
-
label:
|
|
4822
|
-
hint:
|
|
4823
|
-
scopes:
|
|
4824
|
-
}).catchall(
|
|
4953
|
+
version: z31.string().min(1).max(100),
|
|
4954
|
+
digest: z31.string().regex(/^[a-f0-9]{64}$/),
|
|
4955
|
+
package_url: z31.string(),
|
|
4956
|
+
display_name: z31.string(),
|
|
4957
|
+
description: z31.string(),
|
|
4958
|
+
category: z31.string(),
|
|
4959
|
+
documentation: z31.string(),
|
|
4960
|
+
distribution: z31.literal("external"),
|
|
4961
|
+
contract_version: z31.literal(1),
|
|
4962
|
+
auth: z31.object({
|
|
4963
|
+
type: z31.string().optional(),
|
|
4964
|
+
provider: z31.string().optional(),
|
|
4965
|
+
label: z31.string().optional(),
|
|
4966
|
+
hint: z31.string().optional(),
|
|
4967
|
+
scopes: z31.array(z31.string()).optional()
|
|
4968
|
+
}).catchall(z31.json()),
|
|
4825
4969
|
marketplace: jsonObject4,
|
|
4826
4970
|
configuration_schema: jsonObject4,
|
|
4827
|
-
tools:
|
|
4828
|
-
}).catchall(
|
|
4829
|
-
var marketplaceSchema =
|
|
4830
|
-
schema_version:
|
|
4831
|
-
plugins:
|
|
4832
|
-
|
|
4971
|
+
tools: z31.array(jsonObject4)
|
|
4972
|
+
}).catchall(z31.json());
|
|
4973
|
+
var marketplaceSchema = z31.object({
|
|
4974
|
+
schema_version: z31.literal(1),
|
|
4975
|
+
plugins: z31.array(
|
|
4976
|
+
z31.object({
|
|
4833
4977
|
slug,
|
|
4834
|
-
display_name:
|
|
4835
|
-
description:
|
|
4836
|
-
category:
|
|
4837
|
-
permissions:
|
|
4838
|
-
source_version:
|
|
4839
|
-
source_url:
|
|
4840
|
-
url:
|
|
4841
|
-
release_status:
|
|
4842
|
-
auth_type:
|
|
4843
|
-
tags:
|
|
4844
|
-
use_cases:
|
|
4845
|
-
}).catchall(
|
|
4978
|
+
display_name: z31.string(),
|
|
4979
|
+
description: z31.string(),
|
|
4980
|
+
category: z31.string(),
|
|
4981
|
+
permissions: z31.string(),
|
|
4982
|
+
source_version: z31.string(),
|
|
4983
|
+
source_url: z31.string(),
|
|
4984
|
+
url: z31.string(),
|
|
4985
|
+
release_status: z31.enum(["unreleased", "available"]),
|
|
4986
|
+
auth_type: z31.enum(["none", "token", "oauth2"]),
|
|
4987
|
+
tags: z31.array(z31.string()),
|
|
4988
|
+
use_cases: z31.array(z31.string())
|
|
4989
|
+
}).catchall(z31.json())
|
|
4846
4990
|
)
|
|
4847
4991
|
});
|
|
4848
4992
|
|
|
@@ -4908,7 +5052,7 @@ async function catalogEntries() {
|
|
|
4908
5052
|
"Cannot read the configured plugin catalog."
|
|
4909
5053
|
);
|
|
4910
5054
|
}
|
|
4911
|
-
const result =
|
|
5055
|
+
const result = z32.array(releaseSchema).safeParse(entries);
|
|
4912
5056
|
if (!result.success) {
|
|
4913
5057
|
throw new ServiceError(
|
|
4914
5058
|
"PRECONDITION_FAILED",
|
|
@@ -5002,10 +5146,10 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
|
|
|
5002
5146
|
metadata2
|
|
5003
5147
|
);
|
|
5004
5148
|
const installedPlugin = transaction.db.select({ id: plugins.id }).from(plugins).where(
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5149
|
+
and39(
|
|
5150
|
+
eq55(plugins.workspaceId, context.workspace.id),
|
|
5151
|
+
eq55(plugins.projectId, projectId),
|
|
5152
|
+
eq55(plugins.slug, slug2)
|
|
5009
5153
|
)
|
|
5010
5154
|
).limit(1).get();
|
|
5011
5155
|
if (installedPlugin) {
|
|
@@ -5022,7 +5166,7 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
|
|
|
5022
5166
|
|
|
5023
5167
|
// server/router/plugins/update.ts
|
|
5024
5168
|
import { isDeepStrictEqual } from "node:util";
|
|
5025
|
-
import { and as
|
|
5169
|
+
import { and as and40, eq as eq56 } from "drizzle-orm";
|
|
5026
5170
|
var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutation(async ({ ctx: context, input: input2 }) => {
|
|
5027
5171
|
const { id, ...changes } = input2;
|
|
5028
5172
|
const originalPlugin = pluginsRepository(context).find(id);
|
|
@@ -5110,9 +5254,9 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5110
5254
|
releaseMetadata: metadata2,
|
|
5111
5255
|
updatedAt: now()
|
|
5112
5256
|
}).where(
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5257
|
+
and40(
|
|
5258
|
+
eq56(plugins.workspaceId, context.workspace.id),
|
|
5259
|
+
eq56(plugins.id, id)
|
|
5116
5260
|
)
|
|
5117
5261
|
).returning().get();
|
|
5118
5262
|
if (!updatedPlugin) {
|
|
@@ -5124,15 +5268,15 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5124
5268
|
});
|
|
5125
5269
|
|
|
5126
5270
|
// server/router/plugins/delete.ts
|
|
5127
|
-
import { and as
|
|
5271
|
+
import { and as and41, eq as eq57 } from "drizzle-orm";
|
|
5128
5272
|
var deleteProcedure3 = browserManagerProcedure.input(pluginIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
5129
5273
|
inTransaction(ctx, (transaction) => {
|
|
5130
5274
|
assertCurrentPluginManager(transaction);
|
|
5131
5275
|
cancelConnectionRuns(transaction, input2.id);
|
|
5132
5276
|
const deletedPlugin = transaction.db.delete(plugins).where(
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5277
|
+
and41(
|
|
5278
|
+
eq57(plugins.workspaceId, ctx.workspace.id),
|
|
5279
|
+
eq57(plugins.id, input2.id)
|
|
5136
5280
|
)
|
|
5137
5281
|
).returning({ id: plugins.id, credentialId: plugins.credentialId }).get();
|
|
5138
5282
|
if (!deletedPlugin) {
|
|
@@ -5179,6 +5323,8 @@ var marketplaceProcedure = browserWorkspaceProcedure.query(
|
|
|
5179
5323
|
// server/router/plugins/index.ts
|
|
5180
5324
|
var pluginsRouter = router({
|
|
5181
5325
|
mcp: mcpRouter,
|
|
5326
|
+
shellRules: shellRulesProcedure,
|
|
5327
|
+
setShellRule: setShellRuleProcedure,
|
|
5182
5328
|
list: listProcedure8,
|
|
5183
5329
|
get: getProcedure9,
|
|
5184
5330
|
create: createProcedure5,
|
|
@@ -5189,39 +5335,39 @@ var pluginsRouter = router({
|
|
|
5189
5335
|
});
|
|
5190
5336
|
|
|
5191
5337
|
// server/router/projects/list.ts
|
|
5192
|
-
import { and as
|
|
5338
|
+
import { and as and43, eq as eq60 } from "drizzle-orm";
|
|
5193
5339
|
|
|
5194
5340
|
// server/projects/queries.ts
|
|
5195
|
-
import { and as
|
|
5341
|
+
import { and as and42, eq as eq58, inArray as inArray6, or as or3 } from "drizzle-orm";
|
|
5196
5342
|
function projectVisibility(database, workspaceId, grants2) {
|
|
5197
5343
|
if (!grants2) {
|
|
5198
5344
|
return void 0;
|
|
5199
5345
|
}
|
|
5200
5346
|
const grantedActionProjects = database.select({ projectId: actions.projectId }).from(actions).innerJoin(
|
|
5201
5347
|
actionVersions,
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5348
|
+
and42(
|
|
5349
|
+
eq58(actionVersions.actionId, actions.id),
|
|
5350
|
+
eq58(actionVersions.workspaceId, workspaceId)
|
|
5205
5351
|
)
|
|
5206
5352
|
).where(
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5353
|
+
and42(
|
|
5354
|
+
eq58(actions.workspaceId, workspaceId),
|
|
5355
|
+
inArray6(actionVersions.id, grants2.actionVersions)
|
|
5210
5356
|
)
|
|
5211
5357
|
);
|
|
5212
5358
|
return or3(
|
|
5213
|
-
|
|
5214
|
-
|
|
5359
|
+
inArray6(projects.id, grants2.projects),
|
|
5360
|
+
inArray6(projects.id, grantedActionProjects)
|
|
5215
5361
|
);
|
|
5216
5362
|
}
|
|
5217
5363
|
|
|
5218
5364
|
// server/projects/views.ts
|
|
5219
|
-
import { eq as
|
|
5365
|
+
import { eq as eq59 } from "drizzle-orm";
|
|
5220
5366
|
function serializeProject(ctx, row) {
|
|
5221
5367
|
const executor2 = executorsRepository(ctx).list(
|
|
5222
|
-
|
|
5368
|
+
eq59(executors.projectId, row.id)
|
|
5223
5369
|
)[0];
|
|
5224
|
-
const pluginIds = pluginsRepository(ctx).list(
|
|
5370
|
+
const pluginIds = pluginsRepository(ctx).list(eq59(plugins.projectId, row.id)).map((plugin) => plugin.id);
|
|
5225
5371
|
const minimal = {
|
|
5226
5372
|
id: row.id,
|
|
5227
5373
|
name: row.name,
|
|
@@ -5252,8 +5398,8 @@ function serializeProject(ctx, row) {
|
|
|
5252
5398
|
var listProcedure9 = scopedProcedure("catalog:read").query(
|
|
5253
5399
|
({ ctx }) => {
|
|
5254
5400
|
const projects2 = ctx.db.select().from(projects).where(
|
|
5255
|
-
|
|
5256
|
-
|
|
5401
|
+
and43(
|
|
5402
|
+
eq60(projects.workspaceId, ctx.workspace.id),
|
|
5257
5403
|
projectVisibility(ctx.db, ctx.workspace.id, ctx.token)
|
|
5258
5404
|
)
|
|
5259
5405
|
).all();
|
|
@@ -5262,12 +5408,12 @@ var listProcedure9 = scopedProcedure("catalog:read").query(
|
|
|
5262
5408
|
);
|
|
5263
5409
|
|
|
5264
5410
|
// server/router/projects/get.ts
|
|
5265
|
-
import { and as
|
|
5411
|
+
import { and as and44, eq as eq61 } from "drizzle-orm";
|
|
5266
5412
|
var getProcedure10 = scopedProcedure("catalog:read").input(projectIdSchema).query(({ ctx, input: input2 }) => {
|
|
5267
5413
|
const project = ctx.db.select().from(projects).where(
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5414
|
+
and44(
|
|
5415
|
+
eq61(projects.workspaceId, ctx.workspace.id),
|
|
5416
|
+
eq61(projects.id, input2.id),
|
|
5271
5417
|
projectVisibility(ctx.db, ctx.workspace.id, ctx.token)
|
|
5272
5418
|
)
|
|
5273
5419
|
).get();
|
|
@@ -5278,12 +5424,12 @@ var getProcedure10 = scopedProcedure("catalog:read").input(projectIdSchema).quer
|
|
|
5278
5424
|
});
|
|
5279
5425
|
|
|
5280
5426
|
// server/repositories/workspace-tables.ts
|
|
5281
|
-
import { and as
|
|
5427
|
+
import { and as and45, eq as eq62 } from "drizzle-orm";
|
|
5282
5428
|
function findWorkspaceTable(database, workspaceId, id) {
|
|
5283
5429
|
const record = database.select().from(workspaceTables).where(
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5430
|
+
and45(
|
|
5431
|
+
eq62(workspaceTables.workspaceId, workspaceId),
|
|
5432
|
+
eq62(workspaceTables.id, id)
|
|
5287
5433
|
)
|
|
5288
5434
|
).get();
|
|
5289
5435
|
if (!record) {
|
|
@@ -5355,21 +5501,21 @@ var updateProcedure6 = browserManagerProcedure.input(projectChangesSchema).mutat
|
|
|
5355
5501
|
});
|
|
5356
5502
|
|
|
5357
5503
|
// server/router/projects/delete.ts
|
|
5358
|
-
import { and as
|
|
5504
|
+
import { and as and46, eq as eq63 } from "drizzle-orm";
|
|
5359
5505
|
var deleteProcedure4 = browserManagerProcedure.input(projectIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
5360
5506
|
inTransaction(ctx, (transaction) => {
|
|
5361
5507
|
const projects2 = projectsRepository(transaction);
|
|
5362
5508
|
projects2.find(input2.id);
|
|
5363
5509
|
const retainedRun = transaction.db.select({ id: runs.id }).from(runs).where(
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5510
|
+
and46(
|
|
5511
|
+
eq63(runs.workspaceId, ctx.workspace.id),
|
|
5512
|
+
eq63(runs.projectId, input2.id)
|
|
5367
5513
|
)
|
|
5368
5514
|
).limit(1).get();
|
|
5369
5515
|
const retainedAction = transaction.db.select({ id: actions.id }).from(actions).where(
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5516
|
+
and46(
|
|
5517
|
+
eq63(actions.workspaceId, ctx.workspace.id),
|
|
5518
|
+
eq63(actions.projectId, input2.id)
|
|
5373
5519
|
)
|
|
5374
5520
|
).limit(1).get();
|
|
5375
5521
|
if (retainedRun || retainedAction) {
|
|
@@ -5379,9 +5525,9 @@ var deleteProcedure4 = browserManagerProcedure.input(projectIdSchema).mutation((
|
|
|
5379
5525
|
);
|
|
5380
5526
|
}
|
|
5381
5527
|
const deleted = transaction.db.delete(projects).where(
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5528
|
+
and46(
|
|
5529
|
+
eq63(projects.workspaceId, ctx.workspace.id),
|
|
5530
|
+
eq63(projects.id, input2.id)
|
|
5385
5531
|
)
|
|
5386
5532
|
).returning({ id: projects.id }).get();
|
|
5387
5533
|
if (deleted) {
|
|
@@ -5401,20 +5547,20 @@ import { createHmac as createHmac2, randomUUID as randomUUID4 } from "node:crypt
|
|
|
5401
5547
|
|
|
5402
5548
|
// server/projects/executor.ts
|
|
5403
5549
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
5404
|
-
import { and as
|
|
5550
|
+
import { and as and47, eq as eq64, inArray as inArray7 } from "drizzle-orm";
|
|
5405
5551
|
function revokeExecutor(ctx, id) {
|
|
5406
5552
|
const workspaceId = requireWorkspace(ctx).id;
|
|
5407
5553
|
const worker = ctx.db.select().from(executors).where(
|
|
5408
|
-
|
|
5554
|
+
and47(eq64(executors.workspaceId, workspaceId), eq64(executors.projectId, id))
|
|
5409
5555
|
).get();
|
|
5410
5556
|
if (!worker) {
|
|
5411
5557
|
return;
|
|
5412
5558
|
}
|
|
5413
5559
|
const activeRuns = ctx.db.select().from(runs).where(
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5560
|
+
and47(
|
|
5561
|
+
eq64(runs.workspaceId, workspaceId),
|
|
5562
|
+
eq64(runs.executorId, worker.id),
|
|
5563
|
+
inArray7(runs.status, ["running", "waiting_approval"])
|
|
5418
5564
|
)
|
|
5419
5565
|
).all();
|
|
5420
5566
|
for (const run of activeRuns) {
|
|
@@ -5426,10 +5572,10 @@ function revokeExecutor(ctx, id) {
|
|
|
5426
5572
|
leaseExpiresAt: null
|
|
5427
5573
|
});
|
|
5428
5574
|
const pendingApprovals = ctx.db.select().from(approvals).where(
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5575
|
+
and47(
|
|
5576
|
+
eq64(approvals.workspaceId, workspaceId),
|
|
5577
|
+
eq64(approvals.runId, run.id),
|
|
5578
|
+
eq64(approvals.status, "pending")
|
|
5433
5579
|
)
|
|
5434
5580
|
).all();
|
|
5435
5581
|
for (const approval of pendingApprovals) {
|
|
@@ -5518,17 +5664,17 @@ var projectsRouter = router({
|
|
|
5518
5664
|
});
|
|
5519
5665
|
|
|
5520
5666
|
// server/router/runs/list.ts
|
|
5521
|
-
import { and as
|
|
5667
|
+
import { and as and48, desc as desc4, eq as eq65, inArray as inArray8, or as or4 } from "drizzle-orm";
|
|
5522
5668
|
var listProcedure10 = scopedProcedure("runs:read").query(({ ctx }) => {
|
|
5523
5669
|
const token = ctx.token;
|
|
5524
|
-
const grant = token ?
|
|
5525
|
-
|
|
5670
|
+
const grant = token ? and48(
|
|
5671
|
+
eq65(runs.tokenId, token.id),
|
|
5526
5672
|
or4(
|
|
5527
|
-
|
|
5528
|
-
|
|
5673
|
+
inArray8(runs.projectId, token.projects),
|
|
5674
|
+
inArray8(runs.actionVersionId, token.actionVersions)
|
|
5529
5675
|
)
|
|
5530
5676
|
) : void 0;
|
|
5531
|
-
const visibleRuns = ctx.db.select().from(runs).where(
|
|
5677
|
+
const visibleRuns = ctx.db.select().from(runs).where(and48(eq65(runs.workspaceId, ctx.workspace.id), grant)).orderBy(desc4(runs.createdAt)).all();
|
|
5532
5678
|
return page(visibleRuns.map(serializeRun));
|
|
5533
5679
|
});
|
|
5534
5680
|
|
|
@@ -5546,16 +5692,16 @@ var createProcedure7 = protectedProcedure.input(createRunSchema).mutation(({ ctx
|
|
|
5546
5692
|
});
|
|
5547
5693
|
|
|
5548
5694
|
// server/router/runs/events.ts
|
|
5549
|
-
import { and as
|
|
5695
|
+
import { and as and49, asc as asc4, eq as eq66 } from "drizzle-orm";
|
|
5550
5696
|
var eventsProcedure = scopedProcedure("runs:read").input(runIdSchema).query(({ ctx, input: input2 }) => {
|
|
5551
5697
|
const run = runsRepository(ctx).find(input2.id);
|
|
5552
5698
|
authorizeRunRead(ctx, run, null);
|
|
5553
5699
|
const events = ctx.db.select().from(runEvents).where(
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5700
|
+
and49(
|
|
5701
|
+
eq66(runEvents.workspaceId, ctx.workspace.id),
|
|
5702
|
+
eq66(runEvents.runId, input2.id)
|
|
5557
5703
|
)
|
|
5558
|
-
).orderBy(
|
|
5704
|
+
).orderBy(asc4(runEvents.sequence)).all();
|
|
5559
5705
|
return events.map((event) => ({
|
|
5560
5706
|
sequence: event.sequence,
|
|
5561
5707
|
kind: event.kind,
|
|
@@ -5638,7 +5784,7 @@ var retryProcedure = protectedProcedure.input(retryRunSchema).mutation(
|
|
|
5638
5784
|
);
|
|
5639
5785
|
|
|
5640
5786
|
// server/router/runs/cancel.ts
|
|
5641
|
-
import { and as
|
|
5787
|
+
import { and as and50, eq as eq67 } from "drizzle-orm";
|
|
5642
5788
|
var cancelProcedure = scopedProcedure("runs:cancel").input(runIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
5643
5789
|
const id = input2.id;
|
|
5644
5790
|
const updated = inTransaction(ctx, (ctx2) => {
|
|
@@ -5652,10 +5798,10 @@ var cancelProcedure = scopedProcedure("runs:cancel").input(runIdSchema).mutation
|
|
|
5652
5798
|
cancelRequested: true
|
|
5653
5799
|
});
|
|
5654
5800
|
const pendingApprovals = ctx2.db.select().from(approvals).where(
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5801
|
+
and50(
|
|
5802
|
+
eq67(approvals.workspaceId, ctx2.workspace.id),
|
|
5803
|
+
eq67(approvals.runId, id),
|
|
5804
|
+
eq67(approvals.status, "pending")
|
|
5659
5805
|
)
|
|
5660
5806
|
).all();
|
|
5661
5807
|
for (const approval of pendingApprovals) {
|
|
@@ -5711,7 +5857,7 @@ var promoteProcedure = scopedProcedure(["runs:read", "actions:write"]).input(pro
|
|
|
5711
5857
|
|
|
5712
5858
|
// server/router/runs/stream.ts
|
|
5713
5859
|
import { setTimeout } from "node:timers/promises";
|
|
5714
|
-
import { and as
|
|
5860
|
+
import { and as and51, asc as asc5, eq as eq68, gt as gt5 } from "drizzle-orm";
|
|
5715
5861
|
var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscription(async function* ({ ctx, input: input2, signal }) {
|
|
5716
5862
|
const run = runsRepository(ctx).find(input2.id);
|
|
5717
5863
|
authorizeRunRead(ctx, run, null);
|
|
@@ -5721,9 +5867,9 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
|
|
|
5721
5867
|
return;
|
|
5722
5868
|
}
|
|
5723
5869
|
const membership = ctx.db.select().from(memberships).where(
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5870
|
+
and51(
|
|
5871
|
+
eq68(memberships.workspaceId, ctx.workspace.id),
|
|
5872
|
+
eq68(memberships.userId, ctx.userId)
|
|
5727
5873
|
)
|
|
5728
5874
|
).get();
|
|
5729
5875
|
if (!membership) {
|
|
@@ -5732,9 +5878,9 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
|
|
|
5732
5878
|
let currentContext = ctx;
|
|
5733
5879
|
if (ctx.token) {
|
|
5734
5880
|
const token = ctx.db.select().from(accessTokens).where(
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5881
|
+
and51(
|
|
5882
|
+
eq68(accessTokens.id, ctx.token.id),
|
|
5883
|
+
eq68(accessTokens.workspaceId, ctx.workspace.id)
|
|
5738
5884
|
)
|
|
5739
5885
|
).get();
|
|
5740
5886
|
if (!token || token.revoked) {
|
|
@@ -5754,12 +5900,12 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
|
|
|
5754
5900
|
}
|
|
5755
5901
|
const current = runsRepository(currentContext).find(input2.id);
|
|
5756
5902
|
const batch = currentContext.db.select().from(runEvents).where(
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5903
|
+
and51(
|
|
5904
|
+
eq68(runEvents.workspaceId, ctx.workspace.id),
|
|
5905
|
+
eq68(runEvents.runId, input2.id),
|
|
5906
|
+
gt5(runEvents.sequence, after)
|
|
5761
5907
|
)
|
|
5762
|
-
).orderBy(
|
|
5908
|
+
).orderBy(asc5(runEvents.sequence)).limit(100).all();
|
|
5763
5909
|
for (const event of batch) {
|
|
5764
5910
|
after = event.sequence;
|
|
5765
5911
|
yield {
|
|
@@ -5797,7 +5943,7 @@ var runsRouter = router({
|
|
|
5797
5943
|
});
|
|
5798
5944
|
|
|
5799
5945
|
// server/router/schedules/list.ts
|
|
5800
|
-
import { eq as
|
|
5946
|
+
import { eq as eq69 } from "drizzle-orm";
|
|
5801
5947
|
|
|
5802
5948
|
// server/automations/schedule-view.ts
|
|
5803
5949
|
function scheduleView(schedule) {
|
|
@@ -5813,21 +5959,21 @@ function scheduleView(schedule) {
|
|
|
5813
5959
|
|
|
5814
5960
|
// server/router/schedules/list.ts
|
|
5815
5961
|
var listProcedure11 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
5816
|
-
const records = ctx.db.select().from(schedules).where(
|
|
5962
|
+
const records = ctx.db.select().from(schedules).where(eq69(schedules.workspaceId, ctx.workspace.id)).all();
|
|
5817
5963
|
return page(records.map((record) => scheduleView(record)));
|
|
5818
5964
|
});
|
|
5819
5965
|
|
|
5820
5966
|
// server/router/schedules/get.ts
|
|
5821
|
-
import { z as
|
|
5967
|
+
import { z as z33 } from "zod";
|
|
5822
5968
|
|
|
5823
5969
|
// server/repositories/schedules.ts
|
|
5824
|
-
import { and as
|
|
5970
|
+
import { and as and52, eq as eq70 } from "drizzle-orm";
|
|
5825
5971
|
function schedulesRepository(context) {
|
|
5826
5972
|
const workspaceId = requireWorkspace(context).id;
|
|
5827
5973
|
return {
|
|
5828
5974
|
find(id) {
|
|
5829
5975
|
const record = context.db.select().from(schedules).where(
|
|
5830
|
-
|
|
5976
|
+
and52(eq70(schedules.workspaceId, workspaceId), eq70(schedules.id, id))
|
|
5831
5977
|
).get();
|
|
5832
5978
|
if (!record) {
|
|
5833
5979
|
throw new ServiceError("NOT_FOUND", "Not found.");
|
|
@@ -5838,21 +5984,21 @@ function schedulesRepository(context) {
|
|
|
5838
5984
|
}
|
|
5839
5985
|
|
|
5840
5986
|
// server/router/schedules/get.ts
|
|
5841
|
-
var getProcedure12 = browserWorkspaceProcedure.input(
|
|
5987
|
+
var getProcedure12 = browserWorkspaceProcedure.input(z33.object({ id: z33.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
|
|
5842
5988
|
const id = input2.id;
|
|
5843
5989
|
return scheduleView(schedulesRepository(context).find(id));
|
|
5844
5990
|
});
|
|
5845
5991
|
|
|
5846
5992
|
// server/automations/schedule-schemas.ts
|
|
5847
|
-
import { z as
|
|
5848
|
-
var scheduleFields =
|
|
5849
|
-
action:
|
|
5850
|
-
cron:
|
|
5851
|
-
inputs:
|
|
5852
|
-
enabled:
|
|
5993
|
+
import { z as z34 } from "zod";
|
|
5994
|
+
var scheduleFields = z34.object({
|
|
5995
|
+
action: z34.uuid(),
|
|
5996
|
+
cron: z34.string().trim().min(1).max(100),
|
|
5997
|
+
inputs: z34.json().optional(),
|
|
5998
|
+
enabled: z34.boolean().optional()
|
|
5853
5999
|
});
|
|
5854
6000
|
var scheduleCreateSchema = scheduleFields.strict();
|
|
5855
|
-
var scheduleUpdateSchema = scheduleFields.partial().extend({ id:
|
|
6001
|
+
var scheduleUpdateSchema = scheduleFields.partial().extend({ id: z34.uuid() }).strict();
|
|
5856
6002
|
|
|
5857
6003
|
// server/automations/cron.ts
|
|
5858
6004
|
import { CronExpressionParser } from "cron-parser";
|
|
@@ -5903,7 +6049,7 @@ var createProcedure8 = browserWorkspaceProcedure.input(scheduleCreateSchema).mut
|
|
|
5903
6049
|
});
|
|
5904
6050
|
|
|
5905
6051
|
// server/router/schedules/update.ts
|
|
5906
|
-
import { and as
|
|
6052
|
+
import { and as and53, eq as eq71 } from "drizzle-orm";
|
|
5907
6053
|
var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mutation(({ ctx: context, input: input2 }) => {
|
|
5908
6054
|
return inTransaction(context, (context2) => {
|
|
5909
6055
|
const previous = schedulesRepository(context2).find(input2.id);
|
|
@@ -5926,9 +6072,9 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
|
|
|
5926
6072
|
nextRunAt,
|
|
5927
6073
|
updatedAt: now()
|
|
5928
6074
|
}).where(
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
6075
|
+
and53(
|
|
6076
|
+
eq71(schedules.workspaceId, context2.workspace.id),
|
|
6077
|
+
eq71(schedules.id, input2.id)
|
|
5932
6078
|
)
|
|
5933
6079
|
).returning().get();
|
|
5934
6080
|
if (!schedule) {
|
|
@@ -5940,15 +6086,15 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
|
|
|
5940
6086
|
});
|
|
5941
6087
|
|
|
5942
6088
|
// server/router/schedules/delete.ts
|
|
5943
|
-
import { and as
|
|
5944
|
-
import { z as
|
|
5945
|
-
var deleteProcedure5 = browserWorkspaceProcedure.input(
|
|
6089
|
+
import { and as and54, eq as eq72 } from "drizzle-orm";
|
|
6090
|
+
import { z as z35 } from "zod";
|
|
6091
|
+
var deleteProcedure5 = browserWorkspaceProcedure.input(z35.object({ id: z35.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
|
|
5946
6092
|
const id = input2.id;
|
|
5947
6093
|
return inTransaction(context, (context2) => {
|
|
5948
6094
|
const deleted = context2.db.delete(schedules).where(
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
6095
|
+
and54(
|
|
6096
|
+
eq72(schedules.workspaceId, context2.workspace.id),
|
|
6097
|
+
eq72(schedules.id, id)
|
|
5952
6098
|
)
|
|
5953
6099
|
).returning({ id: schedules.id }).get();
|
|
5954
6100
|
if (!deleted) {
|
|
@@ -5968,8 +6114,8 @@ var schedulesRouter = router({
|
|
|
5968
6114
|
});
|
|
5969
6115
|
|
|
5970
6116
|
// server/router/studio/approve.ts
|
|
5971
|
-
import { z as
|
|
5972
|
-
var approve = browserWorkspaceProcedure.input(
|
|
6117
|
+
import { z as z36 } from "zod";
|
|
6118
|
+
var approve = browserWorkspaceProcedure.input(z36.object({ challenge: z36.string().regex(/^[0-9a-f]{64}$/) }).strict()).mutation(({ ctx, input: input2 }) => {
|
|
5973
6119
|
if (ctx.studioOrigin || !ctx.sessionId || ctx.request.headers.get("origin") !== ctx.origin) {
|
|
5974
6120
|
throw new ServiceError(
|
|
5975
6121
|
"FORBIDDEN",
|
|
@@ -5997,9 +6143,9 @@ var discover = publicProcedure.query(({ ctx }) => {
|
|
|
5997
6143
|
});
|
|
5998
6144
|
|
|
5999
6145
|
// server/router/studio/exchange.ts
|
|
6000
|
-
import { z as
|
|
6146
|
+
import { z as z37 } from "zod";
|
|
6001
6147
|
var exchange = publicProcedure.input(
|
|
6002
|
-
|
|
6148
|
+
z37.object({ code: z37.string().length(43), verifier: z37.string().length(64) }).strict()
|
|
6003
6149
|
).mutation(({ ctx, input: input2 }) => {
|
|
6004
6150
|
if (!ctx.studioOrigin) {
|
|
6005
6151
|
throw new ServiceError("FORBIDDEN", "Open the configured dashboard.");
|
|
@@ -6029,7 +6175,7 @@ var systemRouter = router({
|
|
|
6029
6175
|
});
|
|
6030
6176
|
|
|
6031
6177
|
// server/router/tables/list.ts
|
|
6032
|
-
import { eq as
|
|
6178
|
+
import { eq as eq73 } from "drizzle-orm";
|
|
6033
6179
|
|
|
6034
6180
|
// server/tables/views.ts
|
|
6035
6181
|
function standard(row) {
|
|
@@ -6054,48 +6200,48 @@ function rowView(row) {
|
|
|
6054
6200
|
|
|
6055
6201
|
// server/router/tables/list.ts
|
|
6056
6202
|
var listProcedure12 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
6057
|
-
const records = ctx.db.select().from(workspaceTables).where(
|
|
6203
|
+
const records = ctx.db.select().from(workspaceTables).where(eq73(workspaceTables.workspaceId, ctx.workspace.id)).all();
|
|
6058
6204
|
return page(records.map((record) => standard(record)));
|
|
6059
6205
|
});
|
|
6060
6206
|
|
|
6061
6207
|
// server/tables/schemas.ts
|
|
6062
|
-
import { z as
|
|
6063
|
-
var identifier4 =
|
|
6064
|
-
var revision =
|
|
6065
|
-
var columns =
|
|
6066
|
-
|
|
6067
|
-
key:
|
|
6068
|
-
type:
|
|
6069
|
-
required:
|
|
6208
|
+
import { z as z38 } from "zod";
|
|
6209
|
+
var identifier4 = z38.uuid();
|
|
6210
|
+
var revision = z38.number().int().positive();
|
|
6211
|
+
var columns = z38.array(
|
|
6212
|
+
z38.strictObject({
|
|
6213
|
+
key: z38.string(),
|
|
6214
|
+
type: z38.enum(["text", "number", "boolean", "date"]),
|
|
6215
|
+
required: z38.boolean()
|
|
6070
6216
|
})
|
|
6071
6217
|
);
|
|
6072
|
-
var values =
|
|
6073
|
-
var tableIdSchema =
|
|
6074
|
-
var createTableSchema =
|
|
6075
|
-
var updateTableSchema =
|
|
6218
|
+
var values = z38.record(z38.string(), z38.json());
|
|
6219
|
+
var tableIdSchema = z38.strictObject({ id: identifier4 });
|
|
6220
|
+
var createTableSchema = z38.strictObject({ name: z38.string(), columns });
|
|
6221
|
+
var updateTableSchema = z38.strictObject({
|
|
6076
6222
|
id: identifier4,
|
|
6077
6223
|
revision,
|
|
6078
|
-
name:
|
|
6224
|
+
name: z38.string().optional(),
|
|
6079
6225
|
columns: columns.optional()
|
|
6080
6226
|
});
|
|
6081
|
-
var deleteTableSchema =
|
|
6082
|
-
var tableRowSchema =
|
|
6227
|
+
var deleteTableSchema = z38.strictObject({ id: identifier4, revision });
|
|
6228
|
+
var tableRowSchema = z38.strictObject({
|
|
6083
6229
|
id: identifier4,
|
|
6084
6230
|
rowId: identifier4
|
|
6085
6231
|
});
|
|
6086
|
-
var createRowSchema =
|
|
6232
|
+
var createRowSchema = z38.strictObject({
|
|
6087
6233
|
id: identifier4,
|
|
6088
6234
|
table_revision: revision,
|
|
6089
6235
|
values
|
|
6090
6236
|
});
|
|
6091
|
-
var updateRowSchema =
|
|
6237
|
+
var updateRowSchema = z38.strictObject({
|
|
6092
6238
|
id: identifier4,
|
|
6093
6239
|
rowId: identifier4,
|
|
6094
6240
|
table_revision: revision,
|
|
6095
6241
|
revision,
|
|
6096
6242
|
values
|
|
6097
6243
|
});
|
|
6098
|
-
var deleteRowSchema =
|
|
6244
|
+
var deleteRowSchema = z38.strictObject({
|
|
6099
6245
|
id: identifier4,
|
|
6100
6246
|
rowId: identifier4,
|
|
6101
6247
|
revision
|
|
@@ -6121,15 +6267,15 @@ var createProcedure9 = browserManagerProcedure.input(createTableSchema).mutation
|
|
|
6121
6267
|
);
|
|
6122
6268
|
|
|
6123
6269
|
// server/router/tables/update.ts
|
|
6124
|
-
import { and as
|
|
6270
|
+
import { and as and56, eq as eq75 } from "drizzle-orm";
|
|
6125
6271
|
|
|
6126
6272
|
// server/tables/queries.ts
|
|
6127
|
-
import { and as
|
|
6273
|
+
import { and as and55, eq as eq74 } from "drizzle-orm";
|
|
6128
6274
|
function rowsForTable(database, workspaceId, tableId2) {
|
|
6129
6275
|
return database.select().from(tableRows).where(
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6276
|
+
and55(
|
|
6277
|
+
eq74(tableRows.workspaceId, workspaceId),
|
|
6278
|
+
eq74(tableRows.tableId, tableId2)
|
|
6133
6279
|
)
|
|
6134
6280
|
).all();
|
|
6135
6281
|
}
|
|
@@ -6150,9 +6296,9 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
|
|
|
6150
6296
|
revision: current.revision + 1,
|
|
6151
6297
|
updatedAt: now()
|
|
6152
6298
|
}).where(
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6299
|
+
and56(
|
|
6300
|
+
eq75(workspaceTables.workspaceId, ctx2.workspace.id),
|
|
6301
|
+
eq75(workspaceTables.id, input2.id)
|
|
6156
6302
|
)
|
|
6157
6303
|
).returning().get();
|
|
6158
6304
|
if (!table) {
|
|
@@ -6165,14 +6311,14 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
|
|
|
6165
6311
|
});
|
|
6166
6312
|
|
|
6167
6313
|
// server/router/tables/delete.ts
|
|
6168
|
-
import { and as
|
|
6314
|
+
import { and as and58, eq as eq77 } from "drizzle-orm";
|
|
6169
6315
|
|
|
6170
6316
|
// server/repositories/table-rows.ts
|
|
6171
|
-
import { and as
|
|
6317
|
+
import { and as and57, eq as eq76 } from "drizzle-orm";
|
|
6172
6318
|
function removeTableRow(context, id) {
|
|
6173
6319
|
const workspaceId = requireWorkspace(context).id;
|
|
6174
6320
|
inTransaction(context, (transaction) => {
|
|
6175
|
-
const deleted = transaction.db.delete(tableRows).where(
|
|
6321
|
+
const deleted = transaction.db.delete(tableRows).where(and57(eq76(tableRows.workspaceId, workspaceId), eq76(tableRows.id, id))).returning({ id: tableRows.id }).get();
|
|
6176
6322
|
if (deleted) {
|
|
6177
6323
|
recordAudit(transaction, "row", id, "deleted");
|
|
6178
6324
|
}
|
|
@@ -6200,9 +6346,9 @@ var deleteProcedure6 = browserManagerProcedure.input(deleteTableSchema).mutation
|
|
|
6200
6346
|
});
|
|
6201
6347
|
}
|
|
6202
6348
|
const deleted = ctx2.db.delete(workspaceTables).where(
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6349
|
+
and58(
|
|
6350
|
+
eq77(workspaceTables.workspaceId, ctx2.workspace.id),
|
|
6351
|
+
eq77(workspaceTables.id, input2.id)
|
|
6206
6352
|
)
|
|
6207
6353
|
).returning({ id: workspaceTables.id }).get();
|
|
6208
6354
|
if (deleted) {
|
|
@@ -6219,13 +6365,13 @@ var listRowsProcedure = browserWorkspaceProcedure.input(tableIdSchema).query(({
|
|
|
6219
6365
|
});
|
|
6220
6366
|
|
|
6221
6367
|
// server/tables/access.ts
|
|
6222
|
-
import { and as
|
|
6368
|
+
import { and as and59, eq as eq78 } from "drizzle-orm";
|
|
6223
6369
|
function rowInTable(database, workspaceId, tableId2, rowId) {
|
|
6224
6370
|
const row = database.select().from(tableRows).where(
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6371
|
+
and59(
|
|
6372
|
+
eq78(tableRows.workspaceId, workspaceId),
|
|
6373
|
+
eq78(tableRows.tableId, tableId2),
|
|
6374
|
+
eq78(tableRows.id, rowId)
|
|
6229
6375
|
)
|
|
6230
6376
|
).get();
|
|
6231
6377
|
if (!row) {
|
|
@@ -6260,7 +6406,7 @@ var createRowProcedure = browserWorkspaceProcedure.input(createRowSchema).mutati
|
|
|
6260
6406
|
});
|
|
6261
6407
|
|
|
6262
6408
|
// server/router/tables/update-row.ts
|
|
6263
|
-
import { and as
|
|
6409
|
+
import { and as and60, eq as eq79 } from "drizzle-orm";
|
|
6264
6410
|
var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutation(({ ctx, input: input2 }) => {
|
|
6265
6411
|
return rowView(
|
|
6266
6412
|
inTransaction(ctx, (ctx2) => {
|
|
@@ -6274,9 +6420,9 @@ var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutati
|
|
|
6274
6420
|
revision: row.revision + 1,
|
|
6275
6421
|
updatedAt: now()
|
|
6276
6422
|
}).where(
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6423
|
+
and60(
|
|
6424
|
+
eq79(tableRows.workspaceId, ctx2.workspace.id),
|
|
6425
|
+
eq79(tableRows.id, input2.rowId)
|
|
6280
6426
|
)
|
|
6281
6427
|
).returning().get();
|
|
6282
6428
|
if (!updatedRow) {
|
|
@@ -6316,7 +6462,7 @@ var tablesRouter = router({
|
|
|
6316
6462
|
});
|
|
6317
6463
|
|
|
6318
6464
|
// server/router/tokens/list.ts
|
|
6319
|
-
import { eq as
|
|
6465
|
+
import { eq as eq80 } from "drizzle-orm";
|
|
6320
6466
|
|
|
6321
6467
|
// server/tokens/views.ts
|
|
6322
6468
|
function tokenView(row) {
|
|
@@ -6344,18 +6490,18 @@ function tokenView(row) {
|
|
|
6344
6490
|
|
|
6345
6491
|
// server/router/tokens/list.ts
|
|
6346
6492
|
var listProcedure13 = browserManagerProcedure.query(({ ctx }) => {
|
|
6347
|
-
const records = ctx.db.select().from(accessTokens).where(
|
|
6493
|
+
const records = ctx.db.select().from(accessTokens).where(eq80(accessTokens.workspaceId, ctx.workspace.id)).all();
|
|
6348
6494
|
return page(records.map((record) => tokenView(record)));
|
|
6349
6495
|
});
|
|
6350
6496
|
|
|
6351
6497
|
// server/router/tokens/get.ts
|
|
6352
|
-
import { and as
|
|
6353
|
-
import { z as
|
|
6354
|
-
var getProcedure14 = browserManagerProcedure.input(
|
|
6498
|
+
import { and as and61, eq as eq81 } from "drizzle-orm";
|
|
6499
|
+
import { z as z39 } from "zod";
|
|
6500
|
+
var getProcedure14 = browserManagerProcedure.input(z39.strictObject({ id: z39.uuid() })).query(({ ctx, input: input2 }) => {
|
|
6355
6501
|
const token = ctx.db.select().from(accessTokens).where(
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6502
|
+
and61(
|
|
6503
|
+
eq81(accessTokens.workspaceId, ctx.workspace.id),
|
|
6504
|
+
eq81(accessTokens.id, input2.id)
|
|
6359
6505
|
)
|
|
6360
6506
|
).get();
|
|
6361
6507
|
if (!token) {
|
|
@@ -6365,8 +6511,8 @@ var getProcedure14 = browserManagerProcedure.input(z36.strictObject({ id: z36.uu
|
|
|
6365
6511
|
});
|
|
6366
6512
|
|
|
6367
6513
|
// server/tokens/schemas.ts
|
|
6368
|
-
import { z as
|
|
6369
|
-
var clientScopes =
|
|
6514
|
+
import { z as z40 } from "zod";
|
|
6515
|
+
var clientScopes = z40.enum([
|
|
6370
6516
|
"catalog:read",
|
|
6371
6517
|
"code:execute",
|
|
6372
6518
|
"actions:write",
|
|
@@ -6375,11 +6521,11 @@ var clientScopes = z37.enum([
|
|
|
6375
6521
|
"runs:read",
|
|
6376
6522
|
"runs:cancel"
|
|
6377
6523
|
]);
|
|
6378
|
-
var tokenCreateSchema =
|
|
6379
|
-
name:
|
|
6380
|
-
scopes:
|
|
6381
|
-
projects:
|
|
6382
|
-
action_versions:
|
|
6524
|
+
var tokenCreateSchema = z40.object({
|
|
6525
|
+
name: z40.string().trim().min(1).max(100),
|
|
6526
|
+
scopes: z40.array(clientScopes).min(1),
|
|
6527
|
+
projects: z40.array(z40.uuid()).default([]),
|
|
6528
|
+
action_versions: z40.array(z40.uuid()).default([])
|
|
6383
6529
|
}).strict();
|
|
6384
6530
|
|
|
6385
6531
|
// server/router/tokens/create.ts
|
|
@@ -6418,14 +6564,14 @@ var createProcedure10 = browserManagerProcedure.input(tokenCreateSchema).output(
|
|
|
6418
6564
|
});
|
|
6419
6565
|
|
|
6420
6566
|
// server/router/tokens/revoke.ts
|
|
6421
|
-
import { and as
|
|
6422
|
-
import { z as
|
|
6423
|
-
var revokeProcedure = browserManagerProcedure.input(
|
|
6567
|
+
import { and as and62, eq as eq82 } from "drizzle-orm";
|
|
6568
|
+
import { z as z41 } from "zod";
|
|
6569
|
+
var revokeProcedure = browserManagerProcedure.input(z41.strictObject({ id: z41.uuid() })).mutation(({ ctx, input: input2 }) => {
|
|
6424
6570
|
return inTransaction(ctx, (ctx2) => {
|
|
6425
6571
|
const token = ctx2.db.update(accessTokens).set({ revoked: true, updatedAt: now() }).where(
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6572
|
+
and62(
|
|
6573
|
+
eq82(accessTokens.workspaceId, ctx2.workspace.id),
|
|
6574
|
+
eq82(accessTokens.id, input2.id)
|
|
6429
6575
|
)
|
|
6430
6576
|
).returning().get();
|
|
6431
6577
|
if (!token) {
|
|
@@ -6468,20 +6614,20 @@ var usersRouter = router({
|
|
|
6468
6614
|
});
|
|
6469
6615
|
|
|
6470
6616
|
// server/router/webhooks/list.ts
|
|
6471
|
-
import { eq as
|
|
6617
|
+
import { eq as eq84 } from "drizzle-orm";
|
|
6472
6618
|
|
|
6473
6619
|
// server/automations/webhook-view.ts
|
|
6474
|
-
import { desc as desc5, eq as
|
|
6475
|
-
import { and as
|
|
6620
|
+
import { desc as desc5, eq as eq83 } from "drizzle-orm";
|
|
6621
|
+
import { and as and63 } from "drizzle-orm";
|
|
6476
6622
|
function webhookView(context, webhook) {
|
|
6477
6623
|
const version = actionVersionsRepository(context).find(
|
|
6478
6624
|
webhook.actionVersionId
|
|
6479
6625
|
);
|
|
6480
6626
|
const action = actionsRepository(context).find(version.actionId);
|
|
6481
6627
|
const deliveries = context.db.select().from(webhookDeliveries).where(
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6628
|
+
and63(
|
|
6629
|
+
eq83(webhookDeliveries.workspaceId, workspace(context)),
|
|
6630
|
+
eq83(webhookDeliveries.webhookId, webhook.id)
|
|
6485
6631
|
)
|
|
6486
6632
|
).orderBy(desc5(webhookDeliveries.createdAt)).limit(20).all();
|
|
6487
6633
|
return {
|
|
@@ -6510,19 +6656,19 @@ function webhookView(context, webhook) {
|
|
|
6510
6656
|
|
|
6511
6657
|
// server/router/webhooks/list.ts
|
|
6512
6658
|
var listProcedure14 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
6513
|
-
const records = ctx.db.select().from(webhooks).where(
|
|
6659
|
+
const records = ctx.db.select().from(webhooks).where(eq84(webhooks.workspaceId, ctx.workspace.id)).all();
|
|
6514
6660
|
return page(records.map((record) => webhookView(ctx, record)));
|
|
6515
6661
|
});
|
|
6516
6662
|
|
|
6517
6663
|
// server/router/webhooks/get.ts
|
|
6518
|
-
import { z as
|
|
6664
|
+
import { z as z42 } from "zod";
|
|
6519
6665
|
|
|
6520
6666
|
// server/repositories/webhooks.ts
|
|
6521
|
-
import { and as
|
|
6667
|
+
import { and as and64, eq as eq85 } from "drizzle-orm";
|
|
6522
6668
|
function webhooksRepository(context) {
|
|
6523
6669
|
const workspaceId = requireWorkspace(context).id;
|
|
6524
6670
|
const database = context.db;
|
|
6525
|
-
const scoped = (id) =>
|
|
6671
|
+
const scoped = (id) => and64(eq85(webhooks.workspaceId, workspaceId), eq85(webhooks.id, id));
|
|
6526
6672
|
return {
|
|
6527
6673
|
find(id) {
|
|
6528
6674
|
const row = database.select().from(webhooks).where(scoped(id)).get();
|
|
@@ -6546,22 +6692,22 @@ function webhooksRepository(context) {
|
|
|
6546
6692
|
}
|
|
6547
6693
|
|
|
6548
6694
|
// server/router/webhooks/get.ts
|
|
6549
|
-
var getProcedure15 = browserWorkspaceProcedure.input(
|
|
6695
|
+
var getProcedure15 = browserWorkspaceProcedure.input(z42.object({ id: z42.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
|
|
6550
6696
|
const id = input2.id;
|
|
6551
6697
|
return webhookView(context, webhooksRepository(context).find(id));
|
|
6552
6698
|
});
|
|
6553
6699
|
|
|
6554
6700
|
// server/automations/webhook-schemas.ts
|
|
6555
|
-
import { z as
|
|
6556
|
-
var webhookCreateSchema =
|
|
6557
|
-
name:
|
|
6558
|
-
action:
|
|
6559
|
-
enabled:
|
|
6701
|
+
import { z as z43 } from "zod";
|
|
6702
|
+
var webhookCreateSchema = z43.object({
|
|
6703
|
+
name: z43.string().trim().min(1).max(100),
|
|
6704
|
+
action: z43.uuid(),
|
|
6705
|
+
enabled: z43.boolean().optional()
|
|
6560
6706
|
}).strict();
|
|
6561
|
-
var webhookUpdateSchema =
|
|
6562
|
-
id:
|
|
6563
|
-
name:
|
|
6564
|
-
enabled:
|
|
6707
|
+
var webhookUpdateSchema = z43.object({
|
|
6708
|
+
id: z43.uuid(),
|
|
6709
|
+
name: z43.string().trim().min(1).max(100).optional(),
|
|
6710
|
+
enabled: z43.boolean().optional()
|
|
6565
6711
|
}).strict();
|
|
6566
6712
|
|
|
6567
6713
|
// server/router/webhooks/create.ts
|
|
@@ -6606,8 +6752,8 @@ var updateProcedure9 = browserManagerProcedure.input(webhookUpdateSchema).mutati
|
|
|
6606
6752
|
});
|
|
6607
6753
|
|
|
6608
6754
|
// server/router/webhooks/rotate.ts
|
|
6609
|
-
import { z as
|
|
6610
|
-
var rotateProcedure = browserManagerProcedure.input(
|
|
6755
|
+
import { z as z44 } from "zod";
|
|
6756
|
+
var rotateProcedure = browserManagerProcedure.input(z44.object({ id: z44.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
|
|
6611
6757
|
const id = input2.id;
|
|
6612
6758
|
return inTransaction(context, (context2) => {
|
|
6613
6759
|
const secret = randomSecret();
|
|
@@ -6637,7 +6783,7 @@ var listProcedure15 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6637
6783
|
});
|
|
6638
6784
|
|
|
6639
6785
|
// server/router/workspace/current.ts
|
|
6640
|
-
import { eq as
|
|
6786
|
+
import { eq as eq86 } from "drizzle-orm";
|
|
6641
6787
|
|
|
6642
6788
|
// server/workspaces/views.ts
|
|
6643
6789
|
var serializeInvite = (invitation) => ({
|
|
@@ -6656,34 +6802,34 @@ var currentProcedure = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6656
6802
|
workspace: { id: workspace2.id, name: workspace2.name },
|
|
6657
6803
|
role: ctx.role,
|
|
6658
6804
|
members: memberQuery(ctx.db, workspace2.id).all(),
|
|
6659
|
-
invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(
|
|
6805
|
+
invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(eq86(invitations.workspaceId, workspace2.id)).all().map(serializeInvite) : []
|
|
6660
6806
|
};
|
|
6661
6807
|
});
|
|
6662
6808
|
|
|
6663
6809
|
// server/router/workspace/update.ts
|
|
6664
|
-
import { eq as
|
|
6810
|
+
import { eq as eq87 } from "drizzle-orm";
|
|
6665
6811
|
|
|
6666
6812
|
// server/workspaces/schemas.ts
|
|
6667
|
-
import { z as
|
|
6668
|
-
var membershipIdSchema =
|
|
6669
|
-
id:
|
|
6813
|
+
import { z as z45 } from "zod";
|
|
6814
|
+
var membershipIdSchema = z45.strictObject({
|
|
6815
|
+
id: z45.number().int().positive()
|
|
6670
6816
|
});
|
|
6671
|
-
var workspaceNameSchema =
|
|
6672
|
-
name:
|
|
6817
|
+
var workspaceNameSchema = z45.strictObject({
|
|
6818
|
+
name: z45.string().trim().min(1).max(100)
|
|
6673
6819
|
});
|
|
6674
|
-
var roleSchema =
|
|
6820
|
+
var roleSchema = z45.enum(["admin", "member"]);
|
|
6675
6821
|
var memberUpdateSchema = membershipIdSchema.extend({
|
|
6676
6822
|
role: roleSchema
|
|
6677
6823
|
});
|
|
6678
|
-
var ownershipSchema =
|
|
6679
|
-
membership_id:
|
|
6824
|
+
var ownershipSchema = z45.strictObject({
|
|
6825
|
+
membership_id: z45.number().int().positive()
|
|
6680
6826
|
});
|
|
6681
|
-
var invitationSchema =
|
|
6827
|
+
var invitationSchema = z45.strictObject({
|
|
6682
6828
|
email: emailSchema,
|
|
6683
6829
|
role: roleSchema
|
|
6684
6830
|
});
|
|
6685
|
-
var invitationTokenSchema =
|
|
6686
|
-
token:
|
|
6831
|
+
var invitationTokenSchema = z45.strictObject({
|
|
6832
|
+
token: z45.string().min(1)
|
|
6687
6833
|
});
|
|
6688
6834
|
|
|
6689
6835
|
// server/router/workspace/update.ts
|
|
@@ -6700,7 +6846,7 @@ var updateProcedure10 = browserManagerProcedure.input(workspaceNameSchema).mutat
|
|
|
6700
6846
|
"Only workspace owners and admins can manage this workspace."
|
|
6701
6847
|
);
|
|
6702
6848
|
}
|
|
6703
|
-
const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(
|
|
6849
|
+
const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(eq87(workspaces.id, workspace2.id)).returning().get();
|
|
6704
6850
|
return { id: updated.id, name: updated.name };
|
|
6705
6851
|
});
|
|
6706
6852
|
});
|
|
@@ -6728,13 +6874,13 @@ import { randomUUID as randomUUID5 } from "node:crypto";
|
|
|
6728
6874
|
import nodemailer from "nodemailer";
|
|
6729
6875
|
|
|
6730
6876
|
// server/repositories/mail-outbox.ts
|
|
6731
|
-
import { and as
|
|
6877
|
+
import { and as and65, asc as asc6, eq as eq88, isNull, lt as lt3, lte, or as or5 } from "drizzle-orm";
|
|
6732
6878
|
function enqueueMail(store, message) {
|
|
6733
6879
|
store.db.insert(mailOutbox).values({ ...message, nextAttempt: Date.now() }).run();
|
|
6734
6880
|
}
|
|
6735
6881
|
function revokeUnsentMail(store, id) {
|
|
6736
|
-
const unsent =
|
|
6737
|
-
|
|
6882
|
+
const unsent = and65(
|
|
6883
|
+
eq88(mailOutbox.id, id),
|
|
6738
6884
|
isNull(mailOutbox.sentAt),
|
|
6739
6885
|
isNull(mailOutbox.leaseUntil)
|
|
6740
6886
|
);
|
|
@@ -6746,29 +6892,29 @@ function claimMail(store, time) {
|
|
|
6746
6892
|
isNull(mailOutbox.leaseUntil),
|
|
6747
6893
|
lt3(mailOutbox.leaseUntil, time)
|
|
6748
6894
|
);
|
|
6749
|
-
const due =
|
|
6895
|
+
const due = and65(
|
|
6750
6896
|
isNull(mailOutbox.sentAt),
|
|
6751
6897
|
lte(mailOutbox.nextAttempt, time),
|
|
6752
6898
|
availableLease
|
|
6753
6899
|
);
|
|
6754
|
-
const row = store2.db.select().from(mailOutbox).where(due).orderBy(
|
|
6900
|
+
const row = store2.db.select().from(mailOutbox).where(due).orderBy(asc6(mailOutbox.nextAttempt)).limit(1).get();
|
|
6755
6901
|
if (!row) {
|
|
6756
6902
|
return;
|
|
6757
6903
|
}
|
|
6758
6904
|
if (row.id.startsWith("invitation:")) {
|
|
6759
6905
|
const id = Number(row.id.slice("invitation:".length));
|
|
6760
|
-
const invitation = store2.db.select().from(invitations).where(
|
|
6906
|
+
const invitation = store2.db.select().from(invitations).where(eq88(invitations.id, id)).get();
|
|
6761
6907
|
if (!invitation || invitation.acceptedAt || invitation.revokedAt || invitation.expiresAt <= new Date(time).toISOString()) {
|
|
6762
|
-
store2.db.delete(mailOutbox).where(
|
|
6908
|
+
store2.db.delete(mailOutbox).where(eq88(mailOutbox.id, row.id)).run();
|
|
6763
6909
|
return;
|
|
6764
6910
|
}
|
|
6765
6911
|
}
|
|
6766
|
-
store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(
|
|
6912
|
+
store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(eq88(mailOutbox.id, row.id)).run();
|
|
6767
6913
|
return row;
|
|
6768
6914
|
});
|
|
6769
6915
|
}
|
|
6770
6916
|
function markMailSent(store, id) {
|
|
6771
|
-
store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(
|
|
6917
|
+
store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(eq88(mailOutbox.id, id)).run();
|
|
6772
6918
|
}
|
|
6773
6919
|
function retryMail(store, job) {
|
|
6774
6920
|
const attempts = job.attempts + 1;
|
|
@@ -6778,7 +6924,7 @@ function retryMail(store, job) {
|
|
|
6778
6924
|
nextAttempt: Date.now() + delay,
|
|
6779
6925
|
leaseUntil: null,
|
|
6780
6926
|
lastError: "Delivery failed"
|
|
6781
|
-
}).where(
|
|
6927
|
+
}).where(eq88(mailOutbox.id, job.id)).run();
|
|
6782
6928
|
}
|
|
6783
6929
|
|
|
6784
6930
|
// server/mail/outbox.ts
|
|
@@ -6832,7 +6978,7 @@ async function flushOutbox(store, send) {
|
|
|
6832
6978
|
}
|
|
6833
6979
|
|
|
6834
6980
|
// server/router/workspace/invite.ts
|
|
6835
|
-
import { and as
|
|
6981
|
+
import { and as and66, eq as eq89, isNull as isNull2, sql as sql3 } from "drizzle-orm";
|
|
6836
6982
|
var inviteProcedure = browserManagerProcedure.input(invitationSchema).mutation(({ ctx, input: input2 }) => {
|
|
6837
6983
|
const user = ctx.user;
|
|
6838
6984
|
const workspace2 = ctx.workspace;
|
|
@@ -6870,10 +7016,10 @@ This invitation expires in seven days.`
|
|
|
6870
7016
|
"Only the owner can invite admins."
|
|
6871
7017
|
);
|
|
6872
7018
|
}
|
|
6873
|
-
const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users,
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
7019
|
+
const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users, eq89(users.id, memberships.userId)).where(
|
|
7020
|
+
and66(
|
|
7021
|
+
eq89(memberships.workspaceId, workspace2.id),
|
|
7022
|
+
sql3`lower(${users.email}) = ${email}`
|
|
6877
7023
|
)
|
|
6878
7024
|
).get();
|
|
6879
7025
|
if (existingMember) {
|
|
@@ -6883,9 +7029,9 @@ This invitation expires in seven days.`
|
|
|
6883
7029
|
);
|
|
6884
7030
|
}
|
|
6885
7031
|
const prior = db.select({ id: invitations.id, expiresAt: invitations.expiresAt }).from(invitations).where(
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
7032
|
+
and66(
|
|
7033
|
+
eq89(invitations.workspaceId, workspace2.id),
|
|
7034
|
+
sql3`lower(${invitations.email}) = ${email}`,
|
|
6889
7035
|
isNull2(invitations.acceptedAt),
|
|
6890
7036
|
isNull2(invitations.revokedAt)
|
|
6891
7037
|
)
|
|
@@ -6919,7 +7065,7 @@ This invitation expires in seven days.`
|
|
|
6919
7065
|
});
|
|
6920
7066
|
|
|
6921
7067
|
// server/router/workspace/revoke-invitation.ts
|
|
6922
|
-
import { and as
|
|
7068
|
+
import { and as and67, eq as eq90 } from "drizzle-orm";
|
|
6923
7069
|
var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
6924
7070
|
const id = input2.id;
|
|
6925
7071
|
const user = ctx.user;
|
|
@@ -6934,9 +7080,9 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
|
|
|
6934
7080
|
);
|
|
6935
7081
|
}
|
|
6936
7082
|
const invitation = ctx2.db.select().from(invitations).where(
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
7083
|
+
and67(
|
|
7084
|
+
eq90(invitations.workspaceId, workspace2.id),
|
|
7085
|
+
eq90(invitations.id, id)
|
|
6940
7086
|
)
|
|
6941
7087
|
).get();
|
|
6942
7088
|
if (!invitation) {
|
|
@@ -6957,7 +7103,7 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
|
|
|
6957
7103
|
});
|
|
6958
7104
|
|
|
6959
7105
|
// server/router/workspace/accept-invitation.ts
|
|
6960
|
-
import { and as
|
|
7106
|
+
import { and as and68, eq as eq91 } from "drizzle-orm";
|
|
6961
7107
|
var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTokenSchema).mutation(({ ctx, input: input2 }) => {
|
|
6962
7108
|
const token = input2.token;
|
|
6963
7109
|
const user = ctx.user;
|
|
@@ -6969,9 +7115,9 @@ var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTo
|
|
|
6969
7115
|
throw new ServiceError("NOT_FOUND", "Invitation not found.");
|
|
6970
7116
|
}
|
|
6971
7117
|
const invite = db.select().from(invitations).where(
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
7118
|
+
and68(
|
|
7119
|
+
eq91(invitations.workspaceId, workspace2.id),
|
|
7120
|
+
eq91(invitations.tokenDigest, digest(token))
|
|
6975
7121
|
)
|
|
6976
7122
|
).get();
|
|
6977
7123
|
if (!invite) {
|
|
@@ -7052,7 +7198,7 @@ var updateMemberProcedure = browserOwnerProcedure.input(memberUpdateSchema).muta
|
|
|
7052
7198
|
});
|
|
7053
7199
|
|
|
7054
7200
|
// server/router/workspace/remove-member.ts
|
|
7055
|
-
import { and as
|
|
7201
|
+
import { and as and69, eq as eq92 } from "drizzle-orm";
|
|
7056
7202
|
var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
7057
7203
|
const id = input2.id;
|
|
7058
7204
|
inTransaction(ctx, (ctx2) => {
|
|
@@ -7065,9 +7211,9 @@ var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).
|
|
|
7065
7211
|
);
|
|
7066
7212
|
}
|
|
7067
7213
|
ctx2.db.delete(memberships).where(
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7214
|
+
and69(
|
|
7215
|
+
eq92(memberships.workspaceId, target.workspaceId),
|
|
7216
|
+
eq92(memberships.id, id)
|
|
7071
7217
|
)
|
|
7072
7218
|
).run();
|
|
7073
7219
|
});
|
|
@@ -7138,8 +7284,8 @@ var appRouter = router({
|
|
|
7138
7284
|
// server/api/mcp-dispatch.ts
|
|
7139
7285
|
async function dispatchTool(context, name, toolInput) {
|
|
7140
7286
|
const caller = appRouter.createCaller(context);
|
|
7141
|
-
const id = () =>
|
|
7142
|
-
const actionId = () =>
|
|
7287
|
+
const id = () => z46.string().parse(toolInput.id);
|
|
7288
|
+
const actionId = () => z46.string().parse(toolInput.action);
|
|
7143
7289
|
const queueSession = (session) => caller.runs.session(
|
|
7144
7290
|
sessionRunSchema.parse({
|
|
7145
7291
|
project: toolInput.project,
|
|
@@ -7160,7 +7306,7 @@ async function dispatchTool(context, name, toolInput) {
|
|
|
7160
7306
|
};
|
|
7161
7307
|
}
|
|
7162
7308
|
case "get_project_sdk":
|
|
7163
|
-
return caller.projects.sdk({ id:
|
|
7309
|
+
return caller.projects.sdk({ id: z46.string().parse(toolInput.project) });
|
|
7164
7310
|
case "execute_code":
|
|
7165
7311
|
return caller.runs.create(
|
|
7166
7312
|
createRunSchema.strip().parse({ ...toolInput, operation: "code" })
|
|
@@ -7170,23 +7316,23 @@ async function dispatchTool(context, name, toolInput) {
|
|
|
7170
7316
|
case "execute_cell":
|
|
7171
7317
|
return queueSession({
|
|
7172
7318
|
operation: "execute",
|
|
7173
|
-
id:
|
|
7174
|
-
cellId:
|
|
7175
|
-
generation:
|
|
7176
|
-
expectedSequence:
|
|
7319
|
+
id: z46.uuid().parse(toolInput.session_id),
|
|
7320
|
+
cellId: z46.uuid().parse(toolInput.cell_id),
|
|
7321
|
+
generation: z46.number().parse(toolInput.generation),
|
|
7322
|
+
expectedSequence: z46.number().parse(toolInput.expected_sequence),
|
|
7177
7323
|
after: toolInput.after
|
|
7178
7324
|
});
|
|
7179
7325
|
case "read_session":
|
|
7180
7326
|
return queueSession({
|
|
7181
7327
|
operation: "read",
|
|
7182
|
-
id:
|
|
7328
|
+
id: z46.uuid().parse(toolInput.session_id),
|
|
7183
7329
|
after: toolInput.after,
|
|
7184
7330
|
limit: toolInput.limit
|
|
7185
7331
|
});
|
|
7186
7332
|
case "close_session":
|
|
7187
7333
|
return queueSession({
|
|
7188
7334
|
operation: "close",
|
|
7189
|
-
id:
|
|
7335
|
+
id: z46.uuid().parse(toolInput.session_id)
|
|
7190
7336
|
});
|
|
7191
7337
|
case "get_run_events": {
|
|
7192
7338
|
const all = await caller.runs.events({ id: id() });
|
|
@@ -7263,17 +7409,17 @@ async function dispatchTool(context, name, toolInput) {
|
|
|
7263
7409
|
}
|
|
7264
7410
|
|
|
7265
7411
|
// server/api/mcp-schemas.ts
|
|
7266
|
-
import { z as
|
|
7267
|
-
var mcpArgumentsSchema =
|
|
7268
|
-
action:
|
|
7269
|
-
project:
|
|
7270
|
-
id:
|
|
7271
|
-
version:
|
|
7272
|
-
suite_revision:
|
|
7273
|
-
after:
|
|
7274
|
-
offset:
|
|
7275
|
-
limit:
|
|
7276
|
-
}).catchall(
|
|
7412
|
+
import { z as z47 } from "zod";
|
|
7413
|
+
var mcpArgumentsSchema = z47.object({
|
|
7414
|
+
action: z47.string().optional(),
|
|
7415
|
+
project: z47.string().optional(),
|
|
7416
|
+
id: z47.string().optional(),
|
|
7417
|
+
version: z47.number().optional(),
|
|
7418
|
+
suite_revision: z47.number().optional(),
|
|
7419
|
+
after: z47.number().optional(),
|
|
7420
|
+
offset: z47.number().optional(),
|
|
7421
|
+
limit: z47.number().optional()
|
|
7422
|
+
}).catchall(z47.json());
|
|
7277
7423
|
|
|
7278
7424
|
// server/api/mcp.ts
|
|
7279
7425
|
import Ajv2 from "ajv";
|
|
@@ -8024,18 +8170,18 @@ async function handleMcp(ctx) {
|
|
|
8024
8170
|
}
|
|
8025
8171
|
|
|
8026
8172
|
// server/automations/ingress.ts
|
|
8027
|
-
import { z as
|
|
8028
|
-
import { and as
|
|
8173
|
+
import { z as z48 } from "zod";
|
|
8174
|
+
import { and as and71, eq as eq94 } from "drizzle-orm";
|
|
8029
8175
|
import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
8030
8176
|
|
|
8031
8177
|
// server/repositories/webhook-deliveries.ts
|
|
8032
|
-
import { and as
|
|
8178
|
+
import { and as and70, eq as eq93 } from "drizzle-orm";
|
|
8033
8179
|
function webhookDeliveriesRepository(context) {
|
|
8034
8180
|
const workspaceId = requireWorkspace(context).id;
|
|
8035
8181
|
const database = context.db;
|
|
8036
|
-
const scoped = (id, filter) =>
|
|
8037
|
-
|
|
8038
|
-
id === void 0 ? void 0 :
|
|
8182
|
+
const scoped = (id, filter) => and70(
|
|
8183
|
+
eq93(webhookDeliveries.workspaceId, workspaceId),
|
|
8184
|
+
id === void 0 ? void 0 : eq93(webhookDeliveries.id, id),
|
|
8039
8185
|
filter
|
|
8040
8186
|
);
|
|
8041
8187
|
return {
|
|
@@ -8063,7 +8209,7 @@ async function handleWebhookIngress(ctx) {
|
|
|
8063
8209
|
if (ctx.request.method !== "POST") {
|
|
8064
8210
|
throw new HttpError(405, "Method not allowed.");
|
|
8065
8211
|
}
|
|
8066
|
-
const hook = ctx.db.select().from(webhooks).where(
|
|
8212
|
+
const hook = ctx.db.select().from(webhooks).where(eq94(webhooks.id, match[1])).get();
|
|
8067
8213
|
if (!hook || !ctx.workspace || hook.workspaceId !== ctx.workspace.id) {
|
|
8068
8214
|
throw new HttpError(404, "Webhook not found.");
|
|
8069
8215
|
}
|
|
@@ -8098,9 +8244,9 @@ async function handleWebhookIngress(ctx) {
|
|
|
8098
8244
|
jsonValue(payload.inputs, "Inputs");
|
|
8099
8245
|
const actor = identityRepository(ctx.db).user(hook.actorId);
|
|
8100
8246
|
const member = ctx.db.select().from(memberships).where(
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8247
|
+
and71(
|
|
8248
|
+
eq94(memberships.userId, hook.actorId),
|
|
8249
|
+
eq94(memberships.workspaceId, hook.workspaceId)
|
|
8104
8250
|
)
|
|
8105
8251
|
).get();
|
|
8106
8252
|
if (!hook.enabled || !actor || !member) {
|
|
@@ -8121,9 +8267,9 @@ async function handleWebhookIngress(ctx) {
|
|
|
8121
8267
|
throw new HttpError(403, "Webhook is unavailable.");
|
|
8122
8268
|
}
|
|
8123
8269
|
const old = webhookDeliveriesRepository(actorCtx2).list(
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8270
|
+
and71(
|
|
8271
|
+
eq94(webhookDeliveries.webhookId, hook.id),
|
|
8272
|
+
eq94(webhookDeliveries.deliveryId, delivery)
|
|
8127
8273
|
)
|
|
8128
8274
|
)[0];
|
|
8129
8275
|
if (old) {
|
|
@@ -8143,7 +8289,7 @@ async function handleWebhookIngress(ctx) {
|
|
|
8143
8289
|
operation: "action",
|
|
8144
8290
|
action: action.id,
|
|
8145
8291
|
version: version.number,
|
|
8146
|
-
inputs:
|
|
8292
|
+
inputs: z48.record(z48.string(), z48.json()).parse(payload.inputs),
|
|
8147
8293
|
idempotency_key: `webhook:${hook.id}:${delivery}`
|
|
8148
8294
|
});
|
|
8149
8295
|
runsRepository(actorCtx2).update(run.id, {
|
|
@@ -8166,7 +8312,7 @@ async function handleWebhookIngress(ctx) {
|
|
|
8166
8312
|
}
|
|
8167
8313
|
|
|
8168
8314
|
// server/execution/authority.ts
|
|
8169
|
-
import { and as
|
|
8315
|
+
import { and as and72, eq as eq95 } from "drizzle-orm";
|
|
8170
8316
|
import { timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
8171
8317
|
var terminal = /* @__PURE__ */ new Set([
|
|
8172
8318
|
"succeeded",
|
|
@@ -8184,15 +8330,15 @@ function bearer(ctx) {
|
|
|
8184
8330
|
}
|
|
8185
8331
|
function executor(ctx) {
|
|
8186
8332
|
const row = ctx.db.select().from(executors).where(
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8333
|
+
and72(
|
|
8334
|
+
eq95(executors.tokenHash, digest(bearer(ctx))),
|
|
8335
|
+
eq95(executors.enabled, true)
|
|
8190
8336
|
)
|
|
8191
8337
|
).get();
|
|
8192
8338
|
const project = row && ctx.db.select().from(projects).where(
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8339
|
+
and72(
|
|
8340
|
+
eq95(projects.id, row.projectId),
|
|
8341
|
+
eq95(projects.workspaceId, row.workspaceId)
|
|
8196
8342
|
)
|
|
8197
8343
|
).get();
|
|
8198
8344
|
if (!row || !project?.enabled) {
|
|
@@ -8201,17 +8347,17 @@ function executor(ctx) {
|
|
|
8201
8347
|
return row;
|
|
8202
8348
|
}
|
|
8203
8349
|
function runCapability(ctx, expectedId) {
|
|
8204
|
-
const run = ctx.db.select().from(runs).where(
|
|
8350
|
+
const run = ctx.db.select().from(runs).where(eq95(runs.capabilityHash, digest(bearer(ctx)))).get();
|
|
8205
8351
|
const currentTime = now();
|
|
8206
8352
|
if (!run || expectedId && run.id !== expectedId || !run.deadline || run.deadline <= currentTime || !run.leaseExpiresAt || run.leaseExpiresAt <= currentTime) {
|
|
8207
8353
|
throw new HttpError(401, "Invalid or expired run capability.");
|
|
8208
8354
|
}
|
|
8209
|
-
const worker = run.executorId && ctx.db.select().from(executors).where(
|
|
8210
|
-
const project = ctx.db.select().from(projects).where(
|
|
8355
|
+
const worker = run.executorId && ctx.db.select().from(executors).where(eq95(executors.id, run.executorId)).get();
|
|
8356
|
+
const project = ctx.db.select().from(projects).where(eq95(projects.id, run.projectId)).get();
|
|
8211
8357
|
const member = ctx.db.select().from(memberships).where(
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8358
|
+
and72(
|
|
8359
|
+
eq95(memberships.workspaceId, run.workspaceId),
|
|
8360
|
+
eq95(memberships.userId, run.actorId)
|
|
8215
8361
|
)
|
|
8216
8362
|
).get();
|
|
8217
8363
|
if (!worker || !worker.enabled || worker.projectId !== run.projectId || !project?.enabled || !member) {
|
|
@@ -8231,9 +8377,9 @@ function runCapability(ctx, expectedId) {
|
|
|
8231
8377
|
if (!terminal.has(run.status) && !run.cancelRequested) {
|
|
8232
8378
|
const operation = object(command2) ? command2.operation : void 0;
|
|
8233
8379
|
const token = run.tokenId ? ctx.db.select().from(accessTokens).where(
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8380
|
+
and72(
|
|
8381
|
+
eq95(accessTokens.workspaceId, run.workspaceId),
|
|
8382
|
+
eq95(accessTokens.id, run.tokenId)
|
|
8237
8383
|
)
|
|
8238
8384
|
).get() : void 0;
|
|
8239
8385
|
const tokenRevoked = run.tokenId && (!token || token.revoked || !token.projects.includes(run.projectId) || !token.scopes.includes("code:execute") || operation === "read" && !token.scopes.includes("runs:read"));
|
|
@@ -8274,11 +8420,11 @@ function live(run) {
|
|
|
8274
8420
|
}
|
|
8275
8421
|
function actorContext(ctx, run) {
|
|
8276
8422
|
const user = identityRepository(ctx.db).user(run.actorId) ?? null;
|
|
8277
|
-
const workspace2 = ctx.db.select().from(workspaces).where(
|
|
8423
|
+
const workspace2 = ctx.db.select().from(workspaces).where(eq95(workspaces.id, run.workspaceId)).get() ?? null;
|
|
8278
8424
|
const membership = ctx.db.select().from(memberships).where(
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8425
|
+
and72(
|
|
8426
|
+
eq95(memberships.workspaceId, run.workspaceId),
|
|
8427
|
+
eq95(memberships.userId, run.actorId)
|
|
8282
8428
|
)
|
|
8283
8429
|
).get();
|
|
8284
8430
|
if (!user || !workspace2 || !membership) {
|
|
@@ -8295,7 +8441,7 @@ function actorContext(ctx, run) {
|
|
|
8295
8441
|
}
|
|
8296
8442
|
|
|
8297
8443
|
// server/execution/bootstrap.ts
|
|
8298
|
-
import { eq as
|
|
8444
|
+
import { eq as eq96 } from "drizzle-orm";
|
|
8299
8445
|
import { createHmac as createHmac3, randomUUID as randomUUID6 } from "node:crypto";
|
|
8300
8446
|
function bootstrap(ctx) {
|
|
8301
8447
|
const configured = process.env.LOCAL_EXECUTOR_BOOTSTRAP_TOKEN;
|
|
@@ -8303,8 +8449,8 @@ function bootstrap(ctx) {
|
|
|
8303
8449
|
throw new HttpError(403, "Invalid local bootstrap credential.");
|
|
8304
8450
|
}
|
|
8305
8451
|
const registrations = [];
|
|
8306
|
-
for (const project of ctx.db.select().from(projects).where(
|
|
8307
|
-
let worker = ctx.db.select().from(executors).where(
|
|
8452
|
+
for (const project of ctx.db.select().from(projects).where(eq96(projects.enabled, true)).all()) {
|
|
8453
|
+
let worker = ctx.db.select().from(executors).where(eq96(executors.projectId, project.id)).get();
|
|
8308
8454
|
if (worker && (!worker.locallyManaged || !worker.enabled)) {
|
|
8309
8455
|
continue;
|
|
8310
8456
|
}
|
|
@@ -8324,7 +8470,7 @@ function bootstrap(ctx) {
|
|
|
8324
8470
|
}).returning().get();
|
|
8325
8471
|
}
|
|
8326
8472
|
const token = createHmac3("sha256", configured).update(`${worker.id}:${worker.registrationNonce}`).digest("hex");
|
|
8327
|
-
ctx.db.update(executors).set({ tokenHash: digest(token) }).where(
|
|
8473
|
+
ctx.db.update(executors).set({ tokenHash: digest(token) }).where(eq96(executors.id, worker.id)).run();
|
|
8328
8474
|
registrations.push({
|
|
8329
8475
|
agent_id: project.id,
|
|
8330
8476
|
executor_id: worker.id,
|
|
@@ -8335,34 +8481,34 @@ function bootstrap(ctx) {
|
|
|
8335
8481
|
}
|
|
8336
8482
|
|
|
8337
8483
|
// server/execution/claim.ts
|
|
8338
|
-
import { and as
|
|
8484
|
+
import { and as and73, asc as asc7, eq as eq97, inArray as inArray9 } from "drizzle-orm";
|
|
8339
8485
|
function claim(ctx, worker) {
|
|
8340
8486
|
ctx.db.update(executors).set({ lastSeenAt: now() }).where(
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8487
|
+
and73(
|
|
8488
|
+
eq97(executors.id, worker.id),
|
|
8489
|
+
eq97(executors.workspaceId, worker.workspaceId)
|
|
8344
8490
|
)
|
|
8345
8491
|
).run();
|
|
8346
|
-
const setting = ctx.db.select().from(workspaceSettings).where(
|
|
8492
|
+
const setting = ctx.db.select().from(workspaceSettings).where(eq97(workspaceSettings.workspaceId, worker.workspaceId)).get();
|
|
8347
8493
|
if (setting && (!setting.enabled || setting.executionPool !== worker.pool)) {
|
|
8348
8494
|
return new Response(null, { status: 204 });
|
|
8349
8495
|
}
|
|
8350
8496
|
const active = ctx.db.select().from(runs).where(
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8497
|
+
and73(
|
|
8498
|
+
eq97(runs.workspaceId, worker.workspaceId),
|
|
8499
|
+
inArray9(runs.status, ["running", "waiting_approval"])
|
|
8354
8500
|
)
|
|
8355
8501
|
).all();
|
|
8356
8502
|
if (active.some((run) => run.projectId === worker.projectId) || active.length >= (setting?.maxConcurrentRuns ?? 4)) {
|
|
8357
8503
|
return new Response(null, { status: 204 });
|
|
8358
8504
|
}
|
|
8359
8505
|
const candidates = ctx.db.select().from(runs).where(
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8506
|
+
and73(
|
|
8507
|
+
eq97(runs.projectId, worker.projectId),
|
|
8508
|
+
eq97(runs.workspaceId, worker.workspaceId),
|
|
8509
|
+
eq97(runs.status, "queued")
|
|
8364
8510
|
)
|
|
8365
|
-
).orderBy(
|
|
8511
|
+
).orderBy(asc7(runs.createdAt)).all();
|
|
8366
8512
|
for (const run of candidates) {
|
|
8367
8513
|
if (!worker.capabilities.includes(run.operation)) {
|
|
8368
8514
|
continue;
|
|
@@ -8372,18 +8518,18 @@ function claim(ctx, worker) {
|
|
|
8372
8518
|
continue;
|
|
8373
8519
|
}
|
|
8374
8520
|
const member = ctx.db.select().from(memberships).where(
|
|
8375
|
-
|
|
8376
|
-
|
|
8377
|
-
|
|
8521
|
+
and73(
|
|
8522
|
+
eq97(memberships.userId, run.actorId),
|
|
8523
|
+
eq97(memberships.workspaceId, run.workspaceId)
|
|
8378
8524
|
)
|
|
8379
8525
|
).get();
|
|
8380
|
-
const token = run.tokenId ? ctx.db.select().from(accessTokens).where(
|
|
8526
|
+
const token = run.tokenId ? ctx.db.select().from(accessTokens).where(eq97(accessTokens.id, run.tokenId)).get() : null;
|
|
8381
8527
|
if (!member || run.cancelRequested || run.tokenId && (!token || token.revoked)) {
|
|
8382
8528
|
ctx.db.update(runs).set({
|
|
8383
8529
|
status: "cancelled",
|
|
8384
8530
|
cancelRequested: true,
|
|
8385
8531
|
updatedAt: now()
|
|
8386
|
-
}).where(
|
|
8532
|
+
}).where(eq97(runs.id, run.id)).run();
|
|
8387
8533
|
continue;
|
|
8388
8534
|
}
|
|
8389
8535
|
const capability = randomSecret();
|
|
@@ -8395,7 +8541,7 @@ function claim(ctx, worker) {
|
|
|
8395
8541
|
deadline,
|
|
8396
8542
|
leaseExpiresAt: new Date(Date.now() + 6e4).toISOString(),
|
|
8397
8543
|
updatedAt: now()
|
|
8398
|
-
}).where(
|
|
8544
|
+
}).where(eq97(runs.id, run.id)).run();
|
|
8399
8545
|
return json({
|
|
8400
8546
|
protocol_version: protocol,
|
|
8401
8547
|
run_id: run.id,
|
|
@@ -8413,13 +8559,13 @@ function claim(ctx, worker) {
|
|
|
8413
8559
|
}
|
|
8414
8560
|
|
|
8415
8561
|
// server/execution/configuration.ts
|
|
8416
|
-
import { and as
|
|
8562
|
+
import { and as and74, eq as eq98 } from "drizzle-orm";
|
|
8417
8563
|
function pluginsFor(ctx, worker) {
|
|
8418
8564
|
return ctx.db.select().from(plugins).where(
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8565
|
+
and74(
|
|
8566
|
+
eq98(plugins.workspaceId, worker.workspaceId),
|
|
8567
|
+
eq98(plugins.projectId, worker.projectId),
|
|
8568
|
+
eq98(plugins.enabled, true)
|
|
8423
8569
|
)
|
|
8424
8570
|
).all().filter(
|
|
8425
8571
|
(plugin) => plugin.distribution !== "mcp" || worker.protocolVersion >= 4
|
|
@@ -8447,11 +8593,11 @@ function configuration(ctx, worker) {
|
|
|
8447
8593
|
}
|
|
8448
8594
|
|
|
8449
8595
|
// server/execution/credentials.ts
|
|
8450
|
-
import { and as
|
|
8596
|
+
import { and as and77, eq as eq101 } from "drizzle-orm";
|
|
8451
8597
|
|
|
8452
8598
|
// server/mcp/oauth-refresh.ts
|
|
8453
8599
|
import { auth as auth3 } from "@modelcontextprotocol/client";
|
|
8454
|
-
import { and as
|
|
8600
|
+
import { and as and75, eq as eq99 } from "drizzle-orm";
|
|
8455
8601
|
var refreshes = /* @__PURE__ */ new WeakMap();
|
|
8456
8602
|
async function mcpExecutionSecret(ctx, credential) {
|
|
8457
8603
|
let pending = refreshes.get(ctx.db);
|
|
@@ -8473,9 +8619,9 @@ async function mcpExecutionSecret(ctx, credential) {
|
|
|
8473
8619
|
}
|
|
8474
8620
|
async function refresh(ctx, initial) {
|
|
8475
8621
|
const credential = ctx.db.select().from(credentials).where(
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8622
|
+
and75(
|
|
8623
|
+
eq99(credentials.id, initial.id),
|
|
8624
|
+
eq99(credentials.workspaceId, initial.workspaceId)
|
|
8479
8625
|
)
|
|
8480
8626
|
).get();
|
|
8481
8627
|
if (!credential) {
|
|
@@ -8506,9 +8652,9 @@ async function refresh(ctx, initial) {
|
|
|
8506
8652
|
encryptedSecret: encrypt(ctx, JSON.stringify(state)),
|
|
8507
8653
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
8508
8654
|
}).where(
|
|
8509
|
-
|
|
8510
|
-
|
|
8511
|
-
|
|
8655
|
+
and75(
|
|
8656
|
+
eq99(credentials.id, credential.id),
|
|
8657
|
+
eq99(credentials.encryptedSecret, credential.encryptedSecret)
|
|
8512
8658
|
)
|
|
8513
8659
|
).returning().get();
|
|
8514
8660
|
if (!updated) {
|
|
@@ -8532,11 +8678,11 @@ async function refresh(ctx, initial) {
|
|
|
8532
8678
|
}
|
|
8533
8679
|
|
|
8534
8680
|
// server/oauth/refresh.ts
|
|
8535
|
-
import { z as
|
|
8536
|
-
import { and as
|
|
8681
|
+
import { z as z50 } from "zod";
|
|
8682
|
+
import { and as and76, eq as eq100 } from "drizzle-orm";
|
|
8537
8683
|
|
|
8538
8684
|
// server/oauth/tokens.ts
|
|
8539
|
-
import { z as
|
|
8685
|
+
import { z as z49 } from "zod";
|
|
8540
8686
|
async function tokenExchange(providerName, clientId, clientSecret, params, fetcher) {
|
|
8541
8687
|
const fields = new URLSearchParams({ ...params, client_id: clientId });
|
|
8542
8688
|
const headers = new Headers({
|
|
@@ -8577,7 +8723,7 @@ async function tokenExchange(providerName, clientId, clientSecret, params, fetch
|
|
|
8577
8723
|
}
|
|
8578
8724
|
chunks.push(item.value);
|
|
8579
8725
|
}
|
|
8580
|
-
const value =
|
|
8726
|
+
const value = z49.record(z49.string(), z49.unknown()).parse(JSON.parse(Buffer.concat(chunks).toString("utf8")));
|
|
8581
8727
|
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)) {
|
|
8582
8728
|
throw new Error();
|
|
8583
8729
|
}
|
|
@@ -8625,9 +8771,9 @@ function recordSecretVersion(secret, credential) {
|
|
|
8625
8771
|
function assertExecutionSecretCurrent(store, credential, secret) {
|
|
8626
8772
|
const version = secretVersions.get(secret);
|
|
8627
8773
|
const current = store.db.select().from(credentials).where(
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8774
|
+
and76(
|
|
8775
|
+
eq100(credentials.id, credential.id),
|
|
8776
|
+
eq100(credentials.workspaceId, credential.workspaceId)
|
|
8631
8777
|
)
|
|
8632
8778
|
).get();
|
|
8633
8779
|
if (!version || !current || version.id !== current.id || version.workspaceId !== current.workspaceId || version.provider !== current.provider || version.encryptedSecret !== current.encryptedSecret) {
|
|
@@ -8643,7 +8789,7 @@ async function executionSecret(store, credential, fetcher = fetch) {
|
|
|
8643
8789
|
}
|
|
8644
8790
|
if (!provider(credential.provider)) {
|
|
8645
8791
|
return recordSecretVersion(
|
|
8646
|
-
|
|
8792
|
+
z50.record(z50.string(), z50.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret))),
|
|
8647
8793
|
credential
|
|
8648
8794
|
);
|
|
8649
8795
|
}
|
|
@@ -8669,15 +8815,15 @@ async function executionSecret(store, credential, fetcher = fetch) {
|
|
|
8669
8815
|
}
|
|
8670
8816
|
async function resolveExecutionSecret(store, initial, fetcher) {
|
|
8671
8817
|
const credential = store.db.select().from(credentials).where(
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8818
|
+
and76(
|
|
8819
|
+
eq100(credentials.id, initial.id),
|
|
8820
|
+
eq100(credentials.workspaceId, initial.workspaceId)
|
|
8675
8821
|
)
|
|
8676
8822
|
).get();
|
|
8677
8823
|
if (!credential || !provider(credential.provider)) {
|
|
8678
8824
|
throw new ServiceError("BAD_REQUEST", "Reconnect this credential.");
|
|
8679
8825
|
}
|
|
8680
|
-
const payload =
|
|
8826
|
+
const payload = z50.record(z50.string(), z50.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret)));
|
|
8681
8827
|
if (credential.provider === "xero-oauth" && Object.keys(payload).length === 1 && typeof payload.secret_accessToken === "string" && payload.secret_accessToken) {
|
|
8682
8828
|
return recordSecretVersion(
|
|
8683
8829
|
{ secret_accessToken: payload.secret_accessToken },
|
|
@@ -8713,9 +8859,9 @@ async function resolveExecutionSecret(store, initial, fetcher) {
|
|
|
8713
8859
|
JSON.stringify(applyTokens(payload, tokens2))
|
|
8714
8860
|
);
|
|
8715
8861
|
const result = store.db.update(credentials).set({ encryptedSecret: updated, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8862
|
+
and76(
|
|
8863
|
+
eq100(credentials.id, credential.id),
|
|
8864
|
+
eq100(credentials.encryptedSecret, credential.encryptedSecret)
|
|
8719
8865
|
)
|
|
8720
8866
|
).returning().get();
|
|
8721
8867
|
if (!result) {
|
|
@@ -8747,9 +8893,9 @@ async function serveCredential(ctx, credentialId) {
|
|
|
8747
8893
|
throw new HttpError(403, "Credential is outside this run capability.");
|
|
8748
8894
|
}
|
|
8749
8895
|
const credential2 = ctx.db.select().from(credentials).where(
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
|
|
8896
|
+
and77(
|
|
8897
|
+
eq101(credentials.id, credentialId),
|
|
8898
|
+
eq101(credentials.workspaceId, run.workspaceId)
|
|
8753
8899
|
)
|
|
8754
8900
|
).get();
|
|
8755
8901
|
if (!credential2) {
|
|
@@ -8776,11 +8922,164 @@ async function serveCredential(ctx, credentialId) {
|
|
|
8776
8922
|
});
|
|
8777
8923
|
}
|
|
8778
8924
|
|
|
8925
|
+
// server/execution/shell-policy.ts
|
|
8926
|
+
import { and as and78, asc as asc8, eq as eq103 } from "drizzle-orm";
|
|
8927
|
+
import { z as z52 } from "zod";
|
|
8928
|
+
|
|
8929
|
+
// server/execution/redaction.ts
|
|
8930
|
+
import { z as z51 } from "zod";
|
|
8931
|
+
import { eq as eq102 } from "drizzle-orm";
|
|
8932
|
+
function redact(ctx, workspaceId, value) {
|
|
8933
|
+
const secrets = [];
|
|
8934
|
+
const collect = (entry) => {
|
|
8935
|
+
if (typeof entry === "string" && entry) {
|
|
8936
|
+
secrets.push(entry);
|
|
8937
|
+
} else if (Array.isArray(entry)) {
|
|
8938
|
+
entry.forEach(collect);
|
|
8939
|
+
} else if (entry && typeof entry === "object") {
|
|
8940
|
+
Object.values(entry).forEach(collect);
|
|
8941
|
+
}
|
|
8942
|
+
};
|
|
8943
|
+
for (const credential of ctx.db.select().from(credentials).where(eq102(credentials.workspaceId, workspaceId)).all()) {
|
|
8944
|
+
collect(JSON.parse(decrypt(ctx, credential.encryptedSecret)));
|
|
8945
|
+
}
|
|
8946
|
+
secrets.sort((a, b) => b.length - a.length);
|
|
8947
|
+
const mask = (entry) => {
|
|
8948
|
+
if (typeof entry === "string") {
|
|
8949
|
+
return secrets.reduce(
|
|
8950
|
+
(text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
|
|
8951
|
+
entry
|
|
8952
|
+
);
|
|
8953
|
+
}
|
|
8954
|
+
if (Array.isArray(entry)) {
|
|
8955
|
+
return entry.map(mask);
|
|
8956
|
+
}
|
|
8957
|
+
if (entry && typeof entry === "object") {
|
|
8958
|
+
return Object.fromEntries(
|
|
8959
|
+
Object.entries(entry).map(([key, child]) => [
|
|
8960
|
+
typeof key === "string" ? secrets.reduce(
|
|
8961
|
+
(text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
|
|
8962
|
+
key
|
|
8963
|
+
) : key,
|
|
8964
|
+
mask(child)
|
|
8965
|
+
])
|
|
8966
|
+
);
|
|
8967
|
+
}
|
|
8968
|
+
return entry;
|
|
8969
|
+
};
|
|
8970
|
+
return mask(z51.json().parse(value));
|
|
8971
|
+
}
|
|
8972
|
+
function bounded(value, limit = 2e5) {
|
|
8973
|
+
if (Buffer.byteLength(JSON.stringify(value)) > limit) {
|
|
8974
|
+
throw new HttpError(400, "Data exceeds the response limit.");
|
|
8975
|
+
}
|
|
8976
|
+
return value;
|
|
8977
|
+
}
|
|
8978
|
+
|
|
8979
|
+
// server/execution/shell-policy.ts
|
|
8980
|
+
var invocation = z52.strictObject({
|
|
8981
|
+
executable: executableName,
|
|
8982
|
+
args: z52.array(
|
|
8983
|
+
z52.string().max(4096).refine((arg) => !arg.includes("\0"))
|
|
8984
|
+
).max(64)
|
|
8985
|
+
});
|
|
8986
|
+
function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
|
|
8987
|
+
const plugin = ctx.db.select().from(plugins).where(
|
|
8988
|
+
and78(
|
|
8989
|
+
eq103(plugins.id, pluginId),
|
|
8990
|
+
eq103(plugins.projectId, run.projectId),
|
|
8991
|
+
eq103(plugins.workspaceId, run.workspaceId),
|
|
8992
|
+
eq103(plugins.enabled, true)
|
|
8993
|
+
)
|
|
8994
|
+
).get();
|
|
8995
|
+
const agent = snapshotAgents(run.snapshot).find(
|
|
8996
|
+
(agent2) => agent2.id === run.projectId
|
|
8997
|
+
);
|
|
8998
|
+
if (!plugin || !supportsShellPolicy(plugin) || !agent?.plugins.some(
|
|
8999
|
+
(slot) => slot.shell_policy_id === plugin.id && slot.digest === plugin.digest
|
|
9000
|
+
)) {
|
|
9001
|
+
throw new HttpError(
|
|
9002
|
+
403,
|
|
9003
|
+
"Shell is outside this run's active plugin grants."
|
|
9004
|
+
);
|
|
9005
|
+
}
|
|
9006
|
+
if (!approvalId && method === "GET") {
|
|
9007
|
+
return json(
|
|
9008
|
+
ctx.db.select({ name: shellRules.executable }).from(shellRules).where(
|
|
9009
|
+
and78(
|
|
9010
|
+
eq103(shellRules.pluginId, pluginId),
|
|
9011
|
+
eq103(shellRules.decision, "allow")
|
|
9012
|
+
)
|
|
9013
|
+
).orderBy(asc8(shellRules.executable)).all().map((rule2) => rule2.name)
|
|
9014
|
+
);
|
|
9015
|
+
}
|
|
9016
|
+
if (approvalId && method === "GET") {
|
|
9017
|
+
const row2 = ctx.db.select().from(approvals).where(
|
|
9018
|
+
and78(
|
|
9019
|
+
eq103(approvals.id, approvalId),
|
|
9020
|
+
eq103(approvals.workspaceId, run.workspaceId),
|
|
9021
|
+
eq103(approvals.runId, run.id)
|
|
9022
|
+
)
|
|
9023
|
+
).get();
|
|
9024
|
+
if (row2?.shell?.pluginId !== plugin.id || row2.shell.digest !== plugin.digest) {
|
|
9025
|
+
throw new HttpError(404, "Shell approval not found.");
|
|
9026
|
+
}
|
|
9027
|
+
const blocked = ctx.db.select().from(shellRules).where(
|
|
9028
|
+
and78(
|
|
9029
|
+
eq103(shellRules.pluginId, pluginId),
|
|
9030
|
+
eq103(shellRules.executable, row2.shell.executable),
|
|
9031
|
+
eq103(shellRules.decision, "block")
|
|
9032
|
+
)
|
|
9033
|
+
).get();
|
|
9034
|
+
return json({
|
|
9035
|
+
id: row2.id,
|
|
9036
|
+
status: blocked && row2.status === "approved" ? "denied" : row2.status
|
|
9037
|
+
});
|
|
9038
|
+
}
|
|
9039
|
+
if (approvalId || method !== "POST") {
|
|
9040
|
+
throw new HttpError(405, "Method not allowed.");
|
|
9041
|
+
}
|
|
9042
|
+
const parsed = invocation.safeParse(body);
|
|
9043
|
+
if (!parsed.success) {
|
|
9044
|
+
throw new HttpError(400, "Invalid Shell executable or arguments.");
|
|
9045
|
+
}
|
|
9046
|
+
const { executable, args } = parsed.data;
|
|
9047
|
+
const rule = ctx.db.select().from(shellRules).where(
|
|
9048
|
+
and78(
|
|
9049
|
+
eq103(shellRules.pluginId, pluginId),
|
|
9050
|
+
eq103(shellRules.executable, executable)
|
|
9051
|
+
)
|
|
9052
|
+
).get();
|
|
9053
|
+
if (rule) {
|
|
9054
|
+
return json({ status: rule.decision === "allow" ? "approved" : "denied" });
|
|
9055
|
+
}
|
|
9056
|
+
const argv = JSON.stringify(
|
|
9057
|
+
redact(ctx, run.workspaceId, [executable, ...args])
|
|
9058
|
+
).replace(
|
|
9059
|
+
/[\u200b-\u200f\u2028-\u202e\u2060-\u206f]/gu,
|
|
9060
|
+
(character) => "\\u" + character.charCodeAt(0).toString(16).padStart(4, "0")
|
|
9061
|
+
);
|
|
9062
|
+
const row = ctx.db.insert(approvals).values({
|
|
9063
|
+
...base(run.workspaceId),
|
|
9064
|
+
runId: run.id,
|
|
9065
|
+
prompt: argv,
|
|
9066
|
+
shell: {
|
|
9067
|
+
pluginId,
|
|
9068
|
+
projectId: run.projectId,
|
|
9069
|
+
digest: plugin.digest,
|
|
9070
|
+
executable
|
|
9071
|
+
},
|
|
9072
|
+
status: "pending"
|
|
9073
|
+
}).returning().get();
|
|
9074
|
+
ctx.db.update(runs).set({ status: "waiting_approval", updatedAt: now() }).where(eq103(runs.id, run.id)).run();
|
|
9075
|
+
return json({ id: row.id, status: row.status }, 201);
|
|
9076
|
+
}
|
|
9077
|
+
|
|
8779
9078
|
// server/execution/product.ts
|
|
8780
|
-
import { and as
|
|
9079
|
+
import { and as and81, eq as eq106 } from "drizzle-orm";
|
|
8781
9080
|
|
|
8782
9081
|
// server/execution/project-data.ts
|
|
8783
|
-
import { and as
|
|
9082
|
+
import { and as and80, asc as asc9, eq as eq105, inArray as inArray10 } from "drizzle-orm";
|
|
8784
9083
|
|
|
8785
9084
|
// server/execution/data-pagination.ts
|
|
8786
9085
|
function paginateData(items, offset, limit) {
|
|
@@ -8807,106 +9106,56 @@ function paginateData(items, offset, limit) {
|
|
|
8807
9106
|
}
|
|
8808
9107
|
|
|
8809
9108
|
// server/execution/data-schemas.ts
|
|
8810
|
-
import { z as
|
|
9109
|
+
import { z as z53 } from "zod";
|
|
8811
9110
|
var pagination = {
|
|
8812
|
-
offset:
|
|
8813
|
-
limit:
|
|
9111
|
+
offset: z53.number().int().min(0).max(1e6).default(0),
|
|
9112
|
+
limit: z53.number().int().min(1).max(100).default(100)
|
|
8814
9113
|
};
|
|
8815
|
-
var tableId = { table_id:
|
|
8816
|
-
var revision2 =
|
|
8817
|
-
var content =
|
|
9114
|
+
var tableId = { table_id: z53.string().uuid() };
|
|
9115
|
+
var revision2 = z53.number().int().positive();
|
|
9116
|
+
var content = z53.string().refine(
|
|
8818
9117
|
(value) => !value.includes("\0") && Buffer.byteLength(value) <= 2e5
|
|
8819
9118
|
);
|
|
8820
|
-
var dataOperationSchema =
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
operation:
|
|
9119
|
+
var dataOperationSchema = z53.discriminatedUnion("operation", [
|
|
9120
|
+
z53.strictObject({ operation: z53.literal("list_tables"), ...pagination }),
|
|
9121
|
+
z53.strictObject({ operation: z53.literal("get_table"), ...tableId }),
|
|
9122
|
+
z53.strictObject({
|
|
9123
|
+
operation: z53.literal("list_rows"),
|
|
8825
9124
|
...tableId,
|
|
8826
9125
|
...pagination
|
|
8827
9126
|
}),
|
|
8828
|
-
|
|
8829
|
-
operation:
|
|
9127
|
+
z53.strictObject({
|
|
9128
|
+
operation: z53.literal("write_row"),
|
|
8830
9129
|
...tableId,
|
|
8831
9130
|
table_revision: revision2,
|
|
8832
|
-
values:
|
|
8833
|
-
row_id:
|
|
9131
|
+
values: z53.record(z53.string(), z53.json()),
|
|
9132
|
+
row_id: z53.string().uuid().optional(),
|
|
8834
9133
|
revision: revision2.optional()
|
|
8835
9134
|
}).refine(
|
|
8836
9135
|
(input2) => input2.row_id === void 0 === (input2.revision === void 0),
|
|
8837
9136
|
"Row updates require both row ID and revision."
|
|
8838
9137
|
),
|
|
8839
|
-
|
|
8840
|
-
operation:
|
|
9138
|
+
z53.strictObject({
|
|
9139
|
+
operation: z53.literal("delete_row"),
|
|
8841
9140
|
...tableId,
|
|
8842
|
-
row_id:
|
|
9141
|
+
row_id: z53.string().uuid(),
|
|
8843
9142
|
revision: revision2
|
|
8844
9143
|
}),
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
operation:
|
|
8848
|
-
document_id:
|
|
9144
|
+
z53.strictObject({ operation: z53.literal("list_documents"), ...pagination }),
|
|
9145
|
+
z53.strictObject({
|
|
9146
|
+
operation: z53.literal("get_document"),
|
|
9147
|
+
document_id: z53.string().uuid()
|
|
8849
9148
|
}),
|
|
8850
|
-
|
|
8851
|
-
operation:
|
|
8852
|
-
document_id:
|
|
8853
|
-
title:
|
|
9149
|
+
z53.strictObject({
|
|
9150
|
+
operation: z53.literal("write_document"),
|
|
9151
|
+
document_id: z53.string().uuid(),
|
|
9152
|
+
title: z53.string().trim().min(1).max(200).refine((value) => !value.includes("\0")).optional(),
|
|
8854
9153
|
content: content.optional()
|
|
8855
9154
|
})
|
|
8856
9155
|
]);
|
|
8857
9156
|
|
|
8858
|
-
// server/execution/redaction.ts
|
|
8859
|
-
import { z as z49 } from "zod";
|
|
8860
|
-
import { eq as eq99 } from "drizzle-orm";
|
|
8861
|
-
function redact(ctx, workspaceId, value) {
|
|
8862
|
-
const secrets = [];
|
|
8863
|
-
const collect = (entry) => {
|
|
8864
|
-
if (typeof entry === "string" && entry) {
|
|
8865
|
-
secrets.push(entry);
|
|
8866
|
-
} else if (Array.isArray(entry)) {
|
|
8867
|
-
entry.forEach(collect);
|
|
8868
|
-
} else if (entry && typeof entry === "object") {
|
|
8869
|
-
Object.values(entry).forEach(collect);
|
|
8870
|
-
}
|
|
8871
|
-
};
|
|
8872
|
-
for (const credential of ctx.db.select().from(credentials).where(eq99(credentials.workspaceId, workspaceId)).all()) {
|
|
8873
|
-
collect(JSON.parse(decrypt(ctx, credential.encryptedSecret)));
|
|
8874
|
-
}
|
|
8875
|
-
secrets.sort((a, b) => b.length - a.length);
|
|
8876
|
-
const mask = (entry) => {
|
|
8877
|
-
if (typeof entry === "string") {
|
|
8878
|
-
return secrets.reduce(
|
|
8879
|
-
(text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
|
|
8880
|
-
entry
|
|
8881
|
-
);
|
|
8882
|
-
}
|
|
8883
|
-
if (Array.isArray(entry)) {
|
|
8884
|
-
return entry.map(mask);
|
|
8885
|
-
}
|
|
8886
|
-
if (entry && typeof entry === "object") {
|
|
8887
|
-
return Object.fromEntries(
|
|
8888
|
-
Object.entries(entry).map(([key, child]) => [
|
|
8889
|
-
typeof key === "string" ? secrets.reduce(
|
|
8890
|
-
(text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
|
|
8891
|
-
key
|
|
8892
|
-
) : key,
|
|
8893
|
-
mask(child)
|
|
8894
|
-
])
|
|
8895
|
-
);
|
|
8896
|
-
}
|
|
8897
|
-
return entry;
|
|
8898
|
-
};
|
|
8899
|
-
return mask(z49.json().parse(value));
|
|
8900
|
-
}
|
|
8901
|
-
function bounded(value, limit = 2e5) {
|
|
8902
|
-
if (Buffer.byteLength(JSON.stringify(value)) > limit) {
|
|
8903
|
-
throw new HttpError(400, "Data exceeds the response limit.");
|
|
8904
|
-
}
|
|
8905
|
-
return value;
|
|
8906
|
-
}
|
|
8907
|
-
|
|
8908
9157
|
// server/execution/run-grants.ts
|
|
8909
|
-
import { and as
|
|
9158
|
+
import { and as and79, eq as eq104 } from "drizzle-orm";
|
|
8910
9159
|
function grantIds(context, run, kind, write = false) {
|
|
8911
9160
|
const root2 = snapshotAgents(run.snapshot).find(
|
|
8912
9161
|
(agent) => agent.id === run.projectId
|
|
@@ -8917,9 +9166,9 @@ function grantIds(context, run, kind, write = false) {
|
|
|
8917
9166
|
...write ? [] : grants2?.read ?? []
|
|
8918
9167
|
];
|
|
8919
9168
|
const project = context.db.select().from(projects).where(
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
9169
|
+
and79(
|
|
9170
|
+
eq104(projects.id, run.projectId),
|
|
9171
|
+
eq104(projects.workspaceId, run.workspaceId)
|
|
8923
9172
|
)
|
|
8924
9173
|
).get();
|
|
8925
9174
|
if (!project) {
|
|
@@ -8945,11 +9194,11 @@ function projectData(context, run, body) {
|
|
|
8945
9194
|
const documentOperation = input2.operation === "list_documents" || input2.operation === "get_document" || input2.operation === "write_document";
|
|
8946
9195
|
if (documentOperation) {
|
|
8947
9196
|
const accessibleDocuments = context.db.select().from(documents).where(
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
9197
|
+
and80(
|
|
9198
|
+
eq105(documents.workspaceId, run.workspaceId),
|
|
9199
|
+
inArray10(documents.id, grantIds(context, run, "documents"))
|
|
8951
9200
|
)
|
|
8952
|
-
).orderBy(
|
|
9201
|
+
).orderBy(asc9(documents.id)).all();
|
|
8953
9202
|
if (input2.operation === "list_documents") {
|
|
8954
9203
|
return paginateData(
|
|
8955
9204
|
accessibleDocuments.map(documentView2),
|
|
@@ -8974,9 +9223,9 @@ function projectData(context, run, body) {
|
|
|
8974
9223
|
content: input2.content ?? document.content,
|
|
8975
9224
|
updatedAt: now()
|
|
8976
9225
|
}).where(
|
|
8977
|
-
|
|
8978
|
-
|
|
8979
|
-
|
|
9226
|
+
and80(
|
|
9227
|
+
eq105(documents.id, document.id),
|
|
9228
|
+
eq105(documents.workspaceId, run.workspaceId)
|
|
8980
9229
|
)
|
|
8981
9230
|
).returning().get();
|
|
8982
9231
|
if (!updated) {
|
|
@@ -8985,11 +9234,11 @@ function projectData(context, run, body) {
|
|
|
8985
9234
|
return bounded(documentView2(updated));
|
|
8986
9235
|
}
|
|
8987
9236
|
const tables = context.db.select().from(workspaceTables).where(
|
|
8988
|
-
|
|
8989
|
-
|
|
8990
|
-
|
|
9237
|
+
and80(
|
|
9238
|
+
eq105(workspaceTables.workspaceId, run.workspaceId),
|
|
9239
|
+
inArray10(workspaceTables.id, grantIds(context, run, "tables"))
|
|
8991
9240
|
)
|
|
8992
|
-
).orderBy(
|
|
9241
|
+
).orderBy(asc9(workspaceTables.id)).all();
|
|
8993
9242
|
if (input2.operation === "list_tables") {
|
|
8994
9243
|
return paginateData(tables.map(standard), input2.offset, input2.limit);
|
|
8995
9244
|
}
|
|
@@ -9003,15 +9252,15 @@ function projectData(context, run, body) {
|
|
|
9003
9252
|
if (input2.operation !== "list_rows" && !grantIds(context, run, "tables", true).includes(table.id)) {
|
|
9004
9253
|
throw new HttpError(403, "Resource is read only.");
|
|
9005
9254
|
}
|
|
9006
|
-
const matchesTable =
|
|
9007
|
-
|
|
9008
|
-
|
|
9255
|
+
const matchesTable = and80(
|
|
9256
|
+
eq105(tableRows.workspaceId, run.workspaceId),
|
|
9257
|
+
eq105(tableRows.tableId, table.id)
|
|
9009
9258
|
);
|
|
9010
9259
|
if (input2.operation === "list_rows") {
|
|
9011
|
-
const rows = context.db.select().from(tableRows).where(matchesTable).orderBy(
|
|
9260
|
+
const rows = context.db.select().from(tableRows).where(matchesTable).orderBy(asc9(tableRows.id)).all();
|
|
9012
9261
|
return paginateData(rows.map(rowView), input2.offset, input2.limit);
|
|
9013
9262
|
}
|
|
9014
|
-
const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(
|
|
9263
|
+
const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(and80(matchesTable, eq105(tableRows.id, input2.row_id))).get();
|
|
9015
9264
|
if (input2.row_id !== void 0 && !row) {
|
|
9016
9265
|
throw new HttpError(404, "Row not found.");
|
|
9017
9266
|
}
|
|
@@ -9019,7 +9268,7 @@ function projectData(context, run, body) {
|
|
|
9019
9268
|
throw new HttpError(409, "Row changed. Reload before saving.");
|
|
9020
9269
|
}
|
|
9021
9270
|
if (input2.operation === "delete_row") {
|
|
9022
|
-
context.db.delete(tableRows).where(
|
|
9271
|
+
context.db.delete(tableRows).where(and80(matchesTable, eq105(tableRows.id, input2.row_id))).run();
|
|
9023
9272
|
return { deleted: true };
|
|
9024
9273
|
}
|
|
9025
9274
|
if (table.revision !== input2.table_revision) {
|
|
@@ -9031,7 +9280,7 @@ function projectData(context, run, body) {
|
|
|
9031
9280
|
values: input2.values,
|
|
9032
9281
|
revision: row.revision + 1,
|
|
9033
9282
|
updatedAt: now()
|
|
9034
|
-
}).where(
|
|
9283
|
+
}).where(and80(matchesTable, eq105(tableRows.id, row.id))).returning().get();
|
|
9035
9284
|
if (!updated) {
|
|
9036
9285
|
throw new HttpError(404, "Row not found.");
|
|
9037
9286
|
}
|
|
@@ -9048,6 +9297,10 @@ function projectData(context, run, body) {
|
|
|
9048
9297
|
|
|
9049
9298
|
// server/execution/product.ts
|
|
9050
9299
|
function handleProduct(ctx, run, route, method, body) {
|
|
9300
|
+
const shell = route.match(/^product\/shell\/([^/]+)\/(?:([^/]+)\/)?$/);
|
|
9301
|
+
if (shell?.[1]) {
|
|
9302
|
+
return shellPolicyRequest(ctx, run, shell[1], shell[2], method, body);
|
|
9303
|
+
}
|
|
9051
9304
|
if (route === "product/project-data/" && method === "POST") {
|
|
9052
9305
|
return json(projectData(ctx, run, body));
|
|
9053
9306
|
}
|
|
@@ -9071,7 +9324,7 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9071
9324
|
}
|
|
9072
9325
|
if (method === "GET") {
|
|
9073
9326
|
const items = ctx.db.select().from(table).where(
|
|
9074
|
-
|
|
9327
|
+
and81(eq106(table.workspaceId, run.workspaceId), eq106(table.runId, run.id))
|
|
9075
9328
|
).all();
|
|
9076
9329
|
const view = (entry) => "prompt" in entry ? {
|
|
9077
9330
|
id: entry.id,
|
|
@@ -9110,7 +9363,7 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9110
9363
|
status: "pending",
|
|
9111
9364
|
decidedBy: null
|
|
9112
9365
|
}).returning().get();
|
|
9113
|
-
ctx.db.update(runs).set({ status: "waiting_approval" }).where(
|
|
9366
|
+
ctx.db.update(runs).set({ status: "waiting_approval" }).where(eq106(runs.id, run.id)).run();
|
|
9114
9367
|
return json(
|
|
9115
9368
|
{
|
|
9116
9369
|
id: approval.id,
|
|
@@ -9148,7 +9401,7 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9148
9401
|
}
|
|
9149
9402
|
|
|
9150
9403
|
// server/execution/register.ts
|
|
9151
|
-
import { eq as
|
|
9404
|
+
import { eq as eq107 } from "drizzle-orm";
|
|
9152
9405
|
function register(ctx, worker, body) {
|
|
9153
9406
|
const version = body.protocol_version;
|
|
9154
9407
|
const capabilities = body.capabilities;
|
|
@@ -9172,20 +9425,20 @@ function register(ctx, worker, body) {
|
|
|
9172
9425
|
capabilities: validatedCapabilities,
|
|
9173
9426
|
lastSeenAt: now(),
|
|
9174
9427
|
updatedAt: now()
|
|
9175
|
-
}).where(
|
|
9428
|
+
}).where(eq107(executors.id, worker.id)).returning().get();
|
|
9176
9429
|
return json(configuration(ctx, registered));
|
|
9177
9430
|
}
|
|
9178
9431
|
|
|
9179
9432
|
// server/execution/run-update.ts
|
|
9180
|
-
import { and as
|
|
9433
|
+
import { and as and82, eq as eq108 } from "drizzle-orm";
|
|
9181
9434
|
function handleRunUpdate(ctx, run, action, body) {
|
|
9182
9435
|
if (action === "heartbeat") {
|
|
9183
9436
|
if (!terminal.has(run.status)) {
|
|
9184
9437
|
if (run.executorId) {
|
|
9185
9438
|
ctx.db.update(executors).set({ lastSeenAt: now() }).where(
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9439
|
+
and82(
|
|
9440
|
+
eq108(executors.id, run.executorId),
|
|
9441
|
+
eq108(executors.workspaceId, run.workspaceId)
|
|
9189
9442
|
)
|
|
9190
9443
|
).run();
|
|
9191
9444
|
}
|
|
@@ -9194,7 +9447,7 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9194
9447
|
leaseExpiresAt: new Date(
|
|
9195
9448
|
Math.min(Date.now() + 6e4, Date.parse(run.deadline))
|
|
9196
9449
|
).toISOString()
|
|
9197
|
-
}).where(
|
|
9450
|
+
}).where(eq108(runs.id, run.id)).run();
|
|
9198
9451
|
}
|
|
9199
9452
|
return json({
|
|
9200
9453
|
status: run.status,
|
|
@@ -9212,9 +9465,9 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9212
9465
|
"Event data"
|
|
9213
9466
|
);
|
|
9214
9467
|
const existing = ctx.db.select().from(runEvents).where(
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9468
|
+
and82(
|
|
9469
|
+
eq108(runEvents.runId, run.id),
|
|
9470
|
+
eq108(runEvents.sequence, body.sequence)
|
|
9218
9471
|
)
|
|
9219
9472
|
).get();
|
|
9220
9473
|
if (existing && (existing.kind !== body.kind || JSON.stringify(existing.data) !== JSON.stringify(data))) {
|
|
@@ -9268,13 +9521,13 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9268
9521
|
);
|
|
9269
9522
|
}
|
|
9270
9523
|
const pending = ctx.db.select().from(approvals).where(
|
|
9271
|
-
|
|
9524
|
+
and82(eq108(approvals.runId, run.id), eq108(approvals.status, "pending"))
|
|
9272
9525
|
).all();
|
|
9273
9526
|
if (pending.length && status === "succeeded") {
|
|
9274
9527
|
throw new HttpError(400, "Resolve pending approvals before completing.");
|
|
9275
9528
|
}
|
|
9276
9529
|
ctx.db.update(approvals).set({ status: "interrupted" }).where(
|
|
9277
|
-
|
|
9530
|
+
and82(eq108(approvals.runId, run.id), eq108(approvals.status, "pending"))
|
|
9278
9531
|
).run();
|
|
9279
9532
|
ctx.db.update(runs).set({
|
|
9280
9533
|
status,
|
|
@@ -9282,7 +9535,7 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9282
9535
|
error,
|
|
9283
9536
|
cancelRequested: run.cancelRequested,
|
|
9284
9537
|
updatedAt: now()
|
|
9285
|
-
}).where(
|
|
9538
|
+
}).where(eq108(runs.id, run.id)).run();
|
|
9286
9539
|
return new Response(null, { status: 204 });
|
|
9287
9540
|
}
|
|
9288
9541
|
|
|
@@ -9332,7 +9585,7 @@ function handleWorker(ctx, route, method, body) {
|
|
|
9332
9585
|
}
|
|
9333
9586
|
|
|
9334
9587
|
// server/oauth/callback.ts
|
|
9335
|
-
import { and as
|
|
9588
|
+
import { and as and83, eq as eq109 } from "drizzle-orm";
|
|
9336
9589
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
9337
9590
|
async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
9338
9591
|
const workspace2 = authorize(ctx);
|
|
@@ -9346,14 +9599,14 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
|
9346
9599
|
const state = field(input2.state, 500);
|
|
9347
9600
|
const code = field(input2.code, 4e3);
|
|
9348
9601
|
const attempt = inTransaction(ctx, (ctx2) => {
|
|
9349
|
-
const record = ctx2.db.select().from(oauthAttempts).where(
|
|
9602
|
+
const record = ctx2.db.select().from(oauthAttempts).where(eq109(oauthAttempts.stateDigest, digest(state))).get();
|
|
9350
9603
|
if (!record || record.userId !== user.id || record.workspaceId !== workspace2.id || record.sessionId !== ctx2.sessionId || record.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
|
|
9351
9604
|
throw new ServiceError(
|
|
9352
9605
|
"BAD_REQUEST",
|
|
9353
9606
|
"This connection request has expired or belongs to another session."
|
|
9354
9607
|
);
|
|
9355
9608
|
}
|
|
9356
|
-
ctx2.db.delete(oauthAttempts).where(
|
|
9609
|
+
ctx2.db.delete(oauthAttempts).where(eq109(oauthAttempts.stateDigest, record.stateDigest)).run();
|
|
9357
9610
|
return record;
|
|
9358
9611
|
});
|
|
9359
9612
|
const payload = JSON.parse(decrypt(ctx, attempt.encryptedPayload));
|
|
@@ -9378,9 +9631,9 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
|
9378
9631
|
inTransaction(ctx, (ctx2) => {
|
|
9379
9632
|
const session = identityRepository(ctx2.db).session(ctx2.sessionId);
|
|
9380
9633
|
const plugin = ctx2.db.select().from(plugins).where(
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9634
|
+
and83(
|
|
9635
|
+
eq109(plugins.id, attempt.pluginId),
|
|
9636
|
+
eq109(plugins.workspaceId, workspace2.id)
|
|
9384
9637
|
)
|
|
9385
9638
|
).get();
|
|
9386
9639
|
if (!session || session.userId !== user.id || session.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
|
|
@@ -9422,7 +9675,7 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
|
9422
9675
|
createdAt: timestamp,
|
|
9423
9676
|
updatedAt: timestamp
|
|
9424
9677
|
}).run();
|
|
9425
|
-
ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(
|
|
9678
|
+
ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(eq109(plugins.id, plugin.id)).run();
|
|
9426
9679
|
ctx2.db.insert(auditRecords).values({
|
|
9427
9680
|
id: randomUUID7(),
|
|
9428
9681
|
workspaceId: workspace2.id,
|
|
@@ -9480,22 +9733,22 @@ function publicRequest(request) {
|
|
|
9480
9733
|
}
|
|
9481
9734
|
|
|
9482
9735
|
// server/repositories/token-activity.ts
|
|
9483
|
-
import { and as
|
|
9736
|
+
import { and as and84, eq as eq110, sql as sql4 } from "drizzle-orm";
|
|
9484
9737
|
function recordTokenActivity(store, token, status, isMcp, hasFailed) {
|
|
9485
9738
|
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
9486
9739
|
store.db.update(accessTokens).set({
|
|
9487
9740
|
firstUsedAt: token.firstUsedAt ?? time,
|
|
9488
9741
|
lastUsedAt: time,
|
|
9489
|
-
requestCount:
|
|
9490
|
-
...hasFailed ? { errorCount:
|
|
9491
|
-
...isMcp ? { mcpRequestCount:
|
|
9742
|
+
requestCount: sql4`${accessTokens.requestCount} + 1`,
|
|
9743
|
+
...hasFailed ? { errorCount: sql4`${accessTokens.errorCount} + 1` } : { successCount: sql4`${accessTokens.successCount} + 1` },
|
|
9744
|
+
...isMcp ? { mcpRequestCount: sql4`${accessTokens.mcpRequestCount} + 1` } : { trpcRequestCount: sql4`${accessTokens.trpcRequestCount} + 1` },
|
|
9492
9745
|
lastTransport: isMcp ? "mcp" : "trpc",
|
|
9493
9746
|
lastOutcome: hasFailed ? "error" : "success",
|
|
9494
9747
|
lastStatusCode: status
|
|
9495
9748
|
}).where(
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9749
|
+
and84(
|
|
9750
|
+
eq110(accessTokens.id, token.id),
|
|
9751
|
+
eq110(accessTokens.workspaceId, token.workspaceId)
|
|
9499
9752
|
)
|
|
9500
9753
|
).run();
|
|
9501
9754
|
}
|
|
@@ -9770,7 +10023,7 @@ function createApp(dependencies) {
|
|
|
9770
10023
|
}
|
|
9771
10024
|
|
|
9772
10025
|
// server/cli/accounts.ts
|
|
9773
|
-
import { eq as
|
|
10026
|
+
import { eq as eq111, or as or6 } from "drizzle-orm";
|
|
9774
10027
|
import { createInterface } from "node:readline/promises";
|
|
9775
10028
|
import { Writable } from "node:stream";
|
|
9776
10029
|
async function resetPassword(store, email) {
|
|
@@ -9811,9 +10064,9 @@ async function resetPassword(store, email) {
|
|
|
9811
10064
|
}
|
|
9812
10065
|
const passwordHash = await password.hash(password2);
|
|
9813
10066
|
inTransaction(store, (store2) => {
|
|
9814
|
-
store2.db.update(users).set({ passwordHash }).where(
|
|
10067
|
+
store2.db.update(users).set({ passwordHash }).where(eq111(users.id, user.id)).run();
|
|
9815
10068
|
store2.db.delete(sessions).where(
|
|
9816
|
-
or6(
|
|
10069
|
+
or6(eq111(sessions.userId, user.id), eq111(sessions.pendingUserId, user.id))
|
|
9817
10070
|
).run();
|
|
9818
10071
|
});
|
|
9819
10072
|
console.log("Password changed. Existing sign-in sessions were revoked.");
|
|
@@ -9823,17 +10076,17 @@ async function resetPassword(store, email) {
|
|
|
9823
10076
|
}
|
|
9824
10077
|
|
|
9825
10078
|
// server/cli/database.ts
|
|
9826
|
-
import { z as
|
|
10079
|
+
import { z as z54 } from "zod";
|
|
9827
10080
|
|
|
9828
10081
|
// server/db/connection.ts
|
|
9829
|
-
var driver = typeof Bun === "undefined" ? await import("./node-driver-
|
|
10082
|
+
var driver = typeof Bun === "undefined" ? await import("./node-driver-75PFAG2L.js") : await import("./bun-driver-UOZIWBHK.js");
|
|
9830
10083
|
var openDatabase = driver.openDatabase;
|
|
9831
10084
|
|
|
9832
10085
|
// server/cli/database.ts
|
|
9833
10086
|
import { chmodSync, constants, copyFileSync, existsSync as existsSync3 } from "node:fs";
|
|
9834
10087
|
import { join as join3 } from "node:path";
|
|
9835
10088
|
function verifySnapshot(sqlite) {
|
|
9836
|
-
const integrity =
|
|
10089
|
+
const integrity = z54.array(z54.object({ integrity_check: z54.string() })).parse(sqlite.query("PRAGMA integrity_check").all());
|
|
9837
10090
|
if (integrity.length !== 1 || integrity[0]?.integrity_check !== "ok") {
|
|
9838
10091
|
throw new Error("Backup integrity check failed.");
|
|
9839
10092
|
}
|
|
@@ -9981,13 +10234,13 @@ function openStore(dataDir2) {
|
|
|
9981
10234
|
}
|
|
9982
10235
|
|
|
9983
10236
|
// server/execution/maintenance.ts
|
|
9984
|
-
import { z as
|
|
10237
|
+
import { z as z55 } from "zod";
|
|
9985
10238
|
import { CronExpressionParser as CronExpressionParser2 } from "cron-parser";
|
|
9986
|
-
import { and as
|
|
10239
|
+
import { and as and85, eq as eq112, inArray as inArray11 } from "drizzle-orm";
|
|
9987
10240
|
function maintenance(store) {
|
|
9988
10241
|
const currentTime = now();
|
|
9989
10242
|
inTransaction(store, (store2) => {
|
|
9990
|
-
const active = store2.db.select().from(runs).where(
|
|
10243
|
+
const active = store2.db.select().from(runs).where(inArray11(runs.status, ["running", "waiting_approval"])).all();
|
|
9991
10244
|
for (const run of active) {
|
|
9992
10245
|
if (run.leaseExpiresAt && run.leaseExpiresAt <= currentTime || run.deadline && run.deadline <= currentTime) {
|
|
9993
10246
|
store2.db.update(runs).set({
|
|
@@ -9995,22 +10248,22 @@ function maintenance(store) {
|
|
|
9995
10248
|
error: "Execution stopped responding. Review side effects before retrying.",
|
|
9996
10249
|
capabilityHash: "",
|
|
9997
10250
|
updatedAt: currentTime
|
|
9998
|
-
}).where(
|
|
10251
|
+
}).where(eq112(runs.id, run.id)).run();
|
|
9999
10252
|
store2.db.update(approvals).set({ status: "interrupted" }).where(
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
|
|
10253
|
+
and85(
|
|
10254
|
+
eq112(approvals.runId, run.id),
|
|
10255
|
+
eq112(approvals.status, "pending")
|
|
10003
10256
|
)
|
|
10004
10257
|
).run();
|
|
10005
10258
|
}
|
|
10006
10259
|
}
|
|
10007
|
-
for (const schedule of store2.db.select().from(schedules).where(
|
|
10260
|
+
for (const schedule of store2.db.select().from(schedules).where(eq112(schedules.enabled, true)).all()) {
|
|
10008
10261
|
if (schedule.nextRunAt > currentTime) {
|
|
10009
10262
|
continue;
|
|
10010
10263
|
}
|
|
10011
|
-
const action = store2.db.select().from(actions).where(
|
|
10264
|
+
const action = store2.db.select().from(actions).where(eq112(actions.id, schedule.actionId)).get();
|
|
10012
10265
|
if (!action) {
|
|
10013
|
-
store2.db.update(schedules).set({ enabled: false }).where(
|
|
10266
|
+
store2.db.update(schedules).set({ enabled: false }).where(eq112(schedules.id, schedule.id)).run();
|
|
10014
10267
|
continue;
|
|
10015
10268
|
}
|
|
10016
10269
|
const nextRunAt = CronExpressionParser2.parse(schedule.cron, {
|
|
@@ -10041,16 +10294,16 @@ function maintenance(store) {
|
|
|
10041
10294
|
project: action.projectId,
|
|
10042
10295
|
operation: "action",
|
|
10043
10296
|
action: action.id,
|
|
10044
|
-
inputs:
|
|
10297
|
+
inputs: z55.record(z55.string(), z55.json()).parse(schedule.inputs),
|
|
10045
10298
|
idempotency_key: `schedule:${schedule.id}:${schedule.nextRunAt}`
|
|
10046
10299
|
});
|
|
10047
|
-
store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(
|
|
10300
|
+
store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq112(runs.id, run.id)).run();
|
|
10048
10301
|
} catch (error) {
|
|
10049
10302
|
if (!(error instanceof ServiceError)) {
|
|
10050
10303
|
throw error;
|
|
10051
10304
|
}
|
|
10052
10305
|
}
|
|
10053
|
-
store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(
|
|
10306
|
+
store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(eq112(schedules.id, schedule.id)).run();
|
|
10054
10307
|
}
|
|
10055
10308
|
});
|
|
10056
10309
|
}
|