@namzu/zen 2.4.0 → 2.5.2

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 (45) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +30 -11
  3. package/dist/catalogue/catalogue.d.ts +106 -0
  4. package/dist/catalogue/catalogue.d.ts.map +1 -0
  5. package/dist/catalogue/catalogue.js +325 -0
  6. package/dist/catalogue/catalogue.js.map +1 -0
  7. package/dist/catalogue/derive.d.ts +203 -0
  8. package/dist/catalogue/derive.d.ts.map +1 -0
  9. package/dist/catalogue/derive.js +485 -0
  10. package/dist/catalogue/derive.js.map +1 -0
  11. package/dist/catalogue/fetch.d.ts +63 -0
  12. package/dist/catalogue/fetch.d.ts.map +1 -0
  13. package/dist/catalogue/fetch.js +180 -0
  14. package/dist/catalogue/fetch.js.map +1 -0
  15. package/dist/catalogue/index.d.ts +17 -0
  16. package/dist/catalogue/index.d.ts.map +1 -0
  17. package/dist/catalogue/index.js +17 -0
  18. package/dist/catalogue/index.js.map +1 -0
  19. package/dist/client.d.ts +5 -1
  20. package/dist/client.d.ts.map +1 -1
  21. package/dist/client.js +59 -8
  22. package/dist/client.js.map +1 -1
  23. package/dist/index.d.ts +2 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/models.d.ts +6 -0
  28. package/dist/models.d.ts.map +1 -1
  29. package/dist/models.js +49 -9
  30. package/dist/models.js.map +1 -1
  31. package/dist/prompt.d.ts.map +1 -1
  32. package/dist/prompt.js +7 -0
  33. package/dist/prompt.js.map +1 -1
  34. package/dist/types.d.ts +11 -1
  35. package/dist/types.d.ts.map +1 -1
  36. package/package.json +6 -2
  37. package/src/catalogue/catalogue.ts +462 -0
  38. package/src/catalogue/derive.ts +638 -0
  39. package/src/catalogue/fetch.ts +229 -0
  40. package/src/catalogue/index.ts +37 -0
  41. package/src/client.ts +68 -9
  42. package/src/index.ts +2 -1
  43. package/src/models.ts +50 -9
  44. package/src/prompt.ts +7 -0
  45. package/src/types.ts +11 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @namzu/zen
2
2
 
3
+ ## 2.5.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 567ada8: Updated package examples and evaluation fixtures for the SDK's `ToolRegistry`
8
+ removal. Browser, computer-use and LSP documentation now show toolsets; the
9
+ evals use `toolsets` when they call the kernel. Provider changes are test
10
+ fixture migrations only, with no provider runtime API change. Consumers that
11
+ pass tools to the SDK should use `toolsets: readonly Toolset[]` and wrap their
12
+ definitions with `toolset(source, definitions)`.
13
+
14
+ ## 2.5.1
15
+
16
+ ### Patch Changes
17
+
18
+ - 49491b9: A response routed to an Anthropic-backed model that fills the model's context window now carries `finishDetail: 'context_window'` alongside `finishReason: 'length'`. `@ai-sdk/anthropic` folds both `max_tokens` and `model_context_window_exceeded` into `unified: 'length'`, keeping the original word only on `finishReason.raw`, which the driver did not read; the runtime auto-continues a plain `'length'` finish, sending a reply that had just filled the model's context window straight back in, in a prompt now longer than the window it had just overflowed. A plain output-limit `'length'` (`max_tokens`) is unaffected.
19
+ - 443094a: Native replay could be wrongly invalidated by `@namzu/sdk`'s new `BaseMessage.id` field: `createReplayState`'s `prefixDigest` hashed a message's earlier-turn prefix without excluding `id`, so two requests built from the exact same prefix content disagreed on the digest whenever one side was a fresh, never-recorded copy of the other (or a fork's copy, carrying a different session's id for identical content) — a real reasoning/tool-call replay would have been discarded and resent to the model as plain text for no content reason. `id` is now excluded from `prefixDigest` alongside `timestamp`, which it already ignored for the same reason.
20
+
21
+ ## 2.5.0
22
+
23
+ ### Minor Changes
24
+
25
+ - ab9108b: Derive the Zen and Go model catalogue at run time, opt-in. The new `@namzu/zen/catalogue` subpath exports `fetchZenCatalogue()`, which reads the same five sources the bundled snapshot is generated from (both documentation pages, models.dev and both `/models` answers) with a deadline and byte limit per source, and returns a whole validated catalogue plus a report, or rejects. It never returns a partial list. `buildZenCatalogue()` does the same derivation from texts you fetched yourself, and `parseZenCatalogue()` re-admits a stored copy strictly. A derivation is held to the same checks as a stored copy, so a result is never one its own saved copy would fail to read back.
26
+
27
+ Pass the result as the new `ZenConfig.catalogue`, or a function returning it, and the provider checks it before the bundled snapshot for routing, anonymous admission, listing, context windows and effort levels. With a runtime catalogue, a served id that no source gives a wire format for is listed as `<id> (no known wire format)` and can be called only with an explicit `protocol`; the bundled snapshot's entry for such an id, if it has one, is not used. A model name carrying a control, format or line-separator character is refused, in a derivation and in a stored copy.
28
+
29
+ Nothing changes unless you opt in. Importing the package, constructing a provider and `getZenModels`/`findZenModel` still read the bundled snapshot and make no network request. Without `catalogue`, `listModels()` returns what it did before. `ZEN_OMITTED_MODELS` (the reviewed omissions the snapshot was generated under) is now exported from `@namzu/zen` and `@namzu/zen/models`. The bundled roster is unchanged: 61 Zen and 28 Go models.
30
+
3
31
  ## 2.4.0
