`@chat-adapter/web` always names itself `web`, so two web adapters share thread IDs

Aperta
#1,179 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
api, backend

Direzione di ricerca

Read packages/adapter-web/src/adapter.ts, especially the WebAdapter name and thread ID methods cited in the issue, then trace how Chat resolves adapter keys from thread ID prefixes. Check the adapter's existing tests for naming and thread ID behavior. Done when separate web adapters produce IDs that chat.thread() can resolve independently, including IDs returned by threadIdFor.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Description

WebAdapter hard-codes name = "web" and the web: thread ID prefix. Chat resolves a thread by the part of its ID before the first colon and looks that up in the keys of adapters. So a web adapter registered under any key other than web gets thread IDs that chat.thread() can't resolve. Two web adapters, say a support chat and a sales chat, also get the same thread ID for the same user and conversation, so they share subscriptions, locks, and history.

threadIdFor doesn't help, because decodeThreadId throws for any prefix other than web:.

Steps to Reproduce
  1. Register two web adapters under the keys support and sales.
  2. Send the same conversation ID from the same user to each webhook.
  3. Look at thread.id in the handler, then call chat.thread(thread.id).
Expected Behavior

Each adapter has its own name and thread prefix, and chat.thread() resolves its thread IDs.

Actual Behavior

Both handlers see web:u1:c1. chat.thread("web:u1:c1") throws Adapter "web" not found for thread ID "web:u1:c1". With threadIdFor returning sales:u1:c1, decodeThreadId throws Invalid web thread id: sales:u1:c1.

Code Sample
import { Chat } from "chat";
import { createMemoryState } from "@chat-adapter/state-memory";
import { createWebAdapter } from "@chat-adapter/web";

const getUser = () => ({ id: "u1" });
const support = createWebAdapter({ userName: "bot", getUser });
const sales = createWebAdapter({ userName: "bot", getUser });
const chat = new Chat({ userName: "bot", state: createMemoryState(), adapters: { support, sales } });
await chat.initialize();

chat.onDirectMessage(async (thread) => console.log(thread.id)); // "web:u1:c1" for both

for (const key of ["support", "sales"] as const) {
  const body = { id: "c1", messages: [{ id: `m-${key}`, role: "user", parts: [{ type: "text", text: "hi" }] }] };
  await chat.webhooks[key](new Request("https://app.example/api/chat", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }));
}

chat.thread("web:u1:c1"); // Adapter "web" not found for thread ID "web:u1:c1"
Chat SDK Version

4.45.0

Node.js Version

24.21.0

Platform Adapter

Other

Operating System

Linux

Additional Context

A name option on createWebAdapter, defaulting to "web", would fix it. The adapter would use it for name, the default threadIdFor, encodeThreadId, and decodeThreadId. We do this today by overriding name and wrapping both thread ID methods. I can open a PR if you want it.

Lingua principale
TypeScript
Stelle
2.5k
Fork
355
Merge medio
2g 15h
PR unite (30g)
42

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel/chat

Tutte le issue di vercel/chat

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.