@revenium/perplexity 2.0.4 → 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 +32 -33
- package/README.md +120 -101
- 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 -59
- package/dist/cjs/index.js.map +1 -1
- 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 -1
- package/dist/cjs/types/index.js.map +1 -1
- 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 -39
- package/dist/esm/index.js.map +1 -1
- 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 -2
- package/dist/esm/types/index.js.map +1 -1
- 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 -1
- 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 -129
- package/dist/types/types/index.d.ts.map +1 -1
- 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 +124 -220
- package/examples/advanced.ts +123 -0
- package/examples/basic.ts +32 -37
- package/examples/getting_started.ts +26 -49
- package/examples/metadata.ts +51 -48
- package/examples/stream.ts +53 -0
- package/package.json +9 -10
- package/dist/cjs/constants.js +0 -70
- package/dist/cjs/constants.js.map +0 -1
- package/dist/cjs/core/config/perplexity-config.js +0 -45
- package/dist/cjs/core/config/perplexity-config.js.map +0 -1
- package/dist/cjs/core/config/revenium-config.js +0 -80
- package/dist/cjs/core/config/revenium-config.js.map +0 -1
- package/dist/cjs/core/tracking/metering.js +0 -211
- package/dist/cjs/core/tracking/metering.js.map +0 -1
- package/dist/cjs/core/wrapper/perplexity-client.js +0 -187
- package/dist/cjs/core/wrapper/perplexity-client.js.map +0 -1
- package/dist/cjs/utils/logger.js +0 -23
- package/dist/cjs/utils/logger.js.map +0 -1
- package/dist/esm/constants.js +0 -67
- package/dist/esm/constants.js.map +0 -1
- package/dist/esm/core/config/perplexity-config.js +0 -40
- package/dist/esm/core/config/perplexity-config.js.map +0 -1
- package/dist/esm/core/config/revenium-config.js +0 -72
- package/dist/esm/core/config/revenium-config.js.map +0 -1
- package/dist/esm/core/tracking/metering.js +0 -206
- package/dist/esm/core/tracking/metering.js.map +0 -1
- package/dist/esm/core/wrapper/perplexity-client.js +0 -180
- package/dist/esm/core/wrapper/perplexity-client.js.map +0 -1
- package/dist/esm/utils/logger.js +0 -20
- package/dist/esm/utils/logger.js.map +0 -1
- package/dist/types/constants.d.ts +0 -67
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/core/config/perplexity-config.d.ts +0 -24
- package/dist/types/core/config/perplexity-config.d.ts.map +0 -1
- package/dist/types/core/config/revenium-config.d.ts +0 -37
- package/dist/types/core/config/revenium-config.d.ts.map +0 -1
- package/dist/types/core/tracking/metering.d.ts +0 -31
- package/dist/types/core/tracking/metering.d.ts.map +0 -1
- package/dist/types/core/wrapper/perplexity-client.d.ts +0 -32
- package/dist/types/core/wrapper/perplexity-client.d.ts.map +0 -1
- package/dist/types/utils/logger.d.ts +0 -10
- package/dist/types/utils/logger.d.ts.map +0 -1
- package/examples/advanced-features.ts +0 -148
- package/examples/chat.ts +0 -73
- package/examples/streaming.ts +0 -50
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function Parameter Types
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive type definitions for function parameters throughout the middleware.
|
|
5
|
+
* These interfaces provide type safety by replacing 'any' types with proper,
|
|
6
|
+
* well-documented interfaces that match Perplexity API structures and internal requirements.
|
|
7
|
+
*
|
|
8
|
+
* @fileoverview Type-safe function parameter definitions
|
|
9
|
+
* @author Revenium
|
|
10
|
+
* @since 2.0.0
|
|
11
|
+
*/
|
|
12
|
+
import { UsageMetadata } from "./index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Perplexity API response structure for chat completions
|
|
15
|
+
*
|
|
16
|
+
* Represents the complete response structure returned by Perplexity's chat completions API.
|
|
17
|
+
* Includes usage statistics, response choices, and metadata. Used internally for
|
|
18
|
+
* processing responses and extracting usage metrics.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export interface PerplexityChatResponse {
|
|
23
|
+
/** Unique identifier for the chat completion */
|
|
24
|
+
id: string;
|
|
25
|
+
/** Model used for the completion */
|
|
26
|
+
model: string;
|
|
27
|
+
/** Token usage statistics */
|
|
28
|
+
usage: {
|
|
29
|
+
/** Number of tokens in the prompt */
|
|
30
|
+
prompt_tokens: number;
|
|
31
|
+
/** Number of tokens in the completion */
|
|
32
|
+
completion_tokens: number;
|
|
33
|
+
/** Total tokens used (prompt + completion) */
|
|
34
|
+
total_tokens: number;
|
|
35
|
+
};
|
|
36
|
+
/** Array of completion choices */
|
|
37
|
+
choices: Array<{
|
|
38
|
+
/** Reason why the completion finished */
|
|
39
|
+
finish_reason: string | null;
|
|
40
|
+
/** Complete message (for non-streaming responses) */
|
|
41
|
+
message?: {
|
|
42
|
+
/** Message content */
|
|
43
|
+
content: string;
|
|
44
|
+
/** Message role (assistant, user, system) */
|
|
45
|
+
role: string;
|
|
46
|
+
};
|
|
47
|
+
/** Delta message (for streaming responses) */
|
|
48
|
+
delta?: {
|
|
49
|
+
/** Incremental content */
|
|
50
|
+
content?: string;
|
|
51
|
+
/** Message role */
|
|
52
|
+
role?: string;
|
|
53
|
+
};
|
|
54
|
+
}>;
|
|
55
|
+
/** Unix timestamp of when the completion was created */
|
|
56
|
+
created?: number;
|
|
57
|
+
/** Object type identifier */
|
|
58
|
+
object?: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Perplexity API request structure for chat completions
|
|
62
|
+
*
|
|
63
|
+
* Represents the request parameters sent to Perplexity's chat completions API.
|
|
64
|
+
* Includes model selection, messages, and optional parameters.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export interface PerplexityChatRequest {
|
|
69
|
+
/** Model to use for the completion */
|
|
70
|
+
model: string;
|
|
71
|
+
/** Array of messages in the conversation */
|
|
72
|
+
messages: Array<{
|
|
73
|
+
/** Message role */
|
|
74
|
+
role: "system" | "user" | "assistant";
|
|
75
|
+
/** Message content */
|
|
76
|
+
content: string;
|
|
77
|
+
}>;
|
|
78
|
+
/** Maximum number of tokens to generate */
|
|
79
|
+
max_tokens?: number;
|
|
80
|
+
/** Temperature for sampling */
|
|
81
|
+
temperature?: number;
|
|
82
|
+
/** Top-p for nucleus sampling */
|
|
83
|
+
top_p?: number;
|
|
84
|
+
/** Whether to stream the response */
|
|
85
|
+
stream?: boolean;
|
|
86
|
+
/** Presence penalty */
|
|
87
|
+
presence_penalty?: number;
|
|
88
|
+
/** Frequency penalty */
|
|
89
|
+
frequency_penalty?: number;
|
|
90
|
+
/** Usage metadata for Revenium tracking (custom field, not sent to Perplexity) */
|
|
91
|
+
usageMetadata?: UsageMetadata;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Perplexity message structure
|
|
95
|
+
*/
|
|
96
|
+
export interface PerplexityMessage {
|
|
97
|
+
role: "system" | "user" | "assistant";
|
|
98
|
+
content: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Perplexity cost breakdown (specific to Perplexity API)
|
|
102
|
+
*/
|
|
103
|
+
export interface PerplexityCost {
|
|
104
|
+
input_tokens_cost: number;
|
|
105
|
+
output_tokens_cost: number;
|
|
106
|
+
request_cost: number;
|
|
107
|
+
total_cost: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Perplexity usage statistics
|
|
111
|
+
*/
|
|
112
|
+
export interface PerplexityUsage {
|
|
113
|
+
prompt_tokens: number;
|
|
114
|
+
completion_tokens: number;
|
|
115
|
+
total_tokens: number;
|
|
116
|
+
search_context_size?: string;
|
|
117
|
+
cost?: PerplexityCost;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Perplexity choice structure
|
|
121
|
+
*/
|
|
122
|
+
export interface PerplexityChoice {
|
|
123
|
+
index: number;
|
|
124
|
+
message?: {
|
|
125
|
+
role: string;
|
|
126
|
+
content: string;
|
|
127
|
+
};
|
|
128
|
+
delta?: {
|
|
129
|
+
role?: string;
|
|
130
|
+
content?: string;
|
|
131
|
+
};
|
|
132
|
+
finish_reason: string | null;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Perplexity response structure
|
|
136
|
+
*/
|
|
137
|
+
export interface PerplexityResponse {
|
|
138
|
+
id: string;
|
|
139
|
+
object: string;
|
|
140
|
+
created: number;
|
|
141
|
+
model: string;
|
|
142
|
+
choices: PerplexityChoice[];
|
|
143
|
+
usage?: PerplexityUsage;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Perplexity stream chunk structure
|
|
147
|
+
*/
|
|
148
|
+
export interface PerplexityStreamChunk {
|
|
149
|
+
id: string;
|
|
150
|
+
object: string;
|
|
151
|
+
created: number;
|
|
152
|
+
model: string;
|
|
153
|
+
choices: PerplexityChoice[];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Tracking data structure for usage tracking
|
|
157
|
+
*
|
|
158
|
+
* Contains all necessary information for tracking API usage with Revenium.
|
|
159
|
+
* Used internally by the tracking system.
|
|
160
|
+
*
|
|
161
|
+
* @internal
|
|
162
|
+
*/
|
|
163
|
+
export interface TrackingData {
|
|
164
|
+
/** Unique request identifier */
|
|
165
|
+
requestId: string;
|
|
166
|
+
/** Model used for the request */
|
|
167
|
+
model: string;
|
|
168
|
+
/** Number of prompt tokens */
|
|
169
|
+
promptTokens: number;
|
|
170
|
+
/** Number of completion tokens */
|
|
171
|
+
completionTokens: number;
|
|
172
|
+
/** Total number of tokens */
|
|
173
|
+
totalTokens: number;
|
|
174
|
+
/** Request duration in milliseconds */
|
|
175
|
+
duration: number;
|
|
176
|
+
/** Finish reason from the API */
|
|
177
|
+
finishReason: string | null;
|
|
178
|
+
/** Usage metadata */
|
|
179
|
+
usageMetadata?: UsageMetadata;
|
|
180
|
+
/** Whether the request was streamed */
|
|
181
|
+
isStreamed?: boolean;
|
|
182
|
+
/** Time to first token (for streaming) */
|
|
183
|
+
timeToFirstToken?: number;
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=function-parameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-parameters.d.ts","sourceRoot":"","sources":["../../../src/types/function-parameters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C;;;;;;;;GAQG;AACH,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,o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pC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,gBAAgB,EAAE,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,gCAAgC;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,gBAAgB,EAAE,MAAM,CAAC;IACzB,6BAA6B;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,qBAAqB;IACrB,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,uCAAuC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,0CAA0C;IAC1C,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B"}
|
|
@@ -1,151 +1,130 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Core Types Module
|
|
3
|
+
*
|
|
4
|
+
* Central type definitions for the Revenium Perplexity middleware.
|
|
5
|
+
* This module exports all core types used throughout the application.
|
|
3
6
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export interface
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
top_p?: number;
|
|
14
|
-
stream?: boolean;
|
|
15
|
-
presence_penalty?: number;
|
|
16
|
-
frequency_penalty?: number;
|
|
17
|
-
}
|
|
18
|
-
export interface PerplexityUsage {
|
|
19
|
-
prompt_tokens: number;
|
|
20
|
-
completion_tokens: number;
|
|
21
|
-
total_tokens: number;
|
|
22
|
-
}
|
|
23
|
-
export interface PerplexityChoice {
|
|
24
|
-
index: number;
|
|
25
|
-
message?: {
|
|
26
|
-
role: string;
|
|
27
|
-
content: string;
|
|
28
|
-
};
|
|
29
|
-
delta?: {
|
|
30
|
-
role?: string;
|
|
31
|
-
content?: string;
|
|
32
|
-
};
|
|
33
|
-
finish_reason: string | null;
|
|
34
|
-
}
|
|
35
|
-
export interface PerplexityResponse {
|
|
36
|
-
id: string;
|
|
37
|
-
object: string;
|
|
38
|
-
created: number;
|
|
39
|
-
model: string;
|
|
40
|
-
choices: PerplexityChoice[];
|
|
41
|
-
usage?: PerplexityUsage;
|
|
7
|
+
export * from "./function-parameters.js";
|
|
8
|
+
/**
|
|
9
|
+
* Credential information for subscriber authentication
|
|
10
|
+
*/
|
|
11
|
+
export interface Credential {
|
|
12
|
+
/** The name/type of the credential */
|
|
13
|
+
name: string;
|
|
14
|
+
/** The credential value */
|
|
15
|
+
value: string;
|
|
42
16
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Subscriber information for Revenium API
|
|
19
|
+
*/
|
|
20
|
+
export interface Subscriber {
|
|
21
|
+
/** Unique identifier for the subscriber/user */
|
|
22
|
+
id?: string;
|
|
23
|
+
/** Email address of the subscriber */
|
|
24
|
+
email?: string;
|
|
25
|
+
/** Optional authentication credential for the subscriber */
|
|
26
|
+
credential?: Credential;
|
|
49
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Usage metadata interface for tracking additional context
|
|
30
|
+
*/
|
|
50
31
|
export interface UsageMetadata {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
credential?: {
|
|
55
|
-
name: string;
|
|
56
|
-
value: string;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
32
|
+
/** User identification information */
|
|
33
|
+
subscriber?: Subscriber;
|
|
34
|
+
/** Organization or company identifier */
|
|
59
35
|
organizationId?: string;
|
|
60
|
-
|
|
36
|
+
/** Product or application identifier */
|
|
61
37
|
productId?: string;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
outputTokenCount?: number;
|
|
66
|
-
totalTokenCount?: number;
|
|
67
|
-
reasoningTokenCount?: number;
|
|
68
|
-
cacheCreationTokenCount?: number;
|
|
69
|
-
cacheReadTokenCount?: number;
|
|
70
|
-
requestTime?: string;
|
|
71
|
-
responseTime?: string;
|
|
72
|
-
completionStartTime?: string;
|
|
73
|
-
timeToFirstToken?: number;
|
|
74
|
-
operationType?: string;
|
|
38
|
+
/** Subscription identifier */
|
|
39
|
+
subscriptionId?: string;
|
|
40
|
+
/** Task type classification */
|
|
75
41
|
taskType?: string;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
42
|
+
/** Distributed tracing identifier */
|
|
43
|
+
traceId?: string;
|
|
44
|
+
/** Quality score for response evaluation (0.0-1.0 scale) */
|
|
79
45
|
responseQualityScore?: number;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
subscriberCredentialName?: string;
|
|
83
|
-
subscriberCredential?: string;
|
|
46
|
+
/** Agent or model variant identifier */
|
|
47
|
+
agent?: string;
|
|
84
48
|
}
|
|
85
49
|
/**
|
|
86
|
-
*
|
|
87
|
-
* Field order matches the expected API format
|
|
50
|
+
* Provider information for tracking API source
|
|
88
51
|
*/
|
|
89
|
-
export interface
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
52
|
+
export interface ProviderInfo {
|
|
53
|
+
/** The detected AI provider type */
|
|
54
|
+
provider: string;
|
|
55
|
+
/** Model source identifier */
|
|
56
|
+
modelSource: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Logger interface aligned with Go implementation
|
|
60
|
+
*/
|
|
61
|
+
export interface Logger {
|
|
62
|
+
debug(message: string, ...args: unknown[]): void;
|
|
63
|
+
info(message: string, ...args: unknown[]): void;
|
|
64
|
+
warn(message: string, ...args: unknown[]): void;
|
|
65
|
+
error(message: string, ...args: unknown[]): void;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Revenium configuration interface
|
|
69
|
+
*/
|
|
70
|
+
export interface ReveniumConfig {
|
|
71
|
+
/** Revenium API key */
|
|
72
|
+
reveniumApiKey: string;
|
|
73
|
+
/** Revenium base URL */
|
|
74
|
+
reveniumBaseUrl: string;
|
|
75
|
+
/** Perplexity API key */
|
|
76
|
+
perplexityApiKey?: string;
|
|
77
|
+
/** Perplexity base URL */
|
|
78
|
+
perplexityBaseUrl?: string;
|
|
79
|
+
/** Debug mode flag */
|
|
80
|
+
debug?: boolean;
|
|
81
|
+
/** Custom logger */
|
|
82
|
+
logger?: Logger;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Configuration interface (alias for backward compatibility)
|
|
86
|
+
*/
|
|
87
|
+
export interface Config extends ReveniumConfig {
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Revenium API payload structure
|
|
91
|
+
*/
|
|
92
|
+
export interface ReveniumPayload {
|
|
93
|
+
costType: "AI";
|
|
112
94
|
model: string;
|
|
113
|
-
transactionId: string;
|
|
114
95
|
responseTime: string;
|
|
115
96
|
requestDuration: number;
|
|
116
97
|
provider: string;
|
|
98
|
+
modelSource: string;
|
|
117
99
|
requestTime: string;
|
|
118
100
|
completionStartTime: string;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
completionTokens: number;
|
|
130
|
-
totalTokens: number;
|
|
131
|
-
};
|
|
132
|
-
model: string;
|
|
133
|
-
transactionId: string;
|
|
134
|
-
rawResponse: PerplexityResponse;
|
|
135
|
-
}
|
|
136
|
-
export interface StreamingResult {
|
|
137
|
-
stream: AsyncGenerator<PerplexityStreamChunk>;
|
|
101
|
+
inputTokenCount: number;
|
|
102
|
+
outputTokenCount: number;
|
|
103
|
+
totalTokenCount: number;
|
|
104
|
+
reasoningTokenCount?: number;
|
|
105
|
+
cacheCreationTokenCount?: number;
|
|
106
|
+
cacheReadTokenCount?: number;
|
|
107
|
+
organizationId?: string;
|
|
108
|
+
subscriptionId?: string;
|
|
109
|
+
productId?: string;
|
|
110
|
+
subscriber?: Subscriber;
|
|
138
111
|
transactionId: string;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
112
|
+
traceId?: string;
|
|
113
|
+
taskType?: string;
|
|
114
|
+
operationType: "CHAT" | "EMBED";
|
|
115
|
+
stopReason: string;
|
|
116
|
+
isStreamed: boolean;
|
|
117
|
+
timeToFirstToken?: number;
|
|
118
|
+
agent?: string;
|
|
119
|
+
responseQualityScore?: number;
|
|
120
|
+
middlewareSource: string;
|
|
121
|
+
inputTokenCost?: number;
|
|
122
|
+
outputTokenCost?: number;
|
|
123
|
+
totalCost?: number;
|
|
146
124
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Metering data interface (legacy, for backward compatibility)
|
|
127
|
+
*/
|
|
128
|
+
export interface MeteringData extends ReveniumPayload {
|
|
150
129
|
}
|
|
151
130
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;GAK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AAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAG9B,gBAAgB,EAAE,MAAM,CAAC;IAGzB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,eAAe;CAAG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error message patterns for network-related errors
|
|
3
|
+
*/
|
|
4
|
+
export declare const MESSAGE_PATTERNS_TYPE_NETWORK: string[];
|
|
5
|
+
/**
|
|
6
|
+
* Error message patterns for configuration-related errors
|
|
7
|
+
*/
|
|
8
|
+
export declare const ERROR_MESSAGE_PATTERNS_TYPE_CONFIG: string[];
|
|
9
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/utils/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,6BAA6B,UAIzC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kCAAkC,UAI9C,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Handler Utilities
|
|
3
|
+
*
|
|
4
|
+
* Centralized error handling patterns to eliminate repetitive try/catch blocks
|
|
5
|
+
* and provide consistent error logging and recovery strategies.
|
|
6
|
+
*/
|
|
7
|
+
import { Logger } from '../types/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Error handling strategy configuration
|
|
10
|
+
*/
|
|
11
|
+
export interface ErrorHandlingStrategy {
|
|
12
|
+
/** Whether to log the error */
|
|
13
|
+
logError?: boolean;
|
|
14
|
+
/** Whether to re-throw the error */
|
|
15
|
+
rethrow?: boolean;
|
|
16
|
+
/** Custom error message prefix */
|
|
17
|
+
messagePrefix?: string;
|
|
18
|
+
/** Fallback value to return on error */
|
|
19
|
+
fallbackValue?: unknown;
|
|
20
|
+
/** Custom error transformation function */
|
|
21
|
+
transformError?: (error: unknown) => Error;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Safe async operation wrapper with comprehensive error handling
|
|
25
|
+
*
|
|
26
|
+
* @param operation - The async operation to execute
|
|
27
|
+
* @param context - Context information for logging
|
|
28
|
+
* @param strategy - Error handling strategy
|
|
29
|
+
* @param logger - Logger instance
|
|
30
|
+
* @returns Promise with result or fallback value
|
|
31
|
+
*/
|
|
32
|
+
export declare function safeAsyncOperation<T>(operation: () => Promise<T>, context: string, strategy?: ErrorHandlingStrategy, logger?: Logger): Promise<T | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Safe sync operation wrapper
|
|
35
|
+
*
|
|
36
|
+
* @param operation - The sync operation to execute
|
|
37
|
+
* @param context - Context information for logging
|
|
38
|
+
* @param strategy - Error handling strategy
|
|
39
|
+
* @param logger - Logger instance
|
|
40
|
+
* @returns Result or fallback value
|
|
41
|
+
*/
|
|
42
|
+
export declare function safeSyncOperation<T>(operation: () => T, context: string, strategy?: ErrorHandlingStrategy, logger?: Logger): T | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Validation wrapper that provides clear error messages
|
|
45
|
+
*
|
|
46
|
+
* @param value - Value to validate
|
|
47
|
+
* @param validator - Validation function
|
|
48
|
+
* @param errorMessage - Error message if validation fails
|
|
49
|
+
* @returns Validated value
|
|
50
|
+
*/
|
|
51
|
+
export declare function validateOrThrow<T>(value: unknown, validator: (value: unknown) => value is T, errorMessage: string): T;
|
|
52
|
+
/**
|
|
53
|
+
* Validation wrapper that returns undefined on failure
|
|
54
|
+
*
|
|
55
|
+
* @param value - Value to validate
|
|
56
|
+
* @param validator - Validation function
|
|
57
|
+
* @param logger - Optional logger for warnings
|
|
58
|
+
* @param context - Context for logging
|
|
59
|
+
* @returns Validated value or undefined
|
|
60
|
+
*/
|
|
61
|
+
export declare function validateOrUndefined<T>(value: unknown, validator: (value: unknown) => value is T, logger?: Logger, context?: string): T | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Create a retry wrapper for operations that might fail temporarily
|
|
64
|
+
*
|
|
65
|
+
* @param operation - Operation to retry
|
|
66
|
+
* @param maxRetries - Maximum number of retries
|
|
67
|
+
* @param delayMs - Delay between retries in milliseconds
|
|
68
|
+
* @param logger - Logger for retry attempts
|
|
69
|
+
* @returns Promise with operation result
|
|
70
|
+
*/
|
|
71
|
+
export declare function withRetry<T>(operation: () => Promise<T>, maxRetries?: number, delayMs?: number, logger?: Logger): Promise<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Common error types for better error handling
|
|
74
|
+
*/
|
|
75
|
+
export declare class ValidationError extends Error {
|
|
76
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
77
|
+
constructor(message: string, context?: Record<string, unknown> | undefined);
|
|
78
|
+
}
|
|
79
|
+
export declare class ConfigurationError extends Error {
|
|
80
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
81
|
+
constructor(message: string, context?: Record<string, unknown> | undefined);
|
|
82
|
+
}
|
|
83
|
+
export declare class NetworkError extends Error {
|
|
84
|
+
readonly context?: Record<string, unknown> | undefined;
|
|
85
|
+
constructor(message: string, context?: Record<string, unknown> | undefined);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Error classification utility
|
|
89
|
+
*/
|
|
90
|
+
export declare function classifyError(error: unknown): {
|
|
91
|
+
type: 'validation' | 'configuration' | 'network' | 'unknown';
|
|
92
|
+
message: string;
|
|
93
|
+
isRetryable: boolean;
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=error-handler.d.ts.map
|
|
@@ -0,0 +1 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
|
5
|
+
* and provide consistent metadata processing across the codebase.
|
|
6
|
+
*/
|
|
7
|
+
import { UsageMetadata } from '../types/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Build metadata object for payload inclusion
|
|
10
|
+
*
|
|
11
|
+
* This function eliminates the repetitive spreading pattern and provides
|
|
12
|
+
* a clean, testable way to handle metadata transformation.
|
|
13
|
+
* Subscriber object is passed through directly without transformation.
|
|
14
|
+
*
|
|
15
|
+
* @param usageMetadata - Source metadata from request
|
|
16
|
+
* @returns Clean metadata object for payload
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildMetadataFields(usageMetadata?: UsageMetadata): Record<string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Validate metadata completeness for specific use cases
|
|
21
|
+
*
|
|
22
|
+
* @param usageMetadata - Metadata to validate
|
|
23
|
+
* @param requiredFields - List of required field names
|
|
24
|
+
* @returns Validation result
|
|
25
|
+
*/
|
|
26
|
+
export declare function validateMetadata(usageMetadata?: UsageMetadata, requiredFields?: (keyof UsageMetadata)[]): {
|
|
27
|
+
isValid: boolean;
|
|
28
|
+
missingFields: string[];
|
|
29
|
+
warnings: string[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Merge multiple metadata sources with priority
|
|
33
|
+
*
|
|
34
|
+
* @param sources - Metadata sources in priority order (first wins)
|
|
35
|
+
* @returns Merged metadata object
|
|
36
|
+
*/
|
|
37
|
+
export declare function mergeMetadata(...sources: (UsageMetadata | undefined)[]): UsageMetadata;
|
|
38
|
+
/**
|
|
39
|
+
* Extract metadata from request parameters safely
|
|
40
|
+
*
|
|
41
|
+
* @param params - Request parameters that might contain usageMetadata
|
|
42
|
+
* @returns Extracted metadata and cleaned parameters
|
|
43
|
+
*/
|
|
44
|
+
export declare function extractMetadata<T extends Record<string, unknown>>(params: T & {
|
|
45
|
+
usageMetadata?: UsageMetadata;
|
|
46
|
+
}): {
|
|
47
|
+
metadata: UsageMetadata | undefined;
|
|
48
|
+
cleanParams: Omit<T, 'usageMetadata'>;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Create a metadata context for consistent logging
|
|
52
|
+
* Uses sanitization to protect PII (emails are masked)
|
|
53
|
+
*
|
|
54
|
+
* @param usageMetadata - Source metadata
|
|
55
|
+
* @returns Logging context object with sanitized PII
|
|
56
|
+
*/
|
|
57
|
+
export declare function createLoggingContext(usageMetadata?: UsageMetadata): Record<string, unknown>;
|
|
58
|
+
/**
|
|
59
|
+
* Sanitize metadata for logging (remove sensitive fields)
|
|
60
|
+
*
|
|
61
|
+
* @param usageMetadata - Source metadata
|
|
62
|
+
* @returns Sanitized metadata safe for logging
|
|
63
|
+
*/
|
|
64
|
+
export declare function sanitizeMetadataForLogging(usageMetadata?: UsageMetadata): Record<string, unknown>;
|
|
65
|
+
//# sourceMappingURL=metadata-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/metadata-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAc,MAAM,mBAAmB,CAAC;AAuC9D;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAoB1F;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,CAAC,EAAE,aAAa,EAC7B,cAAc,GAAE,CAAC,MAAM,aAAa,CAAC,EAAO,GAC3C;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB,CAqCA;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,OAAO,EAAE,CAAC,aAAa,GAAG,SAAS,CAAC,EAAE,GAAG,aAAa,CAQtF;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,MAAM,EAAE,CAAC,GAAG;IAAE,aAAa,CAAC,EAAE,aAAa,CAAA;CAAE,GAC5C;IACD,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,WAAW,EAAE,IAAI,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC;CACvC,CAMA;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAgB3F;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,aAAa,CAAC,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA8BjG"}
|