mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-04 14:57:42 +00:00
🐛 fix: Persist provisionedAt + scope lazy file_search to agent resources
Round-3 Codex follow-ups completing the round-2 fixes: - The file schema/type dropped codeEnvRef.provisionedAt, so the liveness fast-path was dead after reload. Add provisionedAt to CodeEnvRef + the Mongoose subschema. - Lazily provisioned agent-scoped file_search files were only added to tool_resources.file_search.files, so primeFiles treated them as user attachments and queried without entity_id, missing the agent-scoped vectors. Add agent-scoped files to file_ids instead so they are queried with entity_id.
This commit is contained in:
parent
95f9393722
commit
5291fd89fa
3 changed files with 21 additions and 2 deletions
|
|
@ -295,11 +295,22 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
|
|||
if (!ctx.tool_resources) {
|
||||
ctx.tool_resources = {};
|
||||
}
|
||||
const addProvisionedFile = (file, resourceType) => {
|
||||
const addProvisionedFile = (file, resourceType, agentScoped) => {
|
||||
if (!file.file_id) {
|
||||
return;
|
||||
}
|
||||
const resource = ctx.tool_resources[resourceType] ?? {};
|
||||
/** Agent-scoped file_search files are embedded under `entity_id: agentId`, so
|
||||
* they must be queried by `file_ids` (primeFiles marks those `fromAgent` and
|
||||
* passes `entity_id`); user chat attachments and code files live in `files`. */
|
||||
if (agentScoped && resourceType === EToolResources.file_search) {
|
||||
const fileIds = resource.file_ids ? [...resource.file_ids] : [];
|
||||
if (!fileIds.includes(file.file_id)) {
|
||||
fileIds.push(file.file_id);
|
||||
}
|
||||
ctx.tool_resources[resourceType] = { ...resource, file_ids: fileIds };
|
||||
return;
|
||||
}
|
||||
const files = resource.files ? [...resource.files] : [];
|
||||
if (!files.some((existing) => existing.file_id === file.file_id)) {
|
||||
files.push(file);
|
||||
|
|
@ -341,7 +352,11 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
|
|||
});
|
||||
if (result.embedded) {
|
||||
file.embedded = true;
|
||||
addProvisionedFile(file, EToolResources.file_search);
|
||||
addProvisionedFile(
|
||||
file,
|
||||
EToolResources.file_search,
|
||||
entityIdForFile(file) !== undefined,
|
||||
);
|
||||
if (result.fileUpdate) {
|
||||
pendingUpdates.push(result.fileUpdate);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,9 @@ interface CodeEnvRefBase {
|
|||
id: string;
|
||||
storage_session_id: string;
|
||||
file_id: string;
|
||||
/** Epoch ms when the file was uploaded to the code env; drives the liveness
|
||||
* fast-path (distinct from the usage-bumped `updatedAt`). */
|
||||
provisionedAt?: number;
|
||||
}
|
||||
|
||||
export type CodeEnvRef =
|
||||
|
|
|
|||
|
|
@ -130,6 +130,7 @@ const file: Schema<IMongoFile> = new Schema(
|
|||
storage_session_id: { type: String, required: true },
|
||||
file_id: { type: String, required: true },
|
||||
version: { type: Number },
|
||||
provisionedAt: { type: Number },
|
||||
},
|
||||
{ _id: false },
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue