@exulu/backend 5.22.0 → 5.24.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.
@@ -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-43QIPMLT.js";
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-DAC4VCWO.js");
691
+ const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-RBKOADD7.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
- if (mode === "regular") {
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
- if (table.name.plural !== "agent_sessions" && user?.super_admin === true) {
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
- this.where(`${prefix}rights_mode`, "public");
7882
+ if (!viaCompanion) {
7883
+ this.where(`${prefix}rights_mode`, "public");
7884
+ }
7830
7885
  if (user) {
7831
- this.orWhere(`${prefix}created_by`, user.id);
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.
@@ -12206,13 +12266,14 @@ function createRecallCollector(context, user, db) {
12206
12266
  });
12207
12267
  }
12208
12268
  var cite = (s) => s.replace(/[{}",]/g, " ").replace(/\s+/g, " ").trim();
12269
+ function memoryPromptLine(m) {
12270
+ const who = m.createdBy ? `saved by ${m.createdBy.name}` : "saved earlier";
12271
+ const when = m.createdAt ? ` on ${m.createdAt.slice(0, 10)}` : "";
12272
+ return `- {item_name: "${cite(m.title)}", item_id: "${m.id}", context: "${m.contextId}"} ${m.information} (${who}${when}, ${m.rights_mode})`;
12273
+ }
12209
12274
  function buildMemoryPromptBlock(memories) {
12210
12275
  if (memories.length === 0) return "";
12211
- const lines = memories.map((m) => {
12212
- const who = m.createdBy ? `saved by ${m.createdBy.name}` : "saved earlier";
12213
- const when = m.createdAt ? ` on ${m.createdAt.slice(0, 10)}` : "";
12214
- return `- {item_name: "${cite(m.title)}", item_id: "${m.id}", context: "${m.contextId}"} ${m.information} (${who}${when}, ${m.rights_mode})`;
12215
- });
12276
+ const lines = memories.map(memoryPromptLine);
12216
12277
  return [
12217
12278
  "Memories: facts people saved earlier for this assistant. Use them where relevant and cite each memory you rely on",
12218
12279
  "with its citation object exactly as given, e.g. {item_name: <title>, item_id: <id>, context: <contextId>}",
@@ -12485,11 +12546,41 @@ function collectMemoryDecisions(messages) {
12485
12546
  import { z as z13 } from "zod";
12486
12547
  import { randomUUID as randomUUID3 } from "crypto";
12487
12548
 
12549
+ // src/exulu/companion/write-grant.ts
12550
+ var idOf = (v) => {
12551
+ const id = typeof v === "object" && v !== null ? v.id : v;
12552
+ if (typeof id === "number") return id;
12553
+ if (typeof id === "string" && id !== "") return id;
12554
+ return void 0;
12555
+ };
12556
+ var hasCompanionWriteGrant = async (db, entity, id, user, rightsMode) => {
12557
+ let grantee;
12558
+ if (rightsMode === "users") {
12559
+ grantee = { access_type: "User", user_id: user.id };
12560
+ } else if (rightsMode === "roles") {
12561
+ const roleId = idOf(user.role);
12562
+ if (roleId === void 0) return false;
12563
+ grantee = { access_type: "Role", role_id: roleId };
12564
+ } else if (rightsMode === "teams") {
12565
+ const teamId = idOf(user.team);
12566
+ if (teamId === void 0) return false;
12567
+ grantee = { access_type: "Team", team_id: teamId };
12568
+ } else {
12569
+ return false;
12570
+ }
12571
+ const grant = await db.from("rbac").where({ entity, target_resource_id: id, rights: "write", ...grantee }).first();
12572
+ return !!grant;
12573
+ };
12574
+
12488
12575
  // src/utils/check-item-write-access.ts
12489
12576
  var checkItemWriteAccess = async (context, record, user) => {
12490
12577
  if (!user) {
12491
12578
  return false;
12492
12579
  }
12580
+ if (user.via_companion === true) {
12581
+ const { db: db2 } = await postgresClient();
12582
+ return hasCompanionWriteGrant(db2, getTableName(context.id), record.id, user, record.rights_mode);
12583
+ }
12493
12584
  if (user.super_admin === true) {
12494
12585
  return true;
12495
12586
  }
@@ -13327,7 +13418,7 @@ import { z as z14 } from "zod";
13327
13418
 
13328
13419
  // src/exulu/project-access.ts
13329
13420
  var sameEntityId = (a, b) => a != null && b != null && a !== "" && b !== "" && String(a) === String(b);
13330
- var idOf = (v) => typeof v === "object" && v ? v.id : v;
13421
+ var idOf2 = (v) => typeof v === "object" && v ? v.id : v;
13331
13422
  function hasProjectAccess(args) {
13332
13423
  const { project, rbac, user, want } = args;
13333
13424
  if (user.super_admin) return true;
@@ -13340,9 +13431,9 @@ function hasProjectAccess(args) {
13340
13431
  case "users":
13341
13432
  return granted(rbac.users, user.id);
13342
13433
  case "roles":
13343
- return granted(rbac.roles, idOf(user.role));
13434
+ return granted(rbac.roles, idOf2(user.role));
13344
13435
  case "teams":
13345
- return granted(rbac.teams, idOf(user.team));
13436
+ return granted(rbac.teams, idOf2(user.team));
13346
13437
  default:
13347
13438
  return false;
13348
13439
  }
@@ -17958,103 +18049,6 @@ var createSessionFileReadTool = ({
17958
18049
  import { z as z22 } from "zod";
17959
18050
  import { extname as extname2 } from "path";
17960
18051
 
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
18052
  // src/exulu/attachment-text.ts
18059
18053
  var DEFAULT_ATTACHMENT_MAX_PAGES = 50;
18060
18054
  function attachmentMaxPages(env = process.env) {
@@ -18074,7 +18068,7 @@ function tooLongForToolNotice(filename, pageCount, maxPages) {
18074
18068
  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
18069
  }
18076
18070
  var loadDocumentProcessor = async () => {
18077
- const mod = await import("./doc_processor-VCFQZ5WI.js");
18071
+ const mod = await import("./doc_processor-SR7ZCECL.js");
18078
18072
  return mod.documentProcessor;
18079
18073
  };
18080
18074
  function pagesToText(pages) {
@@ -18095,7 +18089,17 @@ function degradedPagesOf(result) {
18095
18089
  var defaultOfficeParse = (bytes) => officeToText(bytes);
18096
18090
  async function extractDocument(input) {
18097
18091
  const config = input.exuluConfig?.attachments?.documentProcessor;
18092
+ const original = input;
18098
18093
  if (config) {
18094
+ const ext = input.filename.slice(input.filename.lastIndexOf(".")).toLowerCase();
18095
+ if (isPresentationFormat(ext)) {
18096
+ try {
18097
+ const pdf = await (input.toPdf ?? convertOfficeToPdf)(input.bytes, ext);
18098
+ input = { ...input, bytes: pdf, filename: `${input.filename.slice(0, -ext.length)}.pdf` };
18099
+ } catch (error) {
18100
+ console.warn(`[EXULU] Could not render ${input.filename} to PDF:`, error instanceof Error ? error.message : String(error));
18101
+ }
18102
+ }
18099
18103
  if (input.filename.toLowerCase().endsWith(".pdf")) {
18100
18104
  const forTool = input.maxPages !== void 0;
18101
18105
  const maxPages = input.maxPages ?? attachmentMaxPages();
@@ -18109,7 +18113,7 @@ async function extractDocument(input) {
18109
18113
  console.warn(`[EXULU] ${input.filename} has ${pageCount} pages, over the ${forTool ? "document" : "attachment"} cap of ${maxPages}; not read.`);
18110
18114
  return {
18111
18115
  pages: [],
18112
- text: (forTool ? tooLongForToolNotice : tooLongNotice)(input.filename, pageCount, maxPages),
18116
+ text: (forTool ? tooLongForToolNotice : tooLongNotice)(original.filename, pageCount, maxPages),
18113
18117
  engine: "document-processor",
18114
18118
  tooLong: { pageCount, maxPages }
18115
18119
  };
@@ -18145,7 +18149,7 @@ async function extractDocument(input) {
18145
18149
  );
18146
18150
  }
18147
18151
  }
18148
- const text = (await (input.officeParse ?? defaultOfficeParse)(input.bytes)).trim();
18152
+ const text = (await (input.officeParse ?? defaultOfficeParse)(original.bytes)).trim();
18149
18153
  return { pages: [{ page: 1, text }], text, engine: "officeparser" };
18150
18154
  }
18151
18155
  var PROCESSOR_NAMES = /* @__PURE__ */ new Set(["liteparse", "mistral", "officeparser"]);
@@ -18642,14 +18646,14 @@ import { extname as extname4 } from "path";
18642
18646
 
18643
18647
  // src/sessions/pdf-preview-cache.ts
18644
18648
  import { exec as exec3 } from "child_process";
18645
- import { existsSync as existsSync6 } from "fs";
18646
- import { mkdir as mkdir5, readFile as readFile3, rename as rename3, rm as rm4, writeFile as writeFile4 } from "fs/promises";
18647
- import { extname as extname3, join as join8 } from "path";
18648
- import { promisify as promisify5 } from "util";
18649
- var execAsync3 = promisify5(exec3);
18649
+ import { existsSync as existsSync5 } from "fs";
18650
+ import { mkdir as mkdir5, readFile as readFile2, rename as rename3, rm as rm3, writeFile as writeFile3 } from "fs/promises";
18651
+ import { extname as extname3, join as join7 } from "path";
18652
+ import { promisify as promisify4 } from "util";
18653
+ var execAsync3 = promisify4(exec3);
18650
18654
  var CACHE_ROOT = "/tmp/exulu-pdf-cache";
18651
- var CACHE_IN = join8(CACHE_ROOT, "_in");
18652
- var CACHE_OUT = join8(CACHE_ROOT, "_out");
18655
+ var CACHE_IN = join7(CACHE_ROOT, "_in");
18656
+ var CACHE_OUT = join7(CACHE_ROOT, "_out");
18653
18657
  var inFlight2 = /* @__PURE__ */ new Map();
18654
18658
  var PreviewRenderError = class extends Error {
18655
18659
  constructor(message) {
@@ -18666,9 +18670,9 @@ async function getPdfPreviewBytes(opts) {
18666
18670
  if (!safeEtag) {
18667
18671
  throw new PreviewRenderError(`Invalid ETag for ${sourceKey}`);
18668
18672
  }
18669
- const cachedPath = join8(CACHE_ROOT, `${safeEtag}.pdf`);
18670
- if (existsSync6(cachedPath)) {
18671
- return readFile3(cachedPath);
18673
+ const cachedPath = join7(CACHE_ROOT, `${safeEtag}.pdf`);
18674
+ if (existsSync5(cachedPath)) {
18675
+ return readFile2(cachedPath);
18672
18676
  }
18673
18677
  const existing = inFlight2.get(safeEtag);
18674
18678
  if (existing) return existing;
@@ -18677,11 +18681,11 @@ async function getPdfPreviewBytes(opts) {
18677
18681
  await mkdir5(CACHE_IN, { recursive: true });
18678
18682
  await mkdir5(CACHE_OUT, { recursive: true });
18679
18683
  const ext = (extname3(sourceKey) || ".docx").toLowerCase();
18680
- const inputPath = join8(CACHE_IN, `${safeEtag}${ext}`);
18681
- const outputPath = join8(CACHE_OUT, `${safeEtag}.pdf`);
18684
+ const inputPath = join7(CACHE_IN, `${safeEtag}${ext}`);
18685
+ const outputPath = join7(CACHE_OUT, `${safeEtag}.pdf`);
18682
18686
  try {
18683
18687
  const bytes = await getS3ObjectBytes(sourceKey, config);
18684
- await writeFile4(inputPath, bytes);
18688
+ await writeFile3(inputPath, bytes);
18685
18689
  try {
18686
18690
  await execAsync3(
18687
18691
  `soffice --headless --convert-to pdf "${inputPath}" --outdir "${CACHE_OUT}"`,
@@ -18692,15 +18696,15 @@ async function getPdfPreviewBytes(opts) {
18692
18696
  `LibreOffice conversion failed for ${sourceKey} (etag ${etag}): ${err3?.stderr ?? err3?.message ?? "unknown error"}`
18693
18697
  );
18694
18698
  }
18695
- if (!existsSync6(outputPath)) {
18699
+ if (!existsSync5(outputPath)) {
18696
18700
  throw new PreviewRenderError(
18697
18701
  `LibreOffice produced no output for ${sourceKey} (etag ${etag})`
18698
18702
  );
18699
18703
  }
18700
18704
  await rename3(outputPath, cachedPath);
18701
- return await readFile3(cachedPath);
18705
+ return await readFile2(cachedPath);
18702
18706
  } finally {
18703
- await rm4(inputPath, { force: true });
18707
+ await rm3(inputPath, { force: true });
18704
18708
  }
18705
18709
  } finally {
18706
18710
  inFlight2.delete(safeEtag);
@@ -19618,6 +19622,13 @@ export {
19618
19622
  isExpired,
19619
19623
  validateCreateInput,
19620
19624
  readAgentSlots,
19625
+ EXTERNAL_SUPER_ADMIN_ONLY,
19626
+ validateExternalAccess,
19627
+ mayChangeExternalRelease,
19628
+ teamNamesByIds,
19629
+ externalAccessCheckApplies,
19630
+ externalAccessNeedsTeams,
19631
+ validateExternalAccessUpdate,
19621
19632
  canManageShare,
19622
19633
  validateUpdateInput,
19623
19634
  ownsObjectKey,
@@ -19650,9 +19661,11 @@ export {
19650
19661
  canEditMemory,
19651
19662
  displayName,
19652
19663
  createRecallCollector,
19664
+ memoryPromptLine,
19653
19665
  buildMemoryPromptBlock,
19654
19666
  normalizeRbac,
19655
19667
  collectMemoryDecisions,
19668
+ hasCompanionWriteGrant,
19656
19669
  PUBLIC_SURFACE_HEADER,
19657
19670
  isPublicSurface,
19658
19671
  treatAsGuest,
@@ -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-43QIPMLT.js";
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())) {
@@ -3,8 +3,8 @@ import {
3
3
  OUTPUT_OFFLOAD_EXEMPT_TOOL_IDS,
4
4
  convertExuluToolsToAiSdkTools,
5
5
  hydrateVariables
6
- } from "./chunk-6OAYOFEY.js";
7
- import "./chunk-43QIPMLT.js";
6
+ } from "./chunk-6HADZYCD.js";
7
+ import "./chunk-BFIDSFRQ.js";
8
8
  import "./chunk-F534XOQR.js";
9
9
  import "./chunk-6URU62NI.js";
10
10
  export {