@cydm/pie 2.3.0 → 2.4.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/builtin/extensions/ask-user/index.js +3 -3
- package/dist/builtin/extensions/computer-use/index.js +26 -4
- package/dist/builtin/extensions/computer-use/package.json +3 -0
- package/dist/builtin/extensions/computer-use/prebuilt/macos/arm64/pie-computer-use +0 -0
- package/dist/builtin/extensions/computer-use/prebuilt/macos/universal/pie-computer-use.app/Contents/MacOS/pie-computer-use +0 -0
- package/dist/builtin/extensions/computer-use/prebuilt/macos/x64/pie-computer-use +0 -0
- package/dist/builtin/extensions/computer-use/scripts/build-native.mjs +2 -1
- package/dist/builtin/extensions/computer-use/scripts/setup-helper.mjs +2 -2
- package/dist/builtin/extensions/computer-use/scripts/test-native-retention.mjs +204 -0
- package/dist/builtin/extensions/mcp-adapter/index.js +48 -13
- package/dist/builtin/extensions/plan-mode/index.js +3 -3
- package/dist/builtin/extensions/subagent/index.js +4 -4
- package/dist/builtin/extensions/todo/index.js +3 -3
- package/dist/builtin/skills/chrome-devtools-axi/chrome-devtools-axi-runtime.js +1 -1
- package/dist/builtin/skills/chrome-devtools-axi/{cli-F2VCSVL4.js → cli-P4VG6ZZG.js} +48 -8
- package/dist/builtin/skills/skill-creator/scripts/pie_runner.mjs +33 -12
- package/dist/builtin/skills/tui-use/tui-use-daemon.cjs +5 -7
- package/dist/chunks/{chunk-UPPICLVS.js → chunk-FKUEIYFQ.js} +8212 -7366
- package/dist/chunks/{chunk-P3QPJXS7.js → chunk-XVUV3IM2.js} +108 -36
- package/dist/chunks/{chunk-IM43UYVV.js → chunk-YRXXRLMQ.js} +75 -14
- package/dist/chunks/{chunk-QJH6YN2W.js → chunk-ZKHMNEXL.js} +1 -1
- package/dist/chunks/{src-QSP2OPHU.js → src-SXUQ7OY6.js} +2 -2
- package/dist/chunks/{test-stream-CVGWFLSX.js → test-stream-OD3B57AS.js} +1 -1
- package/dist/cli.js +1302 -876
- package/package.json +2 -2
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
createSharedWebSearchTool,
|
|
9
9
|
interpretShellExit,
|
|
10
10
|
requestInteraction
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-FKUEIYFQ.js";
|
|
12
12
|
import {
|
|
13
13
|
getBuiltinDir,
|
|
14
14
|
getConfigDir
|
|
@@ -146,6 +146,43 @@ function truncateStringToBytesFromEnd(str, maxBytes) {
|
|
|
146
146
|
return buf.slice(start).toString("utf-8");
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
// src/capabilities/bash/artifact-sink.ts
|
|
150
|
+
function createArtifactSinkGate(sink, isActive) {
|
|
151
|
+
const sources = /* @__PURE__ */ new Set();
|
|
152
|
+
let drainHandler;
|
|
153
|
+
const onDrain = () => {
|
|
154
|
+
drainHandler = void 0;
|
|
155
|
+
if (!isActive()) return;
|
|
156
|
+
for (const source of sources) {
|
|
157
|
+
if (!source.destroyed) source.resume();
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
registerSource(source) {
|
|
162
|
+
sources.add(source);
|
|
163
|
+
},
|
|
164
|
+
write(chunk) {
|
|
165
|
+
if (sink.write(chunk)) return;
|
|
166
|
+
for (const source of sources) {
|
|
167
|
+
if (!source.destroyed) source.pause();
|
|
168
|
+
}
|
|
169
|
+
if (!drainHandler) {
|
|
170
|
+
drainHandler = onDrain;
|
|
171
|
+
sink.once("drain", onDrain);
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
isBackpressured() {
|
|
175
|
+
return drainHandler !== void 0;
|
|
176
|
+
},
|
|
177
|
+
cleanup() {
|
|
178
|
+
if (drainHandler) {
|
|
179
|
+
sink.removeListener("drain", onDrain);
|
|
180
|
+
drainHandler = void 0;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
149
186
|
// src/capabilities/bash/index.ts
|
|
150
187
|
var bashSchema = Type.Object({
|
|
151
188
|
command: Type.String({ description: "The bash command to execute" }),
|
|
@@ -165,6 +202,7 @@ var bashSchema = Type.Object({
|
|
|
165
202
|
var DEFAULT_TIMEOUT_SECONDS = 120;
|
|
166
203
|
var MAX_GENERIC_TIMEOUT_SECONDS = 120;
|
|
167
204
|
var OUTPUT_DRAIN_TIMEOUT_MS = 1e3;
|
|
205
|
+
var MAX_SHELL_EXIT_DRAIN_MS = 1e4;
|
|
168
206
|
function resolveTimeoutPolicy(requestedTimeout, commandClass) {
|
|
169
207
|
const requestedSeconds = requestedTimeout ?? DEFAULT_TIMEOUT_SECONDS;
|
|
170
208
|
if (requestedSeconds > MAX_GENERIC_TIMEOUT_SECONDS && commandClass !== "package_manager" && commandClass !== "test_or_build") {
|
|
@@ -401,8 +439,9 @@ function formatCommandNonzeroHint(outcome) {
|
|
|
401
439
|
if (outcome.kind !== "command_nonzero") return void 0;
|
|
402
440
|
return `[Command outcome: ${outcome.summary}. The shell tool ran correctly; inspect this as command/test output, not as a tool malfunction.]`;
|
|
403
441
|
}
|
|
404
|
-
function killProcessTree(pid) {
|
|
442
|
+
function killProcessTree(pid, leaderExited) {
|
|
405
443
|
if (process.platform === "win32") {
|
|
444
|
+
if (leaderExited) return;
|
|
406
445
|
try {
|
|
407
446
|
spawn("taskkill", ["/F", "/T", "/PID", String(pid)], {
|
|
408
447
|
stdio: "ignore",
|
|
@@ -411,14 +450,15 @@ function killProcessTree(pid) {
|
|
|
411
450
|
}).unref();
|
|
412
451
|
} catch {
|
|
413
452
|
}
|
|
414
|
-
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
try {
|
|
456
|
+
process.kill(-pid, "SIGKILL");
|
|
457
|
+
} catch {
|
|
458
|
+
if (leaderExited) return;
|
|
415
459
|
try {
|
|
416
|
-
process.kill(
|
|
460
|
+
process.kill(pid, "SIGKILL");
|
|
417
461
|
} catch {
|
|
418
|
-
try {
|
|
419
|
-
process.kill(pid, "SIGKILL");
|
|
420
|
-
} catch {
|
|
421
|
-
}
|
|
422
462
|
}
|
|
423
463
|
}
|
|
424
464
|
}
|
|
@@ -489,6 +529,7 @@ function createBashTool(defaultCwd, options) {
|
|
|
489
529
|
}
|
|
490
530
|
let tempFilePath;
|
|
491
531
|
let tempFileStream;
|
|
532
|
+
let tempFileSink;
|
|
492
533
|
let settled = false;
|
|
493
534
|
let totalBytes = 0;
|
|
494
535
|
const chunks = [];
|
|
@@ -510,6 +551,8 @@ function createBashTool(defaultCwd, options) {
|
|
|
510
551
|
let exitCode = null;
|
|
511
552
|
let exitSignal = null;
|
|
512
553
|
let drainTimer;
|
|
554
|
+
let shellExitAt = 0;
|
|
555
|
+
let lastPipeActivityAt = 0;
|
|
513
556
|
const spawnCommand = buildSpawnCommand(resolvedShell, effectiveCommand);
|
|
514
557
|
const child = (options?.spawnProcess ?? spawn)(spawnCommand.file, spawnCommand.args, {
|
|
515
558
|
shell: spawnCommand.shell,
|
|
@@ -523,12 +566,25 @@ function createBashTool(defaultCwd, options) {
|
|
|
523
566
|
child.stdout?.destroy();
|
|
524
567
|
child.stderr?.destroy();
|
|
525
568
|
};
|
|
569
|
+
const shellExitDrainPending = () => {
|
|
570
|
+
if (tempFileSink?.isBackpressured() === true) return true;
|
|
571
|
+
if (tempFileStream !== void 0 && !tempFileStream.closed && tempFileStream.writableLength > 0) return true;
|
|
572
|
+
return Date.now() - lastPipeActivityAt < OUTPUT_DRAIN_TIMEOUT_MS;
|
|
573
|
+
};
|
|
574
|
+
const onShellExitDrainDeadline = () => {
|
|
575
|
+
if (settled) return;
|
|
576
|
+
if (Date.now() - shellExitAt < MAX_SHELL_EXIT_DRAIN_MS && shellExitDrainPending()) {
|
|
577
|
+
drainTimer = setTimeout(onShellExitDrainDeadline, OUTPUT_DRAIN_TIMEOUT_MS);
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
closePipes();
|
|
581
|
+
child.unref?.();
|
|
582
|
+
void finishExecution(exitCode, exitSignal, true);
|
|
583
|
+
};
|
|
526
584
|
const timeoutId = setTimeout(() => {
|
|
527
585
|
if (settled) return;
|
|
528
586
|
timedOut = true;
|
|
529
|
-
if (child.pid
|
|
530
|
-
killProcessTree(child.pid);
|
|
531
|
-
}
|
|
587
|
+
if (child.pid) killProcessTree(child.pid, processExited);
|
|
532
588
|
closePipes();
|
|
533
589
|
child.unref?.();
|
|
534
590
|
void finishExecution(exitCode, exitSignal, true);
|
|
@@ -536,10 +592,11 @@ function createBashTool(defaultCwd, options) {
|
|
|
536
592
|
const failExecution = (error) => {
|
|
537
593
|
if (settled) return;
|
|
538
594
|
settled = true;
|
|
595
|
+
tempFileSink?.cleanup();
|
|
539
596
|
clearTimeout(timeoutId);
|
|
540
597
|
if (drainTimer) clearTimeout(drainTimer);
|
|
541
598
|
signal?.removeEventListener("abort", onAbort);
|
|
542
|
-
if (child.pid
|
|
599
|
+
if (child.pid) killProcessTree(child.pid, processExited);
|
|
543
600
|
closePipes();
|
|
544
601
|
child.unref?.();
|
|
545
602
|
discardOutputArtifact(tempFilePath, tempFileStream);
|
|
@@ -549,26 +606,40 @@ function createBashTool(defaultCwd, options) {
|
|
|
549
606
|
failExecution(new Error("Operation aborted"));
|
|
550
607
|
};
|
|
551
608
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
609
|
+
const ensureOutputArtifact = () => {
|
|
610
|
+
if (tempFileSink) return tempFileSink;
|
|
611
|
+
const artifact = (options?.createOutputArtifact ?? createPrivateOutputArtifact)();
|
|
612
|
+
tempFilePath = artifact.path;
|
|
613
|
+
tempFileStream = artifact.stream;
|
|
614
|
+
tempFileStream.once("error", failExecution);
|
|
615
|
+
tempFileSink = createArtifactSinkGate(artifact.stream, () => !settled);
|
|
616
|
+
if (child.stdout) tempFileSink.registerSource(child.stdout);
|
|
617
|
+
if (child.stderr) tempFileSink.registerSource(child.stderr);
|
|
618
|
+
return tempFileSink;
|
|
619
|
+
};
|
|
552
620
|
child.stdout?.on("data", (data) => {
|
|
553
621
|
if (settled) return;
|
|
622
|
+
lastPipeActivityAt = Date.now();
|
|
554
623
|
totalBytes += data.length;
|
|
555
624
|
captureHead(data);
|
|
556
625
|
if (totalBytes > DEFAULT_MAX_BYTES && !tempFilePath) {
|
|
557
626
|
try {
|
|
558
|
-
const
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
627
|
+
const sink = ensureOutputArtifact();
|
|
628
|
+
for (const chunk of chunks) {
|
|
629
|
+
sink.write(chunk);
|
|
630
|
+
}
|
|
562
631
|
} catch (error) {
|
|
563
632
|
failExecution(error instanceof Error ? error : new Error(String(error)));
|
|
564
633
|
return;
|
|
565
634
|
}
|
|
566
|
-
for (const chunk of chunks) {
|
|
567
|
-
tempFileStream.write(chunk);
|
|
568
|
-
}
|
|
569
635
|
}
|
|
570
|
-
if (
|
|
571
|
-
|
|
636
|
+
if (tempFileSink) {
|
|
637
|
+
try {
|
|
638
|
+
tempFileSink.write(data);
|
|
639
|
+
} catch (error) {
|
|
640
|
+
failExecution(error instanceof Error ? error : new Error(String(error)));
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
572
643
|
}
|
|
573
644
|
chunks.push(data);
|
|
574
645
|
chunksBytes += data.length;
|
|
@@ -607,24 +678,27 @@ function createBashTool(defaultCwd, options) {
|
|
|
607
678
|
});
|
|
608
679
|
child.stderr?.on("data", (data) => {
|
|
609
680
|
if (settled) return;
|
|
681
|
+
lastPipeActivityAt = Date.now();
|
|
610
682
|
totalBytes += data.length;
|
|
611
683
|
captureHead(data);
|
|
612
684
|
if (totalBytes > DEFAULT_MAX_BYTES && !tempFilePath) {
|
|
613
685
|
try {
|
|
614
|
-
const
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
686
|
+
const sink = ensureOutputArtifact();
|
|
687
|
+
for (const chunk of chunks) {
|
|
688
|
+
sink.write(chunk);
|
|
689
|
+
}
|
|
618
690
|
} catch (error) {
|
|
619
691
|
failExecution(error instanceof Error ? error : new Error(String(error)));
|
|
620
692
|
return;
|
|
621
693
|
}
|
|
622
|
-
for (const chunk of chunks) {
|
|
623
|
-
tempFileStream.write(chunk);
|
|
624
|
-
}
|
|
625
694
|
}
|
|
626
|
-
if (
|
|
627
|
-
|
|
695
|
+
if (tempFileSink) {
|
|
696
|
+
try {
|
|
697
|
+
tempFileSink.write(data);
|
|
698
|
+
} catch (error) {
|
|
699
|
+
failExecution(error instanceof Error ? error : new Error(String(error)));
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
628
702
|
}
|
|
629
703
|
chunks.push(data);
|
|
630
704
|
chunksBytes += data.length;
|
|
@@ -636,6 +710,7 @@ function createBashTool(defaultCwd, options) {
|
|
|
636
710
|
const finishExecution = async (code, sig, stdioIncomplete = false) => {
|
|
637
711
|
if (settled) return;
|
|
638
712
|
settled = true;
|
|
713
|
+
tempFileSink?.cleanup();
|
|
639
714
|
try {
|
|
640
715
|
clearTimeout(timeoutId);
|
|
641
716
|
if (drainTimer) clearTimeout(drainTimer);
|
|
@@ -728,7 +803,7 @@ ${commandNonzeroHint}`;
|
|
|
728
803
|
outputText += "\n[Timeout hint: split custom searches or service polls into smaller bounded steps with progress output, inspect partial results/logs, then make a decision. Avoid repeating long waits. Reserve long timeouts for installs, builds, and tests.]";
|
|
729
804
|
}
|
|
730
805
|
if (stdioIncomplete && !timedOut) {
|
|
731
|
-
outputText += "\n\n[Output capture ended after the command exited because a descendant kept stdio open. Captured output may be incomplete.]";
|
|
806
|
+
outputText += "\n\n[Output capture ended after the command exited because a descendant kept stdio open or the output artifact was still draining (bounded wait). Captured output may be incomplete.]";
|
|
732
807
|
}
|
|
733
808
|
if (timeoutPolicy.capped) {
|
|
734
809
|
outputText += `
|
|
@@ -761,11 +836,8 @@ ${commandNonzeroHint}`;
|
|
|
761
836
|
exitCode = code;
|
|
762
837
|
exitSignal = sig;
|
|
763
838
|
if (settled) return;
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
child.unref?.();
|
|
767
|
-
void finishExecution(code, sig, true);
|
|
768
|
-
}, OUTPUT_DRAIN_TIMEOUT_MS);
|
|
839
|
+
shellExitAt = Date.now();
|
|
840
|
+
drainTimer = setTimeout(onShellExitDrainDeadline, OUTPUT_DRAIN_TIMEOUT_MS);
|
|
769
841
|
});
|
|
770
842
|
child.on("close", (code, sig) => {
|
|
771
843
|
processExited = true;
|
|
@@ -1891,10 +1891,19 @@ var NodeHttpClient = class {
|
|
|
1891
1891
|
reject(e);
|
|
1892
1892
|
});
|
|
1893
1893
|
if (options.signal) {
|
|
1894
|
-
options.signal
|
|
1894
|
+
const requestSignal = options.signal;
|
|
1895
|
+
const onRequestAbort = () => {
|
|
1895
1896
|
logHttp("DEBUG", `Request [${reqTag}] aborted`);
|
|
1896
1897
|
req.destroy(new Error("Request was aborted"));
|
|
1897
|
-
}
|
|
1898
|
+
};
|
|
1899
|
+
if (requestSignal.aborted) {
|
|
1900
|
+
onRequestAbort();
|
|
1901
|
+
} else {
|
|
1902
|
+
requestSignal.addEventListener("abort", onRequestAbort, { once: true });
|
|
1903
|
+
req.once("close", () => {
|
|
1904
|
+
requestSignal.removeEventListener("abort", onRequestAbort);
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1898
1907
|
}
|
|
1899
1908
|
if (!tieredStreamTimeout) {
|
|
1900
1909
|
req.on("timeout", () => {
|
|
@@ -1911,7 +1920,7 @@ var NodeHttpClient = class {
|
|
|
1911
1920
|
req.destroy(requestTimeoutError);
|
|
1912
1921
|
}, tieredFirstByteTimeoutMs);
|
|
1913
1922
|
tieredFirstByteTimer.unref?.();
|
|
1914
|
-
req.
|
|
1923
|
+
req.once("close", clearTieredFirstByteTimer);
|
|
1915
1924
|
}
|
|
1916
1925
|
if (options.body) {
|
|
1917
1926
|
req.write(options.body);
|
|
@@ -2380,7 +2389,7 @@ var FileSystemGateway = class {
|
|
|
2380
2389
|
fs.renameSync(source, destination);
|
|
2381
2390
|
}
|
|
2382
2391
|
/**
|
|
2383
|
-
* Delete file
|
|
2392
|
+
* Delete a file
|
|
2384
2393
|
*/
|
|
2385
2394
|
deleteFile(path) {
|
|
2386
2395
|
if (!this.allowWrites) {
|
|
@@ -2399,6 +2408,53 @@ var FileSystemGateway = class {
|
|
|
2399
2408
|
fs.unlinkSync(path);
|
|
2400
2409
|
}
|
|
2401
2410
|
}
|
|
2411
|
+
/**
|
|
2412
|
+
* Delete a directory and (by default) everything inside it.
|
|
2413
|
+
*/
|
|
2414
|
+
deleteDirectory(path, options) {
|
|
2415
|
+
if (!this.allowWrites) {
|
|
2416
|
+
throw new Error(`Writes not allowed: ${path}`);
|
|
2417
|
+
}
|
|
2418
|
+
this.validatePath(path, "deleteDirectory");
|
|
2419
|
+
const recursive = options?.recursive ?? true;
|
|
2420
|
+
const platform = detectPlatform();
|
|
2421
|
+
if (platform === "puerts" && typeof CS !== "undefined") {
|
|
2422
|
+
if (CS.System.IO.Directory.Exists(path)) {
|
|
2423
|
+
CS.System.IO.Directory.Delete(path, recursive);
|
|
2424
|
+
}
|
|
2425
|
+
return;
|
|
2426
|
+
}
|
|
2427
|
+
const fs = nodeRequire("fs");
|
|
2428
|
+
fs.rmSync(path, { recursive, force: true });
|
|
2429
|
+
}
|
|
2430
|
+
/**
|
|
2431
|
+
* Move a directory to a new path (destination must not exist).
|
|
2432
|
+
* Unlike renameFile this is directory-aware on every host: Node renames,
|
|
2433
|
+
* PuerTS uses Directory.Move.
|
|
2434
|
+
*/
|
|
2435
|
+
moveDirectory(source, destination) {
|
|
2436
|
+
if (!this.allowWrites) {
|
|
2437
|
+
throw new Error(`Writes not allowed: ${destination}`);
|
|
2438
|
+
}
|
|
2439
|
+
this.validatePath(source, "moveDirectory");
|
|
2440
|
+
this.validatePath(destination, "moveDirectory");
|
|
2441
|
+
const platform = detectPlatform();
|
|
2442
|
+
if (platform === "puerts" && typeof CS !== "undefined") {
|
|
2443
|
+
if (!CS.System.IO.Directory.Exists(source)) {
|
|
2444
|
+
throw new Error(`Directory not found: ${source}`);
|
|
2445
|
+
}
|
|
2446
|
+
if (CS.System.IO.Directory.Exists(destination)) {
|
|
2447
|
+
throw new Error(`Move target already exists: ${destination}`);
|
|
2448
|
+
}
|
|
2449
|
+
CS.System.IO.Directory.Move(source, destination);
|
|
2450
|
+
return;
|
|
2451
|
+
}
|
|
2452
|
+
const fs = nodeRequire("fs");
|
|
2453
|
+
if (fs.existsSync(destination)) {
|
|
2454
|
+
throw new Error(`Move target already exists: ${destination}`);
|
|
2455
|
+
}
|
|
2456
|
+
fs.renameSync(source, destination);
|
|
2457
|
+
}
|
|
2402
2458
|
/**
|
|
2403
2459
|
* Create directory
|
|
2404
2460
|
*/
|
|
@@ -3022,7 +3078,7 @@ function logEmptyAssistantContentError(error, model, options) {
|
|
|
3022
3078
|
var DEFAULT_OPENAI_COMPAT_STREAM_IDLE_TIMEOUT_MS = 2 * 60 * 1e3;
|
|
3023
3079
|
var DEFAULT_OPENAI_COMPAT_FIRST_BYTE_TIMEOUT_MS = 3 * 60 * 1e3;
|
|
3024
3080
|
var OPENAI_COMPAT_FIRST_BYTE_MAX_ESCALATION_STEPS = 3;
|
|
3025
|
-
var
|
|
3081
|
+
var openAICompatFirstByteTimeoutsByEndpoint = /* @__PURE__ */ new Map();
|
|
3026
3082
|
var OPENAI_COMPAT_PROTOCOL_ERROR_CODE = "provider_response_protocol_error";
|
|
3027
3083
|
var OpenAICompatProtocolError = class extends Error {
|
|
3028
3084
|
code = OPENAI_COMPAT_PROTOCOL_ERROR_CODE;
|
|
@@ -3039,15 +3095,20 @@ function getOpenAICompatFirstByteTimeoutBaseMs() {
|
|
|
3039
3095
|
const value = Number(process.env.PIE_OPENAI_COMPAT_FIRST_BYTE_TIMEOUT_MS || "");
|
|
3040
3096
|
return Number.isFinite(value) && value > 0 ? value : DEFAULT_OPENAI_COMPAT_FIRST_BYTE_TIMEOUT_MS;
|
|
3041
3097
|
}
|
|
3042
|
-
function
|
|
3098
|
+
function firstByteEscalationKey(model) {
|
|
3099
|
+
return `${model.provider}|${model.baseUrl}|${model.id}`;
|
|
3100
|
+
}
|
|
3101
|
+
function getOpenAICompatFirstByteTimeoutMs(model) {
|
|
3043
3102
|
const base = getOpenAICompatFirstByteTimeoutBaseMs();
|
|
3044
|
-
|
|
3103
|
+
const consecutive = openAICompatFirstByteTimeoutsByEndpoint.get(firstByteEscalationKey(model)) ?? 0;
|
|
3104
|
+
return base * 2 ** Math.min(consecutive, OPENAI_COMPAT_FIRST_BYTE_MAX_ESCALATION_STEPS);
|
|
3045
3105
|
}
|
|
3046
|
-
function noteOpenAICompatFirstByteTimeout() {
|
|
3047
|
-
|
|
3106
|
+
function noteOpenAICompatFirstByteTimeout(model) {
|
|
3107
|
+
const key = firstByteEscalationKey(model);
|
|
3108
|
+
openAICompatFirstByteTimeoutsByEndpoint.set(key, (openAICompatFirstByteTimeoutsByEndpoint.get(key) ?? 0) + 1);
|
|
3048
3109
|
}
|
|
3049
|
-
function resetOpenAICompatFirstByteTimeoutEscalation() {
|
|
3050
|
-
|
|
3110
|
+
function resetOpenAICompatFirstByteTimeoutEscalation(model) {
|
|
3111
|
+
openAICompatFirstByteTimeoutsByEndpoint.delete(firstByteEscalationKey(model));
|
|
3051
3112
|
}
|
|
3052
3113
|
function normalizeTokenCount(value) {
|
|
3053
3114
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
@@ -3180,7 +3241,7 @@ var streamOpenAICompletions = (model, context, options) => {
|
|
|
3180
3241
|
// providers with hidden reasoning are not killed repeatedly) plus a
|
|
3181
3242
|
// stream-idle budget that any traffic resets.
|
|
3182
3243
|
...options?.timeoutMs !== void 0 ? { timeoutMs: options.timeoutMs } : {
|
|
3183
|
-
firstByteTimeoutMs: getOpenAICompatFirstByteTimeoutMs(),
|
|
3244
|
+
firstByteTimeoutMs: getOpenAICompatFirstByteTimeoutMs(model),
|
|
3184
3245
|
streamIdleTimeoutMs: getOpenAICompatStreamTimeoutMs()
|
|
3185
3246
|
},
|
|
3186
3247
|
// Log attribution only (never sent over the wire).
|
|
@@ -3491,13 +3552,13 @@ var streamOpenAICompletions = (model, context, options) => {
|
|
|
3491
3552
|
throw new Error("An unknown error occurred");
|
|
3492
3553
|
}
|
|
3493
3554
|
assertAssistantHasContent(output);
|
|
3494
|
-
resetOpenAICompatFirstByteTimeoutEscalation();
|
|
3555
|
+
resetOpenAICompatFirstByteTimeoutEscalation(model);
|
|
3495
3556
|
stream.push({ type: "done", reason: output.stopReason, message: output });
|
|
3496
3557
|
stream.end();
|
|
3497
3558
|
} catch (error) {
|
|
3498
3559
|
logEmptyAssistantContentError(error, model, options);
|
|
3499
3560
|
if (error instanceof Error && error.message.includes("Request timeout (first byte)")) {
|
|
3500
|
-
noteOpenAICompatFirstByteTimeout();
|
|
3561
|
+
noteOpenAICompatFirstByteTimeout(model);
|
|
3501
3562
|
}
|
|
3502
3563
|
output.stopReason = options?.signal?.aborted ? "aborted" : "error";
|
|
3503
3564
|
output.errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
EventStream
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YRXXRLMQ.js";
|
|
5
5
|
import "./chunk-XXGYUYXI.js";
|
|
6
6
|
import "./chunk-LZQXQOPJ.js";
|
|
7
7
|
|