pty-manager 1.2.7 → 1.2.9
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.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +32 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -17
- package/dist/index.mjs.map +1 -1
- package/dist/pty-worker.js +32 -17
- package/package.json +1 -1
package/dist/pty-worker.js
CHANGED
|
@@ -305,6 +305,7 @@ var PTYSession = class extends import_events.EventEmitter {
|
|
|
305
305
|
messageCounter = 0;
|
|
306
306
|
logger;
|
|
307
307
|
sessionRules = [];
|
|
308
|
+
_lastBlockingPromptHash = null;
|
|
308
309
|
id;
|
|
309
310
|
config;
|
|
310
311
|
get status() {
|
|
@@ -444,31 +445,36 @@ var PTYSession = class extends import_events.EventEmitter {
|
|
|
444
445
|
this._lastActivityAt = /* @__PURE__ */ new Date();
|
|
445
446
|
this.outputBuffer += data;
|
|
446
447
|
this.emit("output", data);
|
|
447
|
-
|
|
448
|
-
if (blockingPrompt) {
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
const loginDetection = this.adapter.detectLogin(this.outputBuffer);
|
|
452
|
-
if (loginDetection.required && this._status !== "authenticating") {
|
|
453
|
-
this._status = "authenticating";
|
|
454
|
-
this.emit("login_required", loginDetection.instructions, loginDetection.url);
|
|
455
|
-
this.logger.warn(
|
|
456
|
-
{ sessionId: this.id, loginType: loginDetection.type },
|
|
457
|
-
"Login required"
|
|
458
|
-
);
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
if (this._status === "starting" && this.adapter.detectReady(this.outputBuffer)) {
|
|
448
|
+
if ((this._status === "starting" || this._status === "authenticating") && this.adapter.detectReady(this.outputBuffer)) {
|
|
462
449
|
this._status = "ready";
|
|
450
|
+
this._lastBlockingPromptHash = null;
|
|
463
451
|
this.emit("ready");
|
|
464
452
|
this.logger.info({ sessionId: this.id }, "Session ready");
|
|
465
453
|
}
|
|
454
|
+
if (this._status !== "ready") {
|
|
455
|
+
const blockingPrompt = this.detectAndHandleBlockingPrompt();
|
|
456
|
+
if (blockingPrompt) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const loginDetection = this.adapter.detectLogin(this.outputBuffer);
|
|
460
|
+
if (loginDetection.required && this._status !== "authenticating") {
|
|
461
|
+
this._status = "authenticating";
|
|
462
|
+
this.emit("login_required", loginDetection.instructions, loginDetection.url);
|
|
463
|
+
this.logger.warn(
|
|
464
|
+
{ sessionId: this.id, loginType: loginDetection.type },
|
|
465
|
+
"Login required"
|
|
466
|
+
);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
466
470
|
const exitDetection = this.adapter.detectExit(this.outputBuffer);
|
|
467
471
|
if (exitDetection.exited) {
|
|
468
472
|
this._status = "stopped";
|
|
469
473
|
this.emit("exit", exitDetection.code || 0);
|
|
470
474
|
}
|
|
471
|
-
this.
|
|
475
|
+
if (this._status !== "starting" && this._status !== "authenticating") {
|
|
476
|
+
this.tryParseOutput();
|
|
477
|
+
}
|
|
472
478
|
});
|
|
473
479
|
this.ptyProcess.onExit(({ exitCode, signal }) => {
|
|
474
480
|
this._status = "stopped";
|
|
@@ -480,7 +486,8 @@ var PTYSession = class extends import_events.EventEmitter {
|
|
|
480
486
|
});
|
|
481
487
|
}
|
|
482
488
|
/**
|
|
483
|
-
* Detect blocking prompts and handle them with auto-responses or user notification
|
|
489
|
+
* Detect blocking prompts and handle them with auto-responses or user notification.
|
|
490
|
+
* Deduplicates emissions - won't re-emit the same blocking prompt repeatedly.
|
|
484
491
|
*/
|
|
485
492
|
detectAndHandleBlockingPrompt() {
|
|
486
493
|
const autoHandled = this.tryAutoResponse();
|
|
@@ -490,6 +497,11 @@ var PTYSession = class extends import_events.EventEmitter {
|
|
|
490
497
|
if (this.adapter.detectBlockingPrompt) {
|
|
491
498
|
const detection = this.adapter.detectBlockingPrompt(this.outputBuffer);
|
|
492
499
|
if (detection.detected) {
|
|
500
|
+
const promptHash = `${detection.type}:${detection.prompt || ""}`;
|
|
501
|
+
if (promptHash === this._lastBlockingPromptHash) {
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
this._lastBlockingPromptHash = promptHash;
|
|
493
505
|
const promptInfo = {
|
|
494
506
|
type: detection.type || "unknown",
|
|
495
507
|
prompt: detection.prompt,
|
|
@@ -508,6 +520,7 @@ var PTYSession = class extends import_events.EventEmitter {
|
|
|
508
520
|
"Auto-responding to blocking prompt"
|
|
509
521
|
);
|
|
510
522
|
this.writeRaw(detection.suggestedResponse + "\r");
|
|
523
|
+
this._lastBlockingPromptHash = null;
|
|
511
524
|
this.emit("blocking_prompt", promptInfo, true);
|
|
512
525
|
return true;
|
|
513
526
|
}
|
|
@@ -524,6 +537,8 @@ var PTYSession = class extends import_events.EventEmitter {
|
|
|
524
537
|
);
|
|
525
538
|
this.emit("blocking_prompt", promptInfo, false);
|
|
526
539
|
return true;
|
|
540
|
+
} else {
|
|
541
|
+
this._lastBlockingPromptHash = null;
|
|
527
542
|
}
|
|
528
543
|
}
|
|
529
544
|
return false;
|
package/package.json
CHANGED