4
32
 
5
33
  ### Minor Changes
package/README.md CHANGED
@@ -124,15 +124,34 @@ controls also depend on the wire. See the [SDK guide](../../../docs/sdk/zen.md)
124
124
  for configuration and refusal details.
125
125
 
126
126
  `listModels(signal?)` intersects the live service catalogue with supported
127
- bundled models and restricts anonymous results to the explicit public set.
128
- Static limits and USD-per-million-token prices are generated from the
129
- services' own documentation pages by `scripts/generate-zen-models.mjs`, and
130
- are estimates rather than invoices: context tiers, caches, Go peak/off-peak
131
- rates, subscription allowances and promotions can change the effective
132
- charge. Refresh the catalogue with that script; the CI gate fails when a
133
- service documents OR SERVES a model the catalogue neither carries nor omits,
134
- naming it, and the scheduled refresh workflow opens a pull request when
135
- upstream has moved.
127
+ models and restricts anonymous results to the explicit public set.
128
+ Static limits and USD-per-million-token prices are derived from the
129
+ services' own documentation pages, models.dev and the services' `/models`
130
+ answers, and are estimates rather than invoices: context tiers, caches, Go
131
+ peak/off-peak rates, subscription allowances and promotions can change the
132
+ effective charge.
133
+
134
+ The package ships a bundled snapshot of that catalogue and never reaches the
135
+ network for it on its own. A host that wants a fresher roster opts in:
136
+
137
+ ```ts
138
+ import { ZenProvider } from '@namzu/zen'
139
+ import { fetchZenCatalogue } from '@namzu/zen/catalogue'
140
+
141
+ const { catalogue, report } = await fetchZenCatalogue({ timeoutMs: 10_000 })
142
+ const provider = new ZenProvider({ apiKey: process.env.OPENCODE_API_KEY, catalogue })
143
+ console.log(report.servedUndocumented)
144
+ ```
145
+
146
+ `fetchZenCatalogue` reads the five sources with per-source deadlines and byte
147
+ limits, applies the same rules the snapshot is generated with, and either
148
+ returns a whole catalogue or rejects — never a partial list. A runtime
149
+ catalogue takes precedence over the bundled snapshot; an id the service serves
150
+ with no known wire is listed as `<id> (no known wire format)` and is callable
151
+ only with an explicit `protocol`. `parseZenCatalogue` re-admits a stored copy
152
+ with the same strictness. The Namzu CLI refreshes it this way in the
153
+ background on every launch. The bundled snapshot is regenerated by hand with
154
+ `scripts/generate-zen-models.mjs`.
136
155
 
