@usagetap/sdk 1.3.2 → 1.7.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 +372 -39
- package/dist/adapters/anthropic.cjs +995 -69
- package/dist/adapters/anthropic.cjs.map +1 -1
- package/dist/adapters/anthropic.d.cts +45 -3
- package/dist/adapters/anthropic.d.ts +45 -3
- package/dist/adapters/anthropic.mjs +995 -70
- package/dist/adapters/anthropic.mjs.map +1 -1
- package/dist/adapters/openai.cjs +1208 -106
- package/dist/adapters/openai.cjs.map +1 -1
- package/dist/adapters/openai.d.cts +46 -3
- package/dist/adapters/openai.d.ts +46 -3
- package/dist/adapters/openai.mjs +1208 -107
- package/dist/adapters/openai.mjs.map +1 -1
- package/dist/adapters/openrouter.cjs +3912 -53
- package/dist/adapters/openrouter.cjs.map +1 -1
- package/dist/adapters/openrouter.d.cts +6 -3
- package/dist/adapters/openrouter.d.ts +6 -3
- package/dist/adapters/openrouter.mjs +3910 -54
- package/dist/adapters/openrouter.mjs.map +1 -1
- package/dist/anthropic/index.cjs +995 -69
- package/dist/anthropic/index.cjs.map +1 -1
- package/dist/anthropic/index.d.cts +2 -2
- package/dist/anthropic/index.d.ts +2 -2
- package/dist/anthropic/index.mjs +995 -70
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/client-C0UiaqVB.d.cts +1305 -0
- package/dist/client-C0UiaqVB.d.ts +1305 -0
- package/dist/express/index.cjs +399 -64
- package/dist/express/index.cjs.map +1 -1
- package/dist/express/index.d.cts +2 -2
- package/dist/express/index.d.ts +2 -2
- package/dist/express/index.mjs +399 -64
- package/dist/express/index.mjs.map +1 -1
- package/dist/index.cjs +1044 -163
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -5
- package/dist/index.d.ts +16 -5
- package/dist/index.mjs +1044 -163
- package/dist/index.mjs.map +1 -1
- package/dist/openai/index.cjs +1209 -107
- package/dist/openai/index.cjs.map +1 -1
- package/dist/openai/index.d.cts +2 -2
- package/dist/openai/index.d.ts +2 -2
- package/dist/openai/index.mjs +1209 -108
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openrouter/index.cjs +1226 -109
- package/dist/openrouter/index.cjs.map +1 -1
- package/dist/openrouter/index.d.cts +3 -3
- package/dist/openrouter/index.d.ts +3 -3
- package/dist/openrouter/index.mjs +1224 -108
- package/dist/openrouter/index.mjs.map +1 -1
- package/dist/react/index.cjs +19 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +17 -4
- package/dist/react/index.d.ts +17 -4
- package/dist/react/index.mjs +19 -1
- package/dist/react/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/client-BD8O2J8Z.d.cts +0 -668
- package/dist/client-BD8O2J8Z.d.ts +0 -668
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
|
-
import { B as BeginCallRequest, P as PromptCompressionProvider, U as UsageTapClient, W as WithUsageOptions,
|
|
2
|
+
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionMode, S as SamplingOptions, U as UsageTapClient, W as WithUsageOptions, b as PromptCompressionTelemetry, V as VendorHints, c as UsageTapSuccessResponse, d as BeginCallResponseBody, E as EndCallRequest } from '../client-C0UiaqVB.cjs';
|
|
3
3
|
|
|
4
4
|
interface OpenAIAdapterInit {
|
|
5
5
|
client: OpenAI;
|
|
6
6
|
usageTap: UsageTapClient;
|
|
7
|
+
/** Vendor label recorded at call_end. Defaults to `openai`. */
|
|
8
|
+
provider?: string;
|
|
7
9
|
}
|
|
8
10
|
interface OpenAIRequestContext {
|
|
9
11
|
hints?: VendorHints;
|
|
@@ -65,6 +67,14 @@ interface OpenAIPromptCompressionOptions {
|
|
|
65
67
|
/** Minimum estimated tokens for each individual text segment. */
|
|
66
68
|
minTokens?: number;
|
|
67
69
|
failOpen?: boolean;
|
|
70
|
+
/** Select deterministic-only, automatic model gating, or a forced model pass. */
|
|
71
|
+
mode?: PromptCompressionMode;
|
|
72
|
+
/** Maximum compression latency the service should target. */
|
|
73
|
+
latencyBudgetMs?: number;
|
|
74
|
+
/** Remove empty user messages before compression. */
|
|
75
|
+
compactEmptyUserMessages?: boolean;
|
|
76
|
+
/** Deduplicate repeated text parts within user messages. */
|
|
77
|
+
compactDuplicateUserTextParts?: boolean;
|
|
68
78
|
tokenCompanyModel?: string;
|
|
69
79
|
aggressiveness?: number | Partial<Record<OpenAIPromptCompressionRole, number>>;
|
|
70
80
|
/** @deprecated Use aggressiveness instead. */
|
|
@@ -74,7 +84,13 @@ interface OpenAIPromptCompressionOptions {
|
|
|
74
84
|
/** @deprecated Use aggressiveness instead. */
|
|
75
85
|
usageTapCompressionAggressiveness?: number | Partial<Record<OpenAIPromptCompressionRole, number>>;
|
|
76
86
|
}
|
|
77
|
-
interface
|
|
87
|
+
interface PromptCompressionTelemetryWithDiagnostics extends PromptCompressionTelemetry {
|
|
88
|
+
originalCharacters: number;
|
|
89
|
+
compressedCharacters: number;
|
|
90
|
+
savedCharacters: number;
|
|
91
|
+
savingsRatio: number;
|
|
92
|
+
}
|
|
93
|
+
interface OpenAIPromptCompressionTurnStats extends PromptCompressionTelemetryWithDiagnostics {
|
|
78
94
|
callId: string;
|
|
79
95
|
operation: "chat.completions.create" | "chat.completions.stream" | "responses.create";
|
|
80
96
|
messagesCompressed: number;
|
|
@@ -105,16 +121,37 @@ declare class OpenAIPromptCompressionStats {
|
|
|
105
121
|
get savingsRatio(): number;
|
|
106
122
|
}
|
|
107
123
|
interface WrapOpenAIOptions {
|
|
124
|
+
/** Vendor label recorded at call_end. Defaults to `openai`. */
|
|
125
|
+
provider?: string;
|
|
108
126
|
defaultContext?: Partial<WrapOpenAIContext>;
|
|
109
127
|
applyVendorHints?: boolean;
|
|
110
128
|
promptCompression?: boolean | OpenAIPromptCompressionOptions;
|
|
129
|
+
/** Retain eligible metered calls with an exact link to their UsageTap call. */
|
|
130
|
+
sampling?: MeteredOpenAISamplingOptions | true;
|
|
111
131
|
}
|
|
112
132
|
interface OpenAICompressionOptions extends OpenAIPromptCompressionOptions {
|
|
113
133
|
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
114
134
|
apiKey?: string;
|
|
115
135
|
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
116
136
|
usageTapClient?: UsageTapClient;
|
|
137
|
+
/** Also retain eligible calls after the provider responds. */
|
|
138
|
+
sampling?: SamplingOptions | true;
|
|
117
139
|
}
|
|
140
|
+
type OpenAISamplingOptions = Partial<SamplingOptions> & {
|
|
141
|
+
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
142
|
+
apiKey?: string;
|
|
143
|
+
/** Reuse an existing UsageTap client. */
|
|
144
|
+
usageTapClient?: UsageTapClient;
|
|
145
|
+
/** Provider label stored with each sample. */
|
|
146
|
+
provider?: string;
|
|
147
|
+
};
|
|
148
|
+
type MeteredOpenAISamplingOptions = Partial<SamplingOptions> & {
|
|
149
|
+
/** Provider label stored with each retained sample. */
|
|
150
|
+
provider?: string;
|
|
151
|
+
};
|
|
152
|
+
type SamplingWrappedOpenAI = OpenAI & {
|
|
153
|
+
unwrap: () => OpenAI;
|
|
154
|
+
};
|
|
118
155
|
type CompressionWrappedOpenAI = OpenAI & {
|
|
119
156
|
/** Return the original, unwrapped OpenAI-compatible client. */
|
|
120
157
|
unwrap: () => OpenAI;
|
|
@@ -124,8 +161,12 @@ type WithMeteringOpenAIOptions = BeginCallRequest & {
|
|
|
124
161
|
apiKey?: string;
|
|
125
162
|
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
126
163
|
usageTapClient?: UsageTapClient;
|
|
164
|
+
/** Vendor label recorded at call_end. Defaults to `openai`. */
|
|
165
|
+
provider?: string;
|
|
127
166
|
applyVendorHints?: boolean;
|
|
128
167
|
promptCompression?: boolean | OpenAIPromptCompressionOptions;
|
|
168
|
+
/** Retain eligible calls using the same ID as the metered UsageTap call. */
|
|
169
|
+
sampling?: MeteredOpenAISamplingOptions | true;
|
|
129
170
|
};
|
|
130
171
|
type ChatCompletionsResource = OpenAI["chat"]["completions"];
|
|
131
172
|
type ChatCompletionCreate = ChatCompletionsResource["create"];
|
|
@@ -208,6 +249,8 @@ type UsageTapStream<T> = AsyncIterable<T> & {
|
|
|
208
249
|
};
|
|
209
250
|
declare function toNextResponse<T>(stream: UsageTapStream<T>, options?: StreamToResponseOptions): Response;
|
|
210
251
|
declare function pipeToResponse<T>(stream: UsageTapStream<T>, res: NodeResponseLike, options?: StreamToResponseOptions): Promise<void>;
|
|
252
|
+
/** Retain locally-selected OpenAI-compatible calls without changing call sites. */
|
|
253
|
+
declare function withSampling(client: OpenAI, options?: OpenAISamplingOptions): SamplingWrappedOpenAI;
|
|
211
254
|
/**
|
|
212
255
|
* Add hosted prompt compression to an OpenAI-compatible client without
|
|
213
256
|
* changing any of its call sites. Works with OpenAI and OpenRouter clients.
|
|
@@ -231,4 +274,4 @@ interface NodeResponseLike {
|
|
|
231
274
|
flush?(): void;
|
|
232
275
|
}
|
|
233
276
|
|
|
234
|
-
export { type CompressionWrappedOpenAI, type NodeResponseLike, type OpenAIAdapter, type OpenAIAdapterInit, type OpenAICompressionOptions, type OpenAIInvokeParams, type OpenAIInvokeResult, type OpenAIPromptCompressionFailure, type OpenAIPromptCompressionOptions, type OpenAIPromptCompressionRole, type OpenAIPromptCompressionRoleOptions, type OpenAIPromptCompressionRoleSetting, OpenAIPromptCompressionStats, type OpenAIPromptCompressionTurnStats, type OpenAIRequestContext, type OpenAIStreamCallResult, type OpenAIStreamParams, type OpenAIStreamResult, type StreamMode, type StreamOpenAIRouteOptions, type StreamToResponseOptions, type UsageTapStream, type WithMeteringOpenAIOptions, type WrapOpenAICallOptions, type WrapOpenAIContext, type WrapOpenAIOptions, type WrapOpenAIResponseCallOptions, type WrappedOpenAI, createOpenAIAdapter, pipeToResponse, streamOpenAIRoute, toNextResponse, withCompression, withMetering, wrapOpenAI };
|
|
277
|
+
export { type CompressionWrappedOpenAI, type MeteredOpenAISamplingOptions, type NodeResponseLike, type OpenAIAdapter, type OpenAIAdapterInit, type OpenAICompressionOptions, type OpenAIInvokeParams, type OpenAIInvokeResult, type OpenAIPromptCompressionFailure, type OpenAIPromptCompressionOptions, type OpenAIPromptCompressionRole, type OpenAIPromptCompressionRoleOptions, type OpenAIPromptCompressionRoleSetting, OpenAIPromptCompressionStats, type OpenAIPromptCompressionTurnStats, type OpenAIRequestContext, type OpenAISamplingOptions, type OpenAIStreamCallResult, type OpenAIStreamParams, type OpenAIStreamResult, type SamplingWrappedOpenAI, type StreamMode, type StreamOpenAIRouteOptions, type StreamToResponseOptions, type UsageTapStream, type WithMeteringOpenAIOptions, type WrapOpenAICallOptions, type WrapOpenAIContext, type WrapOpenAIOptions, type WrapOpenAIResponseCallOptions, type WrappedOpenAI, createOpenAIAdapter, pipeToResponse, streamOpenAIRoute, toNextResponse, withCompression, withMetering, withSampling, wrapOpenAI };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
|
-
import { B as BeginCallRequest, P as PromptCompressionProvider, U as UsageTapClient, W as WithUsageOptions,
|
|
2
|
+
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionMode, S as SamplingOptions, U as UsageTapClient, W as WithUsageOptions, b as PromptCompressionTelemetry, V as VendorHints, c as UsageTapSuccessResponse, d as BeginCallResponseBody, E as EndCallRequest } from '../client-C0UiaqVB.js';
|
|
3
3
|
|
|
4
4
|
interface OpenAIAdapterInit {
|
|
5
5
|
client: OpenAI;
|
|
6
6
|
usageTap: UsageTapClient;
|
|
7
|
+
/** Vendor label recorded at call_end. Defaults to `openai`. */
|
|
8
|
+
provider?: string;
|
|
7
9
|
}
|
|
8
10
|
interface OpenAIRequestContext {
|
|
9
11
|
hints?: VendorHints;
|
|
@@ -65,6 +67,14 @@ interface OpenAIPromptCompressionOptions {
|
|
|
65
67
|
/** Minimum estimated tokens for each individual text segment. */
|
|
66
68
|
minTokens?: number;
|
|
67
69
|
failOpen?: boolean;
|
|
70
|
+
/** Select deterministic-only, automatic model gating, or a forced model pass. */
|
|
71
|
+
mode?: PromptCompressionMode;
|
|
72
|
+
/** Maximum compression latency the service should target. */
|
|
73
|
+
latencyBudgetMs?: number;
|
|
74
|
+
/** Remove empty user messages before compression. */
|
|
75
|
+
compactEmptyUserMessages?: boolean;
|
|
76
|
+
/** Deduplicate repeated text parts within user messages. */
|
|
77
|
+
compactDuplicateUserTextParts?: boolean;
|
|
68
78
|
tokenCompanyModel?: string;
|
|
69
79
|
aggressiveness?: number | Partial<Record<OpenAIPromptCompressionRole, number>>;
|
|
70
80
|
/** @deprecated Use aggressiveness instead. */
|
|
@@ -74,7 +84,13 @@ interface OpenAIPromptCompressionOptions {
|
|
|
74
84
|
/** @deprecated Use aggressiveness instead. */
|
|
75
85
|
usageTapCompressionAggressiveness?: number | Partial<Record<OpenAIPromptCompressionRole, number>>;
|
|
76
86
|
}
|
|
77
|
-
interface
|
|
87
|
+
interface PromptCompressionTelemetryWithDiagnostics extends PromptCompressionTelemetry {
|
|
88
|
+
originalCharacters: number;
|
|
89
|
+
compressedCharacters: number;
|
|
90
|
+
savedCharacters: number;
|
|
91
|
+
savingsRatio: number;
|
|
92
|
+
}
|
|
93
|
+
interface OpenAIPromptCompressionTurnStats extends PromptCompressionTelemetryWithDiagnostics {
|
|
78
94
|
callId: string;
|
|
79
95
|
operation: "chat.completions.create" | "chat.completions.stream" | "responses.create";
|
|
80
96
|
messagesCompressed: number;
|
|
@@ -105,16 +121,37 @@ declare class OpenAIPromptCompressionStats {
|
|
|
105
121
|
get savingsRatio(): number;
|
|
106
122
|
}
|
|
107
123
|
interface WrapOpenAIOptions {
|
|
124
|
+
/** Vendor label recorded at call_end. Defaults to `openai`. */
|
|
125
|
+
provider?: string;
|
|
108
126
|
defaultContext?: Partial<WrapOpenAIContext>;
|
|
109
127
|
applyVendorHints?: boolean;
|
|
110
128
|
promptCompression?: boolean | OpenAIPromptCompressionOptions;
|
|
129
|
+
/** Retain eligible metered calls with an exact link to their UsageTap call. */
|
|
130
|
+
sampling?: MeteredOpenAISamplingOptions | true;
|
|
111
131
|
}
|
|
112
132
|
interface OpenAICompressionOptions extends OpenAIPromptCompressionOptions {
|
|
113
133
|
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
114
134
|
apiKey?: string;
|
|
115
135
|
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
116
136
|
usageTapClient?: UsageTapClient;
|
|
137
|
+
/** Also retain eligible calls after the provider responds. */
|
|
138
|
+
sampling?: SamplingOptions | true;
|
|
117
139
|
}
|
|
140
|
+
type OpenAISamplingOptions = Partial<SamplingOptions> & {
|
|
141
|
+
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
142
|
+
apiKey?: string;
|
|
143
|
+
/** Reuse an existing UsageTap client. */
|
|
144
|
+
usageTapClient?: UsageTapClient;
|
|
145
|
+
/** Provider label stored with each sample. */
|
|
146
|
+
provider?: string;
|
|
147
|
+
};
|
|
148
|
+
type MeteredOpenAISamplingOptions = Partial<SamplingOptions> & {
|
|
149
|
+
/** Provider label stored with each retained sample. */
|
|
150
|
+
provider?: string;
|
|
151
|
+
};
|
|
152
|
+
type SamplingWrappedOpenAI = OpenAI & {
|
|
153
|
+
unwrap: () => OpenAI;
|
|
154
|
+
};
|
|
118
155
|
type CompressionWrappedOpenAI = OpenAI & {
|
|
119
156
|
/** Return the original, unwrapped OpenAI-compatible client. */
|
|
120
157
|
unwrap: () => OpenAI;
|
|
@@ -124,8 +161,12 @@ type WithMeteringOpenAIOptions = BeginCallRequest & {
|
|
|
124
161
|
apiKey?: string;
|
|
125
162
|
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
126
163
|
usageTapClient?: UsageTapClient;
|
|
164
|
+
/** Vendor label recorded at call_end. Defaults to `openai`. */
|
|
165
|
+
provider?: string;
|
|
127
166
|
applyVendorHints?: boolean;
|
|
128
167
|
promptCompression?: boolean | OpenAIPromptCompressionOptions;
|
|
168
|
+
/** Retain eligible calls using the same ID as the metered UsageTap call. */
|
|
169
|
+
sampling?: MeteredOpenAISamplingOptions | true;
|
|
129
170
|
};
|
|
130
171
|
type ChatCompletionsResource = OpenAI["chat"]["completions"];
|
|
131
172
|
type ChatCompletionCreate = ChatCompletionsResource["create"];
|
|
@@ -208,6 +249,8 @@ type UsageTapStream<T> = AsyncIterable<T> & {
|
|
|
208
249
|
};
|
|
209
250
|
declare function toNextResponse<T>(stream: UsageTapStream<T>, options?: StreamToResponseOptions): Response;
|
|
210
251
|
declare function pipeToResponse<T>(stream: UsageTapStream<T>, res: NodeResponseLike, options?: StreamToResponseOptions): Promise<void>;
|
|
252
|
+
/** Retain locally-selected OpenAI-compatible calls without changing call sites. */
|
|
253
|
+
declare function withSampling(client: OpenAI, options?: OpenAISamplingOptions): SamplingWrappedOpenAI;
|
|
211
254
|
/**
|
|
212
255
|
* Add hosted prompt compression to an OpenAI-compatible client without
|
|
213
256
|
* changing any of its call sites. Works with OpenAI and OpenRouter clients.
|
|
@@ -231,4 +274,4 @@ interface NodeResponseLike {
|
|
|
231
274
|
flush?(): void;
|
|
232
275
|
}
|
|
233
276
|
|
|
234
|
-
export { type CompressionWrappedOpenAI, type NodeResponseLike, type OpenAIAdapter, type OpenAIAdapterInit, type OpenAICompressionOptions, type OpenAIInvokeParams, type OpenAIInvokeResult, type OpenAIPromptCompressionFailure, type OpenAIPromptCompressionOptions, type OpenAIPromptCompressionRole, type OpenAIPromptCompressionRoleOptions, type OpenAIPromptCompressionRoleSetting, OpenAIPromptCompressionStats, type OpenAIPromptCompressionTurnStats, type OpenAIRequestContext, type OpenAIStreamCallResult, type OpenAIStreamParams, type OpenAIStreamResult, type StreamMode, type StreamOpenAIRouteOptions, type StreamToResponseOptions, type UsageTapStream, type WithMeteringOpenAIOptions, type WrapOpenAICallOptions, type WrapOpenAIContext, type WrapOpenAIOptions, type WrapOpenAIResponseCallOptions, type WrappedOpenAI, createOpenAIAdapter, pipeToResponse, streamOpenAIRoute, toNextResponse, withCompression, withMetering, wrapOpenAI };
|
|
277
|
+
export { type CompressionWrappedOpenAI, type MeteredOpenAISamplingOptions, type NodeResponseLike, type OpenAIAdapter, type OpenAIAdapterInit, type OpenAICompressionOptions, type OpenAIInvokeParams, type OpenAIInvokeResult, type OpenAIPromptCompressionFailure, type OpenAIPromptCompressionOptions, type OpenAIPromptCompressionRole, type OpenAIPromptCompressionRoleOptions, type OpenAIPromptCompressionRoleSetting, OpenAIPromptCompressionStats, type OpenAIPromptCompressionTurnStats, type OpenAIRequestContext, type OpenAISamplingOptions, type OpenAIStreamCallResult, type OpenAIStreamParams, type OpenAIStreamResult, type SamplingWrappedOpenAI, type StreamMode, type StreamOpenAIRouteOptions, type StreamToResponseOptions, type UsageTapStream, type WithMeteringOpenAIOptions, type WrapOpenAICallOptions, type WrapOpenAIContext, type WrapOpenAIOptions, type WrapOpenAIResponseCallOptions, type WrappedOpenAI, createOpenAIAdapter, pipeToResponse, streamOpenAIRoute, toNextResponse, withCompression, withMetering, withSampling, wrapOpenAI };
|