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

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.d.mts CHANGED
@@ -6178,6 +6178,18 @@ interface O2ASSEAdapterConfig {
6178
6178
  defaultRole: 'assistant' | 'user' | 'system';
6179
6179
  /** 是否生成唯一消息ID */
6180
6180
  generateUniqueMessageId: boolean;
6181
+ /**
6182
+ * 是否启用启发式thinking标记解析
6183
+ *
6184
+ * 当设置为true时,会检测content字段中的<thinking>...</thinking>标记
6185
+ * 并自动分离为thinking_delta事件。
6186
+ *
6187
+ * ⚠️ 警告:只在Provider确认会在content中返回thinking标记时启用!
6188
+ * 例如:iFlow的GLM-4.6等推理模型
6189
+ *
6190
+ * @default false - 默认禁用,需要显式启用
6191
+ */
6192
+ enableThinkingTagParsing: boolean;
6181
6193
  }
6182
6194
 
6183
6195
  /**
package/dist/index.d.ts CHANGED
@@ -6178,6 +6178,18 @@ interface O2ASSEAdapterConfig {
6178
6178
  defaultRole: 'assistant' | 'user' | 'system';
6179
6179
  /** 是否生成唯一消息ID */
6180
6180
  generateUniqueMessageId: boolean;
6181
+ /**
6182
+ * 是否启用启发式thinking标记解析
6183
+ *
6184
+ * 当设置为true时,会检测content字段中的<thinking>...</thinking>标记
6185
+ * 并自动分离为thinking_delta事件。
6186
+ *
6187
+ * ⚠️ 警告:只在Provider确认会在content中返回thinking标记时启用!
6188
+ * 例如:iFlow的GLM-4.6等推理模型
6189
+ *
6190
+ * @default false - 默认禁用,需要显式启用
6191
+ */
6192
+ enableThinkingTagParsing: boolean;
6181
6193
  }
6182
6194
 
