var rt=Object.defineProperty;var Re=i=>{throw TypeError(i)};var st=(i,e,t)=>e in i?rt(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var k=(i,e,t)=>st(i,typeof e!="symbol"?e+"":e,t),it=(i,e,t)=>e.has(i)||Re("Cannot "+t);var Ae=(i,e,t)=>e.has(i)?Re("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(i):e.set(i,t);var M=(i,e,t)=>(it(i,e,"access private method"),t);import{r as v,H as Ce,bR as ot,d as lt,Q as at,A as ct,c as j,e as ie,g as oe,x as T,h as he,au as Ee,i as je,F as pt,v as ut,W as ve,a0 as ht,aS as ft,$ as dt,q as gt,w as mt,f as kt,O as xt,N as bt}from"./BpnUlMNa.js";import{_ as yt}from"./CXgnlbJ0.js";import"./BSuDdRC_.js";import"./DdDSu8zG.js";import"./BIxlrOKS.js";import"./C3hoC6Fc.js";import"./BB_K5-7A.js";import"./8hArVOJ7.js";import"./CPCZYp5N.js";import"./Cc7AFOF1.js";import"./B-AG0Pur.js";import"./BkKXvnCO.js";import"./BDzvEyjh.js";import"./CFU304S8.js";import"./DDg0_8L_.js";import"./DyvNEXVt.js";import"./GO-r33i_.js";import"./CuLB3FBG.js";import"./DQRUkQSq.js";import"./HPYMLvV_.js";import"./DqCj9b4m.js";import"./DAJnrLOn.js";import"./BXZC2147.js";import"./DC0CgjZ0.js";import"./BZ4EKnFQ.js";import"./CLdyA6-S.js";import"./DDYYWAo_.js";import"./D-_Wjm5S.js";import"./BsDtTzKZ.js";import"./BfIcU47v.js";import"./DjbrIdLM.js";import"./2mccsc9e.js";import"./C-cvIfNA.js";import"./DAO5BBHU.js";import"./Dnqi7248.js";import"./B9mSb-3l.js";import"./CnZvnjd2.js";import"./COhilHc3.js";let wt=(i,e=21)=>(t=e)=>{let r="",n=t;for(;n--;)r+=i[Math.random()*i.length|0];return r};var te={exports:{}};const _t=typeof Buffer<"u",Pe=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,Le=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;function De(i,e,t){t==null&&e!==null&&typeof e=="object"&&(t=e,e=void 0),_t&&Buffer.isBuffer(i)&&(i=i.toString()),i&&i.charCodeAt(0)===65279&&(i=i.slice(1));const r=JSON.parse(i,e);if(r===null||typeof r!="object")return r;const n=t&&t.protoAction||"error",s=t&&t.constructorAction||"error";if(n==="ignore"&&s==="ignore")return r;if(n!=="ignore"&&s!=="ignore"){if(Pe.test(i)===!1&&Le.test(i)===!1)return r}else if(n!=="ignore"&&s==="ignore"){if(Pe.test(i)===!1)return r}else if(Le.test(i)===!1)return r;return Fe(r,{protoAction:n,constructorAction:s,safe:t&&t.safe})}function Fe(i,{protoAction:e="error",constructorAction:t="error",safe:r}={}){let n=[i];for(;n.length;){const s=n;n=[];for(const o of s){if(e!=="ignore"&&Object.prototype.hasOwnProperty.call(o,"__proto__")){if(r===!0)return null;if(e==="error")throw new SyntaxError("Object contains forbidden prototype property");delete o.__proto__}if(t!=="ignore"&&Object.prototype.hasOwnProperty.call(o,"constructor")&&Object.prototype.hasOwnProperty.call(o.constructor,"prototype")){if(r===!0)return null;if(t==="error")throw new SyntaxError("Object contains forbidden prototype property");delete o.constructor}for(const l in o){const a=o[l];a&&typeof a=="object"&&n.push(a)}}}return i}function ge(i,e,t){const r=Error.stackTraceLimit;Error.stackTraceLimit=0;try{return De(i,e,t)}finally{Error.stackTraceLimit=r}}function $t(i,e){const t=Error.stackTraceLimit;Error.stackTraceLimit=0;try{return De(i,e,{safe:!0})}catch{return null}finally{Error.stackTraceLimit=t}}te.exports=ge;te.exports.default=ge;te.exports.parse=ge;te.exports.safeParse=$t;te.exports.scan=Fe;var Be=wt("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7);function Tt(i){return i instanceof Error&&(i.name==="AbortError"||i.name==="TimeoutError")}var D={code:"0",name:"text",parse:i=>{if(typeof i!="string")throw new Error('"text" parts expect a string value.');return{type:"text",value:i}}},F={code:"1",name:"function_call",parse:i=>{if(i==null||typeof i!="object"||!("function_call"in i)||typeof i.function_call!="object"||i.function_call==null||!("name"in i.function_call)||!("arguments"in i.function_call)||typeof i.function_call.name!="string"||typeof i.function_call.arguments!="string")throw new Error('"function_call" parts expect an object with a "function_call" property.');return{type:"function_call",value:i}}},Q={code:"2",name:"data",parse:i=>{if(!Array.isArray(i))throw new Error('"data" parts expect an array value.');return{type:"data",value:i}}},H={code:"3",name:"error",parse:i=>{if(typeof i!="string")throw new Error('"error" parts expect a string value.');return{type:"error",value:i}}},U={code:"4",name:"assistant_message",parse:i=>{if(i==null||typeof i!="object"||!("id"in i)||!("role"in i)||!("content"in i)||typeof i.id!="string"||typeof i.role!="string"||i.role!=="assistant"||!Array.isArray(i.content)||!i.content.every(e=>e!=null&&typeof e=="object"&&"type"in e&&e.type==="text"&&"text"in e&&e.text!=null&&typeof e.text=="object"&&"value"in e.text&&typeof e.text.value=="string"))throw new Error('"assistant_message" parts expect an object with an "id", "role", and "content" property.');return{type:"assistant_message",value:i}}},V={code:"5",name:"assistant_control_data",parse:i=>{if(i==null||typeof i!="object"||!("threadId"in i)||!("messageId"in i)||typeof i.threadId!="string"||typeof i.messageId!="string")throw new Error('"assistant_control_data" parts expect an object with a "threadId" and "messageId" property.');return{type:"assistant_control_data",value:{threadId:i.threadId,messageId:i.messageId}}}},J={code:"6",name:"data_message",parse:i=>{if(i==null||typeof i!="object"||!("role"in i)||!("data"in i)||typeof i.role!="string"||i.role!=="data")throw new Error('"data_message" parts expect an object with a "role" and "data" property.');return{type:"data_message",value:i}}},W={code:"7",name:"tool_calls",parse:i=>{if(i==null||typeof i!="object"||!("tool_calls"in i)||typeof i.tool_calls!="object"||i.tool_calls==null||!Array.isArray(i.tool_calls)||i.tool_calls.some(e=>e==null||typeof e!="object"||!("id"in e)||typeof e.id!="string"||!("type"in e)||typeof e.type!="string"||!("function"in e)||e.function==null||typeof e.function!="object"||!("arguments"in e.function)||typeof e.function.name!="string"||typeof e.function.arguments!="string"))throw new Error('"tool_calls" parts expect an object with a ToolCallPayload.');return{type:"tool_calls",value:i}}},G={code:"8",name:"message_annotations",parse:i=>{if(!Array.isArray(i))throw new Error('"message_annotations" parts expect an array value.');return{type:"message_annotations",value:i}}},X={code:"9",name:"tool_call",parse:i=>{if(i==null||typeof i!="object"||!("toolCallId"in i)||typeof i.toolCallId!="string"||!("toolName"in i)||typeof i.toolName!="string"||!("args"in i)||typeof i.args!="object")throw new Error('"tool_call" parts expect an object with a "toolCallId", "toolName", and "args" property.');return{type:"tool_call",value:i}}},K={code:"a",name:"tool_result",parse:i=>{if(i==null||typeof i!="object"||!("toolCallId"in i)||typeof i.toolCallId!="string"||!("toolName"in i)||typeof i.toolName!="string"||!("args"in i)||typeof i.args!="object"||!("result"in i))throw new Error('"tool_result" parts expect an object with a "toolCallId", "toolName", "args", and "result" property.');return{type:"tool_result",value:i}}},Y={code:"b",name:"tool_call_streaming_start",parse:i=>{if(i==null||typeof i!="object"||!("toolCallId"in i)||typeof i.toolCallId!="string"||!("toolName"in i)||typeof i.toolName!="string")throw new Error('"tool_call_streaming_start" parts expect an object with a "toolCallId" and "toolName" property.');return{type:"tool_call_streaming_start",value:i}}},ee={code:"c",name:"tool_call_delta",parse:i=>{if(i==null||typeof i!="object"||!("toolCallId"in i)||typeof i.toolCallId!="string"||!("argsTextDelta"in i)||typeof i.argsTextDelta!="string")throw new Error('"tool_call_delta" parts expect an object with a "toolCallId" and "argsTextDelta" property.');return{type:"tool_call_delta",value:i}}},It=[D,F,Q,H,U,V,J,W,G,X,K,Y,ee],St={[D.code]:D,[F.code]:F,[Q.code]:Q,[H.code]:H,[U.code]:U,[V.code]:V,[J.code]:J,[W.code]:W,[G.code]:G,[X.code]:X,[K.code]:K,[Y.code]:Y,[ee.code]:ee};D.name+"",D.code,F.name+"",F.code,Q.name+"",Q.code,H.name+"",H.code,U.name+"",U.code,V.name+"",V.code,J.name+"",J.code,W.name+"",W.code,G.name+"",G.code,X.name+"",X.code,K.name+"",K.code,Y.name+"",Y.code,ee.name+"",ee.code;var zt=It.map(i=>i.code),Rt=i=>{const e=i.indexOf(":");if(e===-1)throw new Error("Failed to parse stream string. No separator found.");const t=i.slice(0,e);if(!zt.includes(t))throw new Error(`Failed to parse stream string. Invalid code ${t}.`);const r=t,n=i.slice(e+1),s=JSON.parse(n);return St[r].parse(s)},At=10;function Ct(i,e){const t=new Uint8Array(e);let r=0;for(const n of i)t.set(n,r),r+=n.length;return i.length=0,t}async function*Et(i,{isAborted:e}={}){const t=new TextDecoder,r=[];let n=0;for(;;){const{value:s}=await i.read();if(s&&(r.push(s),n+=s.length,s[s.length-1]!==At))continue;if(r.length===0)break;const o=Ct(r,n);n=0;const l=t.decode(o,{stream:!0}).split(`
`).filter(a=>a!=="").map(Rt);for(const a of l)yield a;if(e!=null&&e()){i.cancel();break}}}function jt({api:i,threadId:e,credentials:t,headers:r,body:n,onError:s}){const o=v([]),l=v(""),a=v(void 0),p=v("awaiting_message"),c=v(void 0),u=b=>{o.value=b(o.value)},d=b=>{a.value=b,o.value=[]},f=b=>{var _;l.value=(_=b==null?void 0:b.target)==null?void 0:_.value},h=Ce(()=>p.value==="in_progress"),x=v(null),w=Ce(()=>()=>{x.value&&(x.value.abort(),x.value=null)}),B=async(b,_)=>{var R,$e,Te,Ie;p.value="in_progress";const nt={...b,id:(R=b.id)!=null?R:Be()};u($=>[...$,nt]),l.value="";const Se=new AbortController;try{x.value=Se;const $=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",...r},body:JSON.stringify({...n,message:b.content,threadId:($e=e??a.value)!=null?$e:null,...(_==null?void 0:_.data)&&{data:_==null?void 0:_.data}}),signal:Se.signal,credentials:t});if(!$.ok)throw new Error((Te=$.statusText)!=null?Te:"An error occurred while sending the message");if(!$.body)throw new Error("The response body is empty");for await(const{type:ze,value:I}of Et($.body.getReader()))switch(ze){case"assistant_message":{o.value=[...o.value,{id:I.id,content:I.content[0].text.value,role:I.role}];break}case"assistant_control_data":{I.threadId&&(a.value=I.threadId),u(A=>{const E=A[A.length-1];return E.id=I.messageId,[...A.slice(0,-1),E]});break}case"text":{u(A=>{const E=A[A.length-1];return E.content+=I,[...A.slice(0,-1),E]});break}case"data_message":{u(A=>{var E;return[...A,{id:(E=I.id)!=null?E:Be(),role:"data",content:"",data:I.data}]});break}case"error":c.value=new Error(I);default:{console.error("Unknown message type:",ze);break}}}catch($){if(Tt($)&&((Ie=x.value)!=null&&Ie.signal.aborted)){x.value=null;return}s&&$ instanceof Error&&s($),c.value=$}finally{x.value=null,p.value="awaiting_message"}},se=async(b,_)=>{var R;(R=b==null?void 0:b.preventDefault)==null||R.call(b),l.value&&B({role:"user",content:l.value},_)};return{append:B,messages:o,setMessages:u,threadId:ot(a),setThreadId:d,input:l,handleInputChange:f,handleSubmit:se,isSending:h,status:p,error:c,stop:w}}function me(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let L=me();function Qe(i){L=i}const He=/[&<>"']/,vt=new RegExp(He.source,"g"),Ue=/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,Pt=new RegExp(Ue.source,"g"),Lt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Me=i=>Lt[i];function y(i,e){if(e){if(He.test(i))return i.replace(vt,Me)}else if(Ue.test(i))return i.replace(Pt,Me);return i}const Bt=/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;function Mt(i){return i.replace(Bt,(e,t)=>(t=t.toLowerCase(),t==="colon"?":":t.charAt(0)==="#"?t.charAt(1)==="x"?String.fromCharCode(parseInt(t.substring(2),16)):String.fromCharCode(+t.substring(1)):""))}const Nt=/(^|[^\[])\^/g;function m(i,e){let t=typeof i=="string"?i:i.source;e=e||"";const r={replace:(n,s)=>{let o=typeof s=="string"?s:s.source;return o=o.replace(Nt,"$1"),t=t.replace(n,o),r},getRegex:()=>new RegExp(t,e)};return r}function Ne(i){try{i=encodeURI(i).replace(/%25/g,"%")}catch{return null}return i}const q={exec:()=>null};function Oe(i,e){const t=i.replace(/\|/g,(s,o,l)=>{let a=!1,p=o;for(;--p>=0&&l[p]==="\\";)a=!a;return a?"|":" |"}),r=t.split(/ \|/);let n=0;if(r[0].trim()||r.shift(),r.length>0&&!r[r.length-1].trim()&&r.pop(),e)if(r.length>e)r.splice(e);else for(;r.length<e;)r.push("");for(;n<r.length;n++)r[n]=r[n].trim().replace(/\\\|/g,"|");return r}function N(i,e,t){const r=i.length;if(r===0)return"";let n=0;for(;n<r;){const s=i.charAt(r-n-1);if(s===e&&!t)n++;else if(s!==e&&t)n++;else break}return i.slice(0,r-n)}function Ot(i,e){if(i.indexOf(e[1])===-1)return-1;let t=0;for(let r=0;r<i.length;r++)if(i[r]==="\\")r++;else if(i[r]===e[0])t++;else if(i[r]===e[1]&&(t--,t<0))return r;return-1}function qe(i,e,t,r){const n=e.href,s=e.title?y(e.title):null,o=i[1].replace(/\\([\[\]])/g,"$1");if(i[0].charAt(0)!=="!"){r.state.inLink=!0;const l={type:"link",raw:t,href:n,title:s,text:o,tokens:r.inlineTokens(o)};return r.state.inLink=!1,l}return{type:"image",raw:t,href:n,title:s,text:y(o)}}function qt(i,e){const t=i.match(/^(\s+)(?:```)/);if(t===null)return e;const r=t[1];return e.split(`
`).map(n=>{const s=n.match(/^\s+/);if(s===null)return n;const[o]=s;return o.length>=r.length?n.slice(r.length):n}).join(`
`)}class ae{constructor(e){k(this,"options");k(this,"rules");k(this,"lexer");this.options=e||L}space(e){const t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){const t=this.rules.block.code.exec(e);if(t){const r=t[0].replace(/^ {1,4}/gm,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?r:N(r,`
`)}}}fences(e){const t=this.rules.block.fences.exec(e);if(t){const r=t[0],n=qt(r,t[3]||"");return{type:"code",raw:r,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:n}}}heading(e){const t=this.rules.block.heading.exec(e);if(t){let r=t[2].trim();if(/#$/.test(r)){const n=N(r,"#");(this.options.pedantic||!n||/ $/.test(n))&&(r=n.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(e){const t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:N(t[0],`
`)}}blockquote(e){const t=this.rules.block.blockquote.exec(e);if(t){let r=N(t[0],`
`).split(`
`),n="",s="";const o=[];for(;r.length>0;){let l=!1;const a=[];let p;for(p=0;p<r.length;p++)if(/^ {0,3}>/.test(r[p]))a.push(r[p]),l=!0;else if(!l)a.push(r[p]);else break;r=r.slice(p);const c=a.join(`
`),u=c.replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,`
    $1`).replace(/^ {0,3}>[ \t]?/gm,"");n=n?`${n}
${c}`:c,s=s?`${s}
${u}`:u;const d=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(u,o,!0),this.lexer.state.top=d,r.length===0)break;const f=o[o.length-1];if((f==null?void 0:f.type)==="code")break;if((f==null?void 0:f.type)==="blockquote"){const h=f,x=h.raw+`
`+r.join(`
`),w=this.blockquote(x);o[o.length-1]=w,n=n.substring(0,n.length-h.raw.length)+w.raw,s=s.substring(0,s.length-h.text.length)+w.text;break}else if((f==null?void 0:f.type)==="list"){const h=f,x=h.raw+`
`+r.join(`
`),w=this.list(x);o[o.length-1]=w,n=n.substring(0,n.length-f.raw.length)+w.raw,s=s.substring(0,s.length-h.raw.length)+w.raw,r=x.substring(o[o.length-1].raw.length).split(`
`);continue}}return{type:"blockquote",raw:n,tokens:o,text:s}}}list(e){let t=this.rules.block.list.exec(e);if(t){let r=t[1].trim();const n=r.length>1,s={type:"list",raw:"",ordered:n,start:n?+r.slice(0,-1):"",loose:!1,items:[]};r=n?`\\d{1,9}\\${r.slice(-1)}`:`\\${r}`,this.options.pedantic&&(r=n?r:"[*+-]");const o=new RegExp(`^( {0,3}${r})((?:[	 ][^\\n]*)?(?:\\n|$))`);let l=!1;for(;e;){let a=!1,p="",c="";if(!(t=o.exec(e))||this.rules.block.hr.test(e))break;p=t[0],e=e.substring(p.length);let u=t[2].split(`
`,1)[0].replace(/^\t+/,B=>" ".repeat(3*B.length)),d=e.split(`
`,1)[0],f=!u.trim(),h=0;if(this.options.pedantic?(h=2,c=u.trimStart()):f?h=t[1].length+1:(h=t[2].search(/[^ ]/),h=h>4?1:h,c=u.slice(h),h+=t[1].length),f&&/^ *$/.test(d)&&(p+=d+`
`,e=e.substring(d.length+1),a=!0),!a){const B=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ 	][^\\n]*)?(?:\\n|$))`),se=new RegExp(`^ {0,${Math.min(3,h-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),b=new RegExp(`^ {0,${Math.min(3,h-1)}}(?:\`\`\`|~~~)`),_=new RegExp(`^ {0,${Math.min(3,h-1)}}#`);for(;e;){const R=e.split(`
`,1)[0];if(d=R,this.options.pedantic&&(d=d.replace(/^ {1,4}(?=( {4})*[^ ])/g,"  ")),b.test(d)||_.test(d)||B.test(d)||se.test(e))break;if(d.search(/[^ ]/)>=h||!d.trim())c+=`
`+d.slice(h);else{if(f||u.search(/[^ ]/)>=4||b.test(u)||_.test(u)||se.test(u))break;c+=`
`+d}!f&&!d.trim()&&(f=!0),p+=R+`
`,e=e.substring(R.length+1),u=d.slice(h)}}s.loose||(l?s.loose=!0:/\n *\n *$/.test(p)&&(l=!0));let x=null,w;this.options.gfm&&(x=/^\[[ xX]\] /.exec(c),x&&(w=x[0]!=="[ ] ",c=c.replace(/^\[[ xX]\] +/,""))),s.items.push({type:"list_item",raw:p,task:!!x,checked:w,loose:!1,text:c,tokens:[]}),s.raw+=p}s.items[s.items.length-1].raw=s.items[s.items.length-1].raw.trimEnd(),s.items[s.items.length-1].text=s.items[s.items.length-1].text.trimEnd(),s.raw=s.raw.trimEnd();for(let a=0;a<s.items.length;a++)if(this.lexer.state.top=!1,s.items[a].tokens=this.lexer.blockTokens(s.items[a].text,[]),!s.loose){const p=s.items[a].tokens.filter(u=>u.type==="space"),c=p.length>0&&p.some(u=>/\n.*\n/.test(u.raw));s.loose=c}if(s.loose)for(let a=0;a<s.items.length;a++)s.items[a].loose=!0;return s}}html(e){const t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:t[0]}}def(e){const t=this.rules.block.def.exec(e);if(t){const r=t[1].toLowerCase().replace(/\s+/g," "),n=t[2]?t[2].replace(/^<(.*)>$/,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:r,raw:t[0],href:n,title:s}}}table(e){const t=this.rules.block.table.exec(e);if(!t||!/[:|]/.test(t[2]))return;const r=Oe(t[1]),n=t[2].replace(/^\||\| *$/g,"").split("|"),s=t[3]&&t[3].trim()?t[3].replace(/\n[ \t]*$/,"").split(`
`):[],o={type:"table",raw:t[0],header:[],align:[],rows:[]};if(r.length===n.length){for(const l of n)/^ *-+: *$/.test(l)?o.align.push("right"):/^ *:-+: *$/.test(l)?o.align.push("center"):/^ *:-+ *$/.test(l)?o.align.push("left"):o.align.push(null);for(let l=0;l<r.length;l++)o.header.push({text:r[l],tokens:this.lexer.inline(r[l]),header:!0,align:o.align[l]});for(const l of s)o.rows.push(Oe(l,o.header.length).map((a,p)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:o.align[p]})));return o}}lheading(e){const t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:t[2].charAt(0)==="="?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){const t=this.rules.block.paragraph.exec(e);if(t){const r=t[1].charAt(t[1].length-1)===`
`?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:r,tokens:this.lexer.inline(r)}}}text(e){const t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){const t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:y(t[1])}}tag(e){const t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&/^<a /i.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&/^<\/a>/i.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&/^<(pre|code|kbd|script)(\s|>)/i.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&/^<\/(pre|code|kbd|script)(\s|>)/i.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){const t=this.rules.inline.link.exec(e);if(t){const r=t[2].trim();if(!this.options.pedantic&&/^</.test(r)){if(!/>$/.test(r))return;const o=N(r.slice(0,-1),"\\");if((r.length-o.length)%2===0)return}else{const o=Ot(t[2],"()");if(o>-1){const a=(t[0].indexOf("!")===0?5:4)+t[1].length+o;t[2]=t[2].substring(0,o),t[0]=t[0].substring(0,a).trim(),t[3]=""}}let n=t[2],s="";if(this.options.pedantic){const o=/^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(n);o&&(n=o[1],s=o[3])}else s=t[3]?t[3].slice(1,-1):"";return n=n.trim(),/^</.test(n)&&(this.options.pedantic&&!/>$/.test(r)?n=n.slice(1):n=n.slice(1,-1)),qe(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer)}}reflink(e,t){let r;if((r=this.rules.inline.reflink.exec(e))||(r=this.rules.inline.nolink.exec(e))){const n=(r[2]||r[1]).replace(/\s+/g," "),s=t[n.toLowerCase()];if(!s){const o=r[0].charAt(0);return{type:"text",raw:o,text:o}}return qe(r,s,r[0],this.lexer)}}emStrong(e,t,r=""){let n=this.rules.inline.emStrongLDelim.exec(e);if(!n||n[3]&&r.match(/[\p{L}\p{N}]/u))return;if(!(n[1]||n[2]||"")||!r||this.rules.inline.punctuation.exec(r)){const o=[...n[0]].length-1;let l,a,p=o,c=0;const u=n[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,t=t.slice(-1*e.length+o);(n=u.exec(t))!=null;){if(l=n[1]||n[2]||n[3]||n[4]||n[5]||n[6],!l)continue;if(a=[...l].length,n[3]||n[4]){p+=a;continue}else if((n[5]||n[6])&&o%3&&!((o+a)%3)){c+=a;continue}if(p-=a,p>0)continue;a=Math.min(a,a+p+c);const d=[...n[0]][0].length,f=e.slice(0,o+n.index+d+a);if(Math.min(o,a)%2){const x=f.slice(1,-1);return{type:"em",raw:f,text:x,tokens:this.lexer.inlineTokens(x)}}const h=f.slice(2,-2);return{type:"strong",raw:f,text:h,tokens:this.lexer.inlineTokens(h)}}}}codespan(e){const t=this.rules.inline.code.exec(e);if(t){let r=t[2].replace(/\n/g," ");const n=/[^ ]/.test(r),s=/^ /.test(r)&&/ $/.test(r);return n&&s&&(r=r.substring(1,r.length-1)),r=y(r,!0),{type:"codespan",raw:t[0],text:r}}}br(e){const t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){const t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){const t=this.rules.inline.autolink.exec(e);if(t){let r,n;return t[2]==="@"?(r=y(t[1]),n="mailto:"+r):(r=y(t[1]),n=r),{type:"link",raw:t[0],text:r,href:n,tokens:[{type:"text",raw:r,text:r}]}}}url(e){var r;let t;if(t=this.rules.inline.url.exec(e)){let n,s;if(t[2]==="@")n=y(t[0]),s="mailto:"+n;else{let o;do o=t[0],t[0]=((r=this.rules.inline._backpedal.exec(t[0]))==null?void 0:r[0])??"";while(o!==t[0]);n=y(t[0]),t[1]==="www."?s="http://"+t[0]:s=t[0]}return{type:"link",raw:t[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(e){const t=this.rules.inline.text.exec(e);if(t){let r;return this.lexer.state.inRawBlock?r=t[0]:r=y(t[0]),{type:"text",raw:t[0],text:r}}}}const Zt=/^(?: *(?:\n|$))+/,Dt=/^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,Ft=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,ne=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Qt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,Ve=/(?:[*+-]|\d{1,9}[.)])/,Je=m(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/).replace(/bull/g,Ve).replace(/blockCode/g,/ {4}/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).getRegex(),ke=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Ht=/^[^\n]+/,xe=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Ut=m(/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/).replace("label",xe).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Vt=m(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,Ve).getRegex(),ue="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",be=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Jt=m("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))","i").replace("comment",be).replace("tag",ue).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),We=m(ke).replace("hr",ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ue).getRegex(),Wt=m(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",We).getRegex(),ye={blockquote:Wt,code:Dt,def:Ut,fences:Ft,heading:Qt,hr:ne,html:Jt,lheading:Je,list:Vt,newline:Zt,paragraph:We,table:q,text:Ht},Ze=m("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code"," {4}[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ue).getRegex(),Gt={...ye,table:Ze,paragraph:m(ke).replace("hr",ne).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ze).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",ue).getRegex()},Xt={...ye,html:m(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",be).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:q,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:m(ke).replace("hr",ne).replace("heading",` *#{1,6} *[^
]`).replace("lheading",Je).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Ge=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Kt=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Xe=/^( {2,}|\\)\n(?!\s*$)/,Yt=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,re="\\p{P}\\p{S}",en=m(/^((?![*_])[\spunctuation])/,"u").replace(/punctuation/g,re).getRegex(),tn=/\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g,nn=m(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/,"u").replace(/punct/g,re).getRegex(),rn=m("^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)[punct](\\*+)(?=[\\s]|$)|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])|[\\s](\\*+)(?!\\*)(?=[punct])|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])|[^punct\\s](\\*+)(?=[^punct\\s])","gu").replace(/punct/g,re).getRegex(),sn=m("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\\s]|$)|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)|(?!_)[punct\\s](_+)(?=[^punct\\s])|[\\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])","gu").replace(/punct/g,re).getRegex(),on=m(/\\([punct])/,"gu").replace(/punct/g,re).getRegex(),ln=m(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),an=m(be).replace("(?:-->|$)","-->").getRegex(),cn=m("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",an).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),ce=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,pn=m(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",ce).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Ke=m(/^!?\[(label)\]\[(ref)\]/).replace("label",ce).replace("ref",xe).getRegex(),Ye=m(/^!?\[(ref)\](?:\[\])?/).replace("ref",xe).getRegex(),un=m("reflink|nolink(?!\\()","g").replace("reflink",Ke).replace("nolink",Ye).getRegex(),we={_backpedal:q,anyPunctuation:on,autolink:ln,blockSkip:tn,br:Xe,code:Kt,del:q,emStrongLDelim:nn,emStrongRDelimAst:rn,emStrongRDelimUnd:sn,escape:Ge,link:pn,nolink:Ye,punctuation:en,reflink:Ke,reflinkSearch:un,tag:cn,text:Yt,url:q},hn={...we,link:m(/^!?\[(label)\]\((.*?)\)/).replace("label",ce).getRegex(),reflink:m(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",ce).getRegex()},fe={...we,escape:m(Ge).replace("])","~|])").getRegex(),url:m(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},fn={...fe,br:m(Xe).replace("{2,}","*").getRegex(),text:m(fe.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},le={normal:ye,gfm:Gt,pedantic:Xt},O={normal:we,gfm:fe,breaks:fn,pedantic:hn};class S{constructor(e){k(this,"tokens");k(this,"options");k(this,"state");k(this,"tokenizer");k(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=e||L,this.options.tokenizer=this.options.tokenizer||new ae,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const t={block:le.normal,inline:O.normal};this.options.pedantic?(t.block=le.pedantic,t.inline=O.pedantic):this.options.gfm&&(t.block=le.gfm,this.options.breaks?t.inline=O.breaks:t.inline=O.gfm),this.tokenizer.rules=t}static get rules(){return{block:le,inline:O}}static lex(e,t){return new S(t).lex(e)}static lexInline(e,t){return new S(t).inlineTokens(e)}lex(e){e=e.replace(/\r\n|\r/g,`
`),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){const r=this.inlineQueue[t];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],r=!1){this.options.pedantic?e=e.replace(/\t/g,"    ").replace(/^ +$/gm,""):e=e.replace(/^( *)(\t+)/gm,(l,a,p)=>a+"    ".repeat(p.length));let n,s,o;for(;e;)if(!(this.options.extensions&&this.options.extensions.block&&this.options.extensions.block.some(l=>(n=l.call({lexer:this},e,t))?(e=e.substring(n.raw.length),t.push(n),!0):!1))){if(n=this.tokenizer.space(e)){e=e.substring(n.raw.length),n.raw.length===1&&t.length>0?t[t.length-1].raw+=`
`:t.push(n);continue}if(n=this.tokenizer.code(e)){e=e.substring(n.raw.length),s=t[t.length-1],s&&(s.type==="paragraph"||s.type==="text")?(s.raw+=`
`+n.raw,s.text+=`
`+n.text,this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n);continue}if(n=this.tokenizer.fences(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.heading(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.hr(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.blockquote(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.list(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.html(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.def(e)){e=e.substring(n.raw.length),s=t[t.length-1],s&&(s.type==="paragraph"||s.type==="text")?(s.raw+=`
`+n.raw,s.text+=`
`+n.raw,this.inlineQueue[this.inlineQueue.length-1].src=s.text):this.tokens.links[n.tag]||(this.tokens.links[n.tag]={href:n.href,title:n.title});continue}if(n=this.tokenizer.table(e)){e=e.substring(n.raw.length),t.push(n);continue}if(n=this.tokenizer.lheading(e)){e=e.substring(n.raw.length),t.push(n);continue}if(o=e,this.options.extensions&&this.options.extensions.startBlock){let l=1/0;const a=e.slice(1);let p;this.options.extensions.startBlock.forEach(c=>{p=c.call({lexer:this},a),typeof p=="number"&&p>=0&&(l=Math.min(l,p))}),l<1/0&&l>=0&&(o=e.substring(0,l+1))}if(this.state.top&&(n=this.tokenizer.paragraph(o))){s=t[t.length-1],r&&(s==null?void 0:s.type)==="paragraph"?(s.raw+=`
`+n.raw,s.text+=`
`+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n),r=o.length!==e.length,e=e.substring(n.raw.length);continue}if(n=this.tokenizer.text(e)){e=e.substring(n.raw.length),s=t[t.length-1],s&&s.type==="text"?(s.raw+=`
`+n.raw,s.text+=`
`+n.text,this.inlineQueue.pop(),this.inlineQueue[this.inlineQueue.length-1].src=s.text):t.push(n);continue}if(e){const l="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(l);break}else throw new Error(l)}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){let r,n,s,o=e,l,a,p;if(this.tokens.links){const c=Object.keys(this.tokens.links);if(c.length>0)for(;(l=this.tokenizer.rules.inline.reflinkSearch.exec(o))!=null;)c.includes(l[0].slice(l[0].lastIndexOf("[")+1,-1))&&(o=o.slice(0,l.index)+"["+"a".repeat(l[0].length-2)+"]"+o.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(l=this.tokenizer.rules.inline.blockSkip.exec(o))!=null;)o=o.slice(0,l.index)+"["+"a".repeat(l[0].length-2)+"]"+o.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);for(;(l=this.tokenizer.rules.inline.anyPunctuation.exec(o))!=null;)o=o.slice(0,l.index)+"++"+o.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;e;)if(a||(p=""),a=!1,!(this.options.extensions&&this.options.extensions.inline&&this.options.extensions.inline.some(c=>(r=c.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))){if(r=this.tokenizer.escape(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.tag(e)){e=e.substring(r.raw.length),n=t[t.length-1],n&&r.type==="text"&&n.type==="text"?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if(r=this.tokenizer.link(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length),n=t[t.length-1],n&&r.type==="text"&&n.type==="text"?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if(r=this.tokenizer.emStrong(e,o,p)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.codespan(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.br(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.del(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.autolink(e)){e=e.substring(r.raw.length),t.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}if(s=e,this.options.extensions&&this.options.extensions.startInline){let c=1/0;const u=e.slice(1);let d;this.options.extensions.startInline.forEach(f=>{d=f.call({lexer:this},u),typeof d=="number"&&d>=0&&(c=Math.min(c,d))}),c<1/0&&c>=0&&(s=e.substring(0,c+1))}if(r=this.tokenizer.inlineText(s)){e=e.substring(r.raw.length),r.raw.slice(-1)!=="_"&&(p=r.raw.slice(-1)),a=!0,n=t[t.length-1],n&&n.type==="text"?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if(e){const c="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return t}}class pe{constructor(e){k(this,"options");k(this,"parser");this.options=e||L}space(e){return""}code({text:e,lang:t,escaped:r}){var o;const n=(o=(t||"").match(/^\S*/))==null?void 0:o[0],s=e.replace(/\n$/,"")+`
`;return n?'<pre><code class="language-'+y(n)+'">'+(r?s:y(s,!0))+`</code></pre>
`:"<pre><code>"+(r?s:y(s,!0))+`</code></pre>
`}blockquote({tokens:e}){return`<blockquote>
${this.parser.parse(e)}</blockquote>
`}html({text:e}){return e}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
`}hr(e){return`<hr>
`}list(e){const t=e.ordered,r=e.start;let n="";for(let l=0;l<e.items.length;l++){const a=e.items[l];n+=this.listitem(a)}const s=t?"ol":"ul",o=t&&r!==1?' start="'+r+'"':"";return"<"+s+o+`>
`+n+"</"+s+`>
`}listitem(e){let t="";if(e.task){const r=this.checkbox({checked:!!e.checked});e.loose?e.tokens.length>0&&e.tokens[0].type==="paragraph"?(e.tokens[0].text=r+" "+e.tokens[0].text,e.tokens[0].tokens&&e.tokens[0].tokens.length>0&&e.tokens[0].tokens[0].type==="text"&&(e.tokens[0].tokens[0].text=r+" "+e.tokens[0].tokens[0].text)):e.tokens.unshift({type:"text",raw:r+" ",text:r+" "}):t+=r+" "}return t+=this.parser.parse(e.tokens,!!e.loose),`<li>${t}</li>
`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
`}table(e){let t="",r="";for(let s=0;s<e.header.length;s++)r+=this.tablecell(e.header[s]);t+=this.tablerow({text:r});let n="";for(let s=0;s<e.rows.length;s++){const o=e.rows[s];r="";for(let l=0;l<o.length;l++)r+=this.tablecell(o[l]);n+=this.tablerow({text:r})}return n&&(n=`<tbody>${n}</tbody>`),`<table>
<thead>
`+t+`</thead>
`+n+`</table>
`}tablerow({text:e}){return`<tr>
${e}</tr>
`}tablecell(e){const t=this.parser.parseInline(e.tokens),r=e.header?"th":"td";return(e.align?`<${r} align="${e.align}">`:`<${r}>`)+t+`</${r}>
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${e}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:r}){const n=this.parser.parseInline(r),s=Ne(e);if(s===null)return n;e=s;let o='<a href="'+e+'"';return t&&(o+=' title="'+t+'"'),o+=">"+n+"</a>",o}image({href:e,title:t,text:r}){const n=Ne(e);if(n===null)return r;e=n;let s=`<img src="${e}" alt="${r}"`;return t&&(s+=` title="${t}"`),s+=">",s}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):e.text}}class _e{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}}class z{constructor(e){k(this,"options");k(this,"renderer");k(this,"textRenderer");this.options=e||L,this.options.renderer=this.options.renderer||new pe,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new _e}static parse(e,t){return new z(t).parse(e)}static parseInline(e,t){return new z(t).parseInline(e)}parse(e,t=!0){let r="";for(let n=0;n<e.length;n++){const s=e[n];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]){const l=s,a=this.options.extensions.renderers[l.type].call({parser:this},l);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(l.type)){r+=a||"";continue}}const o=s;switch(o.type){case"space":{r+=this.renderer.space(o);continue}case"hr":{r+=this.renderer.hr(o);continue}case"heading":{r+=this.renderer.heading(o);continue}case"code":{r+=this.renderer.code(o);continue}case"table":{r+=this.renderer.table(o);continue}case"blockquote":{r+=this.renderer.blockquote(o);continue}case"list":{r+=this.renderer.list(o);continue}case"html":{r+=this.renderer.html(o);continue}case"paragraph":{r+=this.renderer.paragraph(o);continue}case"text":{let l=o,a=this.renderer.text(l);for(;n+1<e.length&&e[n+1].type==="text";)l=e[++n],a+=`
`+this.renderer.text(l);t?r+=this.renderer.paragraph({type:"paragraph",raw:a,text:a,tokens:[{type:"text",raw:a,text:a}]}):r+=a;continue}default:{const l='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return r}parseInline(e,t){t=t||this.renderer;let r="";for(let n=0;n<e.length;n++){const s=e[n];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[s.type]){const l=this.options.extensions.renderers[s.type].call({parser:this},s);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type)){r+=l||"";continue}}const o=s;switch(o.type){case"escape":{r+=t.text(o);break}case"html":{r+=t.html(o);break}case"link":{r+=t.link(o);break}case"image":{r+=t.image(o);break}case"strong":{r+=t.strong(o);break}case"em":{r+=t.em(o);break}case"codespan":{r+=t.codespan(o);break}case"br":{r+=t.br(o);break}case"del":{r+=t.del(o);break}case"text":{r+=t.text(o);break}default:{const l='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return r}}class Z{constructor(e){k(this,"options");this.options=e||L}preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}}k(Z,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));var C,et,de,tt;class dn{constructor(...e){Ae(this,C);k(this,"defaults",me());k(this,"options",this.setOptions);k(this,"parse",M(this,C,de).call(this,S.lex,z.parse));k(this,"parseInline",M(this,C,de).call(this,S.lexInline,z.parseInline));k(this,"Parser",z);k(this,"Renderer",pe);k(this,"TextRenderer",_e);k(this,"Lexer",S);k(this,"Tokenizer",ae);k(this,"Hooks",Z);this.use(...e)}walkTokens(e,t){var n,s;let r=[];for(const o of e)switch(r=r.concat(t.call(this,o)),o.type){case"table":{const l=o;for(const a of l.header)r=r.concat(this.walkTokens(a.tokens,t));for(const a of l.rows)for(const p of a)r=r.concat(this.walkTokens(p.tokens,t));break}case"list":{const l=o;r=r.concat(this.walkTokens(l.items,t));break}default:{const l=o;(s=(n=this.defaults.extensions)==null?void 0:n.childTokens)!=null&&s[l.type]?this.defaults.extensions.childTokens[l.type].forEach(a=>{const p=l[a].flat(1/0);r=r.concat(this.walkTokens(p,t))}):l.tokens&&(r=r.concat(this.walkTokens(l.tokens,t)))}}return r}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(r=>{const n={...r};if(n.async=this.defaults.async||n.async||!1,r.extensions&&(r.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){const o=t.renderers[s.name];o?t.renderers[s.name]=function(...l){let a=s.renderer.apply(this,l);return a===!1&&(a=o.apply(this,l)),a}:t.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const o=t[s.level];o?o.unshift(s.tokenizer):t[s.level]=[s.tokenizer],s.start&&(s.level==="block"?t.startBlock?t.startBlock.push(s.start):t.startBlock=[s.start]:s.level==="inline"&&(t.startInline?t.startInline.push(s.start):t.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(t.childTokens[s.name]=s.childTokens)}),n.extensions=t),r.renderer){const s=this.defaults.renderer||new pe(this.defaults);for(const o in r.renderer){if(!(o in s))throw new Error(`renderer '${o}' does not exist`);if(["options","parser"].includes(o))continue;const l=o;let a=r.renderer[l];r.useNewRenderer||(a=M(this,C,et).call(this,a,l,s));const p=s[l];s[l]=(...c)=>{let u=a.apply(s,c);return u===!1&&(u=p.apply(s,c)),u||""}}n.renderer=s}if(r.tokenizer){const s=this.defaults.tokenizer||new ae(this.defaults);for(const o in r.tokenizer){if(!(o in s))throw new Error(`tokenizer '${o}' does not exist`);if(["options","rules","lexer"].includes(o))continue;const l=o,a=r.tokenizer[l],p=s[l];s[l]=(...c)=>{let u=a.apply(s,c);return u===!1&&(u=p.apply(s,c)),u}}n.tokenizer=s}if(r.hooks){const s=this.defaults.hooks||new Z;for(const o in r.hooks){if(!(o in s))throw new Error(`hook '${o}' does not exist`);if(o==="options")continue;const l=o,a=r.hooks[l],p=s[l];Z.passThroughHooks.has(o)?s[l]=c=>{if(this.defaults.async)return Promise.resolve(a.call(s,c)).then(d=>p.call(s,d));const u=a.call(s,c);return p.call(s,u)}:s[l]=(...c)=>{let u=a.apply(s,c);return u===!1&&(u=p.apply(s,c)),u}}n.hooks=s}if(r.walkTokens){const s=this.defaults.walkTokens,o=r.walkTokens;n.walkTokens=function(l){let a=[];return a.push(o.call(this,l)),s&&(a=a.concat(s.call(this,l))),a}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return S.lex(e,t??this.defaults)}parser(e,t){return z.parse(e,t??this.defaults)}}C=new WeakSet,et=function(e,t,r){switch(t){case"heading":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,r.parser.parseInline(n.tokens),n.depth,Mt(r.parser.parseInline(n.tokens,r.parser.textRenderer)))};case"code":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,n.text,n.lang,!!n.escaped)};case"table":return function(n){if(!n.type||n.type!==t)return e.apply(this,arguments);let s="",o="";for(let a=0;a<n.header.length;a++)o+=this.tablecell({text:n.header[a].text,tokens:n.header[a].tokens,header:!0,align:n.align[a]});s+=this.tablerow({text:o});let l="";for(let a=0;a<n.rows.length;a++){const p=n.rows[a];o="";for(let c=0;c<p.length;c++)o+=this.tablecell({text:p[c].text,tokens:p[c].tokens,header:!1,align:n.align[c]});l+=this.tablerow({text:o})}return e.call(this,s,l)};case"blockquote":return function(n){if(!n.type||n.type!==t)return e.apply(this,arguments);const s=this.parser.parse(n.tokens);return e.call(this,s)};case"list":return function(n){if(!n.type||n.type!==t)return e.apply(this,arguments);const s=n.ordered,o=n.start,l=n.loose;let a="";for(let p=0;p<n.items.length;p++){const c=n.items[p],u=c.checked,d=c.task;let f="";if(c.task){const h=this.checkbox({checked:!!u});l?c.tokens.length>0&&c.tokens[0].type==="paragraph"?(c.tokens[0].text=h+" "+c.tokens[0].text,c.tokens[0].tokens&&c.tokens[0].tokens.length>0&&c.tokens[0].tokens[0].type==="text"&&(c.tokens[0].tokens[0].text=h+" "+c.tokens[0].tokens[0].text)):c.tokens.unshift({type:"text",text:h+" "}):f+=h+" "}f+=this.parser.parse(c.tokens,l),a+=this.listitem({type:"list_item",raw:f,text:f,task:d,checked:!!u,loose:l,tokens:c.tokens})}return e.call(this,a,s,o)};case"html":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,n.text,n.block)};case"paragraph":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,this.parser.parseInline(n.tokens))};case"escape":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,n.text)};case"link":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,n.href,n.title,this.parser.parseInline(n.tokens))};case"image":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,n.href,n.title,n.text)};case"strong":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,this.parser.parseInline(n.tokens))};case"em":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,this.parser.parseInline(n.tokens))};case"codespan":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,n.text)};case"del":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,this.parser.parseInline(n.tokens))};case"text":return function(n){return!n.type||n.type!==t?e.apply(this,arguments):e.call(this,n.text)}}return e},de=function(e,t){return(r,n)=>{const s={...n},o={...this.defaults,...s};this.defaults.async===!0&&s.async===!1&&(o.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),o.async=!0);const l=M(this,C,tt).call(this,!!o.silent,!!o.async);if(typeof r>"u"||r===null)return l(new Error("marked(): input parameter is undefined or null"));if(typeof r!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(r)+", string expected"));if(o.hooks&&(o.hooks.options=o),o.async)return Promise.resolve(o.hooks?o.hooks.preprocess(r):r).then(a=>e(a,o)).then(a=>o.hooks?o.hooks.processAllTokens(a):a).then(a=>o.walkTokens?Promise.all(this.walkTokens(a,o.walkTokens)).then(()=>a):a).then(a=>t(a,o)).then(a=>o.hooks?o.hooks.postprocess(a):a).catch(l);try{o.hooks&&(r=o.hooks.preprocess(r));let a=e(r,o);o.hooks&&(a=o.hooks.processAllTokens(a)),o.walkTokens&&this.walkTokens(a,o.walkTokens);let p=t(a,o);return o.hooks&&(p=o.hooks.postprocess(p)),p}catch(a){return l(a)}}},tt=function(e,t){return r=>{if(r.message+=`
Please report this to https://github.com/markedjs/marked.`,e){const n="<p>An error occurred:</p><pre>"+y(r.message+"",!0)+"</pre>";return t?Promise.resolve(n):n}if(t)return Promise.reject(r);throw r}};const P=new dn;function g(i,e){return P.parse(i,e)}g.options=g.setOptions=function(i){return P.setOptions(i),g.defaults=P.defaults,Qe(g.defaults),g};g.getDefaults=me;g.defaults=L;g.use=function(...i){return P.use(...i),g.defaults=P.defaults,Qe(g.defaults),g};g.walkTokens=function(i,e){return P.walkTokens(i,e)};g.parseInline=P.parseInline;g.Parser=z;g.parser=z.parse;g.Renderer=pe;g.TextRenderer=_e;g.Lexer=S;g.lexer=S.lex;g.Tokenizer=ae;g.Hooks=Z;g.parse=g;g.options;g.setOptions;g.use;g.walkTokens;g.parseInline;z.parse;S.lex;const gn={key:1,class:"grid grid-rows-[1fr,auto] gap-2 w-96 h-96 max-w-full max-h-[90vh] relative mt-4"},mn={class:"max-h-full flex flex-col-reverse gap-2 overflow-auto"},kn=["innerHTML"],xn=["disabled"],sr=lt({__name:"bubble",setup(i){const e=kt(),t=v(!1),{status:r,messages:n,input:s,handleSubmit:o,handleInputChange:l}=jt({api:`${e.public.aiBaseUrl}/api/roadtrip/run`}),a=p=>p.role==="assistant"?g.parse(p.content):p.content;return at(n,()=>{if(n.value.length){const p=n.value[n.value.length-1];p.role==="data"&&p.data&&ct(p.data)}},{deep:!0}),(p,c)=>{const u=xt,d=yt,f=bt;return j(),ie("div",{class:ve(["fixed flex flex-col items-center bottom-8 left-1/2 -translate-x-1/2 z-40 bg-white px-4 py-2 rounded-lg shadow-md text-sm overscroll-contain",{"cursor-pointer":!T(t)}]),onClick:c[4]||(c[4]=h=>t.value=!0)},[c[5]||(c[5]=oe("p",{class:"text-base font-semibold"},"Spotty",-1)),T(t)?(j(),he(u,{key:0,name:"general/delete",class:"absolute right-4 text-2xl cursor-pointer",onClick:c[0]||(c[0]=Ee(h=>t.value=!1,["stop"]))})):je("",!0),T(t)?(j(),ie("div",gn,[oe("ol",mn,[(j(!0),ie(pt,null,ut(T(n).filter(h=>h.role!=="data").toReversed(),h=>(j(),ie("li",{key:h.id,class:ve(["inline py-1 px-2 rounded-md max-w-80 prose prose-sm",[h.role==="user"?"ml-auto bg-blue-100":"mr-auto bg-gray-100"]]),innerHTML:a(h)},null,10,kn))),128))]),oe("form",{class:"relative",onSubmit:c[3]||(c[3]=Ee((...h)=>T(o)&&T(o)(...h),["prevent"]))},[ht(oe("textarea",{"onUpdate:modelValue":c[1]||(c[1]=h=>dt(s)?s.value=h:null),class:"[field-sizing:content] max-h-[5lh] w-full resize-none rounded-lg",placeholder:"Type your message here...",disabled:T(r)!=="awaiting_message",onInput:c[2]||(c[2]=(...h)=>T(l)&&T(l)(...h))},null,40,xn),[[ft,T(s)]]),gt(f,{class:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center w-8 h-8 rounded-full !p-0"},{default:mt(()=>[T(r)==="awaiting_message"?(j(),he(u,{key:0,name:"general/arrow-right",class:"text-sm",filled:""})):(j(),he(d,{key:1}))]),_:1})],32)])):je("",!0)],2)}}});export{sr as default};
