@kenkaiiii/gg-agent 5.19.6 → 5.20.0
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.cjs +24 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -240,6 +240,9 @@ async function* agentLoop(messages, options) {
|
|
|
240
240
|
const STALL_DELAY_MS = 1e3;
|
|
241
241
|
const MIN_PARTIAL_PRESERVE_CHARS = 200;
|
|
242
242
|
const PARTIAL_CONTINUATION_PROMPT = "[Your previous response was cut off by a connection failure. The text above is what was already delivered to the user. Continue exactly from where it stopped \u2014 do not repeat or restart it.]";
|
|
243
|
+
const MAX_OUTPUT_CONTINUATIONS = 2;
|
|
244
|
+
const MAX_TOKENS_CONTINUATION_PROMPT = "[Your previous response hit the output-token limit and was cut off. The text above is what was already delivered to the user. Continue exactly from where it stopped \u2014 do not repeat or restart it.]";
|
|
245
|
+
let maxTokensContinuations = 0;
|
|
243
246
|
const OVERLOAD_BASE_DELAY_MS = 2e3;
|
|
244
247
|
const OVERLOAD_MAX_DELAY_MS = 3e4;
|
|
245
248
|
const STREAM_FIRST_EVENT_TIMEOUT_MS = 45e3;
|
|
@@ -812,6 +815,27 @@ async function* agentLoop(messages, options) {
|
|
|
812
815
|
consecutivePauses = 0;
|
|
813
816
|
const allToolCalls = extractToolCalls(response.message.content);
|
|
814
817
|
if (response.stopReason !== "tool_use" && allToolCalls.length === 0) {
|
|
818
|
+
if (response.stopReason === "max_tokens") {
|
|
819
|
+
if (maxTokensContinuations < MAX_OUTPUT_CONTINUATIONS) {
|
|
820
|
+
maxTokensContinuations++;
|
|
821
|
+
diag("max_tokens_continuation", {
|
|
822
|
+
attempt: maxTokensContinuations,
|
|
823
|
+
maxAttempts: MAX_OUTPUT_CONTINUATIONS,
|
|
824
|
+
provider: options.provider,
|
|
825
|
+
model: options.model
|
|
826
|
+
});
|
|
827
|
+
yield { type: "truncated", reason: "max_tokens", continued: true };
|
|
828
|
+
messages.push({ role: "user", content: MAX_TOKENS_CONTINUATION_PROMPT });
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
yield { type: "truncated", reason: "max_tokens", continued: false };
|
|
832
|
+
} else if (response.stopReason === "refusal" || response.stopReason === "error") {
|
|
833
|
+
yield {
|
|
834
|
+
type: "truncated",
|
|
835
|
+
reason: response.stopReason === "refusal" ? "refusal" : "provider_error",
|
|
836
|
+
continued: false
|
|
837
|
+
};
|
|
838
|
+
}
|
|
815
839
|
if (options.getSteeringMessages) {
|
|
816
840
|
const steering = await options.getSteeringMessages();
|
|
817
841
|
if (steering && steering.length > 0) {
|