@orgsdk/cli 2.2.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/server/index.js +386 -252
- package/dist/server/out/accounts/2fa/__next._full.txt +1 -1
- package/dist/server/out/accounts/2fa/__next._tree.txt +1 -1
- package/dist/server/out/accounts/2fa/__next.accounts.2fa.__PAGE__.txt +1 -1
- package/dist/server/out/accounts/2fa/index.html +1 -1
- package/dist/server/out/accounts/2fa/index.txt +1 -1
- package/dist/server/out/accounts/email/__next._full.txt +1 -1
- package/dist/server/out/accounts/email/__next._tree.txt +1 -1
- package/dist/server/out/accounts/email/__next.accounts.email.__PAGE__.txt +1 -1
- package/dist/server/out/accounts/email/index.html +1 -1
- package/dist/server/out/accounts/email/index.txt +1 -1
- package/dist/server/out/accounts/login/__next._full.txt +1 -1
- package/dist/server/out/accounts/login/__next._tree.txt +1 -1
- package/dist/server/out/accounts/login/__next.accounts.login.__PAGE__.txt +1 -1
- package/dist/server/out/accounts/login/index.html +1 -1
- package/dist/server/out/accounts/login/index.txt +1 -1
- package/dist/server/out/accounts/logout/__next._full.txt +1 -1
- package/dist/server/out/accounts/logout/__next._tree.txt +1 -1
- package/dist/server/out/accounts/logout/__next.accounts.logout.__PAGE__.txt +1 -1
- package/dist/server/out/accounts/logout/index.html +1 -1
- package/dist/server/out/accounts/logout/index.txt +1 -1
- package/dist/server/out/accounts/password/change/__next._full.txt +1 -1
- package/dist/server/out/accounts/password/change/__next._tree.txt +1 -1
- package/dist/server/out/accounts/password/change/__next.accounts.password.change.__PAGE__.txt +1 -1
- package/dist/server/out/accounts/password/change/index.html +1 -1
- package/dist/server/out/accounts/password/change/index.txt +1 -1
- package/dist/server/out/accounts/password/reset/__next._full.txt +1 -1
- package/dist/server/out/accounts/password/reset/__next._tree.txt +1 -1
- package/dist/server/out/accounts/password/reset/__next.accounts.password.reset.__PAGE__.txt +1 -1
- package/dist/server/out/accounts/password/reset/index.html +1 -1
- package/dist/server/out/accounts/password/reset/index.txt +1 -1
- package/dist/server/out/accounts/signup/__next._full.txt +1 -1
- package/dist/server/out/accounts/signup/__next._tree.txt +1 -1
- package/dist/server/out/accounts/signup/__next.accounts.signup.__PAGE__.txt +1 -1
- package/dist/server/out/accounts/signup/index.html +1 -1
- package/dist/server/out/accounts/signup/index.txt +1 -1
- package/dist/server/out/setup/__next._full.txt +1 -1
- package/dist/server/out/setup/__next._tree.txt +1 -1
- package/dist/server/out/setup/__next.setup.__PAGE__.txt +1 -1
- package/dist/server/out/setup/index.html +1 -1
- package/dist/server/out/setup/index.txt +1 -1
- package/dist/server/out/studio/approve/__next._full.txt +1 -1
- package/dist/server/out/studio/approve/__next._tree.txt +1 -1
- package/dist/server/out/studio/approve/__next.studio.approve.__PAGE__.txt +1 -1
- package/dist/server/out/studio/approve/index.html +1 -1
- package/dist/server/out/studio/approve/index.txt +1 -1
- package/dist/server/out/workspaces/invite/__next._full.txt +1 -1
- package/dist/server/out/workspaces/invite/__next._tree.txt +1 -1
- package/dist/server/out/workspaces/invite/__next.workspaces.invite.__PAGE__.txt +1 -1
- package/dist/server/out/workspaces/invite/index.html +1 -1
- package/dist/server/out/workspaces/invite/index.txt +1 -1
- package/docs/npm-distribution.md +8 -0
- package/docs/studio.md +3 -1
- package/package.json +2 -1
- /package/dist/server/out/_next/static/{m1cOvyKRNnDjsWBMfcCJt → LKRuw_R6wl92CsuMfKtPZ}/_buildManifest.js +0 -0
- /package/dist/server/out/_next/static/{m1cOvyKRNnDjsWBMfcCJt → LKRuw_R6wl92CsuMfKtPZ}/_clientMiddlewareManifest.js +0 -0
- /package/dist/server/out/_next/static/{m1cOvyKRNnDjsWBMfcCJt → LKRuw_R6wl92CsuMfKtPZ}/_ssgManifest.js +0 -0
package/dist/server/index.js
CHANGED
|
@@ -461,15 +461,50 @@ function studioSession(db, endpoint, audience, token) {
|
|
|
461
461
|
}
|
|
462
462
|
|
|
463
463
|
// server/index.ts
|
|
464
|
+
import { existsSync as existsSync6 } from "node:fs";
|
|
465
|
+
|
|
466
|
+
// server/platform/server-lock.ts
|
|
464
467
|
import {
|
|
465
|
-
existsSync as
|
|
466
|
-
mkdirSync
|
|
467
|
-
readFileSync as
|
|
468
|
-
|
|
469
|
-
|
|
468
|
+
existsSync as existsSync3,
|
|
469
|
+
mkdirSync,
|
|
470
|
+
readFileSync as readFileSync3,
|
|
471
|
+
writeFileSync as writeFileSync3,
|
|
472
|
+
unlinkSync
|
|
470
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
|
|
471
506
|
import { homedir } from "node:os";
|
|
472
|
-
import { join as
|
|
507
|
+
import { join as join6, resolve as resolve3 } from "node:path";
|
|
473
508
|
|
|
474
509
|
// server/mcp/oauth-callback.ts
|
|
475
510
|
import { auth } from "@modelcontextprotocol/client";
|
|
@@ -1179,7 +1214,7 @@ import { fetchRequestHandler } from "@trpc/server/adapters/fetch";
|
|
|
1179
1214
|
import { ZodError as ZodError2 } from "zod";
|
|
1180
1215
|
|
|
1181
1216
|
// server/api/mcp-dispatch.ts
|
|
1182
|
-
import { z as
|
|
1217
|
+
import { z as z48 } from "zod";
|
|
1183
1218
|
|
|
1184
1219
|
// server/actions/schemas.ts
|
|
1185
1220
|
import { z as z8 } from "zod";
|
|
@@ -1525,14 +1560,14 @@ function projectGrant(ctx, id) {
|
|
|
1525
1560
|
throw new ServiceError("FORBIDDEN", "Project is outside the client grant.");
|
|
1526
1561
|
}
|
|
1527
1562
|
}
|
|
1528
|
-
function authorizeVersion(ctx, action,
|
|
1563
|
+
function authorizeVersion(ctx, action, version2, explicit) {
|
|
1529
1564
|
if (!ctx.token) {
|
|
1530
1565
|
return;
|
|
1531
1566
|
}
|
|
1532
1567
|
if (ctx.token.projects.includes(action.projectId)) {
|
|
1533
1568
|
return;
|
|
1534
1569
|
}
|
|
1535
|
-
if (explicit && ctx.token.actionVersions.includes(
|
|
1570
|
+
if (explicit && ctx.token.actionVersions.includes(version2.id)) {
|
|
1536
1571
|
return;
|
|
1537
1572
|
}
|
|
1538
1573
|
throw new ServiceError(
|
|
@@ -1857,7 +1892,7 @@ var casesSchema = z11.array(
|
|
|
1857
1892
|
forbidden_calls: z11.array(toolName).max(100).default([])
|
|
1858
1893
|
})
|
|
1859
1894
|
).min(1).max(50);
|
|
1860
|
-
function validateCases(
|
|
1895
|
+
function validateCases(version2, value) {
|
|
1861
1896
|
const parsed = casesSchema.safeParse(value);
|
|
1862
1897
|
if (!parsed.success || Buffer.byteLength(JSON.stringify(parsed.data)) > 2e5) {
|
|
1863
1898
|
throw new ServiceError(
|
|
@@ -1871,8 +1906,8 @@ function validateCases(version, value) {
|
|
|
1871
1906
|
throw new ServiceError("BAD_REQUEST", "Test case names must be unique.");
|
|
1872
1907
|
}
|
|
1873
1908
|
names.add(testCase.name);
|
|
1874
|
-
validateContract(
|
|
1875
|
-
validateContract(
|
|
1909
|
+
validateContract(version2.inputSchema, testCase.inputs);
|
|
1910
|
+
validateContract(version2.outputSchema, testCase.expected);
|
|
1876
1911
|
}
|
|
1877
1912
|
return parsed.data.map((testCase) => ({
|
|
1878
1913
|
...testCase,
|
|
@@ -2060,11 +2095,11 @@ function findVersion(context, actionId, number) {
|
|
|
2060
2095
|
).orderBy(desc2(actionVersions.number)).limit(1).get();
|
|
2061
2096
|
}
|
|
2062
2097
|
function requireVersion(context, actionId, number) {
|
|
2063
|
-
const
|
|
2064
|
-
if (!
|
|
2098
|
+
const version2 = findVersion(context, actionId, number);
|
|
2099
|
+
if (!version2) {
|
|
2065
2100
|
throw new ServiceError("NOT_FOUND", "Action version not found.");
|
|
2066
2101
|
}
|
|
2067
|
-
return
|
|
2102
|
+
return version2;
|
|
2068
2103
|
}
|
|
2069
2104
|
function findTestSuite(context, versionId, revision3) {
|
|
2070
2105
|
return context.db.select().from(actionTestSuites).where(
|
|
@@ -2079,8 +2114,8 @@ function findTestSuite(context, versionId, revision3) {
|
|
|
2079
2114
|
// server/actions/versions.ts
|
|
2080
2115
|
function actionVersion(ctx, actionId, number) {
|
|
2081
2116
|
const action = actionsRepository(ctx).find(actionId);
|
|
2082
|
-
const
|
|
2083
|
-
return { action, version };
|
|
2117
|
+
const version2 = requireVersion(ctx, action.id, number);
|
|
2118
|
+
return { action, version: version2 };
|
|
2084
2119
|
}
|
|
2085
2120
|
function resolveActionForSave(ctx, projectId, name, id) {
|
|
2086
2121
|
const actionName = text2(name, "name");
|
|
@@ -2137,16 +2172,16 @@ function versionForSave(ctx, action, body, promotedFrom = null) {
|
|
|
2137
2172
|
|
|
2138
2173
|
// server/router/actions/version.ts
|
|
2139
2174
|
var versionProcedure = scopedProcedure("catalog:read").input(actionVersionSchema).query(({ ctx, input: input2 }) => {
|
|
2140
|
-
const { action, version } = actionVersion(ctx, input2.id, input2.version);
|
|
2141
|
-
authorizeVersion(ctx, action,
|
|
2142
|
-
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);
|
|
2143
2178
|
});
|
|
2144
2179
|
|
|
2145
2180
|
// server/router/actions/tests.ts
|
|
2146
2181
|
var testsProcedure = scopedProcedure("catalog:read").input(actionTestsSchema).query(({ ctx, input: input2 }) => {
|
|
2147
|
-
const { action, version } = actionVersion(ctx, input2.id, input2.version);
|
|
2148
|
-
authorizeVersion(ctx, action,
|
|
2149
|
-
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);
|
|
2150
2185
|
if (!selected) {
|
|
2151
2186
|
throw new ServiceError(
|
|
2152
2187
|
"NOT_FOUND",
|
|
@@ -2161,16 +2196,16 @@ var saveTestsProcedure = scopedProcedure("actions:write").input(saveTestsSchema)
|
|
|
2161
2196
|
return inTransaction(ctx, (ctx2) => {
|
|
2162
2197
|
const action = actionsRepository(ctx2).find(input2.id);
|
|
2163
2198
|
projectGrant(ctx2, action.projectId);
|
|
2164
|
-
const
|
|
2165
|
-
const cases = validateCases(
|
|
2199
|
+
const version2 = requireVersion(ctx2, action.id, input2.version);
|
|
2200
|
+
const cases = validateCases(version2, input2.cases);
|
|
2166
2201
|
const hash = digest(JSON.stringify(cases));
|
|
2167
|
-
const latest = findTestSuite(ctx2,
|
|
2202
|
+
const latest = findTestSuite(ctx2, version2.id);
|
|
2168
2203
|
if (latest?.digest === hash) {
|
|
2169
2204
|
return suiteView(latest);
|
|
2170
2205
|
}
|
|
2171
2206
|
const suite = ctx2.db.insert(actionTestSuites).values({
|
|
2172
2207
|
...base(ctx2.workspace.id),
|
|
2173
|
-
versionId:
|
|
2208
|
+
versionId: version2.id,
|
|
2174
2209
|
number: (latest?.number ?? 0) + 1,
|
|
2175
2210
|
cases,
|
|
2176
2211
|
digest: hash
|
|
@@ -2757,11 +2792,11 @@ function createRunInTransaction(ctx, body) {
|
|
|
2757
2792
|
if (setting && !setting.enabled) {
|
|
2758
2793
|
throw new ServiceError("FORBIDDEN", "Workspace execution is disabled.");
|
|
2759
2794
|
}
|
|
2760
|
-
let
|
|
2795
|
+
let version2 = null;
|
|
2761
2796
|
let action = null;
|
|
2762
2797
|
let suite = null;
|
|
2763
2798
|
if (operation === "action" || operation === "test") {
|
|
2764
|
-
({ action, version } = actionVersion(
|
|
2799
|
+
({ action, version: version2 } = actionVersion(
|
|
2765
2800
|
ctx,
|
|
2766
2801
|
text2(body.action, "action"),
|
|
2767
2802
|
body.version
|
|
@@ -2773,9 +2808,9 @@ function createRunInTransaction(ctx, body) {
|
|
|
2773
2808
|
);
|
|
2774
2809
|
}
|
|
2775
2810
|
scope(ctx, operation === "test" ? "actions:test" : "actions:run");
|
|
2776
|
-
authorizeVersion(ctx, action,
|
|
2811
|
+
authorizeVersion(ctx, action, version2, body.version !== void 0);
|
|
2777
2812
|
if (operation === "action") {
|
|
2778
|
-
validateContract(
|
|
2813
|
+
validateContract(version2.inputSchema, inputs);
|
|
2779
2814
|
}
|
|
2780
2815
|
if (operation === "test") {
|
|
2781
2816
|
if (!Number.isInteger(body.version) || typeof body.suite_revision !== "number" || !Number.isInteger(body.suite_revision)) {
|
|
@@ -2784,7 +2819,7 @@ function createRunInTransaction(ctx, body) {
|
|
|
2784
2819
|
"Tests require a version and suite revision."
|
|
2785
2820
|
);
|
|
2786
2821
|
}
|
|
2787
|
-
suite = findTestSuite(ctx,
|
|
2822
|
+
suite = findTestSuite(ctx, version2.id, body.suite_revision) ?? null;
|
|
2788
2823
|
if (!suite) {
|
|
2789
2824
|
throw new ServiceError("NOT_FOUND", "Test suite not found.");
|
|
2790
2825
|
}
|
|
@@ -2821,7 +2856,7 @@ function createRunInTransaction(ctx, body) {
|
|
|
2821
2856
|
);
|
|
2822
2857
|
}
|
|
2823
2858
|
const snapshot = z16.record(z16.string(), z16.json()).parse(projectSnapshot(ctx, project.id, operation));
|
|
2824
|
-
const source =
|
|
2859
|
+
const source = version2?.source ?? (session ? sessionSource(session, body) : sourceText(body.source));
|
|
2825
2860
|
if (session) {
|
|
2826
2861
|
Object.assign(snapshot, {
|
|
2827
2862
|
session,
|
|
@@ -2834,14 +2869,14 @@ function createRunInTransaction(ctx, body) {
|
|
|
2834
2869
|
}
|
|
2835
2870
|
Object.assign(snapshot, {
|
|
2836
2871
|
...source === void 0 ? {} : { source, source_digest: digest(source) },
|
|
2837
|
-
protocol_version: session ? 4 : operation === "validate" || operation === "test" ||
|
|
2872
|
+
protocol_version: session ? 4 : operation === "validate" || operation === "test" || version2?.validationMode === "semantic" ? 3 : 2
|
|
2838
2873
|
});
|
|
2839
|
-
if (
|
|
2874
|
+
if (version2) {
|
|
2840
2875
|
Object.assign(snapshot, {
|
|
2841
|
-
version:
|
|
2842
|
-
validation_mode:
|
|
2843
|
-
input_schema:
|
|
2844
|
-
output_schema:
|
|
2876
|
+
version: version2.number,
|
|
2877
|
+
validation_mode: version2.validationMode,
|
|
2878
|
+
input_schema: version2.inputSchema,
|
|
2879
|
+
output_schema: version2.outputSchema
|
|
2845
2880
|
});
|
|
2846
2881
|
}
|
|
2847
2882
|
if (operation === "validate") {
|
|
@@ -2867,7 +2902,7 @@ function createRunInTransaction(ctx, body) {
|
|
|
2867
2902
|
const existing = findIdempotentRun(ctx2, namespace, key);
|
|
2868
2903
|
if (existing) {
|
|
2869
2904
|
const serializeInputs = session ? canonicalJson : JSON.stringify;
|
|
2870
|
-
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)) {
|
|
2871
2906
|
throw new ServiceError(
|
|
2872
2907
|
"BAD_REQUEST",
|
|
2873
2908
|
"Idempotency key already used for a different request."
|
|
@@ -2882,7 +2917,7 @@ function createRunInTransaction(ctx, body) {
|
|
|
2882
2917
|
projectId: project.id,
|
|
2883
2918
|
actorId: ctx2.user.id,
|
|
2884
2919
|
tokenId: ctx2.token?.id ?? null,
|
|
2885
|
-
actionVersionId:
|
|
2920
|
+
actionVersionId: version2?.id ?? null,
|
|
2886
2921
|
operation,
|
|
2887
2922
|
origin: ctx2.token ? "client" : "browser",
|
|
2888
2923
|
originReference: "",
|
|
@@ -4082,9 +4117,9 @@ function authorize(ctx) {
|
|
|
4082
4117
|
return requireManager(ctx);
|
|
4083
4118
|
}
|
|
4084
4119
|
function checkedMetadata(plugin) {
|
|
4085
|
-
const
|
|
4086
|
-
const auth4 =
|
|
4087
|
-
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(
|
|
4088
4123
|
(scope2) => typeof scope2 !== "string" || !scope2 || scope2.length > 500 || /[\s\x00-\x1f]/.test(scope2)
|
|
4089
4124
|
)) {
|
|
4090
4125
|
throw new ServiceError(
|
|
@@ -4991,7 +5026,7 @@ var marketplaceSchema = z31.object({
|
|
|
4991
5026
|
});
|
|
4992
5027
|
|
|
4993
5028
|
// server/plugins/catalog.ts
|
|
4994
|
-
import { readFileSync as
|
|
5029
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
4995
5030
|
async function fetchCatalogJson(address) {
|
|
4996
5031
|
let url;
|
|
4997
5032
|
try {
|
|
@@ -5040,7 +5075,7 @@ async function fetchCatalogJson(address) {
|
|
|
5040
5075
|
async function catalogEntries() {
|
|
5041
5076
|
let entries;
|
|
5042
5077
|
try {
|
|
5043
|
-
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(
|
|
5044
5079
|
process.env.PLUGIN_CATALOG_URL ?? "https://orgsdk.ai/plugins/releases.json"
|
|
5045
5080
|
) : [];
|
|
5046
5081
|
} catch (error) {
|
|
@@ -5089,10 +5124,10 @@ async function catalogEntries() {
|
|
|
5089
5124
|
auth: jsonValue(entry.auth, "Authentication metadata")
|
|
5090
5125
|
}));
|
|
5091
5126
|
}
|
|
5092
|
-
async function catalogRelease(slug2,
|
|
5127
|
+
async function catalogRelease(slug2, version2) {
|
|
5093
5128
|
const entries = await catalogEntries();
|
|
5094
5129
|
const entry = entries.find(
|
|
5095
|
-
(entry2) => entry2?.slug === slug2 && entry2?.version ===
|
|
5130
|
+
(entry2) => entry2?.slug === slug2 && entry2?.version === version2
|
|
5096
5131
|
);
|
|
5097
5132
|
if (!entry) {
|
|
5098
5133
|
throw new ServiceError(
|
|
@@ -5110,9 +5145,9 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
|
|
|
5110
5145
|
if (!/^[a-z][a-z0-9]*(?:-[a-z][a-z0-9]*)*$/.test(slug2)) {
|
|
5111
5146
|
throw new ServiceError("BAD_REQUEST", "Invalid plugin slug.");
|
|
5112
5147
|
}
|
|
5113
|
-
const
|
|
5148
|
+
const version2 = text2(input2.version, "version");
|
|
5114
5149
|
const distribution = input2.distribution ?? "inline";
|
|
5115
|
-
const metadata2 = distribution === "external" ? await catalogRelease(slug2,
|
|
5150
|
+
const metadata2 = distribution === "external" ? await catalogRelease(slug2, version2) : {};
|
|
5116
5151
|
const source = distribution === "inline" ? sourceText(input2.source) : "";
|
|
5117
5152
|
const configuration2 = jsonValue(input2.configuration ?? {}, "Configuration");
|
|
5118
5153
|
if (distribution === "external") {
|
|
@@ -5125,7 +5160,7 @@ var createProcedure5 = browserManagerProcedure.input(pluginCreateSchema).mutatio
|
|
|
5125
5160
|
const values2 = {
|
|
5126
5161
|
projectId,
|
|
5127
5162
|
slug: slug2,
|
|
5128
|
-
version,
|
|
5163
|
+
version: version2,
|
|
5129
5164
|
distribution,
|
|
5130
5165
|
source,
|
|
5131
5166
|
configuration: configuration2,
|
|
@@ -5199,9 +5234,9 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5199
5234
|
"External plugin source is managed by its release."
|
|
5200
5235
|
);
|
|
5201
5236
|
}
|
|
5202
|
-
const
|
|
5203
|
-
const needsCatalogRelease = originalPlugin.distribution === "external" && (
|
|
5204
|
-
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;
|
|
5205
5240
|
return inTransaction(context, (transaction) => {
|
|
5206
5241
|
assertCurrentPluginManager(transaction);
|
|
5207
5242
|
const plugin = pluginsRepository(transaction).find(id);
|
|
@@ -5227,7 +5262,7 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5227
5262
|
"Configuration"
|
|
5228
5263
|
);
|
|
5229
5264
|
const source = plugin.distribution === "inline" && changes.source !== void 0 ? sourceText(changes.source) : plugin.source;
|
|
5230
|
-
if (source !== plugin.source &&
|
|
5265
|
+
if (source !== plugin.source && version2 === plugin.version) {
|
|
5231
5266
|
throw new ServiceError(
|
|
5232
5267
|
"BAD_REQUEST",
|
|
5233
5268
|
"Changed source requires a new version."
|
|
@@ -5243,7 +5278,7 @@ var updateProcedure5 = browserManagerProcedure.input(pluginChangesSchema).mutati
|
|
|
5243
5278
|
);
|
|
5244
5279
|
}
|
|
5245
5280
|
const updatedPlugin = transaction.db.update(plugins).set({
|
|
5246
|
-
version,
|
|
5281
|
+
version: version2,
|
|
5247
5282
|
source,
|
|
5248
5283
|
configuration: configuration2,
|
|
5249
5284
|
credentialId,
|
|
@@ -5736,11 +5771,11 @@ var retryProcedure = protectedProcedure.input(retryRunSchema).mutation(
|
|
|
5736
5771
|
}
|
|
5737
5772
|
scope(ctx2, required);
|
|
5738
5773
|
if (run.actionVersionId) {
|
|
5739
|
-
const
|
|
5774
|
+
const version2 = actionVersionsRepository(ctx2).find(run.actionVersionId);
|
|
5740
5775
|
authorizeVersion(
|
|
5741
5776
|
ctx2,
|
|
5742
|
-
actionsRepository(ctx2).find(
|
|
5743
|
-
|
|
5777
|
+
actionsRepository(ctx2).find(version2.actionId),
|
|
5778
|
+
version2,
|
|
5744
5779
|
true
|
|
5745
5780
|
);
|
|
5746
5781
|
} else {
|
|
@@ -6030,9 +6065,9 @@ var createProcedure8 = browserWorkspaceProcedure.input(scheduleCreateSchema).mut
|
|
|
6030
6065
|
if (!action.enabled) {
|
|
6031
6066
|
throw new ServiceError("BAD_REQUEST", "Action is disabled.");
|
|
6032
6067
|
}
|
|
6033
|
-
const
|
|
6068
|
+
const version2 = requireVersion(context2, action.id);
|
|
6034
6069
|
const inputs = jsonValue(input2.inputs ?? {}, "Inputs");
|
|
6035
|
-
validateContract(
|
|
6070
|
+
validateContract(version2.inputSchema, inputs);
|
|
6036
6071
|
const nextRunAt = nextCron(input2.cron);
|
|
6037
6072
|
const schedule = context2.db.insert(schedules).values({
|
|
6038
6073
|
...base(context2.workspace.id),
|
|
@@ -6059,9 +6094,9 @@ var updateProcedure7 = browserWorkspaceProcedure.input(scheduleUpdateSchema).mut
|
|
|
6059
6094
|
if (!action.enabled) {
|
|
6060
6095
|
throw new ServiceError("BAD_REQUEST", "Action is disabled.");
|
|
6061
6096
|
}
|
|
6062
|
-
const
|
|
6097
|
+
const version2 = requireVersion(context2, action.id);
|
|
6063
6098
|
const inputs = jsonValue(input2.inputs ?? previous.inputs, "Inputs");
|
|
6064
|
-
validateContract(
|
|
6099
|
+
validateContract(version2.inputSchema, inputs);
|
|
6065
6100
|
const cron = input2.cron ?? previous.cron;
|
|
6066
6101
|
const nextRunAt = cron !== previous.cron || !previous.enabled && input2.enabled ? nextCron(cron) : previous.nextRunAt;
|
|
6067
6102
|
const schedule = context2.db.update(schedules).set({
|
|
@@ -6162,6 +6197,127 @@ var exchange = publicProcedure.input(
|
|
|
6162
6197
|
// server/router/studio/index.ts
|
|
6163
6198
|
var studioRouter = router({ approve, discover, exchange });
|
|
6164
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
|
+
|
|
6165
6321
|
// server/router/system/health.ts
|
|
6166
6322
|
var healthProcedure = publicProcedure.query(() => ({
|
|
6167
6323
|
status: "ok",
|
|
@@ -6171,7 +6327,9 @@ var healthProcedure = publicProcedure.query(() => ({
|
|
|
6171
6327
|
|
|
6172
6328
|
// server/router/system/index.ts
|
|
6173
6329
|
var systemRouter = router({
|
|
6174
|
-
health: healthProcedure
|
|
6330
|
+
health: healthProcedure,
|
|
6331
|
+
updateStatus,
|
|
6332
|
+
requestUpdate
|
|
6175
6333
|
});
|
|
6176
6334
|
|
|
6177
6335
|
// server/router/tables/list.ts
|
|
@@ -6205,43 +6363,43 @@ var listProcedure12 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6205
6363
|
});
|
|
6206
6364
|
|
|
6207
6365
|
// server/tables/schemas.ts
|
|
6208
|
-
import { z as
|
|
6209
|
-
var identifier4 =
|
|
6210
|
-
var revision =
|
|
6211
|
-
var columns =
|
|
6212
|
-
|
|
6213
|
-
key:
|
|
6214
|
-
type:
|
|
6215
|
-
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()
|
|
6216
6374
|
})
|
|
6217
6375
|
);
|
|
6218
|
-
var values =
|
|
6219
|
-
var tableIdSchema =
|
|
6220
|
-
var createTableSchema =
|
|
6221
|
-
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({
|
|
6222
6380
|
id: identifier4,
|
|
6223
6381
|
revision,
|
|
6224
|
-
name:
|
|
6382
|
+
name: z40.string().optional(),
|
|
6225
6383
|
columns: columns.optional()
|
|
6226
6384
|
});
|
|
6227
|
-
var deleteTableSchema =
|
|
6228
|
-
var tableRowSchema =
|
|
6385
|
+
var deleteTableSchema = z40.strictObject({ id: identifier4, revision });
|
|
6386
|
+
var tableRowSchema = z40.strictObject({
|
|
6229
6387
|
id: identifier4,
|
|
6230
6388
|
rowId: identifier4
|
|
6231
6389
|
});
|
|
6232
|
-
var createRowSchema =
|
|
6390
|
+
var createRowSchema = z40.strictObject({
|
|
6233
6391
|
id: identifier4,
|
|
6234
6392
|
table_revision: revision,
|
|
6235
6393
|
values
|
|
6236
6394
|
});
|
|
6237
|
-
var updateRowSchema =
|
|
6395
|
+
var updateRowSchema = z40.strictObject({
|
|
6238
6396
|
id: identifier4,
|
|
6239
6397
|
rowId: identifier4,
|
|
6240
6398
|
table_revision: revision,
|
|
6241
6399
|
revision,
|
|
6242
6400
|
values
|
|
6243
6401
|
});
|
|
6244
|
-
var deleteRowSchema =
|
|
6402
|
+
var deleteRowSchema = z40.strictObject({
|
|
6245
6403
|
id: identifier4,
|
|
6246
6404
|
rowId: identifier4,
|
|
6247
6405
|
revision
|
|
@@ -6496,8 +6654,8 @@ var listProcedure13 = browserManagerProcedure.query(({ ctx }) => {
|
|
|
6496
6654
|
|
|
6497
6655
|
// server/router/tokens/get.ts
|
|
6498
6656
|
import { and as and61, eq as eq81 } from "drizzle-orm";
|
|
6499
|
-
import { z as
|
|
6500
|
-
var getProcedure14 = browserManagerProcedure.input(
|
|
6657
|
+
import { z as z41 } from "zod";
|
|
6658
|
+
var getProcedure14 = browserManagerProcedure.input(z41.strictObject({ id: z41.uuid() })).query(({ ctx, input: input2 }) => {
|
|
6501
6659
|
const token = ctx.db.select().from(accessTokens).where(
|
|
6502
6660
|
and61(
|
|
6503
6661
|
eq81(accessTokens.workspaceId, ctx.workspace.id),
|
|
@@ -6511,8 +6669,8 @@ var getProcedure14 = browserManagerProcedure.input(z39.strictObject({ id: z39.uu
|
|
|
6511
6669
|
});
|
|
6512
6670
|
|
|
6513
6671
|
// server/tokens/schemas.ts
|
|
6514
|
-
import { z as
|
|
6515
|
-
var clientScopes =
|
|
6672
|
+
import { z as z42 } from "zod";
|
|
6673
|
+
var clientScopes = z42.enum([
|
|
6516
6674
|
"catalog:read",
|
|
6517
6675
|
"code:execute",
|
|
6518
6676
|
"actions:write",
|
|
@@ -6521,11 +6679,11 @@ var clientScopes = z40.enum([
|
|
|
6521
6679
|
"runs:read",
|
|
6522
6680
|
"runs:cancel"
|
|
6523
6681
|
]);
|
|
6524
|
-
var tokenCreateSchema =
|
|
6525
|
-
name:
|
|
6526
|
-
scopes:
|
|
6527
|
-
projects:
|
|
6528
|
-
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([])
|
|
6529
6687
|
}).strict();
|
|
6530
6688
|
|
|
6531
6689
|
// server/router/tokens/create.ts
|
|
@@ -6565,8 +6723,8 @@ var createProcedure10 = browserManagerProcedure.input(tokenCreateSchema).output(
|
|
|
6565
6723
|
|
|
6566
6724
|
// server/router/tokens/revoke.ts
|
|
6567
6725
|
import { and as and62, eq as eq82 } from "drizzle-orm";
|
|
6568
|
-
import { z as
|
|
6569
|
-
var revokeProcedure = browserManagerProcedure.input(
|
|
6726
|
+
import { z as z43 } from "zod";
|
|
6727
|
+
var revokeProcedure = browserManagerProcedure.input(z43.strictObject({ id: z43.uuid() })).mutation(({ ctx, input: input2 }) => {
|
|
6570
6728
|
return inTransaction(ctx, (ctx2) => {
|
|
6571
6729
|
const token = ctx2.db.update(accessTokens).set({ revoked: true, updatedAt: now() }).where(
|
|
6572
6730
|
and62(
|
|
@@ -6620,10 +6778,10 @@ import { eq as eq84 } from "drizzle-orm";
|
|
|
6620
6778
|
import { desc as desc5, eq as eq83 } from "drizzle-orm";
|
|
6621
6779
|
import { and as and63 } from "drizzle-orm";
|
|
6622
6780
|
function webhookView(context, webhook) {
|
|
6623
|
-
const
|
|
6781
|
+
const version2 = actionVersionsRepository(context).find(
|
|
6624
6782
|
webhook.actionVersionId
|
|
6625
6783
|
);
|
|
6626
|
-
const action = actionsRepository(context).find(
|
|
6784
|
+
const action = actionsRepository(context).find(version2.actionId);
|
|
6627
6785
|
const deliveries = context.db.select().from(webhookDeliveries).where(
|
|
6628
6786
|
and63(
|
|
6629
6787
|
eq83(webhookDeliveries.workspaceId, workspace(context)),
|
|
@@ -6635,7 +6793,7 @@ function webhookView(context, webhook) {
|
|
|
6635
6793
|
name: webhook.name,
|
|
6636
6794
|
action_id: action.id,
|
|
6637
6795
|
action_name: action.name,
|
|
6638
|
-
version:
|
|
6796
|
+
version: version2.number,
|
|
6639
6797
|
enabled: webhook.enabled,
|
|
6640
6798
|
endpoint: `/webhooks/${webhook.id}`,
|
|
6641
6799
|
rotated_at: webhook.rotatedAt,
|
|
@@ -6661,7 +6819,7 @@ var listProcedure14 = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6661
6819
|
});
|
|
6662
6820
|
|
|
6663
6821
|
// server/router/webhooks/get.ts
|
|
6664
|
-
import { z as
|
|
6822
|
+
import { z as z44 } from "zod";
|
|
6665
6823
|
|
|
6666
6824
|
// server/repositories/webhooks.ts
|
|
6667
6825
|
import { and as and64, eq as eq85 } from "drizzle-orm";
|
|
@@ -6692,28 +6850,28 @@ function webhooksRepository(context) {
|
|
|
6692
6850
|
}
|
|
6693
6851
|
|
|
6694
6852
|
// server/router/webhooks/get.ts
|
|
6695
|
-
var getProcedure15 = browserWorkspaceProcedure.input(
|
|
6853
|
+
var getProcedure15 = browserWorkspaceProcedure.input(z44.object({ id: z44.uuid() }).strict()).query(({ ctx: context, input: input2 }) => {
|
|
6696
6854
|
const id = input2.id;
|
|
6697
6855
|
return webhookView(context, webhooksRepository(context).find(id));
|
|
6698
6856
|
});
|
|
6699
6857
|
|
|
6700
6858
|
// server/automations/webhook-schemas.ts
|
|
6701
|
-
import { z as
|
|
6702
|
-
var webhookCreateSchema =
|
|
6703
|
-
name:
|
|
6704
|
-
action:
|
|
6705
|
-
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()
|
|
6706
6864
|
}).strict();
|
|
6707
|
-
var webhookUpdateSchema =
|
|
6708
|
-
id:
|
|
6709
|
-
name:
|
|
6710
|
-
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()
|
|
6711
6869
|
}).strict();
|
|
6712
6870
|
|
|
6713
6871
|
// server/router/webhooks/create.ts
|
|
6714
6872
|
var createProcedure11 = browserManagerProcedure.input(webhookCreateSchema).mutation(({ ctx: context, input: input2 }) => {
|
|
6715
6873
|
return inTransaction(context, (context2) => {
|
|
6716
|
-
const { action, version } = actionVersion(context2, input2.action);
|
|
6874
|
+
const { action, version: version2 } = actionVersion(context2, input2.action);
|
|
6717
6875
|
if (!action.enabled) {
|
|
6718
6876
|
throw new ServiceError(
|
|
6719
6877
|
"BAD_REQUEST",
|
|
@@ -6724,7 +6882,7 @@ var createProcedure11 = browserManagerProcedure.input(webhookCreateSchema).mutat
|
|
|
6724
6882
|
const webhook = context2.db.insert(webhooks).values({
|
|
6725
6883
|
...base(context2.workspace.id),
|
|
6726
6884
|
name: input2.name,
|
|
6727
|
-
actionVersionId:
|
|
6885
|
+
actionVersionId: version2.id,
|
|
6728
6886
|
actorId: context2.user.id,
|
|
6729
6887
|
secretHash: digest(secret),
|
|
6730
6888
|
enabled: input2.enabled ?? true,
|
|
@@ -6752,8 +6910,8 @@ var updateProcedure9 = browserManagerProcedure.input(webhookUpdateSchema).mutati
|
|
|
6752
6910
|
});
|
|
6753
6911
|
|
|
6754
6912
|
// server/router/webhooks/rotate.ts
|
|
6755
|
-
import { z as
|
|
6756
|
-
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 }) => {
|
|
6757
6915
|
const id = input2.id;
|
|
6758
6916
|
return inTransaction(context, (context2) => {
|
|
6759
6917
|
const secret = randomSecret();
|
|
@@ -6810,26 +6968,26 @@ var currentProcedure = browserWorkspaceProcedure.query(({ ctx }) => {
|
|
|
6810
6968
|
import { eq as eq87 } from "drizzle-orm";
|
|
6811
6969
|
|
|
6812
6970
|
// server/workspaces/schemas.ts
|
|
6813
|
-
import { z as
|
|
6814
|
-
var membershipIdSchema =
|
|
6815
|
-
id:
|
|
6971
|
+
import { z as z47 } from "zod";
|
|
6972
|
+
var membershipIdSchema = z47.strictObject({
|
|
6973
|
+
id: z47.number().int().positive()
|
|
6816
6974
|
});
|
|
6817
|
-
var workspaceNameSchema =
|
|
6818
|
-
name:
|
|
6975
|
+
var workspaceNameSchema = z47.strictObject({
|
|
6976
|
+
name: z47.string().trim().min(1).max(100)
|
|
6819
6977
|
});
|
|
6820
|
-
var roleSchema =
|
|
6978
|
+
var roleSchema = z47.enum(["admin", "member"]);
|
|
6821
6979
|
var memberUpdateSchema = membershipIdSchema.extend({
|
|
6822
6980
|
role: roleSchema
|
|
6823
6981
|
});
|
|
6824
|
-
var ownershipSchema =
|
|
6825
|
-
membership_id:
|
|
6982
|
+
var ownershipSchema = z47.strictObject({
|
|
6983
|
+
membership_id: z47.number().int().positive()
|
|
6826
6984
|
});
|
|
6827
|
-
var invitationSchema =
|
|
6985
|
+
var invitationSchema = z47.strictObject({
|
|
6828
6986
|
email: emailSchema,
|
|
6829
6987
|
role: roleSchema
|
|
6830
6988
|
});
|
|
6831
|
-
var invitationTokenSchema =
|
|
6832
|
-
token:
|
|
6989
|
+
var invitationTokenSchema = z47.strictObject({
|
|
6990
|
+
token: z47.string().min(1)
|
|
6833
6991
|
});
|
|
6834
6992
|
|
|
6835
6993
|
// server/router/workspace/update.ts
|
|
@@ -7284,8 +7442,8 @@ var appRouter = router({
|
|
|
7284
7442
|
// server/api/mcp-dispatch.ts
|
|
7285
7443
|
async function dispatchTool(context, name, toolInput) {
|
|
7286
7444
|
const caller = appRouter.createCaller(context);
|
|
7287
|
-
const id = () =>
|
|
7288
|
-
const actionId = () =>
|
|
7445
|
+
const id = () => z48.string().parse(toolInput.id);
|
|
7446
|
+
const actionId = () => z48.string().parse(toolInput.action);
|
|
7289
7447
|
const queueSession = (session) => caller.runs.session(
|
|
7290
7448
|
sessionRunSchema.parse({
|
|
7291
7449
|
project: toolInput.project,
|
|
@@ -7306,7 +7464,7 @@ async function dispatchTool(context, name, toolInput) {
|
|
|
7306
7464
|
};
|
|
7307
7465
|
}
|
|
7308
7466
|
case "get_project_sdk":
|
|
7309
|
-
return caller.projects.sdk({ id:
|
|
7467
|
+
return caller.projects.sdk({ id: z48.string().parse(toolInput.project) });
|
|
7310
7468
|
case "execute_code":
|
|
7311
7469
|
return caller.runs.create(
|
|
7312
7470
|
createRunSchema.strip().parse({ ...toolInput, operation: "code" })
|
|
@@ -7316,23 +7474,23 @@ async function dispatchTool(context, name, toolInput) {
|
|
|
7316
7474
|
case "execute_cell":
|
|
7317
7475
|
return queueSession({
|
|
7318
7476
|
operation: "execute",
|
|
7319
|
-
id:
|
|
7320
|
-
cellId:
|
|
7321
|
-
generation:
|
|
7322
|
-
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),
|
|
7323
7481
|
after: toolInput.after
|
|
7324
7482
|
});
|
|
7325
7483
|
case "read_session":
|
|
7326
7484
|
return queueSession({
|
|
7327
7485
|
operation: "read",
|
|
7328
|
-
id:
|
|
7486
|
+
id: z48.uuid().parse(toolInput.session_id),
|
|
7329
7487
|
after: toolInput.after,
|
|
7330
7488
|
limit: toolInput.limit
|
|
7331
7489
|
});
|
|
7332
7490
|
case "close_session":
|
|
7333
7491
|
return queueSession({
|
|
7334
7492
|
operation: "close",
|
|
7335
|
-
id:
|
|
7493
|
+
id: z48.uuid().parse(toolInput.session_id)
|
|
7336
7494
|
});
|
|
7337
7495
|
case "get_run_events": {
|
|
7338
7496
|
const all = await caller.runs.events({ id: id() });
|
|
@@ -7409,17 +7567,17 @@ async function dispatchTool(context, name, toolInput) {
|
|
|
7409
7567
|
}
|
|
7410
7568
|
|
|
7411
7569
|
// server/api/mcp-schemas.ts
|
|
7412
|
-
import { z as
|
|
7413
|
-
var mcpArgumentsSchema =
|
|
7414
|
-
action:
|
|
7415
|
-
project:
|
|
7416
|
-
id:
|
|
7417
|
-
version:
|
|
7418
|
-
suite_revision:
|
|
7419
|
-
after:
|
|
7420
|
-
offset:
|
|
7421
|
-
limit:
|
|
7422
|
-
}).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());
|
|
7423
7581
|
|
|
7424
7582
|
// server/api/mcp.ts
|
|
7425
7583
|
import Ajv2 from "ajv";
|
|
@@ -8079,8 +8237,8 @@ async function handleMcp(ctx) {
|
|
|
8079
8237
|
if (ctx.request.method !== "POST") {
|
|
8080
8238
|
return new Response(null, { status: 405, headers: { Allow: "POST" } });
|
|
8081
8239
|
}
|
|
8082
|
-
const
|
|
8083
|
-
if (
|
|
8240
|
+
const version2 = ctx.request.headers.get("mcp-protocol-version");
|
|
8241
|
+
if (version2 && version2 !== "2025-03-26") {
|
|
8084
8242
|
throw new HttpError(400, "Unsupported MCP protocol version.");
|
|
8085
8243
|
}
|
|
8086
8244
|
if (ctx.request.headers.get("content-type")?.split(";")[0] !== "application/json") {
|
|
@@ -8170,7 +8328,7 @@ async function handleMcp(ctx) {
|
|
|
8170
8328
|
}
|
|
8171
8329
|
|
|
8172
8330
|
// server/automations/ingress.ts
|
|
8173
|
-
import { z as
|
|
8331
|
+
import { z as z50 } from "zod";
|
|
8174
8332
|
import { and as and71, eq as eq94 } from "drizzle-orm";
|
|
8175
8333
|
import { timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
8176
8334
|
|
|
@@ -8258,8 +8416,8 @@ async function handleWebhookIngress(ctx) {
|
|
|
8258
8416
|
role: member.role,
|
|
8259
8417
|
token: null
|
|
8260
8418
|
};
|
|
8261
|
-
const
|
|
8262
|
-
const action = actionsRepository(actorCtx).find(
|
|
8419
|
+
const version2 = actionVersionsRepository(actorCtx).find(hook.actionVersionId);
|
|
8420
|
+
const action = actionsRepository(actorCtx).find(version2.actionId);
|
|
8263
8421
|
const hash = digest(canonicalJson(payload));
|
|
8264
8422
|
return inTransaction(actorCtx, (actorCtx2) => {
|
|
8265
8423
|
const current = webhooksRepository(actorCtx2).find(hook.id);
|
|
@@ -8288,8 +8446,8 @@ async function handleWebhookIngress(ctx) {
|
|
|
8288
8446
|
project: action.projectId,
|
|
8289
8447
|
operation: "action",
|
|
8290
8448
|
action: action.id,
|
|
8291
|
-
version:
|
|
8292
|
-
inputs:
|
|
8449
|
+
version: version2.number,
|
|
8450
|
+
inputs: z50.record(z50.string(), z50.json()).parse(payload.inputs),
|
|
8293
8451
|
idempotency_key: `webhook:${hook.id}:${delivery}`
|
|
8294
8452
|
});
|
|
8295
8453
|
runsRepository(actorCtx2).update(run.id, {
|
|
@@ -8477,11 +8635,12 @@ function bootstrap(ctx) {
|
|
|
8477
8635
|
token
|
|
8478
8636
|
});
|
|
8479
8637
|
}
|
|
8638
|
+
managerHeartbeat.set(ctx.secrets, Date.now());
|
|
8480
8639
|
return json({ registrations });
|
|
8481
8640
|
}
|
|
8482
8641
|
|
|
8483
8642
|
// server/execution/claim.ts
|
|
8484
|
-
import { and as and73, asc as asc7, eq as eq97, inArray as
|
|
8643
|
+
import { and as and73, asc as asc7, eq as eq97, inArray as inArray10 } from "drizzle-orm";
|
|
8485
8644
|
function claim(ctx, worker) {
|
|
8486
8645
|
ctx.db.update(executors).set({ lastSeenAt: now() }).where(
|
|
8487
8646
|
and73(
|
|
@@ -8496,7 +8655,7 @@ function claim(ctx, worker) {
|
|
|
8496
8655
|
const active = ctx.db.select().from(runs).where(
|
|
8497
8656
|
and73(
|
|
8498
8657
|
eq97(runs.workspaceId, worker.workspaceId),
|
|
8499
|
-
|
|
8658
|
+
inArray10(runs.status, ["running", "waiting_approval"])
|
|
8500
8659
|
)
|
|
8501
8660
|
).all();
|
|
8502
8661
|
if (active.some((run) => run.projectId === worker.projectId) || active.length >= (setting?.maxConcurrentRuns ?? 4)) {
|
|
@@ -8678,11 +8837,11 @@ async function refresh(ctx, initial) {
|
|
|
8678
8837
|
}
|
|
8679
8838
|
|
|
8680
8839
|
// server/oauth/refresh.ts
|
|
8681
|
-
import { z as
|
|
8840
|
+
import { z as z52 } from "zod";
|
|
8682
8841
|
import { and as and76, eq as eq100 } from "drizzle-orm";
|
|
8683
8842
|
|
|
8684
8843
|
// server/oauth/tokens.ts
|
|
8685
|
-
import { z as
|
|
8844
|
+
import { z as z51 } from "zod";
|
|
8686
8845
|
async function tokenExchange(providerName, clientId, clientSecret, params, fetcher) {
|
|
8687
8846
|
const fields = new URLSearchParams({ ...params, client_id: clientId });
|
|
8688
8847
|
const headers = new Headers({
|
|
@@ -8723,7 +8882,7 @@ async function tokenExchange(providerName, clientId, clientSecret, params, fetch
|
|
|
8723
8882
|
}
|
|
8724
8883
|
chunks.push(item.value);
|
|
8725
8884
|
}
|
|
8726
|
-
const value =
|
|
8885
|
+
const value = z51.record(z51.string(), z51.unknown()).parse(JSON.parse(Buffer.concat(chunks).toString("utf8")));
|
|
8727
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)) {
|
|
8728
8887
|
throw new Error();
|
|
8729
8888
|
}
|
|
@@ -8769,14 +8928,14 @@ function recordSecretVersion(secret, credential) {
|
|
|
8769
8928
|
return secret;
|
|
8770
8929
|
}
|
|
8771
8930
|
function assertExecutionSecretCurrent(store, credential, secret) {
|
|
8772
|
-
const
|
|
8931
|
+
const version2 = secretVersions.get(secret);
|
|
8773
8932
|
const current = store.db.select().from(credentials).where(
|
|
8774
8933
|
and76(
|
|
8775
8934
|
eq100(credentials.id, credential.id),
|
|
8776
8935
|
eq100(credentials.workspaceId, credential.workspaceId)
|
|
8777
8936
|
)
|
|
8778
8937
|
).get();
|
|
8779
|
-
if (!
|
|
8938
|
+
if (!version2 || !current || version2.id !== current.id || version2.workspaceId !== current.workspaceId || version2.provider !== current.provider || version2.encryptedSecret !== current.encryptedSecret) {
|
|
8780
8939
|
throw new ServiceError(
|
|
8781
8940
|
"CONFLICT",
|
|
8782
8941
|
"Credential changed during execution. Retry the run."
|
|
@@ -8789,7 +8948,7 @@ async function executionSecret(store, credential, fetcher = fetch) {
|
|
|
8789
8948
|
}
|
|
8790
8949
|
if (!provider(credential.provider)) {
|
|
8791
8950
|
return recordSecretVersion(
|
|
8792
|
-
|
|
8951
|
+
z52.record(z52.string(), z52.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret))),
|
|
8793
8952
|
credential
|
|
8794
8953
|
);
|
|
8795
8954
|
}
|
|
@@ -8823,7 +8982,7 @@ async function resolveExecutionSecret(store, initial, fetcher) {
|
|
|
8823
8982
|
if (!credential || !provider(credential.provider)) {
|
|
8824
8983
|
throw new ServiceError("BAD_REQUEST", "Reconnect this credential.");
|
|
8825
8984
|
}
|
|
8826
|
-
const payload =
|
|
8985
|
+
const payload = z52.record(z52.string(), z52.unknown()).parse(JSON.parse(decrypt(store, credential.encryptedSecret)));
|
|
8827
8986
|
if (credential.provider === "xero-oauth" && Object.keys(payload).length === 1 && typeof payload.secret_accessToken === "string" && payload.secret_accessToken) {
|
|
8828
8987
|
return recordSecretVersion(
|
|
8829
8988
|
{ secret_accessToken: payload.secret_accessToken },
|
|
@@ -8924,10 +9083,10 @@ async function serveCredential(ctx, credentialId) {
|
|
|
8924
9083
|
|
|
8925
9084
|
// server/execution/shell-policy.ts
|
|
8926
9085
|
import { and as and78, asc as asc8, eq as eq103 } from "drizzle-orm";
|
|
8927
|
-
import { z as
|
|
9086
|
+
import { z as z54 } from "zod";
|
|
8928
9087
|
|
|
8929
9088
|
// server/execution/redaction.ts
|
|
8930
|
-
import { z as
|
|
9089
|
+
import { z as z53 } from "zod";
|
|
8931
9090
|
import { eq as eq102 } from "drizzle-orm";
|
|
8932
9091
|
function redact(ctx, workspaceId, value) {
|
|
8933
9092
|
const secrets = [];
|
|
@@ -8967,7 +9126,7 @@ function redact(ctx, workspaceId, value) {
|
|
|
8967
9126
|
}
|
|
8968
9127
|
return entry;
|
|
8969
9128
|
};
|
|
8970
|
-
return mask(
|
|
9129
|
+
return mask(z53.json().parse(value));
|
|
8971
9130
|
}
|
|
8972
9131
|
function bounded(value, limit = 2e5) {
|
|
8973
9132
|
if (Buffer.byteLength(JSON.stringify(value)) > limit) {
|
|
@@ -8977,10 +9136,10 @@ function bounded(value, limit = 2e5) {
|
|
|
8977
9136
|
}
|
|
8978
9137
|
|
|
8979
9138
|
// server/execution/shell-policy.ts
|
|
8980
|
-
var invocation =
|
|
9139
|
+
var invocation = z54.strictObject({
|
|
8981
9140
|
executable: executableName,
|
|
8982
|
-
args:
|
|
8983
|
-
|
|
9141
|
+
args: z54.array(
|
|
9142
|
+
z54.string().max(4096).refine((arg) => !arg.includes("\0"))
|
|
8984
9143
|
).max(64)
|
|
8985
9144
|
});
|
|
8986
9145
|
function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
|
|
@@ -9079,7 +9238,7 @@ function shellPolicyRequest(ctx, run, pluginId, approvalId, method, body) {
|
|
|
9079
9238
|
import { and as and81, eq as eq106 } from "drizzle-orm";
|
|
9080
9239
|
|
|
9081
9240
|
// server/execution/project-data.ts
|
|
9082
|
-
import { and as and80, asc as asc9, eq as eq105, inArray as
|
|
9241
|
+
import { and as and80, asc as asc9, eq as eq105, inArray as inArray11 } from "drizzle-orm";
|
|
9083
9242
|
|
|
9084
9243
|
// server/execution/data-pagination.ts
|
|
9085
9244
|
function paginateData(items, offset, limit) {
|
|
@@ -9106,50 +9265,50 @@ function paginateData(items, offset, limit) {
|
|
|
9106
9265
|
}
|
|
9107
9266
|
|
|
9108
9267
|
// server/execution/data-schemas.ts
|
|
9109
|
-
import { z as
|
|
9268
|
+
import { z as z55 } from "zod";
|
|
9110
9269
|
var pagination = {
|
|
9111
|
-
offset:
|
|
9112
|
-
limit:
|
|
9270
|
+
offset: z55.number().int().min(0).max(1e6).default(0),
|
|
9271
|
+
limit: z55.number().int().min(1).max(100).default(100)
|
|
9113
9272
|
};
|
|
9114
|
-
var tableId = { table_id:
|
|
9115
|
-
var revision2 =
|
|
9116
|
-
var content =
|
|
9273
|
+
var tableId = { table_id: z55.string().uuid() };
|
|
9274
|
+
var revision2 = z55.number().int().positive();
|
|
9275
|
+
var content = z55.string().refine(
|
|
9117
9276
|
(value) => !value.includes("\0") && Buffer.byteLength(value) <= 2e5
|
|
9118
9277
|
);
|
|
9119
|
-
var dataOperationSchema =
|
|
9120
|
-
|
|
9121
|
-
|
|
9122
|
-
|
|
9123
|
-
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"),
|
|
9124
9283
|
...tableId,
|
|
9125
9284
|
...pagination
|
|
9126
9285
|
}),
|
|
9127
|
-
|
|
9128
|
-
operation:
|
|
9286
|
+
z55.strictObject({
|
|
9287
|
+
operation: z55.literal("write_row"),
|
|
9129
9288
|
...tableId,
|
|
9130
9289
|
table_revision: revision2,
|
|
9131
|
-
values:
|
|
9132
|
-
row_id:
|
|
9290
|
+
values: z55.record(z55.string(), z55.json()),
|
|
9291
|
+
row_id: z55.string().uuid().optional(),
|
|
9133
9292
|
revision: revision2.optional()
|
|
9134
9293
|
}).refine(
|
|
9135
9294
|
(input2) => input2.row_id === void 0 === (input2.revision === void 0),
|
|
9136
9295
|
"Row updates require both row ID and revision."
|
|
9137
9296
|
),
|
|
9138
|
-
|
|
9139
|
-
operation:
|
|
9297
|
+
z55.strictObject({
|
|
9298
|
+
operation: z55.literal("delete_row"),
|
|
9140
9299
|
...tableId,
|
|
9141
|
-
row_id:
|
|
9300
|
+
row_id: z55.string().uuid(),
|
|
9142
9301
|
revision: revision2
|
|
9143
9302
|
}),
|
|
9144
|
-
|
|
9145
|
-
|
|
9146
|
-
operation:
|
|
9147
|
-
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()
|
|
9148
9307
|
}),
|
|
9149
|
-
|
|
9150
|
-
operation:
|
|
9151
|
-
document_id:
|
|
9152
|
-
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(),
|
|
9153
9312
|
content: content.optional()
|
|
9154
9313
|
})
|
|
9155
9314
|
]);
|
|
@@ -9196,7 +9355,7 @@ function projectData(context, run, body) {
|
|
|
9196
9355
|
const accessibleDocuments = context.db.select().from(documents).where(
|
|
9197
9356
|
and80(
|
|
9198
9357
|
eq105(documents.workspaceId, run.workspaceId),
|
|
9199
|
-
|
|
9358
|
+
inArray11(documents.id, grantIds(context, run, "documents"))
|
|
9200
9359
|
)
|
|
9201
9360
|
).orderBy(asc9(documents.id)).all();
|
|
9202
9361
|
if (input2.operation === "list_documents") {
|
|
@@ -9236,7 +9395,7 @@ function projectData(context, run, body) {
|
|
|
9236
9395
|
const tables = context.db.select().from(workspaceTables).where(
|
|
9237
9396
|
and80(
|
|
9238
9397
|
eq105(workspaceTables.workspaceId, run.workspaceId),
|
|
9239
|
-
|
|
9398
|
+
inArray11(workspaceTables.id, grantIds(context, run, "tables"))
|
|
9240
9399
|
)
|
|
9241
9400
|
).orderBy(asc9(workspaceTables.id)).all();
|
|
9242
9401
|
if (input2.operation === "list_tables") {
|
|
@@ -9403,9 +9562,9 @@ function handleProduct(ctx, run, route, method, body) {
|
|
|
9403
9562
|
// server/execution/register.ts
|
|
9404
9563
|
import { eq as eq107 } from "drizzle-orm";
|
|
9405
9564
|
function register(ctx, worker, body) {
|
|
9406
|
-
const
|
|
9565
|
+
const version2 = body.protocol_version;
|
|
9407
9566
|
const capabilities = body.capabilities;
|
|
9408
|
-
if (typeof
|
|
9567
|
+
if (typeof version2 !== "number" || ![1, 2, 3, 4].includes(version2) || !Array.isArray(capabilities) || capabilities.some(
|
|
9409
9568
|
(cap) => ![
|
|
9410
9569
|
"action",
|
|
9411
9570
|
"code",
|
|
@@ -9414,14 +9573,14 @@ function register(ctx, worker, body) {
|
|
|
9414
9573
|
"mcp_discover",
|
|
9415
9574
|
"session"
|
|
9416
9575
|
].includes(String(cap))
|
|
9417
|
-
) ||
|
|
9576
|
+
) || version2 < 4 && (capabilities.includes("mcp_discover") || capabilities.includes("session")) || version2 < 2 && capabilities.includes("code") || version2 < 3 && capabilities.some((cap) => ["validate", "test"].includes(cap))) {
|
|
9418
9577
|
throw new HttpError(400, "Unsupported executor protocol or capability.");
|
|
9419
9578
|
}
|
|
9420
9579
|
const validatedCapabilities = capabilities.filter(
|
|
9421
9580
|
(capability) => typeof capability === "string"
|
|
9422
9581
|
);
|
|
9423
9582
|
const registered = ctx.db.update(executors).set({
|
|
9424
|
-
protocolVersion:
|
|
9583
|
+
protocolVersion: version2,
|
|
9425
9584
|
capabilities: validatedCapabilities,
|
|
9426
9585
|
lastSeenAt: now(),
|
|
9427
9586
|
updatedAt: now()
|
|
@@ -9552,6 +9711,10 @@ async function handleExecution(ctx) {
|
|
|
9552
9711
|
if (credentialRoute && method === "GET") {
|
|
9553
9712
|
return serveCredential(ctx, credentialRoute[1]);
|
|
9554
9713
|
}
|
|
9714
|
+
if (route === "claim/" && method === "POST" && pendingUpdate(ctx.db)) {
|
|
9715
|
+
executor(ctx);
|
|
9716
|
+
return new Response(null, { status: 204 });
|
|
9717
|
+
}
|
|
9555
9718
|
return inTransaction(ctx, (ctx2) => {
|
|
9556
9719
|
if (route === "bootstrap/" && method === "POST") {
|
|
9557
9720
|
return bootstrap(ctx2);
|
|
@@ -10076,17 +10239,17 @@ async function resetPassword(store, email) {
|
|
|
10076
10239
|
}
|
|
10077
10240
|
|
|
10078
10241
|
// server/cli/database.ts
|
|
10079
|
-
import { z as
|
|
10242
|
+
import { z as z56 } from "zod";
|
|
10080
10243
|
|
|
10081
10244
|
// server/db/connection.ts
|
|
10082
10245
|
var driver = typeof Bun === "undefined" ? await import("./node-driver-75PFAG2L.js") : await import("./bun-driver-UOZIWBHK.js");
|
|
10083
10246
|
var openDatabase = driver.openDatabase;
|
|
10084
10247
|
|
|
10085
10248
|
// server/cli/database.ts
|
|
10086
|
-
import { chmodSync, constants, copyFileSync, existsSync as
|
|
10087
|
-
import { join as
|
|
10249
|
+
import { chmodSync, constants, copyFileSync, existsSync as existsSync4 } from "node:fs";
|
|
10250
|
+
import { join as join4 } from "node:path";
|
|
10088
10251
|
function verifySnapshot(sqlite) {
|
|
10089
|
-
const integrity =
|
|
10252
|
+
const integrity = z56.array(z56.object({ integrity_check: z56.string() })).parse(sqlite.query("PRAGMA integrity_check").all());
|
|
10090
10253
|
if (integrity.length !== 1 || integrity[0]?.integrity_check !== "ok") {
|
|
10091
10254
|
throw new Error("Backup integrity check failed.");
|
|
10092
10255
|
}
|
|
@@ -10099,14 +10262,14 @@ function verifySnapshot(sqlite) {
|
|
|
10099
10262
|
}
|
|
10100
10263
|
}
|
|
10101
10264
|
function backupDatabase(dataDir2, destination) {
|
|
10102
|
-
if (!
|
|
10265
|
+
if (!existsSync4(join4(dataDir2, databaseFilename))) {
|
|
10103
10266
|
throw new Error("No database to back up.");
|
|
10104
10267
|
}
|
|
10105
|
-
if (
|
|
10268
|
+
if (existsSync4(destination)) {
|
|
10106
10269
|
throw new Error("Backup destination already exists.");
|
|
10107
10270
|
}
|
|
10108
10271
|
const { sqlite: source } = openDatabase(
|
|
10109
|
-
|
|
10272
|
+
join4(dataDir2, databaseFilename),
|
|
10110
10273
|
true
|
|
10111
10274
|
);
|
|
10112
10275
|
try {
|
|
@@ -10124,8 +10287,8 @@ function backupDatabase(dataDir2, destination) {
|
|
|
10124
10287
|
}
|
|
10125
10288
|
}
|
|
10126
10289
|
function restoreDatabase(dataDir2, source) {
|
|
10127
|
-
const destination =
|
|
10128
|
-
if (
|
|
10290
|
+
const destination = join4(dataDir2, databaseFilename);
|
|
10291
|
+
if (existsSync4(destination)) {
|
|
10129
10292
|
throw new Error("Restore requires an empty installation.");
|
|
10130
10293
|
}
|
|
10131
10294
|
const { sqlite: snapshot } = openDatabase(source, true);
|
|
@@ -10134,7 +10297,7 @@ function restoreDatabase(dataDir2, source) {
|
|
|
10134
10297
|
} finally {
|
|
10135
10298
|
snapshot.close();
|
|
10136
10299
|
}
|
|
10137
|
-
if (!
|
|
10300
|
+
if (!existsSync4(join4(dataDir2, "encryption.key"))) {
|
|
10138
10301
|
throw new Error(
|
|
10139
10302
|
"Restore the original encryption.key before restoring the database."
|
|
10140
10303
|
);
|
|
@@ -10145,8 +10308,8 @@ function restoreDatabase(dataDir2, source) {
|
|
|
10145
10308
|
|
|
10146
10309
|
// server/db/index.ts
|
|
10147
10310
|
import { count, isNotNull, isNull as isNull3, or as or7 } from "drizzle-orm";
|
|
10148
|
-
import { chmodSync as chmodSync2, existsSync as
|
|
10149
|
-
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";
|
|
10150
10313
|
|
|
10151
10314
|
// server/shared/secrets.ts
|
|
10152
10315
|
import { createCipheriv, createDecipheriv, randomBytes as randomBytes4 } from "node:crypto";
|
|
@@ -10184,14 +10347,14 @@ function createSecretCipher(key) {
|
|
|
10184
10347
|
|
|
10185
10348
|
// server/db/index.ts
|
|
10186
10349
|
function openStore(dataDir2) {
|
|
10187
|
-
|
|
10188
|
-
const path =
|
|
10189
|
-
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))) {
|
|
10190
10353
|
throw new Error(
|
|
10191
10354
|
"Existing SQLite database found; use an empty data directory."
|
|
10192
10355
|
);
|
|
10193
10356
|
}
|
|
10194
|
-
if (
|
|
10357
|
+
if (existsSync5(path)) {
|
|
10195
10358
|
const probe = openDatabase(path, true);
|
|
10196
10359
|
try {
|
|
10197
10360
|
assertManagedDatabase(probe.sqlite);
|
|
@@ -10207,7 +10370,7 @@ function openStore(dataDir2) {
|
|
|
10207
10370
|
"PRAGMA foreign_keys=ON; PRAGMA journal_mode=WAL; PRAGMA synchronous=FULL; PRAGMA busy_timeout=5000;"
|
|
10208
10371
|
);
|
|
10209
10372
|
connection.migrate(migrationsFolder);
|
|
10210
|
-
if (!
|
|
10373
|
+
if (!existsSync5(join5(dataDir2, "encryption.key"))) {
|
|
10211
10374
|
const protectedRows = [
|
|
10212
10375
|
db.select({ count: count() }).from(credentials).get()?.count ?? 0,
|
|
10213
10376
|
db.select({ count: count() }).from(users).where(
|
|
@@ -10234,13 +10397,13 @@ function openStore(dataDir2) {
|
|
|
10234
10397
|
}
|
|
10235
10398
|
|
|
10236
10399
|
// server/execution/maintenance.ts
|
|
10237
|
-
import { z as
|
|
10400
|
+
import { z as z57 } from "zod";
|
|
10238
10401
|
import { CronExpressionParser as CronExpressionParser2 } from "cron-parser";
|
|
10239
|
-
import { and as and85, eq as eq112, inArray as
|
|
10402
|
+
import { and as and85, eq as eq112, inArray as inArray12 } from "drizzle-orm";
|
|
10240
10403
|
function maintenance(store) {
|
|
10241
10404
|
const currentTime = now();
|
|
10242
10405
|
inTransaction(store, (store2) => {
|
|
10243
|
-
const active = store2.db.select().from(runs).where(
|
|
10406
|
+
const active = store2.db.select().from(runs).where(inArray12(runs.status, ["running", "waiting_approval"])).all();
|
|
10244
10407
|
for (const run of active) {
|
|
10245
10408
|
if (run.leaseExpiresAt && run.leaseExpiresAt <= currentTime || run.deadline && run.deadline <= currentTime) {
|
|
10246
10409
|
store2.db.update(runs).set({
|
|
@@ -10294,7 +10457,7 @@ function maintenance(store) {
|
|
|
10294
10457
|
project: action.projectId,
|
|
10295
10458
|
operation: "action",
|
|
10296
10459
|
action: action.id,
|
|
10297
|
-
inputs:
|
|
10460
|
+
inputs: z57.record(z57.string(), z57.json()).parse(schedule.inputs),
|
|
10298
10461
|
idempotency_key: `schedule:${schedule.id}:${schedule.nextRunAt}`
|
|
10299
10462
|
});
|
|
10300
10463
|
store2.db.update(runs).set({ origin: "schedule", originReference: schedule.id }).where(eq112(runs.id, run.id)).run();
|
|
@@ -10310,45 +10473,16 @@ function maintenance(store) {
|
|
|
10310
10473
|
|
|
10311
10474
|
// server/index.ts
|
|
10312
10475
|
var dataDir = resolve3(
|
|
10313
|
-
process.env.ORGSDK_DATA_DIR ??
|
|
10476
|
+
process.env.ORGSDK_DATA_DIR ?? join6(homedir(), ".local/share/orgsdk")
|
|
10314
10477
|
);
|
|
10315
10478
|
var command = process.argv[2] ?? "server";
|
|
10316
10479
|
var hostname = process.env.HOST ?? "127.0.0.1";
|
|
10317
|
-
function serverLock() {
|
|
10318
|
-
mkdirSync2(dataDir, { recursive: true, mode: 448 });
|
|
10319
|
-
const file = join5(dataDir, "server.pid");
|
|
10320
|
-
if (existsSync5(file)) {
|
|
10321
|
-
const pid = Number(readFileSync4(file, "utf8"));
|
|
10322
|
-
if (!Number.isInteger(pid) || pid < 1) {
|
|
10323
|
-
throw new Error("Invalid server lock; inspect the data directory.");
|
|
10324
|
-
}
|
|
10325
|
-
let alive = false;
|
|
10326
|
-
try {
|
|
10327
|
-
process.kill(pid, 0);
|
|
10328
|
-
alive = true;
|
|
10329
|
-
} catch (error) {
|
|
10330
|
-
if (!(error instanceof Error) || !("code" in error) || error.code !== "ESRCH") {
|
|
10331
|
-
throw error;
|
|
10332
|
-
}
|
|
10333
|
-
}
|
|
10334
|
-
if (alive) {
|
|
10335
|
-
throw new Error("An OrgSDK server already owns this data directory.");
|
|
10336
|
-
}
|
|
10337
|
-
unlinkSync(file);
|
|
10338
|
-
}
|
|
10339
|
-
writeFileSync3(file, String(process.pid), { flag: "wx", mode: 384 });
|
|
10340
|
-
return () => {
|
|
10341
|
-
if (existsSync5(file) && readFileSync4(file, "utf8") === String(process.pid)) {
|
|
10342
|
-
unlinkSync(file);
|
|
10343
|
-
}
|
|
10344
|
-
};
|
|
10345
|
-
}
|
|
10346
10480
|
async function main() {
|
|
10347
10481
|
if (command === "reset-password") {
|
|
10348
10482
|
if (!process.argv[3]) {
|
|
10349
10483
|
throw new Error("Usage: orgsdk reset-password EMAIL");
|
|
10350
10484
|
}
|
|
10351
|
-
if (!
|
|
10485
|
+
if (!existsSync6(join6(dataDir, databaseFilename))) {
|
|
10352
10486
|
throw new Error("No installation found in this data directory.");
|
|
10353
10487
|
}
|
|
10354
10488
|
const store = openStore(dataDir);
|
|
@@ -10378,7 +10512,7 @@ async function main() {
|
|
|
10378
10512
|
if (!process.argv[3]) {
|
|
10379
10513
|
throw new Error("Usage: orgsdk restore SOURCE");
|
|
10380
10514
|
}
|
|
10381
|
-
const unlock2 = serverLock();
|
|
10515
|
+
const unlock2 = serverLock(dataDir);
|
|
10382
10516
|
try {
|
|
10383
10517
|
restoreDatabase(dataDir, resolve3(process.argv[3]));
|
|
10384
10518
|
console.log("Database restored.");
|
|
@@ -10388,7 +10522,7 @@ async function main() {
|
|
|
10388
10522
|
return;
|
|
10389
10523
|
}
|
|
10390
10524
|
if (command === "migrate") {
|
|
10391
|
-
const unlock2 = serverLock();
|
|
10525
|
+
const unlock2 = serverLock(dataDir);
|
|
10392
10526
|
try {
|
|
10393
10527
|
const store = openStore(dataDir);
|
|
10394
10528
|
store.close();
|
|
@@ -10404,7 +10538,7 @@ async function main() {
|
|
|
10404
10538
|
);
|
|
10405
10539
|
}
|
|
10406
10540
|
const ports = installationPorts(dataDir, hostname);
|
|
10407
|
-
const unlock = serverLock();
|
|
10541
|
+
const unlock = serverLock(dataDir);
|
|
10408
10542
|
try {
|
|
10409
10543
|
let handle;
|
|
10410
10544
|
const server = await listenOnInstallationPort(ports, {
|