mirror of
https://github.com/bitbaum/kits.git
synced 2026-12-04 12:38:06 +01:00
ai-kit/choice: chooseChain, readOwnKey, preferFirst, pickableModels, redactKeys, checkOwnKey: whose model answers a request and whose money it spends, decided once instead of in each product. chatkit: ModelSheet `plan` (the product's paid way to a stronger model), `freeNote`, `ownTitle`; useModelOptions wires chip, sheet, browser store, key check and free list; ModelNudge under an answer a free model wrote. Claude-Session: https://claude.ai/code/session_019MDtmvTCDbJAYNKQpNyKzz Co-authored-by: Claude <noreply@anthropic.com>
162 lines
6.6 KiB
TypeScript
162 lines
6.6 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;
|
|
/** With `onFreePick`: the free models as a choice. */
|
|
pickTitle: string;
|
|
pickHint: string;
|
|
/** The choice that lets the product pick, in order. */
|
|
auto: string;
|
|
autoHint: string;
|
|
/** The link to `compareHref`, where the free models are compared. */
|
|
compare: string;
|
|
/** The chip's title when `served` names the model that last answered. */
|
|
answeredBy: string;
|
|
/** Optional: where the key goes, said plainly above nothing else. */
|
|
safetyTitle?: string;
|
|
safetyBody?: string;
|
|
whyTitle?: string;
|
|
whyBody?: string;
|
|
/**
|
|
* Optional, under the free models: what a reader gives up with them, e.g.
|
|
* "Free models answer simple questions well; a stronger one is more
|
|
* accurate on a hard one." Said where the choice is made, not after a wrong answer.
|
|
*/
|
|
freeNote?: string;
|
|
/** Optional heading above the key fields, once the sheet holds more than one way. */
|
|
ownTitle?: string;
|
|
/** With `plan`: the product's own paid way to a stronger model. */
|
|
planTitle: string;
|
|
planBody: string;
|
|
planAction: string;
|
|
/** Said instead of the offer to a reader who holds the plan. */
|
|
planActive: string;
|
|
};
|
|
/**
|
|
* The product's own paid way to a stronger model: the third choice beside the
|
|
* free models and the reader's own key. What it costs and what it buys are the
|
|
* product's (its plan page, `@bitbaum/paykit`); the sheet only says it exists
|
|
* and leads there. A product that sells nothing passes no `plan` and the sheet
|
|
* does not mention one.
|
|
*/
|
|
export type ModelPlan = {
|
|
/** This reader holds it: the sheet says so and offers nothing. */
|
|
active?: boolean;
|
|
/** Where the plan is bought or managed. */
|
|
href?: string;
|
|
/** Instead of `href`: the product opens its own checkout. */
|
|
onOpen?: () => void;
|
|
};
|
|
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, picked, served, format, answeredBy, className, }: {
|
|
/** The reader's own model (a connected key), if any. */
|
|
model: string | null | undefined;
|
|
label: string;
|
|
onOpen: () => void;
|
|
/** The free model the reader picked in the sheet (`onFreePick`); "" or absent = automatic. */
|
|
picked?: string | null;
|
|
/** The model that wrote the last answer, so "automatic" still names who answered. */
|
|
served?: string | null;
|
|
/** How an id is shown, e.g. without its vendor prefix. Titles keep the full id. */
|
|
format?: (id: string) => string;
|
|
answeredBy?: string;
|
|
className?: string;
|
|
}): import("react").JSX.Element;
|
|
export declare function ModelSheet({ open, onClose, vendors, current, check, onSave, onClear, freeModels, freePick, onFreePick, compareHref, plan, format, 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[];
|
|
/**
|
|
* The free model the reader picked ("" = automatic). With `onFreePick` the
|
|
* free models are a CHOICE (tap one and it is asked first), not a list to read.
|
|
* Where the pick is kept is the product's.
|
|
*/
|
|
freePick?: string;
|
|
onFreePick?: (model: string) => void;
|
|
/** A page comparing the free models, linked under the choice. */
|
|
compareHref?: string;
|
|
/** The product's paid way to a stronger model, if it sells one. */
|
|
plan?: ModelPlan;
|
|
/** How a free model's id is shown (e.g. without its vendor prefix). */
|
|
format?: (id: string) => string;
|
|
labels?: Partial<ModelSheetLabels>;
|
|
}): import("react").JSX.Element;
|
|
//# sourceMappingURL=ModelSheet.d.ts.map
|