@orgsdk/cli 2.1.0 → 2.3.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/bin/options.mjs +10 -3
- package/bin/orgsdk.mjs +68 -12
- package/bin/supervision.mjs +9 -0
- package/dist/launcher/updates.js +264 -0
- 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 +1337 -950
- 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/npm-distribution.md +8 -0
- package/docs/studio.md +9 -1
- package/package.json +2 -1
- package/dist/server/out/_next/static/chunks/22w_ipn94al45.css +0 -1
- /package/dist/server/out/_next/static/{CkCrHy-m0W4Wo6_2T25_g → LKRuw_R6wl92CsuMfKtPZ}/_buildManifest.js +0 -0
- /package/dist/server/out/_next/static/{CkCrHy-m0W4Wo6_2T25_g → LKRuw_R6wl92CsuMfKtPZ}/_clientMiddlewareManifest.js +0 -0
- /package/dist/server/out/_next/static/{CkCrHy-m0W4Wo6_2T25_g → LKRuw_R6wl92CsuMfKtPZ}/_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";
|
|
@@ -460,15 +461,50 @@ function studioSession(db, endpoint, audience, token) {
|
|
|
460
461
|
}
|
|
461
462
|
|
|
462
463
|
// server/index.ts
|
|
464
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
465
|
+
|
|
466
|
+
// server/platform/server-lock.ts
|
|
463
467
|
import {
|
|
464
|
-
existsSync as
|
|
465
|
-
mkdirSync
|
|
466
|
-
readFileSync as
|
|
467
|
-
|
|
468
|
-
|
|
468
|
+
existsSync as existsSync3,
|
|
469
|
+
mkdirSync,
|
|
470
|
+
readFileSync as readFileSync3,
|
|
471
|
+
writeFileSync as writeFileSync3,
|
|
472
|
+
unlinkSync
|
|
469
473
|
} from "node:fs";
|
|
474
|
+
import { join as join3 } from "node:path";
|
|
475
|
+
function serverLock(dataDir2) {
|
|
476
|
+
mkdirSync(dataDir2, { recursive: true, mode: 448 });
|
|
477
|
+
const file = join3(dataDir2, "server.pid");
|
|
478
|
+
if (existsSync3(file)) {
|
|
479
|
+
const pid = Number(readFileSync3(file, "utf8"));
|
|
480
|
+
if (!Number.isInteger(pid) || pid < 1) {
|
|
481
|
+
throw new Error("Invalid server lock; inspect the data directory.");
|
|
482
|
+
}
|
|
483
|
+
let alive = false;
|
|
484
|
+
try {
|
|
485
|
+
process.kill(pid, 0);
|
|
486
|
+
alive = true;
|
|
487
|
+
} catch (error) {
|
|
488
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ESRCH") {
|
|
489
|
+
throw error;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (alive) {
|
|
493
|
+
throw new Error("An OrgSDK server already owns this data directory.");
|
|
494
|
+
}
|
|
495
|
+
unlinkSync(file);
|
|
496
|
+
}
|
|
497
|
+
writeFileSync3(file, String(process.pid), { flag: "wx", mode: 384 });
|
|
498
|
+
return () => {
|
|
499
|
+
if (existsSync3(file) && readFileSync3(file, "utf8") === String(process.pid)) {
|
|
500
|
+
unlinkSync(file);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// server/index.ts
|
|
470
506
|
import { homedir } from "node:os";
|
|
471
|
-
import { join as
|
|
507
|
+
import { join as join6, resolve as resolve3 } from "node:path";
|
|
472
508
|
|
|
473
509
|
// server/mcp/oauth-callback.ts
|
|
474
510
|
import { auth } from "@modelcontextprotocol/client";
|
|
@@ -732,6 +768,8 @@ var agentsSchema = z4.array(
|
|
|
732
768
|
resources: z4.object({ tables: resourceGrant, documents: resourceGrant }).optional(),
|
|
733
769
|
plugins: z4.array(
|
|
734
770
|
z4.object({
|
|
771
|
+
shell_policy_id: z4.uuid().optional(),
|
|
772
|
+
digest: z4.string().optional(),
|
|
735
773
|
credential_id: z4.string().nullable().optional(),
|
|
736
774
|
distribution: z4.string().optional(),
|
|
737
775
|
mcp: z4.object({ id: z4.uuid() }).optional()
|
|
@@ -1176,7 +1214,7 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
|
1176
1214
|
import { ZodError as ZodError2 } from "zod";
|
|
1177
1215
|
|
|
1178
1216
|
// server/api/mcp-dispatch.ts
|
|
1179
|
-
import { z as
|
|
1217
|
+
import { z as z48 } from "zod";
|
|
1180
1218
|
|
|
1181
1219
|
// server/actions/schemas.ts
|
|
1182
1220
|
import { z as z8 } from "zod";
|
|
@@ -1522,14 +1560,14 @@ function projectGrant(ctx, id) {
|
|
|
1522
1560
|
throw new ServiceError("FORBIDDEN", "Project is outside the client grant.");
|
|
1523
1561
|
}
|
|
1524
1562
|
}
|
|
1525
|
-
function authorizeVersion(ctx, action,
|
|
1563
|
+
function authorizeVersion(ctx, action, version2, explicit) {
|
|
1526
1564
|
if (!ctx.token) {
|
|
1527
1565
|
return;
|
|
1528
1566
|
}
|
|
1529
1567
|
if (ctx.token.projects.includes(action.projectId)) {
|
|
1530
1568
|
return;
|
|
1531
1569
|
}
|
|
1532
|
-
if (explicit && ctx.token.actionVersions.includes(
|
|
1570
|
+
if (explicit && ctx.token.actionVersions.includes(version2.id)) {
|
|
1533
1571
|
return;
|
|
1534
1572
|
}
|
|
1535
1573
|
throw new ServiceError(
|
|
@@ -1854,7 +1892,7 @@ var casesSchema = z11.array(
|
|
|
1854
1892
|
forbidden_calls: z11.array(toolName).max(100).default([])
|
|
1855
1893
|
})
|
|
1856
1894
|
).min(1).max(50);
|
|
1857
|
-
function validateCases(
|
|
1895
|
+
function validateCases(version2, value) {
|
|
1858
1896
|
const parsed = casesSchema.safeParse(value);
|
|
1859
1897
|
if (!parsed.success || Buffer.byteLength(JSON.stringify(parsed.data)) > 2e5) {
|
|
1860
1898
|
throw new ServiceError(
|
|
@@ -1868,8 +1906,8 @@ function validateCases(version, value) {
|
|
|
1868
1906
|
throw new ServiceError("BAD_REQUEST", "Test case names must be unique.");
|
|
1869
1907
|
}
|
|
1870
1908
|
names.add(testCase.name);
|
|
1871
|
-
validateContract(
|
|
1872
|
-
validateContract(
|
|
1909
|
+
validateContract(version2.inputSchema, testCase.inputs);
|
|
1910
|
+
validateContract(version2.outputSchema, testCase.expected);
|
|
1873
1911
|
}
|
|
1874
1912
|
return parsed.data.map((testCase) => ({
|
|
1875
1913
|
...testCase,
|
|
@@ -2057,11 +2095,11 @@ function findVersion(context, actionId, number) {
|
|
|
2057
2095
|
).orderBy(desc2(actionVersions.number)).limit(1).get();
|
|
2058
2096
|
}
|
|
2059
2097
|
function requireVersion(context, actionId, number) {
|
|
2060
|
-
const
|
|
2061
|
-
if (!
|
|
2098
|
+
const version2 = findVersion(context, actionId, number);
|
|
2099
|
+
if (!version2) {
|
|
2062
2100
|
throw new ServiceError("NOT_FOUND", "Action version not found.");
|
|
2063
2101
|
}
|
|
2064
|
-
return
|
|
2102
|
+
return version2;
|
|
2065
2103
|
}
|
|
2066
2104
|
function findTestSuite(context, versionId, revision3) {
|
|
2067
2105
|
return context.db.select().from(actionTestSuites).where(
|
|
@@ -2076,8 +2114,8 @@ function findTestSuite(context, versionId, revision3) {
|
|
|
2076
2114
|
// server/actions/versions.ts
|
|
2077
2115
|
function actionVersion(ctx, actionId, number) {
|
|
2078
2116
|
const action = actionsRepository(ctx).find(actionId);
|
|
2079
|
-
const
|
|
2080
|
-
return { action, version };
|
|
2117
|
+
const version2 = requireVersion(ctx, action.id, number);
|
|
2118
|
+
return { action, version: version2 };
|
|
2081
2119
|
}
|
|
2082
2120
|
function resolveActionForSave(ctx, projectId, name, id) {
|
|
2083
2121
|
const actionName = text2(name, "name");
|
|
@@ -2134,16 +2172,16 @@ function versionForSave(ctx, action, body, promotedFrom = null) {
|
|
|
2134
2172
|
|
|
2135
2173
|
// server/router/actions/version.ts
|
|
2136
2174
|
var versionProcedure = scopedProcedure("catalog:read").input(actionVersionSchema).query(({ ctx, input: input2 }) => {
|
|
2137
|
-
const { action, version } = actionVersion(ctx, input2.id, input2.version);
|
|
2138
|
-
authorizeVersion(ctx, action,
|
|
2139
|
-
return serializeVersion(
|
|
2175
|
+
const { action, version: version2 } = actionVersion(ctx, input2.id, input2.version);
|
|
2176
|
+
authorizeVersion(ctx, action, version2, input2.version !== void 0);
|
|
2177
|
+
return serializeVersion(version2);
|
|
2140
2178
|
});
|
|
2141
2179
|
|
|
2142
2180
|
// server/router/actions/tests.ts
|
|
2143
2181
|
var testsProcedure = scopedProcedure("catalog:read").input(actionTestsSchema).query(({ ctx, input: input2 }) => {
|
|
2144
|
-
const { action, version } = actionVersion(ctx, input2.id, input2.version);
|
|
2145
|
-
authorizeVersion(ctx, action,
|
|
2146
|
-
const selected = findTestSuite(ctx,
|
|
2182
|
+
const { action, version: version2 } = actionVersion(ctx, input2.id, input2.version);
|
|
2183
|
+
authorizeVersion(ctx, action, version2, true);
|
|
2184
|
+
const selected = findTestSuite(ctx, version2.id, input2.suite_revision);
|
|
2147
2185
|
if (!selected) {
|
|
2148
2186
|
throw new ServiceError(
|
|
2149
2187
|
"NOT_FOUND",
|
|
@@ -2158,16 +2196,16 @@ var saveTestsProcedure = scopedProcedure("actions:write").input(saveTestsSchema)
|
|
|
2158
2196
|
return inTransaction(ctx, (ctx2) => {
|
|
2159
2197
|
const action = actionsRepository(ctx2).find(input2.id);
|
|
2160
2198
|
projectGrant(ctx2, action.projectId);
|
|
2161
|
-
const
|
|
2162
|
-
const cases = validateCases(
|
|
2199
|
+
const version2 = requireVersion(ctx2, action.id, input2.version);
|
|
2200
|
+
const cases = validateCases(version2, input2.cases);
|
|
2163
2201
|
const hash = digest(JSON.stringify(cases));
|
|
2164
|
-
const latest = findTestSuite(ctx2,
|
|
2202
|
+
const latest = findTestSuite(ctx2, version2.id);
|
|
2165
2203
|
if (latest?.digest === hash) {
|
|
2166
2204
|
return suiteView(latest);
|
|
2167
2205
|
}
|
|
2168
2206
|
const suite = ctx2.db.insert(actionTestSuites).values({
|
|
2169
2207
|
...base(ctx2.workspace.id),
|
|
2170
|
-
versionId:
|
|
2208
|
+
versionId: version2.id,
|
|
2171
2209
|
number: (latest?.number ?? 0) + 1,
|
|
2172
2210
|
cases,
|
|
2173
2211
|
digest: hash
|
|
@@ -2339,7 +2377,81 @@ function findIdempotentRun(ctx, namespace, key) {
|
|
|
2339
2377
|
}
|
|
2340
2378
|
|
|
2341
2379
|
// server/runs/create.ts
|
|
2380
|
+
import { z as z16 } from "zod";
|
|
2381
|
+
|
|
2382
|
+
// server/plugins/shell-policy.ts
|
|
2383
|
+
import { and as and19, eq as eq20, gt as gt2, inArray as inArray5, sql } from "drizzle-orm";
|
|
2384
|
+
|
|
2385
|
+
// server/runs/resume-after-approval.ts
|
|
2386
|
+
import { and as and18, eq as eq19, notExists } from "drizzle-orm";
|
|
2387
|
+
function resumeAfterApproval(ctx, runId) {
|
|
2388
|
+
const pending = ctx.db.select({ id: approvals.id }).from(approvals).where(and18(eq19(approvals.runId, runId), eq19(approvals.status, "pending")));
|
|
2389
|
+
ctx.db.update(runs).set({ status: "running", updatedAt: now() }).where(
|
|
2390
|
+
and18(
|
|
2391
|
+
eq19(runs.id, runId),
|
|
2392
|
+
eq19(runs.status, "waiting_approval"),
|
|
2393
|
+
eq19(runs.cancelRequested, false),
|
|
2394
|
+
notExists(pending)
|
|
2395
|
+
)
|
|
2396
|
+
).run();
|
|
2397
|
+
}
|
|
2398
|
+
|
|
2399
|
+
// server/plugins/shell-policy.ts
|
|
2342
2400
|
import { z as z15 } from "zod";
|
|
2401
|
+
var executableName = z15.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.+-]{0,127}$/);
|
|
2402
|
+
var ruleDecision = z15.enum(["allow", "block", "ask"]);
|
|
2403
|
+
function supportsShellPolicy(plugin) {
|
|
2404
|
+
const tools2 = plugin.releaseMetadata.tools;
|
|
2405
|
+
return plugin.slug === "shell" && plugin.distribution === "external" && Array.isArray(tools2) && tools2.some(
|
|
2406
|
+
(tool) => object(tool) && tool.name === "run" && object(tool.metadata) && tool.metadata.approval === "shell-executable"
|
|
2407
|
+
);
|
|
2408
|
+
}
|
|
2409
|
+
function writeShellRule(ctx, plugin, executable, decision) {
|
|
2410
|
+
const pluginId = plugin.id;
|
|
2411
|
+
if (decision === "ask") {
|
|
2412
|
+
ctx.db.delete(shellRules).where(
|
|
2413
|
+
and19(
|
|
2414
|
+
eq20(shellRules.pluginId, pluginId),
|
|
2415
|
+
eq20(shellRules.executable, executable)
|
|
2416
|
+
)
|
|
2417
|
+
).run();
|
|
2418
|
+
} else {
|
|
2419
|
+
ctx.db.insert(shellRules).values({ pluginId, executable, decision }).onConflictDoUpdate({
|
|
2420
|
+
target: [shellRules.pluginId, shellRules.executable],
|
|
2421
|
+
set: { decision }
|
|
2422
|
+
}).run();
|
|
2423
|
+
}
|
|
2424
|
+
if (decision !== "ask") {
|
|
2425
|
+
const currentTime = now();
|
|
2426
|
+
const liveRunIds = ctx.db.select({ id: runs.id }).from(runs).where(
|
|
2427
|
+
and19(
|
|
2428
|
+
eq20(runs.projectId, plugin.projectId),
|
|
2429
|
+
eq20(runs.workspaceId, plugin.workspaceId),
|
|
2430
|
+
eq20(runs.cancelRequested, false),
|
|
2431
|
+
eq20(runs.status, "waiting_approval"),
|
|
2432
|
+
gt2(runs.leaseExpiresAt, currentTime),
|
|
2433
|
+
gt2(runs.deadline, currentTime)
|
|
2434
|
+
)
|
|
2435
|
+
);
|
|
2436
|
+
const changed = ctx.db.update(approvals).set({
|
|
2437
|
+
status: decision === "allow" ? "approved" : "denied",
|
|
2438
|
+
decidedBy: ctx.user?.id,
|
|
2439
|
+
updatedAt: currentTime
|
|
2440
|
+
}).where(
|
|
2441
|
+
and19(
|
|
2442
|
+
eq20(approvals.workspaceId, plugin.workspaceId),
|
|
2443
|
+
eq20(approvals.status, "pending"),
|
|
2444
|
+
inArray5(approvals.runId, liveRunIds),
|
|
2445
|
+
sql`json_extract(${approvals.shell}, '$.pluginId') = ${plugin.id} and json_extract(${approvals.shell}, '$.digest') = ${plugin.digest} and json_extract(${approvals.shell}, '$.executable') = ${executable}`
|
|
2446
|
+
)
|
|
2447
|
+
).returning({ id: approvals.id, runId: approvals.runId }).all();
|
|
2448
|
+
for (const row of changed) {
|
|
2449
|
+
recordAudit(ctx, "approval", row.id, "updated");
|
|
2450
|
+
resumeAfterApproval(ctx, row.runId);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
recordAudit(ctx, "shell_rule", pluginId + "/" + executable, decision);
|
|
2454
|
+
}
|
|
2343
2455
|
|
|
2344
2456
|
// server/projects/plugin-namespace.ts
|
|
2345
2457
|
function pluginNamespace(slug2) {
|
|
@@ -2429,6 +2541,7 @@ function projectConfiguration(ctx, projectId) {
|
|
|
2429
2541
|
configuration: plugin.configuration,
|
|
2430
2542
|
package_url: plugin.packageUrl,
|
|
2431
2543
|
contract_version: 1,
|
|
2544
|
+
...supportsShellPolicy(plugin) ? { shell_policy_id: plugin.id } : {},
|
|
2432
2545
|
...plugin.distribution === "mcp" ? { mcp: mcpSnapshot(ctx, plugin.id) } : {}
|
|
2433
2546
|
}));
|
|
2434
2547
|
const revision3 = digest(
|
|
@@ -2565,11 +2678,11 @@ function projectSnapshot(ctx, projectId, operation = "code") {
|
|
|
2565
2678
|
}
|
|
2566
2679
|
|
|
2567
2680
|
// server/repositories/runs.ts
|
|
2568
|
-
import { and as
|
|
2681
|
+
import { and as and20, eq as eq21 } from "drizzle-orm";
|
|
2569
2682
|
function runsRepository(context) {
|
|
2570
2683
|
const workspaceId = requireWorkspace(context).id;
|
|
2571
2684
|
const database = context.db;
|
|
2572
|
-
const scoped = (id) =>
|
|
2685
|
+
const scoped = (id) => and20(eq21(runs.workspaceId, workspaceId), eq21(runs.id, id));
|
|
2573
2686
|
return {
|
|
2574
2687
|
find(id) {
|
|
2575
2688
|
const row = database.select().from(runs).where(scoped(id)).get();
|
|
@@ -2601,22 +2714,22 @@ function runsRepository(context) {
|
|
|
2601
2714
|
}
|
|
2602
2715
|
|
|
2603
2716
|
// server/repositories/workspace-settings.ts
|
|
2604
|
-
import { eq as
|
|
2717
|
+
import { eq as eq22 } from "drizzle-orm";
|
|
2605
2718
|
function workspaceSettingsForWorkspace(database, workspaceId) {
|
|
2606
|
-
return database.select().from(workspaceSettings).where(
|
|
2719
|
+
return database.select().from(workspaceSettings).where(eq22(workspaceSettings.workspaceId, workspaceId)).get();
|
|
2607
2720
|
}
|
|
2608
2721
|
|
|
2609
2722
|
// server/runs/sessions.ts
|
|
2610
|
-
import { eq as
|
|
2723
|
+
import { eq as eq24 } from "drizzle-orm";
|
|
2611
2724
|
|
|
2612
2725
|
// server/repositories/executors.ts
|
|
2613
|
-
import { and as
|
|
2726
|
+
import { and as and21, eq as eq23 } from "drizzle-orm";
|
|
2614
2727
|
function executorsRepository(context) {
|
|
2615
2728
|
const workspaceId = requireWorkspace(context).id;
|
|
2616
2729
|
const database = context.db;
|
|
2617
|
-
const scoped = (id, filter) =>
|
|
2618
|
-
|
|
2619
|
-
id === void 0 ? void 0 :
|
|
2730
|
+
const scoped = (id, filter) => and21(
|
|
2731
|
+
eq23(executors.workspaceId, workspaceId),
|
|
2732
|
+
id === void 0 ? void 0 : eq23(executors.id, id),
|
|
2620
2733
|
filter
|
|
2621
2734
|
);
|
|
2622
2735
|
return {
|
|
@@ -2651,7 +2764,7 @@ function sessionSource(command2, input2) {
|
|
|
2651
2764
|
}
|
|
2652
2765
|
function requireSessionRunner(ctx, project, executionPool) {
|
|
2653
2766
|
const [runner] = executorsRepository(ctx).list(
|
|
2654
|
-
|
|
2767
|
+
eq24(executors.projectId, project)
|
|
2655
2768
|
);
|
|
2656
2769
|
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
2770
|
throw new ServiceError(
|
|
@@ -2679,11 +2792,11 @@ function createRunInTransaction(ctx, body) {
|
|
|
2679
2792
|
if (setting && !setting.enabled) {
|
|
2680
2793
|
throw new ServiceError("FORBIDDEN", "Workspace execution is disabled.");
|
|
2681
2794
|
}
|
|
2682
|
-
let
|
|
2795
|
+
let version2 = null;
|
|
2683
2796
|
let action = null;
|
|
2684
2797
|
let suite = null;
|
|
2685
2798
|
if (operation === "action" || operation === "test") {
|
|
2686
|
-
({ action, version } = actionVersion(
|
|
2799
|
+
({ action, version: version2 } = actionVersion(
|
|
2687
2800
|
ctx,
|
|
2688
2801
|
text2(body.action, "action"),
|
|
2689
2802
|
body.version
|
|
@@ -2695,9 +2808,9 @@ function createRunInTransaction(ctx, body) {
|
|
|
2695
2808
|
);
|
|
2696
2809
|
}
|
|
2697
2810
|
scope(ctx, operation === "test" ? "actions:test" : "actions:run");
|
|
2698
|
-
authorizeVersion(ctx, action,
|
|
2811
|
+
authorizeVersion(ctx, action, version2, body.version !== void 0);
|
|
2699
2812
|
if (operation === "action") {
|
|
2700
|
-
validateContract(
|
|
2813
|
+
validateContract(version2.inputSchema, inputs);
|
|
2701
2814
|
}
|
|
2702
2815
|
if (operation === "test") {
|
|
2703
2816
|
if (!Number.isInteger(body.version) || typeof body.suite_revision !== "number" || !Number.isInteger(body.suite_revision)) {
|
|
@@ -2706,7 +2819,7 @@ function createRunInTransaction(ctx, body) {
|
|
|
2706
2819
|
"Tests require a version and suite revision."
|
|
2707
2820
|
);
|
|
2708
2821
|
}
|
|
2709
|
-
suite = findTestSuite(ctx,
|
|
2822
|
+
suite = findTestSuite(ctx, version2.id, body.suite_revision) ?? null;
|
|
2710
2823
|
if (!suite) {
|
|
2711
2824
|
throw new ServiceError("NOT_FOUND", "Test suite not found.");
|
|
2712
2825
|
}
|
|
@@ -2742,8 +2855,8 @@ function createRunInTransaction(ctx, body) {
|
|
|
2742
2855
|
"Schemas are only accepted for validation jobs."
|
|
2743
2856
|
);
|
|
2744
2857
|
}
|
|
2745
|
-
const snapshot =
|
|
2746
|
-
const source =
|
|
2858
|
+
const snapshot = z16.record(z16.string(), z16.json()).parse(projectSnapshot(ctx, project.id, operation));
|
|
2859
|
+
const source = version2?.source ?? (session ? sessionSource(session, body) : sourceText(body.source));
|
|
2747
2860
|
if (session) {
|
|
2748
2861
|
Object.assign(snapshot, {
|
|
2749
2862
|
session,
|
|
@@ -2756,14 +2869,14 @@ function createRunInTransaction(ctx, body) {
|
|
|
2756
2869
|
}
|
|
2757
2870
|
Object.assign(snapshot, {
|
|
2758
2871
|
...source === void 0 ? {} : { source, source_digest: digest(source) },
|
|
2759
|
-
protocol_version: session ? 4 : operation === "validate" || operation === "test" ||
|
|
2872
|
+
protocol_version: session ? 4 : operation === "validate" || operation === "test" || version2?.validationMode === "semantic" ? 3 : 2
|
|
2760
2873
|
});
|
|
2761
|
-
if (
|
|
2874
|
+
if (version2) {
|
|
2762
2875
|
Object.assign(snapshot, {
|
|
2763
|
-
version:
|
|
2764
|
-
validation_mode:
|
|
2765
|
-
input_schema:
|
|
2766
|
-
output_schema:
|
|
2876
|
+
version: version2.number,
|
|
2877
|
+
validation_mode: version2.validationMode,
|
|
2878
|
+
input_schema: version2.inputSchema,
|
|
2879
|
+
output_schema: version2.outputSchema
|
|
2767
2880
|
});
|
|
2768
2881
|
}
|
|
2769
2882
|
if (operation === "validate") {
|
|
@@ -2789,7 +2902,7 @@ function createRunInTransaction(ctx, body) {
|
|
|
2789
2902
|
const existing = findIdempotentRun(ctx2, namespace, key);
|
|
2790
2903
|
if (existing) {
|
|
2791
2904
|
const serializeInputs = session ? canonicalJson : JSON.stringify;
|
|
2792
|
-
if (existing.projectId !== project.id || existing.operation !== operation || existing.actorId !== ctx2.user?.id || existing.actionVersionId !== (
|
|
2905
|
+
if (existing.projectId !== project.id || existing.operation !== operation || existing.actorId !== ctx2.user?.id || existing.actionVersionId !== (version2?.id ?? null) || serializeInputs(existing.inputs) !== serializeInputs(inputs) || existing.snapshot.source !== snapshot.source || session && JSON.stringify(existing.snapshot.session) !== JSON.stringify(session) || operation === "validate" && (JSON.stringify(existing.snapshot.input_schema) !== JSON.stringify(snapshot.input_schema) || JSON.stringify(existing.snapshot.output_schema) !== JSON.stringify(snapshot.output_schema)) || operation === "test" && testSuiteId(existing.snapshot.test_suite) !== testSuiteId(snapshot.test_suite)) {
|
|
2793
2906
|
throw new ServiceError(
|
|
2794
2907
|
"BAD_REQUEST",
|
|
2795
2908
|
"Idempotency key already used for a different request."
|
|
@@ -2804,7 +2917,7 @@ function createRunInTransaction(ctx, body) {
|
|
|
2804
2917
|
projectId: project.id,
|
|
2805
2918
|
actorId: ctx2.user.id,
|
|
2806
2919
|
tokenId: ctx2.token?.id ?? null,
|
|
2807
|
-
actionVersionId:
|
|
2920
|
+
actionVersionId: version2?.id ?? null,
|
|
2808
2921
|
operation,
|
|
2809
2922
|
origin: ctx2.token ? "client" : "browser",
|
|
2810
2923
|
originReference: "",
|
|
@@ -2893,20 +3006,21 @@ var actionsRouter = router({
|
|
|
2893
3006
|
});
|
|
2894
3007
|
|
|
2895
3008
|
// server/router/approvals/list.ts
|
|
2896
|
-
import { eq as
|
|
3009
|
+
import { eq as eq25 } from "drizzle-orm";
|
|
2897
3010
|
|
|
2898
3011
|
// server/runs/approvals.ts
|
|
2899
|
-
import { z as
|
|
2900
|
-
var approvalIdSchema =
|
|
2901
|
-
var decideApprovalSchema =
|
|
2902
|
-
id:
|
|
2903
|
-
decision:
|
|
3012
|
+
import { z as z17 } from "zod";
|
|
3013
|
+
var approvalIdSchema = z17.strictObject({ id: z17.uuid() });
|
|
3014
|
+
var decideApprovalSchema = z17.strictObject({
|
|
3015
|
+
id: z17.uuid(),
|
|
3016
|
+
decision: z17.enum(["approved", "denied", "always_allow", "block"])
|
|
2904
3017
|
});
|
|
2905
3018
|
function approvalView(row) {
|
|
2906
3019
|
return {
|
|
2907
3020
|
id: row.id,
|
|
2908
3021
|
run: row.runId,
|
|
2909
3022
|
prompt: row.prompt,
|
|
3023
|
+
shell: row.shell ? { executable: row.shell.executable, project: row.shell.projectId } : null,
|
|
2910
3024
|
status: row.status,
|
|
2911
3025
|
decided_by: row.decidedBy
|
|
2912
3026
|
};
|
|
@@ -2914,16 +3028,16 @@ function approvalView(row) {
|
|
|
2914
3028
|
|
|
2915
3029
|
// server/router/approvals/list.ts
|
|
2916
3030
|
var listProcedure2 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
2917
|
-
const workspaceApprovals = ctx.db.select().from(approvals).where(
|
|
3031
|
+
const workspaceApprovals = ctx.db.select().from(approvals).where(eq25(approvals.workspaceId, ctx.workspace.id)).all();
|
|
2918
3032
|
return page(workspaceApprovals.map(approvalView));
|
|
2919
3033
|
});
|
|
2920
3034
|
|
|
2921
3035
|
// server/repositories/approvals.ts
|
|
2922
|
-
import { and as
|
|
3036
|
+
import { and as and22, eq as eq26 } from "drizzle-orm";
|
|
2923
3037
|
function approvalsRepository(context) {
|
|
2924
3038
|
const workspaceId = requireWorkspace(context).id;
|
|
2925
3039
|
const database = context.db;
|
|
2926
|
-
const scoped = (id) =>
|
|
3040
|
+
const scoped = (id) => and22(eq26(approvals.workspaceId, workspaceId), eq26(approvals.id, id));
|
|
2927
3041
|
return {
|
|
2928
3042
|
find(id) {
|
|
2929
3043
|
const row = database.select().from(approvals).where(scoped(id)).get();
|
|
@@ -2952,26 +3066,74 @@ var getProcedure2 = browserWorkspaceProcedure.input(approvalIdSchema).query(({ c
|
|
|
2952
3066
|
return approvalView(approvalsRepository(ctx).find(id));
|
|
2953
3067
|
});
|
|
2954
3068
|
|
|
3069
|
+
// server/repositories/plugins.ts
|
|
3070
|
+
import { and as and23, eq as eq27 } from "drizzle-orm";
|
|
3071
|
+
function pluginsRepository(context) {
|
|
3072
|
+
const workspaceId = requireWorkspace(context).id;
|
|
3073
|
+
const database = context.db;
|
|
3074
|
+
const scoped = (id, filter) => and23(
|
|
3075
|
+
eq27(plugins.workspaceId, workspaceId),
|
|
3076
|
+
id === void 0 ? void 0 : eq27(plugins.id, id),
|
|
3077
|
+
filter
|
|
3078
|
+
);
|
|
3079
|
+
return {
|
|
3080
|
+
find(id) {
|
|
3081
|
+
const row = database.select().from(plugins).where(scoped(id)).get();
|
|
3082
|
+
if (!row) {
|
|
3083
|
+
throw new ServiceError("NOT_FOUND", "Not found.");
|
|
3084
|
+
}
|
|
3085
|
+
return row;
|
|
3086
|
+
},
|
|
3087
|
+
list(filter) {
|
|
3088
|
+
return database.select().from(plugins).where(scoped(void 0, filter)).all();
|
|
3089
|
+
}
|
|
3090
|
+
};
|
|
3091
|
+
}
|
|
3092
|
+
|
|
2955
3093
|
// server/router/approvals/decide.ts
|
|
2956
|
-
var decideProcedure = browserManagerProcedure.input(decideApprovalSchema).mutation(
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
3094
|
+
var decideProcedure = browserManagerProcedure.input(decideApprovalSchema).mutation(
|
|
3095
|
+
({ ctx, input: input2 }) => inTransaction(ctx, (ctx2) => {
|
|
3096
|
+
assertCurrentPluginManager(ctx2);
|
|
3097
|
+
const approval = approvalsRepository(ctx2).find(input2.id);
|
|
3098
|
+
const run = runsRepository(ctx2).find(approval.runId);
|
|
3099
|
+
const currentTime = now();
|
|
3100
|
+
if (approval.status !== "pending" || run.cancelRequested || !["running", "waiting_approval"].includes(run.status) || run.deadline && run.deadline <= currentTime || run.leaseExpiresAt && run.leaseExpiresAt <= currentTime) {
|
|
3101
|
+
throw new ServiceError("CONFLICT", "Approval is no longer actionable.");
|
|
3102
|
+
}
|
|
3103
|
+
const persistent = input2.decision === "always_allow" || input2.decision === "block";
|
|
3104
|
+
if (persistent && !approval.shell) {
|
|
3105
|
+
throw new ServiceError(
|
|
3106
|
+
"BAD_REQUEST",
|
|
3107
|
+
"Persistent decisions require a Shell executable request."
|
|
3108
|
+
);
|
|
3109
|
+
}
|
|
3110
|
+
if (approval.shell) {
|
|
3111
|
+
const plugin = pluginsRepository(ctx2).find(approval.shell.pluginId);
|
|
3112
|
+
if (!plugin.enabled || !supportsShellPolicy(plugin) || plugin.projectId !== run.projectId || plugin.digest !== approval.shell.digest) {
|
|
2963
3113
|
throw new ServiceError(
|
|
2964
3114
|
"CONFLICT",
|
|
2965
|
-
"
|
|
3115
|
+
"The Shell installation changed since this request."
|
|
2966
3116
|
);
|
|
2967
3117
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
3118
|
+
if (persistent) {
|
|
3119
|
+
writeShellRule(
|
|
3120
|
+
ctx2,
|
|
3121
|
+
plugin,
|
|
3122
|
+
approval.shell.executable,
|
|
3123
|
+
input2.decision === "block" ? "block" : "allow"
|
|
3124
|
+
);
|
|
3125
|
+
return approvalView(approvalsRepository(ctx2).find(input2.id));
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
const status = input2.decision === "denied" || input2.decision === "block" ? "denied" : "approved";
|
|
3129
|
+
const updated = approvalsRepository(ctx2).update(input2.id, {
|
|
3130
|
+
status,
|
|
3131
|
+
decidedBy: ctx2.user.id
|
|
3132
|
+
});
|
|
3133
|
+
resumeAfterApproval(ctx2, run.id);
|
|
3134
|
+
return approvalView(updated);
|
|
3135
|
+
})
|
|
3136
|
+
);
|
|
2975
3137
|
|
|
2976
3138
|
// server/router/approvals/index.ts
|
|
2977
3139
|
var approvalsRouter = router({
|
|
@@ -2981,11 +3143,11 @@ var approvalsRouter = router({
|
|
|
2981
3143
|
});
|
|
2982
3144
|
|
|
2983
3145
|
// server/router/artifacts/list.ts
|
|
2984
|
-
import { eq as
|
|
3146
|
+
import { eq as eq28 } from "drizzle-orm";
|
|
2985
3147
|
|
|
2986
3148
|
// server/runs/artifacts.ts
|
|
2987
|
-
import { z as
|
|
2988
|
-
var artifactIdSchema =
|
|
3149
|
+
import { z as z18 } from "zod";
|
|
3150
|
+
var artifactIdSchema = z18.strictObject({ id: z18.uuid() });
|
|
2989
3151
|
function artifactView(row) {
|
|
2990
3152
|
return {
|
|
2991
3153
|
id: row.id,
|
|
@@ -2998,17 +3160,17 @@ function artifactView(row) {
|
|
|
2998
3160
|
|
|
2999
3161
|
// server/router/artifacts/list.ts
|
|
3000
3162
|
var listProcedure3 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
3001
|
-
const workspaceArtifacts = ctx.db.select().from(artifacts).where(
|
|
3163
|
+
const workspaceArtifacts = ctx.db.select().from(artifacts).where(eq28(artifacts.workspaceId, ctx.workspace.id)).all();
|
|
3002
3164
|
return page(workspaceArtifacts.map(artifactView));
|
|
3003
3165
|
});
|
|
3004
3166
|
|
|
3005
3167
|
// server/router/artifacts/get.ts
|
|
3006
|
-
import { and as
|
|
3168
|
+
import { and as and24, eq as eq29 } from "drizzle-orm";
|
|
3007
3169
|
var getProcedure3 = browserWorkspaceProcedure.input(artifactIdSchema).query(({ ctx, input: input2 }) => {
|
|
3008
3170
|
const artifact = ctx.db.select().from(artifacts).where(
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3171
|
+
and24(
|
|
3172
|
+
eq29(artifacts.workspaceId, ctx.workspace.id),
|
|
3173
|
+
eq29(artifacts.id, input2.id)
|
|
3012
3174
|
)
|
|
3013
3175
|
).get();
|
|
3014
3176
|
if (!artifact) {
|
|
@@ -3024,10 +3186,10 @@ var artifactsRouter = router({
|
|
|
3024
3186
|
});
|
|
3025
3187
|
|
|
3026
3188
|
// server/router/audit/list.ts
|
|
3027
|
-
import { and as
|
|
3189
|
+
import { and as and26, desc as desc3, eq as eq31, gte, lt } from "drizzle-orm";
|
|
3028
3190
|
|
|
3029
3191
|
// server/audit/queries.ts
|
|
3030
|
-
import { and as
|
|
3192
|
+
import { and as and25, eq as eq30 } from "drizzle-orm";
|
|
3031
3193
|
function auditQueries(database, workspaceId) {
|
|
3032
3194
|
return {
|
|
3033
3195
|
actor(userId) {
|
|
@@ -3039,10 +3201,10 @@ function auditQueries(database, workspaceId) {
|
|
|
3039
3201
|
firstName: users.firstName,
|
|
3040
3202
|
lastName: users.lastName,
|
|
3041
3203
|
username: users.username
|
|
3042
|
-
}).from(memberships).innerJoin(users,
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3204
|
+
}).from(memberships).innerJoin(users, eq30(users.id, memberships.userId)).where(
|
|
3205
|
+
and25(
|
|
3206
|
+
eq30(memberships.workspaceId, workspaceId),
|
|
3207
|
+
eq30(memberships.userId, userId)
|
|
3046
3208
|
)
|
|
3047
3209
|
).get();
|
|
3048
3210
|
}
|
|
@@ -3050,13 +3212,13 @@ function auditQueries(database, workspaceId) {
|
|
|
3050
3212
|
}
|
|
3051
3213
|
|
|
3052
3214
|
// server/audit/schemas.ts
|
|
3053
|
-
import { z as
|
|
3054
|
-
var auditFiltersSchema =
|
|
3055
|
-
actor:
|
|
3056
|
-
kind:
|
|
3057
|
-
object_id:
|
|
3058
|
-
since:
|
|
3059
|
-
before:
|
|
3215
|
+
import { z as z19 } from "zod";
|
|
3216
|
+
var auditFiltersSchema = z19.object({
|
|
3217
|
+
actor: z19.number().int().positive().optional(),
|
|
3218
|
+
kind: z19.string().optional(),
|
|
3219
|
+
object_id: z19.string().optional(),
|
|
3220
|
+
since: z19.iso.datetime().optional(),
|
|
3221
|
+
before: z19.iso.datetime().optional()
|
|
3060
3222
|
}).strict().refine(
|
|
3061
3223
|
(input2) => !input2.since || !input2.before || Date.parse(input2.since) < Date.parse(input2.before),
|
|
3062
3224
|
"Invalid date range."
|
|
@@ -3078,11 +3240,11 @@ function auditView(record, actor) {
|
|
|
3078
3240
|
var listProcedure4 = browserManagerProcedure.input(auditFiltersSchema.optional().default({})).query(({ ctx, input: input2 }) => {
|
|
3079
3241
|
const queries = auditQueries(ctx.db, ctx.workspace.id);
|
|
3080
3242
|
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 :
|
|
3243
|
+
and26(
|
|
3244
|
+
eq31(auditRecords.workspaceId, ctx.workspace.id),
|
|
3245
|
+
input2.actor === void 0 ? void 0 : eq31(auditRecords.actorId, input2.actor),
|
|
3246
|
+
input2.kind === void 0 ? void 0 : eq31(auditRecords.action, input2.kind),
|
|
3247
|
+
input2.object_id === void 0 ? void 0 : eq31(auditRecords.resource, input2.object_id),
|
|
3086
3248
|
input2.since === void 0 ? void 0 : gte(auditRecords.createdAt, input2.since),
|
|
3087
3249
|
input2.before === void 0 ? void 0 : lt(auditRecords.createdAt, input2.before)
|
|
3088
3250
|
)
|
|
@@ -3093,13 +3255,13 @@ var listProcedure4 = browserManagerProcedure.input(auditFiltersSchema.optional()
|
|
|
3093
3255
|
});
|
|
3094
3256
|
|
|
3095
3257
|
// server/router/audit/get.ts
|
|
3096
|
-
import { and as
|
|
3097
|
-
import { z as
|
|
3098
|
-
var getProcedure4 = browserManagerProcedure.input(
|
|
3258
|
+
import { and as and27, eq as eq32 } from "drizzle-orm";
|
|
3259
|
+
import { z as z20 } from "zod";
|
|
3260
|
+
var getProcedure4 = browserManagerProcedure.input(z20.strictObject({ id: z20.uuid() })).query(({ ctx, input: input2 }) => {
|
|
3099
3261
|
const record = ctx.db.select().from(auditRecords).where(
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3262
|
+
and27(
|
|
3263
|
+
eq32(auditRecords.workspaceId, ctx.workspace.id),
|
|
3264
|
+
eq32(auditRecords.id, input2.id)
|
|
3103
3265
|
)
|
|
3104
3266
|
).get();
|
|
3105
3267
|
if (!record) {
|
|
@@ -3148,16 +3310,16 @@ var password = {
|
|
|
3148
3310
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
3149
3311
|
|
|
3150
3312
|
// server/auth/queries.ts
|
|
3151
|
-
import { eq as
|
|
3313
|
+
import { eq as eq33 } from "drizzle-orm";
|
|
3152
3314
|
function createAccount(database, values2) {
|
|
3153
3315
|
return database.insert(users).values(values2).returning().get();
|
|
3154
3316
|
}
|
|
3155
3317
|
function updateAccount(database, userId, changes) {
|
|
3156
|
-
return database.update(users).set(changes).where(
|
|
3318
|
+
return database.update(users).set(changes).where(eq33(users.id, userId)).returning().get();
|
|
3157
3319
|
}
|
|
3158
3320
|
|
|
3159
3321
|
// server/workspaces/queries.ts
|
|
3160
|
-
import { and as
|
|
3322
|
+
import { and as and28, eq as eq34 } from "drizzle-orm";
|
|
3161
3323
|
function memberQuery(database, workspaceId, id) {
|
|
3162
3324
|
return database.select({
|
|
3163
3325
|
id: memberships.id,
|
|
@@ -3165,24 +3327,24 @@ function memberQuery(database, workspaceId, id) {
|
|
|
3165
3327
|
email: users.email,
|
|
3166
3328
|
username: users.username,
|
|
3167
3329
|
role: memberships.role
|
|
3168
|
-
}).from(memberships).innerJoin(users,
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
id === void 0 ? void 0 :
|
|
3330
|
+
}).from(memberships).innerJoin(users, eq34(users.id, memberships.userId)).where(
|
|
3331
|
+
and28(
|
|
3332
|
+
eq34(memberships.workspaceId, workspaceId),
|
|
3333
|
+
id === void 0 ? void 0 : eq34(memberships.id, id)
|
|
3172
3334
|
)
|
|
3173
3335
|
);
|
|
3174
3336
|
}
|
|
3175
3337
|
function membershipForUser(database, workspaceId, userId) {
|
|
3176
3338
|
return database.select().from(memberships).where(
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3339
|
+
and28(
|
|
3340
|
+
eq34(memberships.workspaceId, workspaceId),
|
|
3341
|
+
eq34(memberships.userId, userId)
|
|
3180
3342
|
)
|
|
3181
3343
|
).get();
|
|
3182
3344
|
}
|
|
3183
3345
|
function membershipById(database, workspaceId, id) {
|
|
3184
3346
|
return database.select().from(memberships).where(
|
|
3185
|
-
|
|
3347
|
+
and28(eq34(memberships.workspaceId, workspaceId), eq34(memberships.id, id))
|
|
3186
3348
|
).get();
|
|
3187
3349
|
}
|
|
3188
3350
|
function createMembership(database, values2) {
|
|
@@ -3190,17 +3352,17 @@ function createMembership(database, values2) {
|
|
|
3190
3352
|
}
|
|
3191
3353
|
function setMembershipRole(database, workspaceId, id, role) {
|
|
3192
3354
|
database.update(memberships).set({ role }).where(
|
|
3193
|
-
|
|
3355
|
+
and28(eq34(memberships.workspaceId, workspaceId), eq34(memberships.id, id))
|
|
3194
3356
|
).run();
|
|
3195
3357
|
}
|
|
3196
3358
|
function updateInvitation(database, workspaceId, id, changes) {
|
|
3197
3359
|
database.update(invitations).set(changes).where(
|
|
3198
|
-
|
|
3360
|
+
and28(eq34(invitations.workspaceId, workspaceId), eq34(invitations.id, id))
|
|
3199
3361
|
).run();
|
|
3200
3362
|
}
|
|
3201
3363
|
|
|
3202
3364
|
// server/auth/schemas.ts
|
|
3203
|
-
import { z as
|
|
3365
|
+
import { z as z21 } from "zod";
|
|
3204
3366
|
|
|
3205
3367
|
// server/auth/validation.ts
|
|
3206
3368
|
function strongPassword(value) {
|
|
@@ -3211,38 +3373,38 @@ function validEmail(value) {
|
|
|
3211
3373
|
}
|
|
3212
3374
|
|
|
3213
3375
|
// server/auth/schemas.ts
|
|
3214
|
-
var emailSchema =
|
|
3215
|
-
var passwordSchema =
|
|
3216
|
-
var loginSchema =
|
|
3217
|
-
email:
|
|
3218
|
-
password:
|
|
3219
|
-
});
|
|
3220
|
-
var codeSchema =
|
|
3221
|
-
var signupSchema =
|
|
3376
|
+
var emailSchema = z21.string().refine(validEmail, "Enter a valid email address.");
|
|
3377
|
+
var passwordSchema = z21.string().refine(strongPassword, "Choose a stronger password.");
|
|
3378
|
+
var loginSchema = z21.strictObject({
|
|
3379
|
+
email: z21.string(),
|
|
3380
|
+
password: z21.string().max(1024)
|
|
3381
|
+
});
|
|
3382
|
+
var codeSchema = z21.strictObject({ code: z21.string() });
|
|
3383
|
+
var signupSchema = z21.strictObject({
|
|
3222
3384
|
email: emailSchema,
|
|
3223
|
-
username:
|
|
3385
|
+
username: z21.string().trim().min(1).max(150),
|
|
3224
3386
|
password: passwordSchema
|
|
3225
3387
|
});
|
|
3226
|
-
var setupSchema =
|
|
3227
|
-
domain:
|
|
3228
|
-
workspace_name:
|
|
3229
|
-
username:
|
|
3388
|
+
var setupSchema = z21.strictObject({
|
|
3389
|
+
domain: z21.string(),
|
|
3390
|
+
workspace_name: z21.string().trim().min(1),
|
|
3391
|
+
username: z21.string().trim().min(1),
|
|
3230
3392
|
email: emailSchema,
|
|
3231
3393
|
password1: passwordSchema,
|
|
3232
|
-
password2:
|
|
3233
|
-
project_name:
|
|
3394
|
+
password2: z21.string(),
|
|
3395
|
+
project_name: z21.string().optional()
|
|
3234
3396
|
}).refine((body) => body.password1 === body.password2, "Passwords must match.");
|
|
3235
|
-
var passwordChangeSchema =
|
|
3236
|
-
current_password:
|
|
3397
|
+
var passwordChangeSchema = z21.strictObject({
|
|
3398
|
+
current_password: z21.string().max(1024),
|
|
3237
3399
|
new_password: passwordSchema
|
|
3238
3400
|
});
|
|
3239
|
-
var emailChangeSchema =
|
|
3240
|
-
var reauthenticationSchema =
|
|
3241
|
-
password:
|
|
3401
|
+
var emailChangeSchema = z21.strictObject({ email: emailSchema });
|
|
3402
|
+
var reauthenticationSchema = z21.strictObject({
|
|
3403
|
+
password: z21.string().max(1024)
|
|
3242
3404
|
});
|
|
3243
|
-
var profileSchema =
|
|
3244
|
-
first_name:
|
|
3245
|
-
last_name:
|
|
3405
|
+
var profileSchema = z21.strictObject({
|
|
3406
|
+
first_name: z21.string().optional(),
|
|
3407
|
+
last_name: z21.string().optional()
|
|
3246
3408
|
});
|
|
3247
3409
|
|
|
3248
3410
|
// server/router/auth/setup.ts
|
|
@@ -3386,10 +3548,10 @@ function identityContext(ctx) {
|
|
|
3386
3548
|
}
|
|
3387
3549
|
|
|
3388
3550
|
// server/repositories/auth-attempts.ts
|
|
3389
|
-
import { eq as
|
|
3551
|
+
import { eq as eq35, sql as sql2 } from "drizzle-orm";
|
|
3390
3552
|
function recordAuthAttempt(store, key, time) {
|
|
3391
3553
|
inTransaction(store, (store2) => {
|
|
3392
|
-
const current = store2.db.select().from(authAttempts).where(
|
|
3554
|
+
const current = store2.db.select().from(authAttempts).where(eq35(authAttempts.key, key)).get();
|
|
3393
3555
|
if (current && current.expiresAt > time && current.count >= 10) {
|
|
3394
3556
|
throw new ServiceError(
|
|
3395
3557
|
"TOO_MANY_REQUESTS",
|
|
@@ -3403,7 +3565,7 @@ function recordAuthAttempt(store, key, time) {
|
|
|
3403
3565
|
}).run();
|
|
3404
3566
|
return;
|
|
3405
3567
|
}
|
|
3406
|
-
store2.db.update(authAttempts).set({ count:
|
|
3568
|
+
store2.db.update(authAttempts).set({ count: sql2`${authAttempts.count} + 1` }).where(eq35(authAttempts.key, key)).run();
|
|
3407
3569
|
});
|
|
3408
3570
|
}
|
|
3409
3571
|
|
|
@@ -3448,12 +3610,12 @@ var loginProcedure = browserProcedure.input(loginSchema).mutation(async ({ ctx:
|
|
|
3448
3610
|
});
|
|
3449
3611
|
|
|
3450
3612
|
// server/router/auth/logout.ts
|
|
3451
|
-
import { eq as
|
|
3613
|
+
import { eq as eq36 } from "drizzle-orm";
|
|
3452
3614
|
var logoutProcedure = browserProcedure.mutation(
|
|
3453
3615
|
({ ctx: requestContext }) => {
|
|
3454
3616
|
const ctx = identityContext(requestContext);
|
|
3455
3617
|
if (ctx.sessionId) {
|
|
3456
|
-
ctx.db.delete(sessions).where(
|
|
3618
|
+
ctx.db.delete(sessions).where(eq36(sessions.id, ctx.sessionId)).run();
|
|
3457
3619
|
}
|
|
3458
3620
|
ctx.sessionId = null;
|
|
3459
3621
|
ctx.user = null;
|
|
@@ -3495,8 +3657,8 @@ var signupProcedure = browserProcedure.input(signupSchema).mutation(async ({ ctx
|
|
|
3495
3657
|
});
|
|
3496
3658
|
|
|
3497
3659
|
// server/auth/totp.ts
|
|
3498
|
-
import { z as
|
|
3499
|
-
import { eq as
|
|
3660
|
+
import { z as z22 } from "zod";
|
|
3661
|
+
import { eq as eq37 } from "drizzle-orm";
|
|
3500
3662
|
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
3501
3663
|
var base32Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
3502
3664
|
function base32(bytes) {
|
|
@@ -3555,16 +3717,16 @@ function consumeCode(ctx, user, code) {
|
|
|
3555
3717
|
}
|
|
3556
3718
|
const step = totpCounter(decrypt(ctx2, current.totpSecret), code);
|
|
3557
3719
|
if (step !== null && (current.totpLastCounter === null || step > current.totpLastCounter)) {
|
|
3558
|
-
ctx2.db.update(users).set({ totpLastCounter: step }).where(
|
|
3720
|
+
ctx2.db.update(users).set({ totpLastCounter: step }).where(eq37(users.id, current.id)).run();
|
|
3559
3721
|
return true;
|
|
3560
3722
|
}
|
|
3561
|
-
const hashes =
|
|
3723
|
+
const hashes = z22.array(z22.string()).parse(JSON.parse(current.recoveryCodes));
|
|
3562
3724
|
const index = hashes.indexOf(digest(code));
|
|
3563
3725
|
if (index < 0) {
|
|
3564
3726
|
return false;
|
|
3565
3727
|
}
|
|
3566
3728
|
hashes.splice(index, 1);
|
|
3567
|
-
ctx2.db.update(users).set({ recoveryCodes: JSON.stringify(hashes) }).where(
|
|
3729
|
+
ctx2.db.update(users).set({ recoveryCodes: JSON.stringify(hashes) }).where(eq37(users.id, current.id)).run();
|
|
3568
3730
|
return true;
|
|
3569
3731
|
});
|
|
3570
3732
|
}
|
|
@@ -3633,7 +3795,7 @@ var mfaReauthenticateProcedure = authenticatedBrowserProcedure.input(codeSchema)
|
|
|
3633
3795
|
});
|
|
3634
3796
|
|
|
3635
3797
|
// server/router/auth/change-password.ts
|
|
3636
|
-
import { eq as
|
|
3798
|
+
import { eq as eq38, or as or2 } from "drizzle-orm";
|
|
3637
3799
|
var changePasswordProcedure = freshBrowserProcedure.input(passwordChangeSchema).mutation(async ({ ctx: requestContext, input: input2 }) => {
|
|
3638
3800
|
const ctx = identityContext(requestContext);
|
|
3639
3801
|
const user = requestContext.user;
|
|
@@ -3654,8 +3816,8 @@ var changePasswordProcedure = freshBrowserProcedure.input(passwordChangeSchema).
|
|
|
3654
3816
|
updateAccount(ctx2.db, user.id, { passwordHash });
|
|
3655
3817
|
ctx2.db.delete(sessions).where(
|
|
3656
3818
|
or2(
|
|
3657
|
-
|
|
3658
|
-
|
|
3819
|
+
eq38(sessions.userId, user.id),
|
|
3820
|
+
eq38(sessions.pendingUserId, user.id)
|
|
3659
3821
|
)
|
|
3660
3822
|
).run();
|
|
3661
3823
|
}
|
|
@@ -3805,7 +3967,7 @@ var authRouter = router({
|
|
|
3805
3967
|
});
|
|
3806
3968
|
|
|
3807
3969
|
// server/router/conversations/list.ts
|
|
3808
|
-
import { eq as
|
|
3970
|
+
import { eq as eq39 } from "drizzle-orm";
|
|
3809
3971
|
|
|
3810
3972
|
// server/projects/conversations.ts
|
|
3811
3973
|
var conversationView = (conversation) => {
|
|
@@ -3820,35 +3982,35 @@ var conversationView = (conversation) => {
|
|
|
3820
3982
|
|
|
3821
3983
|
// server/router/conversations/list.ts
|
|
3822
3984
|
var listProcedure5 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
3823
|
-
const records = ctx.db.select().from(conversations).where(
|
|
3985
|
+
const records = ctx.db.select().from(conversations).where(eq39(conversations.workspaceId, ctx.workspace.id)).all();
|
|
3824
3986
|
return page(records.map((record) => conversationView(record)));
|
|
3825
3987
|
});
|
|
3826
3988
|
|
|
3827
3989
|
// server/router/conversations/get.ts
|
|
3828
|
-
import { and as
|
|
3990
|
+
import { and as and29, eq as eq40 } from "drizzle-orm";
|
|
3829
3991
|
|
|
3830
3992
|
// 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:
|
|
3993
|
+
import { z as z23 } from "zod";
|
|
3994
|
+
var projectIdSchema = z23.strictObject({ id: z23.uuid() });
|
|
3995
|
+
var projectCreateSchema = z23.strictObject({
|
|
3996
|
+
name: z23.string().min(1).max(100),
|
|
3997
|
+
enabled: z23.boolean().optional(),
|
|
3998
|
+
readable_tables: z23.array(z23.uuid()).optional(),
|
|
3999
|
+
writable_tables: z23.array(z23.uuid()).optional(),
|
|
4000
|
+
readable_documents: z23.array(z23.uuid()).optional(),
|
|
4001
|
+
writable_documents: z23.array(z23.uuid()).optional()
|
|
4002
|
+
});
|
|
4003
|
+
var projectChangesSchema = projectCreateSchema.partial().extend({ id: z23.uuid() });
|
|
3842
4004
|
var projectExecutorSchema = projectIdSchema.extend({
|
|
3843
|
-
locally_managed:
|
|
4005
|
+
locally_managed: z23.boolean().default(false)
|
|
3844
4006
|
});
|
|
3845
4007
|
|
|
3846
4008
|
// server/router/conversations/get.ts
|
|
3847
4009
|
var getProcedure5 = browserWorkspaceProcedure.input(projectIdSchema).query(({ ctx, input: input2 }) => {
|
|
3848
4010
|
const conversation = ctx.db.select().from(conversations).where(
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
4011
|
+
and29(
|
|
4012
|
+
eq40(conversations.workspaceId, ctx.workspace.id),
|
|
4013
|
+
eq40(conversations.id, input2.id)
|
|
3852
4014
|
)
|
|
3853
4015
|
).get();
|
|
3854
4016
|
if (!conversation) {
|
|
@@ -3864,25 +4026,25 @@ var conversationsRouter = router({
|
|
|
3864
4026
|
});
|
|
3865
4027
|
|
|
3866
4028
|
// server/router/credentials/begin-oauth.ts
|
|
3867
|
-
import { and as
|
|
4029
|
+
import { and as and31, eq as eq42, lt as lt2 } from "drizzle-orm";
|
|
3868
4030
|
import { createHash as createHash2 } from "node:crypto";
|
|
3869
4031
|
|
|
3870
4032
|
// server/oauth/schemas.ts
|
|
3871
|
-
import { z as
|
|
3872
|
-
var oauthConnectSchema =
|
|
3873
|
-
plugin:
|
|
3874
|
-
name:
|
|
3875
|
-
client_id:
|
|
3876
|
-
client_secret:
|
|
4033
|
+
import { z as z24 } from "zod";
|
|
4034
|
+
var oauthConnectSchema = z24.strictObject({
|
|
4035
|
+
plugin: z24.uuid(),
|
|
4036
|
+
name: z24.string().trim().min(1).max(100),
|
|
4037
|
+
client_id: z24.string().trim().min(1).max(500),
|
|
4038
|
+
client_secret: z24.string().trim().min(1).max(2e3)
|
|
3877
4039
|
});
|
|
3878
|
-
var oauthCallbackSchema =
|
|
3879
|
-
state:
|
|
3880
|
-
code:
|
|
3881
|
-
error:
|
|
4040
|
+
var oauthCallbackSchema = z24.object({
|
|
4041
|
+
state: z24.string().optional(),
|
|
4042
|
+
code: z24.string().optional(),
|
|
4043
|
+
error: z24.string().optional()
|
|
3882
4044
|
});
|
|
3883
4045
|
|
|
3884
4046
|
// server/oauth/providers.ts
|
|
3885
|
-
import { and as
|
|
4047
|
+
import { and as and30, eq as eq41 } from "drizzle-orm";
|
|
3886
4048
|
var providers = {
|
|
3887
4049
|
"xero-oauth": {
|
|
3888
4050
|
authorization: "https://login.xero.com/identity/connect/authorize",
|
|
@@ -3955,9 +4117,9 @@ function authorize(ctx) {
|
|
|
3955
4117
|
return requireManager(ctx);
|
|
3956
4118
|
}
|
|
3957
4119
|
function checkedMetadata(plugin) {
|
|
3958
|
-
const
|
|
3959
|
-
const auth4 =
|
|
3960
|
-
if (plugin.distribution !== "external" ||
|
|
4120
|
+
const release2 = plugin.releaseMetadata;
|
|
4121
|
+
const auth4 = release2?.auth;
|
|
4122
|
+
if (plugin.distribution !== "external" || release2?.slug !== plugin.slug || release2?.version !== plugin.version || release2?.digest !== plugin.digest || release2?.package_url !== plugin.packageUrl || auth4?.type !== "oauth2" || !provider(auth4.provider) || !Array.isArray(auth4.scopes) || auth4.scopes.length > 100 || auth4.scopes.some(
|
|
3961
4123
|
(scope2) => typeof scope2 !== "string" || !scope2 || scope2.length > 500 || /[\s\x00-\x1f]/.test(scope2)
|
|
3962
4124
|
)) {
|
|
3963
4125
|
throw new ServiceError(
|
|
@@ -3972,9 +4134,9 @@ function checkedMetadata(plugin) {
|
|
|
3972
4134
|
}
|
|
3973
4135
|
function isCurrentManager(ctx, workspaceId, userId) {
|
|
3974
4136
|
const member = ctx.db.select().from(memberships).where(
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
4137
|
+
and30(
|
|
4138
|
+
eq41(memberships.workspaceId, workspaceId),
|
|
4139
|
+
eq41(memberships.userId, userId)
|
|
3978
4140
|
)
|
|
3979
4141
|
).get();
|
|
3980
4142
|
return member && ["owner", "admin"].includes(member.role);
|
|
@@ -3989,7 +4151,7 @@ var beginOAuthProcedure = browserSessionManagerProcedure.input(oauthConnectSchem
|
|
|
3989
4151
|
const clientId = field(input2.client_id, 500);
|
|
3990
4152
|
const clientSecret = field(input2.client_secret, 2e3);
|
|
3991
4153
|
const plugin = ctx.db.select().from(plugins).where(
|
|
3992
|
-
|
|
4154
|
+
and31(eq42(plugins.id, pluginId), eq42(plugins.workspaceId, workspace2.id))
|
|
3993
4155
|
).get();
|
|
3994
4156
|
if (!plugin) {
|
|
3995
4157
|
throw new ServiceError(
|
|
@@ -4021,8 +4183,8 @@ var beginOAuthProcedure = browserSessionManagerProcedure.input(oauthConnectSchem
|
|
|
4021
4183
|
);
|
|
4022
4184
|
}
|
|
4023
4185
|
ctx2.db.delete(oauthAttempts).where(
|
|
4024
|
-
|
|
4025
|
-
|
|
4186
|
+
and31(
|
|
4187
|
+
eq42(oauthAttempts.workspaceId, workspace2.id),
|
|
4026
4188
|
lt2(oauthAttempts.expiresAt, Date.now())
|
|
4027
4189
|
)
|
|
4028
4190
|
).run();
|
|
@@ -4058,33 +4220,33 @@ var beginOAuthProcedure = browserSessionManagerProcedure.input(oauthConnectSchem
|
|
|
4058
4220
|
});
|
|
4059
4221
|
|
|
4060
4222
|
// server/router/credentials/list.ts
|
|
4061
|
-
import { asc as asc2, eq as
|
|
4223
|
+
import { asc as asc2, eq as eq43 } from "drizzle-orm";
|
|
4062
4224
|
var listProcedure6 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
4063
|
-
const records = ctx.db.select(credentialPublicFields).from(credentials).where(
|
|
4225
|
+
const records = ctx.db.select(credentialPublicFields).from(credentials).where(eq43(credentials.workspaceId, ctx.workspace.id)).orderBy(asc2(credentials.name), asc2(credentials.id)).all();
|
|
4064
4226
|
return page(records);
|
|
4065
4227
|
});
|
|
4066
4228
|
|
|
4067
4229
|
// server/credentials/schemas.ts
|
|
4068
|
-
import { z as
|
|
4069
|
-
var credentialName =
|
|
4070
|
-
var credentialSecret =
|
|
4230
|
+
import { z as z25 } from "zod";
|
|
4231
|
+
var credentialName = z25.string().trim().min(1).max(100).refine((value) => !value.includes("\0"));
|
|
4232
|
+
var credentialSecret = z25.record(z25.string(), z25.json()).refine(
|
|
4071
4233
|
(secret) => Object.keys(secret).length > 0 && Buffer.byteLength(JSON.stringify(secret)) <= 32e3,
|
|
4072
4234
|
"Supply a nonempty secret object under 32KB."
|
|
4073
4235
|
);
|
|
4074
|
-
var credentialSchema =
|
|
4075
|
-
id:
|
|
4076
|
-
name:
|
|
4077
|
-
provider:
|
|
4236
|
+
var credentialSchema = z25.object({
|
|
4237
|
+
id: z25.uuid(),
|
|
4238
|
+
name: z25.string(),
|
|
4239
|
+
provider: z25.string()
|
|
4078
4240
|
});
|
|
4079
|
-
var credentialCreateSchema =
|
|
4241
|
+
var credentialCreateSchema = z25.strictObject({
|
|
4080
4242
|
name: credentialName,
|
|
4081
4243
|
provider: credentialName,
|
|
4082
4244
|
secret: credentialSecret
|
|
4083
4245
|
});
|
|
4084
4246
|
var updateCredentialSchema = credentialCreateSchema.partial();
|
|
4085
|
-
var credentialIdSchema =
|
|
4247
|
+
var credentialIdSchema = z25.strictObject({ id: z25.uuid() });
|
|
4086
4248
|
var credentialChangesSchema = updateCredentialSchema.extend({
|
|
4087
|
-
id:
|
|
4249
|
+
id: z25.uuid()
|
|
4088
4250
|
});
|
|
4089
4251
|
|
|
4090
4252
|
// server/router/credentials/get.ts
|
|
@@ -4118,7 +4280,7 @@ var createProcedure2 = browserManagerProcedure.input(credentialCreateSchema).mut
|
|
|
4118
4280
|
});
|
|
4119
4281
|
|
|
4120
4282
|
// server/router/credentials/update.ts
|
|
4121
|
-
import { and as
|
|
4283
|
+
import { and as and32, eq as eq44 } from "drizzle-orm";
|
|
4122
4284
|
var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mutation(({ ctx, input: input2 }) => {
|
|
4123
4285
|
const changes = {
|
|
4124
4286
|
...input2.name === void 0 ? {} : { name: input2.name },
|
|
@@ -4129,9 +4291,9 @@ var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mu
|
|
|
4129
4291
|
};
|
|
4130
4292
|
return inTransaction(ctx, (transaction) => {
|
|
4131
4293
|
const existing = transaction.db.select({ provider: credentials.provider }).from(credentials).where(
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4294
|
+
and32(
|
|
4295
|
+
eq44(credentials.workspaceId, ctx.workspace.id),
|
|
4296
|
+
eq44(credentials.id, input2.id)
|
|
4135
4297
|
)
|
|
4136
4298
|
).get();
|
|
4137
4299
|
if (input2.provider?.startsWith("mcp-") || existing?.provider.startsWith("mcp-") && (input2.provider !== void 0 || input2.secret !== void 0)) {
|
|
@@ -4141,9 +4303,9 @@ var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mu
|
|
|
4141
4303
|
);
|
|
4142
4304
|
}
|
|
4143
4305
|
const credential = transaction.db.update(credentials).set({ ...changes, updatedAt: now() }).where(
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4306
|
+
and32(
|
|
4307
|
+
eq44(credentials.workspaceId, ctx.workspace.id),
|
|
4308
|
+
eq44(credentials.id, input2.id)
|
|
4147
4309
|
)
|
|
4148
4310
|
).returning(credentialPublicFields).get();
|
|
4149
4311
|
if (!credential) {
|
|
@@ -4155,25 +4317,25 @@ var updateProcedure2 = browserManagerProcedure.input(credentialChangesSchema).mu
|
|
|
4155
4317
|
});
|
|
4156
4318
|
|
|
4157
4319
|
// server/router/credentials/delete.ts
|
|
4158
|
-
import { and as
|
|
4320
|
+
import { and as and33, eq as eq45 } from "drizzle-orm";
|
|
4159
4321
|
var deleteProcedure = browserManagerProcedure.input(credentialIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
4160
4322
|
inTransaction(ctx, (transaction) => {
|
|
4161
4323
|
if (!findCredential(transaction.db, ctx.workspace.id, input2.id)) {
|
|
4162
4324
|
throw new ServiceError("NOT_FOUND", "Credential not found.");
|
|
4163
4325
|
}
|
|
4164
4326
|
const dependentPlugin = transaction.db.select({ id: plugins.id }).from(plugins).where(
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4327
|
+
and33(
|
|
4328
|
+
eq45(plugins.workspaceId, ctx.workspace.id),
|
|
4329
|
+
eq45(plugins.credentialId, input2.id)
|
|
4168
4330
|
)
|
|
4169
4331
|
).limit(1).get();
|
|
4170
4332
|
if (dependentPlugin) {
|
|
4171
4333
|
throw new ServiceError("CONFLICT", "Credential is used by a plugin.");
|
|
4172
4334
|
}
|
|
4173
4335
|
transaction.db.delete(credentials).where(
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4336
|
+
and33(
|
|
4337
|
+
eq45(credentials.workspaceId, ctx.workspace.id),
|
|
4338
|
+
eq45(credentials.id, input2.id)
|
|
4177
4339
|
)
|
|
4178
4340
|
).run();
|
|
4179
4341
|
recordAudit(transaction, "credential", input2.id, "deleted");
|
|
@@ -4191,7 +4353,7 @@ var credentialsRouter = router({
|
|
|
4191
4353
|
});
|
|
4192
4354
|
|
|
4193
4355
|
// server/router/documents/list.ts
|
|
4194
|
-
import { eq as
|
|
4356
|
+
import { eq as eq46 } from "drizzle-orm";
|
|
4195
4357
|
|
|
4196
4358
|
// server/documents/views.ts
|
|
4197
4359
|
function documentView(row) {
|
|
@@ -4200,14 +4362,14 @@ function documentView(row) {
|
|
|
4200
4362
|
|
|
4201
4363
|
// server/router/documents/list.ts
|
|
4202
4364
|
var listProcedure7 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
4203
|
-
const records = ctx.db.select().from(documents).where(
|
|
4365
|
+
const records = ctx.db.select().from(documents).where(eq46(documents.workspaceId, ctx.workspace.id)).all();
|
|
4204
4366
|
return page(records.map((record) => documentView(record)));
|
|
4205
4367
|
});
|
|
4206
4368
|
|
|
4207
4369
|
// server/repositories/documents.ts
|
|
4208
|
-
import { and as
|
|
4370
|
+
import { and as and34, eq as eq47 } from "drizzle-orm";
|
|
4209
4371
|
function findDocument(database, workspaceId, id) {
|
|
4210
|
-
const record = database.select().from(documents).where(
|
|
4372
|
+
const record = database.select().from(documents).where(and34(eq47(documents.workspaceId, workspaceId), eq47(documents.id, id))).get();
|
|
4211
4373
|
if (!record) {
|
|
4212
4374
|
throw new ServiceError("NOT_FOUND", "Not found.");
|
|
4213
4375
|
}
|
|
@@ -4215,18 +4377,18 @@ function findDocument(database, workspaceId, id) {
|
|
|
4215
4377
|
}
|
|
4216
4378
|
|
|
4217
4379
|
// server/documents/schemas.ts
|
|
4218
|
-
import { z as
|
|
4219
|
-
var identifier3 =
|
|
4380
|
+
import { z as z26 } from "zod";
|
|
4381
|
+
var identifier3 = z26.uuid();
|
|
4220
4382
|
var documentFields = {
|
|
4221
|
-
kind:
|
|
4222
|
-
title:
|
|
4223
|
-
content:
|
|
4383
|
+
kind: z26.enum(["memory", "document"]),
|
|
4384
|
+
title: z26.string(),
|
|
4385
|
+
content: z26.string().max(2e5).refine((value) => !value.includes("\0"), "Invalid document.")
|
|
4224
4386
|
};
|
|
4225
|
-
var documentIdSchema =
|
|
4226
|
-
var createDocumentSchema =
|
|
4227
|
-
var updateDocumentSchema =
|
|
4387
|
+
var documentIdSchema = z26.strictObject({ id: identifier3 });
|
|
4388
|
+
var createDocumentSchema = z26.strictObject(documentFields);
|
|
4389
|
+
var updateDocumentSchema = z26.strictObject({
|
|
4228
4390
|
id: identifier3,
|
|
4229
|
-
...
|
|
4391
|
+
...z26.object(documentFields).partial().shape
|
|
4230
4392
|
});
|
|
4231
4393
|
|
|
4232
4394
|
// server/router/documents/get.ts
|
|
@@ -4248,7 +4410,7 @@ var createProcedure3 = browserWorkspaceProcedure.input(createDocumentSchema).mut
|
|
|
4248
4410
|
);
|
|
4249
4411
|
|
|
4250
4412
|
// server/router/documents/update.ts
|
|
4251
|
-
import { and as
|
|
4413
|
+
import { and as and35, eq as eq48 } from "drizzle-orm";
|
|
4252
4414
|
var updateProcedure3 = browserWorkspaceProcedure.input(updateDocumentSchema).mutation(({ ctx, input: input2 }) => {
|
|
4253
4415
|
return inTransaction(ctx, (ctx2) => {
|
|
4254
4416
|
const current = findDocument(ctx2.db, ctx2.workspace.id, input2.id);
|
|
@@ -4258,9 +4420,9 @@ var updateProcedure3 = browserWorkspaceProcedure.input(updateDocumentSchema).mut
|
|
|
4258
4420
|
content: input2.content ?? current.content,
|
|
4259
4421
|
updatedAt: now()
|
|
4260
4422
|
}).where(
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4423
|
+
and35(
|
|
4424
|
+
eq48(documents.workspaceId, ctx2.workspace.id),
|
|
4425
|
+
eq48(documents.id, input2.id)
|
|
4264
4426
|
)
|
|
4265
4427
|
).returning().get();
|
|
4266
4428
|
if (!document) {
|
|
@@ -4272,7 +4434,7 @@ var updateProcedure3 = browserWorkspaceProcedure.input(updateDocumentSchema).mut
|
|
|
4272
4434
|
});
|
|
4273
4435
|
|
|
4274
4436
|
// server/router/documents/delete.ts
|
|
4275
|
-
import { and as
|
|
4437
|
+
import { and as and36, eq as eq49 } from "drizzle-orm";
|
|
4276
4438
|
var deleteProcedure2 = browserWorkspaceProcedure.input(documentIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
4277
4439
|
return inTransaction(ctx, (ctx2) => {
|
|
4278
4440
|
findDocument(ctx2.db, ctx2.workspace.id, input2.id);
|
|
@@ -4287,9 +4449,9 @@ var deleteProcedure2 = browserWorkspaceProcedure.input(documentIdSchema).mutatio
|
|
|
4287
4449
|
});
|
|
4288
4450
|
}
|
|
4289
4451
|
const deleted = ctx2.db.delete(documents).where(
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4452
|
+
and36(
|
|
4453
|
+
eq49(documents.workspaceId, ctx2.workspace.id),
|
|
4454
|
+
eq49(documents.id, input2.id)
|
|
4293
4455
|
)
|
|
4294
4456
|
).returning({ id: documents.id }).get();
|
|
4295
4457
|
if (deleted) {
|
|
@@ -4308,36 +4470,76 @@ var documentsRouter = router({
|
|
|
4308
4470
|
delete: deleteProcedure2
|
|
4309
4471
|
});
|
|
4310
4472
|
|
|
4473
|
+
// server/router/plugins/shell-rules.ts
|
|
4474
|
+
import { asc as asc3, eq as eq50 } from "drizzle-orm";
|
|
4475
|
+
import { z as z27 } from "zod";
|
|
4476
|
+
var shellRulesProcedure = browserWorkspaceProcedure.input(z27.strictObject({ id: z27.uuid() })).query(({ ctx, input: input2 }) => {
|
|
4477
|
+
const plugin = pluginsRepository(ctx).find(input2.id);
|
|
4478
|
+
if (!supportsShellPolicy(plugin)) {
|
|
4479
|
+
throw new ServiceError(
|
|
4480
|
+
"BAD_REQUEST",
|
|
4481
|
+
"This plugin version does not support executable policies."
|
|
4482
|
+
);
|
|
4483
|
+
}
|
|
4484
|
+
return ctx.db.select({
|
|
4485
|
+
executable: shellRules.executable,
|
|
4486
|
+
decision: shellRules.decision
|
|
4487
|
+
}).from(shellRules).where(eq50(shellRules.pluginId, plugin.id)).orderBy(asc3(shellRules.executable)).all();
|
|
4488
|
+
});
|
|
4489
|
+
|
|
4490
|
+
// server/router/plugins/set-shell-rule.ts
|
|
4491
|
+
import { z as z28 } from "zod";
|
|
4492
|
+
var setShellRuleProcedure = browserManagerProcedure.input(
|
|
4493
|
+
z28.strictObject({
|
|
4494
|
+
id: z28.uuid(),
|
|
4495
|
+
executable: executableName,
|
|
4496
|
+
decision: ruleDecision
|
|
4497
|
+
})
|
|
4498
|
+
).mutation(
|
|
4499
|
+
({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
|
|
4500
|
+
assertCurrentPluginManager(transaction);
|
|
4501
|
+
const plugin = pluginsRepository(transaction).find(input2.id);
|
|
4502
|
+
if (!supportsShellPolicy(plugin)) {
|
|
4503
|
+
throw new ServiceError(
|
|
4504
|
+
"BAD_REQUEST",
|
|
4505
|
+
"This plugin version does not support executable policies."
|
|
4506
|
+
);
|
|
4507
|
+
}
|
|
4508
|
+
writeShellRule(transaction, plugin, input2.executable, input2.decision);
|
|
4509
|
+
return { saved: true };
|
|
4510
|
+
})
|
|
4511
|
+
);
|
|
4512
|
+
|
|
4311
4513
|
// server/router/plugins/mcp/begin-oauth.ts
|
|
4312
4514
|
import { auth as auth2, discoverOAuthServerInfo } from "@modelcontextprotocol/client";
|
|
4313
4515
|
|
|
4314
4516
|
// server/mcp/schemas.ts
|
|
4315
|
-
import { z as
|
|
4316
|
-
var connectionInputSchema =
|
|
4317
|
-
project:
|
|
4318
|
-
slug:
|
|
4517
|
+
import { z as z29 } from "zod";
|
|
4518
|
+
var connectionInputSchema = z29.strictObject({
|
|
4519
|
+
project: z29.uuid(),
|
|
4520
|
+
slug: z29.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/).max(50),
|
|
4319
4521
|
endpoint: endpointSchema,
|
|
4320
4522
|
transport: transportSchema.default("auto"),
|
|
4321
|
-
auth_mode:
|
|
4523
|
+
auth_mode: z29.enum(["none", "headers", "oauth"]).default("none"),
|
|
4322
4524
|
headers: headerSchema.optional()
|
|
4323
4525
|
});
|
|
4324
|
-
var connectionUpdateSchema =
|
|
4325
|
-
id:
|
|
4526
|
+
var connectionUpdateSchema = z29.strictObject({
|
|
4527
|
+
id: z29.uuid(),
|
|
4326
4528
|
endpoint: endpointSchema.optional(),
|
|
4327
4529
|
transport: transportSchema.optional(),
|
|
4328
|
-
auth_mode:
|
|
4530
|
+
auth_mode: z29.enum(["none", "headers", "oauth"]).optional(),
|
|
4329
4531
|
headers: headerSchema.optional()
|
|
4330
4532
|
});
|
|
4331
|
-
var catalogueAcceptSchema =
|
|
4332
|
-
id:
|
|
4333
|
-
run:
|
|
4334
|
-
tools:
|
|
4533
|
+
var catalogueAcceptSchema = z29.strictObject({
|
|
4534
|
+
id: z29.uuid(),
|
|
4535
|
+
run: z29.uuid(),
|
|
4536
|
+
tools: z29.array(z29.string()).max(1e3)
|
|
4335
4537
|
});
|
|
4336
|
-
var oauthBeginSchema =
|
|
4337
|
-
id:
|
|
4338
|
-
client_id:
|
|
4339
|
-
client_secret:
|
|
4340
|
-
client_metadata_url:
|
|
4538
|
+
var oauthBeginSchema = z29.strictObject({
|
|
4539
|
+
id: z29.uuid(),
|
|
4540
|
+
client_id: z29.string().max(2e3).optional(),
|
|
4541
|
+
client_secret: z29.string().max(4e3).optional(),
|
|
4542
|
+
client_metadata_url: z29.string().url().optional()
|
|
4341
4543
|
});
|
|
4342
4544
|
|
|
4343
4545
|
// server/router/plugins/mcp/begin-oauth.ts
|
|
@@ -4423,30 +4625,6 @@ function createHeaderCredential(ctx, name, headers) {
|
|
|
4423
4625
|
}).returning().get().id;
|
|
4424
4626
|
}
|
|
4425
4627
|
|
|
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
4628
|
// server/router/plugins/mcp/create.ts
|
|
4451
4629
|
var createProcedure4 = browserManagerProcedure.input(connectionInputSchema).mutation(
|
|
4452
4630
|
({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
|
|
@@ -4485,7 +4663,7 @@ var createProcedure4 = browserManagerProcedure.input(connectionInputSchema).muta
|
|
|
4485
4663
|
);
|
|
4486
4664
|
|
|
4487
4665
|
// server/router/plugins/mcp/update.ts
|
|
4488
|
-
import { eq as
|
|
4666
|
+
import { eq as eq51 } from "drizzle-orm";
|
|
4489
4667
|
var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mutation(
|
|
4490
4668
|
({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
|
|
4491
4669
|
assertCurrentPluginManager(transaction);
|
|
@@ -4513,12 +4691,12 @@ var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mut
|
|
|
4513
4691
|
discoveryRunId: null,
|
|
4514
4692
|
catalogue: [],
|
|
4515
4693
|
enabledTools: []
|
|
4516
|
-
}).where(
|
|
4694
|
+
}).where(eq51(mcpConnections.pluginId, input2.id)).run();
|
|
4517
4695
|
transaction.db.update(plugins).set({
|
|
4518
4696
|
enabled: false,
|
|
4519
4697
|
...credentialId ? { credentialId } : resetAuth ? { credentialId: null } : {},
|
|
4520
4698
|
updatedAt: now()
|
|
4521
|
-
}).where(
|
|
4699
|
+
}).where(eq51(plugins.id, input2.id)).run();
|
|
4522
4700
|
discardMcpCredential(transaction, replacedCredential);
|
|
4523
4701
|
recordAudit(transaction, "plugin", input2.id, "connection.updated");
|
|
4524
4702
|
return { id: input2.id };
|
|
@@ -4526,41 +4704,41 @@ var updateProcedure4 = browserManagerProcedure.input(connectionUpdateSchema).mut
|
|
|
4526
4704
|
);
|
|
4527
4705
|
|
|
4528
4706
|
// 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:
|
|
4707
|
+
import { z as z30 } from "zod";
|
|
4708
|
+
var pluginIdSchema = z30.strictObject({ id: z30.uuid() });
|
|
4709
|
+
var pluginCreateSchema = z30.strictObject({
|
|
4710
|
+
project: z30.uuid(),
|
|
4711
|
+
slug: z30.string(),
|
|
4712
|
+
version: z30.string(),
|
|
4713
|
+
description: z30.string().optional(),
|
|
4714
|
+
source: z30.string().optional(),
|
|
4715
|
+
distribution: z30.enum(["inline", "external"]).optional(),
|
|
4716
|
+
credential: z30.uuid().nullable().optional(),
|
|
4717
|
+
configuration: z30.json().optional(),
|
|
4718
|
+
enabled: z30.boolean().optional()
|
|
4719
|
+
});
|
|
4720
|
+
var pluginChangesSchema = pluginCreateSchema.omit({ slug: true }).partial().extend({ id: z30.uuid(), refresh_bundle: z30.boolean().optional() });
|
|
4543
4721
|
|
|
4544
4722
|
// server/router/plugins/mcp/get.ts
|
|
4545
|
-
import { and as
|
|
4723
|
+
import { and as and37, eq as eq52, gt as gt3 } from "drizzle-orm";
|
|
4546
4724
|
var getProcedure8 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx, input: input2 }) => {
|
|
4547
4725
|
const connection = mcpConnection(ctx, input2.id);
|
|
4548
|
-
const plugin = ctx.db.select().from(plugins).where(
|
|
4726
|
+
const plugin = ctx.db.select().from(plugins).where(eq52(plugins.id, connection.pluginId)).get();
|
|
4549
4727
|
const runner = plugin ? ctx.db.select({ protocolVersion: executors.protocolVersion }).from(executors).where(
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4728
|
+
and37(
|
|
4729
|
+
eq52(executors.workspaceId, ctx.workspace.id),
|
|
4730
|
+
eq52(executors.projectId, plugin.projectId),
|
|
4731
|
+
eq52(executors.enabled, true),
|
|
4732
|
+
gt3(
|
|
4555
4733
|
executors.lastSeenAt,
|
|
4556
4734
|
new Date(Date.now() - 6e4).toISOString()
|
|
4557
4735
|
)
|
|
4558
4736
|
)
|
|
4559
4737
|
).all() : [];
|
|
4560
4738
|
const run = connection.discoveryRunId ? ctx.db.select({ status: runs.status, error: runs.error }).from(runs).where(
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4739
|
+
and37(
|
|
4740
|
+
eq52(runs.id, connection.discoveryRunId),
|
|
4741
|
+
eq52(runs.workspaceId, ctx.workspace.id)
|
|
4564
4742
|
)
|
|
4565
4743
|
).get() : void 0;
|
|
4566
4744
|
return {
|
|
@@ -4573,18 +4751,18 @@ var getProcedure8 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx
|
|
|
4573
4751
|
});
|
|
4574
4752
|
|
|
4575
4753
|
// server/router/plugins/mcp/discover.ts
|
|
4576
|
-
import { and as
|
|
4754
|
+
import { and as and38, eq as eq53, gt as gt4 } from "drizzle-orm";
|
|
4577
4755
|
var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
|
|
4578
4756
|
({ ctx, input: input2 }) => inTransaction(ctx, (transaction) => {
|
|
4579
4757
|
assertCurrentPluginManager(transaction);
|
|
4580
4758
|
const plugin = pluginsRepository(transaction).find(input2.id);
|
|
4581
4759
|
const connection = mcpConnection(transaction, input2.id);
|
|
4582
4760
|
const workers = transaction.db.select().from(executors).where(
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4761
|
+
and38(
|
|
4762
|
+
eq53(executors.workspaceId, ctx.workspace.id),
|
|
4763
|
+
eq53(executors.projectId, plugin.projectId),
|
|
4764
|
+
eq53(executors.enabled, true),
|
|
4765
|
+
gt4(
|
|
4588
4766
|
executors.lastSeenAt,
|
|
4589
4767
|
new Date(Date.now() - 6e4).toISOString()
|
|
4590
4768
|
)
|
|
@@ -4606,16 +4784,16 @@ var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
|
|
|
4606
4784
|
}
|
|
4607
4785
|
if (connection.discoveryRunId) {
|
|
4608
4786
|
const previous = transaction.db.select().from(runs).where(
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4787
|
+
and38(
|
|
4788
|
+
eq53(runs.id, connection.discoveryRunId),
|
|
4789
|
+
eq53(runs.workspaceId, ctx.workspace.id)
|
|
4612
4790
|
)
|
|
4613
4791
|
).get();
|
|
4614
4792
|
if (previous && ["queued", "running"].includes(previous.status)) {
|
|
4615
4793
|
transaction.db.update(runs).set({
|
|
4616
4794
|
cancelRequested: true,
|
|
4617
4795
|
...previous.status === "queued" ? { status: "cancelled" } : {}
|
|
4618
|
-
}).where(
|
|
4796
|
+
}).where(eq53(runs.id, previous.id)).run();
|
|
4619
4797
|
}
|
|
4620
4798
|
}
|
|
4621
4799
|
const target = { ...mcpSnapshot(transaction, input2.id), tools: [] };
|
|
@@ -4647,14 +4825,14 @@ var discoverProcedure = browserManagerProcedure.input(pluginIdSchema).mutation(
|
|
|
4647
4825
|
]
|
|
4648
4826
|
}
|
|
4649
4827
|
}).returning().get();
|
|
4650
|
-
transaction.db.update(mcpConnections).set({ discoveryRunId: run.id, status: "checking", candidate: null }).where(
|
|
4828
|
+
transaction.db.update(mcpConnections).set({ discoveryRunId: run.id, status: "checking", candidate: null }).where(eq53(mcpConnections.pluginId, input2.id)).run();
|
|
4651
4829
|
recordAudit(transaction, "plugin", input2.id, "discovery.requested");
|
|
4652
4830
|
return { run: run.id };
|
|
4653
4831
|
})
|
|
4654
4832
|
);
|
|
4655
4833
|
|
|
4656
4834
|
// server/router/plugins/mcp/accept.ts
|
|
4657
|
-
import { eq as
|
|
4835
|
+
import { eq as eq54 } from "drizzle-orm";
|
|
4658
4836
|
|
|
4659
4837
|
// runtime/src/mcp/aliases.ts
|
|
4660
4838
|
import { createHash as createHash3 } from "node:crypto";
|
|
@@ -4737,13 +4915,13 @@ var acceptProcedure = browserManagerProcedure.input(catalogueAcceptSchema).mutat
|
|
|
4737
4915
|
candidate: null,
|
|
4738
4916
|
revision: revision3,
|
|
4739
4917
|
status: "ready"
|
|
4740
|
-
}).where(
|
|
4918
|
+
}).where(eq54(mcpConnections.pluginId, input2.id)).run();
|
|
4741
4919
|
transaction.db.update(plugins).set({
|
|
4742
4920
|
version: String(revision3),
|
|
4743
4921
|
digest: digest(JSON.stringify(catalogue)),
|
|
4744
4922
|
enabled: selected.size > 0,
|
|
4745
4923
|
updatedAt: now()
|
|
4746
|
-
}).where(
|
|
4924
|
+
}).where(eq54(plugins.id, input2.id)).run();
|
|
4747
4925
|
recordAudit(transaction, "plugin", input2.id, "catalogue.accepted");
|
|
4748
4926
|
return { id: input2.id, revision: revision3 };
|
|
4749
4927
|
})
|
|
@@ -4772,6 +4950,7 @@ var pluginView = (plugin) => {
|
|
|
4772
4950
|
enabled: plugin.enabled,
|
|
4773
4951
|
credential: plugin.credentialId,
|
|
4774
4952
|
distribution: plugin.distribution,
|
|
4953
|
+
shell_policy: supportsShellPolicy(plugin),
|
|
4775
4954
|
configuration: plugin.configuration,
|
|
4776
4955
|
package_url: plugin.packageUrl,
|
|
4777
4956
|
tools: plugin.releaseMetadata?.tools ?? null,
|
|
@@ -4795,59 +4974,59 @@ var getProcedure9 = browserWorkspaceProcedure.input(pluginIdSchema).query(({ ctx
|
|
|
4795
4974
|
});
|
|
4796
4975
|
|
|
4797
4976
|
// server/router/plugins/create.ts
|
|
4798
|
-
import { and as
|
|
4977
|
+
import { and as and39, eq as eq55 } from "drizzle-orm";
|
|
4799
4978
|
|
|
4800
4979
|
// server/plugins/catalog.ts
|
|
4801
|
-
import { z as
|
|
4980
|
+
import { z as z32 } from "zod";
|
|
4802
4981
|
|
|
4803
4982
|
// server/plugins/catalog-schemas.ts
|
|
4804
|
-
import { z as
|
|
4805
|
-
var jsonObject4 =
|
|
4806
|
-
var slug =
|
|
4807
|
-
var releaseSchema =
|
|
4983
|
+
import { z as z31 } from "zod";
|
|
4984
|
+
var jsonObject4 = z31.record(z31.string(), z31.json());
|
|
4985
|
+
var slug = z31.string().regex(/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/);
|
|
4986
|
+
var releaseSchema = z31.object({
|
|
4808
4987
|
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(
|
|
4988
|
+
version: z31.string().min(1).max(100),
|
|
4989
|
+
digest: z31.string().regex(/^[a-f0-9]{64}$/),
|
|
4990
|
+
package_url: z31.string(),
|
|
4991
|
+
display_name: z31.string(),
|
|
4992
|
+
description: z31.string(),
|
|
4993
|
+
category: z31.string(),
|
|
4994
|
+
documentation: z31.string(),
|
|
4995
|
+
distribution: z31.literal("external"),
|
|
4996
|
+
contract_version: z31.literal(1),
|
|
4997
|
+
auth: z31.object({
|
|
4998
|
+
type: z31.string().optional(),
|
|
4999
|
+
provider: z31.string().optional(),
|
|
5000
|
+
label: z31.string().optional(),
|
|
5001
|
+
hint: z31.string().optional(),
|
|
5002
|
+
scopes: z31.array(z31.string()).optional()
|
|
5003
|
+
}).catchall(z31.json()),
|
|
4825
5004
|
marketplace: jsonObject4,
|
|
4826
5005
|
configuration_schema: jsonObject4,
|
|
4827
|
-
tools:
|
|
4828
|
-
}).catchall(
|
|
4829
|
-
var marketplaceSchema =
|
|
4830
|
-
schema_version:
|
|
4831
|
-
plugins:
|
|
4832
|
-
|
|
5006
|
+
tools: z31.array(jsonObject4)
|
|
5007
|
+
}).catchall(z31.json());
|
|
5008
|
+
var marketplaceSchema = z31.object({
|
|
5009
|
+
schema_version: z31.literal(1),
|
|
5010
|
+
plugins: z31.array(
|
|
5011
|
+
z31.object({
|
|
4833
5012
|
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(
|
|
5013
|
+
display_name: z31.string(),
|
|
5014
|
+
description: z31.string(),
|
|
5015
|
+
category: z31.string(),
|
|
5016
|
+
permissions: z31.string(),
|
|
5017
|
+
source_version: z31.string(),
|
|
5018
|
+
source_url: z31.string(),
|
|
5019
|
+
url: z31.string(),
|
|
5020
|
+
release_status: z31.enum(["unreleased", "available"]),
|
|
5021
|
+
auth_type: z31.enum(["none", "token", "oauth2"]),
|
|
5022
|
+
tags: z31.array(z31.string()),
|
|
5023
|
+
use_cases: z31.array(z31.string())
|
|
5024
|
+
}).catchall(z31.json())
|
|
4846
5025
|
)
|
|
4847
5026
|
});
|
|
4848
5027
|
|
|
4849
5028
|
// server/plugins/catalog.ts
|
|
4850
|
-
import { readFileSync as
|
|
5029
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
4851
5030
|
async function fetchCatalogJson(address) {
|
|
4852
5031
|
let url;
|
|
4853
5032
|
try {
|
|
@@ -4896,7 +5075,7 @@ async function fetchCatalogJson(address) {
|
|
|
4896
5075
|
async function catalogEntries() {
|
|
4897
5076
|
let entries;
|
|
4898
5077
|
try {
|
|
4899
|
-
entries = process.env.PLUGIN_CATALOG_PATH ? JSON.parse(
|
|
5078
|
+
entries = process.env.PLUGIN_CATALOG_PATH ? JSON.parse(readFileSync4(process.env.PLUGIN_CATALOG_PATH, "utf8")) : process.env.PLUGIN_CATALOG_URL ?? "https://orgsdk.ai/plugins/releases.json" ? await fetchCatalogJson(
|
|
4900
5079
|
process.env.PLUGIN_CATALOG_URL ?? "https://orgsdk.ai/plugins/releases.json"
|
|
4901
5080
|
) : [];
|
|
4902
5081
|
} catch (error) {
|
|
@@ -4908,7 +5087,7 @@ async function catalogEntries() {
|
|
|
4908
5087
|
"Cannot read the configured plugin catalog."
|
|
4909
5088
|
);
|
|
4910
5089
|
}
|
|
4911
|
-
const result =
|
|
5090
|
+
const result = z32.array(releaseSchema).safeParse(entries);
|
|
4912
5091
|
if (!result.success) {
|
|
4913
5092
|
throw new ServiceError(
|
|
4914
5093
|
"PRECONDITION_FAILED",
|
|
@@ -4945,10 +5124,10 @@ async function catalogEntries() {
|
|
|
4945
5124
|
auth: jsonValue(entry.auth, "Authentication metadata")
|
|
4946
5125
|
}));
|
|
4947
5126
|
}
|
|
4948
|
-
async function catalogRelease(slug2,
|
|
5127
|
+
async function catalogRelease(slug2, version2) {
|
|
4949
5128
|
const entries = await catalogEntries();
|
|
4950
5129
|
const entry = entries.find(
|
|
4951
|
-
(entry2) => entry2?.slug === slug2 && entry2?.version ===
|
|
5130
|
+
(entry2) => entry2?.slug === slug2 && entry2?.version === version2
|
|
4952
5131
|
);
|
|
4953
5132
|
if (!entry) {
|
|
4954
5133
|
throw new ServiceError(
|
|
@@ -4966,9 +5145,9 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
|
|
|
4966
5145
|
if (!/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/.test(slug2)) {
|
|
4967
5146
|
throw new ServiceError("BAD_REQUEST", "Invalid plugin slug.");
|
|
4968
5147
|
}
|
|
4969
|
-
const
|
|
5148
|
+
const version2 = text2(input2.version, "version");
|
|
4970
5149
|
const distribution = input2.distribution ?? "inline";
|
|
4971
|
-
const metadata2 = distribution === "external" ? await catalogRelease(slug2,
|
|
5150
|
+
const metadata2 = distribution === "external" ? await catalogRelease(slug2, version2) : {};
|
|
4972
5151
|
const source = distribution === "inline" ? sourceText(input2.source) : "";
|
|
4973
5152
|
const configuration2 = jsonValue(input2.configuration ?? {}, "Configuration");
|
|
4974
5153
|
if (distribution === "external") {
|
|
@@ -4981,7 +5160,7 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
|
|
|
4981
5160
|
const values2 = {
|
|
4982
5161
|
projectId,
|
|
4983
5162
|
slug: slug2,
|
|
4984
|
-
version,
|
|
5163
|
+
version: version2,
|
|
4985
5164
|
distribution,
|
|
4986
5165
|
source,
|
|
4987
5166
|
configuration: configuration2,
|
|
@@ -5002,10 +5181,10 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
|
|
|
5002
5181
|
metadata2
|
|
5003
5182
|
);
|
|
5004
5183
|
const installedPlugin = transaction.db.select({ id: plugins.id }).from(plugins).where(
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5184
|
+
and39(
|
|
5185
|
+
eq55(plugins.workspaceId, context.workspace.id),
|
|
5186
|
+
eq55(plugins.projectId, projectId),
|
|
5187
|
+
eq55(plugins.slug, slug2)
|
|
5009
5188
|
)
|
|
5010
5189
|
).limit(1).get();
|
|
5011
5190
|
if (installedPlugin) {
|
|
@@ -5022,7 +5201,7 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
|
|
|
5022
5201
|
|
|
5023
5202
|
// server/router/plugins/update.ts
|
|
5024
5203
|
import { isDeepStrictEqual } from "node:util";
|
|
5025
|
-
import { and as
|
|
5204
|
+
import { and as and40, eq as eq56 } from "drizzle-orm";
|
|
5026
5205
|
var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutation(async ({ ctx: context, input: input2 }) => {
|
|
5027
5206
|
const { id, ...changes } = input2;
|
|
5028
5207
|
const originalPlugin = pluginsRepository(context).find(id);
|
|
@@ -5055,9 +5234,9 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5055
5234
|
"External plugin source is managed by its release."
|
|
5056
5235
|
);
|
|
5057
5236
|
}
|
|
5058
|
-
const
|
|
5059
|
-
const needsCatalogRelease = originalPlugin.distribution === "external" && (
|
|
5060
|
-
const metadata2 = needsCatalogRelease ? await catalogRelease(originalPlugin.slug,
|
|
5237
|
+
const version2 = text2(changes.version ?? originalPlugin.version, "version");
|
|
5238
|
+
const needsCatalogRelease = originalPlugin.distribution === "external" && (version2 !== originalPlugin.version || changes.refresh_bundle);
|
|
5239
|
+
const metadata2 = needsCatalogRelease ? await catalogRelease(originalPlugin.slug, version2) : originalPlugin.releaseMetadata;
|
|
5061
5240
|
return inTransaction(context, (transaction) => {
|
|
5062
5241
|
assertCurrentPluginManager(transaction);
|
|
5063
5242
|
const plugin = pluginsRepository(transaction).find(id);
|
|
@@ -5083,7 +5262,7 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5083
5262
|
"Configuration"
|
|
5084
5263
|
);
|
|
5085
5264
|
const source = plugin.distribution === "inline" && changes.source !== void 0 ? sourceText(changes.source) : plugin.source;
|
|
5086
|
-
if (source !== plugin.source &&
|
|
5265
|
+
if (source !== plugin.source && version2 === plugin.version) {
|
|
5087
5266
|
throw new ServiceError(
|
|
5088
5267
|
"BAD_REQUEST",
|
|
5089
5268
|
"Changed source requires a new version."
|
|
@@ -5099,7 +5278,7 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5099
5278
|
);
|
|
5100
5279
|
}
|
|
5101
5280
|
const updatedPlugin = transaction.db.update(plugins).set({
|
|
5102
|
-
version,
|
|
5281
|
+
version: version2,
|
|
5103
5282
|
source,
|
|
5104
5283
|
configuration: configuration2,
|
|
5105
5284
|
credentialId,
|
|
@@ -5110,9 +5289,9 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5110
5289
|
releaseMetadata: metadata2,
|
|
5111
5290
|
updatedAt: now()
|
|
5112
5291
|
}).where(
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5292
|
+
and40(
|
|
5293
|
+
eq56(plugins.workspaceId, context.workspace.id),
|
|
5294
|
+
eq56(plugins.id, id)
|
|
5116
5295
|
)
|
|
5117
5296
|
).returning().get();
|
|
5118
5297
|
if (!updatedPlugin) {
|
|
@@ -5124,15 +5303,15 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5124
5303
|
});
|
|
5125
5304
|
|
|
5126
5305
|
// server/router/plugins/delete.ts
|
|
5127
|
-
import { and as
|
|
5306
|
+
import { and as and41, eq as eq57 } from "drizzle-orm";
|
|
5128
5307
|
var deleteProcedure3 = browserManagerProcedure.input(pluginIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
5129
5308
|
inTransaction(ctx, (transaction) => {
|
|
5130
5309
|
assertCurrentPluginManager(transaction);
|
|
5131
5310
|
cancelConnectionRuns(transaction, input2.id);
|
|
5132
5311
|
const deletedPlugin = transaction.db.delete(plugins).where(
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5312
|
+
and41(
|
|
5313
|
+
eq57(plugins.workspaceId, ctx.workspace.id),
|
|
5314
|
+
eq57(plugins.id, input2.id)
|
|
5136
5315
|
)
|
|
5137
5316
|
).returning({ id: plugins.id, credentialId: plugins.credentialId }).get();
|
|
5138
5317
|
if (!deletedPlugin) {
|
|
@@ -5179,6 +5358,8 @@ var marketplaceProcedure = browserWorkspaceProcedure.query(
|
|
|
5179
5358
|
// server/router/plugins/index.ts
|
|
5180
5359
|
var pluginsRouter = router({
|
|
5181
5360
|
mcp: mcpRouter,
|
|
5361
|
+
shellRules: shellRulesProcedure,
|
|
5362
|
+
setShellRule: setShellRuleProcedure,
|
|
5182
5363
|
list: listProcedure8,
|
|
5183
5364
|
get: getProcedure9,
|
|
5184
5365
|
create: createProcedure5,
|
|
@@ -5189,39 +5370,39 @@ var pluginsRouter = router({
|
|
|
5189
5370
|
});
|
|
5190
5371
|
|
|
5191
5372
|
// server/router/projects/list.ts
|
|
5192
|
-
import { and as
|
|
5373
|
+
import { and as and43, eq as eq60 } from "drizzle-orm";
|
|
5193
5374
|
|
|
5194
5375
|
// server/projects/queries.ts
|
|
5195
|
-
import { and as
|
|
5376
|
+
import { and as and42, eq as eq58, inArray as inArray6, or as or3 } from "drizzle-orm";
|
|
5196
5377
|
function projectVisibility(database, workspaceId, grants2) {
|
|
5197
5378
|
if (!grants2) {
|
|
5198
5379
|
return void 0;
|
|
5199
5380
|
}
|
|
5200
5381
|
const grantedActionProjects = database.select({ projectId: actions.projectId }).from(actions).innerJoin(
|
|
5201
5382
|
actionVersions,
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5383
|
+
and42(
|
|
5384
|
+
eq58(actionVersions.actionId, actions.id),
|
|
5385
|
+
eq58(actionVersions.workspaceId, workspaceId)
|
|
5205
5386
|
)
|
|
5206
5387
|
).where(
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5388
|
+
and42(
|
|
5389
|
+
eq58(actions.workspaceId, workspaceId),
|
|
5390
|
+
inArray6(actionVersions.id, grants2.actionVersions)
|
|
5210
5391
|
)
|
|
5211
5392
|
);
|
|
5212
5393
|
return or3(
|
|
5213
|
-
|
|
5214
|
-
|
|
5394
|
+
inArray6(projects.id, grants2.projects),
|
|
5395
|
+
inArray6(projects.id, grantedActionProjects)
|
|
5215
5396
|
);
|
|
5216
5397
|
}
|
|
5217
5398
|
|
|
5218
5399
|
// server/projects/views.ts
|
|
5219
|
-
import { eq as
|
|
5400
|
+
import { eq as eq59 } from "drizzle-orm";
|
|
5220
5401
|
function serializeProject(ctx, row) {
|
|
5221
5402
|
const executor2 = executorsRepository(ctx).list(
|
|
5222
|
-
|
|
5403
|
+
eq59(executors.projectId, row.id)
|
|
5223
5404
|
)[0];
|
|
5224
|
-
const pluginIds = pluginsRepository(ctx).list(
|
|
5405
|
+
const pluginIds = pluginsRepository(ctx).list(eq59(plugins.projectId, row.id)).map((plugin) => plugin.id);
|
|
5225
5406
|
const minimal = {
|
|
5226
5407
|
id: row.id,
|
|
5227
5408
|
name: row.name,
|
|
@@ -5252,8 +5433,8 @@ function serializeProject(ctx, row) {
|
|
|
5252
5433
|
var listProcedure9 = scopedProcedure("catalog:read").query(
|
|
5253
5434
|
({ ctx }) => {
|
|
5254
5435
|
const projects2 = ctx.db.select().from(projects).where(
|
|
5255
|
-
|
|
5256
|
-
|
|
5436
|
+
and43(
|
|
5437
|
+
eq60(projects.workspaceId, ctx.workspace.id),
|
|
5257
5438
|
projectVisibility(ctx.db, ctx.workspace.id, ctx.token)
|
|
5258
5439
|
)
|
|
5259
5440
|
).all();
|
|
@@ -5262,12 +5443,12 @@ var listProcedure9 = scopedProcedure("catalog:read").query(
|
|
|
5262
5443
|
);
|
|
5263
5444
|
|
|
5264
5445
|
// server/router/projects/get.ts
|
|
5265
|
-
import { and as
|
|
5446
|
+
import { and as and44, eq as eq61 } from "drizzle-orm";
|
|
5266
5447
|
var getProcedure10 = scopedProcedure("catalog:read").input(projectIdSchema).query(({ ctx, input: input2 }) => {
|
|
5267
5448
|
const project = ctx.db.select().from(projects).where(
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
|
|
5449
|
+
and44(
|
|
5450
|
+
eq61(projects.workspaceId, ctx.workspace.id),
|
|
5451
|
+
eq61(projects.id, input2.id),
|
|
5271
5452
|
projectVisibility(ctx.db, ctx.workspace.id, ctx.token)
|
|
5272
5453
|
)
|
|
5273
5454
|
).get();
|
|
@@ -5278,12 +5459,12 @@ var getProcedure10 = scopedProcedure("catalog:read").input(projectIdSchema).quer
|
|
|
5278
5459
|
});
|
|
5279
5460
|
|
|
5280
5461
|
// server/repositories/workspace-tables.ts
|
|
5281
|
-
import { and as
|
|
5462
|
+
import { and as and45, eq as eq62 } from "drizzle-orm";
|
|
5282
5463
|
function findWorkspaceTable(database, workspaceId, id) {
|
|
5283
5464
|
const record = database.select().from(workspaceTables).where(
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5465
|
+
and45(
|
|
5466
|
+
eq62(workspaceTables.workspaceId, workspaceId),
|
|
5467
|
+
eq62(workspaceTables.id, id)
|
|
5287
5468
|
)
|
|
5288
5469
|
).get();
|
|
5289
5470
|
if (!record) {
|
|
@@ -5355,21 +5536,21 @@ var updateProcedure6 = browserManagerProcedure.input(projectChangesSchema).mutat
|
|
|
5355
5536
|
});
|
|
5356
5537
|
|
|
5357
5538
|
// server/router/projects/delete.ts
|
|
5358
|
-
import { and as
|
|
5539
|
+
import { and as and46, eq as eq63 } from "drizzle-orm";
|
|
5359
5540
|
var deleteProcedure4 = browserManagerProcedure.input(projectIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
5360
5541
|
inTransaction(ctx, (transaction) => {
|
|
5361
5542
|
const projects2 = projectsRepository(transaction);
|
|
5362
5543
|
projects2.find(input2.id);
|
|
5363
5544
|
const retainedRun = transaction.db.select({ id: runs.id }).from(runs).where(
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5545
|
+
and46(
|
|
5546
|
+
eq63(runs.workspaceId, ctx.workspace.id),
|
|
5547
|
+
eq63(runs.projectId, input2.id)
|
|
5367
5548
|
)
|
|
5368
5549
|
).limit(1).get();
|
|
5369
5550
|
const retainedAction = transaction.db.select({ id: actions.id }).from(actions).where(
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5551
|
+
and46(
|
|
5552
|
+
eq63(actions.workspaceId, ctx.workspace.id),
|
|
5553
|
+
eq63(actions.projectId, input2.id)
|
|
5373
5554
|
)
|
|
5374
5555
|
).limit(1).get();
|
|
5375
5556
|
if (retainedRun || retainedAction) {
|
|
@@ -5379,9 +5560,9 @@ var deleteProcedure4 = browserManagerProcedure.input(projectIdSchema).mutation((
|
|
|
5379
5560
|
);
|
|
5380
5561
|
}
|
|
5381
5562
|
const deleted = transaction.db.delete(projects).where(
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5563
|
+
and46(
|
|
5564
|
+
eq63(projects.workspaceId, ctx.workspace.id),
|
|
5565
|
+
eq63(projects.id, input2.id)
|
|
5385
5566
|
)
|
|
5386
5567
|
).returning({ id: projects.id }).get();
|
|
5387
5568
|
if (deleted) {
|
|
@@ -5401,20 +5582,20 @@ import { createHmac as createHmac2, randomUUID as randomUUID4 } from "node:crypt
|
|
|
5401
5582
|
|
|
5402
5583
|
// server/projects/executor.ts
|
|
5403
5584
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
5404
|
-
import { and as
|
|
5585
|
+
import { and as and47, eq as eq64, inArray as inArray7 } from "drizzle-orm";
|
|
5405
5586
|
function revokeExecutor(ctx, id) {
|
|
5406
5587
|
const workspaceId = requireWorkspace(ctx).id;
|
|
5407
5588
|
const worker = ctx.db.select().from(executors).where(
|
|
5408
|
-
|
|
5589
|
+
and47(eq64(executors.workspaceId, workspaceId), eq64(executors.projectId, id))
|
|
5409
5590
|
).get();
|
|
5410
5591
|
if (!worker) {
|
|
5411
5592
|
return;
|
|
5412
5593
|
}
|
|
5413
5594
|
const activeRuns = ctx.db.select().from(runs).where(
|
|
5414
|
-
|
|
5415
|
-
|
|
5416
|
-
|
|
5417
|
-
|
|
5595
|
+
and47(
|
|
5596
|
+
eq64(runs.workspaceId, workspaceId),
|
|
5597
|
+
eq64(runs.executorId, worker.id),
|
|
5598
|
+
inArray7(runs.status, ["running", "waiting_approval"])
|
|
5418
5599
|
)
|
|
5419
5600
|
).all();
|
|
5420
5601
|
for (const run of activeRuns) {
|
|
@@ -5426,10 +5607,10 @@ function revokeExecutor(ctx, id) {
|
|
|
5426
5607
|
leaseExpiresAt: null
|
|
5427
5608
|
});
|
|
5428
5609
|
const pendingApprovals = ctx.db.select().from(approvals).where(
|
|
5429
|
-
|
|
5430
|
-
|
|
5431
|
-
|
|
5432
|
-
|
|
5610
|
+
and47(
|
|
5611
|
+
eq64(approvals.workspaceId, workspaceId),
|
|
5612
|
+
eq64(approvals.runId, run.id),
|
|
5613
|
+
eq64(approvals.status, "pending")
|
|
5433
5614
|
)
|
|
5434
5615
|
).all();
|
|
5435
5616
|
for (const approval of pendingApprovals) {
|
|
@@ -5518,17 +5699,17 @@ var projectsRouter = router({
|
|
|
5518
5699
|
});
|
|
5519
5700
|
|
|
5520
5701
|
// server/router/runs/list.ts
|
|
5521
|
-
import { and as
|
|
5702
|
+
import { and as and48, desc as desc4, eq as eq65, inArray as inArray8, or as or4 } from "drizzle-orm";
|
|
5522
5703
|
var listProcedure10 = scopedProcedure("runs:read").query(({ ctx }) => {
|
|
5523
5704
|
const token = ctx.token;
|
|
5524
|
-
const grant = token ?
|
|
5525
|
-
|
|
5705
|
+
const grant = token ? and48(
|
|
5706
|
+
eq65(runs.tokenId, token.id),
|
|
5526
5707
|
or4(
|
|
5527
|
-
|
|
5528
|
-
|
|
5708
|
+
inArray8(runs.projectId, token.projects),
|
|
5709
|
+
inArray8(runs.actionVersionId, token.actionVersions)
|
|
5529
5710
|
)
|
|
5530
5711
|
) : void 0;
|
|
5531
|
-
const visibleRuns = ctx.db.select().from(runs).where(
|
|
5712
|
+
const visibleRuns = ctx.db.select().from(runs).where(and48(eq65(runs.workspaceId, ctx.workspace.id), grant)).orderBy(desc4(runs.createdAt)).all();
|
|
5532
5713
|
return page(visibleRuns.map(serializeRun));
|
|
5533
5714
|
});
|
|
5534
5715
|
|
|
@@ -5546,16 +5727,16 @@ var createProcedure7 = protectedProcedure.input(createRunSchema).mutation(({ ctx
|
|
|
5546
5727
|
});
|
|
5547
5728
|
|
|
5548
5729
|
// server/router/runs/events.ts
|
|
5549
|
-
import { and as
|
|
5730
|
+
import { and as and49, asc as asc4, eq as eq66 } from "drizzle-orm";
|
|
5550
5731
|
var eventsProcedure = scopedProcedure("runs:read").input(runIdSchema).query(({ ctx, input: input2 }) => {
|
|
5551
5732
|
const run = runsRepository(ctx).find(input2.id);
|
|
5552
5733
|
authorizeRunRead(ctx, run, null);
|
|
5553
5734
|
const events = ctx.db.select().from(runEvents).where(
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5735
|
+
and49(
|
|
5736
|
+
eq66(runEvents.workspaceId, ctx.workspace.id),
|
|
5737
|
+
eq66(runEvents.runId, input2.id)
|
|
5557
5738
|
)
|
|
5558
|
-
).orderBy(
|
|
5739
|
+
).orderBy(asc4(runEvents.sequence)).all();
|
|
5559
5740
|
return events.map((event) => ({
|
|
5560
5741
|
sequence: event.sequence,
|
|
5561
5742
|
kind: event.kind,
|
|
@@ -5590,11 +5771,11 @@ var retryProcedure = protectedProcedure.input(retryRunSchema).mutation(
|
|
|
5590
5771
|
}
|
|
5591
5772
|
scope(ctx2, required);
|
|
5592
5773
|
if (run.actionVersionId) {
|
|
5593
|
-
const
|
|
5774
|
+
const version2 = actionVersionsRepository(ctx2).find(run.actionVersionId);
|
|
5594
5775
|
authorizeVersion(
|
|
5595
5776
|
ctx2,
|
|
5596
|
-
actionsRepository(ctx2).find(
|
|
5597
|
-
|
|
5777
|
+
actionsRepository(ctx2).find(version2.actionId),
|
|
5778
|
+
version2,
|
|
5598
5779
|
true
|
|
5599
5780
|
);
|
|
5600
5781
|
} else {
|
|
@@ -5638,7 +5819,7 @@ var retryProcedure = protectedProcedure.input(retryRunSchema).mutation(
|
|
|
5638
5819
|
);
|
|
5639
5820
|
|
|
5640
5821
|
// server/router/runs/cancel.ts
|
|
5641
|
-
import { and as
|
|
5822
|
+
import { and as and50, eq as eq67 } from "drizzle-orm";
|
|
5642
5823
|
var cancelProcedure = scopedProcedure("runs:cancel").input(runIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
5643
5824
|
const id = input2.id;
|
|
5644
5825
|
const updated = inTransaction(ctx, (ctx2) => {
|
|
@@ -5652,10 +5833,10 @@ var cancelProcedure = scopedProcedure("runs:cancel").input(runIdSchema).mutation
|
|
|
5652
5833
|
cancelRequested: true
|
|
5653
5834
|
});
|
|
5654
5835
|
const pendingApprovals = ctx2.db.select().from(approvals).where(
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5836
|
+
and50(
|
|
5837
|
+
eq67(approvals.workspaceId, ctx2.workspace.id),
|
|
5838
|
+
eq67(approvals.runId, id),
|
|
5839
|
+
eq67(approvals.status, "pending")
|
|
5659
5840
|
)
|
|
5660
5841
|
).all();
|
|
5661
5842
|
for (const approval of pendingApprovals) {
|
|
@@ -5711,7 +5892,7 @@ var promoteProcedure = scopedProcedure(["runs:read", "actions:write"]).input(pro
|
|
|
5711
5892
|
|
|
5712
5893
|
// server/router/runs/stream.ts
|
|
5713
5894
|
import { setTimeout } from "node:timers/promises";
|
|
5714
|
-
import { and as
|
|
5895
|
+
import { and as and51, asc as asc5, eq as eq68, gt as gt5 } from "drizzle-orm";
|
|
5715
5896
|
var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscription(async function* ({ ctx, input: input2, signal }) {
|
|
5716
5897
|
const run = runsRepository(ctx).find(input2.id);
|
|
5717
5898
|
authorizeRunRead(ctx, run, null);
|
|
@@ -5721,9 +5902,9 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
|
|
|
5721
5902
|
return;
|
|
5722
5903
|
}
|
|
5723
5904
|
const membership = ctx.db.select().from(memberships).where(
|
|
5724
|
-
|
|
5725
|
-
|
|
5726
|
-
|
|
5905
|
+
and51(
|
|
5906
|
+
eq68(memberships.workspaceId, ctx.workspace.id),
|
|
5907
|
+
eq68(memberships.userId, ctx.userId)
|
|
5727
5908
|
)
|
|
5728
5909
|
).get();
|
|
5729
5910
|
if (!membership) {
|
|
@@ -5732,9 +5913,9 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
|
|
|
5732
5913
|
let currentContext = ctx;
|
|
5733
5914
|
if (ctx.token) {
|
|
5734
5915
|
const token = ctx.db.select().from(accessTokens).where(
|
|
5735
|
-
|
|
5736
|
-
|
|
5737
|
-
|
|
5916
|
+
and51(
|
|
5917
|
+
eq68(accessTokens.id, ctx.token.id),
|
|
5918
|
+
eq68(accessTokens.workspaceId, ctx.workspace.id)
|
|
5738
5919
|
)
|
|
5739
5920
|
).get();
|
|
5740
5921
|
if (!token || token.revoked) {
|
|
@@ -5754,12 +5935,12 @@ var streamProcedure = scopedProcedure("runs:read").input(streamRunSchema).subscr
|
|
|
5754
5935
|
}
|
|
5755
5936
|
const current = runsRepository(currentContext).find(input2.id);
|
|
5756
5937
|
const batch = currentContext.db.select().from(runEvents).where(
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5938
|
+
and51(
|
|
5939
|
+
eq68(runEvents.workspaceId, ctx.workspace.id),
|
|
5940
|
+
eq68(runEvents.runId, input2.id),
|
|
5941
|
+
gt5(runEvents.sequence, after)
|
|
5761
5942
|
)
|
|
5762
|
-
).orderBy(
|
|
5943
|
+
).orderBy(asc5(runEvents.sequence)).limit(100).all();
|
|
5763
5944
|
for (const event of batch) {
|
|
5764
5945
|
after = event.sequence;
|
|
5765
5946
|
yield {
|
|
@@ -5797,7 +5978,7 @@ var runsRouter = router({
|
|
|
5797
5978
|
});
|
|
5798
5979
|
|
|
5799
5980
|
// server/router/schedules/list.ts
|
|
5800
|
-
import { eq as
|
|
5981
|
+
import { eq as eq69 } from "drizzle-orm";
|
|
5801
5982
|
|
|
5802
5983
|
// server/automations/schedule-view.ts
|
|
5803
5984
|
function scheduleView(schedule) {
|
|
@@ -5813,21 +5994,21 @@ function scheduleView(schedule) {
|
|
|
5813
5994
|
|
|
5814
5995
|
// server/router/schedules/list.ts
|
|
5815
5996
|
var listProcedure11 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
5816
|
-
const records = ctx.db.select().from(schedules).where(
|
|
5997
|
+
const records = ctx.db.select().from(schedules).where(eq69(schedules.workspaceId, ctx.workspace.id)).all();
|
|
5817
5998
|
return page(records.map((record) => scheduleView(record)));
|
|
5818
5999
|
});
|
|
5819
6000
|
|
|
5820
6001
|
// server/router/schedules/get.ts
|
|
5821
|
-
import { z as
|
|
6002
|
+
import { z as z33 } from "zod";
|
|
5822
6003
|
|
|
5823
6004
|
// server/repositories/schedules.ts
|
|
5824
|
-
import { and as
|
|
6005
|
+
import { and as and52, eq as eq70 } from "drizzle-orm";
|
|
5825
6006
|
function schedulesRepository(context) {
|
|
5826
6007
|
const workspaceId = requireWorkspace(context).id;
|
|
5827
6008
|
return {
|
|
5828
6009
|
find(id) {
|
|
5829
6010
|
const record = context.db.select().from(schedules).where(
|
|
5830
|
-
|
|
6011
|
+
and52(eq70(schedules.workspaceId, workspaceId), eq70(schedules.id, id))
|
|
5831
6012
|
).get();
|
|
5832
6013
|
if (!record) {
|
|
5833
6014
|
throw new ServiceError("NOT_FOUND", "Not found.");
|
|
@@ -5838,21 +6019,21 @@ function schedulesRepository(context) {
|
|
|
5838
6019
|
}
|
|
5839
6020
|
|
|
5840
6021
|
// server/router/schedules/get.ts
|
|
5841
|
-
var getProcedure12 = browserWorkspaceProcedure.input(
|
|
6022
|
+
var getProcedure12 = browserWorkspaceProcedure.input(z33.object({ id: z33.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
|
|
5842
6023
|
const id = input2.id;
|
|
5843
6024
|
return scheduleView(schedulesRepository(context).find(id));
|
|
5844
6025
|
});
|
|
5845
6026
|
|
|
5846
6027
|
// server/automations/schedule-schemas.ts
|
|
5847
|
-
import { z as
|
|
5848
|
-
var scheduleFields =
|
|
5849
|
-
action:
|
|
5850
|
-
cron:
|
|
5851
|
-
inputs:
|
|
5852
|
-
enabled:
|
|
6028
|
+
import { z as z34 } from "zod";
|
|
6029
|
+
var scheduleFields = z34.object({
|
|
6030
|
+
action: z34.uuid(),
|
|
6031
|
+
cron: z34.string().trim().min(1).max(100),
|
|
6032
|
+
inputs: z34.json().optional(),
|
|
6033
|
+
enabled: z34.boolean().optional()
|
|
5853
6034
|
});
|
|
5854
6035
|
var scheduleCreateSchema = scheduleFields.strict();
|
|
5855
|
-
var scheduleUpdateSchema = scheduleFields.partial().extend({ id:
|
|
6036
|
+
var scheduleUpdateSchema = scheduleFields.partial().extend({ id: z34.uuid() }).strict();
|
|
5856
6037
|
|
|
5857
6038
|
// server/automations/cron.ts
|
|
5858
6039
|
import { CronExpressionParser } from "cron-parser";
|
|
@@ -5884,9 +6065,9 @@ var createProcedure8 = browserWorkspaceProcedure.input(scheduleCreateSchema).mut
|
|
|
5884
6065
|
if (!action.enabled) {
|
|
5885
6066
|
throw new ServiceError("BAD_REQUEST", "Action is disabled.");
|
|
5886
6067
|
}
|
|
5887
|
-
const
|
|
6068
|
+
const version2 = requireVersion(context2, action.id);
|
|
5888
6069
|
const inputs = jsonValue(input2.inputs ?? {}, "Inputs");
|
|
5889
|
-
validateContract(
|
|
6070
|
+
validateContract(version2.inputSchema, inputs);
|
|
5890
6071
|
const nextRunAt = nextCron(input2.cron);
|
|
5891
6072
|
const schedule = context2.db.insert(schedules).values({
|
|
5892
6073
|
...base(context2.workspace.id),
|
|
@@ -5903,7 +6084,7 @@ var createProcedure8 = browserWorkspaceProcedure.input(scheduleCreateSchema).mut
|
|
|
5903
6084
|
});
|
|
5904
6085
|
|
|
5905
6086
|
// server/router/schedules/update.ts
|
|
5906
|
-
import { and as
|
|
6087
|
+
import { and as and53, eq as eq71 } from "drizzle-orm";
|
|
5907
6088
|
var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mutation(({ ctx: context, input: input2 }) => {
|
|
5908
6089
|
return inTransaction(context, (context2) => {
|
|
5909
6090
|
const previous = schedulesRepository(context2).find(input2.id);
|
|
@@ -5913,9 +6094,9 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
|
|
|
5913
6094
|
if (!action.enabled) {
|
|
5914
6095
|
throw new ServiceError("BAD_REQUEST", "Action is disabled.");
|
|
5915
6096
|
}
|
|
5916
|
-
const
|
|
6097
|
+
const version2 = requireVersion(context2, action.id);
|
|
5917
6098
|
const inputs = jsonValue(input2.inputs ?? previous.inputs, "Inputs");
|
|
5918
|
-
validateContract(
|
|
6099
|
+
validateContract(version2.inputSchema, inputs);
|
|
5919
6100
|
const cron = input2.cron ?? previous.cron;
|
|
5920
6101
|
const nextRunAt = cron !== previous.cron || !previous.enabled && input2.enabled ? nextCron(cron) : previous.nextRunAt;
|
|
5921
6102
|
const schedule = context2.db.update(schedules).set({
|
|
@@ -5926,9 +6107,9 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
|
|
|
5926
6107
|
nextRunAt,
|
|
5927
6108
|
updatedAt: now()
|
|
5928
6109
|
}).where(
|
|
5929
|
-
|
|
5930
|
-
|
|
5931
|
-
|
|
6110
|
+
and53(
|
|
6111
|
+
eq71(schedules.workspaceId, context2.workspace.id),
|
|
6112
|
+
eq71(schedules.id, input2.id)
|
|
5932
6113
|
)
|
|
5933
6114
|
).returning().get();
|
|
5934
6115
|
if (!schedule) {
|
|
@@ -5940,15 +6121,15 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
|
|
|
5940
6121
|
});
|
|
5941
6122
|
|
|
5942
6123
|
// server/router/schedules/delete.ts
|
|
5943
|
-
import { and as
|
|
5944
|
-
import { z as
|
|
5945
|
-
var deleteProcedure5 = browserWorkspaceProcedure.input(
|
|
6124
|
+
import { and as and54, eq as eq72 } from "drizzle-orm";
|
|
6125
|
+
import { z as z35 } from "zod";
|
|
6126
|
+
var deleteProcedure5 = browserWorkspaceProcedure.input(z35.object({ id: z35.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
|
|
5946
6127
|
const id = input2.id;
|
|
5947
6128
|
return inTransaction(context, (context2) => {
|
|
5948
6129
|
const deleted = context2.db.delete(schedules).where(
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
6130
|
+
and54(
|
|
6131
|
+
eq72(schedules.workspaceId, context2.workspace.id),
|
|
6132
|
+
eq72(schedules.id, id)
|
|
5952
6133
|
)
|
|
5953
6134
|
).returning({ id: schedules.id }).get();
|
|
5954
6135
|
if (!deleted) {
|
|
@@ -5968,8 +6149,8 @@ var schedulesRouter = router({
|
|
|
5968
6149
|
});
|
|
5969
6150
|
|
|
5970
6151
|
// server/router/studio/approve.ts
|
|
5971
|
-
import { z as
|
|
5972
|
-
var approve = browserWorkspaceProcedure.input(
|
|
6152
|
+
import { z as z36 } from "zod";
|
|
6153
|
+
var approve = browserWorkspaceProcedure.input(z36.object({ challenge: z36.string().regex(/^[0-9a-f]{64}$/) }).strict()).mutation(({ ctx, input: input2 }) => {
|
|
5973
6154
|
if (ctx.studioOrigin || !ctx.sessionId || ctx.request.headers.get("origin") !== ctx.origin) {
|
|
5974
6155
|
throw new ServiceError(
|
|
5975
6156
|
"FORBIDDEN",
|
|
@@ -5997,9 +6178,9 @@ var discover = publicProcedure.query(({ ctx }) => {
|
|
|
5997
6178
|
});
|
|
5998
6179
|
|
|
5999
6180
|
// server/router/studio/exchange.ts
|
|
6000
|
-
import { z as
|
|
6181
|
+
import { z as z37 } from "zod";
|
|
6001
6182
|
var exchange = publicProcedure.input(
|
|
6002
|
-
|
|
6183
|
+
z37.object({ code: z37.string().length(43), verifier: z37.string().length(64) }).strict()
|
|
6003
6184
|
).mutation(({ ctx, input: input2 }) => {
|
|
6004
6185
|
if (!ctx.studioOrigin) {
|
|
6005
6186
|
throw new ServiceError("FORBIDDEN", "Open the configured dashboard.");
|
|
@@ -6016,6 +6197,127 @@ var exchange = publicProcedure.input(
|
|
|
6016
6197
|
// server/router/studio/index.ts
|
|
6017
6198
|
var studioRouter = router({ approve, discover, exchange });
|
|
6018
6199
|
|
|
6200
|
+
// server/platform/installation-update.ts
|
|
6201
|
+
import { inArray as inArray9 } from "drizzle-orm";
|
|
6202
|
+
var managerHeartbeat = /* @__PURE__ */ new WeakMap();
|
|
6203
|
+
var requested = /* @__PURE__ */ new WeakMap();
|
|
6204
|
+
function canManageUpdate(ctx) {
|
|
6205
|
+
return ctx.role === "owner" && !!ctx.sessionId && !ctx.token && process.env.ORGSDK_MANAGED_UPDATES === "1" && !!process.connected && isLoopbackInstallation(ctx.origin) && ctx.db.select({ id: workspaces.id }).from(workspaces).limit(2).all().length === 1;
|
|
6206
|
+
}
|
|
6207
|
+
function pendingUpdate(db) {
|
|
6208
|
+
return requested.get(db) ?? null;
|
|
6209
|
+
}
|
|
6210
|
+
function drainForUpdate(db, version2) {
|
|
6211
|
+
requested.set(db, version2);
|
|
6212
|
+
const timer = setInterval(() => {
|
|
6213
|
+
const busy = db.select({ id: runs.id }).from(runs).where(inArray9(runs.status, ["running", "waiting_approval"])).limit(1).get();
|
|
6214
|
+
if (busy) {
|
|
6215
|
+
return;
|
|
6216
|
+
}
|
|
6217
|
+
clearInterval(timer);
|
|
6218
|
+
if (!process.connected || !process.send) {
|
|
6219
|
+
requested.delete(db);
|
|
6220
|
+
return;
|
|
6221
|
+
}
|
|
6222
|
+
process.send({ update: version2 }, (error) => {
|
|
6223
|
+
if (error) {
|
|
6224
|
+
requested.delete(db);
|
|
6225
|
+
}
|
|
6226
|
+
});
|
|
6227
|
+
}, 1e3);
|
|
6228
|
+
timer.unref();
|
|
6229
|
+
}
|
|
6230
|
+
|
|
6231
|
+
// server/platform/stable-release.ts
|
|
6232
|
+
import { z as z38 } from "zod";
|
|
6233
|
+
var stableVersion = z38.string().max(32).regex(/^(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})\.(0|[1-9]\d{0,8})$/);
|
|
6234
|
+
function newerStable(candidate, installed) {
|
|
6235
|
+
if (!stableVersion.safeParse(candidate).success || !stableVersion.safeParse(installed).success) {
|
|
6236
|
+
return false;
|
|
6237
|
+
}
|
|
6238
|
+
const current = installed.split(".");
|
|
6239
|
+
for (const [index, part] of candidate.split(".").entries()) {
|
|
6240
|
+
const difference = Number(part) - Number(current[index]);
|
|
6241
|
+
if (difference !== 0) {
|
|
6242
|
+
return difference > 0;
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
6245
|
+
return false;
|
|
6246
|
+
}
|
|
6247
|
+
var release = z38.object({
|
|
6248
|
+
name: z38.literal("@orgsdk/cli"),
|
|
6249
|
+
version: stableVersion
|
|
6250
|
+
});
|
|
6251
|
+
var cached;
|
|
6252
|
+
var expires = 0;
|
|
6253
|
+
function latestStable() {
|
|
6254
|
+
if (cached && expires > Date.now()) {
|
|
6255
|
+
return cached;
|
|
6256
|
+
}
|
|
6257
|
+
expires = Date.now() + 60 * 6e4;
|
|
6258
|
+
cached = fetch("https://registry.npmjs.org/@orgsdk%2fcli/latest", {
|
|
6259
|
+
signal: AbortSignal.timeout(3500),
|
|
6260
|
+
redirect: "error"
|
|
6261
|
+
}).then(async (response) => {
|
|
6262
|
+
if (!response.ok) {
|
|
6263
|
+
throw new Error("Registry unavailable.");
|
|
6264
|
+
}
|
|
6265
|
+
return release.parse(await response.json()).version;
|
|
6266
|
+
}).catch(() => {
|
|
6267
|
+
expires = Date.now() + 6e4;
|
|
6268
|
+
return null;
|
|
6269
|
+
});
|
|
6270
|
+
return cached;
|
|
6271
|
+
}
|
|
6272
|
+
|
|
6273
|
+
// package.json
|
|
6274
|
+
var version = "2.3.0";
|
|
6275
|
+
|
|
6276
|
+
// server/router/system/update-status.ts
|
|
6277
|
+
var updateStatus = browserWorkspaceProcedure.query(async ({ ctx }) => {
|
|
6278
|
+
const latest = await latestStable();
|
|
6279
|
+
return {
|
|
6280
|
+
installed: version,
|
|
6281
|
+
available: latest && newerStable(latest, version) ? latest : null,
|
|
6282
|
+
executorReady: Date.now() - (managerHeartbeat.get(ctx.secrets) ?? 0) < 3e4,
|
|
6283
|
+
checked: latest !== null,
|
|
6284
|
+
automatic: canManageUpdate(ctx),
|
|
6285
|
+
pending: pendingUpdate(ctx.db),
|
|
6286
|
+
failed: process.env.ORGSDK_FAILED_UPDATE ?? null
|
|
6287
|
+
};
|
|
6288
|
+
});
|
|
6289
|
+
|
|
6290
|
+
// server/router/system/request-update.ts
|
|
6291
|
+
import { z as z39 } from "zod";
|
|
6292
|
+
var requestUpdate = browserOwnerProcedure.input(z39.object({ version: stableVersion }).strict()).mutation(async ({ ctx, input: input2 }) => {
|
|
6293
|
+
if (!canManageUpdate(ctx)) {
|
|
6294
|
+
throw new ServiceError(
|
|
6295
|
+
"FORBIDDEN",
|
|
6296
|
+
"This installation is managed outside Studio."
|
|
6297
|
+
);
|
|
6298
|
+
}
|
|
6299
|
+
const latest = await latestStable();
|
|
6300
|
+
if (latest !== input2.version || !newerStable(latest, version)) {
|
|
6301
|
+
throw new ServiceError("CONFLICT", "Check the available release again.");
|
|
6302
|
+
}
|
|
6303
|
+
const identity = identityRepository(ctx.db);
|
|
6304
|
+
const session = ctx.sessionId ? identity.session(ctx.sessionId) : void 0;
|
|
6305
|
+
if (!session || session.userId !== ctx.userId || session.expiresAt <= Date.now() || identity.membership(ctx.workspace.id, ctx.userId)?.role !== "owner" || !canManageUpdate(ctx)) {
|
|
6306
|
+
throw new ServiceError(
|
|
6307
|
+
"FORBIDDEN",
|
|
6308
|
+
"Sign in as the local workspace owner."
|
|
6309
|
+
);
|
|
6310
|
+
}
|
|
6311
|
+
const pending = pendingUpdate(ctx.db);
|
|
6312
|
+
if (pending && pending !== latest) {
|
|
6313
|
+
throw new ServiceError("CONFLICT", "Another update is in progress.");
|
|
6314
|
+
}
|
|
6315
|
+
if (!pending) {
|
|
6316
|
+
drainForUpdate(ctx.db, latest);
|
|
6317
|
+
}
|
|
6318
|
+
return { version: latest };
|
|
6319
|
+
});
|
|
6320
|
+
|
|
6019
6321
|
// server/router/system/health.ts
|
|
6020
6322
|
var healthProcedure = publicProcedure.query(() => ({
|
|
6021
6323
|
status: "ok",
|
|
@@ -6025,11 +6327,13 @@ var healthProcedure = publicProcedure.query(() => ({
|
|
|
6025
6327
|
|
|
6026
6328
|
// server/router/system/index.ts
|
|
6027
6329
|
var systemRouter = router({
|
|
6028
|
-
health: healthProcedure
|
|
6330
|
+
health: healthProcedure,
|
|
6331
|
+
updateStatus,
|
|
6332
|
+
requestUpdate
|
|
6029
6333
|
});
|
|
6030
6334
|
|
|
6031
6335
|
// server/router/tables/list.ts
|
|
6032
|
-
import { eq as
|
|
6336
|
+
import { eq as eq73 } from "drizzle-orm";
|
|
6033
6337
|
|
|
6034
6338
|
// server/tables/views.ts
|
|
6035
6339
|
function standard(row) {
|
|
@@ -6054,48 +6358,48 @@ function rowView(row) {
|
|
|
6054
6358
|
|
|
6055
6359
|
// server/router/tables/list.ts
|
|
6056
6360
|
var listProcedure12 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
6057
|
-
const records = ctx.db.select().from(workspaceTables).where(
|
|
6361
|
+
const records = ctx.db.select().from(workspaceTables).where(eq73(workspaceTables.workspaceId, ctx.workspace.id)).all();
|
|
6058
6362
|
return page(records.map((record) => standard(record)));
|
|
6059
6363
|
});
|
|
6060
6364
|
|
|
6061
6365
|
// server/tables/schemas.ts
|
|
6062
|
-
import { z as
|
|
6063
|
-
var identifier4 =
|
|
6064
|
-
var revision =
|
|
6065
|
-
var columns =
|
|
6066
|
-
|
|
6067
|
-
key:
|
|
6068
|
-
type:
|
|
6069
|
-
required:
|
|
6366
|
+
import { z as z40 } from "zod";
|
|
6367
|
+
var identifier4 = z40.uuid();
|
|
6368
|
+
var revision = z40.number().int().positive();
|
|
6369
|
+
var columns = z40.array(
|
|
6370
|
+
z40.strictObject({
|
|
6371
|
+
key: z40.string(),
|
|
6372
|
+
type: z40.enum(["text", "number", "boolean", "date"]),
|
|
6373
|
+
required: z40.boolean()
|
|
6070
6374
|
})
|
|
6071
6375
|
);
|
|
6072
|
-
var values =
|
|
6073
|
-
var tableIdSchema =
|
|
6074
|
-
var createTableSchema =
|
|
6075
|
-
var updateTableSchema =
|
|
6376
|
+
var values = z40.record(z40.string(), z40.json());
|
|
6377
|
+
var tableIdSchema = z40.strictObject({ id: identifier4 });
|
|
6378
|
+
var createTableSchema = z40.strictObject({ name: z40.string(), columns });
|
|
6379
|
+
var updateTableSchema = z40.strictObject({
|
|
6076
6380
|
id: identifier4,
|
|
6077
6381
|
revision,
|
|
6078
|
-
name:
|
|
6382
|
+
name: z40.string().optional(),
|
|
6079
6383
|
columns: columns.optional()
|
|
6080
6384
|
});
|
|
6081
|
-
var deleteTableSchema =
|
|
6082
|
-
var tableRowSchema =
|
|
6385
|
+
var deleteTableSchema = z40.strictObject({ id: identifier4, revision });
|
|
6386
|
+
var tableRowSchema = z40.strictObject({
|
|
6083
6387
|
id: identifier4,
|
|
6084
6388
|
rowId: identifier4
|
|
6085
6389
|
});
|
|
6086
|
-
var createRowSchema =
|
|
6390
|
+
var createRowSchema = z40.strictObject({
|
|
6087
6391
|
id: identifier4,
|
|
6088
6392
|
table_revision: revision,
|
|
6089
6393
|
values
|
|
6090
6394
|
});
|
|
6091
|
-
var updateRowSchema =
|
|
6395
|
+
var updateRowSchema = z40.strictObject({
|
|
6092
6396
|
id: identifier4,
|
|
6093
6397
|
rowId: identifier4,
|
|
6094
6398
|
table_revision: revision,
|
|
6095
6399
|
revision,
|
|
6096
6400
|
values
|
|
6097
6401
|
});
|
|
6098
|
-
var deleteRowSchema =
|
|
6402
|
+
var deleteRowSchema = z40.strictObject({
|
|
6099
6403
|
id: identifier4,
|
|
6100
6404
|
rowId: identifier4,
|
|
6101
6405
|
revision
|
|
@@ -6121,15 +6425,15 @@ var createProcedure9 = browserManagerProcedure.input(createTableSchema).mutation
|
|
|
6121
6425
|
);
|
|
6122
6426
|
|
|
6123
6427
|
// server/router/tables/update.ts
|
|
6124
|
-
import { and as
|
|
6428
|
+
import { and as and56, eq as eq75 } from "drizzle-orm";
|
|
6125
6429
|
|
|
6126
6430
|
// server/tables/queries.ts
|
|
6127
|
-
import { and as
|
|
6431
|
+
import { and as and55, eq as eq74 } from "drizzle-orm";
|
|
6128
6432
|
function rowsForTable(database, workspaceId, tableId2) {
|
|
6129
6433
|
return database.select().from(tableRows).where(
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6434
|
+
and55(
|
|
6435
|
+
eq74(tableRows.workspaceId, workspaceId),
|
|
6436
|
+
eq74(tableRows.tableId, tableId2)
|
|
6133
6437
|
)
|
|
6134
6438
|
).all();
|
|
6135
6439
|
}
|
|
@@ -6150,9 +6454,9 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
|
|
|
6150
6454
|
revision: current.revision + 1,
|
|
6151
6455
|
updatedAt: now()
|
|
6152
6456
|
}).where(
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6457
|
+
and56(
|
|
6458
|
+
eq75(workspaceTables.workspaceId, ctx2.workspace.id),
|
|
6459
|
+
eq75(workspaceTables.id, input2.id)
|
|
6156
6460
|
)
|
|
6157
6461
|
).returning().get();
|
|
6158
6462
|
if (!table) {
|
|
@@ -6165,14 +6469,14 @@ var updateProcedure8 = browserManagerProcedure.input(updateTableSchema).mutation
|
|
|
6165
6469
|
});
|
|
6166
6470
|
|
|
6167
6471
|
// server/router/tables/delete.ts
|
|
6168
|
-
import { and as
|
|
6472
|
+
import { and as and58, eq as eq77 } from "drizzle-orm";
|
|
6169
6473
|
|
|
6170
6474
|
// server/repositories/table-rows.ts
|
|
6171
|
-
import { and as
|
|
6475
|
+
import { and as and57, eq as eq76 } from "drizzle-orm";
|
|
6172
6476
|
function removeTableRow(context, id) {
|
|
6173
6477
|
const workspaceId = requireWorkspace(context).id;
|
|
6174
6478
|
inTransaction(context, (transaction) => {
|
|
6175
|
-
const deleted = transaction.db.delete(tableRows).where(
|
|
6479
|
+
const deleted = transaction.db.delete(tableRows).where(and57(eq76(tableRows.workspaceId, workspaceId), eq76(tableRows.id, id))).returning({ id: tableRows.id }).get();
|
|
6176
6480
|
if (deleted) {
|
|
6177
6481
|
recordAudit(transaction, "row", id, "deleted");
|
|
6178
6482
|
}
|
|
@@ -6200,9 +6504,9 @@ var deleteProcedure6 = browserManagerProcedure.input(deleteTableSchema).mutation
|
|
|
6200
6504
|
});
|
|
6201
6505
|
}
|
|
6202
6506
|
const deleted = ctx2.db.delete(workspaceTables).where(
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6507
|
+
and58(
|
|
6508
|
+
eq77(workspaceTables.workspaceId, ctx2.workspace.id),
|
|
6509
|
+
eq77(workspaceTables.id, input2.id)
|
|
6206
6510
|
)
|
|
6207
6511
|
).returning({ id: workspaceTables.id }).get();
|
|
6208
6512
|
if (deleted) {
|
|
@@ -6219,13 +6523,13 @@ var listRowsProcedure = browserWorkspaceProcedure.input(tableIdSchema).query(({
|
|
|
6219
6523
|
});
|
|
6220
6524
|
|
|
6221
6525
|
// server/tables/access.ts
|
|
6222
|
-
import { and as
|
|
6526
|
+
import { and as and59, eq as eq78 } from "drizzle-orm";
|
|
6223
6527
|
function rowInTable(database, workspaceId, tableId2, rowId) {
|
|
6224
6528
|
const row = database.select().from(tableRows).where(
|
|
6225
|
-
|
|
6226
|
-
|
|
6227
|
-
|
|
6228
|
-
|
|
6529
|
+
and59(
|
|
6530
|
+
eq78(tableRows.workspaceId, workspaceId),
|
|
6531
|
+
eq78(tableRows.tableId, tableId2),
|
|
6532
|
+
eq78(tableRows.id, rowId)
|
|
6229
6533
|
)
|
|
6230
6534
|
).get();
|
|
6231
6535
|
if (!row) {
|
|
@@ -6260,7 +6564,7 @@ var createRowProcedure = browserWorkspaceProcedure.input(createRowSchema).mutati
|
|
|
6260
6564
|
});
|
|
6261
6565
|
|
|
6262
6566
|
// server/router/tables/update-row.ts
|
|
6263
|
-
import { and as
|
|
6567
|
+
import { and as and60, eq as eq79 } from "drizzle-orm";
|
|
6264
6568
|
var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutation(({ ctx, input: input2 }) => {
|
|
6265
6569
|
return rowView(
|
|
6266
6570
|
inTransaction(ctx, (ctx2) => {
|
|
@@ -6274,9 +6578,9 @@ var updateRowProcedure = browserWorkspaceProcedure.input(updateRowSchema).mutati
|
|
|
6274
6578
|
revision: row.revision + 1,
|
|
6275
6579
|
updatedAt: now()
|
|
6276
6580
|
}).where(
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6581
|
+
and60(
|
|
6582
|
+
eq79(tableRows.workspaceId, ctx2.workspace.id),
|
|
6583
|
+
eq79(tableRows.id, input2.rowId)
|
|
6280
6584
|
)
|
|
6281
6585
|
).returning().get();
|
|
6282
6586
|
if (!updatedRow) {
|
|
@@ -6316,7 +6620,7 @@ var tablesRouter = router({
|
|
|
6316
6620
|
});
|
|
6317
6621
|
|
|
6318
6622
|
// server/router/tokens/list.ts
|
|
6319
|
-
import { eq as
|
|
6623
|
+
import { eq as eq80 } from "drizzle-orm";
|
|
6320
6624
|
|
|
6321
6625
|
// server/tokens/views.ts
|
|
6322
6626
|
function tokenView(row) {
|
|
@@ -6344,18 +6648,18 @@ function tokenView(row) {
|
|
|
6344
6648
|
|
|
6345
6649
|
// server/router/tokens/list.ts
|
|
6346
6650
|
var listProcedure13 = browserManagerProcedure.query(({ ctx }) => {
|
|
6347
|
-
const records = ctx.db.select().from(accessTokens).where(
|
|
6651
|
+
const records = ctx.db.select().from(accessTokens).where(eq80(accessTokens.workspaceId, ctx.workspace.id)).all();
|
|
6348
6652
|
return page(records.map((record) => tokenView(record)));
|
|
6349
6653
|
});
|
|
6350
6654
|
|
|
6351
6655
|
// server/router/tokens/get.ts
|
|
6352
|
-
import { and as
|
|
6353
|
-
import { z as
|
|
6354
|
-
var getProcedure14 = browserManagerProcedure.input(
|
|
6656
|
+
import { and as and61, eq as eq81 } from "drizzle-orm";
|
|
6657
|
+
import { z as z41 } from "zod";
|
|
6658
|
+
var getProcedure14 = browserManagerProcedure.input(z41.strictObject({ id: z41.uuid() })).query(({ ctx, input: input2 }) => {
|
|
6355
6659
|
const token = ctx.db.select().from(accessTokens).where(
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6660
|
+
and61(
|
|
6661
|
+
eq81(accessTokens.workspaceId, ctx.workspace.id),
|
|
6662
|
+
eq81(accessTokens.id, input2.id)
|
|
6359
6663
|
)
|
|
6360
6664
|
).get();
|
|
6361
6665
|
if (!token) {
|
|
@@ -6365,8 +6669,8 @@ var getProcedure14 = browserManagerProcedure.input(z36.strictObject({ id: z36.uu
|
|
|
6365
6669
|
});
|
|
6366
6670
|
|
|
6367
6671
|
// server/tokens/schemas.ts
|
|
6368
|
-
import { z as
|
|
6369
|
-
var clientScopes =
|
|
6672
|
+
import { z as z42 } from "zod";
|
|
6673
|
+
var clientScopes = z42.enum([
|
|
6370
6674
|
"catalog:read",
|
|
6371
6675
|
"code:execute",
|
|
6372
6676
|
"actions:write",
|
|
@@ -6375,11 +6679,11 @@ var clientScopes = z37.enum([
|
|
|
6375
6679
|
"runs:read",
|
|
6376
6680
|
"runs:cancel"
|
|
6377
6681
|
]);
|
|
6378
|
-
var tokenCreateSchema =
|
|
6379
|
-
name:
|
|
6380
|
-
scopes:
|
|
6381
|
-
projects:
|
|
6382
|
-
action_versions:
|
|
6682
|
+
var tokenCreateSchema = z42.object({
|
|
6683
|
+
name: z42.string().trim().min(1).max(100),
|
|
6684
|
+
scopes: z42.array(clientScopes).min(1),
|
|
6685
|
+
projects: z42.array(z42.uuid()).default([]),
|
|
6686
|
+
action_versions: z42.array(z42.uuid()).default([])
|
|
6383
6687
|
}).strict();
|
|
6384
6688
|
|
|
6385
6689
|
// server/router/tokens/create.ts
|
|
@@ -6418,14 +6722,14 @@ var createProcedure10 = browserManagerProcedure.input(tokenCreateSchema).output(
|
|
|
6418
6722
|
});
|
|
6419
6723
|
|
|
6420
6724
|
// server/router/tokens/revoke.ts
|
|
6421
|
-
import { and as
|
|
6422
|
-
import { z as
|
|
6423
|
-
var revokeProcedure = browserManagerProcedure.input(
|
|
6725
|
+
import { and as and62, eq as eq82 } from "drizzle-orm";
|
|
6726
|
+
import { z as z43 } from "zod";
|
|
6727
|
+
var revokeProcedure = browserManagerProcedure.input(z43.strictObject({ id: z43.uuid() })).mutation(({ ctx, input: input2 }) => {
|
|
6424
6728
|
return inTransaction(ctx, (ctx2) => {
|
|
6425
6729
|
const token = ctx2.db.update(accessTokens).set({ revoked: true, updatedAt: now() }).where(
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6730
|
+
and62(
|
|
6731
|
+
eq82(accessTokens.workspaceId, ctx2.workspace.id),
|
|
6732
|
+
eq82(accessTokens.id, input2.id)
|
|
6429
6733
|
)
|
|
6430
6734
|
).returning().get();
|
|
6431
6735
|
if (!token) {
|
|
@@ -6468,20 +6772,20 @@ var usersRouter = router({
|
|
|
6468
6772
|
});
|
|
6469
6773
|
|
|
6470
6774
|
// server/router/webhooks/list.ts
|
|
6471
|
-
import { eq as
|
|
6775
|
+
import { eq as eq84 } from "drizzle-orm";
|
|
6472
6776
|
|
|
6473
6777
|
// server/automations/webhook-view.ts
|
|
6474
|
-
import { desc as desc5, eq as
|
|
6475
|
-
import { and as
|
|
6778
|
+
import { desc as desc5, eq as eq83 } from "drizzle-orm";
|
|
6779
|
+
import { and as and63 } from "drizzle-orm";
|
|
6476
6780
|
function webhookView(context, webhook) {
|
|
6477
|
-
const
|
|
6781
|
+
const version2 = actionVersionsRepository(context).find(
|
|
6478
6782
|
webhook.actionVersionId
|
|
6479
6783
|
);
|
|
6480
|
-
const action = actionsRepository(context).find(
|
|
6784
|
+
const action = actionsRepository(context).find(version2.actionId);
|
|
6481
6785
|
const deliveries = context.db.select().from(webhookDeliveries).where(
|
|
6482
|
-
|
|
6483
|
-
|
|
6484
|
-
|
|
6786
|
+
and63(
|
|
6787
|
+
eq83(webhookDeliveries.workspaceId, workspace(context)),
|
|
6788
|
+
eq83(webhookDeliveries.webhookId, webhook.id)
|
|
6485
6789
|
)
|
|
6486
6790
|
).orderBy(desc5(webhookDeliveries.createdAt)).limit(20).all();
|
|
6487
6791
|
return {
|
|
@@ -6489,7 +6793,7 @@ function webhookView(context, webhook) {
|
|
|
6489
6793
|
name: webhook.name,
|
|
6490
6794
|
action_id: action.id,
|
|
6491
6795
|
action_name: action.name,
|
|
6492
|
-
version:
|
|
6796
|
+
version: version2.number,
|
|
6493
6797
|
enabled: webhook.enabled,
|
|
6494
6798
|
endpoint: `/webhooks/${webhook.id}`,
|
|
6495
6799
|
rotated_at: webhook.rotatedAt,
|
|
@@ -6510,19 +6814,19 @@ function webhookView(context, webhook) {
|
|
|
6510
6814
|
|
|
6511
6815
|
// server/router/webhooks/list.ts
|
|
6512
6816
|
var listProcedure14 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
6513
|
-
const records = ctx.db.select().from(webhooks).where(
|
|
6817
|
+
const records = ctx.db.select().from(webhooks).where(eq84(webhooks.workspaceId, ctx.workspace.id)).all();
|
|
6514
6818
|
return page(records.map((record) => webhookView(ctx, record)));
|
|
6515
6819
|
});
|
|
6516
6820
|
|
|
6517
6821
|
// server/router/webhooks/get.ts
|
|
6518
|
-
import { z as
|
|
6822
|
+
import { z as z44 } from "zod";
|
|
6519
6823
|
|
|
6520
6824
|
// server/repositories/webhooks.ts
|
|
6521
|
-
import { and as
|
|
6825
|
+
import { and as and64, eq as eq85 } from "drizzle-orm";
|
|
6522
6826
|
function webhooksRepository(context) {
|
|
6523
6827
|
const workspaceId = requireWorkspace(context).id;
|
|
6524
6828
|
const database = context.db;
|
|
6525
|
-
const scoped = (id) =>
|
|
6829
|
+
const scoped = (id) => and64(eq85(webhooks.workspaceId, workspaceId), eq85(webhooks.id, id));
|
|
6526
6830
|
return {
|
|
6527
6831
|
find(id) {
|
|
6528
6832
|
const row = database.select().from(webhooks).where(scoped(id)).get();
|
|
@@ -6546,28 +6850,28 @@ function webhooksRepository(context) {
|
|
|
6546
6850
|
}
|
|
6547
6851
|
|
|
6548
6852
|
// server/router/webhooks/get.ts
|
|
6549
|
-
var getProcedure15 = browserWorkspaceProcedure.input(
|
|
6853
|
+
var getProcedure15 = browserWorkspaceProcedure.input(z44.object({ id: z44.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
|
|
6550
6854
|
const id = input2.id;
|
|
6551
6855
|
return webhookView(context, webhooksRepository(context).find(id));
|
|
6552
6856
|
});
|
|
6553
6857
|
|
|
6554
6858
|
// server/automations/webhook-schemas.ts
|
|
6555
|
-
import { z as
|
|
6556
|
-
var webhookCreateSchema =
|
|
6557
|
-
name:
|
|
6558
|
-
action:
|
|
6559
|
-
enabled:
|
|
6859
|
+
import { z as z45 } from "zod";
|
|
6860
|
+
var webhookCreateSchema = z45.object({
|
|
6861
|
+
name: z45.string().trim().min(1).max(100),
|
|
6862
|
+
action: z45.uuid(),
|
|
6863
|
+
enabled: z45.boolean().optional()
|
|
6560
6864
|
}).strict();
|
|
6561
|
-
var webhookUpdateSchema =
|
|
6562
|
-
id:
|
|
6563
|
-
name:
|
|
6564
|
-
enabled:
|
|
6865
|
+
var webhookUpdateSchema = z45.object({
|
|
6866
|
+
id: z45.uuid(),
|
|
6867
|
+
name: z45.string().trim().min(1).max(100).optional(),
|
|
6868
|
+
enabled: z45.boolean().optional()
|
|
6565
6869
|
}).strict();
|
|
6566
6870
|
|
|
6567
6871
|
// server/router/webhooks/create.ts
|
|
6568
6872
|
var createProcedure11 = browserManagerProcedure.input(webhookCreateSchema).mutation(({ ctx: context, input: input2 }) => {
|
|
6569
6873
|
return inTransaction(context, (context2) => {
|
|
6570
|
-
const { action, version } = actionVersion(context2, input2.action);
|
|
6874
|
+
const { action, version: version2 } = actionVersion(context2, input2.action);
|
|
6571
6875
|
if (!action.enabled) {
|
|
6572
6876
|
throw new ServiceError(
|
|
6573
6877
|
"BAD_REQUEST",
|
|
@@ -6578,7 +6882,7 @@ var createProcedure11 = browserManagerProcedure.input(webhookCreateSchema).mutat
|
|
|
6578
6882
|
const webhook = context2.db.insert(webhooks).values({
|
|
6579
6883
|
...base(context2.workspace.id),
|
|
6580
6884
|
name: input2.name,
|
|
6581
|
-
actionVersionId:
|
|
6885
|
+
actionVersionId: version2.id,
|
|
6582
6886
|
actorId: context2.user.id,
|
|
6583
6887
|
secretHash: digest(secret),
|
|
6584
6888
|
enabled: input2.enabled ?? true,
|
|
@@ -6606,8 +6910,8 @@ var updateProcedure9 = browserManagerProcedure.input(webhookUpdateSchema).mutati
|
|
|
6606
6910
|
});
|
|
6607
6911
|
|
|
6608
6912
|
// server/router/webhooks/rotate.ts
|
|
6609
|
-
import { z as
|
|
6610
|
-
var rotateProcedure = browserManagerProcedure.input(
|
|
6913
|
+
import { z as z46 } from "zod";
|
|
6914
|
+
var rotateProcedure = browserManagerProcedure.input(z46.object({ id: z46.uuid() }).strict()).mutation(({ ctx: context, input: input2 }) => {
|
|
6611
6915
|
const id = input2.id;
|
|
6612
6916
|
return inTransaction(context, (context2) => {
|
|
6613
6917
|
const secret = randomSecret();
|
|
@@ -6637,7 +6941,7 @@ var listProcedure15 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6637
6941
|
});
|
|
6638
6942
|
|
|
6639
6943
|
// server/router/workspace/current.ts
|
|
6640
|
-
import { eq as
|
|
6944
|
+
import { eq as eq86 } from "drizzle-orm";
|
|
6641
6945
|
|
|
6642
6946
|
// server/workspaces/views.ts
|
|
6643
6947
|
var serializeInvite = (invitation) => ({
|
|
@@ -6656,34 +6960,34 @@ var currentProcedure = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6656
6960
|
workspace: { id: workspace2.id, name: workspace2.name },
|
|
6657
6961
|
role: ctx.role,
|
|
6658
6962
|
members: memberQuery(ctx.db, workspace2.id).all(),
|
|
6659
|
-
invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(
|
|
6963
|
+
invitations: ctx.role && ["owner", "admin"].includes(ctx.role) ? ctx.db.select().from(invitations).where(eq86(invitations.workspaceId, workspace2.id)).all().map(serializeInvite) : []
|
|
6660
6964
|
};
|
|
6661
6965
|
});
|
|
6662
6966
|
|
|
6663
6967
|
// server/router/workspace/update.ts
|
|
6664
|
-
import { eq as
|
|
6968
|
+
import { eq as eq87 } from "drizzle-orm";
|
|
6665
6969
|
|
|
6666
6970
|
// server/workspaces/schemas.ts
|
|
6667
|
-
import { z as
|
|
6668
|
-
var membershipIdSchema =
|
|
6669
|
-
id:
|
|
6971
|
+
import { z as z47 } from "zod";
|
|
6972
|
+
var membershipIdSchema = z47.strictObject({
|
|
6973
|
+
id: z47.number().int().positive()
|
|
6670
6974
|
});
|
|
6671
|
-
var workspaceNameSchema =
|
|
6672
|
-
name:
|
|
6975
|
+
var workspaceNameSchema = z47.strictObject({
|
|
6976
|
+
name: z47.string().trim().min(1).max(100)
|
|
6673
6977
|
});
|
|
6674
|
-
var roleSchema =
|
|
6978
|
+
var roleSchema = z47.enum(["admin", "member"]);
|
|
6675
6979
|
var memberUpdateSchema = membershipIdSchema.extend({
|
|
6676
6980
|
role: roleSchema
|
|
6677
6981
|
});
|
|
6678
|
-
var ownershipSchema =
|
|
6679
|
-
membership_id:
|
|
6982
|
+
var ownershipSchema = z47.strictObject({
|
|
6983
|
+
membership_id: z47.number().int().positive()
|
|
6680
6984
|
});
|
|
6681
|
-
var invitationSchema =
|
|
6985
|
+
var invitationSchema = z47.strictObject({
|
|
6682
6986
|
email: emailSchema,
|
|
6683
6987
|
role: roleSchema
|
|
6684
6988
|
});
|
|
6685
|
-
var invitationTokenSchema =
|
|
6686
|
-
token:
|
|
6989
|
+
var invitationTokenSchema = z47.strictObject({
|
|
6990
|
+
token: z47.string().min(1)
|
|
6687
6991
|
});
|
|
6688
6992
|
|
|
6689
6993
|
// server/router/workspace/update.ts
|
|
@@ -6700,7 +7004,7 @@ var updateProcedure10 = browserManagerProcedure.input(workspaceNameSchema).mutat
|
|
|
6700
7004
|
"Only workspace owners and admins can manage this workspace."
|
|
6701
7005
|
);
|
|
6702
7006
|
}
|
|
6703
|
-
const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(
|
|
7007
|
+
const updated = ctx2.db.update(workspaces).set({ name: name.trim() }).where(eq87(workspaces.id, workspace2.id)).returning().get();
|
|
6704
7008
|
return { id: updated.id, name: updated.name };
|
|
6705
7009
|
});
|
|
6706
7010
|
});
|
|
@@ -6728,13 +7032,13 @@ import { randomUUID as randomUUID5 } from "node:crypto";
|
|
|
6728
7032
|
import nodemailer from "nodemailer";
|
|
6729
7033
|
|
|
6730
7034
|
// server/repositories/mail-outbox.ts
|
|
6731
|
-
import { and as
|
|
7035
|
+
import { and as and65, asc as asc6, eq as eq88, isNull, lt as lt3, lte, or as or5 } from "drizzle-orm";
|
|
6732
7036
|
function enqueueMail(store, message) {
|
|
6733
7037
|
store.db.insert(mailOutbox).values({ ...message, nextAttempt: Date.now() }).run();
|
|
6734
7038
|
}
|
|
6735
7039
|
function revokeUnsentMail(store, id) {
|
|
6736
|
-
const unsent =
|
|
6737
|
-
|
|
7040
|
+
const unsent = and65(
|
|
7041
|
+
eq88(mailOutbox.id, id),
|
|
6738
7042
|
isNull(mailOutbox.sentAt),
|
|
6739
7043
|
isNull(mailOutbox.leaseUntil)
|
|
6740
7044
|
);
|
|
@@ -6746,29 +7050,29 @@ function claimMail(store, time) {
|
|
|
6746
7050
|
isNull(mailOutbox.leaseUntil),
|
|
6747
7051
|
lt3(mailOutbox.leaseUntil, time)
|
|
6748
7052
|
);
|
|
6749
|
-
const due =
|
|
7053
|
+
const due = and65(
|
|
6750
7054
|
isNull(mailOutbox.sentAt),
|
|
6751
7055
|
lte(mailOutbox.nextAttempt, time),
|
|
6752
7056
|
availableLease
|
|
6753
7057
|
);
|
|
6754
|
-
const row = store2.db.select().from(mailOutbox).where(due).orderBy(
|
|
7058
|
+
const row = store2.db.select().from(mailOutbox).where(due).orderBy(asc6(mailOutbox.nextAttempt)).limit(1).get();
|
|
6755
7059
|
if (!row) {
|
|
6756
7060
|
return;
|
|
6757
7061
|
}
|
|
6758
7062
|
if (row.id.startsWith("invitation:")) {
|
|
6759
7063
|
const id = Number(row.id.slice("invitation:".length));
|
|
6760
|
-
const invitation = store2.db.select().from(invitations).where(
|
|
7064
|
+
const invitation = store2.db.select().from(invitations).where(eq88(invitations.id, id)).get();
|
|
6761
7065
|
if (!invitation || invitation.acceptedAt || invitation.revokedAt || invitation.expiresAt <= new Date(time).toISOString()) {
|
|
6762
|
-
store2.db.delete(mailOutbox).where(
|
|
7066
|
+
store2.db.delete(mailOutbox).where(eq88(mailOutbox.id, row.id)).run();
|
|
6763
7067
|
return;
|
|
6764
7068
|
}
|
|
6765
7069
|
}
|
|
6766
|
-
store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(
|
|
7070
|
+
store2.db.update(mailOutbox).set({ leaseUntil: time + 12e4 }).where(eq88(mailOutbox.id, row.id)).run();
|
|
6767
7071
|
return row;
|
|
6768
7072
|
});
|
|
6769
7073
|
}
|
|
6770
7074
|
function markMailSent(store, id) {
|
|
6771
|
-
store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(
|
|
7075
|
+
store.db.update(mailOutbox).set({ sentAt: Date.now(), leaseUntil: null, body: "", lastError: null }).where(eq88(mailOutbox.id, id)).run();
|
|
6772
7076
|
}
|
|
6773
7077
|
function retryMail(store, job) {
|
|
6774
7078
|
const attempts = job.attempts + 1;
|
|
@@ -6778,7 +7082,7 @@ function retryMail(store, job) {
|
|
|
6778
7082
|
nextAttempt: Date.now() + delay,
|
|
6779
7083
|
leaseUntil: null,
|
|
6780
7084
|
lastError: "Delivery failed"
|
|
6781
|
-
}).where(
|
|
7085
|
+
}).where(eq88(mailOutbox.id, job.id)).run();
|
|
6782
7086
|
}
|
|
6783
7087
|
|
|
6784
7088
|
// server/mail/outbox.ts
|
|
@@ -6832,7 +7136,7 @@ async function flushOutbox(store, send) {
|
|
|
6832
7136
|
}
|
|
6833
7137
|
|
|
6834
7138
|
// server/router/workspace/invite.ts
|
|
6835
|
-
import { and as
|
|
7139
|
+
import { and as and66, eq as eq89, isNull as isNull2, sql as sql3 } from "drizzle-orm";
|
|
6836
7140
|
var inviteProcedure = browserManagerProcedure.input(invitationSchema).mutation(({ ctx, input: input2 }) => {
|
|
6837
7141
|
const user = ctx.user;
|
|
6838
7142
|
const workspace2 = ctx.workspace;
|
|
@@ -6870,10 +7174,10 @@ This invitation expires in seven days.`
|
|
|
6870
7174
|
"Only the owner can invite admins."
|
|
6871
7175
|
);
|
|
6872
7176
|
}
|
|
6873
|
-
const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users,
|
|
6874
|
-
|
|
6875
|
-
|
|
6876
|
-
|
|
7177
|
+
const existingMember = db.select({ id: memberships.id }).from(memberships).innerJoin(users, eq89(users.id, memberships.userId)).where(
|
|
7178
|
+
and66(
|
|
7179
|
+
eq89(memberships.workspaceId, workspace2.id),
|
|
7180
|
+
sql3`lower(${users.email}) = ${email}`
|
|
6877
7181
|
)
|
|
6878
7182
|
).get();
|
|
6879
7183
|
if (existingMember) {
|
|
@@ -6883,9 +7187,9 @@ This invitation expires in seven days.`
|
|
|
6883
7187
|
);
|
|
6884
7188
|
}
|
|
6885
7189
|
const prior = db.select({ id: invitations.id, expiresAt: invitations.expiresAt }).from(invitations).where(
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
7190
|
+
and66(
|
|
7191
|
+
eq89(invitations.workspaceId, workspace2.id),
|
|
7192
|
+
sql3`lower(${invitations.email}) = ${email}`,
|
|
6889
7193
|
isNull2(invitations.acceptedAt),
|
|
6890
7194
|
isNull2(invitations.revokedAt)
|
|
6891
7195
|
)
|
|
@@ -6919,7 +7223,7 @@ This invitation expires in seven days.`
|
|
|
6919
7223
|
});
|
|
6920
7224
|
|
|
6921
7225
|
// server/router/workspace/revoke-invitation.ts
|
|
6922
|
-
import { and as
|
|
7226
|
+
import { and as and67, eq as eq90 } from "drizzle-orm";
|
|
6923
7227
|
var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
6924
7228
|
const id = input2.id;
|
|
6925
7229
|
const user = ctx.user;
|
|
@@ -6934,9 +7238,9 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
|
|
|
6934
7238
|
);
|
|
6935
7239
|
}
|
|
6936
7240
|
const invitation = ctx2.db.select().from(invitations).where(
|
|
6937
|
-
|
|
6938
|
-
|
|
6939
|
-
|
|
7241
|
+
and67(
|
|
7242
|
+
eq90(invitations.workspaceId, workspace2.id),
|
|
7243
|
+
eq90(invitations.id, id)
|
|
6940
7244
|
)
|
|
6941
7245
|
).get();
|
|
6942
7246
|
if (!invitation) {
|
|
@@ -6957,7 +7261,7 @@ var revokeInvitationProcedure = browserManagerProcedure.input(membershipIdSchema
|
|
|
6957
7261
|
});
|
|
6958
7262
|
|
|
6959
7263
|
// server/router/workspace/accept-invitation.ts
|
|
6960
|
-
import { and as
|
|
7264
|
+
import { and as and68, eq as eq91 } from "drizzle-orm";
|
|
6961
7265
|
var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTokenSchema).mutation(({ ctx, input: input2 }) => {
|
|
6962
7266
|
const token = input2.token;
|
|
6963
7267
|
const user = ctx.user;
|
|
@@ -6969,9 +7273,9 @@ var acceptInvitationProcedure = authenticatedBrowserProcedure.input(invitationTo
|
|
|
6969
7273
|
throw new ServiceError("NOT_FOUND", "Invitation not found.");
|
|
6970
7274
|
}
|
|
6971
7275
|
const invite = db.select().from(invitations).where(
|
|
6972
|
-
|
|
6973
|
-
|
|
6974
|
-
|
|
7276
|
+
and68(
|
|
7277
|
+
eq91(invitations.workspaceId, workspace2.id),
|
|
7278
|
+
eq91(invitations.tokenDigest, digest(token))
|
|
6975
7279
|
)
|
|
6976
7280
|
).get();
|
|
6977
7281
|
if (!invite) {
|
|
@@ -7052,7 +7356,7 @@ var updateMemberProcedure = browserOwnerProcedure.input(memberUpdateSchema).muta
|
|
|
7052
7356
|
});
|
|
7053
7357
|
|
|
7054
7358
|
// server/router/workspace/remove-member.ts
|
|
7055
|
-
import { and as
|
|
7359
|
+
import { and as and69, eq as eq92 } from "drizzle-orm";
|
|
7056
7360
|
var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).mutation(({ ctx, input: input2 }) => {
|
|
7057
7361
|
const id = input2.id;
|
|
7058
7362
|
inTransaction(ctx, (ctx2) => {
|
|
@@ -7065,9 +7369,9 @@ var removeMemberProcedure = browserWorkspaceProcedure.input(membershipIdSchema).
|
|
|
7065
7369
|
);
|
|
7066
7370
|
}
|
|
7067
7371
|
ctx2.db.delete(memberships).where(
|
|
7068
|
-
|
|
7069
|
-
|
|
7070
|
-
|
|
7372
|
+
and69(
|
|
7373
|
+
eq92(memberships.workspaceId, target.workspaceId),
|
|
7374
|
+
eq92(memberships.id, id)
|
|
7071
7375
|
)
|
|
7072
7376
|
).run();
|
|
7073
7377
|
});
|
|
@@ -7138,8 +7442,8 @@ var appRouter = router({
|
|
|
7138
7442
|
// server/api/mcp-dispatch.ts
|
|
7139
7443
|
async function dispatchTool(context, name, toolInput) {
|
|
7140
7444
|
const caller = appRouter.createCaller(context);
|
|
7141
|
-
const id = () =>
|
|
7142
|
-
const actionId = () =>
|
|
7445
|
+
const id = () => z48.string().parse(toolInput.id);
|
|
7446
|
+
const actionId = () => z48.string().parse(toolInput.action);
|
|
7143
7447
|
const queueSession = (session) => caller.runs.session(
|
|
7144
7448
|
sessionRunSchema.parse({
|
|
7145
7449
|
project: toolInput.project,
|
|
@@ -7160,7 +7464,7 @@ async function dispatchTool(context, name, toolInput) {
|
|
|
7160
7464
|
};
|
|
7161
7465
|
}
|
|
7162
7466
|
case "get_project_sdk":
|
|
7163
|
-
return caller.projects.sdk({ id:
|
|
7467
|
+
return caller.projects.sdk({ id: z48.string().parse(toolInput.project) });
|
|
7164
7468
|
case "execute_code":
|
|
7165
7469
|
return caller.runs.create(
|
|
7166
7470
|
createRunSchema.strip().parse({ ...toolInput, operation: "code" })
|
|
@@ -7170,23 +7474,23 @@ async function dispatchTool(context, name, toolInput) {
|
|
|
7170
7474
|
case "execute_cell":
|
|
7171
7475
|
return queueSession({
|
|
7172
7476
|
operation: "execute",
|
|
7173
|
-
id:
|
|
7174
|
-
cellId:
|
|
7175
|
-
generation:
|
|
7176
|
-
expectedSequence:
|
|
7477
|
+
id: z48.uuid().parse(toolInput.session_id),
|
|
7478
|
+
cellId: z48.uuid().parse(toolInput.cell_id),
|
|
7479
|
+
generation: z48.number().parse(toolInput.generation),
|
|
7480
|
+
expectedSequence: z48.number().parse(toolInput.expected_sequence),
|
|
7177
7481
|
after: toolInput.after
|
|
7178
7482
|
});
|
|
7179
7483
|
case "read_session":
|
|
7180
7484
|
return queueSession({
|
|
7181
7485
|
operation: "read",
|
|
7182
|
-
id:
|
|
7486
|
+
id: z48.uuid().parse(toolInput.session_id),
|
|
7183
7487
|
after: toolInput.after,
|
|
7184
7488
|
limit: toolInput.limit
|
|
7185
7489
|
});
|
|
7186
7490
|
case "close_session":
|
|
7187
7491
|
return queueSession({
|
|
7188
7492
|
operation: "close",
|
|
7189
|
-
id:
|
|
7493
|
+
id: z48.uuid().parse(toolInput.session_id)
|
|
7190
7494
|
});
|
|
7191
7495
|
case "get_run_events": {
|
|
7192
7496
|
const all = await caller.runs.events({ id: id() });
|
|
@@ -7263,17 +7567,17 @@ async function dispatchTool(context, name, toolInput) {
|
|
|
7263
7567
|
}
|
|
7264
7568
|
|
|
7265
7569
|
// 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(
|
|
7570
|
+
import { z as z49 } from "zod";
|
|
7571
|
+
var mcpArgumentsSchema = z49.object({
|
|
7572
|
+
action: z49.string().optional(),
|
|
7573
|
+
project: z49.string().optional(),
|
|
7574
|
+
id: z49.string().optional(),
|
|
7575
|
+
version: z49.number().optional(),
|
|
7576
|
+
suite_revision: z49.number().optional(),
|
|
7577
|
+
after: z49.number().optional(),
|
|
7578
|
+
offset: z49.number().optional(),
|
|
7579
|
+
limit: z49.number().optional()
|
|
7580
|
+
}).catchall(z49.json());
|
|
7277
7581
|
|
|
7278
7582
|
// server/api/mcp.ts
|
|
7279
7583
|
import Ajv2 from "ajv";
|
|
@@ -7933,8 +8237,8 @@ async function handleMcp(ctx) {
|
|
|
7933
8237
|
if (ctx.request.method !== "POST") {
|
|
7934
8238
|
return new Response(null, { status: 405, headers: { Allow: "POST" } });
|
|
7935
8239
|
}
|
|
7936
|
-
const
|
|
7937
|
-
if (
|
|
8240
|
+
const version2 = ctx.request.headers.get("mcp-protocol-version");
|
|
8241
|
+
if (version2 && version2 !== "2025-03-26") {
|
|
7938
8242
|
throw new HttpError(400, "Unsupported MCP protocol version.");
|
|
7939
8243
|
}
|
|
7940
8244
|
if (ctx.request.headers.get("content-type")?.split(";")[0] !== "application/json") {
|
|
@@ -8024,18 +8328,18 @@ async function handleMcp(ctx) {
|
|
|
8024
8328
|
}
|
|
8025
8329
|
|
|
8026
8330
|
// server/automations/ingress.ts
|
|
8027
|
-
import { z as
|
|
8028
|
-
import { and as
|
|
8331
|
+
import { z as z50 } from "zod";
|
|
8332
|
+
import { and as and71, eq as eq94 } from "drizzle-orm";
|
|
8029
8333
|
import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
8030
8334
|
|
|
8031
8335
|
// server/repositories/webhook-deliveries.ts
|
|
8032
|
-
import { and as
|
|
8336
|
+
import { and as and70, eq as eq93 } from "drizzle-orm";
|
|
8033
8337
|
function webhookDeliveriesRepository(context) {
|
|
8034
8338
|
const workspaceId = requireWorkspace(context).id;
|
|
8035
8339
|
const database = context.db;
|
|
8036
|
-
const scoped = (id, filter) =>
|
|
8037
|
-
|
|
8038
|
-
id === void 0 ? void 0 :
|
|
8340
|
+
const scoped = (id, filter) => and70(
|
|
8341
|
+
eq93(webhookDeliveries.workspaceId, workspaceId),
|
|
8342
|
+
id === void 0 ? void 0 : eq93(webhookDeliveries.id, id),
|
|
8039
8343
|
filter
|
|
8040
8344
|
);
|
|
8041
8345
|
return {
|
|
@@ -8063,7 +8367,7 @@ async function handleWebhookIngress(ctx) {
|
|
|
8063
8367
|
if (ctx.request.method !== "POST") {
|
|
8064
8368
|
throw new HttpError(405, "Method not allowed.");
|
|
8065
8369
|
}
|
|
8066
|
-
const hook = ctx.db.select().from(webhooks).where(
|
|
8370
|
+
const hook = ctx.db.select().from(webhooks).where(eq94(webhooks.id, match[1])).get();
|
|
8067
8371
|
if (!hook || !ctx.workspace || hook.workspaceId !== ctx.workspace.id) {
|
|
8068
8372
|
throw new HttpError(404, "Webhook not found.");
|
|
8069
8373
|
}
|
|
@@ -8098,9 +8402,9 @@ async function handleWebhookIngress(ctx) {
|
|
|
8098
8402
|
jsonValue(payload.inputs, "Inputs");
|
|
8099
8403
|
const actor = identityRepository(ctx.db).user(hook.actorId);
|
|
8100
8404
|
const member = ctx.db.select().from(memberships).where(
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8405
|
+
and71(
|
|
8406
|
+
eq94(memberships.userId, hook.actorId),
|
|
8407
|
+
eq94(memberships.workspaceId, hook.workspaceId)
|
|
8104
8408
|
)
|
|
8105
8409
|
).get();
|
|
8106
8410
|
if (!hook.enabled || !actor || !member) {
|
|
@@ -8112,8 +8416,8 @@ async function handleWebhookIngress(ctx) {
|
|
|
8112
8416
|
role: member.role,
|
|
8113
8417
|
token: null
|
|
8114
8418
|
};
|
|
8115
|
-
const
|
|
8116
|
-
const action = actionsRepository(actorCtx).find(
|
|
8419
|
+
const version2 = actionVersionsRepository(actorCtx).find(hook.actionVersionId);
|
|
8420
|
+
const action = actionsRepository(actorCtx).find(version2.actionId);
|
|
8117
8421
|
const hash = digest(canonicalJson(payload));
|
|
8118
8422
|
return inTransaction(actorCtx, (actorCtx2) => {
|
|
8119
8423
|
const current = webhooksRepository(actorCtx2).find(hook.id);
|
|
@@ -8121,9 +8425,9 @@ async function handleWebhookIngress(ctx) {
|
|
|
8121
8425
|
throw new HttpError(403, "Webhook is unavailable.");
|
|
8122
8426
|
}
|
|
8123
8427
|
const old = webhookDeliveriesRepository(actorCtx2).list(
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8428
|
+
and71(
|
|
8429
|
+
eq94(webhookDeliveries.webhookId, hook.id),
|
|
8430
|
+
eq94(webhookDeliveries.deliveryId, delivery)
|
|
8127
8431
|
)
|
|
8128
8432
|
)[0];
|
|
8129
8433
|
if (old) {
|
|
@@ -8142,8 +8446,8 @@ async function handleWebhookIngress(ctx) {
|
|
|
8142
8446
|
project: action.projectId,
|
|
8143
8447
|
operation: "action",
|
|
8144
8448
|
action: action.id,
|
|
8145
|
-
version:
|
|
8146
|
-
inputs:
|
|
8449
|
+
version: version2.number,
|
|
8450
|
+
inputs: z50.record(z50.string(), z50.json()).parse(payload.inputs),
|
|
8147
8451
|
idempotency_key: `webhook:${hook.id}:${delivery}`
|
|
8148
8452
|
});
|
|
8149
8453
|
runsRepository(actorCtx2).update(run.id, {
|
|
@@ -8166,7 +8470,7 @@ async function handleWebhookIngress(ctx) {
|
|
|
8166
8470
|
}
|
|
8167
8471
|
|
|
8168
8472
|
// server/execution/authority.ts
|
|
8169
|
-
import { and as
|
|
8473
|
+
import { and as and72, eq as eq95 } from "drizzle-orm";
|
|
8170
8474
|
import { timingSafeEqual as timingSafeEqual3 } from "node:crypto";
|
|
8171
8475
|
var terminal = /* @__PURE__ */ new Set([
|
|
8172
8476
|
"succeeded",
|
|
@@ -8184,15 +8488,15 @@ function bearer(ctx) {
|
|
|
8184
8488
|
}
|
|
8185
8489
|
function executor(ctx) {
|
|
8186
8490
|
const row = ctx.db.select().from(executors).where(
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8491
|
+
and72(
|
|
8492
|
+
eq95(executors.tokenHash, digest(bearer(ctx))),
|
|
8493
|
+
eq95(executors.enabled, true)
|
|
8190
8494
|
)
|
|
8191
8495
|
).get();
|
|
8192
8496
|
const project = row && ctx.db.select().from(projects).where(
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8497
|
+
and72(
|
|
8498
|
+
eq95(projects.id, row.projectId),
|
|
8499
|
+
eq95(projects.workspaceId, row.workspaceId)
|
|
8196
8500
|
)
|
|
8197
8501
|
).get();
|
|
8198
8502
|
if (!row || !project?.enabled) {
|
|
@@ -8201,17 +8505,17 @@ function executor(ctx) {
|
|
|
8201
8505
|
return row;
|
|
8202
8506
|
}
|
|
8203
8507
|
function runCapability(ctx, expectedId) {
|
|
8204
|
-
const run = ctx.db.select().from(runs).where(
|
|
8508
|
+
const run = ctx.db.select().from(runs).where(eq95(runs.capabilityHash, digest(bearer(ctx)))).get();
|
|
8205
8509
|
const currentTime = now();
|
|
8206
8510
|
if (!run || expectedId && run.id !== expectedId || !run.deadline || run.deadline <= currentTime || !run.leaseExpiresAt || run.leaseExpiresAt <= currentTime) {
|
|
8207
8511
|
throw new HttpError(401, "Invalid or expired run capability.");
|
|
8208
8512
|
}
|
|
8209
|
-
const worker = run.executorId && ctx.db.select().from(executors).where(
|
|
8210
|
-
const project = ctx.db.select().from(projects).where(
|
|
8513
|
+
const worker = run.executorId && ctx.db.select().from(executors).where(eq95(executors.id, run.executorId)).get();
|
|
8514
|
+
const project = ctx.db.select().from(projects).where(eq95(projects.id, run.projectId)).get();
|
|
8211
8515
|
const member = ctx.db.select().from(memberships).where(
|
|
8212
|
-
|
|
8213
|
-
|
|
8214
|
-
|
|
8516
|
+
and72(
|
|
8517
|
+
eq95(memberships.workspaceId, run.workspaceId),
|
|
8518
|
+
eq95(memberships.userId, run.actorId)
|
|
8215
8519
|
)
|
|
8216
8520
|
).get();
|
|
8217
8521
|
if (!worker || !worker.enabled || worker.projectId !== run.projectId || !project?.enabled || !member) {
|
|
@@ -8231,9 +8535,9 @@ function runCapability(ctx, expectedId) {
|
|
|
8231
8535
|
if (!terminal.has(run.status) && !run.cancelRequested) {
|
|
8232
8536
|
const operation = object(command2) ? command2.operation : void 0;
|
|
8233
8537
|
const token = run.tokenId ? ctx.db.select().from(accessTokens).where(
|
|
8234
|
-
|
|
8235
|
-
|
|
8236
|
-
|
|
8538
|
+
and72(
|
|
8539
|
+
eq95(accessTokens.workspaceId, run.workspaceId),
|
|
8540
|
+
eq95(accessTokens.id, run.tokenId)
|
|
8237
8541
|
)
|
|
8238
8542
|
).get() : void 0;
|
|
8239
8543
|
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 +8578,11 @@ function live(run) {
|
|
|
8274
8578
|
}
|
|
8275
8579
|
function actorContext(ctx, run) {
|
|
8276
8580
|
const user = identityRepository(ctx.db).user(run.actorId) ?? null;
|
|
8277
|
-
const workspace2 = ctx.db.select().from(workspaces).where(
|
|
8581
|
+
const workspace2 = ctx.db.select().from(workspaces).where(eq95(workspaces.id, run.workspaceId)).get() ?? null;
|
|
8278
8582
|
const membership = ctx.db.select().from(memberships).where(
|
|
8279
|
-
|
|
8280
|
-
|
|
8281
|
-
|
|
8583
|
+
and72(
|
|
8584
|
+
eq95(memberships.workspaceId, run.workspaceId),
|
|
8585
|
+
eq95(memberships.userId, run.actorId)
|
|
8282
8586
|
)
|
|
8283
8587
|
).get();
|
|
8284
8588
|
if (!user || !workspace2 || !membership) {
|
|
@@ -8295,7 +8599,7 @@ function actorContext(ctx, run) {
|
|
|
8295
8599
|
}
|
|
8296
8600
|
|
|
8297
8601
|
// server/execution/bootstrap.ts
|
|
8298
|
-
import { eq as
|
|
8602
|
+
import { eq as eq96 } from "drizzle-orm";
|
|
8299
8603
|
import { createHmac as createHmac3, randomUUID as randomUUID6 } from "node:crypto";
|
|
8300
8604
|
function bootstrap(ctx) {
|
|
8301
8605
|
const configured = process.env.LOCAL_EXECUTOR_BOOTSTRAP_TOKEN;
|
|
@@ -8303,8 +8607,8 @@ function bootstrap(ctx) {
|
|
|
8303
8607
|
throw new HttpError(403, "Invalid local bootstrap credential.");
|
|
8304
8608
|
}
|
|
8305
8609
|
const registrations = [];
|
|
8306
|
-
for (const project of ctx.db.select().from(projects).where(
|
|
8307
|
-
let worker = ctx.db.select().from(executors).where(
|
|
8610
|
+
for (const project of ctx.db.select().from(projects).where(eq96(projects.enabled, true)).all()) {
|
|
8611
|
+
let worker = ctx.db.select().from(executors).where(eq96(executors.projectId, project.id)).get();
|
|
8308
8612
|
if (worker && (!worker.locallyManaged || !worker.enabled)) {
|
|
8309
8613
|
continue;
|
|
8310
8614
|
}
|
|
@@ -8324,45 +8628,46 @@ function bootstrap(ctx) {
|
|
|
8324
8628
|
}).returning().get();
|
|
8325
8629
|
}
|
|
8326
8630
|
const token = createHmac3("sha256", configured).update(`${worker.id}:${worker.registrationNonce}`).digest("hex");
|
|
8327
|
-
ctx.db.update(executors).set({ tokenHash: digest(token) }).where(
|
|
8631
|
+
ctx.db.update(executors).set({ tokenHash: digest(token) }).where(eq96(executors.id, worker.id)).run();
|
|
8328
8632
|
registrations.push({
|
|
8329
8633
|
agent_id: project.id,
|
|
8330
8634
|
executor_id: worker.id,
|
|
8331
8635
|
token
|
|
8332
8636
|
});
|
|
8333
8637
|
}
|
|
8638
|
+
managerHeartbeat.set(ctx.secrets, Date.now());
|
|
8334
8639
|
return json({ registrations });
|
|
8335
8640
|
}
|
|
8336
8641
|
|
|
8337
8642
|
// server/execution/claim.ts
|
|
8338
|
-
import { and as
|
|
8643
|
+
import { and as and73, asc as asc7, eq as eq97, inArray as inArray10 } from "drizzle-orm";
|
|
8339
8644
|
function claim(ctx, worker) {
|
|
8340
8645
|
ctx.db.update(executors).set({ lastSeenAt: now() }).where(
|
|
8341
|
-
|
|
8342
|
-
|
|
8343
|
-
|
|
8646
|
+
and73(
|
|
8647
|
+
eq97(executors.id, worker.id),
|
|
8648
|
+
eq97(executors.workspaceId, worker.workspaceId)
|
|
8344
8649
|
)
|
|
8345
8650
|
).run();
|
|
8346
|
-
const setting = ctx.db.select().from(workspaceSettings).where(
|
|
8651
|
+
const setting = ctx.db.select().from(workspaceSettings).where(eq97(workspaceSettings.workspaceId, worker.workspaceId)).get();
|
|
8347
8652
|
if (setting && (!setting.enabled || setting.executionPool !== worker.pool)) {
|
|
8348
8653
|
return new Response(null, { status: 204 });
|
|
8349
8654
|
}
|
|
8350
8655
|
const active = ctx.db.select().from(runs).where(
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8656
|
+
and73(
|
|
8657
|
+
eq97(runs.workspaceId, worker.workspaceId),
|
|
8658
|
+
inArray10(runs.status, ["running", "waiting_approval"])
|
|
8354
8659
|
)
|
|
8355
8660
|
).all();
|
|
8356
8661
|
if (active.some((run) => run.projectId === worker.projectId) || active.length >= (setting?.maxConcurrentRuns ?? 4)) {
|
|
8357
8662
|
return new Response(null, { status: 204 });
|
|
8358
8663
|
}
|
|
8359
8664
|
const candidates = ctx.db.select().from(runs).where(
|
|
8360
|
-
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
|
|
8665
|
+
and73(
|
|
8666
|
+
eq97(runs.projectId, worker.projectId),
|
|
8667
|
+
eq97(runs.workspaceId, worker.workspaceId),
|
|
8668
|
+
eq97(runs.status, "queued")
|
|
8364
8669
|
)
|
|
8365
|
-
).orderBy(
|
|
8670
|
+
).orderBy(asc7(runs.createdAt)).all();
|
|
8366
8671
|
for (const run of candidates) {
|
|
8367
8672
|
if (!worker.capabilities.includes(run.operation)) {
|
|
8368
8673
|
continue;
|
|
@@ -8372,18 +8677,18 @@ function claim(ctx, worker) {
|
|
|
8372
8677
|
continue;
|
|
8373
8678
|
}
|
|
8374
8679
|
const member = ctx.db.select().from(memberships).where(
|
|
8375
|
-
|
|
8376
|
-
|
|
8377
|
-
|
|
8680
|
+
and73(
|
|
8681
|
+
eq97(memberships.userId, run.actorId),
|
|
8682
|
+
eq97(memberships.workspaceId, run.workspaceId)
|
|
8378
8683
|
)
|
|
8379
8684
|
).get();
|
|
8380
|
-
const token = run.tokenId ? ctx.db.select().from(accessTokens).where(
|
|
8685
|
+
const token = run.tokenId ? ctx.db.select().from(accessTokens).where(eq97(accessTokens.id, run.tokenId)).get() : null;
|
|
8381
8686
|
if (!member || run.cancelRequested || run.tokenId && (!token || token.revoked)) {
|
|
8382
8687
|
ctx.db.update(runs).set({
|
|
8383
8688
|
status: "cancelled",
|
|
8384
8689
|
cancelRequested: true,
|
|
8385
8690
|
updatedAt: now()
|
|
8386
|
-
}).where(
|
|
8691
|
+
}).where(eq97(runs.id, run.id)).run();
|
|
8387
8692
|
continue;
|
|
8388
8693
|
}
|
|
8389
8694
|
const capability = randomSecret();
|
|
@@ -8395,7 +8700,7 @@ function claim(ctx, worker) {
|
|
|
8395
8700
|
deadline,
|
|
8396
8701
|
leaseExpiresAt: new Date(Date.now() + 6e4).toISOString(),
|
|
8397
8702
|
updatedAt: now()
|
|
8398
|
-
}).where(
|
|
8703
|
+
}).where(eq97(runs.id, run.id)).run();
|
|
8399
8704
|
return json({
|
|
8400
8705
|
protocol_version: protocol,
|
|
8401
8706
|
run_id: run.id,
|
|
@@ -8413,13 +8718,13 @@ function claim(ctx, worker) {
|
|
|
8413
8718
|
}
|
|
8414
8719
|
|
|
8415
8720
|
// server/execution/configuration.ts
|
|
8416
|
-
import { and as
|
|
8721
|
+
import { and as and74, eq as eq98 } from "drizzle-orm";
|
|
8417
8722
|
function pluginsFor(ctx, worker) {
|
|
8418
8723
|
return ctx.db.select().from(plugins).where(
|
|
8419
|
-
|
|
8420
|
-
|
|
8421
|
-
|
|
8422
|
-
|
|
8724
|
+
and74(
|
|
8725
|
+
eq98(plugins.workspaceId, worker.workspaceId),
|
|
8726
|
+
eq98(plugins.projectId, worker.projectId),
|
|
8727
|
+
eq98(plugins.enabled, true)
|
|
8423
8728
|
)
|
|
8424
8729
|
).all().filter(
|
|
8425
8730
|
(plugin) => plugin.distribution !== "mcp" || worker.protocolVersion >= 4
|
|
@@ -8447,11 +8752,11 @@ function configuration(ctx, worker) {
|
|
|
8447
8752
|
}
|
|
8448
8753
|
|
|
8449
8754
|
// server/execution/credentials.ts
|
|
8450
|
-
import { and as
|
|
8755
|
+
import { and as and77, eq as eq101 } from "drizzle-orm";
|
|
8451
8756
|
|
|
8452
8757
|
// server/mcp/oauth-refresh.ts
|
|
8453
8758
|
import { auth as auth3 } from "@modelcontextprotocol/client";
|
|
8454
|
-
import { and as
|
|
8759
|
+
import { and as and75, eq as eq99 } from "drizzle-orm";
|
|
8455
8760
|
var refreshes = /* @__PURE__ */ new WeakMap();
|
|
8456
8761
|
async function mcpExecutionSecret(ctx, credential) {
|
|
8457
8762
|
let pending = refreshes.get(ctx.db);
|
|
@@ -8473,9 +8778,9 @@ async function mcpExecutionSecret(ctx, credential) {
|
|
|
8473
8778
|
}
|
|
8474
8779
|
async function refresh(ctx, initial) {
|
|
8475
8780
|
const credential = ctx.db.select().from(credentials).where(
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8781
|
+
and75(
|
|
8782
|
+
eq99(credentials.id, initial.id),
|
|
8783
|
+
eq99(credentials.workspaceId, initial.workspaceId)
|
|
8479
8784
|
)
|
|
8480
8785
|
).get();
|
|
8481
8786
|
if (!credential) {
|
|
@@ -8506,9 +8811,9 @@ async function refresh(ctx, initial) {
|
|
|
8506
8811
|
encryptedSecret: encrypt(ctx, JSON.stringify(state)),
|
|
8507
8812
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
8508
8813
|
}).where(
|
|
8509
|
-
|
|
8510
|
-
|
|
8511
|
-
|
|
8814
|
+
and75(
|
|
8815
|
+
eq99(credentials.id, credential.id),
|
|
8816
|
+
eq99(credentials.encryptedSecret, credential.encryptedSecret)
|
|
8512
8817
|
)
|
|
8513
8818
|
).returning().get();
|
|
8514
8819
|
if (!updated) {
|
|
@@ -8532,11 +8837,11 @@ async function refresh(ctx, initial) {
|
|
|
8532
8837
|
}
|
|
8533
8838
|
|
|
8534
8839
|
// server/oauth/refresh.ts
|
|
8535
|
-
import { z as
|
|
8536
|
-
import { and as
|
|
8840
|
+
import { z as z52 } from "zod";
|
|
8841
|
+
import { and as and76, eq as eq100 } from "drizzle-orm";
|
|
8537
8842
|
|
|
8538
8843
|
// server/oauth/tokens.ts
|
|
8539
|
-
import { z as
|
|
8844
|
+
import { z as z51 } from "zod";
|
|
8540
8845
|
async function tokenExchange(providerName, clientId, clientSecret, params, fetcher) {
|
|
8541
8846
|
const fields = new URLSearchParams({ ...params, client_id: clientId });
|
|
8542
8847
|
const headers = new Headers({
|
|
@@ -8577,7 +8882,7 @@ async function tokenExchange(providerName, clientId, clientSecret, params, fetch
|
|
|
8577
8882
|
}
|
|
8578
8883
|
chunks.push(item.value);
|
|
8579
8884
|
}
|
|
8580
|
-
const value =
|
|
8885
|
+
const value = z51.record(z51.string(), z51.unknown()).parse(JSON.parse(Buffer.concat(chunks).toString("utf8")));
|
|
8581
8886
|
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
8887
|
throw new Error();
|
|
8583
8888
|
}
|
|
@@ -8623,14 +8928,14 @@ function recordSecretVersion(secret, credential) {
|
|
|
8623
8928
|
return secret;
|
|
8624
8929
|
}
|
|
8625
8930
|
function assertExecutionSecretCurrent(store, credential, secret) {
|
|
8626
|
-
const
|
|
8931
|
+
const version2 = secretVersions.get(secret);
|
|
8627
8932
|
const current = store.db.select().from(credentials).where(
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8933
|
+
and76(
|
|
8934
|
+
eq100(credentials.id, credential.id),
|
|
8935
|
+
eq100(credentials.workspaceId, credential.workspaceId)
|
|
8631
8936
|
)
|
|
8632
8937
|
).get();
|
|
8633
|
-
if (!
|
|
8938
|
+
if (!version2 || !current || version2.id !== current.id || version2.workspaceId !== current.workspaceId || version2.provider !== current.provider || version2.encryptedSecret !== current.encryptedSecret) {
|
|
8634
8939
|
throw new ServiceError(
|
|
8635
8940
|
"CONFLICT",
|
|
8636
8941
|
"Credential changed during execution. Retry the run."
|
|
@@ -8643,7 +8948,7 @@ async function executionSecret(store, credential, fetcher = fetch) {
|
|
|
8643
8948
|
}
|
|
8644
8949
|
if (!provider(credential.provider)) {
|
|
8645
8950
|
return recordSecretVersion(
|
|
8646
|
-
|
|
8951
|
+
z52.record(z52.string(), z52.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret))),
|
|
8647
8952
|
credential
|
|
8648
8953
|
);
|
|
8649
8954
|
}
|
|
@@ -8669,15 +8974,15 @@ async function executionSecret(store, credential, fetcher = fetch) {
|
|
|
8669
8974
|
}
|
|
8670
8975
|
async function resolveExecutionSecret(store, initial, fetcher) {
|
|
8671
8976
|
const credential = store.db.select().from(credentials).where(
|
|
8672
|
-
|
|
8673
|
-
|
|
8674
|
-
|
|
8977
|
+
and76(
|
|
8978
|
+
eq100(credentials.id, initial.id),
|
|
8979
|
+
eq100(credentials.workspaceId, initial.workspaceId)
|
|
8675
8980
|
)
|
|
8676
8981
|
).get();
|
|
8677
8982
|
if (!credential || !provider(credential.provider)) {
|
|
8678
8983
|
throw new ServiceError("BAD_REQUEST", "Reconnect this credential.");
|
|
8679
8984
|
}
|
|
8680
|
-
const payload =
|
|
8985
|
+
const payload = z52.record(z52.string(), z52.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret)));
|
|
8681
8986
|
if (credential.provider === "xero-oauth" && Object.keys(payload).length === 1 && typeof payload.secret_accessToken === "string" && payload.secret_accessToken) {
|
|
8682
8987
|
return recordSecretVersion(
|
|
8683
8988
|
{ secret_accessToken: payload.secret_accessToken },
|
|
@@ -8713,9 +9018,9 @@ async function resolveExecutionSecret(store, initial, fetcher) {
|
|
|
8713
9018
|
JSON.stringify(applyTokens(payload, tokens2))
|
|
8714
9019
|
);
|
|
8715
9020
|
const result = store.db.update(credentials).set({ encryptedSecret: updated, updatedAt: (/* @__PURE__ */ new Date()).toISOString() }).where(
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
9021
|
+
and76(
|
|
9022
|
+
eq100(credentials.id, credential.id),
|
|
9023
|
+
eq100(credentials.encryptedSecret, credential.encryptedSecret)
|
|
8719
9024
|
)
|
|
8720
9025
|
).returning().get();
|
|
8721
9026
|
if (!result) {
|
|
@@ -8747,9 +9052,9 @@ async function serveCredential(ctx, credentialId) {
|
|
|
8747
9052
|
throw new HttpError(403, "Credential is outside this run capability.");
|
|
8748
9053
|
}
|
|
8749
9054
|
const credential2 = ctx.db.select().from(credentials).where(
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
|
|
9055
|
+
and77(
|
|
9056
|
+
eq101(credentials.id, credentialId),
|
|
9057
|
+
eq101(credentials.workspaceId, run.workspaceId)
|
|
8753
9058
|
)
|
|
8754
9059
|
).get();
|
|
8755
9060
|
if (!credential2) {
|
|
@@ -8776,11 +9081,164 @@ async function serveCredential(ctx, credentialId) {
|
|
|
8776
9081
|
});
|
|
8777
9082
|
}
|
|
8778
9083
|
|
|
9084
|
+
// server/execution/shell-policy.ts
|
|
9085
|
+
import { and as and78, asc as asc8, eq as eq103 } from "drizzle-orm";
|
|
9086
|
+
import { z as z54 } from "zod";
|
|
9087
|
+
|
|
9088
|
+
// server/execution/redaction.ts
|
|
9089
|
+
import { z as z53 } from "zod";
|
|
9090
|
+
import { eq as eq102 } from "drizzle-orm";
|
|
9091
|
+
function redact(ctx, workspaceId, value) {
|
|
9092
|
+
const secrets = [];
|
|
9093
|
+
const collect = (entry) => {
|
|
9094
|
+
if (typeof entry === "string" && entry) {
|
|
9095
|
+
secrets.push(entry);
|
|
9096
|
+
} else if (Array.isArray(entry)) {
|
|
9097
|
+
entry.forEach(collect);
|
|
9098
|
+
} else if (entry && typeof entry === "object") {
|
|
9099
|
+
Object.values(entry).forEach(collect);
|
|
9100
|
+
}
|
|
9101
|
+
};
|
|
9102
|
+
for (const credential of ctx.db.select().from(credentials).where(eq102(credentials.workspaceId, workspaceId)).all()) {
|
|
9103
|
+
collect(JSON.parse(decrypt(ctx, credential.encryptedSecret)));
|
|
9104
|
+
}
|
|
9105
|
+
secrets.sort((a, b) => b.length - a.length);
|
|
9106
|
+
const mask = (entry) => {
|
|
9107
|
+
if (typeof entry === "string") {
|
|
9108
|
+
return secrets.reduce(
|
|
9109
|
+
(text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
|
|
9110
|
+
entry
|
|
9111
|
+
);
|
|
9112
|
+
}
|
|
9113
|
+
if (Array.isArray(entry)) {
|
|
9114
|
+
return entry.map(mask);
|
|
9115
|
+
}
|
|
9116
|
+
if (entry && typeof entry === "object") {
|
|
9117
|
+
return Object.fromEntries(
|
|
9118
|
+
Object.entries(entry).map(([key, child]) => [
|
|
9119
|
+
typeof key === "string" ? secrets.reduce(
|
|
9120
|
+
(text3, secret) => text3.replaceAll(secret, "[REDACTED]"),
|
|
9121
|
+
key
|
|
9122
|
+
) : key,
|
|
9123
|
+
mask(child)
|
|
9124
|
+
])
|
|
9125
|
+
);
|
|
9126
|
+
}
|
|
9127
|
+
return entry;
|
|
9128
|
+
};
|
|
9129
|
+
return mask(z53.json().parse(value));
|
|
9130
|
+
}
|
|
9131
|
+
function bounded(value, limit = 2e5) {
|
|
9132
|
+
if (Buffer.byteLength(JSON.stringify(value)) > limit) {
|
|
9133
|
+
throw new HttpError(400, "Data exceeds the response limit.");
|
|
9134
|
+
}
|
|
9135
|
+
return value;
|
|
9136
|
+
}
|
|
9137
|
+
|
|
9138
|
+
// server/execution/shell-policy.ts
|
|
9139
|
+
var invocation = z54.strictObject({
|
|
9140
|
+
executable: executableName,
|
|
9141
|
+
args: z54.array(
|
|
9142
|
+
z54.string().max(4096).refine((arg) => !arg.includes("\0"))
|
|
9143
|
+
).max(64)
|
|
9144
|
+
});
|
|
9145
|
+
function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
|
|
9146
|
+
const plugin = ctx.db.select().from(plugins).where(
|
|
9147
|
+
and78(
|
|
9148
|
+
eq103(plugins.id, pluginId),
|
|
9149
|
+
eq103(plugins.projectId, run.projectId),
|
|
9150
|
+
eq103(plugins.workspaceId, run.workspaceId),
|
|
9151
|
+
eq103(plugins.enabled, true)
|
|
9152
|
+
)
|
|
9153
|
+
).get();
|
|
9154
|
+
const agent = snapshotAgents(run.snapshot).find(
|
|
9155
|
+
(agent2) => agent2.id === run.projectId
|
|
9156
|
+
);
|
|
9157
|
+
if (!plugin || !supportsShellPolicy(plugin) || !agent?.plugins.some(
|
|
9158
|
+
(slot) => slot.shell_policy_id === plugin.id && slot.digest === plugin.digest
|
|
9159
|
+
)) {
|
|
9160
|
+
throw new HttpError(
|
|
9161
|
+
403,
|
|
9162
|
+
"Shell is outside this run's active plugin grants."
|
|
9163
|
+
);
|
|
9164
|
+
}
|
|
9165
|
+
if (!approvalId && method === "GET") {
|
|
9166
|
+
return json(
|
|
9167
|
+
ctx.db.select({ name: shellRules.executable }).from(shellRules).where(
|
|
9168
|
+
and78(
|
|
9169
|
+
eq103(shellRules.pluginId, pluginId),
|
|
9170
|
+
eq103(shellRules.decision, "allow")
|
|
9171
|
+
)
|
|
9172
|
+
).orderBy(asc8(shellRules.executable)).all().map((rule2) => rule2.name)
|
|
9173
|
+
);
|
|
9174
|
+
}
|
|
9175
|
+
if (approvalId && method === "GET") {
|
|
9176
|
+
const row2 = ctx.db.select().from(approvals).where(
|
|
9177
|
+
and78(
|
|
9178
|
+
eq103(approvals.id, approvalId),
|
|
9179
|
+
eq103(approvals.workspaceId, run.workspaceId),
|
|
9180
|
+
eq103(approvals.runId, run.id)
|
|
9181
|
+
)
|
|
9182
|
+
).get();
|
|
9183
|
+
if (row2?.shell?.pluginId !== plugin.id || row2.shell.digest !== plugin.digest) {
|
|
9184
|
+
throw new HttpError(404, "Shell approval not found.");
|
|
9185
|
+
}
|
|
9186
|
+
const blocked = ctx.db.select().from(shellRules).where(
|
|
9187
|
+
and78(
|
|
9188
|
+
eq103(shellRules.pluginId, pluginId),
|
|
9189
|
+
eq103(shellRules.executable, row2.shell.executable),
|
|
9190
|
+
eq103(shellRules.decision, "block")
|
|
9191
|
+
)
|
|
9192
|
+
).get();
|
|
9193
|
+
return json({
|
|
9194
|
+
id: row2.id,
|
|
9195
|
+
status: blocked && row2.status === "approved" ? "denied" : row2.status
|
|
9196
|
+
});
|
|
9197
|
+
}
|
|
9198
|
+
if (approvalId || method !== "POST") {
|
|
9199
|
+
throw new HttpError(405, "Method not allowed.");
|
|
9200
|
+
}
|
|
9201
|
+
const parsed = invocation.safeParse(body);
|
|
9202
|
+
if (!parsed.success) {
|
|
9203
|
+
throw new HttpError(400, "Invalid Shell executable or arguments.");
|
|
9204
|
+
}
|
|
9205
|
+
const { executable, args } = parsed.data;
|
|
9206
|
+
const rule = ctx.db.select().from(shellRules).where(
|
|
9207
|
+
and78(
|
|
9208
|
+
eq103(shellRules.pluginId, pluginId),
|
|
9209
|
+
eq103(shellRules.executable, executable)
|
|
9210
|
+
)
|
|
9211
|
+
).get();
|
|
9212
|
+
if (rule) {
|
|
9213
|
+
return json({ status: rule.decision === "allow" ? "approved" : "denied" });
|
|
9214
|
+
}
|
|
9215
|
+
const argv = JSON.stringify(
|
|
9216
|
+
redact(ctx, run.workspaceId, [executable, ...args])
|
|
9217
|
+
).replace(
|
|
9218
|
+
/[\u200b-\u200f\u2028-\u202e\u2060-\u206f]/gu,
|
|
9219
|
+
(character) => "\\u" + character.charCodeAt(0).toString(16).padStart(4, "0")
|
|
9220
|
+
);
|
|
9221
|
+
const row = ctx.db.insert(approvals).values({
|
|
9222
|
+
...base(run.workspaceId),
|
|
9223
|
+
runId: run.id,
|
|
9224
|
+
prompt: argv,
|
|
9225
|
+
shell: {
|
|
9226
|
+
pluginId,
|
|
9227
|
+
projectId: run.projectId,
|
|
9228
|
+
digest: plugin.digest,
|
|
9229
|
+
executable
|
|
9230
|
+
},
|
|
9231
|
+
status: "pending"
|
|
9232
|
+
}).returning().get();
|
|
9233
|
+
ctx.db.update(runs).set({ status: "waiting_approval", updatedAt: now() }).where(eq103(runs.id, run.id)).run();
|
|
9234
|
+
return json({ id: row.id, status: row.status }, 201);
|
|
9235
|
+
}
|
|
9236
|
+
|
|
8779
9237
|
// server/execution/product.ts
|
|
8780
|
-
import { and as
|
|
9238
|
+
import { and as and81, eq as eq106 } from "drizzle-orm";
|
|
8781
9239
|
|
|
8782
9240
|
// server/execution/project-data.ts
|
|
8783
|
-
import { and as
|
|
9241
|
+
import { and as and80, asc as asc9, eq as eq105, inArray as inArray11 } from "drizzle-orm";
|
|
8784
9242
|
|
|
8785
9243
|
// server/execution/data-pagination.ts
|
|
8786
9244
|
function paginateData(items, offset, limit) {
|
|
@@ -8807,106 +9265,56 @@ function paginateData(items, offset, limit) {
|
|
|
8807
9265
|
}
|
|
8808
9266
|
|
|
8809
9267
|
// server/execution/data-schemas.ts
|
|
8810
|
-
import { z as
|
|
9268
|
+
import { z as z55 } from "zod";
|
|
8811
9269
|
var pagination = {
|
|
8812
|
-
offset:
|
|
8813
|
-
limit:
|
|
9270
|
+
offset: z55.number().int().min(0).max(1e6).default(0),
|
|
9271
|
+
limit: z55.number().int().min(1).max(100).default(100)
|
|
8814
9272
|
};
|
|
8815
|
-
var tableId = { table_id:
|
|
8816
|
-
var revision2 =
|
|
8817
|
-
var content =
|
|
9273
|
+
var tableId = { table_id: z55.string().uuid() };
|
|
9274
|
+
var revision2 = z55.number().int().positive();
|
|
9275
|
+
var content = z55.string().refine(
|
|
8818
9276
|
(value) => !value.includes("\0") && Buffer.byteLength(value) <= 2e5
|
|
8819
9277
|
);
|
|
8820
|
-
var dataOperationSchema =
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
operation:
|
|
9278
|
+
var dataOperationSchema = z55.discriminatedUnion("operation", [
|
|
9279
|
+
z55.strictObject({ operation: z55.literal("list_tables"), ...pagination }),
|
|
9280
|
+
z55.strictObject({ operation: z55.literal("get_table"), ...tableId }),
|
|
9281
|
+
z55.strictObject({
|
|
9282
|
+
operation: z55.literal("list_rows"),
|
|
8825
9283
|
...tableId,
|
|
8826
9284
|
...pagination
|
|
8827
9285
|
}),
|
|
8828
|
-
|
|
8829
|
-
operation:
|
|
9286
|
+
z55.strictObject({
|
|
9287
|
+
operation: z55.literal("write_row"),
|
|
8830
9288
|
...tableId,
|
|
8831
9289
|
table_revision: revision2,
|
|
8832
|
-
values:
|
|
8833
|
-
row_id:
|
|
9290
|
+
values: z55.record(z55.string(), z55.json()),
|
|
9291
|
+
row_id: z55.string().uuid().optional(),
|
|
8834
9292
|
revision: revision2.optional()
|
|
8835
9293
|
}).refine(
|
|
8836
9294
|
(input2) => input2.row_id === void 0 === (input2.revision === void 0),
|
|
8837
9295
|
"Row updates require both row ID and revision."
|
|
8838
9296
|
),
|
|
8839
|
-
|
|
8840
|
-
operation:
|
|
9297
|
+
z55.strictObject({
|
|
9298
|
+
operation: z55.literal("delete_row"),
|
|
8841
9299
|
...tableId,
|
|
8842
|
-
row_id:
|
|
9300
|
+
row_id: z55.string().uuid(),
|
|
8843
9301
|
revision: revision2
|
|
8844
9302
|
}),
|
|
8845
|
-
|
|
8846
|
-
|
|
8847
|
-
operation:
|
|
8848
|
-
document_id:
|
|
9303
|
+
z55.strictObject({ operation: z55.literal("list_documents"), ...pagination }),
|
|
9304
|
+
z55.strictObject({
|
|
9305
|
+
operation: z55.literal("get_document"),
|
|
9306
|
+
document_id: z55.string().uuid()
|
|
8849
9307
|
}),
|
|
8850
|
-
|
|
8851
|
-
operation:
|
|
8852
|
-
document_id:
|
|
8853
|
-
title:
|
|
9308
|
+
z55.strictObject({
|
|
9309
|
+
operation: z55.literal("write_document"),
|
|
9310
|
+
document_id: z55.string().uuid(),
|
|
9311
|
+
title: z55.string().trim().min(1).max(200).refine((value) => !value.includes("\0")).optional(),
|
|
8854
9312
|
content: content.optional()
|
|
8855
9313
|
})
|
|
8856
9314
|
]);
|
|
8857
9315
|
|
|
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
9316
|
// server/execution/run-grants.ts
|
|
8909
|
-
import { and as
|
|
9317
|
+
import { and as and79, eq as eq104 } from "drizzle-orm";
|
|
8910
9318
|
function grantIds(context, run, kind, write = false) {
|
|
8911
9319
|
const root2 = snapshotAgents(run.snapshot).find(
|
|
8912
9320
|
(agent) => agent.id === run.projectId
|
|
@@ -8917,9 +9325,9 @@ function grantIds(context, run, kind, write = false) {
|
|
|
8917
9325
|
...write ? [] : grants2?.read ?? []
|
|
8918
9326
|
];
|
|
8919
9327
|
const project = context.db.select().from(projects).where(
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
9328
|
+
and79(
|
|
9329
|
+
eq104(projects.id, run.projectId),
|
|
9330
|
+
eq104(projects.workspaceId, run.workspaceId)
|
|
8923
9331
|
)
|
|
8924
9332
|
).get();
|
|
8925
9333
|
if (!project) {
|
|
@@ -8945,11 +9353,11 @@ function projectData(context, run, body) {
|
|
|
8945
9353
|
const documentOperation = input2.operation === "list_documents" || input2.operation === "get_document" || input2.operation === "write_document";
|
|
8946
9354
|
if (documentOperation) {
|
|
8947
9355
|
const accessibleDocuments = context.db.select().from(documents).where(
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
9356
|
+
and80(
|
|
9357
|
+
eq105(documents.workspaceId, run.workspaceId),
|
|
9358
|
+
inArray11(documents.id, grantIds(context, run, "documents"))
|
|
8951
9359
|
)
|
|
8952
|
-
).orderBy(
|
|
9360
|
+
).orderBy(asc9(documents.id)).all();
|
|
8953
9361
|
if (input2.operation === "list_documents") {
|
|
8954
9362
|
return paginateData(
|
|
8955
9363
|
accessibleDocuments.map(documentView2),
|
|
@@ -8974,9 +9382,9 @@ function projectData(context, run, body) {
|
|
|
8974
9382
|
content: input2.content ?? document.content,
|
|
8975
9383
|
updatedAt: now()
|
|
8976
9384
|
}).where(
|
|
8977
|
-
|
|
8978
|
-
|
|
8979
|
-
|
|
9385
|
+
and80(
|
|
9386
|
+
eq105(documents.id, document.id),
|
|
9387
|
+
eq105(documents.workspaceId, run.workspaceId)
|
|
8980
9388
|
)
|
|
8981
9389
|
).returning().get();
|
|
8982
9390
|
if (!updated) {
|
|
@@ -8985,11 +9393,11 @@ function projectData(context, run, body) {
|
|
|
8985
9393
|
return bounded(documentView2(updated));
|
|
8986
9394
|
}
|
|
8987
9395
|
const tables = context.db.select().from(workspaceTables).where(
|
|
8988
|
-
|
|
8989
|
-
|
|
8990
|
-
|
|
9396
|
+
and80(
|
|
9397
|
+
eq105(workspaceTables.workspaceId, run.workspaceId),
|
|
9398
|
+
inArray11(workspaceTables.id, grantIds(context, run, "tables"))
|
|
8991
9399
|
)
|
|
8992
|
-
).orderBy(
|
|
9400
|
+
).orderBy(asc9(workspaceTables.id)).all();
|
|
8993
9401
|
if (input2.operation === "list_tables") {
|
|
8994
9402
|
return paginateData(tables.map(standard), input2.offset, input2.limit);
|
|
8995
9403
|
}
|
|
@@ -9003,15 +9411,15 @@ function projectData(context, run, body) {
|
|
|
9003
9411
|
if (input2.operation !== "list_rows" && !grantIds(context, run, "tables", true).includes(table.id)) {
|
|
9004
9412
|
throw new HttpError(403, "Resource is read only.");
|
|
9005
9413
|
}
|
|
9006
|
-
const matchesTable =
|
|
9007
|
-
|
|
9008
|
-
|
|
9414
|
+
const matchesTable = and80(
|
|
9415
|
+
eq105(tableRows.workspaceId, run.workspaceId),
|
|
9416
|
+
eq105(tableRows.tableId, table.id)
|
|
9009
9417
|
);
|
|
9010
9418
|
if (input2.operation === "list_rows") {
|
|
9011
|
-
const rows = context.db.select().from(tableRows).where(matchesTable).orderBy(
|
|
9419
|
+
const rows = context.db.select().from(tableRows).where(matchesTable).orderBy(asc9(tableRows.id)).all();
|
|
9012
9420
|
return paginateData(rows.map(rowView), input2.offset, input2.limit);
|
|
9013
9421
|
}
|
|
9014
|
-
const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(
|
|
9422
|
+
const row = input2.row_id === void 0 ? void 0 : context.db.select().from(tableRows).where(and80(matchesTable, eq105(tableRows.id, input2.row_id))).get();
|
|
9015
9423
|
if (input2.row_id !== void 0 && !row) {
|
|
9016
9424
|
throw new HttpError(404, "Row not found.");
|
|
9017
9425
|
}
|
|
@@ -9019,7 +9427,7 @@ function projectData(context, run, body) {
|
|
|
9019
9427
|
throw new HttpError(409, "Row changed. Reload before saving.");
|
|
9020
9428
|
}
|
|
9021
9429
|
if (input2.operation === "delete_row") {
|
|
9022
|
-
context.db.delete(tableRows).where(
|
|
9430
|
+
context.db.delete(tableRows).where(and80(matchesTable, eq105(tableRows.id, input2.row_id))).run();
|
|
9023
9431
|
return { deleted: true };
|
|
9024
9432
|
}
|
|
9025
9433
|
if (table.revision !== input2.table_revision) {
|
|
@@ -9031,7 +9439,7 @@ function projectData(context, run, body) {
|
|
|
9031
9439
|
values: input2.values,
|
|
9032
9440
|
revision: row.revision + 1,
|
|
9033
9441
|
updatedAt: now()
|
|
9034
|
-
}).where(
|
|
9442
|
+
}).where(and80(matchesTable, eq105(tableRows.id, row.id))).returning().get();
|
|
9035
9443
|
if (!updated) {
|
|
9036
9444
|
throw new HttpError(404, "Row not found.");
|
|
9037
9445
|
}
|
|
@@ -9048,6 +9456,10 @@ function projectData(context, run, body) {
|
|
|
9048
9456
|
|
|
9049
9457
|
// server/execution/product.ts
|
|
9050
9458
|
function handleProduct(ctx, run, route, method, body) {
|
|
9459
|
+
const shell = route.match(/^product\/shell\/([^/]+)\/(?:([^/]+)\/)?$/);
|
|
9460
|
+
if (shell?.[1]) {
|
|
9461
|
+
return shellPolicyRequest(ctx, run, shell[1], shell[2], method, body);
|
|
9462
|
+
}
|
|
9051
9463
|
if (route === "product/project-data/" && method === "POST") {
|
|
9052
9464
|
return json(projectData(ctx, run, body));
|
|
9053
9465
|
}
|
|
@@ -9071,7 +9483,7 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9071
9483
|
}
|
|
9072
9484
|
if (method === "GET") {
|
|
9073
9485
|
const items = ctx.db.select().from(table).where(
|
|
9074
|
-
|
|
9486
|
+
and81(eq106(table.workspaceId, run.workspaceId), eq106(table.runId, run.id))
|
|
9075
9487
|
).all();
|
|
9076
9488
|
const view = (entry) => "prompt" in entry ? {
|
|
9077
9489
|
id: entry.id,
|
|
@@ -9110,7 +9522,7 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9110
9522
|
status: "pending",
|
|
9111
9523
|
decidedBy: null
|
|
9112
9524
|
}).returning().get();
|
|
9113
|
-
ctx.db.update(runs).set({ status: "waiting_approval" }).where(
|
|
9525
|
+
ctx.db.update(runs).set({ status: "waiting_approval" }).where(eq106(runs.id, run.id)).run();
|
|
9114
9526
|
return json(
|
|
9115
9527
|
{
|
|
9116
9528
|
id: approval.id,
|
|
@@ -9148,11 +9560,11 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9148
9560
|
}
|
|
9149
9561
|
|
|
9150
9562
|
// server/execution/register.ts
|
|
9151
|
-
import { eq as
|
|
9563
|
+
import { eq as eq107 } from "drizzle-orm";
|
|
9152
9564
|
function register(ctx, worker, body) {
|
|
9153
|
-
const
|
|
9565
|
+
const version2 = body.protocol_version;
|
|
9154
9566
|
const capabilities = body.capabilities;
|
|
9155
|
-
if (typeof
|
|
9567
|
+
if (typeof version2 !== "number" || ![1, 2, 3, 4].includes(version2) || !Array.isArray(capabilities) || capabilities.some(
|
|
9156
9568
|
(cap) => ![
|
|
9157
9569
|
"action",
|
|
9158
9570
|
"code",
|
|
@@ -9161,31 +9573,31 @@ function register(ctx, worker, body) {
|
|
|
9161
9573
|
"mcp_discover",
|
|
9162
9574
|
"session"
|
|
9163
9575
|
].includes(String(cap))
|
|
9164
|
-
) ||
|
|
9576
|
+
) || version2 < 4 && (capabilities.includes("mcp_discover") || capabilities.includes("session")) || version2 < 2 && capabilities.includes("code") || version2 < 3 && capabilities.some((cap) => ["validate", "test"].includes(cap))) {
|
|
9165
9577
|
throw new HttpError(400, "Unsupported executor protocol or capability.");
|
|
9166
9578
|
}
|
|
9167
9579
|
const validatedCapabilities = capabilities.filter(
|
|
9168
9580
|
(capability) => typeof capability === "string"
|
|
9169
9581
|
);
|
|
9170
9582
|
const registered = ctx.db.update(executors).set({
|
|
9171
|
-
protocolVersion:
|
|
9583
|
+
protocolVersion: version2,
|
|
9172
9584
|
capabilities: validatedCapabilities,
|
|
9173
9585
|
lastSeenAt: now(),
|
|
9174
9586
|
updatedAt: now()
|
|
9175
|
-
}).where(
|
|
9587
|
+
}).where(eq107(executors.id, worker.id)).returning().get();
|
|
9176
9588
|
return json(configuration(ctx, registered));
|
|
9177
9589
|
}
|
|
9178
9590
|
|
|
9179
9591
|
// server/execution/run-update.ts
|
|
9180
|
-
import { and as
|
|
9592
|
+
import { and as and82, eq as eq108 } from "drizzle-orm";
|
|
9181
9593
|
function handleRunUpdate(ctx, run, action, body) {
|
|
9182
9594
|
if (action === "heartbeat") {
|
|
9183
9595
|
if (!terminal.has(run.status)) {
|
|
9184
9596
|
if (run.executorId) {
|
|
9185
9597
|
ctx.db.update(executors).set({ lastSeenAt: now() }).where(
|
|
9186
|
-
|
|
9187
|
-
|
|
9188
|
-
|
|
9598
|
+
and82(
|
|
9599
|
+
eq108(executors.id, run.executorId),
|
|
9600
|
+
eq108(executors.workspaceId, run.workspaceId)
|
|
9189
9601
|
)
|
|
9190
9602
|
).run();
|
|
9191
9603
|
}
|
|
@@ -9194,7 +9606,7 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9194
9606
|
leaseExpiresAt: new Date(
|
|
9195
9607
|
Math.min(Date.now() + 6e4, Date.parse(run.deadline))
|
|
9196
9608
|
).toISOString()
|
|
9197
|
-
}).where(
|
|
9609
|
+
}).where(eq108(runs.id, run.id)).run();
|
|
9198
9610
|
}
|
|
9199
9611
|
return json({
|
|
9200
9612
|
status: run.status,
|
|
@@ -9212,9 +9624,9 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9212
9624
|
"Event data"
|
|
9213
9625
|
);
|
|
9214
9626
|
const existing = ctx.db.select().from(runEvents).where(
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9627
|
+
and82(
|
|
9628
|
+
eq108(runEvents.runId, run.id),
|
|
9629
|
+
eq108(runEvents.sequence, body.sequence)
|
|
9218
9630
|
)
|
|
9219
9631
|
).get();
|
|
9220
9632
|
if (existing && (existing.kind !== body.kind || JSON.stringify(existing.data) !== JSON.stringify(data))) {
|
|
@@ -9268,13 +9680,13 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9268
9680
|
);
|
|
9269
9681
|
}
|
|
9270
9682
|
const pending = ctx.db.select().from(approvals).where(
|
|
9271
|
-
|
|
9683
|
+
and82(eq108(approvals.runId, run.id), eq108(approvals.status, "pending"))
|
|
9272
9684
|
).all();
|
|
9273
9685
|
if (pending.length && status === "succeeded") {
|
|
9274
9686
|
throw new HttpError(400, "Resolve pending approvals before completing.");
|
|
9275
9687
|
}
|
|
9276
9688
|
ctx.db.update(approvals).set({ status: "interrupted" }).where(
|
|
9277
|
-
|
|
9689
|
+
and82(eq108(approvals.runId, run.id), eq108(approvals.status, "pending"))
|
|
9278
9690
|
).run();
|
|
9279
9691
|
ctx.db.update(runs).set({
|
|
9280
9692
|
status,
|
|
@@ -9282,7 +9694,7 @@ function handleRunUpdate(ctx, run, action, body) {
|
|
|
9282
9694
|
error,
|
|
9283
9695
|
cancelRequested: run.cancelRequested,
|
|
9284
9696
|
updatedAt: now()
|
|
9285
|
-
}).where(
|
|
9697
|
+
}).where(eq108(runs.id, run.id)).run();
|
|
9286
9698
|
return new Response(null, { status: 204 });
|
|
9287
9699
|
}
|
|
9288
9700
|
|
|
@@ -9299,6 +9711,10 @@ async function handleExecution(ctx) {
|
|
|
9299
9711
|
if (credentialRoute && method === "GET") {
|
|
9300
9712
|
return serveCredential(ctx, credentialRoute[1]);
|
|
9301
9713
|
}
|
|
9714
|
+
if (route === "claim/" && method === "POST" && pendingUpdate(ctx.db)) {
|
|
9715
|
+
executor(ctx);
|
|
9716
|
+
return new Response(null, { status: 204 });
|
|
9717
|
+
}
|
|
9302
9718
|
return inTransaction(ctx, (ctx2) => {
|
|
9303
9719
|
if (route === "bootstrap/" && method === "POST") {
|
|
9304
9720
|
return bootstrap(ctx2);
|
|
@@ -9332,7 +9748,7 @@ function handleWorker(ctx, route, method, body) {
|
|
|
9332
9748
|
}
|
|
9333
9749
|
|
|
9334
9750
|
// server/oauth/callback.ts
|
|
9335
|
-
import { and as
|
|
9751
|
+
import { and as and83, eq as eq109 } from "drizzle-orm";
|
|
9336
9752
|
import { randomUUID as randomUUID7 } from "node:crypto";
|
|
9337
9753
|
async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
9338
9754
|
const workspace2 = authorize(ctx);
|
|
@@ -9346,14 +9762,14 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
|
9346
9762
|
const state = field(input2.state, 500);
|
|
9347
9763
|
const code = field(input2.code, 4e3);
|
|
9348
9764
|
const attempt = inTransaction(ctx, (ctx2) => {
|
|
9349
|
-
const record = ctx2.db.select().from(oauthAttempts).where(
|
|
9765
|
+
const record = ctx2.db.select().from(oauthAttempts).where(eq109(oauthAttempts.stateDigest, digest(state))).get();
|
|
9350
9766
|
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
9767
|
throw new ServiceError(
|
|
9352
9768
|
"BAD_REQUEST",
|
|
9353
9769
|
"This connection request has expired or belongs to another session."
|
|
9354
9770
|
);
|
|
9355
9771
|
}
|
|
9356
|
-
ctx2.db.delete(oauthAttempts).where(
|
|
9772
|
+
ctx2.db.delete(oauthAttempts).where(eq109(oauthAttempts.stateDigest, record.stateDigest)).run();
|
|
9357
9773
|
return record;
|
|
9358
9774
|
});
|
|
9359
9775
|
const payload = JSON.parse(decrypt(ctx, attempt.encryptedPayload));
|
|
@@ -9378,9 +9794,9 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
|
9378
9794
|
inTransaction(ctx, (ctx2) => {
|
|
9379
9795
|
const session = identityRepository(ctx2.db).session(ctx2.sessionId);
|
|
9380
9796
|
const plugin = ctx2.db.select().from(plugins).where(
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9797
|
+
and83(
|
|
9798
|
+
eq109(plugins.id, attempt.pluginId),
|
|
9799
|
+
eq109(plugins.workspaceId, workspace2.id)
|
|
9384
9800
|
)
|
|
9385
9801
|
).get();
|
|
9386
9802
|
if (!session || session.userId !== user.id || session.expiresAt <= Date.now() || !isCurrentManager(ctx2, workspace2.id, user.id)) {
|
|
@@ -9422,7 +9838,7 @@ async function finishOAuth(ctx, input2, fetcher = fetch) {
|
|
|
9422
9838
|
createdAt: timestamp,
|
|
9423
9839
|
updatedAt: timestamp
|
|
9424
9840
|
}).run();
|
|
9425
|
-
ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(
|
|
9841
|
+
ctx2.db.update(plugins).set({ credentialId, updatedAt: timestamp }).where(eq109(plugins.id, plugin.id)).run();
|
|
9426
9842
|
ctx2.db.insert(auditRecords).values({
|
|
9427
9843
|
id: randomUUID7(),
|
|
9428
9844
|
workspaceId: workspace2.id,
|
|
@@ -9480,22 +9896,22 @@ function publicRequest(request) {
|
|
|
9480
9896
|
}
|
|
9481
9897
|
|
|
9482
9898
|
// server/repositories/token-activity.ts
|
|
9483
|
-
import { and as
|
|
9899
|
+
import { and as and84, eq as eq110, sql as sql4 } from "drizzle-orm";
|
|
9484
9900
|
function recordTokenActivity(store, token, status, isMcp, hasFailed) {
|
|
9485
9901
|
const time = (/* @__PURE__ */ new Date()).toISOString();
|
|
9486
9902
|
store.db.update(accessTokens).set({
|
|
9487
9903
|
firstUsedAt: token.firstUsedAt ?? time,
|
|
9488
9904
|
lastUsedAt: time,
|
|
9489
|
-
requestCount:
|
|
9490
|
-
...hasFailed ? { errorCount:
|
|
9491
|
-
...isMcp ? { mcpRequestCount:
|
|
9905
|
+
requestCount: sql4`${accessTokens.requestCount} + 1`,
|
|
9906
|
+
...hasFailed ? { errorCount: sql4`${accessTokens.errorCount} + 1` } : { successCount: sql4`${accessTokens.successCount} + 1` },
|
|
9907
|
+
...isMcp ? { mcpRequestCount: sql4`${accessTokens.mcpRequestCount} + 1` } : { trpcRequestCount: sql4`${accessTokens.trpcRequestCount} + 1` },
|
|
9492
9908
|
lastTransport: isMcp ? "mcp" : "trpc",
|
|
9493
9909
|
lastOutcome: hasFailed ? "error" : "success",
|
|
9494
9910
|
lastStatusCode: status
|
|
9495
9911
|
}).where(
|
|
9496
|
-
|
|
9497
|
-
|
|
9498
|
-
|
|
9912
|
+
and84(
|
|
9913
|
+
eq110(accessTokens.id, token.id),
|
|
9914
|
+
eq110(accessTokens.workspaceId, token.workspaceId)
|
|
9499
9915
|
)
|
|
9500
9916
|
).run();
|
|
9501
9917
|
}
|
|
@@ -9770,7 +10186,7 @@ function createApp(dependencies) {
|
|
|
9770
10186
|
}
|
|
9771
10187
|
|
|
9772
10188
|
// server/cli/accounts.ts
|
|
9773
|
-
import { eq as
|
|
10189
|
+
import { eq as eq111, or as or6 } from "drizzle-orm";
|
|
9774
10190
|
import { createInterface } from "node:readline/promises";
|
|
9775
10191
|
import { Writable } from "node:stream";
|
|
9776
10192
|
async function resetPassword(store, email) {
|
|
@@ -9811,9 +10227,9 @@ async function resetPassword(store, email) {
|
|
|
9811
10227
|
}
|
|
9812
10228
|
const passwordHash = await password.hash(password2);
|
|
9813
10229
|
inTransaction(store, (store2) => {
|
|
9814
|
-
store2.db.update(users).set({ passwordHash }).where(
|
|
10230
|
+
store2.db.update(users).set({ passwordHash }).where(eq111(users.id, user.id)).run();
|
|
9815
10231
|
store2.db.delete(sessions).where(
|
|
9816
|
-
or6(
|
|
10232
|
+
or6(eq111(sessions.userId, user.id), eq111(sessions.pendingUserId, user.id))
|
|
9817
10233
|
).run();
|
|
9818
10234
|
});
|
|
9819
10235
|
console.log("Password changed. Existing sign-in sessions were revoked.");
|
|
@@ -9823,17 +10239,17 @@ async function resetPassword(store, email) {
|
|
|
9823
10239
|
}
|
|
9824
10240
|
|
|
9825
10241
|
// server/cli/database.ts
|
|
9826
|
-
import { z as
|
|
10242
|
+
import { z as z56 } from "zod";
|
|
9827
10243
|
|
|
9828
10244
|
// server/db/connection.ts
|
|
9829
|
-
var driver = typeof Bun === "undefined" ? await import("./node-driver-
|
|
10245
|
+
var driver = typeof Bun === "undefined" ? await import("./node-driver-75PFAG2L.js") : await import("./bun-driver-UOZIWBHK.js");
|
|
9830
10246
|
var openDatabase = driver.openDatabase;
|
|
9831
10247
|
|
|
9832
10248
|
// server/cli/database.ts
|
|
9833
|
-
import { chmodSync, constants, copyFileSync, existsSync as
|
|
9834
|
-
import { join as
|
|
10249
|
+
import { chmodSync, constants, copyFileSync, existsSync as existsSync4 } from "node:fs";
|
|
10250
|
+
import { join as join4 } from "node:path";
|
|
9835
10251
|
function verifySnapshot(sqlite) {
|
|
9836
|
-
const integrity =
|
|
10252
|
+
const integrity = z56.array(z56.object({ integrity_check: z56.string() })).parse(sqlite.query("PRAGMA integrity_check").all());
|
|
9837
10253
|
if (integrity.length !== 1 || integrity[0]?.integrity_check !== "ok") {
|
|
9838
10254
|
throw new Error("Backup integrity check failed.");
|
|
9839
10255
|
}
|
|
@@ -9846,14 +10262,14 @@ function verifySnapshot(sqlite) {
|
|
|
9846
10262
|
}
|
|
9847
10263
|
}
|
|
9848
10264
|
function backupDatabase(dataDir2, destination) {
|
|
9849
|
-
if (!
|
|
10265
|
+
if (!existsSync4(join4(dataDir2, databaseFilename))) {
|
|
9850
10266
|
throw new Error("No database to back up.");
|
|
9851
10267
|
}
|
|
9852
|
-
if (
|
|
10268
|
+
if (existsSync4(destination)) {
|
|
9853
10269
|
throw new Error("Backup destination already exists.");
|
|
9854
10270
|
}
|
|
9855
10271
|
const { sqlite: source } = openDatabase(
|
|
9856
|
-
|
|
10272
|
+
join4(dataDir2, databaseFilename),
|
|
9857
10273
|
true
|
|
9858
10274
|
);
|
|
9859
10275
|
try {
|
|
@@ -9871,8 +10287,8 @@ function backupDatabase(dataDir2, destination) {
|
|
|
9871
10287
|
}
|
|
9872
10288
|
}
|
|
9873
10289
|
function restoreDatabase(dataDir2, source) {
|
|
9874
|
-
const destination =
|
|
9875
|
-
if (
|
|
10290
|
+
const destination = join4(dataDir2, databaseFilename);
|
|
10291
|
+
if (existsSync4(destination)) {
|
|
9876
10292
|
throw new Error("Restore requires an empty installation.");
|
|
9877
10293
|
}
|
|
9878
10294
|
const { sqlite: snapshot } = openDatabase(source, true);
|
|
@@ -9881,7 +10297,7 @@ function restoreDatabase(dataDir2, source) {
|
|
|
9881
10297
|
} finally {
|
|
9882
10298
|
snapshot.close();
|
|
9883
10299
|
}
|
|
9884
|
-
if (!
|
|
10300
|
+
if (!existsSync4(join4(dataDir2, "encryption.key"))) {
|
|
9885
10301
|
throw new Error(
|
|
9886
10302
|
"Restore the original encryption.key before restoring the database."
|
|
9887
10303
|
);
|
|
@@ -9892,8 +10308,8 @@ function restoreDatabase(dataDir2, source) {
|
|
|
9892
10308
|
|
|
9893
10309
|
// server/db/index.ts
|
|
9894
10310
|
import { count, isNotNull, isNull as isNull3, or as or7 } from "drizzle-orm";
|
|
9895
|
-
import { chmodSync as chmodSync2, existsSync as
|
|
9896
|
-
import { join as
|
|
10311
|
+
import { chmodSync as chmodSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readdirSync } from "node:fs";
|
|
10312
|
+
import { join as join5 } from "node:path";
|
|
9897
10313
|
|
|
9898
10314
|
// server/shared/secrets.ts
|
|
9899
10315
|
import { createCipheriv, createDecipheriv, randomBytes as randomBytes4 } from "node:crypto";
|
|
@@ -9931,14 +10347,14 @@ function createSecretCipher(key) {
|
|
|
9931
10347
|
|
|
9932
10348
|
// server/db/index.ts
|
|
9933
10349
|
function openStore(dataDir2) {
|
|
9934
|
-
|
|
9935
|
-
const path =
|
|
9936
|
-
if (!
|
|
10350
|
+
mkdirSync2(dataDir2, { recursive: true, mode: 448 });
|
|
10351
|
+
const path = join5(dataDir2, databaseFilename);
|
|
10352
|
+
if (!existsSync5(path) && readdirSync(dataDir2).some((name) => /\.(sqlite3?|db)$/i.test(name))) {
|
|
9937
10353
|
throw new Error(
|
|
9938
10354
|
"Existing SQLite database found; use an empty data directory."
|
|
9939
10355
|
);
|
|
9940
10356
|
}
|
|
9941
|
-
if (
|
|
10357
|
+
if (existsSync5(path)) {
|
|
9942
10358
|
const probe = openDatabase(path, true);
|
|
9943
10359
|
try {
|
|
9944
10360
|
assertManagedDatabase(probe.sqlite);
|
|
@@ -9954,7 +10370,7 @@ function openStore(dataDir2) {
|
|
|
9954
10370
|
"PRAGMA foreign_keys=ON; PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL; PRAGMA busy_timeout=5000;"
|
|
9955
10371
|
);
|
|
9956
10372
|
connection.migrate(migrationsFolder);
|
|
9957
|
-
if (!
|
|
10373
|
+
if (!existsSync5(join5(dataDir2, "encryption.key"))) {
|
|
9958
10374
|
const protectedRows = [
|
|
9959
10375
|
db.select({ count: count() }).from(credentials).get()?.count ?? 0,
|
|
9960
10376
|
db.select({ count: count() }).from(users).where(
|
|
@@ -9981,13 +10397,13 @@ function openStore(dataDir2) {
|
|
|
9981
10397
|
}
|
|
9982
10398
|
|
|
9983
10399
|
// server/execution/maintenance.ts
|
|
9984
|
-
import { z as
|
|
10400
|
+
import { z as z57 } from "zod";
|
|
9985
10401
|
import { CronExpressionParser as CronExpressionParser2 } from "cron-parser";
|
|
9986
|
-
import { and as
|
|
10402
|
+
import { and as and85, eq as eq112, inArray as inArray12 } from "drizzle-orm";
|
|
9987
10403
|
function maintenance(store) {
|
|
9988
10404
|
const currentTime = now();
|
|
9989
10405
|
inTransaction(store, (store2) => {
|
|
9990
|
-
const active = store2.db.select().from(runs).where(
|
|
10406
|
+
const active = store2.db.select().from(runs).where(inArray12(runs.status, ["running", "waiting_approval"])).all();
|
|
9991
10407
|
for (const run of active) {
|
|
9992
10408
|
if (run.leaseExpiresAt && run.leaseExpiresAt <= currentTime || run.deadline && run.deadline <= currentTime) {
|
|
9993
10409
|
store2.db.update(runs).set({
|
|
@@ -9995,22 +10411,22 @@ function maintenance(store) {
|
|
|
9995
10411
|
error: "Execution stopped responding. Review side effects before retrying.",
|
|
9996
10412
|
capabilityHash: "",
|
|
9997
10413
|
updatedAt: currentTime
|
|
9998
|
-
}).where(
|
|
10414
|
+
}).where(eq112(runs.id, run.id)).run();
|
|
9999
10415
|
store2.db.update(approvals).set({ status: "interrupted" }).where(
|
|
10000
|
-
|
|
10001
|
-
|
|
10002
|
-
|
|
10416
|
+
and85(
|
|
10417
|
+
eq112(approvals.runId, run.id),
|
|
10418
|
+
eq112(approvals.status, "pending")
|
|
10003
10419
|
)
|
|
10004
10420
|
).run();
|
|
10005
10421
|
}
|
|
10006
10422
|
}
|
|
10007
|
-
for (const schedule of store2.db.select().from(schedules).where(
|
|
10423
|
+
for (const schedule of store2.db.select().from(schedules).where(eq112(schedules.enabled, true)).all()) {
|
|
10008
10424
|
if (schedule.nextRunAt > currentTime) {
|
|
10009
10425
|
continue;
|
|
10010
10426
|
}
|
|
10011
|
-
const action = store2.db.select().from(actions).where(
|
|
10427
|
+
const action = store2.db.select().from(actions).where(eq112(actions.id, schedule.actionId)).get();
|
|
10012
10428
|
if (!action) {
|
|
10013
|
-
store2.db.update(schedules).set({ enabled: false }).where(
|
|
10429
|
+
store2.db.update(schedules).set({ enabled: false }).where(eq112(schedules.id, schedule.id)).run();
|
|
10014
10430
|
continue;
|
|
10015
10431
|
}
|
|
10016
10432
|
const nextRunAt = CronExpressionParser2.parse(schedule.cron, {
|
|
@@ -10041,61 +10457,32 @@ function maintenance(store) {
|
|
|
10041
10457
|
project: action.projectId,
|
|
10042
10458
|
operation: "action",
|
|
10043
10459
|
action: action.id,
|
|
10044
|
-
inputs:
|
|
10460
|
+
inputs: z57.record(z57.string(), z57.json()).parse(schedule.inputs),
|
|
10045
10461
|
idempotency_key: `schedule:${schedule.id}:${schedule.nextRunAt}`
|
|
10046
10462
|
});
|
|
10047
|
-
store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(
|
|
10463
|
+
store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq112(runs.id, run.id)).run();
|
|
10048
10464
|
} catch (error) {
|
|
10049
10465
|
if (!(error instanceof ServiceError)) {
|
|
10050
10466
|
throw error;
|
|
10051
10467
|
}
|
|
10052
10468
|
}
|
|
10053
|
-
store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(
|
|
10469
|
+
store2.db.update(schedules).set({ nextRunAt, updatedAt: currentTime }).where(eq112(schedules.id, schedule.id)).run();
|
|
10054
10470
|
}
|
|
10055
10471
|
});
|
|
10056
10472
|
}
|
|
10057
10473
|
|
|
10058
10474
|
// server/index.ts
|
|
10059
10475
|
var dataDir = resolve3(
|
|
10060
|
-
process.env.ORGSDK_DATA_DIR ??
|
|
10476
|
+
process.env.ORGSDK_DATA_DIR ?? join6(homedir(), ".local/share/orgsdk")
|
|
10061
10477
|
);
|
|
10062
10478
|
var command = process.argv[2] ?? "server";
|
|
10063
10479
|
var hostname = process.env.HOST ?? "127.0.0.1";
|
|
10064
|
-
function serverLock() {
|
|
10065
|
-
mkdirSync2(dataDir, { recursive: true, mode: 448 });
|
|
10066
|
-
const file = join5(dataDir, "server.pid");
|
|
10067
|
-
if (existsSync5(file)) {
|
|
10068
|
-
const pid = Number(readFileSync4(file, "utf8"));
|
|
10069
|
-
if (!Number.isInteger(pid) || pid < 1) {
|
|
10070
|
-
throw new Error("Invalid server lock; inspect the data directory.");
|
|
10071
|
-
}
|
|
10072
|
-
let alive = false;
|
|
10073
|
-
try {
|
|
10074
|
-
process.kill(pid, 0);
|
|
10075
|
-
alive = true;
|
|
10076
|
-
} catch (error) {
|
|
10077
|
-
if (!(error instanceof Error) || !("code" in error) || error.code !== "ESRCH") {
|
|
10078
|
-
throw error;
|
|
10079
|
-
}
|
|
10080
|
-
}
|
|
10081
|
-
if (alive) {
|
|
10082
|
-
throw new Error("An OrgSDK server already owns this data directory.");
|
|
10083
|
-
}
|
|
10084
|
-
unlinkSync(file);
|
|
10085
|
-
}
|
|
10086
|
-
writeFileSync3(file, String(process.pid), { flag: "wx", mode: 384 });
|
|
10087
|
-
return () => {
|
|
10088
|
-
if (existsSync5(file) && readFileSync4(file, "utf8") === String(process.pid)) {
|
|
10089
|
-
unlinkSync(file);
|
|
10090
|
-
}
|
|
10091
|
-
};
|
|
10092
|
-
}
|
|
10093
10480
|
async function main() {
|
|
10094
10481
|
if (command === "reset-password") {
|
|
10095
10482
|
if (!process.argv[3]) {
|
|
10096
10483
|
throw new Error("Usage: orgsdk reset-password EMAIL");
|
|
10097
10484
|
}
|
|
10098
|
-
if (!
|
|
10485
|
+
if (!existsSync6(join6(dataDir, databaseFilename))) {
|
|
10099
10486
|
throw new Error("No installation found in this data directory.");
|
|
10100
10487
|
}
|
|
10101
10488
|
const store = openStore(dataDir);
|
|
@@ -10125,7 +10512,7 @@ async function main() {
|
|
|
10125
10512
|
if (!process.argv[3]) {
|
|
10126
10513
|
throw new Error("Usage: orgsdk restore SOURCE");
|
|
10127
10514
|
}
|
|
10128
|
-
const unlock2 = serverLock();
|
|
10515
|
+
const unlock2 = serverLock(dataDir);
|
|
10129
10516
|
try {
|
|
10130
10517
|
restoreDatabase(dataDir, resolve3(process.argv[3]));
|
|
10131
10518
|
console.log("Database restored.");
|
|
@@ -10135,7 +10522,7 @@ async function main() {
|
|
|
10135
10522
|
return;
|
|
10136
10523
|
}
|
|
10137
10524
|
if (command === "migrate") {
|
|
10138
|
-
const unlock2 = serverLock();
|
|
10525
|
+
const unlock2 = serverLock(dataDir);
|
|
10139
10526
|
try {
|
|
10140
10527
|
const store = openStore(dataDir);
|
|
10141
10528
|
store.close();
|
|
@@ -10151,7 +10538,7 @@ async function main() {
|
|
|
10151
10538
|
);
|
|
10152
10539
|
}
|
|
10153
10540
|
const ports = installationPorts(dataDir, hostname);
|
|
10154
|
-
const unlock = serverLock();
|
|
10541
|
+
const unlock = serverLock(dataDir);
|
|
10155
10542
|
try {
|
|
10156
10543
|
let handle;
|
|
10157
10544
|
const server = await listenOnInstallationPort(ports, {
|