@agents24/chat-react 0.1.10 → 0.2.0
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/README.md +6 -2
- package/dist/{chunk-E3TJ3I6G.js → chunk-FFO6KEB4.js} +2 -1
- package/dist/chunk-FFO6KEB4.js.map +1 -0
- package/dist/index.cjs +40 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +40 -26
- package/dist/index.js.map +1 -1
- package/dist/model.d.ts +0 -1
- package/dist/templates/index.cjs +1 -0
- package/dist/templates/index.cjs.map +1 -1
- package/dist/templates/index.js +1 -1
- package/dist/types.d.ts +3 -3
- package/package.json +1 -1
- package/dist/chunk-E3TJ3I6G.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
LatestThreadScrollerProvider,
|
|
8
8
|
LatestThreadScrollerRoot,
|
|
9
9
|
LatestThreadScrollerViewport
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-FFO6KEB4.js";
|
|
11
11
|
import {
|
|
12
12
|
getActiveStreamingTextPartId,
|
|
13
13
|
isActiveStreamingTextPart,
|
|
@@ -223,12 +223,6 @@ var titleFromMessage = (text, files = []) => {
|
|
|
223
223
|
var threadActivityDate = (thread) => String(thread.updated_at || thread.last_activity_at || thread.created_at || (/* @__PURE__ */ new Date()).toISOString());
|
|
224
224
|
var assistantTextFromResponseBlocks = (blocks) => (blocks || []).filter((block) => block.kind === "assistant_text" && typeof block.text === "string").map((block) => String(block.text)).join("\n\n").trim();
|
|
225
225
|
var assistantTextFromParts = (parts) => (parts || []).filter((part) => part.kind === "text").map((part) => part.text).join("\n\n").trim();
|
|
226
|
-
var textFromFinalOutput = (value) => {
|
|
227
|
-
if (typeof value === "string") return value;
|
|
228
|
-
if (!value || typeof value !== "object") return "";
|
|
229
|
-
const record = value;
|
|
230
|
-
return String(record.message || record.text || record.answer || "");
|
|
231
|
-
};
|
|
232
226
|
var displayTextWithoutInlineAttachments = (text, hasAttachments) => {
|
|
233
227
|
if (!hasAttachments) return text;
|
|
234
228
|
const marker = "Attached text file (";
|
|
@@ -275,7 +269,7 @@ var responseBlocksFromTurn = (turn) => {
|
|
|
275
269
|
var assistantTextFromEvents = (events) => {
|
|
276
270
|
const assistantText = latestEventPayloadValue(events, "assistant_output_text");
|
|
277
271
|
if (typeof assistantText === "string" && assistantText.trim()) return assistantText;
|
|
278
|
-
return
|
|
272
|
+
return "";
|
|
279
273
|
};
|
|
280
274
|
var asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
281
275
|
var optionalString = (value) => typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
@@ -459,7 +453,7 @@ var turnToMessages = (turn, activeRunId) => {
|
|
|
459
453
|
attachments
|
|
460
454
|
});
|
|
461
455
|
}
|
|
462
|
-
const assistantText = turn.assistant_output_text || assistantTextFromResponseBlocks(responseBlocks) || assistantTextFromEvents(turn.run_events)
|
|
456
|
+
const assistantText = turn.assistant_output_text || assistantTextFromResponseBlocks(responseBlocks) || assistantTextFromEvents(turn.run_events);
|
|
463
457
|
if (assistantText || responseBlocks.length > 0 || isRunning) {
|
|
464
458
|
const parts = partsFromResponseBlocks(responseBlocks, assistantText);
|
|
465
459
|
messages.push({
|
|
@@ -707,6 +701,7 @@ function useAgents24ChatController({
|
|
|
707
701
|
const activeRunIdRef = useRef(null);
|
|
708
702
|
const reattachedRunIdRef = useRef(null);
|
|
709
703
|
const abortControllerRef = useRef(null);
|
|
704
|
+
const [lifecycleAbortController] = useState(() => new AbortController());
|
|
710
705
|
const streamingContentRef = useRef("");
|
|
711
706
|
const streamingMessageIdRef = useRef(null);
|
|
712
707
|
const reasoningRef = useRef([]);
|
|
@@ -781,15 +776,16 @@ function useAgents24ChatController({
|
|
|
781
776
|
const seq = ++refreshSeqRef.current;
|
|
782
777
|
setIsRefreshingThreads(true);
|
|
783
778
|
try {
|
|
784
|
-
const data = await transport.listThreads();
|
|
779
|
+
const data = await transport.listThreads({ signal: lifecycleAbortController.signal });
|
|
780
|
+
if (lifecycleAbortController.signal.aborted) return;
|
|
785
781
|
if (seq !== refreshSeqRef.current) return;
|
|
786
782
|
const nextThreads = (data.items || []).map((item) => threadSummaryToStored(item));
|
|
787
783
|
storage.setThreads(mergeStoredThreadsForRefresh(storage.listThreads(), nextThreads));
|
|
788
784
|
setThreads(storage.listThreads());
|
|
789
785
|
} finally {
|
|
790
|
-
if (seq === refreshSeqRef.current) setIsRefreshingThreads(false);
|
|
786
|
+
if (!lifecycleAbortController.signal.aborted && seq === refreshSeqRef.current) setIsRefreshingThreads(false);
|
|
791
787
|
}
|
|
792
|
-
}, [storage, transport]);
|
|
788
|
+
}, [lifecycleAbortController, storage, transport]);
|
|
793
789
|
const applyThreadId = useCallback2(
|
|
794
790
|
(threadId, baseMessages) => {
|
|
795
791
|
if (!threadId || activeThreadIdRef.current === threadId) return;
|
|
@@ -944,7 +940,8 @@ function useAgents24ChatController({
|
|
|
944
940
|
const detail = await transport.getThread({
|
|
945
941
|
threadId,
|
|
946
942
|
limit: pageSize,
|
|
947
|
-
includeRunEvents: false
|
|
943
|
+
includeRunEvents: false,
|
|
944
|
+
signal: lifecycleAbortController.signal
|
|
948
945
|
});
|
|
949
946
|
if (activeThreadIdRef.current !== threadId || seq !== requestSeqRef.current) return;
|
|
950
947
|
void onThreadDetailLoaded?.(detail);
|
|
@@ -973,10 +970,10 @@ function useAgents24ChatController({
|
|
|
973
970
|
}
|
|
974
971
|
throw error;
|
|
975
972
|
} finally {
|
|
976
|
-
if (activeThreadIdRef.current === threadId && seq === requestSeqRef.current) setLoadingHistory(false);
|
|
973
|
+
if (!lifecycleAbortController.signal.aborted && activeThreadIdRef.current === threadId && seq === requestSeqRef.current) setLoadingHistory(false);
|
|
977
974
|
}
|
|
978
975
|
},
|
|
979
|
-
[clearMissingThread, onThreadDetailLoaded, pageSize, setLoadingHistory, transport, upsertStoredThread]
|
|
976
|
+
[clearMissingThread, lifecycleAbortController, onThreadDetailLoaded, pageSize, setLoadingHistory, transport, upsertStoredThread]
|
|
980
977
|
);
|
|
981
978
|
const loadOlderTurns = useCallback2(async () => {
|
|
982
979
|
const threadId = activeThreadIdRef.current;
|
|
@@ -989,7 +986,8 @@ function useAgents24ChatController({
|
|
|
989
986
|
threadId,
|
|
990
987
|
limit: pageSize,
|
|
991
988
|
beforeTurnIndex,
|
|
992
|
-
includeRunEvents: false
|
|
989
|
+
includeRunEvents: false,
|
|
990
|
+
signal: lifecycleAbortController.signal
|
|
993
991
|
});
|
|
994
992
|
if (activeThreadIdRef.current !== threadId) return;
|
|
995
993
|
const older = threadDetailToMessages(detail);
|
|
@@ -1009,10 +1007,10 @@ function useAgents24ChatController({
|
|
|
1009
1007
|
}
|
|
1010
1008
|
throw error;
|
|
1011
1009
|
} finally {
|
|
1012
|
-
if (activeThreadIdRef.current === threadId) setIsLoadingOlder(false);
|
|
1010
|
+
if (!lifecycleAbortController.signal.aborted && activeThreadIdRef.current === threadId) setIsLoadingOlder(false);
|
|
1013
1011
|
isLoadingOlderRef.current = false;
|
|
1014
1012
|
}
|
|
1015
|
-
}, [clearMissingThread, pageSize, persistThread, transport]);
|
|
1013
|
+
}, [clearMissingThread, lifecycleAbortController, pageSize, persistThread, transport]);
|
|
1016
1014
|
const handleStreamEvent = useCallback2(
|
|
1017
1015
|
(input) => {
|
|
1018
1016
|
const { mode, event, assistantMessageId, startedAt, streamThreadIdRef, baseMessages } = input;
|
|
@@ -1059,7 +1057,7 @@ function useAgents24ChatController({
|
|
|
1059
1057
|
streamThreadIdRef.current = terminalThreadId;
|
|
1060
1058
|
applyThreadId(terminalThreadId, baseMessages);
|
|
1061
1059
|
}
|
|
1062
|
-
const finalText = String(payload.assistant_output_text ||
|
|
1060
|
+
const finalText = String(payload.assistant_output_text || assistantTextFromResponseBlocks(responseBlocks || []) || streamingContentRef.current || "");
|
|
1063
1061
|
finalizeAssistantMessage({
|
|
1064
1062
|
threadId: streamThreadIdRef.current || activeThreadIdRef.current,
|
|
1065
1063
|
baseMessages: messagesRef.current,
|
|
@@ -1233,8 +1231,19 @@ function useAgents24ChatController({
|
|
|
1233
1231
|
}
|
|
1234
1232
|
}, [finalizeAssistantMessage, lastThinkingDurationMs, setActiveRunIdValue, setReasoningSteps, transport]);
|
|
1235
1233
|
useEffect(() => {
|
|
1236
|
-
refresh().catch(() =>
|
|
1237
|
-
|
|
1234
|
+
refresh().catch((error) => {
|
|
1235
|
+
if (!isAbortError(error) && !lifecycleAbortController.signal.aborted) {
|
|
1236
|
+
setThreads(storage.listThreads());
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
}, [lifecycleAbortController, refresh, storage]);
|
|
1240
|
+
useEffect(() => {
|
|
1241
|
+
return () => {
|
|
1242
|
+
lifecycleAbortController.abort();
|
|
1243
|
+
abortDetachedStream(abortControllerRef.current);
|
|
1244
|
+
abortControllerRef.current = null;
|
|
1245
|
+
};
|
|
1246
|
+
}, [lifecycleAbortController]);
|
|
1238
1247
|
useEffect(() => {
|
|
1239
1248
|
if (!transport.subscribeThreadEvents) return;
|
|
1240
1249
|
let cancelled = false;
|
|
@@ -1531,7 +1540,9 @@ var consumeSseResponse = async (response, onEvent, options = {}) => {
|
|
|
1531
1540
|
let closed = false;
|
|
1532
1541
|
const closeReader = () => {
|
|
1533
1542
|
closed = true;
|
|
1534
|
-
|
|
1543
|
+
queueMicrotask(() => {
|
|
1544
|
+
void reader.cancel().catch(() => {
|
|
1545
|
+
});
|
|
1535
1546
|
});
|
|
1536
1547
|
};
|
|
1537
1548
|
if (options.signal?.aborted) {
|
|
@@ -1621,7 +1632,7 @@ var createFetchChatTransport = ({
|
|
|
1621
1632
|
}
|
|
1622
1633
|
)
|
|
1623
1634
|
});
|
|
1624
|
-
return consumeSseResponse(response, onEvent);
|
|
1635
|
+
return consumeSseResponse(response, onEvent, { signal: input.signal });
|
|
1625
1636
|
},
|
|
1626
1637
|
async attachRun(input, onEvent) {
|
|
1627
1638
|
const response = await fetchImpl(routes.attachRun(input), {
|
|
@@ -1630,7 +1641,7 @@ var createFetchChatTransport = ({
|
|
|
1630
1641
|
headers: streamHeaders(await loadHeaders()),
|
|
1631
1642
|
body: JSON.stringify({})
|
|
1632
1643
|
});
|
|
1633
|
-
return consumeSseResponse(response, onEvent);
|
|
1644
|
+
return consumeSseResponse(response, onEvent, { signal: input.signal });
|
|
1634
1645
|
},
|
|
1635
1646
|
async cancelRun(input) {
|
|
1636
1647
|
const response = await fetchImpl(routes.cancelRun(input), {
|
|
@@ -1657,7 +1668,11 @@ var createFetchChatTransport = ({
|
|
|
1657
1668
|
signal: input.signal,
|
|
1658
1669
|
headers: streamHeaders(await loadHeaders())
|
|
1659
1670
|
});
|
|
1660
|
-
await consumeSseResponse(
|
|
1671
|
+
await consumeSseResponse(
|
|
1672
|
+
response,
|
|
1673
|
+
(event) => onEvent(event),
|
|
1674
|
+
{ signal: input.signal }
|
|
1675
|
+
);
|
|
1661
1676
|
},
|
|
1662
1677
|
async resumeHitl(input) {
|
|
1663
1678
|
if (!routes.resumeRun) throw new ChatTransportError("HITL resume is not configured.", 501);
|
|
@@ -1741,7 +1756,6 @@ export {
|
|
|
1741
1756
|
partsFromResponseBlocks,
|
|
1742
1757
|
reasoningStepsFromParts,
|
|
1743
1758
|
renderChatPart,
|
|
1744
|
-
textFromFinalOutput,
|
|
1745
1759
|
threadActivityDate,
|
|
1746
1760
|
threadDetailToMessages,
|
|
1747
1761
|
threadPaging,
|