vue-llm 1.10.0 → 1.11.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/README.md CHANGED
@@ -31,7 +31,7 @@
31
31
  - **MCP** — tools of any MCP server (search, files, GitHub, databases) in `useChat` and on the server (`vue-llm/mcp`); users connect their own servers (Notion, Linear…) with OAuth sign-in via `useMCP` / `useMCPServers`, in the browser or through your backend (`createMCPConnector`)
32
32
  - **Vue DevTools** — an LLM tab with every chat, request timeline, time to first token, tool calls and token usage (`vue-llm/devtools`)
33
33
  - **Nuxt module** — auto-imports, components, DevTools in development, server-side runtime config
34
- - **Zero runtime deps** — only `vue` as peer dependency (Vue 3.3+, composables also on Vue 2.7)
34
+ - **Zero runtime deps** — only `vue` as peer dependency (Vue 3.3+ and Vue 2.7, components included)
35
35
  - **TypeScript** — full type safety, exported types
36
36
 
37
37
  ## Quick Start
@@ -9,7 +9,7 @@ type __VLS_Props = {
9
9
  /** Markdown renderer for text parts, see StreamMarkdown */
10
10
  render?: (markdown: string) => string;
11
11
  };
12
- type __VLS_Slots = {
12
+ interface MessagePartsSlots {
13
13
  tool?: (props: {
14
14
  part: ToolCallPart;
15
15
  addResult: (result: unknown) => void;
@@ -17,8 +17,9 @@ type __VLS_Slots = {
17
17
  data?: (props: {
18
18
  part: DataPart;
19
19
  }) => unknown;
20
- };
21
- declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
20
+ }
21
+ type __VLS_Slots = MessagePartsSlots;
22
+ declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
22
23
  "tool-result": (payload: {
23
24
  toolCallId: string;
24
25
  result: unknown;
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),C=/^(?:https?:|mailto:|\/(?!\/)|#|\.\.?\/)/i;function h(s){return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function B(s){const t=s.replace(/\r\n?/g,`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),w=/^(?:https?:|mailto:|\/(?!\/)|#|\.\.?\/)/i;function k(s){return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function B(s){const n=s.replace(/\r\n?/g,`
2
2
  `).split(`
3
- `),l=[];let n=0;for(;n<t.length;){const i=t[n],r=/^\s*(`{3,}|~{3,})\s*([\w+#.-]*)/.exec(i);if(r){const a=[];for(n++;n<t.length&&!t[n].trimStart().startsWith(r[1]);)a.push(t[n]),n++;n++;const u=r[2]?` class="language-${h(r[2])}"`:"";l.push(`<pre><code${u}>${h(a.join(`
4
- `))}</code></pre>`);continue}if(!i.trim()){n++;continue}const m=/^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(i);if(m){const a=m[1].length;l.push(`<h${a}>${p(m[2])}</h${a}>`),n++;continue}if(/^\s*([-*_])(\s*\1){2,}\s*$/.test(i)){l.push("<hr>"),n++;continue}if(/^\s*>/.test(i)){const a=[];for(;n<t.length&&/^\s*>/.test(t[n]);)a.push(t[n].replace(/^\s*>\s?/,"")),n++;l.push(`<blockquote>${B(a.join(`
5
- `))}</blockquote>`);continue}if(v(t,n)){const a=y(t[n]),u=y(t[n+1]).map(c=>c.endsWith(":")?c.startsWith(":")?"center":"right":c.startsWith(":")?"left":"");n+=2;const d=[];for(;n<t.length&&t[n].includes("|")&&t[n].trim();)d.push(y(t[n])),n++;const f=(c,$,g)=>{const E=u[g]?` style="text-align:${u[g]}"`:"";return`<${c}${E}>${p($)}</${c}>`};l.push("<table><thead><tr>"+a.map((c,$)=>f("th",c,$)).join("")+"</tr></thead><tbody>"+d.map(c=>"<tr>"+a.map(($,g)=>f("td",c[g]??"",g)).join("")+"</tr>").join("")+"</tbody></table>");continue}const o=/^\s*([-*+]|\d+[.)])\s+/.exec(i);if(o){const a=/\d/.test(o[1]),u=[];for(;n<t.length;){const c=/^\s*([-*+]|\d+[.)])\s+(.*)$/.exec(t[n]);if(c&&/\d/.test(c[1])===a)u.push(c[2]);else if(t[n].trim()&&/^\s{2,}/.test(t[n])&&u.length>0)u[u.length-1]+=" "+t[n].trim();else break;n++}const d=a?"ol":"ul",f=a&&parseInt(o[1],10)!==1?` start="${parseInt(o[1],10)}"`:"";l.push(`<${d}${f}>${u.map(c=>`<li>${p(c)}</li>`).join("")}</${d}>`);continue}const k=[];for(;n<t.length&&t[n].trim()&&!b(t,n);)k.push(t[n].trim()),n++;l.push(`<p>${k.map(p).join("<br>")}</p>`)}return l.join(`
6
- `)}function p(s){return s.split(/(`+[^`]*`+)/).map((t,l)=>l%2===1?`<code>${h(t.replace(/^`+|`+$/g,""))}</code>`:M(h(t))).join("")}function M(s){return s.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(t,l,n)=>_(n)?`<img src="${n}" alt="${l}">`:l).replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(t,l,n)=>_(n)?`<a href="${n}" target="_blank" rel="noopener noreferrer">${l}</a>`:l).replace(new RegExp("(\\*\\*|__)(?=\\S)(.+?)(?<=\\S)\\1","g"),"<strong>$2</strong>").replace(new RegExp("(?<![\\w*])\\*(?=\\S)(.+?)(?<=\\S)\\*(?![\\w*])","g"),"<em>$1</em>").replace(new RegExp("(?<![\\w_])_(?=\\S)(.+?)(?<=\\S)_(?![\\w_])","g"),"<em>$1</em>").replace(new RegExp("~~(?=\\S)(.+?)(?<=\\S)~~","g"),"<del>$1</del>")}function _(s){const t=s.replace(/&amp;/g,"&").replace(/&#(x?[0-9a-f]+);?/gi,"?");return C.test(t.trim())}function y(s){return s.trim().replace(/^\||\|$/g,"").split("|").map(t=>t.trim())}function v(s,t){return s[t].includes("|")&&t+1<s.length&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(s[t+1])}function b(s,t){const l=s[t];return/^\s*(`{3,}|~{3,})/.test(l)||/^#{1,6}\s/.test(l)||/^\s*>/.test(l)||/^\s*([-*+]|\d+[.)])\s+/.test(l)||/^\s*([-*_])(\s*\1){2,}\s*$/.test(l)||v(s,t)}const x=["innerHTML"],I={key:0,class:"vue-llm-cursor","aria-hidden":"true"},j=e.defineComponent({__name:"StreamMarkdown",props:{content:{},streaming:{type:Boolean},render:{type:Function}},setup(s){const t=s,l=e.computed(()=>(t.render??B)(t.content));return(n,i)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.createElementVNode("div",{class:"vue-llm-markdown",innerHTML:l.value},null,8,x),s.streaming?(e.openBlock(),e.createElementBlock("span",I,"▊")):e.createCommentVNode("",!0)],64))}}),S=(s,t)=>{const l=s.__vccOpts||s;for(const[n,i]of t)l[n]=i;return l},w=S(j,[["__scopeId","data-v-f225ccf4"]]),F=["data-role"],N={key:0,class:"vue-llm-text"},T=["open"],L=["src","alt"],R={key:1,class:"vue-llm-file"},D=["href"],P=e.defineComponent({__name:"MessageParts",props:{message:{},components:{},dataComponents:{},render:{type:Function}},emits:["tool-result"],setup(s,{emit:t}){const l=t,n=(r,m)=>r.type==="tool-call"?r.toolCallId:r.type==="data"&&r.id!==void 0?`data:${r.name}:${r.id}`:m,i=r=>({toolCallId:r.toolCallId,toolName:r.toolName,args:r.args,state:r.state,result:r.result,error:r.error,addResult:m=>l("tool-result",{toolCallId:r.toolCallId,result:m})});return(r,m)=>(e.openBlock(),e.createElementBlock("div",{class:"vue-llm-message","data-role":s.message.role},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.message.parts,(o,k)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:n(o,k)},[o.type==="text"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[s.message.role==="user"?(e.openBlock(),e.createElementBlock("div",N,e.toDisplayString(o.text),1)):(e.openBlock(),e.createBlock(w,{key:1,content:o.text,streaming:o.state==="streaming",render:s.render},null,8,["content","streaming","render"]))],64)):o.type==="reasoning"?(e.openBlock(),e.createElementBlock("details",{key:1,class:"vue-llm-reasoning",open:o.state==="streaming"},[m[0]||(m[0]=e.createElementVNode("summary",null,"Reasoning",-1)),e.createElementVNode("div",null,e.toDisplayString(o.text),1)],8,T)):o.type==="tool-call"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[s.components?.[o.toolName]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(s.components[o.toolName]),e.mergeProps({key:0,ref_for:!0},i(o)),null,16)):e.renderSlot(r.$slots,"tool",{part:o,addResult:i(o).addResult},void 0,!0,1)],64)):o.type==="data"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[s.dataComponents?.[o.name]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(s.dataComponents[o.name]),{key:0,name:o.name,data:o.data},null,8,["name","data"])):e.renderSlot(r.$slots,"data",{part:o},void 0,!0,1)],64)):o.type==="file"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:4},[o.mediaType.startsWith("image/")?(e.openBlock(),e.createElementBlock("img",{key:0,class:"vue-llm-file",src:o.url,alt:o.filename??""},null,8,L)):(e.openBlock(),e.createElementBlock("span",R,e.toDisplayString(o.filename??o.mediaType),1))],64)):o.type==="source"&&/^https?:/i.test(o.url)?(e.openBlock(),e.createElementBlock("a",{key:5,class:"vue-llm-source",href:o.url,target:"_blank",rel:"noopener noreferrer"},e.toDisplayString(o.title??o.url),9,D)):e.createCommentVNode("",!0)],64))),128))],8,F))}}),q=S(P,[["__scopeId","data-v-3868ad67"]]);exports.MessageParts=q;exports.StreamMarkdown=w;exports.escapeHTML=h;exports.renderInline=p;exports.renderMarkdown=B;
3
+ `),l=[];let t=0;for(;t<n.length;){const m=n[t],d=/^\s*(`{3,}|~{3,})\s*([\w+#.-]*)/.exec(m);if(d){const c=[];for(t++;t<n.length&&!n[t].trimStart().startsWith(d[1]);)c.push(n[t]),t++;t++;const u=d[2]?` class="language-${k(d[2])}"`:"";l.push(`<pre><code${u}>${k(c.join(`
4
+ `))}</code></pre>`);continue}if(!m.trim()){t++;continue}const r=/^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(m);if(r){const c=r[1].length;l.push(`<h${c}>${p(r[2])}</h${c}>`),t++;continue}if(/^\s*([-*_])(\s*\1){2,}\s*$/.test(m)){l.push("<hr>"),t++;continue}if(/^\s*>/.test(m)){const c=[];for(;t<n.length&&/^\s*>/.test(n[t]);)c.push(n[t].replace(/^\s*>\s?/,"")),t++;l.push(`<blockquote>${B(c.join(`
5
+ `))}</blockquote>`);continue}if(_(n,t)){const c=y(n[t]),u=y(n[t+1]).map(a=>a.endsWith(":")?a.startsWith(":")?"center":"right":a.startsWith(":")?"left":"");t+=2;const g=[];for(;t<n.length&&n[t].includes("|")&&n[t].trim();)g.push(y(n[t])),t++;const f=(a,$,h)=>{const E=u[h]?` style="text-align:${u[h]}"`:"";return`<${a}${E}>${p($)}</${a}>`};l.push("<table><thead><tr>"+c.map((a,$)=>f("th",a,$)).join("")+"</tr></thead><tbody>"+g.map(a=>"<tr>"+c.map(($,h)=>f("td",a[h]??"",h)).join("")+"</tr>").join("")+"</tbody></table>");continue}const i=/^\s*([-*+]|\d+[.)])\s+/.exec(m);if(i){const c=/\d/.test(i[1]),u=[];for(;t<n.length;){const a=/^\s*([-*+]|\d+[.)])\s+(.*)$/.exec(n[t]);if(a&&/\d/.test(a[1])===c)u.push(a[2]);else if(n[t].trim()&&/^\s{2,}/.test(n[t])&&u.length>0)u[u.length-1]+=" "+n[t].trim();else break;t++}const g=c?"ol":"ul",f=c&&parseInt(i[1],10)!==1?` start="${parseInt(i[1],10)}"`:"";l.push(`<${g}${f}>${u.map(a=>`<li>${p(a)}</li>`).join("")}</${g}>`);continue}const o=[];for(;t<n.length&&n[t].trim()&&!b(n,t);)o.push(n[t].trim()),t++;l.push(`<p>${o.map(p).join("<br>")}</p>`)}return l.join(`
6
+ `)}function p(s){return s.split(/(`+[^`]*`+)/).map((n,l)=>l%2===1?`<code>${k(n.replace(/^`+|`+$/g,""))}</code>`:C(k(n))).join("")}function C(s){return s.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g,(n,l,t)=>v(t)?`<img src="${t}" alt="${l}">`:l).replace(/\[([^\]]+)\]\(([^)\s]+)\)/g,(n,l,t)=>v(t)?`<a href="${t}" target="_blank" rel="noopener noreferrer">${l}</a>`:l).replace(new RegExp("(\\*\\*|__)(?=\\S)(.+?)(?<=\\S)\\1","g"),"<strong>$2</strong>").replace(new RegExp("(?<![\\w*])\\*(?=\\S)(.+?)(?<=\\S)\\*(?![\\w*])","g"),"<em>$1</em>").replace(new RegExp("(?<![\\w_])_(?=\\S)(.+?)(?<=\\S)_(?![\\w_])","g"),"<em>$1</em>").replace(new RegExp("~~(?=\\S)(.+?)(?<=\\S)~~","g"),"<del>$1</del>")}function v(s){const n=s.replace(/&amp;/g,"&").replace(/&#(x?[0-9a-f]+);?/gi,"?");return w.test(n.trim())}function y(s){return s.trim().replace(/^\||\|$/g,"").split("|").map(n=>n.trim())}function _(s,n){return s[n].includes("|")&&n+1<s.length&&/^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(s[n+1])}function b(s,n){const l=s[n];return/^\s*(`{3,}|~{3,})/.test(l)||/^#{1,6}\s/.test(l)||/^\s*>/.test(l)||/^\s*([-*+]|\d+[.)])\s+/.test(l)||/^\s*([-*_])(\s*\1){2,}\s*$/.test(l)||_(s,n)}const M={class:"vue-llm-stream"},j=["innerHTML"],x={key:0,class:"vue-llm-cursor","aria-hidden":"true"},S=e.defineComponent({__name:"StreamMarkdown",props:{content:{},streaming:{type:Boolean},render:{type:Function}},setup(s){const n=s,l=e.computed(()=>(n.render??B)(n.content));return(t,m)=>(e.openBlock(),e.createElementBlock("div",M,[e.createElementVNode("div",{class:"vue-llm-markdown",innerHTML:l.value},null,8,j),s.streaming?(e.openBlock(),e.createElementBlock("span",x,"▊")):e.createCommentVNode("",!0)]))}}),F=["data-role"],I={key:0,class:"vue-llm-text"},N=["open"],T=["src","alt"],L={key:1,class:"vue-llm-file"},P=["href"],R=e.defineComponent({__name:"MessageParts",props:{message:{},components:{},dataComponents:{},render:{type:Function}},emits:["tool-result"],setup(s,{emit:n}){const l=n,t=(r,i)=>r.type==="tool-call"?r.toolCallId:r.type==="data"&&r.id!==void 0?`data:${r.name}:${r.id}`:i,m=r=>({toolCallId:r.toolCallId,toolName:r.toolName,args:r.args,state:r.state,result:r.result,error:r.error,addResult:i=>l("tool-result",{toolCallId:r.toolCallId,result:i})}),d=r=>({part:r,addResult:m(r).addResult});return(r,i)=>(e.openBlock(),e.createElementBlock("div",{class:"vue-llm-message","data-role":s.message.role},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.message.parts,(o,c)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:t(o,c)},[o.type==="text"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[s.message.role==="user"?(e.openBlock(),e.createElementBlock("div",I,e.toDisplayString(o.text),1)):(e.openBlock(),e.createBlock(S,{key:1,content:o.text,streaming:o.state==="streaming",render:s.render},null,8,["content","streaming","render"]))],64)):o.type==="reasoning"?(e.openBlock(),e.createElementBlock("details",{key:1,class:"vue-llm-reasoning",open:o.state==="streaming"},[i[0]||(i[0]=e.createElementVNode("summary",null,"Reasoning",-1)),e.createElementVNode("div",null,e.toDisplayString(o.text),1)],8,N)):o.type==="tool-call"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[s.components?.[o.toolName]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(s.components[o.toolName]),e.mergeProps({key:t(o,c)},{ref_for:!0},m(o)),null,16)):e.renderSlot(r.$slots,"tool",e.mergeProps({ref_for:!0},d(o)),void 0,void 0,1)],64)):o.type==="data"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[s.dataComponents?.[o.name]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(s.dataComponents[o.name]),{key:t(o,c),name:o.name,data:o.data},null,8,["name","data"])):e.renderSlot(r.$slots,"data",{part:o},void 0,void 0,1)],64)):o.type==="file"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:4},[o.mediaType.startsWith("image/")?(e.openBlock(),e.createElementBlock("img",{key:0,class:"vue-llm-file",src:o.url,alt:o.filename??""},null,8,T)):(e.openBlock(),e.createElementBlock("span",L,e.toDisplayString(o.filename??o.mediaType),1))],64)):o.type==="source"&&/^https?:/i.test(o.url)?(e.openBlock(),e.createElementBlock("a",{key:5,class:"vue-llm-source",href:o.url,target:"_blank",rel:"noopener noreferrer"},e.toDisplayString(o.title??o.url),9,P)):e.createCommentVNode("",!0)],64))),128))],8,F))}});exports.MessageParts=R;exports.StreamMarkdown=S;exports.escapeHTML=k;exports.renderInline=p;exports.renderMarkdown=B;
@@ -1,140 +1,135 @@
1
- import { defineComponent as j, computed as B, openBlock as r, createElementBlock as i, Fragment as g, createElementVNode as x, createCommentVNode as M, renderList as W, toDisplayString as _, createBlock as w, resolveDynamicComponent as C, mergeProps as q, renderSlot as b } from "vue";
2
- const E = /^(?:https?:|mailto:|\/(?!\/)|#|\.\.?\/)/i;
3
- function v(s) {
4
- return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1
+ import { defineComponent as I, computed as B, openBlock as a, createElementBlock as c, createElementVNode as C, createCommentVNode as R, Fragment as h, renderList as P, toDisplayString as k, createBlock as w, resolveDynamicComponent as b, mergeProps as x, renderSlot as j } from "vue";
2
+ const W = /^(?:https?:|mailto:|\/(?!\/)|#|\.\.?\/)/i;
3
+ function v(n) {
4
+ return n.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
5
5
  }
6
- function R(s) {
7
- const e = s.replace(/\r\n?/g, `
6
+ function L(n) {
7
+ const t = n.replace(/\r\n?/g, `
8
8
  `).split(`
9
9
  `), o = [];
10
- let t = 0;
11
- for (; t < e.length; ) {
12
- const u = e[t], l = /^\s*(`{3,}|~{3,})\s*([\w+#.-]*)/.exec(u);
13
- if (l) {
14
- const c = [];
15
- for (t++; t < e.length && !e[t].trimStart().startsWith(l[1]); )
16
- c.push(e[t]), t++;
17
- t++;
18
- const d = l[2] ? ` class="language-${v(l[2])}"` : "";
19
- o.push(`<pre><code${d}>${v(c.join(`
10
+ let e = 0;
11
+ for (; e < t.length; ) {
12
+ const m = t[e], g = /^\s*(`{3,}|~{3,})\s*([\w+#.-]*)/.exec(m);
13
+ if (g) {
14
+ const r = [];
15
+ for (e++; e < t.length && !t[e].trimStart().startsWith(g[1]); )
16
+ r.push(t[e]), e++;
17
+ e++;
18
+ const d = g[2] ? ` class="language-${v(g[2])}"` : "";
19
+ o.push(`<pre><code${d}>${v(r.join(`
20
20
  `))}</code></pre>`);
21
21
  continue;
22
22
  }
23
- if (!u.trim()) {
24
- t++;
23
+ if (!m.trim()) {
24
+ e++;
25
25
  continue;
26
26
  }
27
- const m = /^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(u);
28
- if (m) {
29
- const c = m[1].length;
30
- o.push(`<h${c}>${k(m[2])}</h${c}>`), t++;
27
+ const l = /^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(m);
28
+ if (l) {
29
+ const r = l[1].length;
30
+ o.push(`<h${r}>${_(l[2])}</h${r}>`), e++;
31
31
  continue;
32
32
  }
33
- if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(u)) {
34
- o.push("<hr>"), t++;
33
+ if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(m)) {
34
+ o.push("<hr>"), e++;
35
35
  continue;
36
36
  }
37
- if (/^\s*>/.test(u)) {
38
- const c = [];
39
- for (; t < e.length && /^\s*>/.test(e[t]); )
40
- c.push(e[t].replace(/^\s*>\s?/, "")), t++;
41
- o.push(`<blockquote>${R(c.join(`
37
+ if (/^\s*>/.test(m)) {
38
+ const r = [];
39
+ for (; e < t.length && /^\s*>/.test(t[e]); )
40
+ r.push(t[e].replace(/^\s*>\s?/, "")), e++;
41
+ o.push(`<blockquote>${L(r.join(`
42
42
  `))}</blockquote>`);
43
43
  continue;
44
44
  }
45
- if (L(e, t)) {
46
- const c = S(e[t]), d = S(e[t + 1]).map((a) => a.endsWith(":") ? a.startsWith(":") ? "center" : "right" : a.startsWith(":") ? "left" : "");
47
- t += 2;
48
- const h = [];
49
- for (; t < e.length && e[t].includes("|") && e[t].trim(); )
50
- h.push(S(e[t])), t++;
51
- const $ = (a, y, p) => {
52
- const T = d[p] ? ` style="text-align:${d[p]}"` : "";
53
- return `<${a}${T}>${k(y)}</${a}>`;
45
+ if (N(t, e)) {
46
+ const r = S(t[e]), d = S(t[e + 1]).map((i) => i.endsWith(":") ? i.startsWith(":") ? "center" : "right" : i.startsWith(":") ? "left" : "");
47
+ e += 2;
48
+ const $ = [];
49
+ for (; e < t.length && t[e].includes("|") && t[e].trim(); )
50
+ $.push(S(t[e])), e++;
51
+ const p = (i, y, f) => {
52
+ const T = d[f] ? ` style="text-align:${d[f]}"` : "";
53
+ return `<${i}${T}>${_(y)}</${i}>`;
54
54
  };
55
55
  o.push(
56
- "<table><thead><tr>" + c.map((a, y) => $("th", a, y)).join("") + "</tr></thead><tbody>" + h.map((a) => "<tr>" + c.map((y, p) => $("td", a[p] ?? "", p)).join("") + "</tr>").join("") + "</tbody></table>"
56
+ "<table><thead><tr>" + r.map((i, y) => p("th", i, y)).join("") + "</tr></thead><tbody>" + $.map((i) => "<tr>" + r.map((y, f) => p("td", i[f] ?? "", f)).join("") + "</tr>").join("") + "</tbody></table>"
57
57
  );
58
58
  continue;
59
59
  }
60
- const n = /^\s*([-*+]|\d+[.)])\s+/.exec(u);
61
- if (n) {
62
- const c = /\d/.test(n[1]), d = [];
63
- for (; t < e.length; ) {
64
- const a = /^\s*([-*+]|\d+[.)])\s+(.*)$/.exec(e[t]);
65
- if (a && /\d/.test(a[1]) === c)
66
- d.push(a[2]);
67
- else if (e[t].trim() && /^\s{2,}/.test(e[t]) && d.length > 0)
68
- d[d.length - 1] += " " + e[t].trim();
60
+ const u = /^\s*([-*+]|\d+[.)])\s+/.exec(m);
61
+ if (u) {
62
+ const r = /\d/.test(u[1]), d = [];
63
+ for (; e < t.length; ) {
64
+ const i = /^\s*([-*+]|\d+[.)])\s+(.*)$/.exec(t[e]);
65
+ if (i && /\d/.test(i[1]) === r)
66
+ d.push(i[2]);
67
+ else if (t[e].trim() && /^\s{2,}/.test(t[e]) && d.length > 0)
68
+ d[d.length - 1] += " " + t[e].trim();
69
69
  else
70
70
  break;
71
- t++;
71
+ e++;
72
72
  }
73
- const h = c ? "ol" : "ul", $ = c && parseInt(n[1], 10) !== 1 ? ` start="${parseInt(n[1], 10)}"` : "";
74
- o.push(`<${h}${$}>${d.map((a) => `<li>${k(a)}</li>`).join("")}</${h}>`);
73
+ const $ = r ? "ol" : "ul", p = r && parseInt(u[1], 10) !== 1 ? ` start="${parseInt(u[1], 10)}"` : "";
74
+ o.push(`<${$}${p}>${d.map((i) => `<li>${_(i)}</li>`).join("")}</${$}>`);
75
75
  continue;
76
76
  }
77
- const f = [];
78
- for (; t < e.length && e[t].trim() && !P(e, t); )
79
- f.push(e[t].trim()), t++;
80
- o.push(`<p>${f.map(k).join("<br>")}</p>`);
77
+ const s = [];
78
+ for (; e < t.length && t[e].trim() && !E(t, e); )
79
+ s.push(t[e].trim()), e++;
80
+ o.push(`<p>${s.map(_).join("<br>")}</p>`);
81
81
  }
82
82
  return o.join(`
83
83
  `);
84
84
  }
85
- function k(s) {
86
- return s.split(/(`+[^`]*`+)/).map((e, o) => o % 2 === 1 ? `<code>${v(e.replace(/^`+|`+$/g, ""))}</code>` : F(v(e))).join("");
85
+ function _(n) {
86
+ return n.split(/(`+[^`]*`+)/).map((t, o) => o % 2 === 1 ? `<code>${v(t.replace(/^`+|`+$/g, ""))}</code>` : q(v(t))).join("");
87
87
  }
88
- function F(s) {
89
- return s.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (e, o, t) => I(t) ? `<img src="${t}" alt="${o}">` : o).replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (e, o, t) => I(t) ? `<a href="${t}" target="_blank" rel="noopener noreferrer">${o}</a>` : o).replace(new RegExp("(\\*\\*|__)(?=\\S)(.+?)(?<=\\S)\\1", "g"), "<strong>$2</strong>").replace(new RegExp("(?<![\\w*])\\*(?=\\S)(.+?)(?<=\\S)\\*(?![\\w*])", "g"), "<em>$1</em>").replace(new RegExp("(?<![\\w_])_(?=\\S)(.+?)(?<=\\S)_(?![\\w_])", "g"), "<em>$1</em>").replace(new RegExp("~~(?=\\S)(.+?)(?<=\\S)~~", "g"), "<del>$1</del>");
88
+ function q(n) {
89
+ return n.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (t, o, e) => M(e) ? `<img src="${e}" alt="${o}">` : o).replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (t, o, e) => M(e) ? `<a href="${e}" target="_blank" rel="noopener noreferrer">${o}</a>` : o).replace(new RegExp("(\\*\\*|__)(?=\\S)(.+?)(?<=\\S)\\1", "g"), "<strong>$2</strong>").replace(new RegExp("(?<![\\w*])\\*(?=\\S)(.+?)(?<=\\S)\\*(?![\\w*])", "g"), "<em>$1</em>").replace(new RegExp("(?<![\\w_])_(?=\\S)(.+?)(?<=\\S)_(?![\\w_])", "g"), "<em>$1</em>").replace(new RegExp("~~(?=\\S)(.+?)(?<=\\S)~~", "g"), "<del>$1</del>");
90
90
  }
91
- function I(s) {
92
- const e = s.replace(/&amp;/g, "&").replace(/&#(x?[0-9a-f]+);?/gi, "?");
93
- return E.test(e.trim());
91
+ function M(n) {
92
+ const t = n.replace(/&amp;/g, "&").replace(/&#(x?[0-9a-f]+);?/gi, "?");
93
+ return W.test(t.trim());
94
94
  }
95
- function S(s) {
96
- return s.trim().replace(/^\||\|$/g, "").split("|").map((e) => e.trim());
95
+ function S(n) {
96
+ return n.trim().replace(/^\||\|$/g, "").split("|").map((t) => t.trim());
97
97
  }
98
- function L(s, e) {
99
- return s[e].includes("|") && e + 1 < s.length && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(s[e + 1]);
98
+ function N(n, t) {
99
+ return n[t].includes("|") && t + 1 < n.length && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(n[t + 1]);
100
100
  }
101
- function P(s, e) {
102
- const o = s[e];
103
- return /^\s*(`{3,}|~{3,})/.test(o) || /^#{1,6}\s/.test(o) || /^\s*>/.test(o) || /^\s*([-*+]|\d+[.)])\s+/.test(o) || /^\s*([-*_])(\s*\1){2,}\s*$/.test(o) || L(s, e);
101
+ function E(n, t) {
102
+ const o = n[t];
103
+ return /^\s*(`{3,}|~{3,})/.test(o) || /^#{1,6}\s/.test(o) || /^\s*>/.test(o) || /^\s*([-*+]|\d+[.)])\s+/.test(o) || /^\s*([-*_])(\s*\1){2,}\s*$/.test(o) || N(n, t);
104
104
  }
105
- const H = ["innerHTML"], D = {
105
+ const F = { class: "vue-llm-stream" }, H = ["innerHTML"], D = {
106
106
  key: 0,
107
107
  class: "vue-llm-cursor",
108
108
  "aria-hidden": "true"
109
- }, U = /* @__PURE__ */ j({
109
+ }, U = /* @__PURE__ */ I({
110
110
  __name: "StreamMarkdown",
111
111
  props: {
112
112
  content: {},
113
113
  streaming: { type: Boolean },
114
114
  render: { type: Function }
115
115
  },
116
- setup(s) {
117
- const e = s, o = B(() => (e.render ?? R)(e.content));
118
- return (t, u) => (r(), i(g, null, [
119
- x("div", {
116
+ setup(n) {
117
+ const t = n, o = B(() => (t.render ?? L)(t.content));
118
+ return (e, m) => (a(), c("div", F, [
119
+ C("div", {
120
120
  class: "vue-llm-markdown",
121
121
  innerHTML: o.value
122
122
  }, null, 8, H),
123
- s.streaming ? (r(), i("span", D, "▊")) : M("", !0)
124
- ], 64));
123
+ n.streaming ? (a(), c("span", D, "▊")) : R("", !0)
124
+ ]));
125
125
  }
126
- }), N = (s, e) => {
127
- const o = s.__vccOpts || s;
128
- for (const [t, u] of e)
129
- o[t] = u;
130
- return o;
131
- }, V = /* @__PURE__ */ N(U, [["__scopeId", "data-v-f225ccf4"]]), A = ["data-role"], K = {
126
+ }), V = ["data-role"], A = {
132
127
  key: 0,
133
128
  class: "vue-llm-text"
134
- }, O = ["open"], z = ["src", "alt"], G = {
129
+ }, K = ["open"], z = ["src", "alt"], G = {
135
130
  key: 1,
136
131
  class: "vue-llm-file"
137
- }, J = ["href"], Q = /* @__PURE__ */ j({
132
+ }, J = ["href"], Q = /* @__PURE__ */ I({
138
133
  __name: "MessageParts",
139
134
  props: {
140
135
  message: {},
@@ -143,73 +138,69 @@ const H = ["innerHTML"], D = {
143
138
  render: { type: Function }
144
139
  },
145
140
  emits: ["tool-result"],
146
- setup(s, { emit: e }) {
147
- const o = e, t = (l, m) => l.type === "tool-call" ? l.toolCallId : l.type === "data" && l.id !== void 0 ? `data:${l.name}:${l.id}` : m, u = (l) => ({
141
+ setup(n, { emit: t }) {
142
+ const o = t, e = (l, u) => l.type === "tool-call" ? l.toolCallId : l.type === "data" && l.id !== void 0 ? `data:${l.name}:${l.id}` : u, m = (l) => ({
148
143
  toolCallId: l.toolCallId,
149
144
  toolName: l.toolName,
150
145
  args: l.args,
151
146
  state: l.state,
152
147
  result: l.result,
153
148
  error: l.error,
154
- addResult: (m) => o("tool-result", { toolCallId: l.toolCallId, result: m })
155
- });
156
- return (l, m) => (r(), i("div", {
149
+ addResult: (u) => o("tool-result", { toolCallId: l.toolCallId, result: u })
150
+ }), g = (l) => ({ part: l, addResult: m(l).addResult });
151
+ return (l, u) => (a(), c("div", {
157
152
  class: "vue-llm-message",
158
- "data-role": s.message.role
153
+ "data-role": n.message.role
159
154
  }, [
160
- (r(!0), i(g, null, W(s.message.parts, (n, f) => (r(), i(g, {
161
- key: t(n, f)
155
+ (a(!0), c(h, null, P(n.message.parts, (s, r) => (a(), c(h, {
156
+ key: e(s, r)
162
157
  }, [
163
- n.type === "text" ? (r(), i(g, { key: 0 }, [
164
- s.message.role === "user" ? (r(), i("div", K, _(n.text), 1)) : (r(), w(V, {
158
+ s.type === "text" ? (a(), c(h, { key: 0 }, [
159
+ n.message.role === "user" ? (a(), c("div", A, k(s.text), 1)) : (a(), w(U, {
165
160
  key: 1,
166
- content: n.text,
167
- streaming: n.state === "streaming",
168
- render: s.render
161
+ content: s.text,
162
+ streaming: s.state === "streaming",
163
+ render: n.render
169
164
  }, null, 8, ["content", "streaming", "render"]))
170
- ], 64)) : n.type === "reasoning" ? (r(), i("details", {
165
+ ], 64)) : s.type === "reasoning" ? (a(), c("details", {
171
166
  key: 1,
172
167
  class: "vue-llm-reasoning",
173
- open: n.state === "streaming"
168
+ open: s.state === "streaming"
174
169
  }, [
175
- m[0] || (m[0] = x("summary", null, "Reasoning", -1)),
176
- x("div", null, _(n.text), 1)
177
- ], 8, O)) : n.type === "tool-call" ? (r(), i(g, { key: 2 }, [
178
- s.components?.[n.toolName] ? (r(), w(C(s.components[n.toolName]), q({
179
- key: 0,
180
- ref_for: !0
181
- }, u(n)), null, 16)) : b(l.$slots, "tool", {
182
- part: n,
183
- addResult: u(n).addResult
184
- }, void 0, !0, 1)
185
- ], 64)) : n.type === "data" ? (r(), i(g, { key: 3 }, [
186
- s.dataComponents?.[n.name] ? (r(), w(C(s.dataComponents[n.name]), {
187
- key: 0,
188
- name: n.name,
189
- data: n.data
190
- }, null, 8, ["name", "data"])) : b(l.$slots, "data", { part: n }, void 0, !0, 1)
191
- ], 64)) : n.type === "file" ? (r(), i(g, { key: 4 }, [
192
- n.mediaType.startsWith("image/") ? (r(), i("img", {
170
+ u[0] || (u[0] = C("summary", null, "Reasoning", -1)),
171
+ C("div", null, k(s.text), 1)
172
+ ], 8, K)) : s.type === "tool-call" ? (a(), c(h, { key: 2 }, [
173
+ n.components?.[s.toolName] ? (a(), w(b(n.components[s.toolName]), x({
174
+ key: e(s, r)
175
+ }, { ref_for: !0 }, m(s)), null, 16)) : j(l.$slots, "tool", x({ ref_for: !0 }, g(s)), void 0, void 0, 1)
176
+ ], 64)) : s.type === "data" ? (a(), c(h, { key: 3 }, [
177
+ n.dataComponents?.[s.name] ? (a(), w(b(n.dataComponents[s.name]), {
178
+ key: e(s, r),
179
+ name: s.name,
180
+ data: s.data
181
+ }, null, 8, ["name", "data"])) : j(l.$slots, "data", { part: s }, void 0, void 0, 1)
182
+ ], 64)) : s.type === "file" ? (a(), c(h, { key: 4 }, [
183
+ s.mediaType.startsWith("image/") ? (a(), c("img", {
193
184
  key: 0,
194
185
  class: "vue-llm-file",
195
- src: n.url,
196
- alt: n.filename ?? ""
197
- }, null, 8, z)) : (r(), i("span", G, _(n.filename ?? n.mediaType), 1))
198
- ], 64)) : n.type === "source" && /^https?:/i.test(n.url) ? (r(), i("a", {
186
+ src: s.url,
187
+ alt: s.filename ?? ""
188
+ }, null, 8, z)) : (a(), c("span", G, k(s.filename ?? s.mediaType), 1))
189
+ ], 64)) : s.type === "source" && /^https?:/i.test(s.url) ? (a(), c("a", {
199
190
  key: 5,
200
191
  class: "vue-llm-source",
201
- href: n.url,
192
+ href: s.url,
202
193
  target: "_blank",
203
194
  rel: "noopener noreferrer"
204
- }, _(n.title ?? n.url), 9, J)) : M("", !0)
195
+ }, k(s.title ?? s.url), 9, J)) : R("", !0)
205
196
  ], 64))), 128))
206
- ], 8, A));
197
+ ], 8, V));
207
198
  }
208
- }), Y = /* @__PURE__ */ N(Q, [["__scopeId", "data-v-3868ad67"]]);
199
+ });
209
200
  export {
210
- Y as MessageParts,
211
- V as StreamMarkdown,
201
+ Q as MessageParts,
202
+ U as StreamMarkdown,
212
203
  v as escapeHTML,
213
- k as renderInline,
214
- R as renderMarkdown
204
+ _ as renderInline,
205
+ L as renderMarkdown
215
206
  };
package/dist/vue-llm.css CHANGED
@@ -1 +1 @@
1
- .vue-llm-cursor[data-v-f225ccf4]{animation:vue-llm-blink-f225ccf4 .7s step-end infinite}@keyframes vue-llm-blink-f225ccf4{50%{opacity:0}}.vue-llm-text[data-v-3868ad67]{white-space:pre-wrap}.vue-llm-file[data-v-3868ad67]{max-width:100%}
1
+ .vue-llm-cursor{animation:vue-llm-blink .7s step-end infinite}@keyframes vue-llm-blink{50%{opacity:0}}.vue-llm-text{white-space:pre-wrap}.vue-llm-file{max-width:100%}
@@ -0,0 +1,36 @@
1
+ // Types of `vue-llm/components/vue2`, published as dist/vue2/components.d.ts (see vite.vue2.config.ts).
2
+ // Hand-written because vue-tsc emits Vue 3 component types; these use Vue 2.7's own `DefineComponent`.
3
+ import type { Component, DefineComponent } from 'vue'
4
+ import type { DataPart, ToolCallPart, UIMessage } from '../types.js'
5
+
6
+ export interface StreamMarkdownProps {
7
+ content: string
8
+ streaming?: boolean
9
+ /** Markdown renderer, `renderMarkdown` by default */
10
+ render?: (markdown: string) => string
11
+ }
12
+
13
+ export interface MessagePartsProps {
14
+ message: UIMessage
15
+ /** Components that render tool calls, keyed by tool name (Generative UI) */
16
+ components?: Record<string, Component>
17
+ /** Components that render data parts, keyed by their `name` */
18
+ dataComponents?: Record<string, Component>
19
+ /** Markdown renderer for text parts, see StreamMarkdown */
20
+ render?: (markdown: string) => string
21
+ }
22
+
23
+ /** Props of the `tool` and `data` scoped slots of MessageParts */
24
+ export interface MessagePartsSlotProps {
25
+ tool: { part: ToolCallPart; addResult: (result: unknown) => void }
26
+ data: { part: DataPart }
27
+ }
28
+
29
+ export declare const StreamMarkdown: DefineComponent<StreamMarkdownProps>
30
+ export declare const MessageParts: DefineComponent<
31
+ MessagePartsProps,
32
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- placeholders to reach the emits parameter
33
+ {}, {}, {}, {}, {}, {},
34
+ { 'tool-result': (payload: { toolCallId: string; result: unknown }) => void }
35
+ >
36
+ export { renderMarkdown, renderInline, escapeHTML } from '../core/markdown.js'
@@ -0,0 +1,159 @@
1
+ import { defineComponent as S, computed as x } from "vue";
2
+ const j = /^(?:https?:|mailto:|\/(?!\/)|#|\.\.?\/)/i;
3
+ function h(o) {
4
+ return o.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
5
+ }
6
+ function w(o) {
7
+ const e = o.replace(/\r\n?/g, `
8
+ `).split(`
9
+ `), s = [];
10
+ let t = 0;
11
+ for (; t < e.length; ) {
12
+ const n = e[t], r = /^\s*(`{3,}|~{3,})\s*([\w+#.-]*)/.exec(n);
13
+ if (r) {
14
+ const a = [];
15
+ for (t++; t < e.length && !e[t].trimStart().startsWith(r[1]); )
16
+ a.push(e[t]), t++;
17
+ t++;
18
+ const i = r[2] ? ` class="language-${h(r[2])}"` : "";
19
+ s.push(`<pre><code${i}>${h(a.join(`
20
+ `))}</code></pre>`);
21
+ continue;
22
+ }
23
+ if (!n.trim()) {
24
+ t++;
25
+ continue;
26
+ }
27
+ const c = /^(#{1,6})\s+(.*?)\s*#*\s*$/.exec(n);
28
+ if (c) {
29
+ const a = c[1].length;
30
+ s.push(`<h${a}>${_(c[2])}</h${a}>`), t++;
31
+ continue;
32
+ }
33
+ if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(n)) {
34
+ s.push("<hr>"), t++;
35
+ continue;
36
+ }
37
+ if (/^\s*>/.test(n)) {
38
+ const a = [];
39
+ for (; t < e.length && /^\s*>/.test(e[t]); )
40
+ a.push(e[t].replace(/^\s*>\s?/, "")), t++;
41
+ s.push(`<blockquote>${w(a.join(`
42
+ `))}</blockquote>`);
43
+ continue;
44
+ }
45
+ if (C(e, t)) {
46
+ const a = f(e[t]), i = f(e[t + 1]).map((l) => l.endsWith(":") ? l.startsWith(":") ? "center" : "right" : l.startsWith(":") ? "left" : "");
47
+ t += 2;
48
+ const u = [];
49
+ for (; t < e.length && e[t].includes("|") && e[t].trim(); )
50
+ u.push(f(e[t])), t++;
51
+ const p = (l, g, m) => {
52
+ const b = i[m] ? ` style="text-align:${i[m]}"` : "";
53
+ return `<${l}${b}>${_(g)}</${l}>`;
54
+ };
55
+ s.push(
56
+ "<table><thead><tr>" + a.map((l, g) => p("th", l, g)).join("") + "</tr></thead><tbody>" + u.map((l) => "<tr>" + a.map((g, m) => p("td", l[m] ?? "", m)).join("") + "</tr>").join("") + "</tbody></table>"
57
+ );
58
+ continue;
59
+ }
60
+ const d = /^\s*([-*+]|\d+[.)])\s+/.exec(n);
61
+ if (d) {
62
+ const a = /\d/.test(d[1]), i = [];
63
+ for (; t < e.length; ) {
64
+ const l = /^\s*([-*+]|\d+[.)])\s+(.*)$/.exec(e[t]);
65
+ if (l && /\d/.test(l[1]) === a)
66
+ i.push(l[2]);
67
+ else if (e[t].trim() && /^\s{2,}/.test(e[t]) && i.length > 0)
68
+ i[i.length - 1] += " " + e[t].trim();
69
+ else
70
+ break;
71
+ t++;
72
+ }
73
+ const u = a ? "ol" : "ul", p = a && parseInt(d[1], 10) !== 1 ? ` start="${parseInt(d[1], 10)}"` : "";
74
+ s.push(`<${u}${p}>${i.map((l) => `<li>${_(l)}</li>`).join("")}</${u}>`);
75
+ continue;
76
+ }
77
+ const v = [];
78
+ for (; t < e.length && e[t].trim() && !R(e, t); )
79
+ v.push(e[t].trim()), t++;
80
+ s.push(`<p>${v.map(_).join("<br>")}</p>`);
81
+ }
82
+ return s.join(`
83
+ `);
84
+ }
85
+ function _(o) {
86
+ return o.split(/(`+[^`]*`+)/).map((e, s) => s % 2 === 1 ? `<code>${h(e.replace(/^`+|`+$/g, ""))}</code>` : q(h(e))).join("");
87
+ }
88
+ function q(o) {
89
+ return o.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (e, s, t) => y(t) ? `<img src="${t}" alt="${s}">` : s).replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (e, s, t) => y(t) ? `<a href="${t}" target="_blank" rel="noopener noreferrer">${s}</a>` : s).replace(new RegExp("(\\*\\*|__)(?=\\S)(.+?)(?<=\\S)\\1", "g"), "<strong>$2</strong>").replace(new RegExp("(?<![\\w*])\\*(?=\\S)(.+?)(?<=\\S)\\*(?![\\w*])", "g"), "<em>$1</em>").replace(new RegExp("(?<![\\w_])_(?=\\S)(.+?)(?<=\\S)_(?![\\w_])", "g"), "<em>$1</em>").replace(new RegExp("~~(?=\\S)(.+?)(?<=\\S)~~", "g"), "<del>$1</del>");
90
+ }
91
+ function y(o) {
92
+ const e = o.replace(/&amp;/g, "&").replace(/&#(x?[0-9a-f]+);?/gi, "?");
93
+ return j.test(e.trim());
94
+ }
95
+ function f(o) {
96
+ return o.trim().replace(/^\||\|$/g, "").split("|").map((e) => e.trim());
97
+ }
98
+ function C(o, e) {
99
+ return o[e].includes("|") && e + 1 < o.length && /^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/.test(o[e + 1]);
100
+ }
101
+ function R(o, e) {
102
+ const s = o[e];
103
+ return /^\s*(`{3,}|~{3,})/.test(s) || /^#{1,6}\s/.test(s) || /^\s*>/.test(s) || /^\s*([-*+]|\d+[.)])\s+/.test(s) || /^\s*([-*_])(\s*\1){2,}\s*$/.test(s) || C(o, e);
104
+ }
105
+ const $ = /* @__PURE__ */ S({
106
+ __name: "StreamMarkdown",
107
+ props: {
108
+ content: { type: String, required: !0 },
109
+ streaming: { type: Boolean, required: !1 },
110
+ render: { type: Function, required: !1 }
111
+ },
112
+ setup(o) {
113
+ const e = o, s = x(() => (e.render ?? w)(e.content));
114
+ return { __sfc: !0, props: e, html: s };
115
+ }
116
+ });
117
+ var M = function() {
118
+ var e = this, s = e._self._c, t = e._self._setupProxy;
119
+ return s("div", { staticClass: "vue-llm-stream" }, [s("div", { staticClass: "vue-llm-markdown", domProps: { innerHTML: e._s(t.html) } }), e.streaming ? s("span", { staticClass: "vue-llm-cursor", attrs: { "aria-hidden": "true" } }, [e._v("▊")]) : e._e()]);
120
+ }, P = [];
121
+ $.render = M;
122
+ $.staticRenderFns = P;
123
+ const k = /* @__PURE__ */ S({
124
+ __name: "MessageParts",
125
+ props: {
126
+ message: { type: null, required: !0 },
127
+ components: { type: Object, required: !1 },
128
+ dataComponents: { type: Object, required: !1 },
129
+ render: { type: Function, required: !1 }
130
+ },
131
+ emits: ["tool-result"],
132
+ setup(o, { emit: e }) {
133
+ const s = (r, c) => r.type === "tool-call" ? r.toolCallId : r.type === "data" && r.id !== void 0 ? `data:${r.name}:${r.id}` : c, t = (r) => ({
134
+ toolCallId: r.toolCallId,
135
+ toolName: r.toolName,
136
+ args: r.args,
137
+ state: r.state,
138
+ result: r.result,
139
+ error: r.error,
140
+ addResult: (c) => e("tool-result", { toolCallId: r.toolCallId, result: c })
141
+ });
142
+ return { __sfc: !0, emit: e, partKey: s, toolProps: t, toolSlotProps: (r) => ({ part: r, addResult: t(r).addResult }), StreamMarkdown: $ };
143
+ }
144
+ });
145
+ var I = function() {
146
+ var e = this, s = e._self._c, t = e._self._setupProxy;
147
+ return s("div", { staticClass: "vue-llm-message", attrs: { "data-role": e.message.role } }, [e._l(e.message.parts, function(n, r) {
148
+ return [n.type === "text" ? [e.message.role === "user" ? s("div", { staticClass: "vue-llm-text" }, [e._v(e._s(n.text))]) : s(t.StreamMarkdown, { attrs: { content: n.text, streaming: n.state === "streaming", render: e.render } })] : n.type === "reasoning" ? s("details", { staticClass: "vue-llm-reasoning", attrs: { open: n.state === "streaming" } }, [s("summary", [e._v("Reasoning")]), s("div", [e._v(e._s(n.text))])]) : n.type === "tool-call" ? [e.components?.[n.toolName] ? s(e.components[n.toolName], e._b({ key: t.partKey(n, r), tag: "component" }, "component", t.toolProps(n), !1)) : e._t("tool", null, null, t.toolSlotProps(n))] : n.type === "data" ? [e.dataComponents?.[n.name] ? s(e.dataComponents[n.name], { key: t.partKey(n, r), tag: "component", attrs: { name: n.name, data: n.data } }) : e._t("data", null, { part: n })] : n.type === "file" ? [n.mediaType.startsWith("image/") ? s("img", { staticClass: "vue-llm-file", attrs: { src: n.url, alt: n.filename ?? "" } }) : s("span", { staticClass: "vue-llm-file" }, [e._v(e._s(n.filename ?? n.mediaType))])] : n.type === "source" && /^https?:/i.test(n.url) ? s("a", { staticClass: "vue-llm-source", attrs: { href: n.url, target: "_blank", rel: "noopener noreferrer" } }, [e._v(e._s(n.title ?? n.url))]) : e._e()];
149
+ })], 2);
150
+ }, F = [];
151
+ k.render = I;
152
+ k.staticRenderFns = F;
153
+ export {
154
+ k as MessageParts,
155
+ $ as StreamMarkdown,
156
+ h as escapeHTML,
157
+ _ as renderInline,
158
+ w as renderMarkdown
159
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue-llm",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "type": "module",
5
5
  "description": "AI SDK for Vue and Nuxt: streaming useChat, tool calling, Generative UI and in-browser WebGPU models for OpenAI, Anthropic, Gemini and Ollama.",
6
6
  "keywords": [
@@ -66,6 +66,10 @@
66
66
  "types": "./dist/components.d.ts",
67
67
  "import": "./dist/components.js"
68
68
  },
69
+ "./components/vue2": {
70
+ "types": "./dist/vue2/components.d.ts",
71
+ "import": "./dist/vue2/components.js"
72
+ },
69
73
  "./server": {
70
74
  "types": "./dist/server.d.ts",
71
75
  "import": "./dist/server.js",
@@ -95,8 +99,8 @@
95
99
  },
96
100
  "scripts": {
97
101
  "dev": "vite --config playground/vite.config.ts",
98
- "build": "vite build && vue-tsc -p tsconfig.build.json --emitDeclarationOnly && node scripts/fix-dts-vue-imports.mjs",
99
- "typecheck:dist": "tsc -p test/types-nodenext",
102
+ "build": "vite build && vite build -c vite.vue2.config.ts && vue-tsc -p tsconfig.build.json --emitDeclarationOnly && node scripts/fix-dts-vue-imports.mjs",
103
+ "typecheck:dist": "tsc -p test/types-nodenext && tsc -p test/types-vue2",
100
104
  "test": "vitest run",
101
105
  "test:watch": "vitest",
102
106
  "typecheck": "vue-tsc --noEmit",