@revenium/openai 1.0.13 → 1.0.15
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 +65 -11
- package/CODE_OF_CONDUCT.md +57 -0
- package/CONTRIBUTING.md +38 -0
- package/README.md +104 -216
- 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 +11 -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 +21 -0
- package/dist/cjs/core/middleware/index.js.map +1 -0
- package/dist/cjs/core/middleware/interfaces.js +454 -0
- package/dist/cjs/core/middleware/interfaces.js.map +1 -0
- package/dist/cjs/core/middleware/revenium-client.js +152 -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 +21 -14
- package/dist/cjs/core/tracking/api-client.js.map +1 -1
- package/dist/cjs/core/tracking/index.js +5 -1
- package/dist/cjs/core/tracking/index.js.map +1 -1
- package/dist/cjs/core/tracking/payload-builder.js +143 -25
- package/dist/cjs/core/tracking/payload-builder.js.map +1 -1
- package/dist/cjs/core/tracking/usage-tracker.js +111 -18
- package/dist/cjs/core/tracking/usage-tracker.js.map +1 -1
- package/dist/cjs/index.js +39 -202
- 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 +17 -16
- 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/trace-fields.js +115 -0
- package/dist/cjs/utils/trace-fields.js.map +1 -0
- 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 +13 -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 +442 -0
- package/dist/esm/core/middleware/interfaces.js.map +1 -0
- package/dist/esm/core/middleware/revenium-client.js +115 -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 +20 -13
- package/dist/esm/core/tracking/api-client.js.map +1 -1
- package/dist/esm/core/tracking/index.js +4 -4
- package/dist/esm/core/tracking/index.js.map +1 -1
- package/dist/esm/core/tracking/payload-builder.js +142 -26
- package/dist/esm/core/tracking/payload-builder.js.map +1 -1
- package/dist/esm/core/tracking/usage-tracker.js +78 -20
- package/dist/esm/core/tracking/usage-tracker.js.map +1 -1
- package/dist/esm/index.js +9 -177
- 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 +17 -16
- 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/trace-fields.js +100 -0
- package/dist/esm/utils/trace-fields.js.map +1 -0
- 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 +104 -0
- package/dist/types/core/middleware/interfaces.d.ts.map +1 -0
- package/dist/types/core/middleware/revenium-client.d.ts +64 -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/index.d.ts +4 -4
- package/dist/types/core/tracking/index.d.ts.map +1 -1
- package/dist/types/core/tracking/payload-builder.d.ts +5 -3
- package/dist/types/core/tracking/payload-builder.d.ts.map +1 -1
- package/dist/types/core/tracking/usage-tracker.d.ts +4 -2
- package/dist/types/core/tracking/usage-tracker.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -135
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/function-parameters.d.ts +91 -23
- package/dist/types/types/function-parameters.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +53 -108
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/openai-augmentation.d.ts +4 -138
- 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 +2 -2
- 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/trace-fields.d.ts +11 -0
- package/dist/types/utils/trace-fields.d.ts.map +1 -0
- package/examples/README.md +282 -198
- 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 +23 -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 -95
- 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 -137
- 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 -360
- package/src/types/function-parameters.ts +0 -251
- package/src/types/index.ts +0 -310
- package/src/types/openai-augmentation.ts +0 -232
- 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 -228
- 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 -78
- 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, // 0.0-1.0 scale per API spec
|
|
77
|
-
* agent: 'support-bot-v2'
|
|
78
|
-
* };
|
|
79
|
-
* ```
|
|
80
41
|
*/
|
|
81
42
|
export interface UsageMetadata {
|
|
82
43
|
/** User identification information (nested structure for detailed tracking) */
|
|
@@ -102,18 +63,7 @@ export interface UsageMetadata {
|
|
|
102
63
|
* Detailed information about the detected AI provider, including configuration
|
|
103
64
|
* details and Azure-specific settings when applicable. Used internally for
|
|
104
65
|
* provider-specific handling and metrics collection.
|
|
105
|
-
|
|
106
|
-
* @public
|
|
107
|
-
* @example
|
|
108
|
-
* ```typescript
|
|
109
|
-
* const providerInfo: ProviderInfo = {
|
|
110
|
-
* provider: Provider.AZURE_OPENAI,
|
|
111
|
-
* isAzure: true,
|
|
112
|
-
* endpoint: 'https://my-resource.openai.azure.com',
|
|
113
|
-
* apiVersion: '2024-02-01',
|
|
114
|
-
* deployment: 'gpt-4-turbo'
|
|
115
|
-
* };
|
|
116
|
-
* ```
|
|
66
|
+
|
|
117
67
|
*/
|
|
118
68
|
export interface ProviderInfo {
|
|
119
69
|
/** The detected AI provider type */
|
|
@@ -124,8 +74,6 @@ export interface ProviderInfo {
|
|
|
124
74
|
endpoint?: string;
|
|
125
75
|
/** API version (for Azure OpenAI) */
|
|
126
76
|
apiVersion?: string;
|
|
127
|
-
/** Deployment name (for Azure OpenAI) */
|
|
128
|
-
deployment?: string;
|
|
129
77
|
/** Complete Azure configuration when available */
|
|
130
78
|
azureConfig?: AzureConfig;
|
|
131
79
|
}
|
|
@@ -134,14 +82,6 @@ export interface ProviderInfo {
|
|
|
134
82
|
*
|
|
135
83
|
* Enumeration of AI providers supported by the Revenium middleware.
|
|
136
84
|
* Used for automatic detection, routing, and provider-specific handling.
|
|
137
|
-
*
|
|
138
|
-
* @public
|
|
139
|
-
* @example
|
|
140
|
-
* ```typescript
|
|
141
|
-
* if (providerInfo.provider === Provider.AZURE_OPENAI) {
|
|
142
|
-
* console.log('Using Azure OpenAI');
|
|
143
|
-
* }
|
|
144
|
-
* ```
|
|
145
85
|
*/
|
|
146
86
|
export declare enum Provider {
|
|
147
87
|
/** Standard OpenAI API */
|
|
@@ -155,18 +95,6 @@ export declare enum Provider {
|
|
|
155
95
|
* Configuration interface for Azure OpenAI Service integration.
|
|
156
96
|
* Provides all necessary settings for connecting to Azure OpenAI endpoints
|
|
157
97
|
* with proper authentication and resource identification.
|
|
158
|
-
*
|
|
159
|
-
* @public
|
|
160
|
-
* @example
|
|
161
|
-
* ```typescript
|
|
162
|
-
* const azureConfig: AzureConfig = {
|
|
163
|
-
* endpoint: 'https://my-resource.openai.azure.com',
|
|
164
|
-
* apiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
165
|
-
* apiVersion: '2024-02-01',
|
|
166
|
-
* deployment: 'gpt-4-turbo',
|
|
167
|
-
* tenantId: 'your-tenant-id'
|
|
168
|
-
* };
|
|
169
|
-
* ```
|
|
170
98
|
*/
|
|
171
99
|
export interface AzureConfig {
|
|
172
100
|
/** Azure OpenAI endpoint URL */
|
|
@@ -175,12 +103,6 @@ export interface AzureConfig {
|
|
|
175
103
|
apiKey?: string;
|
|
176
104
|
/** Azure OpenAI API version */
|
|
177
105
|
apiVersion?: string;
|
|
178
|
-
/** Azure OpenAI deployment name */
|
|
179
|
-
deployment?: string;
|
|
180
|
-
/** Azure tenant ID for authentication */
|
|
181
|
-
tenantId?: string;
|
|
182
|
-
/** Azure resource group name */
|
|
183
|
-
resourceGroup?: string;
|
|
184
106
|
}
|
|
185
107
|
/**
|
|
186
108
|
* Revenium configuration interface
|
|
@@ -188,17 +110,7 @@ export interface AzureConfig {
|
|
|
188
110
|
* Main configuration interface for initializing the Revenium middleware.
|
|
189
111
|
* Defines all required and optional settings for connecting to Revenium's
|
|
190
112
|
* metering API and configuring middleware behavior.
|
|
191
|
-
|
|
192
|
-
* @public
|
|
193
|
-
* @example
|
|
194
|
-
* ```typescript
|
|
195
|
-
* const config: ReveniumConfig = {
|
|
196
|
-
* reveniumApiKey: 'hak_your_revenium_api_key',
|
|
197
|
-
* reveniumBaseUrl: 'https://api.revenium.ai',
|
|
198
|
-
* debug: true,
|
|
199
|
-
* openaiApiKey: process.env.OPENAI_API_KEY
|
|
200
|
-
* };
|
|
201
|
-
* ```
|
|
113
|
+
|
|
202
114
|
*/
|
|
203
115
|
export interface ReveniumConfig {
|
|
204
116
|
/** Revenium API key for authentication (required) */
|
|
@@ -212,23 +124,17 @@ export interface ReveniumConfig {
|
|
|
212
124
|
/** OpenAI API key (optional, can be set via environment variable) */
|
|
213
125
|
openaiApiKey?: string;
|
|
214
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Alias for ReveniumConfig for internal use
|
|
129
|
+
* @public
|
|
130
|
+
*/
|
|
131
|
+
export type Config = ReveniumConfig;
|
|
215
132
|
/**
|
|
216
133
|
* Logger interface for consistent logging
|
|
217
134
|
*
|
|
218
135
|
* Standardized logging interface that allows custom logger integration
|
|
219
136
|
* while maintaining consistent log levels and metadata support throughout
|
|
220
137
|
* the middleware. Supports both structured and string metadata.
|
|
221
|
-
*
|
|
222
|
-
* @public
|
|
223
|
-
* @example
|
|
224
|
-
* ```typescript
|
|
225
|
-
* const customLogger: Logger = {
|
|
226
|
-
* debug: (msg, meta) => console.debug(`[DEBUG] ${msg}`, meta),
|
|
227
|
-
* info: (msg, meta) => console.info(`[INFO] ${msg}`, meta),
|
|
228
|
-
* warn: (msg, meta) => console.warn(`[WARN] ${msg}`, meta),
|
|
229
|
-
* error: (msg, meta) => console.error(`[ERROR] ${msg}`, meta)
|
|
230
|
-
* };
|
|
231
|
-
* ```
|
|
232
138
|
*/
|
|
233
139
|
export interface Logger {
|
|
234
140
|
/** Log debug-level messages with optional metadata */
|
|
@@ -245,8 +151,8 @@ export interface Logger {
|
|
|
245
151
|
*/
|
|
246
152
|
export interface ReveniumPayload {
|
|
247
153
|
transactionId: string;
|
|
248
|
-
operationType:
|
|
249
|
-
costType:
|
|
154
|
+
operationType: "CHAT" | "GENERATE" | "EMBED" | "CLASSIFY" | "SUMMARIZE" | "TRANSLATE" | "IMAGE" | "AUDIO" | "OTHER";
|
|
155
|
+
costType: "AI";
|
|
250
156
|
model: string;
|
|
251
157
|
provider: string;
|
|
252
158
|
modelSource?: string;
|
|
@@ -255,9 +161,9 @@ export interface ReveniumPayload {
|
|
|
255
161
|
responseTime: string;
|
|
256
162
|
requestDuration: number;
|
|
257
163
|
completionStartTime: string;
|
|
258
|
-
inputTokenCount: number;
|
|
259
|
-
outputTokenCount: number;
|
|
260
|
-
totalTokenCount: number;
|
|
164
|
+
inputTokenCount: number | null;
|
|
165
|
+
outputTokenCount: number | null;
|
|
166
|
+
totalTokenCount: number | null;
|
|
261
167
|
reasoningTokenCount: number | undefined;
|
|
262
168
|
cacheCreationTokenCount: number | undefined;
|
|
263
169
|
cacheReadTokenCount: number | undefined;
|
|
@@ -275,5 +181,44 @@ export interface ReveniumPayload {
|
|
|
275
181
|
subscriber?: Subscriber;
|
|
276
182
|
subscriptionId?: string;
|
|
277
183
|
responseQualityScore?: number;
|
|
184
|
+
requestedImageCount?: number;
|
|
185
|
+
actualImageCount?: number;
|
|
186
|
+
durationSeconds?: number;
|
|
187
|
+
characterCount?: number;
|
|
188
|
+
inputAudioTokenCount?: number;
|
|
189
|
+
outputAudioTokenCount?: number;
|
|
190
|
+
attributes?: Record<string, unknown>;
|
|
191
|
+
}
|
|
192
|
+
export interface ImageAttributes {
|
|
193
|
+
billing_unit: "per_image";
|
|
194
|
+
requested_image_count?: number;
|
|
195
|
+
actual_image_count: number;
|
|
196
|
+
resolution: string;
|
|
197
|
+
quality?: "standard" | "hd";
|
|
198
|
+
operationSubtype: "generation" | "edit" | "variation";
|
|
199
|
+
response_format?: "url" | "b64_json";
|
|
200
|
+
style?: "vivid" | "natural";
|
|
201
|
+
revised_prompt_provided?: boolean;
|
|
202
|
+
has_mask?: boolean;
|
|
203
|
+
}
|
|
204
|
+
export interface AudioTranscriptionAttributes {
|
|
205
|
+
billing_unit: "per_minute";
|
|
206
|
+
actual_duration_seconds: number;
|
|
207
|
+
operationSubtype: "transcription" | "translation";
|
|
208
|
+
language?: string;
|
|
209
|
+
target_language?: string;
|
|
210
|
+
response_format?: string;
|
|
211
|
+
temperature?: number;
|
|
212
|
+
timestamp_granularities?: string[];
|
|
213
|
+
}
|
|
214
|
+
export interface AudioSpeechAttributes {
|
|
215
|
+
billing_unit: "per_character";
|
|
216
|
+
requested_character_count: number;
|
|
217
|
+
operationSubtype: "speech_synthesis";
|
|
218
|
+
voice: string;
|
|
219
|
+
speed?: number;
|
|
220
|
+
response_format?: string;
|
|
221
|
+
audio_size_bytes?: number;
|
|
278
222
|
}
|
|
223
|
+
export type AudioAttributes = AudioTranscriptionAttributes | AudioSpeechAttributes;
|
|
279
224
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -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,cA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MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,MAAM,eAAe,GACvB,4BAA4B,GAC5B,qBAAqB,CAAC"}
|
|
@@ -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,31 +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
|
-
* }
|
|
152
|
-
* ```
|
|
153
|
-
*
|
|
154
|
-
* @example Semantic search application
|
|
155
|
-
* ```typescript
|
|
156
|
-
* usageMetadata: {
|
|
157
|
-
* subscriber: { id: 'user-456' },
|
|
158
|
-
* organizationId: 'enterprise-corp',
|
|
159
|
-
* productId: 'knowledge-base',
|
|
160
|
-
* taskType: 'semantic-search',
|
|
161
|
-
* traceId: 'search-session-789'
|
|
162
|
-
* }
|
|
163
|
-
* ```
|
|
164
|
-
*
|
|
165
65
|
* @see {@link UsageMetadata} for detailed field descriptions
|
|
166
66
|
*/
|
|
167
67
|
usageMetadata?: UsageMetadata;
|
|
@@ -173,7 +73,7 @@ declare module 'openai/resources/embeddings' {
|
|
|
173
73
|
* Extends the new Responses API to support usageMetadata for comprehensive tracking.
|
|
174
74
|
* The Responses API is OpenAI's new unified interface for agent-like applications.
|
|
175
75
|
*/
|
|
176
|
-
declare module
|
|
76
|
+
declare module "openai" {
|
|
177
77
|
namespace Responses {
|
|
178
78
|
interface ResponseCreateParams {
|
|
179
79
|
/**
|
|
@@ -182,40 +82,6 @@ declare module 'openai' {
|
|
|
182
82
|
* Enables comprehensive tracking and analytics for Responses API calls.
|
|
183
83
|
* All fields are optional and can be customized based on your application needs.
|
|
184
84
|
*
|
|
185
|
-
* @example Basic Responses API usage with metadata
|
|
186
|
-
* ```typescript
|
|
187
|
-
* const response = await openai.responses.create({
|
|
188
|
-
* model: 'gpt-4.1',
|
|
189
|
-
* input: 'Analyze this data and provide insights',
|
|
190
|
-
* usageMetadata: {
|
|
191
|
-
* subscriber: {
|
|
192
|
-
* id: 'analyst-123',
|
|
193
|
-
* email: 'analyst@company.com'
|
|
194
|
-
* },
|
|
195
|
-
* organizationId: 'data-corp',
|
|
196
|
-
* productId: 'analytics-platform',
|
|
197
|
-
* taskType: 'data-analysis',
|
|
198
|
-
* agent: 'responses-api-v1'
|
|
199
|
-
* }
|
|
200
|
-
* });
|
|
201
|
-
* ```
|
|
202
|
-
*
|
|
203
|
-
* @example Streaming Responses API with metadata
|
|
204
|
-
* ```typescript
|
|
205
|
-
* const stream = await openai.responses.create({
|
|
206
|
-
* model: 'gpt-4.1',
|
|
207
|
-
* input: [
|
|
208
|
-
* { role: 'user', content: 'Generate a detailed report' }
|
|
209
|
-
* ],
|
|
210
|
-
* stream: true,
|
|
211
|
-
* usageMetadata: {
|
|
212
|
-
* subscriber: { id: 'user-456' },
|
|
213
|
-
* taskType: 'report-generation',
|
|
214
|
-
* traceId: 'session-789'
|
|
215
|
-
* }
|
|
216
|
-
* });
|
|
217
|
-
* ```
|
|
218
|
-
*
|
|
219
85
|
* @see {@link UsageMetadata} for detailed field descriptions
|
|
220
86
|
*/
|
|
221
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"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,GAAG,SAAS,CAQf;AAED;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,UAAU,GAAE,MAAU,EACtB,OAAO,GAAE,MAAa,EACtB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,CAwBZ;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aAGtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBADjD,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED,qBAAa,kBAAmB,SAAQ,KAAK;aAGzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBADjD,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED,qBAAa,YAAa,SAAQ,KAAK;aAGnB,OAAO,CAAC,EAAE,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,7 +45,7 @@ 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
|
|
@@ -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"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function resetRegionCache(): void;
|
|
2
|
+
export declare function getEnvironment(): string | null;
|
|
3
|
+
export declare function getRegion(): Promise<string | null>;
|
|
4
|
+
export declare function getCredentialAlias(): string | null;
|
|
5
|
+
export declare function getTraceType(): string | null;
|
|
6
|
+
export declare function getTraceName(): string | null;
|
|
7
|
+
export declare function detectOperationSubtype(requestBody?: any): string | null;
|
|
8
|
+
export declare function getParentTransactionId(): string | null;
|
|
9
|
+
export declare function getTransactionName(): string | null;
|
|
10
|
+
export declare function getRetryNumber(): number;
|
|
11
|
+
//# sourceMappingURL=trace-fields.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-fields.d.ts","sourceRoot":"","sources":["../../../src/utils/trace-fields.ts"],"names":[],"mappings":"AAQA,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC;AAED,wBAAgB,cAAc,IAAI,MAAM,GAAG,IAAI,CAe9C;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA8BxD;AAED,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAWlD;AAED,wBAAgB,YAAY,IAAI,MAAM,GAAG,IAAI,CAsB5C;AAED,wBAAgB,YAAY,IAAI,MAAM,GAAG,IAAI,CAa5C;AAED,wBAAgB,sBAAsB,CAAC,WAAW,CAAC,EAAE,GAAG,GAAG,MAAM,GAAG,IAAI,CAKvE;AAED,wBAAgB,sBAAsB,IAAI,MAAM,GAAG,IAAI,CAEtD;AAED,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,IAAI,CAElD;AAED,wBAAgB,cAAc,IAAI,MAAM,CAOvC"}
|