@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
|
@@ -1130,6 +1130,131 @@ var officeToText = async (bytes) => {
|
|
|
1130
1130
|
return String(value);
|
|
1131
1131
|
};
|
|
1132
1132
|
|
|
1133
|
+
// src/templates/tools/document-render-helpers.ts
|
|
1134
|
+
import { execFile } from "child_process";
|
|
1135
|
+
import { promisify } from "util";
|
|
1136
|
+
import { existsSync as existsSync2 } from "fs";
|
|
1137
|
+
import { mkdtemp, readdir, readFile, rm, writeFile } from "fs/promises";
|
|
1138
|
+
import { tmpdir } from "os";
|
|
1139
|
+
import { join } from "path";
|
|
1140
|
+
var execFileAsync = promisify(execFile);
|
|
1141
|
+
var MAX_STDOUT_BYTES = 64 * 1024 * 1024;
|
|
1142
|
+
var LEGACY_OFFICE_CONVERSION_TARGETS = {
|
|
1143
|
+
".doc": "docx",
|
|
1144
|
+
".xls": "xlsx",
|
|
1145
|
+
".ppt": "pptx",
|
|
1146
|
+
".rtf": "docx"
|
|
1147
|
+
};
|
|
1148
|
+
function isLegacyOfficeFormat(ext) {
|
|
1149
|
+
return ext in LEGACY_OFFICE_CONVERSION_TARGETS;
|
|
1150
|
+
}
|
|
1151
|
+
async function convertLegacyOfficeToModern(bytes, ext) {
|
|
1152
|
+
const target = LEGACY_OFFICE_CONVERSION_TARGETS[ext];
|
|
1153
|
+
if (!target) {
|
|
1154
|
+
throw new Error(`No modern-format conversion target registered for "${ext}"`);
|
|
1155
|
+
}
|
|
1156
|
+
const dir = await mkdtemp(join(tmpdir(), "exulu-officeconv-"));
|
|
1157
|
+
try {
|
|
1158
|
+
const inputPath = join(dir, `input${ext}`);
|
|
1159
|
+
await writeFile(inputPath, bytes);
|
|
1160
|
+
try {
|
|
1161
|
+
await execFileAsync(
|
|
1162
|
+
"soffice",
|
|
1163
|
+
["--headless", "--convert-to", target, inputPath, "--outdir", dir],
|
|
1164
|
+
{ timeout: 6e4, maxBuffer: MAX_STDOUT_BYTES }
|
|
1165
|
+
);
|
|
1166
|
+
} catch (err) {
|
|
1167
|
+
throw new Error(
|
|
1168
|
+
`LibreOffice could not convert the legacy "${ext}" file to ${target}: ` + (err instanceof Error ? err.message : String(err))
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
const outputPath = join(dir, `input.${target}`);
|
|
1172
|
+
if (!existsSync2(outputPath)) {
|
|
1173
|
+
throw new Error(`LibreOffice produced no output converting "${ext}" to ${target}`);
|
|
1174
|
+
}
|
|
1175
|
+
return await readFile(outputPath);
|
|
1176
|
+
} finally {
|
|
1177
|
+
await rm(dir, { recursive: true, force: true });
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
var PRESENTATION_EXTENSIONS = /* @__PURE__ */ new Set([".pptx", ".ppt", ".pptm", ".odp"]);
|
|
1181
|
+
function isPresentationFormat(ext) {
|
|
1182
|
+
return PRESENTATION_EXTENSIONS.has(ext.toLowerCase());
|
|
1183
|
+
}
|
|
1184
|
+
async function convertOfficeToPdf(bytes, ext) {
|
|
1185
|
+
const dir = await mkdtemp(join(tmpdir(), "exulu-office2pdf-"));
|
|
1186
|
+
try {
|
|
1187
|
+
const inputPath = join(dir, `input${ext.toLowerCase()}`);
|
|
1188
|
+
await writeFile(inputPath, bytes);
|
|
1189
|
+
try {
|
|
1190
|
+
await execFileAsync(
|
|
1191
|
+
"soffice",
|
|
1192
|
+
// Own profile directory: two conversions at once otherwise fight over the user profile lock.
|
|
1193
|
+
[`-env:UserInstallation=file://${join(dir, "profile")}`, "--headless", "--convert-to", "pdf", inputPath, "--outdir", dir],
|
|
1194
|
+
{ timeout: 18e4, maxBuffer: MAX_STDOUT_BYTES }
|
|
1195
|
+
);
|
|
1196
|
+
} catch (err) {
|
|
1197
|
+
throw new Error(`LibreOffice could not convert the "${ext}" file to PDF: ` + (err instanceof Error ? err.message : String(err)));
|
|
1198
|
+
}
|
|
1199
|
+
const outputPath = join(dir, "input.pdf");
|
|
1200
|
+
if (!existsSync2(outputPath)) {
|
|
1201
|
+
throw new Error(`LibreOffice produced no PDF for the "${ext}" file`);
|
|
1202
|
+
}
|
|
1203
|
+
return await readFile(outputPath);
|
|
1204
|
+
} finally {
|
|
1205
|
+
await rm(dir, { recursive: true, force: true });
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
async function pdfToText(pdf) {
|
|
1209
|
+
const dir = await mkdtemp(join(tmpdir(), "exulu-parse-"));
|
|
1210
|
+
try {
|
|
1211
|
+
const inputPath = join(dir, "input.pdf");
|
|
1212
|
+
await writeFile(inputPath, pdf);
|
|
1213
|
+
const { stdout } = await execFileAsync("pdftotext", ["-layout", inputPath, "-"], {
|
|
1214
|
+
timeout: 6e4,
|
|
1215
|
+
maxBuffer: MAX_STDOUT_BYTES
|
|
1216
|
+
});
|
|
1217
|
+
return stdout;
|
|
1218
|
+
} finally {
|
|
1219
|
+
await rm(dir, { recursive: true, force: true });
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
async function pdfPageCount(pdf) {
|
|
1223
|
+
const dir = await mkdtemp(join(tmpdir(), "exulu-pdfinfo-"));
|
|
1224
|
+
try {
|
|
1225
|
+
const inputPath = join(dir, "input.pdf");
|
|
1226
|
+
await writeFile(inputPath, pdf);
|
|
1227
|
+
const { stdout } = await execFileAsync("pdfinfo", [inputPath], { timeout: 3e4, maxBuffer: 1e6 });
|
|
1228
|
+
const match = /^Pages:\s+(\d+)/m.exec(stdout);
|
|
1229
|
+
if (!match) throw new Error("pdfinfo did not report a page count");
|
|
1230
|
+
return Number(match[1]);
|
|
1231
|
+
} finally {
|
|
1232
|
+
await rm(dir, { recursive: true, force: true });
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
async function renderPdfPageToPng(pdf, page, scaleTo) {
|
|
1236
|
+
const dir = await mkdtemp(join(tmpdir(), "exulu-render-"));
|
|
1237
|
+
try {
|
|
1238
|
+
const inputPath = join(dir, "input.pdf");
|
|
1239
|
+
await writeFile(inputPath, pdf);
|
|
1240
|
+
try {
|
|
1241
|
+
await execFileAsync(
|
|
1242
|
+
"pdftoppm",
|
|
1243
|
+
["-png", "-f", String(page), "-l", String(page), "-scale-to", String(scaleTo), inputPath, join(dir, "page")],
|
|
1244
|
+
{ timeout: 6e4, maxBuffer: MAX_STDOUT_BYTES }
|
|
1245
|
+
);
|
|
1246
|
+
} catch (err) {
|
|
1247
|
+
if (err?.code === 99) return null;
|
|
1248
|
+
throw err;
|
|
1249
|
+
}
|
|
1250
|
+
const produced = (await readdir(dir)).find((f) => f.startsWith("page") && f.endsWith(".png"));
|
|
1251
|
+
if (!produced) return null;
|
|
1252
|
+
return await readFile(join(dir, produced));
|
|
1253
|
+
} finally {
|
|
1254
|
+
await rm(dir, { recursive: true, force: true });
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1133
1258
|
// ee/python/documents/processing/limits.ts
|
|
1134
1259
|
import pLimit from "p-limit";
|
|
1135
1260
|
var PROCESS_WIDE_LIMIT = 8;
|
|
@@ -1196,6 +1321,13 @@ export {
|
|
|
1196
1321
|
ResolveModelError,
|
|
1197
1322
|
resolveModel,
|
|
1198
1323
|
officeToText,
|
|
1324
|
+
isLegacyOfficeFormat,
|
|
1325
|
+
convertLegacyOfficeToModern,
|
|
1326
|
+
isPresentationFormat,
|
|
1327
|
+
convertOfficeToPdf,
|
|
1328
|
+
pdfToText,
|
|
1329
|
+
pdfPageCount,
|
|
1330
|
+
renderPdfPageToPng,
|
|
1199
1331
|
processWideLimiters,
|
|
1200
1332
|
ocrConcurrency,
|
|
1201
1333
|
withRetry
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
buildTags,
|
|
7
7
|
checkLicense,
|
|
8
|
+
convertOfficeToPdf,
|
|
8
9
|
isLiteLLMEnabled,
|
|
9
10
|
ocrConcurrency,
|
|
10
11
|
officeToText,
|
|
@@ -12,7 +13,7 @@ import {
|
|
|
12
13
|
resolveModel,
|
|
13
14
|
waitForLiteLLMReady,
|
|
14
15
|
withRetry
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-BFIDSFRQ.js";
|
|
16
17
|
import {
|
|
17
18
|
resolveLiteLLMTarget
|
|
18
19
|
} from "./chunk-6URU62NI.js";
|
|
@@ -706,6 +707,19 @@ async function processDocument(filePath, fileType, buffer, tempDir, config, verb
|
|
|
706
707
|
case "webp":
|
|
707
708
|
result = await processImage(buffer, paths, config, verbose, tolerateVisionFailures, onProgress, limiters);
|
|
708
709
|
break;
|
|
710
|
+
// A presentation is rendered to PDF and then read like any PDF, with whatever
|
|
711
|
+
// processor is configured. The caller does not choose a parser by file type:
|
|
712
|
+
// slides keep their pictures, charts and screenshots through OCR and the vision pass.
|
|
713
|
+
case "pptx":
|
|
714
|
+
case "ppt":
|
|
715
|
+
case "pptm":
|
|
716
|
+
case "odp": {
|
|
717
|
+
const pdf = await convertOfficeToPdf(buffer, `.${stripped}`);
|
|
718
|
+
const pdfPath = path.join(tempDir, "converted.pdf");
|
|
719
|
+
await fs.promises.writeFile(pdfPath, pdf);
|
|
720
|
+
result = await processPdf(pdf, { ...paths, source: pdfPath }, config, verbose, tolerateVisionFailures, onProgress, limiters);
|
|
721
|
+
break;
|
|
722
|
+
}
|
|
709
723
|
// Todo other file types with docx and officeparser
|
|
710
724
|
default:
|
|
711
725
|
throw new Error(`[EXULU] Unsupported file type: ${fileType}`);
|
|
@@ -946,13 +960,13 @@ async function documentProcessor({
|
|
|
946
960
|
let supportedTypes = [];
|
|
947
961
|
switch (config?.processor.name) {
|
|
948
962
|
case "officeparser":
|
|
949
|
-
supportedTypes = ["docx", "pptx", "xlsx", "odt", "odp", "ods", "pdf", "rtf", "csv", "md", "html"];
|
|
963
|
+
supportedTypes = ["docx", "pptx", "ppt", "pptm", "xlsx", "odt", "odp", "ods", "pdf", "rtf", "csv", "md", "html"];
|
|
950
964
|
break;
|
|
951
965
|
case "liteparse":
|
|
952
966
|
supportedTypes = ["pdf", "doc", "docx", "docm", "odt", "rtf", "ppt", "pptx", "pptm", "odp", "xls", "xlsx", "xlsm", "ods", "csv", "tsv"];
|
|
953
967
|
break;
|
|
954
968
|
case "mistral":
|
|
955
|
-
supportedTypes = ["pdf", "docx", "doc", "txt", "md", "jpg", "jpeg", "png", "gif", "webp"];
|
|
969
|
+
supportedTypes = ["pdf", "docx", "doc", "pptx", "ppt", "pptm", "odp", "txt", "md", "jpg", "jpeg", "png", "gif", "webp"];
|
|
956
970
|
break;
|
|
957
971
|
}
|
|
958
972
|
if (!supportedTypes.includes(fileType.toLowerCase())) {
|
|
@@ -2,15 +2,22 @@ import "dotenv/config";
|
|
|
2
2
|
import {
|
|
3
3
|
buildTags,
|
|
4
4
|
checkLicense,
|
|
5
|
+
convertLegacyOfficeToModern,
|
|
6
|
+
convertOfficeToPdf,
|
|
7
|
+
isLegacyOfficeFormat,
|
|
5
8
|
isLiteLLMEnabled,
|
|
9
|
+
isPresentationFormat,
|
|
6
10
|
officeToText,
|
|
11
|
+
pdfPageCount,
|
|
12
|
+
pdfToText,
|
|
7
13
|
postgresClient,
|
|
8
14
|
processWideLimiters,
|
|
9
15
|
provisionDefaultUserBudget,
|
|
16
|
+
renderPdfPageToPng,
|
|
10
17
|
resolveModel,
|
|
11
18
|
waitForLiteLLMReady,
|
|
12
19
|
withRetry
|
|
13
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-BFIDSFRQ.js";
|
|
14
21
|
import {
|
|
15
22
|
findLiteLLMModel
|
|
16
23
|
} from "./chunk-F534XOQR.js";
|
|
@@ -681,7 +688,7 @@ var ExuluTool = class _ExuluTool {
|
|
|
681
688
|
if (!agent) {
|
|
682
689
|
throw new Error("Agent not found.");
|
|
683
690
|
}
|
|
684
|
-
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-
|
|
691
|
+
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-XEPIBTZT.js");
|
|
685
692
|
const tools = await convertExuluToolsToAiSdkTools2(
|
|
686
693
|
[this],
|
|
687
694
|
[],
|
|
@@ -861,6 +868,51 @@ var readAgentSlots = (value) => {
|
|
|
861
868
|
})() : value;
|
|
862
869
|
return Array.isArray(parsed) ? parsed : [];
|
|
863
870
|
};
|
|
871
|
+
var EXTERNAL_LOGIN_ONLY = "External release requires a login share.";
|
|
872
|
+
var EXTERNAL_NEEDS_TEAM = "External release requires the share to be granted to at least one team.";
|
|
873
|
+
var EXTERNAL_SUPER_ADMIN_ONLY = "Only a super admin can release an artifact externally.";
|
|
874
|
+
var EXTERNAL_TEAM_NAME = "external";
|
|
875
|
+
var validateExternalAccess = (input) => {
|
|
876
|
+
const flag = input.external_access;
|
|
877
|
+
if (flag === void 0) return null;
|
|
878
|
+
if (typeof flag !== "boolean") return "external_access must be a boolean.";
|
|
879
|
+
if (!flag) return null;
|
|
880
|
+
if (input.auth_mode !== "regular") return EXTERNAL_LOGIN_ONLY;
|
|
881
|
+
const teams = input.teams ?? [];
|
|
882
|
+
if (input.rights_mode !== "teams" || teams.length === 0) return EXTERNAL_NEEDS_TEAM;
|
|
883
|
+
if (teams.some((t) => String(t.name).trim().toLowerCase() === EXTERNAL_TEAM_NAME)) {
|
|
884
|
+
return `The team "${EXTERNAL_TEAM_NAME}" holds self-registered guests and cannot be used for external release.`;
|
|
885
|
+
}
|
|
886
|
+
return null;
|
|
887
|
+
};
|
|
888
|
+
var mayChangeExternalRelease = (user, requested, current) => requested !== true || current === true || user.super_admin === true;
|
|
889
|
+
var teamNamesByIds = async (db, ids) => {
|
|
890
|
+
const clean = ids.filter((id) => id !== void 0 && id !== null);
|
|
891
|
+
if (!clean.length) return [];
|
|
892
|
+
const rows = await db("teams").whereIn("id", clean).select("name");
|
|
893
|
+
return rows;
|
|
894
|
+
};
|
|
895
|
+
var externalAccessCheckApplies = (input, row) => input.external_access !== void 0 || row.external_access === true;
|
|
896
|
+
var externalAccessNeedsTeams = (input, row) => {
|
|
897
|
+
const mode = input.auth_mode ?? row.auth_mode;
|
|
898
|
+
const effective = input.external_access !== void 0 ? input.external_access : row.external_access === true;
|
|
899
|
+
return effective === true && mode === "regular";
|
|
900
|
+
};
|
|
901
|
+
var validateExternalAccessUpdate = (input, row, teams) => {
|
|
902
|
+
const mode = input.auth_mode ?? row.auth_mode;
|
|
903
|
+
const effective = input.external_access !== void 0 ? input.external_access : row.external_access === true;
|
|
904
|
+
return validateExternalAccess({
|
|
905
|
+
external_access: effective,
|
|
906
|
+
auth_mode: mode,
|
|
907
|
+
rights_mode: resultingRightsMode(input, row),
|
|
908
|
+
teams
|
|
909
|
+
});
|
|
910
|
+
};
|
|
911
|
+
var resultingRightsMode = (input, row) => {
|
|
912
|
+
const mode = input.auth_mode ?? row.auth_mode;
|
|
913
|
+
if (mode !== "regular") return "public";
|
|
914
|
+
return input.rights_mode ?? (row.auth_mode === "regular" ? row.rights_mode ?? "private" : "private");
|
|
915
|
+
};
|
|
864
916
|
var RIGHTS_MODES = /* @__PURE__ */ new Set(["private", "users", "roles", "teams", "public"]);
|
|
865
917
|
var canManageShare = (row, user) => user.super_admin === true || row.created_by != null && String(row.created_by) === String(user.id);
|
|
866
918
|
var validateUpdateInput = (input, row, now) => {
|
|
@@ -909,15 +961,12 @@ var planShareUpdate = (input, row, newPasswordHash, now) => {
|
|
|
909
961
|
if (input.content_type !== void 0) patch.content_type = input.content_type;
|
|
910
962
|
patch.password_hash = mode === "password" ? newPasswordHash ?? row.password_hash : null;
|
|
911
963
|
if (input.expires_at !== void 0) patch.expires_at = input.expires_at;
|
|
912
|
-
|
|
913
|
-
patch.rights_mode = input.rights_mode ?? (row.auth_mode === "regular" ? row.rights_mode ?? "private" : "private");
|
|
914
|
-
} else {
|
|
915
|
-
patch.rights_mode = "public";
|
|
916
|
-
}
|
|
964
|
+
patch.rights_mode = resultingRightsMode(input, row);
|
|
917
965
|
if (input.agent_slots !== void 0) {
|
|
918
966
|
const slotsResult = validateAgentSlots(input.agent_slots);
|
|
919
967
|
if (slotsResult.ok) patch.agent_slots = slotsResult.slots;
|
|
920
968
|
}
|
|
969
|
+
if (typeof input.external_access === "boolean") patch.external_access = input.external_access;
|
|
921
970
|
return patch;
|
|
922
971
|
};
|
|
923
972
|
var hashSharePassword = (password) => bcrypt.hash(password, 10);
|
|
@@ -7803,7 +7852,11 @@ var applyAccessControl = (table, query, user, field_prefix) => {
|
|
|
7803
7852
|
);
|
|
7804
7853
|
return query.whereRaw("1 = 0");
|
|
7805
7854
|
}
|
|
7806
|
-
|
|
7855
|
+
const viaCompanion = user?.via_companion === true;
|
|
7856
|
+
if (viaCompanion && table.RBAC !== true) {
|
|
7857
|
+
return query.whereRaw("1 = 0");
|
|
7858
|
+
}
|
|
7859
|
+
if (!viaCompanion && table.name.plural !== "agent_sessions" && user?.super_admin === true) {
|
|
7807
7860
|
return query;
|
|
7808
7861
|
}
|
|
7809
7862
|
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")))) {
|
|
@@ -7819,16 +7872,20 @@ var applyAccessControl = (table, query, user, field_prefix) => {
|
|
|
7819
7872
|
if (!hasRBAC) {
|
|
7820
7873
|
return query;
|
|
7821
7874
|
}
|
|
7822
|
-
if (user?.super_admin) {
|
|
7875
|
+
if (!viaCompanion && user?.super_admin) {
|
|
7823
7876
|
return query;
|
|
7824
7877
|
}
|
|
7825
7878
|
const prefix = field_prefix ? field_prefix + "." : "";
|
|
7826
7879
|
console.log("[EXULU] applying access control with this prefix", prefix);
|
|
7827
7880
|
try {
|
|
7828
7881
|
query = query.where(function() {
|
|
7829
|
-
|
|
7882
|
+
if (!viaCompanion) {
|
|
7883
|
+
this.where(`${prefix}rights_mode`, "public");
|
|
7884
|
+
}
|
|
7830
7885
|
if (user) {
|
|
7831
|
-
|
|
7886
|
+
if (!viaCompanion) {
|
|
7887
|
+
this.orWhere(`${prefix}created_by`, user.id);
|
|
7888
|
+
}
|
|
7832
7889
|
this.orWhere(function() {
|
|
7833
7890
|
this.where(`${prefix}rights_mode`, "users").whereExists(function() {
|
|
7834
7891
|
this.select("*").from("rbac").whereRaw(
|
|
@@ -11658,6 +11715,9 @@ var sharedArtifactsSchema = {
|
|
|
11658
11715
|
// to protect. /settings and /panel are unaffected: both read row.agent_slots
|
|
11659
11716
|
// straight off the knex row, not through the generated GraphQL field.
|
|
11660
11717
|
{ name: "agent_slots", type: "json", hidden: true },
|
|
11718
|
+
// Released for the public companion server. Only meaningful for
|
|
11719
|
+
// auth_mode "regular" (validateExternalAccess). Not reported by /meta.
|
|
11720
|
+
{ name: "external_access", type: "boolean", default: false },
|
|
11661
11721
|
// Artifact library (2026-12): how a share presents itself and is found in
|
|
11662
11722
|
// the Artifacts screen. All optional, all additive — a database that never
|
|
11663
11723
|
// ran init-db for them reads them as absent, and every reader coerces.
|
|
@@ -12485,11 +12545,41 @@ function collectMemoryDecisions(messages) {
|
|
|
12485
12545
|
import { z as z13 } from "zod";
|
|
12486
12546
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
12487
12547
|
|
|
12548
|
+
// src/exulu/companion/write-grant.ts
|
|
12549
|
+
var idOf = (v) => {
|
|
12550
|
+
const id = typeof v === "object" && v !== null ? v.id : v;
|
|
12551
|
+
if (typeof id === "number") return id;
|
|
12552
|
+
if (typeof id === "string" && id !== "") return id;
|
|
12553
|
+
return void 0;
|
|
12554
|
+
};
|
|
12555
|
+
var hasCompanionWriteGrant = async (db, entity, id, user, rightsMode) => {
|
|
12556
|
+
let grantee;
|
|
12557
|
+
if (rightsMode === "users") {
|
|
12558
|
+
grantee = { access_type: "User", user_id: user.id };
|
|
12559
|
+
} else if (rightsMode === "roles") {
|
|
12560
|
+
const roleId = idOf(user.role);
|
|
12561
|
+
if (roleId === void 0) return false;
|
|
12562
|
+
grantee = { access_type: "Role", role_id: roleId };
|
|
12563
|
+
} else if (rightsMode === "teams") {
|
|
12564
|
+
const teamId = idOf(user.team);
|
|
12565
|
+
if (teamId === void 0) return false;
|
|
12566
|
+
grantee = { access_type: "Team", team_id: teamId };
|
|
12567
|
+
} else {
|
|
12568
|
+
return false;
|
|
12569
|
+
}
|
|
12570
|
+
const grant = await db.from("rbac").where({ entity, target_resource_id: id, rights: "write", ...grantee }).first();
|
|
12571
|
+
return !!grant;
|
|
12572
|
+
};
|
|
12573
|
+
|
|
12488
12574
|
// src/utils/check-item-write-access.ts
|
|
12489
12575
|
var checkItemWriteAccess = async (context, record, user) => {
|
|
12490
12576
|
if (!user) {
|
|
12491
12577
|
return false;
|
|
12492
12578
|
}
|
|
12579
|
+
if (user.via_companion === true) {
|
|
12580
|
+
const { db: db2 } = await postgresClient();
|
|
12581
|
+
return hasCompanionWriteGrant(db2, getTableName(context.id), record.id, user, record.rights_mode);
|
|
12582
|
+
}
|
|
12493
12583
|
if (user.super_admin === true) {
|
|
12494
12584
|
return true;
|
|
12495
12585
|
}
|
|
@@ -13327,7 +13417,7 @@ import { z as z14 } from "zod";
|
|
|
13327
13417
|
|
|
13328
13418
|
// src/exulu/project-access.ts
|
|
13329
13419
|
var sameEntityId = (a, b) => a != null && b != null && a !== "" && b !== "" && String(a) === String(b);
|
|
13330
|
-
var
|
|
13420
|
+
var idOf2 = (v) => typeof v === "object" && v ? v.id : v;
|
|
13331
13421
|
function hasProjectAccess(args) {
|
|
13332
13422
|
const { project, rbac, user, want } = args;
|
|
13333
13423
|
if (user.super_admin) return true;
|
|
@@ -13340,9 +13430,9 @@ function hasProjectAccess(args) {
|
|
|
13340
13430
|
case "users":
|
|
13341
13431
|
return granted(rbac.users, user.id);
|
|
13342
13432
|
case "roles":
|
|
13343
|
-
return granted(rbac.roles,
|
|
13433
|
+
return granted(rbac.roles, idOf2(user.role));
|
|
13344
13434
|
case "teams":
|
|
13345
|
-
return granted(rbac.teams,
|
|
13435
|
+
return granted(rbac.teams, idOf2(user.team));
|
|
13346
13436
|
default:
|
|
13347
13437
|
return false;
|
|
13348
13438
|
}
|
|
@@ -17958,103 +18048,6 @@ var createSessionFileReadTool = ({
|
|
|
17958
18048
|
import { z as z22 } from "zod";
|
|
17959
18049
|
import { extname as extname2 } from "path";
|
|
17960
18050
|
|
|
17961
|
-
// src/templates/tools/document-render-helpers.ts
|
|
17962
|
-
import { execFile as execFile2 } from "child_process";
|
|
17963
|
-
import { promisify as promisify4 } from "util";
|
|
17964
|
-
import { existsSync as existsSync5 } from "fs";
|
|
17965
|
-
import { mkdtemp, readdir as readdir3, readFile as readFile2, rm as rm3, writeFile as writeFile3 } from "fs/promises";
|
|
17966
|
-
import { tmpdir } from "os";
|
|
17967
|
-
import { join as join7 } from "path";
|
|
17968
|
-
var execFileAsync2 = promisify4(execFile2);
|
|
17969
|
-
var MAX_STDOUT_BYTES = 64 * 1024 * 1024;
|
|
17970
|
-
var LEGACY_OFFICE_CONVERSION_TARGETS = {
|
|
17971
|
-
".doc": "docx",
|
|
17972
|
-
".xls": "xlsx",
|
|
17973
|
-
".ppt": "pptx",
|
|
17974
|
-
".rtf": "docx"
|
|
17975
|
-
};
|
|
17976
|
-
function isLegacyOfficeFormat(ext) {
|
|
17977
|
-
return ext in LEGACY_OFFICE_CONVERSION_TARGETS;
|
|
17978
|
-
}
|
|
17979
|
-
async function convertLegacyOfficeToModern(bytes, ext) {
|
|
17980
|
-
const target = LEGACY_OFFICE_CONVERSION_TARGETS[ext];
|
|
17981
|
-
if (!target) {
|
|
17982
|
-
throw new Error(`No modern-format conversion target registered for "${ext}"`);
|
|
17983
|
-
}
|
|
17984
|
-
const dir = await mkdtemp(join7(tmpdir(), "exulu-officeconv-"));
|
|
17985
|
-
try {
|
|
17986
|
-
const inputPath = join7(dir, `input${ext}`);
|
|
17987
|
-
await writeFile3(inputPath, bytes);
|
|
17988
|
-
try {
|
|
17989
|
-
await execFileAsync2(
|
|
17990
|
-
"soffice",
|
|
17991
|
-
["--headless", "--convert-to", target, inputPath, "--outdir", dir],
|
|
17992
|
-
{ timeout: 6e4, maxBuffer: MAX_STDOUT_BYTES }
|
|
17993
|
-
);
|
|
17994
|
-
} catch (err3) {
|
|
17995
|
-
throw new Error(
|
|
17996
|
-
`LibreOffice could not convert the legacy "${ext}" file to ${target}: ` + (err3 instanceof Error ? err3.message : String(err3))
|
|
17997
|
-
);
|
|
17998
|
-
}
|
|
17999
|
-
const outputPath = join7(dir, `input.${target}`);
|
|
18000
|
-
if (!existsSync5(outputPath)) {
|
|
18001
|
-
throw new Error(`LibreOffice produced no output converting "${ext}" to ${target}`);
|
|
18002
|
-
}
|
|
18003
|
-
return await readFile2(outputPath);
|
|
18004
|
-
} finally {
|
|
18005
|
-
await rm3(dir, { recursive: true, force: true });
|
|
18006
|
-
}
|
|
18007
|
-
}
|
|
18008
|
-
async function pdfToText(pdf) {
|
|
18009
|
-
const dir = await mkdtemp(join7(tmpdir(), "exulu-parse-"));
|
|
18010
|
-
try {
|
|
18011
|
-
const inputPath = join7(dir, "input.pdf");
|
|
18012
|
-
await writeFile3(inputPath, pdf);
|
|
18013
|
-
const { stdout } = await execFileAsync2("pdftotext", ["-layout", inputPath, "-"], {
|
|
18014
|
-
timeout: 6e4,
|
|
18015
|
-
maxBuffer: MAX_STDOUT_BYTES
|
|
18016
|
-
});
|
|
18017
|
-
return stdout;
|
|
18018
|
-
} finally {
|
|
18019
|
-
await rm3(dir, { recursive: true, force: true });
|
|
18020
|
-
}
|
|
18021
|
-
}
|
|
18022
|
-
async function pdfPageCount(pdf) {
|
|
18023
|
-
const dir = await mkdtemp(join7(tmpdir(), "exulu-pdfinfo-"));
|
|
18024
|
-
try {
|
|
18025
|
-
const inputPath = join7(dir, "input.pdf");
|
|
18026
|
-
await writeFile3(inputPath, pdf);
|
|
18027
|
-
const { stdout } = await execFileAsync2("pdfinfo", [inputPath], { timeout: 3e4, maxBuffer: 1e6 });
|
|
18028
|
-
const match = /^Pages:\s+(\d+)/m.exec(stdout);
|
|
18029
|
-
if (!match) throw new Error("pdfinfo did not report a page count");
|
|
18030
|
-
return Number(match[1]);
|
|
18031
|
-
} finally {
|
|
18032
|
-
await rm3(dir, { recursive: true, force: true });
|
|
18033
|
-
}
|
|
18034
|
-
}
|
|
18035
|
-
async function renderPdfPageToPng(pdf, page, scaleTo) {
|
|
18036
|
-
const dir = await mkdtemp(join7(tmpdir(), "exulu-render-"));
|
|
18037
|
-
try {
|
|
18038
|
-
const inputPath = join7(dir, "input.pdf");
|
|
18039
|
-
await writeFile3(inputPath, pdf);
|
|
18040
|
-
try {
|
|
18041
|
-
await execFileAsync2(
|
|
18042
|
-
"pdftoppm",
|
|
18043
|
-
["-png", "-f", String(page), "-l", String(page), "-scale-to", String(scaleTo), inputPath, join7(dir, "page")],
|
|
18044
|
-
{ timeout: 6e4, maxBuffer: MAX_STDOUT_BYTES }
|
|
18045
|
-
);
|
|
18046
|
-
} catch (err3) {
|
|
18047
|
-
if (err3?.code === 99) return null;
|
|
18048
|
-
throw err3;
|
|
18049
|
-
}
|
|
18050
|
-
const produced = (await readdir3(dir)).find((f) => f.startsWith("page") && f.endsWith(".png"));
|
|
18051
|
-
if (!produced) return null;
|
|
18052
|
-
return await readFile2(join7(dir, produced));
|
|
18053
|
-
} finally {
|
|
18054
|
-
await rm3(dir, { recursive: true, force: true });
|
|
18055
|
-
}
|
|
18056
|
-
}
|
|
18057
|
-
|
|
18058
18051
|
// src/exulu/attachment-text.ts
|
|
18059
18052
|
var DEFAULT_ATTACHMENT_MAX_PAGES = 50;
|
|
18060
18053
|
function attachmentMaxPages(env = process.env) {
|
|
@@ -18074,7 +18067,7 @@ function tooLongForToolNotice(filename, pageCount, maxPages) {
|
|
|
18074
18067
|
return `[Document too long: "${filename}" has ${pageCount} pages, the limit for reading a document is ${maxPages} pages (EXULU_DOCUMENT_MAX_PAGES). The document was NOT read. Tell the user plainly and suggest splitting the file.]`;
|
|
18075
18068
|
}
|
|
18076
18069
|
var loadDocumentProcessor = async () => {
|
|
18077
|
-
const mod = await import("./doc_processor-
|
|
18070
|
+
const mod = await import("./doc_processor-SR7ZCECL.js");
|
|
18078
18071
|
return mod.documentProcessor;
|
|
18079
18072
|
};
|
|
18080
18073
|
function pagesToText(pages) {
|
|
@@ -18095,7 +18088,17 @@ function degradedPagesOf(result) {
|
|
|
18095
18088
|
var defaultOfficeParse = (bytes) => officeToText(bytes);
|
|
18096
18089
|
async function extractDocument(input) {
|
|
18097
18090
|
const config = input.exuluConfig?.attachments?.documentProcessor;
|
|
18091
|
+
const original = input;
|
|
18098
18092
|
if (config) {
|
|
18093
|
+
const ext = input.filename.slice(input.filename.lastIndexOf(".")).toLowerCase();
|
|
18094
|
+
if (isPresentationFormat(ext)) {
|
|
18095
|
+
try {
|
|
18096
|
+
const pdf = await (input.toPdf ?? convertOfficeToPdf)(input.bytes, ext);
|
|
18097
|
+
input = { ...input, bytes: pdf, filename: `${input.filename.slice(0, -ext.length)}.pdf` };
|
|
18098
|
+
} catch (error) {
|
|
18099
|
+
console.warn(`[EXULU] Could not render ${input.filename} to PDF:`, error instanceof Error ? error.message : String(error));
|
|
18100
|
+
}
|
|
18101
|
+
}
|
|
18099
18102
|
if (input.filename.toLowerCase().endsWith(".pdf")) {
|
|
18100
18103
|
const forTool = input.maxPages !== void 0;
|
|
18101
18104
|
const maxPages = input.maxPages ?? attachmentMaxPages();
|
|
@@ -18109,7 +18112,7 @@ async function extractDocument(input) {
|
|
|
18109
18112
|
console.warn(`[EXULU] ${input.filename} has ${pageCount} pages, over the ${forTool ? "document" : "attachment"} cap of ${maxPages}; not read.`);
|
|
18110
18113
|
return {
|
|
18111
18114
|
pages: [],
|
|
18112
|
-
text: (forTool ? tooLongForToolNotice : tooLongNotice)(
|
|
18115
|
+
text: (forTool ? tooLongForToolNotice : tooLongNotice)(original.filename, pageCount, maxPages),
|
|
18113
18116
|
engine: "document-processor",
|
|
18114
18117
|
tooLong: { pageCount, maxPages }
|
|
18115
18118
|
};
|
|
@@ -18145,7 +18148,7 @@ async function extractDocument(input) {
|
|
|
18145
18148
|
);
|
|
18146
18149
|
}
|
|
18147
18150
|
}
|
|
18148
|
-
const text = (await (input.officeParse ?? defaultOfficeParse)(
|
|
18151
|
+
const text = (await (input.officeParse ?? defaultOfficeParse)(original.bytes)).trim();
|
|
18149
18152
|
return { pages: [{ page: 1, text }], text, engine: "officeparser" };
|
|
18150
18153
|
}
|
|
18151
18154
|
var PROCESSOR_NAMES = /* @__PURE__ */ new Set(["liteparse", "mistral", "officeparser"]);
|
|
@@ -18642,14 +18645,14 @@ import { extname as extname4 } from "path";
|
|
|
18642
18645
|
|
|
18643
18646
|
// src/sessions/pdf-preview-cache.ts
|
|
18644
18647
|
import { exec as exec3 } from "child_process";
|
|
18645
|
-
import { existsSync as
|
|
18646
|
-
import { mkdir as mkdir5, readFile as
|
|
18647
|
-
import { extname as extname3, join as
|
|
18648
|
-
import { promisify as
|
|
18649
|
-
var execAsync3 =
|
|
18648
|
+
import { existsSync as existsSync5 } from "fs";
|
|
18649
|
+
import { mkdir as mkdir5, readFile as readFile2, rename as rename3, rm as rm3, writeFile as writeFile3 } from "fs/promises";
|
|
18650
|
+
import { extname as extname3, join as join7 } from "path";
|
|
18651
|
+
import { promisify as promisify4 } from "util";
|
|
18652
|
+
var execAsync3 = promisify4(exec3);
|
|
18650
18653
|
var CACHE_ROOT = "/tmp/exulu-pdf-cache";
|
|
18651
|
-
var CACHE_IN =
|
|
18652
|
-
var CACHE_OUT =
|
|
18654
|
+
var CACHE_IN = join7(CACHE_ROOT, "_in");
|
|
18655
|
+
var CACHE_OUT = join7(CACHE_ROOT, "_out");
|
|
18653
18656
|
var inFlight2 = /* @__PURE__ */ new Map();
|
|
18654
18657
|
var PreviewRenderError = class extends Error {
|
|
18655
18658
|
constructor(message) {
|
|
@@ -18666,9 +18669,9 @@ async function getPdfPreviewBytes(opts) {
|
|
|
18666
18669
|
if (!safeEtag) {
|
|
18667
18670
|
throw new PreviewRenderError(`Invalid ETag for ${sourceKey}`);
|
|
18668
18671
|
}
|
|
18669
|
-
const cachedPath =
|
|
18670
|
-
if (
|
|
18671
|
-
return
|
|
18672
|
+
const cachedPath = join7(CACHE_ROOT, `${safeEtag}.pdf`);
|
|
18673
|
+
if (existsSync5(cachedPath)) {
|
|
18674
|
+
return readFile2(cachedPath);
|
|
18672
18675
|
}
|
|
18673
18676
|
const existing = inFlight2.get(safeEtag);
|
|
18674
18677
|
if (existing) return existing;
|
|
@@ -18677,11 +18680,11 @@ async function getPdfPreviewBytes(opts) {
|
|
|
18677
18680
|
await mkdir5(CACHE_IN, { recursive: true });
|
|
18678
18681
|
await mkdir5(CACHE_OUT, { recursive: true });
|
|
18679
18682
|
const ext = (extname3(sourceKey) || ".docx").toLowerCase();
|
|
18680
|
-
const inputPath =
|
|
18681
|
-
const outputPath =
|
|
18683
|
+
const inputPath = join7(CACHE_IN, `${safeEtag}${ext}`);
|
|
18684
|
+
const outputPath = join7(CACHE_OUT, `${safeEtag}.pdf`);
|
|
18682
18685
|
try {
|
|
18683
18686
|
const bytes = await getS3ObjectBytes(sourceKey, config);
|
|
18684
|
-
await
|
|
18687
|
+
await writeFile3(inputPath, bytes);
|
|
18685
18688
|
try {
|
|
18686
18689
|
await execAsync3(
|
|
18687
18690
|
`soffice --headless --convert-to pdf "${inputPath}" --outdir "${CACHE_OUT}"`,
|
|
@@ -18692,15 +18695,15 @@ async function getPdfPreviewBytes(opts) {
|
|
|
18692
18695
|
`LibreOffice conversion failed for ${sourceKey} (etag ${etag}): ${err3?.stderr ?? err3?.message ?? "unknown error"}`
|
|
18693
18696
|
);
|
|
18694
18697
|
}
|
|
18695
|
-
if (!
|
|
18698
|
+
if (!existsSync5(outputPath)) {
|
|
18696
18699
|
throw new PreviewRenderError(
|
|
18697
18700
|
`LibreOffice produced no output for ${sourceKey} (etag ${etag})`
|
|
18698
18701
|
);
|
|
18699
18702
|
}
|
|
18700
18703
|
await rename3(outputPath, cachedPath);
|
|
18701
|
-
return await
|
|
18704
|
+
return await readFile2(cachedPath);
|
|
18702
18705
|
} finally {
|
|
18703
|
-
await
|
|
18706
|
+
await rm3(inputPath, { force: true });
|
|
18704
18707
|
}
|
|
18705
18708
|
} finally {
|
|
18706
18709
|
inFlight2.delete(safeEtag);
|
|
@@ -19618,6 +19621,13 @@ export {
|
|
|
19618
19621
|
isExpired,
|
|
19619
19622
|
validateCreateInput,
|
|
19620
19623
|
readAgentSlots,
|
|
19624
|
+
EXTERNAL_SUPER_ADMIN_ONLY,
|
|
19625
|
+
validateExternalAccess,
|
|
19626
|
+
mayChangeExternalRelease,
|
|
19627
|
+
teamNamesByIds,
|
|
19628
|
+
externalAccessCheckApplies,
|
|
19629
|
+
externalAccessNeedsTeams,
|
|
19630
|
+
validateExternalAccessUpdate,
|
|
19621
19631
|
canManageShare,
|
|
19622
19632
|
validateUpdateInput,
|
|
19623
19633
|
ownsObjectKey,
|
|
@@ -19653,6 +19663,7 @@ export {
|
|
|
19653
19663
|
buildMemoryPromptBlock,
|
|
19654
19664
|
normalizeRbac,
|
|
19655
19665
|
collectMemoryDecisions,
|
|
19666
|
+
hasCompanionWriteGrant,
|
|
19656
19667
|
PUBLIC_SURFACE_HEADER,
|
|
19657
19668
|
isPublicSurface,
|
|
19658
19669
|
treatAsGuest,
|
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
OUTPUT_OFFLOAD_EXEMPT_TOOL_IDS,
|
|
4
4
|
convertExuluToolsToAiSdkTools,
|
|
5
5
|
hydrateVariables
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-K7CGLUW4.js";
|
|
7
|
+
import "./chunk-BFIDSFRQ.js";
|
|
8
8
|
import "./chunk-F534XOQR.js";
|
|
9
9
|
import "./chunk-6URU62NI.js";
|
|
10
10
|
export {
|
|
@@ -2,9 +2,9 @@ import "dotenv/config";
|
|
|
2
2
|
import {
|
|
3
3
|
documentProcessor,
|
|
4
4
|
reconstructTableHeaders
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-DAVYWGEE.js";
|
|
6
6
|
import "./chunk-NJWNOXLJ.js";
|
|
7
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-BFIDSFRQ.js";
|
|
8
8
|
import "./chunk-6URU62NI.js";
|
|
9
9
|
export {
|
|
10
10
|
documentProcessor,
|