@vettvangur/ai-sdk 0.1.5 → 0.1.9

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.
Files changed (2) hide show
  1. package/dist/index.js +4 -4
  2. 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;
@@ -977,12 +978,11 @@ function bindChat(root, options = {}) {
977
978
  };
978
979
  let content = null;
979
980
  try {
980
- const registered = registryEntries(options.registry)?.renderers.get(event.data.name);
981
- content = registered?.(context) ?? null;
982
981
  const templateName = dataString(event.data.data, "template");
983
982
  const surfaceName = dataString(event.data.data, "surface");
984
- if (!content && templateName) content = root.querySelector(`template[data-template="${CSS.escape(templateName)}"]`)?.content.cloneNode(true) ?? null;
983
+ if (templateName) content = root.querySelector(`template[data-template="${CSS.escape(templateName)}"]`)?.content.cloneNode(true) ?? null;
985
984
  if (!content && surfaceName) content = registryEntries(options.registry)?.surfaces.get(surfaceName)?.(context) ?? root.querySelector(`template[data-ai-surface="${CSS.escape(surfaceName)}"]`)?.content.cloneNode(true) ?? null;
985
+ if (!content) content = registryEntries(options.registry)?.renderers.get(event.data.name)?.(context) ?? null;
986
986
  content ??= renderAnswerCard(root.ownerDocument, event.data.data, labels);
987
987
  } catch (caught) {
988
988
  options.onError?.(caught instanceof Error ? caught : /* @__PURE__ */ new Error("AI chat extension failed"));
@@ -1008,7 +1008,7 @@ function bindChat(root, options = {}) {
1008
1008
  const question = input.value.trim();
1009
1009
  if (!question || session.status !== "idle") return;
1010
1010
  input.value = "";
1011
- chatThread.replaceChildren();
1011
+ for (const node of initialNodes) node.remove();
1012
1012
  appendMarkdown(appendMessage("user"), question);
1013
1013
  activeAssistant = appendMessage("assistant");
1014
1014
  root.setAttribute("aria-busy", "true");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vettvangur/ai-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.9",
4
4
  "description": "Framework-agnostic AI chat client for server-rendered shells",
5
5
  "type": "module",
6
6
  "access": "public",