@usagetap/sdk 1.2.0 → 1.3.2
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 +710 -735
- package/dist/adapters/anthropic.cjs +1609 -5
- package/dist/adapters/anthropic.cjs.map +1 -1
- package/dist/adapters/anthropic.d.cts +30 -2
- package/dist/adapters/anthropic.d.ts +30 -2
- package/dist/adapters/anthropic.mjs +1608 -6
- package/dist/adapters/anthropic.mjs.map +1 -1
- package/dist/adapters/openai.cjs +1659 -5
- package/dist/adapters/openai.cjs.map +1 -1
- package/dist/adapters/openai.d.cts +37 -2
- package/dist/adapters/openai.d.ts +37 -2
- package/dist/adapters/openai.mjs +1658 -6
- package/dist/adapters/openai.mjs.map +1 -1
- package/dist/adapters/openrouter.cjs.map +1 -1
- package/dist/adapters/openrouter.d.cts +1 -1
- package/dist/adapters/openrouter.d.ts +1 -1
- package/dist/adapters/openrouter.mjs.map +1 -1
- package/dist/anthropic/index.cjs +1609 -5
- 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 +1608 -6
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/{client-EMXt9_fA.d.cts → client-BD8O2J8Z.d.cts} +30 -4
- package/dist/{client-EMXt9_fA.d.ts → client-BD8O2J8Z.d.ts} +30 -4
- package/dist/express/index.cjs +19 -0
- package/dist/express/index.cjs.map +1 -1
- package/dist/express/index.d.cts +1 -1
- package/dist/express/index.d.ts +1 -1
- package/dist/express/index.mjs +19 -0
- package/dist/express/index.mjs.map +1 -1
- package/dist/index.cjs +48 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +48 -20
- package/dist/index.mjs.map +1 -1
- package/dist/openai/index.cjs +1659 -5
- 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 +1658 -6
- package/dist/openai/index.mjs.map +1 -1
- package/dist/openrouter/index.cjs +3024 -0
- package/dist/openrouter/index.cjs.map +1 -0
- package/dist/openrouter/index.d.cts +4 -0
- package/dist/openrouter/index.d.ts +4 -0
- package/dist/openrouter/index.mjs +3019 -0
- package/dist/openrouter/index.mjs.map +1 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.mjs.map +1 -1
- package/package.json +182 -124
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionTelemetry,
|
|
1
|
+
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionTelemetry, U as UsageTapClient, W as WithUsageOptions } from '../client-BD8O2J8Z.cjs';
|
|
2
2
|
|
|
3
3
|
type WrapAnthropicContext = BeginCallRequest;
|
|
4
4
|
type AnthropicPromptCompressionRole = "system" | "user" | "tool" | "assistant";
|
|
@@ -17,6 +17,12 @@ interface AnthropicPromptCompressionOptions {
|
|
|
17
17
|
enabled?: boolean;
|
|
18
18
|
provider?: PromptCompressionProvider;
|
|
19
19
|
roles?: Partial<Record<AnthropicPromptCompressionRole, AnthropicPromptCompressionRoleSetting>>;
|
|
20
|
+
/**
|
|
21
|
+
* Skip compression when the combined request context is estimated below this
|
|
22
|
+
* many tokens. `withCompression` defaults to 1,000; set to 0 to always try.
|
|
23
|
+
*/
|
|
24
|
+
minContextTokens?: number;
|
|
25
|
+
/** Minimum estimated tokens for each individual text segment. */
|
|
20
26
|
minTokens?: number;
|
|
21
27
|
failOpen?: boolean;
|
|
22
28
|
tokenCompanyModel?: string;
|
|
@@ -63,6 +69,20 @@ interface WrapAnthropicOptions {
|
|
|
63
69
|
applyVendorHints?: boolean;
|
|
64
70
|
promptCompression?: boolean | AnthropicPromptCompressionOptions;
|
|
65
71
|
}
|
|
72
|
+
interface AnthropicCompressionOptions extends AnthropicPromptCompressionOptions {
|
|
73
|
+
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
74
|
+
apiKey?: string;
|
|
75
|
+
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
76
|
+
usageTapClient?: UsageTapClient;
|
|
77
|
+
}
|
|
78
|
+
type WithMeteringAnthropicOptions = BeginCallRequest & {
|
|
79
|
+
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
80
|
+
apiKey?: string;
|
|
81
|
+
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
82
|
+
usageTapClient?: UsageTapClient;
|
|
83
|
+
applyVendorHints?: boolean;
|
|
84
|
+
promptCompression?: boolean | AnthropicPromptCompressionOptions;
|
|
85
|
+
};
|
|
66
86
|
interface WrapAnthropicCallOptions {
|
|
67
87
|
usageTap?: Partial<WrapAnthropicContext>;
|
|
68
88
|
withUsage?: WithUsageOptions;
|
|
@@ -84,7 +104,15 @@ type WrappedAnthropic<TClient extends AnthropicClientLike = AnthropicClientLike>
|
|
|
84
104
|
promptCompression: AnthropicPromptCompressionStats;
|
|
85
105
|
unwrap: () => TClient;
|
|
86
106
|
};
|
|
107
|
+
type CompressionWrappedAnthropic<TClient extends AnthropicClientLike = AnthropicClientLike> = TClient & {
|
|
108
|
+
/** Return the original, unwrapped Anthropic client. */
|
|
109
|
+
unwrap: () => TClient;
|
|
110
|
+
};
|
|
87
111
|
type AnthropicMessagesCreateParams = Record<string, unknown>;
|
|
112
|
+
/** Add hosted prompt compression while preserving the Anthropic client API. */
|
|
113
|
+
declare function withCompression<TClient extends AnthropicClientLike>(client: TClient, options?: AnthropicCompressionOptions): CompressionWrappedAnthropic<TClient>;
|
|
114
|
+
/** Add UsageTap metering while preserving the Anthropic client API. */
|
|
115
|
+
declare function withMetering<TClient extends AnthropicClientLike>(client: TClient, customer: string | WithMeteringAnthropicOptions): WrappedAnthropic<TClient>;
|
|
88
116
|
declare function wrapAnthropic<TClient extends AnthropicClientLike>(client: TClient, usageTap: UsageTapClient, options?: WrapAnthropicOptions): WrappedAnthropic<TClient>;
|
|
89
117
|
|
|
90
|
-
export { type AnthropicClientLike, type AnthropicPromptCompressionFailure, type AnthropicPromptCompressionOptions, type AnthropicPromptCompressionRole, type AnthropicPromptCompressionRoleOptions, type AnthropicPromptCompressionRoleSetting, AnthropicPromptCompressionStats, type AnthropicPromptCompressionTurnStats, type WrapAnthropicCallOptions, type WrapAnthropicContext, type WrapAnthropicOptions, type WrappedAnthropic, wrapAnthropic };
|
|
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 };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionTelemetry,
|
|
1
|
+
import { B as BeginCallRequest, P as PromptCompressionProvider, a as PromptCompressionTelemetry, U as UsageTapClient, W as WithUsageOptions } from '../client-BD8O2J8Z.js';
|
|
2
2
|
|
|
3
3
|
type WrapAnthropicContext = BeginCallRequest;
|
|
4
4
|
type AnthropicPromptCompressionRole = "system" | "user" | "tool" | "assistant";
|
|
@@ -17,6 +17,12 @@ interface AnthropicPromptCompressionOptions {
|
|
|
17
17
|
enabled?: boolean;
|
|
18
18
|
provider?: PromptCompressionProvider;
|
|
19
19
|
roles?: Partial<Record<AnthropicPromptCompressionRole, AnthropicPromptCompressionRoleSetting>>;
|
|
20
|
+
/**
|
|
21
|
+
* Skip compression when the combined request context is estimated below this
|
|
22
|
+
* many tokens. `withCompression` defaults to 1,000; set to 0 to always try.
|
|
23
|
+
*/
|
|
24
|
+
minContextTokens?: number;
|
|
25
|
+
/** Minimum estimated tokens for each individual text segment. */
|
|
20
26
|
minTokens?: number;
|
|
21
27
|
failOpen?: boolean;
|
|
22
28
|
tokenCompanyModel?: string;
|
|
@@ -63,6 +69,20 @@ interface WrapAnthropicOptions {
|
|
|
63
69
|
applyVendorHints?: boolean;
|
|
64
70
|
promptCompression?: boolean | AnthropicPromptCompressionOptions;
|
|
65
71
|
}
|
|
72
|
+
interface AnthropicCompressionOptions extends AnthropicPromptCompressionOptions {
|
|
73
|
+
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
74
|
+
apiKey?: string;
|
|
75
|
+
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
76
|
+
usageTapClient?: UsageTapClient;
|
|
77
|
+
}
|
|
78
|
+
type WithMeteringAnthropicOptions = BeginCallRequest & {
|
|
79
|
+
/** UsageTap API key. Defaults to USAGETAP_API_KEY. */
|
|
80
|
+
apiKey?: string;
|
|
81
|
+
/** Reuse an existing client when custom transport or endpoints are configured. */
|
|
82
|
+
usageTapClient?: UsageTapClient;
|
|
83
|
+
applyVendorHints?: boolean;
|
|
84
|
+
promptCompression?: boolean | AnthropicPromptCompressionOptions;
|
|
85
|
+
};
|
|
66
86
|
interface WrapAnthropicCallOptions {
|
|
67
87
|
usageTap?: Partial<WrapAnthropicContext>;
|
|
68
88
|
withUsage?: WithUsageOptions;
|
|
@@ -84,7 +104,15 @@ type WrappedAnthropic<TClient extends AnthropicClientLike = AnthropicClientLike>
|
|
|
84
104
|
promptCompression: AnthropicPromptCompressionStats;
|
|
85
105
|
unwrap: () => TClient;
|
|
86
106
|
};
|
|
107
|
+
type CompressionWrappedAnthropic<TClient extends AnthropicClientLike = AnthropicClientLike> = TClient & {
|
|
108
|
+
/** Return the original, unwrapped Anthropic client. */
|
|
109
|
+
unwrap: () => TClient;
|
|
110
|
+
};
|
|
87
111
|
type AnthropicMessagesCreateParams = Record<string, unknown>;
|
|
112
|
+
/** Add hosted prompt compression while preserving the Anthropic client API. */
|
|
113
|
+
declare function withCompression<TClient extends AnthropicClientLike>(client: TClient, options?: AnthropicCompressionOptions): CompressionWrappedAnthropic<TClient>;
|
|
114
|
+
/** Add UsageTap metering while preserving the Anthropic client API. */
|
|
115
|
+
declare function withMetering<TClient extends AnthropicClientLike>(client: TClient, customer: string | WithMeteringAnthropicOptions): WrappedAnthropic<TClient>;
|
|
88
116
|
declare function wrapAnthropic<TClient extends AnthropicClientLike>(client: TClient, usageTap: UsageTapClient, options?: WrapAnthropicOptions): WrappedAnthropic<TClient>;
|
|
89
117
|
|
|
90
|
-
export { type AnthropicClientLike, type AnthropicPromptCompressionFailure, type AnthropicPromptCompressionOptions, type AnthropicPromptCompressionRole, type AnthropicPromptCompressionRoleOptions, type AnthropicPromptCompressionRoleSetting, AnthropicPromptCompressionStats, type AnthropicPromptCompressionTurnStats, type WrapAnthropicCallOptions, type WrapAnthropicContext, type WrapAnthropicOptions, type WrappedAnthropic, wrapAnthropic };
|
|
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 };
|