@juanbenjumea/pi-agy 0.7.13 → 0.7.15
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.
- package/CHANGELOG.md +21 -0
- package/README.md +10 -2
- package/extensions/index.ts +29 -7
- package/extensions/lib/args.ts +51 -24
- package/extensions/lib/cli.ts +2 -0
- package/extensions/lib/execute.ts +7 -3
- package/extensions/lib/inspect.ts +112 -17
- package/extensions/lib/model-sort.ts +11 -3
- package/extensions/lib/provider-driver.ts +115 -15
- package/extensions/lib/provider-mcp.ts +11 -23
- package/extensions/lib/provider-models.ts +7 -9
- package/extensions/lib/provider-prompt.ts +137 -25
- package/extensions/lib/provider-tools.ts +16 -1
- package/extensions/lib/provider-usage.ts +115 -0
- package/extensions/lib/provider.ts +256 -86
- package/extensions/lib/stream.ts +2 -0
- package/extensions/tools.ts +6 -0
- package/package.json +4 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.15
|
|
4
|
+
|
|
5
|
+
- Resolve every model alias against the live `agy models` catalog; no production path ships a model id, a per-family regex, or a fallback roster, so a renamed or new family needs no package update. An unresolvable alias now fails with the alias name, the exact recovery, and the discovered-catalog requirement instead of launching a stale id.
|
|
6
|
+
- Match aliases structurally (family, optional trailing tier) and let a family that ships no tier variants answer its tier aliases with its top id, so a flagship named without a tier still serves `pro`. A tier-aware family keeps failing loudly for a retired tier instead of substituting a neighbour, and `xhigh` counts as a tier.
|
|
7
|
+
- Report native provider usage: validate `agy` token counts, difference the cumulative `result.usage` of a persistent child so consecutive turns are not double-counted, and normalize to Pi's `Usage` shape (`cache_read` excluded from input, thinking reported as reasoning).
|
|
8
|
+
- Stream agy thinking into Pi's TUI as thinking blocks and deltas, separate from tool/step progress.
|
|
9
|
+
- Send only the new transcript delta to a resumed agy conversation instead of replaying the whole prompt.
|
|
10
|
+
- Deny agy's shadowed built-in tools through a session `--settings` document when the Pi bridge owns the same capability.
|
|
11
|
+
- Batch parallel bridged MCP tool calls inside a short window so Pi answers them in one turn instead of one turn per call. Live verification shows agy's tool loop is serial (two calls arrived across two sequential phases), so this window is insurance rather than observed traffic; the batching behaviour itself is covered by deterministic driver tests.
|
|
12
|
+
- Verify the deny document live: with `--dangerously-skip-permissions` in force, `permissions.deny` still blocks agy's built-in shell tool (`Permission denied ... Matches user-configured deny rule`), while an identical request without the document creates its file. Both controls are in `npm run test:bridge`.
|
|
13
|
+
- Add `npm run test:provider`, an opt-in two-turn live check that keeps one child alive across turns and
|
|
14
|
+
asserts native usage is reported per turn instead of cumulatively; verified against agy 1.5.13
|
|
15
|
+
(`input 10420 / total 10421`, then `input 2119 + cache_read 8376 / total 10496` on reuse).
|
|
16
|
+
- Full 510-test suite, typecheck, live smoke against an authenticated agy CLI, and package checks pass.
|
|
17
|
+
|
|
18
|
+
## 0.7.14
|
|
19
|
+
|
|
20
|
+
- Keep model discovery off Pi's session-start critical path and load the MCP bridge only when needed.
|
|
21
|
+
- Add regression coverage confirming the extension starts without loading the bridge dependencies.
|
|
22
|
+
- Full 491-test suite, typecheck, and package checks pass.
|
|
23
|
+
|
|
3
24
|
## 0.7.13
|
|
4
25
|
|
|
5
26
|
- Refresh the separate `/agy` delegation picker with every discovered concrete model ID, not just fixed aliases; preserve exact names and Gemini tier variants.
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ Useful options include:
|
|
|
24
24
|
- `background=true` to return a handle, then use `agy_tasks` to poll, collect, or cancel
|
|
25
25
|
- `context=summary|recent` to optionally pass bounded Pi conversation context (default: none)
|
|
26
26
|
|
|
27
|
-
The `/agy` command runs tasks from Pi's TUI and can also list agents, inspect quota, diagnose setup, and select saved conversations. Its model picker refreshes the full concrete ID list from `agy models` each time it opens; alias shortcuts remain available. Discovery failures show the reason and mark cached
|
|
27
|
+
The `/agy` command runs tasks from Pi's TUI and can also list agents, inspect quota, diagnose setup, and select saved conversations. Its model picker refreshes the full concrete ID list from `agy models` each time it opens; alias shortcuts remain available. Discovery failures show the reason and mark cached choices as unverified. Use `model=<id>` for an exact CLI model ID; bare aliases such as `sonnet` still work. For example:
|
|
28
28
|
|
|
29
29
|
```text
|
|
30
30
|
/agy plan flash investigate the failing tests
|
|
@@ -34,11 +34,13 @@ The `/agy` command runs tasks from Pi's TUI and can also list agents, inspect qu
|
|
|
34
34
|
/agy doctor
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
Aliases are resolved against the live catalog instead of a shipped table: an alias names a family and optionally a tier (`sonnet`, `flash-low`, `pro-high`), and it matches an id whose hyphen-separated tokens appear contiguously, with a tier only as the id's trailing tokens. A family that ships no tier variants at all answers its tier aliases with its top id, so a flagship named without a tier still serves `pro`. A tier the vendor retires stops resolving and fails with an actionable message rather than quietly substituting a neighbour; the executed concrete id is always reported in the run receipt.
|
|
38
|
+
|
|
37
39
|
In `accept-edits` mode, Pi confirms before writes. agy's own permission behavior is controlled by its configuration and the package's `agy-config.json` settings below.
|
|
38
40
|
|
|
39
41
|
## Use agy as a Pi model
|
|
40
42
|
|
|
41
|
-
The package registers an `antigravity` provider. Select discovered models as `antigravity/<model>` in Pi's `/model` picker. Models refresh automatically from `agy models` at session startup and whenever Pi opens the model picker (Pi 1.5.2 native refresh). New model names need no package update. Failed discovery keeps the last good catalog
|
|
43
|
+
The package registers an `antigravity` provider. Select discovered models as `antigravity/<model>` in Pi's `/model` picker. Models refresh automatically from `agy models` at session startup and whenever Pi opens the model picker (Pi 1.5.2 native refresh). New model names need no package update. Failed discovery keeps the last good catalog; before the first successful discovery the picker is empty rather than a stale built-in list, and `/agy doctor` reports why. Reopen `/model` after signing in to retry. Cache-only refreshes never run the CLI. Gemini thinking levels map to agy's supported effort tiers.
|
|
42
44
|
|
|
43
45
|
Provider turns use a persistent agy process per working directory and can stage attached images for agy to read. By default, an MCP bridge gives agy read-only Pi context and lets it call active Pi tools through Pi's normal permission and approval flow. Set `"providerBridge": false` in `agy-config.json` to disable the bridge.
|
|
44
46
|
|
|
@@ -73,10 +75,16 @@ Development tests are qualified against the exact Pi SDK fixture version 1.5.2,
|
|
|
73
75
|
```bash
|
|
74
76
|
npm test
|
|
75
77
|
npm run typecheck
|
|
78
|
+
npm run test:live # read-only, no inference
|
|
79
|
+
npm run test:bridge # billable: deny-rule and park-path evidence
|
|
76
80
|
```
|
|
77
81
|
|
|
78
82
|
With an installed agy CLI, `npm run test:live` runs read-only integration checks without starting an inference turn.
|
|
79
83
|
|
|
84
|
+
`npm run test:bridge` covers the two behaviours that need a real child on the loopback bridge: that the `--settings` deny document actually stops agy's built-in shell tool (proven with a positive control, so a passing run cannot be the model declining to act), and how many bridged calls a single turn produces. Note that agy's tool loop is serial — it issues one call, waits, then issues the next — so the park micro-batch never sees concurrent calls in practice and stays covered by deterministic driver tests instead.
|
|
85
|
+
|
|
86
|
+
`npm run test:provider` is the one deliberately billable check: it spends two short turns on a budget alias of your choosing (`npm run test:provider -- <model-id>`), keeps the child alive between them, and asserts streamed text, the conversation id, native usage, and that a reused process reports the second turn as a delta rather than the session's cumulative counters. It runs without agy's permission bypass, so a tool call would be escalated rather than silently executed.
|
|
87
|
+
|
|
80
88
|
## License
|
|
81
89
|
|
|
82
90
|
MIT
|
package/extensions/index.ts
CHANGED
|
@@ -48,7 +48,19 @@ function registerAgyProvider(pi: ExtensionAPI): void {
|
|
|
48
48
|
// Only a generation-checked publication may mutate these entries.
|
|
49
49
|
const entries: AgyProviderModelEntry[] = [...FALLBACK_PROVIDER_MODELS];
|
|
50
50
|
const shutdown = new AbortController();
|
|
51
|
-
|
|
51
|
+
let activeUi: { setStatus?: (key: string, text: string | undefined) => void } | undefined;
|
|
52
|
+
const setLiveStatus = (label: string | undefined): void => {
|
|
53
|
+
try {
|
|
54
|
+
activeUi?.setStatus?.(AGY_PROVIDER_ID, label);
|
|
55
|
+
} catch {
|
|
56
|
+
// Status updates are best effort and must never disrupt a turn.
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
pi.on?.("session_shutdown", () => {
|
|
60
|
+
setLiveStatus(undefined);
|
|
61
|
+
activeUi = undefined;
|
|
62
|
+
shutdown.abort();
|
|
63
|
+
});
|
|
52
64
|
const streamSimple = createAgyStreamSimple(
|
|
53
65
|
{
|
|
54
66
|
createStream: () => {
|
|
@@ -65,7 +77,7 @@ function registerAgyProvider(pi: ExtensionAPI): void {
|
|
|
65
77
|
getSystemPrompt: (messages) =>
|
|
66
78
|
getCurrentSystemPrompt(messages as unknown as Parameters<typeof getCurrentSystemPrompt>[0]),
|
|
67
79
|
},
|
|
68
|
-
{ entries },
|
|
80
|
+
{ entries, onActivity: setLiveStatus },
|
|
69
81
|
);
|
|
70
82
|
const baseUrl = "agy-provider://antigravity";
|
|
71
83
|
const modelDefinitions = (catalog: readonly AgyProviderModelEntry[]): Model<any>[] =>
|
|
@@ -128,14 +140,24 @@ function registerAgyProvider(pi: ExtensionAPI): void {
|
|
|
128
140
|
shutdown.abort();
|
|
129
141
|
return;
|
|
130
142
|
}
|
|
131
|
-
pi.on?.("session_start",
|
|
143
|
+
pi.on?.("session_start", (_event, ctx) => {
|
|
144
|
+
if (ctx.hasUI && typeof ctx.ui?.setStatus === "function") {
|
|
145
|
+
activeUi = ctx.ui;
|
|
146
|
+
}
|
|
132
147
|
const signal = AbortSignal.any([shutdown.signal, AbortSignal.timeout(10_000)]);
|
|
133
|
-
|
|
148
|
+
// Keep provider discovery off Pi's session-start critical path. The model
|
|
149
|
+
// picker also refreshes on demand, so startup can use the cached catalog.
|
|
150
|
+
void ctx.modelRegistry.refresh({
|
|
134
151
|
providers: [AGY_PROVIDER_ID], allowNetwork: true, signal,
|
|
152
|
+
}).then((result) => {
|
|
153
|
+
if (!signal.aborted && result.errors.has(AGY_PROVIDER_ID)) {
|
|
154
|
+
ctx.ui.notify("Could not refresh Antigravity models; showing cached models. Reopen /model to retry.", "warning");
|
|
155
|
+
}
|
|
156
|
+
}).catch(() => {
|
|
157
|
+
if (!signal.aborted) {
|
|
158
|
+
ctx.ui.notify("Could not refresh Antigravity models; showing cached models. Reopen /model to retry.", "warning");
|
|
159
|
+
}
|
|
135
160
|
});
|
|
136
|
-
if (!signal.aborted && result.errors.has(AGY_PROVIDER_ID)) {
|
|
137
|
-
ctx.ui.notify("Could not refresh Antigravity models; showing cached models. Reopen /model to retry.", "warning");
|
|
138
|
-
}
|
|
139
161
|
});
|
|
140
162
|
}
|
|
141
163
|
|
package/extensions/lib/args.ts
CHANGED
|
@@ -20,18 +20,11 @@ const PRINT_TIMEOUT_BUFFER_MS = 5_000;
|
|
|
20
20
|
// unbucketed value it replaces (Pi's hard kill still governs the run).
|
|
21
21
|
const PRINT_TIMEOUT_BUCKET_S = 30;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"flash-high": "gemini-3.8-flash-high",
|
|
29
|
-
"pro-low": "gemini-3.1-pro-low",
|
|
30
|
-
"pro-high": "gemini-3.1-pro-high",
|
|
31
|
-
sonnet: "claude-sonnet-4-6",
|
|
32
|
-
opus: "claude-opus-4-6-thinking",
|
|
33
|
-
"gpt-oss": "gpt-oss-120b-medium",
|
|
34
|
-
};
|
|
23
|
+
/**
|
|
24
|
+
* Alias selected when the caller names nothing. Deliberately an alias: a
|
|
25
|
+
* concrete id here would be a hardcoded model name that goes stale silently.
|
|
26
|
+
*/
|
|
27
|
+
const DEFAULT_MODEL_ALIAS: AgyModel = "flash-medium";
|
|
35
28
|
|
|
36
29
|
const TIER_MAP: Record<NonNullable<AgyOptions["tier"]>, AgyModel> = {
|
|
37
30
|
flash: "flash-high",
|
|
@@ -47,19 +40,51 @@ export function resolveAgyModelAlias(
|
|
|
47
40
|
return model ?? (tier ? TIER_MAP[tier] : undefined);
|
|
48
41
|
}
|
|
49
42
|
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Resolve a model alias to a concrete agy model id from the live catalog.
|
|
45
|
+
*
|
|
46
|
+
* Returns `undefined` when the catalog was never observed or the vendor no
|
|
47
|
+
* longer ships a matching id. No id is ever invented: a fabricated fallback
|
|
48
|
+
* turns a retired tier into a runtime failure far from its cause.
|
|
49
|
+
*/
|
|
50
|
+
export function resolveAgyModelId(model?: AgyModel, tier?: AgyOptions["tier"]): string | undefined {
|
|
51
|
+
const alias = resolveAgyModelAlias(model, tier) ?? DEFAULT_MODEL_ALIAS;
|
|
52
|
+
return getModelCatalog()[alias];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Same resolution for argv and prompt paths, where an absent id is fatal.
|
|
57
|
+
* The message names the alias and the exact recovery, so a stale catalog is
|
|
58
|
+
* never mistaken for a bad request.
|
|
59
|
+
*/
|
|
60
|
+
export function requireAgyModelId(model?: AgyModel, tier?: AgyOptions["tier"]): string {
|
|
61
|
+
const alias = resolveAgyModelAlias(model, tier) ?? DEFAULT_MODEL_ALIAS;
|
|
62
|
+
const id = resolveAgyModelId(model, tier);
|
|
63
|
+
if (id) return id;
|
|
64
|
+
throw new Error(
|
|
65
|
+
`agy model alias "${alias}" matches nothing in the current catalog; run \`agy models\` (sign in if needed) or pass model=<exact id>`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Families verified to accept a base slug plus `--effort`. A capability
|
|
71
|
+
* assumption rather than a catalog entry, but it must stay narrow: agy turns a
|
|
72
|
+
* stray `--effort` on a fixed-thinking model into an argument error.
|
|
73
|
+
*/
|
|
74
|
+
const EFFORT_CAPABLE_ID = /^gpt-oss-/;
|
|
75
|
+
|
|
76
|
+
/** Effort capability for a concrete id, the single source of that rule. */
|
|
77
|
+
export function supportsAgyEffortId(id: string): boolean {
|
|
78
|
+
return EFFORT_CAPABLE_ID.test(id);
|
|
54
79
|
}
|
|
55
80
|
|
|
56
81
|
/**
|
|
57
|
-
*
|
|
58
|
-
* thinking
|
|
59
|
-
* expose it without turning a valid tool call into an argument error.
|
|
82
|
+
* Tier-suffixed aliases already select a low/medium/high variant and fixed
|
|
83
|
+
* thinking families reject the flag; only the families above take it.
|
|
60
84
|
*/
|
|
61
85
|
export function supportsAgyEffort(model?: AgyModel, tier?: AgyOptions["tier"]): boolean {
|
|
62
|
-
|
|
86
|
+
const id = resolveAgyModelId(model, tier);
|
|
87
|
+
return id !== undefined && supportsAgyEffortId(id);
|
|
63
88
|
}
|
|
64
89
|
|
|
65
90
|
export function buildAgyArgs(options: AgyOptions): string[] {
|
|
@@ -68,7 +93,7 @@ export function buildAgyArgs(options: AgyOptions): string[] {
|
|
|
68
93
|
}
|
|
69
94
|
|
|
70
95
|
validateModelSelector(options);
|
|
71
|
-
const model = options.model_id ??
|
|
96
|
+
const model = options.model_id ?? requireAgyModelId(options.model, options.tier);
|
|
72
97
|
const agent = normalizeAgyAgentName(options.agent);
|
|
73
98
|
const unbucketedSec = Math.ceil((options.timeout_ms + PRINT_TIMEOUT_BUFFER_MS) / 1000);
|
|
74
99
|
const timeoutSec = Math.ceil(unbucketedSec / PRINT_TIMEOUT_BUCKET_S) * PRINT_TIMEOUT_BUCKET_S;
|
|
@@ -77,6 +102,10 @@ export function buildAgyArgs(options: AgyOptions): string[] {
|
|
|
77
102
|
const skipPermissions = options.skipPermissions ?? true;
|
|
78
103
|
const useStream = options.stream ?? true;
|
|
79
104
|
const structured = mode !== "accept-edits" || useStream;
|
|
105
|
+
// An exact id is asked about directly; an alias is resolved through the catalog.
|
|
106
|
+
const effortCapable = options.model_id
|
|
107
|
+
? supportsAgyEffortId(options.model_id)
|
|
108
|
+
: supportsAgyEffort(options.model, options.tier);
|
|
80
109
|
|
|
81
110
|
const args = [
|
|
82
111
|
"--model",
|
|
@@ -89,9 +118,7 @@ export function buildAgyArgs(options: AgyOptions): string[] {
|
|
|
89
118
|
"--disable-slash-commands",
|
|
90
119
|
...(mode === "sandbox" ? ["--sandbox"] : ["--mode", mode]),
|
|
91
120
|
...(writes && skipPermissions ? ["--dangerously-skip-permissions"] : []),
|
|
92
|
-
...(options.effort &&
|
|
93
|
-
? ["--effort", options.effort]
|
|
94
|
-
: []),
|
|
121
|
+
...(options.effort && effortCapable ? ["--effort", options.effort] : []),
|
|
95
122
|
...(agent ? ["--agent", agent] : []),
|
|
96
123
|
];
|
|
97
124
|
|
package/extensions/lib/cli.ts
CHANGED
|
@@ -44,6 +44,7 @@ export {
|
|
|
44
44
|
checkAgyUsage,
|
|
45
45
|
getModelCatalog,
|
|
46
46
|
inspectAgyAgents,
|
|
47
|
+
inspectAgyModelIds,
|
|
47
48
|
inspectAgyModels,
|
|
48
49
|
inspectAgyVersion,
|
|
49
50
|
isStableModelId,
|
|
@@ -57,6 +58,7 @@ export { isTransientAgyFailure } from "./retry.js";
|
|
|
57
58
|
export {
|
|
58
59
|
buildAgyArgs,
|
|
59
60
|
buildAgyPrompt,
|
|
61
|
+
requireAgyModelId,
|
|
60
62
|
resolveAgyModelAlias,
|
|
61
63
|
resolveAgyModelId,
|
|
62
64
|
supportsAgyEffort,
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
isAgyQuotaExhausted,
|
|
12
12
|
isTransientAgyFailure,
|
|
13
13
|
normalizeAgyAgentName,
|
|
14
|
+
requireAgyModelId,
|
|
14
15
|
resolveAgyModelAlias,
|
|
15
16
|
resolveAgyModelId,
|
|
16
17
|
spawnAgyStream,
|
|
@@ -177,7 +178,7 @@ export async function executeAgyTask(
|
|
|
177
178
|
const run = await runWithTransientRetry(async (trackProgress) => {
|
|
178
179
|
const remainingMs = remainingBudget(startedAt, options.timeout_ms);
|
|
179
180
|
quota = await runPreflight(options.dir, abortSignal, remainingMs);
|
|
180
|
-
const selectedModelId = options.model_id ??
|
|
181
|
+
const selectedModelId = options.model_id ?? requireAgyModelId(model, options.tier);
|
|
181
182
|
const selectedQuotas = findAgyQuotaEntries(quota, selectedModelId);
|
|
182
183
|
quotaStatus = quota
|
|
183
184
|
? selectedQuotas.length === 0
|
|
@@ -192,7 +193,7 @@ export async function executeAgyTask(
|
|
|
192
193
|
: undefined;
|
|
193
194
|
if (fallback) {
|
|
194
195
|
onProgress?.(
|
|
195
|
-
`agy: ${selectedModelId} quota exhausted; falling back to ${resolveAgyModelId(fallback)}…`,
|
|
196
|
+
`agy: ${selectedModelId} quota exhausted; falling back to ${resolveAgyModelId(fallback) ?? fallback}…`,
|
|
196
197
|
);
|
|
197
198
|
model = fallback;
|
|
198
199
|
effectiveModel = fallback;
|
|
@@ -387,7 +388,10 @@ function findAvailableFallbackModel(
|
|
|
387
388
|
if (!snapshot) return undefined;
|
|
388
389
|
return FALLBACK_MODELS.find((candidate) => {
|
|
389
390
|
if (candidate === current) return false;
|
|
390
|
-
|
|
391
|
+
// An alias with no catalog match cannot be run, so it cannot be the fallback.
|
|
392
|
+
const id = resolveAgyModelId(candidate);
|
|
393
|
+
if (!id) return false;
|
|
394
|
+
const entries = findAgyQuotaEntries(snapshot, id);
|
|
391
395
|
return entries.length > 0 && entries.every((entry) => !isAgyQuotaExhausted(entry));
|
|
392
396
|
});
|
|
393
397
|
}
|
|
@@ -10,20 +10,92 @@ import { parseAgyModelIds, type AgyModelId } from "./provider-models.js";
|
|
|
10
10
|
import { compareModelIds } from "./model-sort.js";
|
|
11
11
|
import { runPreflightCommand } from "./spawn.js";
|
|
12
12
|
import { parseAgyUsage, usageError, type AgyUsageSnapshot } from "./usage.js";
|
|
13
|
-
import type
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
import { AGY_MODEL_ALIASES, type AgyModel } from "./cli.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Alias matching is structural, never a literal model name.
|
|
17
|
+
*
|
|
18
|
+
* An alias is `family` or `family-<effort>` (see `AGY_MODEL_ALIASES`). It
|
|
19
|
+
* matches an `agy models` id when the alias's hyphen-separated tokens appear
|
|
20
|
+
* contiguously in the id — and, for an effort alias, only as the id's trailing
|
|
21
|
+
* tokens. `…-flash-low` therefore matches `flash-low` but not `flash-medium`,
|
|
22
|
+
* and a tier the vendor retires stops matching instead of resolving to an
|
|
23
|
+
* invented id. New families and renames resolve with no code change.
|
|
24
|
+
*/
|
|
25
|
+
const EFFORT_TOKENS: readonly string[] = ["low", "medium", "high", "xhigh"];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Release-channel qualifiers that may trail an id (`…-flash-medium-preview`).
|
|
29
|
+
* Structural, not model-specific: these describe maturity, not a family, and
|
|
30
|
+
* stripping them lets a preview catalog resolve while `isStableModelId` still
|
|
31
|
+
* keeps such ids out of the default catalog.
|
|
32
|
+
*/
|
|
33
|
+
const QUALIFIER_TOKENS: readonly string[] = ["preview", "experimental", "beta", "alpha", "snapshot", "next"];
|
|
34
|
+
|
|
35
|
+
export type AgyModelAliasMatcher = (alias: AgyModel, id: string) => boolean;
|
|
36
|
+
|
|
37
|
+
function findTokenRun(haystack: readonly string[], needle: readonly string[]): number {
|
|
38
|
+
if (needle.length === 0 || needle.length > haystack.length) return -1;
|
|
39
|
+
const last = haystack.length - needle.length;
|
|
40
|
+
for (let start = 0; start <= last; start++) {
|
|
41
|
+
let matched = true;
|
|
42
|
+
for (let offset = 0; offset < needle.length; offset++) {
|
|
43
|
+
if (haystack[start + offset] !== needle[offset]) {
|
|
44
|
+
matched = false;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (matched) return start;
|
|
49
|
+
}
|
|
50
|
+
return -1;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function aliasTokens(alias: string): string[] {
|
|
54
|
+
return alias.toLowerCase().split("-").filter(Boolean);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Class tokens of an effort alias (`flash-low` -> `flash`), else undefined. */
|
|
58
|
+
function classTokensOf(alias: string): string[] | undefined {
|
|
59
|
+
const tokens = aliasTokens(alias);
|
|
60
|
+
if (tokens.length < 2) return undefined;
|
|
61
|
+
if (!EFFORT_TOKENS.includes(tokens[tokens.length - 1])) return undefined;
|
|
62
|
+
return tokens.slice(0, -1);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Does this catalog id satisfy the alias? Pure token comparison. */
|
|
66
|
+
export function aliasMatchesModelId(alias: string, id: string): boolean {
|
|
67
|
+
const tokens = aliasTokens(alias);
|
|
68
|
+
const idTokens = id.toLowerCase().split("-").filter(Boolean);
|
|
69
|
+
if (tokens.length === 0) return false;
|
|
70
|
+
const namesEffort = EFFORT_TOKENS.includes(tokens[tokens.length - 1]);
|
|
71
|
+
const start = findTokenRun(idTokens, tokens);
|
|
72
|
+
if (start === -1) return false;
|
|
73
|
+
if (!namesEffort) return true;
|
|
74
|
+
// An effort alias pins the tier: only release-channel qualifiers may follow,
|
|
75
|
+
// so `…-flash-medium-preview` is still flash-medium and `…-flash-medium-x` is not.
|
|
76
|
+
const trailing = idTokens.slice(start + tokens.length);
|
|
77
|
+
return trailing.every((token) => QUALIFIER_TOKENS.includes(token));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Class-level match used only when a family ships no effort variants at all.
|
|
82
|
+
*
|
|
83
|
+
* Vendors do move effort out of the id: a `…-pro-orchestrator-neon` flagship
|
|
84
|
+
* carries no tier token, so every `pro-*` alias would stop resolving and a
|
|
85
|
+
* legacy `tier: "pro"` would fail for a model that plainly exists. Such a
|
|
86
|
+
* family answers its tier aliases with its top id instead. A family that does
|
|
87
|
+
* ship variants never reaches this path, so a retired tier still fails loudly
|
|
88
|
+
* rather than silently upgrading.
|
|
89
|
+
*/
|
|
90
|
+
function classMatchesModelId(classTokens: readonly string[], id: string): boolean {
|
|
91
|
+
const idTokens = id.toLowerCase().split("-").filter(Boolean);
|
|
92
|
+
return findTokenRun(idTokens, classTokens) !== -1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function namesEffortTier(id: string): boolean {
|
|
96
|
+
const idTokens = id.toLowerCase().split("-").filter(Boolean);
|
|
97
|
+
return idTokens.length > 0 && EFFORT_TOKENS.includes(idTokens[idTokens.length - 1]!);
|
|
98
|
+
}
|
|
27
99
|
|
|
28
100
|
export type AgyModelCatalog = Partial<Record<AgyModel, string>>;
|
|
29
101
|
|
|
@@ -44,17 +116,40 @@ export function isStableModelId(id: string): boolean {
|
|
|
44
116
|
*/
|
|
45
117
|
export function parseModelCatalog(output: string, allowPreview = false): AgyModelCatalog {
|
|
46
118
|
const allow = allowPreview || process.env.PI_AGY_ALLOW_PREVIEW === "1";
|
|
47
|
-
const
|
|
119
|
+
const ids: string[] = [];
|
|
48
120
|
for (const line of output.split("\n")) {
|
|
49
121
|
const id = line.trim().split(/\s+/)[0] ?? "";
|
|
50
122
|
if (!id) continue;
|
|
51
123
|
if (!allow && !isStableModelId(id)) continue;
|
|
52
|
-
|
|
53
|
-
|
|
124
|
+
ids.push(id);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const found: AgyModelCatalog = {};
|
|
128
|
+
const unanswered: AgyModel[] = [];
|
|
129
|
+
for (const alias of AGY_MODEL_ALIASES) {
|
|
130
|
+
for (const id of ids) {
|
|
131
|
+
// A catalog line that is just the alias name is the CLI's own shortcut,
|
|
132
|
+
// not a concrete model: letting it win would shadow the real family id.
|
|
133
|
+
if (id === alias) continue;
|
|
134
|
+
if (aliasMatchesModelId(alias, id) && compareModelIds(id, found[alias] ?? "") > 0) {
|
|
54
135
|
found[alias] = id;
|
|
55
136
|
}
|
|
56
137
|
}
|
|
138
|
+
if (found[alias] === undefined) unanswered.push(alias);
|
|
57
139
|
}
|
|
140
|
+
|
|
141
|
+
for (const alias of unanswered) {
|
|
142
|
+
const classTokens = classTokensOf(alias);
|
|
143
|
+
if (!classTokens) continue;
|
|
144
|
+
const candidates = ids.filter((id) => classMatchesModelId(classTokens, id));
|
|
145
|
+
// A class that ships any effort variant is tier-aware: its aliases must
|
|
146
|
+
// match the requested tier or fail, never fall back to another tier.
|
|
147
|
+
if (candidates.length === 0 || candidates.some(namesEffortTier)) continue;
|
|
148
|
+
for (const id of candidates) {
|
|
149
|
+
if (compareModelIds(id, found[alias] ?? "") > 0) found[alias] = id;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
58
153
|
return found;
|
|
59
154
|
}
|
|
60
155
|
|
|
@@ -5,16 +5,24 @@
|
|
|
5
5
|
* catalog state, so it can be tested and reasoned about in isolation.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Dotted version segment following the leading family token, e.g.
|
|
10
|
+
* `acme-3.8-thing` -> `3.8`. Family-agnostic on purpose: naming one vendor
|
|
11
|
+
* here would freeze ordering to that vendor's id shape.
|
|
12
|
+
*/
|
|
13
|
+
const DOTTED_VERSION_RE = /^[a-z][a-z0-9]*-(\d+(?:\.\d+)+)/i;
|
|
14
|
+
|
|
8
15
|
/**
|
|
9
16
|
* Order model ids so the newest-looking id wins catalog resolution.
|
|
10
17
|
* Returns a negative/zero/positive number like `Array.prototype.sort` expects.
|
|
11
18
|
*/
|
|
12
19
|
export function compareModelIds(a: string, b: string): number {
|
|
13
20
|
if (!b) return 1;
|
|
14
|
-
const versionA =
|
|
15
|
-
const versionB =
|
|
21
|
+
const versionA = DOTTED_VERSION_RE.exec(a)?.[1];
|
|
22
|
+
const versionB = DOTTED_VERSION_RE.exec(b)?.[1];
|
|
16
23
|
if (versionA && versionB) return compareDottedVersions(versionA, versionB);
|
|
17
|
-
// Numeric-aware compare so
|
|
24
|
+
// Numeric-aware compare so `x-4-10` sorts above `x-4-6` and a dotted id
|
|
25
|
+
// still outranks a hyphenated lower generation.
|
|
18
26
|
return compareNatural(a, b);
|
|
19
27
|
}
|
|
20
28
|
|