@flytedan/flytebot-design-system 0.71.2 → 0.71.4
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 +30 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -13614,6 +13614,10 @@ function useChatEngine(opts) {
|
|
|
13614
13614
|
const stoppedRef = React70.useRef(false);
|
|
13615
13615
|
const abortRef = React70.useRef(null);
|
|
13616
13616
|
const serverCount = React70.useRef(0);
|
|
13617
|
+
const serverIds = React70.useRef(/* @__PURE__ */ new Set());
|
|
13618
|
+
const liveTurn = React70.useRef(null);
|
|
13619
|
+
const lastTurnOwn = React70.useRef(/* @__PURE__ */ new Set());
|
|
13620
|
+
const retired = React70.useRef(/* @__PURE__ */ new Set());
|
|
13617
13621
|
const threadRef = React70.useRef(null);
|
|
13618
13622
|
const mounted = React70.useRef(true);
|
|
13619
13623
|
React70.useEffect(() => {
|
|
@@ -13642,15 +13646,35 @@ function useChatEngine(opts) {
|
|
|
13642
13646
|
const data = await apiAdapter.getThread(id);
|
|
13643
13647
|
const list = [...data && data.messages || []];
|
|
13644
13648
|
serverCount.current = list.length;
|
|
13649
|
+
serverIds.current = new Set(list.map((m) => m.id));
|
|
13645
13650
|
commit(list);
|
|
13646
13651
|
return list;
|
|
13647
13652
|
}, [apiAdapter]);
|
|
13648
13653
|
async function mergeThread() {
|
|
13649
13654
|
const data = await apiAdapter.getThread(threadRef.current);
|
|
13650
13655
|
const server = data && data.messages || [];
|
|
13656
|
+
const turn = liveTurn.current;
|
|
13657
|
+
const ownIds = /* @__PURE__ */ new Set();
|
|
13658
|
+
let progress;
|
|
13659
|
+
if (turn) {
|
|
13660
|
+
for (const m of server) {
|
|
13661
|
+
if (turn.known.has(m.id)) continue;
|
|
13662
|
+
ownIds.add(m.id);
|
|
13663
|
+
if (m.role === "assistant") progress = m;
|
|
13664
|
+
}
|
|
13665
|
+
}
|
|
13651
13666
|
const ids = new Set(server.map((m) => m.id));
|
|
13652
13667
|
serverCount.current = server.length;
|
|
13653
|
-
|
|
13668
|
+
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))];
|
|
13670
|
+
commit(turn && progress ? next.map((m) => m.id === turn.holderId ? foldProgress(m, progress) : m) : next);
|
|
13671
|
+
}
|
|
13672
|
+
function foldProgress(holder, progress) {
|
|
13673
|
+
return Object.assign({}, holder, {
|
|
13674
|
+
steps: progress.steps ?? holder.steps,
|
|
13675
|
+
text: progress.text || holder.text,
|
|
13676
|
+
packet: progress.packet ?? holder.packet
|
|
13677
|
+
});
|
|
13654
13678
|
}
|
|
13655
13679
|
React70.useEffect(() => {
|
|
13656
13680
|
if (!apiAdapter) {
|
|
@@ -13805,6 +13829,7 @@ function useChatEngine(opts) {
|
|
|
13805
13829
|
{ id: userId, role: "user", text: turn.text || null, attachments: turn.attachments, pending: true, timestamp: (/* @__PURE__ */ new Date()).toISOString() },
|
|
13806
13830
|
{ id: holderId, role: "assistant", text: "", streaming: !!apiAdapter.streamMessage, working: !apiAdapter.streamMessage, timestamp: (/* @__PURE__ */ new Date()).toISOString() }
|
|
13807
13831
|
);
|
|
13832
|
+
liveTurn.current = { known: new Set(serverIds.current), holderId };
|
|
13808
13833
|
const ac = typeof AbortController !== "undefined" ? new AbortController() : { abort() {
|
|
13809
13834
|
}, signal: void 0 };
|
|
13810
13835
|
abortRef.current = ac;
|
|
@@ -13860,6 +13885,9 @@ function useChatEngine(opts) {
|
|
|
13860
13885
|
commit(listRef.current.filter((m) => m.id !== holderId));
|
|
13861
13886
|
}
|
|
13862
13887
|
} finally {
|
|
13888
|
+
const known = liveTurn.current.known;
|
|
13889
|
+
lastTurnOwn.current = new Set([...serverIds.current].filter((id2) => !known.has(id2)));
|
|
13890
|
+
liveTurn.current = null;
|
|
13863
13891
|
abortRef.current = null;
|
|
13864
13892
|
busyRef.current = false;
|
|
13865
13893
|
setBusy(false);
|
|
@@ -13920,6 +13948,7 @@ function useChatEngine(opts) {
|
|
|
13920
13948
|
const turn = list[at];
|
|
13921
13949
|
commit(list.slice(0, at));
|
|
13922
13950
|
serverCount.current = Math.max(0, serverCount.current - 1);
|
|
13951
|
+
lastTurnOwn.current.forEach((id) => retired.current.add(id));
|
|
13923
13952
|
stoppedRef.current = false;
|
|
13924
13953
|
queueRef.current = [{ id: uid("q"), text: turn.text || "", attachments: turn.attachments }].concat(queueRef.current);
|
|
13925
13954
|
setQueue(queueRef.current.slice());
|