@usagetap/sdk 1.3.2 → 1.4.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 +219 -24
- package/dist/adapters/anthropic.cjs +990 -24
- 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 +990 -25
- package/dist/adapters/anthropic.mjs.map +1 -1
- package/dist/adapters/openai.cjs +1164 -44
- 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 +1164 -45
- package/dist/adapters/openai.mjs.map +1 -1
- package/dist/adapters/openrouter.cjs +3899 -22
- 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 +3897 -23
- package/dist/adapters/openrouter.mjs.map +1 -1
- package/dist/anthropic/index.cjs +990 -24
- 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 +990 -25
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/client-CExQ8e1T.d.cts +1225 -0
- package/dist/client-CExQ8e1T.d.ts +1225 -0
- package/dist/express/index.cjs +421 -29
- 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 +421 -29
- package/dist/express/index.mjs.map +1 -1
- package/dist/index.cjs +680 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.mjs +680 -15
- package/dist/index.mjs.map +1 -1
- package/dist/openai/index.cjs +1165 -45
- 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 +1165 -46
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openrouter/index.cjs +1182 -47
- 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 +1180 -46
- 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 +1 -1
- package/dist/client-BD8O2J8Z.d.cts +0 -668
- package/dist/client-BD8O2J8Z.d.ts +0 -668
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionTelemetry, U as UsageTapClient, W as WithUsageOptions } from '../client-
|
|
1
|
+
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionMode, b as PromptCompressionTelemetry, S as SamplingOptions, U as UsageTapClient, W as WithUsageOptions } from '../client-CExQ8e1T.cjs';
|
|
2
2
|
|
|
3
3
|
type WrapAnthropicContext = BeginCallRequest;
|
|
4
4
|
type AnthropicPromptCompressionRole = "system" | "user" | "tool" | "assistant";
|
|
@@ -25,6 +25,14 @@ interface AnthropicPromptCompressionOptions {
|
|
|
25
25
|
/** Minimum estimated tokens for each individual text segment. */
|
|
26
26
|
minTokens?: number;
|
|
27
27
|
failOpen?: boolean;
|
|
28
|
+
/** Select deterministic-only, automatic model gating, or a forced model pass. */
|
|
29
|
+
mode?: PromptCompressionMode;
|
|
30
|
+
/** Maximum compression latency the service should target. */
|
|
31
|
+
latencyBudgetMs?: number;
|
|
32
|
+
/** Remove empty user messages before compression. */
|
|
33
|
+
compactEmptyUserMessages?: boolean;
|
|
34
|
+
/** Deduplicate repeated text parts within user messages. */
|
|
35
|
+
compactDuplicateUserTextParts?: boolean;
|
|
28
36
|
tokenCompanyModel?: string;
|
|
29
37
|
aggressiveness?: number | Partial<Record<AnthropicPromptCompressionRole, number>>;
|
|
30
38
|
/** @deprecated Use aggressiveness instead. */
|
|
@@ -41,7 +49,13 @@ interface AnthropicPromptCompressionFailure {
|
|
|
41
49
|
message: string;
|
|
42
50
|
timestamp: number;
|
|
43
51
|
}
|
|
44
|
-
interface
|
|
52
|
+
interface PromptCompressionTelemetryWithDiagnostics extends PromptCompressionTelemetry {
|
|
53
|
+
originalCharacters: number;
|
|
54
|
+
compressedCharacters: number;
|
|
55
|
+
savedCharacters: number;
|
|
56
|
+
savingsRatio: number;
|
|
57
|
+
}
|
|
58
|
+
interface AnthropicPromptCompressionTurnStats extends PromptCompressionTelemetryWithDiagnostics {
|
|
45
59
|
callId: string;
|
|
46
60
|
operation: "messages.create";
|
|
47
61
|
messagesCompressed: number;
|
|
@@ -68,13 +82,37 @@ interface WrapAnthropicOptions {
|
|
|
68
82
|
defaultContext?: Partial<WrapAnthropicContext>;
|
|
69
83
|
applyVendorHints?: boolean;
|
|
70
84
|
promptCompression?: boolean | AnthropicPromptCompressionOptions;
|
|
85
|
+
/** Retain eligible metered calls with an exact link to their UsageTap call. */
|
|
86
|
+
sampling?: MeteredAnthropicSamplingOptions | true;
|
|
71
87
|
}
|
|
72
88
|
interface AnthropicCompressionOptions extends AnthropicPromptCompressionOptions {
|
|
73
89
|
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
74
90
|
apiKey?: string;
|
|
75
91
|
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
76
92
|
usageTapClient?: UsageTapClient;
|
|
93
|
+
/** Also retain eligible calls after the provider responds. */
|
|
94
|
+
sampling?: SamplingOptions | true;
|
|
95
|
+
}
|
|
96
|
+
type AnthropicSamplingOptions = Partial<SamplingOptions> & {
|
|
97
|
+
apiKey?: string;
|
|
98
|
+
usageTapClient?: UsageTapClient;
|
|
99
|
+
};
|
|
100
|
+
type MeteredAnthropicSamplingOptions = Partial<SamplingOptions>;
|
|
101
|
+
interface AnthropicSamplingContext {
|
|
102
|
+
customerId?: string;
|
|
103
|
+
feature?: string;
|
|
104
|
+
environment?: string;
|
|
105
|
+
tags?: string[];
|
|
77
106
|
}
|
|
107
|
+
type SamplingAnthropicCreate<TCreate> = TCreate extends (params: infer TParams, options?: infer TOptions) => infer TReturn ? (params: TParams, options?: TOptions & {
|
|
108
|
+
usageTap?: AnthropicSamplingContext;
|
|
109
|
+
}) => TReturn : never;
|
|
110
|
+
type SamplingWrappedAnthropic<TClient extends AnthropicClientLike = AnthropicClientLike> = Omit<TClient, "messages"> & {
|
|
111
|
+
messages: Omit<TClient["messages"], "create"> & {
|
|
112
|
+
create: SamplingAnthropicCreate<TClient["messages"]["create"]>;
|
|
113
|
+
};
|
|
114
|
+
unwrap: () => TClient;
|
|
115
|
+
};
|
|
78
116
|
type WithMeteringAnthropicOptions = BeginCallRequest & {
|
|
79
117
|
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
80
118
|
apiKey?: string;
|
|
@@ -82,6 +120,8 @@ type WithMeteringAnthropicOptions = BeginCallRequest & {
|
|
|
82
120
|
usageTapClient?: UsageTapClient;
|
|
83
121
|
applyVendorHints?: boolean;
|
|
84
122
|
promptCompression?: boolean | AnthropicPromptCompressionOptions;
|
|
123
|
+
/** Retain eligible calls using the same ID as the metered UsageTap call. */
|
|
124
|
+
sampling?: MeteredAnthropicSamplingOptions | true;
|
|
85
125
|
};
|
|
86
126
|
interface WrapAnthropicCallOptions {
|
|
87
127
|
usageTap?: Partial<WrapAnthropicContext>;
|
|
@@ -109,10 +149,12 @@ type CompressionWrappedAnthropic<TClient extends AnthropicClientLike = Anthropic
|
|
|
109
149
|
unwrap: () => TClient;
|
|
110
150
|
};
|
|
111
151
|
type AnthropicMessagesCreateParams = Record<string, unknown>;
|
|
152
|
+
/** Retain locally-selected Anthropic calls without changing call sites. */
|
|
153
|
+
declare function withSampling<TClient extends AnthropicClientLike>(client: TClient, options?: AnthropicSamplingOptions): SamplingWrappedAnthropic<TClient>;
|
|
112
154
|
/** Add hosted prompt compression while preserving the Anthropic client API. */
|
|
113
155
|
declare function withCompression<TClient extends AnthropicClientLike>(client: TClient, options?: AnthropicCompressionOptions): CompressionWrappedAnthropic<TClient>;
|
|
114
156
|
/** Add UsageTap metering while preserving the Anthropic client API. */
|
|
115
157
|
declare function withMetering<TClient extends AnthropicClientLike>(client: TClient, customer: string | WithMeteringAnthropicOptions): WrappedAnthropic<TClient>;
|
|
116
158
|
declare function wrapAnthropic<TClient extends AnthropicClientLike>(client: TClient, usageTap: UsageTapClient, options?: WrapAnthropicOptions): WrappedAnthropic<TClient>;
|
|
117
159
|
|
|
118
|
-
export { type AnthropicClientLike, type AnthropicCompressionOptions, type AnthropicPromptCompressionFailure, type AnthropicPromptCompressionOptions, type AnthropicPromptCompressionRole, type AnthropicPromptCompressionRoleOptions, type AnthropicPromptCompressionRoleSetting, AnthropicPromptCompressionStats, type AnthropicPromptCompressionTurnStats, type CompressionWrappedAnthropic, type WithMeteringAnthropicOptions, type WrapAnthropicCallOptions, type WrapAnthropicContext, type WrapAnthropicOptions, type WrappedAnthropic, withCompression, withMetering, wrapAnthropic };
|
|
160
|
+
export { type AnthropicClientLike, type AnthropicCompressionOptions, type AnthropicPromptCompressionFailure, type AnthropicPromptCompressionOptions, type AnthropicPromptCompressionRole, type AnthropicPromptCompressionRoleOptions, type AnthropicPromptCompressionRoleSetting, AnthropicPromptCompressionStats, type AnthropicPromptCompressionTurnStats, type AnthropicSamplingContext, type AnthropicSamplingOptions, type CompressionWrappedAnthropic, type MeteredAnthropicSamplingOptions, type SamplingWrappedAnthropic, type WithMeteringAnthropicOptions, type WrapAnthropicCallOptions, type WrapAnthropicContext, type WrapAnthropicOptions, type WrappedAnthropic, withCompression, withMetering, withSampling, wrapAnthropic };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionTelemetry, U as UsageTapClient, W as WithUsageOptions } from '../client-
|
|
1
|
+
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionMode, b as PromptCompressionTelemetry, S as SamplingOptions, U as UsageTapClient, W as WithUsageOptions } from '../client-CExQ8e1T.js';
|
|
2
2
|
|
|
3
3
|
type WrapAnthropicContext = BeginCallRequest;
|
|
4
4
|
type AnthropicPromptCompressionRole = "system" | "user" | "tool" | "assistant";
|
|
@@ -25,6 +25,14 @@ interface AnthropicPromptCompressionOptions {
|
|
|
25
25
|
/** Minimum estimated tokens for each individual text segment. */
|
|
26
26
|
minTokens?: number;
|
|
27
27
|
failOpen?: boolean;
|
|
28
|
+
/** Select deterministic-only, automatic model gating, or a forced model pass. */
|
|
29
|
+
mode?: PromptCompressionMode;
|
|
30
|
+
/** Maximum compression latency the service should target. */
|
|
31
|
+
latencyBudgetMs?: number;
|
|
32
|
+
/** Remove empty user messages before compression. */
|
|
33
|
+
compactEmptyUserMessages?: boolean;
|
|
34
|
+
/** Deduplicate repeated text parts within user messages. */
|
|
35
|
+
compactDuplicateUserTextParts?: boolean;
|
|
28
36
|
tokenCompanyModel?: string;
|
|
29
37
|
aggressiveness?: number | Partial<Record<AnthropicPromptCompressionRole, number>>;
|
|
30
38
|
/** @deprecated Use aggressiveness instead. */
|
|
@@ -41,7 +49,13 @@ interface AnthropicPromptCompressionFailure {
|
|
|
41
49
|
message: string;
|
|
42
50
|
timestamp: number;
|
|
43
51
|
}
|
|
44
|
-
interface
|
|
52
|
+
interface PromptCompressionTelemetryWithDiagnostics extends PromptCompressionTelemetry {
|
|
53
|
+
originalCharacters: number;
|
|
54
|
+
compressedCharacters: number;
|
|
55
|
+
savedCharacters: number;
|
|
56
|
+
savingsRatio: number;
|
|
57
|
+
}
|
|
58
|
+
interface AnthropicPromptCompressionTurnStats extends PromptCompressionTelemetryWithDiagnostics {
|
|
45
59
|
callId: string;
|
|
46
60
|
operation: "messages.create";
|
|
47
61
|
messagesCompressed: number;
|
|
@@ -68,13 +82,37 @@ interface WrapAnthropicOptions {
|
|
|
68
82
|
defaultContext?: Partial<WrapAnthropicContext>;
|
|
69
83
|
applyVendorHints?: boolean;
|
|
70
84
|
promptCompression?: boolean | AnthropicPromptCompressionOptions;
|
|
85
|
+
/** Retain eligible metered calls with an exact link to their UsageTap call. */
|
|
86
|
+
sampling?: MeteredAnthropicSamplingOptions | true;
|
|
71
87
|
}
|
|
72
88
|
interface AnthropicCompressionOptions extends AnthropicPromptCompressionOptions {
|
|
73
89
|
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
74
90
|
apiKey?: string;
|
|
75
91
|
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
76
92
|
usageTapClient?: UsageTapClient;
|
|
93
|
+
/** Also retain eligible calls after the provider responds. */
|
|
94
|
+
sampling?: SamplingOptions | true;
|
|
95
|
+
}
|
|
96
|
+
type AnthropicSamplingOptions = Partial<SamplingOptions> & {
|
|
97
|
+
apiKey?: string;
|
|
98
|
+
usageTapClient?: UsageTapClient;
|
|
99
|
+
};
|
|
100
|
+
type MeteredAnthropicSamplingOptions = Partial<SamplingOptions>;
|
|
101
|
+
interface AnthropicSamplingContext {
|
|
102
|
+
customerId?: string;
|
|
103
|
+
feature?: string;
|
|
104
|
+
environment?: string;
|
|
105
|
+
tags?: string[];
|
|
77
106
|
}
|
|
107
|
+
type SamplingAnthropicCreate<TCreate> = TCreate extends (params: infer TParams, options?: infer TOptions) => infer TReturn ? (params: TParams, options?: TOptions & {
|
|
108
|
+
usageTap?: AnthropicSamplingContext;
|
|
109
|
+
}) => TReturn : never;
|
|
110
|
+
type SamplingWrappedAnthropic<TClient extends AnthropicClientLike = AnthropicClientLike> = Omit<TClient, "messages"> & {
|
|
111
|
+
messages: Omit<TClient["messages"], "create"> & {
|
|
112
|
+
create: SamplingAnthropicCreate<TClient["messages"]["create"]>;
|
|
113
|
+
};
|
|
114
|
+
unwrap: () => TClient;
|
|
115
|
+
};
|
|
78
116
|
type WithMeteringAnthropicOptions = BeginCallRequest & {
|
|
79
117
|
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
80
118
|
apiKey?: string;
|
|
@@ -82,6 +120,8 @@ type WithMeteringAnthropicOptions = BeginCallRequest & {
|
|
|
82
120
|
usageTapClient?: UsageTapClient;
|
|
83
121
|
applyVendorHints?: boolean;
|
|
84
122
|
promptCompression?: boolean | AnthropicPromptCompressionOptions;
|
|
123
|
+
/** Retain eligible calls using the same ID as the metered UsageTap call. */
|
|
124
|
+
sampling?: MeteredAnthropicSamplingOptions | true;
|
|
85
125
|
};
|
|
86
126
|
interface WrapAnthropicCallOptions {
|
|
87
127
|
usageTap?: Partial<WrapAnthropicContext>;
|
|
@@ -109,10 +149,12 @@ type CompressionWrappedAnthropic<TClient extends AnthropicClientLike = Anthropic
|
|
|
109
149
|
unwrap: () => TClient;
|
|
110
150
|
};
|
|
111
151
|
type AnthropicMessagesCreateParams = Record<string, unknown>;
|
|
152
|
+
/** Retain locally-selected Anthropic calls without changing call sites. */
|
|
153
|
+
declare function withSampling<TClient extends AnthropicClientLike>(client: TClient, options?: AnthropicSamplingOptions): SamplingWrappedAnthropic<TClient>;
|
|
112
154
|
/** Add hosted prompt compression while preserving the Anthropic client API. */
|
|
113
155
|
declare function withCompression<TClient extends AnthropicClientLike>(client: TClient, options?: AnthropicCompressionOptions): CompressionWrappedAnthropic<TClient>;
|
|
114
156
|
/** Add UsageTap metering while preserving the Anthropic client API. */
|
|
115
157
|
declare function withMetering<TClient extends AnthropicClientLike>(client: TClient, customer: string | WithMeteringAnthropicOptions): WrappedAnthropic<TClient>;
|
|
116
158
|
declare function wrapAnthropic<TClient extends AnthropicClientLike>(client: TClient, usageTap: UsageTapClient, options?: WrapAnthropicOptions): WrappedAnthropic<TClient>;
|
|
117
159
|
|
|
118
|
-
export { type AnthropicClientLike, type AnthropicCompressionOptions, type AnthropicPromptCompressionFailure, type AnthropicPromptCompressionOptions, type AnthropicPromptCompressionRole, type AnthropicPromptCompressionRoleOptions, type AnthropicPromptCompressionRoleSetting, AnthropicPromptCompressionStats, type AnthropicPromptCompressionTurnStats, type CompressionWrappedAnthropic, type WithMeteringAnthropicOptions, type WrapAnthropicCallOptions, type WrapAnthropicContext, type WrapAnthropicOptions, type WrappedAnthropic, withCompression, withMetering, wrapAnthropic };
|
|
160
|
+
export { type AnthropicClientLike, type AnthropicCompressionOptions, type AnthropicPromptCompressionFailure, type AnthropicPromptCompressionOptions, type AnthropicPromptCompressionRole, type AnthropicPromptCompressionRoleOptions, type AnthropicPromptCompressionRoleSetting, AnthropicPromptCompressionStats, type AnthropicPromptCompressionTurnStats, type AnthropicSamplingContext, type AnthropicSamplingOptions, type CompressionWrappedAnthropic, type MeteredAnthropicSamplingOptions, type SamplingWrappedAnthropic, type WithMeteringAnthropicOptions, type WrapAnthropicCallOptions, type WrapAnthropicContext, type WrapAnthropicOptions, type WrappedAnthropic, withCompression, withMetering, withSampling, wrapAnthropic };
|