@revenium/perplexity 2.0.6 → 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.
- package/README.md +112 -28
- package/dist/cjs/core/config/index.js +0 -1
- package/dist/cjs/core/config/index.js.map +1 -1
- package/dist/cjs/core/config/manager.js +0 -1
- package/dist/cjs/core/config/manager.js.map +1 -1
- package/dist/cjs/core/providers/detector.js +0 -2
- package/dist/cjs/core/providers/detector.js.map +1 -1
- package/dist/cjs/core/providers/index.js +0 -1
- package/dist/cjs/core/providers/index.js.map +1 -1
- package/dist/cjs/index.js +1 -34
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/stop-reason-mapper.js +18 -20
- package/dist/cjs/utils/stop-reason-mapper.js.map +1 -1
- package/dist/esm/core/config/index.js +3 -4
- package/dist/esm/core/config/index.js.map +1 -1
- package/dist/esm/core/config/manager.js +0 -1
- package/dist/esm/core/config/manager.js.map +1 -1
- package/dist/esm/core/providers/detector.js +0 -2
- package/dist/esm/core/providers/detector.js.map +1 -1
- package/dist/esm/core/providers/index.js +0 -1
- package/dist/esm/core/providers/index.js.map +1 -1
- package/dist/esm/index.js +1 -34
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/stop-reason-mapper.js +18 -20
- package/dist/esm/utils/stop-reason-mapper.js.map +1 -1
- package/dist/types/core/config/index.d.ts +3 -4
- package/dist/types/core/config/index.d.ts.map +1 -1
- package/dist/types/core/config/manager.d.ts +0 -1
- package/dist/types/core/config/manager.d.ts.map +1 -1
- package/dist/types/core/providers/detector.d.ts +0 -2
- package/dist/types/core/providers/detector.d.ts.map +1 -1
- package/dist/types/core/providers/index.d.ts +0 -1
- package/dist/types/core/providers/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -32
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/utils/stop-reason-mapper.d.ts +1 -3
- package/dist/types/utils/stop-reason-mapper.d.ts.map +1 -1
- package/examples/README.md +10 -6
- package/examples/stream.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,9 +23,11 @@ A lightweight, production-ready middleware that adds **Revenium metering and tra
|
|
|
23
23
|
### Quick Start
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
npm install @revenium/perplexity
|
|
26
|
+
npm install @revenium/perplexity
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
**Note:** The `dotenv` package is optional. The middleware automatically loads `.env` files via `Initialize()`.
|
|
30
|
+
|
|
29
31
|
For complete setup instructions, TypeScript patterns, and usage examples, see [examples/README.md](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/examples/README.md).
|
|
30
32
|
|
|
31
33
|
### Step-by-Step Guide
|
|
@@ -46,8 +48,8 @@ npm init -y
|
|
|
46
48
|
#### Step 2: Install Dependencies
|
|
47
49
|
|
|
48
50
|
```bash
|
|
49
|
-
# Install Revenium middleware
|
|
50
|
-
npm install @revenium/perplexity
|
|
51
|
+
# Install Revenium middleware
|
|
52
|
+
npm install @revenium/perplexity
|
|
51
53
|
|
|
52
54
|
# For TypeScript projects (optional)
|
|
53
55
|
npm install -D typescript tsx @types/node
|
|
@@ -55,33 +57,122 @@ npm install -D typescript tsx @types/node
|
|
|
55
57
|
|
|
56
58
|
#### Step 3: Setup Environment Variables
|
|
57
59
|
|
|
58
|
-
Create a `.env` file in your project root
|
|
60
|
+
Create a `.env` file in your project root with your API keys:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# .env
|
|
64
|
+
PERPLEXITY_API_KEY=pplx_your_perplexity_api_key
|
|
65
|
+
REVENIUM_METERING_API_KEY=hak_your_revenium_api_key
|
|
66
|
+
REVENIUM_METERING_BASE_URL=https://api.revenium.ai # Optional, defaults to https://api.revenium.ai
|
|
67
|
+
REVENIUM_DEBUG=false # Optional, enables debug logging
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Replace the placeholder values with your actual keys!**
|
|
71
|
+
|
|
72
|
+
For a complete list of all available environment variables, see the [Configuration Options](#configuration-options) section below.
|
|
73
|
+
|
|
74
|
+
#### Step 4: Implement in Your Code
|
|
75
|
+
|
|
76
|
+
Use the examples as reference for implementing the middleware in your project. See [examples/README.md](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/examples/README.md) for complete implementation examples including:
|
|
77
|
+
|
|
78
|
+
- How to initialize the middleware with your configuration
|
|
79
|
+
- Making API calls with automatic metering
|
|
80
|
+
- Handling streaming responses
|
|
81
|
+
- Adding custom metadata to track business context
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Running Examples from Cloned Repository
|
|
86
|
+
|
|
87
|
+
If you've cloned this repository from GitHub and want to **run the included examples** to see how the middleware works (without modifying the middleware source code):
|
|
88
|
+
|
|
89
|
+
### Setup
|
|
59
90
|
|
|
60
91
|
```bash
|
|
61
|
-
#
|
|
92
|
+
# Install dependencies
|
|
93
|
+
npm install
|
|
94
|
+
|
|
95
|
+
# Build the package
|
|
96
|
+
npm run build
|
|
97
|
+
|
|
98
|
+
# Configure environment variables
|
|
62
99
|
cp .env.example .env
|
|
100
|
+
# Edit .env with your API keys
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Run Examples
|
|
104
|
+
|
|
105
|
+
**Using npm scripts:**
|
|
63
106
|
|
|
64
|
-
|
|
107
|
+
```bash
|
|
108
|
+
npm run example:getting-started # Getting started example
|
|
109
|
+
npm run example:basic # Basic chat completion
|
|
110
|
+
npm run example:stream # Streaming response
|
|
111
|
+
npm run example:metadata # Custom metadata
|
|
112
|
+
npm run example:advanced # Advanced features
|
|
65
113
|
```
|
|
66
114
|
|
|
67
|
-
|
|
115
|
+
**Or use npx tsx directly:**
|
|
68
116
|
|
|
69
|
-
|
|
117
|
+
```bash
|
|
118
|
+
npx tsx examples/getting_started.ts
|
|
119
|
+
npx tsx examples/basic.ts
|
|
120
|
+
npx tsx examples/stream.ts
|
|
121
|
+
npx tsx examples/metadata.ts
|
|
122
|
+
npx tsx examples/advanced.ts
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
For detailed information about each example, see [examples/README.md](examples/README.md).
|
|
126
|
+
|
|
127
|
+
### Want to Modify the Middleware Code?
|
|
128
|
+
|
|
129
|
+
If you're planning to modify the examples or experiment with the code, the setup above is sufficient. However, if you want to **modify the middleware source code itself** (files in `src/`), you'll need to understand the development workflow.
|
|
130
|
+
|
|
131
|
+
See [Local Development and Contributing](#local-development-and-contributing) below for the complete development guide.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Local Development and Contributing
|
|
136
|
+
|
|
137
|
+
**Are you planning to modify the middleware source code?** (Not just run examples)
|
|
138
|
+
|
|
139
|
+
If you want to:
|
|
140
|
+
|
|
141
|
+
- Fix bugs in the middleware
|
|
142
|
+
- Add new features to @revenium/perplexity
|
|
143
|
+
- Contribute to the project
|
|
144
|
+
- Test changes to the middleware before publishing
|
|
145
|
+
|
|
146
|
+
Then follow the complete development workflow in [DEVELOPMENT.md](DEVELOPMENT.md), which covers:
|
|
70
147
|
|
|
71
|
-
|
|
148
|
+
### What DEVELOPMENT.md Includes:
|
|
72
149
|
|
|
73
|
-
**
|
|
150
|
+
- **Development Workflow** - Step-by-step process for making changes
|
|
151
|
+
- **Build System** - Understanding ESM, CJS, and TypeScript compilation
|
|
152
|
+
- **Testing Local Changes** - How to test your modifications properly
|
|
153
|
+
- **When to Rebuild** - Understanding when `npm run build` is needed
|
|
154
|
+
- **Publishing Checklist** - Steps to publish new versions
|
|
155
|
+
- **Architecture Notes** - Understanding the codebase structure
|
|
156
|
+
- **Contributing Guidelines** - How to contribute to the project
|
|
74
157
|
|
|
75
|
-
|
|
158
|
+
### Key Difference:
|
|
159
|
+
|
|
160
|
+
- **Running Examples** (above): You can modify example files (`.ts` in `examples/`) and run them directly with `npx tsx` - no rebuild needed
|
|
161
|
+
- **Modifying Middleware** (DEVELOPMENT.md): If you modify source files (`.ts` in `src/`), you must run `npm run build` before testing
|
|
162
|
+
|
|
163
|
+
**Quick Start for Contributors:**
|
|
76
164
|
|
|
77
165
|
```bash
|
|
78
|
-
|
|
166
|
+
# 1. Make changes to source code
|
|
167
|
+
vim src/index.ts
|
|
168
|
+
|
|
169
|
+
# 2. Rebuild the package
|
|
170
|
+
npm run build
|
|
171
|
+
|
|
172
|
+
# 3. Test your changes
|
|
79
173
|
npm run example:basic
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
npm run example:metadata
|
|
83
|
-
npm run example:advanced
|
|
84
|
-
npm run example:getting-started
|
|
174
|
+
|
|
175
|
+
# 4. See DEVELOPMENT.md for complete workflow
|
|
85
176
|
```
|
|
86
177
|
|
|
87
178
|
---
|
|
@@ -113,8 +204,6 @@ The middleware automatically captures comprehensive usage data:
|
|
|
113
204
|
|
|
114
205
|
## API Overview
|
|
115
206
|
|
|
116
|
-
The middleware provides a Go-aligned API with the following main functions:
|
|
117
|
-
|
|
118
207
|
- **`Initialize(config?)`** - Initialize the middleware (from environment or explicit config)
|
|
119
208
|
- **`GetClient()`** - Get the global Revenium client instance
|
|
120
209
|
- **`Configure(config)`** - Alias for `Initialize()` for programmatic configuration
|
|
@@ -155,21 +244,21 @@ For a complete list of all available environment variables with examples, see [`
|
|
|
155
244
|
|
|
156
245
|
The package includes comprehensive examples in the [`examples/`](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/examples/) directory.
|
|
157
246
|
|
|
158
|
-
|
|
159
247
|
## Project Structure
|
|
160
248
|
|
|
161
249
|
```
|
|
162
250
|
revenium-middleware-perplexity-node/
|
|
163
251
|
├── src/
|
|
164
252
|
│ ├── core/
|
|
253
|
+
│ │ ├── client/ # Client manager (Initialize/GetClient)
|
|
165
254
|
│ │ ├── config/ # Configuration management
|
|
166
|
-
│ │ ├──
|
|
167
|
-
│ │
|
|
255
|
+
│ │ ├── middleware/ # Perplexity API middleware wrapper
|
|
256
|
+
│ │ ├── providers/ # Provider detection
|
|
257
|
+
│ │ └── tracking/ # Metering and tracking
|
|
168
258
|
│ ├── types/ # TypeScript type definitions
|
|
169
259
|
│ ├── utils/ # Utility functions
|
|
170
260
|
│ └── index.ts # Main entry point
|
|
171
261
|
├── examples/ # TypeScript examples
|
|
172
|
-
├── .env.example # Example environment variables
|
|
173
262
|
├── package.json
|
|
174
263
|
├── tsconfig.json
|
|
175
264
|
└── README.md
|
|
@@ -246,7 +335,6 @@ The following table shows what has been tested and verified with working example
|
|
|
246
335
|
|
|
247
336
|
**Note:** "Yes" = Tested with working examples in [`examples/`](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/examples/) directory
|
|
248
337
|
|
|
249
|
-
|
|
250
338
|
## Requirements
|
|
251
339
|
|
|
252
340
|
- Node.js 20+
|
|
@@ -283,10 +371,6 @@ For issues, feature requests, or contributions:
|
|
|
283
371
|
- **Documentation**: [docs.revenium.io](https://docs.revenium.io)
|
|
284
372
|
- **Contact**: Reach out to the Revenium team for additional support
|
|
285
373
|
|
|
286
|
-
## Development
|
|
287
|
-
|
|
288
|
-
For development and testing instructions, see [DEVELOPMENT.md](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/DEVELOPMENT.md).
|
|
289
|
-
|
|
290
374
|
---
|
|
291
375
|
|
|
292
376
|
**Built by Revenium**
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Configuration module - Main exports
|
|
4
4
|
*
|
|
5
5
|
* This module provides a clean interface for configuration management.
|
|
6
|
-
* Aligned with OpenAI modular implementation.
|
|
7
6
|
*/
|
|
8
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
8
|
exports.defaultLogger = exports.initializeConfig = exports.getLogger = exports.setConfig = exports.getConfig = exports.validateConfig = exports.loadConfigFromEnv = void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/config/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/config/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,4CAA4C;AAC5C,yCAAgD;AAAvC,8GAAA,iBAAiB,OAAA;AAE1B,+CAAgD;AAAvC,8GAAA,cAAc,OAAA;AAEvB,2CAMsB;AALpB,uGAAA,SAAS,OAAA;AACT,uGAAA,SAAS,OAAA;AACT,uGAAA,SAAS,OAAA;AACT,8GAAA,gBAAgB,OAAA;AAChB,2GAAA,aAAa,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../../src/core/config/manager.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../../src/core/config/manager.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAoCH,8BAEC;AAKD,8BAQC;AAKD,8BAEC;AAKD,4CAkBC;AA9ED,2CAAgD;AAChD,iDAAgD;AAEhD;;GAEG;AACH,IAAI,YAAY,GAA0B,IAAI,CAAC;AAE/C;;GAEG;AACU,QAAA,aAAa,GAAW;IACnC,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QAC7C,IAAI,YAAY,EAAE,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,MAAM,EAAE,CAAC;YACjE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IACD,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QAC5C,OAAO,CAAC,IAAI,CAAC,cAAc,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QAC5C,OAAO,CAAC,IAAI,CAAC,sBAAsB,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACzD,CAAC;IACD,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QAC7C,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACxD,CAAC;CACF,CAAC;AAEF,IAAI,YAAY,GAAW,qBAAa,CAAC;AAEzC;;GAEG;AACH,SAAgB,SAAS;IACvB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS,CAAC,MAAsB;IAC9C,IAAA,6BAAc,EAAC,MAAM,CAAC,CAAC;IACvB,YAAY,GAAG,MAAM,CAAC;IACtB,YAAY,CAAC,KAAK,CAAC,gCAAgC,EAAE;QACnD,OAAO,EAAE,MAAM,CAAC,eAAe;QAC/B,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc;QACvC,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,gBAAgB;KAC5C,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,SAAS;IACvB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB;IAC9B,MAAM,SAAS,GAAG,IAAA,6BAAiB,GAAE,CAAC;IAEtC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,YAAY,CAAC,KAAK,CAChB,iHAAiH,CAClH,CAAC;QACF,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,SAAS,CAAC,CAAC;IACrB,YAAY,CAAC,KAAK,CAChB,4DAA4D,CAC7D,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Provider Detection Module
|
|
4
4
|
*
|
|
5
5
|
* Handles provider metadata for Perplexity AI.
|
|
6
|
-
* Simplified compared to OpenAI modular since Perplexity doesn't have Azure variant.
|
|
7
6
|
*/
|
|
8
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
8
|
exports.detectProvider = detectProvider;
|
|
@@ -13,7 +12,6 @@ const index_js_1 = require("../config/index.js");
|
|
|
13
12
|
const logger = (0, index_js_1.getLogger)();
|
|
14
13
|
/**
|
|
15
14
|
* Get provider info for Perplexity
|
|
16
|
-
* Always returns Perplexity since there's no Azure variant
|
|
17
15
|
*
|
|
18
16
|
* @returns ProviderInfo with Perplexity provider
|
|
19
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../../../../src/core/providers/detector.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../../../../src/core/providers/detector.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAaH,wCAMC;AAOD,kDAQC;AA/BD,iDAA+C;AAE/C,gBAAgB;AAChB,MAAM,MAAM,GAAG,IAAA,oBAAS,GAAE,CAAC;AAE3B;;;;GAIG;AACH,SAAgB,cAAc;IAC5B,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC7C,OAAO;QACL,QAAQ,EAAE,YAAY;QACtB,WAAW,EAAE,YAAY;KAC1B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB;IAIjC,OAAO;QACL,QAAQ,EAAE,YAAY;QACtB,WAAW,EAAE,YAAY;KAC1B,CAAC;AACJ,CAAC"}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Providers module - Main exports
|
|
4
4
|
*
|
|
5
5
|
* This module provides a clean interface for provider detection and management.
|
|
6
|
-
* Simplified for Perplexity (no Azure variant).
|
|
7
6
|
*/
|
|
8
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
8
|
exports.getProviderMetadata = exports.detectProvider = void 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/providers/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/providers/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,uCAAuC;AACvC,6CAAoE;AAA3D,6GAAA,cAAc,OAAA;AAAE,kHAAA,mBAAmB,OAAA"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,41 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Revenium Perplexity Middleware for TypeScript
|
|
4
|
-
*
|
|
5
|
-
* This middleware tracks Perplexity AI usage and sends metrics to Revenium.
|
|
6
|
-
* Uses Go-aligned API pattern with Initialize/GetClient.
|
|
7
|
-
*
|
|
8
|
-
* Environment Variables:
|
|
9
|
-
* REVENIUM_METERING_API_KEY=hak_your_api_key
|
|
10
|
-
* REVENIUM_METERING_BASE_URL=https://api.revenium.ai (optional)
|
|
11
|
-
* PERPLEXITY_API_KEY=pplx_your_perplexity_key
|
|
12
|
-
*
|
|
13
|
-
* Usage:
|
|
14
|
-
* import { Initialize, GetClient } from "@revenium/perplexity";
|
|
15
|
-
*
|
|
16
|
-
* // Initialize from environment
|
|
17
|
-
* Initialize();
|
|
18
|
-
*
|
|
19
|
-
* // Get client
|
|
20
|
-
* const client = GetClient();
|
|
21
|
-
*
|
|
22
|
-
* // Use client
|
|
23
|
-
* const response = await client.chat().completions().create({
|
|
24
|
-
* model: "sonar",
|
|
25
|
-
* messages: [{ role: "user", content: "Hello!" }]
|
|
26
|
-
* }, {
|
|
27
|
-
* organizationId: "my-org",
|
|
28
|
-
* productId: "my-app",
|
|
29
|
-
* subscriber: {
|
|
30
|
-
* id: "user-123",
|
|
31
|
-
* email: "user@my-org.com"
|
|
32
|
-
* }
|
|
33
|
-
* });
|
|
34
|
-
*/
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.getProviderMetadata = exports.detectProvider = exports.trackUsageAsync = exports.StreamingWrapper = exports.CompletionsInterface = exports.ChatInterface = exports.ReveniumPerplexity = exports.Configure = exports.Reset = exports.IsInitialized = exports.GetClient = exports.Initialize = void 0;
|
|
37
4
|
/**
|
|
38
|
-
* Main API
|
|
5
|
+
* Main API
|
|
39
6
|
*/
|
|
40
7
|
var index_js_1 = require("./core/client/index.js");
|
|
41
8
|
Object.defineProperty(exports, "Initialize", { enumerable: true, get: function () { return index_js_1.Initialize; } });
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AA+BA;;GAEG;AACH,mDAMgC;AAL9B,sGAAA,UAAU,OAAA;AACV,qGAAA,SAAS,OAAA;AACT,yGAAA,aAAa,OAAA;AACb,iGAAA,KAAK,OAAA;AACL,qGAAA,SAAS,OAAA;AAGX;;GAEG;AACH,uDAKoC;AAJlC,8GAAA,kBAAkB,OAAA;AAClB,yGAAA,aAAa,OAAA;AACb,gHAAA,oBAAoB,OAAA;AACpB,4GAAA,gBAAgB,OAAA;AAGlB;;GAEG;AACH,qDAA2D;AAAlD,2GAAA,eAAe,OAAA;AAExB;;GAEG;AACH,sDAAgF;AAAvE,0GAAA,cAAc,OAAA;AAAE,+GAAA,mBAAmB,OAAA"}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
* Stop Reason Mapper Utilities
|
|
4
4
|
*
|
|
5
5
|
* Centralized stop reason mapping logic using lookup tables
|
|
6
|
-
* instead of nested conditionals.
|
|
7
|
-
* from the anthropic-node middleware.
|
|
6
|
+
* instead of nested conditionals.
|
|
8
7
|
*/
|
|
9
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
9
|
exports.mapStopReason = mapStopReason;
|
|
@@ -15,33 +14,32 @@ exports.isStopReasonSupported = isStopReasonSupported;
|
|
|
15
14
|
* Maps provider-specific stop reasons to Revenium's standardized set
|
|
16
15
|
*/
|
|
17
16
|
const STOP_REASON_MAP = {
|
|
18
|
-
// OpenAI
|
|
19
|
-
stop:
|
|
20
|
-
function_call:
|
|
21
|
-
tool_calls:
|
|
22
|
-
timeout:
|
|
23
|
-
length:
|
|
24
|
-
max_tokens:
|
|
25
|
-
cost_limit:
|
|
26
|
-
completion_limit:
|
|
27
|
-
content_filter:
|
|
28
|
-
error:
|
|
29
|
-
cancelled:
|
|
30
|
-
canceled:
|
|
17
|
+
// OpenAI OpenAI stop reasons
|
|
18
|
+
stop: "END",
|
|
19
|
+
function_call: "END_SEQUENCE",
|
|
20
|
+
tool_calls: "END_SEQUENCE",
|
|
21
|
+
timeout: "TIMEOUT",
|
|
22
|
+
length: "TOKEN_LIMIT",
|
|
23
|
+
max_tokens: "TOKEN_LIMIT",
|
|
24
|
+
cost_limit: "COST_LIMIT",
|
|
25
|
+
completion_limit: "COMPLETION_LIMIT",
|
|
26
|
+
content_filter: "ERROR",
|
|
27
|
+
error: "ERROR",
|
|
28
|
+
cancelled: "CANCELLED",
|
|
29
|
+
canceled: "CANCELLED", // Handle both spellings
|
|
31
30
|
// Anthropic stop reasons (for consistency across middleware)
|
|
32
|
-
end_turn:
|
|
33
|
-
stop_sequence:
|
|
34
|
-
tool_use:
|
|
31
|
+
end_turn: "END",
|
|
32
|
+
stop_sequence: "END_SEQUENCE",
|
|
33
|
+
tool_use: "END_SEQUENCE",
|
|
35
34
|
};
|
|
36
35
|
/**
|
|
37
36
|
* Default stop reason when mapping fails
|
|
38
37
|
*/
|
|
39
|
-
const DEFAULT_STOP_REASON =
|
|
38
|
+
const DEFAULT_STOP_REASON = "END";
|
|
40
39
|
/**
|
|
41
40
|
* Map provider stop reasons to Revenium stop reasons
|
|
42
41
|
*
|
|
43
42
|
* This replaces the nested if/switch logic with a clean lookup table approach.
|
|
44
|
-
* Based on the good example from the anthropic-node middleware.
|
|
45
43
|
*
|
|
46
44
|
* @param providerStopReason - Stop reason from the AI provider
|
|
47
45
|
* @param logger - Optional logger for warnings about unknown reasons
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stop-reason-mapper.js","sourceRoot":"","sources":["../../../src/utils/stop-reason-mapper.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"stop-reason-mapper.js","sourceRoot":"","sources":["../../../src/utils/stop-reason-mapper.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAyCH,sCAiBC;AAKD,0DAEC;AAKD,sDAEC;AAtED;;;GAGG;AACH,MAAM,eAAe,GAA2B;IAC9C,6BAA6B;IAC7B,IAAI,EAAE,KAAK;IACX,aAAa,EAAE,cAAc;IAC7B,UAAU,EAAE,cAAc;IAC1B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,aAAa;IACrB,UAAU,EAAE,aAAa;IACzB,UAAU,EAAE,YAAY;IACxB,gBAAgB,EAAE,kBAAkB;IACpC,cAAc,EAAE,OAAO;IACvB,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,WAAW,EAAE,wBAAwB;IAE/C,6DAA6D;IAC7D,QAAQ,EAAE,KAAK;IACf,aAAa,EAAE,cAAc;IAC7B,QAAQ,EAAE,cAAc;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC;;;;;;;;GAQG;AACH,SAAgB,aAAa,CAC3B,kBAA6C,EAC7C,MAA4D;IAE5D,IAAI,CAAC,kBAAkB;QAAE,OAAO,mBAAmB,CAAC;IACpD,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;IAC1D,MAAM,YAAY,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAEvD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,mEAAmE;QACnE,MAAM,EAAE,IAAI,CACV,wBAAwB,kBAAkB,gBAAgB,mBAAmB,EAAE,CAChF,CAAC;QACF,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,SAAgB,uBAAuB;IACrC,OAAO,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,qBAAqB,CAAC,MAAc;IAClD,OAAO,MAAM,CAAC,WAAW,EAAE,IAAI,eAAe,CAAC;AACjD,CAAC"}
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Configuration module - Main exports
|
|
3
3
|
*
|
|
4
4
|
* This module provides a clean interface for configuration management.
|
|
5
|
-
* Aligned with OpenAI modular implementation.
|
|
6
5
|
*/
|
|
7
6
|
// Re-export all configuration functionality
|
|
8
|
-
export { loadConfigFromEnv } from
|
|
9
|
-
export { validateConfig } from
|
|
10
|
-
export { getConfig, setConfig, getLogger, initializeConfig, defaultLogger, } from
|
|
7
|
+
export { loadConfigFromEnv } from "./loader.js";
|
|
8
|
+
export { validateConfig } from "./validator.js";
|
|
9
|
+
export { getConfig, setConfig, getLogger, initializeConfig, defaultLogger, } from "./manager.js";
|
|
11
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/config/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/config/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,4CAA4C;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,aAAa,GACd,MAAM,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../../src/core/config/manager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../../../src/core/config/manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;GAEG;AACH,IAAI,YAAY,GAA0B,IAAI,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW;IACnC,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QAC7C,IAAI,YAAY,EAAE,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,MAAM,EAAE,CAAC;YACjE,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;IACD,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QAC5C,OAAO,CAAC,IAAI,CAAC,cAAc,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACjD,CAAC;IACD,IAAI,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QAC5C,OAAO,CAAC,IAAI,CAAC,sBAAsB,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACzD,CAAC;IACD,KAAK,EAAE,CAAC,OAAe,EAAE,GAAG,IAAe,EAAE,EAAE;QAC7C,OAAO,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC;IACxD,CAAC;CACF,CAAC;AAEF,IAAI,YAAY,GAAW,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAsB;IAC9C,cAAc,CAAC,MAAM,CAAC,CAAC;IACvB,YAAY,GAAG,MAAM,CAAC;IACtB,YAAY,CAAC,KAAK,CAAC,gCAAgC,EAAE;QACnD,OAAO,EAAE,MAAM,CAAC,eAAe;QAC/B,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,cAAc;QACvC,gBAAgB,EAAE,CAAC,CAAC,MAAM,CAAC,gBAAgB;KAC5C,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,SAAS,GAAG,iBAAiB,EAAE,CAAC;IAEtC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,YAAY,CAAC,KAAK,CAChB,iHAAiH,CAClH,CAAC;QACF,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAC;IACJ,CAAC;IAED,SAAS,CAAC,SAAS,CAAC,CAAC;IACrB,YAAY,CAAC,KAAK,CAChB,4DAA4D,CAC7D,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
* Provider Detection Module
|
|
3
3
|
*
|
|
4
4
|
* Handles provider metadata for Perplexity AI.
|
|
5
|
-
* Simplified compared to OpenAI modular since Perplexity doesn't have Azure variant.
|
|
6
5
|
*/
|
|
7
6
|
import { getLogger } from "../config/index.js";
|
|
8
7
|
// Global logger
|
|
9
8
|
const logger = getLogger();
|
|
10
9
|
/**
|
|
11
10
|
* Get provider info for Perplexity
|
|
12
|
-
* Always returns Perplexity since there's no Azure variant
|
|
13
11
|
*
|
|
14
12
|
* @returns ProviderInfo with Perplexity provider
|
|
15
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../../../../src/core/providers/detector.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../../../../src/core/providers/detector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,gBAAgB;AAChB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAE3B;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC7C,OAAO;QACL,QAAQ,EAAE,YAAY;QACtB,WAAW,EAAE,YAAY;KAC1B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB;IAIjC,OAAO;QACL,QAAQ,EAAE,YAAY;QACtB,WAAW,EAAE,YAAY;KAC1B,CAAC;AACJ,CAAC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Providers module - Main exports
|
|
3
3
|
*
|
|
4
4
|
* This module provides a clean interface for provider detection and management.
|
|
5
|
-
* Simplified for Perplexity (no Azure variant).
|
|
6
5
|
*/
|
|
7
6
|
// Re-export all provider functionality
|
|
8
7
|
export { detectProvider, getProviderMetadata } from "./detector.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/providers/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/core/providers/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,38 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* This middleware tracks Perplexity AI usage and sends metrics to Revenium.
|
|
5
|
-
* Uses Go-aligned API pattern with Initialize/GetClient.
|
|
6
|
-
*
|
|
7
|
-
* Environment Variables:
|
|
8
|
-
* REVENIUM_METERING_API_KEY=hak_your_api_key
|
|
9
|
-
* REVENIUM_METERING_BASE_URL=https://api.revenium.ai (optional)
|
|
10
|
-
* PERPLEXITY_API_KEY=pplx_your_perplexity_key
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* import { Initialize, GetClient } from "@revenium/perplexity";
|
|
14
|
-
*
|
|
15
|
-
* // Initialize from environment
|
|
16
|
-
* Initialize();
|
|
17
|
-
*
|
|
18
|
-
* // Get client
|
|
19
|
-
* const client = GetClient();
|
|
20
|
-
*
|
|
21
|
-
* // Use client
|
|
22
|
-
* const response = await client.chat().completions().create({
|
|
23
|
-
* model: "sonar",
|
|
24
|
-
* messages: [{ role: "user", content: "Hello!" }]
|
|
25
|
-
* }, {
|
|
26
|
-
* organizationId: "my-org",
|
|
27
|
-
* productId: "my-app",
|
|
28
|
-
* subscriber: {
|
|
29
|
-
* id: "user-123",
|
|
30
|
-
* email: "user@my-org.com"
|
|
31
|
-
* }
|
|
32
|
-
* });
|
|
33
|
-
*/
|
|
34
|
-
/**
|
|
35
|
-
* Main API - Go-aligned pattern
|
|
2
|
+
* Main API
|
|
36
3
|
*/
|
|
37
4
|
export { Initialize, GetClient, IsInitialized, Reset, Configure, } from "./core/client/index.js";
|
|
38
5
|
/**
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA+BA;;GAEG;AACH,OAAO,EACL,UAAU,EACV,SAAS,EACT,aAAa,EACb,KAAK,EACL,SAAS,GACV,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -2,41 +2,39 @@
|
|
|
2
2
|
* Stop Reason Mapper Utilities
|
|
3
3
|
*
|
|
4
4
|
* Centralized stop reason mapping logic using lookup tables
|
|
5
|
-
* instead of nested conditionals.
|
|
6
|
-
* from the anthropic-node middleware.
|
|
5
|
+
* instead of nested conditionals.
|
|
7
6
|
*/
|
|
8
7
|
/**
|
|
9
8
|
* Stop reason mapping configuration
|
|
10
9
|
* Maps provider-specific stop reasons to Revenium's standardized set
|
|
11
10
|
*/
|
|
12
11
|
const STOP_REASON_MAP = {
|
|
13
|
-
// OpenAI
|
|
14
|
-
stop:
|
|
15
|
-
function_call:
|
|
16
|
-
tool_calls:
|
|
17
|
-
timeout:
|
|
18
|
-
length:
|
|
19
|
-
max_tokens:
|
|
20
|
-
cost_limit:
|
|
21
|
-
completion_limit:
|
|
22
|
-
content_filter:
|
|
23
|
-
error:
|
|
24
|
-
cancelled:
|
|
25
|
-
canceled:
|
|
12
|
+
// OpenAI OpenAI stop reasons
|
|
13
|
+
stop: "END",
|
|
14
|
+
function_call: "END_SEQUENCE",
|
|
15
|
+
tool_calls: "END_SEQUENCE",
|
|
16
|
+
timeout: "TIMEOUT",
|
|
17
|
+
length: "TOKEN_LIMIT",
|
|
18
|
+
max_tokens: "TOKEN_LIMIT",
|
|
19
|
+
cost_limit: "COST_LIMIT",
|
|
20
|
+
completion_limit: "COMPLETION_LIMIT",
|
|
21
|
+
content_filter: "ERROR",
|
|
22
|
+
error: "ERROR",
|
|
23
|
+
cancelled: "CANCELLED",
|
|
24
|
+
canceled: "CANCELLED", // Handle both spellings
|
|
26
25
|
// Anthropic stop reasons (for consistency across middleware)
|
|
27
|
-
end_turn:
|
|
28
|
-
stop_sequence:
|
|
29
|
-
tool_use:
|
|
26
|
+
end_turn: "END",
|
|
27
|
+
stop_sequence: "END_SEQUENCE",
|
|
28
|
+
tool_use: "END_SEQUENCE",
|
|
30
29
|
};
|
|
31
30
|
/**
|
|
32
31
|
* Default stop reason when mapping fails
|
|
33
32
|
*/
|
|
34
|
-
const DEFAULT_STOP_REASON =
|
|
33
|
+
const DEFAULT_STOP_REASON = "END";
|
|
35
34
|
/**
|
|
36
35
|
* Map provider stop reasons to Revenium stop reasons
|
|
37
36
|
*
|
|
38
37
|
* This replaces the nested if/switch logic with a clean lookup table approach.
|
|
39
|
-
* Based on the good example from the anthropic-node middleware.
|
|
40
38
|
*
|
|
41
39
|
* @param providerStopReason - Stop reason from the AI provider
|
|
42
40
|
* @param logger - Optional logger for warnings about unknown reasons
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stop-reason-mapper.js","sourceRoot":"","sources":["../../../src/utils/stop-reason-mapper.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"stop-reason-mapper.js","sourceRoot":"","sources":["../../../src/utils/stop-reason-mapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,MAAM,eAAe,GAA2B;IAC9C,6BAA6B;IAC7B,IAAI,EAAE,KAAK;IACX,aAAa,EAAE,cAAc;IAC7B,UAAU,EAAE,cAAc;IAC1B,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,aAAa;IACrB,UAAU,EAAE,aAAa;IACzB,UAAU,EAAE,YAAY;IACxB,gBAAgB,EAAE,kBAAkB;IACpC,cAAc,EAAE,OAAO;IACvB,KAAK,EAAE,OAAO;IACd,SAAS,EAAE,WAAW;IACtB,QAAQ,EAAE,WAAW,EAAE,wBAAwB;IAE/C,6DAA6D;IAC7D,QAAQ,EAAE,KAAK;IACf,aAAa,EAAE,cAAc;IAC7B,QAAQ,EAAE,cAAc;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC3B,kBAA6C,EAC7C,MAA4D;IAE5D,IAAI,CAAC,kBAAkB;QAAE,OAAO,mBAAmB,CAAC;IACpD,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,WAAW,EAAE,CAAC;IAC1D,MAAM,YAAY,GAAG,eAAe,CAAC,gBAAgB,CAAC,CAAC;IAEvD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,mEAAmE;QACnE,MAAM,EAAE,IAAI,CACV,wBAAwB,kBAAkB,gBAAgB,mBAAmB,EAAE,CAChF,CAAC;QACF,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,OAAO,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,OAAO,MAAM,CAAC,WAAW,EAAE,IAAI,eAAe,CAAC;AACjD,CAAC"}
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
* Configuration module - Main exports
|
|
3
3
|
*
|
|
4
4
|
* This module provides a clean interface for configuration management.
|
|
5
|
-
* Aligned with OpenAI modular implementation.
|
|
6
5
|
*/
|
|
7
|
-
export { loadConfigFromEnv } from
|
|
8
|
-
export { validateConfig } from
|
|
9
|
-
export { getConfig, setConfig, getLogger, initializeConfig, defaultLogger, } from
|
|
6
|
+
export { loadConfigFromEnv } from "./loader.js";
|
|
7
|
+
export { validateConfig } from "./validator.js";
|
|
8
|
+
export { getConfig, setConfig, getLogger, initializeConfig, defaultLogger, } from "./manager.js";
|
|
10
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/config/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/config/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EACL,SAAS,EACT,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,aAAa,GACd,MAAM,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/core/config/manager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/core/config/manager.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAS9D;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAe3B,CAAC;AAIF;;GAEG;AACH,wBAAgB,SAAS,IAAI,cAAc,GAAG,IAAI,CAEjD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAQtD;AAED;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,cAAc,CAkBjD"}
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
* Provider Detection Module
|
|
3
3
|
*
|
|
4
4
|
* Handles provider metadata for Perplexity AI.
|
|
5
|
-
* Simplified compared to OpenAI modular since Perplexity doesn't have Azure variant.
|
|
6
5
|
*/
|
|
7
6
|
import { ProviderInfo } from "../../types/index.js";
|
|
8
7
|
/**
|
|
9
8
|
* Get provider info for Perplexity
|
|
10
|
-
* Always returns Perplexity since there's no Azure variant
|
|
11
9
|
*
|
|
12
10
|
* @returns ProviderInfo with Perplexity provider
|
|
13
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../../../../src/core/providers/detector.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../../../../src/core/providers/detector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAMpD;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,YAAY,CAM7C;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CAKA"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Providers module - Main exports
|
|
3
3
|
*
|
|
4
4
|
* This module provides a clean interface for provider detection and management.
|
|
5
|
-
* Simplified for Perplexity (no Azure variant).
|
|
6
5
|
*/
|
|
7
6
|
export { detectProvider, getProviderMetadata } from "./detector.js";
|
|
8
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/providers/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/providers/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,36 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Revenium Perplexity Middleware for TypeScript
|
|
3
|
-
|
|
4
|
-
* This middleware tracks Perplexity AI usage and sends metrics to Revenium.
|
|
5
|
-
* Uses Go-aligned API pattern with Initialize/GetClient.
|
|
6
|
-
*
|
|
7
|
-
* Environment Variables:
|
|
8
|
-
* REVENIUM_METERING_API_KEY=hak_your_api_key
|
|
9
|
-
* REVENIUM_METERING_BASE_URL=https://api.revenium.ai (optional)
|
|
10
|
-
* PERPLEXITY_API_KEY=pplx_your_perplexity_key
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* import { Initialize, GetClient } from "@revenium/perplexity";
|
|
14
|
-
*
|
|
15
|
-
* // Initialize from environment
|
|
16
|
-
* Initialize();
|
|
17
|
-
*
|
|
18
|
-
* // Get client
|
|
19
|
-
* const client = GetClient();
|
|
20
|
-
*
|
|
21
|
-
* // Use client
|
|
22
|
-
* const response = await client.chat().completions().create({
|
|
23
|
-
* model: "sonar",
|
|
24
|
-
* messages: [{ role: "user", content: "Hello!" }]
|
|
25
|
-
* }, {
|
|
26
|
-
* organizationId: "my-org",
|
|
27
|
-
* productId: "my-app",
|
|
28
|
-
* subscriber: {
|
|
29
|
-
* id: "user-123",
|
|
30
|
-
* email: "user@my-org.com"
|
|
31
|
-
* }
|
|
32
|
-
* });
|
|
33
|
-
*/
|
|
3
|
+
|
|
34
4
|
/**
|
|
35
5
|
* Core types for TypeScript developers using Revenium middleware
|
|
36
6
|
*/
|
|
@@ -40,7 +10,7 @@ export type { ReveniumConfig, UsageMetadata, Logger, ProviderInfo, Subscriber, C
|
|
|
40
10
|
*/
|
|
41
11
|
export type { PerplexityChatRequest, PerplexityChatResponse, PerplexityMessage, PerplexityChoice, PerplexityUsage, PerplexityStreamChunk, PerplexityResponse, TrackingData, } from "./types/function-parameters.js";
|
|
42
12
|
/**
|
|
43
|
-
* Main API
|
|
13
|
+
* Main API
|
|
44
14
|
*/
|
|
45
15
|
export { Initialize, GetClient, IsInitialized, Reset, Configure, } from "./core/client/index.js";
|
|
46
16
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,YAAY,EACV,cAAc,EACd,aAAa,EACb,MAAM,EACN,YAAY,EACZ,UAAU,EACV,UAAU,EACV,eAAe,EACf,YAAY,GACb,MAAM,kBAAkB,CAAC;AAE1B;;GAEG;AACH,YAAY,EACV,qBAAqB,EACrB,sBAAsB,EACtB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,GACb,MAAM,gCAAgC,CAAC;AAExC;;GAEG;AACH,OAAO,EACL,UAAU,EACV,SAAS,EACT,aAAa,EACb,KAAK,EACL,SAAS,GACV,MAAM,wBAAwB,CAAC;AAEhC;;GAEG;AACH,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D;;GAEG;AACH,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
* Stop Reason Mapper Utilities
|
|
3
3
|
*
|
|
4
4
|
* Centralized stop reason mapping logic using lookup tables
|
|
5
|
-
* instead of nested conditionals.
|
|
6
|
-
* from the anthropic-node middleware.
|
|
5
|
+
* instead of nested conditionals.
|
|
7
6
|
*/
|
|
8
7
|
/**
|
|
9
8
|
* Map provider stop reasons to Revenium stop reasons
|
|
10
9
|
*
|
|
11
10
|
* This replaces the nested if/switch logic with a clean lookup table approach.
|
|
12
|
-
* Based on the good example from the anthropic-node middleware.
|
|
13
11
|
*
|
|
14
12
|
* @param providerStopReason - Stop reason from the AI provider
|
|
15
13
|
* @param logger - Optional logger for warnings about unknown reasons
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stop-reason-mapper.d.ts","sourceRoot":"","sources":["../../../src/utils/stop-reason-mapper.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"stop-reason-mapper.d.ts","sourceRoot":"","sources":["../../../src/utils/stop-reason-mapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgCH;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,kBAAkB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC7C,MAAM,CAAC,EAAE;IAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;CAAE,GAC3D,MAAM,CAcR;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,EAAE,CAElD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE7D"}
|
package/examples/README.md
CHANGED
|
@@ -6,8 +6,8 @@ This directory contains examples demonstrating how to use the Revenium Perplexit
|
|
|
6
6
|
|
|
7
7
|
Before running the examples, make sure you have:
|
|
8
8
|
|
|
9
|
-
1. **Node.js
|
|
10
|
-
2. **Revenium API Key** - Get one from [Revenium Dashboard](https://app.revenium.
|
|
9
|
+
1. **Node.js 20+** installed
|
|
10
|
+
2. **Revenium API Key** - Get one from [Revenium Dashboard](https://app.revenium.ai)
|
|
11
11
|
3. **Perplexity API Key** - Get one from [Perplexity Platform](https://www.perplexity.ai)
|
|
12
12
|
|
|
13
13
|
## Setup
|
|
@@ -27,13 +27,17 @@ Before running the examples, make sure you have:
|
|
|
27
27
|
|
|
28
28
|
3. **Configure environment variables**:
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
Create a `.env` file in the project root with your API keys:
|
|
31
31
|
|
|
32
32
|
```bash
|
|
33
|
-
|
|
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
|
|
34
38
|
```
|
|
35
39
|
|
|
36
|
-
|
|
40
|
+
**Note:** The middleware automatically loads `.env` files via `Initialize()`, so no additional configuration is needed.
|
|
37
41
|
|
|
38
42
|
## Examples
|
|
39
43
|
|
|
@@ -215,7 +219,7 @@ npm run example:getting-started
|
|
|
215
219
|
## Next Steps
|
|
216
220
|
|
|
217
221
|
- 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.
|
|
222
|
+
- Visit the [Revenium Dashboard](https://app.revenium.ai) to view your metering data
|
|
219
223
|
- See [.env.example](https://github.com/revenium/revenium-middleware-perplexity-node/blob/HEAD/.env.example) for all configuration options
|
|
220
224
|
|
|
221
225
|
## Support
|
package/examples/stream.ts
CHANGED
package/package.json
CHANGED