@bermudi/pi-delegate 0.1.17 → 0.1.18

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.
Files changed (2) hide show
  1. package/model.ts +34 -2
  2. package/package.json +1 -1
package/model.ts CHANGED
@@ -14,13 +14,45 @@ function resolveModelReference(
14
14
  spec: string,
15
15
  registry: ModelRegistry,
16
16
  ): Model<Api> | undefined {
17
+ // Pi's own reference grammar is case-insensitive (model-resolver.ts
18
+ // lowercases provider and id on every match), and callers echo model
19
+ // strings in whatever casing they saw — e.g. a task model of
20
+ // `modal/zai-org/glm-5.3-flash:max` against a registry id of
21
+ // `zai-org/GLM-5.3-Flash`. Matching stricter than pi about case rejects
22
+ // references pi itself accepts. This is still exact matching: no fuzzy,
23
+ // partial, or fallback-model resolution — a typo must fail loudly rather
24
+ // than silently select a different model.
25
+ const target = spec.toLowerCase();
17
26
  const idx = spec.indexOf("/");
18
27
  if (idx === -1) {
19
28
  // Bare id — match against available models
20
- const match = registry.getAvailable().find((m) => m.id === spec);
29
+ const match = registry
30
+ .getAvailable()
31
+ .find((m) => m.id.toLowerCase() === target);
21
32
  return match ?? undefined;
22
33
  }
23
- return registry.find(spec.slice(0, idx), spec.slice(idx + 1)) ?? undefined;
34
+ const provider = spec.slice(0, idx);
35
+ const id = spec.slice(idx + 1);
36
+ // Exact match first (preserves resolution of unauthenticated models via
37
+ // find), then a case-insensitive scan over the same all-models universe
38
+ // registry.find() searches.
39
+ const exact = registry.find(provider, id);
40
+ if (exact) return exact;
41
+ const providerLower = provider.toLowerCase();
42
+ const idLower = id.toLowerCase();
43
+ const models = registry.getAll();
44
+ const splitMatch = models.find(
45
+ (m) =>
46
+ m.provider.toLowerCase() === providerLower &&
47
+ m.id.toLowerCase() === idLower,
48
+ );
49
+ if (splitMatch) return splitMatch;
50
+ // Pi-grammar fallback: model ids may themselves contain slashes
51
+ // (openrouter-style, or namespaced ids like `zai-org/GLM-5.3-Flash`). When
52
+ // the provider-split reading matches nothing, try the whole spec as an id.
53
+ // The split reading wins when the prefix is a real provider, matching pi's
54
+ // own preference order.
55
+ return models.find((m) => m.id.toLowerCase() === target) ?? undefined;
24
56
  }
25
57
 
26
58
  /** Resolve a model reference, tolerating a Pi-style `:<thinking-level>`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bermudi/pi-delegate",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "Delegate tool for the Pi coding agent.",
5
5
  "keywords": [
6
6
  "pi-package"