ai-protocol-adapters 1.0.0-alpha.10 → 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 +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +54 -6
- package/dist/index.mjs +54 -6
- package/package.json +1 -1
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
|
}
|
|
@@ -5670,6 +5699,7 @@ var StandardProtocolAdapter = class {
|
|
|
5670
5699
|
}
|
|
5671
5700
|
};
|
|
5672
5701
|
let currentTextContent = "";
|
|
5702
|
+
let currentThinkingContent = "";
|
|
5673
5703
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
5674
5704
|
const toolInputBuffers = /* @__PURE__ */ new Map();
|
|
5675
5705
|
const indexToToolId = /* @__PURE__ */ new Map();
|
|
@@ -5709,6 +5739,12 @@ var StandardProtocolAdapter = class {
|
|
|
5709
5739
|
this.logDebug(`\u{1F4DD} [StandardProtocolAdapter] \u7D2F\u79EF\u6587\u672C\u5185\u5BB9 (${currentTextContent.length}\u5B57\u7B26)`, currentTextContent.substring(currentTextContent.length - 20));
|
|
5710
5740
|
}
|
|
5711
5741
|
}
|
|
5742
|
+
if (data.type === "content_block_delta" && data.delta?.type === "thinking_delta") {
|
|
5743
|
+
currentThinkingContent += data.delta.thinking;
|
|
5744
|
+
if (this.debugMode && currentThinkingContent.length % 50 === 0) {
|
|
5745
|
+
this.logDebug(`\u{1F4AD} [StandardProtocolAdapter] \u7D2F\u79EFthinking\u5185\u5BB9 (${currentThinkingContent.length}\u5B57\u7B26)`, currentThinkingContent.substring(currentThinkingContent.length - 20));
|
|
5746
|
+
}
|
|
5747
|
+
}
|
|
5712
5748
|
if (data.type === "content_block_delta" && data.delta?.type === "input_json_delta") {
|
|
5713
5749
|
const toolIndex = data.index;
|
|
5714
5750
|
const toolId = indexToToolId.get(toolIndex);
|
|
@@ -5773,6 +5809,17 @@ var StandardProtocolAdapter = class {
|
|
|
5773
5809
|
}
|
|
5774
5810
|
}
|
|
5775
5811
|
}
|
|
5812
|
+
if (currentThinkingContent.trim()) {
|
|
5813
|
+
response.content.push({
|
|
5814
|
+
type: "text",
|
|
5815
|
+
text: currentThinkingContent.trim()
|
|
5816
|
+
});
|
|
5817
|
+
if (this.debugMode) {
|
|
5818
|
+
this.logDebug("\u{1F4AD} [StandardProtocolAdapter] \u6DFB\u52A0thinking\u5185\u5BB9:", {
|
|
5819
|
+
thinkingLength: currentThinkingContent.length
|
|
5820
|
+
});
|
|
5821
|
+
}
|
|
5822
|
+
}
|
|
5776
5823
|
if (currentTextContent.trim()) {
|
|
5777
5824
|
response.content.push({
|
|
5778
5825
|
type: "text",
|
|
@@ -5784,6 +5831,7 @@ var StandardProtocolAdapter = class {
|
|
|
5784
5831
|
this.logDebug("\u2705 [StandardProtocolAdapter] \u6807\u51C6\u54CD\u5E94\u6784\u5EFA\u5B8C\u6210:", {
|
|
5785
5832
|
contentCount: response.content.length,
|
|
5786
5833
|
textLength: currentTextContent.length,
|
|
5834
|
+
thinkingLength: currentThinkingContent.length,
|
|
5787
5835
|
toolCallsCount: toolCalls.size,
|
|
5788
5836
|
finalUsage: response.usage,
|
|
5789
5837
|
stopReason: response.stop_reason
|
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
|
}
|
|
@@ -5563,6 +5592,7 @@ var StandardProtocolAdapter = class {
|
|
|
5563
5592
|
}
|
|
5564
5593
|
};
|
|
5565
5594
|
let currentTextContent = "";
|
|
5595
|
+
let currentThinkingContent = "";
|
|
5566
5596
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
5567
5597
|
const toolInputBuffers = /* @__PURE__ */ new Map();
|
|
5568
5598
|
const indexToToolId = /* @__PURE__ */ new Map();
|
|
@@ -5602,6 +5632,12 @@ var StandardProtocolAdapter = class {
|
|
|
5602
5632
|
this.logDebug(`\u{1F4DD} [StandardProtocolAdapter] \u7D2F\u79EF\u6587\u672C\u5185\u5BB9 (${currentTextContent.length}\u5B57\u7B26)`, currentTextContent.substring(currentTextContent.length - 20));
|
|
5603
5633
|
}
|
|
5604
5634
|
}
|
|
5635
|
+
if (data.type === "content_block_delta" && data.delta?.type === "thinking_delta") {
|
|
5636
|
+
currentThinkingContent += data.delta.thinking;
|
|
5637
|
+
if (this.debugMode && currentThinkingContent.length % 50 === 0) {
|
|
5638
|
+
this.logDebug(`\u{1F4AD} [StandardProtocolAdapter] \u7D2F\u79EFthinking\u5185\u5BB9 (${currentThinkingContent.length}\u5B57\u7B26)`, currentThinkingContent.substring(currentThinkingContent.length - 20));
|
|
5639
|
+
}
|
|
5640
|
+
}
|
|
5605
5641
|
if (data.type === "content_block_delta" && data.delta?.type === "input_json_delta") {
|
|
5606
5642
|
const toolIndex = data.index;
|
|
5607
5643
|
const toolId = indexToToolId.get(toolIndex);
|
|
@@ -5666,6 +5702,17 @@ var StandardProtocolAdapter = class {
|
|
|
5666
5702
|
}
|
|
5667
5703
|
}
|
|
5668
5704
|
}
|
|
5705
|
+
if (currentThinkingContent.trim()) {
|
|
5706
|
+
response.content.push({
|
|
5707
|
+
type: "text",
|
|
5708
|
+
text: currentThinkingContent.trim()
|
|
5709
|
+
});
|
|
5710
|
+
if (this.debugMode) {
|
|
5711
|
+
this.logDebug("\u{1F4AD} [StandardProtocolAdapter] \u6DFB\u52A0thinking\u5185\u5BB9:", {
|
|
5712
|
+
thinkingLength: currentThinkingContent.length
|
|
5713
|
+
});
|
|
5714
|
+
}
|
|
5715
|
+
}
|
|
5669
5716
|
if (currentTextContent.trim()) {
|
|
5670
5717
|
response.content.push({
|
|
5671
5718
|
type: "text",
|
|
@@ -5677,6 +5724,7 @@ var StandardProtocolAdapter = class {
|
|
|
5677
5724
|
this.logDebug("\u2705 [StandardProtocolAdapter] \u6807\u51C6\u54CD\u5E94\u6784\u5EFA\u5B8C\u6210:", {
|
|
5678
5725
|
contentCount: response.content.length,
|
|
5679
5726
|
textLength: currentTextContent.length,
|
|
5727
|
+
thinkingLength: currentThinkingContent.length,
|
|
5680
5728
|
toolCallsCount: toolCalls.size,
|
|
5681
5729
|
finalUsage: response.usage,
|
|
5682
5730
|
stopReason: response.stop_reason
|
package/package.json
CHANGED