@trazum/core 1.81.0 → 1.83.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/README.md +34 -18
- package/dist/advisories.d.ts +33 -1
- package/dist/advisories.d.ts.map +1 -1
- package/dist/advisories.js +130 -20
- package/dist/advisories.js.map +1 -1
- package/dist/band.d.ts +131 -0
- package/dist/band.d.ts.map +1 -0
- package/dist/band.js +210 -0
- package/dist/band.js.map +1 -0
- package/dist/conform.d.ts +1 -1
- package/dist/conform.d.ts.map +1 -1
- package/dist/conform.js +84 -1
- package/dist/conform.js.map +1 -1
- package/dist/helicone.d.ts +92 -0
- package/dist/helicone.d.ts.map +1 -0
- package/dist/helicone.js +194 -0
- package/dist/helicone.js.map +1 -0
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +16 -3
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/es.d.ts.map +1 -1
- package/dist/i18n/es.js +17 -3
- package/dist/i18n/es.js.map +1 -1
- package/dist/i18n/types.d.ts +60 -1
- package/dist/i18n/types.d.ts.map +1 -1
- package/dist/index.d.ts +16 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/langsmith.d.ts +104 -0
- package/dist/langsmith.d.ts.map +1 -0
- package/dist/langsmith.js +270 -0
- package/dist/langsmith.js.map +1 -0
- package/dist/levers.d.ts +1 -1
- package/dist/levers.js +2 -2
- package/dist/levers.js.map +1 -1
- package/dist/litellm.d.ts +98 -0
- package/dist/litellm.d.ts.map +1 -0
- package/dist/litellm.js +207 -0
- package/dist/litellm.js.map +1 -0
- package/dist/measured-profile.d.ts +4 -0
- package/dist/measured-profile.d.ts.map +1 -1
- package/dist/measured-profile.js +22 -1
- package/dist/measured-profile.js.map +1 -1
- package/dist/pricing.d.ts +98 -3
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +393 -35
- package/dist/pricing.js.map +1 -1
- package/dist/receipt.d.ts +253 -0
- package/dist/receipt.d.ts.map +1 -0
- package/dist/receipt.js +111 -0
- package/dist/receipt.js.map +1 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +36 -0
- package/dist/schemas.js.map +1 -1
- package/dist/tokenizer.d.ts +45 -49
- package/dist/tokenizer.d.ts.map +1 -1
- package/dist/tokenizer.js +100 -51
- package/dist/tokenizer.js.map +1 -1
- package/dist/types.d.ts +108 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/verdict-bridge.d.ts +113 -0
- package/dist/verdict-bridge.d.ts.map +1 -0
- package/dist/verdict-bridge.js +127 -0
- package/dist/verdict-bridge.js.map +1 -0
- package/package.json +1 -1
- package/src/advisories.ts +166 -19
- package/src/band.ts +213 -0
- package/src/conform.ts +100 -1
- package/src/helicone.ts +227 -0
- package/src/i18n/en.ts +19 -3
- package/src/i18n/es.ts +20 -3
- package/src/i18n/types.ts +63 -1
- package/src/index.ts +31 -2
- package/src/langsmith.ts +315 -0
- package/src/levers.ts +3 -3
- package/src/litellm.ts +243 -0
- package/src/measured-profile.ts +26 -2
- package/src/pricing.ts +430 -30
- package/src/receipt.ts +351 -0
- package/src/schemas.ts +36 -0
- package/src/tokenizer.ts +101 -51
- package/src/types.ts +104 -0
- package/src/verdict-bridge.ts +200 -0
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ export { explainGateFailure, gateMargin, GATE_MARGIN_TIGHT } from './gate-explai
|
|
|
20
20
|
export { measuredUsage, labelCoverage, MIN_SCALE_DAYS, SCALE_TO_DAYS } from './measured-profile.js';
|
|
21
21
|
export { assignSources, fleetRollup } from './fleet.js';
|
|
22
22
|
export { rollUp } from './rollup.js';
|
|
23
|
+
export { receiptFrom, RECEIPT_LINE_FIELDS } from './receipt.js';
|
|
23
24
|
export { heartbeats } from './heartbeat.js';
|
|
24
25
|
export { ruleYield } from './rule-yield.js';
|
|
25
26
|
export { buildPlan, planLabelName, parsePlanDocument, PLAN_ACTION_KINDS } from './plan.js';
|
|
@@ -35,7 +36,9 @@ export { qualityGate, MIN_OUTCOMES_EACH_SIDE, MAX_MODEL_MIX_DRIFT, MAX_VOLUME_RA
|
|
|
35
36
|
export { ladderArithmetic, ladderPosition, validateLadder, MIN_CALLS_FOR_LADDER, BREAK_EVEN_BAND, } from './ladder.js';
|
|
36
37
|
export { perOutcome, rankPerOutcome, MIN_OUTCOMES_FOR_RATE, MIN_COVERAGE_FOR_RATE, } from './per-outcome.js';
|
|
37
38
|
export { gatewayDecision, streamingUsageReader, WIRE_SHAPES, usageFromResponse, FAILURE_POLICIES, } from './gateway.js';
|
|
39
|
+
export { BANDS, MEASURED_FOREIGN_ERROR_PCT, bandFor, bucketFor, foreignTokenizer, measuredForeignError, } from './band.js';
|
|
38
40
|
export { conform, CONTRACT_NAMES, requiredFieldsOf } from './conform.js';
|
|
41
|
+
export { readDroppedVerdict, verdictMatchesSlice } from './verdict-bridge.js';
|
|
39
42
|
export { CONTRACT_SCHEMAS, contractSchema } from './schemas.js';
|
|
40
43
|
export { budgetPositions, monthOf, MAX_UNMEASURED_NAMED } from './budget.js';
|
|
41
44
|
export { waiverHistory, waiverDay, isWaiverUse } from './waivers.js';
|
|
@@ -44,6 +47,9 @@ export { judgeLimits } from './judgement.js';
|
|
|
44
47
|
export { indexUsage, positionAt } from './position.js';
|
|
45
48
|
export { claudeCodeRecords, looksLikeClaudeCodeTranscript } from './claude-code.js';
|
|
46
49
|
export { otelRecords, looksLikeOtel } from './otel.js';
|
|
50
|
+
export { litellmRecords, looksLikeLiteLlm } from './litellm.js';
|
|
51
|
+
export { heliconeRecords, looksLikeHelicone } from './helicone.js';
|
|
52
|
+
export { langsmithRecords, looksLikeLangsmith } from './langsmith.js';
|
|
47
53
|
export { positionReport } from './position-report.js';
|
|
48
54
|
export { guardSpend } from './guard.js';
|
|
49
55
|
export { proposeInit, HEADLINE_FLOOR_SHARE, MIN_RATE_DAYS } from './init.js';
|
|
@@ -79,7 +85,7 @@ export { DICTIONARY_STANDING, dictionaryStanding, languagesWithStanding, } from
|
|
|
79
85
|
export { toPromptfoo } from './promptfoo.js';
|
|
80
86
|
export { toOtlpMetrics } from './otlp.js';
|
|
81
87
|
export { SUGGEST_SYSTEM_PROMPT, applyRewrites, rejectionText, suggestRewrites } from './suggest.js';
|
|
82
|
-
export { MODELS, DEFAULT_MODEL, COST_MULTIPLIERS, PRICING_LAST_REVIEWED, reviewAgeDays, BUNDLED_CATALOGUE, getModel, listModels, effectivePricing, cheapestOfTier, modelFrom, cheapestOfTierIn, multipliersFor, } from './pricing.js';
|
|
88
|
+
export { MODELS, DEFAULT_MODEL, COST_MULTIPLIERS, PRICING_LAST_REVIEWED, STALE_PRICING_DAYS, PROVIDER_REVIEWED, reviewAgeDays, BUNDLED_CATALOGUE, getModel, listModels, effectivePricing, cheapestOfTier, modelFrom, cheapestOfTierIn, multipliersFor, isOffered, } from './pricing.js';
|
|
83
89
|
// Local price corrections, so a price change needs no library upgrade.
|
|
84
90
|
export { MAX_PRICING_BYTES, PRICING_MODEL_KEYS, PRICING_OVERLAY_KEYS, PricingOverlayError, applyPricingOverlay, catalogueFromOverlay, parsePricingOverlay, } from './pricing-overlay.js';
|
|
85
91
|
export { openrouterOverlay } from './openrouter.js';
|
|
@@ -93,7 +99,7 @@ export { BASELINE_FILENAME, BASELINE_VERSION, BaselineError, MAX_BASELINE_BYTES,
|
|
|
93
99
|
export { RULES, getRule } from './rules.js';
|
|
94
100
|
export { segment, join, protectedTexts } from './segment.js';
|
|
95
101
|
export { computeSavings, costOfCall, formatUsd, formatSignedUsd } from './savings.js';
|
|
96
|
-
export { buildAdvisories, recommendTier } from './advisories.js';
|
|
102
|
+
export { buildAdvisories, recommendTier, recommendTierDetailed } from './advisories.js';
|
|
97
103
|
export { analyzeCachePrefix } from './cache.js';
|
|
98
104
|
// Rearranging a prompt so its stable instructions sit in the cacheable prefix.
|
|
99
105
|
// The largest saving Trazum knows about, and the most dangerous transformation
|
|
@@ -128,7 +134,7 @@ export { reviewExamples, EXAMPLE_REVIEW_SYSTEM_PROMPT } from './review.js';
|
|
|
128
134
|
// what the measurement cannot tell you.
|
|
129
135
|
export { NothingToPrune, plannedCalls, pruneExamples, withoutExample } from './prune.js';
|
|
130
136
|
// Golden-set evaluation (optional, costs three LLM calls per case)
|
|
131
|
-
export { evaluate, fillPrompt, verdictFor } from './evaluate.js';
|
|
137
|
+
export { agreement, evaluate, fillPrompt, pooled, verdictFor } from './evaluate.js';
|
|
132
138
|
// Comparing two prompt versions
|
|
133
139
|
export { comparePrompts } from './compare.js';
|
|
134
140
|
// Glob matching for config budget patterns. Pure, so it belongs here; the
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,WAAW,EACX,cAAc,EACd,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,UAAU,EACV,cAAc,EACd,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,QAAQ,GACT,MAAM,YAAY,CAAC;AAWpB,OAAO,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAClF,gFAAgF;AAChF,4EAA4E;AAC5E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEtF,2EAA2E;AAC3E,+EAA+E;AAC/E,8EAA8E;AAC9E,0EAA0E;AAC1E,yCAAyC;AACzC,4EAA4E;AAC5E,qDAAqD;AACrD,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,wBAAwB,EACxB,6BAA6B,EAC7B,YAAY,GACb,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAA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AM,cAAc,CAAC;AAQ9C,0EAA0E;AAC1E,+EAA+E;AAC/E,8EAA8E;AAC9E,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEzD,8EAA8E;AAC9E,6EAA6E;AAC7E,2DAA2D;AAC3D,OAAO,EACL,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,SAAS,EACT,WAAW,EACX,WAAW,EACX,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EACN,cAAc,EACd,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,KAAK,GACN,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangSmith's run export, read as a usage log.
|
|
3
|
+
*
|
|
4
|
+
* The fifth converter in the pattern `from-claude-code` started: a pure
|
|
5
|
+
* function turns one tool's export into Trazum's usage-log records, and every
|
|
6
|
+
* door prices it from there. LangSmith is the tracing product most LangChain
|
|
7
|
+
* teams already run, so the export exists before Trazum does.
|
|
8
|
+
*
|
|
9
|
+
* **The format is derived, not guessed.** Every field below is `RunBase` and
|
|
10
|
+
* `Run` in `python/langsmith/schemas.py` in langchain-ai/langsmith-sdk. A
|
|
11
|
+
* converter written from memory of an API is a converter that silently
|
|
12
|
+
* mis-reads somebody's bill.
|
|
13
|
+
*
|
|
14
|
+
* ## A run is not a call, and that is the whole difficulty
|
|
15
|
+
*
|
|
16
|
+
* LangSmith records a **run**, and a trace is a tree of them: chains, tools and
|
|
17
|
+
* retrievers alongside the model calls. Only `run_type: "llm"` carries token
|
|
18
|
+
* counts, and summing the tree would count the same tokens once per level. So
|
|
19
|
+
* everything else is skipped and **counted out loud** — a converter that
|
|
20
|
+
* quietly dropped two thirds of a file would look like one that read it.
|
|
21
|
+
*
|
|
22
|
+
* ## The model, and why it is refused rather than inferred
|
|
23
|
+
*
|
|
24
|
+
* There is no model column. The name lives in `extra.metadata.ls_model_name`,
|
|
25
|
+
* or in the invocation parameters the SDK records beside it, and a run whose
|
|
26
|
+
* metadata carries neither cannot be priced. The obvious guess is the run's
|
|
27
|
+
* own `name` — LangChain names them after the class, `ChatOpenAI`, which is a
|
|
28
|
+
* client and not a model. Pricing a call by the class that made it would be a
|
|
29
|
+
* figure attributed to something it does not describe, which is the fault this
|
|
30
|
+
* repository keeps finding in itself. Such a run is counted in `unnamedModel`
|
|
31
|
+
* and dropped.
|
|
32
|
+
*
|
|
33
|
+
* ## What deliberately does not cross
|
|
34
|
+
*
|
|
35
|
+
* `inputs` and `outputs` are the prompt and the completion, on every single
|
|
36
|
+
* run. **Neither is read.** `extra.metadata` is read for two named keys and
|
|
37
|
+
* nothing else, because it is a free-form bag the operator fills and the next
|
|
38
|
+
* thing they put in it might be a credential. The converter names the fields
|
|
39
|
+
* it takes and takes nothing else, and a fixture plants a marker in each and
|
|
40
|
+
* greps the whole output.
|
|
41
|
+
*
|
|
42
|
+
* ## What it refuses to invent
|
|
43
|
+
*
|
|
44
|
+
* There is no cache-token split. `prompt_cost_details` looks like one and is
|
|
45
|
+
* not: it is LangSmith's own priced breakdown in dollars, computed from
|
|
46
|
+
* LangSmith's price table. It never enters a record, and neither does
|
|
47
|
+
* `total_cost` — `reportedCostUsd` returns it on its own, the way
|
|
48
|
+
* `from-litellm` keeps the gateway's arithmetic apart from Trazum's. Two price
|
|
49
|
+
* tables, two figures; merging them is how a report becomes quietly wrong.
|
|
50
|
+
*/
|
|
51
|
+
/** One converted record, shaped exactly as `parseUsageLine` reads it. */
|
|
52
|
+
export interface LangsmithRecord {
|
|
53
|
+
model: string;
|
|
54
|
+
ts?: string;
|
|
55
|
+
label?: string;
|
|
56
|
+
session?: string;
|
|
57
|
+
usage: {
|
|
58
|
+
input_tokens: number;
|
|
59
|
+
output_tokens: number;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export interface LangsmithConversion {
|
|
63
|
+
records: LangsmithRecord[];
|
|
64
|
+
/** Runs that were model calls and converted. */
|
|
65
|
+
rows: number;
|
|
66
|
+
/**
|
|
67
|
+
* Runs that were not model calls: chains, tools, retrievers, prompts.
|
|
68
|
+
*
|
|
69
|
+
* Counted rather than ignored. They are most of a LangSmith export, and a
|
|
70
|
+
* reader who converted a thousand runs into three hundred records is owed
|
|
71
|
+
* the reason.
|
|
72
|
+
*/
|
|
73
|
+
notModelCalls: number;
|
|
74
|
+
/** Model calls whose metadata named no model: counted, never guessed. */
|
|
75
|
+
unnamedModel: number;
|
|
76
|
+
/** Model calls carrying no token counts at all. */
|
|
77
|
+
noTokens: number;
|
|
78
|
+
/**
|
|
79
|
+
* LangSmith's own cost total, in dollars, or null when no run reported one.
|
|
80
|
+
*
|
|
81
|
+
* Kept apart from anything Trazum computes and never merged into a record.
|
|
82
|
+
* Null is an absence, not a total of nothing.
|
|
83
|
+
*/
|
|
84
|
+
reportedCostUsd: number | null;
|
|
85
|
+
/** Lines or documents that did not parse as JSON at all. */
|
|
86
|
+
unparseable: number;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Convert a LangSmith run export.
|
|
90
|
+
*
|
|
91
|
+
* Accepts a JSON array of runs, a single run, `{ runs: [...] }` as the list
|
|
92
|
+
* endpoint returns it, or newline-delimited runs. Pure over its input.
|
|
93
|
+
*/
|
|
94
|
+
export declare function langsmithRecords(text: string): LangsmithConversion;
|
|
95
|
+
/**
|
|
96
|
+
* Whether a file looks like a LangSmith run export, by shape.
|
|
97
|
+
*
|
|
98
|
+
* Deliberately narrow: `run_type` beside one of the trace fields only
|
|
99
|
+
* LangSmith writes. A looser test would claim a Helicone export or a LiteLLM
|
|
100
|
+
* spend log — both carry `prompt_tokens` — and refuse it in this file's words
|
|
101
|
+
* instead of letting the code that can read it try.
|
|
102
|
+
*/
|
|
103
|
+
export declare function looksLikeLangsmith(text: string, prefixBytes?: number): boolean;
|
|
104
|
+
//# sourceMappingURL=langsmith.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langsmith.d.ts","sourceRoot":"","sources":["../src/langsmith.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;CACrB;AAyGD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAgGlE;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,SAAO,GAAG,OAAO,CAS5E"}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LangSmith's run export, read as a usage log.
|
|
3
|
+
*
|
|
4
|
+
* The fifth converter in the pattern `from-claude-code` started: a pure
|
|
5
|
+
* function turns one tool's export into Trazum's usage-log records, and every
|
|
6
|
+
* door prices it from there. LangSmith is the tracing product most LangChain
|
|
7
|
+
* teams already run, so the export exists before Trazum does.
|
|
8
|
+
*
|
|
9
|
+
* **The format is derived, not guessed.** Every field below is `RunBase` and
|
|
10
|
+
* `Run` in `python/langsmith/schemas.py` in langchain-ai/langsmith-sdk. A
|
|
11
|
+
* converter written from memory of an API is a converter that silently
|
|
12
|
+
* mis-reads somebody's bill.
|
|
13
|
+
*
|
|
14
|
+
* ## A run is not a call, and that is the whole difficulty
|
|
15
|
+
*
|
|
16
|
+
* LangSmith records a **run**, and a trace is a tree of them: chains, tools and
|
|
17
|
+
* retrievers alongside the model calls. Only `run_type: "llm"` carries token
|
|
18
|
+
* counts, and summing the tree would count the same tokens once per level. So
|
|
19
|
+
* everything else is skipped and **counted out loud** — a converter that
|
|
20
|
+
* quietly dropped two thirds of a file would look like one that read it.
|
|
21
|
+
*
|
|
22
|
+
* ## The model, and why it is refused rather than inferred
|
|
23
|
+
*
|
|
24
|
+
* There is no model column. The name lives in `extra.metadata.ls_model_name`,
|
|
25
|
+
* or in the invocation parameters the SDK records beside it, and a run whose
|
|
26
|
+
* metadata carries neither cannot be priced. The obvious guess is the run's
|
|
27
|
+
* own `name` — LangChain names them after the class, `ChatOpenAI`, which is a
|
|
28
|
+
* client and not a model. Pricing a call by the class that made it would be a
|
|
29
|
+
* figure attributed to something it does not describe, which is the fault this
|
|
30
|
+
* repository keeps finding in itself. Such a run is counted in `unnamedModel`
|
|
31
|
+
* and dropped.
|
|
32
|
+
*
|
|
33
|
+
* ## What deliberately does not cross
|
|
34
|
+
*
|
|
35
|
+
* `inputs` and `outputs` are the prompt and the completion, on every single
|
|
36
|
+
* run. **Neither is read.** `extra.metadata` is read for two named keys and
|
|
37
|
+
* nothing else, because it is a free-form bag the operator fills and the next
|
|
38
|
+
* thing they put in it might be a credential. The converter names the fields
|
|
39
|
+
* it takes and takes nothing else, and a fixture plants a marker in each and
|
|
40
|
+
* greps the whole output.
|
|
41
|
+
*
|
|
42
|
+
* ## What it refuses to invent
|
|
43
|
+
*
|
|
44
|
+
* There is no cache-token split. `prompt_cost_details` looks like one and is
|
|
45
|
+
* not: it is LangSmith's own priced breakdown in dollars, computed from
|
|
46
|
+
* LangSmith's price table. It never enters a record, and neither does
|
|
47
|
+
* `total_cost` — `reportedCostUsd` returns it on its own, the way
|
|
48
|
+
* `from-litellm` keeps the gateway's arithmetic apart from Trazum's. Two price
|
|
49
|
+
* tables, two figures; merging them is how a report becomes quietly wrong.
|
|
50
|
+
*/
|
|
51
|
+
const asObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
52
|
+
? value
|
|
53
|
+
: null;
|
|
54
|
+
const tryParse = (text) => {
|
|
55
|
+
try {
|
|
56
|
+
return JSON.parse(text);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const asCount = (value) => {
|
|
63
|
+
const n = typeof value === 'string' ? Number(value) : value;
|
|
64
|
+
return typeof n === 'number' && Number.isFinite(n) && n >= 0 ? n : undefined;
|
|
65
|
+
};
|
|
66
|
+
const asName = (value) => typeof value === 'string' && value.trim() !== '' ? value.trim() : null;
|
|
67
|
+
/** `extra.metadata`, which is where LangSmith documents everything user-set. */
|
|
68
|
+
function metadataOf(run) {
|
|
69
|
+
const extra = asObject(run.extra);
|
|
70
|
+
return extra === null ? asObject(run.metadata) : (asObject(extra.metadata) ?? asObject(run.metadata));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The model, from the two named places it is recorded and nowhere else.
|
|
74
|
+
*
|
|
75
|
+
* `ls_model_name` is what the SDK writes; `model` and `model_name` are what a
|
|
76
|
+
* team writes by hand when they set metadata themselves. The run's `name` is
|
|
77
|
+
* deliberately not consulted: LangChain names a run after the client class,
|
|
78
|
+
* and `ChatOpenAI` is not a model anybody can price.
|
|
79
|
+
*/
|
|
80
|
+
function modelOf(run) {
|
|
81
|
+
const metadata = metadataOf(run);
|
|
82
|
+
if (metadata !== null) {
|
|
83
|
+
for (const key of ['ls_model_name', 'model_name', 'model']) {
|
|
84
|
+
const found = asName(metadata[key]);
|
|
85
|
+
if (found !== null)
|
|
86
|
+
return found;
|
|
87
|
+
}
|
|
88
|
+
// The invocation parameters, where the SDK also records it.
|
|
89
|
+
const params = asObject(metadata.invocation_params);
|
|
90
|
+
if (params !== null) {
|
|
91
|
+
for (const key of ['model', 'model_name']) {
|
|
92
|
+
const found = asName(params[key]);
|
|
93
|
+
if (found !== null)
|
|
94
|
+
return found;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The label, from the tags a team already puts on its traces.
|
|
102
|
+
*
|
|
103
|
+
* `tags` is LangSmith's own list and the first entry wins, because a workload
|
|
104
|
+
* has one name in a bill. Then the two metadata keys a team would plausibly
|
|
105
|
+
* name a workload by. Never joined, never invented.
|
|
106
|
+
*/
|
|
107
|
+
function labelOf(run) {
|
|
108
|
+
if (Array.isArray(run.tags)) {
|
|
109
|
+
for (const tag of run.tags) {
|
|
110
|
+
const found = asName(tag);
|
|
111
|
+
if (found !== null)
|
|
112
|
+
return found;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const metadata = metadataOf(run);
|
|
116
|
+
if (metadata !== null) {
|
|
117
|
+
for (const key of ['label', 'workload']) {
|
|
118
|
+
const found = asName(metadata[key]);
|
|
119
|
+
if (found !== null)
|
|
120
|
+
return found;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
/** The run's start time as an ISO instant, or undefined. */
|
|
126
|
+
function timeOf(run) {
|
|
127
|
+
const raw = run.start_time ?? run.startTime;
|
|
128
|
+
if (typeof raw !== 'string' && typeof raw !== 'number')
|
|
129
|
+
return undefined;
|
|
130
|
+
const ms = typeof raw === 'number' ? raw : Date.parse(raw);
|
|
131
|
+
if (!Number.isFinite(ms))
|
|
132
|
+
return undefined;
|
|
133
|
+
return new Date(ms).toISOString();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The token counts, from the two shapes LangSmith has written them in.
|
|
137
|
+
*
|
|
138
|
+
* `prompt_tokens` and `completion_tokens` sit on the run; newer exports also
|
|
139
|
+
* carry a nested `usage_metadata` with `input_tokens` and `output_tokens`.
|
|
140
|
+
* Both are read because both are in the wild, and an export from last year is
|
|
141
|
+
* still somebody's bill.
|
|
142
|
+
*/
|
|
143
|
+
function tokensOf(run) {
|
|
144
|
+
const nested = asObject(run.usage_metadata);
|
|
145
|
+
return {
|
|
146
|
+
input: asCount(run.prompt_tokens) ?? asCount(nested?.input_tokens),
|
|
147
|
+
output: asCount(run.completion_tokens) ?? asCount(nested?.output_tokens),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Convert a LangSmith run export.
|
|
152
|
+
*
|
|
153
|
+
* Accepts a JSON array of runs, a single run, `{ runs: [...] }` as the list
|
|
154
|
+
* endpoint returns it, or newline-delimited runs. Pure over its input.
|
|
155
|
+
*/
|
|
156
|
+
export function langsmithRecords(text) {
|
|
157
|
+
const out = {
|
|
158
|
+
records: [],
|
|
159
|
+
rows: 0,
|
|
160
|
+
notModelCalls: 0,
|
|
161
|
+
unnamedModel: 0,
|
|
162
|
+
noTokens: 0,
|
|
163
|
+
reportedCostUsd: null,
|
|
164
|
+
unparseable: 0,
|
|
165
|
+
};
|
|
166
|
+
const runs = [];
|
|
167
|
+
const whole = tryParse(text);
|
|
168
|
+
if (whole !== undefined) {
|
|
169
|
+
if (Array.isArray(whole))
|
|
170
|
+
runs.push(...whole);
|
|
171
|
+
else {
|
|
172
|
+
const doc = asObject(whole);
|
|
173
|
+
if (doc !== null && Array.isArray(doc.runs))
|
|
174
|
+
runs.push(...doc.runs);
|
|
175
|
+
else if (doc !== null)
|
|
176
|
+
runs.push(doc);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
for (const line of text.split('\n')) {
|
|
181
|
+
if (line.trim() === '')
|
|
182
|
+
continue;
|
|
183
|
+
const parsed = tryParse(line);
|
|
184
|
+
if (parsed === undefined)
|
|
185
|
+
out.unparseable += 1;
|
|
186
|
+
else if (Array.isArray(parsed))
|
|
187
|
+
runs.push(...parsed);
|
|
188
|
+
else
|
|
189
|
+
runs.push(parsed);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
let cost = 0;
|
|
193
|
+
let sawCost = false;
|
|
194
|
+
for (const raw of runs) {
|
|
195
|
+
const run = asObject(raw);
|
|
196
|
+
if (run === null)
|
|
197
|
+
continue;
|
|
198
|
+
/*
|
|
199
|
+
A run is only a call when LangSmith says it is one. The tree carries
|
|
200
|
+
chains, tools, retrievers and prompts alongside the model calls, and the
|
|
201
|
+
parent chain of an llm run repeats its child's tokens: summing the tree
|
|
202
|
+
would bill the same tokens once per level. `run_type` is the field that
|
|
203
|
+
settles it, and a run with no run_type at all is not a run.
|
|
204
|
+
*/
|
|
205
|
+
const type = asName(run.run_type);
|
|
206
|
+
if (type === null)
|
|
207
|
+
continue;
|
|
208
|
+
if (type !== 'llm') {
|
|
209
|
+
out.notModelCalls += 1;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
out.rows += 1;
|
|
213
|
+
const reported = asCount(run.total_cost);
|
|
214
|
+
if (reported !== undefined) {
|
|
215
|
+
cost += reported;
|
|
216
|
+
sawCost = true;
|
|
217
|
+
}
|
|
218
|
+
const model = modelOf(run);
|
|
219
|
+
if (model === null) {
|
|
220
|
+
out.unnamedModel += 1;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const { input, output } = tokensOf(run);
|
|
224
|
+
if (input === undefined && output === undefined) {
|
|
225
|
+
out.noTokens += 1;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (input === 0 && output === 0)
|
|
229
|
+
out.noTokens += 1;
|
|
230
|
+
const ts = timeOf(run);
|
|
231
|
+
const label = labelOf(run);
|
|
232
|
+
/*
|
|
233
|
+
The trace is the conversation and the run id is one call. `trace_id`
|
|
234
|
+
spans the calls a single request made, which is the identity Trazum's
|
|
235
|
+
conversation findings need; answering them from `id` would report every
|
|
236
|
+
call as a conversation of one.
|
|
237
|
+
*/
|
|
238
|
+
const session = asName(run.trace_id);
|
|
239
|
+
out.records.push({
|
|
240
|
+
model,
|
|
241
|
+
...(ts !== undefined ? { ts } : {}),
|
|
242
|
+
...(label !== undefined ? { label } : {}),
|
|
243
|
+
...(session !== null ? { session } : {}),
|
|
244
|
+
usage: { input_tokens: input ?? 0, output_tokens: output ?? 0 },
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
// Rounded because these are dollars summed in floating point, and a total
|
|
248
|
+
// printed to eight decimal places reads as a precision nobody has.
|
|
249
|
+
if (sawCost)
|
|
250
|
+
out.reportedCostUsd = Math.round(cost * 1e6) / 1e6;
|
|
251
|
+
return out;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Whether a file looks like a LangSmith run export, by shape.
|
|
255
|
+
*
|
|
256
|
+
* Deliberately narrow: `run_type` beside one of the trace fields only
|
|
257
|
+
* LangSmith writes. A looser test would claim a Helicone export or a LiteLLM
|
|
258
|
+
* spend log — both carry `prompt_tokens` — and refuse it in this file's words
|
|
259
|
+
* instead of letting the code that can read it try.
|
|
260
|
+
*/
|
|
261
|
+
export function looksLikeLangsmith(text, prefixBytes = 8192) {
|
|
262
|
+
const head = text.slice(0, prefixBytes);
|
|
263
|
+
if (!head.includes('"run_type"'))
|
|
264
|
+
return false;
|
|
265
|
+
return (head.includes('"trace_id"') ||
|
|
266
|
+
head.includes('"dotted_order"') ||
|
|
267
|
+
head.includes('"start_time"') ||
|
|
268
|
+
head.includes('"session_id"'));
|
|
269
|
+
}
|
|
270
|
+
//# sourceMappingURL=langsmith.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langsmith.js","sourceRoot":"","sources":["../src/langsmith.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAyCH,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAkC,EAAE,CAClE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IAClE,CAAC,CAAE,KAAiC;IACpC,CAAC,CAAC,IAAI,CAAC;AAEX,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAW,EAAE;IACzC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,KAAc,EAAsB,EAAE;IACrD,MAAM,CAAC,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAC5D,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE,CAC/C,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CA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/C,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC;QAC3B,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAC/B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;QAC7B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAC9B,CAAC;AACJ,CAAC"}
|
package/dist/levers.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type { UsageProfileReport } from './usage.js';
|
|
|
18
18
|
*
|
|
19
19
|
* | lever | what it moves |
|
|
20
20
|
* |---|---|
|
|
21
|
-
* | which model the call goes to | Opus 5 → Sonnet 5 is
|
|
21
|
+
* | which model the call goes to | Opus 5 → Sonnet 5 is 60% off; → Haiku 4.5 is 80% |
|
|
22
22
|
* | the Batch API | 50% flat, on input and output |
|
|
23
23
|
* | prompt caching | 3–4x the rules |
|
|
24
24
|
* | shortening the prompt | ~1% |
|
package/dist/levers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { effectivePricing, multipliersFor } from './pricing.js';
|
|
1
|
+
import { effectivePricing, isOffered, multipliersFor } from './pricing.js';
|
|
2
2
|
import { UNLABELLED } from './usage.js';
|
|
3
3
|
/**
|
|
4
4
|
* Weakest first. A step *down* this ladder is what a route offers.
|
|
@@ -63,7 +63,7 @@ function candidateFor(model, breakdown, catalogue, on) {
|
|
|
63
63
|
const candidates = catalogue.models.filter((m) => m.id !== model.id &&
|
|
64
64
|
m.capability === target &&
|
|
65
65
|
m.provider === model.provider &&
|
|
66
|
-
m
|
|
66
|
+
isOffered(m) &&
|
|
67
67
|
m.contextWindow >= avgInput);
|
|
68
68
|
if (candidates.length === 0)
|
|
69
69
|
return null;
|
package/dist/levers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"levers.js","sourceRoot":"","sources":["../src/levers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;
|
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YACd,SAAS,EAAE,KAAK,CAAC,WAAW;YAC5B,KAAK,EAAE,SAAS,CAAC,KAAK;YACtB,QAAQ,EAAE,SAAS,CAAC,QAAQ;YAC5B,KAAK;YACL,KAAK;YACL,WAAW;YACX,WAAW;SACZ,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,WAAW,CAAC;QAC5D,gBAAgB;QAChB,kBAAkB,EAAE,gBAAgB,GAAG,QAAQ;QAC/C,QAAQ;KACT,CAAC;AACJ,CAAC;AAED,uEAAuE;AACvE,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LiteLLM's spend log, read as a usage log.
|
|
3
|
+
*
|
|
4
|
+
* `from-claude-code` proved the pattern and `from-otel` generalised it: a pure
|
|
5
|
+
* converter turns one tool's export into Trazum's usage-log records, and every
|
|
6
|
+
* door prices it from there. LiteLLM is the gateway a great many teams already
|
|
7
|
+
* put in front of every provider, so its `LiteLLM_SpendLogs` table is the one
|
|
8
|
+
* export most likely to already exist on somebody's disk.
|
|
9
|
+
*
|
|
10
|
+
* **The format is derived, not guessed.** Every field below is read off
|
|
11
|
+
* `litellm/proxy/schema.prisma` in BerriAI/litellm, model `LiteLLM_SpendLogs`.
|
|
12
|
+
* A converter written from memory of an API is a converter that silently
|
|
13
|
+
* mis-reads somebody's bill, and this project has one rule above all others
|
|
14
|
+
* about numbers it cannot justify.
|
|
15
|
+
*
|
|
16
|
+
* ## What maps
|
|
17
|
+
*
|
|
18
|
+
* | LiteLLM | Trazum |
|
|
19
|
+
* | --- | --- |
|
|
20
|
+
* | `model` | `model` |
|
|
21
|
+
* | `prompt_tokens` | `usage.input_tokens` |
|
|
22
|
+
* | `completion_tokens` | `usage.output_tokens` |
|
|
23
|
+
* | `startTime` | `ts` |
|
|
24
|
+
* | `session_id` | `session` |
|
|
25
|
+
* | `request_tags[0]`, else `metadata.tags[0]`, else `model_group` | `label` |
|
|
26
|
+
*
|
|
27
|
+
* ## What deliberately does not cross
|
|
28
|
+
*
|
|
29
|
+
* The row carries `messages` and `response` — the prompt itself and the
|
|
30
|
+
* completion — plus `api_key` (hashed, still credential-shaped),
|
|
31
|
+
* `requester_ip_address`, `user` and `end_user`. **None of it is read.** The
|
|
32
|
+
* converter names the fields it takes and takes nothing else, and a fixture
|
|
33
|
+
* plants a marker in each of them and greps the whole output.
|
|
34
|
+
*
|
|
35
|
+
* ## What it refuses to invent
|
|
36
|
+
*
|
|
37
|
+
* `cache_hit` is a flag and `cache_key` an identifier; neither is a token
|
|
38
|
+
* count. A converted record therefore carries no cache split at all, and the
|
|
39
|
+
* caching questions come back `cannot-tell` rather than answered from a
|
|
40
|
+
* guess — the same refusal as inventing a price. `cacheFlagged` counts the
|
|
41
|
+
* rows that said "hit" so the operator can see the gap is real rather than
|
|
42
|
+
* empty.
|
|
43
|
+
*
|
|
44
|
+
* `spend` is LiteLLM's own priced figure and is **never** merged into
|
|
45
|
+
* Trazum's catalogue-priced total. It is a second measurement of the same
|
|
46
|
+
* calls, kept apart the way the store's provider-billed standing is kept
|
|
47
|
+
* apart from the log's, and returned on its own so a caller who wants to
|
|
48
|
+
* compare the two can, deliberately.
|
|
49
|
+
*/
|
|
50
|
+
/** One converted record, shaped exactly as `parseUsageLine` reads it. */
|
|
51
|
+
export interface LiteLlmRecord {
|
|
52
|
+
model: string;
|
|
53
|
+
ts?: string;
|
|
54
|
+
label?: string;
|
|
55
|
+
session?: string;
|
|
56
|
+
usage: {
|
|
57
|
+
input_tokens: number;
|
|
58
|
+
output_tokens: number;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface LiteLlmConversion {
|
|
62
|
+
records: LiteLlmRecord[];
|
|
63
|
+
/** Rows that were spend logs and converted. */
|
|
64
|
+
rows: number;
|
|
65
|
+
/** Rows naming no model: counted, never guessed at, never dropped silently. */
|
|
66
|
+
unnamedModel: number;
|
|
67
|
+
/** Rows carrying no token counts at all — a logged call nobody can price. */
|
|
68
|
+
noTokens: number;
|
|
69
|
+
/** Rows LiteLLM marked as a cache hit, with no token split to act on. */
|
|
70
|
+
cacheFlagged: number;
|
|
71
|
+
/**
|
|
72
|
+
* LiteLLM's own total for the converted rows, in USD, or null when no row
|
|
73
|
+
* carried one. **Never** added to anything Trazum computes: it is the
|
|
74
|
+
* gateway's arithmetic over the gateway's price table, and merging two
|
|
75
|
+
* price tables into one figure is how a report becomes quietly wrong.
|
|
76
|
+
*/
|
|
77
|
+
reportedSpendUsd: number | null;
|
|
78
|
+
/** Lines or documents that did not parse as JSON at all. */
|
|
79
|
+
unparseable: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Convert a LiteLLM spend-log export.
|
|
83
|
+
*
|
|
84
|
+
* Accepts a JSON array of rows, a single row, `{ data: [...] }` as the proxy's
|
|
85
|
+
* own endpoints return it, or newline-delimited rows — so a `psql --json`
|
|
86
|
+
* dump, an API response and a streamed capture all work. Pure over its input.
|
|
87
|
+
*/
|
|
88
|
+
export declare function litellmRecords(text: string): LiteLlmConversion;
|
|
89
|
+
/**
|
|
90
|
+
* Whether a file looks like a LiteLLM spend log, by shape.
|
|
91
|
+
*
|
|
92
|
+
* Deliberately narrow: `request_id` beside one of the two token columns, and
|
|
93
|
+
* a field no other export in this project carries. A looser test would claim
|
|
94
|
+
* an OpenAI usage response, whose rows also have `prompt_tokens`, and refuse
|
|
95
|
+
* it in this file's words instead of letting the code that can read it try.
|
|
96
|
+
*/
|
|
97
|
+
export declare function looksLikeLiteLlm(text: string, prefixBytes?: number): boolean;
|
|
98
|
+
//# sourceMappingURL=litellm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"litellm.d.ts","sourceRoot":"","sources":["../src/litellm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,yEAAyE;AACzE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,+EAA+E;IAC/E,YAAY,EAAE,MAAM,CAAC;IACrB,6EAA6E;IAC7E,QAAQ,EAAE,MAAM,CAAC;IACjB,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;OAKG;IACH,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,4DAA4D;IAC5D,WAAW,EAAE,MAAM,CAAC;CACrB;AAqDD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAmF9D;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,SAAO,GAAG,OAAO,CAQ1E"}
|