@snack-kit/porygon 0.6.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/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;
@@ -566,6 +569,7 @@ interface PersistentProcessOptions {
566
569
  declare class EphemeralProcess {
567
570
  private childProcess;
568
571
  private aborted;
572
+ private timedOut;
569
573
  /**
570
574
  * 执行命令并收集输出。支持 AbortController 进行取消操作。
571
575
  * @param options 进程启动选项
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;
@@ -566,6 +569,7 @@ interface PersistentProcessOptions {
566
569
  declare class EphemeralProcess {
567
570
  private childProcess;
568
571
  private aborted;
572
+ private timedOut;
569
573
  /**
570
574
  * 执行命令并收集输出。支持 AbortController 进行取消操作。
571
575
  * @param options 进程启动选项
package/dist/index.js CHANGED
@@ -6,8 +6,8 @@ var DEFAULT_CONFIG = {
6
6
  defaultBackend: "claude",
7
7
  backends: {},
8
8
  defaults: {
9
- timeoutMs: 3e5,
10
- // 5 minutes
9
+ timeoutMs: 12e4,
10
+ // 空闲超时:进程无任何输出超过此时间则终止
11
11
  maxTurns: 50
12
12
  },
13
13
  proxy: void 0
@@ -243,6 +243,7 @@ var GRACE_PERIOD_MS = 5e3;
243
243
  var EphemeralProcess = class {
244
244
  childProcess = null;
245
245
  aborted = false;
246
+ timedOut = false;
246
247
  /**
247
248
  * 执行命令并收集输出。支持 AbortController 进行取消操作。
248
249
  * @param options 进程启动选项
@@ -264,19 +265,25 @@ var EphemeralProcess = class {
264
265
  this.childProcess = child;
265
266
  const stdoutChunks = [];
266
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();
267
279
  child.stdout?.on("data", (chunk) => {
268
280
  stdoutChunks.push(chunk);
281
+ resetTimeout();
269
282
  });
270
283
  child.stderr?.on("data", (chunk) => {
271
284
  stderrChunks.push(chunk);
285
+ resetTimeout();
272
286
  });
273
- let timeoutTimer;
274
- if (options.timeoutMs !== void 0 && options.timeoutMs > 0) {
275
- timeoutTimer = setTimeout(() => {
276
- this.terminate();
277
- reject(new Error(`Process timed out after ${options.timeoutMs}ms`));
278
- }, options.timeoutMs);
279
- }
280
287
  const onAbort = () => {
281
288
  this.terminate();
282
289
  reject(new Error("Process aborted"));
@@ -311,6 +318,7 @@ var EphemeralProcess = class {
311
318
  throw new Error("Process aborted before start");
312
319
  }
313
320
  this.aborted = false;
321
+ this.timedOut = false;
314
322
  const useStdin = options.stdinData !== void 0;
315
323
  const child = spawn(options.command, options.args, {
316
324
  cwd: options.cwd,
@@ -324,11 +332,16 @@ var EphemeralProcess = class {
324
332
  });
325
333
  }
326
334
  let timeoutTimer;
327
- if (options.timeoutMs !== void 0 && options.timeoutMs > 0) {
328
- timeoutTimer = setTimeout(() => {
329
- this.terminate();
330
- }, options.timeoutMs);
331
- }
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();
332
345
  const onAbort = () => {
333
346
  this.terminate();
334
347
  };
@@ -336,6 +349,7 @@ var EphemeralProcess = class {
336
349
  const stderrChunks = [];
337
350
  child.stderr?.on("data", (chunk) => {
338
351
  stderrChunks.push(chunk);
352
+ resetTimeout();
339
353
  });
340
354
  let exitCode = null;
341
355
  const exitPromise = new Promise((resolve) => {
@@ -344,6 +358,9 @@ var EphemeralProcess = class {
344
358
  resolve();
345
359
  });
346
360
  });
361
+ child.stdout?.on("data", () => {
362
+ resetTimeout();
363
+ });
347
364
  const rl = createInterface({ input: child.stdout });
348
365
  let yieldedLines = 0;
349
366
  try {
@@ -358,6 +375,9 @@ var EphemeralProcess = class {
358
375
  stderr || `Process exited with code ${exitCode}`
359
376
  );
360
377
  }
378
+ if (this.timedOut) {
379
+ throw new Error(`Process idle timed out after ${options.timeoutMs}ms`);
380
+ }
361
381
  } finally {
362
382
  if (timeoutTimer) clearTimeout(timeoutTimer);
363
383
  abortSignal?.removeEventListener("abort", onAbort);