@aipanel/dsh-client 1.2.10 → 1.2.11

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/lib/client.js +28 -5
  2. package/package.json +2 -2
package/lib/client.js CHANGED
@@ -364,6 +364,7 @@ var MSG = WIDGET_MSG;
364
364
  var inject = ["slots", "sessions", "inputTriggers", "conversation"];
365
365
  var SESSION_SETTLE_MS = 400;
366
366
  var FOCUS_OPEN_MAX_ATTEMPTS = 3;
367
+ var FOCUS_INFLIGHT_TIMEOUT_MS = 1e4;
367
368
  function elementContextRef(e) {
368
369
  return JSON.stringify(e);
369
370
  }
@@ -412,6 +413,7 @@ function apply(ctx, config = {}) {
412
413
  let lastCurrent;
413
414
  let settleTimer = null;
414
415
  let targetSessionId;
416
+ let focusDeadline = 0;
415
417
  let pendingFocusId;
416
418
  let focusAttempts = 0;
417
419
  let refreshing = false;
@@ -431,6 +433,10 @@ function apply(ctx, config = {}) {
431
433
  if (!id) return;
432
434
  const snap = sessions.list.getSnapshot();
433
435
  if (!hasBaseline(snap)) return;
436
+ if (Date.now() >= focusDeadline) {
437
+ clearFocusTarget();
438
+ return;
439
+ }
434
440
  pendingFocusId = void 0;
435
441
  focusAttempts = 0;
436
442
  void tryOpenTarget(id);
@@ -439,7 +445,10 @@ function apply(ctx, config = {}) {
439
445
  if (focusAttempts >= FOCUS_OPEN_MAX_ATTEMPTS) return;
440
446
  focusAttempts += 1;
441
447
  const snap = sessions.list.getSnapshot();
442
- if (snap.current === id) return;
448
+ if (snap.current === id) {
449
+ clearFocusTarget();
450
+ return;
451
+ }
443
452
  if (!listContains(snap, id) && !refreshing) {
444
453
  refreshing = true;
445
454
  try {
@@ -459,8 +468,16 @@ function apply(ctx, config = {}) {
459
468
  } catch {
460
469
  }
461
470
  };
462
- const handleFocus = (sessionId) => {
471
+ const clearFocusTarget = () => {
472
+ targetSessionId = void 0;
473
+ focusDeadline = 0;
474
+ pendingFocusId = void 0;
475
+ };
476
+ const handleFocus = (sessionId, source2 = "host") => {
463
477
  targetSessionId = sessionId;
478
+ if (source2 === "host") {
479
+ focusDeadline = Date.now() + FOCUS_INFLIGHT_TIMEOUT_MS;
480
+ }
464
481
  const snap = sessions.list.getSnapshot();
465
482
  if (!hasBaseline(snap)) {
466
483
  pendingFocusId = sessionId;
@@ -487,8 +504,14 @@ function apply(ctx, config = {}) {
487
504
  settleTimer = null;
488
505
  if (sessions.list?.getSnapshot?.()?.current === current) {
489
506
  notifyReady(current);
490
- if (targetSessionId && targetSessionId !== current) {
491
- handleFocus(targetSessionId);
507
+ if (targetSessionId) {
508
+ if (current === targetSessionId) {
509
+ clearFocusTarget();
510
+ } else if (Date.now() < focusDeadline) {
511
+ handleFocus(targetSessionId, "refocus");
512
+ } else {
513
+ clearFocusTarget();
514
+ }
492
515
  }
493
516
  }
494
517
  }, SESSION_SETTLE_MS);
@@ -604,7 +627,7 @@ function apply(ctx, config = {}) {
604
627
  if (data.type === MSG.SET_THEME && typeof data.theme === "string") {
605
628
  applyThemeFromHost(data.theme);
606
629
  } else if (data.type === MSG.FOCUS_SESSION && typeof data.sessionId === "string") {
607
- handleFocus(data.sessionId);
630
+ handleFocus(data.sessionId, "host");
608
631
  } else if (data.type === MSG.INSERT_FILE_PART && data.element) {
609
632
  insertElement(data.element);
610
633
  } else if (data.type === MSG.SELECT_MODE_CHANGE) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aipanel/dsh-client",
3
- "version": "1.2.10",
3
+ "version": "1.2.11",
4
4
  "type": "module",
5
5
  "description": "AIPanel 浏览器侧插件(dsh web Web Client):注册 @aipanel 文件引用 source,选中元素以 file chip 高亮插入并可供模型解析。",
6
6
  "publishConfig": {
@@ -22,7 +22,7 @@
22
22
  "@types/react": "^18.3.0",
23
23
  "esbuild": "^0.25.0",
24
24
  "react": "^18.3.0",
25
- "@aipanel/core": "1.2.10"
25
+ "@aipanel/core": "1.2.11"
26
26
  },
27
27
  "exports": {
28
28
  ".": "./lib/index.js",