@arcgis/portal-components 5.2.0-next.53 → 5.2.0-next.55

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.
@@ -448,4 +448,4 @@ data: ${JSON.stringify({message:String(n)})}
448
448
 
449
449
  `))}finally{r.close()}}})}var UM=class{static subscribeTo(e,t){let{key:r,tags:n}={key:void 0,tags:void 0,...t??{}};if(Array.isArray(e)&&r!==void 0)throw new Error("Can't specify a key when subscribing to multiple channels");let i;return typeof e=="string"?r?i={[r]:e}:i=[e]:i=Object.fromEntries(e.map(a=>[a,a])),new $n({channels:i,triggers:Array.isArray(e)?e:[e],tags:n})}static writeTo(e,t){let r=[];for(let n of e)r.push({channel:n,value:Ir,skipNone:!1});for(let[n,i]of Object.entries(t??{}))se.isRunnable(i)||typeof i=="function"?r.push({channel:n,value:Ir,skipNone:!0,mapper:at(i)}):r.push({channel:n,value:i,skipNone:!1});return new ut(r)}},Q9=class extends se{lc_namespace=["langgraph","pregel"];invoke(e,t){throw new Error("Not implemented")}withConfig(e){return super.withConfig(e)}stream(e,t){return super.stream(e,t)}},Dh=class extends Q9{static lc_name(){return"LangGraph"}lc_namespace=["langgraph","pregel"];lg_is_pregel=!0;nodes;channels;inputChannels;outputChannels;autoValidate=!0;streamMode=["values"];streamChannels;interruptAfter;interruptBefore;stepTimeout;debug=!1;checkpointer;retryPolicy;config;store;cache;userInterrupt;streamTransformers;triggerToNodes={};constructor(e){super(e);let{streamMode:t}=e;if(t!=null&&!Array.isArray(t)&&(t=[t]),this.nodes=e.nodes,this.channels=e.channels,"__pregel_tasks"in this.channels&&"lc_graph_name"in this.channels.__pregel_tasks&&this.channels.__pregel_tasks.lc_graph_name!=="Topic")throw new Error(`Channel '${Rn}' is reserved and cannot be used in the graph.`);this.channels[Rn]=new AS({accumulate:!1}),this.autoValidate=e.autoValidate??this.autoValidate,this.streamMode=t??this.streamMode,this.inputChannels=e.inputChannels,this.outputChannels=e.outputChannels,this.streamChannels=e.streamChannels??this.streamChannels,this.interruptAfter=e.interruptAfter,this.interruptBefore=e.interruptBefore,this.stepTimeout=e.stepTimeout??this.stepTimeout,this.debug=e.debug??this.debug,this.checkpointer=e.checkpointer,this.retryPolicy=e.retryPolicy,this.config=e.config,this.store=e.store,this.cache=e.cache,this.name=e.name,this.triggerToNodes=e.triggerToNodes??this.triggerToNodes,this.userInterrupt=e.userInterrupt,this.streamTransformers=e.streamTransformers??[],this.autoValidate&&this.validate()}withConfig(e){let{streamTransformers:t,...r}=e,n=$t(this.config,r),i=[...this.streamTransformers,...t??[]];return new this.constructor({...this,config:n,streamTransformers:i})}validate(){DM({nodes:this.nodes,channels:this.channels,outputChannels:this.outputChannels,inputChannels:this.inputChannels,streamChannels:this.streamChannels,interruptAfterNodes:this.interruptAfter,interruptBeforeNodes:this.interruptBefore});for(let[e,t]of Object.entries(this.nodes))for(let r of t.triggers)this.triggerToNodes[r]??=[],this.triggerToNodes[r].push(e);return this}get streamChannelsList(){return Array.isArray(this.streamChannels)?this.streamChannels:this.streamChannels?[this.streamChannels]:Object.keys(this.channels)}get streamChannelsAsIs(){return this.streamChannels?this.streamChannels:Object.keys(this.channels)}async getGraphAsync(e){return this.getGraph(e)}*getSubgraphs(e,t){for(let[r,n]of Object.entries(this.nodes)){if(e!==void 0&&!e.startsWith(r))continue;let i=n.subgraphs?.length?n.subgraphs:[n.bound];for(let a of i){let o=Eh(a);if(o!==void 0){if(r===e){yield[r,o];return}if(e===void 0&&(yield[r,o]),t){let s=e;e!==void 0&&(s=e.slice(r.length+1));for(let[c,l]of o.getSubgraphs(s,t))yield[`${r}|${c}`,l]}}}}}async*getSubgraphsAsync(e,t){yield*this.getSubgraphs(e,t)}async _prepareStateSnapshot({config:e,saved:t,subgraphCheckpointer:r,applyPendingWrites:n=!1}){if(t===void 0)return{values:{},next:[],config:e,tasks:[]};let i=await $c(this.channels,t.checkpoint,{saver:typeof this.checkpointer=="object"?this.checkpointer:void 0,config:t.config??e});if(t.pendingWrites?.length){let d=t.pendingWrites.filter(([f,p])=>f===ir).map(([f,p,m])=>[String(p),m]);d.length>0&&hr(t.checkpoint,i,[{name:Pn,writes:d,triggers:[]}],void 0,this.triggerToNodes)}let a=Object.values(Ma(t.checkpoint,t.pendingWrites,this.nodes,i,t.config,!0,{step:(t.metadata?.step??-1)+1,store:this.store})),o=await kn(this.getSubgraphsAsync()),s=t.config.configurable?.checkpoint_ns??"",c={};for(let d of a){let f=o.find(([m])=>m===d.name);if(!f)continue;let p=`${String(d.name)}:${d.id}`;if(s&&(p=`${s}|${p}`),r===void 0){let m={configurable:{thread_id:t.config.configurable?.thread_id,checkpoint_ns:p}};c[d.id]=m}else{let m={configurable:{[Vr]:r,thread_id:t.config.configurable?.thread_id,checkpoint_ns:p}},h=f[1];c[d.id]=await h.getState(m,{subgraphs:!0})}}if(n&&t.pendingWrites?.length){let d=Object.fromEntries(a.map(p=>[p.id,p]));for(let[p,m,h]of t.pendingWrites)["__error__","__interrupt__",Ja].includes(m)||p in d&&d[p].writes.push([String(m),h]);let f=a.filter(p=>p.writes.length>0);f.length>0&&hr(t.checkpoint,i,f,void 0,this.triggerToNodes)}let l=t?.metadata;l&&t?.config?.configurable?.thread_id&&(l={...l,thread_id:t.config.configurable.thread_id});let u=a.filter(d=>d.writes.length===0).map(d=>d.name);return{values:En(i,this.streamChannelsAsIs),next:u,tasks:xS(a,t?.pendingWrites??[],c,this.streamChannelsAsIs),metadata:l,config:Na(t.config,t.metadata),createdAt:t.checkpoint.ts,parentConfig:t.parentConfig}}async getState(e,t){let r=e.configurable?.__pregel_checkpointer??this.checkpointer;if(!r)throw new Ga("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let n=e.configurable?.checkpoint_ns??"";if(n!==""&&e.configurable?.__pregel_read===void 0&&e.configurable?.__pregel_checkpointer===void 0){let o=mh(n);for await(let[s,c]of this.getSubgraphsAsync(o,!0))if(s===o)return await c.getState(Jo(e,{[Vr]:r}),{subgraphs:t?.subgraphs})}let i=$t(this.config,e),a=await r.getTuple(e);return await this._prepareStateSnapshot({config:i,saved:a,subgraphCheckpointer:t?.subgraphs?r:void 0,applyPendingWrites:!e.configurable?.checkpoint_id})}async*getStateHistory(e,t){let r=e.configurable?.__pregel_checkpointer??this.checkpointer;if(!r)throw new Ga("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});let n=e.configurable?.checkpoint_ns??"";if(n!==""&&e.configurable?.__pregel_checkpointer===void 0){let a=mh(n);for await(let[o,s]of this.getSubgraphsAsync(a,!0))if(o===a){yield*s.getStateHistory(Jo(e,{[Vr]:r}),t);return}}let i=$t(this.config,e,{configurable:{checkpoint_ns:n}});for await(let a of r.list(i,t))yield this._prepareStateSnapshot({config:a.config,saved:a})}async bulkUpdateState(e,t){let r=e.configurable?.__pregel_checkpointer??this.checkpointer;if(!r)throw new Ga("No checkpointer set",{lc_error_code:"MISSING_CHECKPOINTER"});if(t.length===0)throw new Error("No supersteps provided");if(t.some(o=>o.updates.length===0))throw new Error("No updates provided");let n=e.configurable?.checkpoint_ns??"";if(n!==""&&e.configurable?.__pregel_checkpointer===void 0){let o=mh(n);for await(let[,s]of this.getSubgraphsAsync(o,!0))return await s.bulkUpdateState(Jo(e,{[Vr]:r}),t);throw new Error(`Subgraph "${o}" not found`)}let i=async(o,s)=>{let c=this.config?$t(this.config,o):o,l=await r.getTuple(c),u=l!==void 0?wn(l.checkpoint):Go(),d={...l?.checkpoint.channel_versions},f=l?.metadata?.step??-1,p=Jo(c,{checkpoint_ns:c.configurable?.checkpoint_ns??""}),m=c.metadata??{};l?.config.configurable&&(p=Jo(c,l.config.configurable),m={...l.metadata,...m});let{values:h,asNode:_}=s[0];if(h==null&&_===void 0){if(s.length>1)throw new ve("Cannot create empty checkpoint with multiple updates");return Na(await r.put(p,xn(u,void 0,f),{source:"update",step:f+1,parents:l?.metadata?.parents??{}},{}),l?l.metadata:void 0)}let y=await $c(this.channels,u,{saver:r,config:l?.config??p});if(h===null&&_==="__end__"){if(s.length>1)throw new ve("Cannot apply multiple updates when clearing state");if(l){let C=Ma(u,l.pendingWrites||[],this.nodes,y,l.config,!0,{step:(l.metadata?.step??-1)+1,checkpointer:r,store:this.store}),b=(l.pendingWrites||[]).filter(B=>B[0]===ir).map(B=>B.slice(1));b.length>0&&hr(u,y,[{name:Pn,writes:b,triggers:[]}],r.getNextVersion.bind(r),this.triggerToNodes);for(let[B,L,q]of l.pendingWrites||[])["__error__","__interrupt__",Ja].includes(L)||B in C&&C[B].writes.push([L,q]);hr(u,y,Object.values(C),r.getNextVersion.bind(r),this.triggerToNodes)}return Na(await r.put(p,xn(u,y,f),{...m,source:"update",step:f+1,parents:l?.metadata?.parents??{}},Pc(d,u.channel_versions)),l?l.metadata:void 0)}if(_==="__copy__"){if(s.length>1)throw new ve("Cannot copy checkpoint with multiple updates");if(l==null)throw new ve("Cannot copy a non-existent checkpoint");let C=L=>!Array.isArray(L)||L.length===0?!1:L.every(q=>Array.isArray(q)&&q.length===2),b=xn(u,void 0,f),B=await r.put(l.parentConfig??Jo(l.config,{checkpoint_id:void 0}),b,{source:"fork",step:f+1,parents:l.metadata?.parents??{}},{});if(C(h)){let L=Ma(b,l.pendingWrites,this.nodes,y,B,!1,{step:f+2}),q=Object.values(L).reduce((Se,{name:Oe,id:mt})=>(Se[Oe]??=[],Se[Oe].push({id:mt}),Se),{}),ae=h.reduce((Se,Oe)=>{let[mt,ye]=Oe;Se[ye]??=[];let V=Se[ye].length,Y=q[ye]?.[V]?.id;return Se[ye].push({values:mt,asNode:ye,taskId:Y}),Se},{});return i(Na(B,l.metadata),Object.values(ae).flat())}return Na(B,l.metadata)}if(_==="__input__"){if(s.length>1)throw new ve("Cannot apply multiple updates when updating as input");let C=await kn(Ih(this.inputChannels,h));if(C.length===0)throw new ve(`Received no input writes for ${JSON.stringify(this.inputChannels,null,2)}`);hr(u,y,[{name:Pn,writes:C,triggers:[]}],r.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let b=l?.metadata?.step!=null?l.metadata.step+1:-1,B=await r.put(p,xn(u,y,b),{source:"input",step:b,parents:l?.metadata?.parents??{}},Pc(d,u.channel_versions));return await r.putWrites(B,C,Mn(Pn,u.id)),Na(B,l?l.metadata:void 0)}if(c.configurable?.checkpoint_id===void 0&&l?.pendingWrites!==void 0&&l.pendingWrites.length>0){let C=Ma(u,l.pendingWrites,this.nodes,y,l.config,!0,{store:this.store,checkpointer:this.checkpointer,step:(l.metadata?.step??-1)+1}),b=(l.pendingWrites??[]).filter(L=>L[0]===ir).map(L=>L.slice(1));b.length>0&&hr(l.checkpoint,y,[{name:Pn,writes:b,triggers:[]}],void 0,this.triggerToNodes);for(let[L,q,ae]of l.pendingWrites)["__error__","__interrupt__",Ja].includes(q)||C[L]===void 0||C[L].writes.push([q,ae]);let B=Object.values(C).filter(L=>L.writes.length>0);B.length>0&&hr(u,y,B,void 0,this.triggerToNodes)}let w=Object.values(u.versions_seen).map(C=>Object.values(C)).flat().find(C=>!!C),x=[];if(s.length===1){let{values:C,asNode:b,taskId:B}=s[0];if(b===void 0&&Object.keys(this.nodes).length===1)[b]=Object.keys(this.nodes);else if(b===void 0&&w===void 0)typeof this.inputChannels=="string"&&this.nodes[this.inputChannels]!==void 0&&(b=this.inputChannels);else if(b===void 0){let L=Object.entries(u.versions_seen).map(([q,ae])=>Object.values(ae).map(Se=>[Se,q])).flat().filter(([q,ae])=>ae!==Le).sort(([q],[ae])=>ah(q,ae));L&&(L.length===1?b=L[0][1]:L[L.length-1][0]!==L[L.length-2][0]&&(b=L[L.length-1][1]))}if(b===void 0)throw new ve('Ambiguous update, specify "asNode"');x.push({values:C,asNode:b,taskId:B})}else for(let{asNode:C,values:b,taskId:B}of s){if(C==null)throw new ve('"asNode" is required when applying multiple updates');x.push({values:b,asNode:C,taskId:B})}let S=[];for(let{asNode:C,values:b,taskId:B}of x){if(this.nodes[C]===void 0)throw new ve(`Node "${C.toString()}" does not exist`);let L=this.nodes[C].getWriters();if(!L.length)throw new ve(`No writers found for node "${C.toString()}"`);S.push({name:C,input:b,proc:L.length>1?Lr.from(L,{omitSequenceTags:!0}):L[0],writes:[],triggers:[Le],id:B??Mn("__interrupt__",u.id),writers:[]})}for(let C of S)await C.proc.invoke(C.input,Ee({...c,store:c?.store??this.store},{runName:c.runName??`${this.getName()}UpdateState`,configurable:{[Ft]:b=>C.writes.push(...b),[er]:(b,B=!1)=>Nc(u,y,C,b,B)}}));for(let C of S){let b=C.writes.filter(B=>B[0]!==nr);l!==void 0&&b.length>0&&await r.putWrites(p,b,C.id)}hr(u,y,S,r.getNextVersion.bind(this.checkpointer),this.triggerToNodes);let $=Pc(d,u.channel_versions),P=await r.put(p,xn(u,y,f+1),{source:"update",step:f+1,parents:l?.metadata?.parents??{}},$);for(let C of S){let b=C.writes.filter(B=>B[0]===nr);b.length>0&&await r.putWrites(P,b,C.id)}return Na(P,l?l.metadata:void 0)},a=e;for(let{updates:o}of t)a=await i(a,o);return a}async updateState(e,t,r){return this.bulkUpdateState(e,[{updates:[{values:t,asNode:r}]}])}_defaults(e){let{debug:t,streamMode:r,inputKeys:n,outputKeys:i,interruptAfter:a,interruptBefore:o,...s}=e,c=!0,l=t!==void 0?t:this.debug,u=i;u===void 0?u=this.streamChannelsAsIs:CS(u,this.channels);let d=n;d===void 0?d=this.inputChannels:CS(d,this.channels);let f=o??this.interruptBefore??[],p=a??this.interruptAfter??[],m;r!==void 0?(m=Array.isArray(r)?r:[r],c=typeof r=="string"):(e.configurable?.__pregel_task_id!==void 0?m=["values"]:m=this.streamMode,c=!0);let h;if(this.checkpointer===!1)h=void 0;else if(e!==void 0&&e.configurable?.__pregel_checkpointer!==void 0)h=e.configurable[Vr];else{if(this.checkpointer===!0)throw new Error("checkpointer: true cannot be used for root graphs.");h=this.checkpointer}let _=e.store??this.store,y=e.cache??this.cache;if(e.durability!=null&&e.checkpointDuring!=null)throw new Error("Cannot use both `durability` and `checkpointDuring` at the same time.");let w=(()=>{if(e.checkpointDuring!=null)return e.checkpointDuring===!1?"exit":"async"})(),x=e.durability??w??e?.configurable?.__pregel_durability??"async";return[l,m,d,u,s,f,p,h,_,c,y,x]}async stream(e,t){let r=new AbortController,n=ph()?.configurable;n?.__pregel_read!==void 0&&t?.configurable?.__pregel_read===void 0&&(t={...t,configurable:{...n,...t?.configurable}});let i={recursionLimit:this.config?.recursionLimit,...t,signal:Ra(t?.signal,r.signal).signal},a=await super.stream(e,i);return new Rh(t?.encoding==="text/event-stream"?SM(a):a,r)}async#e(e,t){let{version:r,encoding:n,transformers:i,...a}=t,o={recursionLimit:this.config?.recursionLimit,...a,configurable:{...this.config?.configurable,...a?.configurable},version:r,streamMode:tS,subgraphs:!0,encoding:void 0},s=this.stream(e,o),c=fS({[Symbol.asyncIterator]:async function*(){let l=await s;for await(let u of l)yield u}},[...this.streamTransformers??[],...i??[]]);if(n==="text/event-stream"){let l=new AbortController;return l.signal.addEventListener("abort",()=>c.abort(l.signal.reason),{once:!0}),new Rh(Y9(c),l)}return c}streamEvents(e,t,r){if(t.version==="v3")return this.#e(e,t);let n=new AbortController,i={recursionLimit:this.config?.recursionLimit,...t,signal:Ra(t?.signal,n.signal).signal};return new Rh(super.streamEvents(e,i,r),n)}async _validateInput(e){return e}async _validateContext(e){return e}async*_streamIterator(e,t){let r="version"in(t??{})?void 0:t?.encoding??void 0,n=t?.subgraphs,i=t?.version==="v3",a=Ec(this.config,t);if(a.recursionLimit===void 0||a.recursionLimit<1)throw new Error('Passed "recursionLimit" must be at least 1.');if(this.checkpointer!==void 0&&this.checkpointer!==!1&&a.configurable===void 0)throw new Error('Checkpointer requires one or more of the following "configurable" keys: "thread_id", "checkpoint_ns", "checkpoint_id"');let o=await this._validateInput(e),{runId:s,...c}=a,[l,u,,d,f,p,m,h,_,y,w,x]=this._defaults(c);f.metadata={ls_integration:"langgraph",...f.metadata},typeof f.context<"u"?f.context=await this._validateContext(f.context):f.configurable=await this._validateContext(f.configurable);let S=new kS({modes:new Set(u)});if(this.checkpointer===!0){f.configurable??={};let ae=f.configurable.checkpoint_ns??"";f.configurable[Cr]=ae.split("|").map(Se=>Se.split(":")[0]).join("|")}if(u.includes("messages")){let ae=i?new RM(Oe=>S.push(Oe)):new OM(Oe=>S.push(Oe)),{callbacks:Se}=f;if(Se===void 0)f.callbacks=[ae];else if(Array.isArray(Se))f.callbacks=Se.concat(ae);else{let Oe=Se.copy();Oe.addHandler(ae,!0),f.callbacks=Oe}}if(u.includes("tools")){let ae=new xM(Oe=>S.push(Oe)),{callbacks:Se}=f;if(Se===void 0)f.callbacks=[ae];else if(Array.isArray(Se))f.callbacks=Se.concat(ae);else{let Oe=Se.copy();Oe.addHandler(ae,!0),f.callbacks=Oe}}f.writer??=ae=>{if(!u.includes("custom"))return;let Se=ph()?.configurable?.[Cr]?.split("|").slice(0,-1);S.push([Se??[],"custom",ae])},f.interrupt??=this.userInterrupt??gS,f.serverInfo==null&&(f.serverInfo=eZ(f)),f.control??=new eS;let $={tracerInheritableMetadata:nZ(f)},P=await(await Xe._configureSync(f?.callbacks,void 0,f?.tags,void 0,f?.metadata,void 0,$))?.handleChainStart(this.toJSON(),oM(e,"input"),s,void 0,void 0,void 0,f?.runName??this.getName()),C=kc(this.channels),b,B,q=(async()=>{try{b=await TM.initialize({input:o,config:f,checkpointer:h,nodes:this.nodes,channelSpecs:C,outputKeys:d,streamKeys:this.streamChannelsAsIs,store:_,cache:w,stream:S,interruptAfter:m,interruptBefore:p,manager:P,debug:this.debug,triggerToNodes:this.triggerToNodes,durability:x});let ae=new jM({loop:b,nodeFinished:f.configurable?.[WS]});t?.subgraphs&&(b.config.configurable={...b.config.configurable,[Dc]:b.stream}),await this._runLoop({loop:b,runner:ae,debug:l,config:f}),x==="sync"&&await Promise.all(b?.checkpointerPromises??[])}catch(ae){B=ae}finally{try{b&&(await b.store?.stop(),await b.cache?.stop()),await Promise.all(b?.checkpointerPromises??[])}catch(ae){B=B??ae}B?(await new Promise(ae=>{queueMicrotask(ae)}),S.error(B)):S.close()}})();try{for await(let ae of S){if(ae===void 0)throw new Error("Data structure error.");let[Se,Oe,mt]=ae,ye="version"in(t??{});if(u.includes(Oe)||Oe==="checkpoints"&&Ic(mt)&&(i||ye&&n&&u.includes("values"))){if(r==="text/event-stream"){n?yield[Se,Oe,mt]:yield[null,Oe,mt];continue}n&&!y?yield[Se,Oe,mt]:y?n?yield[Se,mt]:yield mt:yield[Oe,mt]}}}catch(ae){throw await P?.handleChainError(B),ae}finally{await q}await P?.handleChainEnd(b?.output??{},s,void 0,void 0,void 0)}async invoke(e,t){let r=t?.streamMode??"values",n={...t,outputKeys:t?.outputKeys??this.outputChannels,streamMode:r,encoding:void 0},i=[],a=await this.stream(e,n),o=[],s;for await(let c of a)r==="values"?Ha(c)?o.push(c[Le]):s=c:i.push(c);if(r==="values"){if(o.length>0){let c=o.flat(1);if(s==null)return{[Le]:c};if(typeof s=="object")return{...s,[Le]:c}}return s}return i}async _runLoop(e){let{loop:t,runner:r,debug:n,config:i}=e,a;try{for(;await t.tick({inputKeys:this.inputChannels});){for(let{task:o}of await t._matchCachedWrites())t._outputWrites(o.id,o.writes,!0);n&&yM(t.checkpointMetadata.step,t.channels,this.streamChannelsList),n&&Lu(t.step,Object.values(t.tasks)),await r.tick({timeout:this.stepTimeout,retryPolicy:this.retryPolicy,onStepWrite:(o,s)=>{n&&vM(o,s,this.streamChannelsList)},maxConcurrency:i.maxConcurrency,signal:i.signal})}if(t.status==="draining")throw t.control==null?new Error("Draining status requires run control"):new Ku(t.control.drainReason??"shutdown");if(t.status==="out_of_steps")throw new Vh([`Recursion limit of ${i.recursionLimit} reached`,"without hitting a stop condition. You can increase the",'limit by setting the "recursionLimit" config key.'].join(" "),{lc_error_code:"GRAPH_RECURSION_LIMIT"})}catch(o){if(a=o,!await t.finishAndHandleError(a))throw o}finally{a===void 0&&await t.finishAndHandleError()}}async clearCache(){await this.cache?.clear([])}};function eZ(e){let t=e.metadata??{},r=e.configurable??{},n=r.assistant_id??t.assistant_id,i=r.graph_id??t.graph_id,a=r.langgraph_auth_user,o;if(a!=null&&typeof a=="object"&&"identity"in a&&(o=a),n!=null||i!=null||o!=null)return{assistantId:n!=null?String(n):"",graphId:i!=null?String(i):"",user:o}}var tZ=new Set(["key","token","secret","password","auth"]);function rZ(e,t){let r=e.toLowerCase(),n=!1;for(let i of tZ)if(r.includes(i)){n=!0;break}return e.startsWith("__")||!(typeof t=="string"||typeof t=="number"||typeof t=="boolean")||n}function nZ(e){let t=e.configurable;if(!t)return;let r={};for(let[n,i]of Object.entries(t))rZ(n,i)||(r[n]=i);return Object.keys(r).length>0?r:void 0}var In=class LM extends yt{lc_graph_name="EphemeralValue";guard;value=[];constructor(t=!0){super(),this.guard=t}fromCheckpoint(t){let r=new LM(this.guard);return typeof t<"u"&&(r.value=[t]),r}update(t){if(t.length===0){let r=this.value.length>0;return this.value=[],r}if(t.length!==1&&this.guard)throw new ve("EphemeralValue can only receive one value per step.");return this.value=[t[t.length-1]],!0}get(){if(this.value.length===0)throw new je;return this.value[0]}checkpoint(){if(this.value.length===0)throw new je;return this.value[0]}isAvailable(){return this.value.length!==0}};var OS=class{path;ends;constructor(e){se.isRunnable(e.path)?this.path=e.path:this.path=at(e.path),this.ends=Array.isArray(e.pathMap)?e.pathMap.reduce((t,r)=>(t[r]=r,t),{}):e.pathMap}run(e,t){return ut.registerWriter(new Rt({name:"<branch_run>",trace:!1,func:async(r,n)=>{try{return await this._route(r,n,e,t)}catch(i){throw i.name===Xu.unminifiable_name&&console.warn(`[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.
450
450
  NodeInterrupt should only be thrown inside a node, not in edge conditions.`),i}}}))}async _route(e,t,r,n){let i=await this.path.invoke(n?n(t):e,t);Array.isArray(i)||(i=[i]);let a;if(this.ends?a=i.map(o=>wt(o)?o:this.ends[o]):a=i,a.some(o=>!o))throw new Error("Branch condition returned unknown or null destination");if(a.filter(wt).some(o=>o.node==="__end__"))throw new ve("Cannot send a packet to the END node");return await r(a,t)??e}},PS=class{nodes;edges;branches;entryPoint;compiled=!1;constructor(){this.nodes={},this.edges=new Set,this.branches={}}warnIfCompiled(e){this.compiled&&console.warn(e)}get allEdges(){return this.edges}addNode(...e){function t(n){return n.length>=1&&typeof n[0]!="string"}let r=t(e)?Array.isArray(e[0])?e[0]:Object.entries(e[0]):[[e[0],e[1],e[2]]];if(r.length===0)throw new Error("No nodes provided in `addNode`");for(let[n,i,a]of r){for(let s of["|",":"])if(n.includes(s))throw new Error(`"${s}" is a reserved character and is not allowed in node names.`);if(this.warnIfCompiled("Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph."),n in this.nodes)throw new Error(`Node \`${n}\` already present.`);if(n==="__end__")throw new Error(`Node \`${n}\` is reserved.`);let o=at(i);this.nodes[n]={runnable:o,metadata:a?.metadata,subgraphs:ju(o)?[o]:a?.subgraphs,ends:a?.ends}}return this}addEdge(e,t){if(this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),e==="__end__")throw new Error("END cannot be a start node");if(t==="__start__")throw new Error("START cannot be an end node");if(Array.from(this.edges).some(([r])=>r===e)&&!("channels"in this))throw new Error(`Already found path for ${e}. For multiple edges, use StateGraph.`);return this.edges.add([e,t]),this}addConditionalEdges(e,t,r){let n=typeof e=="object"?e:{source:e,path:t,pathMap:r};this.warnIfCompiled("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph."),se.isRunnable(n.path)||(n.path=at(n.path));let i=n.path.getName()==="RunnableLambda"?"condition":n.path.getName();if(this.branches[n.source]&&this.branches[n.source][i])throw new Error(`Condition \`${i}\` already present for node \`${e}\``);return this.branches[n.source]??={},this.branches[n.source][i]=new OS(n),this}setEntryPoint(e){return this.warnIfCompiled("Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph."),this.addEdge(Je,e)}setFinishPoint(e){return this.warnIfCompiled("Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph."),this.addEdge(e,Qe)}compile({checkpointer:e,interruptBefore:t,interruptAfter:r,name:n,transformers:i}={}){this.validate([...Array.isArray(t)?t:[],...Array.isArray(r)?r:[]]);let a=new NS({builder:this,checkpointer:e,interruptAfter:r,interruptBefore:t,autoValidate:!1,nodes:{},channels:{[Je]:new In,[Qe]:new In},inputChannels:Je,outputChannels:Qe,streamChannels:[],streamMode:"values",name:n,streamTransformers:i});for(let[o,s]of Object.entries(this.nodes))a.attachNode(o,s);for(let[o,s]of this.edges)a.attachEdge(o,s);for(let[o,s]of Object.entries(this.branches))for(let[c,l]of Object.entries(s))a.attachBranch(o,c,l);return a.validate()}validate(e){let t=new Set([...this.allEdges].map(([n,i])=>n));for(let[n]of Object.entries(this.branches))t.add(n);for(let n of t)if(n!=="__start__"&&!(n in this.nodes))throw new Error(`Found edge starting at unknown node \`${n}\``);let r=new Set([...this.allEdges].map(([n,i])=>i));for(let[n,i]of Object.entries(this.branches))for(let a of Object.values(i))if(a.ends!=null)for(let o of Object.values(a.ends))r.add(o);else{r.add(Qe);for(let o of Object.keys(this.nodes))o!==n&&r.add(o)}for(let n of Object.values(this.nodes))for(let i of n.ends??[])r.add(i);if(Object.values(this.nodes).some(n=>n.isErrorHandler))for(let n of Object.keys(this.nodes))r.add(n);for(let n of Object.keys(this.nodes))if(!this.nodes[n].isErrorHandler&&!r.has(n))throw new Hh([`Node \`${n}\` is not reachable.`,"","If you are returning Command objects from your node,",'make sure you are passing names of potential destination nodes as an "ends" array','into ".addNode(..., { ends: ["node1", "node2"] })".'].join(`
451
- `),{lc_error_code:"UNREACHABLE_NODE"});for(let n of r)if(n!=="__end__"&&!(n in this.nodes))throw new Error(`Found edge ending at unknown node \`${n}\``);if(e){for(let n of e)if(!(n in this.nodes))throw new Error(`Interrupt node \`${n}\` is not present`)}this.compiled=!0}},NS=class extends Dh{builder;constructor({builder:e,...t}){super(t),this.builder=e}withConfig(e){return super.withConfig(e)}attachNode(e,t){this.channels[e]=new In,this.nodes[e]=new $n({channels:[],triggers:[],metadata:t.metadata,subgraphs:t.subgraphs,ends:t.ends}).pipe(t.runnable).pipe(new ut([{channel:e,value:Ir}],[ht])),this.streamChannels.push(e)}attachEdge(e,t){if(t==="__end__"){if(e==="__start__")throw new Error("Cannot have an edge from START to END");this.nodes[e].writers.push(new ut([{channel:Qe,value:Ir}],[ht]))}else this.nodes[t].triggers.push(e),this.nodes[t].channels.push(e)}attachBranch(e,t,r){e==="__start__"&&!this.nodes.__start__&&(this.nodes[Je]=UM.subscribeTo(Je,{tags:[ht]})),this.nodes[e].pipe(r.run(i=>new ut(i.map(a=>wt(a)?a:{channel:a==="__end__"?Qe:`branch:${e}:${t}:${a}`,value:Ir}),[ht])));let n=r.ends?Object.values(r.ends):Object.keys(this.nodes);for(let i of n)if(i!=="__end__"){let a=`branch:${e}:${t}:${i}`;this.channels[a]=new In,this.nodes[i].triggers.push(a),this.nodes[i].channels.push(a)}}async getGraphAsync(e){let t=e?.xray,r=new Lo,n={[Je]:r.addNode({schema:rn.any()},Je)},i={},a={};t&&(a=Object.fromEntries((await kn(this.getSubgraphsAsync())).filter(l=>FM(l[1]))));let o=[];function s(l,u,d,f=!1){if(u==="__end__"&&i.__end__===void 0&&(i[Qe]=r.addNode({schema:rn.any()},Qe)),n[l]!==void 0){if(i[u]===void 0)throw new Error(`End node ${u} not found!`);return o.push({src:l,dest:u,conditional:f}),r.addEdge(n[l],i[u],d!==u?d:void 0,f)}}for(let[l,u]of Object.entries(this.builder.nodes)){let d=Tt(l),f=u.runnable,p=u.metadata??{};if(this.interruptBefore?.includes(l)&&this.interruptAfter?.includes(l)?p.__interrupt="before,after":this.interruptBefore?.includes(l)?p.__interrupt="before":this.interruptAfter?.includes(l)&&(p.__interrupt="after"),t){let m=typeof t=="number"?t-1:t,h=a[l]!==void 0?await a[l].getGraphAsync({...e,xray:m}):f.getGraph(e);if(h.trimFirstNode(),h.trimLastNode(),Object.keys(h.nodes).length>1){let w=function(S){return S?S.lc_runnable:!1},x=function(S,$){if(S!==void 0&&!di(S))return S;if(w($))try{let P=$.getName();return P=P.startsWith("Runnable")?P.slice(8):P,P}catch{return $.getName()}else return $.name??"UnknownSchema"},[_,y]=r.extend(h,d);if(_===void 0)throw new Error(`Could not extend subgraph "${l}" due to missing entrypoint.`);y!==void 0&&(n[d]={name:x(y.id,y.data),...y}),i[d]={name:x(_.id,_.data),..._}}else{let _=r.addNode(f,d,p);n[d]=_,i[d]=_}}else{let m=r.addNode(f,d,p);n[d]=m,i[d]=m}}let c=[...this.builder.allEdges].sort(([l],[u])=>l<u?-1:u>l?1:0);for(let[l,u]of c)s(Tt(l),Tt(u));for(let[l,u]of Object.entries(this.builder.branches)){let d={...Object.fromEntries(Object.keys(this.builder.nodes).filter(f=>f!==l).map(f=>[Tt(f),Tt(f)])),[Qe]:Qe};for(let f of Object.values(u)){let p;f.ends!==void 0?p=f.ends:p=d;for(let[m,h]of Object.entries(p))s(Tt(l),Tt(h),m,!0)}}for(let[l,u]of Object.entries(this.builder.nodes))if(u.ends!==void 0)for(let d of u.ends)s(Tt(l),Tt(d),void 0,!0);return BM(this.builder.nodes,o,s),r}getGraph(e){let t=e?.xray,r=new Lo,n={[Je]:r.addNode({schema:rn.any()},Je)},i={},a={};t&&(a=Object.fromEntries(Pa(this.getSubgraphs()).filter(l=>FM(l[1]))));let o=[];function s(l,u,d,f=!1){if(u==="__end__"&&i.__end__===void 0&&(i[Qe]=r.addNode({schema:rn.any()},Qe)),n[l]!==void 0){if(i[u]===void 0)throw new Error(`End node ${u} not found!`);return o.push({src:l,dest:u,conditional:f}),r.addEdge(n[l],i[u],d!==u?d:void 0,f)}}for(let[l,u]of Object.entries(this.builder.nodes)){let d=Tt(l),f=u.runnable,p=u.metadata??{};if(this.interruptBefore?.includes(l)&&this.interruptAfter?.includes(l)?p.__interrupt="before,after":this.interruptBefore?.includes(l)?p.__interrupt="before":this.interruptAfter?.includes(l)&&(p.__interrupt="after"),t){let m=typeof t=="number"?t-1:t,h=a[l]!==void 0?a[l].getGraph({...e,xray:m}):f.getGraph(e);if(h.trimFirstNode(),h.trimLastNode(),Object.keys(h.nodes).length>1){let w=function(S){return S?S.lc_runnable:!1},x=function(S,$){if(S!==void 0&&!di(S))return S;if(w($))try{let P=$.getName();return P=P.startsWith("Runnable")?P.slice(8):P,P}catch{return $.getName()}else return $.name??"UnknownSchema"},[_,y]=r.extend(h,d);if(_===void 0)throw new Error(`Could not extend subgraph "${l}" due to missing entrypoint.`);y!==void 0&&(n[d]={name:x(y.id,y.data),...y}),i[d]={name:x(_.id,_.data),..._}}else{let _=r.addNode(f,d,p);n[d]=_,i[d]=_}}else{let m=r.addNode(f,d,p);n[d]=m,i[d]=m}}let c=[...this.builder.allEdges].sort(([l],[u])=>l<u?-1:u>l?1:0);for(let[l,u]of c)s(Tt(l),Tt(u));for(let[l,u]of Object.entries(this.builder.branches)){let d={...Object.fromEntries(Object.keys(this.builder.nodes).filter(f=>f!==l).map(f=>[Tt(f),Tt(f)])),[Qe]:Qe};for(let f of Object.values(u)){let p;f.ends!==void 0?p=f.ends:p=d;for(let[m,h]of Object.entries(p))s(Tt(l),Tt(h),m,!0)}}for(let[l,u]of Object.entries(this.builder.nodes))if(u.ends!==void 0)for(let d of u.ends)s(Tt(l),Tt(d),void 0,!0);return BM(this.builder.nodes,o,s),r}};function FM(e){return typeof e.attachNode=="function"&&typeof e.attachEdge=="function"}function Tt(e){return e==="subgraph"?`"${e}"`:e}function BM(e,t,r){let n=new Set(t.map(a=>a.src)),i=[...new Set(t.filter(a=>!a.conditional&&a.dest!=="__end__").map(a=>a.dest))].sort();for(let a of i){if(n.has(a))continue;let o=Object.keys(e).find(s=>Tt(s)===a);o!==void 0&&e[o]?.isErrorHandler||r(a,Qe)}}function Mi(e){return typeof e=="object"&&e!==null&&"~standard"in e&&typeof e["~standard"]=="object"&&e["~standard"]!==null&&"validate"in e["~standard"]}function RS(e){return typeof e=="object"&&e!==null&&"~standard"in e&&typeof e["~standard"]=="object"&&e["~standard"]!==null&&"jsonSchema"in e["~standard"]}function iZ(e){return Mi(e)&&RS(e)}function ja(e){if(RS(e))try{return e["~standard"].jsonSchema.input({target:"draft-07"})}catch{return}}function ji(e){if(e!=null&&Mi(e))try{let t=e["~standard"].validate(void 0);if(t&&typeof t=="object"&&!("then"in t&&typeof t.then=="function")){let r=t;if(!r.issues){let n=r.value;return()=>n}}}catch{}}var aZ=e=>e!=null&&e.lc_graph_name==="DeltaChannel",zh=class VM extends yt{lc_graph_name="DeltaChannel";value;reducer;snapshotFrequency;initialValueFactory;constructor(t,r){super();let n=r?.snapshotFrequency??1e3;if(!Number.isInteger(n)||n<=0)throw new Error(`snapshotFrequency must be a positive integer, got ${n}`);this.reducer=t,this.snapshotFrequency=n,this.initialValueFactory=r?.initialValueFactory??(()=>[]),this.value=void 0}fromCheckpoint(t){let r=new VM(this.reducer,{snapshotFrequency:this.snapshotFrequency,initialValueFactory:this.initialValueFactory});return t===void 0?r.value=this.initialValueFactory():Qh(t)?r.value=t.value:r.value=t,r}replayWrites(t){let r=t.map(o=>o[2]);if(r.length===0)return;let n=this.value,i=0;for(let o=0;o<r.length;o+=1){let[s,c]=sn(r[o]);s&&(n=c??this.initialValueFactory(),i=o+1)}let a=r.slice(i);this.value=a.length>0?this.reducer(n,a):n}update(t){if(t.length===0)return!1;let r,n=!1;for(let a of t)if(Za(a)){if(n)throw new ve("Can receive only one Overwrite value per step.");n=!0,[,r]=sn(a)}if(n)return this.value=r??this.initialValueFactory(),!0;let i=this.value===void 0?this.initialValueFactory():this.value;return this.value=this.reducer(i,t),!0}get(){if(this.value===void 0)throw new je;return this.value}checkpoint(){}isAvailable(){return this.value!==void 0}equals(t){return this===t?!0:!aZ(t)||this.snapshotFrequency!==t.snapshotFrequency?!1:this.reducer===t.reducer}};var MS=Symbol.for("langgraph.channel.missing"),Uh=class ZM extends yt{lc_graph_name="UntrackedValue";guard;_value=MS;initialValueFactory;constructor(t){super(),this.guard=t?.guard??!0,this.initialValueFactory=t?.initialValueFactory,this.initialValueFactory&&(this._value=this.initialValueFactory())}fromCheckpoint(t){return new ZM({guard:this.guard,initialValueFactory:this.initialValueFactory})}update(t){if(t.length===0)return!1;if(t.length!==1&&this.guard)throw new ve("UntrackedValue(guard=true) can receive only one value per step. Use guard=false if you want to store any one of multiple values.",{lc_error_code:"INVALID_CONCURRENT_GRAPH_UPDATE"});return this._value=t[t.length-1],!0}get(){if(this._value===MS)throw new je;return this._value}checkpoint(){}isAvailable(){return this._value!==MS}};var Da=(e,t)=>e.size===t.size&&[...e].every(r=>t.has(r)),jS=class HM extends yt{lc_graph_name="NamedBarrierValue";names;seen;constructor(t){super(),this.names=t,this.seen=new Set}fromCheckpoint(t){let r=new HM(this.names);return typeof t<"u"&&(r.seen=new Set(t)),r}update(t){let r=!1;for(let n of t)if(this.names.has(n))this.seen.has(n)||(this.seen.add(n),r=!0);else throw new ve(`Value ${JSON.stringify(n)} not in names ${JSON.stringify(this.names)}`);return r}get(){if(!Da(this.names,this.seen))throw new je}checkpoint(){return[...this.seen]}consume(){return this.seen&&this.names&&Da(this.seen,this.names)?(this.seen=new Set,!0):!1}isAvailable(){return!!this.names&&Da(this.names,this.seen)}},DS=class GM extends yt{lc_graph_name="NamedBarrierValueAfterFinish";names;seen;finished;constructor(t){super(),this.names=t,this.seen=new Set,this.finished=!1}fromCheckpoint(t){let r=new GM(this.names);if(typeof t<"u"){let[n,i]=t;r.seen=new Set(n),r.finished=i}return r}update(t){let r=!1;for(let n of t)if(this.names.has(n)&&!this.seen.has(n))this.seen.add(n),r=!0;else if(!this.names.has(n))throw new ve(`Value ${JSON.stringify(n)} not in names ${JSON.stringify(this.names)}`);return r}get(){if(!this.finished||!Da(this.names,this.seen))throw new je}checkpoint(){return[[...this.seen],this.finished]}consume(){return this.finished&&this.seen&&this.names&&Da(this.seen,this.names)?(this.seen=new Set,this.finished=!1,!0):!1}finish(){return!this.finished&&this.names&&Da(this.names,this.seen)?(this.finished=!0,!0):!1}isAvailable(){return this.finished&&!!this.names&&Da(this.names,this.seen)}};var zS=Symbol.for("langgraph.state.reduced_value"),Di=class{[zS]=!0;valueSchema;inputSchema;reducer;jsonSchemaExtra;constructor(e,t){this.reducer=t.reducer,this.jsonSchemaExtra=t.jsonSchemaExtra,this.valueSchema=e,this.inputSchema="inputSchema"in t?t.inputSchema:e,this.jsonSchemaExtra=t.jsonSchemaExtra}static isInstance(e){return typeof e=="object"&&e!==null&&zS in e&&e[zS]===!0}};var WM=Symbol.for("langgraph.state.untracked_value"),qo=class{[WM]=!0;schema;guard;constructor(e,t){this.schema=e,this.guard=t?.guard??!0}static isInstance(e){return typeof e=="object"&&e!==null&&WM in e}};var US=Symbol.for("langgraph.state.delta_value"),zi=class{[US]=!0;valueSchema;inputSchema;reducer;snapshotFrequency;jsonSchemaExtra;constructor(e,t){this.reducer=t.reducer,this.valueSchema=e,this.inputSchema="inputSchema"in t?t.inputSchema:e,this.snapshotFrequency=t.snapshotFrequency,this.jsonSchemaExtra=t.jsonSchemaExtra}static isInstance(e){return typeof e=="object"&&e!==null&&US in e&&e[US]===!0}};var LS=Symbol.for("langgraph.state.state_schema"),Tn=class{[LS]=!0;constructor(e){this.fields=e}getChannels(){let e={};for(let[t,r]of Object.entries(this.fields))if(zi.isInstance(r)){let n=ji(r.valueSchema);e[t]=new zh(r.reducer,{snapshotFrequency:r.snapshotFrequency,initialValueFactory:n})}else if(Di.isInstance(r)){let n=ji(r.valueSchema);e[t]=new Pi(r.reducer,n)}else if(qo.isInstance(r)){let n=r.schema?ji(r.schema):void 0;e[t]=new Uh({guard:r.guard,initialValueFactory:n})}else if(Mi(r))e[t]=new Sn(ji(r));else throw new Error(`Invalid state field "${t}": must be a schema, ReducedValue, DeltaValue, UntrackedValue, or ManagedValue`);return e}getJsonSchema(){let e={},t=[];for(let[r,n]of Object.entries(this.fields)){let i;if(zi.isInstance(n)||Di.isInstance(n)?(i=ja(n.valueSchema),n.jsonSchemaExtra&&(i={...i??{},...n.jsonSchemaExtra})):qo.isInstance(n)?i=n.schema?ja(n.schema):void 0:Mi(n)&&(i=ja(n)),i){e[r]=i;let a=!1;zi.isInstance(n)||Di.isInstance(n)?a=ji(n.valueSchema)!==void 0:qo.isInstance(n)?a=n.schema?ji(n.schema)!==void 0:!1:a=ji(n)!==void 0,a||t.push(r)}}return{type:"object",properties:e,required:t.length>0?t:void 0}}getInputJsonSchema(){let e={};for(let[t,r]of Object.entries(this.fields)){let n;zi.isInstance(r)||Di.isInstance(r)?(n=ja(r.inputSchema),r.jsonSchemaExtra&&(n={...n??{},...r.jsonSchemaExtra})):qo.isInstance(r)?n=r.schema?ja(r.schema):void 0:Mi(r)&&(n=ja(r)),n&&(e[t]=n)}return{type:"object",properties:e}}getChannelKeys(){return Object.entries(this.fields).map(([e])=>e)}getAllKeys(){return Object.keys(this.fields)}async validateInput(e){if(e==null||typeof e!="object")return e;let t={};for(let[r,n]of Object.entries(e)){let i=this.fields[r];if(i===void 0){t[r]=n;continue}let a;if(zi.isInstance(i)||Di.isInstance(i)){let[o,s]=sn(n);if(o){a=i.valueSchema;let c=await a["~standard"].validate(s);if(c.issues)throw new Error(`Validation failed for field "${r}": ${JSON.stringify(c.issues)}`);t[r]={[On]:c.value};continue}a=i.inputSchema}else qo.isInstance(i)?a=i.schema:Mi(i)&&(a=i);if(a){let o=await a["~standard"].validate(n);if(o.issues)throw new Error(`Validation failed for field "${r}": ${JSON.stringify(o.issues)}`);t[r]=o.value}else t[r]=n}return t}static isInstance(e){return typeof e=="object"&&e!==null&&LS in e&&e[LS]===!0}};var oZ="__remove_all__";function za(e,t){let r=Array.isArray(e)?e:[e],n=Array.isArray(t)?t:[t],i=r.map(kt),a=n.map(kt);for(let u of i)(u.id===null||u.id===void 0)&&(u.id=Xi(),u.lc_kwargs.id=u.id);let o;for(let u=0;u<a.length;u+=1){let d=a[u];(d.id===null||d.id===void 0)&&(d.id=Xi(),d.lc_kwargs.id=d.id),Nr.isInstance(d)&&d.id==="__remove_all__"&&(o=u)}if(o!=null)return a.slice(o+1);let s=[...i],c=new Map(s.map((u,d)=>[u.id,d])),l=new Set;for(let u of a){let d=c.get(u.id);if(d!==void 0)Nr.isInstance(u)?l.add(u.id):(l.delete(u.id),s[d]=u);else{if(Nr.isInstance(u))throw new Error(`Attempting to delete a message with an ID that doesn't exist ('${u.id}')`);c.set(u.id,s.length),s.push(u)}}return s.filter(u=>!l.has(u.id))}function FS(e,t){let r=[];for(let s of t)Array.isArray(s)?r.push(...s):r.push(s);let n=e.length>0&&Pe.isInstance(e[0])?e:e.map(kt),i=r.map(kt),a=new Map;for(let s=0;s<n.length;s+=1){let c=n[s].id;c!=null&&a.set(c,s)}let o=[...n];for(let s of i){let c=s.id;Nr.isInstance(s)&&c==="__remove_all__"?(o.length=0,a.clear()):c==null?o.push(s):Nr.isInstance(s)?a.has(c)&&(o[a.get(c)]=null,a.delete(c)):a.has(c)?o[a.get(c)]=s:(a.set(c,o.length),o.push(s))}return o.filter(s=>s!==null)}var JM=rn.custom().default(()=>[]),KM=rn.custom(),sZ=new Di(JM,{inputSchema:KM,reducer:za,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}}),cZ=new zi(JM,{inputSchema:KM,reducer:FS,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}});var lZ=class{_map=new Map;_extensionCache=new Map;get(e){return this._map.get(e)}extend(e,t){let r=this.get(e);this._map.set(e,t(r))}remove(e){return this._map.delete(e),this}has(e){return this._map.has(e)}getChannelsForSchema(e){let t={},r=xi(e);for(let[n,i]of Object.entries(r)){let a=this.get(i);a?.reducer?t[n]=new Pi(a.reducer.fn,a.default):t[n]=new Sn(a?.default)}return t}getExtendedChannelSchemas(e,t){if(Object.keys(t).length===0)return e;let r=Object.entries(t).filter(([,a])=>a===!0).sort(([a],[o])=>a.localeCompare(o)).map(([a,o])=>`${a}:${o}`).join("|"),n=this._extensionCache.get(r)??new Map;if(n.has(e))return n.get(e);let i=e;if(t.withReducerSchema||t.withJsonSchemaExtrasAsDescription){let a=Object.entries(xi(e)).map(([o,s])=>{let c=this.get(s),l=t.withReducerSchema?c?.reducer?.schema??s:s;if(t.withJsonSchemaExtrasAsDescription&&c?.jsonSchemaExtra){let u=Si(l)??Si(s),d=JSON.stringify({...c.jsonSchemaExtra,description:u});l=l.describe(`lg:${d}`)}return[o,l]});i=xp(e,Object.fromEntries(a)),lt(i)&&(i._def.unknownKeys="strip")}return t.asPartial&&(i=Sa(i)),n.set(e,i),this._extensionCache.set(r,n),i}},Fu=new lZ;function qM(e,t){if(t.reducer&&!t.default){let r=Sp(e);r!=null&&(t.default=r)}if(t.reducer){let r=Object.assign(e,{lg_reducer_schema:t.reducer?.schema??e});return Fu.extend(r,()=>t),r}else return Fu.extend(e,()=>t),e}function Xo(e){return e==null?!1:!!(Tn.isInstance(e)||Jt(e)||typeof e=="object"&&"lc_graph_name"in e&&e.lc_graph_name==="AnnotationRoot"||typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0&&Object.values(e).every(t=>typeof t=="function"||X0(t)))}function XM(e){if(typeof e!="object"||e==null)return!1;let t=e,r="state"in t&&Xo(t.state),n="stateSchema"in t&&Xo(t.stateSchema),i="input"in t&&Xo(t.input);return!(!r&&!n&&!i||"input"in t&&t.input!=null&&!Xo(t.input)||"output"in t&&t.output!=null&&!Xo(t.output))}var Ui="__root__",Rc="__default_error_handler__",Lh=Symbol.for("langgraph.state.partial"),BS=class extends PS{channels={};waitingEdges=new Set;_schemaDefinition;_schemaRuntimeDefinition;_inputDefinition;_inputRuntimeDefinition;_outputDefinition;_outputRuntimeDefinition;_schemaDefinitions=new Map;_metaRegistry=Fu;_configSchema;_configRuntimeSchema;_interrupt;_writer;_nodeDefaults={};constructor(e,t){super();let r=this._normalizeToStateGraphInit(e,t),n=r.state??r.stateSchema??r.input;if(!n)throw new Lc;let i=this._getChannelsFromSchema(n);this._schemaDefinition=i,Tn.isInstance(n)?this._schemaRuntimeDefinition=n:Jt(n)&&(this._schemaRuntimeDefinition=n),r.input?Tn.isInstance(r.input)?this._inputRuntimeDefinition=r.input:Jt(r.input)?this._inputRuntimeDefinition=r.input:this._inputRuntimeDefinition=Lh:this._inputRuntimeDefinition=Lh,r.output?Tn.isInstance(r.output)?this._outputRuntimeDefinition=r.output:Jt(r.output)?this._outputRuntimeDefinition=r.output:this._outputRuntimeDefinition=this._schemaRuntimeDefinition:this._outputRuntimeDefinition=this._schemaRuntimeDefinition;let a=r.input?this._getChannelsFromSchema(r.input):i,o=r.output?this._getChannelsFromSchema(r.output):i;this._inputDefinition=a,this._outputDefinition=o,this._addSchema(this._schemaDefinition),this._addSchema(this._inputDefinition),this._addSchema(this._outputDefinition),r.context&&Jt(r.context)&&(this._configRuntimeSchema=r.context),this._interrupt=r.interrupt,this._writer=r.writer}setNodeDefaults(e){return e.retryPolicy!==void 0&&(this._nodeDefaults.retryPolicy=e.retryPolicy),e.cachePolicy!==void 0&&(this._nodeDefaults.cachePolicy=typeof e.cachePolicy=="boolean"?e.cachePolicy?{}:void 0:e.cachePolicy),e.timeout!==void 0&&(this._nodeDefaults.timeout=Bi(e.timeout)),e.errorHandler!==void 0&&(this._nodeDefaults.errorHandler=e.errorHandler),this}_createDefaultErrorHandlerSpec(){let e=this._nodeDefaults.errorHandler;if(e!==void 0)return{runnable:new Rt({func:(t,r)=>{let n=r?.configurable?.[zc];return e(t,n,r)},name:Rc,trace:!1}),metadata:void 0,input:this._schemaDefinition,retryPolicy:void 0,cachePolicy:void 0,isErrorHandler:!0}}_normalizeToStateGraphInit(e,t){if(XM(e)){if(Jt(t)||dh.isInstance(t))return{...e,context:t};let r=t;return{...e,input:e.input??r?.input,output:e.output??r?.output,context:e.context??r?.context,interrupt:e.interrupt??r?.interrupt,writer:e.writer??r?.writer,nodes:e.nodes??r?.nodes}}if(Xo(e)){if(Jt(t)||dh.isInstance(t))return{state:e,context:t};let r=t;return{state:e,input:r?.input,output:r?.output,context:r?.context,interrupt:r?.interrupt,writer:r?.writer,nodes:r?.nodes}}if(dZ(e))return{state:uZ(e.channels)};throw new Lc}_getChannelsFromSchema(e){if(Tn.isInstance(e))return e.getChannels();if(Jt(e))return this._metaRegistry.getChannelsForSchema(e);if(typeof e=="object"&&"lc_graph_name"in e&&e.lc_graph_name==="AnnotationRoot")return e.spec;if(typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0)return e;throw new Lc("Invalid schema type. Expected StateSchema, Zod object, AnnotationRoot, or StateDefinition.")}get allEdges(){return new Set([...this.edges,...Array.from(this.waitingEdges).flatMap(([e,t])=>e.map(r=>[r,t]))])}_addSchema(e){if(!this._schemaDefinitions.has(e)){this._schemaDefinitions.set(e,e);for(let[t,r]of Object.entries(e)){let n;if(typeof r=="function"?n=r():n=r,this.channels[t]!==void 0){if(!this.channels[t].equals(n)&&n.lc_graph_name!=="LastValue")throw new Error(`Channel "${t}" already exists with a different type.`)}else this.channels[t]=n}}}addNode(...e){function t(n){return n.length>=1&&typeof n[0]!="string"}let r=t(e)?Array.isArray(e[0])?e[0]:Object.entries(e[0]).map(([n,i])=>[n,i]):[[e[0],e[1],e[2]]];if(r.length===0)throw new Error("No nodes provided in `addNode`");for(let[n,i,a]of r){if(n in this.channels)throw new Error(`${n} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);for(let f of["|",":"])if(n.includes(f))throw new Error(`"${f}" is a reserved character and is not allowed in node names.`);if(this.warnIfCompiled("Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph."),n in this.nodes)throw new Error(`Node \`${n}\` already present.`);if(n==="__end__"||n==="__start__")throw new Error(`Node \`${n}\` is reserved.`);let o=this._schemaDefinition;a?.input!==void 0&&(o=this._getChannelsFromSchema(a.input)),this._addSchema(o);let s;se.isRunnable(i)?s=i:typeof i=="function"?s=new Rt({func:i,name:n,trace:!1}):s=at(i);let c=a?.cachePolicy,l;c!==void 0&&(l=typeof c=="boolean"?c?{}:!1:c);let u;if(a?.errorHandler!==void 0){if(u=`__error_handler__${n}`,u in this.nodes)throw new Error(`Cannot add error handler to node \`${n}\`: the reserved name \`${u}\` is already in use. StateGraph registers \`__error_handler__<nodeName>\` when you pass \`errorHandler\` in addNode options. Remove or rename the existing node with that name (for example, you may have added it manually).`);let f=a.errorHandler,p={runnable:new Rt({func:(m,h)=>{let _=h?.configurable?.[zc];return f(m,_,h)},name:u,trace:!1}),metadata:void 0,input:o??this._schemaDefinition,retryPolicy:void 0,cachePolicy:void 0,isErrorHandler:!0};this.nodes[u]=p}let d={runnable:s,retryPolicy:a?.retryPolicy,cachePolicy:l,timeout:Bi(a?.timeout),metadata:a?.metadata,input:o??this._schemaDefinition,subgraphs:ju(s)?[s]:a?.subgraphs,ends:a?.ends,defer:a?.defer,errorHandlerNode:u};this.nodes[n]=d}return this}addEdge(e,t){if(typeof e=="string")return super.addEdge(e,t);this.compiled&&console.warn("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");for(let r of e){if(r==="__end__")throw new Error("END cannot be a start node");if(!Object.keys(this.nodes).some(n=>n===r))throw new Error(`Need to add a node named "${r}" first`)}if(t==="__end__")throw new Error("END cannot be an end node");if(!Object.keys(this.nodes).some(r=>r===t))throw new Error(`Need to add a node named "${t}" first`);return this.waitingEdges.add([e,t]),this}addSequence(e){let t=Array.isArray(e)?e:Object.entries(e);if(t.length===0)throw new Error("Sequence requires at least one node.");let r;for(let[n,i,a]of t){if(n in this.nodes)throw new Error(`Node names must be unique: node with the name "${n}" already exists.`);let o=n;this.addNode(n,i,a),r!=null&&this.addEdge(r,o),r=o}return this}compile({checkpointer:e,store:t,cache:r,interruptBefore:n,interruptAfter:i,name:a,description:o,transformers:s}={}){let c=this._createDefaultErrorHandlerSpec();if(c!==void 0){if(Rc in this.nodes)throw new Error(`Cannot apply a default error handler: the reserved node name \`${Rc}\` is already in use. setNodeDefaults({ errorHandler }) registers a node with that name; rename the conflicting node.`);this.nodes[Rc]=c}try{return this._compileResolved({checkpointer:e,store:t,cache:r,interruptBefore:n,interruptAfter:i,name:a,description:o,transformers:s,defaultErrorHandlerNode:c!==void 0?Rc:void 0})}finally{c!==void 0&&delete this.nodes[Rc]}}_compileResolved({checkpointer:e,store:t,cache:r,interruptBefore:n,interruptAfter:i,name:a,description:o,transformers:s,defaultErrorHandlerNode:c}){this.validate([...Array.isArray(n)?n:[],...Array.isArray(i)?i:[]]);let l=Object.keys(this._schemaDefinitions.get(this._outputDefinition)),u=l.length===1&&l[0]===Ui?Ui:l,d=Object.keys(this.channels),f=d.length===1&&d[0]===Ui?Ui:d,p=this._interrupt,m=new QM({builder:this,checkpointer:e,interruptAfter:i,interruptBefore:n,autoValidate:!1,nodes:{},channels:{...this.channels,[Je]:new In},inputChannels:Je,outputChannels:u,streamChannels:f,streamMode:"updates",store:t,cache:r,name:a,description:o,userInterrupt:p,streamTransformers:s});m.attachNode(Je);let h=this._nodeDefaults,_=h.retryPolicy!==void 0||h.cachePolicy!==void 0||h.timeout!==void 0||c!==void 0;for(let[y,w]of Object.entries(this.nodes)){let x=w.isErrorHandler===!0,S=_?{...w,retryPolicy:w.retryPolicy??h.retryPolicy,cachePolicy:x||w.cachePolicy===!1?void 0:w.cachePolicy??h.cachePolicy,timeout:w.timeout??h.timeout,errorHandlerNode:!x&&c!==void 0&&w.errorHandlerNode===void 0?c:w.errorHandlerNode}:w;m.attachNode(y,S)}m.attachBranch(Je,Bh,YM(),{withReader:!1});for(let[y]of Object.entries(this.nodes))m.attachBranch(y,Bh,YM(),{withReader:!1});for(let[y,w]of this.edges)m.attachEdge(y,w);for(let[y,w]of this.waitingEdges)m.attachEdge(y,w);for(let[y,w]of Object.entries(this.branches))for(let[x,S]of Object.entries(w))m.attachBranch(y,x,S);return m.validate()}};function uZ(e){let t={};for(let[r,n]of Object.entries(e))r===Ui?t[r]=fh(n):t[r]=fh(n);return t}var QM=class extends NS{description;_metaRegistry=Fu;constructor({description:e,...t}){super(t),this.description=e}attachNode(e,t){let r;e==="__start__"?r=Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([c])=>c):r=Object.keys(this.builder.channels);function n(c){if(Ct(c))return c.graph===_r.PARENT?null:c._updateAsTuples();if(Array.isArray(c)&&c.length>0&&c.some(l=>Ct(l))){let l=[];for(let u of c)if(Ct(u)){if(u.graph===_r.PARENT)continue;l.push(...u._updateAsTuples())}else l.push([Ui,u]);return l}else if(c!=null)return[[Ui,c]];return null}let i=e,a=async c=>{if(c==null||c.length===0)return c;let l=this.builder._schemaRuntimeDefinition;if(Tn.isInstance(l)){let u=new Set(l.getChannelKeys());return Promise.all(c.map(async([d,f])=>{if(!u.has(d))return[d,f];let p=await l.validateInput({[d]:f});return[d,Object.prototype.hasOwnProperty.call(p,d)?p[d]:f]}))}if(Jt(l)){let u=new Set(Object.keys(xi(l)));if(c.filter(([p])=>u.has(p)).length===0)return c;let d=Sa(this._metaRegistry.getExtendedChannelSchemas(l,{withReducerSchema:!0})),f=Sa(l);return c.map(([p,m])=>{if(!u.has(p))return[p,m];let[h,_]=sn(m);if(h){let w=xa(f,{[p]:_});return[p,Object.prototype.hasOwnProperty.call(w,p)?{[On]:w[p]}:m]}let y=xa(d,{[p]:m});return[p,Object.prototype.hasOwnProperty.call(y,p)?y[p]:m]})}return c};async function o(c){if(c){if(Ct(c))return c.graph===_r.PARENT?null:a(c._updateAsTuples().filter(([l])=>r.includes(l)));if(Array.isArray(c)&&c.length>0&&c.some(Ct)){let l=[];for(let u of c)if(Ct(u)){if(u.graph===_r.PARENT)continue;l.push(...u._updateAsTuples().filter(([d])=>r.includes(d)))}else{let d=await o(u);d&&l.push(...d??[])}return a(l)}else{if(typeof c=="object"&&!Array.isArray(c))return a(Object.entries(c).filter(([l])=>r.includes(l)));{let l=Array.isArray(c)?"array":typeof c;throw new ve(`Expected node "${i.toString()}" to return an object or an array containing at least one Command object, received ${l}`,{lc_error_code:"INVALID_GRAPH_NODE_RETURN_VALUE"})}}}else return null}let s=[{value:Ir,mapper:new Rt({func:r.length&&r[0]===Ui?n:o,trace:!1,recurse:!1})}];if(e==="__start__")this.nodes[e]=new $n({tags:[ht],triggers:[Je],channels:[Je],writers:[new ut(s,[ht])]});else{let c=t?.input??this.builder._schemaDefinition,l=Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(c)).map(m=>[m,m])),u=Object.keys(l).length===1&&Ui in l,d=`branch:to:${e}`;this.channels[d]=t?.defer?new Q0:new In(!1);let f=t?.cachePolicy,p=f===!1?void 0:f;this.nodes[e]=new $n({triggers:[d],channels:u?Object.keys(l):l,writers:[new ut(s,[ht])],mapper:u?void 0:m=>Object.fromEntries(Object.entries(m).filter(([h])=>h in l)),bound:t?.runnable,metadata:t?.metadata,retryPolicy:t?.retryPolicy,cachePolicy:p,timeout:t?.timeout,subgraphs:t?.subgraphs,ends:t?.ends,isErrorHandler:t?.isErrorHandler,errorHandlerNode:t?.errorHandlerNode})}}attachEdge(e,t){if(t!=="__end__"){if(typeof e=="string")this.nodes[e].writers.push(new ut([{channel:`branch:to:${t}`,value:null}],[ht]));else if(Array.isArray(e)){let r=`join:${e.join("+")}:${t}`;this.channels[r]=this.builder.nodes[t].defer?new DS(new Set(e)):new jS(new Set(e)),this.nodes[t].triggers.push(r);for(let n of e)this.nodes[n].writers.push(new ut([{channel:r,value:n}],[ht]))}}}attachBranch(e,t,r,n={withReader:!0}){let i=async(a,o)=>{let s=a.filter(l=>l!==Qe);if(!s.length)return;let c=s.map(l=>wt(l)?l:{channel:l==="__end__"?l:`branch:to:${l}`,value:e});await ut.doWrite({...o,tags:(o.tags??[]).concat([ht])},c)};this.nodes[e].writers.push(r.run(i,n.withReader?a=>rM.doRead(a,this.streamChannels??this.outputChannels,!0):void 0))}async _validateInput(e){if(e==null)return e;let t=this.builder._inputRuntimeDefinition,r=this.builder._schemaRuntimeDefinition;if(Tn.isInstance(t)){if(Ct(e)){let i=e;return e.update&&(i.update=await t.validateInput(Array.isArray(e.update)?Object.fromEntries(e.update):e.update)),i}return await t.validateInput(e)}if(t===Lh&&Tn.isInstance(r)){if(Ct(e)){let i=e;return e.update&&(i.update=await r.validateInput(Array.isArray(e.update)?Object.fromEntries(e.update):e.update)),i}return await r.validateInput(e)}let n=(()=>{let i=a=>{if(a!=null)return this._metaRegistry.getExtendedChannelSchemas(a,{withReducerSchema:!0})};if(Jt(t))return i(t);if(t===Lh)return Jt(r)?Sa(i(r)):void 0})();if(Ct(e)){let i=e;if(e.update&&n!=null){let a=Array.isArray(e.update)?Object.fromEntries(e.update):e.update,o=xa(n,a);i.update=Object.fromEntries(Object.keys(a).map(s=>[s,o[s]]))}return i}return n!=null?xa(n,e):e}isInterrupted(e){return Ha(e)}async _validateContext(e){let t=this.builder._configRuntimeSchema;return Jt(t)&&xa(t,e),e}};function dZ(e){return typeof e=="object"&&e!==null&&e.channels!==void 0}function fZ(e){if(wt(e))return[e];let t=[];Ct(e)?t.push(e):Array.isArray(e)&&t.push(...e.filter(Ct));let r=[];for(let n of t){if(n.graph===_r.PARENT)throw new Qu(n);wt(n.goto)||typeof n.goto=="string"?r.push(n.goto):Array.isArray(n.goto)&&r.push(...n.goto)}return r}function YM(){return new OS({path:new Rt({func:fZ,tags:[ht],trace:!1,recurse:!1,name:"<control_branch>"})})}var pZ=class extends BS{constructor(){super({channels:{__root__:{reducer:za,default:()=>[]}}})}};function mZ(e,t){let{stateKey:r,...n}=t??{},i=Ec(n),a=r??"messages";r===null&&(a=void 0);let o=kt(e);if(!o.id)throw new Error("Message ID is required.");let s=(Array.isArray(i.callbacks)?i.callbacks:typeof i.callbacks<"u"?i.callbacks.handlers:[]).find(c=>"name"in c&&c.name==="StreamMessagesHandler");if(s){let c=i.metadata??{},l=(c.langgraph_checkpoint_ns??"").split("|");s._emit([l,c],o,void 0,!1)}return a&&i.configurable?.__pregel_send?.([[a,o]]),o}function hZ(e,t){let r=typeof e=="string"?{name:e,retry:void 0,cachePolicy:void 0,timeout:void 0}:e,{name:n,retry:i}=r,a=Bi(r.timeout);if(_S(t)||yS(t))throw new Error("Generators are disallowed as tasks. For streaming responses, use config.write.");let o=r.cachePolicy??("cache"in r?r.cache:void 0),s;return typeof o=="boolean"?s=o?{}:void 0:s=o,(...c)=>dM({func:t,name:n,retry:i,cache:s,timeout:a},...c)}var ej=function(t,r){let{name:n,checkpointer:i,store:a,cache:o}=typeof t=="string"?{name:t,checkpointer:void 0,store:void 0}:t,s=Bi(typeof t=="string"?void 0:t.timeout);if(_S(r)||yS(r))throw new Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");let c="updates",l=uM(n,r);function u(m){return typeof m=="object"&&m!==null&&"__lg_type"in m&&m.__lg_type==="__pregel_final"}let d=new Rt({name:"pluckReturnValue",func:m=>u(m)?m.value:m}),f=new Rt({name:"pluckSaveValue",func:m=>u(m)?m.save:m}),p=new $n({bound:l,triggers:[Je],channels:[Je],timeout:s,writers:[new ut([{channel:Qe,value:Ir,mapper:d},{channel:Wi,value:Ir,mapper:f}],[ht])]});return new Dh({name:n,checkpointer:i,nodes:{[n]:p},channels:{[Je]:new In,[Qe]:new Sn,[Wi]:new Sn},inputChannels:Je,outputChannels:Qe,streamChannels:Qe,streamMode:c,store:a,cache:o})};ej.final=function({value:t,save:r}){return{value:t,save:r,__lg_type:"__pregel_final"}};function gZ(){return Re.getRunnableConfig().configurable?.[Zi]}var _Z=Pu.Root({messages:Pu({reducer:za,default:()=>[]})}),tj={reducer:{fn:za},jsonSchemaExtra:{langgraph_type:"messages"},default:()=>[]},yZ=Nt.object({messages:qM(Nt.custom(),tj)});function vZ(e){let t=Re.getRunnableConfig();if(!t)throw new Error("Called interrupt() outside the context of a graph.");let r=t.configurable;if(!r)throw new Error("No configurable found in config");return r.writer?.(e)}export{Je as a,Qe as b,Le as c,Fh as d,qS as e,Fa as f,wt as g,ij as h,Ha as i,_r as j,Ct as k,Zr as l,Ju as m,Vh as n,Ga as o,Ku as p,qu as q,li as r,Xu as s,Yu as t,oj as u,Qu as v,Zh as w,Ji as x,ui as y,ed as z,sj as A,td as B,je as C,ve as D,cj as E,Hh as F,lj as G,Lc as H,uj as I,Tk as J,ar as K,Dj as L,jn as M,zk as N,Hc as O,Uk as P,Pe as Q,tt as R,St as S,ss as T,cs as U,Ne as V,us as W,it as X,un as Y,qa as Z,Ya as _,Qa as $,or as aa,mi as ba,P$ as ca,Re as da,Wt as ea,$t as fa,ke as ga,Rr as ha,gt as ia,oa as ja,la as ka,fo as la,ha as ma,Vf as na,xo as oa,Ge as pa,lt as qa,xr as ra,wp as sa,xa as ta,Si as ua,Jt as va,xi as wa,Sa as xa,Sp as ya,XC as za,z as Aa,Nt as Ba,Mp as Ca,Et as Da,se as Ea,Qr as Fa,Lr as Ga,qt as Ha,RF as Ia,Hl as Ja,Xp as Ka,Xw as La,gP as Ma,_P as Na,UF as Oa,LF as Pa,Qw as Qa,Ca as Ra,nm as Sa,Aa as Ta,YF as Ua,hx as Va,uc as Wa,pu as Xa,rn as Ya,eV as Za,pV as _a,Go as $a,wn as ab,ih as bb,OR as cb,Sc as db,sh as eb,RR as fb,yt as gb,Pi as hb,Pu as ib,JV as jb,KV as kb,ph as lb,qV as mb,eS as nb,tS as ob,Ic as pb,rS as qb,an as rb,gh as sb,oS as tb,Nu as ub,Ru as vb,sS as wb,cS as xb,_h as yb,dS as zb,GR as Ab,fS as Bb,gS as Cb,Rt as Db,PS as Eb,Mi as Fb,iZ as Gb,ja as Hb,ji as Ib,zh as Jb,Uh as Kb,Di as Lb,qo as Mb,zi as Nb,Tn as Ob,oZ as Pb,za as Qb,FS as Rb,sZ as Sb,cZ as Tb,Fu as Ub,qM as Vb,BS as Wb,QM as Xb,pZ as Yb,mZ as Zb,hZ as _b,ej as $b,gZ as ac,_Z as bc,tj as cc,yZ as dc,vZ as ec};
451
+ `),{lc_error_code:"UNREACHABLE_NODE"});for(let n of r)if(n!=="__end__"&&!(n in this.nodes))throw new Error(`Found edge ending at unknown node \`${n}\``);if(e){for(let n of e)if(!(n in this.nodes))throw new Error(`Interrupt node \`${n}\` is not present`)}this.compiled=!0}},NS=class extends Dh{builder;constructor({builder:e,...t}){super(t),this.builder=e}withConfig(e){return super.withConfig(e)}attachNode(e,t){this.channels[e]=new In,this.nodes[e]=new $n({channels:[],triggers:[],metadata:t.metadata,subgraphs:t.subgraphs,ends:t.ends}).pipe(t.runnable).pipe(new ut([{channel:e,value:Ir}],[ht])),this.streamChannels.push(e)}attachEdge(e,t){if(t==="__end__"){if(e==="__start__")throw new Error("Cannot have an edge from START to END");this.nodes[e].writers.push(new ut([{channel:Qe,value:Ir}],[ht]))}else this.nodes[t].triggers.push(e),this.nodes[t].channels.push(e)}attachBranch(e,t,r){e==="__start__"&&!this.nodes.__start__&&(this.nodes[Je]=UM.subscribeTo(Je,{tags:[ht]})),this.nodes[e].pipe(r.run(i=>new ut(i.map(a=>wt(a)?a:{channel:a==="__end__"?Qe:`branch:${e}:${t}:${a}`,value:Ir}),[ht])));let n=r.ends?Object.values(r.ends):Object.keys(this.nodes);for(let i of n)if(i!=="__end__"){let a=`branch:${e}:${t}:${i}`;this.channels[a]=new In,this.nodes[i].triggers.push(a),this.nodes[i].channels.push(a)}}async getGraphAsync(e){let t=e?.xray,r=new Lo,n={[Je]:r.addNode({schema:rn.any()},Je)},i={},a={};t&&(a=Object.fromEntries((await kn(this.getSubgraphsAsync())).filter(l=>FM(l[1]))));let o=[];function s(l,u,d,f=!1){if(u==="__end__"&&i.__end__===void 0&&(i[Qe]=r.addNode({schema:rn.any()},Qe)),n[l]!==void 0){if(i[u]===void 0)throw new Error(`End node ${u} not found!`);return o.push({src:l,dest:u,conditional:f}),r.addEdge(n[l],i[u],d!==u?d:void 0,f)}}for(let[l,u]of Object.entries(this.builder.nodes)){let d=Tt(l),f=u.runnable,p=u.metadata??{};if(this.interruptBefore?.includes(l)&&this.interruptAfter?.includes(l)?p.__interrupt="before,after":this.interruptBefore?.includes(l)?p.__interrupt="before":this.interruptAfter?.includes(l)&&(p.__interrupt="after"),t){let m=typeof t=="number"?t-1:t,h=a[l]!==void 0?await a[l].getGraphAsync({...e,xray:m}):f.getGraph(e);if(h.trimFirstNode(),h.trimLastNode(),Object.keys(h.nodes).length>1){let w=function(S){return S?S.lc_runnable:!1},x=function(S,$){if(S!==void 0&&!di(S))return S;if(w($))try{let P=$.getName();return P=P.startsWith("Runnable")?P.slice(8):P,P}catch{return $.getName()}else return $.name??"UnknownSchema"},[_,y]=r.extend(h,d);if(_===void 0)throw new Error(`Could not extend subgraph "${l}" due to missing entrypoint.`);y!==void 0&&(n[d]={name:x(y.id,y.data),...y}),i[d]={name:x(_.id,_.data),..._}}else{let _=r.addNode(f,d,p);n[d]=_,i[d]=_}}else{let m=r.addNode(f,d,p);n[d]=m,i[d]=m}}let c=[...this.builder.allEdges].sort(([l],[u])=>l<u?-1:u>l?1:0);for(let[l,u]of c)s(Tt(l),Tt(u));for(let[l,u]of Object.entries(this.builder.branches)){let d={...Object.fromEntries(Object.keys(this.builder.nodes).filter(f=>f!==l).map(f=>[Tt(f),Tt(f)])),[Qe]:Qe};for(let f of Object.values(u)){let p;f.ends!==void 0?p=f.ends:p=d;for(let[m,h]of Object.entries(p))s(Tt(l),Tt(h),m,!0)}}for(let[l,u]of Object.entries(this.builder.nodes))if(u.ends!==void 0)for(let d of u.ends)s(Tt(l),Tt(d),void 0,!0);return BM(this.builder.nodes,o,s),r}getGraph(e){let t=e?.xray,r=new Lo,n={[Je]:r.addNode({schema:rn.any()},Je)},i={},a={};t&&(a=Object.fromEntries(Pa(this.getSubgraphs()).filter(l=>FM(l[1]))));let o=[];function s(l,u,d,f=!1){if(u==="__end__"&&i.__end__===void 0&&(i[Qe]=r.addNode({schema:rn.any()},Qe)),n[l]!==void 0){if(i[u]===void 0)throw new Error(`End node ${u} not found!`);return o.push({src:l,dest:u,conditional:f}),r.addEdge(n[l],i[u],d!==u?d:void 0,f)}}for(let[l,u]of Object.entries(this.builder.nodes)){let d=Tt(l),f=u.runnable,p=u.metadata??{};if(this.interruptBefore?.includes(l)&&this.interruptAfter?.includes(l)?p.__interrupt="before,after":this.interruptBefore?.includes(l)?p.__interrupt="before":this.interruptAfter?.includes(l)&&(p.__interrupt="after"),t){let m=typeof t=="number"?t-1:t,h=a[l]!==void 0?a[l].getGraph({...e,xray:m}):f.getGraph(e);if(h.trimFirstNode(),h.trimLastNode(),Object.keys(h.nodes).length>1){let w=function(S){return S?S.lc_runnable:!1},x=function(S,$){if(S!==void 0&&!di(S))return S;if(w($))try{let P=$.getName();return P=P.startsWith("Runnable")?P.slice(8):P,P}catch{return $.getName()}else return $.name??"UnknownSchema"},[_,y]=r.extend(h,d);if(_===void 0)throw new Error(`Could not extend subgraph "${l}" due to missing entrypoint.`);y!==void 0&&(n[d]={name:x(y.id,y.data),...y}),i[d]={name:x(_.id,_.data),..._}}else{let _=r.addNode(f,d,p);n[d]=_,i[d]=_}}else{let m=r.addNode(f,d,p);n[d]=m,i[d]=m}}let c=[...this.builder.allEdges].sort(([l],[u])=>l<u?-1:u>l?1:0);for(let[l,u]of c)s(Tt(l),Tt(u));for(let[l,u]of Object.entries(this.builder.branches)){let d={...Object.fromEntries(Object.keys(this.builder.nodes).filter(f=>f!==l).map(f=>[Tt(f),Tt(f)])),[Qe]:Qe};for(let f of Object.values(u)){let p;f.ends!==void 0?p=f.ends:p=d;for(let[m,h]of Object.entries(p))s(Tt(l),Tt(h),m,!0)}}for(let[l,u]of Object.entries(this.builder.nodes))if(u.ends!==void 0)for(let d of u.ends)s(Tt(l),Tt(d),void 0,!0);return BM(this.builder.nodes,o,s),r}};function FM(e){return typeof e.attachNode=="function"&&typeof e.attachEdge=="function"}function Tt(e){return e==="subgraph"?`"${e}"`:e}function BM(e,t,r){let n=new Set(t.map(a=>a.src)),i=[...new Set(t.filter(a=>!a.conditional&&a.dest!=="__end__").map(a=>a.dest))].sort();for(let a of i){if(n.has(a))continue;let o=Object.keys(e).find(s=>Tt(s)===a);o!==void 0&&e[o]?.isErrorHandler||r(a,Qe)}}function Mi(e){return typeof e=="object"&&e!==null&&"~standard"in e&&typeof e["~standard"]=="object"&&e["~standard"]!==null&&"validate"in e["~standard"]}function RS(e){return typeof e=="object"&&e!==null&&"~standard"in e&&typeof e["~standard"]=="object"&&e["~standard"]!==null&&"jsonSchema"in e["~standard"]}function iZ(e){return Mi(e)&&RS(e)}function ja(e){if(RS(e))try{return e["~standard"].jsonSchema.input({target:"draft-07"})}catch{return}}function ji(e){if(e!=null&&Mi(e))try{let t=e["~standard"].validate(void 0);if(t&&typeof t=="object"&&!("then"in t&&typeof t.then=="function")){let r=t;if(!r.issues){let n=r.value;return()=>n}}}catch{}}var aZ=e=>e!=null&&e.lc_graph_name==="DeltaChannel",zh=class VM extends yt{lc_graph_name="DeltaChannel";value;reducer;snapshotFrequency;initialValueFactory;constructor(t,r){super();let n=r?.snapshotFrequency??1e3;if(!Number.isInteger(n)||n<=0)throw new Error(`snapshotFrequency must be a positive integer, got ${n}`);this.reducer=t,this.snapshotFrequency=n,this.initialValueFactory=r?.initialValueFactory??(()=>[]),this.value=void 0}fromCheckpoint(t){let r=new VM(this.reducer,{snapshotFrequency:this.snapshotFrequency,initialValueFactory:this.initialValueFactory});return t===void 0?r.value=this.initialValueFactory():Qh(t)?r.value=t.value:r.value=t,r}replayWrites(t){let r=t.map(o=>o[2]);if(r.length===0)return;let n=this.value,i=0;for(let o=0;o<r.length;o+=1){let[s,c]=sn(r[o]);s&&(n=c??this.initialValueFactory(),i=o+1)}let a=r.slice(i);this.value=a.length>0?this.reducer(n,a):n}update(t){if(t.length===0)return!1;let r,n=!1;for(let a of t)if(Za(a)){if(n)throw new ve("Can receive only one Overwrite value per step.");n=!0,[,r]=sn(a)}if(n)return this.value=r??this.initialValueFactory(),!0;let i=this.value===void 0?this.initialValueFactory():this.value;return this.value=this.reducer(i,t),!0}get(){if(this.value===void 0)throw new je;return this.value}checkpoint(){}isAvailable(){return this.value!==void 0}equals(t){return this===t?!0:!aZ(t)||this.snapshotFrequency!==t.snapshotFrequency?!1:this.reducer===t.reducer}};var MS=Symbol.for("langgraph.channel.missing"),Uh=class ZM extends yt{lc_graph_name="UntrackedValue";guard;_value=MS;initialValueFactory;constructor(t){super(),this.guard=t?.guard??!0,this.initialValueFactory=t?.initialValueFactory,this.initialValueFactory&&(this._value=this.initialValueFactory())}fromCheckpoint(t){return new ZM({guard:this.guard,initialValueFactory:this.initialValueFactory})}update(t){if(t.length===0)return!1;if(t.length!==1&&this.guard)throw new ve("UntrackedValue(guard=true) can receive only one value per step. Use guard=false if you want to store any one of multiple values.",{lc_error_code:"INVALID_CONCURRENT_GRAPH_UPDATE"});return this._value=t[t.length-1],!0}get(){if(this._value===MS)throw new je;return this._value}checkpoint(){}isAvailable(){return this._value!==MS}};var Da=(e,t)=>e.size===t.size&&[...e].every(r=>t.has(r)),jS=class HM extends yt{lc_graph_name="NamedBarrierValue";names;seen;constructor(t){super(),this.names=t,this.seen=new Set}fromCheckpoint(t){let r=new HM(this.names);return typeof t<"u"&&(r.seen=new Set(t)),r}update(t){let r=!1;for(let n of t)if(this.names.has(n))this.seen.has(n)||(this.seen.add(n),r=!0);else throw new ve(`Value ${JSON.stringify(n)} not in names ${JSON.stringify(this.names)}`);return r}get(){if(!Da(this.names,this.seen))throw new je}checkpoint(){return[...this.seen]}consume(){return this.seen&&this.names&&Da(this.seen,this.names)?(this.seen=new Set,!0):!1}isAvailable(){return!!this.names&&Da(this.names,this.seen)}},DS=class GM extends yt{lc_graph_name="NamedBarrierValueAfterFinish";names;seen;finished;constructor(t){super(),this.names=t,this.seen=new Set,this.finished=!1}fromCheckpoint(t){let r=new GM(this.names);if(typeof t<"u"){let[n,i]=t;r.seen=new Set(n),r.finished=i}return r}update(t){let r=!1;for(let n of t)if(this.names.has(n)&&!this.seen.has(n))this.seen.add(n),r=!0;else if(!this.names.has(n))throw new ve(`Value ${JSON.stringify(n)} not in names ${JSON.stringify(this.names)}`);return r}get(){if(!this.finished||!Da(this.names,this.seen))throw new je}checkpoint(){return[[...this.seen],this.finished]}consume(){return this.finished&&this.seen&&this.names&&Da(this.seen,this.names)?(this.seen=new Set,this.finished=!1,!0):!1}finish(){return!this.finished&&this.names&&Da(this.names,this.seen)?(this.finished=!0,!0):!1}isAvailable(){return this.finished&&!!this.names&&Da(this.names,this.seen)}};var zS=Symbol.for("langgraph.state.reduced_value"),Di=class{[zS]=!0;valueSchema;inputSchema;reducer;jsonSchemaExtra;constructor(e,t){this.reducer=t.reducer,this.jsonSchemaExtra=t.jsonSchemaExtra,this.valueSchema=e,this.inputSchema="inputSchema"in t?t.inputSchema:e,this.jsonSchemaExtra=t.jsonSchemaExtra}static isInstance(e){return typeof e=="object"&&e!==null&&zS in e&&e[zS]===!0}};var WM=Symbol.for("langgraph.state.untracked_value"),qo=class{[WM]=!0;schema;guard;constructor(e,t){this.schema=e,this.guard=t?.guard??!0}static isInstance(e){return typeof e=="object"&&e!==null&&WM in e}};var US=Symbol.for("langgraph.state.delta_value"),zi=class{[US]=!0;valueSchema;inputSchema;reducer;snapshotFrequency;jsonSchemaExtra;constructor(e,t){this.reducer=t.reducer,this.valueSchema=e,this.inputSchema="inputSchema"in t?t.inputSchema:e,this.snapshotFrequency=t.snapshotFrequency,this.jsonSchemaExtra=t.jsonSchemaExtra}static isInstance(e){return typeof e=="object"&&e!==null&&US in e&&e[US]===!0}};var LS=Symbol.for("langgraph.state.state_schema"),Tn=class{[LS]=!0;constructor(e){this.fields=e}getChannels(){let e={};for(let[t,r]of Object.entries(this.fields))if(zi.isInstance(r)){let n=ji(r.valueSchema);e[t]=new zh(r.reducer,{snapshotFrequency:r.snapshotFrequency,initialValueFactory:n})}else if(Di.isInstance(r)){let n=ji(r.valueSchema);e[t]=new Pi(r.reducer,n)}else if(qo.isInstance(r)){let n=r.schema?ji(r.schema):void 0;e[t]=new Uh({guard:r.guard,initialValueFactory:n})}else if(Mi(r))e[t]=new Sn(ji(r));else throw new Error(`Invalid state field "${t}": must be a schema, ReducedValue, DeltaValue, UntrackedValue, or ManagedValue`);return e}getJsonSchema(){let e={},t=[];for(let[r,n]of Object.entries(this.fields)){let i;if(zi.isInstance(n)||Di.isInstance(n)?(i=ja(n.valueSchema),n.jsonSchemaExtra&&(i={...i??{},...n.jsonSchemaExtra})):qo.isInstance(n)?i=n.schema?ja(n.schema):void 0:Mi(n)&&(i=ja(n)),i){e[r]=i;let a=!1;zi.isInstance(n)||Di.isInstance(n)?a=ji(n.valueSchema)!==void 0:qo.isInstance(n)?a=n.schema?ji(n.schema)!==void 0:!1:a=ji(n)!==void 0,a||t.push(r)}}return{type:"object",properties:e,required:t.length>0?t:void 0}}getInputJsonSchema(){let e={};for(let[t,r]of Object.entries(this.fields)){let n;zi.isInstance(r)||Di.isInstance(r)?(n=ja(r.inputSchema),r.jsonSchemaExtra&&(n={...n??{},...r.jsonSchemaExtra})):qo.isInstance(r)?n=r.schema?ja(r.schema):void 0:Mi(r)&&(n=ja(r)),n&&(e[t]=n)}return{type:"object",properties:e}}getChannelKeys(){return Object.entries(this.fields).map(([e])=>e)}getAllKeys(){return Object.keys(this.fields)}async validateInput(e){if(e==null||typeof e!="object")return e;let t={};for(let[r,n]of Object.entries(e)){let i=this.fields[r];if(i===void 0){t[r]=n;continue}let a;if(zi.isInstance(i)||Di.isInstance(i)){let[o,s]=sn(n);if(o){a=i.valueSchema;let c=await a["~standard"].validate(s);if(c.issues)throw new Error(`Validation failed for field "${r}": ${JSON.stringify(c.issues)}`);t[r]={[On]:c.value};continue}a=i.inputSchema}else qo.isInstance(i)?a=i.schema:Mi(i)&&(a=i);if(a){let o=await a["~standard"].validate(n);if(o.issues)throw new Error(`Validation failed for field "${r}": ${JSON.stringify(o.issues)}`);t[r]=o.value}else t[r]=n}return t}static isInstance(e){return typeof e=="object"&&e!==null&&LS in e&&e[LS]===!0}};var oZ="__remove_all__";function za(e,t){let r=Array.isArray(e)?e:[e],n=Array.isArray(t)?t:[t],i=r.map(kt),a=n.map(kt);for(let u of i)(u.id===null||u.id===void 0)&&(u.id=Xi(),u.lc_kwargs.id=u.id);let o;for(let u=0;u<a.length;u+=1){let d=a[u];(d.id===null||d.id===void 0)&&(d.id=Xi(),d.lc_kwargs.id=d.id),Nr.isInstance(d)&&d.id==="__remove_all__"&&(o=u)}if(o!=null)return a.slice(o+1);let s=[...i],c=new Map(s.map((u,d)=>[u.id,d])),l=new Set;for(let u of a){let d=c.get(u.id);if(d!==void 0)Nr.isInstance(u)?l.add(u.id):(l.delete(u.id),s[d]=u);else{if(Nr.isInstance(u))throw new Error(`Attempting to delete a message with an ID that doesn't exist ('${u.id}')`);c.set(u.id,s.length),s.push(u)}}return s.filter(u=>!l.has(u.id))}function FS(e,t){let r=[];for(let s of t)Array.isArray(s)?r.push(...s):r.push(s);let n=e.length>0&&Pe.isInstance(e[0])?e:e.map(kt),i=r.map(kt),a=new Map;for(let s=0;s<n.length;s+=1){let c=n[s].id;c!=null&&a.set(c,s)}let o=[...n];for(let s of i){let c=s.id;Nr.isInstance(s)&&c==="__remove_all__"?(o.length=0,a.clear()):c==null?o.push(s):Nr.isInstance(s)?a.has(c)&&(o[a.get(c)]=null,a.delete(c)):a.has(c)?o[a.get(c)]=s:(a.set(c,o.length),o.push(s))}return o.filter(s=>s!==null)}var JM=rn.custom().default(()=>[]),KM=rn.custom(),sZ=new Di(JM,{inputSchema:KM,reducer:za,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}}),cZ=new zi(JM,{inputSchema:KM,reducer:FS,jsonSchemaExtra:{langgraph_type:"messages",description:"A list of chat messages"}});var lZ=class{_map=new Map;_extensionCache=new Map;get(e){return this._map.get(e)}extend(e,t){let r=this.get(e);this._map.set(e,t(r))}remove(e){return this._map.delete(e),this}has(e){return this._map.has(e)}getChannelsForSchema(e){let t={},r=xi(e);for(let[n,i]of Object.entries(r)){let a=this.get(i);a?.reducer?t[n]=new Pi(a.reducer.fn,a.default):t[n]=new Sn(a?.default)}return t}getExtendedChannelSchemas(e,t){if(Object.keys(t).length===0)return e;let r=Object.entries(t).filter(([,a])=>a===!0).sort(([a],[o])=>a.localeCompare(o)).map(([a,o])=>`${a}:${o}`).join("|"),n=this._extensionCache.get(r)??new Map;if(n.has(e))return n.get(e);let i=e;if(t.withReducerSchema||t.withJsonSchemaExtrasAsDescription){let a=Object.entries(xi(e)).map(([o,s])=>{let c=this.get(s),l=t.withReducerSchema?c?.reducer?.schema??s:s;if(t.withJsonSchemaExtrasAsDescription&&c?.jsonSchemaExtra){let u=Si(l)??Si(s),d=JSON.stringify({...c.jsonSchemaExtra,description:u});l=l.describe(`lg:${d}`)}return[o,l]});i=xp(e,Object.fromEntries(a)),lt(i)&&(i._def.unknownKeys="strip")}return t.asPartial&&(i=Sa(i)),n.set(e,i),this._extensionCache.set(r,n),i}},Fu=new lZ;function qM(e,t){if(t.reducer&&!t.default){let r=Sp(e);r!=null&&(t.default=r)}if(t.reducer){let r=Object.assign(e,{lg_reducer_schema:t.reducer?.schema??e});return Fu.extend(r,()=>t),r}else return Fu.extend(e,()=>t),e}function Xo(e){return e==null?!1:!!(Tn.isInstance(e)||Jt(e)||typeof e=="object"&&"lc_graph_name"in e&&e.lc_graph_name==="AnnotationRoot"||typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0&&Object.values(e).every(t=>typeof t=="function"||X0(t)))}function XM(e){if(typeof e!="object"||e==null)return!1;let t=e,r="state"in t&&Xo(t.state),n="stateSchema"in t&&Xo(t.stateSchema),i="input"in t&&Xo(t.input);return!(!r&&!n&&!i||"input"in t&&t.input!=null&&!Xo(t.input)||"output"in t&&t.output!=null&&!Xo(t.output))}var Ui="__root__",Rc="__default_error_handler__",Lh=Symbol.for("langgraph.state.partial"),BS=class extends PS{channels={};waitingEdges=new Set;_schemaDefinition;_schemaRuntimeDefinition;_inputDefinition;_inputRuntimeDefinition;_outputDefinition;_outputRuntimeDefinition;_schemaDefinitions=new Map;_metaRegistry=Fu;_configSchema;_configRuntimeSchema;_interrupt;_writer;_nodeDefaults={};constructor(e,t){super();let r=this._normalizeToStateGraphInit(e,t),n=r.state??r.stateSchema??r.input;if(!n)throw new Lc;let i=this._getChannelsFromSchema(n);this._schemaDefinition=i,Tn.isInstance(n)?this._schemaRuntimeDefinition=n:Jt(n)&&(this._schemaRuntimeDefinition=n),r.input?Tn.isInstance(r.input)?this._inputRuntimeDefinition=r.input:Jt(r.input)?this._inputRuntimeDefinition=r.input:this._inputRuntimeDefinition=Lh:this._inputRuntimeDefinition=Lh,r.output?Tn.isInstance(r.output)?this._outputRuntimeDefinition=r.output:Jt(r.output)?this._outputRuntimeDefinition=r.output:this._outputRuntimeDefinition=this._schemaRuntimeDefinition:this._outputRuntimeDefinition=this._schemaRuntimeDefinition;let a=r.input?this._getChannelsFromSchema(r.input):i,o=r.output?this._getChannelsFromSchema(r.output):i;this._inputDefinition=a,this._outputDefinition=o,this._addSchema(this._schemaDefinition),this._addSchema(this._inputDefinition),this._addSchema(this._outputDefinition),r.context&&Jt(r.context)&&(this._configRuntimeSchema=r.context),this._interrupt=r.interrupt,this._writer=r.writer}setNodeDefaults(e){return e.retryPolicy!==void 0&&(this._nodeDefaults.retryPolicy=e.retryPolicy),e.cachePolicy!==void 0&&(this._nodeDefaults.cachePolicy=typeof e.cachePolicy=="boolean"?e.cachePolicy?{}:void 0:e.cachePolicy),e.timeout!==void 0&&(this._nodeDefaults.timeout=Bi(e.timeout)),e.errorHandler!==void 0&&(this._nodeDefaults.errorHandler=e.errorHandler),this}_createDefaultErrorHandlerSpec(){let e=this._nodeDefaults.errorHandler;if(e!==void 0)return{runnable:new Rt({func:(t,r)=>{let n=r?.configurable?.[zc];return e(t,n,r)},name:Rc,trace:!1}),metadata:void 0,input:this._schemaDefinition,retryPolicy:void 0,cachePolicy:void 0,isErrorHandler:!0}}_normalizeToStateGraphInit(e,t){if(XM(e)){if(Jt(t)||dh.isInstance(t))return{...e,context:t};let r=t;return{...e,input:e.input??r?.input,output:e.output??r?.output,context:e.context??r?.context,interrupt:e.interrupt??r?.interrupt,writer:e.writer??r?.writer,nodes:e.nodes??r?.nodes}}if(Xo(e)){if(Jt(t)||dh.isInstance(t))return{state:e,context:t};let r=t;return{state:e,input:r?.input,output:r?.output,context:r?.context,interrupt:r?.interrupt,writer:r?.writer,nodes:r?.nodes}}if(dZ(e))return{state:uZ(e.channels)};throw new Lc}_getChannelsFromSchema(e){if(Tn.isInstance(e))return e.getChannels();if(Jt(e))return this._metaRegistry.getChannelsForSchema(e);if(typeof e=="object"&&"lc_graph_name"in e&&e.lc_graph_name==="AnnotationRoot")return e.spec;if(typeof e=="object"&&!Array.isArray(e)&&Object.keys(e).length>0)return e;throw new Lc("Invalid schema type. Expected StateSchema, Zod object, AnnotationRoot, or StateDefinition.")}get allEdges(){return new Set([...this.edges,...Array.from(this.waitingEdges).flatMap(([e,t])=>e.map(r=>[r,t]))])}_addSchema(e){if(!this._schemaDefinitions.has(e)){this._schemaDefinitions.set(e,e);for(let[t,r]of Object.entries(e)){let n;if(typeof r=="function"?n=r():n=r,this.channels[t]!==void 0){if(!this.channels[t].equals(n)&&n.lc_graph_name!=="LastValue")throw new Error(`Channel "${t}" already exists with a different type.`)}else this.channels[t]=n}}}addNode(...e){function t(n){return n.length>=1&&typeof n[0]!="string"}let r=t(e)?Array.isArray(e[0])?e[0]:Object.entries(e[0]).map(([n,i])=>[n,i]):[[e[0],e[1],e[2]]];if(r.length===0)throw new Error("No nodes provided in `addNode`");for(let[n,i,a]of r){if(n in this.channels)throw new Error(`${n} is already being used as a state attribute (a.k.a. a channel), cannot also be used as a node name.`);for(let f of["|",":"])if(n.includes(f))throw new Error(`"${f}" is a reserved character and is not allowed in node names.`);if(this.warnIfCompiled("Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph."),n in this.nodes)throw new Error(`Node \`${n}\` already present.`);if(n==="__end__"||n==="__start__")throw new Error(`Node \`${n}\` is reserved.`);let o=this._schemaDefinition;a?.input!==void 0&&(o=this._getChannelsFromSchema(a.input)),this._addSchema(o);let s;se.isRunnable(i)?s=i:typeof i=="function"?s=new Rt({func:i,name:n,trace:!1}):s=at(i);let c=a?.cachePolicy,l;c!==void 0&&(l=typeof c=="boolean"?c?{}:!1:c);let u;if(a?.errorHandler!==void 0){if(u=`__error_handler__${n}`,u in this.nodes)throw new Error(`Cannot add error handler to node \`${n}\`: the reserved name \`${u}\` is already in use. StateGraph registers \`__error_handler__<nodeName>\` when you pass \`errorHandler\` in addNode options. Remove or rename the existing node with that name (for example, you may have added it manually).`);let f=a.errorHandler,p={runnable:new Rt({func:(m,h)=>{let _=h?.configurable?.[zc];return f(m,_,h)},name:u,trace:!1}),metadata:void 0,input:o??this._schemaDefinition,retryPolicy:void 0,cachePolicy:void 0,isErrorHandler:!0};this.nodes[u]=p}let d={runnable:s,retryPolicy:a?.retryPolicy,cachePolicy:l,timeout:Bi(a?.timeout),metadata:a?.metadata,input:o??this._schemaDefinition,subgraphs:ju(s)?[s]:a?.subgraphs,ends:a?.ends,defer:a?.defer,errorHandlerNode:u};this.nodes[n]=d}return this}addEdge(e,t){if(typeof e=="string")return super.addEdge(e,t);this.compiled&&console.warn("Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.");for(let r of e){if(r==="__end__")throw new Error("END cannot be a start node");if(!Object.keys(this.nodes).some(n=>n===r))throw new Error(`Need to add a node named "${r}" first`)}if(t==="__end__")throw new Error("END cannot be an end node");if(!Object.keys(this.nodes).some(r=>r===t))throw new Error(`Need to add a node named "${t}" first`);return this.waitingEdges.add([e,t]),this}addSequence(e){let t=Array.isArray(e)?e:Object.entries(e);if(t.length===0)throw new Error("Sequence requires at least one node.");let r;for(let[n,i,a]of t){if(n in this.nodes)throw new Error(`Node names must be unique: node with the name "${n}" already exists.`);let o=n;this.addNode(n,i,a),r!=null&&this.addEdge(r,o),r=o}return this}compile({checkpointer:e,store:t,cache:r,interruptBefore:n,interruptAfter:i,name:a,description:o,transformers:s}={}){let c=this._createDefaultErrorHandlerSpec();if(c!==void 0){if(Rc in this.nodes)throw new Error(`Cannot apply a default error handler: the reserved node name \`${Rc}\` is already in use. setNodeDefaults({ errorHandler }) registers a node with that name; rename the conflicting node.`);this.nodes[Rc]=c}try{return this._compileResolved({checkpointer:e,store:t,cache:r,interruptBefore:n,interruptAfter:i,name:a,description:o,transformers:s,defaultErrorHandlerNode:c!==void 0?Rc:void 0})}finally{c!==void 0&&delete this.nodes[Rc]}}_compileResolved({checkpointer:e,store:t,cache:r,interruptBefore:n,interruptAfter:i,name:a,description:o,transformers:s,defaultErrorHandlerNode:c}){this.validate([...Array.isArray(n)?n:[],...Array.isArray(i)?i:[]]);let l=Object.keys(this._schemaDefinitions.get(this._outputDefinition)),u=l.length===1&&l[0]===Ui?Ui:l,d=Object.keys(this.channels),f=d.length===1&&d[0]===Ui?Ui:d,p=this._interrupt,m=new QM({builder:this,checkpointer:e,interruptAfter:i,interruptBefore:n,autoValidate:!1,nodes:{},channels:{...this.channels,[Je]:new In},inputChannels:Je,outputChannels:u,streamChannels:f,streamMode:"updates",store:t,cache:r,name:a,description:o,userInterrupt:p,streamTransformers:s});m.attachNode(Je);let h=this._nodeDefaults,_=h.retryPolicy!==void 0||h.cachePolicy!==void 0||h.timeout!==void 0||c!==void 0;for(let[y,w]of Object.entries(this.nodes)){let x=w.isErrorHandler===!0,S=_?{...w,retryPolicy:w.retryPolicy??h.retryPolicy,cachePolicy:x||w.cachePolicy===!1?void 0:w.cachePolicy??h.cachePolicy,timeout:w.timeout??h.timeout,errorHandlerNode:!x&&c!==void 0&&w.errorHandlerNode===void 0?c:w.errorHandlerNode}:w;m.attachNode(y,S)}m.attachBranch(Je,Bh,YM(),{withReader:!1});for(let[y]of Object.entries(this.nodes))m.attachBranch(y,Bh,YM(),{withReader:!1});for(let[y,w]of this.edges)m.attachEdge(y,w);for(let[y,w]of this.waitingEdges)m.attachEdge(y,w);for(let[y,w]of Object.entries(this.branches))for(let[x,S]of Object.entries(w))m.attachBranch(y,x,S);return m.validate()}};function uZ(e){let t={};for(let[r,n]of Object.entries(e))r===Ui?t[r]=fh(n):t[r]=fh(n);return t}var QM=class extends NS{description;_metaRegistry=Fu;constructor({description:e,...t}){super(t),this.description=e}attachNode(e,t){let r;e==="__start__"?r=Object.entries(this.builder._schemaDefinitions.get(this.builder._inputDefinition)).map(([c])=>c):r=Object.keys(this.builder.channels);function n(c){if(Ct(c))return c.graph===_r.PARENT?null:c._updateAsTuples();if(Array.isArray(c)&&c.length>0&&c.some(l=>Ct(l))){let l=[];for(let u of c)if(Ct(u)){if(u.graph===_r.PARENT)continue;l.push(...u._updateAsTuples())}else l.push([Ui,u]);return l}else if(c!=null)return[[Ui,c]];return null}let i=e,a=async c=>{if(c==null||c.length===0)return c;let l=this.builder._schemaRuntimeDefinition;if(Tn.isInstance(l)){let u=new Set(l.getChannelKeys());return Promise.all(c.map(async([d,f])=>{if(!u.has(d))return[d,f];let p=await l.validateInput({[d]:f});return[d,Object.prototype.hasOwnProperty.call(p,d)?p[d]:f]}))}if(Jt(l)){let u=new Set(Object.keys(xi(l)));if(c.filter(([p])=>u.has(p)).length===0)return c;let d=Sa(this._metaRegistry.getExtendedChannelSchemas(l,{withReducerSchema:!0})),f=Sa(l);return c.map(([p,m])=>{if(!u.has(p))return[p,m];let[h,_]=sn(m);if(h){let w=xa(f,{[p]:_});return[p,Object.prototype.hasOwnProperty.call(w,p)?{[On]:w[p]}:m]}let y=xa(d,{[p]:m});return[p,Object.prototype.hasOwnProperty.call(y,p)?y[p]:m]})}return c};async function o(c){if(c){if(Ct(c))return c.graph===_r.PARENT?null:a(c._updateAsTuples().filter(([l])=>r.includes(l)));if(Array.isArray(c)&&c.length>0&&c.some(Ct)){let l=[];for(let u of c)if(Ct(u)){if(u.graph===_r.PARENT)continue;l.push(...u._updateAsTuples().filter(([d])=>r.includes(d)))}else{let d=await o(u);d&&l.push(...d??[])}return a(l)}else{if(typeof c=="object"&&!Array.isArray(c))return a(Object.entries(c).filter(([l])=>r.includes(l)));{let l=Array.isArray(c)?"array":typeof c;throw new ve(`Expected node "${i.toString()}" to return an object or an array containing at least one Command object, received ${l}`,{lc_error_code:"INVALID_GRAPH_NODE_RETURN_VALUE"})}}}else return null}let s=[{value:Ir,mapper:new Rt({func:r.length&&r[0]===Ui?n:o,trace:!1,recurse:!1})}];if(e==="__start__")this.nodes[e]=new $n({tags:[ht],triggers:[Je],channels:[Je],writers:[new ut(s,[ht])]});else{let c=t?.input??this.builder._schemaDefinition,l=Object.fromEntries(Object.keys(this.builder._schemaDefinitions.get(c)).map(m=>[m,m])),u=Object.keys(l).length===1&&Ui in l,d=`branch:to:${e}`;this.channels[d]=t?.defer?new Q0:new In(!1);let f=t?.cachePolicy,p=f===!1?void 0:f;this.nodes[e]=new $n({triggers:[d],channels:u?Object.keys(l):l,writers:[new ut(s,[ht])],mapper:u?void 0:m=>Object.fromEntries(Object.entries(m).filter(([h])=>h in l)),bound:t?.runnable,metadata:t?.metadata,retryPolicy:t?.retryPolicy,cachePolicy:p,timeout:t?.timeout,subgraphs:t?.subgraphs,ends:t?.ends,isErrorHandler:t?.isErrorHandler,errorHandlerNode:t?.errorHandlerNode})}}attachEdge(e,t){if(t!=="__end__"){if(typeof e=="string")this.nodes[e].writers.push(new ut([{channel:`branch:to:${t}`,value:null}],[ht]));else if(Array.isArray(e)){let r=`join:${e.join("+")}:${t}`;this.channels[r]=this.builder.nodes[t].defer?new DS(new Set(e)):new jS(new Set(e)),this.nodes[t].triggers.push(r);for(let n of e)this.nodes[n].writers.push(new ut([{channel:r,value:n}],[ht]))}}}attachBranch(e,t,r,n={withReader:!0}){let i=async(a,o)=>{let s=a.filter(l=>l!==Qe);if(!s.length)return;let c=s.map(l=>wt(l)?l:{channel:l==="__end__"?l:`branch:to:${l}`,value:e});await ut.doWrite({...o,tags:(o.tags??[]).concat([ht])},c)};this.nodes[e].writers.push(r.run(i,n.withReader?a=>rM.doRead(a,this.streamChannels??this.outputChannels,!0):void 0))}async _validateInput(e){if(e==null)return e;let t=this.builder._inputRuntimeDefinition,r=this.builder._schemaRuntimeDefinition;if(Tn.isInstance(t)){if(Ct(e)){let i=e;return e.update&&(i.update=await t.validateInput(Array.isArray(e.update)?Object.fromEntries(e.update):e.update)),i}return await t.validateInput(e)}if(t===Lh&&Tn.isInstance(r)){if(Ct(e)){let i=e;return e.update&&(i.update=await r.validateInput(Array.isArray(e.update)?Object.fromEntries(e.update):e.update)),i}return await r.validateInput(e)}let n=(()=>{let i=a=>{if(a!=null)return this._metaRegistry.getExtendedChannelSchemas(a,{withReducerSchema:!0})};if(Jt(t))return i(t);if(t===Lh)return Jt(r)?Sa(i(r)):void 0})();if(Ct(e)){let i=e;if(e.update&&n!=null){let a=Array.isArray(e.update)?Object.fromEntries(e.update):e.update,o=xa(n,a);i.update=Object.fromEntries(Object.keys(a).map(s=>[s,o[s]]))}return i}return n!=null?xa(n,e):e}isInterrupted(e){return Ha(e)}async _validateContext(e){let t=this.builder._configRuntimeSchema;return Jt(t)&&xa(t,e),e}};function dZ(e){return typeof e=="object"&&e!==null&&e.channels!==void 0}function fZ(e){if(wt(e))return[e];let t=[];Ct(e)?t.push(e):Array.isArray(e)&&t.push(...e.filter(Ct));let r=[];for(let n of t){if(n.graph===_r.PARENT)throw new Qu(n);wt(n.goto)||typeof n.goto=="string"?r.push(n.goto):Array.isArray(n.goto)&&r.push(...n.goto)}return r}function YM(){return new OS({path:new Rt({func:fZ,tags:[ht],trace:!1,recurse:!1,name:"<control_branch>"})})}var pZ=class extends BS{constructor(){super({channels:{__root__:{reducer:za,default:()=>[]}}})}};function mZ(e,t){let{stateKey:r,...n}=t??{},i=Ec(n),a=r??"messages";r===null&&(a=void 0);let o=kt(e);if(!o.id)throw new Error("Message ID is required.");let s=(Array.isArray(i.callbacks)?i.callbacks:typeof i.callbacks<"u"?i.callbacks.handlers:[]).find(c=>"name"in c&&c.name==="StreamMessagesHandler");if(s){let c=i.metadata??{},l=(c.langgraph_checkpoint_ns??"").split("|");s._emit([l,c],o,void 0,!1)}return a&&i.configurable?.__pregel_send?.([[a,o]]),o}function hZ(e,t){let r=typeof e=="string"?{name:e,retry:void 0,cachePolicy:void 0,timeout:void 0}:e,{name:n,retry:i}=r,a=Bi(r.timeout);if(_S(t)||yS(t))throw new Error("Generators are disallowed as tasks. For streaming responses, use config.write.");let o=r.cachePolicy??("cache"in r?r.cache:void 0),s;return typeof o=="boolean"?s=o?{}:void 0:s=o,(...c)=>dM({func:t,name:n,retry:i,cache:s,timeout:a},...c)}var ej=function(t,r){let{name:n,checkpointer:i,store:a,cache:o}=typeof t=="string"?{name:t,checkpointer:void 0,store:void 0}:t,s=Bi(typeof t=="string"?void 0:t.timeout);if(_S(r)||yS(r))throw new Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");let c="updates",l=uM(n,r);function u(m){return typeof m=="object"&&m!==null&&"__lg_type"in m&&m.__lg_type==="__pregel_final"}let d=new Rt({name:"pluckReturnValue",func:m=>u(m)?m.value:m}),f=new Rt({name:"pluckSaveValue",func:m=>u(m)?m.save:m}),p=new $n({bound:l,triggers:[Je],channels:[Je],timeout:s,writers:[new ut([{channel:Qe,value:Ir,mapper:d},{channel:Wi,value:Ir,mapper:f}],[ht])]});return new Dh({name:n,checkpointer:i,nodes:{[n]:p},channels:{[Je]:new In,[Qe]:new Sn,[Wi]:new Sn},inputChannels:Je,outputChannels:Qe,streamChannels:Qe,streamMode:c,store:a,cache:o})};ej.final=function({value:t,save:r}){return{value:t,save:r,__lg_type:"__pregel_final"}};function gZ(){return Re.getRunnableConfig().configurable?.[Zi]}var _Z=Pu.Root({messages:Pu({reducer:za,default:()=>[]})}),tj={reducer:{fn:za},jsonSchemaExtra:{langgraph_type:"messages"},default:()=>[]},yZ=Nt.object({messages:qM(Nt.custom(),tj)});function vZ(e){let t=Re.getRunnableConfig();if(!t)throw new Error("Called interrupt() outside the context of a graph.");let r=t.configurable;if(!r)throw new Error("No configurable found in config");return r.writer?.(e)}export{Je as a,Qe as b,Le as c,Fh as d,qS as e,Fa as f,wt as g,ij as h,Ha as i,_r as j,Ct as k,Zr as l,Ju as m,Vh as n,Ga as o,Ku as p,qu as q,li as r,Xu as s,Yu as t,oj as u,Qu as v,Zh as w,Ji as x,ui as y,ed as z,sj as A,td as B,je as C,ve as D,cj as E,Hh as F,lj as G,Lc as H,uj as I,Tk as J,ar as K,Dj as L,jn as M,zk as N,Hc as O,Uk as P,tt as Q,St as R,ss as S,Ne as T,us as U,it as V,un as W,qa as X,Ya as Y,Qa as Z,mi as _,P$ as $,Wt as aa,la as ba,fo as ca,ha as da,Vf as ea,xo as fa,Ge as ga,lt as ha,xr as ia,Si as ja,Sp as ka,z as la,Nt as ma,Et as na,qt as oa,RF as pa,Hl as qa,Xp as ra,Xw as sa,gP as ta,_P as ua,UF as va,LF as wa,Qw as xa,Ca as ya,nm as za,Aa,YF as Ba,hx as Ca,uc as Da,pu as Ea,rn as Fa,eV as Ga,pV as Ha,Go as Ia,wn as Ja,ih as Ka,OR as La,Sc as Ma,sh as Na,RR as Oa,yt as Pa,Pi as Qa,Pu as Ra,JV as Sa,KV as Ta,ph as Ua,qV as Va,eS as Wa,tS as Xa,Ic as Ya,rS as Za,an as _a,gh as $a,oS as ab,Nu as bb,Ru as cb,sS as db,cS as eb,_h as fb,dS as gb,GR as hb,fS as ib,gS as jb,Rt as kb,PS as lb,Mi as mb,iZ as nb,ja as ob,ji as pb,zh as qb,Uh as rb,Di as sb,qo as tb,zi as ub,Tn as vb,oZ as wb,za as xb,FS as yb,sZ as zb,cZ as Ab,Fu as Bb,qM as Cb,BS as Db,QM as Eb,pZ as Fb,mZ as Gb,hZ as Hb,ej as Ib,gZ as Jb,_Z as Kb,tj as Lb,yZ as Mb,vZ as Nb};
@@ -1,65 +1,65 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{a as ce}from"./X6N7Y4IA.js";import{a as oe}from"./DFTUMKSN.js";import{a as le}from"./2GBRZSEC.js";import{a as ae}from"./OFDH6CTA.js";import"./BUKOHPY6.js";import"./XQJNAQVO.js";import{M as se,S as ie,h as ne,j as S,w as Q}from"./STZRXY35.js";import"./UZLQALHY.js";function N(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var z=N();function xe(r){z=r}var R={exec:()=>null};function A(r){let e=[];return t=>{let s=Math.max(0,Math.min(3,t-1)),n=e[s];return n||(n=r(s),e[s]=n),n}}function u(r,e=""){let t=typeof r=="string"?r:r.source,s={replace:(n,i)=>{let l=typeof i=="string"?i:i.source;return l=l.replace(x.caret,"$1"),t=t.replace(n,l),s},getRegex:()=>new RegExp(t,e)};return s}var Ie=((r="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+r)}catch{return!1}})(),x={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,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ 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,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:r=>new RegExp(`^( {0,3}${r})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:A(r=>new RegExp(`^ {0,${r}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:A(r=>new RegExp(`^ {0,${r}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:A(r=>new RegExp(`^ {0,${r}}(?:\`\`\`|~~~)`)),headingBeginRegex:A(r=>new RegExp(`^ {0,${r}}#`)),htmlBeginRegex:A(r=>new RegExp(`^ {0,${r}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:A(r=>new RegExp(`^ {0,${r}}>`))},Le=/^(?:[ \t]*(?:\n|$))+/,Pe=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ve=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,v=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ce=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,G=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,be=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,me=u(be).replace(/bull/g,G).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(),Ee=u(be).replace(/bull/g,G).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(),X=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Be=/^[^\n]+/,W=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,qe=u(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",W).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ze=u(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,G).getRegex(),Z="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",F=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,De=u("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n+|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n+|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\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",F).replace("tag",Z).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),we=r=>u(X).replace("hr",v).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",r).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Z).getRegex(),Me=we(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),Qe=we(/ {0,3}(?:[*+-]|\d{1,9}[.)])[ \t]+[^ \t\n]/),He=u(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Qe).getRegex(),U={blockquote:He,code:Pe,def:qe,fences:ve,heading:Ce,hr:v,html:De,lheading:me,list:Ze,newline:Le,paragraph:Me,table:R,text:Be},he=u("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",v).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[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Z).getRegex(),je={...U,lheading:Ee,table:he,paragraph:u(X).replace("hr",v).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",he).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Z).getRegex()},Oe={...U,html:u(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",F).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:R,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:u(X).replace("hr",v).replace("heading",` *#{1,6} *[^
3
- ]`).replace("lheading",me).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Ne=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Ge=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ye=/^( {2,}|\\)\n(?!\s*$)/,Xe=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,_=/[\p{P}\p{S}]/u,D=/[\s\p{P}\p{S}]/u,J=/[^\s\p{P}\p{S}]/u,We=u(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,D).getRegex(),$e=/(?!~)[\p{P}\p{S}]/u,Fe=/(?!~)[\s\p{P}\p{S}]/u,Ue=/(?:[^\s\p{P}\p{S}]|~)/u,Je=u(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Ie?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Se=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Ke=u(Se,"u").replace(/punct/g,_).getRegex(),Ve=u(Se,"u").replace(/punct/g,$e).getRegex(),Re="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Ye=u(Re,"gu").replace(/notPunctSpace/g,J).replace(/punctSpace/g,D).replace(/punct/g,_).getRegex(),et=u(Re,"gu").replace(/notPunctSpace/g,Ue).replace(/punctSpace/g,Fe).replace(/punct/g,$e).getRegex(),tt=u("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,J).replace(/punctSpace/g,D).replace(/punct/g,_).getRegex(),rt=u(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,_).getRegex(),nt="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",st=u(nt,"gu").replace(/notPunctSpace/g,J).replace(/punctSpace/g,D).replace(/punct/g,_).getRegex(),it=u(/\\(punct)/,"gu").replace(/punct/g,_).getRegex(),lt=u(/^<(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(),at=u(F).replace("(?:-->|$)","-->").getRegex(),ot=u("^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",at).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),E=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,ct=u(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",E).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Te=u(/^!?\[(label)\]\[(ref)\]/).replace("label",E).replace("ref",W).getRegex(),ze=u(/^!?\[(ref)\](?:\[\])?/).replace("ref",W).getRegex(),ht=u("reflink|nolink(?!\\()","g").replace("reflink",Te).replace("nolink",ze).getRegex(),pe=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,K={_backpedal:R,anyPunctuation:it,autolink:lt,blockSkip:Je,br:ye,code:Ge,del:R,delLDelim:R,delRDelim:R,emStrongLDelim:Ke,emStrongRDelimAst:Ye,emStrongRDelimUnd:tt,escape:Ne,link:ct,nolink:ze,punctuation:We,reflink:Te,reflinkSearch:ht,tag:ot,text:Xe,url:R},pt={...K,link:u(/^!?\[(label)\]\((.*?)\)/).replace("label",E).getRegex(),reflink:u(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",E).getRegex()},H={...K,emStrongRDelimAst:et,emStrongLDelim:Ve,delLDelim:rt,delRDelim:st,url:u(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",pe).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\S]|[^\s~\\]))\1(?=[^~]|$)/,text:u(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",pe).getRegex()},ut={...H,br:u(ye).replace("{2,}","*").getRegex(),text:u(H.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},C={normal:U,gfm:je,pedantic:Oe},L={normal:K,gfm:H,breaks:ut,pedantic:pt},gt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ue=r=>gt[r];function w(r,e){if(e){if(x.escapeTest.test(r))return r.replace(x.escapeReplace,ue)}else if(x.escapeTestNoEncode.test(r))return r.replace(x.escapeReplaceNoEncode,ue);return r}function ge(r){try{r=encodeURI(r).replace(x.percentDecode,"%")}catch{return null}return r}function ke(r,e){let t=r.replace(x.findPipe,(i,l,a)=>{let c=!1,o=l;for(;--o>=0&&a[o]==="\\";)c=!c;return c?"|":" |"}),s=t.split(x.splitPipe),n=0;if(s[0].trim()||s.shift(),s.length>0&&!s.at(-1)?.trim()&&s.pop(),e)if(s.length>e)s.splice(e);else for(;s.length<e;)s.push("");for(;n<s.length;n++)s[n]=s[n].trim().replace(x.slashPipe,"|");return s}function $(r,e,t){let s=r.length;if(s===0)return"";let n=0;for(;n<s;){let i=r.charAt(s-n-1);if(i===e&&!t)n++;else if(i!==e&&t)n++;else break}return r.slice(0,s-n)}function de(r){let e=r.split(`
4
- `),t=e.length-1;for(;t>=0&&x.blankLine.test(e[t]);)t--;return e.length-t<=2?r:e.slice(0,t+1).join(`
5
- `)}function kt(r,e){if(r.indexOf(e[1])===-1)return-1;let t=0;for(let s=0;s<r.length;s++)if(r[s]==="\\")s++;else if(r[s]===e[0])t++;else if(r[s]===e[1]&&(t--,t<0))return s;return t>0?-2:-1}function dt(r,e=0){let t=e,s="";for(let n of r)if(n===" "){let i=4-t%4;s+=" ".repeat(i),t+=i}else s+=n,t++;return s}function fe(r,e,t,s,n){let i=e.href,l=e.title||null,a=r[1].replace(n.other.outputLinkReplace,"$1");s.state.inLink=!0;let c={type:r[0].charAt(0)==="!"?"image":"link",raw:t,href:i,title:l,text:a,tokens:s.inlineTokens(a)};return s.state.inLink=!1,c}function ft(r,e,t){let s=r.match(t.other.indentCodeCompensation);if(s===null)return e;let n=s[1];return e.split(`
6
- `).map(i=>{let l=i.match(t.other.beginningSpace);if(l===null)return i;let[a]=l;return a.length>=n.length?i.slice(n.length):i}).join(`
2
+ import{a as ce}from"./X6N7Y4IA.js";import{a as oe}from"./DFTUMKSN.js";import{a as le}from"./2GBRZSEC.js";import{a as ae}from"./OFDH6CTA.js";import"./BUKOHPY6.js";import"./XQJNAQVO.js";import{M as se,S as ie,h as ne,j as R,w as Q}from"./STZRXY35.js";import"./UZLQALHY.js";function N(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var z=N();function xe(r){z=r}var S={exec:()=>null};function A(r){let e=[];return t=>{let s=Math.max(0,Math.min(3,t-1)),n=e[s];return n||(n=r(s),e[s]=n),n}}function u(r,e=""){let t=typeof r=="string"?r:r.source,s={replace:(n,i)=>{let a=typeof i=="string"?i:i.source;return a=a.replace(f.caret,"$1"),t=t.replace(n,a),s},getRegex:()=>new RegExp(t,e)};return s}var Le=((r="")=>{try{return!!new RegExp("(?<=1)(?<!1)"+r)}catch{return!1}})(),f={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,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ 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,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:r=>new RegExp(`^( {0,3}${r})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:A(r=>new RegExp(`^ {0,${r}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:A(r=>new RegExp(`^ {0,${r}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:A(r=>new RegExp(`^ {0,${r}}(?:\`\`\`|~~~)`)),headingBeginRegex:A(r=>new RegExp(`^ {0,${r}}#`)),htmlBeginRegex:A(r=>new RegExp(`^ {0,${r}}<(?:[a-z].*>|!--)`,"i")),blockquoteBeginRegex:A(r=>new RegExp(`^ {0,${r}}>`))},Ie=/^(?:[ \t]*(?:\n|$))+/,Pe=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ve=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,v=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Ce=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,G=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,be=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,me=u(be).replace(/bull/g,G).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}(?:\s|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Ee=u(be).replace(/bull/g,G).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}(?:\s|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),X=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,Be=/^[^\n]+/,W=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,qe=u(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",W).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ze=u(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,G).getRegex(),Z="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",F=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,De=u("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\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",F).replace("tag",Z).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),we=r=>u(X).replace("hr",v).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list",r).replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Z).getRegex(),Me=we(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),Qe=we(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),He=u(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Qe).getRegex(),U={blockquote:He,code:Pe,def:qe,fences:ve,heading:Ce,hr:v,html:De,lheading:me,list:Ze,newline:Ie,paragraph:Me,table:S,text:Be},he=u("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",v).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Z).getRegex(),je={...U,lheading:Ee,table:he,paragraph:u(X).replace("hr",v).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",he).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~~~)[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Z).getRegex()},Oe={...U,html:u(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",F).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:S,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:u(X).replace("hr",v).replace("heading",` *#{1,6} *[^
3
+ ]`).replace("lheading",me).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Ne=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Ge=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ye=/^( {2,}|\\)\n(?!\s*$)/,Xe=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,_=/[\p{P}\p{S}]/u,D=/[\s\p{P}\p{S}]/u,J=/[^\s\p{P}\p{S}]/u,We=u(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,D).getRegex(),$e=/(?!~)[\p{P}\p{S}]/u,Fe=/(?!~)[\s\p{P}\p{S}]/u,Ue=/(?:[^\s\p{P}\p{S}]|~)/u,Je=u(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",Le?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),Re=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,Ke=u(Re,"u").replace(/punct/g,_).getRegex(),Ve=u(Re,"u").replace(/punct/g,$e).getRegex(),Se="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Ye=u(Se,"gu").replace(/notPunctSpace/g,J).replace(/punctSpace/g,D).replace(/punct/g,_).getRegex(),et=u(Se,"gu").replace(/notPunctSpace/g,Ue).replace(/punctSpace/g,Fe).replace(/punct/g,$e).getRegex(),tt=u("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,J).replace(/punctSpace/g,D).replace(/punct/g,_).getRegex(),rt=u(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,_).getRegex(),nt="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",st=u(nt,"gu").replace(/notPunctSpace/g,J).replace(/punctSpace/g,D).replace(/punct/g,_).getRegex(),it=u(/\\(punct)/,"gu").replace(/punct/g,_).getRegex(),lt=u(/^<(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(),at=u(F).replace("(?:-->|$)","-->").getRegex(),ot=u("^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",at).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),E=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,ct=u(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",E).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Te=u(/^!?\[(label)\]\[(ref)\]/).replace("label",E).replace("ref",W).getRegex(),ze=u(/^!?\[(ref)\](?:\[\])?/).replace("ref",W).getRegex(),ht=u("reflink|nolink(?!\\()","g").replace("reflink",Te).replace("nolink",ze).getRegex(),pe=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,K={_backpedal:S,anyPunctuation:it,autolink:lt,blockSkip:Je,br:ye,code:Ge,del:S,delLDelim:S,delRDelim:S,emStrongLDelim:Ke,emStrongRDelimAst:Ye,emStrongRDelimUnd:tt,escape:Ne,link:ct,nolink:ze,punctuation:We,reflink:Te,reflinkSearch:ht,tag:ot,text:Xe,url:S},pt={...K,link:u(/^!?\[(label)\]\((.*?)\)/).replace("label",E).getRegex(),reflink:u(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",E).getRegex()},H={...K,emStrongRDelimAst:et,emStrongLDelim:Ve,delLDelim:rt,delRDelim:st,url:u(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",pe).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\S]|[^\s~\\]))\1(?=[^~]|$)/,text:u(/^(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",pe).getRegex()},ut={...H,br:u(ye).replace("{2,}","*").getRegex(),text:u(H.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},C={normal:U,gfm:je,pedantic:Oe},I={normal:K,gfm:H,breaks:ut,pedantic:pt},gt={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},ue=r=>gt[r];function w(r,e){if(e){if(f.escapeTest.test(r))return r.replace(f.escapeReplace,ue)}else if(f.escapeTestNoEncode.test(r))return r.replace(f.escapeReplaceNoEncode,ue);return r}function ge(r){try{r=encodeURI(r).replace(f.percentDecode,"%")}catch{return null}return r}function ke(r,e){let t=r.replace(f.findPipe,(i,a,l)=>{let o=!1,c=a;for(;--c>=0&&l[c]==="\\";)o=!o;return o?"|":" |"}),s=t.split(f.splitPipe),n=0;if(s[0].trim()||s.shift(),s.length>0&&!s.at(-1)?.trim()&&s.pop(),e)if(s.length>e)s.splice(e);else for(;s.length<e;)s.push("");for(;n<s.length;n++)s[n]=s[n].trim().replace(f.slashPipe,"|");return s}function $(r,e,t){let s=r.length;if(s===0)return"";let n=0;for(;n<s;){let i=r.charAt(s-n-1);if(i===e&&!t)n++;else if(i!==e&&t)n++;else break}return r.slice(0,s-n)}function de(r){let e=r.split(`
4
+ `),t=e.length-1;for(;t>=0&&f.blankLine.test(e[t]);)t--;return e.length-t<=2?r:e.slice(0,t+1).join(`
5
+ `)}function kt(r,e){if(r.indexOf(e[1])===-1)return-1;let t=0;for(let s=0;s<r.length;s++)if(r[s]==="\\")s++;else if(r[s]===e[0])t++;else if(r[s]===e[1]&&(t--,t<0))return s;return t>0?-2:-1}function dt(r,e=0){let t=e,s="";for(let n of r)if(n===" "){let i=4-t%4;s+=" ".repeat(i),t+=i}else s+=n,t++;return s}function fe(r,e,t,s,n){let i=e.href,a=e.title||null,l=r[1].replace(n.other.outputLinkReplace,"$1");s.state.inLink=!0;let o={type:r[0].charAt(0)==="!"?"image":"link",raw:t,href:i,title:a,text:l,tokens:s.inlineTokens(l)};return s.state.inLink=!1,o}function ft(r,e,t){let s=r.match(t.other.indentCodeCompensation);if(s===null)return e;let n=s[1];return e.split(`
6
+ `).map(i=>{let a=i.match(t.other.beginningSpace);if(a===null)return i;let[l]=a;return l.length>=n.length?i.slice(n.length):i}).join(`
7
7
  `)}var B=class{options;rules;lexer;constructor(r){this.options=r||z}space(r){let e=this.rules.block.newline.exec(r);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(r){let e=this.rules.block.code.exec(r);if(e){let t=this.options.pedantic?e[0]:de(e[0]),s=t.replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t,codeBlockStyle:"indented",text:s}}}fences(r){let e=this.rules.block.fences.exec(r);if(e){let t=e[0],s=ft(t,e[3]||"",this.rules);return{type:"code",raw:t,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:s}}}heading(r){let e=this.rules.block.heading.exec(r);if(e){let t=e[2].trim();if(this.rules.other.endingHash.test(t)){let s=$(t,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(t=s.trim())}return{type:"heading",raw:$(e[0],`
8
8
  `),depth:e[1].length,text:t,tokens:this.lexer.inline(t)}}}hr(r){let e=this.rules.block.hr.exec(r);if(e)return{type:"hr",raw:$(e[0],`
9
9
  `)}}blockquote(r){let e=this.rules.block.blockquote.exec(r);if(e){let t=$(e[0],`
10
10
  `).split(`
11
- `),s="",n="",i=[];for(;t.length>0;){let l=!1,a=[],c;for(c=0;c<t.length;c++)if(this.rules.other.blockquoteStart.test(t[c]))a.push(t[c]),l=!0;else if(!l)a.push(t[c]);else break;t=t.slice(c);let o=a.join(`
12
- `),p=o.replace(this.rules.other.blockquoteSetextReplace,`
11
+ `),s="",n="",i=[];for(;t.length>0;){let a=!1,l=[],o;for(o=0;o<t.length;o++)if(this.rules.other.blockquoteStart.test(t[o]))l.push(t[o]),a=!0;else if(!a)l.push(t[o]);else break;t=t.slice(o);let c=l.join(`
12
+ `),p=c.replace(this.rules.other.blockquoteSetextReplace,`
13
13
  $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
14
- ${o}`:o,n=n?`${n}
15
- ${p}`:p;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,i,!0),this.lexer.state.top=h,t.length===0)break;let g=i.at(-1);if(g?.type==="code")break;if(g?.type==="blockquote"){let f=g,d=f.raw+`
14
+ ${c}`:c,n=n?`${n}
15
+ ${p}`:p;let h=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(p,i,!0),this.lexer.state.top=h,t.length===0)break;let g=i.at(-1);if(g?.type==="code")break;if(g?.type==="blockquote"){let x=g,d=x.raw+`
16
16
  `+t.join(`
17
- `),y=this.blockquote(d);i[i.length-1]=y,s=s.substring(0,s.length-f.raw.length)+y.raw,n=n.substring(0,n.length-f.text.length)+y.text;break}else if(g?.type==="list"){let f=g,d=f.raw+`
17
+ `),y=this.blockquote(d);i[i.length-1]=y,s=s.substring(0,s.length-x.raw.length)+y.raw,n=n.substring(0,n.length-x.text.length)+y.text;break}else if(g?.type==="list"){let x=g,d=x.raw+`
18
18
  `+t.join(`
19
- `),y=this.list(d);i[i.length-1]=y,s=s.substring(0,s.length-g.raw.length)+y.raw,n=n.substring(0,n.length-f.raw.length)+y.raw,t=d.substring(i.at(-1).raw.length).split(`
20
- `);continue}}return{type:"blockquote",raw:s,tokens:i,text:n}}}list(r){let e=this.rules.block.list.exec(r);if(e){let t=e[1].trim(),s=t.length>1,n={type:"list",raw:"",ordered:s,start:s?+t.slice(0,-1):"",loose:!1,items:[]};t=s?`\\d{1,9}\\${t.slice(-1)}`:`\\${t}`,this.options.pedantic&&(t=s?t:"[*+-]");let i=this.rules.other.listItemRegex(t),l=!1;for(;r;){let c=!1,o="",p="";if(!(e=i.exec(r))||this.rules.block.hr.test(r))break;o=e[0],r=r.substring(o.length);let h=dt(e[2].split(`
19
+ `),y=this.list(d);i[i.length-1]=y,s=s.substring(0,s.length-g.raw.length)+y.raw,n=n.substring(0,n.length-x.raw.length)+y.raw,t=d.substring(i.at(-1).raw.length).split(`
20
+ `);continue}}return{type:"blockquote",raw:s,tokens:i,text:n}}}list(r){let e=this.rules.block.list.exec(r);if(e){let t=e[1].trim(),s=t.length>1,n={type:"list",raw:"",ordered:s,start:s?+t.slice(0,-1):"",loose:!1,items:[]};t=s?`\\d{1,9}\\${t.slice(-1)}`:`\\${t}`,this.options.pedantic&&(t=s?t:"[*+-]");let i=this.rules.other.listItemRegex(t),a=!1;for(;r;){let o=!1,c="",p="";if(!(e=i.exec(r))||this.rules.block.hr.test(r))break;c=e[0],r=r.substring(c.length);let h=dt(e[2].split(`
21
21
  `,1)[0],e[1].length),g=r.split(`
22
- `,1)[0],f=!h.trim(),d=0;if(this.options.pedantic?(d=2,p=h.trimStart()):f?d=e[1].length+1:(d=h.search(this.rules.other.nonSpaceChar),d=d>4?1:d,p=h.slice(d),d+=e[1].length),f&&this.rules.other.blankLine.test(g)&&(o+=g+`
23
- `,r=r.substring(g.length+1),c=!0),!c){let y=this.rules.other.nextBulletRegex(d),ee=this.rules.other.hrRegex(d),te=this.rules.other.fencesBeginRegex(d),re=this.rules.other.headingBeginRegex(d),Ae=this.rules.other.htmlBeginRegex(d),_e=this.rules.other.blockquoteBeginRegex(d);for(;r;){let M=r.split(`
24
- `,1)[0],I;if(g=M,this.options.pedantic?(g=g.replace(this.rules.other.listReplaceNesting," "),I=g):I=g.replace(this.rules.other.tabCharGlobal," "),te.test(g)||re.test(g)||Ae.test(g)||_e.test(g)||y.test(g)||ee.test(g))break;if(I.search(this.rules.other.nonSpaceChar)>=d||!g.trim())p+=`
25
- `+I.slice(d);else{if(f||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||te.test(h)||re.test(h)||ee.test(h))break;p+=`
26
- `+g}f=!g.trim(),o+=M+`
27
- `,r=r.substring(M.length+1),h=I.slice(d)}}n.loose||(l?n.loose=!0:this.rules.other.doubleBlankLine.test(o)&&(l=!0)),n.items.push({type:"list_item",raw:o,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,tokens:[]}),n.raw+=o}let a=n.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;n.raw=n.raw.trimEnd();for(let c of n.items){this.lexer.state.top=!1,c.tokens=this.lexer.blockTokens(c.text,[]);let o=c.tokens[0];if(c.task&&(o?.type==="text"||o?.type==="paragraph")){c.text=c.text.replace(this.rules.other.listReplaceTask,""),o.raw=o.raw.replace(this.rules.other.listReplaceTask,""),o.text=o.text.replace(this.rules.other.listReplaceTask,"");for(let h=this.lexer.inlineQueue.length-1;h>=0;h--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)){this.lexer.inlineQueue[h].src=this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask,"");break}let p=this.rules.other.listTaskCheckbox.exec(c.raw);if(p){let h={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};c.checked=h.checked,n.loose?c.tokens[0]&&["paragraph","text"].includes(c.tokens[0].type)&&"tokens"in c.tokens[0]&&c.tokens[0].tokens?(c.tokens[0].raw=h.raw+c.tokens[0].raw,c.tokens[0].text=h.raw+c.tokens[0].text,c.tokens[0].tokens.unshift(h)):c.tokens.unshift({type:"paragraph",raw:h.raw,text:h.raw,tokens:[h]}):c.tokens.unshift(h)}}else c.task&&(c.task=!1);if(!n.loose){let p=c.tokens.filter(g=>g.type==="space"),h=p.length>0&&p.some(g=>this.rules.other.anyLine.test(g.raw));n.loose=h}}if(n.loose)for(let c of n.items){c.loose=!0;for(let o of c.tokens)o.type==="text"&&(o.type="paragraph")}return n}}html(r){let e=this.rules.block.html.exec(r);if(e){let t=de(e[0]);return{type:"html",block:!0,raw:t,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:t}}}def(r){let e=this.rules.block.def.exec(r);if(e){let t=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",n=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:t,raw:$(e[0],`
22
+ `,1)[0],x=!h.trim(),d=0;if(this.options.pedantic?(d=2,p=h.trimStart()):x?d=e[1].length+1:(d=h.search(this.rules.other.nonSpaceChar),d=d>4?1:d,p=h.slice(d),d+=e[1].length),x&&this.rules.other.blankLine.test(g)&&(c+=g+`
23
+ `,r=r.substring(g.length+1),o=!0),!o){let y=this.rules.other.nextBulletRegex(d),ee=this.rules.other.hrRegex(d),te=this.rules.other.fencesBeginRegex(d),re=this.rules.other.headingBeginRegex(d),Ae=this.rules.other.htmlBeginRegex(d),_e=this.rules.other.blockquoteBeginRegex(d);for(;r;){let M=r.split(`
24
+ `,1)[0],L;if(g=M,this.options.pedantic?(g=g.replace(this.rules.other.listReplaceNesting," "),L=g):L=g.replace(this.rules.other.tabCharGlobal," "),te.test(g)||re.test(g)||Ae.test(g)||_e.test(g)||y.test(g)||ee.test(g))break;if(L.search(this.rules.other.nonSpaceChar)>=d||!g.trim())p+=`
25
+ `+L.slice(d);else{if(x||h.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||te.test(h)||re.test(h)||ee.test(h))break;p+=`
26
+ `+g}x=!g.trim(),c+=M+`
27
+ `,r=r.substring(M.length+1),h=L.slice(d)}}n.loose||(a?n.loose=!0:this.rules.other.doubleBlankLine.test(c)&&(a=!0)),n.items.push({type:"list_item",raw:c,task:!!this.options.gfm&&this.rules.other.listIsTask.test(p),loose:!1,text:p,tokens:[]}),n.raw+=c}let l=n.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;n.raw=n.raw.trimEnd();for(let o of n.items){this.lexer.state.top=!1,o.tokens=this.lexer.blockTokens(o.text,[]);let c=o.tokens[0];if(o.task&&(c?.type==="text"||c?.type==="paragraph")){o.text=o.text.replace(this.rules.other.listReplaceTask,""),c.raw=c.raw.replace(this.rules.other.listReplaceTask,""),c.text=c.text.replace(this.rules.other.listReplaceTask,"");for(let h=this.lexer.inlineQueue.length-1;h>=0;h--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[h].src)){this.lexer.inlineQueue[h].src=this.lexer.inlineQueue[h].src.replace(this.rules.other.listReplaceTask,"");break}let p=this.rules.other.listTaskCheckbox.exec(o.raw);if(p){let h={type:"checkbox",raw:p[0]+" ",checked:p[0]!=="[ ]"};o.checked=h.checked,n.loose?o.tokens[0]&&["paragraph","text"].includes(o.tokens[0].type)&&"tokens"in o.tokens[0]&&o.tokens[0].tokens?(o.tokens[0].raw=h.raw+o.tokens[0].raw,o.tokens[0].text=h.raw+o.tokens[0].text,o.tokens[0].tokens.unshift(h)):o.tokens.unshift({type:"paragraph",raw:h.raw,text:h.raw,tokens:[h]}):o.tokens.unshift(h)}}else o.task&&(o.task=!1);if(!n.loose){let p=o.tokens.filter(g=>g.type==="space"),h=p.length>0&&p.some(g=>this.rules.other.anyLine.test(g.raw));n.loose=h}}if(n.loose)for(let o of n.items){o.loose=!0;for(let c of o.tokens)c.type==="text"&&(c.type="paragraph")}return n}}html(r){let e=this.rules.block.html.exec(r);if(e){let t=de(e[0]);return{type:"html",block:!0,raw:t,pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:t}}}def(r){let e=this.rules.block.def.exec(r);if(e){let t=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),s=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",n=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:t,raw:$(e[0],`
28
28
  `),href:s,title:n}}}table(r){let e=this.rules.block.table.exec(r);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;let t=ke(e[1]),s=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),n=e[3]?.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
29
29
  `):[],i={type:"table",raw:$(e[0],`
30
- `),header:[],align:[],rows:[]};if(t.length===s.length){for(let l of s)this.rules.other.tableAlignRight.test(l)?i.align.push("right"):this.rules.other.tableAlignCenter.test(l)?i.align.push("center"):this.rules.other.tableAlignLeft.test(l)?i.align.push("left"):i.align.push(null);for(let l=0;l<t.length;l++)i.header.push({text:t[l],tokens:this.lexer.inline(t[l]),header:!0,align:i.align[l]});for(let l of n)i.rows.push(ke(l,i.header.length).map((a,c)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:i.align[c]})));return i}}lheading(r){let e=this.rules.block.lheading.exec(r);if(e){let t=e[1].trim();return{type:"heading",raw:$(e[0],`
30
+ `),header:[],align:[],rows:[]};if(t.length===s.length){for(let a of s)this.rules.other.tableAlignRight.test(a)?i.align.push("right"):this.rules.other.tableAlignCenter.test(a)?i.align.push("center"):this.rules.other.tableAlignLeft.test(a)?i.align.push("left"):i.align.push(null);for(let a=0;a<t.length;a++)i.header.push({text:t[a],tokens:this.lexer.inline(t[a]),header:!0,align:i.align[a]});for(let a of n)i.rows.push(ke(a,i.header.length).map((l,o)=>({text:l,tokens:this.lexer.inline(l),header:!1,align:i.align[o]})));return i}}lheading(r){let e=this.rules.block.lheading.exec(r);if(e){let t=e[1].trim();return{type:"heading",raw:$(e[0],`
31
31
  `),depth:e[2].charAt(0)==="="?1:2,text:t,tokens:this.lexer.inline(t)}}}paragraph(r){let e=this.rules.block.paragraph.exec(r);if(e){let t=e[1].charAt(e[1].length-1)===`
32
- `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(r){let e=this.rules.block.text.exec(r);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(r){let e=this.rules.inline.escape.exec(r);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(r){let e=this.rules.inline.tag.exec(r);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(r){let e=this.rules.inline.link.exec(r);if(e){let t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;let i=$(t.slice(0,-1),"\\");if((t.length-i.length)%2===0)return}else{let i=kt(e[2],"()");if(i===-2)return;if(i>-1){let l=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,l).trim(),e[3]=""}}let s=e[2],n="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(s);i&&(s=i[1],n=i[3])}else n=e[3]?e[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?s=s.slice(1):s=s.slice(1,-1)),fe(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:n&&n.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(r,e){let t;if((t=this.rules.inline.reflink.exec(r))||(t=this.rules.inline.nolink.exec(r))){let s=(t[2]||t[1]).replace(this.rules.other.multipleSpaceGlobal," "),n=e[s.toLowerCase()];if(!n){let i=t[0].charAt(0);return{type:"text",raw:i,text:i}}return fe(t,n,t[0],this.lexer,this.rules)}}emStrong(r,e,t=""){let s=this.rules.inline.emStrongLDelim.exec(r);if(!(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&t.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[3])||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,l,a=n,c=0,o=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(o.lastIndex=0,e=e.slice(-1*r.length+n);(s=o.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i)continue;if(l=[...i].length,s[3]||s[4]){a+=l;continue}else if((s[5]||s[6])&&n%3&&!((n+l)%3)){c+=l;continue}if(a-=l,a>0)continue;l=Math.min(l,l+a+c);let p=[...s[0]][0].length,h=r.slice(0,n+s.index+p+l);if(Math.min(n,l)%2){let f=h.slice(1,-1);return{type:"em",raw:h,text:f,tokens:this.lexer.inlineTokens(f)}}let g=h.slice(2,-2);return{type:"strong",raw:h,text:g,tokens:this.lexer.inlineTokens(g)}}}}codespan(r){let e=this.rules.inline.code.exec(r);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return s&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(r){let e=this.rules.inline.br.exec(r);if(e)return{type:"br",raw:e[0]}}del(r,e,t=""){let s=this.rules.inline.delLDelim.exec(r);if(s&&(!s[1]||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,l,a=n,c=this.rules.inline.delRDelim;for(c.lastIndex=0,e=e.slice(-1*r.length+n);(s=c.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i||(l=[...i].length,l!==n))continue;if(s[3]||s[4]){a+=l;continue}if(a-=l,a>0)continue;l=Math.min(l,l+a);let o=[...s[0]][0].length,p=r.slice(0,n+s.index+o+l),h=p.slice(n,-n);return{type:"del",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(r){let e=this.rules.inline.autolink.exec(r);if(e){let t,s;return e[2]==="@"?(t=e[1],s="mailto:"+t):(t=e[1],s=t),{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}url(r){let e;if(e=this.rules.inline.url.exec(r)){let t,s;if(e[2]==="@")t=e[0],s="mailto:"+t;else{let n;do n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(n!==e[0]);t=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(r){let e=this.rules.inline.text.exec(r);if(e){let t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},b=class j{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||z,this.options.tokenizer=this.options.tokenizer||new B,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:x,block:C.normal,inline:L.normal};this.options.pedantic?(t.block=C.pedantic,t.inline=L.pedantic):this.options.gfm&&(t.block=C.gfm,this.options.breaks?t.inline=L.breaks:t.inline=L.gfm),this.tokenizer.rules=t}static get rules(){return{block:C,inline:L}}static lex(e,t){return new j(t).lex(e)}static lexInline(e,t){return new j(t).inlineTokens(e)}lex(e){e=e.replace(x.carriageReturn,`
33
- `),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let s=this.inlineQueue[t];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],s=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(x.tabCharGlobal," ").replace(x.spaceLine,""));let n=1/0;for(;e;){if(e.length<n)n=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(a=>(i=a.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let a=t.at(-1);i.raw.length===1&&a!==void 0?a.raw+=`
34
- `:t.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let a=t.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
32
+ `?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:t,tokens:this.lexer.inline(t)}}}text(r){let e=this.rules.block.text.exec(r);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(r){let e=this.rules.inline.escape.exec(r);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(r){let e=this.rules.inline.tag.exec(r);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(r){let e=this.rules.inline.link.exec(r);if(e){let t=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(t)){if(!this.rules.other.endAngleBracket.test(t))return;let i=$(t.slice(0,-1),"\\");if((t.length-i.length)%2===0)return}else{let i=kt(e[2],"()");if(i===-2)return;if(i>-1){let a=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,a).trim(),e[3]=""}}let s=e[2],n="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(s);i&&(s=i[1],n=i[3])}else n=e[3]?e[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(t)?s=s.slice(1):s=s.slice(1,-1)),fe(e,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:n&&n.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(r,e){let t;if((t=this.rules.inline.reflink.exec(r))||(t=this.rules.inline.nolink.exec(r))){let s=(t[2]||t[1]).replace(this.rules.other.multipleSpaceGlobal," "),n=e[s.toLowerCase()];if(!n){let i=t[0].charAt(0);return{type:"text",raw:i,text:i}}return fe(t,n,t[0],this.lexer,this.rules)}}emStrong(r,e,t=""){let s=this.rules.inline.emStrongLDelim.exec(r);if(!(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&t.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[3])||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,a,l=n,o=0,c=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,e=e.slice(-1*r.length+n);(s=c.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i)continue;if(a=[...i].length,s[3]||s[4]){l+=a;continue}else if((s[5]||s[6])&&n%3&&!((n+a)%3)){o+=a;continue}if(l-=a,l>0)continue;a=Math.min(a,a+l+o);let p=[...s[0]][0].length,h=r.slice(0,n+s.index+p+a);if(Math.min(n,a)%2){let x=h.slice(1,-1);return{type:"em",raw:h,text:x,tokens:this.lexer.inlineTokens(x)}}let g=h.slice(2,-2);return{type:"strong",raw:h,text:g,tokens:this.lexer.inlineTokens(g)}}}}codespan(r){let e=this.rules.inline.code.exec(r);if(e){let t=e[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(t),n=this.rules.other.startingSpaceChar.test(t)&&this.rules.other.endingSpaceChar.test(t);return s&&n&&(t=t.substring(1,t.length-1)),{type:"codespan",raw:e[0],text:t}}}br(r){let e=this.rules.inline.br.exec(r);if(e)return{type:"br",raw:e[0]}}del(r,e,t=""){let s=this.rules.inline.delLDelim.exec(r);if(s&&(!s[1]||!t||this.rules.inline.punctuation.exec(t))){let n=[...s[0]].length-1,i,a,l=n,o=this.rules.inline.delRDelim;for(o.lastIndex=0,e=e.slice(-1*r.length+n);(s=o.exec(e))!==null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i||(a=[...i].length,a!==n))continue;if(s[3]||s[4]){l+=a;continue}if(l-=a,l>0)continue;a=Math.min(a,a+l);let c=[...s[0]][0].length,p=r.slice(0,n+s.index+c+a),h=p.slice(n,-n);return{type:"del",raw:p,text:h,tokens:this.lexer.inlineTokens(h)}}}}autolink(r){let e=this.rules.inline.autolink.exec(r);if(e){let t,s;return e[2]==="@"?(t=e[1],s="mailto:"+t):(t=e[1],s=t),{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}url(r){let e;if(e=this.rules.inline.url.exec(r)){let t,s;if(e[2]==="@")t=e[0],s="mailto:"+t;else{let n;do n=e[0],e[0]=this.rules.inline._backpedal.exec(e[0])?.[0]??"";while(n!==e[0]);t=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:t,href:s,tokens:[{type:"text",raw:t,text:t}]}}}inlineText(r){let e=this.rules.inline.text.exec(r);if(e){let t=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:t}}}},b=class j{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||z,this.options.tokenizer=this.options.tokenizer||new B,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:f,block:C.normal,inline:I.normal};this.options.pedantic?(t.block=C.pedantic,t.inline=I.pedantic):this.options.gfm&&(t.block=C.gfm,this.options.breaks?t.inline=I.breaks:t.inline=I.gfm),this.tokenizer.rules=t}static get rules(){return{block:C,inline:I}}static lex(e,t){return new j(t).lex(e)}static lexInline(e,t){return new j(t).inlineTokens(e)}lex(e){e=e.replace(f.carriageReturn,`
33
+ `),this.blockTokens(e,this.tokens);for(let t=0;t<this.inlineQueue.length;t++){let s=this.inlineQueue[t];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],s=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(f.tabCharGlobal," ").replace(f.spaceLine,""));let n=1/0;for(;e;){if(e.length<n)n=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(l=>(i=l.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let l=t.at(-1);i.raw.length===1&&l!==void 0?l.raw+=`
34
+ `:t.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let l=t.at(-1);l?.type==="paragraph"||l?.type==="text"?(l.raw+=(l.raw.endsWith(`
35
35
  `)?"":`
36
- `)+i.raw,a.text+=`
37
- `+i.text,this.inlineQueue.at(-1).src=a.text):t.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let a=t.at(-1);a?.type==="paragraph"||a?.type==="text"?(a.raw+=(a.raw.endsWith(`
36
+ `)+i.raw,l.text+=`
37
+ `+i.text,this.inlineQueue.at(-1).src=l.text):t.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let l=t.at(-1);l?.type==="paragraph"||l?.type==="text"?(l.raw+=(l.raw.endsWith(`
38
38
  `)?"":`
39
- `)+i.raw,a.text+=`
40
- `+i.raw,this.inlineQueue.at(-1).src=a.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},t.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),t.push(i);continue}let l=e;if(this.options.extensions?.startBlock){let a=1/0,c=e.slice(1),o;this.options.extensions.startBlock.forEach(p=>{o=p.call({lexer:this},c),typeof o=="number"&&o>=0&&(a=Math.min(a,o))}),a<1/0&&a>=0&&(l=e.substring(0,a+1))}if(this.state.top&&(i=this.tokenizer.paragraph(l))){let a=t.at(-1);s&&a?.type==="paragraph"?(a.raw+=(a.raw.endsWith(`
39
+ `)+i.raw,l.text+=`
40
+ `+i.raw,this.inlineQueue.at(-1).src=l.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},t.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),t.push(i);continue}let a=e;if(this.options.extensions?.startBlock){let l=1/0,o=e.slice(1),c;this.options.extensions.startBlock.forEach(p=>{c=p.call({lexer:this},o),typeof c=="number"&&c>=0&&(l=Math.min(l,c))}),l<1/0&&l>=0&&(a=e.substring(0,l+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let l=t.at(-1);s&&l?.type==="paragraph"?(l.raw+=(l.raw.endsWith(`
41
41
  `)?"":`
42
- `)+i.raw,a.text+=`
43
- `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(i),s=l.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let a=t.at(-1);a?.type==="text"?(a.raw+=(a.raw.endsWith(`
42
+ `)+i.raw,l.text+=`
43
+ `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):t.push(i),s=a.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let l=t.at(-1);l?.type==="text"?(l.raw+=(l.raw.endsWith(`
44
44
  `)?"":`
45
- `)+i.raw,a.text+=`
46
- `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=a.text):t.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let s=e,n=null;if(this.tokens.links){let o=Object.keys(this.tokens.links);if(o.length>0)for(;(n=this.tokenizer.rules.inline.reflinkSearch.exec(s))!==null;)o.includes(n[0].slice(n[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,n.index)+"["+"a".repeat(n[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(n=this.tokenizer.rules.inline.anyPunctuation.exec(s))!==null;)s=s.slice(0,n.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(n=this.tokenizer.rules.inline.blockSkip.exec(s))!==null;)i=n[2]?n[2].length:0,s=s.slice(0,n.index+i)+"["+"a".repeat(n[0].length-i-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;let l=!1,a="",c=1/0;for(;e;){if(e.length<c)c=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}l||(a=""),l=!1;let o;if(this.options.extensions?.inline?.some(h=>(o=h.call({lexer:this},e,t))?(e=e.substring(o.raw.length),t.push(o),!0):!1))continue;if(o=this.tokenizer.escape(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.tag(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.link(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(o.raw.length);let h=t.at(-1);o.type==="text"&&h?.type==="text"?(h.raw+=o.raw,h.text+=o.text):t.push(o);continue}if(o=this.tokenizer.emStrong(e,s,a)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.codespan(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.br(e)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.del(e,s,a)){e=e.substring(o.raw.length),t.push(o);continue}if(o=this.tokenizer.autolink(e)){e=e.substring(o.raw.length),t.push(o);continue}if(!this.state.inLink&&(o=this.tokenizer.url(e))){e=e.substring(o.raw.length),t.push(o);continue}let p=e;if(this.options.extensions?.startInline){let h=1/0,g=e.slice(1),f;this.options.extensions.startInline.forEach(d=>{f=d.call({lexer:this},g),typeof f=="number"&&f>=0&&(h=Math.min(h,f))}),h<1/0&&h>=0&&(p=e.substring(0,h+1))}if(o=this.tokenizer.inlineText(p)){e=e.substring(o.raw.length),o.raw.slice(-1)!=="_"&&(a=o.raw.slice(-1)),l=!0;let h=t.at(-1);h?.type==="text"?(h.raw+=o.raw,h.text+=o.text):t.push(o);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t="Infinite loop on byte: "+e;if(this.options.silent)console.error(t);else throw new Error(t)}},q=class{options;parser;constructor(r){this.options=r||z}space(r){return""}code({text:r,lang:e,escaped:t}){let s=(e||"").match(x.notSpaceStart)?.[0],n=r.replace(x.endingNewline,"")+`
45
+ `)+i.raw,l.text+=`
46
+ `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):t.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let s=e;if(this.tokens.links){let l=Object.keys(this.tokens.links);l.length>0&&(s=s.replace(this.tokenizer.rules.inline.reflinkSearch,o=>l.includes(o.slice(o.lastIndexOf("[")+1,-1))?"["+"a".repeat(o.length-2)+"]":o))}s=s.replace(this.tokenizer.rules.inline.anyPunctuation,"++"),s=s.replace(this.tokenizer.rules.inline.blockSkip,(l,o,c)=>{let p=c?c.length:0;return l.slice(0,p)+"["+"a".repeat(l.length-p-2)+"]"}),s=this.options.hooks?.emStrongMask?.call({lexer:this},s)??s;let n=!1,i="",a=1/0;for(;e;){if(e.length<a)a=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}n||(i=""),n=!1;let l;if(this.options.extensions?.inline?.some(c=>(l=c.call({lexer:this},e,t))?(e=e.substring(l.raw.length),t.push(l),!0):!1))continue;if(l=this.tokenizer.escape(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.tag(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.link(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(l.raw.length);let c=t.at(-1);l.type==="text"&&c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):t.push(l);continue}if(l=this.tokenizer.emStrong(e,s,i)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.codespan(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.br(e)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.del(e,s,i)){e=e.substring(l.raw.length),t.push(l);continue}if(l=this.tokenizer.autolink(e)){e=e.substring(l.raw.length),t.push(l);continue}if(!this.state.inLink&&(l=this.tokenizer.url(e))){e=e.substring(l.raw.length),t.push(l);continue}let o=e;if(this.options.extensions?.startInline){let c=1/0,p=e.slice(1),h;this.options.extensions.startInline.forEach(g=>{h=g.call({lexer:this},p),typeof h=="number"&&h>=0&&(c=Math.min(c,h))}),c<1/0&&c>=0&&(o=e.substring(0,c+1))}if(l=this.tokenizer.inlineText(o)){e=e.substring(l.raw.length),l.raw.slice(-1)!=="_"&&(i=l.raw.slice(-1)),n=!0;let c=t.at(-1);c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):t.push(l);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t="Infinite loop on byte: "+e;if(this.options.silent)console.error(t);else throw new Error(t)}},q=class{options;parser;constructor(r){this.options=r||z}space(r){return""}code({text:r,lang:e,escaped:t}){let s=(e||"").match(f.notSpaceStart)?.[0],n=r.replace(f.endingNewline,"")+`
47
47
  `;return s?'<pre><code class="language-'+w(s)+'">'+(t?n:w(n,!0))+`</code></pre>
48
48
  `:"<pre><code>"+(t?n:w(n,!0))+`</code></pre>
49
49
  `}blockquote({tokens:r}){return`<blockquote>
50
50
  ${this.parser.parse(r)}</blockquote>
51
51
  `}html({text:r}){return r}def(r){return""}heading({tokens:r,depth:e}){return`<h${e}>${this.parser.parseInline(r)}</h${e}>
52
52
  `}hr(r){return`<hr>
53
- `}list(r){let e=r.ordered,t=r.start,s="";for(let l=0;l<r.items.length;l++){let a=r.items[l];s+=this.listitem(a)}let n=e?"ol":"ul",i=e&&t!==1?' start="'+t+'"':"";return"<"+n+i+`>
53
+ `}list(r){let e=r.ordered,t=r.start,s="";for(let a=0;a<r.items.length;a++){let l=r.items[a];s+=this.listitem(l)}let n=e?"ol":"ul",i=e&&t!==1?' start="'+t+'"':"";return"<"+n+i+`>
54
54
  `+s+"</"+n+`>
55
55
  `}listitem(r){return`<li>${this.parser.parse(r.tokens)}</li>
56
56
  `}checkbox({checked:r}){return"<input "+(r?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:r}){return`<p>${this.parser.parseInline(r)}</p>
57
- `}table(r){let e="",t="";for(let n=0;n<r.header.length;n++)t+=this.tablecell(r.header[n]);e+=this.tablerow({text:t});let s="";for(let n=0;n<r.rows.length;n++){let i=r.rows[n];t="";for(let l=0;l<i.length;l++)t+=this.tablecell(i[l]);s+=this.tablerow({text:t})}return s&&(s=`<tbody>${s}</tbody>`),`<table>
57
+ `}table(r){let e="",t="";for(let n=0;n<r.header.length;n++)t+=this.tablecell(r.header[n]);e+=this.tablerow({text:t});let s="";for(let n=0;n<r.rows.length;n++){let i=r.rows[n];t="";for(let a=0;a<i.length;a++)t+=this.tablecell(i[a]);s+=this.tablerow({text:t})}return s&&(s=`<tbody>${s}</tbody>`),`<table>
58
58
  <thead>
59
59
  `+e+`</thead>
60
60
  `+s+`</table>
61
61
  `}tablerow({text:r}){return`<tr>
62
62
  ${r}</tr>
63
63
  `}tablecell(r){let e=this.parser.parseInline(r.tokens),t=r.header?"th":"td";return(r.align?`<${t} align="${r.align}">`:`<${t}>`)+e+`</${t}>
64
- `}strong({tokens:r}){return`<strong>${this.parser.parseInline(r)}</strong>`}em({tokens:r}){return`<em>${this.parser.parseInline(r)}</em>`}codespan({text:r}){return`<code>${w(r,!0)}</code>`}br(r){return"<br>"}del({tokens:r}){return`<del>${this.parser.parseInline(r)}</del>`}link({href:r,title:e,tokens:t}){let s=this.parser.parseInline(t),n=ge(r);if(n===null)return s;r=n;let i='<a href="'+r+'"';return e&&(i+=' title="'+w(e)+'"'),i+=">"+s+"</a>",i}image({href:r,title:e,text:t,tokens:s}){s&&(t=this.parser.parseInline(s,this.parser.textRenderer));let n=ge(r);if(n===null)return w(t);r=n;let i=`<img src="${r}" alt="${w(t)}"`;return e&&(i+=` title="${w(e)}"`),i+=">",i}text(r){return"tokens"in r&&r.tokens?this.parser.parseInline(r.tokens):"escaped"in r&&r.escaped?r.text:w(r.text)}},V=class{strong({text:r}){return r}em({text:r}){return r}codespan({text:r}){return r}del({text:r}){return r}html({text:r}){return r}text({text:r}){return r}link({text:r}){return""+r}image({text:r}){return""+r}br(){return""}checkbox({raw:r}){return r}},m=class O{options;renderer;textRenderer;constructor(e){this.options=e||z,this.options.renderer=this.options.renderer||new q,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new V}static parse(e,t){return new O(t).parse(e)}static parseInline(e,t){return new O(t).parseInline(e)}parse(e){this.renderer.parser=this;let t="";for(let s=0;s<e.length;s++){let n=e[s];if(this.options.extensions?.renderers?.[n.type]){let l=n,a=this.options.extensions.renderers[l.type].call({parser:this},l);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(l.type)){t+=a||"";continue}}let i=n;switch(i.type){case"space":{t+=this.renderer.space(i);break}case"hr":{t+=this.renderer.hr(i);break}case"heading":{t+=this.renderer.heading(i);break}case"code":{t+=this.renderer.code(i);break}case"table":{t+=this.renderer.table(i);break}case"blockquote":{t+=this.renderer.blockquote(i);break}case"list":{t+=this.renderer.list(i);break}case"checkbox":{t+=this.renderer.checkbox(i);break}case"html":{t+=this.renderer.html(i);break}case"def":{t+=this.renderer.def(i);break}case"paragraph":{t+=this.renderer.paragraph(i);break}case"text":{t+=this.renderer.text(i);break}default:{let l='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let s="";for(let n=0;n<e.length;n++){let i=e[n];if(this.options.extensions?.renderers?.[i.type]){let a=this.options.extensions.renderers[i.type].call({parser:this},i);if(a!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){s+=a||"";continue}}let l=i;switch(l.type){case"escape":{s+=t.text(l);break}case"html":{s+=t.html(l);break}case"link":{s+=t.link(l);break}case"image":{s+=t.image(l);break}case"checkbox":{s+=t.checkbox(l);break}case"strong":{s+=t.strong(l);break}case"em":{s+=t.em(l);break}case"codespan":{s+=t.codespan(l);break}case"br":{s+=t.br(l);break}case"del":{s+=t.del(l);break}case"text":{s+=t.text(l);break}default:{let a='Token with "'+l.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return s}},P=class{options;block;constructor(r){this.options=r||z}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(r){return r}postprocess(r){return r}processAllTokens(r){return r}emStrongMask(r){return r}provideLexer(r=this.block){return r?b.lex:b.lexInline}provideParser(r=this.block){return r?m.parse:m.parseInline}},xt=class{defaults=N();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=m;Renderer=q;TextRenderer=V;Lexer=b;Tokenizer=B;Hooks=P;constructor(...r){this.use(...r)}walkTokens(r,e){let t=[];for(let s of r)switch(t=t.concat(e.call(this,s)),s.type){case"table":{let n=s;for(let i of n.header)t=t.concat(this.walkTokens(i.tokens,e));for(let i of n.rows)for(let l of i)t=t.concat(this.walkTokens(l.tokens,e));break}case"list":{let n=s;t=t.concat(this.walkTokens(n.items,e));break}default:{let n=s;this.defaults.extensions?.childTokens?.[n.type]?this.defaults.extensions.childTokens[n.type].forEach(i=>{let l=n[i].flat(1/0);t=t.concat(this.walkTokens(l,e))}):n.tokens&&(t=t.concat(this.walkTokens(n.tokens,e)))}}return t}use(...r){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return r.forEach(t=>{let s={...t};if(s.async=this.defaults.async||s.async||!1,t.extensions&&(t.extensions.forEach(n=>{if(!n.name)throw new Error("extension name required");if("renderer"in n){let i=e.renderers[n.name];i?e.renderers[n.name]=function(...l){let a=n.renderer.apply(this,l);return a===!1&&(a=i.apply(this,l)),a}:e.renderers[n.name]=n.renderer}if("tokenizer"in n){if(!n.level||n.level!=="block"&&n.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=e[n.level];i?i.unshift(n.tokenizer):e[n.level]=[n.tokenizer],n.start&&(n.level==="block"?e.startBlock?e.startBlock.push(n.start):e.startBlock=[n.start]:n.level==="inline"&&(e.startInline?e.startInline.push(n.start):e.startInline=[n.start]))}"childTokens"in n&&n.childTokens&&(e.childTokens[n.name]=n.childTokens)}),s.extensions=e),t.renderer){let n=this.defaults.renderer||new q(this.defaults);for(let i in t.renderer){if(!(i in n))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let l=i,a=t.renderer[l],c=n[l];n[l]=(...o)=>{let p=a.apply(n,o);return p===!1&&(p=c.apply(n,o)),p||""}}s.renderer=n}if(t.tokenizer){let n=this.defaults.tokenizer||new B(this.defaults);for(let i in t.tokenizer){if(!(i in n))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let l=i,a=t.tokenizer[l],c=n[l];n[l]=(...o)=>{let p=a.apply(n,o);return p===!1&&(p=c.apply(n,o)),p}}s.tokenizer=n}if(t.hooks){let n=this.defaults.hooks||new P;for(let i in t.hooks){if(!(i in n))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let l=i,a=t.hooks[l],c=n[l];P.passThroughHooks.has(i)?n[l]=o=>{if(this.defaults.async&&P.passThroughHooksRespectAsync.has(i))return(async()=>{let h=await a.call(n,o);return c.call(n,h)})();let p=a.call(n,o);return c.call(n,p)}:n[l]=(...o)=>{if(this.defaults.async)return(async()=>{let h=await a.apply(n,o);return h===!1&&(h=await c.apply(n,o)),h})();let p=a.apply(n,o);return p===!1&&(p=c.apply(n,o)),p}}s.hooks=n}if(t.walkTokens){let n=this.defaults.walkTokens,i=t.walkTokens;s.walkTokens=function(l){let a=[];return a.push(i.call(this,l)),n&&(a=a.concat(n.call(this,l))),a}}this.defaults={...this.defaults,...s}}),this}setOptions(r){return this.defaults={...this.defaults,...r},this}lexer(r,e){return b.lex(r,e??this.defaults)}parser(r,e){return m.parse(r,e??this.defaults)}parseMarkdown(r){return(e,t)=>{let s={...t},n={...this.defaults,...s},i=this.onError(!!n.silent,!!n.async);if(this.defaults.async===!0&&s.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(n.hooks&&(n.hooks.options=n,n.hooks.block=r),n.async)return(async()=>{let l=n.hooks?await n.hooks.preprocess(e):e,a=await(n.hooks?await n.hooks.provideLexer(r):r?b.lex:b.lexInline)(l,n),c=n.hooks?await n.hooks.processAllTokens(a):a;n.walkTokens&&await Promise.all(this.walkTokens(c,n.walkTokens));let o=await(n.hooks?await n.hooks.provideParser(r):r?m.parse:m.parseInline)(c,n);return n.hooks?await n.hooks.postprocess(o):o})().catch(i);try{n.hooks&&(e=n.hooks.preprocess(e));let l=(n.hooks?n.hooks.provideLexer(r):r?b.lex:b.lexInline)(e,n);n.hooks&&(l=n.hooks.processAllTokens(l)),n.walkTokens&&this.walkTokens(l,n.walkTokens);let a=(n.hooks?n.hooks.provideParser(r):r?m.parse:m.parseInline)(l,n);return n.hooks&&(a=n.hooks.postprocess(a)),a}catch(l){return i(l)}}}onError(r,e){return t=>{if(t.message+=`
65
- Please report this to https://github.com/markedjs/marked.`,r){let s="<p>An error occurred:</p><pre>"+w(t.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(t);throw t}}},T=new xt;function k(r,e){return T.parse(r,e)}k.options=k.setOptions=function(r){return T.setOptions(r),k.defaults=T.defaults,xe(k.defaults),k};k.getDefaults=N;k.defaults=z;k.use=function(...r){return T.use(...r),k.defaults=T.defaults,xe(k.defaults),k};k.walkTokens=function(r,e){return T.walkTokens(r,e)};k.parseInline=T.parseInline;k.Parser=m;k.parser=m.parse;k.Renderer=q;k.TextRenderer=V;k.Lexer=b;k.lexer=b.lex;k.Tokenizer=B;k.Hooks=P;k.parse=k;var wt=k.options,yt=k.setOptions,$t=k.use,St=k.walkTokens,Rt=k.parseInline;var Tt=m.parse,zt=b.lex;var bt=ne`.interrupt-container{display:flex;flex-direction:column;gap:.75rem}.interrupt-actions{display:flex;justify-content:flex-end;gap:.5rem}.interrupt-message{white-space:normal}.interrupt-message :where(p){margin:0}.interrupt-message :where(ul,ol){margin:0;padding-inline-start:1.25rem}`;k.use({gfm:!0,breaks:!0,async:!1});var mt=new oe,Y=class extends se{constructor(){super(...arguments),this.#e=[],this._messages=ae({blocking:!0}),this.arcgisCancel=Q(),this.arcgisSubmit=Q()}static{this.properties={type:1,message:1,options:0}}static{this.styles=bt}#e;_renderMessageContent(){let e=this.message??"",t=k.parse(e,{async:!1});return mt.sanitize(t)}_renderInterruptInput(){let{_messages:e,type:t,options:s}=this;switch(t){case"single-select":return S`<calcite-list class="interrupt-list" .label=${e.singleSelectLabel} selection-mode=single-persist @calciteListChange=${n=>this.#e=n.target.selectedItems[0]?.value}>${s?.map(n=>S`<calcite-list-item .label=${n} .value=${n}></calcite-list-item>`)}</calcite-list>`;case"multi-select":return S`<calcite-list class="interrupt-list" .label=${e.multiSelectLabel} selection-mode=multiple @calciteListChange=${n=>this.#e=n.target.selectedItems.map(i=>i.value)}>${s?.map(n=>S`<calcite-list-item .label=${n} .value=${n}></calcite-list-item>`)}</calcite-list>`;case"text-input":return S`<calcite-input class="interrupt-input" .label=${e.textInputLabel} @calciteInputInput=${n=>this.#e=n.target.value}></calcite-input>`;case"boolean-choice":return null;default:return le(t)}}render(){let{_messages:e,type:t}=this,s=t==="boolean-choice";return S`<div class="interrupt-container"><calcite-notice open kind=neutral width=full><div slot=title>${s?e.titleConfirm:e.titleInput}</div><div slot=message class="interrupt-message">${ce(this._renderMessageContent())}</div></calcite-notice>${this._renderInterruptInput()}<div class="interrupt-actions"><calcite-button appearance=outline @click=${()=>this.arcgisCancel.emit()}>${s?e.cancelButton:e.skipButton}</calcite-button><calcite-button appearance=solid @click=${()=>this.arcgisSubmit.emit(t==="boolean-choice"?!0:this.#e)}>${s?e.confirmButton:e.submitButton}</calcite-button></div></div>`}};ie("arcgis-portal-ai-assistant-interrupt",Y);export{Y as ArcgisPortalAiAssistantInterrupt};
64
+ `}strong({tokens:r}){return`<strong>${this.parser.parseInline(r)}</strong>`}em({tokens:r}){return`<em>${this.parser.parseInline(r)}</em>`}codespan({text:r}){return`<code>${w(r,!0)}</code>`}br(r){return"<br>"}del({tokens:r}){return`<del>${this.parser.parseInline(r)}</del>`}link({href:r,title:e,tokens:t}){let s=this.parser.parseInline(t),n=ge(r);if(n===null)return s;r=n;let i='<a href="'+r+'"';return e&&(i+=' title="'+w(e)+'"'),i+=">"+s+"</a>",i}image({href:r,title:e,text:t,tokens:s}){s&&(t=this.parser.parseInline(s,this.parser.textRenderer));let n=ge(r);if(n===null)return w(t);r=n;let i=`<img src="${r}" alt="${w(t)}"`;return e&&(i+=` title="${w(e)}"`),i+=">",i}text(r){return"tokens"in r&&r.tokens?this.parser.parseInline(r.tokens):"escaped"in r&&r.escaped?r.text:w(r.text)}},V=class{strong({text:r}){return r}em({text:r}){return r}codespan({text:r}){return r}del({text:r}){return r}html({text:r}){return r}text({text:r}){return r}link({text:r}){return""+r}image({text:r}){return""+r}br(){return""}checkbox({raw:r}){return r}},m=class O{options;renderer;textRenderer;constructor(e){this.options=e||z,this.options.renderer=this.options.renderer||new q,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new V}static parse(e,t){return new O(t).parse(e)}static parseInline(e,t){return new O(t).parseInline(e)}parse(e){this.renderer.parser=this;let t="";for(let s=0;s<e.length;s++){let n=e[s];if(this.options.extensions?.renderers?.[n.type]){let a=n,l=this.options.extensions.renderers[a.type].call({parser:this},a);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(a.type)){t+=l||"";continue}}let i=n;switch(i.type){case"space":{t+=this.renderer.space(i);break}case"hr":{t+=this.renderer.hr(i);break}case"heading":{t+=this.renderer.heading(i);break}case"code":{t+=this.renderer.code(i);break}case"table":{t+=this.renderer.table(i);break}case"blockquote":{t+=this.renderer.blockquote(i);break}case"list":{t+=this.renderer.list(i);break}case"checkbox":{t+=this.renderer.checkbox(i);break}case"html":{t+=this.renderer.html(i);break}case"def":{t+=this.renderer.def(i);break}case"paragraph":{t+=this.renderer.paragraph(i);break}case"text":{t+=this.renderer.text(i);break}default:{let a='Token with "'+i.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let s="";for(let n=0;n<e.length;n++){let i=e[n];if(this.options.extensions?.renderers?.[i.type]){let l=this.options.extensions.renderers[i.type].call({parser:this},i);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(i.type)){s+=l||"";continue}}let a=i;switch(a.type){case"escape":{s+=t.text(a);break}case"html":{s+=t.html(a);break}case"link":{s+=t.link(a);break}case"image":{s+=t.image(a);break}case"checkbox":{s+=t.checkbox(a);break}case"strong":{s+=t.strong(a);break}case"em":{s+=t.em(a);break}case"codespan":{s+=t.codespan(a);break}case"br":{s+=t.br(a);break}case"del":{s+=t.del(a);break}case"text":{s+=t.text(a);break}default:{let l='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return s}},P=class{options;block;constructor(r){this.options=r||z}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(r){return r}postprocess(r){return r}processAllTokens(r){return r}emStrongMask(r){return r}provideLexer(r=this.block){return r?b.lex:b.lexInline}provideParser(r=this.block){return r?m.parse:m.parseInline}},xt=class{defaults=N();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=m;Renderer=q;TextRenderer=V;Lexer=b;Tokenizer=B;Hooks=P;constructor(...r){this.use(...r)}walkTokens(r,e){let t=[];for(let s of r)switch(t=t.concat(e.call(this,s)),s.type){case"table":{let n=s;for(let i of n.header)t=t.concat(this.walkTokens(i.tokens,e));for(let i of n.rows)for(let a of i)t=t.concat(this.walkTokens(a.tokens,e));break}case"list":{let n=s;t=t.concat(this.walkTokens(n.items,e));break}default:{let n=s;this.defaults.extensions?.childTokens?.[n.type]?this.defaults.extensions.childTokens[n.type].forEach(i=>{let a=n[i].flat(1/0);t=t.concat(this.walkTokens(a,e))}):n.tokens&&(t=t.concat(this.walkTokens(n.tokens,e)))}}return t}use(...r){let e=this.defaults.extensions||{renderers:{},childTokens:{}};return r.forEach(t=>{let s={...t};if(s.async=this.defaults.async||s.async||!1,t.extensions&&(t.extensions.forEach(n=>{if(!n.name)throw new Error("extension name required");if("renderer"in n){let i=e.renderers[n.name];i?e.renderers[n.name]=function(...a){let l=n.renderer.apply(this,a);return l===!1&&(l=i.apply(this,a)),l}:e.renderers[n.name]=n.renderer}if("tokenizer"in n){if(!n.level||n.level!=="block"&&n.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=e[n.level];i?i.unshift(n.tokenizer):e[n.level]=[n.tokenizer],n.start&&(n.level==="block"?e.startBlock?e.startBlock.push(n.start):e.startBlock=[n.start]:n.level==="inline"&&(e.startInline?e.startInline.push(n.start):e.startInline=[n.start]))}"childTokens"in n&&n.childTokens&&(e.childTokens[n.name]=n.childTokens)}),s.extensions=e),t.renderer){let n=this.defaults.renderer||new q(this.defaults);for(let i in t.renderer){if(!(i in n))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let a=i,l=t.renderer[a],o=n[a];n[a]=(...c)=>{let p=l.apply(n,c);return p===!1&&(p=o.apply(n,c)),p||""}}s.renderer=n}if(t.tokenizer){let n=this.defaults.tokenizer||new B(this.defaults);for(let i in t.tokenizer){if(!(i in n))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let a=i,l=t.tokenizer[a],o=n[a];n[a]=(...c)=>{let p=l.apply(n,c);return p===!1&&(p=o.apply(n,c)),p}}s.tokenizer=n}if(t.hooks){let n=this.defaults.hooks||new P;for(let i in t.hooks){if(!(i in n))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let a=i,l=t.hooks[a],o=n[a];P.passThroughHooks.has(i)?n[a]=c=>{if(this.defaults.async&&P.passThroughHooksRespectAsync.has(i))return(async()=>{let h=await l.call(n,c);return o.call(n,h)})();let p=l.call(n,c);return o.call(n,p)}:n[a]=(...c)=>{if(this.defaults.async)return(async()=>{let h=await l.apply(n,c);return h===!1&&(h=await o.apply(n,c)),h})();let p=l.apply(n,c);return p===!1&&(p=o.apply(n,c)),p}}s.hooks=n}if(t.walkTokens){let n=this.defaults.walkTokens,i=t.walkTokens;s.walkTokens=function(a){let l=[];return l.push(i.call(this,a)),n&&(l=l.concat(n.call(this,a))),l}}this.defaults={...this.defaults,...s}}),this}setOptions(r){return this.defaults={...this.defaults,...r},this}lexer(r,e){return b.lex(r,e??this.defaults)}parser(r,e){return m.parse(r,e??this.defaults)}parseMarkdown(r){return(e,t)=>{let s={...t},n={...this.defaults,...s},i=this.onError(!!n.silent,!!n.async);if(this.defaults.async===!0&&s.async===!1)return i(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof e>"u"||e===null)return i(new Error("marked(): input parameter is undefined or null"));if(typeof e!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(e)+", string expected"));if(n.hooks&&(n.hooks.options=n,n.hooks.block=r),n.async)return(async()=>{let a=n.hooks?await n.hooks.preprocess(e):e,l=await(n.hooks?await n.hooks.provideLexer(r):r?b.lex:b.lexInline)(a,n),o=n.hooks?await n.hooks.processAllTokens(l):l;n.walkTokens&&await Promise.all(this.walkTokens(o,n.walkTokens));let c=await(n.hooks?await n.hooks.provideParser(r):r?m.parse:m.parseInline)(o,n);return n.hooks?await n.hooks.postprocess(c):c})().catch(i);try{n.hooks&&(e=n.hooks.preprocess(e));let a=(n.hooks?n.hooks.provideLexer(r):r?b.lex:b.lexInline)(e,n);n.hooks&&(a=n.hooks.processAllTokens(a)),n.walkTokens&&this.walkTokens(a,n.walkTokens);let l=(n.hooks?n.hooks.provideParser(r):r?m.parse:m.parseInline)(a,n);return n.hooks&&(l=n.hooks.postprocess(l)),l}catch(a){return i(a)}}}onError(r,e){return t=>{if(t.message+=`
65
+ Please report this to https://github.com/markedjs/marked.`,r){let s="<p>An error occurred:</p><pre>"+w(t.message+"",!0)+"</pre>";return e?Promise.resolve(s):s}if(e)return Promise.reject(t);throw t}}},T=new xt;function k(r,e){return T.parse(r,e)}k.options=k.setOptions=function(r){return T.setOptions(r),k.defaults=T.defaults,xe(k.defaults),k};k.getDefaults=N;k.defaults=z;k.use=function(...r){return T.use(...r),k.defaults=T.defaults,xe(k.defaults),k};k.walkTokens=function(r,e){return T.walkTokens(r,e)};k.parseInline=T.parseInline;k.Parser=m;k.parser=m.parse;k.Renderer=q;k.TextRenderer=V;k.Lexer=b;k.lexer=b.lex;k.Tokenizer=B;k.Hooks=P;k.parse=k;var wt=k.options,yt=k.setOptions,$t=k.use,Rt=k.walkTokens,St=k.parseInline;var Tt=m.parse,zt=b.lex;var bt=ne`.interrupt-container{display:flex;flex-direction:column;gap:.75rem}.interrupt-actions{display:flex;justify-content:flex-end;gap:.5rem}.interrupt-message{white-space:normal}.interrupt-message :where(p){margin:0}.interrupt-message :where(ul,ol){margin:0;padding-inline-start:1.25rem}`;k.use({gfm:!0,breaks:!0,async:!1});var mt=new oe,Y=class extends se{constructor(){super(...arguments),this.#e=[],this._messages=ae({blocking:!0}),this.arcgisCancel=Q(),this.arcgisSubmit=Q()}static{this.properties={type:1,message:1,options:0}}static{this.styles=bt}#e;_renderMessageContent(){let e=this.message??"",t=k.parse(e,{async:!1});return mt.sanitize(t)}_renderInterruptInput(){let{_messages:e,type:t,options:s}=this;switch(t){case"single-select":return R`<calcite-list class="interrupt-list" .label=${e.singleSelectLabel} selection-mode=single-persist @calciteListChange=${n=>this.#e=n.target.selectedItems[0]?.value}>${s?.map(n=>R`<calcite-list-item .label=${n} .value=${n}></calcite-list-item>`)}</calcite-list>`;case"multi-select":return R`<calcite-list class="interrupt-list" .label=${e.multiSelectLabel} selection-mode=multiple @calciteListChange=${n=>this.#e=n.target.selectedItems.map(i=>i.value)}>${s?.map(n=>R`<calcite-list-item .label=${n} .value=${n}></calcite-list-item>`)}</calcite-list>`;case"text-input":return R`<calcite-input class="interrupt-input" .label=${e.textInputLabel} @calciteInputInput=${n=>this.#e=n.target.value}></calcite-input>`;case"boolean-choice":return null;default:return le(t)}}render(){let{_messages:e,type:t}=this,s=t==="boolean-choice";return R`<div class="interrupt-container"><calcite-notice open kind=neutral width=full><div slot=title>${s?e.titleConfirm:e.titleInput}</div><div slot=message class="interrupt-message">${ce(this._renderMessageContent())}</div></calcite-notice>${this._renderInterruptInput()}<div class="interrupt-actions"><calcite-button appearance=outline @click=${()=>this.arcgisCancel.emit()}>${s?e.cancelButton:e.skipButton}</calcite-button><calcite-button appearance=solid @click=${()=>this.arcgisSubmit.emit(t==="boolean-choice"?!0:this.#e)}>${s?e.confirmButton:e.submitButton}</calcite-button></div></div>`}};ie("arcgis-portal-ai-assistant-interrupt",Y);export{Y as ArcgisPortalAiAssistantInterrupt};