@askdkc/dsh-cli 0.12.1 → 0.12.3

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/README.md CHANGED
@@ -42,7 +42,7 @@ This is dkc's independently developed fork of [dsh-TUI by chimney](https://githu
42
42
  Requires [Node.js](https://nodejs.org/en) `^22.19 || >=24`, pnpm 11, a
43
43
  [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) source
44
44
  checkout with dependencies installed, and `DEEPSEEK_API_KEY`. We aim to support
45
- the latest DSH release. The primary validated Harness version is `0.2.0-rc.1`;
45
+ the latest DSH release. The primary validated Harness version is `0.2.0-rc.2`;
46
46
  older supported versions are listed in [ADAPTER.md](ADAPTER.md).
47
47
 
48
48
  Clone recursively to fetch submodules. In an existing checkout, run
@@ -57,7 +57,7 @@ node scripts/with-publish-manifest.mjs npm pack --ignore-scripts
57
57
  TARBALL="$PWD/askdkc-dsh-cli-$(node -p "require('./package.json').version").tgz"
58
58
 
59
59
  cd ~/DIR/TO/deepseek-harness
60
- pnpm dsh plugin --profile dsh-cli add "$TARBALL"
60
+ pnpm dsh plugin --profile dsh-cli add "@askdkc/dsh-cli@file:${TARBALL}"
61
61
  pnpm dsh --profile dsh-cli
62
62
  ```
63
63
 
@@ -65,6 +65,11 @@ Replace `~/DIR/TO/deepseek-harness` with your checkout path. The first interacti
65
65
  launch registers `dsh-cli`; open a new shell, then run it from your project directory.
66
66
  To update this fork, rebuild and reinstall the tarball. `/update` uses the registry.
67
67
 
68
+ Use the named `@askdkc/dsh-cli@file:...` form for local tarball updates. A bare
69
+ tarball path can fail with `ENOENT` when pnpm resolves a previous `file:` dependency
70
+ whose archive has been deleted. `TARBALL` holds the archive's absolute path; pass
71
+ it to the install command instead of executing it.
72
+
68
73
  For PATH setup and install issues, see [Getting started](docs/getting-started.en.md).
69
74
 
70
75
  ## Use
@@ -1,9 +1,10 @@
1
1
  /** Primary validated upstream line (newest). */
2
- export declare const UPSTREAM_VALIDATED_VERSION = "0.2.0-rc.1";
2
+ export declare const UPSTREAM_VALIDATED_VERSION = "0.2.0-rc.2";
3
3
  /**
4
4
  * Explicitly supported upstream prerelease lines, oldest first.
5
5
  *
6
- * 0.2.0-rc.1 = primary continuous-CI line; 0.1.7-rc.2/rc.1 = previous
6
+ * 0.2.0-rc.2 = primary continuous-CI line; 0.2.0-rc.1 = previous primary;
7
+ * 0.1.7-rc.2/rc.1 = previous
7
8
  * build (mapped compatibility); 0.1.5-rc.1/alpha.2/alpha.1 = mapped
8
9
  * compatibility lines (source-checked when the primary line moves);
9
10
  * 0.1.3-alpha.2 = compatibility line (the only 0.1.3 build on npm);
@@ -16,7 +17,7 @@ export declare const UPSTREAM_VALIDATED_VERSION = "0.2.0-rc.1";
16
17
  * The peer range in package.json is deliberately wider than this list: an
17
18
  * install on an older or newer line is allowed but reports drift at boot.
18
19
  */
19
- export declare const UPSTREAM_VALIDATED_VERSIONS: readonly ["0.1.0-rc.6", "0.1.0-rc.7", "0.1.0-rc.8", "0.1.1-rc.1", "0.1.1-rc.2", "0.1.2-alpha.3", "0.1.2-alpha.4", "0.1.2-alpha.5", "0.1.2-rc.1", "0.1.3-alpha.2", "0.1.5-alpha.1", "0.1.5-alpha.2", "0.1.5-rc.1", "0.1.7-rc.1", "0.1.7-rc.2", "0.2.0-rc.1"];
20
+ export declare const UPSTREAM_VALIDATED_VERSIONS: readonly ["0.1.0-rc.6", "0.1.0-rc.7", "0.1.0-rc.8", "0.1.1-rc.1", "0.1.1-rc.2", "0.1.2-alpha.3", "0.1.2-alpha.4", "0.1.2-alpha.5", "0.1.2-rc.1", "0.1.3-alpha.2", "0.1.5-alpha.1", "0.1.5-alpha.2", "0.1.5-rc.1", "0.1.7-rc.1", "0.1.7-rc.2", "0.2.0-rc.1", "0.2.0-rc.2"];
20
21
  /**
21
22
  * Framework packages version on their own lines; the contract validates
22
23
  * their MAJOR (breaking surface), not the harness prerelease number.
@@ -1 +1 @@
1
- {"version":3,"file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F,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,iBAAiB,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAA+B,GAC5F,oBAAoB,GAAG,SAAS,CA0BlC"}
@@ -2,7 +2,7 @@
2
2
  * Upstream compatibility contract.
3
3
  *
4
4
  * The TUI is validated against a set of upstream prerelease lines — the
5
- * current primary (0.2.0-rc.1) plus older lines kept in backward
5
+ * current primary (0.2.0-rc.2) plus older lines kept in backward
6
6
  * compatibility across the 0.1.5, 0.1.3, 0.1.2, 0.1.1 and 0.1.0 release
7
7
  * families.
8
8
  * Every official package this adapter touches is blessed here; anything
@@ -16,11 +16,12 @@
16
16
  import { readFileSync } from 'node:fs';
17
17
  import { fileURLToPath } from 'node:url';
18
18
  /** Primary validated upstream line (newest). */
19
- export const UPSTREAM_VALIDATED_VERSION = '0.2.0-rc.1';
19
+ export const UPSTREAM_VALIDATED_VERSION = '0.2.0-rc.2';
20
20
  /**
21
21
  * Explicitly supported upstream prerelease lines, oldest first.
22
22
  *
23
- * 0.2.0-rc.1 = primary continuous-CI line; 0.1.7-rc.2/rc.1 = previous
23
+ * 0.2.0-rc.2 = primary continuous-CI line; 0.2.0-rc.1 = previous primary;
24
+ * 0.1.7-rc.2/rc.1 = previous
24
25
  * build (mapped compatibility); 0.1.5-rc.1/alpha.2/alpha.1 = mapped
25
26
  * compatibility lines (source-checked when the primary line moves);
26
27
  * 0.1.3-alpha.2 = compatibility line (the only 0.1.3 build on npm);
@@ -50,6 +51,7 @@ export const UPSTREAM_VALIDATED_VERSIONS = [
50
51
  '0.1.7-rc.1',
51
52
  '0.1.7-rc.2',
52
53
  '0.2.0-rc.1',
54
+ '0.2.0-rc.2',
53
55
  ];
54
56
  /**
55
57
  * Framework packages version on their own lines; the contract validates
@@ -119,6 +119,12 @@ dsh plugin --profile <name> add @askdkc/dsh-auth
119
119
  (`llm-pi-ai` の設定プロファイルなど)、レジストリはそのルートの登録を拒否します。
120
120
  プラグインは拒否をログに記録し、残りのルートを登録します。
121
121
  1 つのプロバイダーには 1 つのアダプターを割り当ててください。
122
+ - `opencode` / `opencode-go` は、インストール済み pi-ai カタログの上に
123
+ Zen の最新モデル一覧を提供します(モデルごとの通信プロトコルは最も近い
124
+ カタログの兄弟モデルから解決し、既存モデルは常に優先されるため、追加のみで
125
+ 削除は起きません)。`pnpm --dir dsh-auth sync:models` でスナップショットを
126
+ 更新できます(`models.dev` と Zen の `/v1/models` を参照)。
127
+ 実行時にネットワークは使いません。
122
128
 
123
129
  ## セキュリティ上の注意
124
130
 
@@ -118,6 +118,11 @@ the `/auth login <provider>` hint — never silently.
118
118
  profile naming the same provider — is refused by the registry; the plugin
119
119
  logs the refusal and mounts the remaining routes. Keep one provider on one
120
120
  adapter.
121
+ - `opencode` / `opencode-go` serve the live Zen roster on top of the installed
122
+ pi-ai catalog (per-model wire protocols resolve from the nearest catalog
123
+ sibling; installed models always win). Refresh the checked-in snapshot with
124
+ `pnpm --dir dsh-auth sync:models` (reads `models.dev` plus the live Zen
125
+ `/v1/models` rosters); runtime stays offline-safe.
121
126
 
122
127
  ## Security notes
123
128
 
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Fresh OpenCode rosters on top of the installed pi-ai catalog.
3
+ *
4
+ * The installed catalog is the wire authority (per-model `api` protocol,
5
+ * base URLs, compat): overlapping ids are served untouched. The checked-in
6
+ * snapshot (`opencode-snapshot.generated.ts`, refreshed from models.dev plus
7
+ * the live Zen `/v1/models` rosters) contributes only roster ids the
8
+ * installed catalog lacks — each synthesized with per-model protocol
9
+ * resolution, never a route-level default:
10
+ *
11
+ * - models.dev metadata (name, reasoning, modalities, limits, cost) plus the
12
+ * wire envelope (`api`, `baseUrl`, `compat`, thinking levels, image
13
+ * budgets) inherited from the nearest same-route catalog sibling;
14
+ * - ids neither source describes are cloned wholesale from that sibling and
15
+ * keep working wherever the sibling does (provenance lives in the
16
+ * snapshot, not on the model object).
17
+ *
18
+ * The merge only ever adds: the result always covers the installed catalog,
19
+ * so a stale snapshot delays additions but can never remove working models.
20
+ *
21
+ * @module dsh-auth/fresh-models
22
+ */
23
+ import type { PiAiProvider } from './pi-ai.js';
24
+ /** One allowlisted models.dev entry (see scripts/sync-opencode-models.mjs). */
25
+ export interface FreshModelEntry {
26
+ readonly id: string;
27
+ readonly name: string;
28
+ readonly reasoning?: boolean;
29
+ readonly attachment?: boolean;
30
+ readonly modalities: {
31
+ readonly input: readonly string[];
32
+ };
33
+ readonly limit: {
34
+ readonly context: number;
35
+ readonly output?: number;
36
+ };
37
+ readonly cost: {
38
+ readonly input: number;
39
+ readonly output: number;
40
+ readonly cache_read?: number;
41
+ };
42
+ readonly temperature?: boolean;
43
+ readonly reasoning_options?: {
44
+ readonly effort: readonly string[];
45
+ };
46
+ }
47
+ export type FreshRouteId = 'opencode' | 'opencode-go';
48
+ /**
49
+ * Union the snapshot roster onto one catalog provider. Installed models win
50
+ * on conflict and classifier-roster ids stay on pi-ai's classifier path, so
51
+ * the merged list always covers the installed catalog — a stale snapshot
52
+ * delays additions but never removes a working model.
53
+ * @param catalog - the installed pi-ai catalog provider for one route.
54
+ * @param route - the route the snapshot section is keyed under.
55
+ * @returns the catalog provider, or a shallow clone serving the union.
56
+ */
57
+ export declare function withFreshModels(catalog: PiAiProvider, route: FreshRouteId): PiAiProvider;
58
+ /** Snapshot roster ids for one route, for smoke coverage. */
59
+ export declare function freshRosterIds(route: FreshRouteId): readonly string[];
@@ -0,0 +1,246 @@
1
+ import { OPENCODE_SNAPSHOT } from './opencode-snapshot.generated.js';
2
+ function record(value, what) {
3
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
4
+ throw new Error(`dsh-auth: snapshot ${what} is not an object`);
5
+ }
6
+ return value;
7
+ }
8
+ function nonEmptyString(value) {
9
+ return typeof value === 'string' && value.length > 0 ? value : undefined;
10
+ }
11
+ function boundedStringList(value, what, max) {
12
+ if (!Array.isArray(value) || value.length > max || !value.every(item => typeof item === 'string')) {
13
+ throw new Error(`dsh-auth: snapshot ${what} is not a string list`);
14
+ }
15
+ const list = value;
16
+ if (new Set(list).size !== list.length)
17
+ throw new Error(`dsh-auth: snapshot ${what} has duplicates`);
18
+ return list;
19
+ }
20
+ function positiveInt(value) {
21
+ return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value : undefined;
22
+ }
23
+ function nonnegativeNumber(value) {
24
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : undefined;
25
+ }
26
+ function parseEntry(route, key, value) {
27
+ const row = record(value, `${route}/${key}`);
28
+ if (row.id !== key)
29
+ throw new Error(`dsh-auth: snapshot ${route}/${key} names "${String(row.id)}"`);
30
+ const name = nonEmptyString(row.name);
31
+ if (name === undefined)
32
+ throw new Error(`dsh-auth: snapshot ${route}/${key} has no name`);
33
+ const modalities = record(row.modalities ?? fail(route, key, 'modalities'), `${route}/${key} modalities`).input;
34
+ if (!Array.isArray(modalities) || modalities.length === 0 || !modalities.every(m => typeof m === 'string')) {
35
+ throw new Error(`dsh-auth: snapshot ${route}/${key} has no input modalities`);
36
+ }
37
+ const limit = record(row.limit ?? fail(route, key, 'limit'), `${route}/${key} limit`);
38
+ const context = positiveInt(limit.context);
39
+ if (context === undefined)
40
+ throw new Error(`dsh-auth: snapshot ${route}/${key} has no context limit`);
41
+ const output = limit.output === undefined ? undefined : positiveInt(limit.output);
42
+ if (limit.output !== undefined && output === undefined) {
43
+ throw new Error(`dsh-auth: snapshot ${route}/${key} has a malformed output limit`);
44
+ }
45
+ const cost = record(row.cost ?? fail(route, key, 'cost'), `${route}/${key} cost`);
46
+ const input = nonnegativeNumber(cost.input);
47
+ const outputCost = nonnegativeNumber(cost.output);
48
+ if (input === undefined || outputCost === undefined) {
49
+ throw new Error(`dsh-auth: snapshot ${route}/${key} has no pricing`);
50
+ }
51
+ const cacheRead = cost.cache_read === undefined ? undefined : nonnegativeNumber(cost.cache_read);
52
+ if (cost.cache_read !== undefined && cacheRead === undefined) {
53
+ throw new Error(`dsh-auth: snapshot ${route}/${key} has malformed cache pricing`);
54
+ }
55
+ const entry = {
56
+ id: key,
57
+ name,
58
+ reasoning: typeof row.reasoning === 'boolean' ? row.reasoning : undefined,
59
+ attachment: typeof row.attachment === 'boolean' ? row.attachment : undefined,
60
+ temperature: typeof row.temperature === 'boolean' ? row.temperature : undefined,
61
+ reasoning_options: parseEffort(route, key, row.reasoning_options),
62
+ modalities: { input: modalities.slice() },
63
+ limit: output === undefined ? { context } : { context, output },
64
+ cost: cacheRead === undefined ? { input, output: outputCost } : { input, output: outputCost, cache_read: cacheRead },
65
+ };
66
+ return entry;
67
+ }
68
+ function parseEffort(route, key, value) {
69
+ if (value === undefined)
70
+ return undefined;
71
+ const options = record(value, `${route}/${key} reasoning options`).effort;
72
+ if (options === undefined)
73
+ return undefined;
74
+ if (!Array.isArray(options) || !options.every(v => typeof v === 'string')) {
75
+ throw new Error(`dsh-auth: snapshot ${route}/${key} has malformed effort values`);
76
+ }
77
+ return { effort: options.slice() };
78
+ }
79
+ function fail(route, key, what) {
80
+ throw new Error(`dsh-auth: snapshot ${route}/${key} has no ${what}`);
81
+ }
82
+ function parseRoute(route, value) {
83
+ const row = record(value, route);
84
+ const roster = boundedStringList(row.roster, `${route} roster`, 500);
85
+ if (roster.some(id => id.length === 0))
86
+ throw new Error(`dsh-auth: snapshot ${route} roster has an empty id`);
87
+ const entriesRaw = record(row.entries ?? {}, `${route} entries`);
88
+ const entries = {};
89
+ for (const key of Object.keys(entriesRaw))
90
+ entries[key] = parseEntry(route, key, entriesRaw[key]);
91
+ const fallback = boundedStringList(row.fallback ?? [], `${route} fallback`, 500);
92
+ return { roster, entries, fallback };
93
+ }
94
+ /** Validate the checked-in snapshot once; a malformed file is a boot error. */
95
+ function parseSnapshotData(input) {
96
+ const root = record(input, 'root');
97
+ if (root.version !== 1)
98
+ throw new Error('dsh-auth: snapshot has an unsupported version');
99
+ if (nonEmptyString(root.generatedAt) === undefined)
100
+ throw new Error('dsh-auth: snapshot has no timestamp');
101
+ return {
102
+ version: 1,
103
+ generatedAt: root.generatedAt,
104
+ piAiVersion: nonEmptyString(root.piAiVersion) ?? 'unknown',
105
+ classifiers: boundedStringList(root.classifiers ?? [], 'classifiers', 500),
106
+ opencode: parseRoute('opencode', root.opencode),
107
+ 'opencode-go': parseRoute('opencode-go', root['opencode-go']),
108
+ };
109
+ }
110
+ const SNAPSHOT = parseSnapshotData(OPENCODE_SNAPSHOT);
111
+ /** Length of the id prefix two models share (`a-b` vs `a-c` share 2). */
112
+ function sharedPrefixLength(a, b) {
113
+ const end = Math.min(a.length, b.length);
114
+ let length = 0;
115
+ while (length < end && a[length] === b[length])
116
+ length += 1;
117
+ return length;
118
+ }
119
+ /** Wire protocols, most universal first, for deterministic sibling choice. */
120
+ function apiRank(api) {
121
+ if (api === 'openai-completions')
122
+ return 0;
123
+ if (api === 'openai-responses')
124
+ return 1;
125
+ if (api === 'anthropic-messages')
126
+ return 2;
127
+ if (api === 'google-generative-ai')
128
+ return 3;
129
+ return 4;
130
+ }
131
+ /**
132
+ * Nearest same-route catalog sibling: longest shared id prefix wins, then
133
+ * the most universal wire protocol, then alphabetical order. Documented
134
+ * approximation, fully deterministic — the same snapshot and catalog always
135
+ * resolve the same wire envelope.
136
+ */
137
+ function nearestSibling(catalog, id) {
138
+ let best = catalog[0];
139
+ if (best === undefined)
140
+ throw new Error('dsh-auth: installed catalog is empty');
141
+ for (const candidate of catalog) {
142
+ const prefix = sharedPrefixLength(candidate.id, id);
143
+ const bestPrefix = sharedPrefixLength(best.id, id);
144
+ if (prefix > bestPrefix
145
+ || (prefix === bestPrefix && apiRank(candidate.api) < apiRank(best.api))
146
+ || (prefix === bestPrefix && apiRank(candidate.api) === apiRank(best.api) && candidate.id < best.id)) {
147
+ best = candidate;
148
+ }
149
+ }
150
+ return best;
151
+ }
152
+ /** pi-ai thinking levels; `off` is always unsupported, the rest map to themselves. */
153
+ const THINKING_LEVELS = ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
154
+ function thinkingLevels(effort, sibling) {
155
+ const siblingMap = (sibling.thinkingLevelMap ?? {});
156
+ const levels = new Set(effort);
157
+ // Only narrow the sibling envelope when every effort value it names fits
158
+ // inside it; otherwise the sibling map stands (documented approximation).
159
+ if (![...levels].every(level => Object.hasOwn(siblingMap, level)))
160
+ return sibling.thinkingLevelMap;
161
+ const map = { off: null };
162
+ for (const level of THINKING_LEVELS) {
163
+ if (!Object.hasOwn(siblingMap, level))
164
+ continue;
165
+ map[level] = levels.has(level) ? level : null;
166
+ }
167
+ return map;
168
+ }
169
+ /**
170
+ * Resolve one snapshot roster id to a pi-shaped model: wire envelope from
171
+ * the sibling, display metadata and capacity from models.dev. pi-ai drops
172
+ * video/pdf/audio modalities (text/image only) and never discloses
173
+ * cache-write pricing, so both are inherited or omitted — see field notes.
174
+ */
175
+ function synthesize(catalog, route, id, entry) {
176
+ const sibling = nearestSibling(catalog, id);
177
+ // Same-route sibling, so its provider id is already the route's own.
178
+ if (entry === undefined)
179
+ return { ...sibling, id, name: id };
180
+ const modalities = new Set(entry.modalities.input);
181
+ if (!modalities.has('text')) {
182
+ throw new Error(`dsh-auth: snapshot ${route}/${id} has no text modality`);
183
+ }
184
+ const compat = entry.temperature === false
185
+ ? { ...sibling.compat, supportsTemperature: false }
186
+ : sibling.compat;
187
+ const input = modalities.has('image') ? ['text', 'image'] : ['text'];
188
+ return {
189
+ ...sibling,
190
+ id,
191
+ name: entry.name,
192
+ reasoning: entry.reasoning ?? sibling.reasoning,
193
+ input: [...input],
194
+ cost: {
195
+ input: entry.cost.input,
196
+ output: entry.cost.output,
197
+ cacheRead: entry.cost.cache_read ?? sibling.cost.cacheRead ?? 0,
198
+ cacheWrite: sibling.cost.cacheWrite ?? 0,
199
+ },
200
+ contextWindow: entry.limit.context,
201
+ maxTokens: entry.limit.output ?? sibling.maxTokens,
202
+ compat,
203
+ thinkingLevelMap: entry.reasoning === false
204
+ ? undefined
205
+ : entry.reasoning_options === undefined
206
+ ? sibling.thinkingLevelMap
207
+ : thinkingLevels(entry.reasoning_options.effort, sibling),
208
+ type: 'chat',
209
+ };
210
+ }
211
+ /**
212
+ * Union the snapshot roster onto one catalog provider. Installed models win
213
+ * on conflict and classifier-roster ids stay on pi-ai's classifier path, so
214
+ * the merged list always covers the installed catalog — a stale snapshot
215
+ * delays additions but never removes a working model.
216
+ * @param catalog - the installed pi-ai catalog provider for one route.
217
+ * @param route - the route the snapshot section is keyed under.
218
+ * @returns the catalog provider, or a shallow clone serving the union.
219
+ */
220
+ export function withFreshModels(catalog, route) {
221
+ const section = SNAPSHOT[route];
222
+ const installed = new Map(catalog.getModels().map(model => [model.id, model]));
223
+ const classifiers = new Set(SNAPSHOT.classifiers);
224
+ const catalogModels = catalog.getModels();
225
+ const extras = [];
226
+ for (const id of section.roster) {
227
+ if (installed.has(id) || classifiers.has(id))
228
+ continue;
229
+ const marker = section.fallback.includes(id);
230
+ const key = marker ? undefined : section.entries[id];
231
+ if (!marker && key === undefined) {
232
+ throw new Error(`dsh-auth: snapshot ${route}/${id} is on the roster but has neither metadata nor a fallback marker`);
233
+ }
234
+ extras.push(synthesize(catalogModels, route, id, key));
235
+ }
236
+ if (extras.length === 0)
237
+ return catalog;
238
+ return {
239
+ ...catalog,
240
+ getModels: () => [...catalog.getModels(), ...extras],
241
+ };
242
+ }
243
+ /** Snapshot roster ids for one route, for smoke coverage. */
244
+ export function freshRosterIds(route) {
245
+ return SNAPSHOT[route].roster.slice();
246
+ }
@@ -73,6 +73,7 @@ export type { AskFn, QuestionBridgeHelpers } from './interaction.js';
73
73
  export { copyToClipboard, openInBrowser, openerFor } from './opener.js';
74
74
  export { CredentialFile, defaultCredentialsFile } from './credentials.js';
75
75
  export { OAUTH_PROVIDER_IDS, CATALOG_PROVIDER_IDS, AUTH_PROVIDER_IDS, canonicalProvider, buildOAuthProfile, type ModelOverride } from './profiles.js';
76
+ export { freshRosterIds, type FreshRouteId } from './fresh-models.js';
76
77
  /**
77
78
  * The adapter the plugin registers: a {@link PiAiAdapter} whose *advisory
78
79
  * catalog* is credential-gated. A provider with no stored credential
@@ -68,6 +68,7 @@ export { QuestionBridge, describeEvent } from './interaction.js';
68
68
  export { copyToClipboard, openInBrowser, openerFor } from './opener.js';
69
69
  export { CredentialFile, defaultCredentialsFile } from './credentials.js';
70
70
  export { OAUTH_PROVIDER_IDS, CATALOG_PROVIDER_IDS, AUTH_PROVIDER_IDS, canonicalProvider, buildOAuthProfile } from './profiles.js';
71
+ export { freshRosterIds } from './fresh-models.js';
71
72
  /**
72
73
  * The ambient auth context providers may consult while resolving their own
73
74
  * auth. `env()` answers from the process environment; `fileExists()` answers