@spteck/react-controls-v2 2.0.12 → 2.0.14
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.mjs
CHANGED
|
@@ -25454,8 +25454,18 @@ function useStreamRequest() {
|
|
|
25454
25454
|
if (line2.startsWith("event:")) {
|
|
25455
25455
|
currentEvent = line2.substring(6).trim();
|
|
25456
25456
|
} else if (line2.startsWith("data:")) {
|
|
25457
|
-
|
|
25457
|
+
const dataContent = line2.substring(5).trim();
|
|
25458
|
+
if (currentData && dataContent) {
|
|
25459
|
+
currentData += "\n" + dataContent;
|
|
25460
|
+
} else {
|
|
25461
|
+
currentData = dataContent;
|
|
25462
|
+
}
|
|
25458
25463
|
} else if (line2 === "") {
|
|
25464
|
+
if (!currentData) {
|
|
25465
|
+
currentEvent = "";
|
|
25466
|
+
currentData = "";
|
|
25467
|
+
continue;
|
|
25468
|
+
}
|
|
25459
25469
|
if (currentEvent === "error") {
|
|
25460
25470
|
try {
|
|
25461
25471
|
const errorData = JSON.parse(currentData);
|
|
@@ -25475,32 +25485,32 @@ function useStreamRequest() {
|
|
|
25475
25485
|
}
|
|
25476
25486
|
} else if (currentEvent === "done") {
|
|
25477
25487
|
done = true;
|
|
25478
|
-
} else if (
|
|
25479
|
-
|
|
25480
|
-
|
|
25481
|
-
|
|
25482
|
-
|
|
25483
|
-
|
|
25484
|
-
|
|
25485
|
-
|
|
25486
|
-
|
|
25487
|
-
|
|
25488
|
-
|
|
25489
|
-
}
|
|
25490
|
-
} else {
|
|
25491
|
-
accumulatedData += currentData;
|
|
25492
|
-
setData(accumulatedData);
|
|
25493
|
-
if (onChunk) {
|
|
25494
|
-
onChunk(currentData);
|
|
25495
|
-
}
|
|
25488
|
+
} else if (currentEvent === "tool") {
|
|
25489
|
+
} else {
|
|
25490
|
+
try {
|
|
25491
|
+
const parsed = JSON.parse(currentData);
|
|
25492
|
+
if (parsed.status && Object.keys(parsed).length === 1) {
|
|
25493
|
+
} else if (parsed.content) {
|
|
25494
|
+
const contentStr = typeof parsed.content === "string" ? parsed.content : JSON.stringify(parsed.content, null, 2);
|
|
25495
|
+
accumulatedData += contentStr;
|
|
25496
|
+
setData(accumulatedData);
|
|
25497
|
+
if (onChunk) {
|
|
25498
|
+
onChunk(contentStr);
|
|
25496
25499
|
}
|
|
25497
|
-
}
|
|
25498
|
-
|
|
25500
|
+
} else {
|
|
25501
|
+
const formattedJson = JSON.stringify(parsed, null, 2);
|
|
25502
|
+
accumulatedData += formattedJson + "\n";
|
|
25499
25503
|
setData(accumulatedData);
|
|
25500
25504
|
if (onChunk) {
|
|
25501
|
-
onChunk(
|
|
25505
|
+
onChunk(formattedJson);
|
|
25502
25506
|
}
|
|
25503
25507
|
}
|
|
25508
|
+
} catch {
|
|
25509
|
+
accumulatedData += currentData + "\n";
|
|
25510
|
+
setData(accumulatedData);
|
|
25511
|
+
if (onChunk) {
|
|
25512
|
+
onChunk(currentData);
|
|
25513
|
+
}
|
|
25504
25514
|
}
|
|
25505
25515
|
}
|
|
25506
25516
|
currentEvent = "";
|
|
@@ -25657,20 +25667,40 @@ const AIAssistant = (props) => {
|
|
|
25657
25667
|
try {
|
|
25658
25668
|
await sendRequest(endpoint, payload, void 0, (chunk) => {
|
|
25659
25669
|
currentResponse += chunk;
|
|
25660
|
-
|
|
25661
|
-
|
|
25662
|
-
|
|
25663
|
-
|
|
25664
|
-
message:
|
|
25665
|
-
|
|
25666
|
-
|
|
25667
|
-
status: status ? status : "received"
|
|
25668
|
-
}
|
|
25669
|
-
});
|
|
25670
|
-
dispatch({
|
|
25671
|
-
type: "SET_IS_RUNNING"
|
|
25672
|
-
});
|
|
25670
|
+
dispatch({
|
|
25671
|
+
type: "UPDATE_LAST_ASSISTANT_MESSAGE",
|
|
25672
|
+
message: {
|
|
25673
|
+
...assistantMessage,
|
|
25674
|
+
message: currentResponse,
|
|
25675
|
+
status: "received"
|
|
25676
|
+
}
|
|
25673
25677
|
});
|
|
25678
|
+
if (onResponse) {
|
|
25679
|
+
onResponse(currentResponse).then((response) => {
|
|
25680
|
+
const { message, status } = response;
|
|
25681
|
+
dispatch({
|
|
25682
|
+
type: "UPDATE_LAST_ASSISTANT_MESSAGE",
|
|
25683
|
+
message: {
|
|
25684
|
+
...assistantMessage,
|
|
25685
|
+
message: message ? message : currentResponse,
|
|
25686
|
+
status: status ? status : "received"
|
|
25687
|
+
}
|
|
25688
|
+
});
|
|
25689
|
+
}).catch((err) => {
|
|
25690
|
+
console.error("onResponse callback error:", err);
|
|
25691
|
+
});
|
|
25692
|
+
}
|
|
25693
|
+
});
|
|
25694
|
+
dispatch({
|
|
25695
|
+
type: "UPDATE_LAST_ASSISTANT_MESSAGE",
|
|
25696
|
+
message: {
|
|
25697
|
+
...assistantMessage,
|
|
25698
|
+
message: currentResponse,
|
|
25699
|
+
status: "received"
|
|
25700
|
+
}
|
|
25701
|
+
});
|
|
25702
|
+
dispatch({
|
|
25703
|
+
type: "SET_IS_RUNNING"
|
|
25674
25704
|
});
|
|
25675
25705
|
} catch (err) {
|
|
25676
25706
|
console.error("Error during streaming:", err);
|