@revenium/openai 1.0.13 → 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 +44 -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 +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 +15 -25
- 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 -195
- 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/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 +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 +16 -26
- 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 -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/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 -135
- 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 +11 -105
- 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/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 +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 -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
package/README.md
CHANGED
|
@@ -8,18 +8,21 @@
|
|
|
8
8
|
|
|
9
9
|
**Transparent TypeScript middleware for automatic Revenium usage tracking with OpenAI**
|
|
10
10
|
|
|
11
|
-
A professional-grade Node.js middleware that seamlessly integrates with OpenAI and Azure OpenAI to provide automatic usage tracking, billing analytics, and comprehensive metadata collection. Features native TypeScript support with zero type casting required and supports both
|
|
11
|
+
A professional-grade Node.js middleware that seamlessly integrates with OpenAI and Azure OpenAI to provide automatic usage tracking, billing analytics, and comprehensive metadata collection. Features native TypeScript support with zero type casting required and supports both Chat Completions API, Embeddings API, and Responses API.
|
|
12
|
+
|
|
13
|
+
**Go-aligned API for consistent cross-language development!**
|
|
12
14
|
|
|
13
15
|
## Features
|
|
14
16
|
|
|
17
|
+
- **Go-Aligned API** - Same `Initialize()`/`GetClient()` pattern as Go implementation
|
|
15
18
|
- **Seamless Integration** - Native TypeScript support, no type casting required
|
|
16
|
-
- **Optional Metadata** - Track users, organizations, and business context (
|
|
17
|
-
- **
|
|
19
|
+
- **Optional Metadata** - Track users, organizations, and business context (all fields optional)
|
|
20
|
+
- **Multiple API Support** - Chat Completions, Embeddings, and Responses API
|
|
18
21
|
- **Azure OpenAI Support** - Full Azure OpenAI integration with automatic detection
|
|
19
22
|
- **Type Safety** - Complete TypeScript support with IntelliSense
|
|
20
23
|
- **Streaming Support** - Handles regular and streaming requests seamlessly
|
|
21
24
|
- **Fire-and-Forget** - Never blocks your application flow
|
|
22
|
-
- **
|
|
25
|
+
- **Automatic .env Loading** - Loads environment variables automatically
|
|
23
26
|
|
|
24
27
|
## Getting Started
|
|
25
28
|
|
|
@@ -40,35 +43,21 @@ npm install --save-dev typescript @types/node
|
|
|
40
43
|
|
|
41
44
|
### 2. Configure Environment Variables
|
|
42
45
|
|
|
43
|
-
Create a `.env` file
|
|
46
|
+
Create a `.env` file in your project root. See [`.env.example`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/.env.example) for all available configuration options.
|
|
44
47
|
|
|
45
|
-
**
|
|
48
|
+
**Minimum required configuration:**
|
|
46
49
|
|
|
47
50
|
```env
|
|
48
|
-
REVENIUM_METERING_BASE_URL=https://api.revenium.ai
|
|
49
51
|
REVENIUM_METERING_API_KEY=hak_your_revenium_api_key_here
|
|
52
|
+
REVENIUM_METERING_BASE_URL=https://api.revenium.ai
|
|
50
53
|
OPENAI_API_KEY=sk_your_openai_api_key_here
|
|
51
54
|
```
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Run the [getting started example](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/getting_started.ts):
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
npx tsx node_modules/@revenium/openai/examples/getting_started.ts
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Or with debug logging:
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
# Linux/macOS
|
|
65
|
-
REVENIUM_DEBUG=true npx tsx node_modules/@revenium/openai/examples/getting_started.ts
|
|
56
|
+
**NOTE: Replace the placeholder values with your actual API keys.**
|
|
66
57
|
|
|
67
|
-
|
|
68
|
-
$env:REVENIUM_DEBUG="true"; npx tsx node_modules/@revenium/openai/examples/getting_started.ts
|
|
69
|
-
```
|
|
58
|
+
### 3. Run Your First Example
|
|
70
59
|
|
|
71
|
-
**For
|
|
60
|
+
**For complete examples and usage patterns, see [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).**
|
|
72
61
|
|
|
73
62
|
---
|
|
74
63
|
|
|
@@ -105,250 +94,152 @@ The middleware automatically captures comprehensive usage data:
|
|
|
105
94
|
- **Error Tracking** - Failed requests, error types, retry attempts
|
|
106
95
|
- **Environment Info** - Development vs production usage
|
|
107
96
|
|
|
108
|
-
##
|
|
109
|
-
|
|
110
|
-
### Initialization Options
|
|
111
|
-
|
|
112
|
-
The middleware supports three initialization patterns:
|
|
113
|
-
|
|
114
|
-
**Automatic (Recommended)** - Import and patch OpenAI instance:
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
import { patchOpenAIInstance } from '@revenium/openai';
|
|
118
|
-
import OpenAI from 'openai';
|
|
119
|
-
|
|
120
|
-
const openai = patchOpenAIInstance(new OpenAI());
|
|
121
|
-
// Tracking works automatically if env vars are set
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
**Explicit** - Call `initializeReveniumFromEnv()` for error handling control:
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
import { initializeReveniumFromEnv, patchOpenAIInstance } from '@revenium/openai';
|
|
128
|
-
import OpenAI from 'openai';
|
|
129
|
-
|
|
130
|
-
const result = initializeReveniumFromEnv();
|
|
131
|
-
if (!result.success) {
|
|
132
|
-
console.error('Failed to initialize:', result.message);
|
|
133
|
-
process.exit(1);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const openai = patchOpenAIInstance(new OpenAI());
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
**Manual** - Use `configure()` to set all options programmatically (see Manual Configuration below).
|
|
140
|
-
|
|
141
|
-
For detailed examples of all initialization patterns, see [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).
|
|
142
|
-
|
|
143
|
-
### Streaming Responses
|
|
144
|
-
|
|
145
|
-
Streaming is fully supported with real-time token tracking. The middleware automatically tracks streaming responses without any additional configuration.
|
|
146
|
-
|
|
147
|
-
See [`examples/openai-streaming.ts`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/openai-streaming.ts) and [`examples/azure-streaming.ts`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/azure-streaming.ts) for working streaming examples.
|
|
148
|
-
|
|
149
|
-
### Custom Metadata Tracking
|
|
150
|
-
|
|
151
|
-
Add business context to track usage by organization, user, task type, or custom identifiers. Pass a `usageMetadata` object with any of these optional fields:
|
|
152
|
-
|
|
153
|
-
| Field | Description | Use Case |
|
|
154
|
-
|-------|-------------|----------|
|
|
155
|
-
| `traceId` | Unique identifier for session or conversation tracking | Link multiple API calls together for debugging, user session analytics, or distributed tracing across services |
|
|
156
|
-
| `taskType` | Type of AI task being performed | Categorize usage by workload (e.g., "chat", "code-generation", "doc-summary") for cost analysis and optimization |
|
|
157
|
-
| `subscriber.id` | Unique user identifier | Track individual user consumption for billing, rate limiting, or user analytics |
|
|
158
|
-
| `subscriber.email` | User email address | Identify users for support, compliance, or usage reports |
|
|
159
|
-
| `subscriber.credential.name` | Authentication credential name | Track which API key or service account made the request |
|
|
160
|
-
| `subscriber.credential.value` | Authentication credential value | Associate usage with specific credentials for security auditing |
|
|
161
|
-
| `organizationId` | Organization or company identifier | Multi-tenant cost allocation, usage quotas per organization |
|
|
162
|
-
| `subscriptionId` | Subscription plan identifier | Track usage against subscription limits, identify plan upgrade opportunities |
|
|
163
|
-
| `productId` | Your product or feature identifier | Attribute AI costs to specific features in your application (e.g., "chatbot", "email-assistant") |
|
|
164
|
-
| `agent` | AI agent or bot identifier | Distinguish between multiple AI agents or automation workflows in your system |
|
|
165
|
-
| `responseQualityScore` | Custom quality rating (0.0-1.0) | Track user satisfaction or automated quality metrics for model performance analysis |
|
|
97
|
+
## API Overview
|
|
166
98
|
|
|
167
|
-
|
|
168
|
-
- [API Reference](https://revenium.readme.io/reference/meter_ai_completion) - Complete metadata field documentation
|
|
99
|
+
The middleware provides a Go-aligned API with the following main functions:
|
|
169
100
|
|
|
170
|
-
|
|
171
|
-
|
|
101
|
+
- **`Initialize(config?)`** - Initialize the middleware (from environment or explicit config)
|
|
102
|
+
- **`GetClient()`** - Get the global Revenium client instance
|
|
103
|
+
- **`Configure(config)`** - Alias for `Initialize()` for programmatic configuration
|
|
104
|
+
- **`IsInitialized()`** - Check if the middleware is initialized
|
|
105
|
+
- **`Reset()`** - Reset the global client (useful for testing)
|
|
172
106
|
|
|
173
|
-
|
|
174
|
-
- `examples/openai-responses-basic.ts` - Basic Responses API usage
|
|
175
|
-
- `examples/openai-responses-streaming.ts` - Streaming with Responses API
|
|
107
|
+
**For complete API documentation and usage examples, see [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).**
|
|
176
108
|
|
|
177
|
-
|
|
178
|
-
**Use case:** Automatic Azure OpenAI detection with deployment name resolution and accurate pricing.
|
|
109
|
+
## Metadata Fields
|
|
179
110
|
|
|
180
|
-
|
|
181
|
-
- `examples/azure-basic.ts` - Azure chat completions and embeddings
|
|
182
|
-
- `examples/azure-responses-basic.ts` - Azure Responses API integration
|
|
111
|
+
The middleware supports the following optional metadata fields for tracking:
|
|
183
112
|
|
|
184
|
-
|
|
185
|
-
|
|
113
|
+
| Field | Type | Description |
|
|
114
|
+
| ----------------------- | ------ | ----------------------------------------------------------- |
|
|
115
|
+
| `traceId` | string | Unique identifier for session or conversation tracking |
|
|
116
|
+
| `taskType` | string | Type of AI task being performed (e.g., "chat", "embedding") |
|
|
117
|
+
| `agent` | string | AI agent or bot identifier |
|
|
118
|
+
| `organizationId` | string | Organization or company identifier |
|
|
119
|
+
| `productId` | string | Your product or feature identifier |
|
|
120
|
+
| `subscriptionId` | string | Subscription plan identifier |
|
|
121
|
+
| `responseQualityScore` | number | Custom quality rating (0.0-1.0) |
|
|
122
|
+
| `subscriber.id` | string | Unique user identifier |
|
|
123
|
+
| `subscriber.email` | string | User email address |
|
|
124
|
+
| `subscriber.credential` | object | Authentication credential (`name` and `value` fields) |
|
|
186
125
|
|
|
187
|
-
|
|
188
|
-
- `examples/openai-basic.ts` - Text embeddings with metadata
|
|
189
|
-
- `examples/openai-streaming.ts` - Batch embeddings processing
|
|
126
|
+
**All metadata fields are optional.** For complete metadata documentation and usage examples, see:
|
|
190
127
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
For advanced use cases, configure the middleware manually:
|
|
194
|
-
|
|
195
|
-
```typescript
|
|
196
|
-
import { configure, patchOpenAIInstance } from '@revenium/openai';
|
|
197
|
-
import OpenAI from 'openai';
|
|
198
|
-
|
|
199
|
-
configure({
|
|
200
|
-
reveniumApiKey: 'hak_your_api_key',
|
|
201
|
-
reveniumBaseUrl: 'https://api.revenium.ai',
|
|
202
|
-
debug: true,
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
const openai = patchOpenAIInstance(new OpenAI());
|
|
206
|
-
```
|
|
128
|
+
- [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md) - All usage examples
|
|
129
|
+
- [Revenium API Reference](https://revenium.readme.io/reference/meter_ai_completion) - Complete API documentation
|
|
207
130
|
|
|
208
131
|
## Configuration Options
|
|
209
132
|
|
|
210
133
|
### Environment Variables
|
|
211
134
|
|
|
212
|
-
|
|
213
|
-
| ------------------------------ | -------- | ------------------------------- | ---------------------------------------------- |
|
|
214
|
-
| `REVENIUM_METERING_API_KEY` | true | - | Your Revenium API key (starts with `hak_`) |
|
|
215
|
-
| `OPENAI_API_KEY` | true | - | Your OpenAI API key (starts with `sk-`) |
|
|
216
|
-
| `REVENIUM_METERING_BASE_URL` | false | `https://api.revenium.ai` | Revenium metering API base URL |
|
|
217
|
-
| `REVENIUM_DEBUG` | false | `false` | Enable debug logging (`true`/`false`) |
|
|
218
|
-
| `AZURE_OPENAI_ENDPOINT` | false | - | Azure OpenAI endpoint URL (for Azure testing) |
|
|
219
|
-
| `AZURE_OPENAI_API_KEY` | false | - | Azure OpenAI API key (for Azure testing) |
|
|
220
|
-
| `AZURE_OPENAI_DEPLOYMENT` | false | - | Azure OpenAI deployment name (for Azure) |
|
|
221
|
-
| `AZURE_OPENAI_API_VERSION` | false | `2024-12-01-preview` | Azure OpenAI API version (for Azure) |
|
|
135
|
+
For a complete list of all available environment variables with examples, see [`.env.example`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/.env.example).
|
|
222
136
|
|
|
223
|
-
|
|
137
|
+
## Examples
|
|
224
138
|
|
|
225
|
-
|
|
226
|
-
- If you don't set it explicitly, the middleware will use the default production endpoint
|
|
227
|
-
- However, you may see console warnings or errors if the middleware cannot determine the correct environment
|
|
228
|
-
- **Best practice:** Always set this variable explicitly to match your environment:
|
|
139
|
+
The package includes comprehensive examples in the [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/) directory.
|
|
229
140
|
|
|
230
|
-
|
|
231
|
-
# Default production URL (recommended)
|
|
232
|
-
REVENIUM_METERING_BASE_URL=https://api.revenium.ai
|
|
233
|
-
```
|
|
141
|
+
### Getting Started
|
|
234
142
|
|
|
235
|
-
|
|
143
|
+
```bash
|
|
144
|
+
npm run example:getting-started
|
|
145
|
+
```
|
|
236
146
|
|
|
237
|
-
|
|
147
|
+
### OpenAI Examples
|
|
238
148
|
|
|
239
|
-
|
|
149
|
+
| Example | Command | Description |
|
|
150
|
+
| ------------------------------- | ----------------------------------- | --------------------------------- |
|
|
151
|
+
| `openai/basic.ts` | `npm run example:openai-basic` | Chat completions and embeddings |
|
|
152
|
+
| `openai/metadata.ts` | `npm run example:openai-metadata` | All metadata fields demonstration |
|
|
153
|
+
| `openai/streaming.ts` | `npm run example:openai-stream` | Streaming chat completions |
|
|
154
|
+
| `openai/responses-basic.ts` | `npm run example:openai-res-basic` | Responses API usage |
|
|
155
|
+
| `openai/responses-embed.ts` | `npm run example:openai-res-embed` | Embeddings with Responses API |
|
|
156
|
+
| `openai/responses-streaming.ts` | `npm run example:openai-res-stream` | Streaming Responses API |
|
|
240
157
|
|
|
241
|
-
|
|
242
|
-
- **Chat Completions** - Basic and streaming usage patterns
|
|
243
|
-
- **Responses API** - OpenAI's new API with simplified interface
|
|
244
|
-
- **Azure OpenAI** - Automatic Azure detection and integration
|
|
245
|
-
- **Embeddings** - Text embedding generation with tracking
|
|
158
|
+
### Azure OpenAI Examples
|
|
246
159
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
160
|
+
| Example | Command | Description |
|
|
161
|
+
| --------------------------- | ---------------------------------- | ----------------------------- |
|
|
162
|
+
| `azure/basic.ts` | `npm run example:azure-basic` | Azure chat completions |
|
|
163
|
+
| `azure/stream.ts` | `npm run example:azure-stream` | Azure streaming |
|
|
164
|
+
| `azure/responses-basic.ts` | `npm run example:azure-res-basic` | Azure Responses API |
|
|
165
|
+
| `azure/responses-stream.ts` | `npm run example:azure-res-stream` | Azure Responses API streaming |
|
|
251
166
|
|
|
252
|
-
For complete example documentation, setup instructions, and
|
|
167
|
+
**For complete example documentation, setup instructions, and usage patterns, see [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md).**
|
|
253
168
|
|
|
254
169
|
## How It Works
|
|
255
170
|
|
|
256
|
-
1. **
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
- `embeddings.create` (Embeddings API)
|
|
260
|
-
2. **Request Interception**: All OpenAI requests are intercepted to extract metadata
|
|
261
|
-
3. **Usage Extraction**: Token counts, model info, and timing data are captured
|
|
171
|
+
1. **Initialize**: Call `Initialize()` to set up the middleware with your configuration
|
|
172
|
+
2. **Get Client**: Call `GetClient()` to get a wrapped OpenAI client instance
|
|
173
|
+
3. **Make Requests**: Use the client normally - all requests are automatically tracked
|
|
262
174
|
4. **Async Tracking**: Usage data is sent to Revenium in the background (fire-and-forget)
|
|
263
175
|
5. **Transparent Response**: Original OpenAI responses are returned unchanged
|
|
264
176
|
|
|
265
177
|
The middleware never blocks your application - if Revenium tracking fails, your OpenAI requests continue normally.
|
|
266
178
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
### Common Issues
|
|
270
|
-
|
|
271
|
-
#### No tracking data appears
|
|
272
|
-
|
|
273
|
-
Ensure environment variables are set and enable debug logging:
|
|
179
|
+
**Supported APIs:**
|
|
274
180
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
export REVENIUM_DEBUG=true
|
|
279
|
-
```
|
|
181
|
+
- Chat Completions API (`client.chat().completions().create()`)
|
|
182
|
+
- Embeddings API (`client.embeddings().create()`)
|
|
183
|
+
- Responses API (`client.responses().create()` and `client.responses().createStreaming()`)
|
|
280
184
|
|
|
281
|
-
|
|
282
|
-
```
|
|
283
|
-
[Revenium Debug] OpenAI chat.completions.create intercepted
|
|
284
|
-
[Revenium Debug] Revenium tracking successful
|
|
285
|
-
```
|
|
185
|
+
## Troubleshooting
|
|
286
186
|
|
|
287
|
-
|
|
187
|
+
### Common Issues
|
|
288
188
|
|
|
289
|
-
|
|
189
|
+
**No tracking data appears:**
|
|
290
190
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
191
|
+
1. Verify environment variables are set correctly in `.env`
|
|
192
|
+
2. Enable debug logging by setting `REVENIUM_DEBUG=true` in `.env`
|
|
193
|
+
3. Check console for `[Revenium]` log messages
|
|
194
|
+
4. Verify your `REVENIUM_METERING_API_KEY` is valid
|
|
295
195
|
|
|
296
|
-
|
|
196
|
+
**Client not initialized error:**
|
|
297
197
|
|
|
298
|
-
|
|
198
|
+
- Make sure you call `Initialize()` before `GetClient()`
|
|
199
|
+
- Check that your `.env` file is in the project root
|
|
200
|
+
- Verify `REVENIUM_METERING_API_KEY` is set
|
|
299
201
|
|
|
300
|
-
|
|
301
|
-
import { AzureOpenAI } from 'openai';
|
|
302
|
-
import { patchOpenAIInstance } from '@revenium/openai';
|
|
202
|
+
**Azure OpenAI not working:**
|
|
303
203
|
|
|
304
|
-
|
|
305
|
-
|
|
204
|
+
- Verify all Azure environment variables are set (see `.env.example`)
|
|
205
|
+
- Check that `AZURE_OPENAI_ENDPOINT` and `AZURE_OPENAI_API_KEY` are correct
|
|
206
|
+
- Ensure you're using a valid deployment name in the `model` parameter
|
|
306
207
|
|
|
307
208
|
### Debug Mode
|
|
308
209
|
|
|
309
|
-
Enable detailed logging
|
|
210
|
+
Enable detailed logging by adding to your `.env`:
|
|
310
211
|
|
|
311
|
-
```
|
|
312
|
-
|
|
212
|
+
```env
|
|
213
|
+
REVENIUM_DEBUG=true
|
|
313
214
|
```
|
|
314
215
|
|
|
315
216
|
### Getting Help
|
|
316
217
|
|
|
317
218
|
If issues persist:
|
|
318
219
|
|
|
319
|
-
1.
|
|
320
|
-
2.
|
|
321
|
-
3.
|
|
220
|
+
1. Enable debug logging (`REVENIUM_DEBUG=true`)
|
|
221
|
+
2. Check the [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/) directory for working examples
|
|
222
|
+
3. Review [`examples/README.md`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/README.md) for detailed setup instructions
|
|
322
223
|
4. Contact support@revenium.io with debug logs
|
|
323
224
|
|
|
324
225
|
## Supported Models
|
|
325
226
|
|
|
326
|
-
This middleware works with any OpenAI model.
|
|
227
|
+
This middleware works with any OpenAI model. For the complete model list, see the [OpenAI Models Documentation](https://platform.openai.com/docs/models).
|
|
327
228
|
|
|
328
|
-
|
|
329
|
-
- `gpt-4o-mini`, `gpt-4o` (GPT-4 family)
|
|
330
|
-
- `gpt-5`, `gpt-5-mini`, `gpt-5-nano` (GPT-5 family)
|
|
331
|
-
|
|
332
|
-
**Embeddings:**
|
|
333
|
-
- `text-embedding-3-small`, `text-embedding-3-large`
|
|
334
|
-
|
|
335
|
-
**Azure OpenAI:**
|
|
336
|
-
- Works with any Azure deployment (deployment names automatically resolved)
|
|
229
|
+
### API Support Matrix
|
|
337
230
|
|
|
338
|
-
|
|
231
|
+
The following table shows what has been tested and verified with working examples:
|
|
339
232
|
|
|
340
|
-
|
|
233
|
+
| Feature | Chat Completions | Embeddings | Responses API |
|
|
234
|
+
| --------------------- | ---------------- | ---------- | ------------- |
|
|
235
|
+
| **OpenAI Basic** | Yes | Yes | Yes |
|
|
236
|
+
| **OpenAI Streaming** | Yes | No | Yes |
|
|
237
|
+
| **Azure Basic** | Yes | No | Yes |
|
|
238
|
+
| **Azure Streaming** | Yes | No | Yes |
|
|
239
|
+
| **Metadata Tracking** | Yes | Yes | Yes |
|
|
240
|
+
| **Token Counting** | Yes | Yes | Yes |
|
|
341
241
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
| Feature | Chat Completions API | Responses API | Embeddings API |
|
|
345
|
-
| --------------------- | -------------------- | ------------- | -------------- |
|
|
346
|
-
| **Basic Requests** | Yes | Yes | Yes |
|
|
347
|
-
| **Streaming** | Yes | Yes | No |
|
|
348
|
-
| **Metadata Tracking** | Yes | Yes | Yes |
|
|
349
|
-
| **Azure OpenAI** | Yes | Yes | Yes |
|
|
350
|
-
| **Cost Calculation** | Yes | Yes | Yes |
|
|
351
|
-
| **Token Counting** | Yes | Yes | Yes |
|
|
242
|
+
**Note:** "Yes" = Tested with working examples in [`examples/`](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/examples/) directory
|
|
352
243
|
|
|
353
244
|
## Documentation
|
|
354
245
|
|
|
@@ -374,14 +265,11 @@ This project is licensed under the MIT License - see the [LICENSE](https://githu
|
|
|
374
265
|
|
|
375
266
|
For issues, feature requests, or contributions:
|
|
376
267
|
|
|
268
|
+
- **Website**: [www.revenium.ai](https://www.revenium.ai)
|
|
377
269
|
- **GitHub Repository**: [revenium/revenium-middleware-openai-node](https://github.com/revenium/revenium-middleware-openai-node)
|
|
378
270
|
- **Issues**: [Report bugs or request features](https://github.com/revenium/revenium-middleware-openai-node/issues)
|
|
379
271
|
- **Documentation**: [docs.revenium.io](https://docs.revenium.io)
|
|
380
|
-
- **
|
|
381
|
-
|
|
382
|
-
## Development
|
|
383
|
-
|
|
384
|
-
For development and testing instructions, see [DEVELOPMENT.md](https://github.com/revenium/revenium-middleware-openai-node/blob/HEAD/DEVELOPMENT.md).
|
|
272
|
+
- **Email**: support@revenium.io
|
|
385
273
|
|
|
386
274
|
---
|
|
387
275
|
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
If you discover a security vulnerability in this package, please report it to us.
|
|
6
|
+
|
|
7
|
+
**DO NOT** create a public GitHub issue for security vulnerabilities.
|
|
8
|
+
|
|
9
|
+
### How to Report
|
|
10
|
+
|
|
11
|
+
Email: support@revenium.io
|
|
12
|
+
|
|
13
|
+
Please include:
|
|
14
|
+
- Package name and version
|
|
15
|
+
- Description of the vulnerability
|
|
16
|
+
- Steps to reproduce (if applicable)
|
|
17
|
+
- Potential impact
|
|
18
|
+
- Suggested fix (if available)
|
|
19
|
+
|
|
20
|
+
We will review and respond to security reports in a timely manner.
|
|
21
|
+
|
|
22
|
+
## Security Best Practices
|
|
23
|
+
|
|
24
|
+
When using this middleware:
|
|
25
|
+
|
|
26
|
+
1. **API Keys**: Never commit API keys to version control
|
|
27
|
+
2. **Environment Variables**: Use environment variables for sensitive configuration
|
|
28
|
+
3. **PII Handling**: Ensure no PII is sent to Revenium unless explicitly configured for billing purposes
|
|
29
|
+
4. **Network Security**: Always use HTTPS connections
|
|
30
|
+
5. **Updates**: Keep the package updated to the latest version
|
|
31
|
+
|
|
32
|
+
## Additional Resources
|
|
33
|
+
|
|
34
|
+
- [Revenium Documentation](https://docs.revenium.io)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Client Module
|
|
4
|
+
* Exports client management functions.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Configure = exports.Reset = exports.IsInitialized = exports.GetClient = exports.Initialize = void 0;
|
|
8
|
+
var manager_js_1 = require("./manager.js");
|
|
9
|
+
Object.defineProperty(exports, "Initialize", { enumerable: true, get: function () { return manager_js_1.Initialize; } });
|
|
10
|
+
Object.defineProperty(exports, "GetClient", { enumerable: true, get: function () { return manager_js_1.GetClient; } });
|
|
11
|
+
Object.defineProperty(exports, "IsInitialized", { enumerable: true, get: function () { return manager_js_1.IsInitialized; } });
|
|
12
|
+
Object.defineProperty(exports, "Reset", { enumerable: true, get: function () { return manager_js_1.Reset; } });
|
|
13
|
+
Object.defineProperty(exports, "Configure", { enumerable: true, get: function () { return manager_js_1.Configure; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/client/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAMsB;AALpB,wGAAA,UAAU,OAAA;AACV,uGAAA,SAAS,OAAA;AACT,2GAAA,aAAa,OAAA;AACb,mGAAA,KAAK,OAAA;AACL,uGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Client Manager
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Initialize = Initialize;
|
|
7
|
+
exports.GetClient = GetClient;
|
|
8
|
+
exports.IsInitialized = IsInitialized;
|
|
9
|
+
exports.Reset = Reset;
|
|
10
|
+
exports.Configure = Configure;
|
|
11
|
+
const revenium_client_js_1 = require("../middleware/revenium-client.js");
|
|
12
|
+
const config_1 = require("../config");
|
|
13
|
+
const providers_1 = require("../providers");
|
|
14
|
+
const config_2 = require("../config");
|
|
15
|
+
const constants_js_1 = require("../../utils/constants.js");
|
|
16
|
+
// Global client singleton
|
|
17
|
+
let globalClient = null;
|
|
18
|
+
// Global logger
|
|
19
|
+
const logger = (0, config_2.getLogger)();
|
|
20
|
+
/**
|
|
21
|
+
* Initialize - Initialize Revenium client
|
|
22
|
+
* Can be called with explicit config or will load from environment variables.
|
|
23
|
+
* @param config - Optional configuration. If not provided, loads from environment.
|
|
24
|
+
*/
|
|
25
|
+
function Initialize(config) {
|
|
26
|
+
logger.debug("Initializing Revenium client");
|
|
27
|
+
let finalConfig;
|
|
28
|
+
if (config) {
|
|
29
|
+
// Merge provided config with defaults
|
|
30
|
+
const defaultConfig = {
|
|
31
|
+
reveniumBaseUrl: constants_js_1.DEFAULT_REVENIUM_BASE_URL,
|
|
32
|
+
debug: false,
|
|
33
|
+
};
|
|
34
|
+
finalConfig = {
|
|
35
|
+
...defaultConfig,
|
|
36
|
+
...config,
|
|
37
|
+
};
|
|
38
|
+
logger.debug("Using provided configuration");
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
// Load from environment variables
|
|
42
|
+
const envLoaded = (0, config_1.initializeConfig)();
|
|
43
|
+
if (!envLoaded) {
|
|
44
|
+
throw new Error("Failed to load configuration from environment variables. " +
|
|
45
|
+
"Ensure REVENIUM_METERING_API_KEY and OPENAI_API_KEY are set, " +
|
|
46
|
+
"or provide configuration explicitly to Initialize().");
|
|
47
|
+
}
|
|
48
|
+
finalConfig = (0, config_1.getConfig)();
|
|
49
|
+
logger.debug("Loaded configuration from environment");
|
|
50
|
+
}
|
|
51
|
+
// Validate configuration
|
|
52
|
+
try {
|
|
53
|
+
(0, config_1.validateConfig)(finalConfig);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
logger.error("Configuration validation failed", {
|
|
57
|
+
error: error instanceof Error ? error.message : String(error),
|
|
58
|
+
});
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
// Store config globally
|
|
62
|
+
(0, config_1.setConfig)(finalConfig);
|
|
63
|
+
// Detect provider from configuration
|
|
64
|
+
const providerInfo = (0, providers_1.detectProviderFromConfig)(finalConfig);
|
|
65
|
+
logger.info("Detected provider", {
|
|
66
|
+
provider: providerInfo.provider,
|
|
67
|
+
isAzure: providerInfo.isAzure,
|
|
68
|
+
});
|
|
69
|
+
// Create global client
|
|
70
|
+
globalClient = new revenium_client_js_1.ReveniumOpenAI(finalConfig, providerInfo.provider);
|
|
71
|
+
logger.info("Revenium client initialized successfully");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* GetClient - Get the global Revenium client
|
|
75
|
+
* @returns The global ReveniumOpenAI client
|
|
76
|
+
* @throws Error if client is not initialized
|
|
77
|
+
*/
|
|
78
|
+
function GetClient() {
|
|
79
|
+
if (!globalClient) {
|
|
80
|
+
throw new Error("Revenium client not initialized. Call Initialize() first.\n\n" +
|
|
81
|
+
"Example:\n" +
|
|
82
|
+
' import { Initialize, GetClient } from "@revenium/openai";\n' +
|
|
83
|
+
" Initialize();\n" +
|
|
84
|
+
" const client = GetClient();");
|
|
85
|
+
}
|
|
86
|
+
return globalClient;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* IsInitialized - Check if client is initialized
|
|
90
|
+
* @returns true if client is initialized, false otherwise
|
|
91
|
+
*/
|
|
92
|
+
function IsInitialized() {
|
|
93
|
+
return globalClient !== null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Reset - Reset the global client
|
|
97
|
+
*/
|
|
98
|
+
function Reset() {
|
|
99
|
+
logger.debug("Resetting global client");
|
|
100
|
+
globalClient = null;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Configure - Alias for Initialize
|
|
104
|
+
* @param config - Configuration object
|
|
105
|
+
*/
|
|
106
|
+
function Configure(config) {
|
|
107
|
+
Initialize(config);
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../../src/core/client/manager.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAyBH,gCA0DC;AAOD,8BAWC;AAMD,sCAEC;AAKD,sBAGC;AAMD,8BAEC;AA3HD,yEAAkE;AAElE,sCAKmB;AACnB,4CAAwD;AACxD,sCAAsC;AACtC,2DAAqE;AAErE,0BAA0B;AAC1B,IAAI,YAAY,GAA0B,IAAI,CAAC;AAE/C,gBAAgB;AAChB,MAAM,MAAM,GAAG,IAAA,kBAAS,GAAE,CAAC;AAE3B;;;;GAIG;AACH,SAAgB,UAAU,CAAC,MAAwB;IACjD,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAE7C,IAAI,WAAmB,CAAC;IAExB,IAAI,MAAM,EAAE,CAAC;QACX,sCAAsC;QACtC,MAAM,aAAa,GAAG;YACpB,eAAe,EAAE,wCAAyB;YAC1C,KAAK,EAAE,KAAK;SACb,CAAC;QAEF,WAAW,GAAG;YACZ,GAAG,aAAa;YAChB,GAAG,MAAM;SACA,CAAC;QAEZ,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC/C,CAAC;SAAM,CAAC;QACN,kCAAkC;QAClC,MAAM,SAAS,GAAG,IAAA,yBAAgB,GAAE,CAAC;QAErC,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,2DAA2D;gBACzD,+DAA+D;gBAC/D,sDAAsD,CACzD,CAAC;QACJ,CAAC;QAED,WAAW,GAAG,IAAA,kBAAS,GAAG,CAAC;QAC3B,MAAM,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;IACxD,CAAC;IAED,yBAAyB;IACzB,IAAI,CAAC;QACH,IAAA,uBAAc,EAAC,WAAW,CAAC,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE;YAC9C,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC,CAAC;QACH,MAAM,KAAK,CAAC;IACd,CAAC;IAED,wBAAwB;IACxB,IAAA,kBAAS,EAAC,WAAW,CAAC,CAAC;IAEvB,qCAAqC;IACrC,MAAM,YAAY,GAAG,IAAA,oCAAwB,EAAC,WAAW,CAAC,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,mBAAmB,EAAE;QAC/B,QAAQ,EAAE,YAAY,CAAC,QAAQ;QAC/B,OAAO,EAAE,YAAY,CAAC,OAAO;KAC9B,CAAC,CAAC;IAEH,uBAAuB;IACvB,YAAY,GAAG,IAAI,mCAAc,CAAC,WAAW,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,SAAgB,SAAS;IACvB,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,+DAA+D;YAC7D,YAAY;YACZ,+DAA+D;YAC/D,mBAAmB;YACnB,+BAA+B,CAClC,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,SAAgB,aAAa;IAC3B,OAAO,YAAY,KAAK,IAAI,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,SAAgB,KAAK;IACnB,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACxC,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,MAAuB;IAC/C,UAAU,CAAC,MAAM,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -21,41 +21,29 @@ function gatherAzureConfig(client) {
|
|
|
21
21
|
try {
|
|
22
22
|
// Extract from client baseURL if available
|
|
23
23
|
if (client?.baseURL) {
|
|
24
|
-
const baseUrl = typeof client.baseURL ===
|
|
24
|
+
const baseUrl = typeof client.baseURL === "string"
|
|
25
|
+
? client.baseURL
|
|
26
|
+
: client.baseURL?.toString();
|
|
25
27
|
config.endpoint = baseUrl;
|
|
26
28
|
}
|
|
27
29
|
// Extract from environment variables
|
|
28
30
|
if (process.env.AZURE_OPENAI_ENDPOINT) {
|
|
29
31
|
config.endpoint = process.env.AZURE_OPENAI_ENDPOINT;
|
|
30
32
|
}
|
|
31
|
-
if (process.env.AZURE_OPENAI_DEPLOYMENT) {
|
|
32
|
-
config.deployment = process.env.AZURE_OPENAI_DEPLOYMENT;
|
|
33
|
-
}
|
|
34
33
|
if (process.env.AZURE_OPENAI_API_VERSION) {
|
|
35
34
|
config.apiVersion = process.env.AZURE_OPENAI_API_VERSION;
|
|
36
35
|
}
|
|
37
|
-
else {
|
|
38
|
-
// Default to preferred API version from Python learnings
|
|
39
|
-
config.apiVersion = '2024-12-01-preview';
|
|
40
|
-
}
|
|
41
36
|
if (process.env.AZURE_OPENAI_API_KEY) {
|
|
42
37
|
config.apiKey = process.env.AZURE_OPENAI_API_KEY;
|
|
43
38
|
}
|
|
44
|
-
|
|
45
|
-
config.tenantId = process.env.AZURE_OPENAI_TENANT_ID;
|
|
46
|
-
}
|
|
47
|
-
if (process.env.AZURE_OPENAI_RESOURCE_GROUP) {
|
|
48
|
-
config.resourceGroup = process.env.AZURE_OPENAI_RESOURCE_GROUP;
|
|
49
|
-
}
|
|
50
|
-
logger.debug('Azure configuration gathered', {
|
|
39
|
+
logger.debug("Azure configuration gathered", {
|
|
51
40
|
hasEndpoint: !!config.endpoint,
|
|
52
|
-
hasDeployment: !!config.deployment,
|
|
53
41
|
hasApiKey: !!config.apiKey,
|
|
54
42
|
apiVersion: config.apiVersion,
|
|
55
43
|
});
|
|
56
44
|
}
|
|
57
45
|
catch (error) {
|
|
58
|
-
logger.warn(
|
|
46
|
+
logger.warn("Error gathering Azure configuration", {
|
|
59
47
|
error: error instanceof Error ? error.message : String(error),
|
|
60
48
|
});
|
|
61
49
|
}
|