lupislabs 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +221 -359
  2. package/dist/cost-utils.d.ts +5 -0
  3. package/dist/cost-utils.d.ts.map +1 -0
  4. package/dist/cost-utils.js +51 -0
  5. package/dist/cost-utils.js.map +1 -0
  6. package/dist/endpoints.d.ts +2 -0
  7. package/dist/endpoints.d.ts.map +1 -0
  8. package/dist/endpoints.js +2 -0
  9. package/dist/endpoints.js.map +1 -0
  10. package/dist/http-interceptor.d.ts +18 -8
  11. package/dist/http-interceptor.d.ts.map +1 -1
  12. package/dist/http-interceptor.js +164 -416
  13. package/dist/http-interceptor.js.map +1 -1
  14. package/dist/index.d.ts +33 -6
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +96 -8
  17. package/dist/index.js.map +1 -1
  18. package/dist/interceptors/axios-interceptor.d.ts +18 -0
  19. package/dist/interceptors/axios-interceptor.d.ts.map +1 -0
  20. package/dist/interceptors/axios-interceptor.js +115 -0
  21. package/dist/interceptors/axios-interceptor.js.map +1 -0
  22. package/dist/interceptors/fetch-interceptor.d.ts +18 -0
  23. package/dist/interceptors/fetch-interceptor.d.ts.map +1 -0
  24. package/dist/interceptors/fetch-interceptor.js +228 -0
  25. package/dist/interceptors/fetch-interceptor.js.map +1 -0
  26. package/dist/interceptors/got-interceptor.d.ts +18 -0
  27. package/dist/interceptors/got-interceptor.d.ts.map +1 -0
  28. package/dist/interceptors/got-interceptor.js +103 -0
  29. package/dist/interceptors/got-interceptor.js.map +1 -0
  30. package/dist/interceptors/node-http-interceptor.d.ts +21 -0
  31. package/dist/interceptors/node-http-interceptor.d.ts.map +1 -0
  32. package/dist/interceptors/node-http-interceptor.js +301 -0
  33. package/dist/interceptors/node-http-interceptor.js.map +1 -0
  34. package/dist/providers/anthropic-handler.d.ts +3 -0
  35. package/dist/providers/anthropic-handler.d.ts.map +1 -0
  36. package/dist/providers/anthropic-handler.js +50 -0
  37. package/dist/providers/anthropic-handler.js.map +1 -0
  38. package/dist/providers/openai-handler.d.ts +3 -0
  39. package/dist/providers/openai-handler.d.ts.map +1 -0
  40. package/dist/providers/openai-handler.js +46 -0
  41. package/dist/providers/openai-handler.js.map +1 -0
  42. package/dist/providers/provider-detector.d.ts +4 -0
  43. package/dist/providers/provider-detector.d.ts.map +1 -0
  44. package/dist/providers/provider-detector.js +27 -0
  45. package/dist/providers/provider-detector.js.map +1 -0
  46. package/dist/sensitive-data-filter.d.ts +20 -0
  47. package/dist/sensitive-data-filter.d.ts.map +1 -0
  48. package/dist/sensitive-data-filter.js +280 -0
  49. package/dist/sensitive-data-filter.js.map +1 -0
  50. package/dist/trace-collector.d.ts +40 -0
  51. package/dist/trace-collector.d.ts.map +1 -0
  52. package/dist/trace-collector.js +59 -0
  53. package/dist/trace-collector.js.map +1 -0
  54. package/dist/tracer.d.ts +30 -7
  55. package/dist/tracer.d.ts.map +1 -1
  56. package/dist/tracer.js +76 -70
  57. package/dist/tracer.js.map +1 -1
  58. package/dist/types.d.ts +82 -6
  59. package/dist/types.d.ts.map +1 -1
  60. package/package.json +3 -17
