mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
* 🎒 feat: Carry Project Context Across Conversations
* fix: fail a project attach whose upload hold cannot be released and keep file deletes independent of project cleanup
- Attaching a project file now fails, with nothing attached, when the file's
temporary upload hold cannot be released, instead of attaching a file that
can still expire.
- A failed project cleanup after a file delete is logged rather than failing a
delete that already happened, and a user-wide delete clears that user's
project references without reading every file first.
- Both resize handles share the orientation-aware grip, so a primary handle in
a vertical group renders a rotated grip like the alternate one.
* fix: treat an empty tenant id as no tenant in the project file picker
* fix: attach nothing when a project file is deleted while the attach is in flight
* fix: localize project file association failures instead of showing server text
* test: expect a localized reason for a rejected project file association
* fix: scope project file listing to the caller's tenant and name the file limit when attaching an existing file
- Listing a project's attached files now returns not found when the project
belongs to another tenant, matching the available-file listing and the
chat context resolver.
- Choosing an existing file for a full project now names the project file
limit instead of the generic attach error, like the upload path.
* fix: treat an empty tenant id as no tenant in every project tenant check
A caller whose tenant id is an empty string was refused its own tenantless
project when listing attached or available files, because the handlers
compared '' with null. The project handlers and the chat context resolver now
share one comparison that treats an empty tenant id as no tenant, the rule the
project file queries already follow.
* test: wait for the workspace layout swap and the mobile drawer before acting in the long-metadata spec
The desktop title was measured while the phone layout could still be the one
rendered, and the sidebar row menu was opened before the mobile drawer
committed its open state, which closes a menu opened ahead of it. The spec
now waits for the workspace's phone-only sidebar toggle to leave and for the
drawer to drop inert, the same drawer signal the agents helpers use.
* fix: keep the agent context fingerprint of a turn outside any project unchanged
Every turn now passes a project context key into the agent context
fingerprint, and a turn outside any project passed the no-project sentinel,
which changed the digest of every existing no-project checkpoint. An agent
event conversation written before this change then cold-started and reloaded
its history on its next event. The fingerprint now hashes the no-project key
as absent, so those checkpoints keep matching.
* test: load the long-metadata spec at phone width before driving the mobile drawer
The spec crossed back from desktop to phone width without a reload, which
leaves the drawer on the desktop toggle path whose delayed focus handoff to
the close button dismissed the row menu roughly 200ms after it opened. The
spec now reloads at phone width, as a phone arrives, and waits for the
drawer's own focus handoff before opening the menu.
(cherry picked from commit 4062bc3c00)
Original-PR: https://github.com/LibreChat-AI/LibreChat/pull/15684
122 lines
5.2 KiB
JavaScript
122 lines
5.2 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
/**
|
|
* `FILE_SEARCH` and `RUN_CODE` are enforced by pairing each read of the matching
|
|
* `AgentCapabilities` entry with the role grant from `resolveToolRoleGrants`.
|
|
* The capability is the deployment switch; the grant is the per-role half. A
|
|
* read that gets one without the other is a hole — which is how every gap in
|
|
* this area has been found: a boundary nobody knew existed.
|
|
*
|
|
* So the boundary list is pinned here. Adding a read of either capability fails
|
|
* this test until it is classified below, which is the point: the classification
|
|
* is the review, and it cannot be skipped by not knowing the site exists.
|
|
*/
|
|
|
|
const REPO_ROOT = path.resolve(__dirname, '../../../..');
|
|
const SEARCH_ROOTS = ['api/app', 'api/server', 'packages/api/src', 'packages/data-provider/src'];
|
|
const CAPABILITY_PATTERN =
|
|
/AgentCapabilities\.(execute_code|file_search)\b|EToolResources\.code_interpreter\b/;
|
|
|
|
/**
|
|
* Every file holding at least one read, with the count and why each is sound.
|
|
* Counts rather than line numbers so ordinary edits above a gate don't churn it.
|
|
*/
|
|
const CLASSIFIED = {
|
|
// -- Gates: capability AND grant --------------------------------------------
|
|
/** 7 gates + 2 map entries + 2 warning-list entries. */
|
|
'api/server/services/ToolService.js': 11,
|
|
/** `codeEnvAvailable` and `fileSearchAvailable`, both paired after the
|
|
* startup batch from the one grant read that batch joins. */
|
|
'api/server/services/Endpoints/agents/initialize.js': 2,
|
|
/** `codeEnvAvailable` and `fileSearchAvailable` for the OpenAI-compatible
|
|
* route, both paired with the shared grant read. */
|
|
'api/server/controllers/agents/openai.js': 2,
|
|
/** `codeEnvAvailable` and `fileSearchAvailable` for the Responses route,
|
|
* both paired with the shared grant read. */
|
|
'api/server/controllers/agents/responses.js': 2,
|
|
/** `codeEnvAvailable` for the memory-agent initializer. */
|
|
'api/server/controllers/agents/client.js': 1,
|
|
/** Upload processing: two consumer-map entries, the role-gated consumer checks,
|
|
* and the code-environment/file-search branches. All consumer selection shares
|
|
* the role grant resolved before routing. */
|
|
'api/server/services/Files/process.js': 5,
|
|
/** Agent-management upload purposes. */
|
|
'api/server/routes/agents/management.js': 2,
|
|
/** Two gates, each paired when the embedder wires `getRoleByName`; one in a
|
|
* comment. */
|
|
'packages/api/src/agents/openai/service.ts': 3,
|
|
|
|
/** Two gates for the project file corpus (`addProjectFilesToFileSearch` and
|
|
* `canUseProjectFileSearch`), each paired with the `fileSearchAvailable`
|
|
* grant resolved by the caller, plus two `recordCapabilityToolNames`
|
|
* bookkeeping reads that describe what was built. */
|
|
'packages/api/src/agents/initialize.ts': 4,
|
|
|
|
// -- Not gates ---------------------------------------------------------------
|
|
/** The upload-resource map entry, and one mention in a doc comment. */
|
|
'packages/api/src/tools/rolePermissions.ts': 2,
|
|
/** Default capability list shipped in config. */
|
|
'packages/data-provider/src/config.ts': 2,
|
|
/** Config normalization only: strips stale `tool_options` when the capability
|
|
* is off. Execution is gated by the loaders, so this needs no grant. */
|
|
'api/server/controllers/agents/v1.js': 1,
|
|
};
|
|
|
|
/** @returns {string[]} repo-relative files under `dir`, excluding tests. */
|
|
function walk(dir) {
|
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
return entries.flatMap((entry) => {
|
|
const full = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
return entry.name === 'node_modules' || entry.name === 'dist' ? [] : walk(full);
|
|
}
|
|
if (!/\.(js|ts)$/.test(entry.name) || /\.(test|spec)\.[jt]s$/.test(entry.name)) {
|
|
return [];
|
|
}
|
|
return [full];
|
|
});
|
|
}
|
|
|
|
function collectReads() {
|
|
const found = {};
|
|
for (const root of SEARCH_ROOTS) {
|
|
for (const file of walk(path.join(REPO_ROOT, root))) {
|
|
const matches = fs
|
|
.readFileSync(file, 'utf8')
|
|
.split('\n')
|
|
.filter((line) => CAPABILITY_PATTERN.test(line));
|
|
if (matches.length > 0) {
|
|
found[path.relative(REPO_ROOT, file)] = matches.length;
|
|
}
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
describe('FILE_SEARCH / RUN_CODE capability reads are all classified', () => {
|
|
const found = collectReads();
|
|
|
|
it('has no unclassified file reading a role-gated capability', () => {
|
|
const unclassified = Object.keys(found)
|
|
.filter((file) => CLASSIFIED[file] == null)
|
|
.sort();
|
|
|
|
expect({
|
|
unclassified,
|
|
hint: 'A new read of AgentCapabilities.execute_code / file_search or EToolResources.code_interpreter. Pair it with resolveToolRoleGrants, then record it in CLASSIFIED with why it is sound.',
|
|
}).toEqual({ unclassified: [], hint: expect.any(String) });
|
|
});
|
|
|
|
it('has no classified file whose read count drifted', () => {
|
|
const drifted = Object.entries(CLASSIFIED)
|
|
.filter(([file, expected]) => (found[file] ?? 0) !== expected)
|
|
.map(([file, expected]) => `${file}: expected ${expected}, found ${found[file] ?? 0}`)
|
|
.sort();
|
|
|
|
expect({
|
|
drifted,
|
|
hint: 'A capability read was added or removed. If added, pair it with the grant before updating the count.',
|
|
}).toEqual({ drifted: [], hint: expect.any(String) });
|
|
});
|
|
});
|