LibreChat/api/server/services/Files/provision.js
Danny Avila 5e90cc45e4
📎 feat: Copy Chat Attachments into Attached Workspaces (#17376)
* 📎 feat: Copy Chat Attachments into Attached Workspaces

A chat on an attached workspace now copies the user's own attachments into
.librechat/attachments/ before the model runs, through the worker's
import_file operation, and tells the model where they are. A worker without
the operation, a deny file-write policy, or a copy that fails or runs past
its bound leaves a plain note saying the file is not on this machine and why.

* 🧭 fix: Scope Attachment Records by Tenant and Prime Late Subagents

Match the tenant when recording a workspace copy, require write_file so the
folder can always ignore itself, key copies by the live Code API route and
worker, keep a digest when a copy fails so it is not hashed again, stop
waiting on bookkeeping at the deadline, refuse to start on a cancelled turn,
prime lazily initialized subagents through one per-turn primer, and make the
budget configurable as endpoints.agents.workspaceAttachments.timeoutMs.

* 🙈 fix: Copy Attachments Only Where the Folder Ignores Itself

Gate every copy on .librechat/attachments/.gitignore ignoring the whole
folder: create it with *, and accept an existing one only when it already
ignores everything, otherwise report the file as unavailable with how to fix
it. Prime a lazily routed subagent against its own tool context with a
provisioning callback bound to it, and check for a cancelled turn before
arming the deadline timer.

* 🪢 fix: Recheck the Attachment Ignore Rule Each Turn and Share One Request Cap

Drop the process-wide ignore cache and check the folder once per turn, shared
by every agent, rejecting a truncated read. Cap workspace requests per turn
across agents (workspaceAttachments.concurrency, default 3), name converted
images for their stored type, log only safe error metadata, and keep the
bookkeeping write from advancing updatedAt.

* 🔀 chore: Take dev's File Methods Ahead of Merging dev

dev and this branch both add to the same lines of the file methods module.
Take dev's version here so the merge of dev that follows is clean; the next
commit adds recordFileWorkspaceImport back beside dev's new methods.

* 🧩 fix: Ignore Workspace Operations a Newer Worker Advertises

Bring recordFileWorkspaceImport back beside dev's new file methods after the
merge. Drop well-formed operation names this build does not know from a
worker's capabilities, globally and per workspace, instead of rejecting the
whole status, so workers can turn on new operations such as import_file by
default. Known names keep their strict checks, malformed lists are still
refused, and a worker offering only unknown operations offers no workspace
tools rather than failing.
2026-10-23 07:37:50 +02:00

23 lines
1.2 KiB
JavaScript

const { createProvisionService } = require('@librechat/api');
const { loadAuthValues } = require('~/server/services/Tools/credentials');
const { uploadVectors } = require('./VectorDB/crud');
const { getStrategyFunctions } = require('./strategies');
/* Wiring only: the provisioning logic lives in packages/api, where it is type checked.
* Storage strategies, vector upload, and credential lookup are api-workspace concerns,
* so they are bound here and injected.
*
* Built on first use rather than at module load: this module is reachable from the
* OpenAI-compatible controllers, whose suites partially mock @librechat/api, and a
* load-time call would throw before any provisioning is requested. */
let service;
const getService = () =>
(service ??= createProvisionService({ getStrategyFunctions, uploadVectors, loadAuthValues }));
module.exports = {
loadCodeApiKey: (...args) => getService().loadCodeApiKey(...args),
provisionToCodeEnv: (...args) => getService().provisionToCodeEnv(...args),
provisionToVectorDB: (...args) => getService().provisionToVectorDB(...args),
digestFile: (...args) => getService().digestFile(...args),
checkSessionsAlive: (...args) => getService().checkSessionsAlive(...args),
};