deadpipe 2.0.1 → 3.0.0

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/dist/index.js CHANGED
@@ -22,23 +22,34 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  PromptTracker: () => PromptTracker,
24
24
  VERSION: () => VERSION,
25
+ default: () => index_default,
26
+ detectClientProvider: () => detectClientProvider,
27
+ detectProvider: () => detectProvider,
25
28
  detectRefusal: () => detectRefusal,
26
29
  estimateCost: () => estimateCost,
27
30
  extractAnthropicResponse: () => extractAnthropicResponse,
31
+ extractCohereResponse: () => extractCohereResponse,
32
+ extractGoogleAIResponse: () => extractGoogleAIResponse,
33
+ extractMistralResponse: () => extractMistralResponse,
28
34
  extractOpenAIResponse: () => extractOpenAIResponse,
35
+ extractResponse: () => extractResponse,
29
36
  track: () => track,
30
37
  validateEnumBounds: () => validateEnumBounds,
31
38
  validateNumericBounds: () => validateNumericBounds,
39
+ wrap: () => wrap,
40
+ wrapAnthropic: () => wrapAnthropic,
41
+ wrapClient: () => wrap,
42
+ wrapCohere: () => wrapCohere,
43
+ wrapGoogleAI: () => wrapGoogleAI,
44
+ wrapMistral: () => wrapMistral,
32
45
  wrapOpenAI: () => wrapOpenAI
33
46
  });
34
47
  module.exports = __toCommonJS(index_exports);
