@restranger/repi-subagents 0.0.0-stage → 0.0.1-1a48fc0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,58 @@
1
+ import { isModelLike, scoreModel } from "@restranger/repi-lib";
2
+ import type { ModelResolution } from "./types.js";
3
+
4
+ export interface ModelRegistryLike {
5
+ find(provider: string, modelId: string): unknown;
6
+ getAll(): readonly unknown[];
7
+ getAvailable?(): readonly unknown[];
8
+ }
9
+
10
+ /**
11
+ * Resolve an agent's `model:` string.
12
+ *
13
+ * `inherit`/absent is the caller's job; this function is only called for an explicit request.
14
+ * It prefers an exact `provider/id` match, then a unique fuzzy match, and fails with a model list
15
+ * rather than silently running the child on a different model than its declaration names.
16
+ */
17
+ export function resolveModel(input: string, registry: ModelRegistryLike | undefined): ModelResolution {
18
+ if (!registry) {
19
+ return { error: `Model "${input}" cannot be resolved: the host exposes no model registry.` };
20
+ }
21
+
22
+ const all = registry.getAvailable?.() ?? registry.getAll();
23
+ const models = all.filter(isModelLike);
24
+ const normalized = input.trim().toLowerCase();
25
+ const fullNames = new Map(models.map((model) => [`${model.provider}/${model.id}`.toLowerCase(), model]));
26
+
27
+ const exact = fullNames.get(normalized);
28
+ if (exact) {
29
+ return { model: exact };
30
+ }
31
+
32
+ const slash = normalized.indexOf("/");
33
+ if (slash > 0) {
34
+ const provider = normalized.slice(0, slash);
35
+ const id = normalized.slice(slash + 1);
36
+ const found = registry.find(provider, id);
37
+ if (isModelLike(found)) {
38
+ return { model: found };
39
+ }
40
+ }
41
+
42
+ const scored = models
43
+ .map((model) => ({ model, score: scoreModel(model, normalized) }))
44
+ .filter((entry) => entry.score >= 20)
45
+ .sort((left, right) => right.score - left.score);
46
+ const best = scored[0];
47
+ if (best && (!scored[1] || scored[1].score < best.score)) {
48
+ return { model: best.model };
49
+ }
50
+
51
+ const available = models
52
+ .map((model) => ` ${model.provider}/${model.id}`)
53
+ .sort()
54
+ .join("\n");
55
+ return {
56
+ error: `Model not found: "${input}".${available ? `\n\nAvailable models:\n${available}` : ""}`,
57
+ };
58
+ }