mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-04 04:47:19 +01:00
The four steps 0.41 left in the README are done: - One frame: TypingBox (typing.tsx) draws the voice bar, box, strip, text, tools row and the take's problem for both. The field's tools row is the composer's ck-tools, so its paperclip and microphone are bare icons like the composer's (they were bordered circles). Frame and text share one set of rules in styles.css; each shape keeps only its differences. - One text hookup: useTypingText (dictation + appendTranscript + clipToMaxLength + the latest-text ref). - One submit-key rule: submitKeyAction in composer.ts, exported. - Same controls on both: Composer `attachments`; DictationField `handleRef` (DictationFieldHandle) and `attachExtras`. Public APIs are additive. All existing tests unchanged; new unit, render and browser checks (390px, 320px dark, desktop). Claude-Session: https://claude.ai/code/session_019MDtmv1SAs6YZn4FrewbXR Co-authored-by: Claude <noreply@anthropic.com>
149 lines
7.9 KiB
TypeScript
149 lines
7.9 KiB
TypeScript
import { type ReactNode, type Ref, type RefObject } from "react";
|
|
import { type ComposerMode, type ComposerSendResult } from "../composer.js";
|
|
import type { DictationProblem } from "../dictation.js";
|
|
import type { Attachment, AttachOptions, AttachmentNotes } from "../attachments.js";
|
|
import type { UseDictationOptions } from "./use-dictation.js";
|
|
import type { AttachmentsController } from "./use-attachments.js";
|
|
import type { AttachExtra, AttachMenuLabels } from "./AttachMenu.js";
|
|
import { type TypingAttachLabelOverrides, type TypingHandle } from "./typing.js";
|
|
export type ComposerLabels = {
|
|
send: string;
|
|
stop: string;
|
|
voice: string;
|
|
voiceStop: string;
|
|
cancelRecording: string;
|
|
confirmRecording: string;
|
|
listening: string;
|
|
transcribing: string;
|
|
attach: string;
|
|
/** The Camera / Photos / Files sheet the paperclip opens on a phone. */
|
|
attachMenu: Omit<AttachMenuLabels, "attach">;
|
|
/** The placeholder while a turn runs and the next message will be queued. */
|
|
queue: string;
|
|
remove: (name: string) => string;
|
|
dismiss: string;
|
|
/** Re-send a take whose transcription failed (it is kept). */
|
|
retryTake: string;
|
|
dictation: Record<DictationProblem, string>;
|
|
/** Why a file did not attach. */
|
|
attachNotes: AttachmentNotes;
|
|
};
|
|
export declare const DEFAULT_COMPOSER_LABELS: ComposerLabels;
|
|
export type ComposerVoice = Omit<UseDictationOptions, "onText">;
|
|
/** What a page can do to a composer it does not type into (`handleRef`):
|
|
* `setText` replaces the draft, `addFiles` stages as the paperclip would,
|
|
* `focus`, and `submit` presses Send with the same checks as `Enter`. The
|
|
* same shape as `DictationFieldHandle`. */
|
|
export type ComposerHandle = TypingHandle;
|
|
/** Overrides: every label is optional, including each dictation and attachment note. */
|
|
export type ComposerLabelOverrides = Partial<Omit<ComposerLabels, "dictation" | "attachNotes" | "attachMenu">> & {
|
|
dictation?: Partial<ComposerLabels["dictation"]>;
|
|
} & TypingAttachLabelOverrides;
|
|
export type ComposerProps = {
|
|
/** Deliver what was written. Return `false` (or resolve to it) to keep the
|
|
* draft — a failed send is retried from the same box, not retyped. */
|
|
onSend: (text: string, attachments: Attachment[]) => ComposerSendResult | Promise<ComposerSendResult>;
|
|
placeholder: string;
|
|
ariaLabel?: string;
|
|
disabled?: boolean;
|
|
/** Typing is fine, sending is not — shown as the send button's title. */
|
|
sendBlockedReason?: string | null;
|
|
sending?: boolean;
|
|
/** Given, the send slot becomes Stop while `sending`: a turn you cannot
|
|
* cancel is what makes a slow answer feel broken. */
|
|
onStop?: () => void;
|
|
/** What an attachments-only send says. Omit and empty text cannot send. */
|
|
attachmentOnlyText?: string;
|
|
/** Attachments the APP holds rather than the composer — things chatkit has
|
|
* no model for (orangecat's references to the person's own listings, a
|
|
* photo already shrunk and staged by the app) and shows in `header`. They
|
|
* count toward "may this send?" exactly like the composer's own, so a
|
|
* message that is only such an attachment can be sent; without this the
|
|
* send button stayed dead for it. Pair with `attachmentOnlyText`. */
|
|
heldAttachments?: number;
|
|
/** The app takes a message while a turn runs and sends it when the turn
|
|
* ends. Then Send stays live beside Stop and the placeholder says the
|
|
* message will be queued — the next thought is typed while the last one is
|
|
* still being answered, never held until a spinner stops. */
|
|
queue?: boolean;
|
|
/** Attachments on, optionally with the app's own limits and `readFile`, its
|
|
* own reading of a file chatkit would refuse or read differently (a PDF —
|
|
* see `@bitbaum/chatkit/pdf`). Off by default: only offer what the app's
|
|
* API accepts. */
|
|
attach?: boolean | AttachOptions;
|
|
/** The staged files, held by the APP (0.43): `const files =
|
|
* useAttachments(opts)`, passed here, so the app can read or stage them
|
|
* outside the box. The composer still sends them with `onSend` and clears
|
|
* them after a send it may clear. Without it the composer stages into its
|
|
* own — `DictationField`'s `attachments`, the same prop. */
|
|
attachments?: AttachmentsController;
|
|
/** The app's own rows in the same attach sheet, under Camera · Photos ·
|
|
* Files (one of the person's things, a saved note). With `attach: false`
|
|
* the paperclip opens a sheet of only these rows. */
|
|
attachExtras?: readonly AttachExtra[];
|
|
/** Fill, stage, focus or send from outside the box (see `ComposerHandle`). */
|
|
handleRef?: Ref<ComposerHandle>;
|
|
/** The microphone. On by default. Pass `transcribeUrl` (or `transcribe`) so
|
|
* it still works where the browser recogniser does not — that fallback is
|
|
* what makes the mic never a dead button. `false` only for a surface that
|
|
* truly cannot take speech. */
|
|
voice?: ComposerVoice | false;
|
|
modes?: readonly ComposerMode[];
|
|
mode?: string;
|
|
onModeChange?: (id: string) => void;
|
|
/** "/" typed into an empty composer — open a library instead of typing. */
|
|
onEmptySlash?: () => void;
|
|
value?: string;
|
|
onValueChange?: (text: string) => void;
|
|
defaultValue?: string;
|
|
inputRef?: RefObject<HTMLTextAreaElement | null>;
|
|
density?: "comfortable" | "compact";
|
|
/**
|
|
* `"stacked"` (the default) is the box of an assistant: the words on top,
|
|
* the tools in a row under them. `"inline"` is the box of a messenger: one
|
|
* row — attach, the words, the microphone, send — that grows upward as the
|
|
* text does. A conversation between people is mostly short lines, and a box
|
|
* two rows tall under each of them is a fifth of a phone given to chrome.
|
|
*/
|
|
layout?: "stacked" | "inline";
|
|
/** A message of only attachments goes out with no words at all (a
|
|
* messenger: a photo needs no caption). `attachmentOnlyText` is the other
|
|
* answer, for a model that must be told something. */
|
|
attachmentsAlone?: boolean;
|
|
/** Outside the box, above it (suggestion chips). */
|
|
above?: ReactNode;
|
|
/** Inside the box, above the text (scope pills, an error). */
|
|
header?: ReactNode;
|
|
/** Extra tools after attach and voice (a model picker, a library). */
|
|
tools?: ReactNode;
|
|
/** Just before the send button. */
|
|
trailing?: ReactNode;
|
|
/**
|
|
* What the send slot does while there is nothing to send (a messenger: record
|
|
* a voice message). Without it the slot is a disabled arrow. The slot never
|
|
* moves: the same place sends words, or a voice.
|
|
*/
|
|
emptyAction?: {
|
|
label: string;
|
|
icon: ReactNode;
|
|
onPress: () => void;
|
|
};
|
|
/** Inside the box, under the controls. */
|
|
footer?: ReactNode;
|
|
hint?: string;
|
|
/** Where staged pictures and files sit: under the text (the default) or
|
|
* above it, as the ChatGPT and Claude apps draw them. ChatApp uses above. */
|
|
stagedPosition?: "above" | "below";
|
|
labels?: ComposerLabelOverrides;
|
|
autoFocus?: boolean;
|
|
};
|
|
/**
|
|
* THE composer: write words — or say them, or paste a screenshot — and send
|
|
* them. Enter sends, Shift+Enter breaks the line, an IME composition never
|
|
* sends half a word. 16px text, so iOS never zooms the page on focus.
|
|
*
|
|
* Extracted from loki `components/composer/Composer.tsx` (itself the merge of
|
|
* four composers in one app), with heidi's microphone and orangecat's lessons.
|
|
*/
|
|
export declare function Composer({ onSend, placeholder, ariaLabel, disabled, sendBlockedReason, emptyAction, sending, onStop, attachmentOnlyText, heldAttachments, queue, attach, attachments: attachmentsGiven, attachExtras, handleRef, voice, modes, mode, onModeChange, onEmptySlash, value, onValueChange, defaultValue, inputRef, density, layout, attachmentsAlone, above, header, tools, trailing, footer, hint, stagedPosition, labels: labelOverrides, autoFocus, }: ComposerProps): import("react").JSX.Element;
|
|
//# sourceMappingURL=Composer.d.ts.map
|