@revenium/perplexity 2.0.3 → 2.0.5
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/CHANGELOG.md +47 -10
- package/README.md +144 -720
- package/SECURITY.md +34 -0
- package/dist/cjs/constants/models.js +38 -0
- package/dist/cjs/constants/models.js.map +1 -0
- package/dist/cjs/core/client/index.js +13 -0
- package/dist/cjs/core/client/index.js.map +1 -0
- package/dist/cjs/core/client/manager.js +85 -0
- package/dist/cjs/core/client/manager.js.map +1 -0
- package/dist/cjs/core/config/index.js +21 -0
- package/dist/cjs/core/config/index.js.map +1 -0
- package/dist/cjs/core/config/loader.js +48 -0
- package/dist/cjs/core/config/loader.js.map +1 -0
- package/dist/cjs/core/config/manager.js +77 -0
- package/dist/cjs/core/config/manager.js.map +1 -0
- package/dist/cjs/core/config/validator.js +45 -0
- package/dist/cjs/core/config/validator.js.map +1 -0
- package/dist/cjs/core/middleware/index.js +14 -0
- package/dist/cjs/core/middleware/index.js.map +1 -0
- package/dist/cjs/core/middleware/interfaces.js +94 -0
- package/dist/cjs/core/middleware/interfaces.js.map +1 -0
- package/dist/cjs/core/middleware/revenium-client.js +44 -0
- package/dist/cjs/core/middleware/revenium-client.js.map +1 -0
- package/dist/cjs/core/middleware/streaming-wrapper.js +80 -0
- package/dist/cjs/core/middleware/streaming-wrapper.js.map +1 -0
- package/dist/cjs/core/providers/detector.js +38 -0
- package/dist/cjs/core/providers/detector.js.map +1 -0
- package/dist/cjs/core/providers/index.js +14 -0
- package/dist/cjs/core/providers/index.js.map +1 -0
- package/dist/cjs/core/tracking/api-client.js +67 -0
- package/dist/cjs/core/tracking/api-client.js.map +1 -0
- package/dist/cjs/core/tracking/index.js +21 -0
- package/dist/cjs/core/tracking/index.js.map +1 -0
- package/dist/cjs/core/tracking/payload-builder.js +95 -0
- package/dist/cjs/core/tracking/payload-builder.js.map +1 -0
- package/dist/cjs/core/tracking/usage-tracker.js +83 -0
- package/dist/cjs/core/tracking/usage-tracker.js.map +1 -0
- package/dist/cjs/index.js +60 -54
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types/function-parameters.js +14 -0
- package/dist/cjs/types/function-parameters.js.map +1 -0
- package/dist/cjs/types/index.js +20 -16
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/utils/constants.js +20 -0
- package/dist/cjs/utils/constants.js.map +1 -0
- package/dist/cjs/utils/error-handler.js +194 -0
- package/dist/cjs/utils/error-handler.js.map +1 -0
- package/dist/cjs/utils/metadata-builder.js +191 -0
- package/dist/cjs/utils/metadata-builder.js.map +1 -0
- package/dist/cjs/utils/stop-reason-mapper.js +74 -0
- package/dist/cjs/utils/stop-reason-mapper.js.map +1 -0
- package/dist/cjs/utils/transaction-id.js +19 -0
- package/dist/cjs/utils/transaction-id.js.map +1 -0
- package/dist/cjs/utils/url-builder.js +57 -0
- package/dist/cjs/utils/url-builder.js.map +1 -0
- package/dist/esm/constants/models.js +35 -0
- package/dist/esm/constants/models.js.map +1 -0
- package/dist/esm/core/client/index.js +5 -0
- package/dist/esm/core/client/index.js.map +1 -0
- package/dist/esm/core/client/manager.js +78 -0
- package/dist/esm/core/client/manager.js.map +1 -0
- package/dist/esm/core/config/index.js +11 -0
- package/dist/esm/core/config/index.js.map +1 -0
- package/dist/esm/core/config/loader.js +45 -0
- package/dist/esm/core/config/loader.js.map +1 -0
- package/dist/esm/core/config/manager.js +70 -0
- package/dist/esm/core/config/manager.js.map +1 -0
- package/dist/esm/core/config/validator.js +42 -0
- package/dist/esm/core/config/validator.js.map +1 -0
- package/dist/esm/core/middleware/index.js +7 -0
- package/dist/esm/core/middleware/index.js.map +1 -0
- package/dist/esm/core/middleware/interfaces.js +89 -0
- package/dist/esm/core/middleware/interfaces.js.map +1 -0
- package/dist/esm/core/middleware/revenium-client.js +37 -0
- package/dist/esm/core/middleware/revenium-client.js.map +1 -0
- package/dist/esm/core/middleware/streaming-wrapper.js +76 -0
- package/dist/esm/core/middleware/streaming-wrapper.js.map +1 -0
- package/dist/esm/core/providers/detector.js +34 -0
- package/dist/esm/core/providers/detector.js.map +1 -0
- package/dist/esm/core/providers/index.js +9 -0
- package/dist/esm/core/providers/index.js.map +1 -0
- package/dist/esm/core/tracking/api-client.js +64 -0
- package/dist/esm/core/tracking/api-client.js.map +1 -0
- package/dist/esm/core/tracking/index.js +13 -0
- package/dist/esm/core/tracking/index.js.map +1 -0
- package/dist/esm/core/tracking/payload-builder.js +92 -0
- package/dist/esm/core/tracking/payload-builder.js.map +1 -0
- package/dist/esm/core/tracking/usage-tracker.js +79 -0
- package/dist/esm/core/tracking/usage-tracker.js.map +1 -0
- package/dist/esm/index.js +46 -36
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types/function-parameters.js +13 -0
- package/dist/esm/types/function-parameters.js.map +1 -0
- package/dist/esm/types/index.js +6 -15
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/utils/constants.js +17 -0
- package/dist/esm/utils/constants.js.map +1 -0
- package/dist/esm/utils/error-handler.js +182 -0
- package/dist/esm/utils/error-handler.js.map +1 -0
- package/dist/esm/utils/metadata-builder.js +183 -0
- package/dist/esm/utils/metadata-builder.js.map +1 -0
- package/dist/esm/utils/stop-reason-mapper.js +69 -0
- package/dist/esm/utils/stop-reason-mapper.js.map +1 -0
- package/dist/esm/utils/transaction-id.js +16 -0
- package/dist/esm/utils/transaction-id.js.map +1 -0
- package/dist/esm/utils/url-builder.js +53 -0
- package/dist/esm/utils/url-builder.js.map +1 -0
- package/dist/types/constants/models.d.ts +39 -0
- package/dist/types/constants/models.d.ts.map +1 -0
- package/dist/types/core/client/index.d.ts +5 -0
- package/dist/types/core/client/index.d.ts.map +1 -0
- package/dist/types/core/client/manager.d.ts +44 -0
- package/dist/types/core/client/manager.d.ts.map +1 -0
- package/dist/types/core/config/index.d.ts +10 -0
- package/dist/types/core/config/index.d.ts.map +1 -0
- package/dist/types/core/config/loader.d.ts +13 -0
- package/dist/types/core/config/loader.d.ts.map +1 -0
- package/dist/types/core/config/manager.d.ts +28 -0
- package/dist/types/core/config/manager.d.ts.map +1 -0
- package/dist/types/core/config/validator.d.ts +12 -0
- package/dist/types/core/config/validator.d.ts.map +1 -0
- package/dist/types/core/middleware/index.d.ts +7 -0
- package/dist/types/core/middleware/index.d.ts.map +1 -0
- package/dist/types/core/middleware/interfaces.d.ts +35 -0
- package/dist/types/core/middleware/interfaces.d.ts.map +1 -0
- package/dist/types/core/middleware/revenium-client.d.ts +25 -0
- package/dist/types/core/middleware/revenium-client.d.ts.map +1 -0
- package/dist/types/core/middleware/streaming-wrapper.d.ts +21 -0
- package/dist/types/core/middleware/streaming-wrapper.d.ts.map +1 -0
- package/dist/types/core/providers/detector.d.ts +24 -0
- package/dist/types/core/providers/detector.d.ts.map +1 -0
- package/dist/types/core/providers/index.d.ts +8 -0
- package/dist/types/core/providers/index.d.ts.map +1 -0
- package/dist/types/core/tracking/api-client.d.ts +17 -0
- package/dist/types/core/tracking/api-client.d.ts.map +1 -0
- package/dist/types/core/tracking/index.d.ts +11 -0
- package/dist/types/core/tracking/index.d.ts.map +1 -0
- package/dist/types/core/tracking/payload-builder.d.ts +24 -0
- package/dist/types/core/tracking/payload-builder.d.ts.map +1 -0
- package/dist/types/core/tracking/usage-tracker.d.ts +30 -0
- package/dist/types/core/tracking/usage-tracker.d.ts.map +1 -0
- package/dist/types/index.d.ts +56 -27
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types/function-parameters.d.ts +185 -0
- package/dist/types/types/function-parameters.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +108 -137
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/utils/constants.d.ts +9 -0
- package/dist/types/utils/constants.d.ts.map +1 -0
- package/dist/types/utils/error-handler.d.ts +95 -0
- package/dist/types/utils/error-handler.d.ts.map +1 -0
- package/dist/types/utils/metadata-builder.d.ts +65 -0
- package/dist/types/utils/metadata-builder.d.ts.map +1 -0
- package/dist/types/utils/stop-reason-mapper.d.ts +29 -0
- package/dist/types/utils/stop-reason-mapper.d.ts.map +1 -0
- package/dist/types/utils/transaction-id.d.ts +14 -0
- package/dist/types/utils/transaction-id.d.ts.map +1 -0
- package/dist/types/utils/url-builder.d.ts +22 -0
- package/dist/types/utils/url-builder.d.ts.map +1 -0
- package/examples/README.md +136 -233
- package/examples/advanced.ts +123 -0
- package/examples/basic.ts +36 -46
- package/examples/getting_started.ts +41 -0
- package/examples/metadata.ts +55 -59
- package/examples/stream.ts +53 -0
- package/package.json +12 -17
- package/dist/cjs/core/config/perplexity-config.js +0 -45
- package/dist/cjs/core/config/revenium-config.js +0 -80
- package/dist/cjs/core/tracking/metering.js +0 -131
- package/dist/cjs/core/wrapper/perplexity-client.js +0 -177
- package/dist/cjs/utils/logger.js +0 -23
- package/dist/esm/core/config/perplexity-config.js +0 -40
- package/dist/esm/core/config/revenium-config.js +0 -72
- package/dist/esm/core/tracking/metering.js +0 -126
- package/dist/esm/core/wrapper/perplexity-client.js +0 -170
- package/dist/esm/utils/logger.js +0 -20
- package/dist/types/core/config/perplexity-config.d.ts +0 -24
- package/dist/types/core/config/revenium-config.d.ts +0 -37
- package/dist/types/core/tracking/metering.d.ts +0 -31
- package/dist/types/core/wrapper/perplexity-client.d.ts +0 -32
- package/dist/types/utils/logger.d.ts +0 -10
- package/examples/chat.ts +0 -87
- package/examples/streaming.ts +0 -61
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata Builder Utilities
|
|
3
|
+
*
|
|
4
|
+
* Centralized metadata handling to eliminate repetitive spreading
|
|
5
|
+
* and provide consistent metadata processing across the codebase.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Metadata mapping configuration
|
|
9
|
+
* Maps UsageMetadata fields to payload fields with optional transformations
|
|
10
|
+
* Subscriber object is passed through directly without transformation
|
|
11
|
+
*/
|
|
12
|
+
const METADATA_FIELD_MAP = [
|
|
13
|
+
{ source: 'traceId' },
|
|
14
|
+
{ source: 'taskType' },
|
|
15
|
+
{ source: 'agent' },
|
|
16
|
+
{ source: 'organizationId' },
|
|
17
|
+
{ source: 'productId' },
|
|
18
|
+
{ source: 'subscriber' }, // Pass through nested subscriber object directly
|
|
19
|
+
{ source: 'subscriptionId' },
|
|
20
|
+
{
|
|
21
|
+
source: 'responseQualityScore',
|
|
22
|
+
transform: (value) => {
|
|
23
|
+
// Ensure quality score is between 0.0 and 1.0 (API spec requirement)
|
|
24
|
+
if (typeof value === 'number')
|
|
25
|
+
return Math.max(0, Math.min(1, value));
|
|
26
|
+
return value;
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
/**
|
|
31
|
+
* Build metadata object for payload inclusion
|
|
32
|
+
*
|
|
33
|
+
* This function eliminates the repetitive spreading pattern and provides
|
|
34
|
+
* a clean, testable way to handle metadata transformation.
|
|
35
|
+
* Subscriber object is passed through directly without transformation.
|
|
36
|
+
*
|
|
37
|
+
* @param usageMetadata - Source metadata from request
|
|
38
|
+
* @returns Clean metadata object for payload
|
|
39
|
+
*/
|
|
40
|
+
export function buildMetadataFields(usageMetadata) {
|
|
41
|
+
if (!usageMetadata)
|
|
42
|
+
return {};
|
|
43
|
+
const result = {};
|
|
44
|
+
// Process all metadata fields including nested subscriber object
|
|
45
|
+
for (const config of METADATA_FIELD_MAP) {
|
|
46
|
+
const value = usageMetadata[config.source];
|
|
47
|
+
// Skip undefined values (but allow null, empty strings, objects, etc.)
|
|
48
|
+
if (value === undefined)
|
|
49
|
+
continue;
|
|
50
|
+
// Apply transformation if configured
|
|
51
|
+
const transformedValue = config.transform ? config.transform(value) : value;
|
|
52
|
+
// Use target field name or default to source
|
|
53
|
+
const targetField = config.target || config.source;
|
|
54
|
+
result[targetField] = transformedValue;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Validate metadata completeness for specific use cases
|
|
60
|
+
*
|
|
61
|
+
* @param usageMetadata - Metadata to validate
|
|
62
|
+
* @param requiredFields - List of required field names
|
|
63
|
+
* @returns Validation result
|
|
64
|
+
*/
|
|
65
|
+
export function validateMetadata(usageMetadata, requiredFields = []) {
|
|
66
|
+
const missingFields = [];
|
|
67
|
+
const warnings = [];
|
|
68
|
+
if (!usageMetadata && requiredFields.length > 0) {
|
|
69
|
+
return {
|
|
70
|
+
isValid: false,
|
|
71
|
+
missingFields: requiredFields,
|
|
72
|
+
warnings: ['No metadata provided'],
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
if (usageMetadata) {
|
|
76
|
+
// Check required fields
|
|
77
|
+
for (const field of requiredFields) {
|
|
78
|
+
if (!usageMetadata[field])
|
|
79
|
+
missingFields.push(String(field));
|
|
80
|
+
}
|
|
81
|
+
// Check for common issues
|
|
82
|
+
if (usageMetadata.responseQualityScore) {
|
|
83
|
+
const score = usageMetadata.responseQualityScore;
|
|
84
|
+
// API Spec: https://revenium.readme.io/reference/meter_ai_completion (responseQualityScore)
|
|
85
|
+
// "typically on a 0.0-1.0 scale"
|
|
86
|
+
if (typeof score !== 'number' || score < 0 || score > 1) {
|
|
87
|
+
warnings.push('responseQualityScore should be a number between 0.0 and 1.0');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (usageMetadata.subscriber?.email && !usageMetadata.subscriber.email.includes('@')) {
|
|
91
|
+
warnings.push('subscriber.email does not appear to be a valid email address');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
isValid: missingFields.length === 0,
|
|
96
|
+
missingFields,
|
|
97
|
+
warnings,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Merge multiple metadata sources with priority
|
|
102
|
+
*
|
|
103
|
+
* @param sources - Metadata sources in priority order (first wins)
|
|
104
|
+
* @returns Merged metadata object
|
|
105
|
+
*/
|
|
106
|
+
export function mergeMetadata(...sources) {
|
|
107
|
+
const result = {};
|
|
108
|
+
// Process sources in reverse order so first source wins
|
|
109
|
+
for (const source of sources.reverse()) {
|
|
110
|
+
if (source)
|
|
111
|
+
Object.assign(result, source);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Extract metadata from request parameters safely
|
|
117
|
+
*
|
|
118
|
+
* @param params - Request parameters that might contain usageMetadata
|
|
119
|
+
* @returns Extracted metadata and cleaned parameters
|
|
120
|
+
*/
|
|
121
|
+
export function extractMetadata(params) {
|
|
122
|
+
const { usageMetadata, ...cleanParams } = params;
|
|
123
|
+
return {
|
|
124
|
+
metadata: usageMetadata,
|
|
125
|
+
cleanParams: cleanParams,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create a metadata context for consistent logging
|
|
130
|
+
* Uses sanitization to protect PII (emails are masked)
|
|
131
|
+
*
|
|
132
|
+
* @param usageMetadata - Source metadata
|
|
133
|
+
* @returns Logging context object with sanitized PII
|
|
134
|
+
*/
|
|
135
|
+
export function createLoggingContext(usageMetadata) {
|
|
136
|
+
if (!usageMetadata)
|
|
137
|
+
return {};
|
|
138
|
+
// Use sanitizer to protect PII in logs
|
|
139
|
+
const sanitized = sanitizeMetadataForLogging(usageMetadata);
|
|
140
|
+
const sanitizedSubscriber = sanitized.subscriber;
|
|
141
|
+
return {
|
|
142
|
+
traceId: usageMetadata.traceId,
|
|
143
|
+
taskType: usageMetadata.taskType,
|
|
144
|
+
subscriberId: usageMetadata.subscriber?.id,
|
|
145
|
+
subscriberEmail: sanitizedSubscriber?.email, // ← Now masked: us***@example.com
|
|
146
|
+
organizationId: usageMetadata.organizationId,
|
|
147
|
+
productId: usageMetadata.productId,
|
|
148
|
+
agent: usageMetadata.agent,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Sanitize metadata for logging (remove sensitive fields)
|
|
153
|
+
*
|
|
154
|
+
* @param usageMetadata - Source metadata
|
|
155
|
+
* @returns Sanitized metadata safe for logging
|
|
156
|
+
*/
|
|
157
|
+
export function sanitizeMetadataForLogging(usageMetadata) {
|
|
158
|
+
if (!usageMetadata)
|
|
159
|
+
return {};
|
|
160
|
+
// Create a copy and handle nested subscriber object
|
|
161
|
+
const { subscriber, ...safeMetadata } = usageMetadata;
|
|
162
|
+
const result = { ...safeMetadata };
|
|
163
|
+
// Sanitize subscriber object if present
|
|
164
|
+
if (subscriber) {
|
|
165
|
+
const sanitizedSubscriber = {};
|
|
166
|
+
if (subscriber.id) {
|
|
167
|
+
sanitizedSubscriber.id = subscriber.id;
|
|
168
|
+
}
|
|
169
|
+
if (subscriber.email) {
|
|
170
|
+
// Mask email: handles single-char emails (a@x.com → a***@x.com)
|
|
171
|
+
sanitizedSubscriber.email = subscriber.email.replace(/(.{1,2}).*(@.*)/, '$1***$2');
|
|
172
|
+
}
|
|
173
|
+
if (subscriber.credential) {
|
|
174
|
+
sanitizedSubscriber.credential = {
|
|
175
|
+
name: subscriber.credential.name,
|
|
176
|
+
value: '[REDACTED]',
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
result.subscriber = sanitizedSubscriber;
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=metadata-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-builder.js","sourceRoot":"","sources":["../../../src/utils/metadata-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH;;;;GAIG;AACH,MAAM,kBAAkB,GAA0B;IAChD,EAAE,MAAM,EAAE,SAAS,EAAE;IACrB,EAAE,MAAM,EAAE,UAAU,EAAE;IACtB,EAAE,MAAM,EAAE,OAAO,EAAE;IACnB,EAAE,MAAM,EAAE,gBAAgB,EAAE;IAC5B,EAAE,MAAM,EAAE,WAAW,EAAE;IACvB,EAAE,MAAM,EAAE,YAAY,EAAE,EAAE,iDAAiD;IAC3E,EAAE,MAAM,EAAE,gBAAgB,EAAE;IAC5B;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mB,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,EAAE,SAAS,CAAC,CAAC;QACrF,CAAC;QAED,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;YAC1B,mBAAmB,CAAC,UAAU,GAAG;gBAC/B,IAAI,EAAE,UAAU,CAAC,UAAU,CAAC,IAAI;gBAChC,KAAK,EAAE,YAAY;aACpB,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,UAAU,GAAG,mBAAmB,CAAC;IAC1C,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stop Reason Mapper Utilities
|
|
3
|
+
*
|
|
4
|
+
* Centralized stop reason mapping logic using lookup tables
|
|
5
|
+
* instead of nested conditionals. Based on the good example
|
|
6
|
+
* from the anthropic-node middleware.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Stop reason mapping configuration
|
|
10
|
+
* Maps provider-specific stop reasons to Revenium's standardized set
|
|
11
|
+
*/
|
|
12
|
+
const STOP_REASON_MAP = {
|
|
13
|
+
// OpenAI/Azure OpenAI stop reasons
|
|
14
|
+
stop: 'END',
|
|
15
|
+
function_call: 'END_SEQUENCE',
|
|
16
|
+
tool_calls: 'END_SEQUENCE',
|
|
17
|
+
timeout: 'TIMEOUT',
|
|
18
|
+
length: 'TOKEN_LIMIT',
|
|
19
|
+
max_tokens: 'TOKEN_LIMIT',
|
|
20
|
+
cost_limit: 'COST_LIMIT',
|
|
21
|
+
completion_limit: 'COMPLETION_LIMIT',
|
|
22
|
+
content_filter: 'ERROR',
|
|
23
|
+
error: 'ERROR',
|
|
24
|
+
cancelled: 'CANCELLED',
|
|
25
|
+
canceled: 'CANCELLED', // Handle both spellings
|
|
26
|
+
// Anthropic stop reasons (for consistency across middleware)
|
|
27
|
+
end_turn: 'END',
|
|
28
|
+
stop_sequence: 'END_SEQUENCE',
|
|
29
|
+
tool_use: 'END_SEQUENCE',
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Default stop reason when mapping fails
|
|
33
|
+
*/
|
|
34
|
+
const DEFAULT_STOP_REASON = 'END';
|
|
35
|
+
/**
|
|
36
|
+
* Map provider stop reasons to Revenium stop reasons
|
|
37
|
+
*
|
|
38
|
+
* 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
|
+
*
|
|
41
|
+
* @param providerStopReason - Stop reason from the AI provider
|
|
42
|
+
* @param logger - Optional logger for warnings about unknown reasons
|
|
43
|
+
* @returns Standardized Revenium stop reason
|
|
44
|
+
*/
|
|
45
|
+
export function mapStopReason(providerStopReason, logger) {
|
|
46
|
+
if (!providerStopReason)
|
|
47
|
+
return DEFAULT_STOP_REASON;
|
|
48
|
+
const normalizedReason = providerStopReason.toLowerCase();
|
|
49
|
+
const mappedReason = STOP_REASON_MAP[normalizedReason];
|
|
50
|
+
if (!mappedReason) {
|
|
51
|
+
// Log warning for unknown stop reasons to help with future mapping
|
|
52
|
+
logger?.warn(`Unknown stop reason: ${providerStopReason}, mapping to ${DEFAULT_STOP_REASON}`);
|
|
53
|
+
return DEFAULT_STOP_REASON;
|
|
54
|
+
}
|
|
55
|
+
return mappedReason;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get all supported stop reasons for documentation/testing
|
|
59
|
+
*/
|
|
60
|
+
export function getSupportedStopReasons() {
|
|
61
|
+
return Object.keys(STOP_REASON_MAP);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Check if a stop reason is supported
|
|
65
|
+
*/
|
|
66
|
+
export function isStopReasonSupported(reason) {
|
|
67
|
+
return reason.toLowerCase() in STOP_REASON_MAP;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=stop-reason-mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-reason-mapper.js","sourceRoot":"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Ae,CAAC;AACjD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction ID Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates unique transaction IDs for tracking requests.
|
|
5
|
+
* Format: txn_{timestamp}_{random}
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Generate a unique transaction ID
|
|
9
|
+
*
|
|
10
|
+
* @returns A unique transaction ID in format: txn_{timestamp}_{random}
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
export function generateTransactionId() {
|
|
14
|
+
return `txn_${Date.now()}_${Math.random().toString(36).substring(2, 15)}`;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=transaction-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-id.js","sourceRoot":"","sources":["../../../src/utils/transaction-id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;AAC5E,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL Builder Utilities
|
|
3
|
+
*
|
|
4
|
+
* Centralized URL construction logic to eliminate nested conditionals.
|
|
5
|
+
* Replaces the complex URL building logic from tracking.ts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Build Revenium API URL with proper path handling
|
|
9
|
+
*
|
|
10
|
+
* @param baseUrl - The base URL from configuration (may include /meter or /meter/v2)
|
|
11
|
+
* @param endpoint - The API endpoint to append (e.g., '/ai/completions')
|
|
12
|
+
* @returns Complete URL for the API call
|
|
13
|
+
*/
|
|
14
|
+
export function buildReveniumUrl(baseUrl, endpoint) {
|
|
15
|
+
// Normalize the base URL by removing trailing slashes
|
|
16
|
+
let normalizedBase = baseUrl.replace(/\/+$/, '');
|
|
17
|
+
// Check if /meter/v2 is already at the end
|
|
18
|
+
const hasMeterV2AtEnd = /\/meter\/v2$/i.test(normalizedBase);
|
|
19
|
+
if (hasMeterV2AtEnd) {
|
|
20
|
+
// Already has /meter/v2, just append endpoint
|
|
21
|
+
return `${normalizedBase}${endpoint}`;
|
|
22
|
+
}
|
|
23
|
+
// Check if /meter is at the end (but not /meter/v2)
|
|
24
|
+
const hasMeterAtEnd = /\/meter$/i.test(normalizedBase);
|
|
25
|
+
if (hasMeterAtEnd) {
|
|
26
|
+
// Has /meter but not /v2, append /v2 and endpoint
|
|
27
|
+
return `${normalizedBase}/v2${endpoint}`;
|
|
28
|
+
}
|
|
29
|
+
// Check if /v2 is at the end (without /meter)
|
|
30
|
+
const hasV2AtEnd = /\/v2$/i.test(normalizedBase);
|
|
31
|
+
if (hasV2AtEnd) {
|
|
32
|
+
// Has /v2 but not /meter, append endpoint as-is
|
|
33
|
+
return `${normalizedBase}${endpoint}`;
|
|
34
|
+
}
|
|
35
|
+
// Has neither /meter nor /v2, append /meter/v2 and endpoint
|
|
36
|
+
return `${normalizedBase}/meter/v2${endpoint}`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Validate URL format
|
|
40
|
+
*
|
|
41
|
+
* @param url - URL to validate
|
|
42
|
+
* @returns true if valid, false otherwise
|
|
43
|
+
*/
|
|
44
|
+
export function isValidUrl(url) {
|
|
45
|
+
try {
|
|
46
|
+
new URL(url);
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=url-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-builder.js","sourceRoot":"","sources":["../../../src/utils/url-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAE,QAAgB;IAChE,sDAAsD;IACtD,IAAI,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAEjD,2CAA2C;IAC3C,MAAM,eAAe,GAAG,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC7D,IAAI,eAAe,EAAE,CAAC;QACpB,8CAA8C;QAC9C,OAAO,GAAG,cAAc,GAAG,QAAQ,EAAE,CAAC;IACxC,CAAC;IAED,oDAAoD;IACpD,MAAM,aAAa,GAAG,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACvD,IAAI,aAAa,EAAE,CAAC;QAClB,kDAAkD;QAClD,OAAO,GAAG,cAAc,MAAM,QAAQ,EAAE,CAAC;IAC3C,CAAC;IAED,8CAA8C;IAC9C,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACjD,IAAI,UAAU,EAAE,CAAC;QACf,gDAAgD;QAChD,OAAO,GAAG,cAAc,GAAG,QAAQ,EAAE,CAAC;IACxC,CAAC;IAED,4DAA4D;IAC5D,OAAO,GAAG,cAAc,YAAY,QAAQ,EAAE,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,CAAC;QACH,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Perplexity Model Constants
|
|
3
|
+
*
|
|
4
|
+
* Official model names for Perplexity AI.
|
|
5
|
+
* Use these constants instead of hardcoding model strings.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { PERPLEXITY_MODELS } from "@revenium/perplexity";
|
|
10
|
+
*
|
|
11
|
+
* const response = await client.chat().completions().create({
|
|
12
|
+
* model: PERPLEXITY_MODELS.SONAR_PRO,
|
|
13
|
+
* messages: [{ role: "user", content: "Hello!" }]
|
|
14
|
+
* });
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Available Perplexity AI models
|
|
19
|
+
* @see https://docs.perplexity.ai/docs/model-cards
|
|
20
|
+
*/
|
|
21
|
+
export declare const PERPLEXITY_MODELS: {
|
|
22
|
+
/**
|
|
23
|
+
* Sonar Pro - Most capable model for complex queries
|
|
24
|
+
*/
|
|
25
|
+
readonly SONAR_PRO: "sonar-pro";
|
|
26
|
+
/**
|
|
27
|
+
* Sonar - Standard model for most use cases
|
|
28
|
+
*/
|
|
29
|
+
readonly SONAR: "sonar";
|
|
30
|
+
/**
|
|
31
|
+
* Sonar Reasoning - Specialized for reasoning tasks
|
|
32
|
+
*/
|
|
33
|
+
readonly SONAR_REASONING: "sonar-reasoning";
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Type representing valid Perplexity model names
|
|
37
|
+
*/
|
|
38
|
+
export type PerplexityModel = (typeof PERPLEXITY_MODELS)[keyof typeof PERPLEXITY_MODELS];
|
|
39
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../src/constants/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;;GAGG;AACH,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;;IAGH;;OAEG;;IAGH;;OAEG;;CAEK,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,eAAe,GACzB,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/client/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client Manager - singleton pattern
|
|
3
|
+
*
|
|
4
|
+
* Provides Initialize/GetClient pattern.
|
|
5
|
+
* Manages singleton instance of ReveniumPerplexity client.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import { ReveniumPerplexity } from "../middleware/revenium-client.js";
|
|
9
|
+
import type { ReveniumConfig } from "../../types/index.js";
|
|
10
|
+
/**
|
|
11
|
+
* Initialize Revenium Perplexity client from environment variables
|
|
12
|
+
*
|
|
13
|
+
* Loads configuration from environment:
|
|
14
|
+
* - REVENIUM_METERING_API_KEY (required)
|
|
15
|
+
* - PERPLEXITY_API_KEY (required)
|
|
16
|
+
* @throws {Error} If required environment variables are missing
|
|
17
|
+
*/
|
|
18
|
+
export declare function Initialize(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Configure Revenium Perplexity client with custom configuration
|
|
21
|
+
*
|
|
22
|
+
* @param config - Configuration object
|
|
23
|
+
* @throws {Error} If required configuration fields are missing
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
export declare function Configure(config: ReveniumConfig): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get the singleton ReveniumPerplexity client instance
|
|
29
|
+
*
|
|
30
|
+
* @returns {ReveniumPerplexity} The client instance
|
|
31
|
+
* @throws {Error} If client has not been initialized
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
34
|
+
export declare function GetClient(): ReveniumPerplexity;
|
|
35
|
+
/**
|
|
36
|
+
* Check if client has been initialized
|
|
37
|
+
* @returns {boolean} True if client is initialized
|
|
38
|
+
*/
|
|
39
|
+
export declare function IsInitialized(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Reset the client instance (useful for testing)
|
|
42
|
+
*/
|
|
43
|
+
export declare function Reset(): void;
|
|
44
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/core/client/manager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAW3D;;;;;;;GAOG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAOjC;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAkBtD;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,IAAI,kBAAkB,CAO9C;AAED;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;GAEG;AACH,wBAAgB,KAAK,IAAI,IAAI,CAE5B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration module - Main exports
|
|
3
|
+
*
|
|
4
|
+
* This module provides a clean interface for configuration management.
|
|
5
|
+
* Aligned with OpenAI modular implementation.
|
|
6
|
+
*/
|
|
7
|
+
export { loadConfigFromEnv } from './loader.js';
|
|
8
|
+
export { validateConfig } from './validator.js';
|
|
9
|
+
export { getConfig, setConfig, getLogger, initializeConfig, defaultLogger, } from './manager.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/config/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Loader Module
|
|
3
|
+
*
|
|
4
|
+
* Handles loading configuration from environment variables.
|
|
5
|
+
* Separated from validation and management for single responsibility.
|
|
6
|
+
*/
|
|
7
|
+
import { ReveniumConfig } from "../../types/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Load configuration from environment variables
|
|
10
|
+
* Automatically loads .env file from current directory if present
|
|
11
|
+
*/
|
|
12
|
+
export declare function loadConfigFromEnv(): ReveniumConfig | null;
|
|
13
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../src/core/config/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AActD;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,IAAI,CA2BzD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Manager Module
|
|
3
|
+
*
|
|
4
|
+
* Handles global configuration state management and logging.
|
|
5
|
+
* Aligned with OpenAI modular implementation.
|
|
6
|
+
*/
|
|
7
|
+
import { ReveniumConfig, Logger } from "../../types/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Default console logger implementation
|
|
10
|
+
*/
|
|
11
|
+
export declare const defaultLogger: Logger;
|
|
12
|
+
/**
|
|
13
|
+
* Get the current global configuration
|
|
14
|
+
*/
|
|
15
|
+
export declare function getConfig(): ReveniumConfig | null;
|
|
16
|
+
/**
|
|
17
|
+
* Set the global configuration
|
|
18
|
+
*/
|
|
19
|
+
export declare function setConfig(config: ReveniumConfig): void;
|
|
20
|
+
/**
|
|
21
|
+
* Get the current logger
|
|
22
|
+
*/
|
|
23
|
+
export declare function getLogger(): Logger;
|
|
24
|
+
/**
|
|
25
|
+
* Initialize configuration from environment variables
|
|
26
|
+
*/
|
|
27
|
+
export declare function initializeConfig(): ReveniumConfig;
|
|
28
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../../../src/core/config/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAY9D;;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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration Validator Module
|
|
3
|
+
*
|
|
4
|
+
* Handles validation of configuration objects.
|
|
5
|
+
* Separated from loading and management for single responsibility.
|
|
6
|
+
*/
|
|
7
|
+
import { ReveniumConfig } from "../../types/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Validate Revenium configuration
|
|
10
|
+
*/
|
|
11
|
+
export declare function validateConfig(config: ReveniumConfig): void;
|
|
12
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../../src/core/config/validator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CA8C3D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Middleware module exports
|
|
3
|
+
*/
|
|
4
|
+
export { ReveniumPerplexity } from "./revenium-client.js";
|
|
5
|
+
export { ChatInterface, CompletionsInterface } from "./interfaces.js";
|
|
6
|
+
export { StreamingWrapper } from "./streaming-wrapper.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/middleware/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Middleware interfaces for Perplexity API
|
|
3
|
+
*/
|
|
4
|
+
import type OpenAI from "openai";
|
|
5
|
+
import type { UsageMetadata } from "../../types";
|
|
6
|
+
import { StreamingWrapper } from "./streaming-wrapper.js";
|
|
7
|
+
/**
|
|
8
|
+
* Chat interface - provides access to chat completions
|
|
9
|
+
*/
|
|
10
|
+
export declare class ChatInterface {
|
|
11
|
+
private client;
|
|
12
|
+
private config;
|
|
13
|
+
constructor(client: OpenAI, config: any);
|
|
14
|
+
/**
|
|
15
|
+
* Get completions interface
|
|
16
|
+
*/
|
|
17
|
+
completions(): CompletionsInterface;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Completions interface - handles chat completion requests
|
|
21
|
+
*/
|
|
22
|
+
export declare class CompletionsInterface {
|
|
23
|
+
private client;
|
|
24
|
+
private config;
|
|
25
|
+
constructor(client: OpenAI, config: any);
|
|
26
|
+
/**
|
|
27
|
+
* Create a chat completion
|
|
28
|
+
*/
|
|
29
|
+
create(params: OpenAI.Chat.ChatCompletionCreateParams, metadata?: UsageMetadata): Promise<any>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a streaming chat completion
|
|
32
|
+
*/
|
|
33
|
+
createStreaming(params: OpenAI.Chat.ChatCompletionCreateParams, metadata?: UsageMetadata): Promise<StreamingWrapper>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../../src/core/middleware/interfaces.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAIjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAI1D;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,MAAM;IAAU,OAAO,CAAC,MAAM;gBAA9B,MAAM,EAAE,MAAM,EAAU,MAAM,EAAE,GAAG;IAEvD;;OAEG;IACH,WAAW,IAAI,oBAAoB;CAGpC;AAED;;GAEG;AACH,qBAAa,oBAAoB;IACnB,OAAO,CAAC,MAAM;IAAU,OAAO,CAAC,MAAM;gBAA9B,MAAM,EAAE,MAAM,EAAU,MAAM,EAAE,GAAG;IAEvD;;OAEG;IACG,MAAM,CACV,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAC9C,QAAQ,CAAC,EAAE,aAAa,GACvB,OAAO,CAAC,GAAG,CAAC;IA2Cf;;OAEG;IACG,eAAe,CACnB,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAC9C,QAAQ,CAAC,EAAE,aAAa;CA8B3B"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Revenium Perplexity Client
|
|
3
|
+
*
|
|
4
|
+
* Main client class that wraps Perplexity API with Revenium tracking
|
|
5
|
+
*/
|
|
6
|
+
import OpenAI from "openai";
|
|
7
|
+
import { ChatInterface } from "./interfaces.js";
|
|
8
|
+
import type { ReveniumConfig } from "../../types/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Revenium Perplexity client with usage tracking
|
|
11
|
+
*/
|
|
12
|
+
export declare class ReveniumPerplexity {
|
|
13
|
+
private client;
|
|
14
|
+
private config;
|
|
15
|
+
constructor(config: ReveniumConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Get chat interface
|
|
18
|
+
*/
|
|
19
|
+
chat(): ChatInterface;
|
|
20
|
+
/**
|
|
21
|
+
* Get underlying OpenAI client (for advanced use cases)
|
|
22
|
+
*/
|
|
23
|
+
getUnderlyingClient(): OpenAI;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=revenium-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revenium-client.d.ts","sourceRoot":"","sources":["../../../../src/core/middleware/revenium-client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,cAAc;IAclC;;OAEG;IACH,IAAI,IAAI,aAAa;IAIrB;;OAEG;IACH,mBAAmB,IAAI,MAAM;CAG9B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streaming wrapper for Perplexity API
|
|
3
|
+
*/
|
|
4
|
+
import type { UsageMetadata } from "../../types";
|
|
5
|
+
/**
|
|
6
|
+
* Wrapper for streaming responses that tracks usage
|
|
7
|
+
*/
|
|
8
|
+
export declare class StreamingWrapper {
|
|
9
|
+
private stream;
|
|
10
|
+
private model;
|
|
11
|
+
private startTime;
|
|
12
|
+
private transactionId;
|
|
13
|
+
private metadata?;
|
|
14
|
+
private config;
|
|
15
|
+
constructor(stream: AsyncIterable<any>, model: string, startTime: Date, transactionId: string, metadata?: UsageMetadata, config?: any);
|
|
16
|
+
/**
|
|
17
|
+
* Iterate over stream chunks
|
|
18
|
+
*/
|
|
19
|
+
[Symbol.asyncIterator](): AsyncGenerator<any>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=streaming-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-wrapper.d.ts","sourceRoot":"","sources":["../../../../src/core/middleware/streaming-wrapper.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD;;GAEG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAqB;IACnC,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,SAAS,CAAO;IACxB,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,CAAgB;IACjC,OAAO,CAAC,MAAM,CAAM;gBAGlB,MAAM,EAAE,aAAa,CAAC,GAAG,CAAC,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,IAAI,EACf,aAAa,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,aAAa,EACxB,MAAM,CAAC,EAAE,GAAG;IAUd;;OAEG;IACI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,GAAG,CAAC;CA0DrD"}
|