mirror of
https://github.com/bitbaum/chatkit.git
synced 2026-12-04 00:27:49 +01:00
The model button, the bring-your-own-key sheet and the link under a failed
turn ("Get a pass") were built in Heidi. They are the chat's experience, so
they belong here: ModelChip for the header, ModelSheet driven by the
product's vendor allowlist and key check, and ChatFailure.action/retry so a
transport can say what the reader can do next and when Retry cannot help.
Claude-Session: https://claude.ai/code/session_019MDtmteJuDGFouA1itJ5tM
Co-authored-by: Claude <noreply@anthropic.com>
101 lines
3.9 KiB
TypeScript
101 lines
3.9 KiB
TypeScript
/**
|
|
* Which model answers, and the reader's own key: the button in a chat's
|
|
* header and the sheet it opens.
|
|
*
|
|
* WHY IT IS HERE. Every product that offers "bring your own key" needs the
|
|
* same three things on screen: which model answers now, where to get a key,
|
|
* and a check that says at once whether the key works and which models it
|
|
* reaches. Heidi built them for itself; a second product would have built
|
|
* them again. The screen is the package's; what the key is checked against,
|
|
* where it is kept and which vendors are allowed stay the product's (and
|
|
* `@bitbaum/ai-kit`'s, whose `BYOK_VENDORS` and `probeByokKey` are what a
|
|
* product normally passes in).
|
|
*
|
|
* WHAT IT DOES NOT DO. It never sends a key anywhere itself: `check` is the
|
|
* product's, and so is storing what `onSave` is handed. It does not choose a
|
|
* vendor list: an open base URL would be a server-side request forgery hole,
|
|
* so the list is the product's allowlist.
|
|
*/
|
|
/** A vendor a key may be for. `@bitbaum/ai-kit`'s `BYOK_VENDORS` has this shape. */
|
|
export type ModelVendor = {
|
|
id: string;
|
|
label: string;
|
|
/** Where the reader creates a key. */
|
|
keyUrl?: string;
|
|
/** A placeholder for the key field, e.g. `sk-or-…`. Not validation. */
|
|
keyHint?: string;
|
|
/** A placeholder for the model field when the vendor lists none. */
|
|
modelExample?: string;
|
|
};
|
|
/** The reader's own model, as the product stores it. */
|
|
export type ModelChoice = {
|
|
vendor: string;
|
|
key: string;
|
|
model: string;
|
|
};
|
|
/** What the product's check of a key found. */
|
|
export type ModelCheck = {
|
|
ok: boolean;
|
|
/** Models this key can use, best first. */
|
|
models?: readonly string[];
|
|
/** The one to preselect. */
|
|
suggested?: string | null;
|
|
/** The vendor's own words when it refused, e.g. "insufficient credits". */
|
|
message?: string;
|
|
/** False when the vendor could not be reached at all: not the key's fault. */
|
|
reachable?: boolean;
|
|
};
|
|
export type ModelSheetLabels = {
|
|
title: string;
|
|
lead: string;
|
|
close: string;
|
|
/** Shown above the free models, e.g. "Without a key, these answer, in this order:". */
|
|
freeNow: string;
|
|
vendor: string;
|
|
getKey: string;
|
|
key: string;
|
|
keyPlaceholder: string;
|
|
pasteHint: string;
|
|
checking: string;
|
|
model: string;
|
|
strongest: string;
|
|
use: string;
|
|
connected: string;
|
|
connectedWith: string;
|
|
failed: string;
|
|
unreachable: string;
|
|
vendorSaid: string;
|
|
remove: string;
|
|
/** Optional: where the key goes, said plainly above nothing else. */
|
|
safetyTitle?: string;
|
|
safetyBody?: string;
|
|
whyTitle?: string;
|
|
whyBody?: string;
|
|
};
|
|
export declare const DEFAULT_MODEL_SHEET_LABELS: ModelSheetLabels;
|
|
/**
|
|
* The button in a chat's header. Everybody gets it, not only somebody who has
|
|
* connected a key: without one it was nowhere, and the only way to the sheet
|
|
* was a settings page. It names the reader's own model, or says `label`
|
|
* ("Model") while the product's answers.
|
|
*/
|
|
export declare function ModelChip({ model, label, onOpen, }: {
|
|
model: string | null | undefined;
|
|
label: string;
|
|
onOpen: () => void;
|
|
}): import("react").JSX.Element;
|
|
export declare function ModelSheet({ open, onClose, vendors, current, check, onSave, onClear, freeModels, labels: overrides, }: {
|
|
open: boolean;
|
|
onClose: () => void;
|
|
/** The vendors a key may be for: the product's allowlist. */
|
|
vendors: readonly ModelVendor[];
|
|
current: ModelChoice | null;
|
|
/** The product's check of a key, normally its own route around ai-kit's `probeByokKey`. */
|
|
check: (vendor: string, key: string) => Promise<ModelCheck>;
|
|
onSave: (choice: ModelChoice) => void;
|
|
onClear: () => void;
|
|
/** What answers without a key, in order, so the choice has two sides. */
|
|
freeModels?: readonly string[];
|
|
labels?: Partial<ModelSheetLabels>;
|
|
}): import("react").JSX.Element;
|
|
//# sourceMappingURL=ModelSheet.d.ts.map
|