35
- var VERSION = "2.0.0";
48
+ var VERSION = "3.0.0";
36
49
  var MODEL_COSTS = {
37
50
  // OpenAI
38
51
  "gpt-4": { input: 0.03, output: 0.06 },
39
- // legacy
40
52
  "gpt-4-turbo": { input: 0.01, output: 0.03 },
41
- // legacy
42
53
  "gpt-4o": { input: 5e-3, output: 0.015 },
43
54
  "gpt-4o-mini": { input: 15e-5, output: 6e-4 },
44
55
  "gpt-4.1": { input: 2e-3, output: 8e-3 },
@@ -46,14 +57,37 @@ var MODEL_COSTS = {
46
57
  "gpt-5": { input: 175e-5, output: 0.014 },
47
58
  "gpt-5-mini": { input: 25e-5, output: 2e-3 },
48
59
  "gpt-5.2-pro": { input: 0.021, output: 0.168 },
60
+ "o1": { input: 0.015, output: 0.06 },
61
+ "o1-mini": { input: 3e-3, output: 0.012 },
62
+ "o1-pro": { input: 0.15, output: 0.6 },
49
63
  // Anthropic
50
64
  "claude-3-opus": { input: 0.015, output: 0.075 },
51
65
  "claude-3-sonnet": { input: 3e-3, output: 0.015 },
52
66
  "claude-3-haiku": { input: 25e-5, output: 125e-5 },
53
67
  "claude-3.5-sonnet": { input: 3e-3, output: 0.015 },
68
+ "claude-3.5-haiku": { input: 8e-4, output: 4e-3 },
54
69
  "claude-opus-4": { input: 0.015, output: 0.075 },
55
70
  "claude-sonnet-4": { input: 3e-3, output: 0.015 },
56
- "claude-haiku-4": { input: 25e-5, output: 125e-5 }
71
+ "claude-haiku-4": { input: 25e-5, output: 125e-5 },
72
+ // Google AI / Gemini
73
+ "gemini-1.5-pro": { input: 125e-5, output: 5e-3 },
74
+ "gemini-1.5-flash": { input: 75e-6, output: 3e-4 },
75
+ "gemini-2.0-flash": { input: 1e-4, output: 4e-4 },
76
+ "gemini-2.0-pro": { input: 125e-5, output: 5e-3 },
77
+ "gemini-pro": { input: 5e-4, output: 15e-4 },
78
+ // Mistral
79
+ "mistral-large": { input: 4e-3, output: 0.012 },
80
+ "mistral-medium": { input: 27e-4, output: 81e-4 },
81
+ "mistral-small": { input: 1e-3, output: 3e-3 },
82
+ "mistral-nemo": { input: 3e-4, output: 3e-4 },
83
+ "codestral": { input: 1e-3, output: 3e-3 },
84
+ "pixtral": { input: 2e-3, output: 6e-3 },
85
+ "ministral": { input: 1e-4, output: 1e-4 },
86
+ // Cohere
87
+ "command-r-plus": { input: 3e-3, output: 0.015 },
88
+ "command-r": { input: 5e-4, output: 15e-4 },
89
+ "command": { input: 1e-3, output: 2e-3 },
90
+ "command-light": { input: 3e-4, output: 6e-4 }
57
91
  };
58
92
  function estimateCost(model, inputTokens, outputTokens) {
59
93
  const modelLower = model.toLowerCase();
@@ -132,6 +166,59 @@ function validateNumericBounds(data, numericBounds) {
132
166
  }
133
167
  return true;
134
168
  }
169
+ function detectProvider(response) {
170
+ if (!response) return "unknown";
171
+ if (Array.isArray(response.content) && response.stop_reason !== void 0) {
172
+ return "anthropic";
173
+ }
174
+ if (response.candidates !== void 0 || response.promptFeedback !== void 0) {
175
+ return "google";
176
+ }
177
+ if (response.text !== void 0 && response.generation_id !== void 0 || response.generations !== void 0) {
178
+ return "cohere";
179
+ }
180
+ if (response.choices !== void 0 || response.output !== void 0) {
181
+ const model = String(response.model || "").toLowerCase();
182
+ if (model.includes("mistral") || model.includes("codestral") || model.includes("pixtral") || model.includes("ministral")) {
183
+ return "mistral";
184
+ }
185
+ return "openai";
186
+ }
187
+ if (response.model) {
188
+ const modelLower = String(response.model).toLowerCase();
189
+ if (modelLower.includes("claude")) return "anthropic";
190
+ if (modelLower.includes("gemini")) return "google";
191
+ if (modelLower.includes("mistral") || modelLower.includes("codestral")) return "mistral";
192
+ if (modelLower.includes("command")) return "cohere";
193
+ if (modelLower.includes("gpt") || modelLower.includes("o1")) return "openai";
194
+ }
195
+ return "unknown";
196
+ }
197
+ function detectClientProvider(client) {
198
+ if (!client) return "unknown";
199
+ if (client.chat?.completions || client.responses) {
200
+ if (client._client?.baseURL?.includes("mistral") || client.baseURL?.includes("mistral")) {
201
+ return "mistral";
202
+ }
203
+ return "openai";
204
+ }
205
+ if (client.messages?.create) {
206
+ return "anthropic";
207
+ }
208
+ if (client.getGenerativeModel) {
209
+ return "google";
210
+ }
211
+ if (client.chat?.complete || client.chat) {
212
+ return "mistral";
213
+ }
214
+ if (client.chat && typeof client.chat === "function") {
215
+ return "cohere";
216
+ }
217
+ if (client.generate) {
218
+ return "cohere";
219
+ }
220
+ return "unknown";
221
+ }
135
222
  function extractOpenAIResponse(response) {
136
223
  const result = {
137
224
  model: "",
@@ -211,6 +298,110 @@ function extractAnthropicResponse(response) {
211
298
  }
212
299
  return result;
213
300
  }
301
+ function extractGoogleAIResponse(response) {
302
+ const result = {
303
+ model: "",
304
+ content: "",
305
+ inputTokens: null,
306
+ outputTokens: null,
307
+ totalTokens: null,
308
+ finishReason: null,
309
+ toolCalls: [],
310
+ logprobs: null
311
+ };
312
+ if (response?.modelVersion) {
313
+ result.model = response.modelVersion;
314
+ }
315
+ if (response?.candidates?.[0]) {
316
+ const candidate = response.candidates[0];
317
+ if (candidate.content?.parts) {
318
+ const textParts = candidate.content.parts.filter((part) => part.text !== void 0).map((part) => part.text);
319
+ result.content = textParts.join("");
320
+ const functionCalls = candidate.content.parts.filter((part) => part.functionCall).map((part) => ({
321
+ name: part.functionCall.name,
322
+ arguments: JSON.stringify(part.functionCall.args)
323
+ }));
324
+ result.toolCalls = functionCalls;
325
+ }
326
+ if (candidate.finishReason) {
327
+ result.finishReason = candidate.finishReason;
328
+ }
329
+ }
330
+ if (response?.usageMetadata) {
331
+ result.inputTokens = response.usageMetadata.promptTokenCount ?? null;
332
+ result.outputTokens = response.usageMetadata.candidatesTokenCount ?? null;
333
+ result.totalTokens = response.usageMetadata.totalTokenCount ?? null;
334
+ }
335
+ return result;
336
+ }
337
+ function extractMistralResponse(response) {
338
+ const result = extractOpenAIResponse(response);
339
+ if (response?.model) {
340
+ result.model = response.model;
341
+ }
342
+ return result;
343
+ }
344
+ function extractCohereResponse(response) {
345
+ const result = {
346
+ model: "",
347
+ content: "",
348
+ inputTokens: null,
349
+ outputTokens: null,
350
+ totalTokens: null,
351
+ finishReason: null,
352
+ toolCalls: [],
353
+ logprobs: null
354
+ };
355
+ if (response?.text !== void 0) {
356
+ result.content = response.text || "";
357
+ }
358
+ if (response?.generations?.[0]) {
359
+ result.content = response.generations[0].text || "";
360
+ }
361
+ if (response?.model) {
362
+ result.model = response.model;
363
+ }
364
+ if (response?.finish_reason) {
365
+ result.finishReason = response.finish_reason;
366
+ }
367
+ if (response?.tool_calls && Array.isArray(response.tool_calls)) {
368
+ result.toolCalls = response.tool_calls.map((tc) => ({
369
+ name: tc.name,
370
+ arguments: JSON.stringify(tc.parameters)
371
+ }));
372
+ }
373
+ if (response?.meta?.tokens) {
374
+ result.inputTokens = response.meta.tokens.input_tokens ?? null;
375
+ result.outputTokens = response.meta.tokens.output_tokens ?? null;
376
+ if (result.inputTokens !== null && result.outputTokens !== null) {
377
+ result.totalTokens = result.inputTokens + result.outputTokens;
378
+ }
379
+ }
380
+ if (response?.meta?.billed_units) {
381
+ result.inputTokens = response.meta.billed_units.input_tokens ?? null;
382
+ result.outputTokens = response.meta.billed_units.output_tokens ?? null;
383
+ if (result.inputTokens !== null && result.outputTokens !== null) {
384
+ result.totalTokens = result.inputTokens + result.outputTokens;
385
+ }
386
+ }
387
+ return result;
388
+ }
389
+ function extractResponse(response, provider) {
390
+ const detectedProvider = provider || detectProvider(response);
391
+ switch (detectedProvider) {
392
+ case "anthropic":
393
+ return extractAnthropicResponse(response);
394
+ case "google":
395
+ return extractGoogleAIResponse(response);
396
+ case "mistral":
397
+ return extractMistralResponse(response);
398
+ case "cohere":
399
+ return extractCohereResponse(response);
400
+ case "openai":
401
+ default:
402
+ return extractOpenAIResponse(response);
403
+ }
404
+ }
214
405
  function calculateLogprobMean(logprobs) {
215
406
  if (!logprobs?.content) return null;
216
407
  try {
@@ -231,16 +422,15 @@ var PromptTracker = class {
231
422
  appId;
232
423
  environment;
233
424
  versionStr;
234
- provider;
235
425
  // Validation
236
426
  schema;
237
427
  enumFields;
238
428
  numericBounds;
239
- // Context hashes
429
+ // Context hashes (auto-extracted from response)
240
430
  promptHash;
241
431
  toolSchemaHash;
242
432
  systemPromptHash;
243
- // Context for previews
433
+ // Context for previews (auto-extracted from response)
244
434
  messages;
245
435
  systemPrompt;
246
436
  // Timing
@@ -259,24 +449,19 @@ var PromptTracker = class {
259
449
  this.appId = options.appId || process.env.DEADPIPE_APP_ID;
260
450
  this.environment = options.environment || process.env.DEADPIPE_ENVIRONMENT;
261
451
  this.versionStr = options.version || process.env.DEADPIPE_VERSION || process.env.GIT_COMMIT;
262
- this.provider = options.provider || "openai";
263
452
  this.schema = options.schema;
264
453
  this.enumFields = options.enumFields;
265
454
  this.numericBounds = options.numericBounds;
266
- this.promptHash = options.messages ? hashMessages(options.messages) : void 0;
267
- this.toolSchemaHash = hashTools(options.tools);
268
- this.systemPromptHash = options.systemPrompt ? hashContentSync(options.systemPrompt) : void 0;
269
- this.messages = options.messages;
270
- this.systemPrompt = options.systemPrompt;
455
+ this.messages = void 0;
456
+ this.systemPrompt = void 0;
457
+ this.promptHash = void 0;
458
+ this.toolSchemaHash = void 0;
459
+ this.systemPromptHash = void 0;
271
460
  this.telemetry = {
272
461
  prompt_id: this.promptId,
273
- provider: this.provider,
274
462
  app_id: this.appId,
275
463
  environment: this.environment,
276
464
  version: this.versionStr,
277
- prompt_hash: this.promptHash,
278
- tool_schema_hash: this.toolSchemaHash,
279
- system_prompt_hash: this.systemPromptHash,
280
465
  status: "success"
281
466
  };
282
467
  }
@@ -295,11 +480,49 @@ var PromptTracker = class {
295
480
  this.telemetry.retry_count = this.retryCount;
296
481
  }
297
482
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
298
- record(response, parsedOutput) {
483
+ record(response, parsedOutput, input) {
299
484
  this.endTime = Date.now();
300
485
  this.telemetry.end_time = new Date(this.endTime).toISOString();
301
486
  this.telemetry.total_latency = this.startTime ? this.endTime - this.startTime : 0;
302
- const extracted = this.provider === "anthropic" ? extractAnthropicResponse(response) : extractOpenAIResponse(response);
487
+ const detectedProvider = detectProvider(response);
488
+ this.telemetry.provider = detectedProvider !== "unknown" ? detectedProvider : "openai";
489
+ const extracted = extractResponse(response, detectedProvider);
490
+ if (input) {
491
+ const messages = input.messages || [];
492
+ const tools = input.tools;
493
+ let systemPrompt;
494
+ if (input.system) {
495
+ systemPrompt = typeof input.system === "string" ? input.system : JSON.stringify(input.system);
496
+ }
497
+ if (!systemPrompt) {
498
+ for (const msg of messages) {
499
+ if (msg.role === "system") {
500
+ systemPrompt = msg.content || "";
501
+ break;
502
+ }
503
+ }
504
+ }
505
+ if (messages.length > 0) {
506
+ this.promptHash = hashMessages(messages);
507
+ this.messages = messages;
508
+ }
509
+ if (tools) {
510
+ this.toolSchemaHash = hashTools(tools);
511
+ }
512
+ if (systemPrompt) {
513
+ this.systemPromptHash = hashContentSync(systemPrompt);
514
+ this.systemPrompt = systemPrompt;
515
+ }
516
+ }
517
+ if (this.promptHash) {
518
+ this.telemetry.prompt_hash = this.promptHash;
519
+ }
520
+ if (this.toolSchemaHash) {
521
+ this.telemetry.tool_schema_hash = this.toolSchemaHash;
522
+ }
523
+ if (this.systemPromptHash) {
524
+ this.telemetry.system_prompt_hash = this.systemPromptHash;
525
+ }
303
526
  this.telemetry.model = extracted.model;
304
527
  this.telemetry.input_tokens = extracted.inputTokens ?? void 0;
305
528
  this.telemetry.output_tokens = extracted.outputTokens ?? void 0;
@@ -308,7 +531,7 @@ var PromptTracker = class {
308
531
  const content = extracted.content;
309
532
  this.telemetry.output_length = content?.length ?? 0;
310
533
  this.telemetry.empty_output = !content || content.trim().length === 0;
311
- this.telemetry.truncated = extracted.finishReason === "length";
534
+ this.telemetry.truncated = extracted.finishReason === "length" || extracted.finishReason === "MAX_TOKENS";
312
535
  const MAX_PREVIEW_LENGTH = 2e3;
313
536
  if (content) {
314
537
  this.telemetry.output_preview = content.length > MAX_PREVIEW_LENGTH ? content.substring(0, MAX_PREVIEW_LENGTH) + "..." : content;
@@ -418,17 +641,25 @@ var PromptTracker = class {
418
641
  this.recorded = true;
419
642
  }
420
643
  async send() {
421
- if (!this.apiKey) return;
644
+ if (!this.apiKey) {
645
+ if (process.env.NODE_ENV === "development" || process.env.DEADPIPE_DEBUG === "1") {
646
+ console.warn("[Deadpipe] DEADPIPE_API_KEY not set. Telemetry will not be sent.");
647
+ }
648
+ return;
649
+ }
422
650
  try {
423
651
  const controller = new AbortController();
424
652
  const timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
425
653
  const payload = {};
426
654
  for (const [key, value] of Object.entries(this.telemetry)) {
427
- if (value !== void 0) {
428
- payload[key] = value;
429
- }
655
+ if (value === void 0 || value === null) continue;
656
+ if (typeof value === "string" && value === "") continue;
657
+ if (typeof value === "boolean" && value === false) continue;
658
+ if (Array.isArray(value) && value.length === 0) continue;
659
+ if (typeof value === "object" && Object.keys(value).length === 0) continue;
660
+ payload[key] = value;
430
661
  }
431
- await fetch(`${this.baseUrl}/prompt`, {
662
+ fetch(`${this.baseUrl}/prompt`, {
432
663
  method: "POST",
433
664
  headers: {
434
665
  "Content-Type": "application/json",
@@ -436,8 +667,10 @@ var PromptTracker = class {
436
667
  },
437
668
  body: JSON.stringify(payload),
438
669
  signal: controller.signal
670
+ }).catch(() => {
671
+ }).finally(() => {
672
+ clearTimeout(timeoutId);
439
673
  });
440
- clearTimeout(timeoutId);
441
674
  } catch {
442
675
  }
443
676
  }
@@ -474,28 +707,14 @@ function wrapOpenAI(client, options) {
474
707
  ...client.chat.completions,
475
708
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
476
709
  create: async (params) => {
477
- const messages = params.messages || [];
478
- const tools = params.tools;
479
- let systemPrompt;
480
- for (const msg of messages) {
481
- if (msg.role === "system") {
482
- systemPrompt = msg.content || "";
483
- break;
484
- }
485
- }
486
710
  return track(
487
711
  promptId,
488
712
  async (t) => {
489
713
  const response = await client.chat.completions.create(params);
490
- t.record(response);
714
+ t.record(response, void 0, params);
491
715
  return response;
492
716
  },
493
- {
494
- ...trackOptions,
495
- messages,
496
- tools,
497
- systemPrompt
498
- }
717
+ trackOptions
499
718
  );
500
719
  }
501
720
  }
@@ -506,35 +725,224 @@ function wrapOpenAI(client, options) {
506
725
  ...client.responses,
507
726
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
508
727
  create: async (params) => {
509
- const inputContent = params.input || "";
510
- const messages = typeof inputContent === "string" ? [{ role: "user", content: inputContent }] : inputContent;
511
728
  return track(
512
729
  promptId,
513
730
  async (t) => {
514
731
  const response = await client.responses.create(params);
515
- t.record(response);
732
+ t.record(response, void 0, params);
516
733
  return response;
517
734
  },
518
- {
519
- ...trackOptions,
520
- messages
521
- }
735
+ trackOptions
736
+ );
737
+ }
738
+ };
739
+ }
740
+ return wrappedClient;
741
+ }
742
+ function wrapAnthropic(client, options) {
743
+ const { promptId, ...trackOptions } = options;
744
+ const wrappedClient = Object.create(client);
745
+ if (client.messages) {
746
+ wrappedClient.messages = {
747
+ ...client.messages,
748
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
749
+ create: async (params) => {
750
+ return track(
751
+ promptId,
752
+ async (t) => {
753
+ const response = await client.messages.create(params);
754
+ t.record(response, void 0, params);
755
+ return response;
756
+ },
757
+ trackOptions
758
+ );
759
+ }
760
+ };
761
+ }
762
+ return wrappedClient;
763
+ }
764
+ function wrapGoogleAI(client, options) {
765
+ const { promptId, ...trackOptions } = options;
766
+ return {
767
+ ...client,
768
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
769
+ getGenerativeModel: (modelParams) => {
770
+ const model = client.getGenerativeModel(modelParams);
771
+ return {
772
+ ...model,
773
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
774
+ generateContent: async (params) => {
775
+ return track(
776
+ promptId,
777
+ async (t) => {
778
+ const response = await model.generateContent(params);
779
+ const input = {
780
+ messages: Array.isArray(params) ? params.map((p) => ({
781
+ role: "user",
782
+ content: typeof p === "string" ? p : p.text || ""
783
+ })) : [{ role: "user", content: typeof params === "string" ? params : params.contents?.[0]?.parts?.[0]?.text || "" }]
784
+ };
785
+ t.record(response.response || response, void 0, input);
786
+ return response;
787
+ },
788
+ trackOptions
789
+ );
790
+ },
791
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
792
+ startChat: (chatParams) => {
793
+ const chat = model.startChat(chatParams);
794
+ return {
795
+ ...chat,
796
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
797
+ sendMessage: async (message) => {
798
+ return track(
799
+ promptId,
800
+ async (t) => {
801
+ const response = await chat.sendMessage(message);
802
+ const input = {
803
+ messages: [{ role: "user", content: typeof message === "string" ? message : JSON.stringify(message) }]
804
+ };
805
+ t.record(response.response || response, void 0, input);
806
+ return response;
807
+ },
808
+ trackOptions
809
+ );
810
+ }
811
+ };
812
+ }
813
+ };
814
+ }
815
+ };
816
+ }
817
+ function wrapMistral(client, options) {
818
+ const { promptId, ...trackOptions } = options;
819
+ const wrappedClient = Object.create(client);
820
+ if (client.chat?.complete) {
821
+ wrappedClient.chat = {
822
+ ...client.chat,
823
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
824
+ complete: async (params) => {
825
+ return track(
826
+ promptId,
827
+ async (t) => {
828
+ const response = await client.chat.complete(params);
829
+ t.record(response, void 0, params);
830
+ return response;
831
+ },
832
+ trackOptions
522
833
  );
523
834
  }
524
835
  };
525
836
  }
837
+ if (client.chat?.completions) {
838
+ wrappedClient.chat = {
839
+ ...client.chat,
840
+ completions: {
841
+ ...client.chat.completions,
842
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
843
+ create: async (params) => {
844
+ return track(
845
+ promptId,
846
+ async (t) => {
847
+ const response = await client.chat.completions.create(params);
848
+ t.record(response, void 0, params);
849
+ return response;
850
+ },
851
+ trackOptions
852
+ );
853
+ }
854
+ }
855
+ };
856
+ }
857
+ return wrappedClient;
858
+ }
859
+ function wrapCohere(client, options) {
860
+ const { promptId, ...trackOptions } = options;
861
+ const wrappedClient = Object.create(client);
862
+ if (typeof client.chat === "function") {
863
+ wrappedClient.chat = async (params) => {
864
+ return track(
865
+ promptId,
866
+ async (t) => {
867
+ const response = await client.chat(params);
868
+ const input = {
869
+ messages: params.chat_history || []
870
+ };
871
+ if (params.message) {
872
+ input.messages.push({ role: "user", content: params.message });
873
+ }
874
+ t.record(response, void 0, input);
875
+ return response;
876
+ },
877
+ trackOptions
878
+ );
879
+ };
880
+ }
881
+ if (typeof client.generate === "function") {
882
+ wrappedClient.generate = async (params) => {
883
+ return track(
884
+ promptId,
885
+ async (t) => {
886
+ const response = await client.generate(params);
887
+ const input = {
888
+ messages: [{ role: "user", content: params.prompt || "" }]
889
+ };
890
+ t.record(response, void 0, input);
891
+ return response;
892
+ },
893
+ trackOptions
894
+ );
895
+ };
896
+ }
526
897
  return wrappedClient;
527
898
  }
899
+ function wrap(client, options) {
900
+ const provider = detectClientProvider(client);
901
+ switch (provider) {
902
+ case "openai":
903
+ return wrapOpenAI(client, options);
904
+ case "anthropic":
905
+ return wrapAnthropic(client, options);
906
+ case "google":
907
+ return wrapGoogleAI(client, options);
908
+ case "mistral":
909
+ return wrapMistral(client, options);
910
+ case "cohere":
911
+ return wrapCohere(client, options);
912
+ default:
913
+ if (client.chat?.completions) {
914
+ return wrapOpenAI(client, options);
915
+ }
916
+ if (client.messages) {
917
+ return wrapAnthropic(client, options);
918
+ }
919
+ console.warn("[Deadpipe] Could not detect provider. Returning unwrapped client.");
920
+ return client;
921
+ }
922
+ }
923
+ var index_default = wrap;
528
924
  // Annotate the CommonJS export names for ESM import in node:
529
925
  0 && (module.exports = {
530
926
  PromptTracker,
531
927
  VERSION,
928
+ detectClientProvider,
929
+ detectProvider,
532
930
  detectRefusal,
533
931
  estimateCost,
534
932
  extractAnthropicResponse,
933
+ extractCohereResponse,
934
+ extractGoogleAIResponse,
935
+ extractMistralResponse,
535
936
  extractOpenAIResponse,
937
+ extractResponse,
536
938
  track,
537
939
  validateEnumBounds,
538
940
  validateNumericBounds,
941
+ wrap,
942
+ wrapAnthropic,
943
+ wrapClient,
944
+ wrapCohere,
945
+ wrapGoogleAI,
946
+ wrapMistral,
539
947
  wrapOpenAI
540
948
  });