picosh 0.2.4 → 0.2.5

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.
Files changed (2) hide show
  1. package/index.js +10 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -49,38 +49,38 @@ 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);
56
57
  if (typeof window !== 'undefined') {
57
58
  window.dispatchEvent(new CustomEvent('picosh-ai-waiting', {detail: {uid, waiting}}));
58
59
  }
59
60
  }
60
61
 
61
62
  exports.middleware = () => (next) => (action) => {
62
- if (action.type && action.type.startsWith('SESSION_')) {
63
- console.log('[picosh] action:', action.type, action.uid ? action.uid.slice(0, 8) : '');
63
+ if (action.type === 'SESSION_ADD' || action.type === 'SESSION_SET_ACTIVE') {
64
+ if (action.uid) activeUid = action.uid;
64
65
  }
65
66
 
66
67
  if (action.type === 'SESSION_ADD_DATA') {
67
- const {uid, data} = action;
68
+ const uid = action.uid || activeUid;
69
+ const {data} = action;
68
70
  const clean = data.replace(ANSI_RE, '');
69
- console.log('[picosh] data:', JSON.stringify(clean.slice(-50)));
70
71
 
71
72
  clearTimeout(timers[uid]);
72
73
  setWaiting(uid, false);
73
74
 
74
75
  timers[uid] = setTimeout(() => {
75
- const matched = PROMPT_RE.test(clean);
76
- console.log('[picosh] prompt match:', matched);
77
- if (matched) setWaiting(uid, true);
76
+ if (PROMPT_RE.test(clean)) setWaiting(uid, true);
78
77
  }, 500);
79
78
  }
80
79
 
81
80
  if (action.type === 'SESSION_PTY_DATA') {
82
- clearTimeout(timers[action.uid]);
83
- setWaiting(action.uid, false);
81
+ const uid = action.uid || activeUid;
82
+ clearTimeout(timers[uid]);
83
+ setWaiting(uid, false);
84
84
  }
85
85
 
86
86
  return next(action);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "picosh",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Hyper plugin: paste clipboard images as file paths",
5
5
  "main": "index.js",
6
6
  "license": "MIT",