@revenium/perplexity 2.0.5 → 2.0.7

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +113 -97
  2. package/LICENSE +21 -21
  3. package/README.md +376 -290
  4. package/SECURITY.md +34 -34
  5. package/dist/cjs/core/client/manager.js +6 -3
  6. package/dist/cjs/core/client/manager.js.map +1 -1
  7. package/dist/cjs/core/config/index.js +0 -1
  8. package/dist/cjs/core/config/index.js.map +1 -1
  9. package/dist/cjs/core/config/manager.js +0 -1
  10. package/dist/cjs/core/config/manager.js.map +1 -1
  11. package/dist/cjs/core/config/validator.js +18 -16
  12. package/dist/cjs/core/config/validator.js.map +1 -1
  13. package/dist/cjs/core/middleware/interfaces.js +4 -4
  14. package/dist/cjs/core/middleware/interfaces.js.map +1 -1
  15. package/dist/cjs/core/middleware/streaming-wrapper.js +4 -4
  16. package/dist/cjs/core/middleware/streaming-wrapper.js.map +1 -1
  17. package/dist/cjs/core/providers/detector.js +0 -2
  18. package/dist/cjs/core/providers/detector.js.map +1 -1
  19. package/dist/cjs/core/providers/index.js +0 -1
  20. package/dist/cjs/core/providers/index.js.map +1 -1
  21. package/dist/cjs/core/tracking/api-client.js +3 -3
  22. package/dist/cjs/core/tracking/api-client.js.map +1 -1
  23. package/dist/cjs/index.js +2 -40
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/utils/stop-reason-mapper.js +18 -20
  26. package/dist/cjs/utils/stop-reason-mapper.js.map +1 -1
  27. package/dist/esm/core/client/manager.js +6 -3
  28. package/dist/esm/core/client/manager.js.map +1 -1
  29. package/dist/esm/core/config/index.js +3 -4
  30. package/dist/esm/core/config/index.js.map +1 -1
  31. package/dist/esm/core/config/manager.js +0 -1
  32. package/dist/esm/core/config/manager.js.map +1 -1
  33. package/dist/esm/core/config/validator.js +18 -16
  34. package/dist/esm/core/config/validator.js.map +1 -1
  35. package/dist/esm/core/middleware/interfaces.js +1 -1
  36. package/dist/esm/core/middleware/interfaces.js.map +1 -1
  37. package/dist/esm/core/middleware/streaming-wrapper.js +2 -2
  38. package/dist/esm/core/middleware/streaming-wrapper.js.map +1 -1
  39. package/dist/esm/core/providers/detector.js +0 -2
  40. package/dist/esm/core/providers/detector.js.map +1 -1
  41. package/dist/esm/core/providers/index.js +0 -1
  42. package/dist/esm/core/providers/index.js.map +1 -1
  43. package/dist/esm/core/tracking/api-client.js +1 -1
  44. package/dist/esm/core/tracking/api-client.js.map +1 -1
  45. package/dist/esm/index.js +1 -38
  46. package/dist/esm/index.js.map +1 -1
  47. package/dist/esm/utils/stop-reason-mapper.js +18 -20
  48. package/dist/esm/utils/stop-reason-mapper.js.map +1 -1
  49. package/dist/types/core/client/manager.d.ts.map +1 -1
  50. package/dist/types/core/config/index.d.ts +3 -4
  51. package/dist/types/core/config/index.d.ts.map +1 -1
  52. package/dist/types/core/config/manager.d.ts +0 -1
  53. package/dist/types/core/config/manager.d.ts.map +1 -1
  54. package/dist/types/core/config/validator.d.ts.map +1 -1
  55. package/dist/types/core/providers/detector.d.ts +0 -2
  56. package/dist/types/core/providers/detector.d.ts.map +1 -1
  57. package/dist/types/core/providers/index.d.ts +0 -1
  58. package/dist/types/core/providers/index.d.ts.map +1 -1
  59. package/dist/types/index.d.ts +2 -37
  60. package/dist/types/index.d.ts.map +1 -1
  61. package/dist/types/types/index.d.ts +1 -1
  62. package/dist/types/utils/stop-reason-mapper.d.ts +1 -3
  63. package/dist/types/utils/stop-reason-mapper.d.ts.map +1 -1
  64. package/examples/README.md +230 -226
  65. package/examples/advanced.ts +123 -123
  66. package/examples/basic.ts +45 -45
  67. package/examples/getting_started.ts +41 -41
  68. package/examples/metadata.ts +68 -68
  69. package/examples/stream.ts +53 -53
  70. package/package.json +72 -71
  71. package/dist/cjs/constants/models.js +0 -38
  72. package/dist/cjs/constants/models.js.map +0 -1
  73. package/dist/esm/constants/models.js +0 -35
  74. package/dist/esm/constants/models.js.map +0 -1
  75. package/dist/types/constants/models.d.ts +0 -39
  76. package/dist/types/constants/models.d.ts.map +0 -1
