@trazum/cli 1.83.0 → 1.85.0
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/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +5 -0
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +5 -0
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +11 -0
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +93 -18
- package/dist/index.js.map +1 -1
- package/dist/optional-counters.d.ts +18 -0
- package/dist/optional-counters.d.ts.map +1 -0
- package/dist/optional-counters.js +20 -0
- package/dist/optional-counters.js.map +1 -0
- package/dist/style.d.ts +11 -0
- package/dist/style.d.ts.map +1 -1
- package/dist/style.js +11 -0
- package/dist/style.js.map +1 -1
- package/package.json +2 -2
- package/src/i18n/en.ts +6 -0
- package/src/i18n/es.ts +6 -0
- package/src/i18n/types.ts +11 -0
- package/src/index.ts +113 -1
- package/src/optional-counters.ts +21 -0
- package/src/style.ts +12 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Providers whose tokens an optional package can count exactly, by provider id.
|
|
3
|
+
*
|
|
4
|
+
* Its own module rather than a constant inside the command, because two
|
|
5
|
+
* different readers need it: the CLI, to decide whether to try loading one, and
|
|
6
|
+
* `band-family.test.js`, which walks every priced provider and asserts that the
|
|
7
|
+
* ones this tool cannot count are refused by name. That suite's whole design is
|
|
8
|
+
* that a family leaves its assertions by *becoming countable* rather than by
|
|
9
|
+
* anybody editing the test -- which only works if there is one place that says
|
|
10
|
+
* which families those are.
|
|
11
|
+
*
|
|
12
|
+
* A map rather than a list, so the refusal for a family that is not installed
|
|
13
|
+
* can name the package that would fix it.
|
|
14
|
+
*/
|
|
15
|
+
export declare const OPTIONAL_COUNTERS: Readonly<Record<string, string>>;
|
|
16
|
+
/** Whether some optional package exists that counts this provider exactly. */
|
|
17
|
+
export declare const countableLocally: (provider: string | null | undefined) => boolean;
|
|
18
|
+
//# sourceMappingURL=optional-counters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional-counters.d.ts","sourceRoot":"","sources":["../src/optional-counters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE7D,CAAC;AAEH,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,aAAc,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OACO,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Providers whose tokens an optional package can count exactly, by provider id.
|
|
3
|
+
*
|
|
4
|
+
* Its own module rather than a constant inside the command, because two
|
|
5
|
+
* different readers need it: the CLI, to decide whether to try loading one, and
|
|
6
|
+
* `band-family.test.js`, which walks every priced provider and asserts that the
|
|
7
|
+
* ones this tool cannot count are refused by name. That suite's whole design is
|
|
8
|
+
* that a family leaves its assertions by *becoming countable* rather than by
|
|
9
|
+
* anybody editing the test -- which only works if there is one place that says
|
|
10
|
+
* which families those are.
|
|
11
|
+
*
|
|
12
|
+
* A map rather than a list, so the refusal for a family that is not installed
|
|
13
|
+
* can name the package that would fix it.
|
|
14
|
+
*/
|
|
15
|
+
export const OPTIONAL_COUNTERS = Object.freeze({
|
|
16
|
+
openai: '@trazum/tokenizer-openai',
|
|
17
|
+
});
|
|
18
|
+
/** Whether some optional package exists that counts this provider exactly. */
|
|
19
|
+
export const countableLocally = (provider) => provider !== null && provider !== undefined && provider in OPTIONAL_COUNTERS;
|
|
20
|
+
//# sourceMappingURL=optional-counters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional-counters.js","sourceRoot":"","sources":["../src/optional-counters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAqC,MAAM,CAAC,MAAM,CAAC;IAC/E,MAAM,EAAE,0BAA0B;CACnC,CAAC,CAAC;AAEH,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,QAAmC,EAAW,EAAE,CAC/E,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,IAAI,iBAAiB,CAAC"}
|
package/dist/style.d.ts
CHANGED
|
@@ -12,6 +12,17 @@
|
|
|
12
12
|
* stays plain: every `trazum ... | grep` in somebody's script is owed the
|
|
13
13
|
* bytes their script was written against.
|
|
14
14
|
*/
|
|
15
|
+
/**
|
|
16
|
+
* The variables the decision below reads.
|
|
17
|
+
*
|
|
18
|
+
* Exported for the same reason `LOCALE_ENV_VARS` is: the test suite has to
|
|
19
|
+
* neutralise the machine before asserting on output, and a list of what to
|
|
20
|
+
* neutralise kept in the test file drifts from the list that is read here. It
|
|
21
|
+
* drifted once already, in the other direction: `env.mjs` set `NO_COLOR` and
|
|
22
|
+
* left `FORCE_COLOR` alone, so a contributor whose shell exports `FORCE_COLOR`
|
|
23
|
+
* ran the whole CLI suite against painted output and twenty-nine tests failed.
|
|
24
|
+
*/
|
|
25
|
+
export declare const COLOUR_ENV_VARS: readonly ['FORCE_COLOR', 'NO_COLOR'];
|
|
15
26
|
export declare const useColor: boolean;
|
|
16
27
|
export declare const c: {
|
|
17
28
|
bold: (s: string) => string;
|
package/dist/style.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,YAAI,aAAa,EAAE,UAAU,CAAU,CAAC;AAGpE,eAAO,MAAM,QAAQ,SAAkF,CAAC;AAExG,eAAO,MAAM,CAAC;IACZ,IAAI,MAAM,MAAM;IAChB,GAAG,MAAM,MAAM;IACf,KAAK,MAAM,MAAM;IACjB,GAAG,MAAM,MAAM;IACf,MAAM,MAAM,MAAM;IAClB,IAAI,MAAM,MAAM;CACjB,CAAC;AAEF,gFAAgF;AAChF,eAAO,MAAM,YAAY,KAAK,CAAC;AAI/B;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,MAAM,CAGjF;AAED,MAAM,WAAW,WAAW;IAC1B,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,SAAO,GAAG,MAAM,EAAE,CAiBvF;AAED;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,MAAM,CAIrD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAe,GAAG,MAAM,CAGzE"}
|
package/dist/style.js
CHANGED
|
@@ -12,6 +12,17 @@
|
|
|
12
12
|
* stays plain: every `trazum ... | grep` in somebody's script is owed the
|
|
13
13
|
* bytes their script was written against.
|
|
14
14
|
*/
|
|
15
|
+
/**
|
|
16
|
+
* The variables the decision below reads.
|
|
17
|
+
*
|
|
18
|
+
* Exported for the same reason `LOCALE_ENV_VARS` is: the test suite has to
|
|
19
|
+
* neutralise the machine before asserting on output, and a list of what to
|
|
20
|
+
* neutralise kept in the test file drifts from the list that is read here. It
|
|
21
|
+
* drifted once already, in the other direction: `env.mjs` set `NO_COLOR` and
|
|
22
|
+
* left `FORCE_COLOR` alone, so a contributor whose shell exports `FORCE_COLOR`
|
|
23
|
+
* ran the whole CLI suite against painted output and twenty-nine tests failed.
|
|
24
|
+
*/
|
|
25
|
+
export const COLOUR_ENV_VARS = ['FORCE_COLOR', 'NO_COLOR'];
|
|
15
26
|
const forced = process.env.FORCE_COLOR === '1';
|
|
16
27
|
export const useColor = forced || (process.stdout.isTTY === true && process.env.NO_COLOR === undefined);
|
|
17
28
|
export const c = {
|
package/dist/style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,KAAK,GAAG,CAAC;AAC/C,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC;AAExG,MAAM,CAAC,MAAM,CAAC,GAAG;IACf,IAAI,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,GAAG,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,KAAK,EAAE,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,GAAG,EAAE,CAA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CAAC,KAAa,EAAE,KAAK,GAAG,EAAE;IAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC;IAC3C,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,KAAK,GAAG,YAAY;IAC/D,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACzD,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC;AAChE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trazum/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.85.0",
|
|
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",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"prepublishOnly": "npm run build && npm test"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@trazum/core": "1.
|
|
44
|
+
"@trazum/core": "1.85.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/node": "^26.2.0",
|
package/src/i18n/en.ts
CHANGED
|
@@ -1099,6 +1099,12 @@ ${bold('EXAMPLES')}
|
|
|
1099
1099
|
}. Counting it there would either be refused upstream or return a number for a different tokenizer, and this tool will not label that exact. Drop --exact-tokens for the estimate, which is honest about being one, or count with ${
|
|
1100
1100
|
provider === null ? "that model's" : provider + "'s"
|
|
1101
1101
|
} own tooling.`,
|
|
1102
|
+
exactTokensNeedsPackage: (model, packageName) =>
|
|
1103
|
+
`--exact-tokens can count ${model} exactly, offline and without a key, but that ` +
|
|
1104
|
+
`needs ${packageName}, which is not installed. It is a separate package because its ` +
|
|
1105
|
+
'rank tables are twenty-two megabytes and @trazum/core depends on nothing.\n' +
|
|
1106
|
+
` npm install ${packageName}\n` +
|
|
1107
|
+
'Or drop --exact-tokens for the estimate, which says how far out it is.',
|
|
1102
1108
|
checkNeedsMaxTokens: () => 'trazum check needs --max-tokens <n>.',
|
|
1103
1109
|
evalNeedsCases: () => 'trazum eval needs --cases <file>.',
|
|
1104
1110
|
unknownExportFormat: (received, allowed) =>
|
package/src/i18n/es.ts
CHANGED
|
@@ -1135,6 +1135,12 @@ ${bold('EJEMPLOS')}
|
|
|
1135
1135
|
}. Contarlo ahí sería rechazado arriba o devolvería un número de otro tokenizador, y esta herramienta no va a llamar exacto a eso. Quita --exact-tokens y quédate con la estimación (que es honesta sobre serlo) o cuenta con las herramientas de ${
|
|
1136
1136
|
provider === null ? 'ese modelo' : provider
|
|
1137
1137
|
}.`,
|
|
1138
|
+
exactTokensNeedsPackage: (model, packageName) =>
|
|
1139
|
+
`--exact-tokens puede contar ${model} de forma exacta, sin conexión y sin clave, pero ` +
|
|
1140
|
+
`necesita ${packageName}, que no está instalado. Es un paquete aparte porque sus tablas ` +
|
|
1141
|
+
'de rangos ocupan veintidós megabytes y @trazum/core no depende de nada.\n' +
|
|
1142
|
+
` npm install ${packageName}\n` +
|
|
1143
|
+
'O quita --exact-tokens y quédate con la estimación, que dice cuánto se desvía.',
|
|
1138
1144
|
checkNeedsMaxTokens: () => 'trazum check necesita --max-tokens <n>.',
|
|
1139
1145
|
evalNeedsCases: () => 'trazum eval necesita --cases <fichero>.',
|
|
1140
1146
|
unknownExportFormat: (received, allowed) =>
|
package/src/i18n/types.ts
CHANGED
|
@@ -125,6 +125,17 @@ export interface CliMessages {
|
|
|
125
125
|
* cannot count, and told as a different sentence.
|
|
126
126
|
*/
|
|
127
127
|
exactTokensWrongFamily(model: string, provider: string | null): string;
|
|
128
|
+
/**
|
|
129
|
+
* A family Trazum *can* count exactly, through an optional package that is
|
|
130
|
+
* not installed.
|
|
131
|
+
*
|
|
132
|
+
* A third sentence rather than a branch inside `exactTokensWrongFamily`,
|
|
133
|
+
* because it is a different fact: not *nobody here can count this* but
|
|
134
|
+
* *one `npm install` away*, and telling somebody to go and find another
|
|
135
|
+
* tool when the answer ships under the same scope is a worse refusal than
|
|
136
|
+
* the one it replaced.
|
|
137
|
+
*/
|
|
138
|
+
exactTokensNeedsPackage(model: string, packageName: string): string;
|
|
128
139
|
checkNeedsMaxTokens(): string;
|
|
129
140
|
evalNeedsCases(): string;
|
|
130
141
|
evalNoCases(path: string): string;
|
package/src/index.ts
CHANGED
|
@@ -153,6 +153,7 @@ import {
|
|
|
153
153
|
withExactTokenCounts,
|
|
154
154
|
} from '@trazum/core';
|
|
155
155
|
import { cacheDir, cacheStats, cachingProvider, clearCache } from './suggest-cache.js';
|
|
156
|
+
import { OPTIONAL_COUNTERS } from './optional-counters.js';
|
|
156
157
|
import { dayOf, formatGap, median, spanDays } from './time.js';
|
|
157
158
|
import type {
|
|
158
159
|
BucketedReport,
|
|
@@ -5508,6 +5509,80 @@ async function readInput(
|
|
|
5508
5509
|
return limit === null ? text : capInput(text, source, limit, t);
|
|
5509
5510
|
}
|
|
5510
5511
|
|
|
5512
|
+
/**
|
|
5513
|
+
* The part of an optional counter package this CLI actually uses.
|
|
5514
|
+
*
|
|
5515
|
+
* Declared here rather than imported as `typeof import('@trazum/tokenizer-openai')`,
|
|
5516
|
+
* and the reason is a build that failed in CI and was right to.
|
|
5517
|
+
*
|
|
5518
|
+
* A static type reference to an optional package is a **compile-time**
|
|
5519
|
+
* dependency on it: `tsc` resolves the module while type-checking, so the CLI
|
|
5520
|
+
* could not be built at all unless the optional package had been built first.
|
|
5521
|
+
* That is the opposite of optional, and it made a package somebody chooses to
|
|
5522
|
+
* install into one this repository could not compile without.
|
|
5523
|
+
*
|
|
5524
|
+
* So the contract is written out. It costs a few lines and it is the honest
|
|
5525
|
+
* shape: this is what the CLI relies on, and `optional-counter-contract.test.js`
|
|
5526
|
+
* asserts the real package still provides it, so the two cannot drift apart
|
|
5527
|
+
* without a red test rather than a wrong number.
|
|
5528
|
+
*/
|
|
5529
|
+
export interface OptionalCounterModule {
|
|
5530
|
+
openaiCounter(model: string): Promise<
|
|
5531
|
+
| { ok: true; count: (text: string) => number; encoding: string; model: string }
|
|
5532
|
+
| { ok: false; refusal: { reason: string; model: string; known: readonly string[] } }
|
|
5533
|
+
>;
|
|
5534
|
+
}
|
|
5535
|
+
|
|
5536
|
+
interface LocalCounter {
|
|
5537
|
+
count: (text: string) => number;
|
|
5538
|
+
/** A stable id for the counter, for `TokenProvenance`. */
|
|
5539
|
+
counter: string;
|
|
5540
|
+
/** What a person needs to know: which rank table produced the number. */
|
|
5541
|
+
detail: string;
|
|
5542
|
+
}
|
|
5543
|
+
|
|
5544
|
+
/**
|
|
5545
|
+
* A counter for this model from an optional package, or `null`.
|
|
5546
|
+
*
|
|
5547
|
+
* `null` covers three different situations on purpose -- the package is not
|
|
5548
|
+
* installed, it is installed and does not know this model, or the model belongs
|
|
5549
|
+
* to a family no optional package exists for. The caller does not branch on
|
|
5550
|
+
* which: it falls through to the remote path, which produces the right sentence
|
|
5551
|
+
* for each. What matters here is that **a missing package is not an error**.
|
|
5552
|
+
* `@trazum/core` depends on nothing and so does this CLI; a dynamic import that
|
|
5553
|
+
* throws `ERR_MODULE_NOT_FOUND` is the normal, expected state of a machine that
|
|
5554
|
+
* did not opt in, and turning it into a crash would make an optional dependency
|
|
5555
|
+
* a required one by accident.
|
|
5556
|
+
*/
|
|
5557
|
+
async function localCounterFor(model: string): Promise<LocalCounter | null> {
|
|
5558
|
+
let loaded: OptionalCounterModule;
|
|
5559
|
+
try {
|
|
5560
|
+
/*
|
|
5561
|
+
* The specifier is built rather than written literally, so `tsc` cannot
|
|
5562
|
+
* resolve it at compile time and try to type-check a package that may not
|
|
5563
|
+
* be installed. The cast is to the contract declared above, which is
|
|
5564
|
+
* checked against the real package by a test rather than assumed here.
|
|
5565
|
+
*/
|
|
5566
|
+
const specifier = ['@trazum', 'tokenizer-openai'].join('/');
|
|
5567
|
+
loaded = (await import(specifier)) as OptionalCounterModule;
|
|
5568
|
+
} catch {
|
|
5569
|
+
/*
|
|
5570
|
+
* Not installed. Deliberately swallowed and not logged: it is the default
|
|
5571
|
+
* state, and a CLI that warned about it on every run would be nagging
|
|
5572
|
+
* people to install twenty-two megabytes they have already decided against.
|
|
5573
|
+
*/
|
|
5574
|
+
return null;
|
|
5575
|
+
}
|
|
5576
|
+
|
|
5577
|
+
const result = await loaded.openaiCounter(model);
|
|
5578
|
+
if (!result.ok) return null;
|
|
5579
|
+
return {
|
|
5580
|
+
count: result.count,
|
|
5581
|
+
counter: 'openai-tiktoken',
|
|
5582
|
+
detail: result.encoding,
|
|
5583
|
+
};
|
|
5584
|
+
}
|
|
5585
|
+
|
|
5511
5586
|
async function commandOptimize(
|
|
5512
5587
|
args: Args,
|
|
5513
5588
|
config: TrazumConfig,
|
|
@@ -5809,6 +5884,28 @@ async function commandOptimize(
|
|
|
5809
5884
|
}
|
|
5810
5885
|
|
|
5811
5886
|
if (boolFlag(args, 'exact-tokens')) {
|
|
5887
|
+
/**
|
|
5888
|
+
* The local counter is tried first, and the order is deliberate.
|
|
5889
|
+
*
|
|
5890
|
+
* It costs nothing, sends nothing and needs no credential, so a family it
|
|
5891
|
+
* can count should never be sent looking for a key -- and never sent over
|
|
5892
|
+
* the network at all. A prompt counted here is read in this process and
|
|
5893
|
+
* goes nowhere, which is the distinction `TokenProvenance.where` carries.
|
|
5894
|
+
*/
|
|
5895
|
+
const local = await localCounterFor(result.usage.model);
|
|
5896
|
+
if (local !== null) {
|
|
5897
|
+
result = await withExactTokenCounts(
|
|
5898
|
+
result,
|
|
5899
|
+
async (text) => local.count(text),
|
|
5900
|
+
pricing,
|
|
5901
|
+
{
|
|
5902
|
+
counter: local.counter,
|
|
5903
|
+
model: result.usage.model,
|
|
5904
|
+
detail: local.detail,
|
|
5905
|
+
where: 'local',
|
|
5906
|
+
},
|
|
5907
|
+
);
|
|
5908
|
+
} else {
|
|
5812
5909
|
/**
|
|
5813
5910
|
* The family check comes **before** the key check, and the order is the
|
|
5814
5911
|
* point.
|
|
@@ -5825,8 +5922,16 @@ async function commandOptimize(
|
|
|
5825
5922
|
*/
|
|
5826
5923
|
const priced = pricing.byId.get(result.usage.model);
|
|
5827
5924
|
if (!bandGoverns(priced?.provider)) {
|
|
5925
|
+
/*
|
|
5926
|
+
* A family with an optional counter gets a different sentence from one
|
|
5927
|
+
* with none. "Go and find somebody else's tooling" is the wrong refusal
|
|
5928
|
+
* when the answer ships under this scope and is one install away.
|
|
5929
|
+
*/
|
|
5930
|
+
const offered = OPTIONAL_COUNTERS[priced?.provider ?? ''];
|
|
5828
5931
|
throw new Error(
|
|
5829
|
-
|
|
5932
|
+
offered === undefined
|
|
5933
|
+
? t.errors.exactTokensWrongFamily(result.usage.model, priced?.provider ?? null)
|
|
5934
|
+
: t.errors.exactTokensNeedsPackage(result.usage.model, offered),
|
|
5830
5935
|
);
|
|
5831
5936
|
}
|
|
5832
5937
|
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
@@ -5837,7 +5942,14 @@ async function commandOptimize(
|
|
|
5837
5942
|
result,
|
|
5838
5943
|
countTokensAnthropic({ apiKey, model: result.usage.model }),
|
|
5839
5944
|
pricing,
|
|
5945
|
+
{
|
|
5946
|
+
counter: 'anthropic-count-tokens',
|
|
5947
|
+
model: result.usage.model,
|
|
5948
|
+
detail: 'api.anthropic.com/v1/messages/count_tokens',
|
|
5949
|
+
where: 'remote',
|
|
5950
|
+
},
|
|
5840
5951
|
);
|
|
5952
|
+
}
|
|
5841
5953
|
}
|
|
5842
5954
|
|
|
5843
5955
|
const outPath = stringFlag(args, 'out');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Providers whose tokens an optional package can count exactly, by provider id.
|
|
3
|
+
*
|
|
4
|
+
* Its own module rather than a constant inside the command, because two
|
|
5
|
+
* different readers need it: the CLI, to decide whether to try loading one, and
|
|
6
|
+
* `band-family.test.js`, which walks every priced provider and asserts that the
|
|
7
|
+
* ones this tool cannot count are refused by name. That suite's whole design is
|
|
8
|
+
* that a family leaves its assertions by *becoming countable* rather than by
|
|
9
|
+
* anybody editing the test -- which only works if there is one place that says
|
|
10
|
+
* which families those are.
|
|
11
|
+
*
|
|
12
|
+
* A map rather than a list, so the refusal for a family that is not installed
|
|
13
|
+
* can name the package that would fix it.
|
|
14
|
+
*/
|
|
15
|
+
export const OPTIONAL_COUNTERS: Readonly<Record<string, string>> = Object.freeze({
|
|
16
|
+
openai: '@trazum/tokenizer-openai',
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/** Whether some optional package exists that counts this provider exactly. */
|
|
20
|
+
export const countableLocally = (provider: string | null | undefined): boolean =>
|
|
21
|
+
provider !== null && provider !== undefined && provider in OPTIONAL_COUNTERS;
|
package/src/style.ts
CHANGED
|
@@ -13,6 +13,18 @@
|
|
|
13
13
|
* bytes their script was written against.
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* The variables the decision below reads.
|
|
18
|
+
*
|
|
19
|
+
* Exported for the same reason `LOCALE_ENV_VARS` is: the test suite has to
|
|
20
|
+
* neutralise the machine before asserting on output, and a list of what to
|
|
21
|
+
* neutralise kept in the test file drifts from the list that is read here. It
|
|
22
|
+
* drifted once already, in the other direction: `env.mjs` set `NO_COLOR` and
|
|
23
|
+
* left `FORCE_COLOR` alone, so a contributor whose shell exports `FORCE_COLOR`
|
|
24
|
+
* ran the whole CLI suite against painted output and twenty-nine tests failed.
|
|
25
|
+
*/
|
|
26
|
+
export const COLOUR_ENV_VARS = ['FORCE_COLOR', 'NO_COLOR'] as const;
|
|
27
|
+
|
|
16
28
|
const forced = process.env.FORCE_COLOR === '1';
|
|
17
29
|
export const useColor = forced || (process.stdout.isTTY === true && process.env.NO_COLOR === undefined);
|
|
18
30
|
|