Files
chatkit/dist/react/MessengerScreen.d.ts
T
CatoandClaude e690b2254a Messenger: people talking to people, and to the agents among them (0.29.0) (#82)
* 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>
2026-11-12 16:26:03 +01:00

77 lines
3.9 KiB
TypeScript

import { type ReactNode, type RefObject } from "react";
import { type MessengerAgent, type MessengerConversation, type MessengerDrafts, type MessengerParticipant, type MessengerTransport } from "../messenger.js";
import { type ComposerLabelOverrides, type ComposerVoice } from "./Composer.js";
import { type ConversationListProps } from "./ConversationList.js";
import type { RenderLink } from "./Markdown.js";
import { type MessengerLabelOverrides } from "./messenger-labels.js";
import { type UploadOptions } from "./use-uploads.js";
export type MessengerComposerOptions = {
/** The microphone. Pass `{ transcribeUrl }` so it works where the browser's
* recogniser does not. */
voice?: ComposerVoice | false;
/** What may be attached and how photos are shrunk. `false` offers no files
* even when the transport can upload. */
attach?: UploadOptions | false;
/** Inside the box, above the words: a product's own line ("Sending as …"). */
header?: ReactNode;
/** Around the box: a menu that needs the keys before the box does. */
wrap?: (box: ReactNode) => ReactNode;
inputRef?: RefObject<HTMLTextAreaElement | null>;
/** What a conversation's box holds when it is opened by a link that says
* what to write. Wins over a kept draft, once. */
initialDraft?: (conversationId: string) => string | undefined;
labels?: ComposerLabelOverrides;
};
export type MessengerProps = {
/** Who is using it. `id` is what their own messages carry as `authorId`. */
viewer: {
id: string;
};
/** The app's backend (see `MessengerTransport`). */
transport: MessengerTransport;
/** Agents people can bring in by naming them. */
agents?: readonly MessengerAgent[];
/** The open conversation, when the app keeps it (the URL). */
conversationId?: string | null;
onConversationChange?: (id: string | null) => void;
composer?: MessengerComposerOptions;
/** Where unsent words are kept. Default: this tab (`sessionDrafts`). */
drafts?: MessengerDrafts;
/** Under the list's title. */
listHeader?: ReactNode;
/** At the end of a conversation's top bar: a product's own controls. */
headerActions?: (conversation: MessengerConversation) => ReactNode;
/** Where the name in the top bar leads (a profile), if anywhere. */
profileHref?: (participant: MessengerParticipant) => string | undefined;
search?: ConversationListProps["search"];
renderLink?: RenderLink;
/** The product's own mark for its agent, where it has no picture. */
agentMark?: ReactNode;
/**
* `"parent"` (the default) fills the box it is given — give it a height.
* `"viewport"` is the whole display and follows the visual viewport, so the
* box rides above the phone keyboard.
*/
fill?: "parent" | "viewport";
locale?: string;
timeZone?: string;
agentPatienceMs?: number;
labels?: MessengerLabelOverrides;
className?: string;
};
/**
* The messenger, whole: the list of conversations, the conversation, the box.
* On a phone it is one screen at a time — the list, then the conversation
* with its own way back — and from 48rem of its own width the two sit side
* by side. The app gives it a `transport` and a place to live; it has no
* database, no websocket and no storage of its own.
*
* <Messenger viewer={{ id }} transport={transport} agents={[cat]}
* conversationId={id} onConversationChange={setId}
* composer={{ voice: { transcribeUrl: "/api/transcribe" } }} />
*
* An app that needs its own arrangement uses the parts it is made of:
* `useMessenger`, `ConversationList`, `MessageThread`.
*/
export declare function Messenger({ viewer, transport, agents, conversationId, onConversationChange, composer, drafts, listHeader, headerActions, profileHref, search, renderLink, agentMark, fill, locale, timeZone, agentPatienceMs, labels: labelOverrides, className, }: MessengerProps): import("react").JSX.Element;
//# sourceMappingURL=MessengerScreen.d.ts.map