ai-protocol-adapters 1.0.0-alpha.11 → 1.0.0-alpha.13

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
@@ -3513,13 +3513,6 @@ var A2ORequestAdapter = class {
3513
3513
  convertOpenAIResponseToClaude(openaiResponse) {
3514
3514
  const claudeContent = [];
3515
3515
  const message = openaiResponse.choices?.[0]?.message;
3516
- const messageAny = message;
3517
- if (messageAny?.reasoning_content && typeof messageAny.reasoning_content === "string") {
3518
- claudeContent.push({
3519
- type: "text",
3520
- text: messageAny.reasoning_content
3521
- });
3522
- }
3523
3516
  if (message?.content) {
3524
3517
  claudeContent.push({
3525
3518
  type: "text",
@@ -4043,6 +4036,14 @@ var StreamingProtocolAdapter = class {
4043
4036
  if (!content) return;
4044
4037
  state.reasoningContent += content;
4045
4038
  if (!state.thinkingBlockStarted) {
4039
+ if (state.contentBlockStarted) {
4040
+ sseLines.push(
4041
+ "event: content_block_stop",
4042
+ 'data: {"type":"content_block_stop","index":0}',
4043
+ ""
4044
+ );
4045
+ state.contentBlockStarted = false;
4046
+ }
4046
4047
  sseLines.push(
4047
4048
  "event: content_block_start",
4048
4049
  'data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":"<thinking>"}}',
@@ -5295,6 +5296,17 @@ var O2ASSEAdapter = class {
5295
5296
  }
5296
5297
  try {
5297
5298
  const data = JSON.parse(dataContent);
5299
+ if ((data.choices?.length === 0 || !data.choices) && data.prompt_filter_results) {
5300
+ if (this.debugMode) {
5301
+ console.warn("\u26A0\uFE0F [O2ASSEAdapter] \u68C0\u6D4B\u5230Azure\u5185\u5BB9\u8FC7\u6EE4\u5668\u54CD\u5E94:", data.prompt_filter_results);
5302
+ }
5303
+ StreamingStateManager.processTextContent(
5304
+ `\u9519\u8BEF\uFF1A\u5185\u5BB9\u8FC7\u6EE4\u5668\u62E6\u622A\u4E86\u8BF7\u6C42\u3002\u8BF7\u68C0\u67E5\u8F93\u5165\u5185\u5BB9\u662F\u5426\u7B26\u5408\u4F7F\u7528\u653F\u7B56\u3002`,
5305
+ state,
5306
+ sseLines
5307
+ );
5308
+ break;
5309
+ }
5298
5310
  const choice = data.choices?.[0];
5299
5311
  const delta = choice?.delta;
5300
5312
  if (!delta) {
@@ -5306,9 +5318,6 @@ var O2ASSEAdapter = class {
5306
5318
  }
5307
5319
  continue;
5308
5320
  }
5309
- if (delta.reasoning_content) {
5310
- StreamingStateManager.processReasoningContent(delta.reasoning_content, state, sseLines);
5311
- }
5312
5321
  if (delta.content) {
5313
5322
  StreamingStateManager.processTextContent(delta.content, state, sseLines);
5314
5323
  }
@@ -5341,6 +5350,19 @@ var O2ASSEAdapter = class {
5341
5350
  processNonStreamingResponse(data, state, sseLines) {
5342
5351
  const choice = data.choices?.[0];
5343
5352
  if (!choice) {
5353
+ if (data.prompt_filter_results || data.choices?.length === 0) {
5354
+ const errorMsg = "Azure\u5185\u5BB9\u8FC7\u6EE4\u5668\u62E6\u622A\u4E86\u8BF7\u6C42";
5355
+ const filterDetails = data.prompt_filter_results ? JSON.stringify(data.prompt_filter_results).substring(0, 500) : "choices\u4E3A\u7A7A";
5356
+ if (this.debugMode) {
5357
+ console.warn(`\u26A0\uFE0F [O2ASSEAdapter] ${errorMsg}:`, filterDetails);
5358
+ }
5359
+ StreamingStateManager.processTextContent(
5360
+ `\u9519\u8BEF\uFF1A\u5185\u5BB9\u8FC7\u6EE4\u5668\u62E6\u622A\u4E86\u8BF7\u6C42\u3002\u8BF7\u68C0\u67E5\u8F93\u5165\u5185\u5BB9\u662F\u5426\u7B26\u5408\u4F7F\u7528\u653F\u7B56\u3002`,
5361
+ state,
5362
+ sseLines
5363
+ );
5364
+ return;
5365
+ }
5344
5366
  if (this.debugMode) {
5345
5367
  console.warn("\u26A0\uFE0F [O2ASSEAdapter] \u975E\u6D41\u5F0F\u54CD\u5E94\u6CA1\u6709choices\u6570\u636E");
5346
5368
  }
@@ -5670,7 +5692,6 @@ var StandardProtocolAdapter = class {
5670
5692
  }
5671
5693
  };
5672
5694
  let currentTextContent = "";
5673
- let currentThinkingContent = "";
5674
5695
  const toolCalls = /* @__PURE__ */ new Map();
5675
5696
  const toolInputBuffers = /* @__PURE__ */ new Map();
5676
5697
  const indexToToolId = /* @__PURE__ */ new Map();
@@ -5710,12 +5731,6 @@ var StandardProtocolAdapter = class {
5710
5731
  this.logDebug(`\u{1F4DD} [StandardProtocolAdapter] \u7D2F\u79EF\u6587\u672C\u5185\u5BB9 (${currentTextContent.length}\u5B57\u7B26)`, currentTextContent.substring(currentTextContent.length - 20));
5711
5732
  }
5712
5733
  }
5713
- if (data.type === "content_block_delta" && data.delta?.type === "thinking_delta") {
5714
- currentThinkingContent += data.delta.thinking;
5715
- if (this.debugMode && currentThinkingContent.length % 50 === 0) {
5716
- this.logDebug(`\u{1F4AD} [StandardProtocolAdapter] \u7D2F\u79EFthinking\u5185\u5BB9 (${currentThinkingContent.length}\u5B57\u7B26)`, currentThinkingContent.substring(currentThinkingContent.length - 20));
5717
- }
5718
- }
5719
5734
  if (data.type === "content_block_delta" && data.delta?.type === "input_json_delta") {
5720
5735
  const toolIndex = data.index;
5721
5736
  const toolId = indexToToolId.get(toolIndex);
@@ -5780,17 +5795,6 @@ var StandardProtocolAdapter = class {
5780
5795
  }
5781
5796
  }
5782
5797
  }
5783
- if (currentThinkingContent.trim()) {
5784
- response.content.push({
5785
- type: "text",
5786
- text: currentThinkingContent.trim()
5787
- });
5788
- if (this.debugMode) {
5789
- this.logDebug("\u{1F4AD} [StandardProtocolAdapter] \u6DFB\u52A0thinking\u5185\u5BB9:", {
5790
- thinkingLength: currentThinkingContent.length
5791
- });
5792
- }
5793
- }
5794
5798
  if (currentTextContent.trim()) {
5795
5799
  response.content.push({
5796
5800
  type: "text",
@@ -5802,7 +5806,6 @@ var StandardProtocolAdapter = class {
5802
5806
  this.logDebug("\u2705 [StandardProtocolAdapter] \u6807\u51C6\u54CD\u5E94\u6784\u5EFA\u5B8C\u6210:", {
5803
5807
  contentCount: response.content.length,
5804
5808
  textLength: currentTextContent.length,
5805
- thinkingLength: currentThinkingContent.length,
5806
5809
  toolCallsCount: toolCalls.size,
5807
5810
  finalUsage: response.usage,
5808
5811
  stopReason: response.stop_reason
package/dist/index.mjs CHANGED
@@ -3406,13 +3406,6 @@ var A2ORequestAdapter = class {
3406
3406
  convertOpenAIResponseToClaude(openaiResponse) {
3407
3407
  const claudeContent = [];
3408
3408
  const message = openaiResponse.choices?.[0]?.message;
3409
- const messageAny = message;
3410
- if (messageAny?.reasoning_content && typeof messageAny.reasoning_content === "string") {
3411
- claudeContent.push({
3412
- type: "text",
3413
- text: messageAny.reasoning_content
3414
- });
3415
- }
3416
3409
  if (message?.content) {
3417
3410
  claudeContent.push({
3418
3411
  type: "text",
@@ -3936,6 +3929,14 @@ var StreamingProtocolAdapter = class {
3936
3929
  if (!content) return;
3937
3930
  state.reasoningContent += content;
3938
3931
  if (!state.thinkingBlockStarted) {
3932
+ if (state.contentBlockStarted) {
3933
+ sseLines.push(
3934
+ "event: content_block_stop",
3935
+ 'data: {"type":"content_block_stop","index":0}',
3936
+ ""
3937
+ );
3938
+ state.contentBlockStarted = false;
3939
+ }
3939
3940
  sseLines.push(
3940
3941
  "event: content_block_start",
3941
3942
  'data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":"<thinking>"}}',
@@ -5188,6 +5189,17 @@ var O2ASSEAdapter = class {
5188
5189
  }
5189
5190
  try {
5190
5191
  const data = JSON.parse(dataContent);
5192
+ if ((data.choices?.length === 0 || !data.choices) && data.prompt_filter_results) {
5193
+ if (this.debugMode) {
5194
+ console.warn("\u26A0\uFE0F [O2ASSEAdapter] \u68C0\u6D4B\u5230Azure\u5185\u5BB9\u8FC7\u6EE4\u5668\u54CD\u5E94:", data.prompt_filter_results);
5195
+ }
5196
+ StreamingStateManager.processTextContent(
5197
+ `\u9519\u8BEF\uFF1A\u5185\u5BB9\u8FC7\u6EE4\u5668\u62E6\u622A\u4E86\u8BF7\u6C42\u3002\u8BF7\u68C0\u67E5\u8F93\u5165\u5185\u5BB9\u662F\u5426\u7B26\u5408\u4F7F\u7528\u653F\u7B56\u3002`,
5198
+ state,
5199
+ sseLines
5200
+ );
5201
+ break;
5202
+ }
5191
5203
  const choice = data.choices?.[0];
5192
5204
  const delta = choice?.delta;
5193
5205
  if (!delta) {
@@ -5199,9 +5211,6 @@ var O2ASSEAdapter = class {
5199
5211
  }
5200
5212
  continue;
5201
5213
  }
5202
- if (delta.reasoning_content) {
5203
- StreamingStateManager.processReasoningContent(delta.reasoning_content, state, sseLines);
5204
- }
5205
5214
  if (delta.content) {
5206
5215
  StreamingStateManager.processTextContent(delta.content, state, sseLines);
5207
5216
  }
@@ -5234,6 +5243,19 @@ var O2ASSEAdapter = class {
5234
5243
  processNonStreamingResponse(data, state, sseLines) {
5235
5244
  const choice = data.choices?.[0];
5236
5245
  if (!choice) {
5246
+ if (data.prompt_filter_results || data.choices?.length === 0) {
5247
+ const errorMsg = "Azure\u5185\u5BB9\u8FC7\u6EE4\u5668\u62E6\u622A\u4E86\u8BF7\u6C42";
5248
+ const filterDetails = data.prompt_filter_results ? JSON.stringify(data.prompt_filter_results).substring(0, 500) : "choices\u4E3A\u7A7A";
5249
+ if (this.debugMode) {
5250
+ console.warn(`\u26A0\uFE0F [O2ASSEAdapter] ${errorMsg}:`, filterDetails);
5251
+ }
5252
+ StreamingStateManager.processTextContent(
5253
+ `\u9519\u8BEF\uFF1A\u5185\u5BB9\u8FC7\u6EE4\u5668\u62E6\u622A\u4E86\u8BF7\u6C42\u3002\u8BF7\u68C0\u67E5\u8F93\u5165\u5185\u5BB9\u662F\u5426\u7B26\u5408\u4F7F\u7528\u653F\u7B56\u3002`,
5254
+ state,
5255
+ sseLines
5256
+ );
5257
+ return;
5258
+ }
5237
5259
  if (this.debugMode) {
5238
5260
  console.warn("\u26A0\uFE0F [O2ASSEAdapter] \u975E\u6D41\u5F0F\u54CD\u5E94\u6CA1\u6709choices\u6570\u636E");
5239
5261
  }
@@ -5563,7 +5585,6 @@ var StandardProtocolAdapter = class {
5563
5585
  }
5564
5586
  };
5565
5587
  let currentTextContent = "";
5566
- let currentThinkingContent = "";
5567
5588
  const toolCalls = /* @__PURE__ */ new Map();
5568
5589
  const toolInputBuffers = /* @__PURE__ */ new Map();
5569
5590
  const indexToToolId = /* @__PURE__ */ new Map();
@@ -5603,12 +5624,6 @@ var StandardProtocolAdapter = class {
5603
5624
  this.logDebug(`\u{1F4DD} [StandardProtocolAdapter] \u7D2F\u79EF\u6587\u672C\u5185\u5BB9 (${currentTextContent.length}\u5B57\u7B26)`, currentTextContent.substring(currentTextContent.length - 20));
5604
5625
  }
5605
5626
  }
5606
- if (data.type === "content_block_delta" && data.delta?.type === "thinking_delta") {
5607
- currentThinkingContent += data.delta.thinking;
5608
- if (this.debugMode && currentThinkingContent.length % 50 === 0) {
5609
- this.logDebug(`\u{1F4AD} [StandardProtocolAdapter] \u7D2F\u79EFthinking\u5185\u5BB9 (${currentThinkingContent.length}\u5B57\u7B26)`, currentThinkingContent.substring(currentThinkingContent.length - 20));
5610
- }
5611
- }
5612
5627
  if (data.type === "content_block_delta" && data.delta?.type === "input_json_delta") {
5613
5628
  const toolIndex = data.index;
5614
5629
  const toolId = indexToToolId.get(toolIndex);
@@ -5673,17 +5688,6 @@ var StandardProtocolAdapter = class {
5673
5688
  }
5674
5689
  }
5675
5690
  }
5676
- if (currentThinkingContent.trim()) {
5677
- response.content.push({
5678
- type: "text",
5679
- text: currentThinkingContent.trim()
5680
- });
5681
- if (this.debugMode) {
5682
- this.logDebug("\u{1F4AD} [StandardProtocolAdapter] \u6DFB\u52A0thinking\u5185\u5BB9:", {
5683
- thinkingLength: currentThinkingContent.length
5684
- });
5685
- }
5686
- }
5687
5691
  if (currentTextContent.trim()) {
5688
5692
  response.content.push({
5689
5693
  type: "text",
@@ -5695,7 +5699,6 @@ var StandardProtocolAdapter = class {
5695
5699
  this.logDebug("\u2705 [StandardProtocolAdapter] \u6807\u51C6\u54CD\u5E94\u6784\u5EFA\u5B8C\u6210:", {
5696
5700
  contentCount: response.content.length,
5697
5701
  textLength: currentTextContent.length,
5698
- thinkingLength: currentThinkingContent.length,
5699
5702
  toolCallsCount: toolCalls.size,
5700
5703
  finalUsage: response.usage,
5701
5704
  stopReason: response.stop_reason
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-protocol-adapters",
3
- "version": "1.0.0-alpha.11",
3
+ "version": "1.0.0-alpha.13",
4
4
  "description": "Universal AI Protocol Converter - OpenAI ⇄ Anthropic with full TypeScript support",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",