blob: 602e0efe67f338b4429fefb3f8b57dbf8ba3b522 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
import type { ModelMetadata } from "@dispatch/transport-contract";
/**
* Pure helpers for the two-step model picker.
*
* Models arrive from `GET /models` as `<key>/<model>` strings, where `key` is
* the credential name (the part before the FIRST slash) and `model` is the rest.
* These pure functions split that into a key selector + a model selector and
* recombine the choice — zero DOM, zero Svelte.
*/
export interface SplitModel {
readonly key: string;
readonly model: string;
}
/** Split `<key>/<model>` on the first slash. A slashless name is all-key. */
export function splitModelName(full: string): SplitModel {
const i = full.indexOf("/");
if (i === -1) return { key: full, model: "" };
return { key: full.slice(0, i), model: full.slice(i + 1) };
}
/** Recombine a key + model into a `<key>/<model>` name (key-only if no model). */
export function joinModelName(key: string, model: string): string {
return model === "" ? key : `${key}/${model}`;
}
/** Distinct keys across all models, in first-seen order. */
export function modelKeys(models: readonly string[]): string[] {
const seen = new Set<string>();
const out: string[] = [];
for (const full of models) {
const { key } = splitModelName(full);
if (!seen.has(key)) {
seen.add(key);
out.push(key);
}
}
return out;
}
/** The model suffixes available under a given key, in order. */
export function modelsForKey(models: readonly string[], key: string): string[] {
const out: string[] = [];
for (const full of models) {
const split = splitModelName(full);
if (split.key === key) out.push(split.model);
}
return out;
}
/**
* Whether a given full model name (`<key>/<model>`) is vision-capable — i.e.
* `GET /models` `modelInfo[name].vision === true`. Absent/`false`/unknown →
* `false` (the server's vision handoff transcribes images to text for it).
* Pure lookup against the catalog metadata; zero DOM.
*/
export function isVisionModel(
modelInfo: Readonly<Record<string, ModelMetadata>>,
fullName: string,
): boolean {
return modelInfo[fullName]?.vision === true;
}
|