@exulu/backend 5.2.0 → 5.4.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.
@@ -1723,7 +1723,7 @@ var ExuluTool = class _ExuluTool {
1723
1723
  if (!agent) {
1724
1724
  throw new Error("Agent not found.");
1725
1725
  }
1726
- const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-MFLZQONB.js");
1726
+ const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-437EHCSN.js");
1727
1727
  const tools = await convertExuluToolsToAiSdkTools2(
1728
1728
  [this],
1729
1729
  [],
@@ -10563,6 +10563,14 @@ var usersSchema = {
10563
10563
  name: "favourite_items",
10564
10564
  type: "json"
10565
10565
  },
10566
+ {
10567
+ // Artifacts (2026-10): the shared artifacts a user starred, as a JSON
10568
+ // array of share names — mirrors favourite_projects. Auto-added to
10569
+ // existing DBs by the init-exulu-db column sync; read via userById,
10570
+ // written via usersUpdateOne.
10571
+ name: "favourite_artifacts",
10572
+ type: "json"
10573
+ },
10566
10574
  {
10567
10575
  // Knowledge: per-user "recently viewed" data items. Ordered JSON array
10568
10576
  // of global item ids ("<contextId>/<itemId>"), most-recent first, capped
@@ -11041,6 +11049,10 @@ var sharedArtifactsSchema = {
11041
11049
  // RBAC drives the "regular" auth_mode: rights_mode + the rbac table scope
11042
11050
  // who may view. public/password modes ignore rights_mode.
11043
11051
  RBAC: true,
11052
+ // Generic GraphQL writes are super-admin only: public/password shares carry
11053
+ // rights_mode "public", which the generic write check reads as "anyone may
11054
+ // edit". Creators change their shares through PATCH /shared-artifacts/:name.
11055
+ apiWrites: "super_admin",
11044
11056
  fields: [
11045
11057
  { name: "name", type: "text", index: true, unique: true, required: true },
11046
11058
  { name: "s3key", type: "text", required: true },
@@ -13098,6 +13110,16 @@ var getAllExuluVariables = async () => {
13098
13110
  return { granted, withheldNames: deriveWithheldNames(rows, granted) };
13099
13111
  };
13100
13112
  var execAsync2 = promisify2(exec2);
13113
+ var backendSecretFiles = () => {
13114
+ const cwd = process.cwd();
13115
+ const names = [".env", ".env.local", ".env.production", ".env.production.local"];
13116
+ const paths = /* @__PURE__ */ new Set();
13117
+ for (const name of names) {
13118
+ paths.add(join2(cwd, name));
13119
+ paths.add(join2("/app", name));
13120
+ }
13121
+ return [...paths];
13122
+ };
13101
13123
  var EXEC_MAX_BUFFER = 32 * 1024 * 1024;
13102
13124
  var litellmSecretNamesCache;
13103
13125
  var litellmConfigSecretNames = () => {
@@ -13354,7 +13376,12 @@ Probe error: ${probe.reason ?? "(no detail)"}`
13354
13376
  // todo
13355
13377
  },
13356
13378
  filesystem: {
13357
- denyRead: ["~"],
13379
+ // The backend's own dotenv file sits under the process cwd (and
13380
+ // /app in the shipped image); a bash command could otherwise
13381
+ // `cat` the database password out of it (seen in an ALGI session
13382
+ // 2026-10-07). Deny it explicitly — the rest of the tree stays
13383
+ // readable for node_modules / skill assets.
13384
+ denyRead: ["~", ...backendSecretFiles()],
13358
13385
  allowRead: [
13359
13386
  sessionDir,
13360
13387
  // Allow Node to read globally-installed packages from inside
@@ -3,7 +3,7 @@ import {
3
3
  OUTPUT_OFFLOAD_EXEMPT_TOOL_IDS,
4
4
  convertExuluToolsToAiSdkTools,
5
5
  hydrateVariables
6
- } from "./chunk-ASF74XFZ.js";
6
+ } from "./chunk-CWSP2WOQ.js";
7
7
  import "./chunk-4PDWNVNT.js";
8
8
  export {
9
9
  OUTPUT_OFFLOAD_EXEMPT_TOOL_IDS,
package/dist/index.cjs CHANGED
@@ -5206,6 +5206,14 @@ var init_core_schema = __esm({
5206
5206
  name: "favourite_items",
5207
5207
  type: "json"
5208
5208
  },
5209
+ {
5210
+ // Artifacts (2026-10): the shared artifacts a user starred, as a JSON
5211
+ // array of share names — mirrors favourite_projects. Auto-added to
5212
+ // existing DBs by the init-exulu-db column sync; read via userById,
5213
+ // written via usersUpdateOne.
5214
+ name: "favourite_artifacts",
5215
+ type: "json"
5216
+ },
5209
5217
  {
5210
5218
  // Knowledge: per-user "recently viewed" data items. Ordered JSON array
5211
5219
  // of global item ids ("<contextId>/<itemId>"), most-recent first, capped
@@ -5670,6 +5678,10 @@ var init_core_schema = __esm({
5670
5678
  // RBAC drives the "regular" auth_mode: rights_mode + the rbac table scope
5671
5679
  // who may view. public/password modes ignore rights_mode.
5672
5680
  RBAC: true,
5681
+ // Generic GraphQL writes are super-admin only: public/password shares carry
5682
+ // rights_mode "public", which the generic write check reads as "anyone may
5683
+ // edit". Creators change their shares through PATCH /shared-artifacts/:name.
5684
+ apiWrites: "super_admin",
5673
5685
  fields: [
5674
5686
  { name: "name", type: "text", index: true, unique: true, required: true },
5675
5687
  { name: "s3key", type: "text", required: true },
@@ -11589,7 +11601,12 @@ Probe error: ${probe.reason ?? "(no detail)"}`
11589
11601
  // todo
11590
11602
  },
11591
11603
  filesystem: {
11592
- denyRead: ["~"],
11604
+ // The backend's own dotenv file sits under the process cwd (and
11605
+ // /app in the shipped image); a bash command could otherwise
11606
+ // `cat` the database password out of it (seen in an ALGI session
11607
+ // 2026-10-07). Deny it explicitly — the rest of the tree stays
11608
+ // readable for node_modules / skill assets.
11609
+ denyRead: ["~", ...backendSecretFiles()],
11593
11610
  allowRead: [
11594
11611
  sessionDir,
11595
11612
  // Allow Node to read globally-installed packages from inside
@@ -11912,7 +11929,7 @@ ${lines.join("\n")}`;
11912
11929
  sandboxCache.set(sessionId, { handle, installedSkills });
11913
11930
  return handle;
11914
11931
  }
11915
- var import_sandbox_runtime, import_promises2, import_node_fs6, import_node_path5, import_node_child_process4, import_node_util3, import_bash_tool, import_ai2, import_zod6, import_crypto_js3, getAllExuluVariables, execAsync3, EXEC_MAX_BUFFER, litellmSecretNamesCache, litellmConfigSecretNames, sandboxProbePromise, SANDBOX_FALLBACK_INSTRUCTIONS, degradedModeLogged, sandboxCache;
11932
+ var import_sandbox_runtime, import_promises2, import_node_fs6, import_node_path5, import_node_child_process4, import_node_util3, import_bash_tool, import_ai2, import_zod6, import_crypto_js3, getAllExuluVariables, execAsync3, backendSecretFiles, EXEC_MAX_BUFFER, litellmSecretNamesCache, litellmConfigSecretNames, sandboxProbePromise, SANDBOX_FALLBACK_INSTRUCTIONS, degradedModeLogged, sandboxCache;
11916
11933
  var init_create_sandbox = __esm({
11917
11934
  "ee/invoke-skills/create-sandbox.ts"() {
11918
11935
  "use strict";
@@ -11961,6 +11978,16 @@ var init_create_sandbox = __esm({
11961
11978
  return { granted, withheldNames: deriveWithheldNames(rows, granted) };
11962
11979
  };
11963
11980
  execAsync3 = (0, import_node_util3.promisify)(import_node_child_process4.exec);
11981
+ backendSecretFiles = () => {
11982
+ const cwd = process.cwd();
11983
+ const names = [".env", ".env.local", ".env.production", ".env.production.local"];
11984
+ const paths = /* @__PURE__ */ new Set();
11985
+ for (const name of names) {
11986
+ paths.add((0, import_node_path5.join)(cwd, name));
11987
+ paths.add((0, import_node_path5.join)("/app", name));
11988
+ }
11989
+ return [...paths];
11990
+ };
11964
11991
  EXEC_MAX_BUFFER = 32 * 1024 * 1024;
11965
11992
  litellmConfigSecretNames = () => {
11966
11993
  if (litellmSecretNamesCache === void 0) {
@@ -18412,6 +18439,44 @@ var validateCreateInput = (input, now) => {
18412
18439
  }
18413
18440
  return { ok: true };
18414
18441
  };
18442
+ var RIGHTS_MODES = /* @__PURE__ */ new Set(["private", "users", "roles", "teams", "public"]);
18443
+ var canManageShare = (row, user) => user.super_admin === true || row.created_by != null && String(row.created_by) === String(user.id);
18444
+ var validateUpdateInput = (input, row, now) => {
18445
+ if (input.name !== void 0 && !slugifyShareName(input.name)) {
18446
+ return { ok: false, message: "name must contain url-safe characters." };
18447
+ }
18448
+ const mode = input.auth_mode ?? row.auth_mode;
18449
+ if (mode !== "public" && mode !== "password" && mode !== "regular") {
18450
+ return { ok: false, message: "auth_mode must be public, password, or regular." };
18451
+ }
18452
+ const keepsPassword = row.auth_mode === "password" && !!row.password_hash;
18453
+ if (mode === "password" && !input.password && !keepsPassword) {
18454
+ return { ok: false, message: "A password is required for password mode." };
18455
+ }
18456
+ if (input.expires_at && Number.isNaN(new Date(input.expires_at).getTime())) {
18457
+ return { ok: false, message: "expires_at is not a valid date." };
18458
+ }
18459
+ if (input.expires_at && isExpired(input.expires_at, now)) {
18460
+ return { ok: false, message: "expires_at must be in the future." };
18461
+ }
18462
+ if (input.rights_mode !== void 0 && !RIGHTS_MODES.has(input.rights_mode)) {
18463
+ return { ok: false, message: "rights_mode must be private, users, roles, teams, or public." };
18464
+ }
18465
+ return { ok: true };
18466
+ };
18467
+ var planShareUpdate = (input, row, newPasswordHash, now) => {
18468
+ const mode = input.auth_mode ?? row.auth_mode;
18469
+ const patch = { auth_mode: mode, updatedAt: now };
18470
+ if (input.name !== void 0) patch.name = slugifyShareName(input.name);
18471
+ patch.password_hash = mode === "password" ? newPasswordHash ?? row.password_hash : null;
18472
+ if (input.expires_at !== void 0) patch.expires_at = input.expires_at;
18473
+ if (mode === "regular") {
18474
+ patch.rights_mode = input.rights_mode ?? (row.auth_mode === "regular" ? row.rights_mode ?? "private" : "private");
18475
+ } else {
18476
+ patch.rights_mode = "public";
18477
+ }
18478
+ return patch;
18479
+ };
18415
18480
  var hashSharePassword = (password) => import_bcryptjs3.default.hash(password, 10);
18416
18481
  var verifySharePassword = (password, hash) => import_bcryptjs3.default.compare(password, hash);
18417
18482
  var contentHeadersFor = (key, contentType, filename) => {
@@ -19829,6 +19894,28 @@ function createMutations(table, contexts, tools, config) {
19829
19894
  await saveTranscriptsSettings(parseSettingsInput(args.input));
19830
19895
  return buildTranscriptsSettingsInfo();
19831
19896
  };
19897
+ if (table.apiWrites === "super_admin") {
19898
+ for (const key of [
19899
+ `${tableNamePlural}CreateOne`,
19900
+ `${tableNamePlural}CopyOneById`,
19901
+ `${tableNamePlural}UpdateOne`,
19902
+ `${tableNamePlural}UpdateOneById`,
19903
+ `${tableNamePlural}RemoveOneById`,
19904
+ `${tableNamePlural}RemoveOne`,
19905
+ `${tableNamePlural}BulkUpdateRBAC`
19906
+ ]) {
19907
+ const inner = mutations[key];
19908
+ if (!inner) continue;
19909
+ mutations[key] = async (parent, args, context, info) => {
19910
+ if (context?.user?.super_admin !== true) {
19911
+ throw new Error(
19912
+ `${table.name.plural} rows are changed through their own API; the generic mutation is reserved for super admins.`
19913
+ );
19914
+ }
19915
+ return inner(parent, args, context, info);
19916
+ };
19917
+ }
19918
+ }
19832
19919
  return mutations;
19833
19920
  }
19834
19921
 
@@ -21448,6 +21535,27 @@ init_storage();
21448
21535
  init_context();
21449
21536
  init_hydrate_embedders();
21450
21537
  init_resolve_model();
21538
+
21539
+ // src/exulu/resolve-context-window.ts
21540
+ init_cjs_shims();
21541
+ init_catalog();
21542
+ init_context_budget();
21543
+ var resolveContextWindow = async ({
21544
+ modelId
21545
+ }) => {
21546
+ if (process.env.EXULU_USE_LITELLM !== "true") {
21547
+ throw new Error("Litellm not configured.");
21548
+ }
21549
+ const entry = await findLiteLLMModel(modelId);
21550
+ const fromCatalog = entry?.max_input_tokens ?? entry?.max_tokens;
21551
+ if (fromCatalog != null && fromCatalog > 0) return fromCatalog;
21552
+ console.warn(
21553
+ `[EXULU] Unknown context window for model "${modelId}" \u2014 assuming ${DEFAULT_CONTEXT_WINDOW}. Check the LiteLLM catalog / provider template metadata.`
21554
+ );
21555
+ return DEFAULT_CONTEXT_WINDOW;
21556
+ };
21557
+
21558
+ // ee/workers.ts
21451
21559
  init_client();
21452
21560
  init_prune_job_results();
21453
21561
  var import_api = require("@opentelemetry/api");
@@ -21737,7 +21845,12 @@ var workflowRunLabel = (workflowId) => `workflow-run-${workflowId}`;
21737
21845
  var baseTriggerMetadata = (email) => ({
21738
21846
  from: email.from.address,
21739
21847
  subject: email.subject,
21740
- message_id: email.messageId
21848
+ message_id: email.messageId,
21849
+ attachments: email.attachments.map((attachment) => ({
21850
+ filename: attachment.filename,
21851
+ content_type: attachment.contentType,
21852
+ size: attachment.content?.length ?? 0
21853
+ }))
21741
21854
  });
21742
21855
  var resolveTriggerBySecret = async (db2, secret) => db2.from("workflow_triggers").where({ secret }).first();
21743
21856
  var resolveTriggerById = async (db2, triggerId) => db2.from("workflow_triggers").where({ id: triggerId }).first();
@@ -23099,6 +23212,12 @@ var processUiMessagesFlow = async ({
23099
23212
  routine
23100
23213
  });
23101
23214
  const resolvedLanguageModel = resolved.languageModel;
23215
+ let contextWindow;
23216
+ try {
23217
+ contextWindow = await resolveContextWindow({ modelId: resolved.model.id });
23218
+ } catch (err2) {
23219
+ console.warn(`[EXULU] Could not resolve the context window for routine model "${resolved.model.id}"; using the default.`, err2);
23220
+ }
23102
23221
  const messagesWithoutPlaceholder = inputMessages.filter(
23103
23222
  (message) => message.metadata?.type !== "placeholder"
23104
23223
  );
@@ -23162,7 +23281,8 @@ var processUiMessagesFlow = async ({
23162
23281
  allExuluTools: tools,
23163
23282
  languageModel: resolvedLanguageModel,
23164
23283
  toolConfigs: agent.tools,
23165
- exuluConfig: config
23284
+ exuluConfig: config,
23285
+ contextWindow
23166
23286
  });
23167
23287
  console.log("[EXULU] consuming stream for agent.");
23168
23288
  const stream = result.stream.toUIMessageStream({
@@ -29134,27 +29254,6 @@ ${SUGGESTIONS_SYSTEM_PROMPT}` : SUGGESTIONS_SYSTEM_PROMPT;
29134
29254
  // src/exulu/routes.ts
29135
29255
  init_resolve_model();
29136
29256
  init_supervisor();
29137
-
29138
- // src/exulu/resolve-context-window.ts
29139
- init_cjs_shims();
29140
- init_catalog();
29141
- init_context_budget();
29142
- var resolveContextWindow = async ({
29143
- modelId
29144
- }) => {
29145
- if (process.env.EXULU_USE_LITELLM !== "true") {
29146
- throw new Error("Litellm not configured.");
29147
- }
29148
- const entry = await findLiteLLMModel(modelId);
29149
- const fromCatalog = entry?.max_input_tokens ?? entry?.max_tokens;
29150
- if (fromCatalog != null && fromCatalog > 0) return fromCatalog;
29151
- console.warn(
29152
- `[EXULU] Unknown context window for model "${modelId}" \u2014 assuming ${DEFAULT_CONTEXT_WINDOW}. Check the LiteLLM catalog / provider template metadata.`
29153
- );
29154
- return DEFAULT_CONTEXT_WINDOW;
29155
- };
29156
-
29157
- // src/exulu/routes.ts
29158
29257
  init_context_budget();
29159
29258
 
29160
29259
  // src/exulu/compact-session.ts
@@ -33037,7 +33136,8 @@ var {
33037
33136
  entityTypeSettingsSchema: entityTypeSettingsSchema2,
33038
33137
  promptFavoritesSchema: promptFavoritesSchema2,
33039
33138
  statisticsSchema: statisticsSchema2,
33040
- transcriptionJobsSchema: transcriptionJobsSchema2
33139
+ transcriptionJobsSchema: transcriptionJobsSchema2,
33140
+ sharedArtifactsSchema: sharedArtifactsSchema2
33041
33141
  } = coreSchemas.get();
33042
33142
  var claimCheckLimiter = claimCheckRateLimiter();
33043
33143
  var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) => {
@@ -33108,7 +33208,13 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
33108
33208
  workflowTemplatesSchema2(),
33109
33209
  statisticsSchema2(),
33110
33210
  rbacSchema2(),
33111
- transcriptionJobsSchema2()
33211
+ transcriptionJobsSchema2(),
33212
+ // Shared artifacts (2026-10): listed and favourited from the IMP's
33213
+ // Artifacts page through the generated operations. The table carries
33214
+ // RBAC, so the generic access control applies (public, own, shared with
33215
+ // me / my role / my team); `password_hash` is hidden and never leaves
33216
+ // the resolvers. The bytes still come from /shared-artifacts/:name/content.
33217
+ sharedArtifactsSchema2()
33112
33218
  ],
33113
33219
  contexts ?? [],
33114
33220
  tools,
@@ -36613,7 +36719,7 @@ ${style.markdown}` : params.prompt;
36613
36719
  res.status(404).json({ detail: "Not found." });
36614
36720
  return;
36615
36721
  }
36616
- if (row.created_by !== auth.user.id) {
36722
+ if (!canManageShare(row, auth.user)) {
36617
36723
  res.status(403).json({ detail: "You can only delete your own share links." });
36618
36724
  return;
36619
36725
  }
@@ -36621,6 +36727,85 @@ ${style.markdown}` : params.prompt;
36621
36727
  await db2("shared_artifacts").where({ id: row.id }).delete();
36622
36728
  res.status(204).end();
36623
36729
  });
36730
+ app.get("/shared-artifacts/:name/settings", async (req, res) => {
36731
+ const { db: db2 } = await postgresClient();
36732
+ const auth = await requestValidators.authenticate(req);
36733
+ if (!auth.user?.id) {
36734
+ res.status(401).json({ detail: "Authentication required." });
36735
+ return;
36736
+ }
36737
+ const row = await getSharedArtifactByName(db2, req.params.name ?? "");
36738
+ if (!row) {
36739
+ res.status(404).json({ detail: "Not found." });
36740
+ return;
36741
+ }
36742
+ if (!canManageShare(row, auth.user)) {
36743
+ res.status(403).json({ detail: "You can only manage your own share links." });
36744
+ return;
36745
+ }
36746
+ const rbac = await db2("rbac").where({ entity: "shared_artifact", target_resource_id: row.id }).select("*");
36747
+ res.json({
36748
+ name: row.name,
36749
+ auth_mode: row.auth_mode,
36750
+ expires_at: row.expires_at ?? null,
36751
+ rights_mode: row.rights_mode ?? null,
36752
+ content_type: row.content_type ?? null,
36753
+ created_by: row.created_by ?? null,
36754
+ rbac: {
36755
+ users: rbac.filter((r) => r.access_type === "User").map((r) => ({ id: r.user_id, rights: r.rights })),
36756
+ roles: rbac.filter((r) => r.access_type === "Role").map((r) => ({ id: r.role_id, rights: r.rights })),
36757
+ teams: rbac.filter((r) => r.access_type === "Team").map((r) => ({ id: r.team_id, rights: r.rights }))
36758
+ }
36759
+ });
36760
+ });
36761
+ app.patch("/shared-artifacts/:name", async (req, res) => {
36762
+ const { db: db2 } = await postgresClient();
36763
+ const auth = await requestValidators.authenticate(req);
36764
+ if (!auth.user?.id) {
36765
+ res.status(401).json({ detail: "Authentication required." });
36766
+ return;
36767
+ }
36768
+ const row = await getSharedArtifactByName(db2, req.params.name ?? "");
36769
+ if (!row) {
36770
+ res.status(404).json({ detail: "Not found." });
36771
+ return;
36772
+ }
36773
+ if (!canManageShare(row, auth.user)) {
36774
+ res.status(403).json({ detail: "You can only change your own share links." });
36775
+ return;
36776
+ }
36777
+ const input = req.body ?? {};
36778
+ const now = /* @__PURE__ */ new Date();
36779
+ const valid = validateUpdateInput(input, row, now);
36780
+ if (!valid.ok) {
36781
+ res.status(400).json({ detail: valid.message });
36782
+ return;
36783
+ }
36784
+ const newHash = input.password ? await hashSharePassword(String(input.password)) : null;
36785
+ const patch = planShareUpdate(input, row, newHash, now);
36786
+ if (typeof patch.name === "string" && patch.name !== row.name) {
36787
+ const taken = await getSharedArtifactByName(db2, patch.name);
36788
+ if (taken) {
36789
+ res.status(409).json({ detail: "That share name is already taken." });
36790
+ return;
36791
+ }
36792
+ }
36793
+ const [updated] = await db2("shared_artifacts").where({ id: row.id }).update(patch).returning("*");
36794
+ if (patch.auth_mode === "regular") {
36795
+ if (input.rbac && typeof input.rbac === "object") {
36796
+ const existing = await db2("rbac").where({ entity: "shared_artifact", target_resource_id: row.id }).select("*");
36797
+ await handleRBACUpdate(db2, "shared_artifact", row.id, input.rbac, existing);
36798
+ }
36799
+ } else {
36800
+ await db2("rbac").where({ entity: "shared_artifact", target_resource_id: row.id }).delete();
36801
+ }
36802
+ res.json({
36803
+ name: updated.name,
36804
+ auth_mode: updated.auth_mode,
36805
+ expires_at: updated.expires_at ?? null,
36806
+ rights_mode: updated.rights_mode ?? null
36807
+ });
36808
+ });
36624
36809
  app.post("/shared-artifacts", async (req, res) => {
36625
36810
  const { db: db2 } = await postgresClient();
36626
36811
  const auth = await requestValidators.authenticate(req);
@@ -39651,7 +39836,7 @@ var {
39651
39836
  memoryConflictScansSchema: memoryConflictScansSchema2,
39652
39837
  transcriptionJobsSchema: transcriptionJobsSchema3,
39653
39838
  imageGenerationsSchema: imageGenerationsSchema2,
39654
- sharedArtifactsSchema: sharedArtifactsSchema2,
39839
+ sharedArtifactsSchema: sharedArtifactsSchema3,
39655
39840
  otpSendAttemptsSchema: otpSendAttemptsSchema2
39656
39841
  } = coreSchemas.get();
39657
39842
  var addMissingFields = async (knex, tableName, fields, skipFields = []) => {
@@ -39714,7 +39899,7 @@ var up = async function(knex) {
39714
39899
  memoryConflictScansSchema2(),
39715
39900
  transcriptionJobsSchema3(),
39716
39901
  imageGenerationsSchema2(),
39717
- sharedArtifactsSchema2(),
39902
+ sharedArtifactsSchema3(),
39718
39903
  rbacSchema3(),
39719
39904
  agentsSchema3(),
39720
39905
  feedbackSchema3(),
package/dist/index.js CHANGED
@@ -193,7 +193,7 @@ import {
193
193
  willEmbedOnQueue,
194
194
  withRetry,
195
195
  workflowTemplatesSchema
196
- } from "./chunk-ASF74XFZ.js";
196
+ } from "./chunk-CWSP2WOQ.js";
197
197
  import {
198
198
  LiteLLMAdminError,
199
199
  findLiteLLMModel,
@@ -1940,6 +1940,44 @@ var validateCreateInput = (input, now) => {
1940
1940
  }
1941
1941
  return { ok: true };
1942
1942
  };
1943
+ var RIGHTS_MODES = /* @__PURE__ */ new Set(["private", "users", "roles", "teams", "public"]);
1944
+ var canManageShare = (row, user) => user.super_admin === true || row.created_by != null && String(row.created_by) === String(user.id);
1945
+ var validateUpdateInput = (input, row, now) => {
1946
+ if (input.name !== void 0 && !slugifyShareName(input.name)) {
1947
+ return { ok: false, message: "name must contain url-safe characters." };
1948
+ }
1949
+ const mode = input.auth_mode ?? row.auth_mode;
1950
+ if (mode !== "public" && mode !== "password" && mode !== "regular") {
1951
+ return { ok: false, message: "auth_mode must be public, password, or regular." };
1952
+ }
1953
+ const keepsPassword = row.auth_mode === "password" && !!row.password_hash;
1954
+ if (mode === "password" && !input.password && !keepsPassword) {
1955
+ return { ok: false, message: "A password is required for password mode." };
1956
+ }
1957
+ if (input.expires_at && Number.isNaN(new Date(input.expires_at).getTime())) {
1958
+ return { ok: false, message: "expires_at is not a valid date." };
1959
+ }
1960
+ if (input.expires_at && isExpired(input.expires_at, now)) {
1961
+ return { ok: false, message: "expires_at must be in the future." };
1962
+ }
1963
+ if (input.rights_mode !== void 0 && !RIGHTS_MODES.has(input.rights_mode)) {
1964
+ return { ok: false, message: "rights_mode must be private, users, roles, teams, or public." };
1965
+ }
1966
+ return { ok: true };
1967
+ };
1968
+ var planShareUpdate = (input, row, newPasswordHash, now) => {
1969
+ const mode = input.auth_mode ?? row.auth_mode;
1970
+ const patch = { auth_mode: mode, updatedAt: now };
1971
+ if (input.name !== void 0) patch.name = slugifyShareName(input.name);
1972
+ patch.password_hash = mode === "password" ? newPasswordHash ?? row.password_hash : null;
1973
+ if (input.expires_at !== void 0) patch.expires_at = input.expires_at;
1974
+ if (mode === "regular") {
1975
+ patch.rights_mode = input.rights_mode ?? (row.auth_mode === "regular" ? row.rights_mode ?? "private" : "private");
1976
+ } else {
1977
+ patch.rights_mode = "public";
1978
+ }
1979
+ return patch;
1980
+ };
1943
1981
  var hashSharePassword = (password) => bcrypt2.hash(password, 10);
1944
1982
  var verifySharePassword = (password, hash) => bcrypt2.compare(password, hash);
1945
1983
  var contentHeadersFor = (key, contentType, filename) => {
@@ -3337,6 +3375,28 @@ function createMutations(table, contexts, tools, config) {
3337
3375
  await saveTranscriptsSettings(parseSettingsInput(args.input));
3338
3376
  return buildTranscriptsSettingsInfo();
3339
3377
  };
3378
+ if (table.apiWrites === "super_admin") {
3379
+ for (const key of [
3380
+ `${tableNamePlural}CreateOne`,
3381
+ `${tableNamePlural}CopyOneById`,
3382
+ `${tableNamePlural}UpdateOne`,
3383
+ `${tableNamePlural}UpdateOneById`,
3384
+ `${tableNamePlural}RemoveOneById`,
3385
+ `${tableNamePlural}RemoveOne`,
3386
+ `${tableNamePlural}BulkUpdateRBAC`
3387
+ ]) {
3388
+ const inner = mutations[key];
3389
+ if (!inner) continue;
3390
+ mutations[key] = async (parent, args, context, info) => {
3391
+ if (context?.user?.super_admin !== true) {
3392
+ throw new Error(
3393
+ `${table.name.plural} rows are changed through their own API; the generic mutation is reserved for super admins.`
3394
+ );
3395
+ }
3396
+ return inner(parent, args, context, info);
3397
+ };
3398
+ }
3399
+ }
3340
3400
  return mutations;
3341
3401
  }
3342
3402
 
@@ -4885,6 +4945,22 @@ var getEnabledTools = async (agent, allExuluTools, allContexts, disabledTools =
4885
4945
  return enabledTools;
4886
4946
  };
4887
4947
 
4948
+ // src/exulu/resolve-context-window.ts
4949
+ var resolveContextWindow = async ({
4950
+ modelId
4951
+ }) => {
4952
+ if (process.env.EXULU_USE_LITELLM !== "true") {
4953
+ throw new Error("Litellm not configured.");
4954
+ }
4955
+ const entry = await findLiteLLMModel(modelId);
4956
+ const fromCatalog = entry?.max_input_tokens ?? entry?.max_tokens;
4957
+ if (fromCatalog != null && fromCatalog > 0) return fromCatalog;
4958
+ console.warn(
4959
+ `[EXULU] Unknown context window for model "${modelId}" \u2014 assuming ${DEFAULT_CONTEXT_WINDOW}. Check the LiteLLM catalog / provider template metadata.`
4960
+ );
4961
+ return DEFAULT_CONTEXT_WINDOW;
4962
+ };
4963
+
4888
4964
  // ee/workers.ts
4889
4965
  import "@opentelemetry/api";
4890
4966
  import { v4 as uuidv42 } from "uuid";
@@ -5158,7 +5234,12 @@ var workflowRunLabel = (workflowId) => `workflow-run-${workflowId}`;
5158
5234
  var baseTriggerMetadata = (email) => ({
5159
5235
  from: email.from.address,
5160
5236
  subject: email.subject,
5161
- message_id: email.messageId
5237
+ message_id: email.messageId,
5238
+ attachments: email.attachments.map((attachment) => ({
5239
+ filename: attachment.filename,
5240
+ content_type: attachment.contentType,
5241
+ size: attachment.content?.length ?? 0
5242
+ }))
5162
5243
  });
5163
5244
  var resolveTriggerBySecret = async (db, secret) => db.from("workflow_triggers").where({ secret }).first();
5164
5245
  var resolveTriggerById = async (db, triggerId) => db.from("workflow_triggers").where({ id: triggerId }).first();
@@ -6515,6 +6596,12 @@ var processUiMessagesFlow = async ({
6515
6596
  routine
6516
6597
  });
6517
6598
  const resolvedLanguageModel = resolved.languageModel;
6599
+ let contextWindow;
6600
+ try {
6601
+ contextWindow = await resolveContextWindow({ modelId: resolved.model.id });
6602
+ } catch (err) {
6603
+ console.warn(`[EXULU] Could not resolve the context window for routine model "${resolved.model.id}"; using the default.`, err);
6604
+ }
6518
6605
  const messagesWithoutPlaceholder = inputMessages.filter(
6519
6606
  (message) => message.metadata?.type !== "placeholder"
6520
6607
  );
@@ -6578,7 +6665,8 @@ var processUiMessagesFlow = async ({
6578
6665
  allExuluTools: tools,
6579
6666
  languageModel: resolvedLanguageModel,
6580
6667
  toolConfigs: agent.tools,
6581
- exuluConfig: config
6668
+ exuluConfig: config,
6669
+ contextWindow
6582
6670
  });
6583
6671
  console.log("[EXULU] consuming stream for agent.");
6584
6672
  const stream = result.stream.toUIMessageStream({
@@ -12380,7 +12468,9 @@ import fs2 from "fs";
12380
12468
  import { randomUUID as randomUUID7 } from "crypto";
12381
12469
  import "@opentelemetry/api";
12382
12470
  import JSZip3 from "jszip";
12383
- import { createIdGenerator as createIdGenerator2 } from "ai";
12471
+ import {
12472
+ createIdGenerator as createIdGenerator2
12473
+ } from "ai";
12384
12474
  import cookieParser from "cookie-parser";
12385
12475
 
12386
12476
  // src/exulu/suggestions.ts
@@ -12453,22 +12543,6 @@ ${SUGGESTIONS_SYSTEM_PROMPT}` : SUGGESTIONS_SYSTEM_PROMPT;
12453
12543
  };
12454
12544
  };
12455
12545
 
12456
- // src/exulu/resolve-context-window.ts
12457
- var resolveContextWindow = async ({
12458
- modelId
12459
- }) => {
12460
- if (process.env.EXULU_USE_LITELLM !== "true") {
12461
- throw new Error("Litellm not configured.");
12462
- }
12463
- const entry = await findLiteLLMModel(modelId);
12464
- const fromCatalog = entry?.max_input_tokens ?? entry?.max_tokens;
12465
- if (fromCatalog != null && fromCatalog > 0) return fromCatalog;
12466
- console.warn(
12467
- `[EXULU] Unknown context window for model "${modelId}" \u2014 assuming ${DEFAULT_CONTEXT_WINDOW}. Check the LiteLLM catalog / provider template metadata.`
12468
- );
12469
- return DEFAULT_CONTEXT_WINDOW;
12470
- };
12471
-
12472
12546
  // src/exulu/compact-session.ts
12473
12547
  import { randomUUID as randomUUID6 } from "crypto";
12474
12548
  import { generateText as generateText6, validateUIMessages as validateUIMessages2 } from "ai";
@@ -16221,7 +16295,8 @@ var {
16221
16295
  entityTypeSettingsSchema,
16222
16296
  promptFavoritesSchema,
16223
16297
  statisticsSchema,
16224
- transcriptionJobsSchema
16298
+ transcriptionJobsSchema,
16299
+ sharedArtifactsSchema
16225
16300
  } = coreSchemas.get();
16226
16301
  var claimCheckLimiter = claimCheckRateLimiter();
16227
16302
  var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) => {
@@ -16292,7 +16367,13 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
16292
16367
  workflowTemplatesSchema2(),
16293
16368
  statisticsSchema(),
16294
16369
  rbacSchema(),
16295
- transcriptionJobsSchema()
16370
+ transcriptionJobsSchema(),
16371
+ // Shared artifacts (2026-10): listed and favourited from the IMP's
16372
+ // Artifacts page through the generated operations. The table carries
16373
+ // RBAC, so the generic access control applies (public, own, shared with
16374
+ // me / my role / my team); `password_hash` is hidden and never leaves
16375
+ // the resolvers. The bytes still come from /shared-artifacts/:name/content.
16376
+ sharedArtifactsSchema()
16296
16377
  ],
16297
16378
  contexts ?? [],
16298
16379
  tools,
@@ -19797,7 +19878,7 @@ ${style.markdown}` : params.prompt;
19797
19878
  res.status(404).json({ detail: "Not found." });
19798
19879
  return;
19799
19880
  }
19800
- if (row.created_by !== auth.user.id) {
19881
+ if (!canManageShare(row, auth.user)) {
19801
19882
  res.status(403).json({ detail: "You can only delete your own share links." });
19802
19883
  return;
19803
19884
  }
@@ -19805,6 +19886,85 @@ ${style.markdown}` : params.prompt;
19805
19886
  await db("shared_artifacts").where({ id: row.id }).delete();
19806
19887
  res.status(204).end();
19807
19888
  });
19889
+ app.get("/shared-artifacts/:name/settings", async (req, res) => {
19890
+ const { db } = await postgresClient();
19891
+ const auth = await requestValidators.authenticate(req);
19892
+ if (!auth.user?.id) {
19893
+ res.status(401).json({ detail: "Authentication required." });
19894
+ return;
19895
+ }
19896
+ const row = await getSharedArtifactByName(db, req.params.name ?? "");
19897
+ if (!row) {
19898
+ res.status(404).json({ detail: "Not found." });
19899
+ return;
19900
+ }
19901
+ if (!canManageShare(row, auth.user)) {
19902
+ res.status(403).json({ detail: "You can only manage your own share links." });
19903
+ return;
19904
+ }
19905
+ const rbac = await db("rbac").where({ entity: "shared_artifact", target_resource_id: row.id }).select("*");
19906
+ res.json({
19907
+ name: row.name,
19908
+ auth_mode: row.auth_mode,
19909
+ expires_at: row.expires_at ?? null,
19910
+ rights_mode: row.rights_mode ?? null,
19911
+ content_type: row.content_type ?? null,
19912
+ created_by: row.created_by ?? null,
19913
+ rbac: {
19914
+ users: rbac.filter((r) => r.access_type === "User").map((r) => ({ id: r.user_id, rights: r.rights })),
19915
+ roles: rbac.filter((r) => r.access_type === "Role").map((r) => ({ id: r.role_id, rights: r.rights })),
19916
+ teams: rbac.filter((r) => r.access_type === "Team").map((r) => ({ id: r.team_id, rights: r.rights }))
19917
+ }
19918
+ });
19919
+ });
19920
+ app.patch("/shared-artifacts/:name", async (req, res) => {
19921
+ const { db } = await postgresClient();
19922
+ const auth = await requestValidators.authenticate(req);
19923
+ if (!auth.user?.id) {
19924
+ res.status(401).json({ detail: "Authentication required." });
19925
+ return;
19926
+ }
19927
+ const row = await getSharedArtifactByName(db, req.params.name ?? "");
19928
+ if (!row) {
19929
+ res.status(404).json({ detail: "Not found." });
19930
+ return;
19931
+ }
19932
+ if (!canManageShare(row, auth.user)) {
19933
+ res.status(403).json({ detail: "You can only change your own share links." });
19934
+ return;
19935
+ }
19936
+ const input = req.body ?? {};
19937
+ const now = /* @__PURE__ */ new Date();
19938
+ const valid = validateUpdateInput(input, row, now);
19939
+ if (!valid.ok) {
19940
+ res.status(400).json({ detail: valid.message });
19941
+ return;
19942
+ }
19943
+ const newHash = input.password ? await hashSharePassword(String(input.password)) : null;
19944
+ const patch = planShareUpdate(input, row, newHash, now);
19945
+ if (typeof patch.name === "string" && patch.name !== row.name) {
19946
+ const taken = await getSharedArtifactByName(db, patch.name);
19947
+ if (taken) {
19948
+ res.status(409).json({ detail: "That share name is already taken." });
19949
+ return;
19950
+ }
19951
+ }
19952
+ const [updated] = await db("shared_artifacts").where({ id: row.id }).update(patch).returning("*");
19953
+ if (patch.auth_mode === "regular") {
19954
+ if (input.rbac && typeof input.rbac === "object") {
19955
+ const existing = await db("rbac").where({ entity: "shared_artifact", target_resource_id: row.id }).select("*");
19956
+ await handleRBACUpdate(db, "shared_artifact", row.id, input.rbac, existing);
19957
+ }
19958
+ } else {
19959
+ await db("rbac").where({ entity: "shared_artifact", target_resource_id: row.id }).delete();
19960
+ }
19961
+ res.json({
19962
+ name: updated.name,
19963
+ auth_mode: updated.auth_mode,
19964
+ expires_at: updated.expires_at ?? null,
19965
+ rights_mode: updated.rights_mode ?? null
19966
+ });
19967
+ });
19808
19968
  app.post("/shared-artifacts", async (req, res) => {
19809
19969
  const { db } = await postgresClient();
19810
19970
  const auth = await requestValidators.authenticate(req);
@@ -22738,7 +22898,7 @@ var {
22738
22898
  memoryConflictScansSchema,
22739
22899
  transcriptionJobsSchema: transcriptionJobsSchema2,
22740
22900
  imageGenerationsSchema,
22741
- sharedArtifactsSchema,
22901
+ sharedArtifactsSchema: sharedArtifactsSchema2,
22742
22902
  otpSendAttemptsSchema
22743
22903
  } = coreSchemas.get();
22744
22904
  var addMissingFields = async (knex, tableName, fields, skipFields = []) => {
@@ -22801,7 +22961,7 @@ var up = async function(knex) {
22801
22961
  memoryConflictScansSchema(),
22802
22962
  transcriptionJobsSchema2(),
22803
22963
  imageGenerationsSchema(),
22804
- sharedArtifactsSchema(),
22964
+ sharedArtifactsSchema2(),
22805
22965
  rbacSchema2(),
22806
22966
  agentsSchema2(),
22807
22967
  feedbackSchema2(),
@@ -78,6 +78,18 @@ const getAllExuluVariables = async (): Promise<{
78
78
  }
79
79
 
80
80
  const execAsync = promisify(exec);
81
+
82
+ /** Dotenv files of the running backend that a sandboxed command must not read. */
83
+ export const backendSecretFiles = (): string[] => {
84
+ const cwd = process.cwd();
85
+ const names = ['.env', '.env.local', '.env.production', '.env.production.local'];
86
+ const paths = new Set<string>();
87
+ for (const name of names) {
88
+ paths.add(join(cwd, name));
89
+ paths.add(join('/app', name));
90
+ }
91
+ return [...paths];
92
+ };
81
93
  // Sandbox commands can be very long (long deny lists) — bump default buffer.
82
94
  const EXEC_MAX_BUFFER = 32 * 1024 * 1024;
83
95
 
@@ -595,7 +607,12 @@ export async function createSessionSandbox(
595
607
  deniedDomains: [], // todo
596
608
  },
597
609
  filesystem: {
598
- denyRead: ['~'],
610
+ // The backend's own dotenv file sits under the process cwd (and
611
+ // /app in the shipped image); a bash command could otherwise
612
+ // `cat` the database password out of it (seen in an ALGI session
613
+ // 2026-10-07). Deny it explicitly — the rest of the tree stays
614
+ // readable for node_modules / skill assets.
615
+ denyRead: ['~', ...backendSecretFiles()],
599
616
  allowRead: [
600
617
  sessionDir,
601
618
  // Allow Node to read globally-installed packages from inside
@@ -67,3 +67,6 @@ google-cloud-aiplatform>=1.38
67
67
  python-docx>=1.1
68
68
  python-pptx>=1.0
69
69
  openpyxl>=3.1
70
+ # Legacy .xls (BIFF) workbooks: pandas.read_excel / xlrd — parse_document converts them via
71
+ # LibreOffice, but skill scripts that open the file themselves need this (ALGI feedback 2026-09-17).
72
+ xlrd>=2.0
package/ee/workers.ts CHANGED
@@ -14,6 +14,7 @@ import { refreshContextEmbeddersIfStale } from "@SRC/exulu/hydrate-embedders";
14
14
  import type { ExuluEval } from "@SRC/exulu/evals.ts";
15
15
  import type { ExuluTool } from "@SRC/exulu/tool.ts";
16
16
  import { resolveModel } from "@SRC/exulu/resolve-model.ts";
17
+ import { resolveContextWindow } from "@SRC/exulu/resolve-context-window.ts";
17
18
  import { postgresClient } from "@SRC/postgres/client";
18
19
  import type { BullMqJobData } from "@EE/queues/decorator.ts";
19
20
  import { maybePruneJobResults } from "@EE/queues/prune-job-results.ts";
@@ -1600,6 +1601,17 @@ export const processUiMessagesFlow = async ({
1600
1601
 
1601
1602
  const resolvedLanguageModel = resolved.languageModel;
1602
1603
 
1604
+ // Routine runs used to omit the context window, so generateStream fell back
1605
+ // to the 128k default and a Gemini run with ~500k tokens of tool results was
1606
+ // rejected with CONTEXT_COMPACTION_REQUIRED ("of 102,400 usable tokens")
1607
+ // although the model takes 1M. Resolve it like the chat route does.
1608
+ let contextWindow: number | undefined;
1609
+ try {
1610
+ contextWindow = await resolveContextWindow({ modelId: resolved.model.id });
1611
+ } catch (err) {
1612
+ console.warn(`[EXULU] Could not resolve the context window for routine model "${resolved.model.id}"; using the default.`, err);
1613
+ }
1614
+
1603
1615
  // Remove placeholder agent response before sending
1604
1616
  const messagesWithoutPlaceholder = inputMessages.filter(
1605
1617
  (message) => (message.metadata as any)?.type !== "placeholder",
@@ -1712,6 +1724,7 @@ export const processUiMessagesFlow = async ({
1712
1724
  languageModel: resolvedLanguageModel,
1713
1725
  toolConfigs: agent.tools,
1714
1726
  exuluConfig: config,
1727
+ contextWindow,
1715
1728
  });
1716
1729
 
1717
1730
  console.log("[EXULU] consuming stream for agent.");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exulu/backend",
3
3
  "author": "Qventu B.V.",
4
- "version": "5.2.0",
4
+ "version": "5.4.0",
5
5
  "main": "./dist/index.js",
6
6
  "private": false,
7
7
  "publishConfig": {