@exulu/backend 5.22.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-6OAYOFEY.js → chunk-K7CGLUW4.js} +141 -130
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-DAC4VCWO.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 +623 -191
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +373 -84
- 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);
|
|
@@ -17347,16 +17438,16 @@ var init_routine_status_tool = __esm({
|
|
|
17347
17438
|
});
|
|
17348
17439
|
|
|
17349
17440
|
// src/templates/tools/tool-upload.ts
|
|
17350
|
-
var import_client_s33,
|
|
17441
|
+
var import_client_s33, import_node_crypto10, generateS3Key, s3Client2, buildToolUpload;
|
|
17351
17442
|
var init_tool_upload = __esm({
|
|
17352
17443
|
"src/templates/tools/tool-upload.ts"() {
|
|
17353
17444
|
"use strict";
|
|
17354
17445
|
init_cjs_shims();
|
|
17355
17446
|
import_client_s33 = require("@aws-sdk/client-s3");
|
|
17356
|
-
|
|
17447
|
+
import_node_crypto10 = require("crypto");
|
|
17357
17448
|
init_session_file_write();
|
|
17358
17449
|
init_uppy();
|
|
17359
|
-
generateS3Key = (filename) => `${(0,
|
|
17450
|
+
generateS3Key = (filename) => `${(0, import_node_crypto10.randomUUID)()}-${filename}`;
|
|
17360
17451
|
buildToolUpload = (exuluConfig, user) => {
|
|
17361
17452
|
const uploads = exuluConfig?.fileUploads;
|
|
17362
17453
|
if (!uploads?.s3endpoint || !uploads?.s3key || !uploads?.s3secret || !uploads?.s3Bucket) {
|
|
@@ -17538,19 +17629,19 @@ var init_context_budget = __esm({
|
|
|
17538
17629
|
});
|
|
17539
17630
|
|
|
17540
17631
|
// src/exulu/tool-output-offload.ts
|
|
17541
|
-
var
|
|
17632
|
+
var import_node_crypto11, PREVIEW_CHARS, storeAsSessionFile, buildNotice, guardToolOutput, guardExtractedFileText;
|
|
17542
17633
|
var init_tool_output_offload = __esm({
|
|
17543
17634
|
"src/exulu/tool-output-offload.ts"() {
|
|
17544
17635
|
"use strict";
|
|
17545
17636
|
init_cjs_shims();
|
|
17546
|
-
|
|
17637
|
+
import_node_crypto11 = require("crypto");
|
|
17547
17638
|
init_uppy();
|
|
17548
17639
|
init_context_budget();
|
|
17549
17640
|
PREVIEW_CHARS = 4e3;
|
|
17550
17641
|
storeAsSessionFile = async (serialized, ctx) => {
|
|
17551
17642
|
if (!ctx.sessionID || !ctx.exuluConfig?.fileUploads) return void 0;
|
|
17552
17643
|
const safeTool = ctx.toolName.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 40);
|
|
17553
|
-
const name = `tool-output-${safeTool}-${(0,
|
|
17644
|
+
const name = `tool-output-${safeTool}-${(0, import_node_crypto11.randomUUID)().slice(0, 8)}.txt`;
|
|
17554
17645
|
try {
|
|
17555
17646
|
await uploadFile(
|
|
17556
17647
|
Buffer.from(serialized, "utf-8"),
|
|
@@ -17800,6 +17891,33 @@ async function convertLegacyOfficeToModern(bytes, ext) {
|
|
|
17800
17891
|
await (0, import_promises6.rm)(dir, { recursive: true, force: true });
|
|
17801
17892
|
}
|
|
17802
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
|
+
}
|
|
17803
17921
|
async function pdfToText(pdf) {
|
|
17804
17922
|
const dir = await (0, import_promises6.mkdtemp)((0, import_node_path11.join)((0, import_node_os2.tmpdir)(), "exulu-parse-"));
|
|
17805
17923
|
try {
|
|
@@ -17849,7 +17967,7 @@ async function renderPdfPageToPng(pdf, page, scaleTo) {
|
|
|
17849
17967
|
await (0, import_promises6.rm)(dir, { recursive: true, force: true });
|
|
17850
17968
|
}
|
|
17851
17969
|
}
|
|
17852
|
-
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;
|
|
17853
17971
|
var init_document_render_helpers = __esm({
|
|
17854
17972
|
"src/templates/tools/document-render-helpers.ts"() {
|
|
17855
17973
|
"use strict";
|
|
@@ -17868,6 +17986,7 @@ var init_document_render_helpers = __esm({
|
|
|
17868
17986
|
".ppt": "pptx",
|
|
17869
17987
|
".rtf": "docx"
|
|
17870
17988
|
};
|
|
17989
|
+
PRESENTATION_EXTENSIONS = /* @__PURE__ */ new Set([".pptx", ".ppt", ".pptm", ".odp"]);
|
|
17871
17990
|
}
|
|
17872
17991
|
});
|
|
17873
17992
|
|
|
@@ -18622,6 +18741,19 @@ async function processDocument(filePath, fileType, buffer, tempDir, config, verb
|
|
|
18622
18741
|
case "webp":
|
|
18623
18742
|
result = await processImage(buffer, paths, config, verbose, tolerateVisionFailures, onProgress, limiters);
|
|
18624
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
|
+
}
|
|
18625
18757
|
// Todo other file types with docx and officeparser
|
|
18626
18758
|
default:
|
|
18627
18759
|
throw new Error(`[EXULU] Unsupported file type: ${fileType}`);
|
|
@@ -18835,13 +18967,13 @@ async function documentProcessor({
|
|
|
18835
18967
|
let supportedTypes = [];
|
|
18836
18968
|
switch (config?.processor.name) {
|
|
18837
18969
|
case "officeparser":
|
|
18838
|
-
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"];
|
|
18839
18971
|
break;
|
|
18840
18972
|
case "liteparse":
|
|
18841
18973
|
supportedTypes = ["pdf", "doc", "docx", "docm", "odt", "rtf", "ppt", "pptx", "pptm", "odp", "xls", "xlsx", "xlsm", "ods", "csv", "tsv"];
|
|
18842
18974
|
break;
|
|
18843
18975
|
case "mistral":
|
|
18844
|
-
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"];
|
|
18845
18977
|
break;
|
|
18846
18978
|
}
|
|
18847
18979
|
if (!supportedTypes.includes(fileType.toLowerCase())) {
|
|
@@ -18898,6 +19030,7 @@ var init_doc_processor = __esm({
|
|
|
18898
19030
|
init_resolve_ocr();
|
|
18899
19031
|
init_resolve_model();
|
|
18900
19032
|
init_limits();
|
|
19033
|
+
init_document_render_helpers();
|
|
18901
19034
|
loadFile = async (file, name, tempDir) => {
|
|
18902
19035
|
let filePath = file;
|
|
18903
19036
|
let fileType = name?.split(".").pop();
|
|
@@ -18962,7 +19095,17 @@ function degradedPagesOf(result) {
|
|
|
18962
19095
|
}
|
|
18963
19096
|
async function extractDocument(input) {
|
|
18964
19097
|
const config = input.exuluConfig?.attachments?.documentProcessor;
|
|
19098
|
+
const original = input;
|
|
18965
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
|
+
}
|
|
18966
19109
|
if (input.filename.toLowerCase().endsWith(".pdf")) {
|
|
18967
19110
|
const forTool = input.maxPages !== void 0;
|
|
18968
19111
|
const maxPages = input.maxPages ?? attachmentMaxPages();
|
|
@@ -18976,7 +19119,7 @@ async function extractDocument(input) {
|
|
|
18976
19119
|
console.warn(`[EXULU] ${input.filename} has ${pageCount} pages, over the ${forTool ? "document" : "attachment"} cap of ${maxPages}; not read.`);
|
|
18977
19120
|
return {
|
|
18978
19121
|
pages: [],
|
|
18979
|
-
text: (forTool ? tooLongForToolNotice : tooLongNotice)(
|
|
19122
|
+
text: (forTool ? tooLongForToolNotice : tooLongNotice)(original.filename, pageCount, maxPages),
|
|
18980
19123
|
engine: "document-processor",
|
|
18981
19124
|
tooLong: { pageCount, maxPages }
|
|
18982
19125
|
};
|
|
@@ -19012,7 +19155,7 @@ async function extractDocument(input) {
|
|
|
19012
19155
|
);
|
|
19013
19156
|
}
|
|
19014
19157
|
}
|
|
19015
|
-
const text = (await (input.officeParse ?? defaultOfficeParse)(
|
|
19158
|
+
const text = (await (input.officeParse ?? defaultOfficeParse)(original.bytes)).trim();
|
|
19016
19159
|
return { pages: [{ page: 1, text }], text, engine: "officeparser" };
|
|
19017
19160
|
}
|
|
19018
19161
|
function validateAttachmentsConfig(config, license) {
|
|
@@ -20595,7 +20738,7 @@ var init_convert_exulu_tools_to_ai_sdk_tools = __esm({
|
|
|
20595
20738
|
});
|
|
20596
20739
|
|
|
20597
20740
|
// src/exulu/tool.ts
|
|
20598
|
-
var import_ai4, import_zod19,
|
|
20741
|
+
var import_ai4, import_zod19, import_node_crypto12, PUBLIC_TOOL_TYPES, ExuluTool;
|
|
20599
20742
|
var init_tool2 = __esm({
|
|
20600
20743
|
"src/exulu/tool.ts"() {
|
|
20601
20744
|
"use strict";
|
|
@@ -20603,7 +20746,7 @@ var init_tool2 = __esm({
|
|
|
20603
20746
|
import_ai4 = require("ai");
|
|
20604
20747
|
import_zod19 = require("zod");
|
|
20605
20748
|
init_sanitize_name();
|
|
20606
|
-
|
|
20749
|
+
import_node_crypto12 = require("crypto");
|
|
20607
20750
|
init_singleton();
|
|
20608
20751
|
init_resolve_model();
|
|
20609
20752
|
init_validate();
|
|
@@ -20748,7 +20891,7 @@ var init_tool2 = __esm({
|
|
|
20748
20891
|
throw new Error("Tool " + sanitizeName(this.name) + " not found in " + JSON.stringify(tools));
|
|
20749
20892
|
}
|
|
20750
20893
|
console.log("[EXULU] Tool found", this.name);
|
|
20751
|
-
const toolCallId = this.id + "_" + (0,
|
|
20894
|
+
const toolCallId = this.id + "_" + (0, import_node_crypto12.randomUUID)();
|
|
20752
20895
|
console.log("[EXULU] Calling tool execute", {
|
|
20753
20896
|
inputs,
|
|
20754
20897
|
toolCallId,
|
|
@@ -23778,6 +23921,153 @@ var import_express6 = require("express");
|
|
|
23778
23921
|
|
|
23779
23922
|
// src/exulu/routes.ts
|
|
23780
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
|
|
23781
24071
|
var import_express2 = require("express");
|
|
23782
24072
|
|
|
23783
24073
|
// src/exulu/channels/lifecycle.ts
|
|
@@ -24402,8 +24692,8 @@ init_skill_author_tools();
|
|
|
24402
24692
|
|
|
24403
24693
|
// src/graphql/types/index.ts
|
|
24404
24694
|
init_cjs_shims();
|
|
24405
|
-
var
|
|
24406
|
-
var GraphQLDate = new
|
|
24695
|
+
var import_graphql3 = require("graphql");
|
|
24696
|
+
var GraphQLDate = new import_graphql3.GraphQLScalarType({
|
|
24407
24697
|
name: "Date",
|
|
24408
24698
|
description: "Date custom scalar type",
|
|
24409
24699
|
serialize(value) {
|
|
@@ -24428,10 +24718,10 @@ var GraphQLDate = new import_graphql.GraphQLScalarType({
|
|
|
24428
24718
|
return value;
|
|
24429
24719
|
},
|
|
24430
24720
|
parseLiteral(ast) {
|
|
24431
|
-
if (ast.kind ===
|
|
24721
|
+
if (ast.kind === import_graphql3.Kind.STRING) {
|
|
24432
24722
|
return new Date(ast.value);
|
|
24433
24723
|
}
|
|
24434
|
-
if (ast.kind ===
|
|
24724
|
+
if (ast.kind === import_graphql3.Kind.INT) {
|
|
24435
24725
|
return new Date(parseInt(ast.value, 10));
|
|
24436
24726
|
}
|
|
24437
24727
|
return null;
|
|
@@ -24509,6 +24799,14 @@ var contextItemsProcessorHandler = async (context, config, items, user, role) =>
|
|
|
24509
24799
|
init_access_control();
|
|
24510
24800
|
init_rbac_resolver();
|
|
24511
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
|
+
|
|
24512
24810
|
// src/graphql/resolvers/index.ts
|
|
24513
24811
|
init_cjs_shims();
|
|
24514
24812
|
|
|
@@ -25863,7 +26161,7 @@ function registerImportQueue() {
|
|
|
25863
26161
|
|
|
25864
26162
|
// src/exulu/import/start-import.ts
|
|
25865
26163
|
init_cjs_shims();
|
|
25866
|
-
var
|
|
26164
|
+
var import_node_crypto13 = require("crypto");
|
|
25867
26165
|
|
|
25868
26166
|
// src/utils/serialize-error.ts
|
|
25869
26167
|
init_cjs_shims();
|
|
@@ -26050,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;
|
|
|
26050
26348
|
function isUuid(value) {
|
|
26051
26349
|
return UUID_RE.test(value);
|
|
26052
26350
|
}
|
|
26053
|
-
function
|
|
26351
|
+
function idOf3(value) {
|
|
26054
26352
|
if (typeof value === "string") return value;
|
|
26055
26353
|
if (value != null && typeof value === "object" && "id" in value) {
|
|
26056
26354
|
const id = value.id;
|
|
@@ -26071,14 +26369,14 @@ function canWrite(existing, user) {
|
|
|
26071
26369
|
);
|
|
26072
26370
|
}
|
|
26073
26371
|
if (existing.rights_mode === "roles") {
|
|
26074
|
-
const roleId =
|
|
26372
|
+
const roleId = idOf3(user.role);
|
|
26075
26373
|
if (!roleId) return false;
|
|
26076
26374
|
return grantsOf(existing).some(
|
|
26077
26375
|
(g) => g.access_type === "Role" && String(g.role_id) === roleId && g.rights === "write"
|
|
26078
26376
|
);
|
|
26079
26377
|
}
|
|
26080
26378
|
if (existing.rights_mode === "teams") {
|
|
26081
|
-
const teamId =
|
|
26379
|
+
const teamId = idOf3(user.team);
|
|
26082
26380
|
if (!teamId) return false;
|
|
26083
26381
|
return grantsOf(existing).some(
|
|
26084
26382
|
(g) => g.access_type === "Team" && String(g.team_id) === teamId && g.rights === "write"
|
|
@@ -26154,7 +26452,7 @@ async function uploadErrorReport(csv, contextId, jobResultId, config, user) {
|
|
|
26154
26452
|
function buildWorkerDeps(input) {
|
|
26155
26453
|
const { db: db2, config, context, contextId, jobResultId, stream, fields, mapping, access, options, user, log: log7 } = input;
|
|
26156
26454
|
const tableName = getTableName(contextId);
|
|
26157
|
-
const roleId =
|
|
26455
|
+
const roleId = idOf3(user.role);
|
|
26158
26456
|
const generateEmbeddingsOverwrite = options.skipEmbeddings ? false : void 0;
|
|
26159
26457
|
const rbac = rbacGrantsFor(access);
|
|
26160
26458
|
const total = typeof input.total === "number" && input.total > 0 ? input.total : void 0;
|
|
@@ -26241,7 +26539,7 @@ async function startImport(deps, args) {
|
|
|
26241
26539
|
if (running) {
|
|
26242
26540
|
throw new StartImportError("IMPORT_ALREADY_RUNNING");
|
|
26243
26541
|
}
|
|
26244
|
-
const id = (uuid ??
|
|
26542
|
+
const id = (uuid ?? import_node_crypto13.randomUUID)();
|
|
26245
26543
|
const label = `Import ${args.fileName}`;
|
|
26246
26544
|
const userSnapshot = {
|
|
26247
26545
|
id: user.id,
|
|
@@ -27622,6 +27920,7 @@ var markSessionSeenForViewer = async ({
|
|
|
27622
27920
|
|
|
27623
27921
|
// src/graphql/mutations/index.ts
|
|
27624
27922
|
init_skill_access();
|
|
27923
|
+
init_write_grant();
|
|
27625
27924
|
var VALID_RIGHTS_MODES3 = ["private", "users", "roles", "teams", "public"];
|
|
27626
27925
|
var postprocessDeletion = async ({
|
|
27627
27926
|
table,
|
|
@@ -27807,6 +28106,12 @@ function createMutations(table, contexts, tools, config) {
|
|
|
27807
28106
|
const validateWriteAccess = async (id, context) => {
|
|
27808
28107
|
try {
|
|
27809
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
|
+
}
|
|
27810
28115
|
if (user.super_admin === true) {
|
|
27811
28116
|
return true;
|
|
27812
28117
|
}
|
|
@@ -28157,6 +28462,14 @@ function createMutations(table, contexts, tools, config) {
|
|
|
28157
28462
|
[`${tableNamePlural}UpdateOneById`]: async (_, args, context, info) => {
|
|
28158
28463
|
const { db: db2, req } = context;
|
|
28159
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
|
+
}
|
|
28160
28473
|
await validateCreateOrRemoveSuperAdminPermission(tableNamePlural, input, req);
|
|
28161
28474
|
await validateWriteAccess(id, context);
|
|
28162
28475
|
if (table.type === "items") {
|
|
@@ -29807,7 +30120,7 @@ async function recordMemoryUsage(input) {
|
|
|
29807
30120
|
}
|
|
29808
30121
|
|
|
29809
30122
|
// src/exulu/generate-stream.ts
|
|
29810
|
-
var
|
|
30123
|
+
var import_node_crypto14 = require("crypto");
|
|
29811
30124
|
var processFilePartsInMessages = async (messages, offloadCtx) => {
|
|
29812
30125
|
const processedMessages = await Promise.all(
|
|
29813
30126
|
messages.map(async (message) => {
|
|
@@ -30238,7 +30551,7 @@ When a tool execution is not approved by the user, do not retry it unless explic
|
|
|
30238
30551
|
contextId: agent.memory,
|
|
30239
30552
|
agentId: agent.id,
|
|
30240
30553
|
session: session ?? null,
|
|
30241
|
-
messageId: output.response?.id ?? (0,
|
|
30554
|
+
messageId: output.response?.id ?? (0, import_node_crypto14.randomUUID)(),
|
|
30242
30555
|
userId: user?.id ?? null
|
|
30243
30556
|
});
|
|
30244
30557
|
}
|
|
@@ -30314,7 +30627,7 @@ When a tool execution is not approved by the user, do not retry it unless explic
|
|
|
30314
30627
|
contextId: agent.memory,
|
|
30315
30628
|
agentId: agent.id,
|
|
30316
30629
|
session: session ?? null,
|
|
30317
|
-
messageId: response?.id ?? (0,
|
|
30630
|
+
messageId: response?.id ?? (0, import_node_crypto14.randomUUID)(),
|
|
30318
30631
|
userId: user?.id ?? null
|
|
30319
30632
|
});
|
|
30320
30633
|
}
|
|
@@ -30884,7 +31197,7 @@ init_singleton();
|
|
|
30884
31197
|
|
|
30885
31198
|
// src/exulu/email-inbound/intake.ts
|
|
30886
31199
|
init_cjs_shims();
|
|
30887
|
-
var
|
|
31200
|
+
var import_node_crypto17 = require("crypto");
|
|
30888
31201
|
init_client();
|
|
30889
31202
|
init_uppy();
|
|
30890
31203
|
init_singleton();
|
|
@@ -30892,7 +31205,7 @@ init_run_session();
|
|
|
30892
31205
|
|
|
30893
31206
|
// src/exulu/email-inbound/normalize.ts
|
|
30894
31207
|
init_cjs_shims();
|
|
30895
|
-
var
|
|
31208
|
+
var import_node_crypto15 = require("crypto");
|
|
30896
31209
|
var import_mailparser = require("mailparser");
|
|
30897
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();
|
|
30898
31211
|
var headerValueToString = (value) => {
|
|
@@ -30933,7 +31246,7 @@ async function parseRawMime(raw) {
|
|
|
30933
31246
|
return {
|
|
30934
31247
|
// Message-ID is the dedup key (spec §4.4.5). A missing header gets a
|
|
30935
31248
|
// deterministic content hash so webhook/job retries still dedup.
|
|
30936
|
-
messageId: parsed.messageId ?? `generated-${(0,
|
|
31249
|
+
messageId: parsed.messageId ?? `generated-${(0, import_node_crypto15.createHash)("sha256").update(raw).digest("hex")}`,
|
|
30937
31250
|
from: {
|
|
30938
31251
|
address: fromEntry.address.toLowerCase(),
|
|
30939
31252
|
...fromEntry.name ? { name: fromEntry.name } : {}
|
|
@@ -30953,7 +31266,7 @@ async function parseRawMime(raw) {
|
|
|
30953
31266
|
|
|
30954
31267
|
// src/exulu/email-inbound/adapters.ts
|
|
30955
31268
|
init_cjs_shims();
|
|
30956
|
-
var
|
|
31269
|
+
var import_node_crypto16 = require("crypto");
|
|
30957
31270
|
var import_node_stream = require("stream");
|
|
30958
31271
|
var import_busboy = __toESM(require("busboy"), 1);
|
|
30959
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();
|
|
@@ -31018,7 +31331,7 @@ function jsonToInboundEmail(raw) {
|
|
|
31018
31331
|
const subject = typeof obj.subject === "string" ? obj.subject : "";
|
|
31019
31332
|
const html = typeof obj.html === "string" ? obj.html : void 0;
|
|
31020
31333
|
const text = typeof obj.text === "string" && obj.text ? obj.text : html ? htmlToText2(html) : "";
|
|
31021
|
-
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>`;
|
|
31022
31335
|
const looksLikeAttachment = (a) => !!a && typeof a === "object" && !Array.isArray(a) && (typeof a.content_base64 === "string" || typeof a.filename === "string");
|
|
31023
31336
|
let rawAttachments;
|
|
31024
31337
|
if (obj.attachments === void 0 || obj.attachments === null) rawAttachments = [];
|
|
@@ -31067,7 +31380,7 @@ var DEFAULT_SENDER_RATE_LIMIT_PER_HOUR = 10;
|
|
|
31067
31380
|
var DEFAULT_FILTERED_RUN_RETENTION = 200;
|
|
31068
31381
|
var FILTER_BODY_BYTE_CAP = 10 * 1024;
|
|
31069
31382
|
var AUTO_REPLY_PRECEDENCE = /* @__PURE__ */ new Set(["bulk", "junk", "list"]);
|
|
31070
|
-
var
|
|
31383
|
+
var HOUR_MS2 = 60 * 60 * 1e3;
|
|
31071
31384
|
var isAutoReply = (email) => {
|
|
31072
31385
|
const autoSubmitted = email.headers.get("auto-submitted");
|
|
31073
31386
|
if (autoSubmitted !== void 0 && autoSubmitted.trim().toLowerCase() !== "no") {
|
|
@@ -31099,7 +31412,7 @@ var senderAllowed = (address, allowedSenders) => {
|
|
|
31099
31412
|
var checkRateLimit = async (redis, key, limitPerHour, now = Date.now()) => {
|
|
31100
31413
|
if (!redis) return true;
|
|
31101
31414
|
try {
|
|
31102
|
-
const currentBucket = Math.floor(now /
|
|
31415
|
+
const currentBucket = Math.floor(now / HOUR_MS2);
|
|
31103
31416
|
const currentKey = `${key}:${currentBucket}`;
|
|
31104
31417
|
const previousKey = `${key}:${currentBucket - 1}`;
|
|
31105
31418
|
const count2 = await redis.incr(currentKey);
|
|
@@ -31108,7 +31421,7 @@ var checkRateLimit = async (redis, key, limitPerHour, now = Date.now()) => {
|
|
|
31108
31421
|
}
|
|
31109
31422
|
const previousRaw = await redis.get(previousKey);
|
|
31110
31423
|
const previous = previousRaw ? Number(previousRaw) : 0;
|
|
31111
|
-
const elapsedFraction = now %
|
|
31424
|
+
const elapsedFraction = now % HOUR_MS2 / HOUR_MS2;
|
|
31112
31425
|
const weighted = count2 + previous * (1 - elapsedFraction);
|
|
31113
31426
|
return weighted <= limitPerHour;
|
|
31114
31427
|
} catch (err4) {
|
|
@@ -31288,7 +31601,7 @@ var fireRun = async (opts) => {
|
|
|
31288
31601
|
}
|
|
31289
31602
|
const warningNote = warnings.length ? "\n\n[Hinweis des Systems] " + warnings.map((w) => INTAKE_WARNING_TEXTS[w]).join(" ") : "";
|
|
31290
31603
|
const initialMessage = {
|
|
31291
|
-
id: (0,
|
|
31604
|
+
id: (0, import_node_crypto17.randomUUID)(),
|
|
31292
31605
|
role: "user",
|
|
31293
31606
|
parts: [
|
|
31294
31607
|
{
|
|
@@ -32101,71 +32414,6 @@ var createRunLock = (redis) => ({
|
|
|
32101
32414
|
|
|
32102
32415
|
// src/exulu/channels/wiring.ts
|
|
32103
32416
|
init_cjs_shims();
|
|
32104
|
-
|
|
32105
|
-
// src/exulu/external-rate-limit.ts
|
|
32106
|
-
init_cjs_shims();
|
|
32107
|
-
var MINUTE_MS = 6e4;
|
|
32108
|
-
var HOUR_MS2 = 36e5;
|
|
32109
|
-
var perMinuteLimit = () => parseInt(process.env.EXULU_EXTERNAL_RATE_PER_MINUTE || "30", 10);
|
|
32110
|
-
var perHourLimit = () => parseInt(process.env.EXULU_EXTERNAL_RATE_PER_HOUR || "300", 10);
|
|
32111
|
-
var windows = /* @__PURE__ */ new Map();
|
|
32112
|
-
var externalRateLimitExceeded = (userId, now = Date.now()) => {
|
|
32113
|
-
const state = windows.get(userId) ?? {
|
|
32114
|
-
minuteStart: now,
|
|
32115
|
-
minuteCount: 0,
|
|
32116
|
-
hourStart: now,
|
|
32117
|
-
hourCount: 0,
|
|
32118
|
-
lastSeen: now
|
|
32119
|
-
};
|
|
32120
|
-
if (now - state.minuteStart >= MINUTE_MS) {
|
|
32121
|
-
state.minuteStart = now;
|
|
32122
|
-
state.minuteCount = 0;
|
|
32123
|
-
}
|
|
32124
|
-
if (now - state.hourStart >= HOUR_MS2) {
|
|
32125
|
-
state.hourStart = now;
|
|
32126
|
-
state.hourCount = 0;
|
|
32127
|
-
}
|
|
32128
|
-
state.minuteCount += 1;
|
|
32129
|
-
state.hourCount += 1;
|
|
32130
|
-
state.lastSeen = now;
|
|
32131
|
-
windows.set(userId, state);
|
|
32132
|
-
if (windows.size > 1e4) {
|
|
32133
|
-
for (const [key, value] of windows) {
|
|
32134
|
-
if (now - value.lastSeen >= HOUR_MS2) windows.delete(key);
|
|
32135
|
-
}
|
|
32136
|
-
if (windows.size > 1e4) {
|
|
32137
|
-
const sorted = [...windows.entries()].sort(
|
|
32138
|
-
(a, b) => a[1].lastSeen - b[1].lastSeen
|
|
32139
|
-
);
|
|
32140
|
-
for (const [key] of sorted) {
|
|
32141
|
-
if (windows.size <= 1e4) break;
|
|
32142
|
-
windows.delete(key);
|
|
32143
|
-
}
|
|
32144
|
-
}
|
|
32145
|
-
}
|
|
32146
|
-
const minuteLimitExceeded = state.minuteCount > perMinuteLimit();
|
|
32147
|
-
const hourLimitExceeded = state.hourCount > perHourLimit();
|
|
32148
|
-
const limitExceeded = minuteLimitExceeded || hourLimitExceeded;
|
|
32149
|
-
if (limitExceeded) {
|
|
32150
|
-
const limits = {
|
|
32151
|
-
perMinute: perMinuteLimit(),
|
|
32152
|
-
perHour: perHourLimit()
|
|
32153
|
-
};
|
|
32154
|
-
const current = {
|
|
32155
|
-
minute: state.minuteCount,
|
|
32156
|
-
hour: state.hourCount
|
|
32157
|
-
};
|
|
32158
|
-
console.warn(
|
|
32159
|
-
`[EXULU] Rate limit exceeded for user ${userId}${minuteLimitExceeded ? ` per-minute (${current.minute}/${limits.perMinute})` : ""}${minuteLimitExceeded && hourLimitExceeded ? " and" : ""}${hourLimitExceeded ? ` per-hour (${current.hour}/${limits.perHour})` : ""}`
|
|
32160
|
-
);
|
|
32161
|
-
}
|
|
32162
|
-
return limitExceeded;
|
|
32163
|
-
};
|
|
32164
|
-
var isExternalUser = (user) => {
|
|
32165
|
-
return user?.role?.name === "external";
|
|
32166
|
-
};
|
|
32167
|
-
|
|
32168
|
-
// src/exulu/channels/wiring.ts
|
|
32169
32417
|
var channelStoreFromRedis = (client2) => ({
|
|
32170
32418
|
set: (key, value, opts) => client2.set(key, value, opts.NX ? { EX: opts.EX, NX: true } : { EX: opts.EX }),
|
|
32171
32419
|
getDel: (key) => client2.getDel(key),
|
|
@@ -35921,7 +36169,7 @@ var liveRecordingService = {
|
|
|
35921
36169
|
|
|
35922
36170
|
// src/exulu/email-inbound/trigger-config.ts
|
|
35923
36171
|
init_cjs_shims();
|
|
35924
|
-
var
|
|
36172
|
+
var import_node_crypto18 = require("crypto");
|
|
35925
36173
|
var import_safe_regex = __toESM(require("safe-regex"), 1);
|
|
35926
36174
|
var MAX_FILTER_PATTERN_LENGTH = 200;
|
|
35927
36175
|
var FILTER_FIELDS = [
|
|
@@ -36015,10 +36263,10 @@ function validateEmailTriggerConfig(raw) {
|
|
|
36015
36263
|
return config;
|
|
36016
36264
|
}
|
|
36017
36265
|
function generateTriggerSecret() {
|
|
36018
|
-
return (0,
|
|
36266
|
+
return (0, import_node_crypto18.randomBytes)(32).toString("base64url");
|
|
36019
36267
|
}
|
|
36020
36268
|
function generateSigningSecret() {
|
|
36021
|
-
return (0,
|
|
36269
|
+
return (0, import_node_crypto18.randomBytes)(32).toString("base64url");
|
|
36022
36270
|
}
|
|
36023
36271
|
|
|
36024
36272
|
// src/graphql/schemas/index.ts
|
|
@@ -36058,11 +36306,11 @@ async function insertTriggerWithSecretRetry(insertFn, baseRow) {
|
|
|
36058
36306
|
|
|
36059
36307
|
// src/exulu/email-inbound/webhook.ts
|
|
36060
36308
|
init_cjs_shims();
|
|
36061
|
-
var
|
|
36309
|
+
var import_node_crypto20 = require("crypto");
|
|
36062
36310
|
|
|
36063
36311
|
// src/exulu/email-inbound/verify-signature.ts
|
|
36064
36312
|
init_cjs_shims();
|
|
36065
|
-
var
|
|
36313
|
+
var import_node_crypto19 = require("crypto");
|
|
36066
36314
|
var SIGNATURE_REPLAY_WINDOW_SECONDS = 300;
|
|
36067
36315
|
var REPLAY_TTL_SECONDS = 900;
|
|
36068
36316
|
function verifyPayloadSignature(rawBody, signatureHeader, timestampHeader, secret) {
|
|
@@ -36071,11 +36319,11 @@ function verifyPayloadSignature(rawBody, signatureHeader, timestampHeader, secre
|
|
|
36071
36319
|
const provided = signatureHeader.slice("sha256=".length);
|
|
36072
36320
|
if (!/^[0-9a-f]+$/i.test(provided)) return false;
|
|
36073
36321
|
const message = timestampHeader ? Buffer.concat([Buffer.from(`${timestampHeader}.`), rawBody]) : rawBody;
|
|
36074
|
-
const expected = (0,
|
|
36322
|
+
const expected = (0, import_node_crypto19.createHmac)("sha256", secret).update(message).digest("hex");
|
|
36075
36323
|
const expectedBuf = Buffer.from(expected, "utf8");
|
|
36076
36324
|
const providedBuf = Buffer.from(provided.toLowerCase(), "utf8");
|
|
36077
36325
|
if (expectedBuf.length !== providedBuf.length) return false;
|
|
36078
|
-
return (0,
|
|
36326
|
+
return (0, import_node_crypto19.timingSafeEqual)(expectedBuf, providedBuf);
|
|
36079
36327
|
}
|
|
36080
36328
|
async function isReplay(redis, signature, timestamp) {
|
|
36081
36329
|
const ts = Number(timestamp);
|
|
@@ -36180,7 +36428,7 @@ var createRoutineWebhookHandler = (deps) => async (req, res) => {
|
|
|
36180
36428
|
);
|
|
36181
36429
|
try {
|
|
36182
36430
|
const ext = format === "json" ? "json" : "eml";
|
|
36183
|
-
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);
|
|
36184
36432
|
await deps.enqueueIntake({ s3Key, triggerId: trigger.id, format });
|
|
36185
36433
|
} catch (error) {
|
|
36186
36434
|
console.error("[EXULU-WEBHOOK] persist/enqueue failed", error);
|
|
@@ -36192,7 +36440,7 @@ var createRoutineWebhookHandler = (deps) => async (req, res) => {
|
|
|
36192
36440
|
|
|
36193
36441
|
// src/graphql/schemas/index.ts
|
|
36194
36442
|
init_uppy();
|
|
36195
|
-
var
|
|
36443
|
+
var import_node_crypto21 = require("crypto");
|
|
36196
36444
|
init_memory_base();
|
|
36197
36445
|
|
|
36198
36446
|
// src/graphql/resolvers/memory-base-stats.ts
|
|
@@ -38030,13 +38278,7 @@ type PageInfo {
|
|
|
38030
38278
|
if (!resolvers2[rbacResolverName]) {
|
|
38031
38279
|
resolvers2[rbacResolverName] = {};
|
|
38032
38280
|
}
|
|
38033
|
-
resolvers2[rbacResolverName].RBAC = async (parent, args, context) =>
|
|
38034
|
-
const { db: db2 } = context;
|
|
38035
|
-
const resourceId = parent.id;
|
|
38036
|
-
const entityName = table.name.singular;
|
|
38037
|
-
const rights_mode = parent.rights_mode;
|
|
38038
|
-
return RBACResolver(db2, entityName, resourceId, rights_mode);
|
|
38039
|
-
};
|
|
38281
|
+
resolvers2[rbacResolverName].RBAC = async (parent, args, context) => resolveRbacField(table, parent, context);
|
|
38040
38282
|
}
|
|
38041
38283
|
}
|
|
38042
38284
|
typeDefs += `
|
|
@@ -38734,7 +38976,7 @@ type EmbeddingModelOption {
|
|
|
38734
38976
|
const ext = format === "json" ? "json" : "eml";
|
|
38735
38977
|
const fullKey = await uploadFile(
|
|
38736
38978
|
bytes,
|
|
38737
|
-
`${EMAIL_INBOUND_S3_PREFIX}${(0,
|
|
38979
|
+
`${EMAIL_INBOUND_S3_PREFIX}${(0, import_node_crypto21.randomUUID)()}.${ext}`,
|
|
38738
38980
|
config,
|
|
38739
38981
|
{ contentType: "application/octet-stream" },
|
|
38740
38982
|
void 0,
|
|
@@ -40041,7 +40283,7 @@ var import_body_parser = __toESM(require("body-parser"), 1);
|
|
|
40041
40283
|
var import_crypto_js7 = require("crypto-js");
|
|
40042
40284
|
var import_openai = require("openai");
|
|
40043
40285
|
var import_fs5 = __toESM(require("fs"), 1);
|
|
40044
|
-
var
|
|
40286
|
+
var import_node_crypto26 = require("crypto");
|
|
40045
40287
|
var import_api3 = require("@opentelemetry/api");
|
|
40046
40288
|
init_check_record_access();
|
|
40047
40289
|
var import_jszip4 = __toESM(require("jszip"), 1);
|
|
@@ -40049,7 +40291,7 @@ var import_jszip4 = __toESM(require("jszip"), 1);
|
|
|
40049
40291
|
// src/skills/bundled.ts
|
|
40050
40292
|
init_cjs_shims();
|
|
40051
40293
|
var import_jszip3 = __toESM(require("jszip"), 1);
|
|
40052
|
-
var
|
|
40294
|
+
var import_node_crypto22 = require("crypto");
|
|
40053
40295
|
|
|
40054
40296
|
// src/skills/bundled.generated.ts
|
|
40055
40297
|
init_cjs_shims();
|
|
@@ -40074,7 +40316,7 @@ var BUNDLED_SKILLS = [
|
|
|
40074
40316
|
init_frontmatter();
|
|
40075
40317
|
var BUNDLED_LABEL = "Bundled with the IMP";
|
|
40076
40318
|
function bundledSkillHash(skill) {
|
|
40077
|
-
const h = (0,
|
|
40319
|
+
const h = (0, import_node_crypto22.createHash)("sha256");
|
|
40078
40320
|
for (const path4 of Object.keys(skill.files).sort()) {
|
|
40079
40321
|
h.update(path4).update("\0").update(skill.files[path4]).update("\0");
|
|
40080
40322
|
}
|
|
@@ -40135,7 +40377,7 @@ async function seedBundledSkills({
|
|
|
40135
40377
|
log7(`"${skill.name}" updated to v${nextVersion}`);
|
|
40136
40378
|
continue;
|
|
40137
40379
|
}
|
|
40138
|
-
const skillId = (0,
|
|
40380
|
+
const skillId = (0, import_node_crypto22.randomUUID)();
|
|
40139
40381
|
await extractBundleToVersion({ bytes: await bundledSkillZip(skill), skillId, version: 1, config });
|
|
40140
40382
|
await db2("skills").insert({
|
|
40141
40383
|
id: skillId,
|
|
@@ -40247,7 +40489,7 @@ var persistThroughDisconnect = () => ({
|
|
|
40247
40489
|
|
|
40248
40490
|
// src/exulu/compact-session.ts
|
|
40249
40491
|
init_cjs_shims();
|
|
40250
|
-
var
|
|
40492
|
+
var import_node_crypto23 = require("crypto");
|
|
40251
40493
|
var import_ai14 = require("ai");
|
|
40252
40494
|
init_truncate_tool_output();
|
|
40253
40495
|
init_context_budget();
|
|
@@ -40353,7 +40595,7 @@ Focus especially on: ${steer.trim()}` : SUMMARY_SYSTEM;
|
|
|
40353
40595
|
...steer?.trim() ? { steer: steer.trim() } : {}
|
|
40354
40596
|
};
|
|
40355
40597
|
const checkpoint = {
|
|
40356
|
-
id: `compaction_${(0,
|
|
40598
|
+
id: `compaction_${(0, import_node_crypto23.randomUUID)()}`,
|
|
40357
40599
|
role: "user",
|
|
40358
40600
|
parts: [{ type: "text", text: `[Conversation summary \u2014 earlier messages were compacted]
|
|
40359
40601
|
|
|
@@ -41389,13 +41631,13 @@ function isInside2(key, fullPrefix) {
|
|
|
41389
41631
|
return key.startsWith(fullPrefix) && !key.includes("..");
|
|
41390
41632
|
}
|
|
41391
41633
|
function registerProjectFileRoutes(app, deps) {
|
|
41392
|
-
const
|
|
41634
|
+
const idOf4 = (req) => String(req.params.projectId ?? "");
|
|
41393
41635
|
const rowId = (authed) => String(authed.project.id);
|
|
41394
41636
|
const listObjects = async (projectId) => (await deps.s3.list(projectFilePrefix(projectId, deps.s3prefix).projectPrefix)).filter(
|
|
41395
41637
|
(o) => !o.key.endsWith("/")
|
|
41396
41638
|
);
|
|
41397
41639
|
app.get("/projects/:projectId/files", async (req, res) => {
|
|
41398
|
-
const projectId =
|
|
41640
|
+
const projectId = idOf4(req);
|
|
41399
41641
|
const authed = await deps.loadAuthedProject(req, res, projectId, "read");
|
|
41400
41642
|
if (!authed) return;
|
|
41401
41643
|
const canWrite2 = await deps.canWrite(authed.user, authed.project);
|
|
@@ -41416,7 +41658,7 @@ function registerProjectFileRoutes(app, deps) {
|
|
|
41416
41658
|
res.json({ canWrite: canWrite2, files });
|
|
41417
41659
|
});
|
|
41418
41660
|
app.post("/projects/:projectId/files/upload-sign", async (req, res) => {
|
|
41419
|
-
const projectId =
|
|
41661
|
+
const projectId = idOf4(req);
|
|
41420
41662
|
const authed = await deps.loadAuthedProject(req, res, projectId, "write");
|
|
41421
41663
|
if (!authed) return;
|
|
41422
41664
|
const { filename, contentType, overwrite } = req.body ?? {};
|
|
@@ -41456,7 +41698,7 @@ function registerProjectFileRoutes(app, deps) {
|
|
|
41456
41698
|
}
|
|
41457
41699
|
});
|
|
41458
41700
|
app.delete("/projects/:projectId/files", async (req, res) => {
|
|
41459
|
-
const projectId =
|
|
41701
|
+
const projectId = idOf4(req);
|
|
41460
41702
|
const key = req.query.key;
|
|
41461
41703
|
if (!key || typeof key !== "string") {
|
|
41462
41704
|
res.status(400).json({ detail: "Missing or invalid 'key' query parameter." });
|
|
@@ -41481,7 +41723,7 @@ function registerProjectFileRoutes(app, deps) {
|
|
|
41481
41723
|
if (!req.headers.authorization && typeof req.query.auth === "string") {
|
|
41482
41724
|
req.headers.authorization = `Bearer ${req.query.auth}`;
|
|
41483
41725
|
}
|
|
41484
|
-
const projectId =
|
|
41726
|
+
const projectId = idOf4(req);
|
|
41485
41727
|
const key = req.query.key;
|
|
41486
41728
|
if (!key || typeof key !== "string") {
|
|
41487
41729
|
res.status(400).json({ detail: "Missing or invalid 'key' query parameter." });
|
|
@@ -41510,7 +41752,7 @@ function registerProjectFileRoutes(app, deps) {
|
|
|
41510
41752
|
}
|
|
41511
41753
|
});
|
|
41512
41754
|
app.post("/projects/:projectId/files/promote", async (req, res) => {
|
|
41513
|
-
const projectId =
|
|
41755
|
+
const projectId = idOf4(req);
|
|
41514
41756
|
const { sessionId, keys, overwrite } = req.body ?? {};
|
|
41515
41757
|
if (typeof sessionId !== "string" || !sessionId || !Array.isArray(keys)) {
|
|
41516
41758
|
res.status(400).json({ detail: "sessionId (string) and keys (array) are required." });
|
|
@@ -41597,9 +41839,142 @@ function registerViewerIdentityRoutes(app, deps) {
|
|
|
41597
41839
|
});
|
|
41598
41840
|
}
|
|
41599
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
|
+
|
|
41600
41975
|
// src/exulu/tool-api-route.ts
|
|
41601
41976
|
init_cjs_shims();
|
|
41602
|
-
var
|
|
41977
|
+
var import_node_crypto24 = require("crypto");
|
|
41603
41978
|
init_progress();
|
|
41604
41979
|
var TOOL_API_ROUTE_PATH = "/tools/:id";
|
|
41605
41980
|
var toolConfigDefaults = (tool5) => Object.fromEntries(
|
|
@@ -41640,7 +42015,7 @@ function registerToolApiRoutes(app, deps) {
|
|
|
41640
42015
|
res.status(500).json({ detail: "Tool has no execute function." });
|
|
41641
42016
|
return;
|
|
41642
42017
|
}
|
|
41643
|
-
const toolCallId = `${tool5.id}_${(0,
|
|
42018
|
+
const toolCallId = `${tool5.id}_${(0, import_node_crypto24.randomUUID)()}`;
|
|
41644
42019
|
const started = Date.now();
|
|
41645
42020
|
let output;
|
|
41646
42021
|
let status = "ok";
|
|
@@ -41724,6 +42099,23 @@ function registerCreateShareRoute(app, deps) {
|
|
|
41724
42099
|
res.status(400).json({ detail: valid.message });
|
|
41725
42100
|
return;
|
|
41726
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
|
+
}
|
|
41727
42119
|
const details = planDetails({ ...req.body, archived: void 0 }, now);
|
|
41728
42120
|
if (!details.ok) {
|
|
41729
42121
|
res.status(400).json({ detail: details.message });
|
|
@@ -41754,6 +42146,7 @@ function registerCreateShareRoute(app, deps) {
|
|
|
41754
42146
|
password_hash,
|
|
41755
42147
|
expires_at: req.body.expires_at ?? null,
|
|
41756
42148
|
content_type: req.body.content_type ?? null,
|
|
42149
|
+
external_access: req.body.external_access === true,
|
|
41757
42150
|
rights_mode,
|
|
41758
42151
|
created_by: auth.user.id,
|
|
41759
42152
|
...details.patch,
|
|
@@ -44579,7 +44972,7 @@ init_flow();
|
|
|
44579
44972
|
|
|
44580
44973
|
// src/exulu/recall/verify.ts
|
|
44581
44974
|
init_cjs_shims();
|
|
44582
|
-
var
|
|
44975
|
+
var import_node_crypto25 = require("crypto");
|
|
44583
44976
|
var TOLERANCE_SECONDS = 5 * 60;
|
|
44584
44977
|
var header = (headers, ...names) => {
|
|
44585
44978
|
for (const name of names) {
|
|
@@ -44597,7 +44990,7 @@ var safeEqual = (a, b) => {
|
|
|
44597
44990
|
const bufA = Buffer.from(a);
|
|
44598
44991
|
const bufB = Buffer.from(b);
|
|
44599
44992
|
if (bufA.length !== bufB.length) return false;
|
|
44600
|
-
return (0,
|
|
44993
|
+
return (0, import_node_crypto25.timingSafeEqual)(bufA, bufB);
|
|
44601
44994
|
};
|
|
44602
44995
|
var verifyRecallRequest = (headers, rawBody, secret = recallVerificationSecret()) => {
|
|
44603
44996
|
if (!secret) {
|
|
@@ -44619,7 +45012,7 @@ var verifyRecallRequest = (headers, rawBody, secret = recallVerificationSecret()
|
|
|
44619
45012
|
}
|
|
44620
45013
|
const body = typeof rawBody === "string" ? rawBody : rawBody.toString("utf8");
|
|
44621
45014
|
const signedContent = `${id}.${timestamp}.${body}`;
|
|
44622
|
-
const expected = (0,
|
|
45015
|
+
const expected = (0, import_node_crypto25.createHmac)("sha256", secretKey(secret)).update(signedContent).digest("base64");
|
|
44623
45016
|
const passed = signatureHeader.split(" ").some((entry) => {
|
|
44624
45017
|
const [, sig] = entry.split(",");
|
|
44625
45018
|
return !!sig && safeEqual(sig, expected);
|
|
@@ -44992,7 +45385,12 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
44992
45385
|
const server = new import_server5.ApolloServer({
|
|
44993
45386
|
cache: new import_utils5.InMemoryLRUCache(),
|
|
44994
45387
|
schema: schema7,
|
|
44995
|
-
introspection: true
|
|
45388
|
+
introspection: true,
|
|
45389
|
+
plugins: [
|
|
45390
|
+
companionOperationGuard(
|
|
45391
|
+
companionAllowedOperations((contexts ?? []).map(convertContextToTableDefinition))
|
|
45392
|
+
)
|
|
45393
|
+
]
|
|
44996
45394
|
});
|
|
44997
45395
|
await server.start();
|
|
44998
45396
|
app.use(
|
|
@@ -45011,7 +45409,10 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
45011
45409
|
return {
|
|
45012
45410
|
req,
|
|
45013
45411
|
db: db2,
|
|
45014
|
-
user:
|
|
45412
|
+
user: admitCompanionUser(
|
|
45413
|
+
companionRequestState(req.headers),
|
|
45414
|
+
authenticationResult.user
|
|
45415
|
+
)
|
|
45015
45416
|
};
|
|
45016
45417
|
}
|
|
45017
45418
|
})
|
|
@@ -45146,7 +45547,7 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
45146
45547
|
inputs: payload
|
|
45147
45548
|
};
|
|
45148
45549
|
await queue.queue.add("email-intake", jobData, {
|
|
45149
|
-
jobId: (0,
|
|
45550
|
+
jobId: (0, import_node_crypto26.randomUUID)(),
|
|
45150
45551
|
attempts: 3,
|
|
45151
45552
|
removeOnComplete: 5e3,
|
|
45152
45553
|
removeOnFail: 1e4,
|
|
@@ -45554,7 +45955,7 @@ ${customInstructions}` : agent.instructions,
|
|
|
45554
45955
|
contextId: agent.memory,
|
|
45555
45956
|
agentId: agent.id,
|
|
45556
45957
|
session: headers.session ?? null,
|
|
45557
|
-
messageId: responseMessage?.id ?? messages[messages.length - 1]?.id ?? (0,
|
|
45958
|
+
messageId: responseMessage?.id ?? messages[messages.length - 1]?.id ?? (0, import_node_crypto26.randomUUID)(),
|
|
45558
45959
|
userId: user?.id ?? null
|
|
45559
45960
|
});
|
|
45560
45961
|
}
|
|
@@ -46247,7 +46648,7 @@ ${outputSchemaInstructions(outputSchema)}` : baseInstructions;
|
|
|
46247
46648
|
const keys = [];
|
|
46248
46649
|
const revisedPrompts = [];
|
|
46249
46650
|
for (const img of images) {
|
|
46250
|
-
const filename = `${(0,
|
|
46651
|
+
const filename = `${(0, import_node_crypto26.randomUUID)()}.${img.extension}`;
|
|
46251
46652
|
const key = `sessions/${sessionId}/images/${toolCallId}/${filename}`;
|
|
46252
46653
|
const fullKey = await uploadFile(
|
|
46253
46654
|
img.buffer,
|
|
@@ -46535,7 +46936,7 @@ ${style.markdown}` : params.prompt;
|
|
|
46535
46936
|
(d) => `- ${d.presignedUrl} (prompt: "${d.prompt}", model: ${d.model}${d.styleName ? `, style: ${d.styleName}` : ""})`
|
|
46536
46937
|
);
|
|
46537
46938
|
const messageText2 = "The user generated and selected the following image(s) in this chat:\n" + lines.join("\n");
|
|
46538
|
-
const messageId = (0,
|
|
46939
|
+
const messageId = (0, import_node_crypto26.randomUUID)();
|
|
46539
46940
|
const uiMessage = {
|
|
46540
46941
|
id: messageId,
|
|
46541
46942
|
role: "system",
|
|
@@ -47632,7 +48033,7 @@ ${style.markdown}` : params.prompt;
|
|
|
47632
48033
|
return;
|
|
47633
48034
|
}
|
|
47634
48035
|
const meta = await parseSkillFrontmatter(bytes);
|
|
47635
|
-
const skillId = (0,
|
|
48036
|
+
const skillId = (0, import_node_crypto26.randomUUID)();
|
|
47636
48037
|
try {
|
|
47637
48038
|
await extractBundleToVersion({ bytes, skillId, version: 1, config });
|
|
47638
48039
|
} catch (err4) {
|
|
@@ -47755,7 +48156,7 @@ ${style.markdown}` : params.prompt;
|
|
|
47755
48156
|
return;
|
|
47756
48157
|
}
|
|
47757
48158
|
if (!await ensureSkillWrite(db2, skill, authResult.user, res)) return;
|
|
47758
|
-
const stagingKey = `user_${authResult.user.id}/skills/_staging/${(0,
|
|
48159
|
+
const stagingKey = `user_${authResult.user.id}/skills/_staging/${(0, import_node_crypto26.randomUUID)()}${extension}`;
|
|
47759
48160
|
const fullKey = config.fileUploads?.s3prefix ? `${config.fileUploads.s3prefix.replace(/\/$/, "")}/${stagingKey}` : stagingKey;
|
|
47760
48161
|
const uploadUrl = await getS3SignedUploadUrl(fullKey, contentType, config);
|
|
47761
48162
|
res.json({ uploadUrl, stagingKey });
|
|
@@ -48758,6 +49159,7 @@ ${style.markdown}` : params.prompt;
|
|
|
48758
49159
|
// Coerced, not `?? []`: see readAgentSlots on why a stored non-array is
|
|
48759
49160
|
// a real possibility and why a reader has to survive one.
|
|
48760
49161
|
agent_slots: readAgentSlots(row.agent_slots),
|
|
49162
|
+
external_access: row.external_access === true,
|
|
48761
49163
|
...detailsOf(row),
|
|
48762
49164
|
// Older files, newest first; at most MAX_OLDER_VERSIONS (artifact-library.ts).
|
|
48763
49165
|
versions: versions.map((v) => ({
|
|
@@ -48797,6 +49199,28 @@ ${style.markdown}` : params.prompt;
|
|
|
48797
49199
|
res.status(400).json({ detail: valid.message });
|
|
48798
49200
|
return;
|
|
48799
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
|
+
}
|
|
48800
49224
|
const details = planDetails(input, now);
|
|
48801
49225
|
if (!details.ok) {
|
|
48802
49226
|
res.status(400).json({ detail: details.message });
|
|
@@ -48841,6 +49265,7 @@ ${style.markdown}` : params.prompt;
|
|
|
48841
49265
|
expires_at: updated.expires_at ?? null,
|
|
48842
49266
|
rights_mode: updated.rights_mode ?? null,
|
|
48843
49267
|
agent_slots: readAgentSlots(updated.agent_slots),
|
|
49268
|
+
external_access: updated.external_access === true,
|
|
48844
49269
|
...detailsOf(updated),
|
|
48845
49270
|
version_count: readVersions(updated.versions).length
|
|
48846
49271
|
});
|
|
@@ -48910,6 +49335,13 @@ ${style.markdown}` : params.prompt;
|
|
|
48910
49335
|
RBACResolver,
|
|
48911
49336
|
checkRecordAccess
|
|
48912
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
|
+
});
|
|
48913
49345
|
registerToolApiRoutes(app, {
|
|
48914
49346
|
authenticate: (req) => requestValidators.authenticate(req),
|
|
48915
49347
|
tools,
|
|
@@ -49257,7 +49689,7 @@ function buildUnifiedDiff(fromLines, toLines, fromLabel, toLabel) {
|
|
|
49257
49689
|
// src/mcp/index.ts
|
|
49258
49690
|
init_cjs_shims();
|
|
49259
49691
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
49260
|
-
var
|
|
49692
|
+
var import_node_crypto27 = require("crypto");
|
|
49261
49693
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
49262
49694
|
var import_types14 = require("@modelcontextprotocol/sdk/types.js");
|
|
49263
49695
|
init_sanitize_tool_name();
|
|
@@ -49358,7 +49790,7 @@ var ExuluMCP = class {
|
|
|
49358
49790
|
throw new Error("Tool not found in converted tools array.");
|
|
49359
49791
|
}
|
|
49360
49792
|
const iterator = await convertedTool.execute(inputs, {
|
|
49361
|
-
toolCallId: tool5.id + "_" + (0,
|
|
49793
|
+
toolCallId: tool5.id + "_" + (0, import_node_crypto27.randomUUID)(),
|
|
49362
49794
|
messages: []
|
|
49363
49795
|
});
|
|
49364
49796
|
let result;
|
|
@@ -49548,7 +49980,7 @@ var ExuluMCP = class {
|
|
|
49548
49980
|
transport = this.transports[sessionId];
|
|
49549
49981
|
} else if (!sessionId && (0, import_types14.isInitializeRequest)(req.body)) {
|
|
49550
49982
|
transport = new import_streamableHttp.StreamableHTTPServerTransport({
|
|
49551
|
-
sessionIdGenerator: () => (0,
|
|
49983
|
+
sessionIdGenerator: () => (0, import_node_crypto27.randomUUID)(),
|
|
49552
49984
|
onsessioninitialized: (sessionId2) => {
|
|
49553
49985
|
this.transports[sessionId2] = transport;
|
|
49554
49986
|
}
|
|
@@ -50154,7 +50586,7 @@ var import_zod39 = __toESM(require("zod"), 1);
|
|
|
50154
50586
|
init_tool2();
|
|
50155
50587
|
init_check_record_access();
|
|
50156
50588
|
init_client();
|
|
50157
|
-
var
|
|
50589
|
+
var import_node_crypto28 = require("crypto");
|
|
50158
50590
|
var AnswerOptionSchema = import_zod39.default.object({
|
|
50159
50591
|
id: import_zod39.default.string().describe("Unique identifier for the answer option"),
|
|
50160
50592
|
text: import_zod39.default.string().describe("The text of the answer option")
|
|
@@ -50208,15 +50640,15 @@ var QuestionAskTool = new ExuluTool({
|
|
|
50208
50640
|
throw new Error("You don't have access to this session " + session.id + ".");
|
|
50209
50641
|
}
|
|
50210
50642
|
const answerOptionsWithIds = answerOptions.map((text) => ({
|
|
50211
|
-
id: (0,
|
|
50643
|
+
id: (0, import_node_crypto28.randomUUID)(),
|
|
50212
50644
|
text
|
|
50213
50645
|
}));
|
|
50214
50646
|
answerOptionsWithIds.push({
|
|
50215
|
-
id: (0,
|
|
50647
|
+
id: (0, import_node_crypto28.randomUUID)(),
|
|
50216
50648
|
text: "None of the above..."
|
|
50217
50649
|
});
|
|
50218
50650
|
const newQuestion = {
|
|
50219
|
-
id: (0,
|
|
50651
|
+
id: (0, import_node_crypto28.randomUUID)(),
|
|
50220
50652
|
question,
|
|
50221
50653
|
answerOptions: answerOptionsWithIds,
|
|
50222
50654
|
status: "pending"
|