@@ -0,0 +1,301 @@
1
+ import { calculateCost } from '../cost-utils.js';
2
+ import http from 'http';
3
+ import https from 'https';
4
+ import zlib from 'zlib';
5
+ export function patchNodeHttp(context) {
6
+ try {
7
+ context.zlib = zlib;
8
+ context.originalHttpRequest = http.request;
9
+ context.originalHttpsRequest = https.request;
10
+ console.log('[Lupis SDK] Patching Node.js xxx');
11
+ const self = context;
12
+ const debugEnv = (() => { try {
13
+ return typeof process !== 'undefined' ? (process.env?.LUPIS_DEBUG_HTTP || process.env?.LUPIS_DEBUG) : undefined;
14
+ }
15
+ catch {
16
+ return undefined;
17
+ } })();
18
+ const debugOn = !!debugEnv && (debugEnv === 'true' || /http|all/i.test(String(debugEnv)));
19
+ const debug = (...args) => { if (debugOn) {
20
+ try {
21
+ console.log('[Lupis SDK][NodeHTTP]', ...args);
22
+ }
23
+ catch { }
24
+ } };
25
+ const createPatchedRequest = (original, protocol) => {
26
+ return function (options, callback) {
27
+ const url = typeof options === 'string' ? options :
28
+ `${protocol}://${options.hostname || options.host || 'localhost'}${options.port ? ':' + options.port : ''}${options.path || '/'}`;
29
+ debug('request', protocol.toUpperCase(), options.method || 'GET', url);
30
+ if (url.includes('/v1/traces') || url.includes('/api/traces')) {
31
+ debug('skip', url);
32
+ return original.call(this, options, callback);
33
+ }
34
+ const method = options.method || 'GET';
35
+ const provider = self.detectProvider(url);
36
+ const handler = self.resolveHandler(provider);
37
+ const startTime = Date.now();
38
+ let requestHeaders;
39
+ if (options.headers) {
40
+ requestHeaders = self.sensitiveDataFilter.filterHeaders(options.headers);
41
+ }
42
+ const requestOptions = {
43
+ ...options
44
+ };
45
+ debug('options', { method, provider, requestHeaders });
46
+ const requestBodyChunks = [];
47
+ let sanitizedRequestBody;
48
+ const captureRequestChunk = (chunk, encoding) => {
49
+ try {
50
+ if (!chunk) {
51
+ return;
52
+ }
53
+ if (Buffer.isBuffer(chunk)) {
54
+ requestBodyChunks.push(chunk);
55
+ return;
56
+ }
57
+ if (typeof chunk === 'string') {
58
+ const buffer = Buffer.from(chunk, encoding ?? 'utf8');
59
+ requestBodyChunks.push(buffer);
60
+ return;
61
+ }
62
+ if (chunk instanceof Uint8Array) {
63
+ requestBodyChunks.push(Buffer.from(chunk));
64
+ }
65
+ }
66
+ catch (captureError) {
67
+ debug('request:captureError', captureError);
68
+ }
69
+ };
70
+ const finalizeRequestBody = () => {
71
+ if (sanitizedRequestBody !== undefined) {
72
+ return sanitizedRequestBody;
73
+ }
74
+ if (requestBodyChunks.length === 0) {
75
+ return undefined;
76
+ }
77
+ try {
78
+ const combined = Buffer.concat(requestBodyChunks);
79
+ sanitizedRequestBody = self.sanitizeRequestBody(combined);
80
+ }
81
+ catch (error) {
82
+ debug('request:sanitizeError', error);
83
+ }
84
+ return sanitizedRequestBody;
85
+ };
86
+ const req = original.call(this, requestOptions, (res) => {
87
+ const responseHeaders = {};
88
+ Object.keys(res.headers || {}).forEach(key => {
89
+ responseHeaders[key] = res.headers[key];
90
+ });
91
+ const filteredResponseHeaders = self.sensitiveDataFilter.filterHeaders(responseHeaders);
92
+ const responseChunks = [];
93
+ let sanitizedResponseBody;
94
+ const originalOn = res.on.bind(res);
95
+ const originalOnce = res.once.bind(res);
96
+ const originalAddListener = res.addListener?.bind(res);
97
+ const contentType = res.headers['content-type'] || '';
98
+ const isStreaming = contentType.includes('text/event-stream');
99
+ let streamState = undefined;
100
+ let tokenUsage;
101
+ let costBreakdown;
102
+ let model;
103
+ const durationStart = Date.now();
104
+ let responseEndProcessed = false;
105
+ debug('response:start', { statusCode: res.statusCode, contentType, contentEncoding: res.headers['content-encoding'] });
106
+ const processResponseEnd = () => {
107
+ if (responseEndProcessed) {
108
+ return;
109
+ }
110
+ responseEndProcessed = true;
111
+ const duration = Date.now() - durationStart;
112
+ if (responseChunks.length > 0) {
113
+ try {
114
+ const buffer = Buffer.concat(responseChunks);
115
+ const contentEncoding = res.headers['content-encoding'];
116
+ const decompressed = self.decompressIfNeeded(buffer, contentEncoding);
117
+ const limitedText = decompressed.length > 1000000
118
+ ? decompressed.substring(0, 1000000) + '...[truncated]'
119
+ : decompressed;
120
+ let normalizedBody;
121
+ if (handler) {
122
+ if (isStreaming && streamState && Array.isArray(streamState.__rawChunks)) {
123
+ const usage = streamState.__usage;
124
+ if (usage) {
125
+ tokenUsage = usage;
126
+ costBreakdown = calculateCost(usage, provider, streamState.model);
127
+ model = streamState.model;
128
+ }
129
+ }
130
+ else {
131
+ normalizedBody = handler.normalizeFinal(limitedText);
132
+ if (normalizedBody && typeof normalizedBody === 'object' && normalizedBody.usage) {
133
+ tokenUsage = normalizedBody.usage;
134
+ costBreakdown = calculateCost(normalizedBody.usage, provider, normalizedBody.model);
135
+ model = normalizedBody.model;
136
+ }
137
+ }
138
+ }
139
+ try {
140
+ const aggregatedText = isStreaming && streamState && typeof streamState.__aggregatedText === 'string'
141
+ ? streamState.__aggregatedText
142
+ : undefined;
143
+ const normalizedAggregated = normalizedBody && typeof normalizedBody === 'object'
144
+ ? normalizedBody.aggregatedText
145
+ : undefined;
146
+ const resolvedText = (aggregatedText && aggregatedText.length > 0)
147
+ ? aggregatedText
148
+ : (normalizedAggregated && typeof normalizedAggregated === 'string' && normalizedAggregated.length > 0)
149
+ ? normalizedAggregated
150
+ : limitedText;
151
+ let streamingPayload;
152
+ if (resolvedText !== undefined) {
153
+ const totalChunks = streamState && Array.isArray(streamState.__rawChunks)
154
+ ? streamState.__rawChunks.length
155
+ : undefined;
156
+ const totalLength = typeof resolvedText === 'string' ? resolvedText.length : undefined;
157
+ streamingPayload = {
158
+ type: 'streaming_response',
159
+ provider,
160
+ model: model ?? (streamState ? streamState.model : undefined) ?? (normalizedBody && typeof normalizedBody === 'object' ? normalizedBody.model : undefined),
161
+ aggregatedText: resolvedText,
162
+ totalChunks,
163
+ totalLength,
164
+ usage: tokenUsage ?? (streamState ? streamState.__usage : undefined) ?? (normalizedBody && typeof normalizedBody === 'object' ? normalizedBody.usage : undefined),
165
+ };
166
+ }
167
+ const responseBodyValue = streamingPayload ?? (resolvedText !== undefined ? resolvedText : limitedText);
168
+ sanitizedResponseBody = responseBodyValue !== undefined
169
+ ? self.sanitizeResponseBody(responseBodyValue)
170
+ : undefined;
171
+ }
172
+ catch (sanitizeError) {
173
+ debug('response:sanitizeError', sanitizeError);
174
+ }
175
+ }
176
+ catch (e) {
177
+ }
178
+ }
179
+ const retryHint = res.statusCode >= 500 || res.statusCode === 429;
180
+ debug('response:end', { statusCode: res.statusCode, duration, hasUsage: !!tokenUsage, model, retryHint });
181
+ const trace = self.createTrace(url, method, res.statusCode, duration, provider, requestHeaders, filteredResponseHeaders, tokenUsage, costBreakdown, model, finalizeRequestBody(), sanitizedResponseBody);
182
+ self.traceCollector.addTrace(trace);
183
+ };
184
+ const wrapDataHandler = (eventHandler) => {
185
+ return (chunk) => {
186
+ if (!responseEndProcessed) {
187
+ responseChunks.push(Buffer.from(chunk));
188
+ if (isStreaming && handler) {
189
+ const chunkText = chunk.toString('utf8');
190
+ if (handler.isStreamingChunk(chunkText)) {
191
+ const { state } = handler.accumulateChunk(streamState, chunkText);
192
+ streamState = state;
193
+ }
194
+ }
195
+ }
196
+ debug('response:data', { size: typeof chunk === 'string' ? Buffer.byteLength(chunk) : (chunk?.length || 0) });
197
+ if (eventHandler) {
198
+ try {
199
+ const result = eventHandler(chunk);
200
+ return result;
201
+ }
202
+ catch (e) {
203
+ throw e;
204
+ }
205
+ }
206
+ };
207
+ };
208
+ const wrapEndHandler = (eventHandler) => {
209
+ return () => {
210
+ processResponseEnd();
211
+ if (eventHandler) {
212
+ try {
213
+ const result = eventHandler();
214
+ return result;
215
+ }
216
+ catch (e) {
217
+ throw e;
218
+ }
219
+ }
220
+ };
221
+ };
222
+ res.on = function (event, eventHandler) {
223
+ if (event === 'data') {
224
+ return originalOn(event, wrapDataHandler(eventHandler));
225
+ }
226
+ if (event === 'end') {
227
+ return originalOn(event, wrapEndHandler(eventHandler));
228
+ }
229
+ return originalOn(event, eventHandler);
230
+ };
231
+ res.once = function (event, eventHandler) {
232
+ if (event === 'data') {
233
+ return originalOnce(event, wrapDataHandler(eventHandler));
234
+ }
235
+ if (event === 'end') {
236
+ return originalOnce(event, wrapEndHandler(eventHandler));
237
+ }
238
+ return originalOnce(event, eventHandler);
239
+ };
240
+ if (originalAddListener) {
241
+ res.addListener = function (event, eventHandler) {
242
+ if (event === 'data') {
243
+ return originalAddListener(event, wrapDataHandler(eventHandler));
244
+ }
245
+ if (event === 'end') {
246
+ return originalAddListener(event, wrapEndHandler(eventHandler));
247
+ }
248
+ return originalAddListener(event, eventHandler);
249
+ };
250
+ }
251
+ originalOnce('end', () => {
252
+ processResponseEnd();
253
+ });
254
+ originalOnce('error', () => {
255
+ debug('response:error:event');
256
+ const duration = Date.now() - durationStart;
257
+ const trace = self.createTrace(url, method, 0, duration, provider, requestHeaders, filteredResponseHeaders, undefined, undefined, undefined, finalizeRequestBody(), sanitizedResponseBody, 'Request error');
258
+ self.traceCollector.addTrace(trace);
259
+ });
260
+ if (callback) {
261
+ callback(res);
262
+ }
263
+ });
264
+ const originalWrite = req.write;
265
+ req.write = function (...args) {
266
+ const chunk = args[0];
267
+ const encoding = typeof args[1] === 'string' ? args[1] : undefined;
268
+ captureRequestChunk(chunk, encoding);
269
+ return originalWrite.apply(this, args);
270
+ };
271
+ const originalEnd = req.end;
272
+ req.end = function (...args) {
273
+ const chunk = args[0];
274
+ const encoding = typeof args[1] === 'string' ? args[1] : undefined;
275
+ if (chunk) {
276
+ captureRequestChunk(chunk, encoding);
277
+ }
278
+ const result = originalEnd.apply(this, args);
279
+ finalizeRequestBody();
280
+ return result;
281
+ };
282
+ req.on('error', (error) => {
283
+ debug('request:error', error?.message || String(error));
284
+ const duration = Date.now() - startTime;
285
+ const trace = self.createTrace(url, method, 0, duration, provider, requestHeaders, undefined, undefined, undefined, undefined, finalizeRequestBody(), undefined, error.message);
286
+ self.traceCollector.addTrace(trace);
287
+ });
288
+ return req;
289
+ };
290
+ };
291
+ http.request = createPatchedRequest(context.originalHttpRequest, 'http');
292
+ https.request = createPatchedRequest(context.originalHttpsRequest, 'https');
293
+ }
294
+ catch (e) {
295
+ try {
296
+ console.warn('[Lupis SDK] Failed to patch Node.js http/https:', e);
297
+ }
298
+ catch { }
299
+ }
300
+ }
301
+ //# sourceMappingURL=node-http-interceptor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-http-interceptor.js","sourceRoot":"","sources":["../../src/interceptors/node-http-interceptor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AAkCxB,MAAM,UAAU,aAAa,CAAC,OAAmC;I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,cAAc,EACd,SAAS,EACT,SAAS,EACT,SAAS,EACT,SAAS,EACT,mBAAmB,EAAE,EACrB,SAAS,EACT,KAAK,CAAC,OAAO,CACd,CAAC;oBACF,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACtC,CAAC,CAAC,CAAC;gBAEH,OAAO,GAAG,CAAC;YACb,CAAC,CAAC;QACJ,CAAC,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;QACzE,KAAK,CAAC,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;IAE9E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC;YAAC,OAAO,CAAC,IAAI,CAAC,iDAAiD,EAAE,CAAC,CAAC,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACtF,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ProviderHandler } from '../http-types.js';
2
+ export declare const AnthropicHandler: ProviderHandler;
3
+ //# sourceMappingURL=anthropic-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-handler.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,eAAO,MAAM,gBAAgB,EAAE,eA0C9B,CAAC"}
@@ -0,0 +1,50 @@
1
+ export const AnthropicHandler = {
2
+ provider: 'claude',
3
+ detect: (url) => url.includes('api.anthropic.com'),
4
+ isStreamingChunk: (textChunk) => textChunk.includes('\nevent: ') || textChunk.includes('\ndata: '),
5
+ accumulateChunk: (state, textChunk) => {
6
+ const next = state || { __rawChunks: [], __aggregatedText: '', __toolCalls: [], __usage: null };
7
+ next.__rawChunks.push(textChunk);
8
+ const lines = textChunk.split('\n');
9
+ for (const line of lines) {
10
+ if (!line.startsWith('data: '))
11
+ continue;
12
+ try {
13
+ const json = JSON.parse(line.substring(6));
14
+ if (json?.message?.model)
15
+ next.model = json.message.model;
16
+ else if (json?.model)
17
+ next.model = json.model;
18
+ if (json?.delta?.text)
19
+ next.__aggregatedText += json.delta.text;
20
+ if (json?.type === 'tool_use') {
21
+ next.__toolCalls.push({
22
+ id: json.id,
23
+ name: json.name,
24
+ type: 'function',
25
+ function: { name: json.name, arguments: JSON.stringify(json.input || {}) },
26
+ });
27
+ }
28
+ if (json?.usage) {
29
+ next.__usage = json.usage;
30
+ }
31
+ if (json?.type === 'message_delta' && json?.usage) {
32
+ next.__usage = json.usage;
33
+ }
34
+ }
35
+ catch { }
36
+ }
37
+ return { state: next };
38
+ },
39
+ normalizeFinal: (rawBodyText) => {
40
+ try {
41
+ const parsed = JSON.parse(rawBodyText);
42
+ const aggregatedText = parsed.content?.[0]?.text || '';
43
+ return { ...parsed, aggregatedText };
44
+ }
45
+ catch {
46
+ return rawBodyText;
47
+ }
48
+ },
49
+ };
50
+ //# sourceMappingURL=anthropic-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-handler.js","sourceRoot":"","sources":["../../src/providers/anthropic-handler.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,gBAAgB,GAAoB;IAC/C,QAAQ,EAAE,QAAQ;IAClB,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IAClD,gBAAgB,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;IAClG,eAAe,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACpC,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,WAAW,EAAE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eAAe,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC;oBAClD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;gBAC5B,CAAC;YACH,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;QACZ,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;IACD,cAAc,EAAE,CAAC,WAAW,EAAE,EAAE;QAC9B,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;YACvC,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,IAAI,EAAE,CAAC;YACvD,OAAO,EAAE,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC;QACvC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,WAAW,CAAC;QACrB,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ProviderHandler } from '../http-types.js';
2
+ export declare const OpenAIHandler: ProviderHandler;
3
+ //# sourceMappingURL=openai-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-handler.d.ts","sourceRoot":"","sources":["../../src/providers/openai-handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,eAAO,MAAM,aAAa,EAAE,eAqC3B,CAAC"}
@@ -0,0 +1,46 @@
1
+ export const OpenAIHandler = {
2
+ provider: 'openai',
3
+ detect: (url) => url.includes('api.openai.com'),
4
+ isStreamingChunk: (textChunk) => textChunk.includes('\ndata: '),
5
+ accumulateChunk: (state, textChunk) => {
6
+ const next = state || { __rawChunks: [], __aggregatedText: '', __toolCalls: [], __usage: null };
7
+ next.__rawChunks.push(textChunk);
8
+ const lines = textChunk.split('\n');
9
+ for (const line of lines) {
10
+ if (!line.startsWith('data: '))
11
+ continue;
12
+ const payload = line.substring(6).trim();
13
+ if (payload === '[DONE]')
14
+ continue;
15
+ try {
16
+ const json = JSON.parse(payload);
17
+ if (json?.model)
18
+ next.model = json.model;
19
+ if (Array.isArray(json.choices)) {
20
+ for (const choice of json.choices) {
21
+ if (choice.delta?.content)
22
+ next.__aggregatedText += choice.delta.content;
23
+ if (Array.isArray(choice.delta?.tool_calls))
24
+ next.__toolCalls.push(...choice.delta.tool_calls);
25
+ }
26
+ }
27
+ if (json?.usage) {
28
+ next.__usage = json.usage;
29
+ }
30
+ }
31
+ catch { }
32
+ }
33
+ return { state: next };
34
+ },
35
+ normalizeFinal: (rawBodyText) => {
36
+ try {
37
+ const parsed = JSON.parse(rawBodyText);
38
+ const aggregatedText = parsed.choices?.[0]?.message?.content || '';
39
+ return { ...parsed, aggregatedText };
40
+ }
41
+ catch {
42
+ return rawBodyText;
43
+ }
44
+ },
45
+ };
46
+ //# sourceMappingURL=openai-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openai-handler.js","sourceRoot":"","sources":["../../src/providers/openai-handler.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,aAAa,GAAoB;IAC5C,QAAQ,EAAE,QAAQ;IAClB,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IAC/C,gBAAgB,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;IAC/D,eAAe,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACpC,MAAM,IAAI,GAAG,KAAK,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAChG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpC,K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OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE,CAAC;YACnE,OAAO,EAAE,GAAG,MAAM,EAAE,cAAc,EAAE,CAAC;QACvC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,WAAW,CAAC;QACrB,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { ProviderHandler } from '../http-types.js';
2
+ export declare function detectProvider(url: string): string;
3
+ export declare function resolveHandler(provider: string): ProviderHandler | undefined;
4
+ //# sourceMappingURL=provider-detector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-detector.d.ts","sourceRoot":"","sources":["../../src/providers/provider-detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAgB,MAAM,kBAAkB,CAAC;AAIjE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAU5E"}
@@ -0,0 +1,27 @@
1
+ import { OpenAIHandler } from './openai-handler.js';
2
+ import { AnthropicHandler } from './anthropic-handler.js';
3
+ export function detectProvider(url) {
4
+ if (url.includes('api.openai.com'))
5
+ return 'openai';
6
+ if (url.includes('api.anthropic.com'))
7
+ return 'claude';
8
+ if (url.includes('api.cohere.ai'))
9
+ return 'cohere';
10
+ if (url.includes('api.huggingface.co'))
11
+ return 'huggingface';
12
+ if (url.includes('api.google.com'))
13
+ return 'google';
14
+ return 'unknown';
15
+ }
16
+ export function resolveHandler(provider) {
17
+ const p = provider;
18
+ switch (p) {
19
+ case 'openai':
20
+ return OpenAIHandler;
21
+ case 'claude':
22
+ return AnthropicHandler;
23
+ default:
24
+ return undefined;
25
+ }
26
+ }
27
+ //# sourceMappingURL=provider-detector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-detector.js","sourceRoot":"","sources":["../../src/providers/provider-detector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,IAAI,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAAE,OAAO,QAAQ,CAAC;IACpD,IAAI,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAAE,OAAO,QAAQ,CAAC;IACvD,IAAI,GAAG,CAAC,QAAQ,CAAC,eAAe,CAAC;QAAE,OAAO,QAAQ,CAAC;IACnD,IAAI,GAAG,CAAC,QAAQ,CAAC,oBAAoB,CAAC;QAAE,OAAO,aAAa,CAAC;IAC7D,IAAI,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QAAE,OAAO,QAAQ,CAAC;IACpD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,QAAgB;IAC7C,MAAM,CAAC,GAAG,QAAwB,CAAC;IACnC,QAAQ,CAAC,EAAE,CAAC;QACV,KAAK,QAAQ;YACX,OAAO,aAAa,CAAC;QACvB,KAAK,QAAQ;YACX,OAAO,gBAAgB,CAAC;QAC1B;YACE,OAAO,SAAS,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { SensitiveDataFilter } from './types.js';
2
+ export declare class SensitiveDataFilterUtil {
3
+ private filter;
4
+ private defaultPatterns;
5
+ constructor(filter: SensitiveDataFilter);
6
+ private readonly MAX_BODY_LENGTH;
7
+ filterObject(obj: any): any;
8
+ sanitizeRequestBody(body: unknown): string | undefined;
9
+ sanitizeResponseBody(body: unknown): string | undefined;
10
+ private filterString;
11
+ private isSensitiveKey;
12
+ private getRedactedValue;
13
+ private truncateBody;
14
+ private normalizeToString;
15
+ private normalizeBodyToString;
16
+ filterHeaders(headers: Record<string, unknown>): Record<string, string>;
17
+ filterRequestBody(body: string): string;
18
+ filterResponseBody(body: string): string;
19
+ }
20
+ //# sourceMappingURL=sensitive-data-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sensitive-data-filter.d.ts","sourceRoot":"","sources":["../src/sensitive-data-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,qBAAa,uBAAuB;IAClC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,eAAe,CAsCrB;gBAEU,MAAM,EAAE,mBAAmB;IAUvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;IAE1C,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG;IA4B3B,mBAAmB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS;IAUtD,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS;IAUvD,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,gBAAgB;IA4BxB,OAAO,CAAC,YAAY;IAQpB,OAAO,CAAC,iBAAiB;IAoCzB,OAAO,CAAC,qBAAqB;IAwE7B,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAsBvE,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAevC,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAGzC"}