mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
* 🔗 feat(agents): use LibreChat prompt groups as agent instructions
Agents can link a prompt group revision or Production as their instructions. The link resolves at the start of each turn through a cached resolver. The cache clears on promote and delete. Editors without VIEW on the group see a restricted placeholder.
* fix: remove duplicate logger import from agent initialization tests
* fix: honor prompt management capabilities for linked agent instructions
* test: seed prompt manager capabilities in authorization fixtures
* fix: clear acknowledged linked prompt edits before version restore
* test: adapt merged chain coverage to prompt-aware payload helper
---------
Co-authored-by: Lia <lia@librechat.ai>
37 lines
1.5 KiB
JavaScript
37 lines
1.5 KiB
JavaScript
const { logger, SystemCapabilities } = require('@librechat/data-schemas');
|
|
const {
|
|
checkAccess,
|
|
createPromptService,
|
|
assertModelBoundContent,
|
|
createInstructionsPromptAccess,
|
|
} = require('@librechat/api');
|
|
const { Permissions, PermissionTypes } = require('librechat-data-provider');
|
|
const {
|
|
grantPermission,
|
|
getResourcePermissionsMap,
|
|
} = require('~/server/services/PermissionService');
|
|
const { hasCapability } = require('~/server/middleware/roles/capabilities');
|
|
const db = require('~/models');
|
|
|
|
/** Wiring only: the write/present decision logic lives in `@librechat/api` (`createInstructionsPromptAccess`, `checkInstructionsPromptWrite`). */
|
|
const instructionsPromptAccess = createInstructionsPromptAccess({
|
|
getResourcePermissionsMap,
|
|
canManagePrompts: (user) => hasCapability(user, SystemCapabilities.MANAGE_PROMPTS),
|
|
promptService: createPromptService({ db, grantPermission }),
|
|
assertAgentInstructionsContent: ({ instructions, filters }) =>
|
|
assertModelBoundContent({ filters, agents: [{ instructions }] }),
|
|
/** The same role-level gate `checkPromptAccess` applies to every `/prompts` route
|
|
* (`PermissionTypes.PROMPTS`, `Permissions.USE`). Only `.role` is read, so the
|
|
* `{ id, role }` identity `validateLinkWrite` carries is enough. */
|
|
canUsePrompts: (user, req) =>
|
|
checkAccess({
|
|
req,
|
|
user,
|
|
permissionType: PermissionTypes.PROMPTS,
|
|
permissions: [Permissions.USE],
|
|
getRoleByName: db.getRoleByName,
|
|
}),
|
|
logger,
|
|
});
|
|
|
|
module.exports = { instructionsPromptAccess };
|