@astralform/js 3.0.0 → 3.0.1
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 +16 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -6
- package/dist/index.d.ts +17 -6
- package/dist/index.js +16 -21
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1674,17 +1674,12 @@ var ChatSession = class {
|
|
|
1674
1674
|
]);
|
|
1675
1675
|
this.messages = messagesResult.status === "fulfilled" ? messagesResult.value : [];
|
|
1676
1676
|
if (eventsResult.status === "fulfilled") {
|
|
1677
|
-
|
|
1677
|
+
if (userMessageContent) {
|
|
1678
|
+
this.emit({ type: "user_message", content: userMessageContent });
|
|
1679
|
+
}
|
|
1678
1680
|
for (const ev of eventsResult.value) {
|
|
1679
1681
|
const type = ev.data.type || ev.event;
|
|
1680
1682
|
if (!type || type === "done") continue;
|
|
1681
|
-
if (!userMessageEmitted && type === "message_start") {
|
|
1682
|
-
this.emit({
|
|
1683
|
-
type: "user_message",
|
|
1684
|
-
content: userMessageContent
|
|
1685
|
-
});
|
|
1686
|
-
userMessageEmitted = true;
|
|
1687
|
-
}
|
|
1688
1683
|
const wire = { ...ev.data, type };
|
|
1689
1684
|
try {
|
|
1690
1685
|
await this.dispatchWireEvent(
|
|
@@ -1993,21 +1988,21 @@ function mapSseToChat(raw) {
|
|
|
1993
1988
|
function replayEvents(sseEvents, userMessages, handleEvent, addBlock) {
|
|
1994
1989
|
const userMsgs = userMessages.filter((m) => m.role === "user");
|
|
1995
1990
|
let userIdx = 0;
|
|
1996
|
-
let
|
|
1991
|
+
let currentJobId = null;
|
|
1997
1992
|
for (const raw of sseEvents) {
|
|
1998
1993
|
const type = raw.data.type || raw.event;
|
|
1999
|
-
if (type === "
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
1994
|
+
if (!type || type === "done") continue;
|
|
1995
|
+
const jobId = raw.data.job_id ?? null;
|
|
1996
|
+
if (jobId !== null && jobId !== currentJobId) {
|
|
1997
|
+
currentJobId = jobId;
|
|
1998
|
+
if (userIdx < userMsgs.length) {
|
|
1999
|
+
addBlock({
|
|
2000
|
+
type: "user",
|
|
2001
|
+
id: `replay_user_${userIdx}`,
|
|
2002
|
+
content: userMsgs[userIdx].content
|
|
2003
|
+
});
|
|
2004
|
+
userIdx++;
|
|
2005
|
+
}
|
|
2011
2006
|
}
|
|
2012
2007
|
for (const ce of mapSseToChat(raw)) {
|
|
2013
2008
|
handleEvent(ce);
|