@meetsmore-oss/use-ai-client 1.9.4 → 1.10.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/dist/bundled.js +110 -39
- package/dist/bundled.js.map +1 -1
- package/dist/index.js +110 -39
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/bundled.js
CHANGED
|
@@ -1553,6 +1553,54 @@ function getTextFromContent(content3) {
|
|
|
1553
1553
|
return content3.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
1554
1554
|
}
|
|
1555
1555
|
|
|
1556
|
+
// src/utils/mergeAssistantMessages.ts
|
|
1557
|
+
function mergeAssistantMessagesForDisplay(messages) {
|
|
1558
|
+
const result = [];
|
|
1559
|
+
let pendingTexts = [];
|
|
1560
|
+
let pendingIds = [];
|
|
1561
|
+
for (const msg of messages) {
|
|
1562
|
+
if (msg.role === "tool") {
|
|
1563
|
+
continue;
|
|
1564
|
+
}
|
|
1565
|
+
if (msg.role === "assistant") {
|
|
1566
|
+
const text5 = getTextFromContent(msg.content);
|
|
1567
|
+
if (msg.toolCalls && msg.toolCalls.length > 0) {
|
|
1568
|
+
pendingIds.push(msg.id);
|
|
1569
|
+
if (text5) {
|
|
1570
|
+
pendingTexts.push(text5);
|
|
1571
|
+
}
|
|
1572
|
+
} else {
|
|
1573
|
+
const allTexts = text5 ? [...pendingTexts, text5] : pendingTexts;
|
|
1574
|
+
const combined = allTexts.join("\n\n");
|
|
1575
|
+
result.push({ ...msg, content: combined || "" });
|
|
1576
|
+
pendingTexts = [];
|
|
1577
|
+
pendingIds = [];
|
|
1578
|
+
}
|
|
1579
|
+
} else {
|
|
1580
|
+
if (pendingTexts.length > 0) {
|
|
1581
|
+
result.push({
|
|
1582
|
+
id: `merged-${pendingIds.join("-")}`,
|
|
1583
|
+
role: "assistant",
|
|
1584
|
+
content: pendingTexts.join("\n\n"),
|
|
1585
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
1586
|
+
});
|
|
1587
|
+
pendingTexts = [];
|
|
1588
|
+
pendingIds = [];
|
|
1589
|
+
}
|
|
1590
|
+
result.push(msg);
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
if (pendingTexts.length > 0) {
|
|
1594
|
+
result.push({
|
|
1595
|
+
id: `merged-${pendingIds.join("-")}`,
|
|
1596
|
+
role: "assistant",
|
|
1597
|
+
content: pendingTexts.join("\n\n"),
|
|
1598
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
return result;
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1556
1604
|
// ../../node_modules/.bun/react-markdown@8.0.7+32264e8fb3466d46/node_modules/react-markdown/lib/uri-transformer.js
|
|
1557
1605
|
var protocols = ["http", "https", "mailto", "tel"];
|
|
1558
1606
|
function uriTransformer(uri) {
|
|
@@ -14451,11 +14499,7 @@ function UseAIChatPanel({
|
|
|
14451
14499
|
}) {
|
|
14452
14500
|
const strings = useStrings();
|
|
14453
14501
|
const theme = useTheme();
|
|
14454
|
-
const displayMessages = messages
|
|
14455
|
-
if (m.role === "tool") return false;
|
|
14456
|
-
if (m.role === "assistant" && m.toolCalls && m.toolCalls.length > 0 && !getTextFromContent(m.content)) return false;
|
|
14457
|
-
return true;
|
|
14458
|
-
});
|
|
14502
|
+
const displayMessages = mergeAssistantMessagesForDisplay(messages);
|
|
14459
14503
|
const [input, setInput] = useState5("");
|
|
14460
14504
|
const chatHistoryDropdown = useDropdownState();
|
|
14461
14505
|
const agentDropdown = useDropdownState();
|
|
@@ -23589,6 +23633,20 @@ var UseAIClient = class {
|
|
|
23589
23633
|
toolCallId: e.toolCallId
|
|
23590
23634
|
});
|
|
23591
23635
|
}
|
|
23636
|
+
} else if (event.type === export_EventType.STEP_FINISHED) {
|
|
23637
|
+
if (this._currentAssistantToolCalls.length > 0 && this._currentAssistantMessage) {
|
|
23638
|
+
const assistantMsg = {
|
|
23639
|
+
id: this._currentAssistantMessage.id || v4_default(),
|
|
23640
|
+
role: "assistant",
|
|
23641
|
+
content: this._currentAssistantMessage.content || "",
|
|
23642
|
+
toolCalls: [...this._currentAssistantToolCalls]
|
|
23643
|
+
};
|
|
23644
|
+
this._messages.push(assistantMsg);
|
|
23645
|
+
this._messages.push(...this._pendingToolResults);
|
|
23646
|
+
this._currentAssistantMessage = { id: v4_default(), role: "assistant", content: "" };
|
|
23647
|
+
this._currentAssistantToolCalls = [];
|
|
23648
|
+
this._pendingToolResults = [];
|
|
23649
|
+
}
|
|
23592
23650
|
} else if (event.type === export_EventType.RUN_FINISHED) {
|
|
23593
23651
|
if (this._currentAssistantMessage) {
|
|
23594
23652
|
if (this._currentAssistantToolCalls.length > 0) {
|
|
@@ -38015,13 +38073,8 @@ var LocalStorageChatRepository = class {
|
|
|
38015
38073
|
|
|
38016
38074
|
// src/hooks/useChatManagement.ts
|
|
38017
38075
|
import { useState as useState6, useCallback as useCallback4, useRef as useRef5, useEffect as useEffect5 } from "react";
|
|
38018
|
-
|
|
38019
|
-
|
|
38020
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
38021
|
-
}
|
|
38022
|
-
function generateChatTitle(message) {
|
|
38023
|
-
return message.length > CHAT_TITLE_MAX_LENGTH ? message.substring(0, CHAT_TITLE_MAX_LENGTH) + "..." : message;
|
|
38024
|
-
}
|
|
38076
|
+
|
|
38077
|
+
// src/utils/messageConversion.ts
|
|
38025
38078
|
function transformMessagesToClientFormat(persistedMessages) {
|
|
38026
38079
|
return persistedMessages.map((msg) => {
|
|
38027
38080
|
const textContent = getTextFromContent(msg.content);
|
|
@@ -38049,6 +38102,39 @@ function transformMessagesToClientFormat(persistedMessages) {
|
|
|
38049
38102
|
}
|
|
38050
38103
|
});
|
|
38051
38104
|
}
|
|
38105
|
+
function extractTurnMessages(messages, startIndex) {
|
|
38106
|
+
const turnSlice = messages.slice(startIndex);
|
|
38107
|
+
const result = [];
|
|
38108
|
+
for (const msg of turnSlice) {
|
|
38109
|
+
if (msg.role === "assistant" && "toolCalls" in msg && msg.toolCalls) {
|
|
38110
|
+
result.push({
|
|
38111
|
+
id: msg.id,
|
|
38112
|
+
role: "assistant",
|
|
38113
|
+
content: typeof msg.content === "string" ? msg.content : "",
|
|
38114
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
38115
|
+
toolCalls: msg.toolCalls
|
|
38116
|
+
});
|
|
38117
|
+
} else if (msg.role === "tool") {
|
|
38118
|
+
result.push({
|
|
38119
|
+
id: msg.id,
|
|
38120
|
+
role: "tool",
|
|
38121
|
+
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content),
|
|
38122
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
38123
|
+
toolCallId: "toolCallId" in msg && msg.toolCallId ? msg.toolCallId : void 0
|
|
38124
|
+
});
|
|
38125
|
+
}
|
|
38126
|
+
}
|
|
38127
|
+
return result;
|
|
38128
|
+
}
|
|
38129
|
+
|
|
38130
|
+
// src/hooks/useChatManagement.ts
|
|
38131
|
+
var CHAT_TITLE_MAX_LENGTH = 50;
|
|
38132
|
+
function deepEquals(a, b) {
|
|
38133
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
38134
|
+
}
|
|
38135
|
+
function generateChatTitle(message) {
|
|
38136
|
+
return message.length > CHAT_TITLE_MAX_LENGTH ? message.substring(0, CHAT_TITLE_MAX_LENGTH) + "..." : message;
|
|
38137
|
+
}
|
|
38052
38138
|
function useChatManagement({
|
|
38053
38139
|
repository,
|
|
38054
38140
|
clientRef,
|
|
@@ -38934,30 +39020,6 @@ function useFeedback({
|
|
|
38934
39020
|
|
|
38935
39021
|
// src/hooks/useServerEvents.ts
|
|
38936
39022
|
import { useState as useState12, useCallback as useCallback10, useRef as useRef10 } from "react";
|
|
38937
|
-
function extractTurnMessages(messages, startIndex) {
|
|
38938
|
-
const turnSlice = messages.slice(startIndex);
|
|
38939
|
-
const result = [];
|
|
38940
|
-
for (const msg of turnSlice) {
|
|
38941
|
-
if (msg.role === "assistant" && "toolCalls" in msg && msg.toolCalls) {
|
|
38942
|
-
result.push({
|
|
38943
|
-
id: msg.id,
|
|
38944
|
-
role: "assistant",
|
|
38945
|
-
content: "",
|
|
38946
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
38947
|
-
toolCalls: msg.toolCalls
|
|
38948
|
-
});
|
|
38949
|
-
} else if (msg.role === "tool") {
|
|
38950
|
-
result.push({
|
|
38951
|
-
id: msg.id,
|
|
38952
|
-
role: "tool",
|
|
38953
|
-
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content),
|
|
38954
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
38955
|
-
toolCallId: "toolCallId" in msg && msg.toolCallId ? msg.toolCallId : void 0
|
|
38956
|
-
});
|
|
38957
|
-
}
|
|
38958
|
-
}
|
|
38959
|
-
return result;
|
|
38960
|
-
}
|
|
38961
39023
|
function useServerEvents({
|
|
38962
39024
|
toolSystem,
|
|
38963
39025
|
saveAIResponse,
|
|
@@ -38967,6 +39029,7 @@ function useServerEvents({
|
|
|
38967
39029
|
const [streamingText, setStreamingText] = useState12("");
|
|
38968
39030
|
const streamingChatIdRef = useRef10(null);
|
|
38969
39031
|
const messageCountAtRunStartRef = useRef10(0);
|
|
39032
|
+
const hasTextFromPriorStepRef = useRef10(false);
|
|
38970
39033
|
const [executingToolRaw, setExecutingTool] = useState12(null);
|
|
38971
39034
|
const executingToolFallbackRef = useRef10(null);
|
|
38972
39035
|
const clearStreamingText = useCallback10(() => {
|
|
@@ -38983,6 +39046,11 @@ function useServerEvents({
|
|
|
38983
39046
|
const strs = stringsRef.current;
|
|
38984
39047
|
if (event.type === export_EventType.RUN_STARTED) {
|
|
38985
39048
|
messageCountAtRunStartRef.current = client.messages.length;
|
|
39049
|
+
hasTextFromPriorStepRef.current = false;
|
|
39050
|
+
} else if (event.type === export_EventType.TEXT_MESSAGE_START) {
|
|
39051
|
+
if (hasTextFromPriorStepRef.current) {
|
|
39052
|
+
setStreamingText((prev) => prev + "\n\n");
|
|
39053
|
+
}
|
|
38986
39054
|
} else if (event.type === export_EventType.TOOL_CALL_START) {
|
|
38987
39055
|
const e = event;
|
|
38988
39056
|
const tool = ts.aggregatedToolsRef.current[e.toolCallName];
|
|
@@ -39019,10 +39087,9 @@ function useServerEvents({
|
|
|
39019
39087
|
ts.handleApprovalRequest(e);
|
|
39020
39088
|
} else if (event.type === export_EventType.TEXT_MESSAGE_CONTENT) {
|
|
39021
39089
|
const contentEvent = event;
|
|
39090
|
+
hasTextFromPriorStepRef.current = true;
|
|
39022
39091
|
setStreamingText((prev) => prev + contentEvent.delta);
|
|
39023
39092
|
} else if (event.type === export_EventType.TEXT_MESSAGE_END) {
|
|
39024
|
-
setStreamingText("");
|
|
39025
|
-
streamingChatIdRef.current = null;
|
|
39026
39093
|
} else if (event.type === export_EventType.RUN_FINISHED) {
|
|
39027
39094
|
const content3 = client.currentMessageContent;
|
|
39028
39095
|
if (content3) {
|
|
@@ -39031,15 +39098,19 @@ function useServerEvents({
|
|
|
39031
39098
|
const turnMessages = extractTurnMessages(client.messages, messageCountAtRunStartRef.current);
|
|
39032
39099
|
saveAIResponseRef.current(content3, void 0, traceId, turnMessages);
|
|
39033
39100
|
}
|
|
39101
|
+
setStreamingText("");
|
|
39102
|
+
streamingChatIdRef.current = null;
|
|
39103
|
+
setExecutingTool(null);
|
|
39034
39104
|
setLoading(false);
|
|
39035
39105
|
} else if (event.type === export_EventType.RUN_ERROR) {
|
|
39036
39106
|
const errorEvent = event;
|
|
39037
39107
|
const errorCode = errorEvent.message;
|
|
39038
39108
|
console.error("[ServerEvents] Run error:", errorCode);
|
|
39039
|
-
const userMessage = strs.errors[errorCode] || strs.errors[ErrorCode.UNKNOWN_ERROR];
|
|
39109
|
+
const userMessage = strs.errors[errorCode] || errorEvent.message || strs.errors[ErrorCode.UNKNOWN_ERROR];
|
|
39040
39110
|
saveAIResponseRef.current(userMessage, "error");
|
|
39041
39111
|
setStreamingText("");
|
|
39042
39112
|
streamingChatIdRef.current = null;
|
|
39113
|
+
setExecutingTool(null);
|
|
39043
39114
|
setLoading(false);
|
|
39044
39115
|
}
|
|
39045
39116
|
}, []);
|