@aivin-labs/cli 1.0.46 → 1.0.50

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 (38) hide show
  1. package/bin/cli.mjs +16 -5
  2. package/bin/lib/auth.mjs +24 -10
  3. package/bin/lib/projectEnv.mjs +27 -0
  4. package/bin/lib/remote/client.mjs +1412 -1162
  5. package/bin/lib/remote/confirmBarrier.mjs +45 -0
  6. package/bin/lib/remote/constants.mjs +7 -1
  7. package/bin/lib/remote/desktop/aivinIco.mjs +696 -0
  8. package/bin/lib/remote/desktop/castAuth.mjs +74 -69
  9. package/bin/lib/remote/desktop/castConsent.mjs +90 -0
  10. package/bin/lib/remote/desktop/castFileDrop.mjs +24 -0
  11. package/bin/lib/remote/desktop/castInput.mjs +89 -24
  12. package/bin/lib/remote/desktop/castTouchViewers.mjs +26 -0
  13. package/bin/lib/remote/desktop/desktopCast.mjs +28 -2
  14. package/bin/lib/remote/desktop/desktopCastSource.mjs +410 -121
  15. package/bin/lib/remote/desktop/desktopWebRtc.mjs +17 -1
  16. package/bin/lib/remote/desktop/index.mjs +5 -3
  17. package/bin/lib/remote/desktop/traySource.mjs +1289 -1274
  18. package/bin/lib/remote/desktop/webrtcWorker.mjs +3 -0
  19. package/bin/lib/remote/deviceProfile.mjs +2 -0
  20. package/bin/lib/remote/gui/index.mjs +485 -480
  21. package/bin/lib/remote/humanInput.mjs +117 -0
  22. package/bin/lib/remote/idempotency.mjs +19 -2
  23. package/bin/lib/remote/keepAwake.mjs +15 -9
  24. package/bin/lib/remote/localConfirm.mjs +26 -7
  25. package/bin/lib/remote/localPolicy.mjs +15 -2
  26. package/bin/lib/remote/mascot/ask.mjs +23 -4
  27. package/bin/lib/remote/mascot/askHostSource.mjs +10 -4
  28. package/bin/lib/remote/mascot/bot.mjs +5 -1
  29. package/bin/lib/remote/mascot/hostSource.mjs +8 -1
  30. package/bin/lib/remote/mascot/index.mjs +55 -51
  31. package/bin/lib/remote/mascot/rigSource.mjs +28 -2
  32. package/bin/lib/remote/policyCommand.mjs +16 -3
  33. package/bin/lib/remote/processes.mjs +231 -230
  34. package/bin/lib/remote/sandbox.mjs +6 -4
  35. package/bin/lib/remote/scheduler.mjs +164 -124
  36. package/bin/lib/remote/toolHandlers.mjs +3 -2
  37. package/bin/lib/remote/winTree.mjs +29 -0
  38. package/package.json +1 -1
@@ -21,6 +21,9 @@ function hostFiles(dir = CAST_DIR) {
21
21
  return { src, ps1, dll: path.join(dir, `cast-${hash}.dll`) };
22
22
  }
23
23
 
24
+ /** Chờ tiến trình quay tự thoát sau "stop" (nhả phím / nút, thả pipe) trước khi giết. */
25
+ export const STOP_GRACE_MS = 3000;
26
+
24
27
  const RAW_HEADER_BYTES = 12;
25
28
  const MAX_RAW_FRAME_BYTES = 64 * 1024 * 1024;
26
29
 
@@ -143,10 +146,13 @@ export function createDesktopCastManager({ dir = CAST_DIR, spawnImpl = spawn } =
143
146
  onCursor,
144
147
  onCursorShape,
145
148
  onInputFocus,
149
+ onPasteFailed,
150
+ onDropRefused,
146
151
  onClipboard,
147
152
  onSecureDesktop,
148
153
  onCapture,
149
154
  rawPipe = false,
155
+ inputTag = null,
150
156
  onReady,
151
157
  onError,
152
158
  onStop,
@@ -169,6 +175,8 @@ export function createDesktopCastManager({ dir = CAST_DIR, spawnImpl = spawn } =
169
175
  quality,
170
176
  monitor,
171
177
  ...(pipeName ? { pipe: pipeName } : {}),
178
+ // Dấu bí mật của phiên trên thao tác bơm vào (humanInput.mjs) — chuỗi để không mất chính xác qua JSON.
179
+ ...(Number.isSafeInteger(inputTag) && inputTag > 0 ? { input_tag: String(inputTag) } : {}),
172
180
  });
