@jeffusion/bungee-llms 3.2.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1139 -10
- package/dist/plugin-api.d.ts +2 -0
- package/dist/plugin-api.js +1124 -10
- package/dist/token-accounting/capabilities.d.ts +47 -0
- package/dist/token-accounting/helpers.d.ts +16 -0
- package/dist/token-accounting/index.d.ts +4 -0
- package/dist/token-accounting/session.d.ts +2 -0
- package/dist/token-accounting/types.d.ts +96 -0
- package/package.json +2 -2
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { LLMProvider } from '../core/types';
|
|
2
|
+
import type { ProviderTokenAccountingCapabilities } from './types';
|
|
3
|
+
export declare const PROVIDER_TOKEN_ACCOUNTING_CAPABILITY_MATRIX: {
|
|
4
|
+
readonly openai: {
|
|
5
|
+
readonly provider: "openai";
|
|
6
|
+
readonly supportsOfficialResponseUsage: true;
|
|
7
|
+
readonly supportsStreamingResponseUsage: true;
|
|
8
|
+
readonly supportsDedicatedCountEndpoint: true;
|
|
9
|
+
readonly supportsLocalTokenizer: true;
|
|
10
|
+
readonly supportsHeuristicFallback: true;
|
|
11
|
+
readonly dedicatedCountEndpoint: {
|
|
12
|
+
readonly supported: true;
|
|
13
|
+
readonly mode: "input_estimate_only";
|
|
14
|
+
readonly defaultEnabled: false;
|
|
15
|
+
readonly endpoint: "/responses/input_tokens";
|
|
16
|
+
readonly livePathAuthority: false;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
readonly anthropic: {
|
|
20
|
+
readonly provider: "anthropic";
|
|
21
|
+
readonly supportsOfficialResponseUsage: true;
|
|
22
|
+
readonly supportsStreamingResponseUsage: true;
|
|
23
|
+
readonly supportsDedicatedCountEndpoint: true;
|
|
24
|
+
readonly supportsLocalTokenizer: true;
|
|
25
|
+
readonly supportsHeuristicFallback: true;
|
|
26
|
+
readonly dedicatedCountEndpoint: {
|
|
27
|
+
readonly supported: true;
|
|
28
|
+
readonly mode: "input_estimate_only";
|
|
29
|
+
readonly livePathAuthority: false;
|
|
30
|
+
readonly endpoint: "/v1/messages/count_tokens";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
readonly gemini: {
|
|
34
|
+
readonly provider: "gemini";
|
|
35
|
+
readonly supportsOfficialResponseUsage: true;
|
|
36
|
+
readonly supportsStreamingResponseUsage: true;
|
|
37
|
+
readonly supportsDedicatedCountEndpoint: true;
|
|
38
|
+
readonly supportsLocalTokenizer: true;
|
|
39
|
+
readonly supportsHeuristicFallback: true;
|
|
40
|
+
readonly countTokens: {
|
|
41
|
+
readonly supported: true;
|
|
42
|
+
readonly mode: "input_estimate_only";
|
|
43
|
+
readonly livePathAuthority: false;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export declare function getProviderTokenAccountingCapabilities(provider: LLMProvider): ProviderTokenAccountingCapabilities;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CanonicalTokenAccountingEventV2, TokenAccountingOutcome, TokenAccountingSessionState } from './types';
|
|
2
|
+
type JsonRecord = Record<string, unknown>;
|
|
3
|
+
export declare function isRecord(value: unknown): value is JsonRecord;
|
|
4
|
+
export declare function asString(value: unknown): string | undefined;
|
|
5
|
+
export declare function asFiniteNumber(value: unknown): number | undefined;
|
|
6
|
+
export declare function readNumber(record: JsonRecord | undefined, key: string): number | undefined;
|
|
7
|
+
export declare function readRecord(record: JsonRecord | undefined, key: string): JsonRecord | undefined;
|
|
8
|
+
export declare function countTextTokens(text: string): number;
|
|
9
|
+
export declare function countModelTextTokens(text: string, model?: string): number;
|
|
10
|
+
export declare function countJsonLikeTokens(value: unknown): number;
|
|
11
|
+
export declare function clampTokens(value: number | undefined): number | undefined;
|
|
12
|
+
export declare function buildBaseEvent(state: TokenAccountingSessionState, overrides: Partial<CanonicalTokenAccountingEventV2>): CanonicalTokenAccountingEventV2;
|
|
13
|
+
export declare function createPartialTokenAccountingEvent(state: TokenAccountingSessionState, overrides?: Partial<CanonicalTokenAccountingEventV2>): CanonicalTokenAccountingEventV2;
|
|
14
|
+
export declare function finalizeTokenAccountingEvent(state: TokenAccountingSessionState, overrides?: Partial<CanonicalTokenAccountingEventV2>, outcome?: TokenAccountingOutcome): CanonicalTokenAccountingEventV2;
|
|
15
|
+
export declare function assertCanonicalTokenAccountingEventV2(event: unknown): asserts event is CanonicalTokenAccountingEventV2;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { LLMProvider } from '../core/types';
|
|
2
|
+
export declare const SUPPORTED_TOKEN_ACCOUNTING_PROVIDERS: readonly ["openai", "anthropic", "gemini"];
|
|
3
|
+
export type SupportedTokenAccountingProvider = typeof SUPPORTED_TOKEN_ACCOUNTING_PROVIDERS[number];
|
|
4
|
+
export declare const TOKEN_ACCOUNTING_AUTHORITIES: readonly ["official", "local", "heuristic", "partial", "none"];
|
|
5
|
+
export declare const TOKEN_ACCOUNTING_OUTCOMES: readonly ["completed", "aborted", "failed"];
|
|
6
|
+
export type TokenAccountingAuthority = typeof TOKEN_ACCOUNTING_AUTHORITIES[number];
|
|
7
|
+
export type TokenAccountingOutcome = typeof TOKEN_ACCOUNTING_OUTCOMES[number];
|
|
8
|
+
export interface CanonicalTokenAccountingEventV2 {
|
|
9
|
+
requestId: string;
|
|
10
|
+
attemptId: string;
|
|
11
|
+
routeId: string;
|
|
12
|
+
upstreamId: string;
|
|
13
|
+
provider: LLMProvider;
|
|
14
|
+
model: string;
|
|
15
|
+
streaming: boolean;
|
|
16
|
+
inputTokens?: number;
|
|
17
|
+
outputTokens?: number;
|
|
18
|
+
cacheReadTokens?: number;
|
|
19
|
+
cacheWriteTokens?: number;
|
|
20
|
+
inputAuthority: TokenAccountingAuthority;
|
|
21
|
+
outputAuthority: TokenAccountingAuthority;
|
|
22
|
+
final: boolean;
|
|
23
|
+
outcome: TokenAccountingOutcome;
|
|
24
|
+
countedAt: string;
|
|
25
|
+
}
|
|
26
|
+
export interface TokenAccountingSessionInput {
|
|
27
|
+
provider: LLMProvider;
|
|
28
|
+
model?: string;
|
|
29
|
+
routeId: string;
|
|
30
|
+
upstreamId: string;
|
|
31
|
+
requestId: string;
|
|
32
|
+
attemptId: string;
|
|
33
|
+
streaming: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface TokenAccountingRequestInput {
|
|
36
|
+
body: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
export interface TokenAccountingResponseInput {
|
|
39
|
+
body: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
export interface TokenAccountingStreamChunkInput {
|
|
42
|
+
chunk: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
export interface TokenAccountingSession {
|
|
45
|
+
consumeRequest(input: TokenAccountingRequestInput): void;
|
|
46
|
+
consumeResponse(input: TokenAccountingResponseInput): CanonicalTokenAccountingEventV2;
|
|
47
|
+
consumeStreamChunk(input: TokenAccountingStreamChunkInput): CanonicalTokenAccountingEventV2 | null;
|
|
48
|
+
finalizeAbortedStream(): CanonicalTokenAccountingEventV2;
|
|
49
|
+
}
|
|
50
|
+
export interface DedicatedCountEndpointCapability {
|
|
51
|
+
supported: boolean;
|
|
52
|
+
mode: 'input_estimate_only';
|
|
53
|
+
livePathAuthority: false;
|
|
54
|
+
defaultEnabled?: false;
|
|
55
|
+
endpoint?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface ProviderTokenAccountingCapabilities {
|
|
58
|
+
provider: SupportedTokenAccountingProvider;
|
|
59
|
+
supportsOfficialResponseUsage: boolean;
|
|
60
|
+
supportsStreamingResponseUsage: boolean;
|
|
61
|
+
supportsDedicatedCountEndpoint: boolean;
|
|
62
|
+
supportsLocalTokenizer: boolean;
|
|
63
|
+
supportsHeuristicFallback: boolean;
|
|
64
|
+
dedicatedCountEndpoint?: DedicatedCountEndpointCapability;
|
|
65
|
+
countTokens?: {
|
|
66
|
+
supported: boolean;
|
|
67
|
+
mode: 'input_estimate_only';
|
|
68
|
+
livePathAuthority: false;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export type ProviderTokenAccountingCapabilityMatrix = Record<SupportedTokenAccountingProvider, ProviderTokenAccountingCapabilities>;
|
|
72
|
+
export interface TokenAccountingSessionState {
|
|
73
|
+
provider: LLMProvider;
|
|
74
|
+
routeId: string;
|
|
75
|
+
upstreamId: string;
|
|
76
|
+
requestId: string;
|
|
77
|
+
attemptId: string;
|
|
78
|
+
streaming: boolean;
|
|
79
|
+
model?: string;
|
|
80
|
+
requestBody?: Record<string, unknown>;
|
|
81
|
+
estimatedInputTokens?: number;
|
|
82
|
+
estimatedInputAuthority?: TokenAccountingAuthority;
|
|
83
|
+
outputTokens?: number;
|
|
84
|
+
outputAuthority?: TokenAccountingAuthority;
|
|
85
|
+
cacheReadTokens?: number;
|
|
86
|
+
cacheWriteTokens?: number;
|
|
87
|
+
finalReceived: boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface ProviderTokenAccountingAdapter {
|
|
90
|
+
readonly provider: LLMProvider;
|
|
91
|
+
readonly capabilities: ProviderTokenAccountingCapabilities;
|
|
92
|
+
consumeRequest(state: TokenAccountingSessionState, body: Record<string, unknown>): void;
|
|
93
|
+
consumeResponse(state: TokenAccountingSessionState, body: Record<string, unknown>): CanonicalTokenAccountingEventV2;
|
|
94
|
+
consumeStreamChunk(state: TokenAccountingSessionState, chunk: Record<string, unknown>): CanonicalTokenAccountingEventV2 | null;
|
|
95
|
+
finalizeAbortedStream(state: TokenAccountingSessionState): CanonicalTokenAccountingEventV2;
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffusion/bungee-llms",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Extensible LLM adapters and protocol conversion package for Bungee",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"prepublishOnly": "bun run build"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@jeffusion/bungee-types": "^3.
|
|
14
|
+
"@jeffusion/bungee-types": "^3.3.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"bun-types": "^1.3.2",
|