mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-04 07:37:26 +01:00
* docs: the fleet's chats side by side Every product renders chatkit's Composer, most render ChatScreen and ChatThread, but the app around them — chat list, New chat, Temporary chat, titles, rename/delete, restore on reload, the queue, attachment defaults — is written again in each product. One table, read from each repo's main on 2026-10-27, with the file each cell comes from. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE * feat(app): ChatApp, the whole chat app every product shares The pieces were shared; the app was not. ChatApp composes ChatScreen, Composer and ChatThread and owns what each product re-implemented: - the header (Chats · title · New chat · More with Temporary chat, Share, Rename, Delete) as frosted pills, with headerStart/headerEnd slots; - the chat list: a <dialog> drawer on a phone (Escape, focus trap and restore from the browser; opens on its close button, not the search box), a rail when wide; search, Today/Yesterday/Earlier, one row anatomy (title, date, one "…" → Rename · Delete as equal cells); - New chat; Temporary chat that writes nothing and ends on leaving; - titles from the first message (Heidi's rule) or makeTitle(); - the open chat restored on reload (or driven by conversationId); - turns per conversation that keep running in the background, Stop that keeps what arrived, Retry on a failure, a queue behind a running answer; - attachments on by default, staged above the text, shown in the turn. Storage is an adapter: ConversationStore (list/get/create/append/rename/ remove) with localConversationStore (versioned, never throws, quota drops the oldest) and httpConversationStore (Heidi's REST shape, serverWritesTurns for routes that store turns themselves). The product supplies the transport and its words. Additive: ChatScreen, Composer and ChatThread behave as before; ChatMessageData gains optional attachments and Composer an optional stagedPosition. Unit tests cover grouping, titles, search, dates, restore and both stores (with storage that throws and a quota); test/browser-app.mjs drives demo/app.html at 390px and 1440px. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE --------- Co-authored-by: Claude <noreply@anthropic.com>
63 lines
3.0 KiB
TypeScript
63 lines
3.0 KiB
TypeScript
/**
|
|
* Where a ChatApp keeps its conversations. Storage is an ADAPTER: the screen
|
|
* reads and writes through `ConversationStore` and never knows whether the
|
|
* chats are on the device or on a server. Two reference adapters:
|
|
*
|
|
* localConversationStore({ key }) the device — signed-out chats
|
|
* httpConversationStore({ baseUrl }) the product's server — signed-in chats
|
|
*/
|
|
import { type ConversationStore } from "./conversations.js";
|
|
type KeyValue = Pick<Storage, "getItem" | "setItem" | "removeItem">;
|
|
/** Bumped when the stored shape changes; an older shape is read as empty
|
|
* rather than misread. */
|
|
export declare const LOCAL_STORE_VERSION = 1;
|
|
/** A store in memory: a temporary chat, a test, a page with no storage. */
|
|
export declare function memoryConversationStore(): ConversationStore;
|
|
/**
|
|
* Conversations on the device. Never throws: storage that is missing, full,
|
|
* blocked or holding something unreadable degrades to memory for this page,
|
|
* so the chat still works and simply is not there after a reload.
|
|
*
|
|
* Layout (versioned): `<key>:v1` holds the list, `<key>:v1:<id>` each chat's
|
|
* messages — so one long chat can be evicted without losing the others. When
|
|
* the quota is reached the OLDEST chats are dropped until the write fits.
|
|
*/
|
|
export declare function localConversationStore({ key, storage, limit, }?: {
|
|
/** Namespace on the device. One per product (and per signed-out person, if
|
|
* the device is shared and the product can tell them apart). */
|
|
key?: string;
|
|
/** Defaults to localStorage. `null` keeps everything in memory. */
|
|
storage?: KeyValue | null;
|
|
/** Most chats kept; the oldest go first. */
|
|
limit?: number;
|
|
}): ConversationStore;
|
|
export type HttpConversationStoreOptions = {
|
|
/** The collection, e.g. "/api/conversations". */
|
|
baseUrl: string;
|
|
/** Headers on every request (an auth token), or a function returning them. */
|
|
headers?: Record<string, string> | (() => Record<string, string>);
|
|
/** Defaults to the global fetch. */
|
|
fetch?: typeof fetch;
|
|
/**
|
|
* The product's own chat route already writes every turn (Heidi's
|
|
* `/messages`, Loki's `/api/loki`): then `append` sends nothing, so a turn
|
|
* is never stored twice.
|
|
*/
|
|
serverWritesTurns?: boolean;
|
|
};
|
|
/**
|
|
* Conversations on the product's server, over this REST shape (Heidi's
|
|
* `/api/conversations`, generalised):
|
|
*
|
|
* GET {base} → { conversations: [{ id, title, updatedAt }] }
|
|
* POST {base} { title } → { conversation: { id, title, updatedAt } }
|
|
* GET {base}/{id} → { conversation, messages: [...] } 404 = gone
|
|
* POST {base}/{id}/messages { message } → 2xx
|
|
* PATCH {base}/{id} { title } → 2xx
|
|
* DELETE {base}/{id} → 2xx
|
|
*
|
|
* A failed request throws an Error naming the call; ChatApp shows it in words.
|
|
*/
|
|
export declare function httpConversationStore({ baseUrl, headers, fetch: fetchImpl, serverWritesTurns, }: HttpConversationStoreOptions): ConversationStore;
|
|
export {};
|
|
//# sourceMappingURL=stores.d.ts.map
|