137
156
  Tests use the real provider adapters with local HTTP/SSE fixtures, including
138
157
  tool continuations, signatures, cancellation and error classification.
@@ -140,9 +159,9 @@ An SDK kernel test executes a registered tool and feeds its result into the
140
159
  next model request before completing the turn.
141
160
  On 2026-09-08, live text inference on `muse-spark-1.3-contributor-free`
142
161
  succeeded without an account key through installed OpenCode and Namzu's
143
- driver. A live Namzu `run-stream` call with low effort and production tools
162
+ driver. A live Namzu `run-stream` call (the command is now `namzu exec --json`) with low effort and production tools
144
163
  also read `verification.txt`, then returned its exact nonce, absent from
145
- the prompt, after two model requests. The read succeeded and the run ended
164
+ the prompt, after two model requests. The read succeeded and the turn ended
146
165
  with `end_turn`. This validates that model's public text and file-tool path;
147
166
  it does not establish every public or paid model, Go access, or billing.
148
167
 
@@ -0,0 +1,106 @@
1
+ /**
2
+ * A Zen catalogue assembled at run time from the same sources, by the same
3
+ * rules, as the bundled snapshot in `models.ts`.
4
+ *
5
+ * Nothing here reaches the network. `buildZenCatalogue` turns source TEXTS
6
+ * into a catalogue; `fetch.ts` is the one place those texts are fetched, and
7
+ * only when a caller asks. `parseZenCatalogue` re-admits a catalogue a host
8
+ * stored earlier, with the same strictness a fresh derivation has: a document
9
+ * that is not exactly a catalogue is refused whole, never read in part.
10
+ */
11
+ import { type ZenModel, type ZenService } from '../models.js';
12
+ import { type ZenOmissions } from './derive.js';
13
+ /** The stored shape's version. A document carrying any other is refused. */
14
+ export declare const ZEN_CATALOGUE_VERSION = 1;
15
+ /**
16
+ * A complete Zen and Go roster.
17
+ *
18
+ * `unrouted` lists, per service, the ids the service's own `/models` answer
19
+ * serves that this catalogue neither carries nor omits by review: no source
20
+ * states a wire for them (or the rest of what carrying needs), so a driver
21
+ * lists them as having no known wire format and calls one only when its host
22
+ * names the protocol explicitly.
23
+ */
24
+ export interface ZenCatalogue {
25
+ readonly version: typeof ZEN_CATALOGUE_VERSION;
26
+ /** When the sources were read, as an ISO 8601 timestamp. */
27
+ readonly fetchedAt: string;
28
+ readonly zen: readonly ZenModel[];
29
+ readonly go: readonly ZenModel[];
30
+ readonly unrouted: Readonly<Record<ZenService, readonly string[]>>;
31
+ }
32
+ /** What a derivation found and did not carry. Informational: none of it fails a build. */
33
+ export interface ZenCatalogueReport {
34
+ /** `service/id`: served by the service, documented on no page, omitted by nothing. */
35
+ readonly servedUndocumented: readonly string[];
36
+ /** `[service/id, why]`: documented, not carryable, omitted by nothing. */
37
+ readonly undecided: readonly (readonly [string, string])[];
38
+ /** `service/id`: omissions upstream neither documents nor serves any more. */
39
+ readonly stale: readonly string[];
40
+ /** `service: name`: price rows no route row names. */
41
+ readonly orphanPrices: readonly string[];
42
+ }
43
+ /** The five upstream documents, as the texts they were served as. */
44
+ export interface ZenCatalogueSources {
45
+ readonly docs: Readonly<Record<ZenService, string>>;
46
+ /** `https://models.dev/api.json`. */
47
+ readonly modelsDev: string;
48
+ /** Each service's own `/models` answer. */
49
+ readonly served: Readonly<Record<ZenService, string>>;
50
+ }
51
+ export interface BuildZenCatalogueOptions {
52
+ /**
53
+ * Reviewed omissions, as `service/id` keys or the review file's record.
54
+ * Defaults to the decisions the bundled snapshot was generated under.
55
+ */
56
+ readonly omissions?: ZenOmissions;
57
+ /**
58
+ * The roster a result is measured against for collapse: fewer than 80% of
59
+ * its models on either service refuses the result. Defaults to the bundled
60
+ * snapshot.
61
+ */
62
+ readonly baseline?: Readonly<Record<ZenService, readonly unknown[]>>;
63
+ /** Stamped as `fetchedAt`. Defaults to now. */
64
+ readonly fetchedAt?: Date;
65
+ }
66
+ export interface ZenCatalogueResult {
67
+ readonly catalogue: ZenCatalogue;
68
+ readonly report: ZenCatalogueReport;
69
+ }
70
+ /**
71
+ * Derive a catalogue from upstream texts, or throw `ZenCatalogueSourceError`.
72
+ *
73
+ * All or nothing: a page that moved, a models.dev that changed shape, a served
74
+ * answer with no ids or a roster that collapsed past the floor refuses the
75
+ * whole result, so a caller holding an older catalogue keeps it rather than
76
+ * receiving part of a new one.
77
+ */
78
+ export declare function buildZenCatalogue(sources: ZenCatalogueSources, options?: BuildZenCatalogueOptions): ZenCatalogueResult;
79
+ /** A stored catalogue that is not exactly a catalogue. */
80
+ export declare class ZenCatalogueFormatError extends Error {
81
+ readonly name = "ZenCatalogueFormatError";
82
+ }
83
+ /**
84
+ * Re-admit a catalogue a host stored — the output of `JSON.parse` on what
85
+ * `JSON.stringify(catalogue)` wrote — or throw `ZenCatalogueFormatError`.
86
+ *
87
+ * Every field is checked as strictly as a derivation checks its sources, and a
88
+ * document with one bad field is refused whole: a cache someone edited, a
89
+ * truncated write or a file from another version never becomes a partial
90
+ * roster.
91
+ */
92
+ export declare function parseZenCatalogue(value: unknown): ZenCatalogue;
93
+ /**
94
+ * Exact lookup with the runtime catalogue first and the bundled snapshot
95
+ * second. `catalogue` undefined is the bundled snapshot alone.
96
+ *
97
+ * An id the runtime catalogue lists in `unrouted` is found in neither: the
98
+ * newer sources say the service serves it and state no wire for it, and the
99
+ * bundled snapshot's older entry is not allowed to answer for them. Falling
100
+ * back would route the model on a wire nobody states any more, anonymously
101
+ * too if the old entry said so, and without saying anything.
102
+ */
103
+ export declare function findZenCatalogueModel(catalogue: ZenCatalogue | undefined, service: ZenService, id: string): ZenModel | undefined;
104
+ /** Whether a runtime catalogue lists `id` as served with no known wire format. */
105
+ export declare function isUnroutedZenModel(catalogue: ZenCatalogue | undefined, service: ZenService, id: string): boolean;
106
+ //# sourceMappingURL=catalogue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalogue.d.ts","sourceRoot":"","sources":["../../src/catalogue/catalogue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAEN,KAAK,QAAQ,EAEb,KAAK,UAAU,EAGf,MAAM,cAAc,CAAA;AACrB,OAAO,EAKN,KAAK,YAAY,EAMjB,MAAM,aAAa,CAAA;AAEpB,4EAA4E;AAC5E,eAAO,MAAM,qBAAqB,IAAI,CAAA;AAEtC;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,qBAAqB,CAAA;IAC9C,4DAA4D;IAC5D,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,GAAG,EAAE,SAAS,QAAQ,EAAE,CAAA;IACjC,QAAQ,CAAC,EAAE,EAAE,SAAS,QAAQ,EAAE,CAAA;IAChC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAAA;CAClE;AAED,0FAA0F;AAC1F,MAAM,WAAW,kBAAkB;IAClC,sFAAsF;IACtF,QAAQ,CAAC,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAA;IAC9C,0EAA0E;IAC1E,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAA;IAC1D,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,sDAA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kF;AAClF,wBAAgB,kBAAkB,CACjC,SAAS,EAAE,YAAY,GAAG,SAAS,EACnC,OAAO,EAAE,UAAU,EACnB,EAAE,EAAE,MAAM,GACR,OAAO,CAET"}
@@ -0,0 +1,325 @@
1
+ /**
2
+ * A Zen catalogue assembled at run time from the same sources, by the same
3
+ * rules, as the bundled snapshot in `models.ts`.
4
+ *
5
+ * Nothing here reaches the network. `buildZenCatalogue` turns source TEXTS
6
+ * into a catalogue; `fetch.ts` is the one place those texts are fetched, and
7
+ * only when a caller asks. `parseZenCatalogue` re-admits a catalogue a host
8
+ * stored earlier, with the same strictness a fresh derivation has: a document
9
+ * that is not exactly a catalogue is refused whole, never read in part.
10
+ */
11
+ import { ZEN_OMITTED_MODELS, findZenModel, getZenModels, } from '../models.js';
12
+ import { ZEN_SERVICES, ZenCatalogueSourceError, checkRosterFloor, derive, isDisplayableName, parsePage, parseServed, } from './derive.js';
13
+ /** The stored shape's version. A document carrying any other is refused. */
14
+ export const ZEN_CATALOGUE_VERSION = 1;
15
+ /**
16
+ * Derive a catalogue from upstream texts, or throw `ZenCatalogueSourceError`.
17
+ *
18
+ * All or nothing: a page that moved, a models.dev that changed shape, a served
19
+ * answer with no ids or a roster that collapsed past the floor refuses the
20
+ * whole result, so a caller holding an older catalogue keeps it rather than
21
+ * receiving part of a new one.
22
+ */
23
+ export function buildZenCatalogue(sources, options = {}) {
24
+ const omissions = options.omissions ?? new Set(ZEN_OMITTED_MODELS);
25
+ const omitted = omissions instanceof Set ? omissions : new Set(Object.keys(omissions));
26
+ let modelsDev;
27
+ try {
28
+ modelsDev = JSON.parse(sources.modelsDev);
29
+ }
30
+ catch (error) {
31
+ throw new ZenCatalogueSourceError(`models.dev is not JSON: ${error instanceof Error ? error.message : String(error)}`);
32
+ }
33
+ const carried = { zen: [], go: [] };
34
+ const unrouted = { zen: [], go: [] };
35
+ const servedUndocumented = [];
36
+ const undecided = [];
37
+ const stale = [];
38
+ const orphanPrices = [];
39
+ for (const { service, page, provider } of ZEN_SERVICES) {
40
+ const parsed = parsePage(sources.docs[service], { page, service });
41
+ const served = parseServed(service, sources.served[service]);
42
+ const entry = modelsDev !== null && typeof modelsDev === 'object'
43
+ ? modelsDev[provider]
44
+ : undefined;
45
+ const models = entry !== null && typeof entry === 'object'
46
+ ? entry.models
47
+ : undefined;
48
+ if (models === null || typeof models !== 'object' || Array.isArray(models)) {
49
+ throw new ZenCatalogueSourceError(`models.dev has no \`${provider}\` provider entry.`);
50
+ }
51
+ const derived = derive(service, parsed, provider, { models }, omitted, served);
52
+ carried[service] = derived.models.map(toZenModel);
53
+ const ids = new Set(carried[service].map((model) => model.id));
54
+ unrouted[service] = [...served]
55
+ .filter((id) => !ids.has(id) && !omitted.has(`${service}/${id}`))
56
+ .sort();
57
+ servedUndocumented.push(...derived.servedUncurried.map((id) => `${service}/${id}`));
58
+ undecided.push(...derived.undecided);
59
+ stale.push(...derived.stale.map((id) => `${service}/${id}`));
60
+ orphanPrices.push(...derived.orphanPrices.map((name) => `${service}: ${name}`));
61
+ }
62
+ checkRosterFloor(carried, options.baseline ?? { zen: getZenModels('zen'), go: getZenModels('go') });
63
+ // The result is admitted by the same checks a stored copy of it will face.
64
+ // A derivation that yields something `parseZenCatalogue` would refuse on the
65
+ // next launch — a NaN rate, a repeated id, a name no picker can show — is
66
+ // refused now, whole, instead of becoming this session's roster.
67
+ let catalogue;
68
+ try {
69
+ catalogue = parseZenCatalogue({
70
+ version: ZEN_CATALOGUE_VERSION,
71
+ fetchedAt: (options.fetchedAt ?? new Date()).toISOString(),
72
+ zen: carried.zen,
73
+ go: carried.go,
74
+ unrouted,
75
+ });
76
+ }
77
+ catch (error) {
78
+ if (!(error instanceof ZenCatalogueFormatError))
79
+ throw error;
80
+ throw new ZenCatalogueSourceError(`The derived catalogue is not one a stored copy could be read back as: ${error.message}`);
81
+ }
82
+ return {
83
+ catalogue,
84
+ report: Object.freeze({
85
+ servedUndocumented: Object.freeze(servedUndocumented),
86
+ undecided: Object.freeze(undecided.map((pair) => Object.freeze(pair))),
87
+ stale: Object.freeze(stale),
88
+ orphanPrices: Object.freeze(orphanPrices),
89
+ }),
90
+ };
91
+ }
92
+ /** The shape the bundled snapshot uses: streaming stated, anonymity only when true. */
93
+ function toZenModel(model) {
94
+ return {
95
+ id: model.id,
96
+ name: model.name,
97
+ protocol: model.protocol,
98
+ contextWindow: model.contextWindow,
99
+ maxOutputTokens: model.maxOutputTokens,
100
+ inputModalities: [...model.inputModalities],
101
+ inputPrice: model.inputPrice,
102
+ outputPrice: model.outputPrice,
103
+ supportsToolUse: model.supportsToolUse,
104
+ supportsStreaming: true,
105
+ effortLevels: [...model.effortLevels],
106
+ ...(model.supportsAnonymousAccess ? { supportsAnonymousAccess: true } : {}),
107
+ };
108
+ }
109
+ function freezeCatalogue(catalogue) {
110
+ for (const service of ['zen', 'go']) {
111
+ for (const model of catalogue[service]) {
112
+ if (model.inputModalities)
113
+ Object.freeze(model.inputModalities);
114
+ if (model.effortLevels)
115
+ Object.freeze(model.effortLevels);
116
+ Object.freeze(model);
117
+ }
118
+ Object.freeze(catalogue[service]);
119
+ Object.freeze(catalogue.unrouted[service]);
120
+ }
121
+ Object.freeze(catalogue.unrouted);
122
+ return Object.freeze(catalogue);
123
+ }
124
+ const MODEL_ID = /^[a-z0-9][a-z0-9.-]*$/;
125
+ const PROTOCOLS = new Set([
126
+ 'chat',
127
+ 'responses',
128
+ 'messages',
129
+ 'google',
130
+ ]);
131
+ const INPUT_MODALITIES = new Set([
132
+ 'text',
133
+ 'image',
134
+ 'document',
135
+ ]);
136
+ const EFFORTS = new Set([
137
+ 'none',
138
+ 'minimal',
139
+ 'low',
140
+ 'medium',
141
+ 'high',
142
+ 'xhigh',
143
+ 'max',
144
+ 'ultra',
145
+ ]);
146
+ const MODEL_KEYS = new Set([
147
+ 'id',
148
+ 'name',
149
+ 'protocol',
150
+ 'contextWindow',
151
+ 'maxOutputTokens',
152
+ 'inputModalities',
153
+ 'inputPrice',
154
+ 'outputPrice',
155
+ 'supportsToolUse',
156
+ 'supportsStreaming',
157
+ 'effortLevels',
158
+ 'supportsAnonymousAccess',
159
+ ]);
160
+ /** A stored catalogue that is not exactly a catalogue. */
161
+ export class ZenCatalogueFormatError extends Error {
162
+ name = 'ZenCatalogueFormatError';
163
+ }
164
+ function invalid(where, why) {
165
+ throw new ZenCatalogueFormatError(`${where} ${why}.`);
166
+ }
167
+ function record(value, where) {
168
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
169
+ invalid(where, 'is not an object');
170
+ }
171
+ return value;
172
+ }
173
+ function onlyKeys(value, keys, where) {
174
+ for (const key of Object.keys(value)) {
175
+ if (!keys.has(key))
176
+ invalid(`${where}.${key}`, 'is not a catalogue field');
177
+ }
178
+ }
179
+ function positiveInteger(value, where) {
180
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value <= 0) {
181
+ invalid(where, 'is not a positive integer');
182
+ }
183
+ return value;
184
+ }
185
+ function price(value, where) {
186
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) {
187
+ invalid(where, 'is not a non-negative price');
188
+ }
189
+ return value;
190
+ }
191
+ function members(value, allowed, where, nonEmpty) {
192
+ if (!Array.isArray(value))
193
+ invalid(where, 'is not a list');
194
+ if (nonEmpty && value.length === 0)
195
+ invalid(where, 'is empty');
196
+ for (const item of value) {
197
+ if (typeof item !== 'string' || !allowed.has(item)) {
198
+ invalid(where, `names ${JSON.stringify(item)}, which is not one it may name`);
199
+ }
200
+ }
201
+ if (new Set(value).size !== value.length)
202
+ invalid(where, 'repeats an entry');
203
+ return [...value];
204
+ }
205
+ function parseModel(value, service, where) {
206
+ const raw = record(value, where);
207
+ onlyKeys(raw, MODEL_KEYS, where);
208
+ const id = raw.id;
209
+ if (typeof id !== 'string' || !MODEL_ID.test(id))
210
+ invalid(`${where}.id`, 'is not a model id');
211
+ const name = raw.name;
212
+ if (typeof name !== 'string' ||
213
+ name.trim().length === 0 ||
214
+ name.length > 200 ||
215
+ !isDisplayableName(name)) {
216
+ invalid(`${where}.name`, 'is not a model name');
217
+ }
218
+ const protocol = raw.protocol;
219
+ if (typeof protocol !== 'string' || !PROTOCOLS.has(protocol)) {
220
+ invalid(`${where}.protocol`, 'is not a Zen protocol');
221
+ }
222
+ if (typeof raw.supportsToolUse !== 'boolean') {
223
+ invalid(`${where}.supportsToolUse`, 'is not true or false');
224
+ }
225
+ if (raw.supportsStreaming !== true)
226
+ invalid(`${where}.supportsStreaming`, 'is not true');
227
+ const anonymous = raw.supportsAnonymousAccess;
228
+ if (anonymous !== undefined && (anonymous !== true || service !== 'zen')) {
229
+ invalid(`${where}.supportsAnonymousAccess`, 'is only ever `true`, and only on zen');
230
+ }
231
+ return {
232
+ id,
233
+ name,
234
+ protocol: protocol,
235
+ contextWindow: positiveInteger(raw.contextWindow, `${where}.contextWindow`),
236
+ maxOutputTokens: positiveInteger(raw.maxOutputTokens, `${where}.maxOutputTokens`),
237
+ inputModalities: members(raw.inputModalities, INPUT_MODALITIES, `${where}.inputModalities`, true),
238
+ inputPrice: price(raw.inputPrice, `${where}.inputPrice`),
239
+ outputPrice: price(raw.outputPrice, `${where}.outputPrice`),
240
+ supportsToolUse: raw.supportsToolUse,
241
+ supportsStreaming: true,
242
+ effortLevels: members(raw.effortLevels, EFFORTS, `${where}.effortLevels`, false),
243
+ ...(anonymous === true ? { supportsAnonymousAccess: true } : {}),
244
+ };
245
+ }
246
+ /**
247
+ * Re-admit a catalogue a host stored — the output of `JSON.parse` on what
248
+ * `JSON.stringify(catalogue)` wrote — or throw `ZenCatalogueFormatError`.
249
+ *
250
+ * Every field is checked as strictly as a derivation checks its sources, and a
251
+ * document with one bad field is refused whole: a cache someone edited, a
252
+ * truncated write or a file from another version never becomes a partial
253
+ * roster.
254
+ */
255
+ export function parseZenCatalogue(value) {
256
+ const raw = record(value, 'catalogue');
257
+ onlyKeys(raw, new Set(['version', 'fetchedAt', 'zen', 'go', 'unrouted']), 'catalogue');
258
+ if (raw.version !== ZEN_CATALOGUE_VERSION) {
259
+ invalid('catalogue.version', `is not ${ZEN_CATALOGUE_VERSION}`);
260
+ }
261
+ const fetchedAt = raw.fetchedAt;
262
+ if (typeof fetchedAt !== 'string' ||
263
+ Number.isNaN(Date.parse(fetchedAt)) ||
264
+ new Date(fetchedAt).toISOString() !== fetchedAt) {
265
+ invalid('catalogue.fetchedAt', 'is not an ISO 8601 timestamp');
266
+ }
267
+ const unroutedRaw = record(raw.unrouted, 'catalogue.unrouted');
268
+ onlyKeys(unroutedRaw, new Set(['zen', 'go']), 'catalogue.unrouted');
269
+ const carried = { zen: [], go: [] };
270
+ const unrouted = { zen: [], go: [] };
271
+ for (const service of ['zen', 'go']) {
272
+ const list = raw[service];
273
+ if (!Array.isArray(list) || list.length === 0) {
274
+ invalid(`catalogue.${service}`, 'is not a non-empty list of models');
275
+ }
276
+ carried[service] = list.map((entry, index) => parseModel(entry, service, `catalogue.${service}[${index}]`));
277
+ const ids = new Set(carried[service].map((model) => model.id));
278
+ if (ids.size !== carried[service].length)
279
+ invalid(`catalogue.${service}`, 'repeats a model id');
280
+ const names = unroutedRaw[service];
281
+ if (!Array.isArray(names))
282
+ invalid(`catalogue.unrouted.${service}`, 'is not a list');
283
+ for (const id of names) {
284
+ if (typeof id !== 'string' || !MODEL_ID.test(id)) {
285
+ invalid(`catalogue.unrouted.${service}`, `names ${JSON.stringify(id)}, which is not a model id`);
286
+ }
287
+ if (ids.has(id))
288
+ invalid(`catalogue.unrouted.${service}`, `names the carried model "${id}"`);
289
+ }
290
+ if (new Set(names).size !== names.length) {
291
+ invalid(`catalogue.unrouted.${service}`, 'repeats an id');
292
+ }
293
+ unrouted[service] = [...names];
294
+ }
295
+ return freezeCatalogue({
296
+ version: ZEN_CATALOGUE_VERSION,
297
+ fetchedAt,
298
+ zen: carried.zen,
299
+ go: carried.go,
300
+ unrouted,
301
+ });
302
+ }
303
+ /**
304
+ * Exact lookup with the runtime catalogue first and the bundled snapshot
305
+ * second. `catalogue` undefined is the bundled snapshot alone.
306
+ *
307
+ * An id the runtime catalogue lists in `unrouted` is found in neither: the
308
+ * newer sources say the service serves it and state no wire for it, and the
309
+ * bundled snapshot's older entry is not allowed to answer for them. Falling
310
+ * back would route the model on a wire nobody states any more, anonymously
311
+ * too if the old entry said so, and without saying anything.
312
+ */
313
+ export function findZenCatalogueModel(catalogue, service, id) {
314
+ const runtime = catalogue?.[service].find((model) => model.id === id);
315
+ if (runtime)
316
+ return runtime;
317
+ if (isUnroutedZenModel(catalogue, service, id))
318
+ return undefined;
319
+ return findZenModel(service, id);
320
+ }
321
+ /** Whether a runtime catalogue lists `id` as served with no known wire format. */
322
+ export function isUnroutedZenModel(catalogue, service, id) {
323
+ return catalogue?.unrouted[service].includes(id) === true;
324
+ }
325
+ //# sourceMappingURL=catalogue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"catalogue.js","sourceRoot":"","sources":["../../src/catalogue/catalogue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EACN,kBAAkB,EAIlB,YAAY,EACZ,YAAY,GACZ,MAAM,cAAc,CAAA;AACrB,OAAO,EAGN,YAAY,EACZ,uBAAuB,EAEvB,gBAAgB,EAChB,MAAM,EACN,iBAAiB,EACjB,SAAS,EACT,WAAW,GACX,MAAM,aAAa,CAAA;AAEpB,4EAA4E;AAC5E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAA;AA8DtC;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAChC,OAA4B,EAC5B,UAAoC,EAAE;IAEtC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,GAAG,CAAC,kBAAkB,CAAC,CAAA;IAClE,MAAM,OAAO,GAAG,SAAS,YAAY,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;IACtF,IAAI,SAAkB,CAAA;IACtB,IAAI,CAA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