@snack-kit/porygon 0.7.0 → 0.8.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/README.md +14 -0
- package/dist/index.cjs +30 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +30 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -36,6 +36,7 @@ interface PorygonConfig {
|
|
|
36
36
|
backends?: Record<string, BackendConfig>;
|
|
37
37
|
defaults?: {
|
|
38
38
|
appendSystemPrompt?: string;
|
|
39
|
+
/** 空闲超时(毫秒):进程无任何输出超过此时间则终止,收到输出会重置计时器。默认 120_000 */
|
|
39
40
|
timeoutMs?: number;
|
|
40
41
|
maxTurns?: number;
|
|
41
42
|
/** 禁止使用的工具黑名单(全局默认) */
|
|
@@ -66,6 +67,7 @@ interface PromptRequest {
|
|
|
66
67
|
/** 系统提示词(追加模式) */
|
|
67
68
|
appendSystemPrompt?: string;
|
|
68
69
|
model?: string;
|
|
70
|
+
/** 空闲超时(毫秒):进程无任何输出超过此时间则终止,收到输出会重置计时器。默认 120_000 */
|
|
69
71
|
timeoutMs?: number;
|
|
70
72
|
/**
|
|
71
73
|
* 仅允许使用的工具白名单。
|
|
@@ -532,6 +534,7 @@ interface SpawnOptions {
|
|
|
532
534
|
args: string[];
|
|
533
535
|
cwd?: string;
|
|
534
536
|
env?: Record<string, string>;
|
|
537
|
+
/** 空闲超时(毫秒):进程无任何输出超过此时间则终止,收到输出会重置计时器 */
|
|
535
538
|
timeoutMs?: number;
|
|
536
539
|
/** 写入 stdin 后自动关闭的数据 */
|
|
537
540
|
stdinData?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -36,6 +36,7 @@ interface PorygonConfig {
|
|
|
36
36
|
backends?: Record<string, BackendConfig>;
|
|
37
37
|
defaults?: {
|
|
38
38
|
appendSystemPrompt?: string;
|
|
39
|
+
/** 空闲超时(毫秒):进程无任何输出超过此时间则终止,收到输出会重置计时器。默认 120_000 */
|
|
39
40
|
timeoutMs?: number;
|
|
40
41
|
maxTurns?: number;
|
|
41
42
|
/** 禁止使用的工具黑名单(全局默认) */
|
|
@@ -66,6 +67,7 @@ interface PromptRequest {
|
|
|
66
67
|
/** 系统提示词(追加模式) */
|
|
67
68
|
appendSystemPrompt?: string;
|
|
68
69
|
model?: string;
|
|
70
|
+
/** 空闲超时(毫秒):进程无任何输出超过此时间则终止,收到输出会重置计时器。默认 120_000 */
|
|
69
71
|
timeoutMs?: number;
|
|
70
72
|
/**
|
|
71
73
|
* 仅允许使用的工具白名单。
|
|
@@ -532,6 +534,7 @@ interface SpawnOptions {
|
|
|
532
534
|
args: string[];
|
|
533
535
|
cwd?: string;
|
|
534
536
|
env?: Record<string, string>;
|
|
537
|
+
/** 空闲超时(毫秒):进程无任何输出超过此时间则终止,收到输出会重置计时器 */
|
|
535
538
|
timeoutMs?: number;
|
|
536
539
|
/** 写入 stdin 后自动关闭的数据 */
|
|
537
540
|
stdinData?: string;
|
package/dist/index.js
CHANGED
|
@@ -6,8 +6,8 @@ var DEFAULT_CONFIG = {
|
|
|
6
6
|
defaultBackend: "claude",
|
|
7
7
|
backends: {},
|
|
8
8
|
defaults: {
|
|
9
|
-
timeoutMs:
|
|
10
|
-
//
|
|
9
|
+
timeoutMs: 12e4,
|
|
10
|
+
// 空闲超时:进程无任何输出超过此时间则终止
|
|
11
11
|
maxTurns: 50
|
|
12
12
|
},
|
|
13
13
|
proxy: void 0
|
|
@@ -265,19 +265,25 @@ var EphemeralProcess = class {
|
|
|
265
265
|
this.childProcess = child;
|
|
266
266
|
const stdoutChunks = [];
|
|
267
267
|
const stderrChunks = [];
|
|
268
|
+
let timeoutTimer;
|
|
269
|
+
const resetTimeout = () => {
|
|
270
|
+
if (options.timeoutMs !== void 0 && options.timeoutMs > 0) {
|
|
271
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
272
|
+
timeoutTimer = setTimeout(() => {
|
|
273
|
+
this.terminate();
|
|
274
|
+
reject(new Error(`Process idle timed out after ${options.timeoutMs}ms`));
|
|
275
|
+
}, options.timeoutMs);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
resetTimeout();
|
|
268
279
|
child.stdout?.on("data", (chunk) => {
|
|
269
280
|
stdoutChunks.push(chunk);
|
|
281
|
+
resetTimeout();
|
|
270
282
|
});
|
|
271
283
|
child.stderr?.on("data", (chunk) => {
|
|
272
284
|
stderrChunks.push(chunk);
|
|
285
|
+
resetTimeout();
|
|
273
286
|
});
|
|
274
|
-
let timeoutTimer;
|
|
275
|
-
if (options.timeoutMs !== void 0 && options.timeoutMs > 0) {
|
|
276
|
-
timeoutTimer = setTimeout(() => {
|
|
277
|
-
this.terminate();
|
|
278
|
-
reject(new Error(`Process timed out after ${options.timeoutMs}ms`));
|
|
279
|
-
}, options.timeoutMs);
|
|
280
|
-
}
|
|
281
287
|
const onAbort = () => {
|
|
282
288
|
this.terminate();
|
|
283
289
|
reject(new Error("Process aborted"));
|
|
@@ -326,12 +332,16 @@ var EphemeralProcess = class {
|
|
|
326
332
|
});
|
|
327
333
|
}
|
|
328
334
|
let timeoutTimer;
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
+
const resetTimeout = () => {
|
|
336
|
+
if (options.timeoutMs !== void 0 && options.timeoutMs > 0) {
|
|
337
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
338
|
+
timeoutTimer = setTimeout(() => {
|
|
339
|
+
this.timedOut = true;
|
|
340
|
+
this.terminate();
|
|
341
|
+
}, options.timeoutMs);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
resetTimeout();
|
|
335
345
|
const onAbort = () => {
|
|
336
346
|
this.terminate();
|
|
337
347
|
};
|
|
@@ -339,6 +349,7 @@ var EphemeralProcess = class {
|
|
|
339
349
|
const stderrChunks = [];
|
|
340
350
|
child.stderr?.on("data", (chunk) => {
|
|
341
351
|
stderrChunks.push(chunk);
|
|
352
|
+
resetTimeout();
|
|
342
353
|
});
|
|
343
354
|
let exitCode = null;
|
|
344
355
|
const exitPromise = new Promise((resolve) => {
|
|
@@ -347,6 +358,9 @@ var EphemeralProcess = class {
|
|
|
347
358
|
resolve();
|
|
348
359
|
});
|
|
349
360
|
});
|
|
361
|
+
child.stdout?.on("data", () => {
|
|
362
|
+
resetTimeout();
|
|
363
|
+
});
|
|
350
364
|
const rl = createInterface({ input: child.stdout });
|
|
351
365
|
let yieldedLines = 0;
|
|
352
366
|
try {
|
|
@@ -362,7 +376,7 @@ var EphemeralProcess = class {
|
|
|
362
376
|
);
|
|
363
377
|
}
|
|
364
378
|
if (this.timedOut) {
|
|
365
|
-
throw new Error(`Process timed out after ${options.timeoutMs}ms`);
|
|
379
|
+
throw new Error(`Process idle timed out after ${options.timeoutMs}ms`);
|
|
366
380
|
}
|
|
367
381
|
} finally {
|
|
368
382
|
if (timeoutTimer) clearTimeout(timeoutTimer);
|