@jeffusion/bungee-llms 5.14.0 → 5.15.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
@@ -367,37 +367,17 @@ class OpenAIProtocolConversion {
367
367
  }
368
368
  return normalizedBody;
369
369
  }
370
- async ensureAssistantToolUseReasoningContent(response) {
371
- const contentType = response.headers.get("content-type") || "";
372
- if (!contentType.includes("application/json")) {
373
- return response;
374
- }
375
- let body;
376
- try {
377
- body = await response.clone().json();
378
- } catch {
379
- return response;
380
- }
370
+ ensureAssistantToolUseReasoningContent(body) {
381
371
  if (!isRecord(body) || body.type !== "message" || body.role !== "assistant" || !Array.isArray(body.content)) {
382
- return response;
383
- }
384
- if (!body.content.some((block) => isRecord(block) && block.type === "tool_use")) {
385
- return response;
372
+ return body;
386
373
  }
387
- const existingReasoningContent = typeof body.reasoning_content === "string" ? body.reasoning_content : undefined;
388
- if (existingReasoningContent !== undefined) {
389
- return response;
374
+ if (!body.content.some((block) => isRecord(block) && block.type === "tool_use") || typeof body.reasoning_content === "string") {
375
+ return body;
390
376
  }
391
- const extractedReasoning = this.extractThinkingTextFromAnthropicContent(body.content);
392
- const patchedBody = {
377
+ return {
393
378
  ...body,
394
- reasoning_content: extractedReasoning
379
+ reasoning_content: this.extractThinkingTextFromAnthropicContent(body.content)
395
380
  };
396
- return new Response(JSON.stringify(patchedBody), {
397
- status: response.status,
398
- statusText: response.statusText,
399
- headers: response.headers
400
- });
401
381
  }
402
382
  ensureMessagesStreamCompatibility(events, ctx) {
403
383
  const withUsage = this.ensureMessageDeltaUsage(events, ctx);
@@ -2846,8 +2826,7 @@ class AnthropicToGeminiConverter {
2846
2826
  }
2847
2827
  let geminiBody;
2848
2828
  try {
2849
- const responseClone = ctx.response.clone();
2850
- geminiBody = await responseClone.json();
2829
+ geminiBody = await ctx.bodyHandle.json();
2851
2830
  } catch {
2852
2831
  return ctx.response;
2853
2832
  }
@@ -3127,6 +3106,7 @@ class AnthropicToGeminiConverter {
3127
3106
  class AnthropicToOpenAIConverter {
3128
3107
  from = "anthropic";
3129
3108
  to = "openai";
3109
+ protocolConversion = new OpenAIProtocolConversion;
3130
3110
  configuredApiMode;
3131
3111
  setApiMode(mode) {
3132
3112
  if (typeof mode !== "string") {
@@ -3786,8 +3766,7 @@ class AnthropicToOpenAIConverter {
3786
3766
  }
3787
3767
  let openaiBody;
3788
3768
  try {
3789
- const responseClone = ctx.response.clone();
3790
- openaiBody = await responseClone.json();
3769
+ openaiBody = await ctx.bodyHandle.json();
3791
3770
  } catch {
3792
3771
  return ctx.response;
3793
3772
  }
@@ -3837,7 +3816,7 @@ class AnthropicToOpenAIConverter {
3837
3816
  return ctx.response;
3838
3817
  }
3839
3818
  const anthropicBody = this.isResponsesApiBody(openaiBody) ? this.convertOpenAIResponsesToAnthropic(openaiBody) : this.convertOpenAIResponseToAnthropic(openaiBody);
3840
- return new Response(JSON.stringify(anthropicBody), {
3819
+ return new Response(JSON.stringify(this.protocolConversion.ensureAssistantToolUseReasoningContent(anthropicBody)), {
3841
3820
  status: ctx.response.status,
3842
3821
  statusText: ctx.response.statusText,
3843
3822
  headers: ctx.response.headers
@@ -5353,8 +5332,7 @@ class GeminiToAnthropicConverter {
5353
5332
  }
5354
5333
  let anthropicBody;
5355
5334
  try {
5356
- const responseClone = ctx.response.clone();
5357
- anthropicBody = await responseClone.json();
5335
+ anthropicBody = await ctx.bodyHandle.json();
5358
5336
  } catch {
5359
5337
  return ctx.response;
5360
5338
  }
@@ -5799,8 +5777,7 @@ class GeminiToOpenAIConverter {
5799
5777
  }
5800
5778
  let openaiBody;
5801
5779
  try {
5802
- const responseClone = ctx.response.clone();
5803
- openaiBody = await responseClone.json();
5780
+ openaiBody = await ctx.bodyHandle.json();
5804
5781
  } catch {
5805
5782
  return ctx.response;
5806
5783
  }
@@ -6019,8 +5996,7 @@ class OpenAIToAnthropicConverter {
6019
5996
  }
6020
5997
  if (!ctx.response.ok) {
6021
5998
  try {
6022
- const responseClone = ctx.response.clone();
6023
- const errorBody = await responseClone.json();
5999
+ const errorBody = await ctx.bodyHandle.json();
6024
6000
  if (!this.isLikelyAnthropicErrorBody(errorBody)) {
6025
6001
  return ctx.response;
6026
6002
  }
@@ -6029,8 +6005,7 @@ class OpenAIToAnthropicConverter {
6029
6005
  return ctx.response;
6030
6006
  }
6031
6007
  }
6032
- const responseClone = ctx.response.clone();
6033
- const anthropicBody = await responseClone.json();
6008
+ const anthropicBody = await ctx.bodyHandle.json();
6034
6009
  const openaiBody = this.convertAnthropicResponseToOpenAI(anthropicBody);
6035
6010
  return new Response(JSON.stringify(openaiBody), {
6036
6011
  status: ctx.response.status,
@@ -6507,8 +6482,7 @@ class OpenAIToGeminiConverter {
6507
6482
  }
6508
6483
  if (!ctx.response.ok) {
6509
6484
  try {
6510
- const responseClone = ctx.response.clone();
6511
- const errorBody = await responseClone.json();
6485
+ const errorBody = await ctx.bodyHandle.json();
6512
6486
  if (!this.isLikelyGeminiErrorBody(errorBody)) {
6513
6487
  return ctx.response;
6514
6488
  }
@@ -6517,8 +6491,7 @@ class OpenAIToGeminiConverter {
6517
6491
  return ctx.response;
6518
6492
  }
6519
6493
  }
6520
- const responseClone = ctx.response.clone();
6521
- const geminiBody = await responseClone.json();
6494
+ const geminiBody = await ctx.bodyHandle.json();
6522
6495
  const openaiBody = this.convertGeminiResponseToOpenAI(geminiBody);
6523
6496
  return new Response(JSON.stringify(openaiBody), {
6524
6497
  status: ctx.response.status,