picosh 0.2.4 → 0.2.6
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/index.js +15 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -49,10 +49,12 @@ const ANSI_RE = /\x1b\[[0-9;]*[A-Za-z]|\x1b\][^\x07]*\x07|\x07/g;
|
|
|
49
49
|
const PROMPT_RE = /❯\s*\?/;
|
|
50
50
|
const timers = {};
|
|
51
51
|
const waitingState = {};
|
|
52
|
+
let activeUid = null;
|
|
52
53
|
|
|
53
54
|
function setWaiting(uid, waiting) {
|
|
55
|
+
if (!uid) return;
|
|
54
56
|
waitingState[uid] = waiting;
|
|
55
|
-
console.log('[picosh] setWaiting', uid.slice(0, 8), waiting);
|
|
57
|
+
console.log('[picosh] setWaiting uid:', uid.slice(0, 8), 'waiting:', waiting);
|
|
56
58
|
if (typeof window !== 'undefined') {
|
|
57
59
|
window.dispatchEvent(new CustomEvent('picosh-ai-waiting', {detail: {uid, waiting}}));
|
|
58
60
|
}
|
|
@@ -60,27 +62,33 @@ function setWaiting(uid, waiting) {
|
|
|
60
62
|
|
|
61
63
|
exports.middleware = () => (next) => (action) => {
|
|
62
64
|
if (action.type && action.type.startsWith('SESSION_')) {
|
|
63
|
-
console.log('[picosh] action:', action.type, action.uid ? action.uid.slice(0, 8) : '');
|
|
65
|
+
console.log('[picosh] action:', action.type, 'uid:', action.uid ? action.uid.slice(0, 8) : 'none', 'activeUid:', activeUid ? activeUid.slice(0, 8) : 'none');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (action.type === 'SESSION_ADD' || action.type === 'SESSION_SET_ACTIVE') {
|
|
69
|
+
if (action.uid) activeUid = action.uid;
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
if (action.type === 'SESSION_ADD_DATA') {
|
|
67
|
-
const
|
|
73
|
+
const uid = action.uid || activeUid;
|
|
74
|
+
const {data} = action;
|
|
68
75
|
const clean = data.replace(ANSI_RE, '');
|
|
69
|
-
console.log('[picosh] data:', JSON.stringify(clean.slice(-
|
|
76
|
+
console.log('[picosh] SESSION_ADD_DATA uid:', uid ? uid.slice(0, 8) : 'NONE', 'data tail:', JSON.stringify(clean.slice(-40)));
|
|
70
77
|
|
|
71
78
|
clearTimeout(timers[uid]);
|
|
72
79
|
setWaiting(uid, false);
|
|
73
80
|
|
|
74
81
|
timers[uid] = setTimeout(() => {
|
|
75
82
|
const matched = PROMPT_RE.test(clean);
|
|
76
|
-
console.log('[picosh]
|
|
83
|
+
console.log('[picosh] timer fired, PROMPT_RE match:', matched, 'on:', JSON.stringify(clean.slice(-40)));
|
|
77
84
|
if (matched) setWaiting(uid, true);
|
|
78
85
|
}, 500);
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
if (action.type === 'SESSION_PTY_DATA') {
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
const uid = action.uid || activeUid;
|
|
90
|
+
clearTimeout(timers[uid]);
|
|
91
|
+
setWaiting(uid, false);
|
|
84
92
|
}
|
|
85
93
|
|
|
86
94
|
return next(action);
|