docs(chat): avoid sdk_client changes; skeleton MessageBus as host API

This commit is contained in:
LeCoffre Deployment 2025-10-05 12:06:31 +00:00
parent 1267279322
commit 69eb9b9117

View File

@ -3,9 +3,10 @@
This document specifies a chat feature embedded as an iframe of `ihm_client`, communicating with the host application through `postMessage`. It maximizes reuse of existing `MessageType` where appropriate and introduces a minimal, versioned `CHAT_*` message family for chat-specific flows.
### Scope and roles
- **Host app**: embeds `ihm_client` in an iframe, uses `sdk_client` or `skeleton` `MessageBus` to exchange messages.
- **Host app**: embeds `ihm_client` in an iframe, uses the `skeleton` `MessageBus` (or host-native bus) to exchange messages.
- **ihm_client (iframe)**: renders the chat UI, persists data, validates tokens, and routes messages.
- **sdk_common**: unchanged. No modification required for the chat feature.
- **sdk_client**: unchanged. No modification required; chat can be driven via `skeleton` `MessageBus`.
- **skeleton**: integrates the iframe and routes messages via `iframe.contentWindow.postMessage` with strict `origin`.
### Reused MessageType and rationale
@ -79,10 +80,9 @@ Types used above:
- `skeleton/src/sdk/MessageBus.ts`:
- Reuse existing `postMessage` to iframe; add a registry for pending requests keyed by `messageId` to resolve promises on `correlationId`.
- Filter by strict `origin`.
- `sdk_client`:
- Provide a facade `chat.ts` exporting: `initChat`, `subscribe`, `unsubscribe`, `sendMessage`, `setTyping`, `markRead`, `getHistory`, `listChannels` (helpers and runtime checks local to this module).
- `sdk_common`:
- No changes.
Note: `sdk_client` remains unchanged. If desired later, a thin optional wrapper can live outside `sdk_client`.
### State flows
1) Ready
@ -140,8 +140,8 @@ if (event.data.type === 'CHANNEL_MESSAGE' && event.data.payload?.action === 'SEN
}
```
### Delivery plan (no changes to `sdk_common`)
1) `sdk_client`: add a local `chat.ts` facade (helpers, runtime guards) and enhance `skeleton` `MessageBus` for request/response correlation.
### Delivery plan (no changes to `sdk_common` or `sdk_client`)
1) `skeleton`: enhance `MessageBus` for request/response correlation and strict origin filtering (host-side only).
2) `ihm_client`: implement `CHANNEL_MESSAGE` handlers in `registerAllListeners()` and a basic chat UI (list, thread, composer).
3) Persistence: reuse service worker/IndexedDB; add `channels`/`messages` stores and outbox logic within `ihm_client`.
4) Tests: unit (router handlers, runtime guards), integration (subscribe, send/recv, history, typing/read), E2E (Playwright, mocked backend).