@@ -1,226 +1,230 @@
1
- # Revenium Perplexity Middleware - Examples
2
-
3
- This directory contains examples demonstrating how to use the Revenium Perplexity middleware.
4
-
5
- ## Prerequisites
6
-
7
- Before running the examples, make sure you have:
8
-
9
- 1. **Node.js 20 or later** installed
10
- 2. **Revenium API Key** - Get one from [Revenium Dashboard](https://app.revenium.io)
11
- 3. **Perplexity API Key** - Get one from [Perplexity Platform](https://www.perplexity.ai)
12
-
13
- ## Setup
14
-
15
- 1. **Clone the repository** (if you haven't already):
16
-
17
- ```bash
18
- git clone https://github.com/revenium/revenium-middleware-perplexity-node.git
19
- cd revenium-middleware-perplexity-node
20
- ```
21
-
22
- 2. **Install dependencies**:
23
-
24
- ```bash
25
- npm install
26
- ```
27
-
28
- 3. **Configure environment variables**:
29
-
30
- Copy the `.env.example` file to `.env` and edit it with your API keys:
31
-
32
- ```bash
33
- cp .env.example .env
34
- ```
35
-
36
- See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all available configuration options.
37
-
38
- ## Examples
39
-
40
- ### 1. Getting Started
41
-
42
- **File:** `getting_started.ts`
43
-
44
- The simplest example to get you started with Revenium tracking:
45
-
46
- - Initialize the middleware
47
- - Create a basic chat completion
48
- - Display response and usage metrics
49
-
50
- **Run:**
51
-
52
- ```bash
53
- npm run example:getting-started
54
- # or
55
- npx tsx examples/getting_started.ts
56
- ```
57
-
58
- **What it does:**
59
-
60
- - Loads configuration from environment variables
61
- - Creates a simple chat completion request
62
- - Automatically sends metering data to Revenium API
63
- - Displays the response
64
-
65
- ---
66
-
67
- ### 2. Basic Usage
68
-
69
- **File:** `basic.ts`
70
-
71
- Demonstrates standard Perplexity API usage:
72
-
73
- - Chat completions with metadata
74
- - Simple metadata tracking
75
-
76
- **Run:**
77
-
78
- ```bash
79
- npm run example:basic
80
- # or
81
- npx tsx examples/basic.ts
82
- ```
83
-
84
- **What it does:**
85
-
86
- - Creates chat completions with metadata tracking
87
- - Demonstrates basic metadata usage
88
-
89
- ---
90
-
91
- ### 3. Metadata
92
-
93
- **File:** `metadata.ts`
94
-
95
- Demonstrates all available metadata fields:
96
-
97
- - Complete metadata structure
98
- - All optional fields documented
99
- - Subscriber information
100
-
101
- **Run:**
102
-
103
- ```bash
104
- npm run example:metadata
105
- # or
106
- npx tsx examples/metadata.ts
107
- ```
108
-
109
- **What it does:**
110
-
111
- - Shows all available metadata fields
112
- - Demonstrates subscriber tracking
113
- - Includes organization and product tracking
114
-
115
- **Metadata fields supported:**
116
-
117
- - `traceId` - Session or conversation tracking identifier
118
- - `taskType` - Type of AI task being performed
119
- - `agent` - AI agent or bot identifier
120
- - `organizationId` - Organization identifier
121
- - `productId` - Product or service identifier
122
- - `subscriptionId` - Subscription tier identifier
123
- - `responseQualityScore` - Quality rating (0.0-1.0)
124
- - `subscriber` - Nested subscriber object with `id`, `email`, `credential` (with `name` and `value`)
125
-
126
- ---
127
-
128
- ### 4. Streaming
129
-
130
- **File:** `stream.ts`
131
-
132
- Demonstrates streaming responses:
133
-
134
- - Real-time token streaming
135
- - Accumulating responses
136
- - Streaming metrics
137
-
138
- **Run:**
139
-
140
- ```bash
141
- npm run example:stream
142
- # or
143
- npx tsx examples/stream.ts
144
- ```
145
-
146
- **What it does:**
147
-
148
- - Creates a streaming chat completion
149
- - Displays tokens as they arrive in real-time
150
- - Tracks streaming metrics
151
- - Sends metering data after stream completes
152
-
153
- ---
154
-
155
- ### 5. Advanced Features
156
-
157
- **File:** `advanced.ts`
158
-
159
- Demonstrates advanced Perplexity features:
160
-
161
- - Multi-turn conversations
162
- - Different temperature settings
163
- - Multiple Perplexity models
164
-
165
- **Run:**
166
-
167
- ```bash
168
- npm run example:advanced
169
- # or
170
- npx tsx examples/advanced.ts
171
- ```
172
-
173
- **What it does:**
174
-
175
- - Demonstrates multi-turn conversation with system prompt
176
- - Shows creative responses with higher temperature
177
- - Uses sonar-reasoning model for complex reasoning tasks
178
-
179
- ---
180
-
181
- ## Common Issues
182
-
183
- ### "Client not initialized" error
184
-
185
- **Solution:** Make sure to call `Initialize()` before using `GetClient()`.
186
-
187
- ### "REVENIUM_METERING_API_KEY is required" error
188
-
189
- **Solution:** Set the `REVENIUM_METERING_API_KEY` environment variable in your `.env` file.
190
-
191
- ### "invalid Revenium API key format" error
192
-
193
- **Solution:** Revenium API keys should start with `hak_`. Check your API key format.
194
-
195
- ### Environment variables not loading
196
-
197
- **Solution:** Make sure your `.env` file is in the project root directory and contains the required variables.
198
-
199
- ### Perplexity API errors
200
-
201
- **Solution:** Make sure you have set `PERPLEXITY_API_KEY` in your `.env` file and that it starts with `pplx-`.
202
-
203
- ### Debug Mode
204
-
205
- Enable detailed logging to troubleshoot issues:
206
-
207
- ```bash
208
- # In .env file
209
- REVENIUM_DEBUG=true
210
-
211
- # Then run examples
212
- npm run example:getting-started
213
- ```
214
-
215
- ## Next Steps
216
-
217
- - Check the [main README](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/README.md) for detailed documentation
218
- - Visit the [Revenium Dashboard](https://app.revenium.io) to view your metering data
219
- - See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all configuration options
220
-
221
- ## Support
222
-
223
- For issues or questions:
224
-
225
- - Documentation: https://docs.revenium.io
226
- - Email: support@revenium.io
1
+ # Revenium Perplexity Middleware - Examples
2
+
3
+ This directory contains examples demonstrating how to use the Revenium Perplexity middleware.
4
+
5
+ ## Prerequisites
6
+
7
+ Before running the examples, make sure you have:
8
+
9
+ 1. **Node.js 20+** installed
10
+ 2. **Revenium API Key** - Get one from [Revenium Dashboard](https://app.revenium.ai)
11
+ 3. **Perplexity API Key** - Get one from [Perplexity Platform](https://www.perplexity.ai)
12
+
13
+ ## Setup
14
+
15
+ 1. **Clone the repository** (if you haven't already):
16
+
17
+ ```bash
18
+ git clone https://github.com/revenium/revenium-middleware-perplexity-node.git
19
+ cd revenium-middleware-perplexity-node
20
+ ```
21
+
22
+ 2. **Install dependencies**:
23
+
24
+ ```bash
25
+ npm install
26
+ ```
27
+
28
+ 3. **Configure environment variables**:
29
+
30
+ Create a `.env` file in the project root with your API keys:
31
+
32
+ ```bash
33
+ # .env
34
+ PERPLEXITY_API_KEY=pplx_your_perplexity_api_key
35
+ REVENIUM_METERING_API_KEY=hak_your_revenium_api_key
36
+ REVENIUM_METERING_BASE_URL=https://api.revenium.ai # Optional, defaults to https://api.revenium.ai
37
+ REVENIUM_DEBUG=true # Optional, enables debug logging
38
+ ```
39
+
40
+ **Note:** The middleware automatically loads `.env` files via `Initialize()`, so no additional configuration is needed.
41
+
42
+ ## Examples
43
+
44
+ ### 1. Getting Started
45
+
46
+ **File:** `getting_started.ts`
47
+
48
+ The simplest example to get you started with Revenium tracking:
49
+
50
+ - Initialize the middleware
51
+ - Create a basic chat completion
52
+ - Display response and usage metrics
53
+
54
+ **Run:**
55
+
56
+ ```bash
57
+ npm run example:getting-started
58
+ # or
59
+ npx tsx examples/getting_started.ts
60
+ ```
61
+
62
+ **What it does:**
63
+
64
+ - Loads configuration from environment variables
65
+ - Creates a simple chat completion request
66
+ - Automatically sends metering data to Revenium API
67
+ - Displays the response
68
+
69
+ ---
70
+
71
+ ### 2. Basic Usage
72
+
73
+ **File:** `basic.ts`
74
+
75
+ Demonstrates standard Perplexity API usage:
76
+
77
+ - Chat completions with metadata
78
+ - Simple metadata tracking
79
+
80
+ **Run:**
81
+
82
+ ```bash
83
+ npm run example:basic
84
+ # or
85
+ npx tsx examples/basic.ts
86
+ ```
87
+
88
+ **What it does:**
89
+
90
+ - Creates chat completions with metadata tracking
91
+ - Demonstrates basic metadata usage
92
+
93
+ ---
94
+
95
+ ### 3. Metadata
96
+
97
+ **File:** `metadata.ts`
98
+
99
+ Demonstrates all available metadata fields:
100
+
101
+ - Complete metadata structure
102
+ - All optional fields documented
103
+ - Subscriber information
104
+
105
+ **Run:**
106
+
107
+ ```bash
108
+ npm run example:metadata
109
+ # or
110
+ npx tsx examples/metadata.ts
111
+ ```
112
+
113
+ **What it does:**
114
+
115
+ - Shows all available metadata fields
116
+ - Demonstrates subscriber tracking
117
+ - Includes organization and product tracking
118
+
119
+ **Metadata fields supported:**
120
+
121
+ - `traceId` - Session or conversation tracking identifier
122
+ - `taskType` - Type of AI task being performed
123
+ - `agent` - AI agent or bot identifier
124
+ - `organizationId` - Organization identifier
125
+ - `productId` - Product or service identifier
126
+ - `subscriptionId` - Subscription tier identifier
127
+ - `responseQualityScore` - Quality rating (0.0-1.0)
128
+ - `subscriber` - Nested subscriber object with `id`, `email`, `credential` (with `name` and `value`)
129
+
130
+ ---
131
+
132
+ ### 4. Streaming
133
+
134
+ **File:** `stream.ts`
135
+
136
+ Demonstrates streaming responses:
137
+
138
+ - Real-time token streaming
139
+ - Accumulating responses
140
+ - Streaming metrics
141
+
142
+ **Run:**
143
+
144
+ ```bash
145
+ npm run example:stream
146
+ # or
147
+ npx tsx examples/stream.ts
148
+ ```
149
+
150
+ **What it does:**
151
+
152
+ - Creates a streaming chat completion
153
+ - Displays tokens as they arrive in real-time
154
+ - Tracks streaming metrics
155
+ - Sends metering data after stream completes
156
+
157
+ ---
158
+
159
+ ### 5. Advanced Features
160
+
161
+ **File:** `advanced.ts`
162
+
163
+ Demonstrates advanced Perplexity features:
164
+
165
+ - Multi-turn conversations
166
+ - Different temperature settings
167
+ - Multiple Perplexity models
168
+
169
+ **Run:**
170
+
171
+ ```bash
172
+ npm run example:advanced
173
+ # or
174
+ npx tsx examples/advanced.ts
175
+ ```
176
+
177
+ **What it does:**
178
+
179
+ - Demonstrates multi-turn conversation with system prompt
180
+ - Shows creative responses with higher temperature
181
+ - Uses sonar-reasoning model for complex reasoning tasks
182
+
183
+ ---
184
+
185
+ ## Common Issues
186
+
187
+ ### "Client not initialized" error
188
+
189
+ **Solution:** Make sure to call `Initialize()` before using `GetClient()`.
190
+
191
+ ### "REVENIUM_METERING_API_KEY is required" error
192
+
193
+ **Solution:** Set the `REVENIUM_METERING_API_KEY` environment variable in your `.env` file.
194
+
195
+ ### "invalid Revenium API key format" error
196
+
197
+ **Solution:** Revenium API keys should start with `hak_`. Check your API key format.
198
+
199
+ ### Environment variables not loading
200
+
201
+ **Solution:** Make sure your `.env` file is in the project root directory and contains the required variables.
202
+
203
+ ### Perplexity API errors
204
+
205
+ **Solution:** Make sure you have set `PERPLEXITY_API_KEY` in your `.env` file and that it starts with `pplx-`.
206
+
207
+ ### Debug Mode
208
+
209
+ Enable detailed logging to troubleshoot issues:
210
+
211
+ ```bash
212
+ # In .env file
213
+ REVENIUM_DEBUG=true
214
+
215
+ # Then run examples
216
+ npm run example:getting-started
217
+ ```
218
+
219
+ ## Next Steps
220
+
221
+ - Check the [main README](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/README.md) for detailed documentation
222
+ - Visit the [Revenium Dashboard](https://app.revenium.ai) to view your metering data
223
+ - See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all configuration options
224
+
225
+ ## Support
226
+
227
+ For issues or questions:
228
+
229
+ - Documentation: https://docs.revenium.io
230
+ - Email: support@revenium.io