mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-03 20:27:26 +01:00
* Messenger: people talking to people, and to the agents among them (0.26.0) OrangeCat's direct messages were built in the app, so what was wrong with them could not be fixed for the next product: an agent's answer in a conversation between two people looked like the other person's, nothing said an agent was taking part, top bar and a two-row box took half a phone, and nothing could be attached. This is the messenger as a package. @bitbaum/chatkit/messenger: Messenger (the whole screen) and its parts useMessenger, ConversationList, MessageThread, MessageAttachments. The app implements MessengerTransport; the package has no database, websocket or storage. styles/messenger.css is the embedded sheet plus the Messenger's section, without ChatApp. - An agent is told from a person by the shape of its face, an Agent mark with whom it answered for, and an outlined bubble; the top bar says it is in the conversation; naming it shows that it is thinking, and says so if it never answers. - Files: Camera, Photos, Videos, Files, checked against the attachment policy before an upload starts, photos shrunk in the browser, progress and Try again per file, a full-screen viewer, a film drawn as its still. - The thread: runs, day lines, a New line, ticks from readState, a failed message kept with Try again, earlier messages loaded above with the reader's place kept, one bubble per message however often it arrives. - Composer: layout="inline", attachmentsAlone, attach.take, attach.accept, a "videos" source, files dropped onto the box. Defaults unchanged. The state is one pure function (messengerReducer), tested in Node. test/browser-messenger.mjs drives demo/messenger.html at 390px, 320px dark and 1280px. It found two defects before any product did: a read mark that cleared the badge without telling the server, and a page of history that pulled the reader to the end of the thread. threadkit 0.1.2 (attachment policy, mention matcher, readState) is merged and tagged but not on npm, so those rules are carried word for word in src/thread-rules.ts with threadkit's own tests; the file says when it goes. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmsmMXvM981mcszxEA6 * test(messenger): wait for the opened conversation before reading its thread Side by side, the conversation that was open can still be on screen with a "New" line of its own, so the check read the old thread on a slow runner. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019MDtmsmMXvM981mcszxEA6 --------- Co-authored-by: Claude <noreply@anthropic.com>
70 lines
3.3 KiB
TypeScript
70 lines
3.3 KiB
TypeScript
import { type ReactNode } from "react";
|
|
import { type AttachSource } from "../attachments.js";
|
|
export type AttachMenuLabels = {
|
|
/** The paperclip's name. */
|
|
attach: string;
|
|
/** The sheet's title. */
|
|
title: string;
|
|
close: string;
|
|
/** `videos` may be left out by an app that set its labels before the
|
|
* source existed: it then reads the default. */
|
|
sources: Record<Exclude<AttachSource, "videos">, string> & {
|
|
videos?: string;
|
|
};
|
|
};
|
|
export declare const DEFAULT_ATTACH_MENU_LABELS: AttachMenuLabels;
|
|
/**
|
|
* One of the app's own rows in the attach sheet, under Camera · Photos ·
|
|
* Files: an icon, what it adds (`label`), an optional second line. Every row
|
|
* has this one anatomy, so a product's "Your things" reads as part of the
|
|
* same sheet, not a second menu. Picking a row closes the sheet first.
|
|
*/
|
|
export type AttachExtra = {
|
|
id: string;
|
|
label: string;
|
|
detail?: string;
|
|
icon?: ReactNode;
|
|
onPick: () => void;
|
|
};
|
|
/**
|
|
* The paperclip, and what it opens on a phone: a sheet with Camera, Photos and
|
|
* Files — one input each. See `ATTACH_SOURCE_INPUT` for why three inputs and
|
|
* not one: a single mixed-`accept` input is what made a phone offer a recorder
|
|
* and no way to the screenshot.
|
|
*
|
|
* The sheet is a native `<dialog>` opened with `showModal()`: it renders in the
|
|
* browser's top layer, so a composer inside a transformed or overflow-clipped
|
|
* panel (a drawer, a floating rail) still gets a full-screen sheet — and the
|
|
* browser supplies Escape, the focus trap and focus restore.
|
|
*
|
|
* Every app that attaches anything gets this from the composer. An app with a
|
|
* custom box renders `<AttachMenu>` itself rather than a bare file input, and
|
|
* an app with more to bring into a message than files — one of the person's
|
|
* own things, a note the model reads every time — puts those rows in `extra`:
|
|
* they sit under Camera · Photos · Files in the same sheet, on every pointer,
|
|
* since a mouse cannot reach them through a file dialog.
|
|
*/
|
|
export declare function AttachMenu({ onFiles, disabled, labels, sources, accept, trigger, extra, rows, onOpenChange, }: {
|
|
onFiles: (files: FileList | null) => void;
|
|
disabled?: boolean;
|
|
labels?: AttachMenuLabels;
|
|
/** Which sources to offer, in order. An avatar or product-photo uploader
|
|
* passes `["camera", "photos"]`; one source skips the sheet entirely. */
|
|
sources?: readonly AttachSource[];
|
|
/** What a source asks the phone for, where `ATTACH_SOURCE_INPUT` is not it
|
|
* (a messenger's Files: `MESSAGE_FILES_ACCEPT`). One family per source. */
|
|
accept?: Partial<Record<AttachSource, string>>;
|
|
/** The button's content. Defaults to a paperclip icon; an uploader passes
|
|
* its own ("Add photo"). The button keeps chatkit's 44px target. */
|
|
trigger?: ReactNode;
|
|
/** The app's own rows under the three sources (see above). With it the
|
|
* sheet opens on every pointer. A row that should close the sheet calls
|
|
* the `close` it is given. */
|
|
extra?: (close: () => void) => ReactNode;
|
|
/** The app's rows as data — drawn with one anatomy (see `AttachExtra`).
|
|
* With them the sheet opens on every pointer; with no `sources` it holds
|
|
* only them. */
|
|
rows?: readonly AttachExtra[];
|
|
onOpenChange?: (open: boolean) => void;
|
|
}): import("react").JSX.Element;
|
|
//# sourceMappingURL=AttachMenu.d.ts.map
|