mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-05 03:09:58 +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>
60 lines
2.5 KiB
TypeScript
60 lines
2.5 KiB
TypeScript
import { type AttachmentKind, type AttachmentPolicy } from "../thread-rules.js";
|
|
import { type MessengerAttachment, type MessengerRefusalLabels, type MessengerTransport } from "../messenger.js";
|
|
/** A file between being picked and being on a message. */
|
|
export type UploadItem = {
|
|
key: string;
|
|
name: string;
|
|
kind: AttachmentKind;
|
|
bytes: number;
|
|
/** A `blob:` picture of it (the photo itself, a video's first frame). */
|
|
previewUrl?: string;
|
|
/** 0..1 while its bytes travel. */
|
|
progress: number;
|
|
state: "preparing" | "uploading" | "done" | "failed";
|
|
attachment?: MessengerAttachment;
|
|
};
|
|
export type UploadOptions = {
|
|
/** What may be attached. threadkit's default when left out. */
|
|
policy?: AttachmentPolicy;
|
|
/**
|
|
* Longest edge, in pixels, a photo is shrunk to before it is uploaded.
|
|
* A phone photo is 12 megapixels and several megabytes; nobody reads a
|
|
* conversation at that size, and every byte is stored until somebody
|
|
* deletes it. 0 sends the original.
|
|
*/
|
|
imageMaxEdge?: number;
|
|
/** What a shrunk photo must fit, in bytes. */
|
|
imageMaxBytes?: number;
|
|
};
|
|
export declare const DEFAULT_UPLOAD_OPTIONS: Required<Omit<UploadOptions, "policy">>;
|
|
export type UploadsController = {
|
|
items: UploadItem[];
|
|
/** Why something was not taken, in words. */
|
|
note: string | null;
|
|
clearNote: () => void;
|
|
add: (files: readonly File[]) => void;
|
|
remove: (key: string) => void;
|
|
retry: (key: string) => void;
|
|
/** Forget everything staged (after a send, or when the conversation changes). */
|
|
clear: () => void;
|
|
/** The uploads that are ready to go on a message, in the order picked. */
|
|
attachments: MessengerAttachment[];
|
|
/** Something is still on its way. */
|
|
busy: boolean;
|
|
};
|
|
/**
|
|
* Files on their way to a message: checked against the policy before a byte
|
|
* moves, photos shrunk in the browser, each uploaded through the app's
|
|
* `transport.upload` with its progress shown, a failure kept with Try again.
|
|
* The same rule that refuses a file here refuses it on the server
|
|
* (`@bitbaum/threadkit` `checkAttachment`), so the two cannot disagree.
|
|
*/
|
|
export declare function useUploads({ transport, conversationId, options, labels, failedText, }: {
|
|
transport: MessengerTransport;
|
|
conversationId: string | null;
|
|
options?: UploadOptions;
|
|
labels: MessengerRefusalLabels;
|
|
/** "{name} could not be uploaded." */
|
|
failedText: string;
|
|
}): UploadsController;
|
|
//# sourceMappingURL=use-uploads.d.ts.map
|