@revenium/openai 1.0.12 → 1.0.14
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/.env.example +10 -15
- package/CHANGELOG.md +59 -0
- package/CODE_OF_CONDUCT.md +57 -0
- package/CONTRIBUTING.md +38 -0
- package/README.md +109 -515
- package/SECURITY.md +34 -0
- package/dist/cjs/core/client/index.js +14 -0
- package/dist/cjs/core/client/index.js.map +1 -0
- package/dist/cjs/core/client/manager.js +109 -0
- package/dist/cjs/core/client/manager.js.map +1 -0
- package/dist/cjs/core/config/azure-config.js +5 -17
- package/dist/cjs/core/config/azure-config.js.map +1 -1
- package/dist/cjs/core/config/index.js +2 -2
- package/dist/cjs/core/config/index.js.map +1 -1
- package/dist/cjs/core/config/loader.js +34 -14
- package/dist/cjs/core/config/loader.js.map +1 -1
- package/dist/cjs/core/config/manager.js +12 -5
- package/dist/cjs/core/config/manager.js.map +1 -1
- package/dist/cjs/core/config/validator.js +3 -45
- package/dist/cjs/core/config/validator.js.map +1 -1
- package/dist/cjs/core/middleware/index.js +17 -0
- package/dist/cjs/core/middleware/index.js.map +1 -0
- package/dist/cjs/core/middleware/interfaces.js +361 -0
- package/dist/cjs/core/middleware/interfaces.js.map +1 -0
- package/dist/cjs/core/middleware/revenium-client.js +142 -0
- package/dist/cjs/core/middleware/revenium-client.js.map +1 -0
- package/dist/cjs/core/providers/detector.js +45 -23
- package/dist/cjs/core/providers/detector.js.map +1 -1
- package/dist/cjs/core/providers/index.js +2 -1
- package/dist/cjs/core/providers/index.js.map +1 -1
- package/dist/cjs/core/tracking/api-client.js +14 -13
- package/dist/cjs/core/tracking/api-client.js.map +1 -1
- package/dist/cjs/core/tracking/payload-builder.js +30 -35
- package/dist/cjs/core/tracking/payload-builder.js.map +1 -1
- package/dist/cjs/core/tracking/usage-tracker.js +22 -18
- package/dist/cjs/core/tracking/usage-tracker.js.map +1 -1
- package/dist/cjs/index.js +26 -174
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/index.js +0 -8
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/openai-augmentation.js +0 -49
- package/dist/cjs/types/openai-augmentation.js.map +1 -1
- package/dist/cjs/utils/constants.js +17 -20
- package/dist/cjs/utils/constants.js.map +1 -1
- package/dist/cjs/utils/error-handler.js +18 -14
- package/dist/cjs/utils/error-handler.js.map +1 -1
- package/dist/cjs/utils/metadata-builder.js +27 -19
- package/dist/cjs/utils/metadata-builder.js.map +1 -1
- package/dist/cjs/utils/provider-detection.js +25 -28
- package/dist/cjs/utils/provider-detection.js.map +1 -1
- package/dist/cjs/utils/stop-reason-mapper.js +4 -0
- package/dist/cjs/utils/stop-reason-mapper.js.map +1 -1
- package/dist/cjs/utils/url-builder.js +3 -3
- package/dist/esm/core/client/index.js +6 -0
- package/dist/esm/core/client/index.js.map +1 -0
- package/dist/esm/core/client/manager.js +102 -0
- package/dist/esm/core/client/manager.js.map +1 -0
- package/dist/esm/core/config/azure-config.js +6 -18
- package/dist/esm/core/config/azure-config.js.map +1 -1
- package/dist/esm/core/config/index.js +5 -4
- package/dist/esm/core/config/index.js.map +1 -1
- package/dist/esm/core/config/loader.js +33 -13
- package/dist/esm/core/config/loader.js.map +1 -1
- package/dist/esm/core/config/manager.js +14 -7
- package/dist/esm/core/config/manager.js.map +1 -1
- package/dist/esm/core/config/validator.js +3 -44
- package/dist/esm/core/config/validator.js.map +1 -1
- package/dist/esm/core/middleware/index.js +8 -0
- package/dist/esm/core/middleware/index.js.map +1 -0
- package/dist/esm/core/middleware/interfaces.js +353 -0
- package/dist/esm/core/middleware/interfaces.js.map +1 -0
- package/dist/esm/core/middleware/revenium-client.js +105 -0
- package/dist/esm/core/middleware/revenium-client.js.map +1 -0
- package/dist/esm/core/providers/detector.js +43 -22
- package/dist/esm/core/providers/detector.js.map +1 -1
- package/dist/esm/core/providers/index.js +2 -2
- package/dist/esm/core/providers/index.js.map +1 -1
- package/dist/esm/core/tracking/api-client.js +13 -12
- package/dist/esm/core/tracking/api-client.js.map +1 -1
- package/dist/esm/core/tracking/payload-builder.js +31 -36
- package/dist/esm/core/tracking/payload-builder.js.map +1 -1
- package/dist/esm/core/tracking/usage-tracker.js +24 -20
- package/dist/esm/core/tracking/usage-tracker.js.map +1 -1
- package/dist/esm/index.js +9 -157
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/index.js +2 -10
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/openai-augmentation.js +0 -49
- package/dist/esm/types/openai-augmentation.js.map +1 -1
- package/dist/esm/utils/constants.js +16 -19
- package/dist/esm/utils/constants.js.map +1 -1
- package/dist/esm/utils/error-handler.js +19 -15
- package/dist/esm/utils/error-handler.js.map +1 -1
- package/dist/esm/utils/metadata-builder.js +27 -19
- package/dist/esm/utils/metadata-builder.js.map +1 -1
- package/dist/esm/utils/provider-detection.js +26 -29
- package/dist/esm/utils/provider-detection.js.map +1 -1
- package/dist/esm/utils/stop-reason-mapper.js +4 -0
- package/dist/esm/utils/stop-reason-mapper.js.map +1 -1
- package/dist/esm/utils/url-builder.js +3 -3
- package/dist/types/core/client/index.d.ts +6 -0
- package/dist/types/core/client/index.d.ts.map +1 -0
- package/dist/types/core/client/manager.d.ts +32 -0
- package/dist/types/core/client/manager.d.ts.map +1 -0
- package/dist/types/core/config/azure-config.d.ts +2 -2
- package/dist/types/core/config/azure-config.d.ts.map +1 -1
- package/dist/types/core/config/index.d.ts +4 -4
- package/dist/types/core/config/index.d.ts.map +1 -1
- package/dist/types/core/config/loader.d.ts +3 -1
- package/dist/types/core/config/loader.d.ts.map +1 -1
- package/dist/types/core/config/manager.d.ts +1 -1
- package/dist/types/core/config/manager.d.ts.map +1 -1
- package/dist/types/core/config/validator.d.ts +1 -12
- package/dist/types/core/config/validator.d.ts.map +1 -1
- package/dist/types/core/middleware/index.d.ts +8 -0
- package/dist/types/core/middleware/index.d.ts.map +1 -0
- package/dist/types/core/middleware/interfaces.d.ts +74 -0
- package/dist/types/core/middleware/interfaces.d.ts.map +1 -0
- package/dist/types/core/middleware/revenium-client.d.ts +58 -0
- package/dist/types/core/middleware/revenium-client.d.ts.map +1 -0
- package/dist/types/core/providers/detector.d.ts +9 -2
- package/dist/types/core/providers/detector.d.ts.map +1 -1
- package/dist/types/core/providers/index.d.ts +2 -2
- package/dist/types/core/providers/index.d.ts.map +1 -1
- package/dist/types/core/tracking/api-client.d.ts +1 -1
- package/dist/types/core/tracking/api-client.d.ts.map +1 -1
- package/dist/types/core/tracking/payload-builder.d.ts +3 -3
- package/dist/types/core/tracking/payload-builder.d.ts.map +1 -1
- package/dist/types/core/tracking/usage-tracker.d.ts +2 -2
- package/dist/types/core/tracking/usage-tracker.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -114
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/function-parameters.d.ts +2 -23
- package/dist/types/types/function-parameters.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +17 -115
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/openai-augmentation.d.ts +4 -139
- package/dist/types/types/openai-augmentation.d.ts.map +1 -1
- package/dist/types/utils/constants.d.ts +7 -1
- package/dist/types/utils/constants.d.ts.map +1 -1
- package/dist/types/utils/error-handler.d.ts +2 -2
- package/dist/types/utils/error-handler.d.ts.map +1 -1
- package/dist/types/utils/metadata-builder.d.ts +4 -3
- package/dist/types/utils/metadata-builder.d.ts.map +1 -1
- package/dist/types/utils/provider-detection.d.ts +3 -3
- package/dist/types/utils/provider-detection.d.ts.map +1 -1
- package/dist/types/utils/stop-reason-mapper.d.ts.map +1 -1
- package/dist/types/utils/url-builder.d.ts +3 -3
- package/examples/README.md +270 -224
- package/examples/azure/basic.ts +62 -0
- package/examples/azure/responses-basic.ts +45 -0
- package/examples/azure/responses-stream.ts +61 -0
- package/examples/azure/stream.ts +56 -0
- package/examples/getting_started.ts +31 -43
- package/examples/openai/basic.ts +45 -0
- package/examples/openai/metadata.ts +67 -0
- package/examples/openai/responses-basic.ts +44 -0
- package/examples/openai/responses-embed.ts +34 -0
- package/examples/openai/responses-streaming.ts +63 -0
- package/examples/openai/streaming.ts +59 -0
- package/package.json +20 -13
- package/dist/cjs/core/wrapper/index.js +0 -15
- package/dist/cjs/core/wrapper/index.js.map +0 -1
- package/dist/cjs/core/wrapper/instance-patcher.js +0 -202
- package/dist/cjs/core/wrapper/instance-patcher.js.map +0 -1
- package/dist/cjs/core/wrapper/request-handler.js +0 -317
- package/dist/cjs/core/wrapper/request-handler.js.map +0 -1
- package/dist/cjs/core/wrapper/stream-wrapper.js +0 -82
- package/dist/cjs/core/wrapper/stream-wrapper.js.map +0 -1
- package/dist/cjs/utils/azure-model-resolver.js +0 -211
- package/dist/cjs/utils/azure-model-resolver.js.map +0 -1
- package/dist/cjs/utils/request-handler-factory.js +0 -185
- package/dist/cjs/utils/request-handler-factory.js.map +0 -1
- package/dist/esm/core/wrapper/index.js +0 -9
- package/dist/esm/core/wrapper/index.js.map +0 -1
- package/dist/esm/core/wrapper/instance-patcher.js +0 -199
- package/dist/esm/core/wrapper/instance-patcher.js.map +0 -1
- package/dist/esm/core/wrapper/request-handler.js +0 -310
- package/dist/esm/core/wrapper/request-handler.js.map +0 -1
- package/dist/esm/core/wrapper/stream-wrapper.js +0 -79
- package/dist/esm/core/wrapper/stream-wrapper.js.map +0 -1
- package/dist/esm/utils/azure-model-resolver.js +0 -204
- package/dist/esm/utils/azure-model-resolver.js.map +0 -1
- package/dist/esm/utils/request-handler-factory.js +0 -146
- package/dist/esm/utils/request-handler-factory.js.map +0 -1
- package/dist/types/core/wrapper/index.d.ts +0 -8
- package/dist/types/core/wrapper/index.d.ts.map +0 -1
- package/dist/types/core/wrapper/instance-patcher.d.ts +0 -33
- package/dist/types/core/wrapper/instance-patcher.d.ts.map +0 -1
- package/dist/types/core/wrapper/request-handler.d.ts +0 -29
- package/dist/types/core/wrapper/request-handler.d.ts.map +0 -1
- package/dist/types/core/wrapper/stream-wrapper.d.ts +0 -13
- package/dist/types/core/wrapper/stream-wrapper.d.ts.map +0 -1
- package/dist/types/utils/azure-model-resolver.d.ts +0 -41
- package/dist/types/utils/azure-model-resolver.d.ts.map +0 -1
- package/dist/types/utils/request-handler-factory.d.ts +0 -81
- package/dist/types/utils/request-handler-factory.d.ts.map +0 -1
- package/examples/azure-basic.ts +0 -206
- package/examples/azure-responses-basic.ts +0 -233
- package/examples/azure-responses-streaming.ts +0 -255
- package/examples/azure-streaming.ts +0 -209
- package/examples/openai-basic.ts +0 -147
- package/examples/openai-function-calling.ts +0 -259
- package/examples/openai-responses-basic.ts +0 -212
- package/examples/openai-responses-streaming.ts +0 -232
- package/examples/openai-streaming.ts +0 -172
- package/examples/openai-vision.ts +0 -289
- package/src/core/config/azure-config.ts +0 -72
- package/src/core/config/index.ts +0 -23
- package/src/core/config/loader.ts +0 -66
- package/src/core/config/manager.ts +0 -94
- package/src/core/config/validator.ts +0 -89
- package/src/core/providers/detector.ts +0 -159
- package/src/core/providers/index.ts +0 -16
- package/src/core/tracking/api-client.ts +0 -78
- package/src/core/tracking/index.ts +0 -21
- package/src/core/tracking/payload-builder.ts +0 -132
- package/src/core/tracking/usage-tracker.ts +0 -189
- package/src/core/wrapper/index.ts +0 -9
- package/src/core/wrapper/instance-patcher.ts +0 -288
- package/src/core/wrapper/request-handler.ts +0 -423
- package/src/core/wrapper/stream-wrapper.ts +0 -100
- package/src/index.ts +0 -336
- package/src/types/function-parameters.ts +0 -251
- package/src/types/index.ts +0 -313
- package/src/types/openai-augmentation.ts +0 -233
- package/src/types/responses-api.ts +0 -308
- package/src/utils/azure-model-resolver.ts +0 -220
- package/src/utils/constants.ts +0 -21
- package/src/utils/error-handler.ts +0 -251
- package/src/utils/metadata-builder.ts +0 -219
- package/src/utils/provider-detection.ts +0 -257
- package/src/utils/request-handler-factory.ts +0 -285
- package/src/utils/stop-reason-mapper.ts +0 -74
- package/src/utils/type-guards.ts +0 -202
- package/src/utils/url-builder.ts +0 -68
|
@@ -4,22 +4,13 @@
|
|
|
4
4
|
* Central type definitions for the Revenium OpenAI middleware.
|
|
5
5
|
* This module exports all core types used throughout the application.
|
|
6
6
|
*/
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
7
|
+
export * from "./function-parameters.js";
|
|
8
|
+
export * from "./responses-api.js";
|
|
9
9
|
/**
|
|
10
10
|
* Credential information for subscriber authentication
|
|
11
11
|
*
|
|
12
12
|
* Represents authentication credentials that can be attached to subscriber information
|
|
13
13
|
* for enhanced security and tracking capabilities.
|
|
14
|
-
*
|
|
15
|
-
* @public
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const credential: Credential = {
|
|
19
|
-
* name: 'api_token',
|
|
20
|
-
* value: 'user_token_abc123'
|
|
21
|
-
* };
|
|
22
|
-
* ```
|
|
23
14
|
*/
|
|
24
15
|
export interface Credential {
|
|
25
16
|
/** The name/type of the credential (e.g., 'api_token', 'session_id') */
|
|
@@ -32,19 +23,6 @@ export interface Credential {
|
|
|
32
23
|
*
|
|
33
24
|
* Represents end-user information for tracking and billing purposes.
|
|
34
25
|
* All fields are optional to provide maximum flexibility in implementation.
|
|
35
|
-
*
|
|
36
|
-
* @public
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* const subscriber: Subscriber = {
|
|
40
|
-
* id: 'user-12345',
|
|
41
|
-
* email: 'john.doe@company.com',
|
|
42
|
-
* credential: {
|
|
43
|
-
* name: 'session_token',
|
|
44
|
-
* value: 'abc123xyz'
|
|
45
|
-
* }
|
|
46
|
-
* };
|
|
47
|
-
* ```
|
|
48
26
|
*/
|
|
49
27
|
export interface Subscriber {
|
|
50
28
|
/** Unique identifier for the subscriber/user */
|
|
@@ -60,23 +38,6 @@ export interface Subscriber {
|
|
|
60
38
|
* Comprehensive metadata structure that enables detailed tracking of AI API usage
|
|
61
39
|
* for analytics, billing, and business intelligence purposes. All fields are optional
|
|
62
40
|
* to provide maximum flexibility while maintaining consistency across language implementations.
|
|
63
|
-
*
|
|
64
|
-
* @public
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* const metadata: UsageMetadata = {
|
|
68
|
-
* subscriber: {
|
|
69
|
-
* id: 'user-123',
|
|
70
|
-
* email: 'user@company.com'
|
|
71
|
-
* },
|
|
72
|
-
* organizationId: 'org-456',
|
|
73
|
-
* productId: 'chat-assistant',
|
|
74
|
-
* taskType: 'customer-support',
|
|
75
|
-
* traceId: 'trace-789',
|
|
76
|
-
* responseQualityScore: 0.95,
|
|
77
|
-
* agent: 'support-bot-v2'
|
|
78
|
-
* };
|
|
79
|
-
* ```
|
|
80
41
|
*/
|
|
81
42
|
export interface UsageMetadata {
|
|
82
43
|
/** User identification information (nested structure for detailed tracking) */
|
|
@@ -89,16 +50,12 @@ export interface UsageMetadata {
|
|
|
89
50
|
subscriptionId?: string;
|
|
90
51
|
/** Task type classification (e.g., 'chat', 'summarization', 'translation') */
|
|
91
52
|
taskType?: string;
|
|
92
|
-
/** Unique task identifier for request correlation */
|
|
93
|
-
taskId?: string;
|
|
94
53
|
/** Distributed tracing identifier for request tracking across services */
|
|
95
54
|
traceId?: string;
|
|
96
|
-
/** Quality score for response evaluation (0.0
|
|
55
|
+
/** Quality score for response evaluation (0.0-1.0 scale per API spec) */
|
|
97
56
|
responseQualityScore?: number;
|
|
98
57
|
/** Agent or model variant identifier for A/B testing and performance tracking */
|
|
99
58
|
agent?: string;
|
|
100
|
-
/** Allow additional custom fields for extensibility */
|
|
101
|
-
[key: string]: unknown;
|
|
102
59
|
}
|
|
103
60
|
/**
|
|
104
61
|
* Provider information for tracking API source
|
|
@@ -106,18 +63,7 @@ export interface UsageMetadata {
|
|
|
106
63
|
* Detailed information about the detected AI provider, including configuration
|
|
107
64
|
* details and Azure-specific settings when applicable. Used internally for
|
|
108
65
|
* provider-specific handling and metrics collection.
|
|
109
|
-
|
|
110
|
-
* @public
|
|
111
|
-
* @example
|
|
112
|
-
* ```typescript
|
|
113
|
-
* const providerInfo: ProviderInfo = {
|
|
114
|
-
* provider: Provider.AZURE_OPENAI,
|
|
115
|
-
* isAzure: true,
|
|
116
|
-
* endpoint: 'https://my-resource.openai.azure.com',
|
|
117
|
-
* apiVersion: '2024-02-01',
|
|
118
|
-
* deployment: 'gpt-4-turbo'
|
|
119
|
-
* };
|
|
120
|
-
* ```
|
|
66
|
+
|
|
121
67
|
*/
|
|
122
68
|
export interface ProviderInfo {
|
|
123
69
|
/** The detected AI provider type */
|
|
@@ -128,8 +74,6 @@ export interface ProviderInfo {
|
|
|
128
74
|
endpoint?: string;
|
|
129
75
|
/** API version (for Azure OpenAI) */
|
|
130
76
|
apiVersion?: string;
|
|
131
|
-
/** Deployment name (for Azure OpenAI) */
|
|
132
|
-
deployment?: string;
|
|
133
77
|
/** Complete Azure configuration when available */
|
|
134
78
|
azureConfig?: AzureConfig;
|
|
135
79
|
}
|
|
@@ -138,14 +82,6 @@ export interface ProviderInfo {
|
|
|
138
82
|
*
|
|
139
83
|
* Enumeration of AI providers supported by the Revenium middleware.
|
|
140
84
|
* Used for automatic detection, routing, and provider-specific handling.
|
|
141
|
-
*
|
|
142
|
-
* @public
|
|
143
|
-
* @example
|
|
144
|
-
* ```typescript
|
|
145
|
-
* if (providerInfo.provider === Provider.AZURE_OPENAI) {
|
|
146
|
-
* console.log('Using Azure OpenAI');
|
|
147
|
-
* }
|
|
148
|
-
* ```
|
|
149
85
|
*/
|
|
150
86
|
export declare enum Provider {
|
|
151
87
|
/** Standard OpenAI API */
|
|
@@ -159,18 +95,6 @@ export declare enum Provider {
|
|
|
159
95
|
* Configuration interface for Azure OpenAI Service integration.
|
|
160
96
|
* Provides all necessary settings for connecting to Azure OpenAI endpoints
|
|
161
97
|
* with proper authentication and resource identification.
|
|
162
|
-
*
|
|
163
|
-
* @public
|
|
164
|
-
* @example
|
|
165
|
-
* ```typescript
|
|
166
|
-
* const azureConfig: AzureConfig = {
|
|
167
|
-
* endpoint: 'https://my-resource.openai.azure.com',
|
|
168
|
-
* apiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
169
|
-
* apiVersion: '2024-02-01',
|
|
170
|
-
* deployment: 'gpt-4-turbo',
|
|
171
|
-
* tenantId: 'your-tenant-id'
|
|
172
|
-
* };
|
|
173
|
-
* ```
|
|
174
98
|
*/
|
|
175
99
|
export interface AzureConfig {
|
|
176
100
|
/** Azure OpenAI endpoint URL */
|
|
@@ -179,12 +103,6 @@ export interface AzureConfig {
|
|
|
179
103
|
apiKey?: string;
|
|
180
104
|
/** Azure OpenAI API version */
|
|
181
105
|
apiVersion?: string;
|
|
182
|
-
/** Azure OpenAI deployment name */
|
|
183
|
-
deployment?: string;
|
|
184
|
-
/** Azure tenant ID for authentication */
|
|
185
|
-
tenantId?: string;
|
|
186
|
-
/** Azure resource group name */
|
|
187
|
-
resourceGroup?: string;
|
|
188
106
|
}
|
|
189
107
|
/**
|
|
190
108
|
* Revenium configuration interface
|
|
@@ -192,22 +110,12 @@ export interface AzureConfig {
|
|
|
192
110
|
* Main configuration interface for initializing the Revenium middleware.
|
|
193
111
|
* Defines all required and optional settings for connecting to Revenium's
|
|
194
112
|
* metering API and configuring middleware behavior.
|
|
195
|
-
|
|
196
|
-
* @public
|
|
197
|
-
* @example
|
|
198
|
-
* ```typescript
|
|
199
|
-
* const config: ReveniumConfig = {
|
|
200
|
-
* reveniumApiKey: 'hak_your_revenium_api_key',
|
|
201
|
-
* reveniumBaseUrl: 'https://api.revenium.io',
|
|
202
|
-
* debug: true,
|
|
203
|
-
* openaiApiKey: process.env.OPENAI_API_KEY
|
|
204
|
-
* };
|
|
205
|
-
* ```
|
|
113
|
+
|
|
206
114
|
*/
|
|
207
115
|
export interface ReveniumConfig {
|
|
208
116
|
/** Revenium API key for authentication (required) */
|
|
209
117
|
reveniumApiKey: string;
|
|
210
|
-
/** Revenium API base URL (optional, defaults to https://api.revenium.
|
|
118
|
+
/** Revenium API base URL (optional, defaults to https://api.revenium.ai) */
|
|
211
119
|
reveniumBaseUrl?: string;
|
|
212
120
|
/** Enable debug logging (optional, defaults to false) */
|
|
213
121
|
debug?: boolean;
|
|
@@ -216,23 +124,17 @@ export interface ReveniumConfig {
|
|
|
216
124
|
/** OpenAI API key (optional, can be set via environment variable) */
|
|
217
125
|
openaiApiKey?: string;
|
|
218
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Alias for ReveniumConfig for internal use
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
export type Config = ReveniumConfig;
|
|
219
132
|
/**
|
|
220
133
|
* Logger interface for consistent logging
|
|
221
134
|
*
|
|
222
135
|
* Standardized logging interface that allows custom logger integration
|
|
223
136
|
* while maintaining consistent log levels and metadata support throughout
|
|
224
137
|
* the middleware. Supports both structured and string metadata.
|
|
225
|
-
*
|
|
226
|
-
* @public
|
|
227
|
-
* @example
|
|
228
|
-
* ```typescript
|
|
229
|
-
* const customLogger: Logger = {
|
|
230
|
-
* debug: (msg, meta) => console.debug(`[DEBUG] ${msg}`, meta),
|
|
231
|
-
* info: (msg, meta) => console.info(`[INFO] ${msg}`, meta),
|
|
232
|
-
* warn: (msg, meta) => console.warn(`[WARN] ${msg}`, meta),
|
|
233
|
-
* error: (msg, meta) => console.error(`[ERROR] ${msg}`, meta)
|
|
234
|
-
* };
|
|
235
|
-
* ```
|
|
236
138
|
*/
|
|
237
139
|
export interface Logger {
|
|
238
140
|
/** Log debug-level messages with optional metadata */
|
|
@@ -249,8 +151,8 @@ export interface Logger {
|
|
|
249
151
|
*/
|
|
250
152
|
export interface ReveniumPayload {
|
|
251
153
|
transactionId: string;
|
|
252
|
-
operationType:
|
|
253
|
-
costType:
|
|
154
|
+
operationType: "CHAT" | "GENERATE" | "EMBED" | "CLASSIFY" | "SUMMARIZE" | "TRANSLATE" | "OTHER";
|
|
155
|
+
costType: "AI";
|
|
254
156
|
model: string;
|
|
255
157
|
provider: string;
|
|
256
158
|
modelSource?: string;
|
|
@@ -262,12 +164,12 @@ export interface ReveniumPayload {
|
|
|
262
164
|
inputTokenCount: number;
|
|
263
165
|
outputTokenCount: number;
|
|
264
166
|
totalTokenCount: number;
|
|
265
|
-
reasoningTokenCount: number;
|
|
266
|
-
cacheCreationTokenCount: number;
|
|
267
|
-
cacheReadTokenCount: number;
|
|
167
|
+
reasoningTokenCount: number | undefined;
|
|
168
|
+
cacheCreationTokenCount: number | undefined;
|
|
169
|
+
cacheReadTokenCount: number | undefined;
|
|
268
170
|
stopReason: string;
|
|
269
171
|
isStreamed: boolean;
|
|
270
|
-
timeToFirstToken?: number;
|
|
172
|
+
timeToFirstToken?: number | undefined;
|
|
271
173
|
inputTokenCost?: number;
|
|
272
174
|
outputTokenCost?: number;
|
|
273
175
|
totalCost?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,0BAA0B,CAAC;AAGzC,cAAc,oBAAoB,CAAC;AAEnC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,0BAA0B,CAAC;AAGzC,cAAc,oBAAoB,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,gDAAgD;IAChD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4DAA4D;IAC5D,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC5B,+EAA+E;IAC/E,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB,uEAAuE;IACvE,cAAc,CAAC,EAAE,MAAM,CAAC;I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GAAG,SAAS,CAAC;IACxC,uBAAuB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IAGxC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAGtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B"}
|
|
@@ -1,56 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TypeScript module augmentation for OpenAI SDK
|
|
3
|
-
*
|
|
4
|
-
* This file extends OpenAI's existing types to include the usageMetadata field
|
|
5
|
-
* through TypeScript's declaration merging feature. This provides seamless
|
|
6
|
-
* integration with the OpenAI SDK, allowing developers to use usageMetadata
|
|
7
|
-
* directly in OpenAI API calls without type casting or additional imports.
|
|
8
|
-
*
|
|
9
|
-
* The augmentation covers all major OpenAI API endpoints including:
|
|
10
|
-
* - Chat completions (streaming and non-streaming)
|
|
11
|
-
* - Embeddings
|
|
12
|
-
* - Future API endpoints as they become available
|
|
13
|
-
*
|
|
14
|
-
* @fileoverview OpenAI SDK type augmentation for Revenium middleware
|
|
15
|
-
* @author Revenium
|
|
16
|
-
* @since 1.0.0
|
|
17
|
-
*
|
|
18
|
-
* @example Basic usage with chat completions
|
|
19
|
-
* ```typescript
|
|
20
|
-
* import '@revenium/openai';
|
|
21
|
-
* import OpenAI from 'openai';
|
|
22
|
-
*
|
|
23
|
-
* const openai = new OpenAI();
|
|
24
|
-
*
|
|
25
|
-
* const response = await openai.chat.completions.create({
|
|
26
|
-
* model: 'gpt-4o-mini',
|
|
27
|
-
* messages: [{ role: 'user', content: 'Hello!' }],
|
|
28
|
-
* usageMetadata: { // TypeScript recognizes this natively
|
|
29
|
-
* subscriber: {
|
|
30
|
-
* id: 'user-123',
|
|
31
|
-
* email: 'user@my-company.com'
|
|
32
|
-
* },
|
|
33
|
-
* organizationId: 'my-company',
|
|
34
|
-
* productId: 'chat-app',
|
|
35
|
-
* taskType: 'customer-support'
|
|
36
|
-
* }
|
|
37
|
-
* });
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @example Usage with embeddings
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const embedding = await openai.embeddings.create({
|
|
43
|
-
* model: 'text-embedding-ada-002',
|
|
44
|
-
* input: 'Text to embed',
|
|
45
|
-
* usageMetadata: {
|
|
46
|
-
* subscriber: { id: 'user-456' },
|
|
47
|
-
* productId: 'search-engine',
|
|
48
|
-
* taskType: 'document-indexing'
|
|
49
|
-
* }
|
|
50
|
-
* });
|
|
51
|
-
* ```
|
|
52
3
|
*/
|
|
53
|
-
import { UsageMetadata } from
|
|
4
|
+
import { UsageMetadata } from "./index.js";
|
|
54
5
|
export {};
|
|
55
6
|
/**
|
|
56
7
|
* OpenAI Chat Completions API augmentation
|
|
@@ -58,7 +9,7 @@ export {};
|
|
|
58
9
|
* Extends the OpenAI chat completions interfaces to include usageMetadata
|
|
59
10
|
* for all completion types (base, streaming, and non-streaming).
|
|
60
11
|
*/
|
|
61
|
-
declare module
|
|
12
|
+
declare module "openai/resources/chat/completions/completions" {
|
|
62
13
|
interface ChatCompletionCreateParamsBase {
|
|
63
14
|
/**
|
|
64
15
|
* Optional metadata for enhanced tracking and analytics.
|
|
@@ -68,32 +19,6 @@ declare module 'openai/resources/chat/completions/completions' {
|
|
|
68
19
|
*
|
|
69
20
|
* This metadata is automatically captured by the Revenium middleware and sent to
|
|
70
21
|
* the Revenium API for detailed usage analytics and billing calculations.
|
|
71
|
-
*
|
|
72
|
-
* @since 1.0.0
|
|
73
|
-
* @example Basic user tracking
|
|
74
|
-
* ```typescript
|
|
75
|
-
* usageMetadata: {
|
|
76
|
-
* subscriber: {
|
|
77
|
-
* id: 'user-123',
|
|
78
|
-
* email: 'user@my-company.com'
|
|
79
|
-
* },
|
|
80
|
-
* organizationId: 'my-company',
|
|
81
|
-
* productId: 'support-app'
|
|
82
|
-
* }
|
|
83
|
-
* ```
|
|
84
|
-
*
|
|
85
|
-
* @example Advanced tracking with quality metrics
|
|
86
|
-
* ```typescript
|
|
87
|
-
* usageMetadata: {
|
|
88
|
-
* subscriber: { id: 'user-456' },
|
|
89
|
-
* organizationId: 'enterprise-corp',
|
|
90
|
-
* productId: 'ai-assistant',
|
|
91
|
-
* taskType: 'customer-support',
|
|
92
|
-
* traceId: 'session-abc-123',
|
|
93
|
-
* responseQualityScore: 0.95,
|
|
94
|
-
* agent: 'support-bot-v2'
|
|
95
|
-
* }
|
|
96
|
-
* ```
|
|
97
22
|
*/
|
|
98
23
|
usageMetadata?: UsageMetadata;
|
|
99
24
|
}
|
|
@@ -126,7 +51,7 @@ declare module 'openai/resources/chat/completions/completions' {
|
|
|
126
51
|
* Extends the OpenAI embeddings interface to include usageMetadata
|
|
127
52
|
* for comprehensive tracking of embedding generation requests.
|
|
128
53
|
*/
|
|
129
|
-
declare module
|
|
54
|
+
declare module "openai/resources/embeddings" {
|
|
130
55
|
interface EmbeddingCreateParams {
|
|
131
56
|
/**
|
|
132
57
|
* Optional metadata for enhanced tracking and analytics.
|
|
@@ -137,32 +62,6 @@ declare module 'openai/resources/embeddings' {
|
|
|
137
62
|
*
|
|
138
63
|
* All fields are optional to maintain backward compatibility and provide maximum flexibility.
|
|
139
64
|
*
|
|
140
|
-
* @since 1.0.0
|
|
141
|
-
* @example Document indexing workflow
|
|
142
|
-
* ```typescript
|
|
143
|
-
* usageMetadata: {
|
|
144
|
-
* subscriber: {
|
|
145
|
-
* id: 'user-123',
|
|
146
|
-
* email: 'user@my-company.com'
|
|
147
|
-
* },
|
|
148
|
-
* organizationId: 'my-company',
|
|
149
|
-
* productId: 'vector-search',
|
|
150
|
-
* taskType: 'document-indexing',
|
|
151
|
-
* taskId: 'batch-index-2024-01'
|
|
152
|
-
* }
|
|
153
|
-
* ```
|
|
154
|
-
*
|
|
155
|
-
* @example Semantic search application
|
|
156
|
-
* ```typescript
|
|
157
|
-
* usageMetadata: {
|
|
158
|
-
* subscriber: { id: 'user-456' },
|
|
159
|
-
* organizationId: 'enterprise-corp',
|
|
160
|
-
* productId: 'knowledge-base',
|
|
161
|
-
* taskType: 'semantic-search',
|
|
162
|
-
* traceId: 'search-session-789'
|
|
163
|
-
* }
|
|
164
|
-
* ```
|
|
165
|
-
*
|
|
166
65
|
* @see {@link UsageMetadata} for detailed field descriptions
|
|
167
66
|
*/
|
|
168
67
|
usageMetadata?: UsageMetadata;
|
|
@@ -174,7 +73,7 @@ declare module 'openai/resources/embeddings' {
|
|
|
174
73
|
* Extends the new Responses API to support usageMetadata for comprehensive tracking.
|
|
175
74
|
* The Responses API is OpenAI's new unified interface for agent-like applications.
|
|
176
75
|
*/
|
|
177
|
-
declare module
|
|
76
|
+
declare module "openai" {
|
|
178
77
|
namespace Responses {
|
|
179
78
|
interface ResponseCreateParams {
|
|
180
79
|
/**
|
|
@@ -183,40 +82,6 @@ declare module 'openai' {
|
|
|
183
82
|
* Enables comprehensive tracking and analytics for Responses API calls.
|
|
184
83
|
* All fields are optional and can be customized based on your application needs.
|
|
185
84
|
*
|
|
186
|
-
* @example Basic Responses API usage with metadata
|
|
187
|
-
* ```typescript
|
|
188
|
-
* const response = await openai.responses.create({
|
|
189
|
-
* model: 'gpt-4.1',
|
|
190
|
-
* input: 'Analyze this data and provide insights',
|
|
191
|
-
* usageMetadata: {
|
|
192
|
-
* subscriber: {
|
|
193
|
-
* id: 'analyst-123',
|
|
194
|
-
* email: 'analyst@company.com'
|
|
195
|
-
* },
|
|
196
|
-
* organizationId: 'data-corp',
|
|
197
|
-
* productId: 'analytics-platform',
|
|
198
|
-
* taskType: 'data-analysis',
|
|
199
|
-
* agent: 'responses-api-v1'
|
|
200
|
-
* }
|
|
201
|
-
* });
|
|
202
|
-
* ```
|
|
203
|
-
*
|
|
204
|
-
* @example Streaming Responses API with metadata
|
|
205
|
-
* ```typescript
|
|
206
|
-
* const stream = await openai.responses.create({
|
|
207
|
-
* model: 'gpt-4.1',
|
|
208
|
-
* input: [
|
|
209
|
-
* { role: 'user', content: 'Generate a detailed report' }
|
|
210
|
-
* ],
|
|
211
|
-
* stream: true,
|
|
212
|
-
* usageMetadata: {
|
|
213
|
-
* subscriber: { id: 'user-456' },
|
|
214
|
-
* taskType: 'report-generation',
|
|
215
|
-
* traceId: 'session-789'
|
|
216
|
-
* }
|
|
217
|
-
* });
|
|
218
|
-
* ```
|
|
219
|
-
*
|
|
220
85
|
* @see {@link UsageMetadata} for detailed field descriptions
|
|
221
86
|
*/
|
|
222
87
|
usageMetadata?: UsageMetadata;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-augmentation.d.ts","sourceRoot":"","sources":["../../../src/types/openai-augmentation.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"openai-augmentation.d.ts","sourceRoot":"","sources":["../../../src/types/openai-augmentation.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,OAAO,EAAE,CAAC;AAEV;;;;;GAKG;AACH,OAAO,QAAQ,+CAA+C,CAAC;IAC7D,UAAU,8BAA8B;QACtC;;;;;;;;WAQG;QACH,aAAa,CAAC,EAAE,aAAa,CAAC;KAC/B;IAED,UAAU,sCAAsC;QAC9C;;;;;;;WAOG;QACH,aAAa,CAAC,EAAE,aAAa,CAAC;KAC/B;IAED,UAAU,mCAAmC;QAC3C;;;;;;;WAOG;QACH,aAAa,CAAC,EAAE,aAAa,CAAC;KAC/B;CACF;AAED;;;;;GAKG;AACH,OAAO,QAAQ,6BAA6B,CAAC;IAC3C,UAAU,qBAAqB;QAC7B;;;;;;;;;;WAUG;QACH,aAAa,CAAC,EAAE,aAAa,CAAC;KAC/B;CACF;AAED;;;;;GAKG;AACH,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,SAAS,CAAC;QAClB,UAAU,oBAAoB;YAC5B;;;;;;;eAOG;YACH,aAAa,CAAC,EAAE,aAAa,CAAC;SAC/B;KACF;CACF"}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Error message patterns for network-related errors
|
|
3
|
+
*/
|
|
2
4
|
export declare const MESSAGE_PATTERNS_TYPE_NETWORK: string[];
|
|
5
|
+
/**
|
|
6
|
+
* Error message patterns for configuration-related errors
|
|
7
|
+
*/
|
|
3
8
|
export declare const ERROR_MESSAGE_PATTERNS_TYPE_CONFIG: string[];
|
|
9
|
+
export declare const DEFAULT_REVENIUM_BASE_URL = "https://api.revenium.ai";
|
|
4
10
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,6BAA6B,UAIzC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kCAAkC,UAI9C,CAAC;AAEF,eAAO,MAAM,yBAAyB,4BAA4B,CAAC"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Centralized error handling patterns to eliminate repetitive try/catch blocks
|
|
5
5
|
* and provide consistent error logging and recovery strategies.
|
|
6
6
|
*/
|
|
7
|
-
import { Logger } from
|
|
7
|
+
import { Logger } from "../types";
|
|
8
8
|
/**
|
|
9
9
|
* Error handling strategy configuration
|
|
10
10
|
*/
|
|
@@ -88,7 +88,7 @@ export declare class NetworkError extends Error {
|
|
|
88
88
|
* Error classification utility
|
|
89
89
|
*/
|
|
90
90
|
export declare function classifyError(error: unknown): {
|
|
91
|
-
type:
|
|
91
|
+
type: "validation" | "configuration" | "network" | "unknown";
|
|
92
92
|
message: string;
|
|
93
93
|
isRetryable: boolean;
|
|
94
94
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMlC;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kCAAkC;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC;CAC5C;AAcD;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,qBAA0B,EACpC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAkBxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB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E,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBADjD,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG;IAC7C,IAAI,EAAE,YAAY,GAAG,eAAe,GAAG,SAAS,GAAG,SAAS,CAAC;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB,CAkCA"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Centralized metadata handling to eliminate repetitive spreading
|
|
5
5
|
* and provide consistent metadata processing across the codebase.
|
|
6
6
|
*/
|
|
7
|
-
import { UsageMetadata } from
|
|
7
|
+
import { UsageMetadata } from "../types";
|
|
8
8
|
/**
|
|
9
9
|
* Build metadata object for payload inclusion
|
|
10
10
|
*
|
|
@@ -45,13 +45,14 @@ export declare function extractMetadata<T extends Record<string, unknown>>(param
|
|
|
45
45
|
usageMetadata?: UsageMetadata;
|
|
46
46
|
}): {
|
|
47
47
|
metadata: UsageMetadata | undefined;
|
|
48
|
-
cleanParams: Omit<T,
|
|
48
|
+
cleanParams: Omit<T, "usageMetadata">;
|
|
49
49
|
};
|
|
50
50
|
/**
|
|
51
51
|
* Create a metadata context for consistent logging
|
|
52
|
+
* Uses sanitization to protect PII (emails are masked)
|
|
52
53
|
*
|
|
53
54
|
* @param usageMetadata - Source metadata
|
|
54
|
-
* @returns Logging context object
|
|
55
|
+
* @returns Logging context object with sanitized PII
|
|
55
56
|
*/
|
|
56
57
|
export declare function createLoggingContext(usageMetadata?: UsageMetadata): Record<string, unknown>;
|
|
57
58
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/metadata-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"metadata-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/metadata-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAuCzC;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,CAAC,EAAE,aAAa,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoBzB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,CAAC,EAAE,aAAa,EAC7B,cAAc,GAAE,CAAC,MAAM,aAAa,CAAC,EAAO,GAC3C;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CA4CA;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,GAAG,OAAO,EAAE,CAAC,aAAa,GAAG,SAAS,CAAC,EAAE,GACxC,aAAa,CAQf;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,MAAM,EAAE,CAAC,GAAG;IAAE,aAAa,CAAC,EAAE,aAAa,CAAA;CAAE,GAC5C;IACD,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,WAAW,EAAE,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;CACvC,CAMA;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,CAAC,EAAE,aAAa,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoBzB;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,aAAa,CAAC,EAAE,aAAa,GAC5B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiCzB"}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* Simplifies complex provider detection logic using strategy pattern
|
|
5
5
|
* instead of nested conditionals.
|
|
6
6
|
*/
|
|
7
|
-
import { Provider, ProviderInfo, AzureConfig } from
|
|
8
|
-
import { OpenAIClientInstance } from
|
|
9
|
-
import { Logger } from
|
|
7
|
+
import { Provider, ProviderInfo, AzureConfig } from "../types/index.js";
|
|
8
|
+
import { OpenAIClientInstance } from "../types/function-parameters.js";
|
|
9
|
+
import { Logger } from "../types/index.js";
|
|
10
10
|
/**
|
|
11
11
|
* Detect provider using strategy pattern
|
|
12
12
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-detection.d.ts","sourceRoot":"","sources":["../../../src/utils/provider-detection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"provider-detection.d.ts","sourceRoot":"","sources":["../../../src/utils/provider-detection.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAwE3C;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAsCA;AA4BD;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,WAAW,CA8Bb;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,oBAAoB,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,YAAY,CAkBd;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,YAAY,GAAG;IAChE,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAqBA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stop-reason-mapper.d.ts","sourceRoot":"","sources":["../../../src/utils/stop-reason-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"stop-reason-mapper.d.ts","sourceRoot":"","sources":["../../../src/utils/stop-reason-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgCH;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7C,MAAM,CAAC,EAAE;IAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;CAAE,GAC3D,MAAM,CAYR;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,EAAE,CAElD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE7D"}
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
* - If URL has neither → append /meter/v2 and endpoint
|
|
15
15
|
*
|
|
16
16
|
* Examples:
|
|
17
|
-
* - 'https://api.revenium.
|
|
18
|
-
* - 'https://api.revenium.
|
|
19
|
-
* - 'https://api.revenium.
|
|
17
|
+
* - 'https://api.revenium.ai' + '/ai/completions' → 'https://api.revenium.ai/meter/v2/ai/completions'
|
|
18
|
+
* - 'https://api.revenium.ai/meter' + '/ai/completions' → 'https://api.revenium.ai/meter/v2/ai/completions'
|
|
19
|
+
* - 'https://api.revenium.ai/meter/v2' + '/ai/completions' → 'https://api.revenium.ai/meter/v2/ai/completions'
|
|
20
20
|
*
|
|
21
21
|
* @param baseUrl - The base URL from configuration (may include /meter or /meter/v2)
|
|
22
22
|
* @param endpoint - The API endpoint to append (e.g., '/ai/completions')
|