Files
chat/api/server/services/OboPolicyService.js
zooqueen 48eac75e13 refactor: fork @librechat/api workspace package to @hanzochat/api
Forks the internal @librechat/api workspace package (packages/api) to
@hanzochat/api, matching the app package @hanzochat/chat. De-LibreChats
the package name and puts its build under our control.

Fixes the live prod bug where the deployed chat image shipped a stale
@librechat/api/dist missing the exported handleError(), breaking every
error path with "handleError is not a function" and killing the SSE
stream. A clean build of @hanzochat/api produces dist/index.js that
exports handleError (verified: exports.handleError = handleError).

- packages/api/package.json: name @librechat/api -> @hanzochat/api
- 254 source/config/doc/lockfile sites: @librechat/api -> @hanzochat/api
  (api/, packages/, config/, turbo.json, pnpm-lock.yaml, bun.lock,
   package-lock.json, LLM.md)
- @librechat/api-client (distinct MCP client id string) left untouched
- other @librechat/* packages (client, data-schemas, data-provider)
  left as-is per scope

pnpm install (regenerated lockfile) + build:api green; dist exports
handleError. api/data-schemas/client packages build; full build:packages
and api test:ci are blocked by a PRE-EXISTING, unrelated upstream break
in librechat-data-provider (config.spec.ts / cloudfront-config.spec.ts
reference exports that src/config.ts no longer has) -- out of scope here.
2026-06-19 22:00:19 -07:00

44 lines
1.4 KiB
JavaScript

const { isOboConfigStillTrusted } = require('@hanzochat/api');
const db = require('~/models');
/**
* Checks whether a parsed MCP server config is DB-sourced (user-created) using
* the same `isUserSourced` heuristics as the rest of the MCP layer: an explicit
* `source` is authoritative when present; otherwise `dbId` presence is used.
*/
function isDbSourced({ source, dbId }) {
if (source != null) {
return source === 'user';
}
return !!dbId;
}
/**
* Builds the predicate the MCP runtime calls before performing an OBO token exchange.
*
* YAML/Config-sourced configs (admin-defined) bypass the check — admins are
* already trusted at the deployment level. DB-sourced configs (created via the
* UI) are gated on the original author still holding `MCP_SERVERS.CONFIGURE_OBO`,
* so retained configs fail closed when an author's role is downgraded.
*/
function createOboTrustChecker() {
return async ({ source, author, dbId }) => {
if (!isDbSourced({ source, dbId })) {
return true;
}
return isOboConfigStillTrusted({
authorId: author,
getUserRoleByAuthorId: async (userId) => {
const user = await db.findUser({ _id: userId }, 'role');
return user?.role;
},
getRolePermissions: async (roleName) => {
const role = await db.getRoleByName(roleName);
return role?.permissions;
},
});
};
}
module.exports = { createOboTrustChecker };