@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.cjs CHANGED
@@ -13611,6 +13611,7 @@ function useChatEngine(opts) {
13611
13611
  const listRef = React70.useRef([]);
13612
13612
  const queueRef = React70.useRef([]);
13613
13613
  const busyRef = React70.useRef(false);
13614
+ const loadedRef = React70.useRef(false);
13614
13615
  const stoppedRef = React70.useRef(false);
13615
13616
  const abortRef = React70.useRef(null);
13616
13617
  const serverCount = React70.useRef(0);
@@ -13655,18 +13656,24 @@ function useChatEngine(opts) {
13655
13656
  const server = data && data.messages || [];
13656
13657
  const turn = liveTurn.current;
13657
13658
  const ownIds = /* @__PURE__ */ new Set();
13658
- let progress;
13659
+ const ownAssistants = [];
13659
13660
  if (turn) {
13660
13661
  for (const m of server) {
13661
13662
  if (turn.known.has(m.id)) continue;
13662
13663
  ownIds.add(m.id);
13663
- if (m.role === "assistant") progress = m;
13664
+ if (m.role === "assistant") ownAssistants.push(m);
13664
13665
  }
13665
13666
  }
13667
+ const progress = ownAssistants.pop();
13668
+ const cards = ownAssistants;
13666
13669
  const ids = new Set(server.map((m) => m.id));
13667
13670
  serverCount.current = server.length;
13668
13671
  serverIds.current = ids;
13669
- const next = [...server.filter((m) => !ownIds.has(m.id) && !retired.current.has(m.id)), ...listRef.current.filter((m) => !ids.has(m.id))];
13672
+ const settled = server.filter((m) => !ownIds.has(m.id) && !retired.current.has(m.id));
13673
+ const local = listRef.current.filter((m) => !ids.has(m.id));
13674
+ const at = local.findIndex((m) => m.id === turn?.holderId);
13675
+ const tail = at < 0 ? [...cards, ...local] : [...local.slice(0, at), ...cards, ...local.slice(at)];
13676
+ const next = [...settled, ...tail];
13670
13677
  commit(turn && progress ? next.map((m) => m.id === turn.holderId ? foldProgress(m, progress) : m) : next);
13671
13678
  }
13672
13679
  function foldProgress(holder, progress) {
@@ -13700,6 +13707,7 @@ function useChatEngine(opts) {
13700
13707
  queueRef.current = [];
13701
13708
  setQueue([]);
13702
13709
  stoppedRef.current = false;
13710
+ loadedRef.current = false;
13703
13711
  setStatus("resolving");
13704
13712
  setFatal(null);
13705
13713
  (async () => {
@@ -13720,12 +13728,14 @@ function useChatEngine(opts) {
13720
13728
  await loadThread(id);
13721
13729
  if (dead) return;
13722
13730
  setStatus("ready");
13731
+ loadedRef.current = true;
13723
13732
  onThreadReady && onThreadReady(id);
13724
13733
  const stored = store.get(STORAGE_PREFIX + id);
13725
13734
  const last = [...visibleMessages(listRef.current)].reverse().find((m) => m.role === "assistant");
13726
13735
  if (stored) resumeJob(stored);
13727
13736
  else if (last && last.working && last.jobId) resumeJob(last.jobId, last.id);
13728
13737
  else if (initialMessage) send(initialMessage);
13738
+ drain();
13729
13739
  } catch (err) {
13730
13740
  if (dead) return;
13731
13741
  if (!fail(err)) {
@@ -13815,6 +13825,7 @@ function useChatEngine(opts) {
13815
13825
  busyRef.current = false;
13816
13826
  setBusy(false);
13817
13827
  setTurnStartedAt(null);
13828
+ drain();
13818
13829
  });
13819
13830
  }
13820
13831
  async function dispatchTurn(turn) {
@@ -13895,7 +13906,7 @@ function useChatEngine(opts) {
13895
13906
  }
13896
13907
  }
13897
13908
  async function drain() {
13898
- if (busyRef.current) return;
13909
+ if (busyRef.current || !loadedRef.current) return;
13899
13910
  while (queueRef.current.length) {
13900
13911
  if (stoppedRef.current) return;
13901
13912
  const turn = queueRef.current[0];