@f3d1/llmkit-shared 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/errors.d.ts +32 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +64 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/providers.d.ts +14 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +131 -0
- package/dist/providers.js.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +22 -0
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class LLMKitError extends Error {
|
|
2
|
+
code: ErrorCode;
|
|
3
|
+
statusCode: number;
|
|
4
|
+
provider?: string | undefined;
|
|
5
|
+
constructor(message: string, code: ErrorCode, statusCode?: number, provider?: string | undefined);
|
|
6
|
+
}
|
|
7
|
+
export declare class BudgetExceededError extends LLMKitError {
|
|
8
|
+
budgetId: string;
|
|
9
|
+
limitCents: number;
|
|
10
|
+
usedCents: number;
|
|
11
|
+
constructor(budgetId: string, limitCents: number, usedCents: number);
|
|
12
|
+
}
|
|
13
|
+
export declare class ProviderError extends LLMKitError {
|
|
14
|
+
upstreamStatus?: number | undefined;
|
|
15
|
+
constructor(message: string, provider: string, upstreamStatus?: number | undefined);
|
|
16
|
+
}
|
|
17
|
+
export declare class AllProvidersFailedError extends LLMKitError {
|
|
18
|
+
errors: ProviderError[];
|
|
19
|
+
constructor(errors: ProviderError[]);
|
|
20
|
+
}
|
|
21
|
+
export declare class AuthError extends LLMKitError {
|
|
22
|
+
constructor(message?: string);
|
|
23
|
+
}
|
|
24
|
+
export declare class ValidationError extends LLMKitError {
|
|
25
|
+
constructor(message: string);
|
|
26
|
+
}
|
|
27
|
+
export declare class RateLimitError extends LLMKitError {
|
|
28
|
+
retryAfterMs?: number | undefined;
|
|
29
|
+
constructor(retryAfterMs?: number | undefined, provider?: string);
|
|
30
|
+
}
|
|
31
|
+
export type ErrorCode = 'BUDGET_EXCEEDED' | 'PROVIDER_ERROR' | 'ALL_PROVIDERS_FAILED' | 'AUTH_ERROR' | 'RATE_LIMIT' | 'INVALID_REQUEST' | 'INTERNAL_ERROR';
|
|
32
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAY,SAAQ,KAAK;IAG3B,IAAI,EAAE,SAAS;IACf,UAAU,EAAE,MAAM;IAClB,QAAQ,CAAC,EAAE,MAAM;gBAHxB,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,SAAS,EACf,UAAU,GAAE,MAAY,EACxB,QAAQ,CAAC,EAAE,MAAM,YAAA;CAK3B;AAED,qBAAa,mBAAoB,SAAQ,WAAW;IAEzC,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,MAAM;IAClB,SAAS,EAAE,MAAM;gBAFjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM;CAS3B;AAED,qBAAa,aAAc,SAAQ,WAAW;IAInC,cAAc,CAAC,EAAE,MAAM;gBAF9B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EACT,cAAc,CAAC,EAAE,MAAM,YAAA;CAKjC;AAED,qBAAa,uBAAwB,SAAQ,WAAW;IACnC,MAAM,EAAE,aAAa,EAAE;gBAAvB,MAAM,EAAE,aAAa,EAAE;CAO3C;AAED,qBAAa,SAAU,SAAQ,WAAW;gBAC5B,OAAO,SAA+B;CAInD;AAED,qBAAa,eAAgB,SAAQ,WAAW;gBAClC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,cAAe,SAAQ,WAAW;IAEpC,YAAY,CAAC,EAAE,MAAM;gBAArB,YAAY,CAAC,EAAE,MAAM,YAAA,EAC5B,QAAQ,CAAC,EAAE,MAAM;CAKpB;AAED,MAAM,MAAM,SAAS,GACjB,iBAAiB,GACjB,gBAAgB,GAChB,sBAAsB,GACtB,YAAY,GACZ,YAAY,GACZ,iBAAiB,GACjB,gBAAgB,CAAC"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export class LLMKitError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
statusCode;
|
|
4
|
+
provider;
|
|
5
|
+
constructor(message, code, statusCode = 500, provider) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.provider = provider;
|
|
10
|
+
this.name = 'LLMKitError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class BudgetExceededError extends LLMKitError {
|
|
14
|
+
budgetId;
|
|
15
|
+
limitCents;
|
|
16
|
+
usedCents;
|
|
17
|
+
constructor(budgetId, limitCents, usedCents) {
|
|
18
|
+
super(`Budget exceeded: ${usedCents / 100}/${limitCents / 100} USD`, 'BUDGET_EXCEEDED', 402);
|
|
19
|
+
this.budgetId = budgetId;
|
|
20
|
+
this.limitCents = limitCents;
|
|
21
|
+
this.usedCents = usedCents;
|
|
22
|
+
this.name = 'BudgetExceededError';
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class ProviderError extends LLMKitError {
|
|
26
|
+
upstreamStatus;
|
|
27
|
+
constructor(message, provider, upstreamStatus) {
|
|
28
|
+
super(message, 'PROVIDER_ERROR', 502, provider);
|
|
29
|
+
this.upstreamStatus = upstreamStatus;
|
|
30
|
+
this.name = 'ProviderError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class AllProvidersFailedError extends LLMKitError {
|
|
34
|
+
errors;
|
|
35
|
+
constructor(errors) {
|
|
36
|
+
const summary = errors
|
|
37
|
+
.map((e) => `${e.provider}: ${e.message}`)
|
|
38
|
+
.join('; ');
|
|
39
|
+
super(`All providers failed: ${summary}`, 'ALL_PROVIDERS_FAILED', 503);
|
|
40
|
+
this.errors = errors;
|
|
41
|
+
this.name = 'AllProvidersFailedError';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export class AuthError extends LLMKitError {
|
|
45
|
+
constructor(message = 'Invalid or missing API key') {
|
|
46
|
+
super(message, 'AUTH_ERROR', 401);
|
|
47
|
+
this.name = 'AuthError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class ValidationError extends LLMKitError {
|
|
51
|
+
constructor(message) {
|
|
52
|
+
super(message, 'INVALID_REQUEST', 400);
|
|
53
|
+
this.name = 'ValidationError';
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export class RateLimitError extends LLMKitError {
|
|
57
|
+
retryAfterMs;
|
|
58
|
+
constructor(retryAfterMs, provider) {
|
|
59
|
+
super('Rate limit exceeded', 'RATE_LIMIT', 429, provider);
|
|
60
|
+
this.retryAfterMs = retryAfterMs;
|
|
61
|
+
this.name = 'RateLimitError';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAG3B;IACA;IACA;IAJT,YACE,OAAe,EACR,IAAe,EACf,aAAqB,GAAG,EACxB,QAAiB;QAExB,KAAK,CAAC,OAAO,CAAC,CAAC;QAJR,SAAI,GAAJ,IAAI,CAAW;QACf,eAAU,GAAV,UAAU,CAAc;QACxB,aAAQ,GAAR,QAAQ,CAAS;QAGxB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAEzC;IACA;IACA;IA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AAK,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,WAAW;IAEpC;IADT,YACS,YAAqB,EAC5B,QAAiB;QAEjB,KAAK,CAAC,qBAAqB,EAAE,YAAY,EAAE,GAAG,EAAE,QAAQ,CAAC,CAAC;QAHnD,iBAAY,GAAZ,YAAY,CAAS;QAI5B,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ProviderName } from './types.js';
|
|
2
|
+
interface ModelPricing {
|
|
3
|
+
inputPerMillion: number;
|
|
4
|
+
outputPerMillion: number;
|
|
5
|
+
cacheReadPerMillion?: number;
|
|
6
|
+
cacheWritePerMillion?: number;
|
|
7
|
+
}
|
|
8
|
+
type PricingTable = Record<string, ModelPricing>;
|
|
9
|
+
declare const PRICING: Record<ProviderName, PricingTable>;
|
|
10
|
+
export declare function getModelPricing(provider: ProviderName, model: string): ModelPricing | undefined;
|
|
11
|
+
export declare function calculateCost(provider: ProviderName, model: string, inputTokens: number, outputTokens: number, cacheReadTokens?: number, cacheWriteTokens?: number): number;
|
|
12
|
+
export { PRICING };
|
|
13
|
+
export type { ModelPricing, PricingTable };
|
|
14
|
+
//# sourceMappingURL=providers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,UAAU,YAAY;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAIjD,QAAA,MAAM,OAAO,EAAE,MAAM,CAAC,YAAY,EAAE,YAAY,CAkG/C,CAAC;AAEF,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,GACZ,YAAY,GAAG,SAAS,CAwB1B;AAED,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,YAAY,EACtB,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,eAAe,SAAI,EACnB,gBAAgB,SAAI,GACnB,MAAM,CAgBR;AAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACnB,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// last updated: 2026-02-20
|
|
2
|
+
// prices in USD per 1M tokens
|
|
3
|
+
const PRICING = {
|
|
4
|
+
anthropic: {
|
|
5
|
+
'claude-sonnet-4-20250514': {
|
|
6
|
+
inputPerMillion: 3.0,
|
|
7
|
+
outputPerMillion: 15.0,
|
|
8
|
+
cacheReadPerMillion: 0.3,
|
|
9
|
+
cacheWritePerMillion: 3.75,
|
|
10
|
+
},
|
|
11
|
+
'claude-3-5-haiku-20241022': {
|
|
12
|
+
inputPerMillion: 0.8,
|
|
13
|
+
outputPerMillion: 4.0,
|
|
14
|
+
cacheReadPerMillion: 0.08,
|
|
15
|
+
cacheWritePerMillion: 1.0,
|
|
16
|
+
},
|
|
17
|
+
'claude-3-haiku-20240307': {
|
|
18
|
+
inputPerMillion: 0.25,
|
|
19
|
+
outputPerMillion: 1.25,
|
|
20
|
+
},
|
|
21
|
+
'claude-opus-4-20250514': {
|
|
22
|
+
inputPerMillion: 15.0,
|
|
23
|
+
outputPerMillion: 75.0,
|
|
24
|
+
cacheReadPerMillion: 1.5,
|
|
25
|
+
cacheWritePerMillion: 18.75,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
openai: {
|
|
29
|
+
'gpt-4o': { inputPerMillion: 2.5, outputPerMillion: 10.0 },
|
|
30
|
+
'gpt-4o-mini': { inputPerMillion: 0.15, outputPerMillion: 0.6 },
|
|
31
|
+
'o3': { inputPerMillion: 2.0, outputPerMillion: 8.0 },
|
|
32
|
+
'o3-mini': { inputPerMillion: 1.1, outputPerMillion: 4.4 },
|
|
33
|
+
'gpt-4-turbo': { inputPerMillion: 10.0, outputPerMillion: 30.0 },
|
|
34
|
+
},
|
|
35
|
+
gemini: {
|
|
36
|
+
'gemini-2.0-flash': { inputPerMillion: 0.1, outputPerMillion: 0.4 },
|
|
37
|
+
'gemini-2.5-pro': { inputPerMillion: 1.25, outputPerMillion: 10.0 },
|
|
38
|
+
'gemini-2.5-flash': { inputPerMillion: 0.15, outputPerMillion: 0.6 },
|
|
39
|
+
},
|
|
40
|
+
groq: {
|
|
41
|
+
// mixtral-8x7b discontinued on Groq as of late 2025
|
|
42
|
+
'llama-3.3-70b-versatile': { inputPerMillion: 0.59, outputPerMillion: 0.79 },
|
|
43
|
+
'llama-3.1-8b-instant': { inputPerMillion: 0.05, outputPerMillion: 0.08 },
|
|
44
|
+
'gemma2-9b-it': { inputPerMillion: 0.20, outputPerMillion: 0.20 },
|
|
45
|
+
},
|
|
46
|
+
together: {
|
|
47
|
+
'meta-llama/Meta-Llama-3.3-70B-Instruct-Turbo': { inputPerMillion: 0.88, outputPerMillion: 0.88 },
|
|
48
|
+
'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo': { inputPerMillion: 0.18, outputPerMillion: 0.18 },
|
|
49
|
+
'Qwen/Qwen2.5-72B-Instruct-Turbo': { inputPerMillion: 1.20, outputPerMillion: 1.20 },
|
|
50
|
+
'mistralai/Mixtral-8x7B-Instruct-v0.1': { inputPerMillion: 0.60, outputPerMillion: 0.60 },
|
|
51
|
+
},
|
|
52
|
+
fireworks: {
|
|
53
|
+
// fireworks gives 50% discount on cached input automatically
|
|
54
|
+
'accounts/fireworks/models/llama-v3p3-70b-instruct': {
|
|
55
|
+
inputPerMillion: 0.90, outputPerMillion: 0.90,
|
|
56
|
+
cacheReadPerMillion: 0.45,
|
|
57
|
+
},
|
|
58
|
+
'accounts/fireworks/models/llama-v3p1-8b-instruct': {
|
|
59
|
+
inputPerMillion: 0.20, outputPerMillion: 0.20,
|
|
60
|
+
cacheReadPerMillion: 0.10,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
deepseek: {
|
|
64
|
+
// V3.2 unified pricing (Sep 2025) - both models same rate
|
|
65
|
+
// cache hits are 90% cheaper, auto-caching no config needed
|
|
66
|
+
'deepseek-chat': {
|
|
67
|
+
inputPerMillion: 0.28,
|
|
68
|
+
outputPerMillion: 0.42,
|
|
69
|
+
cacheReadPerMillion: 0.028,
|
|
70
|
+
},
|
|
71
|
+
'deepseek-reasoner': {
|
|
72
|
+
inputPerMillion: 0.28,
|
|
73
|
+
outputPerMillion: 0.42,
|
|
74
|
+
cacheReadPerMillion: 0.028,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
mistral: {
|
|
78
|
+
'mistral-large-latest': { inputPerMillion: 2.0, outputPerMillion: 6.0 },
|
|
79
|
+
'mistral-small-latest': { inputPerMillion: 0.10, outputPerMillion: 0.30 },
|
|
80
|
+
'codestral-latest': { inputPerMillion: 0.30, outputPerMillion: 0.90 },
|
|
81
|
+
},
|
|
82
|
+
xai: {
|
|
83
|
+
'grok-2': { inputPerMillion: 2.0, outputPerMillion: 10.0 },
|
|
84
|
+
'grok-3': { inputPerMillion: 3.0, outputPerMillion: 15.0 },
|
|
85
|
+
'grok-3-mini': { inputPerMillion: 0.30, outputPerMillion: 0.50 },
|
|
86
|
+
},
|
|
87
|
+
// local models - no cost
|
|
88
|
+
ollama: {},
|
|
89
|
+
// meta-gateway, pricing varies per model - tracked by underlying provider
|
|
90
|
+
openrouter: {},
|
|
91
|
+
};
|
|
92
|
+
export function getModelPricing(provider, model) {
|
|
93
|
+
const providerPricing = PRICING[provider];
|
|
94
|
+
if (!providerPricing)
|
|
95
|
+
return undefined;
|
|
96
|
+
// exact match first
|
|
97
|
+
if (providerPricing[model])
|
|
98
|
+
return providerPricing[model];
|
|
99
|
+
// prefix match for versioned models (e.g. "claude-sonnet-4" matches "claude-sonnet-4-20250514")
|
|
100
|
+
// longest match wins to avoid "gpt-4o" matching before "gpt-4o-mini"
|
|
101
|
+
let best;
|
|
102
|
+
let bestLen = 0;
|
|
103
|
+
for (const [key, pricing] of Object.entries(providerPricing)) {
|
|
104
|
+
if (model.startsWith(key) && key.length > bestLen) {
|
|
105
|
+
bestLen = key.length;
|
|
106
|
+
best = pricing;
|
|
107
|
+
}
|
|
108
|
+
if (key.startsWith(model) && model.length > bestLen) {
|
|
109
|
+
bestLen = model.length;
|
|
110
|
+
best = pricing;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return best;
|
|
114
|
+
}
|
|
115
|
+
export function calculateCost(provider, model, inputTokens, outputTokens, cacheReadTokens = 0, cacheWriteTokens = 0) {
|
|
116
|
+
const pricing = getModelPricing(provider, model);
|
|
117
|
+
if (!pricing)
|
|
118
|
+
return 0;
|
|
119
|
+
let cost = 0;
|
|
120
|
+
cost += (inputTokens / 1_000_000) * pricing.inputPerMillion;
|
|
121
|
+
cost += (outputTokens / 1_000_000) * pricing.outputPerMillion;
|
|
122
|
+
if (pricing.cacheReadPerMillion && cacheReadTokens > 0) {
|
|
123
|
+
cost += (cacheReadTokens / 1_000_000) * pricing.cacheReadPerMillion;
|
|
124
|
+
}
|
|
125
|
+
if (pricing.cacheWritePerMillion && cacheWriteTokens > 0) {
|
|
126
|
+
cost += (cacheWriteTokens / 1_000_000) * pricing.cacheWritePerMillion;
|
|
127
|
+
}
|
|
128
|
+
return cost;
|
|
129
|
+
}
|
|
130
|
+
export { PRICING };
|
|
131
|
+
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.js","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAWA,2BAA2B;AAC3B,8BAA8B;AAC9B,MAAM,OAAO,GAAuC;IAClD,SAAS,EAAE;QACT,0BAA0B,EAAE;YAC1B,eAAe,EAAE,GAAG;YACpB,gBAAgB,EAAE,IAAI;YACtB,mBAAmB,EAAE,GAAG;YACxB,oBAAoB,EAAE,IAAI;SAC3B;QACD,2BAA2B,EAAE;YAC3B,eAAe,EAAE,GAAG;YACpB,gBAAgB,EAAE,GAAG;YACrB,mBAAmB,EAAE,IAAI;YACzB,oBAAoB,EAAE,GAAG;SAC1B;QACD,yBAAyB,EAAE;YACzB,eAAe,EAAE,IAAI;YACrB,gBAAgB,EAAE,IAAI;SACvB;QACD,wBAAwB,EAAE;YACxB,eAAe,EAAE,IAAI;YACrB,gBAAgB,EAAE,IAAI;YACtB,mBAAmB,EAAE,GAAG;YACxB,oBAAoB,EAAE,KAAK;SAC5B;KACF;IAED,MAAM,EAAE;QACN,QAAQ,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE;QAC1D,aAAa,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE;QAC/D,IAAI,EAAE,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,EAAE,GAAG,EAAE;QACrD,SAAS,EAAE,E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C;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
export interface LLMRequest {
|
|
2
|
+
provider: ProviderName;
|
|
3
|
+
model: string;
|
|
4
|
+
messages: Message[];
|
|
5
|
+
stream?: boolean;
|
|
6
|
+
temperature?: number;
|
|
7
|
+
maxTokens?: number;
|
|
8
|
+
sessionId?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface LLMResponse {
|
|
11
|
+
id: string;
|
|
12
|
+
provider: ProviderName;
|
|
13
|
+
model: string;
|
|
14
|
+
content: string;
|
|
15
|
+
usage: TokenUsage;
|
|
16
|
+
cost: CostBreakdown;
|
|
17
|
+
latencyMs: number;
|
|
18
|
+
cached: boolean;
|
|
19
|
+
sessionId?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Message {
|
|
22
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
23
|
+
content: string;
|
|
24
|
+
}
|
|
25
|
+
export interface TokenUsage {
|
|
26
|
+
inputTokens: number;
|
|
27
|
+
outputTokens: number;
|
|
28
|
+
cacheReadTokens?: number;
|
|
29
|
+
cacheWriteTokens?: number;
|
|
30
|
+
totalTokens: number;
|
|
31
|
+
}
|
|
32
|
+
export interface CostBreakdown {
|
|
33
|
+
inputCost: number;
|
|
34
|
+
outputCost: number;
|
|
35
|
+
cacheReadCost?: number;
|
|
36
|
+
cacheWriteCost?: number;
|
|
37
|
+
totalCost: number;
|
|
38
|
+
currency: 'USD';
|
|
39
|
+
}
|
|
40
|
+
export interface Budget {
|
|
41
|
+
id: string;
|
|
42
|
+
keyId: string;
|
|
43
|
+
limitCents: number;
|
|
44
|
+
usedCents: number;
|
|
45
|
+
period: 'daily' | 'weekly' | 'monthly';
|
|
46
|
+
resetAt: Date;
|
|
47
|
+
scope?: 'key' | 'session';
|
|
48
|
+
}
|
|
49
|
+
export interface BudgetAlert {
|
|
50
|
+
type: 'budget.threshold';
|
|
51
|
+
budgetId: string;
|
|
52
|
+
usedCents: number;
|
|
53
|
+
limitCents: number;
|
|
54
|
+
percentage: number;
|
|
55
|
+
period: string;
|
|
56
|
+
timestamp: string;
|
|
57
|
+
}
|
|
58
|
+
export interface SessionSummary {
|
|
59
|
+
sessionId: string;
|
|
60
|
+
requestCount: number;
|
|
61
|
+
totalCost: CostBreakdown;
|
|
62
|
+
totalTokens: TokenUsage;
|
|
63
|
+
providers: ProviderName[];
|
|
64
|
+
startedAt: Date;
|
|
65
|
+
lastRequestAt: Date;
|
|
66
|
+
durationMs: number;
|
|
67
|
+
}
|
|
68
|
+
export type ProviderName = 'anthropic' | 'openai' | 'gemini' | 'groq' | 'together' | 'fireworks' | 'deepseek' | 'mistral' | 'xai' | 'ollama' | 'openrouter';
|
|
69
|
+
export interface ProviderConfig {
|
|
70
|
+
name: ProviderName;
|
|
71
|
+
apiKey: string;
|
|
72
|
+
baseUrl?: string;
|
|
73
|
+
priority: number;
|
|
74
|
+
enabled: boolean;
|
|
75
|
+
}
|
|
76
|
+
export interface FallbackConfig {
|
|
77
|
+
providers: ProviderName[];
|
|
78
|
+
retryOn: number[];
|
|
79
|
+
maxRetries: number;
|
|
80
|
+
}
|
|
81
|
+
export interface LLMKitConfig {
|
|
82
|
+
apiKey: string;
|
|
83
|
+
baseUrl?: string;
|
|
84
|
+
defaultProvider?: ProviderName;
|
|
85
|
+
fallback?: FallbackConfig;
|
|
86
|
+
sessionId?: string;
|
|
87
|
+
budgetId?: string;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,MA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,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@f3d1/llmkit-shared",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Shared types, pricing data, and constants for LLMKit packages",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"dev": "tsc --watch",
|
|
19
|
+
"typecheck": "tsc --noEmit",
|
|
20
|
+
"clean": "rm -rf dist"
|
|
21
|
+
}
|
|
22
|
+
}
|