@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
|
@@ -1,159 +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;
|
|
36
|
+
/** Product or application identifier */
|
|
60
37
|
productId?: string;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
outputTokenCount?: number;
|
|
65
|
-
totalTokenCount?: number;
|
|
66
|
-
reasoningTokenCount?: number;
|
|
67
|
-
cacheCreationTokenCount?: number;
|
|
68
|
-
cacheReadTokenCount?: number;
|
|
69
|
-
requestTime?: string;
|
|
70
|
-
responseTime?: string;
|
|
71
|
-
completionStartTime?: string;
|
|
72
|
-
timeToFirstToken?: number;
|
|
73
|
-
operationType?: string;
|
|
38
|
+
/** Subscription identifier */
|
|
39
|
+
subscriptionId?: string;
|
|
40
|
+
/** Task type classification */
|
|
74
41
|
taskType?: string;
|
|
42
|
+
/** Distributed tracing identifier */
|
|
43
|
+
traceId?: string;
|
|
44
|
+
/** Quality score for response evaluation (0.0-1.0 scale) */
|
|
45
|
+
responseQualityScore?: number;
|
|
46
|
+
/** Agent or model variant identifier */
|
|
75
47
|
agent?: string;
|
|
76
|
-
stopReason?: string;
|
|
77
|
-
costType?: string;
|
|
78
|
-
subscriberId?: string;
|
|
79
|
-
subscriberEmail?: string;
|
|
80
|
-
subscriberCredentialName?: string;
|
|
81
|
-
subscriberCredential?: string;
|
|
82
48
|
}
|
|
83
49
|
/**
|
|
84
|
-
*
|
|
85
|
-
* Field order matches the expected API format
|
|
50
|
+
* Provider information for tracking API source
|
|
86
51
|
*/
|
|
87
|
-
export interface
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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";
|
|
110
94
|
model: string;
|
|
111
|
-
transactionId: string;
|
|
112
95
|
responseTime: string;
|
|
113
96
|
requestDuration: number;
|
|
114
97
|
provider: string;
|
|
98
|
+
modelSource: string;
|
|
115
99
|
requestTime: string;
|
|
116
100
|
completionStartTime: string;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
completionTokens: number;
|
|
128
|
-
totalTokens: number;
|
|
129
|
-
};
|
|
130
|
-
model: string;
|
|
131
|
-
transactionId: string;
|
|
132
|
-
rawResponse: PerplexityResponse;
|
|
133
|
-
}
|
|
134
|
-
export interface StreamingResult {
|
|
135
|
-
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;
|
|
136
111
|
transactionId: string;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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;
|
|
144
124
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
125
|
+
/**
|
|
126
|
+
* Metering data interface (legacy, for backward compatibility)
|
|
127
|
+
*/
|
|
128
|
+
export interface MeteringData extends ReveniumPayload {
|
|
148
129
|
}
|
|
149
|
-
export declare const PERPLEXITY_MODELS: {
|
|
150
|
-
readonly SONAR: "sonar";
|
|
151
|
-
readonly SONAR_PRO: "sonar-pro";
|
|
152
|
-
readonly SONAR_REASONING: "sonar-reasoning";
|
|
153
|
-
readonly LLAMA_3_1_SONAR_SMALL_128K_CHAT: "llama-3.1-sonar-small-128k-chat";
|
|
154
|
-
readonly LLAMA_3_1_SONAR_LARGE_128K_CHAT: "llama-3.1-sonar-large-128k-chat";
|
|
155
|
-
readonly LLAMA_3_1_SONAR_HUGE_128K_CHAT: "llama-3.1-sonar-huge-128k-chat";
|
|
156
|
-
};
|
|
157
|
-
export type PerplexityModel = (typeof PERPLEXITY_MODELS)[keyof typeof PERPLEXITY_MODELS];
|
|
158
|
-
export declare const DEFAULT_MODEL: PerplexityModel;
|
|
159
130
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.d.ts","sourceRoot":"","sources":["../../../src/utils/error-handler.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oCAAoC;IACpC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kCAAkC;IAClC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,CAAC;CAC5C;AAaD;;;;;;;;GAQG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,qBAA0B,EACpC,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAkBxB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,SAAS,EAAE,MAAM,CAAC,EAClB,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,qBAA0B,EACpC,MAAM,CAAC,EAAE,MAAM,GACd,CAAC,GAAG,SAAS,CAkBf;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAC/B,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,EACzC,YAAY,EAAE,MAAM,GACnB,CAAC,CAGH;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,CAAC,EACzC,MAAM,CAAC,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,GACf,CAAC,GAAG,SAAS,CAQf;AAED;;;;;;;;GAQG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,UAAU,GAAE,MAAU,EACtB,OAAO,GAAE,MAAa,EACtB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,CAAC,CAAC,CAwBZ;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aAGtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBADjD,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED,qBAAa,kBAAmB,SAAQ,KAAK;aAGzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBADjD,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED,qBAAa,YAAa,SAAQ,KAAK;aAGnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBADjD,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKpD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG;IAC7C,IAAI,EAAE,YAAY,GAAG,eAAe,GAAG,SAAS,GAAG,SAAS,CAAC;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB,CAwBA"}
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
* Map provider stop reasons to Revenium stop reasons
|
|
10
|
+
*
|
|
11
|
+
* 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
|
+
*
|
|
14
|
+
* @param providerStopReason - Stop reason from the AI provider
|
|
15
|
+
* @param logger - Optional logger for warnings about unknown reasons
|
|
16
|
+
* @returns Standardized Revenium stop reason
|
|
17
|
+
*/
|
|
18
|
+
export declare function mapStopReason(providerStopReason: string | null | undefined, logger?: {
|
|
19
|
+
warn: (message: string, ...args: any[]) => void;
|
|
20
|
+
}): string;
|
|
21
|
+
/**
|
|
22
|
+
* Get all supported stop reasons for documentation/testing
|
|
23
|
+
*/
|
|
24
|
+
export declare function getSupportedStopReasons(): string[];
|
|
25
|
+
/**
|
|
26
|
+
* Check if a stop reason is supported
|
|
27
|
+
*/
|
|
28
|
+
export declare function isStopReasonSupported(reason: string): boolean;
|
|
29
|
+
//# sourceMappingURL=stop-reason-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stop-reason-mapper.d.ts","sourceRoot":"","sources":["../../../src/utils/stop-reason-mapper.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgCH;;;;;;;;;GASG;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,CAYR;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,EAAE,CAElD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE7D"}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 declare function generateTransactionId(): string;
|
|
14
|
+
//# sourceMappingURL=transaction-id.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction-id.d.ts","sourceRoot":"","sources":["../../../src/utils/transaction-id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 declare function buildReveniumUrl(baseUrl: string, endpoint: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Validate URL format
|
|
17
|
+
*
|
|
18
|
+
* @param url - URL to validate
|
|
19
|
+
* @returns true if valid, false otherwise
|
|
20
|
+
*/
|
|
21
|
+
export declare function isValidUrl(url: string): boolean;
|
|
22
|
+
//# sourceMappingURL=url-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-builder.d.ts","sourceRoot":"","sources":["../../../src/utils/url-builder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CA2B1E;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAO/C"}
|