LibreChat/packages/api
Danny Avila 96312aa4fd
🎯 fix: Use Resolved Provider for Agent Token Lookup on Custom Endpoints (#12574)
* fix: Use resolved provider for agent token lookup on custom endpoints

The providerEndpointMap lookup in initializeAgent used the original
provider name (e.g. "EduGPT") instead of the resolved overrideProvider
("openai"). Since providerEndpointMap only contains 4 built-in
providers, custom providers resolved to undefined, causing
getModelMaxTokens to miss the token map and fall back to 18000 tokens.
With agent instructions + tool schemas consuming most of that budget,
createPruneMessages would strip all messages on the first turn.

* fix: Use correct EndpointTokenConfig type in test

* refactor: Unify test factory, remove non-discriminating test

Address review findings:
- Remove Test 2 ("uses the model real context window") which passed
  with and without the fix due to getModelMaxTokens defaulting to
  openAI when endpoint is undefined (JS default parameter semantics)
- Merge createCustomProviderMocks into createMocks via provider,
  overrideProvider, and useRealTokenLookup parameters
- Hoist jest.requireActual to file scope for shared access

* refactor: Address followup review findings

- Replace loose `maxContextTokens > 18000` assertion with precise
  computed value `Math.round((65536 - 4096) * 0.95)` so the outcome
  assertion is meaningful and self-documenting
- Hoist `customProvider` to describe-level constant `CUSTOM_PROVIDER`
- Document `overrideProvider` semantics and `useRealTokenLookup` in
  factory JSDoc
- Add comment on real `optionalChainWithEmptyCheck` noting its
  zero-handling semantics are load-bearing for the maxContextTokens=0
  test

* style: Use // for inline comment, clarify pipeline assertion role
2026-04-08 15:07:38 -04:00
..
src 🎯 fix: Use Resolved Provider for Agent Token Lookup on Custom Endpoints (#12574) 2026-04-08 15:07:38 -04:00
types 🔬 ci: Add TypeScript Type Checks to Backend Workflow and Fix All Type Errors (#12451) 2026-03-28 21:06:39 -04:00
.gitignore
babel.config.cjs
jest.config.mjs refactor: Use in-memory cache for App MCP configs to avoid Redis SCAN (#12410) 2026-03-26 14:44:31 -04:00
package.json 📦 chore: bump axios to exact v1.13.6, @librechat/agents to v3.1.63, @aws-sdk/client-bedrock-runtime to v3.1013.0 (#12488) 2026-03-31 14:49:31 -04:00
rollup.config.js
tsconfig-paths-bootstrap.mjs
tsconfig.build.json
tsconfig.json
tsconfig.spec.json