@codemieai/code 0.15.3 → 0.15.4
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/agents/core/AgentCLI.d.ts.map +1 -1
- package/dist/agents/core/AgentCLI.js +9 -0
- package/dist/agents/core/AgentCLI.js.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.d.ts.map +1 -1
- package/dist/agents/core/BaseAgentAdapter.js +34 -9
- package/dist/agents/core/BaseAgentAdapter.js.map +1 -1
- package/dist/agents/plugins/claude/claude.models.d.ts +58 -0
- package/dist/agents/plugins/claude/claude.models.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.models.js +196 -10
- package/dist/agents/plugins/claude/claude.models.js.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/claude/claude.plugin.js +147 -45
- package/dist/agents/plugins/claude/claude.plugin.js.map +1 -1
- package/dist/agents/plugins/claude/plugin/statusline.bundle.mjs +729 -0
- package/dist/agents/plugins/claude/statusline-installer.d.ts +1 -1
- package/dist/agents/plugins/claude/statusline-installer.d.ts.map +1 -1
- package/dist/agents/plugins/claude/statusline-installer.js +41 -3
- package/dist/agents/plugins/claude/statusline-installer.js.map +1 -1
- package/dist/agents/plugins/codex/codex-models.d.ts.map +1 -1
- package/dist/agents/plugins/codex/codex-models.js +109 -8
- package/dist/agents/plugins/codex/codex-models.js.map +1 -1
- package/dist/agents/plugins/codex/codex.correlation.d.ts +39 -0
- package/dist/agents/plugins/codex/codex.correlation.d.ts.map +1 -0
- package/dist/agents/plugins/codex/codex.correlation.js +150 -0
- package/dist/agents/plugins/codex/codex.correlation.js.map +1 -0
- package/dist/agents/plugins/codex/codex.plugin.d.ts.map +1 -1
- package/dist/agents/plugins/codex/codex.plugin.js +8 -40
- package/dist/agents/plugins/codex/codex.plugin.js.map +1 -1
- package/dist/agents/plugins/kimi/kimi.env-model.d.ts +27 -0
- package/dist/agents/plugins/kimi/kimi.env-model.d.ts.map +1 -0
- package/dist/agents/plugins/kimi/kimi.env-model.js +52 -0
- package/dist/agents/plugins/kimi/kimi.env-model.js.map +1 -0
- package/dist/agents/plugins/kimi/kimi.session.d.ts +6 -0
- package/dist/agents/plugins/kimi/kimi.session.d.ts.map +1 -1
- package/dist/agents/plugins/kimi/kimi.session.js +24 -2
- package/dist/agents/plugins/kimi/kimi.session.js.map +1 -1
- package/dist/agents/plugins/opencode/opencode-dynamic-models.js +1 -1
- package/dist/agents/plugins/opencode/opencode-dynamic-models.js.map +1 -1
- package/dist/cli/commands/analytics/cost/cost-enricher.d.ts +19 -2
- package/dist/cli/commands/analytics/cost/cost-enricher.d.ts.map +1 -1
- package/dist/cli/commands/analytics/cost/cost-enricher.js +171 -14
- package/dist/cli/commands/analytics/cost/cost-enricher.js.map +1 -1
- package/dist/cli/commands/analytics/cost/local-models.d.ts +15 -0
- package/dist/cli/commands/analytics/cost/local-models.d.ts.map +1 -0
- package/dist/cli/commands/analytics/cost/local-models.js +21 -0
- package/dist/cli/commands/analytics/cost/local-models.js.map +1 -0
- package/dist/cli/commands/analytics/cost/types.d.ts +60 -0
- package/dist/cli/commands/analytics/cost/types.d.ts.map +1 -1
- package/dist/cli/commands/analytics/cost/types.js.map +1 -1
- package/dist/cli/commands/analytics/cost/usage-readers.d.ts +25 -2
- package/dist/cli/commands/analytics/cost/usage-readers.d.ts.map +1 -1
- package/dist/cli/commands/analytics/cost/usage-readers.js +61 -3
- package/dist/cli/commands/analytics/cost/usage-readers.js.map +1 -1
- package/dist/cli/commands/analytics/formatter.d.ts +11 -0
- package/dist/cli/commands/analytics/formatter.d.ts.map +1 -1
- package/dist/cli/commands/analytics/formatter.js +28 -0
- package/dist/cli/commands/analytics/formatter.js.map +1 -1
- package/dist/cli/commands/analytics/index.d.ts.map +1 -1
- package/dist/cli/commands/analytics/index.js +70 -73
- package/dist/cli/commands/analytics/index.js.map +1 -1
- package/dist/cli/commands/analytics/otel-loader.d.ts.map +1 -1
- package/dist/cli/commands/analytics/otel-loader.js +60 -14
- package/dist/cli/commands/analytics/otel-loader.js.map +1 -1
- package/dist/cli/commands/analytics/otel-pricing.d.ts +38 -0
- package/dist/cli/commands/analytics/otel-pricing.d.ts.map +1 -0
- package/dist/cli/commands/analytics/otel-pricing.js +33 -0
- package/dist/cli/commands/analytics/otel-pricing.js.map +1 -0
- package/dist/cli/commands/analytics/report/client/app.js +279 -18
- package/dist/cli/commands/analytics/report/output-target.d.ts +22 -0
- package/dist/cli/commands/analytics/report/output-target.d.ts.map +1 -0
- package/dist/cli/commands/analytics/report/output-target.js +56 -0
- package/dist/cli/commands/analytics/report/output-target.js.map +1 -0
- package/dist/cli/commands/analytics/report/payload-builder.d.ts.map +1 -1
- package/dist/cli/commands/analytics/report/payload-builder.js +6 -0
- package/dist/cli/commands/analytics/report/payload-builder.js.map +1 -1
- package/dist/cli/commands/analytics/report/report-generator.d.ts +1 -1
- package/dist/cli/commands/analytics/report/report-generator.js +1 -1
- package/dist/cli/commands/analytics/report/session-report.d.ts +1 -3
- package/dist/cli/commands/analytics/report/session-report.d.ts.map +1 -1
- package/dist/cli/commands/analytics/report/session-report.js +1 -3
- package/dist/cli/commands/analytics/report/session-report.js.map +1 -1
- package/dist/cli/commands/analytics/report/template.html +6 -6
- package/dist/cli/commands/analytics/report/types.d.ts +17 -1
- package/dist/cli/commands/analytics/report/types.d.ts.map +1 -1
- package/dist/cli/commands/analytics/sources/sessions-source.d.ts.map +1 -1
- package/dist/cli/commands/analytics/sources/sessions-source.js +9 -11
- package/dist/cli/commands/analytics/sources/sessions-source.js.map +1 -1
- package/dist/cli/commands/analytics/sources/types.d.ts +0 -2
- package/dist/cli/commands/analytics/sources/types.d.ts.map +1 -1
- package/dist/cli/commands/analytics/types.d.ts +8 -8
- package/dist/cli/commands/analytics/types.d.ts.map +1 -1
- package/dist/cli/commands/models.d.ts.map +1 -1
- package/dist/cli/commands/models.js +16 -3
- package/dist/cli/commands/models.js.map +1 -1
- package/dist/cli/commands/proxy/connect-orchestrator.js +1 -1
- package/dist/cli/commands/proxy/connect-orchestrator.js.map +1 -1
- package/dist/cli/commands/proxy/connectors/tenant-catalog.d.ts +16 -4
- package/dist/cli/commands/proxy/connectors/tenant-catalog.d.ts.map +1 -1
- package/dist/cli/commands/proxy/connectors/tenant-catalog.js +42 -14
- package/dist/cli/commands/proxy/connectors/tenant-catalog.js.map +1 -1
- package/dist/cli/commands/proxy/connectors/vscode-models.d.ts +18 -0
- package/dist/cli/commands/proxy/connectors/vscode-models.d.ts.map +1 -1
- package/dist/cli/commands/proxy/connectors/vscode-models.js +58 -0
- package/dist/cli/commands/proxy/connectors/vscode-models.js.map +1 -1
- package/dist/cli/commands/proxy/connectors/vscode.d.ts +2 -2
- package/dist/cli/commands/proxy/connectors/vscode.d.ts.map +1 -1
- package/dist/cli/commands/proxy/connectors/vscode.js +27 -38
- package/dist/cli/commands/proxy/connectors/vscode.js.map +1 -1
- package/dist/providers/core/codemie-auth-helpers.d.ts.map +1 -1
- package/dist/providers/core/codemie-auth-helpers.js +6 -1
- package/dist/providers/core/codemie-auth-helpers.js.map +1 -1
- package/dist/providers/core/default-agent-hooks.d.ts.map +1 -1
- package/dist/providers/core/default-agent-hooks.js +9 -0
- package/dist/providers/core/default-agent-hooks.js.map +1 -1
- package/dist/providers/plugins/bedrock/bedrock.template.d.ts.map +1 -1
- package/dist/providers/plugins/bedrock/bedrock.template.js +5 -31
- package/dist/providers/plugins/bedrock/bedrock.template.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/background-request-normalizer.plugin.d.ts +44 -0
- package/dist/providers/plugins/sso/proxy/plugins/background-request-normalizer.plugin.d.ts.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/background-request-normalizer.plugin.js +106 -0
- package/dist/providers/plugins/sso/proxy/plugins/background-request-normalizer.plugin.js.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts +3 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.d.ts.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.js +5 -1
- package/dist/providers/plugins/sso/proxy/plugins/index.js.map +1 -1
- package/dist/providers/plugins/sso/proxy/plugins/routing-header-injector.plugin.d.ts +67 -0
- package/dist/providers/plugins/sso/proxy/plugins/routing-header-injector.plugin.d.ts.map +1 -0
- package/dist/providers/plugins/sso/proxy/plugins/routing-header-injector.plugin.js +203 -0
- package/dist/providers/plugins/sso/proxy/plugins/routing-header-injector.plugin.js.map +1 -0
- package/dist/providers/plugins/sso/sso.http-client.d.ts +95 -0
- package/dist/providers/plugins/sso/sso.http-client.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.http-client.js +79 -0
- package/dist/providers/plugins/sso/sso.http-client.js.map +1 -1
- package/dist/providers/plugins/sso/sso.models.d.ts +7 -0
- package/dist/providers/plugins/sso/sso.models.d.ts.map +1 -1
- package/dist/providers/plugins/sso/sso.models.js +22 -14
- package/dist/providers/plugins/sso/sso.models.js.map +1 -1
- package/dist/utils/bedrock-pricing.mjs +111 -0
- package/dist/utils/cli-updater.d.ts.map +1 -1
- package/dist/utils/cli-updater.js +32 -7
- package/dist/utils/cli-updater.js.map +1 -1
- package/dist/utils/credential-crypto.d.ts +51 -0
- package/dist/utils/credential-crypto.d.ts.map +1 -0
- package/dist/utils/credential-crypto.js +96 -0
- package/dist/utils/credential-crypto.js.map +1 -0
- package/dist/utils/model-normalizer.d.ts +6 -0
- package/dist/utils/model-normalizer.d.ts.map +1 -1
- package/dist/utils/model-normalizer.js +37 -19
- package/dist/utils/model-normalizer.js.map +1 -1
- package/dist/utils/price-resolution.d.ts +42 -0
- package/dist/utils/price-resolution.d.ts.map +1 -0
- package/dist/utils/price-resolution.js +112 -0
- package/dist/utils/price-resolution.js.map +1 -0
- package/dist/utils/pricing.d.ts +65 -6
- package/dist/utils/pricing.d.ts.map +1 -1
- package/dist/utils/pricing.js +91 -117
- package/dist/utils/pricing.js.map +1 -1
- package/dist/utils/pricing.json +201 -20
- package/dist/utils/routing-headers.mjs +104 -0
- package/dist/utils/security.d.ts +0 -32
- package/dist/utils/security.d.ts.map +1 -1
- package/dist/utils/security.js +20 -102
- package/dist/utils/security.js.map +1 -1
- package/package.json +4 -2
- package/scripts/bundle-statusline.mjs +37 -0
- package/scripts/copy-plugins.js +19 -2
- package/src/utils/tips.json +9 -9
- package/dist/agents/plugins/claude/plugin/__tests__/statusline.test.ts +0 -323
- package/dist/agents/plugins/claude/plugin/statusline.mjs +0 -282
- package/dist/cli/commands/analytics/exporter.d.ts +0 -20
- package/dist/cli/commands/analytics/exporter.d.ts.map +0 -1
- package/dist/cli/commands/analytics/exporter.js +0 -91
- package/dist/cli/commands/analytics/exporter.js.map +0 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-id → pricing-table-key resolution, shared by every consumer that prices a model id:
|
|
3
|
+
* src/utils/pricing.ts (the analytics report's resolvePrice()) and the standalone Claude
|
|
4
|
+
* statusline (src/agents/plugins/claude/plugin/statusline.ts, bundled into one self-contained file
|
|
5
|
+
* by scripts/bundle-statusline.mjs). Keeping one copy is what stops the live statusline cost and
|
|
6
|
+
* the analytics report from disagreeing on the same transcript.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately free of I/O and of any import beyond model-normalizer.ts (itself dependency-free),
|
|
9
|
+
* so the statusline bundle stays small and never drags in fs/config/keytar-bearing modules. It
|
|
10
|
+
* knows nothing about the shape of a price row — callers pass a key lookup over their own table.
|
|
11
|
+
*/
|
|
12
|
+
/** How an observed model id was matched to a table key. */
|
|
13
|
+
export type PriceMatch = 'exact' | 'snapshot' | 'reordered';
|
|
14
|
+
/** A table key an observed id resolved to, the value found under it, and how it matched. */
|
|
15
|
+
export interface PriceKeyHit<T> {
|
|
16
|
+
key: string;
|
|
17
|
+
match: PriceMatch;
|
|
18
|
+
value: T;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The table-key form of a raw pricing-data key: lowercased, dots turned to dashes, so `GLM-4.7`
|
|
22
|
+
* and `glm-4-7` land on the same entry. Both sides of a lookup must be folded the same way —
|
|
23
|
+
* observed ids go through {@link canonicalizeModelId}, which ends in this same folding.
|
|
24
|
+
*/
|
|
25
|
+
export declare function priceTableKey(rawKey: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Canonicalizes an observed model id into the form used as a pricing-table key. Extends
|
|
28
|
+
* {@link normalizeModelName} (which strips Bedrock/Kimi/vendor-path prefixes) with:
|
|
29
|
+
* 1. Lowercasing, dots turned to dashes, and `@` turned to `-` (so Vertex's `claude-x@20260205`
|
|
30
|
+
* folds to the same shape as a dated id).
|
|
31
|
+
* 2. Stripping a trailing `-vertex` suffix.
|
|
32
|
+
* Used by the pricing resolver, the statusline and cost reconciliation, so every consumer treats
|
|
33
|
+
* the same observed id the same way.
|
|
34
|
+
*/
|
|
35
|
+
export declare function canonicalizeModelId(model: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Resolves an observed model id against a pricing table through `lookup`, trying the keys of
|
|
38
|
+
* {@link priceKeyCandidates} in order and returning the first hit. Returns null when nothing
|
|
39
|
+
* matches — the model is unpriced, never a guessed price.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolvePriceKey<T>(model: string, lookup: (key: string) => T | undefined): PriceKeyHit<T> | null;
|
|
42
|
+
//# sourceMappingURL=price-resolution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price-resolution.d.ts","sourceRoot":"","sources":["../../src/utils/price-resolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAsBH,2DAA2D;AAC3D,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,UAAU,GAAG,WAAW,CAAC;AAE5D,4FAA4F;AAC5F,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,UAAU,CAAC;IAClB,KAAK,EAAE,CAAC,CAAC;CACV;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIzD;AAoDD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAQ/G"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-id → pricing-table-key resolution, shared by every consumer that prices a model id:
|
|
3
|
+
* src/utils/pricing.ts (the analytics report's resolvePrice()) and the standalone Claude
|
|
4
|
+
* statusline (src/agents/plugins/claude/plugin/statusline.ts, bundled into one self-contained file
|
|
5
|
+
* by scripts/bundle-statusline.mjs). Keeping one copy is what stops the live statusline cost and
|
|
6
|
+
* the analytics report from disagreeing on the same transcript.
|
|
7
|
+
*
|
|
8
|
+
* Deliberately free of I/O and of any import beyond model-normalizer.ts (itself dependency-free),
|
|
9
|
+
* so the statusline bundle stays small and never drags in fs/config/keytar-bearing modules. It
|
|
10
|
+
* knows nothing about the shape of a price row — callers pass a key lookup over their own table.
|
|
11
|
+
*/
|
|
12
|
+
import { normalizeModelName } from './model-normalizer.js';
|
|
13
|
+
/**
|
|
14
|
+
* A trailing snapshot/version suffix stripped once during lookup (never during canonicalization):
|
|
15
|
+
* an 8-digit date (`-20260205`), a dashed date (`-2026-02-05`), or the `-latest`/`-preview` tags.
|
|
16
|
+
* Applied at most once, so a key that is itself dated (`gpt-4o-2024-05-13`) is tried as an exact
|
|
17
|
+
* match first and never has a second suffix stripped from it.
|
|
18
|
+
*/
|
|
19
|
+
const SNAPSHOT_SUFFIX_PATTERN = /-(?:\d{8}|\d{4}-\d{2}-\d{2}|latest|preview)$/;
|
|
20
|
+
/**
|
|
21
|
+
* Matches a Claude id given in version-first order — `claude-<ver>-<family>[<rest>]`, where `ver`
|
|
22
|
+
* is one or more dash-separated numeric segments and `family` is `opus`/`sonnet`/`haiku` — so it
|
|
23
|
+
* can be reordered to the family-first form (`claude-<family>-<ver>[<rest>]`) the pricing table
|
|
24
|
+
* keys newer Claude generations under (e.g. `claude-sonnet-4-5`, `claude-opus-4-8`; see
|
|
25
|
+
* pricing.json's own rows). Never applied to a key that is already family-first, since that
|
|
26
|
+
* doesn't match this pattern in the first place.
|
|
27
|
+
*/
|
|
28
|
+
const CLAUDE_VERSION_FIRST_PATTERN = /^claude-(\d+(?:-\d+)*)-(opus|sonnet|haiku)(-.+)?$/;
|
|
29
|
+
/**
|
|
30
|
+
* The table-key form of a raw pricing-data key: lowercased, dots turned to dashes, so `GLM-4.7`
|
|
31
|
+
* and `glm-4-7` land on the same entry. Both sides of a lookup must be folded the same way —
|
|
32
|
+
* observed ids go through {@link canonicalizeModelId}, which ends in this same folding.
|
|
33
|
+
*/
|
|
34
|
+
export function priceTableKey(rawKey) {
|
|
35
|
+
return rawKey.toLowerCase().replace(/\./g, '-');
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Canonicalizes an observed model id into the form used as a pricing-table key. Extends
|
|
39
|
+
* {@link normalizeModelName} (which strips Bedrock/Kimi/vendor-path prefixes) with:
|
|
40
|
+
* 1. Lowercasing, dots turned to dashes, and `@` turned to `-` (so Vertex's `claude-x@20260205`
|
|
41
|
+
* folds to the same shape as a dated id).
|
|
42
|
+
* 2. Stripping a trailing `-vertex` suffix.
|
|
43
|
+
* Used by the pricing resolver, the statusline and cost reconciliation, so every consumer treats
|
|
44
|
+
* the same observed id the same way.
|
|
45
|
+
*/
|
|
46
|
+
export function canonicalizeModelId(model) {
|
|
47
|
+
return priceTableKey(normalizeModelName(model))
|
|
48
|
+
.replace(/@/g, '-')
|
|
49
|
+
.replace(/-vertex$/, '');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reorders a version-first Claude id (`claude-4-5-sonnet`) to the family-first form
|
|
53
|
+
* (`claude-sonnet-4-5`) the table keys such rows under, preserving any trailing suffix (a
|
|
54
|
+
* snapshot date, `-latest`, ...). Returns null when `id` isn't in that shape.
|
|
55
|
+
*/
|
|
56
|
+
function reorderClaudeVersionFamily(id) {
|
|
57
|
+
const match = id.match(CLAUDE_VERSION_FIRST_PATTERN);
|
|
58
|
+
if (!match) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const [, version, family, rest = ''] = match;
|
|
62
|
+
return `claude-${family}-${version}${rest}`;
|
|
63
|
+
}
|
|
64
|
+
/** `key` with one trailing snapshot suffix stripped, or null when it carries none. */
|
|
65
|
+
function withoutSnapshot(key) {
|
|
66
|
+
const stripped = key.replace(SNAPSHOT_SUFFIX_PATTERN, '');
|
|
67
|
+
return stripped === key ? null : stripped;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The ordered table keys tried for an observed id, against its {@link canonicalizeModelId} form:
|
|
71
|
+
* 1. Exact match — keeps distinct dated rows (e.g. `gpt-4o-2024-05-13`) authoritative.
|
|
72
|
+
* 2. Exact match after stripping one trailing snapshot suffix — e.g. `claude-opus-4-6-20260205`
|
|
73
|
+
* resolves to the `claude-opus-4-6` row.
|
|
74
|
+
* 3. A version-first Claude id (`claude-4-5-sonnet`) reordered to the table's family-first form
|
|
75
|
+
* (`claude-sonnet-4-5`), tried exact and then with a trailing snapshot suffix stripped — only
|
|
76
|
+
* once steps 1-2 have already failed on the as-is id. That ordering is what keeps every
|
|
77
|
+
* pre-existing version-first key (`claude-3-5-sonnet`, `claude-3-7-sonnet-20250219`, ...)
|
|
78
|
+
* resolving unchanged: those rows match as-is at step 1 and this fallback is never reached.
|
|
79
|
+
* There is no segment/family match and no same-tier fallback.
|
|
80
|
+
*/
|
|
81
|
+
function priceKeyCandidates(model) {
|
|
82
|
+
const canonical = canonicalizeModelId(model);
|
|
83
|
+
const candidates = [{ key: canonical, match: 'exact' }];
|
|
84
|
+
const snapshot = withoutSnapshot(canonical);
|
|
85
|
+
if (snapshot) {
|
|
86
|
+
candidates.push({ key: snapshot, match: 'snapshot' });
|
|
87
|
+
}
|
|
88
|
+
const reordered = reorderClaudeVersionFamily(canonical);
|
|
89
|
+
if (reordered) {
|
|
90
|
+
candidates.push({ key: reordered, match: 'reordered' });
|
|
91
|
+
const reorderedSnapshot = withoutSnapshot(reordered);
|
|
92
|
+
if (reorderedSnapshot) {
|
|
93
|
+
candidates.push({ key: reorderedSnapshot, match: 'reordered' });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return candidates;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Resolves an observed model id against a pricing table through `lookup`, trying the keys of
|
|
100
|
+
* {@link priceKeyCandidates} in order and returning the first hit. Returns null when nothing
|
|
101
|
+
* matches — the model is unpriced, never a guessed price.
|
|
102
|
+
*/
|
|
103
|
+
export function resolvePriceKey(model, lookup) {
|
|
104
|
+
for (const { key, match } of priceKeyCandidates(model)) {
|
|
105
|
+
const value = key ? lookup(key) : undefined;
|
|
106
|
+
if (value !== undefined) {
|
|
107
|
+
return { key, match, value };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=price-resolution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price-resolution.js","sourceRoot":"","sources":["../../src/utils/price-resolution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,uBAAuB,GAAG,8CAA8C,CAAC;AAE/E;;;;;;;GAOG;AACH,MAAM,4BAA4B,GAAG,mDAAmD,CAAC;AAYzF;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE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ACD,MAAM,SAAS,GAAG,0BAA0B,CAAC,SAAS,CAAC,CAAC;IACxD,IAAI,SAAS,EAAE,CAAC;QACd,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;QACxD,MAAM,iBAAiB,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QACrD,IAAI,iBAAiB,EAAE,CAAC;YACtB,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAC;QAClE,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAI,KAAa,EAAE,MAAsC;IACtF,KAAK,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;QACvD,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;QAC/B,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/utils/pricing.d.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* re-copy that file. Prices are USD per 1,000,000 tokens. The source uses
|
|
6
6
|
* `cacheWrite`; we expose it as `cacheCreation` to match Claude's terminology.
|
|
7
7
|
*/
|
|
8
|
+
import { type PriceMatch } from './price-resolution.js';
|
|
9
|
+
export { canonicalizeModelId } from './price-resolution.js';
|
|
8
10
|
/** USD per 1,000,000 tokens. */
|
|
9
11
|
export interface ModelPrice {
|
|
10
12
|
input: number;
|
|
@@ -12,14 +14,71 @@ export interface ModelPrice {
|
|
|
12
14
|
cacheRead: number;
|
|
13
15
|
cacheCreation: number;
|
|
14
16
|
cacheWrite1h?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Amazon Bedrock's premium for a regional/multi-region endpoint over this model's global one
|
|
19
|
+
* — present only on rows where Anthropic documents the two-endpoint-type Bedrock pricing
|
|
20
|
+
* structure (Sonnet 4.5+, Haiku 4.5+, Opus 4.5+ and their dated snapshots). Absent (no premium)
|
|
21
|
+
* on every older row, since Anthropic does not document this structure applying there. See
|
|
22
|
+
* isBedrockRegionalPremium()'s own doc comment (bedrock-pricing.mjs) for the source.
|
|
23
|
+
*/
|
|
24
|
+
bedrockRegionalMultiplier?: number;
|
|
25
|
+
/**
|
|
26
|
+
* True when this row is not a directly published rate but an estimate (e.g. a tier-price
|
|
27
|
+
* carried forward for a model generation with no confirmed pricing yet). Every row's
|
|
28
|
+
* provenance should be cited in `pricing.json`'s `_meta.sources`/`note`; this flag is what
|
|
29
|
+
* callers use to surface "estimated" alongside the resolved price rather than presenting it
|
|
30
|
+
* as authoritative.
|
|
31
|
+
*/
|
|
32
|
+
estimated?: boolean;
|
|
15
33
|
}
|
|
34
|
+
export interface RawPrice {
|
|
35
|
+
input?: number;
|
|
36
|
+
output?: number;
|
|
37
|
+
cacheRead?: number;
|
|
38
|
+
cacheWrite?: number;
|
|
39
|
+
cacheWrite1h?: number;
|
|
40
|
+
bedrockRegionalMultiplier?: number;
|
|
41
|
+
estimated?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Builds the rate card from a bag of raw rows (a parsed `pricing.json`, an injected fixture for
|
|
45
|
+
* tests, or any merge of the two): every key is lowercased and dots are turned to dashes, so
|
|
46
|
+
* `GLM-4.7` and `glm-4-7` land on the same table entry. When two distinct raw keys normalize to
|
|
47
|
+
* the same table key, they must carry identical prices — that is the only way the pricing data
|
|
48
|
+
* itself can declare two spellings of the same model (e.g. `gemini-3.7-flash` / `gemini-3-7-flash`)
|
|
49
|
+
* — otherwise the table is ambiguous and this throws rather than silently picking one.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildPriceTable(rows: Record<string, RawPrice>): Record<string, ModelPrice>;
|
|
52
|
+
/**
|
|
53
|
+
* The fully built rate card: the vendored table with {@link CODEMIE_PRICES} merged over it and every
|
|
54
|
+
* key lowercased. Exported so consumers that cannot import this module — the standalone Claude
|
|
55
|
+
* statusline, which runs as a detached `node <path>` process — can be handed the same rates rather
|
|
56
|
+
* than a copy of the raw `pricing.json`, which carries none of the CodeMie-only rows.
|
|
57
|
+
*/
|
|
58
|
+
export declare function priceTable(): Record<string, ModelPrice>;
|
|
59
|
+
/** How {@link resolvePrice} matched an observed model id to a table row. */
|
|
60
|
+
export interface PriceResolution {
|
|
61
|
+
price: ModelPrice;
|
|
62
|
+
key: string;
|
|
63
|
+
match: PriceMatch;
|
|
64
|
+
estimated: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Resolves pricing for a model, reporting how it was matched. Returns null when no entry
|
|
68
|
+
* matches (the caller marks the model `unpriced` — never a silent $0, and never a guessed
|
|
69
|
+
* family/tier price). The lookup order (exact, then one snapshot suffix stripped, then a
|
|
70
|
+
* version-first Claude id reordered to family-first) lives in {@link resolvePriceKey}, shared
|
|
71
|
+
* with the Claude statusline so the two can never price the same id differently.
|
|
72
|
+
*
|
|
73
|
+
* `model` is also checked, in its original unnormalized form, for a Bedrock region qualifier
|
|
74
|
+
* (see {@link applyBedrockRegionalPremium}) — pass the raw backend id straight through rather
|
|
75
|
+
* than pre-normalizing it, or the premium this exists to detect is invisible by the time it gets
|
|
76
|
+
* here.
|
|
77
|
+
*/
|
|
78
|
+
export declare function resolvePrice(model: string): PriceResolution | null;
|
|
16
79
|
/**
|
|
17
|
-
* Look up pricing for a model. Returns null when no entry matches
|
|
18
|
-
*
|
|
19
|
-
* 1. Exact (normalized) match — authoritative.
|
|
20
|
-
* 2. Longest key aligned to a segment boundary — a deliberate family fallback, logged as inexact.
|
|
21
|
-
* 3. Latest same-tier Claude price — for a model newer than every table entry, logged as inexact.
|
|
22
|
-
* Dots are folded to dashes first because the table keys use dashes (e.g. `gpt-4-1`, not `gpt-4.1`).
|
|
80
|
+
* Look up pricing for a model. Returns null when no entry matches. Thin wrapper over
|
|
81
|
+
* {@link resolvePrice} for callers that only need the price, not its provenance.
|
|
23
82
|
*/
|
|
24
83
|
export declare function lookupPrice(model: string): ModelPrice | null;
|
|
25
84
|
//# sourceMappingURL=pricing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../src/utils/pricing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"pricing.d.ts","sourceRoot":"","sources":["../../src/utils/pricing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAOH,OAAO,EAAkC,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExF,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,gCAAgC;AAChC,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;;;OAMG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA4CD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAiB1F;AAWD;;;;;GAKG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAEvD;AAED,4EAA4E;AAC5E,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,UAAU,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,UAAU,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAYlE;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAE5D"}
|
package/dist/utils/pricing.js
CHANGED
|
@@ -8,142 +8,116 @@
|
|
|
8
8
|
import { readFileSync } from 'node:fs';
|
|
9
9
|
import { join } from 'node:path';
|
|
10
10
|
import { getDirname } from './paths.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { applyBedrockRegionalPremium } from './bedrock-pricing.mjs';
|
|
12
|
+
import { ConfigurationError } from './errors.js';
|
|
13
|
+
import { priceTableKey, resolvePriceKey } from './price-resolution.js';
|
|
14
|
+
export { canonicalizeModelId } from './price-resolution.js';
|
|
15
|
+
/**
|
|
16
|
+
* CodeMie-specific ids the vendored table will never carry. Merged over the vendored rows
|
|
17
|
+
* in {@link table}, so re-copying `pricing.json` from agentlytics does not silently drop them.
|
|
18
|
+
*
|
|
19
|
+
* `claude-smart-router` is a Switchyard routing alias, not a generation model. The alias bills
|
|
20
|
+
* only the Haiku classifier hop that picks a target; the generation itself is billed against the
|
|
21
|
+
* model the router dispatched to, which arrives in the response body's own `model` field and is
|
|
22
|
+
* priced from its own row. Haiku rates therefore price what this id actually costs — without a
|
|
23
|
+
* row at all, `lookupPrice` returns null and the turn drops out of every cost total.
|
|
24
|
+
*/
|
|
25
|
+
const CODEMIE_PRICES = {
|
|
26
|
+
'claude-smart-router': { input: 1, output: 5, cacheRead: 0.1, cacheWrite: 1.25, cacheWrite1h: 2 },
|
|
27
|
+
};
|
|
13
28
|
const HERE = getDirname(import.meta.url);
|
|
14
29
|
let TABLE = null;
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return TABLE;
|
|
30
|
+
function toModelPrice(p) {
|
|
31
|
+
return {
|
|
32
|
+
input: p.input ?? 0,
|
|
33
|
+
output: p.output ?? 0,
|
|
34
|
+
cacheRead: p.cacheRead ?? 0,
|
|
35
|
+
cacheCreation: p.cacheWrite ?? 0,
|
|
36
|
+
cacheWrite1h: p.cacheWrite1h,
|
|
37
|
+
bedrockRegionalMultiplier: p.bedrockRegionalMultiplier,
|
|
38
|
+
estimated: p.estimated,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function pricesEqual(a, b) {
|
|
42
|
+
return (a.input === b.input
|
|
43
|
+
&& a.output === b.output
|
|
44
|
+
&& a.cacheRead === b.cacheRead
|
|
45
|
+
&& a.cacheCreation === b.cacheCreation
|
|
46
|
+
&& a.cacheWrite1h === b.cacheWrite1h
|
|
47
|
+
&& a.bedrockRegionalMultiplier === b.bedrockRegionalMultiplier
|
|
48
|
+
&& a.estimated === b.estimated);
|
|
35
49
|
}
|
|
36
50
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* `
|
|
40
|
-
*
|
|
51
|
+
* Builds the rate card from a bag of raw rows (a parsed `pricing.json`, an injected fixture for
|
|
52
|
+
* tests, or any merge of the two): every key is lowercased and dots are turned to dashes, so
|
|
53
|
+
* `GLM-4.7` and `glm-4-7` land on the same table entry. When two distinct raw keys normalize to
|
|
54
|
+
* the same table key, they must carry identical prices — that is the only way the pricing data
|
|
55
|
+
* itself can declare two spellings of the same model (e.g. `gemini-3.7-flash` / `gemini-3-7-flash`)
|
|
56
|
+
* — otherwise the table is ambiguous and this throws rather than silently picking one.
|
|
41
57
|
*/
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
58
|
+
export function buildPriceTable(rows) {
|
|
59
|
+
const built = {};
|
|
60
|
+
for (const [rawKey, raw] of Object.entries(rows)) {
|
|
61
|
+
if (rawKey.startsWith('_')) {
|
|
62
|
+
continue; // skip _meta and similar
|
|
47
63
|
}
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
|
|
64
|
+
const key = priceTableKey(rawKey);
|
|
65
|
+
const price = toModelPrice(raw);
|
|
66
|
+
const existing = built[key];
|
|
67
|
+
if (existing && !pricesEqual(existing, price)) {
|
|
68
|
+
throw new ConfigurationError(`[pricing] "${rawKey}" normalizes to key "${key}", which already holds a different price`);
|
|
53
69
|
}
|
|
54
|
-
|
|
70
|
+
built[key] = price;
|
|
55
71
|
}
|
|
72
|
+
return built;
|
|
56
73
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* Parse the version segments trailing a tier prefix into a numeric tuple for comparison, e.g.
|
|
61
|
-
* `claude-sonnet-4-8` under tier `claude-sonnet` -> `[4, 8]`. Returns null for keys that don't
|
|
62
|
-
* fit the plain `<tier>(-<digits>)*` shape — non-numeric segments (`-latest`) or a long numeric
|
|
63
|
-
* segment (a pinned date snapshot like `-20250514`, 8 digits) — since those aren't meaningful
|
|
64
|
-
* "is this newer" signals and would otherwise outrank a real version bump by raw magnitude.
|
|
65
|
-
*/
|
|
66
|
-
function tierVersionTuple(key, tier) {
|
|
67
|
-
const rest = key.slice(tier.length);
|
|
68
|
-
if (!rest) {
|
|
69
|
-
return [0];
|
|
70
|
-
}
|
|
71
|
-
const segments = rest.split('-').filter(Boolean);
|
|
72
|
-
const nums = [];
|
|
73
|
-
for (const segment of segments) {
|
|
74
|
-
if (!/^\d+$/.test(segment) || segment.length >= 8) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
nums.push(Number(segment));
|
|
74
|
+
function table() {
|
|
75
|
+
if (TABLE) {
|
|
76
|
+
return TABLE;
|
|
78
77
|
}
|
|
79
|
-
|
|
78
|
+
const raw = JSON.parse(readFileSync(join(HERE, 'pricing.json'), 'utf-8'));
|
|
79
|
+
TABLE = buildPriceTable({ ...raw, ...CODEMIE_PRICES });
|
|
80
|
+
return TABLE;
|
|
80
81
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return
|
|
82
|
+
/**
|
|
83
|
+
* The fully built rate card: the vendored table with {@link CODEMIE_PRICES} merged over it and every
|
|
84
|
+
* key lowercased. Exported so consumers that cannot import this module — the standalone Claude
|
|
85
|
+
* statusline, which runs as a detached `node <path>` process — can be handed the same rates rather
|
|
86
|
+
* than a copy of the raw `pricing.json`, which carries none of the CodeMie-only rows.
|
|
87
|
+
*/
|
|
88
|
+
export function priceTable() {
|
|
89
|
+
return table();
|
|
89
90
|
}
|
|
90
91
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
92
|
+
* Resolves pricing for a model, reporting how it was matched. Returns null when no entry
|
|
93
|
+
* matches (the caller marks the model `unpriced` — never a silent $0, and never a guessed
|
|
94
|
+
* family/tier price). The lookup order (exact, then one snapshot suffix stripped, then a
|
|
95
|
+
* version-first Claude id reordered to family-first) lives in {@link resolvePriceKey}, shared
|
|
96
|
+
* with the Claude statusline so the two can never price the same id differently.
|
|
97
|
+
*
|
|
98
|
+
* `model` is also checked, in its original unnormalized form, for a Bedrock region qualifier
|
|
99
|
+
* (see {@link applyBedrockRegionalPremium}) — pass the raw backend id straight through rather
|
|
100
|
+
* than pre-normalizing it, or the premium this exists to detect is invisible by the time it gets
|
|
101
|
+
* here.
|
|
96
102
|
*/
|
|
97
|
-
function
|
|
98
|
-
const
|
|
99
|
-
|
|
103
|
+
export function resolvePrice(model) {
|
|
104
|
+
const prices = table();
|
|
105
|
+
const hit = resolvePriceKey(model, (key) => (Object.hasOwn(prices, key) ? prices[key] : undefined));
|
|
106
|
+
if (!hit) {
|
|
100
107
|
return null;
|
|
101
108
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (version === null) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
|
-
if (!best || compareVersionTuples(version, best.version) > 0) {
|
|
112
|
-
best = { key, version, price };
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return best ? { key: best.key, price: best.price } : null;
|
|
109
|
+
return {
|
|
110
|
+
price: applyBedrockRegionalPremium(hit.value, model),
|
|
111
|
+
key: hit.key,
|
|
112
|
+
match: hit.match,
|
|
113
|
+
estimated: hit.value.estimated ?? false,
|
|
114
|
+
};
|
|
116
115
|
}
|
|
117
116
|
/**
|
|
118
|
-
* Look up pricing for a model. Returns null when no entry matches
|
|
119
|
-
*
|
|
120
|
-
* 1. Exact (normalized) match — authoritative.
|
|
121
|
-
* 2. Longest key aligned to a segment boundary — a deliberate family fallback, logged as inexact.
|
|
122
|
-
* 3. Latest same-tier Claude price — for a model newer than every table entry, logged as inexact.
|
|
123
|
-
* Dots are folded to dashes first because the table keys use dashes (e.g. `gpt-4-1`, not `gpt-4.1`).
|
|
117
|
+
* Look up pricing for a model. Returns null when no entry matches. Thin wrapper over
|
|
118
|
+
* {@link resolvePrice} for callers that only need the price, not its provenance.
|
|
124
119
|
*/
|
|
125
120
|
export function lookupPrice(model) {
|
|
126
|
-
|
|
127
|
-
const prices = table();
|
|
128
|
-
const exact = prices[normalized];
|
|
129
|
-
if (exact) {
|
|
130
|
-
return exact;
|
|
131
|
-
}
|
|
132
|
-
let best = null;
|
|
133
|
-
for (const [key, price] of Object.entries(prices)) {
|
|
134
|
-
if (isSegmentMatch(normalized, key) && (!best || key.length > best.key.length)) {
|
|
135
|
-
best = { key, price };
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (best) {
|
|
139
|
-
logger.debug(`[pricing] no exact entry for "${normalized}"; using family price "${best.key}"`);
|
|
140
|
-
return best.price;
|
|
141
|
-
}
|
|
142
|
-
const tierFallback = claudeTierFallback(normalized, prices);
|
|
143
|
-
if (tierFallback) {
|
|
144
|
-
logger.debug(`[pricing] no entry for "${normalized}"; using latest same-tier price "${tierFallback.key}"`);
|
|
145
|
-
return tierFallback.price;
|
|
146
|
-
}
|
|
147
|
-
return null;
|
|
121
|
+
return resolvePrice(model)?.price ?? null;
|
|
148
122
|
}
|
|
149
123
|
//# sourceMappingURL=pricing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../src/utils/pricing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"pricing.js","sourceRoot":"","sources":["../../src/utils/pricing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,2BAA2B,E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