billion-context 0.1.37 → 0.1.39

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
@@ -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 === "text") {
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
  );
@@ -49245,8 +49294,10 @@ function createOpenaiAdapter(requestBody) {
49245
49294
  const delta = choice.delta;
49246
49295
  const finishReason = typeof choice.finish_reason === "string" ? choice.finish_reason : void 0;
49247
49296
  if (finishReason) {
49297
+ let yieldedToolCall = false;
49248
49298
  for (const [, tc] of pending) {
49249
49299
  if (tc.name.length > 0 || tc.id.length > 0) {
49300
+ yieldedToolCall = true;
49250
49301
  yield {
49251
49302
  kind: "tool_call",
49252
49303
  name: tc.name,
@@ -49264,9 +49315,15 @@ function createOpenaiAdapter(requestBody) {
49264
49315
  outputTokens: typeof u2?.completion_tokens === "number" ? u2.completion_tokens : void 0,
49265
49316
  cachedTokens: typeof pd?.cached_tokens === "number" ? pd.cached_tokens : void 0
49266
49317
  };
49267
- yield { kind: "done", finishReason };
49318
+ yield {
49319
+ kind: "done",
49320
+ finishReason: yieldedToolCall && finishReason === "stop" ? "tool_calls" : finishReason
49321
+ };
49268
49322
  }
49269
49323
  if (!delta) continue;
49324
+ if (typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0) {
49325
+ yield { kind: "reasoning", delta: delta.reasoning_content, raw: rawBuf };
49326
+ }
49270
49327
  if (delta.tool_calls) {
49271
49328
  const tcs = delta.tool_calls;
49272
49329
  for (const tc of tcs) {
@@ -49290,9 +49347,10 @@ function createOpenaiAdapter(requestBody) {
49290
49347
  }
49291
49348
  continue;
49292
49349
  }
49350
+ const hasReasoning = typeof delta.reasoning_content === "string" && delta.reasoning_content.length > 0;
49293
49351
  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) {
49352
+ yield { kind: "text", delta: delta.content, ...hasReasoning ? {} : { raw: rawBuf } };
49353
+ } else if (!hasReasoning && (delta.role || Object.keys(delta).length === 0 && !finishReason)) {
49296
49354
  yield { kind: "meta", chunk: rawBuf, firstRoundOnly: true };
49297
49355
  }
49298
49356
  }
@@ -49300,6 +49358,9 @@ function createOpenaiAdapter(requestBody) {
49300
49358
  emitText(delta) {
49301
49359
  return buildContent(delta);
49302
49360
  },
49361
+ emitReasoning(delta) {
49362
+ return buildReasoning(delta);
49363
+ },
49303
49364
  emitToolCall(call) {
49304
49365
  return buildToolCall(call);
49305
49366
  },