@exulu/backend 5.21.0 → 5.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-43QIPMLT.js → chunk-BFIDSFRQ.js} +132 -0
- package/dist/{chunk-Q4DFJFUI.js → chunk-DAVYWGEE.js} +17 -3
- package/dist/{chunk-YTW26TUA.js → chunk-K7CGLUW4.js} +176 -132
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-4TT2M2JH.js → convert-exulu-tools-to-ai-sdk-tools-XEPIBTZT.js} +2 -2
- package/dist/{doc_processor-VCFQZ5WI.js → doc_processor-SR7ZCECL.js} +2 -2
- package/dist/index.cjs +844 -214
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +550 -105
- package/ee/python/documents/processing/doc_processor.presentations.test.ts +55 -0
- package/ee/python/documents/processing/doc_processor.ts +17 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -802,7 +802,7 @@ function buildStsPolicy(bucket, userId, s3prefix) {
|
|
|
802
802
|
]
|
|
803
803
|
};
|
|
804
804
|
}
|
|
805
|
-
var import_express, import_client_s3, import_s3_request_presigner, import_client_sts,
|
|
805
|
+
var import_express, import_client_s3, import_s3_request_presigner, import_client_sts, import_node_crypto2, expiresIn, s3Client, getPresignedUrl, addGeneralPrefixToKey, addUserPrefixToKey, addBucketPrefixToKey, uploadFile, listS3ObjectsByPrefix, encodeS3KeyForCopySource, copyS3Object, getS3ObjectContent, getS3ObjectStream, getS3ObjectEtag, getS3ObjectMetadataStrict, getS3ObjectSize, getS3ObjectBytes, getS3ObjectTextExact, getS3ObjectBytesWithInfo, headS3ObjectExact, putS3ObjectTextExact, deleteS3Object, listS3ObjectsExact, deleteS3ObjectsExact, getS3SignedUploadUrl, createUppyRoutes;
|
|
806
806
|
var init_uppy = __esm({
|
|
807
807
|
"src/uppy/index.ts"() {
|
|
808
808
|
"use strict";
|
|
@@ -814,7 +814,7 @@ var init_uppy = __esm({
|
|
|
814
814
|
import_client_s3 = require("@aws-sdk/client-s3");
|
|
815
815
|
import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
|
|
816
816
|
import_client_sts = require("@aws-sdk/client-sts");
|
|
817
|
-
|
|
817
|
+
import_node_crypto2 = require("crypto");
|
|
818
818
|
init_project_files();
|
|
819
819
|
init_keys();
|
|
820
820
|
expiresIn = 60 * 60 * 24 * 1;
|
|
@@ -1506,7 +1506,7 @@ var init_uppy = __esm({
|
|
|
1506
1506
|
contentType: params.type
|
|
1507
1507
|
};
|
|
1508
1508
|
};
|
|
1509
|
-
const generateS3Key2 = (filename) => `${(0,
|
|
1509
|
+
const generateS3Key2 = (filename) => `${(0, import_node_crypto2.randomUUID)()}-_EXULU_${filename}`;
|
|
1510
1510
|
const signOnServer = async (req, res, next) => {
|
|
1511
1511
|
if (!config.fileUploads) {
|
|
1512
1512
|
throw new Error("File uploads are not configured");
|
|
@@ -1591,7 +1591,7 @@ var init_uppy = __esm({
|
|
|
1591
1591
|
if (typeof type !== "string") {
|
|
1592
1592
|
return res.status(400).json({ error: "s3: content type must be a string" });
|
|
1593
1593
|
}
|
|
1594
|
-
const key = `${(0,
|
|
1594
|
+
const key = `${(0, import_node_crypto2.randomUUID)()}-_EXULU_${filename}`;
|
|
1595
1595
|
let fullKey = key;
|
|
1596
1596
|
console.log("[EXULU] global", req.headers.global);
|
|
1597
1597
|
if (!req.headers.global) {
|
|
@@ -4958,7 +4958,11 @@ var init_access_control = __esm({
|
|
|
4958
4958
|
);
|
|
4959
4959
|
return query.whereRaw("1 = 0");
|
|
4960
4960
|
}
|
|
4961
|
-
|
|
4961
|
+
const viaCompanion = user?.via_companion === true;
|
|
4962
|
+
if (viaCompanion && table.RBAC !== true) {
|
|
4963
|
+
return query.whereRaw("1 = 0");
|
|
4964
|
+
}
|
|
4965
|
+
if (!viaCompanion && table.name.plural !== "agent_sessions" && user?.super_admin === true) {
|
|
4962
4966
|
return query;
|
|
4963
4967
|
}
|
|
4964
4968
|
if (user && !user?.super_admin && (table.name.plural === "agents" || table.name.plural === "workflow_templates" || table.name.plural === "variables" || table.name.plural === "users" || table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && (!user?.role || !(table.name.plural === "agents" && (user.role.agents === "read" || user.role.agents === "write")) && !(table.name.plural === "workflow_templates" && (user.role.workflows === "read" || user.role.workflows === "write")) && !(table.name.plural === "variables" && (user.role.variables === "read" || user.role.variables === "write")) && !(table.name.plural === "users" && (user.role.users === "read" || user.role.users === "write")) && !((table.name.plural === "test_cases" || table.name.plural === "eval_sets" || table.name.plural === "eval_runs") && (user.role.evals === "read" || user.role.evals === "write")))) {
|
|
@@ -4974,16 +4978,20 @@ var init_access_control = __esm({
|
|
|
4974
4978
|
if (!hasRBAC) {
|
|
4975
4979
|
return query;
|
|
4976
4980
|
}
|
|
4977
|
-
if (user?.super_admin) {
|
|
4981
|
+
if (!viaCompanion && user?.super_admin) {
|
|
4978
4982
|
return query;
|
|
4979
4983
|
}
|
|
4980
4984
|
const prefix = field_prefix ? field_prefix + "." : "";
|
|
4981
4985
|
console.log("[EXULU] applying access control with this prefix", prefix);
|
|
4982
4986
|
try {
|
|
4983
4987
|
query = query.where(function() {
|
|
4984
|
-
|
|
4988
|
+
if (!viaCompanion) {
|
|
4989
|
+
this.where(`${prefix}rights_mode`, "public");
|
|
4990
|
+
}
|
|
4985
4991
|
if (user) {
|
|
4986
|
-
|
|
4992
|
+
if (!viaCompanion) {
|
|
4993
|
+
this.orWhere(`${prefix}created_by`, user.id);
|
|
4994
|
+
}
|
|
4987
4995
|
this.orWhere(function() {
|
|
4988
4996
|
this.where(`${prefix}rights_mode`, "users").whereExists(function() {
|
|
4989
4997
|
this.select("*").from("rbac").whereRaw(
|
|
@@ -6733,6 +6741,9 @@ var init_core_schema = __esm({
|
|
|
6733
6741
|
// to protect. /settings and /panel are unaffected: both read row.agent_slots
|
|
6734
6742
|
// straight off the knex row, not through the generated GraphQL field.
|
|
6735
6743
|
{ name: "agent_slots", type: "json", hidden: true },
|
|
6744
|
+
// Released for the public companion server. Only meaningful for
|
|
6745
|
+
// auth_mode "regular" (validateExternalAccess). Not reported by /meta.
|
|
6746
|
+
{ name: "external_access", type: "boolean", default: false },
|
|
6736
6747
|
// Artifact library (2026-12): how a share presents itself and is found in
|
|
6737
6748
|
// the Artifacts screen. All optional, all additive — a database that never
|
|
6738
6749
|
// ran init-db for them reads them as absent, and every reader coerces.
|
|
@@ -9905,13 +9916,13 @@ function oauthBlobToRecord(b) {
|
|
|
9905
9916
|
expiresAt: b.expiresAt ? new Date(b.expiresAt) : null
|
|
9906
9917
|
};
|
|
9907
9918
|
}
|
|
9908
|
-
var import_crypto_js2,
|
|
9919
|
+
var import_crypto_js2, import_node_crypto3, OAUTH_CALLBACK_PATH, STATE_TTL_MS, EXPIRY_SKEW_MS, getOauthRedirectUri, toBase64Url, fromBase64Url, encryptOauthState, decryptOauthState, buildAuthorizationUrl, tokenResponseToRecord, postTokenEndpoint, exchangeCodeForTokens, refreshAccessToken, getValidAccessToken;
|
|
9909
9920
|
var init_flow = __esm({
|
|
9910
9921
|
"src/exulu/auth/flow.ts"() {
|
|
9911
9922
|
"use strict";
|
|
9912
9923
|
init_cjs_shims();
|
|
9913
9924
|
import_crypto_js2 = __toESM(require("crypto-js"), 1);
|
|
9914
|
-
|
|
9925
|
+
import_node_crypto3 = require("crypto");
|
|
9915
9926
|
init_credential_store();
|
|
9916
9927
|
init_provider_key();
|
|
9917
9928
|
OAUTH_CALLBACK_PATH = "/oauth/callback";
|
|
@@ -9963,7 +9974,7 @@ var init_flow = __esm({
|
|
|
9963
9974
|
config
|
|
9964
9975
|
}) => {
|
|
9965
9976
|
const pkce = config.pkce !== false;
|
|
9966
|
-
const codeVerifier = pkce ? (0,
|
|
9977
|
+
const codeVerifier = pkce ? (0, import_node_crypto3.randomBytes)(48).toString("base64url") : void 0;
|
|
9967
9978
|
const state = encryptOauthState({
|
|
9968
9979
|
provider: providerKeyFor(toolId, config),
|
|
9969
9980
|
toolId,
|
|
@@ -9982,7 +9993,7 @@ var init_flow = __esm({
|
|
|
9982
9993
|
if (codeVerifier) {
|
|
9983
9994
|
url.searchParams.set(
|
|
9984
9995
|
"code_challenge",
|
|
9985
|
-
(0,
|
|
9996
|
+
(0, import_node_crypto3.createHash)("sha256").update(codeVerifier).digest("base64url")
|
|
9986
9997
|
);
|
|
9987
9998
|
url.searchParams.set("code_challenge_method", "S256");
|
|
9988
9999
|
}
|
|
@@ -10303,7 +10314,7 @@ var init_rbac_resolver = __esm({
|
|
|
10303
10314
|
});
|
|
10304
10315
|
|
|
10305
10316
|
// src/exulu/shared-artifacts.ts
|
|
10306
|
-
var import_bcryptjs2, normalizeS3Key, isHtmlKey, deriveFilename, slugifyShareName, isExpired, validateCreateInput, validateAgentSlots, readAgentSlots, RIGHTS_MODES, canManageShare, validateUpdateInput, ownsObjectKey, planShareUpdate, hashSharePassword, verifySharePassword, contentHeadersFor, publicMetaFor, getSharedArtifactByName;
|
|
10317
|
+
var import_bcryptjs2, normalizeS3Key, isHtmlKey, deriveFilename, slugifyShareName, isExpired, validateCreateInput, validateAgentSlots, readAgentSlots, EXTERNAL_LOGIN_ONLY, EXTERNAL_NEEDS_TEAM, EXTERNAL_SUPER_ADMIN_ONLY, EXTERNAL_TEAM_NAME, validateExternalAccess, mayChangeExternalRelease, teamNamesByIds, externalAccessCheckApplies, externalAccessNeedsTeams, validateExternalAccessUpdate, resultingRightsMode, RIGHTS_MODES, canManageShare, validateUpdateInput, ownsObjectKey, planShareUpdate, hashSharePassword, verifySharePassword, contentHeadersFor, publicMetaFor, getSharedArtifactByName;
|
|
10307
10318
|
var init_shared_artifacts = __esm({
|
|
10308
10319
|
"src/exulu/shared-artifacts.ts"() {
|
|
10309
10320
|
"use strict";
|
|
@@ -10378,6 +10389,51 @@ var init_shared_artifacts = __esm({
|
|
|
10378
10389
|
})() : value;
|
|
10379
10390
|
return Array.isArray(parsed) ? parsed : [];
|
|
10380
10391
|
};
|
|
10392
|
+
EXTERNAL_LOGIN_ONLY = "External release requires a login share.";
|
|
10393
|
+
EXTERNAL_NEEDS_TEAM = "External release requires the share to be granted to at least one team.";
|
|
10394
|
+
EXTERNAL_SUPER_ADMIN_ONLY = "Only a super admin can release an artifact externally.";
|
|
10395
|
+
EXTERNAL_TEAM_NAME = "external";
|
|
10396
|
+
validateExternalAccess = (input) => {
|
|
10397
|
+
const flag2 = input.external_access;
|
|
10398
|
+
if (flag2 === void 0) return null;
|
|
10399
|
+
if (typeof flag2 !== "boolean") return "external_access must be a boolean.";
|
|
10400
|
+
if (!flag2) return null;
|
|
10401
|
+
if (input.auth_mode !== "regular") return EXTERNAL_LOGIN_ONLY;
|
|
10402
|
+
const teams = input.teams ?? [];
|
|
10403
|
+
if (input.rights_mode !== "teams" || teams.length === 0) return EXTERNAL_NEEDS_TEAM;
|
|
10404
|
+
if (teams.some((t) => String(t.name).trim().toLowerCase() === EXTERNAL_TEAM_NAME)) {
|
|
10405
|
+
return `The team "${EXTERNAL_TEAM_NAME}" holds self-registered guests and cannot be used for external release.`;
|
|
10406
|
+
}
|
|
10407
|
+
return null;
|
|
10408
|
+
};
|
|
10409
|
+
mayChangeExternalRelease = (user, requested, current) => requested !== true || current === true || user.super_admin === true;
|
|
10410
|
+
teamNamesByIds = async (db2, ids) => {
|
|
10411
|
+
const clean = ids.filter((id) => id !== void 0 && id !== null);
|
|
10412
|
+
if (!clean.length) return [];
|
|
10413
|
+
const rows = await db2("teams").whereIn("id", clean).select("name");
|
|
10414
|
+
return rows;
|
|
10415
|
+
};
|
|
10416
|
+
externalAccessCheckApplies = (input, row) => input.external_access !== void 0 || row.external_access === true;
|
|
10417
|
+
externalAccessNeedsTeams = (input, row) => {
|
|
10418
|
+
const mode = input.auth_mode ?? row.auth_mode;
|
|
10419
|
+
const effective = input.external_access !== void 0 ? input.external_access : row.external_access === true;
|
|
10420
|
+
return effective === true && mode === "regular";
|
|
10421
|
+
};
|
|
10422
|
+
validateExternalAccessUpdate = (input, row, teams) => {
|
|
10423
|
+
const mode = input.auth_mode ?? row.auth_mode;
|
|
10424
|
+
const effective = input.external_access !== void 0 ? input.external_access : row.external_access === true;
|
|
10425
|
+
return validateExternalAccess({
|
|
10426
|
+
external_access: effective,
|
|
10427
|
+
auth_mode: mode,
|
|
10428
|
+
rights_mode: resultingRightsMode(input, row),
|
|
10429
|
+
teams
|
|
10430
|
+
});
|
|
10431
|
+
};
|
|
10432
|
+
resultingRightsMode = (input, row) => {
|
|
10433
|
+
const mode = input.auth_mode ?? row.auth_mode;
|
|
10434
|
+
if (mode !== "regular") return "public";
|
|
10435
|
+
return input.rights_mode ?? (row.auth_mode === "regular" ? row.rights_mode ?? "private" : "private");
|
|
10436
|
+
};
|
|
10381
10437
|
RIGHTS_MODES = /* @__PURE__ */ new Set(["private", "users", "roles", "teams", "public"]);
|
|
10382
10438
|
canManageShare = (row, user) => user.super_admin === true || row.created_by != null && String(row.created_by) === String(user.id);
|
|
10383
10439
|
validateUpdateInput = (input, row, now) => {
|
|
@@ -10426,15 +10482,12 @@ var init_shared_artifacts = __esm({
|
|
|
10426
10482
|
if (input.content_type !== void 0) patch.content_type = input.content_type;
|
|
10427
10483
|
patch.password_hash = mode === "password" ? newPasswordHash ?? row.password_hash : null;
|
|
10428
10484
|
if (input.expires_at !== void 0) patch.expires_at = input.expires_at;
|
|
10429
|
-
|
|
10430
|
-
patch.rights_mode = input.rights_mode ?? (row.auth_mode === "regular" ? row.rights_mode ?? "private" : "private");
|
|
10431
|
-
} else {
|
|
10432
|
-
patch.rights_mode = "public";
|
|
10433
|
-
}
|
|
10485
|
+
patch.rights_mode = resultingRightsMode(input, row);
|
|
10434
10486
|
if (input.agent_slots !== void 0) {
|
|
10435
10487
|
const slotsResult = validateAgentSlots(input.agent_slots);
|
|
10436
10488
|
if (slotsResult.ok) patch.agent_slots = slotsResult.slots;
|
|
10437
10489
|
}
|
|
10490
|
+
if (typeof input.external_access === "boolean") patch.external_access = input.external_access;
|
|
10438
10491
|
return patch;
|
|
10439
10492
|
};
|
|
10440
10493
|
hashSharePassword = (password) => import_bcryptjs2.default.hash(password, 10);
|
|
@@ -11540,6 +11593,39 @@ var init_decisions = __esm({
|
|
|
11540
11593
|
}
|
|
11541
11594
|
});
|
|
11542
11595
|
|
|
11596
|
+
// src/exulu/companion/write-grant.ts
|
|
11597
|
+
var idOf, hasCompanionWriteGrant;
|
|
11598
|
+
var init_write_grant = __esm({
|
|
11599
|
+
"src/exulu/companion/write-grant.ts"() {
|
|
11600
|
+
"use strict";
|
|
11601
|
+
init_cjs_shims();
|
|
11602
|
+
idOf = (v) => {
|
|
11603
|
+
const id = typeof v === "object" && v !== null ? v.id : v;
|
|
11604
|
+
if (typeof id === "number") return id;
|
|
11605
|
+
if (typeof id === "string" && id !== "") return id;
|
|
11606
|
+
return void 0;
|
|
11607
|
+
};
|
|
11608
|
+
hasCompanionWriteGrant = async (db2, entity, id, user, rightsMode) => {
|
|
11609
|
+
let grantee;
|
|
11610
|
+
if (rightsMode === "users") {
|
|
11611
|
+
grantee = { access_type: "User", user_id: user.id };
|
|
11612
|
+
} else if (rightsMode === "roles") {
|
|
11613
|
+
const roleId = idOf(user.role);
|
|
11614
|
+
if (roleId === void 0) return false;
|
|
11615
|
+
grantee = { access_type: "Role", role_id: roleId };
|
|
11616
|
+
} else if (rightsMode === "teams") {
|
|
11617
|
+
const teamId = idOf(user.team);
|
|
11618
|
+
if (teamId === void 0) return false;
|
|
11619
|
+
grantee = { access_type: "Team", team_id: teamId };
|
|
11620
|
+
} else {
|
|
11621
|
+
return false;
|
|
11622
|
+
}
|
|
11623
|
+
const grant = await db2.from("rbac").where({ entity, target_resource_id: id, rights: "write", ...grantee }).first();
|
|
11624
|
+
return !!grant;
|
|
11625
|
+
};
|
|
11626
|
+
}
|
|
11627
|
+
});
|
|
11628
|
+
|
|
11543
11629
|
// src/utils/check-item-write-access.ts
|
|
11544
11630
|
var checkItemWriteAccess;
|
|
11545
11631
|
var init_check_item_write_access = __esm({
|
|
@@ -11548,10 +11634,15 @@ var init_check_item_write_access = __esm({
|
|
|
11548
11634
|
init_cjs_shims();
|
|
11549
11635
|
init_client();
|
|
11550
11636
|
init_table_names();
|
|
11637
|
+
init_write_grant();
|
|
11551
11638
|
checkItemWriteAccess = async (context, record, user) => {
|
|
11552
11639
|
if (!user) {
|
|
11553
11640
|
return false;
|
|
11554
11641
|
}
|
|
11642
|
+
if (user.via_companion === true) {
|
|
11643
|
+
const { db: db3 } = await postgresClient();
|
|
11644
|
+
return hasCompanionWriteGrant(db3, getTableName(context.id), record.id, user, record.rights_mode);
|
|
11645
|
+
}
|
|
11555
11646
|
if (user.super_admin === true) {
|
|
11556
11647
|
return true;
|
|
11557
11648
|
}
|
|
@@ -12070,14 +12161,14 @@ var init_context_read_tools = __esm({
|
|
|
12070
12161
|
});
|
|
12071
12162
|
|
|
12072
12163
|
// src/templates/tools/context-write-tools.ts
|
|
12073
|
-
var import_zod7,
|
|
12164
|
+
var import_zod7, import_node_crypto4, MAX_CONTEXT_SEGMENT, contextToolSegment, itemNotFoundMessage, isHiddenField, RESERVED_INPUT_KEYS, buildWriteSchema, BARE_FILENAME, attachSessionFiles, canonicalizeEnumFields, pickContent, jobNote, createContextWriteTools, createKbEditorPickerTool, collectKbWriteTools;
|
|
12074
12165
|
var init_context_write_tools = __esm({
|
|
12075
12166
|
"src/templates/tools/context-write-tools.ts"() {
|
|
12076
12167
|
"use strict";
|
|
12077
12168
|
init_cjs_shims();
|
|
12078
12169
|
init_tool2();
|
|
12079
12170
|
import_zod7 = require("zod");
|
|
12080
|
-
|
|
12171
|
+
import_node_crypto4 = require("crypto");
|
|
12081
12172
|
init_session_files();
|
|
12082
12173
|
init_uppy();
|
|
12083
12174
|
init_sanitize_name();
|
|
@@ -12207,7 +12298,7 @@ var init_context_write_tools = __esm({
|
|
|
12207
12298
|
return `"${name}" has type "${ext || "none"}", but the ${field.input} field only accepts ${field.allowed.join(", ")}.`;
|
|
12208
12299
|
}
|
|
12209
12300
|
const sourceKey = `${sessionFilePrefix(deps.sessionOwnerId ?? owner ?? "api", sessionID, uploads.s3prefix)}${name}`;
|
|
12210
|
-
const destKey = `${general}user_${owner}/${(0,
|
|
12301
|
+
const destKey = `${general}user_${owner}/${(0, import_node_crypto4.randomUUID)()}-_EXULU_${name}`;
|
|
12211
12302
|
try {
|
|
12212
12303
|
await copy(sourceKey, destKey, exuluConfig);
|
|
12213
12304
|
} catch (error) {
|
|
@@ -12452,20 +12543,20 @@ function hasProjectAccess(args) {
|
|
|
12452
12543
|
case "users":
|
|
12453
12544
|
return granted(rbac.users, user.id);
|
|
12454
12545
|
case "roles":
|
|
12455
|
-
return granted(rbac.roles,
|
|
12546
|
+
return granted(rbac.roles, idOf2(user.role));
|
|
12456
12547
|
case "teams":
|
|
12457
|
-
return granted(rbac.teams,
|
|
12548
|
+
return granted(rbac.teams, idOf2(user.team));
|
|
12458
12549
|
default:
|
|
12459
12550
|
return false;
|
|
12460
12551
|
}
|
|
12461
12552
|
}
|
|
12462
|
-
var sameEntityId,
|
|
12553
|
+
var sameEntityId, idOf2;
|
|
12463
12554
|
var init_project_access = __esm({
|
|
12464
12555
|
"src/exulu/project-access.ts"() {
|
|
12465
12556
|
"use strict";
|
|
12466
12557
|
init_cjs_shims();
|
|
12467
12558
|
sameEntityId = (a, b) => a != null && b != null && a !== "" && b !== "" && String(a) === String(b);
|
|
12468
|
-
|
|
12559
|
+
idOf2 = (v) => typeof v === "object" && v ? v.id : v;
|
|
12469
12560
|
}
|
|
12470
12561
|
});
|
|
12471
12562
|
|
|
@@ -12633,7 +12724,7 @@ async function createProjectForUser(db2, user, input) {
|
|
|
12633
12724
|
const values = { name, ...description ? { description } : {} };
|
|
12634
12725
|
const validation = prepareItemWrite({ fields: projectFields(), existing: null, input: values });
|
|
12635
12726
|
if (!validation.ok) throw new Error(validation.message);
|
|
12636
|
-
const row = { ...values, id: (0,
|
|
12727
|
+
const row = { ...values, id: (0, import_node_crypto5.randomUUID)(), created_by: user.id, rights_mode: "private" };
|
|
12637
12728
|
const [created] = await db2("projects").insert(row).returning(["id", "name"]);
|
|
12638
12729
|
if (!created?.id) throw new Error("The project could not be created.");
|
|
12639
12730
|
return { id: String(created.id), name: String(created.name ?? name) };
|
|
@@ -12730,12 +12821,12 @@ function planMove(args) {
|
|
|
12730
12821
|
if (batch.length > 0) batches.push(batch);
|
|
12731
12822
|
return { batches, skipped };
|
|
12732
12823
|
}
|
|
12733
|
-
var
|
|
12824
|
+
var import_node_crypto5, MAX_PROJECT_NAME_LENGTH, MAX_PROJECT_DESCRIPTION_LENGTH, TOOL_OUTPUT_PREFIX, cachedProjectFields, projectFields, bareId, SKIP_CLASH, SKIP_UNKNOWN, SKIP_NESTED, SKIP_TOO_LARGE, SKIP_PROJECT_FULL, isDefaultMoveCandidate;
|
|
12734
12825
|
var init_project_create = __esm({
|
|
12735
12826
|
"src/exulu/project-create.ts"() {
|
|
12736
12827
|
"use strict";
|
|
12737
12828
|
init_cjs_shims();
|
|
12738
|
-
|
|
12829
|
+
import_node_crypto5 = require("crypto");
|
|
12739
12830
|
init_rbac_resolver();
|
|
12740
12831
|
init_artifact_filter();
|
|
12741
12832
|
init_core_schema();
|
|
@@ -13970,12 +14061,12 @@ async function resolveSkill(db2, ref) {
|
|
|
13970
14061
|
const byId = /^[0-9a-f-]{36}$/i.test(value) ? await db2("skills").where({ id: value }).first() : null;
|
|
13971
14062
|
return byId ?? await resolveSkillByName(db2, value);
|
|
13972
14063
|
}
|
|
13973
|
-
var
|
|
14064
|
+
var import_node_crypto6, import_zod11, MAX_READ_BYTES, defaultIo, err2, safeSkillPath, contentTypeFor, yamlString, ensureFrontmatter, generalPrefix3, relativePaths, normalizeFiles, actionsFileError, createSkillAuthorTools, createSkillAuthorPickerTool, collectSkillAuthorTools;
|
|
13974
14065
|
var init_skill_author_tools = __esm({
|
|
13975
14066
|
"src/templates/tools/skill-author-tools.ts"() {
|
|
13976
14067
|
"use strict";
|
|
13977
14068
|
init_cjs_shims();
|
|
13978
|
-
|
|
14069
|
+
import_node_crypto6 = require("crypto");
|
|
13979
14070
|
import_zod11 = require("zod");
|
|
13980
14071
|
init_tool2();
|
|
13981
14072
|
init_client();
|
|
@@ -14180,7 +14271,7 @@ ${content}`
|
|
|
14180
14271
|
const db2 = await getDb();
|
|
14181
14272
|
if (await resolveSkillByName(db2, name)) return err2(`A skill named "${name}" already exists. Use skill_update to change it, or choose another name.`);
|
|
14182
14273
|
const rights_mode = decision?.rights_mode ?? "private";
|
|
14183
|
-
const skillId = (0,
|
|
14274
|
+
const skillId = (0, import_node_crypto6.randomUUID)();
|
|
14184
14275
|
const stamp2 = now().toISOString();
|
|
14185
14276
|
for (const f of files) {
|
|
14186
14277
|
await io.upload(Buffer.from(f.content, "utf8"), `skills/${skillId}/v1/${f.path}`, exuluConfig, contentTypeFor(f.path));
|
|
@@ -14513,7 +14604,7 @@ async function syncProjectDir(args) {
|
|
|
14513
14604
|
await (0, import_promises2.rename)((0, import_node_path6.join)(old, name), (0, import_node_path6.join)(staging, name));
|
|
14514
14605
|
const moved = await (0, import_promises2.lstat)((0, import_node_path6.join)(staging, name)).catch(() => null);
|
|
14515
14606
|
if (!moved?.isFile()) {
|
|
14516
|
-
await (0, import_promises2.rename)((0, import_node_path6.join)(staging, name), (0, import_node_path6.join)(old, `.rejected-${(0,
|
|
14607
|
+
await (0, import_promises2.rename)((0, import_node_path6.join)(staging, name), (0, import_node_path6.join)(old, `.rejected-${(0, import_node_crypto7.randomBytes)(4).toString("hex")}`)).catch(() => {
|
|
14517
14608
|
});
|
|
14518
14609
|
continue;
|
|
14519
14610
|
}
|
|
@@ -14569,13 +14660,13 @@ async function resolveSandboxProjectId(args, deps) {
|
|
|
14569
14660
|
return null;
|
|
14570
14661
|
}
|
|
14571
14662
|
}
|
|
14572
|
-
var import_promises2,
|
|
14663
|
+
var import_promises2, import_node_crypto7, import_node_path6, import_node_child_process3, import_node_util2, isFlatName, HELPER_KINDS, helperRoot, helperPath, execFileAsync2, DAY_MS3, errCode;
|
|
14573
14664
|
var init_project_sync = __esm({
|
|
14574
14665
|
"ee/invoke-skills/project-sync.ts"() {
|
|
14575
14666
|
"use strict";
|
|
14576
14667
|
init_cjs_shims();
|
|
14577
14668
|
import_promises2 = require("fs/promises");
|
|
14578
|
-
|
|
14669
|
+
import_node_crypto7 = require("crypto");
|
|
14579
14670
|
import_node_path6 = require("path");
|
|
14580
14671
|
import_node_child_process3 = require("child_process");
|
|
14581
14672
|
import_node_util2 = require("util");
|
|
@@ -14585,7 +14676,7 @@ var init_project_sync = __esm({
|
|
|
14585
14676
|
isFlatName = (name) => !!name && !name.includes("/") && !name.includes("\\") && name !== "." && name !== "..";
|
|
14586
14677
|
HELPER_KINDS = [".project-staging", ".project-trash"];
|
|
14587
14678
|
helperRoot = (sessionDir, kind) => (0, import_node_path6.join)((0, import_node_path6.dirname)(sessionDir), kind);
|
|
14588
|
-
helperPath = (sessionDir, kind) => (0, import_node_path6.join)(helperRoot(sessionDir, kind), `${(0, import_node_path6.basename)(sessionDir)}-${(0,
|
|
14679
|
+
helperPath = (sessionDir, kind) => (0, import_node_path6.join)(helperRoot(sessionDir, kind), `${(0, import_node_path6.basename)(sessionDir)}-${(0, import_node_crypto7.randomBytes)(8).toString("hex")}`);
|
|
14589
14680
|
execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process3.execFile);
|
|
14590
14681
|
DAY_MS3 = 24 * 60 * 60 * 1e3;
|
|
14591
14682
|
errCode = (err4) => err4?.code;
|
|
@@ -14688,7 +14779,7 @@ async function writeFileInside(sessionDir, relativePath, bytes, opts = {}) {
|
|
|
14688
14779
|
if (opts.notUnder !== void 0 && await landsInside(sessionDir, destination, opts.notUnder)) {
|
|
14689
14780
|
throw new UnsafeSessionPathError(`Refusing to write ${destination}: it lands in ${opts.notUnder}/.`);
|
|
14690
14781
|
}
|
|
14691
|
-
const temp = (0, import_node_path7.join)(parent, `.exulu-write-${(0,
|
|
14782
|
+
const temp = (0, import_node_path7.join)(parent, `.exulu-write-${(0, import_node_crypto8.randomBytes)(8).toString("hex")}`);
|
|
14692
14783
|
await (0, import_promises3.writeFile)(temp, bytes, { flag: "wx" });
|
|
14693
14784
|
try {
|
|
14694
14785
|
await (0, import_promises3.rename)(temp, destination);
|
|
@@ -14754,14 +14845,14 @@ async function landsInside(sessionDir, path4, relativeDir) {
|
|
|
14754
14845
|
return errCode2(err4) !== "ENOTDIR";
|
|
14755
14846
|
}
|
|
14756
14847
|
}
|
|
14757
|
-
var import_node_fs4, import_promises3,
|
|
14848
|
+
var import_node_fs4, import_promises3, import_node_crypto8, import_node_path7, UnsafeSessionPathError, errCode2, isInside, MAX_LINK_HOPS;
|
|
14758
14849
|
var init_safe_fs = __esm({
|
|
14759
14850
|
"ee/invoke-skills/safe-fs.ts"() {
|
|
14760
14851
|
"use strict";
|
|
14761
14852
|
init_cjs_shims();
|
|
14762
14853
|
import_node_fs4 = require("fs");
|
|
14763
14854
|
import_promises3 = require("fs/promises");
|
|
14764
|
-
|
|
14855
|
+
import_node_crypto8 = require("crypto");
|
|
14765
14856
|
init_project_sync();
|
|
14766
14857
|
import_node_path7 = require("path");
|
|
14767
14858
|
init_session_file_adopt();
|
|
@@ -14778,12 +14869,12 @@ var init_safe_fs = __esm({
|
|
|
14778
14869
|
});
|
|
14779
14870
|
|
|
14780
14871
|
// ee/invoke-skills/skill-actions/tool.ts
|
|
14781
|
-
var
|
|
14872
|
+
var import_node_crypto9, import_promises4, import_node_path8, import_zod12, RUN_SKILL_ACTION_TOOL_ID, TEXT_MAX_CHARS, ITEMS_DEFAULT_LIMIT, ITEMS_MAX_LIMIT, ARGS_FILE_STEM, isPlainObject3, listOrNone, createRunSkillActionTool, RESULT_MARGIN_CHARS, STDERR_SHARE, fitResult, disabledSearchContexts, deriveConnectedContextIds;
|
|
14782
14873
|
var init_tool = __esm({
|
|
14783
14874
|
"ee/invoke-skills/skill-actions/tool.ts"() {
|
|
14784
14875
|
"use strict";
|
|
14785
14876
|
init_cjs_shims();
|
|
14786
|
-
|
|
14877
|
+
import_node_crypto9 = require("crypto");
|
|
14787
14878
|
import_promises4 = require("fs/promises");
|
|
14788
14879
|
import_node_path8 = require("path");
|
|
14789
14880
|
import_zod12 = require("zod");
|
|
@@ -14946,7 +15037,7 @@ var init_tool = __esm({
|
|
|
14946
15037
|
files.push({ file: `${ARGS_FILE_STEM}.json`, content: textArgs });
|
|
14947
15038
|
}
|
|
14948
15039
|
const sessionDir = handle.sessionDir;
|
|
14949
|
-
const runId = (0,
|
|
15040
|
+
const runId = (0, import_node_crypto9.randomUUID)();
|
|
14950
15041
|
const runRelative = `${ACTION_INPUTS_DIR}/${runId}`;
|
|
14951
15042
|
try {
|
|
14952
15043
|
const parent = await ensureRealDirectory(sessionDir, ACTION_INPUTS_DIR);
|
|
@@ -17201,7 +17292,8 @@ function buildSaveSessionFile(args) {
|
|
|
17201
17292
|
if (!uploads?.s3endpoint || !uploads.s3key || !uploads.s3secret || !uploads.s3Bucket) {
|
|
17202
17293
|
return void 0;
|
|
17203
17294
|
}
|
|
17204
|
-
if (args.inRoutineRun
|
|
17295
|
+
if (args.inRoutineRun) return void 0;
|
|
17296
|
+
if (treatAsGuest(args.req, args.user) && !(args.user?.id && args.guestFiles)) return void 0;
|
|
17205
17297
|
const ownerId = args.ownerId ?? args.user?.id;
|
|
17206
17298
|
return (file) => writeSessionFile({
|
|
17207
17299
|
ownerId,
|
|
@@ -17274,6 +17366,38 @@ var init_session_file_write = __esm({
|
|
|
17274
17366
|
}
|
|
17275
17367
|
});
|
|
17276
17368
|
|
|
17369
|
+
// src/exulu/guest-session-files.ts
|
|
17370
|
+
function guestFilesEnabled(agent) {
|
|
17371
|
+
return agent?.sandbox_enabled === true && (agent.guest_auth_mode || "regular") === "regular";
|
|
17372
|
+
}
|
|
17373
|
+
function agentAllowsGuestFiles(agent) {
|
|
17374
|
+
return agent?.guest_access === true && agent.active !== false && guestFilesEnabled(agent);
|
|
17375
|
+
}
|
|
17376
|
+
function guestUploadRefusal(objects) {
|
|
17377
|
+
if (objects.length >= GUEST_MAX_SESSION_FILES) {
|
|
17378
|
+
return `This conversation already holds ${GUEST_MAX_SESSION_FILES} files. Remove one or start a new conversation.`;
|
|
17379
|
+
}
|
|
17380
|
+
const total = objects.reduce((sum, object) => sum + (object.size || 0), 0);
|
|
17381
|
+
if (total >= GUEST_MAX_SESSION_BYTES) {
|
|
17382
|
+
return "This conversation's file storage is full. Remove a file or start a new conversation.";
|
|
17383
|
+
}
|
|
17384
|
+
return void 0;
|
|
17385
|
+
}
|
|
17386
|
+
function guestFileTooLarge(size) {
|
|
17387
|
+
return typeof size === "number" && size > GUEST_MAX_FILE_BYTES;
|
|
17388
|
+
}
|
|
17389
|
+
var GUEST_MAX_FILE_BYTES, GUEST_MAX_SESSION_FILES, GUEST_MAX_SESSION_BYTES;
|
|
17390
|
+
var init_guest_session_files = __esm({
|
|
17391
|
+
"src/exulu/guest-session-files.ts"() {
|
|
17392
|
+
"use strict";
|
|
17393
|
+
init_cjs_shims();
|
|
17394
|
+
init_session_file_adopt();
|
|
17395
|
+
GUEST_MAX_FILE_BYTES = MAX_ADOPT_UPLOAD_BYTES;
|
|
17396
|
+
GUEST_MAX_SESSION_FILES = 50;
|
|
17397
|
+
GUEST_MAX_SESSION_BYTES = 250 * 1024 * 1024;
|
|
17398
|
+
}
|
|
17399
|
+
});
|
|
17400
|
+
|
|
17277
17401
|
// src/templates/tools/routine-status-tool.ts
|
|
17278
17402
|
function createRoutineStatusTool(handle) {
|
|
17279
17403
|
if (!handle || handle.statuses.length === 0) return void 0;
|
|
@@ -17314,16 +17438,16 @@ var init_routine_status_tool = __esm({
|
|
|
17314
17438
|
});
|
|
17315
17439
|
|
|
17316
17440
|
// src/templates/tools/tool-upload.ts
|
|
17317
|
-
var import_client_s33,
|
|
17441
|
+
var import_client_s33, import_node_crypto10, generateS3Key, s3Client2, buildToolUpload;
|
|
17318
17442
|
var init_tool_upload = __esm({
|
|
17319
17443
|
"src/templates/tools/tool-upload.ts"() {
|
|
17320
17444
|
"use strict";
|
|
17321
17445
|
init_cjs_shims();
|
|
17322
17446
|
import_client_s33 = require("@aws-sdk/client-s3");
|
|
17323
|
-
|
|
17447
|
+
import_node_crypto10 = require("crypto");
|
|
17324
17448
|
init_session_file_write();
|
|
17325
17449
|
init_uppy();
|
|
17326
|
-
generateS3Key = (filename) => `${(0,
|
|
17450
|
+
generateS3Key = (filename) => `${(0, import_node_crypto10.randomUUID)()}-${filename}`;
|
|
17327
17451
|
buildToolUpload = (exuluConfig, user) => {
|
|
17328
17452
|
const uploads = exuluConfig?.fileUploads;
|
|
17329
17453
|
if (!uploads?.s3endpoint || !uploads?.s3key || !uploads?.s3secret || !uploads?.s3Bucket) {
|
|
@@ -17505,19 +17629,19 @@ var init_context_budget = __esm({
|
|
|
17505
17629
|
});
|
|
17506
17630
|
|
|
17507
17631
|
// src/exulu/tool-output-offload.ts
|
|
17508
|
-
var
|
|
17632
|
+
var import_node_crypto11, PREVIEW_CHARS, storeAsSessionFile, buildNotice, guardToolOutput, guardExtractedFileText;
|
|
17509
17633
|
var init_tool_output_offload = __esm({
|
|
17510
17634
|
"src/exulu/tool-output-offload.ts"() {
|
|
17511
17635
|
"use strict";
|
|
17512
17636
|
init_cjs_shims();
|
|
17513
|
-
|
|
17637
|
+
import_node_crypto11 = require("crypto");
|
|
17514
17638
|
init_uppy();
|
|
17515
17639
|
init_context_budget();
|
|
17516
17640
|
PREVIEW_CHARS = 4e3;
|
|
17517
17641
|
storeAsSessionFile = async (serialized, ctx) => {
|
|
17518
17642
|
if (!ctx.sessionID || !ctx.exuluConfig?.fileUploads) return void 0;
|
|
17519
17643
|
const safeTool = ctx.toolName.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 40);
|
|
17520
|
-
const name = `tool-output-${safeTool}-${(0,
|
|
17644
|
+
const name = `tool-output-${safeTool}-${(0, import_node_crypto11.randomUUID)().slice(0, 8)}.txt`;
|
|
17521
17645
|
try {
|
|
17522
17646
|
await uploadFile(
|
|
17523
17647
|
Buffer.from(serialized, "utf-8"),
|
|
@@ -17767,6 +17891,33 @@ async function convertLegacyOfficeToModern(bytes, ext) {
|
|
|
17767
17891
|
await (0, import_promises6.rm)(dir, { recursive: true, force: true });
|
|
17768
17892
|
}
|
|
17769
17893
|
}
|
|
17894
|
+
function isPresentationFormat(ext) {
|
|
17895
|
+
return PRESENTATION_EXTENSIONS.has(ext.toLowerCase());
|
|
17896
|
+
}
|
|
17897
|
+
async function convertOfficeToPdf(bytes, ext) {
|
|
17898
|
+
const dir = await (0, import_promises6.mkdtemp)((0, import_node_path11.join)((0, import_node_os2.tmpdir)(), "exulu-office2pdf-"));
|
|
17899
|
+
try {
|
|
17900
|
+
const inputPath = (0, import_node_path11.join)(dir, `input${ext.toLowerCase()}`);
|
|
17901
|
+
await (0, import_promises6.writeFile)(inputPath, bytes);
|
|
17902
|
+
try {
|
|
17903
|
+
await execFileAsync3(
|
|
17904
|
+
"soffice",
|
|
17905
|
+
// Own profile directory: two conversions at once otherwise fight over the user profile lock.
|
|
17906
|
+
[`-env:UserInstallation=file://${(0, import_node_path11.join)(dir, "profile")}`, "--headless", "--convert-to", "pdf", inputPath, "--outdir", dir],
|
|
17907
|
+
{ timeout: 18e4, maxBuffer: MAX_STDOUT_BYTES }
|
|
17908
|
+
);
|
|
17909
|
+
} catch (err4) {
|
|
17910
|
+
throw new Error(`LibreOffice could not convert the "${ext}" file to PDF: ` + (err4 instanceof Error ? err4.message : String(err4)));
|
|
17911
|
+
}
|
|
17912
|
+
const outputPath = (0, import_node_path11.join)(dir, "input.pdf");
|
|
17913
|
+
if (!(0, import_node_fs8.existsSync)(outputPath)) {
|
|
17914
|
+
throw new Error(`LibreOffice produced no PDF for the "${ext}" file`);
|
|
17915
|
+
}
|
|
17916
|
+
return await (0, import_promises6.readFile)(outputPath);
|
|
17917
|
+
} finally {
|
|
17918
|
+
await (0, import_promises6.rm)(dir, { recursive: true, force: true });
|
|
17919
|
+
}
|
|
17920
|
+
}
|
|
17770
17921
|
async function pdfToText(pdf) {
|
|
17771
17922
|
const dir = await (0, import_promises6.mkdtemp)((0, import_node_path11.join)((0, import_node_os2.tmpdir)(), "exulu-parse-"));
|
|
17772
17923
|
try {
|
|
@@ -17816,7 +17967,7 @@ async function renderPdfPageToPng(pdf, page, scaleTo) {
|
|
|
17816
17967
|
await (0, import_promises6.rm)(dir, { recursive: true, force: true });
|
|
17817
17968
|
}
|
|
17818
17969
|
}
|
|
17819
|
-
var import_node_child_process6, import_node_util5, import_node_fs8, import_promises6, import_node_os2, import_node_path11, execFileAsync3, MAX_STDOUT_BYTES, LEGACY_OFFICE_CONVERSION_TARGETS;
|
|
17970
|
+
var import_node_child_process6, import_node_util5, import_node_fs8, import_promises6, import_node_os2, import_node_path11, execFileAsync3, MAX_STDOUT_BYTES, LEGACY_OFFICE_CONVERSION_TARGETS, PRESENTATION_EXTENSIONS;
|
|
17820
17971
|
var init_document_render_helpers = __esm({
|
|
17821
17972
|
"src/templates/tools/document-render-helpers.ts"() {
|
|
17822
17973
|
"use strict";
|
|
@@ -17835,6 +17986,7 @@ var init_document_render_helpers = __esm({
|
|
|
17835
17986
|
".ppt": "pptx",
|
|
17836
17987
|
".rtf": "docx"
|
|
17837
17988
|
};
|
|
17989
|
+
PRESENTATION_EXTENSIONS = /* @__PURE__ */ new Set([".pptx", ".ppt", ".pptm", ".odp"]);
|
|
17838
17990
|
}
|
|
17839
17991
|
});
|
|
17840
17992
|
|
|
@@ -18589,6 +18741,19 @@ async function processDocument(filePath, fileType, buffer, tempDir, config, verb
|
|
|
18589
18741
|
case "webp":
|
|
18590
18742
|
result = await processImage(buffer, paths, config, verbose, tolerateVisionFailures, onProgress, limiters);
|
|
18591
18743
|
break;
|
|
18744
|
+
// A presentation is rendered to PDF and then read like any PDF, with whatever
|
|
18745
|
+
// processor is configured. The caller does not choose a parser by file type:
|
|
18746
|
+
// slides keep their pictures, charts and screenshots through OCR and the vision pass.
|
|
18747
|
+
case "pptx":
|
|
18748
|
+
case "ppt":
|
|
18749
|
+
case "pptm":
|
|
18750
|
+
case "odp": {
|
|
18751
|
+
const pdf = await convertOfficeToPdf(buffer, `.${stripped}`);
|
|
18752
|
+
const pdfPath = path3.join(tempDir, "converted.pdf");
|
|
18753
|
+
await fs2.promises.writeFile(pdfPath, pdf);
|
|
18754
|
+
result = await processPdf(pdf, { ...paths, source: pdfPath }, config, verbose, tolerateVisionFailures, onProgress, limiters);
|
|
18755
|
+
break;
|
|
18756
|
+
}
|
|
18592
18757
|
// Todo other file types with docx and officeparser
|
|
18593
18758
|
default:
|
|
18594
18759
|
throw new Error(`[EXULU] Unsupported file type: ${fileType}`);
|
|
@@ -18802,13 +18967,13 @@ async function documentProcessor({
|
|
|
18802
18967
|
let supportedTypes = [];
|
|
18803
18968
|
switch (config?.processor.name) {
|
|
18804
18969
|
case "officeparser":
|
|
18805
|
-
supportedTypes = ["docx", "pptx", "xlsx", "odt", "odp", "ods", "pdf", "rtf", "csv", "md", "html"];
|
|
18970
|
+
supportedTypes = ["docx", "pptx", "ppt", "pptm", "xlsx", "odt", "odp", "ods", "pdf", "rtf", "csv", "md", "html"];
|
|
18806
18971
|
break;
|
|
18807
18972
|
case "liteparse":
|
|
18808
18973
|
supportedTypes = ["pdf", "doc", "docx", "docm", "odt", "rtf", "ppt", "pptx", "pptm", "odp", "xls", "xlsx", "xlsm", "ods", "csv", "tsv"];
|
|
18809
18974
|
break;
|
|
18810
18975
|
case "mistral":
|
|
18811
|
-
supportedTypes = ["pdf", "docx", "doc", "txt", "md", "jpg", "jpeg", "png", "gif", "webp"];
|
|
18976
|
+
supportedTypes = ["pdf", "docx", "doc", "pptx", "ppt", "pptm", "odp", "txt", "md", "jpg", "jpeg", "png", "gif", "webp"];
|
|
18812
18977
|
break;
|
|
18813
18978
|
}
|
|
18814
18979
|
if (!supportedTypes.includes(fileType.toLowerCase())) {
|
|
@@ -18865,6 +19030,7 @@ var init_doc_processor = __esm({
|
|
|
18865
19030
|
init_resolve_ocr();
|
|
18866
19031
|
init_resolve_model();
|
|
18867
19032
|
init_limits();
|
|
19033
|
+
init_document_render_helpers();
|
|
18868
19034
|
loadFile = async (file, name, tempDir) => {
|
|
18869
19035
|
let filePath = file;
|
|
18870
19036
|
let fileType = name?.split(".").pop();
|
|
@@ -18929,7 +19095,17 @@ function degradedPagesOf(result) {
|
|
|
18929
19095
|
}
|
|
18930
19096
|
async function extractDocument(input) {
|
|
18931
19097
|
const config = input.exuluConfig?.attachments?.documentProcessor;
|
|
19098
|
+
const original = input;
|
|
18932
19099
|
if (config) {
|
|
19100
|
+
const ext = input.filename.slice(input.filename.lastIndexOf(".")).toLowerCase();
|
|
19101
|
+
if (isPresentationFormat(ext)) {
|
|
19102
|
+
try {
|
|
19103
|
+
const pdf = await (input.toPdf ?? convertOfficeToPdf)(input.bytes, ext);
|
|
19104
|
+
input = { ...input, bytes: pdf, filename: `${input.filename.slice(0, -ext.length)}.pdf` };
|
|
19105
|
+
} catch (error) {
|
|
19106
|
+
console.warn(`[EXULU] Could not render ${input.filename} to PDF:`, error instanceof Error ? error.message : String(error));
|
|
19107
|
+
}
|
|
19108
|
+
}
|
|
18933
19109
|
if (input.filename.toLowerCase().endsWith(".pdf")) {
|
|
18934
19110
|
const forTool = input.maxPages !== void 0;
|
|
18935
19111
|
const maxPages = input.maxPages ?? attachmentMaxPages();
|
|
@@ -18943,7 +19119,7 @@ async function extractDocument(input) {
|
|
|
18943
19119
|
console.warn(`[EXULU] ${input.filename} has ${pageCount} pages, over the ${forTool ? "document" : "attachment"} cap of ${maxPages}; not read.`);
|
|
18944
19120
|
return {
|
|
18945
19121
|
pages: [],
|
|
18946
|
-
text: (forTool ? tooLongForToolNotice : tooLongNotice)(
|
|
19122
|
+
text: (forTool ? tooLongForToolNotice : tooLongNotice)(original.filename, pageCount, maxPages),
|
|
18947
19123
|
engine: "document-processor",
|
|
18948
19124
|
tooLong: { pageCount, maxPages }
|
|
18949
19125
|
};
|
|
@@ -18979,7 +19155,7 @@ async function extractDocument(input) {
|
|
|
18979
19155
|
);
|
|
18980
19156
|
}
|
|
18981
19157
|
}
|
|
18982
|
-
const text = (await (input.officeParse ?? defaultOfficeParse)(
|
|
19158
|
+
const text = (await (input.officeParse ?? defaultOfficeParse)(original.bytes)).trim();
|
|
18983
19159
|
return { pages: [{ page: 1, text }], text, engine: "officeparser" };
|
|
18984
19160
|
}
|
|
18985
19161
|
function validateAttachmentsConfig(config, license) {
|
|
@@ -20013,6 +20189,7 @@ var init_convert_exulu_tools_to_ai_sdk_tools = __esm({
|
|
|
20013
20189
|
init_create_sandbox();
|
|
20014
20190
|
init_resolve_session_project();
|
|
20015
20191
|
init_session_file_write();
|
|
20192
|
+
init_guest_session_files();
|
|
20016
20193
|
init_routine_status_tool();
|
|
20017
20194
|
init_tool_upload();
|
|
20018
20195
|
init_truncate_tool_output();
|
|
@@ -20468,7 +20645,8 @@ var init_convert_exulu_tools_to_ai_sdk_tools = __esm({
|
|
|
20468
20645
|
user,
|
|
20469
20646
|
req,
|
|
20470
20647
|
exuluConfig,
|
|
20471
|
-
inRoutineRun: inRoutineRun ?? Boolean(routineHandleFactory)
|
|
20648
|
+
inRoutineRun: inRoutineRun ?? Boolean(routineHandleFactory),
|
|
20649
|
+
guestFiles: agentAllowsGuestFiles(agent)
|
|
20472
20650
|
}),
|
|
20473
20651
|
exuluConfig,
|
|
20474
20652
|
toolVariablesConfig: toolVariablesConfigData,
|
|
@@ -20560,7 +20738,7 @@ var init_convert_exulu_tools_to_ai_sdk_tools = __esm({
|
|
|
20560
20738
|
});
|
|
20561
20739
|
|
|
20562
20740
|
// src/exulu/tool.ts
|
|
20563
|
-
var import_ai4, import_zod19,
|
|
20741
|
+
var import_ai4, import_zod19, import_node_crypto12, PUBLIC_TOOL_TYPES, ExuluTool;
|
|
20564
20742
|
var init_tool2 = __esm({
|
|
20565
20743
|
"src/exulu/tool.ts"() {
|
|
20566
20744
|
"use strict";
|
|
@@ -20568,7 +20746,7 @@ var init_tool2 = __esm({
|
|
|
20568
20746
|
import_ai4 = require("ai");
|
|
20569
20747
|
import_zod19 = require("zod");
|
|
20570
20748
|
init_sanitize_name();
|
|
20571
|
-
|
|
20749
|
+
import_node_crypto12 = require("crypto");
|
|
20572
20750
|
init_singleton();
|
|
20573
20751
|
init_resolve_model();
|
|
20574
20752
|
init_validate();
|
|
@@ -20713,7 +20891,7 @@ var init_tool2 = __esm({
|
|
|
20713
20891
|
throw new Error("Tool " + sanitizeName(this.name) + " not found in " + JSON.stringify(tools));
|
|
20714
20892
|
}
|
|
20715
20893
|
console.log("[EXULU] Tool found", this.name);
|
|
20716
|
-
const toolCallId = this.id + "_" + (0,
|
|
20894
|
+
const toolCallId = this.id + "_" + (0, import_node_crypto12.randomUUID)();
|
|
20717
20895
|
console.log("[EXULU] Calling tool execute", {
|
|
20718
20896
|
inputs,
|
|
20719
20897
|
toolCallId,
|
|
@@ -23743,6 +23921,153 @@ var import_express6 = require("express");
|
|
|
23743
23921
|
|
|
23744
23922
|
// src/exulu/routes.ts
|
|
23745
23923
|
init_cjs_shims();
|
|
23924
|
+
|
|
23925
|
+
// src/exulu/companion/operation-guard.ts
|
|
23926
|
+
init_cjs_shims();
|
|
23927
|
+
var import_graphql = require("graphql");
|
|
23928
|
+
var companionAllowedOperations = (tables) => {
|
|
23929
|
+
const allowed = /* @__PURE__ */ new Set();
|
|
23930
|
+
for (const table of tables) {
|
|
23931
|
+
const plural = table.name.plural.toLowerCase();
|
|
23932
|
+
const singular = table.name.singular.toLowerCase();
|
|
23933
|
+
allowed.add(`${plural}Pagination`);
|
|
23934
|
+
allowed.add(`${singular}ById`);
|
|
23935
|
+
allowed.add(`${plural}UpdateOneById`);
|
|
23936
|
+
}
|
|
23937
|
+
return allowed;
|
|
23938
|
+
};
|
|
23939
|
+
var fieldNamesOf = (operation, document2) => {
|
|
23940
|
+
const fragments = /* @__PURE__ */ new Map();
|
|
23941
|
+
for (const def of document2.definitions) {
|
|
23942
|
+
if (def.kind === import_graphql.Kind.FRAGMENT_DEFINITION) fragments.set(def.name.value, def.selectionSet);
|
|
23943
|
+
}
|
|
23944
|
+
const names = [];
|
|
23945
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23946
|
+
const walk = (set) => {
|
|
23947
|
+
for (const selection of set.selections) {
|
|
23948
|
+
if (selection.kind === import_graphql.Kind.FIELD) names.push(selection.name.value);
|
|
23949
|
+
else if (selection.kind === import_graphql.Kind.INLINE_FRAGMENT) walk(selection.selectionSet);
|
|
23950
|
+
else {
|
|
23951
|
+
const name = selection.name.value;
|
|
23952
|
+
const fragment = fragments.get(name);
|
|
23953
|
+
if (fragment && !seen.has(name)) {
|
|
23954
|
+
seen.add(name);
|
|
23955
|
+
walk(fragment);
|
|
23956
|
+
}
|
|
23957
|
+
}
|
|
23958
|
+
}
|
|
23959
|
+
};
|
|
23960
|
+
walk(operation.selectionSet);
|
|
23961
|
+
return names;
|
|
23962
|
+
};
|
|
23963
|
+
var companionOperationGuard = (allowed) => ({
|
|
23964
|
+
async requestDidStart() {
|
|
23965
|
+
return {
|
|
23966
|
+
async didResolveOperation({ contextValue, document: document2, operation }) {
|
|
23967
|
+
if (!contextValue?.user?.via_companion) return;
|
|
23968
|
+
const names = operation ? fieldNamesOf(operation, document2) : [];
|
|
23969
|
+
const permitted = names.length > 0 && names.every((name) => name === "__typename" || allowed.has(name));
|
|
23970
|
+
if (!permitted) {
|
|
23971
|
+
throw new import_graphql.GraphQLError("This operation is not available through the companion server.", {
|
|
23972
|
+
extensions: { code: "FORBIDDEN", http: { status: 403 } }
|
|
23973
|
+
});
|
|
23974
|
+
}
|
|
23975
|
+
}
|
|
23976
|
+
};
|
|
23977
|
+
}
|
|
23978
|
+
});
|
|
23979
|
+
|
|
23980
|
+
// src/exulu/companion/request.ts
|
|
23981
|
+
init_cjs_shims();
|
|
23982
|
+
var import_node_crypto = require("crypto");
|
|
23983
|
+
var import_graphql2 = require("graphql");
|
|
23984
|
+
|
|
23985
|
+
// src/exulu/external-rate-limit.ts
|
|
23986
|
+
init_cjs_shims();
|
|
23987
|
+
var MINUTE_MS = 6e4;
|
|
23988
|
+
var HOUR_MS = 36e5;
|
|
23989
|
+
var perMinuteLimit = () => parseInt(process.env.EXULU_EXTERNAL_RATE_PER_MINUTE || "30", 10);
|
|
23990
|
+
var perHourLimit = () => parseInt(process.env.EXULU_EXTERNAL_RATE_PER_HOUR || "300", 10);
|
|
23991
|
+
var windows = /* @__PURE__ */ new Map();
|
|
23992
|
+
var externalRateLimitExceeded = (userId, now = Date.now()) => {
|
|
23993
|
+
const state = windows.get(userId) ?? {
|
|
23994
|
+
minuteStart: now,
|
|
23995
|
+
minuteCount: 0,
|
|
23996
|
+
hourStart: now,
|
|
23997
|
+
hourCount: 0,
|
|
23998
|
+
lastSeen: now
|
|
23999
|
+
};
|
|
24000
|
+
if (now - state.minuteStart >= MINUTE_MS) {
|
|
24001
|
+
state.minuteStart = now;
|
|
24002
|
+
state.minuteCount = 0;
|
|
24003
|
+
}
|
|
24004
|
+
if (now - state.hourStart >= HOUR_MS) {
|
|
24005
|
+
state.hourStart = now;
|
|
24006
|
+
state.hourCount = 0;
|
|
24007
|
+
}
|
|
24008
|
+
state.minuteCount += 1;
|
|
24009
|
+
state.hourCount += 1;
|
|
24010
|
+
state.lastSeen = now;
|
|
24011
|
+
windows.set(userId, state);
|
|
24012
|
+
if (windows.size > 1e4) {
|
|
24013
|
+
for (const [key, value] of windows) {
|
|
24014
|
+
if (now - value.lastSeen >= HOUR_MS) windows.delete(key);
|
|
24015
|
+
}
|
|
24016
|
+
if (windows.size > 1e4) {
|
|
24017
|
+
const sorted = [...windows.entries()].sort(
|
|
24018
|
+
(a, b) => a[1].lastSeen - b[1].lastSeen
|
|
24019
|
+
);
|
|
24020
|
+
for (const [key] of sorted) {
|
|
24021
|
+
if (windows.size <= 1e4) break;
|
|
24022
|
+
windows.delete(key);
|
|
24023
|
+
}
|
|
24024
|
+
}
|
|
24025
|
+
}
|
|
24026
|
+
const minuteLimitExceeded = state.minuteCount > perMinuteLimit();
|
|
24027
|
+
const hourLimitExceeded = state.hourCount > perHourLimit();
|
|
24028
|
+
const limitExceeded = minuteLimitExceeded || hourLimitExceeded;
|
|
24029
|
+
if (limitExceeded) {
|
|
24030
|
+
const limits = {
|
|
24031
|
+
perMinute: perMinuteLimit(),
|
|
24032
|
+
perHour: perHourLimit()
|
|
24033
|
+
};
|
|
24034
|
+
const current = {
|
|
24035
|
+
minute: state.minuteCount,
|
|
24036
|
+
hour: state.hourCount
|
|
24037
|
+
};
|
|
24038
|
+
console.warn(
|
|
24039
|
+
`[EXULU] Rate limit exceeded for user ${userId}${minuteLimitExceeded ? ` per-minute (${current.minute}/${limits.perMinute})` : ""}${minuteLimitExceeded && hourLimitExceeded ? " and" : ""}${hourLimitExceeded ? ` per-hour (${current.hour}/${limits.perHour})` : ""}`
|
|
24040
|
+
);
|
|
24041
|
+
}
|
|
24042
|
+
return limitExceeded;
|
|
24043
|
+
};
|
|
24044
|
+
var isExternalUser = (user) => {
|
|
24045
|
+
return user?.role?.name === "external";
|
|
24046
|
+
};
|
|
24047
|
+
|
|
24048
|
+
// src/exulu/companion/request.ts
|
|
24049
|
+
var COMPANION_HEADER = "x-exulu-companion";
|
|
24050
|
+
var companionRequestState = (headers, env = process.env) => {
|
|
24051
|
+
const received = headers[COMPANION_HEADER];
|
|
24052
|
+
if (received === void 0) return "absent";
|
|
24053
|
+
const expected = env.EXULU_COMPANION_KEY;
|
|
24054
|
+
if (typeof received !== "string" || received === "" || !expected) return "invalid";
|
|
24055
|
+
const a = Buffer.from(received);
|
|
24056
|
+
const b = Buffer.from(expected);
|
|
24057
|
+
if (a.length !== b.length) return "invalid";
|
|
24058
|
+
return (0, import_node_crypto.timingSafeEqual)(a, b) ? "valid" : "invalid";
|
|
24059
|
+
};
|
|
24060
|
+
var forbidden = (message) => new import_graphql2.GraphQLError(message, { extensions: { code: "FORBIDDEN", http: { status: 403 } } });
|
|
24061
|
+
var admitCompanionUser = (state, user) => {
|
|
24062
|
+
if (state === "absent") return user;
|
|
24063
|
+
if (state === "invalid") throw forbidden("Companion key rejected.");
|
|
24064
|
+
if (user.super_admin || !isExternalUser(user)) {
|
|
24065
|
+
throw forbidden("This account cannot be used through the companion server.");
|
|
24066
|
+
}
|
|
24067
|
+
return { ...user, via_companion: true };
|
|
24068
|
+
};
|
|
24069
|
+
|
|
24070
|
+
// src/exulu/routes.ts
|
|
23746
24071
|
var import_express2 = require("express");
|
|
23747
24072
|
|
|
23748
24073
|
// src/exulu/channels/lifecycle.ts
|
|
@@ -24367,8 +24692,8 @@ init_skill_author_tools();
|
|
|
24367
24692
|
|
|
24368
24693
|
// src/graphql/types/index.ts
|
|
24369
24694
|
init_cjs_shims();
|
|
24370
|
-
var
|
|
24371
|
-
var GraphQLDate = new
|
|
24695
|
+
var import_graphql3 = require("graphql");
|
|
24696
|
+
var GraphQLDate = new import_graphql3.GraphQLScalarType({
|
|
24372
24697
|
name: "Date",
|
|
24373
24698
|
description: "Date custom scalar type",
|
|
24374
24699
|
serialize(value) {
|
|
@@ -24393,10 +24718,10 @@ var GraphQLDate = new import_graphql.GraphQLScalarType({
|
|
|
24393
24718
|
return value;
|
|
24394
24719
|
},
|
|
24395
24720
|
parseLiteral(ast) {
|
|
24396
|
-
if (ast.kind ===
|
|
24721
|
+
if (ast.kind === import_graphql3.Kind.STRING) {
|
|
24397
24722
|
return new Date(ast.value);
|
|
24398
24723
|
}
|
|
24399
|
-
if (ast.kind ===
|
|
24724
|
+
if (ast.kind === import_graphql3.Kind.INT) {
|
|
24400
24725
|
return new Date(parseInt(ast.value, 10));
|
|
24401
24726
|
}
|
|
24402
24727
|
return null;
|
|
@@ -24474,6 +24799,14 @@ var contextItemsProcessorHandler = async (context, config, items, user, role) =>
|
|
|
24474
24799
|
init_access_control();
|
|
24475
24800
|
init_rbac_resolver();
|
|
24476
24801
|
|
|
24802
|
+
// src/graphql/schemas/rbac-field.ts
|
|
24803
|
+
init_cjs_shims();
|
|
24804
|
+
init_rbac_resolver();
|
|
24805
|
+
var resolveRbacField = async (table, parent, context) => {
|
|
24806
|
+
if (context.user?.via_companion === true) return null;
|
|
24807
|
+
return RBACResolver(context.db, table.name.singular, parent.id, parent.rights_mode);
|
|
24808
|
+
};
|
|
24809
|
+
|
|
24477
24810
|
// src/graphql/resolvers/index.ts
|
|
24478
24811
|
init_cjs_shims();
|
|
24479
24812
|
|
|
@@ -24496,6 +24829,72 @@ init_context();
|
|
|
24496
24829
|
init_entities();
|
|
24497
24830
|
init_vector_search();
|
|
24498
24831
|
|
|
24832
|
+
// src/graphql/resolvers/chunk-source-document.ts
|
|
24833
|
+
init_cjs_shims();
|
|
24834
|
+
init_context();
|
|
24835
|
+
init_keys();
|
|
24836
|
+
init_project_files();
|
|
24837
|
+
init_access_control();
|
|
24838
|
+
function chunkWithItemQuery(db2, table, contextId, user, chunkId, itemColumns = []) {
|
|
24839
|
+
const query = db2(getChunksTableName(contextId) + " as chunks").select([
|
|
24840
|
+
"chunks.id as chunk_id",
|
|
24841
|
+
"chunks.source as chunk_source",
|
|
24842
|
+
"chunks.content as chunk_content",
|
|
24843
|
+
"chunks.chunk_index",
|
|
24844
|
+
"chunks.metadata as chunk_metadata",
|
|
24845
|
+
db2.raw('chunks."createdAt" as chunk_created_at'),
|
|
24846
|
+
db2.raw('chunks."updatedAt" as chunk_updated_at'),
|
|
24847
|
+
"items.id as item_id",
|
|
24848
|
+
"items.name as item_name",
|
|
24849
|
+
"items.external_id as item_external_id",
|
|
24850
|
+
db2.raw('items."updatedAt" as item_updated_at'),
|
|
24851
|
+
db2.raw('items."createdAt" as item_created_at'),
|
|
24852
|
+
...itemColumns.map((column) => `items.${column} as item_file_${column}`)
|
|
24853
|
+
]).join(getTableName(contextId) + " as items", "chunks.source", "items.id").where("chunks.id", chunkId);
|
|
24854
|
+
return applyAccessControl(table, query, user, "items").first();
|
|
24855
|
+
}
|
|
24856
|
+
function fileKeyColumns(fields) {
|
|
24857
|
+
return (fields ?? []).filter((field) => field.type === "file").map((field) => field.name.endsWith("_s3key") ? field.name : `${field.name}_s3key`);
|
|
24858
|
+
}
|
|
24859
|
+
function pickSourceDocumentKey(metadata, itemFileKeys) {
|
|
24860
|
+
if (!metadata || typeof metadata !== "object") return void 0;
|
|
24861
|
+
const { pdf, document: document2 } = metadata;
|
|
24862
|
+
const stored = new Set(itemFileKeys.filter((k) => typeof k === "string" && k !== ""));
|
|
24863
|
+
return [pdf, document2].find((k) => typeof k === "string" && stored.has(k));
|
|
24864
|
+
}
|
|
24865
|
+
async function chunkSourceDocument(deps) {
|
|
24866
|
+
const columns = fileKeyColumns(deps.context.fields);
|
|
24867
|
+
if (columns.length === 0) return null;
|
|
24868
|
+
const row = await chunkWithItemQuery(
|
|
24869
|
+
deps.db,
|
|
24870
|
+
deps.table,
|
|
24871
|
+
deps.context.id,
|
|
24872
|
+
deps.user,
|
|
24873
|
+
deps.chunkId,
|
|
24874
|
+
columns
|
|
24875
|
+
);
|
|
24876
|
+
if (!row) return null;
|
|
24877
|
+
const stored = pickSourceDocumentKey(
|
|
24878
|
+
row.chunk_metadata,
|
|
24879
|
+
columns.map((column) => row[`item_file_${column}`])
|
|
24880
|
+
);
|
|
24881
|
+
if (!stored) return null;
|
|
24882
|
+
const slash = stored.indexOf("/");
|
|
24883
|
+
if (slash <= 0) return null;
|
|
24884
|
+
const bucket = stored.slice(0, slash);
|
|
24885
|
+
const key = stored.slice(slash + 1);
|
|
24886
|
+
if (!key || isDerivedKey(key, deps.s3prefix) || isProjectKey(key, deps.s3prefix)) return null;
|
|
24887
|
+
const page = Number.parseInt(String(row.chunk_metadata?.page ?? ""), 10);
|
|
24888
|
+
return {
|
|
24889
|
+
url: await deps.sign(bucket, key),
|
|
24890
|
+
filename: key.slice(key.lastIndexOf("/") + 1),
|
|
24891
|
+
page: Number.isFinite(page) && page > 0 ? page : null
|
|
24892
|
+
};
|
|
24893
|
+
}
|
|
24894
|
+
|
|
24895
|
+
// src/graphql/resolvers/index.ts
|
|
24896
|
+
init_uppy();
|
|
24897
|
+
|
|
24499
24898
|
// src/graphql/utilities/sanitize-and-hydrate-fields.ts
|
|
24500
24899
|
init_cjs_shims();
|
|
24501
24900
|
init_context();
|
|
@@ -24916,7 +25315,7 @@ var sanitizeRequestedFields = (table, requestedFields) => {
|
|
|
24916
25315
|
}
|
|
24917
25316
|
return requestedFields;
|
|
24918
25317
|
};
|
|
24919
|
-
function createQueries(table, tools, contexts) {
|
|
25318
|
+
function createQueries(table, tools, contexts, config) {
|
|
24920
25319
|
const tableNamePlural = table.name.plural.toLowerCase();
|
|
24921
25320
|
const tableNameSingular = table.name.singular.toLowerCase();
|
|
24922
25321
|
const queries = {
|
|
@@ -25165,23 +25564,7 @@ function createQueries(table, tools, contexts) {
|
|
|
25165
25564
|
if (!exists) {
|
|
25166
25565
|
throw new Error("Context " + table.id + " not found in registry.");
|
|
25167
25566
|
}
|
|
25168
|
-
const
|
|
25169
|
-
const chunksTable = getChunksTableName(exists.id);
|
|
25170
|
-
const mainTable = getTableName(exists.id);
|
|
25171
|
-
const chunk2 = await db2(chunksTable + " as chunks").select([
|
|
25172
|
-
"chunks.id as chunk_id",
|
|
25173
|
-
"chunks.source as chunk_source",
|
|
25174
|
-
"chunks.content as chunk_content",
|
|
25175
|
-
"chunks.chunk_index",
|
|
25176
|
-
"chunks.metadata as chunk_metadata",
|
|
25177
|
-
db2.raw('chunks."createdAt" as chunk_created_at'),
|
|
25178
|
-
db2.raw('chunks."updatedAt" as chunk_updated_at'),
|
|
25179
|
-
"items.id as item_id",
|
|
25180
|
-
"items.name as item_name",
|
|
25181
|
-
"items.external_id as item_external_id",
|
|
25182
|
-
db2.raw('items."updatedAt" as item_updated_at'),
|
|
25183
|
-
db2.raw('items."createdAt" as item_created_at')
|
|
25184
|
-
]).leftJoin(mainTable + " as items", "chunks.source", "items.id").where("chunks.id", args.id).first();
|
|
25567
|
+
const chunk2 = await chunkWithItemQuery(context.db, table, exists.id, context.user, args.id);
|
|
25185
25568
|
if (!chunk2) {
|
|
25186
25569
|
return null;
|
|
25187
25570
|
}
|
|
@@ -25200,6 +25583,24 @@ function createQueries(table, tools, contexts) {
|
|
|
25200
25583
|
item_created_at: chunk2.item_created_at
|
|
25201
25584
|
};
|
|
25202
25585
|
};
|
|
25586
|
+
queries[`${tableNameSingular}ChunkSourceDocument`] = async (_, args, context) => {
|
|
25587
|
+
const exists = contexts.find((ctx) => ctx.id === table.id);
|
|
25588
|
+
if (!exists) {
|
|
25589
|
+
throw new Error("Context " + table.id + " not found in registry.");
|
|
25590
|
+
}
|
|
25591
|
+
if (!config?.fileUploads) {
|
|
25592
|
+
return null;
|
|
25593
|
+
}
|
|
25594
|
+
return await chunkSourceDocument({
|
|
25595
|
+
db: context.db,
|
|
25596
|
+
table,
|
|
25597
|
+
context: exists,
|
|
25598
|
+
user: context.user,
|
|
25599
|
+
chunkId: args.id,
|
|
25600
|
+
s3prefix: config.fileUploads.s3prefix,
|
|
25601
|
+
sign: (bucket, key) => getPresignedUrl(bucket, key, config)
|
|
25602
|
+
});
|
|
25603
|
+
};
|
|
25203
25604
|
}
|
|
25204
25605
|
return queries;
|
|
25205
25606
|
}
|
|
@@ -25233,6 +25634,32 @@ async function getJobsByQueueName(queueName, statusses, page, limit) {
|
|
|
25233
25634
|
init_cjs_shims();
|
|
25234
25635
|
init_context();
|
|
25235
25636
|
init_item_write();
|
|
25637
|
+
|
|
25638
|
+
// src/exulu/item-file-keys.ts
|
|
25639
|
+
init_cjs_shims();
|
|
25640
|
+
init_uppy();
|
|
25641
|
+
function unreadableFileKeyColumns(input, user, s3prefix) {
|
|
25642
|
+
const caller = user ?? {};
|
|
25643
|
+
return Object.entries(input).filter(([column, value]) => column.endsWith("_s3key") && typeof value === "string" && value !== "").filter(([, value]) => {
|
|
25644
|
+
const stored = value;
|
|
25645
|
+
const key = stored.slice(stored.indexOf("/") + 1);
|
|
25646
|
+
if (!stored.includes("/") || !key) return true;
|
|
25647
|
+
return !mayUseGenericS3Route(key, caller, s3prefix) || !mayReadGenericS3Key(key, caller, s3prefix);
|
|
25648
|
+
}).map(([column]) => column);
|
|
25649
|
+
}
|
|
25650
|
+
async function assertItemFileKeysReadable(deps) {
|
|
25651
|
+
const flagged = unreadableFileKeyColumns(deps.input, deps.user, deps.s3prefix);
|
|
25652
|
+
if (flagged.length === 0) return;
|
|
25653
|
+
const existing = await deps.loadExisting();
|
|
25654
|
+
const refused = flagged.filter((column) => existing?.[column] !== deps.input[column]);
|
|
25655
|
+
if (refused.length > 0) {
|
|
25656
|
+
throw new Error(
|
|
25657
|
+
`Not allowed to attach the file in ${refused.join(", ")}: it is not one of your own uploads or a shared file.`
|
|
25658
|
+
);
|
|
25659
|
+
}
|
|
25660
|
+
}
|
|
25661
|
+
|
|
25662
|
+
// src/graphql/mutations/index.ts
|
|
25236
25663
|
init_entities();
|
|
25237
25664
|
init_statistics2();
|
|
25238
25665
|
init_access_control();
|
|
@@ -25734,7 +26161,7 @@ function registerImportQueue() {
|
|
|
25734
26161
|
|
|
25735
26162
|
// src/exulu/import/start-import.ts
|
|
25736
26163
|
init_cjs_shims();
|
|
25737
|
-
var
|
|
26164
|
+
var import_node_crypto13 = require("crypto");
|
|
25738
26165
|
|
|
25739
26166
|
// src/utils/serialize-error.ts
|
|
25740
26167
|
init_cjs_shims();
|
|
@@ -25921,7 +26348,7 @@ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
|
25921
26348
|
function isUuid(value) {
|
|
25922
26349
|
return UUID_RE.test(value);
|
|
25923
26350
|
}
|
|
25924
|
-
function
|
|
26351
|
+
function idOf3(value) {
|
|
25925
26352
|
if (typeof value === "string") return value;
|
|
25926
26353
|
if (value != null && typeof value === "object" && "id" in value) {
|
|
25927
26354
|
const id = value.id;
|
|
@@ -25942,14 +26369,14 @@ function canWrite(existing, user) {
|
|
|
25942
26369
|
);
|
|
25943
26370
|
}
|
|
25944
26371
|
if (existing.rights_mode === "roles") {
|
|
25945
|
-
const roleId =
|
|
26372
|
+
const roleId = idOf3(user.role);
|
|
25946
26373
|
if (!roleId) return false;
|
|
25947
26374
|
return grantsOf(existing).some(
|
|
25948
26375
|
(g) => g.access_type === "Role" && String(g.role_id) === roleId && g.rights === "write"
|
|
25949
26376
|
);
|
|
25950
26377
|
}
|
|
25951
26378
|
if (existing.rights_mode === "teams") {
|
|
25952
|
-
const teamId =
|
|
26379
|
+
const teamId = idOf3(user.team);
|
|
25953
26380
|
if (!teamId) return false;
|
|
25954
26381
|
return grantsOf(existing).some(
|
|
25955
26382
|
(g) => g.access_type === "Team" && String(g.team_id) === teamId && g.rights === "write"
|
|
@@ -26025,7 +26452,7 @@ async function uploadErrorReport(csv, contextId, jobResultId, config, user) {
|
|
|
26025
26452
|
function buildWorkerDeps(input) {
|
|
26026
26453
|
const { db: db2, config, context, contextId, jobResultId, stream, fields, mapping, access, options, user, log: log7 } = input;
|
|
26027
26454
|
const tableName = getTableName(contextId);
|
|
26028
|
-
const roleId =
|
|
26455
|
+
const roleId = idOf3(user.role);
|
|
26029
26456
|
const generateEmbeddingsOverwrite = options.skipEmbeddings ? false : void 0;
|
|
26030
26457
|
const rbac = rbacGrantsFor(access);
|
|
26031
26458
|
const total = typeof input.total === "number" && input.total > 0 ? input.total : void 0;
|
|
@@ -26112,7 +26539,7 @@ async function startImport(deps, args) {
|
|
|
26112
26539
|
if (running) {
|
|
26113
26540
|
throw new StartImportError("IMPORT_ALREADY_RUNNING");
|
|
26114
26541
|
}
|
|
26115
|
-
const id = (uuid ??
|
|
26542
|
+
const id = (uuid ?? import_node_crypto13.randomUUID)();
|
|
26116
26543
|
const label = `Import ${args.fileName}`;
|
|
26117
26544
|
const userSnapshot = {
|
|
26118
26545
|
id: user.id,
|
|
@@ -26253,6 +26680,7 @@ init_cjs_shims();
|
|
|
26253
26680
|
// src/exulu/public-agents.ts
|
|
26254
26681
|
init_cjs_shims();
|
|
26255
26682
|
init_shared_artifacts();
|
|
26683
|
+
init_guest_session_files();
|
|
26256
26684
|
var LOCALE_KEY = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})?$/;
|
|
26257
26685
|
var welcomeTranslations = (raw) => {
|
|
26258
26686
|
let value = raw;
|
|
@@ -26283,7 +26711,8 @@ var publicAgentView = (row, slug) => ({
|
|
|
26283
26711
|
guest_auth_mode: row.guest_auth_mode || "regular",
|
|
26284
26712
|
guest_has_cover: !!row.guest_cover_image,
|
|
26285
26713
|
guest_has_idle_animation: !!row.animation_idle,
|
|
26286
|
-
guest_has_responding_animation: !!row.animation_responding
|
|
26714
|
+
guest_has_responding_animation: !!row.animation_responding,
|
|
26715
|
+
guest_files_enabled: guestFilesEnabled(row)
|
|
26287
26716
|
});
|
|
26288
26717
|
var evaluateGuestChatAccess = async (agent, userId, guestPassword) => {
|
|
26289
26718
|
if (agent.guest_access) {
|
|
@@ -27491,6 +27920,7 @@ var markSessionSeenForViewer = async ({
|
|
|
27491
27920
|
|
|
27492
27921
|
// src/graphql/mutations/index.ts
|
|
27493
27922
|
init_skill_access();
|
|
27923
|
+
init_write_grant();
|
|
27494
27924
|
var VALID_RIGHTS_MODES3 = ["private", "users", "roles", "teams", "public"];
|
|
27495
27925
|
var postprocessDeletion = async ({
|
|
27496
27926
|
table,
|
|
@@ -27676,6 +28106,12 @@ function createMutations(table, contexts, tools, config) {
|
|
|
27676
28106
|
const validateWriteAccess = async (id, context) => {
|
|
27677
28107
|
try {
|
|
27678
28108
|
const { db: db2, user } = context;
|
|
28109
|
+
if (user.via_companion === true) {
|
|
28110
|
+
const row = table.RBAC === true ? await db2.from(tableNamePlural).select(["rights_mode"]).where({ id }).first() : void 0;
|
|
28111
|
+
const grant = !!row && await hasCompanionWriteGrant(db2, table.name.singular, id, user, row.rights_mode);
|
|
28112
|
+
if (grant) return true;
|
|
28113
|
+
throw new Error("Insufficient permissions to edit this record");
|
|
28114
|
+
}
|
|
27679
28115
|
if (user.super_admin === true) {
|
|
27680
28116
|
return true;
|
|
27681
28117
|
}
|
|
@@ -27838,6 +28274,20 @@ function createMutations(table, contexts, tools, config) {
|
|
|
27838
28274
|
if (table.name.singular === "user" && context.user?.super_admin !== true) {
|
|
27839
28275
|
throw new Error("You are not authorized to create users");
|
|
27840
28276
|
}
|
|
28277
|
+
if (table.type === "items") {
|
|
28278
|
+
await assertItemFileKeysReadable({
|
|
28279
|
+
input,
|
|
28280
|
+
user: context.user,
|
|
28281
|
+
s3prefix: config?.fileUploads?.s3prefix,
|
|
28282
|
+
// An upsert may land on an existing row, whose stored keys stay valid.
|
|
28283
|
+
loadExisting: async () => {
|
|
28284
|
+
if (!args.upsert) return null;
|
|
28285
|
+
if (input.id) return db2.from(tableNamePlural).where({ id: input.id }).first();
|
|
28286
|
+
if (input.external_id) return db2.from(tableNamePlural).where({ external_id: input.external_id }).first();
|
|
28287
|
+
return null;
|
|
28288
|
+
}
|
|
28289
|
+
});
|
|
28290
|
+
}
|
|
27841
28291
|
if (table.name.singular === "user" && input.email) {
|
|
27842
28292
|
input.email = String(input.email).trim().toLowerCase();
|
|
27843
28293
|
}
|
|
@@ -27940,6 +28390,14 @@ function createMutations(table, contexts, tools, config) {
|
|
|
27940
28390
|
throw new Error("Record not found");
|
|
27941
28391
|
}
|
|
27942
28392
|
await validateWriteAccess(item.id, context);
|
|
28393
|
+
if (table.type === "items") {
|
|
28394
|
+
await assertItemFileKeysReadable({
|
|
28395
|
+
input,
|
|
28396
|
+
user: context.user,
|
|
28397
|
+
s3prefix: config?.fileUploads?.s3prefix,
|
|
28398
|
+
loadExisting: () => db2.from(tableNamePlural).where({ id: item.id }).first()
|
|
28399
|
+
});
|
|
28400
|
+
}
|
|
27943
28401
|
const existingRow = args.merge?.length ? await db2.from(tableNamePlural).where({ id: item.id }).first() : null;
|
|
27944
28402
|
const prepared = prepareItemWrite({
|
|
27945
28403
|
fields: table.fields,
|
|
@@ -28004,8 +28462,24 @@ function createMutations(table, contexts, tools, config) {
|
|
|
28004
28462
|
[`${tableNamePlural}UpdateOneById`]: async (_, args, context, info) => {
|
|
28005
28463
|
const { db: db2, req } = context;
|
|
28006
28464
|
let { id, input } = args;
|
|
28465
|
+
if (context.user?.via_companion === true && ["rights_mode", "RBAC", "created_by", "id"].some(
|
|
28466
|
+
(key) => Object.prototype.hasOwnProperty.call(input ?? {}, key)
|
|
28467
|
+
)) {
|
|
28468
|
+
throw new Error("Access rights of a row cannot be changed through the companion server.");
|
|
28469
|
+
}
|
|
28470
|
+
if (context.user?.via_companion === true && args.generateEmbeddings === true) {
|
|
28471
|
+
throw new Error("Embedding generation cannot be requested through the companion server.");
|
|
28472
|
+
}
|
|
28007
28473
|
await validateCreateOrRemoveSuperAdminPermission(tableNamePlural, input, req);
|
|
28008
28474
|
await validateWriteAccess(id, context);
|
|
28475
|
+
if (table.type === "items") {
|
|
28476
|
+
await assertItemFileKeysReadable({
|
|
28477
|
+
input,
|
|
28478
|
+
user: context.user,
|
|
28479
|
+
s3prefix: config?.fileUploads?.s3prefix,
|
|
28480
|
+
loadExisting: () => db2.from(tableNamePlural).where({ id }).first()
|
|
28481
|
+
});
|
|
28482
|
+
}
|
|
28009
28483
|
const rbacData = input.RBAC;
|
|
28010
28484
|
delete input.RBAC;
|
|
28011
28485
|
delete input.created_by;
|
|
@@ -29646,7 +30120,7 @@ async function recordMemoryUsage(input) {
|
|
|
29646
30120
|
}
|
|
29647
30121
|
|
|
29648
30122
|
// src/exulu/generate-stream.ts
|
|
29649
|
-
var
|
|
30123
|
+
var import_node_crypto14 = require("crypto");
|
|
29650
30124
|
var processFilePartsInMessages = async (messages, offloadCtx) => {
|
|
29651
30125
|
const processedMessages = await Promise.all(
|
|
29652
30126
|
messages.map(async (message) => {
|
|
@@ -30077,7 +30551,7 @@ When a tool execution is not approved by the user, do not retry it unless explic
|
|
|
30077
30551
|
contextId: agent.memory,
|
|
30078
30552
|
agentId: agent.id,
|
|
30079
30553
|
session: session ?? null,
|
|
30080
|
-
messageId: output.response?.id ?? (0,
|
|
30554
|
+
messageId: output.response?.id ?? (0, import_node_crypto14.randomUUID)(),
|
|
30081
30555
|
userId: user?.id ?? null
|
|
30082
30556
|
});
|
|
30083
30557
|
}
|
|
@@ -30153,7 +30627,7 @@ When a tool execution is not approved by the user, do not retry it unless explic
|
|
|
30153
30627
|
contextId: agent.memory,
|
|
30154
30628
|
agentId: agent.id,
|
|
30155
30629
|
session: session ?? null,
|
|
30156
|
-
messageId: response?.id ?? (0,
|
|
30630
|
+
messageId: response?.id ?? (0, import_node_crypto14.randomUUID)(),
|
|
30157
30631
|
userId: user?.id ?? null
|
|
30158
30632
|
});
|
|
30159
30633
|
}
|
|
@@ -30723,7 +31197,7 @@ init_singleton();
|
|
|
30723
31197
|
|
|
30724
31198
|
// src/exulu/email-inbound/intake.ts
|
|
30725
31199
|
init_cjs_shims();
|
|
30726
|
-
var
|
|
31200
|
+
var import_node_crypto17 = require("crypto");
|
|
30727
31201
|
init_client();
|
|
30728
31202
|
init_uppy();
|
|
30729
31203
|
init_singleton();
|
|
@@ -30731,7 +31205,7 @@ init_run_session();
|
|
|
30731
31205
|
|
|
30732
31206
|
// src/exulu/email-inbound/normalize.ts
|
|
30733
31207
|
init_cjs_shims();
|
|
30734
|
-
var
|
|
31208
|
+
var import_node_crypto15 = require("crypto");
|
|
30735
31209
|
var import_mailparser = require("mailparser");
|
|
30736
31210
|
var htmlToText = (html) => html.replace(/<style[\s\S]*?<\/style>/gi, " ").replace(/<script[\s\S]*?<\/script>/gi, " ").replace(/<[^>]+>/g, " ").replace(/ /gi, " ").replace(/</gi, "<").replace(/>/gi, ">").replace(/&/gi, "&").replace(/\s+/g, " ").trim();
|
|
30737
31211
|
var headerValueToString = (value) => {
|
|
@@ -30772,7 +31246,7 @@ async function parseRawMime(raw) {
|
|
|
30772
31246
|
return {
|
|
30773
31247
|
// Message-ID is the dedup key (spec §4.4.5). A missing header gets a
|
|
30774
31248
|
// deterministic content hash so webhook/job retries still dedup.
|
|
30775
|
-
messageId: parsed.messageId ?? `generated-${(0,
|
|
31249
|
+
messageId: parsed.messageId ?? `generated-${(0, import_node_crypto15.createHash)("sha256").update(raw).digest("hex")}`,
|
|
30776
31250
|
from: {
|
|
30777
31251
|
address: fromEntry.address.toLowerCase(),
|
|
30778
31252
|
...fromEntry.name ? { name: fromEntry.name } : {}
|
|
@@ -30792,7 +31266,7 @@ async function parseRawMime(raw) {
|
|
|
30792
31266
|
|
|
30793
31267
|
// src/exulu/email-inbound/adapters.ts
|
|
30794
31268
|
init_cjs_shims();
|
|
30795
|
-
var
|
|
31269
|
+
var import_node_crypto16 = require("crypto");
|
|
30796
31270
|
var import_node_stream = require("stream");
|
|
30797
31271
|
var import_busboy = __toESM(require("busboy"), 1);
|
|
30798
31272
|
var htmlToText2 = (html) => html.replace(/<\s*(script|style)[^>]*>[\s\S]*?<\s*\/\s*\1\s*>/gi, "").replace(/<[^>]+>/g, " ").replace(/ /gi, " ").replace(/&/gi, "&").replace(/</gi, "<").replace(/>/gi, ">").replace(/\s+/g, " ").trim();
|
|
@@ -30857,7 +31331,7 @@ function jsonToInboundEmail(raw) {
|
|
|
30857
31331
|
const subject = typeof obj.subject === "string" ? obj.subject : "";
|
|
30858
31332
|
const html = typeof obj.html === "string" ? obj.html : void 0;
|
|
30859
31333
|
const text = typeof obj.text === "string" && obj.text ? obj.text : html ? htmlToText2(html) : "";
|
|
30860
|
-
const messageId = typeof obj.message_id === "string" && obj.message_id ? obj.message_id : `<${(0,
|
|
31334
|
+
const messageId = typeof obj.message_id === "string" && obj.message_id ? obj.message_id : `<${(0, import_node_crypto16.randomUUID)()}@webhook.local>`;
|
|
30861
31335
|
const looksLikeAttachment = (a) => !!a && typeof a === "object" && !Array.isArray(a) && (typeof a.content_base64 === "string" || typeof a.filename === "string");
|
|
30862
31336
|
let rawAttachments;
|
|
30863
31337
|
if (obj.attachments === void 0 || obj.attachments === null) rawAttachments = [];
|
|
@@ -30906,7 +31380,7 @@ var DEFAULT_SENDER_RATE_LIMIT_PER_HOUR = 10;
|
|
|
30906
31380
|
var DEFAULT_FILTERED_RUN_RETENTION = 200;
|
|
30907
31381
|
var FILTER_BODY_BYTE_CAP = 10 * 1024;
|
|
30908
31382
|
var AUTO_REPLY_PRECEDENCE = /* @__PURE__ */ new Set(["bulk", "junk", "list"]);
|
|
30909
|
-
var
|
|
31383
|
+
var HOUR_MS2 = 60 * 60 * 1e3;
|
|
30910
31384
|
var isAutoReply = (email) => {
|
|
30911
31385
|
const autoSubmitted = email.headers.get("auto-submitted");
|
|
30912
31386
|
if (autoSubmitted !== void 0 && autoSubmitted.trim().toLowerCase() !== "no") {
|
|
@@ -30938,7 +31412,7 @@ var senderAllowed = (address, allowedSenders) => {
|
|
|
30938
31412
|
var checkRateLimit = async (redis, key, limitPerHour, now = Date.now()) => {
|
|
30939
31413
|
if (!redis) return true;
|
|
30940
31414
|
try {
|
|
30941
|
-
const currentBucket = Math.floor(now /
|
|
31415
|
+
const currentBucket = Math.floor(now / HOUR_MS2);
|
|
30942
31416
|
const currentKey = `${key}:${currentBucket}`;
|
|
30943
31417
|
const previousKey = `${key}:${currentBucket - 1}`;
|
|
30944
31418
|
const count2 = await redis.incr(currentKey);
|
|
@@ -30947,7 +31421,7 @@ var checkRateLimit = async (redis, key, limitPerHour, now = Date.now()) => {
|
|
|
30947
31421
|
}
|
|
30948
31422
|
const previousRaw = await redis.get(previousKey);
|
|
30949
31423
|
const previous = previousRaw ? Number(previousRaw) : 0;
|
|
30950
|
-
const elapsedFraction = now %
|
|
31424
|
+
const elapsedFraction = now % HOUR_MS2 / HOUR_MS2;
|
|
30951
31425
|
const weighted = count2 + previous * (1 - elapsedFraction);
|
|
30952
31426
|
return weighted <= limitPerHour;
|
|
30953
31427
|
} catch (err4) {
|
|
@@ -31127,7 +31601,7 @@ var fireRun = async (opts) => {
|
|
|
31127
31601
|
}
|
|
31128
31602
|
const warningNote = warnings.length ? "\n\n[Hinweis des Systems] " + warnings.map((w) => INTAKE_WARNING_TEXTS[w]).join(" ") : "";
|
|
31129
31603
|
const initialMessage = {
|
|
31130
|
-
id: (0,
|
|
31604
|
+
id: (0, import_node_crypto17.randomUUID)(),
|
|
31131
31605
|
role: "user",
|
|
31132
31606
|
parts: [
|
|
31133
31607
|
{
|
|
@@ -31940,71 +32414,6 @@ var createRunLock = (redis) => ({
|
|
|
31940
32414
|
|
|
31941
32415
|
// src/exulu/channels/wiring.ts
|
|
31942
32416
|
init_cjs_shims();
|
|
31943
|
-
|
|
31944
|
-
// src/exulu/external-rate-limit.ts
|
|
31945
|
-
init_cjs_shims();
|
|
31946
|
-
var MINUTE_MS = 6e4;
|
|
31947
|
-
var HOUR_MS2 = 36e5;
|
|
31948
|
-
var perMinuteLimit = () => parseInt(process.env.EXULU_EXTERNAL_RATE_PER_MINUTE || "30", 10);
|
|
31949
|
-
var perHourLimit = () => parseInt(process.env.EXULU_EXTERNAL_RATE_PER_HOUR || "300", 10);
|
|
31950
|
-
var windows = /* @__PURE__ */ new Map();
|
|
31951
|
-
var externalRateLimitExceeded = (userId, now = Date.now()) => {
|
|
31952
|
-
const state = windows.get(userId) ?? {
|
|
31953
|
-
minuteStart: now,
|
|
31954
|
-
minuteCount: 0,
|
|
31955
|
-
hourStart: now,
|
|
31956
|
-
hourCount: 0,
|
|
31957
|
-
lastSeen: now
|
|
31958
|
-
};
|
|
31959
|
-
if (now - state.minuteStart >= MINUTE_MS) {
|
|
31960
|
-
state.minuteStart = now;
|
|
31961
|
-
state.minuteCount = 0;
|
|
31962
|
-
}
|
|
31963
|
-
if (now - state.hourStart >= HOUR_MS2) {
|
|
31964
|
-
state.hourStart = now;
|
|
31965
|
-
state.hourCount = 0;
|
|
31966
|
-
}
|
|
31967
|
-
state.minuteCount += 1;
|
|
31968
|
-
state.hourCount += 1;
|
|
31969
|
-
state.lastSeen = now;
|
|
31970
|
-
windows.set(userId, state);
|
|
31971
|
-
if (windows.size > 1e4) {
|
|
31972
|
-
for (const [key, value] of windows) {
|
|
31973
|
-
if (now - value.lastSeen >= HOUR_MS2) windows.delete(key);
|
|
31974
|
-
}
|
|
31975
|
-
if (windows.size > 1e4) {
|
|
31976
|
-
const sorted = [...windows.entries()].sort(
|
|
31977
|
-
(a, b) => a[1].lastSeen - b[1].lastSeen
|
|
31978
|
-
);
|
|
31979
|
-
for (const [key] of sorted) {
|
|
31980
|
-
if (windows.size <= 1e4) break;
|
|
31981
|
-
windows.delete(key);
|
|
31982
|
-
}
|
|
31983
|
-
}
|
|
31984
|
-
}
|
|
31985
|
-
const minuteLimitExceeded = state.minuteCount > perMinuteLimit();
|
|
31986
|
-
const hourLimitExceeded = state.hourCount > perHourLimit();
|
|
31987
|
-
const limitExceeded = minuteLimitExceeded || hourLimitExceeded;
|
|
31988
|
-
if (limitExceeded) {
|
|
31989
|
-
const limits = {
|
|
31990
|
-
perMinute: perMinuteLimit(),
|
|
31991
|
-
perHour: perHourLimit()
|
|
31992
|
-
};
|
|
31993
|
-
const current = {
|
|
31994
|
-
minute: state.minuteCount,
|
|
31995
|
-
hour: state.hourCount
|
|
31996
|
-
};
|
|
31997
|
-
console.warn(
|
|
31998
|
-
`[EXULU] Rate limit exceeded for user ${userId}${minuteLimitExceeded ? ` per-minute (${current.minute}/${limits.perMinute})` : ""}${minuteLimitExceeded && hourLimitExceeded ? " and" : ""}${hourLimitExceeded ? ` per-hour (${current.hour}/${limits.perHour})` : ""}`
|
|
31999
|
-
);
|
|
32000
|
-
}
|
|
32001
|
-
return limitExceeded;
|
|
32002
|
-
};
|
|
32003
|
-
var isExternalUser = (user) => {
|
|
32004
|
-
return user?.role?.name === "external";
|
|
32005
|
-
};
|
|
32006
|
-
|
|
32007
|
-
// src/exulu/channels/wiring.ts
|
|
32008
32417
|
var channelStoreFromRedis = (client2) => ({
|
|
32009
32418
|
set: (key, value, opts) => client2.set(key, value, opts.NX ? { EX: opts.EX, NX: true } : { EX: opts.EX }),
|
|
32010
32419
|
getDel: (key) => client2.getDel(key),
|
|
@@ -35760,7 +36169,7 @@ var liveRecordingService = {
|
|
|
35760
36169
|
|
|
35761
36170
|
// src/exulu/email-inbound/trigger-config.ts
|
|
35762
36171
|
init_cjs_shims();
|
|
35763
|
-
var
|
|
36172
|
+
var import_node_crypto18 = require("crypto");
|
|
35764
36173
|
var import_safe_regex = __toESM(require("safe-regex"), 1);
|
|
35765
36174
|
var MAX_FILTER_PATTERN_LENGTH = 200;
|
|
35766
36175
|
var FILTER_FIELDS = [
|
|
@@ -35854,10 +36263,10 @@ function validateEmailTriggerConfig(raw) {
|
|
|
35854
36263
|
return config;
|
|
35855
36264
|
}
|
|
35856
36265
|
function generateTriggerSecret() {
|
|
35857
|
-
return (0,
|
|
36266
|
+
return (0, import_node_crypto18.randomBytes)(32).toString("base64url");
|
|
35858
36267
|
}
|
|
35859
36268
|
function generateSigningSecret() {
|
|
35860
|
-
return (0,
|
|
36269
|
+
return (0, import_node_crypto18.randomBytes)(32).toString("base64url");
|
|
35861
36270
|
}
|
|
35862
36271
|
|
|
35863
36272
|
// src/graphql/schemas/index.ts
|
|
@@ -35897,11 +36306,11 @@ async function insertTriggerWithSecretRetry(insertFn, baseRow) {
|
|
|
35897
36306
|
|
|
35898
36307
|
// src/exulu/email-inbound/webhook.ts
|
|
35899
36308
|
init_cjs_shims();
|
|
35900
|
-
var
|
|
36309
|
+
var import_node_crypto20 = require("crypto");
|
|
35901
36310
|
|
|
35902
36311
|
// src/exulu/email-inbound/verify-signature.ts
|
|
35903
36312
|
init_cjs_shims();
|
|
35904
|
-
var
|
|
36313
|
+
var import_node_crypto19 = require("crypto");
|
|
35905
36314
|
var SIGNATURE_REPLAY_WINDOW_SECONDS = 300;
|
|
35906
36315
|
var REPLAY_TTL_SECONDS = 900;
|
|
35907
36316
|
function verifyPayloadSignature(rawBody, signatureHeader, timestampHeader, secret) {
|
|
@@ -35910,11 +36319,11 @@ function verifyPayloadSignature(rawBody, signatureHeader, timestampHeader, secre
|
|
|
35910
36319
|
const provided = signatureHeader.slice("sha256=".length);
|
|
35911
36320
|
if (!/^[0-9a-f]+$/i.test(provided)) return false;
|
|
35912
36321
|
const message = timestampHeader ? Buffer.concat([Buffer.from(`${timestampHeader}.`), rawBody]) : rawBody;
|
|
35913
|
-
const expected = (0,
|
|
36322
|
+
const expected = (0, import_node_crypto19.createHmac)("sha256", secret).update(message).digest("hex");
|
|
35914
36323
|
const expectedBuf = Buffer.from(expected, "utf8");
|
|
35915
36324
|
const providedBuf = Buffer.from(provided.toLowerCase(), "utf8");
|
|
35916
36325
|
if (expectedBuf.length !== providedBuf.length) return false;
|
|
35917
|
-
return (0,
|
|
36326
|
+
return (0, import_node_crypto19.timingSafeEqual)(expectedBuf, providedBuf);
|
|
35918
36327
|
}
|
|
35919
36328
|
async function isReplay(redis, signature, timestamp) {
|
|
35920
36329
|
const ts = Number(timestamp);
|
|
@@ -36019,7 +36428,7 @@ var createRoutineWebhookHandler = (deps) => async (req, res) => {
|
|
|
36019
36428
|
);
|
|
36020
36429
|
try {
|
|
36021
36430
|
const ext = format === "json" ? "json" : "eml";
|
|
36022
|
-
const s3Key = await deps.putRawPayload(`${EMAIL_INBOUND_S3_PREFIX}${(0,
|
|
36431
|
+
const s3Key = await deps.putRawPayload(`${EMAIL_INBOUND_S3_PREFIX}${(0, import_node_crypto20.randomUUID)()}.${ext}`, payloadBytes);
|
|
36023
36432
|
await deps.enqueueIntake({ s3Key, triggerId: trigger.id, format });
|
|
36024
36433
|
} catch (error) {
|
|
36025
36434
|
console.error("[EXULU-WEBHOOK] persist/enqueue failed", error);
|
|
@@ -36031,7 +36440,7 @@ var createRoutineWebhookHandler = (deps) => async (req, res) => {
|
|
|
36031
36440
|
|
|
36032
36441
|
// src/graphql/schemas/index.ts
|
|
36033
36442
|
init_uppy();
|
|
36034
|
-
var
|
|
36443
|
+
var import_node_crypto21 = require("crypto");
|
|
36035
36444
|
init_memory_base();
|
|
36036
36445
|
|
|
36037
36446
|
// src/graphql/resolvers/memory-base-stats.ts
|
|
@@ -37456,6 +37865,12 @@ type StatisticsResult {
|
|
|
37456
37865
|
group: String!
|
|
37457
37866
|
count: Int!
|
|
37458
37867
|
}
|
|
37868
|
+
|
|
37869
|
+
type ChunkSourceDocument {
|
|
37870
|
+
url: String!
|
|
37871
|
+
filename: String!
|
|
37872
|
+
page: Int
|
|
37873
|
+
}
|
|
37459
37874
|
`;
|
|
37460
37875
|
}
|
|
37461
37876
|
function createSDL(tables, contexts, tools, config, evals) {
|
|
@@ -37556,6 +37971,7 @@ function createSDL(tables, contexts, tools, config, evals) {
|
|
|
37556
37971
|
typeDefs += `
|
|
37557
37972
|
${tableNamePlural}VectorSearch(limit: Int, query: String!, method: VectorMethodEnum!, itemFilters: [Filter${tableNameSingularUpperCaseFirst}], cutoffs: SearchCutoffs, expand: SearchExpand, entityFilter: ${tableNameSingular}EntityFilterInput): ${tableNameSingular}VectorSearchResult
|
|
37558
37973
|
${tableNameSingular}ChunkById(id: ID!): ${tableNameSingular}VectorSearchChunk
|
|
37974
|
+
${tableNameSingular}ChunkSourceDocument(id: ID!): ChunkSourceDocument
|
|
37559
37975
|
${tableNameSingular}StaleEntityCount: Int
|
|
37560
37976
|
${tableNameSingular}EntityModel: ${tableNameSingular}EntityModelInfo
|
|
37561
37977
|
${tableNameSingular}EntitiesForItem(item: ID!): [${tableNameSingular}ItemEntity!]
|
|
@@ -37852,7 +38268,7 @@ type PageInfo {
|
|
|
37852
38268
|
hasNextPage: Boolean!
|
|
37853
38269
|
}
|
|
37854
38270
|
`;
|
|
37855
|
-
Object.assign(resolvers2.Query, createQueries(table, tools, contexts));
|
|
38271
|
+
Object.assign(resolvers2.Query, createQueries(table, tools, contexts, config));
|
|
37856
38272
|
Object.assign(
|
|
37857
38273
|
resolvers2.Mutation,
|
|
37858
38274
|
createMutations(table, contexts, tools, config)
|
|
@@ -37862,13 +38278,7 @@ type PageInfo {
|
|
|
37862
38278
|
if (!resolvers2[rbacResolverName]) {
|
|
37863
38279
|
resolvers2[rbacResolverName] = {};
|
|
37864
38280
|
}
|
|
37865
|
-
resolvers2[rbacResolverName].RBAC = async (parent, args, context) =>
|
|
37866
|
-
const { db: db2 } = context;
|
|
37867
|
-
const resourceId = parent.id;
|
|
37868
|
-
const entityName = table.name.singular;
|
|
37869
|
-
const rights_mode = parent.rights_mode;
|
|
37870
|
-
return RBACResolver(db2, entityName, resourceId, rights_mode);
|
|
37871
|
-
};
|
|
38281
|
+
resolvers2[rbacResolverName].RBAC = async (parent, args, context) => resolveRbacField(table, parent, context);
|
|
37872
38282
|
}
|
|
37873
38283
|
}
|
|
37874
38284
|
typeDefs += `
|
|
@@ -38566,7 +38976,7 @@ type EmbeddingModelOption {
|
|
|
38566
38976
|
const ext = format === "json" ? "json" : "eml";
|
|
38567
38977
|
const fullKey = await uploadFile(
|
|
38568
38978
|
bytes,
|
|
38569
|
-
`${EMAIL_INBOUND_S3_PREFIX}${(0,
|
|
38979
|
+
`${EMAIL_INBOUND_S3_PREFIX}${(0, import_node_crypto21.randomUUID)()}.${ext}`,
|
|
38570
38980
|
config,
|
|
38571
38981
|
{ contentType: "application/octet-stream" },
|
|
38572
38982
|
void 0,
|
|
@@ -39873,7 +40283,7 @@ var import_body_parser = __toESM(require("body-parser"), 1);
|
|
|
39873
40283
|
var import_crypto_js7 = require("crypto-js");
|
|
39874
40284
|
var import_openai = require("openai");
|
|
39875
40285
|
var import_fs5 = __toESM(require("fs"), 1);
|
|
39876
|
-
var
|
|
40286
|
+
var import_node_crypto26 = require("crypto");
|
|
39877
40287
|
var import_api3 = require("@opentelemetry/api");
|
|
39878
40288
|
init_check_record_access();
|
|
39879
40289
|
var import_jszip4 = __toESM(require("jszip"), 1);
|
|
@@ -39881,7 +40291,7 @@ var import_jszip4 = __toESM(require("jszip"), 1);
|
|
|
39881
40291
|
// src/skills/bundled.ts
|
|
39882
40292
|
init_cjs_shims();
|
|
39883
40293
|
var import_jszip3 = __toESM(require("jszip"), 1);
|
|
39884
|
-
var
|
|
40294
|
+
var import_node_crypto22 = require("crypto");
|
|
39885
40295
|
|
|
39886
40296
|
// src/skills/bundled.generated.ts
|
|
39887
40297
|
init_cjs_shims();
|
|
@@ -39906,7 +40316,7 @@ var BUNDLED_SKILLS = [
|
|
|
39906
40316
|
init_frontmatter();
|
|
39907
40317
|
var BUNDLED_LABEL = "Bundled with the IMP";
|
|
39908
40318
|
function bundledSkillHash(skill) {
|
|
39909
|
-
const h = (0,
|
|
40319
|
+
const h = (0, import_node_crypto22.createHash)("sha256");
|
|
39910
40320
|
for (const path4 of Object.keys(skill.files).sort()) {
|
|
39911
40321
|
h.update(path4).update("\0").update(skill.files[path4]).update("\0");
|
|
39912
40322
|
}
|
|
@@ -39967,7 +40377,7 @@ async function seedBundledSkills({
|
|
|
39967
40377
|
log7(`"${skill.name}" updated to v${nextVersion}`);
|
|
39968
40378
|
continue;
|
|
39969
40379
|
}
|
|
39970
|
-
const skillId = (0,
|
|
40380
|
+
const skillId = (0, import_node_crypto22.randomUUID)();
|
|
39971
40381
|
await extractBundleToVersion({ bytes: await bundledSkillZip(skill), skillId, version: 1, config });
|
|
39972
40382
|
await db2("skills").insert({
|
|
39973
40383
|
id: skillId,
|
|
@@ -40079,7 +40489,7 @@ var persistThroughDisconnect = () => ({
|
|
|
40079
40489
|
|
|
40080
40490
|
// src/exulu/compact-session.ts
|
|
40081
40491
|
init_cjs_shims();
|
|
40082
|
-
var
|
|
40492
|
+
var import_node_crypto23 = require("crypto");
|
|
40083
40493
|
var import_ai14 = require("ai");
|
|
40084
40494
|
init_truncate_tool_output();
|
|
40085
40495
|
init_context_budget();
|
|
@@ -40185,7 +40595,7 @@ Focus especially on: ${steer.trim()}` : SUMMARY_SYSTEM;
|
|
|
40185
40595
|
...steer?.trim() ? { steer: steer.trim() } : {}
|
|
40186
40596
|
};
|
|
40187
40597
|
const checkpoint = {
|
|
40188
|
-
id: `compaction_${(0,
|
|
40598
|
+
id: `compaction_${(0, import_node_crypto23.randomUUID)()}`,
|
|
40189
40599
|
role: "user",
|
|
40190
40600
|
parts: [{ type: "text", text: `[Conversation summary \u2014 earlier messages were compacted]
|
|
40191
40601
|
|
|
@@ -41221,13 +41631,13 @@ function isInside2(key, fullPrefix) {
|
|
|
41221
41631
|
return key.startsWith(fullPrefix) && !key.includes("..");
|
|
41222
41632
|
}
|
|
41223
41633
|
function registerProjectFileRoutes(app, deps) {
|
|
41224
|
-
const
|
|
41634
|
+
const idOf4 = (req) => String(req.params.projectId ?? "");
|
|
41225
41635
|
const rowId = (authed) => String(authed.project.id);
|
|
41226
41636
|
const listObjects = async (projectId) => (await deps.s3.list(projectFilePrefix(projectId, deps.s3prefix).projectPrefix)).filter(
|
|
41227
41637
|
(o) => !o.key.endsWith("/")
|
|
41228
41638
|
);
|
|
41229
41639
|
app.get("/projects/:projectId/files", async (req, res) => {
|
|
41230
|
-
const projectId =
|
|
41640
|
+
const projectId = idOf4(req);
|
|
41231
41641
|
const authed = await deps.loadAuthedProject(req, res, projectId, "read");
|
|
41232
41642
|
if (!authed) return;
|
|
41233
41643
|
const canWrite2 = await deps.canWrite(authed.user, authed.project);
|
|
@@ -41248,7 +41658,7 @@ function registerProjectFileRoutes(app, deps) {
|
|
|
41248
41658
|
res.json({ canWrite: canWrite2, files });
|
|
41249
41659
|
});
|
|
41250
41660
|
app.post("/projects/:projectId/files/upload-sign", async (req, res) => {
|
|
41251
|
-
const projectId =
|
|
41661
|
+
const projectId = idOf4(req);
|
|
41252
41662
|
const authed = await deps.loadAuthedProject(req, res, projectId, "write");
|
|
41253
41663
|
if (!authed) return;
|
|
41254
41664
|
const { filename, contentType, overwrite } = req.body ?? {};
|
|
@@ -41288,7 +41698,7 @@ function registerProjectFileRoutes(app, deps) {
|
|
|
41288
41698
|
}
|
|
41289
41699
|
});
|
|
41290
41700
|
app.delete("/projects/:projectId/files", async (req, res) => {
|
|
41291
|
-
const projectId =
|
|
41701
|
+
const projectId = idOf4(req);
|
|
41292
41702
|
const key = req.query.key;
|
|
41293
41703
|
if (!key || typeof key !== "string") {
|
|
41294
41704
|
res.status(400).json({ detail: "Missing or invalid 'key' query parameter." });
|
|
@@ -41313,7 +41723,7 @@ function registerProjectFileRoutes(app, deps) {
|
|
|
41313
41723
|
if (!req.headers.authorization && typeof req.query.auth === "string") {
|
|
41314
41724
|
req.headers.authorization = `Bearer ${req.query.auth}`;
|
|
41315
41725
|
}
|
|
41316
|
-
const projectId =
|
|
41726
|
+
const projectId = idOf4(req);
|
|
41317
41727
|
const key = req.query.key;
|
|
41318
41728
|
if (!key || typeof key !== "string") {
|
|
41319
41729
|
res.status(400).json({ detail: "Missing or invalid 'key' query parameter." });
|
|
@@ -41342,7 +41752,7 @@ function registerProjectFileRoutes(app, deps) {
|
|
|
41342
41752
|
}
|
|
41343
41753
|
});
|
|
41344
41754
|
app.post("/projects/:projectId/files/promote", async (req, res) => {
|
|
41345
|
-
const projectId =
|
|
41755
|
+
const projectId = idOf4(req);
|
|
41346
41756
|
const { sessionId, keys, overwrite } = req.body ?? {};
|
|
41347
41757
|
if (typeof sessionId !== "string" || !sessionId || !Array.isArray(keys)) {
|
|
41348
41758
|
res.status(400).json({ detail: "sessionId (string) and keys (array) are required." });
|
|
@@ -41429,9 +41839,142 @@ function registerViewerIdentityRoutes(app, deps) {
|
|
|
41429
41839
|
});
|
|
41430
41840
|
}
|
|
41431
41841
|
|
|
41842
|
+
// src/exulu/companion/external-share-route.ts
|
|
41843
|
+
init_cjs_shims();
|
|
41844
|
+
init_shared_artifacts();
|
|
41845
|
+
var SHARED_ARTIFACT_EXTERNAL_PATH = "/shared-artifacts/:name/external";
|
|
41846
|
+
function registerExternalShareRoute(app, deps) {
|
|
41847
|
+
app.get(SHARED_ARTIFACT_EXTERNAL_PATH, async (req, res) => {
|
|
41848
|
+
const notFound = () => res.status(404).json({ detail: "Not found." });
|
|
41849
|
+
try {
|
|
41850
|
+
if (companionRequestState(req.headers, deps.env ?? process.env) !== "valid") {
|
|
41851
|
+
notFound();
|
|
41852
|
+
return;
|
|
41853
|
+
}
|
|
41854
|
+
const db2 = await deps.getDb();
|
|
41855
|
+
const row = await getSharedArtifactByName(db2, req.params.name ?? "");
|
|
41856
|
+
if (!row || isExpired(row.expires_at, /* @__PURE__ */ new Date()) || row.auth_mode !== "regular" || row.external_access !== true) {
|
|
41857
|
+
notFound();
|
|
41858
|
+
return;
|
|
41859
|
+
}
|
|
41860
|
+
const grants = await db2("rbac").where({ entity: "shared_artifact", target_resource_id: row.id, access_type: "Team" }).select("team_id");
|
|
41861
|
+
const teams = await teamNamesByIds(db2, grants.map((g) => g.team_id));
|
|
41862
|
+
if (validateExternalAccess({
|
|
41863
|
+
external_access: true,
|
|
41864
|
+
auth_mode: row.auth_mode,
|
|
41865
|
+
rights_mode: row.rights_mode,
|
|
41866
|
+
teams
|
|
41867
|
+
}) !== null) {
|
|
41868
|
+
notFound();
|
|
41869
|
+
return;
|
|
41870
|
+
}
|
|
41871
|
+
res.status(204).end();
|
|
41872
|
+
} catch (e) {
|
|
41873
|
+
console.error("[EXULU] companion external check failed", e);
|
|
41874
|
+
notFound();
|
|
41875
|
+
}
|
|
41876
|
+
});
|
|
41877
|
+
}
|
|
41878
|
+
|
|
41879
|
+
// src/exulu/companion/status-routes.ts
|
|
41880
|
+
init_cjs_shims();
|
|
41881
|
+
|
|
41882
|
+
// src/exulu/companion/status.ts
|
|
41883
|
+
init_cjs_shims();
|
|
41884
|
+
var HEALTH_TIMEOUT_MS = 5e3;
|
|
41885
|
+
var CACHE_TTL_MS2 = 3e4;
|
|
41886
|
+
var VERSION_RE = /^[\w.+-]{1,32}$/;
|
|
41887
|
+
var HOST_RE = /^[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?(:\d{1,5})?$/;
|
|
41888
|
+
var checkCompanion = async (deps) => {
|
|
41889
|
+
const host = deps.env.EXULU_COMPANION_HOST;
|
|
41890
|
+
const key = deps.env.EXULU_COMPANION_KEY;
|
|
41891
|
+
if (!host || !key || !HOST_RE.test(host)) return { state: "not_configured" };
|
|
41892
|
+
const checkedAt = deps.now().toISOString();
|
|
41893
|
+
const unreachable = { state: "unreachable", host, checkedAt };
|
|
41894
|
+
try {
|
|
41895
|
+
const res = await deps.fetch(`https://${host}/_companion/health`, {
|
|
41896
|
+
method: "GET",
|
|
41897
|
+
headers: { [COMPANION_HEADER]: key },
|
|
41898
|
+
redirect: "error",
|
|
41899
|
+
signal: AbortSignal.timeout(HEALTH_TIMEOUT_MS)
|
|
41900
|
+
});
|
|
41901
|
+
if (res.status !== 200) return unreachable;
|
|
41902
|
+
const body = await res.json();
|
|
41903
|
+
if (!body || typeof body !== "object" || typeof body.version !== "string" || !VERSION_RE.test(body.version) || typeof body.upstream !== "boolean") {
|
|
41904
|
+
return unreachable;
|
|
41905
|
+
}
|
|
41906
|
+
const { version, upstream } = body;
|
|
41907
|
+
if (version.includes(key)) return unreachable;
|
|
41908
|
+
return { state: upstream ? "connected" : "no_tunnel", host, version, checkedAt };
|
|
41909
|
+
} catch {
|
|
41910
|
+
return unreachable;
|
|
41911
|
+
}
|
|
41912
|
+
};
|
|
41913
|
+
var createCompanionStatusCache = (deps) => {
|
|
41914
|
+
let cached = null;
|
|
41915
|
+
return {
|
|
41916
|
+
get: async (refresh = false) => {
|
|
41917
|
+
const t = deps.now().getTime();
|
|
41918
|
+
if (!refresh && cached && t - cached.at < CACHE_TTL_MS2 && t >= cached.at) return cached.value;
|
|
41919
|
+
const value = await checkCompanion(deps);
|
|
41920
|
+
cached = { at: t, value };
|
|
41921
|
+
return value;
|
|
41922
|
+
}
|
|
41923
|
+
};
|
|
41924
|
+
};
|
|
41925
|
+
var cachedCompanionStatus = createCompanionStatusCache({
|
|
41926
|
+
env: process.env,
|
|
41927
|
+
fetch: globalThis.fetch,
|
|
41928
|
+
now: () => /* @__PURE__ */ new Date()
|
|
41929
|
+
});
|
|
41930
|
+
|
|
41931
|
+
// src/exulu/companion/status-routes.ts
|
|
41932
|
+
function registerCompanionStatusRoutes(app, deps) {
|
|
41933
|
+
const status = deps.status ?? cachedCompanionStatus;
|
|
41934
|
+
const requireSuperAdmin = async (req, res) => {
|
|
41935
|
+
const auth = await deps.authenticate(req);
|
|
41936
|
+
if (!auth.user?.id) {
|
|
41937
|
+
res.status(auth.code ?? 401).json({ detail: auth.message });
|
|
41938
|
+
return false;
|
|
41939
|
+
}
|
|
41940
|
+
if (auth.user.super_admin !== true) {
|
|
41941
|
+
res.status(403).json({ detail: "Only a super admin can view the companion server." });
|
|
41942
|
+
return false;
|
|
41943
|
+
}
|
|
41944
|
+
return true;
|
|
41945
|
+
};
|
|
41946
|
+
app.get("/companion/status", async (req, res) => {
|
|
41947
|
+
if (!await requireSuperAdmin(req, res)) return;
|
|
41948
|
+
res.json(await status.get(req.query.refresh === "1"));
|
|
41949
|
+
});
|
|
41950
|
+
app.get("/companion/released", async (req, res) => {
|
|
41951
|
+
if (!await requireSuperAdmin(req, res)) return;
|
|
41952
|
+
try {
|
|
41953
|
+
const db2 = await deps.getDb();
|
|
41954
|
+
const shares = await db2("shared_artifacts").where({ external_access: true }).select("id", "name");
|
|
41955
|
+
const grants = shares.length ? await db2("rbac").where({ entity: "shared_artifact", access_type: "Team" }).whereIn("target_resource_id", shares.map((s) => s.id)).select("target_resource_id", "team_id") : [];
|
|
41956
|
+
const teamIds = [...new Set(grants.map((g) => g.team_id).filter(Boolean))];
|
|
41957
|
+
const teams = teamIds.length ? await db2("teams").whereIn("id", teamIds).select("id", "name") : [];
|
|
41958
|
+
const users = teamIds.length ? await db2("users").where({ type: "external" }).whereIn("team", teamIds).select("team") : [];
|
|
41959
|
+
const counts = /* @__PURE__ */ new Map();
|
|
41960
|
+
for (const u of users) counts.set(u.team, (counts.get(u.team) ?? 0) + 1);
|
|
41961
|
+
const teamName = new Map(teams.map((t) => [t.id, t.name]));
|
|
41962
|
+
res.json({
|
|
41963
|
+
items: shares.map((s) => ({
|
|
41964
|
+
name: s.name,
|
|
41965
|
+
teams: [...new Set(grants.filter((g) => g.target_resource_id === s.id).map((g) => g.team_id))].filter((id) => teamName.has(id)).map((id) => ({ id, name: teamName.get(id), users: counts.get(id) ?? 0 }))
|
|
41966
|
+
}))
|
|
41967
|
+
});
|
|
41968
|
+
} catch (e) {
|
|
41969
|
+
console.error("[EXULU] companion released listing failed", e);
|
|
41970
|
+
res.status(500).json({ detail: "Failed to list released artifacts." });
|
|
41971
|
+
}
|
|
41972
|
+
});
|
|
41973
|
+
}
|
|
41974
|
+
|
|
41432
41975
|
// src/exulu/tool-api-route.ts
|
|
41433
41976
|
init_cjs_shims();
|
|
41434
|
-
var
|
|
41977
|
+
var import_node_crypto24 = require("crypto");
|
|
41435
41978
|
init_progress();
|
|
41436
41979
|
var TOOL_API_ROUTE_PATH = "/tools/:id";
|
|
41437
41980
|
var toolConfigDefaults = (tool5) => Object.fromEntries(
|
|
@@ -41472,7 +42015,7 @@ function registerToolApiRoutes(app, deps) {
|
|
|
41472
42015
|
res.status(500).json({ detail: "Tool has no execute function." });
|
|
41473
42016
|
return;
|
|
41474
42017
|
}
|
|
41475
|
-
const toolCallId = `${tool5.id}_${(0,
|
|
42018
|
+
const toolCallId = `${tool5.id}_${(0, import_node_crypto24.randomUUID)()}`;
|
|
41476
42019
|
const started = Date.now();
|
|
41477
42020
|
let output;
|
|
41478
42021
|
let status = "ok";
|
|
@@ -41556,6 +42099,23 @@ function registerCreateShareRoute(app, deps) {
|
|
|
41556
42099
|
res.status(400).json({ detail: valid.message });
|
|
41557
42100
|
return;
|
|
41558
42101
|
}
|
|
42102
|
+
if (!mayChangeExternalRelease(auth.user, req.body.external_access, false)) {
|
|
42103
|
+
res.status(403).json({ detail: EXTERNAL_SUPER_ADMIN_ONLY });
|
|
42104
|
+
return;
|
|
42105
|
+
}
|
|
42106
|
+
if (req.body.external_access !== void 0) {
|
|
42107
|
+
const teamIds = req.body.external_access === true && Array.isArray(req.body.rbac?.teams) ? req.body.rbac.teams.map((t) => t?.id) : [];
|
|
42108
|
+
const externalError = validateExternalAccess({
|
|
42109
|
+
external_access: req.body.external_access,
|
|
42110
|
+
auth_mode: req.body.auth_mode,
|
|
42111
|
+
rights_mode: req.body.rights_mode ?? "private",
|
|
42112
|
+
teams: await teamNamesByIds(db2, teamIds)
|
|
42113
|
+
});
|
|
42114
|
+
if (externalError) {
|
|
42115
|
+
res.status(400).json({ detail: externalError });
|
|
42116
|
+
return;
|
|
42117
|
+
}
|
|
42118
|
+
}
|
|
41559
42119
|
const details = planDetails({ ...req.body, archived: void 0 }, now);
|
|
41560
42120
|
if (!details.ok) {
|
|
41561
42121
|
res.status(400).json({ detail: details.message });
|
|
@@ -41586,6 +42146,7 @@ function registerCreateShareRoute(app, deps) {
|
|
|
41586
42146
|
password_hash,
|
|
41587
42147
|
expires_at: req.body.expires_at ?? null,
|
|
41588
42148
|
content_type: req.body.content_type ?? null,
|
|
42149
|
+
external_access: req.body.external_access === true,
|
|
41589
42150
|
rights_mode,
|
|
41590
42151
|
created_by: auth.user.id,
|
|
41591
42152
|
...details.patch,
|
|
@@ -44411,7 +44972,7 @@ init_flow();
|
|
|
44411
44972
|
|
|
44412
44973
|
// src/exulu/recall/verify.ts
|
|
44413
44974
|
init_cjs_shims();
|
|
44414
|
-
var
|
|
44975
|
+
var import_node_crypto25 = require("crypto");
|
|
44415
44976
|
var TOLERANCE_SECONDS = 5 * 60;
|
|
44416
44977
|
var header = (headers, ...names) => {
|
|
44417
44978
|
for (const name of names) {
|
|
@@ -44429,7 +44990,7 @@ var safeEqual = (a, b) => {
|
|
|
44429
44990
|
const bufA = Buffer.from(a);
|
|
44430
44991
|
const bufB = Buffer.from(b);
|
|
44431
44992
|
if (bufA.length !== bufB.length) return false;
|
|
44432
|
-
return (0,
|
|
44993
|
+
return (0, import_node_crypto25.timingSafeEqual)(bufA, bufB);
|
|
44433
44994
|
};
|
|
44434
44995
|
var verifyRecallRequest = (headers, rawBody, secret = recallVerificationSecret()) => {
|
|
44435
44996
|
if (!secret) {
|
|
@@ -44451,7 +45012,7 @@ var verifyRecallRequest = (headers, rawBody, secret = recallVerificationSecret()
|
|
|
44451
45012
|
}
|
|
44452
45013
|
const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
|
|
44453
45014
|
const signedContent = `${id}.${timestamp}.${body}`;
|
|
44454
|
-
const expected = (0,
|
|
45015
|
+
const expected = (0, import_node_crypto25.createHmac)("sha256", secretKey(secret)).update(signedContent).digest("base64");
|
|
44455
45016
|
const passed = signatureHeader.split(" ").some((entry) => {
|
|
44456
45017
|
const [, sig] = entry.split(",");
|
|
44457
45018
|
return !!sig && safeEqual(sig, expected);
|
|
@@ -44464,6 +45025,7 @@ init_rbac_update();
|
|
|
44464
45025
|
init_shared_artifacts();
|
|
44465
45026
|
init_session_files();
|
|
44466
45027
|
init_session_file_adopt();
|
|
45028
|
+
init_guest_session_files();
|
|
44467
45029
|
|
|
44468
45030
|
// src/exulu/guest-rate-limit.ts
|
|
44469
45031
|
init_cjs_shims();
|
|
@@ -44823,7 +45385,12 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
44823
45385
|
const server = new import_server5.ApolloServer({
|
|
44824
45386
|
cache: new import_utils5.InMemoryLRUCache(),
|
|
44825
45387
|
schema: schema7,
|
|
44826
|
-
introspection: true
|
|
45388
|
+
introspection: true,
|
|
45389
|
+
plugins: [
|
|
45390
|
+
companionOperationGuard(
|
|
45391
|
+
companionAllowedOperations((contexts ?? []).map(convertContextToTableDefinition))
|
|
45392
|
+
)
|
|
45393
|
+
]
|
|
44827
45394
|
});
|
|
44828
45395
|
await server.start();
|
|
44829
45396
|
app.use(
|
|
@@ -44842,7 +45409,10 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
44842
45409
|
return {
|
|
44843
45410
|
req,
|
|
44844
45411
|
db: db2,
|
|
44845
|
-
user:
|
|
45412
|
+
user: admitCompanionUser(
|
|
45413
|
+
companionRequestState(req.headers),
|
|
45414
|
+
authenticationResult.user
|
|
45415
|
+
)
|
|
44846
45416
|
};
|
|
44847
45417
|
}
|
|
44848
45418
|
})
|
|
@@ -44977,7 +45547,7 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
44977
45547
|
inputs: payload
|
|
44978
45548
|
};
|
|
44979
45549
|
await queue.queue.add("email-intake", jobData, {
|
|
44980
|
-
jobId: (0,
|
|
45550
|
+
jobId: (0, import_node_crypto26.randomUUID)(),
|
|
44981
45551
|
attempts: 3,
|
|
44982
45552
|
removeOnComplete: 5e3,
|
|
44983
45553
|
removeOnFail: 1e4,
|
|
@@ -45385,7 +45955,7 @@ ${customInstructions}` : agent.instructions,
|
|
|
45385
45955
|
contextId: agent.memory,
|
|
45386
45956
|
agentId: agent.id,
|
|
45387
45957
|
session: headers.session ?? null,
|
|
45388
|
-
messageId: responseMessage?.id ?? messages[messages.length - 1]?.id ?? (0,
|
|
45958
|
+
messageId: responseMessage?.id ?? messages[messages.length - 1]?.id ?? (0, import_node_crypto26.randomUUID)(),
|
|
45389
45959
|
userId: user?.id ?? null
|
|
45390
45960
|
});
|
|
45391
45961
|
}
|
|
@@ -46078,7 +46648,7 @@ ${outputSchemaInstructions(outputSchema)}` : baseInstructions;
|
|
|
46078
46648
|
const keys = [];
|
|
46079
46649
|
const revisedPrompts = [];
|
|
46080
46650
|
for (const img of images) {
|
|
46081
|
-
const filename = `${(0,
|
|
46651
|
+
const filename = `${(0, import_node_crypto26.randomUUID)()}.${img.extension}`;
|
|
46082
46652
|
const key = `sessions/${sessionId}/images/${toolCallId}/${filename}`;
|
|
46083
46653
|
const fullKey = await uploadFile(
|
|
46084
46654
|
img.buffer,
|
|
@@ -46366,7 +46936,7 @@ ${style.markdown}` : params.prompt;
|
|
|
46366
46936
|
(d) => `- ${d.presignedUrl} (prompt: "${d.prompt}", model: ${d.model}${d.styleName ? `, style: ${d.styleName}` : ""})`
|
|
46367
46937
|
);
|
|
46368
46938
|
const messageText2 = "The user generated and selected the following image(s) in this chat:\n" + lines.join("\n");
|
|
46369
|
-
const messageId = (0,
|
|
46939
|
+
const messageId = (0, import_node_crypto26.randomUUID)();
|
|
46370
46940
|
const uiMessage = {
|
|
46371
46941
|
id: messageId,
|
|
46372
46942
|
role: "system",
|
|
@@ -47463,7 +48033,7 @@ ${style.markdown}` : params.prompt;
|
|
|
47463
48033
|
return;
|
|
47464
48034
|
}
|
|
47465
48035
|
const meta = await parseSkillFrontmatter(bytes);
|
|
47466
|
-
const skillId = (0,
|
|
48036
|
+
const skillId = (0, import_node_crypto26.randomUUID)();
|
|
47467
48037
|
try {
|
|
47468
48038
|
await extractBundleToVersion({ bytes, skillId, version: 1, config });
|
|
47469
48039
|
} catch (err4) {
|
|
@@ -47586,7 +48156,7 @@ ${style.markdown}` : params.prompt;
|
|
|
47586
48156
|
return;
|
|
47587
48157
|
}
|
|
47588
48158
|
if (!await ensureSkillWrite(db2, skill, authResult.user, res)) return;
|
|
47589
|
-
const stagingKey = `user_${authResult.user.id}/skills/_staging/${(0,
|
|
48159
|
+
const stagingKey = `user_${authResult.user.id}/skills/_staging/${(0, import_node_crypto26.randomUUID)()}${extension}`;
|
|
47590
48160
|
const fullKey = config.fileUploads?.s3prefix ? `${config.fileUploads.s3prefix.replace(/\/$/, "")}/${stagingKey}` : stagingKey;
|
|
47591
48161
|
const uploadUrl = await getS3SignedUploadUrl(fullKey, contentType, config);
|
|
47592
48162
|
res.json({ uploadUrl, stagingKey });
|
|
@@ -48055,6 +48625,14 @@ ${style.markdown}` : params.prompt;
|
|
|
48055
48625
|
const loadSessionFilesAuth = async (req, res, sessionId, rights) => {
|
|
48056
48626
|
const authed = await loadAuthedSession(req, res, sessionId, rights);
|
|
48057
48627
|
if (!authed) return null;
|
|
48628
|
+
if (isExternalUser(authed.user)) {
|
|
48629
|
+
const agentId = authed.session?.agent;
|
|
48630
|
+
const agentRow = agentId ? await authed.db.from("agents").where({ id: agentId }).select("guest_access", "guest_auth_mode", "sandbox_enabled", "active").first() : null;
|
|
48631
|
+
if (!agentAllowsGuestFiles(agentRow)) {
|
|
48632
|
+
res.status(403).json({ detail: "Files are not available for this conversation." });
|
|
48633
|
+
return null;
|
|
48634
|
+
}
|
|
48635
|
+
}
|
|
48058
48636
|
const ownerId = authed.session.user ?? authed.user.id;
|
|
48059
48637
|
return { ...authed, ownerId, ...buildSessionPrefixes(ownerId, sessionId) };
|
|
48060
48638
|
};
|
|
@@ -48143,6 +48721,15 @@ ${style.markdown}` : params.prompt;
|
|
|
48143
48721
|
res.status(400).json({ detail: "Missing contentType in request body." });
|
|
48144
48722
|
return;
|
|
48145
48723
|
}
|
|
48724
|
+
if (isExternalUser(authed.user)) {
|
|
48725
|
+
const refusal = guestUploadRefusal(
|
|
48726
|
+
await listS3ObjectsByPrefix(authed.userSessionPrefix, config)
|
|
48727
|
+
);
|
|
48728
|
+
if (refusal) {
|
|
48729
|
+
res.status(413).json({ detail: refusal });
|
|
48730
|
+
return;
|
|
48731
|
+
}
|
|
48732
|
+
}
|
|
48146
48733
|
const fullKey = `${authed.fullSessionPrefix}${safeName}`;
|
|
48147
48734
|
const uploadUrl = await getS3SignedUploadUrl(fullKey, contentType, config);
|
|
48148
48735
|
res.json({ uploadUrl, key: fullKey });
|
|
@@ -48167,6 +48754,16 @@ ${style.markdown}` : params.prompt;
|
|
|
48167
48754
|
res.status(403).json({ detail: "Key does not belong to this session." });
|
|
48168
48755
|
return;
|
|
48169
48756
|
}
|
|
48757
|
+
if (isExternalUser(authed.user)) {
|
|
48758
|
+
const uploaded = (await listS3ObjectsByPrefix(authed.userSessionPrefix, config)).find(
|
|
48759
|
+
(object) => object.key === key
|
|
48760
|
+
);
|
|
48761
|
+
if (guestFileTooLarge(uploaded?.size)) {
|
|
48762
|
+
await deleteS3Object(key, config);
|
|
48763
|
+
res.status(413).json({ detail: "This file is too large." });
|
|
48764
|
+
return;
|
|
48765
|
+
}
|
|
48766
|
+
}
|
|
48170
48767
|
try {
|
|
48171
48768
|
const result = await downloadKeyIntoSandbox({
|
|
48172
48769
|
sessionId,
|
|
@@ -48562,6 +49159,7 @@ ${style.markdown}` : params.prompt;
|
|
|
48562
49159
|
// Coerced, not `?? []`: see readAgentSlots on why a stored non-array is
|
|
48563
49160
|
// a real possibility and why a reader has to survive one.
|
|
48564
49161
|
agent_slots: readAgentSlots(row.agent_slots),
|
|
49162
|
+
external_access: row.external_access === true,
|
|
48565
49163
|
...detailsOf(row),
|
|
48566
49164
|
// Older files, newest first; at most MAX_OLDER_VERSIONS (artifact-library.ts).
|
|
48567
49165
|
versions: versions.map((v) => ({
|
|
@@ -48601,6 +49199,28 @@ ${style.markdown}` : params.prompt;
|
|
|
48601
49199
|
res.status(400).json({ detail: valid.message });
|
|
48602
49200
|
return;
|
|
48603
49201
|
}
|
|
49202
|
+
if (!mayChangeExternalRelease(auth.user, input.external_access, row.external_access)) {
|
|
49203
|
+
res.status(403).json({ detail: EXTERNAL_SUPER_ADMIN_ONLY });
|
|
49204
|
+
return;
|
|
49205
|
+
}
|
|
49206
|
+
if (externalAccessCheckApplies(input, row)) {
|
|
49207
|
+
let teams = [];
|
|
49208
|
+
if (externalAccessNeedsTeams(input, row)) {
|
|
49209
|
+
let teamIds;
|
|
49210
|
+
if (input.rbac && typeof input.rbac === "object") {
|
|
49211
|
+
teamIds = Array.isArray(input.rbac.teams) ? input.rbac.teams.map((t) => t?.id) : [];
|
|
49212
|
+
} else {
|
|
49213
|
+
const stored = await db2("rbac").where({ entity: "shared_artifact", target_resource_id: row.id, access_type: "Team" }).select("team_id");
|
|
49214
|
+
teamIds = stored.map((r) => r.team_id);
|
|
49215
|
+
}
|
|
49216
|
+
teams = await teamNamesByIds(db2, teamIds);
|
|
49217
|
+
}
|
|
49218
|
+
const externalError = validateExternalAccessUpdate(input, row, teams);
|
|
49219
|
+
if (externalError) {
|
|
49220
|
+
res.status(400).json({ detail: externalError });
|
|
49221
|
+
return;
|
|
49222
|
+
}
|
|
49223
|
+
}
|
|
48604
49224
|
const details = planDetails(input, now);
|
|
48605
49225
|
if (!details.ok) {
|
|
48606
49226
|
res.status(400).json({ detail: details.message });
|
|
@@ -48645,6 +49265,7 @@ ${style.markdown}` : params.prompt;
|
|
|
48645
49265
|
expires_at: updated.expires_at ?? null,
|
|
48646
49266
|
rights_mode: updated.rights_mode ?? null,
|
|
48647
49267
|
agent_slots: readAgentSlots(updated.agent_slots),
|
|
49268
|
+
external_access: updated.external_access === true,
|
|
48648
49269
|
...detailsOf(updated),
|
|
48649
49270
|
version_count: readVersions(updated.versions).length
|
|
48650
49271
|
});
|
|
@@ -48714,6 +49335,13 @@ ${style.markdown}` : params.prompt;
|
|
|
48714
49335
|
RBACResolver,
|
|
48715
49336
|
checkRecordAccess
|
|
48716
49337
|
});
|
|
49338
|
+
registerExternalShareRoute(app, {
|
|
49339
|
+
getDb: async () => (await postgresClient()).db
|
|
49340
|
+
});
|
|
49341
|
+
registerCompanionStatusRoutes(app, {
|
|
49342
|
+
authenticate: (req) => requestValidators.authenticate(req),
|
|
49343
|
+
getDb: async () => (await postgresClient()).db
|
|
49344
|
+
});
|
|
48717
49345
|
registerToolApiRoutes(app, {
|
|
48718
49346
|
authenticate: (req) => requestValidators.authenticate(req),
|
|
48719
49347
|
tools,
|
|
@@ -48894,7 +49522,9 @@ ${style.markdown}` : params.prompt;
|
|
|
48894
49522
|
// Presence only — publicAgentView turns these into booleans and the
|
|
48895
49523
|
// bytes are served by /public-agents/:id/animation/:kind.
|
|
48896
49524
|
"animation_idle",
|
|
48897
|
-
"animation_responding"
|
|
49525
|
+
"animation_responding",
|
|
49526
|
+
// Presence of the guest files feature, never the sandbox itself.
|
|
49527
|
+
"sandbox_enabled"
|
|
48898
49528
|
);
|
|
48899
49529
|
const views = await Promise.all(
|
|
48900
49530
|
rows.map(
|
|
@@ -49059,7 +49689,7 @@ function buildUnifiedDiff(fromLines, toLines, fromLabel, toLabel) {
|
|
|
49059
49689
|
// src/mcp/index.ts
|
|
49060
49690
|
init_cjs_shims();
|
|
49061
49691
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
49062
|
-
var
|
|
49692
|
+
var import_node_crypto27 = require("crypto");
|
|
49063
49693
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
49064
49694
|
var import_types14 = require("@modelcontextprotocol/sdk/types.js");
|
|
49065
49695
|
init_sanitize_tool_name();
|
|
@@ -49160,7 +49790,7 @@ var ExuluMCP = class {
|
|
|
49160
49790
|
throw new Error("Tool not found in converted tools array.");
|
|
49161
49791
|
}
|
|
49162
49792
|
const iterator = await convertedTool.execute(inputs, {
|
|
49163
|
-
toolCallId: tool5.id + "_" + (0,
|
|
49793
|
+
toolCallId: tool5.id + "_" + (0, import_node_crypto27.randomUUID)(),
|
|
49164
49794
|
messages: []
|
|
49165
49795
|
});
|
|
49166
49796
|
let result;
|
|
@@ -49350,7 +49980,7 @@ var ExuluMCP = class {
|
|
|
49350
49980
|
transport = this.transports[sessionId];
|
|
49351
49981
|
} else if (!sessionId && (0, import_types14.isInitializeRequest)(req.body)) {
|
|
49352
49982
|
transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
49353
|
-
sessionIdGenerator: () => (0,
|
|
49983
|
+
sessionIdGenerator: () => (0, import_node_crypto27.randomUUID)(),
|
|
49354
49984
|
onsessioninitialized: (sessionId2) => {
|
|
49355
49985
|
this.transports[sessionId2] = transport;
|
|
49356
49986
|
}
|
|
@@ -49956,7 +50586,7 @@ var import_zod39 = __toESM(require("zod"), 1);
|
|
|
49956
50586
|
init_tool2();
|
|
49957
50587
|
init_check_record_access();
|
|
49958
50588
|
init_client();
|
|
49959
|
-
var
|
|
50589
|
+
var import_node_crypto28 = require("crypto");
|
|
49960
50590
|
var AnswerOptionSchema = import_zod39.default.object({
|
|
49961
50591
|
id: import_zod39.default.string().describe("Unique identifier for the answer option"),
|
|
49962
50592
|
text: import_zod39.default.string().describe("The text of the answer option")
|
|
@@ -50010,15 +50640,15 @@ var QuestionAskTool = new ExuluTool({
|
|
|
50010
50640
|
throw new Error("You don't have access to this session " + session.id + ".");
|
|
50011
50641
|
}
|
|
50012
50642
|
const answerOptionsWithIds = answerOptions.map((text) => ({
|
|
50013
|
-
id: (0,
|
|
50643
|
+
id: (0, import_node_crypto28.randomUUID)(),
|
|
50014
50644
|
text
|
|
50015
50645
|
}));
|
|
50016
50646
|
answerOptionsWithIds.push({
|
|
50017
|
-
id: (0,
|
|
50647
|
+
id: (0, import_node_crypto28.randomUUID)(),
|
|
50018
50648
|
text: "None of the above..."
|
|
50019
50649
|
});
|
|
50020
50650
|
const newQuestion = {
|
|
50021
|
-
id: (0,
|
|
50651
|
+
id: (0, import_node_crypto28.randomUUID)(),
|
|
50022
50652
|
question,
|
|
50023
50653
|
answerOptions: answerOptionsWithIds,
|
|
50024
50654
|
status: "pending"
|