Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extraheaders within the socket connection not being updated. #1507

Open
deepakjyadav01 opened this issue Nov 8, 2024 · 1 comment
Open
Labels
bug Something isn't working frontend Pertains to the frontend. needs-triage

Comments

@deepakjyadav01
Copy link

deepakjyadav01 commented Nov 8, 2024

Describe the bug
I'm using a custom frontend repo and chainlit/react-client lib to establish a WebSocket connection with Chainlit. The issue is that the X-Chainlit-Thread-Id header doesn’t update as expected when I try to set a old thread ID dynamically through idToResume. The header only updates correctly if the page is refreshed. Without a refresh, the header retains an old value or fails to set the new thread ID, resulting in a new connection without the intended idToResume value in the header.

According to my understanding :
IdToResume hook sets the X-Chainlit-Thread-Id header and setIdtoResume from chatInteract can be used to set IdToResume.
Accordinglt whenever IdToResume changes sessionstate recoil state(if you are using one) should get updated right? but it only happens when i reload/refresh the page.

To Reproduce
Steps to reproduce the behavior:

  1. Open the custom frontend and initiate a WebSocket connection with a specific idToResume set in the headers.
  2. Click on an item or perform an action that updates idToResume and should trigger a new WebSocket connection with the updated X-Chainlit-Thread-Id.
  3. Observe that the header does not update as expected and either has an empty X-Chainlit-Thread-Id or retains the old value.
  4. Refresh the page and note that the header is then correctly updated with the intended idToResume.
  5. Expected behavior
  6. The X-Chainlit-Thread-Id header should update dynamically whenever idToResume is changed, without requiring a page refresh to set the new thread ID properly in the WebSocket connection.

I am looking for guidance on the best way to dynamically set X-Chainlit-Thread-Id without refreshing the page each time idToResume is updated. Is there a recommended way to ensure the WebSocket connection uses the updated idToResume header immediately upon reconnecting?
I tried using clear() and disconnect but still facing difficulties in trying to get the header updated when reconnecting to the old chat using Idtoresume hook, though the same functionality works when i reload the page.

@dosubot dosubot bot added bug Something isn't working frontend Pertains to the frontend. labels Nov 8, 2024
dokterbob pushed a commit that referenced this issue Dec 12, 2024
This improves Socket.IO configuration and CORS handling for cross-origin use cases,
particularly focusing on scenarios where Chainlit is embedded in other websites (copilot, closes #1279) or deployed behind load balancers:

- Make Socket.IO client transports configurable via `project.transports` setting
- Move connection parameters from headers to Socket.IO auth object for better
  websocket compatibility
- Update CORS handling to properly support authenticated cross-origin requests. Closes #1359.
- Remove unnecessary task start/end events from window_message handler

BREAKING CHANGE: For cross-origin deployments, wildcard "*" is no longer supported
in allow_origins when using authenticated connections. Specific origins must be
listed in the project config.

Possibly resolves #719, #1339, #1369, #1407, #1492, #1507.
@dokterbob
Copy link
Collaborator

Should be resolved with #1575. Please let me know if you experience any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working frontend Pertains to the frontend. needs-triage
Projects
None yet
Development

No branches or pull requests

2 participants