randmarcomps 1.110.0 → 1.112.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/dist/randmarcomps.js
CHANGED
|
@@ -46057,7 +46057,7 @@ function useAIAssistant({ userId: e, apiKey: t }) {
|
|
|
46057
46057
|
}, [R]), useEffect(() => {
|
|
46058
46058
|
(async () => {
|
|
46059
46059
|
try {
|
|
46060
|
-
const O = await (await fetch("https://docs.google.com/document/d/e/2PACX-1vT-f5SWSJ2BcRUcyiumzT1aPUeC8kyyV7ryJTTymWJWOcRbDRgV5nX6Wyh7HaSPf8rxTY9w63Q2C8rG/pub")).text(), B = new DOMParser().parseFromString(O, "text/html").querySelector(".doc-content").innerHTML.replace(
|
|
46060
|
+
const O = await (await fetch("https://docs.google.com/document/d/e/2PACX-1vT-f5SWSJ2BcRUcyiumzT1aPUeC8kyyV7ryJTTymWJWOcRbDRgV5nX6Wyh7HaSPf8rxTY9w63Q2C8rG/pub")).text(), B = new DOMParser().parseFromString(O, "text/html").querySelector(".doc-content").innerHTML.replace(/__user_id__/g, e);
|
|
46061
46061
|
console.log("google doc fetched: ", B), E(B);
|
|
46062
46062
|
} catch (T) {
|
|
46063
46063
|
console.error("Error fetching system instructions:", T), E("You are a helpful assistant, but cannot help the user right now. They should come back another time.");
|
|
@@ -860,7 +860,7 @@ Hook ${d} was either not provided or not a function.`)}return{name:reactHooksMod
|
|
|
860
860
|
* limitations under the License.
|
|
861
861
|
*/class GoogleGenerativeAI{constructor(t){this.apiKey=t}getGenerativeModel(t,n){if(!t.model)throw new GoogleGenerativeAIError("Must provide a model name. Example: genai.getGenerativeModel({ model: 'my-model-name' })");return new GenerativeModel(this.apiKey,t,n)}getGenerativeModelFromCachedContent(t,n,i){if(!t.name)throw new GoogleGenerativeAIRequestInputError("Cached content must contain a `name` field.");if(!t.model)throw new GoogleGenerativeAIRequestInputError("Cached content must contain a `model` field.");const o=["model","systemInstruction"];for(const u of o)if(n!=null&&n[u]&&t[u]&&(n==null?void 0:n[u])!==t[u]){if(u==="model"){const d=n.model.startsWith("models/")?n.model.replace("models/",""):n.model,f=t.model.startsWith("models/")?t.model.replace("models/",""):t.model;if(d===f)continue}throw new GoogleGenerativeAIRequestInputError(`Different value for "${u}" specified in modelParams (${n[u]}) and cachedContent (${t[u]})`)}const l=Object.assign(Object.assign({},n),{model:t.model,tools:t.tools,toolConfig:t.toolConfig,systemInstruction:t.systemInstruction,cachedContent:t});return new GenerativeModel(this.apiKey,l,i)}}const bodyKey="TheRequestBody";async function fetchApiFunctions(){var e,t;try{const n=await fetch("https://api.randmar.io/swagger/V4/swagger.json");if(!n.ok)throw new Error("Failed to fetch Swagger spec");const i=await n.json(),o=[];for(const[l,u]of Object.entries(i.paths)){const d=["get","post","put","delete"];for(const f of d){const p=u[f];if(!p||p["x-allowed-for-chatbots"]!==!0)continue;const m=l.split("/").filter(Boolean);let g=`${f}_${m.slice(1).join("_")}`;g=g.replace(/[^a-zA-Z0-9_.-]/g,"_"),g.length>60&&(g=g.substring(0,60));const b={},_=[];(e=p.parameters)==null||e.forEach(C=>{b[C.name]={type:C.schema.type,description:C.description||`The ${C.name} parameter`},C.required&&_.push(C.name)});const E=((t=p.parameters)==null?void 0:t.filter(C=>C.in==="path").map(C=>C.name))||[];(f==="post"||f==="put")&&p.requestBody&&(b[bodyKey]={type:SchemaType.STRING,description:p.requestBody.description||"Request body content"},_.push(bodyKey));const R={name:g,description:p.description?`${p.summary}
|
|
862
862
|
|
|
863
|
-
${p.description}`:p.summary||`${f.toUpperCase()} ${m[m.length-1]}`,parameters:{type:SchemaType.OBJECT,properties:b,required:_}},S=async C=>{var A;try{let I=`https://api.randmar.io${l}`;console.log(`[API Function] ${g} called with args:`,C),console.log(`[API Function] Original URL: ${I}`),E.forEach(L=>{const F=`{${L}}`,V=L;I=I.replace(F,C[V])}),console.log(`[API Function] Final URL: ${I}`);const M=localStorage.getItem("access_token"),T={method:f.toUpperCase(),headers:{Authorization:M?`Bearer ${M}`:"","Content-Type":"application/json"}},O=[];if((((A=p.parameters)==null?void 0:A.filter(L=>L.in==="query"))||[]).forEach(L=>{const F=L.name,V=C[F];V&&O.push(`${L.name}=${encodeURIComponent(V)}`)}),O.length>0&&(I+=`?${O.join("&")}`),f==="post"||f==="put"){const F=C[bodyKey];F&&(T.body=F)}console.log(`[API Function] Making request to: ${I}`),console.log("[API Function] Request options:",T);const N=await fetch(I,T);if(console.log(`[API Function] Response status: ${N.status}`),!N.ok){const L=await N.text();throw console.error(`[API Function] Error response: ${L}`),new Error(`Error ${N.status}: ${L}`)}const D=await N.json();console.log("[API Function] Response data:",D);const B=getComponent(l,D);return B?{component:B,summary:JSON.stringify(D,null,2)}:JSON.stringify(D,null,2)}catch(I){return console.error(`Error in ${g}:`,I),`I'm sorry, I couldn't retrieve the requested information. Error: ${I instanceof Error?I.message:"Unknown error"}`}};o.push({declaration:R,handler:S})}}return console.log(o),o}catch(n){return console.error("Error fetching API functions:",n),[]}}const getComponent=(e,t)=>{switch(console.log("getting comp for path",e),e){case"/V4/Partner/{routeApplicationId}/Search":return handleSearchResults(t);default:console.log("no component mapping for path",e);break}return null},handleSearchResults=e=>{if(!Array.isArray(e))return null;const n=e.filter(i=>i.ContentType==="Product").map(i=>i.Content).filter(i=>i.MPN);return n.length==0?null:jsxRuntime.jsx(jsxRuntime.Fragment,{children:n.map(i=>jsxRuntime.jsx("div",{className:"mt-2 mb-2",children:jsxRuntime.jsx(ProductCard,{item:i})}))})};function useAIAssistant({userId:e,apiKey:t}){const[n,i]=React.useState(!1),[o,l]=React.useState(null),[u,d]=React.useState([]),[f,p]=React.useState([]),[m,g]=React.useState([]),[b,_]=React.useState(!0),[E,R]=React.useState(""),S=new GoogleGenerativeAI(t);React.useEffect(()=>{E&&p(M=>[...M,"System instructions updated."])},[E]),React.useEffect(()=>{(async()=>{try{const O=await(await fetch("https://docs.google.com/document/d/e/2PACX-1vT-f5SWSJ2BcRUcyiumzT1aPUeC8kyyV7ryJTTymWJWOcRbDRgV5nX6Wyh7HaSPf8rxTY9w63Q2C8rG/pub")).text(),B=new DOMParser().parseFromString(O,"text/html").querySelector(".doc-content").innerHTML.replace("__user_id__",e);console.log("google doc fetched: ",B),R(B)}catch(T){console.error("Error fetching system instructions:",T),R("You are a helpful assistant, but cannot help the user right now. They should come back another time.")}})()},[]),React.useEffect(()=>{const M=async()=>{try{const O=S.getGenerativeModel({model:"gemini-2.0-flash"}).startChat({generationConfig:{maxOutputTokens:4096},history:[{role:"user",parts:[{text:"Tell me about your instructions. What are the rules that define how you respond?"}]},{role:"model",parts:[{text:E}]}],tools:m.length>0?[{functionDeclarations:m.map(({declaration:j})=>j)}]:[]});l(O)}catch(T){console.error("Error initializing chat:",T)}};o||b||E!==""&&M()},[b,o,E]),React.useEffect(()=>{(async()=>{try{const T=await fetchApiFunctions();g(T)}catch(T){console.error("Error loading API functions:",T)}finally{_(!1)}})()},[]);const C=Object.fromEntries(m.map(({declaration:M,handler:T})=>[M.name,T])),A=async M=>{var O;const T=M.name;if(T in C){const j=C[T],N=M.args||{};if(console.log(`[Function Call] ${T} with args:`,N),!((O=m.find(B=>B.declaration.name===T))==null?void 0:O.declaration)){console.error(`[Function Call] Could not find declaration for ${T}`);return}try{const B=await j(N);let L,F=null,V=!1;if(typeof B=="string"?L=B:(L=B.summary,F=B.component,V=!0),console.log(`[Function Response] ${T} returned:`,L),o){const H={functionResponse:{name:T,response:{content:L}}};if(V&&F){const Z={role:"assistant",content:F,timestamp:new Date,isComponent:!0};d(q=>[...q,Z])}const W={role:"assistant",content:(await o.sendMessage([H])).response.text(),timestamp:new Date};d(Z=>[...Z,W])}}catch(B){console.error("Error executing function:",B);const L={role:"assistant",content:"I encountered an error while processing your request. Please try again.",timestamp:new Date};d(F=>[...F,L])}}else console.error(`Function ${T} not found`)};return{handleSubmitToBot:async M=>{if(M.trim()&&!n&&o){const T={role:"user",content:M,timestamp:new Date};d(O=>[...O,T]),i(!0);try{const j=(await o.sendMessage(M.trim())).response,N=j.functionCalls();if(N&&N.length>0)for(const D of N)await A(D);else{const D={role:"assistant",content:j.text(),timestamp:new Date};d(B=>[...B,D])}}catch(O){console.error("Error sending message:",O);const j={role:"assistant",content:"I'm sorry, I encountered an error processing your request. Please try again later.",timestamp:new Date};d(N=>[...N,j])}finally{i(!1)}}},botMessages:u,botReady:!!o,isProcessingSubmission:n,debugMessages:f}}function _getDefaults(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let _defaults=_getDefaults();function changeDefaults(e){_defaults=e}const noopTest={exec:()=>null};function edit(e,t=""){let n=typeof e=="string"?e:e.source;const i={replace:(o,l)=>{let u=typeof l=="string"?l:l.source;return u=u.replace(other.caret,"$1"),n=n.replace(o,u),i},getRegex:()=>new RegExp(n,t)};return i}const other={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},newline=/^(?:[ \t]*(?:\n|$))+/,blockCode=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,fences=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,bullet=/(?:[*+-]|\d{1,9}[.)])/,lheadingCore=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,lheading=edit(lheadingCore).replace(/bull/g,bullet).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/\|table/g,"").getRegex(),lheadingGfm=edit(lheadingCore).replace(/bull/g,bullet).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),_paragraph=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,blockText=/^[^\n]+/,_blockLabel=/(?!\s*\])(?:\\.|[^\[\]\\])+/,def=edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",_blockLabel).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),list=edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,bullet).getRegex(),_tag="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",_comment=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,html=edit("^ {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",_comment).replace("tag",_tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),paragraph=edit(_paragraph).replace("hr",hr).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",_tag).getRegex(),blockquote=edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",paragraph).getRegex(),blockNormal={blockquote,code:blockCode,def,fences,heading,hr,html,lheading,list,newline,paragraph,table:noopTest,text:blockText},gfmTable=edit("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",hr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\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",_tag).getRegex(),blockGfm={...blockNormal,lheading:lheadingGfm,table:gfmTable,paragraph:edit(_paragraph).replace("hr",hr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",gfmTable).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",_tag).getRegex()},blockPedantic={...blockNormal,html:edit(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",_comment).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:noopTest,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:edit(_paragraph).replace("hr",hr).replace("heading",` *#{1,6} *[^
|
|
863
|
+
${p.description}`:p.summary||`${f.toUpperCase()} ${m[m.length-1]}`,parameters:{type:SchemaType.OBJECT,properties:b,required:_}},S=async C=>{var A;try{let I=`https://api.randmar.io${l}`;console.log(`[API Function] ${g} called with args:`,C),console.log(`[API Function] Original URL: ${I}`),E.forEach(L=>{const F=`{${L}}`,V=L;I=I.replace(F,C[V])}),console.log(`[API Function] Final URL: ${I}`);const M=localStorage.getItem("access_token"),T={method:f.toUpperCase(),headers:{Authorization:M?`Bearer ${M}`:"","Content-Type":"application/json"}},O=[];if((((A=p.parameters)==null?void 0:A.filter(L=>L.in==="query"))||[]).forEach(L=>{const F=L.name,V=C[F];V&&O.push(`${L.name}=${encodeURIComponent(V)}`)}),O.length>0&&(I+=`?${O.join("&")}`),f==="post"||f==="put"){const F=C[bodyKey];F&&(T.body=F)}console.log(`[API Function] Making request to: ${I}`),console.log("[API Function] Request options:",T);const N=await fetch(I,T);if(console.log(`[API Function] Response status: ${N.status}`),!N.ok){const L=await N.text();throw console.error(`[API Function] Error response: ${L}`),new Error(`Error ${N.status}: ${L}`)}const D=await N.json();console.log("[API Function] Response data:",D);const B=getComponent(l,D);return B?{component:B,summary:JSON.stringify(D,null,2)}:JSON.stringify(D,null,2)}catch(I){return console.error(`Error in ${g}:`,I),`I'm sorry, I couldn't retrieve the requested information. Error: ${I instanceof Error?I.message:"Unknown error"}`}};o.push({declaration:R,handler:S})}}return console.log(o),o}catch(n){return console.error("Error fetching API functions:",n),[]}}const getComponent=(e,t)=>{switch(console.log("getting comp for path",e),e){case"/V4/Partner/{routeApplicationId}/Search":return handleSearchResults(t);default:console.log("no component mapping for path",e);break}return null},handleSearchResults=e=>{if(!Array.isArray(e))return null;const n=e.filter(i=>i.ContentType==="Product").map(i=>i.Content).filter(i=>i.MPN);return n.length==0?null:jsxRuntime.jsx(jsxRuntime.Fragment,{children:n.map(i=>jsxRuntime.jsx("div",{className:"mt-2 mb-2",children:jsxRuntime.jsx(ProductCard,{item:i})}))})};function useAIAssistant({userId:e,apiKey:t}){const[n,i]=React.useState(!1),[o,l]=React.useState(null),[u,d]=React.useState([]),[f,p]=React.useState([]),[m,g]=React.useState([]),[b,_]=React.useState(!0),[E,R]=React.useState(""),S=new GoogleGenerativeAI(t);React.useEffect(()=>{E&&p(M=>[...M,"System instructions updated."])},[E]),React.useEffect(()=>{(async()=>{try{const O=await(await fetch("https://docs.google.com/document/d/e/2PACX-1vT-f5SWSJ2BcRUcyiumzT1aPUeC8kyyV7ryJTTymWJWOcRbDRgV5nX6Wyh7HaSPf8rxTY9w63Q2C8rG/pub")).text(),B=new DOMParser().parseFromString(O,"text/html").querySelector(".doc-content").innerHTML.replace(/__user_id__/g,e);console.log("google doc fetched: ",B),R(B)}catch(T){console.error("Error fetching system instructions:",T),R("You are a helpful assistant, but cannot help the user right now. They should come back another time.")}})()},[]),React.useEffect(()=>{const M=async()=>{try{const O=S.getGenerativeModel({model:"gemini-2.0-flash"}).startChat({generationConfig:{maxOutputTokens:4096},history:[{role:"user",parts:[{text:"Tell me about your instructions. What are the rules that define how you respond?"}]},{role:"model",parts:[{text:E}]}],tools:m.length>0?[{functionDeclarations:m.map(({declaration:j})=>j)}]:[]});l(O)}catch(T){console.error("Error initializing chat:",T)}};o||b||E!==""&&M()},[b,o,E]),React.useEffect(()=>{(async()=>{try{const T=await fetchApiFunctions();g(T)}catch(T){console.error("Error loading API functions:",T)}finally{_(!1)}})()},[]);const C=Object.fromEntries(m.map(({declaration:M,handler:T})=>[M.name,T])),A=async M=>{var O;const T=M.name;if(T in C){const j=C[T],N=M.args||{};if(console.log(`[Function Call] ${T} with args:`,N),!((O=m.find(B=>B.declaration.name===T))==null?void 0:O.declaration)){console.error(`[Function Call] Could not find declaration for ${T}`);return}try{const B=await j(N);let L,F=null,V=!1;if(typeof B=="string"?L=B:(L=B.summary,F=B.component,V=!0),console.log(`[Function Response] ${T} returned:`,L),o){const H={functionResponse:{name:T,response:{content:L}}};if(V&&F){const Z={role:"assistant",content:F,timestamp:new Date,isComponent:!0};d(q=>[...q,Z])}const W={role:"assistant",content:(await o.sendMessage([H])).response.text(),timestamp:new Date};d(Z=>[...Z,W])}}catch(B){console.error("Error executing function:",B);const L={role:"assistant",content:"I encountered an error while processing your request. Please try again.",timestamp:new Date};d(F=>[...F,L])}}else console.error(`Function ${T} not found`)};return{handleSubmitToBot:async M=>{if(M.trim()&&!n&&o){const T={role:"user",content:M,timestamp:new Date};d(O=>[...O,T]),i(!0);try{const j=(await o.sendMessage(M.trim())).response,N=j.functionCalls();if(N&&N.length>0)for(const D of N)await A(D);else{const D={role:"assistant",content:j.text(),timestamp:new Date};d(B=>[...B,D])}}catch(O){console.error("Error sending message:",O);const j={role:"assistant",content:"I'm sorry, I encountered an error processing your request. Please try again later.",timestamp:new Date};d(N=>[...N,j])}finally{i(!1)}}},botMessages:u,botReady:!!o,isProcessingSubmission:n,debugMessages:f}}function _getDefaults(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}let _defaults=_getDefaults();function changeDefaults(e){_defaults=e}const noopTest={exec:()=>null};function edit(e,t=""){let n=typeof e=="string"?e:e.source;const i={replace:(o,l)=>{let u=typeof l=="string"?l:l.source;return u=u.replace(other.caret,"$1"),n=n.replace(o,u),i},getRegex:()=>new RegExp(n,t)};return i}const other={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},newline=/^(?:[ \t]*(?:\n|$))+/,blockCode=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,fences=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,hr=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,heading=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,bullet=/(?:[*+-]|\d{1,9}[.)])/,lheadingCore=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,lheading=edit(lheadingCore).replace(/bull/g,bullet).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/\|table/g,"").getRegex(),lheadingGfm=edit(lheadingCore).replace(/bull/g,bullet).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).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/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),_paragraph=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,blockText=/^[^\n]+/,_blockLabel=/(?!\s*\])(?:\\.|[^\[\]\\])+/,def=edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",_blockLabel).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),list=edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,bullet).getRegex(),_tag="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",_comment=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,html=edit("^ {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",_comment).replace("tag",_tag).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),paragraph=edit(_paragraph).replace("hr",hr).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",_tag).getRegex(),blockquote=edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",paragraph).getRegex(),blockNormal={blockquote,code:blockCode,def,fences,heading,hr,html,lheading,list,newline,paragraph,table:noopTest,text:blockText},gfmTable=edit("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",hr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\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",_tag).getRegex(),blockGfm={...blockNormal,lheading:lheadingGfm,table:gfmTable,paragraph:edit(_paragraph).replace("hr",hr).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",gfmTable).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",_tag).getRegex()},blockPedantic={...blockNormal,html:edit(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",_comment).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:noopTest,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:edit(_paragraph).replace("hr",hr).replace("heading",` *#{1,6} *[^
|
|
864
864
|
]`).replace("lheading",lheading).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},escape$1=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,inlineCode=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,br=/^( {2,}|\\)\n(?!\s*$)/,inlineText=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,_punctuation=/[\p{P}\p{S}]/u,_punctuationOrSpace=/[\s\p{P}\p{S}]/u,_notPunctuationOrSpace=/[^\s\p{P}\p{S}]/u,punctuation=edit(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,_punctuationOrSpace).getRegex(),_punctuationGfmStrongEm=/(?!~)[\p{P}\p{S}]/u,_punctuationOrSpaceGfmStrongEm=/(?!~)[\s\p{P}\p{S}]/u,_notPunctuationOrSpaceGfmStrongEm=/(?:[^\s\p{P}\p{S}]|~)/u,blockSkip=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,emStrongLDelimCore=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,emStrongLDelim=edit(emStrongLDelimCore,"u").replace(/punct/g,_punctuation).getRegex(),emStrongLDelimGfm=edit(emStrongLDelimCore,"u").replace(/punct/g,_punctuationGfmStrongEm).getRegex(),emStrongRDelimAstCore="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",emStrongRDelimAst=edit(emStrongRDelimAstCore,"gu").replace(/notPunctSpace/g,_notPunctuationOrSpace).replace(/punctSpace/g,_punctuationOrSpace).replace(/punct/g,_punctuation).getRegex(),emStrongRDelimAstGfm=edit(emStrongRDelimAstCore,"gu").replace(/notPunctSpace/g,_notPunctuationOrSpaceGfmStrongEm).replace(/punctSpace/g,_punctuationOrSpaceGfmStrongEm).replace(/punct/g,_punctuationGfmStrongEm).getRegex(),emStrongRDelimUnd=edit("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,_notPunctuationOrSpace).replace(/punctSpace/g,_punctuationOrSpace).replace(/punct/g,_punctuation).getRegex(),anyPunctuation=edit(/\\(punct)/,"gu").replace(/punct/g,_punctuation).getRegex(),autolink=edit(/^<(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(),_inlineComment=edit(_comment).replace("(?:-->|$)","-->").getRegex(),tag=edit("^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",_inlineComment).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),_inlineLabel=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,link=edit(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/).replace("label",_inlineLabel).replace("href",/<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),reflink=edit(/^!?\[(label)\]\[(ref)\]/).replace("label",_inlineLabel).replace("ref",_blockLabel).getRegex(),nolink=edit(/^!?\[(ref)\](?:\[\])?/).replace("ref",_blockLabel).getRegex(),reflinkSearch=edit("reflink|nolink(?!\\()","g").replace("reflink",reflink).replace("nolink",nolink).getRegex(),inlineNormal={_backpedal:noopTest,anyPunctuation,autolink,blockSkip,br,code:inlineCode,del:noopTest,emStrongLDelim,emStrongRDelimAst,emStrongRDelimUnd,escape:escape$1,link,nolink,punctuation,reflink,reflinkSearch,tag,text:inlineText,url:noopTest},inlinePedantic={...inlineNormal,link:edit(/^!?\[(label)\]\((.*?)\)/).replace("label",_inlineLabel).getRegex(),reflink:edit(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",_inlineLabel).getRegex()},inlineGfm={...inlineNormal,emStrongRDelimAst:emStrongRDelimAstGfm,emStrongLDelim:emStrongLDelimGfm,url:edit(/^((?: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~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},inlineBreaks={...inlineGfm,br:edit(br).replace("{2,}","*").getRegex(),text:edit(inlineGfm.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},block={normal:blockNormal,gfm:blockGfm,pedantic:blockPedantic},inline={normal:inlineNormal,gfm:inlineGfm,breaks:inlineBreaks,pedantic:inlinePedantic},escapeReplacements={"&":"&","<":"<",">":">",'"':""","'":"'"},getEscapeReplacement=e=>escapeReplacements[e];function escape$2(e,t){if(t){if(other.escapeTest.test(e))return e.replace(other.escapeReplace,getEscapeReplacement)}else if(other.escapeTestNoEncode.test(e))return e.replace(other.escapeReplaceNoEncode,getEscapeReplacement);return e}function cleanUrl(e){try{e=encodeURI(e).replace(other.percentDecode,"%")}catch{return null}return e}function splitCells(e,t){var l;const n=e.replace(other.findPipe,(u,d,f)=>{let p=!1,m=d;for(;--m>=0&&f[m]==="\\";)p=!p;return p?"|":" |"}),i=n.split(other.splitPipe);let o=0;if(i[0].trim()||i.shift(),i.length>0&&!((l=i.at(-1))!=null&&l.trim())&&i.pop(),t)if(i.length>t)i.splice(t);else for(;i.length<t;)i.push("");for(;o<i.length;o++)i[o]=i[o].trim().replace(other.slashPipe,"|");return i}function rtrim(e,t,n){const i=e.length;if(i===0)return"";let o=0;for(;o<i&&e.charAt(i-o-1)===t;)o++;return e.slice(0,i-o)}function findClosingBracket(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let i=0;i<e.length;i++)if(e[i]==="\\")i++;else if(e[i]===t[0])n++;else if(e[i]===t[1]&&(n--,n<0))return i;return-1}function outputLink(e,t,n,i,o){const l=t.href,u=t.title||null,d=e[1].replace(o.other.outputLinkReplace,"$1");if(e[0].charAt(0)!=="!"){i.state.inLink=!0;const f={type:"link",raw:n,href:l,title:u,text:d,tokens:i.inlineTokens(d)};return i.state.inLink=!1,f}return{type:"image",raw:n,href:l,title:u,text:d}}function indentCodeCompensation(e,t,n){const i=e.match(n.other.indentCodeCompensation);if(i===null)return t;const o=i[1];return t.split(`
|
|
865
865
|
`).map(l=>{const u=l.match(n.other.beginningSpace);if(u===null)return l;const[d]=u;return d.length>=o.length?l.slice(o.length):l}).join(`
|
|
866
866
|
`)}class _Tokenizer{constructor(t){be(this,"options");be(this,"rules");be(this,"lexer");this.options=t||_defaults}space(t){const n=this.rules.block.newline.exec(t);if(n&&n[0].length>0)return{type:"space",raw:n[0]}}code(t){const n=this.rules.block.code.exec(t);if(n){const i=n[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:n[0],codeBlockStyle:"indented",text:this.options.pedantic?i:rtrim(i,`
|