🧳 fix: Carry Custom Endpoint Names Through Chat URLs - #15424
🧳 fix: Carry Custom Endpoint Names Through Chat URLs#15424abhishekbiswas772 wants to merge 1 commit into
Conversation
|
👋 Thanks for the contribution! LibreChat merges all changes into Nothing is needed from you; your commits, reviews and discussion are unchanged. If the diff now shows files you did not touch, rebase onto git remote add upstream https://github.com/danny-avila/LibreChat.git
git fetch upstream dev
git rebase upstream/dev
git push --force-with-leaseMaintainers: apply the |
`createPayload` interpolated the endpoint name straight into the chat URL, so a custom endpoint named `Company/API` produced `/api/agents/chat/Company/API`. The slash reads as a path separator, the request no longer matches the router's `/:endpoint`, and it falls through to the catch-all handler, which answers `404 Endpoint not found`. Encoding the name keeps it a single path segment. Express matches the encoded segment and decodes it back, and the endpoint the server acts on comes from the request body regardless, so nothing else has to change. Closes danny-avila#15270
9258c1e to
0ea7400
Compare
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Fixes #15270.
createPayloadinterpolated the endpoint name straight into the chat URL:Custom endpoint names are user-defined, so a name like
Company/APIproduces/api/agents/chat/Company/API. The slash reads as a path separator, the request stops matching the router's/:endpointinapi/server/routes/agents/chat.js, and it falls through to the catch-all handler inpackages/api/src/middleware/notFound.ts— which is where the reportedEndpoint not foundactually comes from. It is the generic API 404, not an endpoint-resolution error, which is why the message gives no hint about the real cause.Encoding the name keeps it a single path segment. Express matches the encoded segment and decodes
req.params.endpointback to the original value, and the endpoint the server acts on is read from the request body regardless (req.params.endpointis never read anywhere in the codebase — the segment exists only for routing), so nothing downstream has to change.This also aligns the call site with the
encodeURIComponentconvention already used throughoutapi-endpoints.ts.I went with encoding rather than rejecting slashes at config-validation time, since the issue offers both and encoding keeps working configurations working. Happy to switch to validation instead if maintainers prefer that direction.
Change Type
Testing
Confirmed the routing behaviour empirically against this repo's Express version before writing the fix — a raw slash reproduces the exact reported 404, and the percent-encoded form matches
/:endpointand decodes back toCompany/API.Added
packages/data-provider/specs/createPayload.spec.ts:?,=,#)The slash and unsafe-character cases fail without the fix; the rest pass either way, confirming existing URLs are unchanged.
Test Configuration:
Node.js v24.16.0, Windows. Reproduces with any custom endpoint whose
namecontains/.Checklist