173
181
 
174
182
  const child = spawnImpl('powershell.exe', [
@@ -188,7 +196,10 @@ export function createDesktopCastManager({ dir = CAST_DIR, spawnImpl = spawn } =
188
196
  windowsHide: true,
189
197
  });
190
198
 
199
+ // Ghi vào stdin lúc tiến trình đang thoát (ống đã đóng) báo lỗi bất đồng bộ — không để thành lỗi không ai bắt.
200
+ child.stdin?.on?.('error', () => {});
191
201
  let rl = readline.createInterface({ input: child.stdout });
202
+ let packetSeq = 0;
192
203
 
193
204
  rl.on('line', (line) => {
194
205
  let msg;
@@ -203,6 +214,7 @@ export function createDesktopCastManager({ dir = CAST_DIR, spawnImpl = spawn } =
203
214
  } else if (msg.t === 'frame') {
204
215
  onFrame?.({
205
216
  sessionId: session.sessionId,
217
+ seq: ++packetSeq,
206
218
  image: msg.image,
207
219
  width: msg.width,
208
220
  height: msg.height,
@@ -219,6 +231,7 @@ export function createDesktopCastManager({ dir = CAST_DIR, spawnImpl = spawn } =
219
231
  } else if (msg.t === 'meta') {
220
232
  onMeta?.({
221
233
  sessionId: session.sessionId,
234
+ seq: ++packetSeq,
222
235
  width: msg.width,
223
236
  height: msg.height,
224
237
  screenWidth: msg.screenWidth,
@@ -235,6 +248,10 @@ export function createDesktopCastManager({ dir = CAST_DIR, spawnImpl = spawn } =
235
248
  onCursor?.({ x: msg.x, y: msg.y, visible: msg.visible, shape: msg.shape });
236
249
  } else if (msg.t === 'cursor_shape') {
237
250
  onCursorShape?.({ id: msg.id, png: msg.png, hotX: msg.hotX, hotY: msg.hotY });
251
+ } else if (msg.t === 'drop_refused') {
252
+ onDropRefused?.();
253
+ } else if (msg.t === 'paste_failed') {
254
+ onPasteFailed?.();
238
255
  } else if (msg.t === 'input_focus') {
239
256
  onInputFocus?.({ editable: msg.editable === true });
240
257
  } else if (msg.t === 'clipboard') {
@@ -309,22 +326,31 @@ export function createDesktopCastManager({ dir = CAST_DIR, spawnImpl = spawn } =
309
326
  try { child.stdin.write(JSON.stringify({ op: 'refresh' }) + '\n'); } catch { /* đang đóng */ }
310
327
  }
311
328
 
329
+ /**
330
+ * Dừng: gửi "stop" (tiến trình bỏ thao tác còn xếp hàng, nhả phím / nút đang giữ rồi tự thoát). Chỉ giết khi quá `STOP_GRACE_MS` — giết
331
+ * sớm (trước đây 500 ms) giữa lúc kéo thả / tổ hợp phím là nút chuột, Ctrl / Shift kẹt xuống trên máy (TerminateProcess bỏ qua `finally`).
332
+ */
333
+ let killTimer = null;
334
+ child.on('close', () => clearTimeout(killTimer));
312
335
  function stop() {
313
336
  if (activeSession === session) activeSession = null;
337
+ if (killTimer) return;
314
338
  try {
315
339
  if (child.stdin && !child.stdin.destroyed) {
316
340
  child.stdin.write('stop\n');
341
+ child.stdin.end();
317
342
  }
318
343
  } catch {
319
344
  // bỏ qua
320
345
  }
321
- setTimeout(() => {
346
+ killTimer = setTimeout(() => {
322
347
  try {
323
348
  child.kill();
324
349
  } catch {
325
350
  // bỏ qua
326
351
  }
327
- }, 500);
352
+ }, STOP_GRACE_MS);
353
+ killTimer.unref?.();
328
354
  }
329
355
 
330
356
  const session = {