mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
Some checks failed
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Has been cancelled
Main Promotion Policy Tests / Main promotion denial and fast-forward tests (push) Has been cancelled
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been cancelled
- Let agents use Langfuse prompts by production label or pinned version, with the existing permission and usage checks. - Add a configuration switch, disabled by default. Preserve saved links while disabled, without resolving them or falling back to inline text. - Share source-specific production and exact selections across agent links and the prompt service. Reject source mismatches. - Add revision lists for the Agent Builder version picker. Resolve Langfuse instructions on each initialization without caching. - Improve disabled and unavailable states and test source changes, revision loading, and permission failures.
131 lines
3.6 KiB
JavaScript
131 lines
3.6 KiB
JavaScript
const express = require('express');
|
|
const {
|
|
generateCheckAccess,
|
|
createPromptHandlers,
|
|
invalidateLinkedPrompt,
|
|
} = require('@librechat/api');
|
|
const {
|
|
CacheKeys,
|
|
Permissions,
|
|
PermissionBits,
|
|
PermissionTypes,
|
|
} = require('librechat-data-provider');
|
|
const {
|
|
canAccessPromptGroupResource,
|
|
canAccessPromptViaGroup,
|
|
promptUsageLimiter,
|
|
promptResolveLimiter,
|
|
requireJwtAuth,
|
|
configMiddleware,
|
|
} = require('~/server/middleware');
|
|
const { getEffectivePermissions } = require('~/server/services/PermissionService');
|
|
const { promptService } = require('~/server/services/Prompts');
|
|
const { getLogStores } = require('~/cache');
|
|
const db = require('~/models');
|
|
|
|
const { getRoleByName } = db;
|
|
const router = express.Router();
|
|
|
|
const linkedInstructionsCache = getLogStores(CacheKeys.AGENT_LINKED_INSTRUCTIONS);
|
|
|
|
const handlers = createPromptHandlers({
|
|
service: promptService,
|
|
getPromptGroupAccessContext: db.getPromptGroupAccessContext,
|
|
getEffectivePermissions,
|
|
invalidateLinkedPrompt: (groupId, promptIds) =>
|
|
invalidateLinkedPrompt(linkedInstructionsCache, groupId, promptIds),
|
|
});
|
|
|
|
const checkPromptAccess = generateCheckAccess({
|
|
permissionType: PermissionTypes.PROMPTS,
|
|
permissions: [Permissions.USE],
|
|
getRoleByName,
|
|
});
|
|
const checkPromptCreate = generateCheckAccess({
|
|
permissionType: PermissionTypes.PROMPTS,
|
|
permissions: [Permissions.USE, Permissions.CREATE],
|
|
getRoleByName,
|
|
});
|
|
|
|
router.use(requireJwtAuth);
|
|
router.use(checkPromptAccess);
|
|
|
|
router.get(
|
|
'/groups/:groupId',
|
|
canAccessPromptGroupResource({ requiredPermission: PermissionBits.VIEW }),
|
|
configMiddleware,
|
|
handlers.getPromptGroup,
|
|
);
|
|
router.get(
|
|
'/groups/:groupId/resolve',
|
|
promptResolveLimiter,
|
|
canAccessPromptGroupResource({ requiredPermission: PermissionBits.VIEW }),
|
|
configMiddleware,
|
|
handlers.resolvePrompt,
|
|
);
|
|
router.get(
|
|
'/groups/:groupId/revisions',
|
|
promptResolveLimiter,
|
|
canAccessPromptGroupResource({ requiredPermission: PermissionBits.VIEW }),
|
|
handlers.listRevisions,
|
|
);
|
|
router.get('/all', configMiddleware, handlers.listAllPromptGroups);
|
|
router.get('/groups', configMiddleware, handlers.listPromptGroups);
|
|
|
|
router.post('/', checkPromptCreate, configMiddleware, handlers.createPromptGroup);
|
|
router.post(
|
|
'/groups/:groupId/prompts',
|
|
checkPromptAccess,
|
|
canAccessPromptGroupResource({ requiredPermission: PermissionBits.EDIT }),
|
|
configMiddleware,
|
|
handlers.savePrompt,
|
|
);
|
|
router.post(
|
|
'/groups/:groupId/use',
|
|
promptUsageLimiter,
|
|
canAccessPromptGroupResource({ requiredPermission: PermissionBits.VIEW }),
|
|
handlers.recordPromptUsage,
|
|
);
|
|
|
|
router.patch(
|
|
'/groups/:groupId',
|
|
checkPromptCreate,
|
|
canAccessPromptGroupResource({ requiredPermission: PermissionBits.EDIT }),
|
|
configMiddleware,
|
|
handlers.updatePromptGroup,
|
|
);
|
|
router.patch(
|
|
'/:promptId/tags/production',
|
|
checkPromptCreate,
|
|
canAccessPromptViaGroup({ requiredPermission: PermissionBits.EDIT, resourceIdParam: 'promptId' }),
|
|
configMiddleware,
|
|
handlers.makePromptProduction,
|
|
);
|
|
|
|
router.get(
|
|
'/:promptId',
|
|
canAccessPromptViaGroup({ requiredPermission: PermissionBits.VIEW, resourceIdParam: 'promptId' }),
|
|
configMiddleware,
|
|
handlers.getPrompt,
|
|
);
|
|
router.get('/', configMiddleware, handlers.getPrompts);
|
|
|
|
router.delete(
|
|
'/:promptId',
|
|
checkPromptCreate,
|
|
canAccessPromptViaGroup({
|
|
requiredPermission: PermissionBits.DELETE,
|
|
resourceIdParam: 'promptId',
|
|
}),
|
|
configMiddleware,
|
|
handlers.deletePrompt,
|
|
);
|
|
router.delete(
|
|
'/groups/:groupId',
|
|
checkPromptCreate,
|
|
canAccessPromptGroupResource({ requiredPermission: PermissionBits.DELETE }),
|
|
configMiddleware,
|
|
handlers.deletePromptGroup,
|
|
);
|
|
|
|
module.exports = router;
|