billion-context 0.1.37 → 0.1.38
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 +62 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -46861,6 +46861,17 @@ function openaiToCore(body) {
|
|
|
46861
46861
|
break;
|
|
46862
46862
|
}
|
|
46863
46863
|
case "assistant": {
|
|
46864
|
+
const reasoning = typeof m2.reasoning_content === "string" ? m2.reasoning_content : "";
|
|
46865
|
+
if (reasoning) {
|
|
46866
|
+
const base = deriveMessageId("assistant", "reasoning", reasoning);
|
|
46867
|
+
msgs.push({
|
|
46868
|
+
id: clusters.next(base),
|
|
46869
|
+
role: "assistant",
|
|
46870
|
+
contentType: "reasoning",
|
|
46871
|
+
text: reasoning,
|
|
46872
|
+
reasoningContent: reasoning
|
|
46873
|
+
});
|
|
46874
|
+
}
|
|
46864
46875
|
const text = stringContent(m2.content);
|
|
46865
46876
|
if (text) {
|
|
46866
46877
|
const base = deriveMessageId("assistant", "text", text);
|
|
@@ -46906,21 +46917,27 @@ function coreToOpenai(messages) {
|
|
|
46906
46917
|
let pending = null;
|
|
46907
46918
|
const flush = () => {
|
|
46908
46919
|
if (!pending) return;
|
|
46920
|
+
const reasoning = pending.reasoning !== null && pending.reasoning.length > 0 ? pending.reasoning : void 0;
|
|
46909
46921
|
if (pending.toolCalls.length > 0) {
|
|
46910
46922
|
out.push({
|
|
46911
46923
|
role: "assistant",
|
|
46912
46924
|
content: pending.text ?? null,
|
|
46913
|
-
tool_calls: pending.toolCalls
|
|
46925
|
+
tool_calls: pending.toolCalls,
|
|
46926
|
+
...reasoning ? { reasoning_content: reasoning } : {}
|
|
46914
46927
|
});
|
|
46915
46928
|
} else if (pending.text !== null) {
|
|
46916
|
-
out.push({ role: "assistant", content: pending.text });
|
|
46929
|
+
out.push({ role: "assistant", content: pending.text, ...reasoning ? { reasoning_content: reasoning } : {} });
|
|
46930
|
+
} else if (reasoning) {
|
|
46931
|
+
out.push({ role: "assistant", content: null, reasoning_content: reasoning });
|
|
46917
46932
|
}
|
|
46918
46933
|
pending = null;
|
|
46919
46934
|
};
|
|
46920
46935
|
for (const m2 of messages) {
|
|
46921
46936
|
if (m2.role === "assistant") {
|
|
46922
|
-
if (!pending) pending = { text: null, toolCalls: [] };
|
|
46923
|
-
if (m2.contentType === "
|
|
46937
|
+
if (!pending) pending = { text: null, toolCalls: [], reasoning: null };
|
|
46938
|
+
if (m2.contentType === "reasoning") {
|
|
46939
|
+
pending.reasoning = (pending.reasoning ?? "") + (m2.reasoningContent ?? m2.text ?? "");
|
|
46940
|
+
} else if (m2.contentType === "text") {
|
|
46924
46941
|
pending.text = (pending.text ?? "") + (m2.text ?? "");
|
|
46925
46942
|
} else if (m2.contentType === "tool-call") {
|
|
46926
46943
|
pending.toolCalls.push({
|
|
@@ -48569,6 +48586,7 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
48569
48586
|
for (let round = 1; round <= MAX_LOOP_ROUNDS; round++) {
|
|
48570
48587
|
if (signal?.aborted) break;
|
|
48571
48588
|
let assistantText = "";
|
|
48589
|
+
let assistantReasoning = "";
|
|
48572
48590
|
const calls = [];
|
|
48573
48591
|
let usage = {};
|
|
48574
48592
|
let finishReason;
|
|
@@ -48581,6 +48599,15 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
48581
48599
|
} else if (!ctx.textProtocol && round > 1 && ev.delta.length > 0) {
|
|
48582
48600
|
yield adapter.emitText(ev.delta);
|
|
48583
48601
|
}
|
|
48602
|
+
} else if (ev.kind === "reasoning") {
|
|
48603
|
+
assistantReasoning += ev.delta;
|
|
48604
|
+
if (!ctx.textProtocol) {
|
|
48605
|
+
if (ev.raw) {
|
|
48606
|
+
yield ev.raw;
|
|
48607
|
+
} else if (round > 1 && ev.delta.length > 0 && adapter.emitReasoning) {
|
|
48608
|
+
yield adapter.emitReasoning(ev.delta);
|
|
48609
|
+
}
|
|
48610
|
+
}
|
|
48584
48611
|
} else if (ev.kind === "tool_call") {
|
|
48585
48612
|
calls.push({ name: ev.name, callId: ev.callId, arguments: ev.arguments });
|
|
48586
48613
|
} else if (ev.kind === "usage") {
|
|
@@ -48643,6 +48670,16 @@ async function* runCompressLoop(upstream, ctx, requestBody, requestOptions, adap
|
|
|
48643
48670
|
if (realCalls > 0) ctx.log(`[acp-loop] round ${round}: ${realCalls} real tool call(s) forwarded to client`);
|
|
48644
48671
|
}
|
|
48645
48672
|
if (proxyResults.length > 0) {
|
|
48673
|
+
if (assistantReasoning.length > 0) {
|
|
48674
|
+
const reasoningMsg = {
|
|
48675
|
+
id: `acp_loop_r${round}_reasoning`,
|
|
48676
|
+
role: "assistant",
|
|
48677
|
+
contentType: "reasoning",
|
|
48678
|
+
text: assistantReasoning,
|
|
48679
|
+
reasoningContent: assistantReasoning
|
|
48680
|
+
};
|
|
48681
|
+
coreMessages.push(reasoningMsg);
|
|
48682
|
+
}
|
|
48646
48683
|
if (assistantText.length > 0) {
|
|
48647
48684
|
coreMessages.push({
|
|
48648
48685
|
id: `acp_loop_r${round}_asst`,
|
|
@@ -49157,6 +49194,18 @@ function createOpenaiAdapter(requestBody) {
|
|
|
49157
49194
|
choices: [{ index: 0, delta: { content }, finish_reason: null }]
|
|
49158
49195
|
})}
|
|
49159
49196
|
|
|
49197
|
+
`,
|
|
49198
|
+
"utf8"
|
|
49199
|
+
);
|
|
49200
|
+
const buildReasoning = (content) => Buffer.from(
|
|
49201
|
+
`data: ${JSON.stringify({
|
|
49202
|
+
id: responseId,
|
|
49203
|
+
object: "chat.completion.chunk",
|
|
49204
|
+
created: Date.now(),
|
|
49205
|
+
model,
|
|
49206
|
+
choices: [{ index: 0, delta: { reasoning_content: content }, finish_reason: null }]
|
|
49207
|
+
})}
|
|
49208
|
+
|
|
49160
49209
|
`,
|
|
49161
49210
|
"utf8"
|
|
49162
49211
|
);
|
|
@@ -49267,6 +49316,9 @@ function createOpenaiAdapter(requestBody) {
|
|
|
49267
49316
|
yield { kind: "done", finishReason };
|
|
49268
49317
|
}
|
|
49269
49318
|
if (!delta) continue;
|
|
49319
|
+
if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
|
|
49320
|
+
yield { kind: "reasoning", delta: delta.reasoning_content, raw: rawBuf };
|
|
49321
|
+
}
|
|
49270
49322
|
if (delta.tool_calls) {
|
|
49271
49323
|
const tcs = delta.tool_calls;
|
|
49272
49324
|
for (const tc of tcs) {
|
|
@@ -49290,9 +49342,10 @@ function createOpenaiAdapter(requestBody) {
|
|
|
49290
49342
|
}
|
|
49291
49343
|
continue;
|
|
49292
49344
|
}
|
|
49345
|
+
const hasReasoning = typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0;
|
|
49293
49346
|
if (typeof delta.content === "string" && delta.content.length > 0) {
|
|
49294
|
-
yield { kind: "text", delta: delta.content, raw: rawBuf };
|
|
49295
|
-
} else if (delta.role || Object.keys(delta).length === 0 && !finishReason) {
|
|
49347
|
+
yield { kind: "text", delta: delta.content, ...hasReasoning ? {} : { raw: rawBuf } };
|
|
49348
|
+
} else if (!hasReasoning && (delta.role || Object.keys(delta).length === 0 && !finishReason)) {
|
|
49296
49349
|
yield { kind: "meta", chunk: rawBuf, firstRoundOnly: true };
|
|
49297
49350
|
}
|
|
49298
49351
|
}
|
|
@@ -49300,6 +49353,9 @@ function createOpenaiAdapter(requestBody) {
|
|
|
49300
49353
|
emitText(delta) {
|
|
49301
49354
|
return buildContent(delta);
|
|
49302
49355
|
},
|
|
49356
|
+
emitReasoning(delta) {
|
|
49357
|
+
return buildReasoning(delta);
|
|
49358
|
+
},
|
|
49303
49359
|
emitToolCall(call) {
|
|
49304
49360
|
return buildToolCall(call);
|
|
49305
49361
|
},
|