@trazum/cli 1.51.2 → 1.52.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trazum/cli",
3
- "version": "1.51.2",
3
+ "version": "1.52.1",
4
4
  "description": "Trazum CLI: find where your LLM bill goes, price every finding per month, and enforce token budgets in CI.",
5
5
  "license": "MIT",
6
6
  "author": "David Mu\u00f1oz Rey",
@@ -37,7 +37,7 @@
37
37
  "prepublishOnly": "npm run build && npm test"
38
38
  },
39
39
  "dependencies": {
40
- "@trazum/core": "1.51.2"
40
+ "@trazum/core": "1.52.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^26.2.0",
@@ -59,15 +59,107 @@ export const MAX_GATEWAY_BODY_BYTES = 8 * 1024 * 1024;
59
59
  * proxy for somebody's API key, and the budget decision only has meaning for
60
60
  * the endpoint that spends tokens.
61
61
  */
62
- export const UPSTREAMS: Readonly<Record<string, { origin: string; path: string }>> = {
62
+ export interface Upstream {
63
+ origin: string;
64
+ /**
65
+ * The one path, or the one *shape* of path when the model is part of it.
66
+ *
67
+ * A pattern is not a widening. It exists because Google puts the model in
68
+ * the URL rather than the body, so "one path" cannot be written down as a
69
+ * literal for that provider — and every pattern here is anchored at both
70
+ * ends with the model segment restricted to characters a model id is made
71
+ * of, which is a narrower grammar than a literal comparison against a string
72
+ * somebody could have put a `?` or a `..` in.
73
+ */
74
+ path: string | RegExp;
75
+ /**
76
+ * Where the model name is, when the request body does not carry one.
77
+ *
78
+ * Gemini's body has `contents` and no `model` field. Reading it out of the
79
+ * validated path is the only honest source: the alternative is a gateway
80
+ * that forwards a call it could not price, which is the one thing standing
81
+ * in the path was for.
82
+ */
83
+ modelIn?: 'path';
84
+ }
85
+
86
+ export const UPSTREAMS: Readonly<Record<string, Upstream>> = {
63
87
  anthropic: { origin: 'https://api.anthropic.com', path: '/v1/messages' },
64
88
  openai: { origin: 'https://api.openai.com', path: '/v1/chat/completions' },
89
+ /**
90
+ * DeepSeek's host is not a new fact: `scripts/measure-token-band.mjs` has
91
+ * sent a real API key to `https://api.deepseek.com/chat/completions` since
92
+ * the band harness learned a second provider. Reusing the endpoint this
93
+ * repository already trusts with a credential is the difference between
94
+ * adding an upstream and inventing one — and the path has no `/v1`, which is
95
+ * the kind of detail recall gets wrong.
96
+ */
97
+ deepseek: { origin: 'https://api.deepseek.com', path: '/chat/completions' },
98
+ /**
99
+ * Google, on the same rule and from a fuller record than DeepSeek's.
100
+ *
101
+ * `packages/core/src/llm.ts` has sent a real key to
102
+ * `https://generativelanguage.googleapis.com` at
103
+ * `/v1beta/models/{model}:generateContent`, with the key in an
104
+ * `x-goog-api-key` header rather than the query string, since the Gemini
105
+ * provider landed. `packages/core/src/usage.ts` has read the counts that
106
+ * come back. Host, path, credential header and response shape are all
107
+ * facts this repository already holds — nothing here was recalled.
108
+ *
109
+ * Only `:generateContent`. `:streamGenerateContent` and `:countTokens` are
110
+ * different operations whose shapes nobody here has established, and a
111
+ * gateway that forwards an operation it cannot read is a general proxy for
112
+ * somebody's key with extra steps.
113
+ */
114
+ google: {
115
+ origin: 'https://generativelanguage.googleapis.com',
116
+ path: /^\/v1beta\/models\/([A-Za-z0-9._-]+):generateContent$/,
117
+ modelIn: 'path',
118
+ },
65
119
  };
66
120
 
121
+ /**
122
+ * The path this gateway forwards for a provider, as a person reads it.
123
+ *
124
+ * One phrasing, used by the refusal, the documentation guard and the security
125
+ * allowlist — because three renderings of the same fact is how the page, the
126
+ * refusal and the test come to disagree about what is actually forwarded.
127
+ */
128
+ export function forwards(upstream: Upstream): string {
129
+ return typeof upstream.path === 'string' ? upstream.path : '/v1beta/models/{model}:generateContent';
130
+ }
131
+
132
+ /**
133
+ * Whether this request is the one call this gateway speaks for, and the model
134
+ * the path named if it named one.
135
+ *
136
+ * The returned path is **built here**, never the caller's string echoed back.
137
+ * A pattern that matched is evidence the request was well formed; it is not a
138
+ * licence to forward whatever matched it. Nothing reaches the upstream URL
139
+ * except the compiled-in origin and a path assembled from a model id that has
140
+ * already been restricted to `[A-Za-z0-9._-]`.
141
+ */
142
+ export function route(upstream: Upstream, url: string | undefined): { path: string; model: string | null } | null {
143
+ if (url === undefined) return null;
144
+ if (typeof upstream.path === 'string') {
145
+ return url === upstream.path ? { path: upstream.path, model: null } : null;
146
+ }
147
+ const matched = upstream.path.exec(url);
148
+ const model = matched?.[1];
149
+ // A pattern that matched but captured nothing would otherwise build a path
150
+ // containing the word `undefined` and forward it. Refusing is the only
151
+ // answer: there is no model, so there is nothing to price the call against.
152
+ if (model === undefined) return null;
153
+ return { path: `/v1beta/models/${model}:generateContent`, model };
154
+ }
155
+
67
156
  /**
68
157
  * Headers Trazum adds or removes. Everything else the caller sent is forwarded
69
158
  * verbatim, including their credential, which this never reads.
70
159
  */
160
+ /** Why a forwarded call's cost could not be measured. */
161
+ export type UnmeasuredCause = 'stream-broke' | 'no-usage-event' | 'no-usage-in-body';
162
+
71
163
  const HOP_BY_HOP = new Set([
72
164
  'connection',
73
165
  'keep-alive',
@@ -103,6 +195,26 @@ export interface GatewayContext {
103
195
  cacheWriteTokens: number;
104
196
  substituted: boolean;
105
197
  }) => void;
198
+ /**
199
+ * A call that was forwarded and whose cost could not be measured.
200
+ *
201
+ * The money is spent either way — the provider generated what it generated —
202
+ * and the period's total will be lower than the bill by however much these
203
+ * came to. Naming them is the only honest option: a zero would be a
204
+ * measurement, and inventing an estimate would merge the two halves this
205
+ * product spent an arc separating.
206
+ *
207
+ * Two causes, and the second is not a failure at all:
208
+ *
209
+ * - `stream-broke` — the connection died before the event carrying the
210
+ * counts. Rare, and a real error.
211
+ * - `no-usage-event` — the stream simply carried no counts. On OpenAI that is
212
+ * **every streaming call** unless the caller passed `stream_options:
213
+ * {include_usage: true}`, so this is the common case rather than the
214
+ * exception, and an operator who is not told will read a total that is
215
+ * quietly missing most of their traffic.
216
+ */
217
+ unmeasured?: (cause: UnmeasuredCause) => void;
106
218
  /** A line for the operator's terminal. Never given a body, ever. */
107
219
  note: (line: string) => void;
108
220
  /** Injected so the proxy is testable against a stub upstream. */
@@ -133,7 +245,7 @@ async function readBody(request: IncomingMessage): Promise<string | null> {
133
245
  * of here, including the decision and the record, is structurally incapable of
134
246
  * carrying a prompt.
135
247
  */
136
- function describe(body: string, provider: string): {
248
+ function describe(body: string, provider: string, modelFromPath: string | null): {
137
249
  model: string;
138
250
  inputTokens: number | null;
139
251
  maxOutputTokens: number | null;
@@ -147,7 +259,15 @@ function describe(body: string, provider: string): {
147
259
  }
148
260
  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) return null;
149
261
  const request = parsed as Record<string, unknown>;
150
- if (typeof request.model !== 'string') return null;
262
+ /**
263
+ * The body's model, or the one the validated path named.
264
+ *
265
+ * Never both, and the path never overrides a body that carried one: a
266
+ * gateway that preferred the URL could price a call as one model and forward
267
+ * it as another, which is the substitution this product exists to refuse.
268
+ */
269
+ const model = typeof request.model === 'string' ? request.model : modelFromPath;
270
+ if (model === null) return null;
151
271
 
152
272
  // Every text field the wire format puts in front of the model, counted and
153
273
  // then dropped. `JSON.stringify` of the messages over-counts by the
@@ -158,12 +278,25 @@ function describe(body: string, provider: string): {
158
278
  if (typeof request.system === 'string') parts.push(request.system);
159
279
  if (Array.isArray(request.messages)) parts.push(JSON.stringify(request.messages));
160
280
  if (Array.isArray(request.input)) parts.push(JSON.stringify(request.input));
281
+ // Gemini names the same two things differently: the system prompt is a
282
+ // `systemInstruction` document rather than a string, and the turns are
283
+ // `contents` rather than `messages`. Counted the same way and dropped the
284
+ // same way.
285
+ if (typeof request.systemInstruction === 'object' && request.systemInstruction !== null) {
286
+ parts.push(JSON.stringify(request.systemInstruction));
287
+ }
288
+ if (Array.isArray(request.contents)) parts.push(JSON.stringify(request.contents));
161
289
 
162
290
  const text = parts.join('\n');
163
- const max = provider === 'anthropic' ? request.max_tokens : request.max_completion_tokens ?? request.max_tokens;
291
+ const generation = typeof request.generationConfig === 'object' && request.generationConfig !== null
292
+ ? (request.generationConfig as Record<string, unknown>).maxOutputTokens
293
+ : undefined;
294
+ const max = provider === 'anthropic'
295
+ ? request.max_tokens
296
+ : request.max_completion_tokens ?? request.max_tokens ?? generation;
164
297
 
165
298
  return {
166
- model: request.model,
299
+ model,
167
300
  inputTokens: text === '' ? null : estimateTokens(text),
168
301
  maxOutputTokens: typeof max === 'number' && Number.isFinite(max) ? max : null,
169
302
  /**
@@ -213,11 +346,19 @@ export function buildGateway(context: GatewayContext): Server {
213
346
  response.end(`${JSON.stringify({ error: 'no upstream configured for this provider' })}\n`);
214
347
  return;
215
348
  }
216
- if (request.method !== 'POST' || request.url !== upstream.path) {
349
+ const routed = request.method === 'POST' ? route(upstream, request.url) : null;
350
+ if (routed === null) {
217
351
  // Only the one path that spends tokens. A gateway forwarding anything
218
352
  // else is a general proxy for somebody's API key.
219
353
  response.writeHead(404, { 'content-type': 'application/json' });
220
- response.end(`${JSON.stringify({ error: 'not a path this gateway forwards' })}\n`);
354
+ response.end(
355
+ // A refusal never arrives bare: the one thing it does forward, said
356
+ // from the upstream table rather than written out again here.
357
+ `${JSON.stringify({
358
+ error: 'not a path this gateway forwards',
359
+ forwards: `POST ${forwards(upstream)}`,
360
+ })}\n`,
361
+ );
221
362
  return;
222
363
  }
223
364
 
@@ -228,7 +369,7 @@ export function buildGateway(context: GatewayContext): Server {
228
369
  return;
229
370
  }
230
371
 
231
- const described = describe(body, context.provider);
372
+ const described = describe(body, context.provider, routed.model);
232
373
  if (described === null) {
233
374
  response.writeHead(400, { 'content-type': 'application/json' });
234
375
  response.end(`${JSON.stringify({ error: 'could not read a model out of this request' })}\n`);
@@ -280,7 +421,7 @@ export function buildGateway(context: GatewayContext): Server {
280
421
 
281
422
  let upstreamResponse: Response;
282
423
  try {
283
- upstreamResponse = await doFetch(`${upstream.origin}${upstream.path}`, {
424
+ upstreamResponse = await doFetch(`${upstream.origin}${routed.path}`, {
284
425
  method: 'POST',
285
426
  headers: outgoing,
286
427
  body: forwarded,
@@ -343,7 +484,30 @@ export function buildGateway(context: GatewayContext): Server {
343
484
  } catch {
344
485
  measured = null;
345
486
  }
346
- recordUsage(usageFromResponse(context.provider, measured));
487
+ const buffered = usageFromResponse(context.provider, measured);
488
+ /**
489
+ * The buffered path was the silent one.
490
+ *
491
+ * 1.52 taught the streaming path to say *this call is unmeasured*
492
+ * when no usage event arrived, and left this branch recording nothing
493
+ * and saying nothing — the same silence, on the other side of one
494
+ * `if`. A guard that covers one branch of a fork reads as coverage of
495
+ * the fork.
496
+ *
497
+ * Only on a response the provider called **ok**. An upstream error
498
+ * carries no counts because it produced none, and its own status
499
+ * already says so; announcing those as unmeasured calls would bury the
500
+ * ones that actually spent money.
501
+ */
502
+ if (buffered === null && upstreamResponse.ok) {
503
+ // The word "body" is deliberately not in this sentence. A security
504
+ // test refuses any `note(...)` mentioning it, prose or variable,
505
+ // because the cost of that rule being blunt is one word of wording
506
+ // and the cost of it being clever is somebody's prompt in a log.
507
+ context.note(`${described.model} answered with no usage counts — this call is unmeasured`);
508
+ context.unmeasured?.('no-usage-in-body');
509
+ }
510
+ recordUsage(buffered);
347
511
  response.writeHead(upstreamResponse.status, back);
348
512
  response.end(text);
349
513
  return;
@@ -378,11 +542,22 @@ export function buildGateway(context: GatewayContext): Server {
378
542
  context.note(
379
543
  `stream broke before its usage event: ${error instanceof Error ? error.message : String(error)} — this call is unmeasured`,
380
544
  );
545
+ context.unmeasured?.('stream-broke');
381
546
  response.destroy();
382
547
  return;
383
548
  }
384
549
 
385
- recordUsage(reader.done());
550
+ const streamed = reader.done();
551
+ if (streamed === null) {
552
+ /**
553
+ * The stream ended cleanly and carried no counts. Not an error, and on
554
+ * OpenAI not even unusual — but the call is still unmeasured, and the
555
+ * operator has to hear it from here rather than infer it from a total
556
+ * that looks too small.
557
+ */
558
+ context.unmeasured?.('no-usage-event');
559
+ }
560
+ recordUsage(streamed);
386
561
  response.end();
387
562
  })();
388
563
  });
package/src/i18n/en.ts CHANGED
@@ -1262,9 +1262,29 @@ ${bold('EXAMPLES')}
1262
1262
  given === ''
1263
1263
  ? `Name the provider to stand in front of. Known: ${known}.`
1264
1264
  : `"${given}" is not a provider this gateway speaks for. Known: ${known}.`,
1265
+ pricedNotFronted: (given, known) =>
1266
+ `Trazum prices ${given} but this gateway does not stand in front of it yet — it fronts ${known}. That is a real gap and it is on the roadmap, not a typo on your part. Until then: "trazum profile" prices a ${given} log you export, and its --max-usd gate fails a build on the bill after the fact. What you do not get is a refusal before the money is spent, which is the whole point of the gateway and the reason this is worth saying rather than listing ${given} as unknown.`,
1265
1267
  needsPolicy: (policies) =>
1266
1268
  `--on-cannot-tell is required, and there is no default: ${policies}. When the gateway cannot judge a call — no budget, nothing measured, an unpriced model — one of these happens, and only you know which failure your product can survive. fail-open keeps it working and lets the bill run; fail-closed stops the bill and takes it down with it. Picking one for you would be the most consequential decision in your architecture, made silently at install time.`,
1267
1269
  listening: (where, provider) => `Gateway on ${where}, in front of ${provider}`,
1270
+ /**
1271
+ * One sentence per cause, and no `else`.
1272
+ *
1273
+ * This was a two-branch ternary whose second arm explained OpenAI's
1274
+ * `stream_options`. A third cause added later would have inherited that
1275
+ * sentence and told a Gemini user about a setting that does not exist in
1276
+ * their SDK — a message bounded by its neighbour rather than by its
1277
+ * subject, which is this project's most repeated mistake.
1278
+ */
1279
+ unmeasured: (cause, sofar) => {
1280
+ if (cause === 'stream-broke') {
1281
+ return `unmeasured: the stream broke before its usage event — the provider billed this call and this session cannot see it (${sofar} unmeasured so far)`;
1282
+ }
1283
+ if (cause === 'no-usage-event') {
1284
+ return `unmeasured: the stream carried no usage event — on OpenAI that is every streaming call without stream_options.include_usage, so the total below is short by these (${sofar} unmeasured so far)`;
1285
+ }
1286
+ return `unmeasured: the provider answered without any usage in the body — the call was made and its cost is not knowable from the response, so the total below is short by these (${sofar} unmeasured so far)`;
1287
+ },
1268
1288
  pointYourSdk: (where) =>
1269
1289
  `Point your SDK's base URL at ${where} and change nothing else. It speaks the provider's own wire format, so no code changes and no new client.`,
1270
1290
  credential: () =>
@@ -2242,6 +2262,8 @@ ${bold('EXAMPLES')}
2242
2262
  `Name a provider to read your bill from: trazum connect anthropic. Available: ${providers}. The credential comes from the environment and is never stored — add --dry-run to see exactly what would be called and which variable it would be read from.`,
2243
2263
  unknownProvider: (id, providers) =>
2244
2264
  `There is no connector for "${id}". The ones that exist are: ${providers}.`,
2265
+ pricedNoConnector: (id, providers) =>
2266
+ `Trazum prices ${id} but has no connector for it yet — it connects to ${providers}. Either that provider publishes no usage API, or one has not been written; both are gaps rather than mistakes of yours. Until then, export a log and run "trazum profile" on it: every figure works except the ones a usage API would supply on its own.`,
2245
2267
  dryRun: (provider, from, to, envVars, keyKind) =>
2246
2268
  `Would read ${provider} usage from ${from} to ${to}, using ${keyKind} taken from ${envVars}. Nothing was sent and no credential was needed to print this.`,
2247
2269
  heading: (provider, from, to, usd, calls) =>
package/src/i18n/es.ts CHANGED
@@ -1299,9 +1299,20 @@ ${bold('EJEMPLOS')}
1299
1299
  given === ''
1300
1300
  ? `Nombra el proveedor delante del que ponerse. Conocidos: ${known}.`
1301
1301
  : `"${given}" no es un proveedor por el que hable esta pasarela. Conocidos: ${known}.`,
1302
+ pricedNotFronted: (given, known) =>
1303
+ `Trazum tarifa ${given} pero esta pasarela todavía no se pone delante de él — cubre ${known}. Es un hueco real y está en la hoja de ruta, no una errata tuya. Mientras tanto: "trazum profile" tarifa un registro de ${given} que exportes, y su gate --max-usd tumba una build por la factura ya gastada. Lo que no tienes es un rechazo antes de gastar el dinero, que es justo el sentido de la pasarela y la razón de decir esto en vez de listar ${given} como desconocido.`,
1302
1304
  needsPolicy: (policies) =>
1303
1305
  `--on-cannot-tell es obligatorio, y no hay valor por defecto: ${policies}. Cuando la pasarela no puede juzgar una llamada — sin presupuesto, sin nada medido, un modelo sin precio — pasa una de las dos, y solo tú sabes qué fallo puede sobrevivir tu producto. fail-open lo mantiene funcionando y deja correr la factura; fail-closed para la factura y se lo lleva por delante. Elegir por ti sería tomar la decisión más consecuente de tu arquitectura, en silencio, al instalar.`,
1304
1306
  listening: (where, provider) => `Pasarela en ${where}, delante de ${provider}`,
1307
+ unmeasured: (cause, sofar) => {
1308
+ if (cause === 'stream-broke') {
1309
+ return `sin medir: el stream se rompió antes de su evento de uso — el proveedor facturó esta llamada y esta sesión no puede verla (${sofar} sin medir hasta ahora)`;
1310
+ }
1311
+ if (cause === 'no-usage-event') {
1312
+ return `sin medir: el stream no llevó evento de uso — en OpenAI eso es toda llamada en streaming sin stream_options.include_usage, así que el total de abajo se queda corto (${sofar} sin medir hasta ahora)`;
1313
+ }
1314
+ return `sin medir: el proveedor respondió sin uso alguno en el cuerpo — la llamada se hizo y su coste no es deducible de la respuesta, así que el total de abajo se queda corto (${sofar} sin medir hasta ahora)`;
1315
+ },
1305
1316
  pointYourSdk: (where) =>
1306
1317
  `Apunta la URL base de tu SDK a ${where} y no cambies nada más. Habla el formato del propio proveedor, así que no hay cambios de código ni cliente nuevo.`,
1307
1318
  credential: () =>
@@ -2261,6 +2272,8 @@ ${bold('EJEMPLOS')}
2261
2272
  `Nombra un proveedor del que leer tu factura: trazum connect anthropic. Disponibles: ${providers}. La credencial sale del entorno y nunca se guarda — añade --dry-run para ver exactamente qué se llamaría y de qué variable saldría.`,
2262
2273
  unknownProvider: (id, providers) =>
2263
2274
  `No hay conector para "${id}". Los que existen son: ${providers}.`,
2275
+ pricedNoConnector: (id, providers) =>
2276
+ `Trazum tarifa ${id} pero todavía no tiene conector para él — conecta con ${providers}. O ese proveedor no publica una API de uso, o nadie ha escrito el conector; ambos son huecos, no errores tuyos. Mientras tanto, exporta un registro y pásale "trazum profile": funciona todo salvo lo que solo una API de uso podría aportar.`,
2264
2277
  dryRun: (provider, from, to, envVars, keyKind) =>
2265
2278
  `Leería el uso de ${provider} del ${from} al ${to}, usando ${keyKind} tomada de ${envVars}. No se envió nada y no hizo falta ninguna credencial para imprimir esto.`,
2266
2279
  heading: (provider, from, to, usd, calls) =>
package/src/i18n/types.ts CHANGED
@@ -377,8 +377,10 @@ export interface CliMessages {
377
377
 
378
378
  gateway: {
379
379
  badProvider(given: string, known: string): string;
380
+ pricedNotFronted(given: string, known: string): string;
380
381
  needsPolicy(policies: string): string;
381
382
  listening(where: string, provider: string): string;
383
+ unmeasured(cause: 'stream-broke' | 'no-usage-event' | 'no-usage-in-body', sofar: number): string;
382
384
  pointYourSdk(where: string): string;
383
385
  credential(): string;
384
386
  neverSubstitutes(): string;
@@ -1420,6 +1422,7 @@ export interface CliMessages {
1420
1422
  connect: {
1421
1423
  noTarget(providers: string): string;
1422
1424
  unknownProvider(id: string, providers: string): string;
1425
+ pricedNoConnector(id: string, providers: string): string;
1423
1426
  /** What would be called, with no key needed and nothing sent. */
1424
1427
  dryRun(provider: string, from: string, to: string, envVars: string, keyKind: string): string;
1425
1428
  /** `calls` is null on a source that serves no request count. */
package/src/index.ts CHANGED
@@ -2131,6 +2131,18 @@ function commandFeedback(t: CliMessages): void {
2131
2131
  * config, with the operator's own reason, and every substituted call is marked
2132
2132
  * so no later report treats it as the call the caller made.
2133
2133
  */
2134
+ /**
2135
+ * Every provider the catalogue prices.
2136
+ *
2137
+ * `provider` is optional on a model — an overlay may add one without it — so a
2138
+ * missing provider is skipped rather than coerced. A model with no provider
2139
+ * cannot make its provider "supported" by accident.
2140
+ */
2141
+ function pricedProviders(catalogue: PricingCatalogue): Set<string> {
2142
+ const models = catalogue.models ?? [];
2143
+ return new Set(models.map((m) => m.provider).filter((p): p is string => typeof p === 'string'));
2144
+ }
2145
+
2134
2146
  async function commandGateway(
2135
2147
  args: Args,
2136
2148
  config: TrazumConfig,
@@ -2140,6 +2152,22 @@ async function commandGateway(
2140
2152
  ): Promise<void> {
2141
2153
  const provider = args.positional[0];
2142
2154
  if (provider === undefined || UPSTREAMS[provider] === undefined) {
2155
+ /**
2156
+ * Three answers, not two.
2157
+ *
2158
+ * A provider Trazum **prices** but does not front is a different situation
2159
+ * from a name it has never heard, and until 1.53 both got the same
2160
+ * sentence. One is a gap in this tool with a workaround; the other is a
2161
+ * typo. Telling them apart is the difference between a user reaching for
2162
+ * `profile` and a user checking their spelling.
2163
+ *
2164
+ * Derived from the catalogue, so a provider added to pricing starts
2165
+ * getting the better answer without anyone remembering to update a list.
2166
+ */
2167
+ const priced = pricedProviders(pricing);
2168
+ if (provider !== undefined && priced.has(provider)) {
2169
+ throw new Error(t.gateway.pricedNotFronted(provider, Object.keys(UPSTREAMS).join(', ')));
2170
+ }
2143
2171
  throw new Error(t.gateway.badProvider(provider ?? '', Object.keys(UPSTREAMS).join(', ')));
2144
2172
  }
2145
2173
 
@@ -2178,6 +2206,14 @@ async function commandGateway(
2178
2206
  };
2179
2207
 
2180
2208
  const measured: { calls: number; usd: number } = { calls: 0, usd: 0 };
2209
+ /**
2210
+ * Forwarded calls whose cost this session cannot see.
2211
+ *
2212
+ * Counted separately and never folded into `measured`: the money was spent,
2213
+ * so the two are not interchangeable, and a total that quietly absorbed them
2214
+ * would be the flattering direction.
2215
+ */
2216
+ let unmeasured = 0;
2181
2217
  const server = buildGateway({
2182
2218
  provider,
2183
2219
  catalogue: pricing,
@@ -2200,6 +2236,10 @@ async function commandGateway(
2200
2236
  ),
2201
2237
  );
2202
2238
  },
2239
+ unmeasured: (cause) => {
2240
+ unmeasured += 1;
2241
+ console.error(c.yellow(` ${t.gateway.unmeasured(cause, unmeasured)}`));
2242
+ },
2203
2243
  note: (line) => {
2204
2244
  console.error(c.yellow(` ${line}`));
2205
2245
  },
@@ -4597,7 +4637,12 @@ async function commandConnect(
4597
4637
  }
4598
4638
  const descriptor = connectorFor(id);
4599
4639
  if (descriptor === null) {
4600
- throw new Error(t.connect.unknownProvider(id, CONNECTORS.map((c) => c.id).join(', ')));
4640
+ // The same three-way split as the gateway, for the same reason.
4641
+ const priced = pricedProviders(pricing);
4642
+ const known = CONNECTORS.map((c) => c.id).join(', ');
4643
+ throw new Error(
4644
+ priced.has(id) ? t.connect.pricedNoConnector(id, known) : t.connect.unknownProvider(id, known),
4645
+ );
4601
4646
  }
4602
4647
 
4603
4648
  const now = Date.now();