@meetsmore-oss/use-ai-client 1.9.4 → 1.9.5
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 +109 -38
- package/dist/bundled.js.map +1 -1
- package/dist/index.js +109 -38
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -276,6 +276,54 @@ function getTextFromContent(content) {
|
|
|
276
276
|
return content.filter((part) => part.type === "text").map((part) => part.text).join("\n");
|
|
277
277
|
}
|
|
278
278
|
|
|
279
|
+
// src/utils/mergeAssistantMessages.ts
|
|
280
|
+
function mergeAssistantMessagesForDisplay(messages) {
|
|
281
|
+
const result = [];
|
|
282
|
+
let pendingTexts = [];
|
|
283
|
+
let pendingIds = [];
|
|
284
|
+
for (const msg of messages) {
|
|
285
|
+
if (msg.role === "tool") {
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (msg.role === "assistant") {
|
|
289
|
+
const text = getTextFromContent(msg.content);
|
|
290
|
+
if (msg.toolCalls && msg.toolCalls.length > 0) {
|
|
291
|
+
pendingIds.push(msg.id);
|
|
292
|
+
if (text) {
|
|
293
|
+
pendingTexts.push(text);
|
|
294
|
+
}
|
|
295
|
+
} else {
|
|
296
|
+
const allTexts = text ? [...pendingTexts, text] : pendingTexts;
|
|
297
|
+
const combined = allTexts.join("\n\n");
|
|
298
|
+
result.push({ ...msg, content: combined || "" });
|
|
299
|
+
pendingTexts = [];
|
|
300
|
+
pendingIds = [];
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
if (pendingTexts.length > 0) {
|
|
304
|
+
result.push({
|
|
305
|
+
id: `merged-${pendingIds.join("-")}`,
|
|
306
|
+
role: "assistant",
|
|
307
|
+
content: pendingTexts.join("\n\n"),
|
|
308
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
309
|
+
});
|
|
310
|
+
pendingTexts = [];
|
|
311
|
+
pendingIds = [];
|
|
312
|
+
}
|
|
313
|
+
result.push(msg);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (pendingTexts.length > 0) {
|
|
317
|
+
result.push({
|
|
318
|
+
id: `merged-${pendingIds.join("-")}`,
|
|
319
|
+
role: "assistant",
|
|
320
|
+
content: pendingTexts.join("\n\n"),
|
|
321
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
|
|
279
327
|
// src/components/MarkdownContent.tsx
|
|
280
328
|
import ReactMarkdown from "react-markdown";
|
|
281
329
|
import remarkGfm from "remark-gfm";
|
|
@@ -1949,11 +1997,7 @@ function UseAIChatPanel({
|
|
|
1949
1997
|
}) {
|
|
1950
1998
|
const strings = useStrings();
|
|
1951
1999
|
const theme = useTheme();
|
|
1952
|
-
const displayMessages = messages
|
|
1953
|
-
if (m.role === "tool") return false;
|
|
1954
|
-
if (m.role === "assistant" && m.toolCalls && m.toolCalls.length > 0 && !getTextFromContent(m.content)) return false;
|
|
1955
|
-
return true;
|
|
1956
|
-
});
|
|
2000
|
+
const displayMessages = mergeAssistantMessagesForDisplay(messages);
|
|
1957
2001
|
const [input, setInput] = useState5("");
|
|
1958
2002
|
const chatHistoryDropdown = useDropdownState();
|
|
1959
2003
|
const agentDropdown = useDropdownState();
|
|
@@ -3226,6 +3270,20 @@ var UseAIClient = class {
|
|
|
3226
3270
|
toolCallId: e.toolCallId
|
|
3227
3271
|
});
|
|
3228
3272
|
}
|
|
3273
|
+
} else if (event.type === EventType.STEP_FINISHED) {
|
|
3274
|
+
if (this._currentAssistantToolCalls.length > 0 && this._currentAssistantMessage) {
|
|
3275
|
+
const assistantMsg = {
|
|
3276
|
+
id: this._currentAssistantMessage.id || uuidv42(),
|
|
3277
|
+
role: "assistant",
|
|
3278
|
+
content: this._currentAssistantMessage.content || "",
|
|
3279
|
+
toolCalls: [...this._currentAssistantToolCalls]
|
|
3280
|
+
};
|
|
3281
|
+
this._messages.push(assistantMsg);
|
|
3282
|
+
this._messages.push(...this._pendingToolResults);
|
|
3283
|
+
this._currentAssistantMessage = { id: uuidv42(), role: "assistant", content: "" };
|
|
3284
|
+
this._currentAssistantToolCalls = [];
|
|
3285
|
+
this._pendingToolResults = [];
|
|
3286
|
+
}
|
|
3229
3287
|
} else if (event.type === EventType.RUN_FINISHED) {
|
|
3230
3288
|
if (this._currentAssistantMessage) {
|
|
3231
3289
|
if (this._currentAssistantToolCalls.length > 0) {
|
|
@@ -3885,13 +3943,8 @@ var LocalStorageChatRepository = class {
|
|
|
3885
3943
|
|
|
3886
3944
|
// src/hooks/useChatManagement.ts
|
|
3887
3945
|
import { useState as useState6, useCallback as useCallback4, useRef as useRef5, useEffect as useEffect5 } from "react";
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
return JSON.stringify(a) === JSON.stringify(b);
|
|
3891
|
-
}
|
|
3892
|
-
function generateChatTitle(message) {
|
|
3893
|
-
return message.length > CHAT_TITLE_MAX_LENGTH ? message.substring(0, CHAT_TITLE_MAX_LENGTH) + "..." : message;
|
|
3894
|
-
}
|
|
3946
|
+
|
|
3947
|
+
// src/utils/messageConversion.ts
|
|
3895
3948
|
function transformMessagesToClientFormat(persistedMessages) {
|
|
3896
3949
|
return persistedMessages.map((msg) => {
|
|
3897
3950
|
const textContent = getTextFromContent(msg.content);
|
|
@@ -3919,6 +3972,39 @@ function transformMessagesToClientFormat(persistedMessages) {
|
|
|
3919
3972
|
}
|
|
3920
3973
|
});
|
|
3921
3974
|
}
|
|
3975
|
+
function extractTurnMessages(messages, startIndex) {
|
|
3976
|
+
const turnSlice = messages.slice(startIndex);
|
|
3977
|
+
const result = [];
|
|
3978
|
+
for (const msg of turnSlice) {
|
|
3979
|
+
if (msg.role === "assistant" && "toolCalls" in msg && msg.toolCalls) {
|
|
3980
|
+
result.push({
|
|
3981
|
+
id: msg.id,
|
|
3982
|
+
role: "assistant",
|
|
3983
|
+
content: typeof msg.content === "string" ? msg.content : "",
|
|
3984
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
3985
|
+
toolCalls: msg.toolCalls
|
|
3986
|
+
});
|
|
3987
|
+
} else if (msg.role === "tool") {
|
|
3988
|
+
result.push({
|
|
3989
|
+
id: msg.id,
|
|
3990
|
+
role: "tool",
|
|
3991
|
+
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content),
|
|
3992
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
3993
|
+
toolCallId: "toolCallId" in msg && msg.toolCallId ? msg.toolCallId : void 0
|
|
3994
|
+
});
|
|
3995
|
+
}
|
|
3996
|
+
}
|
|
3997
|
+
return result;
|
|
3998
|
+
}
|
|
3999
|
+
|
|
4000
|
+
// src/hooks/useChatManagement.ts
|
|
4001
|
+
var CHAT_TITLE_MAX_LENGTH = 50;
|
|
4002
|
+
function deepEquals(a, b) {
|
|
4003
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
4004
|
+
}
|
|
4005
|
+
function generateChatTitle(message) {
|
|
4006
|
+
return message.length > CHAT_TITLE_MAX_LENGTH ? message.substring(0, CHAT_TITLE_MAX_LENGTH) + "..." : message;
|
|
4007
|
+
}
|
|
3922
4008
|
function useChatManagement({
|
|
3923
4009
|
repository,
|
|
3924
4010
|
clientRef,
|
|
@@ -4809,30 +4895,6 @@ import { useState as useState12, useCallback as useCallback10, useRef as useRef1
|
|
|
4809
4895
|
import { EventType as EventType2, ErrorCode, TOOL_APPROVAL_REQUEST } from "@meetsmore-oss/use-ai-core";
|
|
4810
4896
|
|
|
4811
4897
|
// src/hooks/useServerEvents.ts
|
|
4812
|
-
function extractTurnMessages(messages, startIndex) {
|
|
4813
|
-
const turnSlice = messages.slice(startIndex);
|
|
4814
|
-
const result = [];
|
|
4815
|
-
for (const msg of turnSlice) {
|
|
4816
|
-
if (msg.role === "assistant" && "toolCalls" in msg && msg.toolCalls) {
|
|
4817
|
-
result.push({
|
|
4818
|
-
id: msg.id,
|
|
4819
|
-
role: "assistant",
|
|
4820
|
-
content: "",
|
|
4821
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
4822
|
-
toolCalls: msg.toolCalls
|
|
4823
|
-
});
|
|
4824
|
-
} else if (msg.role === "tool") {
|
|
4825
|
-
result.push({
|
|
4826
|
-
id: msg.id,
|
|
4827
|
-
role: "tool",
|
|
4828
|
-
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content),
|
|
4829
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
4830
|
-
toolCallId: "toolCallId" in msg && msg.toolCallId ? msg.toolCallId : void 0
|
|
4831
|
-
});
|
|
4832
|
-
}
|
|
4833
|
-
}
|
|
4834
|
-
return result;
|
|
4835
|
-
}
|
|
4836
4898
|
function useServerEvents({
|
|
4837
4899
|
toolSystem,
|
|
4838
4900
|
saveAIResponse,
|
|
@@ -4842,6 +4904,7 @@ function useServerEvents({
|
|
|
4842
4904
|
const [streamingText, setStreamingText] = useState12("");
|
|
4843
4905
|
const streamingChatIdRef = useRef10(null);
|
|
4844
4906
|
const messageCountAtRunStartRef = useRef10(0);
|
|
4907
|
+
const hasTextFromPriorStepRef = useRef10(false);
|
|
4845
4908
|
const [executingToolRaw, setExecutingTool] = useState12(null);
|
|
4846
4909
|
const executingToolFallbackRef = useRef10(null);
|
|
4847
4910
|
const clearStreamingText = useCallback10(() => {
|
|
@@ -4858,6 +4921,11 @@ function useServerEvents({
|
|
|
4858
4921
|
const strs = stringsRef.current;
|
|
4859
4922
|
if (event.type === EventType2.RUN_STARTED) {
|
|
4860
4923
|
messageCountAtRunStartRef.current = client.messages.length;
|
|
4924
|
+
hasTextFromPriorStepRef.current = false;
|
|
4925
|
+
} else if (event.type === EventType2.TEXT_MESSAGE_START) {
|
|
4926
|
+
if (hasTextFromPriorStepRef.current) {
|
|
4927
|
+
setStreamingText((prev) => prev + "\n\n");
|
|
4928
|
+
}
|
|
4861
4929
|
} else if (event.type === EventType2.TOOL_CALL_START) {
|
|
4862
4930
|
const e = event;
|
|
4863
4931
|
const tool = ts.aggregatedToolsRef.current[e.toolCallName];
|
|
@@ -4894,10 +4962,9 @@ function useServerEvents({
|
|
|
4894
4962
|
ts.handleApprovalRequest(e);
|
|
4895
4963
|
} else if (event.type === EventType2.TEXT_MESSAGE_CONTENT) {
|
|
4896
4964
|
const contentEvent = event;
|
|
4965
|
+
hasTextFromPriorStepRef.current = true;
|
|
4897
4966
|
setStreamingText((prev) => prev + contentEvent.delta);
|
|
4898
4967
|
} else if (event.type === EventType2.TEXT_MESSAGE_END) {
|
|
4899
|
-
setStreamingText("");
|
|
4900
|
-
streamingChatIdRef.current = null;
|
|
4901
4968
|
} else if (event.type === EventType2.RUN_FINISHED) {
|
|
4902
4969
|
const content = client.currentMessageContent;
|
|
4903
4970
|
if (content) {
|
|
@@ -4906,6 +4973,9 @@ function useServerEvents({
|
|
|
4906
4973
|
const turnMessages = extractTurnMessages(client.messages, messageCountAtRunStartRef.current);
|
|
4907
4974
|
saveAIResponseRef.current(content, void 0, traceId, turnMessages);
|
|
4908
4975
|
}
|
|
4976
|
+
setStreamingText("");
|
|
4977
|
+
streamingChatIdRef.current = null;
|
|
4978
|
+
setExecutingTool(null);
|
|
4909
4979
|
setLoading(false);
|
|
4910
4980
|
} else if (event.type === EventType2.RUN_ERROR) {
|
|
4911
4981
|
const errorEvent = event;
|
|
@@ -4915,6 +4985,7 @@ function useServerEvents({
|
|
|
4915
4985
|
saveAIResponseRef.current(userMessage, "error");
|
|
4916
4986
|
setStreamingText("");
|
|
4917
4987
|
streamingChatIdRef.current = null;
|
|
4988
|
+
setExecutingTool(null);
|
|
4918
4989
|
setLoading(false);
|
|
4919
4990
|
}
|
|
4920
4991
|
}, []);
|