@vettvangur/ai-sdk 0.1.4 → 0.1.7
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.js +20 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -905,6 +905,7 @@ function bindChat(root, options = {}) {
|
|
|
905
905
|
...options.classes
|
|
906
906
|
};
|
|
907
907
|
const initialThread = chatThread.cloneNode(true);
|
|
908
|
+
const initialNodes = Array.from(chatThread.childNodes);
|
|
908
909
|
const endpoint = options.endpoint ?? root.dataset.aiChatEndpoint ?? form.action;
|
|
909
910
|
const header = options.antiforgeryHeader ?? root.dataset.aiChatAntiforgeryHeader;
|
|
910
911
|
const token = options.antiforgeryToken ?? root.dataset.aiChatAntiforgeryToken;
|
|
@@ -940,16 +941,31 @@ function bindChat(root, options = {}) {
|
|
|
940
941
|
chatThread.append(message);
|
|
941
942
|
}
|
|
942
943
|
function tool(id, _name) {
|
|
943
|
-
const element = root.ownerDocument.createElement("
|
|
944
|
+
const element = root.ownerDocument.createElement("div");
|
|
944
945
|
element.dataset.aiChatTool = id;
|
|
945
946
|
element.className = classes.tool;
|
|
946
|
-
|
|
947
|
+
const dot = root.ownerDocument.createElement("span");
|
|
948
|
+
dot.className = "ai-chat__tool-dot";
|
|
949
|
+
dot.setAttribute("aria-hidden", "true");
|
|
950
|
+
const label = root.ownerDocument.createElement("span");
|
|
951
|
+
label.append(root.ownerDocument.createTextNode(labels.toolRunning));
|
|
952
|
+
const status = root.ownerDocument.createElement("span");
|
|
953
|
+
status.className = "ai-chat__tool-status sr-only";
|
|
954
|
+
element.append(dot, label, status);
|
|
947
955
|
activeAssistant?.append(element);
|
|
948
956
|
return element;
|
|
949
957
|
}
|
|
950
958
|
function finishTool(id, failed, interrupted = false) {
|
|
951
959
|
const element = activeAssistant?.querySelector(`[data-ai-chat-tool="${CSS.escape(id)}"]`);
|
|
952
|
-
if (element)
|
|
960
|
+
if (element) {
|
|
961
|
+
element.classList.add("ai-chat__tool--done");
|
|
962
|
+
element.classList.toggle("ai-chat__tool--failed", failed || interrupted);
|
|
963
|
+
const status = element.querySelector(".ai-chat__tool-status");
|
|
964
|
+
if (status) {
|
|
965
|
+
status.textContent = interrupted ? labels.toolInterrupted : failed ? labels.toolFailed : labels.toolComplete;
|
|
966
|
+
status.classList.remove("sr-only");
|
|
967
|
+
}
|
|
968
|
+
}
|
|
953
969
|
}
|
|
954
970
|
function renderResult(event) {
|
|
955
971
|
if (!activeAssistant) return;
|
|
@@ -993,6 +1009,7 @@ function bindChat(root, options = {}) {
|
|
|
993
1009
|
const question = input.value.trim();
|
|
994
1010
|
if (!question || session.status !== "idle") return;
|
|
995
1011
|
input.value = "";
|
|
1012
|
+
for (const node of initialNodes) node.remove();
|
|
996
1013
|
appendMarkdown(appendMessage("user"), question);
|
|
997
1014
|
activeAssistant = appendMessage("assistant");
|
|
998
1015
|
root.setAttribute("aria-busy", "true");
|