@flytedan/flytebot-design-system 0.71.4 → 0.71.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/dist/index.js CHANGED
@@ -12434,6 +12434,7 @@ function useChatEngine(opts) {
12434
12434
  const listRef = React70.useRef([]);
12435
12435
  const queueRef = React70.useRef([]);
12436
12436
  const busyRef = React70.useRef(false);
12437
+ const loadedRef = React70.useRef(false);
12437
12438
  const stoppedRef = React70.useRef(false);
12438
12439
  const abortRef = React70.useRef(null);
12439
12440
  const serverCount = React70.useRef(0);
@@ -12478,18 +12479,24 @@ function useChatEngine(opts) {
12478
12479
  const server = data && data.messages || [];
12479
12480
  const turn = liveTurn.current;
12480
12481
  const ownIds = /* @__PURE__ */ new Set();
12481
- let progress;
12482
+ const ownAssistants = [];
12482
12483
  if (turn) {
12483
12484
  for (const m of server) {
12484
12485
  if (turn.known.has(m.id)) continue;
12485
12486
  ownIds.add(m.id);
12486
- if (m.role === "assistant") progress = m;
12487
+ if (m.role === "assistant") ownAssistants.push(m);
12487
12488
  }
12488
12489
  }
12490
+ const progress = ownAssistants.pop();
12491
+ const cards = ownAssistants;
12489
12492
  const ids = new Set(server.map((m) => m.id));
12490
12493
  serverCount.current = server.length;
12491
12494
  serverIds.current = ids;
12492
- const next = [...server.filter((m) => !ownIds.has(m.id) && !retired.current.has(m.id)), ...listRef.current.filter((m) => !ids.has(m.id))];
12495
+ const settled = server.filter((m) => !ownIds.has(m.id) && !retired.current.has(m.id));
12496
+ const local = listRef.current.filter((m) => !ids.has(m.id));
12497
+ const at = local.findIndex((m) => m.id === turn?.holderId);
12498
+ const tail = at < 0 ? [...cards, ...local] : [...local.slice(0, at), ...cards, ...local.slice(at)];
12499
+ const next = [...settled, ...tail];
12493
12500
  commit(turn && progress ? next.map((m) => m.id === turn.holderId ? foldProgress(m, progress) : m) : next);
12494
12501
  }
12495
12502
  function foldProgress(holder, progress) {
@@ -12523,6 +12530,7 @@ function useChatEngine(opts) {
12523
12530
  queueRef.current = [];
12524
12531
  setQueue([]);
12525
12532
  stoppedRef.current = false;
12533
+ loadedRef.current = false;
12526
12534
  setStatus("resolving");
12527
12535
  setFatal(null);
12528
12536
  (async () => {
@@ -12543,12 +12551,14 @@ function useChatEngine(opts) {
12543
12551
  await loadThread(id);
12544
12552
  if (dead) return;
12545
12553
  setStatus("ready");
12554
+ loadedRef.current = true;
12546
12555
  onThreadReady && onThreadReady(id);
12547
12556
  const stored = store.get(STORAGE_PREFIX + id);
12548
12557
  const last = [...visibleMessages(listRef.current)].reverse().find((m) => m.role === "assistant");
12549
12558
  if (stored) resumeJob(stored);
12550
12559
  else if (last && last.working && last.jobId) resumeJob(last.jobId, last.id);
12551
12560
  else if (initialMessage) send(initialMessage);
12561
+ drain();
12552
12562
  } catch (err) {
12553
12563
  if (dead) return;
12554
12564
  if (!fail(err)) {
@@ -12638,6 +12648,7 @@ function useChatEngine(opts) {
12638
12648
  busyRef.current = false;
12639
12649
  setBusy(false);
12640
12650
  setTurnStartedAt(null);
12651
+ drain();
12641
12652
  });
12642
12653
  }
12643
12654
  async function dispatchTurn(turn) {
@@ -12718,7 +12729,7 @@ function useChatEngine(opts) {
12718
12729
  }
12719
12730
  }
12720
12731
  async function drain() {
12721
- if (busyRef.current) return;
12732
+ if (busyRef.current || !loadedRef.current) return;
12722
12733
  while (queueRef.current.length) {
12723
12734
  if (stoppedRef.current) return;
12724
12735
  const turn = queueRef.current[0];