@corbat-tech/coco 2.8.1 → 2.8.2

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/cli/index.js CHANGED
@@ -1031,6 +1031,7 @@ var init_anthropic = __esm({
1031
1031
  };
1032
1032
  const timeoutInterval = setInterval(checkTimeout, 5e3);
1033
1033
  try {
1034
+ let streamStopReason;
1034
1035
  for await (const event of stream) {
1035
1036
  lastActivityTime = Date.now();
1036
1037
  if (event.type === "content_block_delta") {
@@ -1038,9 +1039,14 @@ var init_anthropic = __esm({
1038
1039
  if (delta.type === "text_delta" && delta.text) {
1039
1040
  yield { type: "text", text: delta.text };
1040
1041
  }
1042
+ } else if (event.type === "message_delta") {
1043
+ const delta = event.delta;
1044
+ if (delta.stop_reason) {
1045
+ streamStopReason = this.mapStopReason(delta.stop_reason);
1046
+ }
1041
1047
  }
1042
1048
  }
1043
- yield { type: "done" };
1049
+ yield { type: "done", stopReason: streamStopReason };
1044
1050
  } finally {
1045
1051
  clearInterval(timeoutInterval);
1046
1052
  }
@@ -1077,9 +1083,15 @@ var init_anthropic = __esm({
1077
1083
  };
1078
1084
  const timeoutInterval = setInterval(checkTimeout, 5e3);
1079
1085
  try {
1086
+ let streamStopReason;
1080
1087
  for await (const event of stream) {
1081
1088
  lastActivityTime = Date.now();
1082
- if (event.type === "content_block_start") {
1089
+ if (event.type === "message_delta") {
1090
+ const delta = event.delta;
1091
+ if (delta.stop_reason) {
1092
+ streamStopReason = this.mapStopReason(delta.stop_reason);
1093
+ }
1094
+ } else if (event.type === "content_block_start") {
1083
1095
  const contentBlock = event.content_block;
1084
1096
  if (contentBlock.type === "tool_use") {
1085
1097
  if (currentToolCall) {
@@ -1150,7 +1162,7 @@ var init_anthropic = __esm({
1150
1162
  }
1151
1163
  }
1152
1164
  }
1153
- yield { type: "done" };
1165
+ yield { type: "done", stopReason: streamStopReason };
1154
1166
  } finally {
1155
1167
  clearInterval(timeoutInterval);
1156
1168
  }
@@ -1653,13 +1665,18 @@ var init_openai = __esm({
1653
1665
  stream: true,
1654
1666
  ...supportsTemp && { temperature: options?.temperature ?? this.config.temperature ?? 0 }
1655
1667
  });
1668
+ let streamStopReason;
1656
1669
  for await (const chunk of stream) {
1657
1670
  const delta = chunk.choices[0]?.delta;
1658
1671
  if (delta?.content) {
1659
1672
  yield { type: "text", text: delta.content };
1660
1673
  }
1674
+ const finishReason = chunk.choices[0]?.finish_reason;
1675
+ if (finishReason) {
1676
+ streamStopReason = this.mapFinishReason(finishReason);
1677
+ }
1661
1678
  }
1662
- yield { type: "done" };
1679
+ yield { type: "done", stopReason: streamStopReason };
1663
1680
  } catch (error) {
1664
1681
  throw this.handleError(error);
1665
1682
  }
@@ -1724,6 +1741,7 @@ var init_openai = __esm({
1724
1741
  return input;
1725
1742
  };
1726
1743
  try {
1744
+ let streamStopReason;
1727
1745
  for await (const chunk of stream) {
1728
1746
  const delta = chunk.choices[0]?.delta;
1729
1747
  if (delta?.content || delta?.tool_calls) {
@@ -1770,6 +1788,9 @@ var init_openai = __esm({
1770
1788
  }
1771
1789
  }
1772
1790
  const finishReason = chunk.choices[0]?.finish_reason;
1791
+ if (finishReason) {
1792
+ streamStopReason = this.mapFinishReason(finishReason);
1793
+ }
1773
1794
  if (finishReason && toolCallBuilders.size > 0) {
1774
1795
  for (const [, builder] of toolCallBuilders) {
1775
1796
  yield {
@@ -1794,7 +1815,7 @@ var init_openai = __esm({
1794
1815
  }
1795
1816
  };
1796
1817
  }
1797
- yield { type: "done" };
1818
+ yield { type: "done", stopReason: streamStopReason };
1798
1819
  } finally {
1799
1820
  clearInterval(timeoutInterval);
1800
1821
  }
@@ -3601,7 +3622,7 @@ var init_codex = __esm({
3601
3622
  }
3602
3623
  }
3603
3624
  }
3604
- yield { type: "done" };
3625
+ yield { type: "done", stopReason: response.stopReason };
3605
3626
  }
3606
3627
  /**
3607
3628
  * Stream a chat response with tool use
@@ -3769,13 +3790,18 @@ var init_gemini = __esm({
3769
3790
  const { history, lastMessage } = this.convertMessages(messages);
3770
3791
  const chat = model.startChat({ history });
3771
3792
  const result = await chat.sendMessageStream(lastMessage);
3793
+ let streamStopReason;
3772
3794
  for await (const chunk of result.stream) {
3773
3795
  const text13 = chunk.text();
3774
3796
  if (text13) {
3775
3797
  yield { type: "text", text: text13 };
3776
3798
  }
3799
+ const finishReason = chunk.candidates?.[0]?.finishReason;
3800
+ if (finishReason) {
3801
+ streamStopReason = this.mapFinishReason(finishReason);
3802
+ }
3777
3803
  }
3778
- yield { type: "done" };
3804
+ yield { type: "done", stopReason: streamStopReason };
3779
3805
  } catch (error) {
3780
3806
  throw this.handleError(error);
3781
3807
  }
@@ -3810,11 +3836,16 @@ var init_gemini = __esm({
3810
3836
  const chat = model.startChat({ history });
3811
3837
  const result = await chat.sendMessageStream(lastMessage);
3812
3838
  const emittedToolCalls = /* @__PURE__ */ new Set();
3839
+ let streamStopReason;
3813
3840
  for await (const chunk of result.stream) {
3814
3841
  const text13 = chunk.text();
3815
3842
  if (text13) {
3816
3843
  yield { type: "text", text: text13 };
3817
3844
  }
3845
+ const finishReason = chunk.candidates?.[0]?.finishReason;
3846
+ if (finishReason) {
3847
+ streamStopReason = this.mapFinishReason(finishReason);
3848
+ }
3818
3849
  const candidate = chunk.candidates?.[0];
3819
3850
  if (candidate?.content?.parts) {
3820
3851
  for (const part of candidate.content.parts) {
@@ -3848,7 +3879,7 @@ var init_gemini = __esm({
3848
3879
  }
3849
3880
  }
3850
3881
  }
3851
- yield { type: "done" };
3882
+ yield { type: "done", stopReason: streamStopReason };
3852
3883
  } catch (error) {
3853
3884
  throw this.handleError(error);
3854
3885
  }
@@ -44640,6 +44671,7 @@ async function executeAgentTurn(session, userMessage, provider, toolRegistry, op
44640
44671
  let responseContent = "";
44641
44672
  const collectedToolCalls = [];
44642
44673
  let thinkingEnded = false;
44674
+ let lastStopReason;
44643
44675
  const toolCallBuilders = /* @__PURE__ */ new Map();
44644
44676
  for await (const chunk of provider.streamWithTools(messages, {
44645
44677
  tools,
@@ -44694,6 +44726,9 @@ async function executeAgentTurn(session, userMessage, provider, toolRegistry, op
44694
44726
  }
44695
44727
  }
44696
44728
  if (chunk.type === "done") {
44729
+ if (chunk.stopReason) {
44730
+ lastStopReason = chunk.stopReason;
44731
+ }
44697
44732
  if (!thinkingEnded) {
44698
44733
  options.onThinkingEnd?.();
44699
44734
  thinkingEnded = true;
@@ -44712,6 +44747,14 @@ async function executeAgentTurn(session, userMessage, provider, toolRegistry, op
44712
44747
  if (options.signal?.aborted) {
44713
44748
  return abortReturn();
44714
44749
  }
44750
+ if (lastStopReason === "max_tokens" && responseContent) {
44751
+ addMessage(session, { role: "assistant", content: responseContent });
44752
+ addMessage(session, {
44753
+ role: "user",
44754
+ content: "[System: Your previous response was cut off due to the output token limit. Continue exactly where you left off.]"
44755
+ });
44756
+ continue;
44757
+ }
44715
44758
  addMessage(session, { role: "assistant", content: responseContent });
44716
44759
  break;
44717
44760
  }
@@ -44933,6 +44976,14 @@ async function executeAgentTurn(session, userMessage, provider, toolRegistry, op
44933
44976
  break;
44934
44977
  }
44935
44978
  }
44979
+ if (iteration >= maxIterations) {
44980
+ const notice = `
44981
+
44982
+ ---
44983
+ _Reached the iteration limit (${maxIterations}). The task may be incomplete. You can say "continue" to resume._`;
44984
+ finalContent += notice;
44985
+ options.onStream?.({ type: "text", text: notice });
44986
+ }
44936
44987
  options.onStream?.({ type: "done" });
44937
44988
  return {
44938
44989
  content: finalContent,