6183
6195
  /**
package/dist/index.js CHANGED
@@ -4787,9 +4787,36 @@ var StreamingStateManager = class {
4787
4787
  };
4788
4788
  }
4789
4789
  /**
4790
- * 处理文本内容
4791
- */
4792
- static processTextContent(content, state, sseLines) {
4790
+ * 处理文本内容(支持可选的启发式思考标记检测)
4791
+ */
4792
+ static processTextContent(content, state, sseLines, enableThinkingTagParsing = false) {
4793
+ if (enableThinkingTagParsing) {
4794
+ const thinkingTagPattern = /<thinking>([\s\S]*?)(<\/thinking>|$)/i;
4795
+ const match = content.match(thinkingTagPattern);
4796
+ if (match) {
4797
+ const beforeThinking = content.substring(0, match.index);
4798
+ const thinkingContent = match[1];
4799
+ const afterThinking = match[2] === "</thinking>" ? content.substring(match.index + match[0].length) : "";
4800
+ if (beforeThinking.trim()) {
4801
+ if (!state.hasContent) {
4802
+ sseLines.push(...SSEEventGenerator.generateTextBlockStart(state.contentBlockIndex));
4803
+ state.hasContent = true;
4804
+ }
4805
+ sseLines.push(...SSEEventGenerator.generateTextDelta(state.contentBlockIndex, beforeThinking));
4806
+ }
4807
+ if (thinkingContent.trim()) {
4808
+ this.processReasoningContent(thinkingContent, state, sseLines);
4809
+ }
4810
+ if (afterThinking.trim()) {
4811
+ if (!state.hasContent) {
4812
+ sseLines.push(...SSEEventGenerator.generateTextBlockStart(state.contentBlockIndex));
4813
+ state.hasContent = true;
4814
+ }
4815
+ sseLines.push(...SSEEventGenerator.generateTextDelta(state.contentBlockIndex, afterThinking));
4816
+ }
4817
+ return;
4818
+ }
4819
+ }
4793
4820
  if (!state.hasContent) {
4794
4821
  sseLines.push(...SSEEventGenerator.generateTextBlockStart(state.contentBlockIndex));
4795
4822
  state.hasContent = true;
@@ -4877,7 +4904,9 @@ var DEFAULT_CONFIG2 = {
4877
4904
  errorDataMaxLength: 100,
4878
4905
  warningDataMaxLength: 50,
4879
4906
  defaultRole: "assistant",
4880
- generateUniqueMessageId: true
4907
+ generateUniqueMessageId: true,
4908
+ enableThinkingTagParsing: false
4909
+ // 🔒 默认禁用
4881
4910
  };
4882
4911
  function generateMessageId() {
4883
4912
  return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
@@ -5310,7 +5339,7 @@ var O2ASSEAdapter = class {
5310
5339
  StreamingStateManager.processReasoningContent(delta.reasoning_content, state, sseLines);
5311
5340
  }
5312
5341
  if (delta.content) {
5313
- StreamingStateManager.processTextContent(delta.content, state, sseLines);
5342
+ StreamingStateManager.processTextContent(delta.content, state, sseLines, this.config.enableThinkingTagParsing);
5314
5343
  }
5315
5344
  if (delta.tool_calls) {
5316
5345
  ToolCallProcessor.processBatchToolCalls(delta.tool_calls, state, sseLines);
@@ -5354,7 +5383,7 @@ var O2ASSEAdapter = class {
5354
5383
  }
5355
5384
  const message = choice.message;
5356
5385
  if (message?.content) {
5357
- StreamingStateManager.processTextContent(message.content, state, sseLines);
5386
+ StreamingStateManager.processTextContent(message.content, state, sseLines, this.config.enableThinkingTagParsing);
5358
5387
  if (this.debugMode) {
5359
5388
  console.log("\u{1F50D} [O2ASSEAdapter] \u975E\u6D41\u5F0F\u54CD\u5E94content:", message.content);
5360
5389
  }
package/dist/index.mjs CHANGED
@@ -4680,9 +4680,36 @@ var StreamingStateManager = class {
4680
4680
  };
4681
4681
  }
4682
4682
  /**
4683
- * 处理文本内容
4684
- */
4685
- static processTextContent(content, state, sseLines) {
4683
+ * 处理文本内容(支持可选的启发式思考标记检测)
4684
+ */
4685
+ static processTextContent(content, state, sseLines, enableThinkingTagParsing = false) {
4686
+ if (enableThinkingTagParsing) {
4687
+ const thinkingTagPattern = /<thinking>([\s\S]*?)(<\/thinking>|$)/i;
4688
+ const match = content.match(thinkingTagPattern);
4689
+ if (match) {
4690
+ const beforeThinking = content.substring(0, match.index);
4691
+ const thinkingContent = match[1];
4692
+ const afterThinking = match[2] === "</thinking>" ? content.substring(match.index + match[0].length) : "";
4693
+ if (beforeThinking.trim()) {
4694
+ if (!state.hasContent) {
4695
+ sseLines.push(...SSEEventGenerator.generateTextBlockStart(state.contentBlockIndex));
4696
+ state.hasContent = true;
4697
+ }
4698
+ sseLines.push(...SSEEventGenerator.generateTextDelta(state.contentBlockIndex, beforeThinking));
4699
+ }
4700
+ if (thinkingContent.trim()) {
4701
+ this.processReasoningContent(thinkingContent, state, sseLines);
4702
+ }
4703
+ if (afterThinking.trim()) {
4704
+ if (!state.hasContent) {
4705
+ sseLines.push(...SSEEventGenerator.generateTextBlockStart(state.contentBlockIndex));
4706
+ state.hasContent = true;
4707
+ }
4708
+ sseLines.push(...SSEEventGenerator.generateTextDelta(state.contentBlockIndex, afterThinking));
4709
+ }
4710
+ return;
4711
+ }
4712
+ }
4686
4713
  if (!state.hasContent) {
4687
4714
  sseLines.push(...SSEEventGenerator.generateTextBlockStart(state.contentBlockIndex));
4688
4715
  state.hasContent = true;
@@ -4770,7 +4797,9 @@ var DEFAULT_CONFIG2 = {
4770
4797
  errorDataMaxLength: 100,
4771
4798
  warningDataMaxLength: 50,
4772
4799
  defaultRole: "assistant",
4773
- generateUniqueMessageId: true
4800
+ generateUniqueMessageId: true,
4801
+ enableThinkingTagParsing: false
4802
+ // 🔒 默认禁用
4774
4803
  };
4775
4804
  function generateMessageId() {
4776
4805
  return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
@@ -5203,7 +5232,7 @@ var O2ASSEAdapter = class {
5203
5232
  StreamingStateManager.processReasoningContent(delta.reasoning_content, state, sseLines);
5204
5233
  }
5205
5234
  if (delta.content) {
5206
- StreamingStateManager.processTextContent(delta.content, state, sseLines);
5235
+ StreamingStateManager.processTextContent(delta.content, state, sseLines, this.config.enableThinkingTagParsing);
5207
5236
  }
5208
5237
  if (delta.tool_calls) {
5209
5238
  ToolCallProcessor.processBatchToolCalls(delta.tool_calls, state, sseLines);
@@ -5247,7 +5276,7 @@ var O2ASSEAdapter = class {
5247
5276
  }
5248
5277
  const message = choice.message;
5249
5278
  if (message?.content) {
5250
- StreamingStateManager.processTextContent(message.content, state, sseLines);
5279
+ StreamingStateManager.processTextContent(message.content, state, sseLines, this.config.enableThinkingTagParsing);
5251
5280
  if (this.debugMode) {
5252
5281
  console.log("\u{1F50D} [O2ASSEAdapter] \u975E\u6D41\u5F0F\u54CD\u5E94content:", message.content);
5253
5282
  }
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.12",
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",