ai-protocol-adapters 1.0.0-alpha.20 → 1.0.0-alpha.21
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 +36 -3
- package/dist/index.mjs +36 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3782,6 +3782,12 @@ var A2ORequestAdapter = class {
|
|
|
3782
3782
|
convertOpenAIResponseToClaude(openaiResponse) {
|
|
3783
3783
|
const claudeContent = [];
|
|
3784
3784
|
const message = openaiResponse.choices?.[0]?.message;
|
|
3785
|
+
if (message?.reasoning_content) {
|
|
3786
|
+
claudeContent.push({
|
|
3787
|
+
type: "thinking",
|
|
3788
|
+
thinking: message.reasoning_content
|
|
3789
|
+
});
|
|
3790
|
+
}
|
|
3785
3791
|
if (message?.content) {
|
|
3786
3792
|
claudeContent.push({
|
|
3787
3793
|
type: "text",
|
|
@@ -4412,6 +4418,10 @@ var StreamingProtocolAdapter = class {
|
|
|
4412
4418
|
}
|
|
4413
4419
|
appendTextContent(content, state, sseLines) {
|
|
4414
4420
|
if (!content || content === "") return;
|
|
4421
|
+
if (!state.thinkingBlockStarted && !state.contentBlockStarted && content.trim() === "") {
|
|
4422
|
+
state.textContent += content;
|
|
4423
|
+
return;
|
|
4424
|
+
}
|
|
4415
4425
|
if (state.thinkingBlockStarted && !state.contentBlockStarted) {
|
|
4416
4426
|
sseLines.push(
|
|
4417
4427
|
"event: content_block_stop",
|
|
@@ -5178,9 +5188,10 @@ var StreamingStateManager = class {
|
|
|
5178
5188
|
return {
|
|
5179
5189
|
hasContent: false,
|
|
5180
5190
|
hasThinking: false,
|
|
5181
|
-
contentBlockIndex:
|
|
5182
|
-
|
|
5183
|
-
|
|
5191
|
+
contentBlockIndex: 1,
|
|
5192
|
+
// 🔧 修复:text block 在 thinking 之后 (index 1)
|
|
5193
|
+
thinkingBlockIndex: 0,
|
|
5194
|
+
// 🔧 修复:thinking block 先发送 (index 0)
|
|
5184
5195
|
toolCallsMap: /* @__PURE__ */ new Map(),
|
|
5185
5196
|
completedToolCalls: /* @__PURE__ */ new Set(),
|
|
5186
5197
|
accumulatedUsage: {
|
|
@@ -5196,6 +5207,9 @@ var StreamingStateManager = class {
|
|
|
5196
5207
|
* 处理文本内容
|
|
5197
5208
|
*/
|
|
5198
5209
|
static processTextContent(content, state, sseLines) {
|
|
5210
|
+
if (!state.hasThinking && !state.hasContent && content.trim() === "") {
|
|
5211
|
+
return;
|
|
5212
|
+
}
|
|
5199
5213
|
if (!state.hasContent) {
|
|
5200
5214
|
sseLines.push(...SSEEventGenerator.generateTextBlockStart(state.contentBlockIndex));
|
|
5201
5215
|
state.hasContent = true;
|
|
@@ -5726,6 +5740,11 @@ var O2ASSEAdapter = class {
|
|
|
5726
5740
|
if (delta.content) {
|
|
5727
5741
|
StreamingStateManager.processTextContent(delta.content, state, sseLines);
|
|
5728
5742
|
}
|
|
5743
|
+
if (delta.reasoning_content) {
|
|
5744
|
+
if (typeof delta.reasoning_content === "string") {
|
|
5745
|
+
StreamingStateManager.processReasoningContent(delta.reasoning_content, state, sseLines);
|
|
5746
|
+
}
|
|
5747
|
+
}
|
|
5729
5748
|
if (delta.tool_calls) {
|
|
5730
5749
|
ToolCallProcessor.processBatchToolCalls(delta.tool_calls, state, sseLines);
|
|
5731
5750
|
}
|
|
@@ -6097,6 +6116,7 @@ var StandardProtocolAdapter = class {
|
|
|
6097
6116
|
}
|
|
6098
6117
|
};
|
|
6099
6118
|
let currentTextContent = "";
|
|
6119
|
+
let currentThinkingContent = "";
|
|
6100
6120
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
6101
6121
|
const toolInputBuffers = /* @__PURE__ */ new Map();
|
|
6102
6122
|
const indexToToolId = /* @__PURE__ */ new Map();
|
|
@@ -6136,6 +6156,12 @@ var StandardProtocolAdapter = class {
|
|
|
6136
6156
|
this.logDebug(`\u{1F4DD} [StandardProtocolAdapter] \u7D2F\u79EF\u6587\u672C\u5185\u5BB9 (${currentTextContent.length}\u5B57\u7B26)`, currentTextContent.substring(currentTextContent.length - 20));
|
|
6137
6157
|
}
|
|
6138
6158
|
}
|
|
6159
|
+
if (data.type === "content_block_delta" && data.delta?.type === "thinking_delta") {
|
|
6160
|
+
currentThinkingContent += data.delta.thinking;
|
|
6161
|
+
if (this.debugMode && currentThinkingContent.length % 100 === 0) {
|
|
6162
|
+
this.logDebug(`\u{1F9E0} [StandardProtocolAdapter] \u7D2F\u79EFthinking\u5185\u5BB9 (${currentThinkingContent.length}\u5B57\u7B26)`);
|
|
6163
|
+
}
|
|
6164
|
+
}
|
|
6139
6165
|
if (data.type === "content_block_delta" && data.delta?.type === "input_json_delta") {
|
|
6140
6166
|
const toolIndex = data.index;
|
|
6141
6167
|
const toolId = indexToToolId.get(toolIndex);
|
|
@@ -6200,6 +6226,12 @@ var StandardProtocolAdapter = class {
|
|
|
6200
6226
|
}
|
|
6201
6227
|
}
|
|
6202
6228
|
}
|
|
6229
|
+
if (currentThinkingContent.trim()) {
|
|
6230
|
+
response.content.push({
|
|
6231
|
+
type: "thinking",
|
|
6232
|
+
thinking: currentThinkingContent.trim()
|
|
6233
|
+
});
|
|
6234
|
+
}
|
|
6203
6235
|
if (currentTextContent.trim()) {
|
|
6204
6236
|
response.content.push({
|
|
6205
6237
|
type: "text",
|
|
@@ -6210,6 +6242,7 @@ var StandardProtocolAdapter = class {
|
|
|
6210
6242
|
if (this.debugMode) {
|
|
6211
6243
|
this.logDebug("\u2705 [StandardProtocolAdapter] \u6807\u51C6\u54CD\u5E94\u6784\u5EFA\u5B8C\u6210:", {
|
|
6212
6244
|
contentCount: response.content.length,
|
|
6245
|
+
thinkingLength: currentThinkingContent.length,
|
|
6213
6246
|
textLength: currentTextContent.length,
|
|
6214
6247
|
toolCallsCount: toolCalls.size,
|
|
6215
6248
|
finalUsage: response.usage,
|
package/dist/index.mjs
CHANGED
|
@@ -3672,6 +3672,12 @@ var A2ORequestAdapter = class {
|
|
|
3672
3672
|
convertOpenAIResponseToClaude(openaiResponse) {
|
|
3673
3673
|
const claudeContent = [];
|
|
3674
3674
|
const message = openaiResponse.choices?.[0]?.message;
|
|
3675
|
+
if (message?.reasoning_content) {
|
|
3676
|
+
claudeContent.push({
|
|
3677
|
+
type: "thinking",
|
|
3678
|
+
thinking: message.reasoning_content
|
|
3679
|
+
});
|
|
3680
|
+
}
|
|
3675
3681
|
if (message?.content) {
|
|
3676
3682
|
claudeContent.push({
|
|
3677
3683
|
type: "text",
|
|
@@ -4302,6 +4308,10 @@ var StreamingProtocolAdapter = class {
|
|
|
4302
4308
|
}
|
|
4303
4309
|
appendTextContent(content, state, sseLines) {
|
|
4304
4310
|
if (!content || content === "") return;
|
|
4311
|
+
if (!state.thinkingBlockStarted && !state.contentBlockStarted && content.trim() === "") {
|
|
4312
|
+
state.textContent += content;
|
|
4313
|
+
return;
|
|
4314
|
+
}
|
|
4305
4315
|
if (state.thinkingBlockStarted && !state.contentBlockStarted) {
|
|
4306
4316
|
sseLines.push(
|
|
4307
4317
|
"event: content_block_stop",
|
|
@@ -5068,9 +5078,10 @@ var StreamingStateManager = class {
|
|
|
5068
5078
|
return {
|
|
5069
5079
|
hasContent: false,
|
|
5070
5080
|
hasThinking: false,
|
|
5071
|
-
contentBlockIndex:
|
|
5072
|
-
|
|
5073
|
-
|
|
5081
|
+
contentBlockIndex: 1,
|
|
5082
|
+
// 🔧 修复:text block 在 thinking 之后 (index 1)
|
|
5083
|
+
thinkingBlockIndex: 0,
|
|
5084
|
+
// 🔧 修复:thinking block 先发送 (index 0)
|
|
5074
5085
|
toolCallsMap: /* @__PURE__ */ new Map(),
|
|
5075
5086
|
completedToolCalls: /* @__PURE__ */ new Set(),
|
|
5076
5087
|
accumulatedUsage: {
|
|
@@ -5086,6 +5097,9 @@ var StreamingStateManager = class {
|
|
|
5086
5097
|
* 处理文本内容
|
|
5087
5098
|
*/
|
|
5088
5099
|
static processTextContent(content, state, sseLines) {
|
|
5100
|
+
if (!state.hasThinking && !state.hasContent && content.trim() === "") {
|
|
5101
|
+
return;
|
|
5102
|
+
}
|
|
5089
5103
|
if (!state.hasContent) {
|
|
5090
5104
|
sseLines.push(...SSEEventGenerator.generateTextBlockStart(state.contentBlockIndex));
|
|
5091
5105
|
state.hasContent = true;
|
|
@@ -5616,6 +5630,11 @@ var O2ASSEAdapter = class {
|
|
|
5616
5630
|
if (delta.content) {
|
|
5617
5631
|
StreamingStateManager.processTextContent(delta.content, state, sseLines);
|
|
5618
5632
|
}
|
|
5633
|
+
if (delta.reasoning_content) {
|
|
5634
|
+
if (typeof delta.reasoning_content === "string") {
|
|
5635
|
+
StreamingStateManager.processReasoningContent(delta.reasoning_content, state, sseLines);
|
|
5636
|
+
}
|
|
5637
|
+
}
|
|
5619
5638
|
if (delta.tool_calls) {
|
|
5620
5639
|
ToolCallProcessor.processBatchToolCalls(delta.tool_calls, state, sseLines);
|
|
5621
5640
|
}
|
|
@@ -5987,6 +6006,7 @@ var StandardProtocolAdapter = class {
|
|
|
5987
6006
|
}
|
|
5988
6007
|
};
|
|
5989
6008
|
let currentTextContent = "";
|
|
6009
|
+
let currentThinkingContent = "";
|
|
5990
6010
|
const toolCalls = /* @__PURE__ */ new Map();
|
|
5991
6011
|
const toolInputBuffers = /* @__PURE__ */ new Map();
|
|
5992
6012
|
const indexToToolId = /* @__PURE__ */ new Map();
|
|
@@ -6026,6 +6046,12 @@ var StandardProtocolAdapter = class {
|
|
|
6026
6046
|
this.logDebug(`\u{1F4DD} [StandardProtocolAdapter] \u7D2F\u79EF\u6587\u672C\u5185\u5BB9 (${currentTextContent.length}\u5B57\u7B26)`, currentTextContent.substring(currentTextContent.length - 20));
|
|
6027
6047
|
}
|
|
6028
6048
|
}
|
|
6049
|
+
if (data.type === "content_block_delta" && data.delta?.type === "thinking_delta") {
|
|
6050
|
+
currentThinkingContent += data.delta.thinking;
|
|
6051
|
+
if (this.debugMode && currentThinkingContent.length % 100 === 0) {
|
|
6052
|
+
this.logDebug(`\u{1F9E0} [StandardProtocolAdapter] \u7D2F\u79EFthinking\u5185\u5BB9 (${currentThinkingContent.length}\u5B57\u7B26)`);
|
|
6053
|
+
}
|
|
6054
|
+
}
|
|
6029
6055
|
if (data.type === "content_block_delta" && data.delta?.type === "input_json_delta") {
|
|
6030
6056
|
const toolIndex = data.index;
|
|
6031
6057
|
const toolId = indexToToolId.get(toolIndex);
|
|
@@ -6090,6 +6116,12 @@ var StandardProtocolAdapter = class {
|
|
|
6090
6116
|
}
|
|
6091
6117
|
}
|
|
6092
6118
|
}
|
|
6119
|
+
if (currentThinkingContent.trim()) {
|
|
6120
|
+
response.content.push({
|
|
6121
|
+
type: "thinking",
|
|
6122
|
+
thinking: currentThinkingContent.trim()
|
|
6123
|
+
});
|
|
6124
|
+
}
|
|
6093
6125
|
if (currentTextContent.trim()) {
|
|
6094
6126
|
response.content.push({
|
|
6095
6127
|
type: "text",
|
|
@@ -6100,6 +6132,7 @@ var StandardProtocolAdapter = class {
|
|
|
6100
6132
|
if (this.debugMode) {
|
|
6101
6133
|
this.logDebug("\u2705 [StandardProtocolAdapter] \u6807\u51C6\u54CD\u5E94\u6784\u5EFA\u5B8C\u6210:", {
|
|
6102
6134
|
contentCount: response.content.length,
|
|
6135
|
+
thinkingLength: currentThinkingContent.length,
|
|
6103
6136
|
textLength: currentTextContent.length,
|
|
6104
6137
|
toolCallsCount: toolCalls.size,
|
|
6105
6138
|
finalUsage: response.usage,
|
package/package.json
CHANGED