@applica-software-guru/persona-sdk 0.1.83 → 0.1.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +104 -0
  2. package/dist/bundle.cjs.js +18 -30
  3. package/dist/bundle.cjs.js.map +1 -1
  4. package/dist/bundle.es.js +3506 -7033
  5. package/dist/bundle.es.js.map +1 -1
  6. package/dist/bundle.iife.js +18 -30
  7. package/dist/bundle.iife.js.map +1 -1
  8. package/dist/bundle.umd.js +17 -29
  9. package/dist/bundle.umd.js.map +1 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/messages.d.ts +2 -0
  13. package/dist/messages.d.ts.map +1 -1
  14. package/dist/protocol/webrtc.d.ts.map +1 -1
  15. package/dist/protocol/websocket.d.ts.map +1 -1
  16. package/dist/runtime/context.d.ts +34 -0
  17. package/dist/runtime/context.d.ts.map +1 -0
  18. package/dist/runtime/handlers.d.ts +21 -0
  19. package/dist/runtime/handlers.d.ts.map +1 -0
  20. package/dist/runtime/listeners.d.ts +6 -0
  21. package/dist/runtime/listeners.d.ts.map +1 -0
  22. package/dist/runtime/protocols.d.ts +17 -0
  23. package/dist/runtime/protocols.d.ts.map +1 -0
  24. package/dist/runtime/threads.d.ts +35 -0
  25. package/dist/runtime/threads.d.ts.map +1 -0
  26. package/dist/runtime/utils.d.ts +10 -0
  27. package/dist/runtime/utils.d.ts.map +1 -0
  28. package/dist/runtime.d.ts +4 -22
  29. package/dist/runtime.d.ts.map +1 -1
  30. package/dist/storage/base.d.ts +19 -0
  31. package/dist/storage/base.d.ts.map +1 -0
  32. package/dist/storage/index.d.ts +3 -0
  33. package/dist/storage/index.d.ts.map +1 -0
  34. package/dist/storage/persona.d.ts +30 -0
  35. package/dist/storage/persona.d.ts.map +1 -0
  36. package/dist/types.d.ts +51 -1
  37. package/dist/types.d.ts.map +1 -1
  38. package/package.json +16 -10
  39. package/playground/src/chat.tsx +51 -66
  40. package/playground/src/components/assistant-ui/thread-list.tsx +45 -12
  41. package/playground/src/components/assistant-ui/thread.tsx +34 -96
  42. package/playground/src/components/assistant-ui/threadlist-sidebar.tsx +59 -0
  43. package/playground/src/components/chat/logging.tsx +53 -0
  44. package/playground/src/components/ui/input.tsx +21 -0
  45. package/playground/src/components/ui/separator.tsx +26 -0
  46. package/playground/src/components/ui/sheet.tsx +139 -0
  47. package/playground/src/components/ui/sidebar.tsx +619 -0
  48. package/playground/src/components/ui/skeleton.tsx +13 -0
  49. package/playground/src/components/ui/tooltip.tsx +0 -2
  50. package/playground/src/hooks/theme.ts +70 -0
  51. package/playground/src/hooks/use-mobile.ts +19 -0
  52. package/src/index.ts +1 -0
  53. package/src/messages.ts +98 -8
  54. package/src/protocol/webrtc.ts +1 -0
  55. package/src/protocol/websocket.ts +5 -2
  56. package/src/runtime/context.ts +88 -0
  57. package/src/runtime/handlers.ts +276 -0
  58. package/src/runtime/index.ts +6 -0
  59. package/src/runtime/listeners.ts +79 -0
  60. package/src/runtime/protocols.ts +169 -0
  61. package/src/runtime/threads.ts +120 -0
  62. package/src/runtime/utils.ts +46 -0
  63. package/src/runtime.tsx +226 -326
  64. package/src/storage/base.ts +21 -0
  65. package/src/storage/index.ts +2 -0
  66. package/src/storage/persona.ts +132 -0
  67. package/src/types.ts +64 -2
  68. package/vite.config.ts +11 -1
@@ -1,40 +1,28 @@
1
- (function(Y,B){typeof exports=="object"&&typeof module<"u"?B(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],B):(Y=typeof globalThis<"u"?globalThis:Y||self,B(Y.personaSDK={},Y.React))})(this,function(Y,B){"use strict";var Av=Object.defineProperty;var Cv=(Y,B,oe)=>B in Y?Av(Y,B,{enumerable:!0,configurable:!0,writable:!0,value:oe}):Y[B]=oe;var S=(Y,B,oe)=>Cv(Y,typeof B!="symbol"?B+"":B,oe);var Xt,Ue;var oe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function $i(n){return n&&n.__esModule&&Object.prototype.hasOwnProperty.call(n,"default")?n.default:n}var qi={exports:{}},yn={};/**
2
- * @license React
3
- * react-jsx-runtime.production.js
4
- *
5
- * Copyright (c) Meta Platforms, Inc. and affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var zi;function dc(){if(zi)return yn;zi=1;var n=Symbol.for("react.transitional.element"),i=Symbol.for("react.fragment");function r(a,h,f){var p=null;if(f!==void 0&&(p=""+f),h.key!==void 0&&(p=""+h.key),"key"in h){f={};for(var m in h)m!=="key"&&(f[m]=h[m])}else f=h;return h=f.ref,{$$typeof:n,type:a,key:p,ref:h!==void 0?h:null,props:f}}return yn.Fragment=i,yn.jsx=r,yn.jsxs=r,yn}qi.exports=dc();var Ee=qi.exports,pc=n=>Array.from(n).map(r=>r.getModelContext()).sort((r,a)=>(a.priority??0)-(r.priority??0)).reduce((r,a)=>{var h;if(a.system&&(r.system?r.system+=`
10
-
11
- ${a.system}`:r.system=a.system),a.tools)for(const[f,p]of Object.entries(a.tools)){const m=(h=r.tools)==null?void 0:h[f];if(m&&m!==p)throw new Error(`You tried to define a tool with the name ${f}, but it already exists.`);r.tools||(r.tools={}),r.tools[f]=p}return a.config&&(r.config={...r.config,...a.config}),a.callSettings&&(r.callSettings={...r.callSettings,...a.callSettings}),r},{}),Hi=class{constructor(){S(this,"_providers",new Set);S(this,"_subscribers",new Set)}getModelContext(){return pc(this._providers)}registerModelContextProvider(n){var r;this._providers.add(n);const i=(r=n.subscribe)==null?void 0:r.call(n,()=>{this.notifySubscribers()});return this.notifySubscribers(),()=>{this._providers.delete(n),i==null||i(),this.notifySubscribers()}}notifySubscribers(){for(const n of this._subscribers)n()}subscribe(n){return this._subscribers.add(n),()=>this._subscribers.delete(n)}},gc=class{constructor(){S(this,"_contextProvider",new Hi)}registerModelContextProvider(n){return this._contextProvider.registerModelContextProvider(n)}getModelContextProvider(){return this._contextProvider}},_c=class{constructor(){S(this,"_subscribers",new Set)}subscribe(n){return this._subscribers.add(n),()=>this._subscribers.delete(n)}waitForUpdate(){return new Promise(n=>{const i=this.subscribe(()=>{i(),n()})})}_notifySubscribers(){const n=[];for(const i of this._subscribers)try{i()}catch(r){n.push(r)}if(n.length>0)throw n.length===1?n[0]:new AggregateError(n)}},bc=n=>n.status.type==="complete",Ji=class extends _c{constructor(){super(...arguments);S(this,"isEditing",!0);S(this,"_attachments",[]);S(this,"_text","");S(this,"_role","user");S(this,"_runConfig",{});S(this,"_eventSubscribers",new Map)}get attachmentAccept(){var i;return((i=this.getAttachmentAdapter())==null?void 0:i.accept)??"*"}get attachments(){return this._attachments}setAttachments(i){this._attachments=i,this._notifySubscribers()}get isEmpty(){return!this.text.trim()&&!this.attachments.length}get text(){return this._text}get role(){return this._role}get runConfig(){return this._runConfig}setText(i){this._text!==i&&(this._text=i,this._notifySubscribers())}setRole(i){this._role!==i&&(this._role=i,this._notifySubscribers())}setRunConfig(i){this._runConfig!==i&&(this._runConfig=i,this._notifySubscribers())}_emptyTextAndAttachments(){this._attachments=[],this._text="",this._notifySubscribers()}async _onClearAttachments(){const i=this.getAttachmentAdapter();i&&await Promise.all(this._attachments.map(r=>i.remove(r)))}async reset(){if(this._attachments.length===0&&this._text===""&&this._role==="user"&&Object.keys(this._runConfig).length===0)return;this._role="user",this._runConfig={};const i=this._onClearAttachments();this._emptyTextAndAttachments(),await i}async clearAttachments(){const i=this._onClearAttachments();this.setAttachments([]),await i}async send(){const i=this.getAttachmentAdapter(),r=i&&this.attachments.length>0?Promise.all(this.attachments.map(async f=>bc(f)?f:await i.send(f))):[],a=this.text;this._emptyTextAndAttachments();const h={createdAt:new Date,role:this.role,content:a?[{type:"text",text:a}]:[],attachments:await r,runConfig:this.runConfig,metadata:{custom:{}}};this.handleSend(h),this._notifyEventSubscribers("send")}cancel(){this.handleCancel()}async addAttachment(i){const r=this.getAttachmentAdapter();if(!r)throw new Error("Attachments are not supported");const a=f=>{const p=this._attachments.findIndex(m=>m.id===f.id);p!==-1?this._attachments=[...this._attachments.slice(0,p),f,...this._attachments.slice(p+1)]:this._attachments=[...this._attachments,f],this._notifySubscribers()},h=r.add({file:i});if(Symbol.asyncIterator in h)for await(const f of h)a(f);else a(await h);this._notifyEventSubscribers("attachment-add"),this._notifySubscribers()}async removeAttachment(i){const r=this.getAttachmentAdapter();if(!r)throw new Error("Attachments are not supported");const a=this._attachments.findIndex(f=>f.id===i);if(a===-1)throw new Error("Attachment not found");const h=this._attachments[a];await r.remove(h),this._attachments=[...this._attachments.slice(0,a),...this._attachments.slice(a+1)],this._notifySubscribers()}_notifyEventSubscribers(i){const r=this._eventSubscribers.get(i);if(r)for(const a of r)a()}unstable_on(i,r){const a=this._eventSubscribers.get(i);return a?a.add(r):this._eventSubscribers.set(i,new Set([r])),()=>{const h=this._eventSubscribers.get(i);h&&h.delete(r)}}},mc=class extends Ji{constructor(i){super();S(this,"_canCancel",!1);this.runtime=i,this.connect()}get canCancel(){return this._canCancel}get attachments(){return super.attachments}getAttachmentAdapter(){var i;return(i=this.runtime.adapters)==null?void 0:i.attachments}connect(){return this.runtime.subscribe(()=>{this.canCancel!==this.runtime.capabilities.cancel&&(this._canCancel=this.runtime.capabilities.cancel,this._notifySubscribers())})}async handleSend(i){var r;this.runtime.append({...i,parentId:((r=this.runtime.messages.at(-1))==null?void 0:r.id)??null,sourceId:null})}async handleCancel(){this.runtime.cancelRun()}},es=((n,i=21)=>(r=i)=>{let a="",h=r|0;for(;h--;)a+=n[Math.random()*n.length|0];return a})("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",7),vc="__optimistic__",wc=()=>`${vc}${es()}`,Qe=Symbol("autoStatus"),yc=Object.freeze(Object.assign({type:"running"},{[Qe]:!0})),Sc=Object.freeze(Object.assign({type:"complete",reason:"unknown"},{[Qe]:!0}));Object.freeze(Object.assign({type:"requires-action",reason:"tool-calls"},{[Qe]:!0})),Object.freeze(Object.assign({type:"requires-action",reason:"interrupt"},{[Qe]:!0}));var Ec=n=>n[Qe]===!0,Gi=(n,i,r,a,h)=>n&&h?Object.assign({type:"incomplete",reason:"error",error:h},{[Qe]:!0}):n&&i?yc:Sc,je={exports:{}};const xc=typeof Buffer<"u",Ki=/"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/,Yi=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;function Vi(n,i,r){r==null&&i!==null&&typeof i=="object"&&(r=i,i=void 0),xc&&Buffer.isBuffer(n)&&(n=n.toString()),n&&n.charCodeAt(0)===65279&&(n=n.slice(1));const a=JSON.parse(n,i);if(a===null||typeof a!="object")return a;const h=r&&r.protoAction||"error",f=r&&r.constructorAction||"error";if(h==="ignore"&&f==="ignore")return a;if(h!=="ignore"&&f!=="ignore"){if(Ki.test(n)===!1&&Yi.test(n)===!1)return a}else if(h!=="ignore"&&f==="ignore"){if(Ki.test(n)===!1)return a}else if(Yi.test(n)===!1)return a;return Zi(a,{protoAction:h,constructorAction:f,safe:r&&r.safe})}function Zi(n,{protoAction:i="error",constructorAction:r="error",safe:a}={}){let h=[n];for(;h.length;){const f=h;h=[];for(const p of f){if(i!=="ignore"&&Object.prototype.hasOwnProperty.call(p,"__proto__")){if(a===!0)return null;if(i==="error")throw new SyntaxError("Object contains forbidden prototype property");delete p.__proto__}if(r!=="ignore"&&Object.prototype.hasOwnProperty.call(p,"constructor")&&p.constructor!==null&&typeof p.constructor=="object"&&Object.prototype.hasOwnProperty.call(p.constructor,"prototype")){if(a===!0)return null;if(r==="error")throw new SyntaxError("Object contains forbidden prototype property");delete p.constructor}for(const m in p){const w=p[m];w&&typeof w=="object"&&h.push(w)}}}return n}function ns(n,i,r){const{stackTraceLimit:a}=Error;Error.stackTraceLimit=0;try{return Vi(n,i,r)}finally{Error.stackTraceLimit=a}}function Tc(n,i){const{stackTraceLimit:r}=Error;Error.stackTraceLimit=0;try{return Vi(n,i,{safe:!0})}catch{return}finally{Error.stackTraceLimit=r}}je.exports=ns,je.exports.default=ns,je.exports.parse=ns,je.exports.safeParse=Tc,je.exports.scan=Zi;var Ac=je.exports;const Xi=$i(Ac);function Cc(n){const i=["ROOT"];let r=-1,a=null;const h=[];let f;function p(){f!==void 0&&(h.push(JSON.parse('"'+f+'"')),f=void 0)}function m(C,A,R){switch(C){case'"':{r=A,i.pop(),i.push(R),i.push("INSIDE_STRING"),p();break}case"f":case"t":case"n":{r=A,a=A,i.pop(),i.push(R),i.push("INSIDE_LITERAL");break}case"-":{i.pop(),i.push(R),i.push("INSIDE_NUMBER"),p();break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{r=A,i.pop(),i.push(R),i.push("INSIDE_NUMBER"),p();break}case"{":{r=A,i.pop(),i.push(R),i.push("INSIDE_OBJECT_START"),p();break}case"[":{r=A,i.pop(),i.push(R),i.push("INSIDE_ARRAY_START"),p();break}}}function w(C,A){switch(C){case",":{i.pop(),i.push("INSIDE_OBJECT_AFTER_COMMA");break}case"}":{r=A,i.pop(),f=h.pop();break}}}function I(C,A){switch(C){case",":{i.pop(),i.push("INSIDE_ARRAY_AFTER_COMMA"),f=(Number(f)+1).toString();break}case"]":{r=A,i.pop(),f=h.pop();break}}}for(let C=0;C<n.length;C++){const A=n[C];switch(i[i.length-1]){case"ROOT":m(A,C,"FINISH");break;case"INSIDE_OBJECT_START":{switch(A){case'"':{i.pop(),i.push("INSIDE_OBJECT_KEY"),f="";break}case"}":{r=C,i.pop(),f=h.pop();break}}break}case"INSIDE_OBJECT_AFTER_COMMA":{switch(A){case'"':{i.pop(),i.push("INSIDE_OBJECT_KEY"),f="";break}}break}case"INSIDE_OBJECT_KEY":{switch(A){case'"':{i.pop(),i.push("INSIDE_OBJECT_AFTER_KEY");break}case"\\":{i.push("INSIDE_STRING_ESCAPE"),f+=A;break}default:{f+=A;break}}break}case"INSIDE_OBJECT_AFTER_KEY":{switch(A){case":":{i.pop(),i.push("INSIDE_OBJECT_BEFORE_VALUE");break}}break}case"INSIDE_OBJECT_BEFORE_VALUE":{m(A,C,"INSIDE_OBJECT_AFTER_VALUE");break}case"INSIDE_OBJECT_AFTER_VALUE":{w(A,C);break}case"INSIDE_STRING":{switch(A){case'"':{i.pop(),r=C,f=h.pop();break}case"\\":{i.push("INSIDE_STRING_ESCAPE");break}default:r=C}break}case"INSIDE_ARRAY_START":{switch(A){case"]":{r=C,i.pop(),f=h.pop();break}default:{r=C,f="0",m(A,C,"INSIDE_ARRAY_AFTER_VALUE");break}}break}case"INSIDE_ARRAY_AFTER_VALUE":{switch(A){case",":{i.pop(),i.push("INSIDE_ARRAY_AFTER_COMMA"),f=(Number(f)+1).toString();break}case"]":{r=C,i.pop(),f=h.pop();break}default:{r=C;break}}break}case"INSIDE_ARRAY_AFTER_COMMA":{m(A,C,"INSIDE_ARRAY_AFTER_VALUE");break}case"INSIDE_STRING_ESCAPE":{i.pop(),i[i.length-1]==="INSIDE_STRING"?r=C:i[i.length-1]==="INSIDE_OBJECT_KEY"&&(f+=A);break}case"INSIDE_NUMBER":{switch(A){case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":{r=C;break}case"e":case"E":case"-":case".":break;case",":{i.pop(),f=h.pop(),i[i.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&I(A,C),i[i.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&w(A,C);break}case"}":{i.pop(),f=h.pop(),i[i.length-1]==="INSIDE_OBJECT_AFTER_VALUE"&&w(A,C);break}case"]":{i.pop(),f=h.pop(),i[i.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&I(A,C);break}default:{i.pop(),f=h.pop();break}}break}case"INSIDE_LITERAL":{const K=n.substring(a,C+1);!"false".startsWith(K)&&!"true".startsWith(K)&&!"null".startsWith(K)?(i.pop(),i[i.length-1]==="INSIDE_OBJECT_AFTER_VALUE"?w(A,C):i[i.length-1]==="INSIDE_ARRAY_AFTER_VALUE"&&I(A,C)):r=C;break}}}let P=n.slice(0,r+1);for(let C=i.length-1;C>=0;C--)switch(i[C]){case"INSIDE_STRING":{P+='"';break}case"INSIDE_OBJECT_KEY":case"INSIDE_OBJECT_AFTER_KEY":case"INSIDE_OBJECT_AFTER_COMMA":case"INSIDE_OBJECT_START":case"INSIDE_OBJECT_BEFORE_VALUE":case"INSIDE_OBJECT_AFTER_VALUE":{P+="}";break}case"INSIDE_ARRAY_START":case"INSIDE_ARRAY_AFTER_COMMA":case"INSIDE_ARRAY_AFTER_VALUE":{P+="]";break}case"INSIDE_LITERAL":{const R=n.substring(a,n.length);"true".startsWith(R)?P+="true".slice(R.length):"false".startsWith(R)?P+="false".slice(R.length):"null".startsWith(R)&&(P+="null".slice(R.length))}}return[P,h]}var rs=Symbol("aui.parse-partial-json-object.meta"),Ic=n=>{if(n.length===0)return{[rs]:{state:"partial",partialPath:[]}};try{const i=Xi.parse(n);if(typeof i!="object"||i===null)throw new Error("argsText is expected to be an object");return i[rs]={state:"complete",partialPath:[]},i}catch{try{const[i,r]=Cc(n),a=Xi.parse(i);if(typeof a!="object"||a===null)throw new Error("argsText is expected to be an object");return a[rs]={state:"partial",partialPath:r},a}catch{return}}},ss=(n,i,r)=>{const{role:a,id:h,createdAt:f,attachments:p,status:m,metadata:w}=n,I={id:h??i,createdAt:f??new Date},P=typeof n.content=="string"?[{type:"text",text:n.content}]:n.content,C=({image:A,...R})=>A.match(/^data:image\/(png|jpeg|jpg|gif|webp);base64,(.*)$/)?{...R,image:A}:(console.warn("Invalid image data format detected"),null);if(a!=="user"&&(p!=null&&p.length))throw new Error("attachments are only supported for user messages");if(a!=="assistant"&&m)throw new Error("status is only supported for assistant messages");if(a!=="assistant"&&(w!=null&&w.steps))throw new Error("metadata.steps is only supported for assistant messages");switch(a){case"assistant":return{...I,role:a,content:P.map(A=>{const R=A.type;switch(R){case"text":case"reasoning":return A.text.trim().length===0?null:A;case"file":case"source":return A;case"image":return C(A);case"data":return A;case"tool-call":{const{parentId:K,messages:At,...gt}=A,ct={...gt,toolCallId:A.toolCallId??`tool-${es()}`,...K!==void 0&&{parentId:K},...At!==void 0&&{messages:At}};return A.args?{...ct,args:A.args,argsText:A.argsText??JSON.stringify(A.args)}:{...ct,args:Ic(A.argsText??"")??{},argsText:A.argsText??""}}default:{const K=R;throw new Error(`Unsupported assistant message part type: ${K}`)}}}).filter(A=>!!A),status:m??r,metadata:{unstable_state:(w==null?void 0:w.unstable_state)??null,unstable_annotations:(w==null?void 0:w.unstable_annotations)??[],unstable_data:(w==null?void 0:w.unstable_data)??[],custom:(w==null?void 0:w.custom)??{},steps:(w==null?void 0:w.steps)??[],...(w==null?void 0:w.submittedFeedback)&&{submittedFeedback:w.submittedFeedback}}};case"user":return{...I,role:a,content:P.map(A=>{const R=A.type;switch(R){case"text":case"image":case"audio":case"file":return A;default:{const K=R;throw new Error(`Unsupported user message part type: ${K}`)}}}),attachments:p??[],metadata:{custom:(w==null?void 0:w.custom)??{}}};case"system":if(P.length!==1||P[0].type!=="text")throw new Error("System messages must have exactly one text message part.");return{...I,role:a,content:P,metadata:{custom:(w==null?void 0:w.custom)??{}}};default:{const A=a;throw new Error(`Unknown message role: ${A}`)}}},is={fromArray:n=>{const i=n.map(r=>ss(r,es(),Gi(!1,!1,!1,!1,void 0)));return{messages:i.map((r,a)=>({parentId:a>0?i[a-1].id:null,message:r}))}}},Xn=n=>n.next?Xn(n.next):"current"in n?n:null,Rc=class{constructor(n){S(this,"_value",null);this.func=n}get value(){return this._value===null&&(this._value=this.func()),this._value}dirty(){this._value=null}},Qi=class{constructor(){S(this,"messages",new Map);S(this,"head",null);S(this,"root",{children:[],next:null});S(this,"_messages",new Rc(()=>{var i;const n=new Array((((i=this.head)==null?void 0:i.level)??-1)+1);for(let r=this.head;r;r=r.prev)n[r.level]=r.current;return n}))}updateLevels(n,i){n.level=i;for(const r of n.children){const a=this.messages.get(r);a&&this.updateLevels(a,i+1)}}performOp(n,i,r){const a=i.prev??this.root,h=n??this.root;if(!(r==="relink"&&a===h)){if(r!=="link"&&(a.children=a.children.filter(f=>f!==i.current.id),a.next===i)){const f=a.children.at(-1),p=f?this.messages.get(f):null;if(p===void 0)throw new Error("MessageRepository(performOp/cut): Fallback sibling message not found. This is likely an internal bug in assistant-ui.");a.next=p}if(r!=="cut"){for(let p=n;p;p=p.prev)if(p.current.id===i.current.id)throw new Error("MessageRepository(performOp/link): A message with the same id already exists in the parent tree. This error occurs if the same message id is found multiple times. This is likely an internal bug in assistant-ui.");h.children=[...h.children,i.current.id],(Xn(i)===this.head||h.next===null)&&(h.next=i),i.prev=n;const f=n?n.level+1:0;this.updateLevels(i,f)}}}get headId(){var n;return((n=this.head)==null?void 0:n.current.id)??null}getMessages(n){var a;if(n===void 0||n===((a=this.head)==null?void 0:a.current.id))return this._messages.value;const i=this.messages.get(n);if(!i)throw new Error("MessageRepository(getMessages): Head message not found. This is likely an internal bug in assistant-ui.");const r=new Array(i.level+1);for(let h=i;h;h=h.prev)r[h.level]=h.current;return r}addOrUpdateMessage(n,i){const r=this.messages.get(i.id),a=n?this.messages.get(n):null;if(a===void 0)throw new Error("MessageRepository(addOrUpdateMessage): Parent message not found. This is likely an internal bug in assistant-ui.");if(r){r.current=i,this.performOp(a,r,"relink"),this._messages.dirty();return}const h={prev:a,current:i,next:null,children:[],level:a?a.level+1:0};this.messages.set(i.id,h),this.performOp(a,h,"link"),this.head===a&&(this.head=h),this._messages.dirty()}getMessage(n){var r;const i=this.messages.get(n);if(!i)throw new Error("MessageRepository(updateMessage): Message not found. This is likely an internal bug in assistant-ui.");return{parentId:((r=i.prev)==null?void 0:r.current.id)??null,message:i.current,index:i.level}}appendOptimisticMessage(n,i){let r;do r=wc();while(this.messages.has(r));return this.addOrUpdateMessage(n,ss(i,r,{type:"running"})),r}deleteMessage(n,i){const r=this.messages.get(n);if(!r)throw new Error("MessageRepository(deleteMessage): Message not found. This is likely an internal bug in assistant-ui.");const a=i===void 0?r.prev:i===null?null:this.messages.get(i);if(a===void 0)throw new Error("MessageRepository(deleteMessage): Replacement not found. This is likely an internal bug in assistant-ui.");for(const h of r.children){const f=this.messages.get(h);if(!f)throw new Error("MessageRepository(deleteMessage): Child message not found. This is likely an internal bug in assistant-ui.");this.performOp(a,f,"relink")}this.performOp(null,r,"cut"),this.messages.delete(n),this.head===r&&(this.head=Xn(a??this.root)),this._messages.dirty()}getBranches(n){const i=this.messages.get(n);if(!i)throw new Error("MessageRepository(getBranches): Message not found. This is likely an internal bug in assistant-ui.");const{children:r}=i.prev??this.root;return r}switchToBranch(n){const i=this.messages.get(n);if(!i)throw new Error("MessageRepository(switchToBranch): Branch not found. This is likely an internal bug in assistant-ui.");const r=i.prev??this.root;r.next=i,this.head=Xn(i),this._messages.dirty()}resetHead(n){if(n===null){this.clear();return}const i=this.messages.get(n);if(!i)throw new Error("MessageRepository(resetHead): Branch not found. This is likely an internal bug in assistant-ui.");if(i.children.length>0){const r=a=>{for(const h of a.children){const f=this.messages.get(h);f&&(r(f),this.messages.delete(h))}};r(i),i.children=[],i.next=null}this.head=i;for(let r=i;r;r=r.prev)r.prev&&(r.prev.next=r);this._messages.dirty()}clear(){this.messages.clear(),this.head=null,this.root={children:[],next:null},this._messages.dirty()}export(){var i,r;const n=[];for(const[,a]of this.messages)n.push({message:a.current,parentId:((i=a.prev)==null?void 0:i.current.id)??null});return{headId:((r=this.head)==null?void 0:r.current.id)??null,messages:n}}import({headId:n,messages:i}){var r;for(const{message:a,parentId:h}of i)this.addOrUpdateMessage(h,a);this.resetHead(n??((r=i.at(-1))==null?void 0:r.message.id)??null)}},Qn=class{constructor(){S(this,"_subscriptions",new Set);S(this,"_connection")}get isConnected(){return!!this._connection}notifySubscribers(){for(const n of this._subscriptions)n()}_updateConnection(){var n;if(this._subscriptions.size>0){if(this._connection)return;this._connection=this._connect()}else(n=this._connection)==null||n.call(this),this._connection=void 0}subscribe(n){return this._subscriptions.add(n),this._updateConnection(),()=>{this._subscriptions.delete(n),this._updateConnection()}}},Yt=Symbol("skip-update"),os=class extends Qn{constructor(i){super();S(this,"_previousStateDirty",!0);S(this,"_previousState");S(this,"getState",()=>{if(!this.isConnected||this._previousStateDirty){const i=this.binding.getState();i!==Yt&&(this._previousState=i),this._previousStateDirty=!1}if(this._previousState===void 0)throw new Error("Entry not available in the store");return this._previousState});this.binding=i}get path(){return this.binding.path}_connect(){const i=()=>{this._previousStateDirty=!0,this.notifySubscribers()};return this.binding.subscribe(i)}},jn=class{constructor(n,i){this._core=n,this._threadListBinding=i,this.__internal_bindMethods()}get path(){return this._core.path}__internal_bindMethods(){this.switchTo=this.switchTo.bind(this),this.rename=this.rename.bind(this),this.archive=this.archive.bind(this),this.unarchive=this.unarchive.bind(this),this.delete=this.delete.bind(this),this.initialize=this.initialize.bind(this),this.generateTitle=this.generateTitle.bind(this),this.subscribe=this.subscribe.bind(this),this.unstable_on=this.unstable_on.bind(this),this.getState=this.getState.bind(this),this.detach=this.detach.bind(this)}getState(){return this._core.getState()}switchTo(){const n=this._core.getState();return this._threadListBinding.switchToThread(n.id)}rename(n){const i=this._core.getState();return this._threadListBinding.rename(i.id,n)}archive(){const n=this._core.getState();return this._threadListBinding.archive(n.id)}unarchive(){const n=this._core.getState();return this._threadListBinding.unarchive(n.id)}delete(){const n=this._core.getState();return this._threadListBinding.delete(n.id)}initialize(){const n=this._core.getState();return this._threadListBinding.initialize(n.id)}generateTitle(){const n=this._core.getState();return this._threadListBinding.generateTitle(n.id)}unstable_on(n,i){let r=this._core.getState().isMain,a=this._core.getState().id;return this.subscribe(()=>{const h=this._core.getState(),f=h.isMain,p=h.id;r===f&&a===p||(r=f,a=p,!(n==="switched-to"&&!f)&&(n==="switched-away"&&f||i()))})}subscribe(n){return this._core.subscribe(n)}detach(){const n=this._core.getState();this._threadListBinding.detach(n.id)}__internal_getRuntime(){return this}};function Mc(n,i){if(n===void 0&&i===void 0)return!0;if(n===void 0||i===void 0)return!1;for(const r of Object.keys(n)){const a=n[r],h=i[r];if(!Object.is(a,h))return!1}return!0}var Vt=class extends Qn{constructor(i){super();S(this,"_previousState");S(this,"getState",()=>(this.isConnected||this._syncState(),this._previousState));this.binding=i;const r=i.getState();if(r===Yt)throw new Error("Entry not available in the store");this._previousState=r}get path(){return this.binding.path}_syncState(){const i=this.binding.getState();return i===Yt||Mc(i,this._previousState)?!1:(this._previousState=i,!0)}_connect(){const i=()=>{this._syncState()&&this.notifySubscribers()};return this.binding.subscribe(i)}},tn=Symbol("innerMessage"),Pc=n=>n[tn],Sn=n=>n.content.filter(r=>r.type==="text").map(r=>r.text).join(`
12
-
13
- `),ji=class{constructor(n){this._core=n,this.__internal_bindMethods()}get path(){return this._core.path}__internal_bindMethods(){this.getState=this.getState.bind(this),this.remove=this.remove.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this._core.getState()}subscribe(n){return this._core.subscribe(n)}},to=class extends ji{constructor(n,i){super(n),this._composerApi=i}remove(){const n=this._composerApi.getState();if(!n)throw new Error("Composer is not available");return n.removeAttachment(this.getState().id)}},Oc=class extends to{get source(){return"thread-composer"}},Lc=class extends to{get source(){return"edit-composer"}},Bc=class extends ji{get source(){return"message"}constructor(n){super(n)}remove(){throw new Error("Message attachments cannot be removed")}},eo=class extends Qn{constructor(n){super(),this.config=n}getState(){return this.config.binding.getState()}outerSubscribe(n){return this.config.binding.subscribe(n)}_connect(){const n=()=>{this.notifySubscribers()};let i=this.config.binding.getState(),r=i==null?void 0:i.unstable_on(this.config.event,n);const a=()=>{var p;const f=this.config.binding.getState();f!==i&&(i=f,r==null||r(),r=(p=this.config.binding.getState())==null?void 0:p.unstable_on(this.config.event,n))},h=this.outerSubscribe(a);return()=>{h==null||h(),r==null||r()}}},no=Object.freeze([]),ro=Object.freeze({}),kc=n=>Object.freeze({type:"thread",isEditing:(n==null?void 0:n.isEditing)??!1,canCancel:(n==null?void 0:n.canCancel)??!1,isEmpty:(n==null?void 0:n.isEmpty)??!0,attachments:(n==null?void 0:n.attachments)??no,text:(n==null?void 0:n.text)??"",role:(n==null?void 0:n.role)??"user",runConfig:(n==null?void 0:n.runConfig)??ro,attachmentAccept:(n==null?void 0:n.attachmentAccept)??"",value:(n==null?void 0:n.text)??""}),Dc=n=>Object.freeze({type:"edit",isEditing:(n==null?void 0:n.isEditing)??!1,canCancel:(n==null?void 0:n.canCancel)??!1,isEmpty:(n==null?void 0:n.isEmpty)??!0,text:(n==null?void 0:n.text)??"",role:(n==null?void 0:n.role)??"user",attachments:(n==null?void 0:n.attachments)??no,runConfig:(n==null?void 0:n.runConfig)??ro,attachmentAccept:(n==null?void 0:n.attachmentAccept)??"",value:(n==null?void 0:n.text)??""}),so=class{constructor(n){S(this,"_eventSubscriptionSubjects",new Map);this._core=n}get path(){return this._core.path}__internal_bindMethods(){this.setText=this.setText.bind(this),this.setRunConfig=this.setRunConfig.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.addAttachment=this.addAttachment.bind(this),this.reset=this.reset.bind(this),this.clearAttachments=this.clearAttachments.bind(this),this.send=this.send.bind(this),this.cancel=this.cancel.bind(this),this.setRole=this.setRole.bind(this),this.getAttachmentByIndex=this.getAttachmentByIndex.bind(this),this.unstable_on=this.unstable_on.bind(this)}setText(n){const i=this._core.getState();if(!i)throw new Error("Composer is not available");i.setText(n)}setRunConfig(n){const i=this._core.getState();if(!i)throw new Error("Composer is not available");i.setRunConfig(n)}addAttachment(n){const i=this._core.getState();if(!i)throw new Error("Composer is not available");return i.addAttachment(n)}reset(){const n=this._core.getState();if(!n)throw new Error("Composer is not available");return n.reset()}clearAttachments(){const n=this._core.getState();if(!n)throw new Error("Composer is not available");return n.clearAttachments()}send(){const n=this._core.getState();if(!n)throw new Error("Composer is not available");n.send()}cancel(){const n=this._core.getState();if(!n)throw new Error("Composer is not available");n.cancel()}setRole(n){const i=this._core.getState();if(!i)throw new Error("Composer is not available");i.setRole(n)}subscribe(n){return this._core.subscribe(n)}unstable_on(n,i){let r=this._eventSubscriptionSubjects.get(n);return r||(r=new eo({event:n,binding:this._core}),this._eventSubscriptionSubjects.set(n,r)),r.subscribe(i)}},Nc=class extends so{constructor(i){const r=new os({path:i.path,getState:()=>kc(i.getState()),subscribe:a=>i.subscribe(a)});super({path:i.path,getState:()=>i.getState(),subscribe:a=>r.subscribe(a)});S(this,"_getState");this._getState=r.getState.bind(r),this.__internal_bindMethods()}get path(){return this._core.path}get type(){return"thread"}getState(){return this._getState()}getAttachmentByIndex(i){return new Oc(new Vt({path:{...this.path,attachmentSource:"thread-composer",attachmentSelector:{type:"index",index:i},ref:`${this.path.ref}${this.path.ref}.attachments[${i}]`},getState:()=>{const a=this.getState().attachments[i];return a?{...a,source:"thread-composer"}:Yt},subscribe:r=>this._core.subscribe(r)}),this._core)}},Fc=class extends so{constructor(i,r){const a=new os({path:i.path,getState:()=>Dc(i.getState()),subscribe:h=>i.subscribe(h)});super({path:i.path,getState:()=>i.getState(),subscribe:h=>a.subscribe(h)});S(this,"_getState");this._beginEdit=r,this._getState=a.getState.bind(a),this.__internal_bindMethods()}get path(){return this._core.path}get type(){return"edit"}__internal_bindMethods(){super.__internal_bindMethods(),this.beginEdit=this.beginEdit.bind(this)}getState(){return this._getState()}beginEdit(){this._beginEdit()}getAttachmentByIndex(i){return new Lc(new Vt({path:{...this.path,attachmentSource:"edit-composer",attachmentSelector:{type:"index",index:i},ref:`${this.path.ref}${this.path.ref}.attachments[${i}]`},getState:()=>{const a=this.getState().attachments[i];return a?{...a,source:"edit-composer"}:Yt},subscribe:r=>this._core.subscribe(r)}),this._core)}},io=Symbol.for("aui.tool-response"),Uc=class Wi{constructor(i){S(this,"artifact");S(this,"result");S(this,"isError");i.artifact!==void 0&&(this.artifact=i.artifact),this.result=i.result,this.isError=i.isError??!1}get[io](){return!0}static[Symbol.hasInstance](i){return typeof i=="object"&&i!==null&&io in i}static toResponse(i){return i instanceof Wi?i:new Wi({result:i===void 0?"<no result>":i})}},oo=class{constructor(n,i,r){this.contentBinding=n,this.messageApi=i,this.threadApi=r,this.__internal_bindMethods()}get path(){return this.contentBinding.path}__internal_bindMethods(){this.addToolResult=this.addToolResult.bind(this),this.resumeToolCall=this.resumeToolCall.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this)}getState(){return this.contentBinding.getState()}addToolResult(n){const i=this.contentBinding.getState();if(!i)throw new Error("Message part is not available");if(i.type!=="tool-call")throw new Error("Tried to add tool result to non-tool message part");if(!this.messageApi)throw new Error("Message API is not available. This is likely a bug in assistant-ui.");if(!this.threadApi)throw new Error("Thread API is not available");const r=this.messageApi.getState();if(!r)throw new Error("Message is not available");const a=i.toolName,h=i.toolCallId,f=Uc.toResponse(n);this.threadApi.getState().addToolResult({messageId:r.id,toolName:a,toolCallId:h,result:f.result,artifact:f.artifact,isError:f.isError})}resumeToolCall(n){const i=this.contentBinding.getState();if(!i)throw new Error("Message part is not available");if(i.type!=="tool-call")throw new Error("Tried to resume tool call on non-tool message part");if(!this.threadApi)throw new Error("Thread API is not available");const r=i.toolCallId;this.threadApi.getState().resumeToolCall({toolCallId:r,payload:n})}subscribe(n){return this.contentBinding.subscribe(n)}},tr=class extends Qn{constructor(n){super(),this.binding=n}get path(){return this.binding.path}getState(){return this.binding.getState()}outerSubscribe(n){return this.binding.subscribe(n)}_connect(){const n=()=>{this.notifySubscribers()};let i=this.binding.getState(),r=i==null?void 0:i.subscribe(n);const a=()=>{var p;const f=this.binding.getState();f!==i&&(i=f,r==null||r(),r=(p=this.binding.getState())==null?void 0:p.subscribe(n),n())},h=this.outerSubscribe(a);return()=>{h==null||h(),r==null||r()}}},er=Object.freeze({type:"complete"}),Wc=(n,i,r)=>{if(n.role!=="assistant")return er;if(r.type==="tool-call")return r.result?er:n.status;const a=i===Math.max(0,n.content.length-1);return n.status.type==="requires-action"?er:a?n.status:er},ao=(n,i)=>{const r=n.content[i];if(!r)return Yt;const a=Wc(n,i,r);return Object.freeze({...r,[tn]:r[tn],status:a})},$c=class{constructor(n,i){S(this,"composer");S(this,"_getEditComposerRuntimeCore",()=>this._threadBinding.getState().getEditComposer(this._core.getState().id));this._core=n,this._threadBinding=i,this.composer=new Fc(new tr({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.composer`,composerSource:"edit"},getState:this._getEditComposerRuntimeCore,subscribe:r=>this._threadBinding.subscribe(r)}),()=>this._threadBinding.getState().beginEdit(this._core.getState().id)),this.__internal_bindMethods()}get path(){return this._core.path}__internal_bindMethods(){this.reload=this.reload.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.getMessagePartByIndex=this.getMessagePartByIndex.bind(this),this.getMessagePartByToolCallId=this.getMessagePartByToolCallId.bind(this),this.getAttachmentByIndex=this.getAttachmentByIndex.bind(this),this.unstable_getCopyText=this.unstable_getCopyText.bind(this),this.speak=this.speak.bind(this),this.stopSpeaking=this.stopSpeaking.bind(this),this.submitFeedback=this.submitFeedback.bind(this),this.switchToBranch=this.switchToBranch.bind(this)}getState(){return this._core.getState()}reload(n={}){const i=this._getEditComposerRuntimeCore(),r=i??this._threadBinding.getState().composer,a=i??r,{runConfig:h=a.runConfig}=n,f=this._core.getState();if(f.role!=="assistant")throw new Error("Can only reload assistant messages");this._threadBinding.getState().startRun({parentId:f.parentId,sourceId:f.id,runConfig:h})}speak(){const n=this._core.getState();return this._threadBinding.getState().speak(n.id)}stopSpeaking(){var r;const n=this._core.getState();if(((r=this._threadBinding.getState().speech)==null?void 0:r.messageId)===n.id)this._threadBinding.getState().stopSpeaking();else throw new Error("Message is not being spoken")}submitFeedback({type:n}){const i=this._core.getState();this._threadBinding.getState().submitFeedback({messageId:i.id,type:n})}switchToBranch({position:n,branchId:i}){const r=this._core.getState();if(i&&n)throw new Error("May not specify both branchId and position");if(!i&&!n)throw new Error("Must specify either branchId or position");const h=this._threadBinding.getState().getBranches(r.id);let f=i;if(n==="previous"?f=h[r.branchNumber-2]:n==="next"&&(f=h[r.branchNumber]),!f)throw new Error("Branch not found");this._threadBinding.getState().switchToBranch(f)}unstable_getCopyText(){return Sn(this.getState())}subscribe(n){return this._core.subscribe(n)}getMessagePartByIndex(n){if(n<0)throw new Error("Message part index must be >= 0");return new oo(new Vt({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.content[${n}]`,messagePartSelector:{type:"index",index:n}},getState:()=>ao(this.getState(),n),subscribe:i=>this._core.subscribe(i)}),this._core,this._threadBinding)}getMessagePartByToolCallId(n){return new oo(new Vt({path:{...this.path,ref:this.path.ref+`${this.path.ref}.content[toolCallId=${JSON.stringify(n)}]`,messagePartSelector:{type:"toolCallId",toolCallId:n}},getState:()=>{const i=this._core.getState(),r=i.content.findIndex(a=>a.type==="tool-call"&&a.toolCallId===n);return r===-1?Yt:ao(i,r)},subscribe:i=>this._core.subscribe(i)}),this._core,this._threadBinding)}getAttachmentByIndex(n){return new Bc(new Vt({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.attachments[${n}]`,attachmentSource:"message",attachmentSelector:{type:"index",index:n}},getState:()=>{const i=this.getState().attachments,r=i==null?void 0:i[n];return r?{...r,source:"message"}:Yt},subscribe:i=>this._core.subscribe(i)}))}},qc=n=>({parentId:n.parentId??null,sourceId:n.sourceId??null,runConfig:n.runConfig??{},...n.stream?{stream:n.stream}:{}}),zc=n=>({parentId:n.parentId??null,sourceId:n.sourceId??null,runConfig:n.runConfig??{}}),Hc=(n,i)=>{var r,a;return typeof i=="string"?{createdAt:new Date,parentId:((r=n.at(-1))==null?void 0:r.id)??null,sourceId:null,runConfig:{},role:"user",content:[{type:"text",text:i}],attachments:[],metadata:{custom:{}}}:{createdAt:i.createdAt??new Date,parentId:i.parentId??((a=n.at(-1))==null?void 0:a.id)??null,sourceId:i.sourceId??null,role:i.role??"user",content:i.content,attachments:i.attachments??[],metadata:i.metadata??{custom:{}},runConfig:i.runConfig??{},startRun:i.startRun}},Jc=(n,i)=>{const r=n.messages.at(-1);return Object.freeze({threadId:i.id,metadata:i,capabilities:n.capabilities,isDisabled:n.isDisabled,isLoading:n.isLoading,isRunning:(r==null?void 0:r.role)!=="assistant"?!1:r.status.type==="running",messages:n.messages,state:n.state,suggestions:n.suggestions,extras:n.extras,speech:n.speech})},Gc=class{constructor(n,i){S(this,"_threadBinding");S(this,"composer");S(this,"_eventSubscriptionSubjects",new Map);const r=new Vt({path:n.path,getState:()=>Jc(n.getState(),i.getState()),subscribe:a=>{const h=n.subscribe(a),f=i.subscribe(a);return()=>{h(),f()}}});this._threadBinding={path:n.path,getState:()=>n.getState(),getStateState:()=>r.getState(),outerSubscribe:a=>n.outerSubscribe(a),subscribe:a=>n.subscribe(a)},this.composer=new Nc(new tr({path:{...this.path,ref:`${this.path.ref}${this.path.ref}.composer`,composerSource:"thread"},getState:()=>this._threadBinding.getState().composer,subscribe:a=>this._threadBinding.subscribe(a)})),this.__internal_bindMethods()}get path(){return this._threadBinding.path}get __internal_threadBinding(){return this._threadBinding}__internal_bindMethods(){this.append=this.append.bind(this),this.unstable_resumeRun=this.unstable_resumeRun.bind(this),this.unstable_loadExternalState=this.unstable_loadExternalState.bind(this),this.startRun=this.startRun.bind(this),this.cancelRun=this.cancelRun.bind(this),this.stopSpeaking=this.stopSpeaking.bind(this),this.export=this.export.bind(this),this.import=this.import.bind(this),this.reset=this.reset.bind(this),this.getMessageByIndex=this.getMessageByIndex.bind(this),this.getMessageById=this.getMessageById.bind(this),this.subscribe=this.subscribe.bind(this),this.unstable_on=this.unstable_on.bind(this),this.getModelContext=this.getModelContext.bind(this),this.getModelConfig=this.getModelConfig.bind(this),this.getState=this.getState.bind(this)}getState(){return this._threadBinding.getStateState()}append(n){this._threadBinding.getState().append(Hc(this._threadBinding.getState().messages,n))}subscribe(n){return this._threadBinding.subscribe(n)}getModelContext(){return this._threadBinding.getState().getModelContext()}getModelConfig(){return this.getModelContext()}startRun(n){const i=n===null||typeof n=="string"?{parentId:n}:n;return this._threadBinding.getState().startRun(zc(i))}unstable_resumeRun(n){return this._threadBinding.getState().resumeRun(qc(n))}unstable_loadExternalState(n){this._threadBinding.getState().unstable_loadExternalState(n)}cancelRun(){this._threadBinding.getState().cancelRun()}stopSpeaking(){return this._threadBinding.getState().stopSpeaking()}export(){return this._threadBinding.getState().export()}import(n){this._threadBinding.getState().import(n)}reset(n){this._threadBinding.getState().reset(n)}getMessageByIndex(n){if(n<0)throw new Error("Message index must be >= 0");return this._getMessageRuntime({...this.path,ref:`${this.path.ref}${this.path.ref}.messages[${n}]`,messageSelector:{type:"index",index:n}},()=>{var a;const i=this._threadBinding.getState().messages,r=i[n];if(r)return{message:r,parentId:((a=i[n-1])==null?void 0:a.id)??null,index:n}})}getMessageById(n){return this._getMessageRuntime({...this.path,ref:this.path.ref+`${this.path.ref}.messages[messageId=${JSON.stringify(n)}]`,messageSelector:{type:"messageId",messageId:n}},()=>this._threadBinding.getState().getMessageById(n))}_getMessageRuntime(n,i){return new $c(new Vt({path:n,getState:()=>{var P;const{message:r,parentId:a,index:h}=i()??{},{messages:f,speech:p}=this._threadBinding.getState();if(!r||a===void 0||h===void 0)return Yt;const w=this._threadBinding.getState().getBranches(r.id),I=r.metadata.submittedFeedback;return{...r,[tn]:r[tn],index:h,isLast:((P=f.at(-1))==null?void 0:P.id)===r.id,parentId:a,branchNumber:w.indexOf(r.id)+1,branchCount:w.length,speech:(p==null?void 0:p.messageId)===r.id?p:void 0,submittedFeedback:I}},subscribe:r=>this._threadBinding.subscribe(r)}),this._threadBinding)}unstable_on(n,i){let r=this._eventSubscriptionSubjects.get(n);return r||(r=new eo({event:n,binding:this._threadBinding}),this._eventSubscriptionSubjects.set(n,r)),r.subscribe(i)}},Kc=n=>({mainThreadId:n.mainThreadId,newThread:n.newThreadId,threads:n.threadIds,archivedThreads:n.archivedThreadIds,isLoading:n.isLoading,threadItems:n.threadData}),nr=(n,i)=>{if(i===void 0)return Yt;const r=n.getItemById(i);return r?{id:r.id,threadId:r.id,remoteId:r.remoteId,externalId:r.externalId,title:r.title,status:r.status,isMain:r.id===n.mainThreadId}:Yt},Yc=class{constructor(n,i=Gc){S(this,"_getState");S(this,"_mainThreadListItemRuntime");S(this,"main");this._core=n,this._runtimeFactory=i;const r=new os({path:{},getState:()=>Kc(n),subscribe:a=>n.subscribe(a)});this._getState=r.getState.bind(r),this._mainThreadListItemRuntime=new jn(new Vt({path:{ref:"threadItems[main]",threadSelector:{type:"main"}},getState:()=>nr(this._core,this._core.mainThreadId),subscribe:a=>this._core.subscribe(a)}),this._core),this.main=new i(new tr({path:{ref:"threads.main",threadSelector:{type:"main"}},getState:()=>n.getMainThreadRuntimeCore(),subscribe:a=>n.subscribe(a)}),this._mainThreadListItemRuntime),this.__internal_bindMethods()}__internal_bindMethods(){this.switchToThread=this.switchToThread.bind(this),this.switchToNewThread=this.switchToNewThread.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.getById=this.getById.bind(this),this.getItemById=this.getItemById.bind(this),this.getItemByIndex=this.getItemByIndex.bind(this),this.getArchivedItemByIndex=this.getArchivedItemByIndex.bind(this)}switchToThread(n){return this._core.switchToThread(n)}switchToNewThread(){return this._core.switchToNewThread()}getState(){return this._getState()}subscribe(n){return this._core.subscribe(n)}get mainItem(){return this._mainThreadListItemRuntime}getById(n){return new this._runtimeFactory(new tr({path:{ref:`threads[threadId=${JSON.stringify(n)}]`,threadSelector:{type:"threadId",threadId:n}},getState:()=>this._core.getThreadRuntimeCore(n),subscribe:i=>this._core.subscribe(i)}),this.mainItem)}getItemByIndex(n){return new jn(new Vt({path:{ref:`threadItems[${n}]`,threadSelector:{type:"index",index:n}},getState:()=>nr(this._core,this._core.threadIds[n]),subscribe:i=>this._core.subscribe(i)}),this._core)}getArchivedItemByIndex(n){return new jn(new Vt({path:{ref:`archivedThreadItems[${n}]`,threadSelector:{type:"archiveIndex",index:n}},getState:()=>nr(this._core,this._core.archivedThreadIds[n]),subscribe:i=>this._core.subscribe(i)}),this._core)}getItemById(n){return new jn(new Vt({path:{ref:`threadItems[threadId=${n}]`,threadSelector:{type:"threadId",threadId:n}},getState:()=>nr(this._core,n),subscribe:i=>this._core.subscribe(i)}),this._core)}},Vc=class{constructor(){S(this,"accept","image/*")}async add(n){return{id:n.file.name,type:"image",name:n.file.name,contentType:n.file.type,file:n.file,status:{type:"requires-action",reason:"composer-send"}}}async send(n){return{...n,status:{type:"complete"},content:[{type:"image",image:await Zc(n.file)}]}}async remove(){}},Zc=n=>new Promise((i,r)=>{const a=new FileReader;a.onload=()=>i(a.result),a.onerror=h=>r(h),a.readAsDataURL(n)});function as(n,i){if(i==="*")return!0;const r=i.split(",").map(f=>f.trim().toLowerCase()),a=`.${n.name.split(".").pop().toLowerCase()}`,h=n.type.toLowerCase();for(const f of r){if(f.startsWith(".")&&f===a||f.includes("/")&&f===h)return!0;if((f==="image/*"||f==="video/*"||f==="audio/*")&&f.endsWith("/*")){const p=f.split("/")[0];if(h.startsWith(`${p}/`))return!0}}return!1}var Xc=class{constructor(n){S(this,"_adapters");S(this,"accept");this._adapters=n;const i=n.findIndex(r=>r.accept==="*");if(i!==-1){if(i!==n.length-1)throw new Error("A wildcard adapter (handling all files) can only be specified as the last adapter.");this.accept="*"}else this.accept=n.map(r=>r.accept).join(",")}add(n){for(const i of this._adapters)if(as(n.file,i.accept))return i.add(n);throw new Error("No matching adapter found for file")}async send(n){const i=this._adapters.slice();for(const r of i)if(as(n.file,r.accept))return r.send(n);throw new Error("No matching adapter found for attachment")}async remove(n){const i=this._adapters.slice();for(const r of i)if(as({name:n.name,type:n.contentType},r.accept))return r.remove(n);throw new Error("No matching adapter found for attachment")}},Qc=B.createContext(null),jc=()=>B.useContext(Qc),ke=Object.freeze([]),De="DEFAULT_THREAD_ID",th=Object.freeze([De]),uo=Object.freeze({id:De,remoteId:void 0,externalId:void 0,status:"regular"}),eh=Promise.resolve(),co=Object.freeze({[De]:uo}),nh=class{constructor(n={},i){S(this,"_mainThreadId",De);S(this,"_threads",th);S(this,"_archivedThreads",ke);S(this,"_threadData",co);S(this,"_mainThread");S(this,"_subscriptions",new Set);this.adapter=n,this.threadFactory=i,this._mainThread=this.threadFactory(),this.__internal_setAdapter(n,!0)}get isLoading(){return this.adapter.isLoading??!1}get newThreadId(){}get threadIds(){return this._threads}get archivedThreadIds(){return this._archivedThreads}get threadData(){return this._threadData}getLoadThreadsPromise(){return eh}get mainThreadId(){return this._mainThreadId}getMainThreadRuntimeCore(){return this._mainThread}getThreadRuntimeCore(){throw new Error("Method not implemented.")}getItemById(n){for(const i of this.adapter.threads??[])if(i.id===n)return i;for(const i of this.adapter.archivedThreads??[])if(i.id===n)return i;if(n===De)return uo}__internal_setAdapter(n,i=!1){var I,P,C,A;const r=this.adapter;this.adapter=n;const a=n.threadId??De,h=n.threads??ke,f=n.archivedThreads??ke,p=r.threadId??De,m=r.threads??ke,w=r.archivedThreads??ke;!i&&p===a&&m===h&&w===f||(this._threadData={...co,...Object.fromEntries(((I=n.threads)==null?void 0:I.map(R=>[R.id,{...R,remoteId:R.remoteId,externalId:R.externalId,status:"regular"}]))??[]),...Object.fromEntries(((P=n.archivedThreads)==null?void 0:P.map(R=>[R.id,{...R,remoteId:R.remoteId,externalId:R.externalId,status:"archived"}]))??[])},m!==h&&(this._threads=((C=this.adapter.threads)==null?void 0:C.map(R=>R.id))??ke),w!==f&&(this._archivedThreads=((A=this.adapter.archivedThreads)==null?void 0:A.map(R=>R.id))??ke),p!==a&&(this._mainThreadId=a,this._mainThread=this.threadFactory()),this._notifySubscribers())}async switchToThread(n){if(this._mainThreadId===n)return;const i=this.adapter.onSwitchToThread;if(!i)throw new Error("External store adapter does not support switching to thread");i(n)}async switchToNewThread(){const n=this.adapter.onSwitchToNewThread;if(!n)throw new Error("External store adapter does not support switching to new thread");n()}async rename(n,i){const r=this.adapter.onRename;if(!r)throw new Error("External store adapter does not support renaming");r(n,i)}async detach(){}async archive(n){const i=this.adapter.onArchive;if(!i)throw new Error("External store adapter does not support archiving");i(n)}async unarchive(n){const i=this.adapter.onUnarchive;if(!i)throw new Error("External store adapter does not support unarchiving");i(n)}async delete(n){const i=this.adapter.onDelete;if(!i)throw new Error("External store adapter does not support deleting");i(n)}initialize(n){return Promise.resolve({remoteId:n,externalId:void 0})}generateTitle(){throw new Error("Method not implemented.")}subscribe(n){return this._subscriptions.add(n),()=>this._subscriptions.delete(n)}_notifySubscribers(){for(const n of this._subscriptions)n()}},ho=class{constructor(){S(this,"cache",new WeakMap)}convertMessages(n,i){return n.map((r,a)=>{const h=this.cache.get(r),f=i(h,r,a);return this.cache.set(r,f),f})}},rh=class extends Ji{constructor(i,r,{parentId:a,message:h}){super();S(this,"_nonTextParts");S(this,"_previousText");S(this,"_parentId");S(this,"_sourceId");this.runtime=i,this.endEditCallback=r,this._parentId=a,this._sourceId=h.id,this._previousText=Sn(h),this.setText(this._previousText),this.setRole(h.role),this.setAttachments(h.attachments??[]),this._nonTextParts=h.content.filter(f=>f.type!=="text"),this.setRunConfig({...i.composer.runConfig})}get canCancel(){return!0}getAttachmentAdapter(){var i;return(i=this.runtime.adapters)==null?void 0:i.attachments}async handleSend(i){Sn(i)!==this._previousText&&this.runtime.append({...i,content:[...i.content,...this._nonTextParts],parentId:this._parentId,sourceId:this._sourceId}),this.handleCancel()}handleCancel(){this.endEditCallback(),this._notifySubscribers()}},sh=class{constructor(n){S(this,"_subscriptions",new Set);S(this,"_isInitialized",!1);S(this,"repository",new Qi);S(this,"composer",new mc(this));S(this,"_editComposers",new Map);S(this,"_stopSpeaking");S(this,"speech");S(this,"_eventSubscribers",new Map);this._contextProvider=n}get messages(){return this.repository.getMessages()}get state(){let n;for(const i of this.messages)if(i.role==="assistant"){n=i;break}return(n==null?void 0:n.metadata.unstable_state)??null}getModelContext(){return this._contextProvider.getModelContext()}getEditComposer(n){return this._editComposers.get(n)}beginEdit(n){if(this._editComposers.has(n))throw new Error("Edit already in progress");this._editComposers.set(n,new rh(this,()=>this._editComposers.delete(n),this.repository.getMessage(n))),this._notifySubscribers()}getMessageById(n){try{return this.repository.getMessage(n)}catch{return}}getBranches(n){return this.repository.getBranches(n)}switchToBranch(n){this.repository.switchToBranch(n),this._notifySubscribers()}_notifySubscribers(){for(const n of this._subscriptions)n()}_notifyEventSubscribers(n){const i=this._eventSubscribers.get(n);if(i)for(const r of i)r()}subscribe(n){return this._subscriptions.add(n),()=>this._subscriptions.delete(n)}submitFeedback({messageId:n,type:i}){var f;const r=(f=this.adapters)==null?void 0:f.feedback;if(!r)throw new Error("Feedback adapter not configured");const{message:a,parentId:h}=this.repository.getMessage(n);if(r.submit({message:a,type:i}),a.role==="assistant"){const p={...a,metadata:{...a.metadata,submittedFeedback:{type:i}}};this.repository.addOrUpdateMessage(h,p)}this._notifySubscribers()}speak(n){var f,p;const i=(f=this.adapters)==null?void 0:f.speech;if(!i)throw new Error("Speech adapter not configured");const{message:r}=this.repository.getMessage(n);(p=this._stopSpeaking)==null||p.call(this);const a=i.speak(Sn(r)),h=a.subscribe(()=>{a.status.type==="ended"?(this._stopSpeaking=void 0,this.speech=void 0):this.speech={messageId:n,status:a.status},this._notifySubscribers()});this.speech={messageId:n,status:a.status},this._notifySubscribers(),this._stopSpeaking=()=>{a.cancel(),h(),this.speech=void 0,this._stopSpeaking=void 0}}stopSpeaking(){if(!this._stopSpeaking)throw new Error("No message is being spoken");this._stopSpeaking(),this._notifySubscribers()}ensureInitialized(){this._isInitialized||(this._isInitialized=!0,this._notifyEventSubscribers("initialize"))}export(){return this.repository.export()}import(n){this.ensureInitialized(),this.repository.clear(),this.repository.import(n),this._notifySubscribers()}reset(n){this.import(is.fromArray(n??[]))}unstable_on(n,i){var a,h;if(n==="model-context-update")return((h=(a=this._contextProvider).subscribe)==null?void 0:h.call(a,i))??(()=>{});const r=this._eventSubscribers.get(n);return r?r.add(i):this._eventSubscribers.set(n,new Set([i])),()=>{this._eventSubscribers.get(n).delete(i)}}},ih=Object.freeze([]),oh=(n,i)=>{var r;return n&&((r=i[i.length-1])==null?void 0:r.role)!=="assistant"},ah=class extends sh{constructor(i,r){super(i);S(this,"_assistantOptimisticId",null);S(this,"_capabilities",{switchToBranch:!1,switchBranchDuringRun:!1,edit:!1,reload:!1,cancel:!1,unstable_copy:!1,speech:!1,attachments:!1,feedback:!1});S(this,"_messages");S(this,"isDisabled");S(this,"suggestions",[]);S(this,"extras");S(this,"_converter",new ho);S(this,"_store");S(this,"updateMessages",i=>{var a,h,f,p;this._store.convertMessage!==void 0?(h=(a=this._store).setMessages)==null||h.call(a,i.flatMap(Pc).filter(m=>m!=null)):(p=(f=this._store).setMessages)==null||p.call(f,i)});this.__internal_setAdapter(r)}get capabilities(){return this._capabilities}get isLoading(){return this._store.isLoading??!1}get messages(){return this._messages}get state(){return this._store.state??super.state}get adapters(){return this._store.adapters}beginEdit(i){if(!this._store.onEdit)throw new Error("Runtime does not support editing.");super.beginEdit(i)}__internal_setAdapter(i){var f,p,m,w,I,P;if(this._store===i)return;const r=i.isRunning??!1;this.isDisabled=i.isDisabled??!1;const a=this._store;this._store=i,this.extras=i.extras,this.suggestions=i.suggestions??ih,this._capabilities={switchToBranch:this._store.setMessages!==void 0,switchBranchDuringRun:!1,edit:this._store.onEdit!==void 0,reload:this._store.onReload!==void 0,cancel:this._store.onCancel!==void 0,speech:((f=this._store.adapters)==null?void 0:f.speech)!==void 0,unstable_copy:((p=this._store.unstable_capabilities)==null?void 0:p.copy)!==!1,attachments:!!((m=this._store.adapters)!=null&&m.attachments),feedback:!!((w=this._store.adapters)!=null&&w.feedback)};let h;if(i.messageRepository){if(a&&a.isRunning===i.isRunning&&a.messageRepository===i.messageRepository){this._notifySubscribers();return}this.repository.clear(),this._assistantOptimisticId=null,this.repository.import(i.messageRepository),h=this.repository.getMessages()}else if(i.messages){if(a){if(a.convertMessage!==i.convertMessage)this._converter=new ho;else if(a.isRunning===i.isRunning&&a.messages===i.messages){this._notifySubscribers();return}}h=i.convertMessage?this._converter.convertMessages(i.messages,(C,A,R)=>{if(!i.convertMessage)return A;const K=R===i.messages.length-1,At=Gi(K,r,!1,!1,void 0);if(C&&(C.role!=="assistant"||!Ec(C.status)||C.status===At))return C;const gt=i.convertMessage(A,R),ct=ss(gt,R.toString(),At);return ct[tn]=A,ct}):i.messages;for(let C=0;C<h.length;C++){const A=h[C],R=h[C-1];this.repository.addOrUpdateMessage((R==null?void 0:R.id)??null,A)}}else throw new Error("ExternalStoreAdapter must provide either 'messages' or 'messageRepository'");h.length>0&&this.ensureInitialized(),((a==null?void 0:a.isRunning)??!1)!==(i.isRunning??!1)&&(i.isRunning?this._notifyEventSubscribers("run-start"):this._notifyEventSubscribers("run-end")),this._assistantOptimisticId&&(this.repository.deleteMessage(this._assistantOptimisticId),this._assistantOptimisticId=null),oh(r,h)&&(this._assistantOptimisticId=this.repository.appendOptimisticMessage(((I=h.at(-1))==null?void 0:I.id)??null,{role:"assistant",content:[]})),this.repository.resetHead(this._assistantOptimisticId??((P=h.at(-1))==null?void 0:P.id)??null),this._messages=this.repository.getMessages(),this._notifySubscribers()}switchToBranch(i){if(!this._store.setMessages)throw new Error("Runtime does not support switching branches.");this._store.isRunning||(this.repository.switchToBranch(i),this.updateMessages(this.repository.getMessages()))}async append(i){var r;if(i.parentId!==(((r=this.messages.at(-1))==null?void 0:r.id)??null)){if(!this._store.onEdit)throw new Error("Runtime does not support editing messages.");await this._store.onEdit(i)}else await this._store.onNew(i)}async startRun(i){if(!this._store.onReload)throw new Error("Runtime does not support reloading messages.");await this._store.onReload(i.parentId,i)}async resumeRun(i){if(!this._store.onResume)throw new Error("Runtime does not support resuming runs.");await this._store.onResume(i)}unstable_loadExternalState(i){if(!this._store.onLoadExternalState)throw new Error("Runtime does not support importing states.");this._store.onLoadExternalState(i)}cancelRun(){var a;if(!this._store.onCancel)throw new Error("Runtime does not support cancelling runs.");this._store.onCancel(),this._assistantOptimisticId&&(this.repository.deleteMessage(this._assistantOptimisticId),this._assistantOptimisticId=null);let i=this.repository.getMessages();const r=i[i.length-1];(r==null?void 0:r.role)==="user"&&r.id===((a=i.at(-1))==null?void 0:a.id)?(this.repository.deleteMessage(r.id),this.composer.text.trim()||this.composer.setText(Sn(r)),i=this.repository.getMessages()):this._notifySubscribers(),setTimeout(()=>{this.updateMessages(i)},0)}addToolResult(i){var r,a;if(!this._store.onAddToolResult&&!this._store.onAddToolResult)throw new Error("Runtime does not support tool results.");(a=(r=this._store).onAddToolResult)==null||a.call(r,i)}resumeToolCall(i){if(!this._store.onResumeToolCall)throw new Error("Runtime does not support resuming tool calls.");this._store.onResumeToolCall(i)}reset(i){const r=new Qi;r.import(is.fromArray(i??[])),this.updateMessages(r.getMessages())}import(i){this._assistantOptimisticId=null,super.import(i),this._store.onImport&&this._store.onImport(this.repository.getMessages())}},lo=n=>{var i;return((i=n.adapters)==null?void 0:i.threadList)??{}},uh=class extends gc{constructor(i){super();S(this,"threads");this.threads=new nh(lo(i),()=>new ah(this._contextProvider,i))}setAdapter(i){this.threads.__internal_setAdapter(lo(i)),this.threads.getMainThreadRuntimeCore().__internal_setAdapter(i)}},ch=n=>{const[i]=B.useState(()=>new uh(n));B.useEffect(()=>{i.setAdapter(n)});const{modelContext:r}=jc()??{};return B.useEffect(()=>{if(r)return i.registerModelContextProvider(r)},[r,i]),B.useMemo(()=>new dl(i),[i])};function hh(n,i){n.commitTasks.forEach(r=>{const a=r.cellIndex,h=i.cells[a];if(h.type!=="effect")throw new Error("Cannot find effect cell");let f=!0;if(h.deps!==void 0&&r.deps!==void 0&&(f=h.deps.length!==r.deps.length||h.deps.some((p,m)=>!Object.is(p,r.deps[m]))),f){if(h.mounted){if(typeof h.deps!=typeof r.deps)throw new Error("tapEffect called with and without dependencies across re-renders");try{h.mounted&&h.cleanup&&h.cleanup()}finally{h.mounted=!1}}try{const p=r.effect();if(p!==void 0&&typeof p!="function")throw new Error(`An effect function must either return a cleanup function or nothing. Received: ${typeof p}`);h.mounted=!0,h.cleanup=typeof p=="function"?p:void 0,h.deps=r.deps}catch(p){throw p}}})}function lh(n){let i=null;for(let r=n.cells.length-1;r>=0;r--){const a=n.cells[r];if((a==null?void 0:a.type)==="effect"&&a.mounted&&a.cleanup)try{a.cleanup()}catch(h){i==null&&(i=h)}finally{a.mounted=!1}}if(i!=null)throw i}var En=null;function fh(n,i){n.currentIndex=0;const r=En;En=n;try{if(i(),n.isFirstRender=!1,n.cells.length!==n.currentIndex)throw new Error(`Rendered ${n.currentIndex} hooks but expected ${n.cells.length}. Hooks must be called in the exact same order in every render.`)}finally{En=r}}function us(){if(!En)throw new Error("No resource fiber available");return En}function fo(n,i){const r=n[po];if(!r)throw new Error("ResourceElement.type is not a valid Resource");return r(i)}var po=Symbol("fnSymbol");function rr(n,i){return{resource:n,scheduleRerender:i,cells:[],currentIndex:0,renderContext:void 0,isFirstRender:!0,isMounted:!1,isNeverMounted:!0}}function en(n){n.isMounted=!1,lh(n)}function xn(n,i){const r={commitTasks:[],props:i,state:void 0};return fh(n,()=>{n.renderContext=r;try{r.state=fo(n.resource,i)}finally{n.renderContext=void 0}}),r}function nn(n,i){n.isMounted=!0,n.isNeverMounted=!1,hh(i,n)}var dh=globalThis.__ASSISTANT_UI_DISABLE_LAYOUT_EFFECT__===!0,go=dh?B.useEffect:B.useLayoutEffect;function ph(n){const[,i]=B.useState({}),r=B.useMemo(()=>rr(n.type,()=>i({})),[n.type,i]),a=xn(r,n.props);return go(()=>()=>en(r),[]),go(()=>{nn(r,a)}),a.state}var _o=n=>typeof n=="string"?{scope:n.split(".")[0],event:n}:{scope:n.scope,event:n.event},cs=(n,i,r)=>i===n,rn,hs=()=>{if(rn)return rn;const n=()=>({apis:new Map,nextId:0,listeners:new Set});if(typeof window>"u")return rn=n(),rn;const i=window.__ASSISTANT_UI_DEVTOOLS_HOOK__;if(i)return rn=i,i;const r=n();return window.__ASSISTANT_UI_DEVTOOLS_HOOK__=r,rn=r,r},gh=(Xt=class{static register(i){var m,w;const r=hs();for(const I of r.apis.values())if(I.api===i)return()=>{};const a=r.nextId++,h={api:i,logs:[]},f=(m=i.on)==null?void 0:m.call(i,"*",I=>{const P=r.apis.get(a);P&&(P.logs.push({time:new Date,event:I.event,data:I.payload}),P.logs.length>Xt.MAX_EVENT_LOGS_PER_API&&(P.logs=P.logs.slice(-200)),Xt.notifyListeners(a))}),p=(w=i.subscribe)==null?void 0:w.call(i,()=>{Xt.notifyListeners(a)});return r.apis.set(a,h),Xt.notifyListeners(a),()=>{const I=hs();I.apis.get(a)&&(f==null||f(),p==null||p(),I.apis.delete(a),Xt.notifyListeners(a))}}static notifyListeners(i){hs().listeners.forEach(a=>a(i))}},S(Xt,"MAX_EVENT_LOGS_PER_API",200),Xt);function lt(n){const i=(r,a)=>({type:i,props:r,...(a==null?void 0:a.key)!==void 0&&{key:a.key}});return i[po]=n,i}var _h=n=>{if(n.renderContext)throw new Error("Resource updated during render");if(n.isNeverMounted)throw new Error("Resource updated before mount");n.isMounted&&n.scheduleRerender()};function bh(n){const i=us(),r=i.currentIndex++;if(!i.isFirstRender&&r>=i.cells.length)throw new Error("Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render.");if(!i.cells[r]){const f={type:"state",value:typeof n=="function"?n():n,set:p=>{const m=f.value,w=typeof p=="function"?p(m):p;Object.is(m,w)||(f.value=w,_h(i))}};i.cells[r]=f}const a=i.cells[r];if(a.type!=="state")throw new Error("Hook order changed between renders");return a}function ae(n){const i=bh(n);return[i.value,i.set]}function mh(){const n=us(),i=n.currentIndex++;if(!n.isFirstRender&&i>=n.cells.length)throw new Error("Rendered more hooks than during the previous render. Hooks must be called in the exact same order in every render.");if(!n.cells[i]){const a={type:"effect",mounted:!1};n.cells[i]=a}if(n.cells[i].type!=="effect")throw new Error("Hook order changed between renders");return i}function Pt(n,i){const r=us(),a=mh();r.renderContext.commitTasks.push({effect:n,deps:i,cellIndex:a})}function sr(n){const[i]=ae(()=>({current:n}));return i}var vh=(n,i)=>{if(n.length!==i.length)return!1;for(let r=0;r<n.length;r++)if(!Object.is(n[r],i[r]))return!1;return!0},rt=(n,i)=>{const r=sr();return r.current||(r.current={value:n(),deps:i}),vh(r.current.deps,i)||(r.current.value=n(),r.current.deps=i),r.current.value};function ls(n,i){const[r,a]=ae({}),h=rt(()=>rr(n.type,()=>a({})),[n.type]),f=i?rt(()=>n.props,i):n.props,p=rt(()=>xn(h,f),[h,f,r]);return Pt(()=>()=>en(h),[h]),Pt(()=>{nn(h,p)},[h,p]),p.state}function Zt(n){return fo(n.type,n.props)}function wh(n){const i=new Set;n.forEach((m,w)=>{if(m.key===void 0)throw new Error(`tapResources: All resource elements must have a key. Element at index ${w} is missing a key.`);if(i.has(m.key))throw new Error(`tapResources: Duplicate key "${m.key}" found. All keys must be unique.`);i.add(m.key)});const[r,a]=ae({}),h=rt(()=>new Map(n.map(m=>[m.key,m])),[n]),[f]=ae(()=>new Map),p=rt(()=>{const m=new Map,w=new Set;return h.forEach((I,P)=>{w.add(P);let C=f.get(P);(!C||C.resource!==I.type)&&(C&&en(C),C=rr(I.type,()=>a({})),f.set(P,C));const A=xn(C,I.props);m.set(P,A)}),f.forEach((I,P)=>{w.has(P)||(en(I),f.delete(P))}),m},[h,r]);return Pt(()=>{p.forEach((m,w)=>{const I=f.get(w);I&&nn(I,m)})},[p,f]),Pt(()=>()=>{f.forEach(m=>{en(m)}),f.clear()},[f]),rt(()=>n.map(m=>{var w;return(w=p.get(m.key))==null?void 0:w.state}),[n,p])}var fs=[],ds=!1;function yh(){ds=!1;const n=fs;fs=[];for(const i of n)try{i()}catch(r){console.error("Error in scheduled task:",r)}}function Sh(n){fs.push(n),ds||(ds=!0,queueMicrotask(yh))}var Eh=(Ue=class{constructor(i){S(this,"_isDirty",!1);S(this,"_hasScheduledTask",!1);S(this,"_isFlushing",!1);this._task=i}get isDirty(){return this._isDirty}markDirty(){this._isDirty=!0,!(this._hasScheduledTask||this._isFlushing)&&(this._hasScheduledTask=!0,Sh(()=>{this._hasScheduledTask=!1,this.flushSync()}))}flushSync(){if(this._isFlushing)return;this._isFlushing=!0;let i=0;try{for(;this._isDirty;){if(i++,i>Ue.MAX_FLUSH_DEPTH)throw new Error("Maximum update depth exceeded. This can happen when a resource repeatedly calls setState inside tapEffect.");this._isDirty=!1,this._task()}}finally{this._isFlushing=!1}}},S(Ue,"MAX_FLUSH_DEPTH",50),Ue),xh=lt(({element:n,onUpdateInput:i,onFlushSync:r,onDispose:a})=>{const[h,f]=ae(n.props),p=Zt({type:n.type,props:h}),m=sr(new Set).current,w=sr(p);return Pt(()=>{p!==w.current&&(w.current=p,m.forEach(P=>P()))}),rt(()=>({getState:()=>w.current,subscribe:P=>(m.add(P),()=>m.delete(P)),updateInput:P=>{i(),f(()=>P)},flushSync:r,dispose:a}),[])}),Th=(n,i=!1)=>{let r=!i;const a={element:n,onUpdateInput:()=>{r||(r=!0,nn(f,p))},onFlushSync:()=>{h.flushSync()},onDispose:()=>en(f)},h=new Eh(()=>{p=xn(f,a),r&&nn(f,p)}),f=rr(xh,()=>h.markDirty());let p=xn(f,a);return r&&nn(f,p),p.state},Tn=Symbol("tap.Context"),bo=n=>({[Tn]:n}),mo=(n,i,r)=>{const a=n[Tn];n[Tn]=i;try{return r()}finally{n[Tn]=a}},vo=n=>n[Tn];const wo=n=>{let i;const r=new Set,a=(I,P)=>{const C=typeof I=="function"?I(i):I;if(!Object.is(C,i)){const A=i;i=P??(typeof C!="object"||C===null)?C:Object.assign({},i,C),r.forEach(R=>R(i,A))}},h=()=>i,m={setState:a,getState:h,getInitialState:()=>w,subscribe:I=>(r.add(I),()=>r.delete(I))},w=i=n(a,h,m);return m},Ah=n=>n?wo(n):wo,Ch=n=>n;function Ih(n,i=Ch){const r=B.useSyncExternalStore(n.subscribe,B.useCallback(()=>i(n.getState()),[n,i]),B.useCallback(()=>i(n.getInitialState()),[n,i]));return B.useDebugValue(r),r}const yo=n=>{const i=Ah(n),r=a=>Ih(i,a);return Object.assign(r,i),r},Rh=n=>n?yo(n):yo;var Mh=lt(n=>{const i=rt(()=>Th(n,!0),[n.type]);return Pt(()=>{i.updateInput(n.props)}),i}),Ph=class{constructor(n){this.getApi=n}get(n,i){return this.getApi()[i]}ownKeys(){return Object.keys(this.getApi())}has(n,i){return i in this.getApi()}getOwnPropertyDescriptor(n,i){return Object.getOwnPropertyDescriptor(this.getApi(),i)}set(){return!1}defineProperty(){return!1}deleteProperty(){return!1}},ue=(n,i)=>{const r=sr(n);Pt(()=>{r.current=n});const a=rt(()=>new Proxy({},new Ph(()=>r.current)),[]),h=i==null?void 0:i.key,f=n.getState();return rt(()=>({key:h,state:f,api:a}),[f,h])},So=bo(null),Oh=(n,i)=>mo(So,n,i),Eo=()=>{const n=vo(So);if(!n)throw new Error("Model context is not available in this context");return n},Lh=lt(({toolkit:n})=>{const[i,r]=ae(()=>({tools:{}})),a=Eo();Pt(()=>{if(!n)return;const f=[];for(const[w,I]of Object.entries(n))I.render&&f.push(h(w,I.render));const p=Object.entries(n).reduce((w,[I,P])=>{const{render:C,...A}=P;return w[I]=A,w},{}),m={getModelContext:()=>({tools:p})};return f.push(a.register(m)),()=>{f.forEach(w=>w())}},[n,a]);const h=(f,p)=>(r(m=>({...m,tools:{...m.tools,[f]:[...m.tools[f]??[],p]}})),()=>{r(m=>{var w;return{...m,tools:{...m.tools,[f]:((w=m.tools[f])==null?void 0:w.filter(I=>I!==p))??[]}}})});return ue({getState:()=>i,setToolUI:h})}),Bh=lt(()=>rt(()=>{const i=new Map;return{on:(r,a)=>{i.has(r)||i.set(r,new Set);const h=i.get(r);return h.add(a),()=>{h.delete(a),h.size===0&&i.delete(r)}},emit:(r,a)=>{const h=i.get(r),f=i.get("*");!h&&!f||queueMicrotask(()=>{if(h)for(const p of h)p(a);if(f)for(const p of f)p({event:r,payload:a})})}}},[])),xo=bo(null),kh=(n,i)=>mo(xo,n,i),ps=()=>{const n=vo(xo);if(!n)throw new Error("Events context is not available");return n},Dh=lt(()=>{const[n]=ae(()=>({})),i=new Hi;return ue({getState:()=>n,getModelContext:()=>i.getModelContext(),subscribe:r=>i.subscribe(r),register:r=>i.registerModelContextProvider(r)})}),Nh=lt(({threads:n,modelContext:i,tools:r})=>{const a=Zt(Bh()),{threads:h,tools:f,modelContext:p}=kh(a,()=>{const w=ls(i??Dh(),[i]);return Oh(w.api,()=>({modelContext:w,tools:ls(r??Lh({}),[r]),threads:ls(n,[n])}))}),m=rt(()=>({threads:h.state,tools:f.state,modelContext:p.state}),[h.state,f.state,p.state]);return ue({getState:()=>m,threads:h.api,tools:f.api,modelContext:p.api,on:a.on})}),Fh=n=>{const i=()=>n.getState().api.threads.item("main");return{threads:yt({source:"root",query:{},get:()=>n.getState().api.threads}),tools:yt({source:"root",query:{},get:()=>n.getState().api.tools}),modelContext:yt({source:"root",query:{},get:()=>n.getState().api.modelContext}),thread:yt({source:"threads",query:{type:"main"},get:()=>n.getState().api.threads.thread("main")}),threadListItem:yt({source:"threads",query:{type:"main"},get:()=>i()}),composer:yt({source:"thread",query:{},get:()=>n.getState().api.threads.thread("main").composer}),on(r,a){const{event:h,scope:f}=_o(r);if(f==="*")return n.getState().api.on(h,a);if(cs("thread",f)||cs("thread-list-item",f)||cs("composer",f))return n.getState().api.on(h,p=>{p.threadId===i().getState().id&&a(p)});throw new Error(`Event scope is not available in this component: ${f}`)},subscribe:n.subscribe,flushSync:n.flushSync}},Uh=n=>{const i=Ao(),r=ph(Mh(Nh(n))),a=B.useMemo(()=>Fh(r),[r]);return B.useMemo(()=>Hh(i,a),[i,a])},yt=n=>{const i=n.get;return i.source=n.source,i.query=n.query,i},xe=()=>()=>{},To=B.createContext({threads:yt({source:null,query:{},get:()=>{throw new Error("Threads is only available inside <AssistantProvider />")}}),tools:yt({source:null,query:{},get:()=>{throw new Error("Tools is only available inside <AssistantProvider />")}}),modelContext:yt({source:null,query:{},get:()=>{throw new Error("ModelContext is only available inside <AssistantProvider />")}}),threadListItem:yt({source:null,query:{},get:()=>{throw new Error("ThreadListItem is only available inside <AssistantProvider />")}}),thread:yt({source:null,query:{},get:()=>{throw new Error("Thread is only available inside <AssistantProvider />")}}),composer:yt({source:null,query:{},get:()=>{throw new Error("Composer is only available inside <AssistantProvider />")}}),message:yt({source:null,query:{},get:()=>{throw new Error("Message is only available inside <ThreadPrimitive.Messages />")}}),part:yt({source:null,query:{},get:()=>{throw new Error("Part is only available inside <MessagePrimitive.Parts />")}}),attachment:yt({source:null,query:{},get:()=>{throw new Error("Attachment is only available inside <MessagePrimitive.Attachments /> or <ComposerPrimitive.Attachments />")}}),subscribe:xe,flushSync:xe,on:n=>{const{scope:i}=_o(n);throw new Error(`Event scope is not available in this component: ${i}`)}}),Ao=()=>B.useContext(To),Wh=n=>Uh(n);function $h(n){return n?Wh(n):Ao()}var qh=(n,i)=>n===xe?i:i===xe?n:(...r)=>{n(...r),i(...r)},zh=(n,i)=>n===xe?i:i===xe?n:(...r)=>{const a=n(...r),h=i(...r);return()=>{a(),h()}},Hh=(n,i)=>{const r=i.subscribe,a=i.flushSync;return{...n,...i,subscribe:zh(n.subscribe,r??xe),flushSync:qh(n.flushSync,a??xe)}},Jh=({api:n,children:i,devToolsVisible:r=!0})=>(B.useEffect(()=>{if(!(!r||!n.subscribe))return gh.register(n)},[n,r]),Ee.jsx(To.Provider,{value:n,children:i}));function Gh(n,i){function r(a){const h=B.useContext(n);if(!(a!=null&&a.optional)&&!h)throw new Error(`This component must be used within ${i}.`);return h}return r}function Kh(n,i){function r(h){const f=n(h);return f?f[i]:null}function a(h){let f=!1,p;typeof h=="function"?p=h:h&&typeof h=="object"&&(f=!!h.optional,p=h.selector);const m=r({optional:f});return m?p?m(p):m():null}return{[i]:a,[`${i}Store`]:r}}var Co=B.createContext(null),Yh=Gh(Co,"ThreadPrimitive.Viewport"),{useThreadViewportStore:Vh}=Kh(Yh,"useThreadViewport"),Ne=n=>{const[,i]=ae(n.getState);return Pt(()=>(i(n.getState()),n.subscribe(()=>{i(n.getState())})),[n]),n.getState()},Zh=lt(({runtime:n})=>{const i=Ne(n),r=ps();return Pt(()=>{const a=[],h=["switched-to","switched-away"];for(const f of h){const p=n.unstable_on(f,()=>{r.emit(`thread-list-item.${f}`,{threadId:n.getState().id})});a.push(p)}return()=>{for(const f of a)f()}},[n,r]),ue({getState:()=>i,switchTo:n.switchTo,rename:n.rename,archive:n.archive,unarchive:n.unarchive,delete:n.delete,generateTitle:n.generateTitle,initialize:n.initialize,detach:n.detach,__internal_getRuntime:()=>n},{key:i.id})}),An=n=>{const i=wh(n);return{state:i.map(r=>r.state),api:r=>{var h,f;const a="index"in r?(h=i[r.index])==null?void 0:h.api:(f=i.find(p=>p.key===r.key))==null?void 0:f.api;if(!a)throw new Error(`tapLookupResources: Resource not found for lookup: ${JSON.stringify(r)}`);return a}}},Io=lt(({runtime:n})=>{const i=Ne(n);return ue({getState:()=>i,remove:n.remove,__internal_getRuntime:()=>n},{key:i.id})}),Xh=lt(({runtime:n,index:i})=>{const r=rt(()=>n.getAttachmentByIndex(i),[n,i]);return Zt(Io({runtime:r}))}),Ro=lt(({threadIdRef:n,messageIdRef:i,runtime:r})=>{const a=Ne(r),h=ps();Pt(()=>{const m=[],w=["send","attachment-add"];for(const I of w){const P=r.unstable_on(I,()=>{h.emit(`composer.${I}`,{threadId:n.current,...i&&{messageId:i.current}})});m.push(P)}return()=>{for(const I of m)I()}},[r,h,n,i]);const f=An(a.attachments.map((m,w)=>Xh({runtime:r,index:w},{key:w}))),p=rt(()=>({text:a.text,role:a.role,attachments:f.state,runConfig:a.runConfig,isEditing:a.isEditing,canCancel:a.canCancel,attachmentAccept:a.attachmentAccept,isEmpty:a.isEmpty,type:a.type??"thread"}),[a,f.state]);return ue({getState:()=>p,setText:r.setText,setRole:r.setRole,setRunConfig:r.setRunConfig,addAttachment:r.addAttachment,reset:r.reset,clearAttachments:r.clearAttachments,send:r.send,cancel:r.cancel,beginEdit:r.beginEdit??(()=>{throw new Error("beginEdit is not supported in this runtime")}),attachment:m=>"id"in m?f.api({key:m.id}):f.api(m),__internal_getRuntime:()=>r})}),Qh=lt(({runtime:n})=>{const i=Ne(n);return ue({getState:()=>i,addToolResult:a=>n.addToolResult(a),resumeToolCall:a=>n.resumeToolCall(a),__internal_getRuntime:()=>n},{key:i.type==="tool-call"?`toolCallId-${i.toolCallId}`:void 0})}),jh=lt(({runtime:n,index:i})=>{const r=rt(()=>n.getAttachmentByIndex(i),[n,i]);return Zt(Io({runtime:r}))}),tl=lt(({runtime:n,index:i})=>{const r=rt(()=>n.getMessagePartByIndex(i),[n,i]);return Zt(Qh({runtime:r}))}),el=lt(({runtime:n,threadIdRef:i})=>{var A;const r=Ne(n),[a,h]=ae(!1),[f,p]=ae(!1),m=rt(()=>({get current(){return n.getState().id}}),[n]),w=Zt(Ro({runtime:n.composer,threadIdRef:i,messageIdRef:m})),I=An(r.content.map((R,K)=>tl({runtime:n,index:K},{key:K}))),P=An(((A=r.attachments)==null?void 0:A.map((R,K)=>jh({runtime:n,index:K},{key:K})))??[]),C=rt(()=>({...r,parts:I.state,composer:w.state,isCopied:a,isHovering:f}),[r,I.state,w.state,a,f]);return ue({getState:()=>C,composer:w.api,reload:R=>n.reload(R),speak:()=>n.speak(),stopSpeaking:()=>n.stopSpeaking(),submitFeedback:R=>n.submitFeedback(R),switchToBranch:R=>n.switchToBranch(R),getCopyText:()=>n.unstable_getCopyText(),part:R=>"index"in R?I.api({index:R.index}):I.api({key:`toolCallId-${R.toolCallId}`}),attachment:R=>"id"in R?P.api({key:R.id}):P.api(R),setIsCopied:h,setIsHovering:p,__internal_getRuntime:()=>n},{key:r.id})}),nl=lt(({runtime:n,id:i,threadIdRef:r})=>{const a=rt(()=>n.getMessageById(i),[n,i]);return Zt(el({runtime:a,threadIdRef:r}))}),rl=lt(({runtime:n})=>{const i=Ne(n),r=ps();Pt(()=>{const m=[],w=["run-start","run-end","initialize","model-context-update"];for(const I of w){const P=n.unstable_on(I,()=>{var A;const C=((A=n.getState())==null?void 0:A.threadId)||"unknown";r.emit(`thread.${I}`,{threadId:C})});m.push(P)}return()=>{for(const I of m)I()}},[n]);const a=rt(()=>({get current(){return n.getState().threadId}}),[n]),h=Zt(Ro({runtime:n.composer,threadIdRef:a})),f=An(i.messages.map(m=>nl({runtime:n,id:m.id,threadIdRef:a},{key:m.id}))),p=rt(()=>({isDisabled:i.isDisabled,isLoading:i.isLoading,isRunning:i.isRunning,capabilities:i.capabilities,state:i.state,suggestions:i.suggestions,extras:i.extras,speech:i.speech,composer:h.state,messages:f.state}),[i,f,h.state]);return ue({getState:()=>p,composer:h.api,append:n.append,startRun:n.startRun,unstable_resumeRun:n.unstable_resumeRun,cancelRun:n.cancelRun,getModelContext:n.getModelContext,export:n.export,import:n.import,reset:n.reset,stopSpeaking:n.stopSpeaking,startVoice:async()=>{throw new Error("startVoice is not supported in this runtime")},stopVoice:async()=>{throw new Error("stopVoice is not supported in this runtime")},message:m=>"id"in m?f.api({key:m.id}):f.api(m),__internal_getRuntime:()=>n})}),sl=lt(({runtime:n,id:i})=>{const r=rt(()=>n.getItemById(i),[n,i]);return Zt(Zh({runtime:r}))}),il=lt(({runtime:n,__internal_assistantRuntime:i})=>{const r=Ne(n),a=Zt(rl({runtime:n.main})),h=An(Object.keys(r.threadItems).map(p=>sl({runtime:n,id:p},{key:p}))),f=rt(()=>({mainThreadId:r.mainThreadId,newThreadId:r.newThread??null,isLoading:r.isLoading,threadIds:r.threads,archivedThreadIds:r.archivedThreads,threadItems:h.state,main:a.state}),[r,h.state,a.state]);return ue({getState:()=>f,thread:()=>a.api,item:p=>{if(p==="main")return h.api({key:f.mainThreadId});if("id"in p)return h.api({key:p.id});const{index:m,archived:w=!1}=p,I=w?f.archivedThreadIds[m]:f.threadIds[m];return h.api({key:I})},switchToThread:p=>{n.switchToThread(p)},switchToNewThread:()=>{n.switchToNewThread()},__internal_getAssistantRuntime:()=>i})}),ol=lt(n=>{const i=Eo();return Pt(()=>n.registerModelContextProvider(i),[n,i]),Zt(il({runtime:n.threads,__internal_assistantRuntime:n}))}),gs=n=>{const i=new Map,r=()=>{let a=0;for(const h of i.values())a+=h;n(a)};return{register:()=>{const a=Symbol();return i.set(a,0),{setHeight:h=>{i.get(a)!==h&&(i.set(a,h),r())},unregister:()=>{i.delete(a),r()}}}}},al=(n={})=>{const i=new Set,r=gs(p=>{f.setState({height:{...f.getState().height,viewport:p}})}),a=gs(p=>{f.setState({height:{...f.getState().height,inset:p}})}),h=gs(p=>{f.setState({height:{...f.getState().height,userMessage:p}})}),f=Rh(()=>({isAtBottom:!0,scrollToBottom:({behavior:p="auto"}={})=>{for(const m of i)m({behavior:p})},onScrollToBottom:p=>(i.add(p),()=>{i.delete(p)}),turnAnchor:n.turnAnchor??"bottom",height:{viewport:0,inset:0,userMessage:0},registerViewport:r.register,registerContentInset:a.register,registerUserMessageHeight:h.register}));return f},Mo=n=>n,ul=n=>{const i=Vh({optional:!0}),[r]=B.useState(()=>al(n));return B.useEffect(()=>i==null?void 0:i.getState().onScrollToBottom(()=>{r.getState().scrollToBottom()}),[i,r]),B.useEffect(()=>{if(i)return r.subscribe(a=>{i.getState().isAtBottom!==a.isAtBottom&&Mo(i).setState({isAtBottom:a.isAtBottom})})},[r,i]),B.useEffect(()=>{const a={turnAnchor:n.turnAnchor??"bottom"};r.getState().turnAnchor!==a.turnAnchor&&Mo(r).setState(a)},[r,n.turnAnchor]),r},cl=({children:n,options:i={}})=>{const r=ul(i),[a]=B.useState(()=>({useThreadViewport:r}));return Ee.jsx(Co.Provider,{value:a,children:n})},hl=n=>{var i;return(i=n._core)==null?void 0:i.RenderComponent},ll=({children:n,runtime:i})=>{const r=$h({threads:ol(i)}),a=hl(i);return Ee.jsxs(Jh,{api:r,children:[a&&Ee.jsx(a,{}),Ee.jsx(cl,{children:n})]})},fl=B.memo(ll),dl=class{constructor(n){S(this,"threads");S(this,"_thread");this._core=n,this.threads=new Yc(n.threads),this._thread=this.threads.main,this.__internal_bindMethods()}get threadList(){return this.threads}__internal_bindMethods(){this.switchToNewThread=this.switchToNewThread.bind(this),this.switchToThread=this.switchToThread.bind(this),this.registerModelContextProvider=this.registerModelContextProvider.bind(this),this.registerModelConfigProvider=this.registerModelConfigProvider.bind(this),this.reset=this.reset.bind(this)}get thread(){return this._thread}switchToNewThread(){return this._core.threads.switchToNewThread()}switchToThread(n){return this._core.threads.switchToThread(n)}registerModelContextProvider(n){return this._core.registerModelContextProvider(n)}registerModelConfigProvider(n){return this.registerModelContextProvider(n)}reset({initialMessages:n}={}){return this._core.threads.getMainThreadRuntimeCore().import(is.fromArray(n??[]))}};function pl(n){return n.filter(i=>i.finishReason==="stop"?i.text!==null&&i.text.trim()!=="":!0)}function Po(n){const i=[];let r=null;for(const h of n)if(h.type!=="transaction")if(h.file){r&&(i.push(r),r=null),i.push(h);continue}else h.functionCalls?(r&&i.push(r),i.push(h),r=null):h.functionResponse?i[i.length-1]={...i[i.length-1],functionResponse:h.functionResponse}:r&&h.type===r.type&&h.protocol===r.protocol&&r.role===h.role?(r.text+=h.text,r.file=r.file||h.file):(r&&i.push(r),r={...h,text:h.file?"":h.text,finishReason:h.file?void 0:h.finishReason});return r&&i.push(r),pl(i)}function gl(n){var r;const i=n.file?[{type:"file",data:n.file.url,mimeType:n.file.contentType}]:[];return n.role==="function"?{id:n.id,role:"assistant",status:(n==null?void 0:n.functionResponse)===null?{type:"running"}:{type:"complete",reason:"stop"},content:((r=n.functionCalls)==null?void 0:r.map(a=>{var h;return{type:"tool-call",toolName:a.name,toolCallId:a.id,args:a.args,result:(h=n.functionResponse)==null?void 0:h.result}}))??[]}:{id:n.id,role:n.role,content:n.type==="reasoning"?[{type:"reasoning",text:n.text},...i]:[{type:"text",text:n.text},...i]}}class Cn{constructor(){S(this,"statusChangeCallbacks",[]);S(this,"messageCallbacks",[])}addStatusChangeListener(i){this.statusChangeCallbacks.push(i)}addPacketListener(i){this.messageCallbacks.push(i)}async syncSession(i){this.session=i}async notifyPacket(i){this.messageCallbacks.forEach(r=>r(i))}async notifyPackets(i){i.forEach(r=>{this.messageCallbacks.forEach(a=>a(r))})}async setSession(i){this.session=i}async setStatus(i){const r=this.status!==i;this.status=i,r&&this.statusChangeCallbacks.forEach(a=>a(i))}clearListeners(){this.statusChangeCallbacks=[],this.messageCallbacks=[]}onTransaction(i){}}class _s extends Cn{constructor(r){super();S(this,"status");S(this,"autostart");S(this,"session");S(this,"config");S(this,"notify",!0);S(this,"context",{});S(this,"tools",[]);this.config=r,this.status="disconnected",this.autostart=!0}getName(){return"rest"}getPriority(){return 100}async connect(r){return this.setStatus("connected"),r}async disconnect(){this.setStatus("disconnected"),this.session=null}async syncSession(r){this.session=r}async sendPacket(r){var w,I,P,C,A;const{apiUrl:a,apiKey:h,agentId:f}=this.config,p=this.session??"new";if(r.type==="command"&&((w=r==null?void 0:r.payload)==null?void 0:w.command)=="set_initial_context"){this.context=(I=r==null?void 0:r.payload)==null?void 0:I.arguments;return}else if(r.type==="command"&&((P=r==null?void 0:r.payload)==null?void 0:P.command)=="set_local_tools"){const R=(C=r==null?void 0:r.payload)==null?void 0:C.arguments.tools;(R==null?void 0:R.length)>0&&this.notifyPacket({type:"message",payload:{type:"text",role:"assistant",text:"Local tools with rest protocol are not supported."}});return}const m=r.payload;try{const K=await(await fetch(`${a}/sessions/${p}/messages`,{body:JSON.stringify({agentId:f,userMessage:m,initialContext:this.context,tools:this.tools}),method:"POST",headers:{"Content-Type":"application/json","x-persona-apikey":h}})).json();this.notifyPackets(K.response.messages.map(At=>({type:"message",payload:At})))}catch(R){this.notifyPacket({type:"message",payload:{role:"assistant",type:"text",text:"An error occurred while processing your request. Please try again later."}}),(A=this.config.logger)==null||A.error("Error sending packet:",R)}}}class bs extends Cn{constructor(r){super();S(this,"status");S(this,"autostart");S(this,"session");S(this,"config");S(this,"webSocket");this.config=r,this.status="disconnected",this.autostart=!0,this.session=null,this.webSocket=null}getName(){return"websocket"}getPriority(){return 500}async syncSession(r){var a;(a=this.config.logger)==null||a.debug("Syncing session with WebSocket protocol:",r),this.session=r,this.webSocket&&this.status==="connected"&&(this.disconnect(),this.connect(r))}connect(r){var m;if(this.webSocket!==null&&this.status==="connected")return Promise.resolve(this.session);const a=r||this.session||"new";(m=this.config.logger)==null||m.debug("Connecting to WebSocket with sessionId:",a);const h=encodeURIComponent(this.config.apiKey),f=this.config.agentId,p=`${this.config.webSocketUrl}?sessionCode=${a}&agentId=${f}&apiKey=${h}`;return this.setStatus("connecting"),this.webSocket=new WebSocket(p),this.webSocket.addEventListener("open",()=>{this.setStatus("connected")}),this.webSocket.addEventListener("message",w=>{const I=JSON.parse(w.data);this.notifyPacket(I)}),this.webSocket.addEventListener("close",w=>{var I;this.setStatus("disconnected"),this.webSocket=null,w.code!==1e3&&(this.notifyPacket({type:"message",payload:{role:"assistant",type:"text",text:"Oops! The connection to the server was lost. Please try again later."}}),(I=this.config.logger)==null||I.warn("WebSocket connection closed"))}),this.webSocket.addEventListener("error",()=>{var w;this.setStatus("disconnected"),this.webSocket=null,(w=this.config.logger)==null||w.error("WebSocket connection error")}),Promise.resolve(a)}disconnect(){var r;return(r=this.config.logger)==null||r.debug("Disconnecting WebSocket"),this.webSocket&&this.status==="connected"&&(this.webSocket.close(),this.setStatus("disconnected"),this.webSocket=null),Promise.resolve()}sendPacket(r){return this.webSocket&&this.status==="connected"?(this.webSocket.send(JSON.stringify(r)),Promise.resolve()):Promise.reject(new Error("WebSocket is not connected"))}}class _l{constructor(i){S(this,"config");S(this,"pc",null);S(this,"ws",null);S(this,"localStream",null);S(this,"remoteStream",new MediaStream);S(this,"audioCtx",null);S(this,"localAnalyser",null);S(this,"remoteAnalyser",null);S(this,"analyzerFrame",null);S(this,"dataChannel",null);S(this,"isConnected",!1);S(this,"visualizerCallbacks",[]);S(this,"messageCallbacks",[]);S(this,"errorCallbacks",[]);S(this,"queuedMessages",[]);this.config=i}async connect(i){var a;if(this.isConnected)return;this.isConnected=!0;try{this.localStream=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(h){(a=this.config.logger)==null||a.error("Error accessing microphone:",h);return}this.pc=new RTCPeerConnection({iceServers:this.config.iceServers||[{urls:"stun:34.38.108.251:3478"},{urls:"turn:34.38.108.251:3478",username:"webrtc",credential:"webrtc"}]}),this.localStream.getTracks().forEach(h=>{this.pc.addTrack(h,this.localStream)}),this.pc.ontrack=h=>{h.streams[0].getTracks().forEach(p=>{this.remoteStream.addTrack(p)}),this.audioCtx||this._startAnalyzers();const f=new Audio;f.srcObject=this.remoteStream,f.play().catch(p=>{var m;(m=this.config.logger)==null||m.error("Error playing remote audio:",p)})},this.pc.onicecandidate=h=>{var f;h.candidate&&((f=this.ws)==null?void 0:f.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"CANDIDATE",src:"client",payload:{candidate:h.candidate}}))},this.pc.ondatachannel=h=>{const f=h.channel;f.onmessage=p=>{this.messageCallbacks.forEach(m=>{m(p)})},f.onopen=()=>{var p;for(;this.queuedMessages.length>0;){const m=this.queuedMessages.shift();m&&(f.send(JSON.stringify(m)),(p=this.config.logger)==null||p.info("Sent queued message:",m))}}};const r=this.config.webrtcUrl||"wss://persona.applica.guru/api/webrtc";this.ws=new WebSocket(`${r}?apiKey=${encodeURIComponent(this.config.apiKey)}`),this.ws.onopen=async()=>{var m,w;const h=await this.pc.createOffer();await this.pc.setLocalDescription(h);const f={apiKey:this.config.apiKey,agentId:this.config.agentId,sessionCode:i};(m=this.config.logger)==null||m.debug("Opening connection to WebRTC server: ",f);const p={type:"OFFER",src:((w=crypto.randomUUID)==null?void 0:w.call(crypto))||"client_"+Date.now(),payload:{sdp:{sdp:h.sdp,type:h.type},connectionId:(Date.now()%1e6).toString(),metadata:f}};this.ws.send(JSON.stringify(p))},this.ws.onmessage=async h=>{var p;const f=JSON.parse(h.data);if(f.type==="ANSWER")await this.pc.setRemoteDescription(new RTCSessionDescription(f.payload.sdp));else if(f.type==="CANDIDATE")try{await this.pc.addIceCandidate(new RTCIceCandidate(f.payload.candidate))}catch(m){(p=this.config.logger)==null||p.error("Error adding ICE candidate:",m)}},this.ws.onclose=h=>{h.code!==1e3&&this.errorCallbacks.forEach(f=>{f("Oops! The connection to the server was lost. Please try again later.")}),this._stopAnalyzers()}}async disconnect(){var i;this.isConnected&&(this.isConnected=!1,((i=this.ws)==null?void 0:i.readyState)===WebSocket.OPEN&&this.ws.close(),this.pc&&this.pc.close(),this.localStream&&this.localStream.getTracks().forEach(r=>r.stop()),this.remoteStream=new MediaStream,this.audioCtx&&(await this.audioCtx.close(),this.audioCtx=null),this._stopAnalyzers())}addVisualizerCallback(i){this.visualizerCallbacks.push(i)}addMessageCallback(i){this.messageCallbacks.push(i)}addErrorCallback(i){this.errorCallbacks.push(i)}createDataChannel(i="messages"){this.pc&&(this.dataChannel=this.pc.createDataChannel(i),this.dataChannel.onopen=()=>{var r,a;for((r=this.config.logger)==null||r.info("Data channel opened");this.queuedMessages.length>0;){const h=this.queuedMessages.shift();h&&(this.dataChannel.send(JSON.stringify(h)),(a=this.config.logger)==null||a.info("Sent queued message:",h))}},this.dataChannel.onmessage=r=>{this.messageCallbacks.forEach(a=>{a(r)})})}sendPacket(i){var r;if(!this.dataChannel||this.dataChannel.readyState!=="open"){this.queuedMessages.push(i);return}this.dataChannel.send(JSON.stringify(i)),(r=this.config.logger)==null||r.info("Sent message:",i)}_startAnalyzers(){if(!this.localStream||!this.remoteStream||this.visualizerCallbacks.length===0)return;this.audioCtx=new(window.AudioContext||window.webkitAudioContext);const i=this.audioCtx.createMediaStreamSource(this.localStream),r=this.audioCtx.createMediaStreamSource(this.remoteStream);this.localAnalyser=this.audioCtx.createAnalyser(),this.remoteAnalyser=this.audioCtx.createAnalyser(),this.localAnalyser.fftSize=256,this.remoteAnalyser.fftSize=256,i.connect(this.localAnalyser),r.connect(this.remoteAnalyser);const a=()=>{if(!this.localAnalyser||!this.remoteAnalyser||this.visualizerCallbacks.length===0)return;const h=new Uint8Array(this.localAnalyser.frequencyBinCount),f=new Uint8Array(this.remoteAnalyser.frequencyBinCount);this.localAnalyser.getByteFrequencyData(h),this.remoteAnalyser.getByteFrequencyData(f);const p=h.reduce((w,I)=>w+I,0)/h.length,m=f.reduce((w,I)=>w+I,0)/f.length;this.visualizerCallbacks.length>0&&this.visualizerCallbacks.forEach(w=>{w({localAmplitude:p,remoteAmplitude:m})}),this.analyzerFrame=requestAnimationFrame(a)};this.analyzerFrame=requestAnimationFrame(a)}_stopAnalyzers(){this.analyzerFrame&&(cancelAnimationFrame(this.analyzerFrame),this.analyzerFrame=null),this.localAnalyser=null,this.remoteAnalyser=null}}class ms extends Cn{constructor(r){super();S(this,"status");S(this,"session");S(this,"autostart");S(this,"config");S(this,"webRTCClient");this.config=r,this.status="disconnected",this.session=null,this.autostart=(r==null?void 0:r.autostart)??!1,this.webRTCClient=new _l(r),this.webRTCClient.addMessageCallback(a=>{const h=JSON.parse(a.data);this.notifyPacket(h)}),this.webRTCClient.addErrorCallback(a=>{var h;(h=this.config.logger)==null||h.error("WebRTC error:",a),this.notifyPacket({type:"message",payload:{type:"text",role:"assistant",text:a}})})}getName(){return"webrtc"}getPriority(){return 1e3}async syncSession(r){super.syncSession(r),this.status==="connected"&&(await this.disconnect(),await this.connect(r))}async connect(r){var a;return this.status==="connected"?Promise.resolve(this.session):(this.session=r||this.session||"new",this.setStatus("connecting"),(a=this.config.logger)==null||a.debug("Connecting to WebRTC with sessionId:",this.session),await this.webRTCClient.connect(this.session),this.setStatus("connected"),await this.webRTCClient.createDataChannel(),this.session)}async disconnect(){var r,a,h;if(this.status==="disconnected")return(r=this.config.logger)==null||r.warn("Already disconnected"),Promise.resolve();await this.webRTCClient.disconnect(),this.setStatus("disconnected"),(h=(a=this.config)==null?void 0:a.logger)==null||h.debug("Disconnected from WebRTC")}sendPacket(r){return this.status!=="connected"?Promise.reject(new Error("Not connected")):(this.webRTCClient.sendPacket(r),Promise.resolve())}}var ir={exports:{}};/**
1
+ (function(H,vt){typeof exports=="object"&&typeof module<"u"?vt(exports,require("react/jsx-runtime"),require("react"),require("@assistant-ui/react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@assistant-ui/react"],vt):(H=typeof globalThis<"u"?globalThis:H||self,vt(H.personaSDK={},H.React,H.React,H.AssistantUI))})(this,function(H,vt,J,Ee){"use strict";var u_=Object.defineProperty;var s_=(H,vt,J)=>vt in H?u_(H,vt,{enumerable:!0,configurable:!0,writable:!0,value:J}):H[vt]=J;var D=(H,vt,J)=>s_(H,typeof vt!="symbol"?vt+"":vt,J);let No=0;function Uo(){return`msg_${Date.now()}_${No++}`}function Bo(d){return d.thought&&(d={...d,type:"reasoning"}),d.id?d.createdAt?d:{...d,createdAt:new Date}:{...d,id:Uo(),createdAt:d.createdAt||new Date}}function Mo(d){return d.filter(f=>f.finishReason==="stop"?f.text!==null&&f.text.trim()!=="":!0)}function $n(d){const f=[];let i=null;for(let _ of d)if(_=Bo(_),_.type!=="transaction")if(_.file){i&&(f.push(i),i=null),f.push(_);continue}else _.functionCalls?(i&&f.push(i),f.push(_),i=null):_.functionResponse?f[f.length-1]={...f[f.length-1],functionResponse:_.functionResponse}:i&&_.type===i.type&&_.protocol===i.protocol&&i.role===_.role&&(_.id===i.id||!i.finishReason)?(i.text+=_.text,i.file=i.file||_.file,i.finishReason=_.finishReason||i.finishReason,i.id=i.id||_.id):(i&&f.push(i),i={..._,text:_.file?"":_.text,finishReason:_.file?void 0:_.finishReason});return i&&f.push(i),Mo(f)}function $o(d){var _,v,S;const f=d.file?[{type:"file",data:d.file.url,mimeType:d.file.contentType}]:[];let i;if((d.role==="assistant"||d.role==="function")&&(d.status?i=d.status:d.finishReason==="stop"?i={type:"complete",reason:"stop"}:d.finishReason==="function_call"?i={type:"complete",reason:"stop"}:d.finishReason||(i=void 0)),d.role==="function"){const E={id:d.id,role:"assistant",createdAt:d.createdAt,content:((_=d.functionCalls)==null?void 0:_.map(C=>{var M;return{type:"tool-call",toolName:C.name,toolCallId:C.id||`tool_${Date.now()}`,args:C.args,result:(M=d.functionResponse)==null?void 0:M.result}}))??[],metadata:{...d.metadata,custom:{protocol:d.protocol,sessionId:d.sessionId,sources:d.sources,...(v=d.metadata)==null?void 0:v.custom}}};return i?{...E,status:i}:E}const p={id:d.id,role:d.role,createdAt:d.createdAt,content:d.type==="reasoning"?[{type:"reasoning",text:d.text},...f]:[{type:"text",text:d.text},...f],metadata:{...d.metadata,custom:{protocol:d.protocol,sessionId:d.sessionId,sources:d.sources,type:d.type,...(S=d.metadata)==null?void 0:S.custom}}};return d.role==="assistant"&&i?{...p,status:i}:p}class ue{constructor(){D(this,"statusChangeCallbacks",[]);D(this,"messageCallbacks",[])}addStatusChangeListener(f){this.statusChangeCallbacks.push(f)}addPacketListener(f){this.messageCallbacks.push(f)}async syncSession(f){this.session=f}async notifyPacket(f){this.messageCallbacks.forEach(i=>i(f))}async notifyPackets(f){f.forEach(i=>{this.messageCallbacks.forEach(p=>p(i))})}async setSession(f){this.session=f}async setStatus(f){const i=this.status!==f;this.status=f,i&&this.statusChangeCallbacks.forEach(p=>p(f))}clearListeners(){this.statusChangeCallbacks=[],this.messageCallbacks=[]}onTransaction(f){}}class Pr extends ue{constructor(i){super();D(this,"status");D(this,"autostart");D(this,"session");D(this,"config");D(this,"notify",!0);D(this,"context",{});D(this,"tools",[]);this.config=i,this.status="disconnected",this.autostart=!0}getName(){return"rest"}getPriority(){return 100}async connect(i){return this.setStatus("connected"),i}async disconnect(){this.setStatus("disconnected"),this.session=null}async syncSession(i){this.session=i}async sendPacket(i){var C,M,R,P,T;const{apiUrl:p,apiKey:_,agentId:v}=this.config,S=this.session??"new";if(i.type==="command"&&((C=i==null?void 0:i.payload)==null?void 0:C.command)=="set_initial_context"){this.context=(M=i==null?void 0:i.payload)==null?void 0:M.arguments;return}else if(i.type==="command"&&((R=i==null?void 0:i.payload)==null?void 0:R.command)=="set_local_tools"){const F=(P=i==null?void 0:i.payload)==null?void 0:P.arguments.tools;(F==null?void 0:F.length)>0&&this.notifyPacket({type:"message",payload:{type:"text",role:"assistant",text:"Local tools with rest protocol are not supported."}});return}const E=i.payload;try{const Y=await(await fetch(`${p}/sessions/${S}/messages`,{body:JSON.stringify({agentId:v,userMessage:E,initialContext:this.context,tools:this.tools}),method:"POST",headers:{"Content-Type":"application/json","x-persona-apikey":_}})).json();this.notifyPackets(Y.response.messages.map(q=>({type:"message",payload:q})))}catch(F){this.notifyPacket({type:"message",payload:{role:"assistant",type:"text",text:"An error occurred while processing your request. Please try again later."}}),(T=this.config.logger)==null||T.error("Error sending packet:",F)}}}class Ir extends ue{constructor(i){super();D(this,"status");D(this,"autostart");D(this,"session");D(this,"config");D(this,"webSocket");this.config=i,this.status="disconnected",this.autostart=!0,this.session=null,this.webSocket=null}getName(){return"websocket"}getPriority(){return 500}async syncSession(i){var p;(p=this.config.logger)==null||p.debug("Syncing session with WebSocket protocol:",i),this.session=i,this.webSocket&&this.status==="connected"&&(this.disconnect(),this.connect(i))}connect(i){var C;if(this.webSocket!==null&&this.status==="connected")return Promise.resolve(this.session);const p=i||this.session||"new";(C=this.config.logger)==null||C.debug("Connecting to WebSocket with sessionId:",p);const _=encodeURIComponent(this.config.apiKey),v=this.config.agentId,S=this.config.userId||"anonymous",E=`${this.config.webSocketUrl}?sessionCode=${p}&agentId=${v}&apiKey=${_}&userId=${encodeURIComponent(S)}`;return this.setStatus("connecting"),this.webSocket=new WebSocket(E),this.webSocket.addEventListener("open",()=>{this.setStatus("connected")}),this.webSocket.addEventListener("message",M=>{const R=JSON.parse(M.data);this.notifyPacket(R)}),this.webSocket.addEventListener("close",M=>{var R;this.setStatus("disconnected"),this.webSocket=null,M.code!==1e3&&(this.notifyPacket({type:"message",payload:{role:"assistant",type:"text",text:"Oops! The connection to the server was lost. Please try again later."}}),(R=this.config.logger)==null||R.warn("WebSocket connection closed"))}),this.webSocket.addEventListener("error",()=>{var M;this.setStatus("disconnected"),this.webSocket=null,(M=this.config.logger)==null||M.error("WebSocket connection error")}),Promise.resolve(p)}disconnect(){var i;return(i=this.config.logger)==null||i.debug("Disconnecting WebSocket"),this.webSocket&&this.status==="connected"&&(this.webSocket.close(1e3,"Normal closure"),this.setStatus("disconnected"),this.webSocket=null),Promise.resolve()}sendPacket(i){return this.webSocket&&this.status==="connected"?(this.webSocket.send(JSON.stringify(i)),Promise.resolve()):Promise.reject(new Error("WebSocket is not connected"))}}class Ko{constructor(f){D(this,"config");D(this,"pc",null);D(this,"ws",null);D(this,"localStream",null);D(this,"remoteStream",new MediaStream);D(this,"audioCtx",null);D(this,"localAnalyser",null);D(this,"remoteAnalyser",null);D(this,"analyzerFrame",null);D(this,"dataChannel",null);D(this,"isConnected",!1);D(this,"visualizerCallbacks",[]);D(this,"messageCallbacks",[]);D(this,"errorCallbacks",[]);D(this,"queuedMessages",[]);this.config=f}async connect(f){var p;if(this.isConnected)return;this.isConnected=!0;try{this.localStream=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(_){(p=this.config.logger)==null||p.error("Error accessing microphone:",_);return}this.pc=new RTCPeerConnection({iceServers:this.config.iceServers||[{urls:"stun:34.38.108.251:3478"},{urls:"turn:34.38.108.251:3478",username:"webrtc",credential:"webrtc"}]}),this.localStream.getTracks().forEach(_=>{this.pc.addTrack(_,this.localStream)}),this.pc.ontrack=_=>{_.streams[0].getTracks().forEach(S=>{this.remoteStream.addTrack(S)}),this.audioCtx||this._startAnalyzers();const v=new Audio;v.srcObject=this.remoteStream,v.play().catch(S=>{var E;(E=this.config.logger)==null||E.error("Error playing remote audio:",S)})},this.pc.onicecandidate=_=>{var v;_.candidate&&((v=this.ws)==null?void 0:v.readyState)===WebSocket.OPEN&&this.ws.send(JSON.stringify({type:"CANDIDATE",src:"client",payload:{candidate:_.candidate}}))},this.pc.ondatachannel=_=>{const v=_.channel;v.onmessage=S=>{this.messageCallbacks.forEach(E=>{E(S)})},v.onopen=()=>{var S;for(;this.queuedMessages.length>0;){const E=this.queuedMessages.shift();E&&(v.send(JSON.stringify(E)),(S=this.config.logger)==null||S.info("Sent queued message:",E))}}};const i=this.config.webrtcUrl||"wss://persona.applica.guru/api/webrtc";this.ws=new WebSocket(`${i}?apiKey=${encodeURIComponent(this.config.apiKey)}`),this.ws.onopen=async()=>{var E,C;const _=await this.pc.createOffer();await this.pc.setLocalDescription(_);const v={apiKey:this.config.apiKey,agentId:this.config.agentId,userId:this.config.userId||"anonymous",sessionCode:f};(E=this.config.logger)==null||E.debug("Opening connection to WebRTC server: ",v);const S={type:"OFFER",src:((C=crypto.randomUUID)==null?void 0:C.call(crypto))||"client_"+Date.now(),payload:{sdp:{sdp:_.sdp,type:_.type},connectionId:(Date.now()%1e6).toString(),metadata:v}};this.ws.send(JSON.stringify(S))},this.ws.onmessage=async _=>{var S;const v=JSON.parse(_.data);if(v.type==="ANSWER")await this.pc.setRemoteDescription(new RTCSessionDescription(v.payload.sdp));else if(v.type==="CANDIDATE")try{await this.pc.addIceCandidate(new RTCIceCandidate(v.payload.candidate))}catch(E){(S=this.config.logger)==null||S.error("Error adding ICE candidate:",E)}},this.ws.onclose=_=>{_.code!==1e3&&this.errorCallbacks.forEach(v=>{v("Oops! The connection to the server was lost. Please try again later.")}),this._stopAnalyzers()}}async disconnect(){var f;this.isConnected&&(this.isConnected=!1,((f=this.ws)==null?void 0:f.readyState)===WebSocket.OPEN&&this.ws.close(),this.pc&&this.pc.close(),this.localStream&&this.localStream.getTracks().forEach(i=>i.stop()),this.remoteStream=new MediaStream,this.audioCtx&&(await this.audioCtx.close(),this.audioCtx=null),this._stopAnalyzers())}addVisualizerCallback(f){this.visualizerCallbacks.push(f)}addMessageCallback(f){this.messageCallbacks.push(f)}addErrorCallback(f){this.errorCallbacks.push(f)}createDataChannel(f="messages"){this.pc&&(this.dataChannel=this.pc.createDataChannel(f),this.dataChannel.onopen=()=>{var i,p;for((i=this.config.logger)==null||i.info("Data channel opened");this.queuedMessages.length>0;){const _=this.queuedMessages.shift();_&&(this.dataChannel.send(JSON.stringify(_)),(p=this.config.logger)==null||p.info("Sent queued message:",_))}},this.dataChannel.onmessage=i=>{this.messageCallbacks.forEach(p=>{p(i)})})}sendPacket(f){var i;if(!this.dataChannel||this.dataChannel.readyState!=="open"){this.queuedMessages.push(f);return}this.dataChannel.send(JSON.stringify(f)),(i=this.config.logger)==null||i.info("Sent message:",f)}_startAnalyzers(){if(!this.localStream||!this.remoteStream||this.visualizerCallbacks.length===0)return;this.audioCtx=new(window.AudioContext||window.webkitAudioContext);const f=this.audioCtx.createMediaStreamSource(this.localStream),i=this.audioCtx.createMediaStreamSource(this.remoteStream);this.localAnalyser=this.audioCtx.createAnalyser(),this.remoteAnalyser=this.audioCtx.createAnalyser(),this.localAnalyser.fftSize=256,this.remoteAnalyser.fftSize=256,f.connect(this.localAnalyser),i.connect(this.remoteAnalyser);const p=()=>{if(!this.localAnalyser||!this.remoteAnalyser||this.visualizerCallbacks.length===0)return;const _=new Uint8Array(this.localAnalyser.frequencyBinCount),v=new Uint8Array(this.remoteAnalyser.frequencyBinCount);this.localAnalyser.getByteFrequencyData(_),this.remoteAnalyser.getByteFrequencyData(v);const S=_.reduce((C,M)=>C+M,0)/_.length,E=v.reduce((C,M)=>C+M,0)/v.length;this.visualizerCallbacks.length>0&&this.visualizerCallbacks.forEach(C=>{C({localAmplitude:S,remoteAmplitude:E})}),this.analyzerFrame=requestAnimationFrame(p)};this.analyzerFrame=requestAnimationFrame(p)}_stopAnalyzers(){this.analyzerFrame&&(cancelAnimationFrame(this.analyzerFrame),this.analyzerFrame=null),this.localAnalyser=null,this.remoteAnalyser=null}}class Rr extends ue{constructor(i){super();D(this,"status");D(this,"session");D(this,"autostart");D(this,"config");D(this,"webRTCClient");this.config=i,this.status="disconnected",this.session=null,this.autostart=(i==null?void 0:i.autostart)??!1,this.webRTCClient=new Ko(i),this.webRTCClient.addMessageCallback(p=>{const _=JSON.parse(p.data);this.notifyPacket(_)}),this.webRTCClient.addErrorCallback(p=>{var _;(_=this.config.logger)==null||_.error("WebRTC error:",p),this.notifyPacket({type:"message",payload:{type:"text",role:"assistant",text:p}})})}getName(){return"webrtc"}getPriority(){return 1e3}async syncSession(i){super.syncSession(i),this.status==="connected"&&(await this.disconnect(),await this.connect(i))}async connect(i){var p;return this.status==="connected"?Promise.resolve(this.session):(this.session=i||this.session||"new",this.setStatus("connecting"),(p=this.config.logger)==null||p.debug("Connecting to WebRTC with sessionId:",this.session),await this.webRTCClient.connect(this.session),this.setStatus("connected"),await this.webRTCClient.createDataChannel(),this.session)}async disconnect(){var i,p,_;if(this.status==="disconnected")return(i=this.config.logger)==null||i.warn("Already disconnected"),Promise.resolve();await this.webRTCClient.disconnect(),this.setStatus("disconnected"),(_=(p=this.config)==null?void 0:p.logger)==null||_.debug("Disconnected from WebRTC")}sendPacket(i){return this.status!=="connected"?Promise.reject(new Error("Not connected")):(this.webRTCClient.sendPacket(i),Promise.resolve())}}var se=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function qo(d){return d&&d.__esModule&&Object.prototype.hasOwnProperty.call(d,"default")?d.default:d}var Te={exports:{}};/**
14
2
  * @license
15
3
  * Lodash <https://lodash.com/>
16
4
  * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
17
5
  * Released under MIT license <https://lodash.com/license>
18
6
  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
19
7
  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
20
- */ir.exports,function(n,i){(function(){var r,a="4.17.21",h=200,f="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",p="Expected a function",m="Invalid `variable` option passed into `_.template`",w="__lodash_hash_undefined__",I=500,P="__lodash_placeholder__",C=1,A=2,R=4,K=1,At=2,gt=1,ct=2,ar=4,Qt=8,We=16,jt=32,$e=64,q=128,ht=256,Q=512,Ft=30,ft="...",Ut=800,it=16,St=1,Bl=2,kl=3,qe=1/0,Te=9007199254740991,Dl=17976931348623157e292,ur=NaN,ce=4294967295,Nl=ce-1,Fl=ce>>>1,Ul=[["ary",q],["bind",gt],["bindKey",ct],["curry",Qt],["curryRight",We],["flip",Q],["partial",jt],["partialRight",$e],["rearg",ht]],sn="[object Arguments]",cr="[object Array]",Wl="[object AsyncFunction]",Rn="[object Boolean]",Mn="[object Date]",$l="[object DOMException]",hr="[object Error]",lr="[object Function]",Do="[object GeneratorFunction]",te="[object Map]",Pn="[object Number]",ql="[object Null]",de="[object Object]",No="[object Promise]",zl="[object Proxy]",On="[object RegExp]",ee="[object Set]",Ln="[object String]",fr="[object Symbol]",Hl="[object Undefined]",Bn="[object WeakMap]",Jl="[object WeakSet]",kn="[object ArrayBuffer]",on="[object DataView]",vs="[object Float32Array]",ws="[object Float64Array]",ys="[object Int8Array]",Ss="[object Int16Array]",Es="[object Int32Array]",xs="[object Uint8Array]",Ts="[object Uint8ClampedArray]",As="[object Uint16Array]",Cs="[object Uint32Array]",Gl=/\b__p \+= '';/g,Kl=/\b(__p \+=) '' \+/g,Yl=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Fo=/&(?:amp|lt|gt|quot|#39);/g,Uo=/[&<>"']/g,Vl=RegExp(Fo.source),Zl=RegExp(Uo.source),Xl=/<%-([\s\S]+?)%>/g,Ql=/<%([\s\S]+?)%>/g,Wo=/<%=([\s\S]+?)%>/g,jl=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,tf=/^\w*$/,ef=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Is=/[\\^$.*+?()[\]{}|]/g,nf=RegExp(Is.source),Rs=/^\s+/,rf=/\s/,sf=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,of=/\{\n\/\* \[wrapped with (.+)\] \*/,af=/,? & /,uf=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,cf=/[()=,{}\[\]\/\s]/,hf=/\\(\\)?/g,lf=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,$o=/\w*$/,ff=/^[-+]0x[0-9a-f]+$/i,df=/^0b[01]+$/i,pf=/^\[object .+?Constructor\]$/,gf=/^0o[0-7]+$/i,_f=/^(?:0|[1-9]\d*)$/,bf=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,dr=/($^)/,mf=/['\n\r\u2028\u2029\\]/g,pr="\\ud800-\\udfff",vf="\\u0300-\\u036f",wf="\\ufe20-\\ufe2f",yf="\\u20d0-\\u20ff",qo=vf+wf+yf,zo="\\u2700-\\u27bf",Ho="a-z\\xdf-\\xf6\\xf8-\\xff",Sf="\\xac\\xb1\\xd7\\xf7",Ef="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",xf="\\u2000-\\u206f",Tf=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",Jo="A-Z\\xc0-\\xd6\\xd8-\\xde",Go="\\ufe0e\\ufe0f",Ko=Sf+Ef+xf+Tf,Ms="['’]",Af="["+pr+"]",Yo="["+Ko+"]",gr="["+qo+"]",Vo="\\d+",Cf="["+zo+"]",Zo="["+Ho+"]",Xo="[^"+pr+Ko+Vo+zo+Ho+Jo+"]",Ps="\\ud83c[\\udffb-\\udfff]",If="(?:"+gr+"|"+Ps+")",Qo="[^"+pr+"]",Os="(?:\\ud83c[\\udde6-\\uddff]){2}",Ls="[\\ud800-\\udbff][\\udc00-\\udfff]",an="["+Jo+"]",jo="\\u200d",ta="(?:"+Zo+"|"+Xo+")",Rf="(?:"+an+"|"+Xo+")",ea="(?:"+Ms+"(?:d|ll|m|re|s|t|ve))?",na="(?:"+Ms+"(?:D|LL|M|RE|S|T|VE))?",ra=If+"?",sa="["+Go+"]?",Mf="(?:"+jo+"(?:"+[Qo,Os,Ls].join("|")+")"+sa+ra+")*",Pf="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Of="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",ia=sa+ra+Mf,Lf="(?:"+[Cf,Os,Ls].join("|")+")"+ia,Bf="(?:"+[Qo+gr+"?",gr,Os,Ls,Af].join("|")+")",kf=RegExp(Ms,"g"),Df=RegExp(gr,"g"),Bs=RegExp(Ps+"(?="+Ps+")|"+Bf+ia,"g"),Nf=RegExp([an+"?"+Zo+"+"+ea+"(?="+[Yo,an,"$"].join("|")+")",Rf+"+"+na+"(?="+[Yo,an+ta,"$"].join("|")+")",an+"?"+ta+"+"+ea,an+"+"+na,Of,Pf,Vo,Lf].join("|"),"g"),Ff=RegExp("["+jo+pr+qo+Go+"]"),Uf=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Wf=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],$f=-1,et={};et[vs]=et[ws]=et[ys]=et[Ss]=et[Es]=et[xs]=et[Ts]=et[As]=et[Cs]=!0,et[sn]=et[cr]=et[kn]=et[Rn]=et[on]=et[Mn]=et[hr]=et[lr]=et[te]=et[Pn]=et[de]=et[On]=et[ee]=et[Ln]=et[Bn]=!1;var tt={};tt[sn]=tt[cr]=tt[kn]=tt[on]=tt[Rn]=tt[Mn]=tt[vs]=tt[ws]=tt[ys]=tt[Ss]=tt[Es]=tt[te]=tt[Pn]=tt[de]=tt[On]=tt[ee]=tt[Ln]=tt[fr]=tt[xs]=tt[Ts]=tt[As]=tt[Cs]=!0,tt[hr]=tt[lr]=tt[Bn]=!1;var qf={À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"},zf={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Hf={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},Jf={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Gf=parseFloat,Kf=parseInt,oa=typeof oe=="object"&&oe&&oe.Object===Object&&oe,Yf=typeof self=="object"&&self&&self.Object===Object&&self,bt=oa||Yf||Function("return this")(),ks=i&&!i.nodeType&&i,ze=ks&&!0&&n&&!n.nodeType&&n,aa=ze&&ze.exports===ks,Ds=aa&&oa.process,Wt=function(){try{var _=ze&&ze.require&&ze.require("util").types;return _||Ds&&Ds.binding&&Ds.binding("util")}catch{}}(),ua=Wt&&Wt.isArrayBuffer,ca=Wt&&Wt.isDate,ha=Wt&&Wt.isMap,la=Wt&&Wt.isRegExp,fa=Wt&&Wt.isSet,da=Wt&&Wt.isTypedArray;function Ot(_,y,v){switch(v.length){case 0:return _.call(y);case 1:return _.call(y,v[0]);case 2:return _.call(y,v[0],v[1]);case 3:return _.call(y,v[0],v[1],v[2])}return _.apply(y,v)}function Vf(_,y,v,O){for(var F=-1,V=_==null?0:_.length;++F<V;){var dt=_[F];y(O,dt,v(dt),_)}return O}function $t(_,y){for(var v=-1,O=_==null?0:_.length;++v<O&&y(_[v],v,_)!==!1;);return _}function Zf(_,y){for(var v=_==null?0:_.length;v--&&y(_[v],v,_)!==!1;);return _}function pa(_,y){for(var v=-1,O=_==null?0:_.length;++v<O;)if(!y(_[v],v,_))return!1;return!0}function Ae(_,y){for(var v=-1,O=_==null?0:_.length,F=0,V=[];++v<O;){var dt=_[v];y(dt,v,_)&&(V[F++]=dt)}return V}function _r(_,y){var v=_==null?0:_.length;return!!v&&un(_,y,0)>-1}function Ns(_,y,v){for(var O=-1,F=_==null?0:_.length;++O<F;)if(v(y,_[O]))return!0;return!1}function nt(_,y){for(var v=-1,O=_==null?0:_.length,F=Array(O);++v<O;)F[v]=y(_[v],v,_);return F}function Ce(_,y){for(var v=-1,O=y.length,F=_.length;++v<O;)_[F+v]=y[v];return _}function Fs(_,y,v,O){var F=-1,V=_==null?0:_.length;for(O&&V&&(v=_[++F]);++F<V;)v=y(v,_[F],F,_);return v}function Xf(_,y,v,O){var F=_==null?0:_.length;for(O&&F&&(v=_[--F]);F--;)v=y(v,_[F],F,_);return v}function Us(_,y){for(var v=-1,O=_==null?0:_.length;++v<O;)if(y(_[v],v,_))return!0;return!1}var Qf=Ws("length");function jf(_){return _.split("")}function td(_){return _.match(uf)||[]}function ga(_,y,v){var O;return v(_,function(F,V,dt){if(y(F,V,dt))return O=V,!1}),O}function br(_,y,v,O){for(var F=_.length,V=v+(O?1:-1);O?V--:++V<F;)if(y(_[V],V,_))return V;return-1}function un(_,y,v){return y===y?fd(_,y,v):br(_,_a,v)}function ed(_,y,v,O){for(var F=v-1,V=_.length;++F<V;)if(O(_[F],y))return F;return-1}function _a(_){return _!==_}function ba(_,y){var v=_==null?0:_.length;return v?qs(_,y)/v:ur}function Ws(_){return function(y){return y==null?r:y[_]}}function $s(_){return function(y){return _==null?r:_[y]}}function ma(_,y,v,O,F){return F(_,function(V,dt,j){v=O?(O=!1,V):y(v,V,dt,j)}),v}function nd(_,y){var v=_.length;for(_.sort(y);v--;)_[v]=_[v].value;return _}function qs(_,y){for(var v,O=-1,F=_.length;++O<F;){var V=y(_[O]);V!==r&&(v=v===r?V:v+V)}return v}function zs(_,y){for(var v=-1,O=Array(_);++v<_;)O[v]=y(v);return O}function rd(_,y){return nt(y,function(v){return[v,_[v]]})}function va(_){return _&&_.slice(0,Ea(_)+1).replace(Rs,"")}function Lt(_){return function(y){return _(y)}}function Hs(_,y){return nt(y,function(v){return _[v]})}function Dn(_,y){return _.has(y)}function wa(_,y){for(var v=-1,O=_.length;++v<O&&un(y,_[v],0)>-1;);return v}function ya(_,y){for(var v=_.length;v--&&un(y,_[v],0)>-1;);return v}function sd(_,y){for(var v=_.length,O=0;v--;)_[v]===y&&++O;return O}var id=$s(qf),od=$s(zf);function ad(_){return"\\"+Jf[_]}function ud(_,y){return _==null?r:_[y]}function cn(_){return Ff.test(_)}function cd(_){return Uf.test(_)}function hd(_){for(var y,v=[];!(y=_.next()).done;)v.push(y.value);return v}function Js(_){var y=-1,v=Array(_.size);return _.forEach(function(O,F){v[++y]=[F,O]}),v}function Sa(_,y){return function(v){return _(y(v))}}function Ie(_,y){for(var v=-1,O=_.length,F=0,V=[];++v<O;){var dt=_[v];(dt===y||dt===P)&&(_[v]=P,V[F++]=v)}return V}function mr(_){var y=-1,v=Array(_.size);return _.forEach(function(O){v[++y]=O}),v}function ld(_){var y=-1,v=Array(_.size);return _.forEach(function(O){v[++y]=[O,O]}),v}function fd(_,y,v){for(var O=v-1,F=_.length;++O<F;)if(_[O]===y)return O;return-1}function dd(_,y,v){for(var O=v+1;O--;)if(_[O]===y)return O;return O}function hn(_){return cn(_)?gd(_):Qf(_)}function ne(_){return cn(_)?_d(_):jf(_)}function Ea(_){for(var y=_.length;y--&&rf.test(_.charAt(y)););return y}var pd=$s(Hf);function gd(_){for(var y=Bs.lastIndex=0;Bs.test(_);)++y;return y}function _d(_){return _.match(Bs)||[]}function bd(_){return _.match(Nf)||[]}var md=function _(y){y=y==null?bt:ln.defaults(bt.Object(),y,ln.pick(bt,Wf));var v=y.Array,O=y.Date,F=y.Error,V=y.Function,dt=y.Math,j=y.Object,Gs=y.RegExp,vd=y.String,qt=y.TypeError,vr=v.prototype,wd=V.prototype,fn=j.prototype,wr=y["__core-js_shared__"],yr=wd.toString,X=fn.hasOwnProperty,yd=0,xa=function(){var t=/[^.]+$/.exec(wr&&wr.keys&&wr.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Sr=fn.toString,Sd=yr.call(j),Ed=bt._,xd=Gs("^"+yr.call(X).replace(Is,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Er=aa?y.Buffer:r,Re=y.Symbol,xr=y.Uint8Array,Ta=Er?Er.allocUnsafe:r,Tr=Sa(j.getPrototypeOf,j),Aa=j.create,Ca=fn.propertyIsEnumerable,Ar=vr.splice,Ia=Re?Re.isConcatSpreadable:r,Nn=Re?Re.iterator:r,He=Re?Re.toStringTag:r,Cr=function(){try{var t=Ve(j,"defineProperty");return t({},"",{}),t}catch{}}(),Td=y.clearTimeout!==bt.clearTimeout&&y.clearTimeout,Ad=O&&O.now!==bt.Date.now&&O.now,Cd=y.setTimeout!==bt.setTimeout&&y.setTimeout,Ir=dt.ceil,Rr=dt.floor,Ks=j.getOwnPropertySymbols,Id=Er?Er.isBuffer:r,Ra=y.isFinite,Rd=vr.join,Md=Sa(j.keys,j),pt=dt.max,vt=dt.min,Pd=O.now,Od=y.parseInt,Ma=dt.random,Ld=vr.reverse,Ys=Ve(y,"DataView"),Fn=Ve(y,"Map"),Vs=Ve(y,"Promise"),dn=Ve(y,"Set"),Un=Ve(y,"WeakMap"),Wn=Ve(j,"create"),Mr=Un&&new Un,pn={},Bd=Ze(Ys),kd=Ze(Fn),Dd=Ze(Vs),Nd=Ze(dn),Fd=Ze(Un),Pr=Re?Re.prototype:r,$n=Pr?Pr.valueOf:r,Pa=Pr?Pr.toString:r;function c(t){if(ot(t)&&!U(t)&&!(t instanceof J)){if(t instanceof zt)return t;if(X.call(t,"__wrapped__"))return Ou(t)}return new zt(t)}var gn=function(){function t(){}return function(e){if(!st(e))return{};if(Aa)return Aa(e);t.prototype=e;var s=new t;return t.prototype=r,s}}();function Or(){}function zt(t,e){this.__wrapped__=t,this.__actions__=[],this.__chain__=!!e,this.__index__=0,this.__values__=r}c.templateSettings={escape:Xl,evaluate:Ql,interpolate:Wo,variable:"",imports:{_:c}},c.prototype=Or.prototype,c.prototype.constructor=c,zt.prototype=gn(Or.prototype),zt.prototype.constructor=zt;function J(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=ce,this.__views__=[]}function Ud(){var t=new J(this.__wrapped__);return t.__actions__=Ct(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=Ct(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=Ct(this.__views__),t}function Wd(){if(this.__filtered__){var t=new J(this);t.__dir__=-1,t.__filtered__=!0}else t=this.clone(),t.__dir__*=-1;return t}function $d(){var t=this.__wrapped__.value(),e=this.__dir__,s=U(t),o=e<0,u=s?t.length:0,l=jp(0,u,this.__views__),d=l.start,g=l.end,b=g-d,E=o?g:d-1,x=this.__iteratees__,T=x.length,M=0,L=vt(b,this.__takeCount__);if(!s||!o&&u==b&&L==b)return eu(t,this.__actions__);var D=[];t:for(;b--&&M<L;){E+=e;for(var $=-1,N=t[E];++$<T;){var H=x[$],G=H.iteratee,Dt=H.type,Tt=G(N);if(Dt==Bl)N=Tt;else if(!Tt){if(Dt==St)continue t;break t}}D[M++]=N}return D}J.prototype=gn(Or.prototype),J.prototype.constructor=J;function Je(t){var e=-1,s=t==null?0:t.length;for(this.clear();++e<s;){var o=t[e];this.set(o[0],o[1])}}function qd(){this.__data__=Wn?Wn(null):{},this.size=0}function zd(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e}function Hd(t){var e=this.__data__;if(Wn){var s=e[t];return s===w?r:s}return X.call(e,t)?e[t]:r}function Jd(t){var e=this.__data__;return Wn?e[t]!==r:X.call(e,t)}function Gd(t,e){var s=this.__data__;return this.size+=this.has(t)?0:1,s[t]=Wn&&e===r?w:e,this}Je.prototype.clear=qd,Je.prototype.delete=zd,Je.prototype.get=Hd,Je.prototype.has=Jd,Je.prototype.set=Gd;function pe(t){var e=-1,s=t==null?0:t.length;for(this.clear();++e<s;){var o=t[e];this.set(o[0],o[1])}}function Kd(){this.__data__=[],this.size=0}function Yd(t){var e=this.__data__,s=Lr(e,t);if(s<0)return!1;var o=e.length-1;return s==o?e.pop():Ar.call(e,s,1),--this.size,!0}function Vd(t){var e=this.__data__,s=Lr(e,t);return s<0?r:e[s][1]}function Zd(t){return Lr(this.__data__,t)>-1}function Xd(t,e){var s=this.__data__,o=Lr(s,t);return o<0?(++this.size,s.push([t,e])):s[o][1]=e,this}pe.prototype.clear=Kd,pe.prototype.delete=Yd,pe.prototype.get=Vd,pe.prototype.has=Zd,pe.prototype.set=Xd;function ge(t){var e=-1,s=t==null?0:t.length;for(this.clear();++e<s;){var o=t[e];this.set(o[0],o[1])}}function Qd(){this.size=0,this.__data__={hash:new Je,map:new(Fn||pe),string:new Je}}function jd(t){var e=Jr(this,t).delete(t);return this.size-=e?1:0,e}function tp(t){return Jr(this,t).get(t)}function ep(t){return Jr(this,t).has(t)}function np(t,e){var s=Jr(this,t),o=s.size;return s.set(t,e),this.size+=s.size==o?0:1,this}ge.prototype.clear=Qd,ge.prototype.delete=jd,ge.prototype.get=tp,ge.prototype.has=ep,ge.prototype.set=np;function Ge(t){var e=-1,s=t==null?0:t.length;for(this.__data__=new ge;++e<s;)this.add(t[e])}function rp(t){return this.__data__.set(t,w),this}function sp(t){return this.__data__.has(t)}Ge.prototype.add=Ge.prototype.push=rp,Ge.prototype.has=sp;function re(t){var e=this.__data__=new pe(t);this.size=e.size}function ip(){this.__data__=new pe,this.size=0}function op(t){var e=this.__data__,s=e.delete(t);return this.size=e.size,s}function ap(t){return this.__data__.get(t)}function up(t){return this.__data__.has(t)}function cp(t,e){var s=this.__data__;if(s instanceof pe){var o=s.__data__;if(!Fn||o.length<h-1)return o.push([t,e]),this.size=++s.size,this;s=this.__data__=new ge(o)}return s.set(t,e),this.size=s.size,this}re.prototype.clear=ip,re.prototype.delete=op,re.prototype.get=ap,re.prototype.has=up,re.prototype.set=cp;function Oa(t,e){var s=U(t),o=!s&&Xe(t),u=!s&&!o&&Be(t),l=!s&&!o&&!u&&vn(t),d=s||o||u||l,g=d?zs(t.length,vd):[],b=g.length;for(var E in t)(e||X.call(t,E))&&!(d&&(E=="length"||u&&(E=="offset"||E=="parent")||l&&(E=="buffer"||E=="byteLength"||E=="byteOffset")||ve(E,b)))&&g.push(E);return g}function La(t){var e=t.length;return e?t[oi(0,e-1)]:r}function hp(t,e){return Gr(Ct(t),Ke(e,0,t.length))}function lp(t){return Gr(Ct(t))}function Zs(t,e,s){(s!==r&&!se(t[e],s)||s===r&&!(e in t))&&_e(t,e,s)}function qn(t,e,s){var o=t[e];(!(X.call(t,e)&&se(o,s))||s===r&&!(e in t))&&_e(t,e,s)}function Lr(t,e){for(var s=t.length;s--;)if(se(t[s][0],e))return s;return-1}function fp(t,e,s,o){return Me(t,function(u,l,d){e(o,u,s(u),d)}),o}function Ba(t,e){return t&&le(e,_t(e),t)}function dp(t,e){return t&&le(e,Rt(e),t)}function _e(t,e,s){e=="__proto__"&&Cr?Cr(t,e,{configurable:!0,enumerable:!0,value:s,writable:!0}):t[e]=s}function Xs(t,e){for(var s=-1,o=e.length,u=v(o),l=t==null;++s<o;)u[s]=l?r:Pi(t,e[s]);return u}function Ke(t,e,s){return t===t&&(s!==r&&(t=t<=s?t:s),e!==r&&(t=t>=e?t:e)),t}function Ht(t,e,s,o,u,l){var d,g=e&C,b=e&A,E=e&R;if(s&&(d=u?s(t,o,u,l):s(t)),d!==r)return d;if(!st(t))return t;var x=U(t);if(x){if(d=eg(t),!g)return Ct(t,d)}else{var T=wt(t),M=T==lr||T==Do;if(Be(t))return su(t,g);if(T==de||T==sn||M&&!u){if(d=b||M?{}:Eu(t),!g)return b?Hp(t,dp(d,t)):zp(t,Ba(d,t))}else{if(!tt[T])return u?t:{};d=ng(t,T,g)}}l||(l=new re);var L=l.get(t);if(L)return L;l.set(t,d),Qu(t)?t.forEach(function(N){d.add(Ht(N,e,s,N,t,l))}):Zu(t)&&t.forEach(function(N,H){d.set(H,Ht(N,e,s,H,t,l))});var D=E?b?bi:_i:b?Rt:_t,$=x?r:D(t);return $t($||t,function(N,H){$&&(H=N,N=t[H]),qn(d,H,Ht(N,e,s,H,t,l))}),d}function pp(t){var e=_t(t);return function(s){return ka(s,t,e)}}function ka(t,e,s){var o=s.length;if(t==null)return!o;for(t=j(t);o--;){var u=s[o],l=e[u],d=t[u];if(d===r&&!(u in t)||!l(d))return!1}return!0}function Da(t,e,s){if(typeof t!="function")throw new qt(p);return Vn(function(){t.apply(r,s)},e)}function zn(t,e,s,o){var u=-1,l=_r,d=!0,g=t.length,b=[],E=e.length;if(!g)return b;s&&(e=nt(e,Lt(s))),o?(l=Ns,d=!1):e.length>=h&&(l=Dn,d=!1,e=new Ge(e));t:for(;++u<g;){var x=t[u],T=s==null?x:s(x);if(x=o||x!==0?x:0,d&&T===T){for(var M=E;M--;)if(e[M]===T)continue t;b.push(x)}else l(e,T,o)||b.push(x)}return b}var Me=cu(he),Na=cu(js,!0);function gp(t,e){var s=!0;return Me(t,function(o,u,l){return s=!!e(o,u,l),s}),s}function Br(t,e,s){for(var o=-1,u=t.length;++o<u;){var l=t[o],d=e(l);if(d!=null&&(g===r?d===d&&!kt(d):s(d,g)))var g=d,b=l}return b}function _p(t,e,s,o){var u=t.length;for(s=W(s),s<0&&(s=-s>u?0:u+s),o=o===r||o>u?u:W(o),o<0&&(o+=u),o=s>o?0:tc(o);s<o;)t[s++]=e;return t}function Fa(t,e){var s=[];return Me(t,function(o,u,l){e(o,u,l)&&s.push(o)}),s}function mt(t,e,s,o,u){var l=-1,d=t.length;for(s||(s=sg),u||(u=[]);++l<d;){var g=t[l];e>0&&s(g)?e>1?mt(g,e-1,s,o,u):Ce(u,g):o||(u[u.length]=g)}return u}var Qs=hu(),Ua=hu(!0);function he(t,e){return t&&Qs(t,e,_t)}function js(t,e){return t&&Ua(t,e,_t)}function kr(t,e){return Ae(e,function(s){return we(t[s])})}function Ye(t,e){e=Oe(e,t);for(var s=0,o=e.length;t!=null&&s<o;)t=t[fe(e[s++])];return s&&s==o?t:r}function Wa(t,e,s){var o=e(t);return U(t)?o:Ce(o,s(t))}function Et(t){return t==null?t===r?Hl:ql:He&&He in j(t)?Qp(t):lg(t)}function ti(t,e){return t>e}function bp(t,e){return t!=null&&X.call(t,e)}function mp(t,e){return t!=null&&e in j(t)}function vp(t,e,s){return t>=vt(e,s)&&t<pt(e,s)}function ei(t,e,s){for(var o=s?Ns:_r,u=t[0].length,l=t.length,d=l,g=v(l),b=1/0,E=[];d--;){var x=t[d];d&&e&&(x=nt(x,Lt(e))),b=vt(x.length,b),g[d]=!s&&(e||u>=120&&x.length>=120)?new Ge(d&&x):r}x=t[0];var T=-1,M=g[0];t:for(;++T<u&&E.length<b;){var L=x[T],D=e?e(L):L;if(L=s||L!==0?L:0,!(M?Dn(M,D):o(E,D,s))){for(d=l;--d;){var $=g[d];if(!($?Dn($,D):o(t[d],D,s)))continue t}M&&M.push(D),E.push(L)}}return E}function wp(t,e,s,o){return he(t,function(u,l,d){e(o,s(u),l,d)}),o}function Hn(t,e,s){e=Oe(e,t),t=Cu(t,e);var o=t==null?t:t[fe(Gt(e))];return o==null?r:Ot(o,t,s)}function $a(t){return ot(t)&&Et(t)==sn}function yp(t){return ot(t)&&Et(t)==kn}function Sp(t){return ot(t)&&Et(t)==Mn}function Jn(t,e,s,o,u){return t===e?!0:t==null||e==null||!ot(t)&&!ot(e)?t!==t&&e!==e:Ep(t,e,s,o,Jn,u)}function Ep(t,e,s,o,u,l){var d=U(t),g=U(e),b=d?cr:wt(t),E=g?cr:wt(e);b=b==sn?de:b,E=E==sn?de:E;var x=b==de,T=E==de,M=b==E;if(M&&Be(t)){if(!Be(e))return!1;d=!0,x=!1}if(M&&!x)return l||(l=new re),d||vn(t)?wu(t,e,s,o,u,l):Zp(t,e,b,s,o,u,l);if(!(s&K)){var L=x&&X.call(t,"__wrapped__"),D=T&&X.call(e,"__wrapped__");if(L||D){var $=L?t.value():t,N=D?e.value():e;return l||(l=new re),u($,N,s,o,l)}}return M?(l||(l=new re),Xp(t,e,s,o,u,l)):!1}function xp(t){return ot(t)&&wt(t)==te}function ni(t,e,s,o){var u=s.length,l=u,d=!o;if(t==null)return!l;for(t=j(t);u--;){var g=s[u];if(d&&g[2]?g[1]!==t[g[0]]:!(g[0]in t))return!1}for(;++u<l;){g=s[u];var b=g[0],E=t[b],x=g[1];if(d&&g[2]){if(E===r&&!(b in t))return!1}else{var T=new re;if(o)var M=o(E,x,b,t,e,T);if(!(M===r?Jn(x,E,K|At,o,T):M))return!1}}return!0}function qa(t){if(!st(t)||og(t))return!1;var e=we(t)?xd:pf;return e.test(Ze(t))}function Tp(t){return ot(t)&&Et(t)==On}function Ap(t){return ot(t)&&wt(t)==ee}function Cp(t){return ot(t)&&Qr(t.length)&&!!et[Et(t)]}function za(t){return typeof t=="function"?t:t==null?Mt:typeof t=="object"?U(t)?Ga(t[0],t[1]):Ja(t):lc(t)}function ri(t){if(!Yn(t))return Md(t);var e=[];for(var s in j(t))X.call(t,s)&&s!="constructor"&&e.push(s);return e}function Ip(t){if(!st(t))return hg(t);var e=Yn(t),s=[];for(var o in t)o=="constructor"&&(e||!X.call(t,o))||s.push(o);return s}function si(t,e){return t<e}function Ha(t,e){var s=-1,o=It(t)?v(t.length):[];return Me(t,function(u,l,d){o[++s]=e(u,l,d)}),o}function Ja(t){var e=vi(t);return e.length==1&&e[0][2]?Tu(e[0][0],e[0][1]):function(s){return s===t||ni(s,t,e)}}function Ga(t,e){return yi(t)&&xu(e)?Tu(fe(t),e):function(s){var o=Pi(s,t);return o===r&&o===e?Oi(s,t):Jn(e,o,K|At)}}function Dr(t,e,s,o,u){t!==e&&Qs(e,function(l,d){if(u||(u=new re),st(l))Rp(t,e,d,s,Dr,o,u);else{var g=o?o(Ei(t,d),l,d+"",t,e,u):r;g===r&&(g=l),Zs(t,d,g)}},Rt)}function Rp(t,e,s,o,u,l,d){var g=Ei(t,s),b=Ei(e,s),E=d.get(b);if(E){Zs(t,s,E);return}var x=l?l(g,b,s+"",t,e,d):r,T=x===r;if(T){var M=U(b),L=!M&&Be(b),D=!M&&!L&&vn(b);x=b,M||L||D?U(g)?x=g:at(g)?x=Ct(g):L?(T=!1,x=su(b,!0)):D?(T=!1,x=iu(b,!0)):x=[]:Zn(b)||Xe(b)?(x=g,Xe(g)?x=ec(g):(!st(g)||we(g))&&(x=Eu(b))):T=!1}T&&(d.set(b,x),u(x,b,o,l,d),d.delete(b)),Zs(t,s,x)}function Ka(t,e){var s=t.length;if(s)return e+=e<0?s:0,ve(e,s)?t[e]:r}function Ya(t,e,s){e.length?e=nt(e,function(l){return U(l)?function(d){return Ye(d,l.length===1?l[0]:l)}:l}):e=[Mt];var o=-1;e=nt(e,Lt(k()));var u=Ha(t,function(l,d,g){var b=nt(e,function(E){return E(l)});return{criteria:b,index:++o,value:l}});return nd(u,function(l,d){return qp(l,d,s)})}function Mp(t,e){return Va(t,e,function(s,o){return Oi(t,o)})}function Va(t,e,s){for(var o=-1,u=e.length,l={};++o<u;){var d=e[o],g=Ye(t,d);s(g,d)&&Gn(l,Oe(d,t),g)}return l}function Pp(t){return function(e){return Ye(e,t)}}function ii(t,e,s,o){var u=o?ed:un,l=-1,d=e.length,g=t;for(t===e&&(e=Ct(e)),s&&(g=nt(t,Lt(s)));++l<d;)for(var b=0,E=e[l],x=s?s(E):E;(b=u(g,x,b,o))>-1;)g!==t&&Ar.call(g,b,1),Ar.call(t,b,1);return t}function Za(t,e){for(var s=t?e.length:0,o=s-1;s--;){var u=e[s];if(s==o||u!==l){var l=u;ve(u)?Ar.call(t,u,1):ci(t,u)}}return t}function oi(t,e){return t+Rr(Ma()*(e-t+1))}function Op(t,e,s,o){for(var u=-1,l=pt(Ir((e-t)/(s||1)),0),d=v(l);l--;)d[o?l:++u]=t,t+=s;return d}function ai(t,e){var s="";if(!t||e<1||e>Te)return s;do e%2&&(s+=t),e=Rr(e/2),e&&(t+=t);while(e);return s}function z(t,e){return xi(Au(t,e,Mt),t+"")}function Lp(t){return La(wn(t))}function Bp(t,e){var s=wn(t);return Gr(s,Ke(e,0,s.length))}function Gn(t,e,s,o){if(!st(t))return t;e=Oe(e,t);for(var u=-1,l=e.length,d=l-1,g=t;g!=null&&++u<l;){var b=fe(e[u]),E=s;if(b==="__proto__"||b==="constructor"||b==="prototype")return t;if(u!=d){var x=g[b];E=o?o(x,b,g):r,E===r&&(E=st(x)?x:ve(e[u+1])?[]:{})}qn(g,b,E),g=g[b]}return t}var Xa=Mr?function(t,e){return Mr.set(t,e),t}:Mt,kp=Cr?function(t,e){return Cr(t,"toString",{configurable:!0,enumerable:!1,value:Bi(e),writable:!0})}:Mt;function Dp(t){return Gr(wn(t))}function Jt(t,e,s){var o=-1,u=t.length;e<0&&(e=-e>u?0:u+e),s=s>u?u:s,s<0&&(s+=u),u=e>s?0:s-e>>>0,e>>>=0;for(var l=v(u);++o<u;)l[o]=t[o+e];return l}function Np(t,e){var s;return Me(t,function(o,u,l){return s=e(o,u,l),!s}),!!s}function Nr(t,e,s){var o=0,u=t==null?o:t.length;if(typeof e=="number"&&e===e&&u<=Fl){for(;o<u;){var l=o+u>>>1,d=t[l];d!==null&&!kt(d)&&(s?d<=e:d<e)?o=l+1:u=l}return u}return ui(t,e,Mt,s)}function ui(t,e,s,o){var u=0,l=t==null?0:t.length;if(l===0)return 0;e=s(e);for(var d=e!==e,g=e===null,b=kt(e),E=e===r;u<l;){var x=Rr((u+l)/2),T=s(t[x]),M=T!==r,L=T===null,D=T===T,$=kt(T);if(d)var N=o||D;else E?N=D&&(o||M):g?N=D&&M&&(o||!L):b?N=D&&M&&!L&&(o||!$):L||$?N=!1:N=o?T<=e:T<e;N?u=x+1:l=x}return vt(l,Nl)}function Qa(t,e){for(var s=-1,o=t.length,u=0,l=[];++s<o;){var d=t[s],g=e?e(d):d;if(!s||!se(g,b)){var b=g;l[u++]=d===0?0:d}}return l}function ja(t){return typeof t=="number"?t:kt(t)?ur:+t}function Bt(t){if(typeof t=="string")return t;if(U(t))return nt(t,Bt)+"";if(kt(t))return Pa?Pa.call(t):"";var e=t+"";return e=="0"&&1/t==-qe?"-0":e}function Pe(t,e,s){var o=-1,u=_r,l=t.length,d=!0,g=[],b=g;if(s)d=!1,u=Ns;else if(l>=h){var E=e?null:Yp(t);if(E)return mr(E);d=!1,u=Dn,b=new Ge}else b=e?[]:g;t:for(;++o<l;){var x=t[o],T=e?e(x):x;if(x=s||x!==0?x:0,d&&T===T){for(var M=b.length;M--;)if(b[M]===T)continue t;e&&b.push(T),g.push(x)}else u(b,T,s)||(b!==g&&b.push(T),g.push(x))}return g}function ci(t,e){return e=Oe(e,t),t=Cu(t,e),t==null||delete t[fe(Gt(e))]}function tu(t,e,s,o){return Gn(t,e,s(Ye(t,e)),o)}function Fr(t,e,s,o){for(var u=t.length,l=o?u:-1;(o?l--:++l<u)&&e(t[l],l,t););return s?Jt(t,o?0:l,o?l+1:u):Jt(t,o?l+1:0,o?u:l)}function eu(t,e){var s=t;return s instanceof J&&(s=s.value()),Fs(e,function(o,u){return u.func.apply(u.thisArg,Ce([o],u.args))},s)}function hi(t,e,s){var o=t.length;if(o<2)return o?Pe(t[0]):[];for(var u=-1,l=v(o);++u<o;)for(var d=t[u],g=-1;++g<o;)g!=u&&(l[u]=zn(l[u]||d,t[g],e,s));return Pe(mt(l,1),e,s)}function nu(t,e,s){for(var o=-1,u=t.length,l=e.length,d={};++o<u;){var g=o<l?e[o]:r;s(d,t[o],g)}return d}function li(t){return at(t)?t:[]}function fi(t){return typeof t=="function"?t:Mt}function Oe(t,e){return U(t)?t:yi(t,e)?[t]:Pu(Z(t))}var Fp=z;function Le(t,e,s){var o=t.length;return s=s===r?o:s,!e&&s>=o?t:Jt(t,e,s)}var ru=Td||function(t){return bt.clearTimeout(t)};function su(t,e){if(e)return t.slice();var s=t.length,o=Ta?Ta(s):new t.constructor(s);return t.copy(o),o}function di(t){var e=new t.constructor(t.byteLength);return new xr(e).set(new xr(t)),e}function Up(t,e){var s=e?di(t.buffer):t.buffer;return new t.constructor(s,t.byteOffset,t.byteLength)}function Wp(t){var e=new t.constructor(t.source,$o.exec(t));return e.lastIndex=t.lastIndex,e}function $p(t){return $n?j($n.call(t)):{}}function iu(t,e){var s=e?di(t.buffer):t.buffer;return new t.constructor(s,t.byteOffset,t.length)}function ou(t,e){if(t!==e){var s=t!==r,o=t===null,u=t===t,l=kt(t),d=e!==r,g=e===null,b=e===e,E=kt(e);if(!g&&!E&&!l&&t>e||l&&d&&b&&!g&&!E||o&&d&&b||!s&&b||!u)return 1;if(!o&&!l&&!E&&t<e||E&&s&&u&&!o&&!l||g&&s&&u||!d&&u||!b)return-1}return 0}function qp(t,e,s){for(var o=-1,u=t.criteria,l=e.criteria,d=u.length,g=s.length;++o<d;){var b=ou(u[o],l[o]);if(b){if(o>=g)return b;var E=s[o];return b*(E=="desc"?-1:1)}}return t.index-e.index}function au(t,e,s,o){for(var u=-1,l=t.length,d=s.length,g=-1,b=e.length,E=pt(l-d,0),x=v(b+E),T=!o;++g<b;)x[g]=e[g];for(;++u<d;)(T||u<l)&&(x[s[u]]=t[u]);for(;E--;)x[g++]=t[u++];return x}function uu(t,e,s,o){for(var u=-1,l=t.length,d=-1,g=s.length,b=-1,E=e.length,x=pt(l-g,0),T=v(x+E),M=!o;++u<x;)T[u]=t[u];for(var L=u;++b<E;)T[L+b]=e[b];for(;++d<g;)(M||u<l)&&(T[L+s[d]]=t[u++]);return T}function Ct(t,e){var s=-1,o=t.length;for(e||(e=v(o));++s<o;)e[s]=t[s];return e}function le(t,e,s,o){var u=!s;s||(s={});for(var l=-1,d=e.length;++l<d;){var g=e[l],b=o?o(s[g],t[g],g,s,t):r;b===r&&(b=t[g]),u?_e(s,g,b):qn(s,g,b)}return s}function zp(t,e){return le(t,wi(t),e)}function Hp(t,e){return le(t,yu(t),e)}function Ur(t,e){return function(s,o){var u=U(s)?Vf:fp,l=e?e():{};return u(s,t,k(o,2),l)}}function _n(t){return z(function(e,s){var o=-1,u=s.length,l=u>1?s[u-1]:r,d=u>2?s[2]:r;for(l=t.length>3&&typeof l=="function"?(u--,l):r,d&&xt(s[0],s[1],d)&&(l=u<3?r:l,u=1),e=j(e);++o<u;){var g=s[o];g&&t(e,g,o,l)}return e})}function cu(t,e){return function(s,o){if(s==null)return s;if(!It(s))return t(s,o);for(var u=s.length,l=e?u:-1,d=j(s);(e?l--:++l<u)&&o(d[l],l,d)!==!1;);return s}}function hu(t){return function(e,s,o){for(var u=-1,l=j(e),d=o(e),g=d.length;g--;){var b=d[t?g:++u];if(s(l[b],b,l)===!1)break}return e}}function Jp(t,e,s){var o=e&gt,u=Kn(t);function l(){var d=this&&this!==bt&&this instanceof l?u:t;return d.apply(o?s:this,arguments)}return l}function lu(t){return function(e){e=Z(e);var s=cn(e)?ne(e):r,o=s?s[0]:e.charAt(0),u=s?Le(s,1).join(""):e.slice(1);return o[t]()+u}}function bn(t){return function(e){return Fs(cc(uc(e).replace(kf,"")),t,"")}}function Kn(t){return function(){var e=arguments;switch(e.length){case 0:return new t;case 1:return new t(e[0]);case 2:return new t(e[0],e[1]);case 3:return new t(e[0],e[1],e[2]);case 4:return new t(e[0],e[1],e[2],e[3]);case 5:return new t(e[0],e[1],e[2],e[3],e[4]);case 6:return new t(e[0],e[1],e[2],e[3],e[4],e[5]);case 7:return new t(e[0],e[1],e[2],e[3],e[4],e[5],e[6])}var s=gn(t.prototype),o=t.apply(s,e);return st(o)?o:s}}function Gp(t,e,s){var o=Kn(t);function u(){for(var l=arguments.length,d=v(l),g=l,b=mn(u);g--;)d[g]=arguments[g];var E=l<3&&d[0]!==b&&d[l-1]!==b?[]:Ie(d,b);if(l-=E.length,l<s)return _u(t,e,Wr,u.placeholder,r,d,E,r,r,s-l);var x=this&&this!==bt&&this instanceof u?o:t;return Ot(x,this,d)}return u}function fu(t){return function(e,s,o){var u=j(e);if(!It(e)){var l=k(s,3);e=_t(e),s=function(g){return l(u[g],g,u)}}var d=t(e,s,o);return d>-1?u[l?e[d]:d]:r}}function du(t){return me(function(e){var s=e.length,o=s,u=zt.prototype.thru;for(t&&e.reverse();o--;){var l=e[o];if(typeof l!="function")throw new qt(p);if(u&&!d&&Hr(l)=="wrapper")var d=new zt([],!0)}for(o=d?o:s;++o<s;){l=e[o];var g=Hr(l),b=g=="wrapper"?mi(l):r;b&&Si(b[0])&&b[1]==(q|Qt|jt|ht)&&!b[4].length&&b[9]==1?d=d[Hr(b[0])].apply(d,b[3]):d=l.length==1&&Si(l)?d[g]():d.thru(l)}return function(){var E=arguments,x=E[0];if(d&&E.length==1&&U(x))return d.plant(x).value();for(var T=0,M=s?e[T].apply(this,E):x;++T<s;)M=e[T].call(this,M);return M}})}function Wr(t,e,s,o,u,l,d,g,b,E){var x=e&q,T=e&gt,M=e&ct,L=e&(Qt|We),D=e&Q,$=M?r:Kn(t);function N(){for(var H=arguments.length,G=v(H),Dt=H;Dt--;)G[Dt]=arguments[Dt];if(L)var Tt=mn(N),Nt=sd(G,Tt);if(o&&(G=au(G,o,u,L)),l&&(G=uu(G,l,d,L)),H-=Nt,L&&H<E){var ut=Ie(G,Tt);return _u(t,e,Wr,N.placeholder,s,G,ut,g,b,E-H)}var ie=T?s:this,Se=M?ie[t]:t;return H=G.length,g?G=fg(G,g):D&&H>1&&G.reverse(),x&&b<H&&(G.length=b),this&&this!==bt&&this instanceof N&&(Se=$||Kn(Se)),Se.apply(ie,G)}return N}function pu(t,e){return function(s,o){return wp(s,t,e(o),{})}}function $r(t,e){return function(s,o){var u;if(s===r&&o===r)return e;if(s!==r&&(u=s),o!==r){if(u===r)return o;typeof s=="string"||typeof o=="string"?(s=Bt(s),o=Bt(o)):(s=ja(s),o=ja(o)),u=t(s,o)}return u}}function pi(t){return me(function(e){return e=nt(e,Lt(k())),z(function(s){var o=this;return t(e,function(u){return Ot(u,o,s)})})})}function qr(t,e){e=e===r?" ":Bt(e);var s=e.length;if(s<2)return s?ai(e,t):e;var o=ai(e,Ir(t/hn(e)));return cn(e)?Le(ne(o),0,t).join(""):o.slice(0,t)}function Kp(t,e,s,o){var u=e&gt,l=Kn(t);function d(){for(var g=-1,b=arguments.length,E=-1,x=o.length,T=v(x+b),M=this&&this!==bt&&this instanceof d?l:t;++E<x;)T[E]=o[E];for(;b--;)T[E++]=arguments[++g];return Ot(M,u?s:this,T)}return d}function gu(t){return function(e,s,o){return o&&typeof o!="number"&&xt(e,s,o)&&(s=o=r),e=ye(e),s===r?(s=e,e=0):s=ye(s),o=o===r?e<s?1:-1:ye(o),Op(e,s,o,t)}}function zr(t){return function(e,s){return typeof e=="string"&&typeof s=="string"||(e=Kt(e),s=Kt(s)),t(e,s)}}function _u(t,e,s,o,u,l,d,g,b,E){var x=e&Qt,T=x?d:r,M=x?r:d,L=x?l:r,D=x?r:l;e|=x?jt:$e,e&=~(x?$e:jt),e&ar||(e&=-4);var $=[t,e,u,L,T,D,M,g,b,E],N=s.apply(r,$);return Si(t)&&Iu(N,$),N.placeholder=o,Ru(N,t,e)}function gi(t){var e=dt[t];return function(s,o){if(s=Kt(s),o=o==null?0:vt(W(o),292),o&&Ra(s)){var u=(Z(s)+"e").split("e"),l=e(u[0]+"e"+(+u[1]+o));return u=(Z(l)+"e").split("e"),+(u[0]+"e"+(+u[1]-o))}return e(s)}}var Yp=dn&&1/mr(new dn([,-0]))[1]==qe?function(t){return new dn(t)}:Ni;function bu(t){return function(e){var s=wt(e);return s==te?Js(e):s==ee?ld(e):rd(e,t(e))}}function be(t,e,s,o,u,l,d,g){var b=e&ct;if(!b&&typeof t!="function")throw new qt(p);var E=o?o.length:0;if(E||(e&=-97,o=u=r),d=d===r?d:pt(W(d),0),g=g===r?g:W(g),E-=u?u.length:0,e&$e){var x=o,T=u;o=u=r}var M=b?r:mi(t),L=[t,e,s,o,u,x,T,l,d,g];if(M&&cg(L,M),t=L[0],e=L[1],s=L[2],o=L[3],u=L[4],g=L[9]=L[9]===r?b?0:t.length:pt(L[9]-E,0),!g&&e&(Qt|We)&&(e&=-25),!e||e==gt)var D=Jp(t,e,s);else e==Qt||e==We?D=Gp(t,e,g):(e==jt||e==(gt|jt))&&!u.length?D=Kp(t,e,s,o):D=Wr.apply(r,L);var $=M?Xa:Iu;return Ru($(D,L),t,e)}function mu(t,e,s,o){return t===r||se(t,fn[s])&&!X.call(o,s)?e:t}function vu(t,e,s,o,u,l){return st(t)&&st(e)&&(l.set(e,t),Dr(t,e,r,vu,l),l.delete(e)),t}function Vp(t){return Zn(t)?r:t}function wu(t,e,s,o,u,l){var d=s&K,g=t.length,b=e.length;if(g!=b&&!(d&&b>g))return!1;var E=l.get(t),x=l.get(e);if(E&&x)return E==e&&x==t;var T=-1,M=!0,L=s&At?new Ge:r;for(l.set(t,e),l.set(e,t);++T<g;){var D=t[T],$=e[T];if(o)var N=d?o($,D,T,e,t,l):o(D,$,T,t,e,l);if(N!==r){if(N)continue;M=!1;break}if(L){if(!Us(e,function(H,G){if(!Dn(L,G)&&(D===H||u(D,H,s,o,l)))return L.push(G)})){M=!1;break}}else if(!(D===$||u(D,$,s,o,l))){M=!1;break}}return l.delete(t),l.delete(e),M}function Zp(t,e,s,o,u,l,d){switch(s){case on:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case kn:return!(t.byteLength!=e.byteLength||!l(new xr(t),new xr(e)));case Rn:case Mn:case Pn:return se(+t,+e);case hr:return t.name==e.name&&t.message==e.message;case On:case Ln:return t==e+"";case te:var g=Js;case ee:var b=o&K;if(g||(g=mr),t.size!=e.size&&!b)return!1;var E=d.get(t);if(E)return E==e;o|=At,d.set(t,e);var x=wu(g(t),g(e),o,u,l,d);return d.delete(t),x;case fr:if($n)return $n.call(t)==$n.call(e)}return!1}function Xp(t,e,s,o,u,l){var d=s&K,g=_i(t),b=g.length,E=_i(e),x=E.length;if(b!=x&&!d)return!1;for(var T=b;T--;){var M=g[T];if(!(d?M in e:X.call(e,M)))return!1}var L=l.get(t),D=l.get(e);if(L&&D)return L==e&&D==t;var $=!0;l.set(t,e),l.set(e,t);for(var N=d;++T<b;){M=g[T];var H=t[M],G=e[M];if(o)var Dt=d?o(G,H,M,e,t,l):o(H,G,M,t,e,l);if(!(Dt===r?H===G||u(H,G,s,o,l):Dt)){$=!1;break}N||(N=M=="constructor")}if($&&!N){var Tt=t.constructor,Nt=e.constructor;Tt!=Nt&&"constructor"in t&&"constructor"in e&&!(typeof Tt=="function"&&Tt instanceof Tt&&typeof Nt=="function"&&Nt instanceof Nt)&&($=!1)}return l.delete(t),l.delete(e),$}function me(t){return xi(Au(t,r,ku),t+"")}function _i(t){return Wa(t,_t,wi)}function bi(t){return Wa(t,Rt,yu)}var mi=Mr?function(t){return Mr.get(t)}:Ni;function Hr(t){for(var e=t.name+"",s=pn[e],o=X.call(pn,e)?s.length:0;o--;){var u=s[o],l=u.func;if(l==null||l==t)return u.name}return e}function mn(t){var e=X.call(c,"placeholder")?c:t;return e.placeholder}function k(){var t=c.iteratee||ki;return t=t===ki?za:t,arguments.length?t(arguments[0],arguments[1]):t}function Jr(t,e){var s=t.__data__;return ig(e)?s[typeof e=="string"?"string":"hash"]:s.map}function vi(t){for(var e=_t(t),s=e.length;s--;){var o=e[s],u=t[o];e[s]=[o,u,xu(u)]}return e}function Ve(t,e){var s=ud(t,e);return qa(s)?s:r}function Qp(t){var e=X.call(t,He),s=t[He];try{t[He]=r;var o=!0}catch{}var u=Sr.call(t);return o&&(e?t[He]=s:delete t[He]),u}var wi=Ks?function(t){return t==null?[]:(t=j(t),Ae(Ks(t),function(e){return Ca.call(t,e)}))}:Fi,yu=Ks?function(t){for(var e=[];t;)Ce(e,wi(t)),t=Tr(t);return e}:Fi,wt=Et;(Ys&&wt(new Ys(new ArrayBuffer(1)))!=on||Fn&&wt(new Fn)!=te||Vs&&wt(Vs.resolve())!=No||dn&&wt(new dn)!=ee||Un&&wt(new Un)!=Bn)&&(wt=function(t){var e=Et(t),s=e==de?t.constructor:r,o=s?Ze(s):"";if(o)switch(o){case Bd:return on;case kd:return te;case Dd:return No;case Nd:return ee;case Fd:return Bn}return e});function jp(t,e,s){for(var o=-1,u=s.length;++o<u;){var l=s[o],d=l.size;switch(l.type){case"drop":t+=d;break;case"dropRight":e-=d;break;case"take":e=vt(e,t+d);break;case"takeRight":t=pt(t,e-d);break}}return{start:t,end:e}}function tg(t){var e=t.match(of);return e?e[1].split(af):[]}function Su(t,e,s){e=Oe(e,t);for(var o=-1,u=e.length,l=!1;++o<u;){var d=fe(e[o]);if(!(l=t!=null&&s(t,d)))break;t=t[d]}return l||++o!=u?l:(u=t==null?0:t.length,!!u&&Qr(u)&&ve(d,u)&&(U(t)||Xe(t)))}function eg(t){var e=t.length,s=new t.constructor(e);return e&&typeof t[0]=="string"&&X.call(t,"index")&&(s.index=t.index,s.input=t.input),s}function Eu(t){return typeof t.constructor=="function"&&!Yn(t)?gn(Tr(t)):{}}function ng(t,e,s){var o=t.constructor;switch(e){case kn:return di(t);case Rn:case Mn:return new o(+t);case on:return Up(t,s);case vs:case ws:case ys:case Ss:case Es:case xs:case Ts:case As:case Cs:return iu(t,s);case te:return new o;case Pn:case Ln:return new o(t);case On:return Wp(t);case ee:return new o;case fr:return $p(t)}}function rg(t,e){var s=e.length;if(!s)return t;var o=s-1;return e[o]=(s>1?"& ":"")+e[o],e=e.join(s>2?", ":" "),t.replace(sf,`{
21
- /* [wrapped with `+e+`] */
22
- `)}function sg(t){return U(t)||Xe(t)||!!(Ia&&t&&t[Ia])}function ve(t,e){var s=typeof t;return e=e??Te,!!e&&(s=="number"||s!="symbol"&&_f.test(t))&&t>-1&&t%1==0&&t<e}function xt(t,e,s){if(!st(s))return!1;var o=typeof e;return(o=="number"?It(s)&&ve(e,s.length):o=="string"&&e in s)?se(s[e],t):!1}function yi(t,e){if(U(t))return!1;var s=typeof t;return s=="number"||s=="symbol"||s=="boolean"||t==null||kt(t)?!0:tf.test(t)||!jl.test(t)||e!=null&&t in j(e)}function ig(t){var e=typeof t;return e=="string"||e=="number"||e=="symbol"||e=="boolean"?t!=="__proto__":t===null}function Si(t){var e=Hr(t),s=c[e];if(typeof s!="function"||!(e in J.prototype))return!1;if(t===s)return!0;var o=mi(s);return!!o&&t===o[0]}function og(t){return!!xa&&xa in t}var ag=wr?we:Ui;function Yn(t){var e=t&&t.constructor,s=typeof e=="function"&&e.prototype||fn;return t===s}function xu(t){return t===t&&!st(t)}function Tu(t,e){return function(s){return s==null?!1:s[t]===e&&(e!==r||t in j(s))}}function ug(t){var e=Zr(t,function(o){return s.size===I&&s.clear(),o}),s=e.cache;return e}function cg(t,e){var s=t[1],o=e[1],u=s|o,l=u<(gt|ct|q),d=o==q&&s==Qt||o==q&&s==ht&&t[7].length<=e[8]||o==(q|ht)&&e[7].length<=e[8]&&s==Qt;if(!(l||d))return t;o&gt&&(t[2]=e[2],u|=s&gt?0:ar);var g=e[3];if(g){var b=t[3];t[3]=b?au(b,g,e[4]):g,t[4]=b?Ie(t[3],P):e[4]}return g=e[5],g&&(b=t[5],t[5]=b?uu(b,g,e[6]):g,t[6]=b?Ie(t[5],P):e[6]),g=e[7],g&&(t[7]=g),o&q&&(t[8]=t[8]==null?e[8]:vt(t[8],e[8])),t[9]==null&&(t[9]=e[9]),t[0]=e[0],t[1]=u,t}function hg(t){var e=[];if(t!=null)for(var s in j(t))e.push(s);return e}function lg(t){return Sr.call(t)}function Au(t,e,s){return e=pt(e===r?t.length-1:e,0),function(){for(var o=arguments,u=-1,l=pt(o.length-e,0),d=v(l);++u<l;)d[u]=o[e+u];u=-1;for(var g=v(e+1);++u<e;)g[u]=o[u];return g[e]=s(d),Ot(t,this,g)}}function Cu(t,e){return e.length<2?t:Ye(t,Jt(e,0,-1))}function fg(t,e){for(var s=t.length,o=vt(e.length,s),u=Ct(t);o--;){var l=e[o];t[o]=ve(l,s)?u[l]:r}return t}function Ei(t,e){if(!(e==="constructor"&&typeof t[e]=="function")&&e!="__proto__")return t[e]}var Iu=Mu(Xa),Vn=Cd||function(t,e){return bt.setTimeout(t,e)},xi=Mu(kp);function Ru(t,e,s){var o=e+"";return xi(t,rg(o,dg(tg(o),s)))}function Mu(t){var e=0,s=0;return function(){var o=Pd(),u=it-(o-s);if(s=o,u>0){if(++e>=Ut)return arguments[0]}else e=0;return t.apply(r,arguments)}}function Gr(t,e){var s=-1,o=t.length,u=o-1;for(e=e===r?o:e;++s<e;){var l=oi(s,u),d=t[l];t[l]=t[s],t[s]=d}return t.length=e,t}var Pu=ug(function(t){var e=[];return t.charCodeAt(0)===46&&e.push(""),t.replace(ef,function(s,o,u,l){e.push(u?l.replace(hf,"$1"):o||s)}),e});function fe(t){if(typeof t=="string"||kt(t))return t;var e=t+"";return e=="0"&&1/t==-qe?"-0":e}function Ze(t){if(t!=null){try{return yr.call(t)}catch{}try{return t+""}catch{}}return""}function dg(t,e){return $t(Ul,function(s){var o="_."+s[0];e&s[1]&&!_r(t,o)&&t.push(o)}),t.sort()}function Ou(t){if(t instanceof J)return t.clone();var e=new zt(t.__wrapped__,t.__chain__);return e.__actions__=Ct(t.__actions__),e.__index__=t.__index__,e.__values__=t.__values__,e}function pg(t,e,s){(s?xt(t,e,s):e===r)?e=1:e=pt(W(e),0);var o=t==null?0:t.length;if(!o||e<1)return[];for(var u=0,l=0,d=v(Ir(o/e));u<o;)d[l++]=Jt(t,u,u+=e);return d}function gg(t){for(var e=-1,s=t==null?0:t.length,o=0,u=[];++e<s;){var l=t[e];l&&(u[o++]=l)}return u}function _g(){var t=arguments.length;if(!t)return[];for(var e=v(t-1),s=arguments[0],o=t;o--;)e[o-1]=arguments[o];return Ce(U(s)?Ct(s):[s],mt(e,1))}var bg=z(function(t,e){return at(t)?zn(t,mt(e,1,at,!0)):[]}),mg=z(function(t,e){var s=Gt(e);return at(s)&&(s=r),at(t)?zn(t,mt(e,1,at,!0),k(s,2)):[]}),vg=z(function(t,e){var s=Gt(e);return at(s)&&(s=r),at(t)?zn(t,mt(e,1,at,!0),r,s):[]});function wg(t,e,s){var o=t==null?0:t.length;return o?(e=s||e===r?1:W(e),Jt(t,e<0?0:e,o)):[]}function yg(t,e,s){var o=t==null?0:t.length;return o?(e=s||e===r?1:W(e),e=o-e,Jt(t,0,e<0?0:e)):[]}function Sg(t,e){return t&&t.length?Fr(t,k(e,3),!0,!0):[]}function Eg(t,e){return t&&t.length?Fr(t,k(e,3),!0):[]}function xg(t,e,s,o){var u=t==null?0:t.length;return u?(s&&typeof s!="number"&&xt(t,e,s)&&(s=0,o=u),_p(t,e,s,o)):[]}function Lu(t,e,s){var o=t==null?0:t.length;if(!o)return-1;var u=s==null?0:W(s);return u<0&&(u=pt(o+u,0)),br(t,k(e,3),u)}function Bu(t,e,s){var o=t==null?0:t.length;if(!o)return-1;var u=o-1;return s!==r&&(u=W(s),u=s<0?pt(o+u,0):vt(u,o-1)),br(t,k(e,3),u,!0)}function ku(t){var e=t==null?0:t.length;return e?mt(t,1):[]}function Tg(t){var e=t==null?0:t.length;return e?mt(t,qe):[]}function Ag(t,e){var s=t==null?0:t.length;return s?(e=e===r?1:W(e),mt(t,e)):[]}function Cg(t){for(var e=-1,s=t==null?0:t.length,o={};++e<s;){var u=t[e];o[u[0]]=u[1]}return o}function Du(t){return t&&t.length?t[0]:r}function Ig(t,e,s){var o=t==null?0:t.length;if(!o)return-1;var u=s==null?0:W(s);return u<0&&(u=pt(o+u,0)),un(t,e,u)}function Rg(t){var e=t==null?0:t.length;return e?Jt(t,0,-1):[]}var Mg=z(function(t){var e=nt(t,li);return e.length&&e[0]===t[0]?ei(e):[]}),Pg=z(function(t){var e=Gt(t),s=nt(t,li);return e===Gt(s)?e=r:s.pop(),s.length&&s[0]===t[0]?ei(s,k(e,2)):[]}),Og=z(function(t){var e=Gt(t),s=nt(t,li);return e=typeof e=="function"?e:r,e&&s.pop(),s.length&&s[0]===t[0]?ei(s,r,e):[]});function Lg(t,e){return t==null?"":Rd.call(t,e)}function Gt(t){var e=t==null?0:t.length;return e?t[e-1]:r}function Bg(t,e,s){var o=t==null?0:t.length;if(!o)return-1;var u=o;return s!==r&&(u=W(s),u=u<0?pt(o+u,0):vt(u,o-1)),e===e?dd(t,e,u):br(t,_a,u,!0)}function kg(t,e){return t&&t.length?Ka(t,W(e)):r}var Dg=z(Nu);function Nu(t,e){return t&&t.length&&e&&e.length?ii(t,e):t}function Ng(t,e,s){return t&&t.length&&e&&e.length?ii(t,e,k(s,2)):t}function Fg(t,e,s){return t&&t.length&&e&&e.length?ii(t,e,r,s):t}var Ug=me(function(t,e){var s=t==null?0:t.length,o=Xs(t,e);return Za(t,nt(e,function(u){return ve(u,s)?+u:u}).sort(ou)),o});function Wg(t,e){var s=[];if(!(t&&t.length))return s;var o=-1,u=[],l=t.length;for(e=k(e,3);++o<l;){var d=t[o];e(d,o,t)&&(s.push(d),u.push(o))}return Za(t,u),s}function Ti(t){return t==null?t:Ld.call(t)}function $g(t,e,s){var o=t==null?0:t.length;return o?(s&&typeof s!="number"&&xt(t,e,s)?(e=0,s=o):(e=e==null?0:W(e),s=s===r?o:W(s)),Jt(t,e,s)):[]}function qg(t,e){return Nr(t,e)}function zg(t,e,s){return ui(t,e,k(s,2))}function Hg(t,e){var s=t==null?0:t.length;if(s){var o=Nr(t,e);if(o<s&&se(t[o],e))return o}return-1}function Jg(t,e){return Nr(t,e,!0)}function Gg(t,e,s){return ui(t,e,k(s,2),!0)}function Kg(t,e){var s=t==null?0:t.length;if(s){var o=Nr(t,e,!0)-1;if(se(t[o],e))return o}return-1}function Yg(t){return t&&t.length?Qa(t):[]}function Vg(t,e){return t&&t.length?Qa(t,k(e,2)):[]}function Zg(t){var e=t==null?0:t.length;return e?Jt(t,1,e):[]}function Xg(t,e,s){return t&&t.length?(e=s||e===r?1:W(e),Jt(t,0,e<0?0:e)):[]}function Qg(t,e,s){var o=t==null?0:t.length;return o?(e=s||e===r?1:W(e),e=o-e,Jt(t,e<0?0:e,o)):[]}function jg(t,e){return t&&t.length?Fr(t,k(e,3),!1,!0):[]}function t_(t,e){return t&&t.length?Fr(t,k(e,3)):[]}var e_=z(function(t){return Pe(mt(t,1,at,!0))}),n_=z(function(t){var e=Gt(t);return at(e)&&(e=r),Pe(mt(t,1,at,!0),k(e,2))}),r_=z(function(t){var e=Gt(t);return e=typeof e=="function"?e:r,Pe(mt(t,1,at,!0),r,e)});function s_(t){return t&&t.length?Pe(t):[]}function i_(t,e){return t&&t.length?Pe(t,k(e,2)):[]}function o_(t,e){return e=typeof e=="function"?e:r,t&&t.length?Pe(t,r,e):[]}function Ai(t){if(!(t&&t.length))return[];var e=0;return t=Ae(t,function(s){if(at(s))return e=pt(s.length,e),!0}),zs(e,function(s){return nt(t,Ws(s))})}function Fu(t,e){if(!(t&&t.length))return[];var s=Ai(t);return e==null?s:nt(s,function(o){return Ot(e,r,o)})}var a_=z(function(t,e){return at(t)?zn(t,e):[]}),u_=z(function(t){return hi(Ae(t,at))}),c_=z(function(t){var e=Gt(t);return at(e)&&(e=r),hi(Ae(t,at),k(e,2))}),h_=z(function(t){var e=Gt(t);return e=typeof e=="function"?e:r,hi(Ae(t,at),r,e)}),l_=z(Ai);function f_(t,e){return nu(t||[],e||[],qn)}function d_(t,e){return nu(t||[],e||[],Gn)}var p_=z(function(t){var e=t.length,s=e>1?t[e-1]:r;return s=typeof s=="function"?(t.pop(),s):r,Fu(t,s)});function Uu(t){var e=c(t);return e.__chain__=!0,e}function g_(t,e){return e(t),t}function Kr(t,e){return e(t)}var __=me(function(t){var e=t.length,s=e?t[0]:0,o=this.__wrapped__,u=function(l){return Xs(l,t)};return e>1||this.__actions__.length||!(o instanceof J)||!ve(s)?this.thru(u):(o=o.slice(s,+s+(e?1:0)),o.__actions__.push({func:Kr,args:[u],thisArg:r}),new zt(o,this.__chain__).thru(function(l){return e&&!l.length&&l.push(r),l}))});function b_(){return Uu(this)}function m_(){return new zt(this.value(),this.__chain__)}function v_(){this.__values__===r&&(this.__values__=ju(this.value()));var t=this.__index__>=this.__values__.length,e=t?r:this.__values__[this.__index__++];return{done:t,value:e}}function w_(){return this}function y_(t){for(var e,s=this;s instanceof Or;){var o=Ou(s);o.__index__=0,o.__values__=r,e?u.__wrapped__=o:e=o;var u=o;s=s.__wrapped__}return u.__wrapped__=t,e}function S_(){var t=this.__wrapped__;if(t instanceof J){var e=t;return this.__actions__.length&&(e=new J(this)),e=e.reverse(),e.__actions__.push({func:Kr,args:[Ti],thisArg:r}),new zt(e,this.__chain__)}return this.thru(Ti)}function E_(){return eu(this.__wrapped__,this.__actions__)}var x_=Ur(function(t,e,s){X.call(t,s)?++t[s]:_e(t,s,1)});function T_(t,e,s){var o=U(t)?pa:gp;return s&&xt(t,e,s)&&(e=r),o(t,k(e,3))}function A_(t,e){var s=U(t)?Ae:Fa;return s(t,k(e,3))}var C_=fu(Lu),I_=fu(Bu);function R_(t,e){return mt(Yr(t,e),1)}function M_(t,e){return mt(Yr(t,e),qe)}function P_(t,e,s){return s=s===r?1:W(s),mt(Yr(t,e),s)}function Wu(t,e){var s=U(t)?$t:Me;return s(t,k(e,3))}function $u(t,e){var s=U(t)?Zf:Na;return s(t,k(e,3))}var O_=Ur(function(t,e,s){X.call(t,s)?t[s].push(e):_e(t,s,[e])});function L_(t,e,s,o){t=It(t)?t:wn(t),s=s&&!o?W(s):0;var u=t.length;return s<0&&(s=pt(u+s,0)),jr(t)?s<=u&&t.indexOf(e,s)>-1:!!u&&un(t,e,s)>-1}var B_=z(function(t,e,s){var o=-1,u=typeof e=="function",l=It(t)?v(t.length):[];return Me(t,function(d){l[++o]=u?Ot(e,d,s):Hn(d,e,s)}),l}),k_=Ur(function(t,e,s){_e(t,s,e)});function Yr(t,e){var s=U(t)?nt:Ha;return s(t,k(e,3))}function D_(t,e,s,o){return t==null?[]:(U(e)||(e=e==null?[]:[e]),s=o?r:s,U(s)||(s=s==null?[]:[s]),Ya(t,e,s))}var N_=Ur(function(t,e,s){t[s?0:1].push(e)},function(){return[[],[]]});function F_(t,e,s){var o=U(t)?Fs:ma,u=arguments.length<3;return o(t,k(e,4),s,u,Me)}function U_(t,e,s){var o=U(t)?Xf:ma,u=arguments.length<3;return o(t,k(e,4),s,u,Na)}function W_(t,e){var s=U(t)?Ae:Fa;return s(t,Xr(k(e,3)))}function $_(t){var e=U(t)?La:Lp;return e(t)}function q_(t,e,s){(s?xt(t,e,s):e===r)?e=1:e=W(e);var o=U(t)?hp:Bp;return o(t,e)}function z_(t){var e=U(t)?lp:Dp;return e(t)}function H_(t){if(t==null)return 0;if(It(t))return jr(t)?hn(t):t.length;var e=wt(t);return e==te||e==ee?t.size:ri(t).length}function J_(t,e,s){var o=U(t)?Us:Np;return s&&xt(t,e,s)&&(e=r),o(t,k(e,3))}var G_=z(function(t,e){if(t==null)return[];var s=e.length;return s>1&&xt(t,e[0],e[1])?e=[]:s>2&&xt(e[0],e[1],e[2])&&(e=[e[0]]),Ya(t,mt(e,1),[])}),Vr=Ad||function(){return bt.Date.now()};function K_(t,e){if(typeof e!="function")throw new qt(p);return t=W(t),function(){if(--t<1)return e.apply(this,arguments)}}function qu(t,e,s){return e=s?r:e,e=t&&e==null?t.length:e,be(t,q,r,r,r,r,e)}function zu(t,e){var s;if(typeof e!="function")throw new qt(p);return t=W(t),function(){return--t>0&&(s=e.apply(this,arguments)),t<=1&&(e=r),s}}var Ci=z(function(t,e,s){var o=gt;if(s.length){var u=Ie(s,mn(Ci));o|=jt}return be(t,o,e,s,u)}),Hu=z(function(t,e,s){var o=gt|ct;if(s.length){var u=Ie(s,mn(Hu));o|=jt}return be(e,o,t,s,u)});function Ju(t,e,s){e=s?r:e;var o=be(t,Qt,r,r,r,r,r,e);return o.placeholder=Ju.placeholder,o}function Gu(t,e,s){e=s?r:e;var o=be(t,We,r,r,r,r,r,e);return o.placeholder=Gu.placeholder,o}function Ku(t,e,s){var o,u,l,d,g,b,E=0,x=!1,T=!1,M=!0;if(typeof t!="function")throw new qt(p);e=Kt(e)||0,st(s)&&(x=!!s.leading,T="maxWait"in s,l=T?pt(Kt(s.maxWait)||0,e):l,M="trailing"in s?!!s.trailing:M);function L(ut){var ie=o,Se=u;return o=u=r,E=ut,d=t.apply(Se,ie),d}function D(ut){return E=ut,g=Vn(H,e),x?L(ut):d}function $(ut){var ie=ut-b,Se=ut-E,fc=e-ie;return T?vt(fc,l-Se):fc}function N(ut){var ie=ut-b,Se=ut-E;return b===r||ie>=e||ie<0||T&&Se>=l}function H(){var ut=Vr();if(N(ut))return G(ut);g=Vn(H,$(ut))}function G(ut){return g=r,M&&o?L(ut):(o=u=r,d)}function Dt(){g!==r&&ru(g),E=0,o=b=u=g=r}function Tt(){return g===r?d:G(Vr())}function Nt(){var ut=Vr(),ie=N(ut);if(o=arguments,u=this,b=ut,ie){if(g===r)return D(b);if(T)return ru(g),g=Vn(H,e),L(b)}return g===r&&(g=Vn(H,e)),d}return Nt.cancel=Dt,Nt.flush=Tt,Nt}var Y_=z(function(t,e){return Da(t,1,e)}),V_=z(function(t,e,s){return Da(t,Kt(e)||0,s)});function Z_(t){return be(t,Q)}function Zr(t,e){if(typeof t!="function"||e!=null&&typeof e!="function")throw new qt(p);var s=function(){var o=arguments,u=e?e.apply(this,o):o[0],l=s.cache;if(l.has(u))return l.get(u);var d=t.apply(this,o);return s.cache=l.set(u,d)||l,d};return s.cache=new(Zr.Cache||ge),s}Zr.Cache=ge;function Xr(t){if(typeof t!="function")throw new qt(p);return function(){var e=arguments;switch(e.length){case 0:return!t.call(this);case 1:return!t.call(this,e[0]);case 2:return!t.call(this,e[0],e[1]);case 3:return!t.call(this,e[0],e[1],e[2])}return!t.apply(this,e)}}function X_(t){return zu(2,t)}var Q_=Fp(function(t,e){e=e.length==1&&U(e[0])?nt(e[0],Lt(k())):nt(mt(e,1),Lt(k()));var s=e.length;return z(function(o){for(var u=-1,l=vt(o.length,s);++u<l;)o[u]=e[u].call(this,o[u]);return Ot(t,this,o)})}),Ii=z(function(t,e){var s=Ie(e,mn(Ii));return be(t,jt,r,e,s)}),Yu=z(function(t,e){var s=Ie(e,mn(Yu));return be(t,$e,r,e,s)}),j_=me(function(t,e){return be(t,ht,r,r,r,e)});function tb(t,e){if(typeof t!="function")throw new qt(p);return e=e===r?e:W(e),z(t,e)}function eb(t,e){if(typeof t!="function")throw new qt(p);return e=e==null?0:pt(W(e),0),z(function(s){var o=s[e],u=Le(s,0,e);return o&&Ce(u,o),Ot(t,this,u)})}function nb(t,e,s){var o=!0,u=!0;if(typeof t!="function")throw new qt(p);return st(s)&&(o="leading"in s?!!s.leading:o,u="trailing"in s?!!s.trailing:u),Ku(t,e,{leading:o,maxWait:e,trailing:u})}function rb(t){return qu(t,1)}function sb(t,e){return Ii(fi(e),t)}function ib(){if(!arguments.length)return[];var t=arguments[0];return U(t)?t:[t]}function ob(t){return Ht(t,R)}function ab(t,e){return e=typeof e=="function"?e:r,Ht(t,R,e)}function ub(t){return Ht(t,C|R)}function cb(t,e){return e=typeof e=="function"?e:r,Ht(t,C|R,e)}function hb(t,e){return e==null||ka(t,e,_t(e))}function se(t,e){return t===e||t!==t&&e!==e}var lb=zr(ti),fb=zr(function(t,e){return t>=e}),Xe=$a(function(){return arguments}())?$a:function(t){return ot(t)&&X.call(t,"callee")&&!Ca.call(t,"callee")},U=v.isArray,db=ua?Lt(ua):yp;function It(t){return t!=null&&Qr(t.length)&&!we(t)}function at(t){return ot(t)&&It(t)}function pb(t){return t===!0||t===!1||ot(t)&&Et(t)==Rn}var Be=Id||Ui,gb=ca?Lt(ca):Sp;function _b(t){return ot(t)&&t.nodeType===1&&!Zn(t)}function bb(t){if(t==null)return!0;if(It(t)&&(U(t)||typeof t=="string"||typeof t.splice=="function"||Be(t)||vn(t)||Xe(t)))return!t.length;var e=wt(t);if(e==te||e==ee)return!t.size;if(Yn(t))return!ri(t).length;for(var s in t)if(X.call(t,s))return!1;return!0}function mb(t,e){return Jn(t,e)}function vb(t,e,s){s=typeof s=="function"?s:r;var o=s?s(t,e):r;return o===r?Jn(t,e,r,s):!!o}function Ri(t){if(!ot(t))return!1;var e=Et(t);return e==hr||e==$l||typeof t.message=="string"&&typeof t.name=="string"&&!Zn(t)}function wb(t){return typeof t=="number"&&Ra(t)}function we(t){if(!st(t))return!1;var e=Et(t);return e==lr||e==Do||e==Wl||e==zl}function Vu(t){return typeof t=="number"&&t==W(t)}function Qr(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=Te}function st(t){var e=typeof t;return t!=null&&(e=="object"||e=="function")}function ot(t){return t!=null&&typeof t=="object"}var Zu=ha?Lt(ha):xp;function yb(t,e){return t===e||ni(t,e,vi(e))}function Sb(t,e,s){return s=typeof s=="function"?s:r,ni(t,e,vi(e),s)}function Eb(t){return Xu(t)&&t!=+t}function xb(t){if(ag(t))throw new F(f);return qa(t)}function Tb(t){return t===null}function Ab(t){return t==null}function Xu(t){return typeof t=="number"||ot(t)&&Et(t)==Pn}function Zn(t){if(!ot(t)||Et(t)!=de)return!1;var e=Tr(t);if(e===null)return!0;var s=X.call(e,"constructor")&&e.constructor;return typeof s=="function"&&s instanceof s&&yr.call(s)==Sd}var Mi=la?Lt(la):Tp;function Cb(t){return Vu(t)&&t>=-Te&&t<=Te}var Qu=fa?Lt(fa):Ap;function jr(t){return typeof t=="string"||!U(t)&&ot(t)&&Et(t)==Ln}function kt(t){return typeof t=="symbol"||ot(t)&&Et(t)==fr}var vn=da?Lt(da):Cp;function Ib(t){return t===r}function Rb(t){return ot(t)&&wt(t)==Bn}function Mb(t){return ot(t)&&Et(t)==Jl}var Pb=zr(si),Ob=zr(function(t,e){return t<=e});function ju(t){if(!t)return[];if(It(t))return jr(t)?ne(t):Ct(t);if(Nn&&t[Nn])return hd(t[Nn]());var e=wt(t),s=e==te?Js:e==ee?mr:wn;return s(t)}function ye(t){if(!t)return t===0?t:0;if(t=Kt(t),t===qe||t===-qe){var e=t<0?-1:1;return e*Dl}return t===t?t:0}function W(t){var e=ye(t),s=e%1;return e===e?s?e-s:e:0}function tc(t){return t?Ke(W(t),0,ce):0}function Kt(t){if(typeof t=="number")return t;if(kt(t))return ur;if(st(t)){var e=typeof t.valueOf=="function"?t.valueOf():t;t=st(e)?e+"":e}if(typeof t!="string")return t===0?t:+t;t=va(t);var s=df.test(t);return s||gf.test(t)?Kf(t.slice(2),s?2:8):ff.test(t)?ur:+t}function ec(t){return le(t,Rt(t))}function Lb(t){return t?Ke(W(t),-Te,Te):t===0?t:0}function Z(t){return t==null?"":Bt(t)}var Bb=_n(function(t,e){if(Yn(e)||It(e)){le(e,_t(e),t);return}for(var s in e)X.call(e,s)&&qn(t,s,e[s])}),nc=_n(function(t,e){le(e,Rt(e),t)}),ts=_n(function(t,e,s,o){le(e,Rt(e),t,o)}),kb=_n(function(t,e,s,o){le(e,_t(e),t,o)}),Db=me(Xs);function Nb(t,e){var s=gn(t);return e==null?s:Ba(s,e)}var Fb=z(function(t,e){t=j(t);var s=-1,o=e.length,u=o>2?e[2]:r;for(u&&xt(e[0],e[1],u)&&(o=1);++s<o;)for(var l=e[s],d=Rt(l),g=-1,b=d.length;++g<b;){var E=d[g],x=t[E];(x===r||se(x,fn[E])&&!X.call(t,E))&&(t[E]=l[E])}return t}),Ub=z(function(t){return t.push(r,vu),Ot(rc,r,t)});function Wb(t,e){return ga(t,k(e,3),he)}function $b(t,e){return ga(t,k(e,3),js)}function qb(t,e){return t==null?t:Qs(t,k(e,3),Rt)}function zb(t,e){return t==null?t:Ua(t,k(e,3),Rt)}function Hb(t,e){return t&&he(t,k(e,3))}function Jb(t,e){return t&&js(t,k(e,3))}function Gb(t){return t==null?[]:kr(t,_t(t))}function Kb(t){return t==null?[]:kr(t,Rt(t))}function Pi(t,e,s){var o=t==null?r:Ye(t,e);return o===r?s:o}function Yb(t,e){return t!=null&&Su(t,e,bp)}function Oi(t,e){return t!=null&&Su(t,e,mp)}var Vb=pu(function(t,e,s){e!=null&&typeof e.toString!="function"&&(e=Sr.call(e)),t[e]=s},Bi(Mt)),Zb=pu(function(t,e,s){e!=null&&typeof e.toString!="function"&&(e=Sr.call(e)),X.call(t,e)?t[e].push(s):t[e]=[s]},k),Xb=z(Hn);function _t(t){return It(t)?Oa(t):ri(t)}function Rt(t){return It(t)?Oa(t,!0):Ip(t)}function Qb(t,e){var s={};return e=k(e,3),he(t,function(o,u,l){_e(s,e(o,u,l),o)}),s}function jb(t,e){var s={};return e=k(e,3),he(t,function(o,u,l){_e(s,u,e(o,u,l))}),s}var tm=_n(function(t,e,s){Dr(t,e,s)}),rc=_n(function(t,e,s,o){Dr(t,e,s,o)}),em=me(function(t,e){var s={};if(t==null)return s;var o=!1;e=nt(e,function(l){return l=Oe(l,t),o||(o=l.length>1),l}),le(t,bi(t),s),o&&(s=Ht(s,C|A|R,Vp));for(var u=e.length;u--;)ci(s,e[u]);return s});function nm(t,e){return sc(t,Xr(k(e)))}var rm=me(function(t,e){return t==null?{}:Mp(t,e)});function sc(t,e){if(t==null)return{};var s=nt(bi(t),function(o){return[o]});return e=k(e),Va(t,s,function(o,u){return e(o,u[0])})}function sm(t,e,s){e=Oe(e,t);var o=-1,u=e.length;for(u||(u=1,t=r);++o<u;){var l=t==null?r:t[fe(e[o])];l===r&&(o=u,l=s),t=we(l)?l.call(t):l}return t}function im(t,e,s){return t==null?t:Gn(t,e,s)}function om(t,e,s,o){return o=typeof o=="function"?o:r,t==null?t:Gn(t,e,s,o)}var ic=bu(_t),oc=bu(Rt);function am(t,e,s){var o=U(t),u=o||Be(t)||vn(t);if(e=k(e,4),s==null){var l=t&&t.constructor;u?s=o?new l:[]:st(t)?s=we(l)?gn(Tr(t)):{}:s={}}return(u?$t:he)(t,function(d,g,b){return e(s,d,g,b)}),s}function um(t,e){return t==null?!0:ci(t,e)}function cm(t,e,s){return t==null?t:tu(t,e,fi(s))}function hm(t,e,s,o){return o=typeof o=="function"?o:r,t==null?t:tu(t,e,fi(s),o)}function wn(t){return t==null?[]:Hs(t,_t(t))}function lm(t){return t==null?[]:Hs(t,Rt(t))}function fm(t,e,s){return s===r&&(s=e,e=r),s!==r&&(s=Kt(s),s=s===s?s:0),e!==r&&(e=Kt(e),e=e===e?e:0),Ke(Kt(t),e,s)}function dm(t,e,s){return e=ye(e),s===r?(s=e,e=0):s=ye(s),t=Kt(t),vp(t,e,s)}function pm(t,e,s){if(s&&typeof s!="boolean"&&xt(t,e,s)&&(e=s=r),s===r&&(typeof e=="boolean"?(s=e,e=r):typeof t=="boolean"&&(s=t,t=r)),t===r&&e===r?(t=0,e=1):(t=ye(t),e===r?(e=t,t=0):e=ye(e)),t>e){var o=t;t=e,e=o}if(s||t%1||e%1){var u=Ma();return vt(t+u*(e-t+Gf("1e-"+((u+"").length-1))),e)}return oi(t,e)}var gm=bn(function(t,e,s){return e=e.toLowerCase(),t+(s?ac(e):e)});function ac(t){return Li(Z(t).toLowerCase())}function uc(t){return t=Z(t),t&&t.replace(bf,id).replace(Df,"")}function _m(t,e,s){t=Z(t),e=Bt(e);var o=t.length;s=s===r?o:Ke(W(s),0,o);var u=s;return s-=e.length,s>=0&&t.slice(s,u)==e}function bm(t){return t=Z(t),t&&Zl.test(t)?t.replace(Uo,od):t}function mm(t){return t=Z(t),t&&nf.test(t)?t.replace(Is,"\\$&"):t}var vm=bn(function(t,e,s){return t+(s?"-":"")+e.toLowerCase()}),wm=bn(function(t,e,s){return t+(s?" ":"")+e.toLowerCase()}),ym=lu("toLowerCase");function Sm(t,e,s){t=Z(t),e=W(e);var o=e?hn(t):0;if(!e||o>=e)return t;var u=(e-o)/2;return qr(Rr(u),s)+t+qr(Ir(u),s)}function Em(t,e,s){t=Z(t),e=W(e);var o=e?hn(t):0;return e&&o<e?t+qr(e-o,s):t}function xm(t,e,s){t=Z(t),e=W(e);var o=e?hn(t):0;return e&&o<e?qr(e-o,s)+t:t}function Tm(t,e,s){return s||e==null?e=0:e&&(e=+e),Od(Z(t).replace(Rs,""),e||0)}function Am(t,e,s){return(s?xt(t,e,s):e===r)?e=1:e=W(e),ai(Z(t),e)}function Cm(){var t=arguments,e=Z(t[0]);return t.length<3?e:e.replace(t[1],t[2])}var Im=bn(function(t,e,s){return t+(s?"_":"")+e.toLowerCase()});function Rm(t,e,s){return s&&typeof s!="number"&&xt(t,e,s)&&(e=s=r),s=s===r?ce:s>>>0,s?(t=Z(t),t&&(typeof e=="string"||e!=null&&!Mi(e))&&(e=Bt(e),!e&&cn(t))?Le(ne(t),0,s):t.split(e,s)):[]}var Mm=bn(function(t,e,s){return t+(s?" ":"")+Li(e)});function Pm(t,e,s){return t=Z(t),s=s==null?0:Ke(W(s),0,t.length),e=Bt(e),t.slice(s,s+e.length)==e}function Om(t,e,s){var o=c.templateSettings;s&&xt(t,e,s)&&(e=r),t=Z(t),e=ts({},e,o,mu);var u=ts({},e.imports,o.imports,mu),l=_t(u),d=Hs(u,l),g,b,E=0,x=e.interpolate||dr,T="__p += '",M=Gs((e.escape||dr).source+"|"+x.source+"|"+(x===Wo?lf:dr).source+"|"+(e.evaluate||dr).source+"|$","g"),L="//# sourceURL="+(X.call(e,"sourceURL")?(e.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++$f+"]")+`
23
- `;t.replace(M,function(N,H,G,Dt,Tt,Nt){return G||(G=Dt),T+=t.slice(E,Nt).replace(mf,ad),H&&(g=!0,T+=`' +
24
- __e(`+H+`) +
25
- '`),Tt&&(b=!0,T+=`';
26
- `+Tt+`;
27
- __p += '`),G&&(T+=`' +
8
+ */Te.exports,function(d,f){(function(){var i,p="4.17.21",_=200,v="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",S="Expected a function",E="Invalid `variable` option passed into `_.template`",C="__lodash_hash_undefined__",M=500,R="__lodash_placeholder__",P=1,T=2,F=4,Y=1,q=2,wt=1,Rt=2,tn=4,ot=8,En=16,Gt=32,vn=64,At=128,Nt=256,Kn=512,Oe=30,Et="...",We=800,qn=16,ae=1,ct=2,Er=3,sn=1/0,nn=9007199254740991,Tr=17976931348623157e292,kn=NaN,Ut=4294967295,De=Ut-1,Lr=Ut>>>1,V=[["ary",At],["bind",wt],["bindKey",Rt],["curry",ot],["curryRight",En],["flip",Kn],["partial",Gt],["partialRight",vn],["rearg",Nt]],lt="[object Arguments]",Jt="[object Array]",Tn="[object AsyncFunction]",wn="[object Boolean]",yt="[object Date]",ma="[object DOMException]",Fe="[object Error]",Ne="[object Function]",iu="[object GeneratorFunction]",Zt="[object Map]",fe="[object Number]",xa="[object Null]",on="[object Object]",uu="[object Promise]",Sa="[object Proxy]",ce="[object RegExp]",Yt="[object Set]",le="[object String]",Ue="[object Symbol]",Aa="[object Undefined]",he="[object WeakMap]",ba="[object WeakSet]",de="[object ArrayBuffer]",zn="[object DataView]",Or="[object Float32Array]",Wr="[object Float64Array]",Dr="[object Int8Array]",Fr="[object Int16Array]",Nr="[object Int32Array]",Ur="[object Uint8Array]",Br="[object Uint8ClampedArray]",Mr="[object Uint16Array]",$r="[object Uint32Array]",Ca=/\b__p \+= '';/g,Pa=/\b(__p \+=) '' \+/g,Ia=/(__e\(.*?\)|\b__t\)) \+\n'';/g,su=/&(?:amp|lt|gt|quot|#39);/g,ou=/[&<>"']/g,Ra=RegExp(su.source),Ea=RegExp(ou.source),Ta=/<%-([\s\S]+?)%>/g,La=/<%([\s\S]+?)%>/g,au=/<%=([\s\S]+?)%>/g,Oa=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Wa=/^\w*$/,Da=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Kr=/[\\^$.*+?()[\]{}|]/g,Fa=RegExp(Kr.source),qr=/^\s+/,Na=/\s/,Ua=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Ba=/\{\n\/\* \[wrapped with (.+)\] \*/,Ma=/,? & /,$a=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,Ka=/[()=,{}\[\]\/\s]/,qa=/\\(\\)?/g,ka=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,fu=/\w*$/,za=/^[-+]0x[0-9a-f]+$/i,Ha=/^0b[01]+$/i,Ga=/^\[object .+?Constructor\]$/,Ja=/^0o[0-7]+$/i,Za=/^(?:0|[1-9]\d*)$/,Ya=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Be=/($^)/,Xa=/['\n\r\u2028\u2029\\]/g,Me="\\ud800-\\udfff",Qa="\\u0300-\\u036f",Va="\\ufe20-\\ufe2f",ja="\\u20d0-\\u20ff",cu=Qa+Va+ja,lu="\\u2700-\\u27bf",hu="a-z\\xdf-\\xf6\\xf8-\\xff",tf="\\xac\\xb1\\xd7\\xf7",nf="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",ef="\\u2000-\\u206f",rf=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",du="A-Z\\xc0-\\xd6\\xd8-\\xde",pu="\\ufe0e\\ufe0f",gu=tf+nf+ef+rf,kr="['’]",uf="["+Me+"]",_u="["+gu+"]",$e="["+cu+"]",vu="\\d+",sf="["+lu+"]",wu="["+hu+"]",yu="[^"+Me+gu+vu+lu+hu+du+"]",zr="\\ud83c[\\udffb-\\udfff]",of="(?:"+$e+"|"+zr+")",mu="[^"+Me+"]",Hr="(?:\\ud83c[\\udde6-\\uddff]){2}",Gr="[\\ud800-\\udbff][\\udc00-\\udfff]",Hn="["+du+"]",xu="\\u200d",Su="(?:"+wu+"|"+yu+")",af="(?:"+Hn+"|"+yu+")",Au="(?:"+kr+"(?:d|ll|m|re|s|t|ve))?",bu="(?:"+kr+"(?:D|LL|M|RE|S|T|VE))?",Cu=of+"?",Pu="["+pu+"]?",ff="(?:"+xu+"(?:"+[mu,Hr,Gr].join("|")+")"+Pu+Cu+")*",cf="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",lf="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",Iu=Pu+Cu+ff,hf="(?:"+[sf,Hr,Gr].join("|")+")"+Iu,df="(?:"+[mu+$e+"?",$e,Hr,Gr,uf].join("|")+")",pf=RegExp(kr,"g"),gf=RegExp($e,"g"),Jr=RegExp(zr+"(?="+zr+")|"+df+Iu,"g"),_f=RegExp([Hn+"?"+wu+"+"+Au+"(?="+[_u,Hn,"$"].join("|")+")",af+"+"+bu+"(?="+[_u,Hn+Su,"$"].join("|")+")",Hn+"?"+Su+"+"+Au,Hn+"+"+bu,lf,cf,vu,hf].join("|"),"g"),vf=RegExp("["+xu+Me+cu+pu+"]"),wf=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,yf=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"],mf=-1,nt={};nt[Or]=nt[Wr]=nt[Dr]=nt[Fr]=nt[Nr]=nt[Ur]=nt[Br]=nt[Mr]=nt[$r]=!0,nt[lt]=nt[Jt]=nt[de]=nt[wn]=nt[zn]=nt[yt]=nt[Fe]=nt[Ne]=nt[Zt]=nt[fe]=nt[on]=nt[ce]=nt[Yt]=nt[le]=nt[he]=!1;var tt={};tt[lt]=tt[Jt]=tt[de]=tt[zn]=tt[wn]=tt[yt]=tt[Or]=tt[Wr]=tt[Dr]=tt[Fr]=tt[Nr]=tt[Zt]=tt[fe]=tt[on]=tt[ce]=tt[Yt]=tt[le]=tt[Ue]=tt[Ur]=tt[Br]=tt[Mr]=tt[$r]=!0,tt[Fe]=tt[Ne]=tt[he]=!1;var xf={À:"A",Á:"A",Â:"A",Ã:"A",Ä:"A",Å:"A",à:"a",á:"a",â:"a",ã:"a",ä:"a",å:"a",Ç:"C",ç:"c",Ð:"D",ð:"d",È:"E",É:"E",Ê:"E",Ë:"E",è:"e",é:"e",ê:"e",ë:"e",Ì:"I",Í:"I",Î:"I",Ï:"I",ì:"i",í:"i",î:"i",ï:"i",Ñ:"N",ñ:"n",Ò:"O",Ó:"O",Ô:"O",Õ:"O",Ö:"O",Ø:"O",ò:"o",ó:"o",ô:"o",õ:"o",ö:"o",ø:"o",Ù:"U",Ú:"U",Û:"U",Ü:"U",ù:"u",ú:"u",û:"u",ü:"u",Ý:"Y",ý:"y",ÿ:"y",Æ:"Ae",æ:"ae",Þ:"Th",þ:"th",ß:"ss",Ā:"A",Ă:"A",Ą:"A",ā:"a",ă:"a",ą:"a",Ć:"C",Ĉ:"C",Ċ:"C",Č:"C",ć:"c",ĉ:"c",ċ:"c",č:"c",Ď:"D",Đ:"D",ď:"d",đ:"d",Ē:"E",Ĕ:"E",Ė:"E",Ę:"E",Ě:"E",ē:"e",ĕ:"e",ė:"e",ę:"e",ě:"e",Ĝ:"G",Ğ:"G",Ġ:"G",Ģ:"G",ĝ:"g",ğ:"g",ġ:"g",ģ:"g",Ĥ:"H",Ħ:"H",ĥ:"h",ħ:"h",Ĩ:"I",Ī:"I",Ĭ:"I",Į:"I",İ:"I",ĩ:"i",ī:"i",ĭ:"i",į:"i",ı:"i",Ĵ:"J",ĵ:"j",Ķ:"K",ķ:"k",ĸ:"k",Ĺ:"L",Ļ:"L",Ľ:"L",Ŀ:"L",Ł:"L",ĺ:"l",ļ:"l",ľ:"l",ŀ:"l",ł:"l",Ń:"N",Ņ:"N",Ň:"N",Ŋ:"N",ń:"n",ņ:"n",ň:"n",ŋ:"n",Ō:"O",Ŏ:"O",Ő:"O",ō:"o",ŏ:"o",ő:"o",Ŕ:"R",Ŗ:"R",Ř:"R",ŕ:"r",ŗ:"r",ř:"r",Ś:"S",Ŝ:"S",Ş:"S",Š:"S",ś:"s",ŝ:"s",ş:"s",š:"s",Ţ:"T",Ť:"T",Ŧ:"T",ţ:"t",ť:"t",ŧ:"t",Ũ:"U",Ū:"U",Ŭ:"U",Ů:"U",Ű:"U",Ų:"U",ũ:"u",ū:"u",ŭ:"u",ů:"u",ű:"u",ų:"u",Ŵ:"W",ŵ:"w",Ŷ:"Y",ŷ:"y",Ÿ:"Y",Ź:"Z",Ż:"Z",Ž:"Z",ź:"z",ż:"z",ž:"z",IJ:"IJ",ij:"ij",Œ:"Oe",œ:"oe",ʼn:"'n",ſ:"s"},Sf={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},Af={"&amp;":"&","&lt;":"<","&gt;":">","&quot;":'"',"&#39;":"'"},bf={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},Cf=parseFloat,Pf=parseInt,Ru=typeof se=="object"&&se&&se.Object===Object&&se,If=typeof self=="object"&&self&&self.Object===Object&&self,dt=Ru||If||Function("return this")(),Zr=f&&!f.nodeType&&f,Ln=Zr&&!0&&d&&!d.nodeType&&d,Eu=Ln&&Ln.exports===Zr,Yr=Eu&&Ru.process,Bt=function(){try{var l=Ln&&Ln.require&&Ln.require("util").types;return l||Yr&&Yr.binding&&Yr.binding("util")}catch{}}(),Tu=Bt&&Bt.isArrayBuffer,Lu=Bt&&Bt.isDate,Ou=Bt&&Bt.isMap,Wu=Bt&&Bt.isRegExp,Du=Bt&&Bt.isSet,Fu=Bt&&Bt.isTypedArray;function Tt(l,w,g){switch(g.length){case 0:return l.call(w);case 1:return l.call(w,g[0]);case 2:return l.call(w,g[0],g[1]);case 3:return l.call(w,g[0],g[1],g[2])}return l.apply(w,g)}function Rf(l,w,g,b){for(var N=-1,Z=l==null?0:l.length;++N<Z;){var at=l[N];w(b,at,g(at),l)}return b}function Mt(l,w){for(var g=-1,b=l==null?0:l.length;++g<b&&w(l[g],g,l)!==!1;);return l}function Ef(l,w){for(var g=l==null?0:l.length;g--&&w(l[g],g,l)!==!1;);return l}function Nu(l,w){for(var g=-1,b=l==null?0:l.length;++g<b;)if(!w(l[g],g,l))return!1;return!0}function yn(l,w){for(var g=-1,b=l==null?0:l.length,N=0,Z=[];++g<b;){var at=l[g];w(at,g,l)&&(Z[N++]=at)}return Z}function Ke(l,w){var g=l==null?0:l.length;return!!g&&Gn(l,w,0)>-1}function Xr(l,w,g){for(var b=-1,N=l==null?0:l.length;++b<N;)if(g(w,l[b]))return!0;return!1}function et(l,w){for(var g=-1,b=l==null?0:l.length,N=Array(b);++g<b;)N[g]=w(l[g],g,l);return N}function mn(l,w){for(var g=-1,b=w.length,N=l.length;++g<b;)l[N+g]=w[g];return l}function Qr(l,w,g,b){var N=-1,Z=l==null?0:l.length;for(b&&Z&&(g=l[++N]);++N<Z;)g=w(g,l[N],N,l);return g}function Tf(l,w,g,b){var N=l==null?0:l.length;for(b&&N&&(g=l[--N]);N--;)g=w(g,l[N],N,l);return g}function Vr(l,w){for(var g=-1,b=l==null?0:l.length;++g<b;)if(w(l[g],g,l))return!0;return!1}var Lf=jr("length");function Of(l){return l.split("")}function Wf(l){return l.match($a)||[]}function Uu(l,w,g){var b;return g(l,function(N,Z,at){if(w(N,Z,at))return b=Z,!1}),b}function qe(l,w,g,b){for(var N=l.length,Z=g+(b?1:-1);b?Z--:++Z<N;)if(w(l[Z],Z,l))return Z;return-1}function Gn(l,w,g){return w===w?Hf(l,w,g):qe(l,Bu,g)}function Df(l,w,g,b){for(var N=g-1,Z=l.length;++N<Z;)if(b(l[N],w))return N;return-1}function Bu(l){return l!==l}function Mu(l,w){var g=l==null?0:l.length;return g?ni(l,w)/g:kn}function jr(l){return function(w){return w==null?i:w[l]}}function ti(l){return function(w){return l==null?i:l[w]}}function $u(l,w,g,b,N){return N(l,function(Z,at,j){g=b?(b=!1,Z):w(g,Z,at,j)}),g}function Ff(l,w){var g=l.length;for(l.sort(w);g--;)l[g]=l[g].value;return l}function ni(l,w){for(var g,b=-1,N=l.length;++b<N;){var Z=w(l[b]);Z!==i&&(g=g===i?Z:g+Z)}return g}function ei(l,w){for(var g=-1,b=Array(l);++g<l;)b[g]=w(g);return b}function Nf(l,w){return et(w,function(g){return[g,l[g]]})}function Ku(l){return l&&l.slice(0,Hu(l)+1).replace(qr,"")}function Lt(l){return function(w){return l(w)}}function ri(l,w){return et(w,function(g){return l[g]})}function pe(l,w){return l.has(w)}function qu(l,w){for(var g=-1,b=l.length;++g<b&&Gn(w,l[g],0)>-1;);return g}function ku(l,w){for(var g=l.length;g--&&Gn(w,l[g],0)>-1;);return g}function Uf(l,w){for(var g=l.length,b=0;g--;)l[g]===w&&++b;return b}var Bf=ti(xf),Mf=ti(Sf);function $f(l){return"\\"+bf[l]}function Kf(l,w){return l==null?i:l[w]}function Jn(l){return vf.test(l)}function qf(l){return wf.test(l)}function kf(l){for(var w,g=[];!(w=l.next()).done;)g.push(w.value);return g}function ii(l){var w=-1,g=Array(l.size);return l.forEach(function(b,N){g[++w]=[N,b]}),g}function zu(l,w){return function(g){return l(w(g))}}function xn(l,w){for(var g=-1,b=l.length,N=0,Z=[];++g<b;){var at=l[g];(at===w||at===R)&&(l[g]=R,Z[N++]=g)}return Z}function ke(l){var w=-1,g=Array(l.size);return l.forEach(function(b){g[++w]=b}),g}function zf(l){var w=-1,g=Array(l.size);return l.forEach(function(b){g[++w]=[b,b]}),g}function Hf(l,w,g){for(var b=g-1,N=l.length;++b<N;)if(l[b]===w)return b;return-1}function Gf(l,w,g){for(var b=g+1;b--;)if(l[b]===w)return b;return b}function Zn(l){return Jn(l)?Zf(l):Lf(l)}function Xt(l){return Jn(l)?Yf(l):Of(l)}function Hu(l){for(var w=l.length;w--&&Na.test(l.charAt(w)););return w}var Jf=ti(Af);function Zf(l){for(var w=Jr.lastIndex=0;Jr.test(l);)++w;return w}function Yf(l){return l.match(Jr)||[]}function Xf(l){return l.match(_f)||[]}var Qf=function l(w){w=w==null?dt:Yn.defaults(dt.Object(),w,Yn.pick(dt,yf));var g=w.Array,b=w.Date,N=w.Error,Z=w.Function,at=w.Math,j=w.Object,ui=w.RegExp,Vf=w.String,$t=w.TypeError,ze=g.prototype,jf=Z.prototype,Xn=j.prototype,He=w["__core-js_shared__"],Ge=jf.toString,Q=Xn.hasOwnProperty,tc=0,Gu=function(){var t=/[^.]+$/.exec(He&&He.keys&&He.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Je=Xn.toString,nc=Ge.call(j),ec=dt._,rc=ui("^"+Ge.call(Q).replace(Kr,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Ze=Eu?w.Buffer:i,Sn=w.Symbol,Ye=w.Uint8Array,Ju=Ze?Ze.allocUnsafe:i,Xe=zu(j.getPrototypeOf,j),Zu=j.create,Yu=Xn.propertyIsEnumerable,Qe=ze.splice,Xu=Sn?Sn.isConcatSpreadable:i,ge=Sn?Sn.iterator:i,On=Sn?Sn.toStringTag:i,Ve=function(){try{var t=Un(j,"defineProperty");return t({},"",{}),t}catch{}}(),ic=w.clearTimeout!==dt.clearTimeout&&w.clearTimeout,uc=b&&b.now!==dt.Date.now&&b.now,sc=w.setTimeout!==dt.setTimeout&&w.setTimeout,je=at.ceil,tr=at.floor,si=j.getOwnPropertySymbols,oc=Ze?Ze.isBuffer:i,Qu=w.isFinite,ac=ze.join,fc=zu(j.keys,j),ft=at.max,gt=at.min,cc=b.now,lc=w.parseInt,Vu=at.random,hc=ze.reverse,oi=Un(w,"DataView"),_e=Un(w,"Map"),ai=Un(w,"Promise"),Qn=Un(w,"Set"),ve=Un(w,"WeakMap"),we=Un(j,"create"),nr=ve&&new ve,Vn={},dc=Bn(oi),pc=Bn(_e),gc=Bn(ai),_c=Bn(Qn),vc=Bn(ve),er=Sn?Sn.prototype:i,ye=er?er.valueOf:i,ju=er?er.toString:i;function s(t){if(it(t)&&!U(t)&&!(t instanceof z)){if(t instanceof Kt)return t;if(Q.call(t,"__wrapped__"))return to(t)}return new Kt(t)}var jn=function(){function t(){}return function(n){if(!rt(n))return{};if(Zu)return Zu(n);t.prototype=n;var e=new t;return t.prototype=i,e}}();function rr(){}function Kt(t,n){this.__wrapped__=t,this.__actions__=[],this.__chain__=!!n,this.__index__=0,this.__values__=i}s.templateSettings={escape:Ta,evaluate:La,interpolate:au,variable:"",imports:{_:s}},s.prototype=rr.prototype,s.prototype.constructor=s,Kt.prototype=jn(rr.prototype),Kt.prototype.constructor=Kt;function z(t){this.__wrapped__=t,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=Ut,this.__views__=[]}function wc(){var t=new z(this.__wrapped__);return t.__actions__=bt(this.__actions__),t.__dir__=this.__dir__,t.__filtered__=this.__filtered__,t.__iteratees__=bt(this.__iteratees__),t.__takeCount__=this.__takeCount__,t.__views__=bt(this.__views__),t}function yc(){if(this.__filtered__){var t=new z(this);t.__dir__=-1,t.__filtered__=!0}else t=this.clone(),t.__dir__*=-1;return t}function mc(){var t=this.__wrapped__.value(),n=this.__dir__,e=U(t),r=n<0,u=e?t.length:0,o=Ol(0,u,this.__views__),a=o.start,c=o.end,h=c-a,y=r?c:a-1,m=this.__iteratees__,x=m.length,A=0,I=gt(h,this.__takeCount__);if(!e||!r&&u==h&&I==h)return As(t,this.__actions__);var O=[];t:for(;h--&&A<I;){y+=n;for(var $=-1,W=t[y];++$<x;){var k=m[$],G=k.iteratee,Dt=k.type,St=G(W);if(Dt==ct)W=St;else if(!St){if(Dt==ae)continue t;break t}}O[A++]=W}return O}z.prototype=jn(rr.prototype),z.prototype.constructor=z;function Wn(t){var n=-1,e=t==null?0:t.length;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function xc(){this.__data__=we?we(null):{},this.size=0}function Sc(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}function Ac(t){var n=this.__data__;if(we){var e=n[t];return e===C?i:e}return Q.call(n,t)?n[t]:i}function bc(t){var n=this.__data__;return we?n[t]!==i:Q.call(n,t)}function Cc(t,n){var e=this.__data__;return this.size+=this.has(t)?0:1,e[t]=we&&n===i?C:n,this}Wn.prototype.clear=xc,Wn.prototype.delete=Sc,Wn.prototype.get=Ac,Wn.prototype.has=bc,Wn.prototype.set=Cc;function an(t){var n=-1,e=t==null?0:t.length;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Pc(){this.__data__=[],this.size=0}function Ic(t){var n=this.__data__,e=ir(n,t);if(e<0)return!1;var r=n.length-1;return e==r?n.pop():Qe.call(n,e,1),--this.size,!0}function Rc(t){var n=this.__data__,e=ir(n,t);return e<0?i:n[e][1]}function Ec(t){return ir(this.__data__,t)>-1}function Tc(t,n){var e=this.__data__,r=ir(e,t);return r<0?(++this.size,e.push([t,n])):e[r][1]=n,this}an.prototype.clear=Pc,an.prototype.delete=Ic,an.prototype.get=Rc,an.prototype.has=Ec,an.prototype.set=Tc;function fn(t){var n=-1,e=t==null?0:t.length;for(this.clear();++n<e;){var r=t[n];this.set(r[0],r[1])}}function Lc(){this.size=0,this.__data__={hash:new Wn,map:new(_e||an),string:new Wn}}function Oc(t){var n=_r(this,t).delete(t);return this.size-=n?1:0,n}function Wc(t){return _r(this,t).get(t)}function Dc(t){return _r(this,t).has(t)}function Fc(t,n){var e=_r(this,t),r=e.size;return e.set(t,n),this.size+=e.size==r?0:1,this}fn.prototype.clear=Lc,fn.prototype.delete=Oc,fn.prototype.get=Wc,fn.prototype.has=Dc,fn.prototype.set=Fc;function Dn(t){var n=-1,e=t==null?0:t.length;for(this.__data__=new fn;++n<e;)this.add(t[n])}function Nc(t){return this.__data__.set(t,C),this}function Uc(t){return this.__data__.has(t)}Dn.prototype.add=Dn.prototype.push=Nc,Dn.prototype.has=Uc;function Qt(t){var n=this.__data__=new an(t);this.size=n.size}function Bc(){this.__data__=new an,this.size=0}function Mc(t){var n=this.__data__,e=n.delete(t);return this.size=n.size,e}function $c(t){return this.__data__.get(t)}function Kc(t){return this.__data__.has(t)}function qc(t,n){var e=this.__data__;if(e instanceof an){var r=e.__data__;if(!_e||r.length<_-1)return r.push([t,n]),this.size=++e.size,this;e=this.__data__=new fn(r)}return e.set(t,n),this.size=e.size,this}Qt.prototype.clear=Bc,Qt.prototype.delete=Mc,Qt.prototype.get=$c,Qt.prototype.has=Kc,Qt.prototype.set=qc;function ts(t,n){var e=U(t),r=!e&&Mn(t),u=!e&&!r&&In(t),o=!e&&!r&&!u&&re(t),a=e||r||u||o,c=a?ei(t.length,Vf):[],h=c.length;for(var y in t)(n||Q.call(t,y))&&!(a&&(y=="length"||u&&(y=="offset"||y=="parent")||o&&(y=="buffer"||y=="byteLength"||y=="byteOffset")||dn(y,h)))&&c.push(y);return c}function ns(t){var n=t.length;return n?t[yi(0,n-1)]:i}function kc(t,n){return vr(bt(t),Fn(n,0,t.length))}function zc(t){return vr(bt(t))}function fi(t,n,e){(e!==i&&!Vt(t[n],e)||e===i&&!(n in t))&&cn(t,n,e)}function me(t,n,e){var r=t[n];(!(Q.call(t,n)&&Vt(r,e))||e===i&&!(n in t))&&cn(t,n,e)}function ir(t,n){for(var e=t.length;e--;)if(Vt(t[e][0],n))return e;return-1}function Hc(t,n,e,r){return An(t,function(u,o,a){n(r,u,e(u),a)}),r}function es(t,n){return t&&rn(n,ht(n),t)}function Gc(t,n){return t&&rn(n,Pt(n),t)}function cn(t,n,e){n=="__proto__"&&Ve?Ve(t,n,{configurable:!0,enumerable:!0,value:e,writable:!0}):t[n]=e}function ci(t,n){for(var e=-1,r=n.length,u=g(r),o=t==null;++e<r;)u[e]=o?i:zi(t,n[e]);return u}function Fn(t,n,e){return t===t&&(e!==i&&(t=t<=e?t:e),n!==i&&(t=t>=n?t:n)),t}function qt(t,n,e,r,u,o){var a,c=n&P,h=n&T,y=n&F;if(e&&(a=u?e(t,r,u,o):e(t)),a!==i)return a;if(!rt(t))return t;var m=U(t);if(m){if(a=Dl(t),!c)return bt(t,a)}else{var x=_t(t),A=x==Ne||x==iu;if(In(t))return Ps(t,c);if(x==on||x==lt||A&&!u){if(a=h||A?{}:Hs(t),!c)return h?Al(t,Gc(a,t)):Sl(t,es(a,t))}else{if(!tt[x])return u?t:{};a=Fl(t,x,c)}}o||(o=new Qt);var I=o.get(t);if(I)return I;o.set(t,a),xo(t)?t.forEach(function(W){a.add(qt(W,n,e,W,t,o))}):yo(t)&&t.forEach(function(W,k){a.set(k,qt(W,n,e,k,t,o))});var O=y?h?Ti:Ei:h?Pt:ht,$=m?i:O(t);return Mt($||t,function(W,k){$&&(k=W,W=t[k]),me(a,k,qt(W,n,e,k,t,o))}),a}function Jc(t){var n=ht(t);return function(e){return rs(e,t,n)}}function rs(t,n,e){var r=e.length;if(t==null)return!r;for(t=j(t);r--;){var u=e[r],o=n[u],a=t[u];if(a===i&&!(u in t)||!o(a))return!1}return!0}function is(t,n,e){if(typeof t!="function")throw new $t(S);return Ie(function(){t.apply(i,e)},n)}function xe(t,n,e,r){var u=-1,o=Ke,a=!0,c=t.length,h=[],y=n.length;if(!c)return h;e&&(n=et(n,Lt(e))),r?(o=Xr,a=!1):n.length>=_&&(o=pe,a=!1,n=new Dn(n));t:for(;++u<c;){var m=t[u],x=e==null?m:e(m);if(m=r||m!==0?m:0,a&&x===x){for(var A=y;A--;)if(n[A]===x)continue t;h.push(m)}else o(n,x,r)||h.push(m)}return h}var An=Ls(en),us=Ls(hi,!0);function Zc(t,n){var e=!0;return An(t,function(r,u,o){return e=!!n(r,u,o),e}),e}function ur(t,n,e){for(var r=-1,u=t.length;++r<u;){var o=t[r],a=n(o);if(a!=null&&(c===i?a===a&&!Wt(a):e(a,c)))var c=a,h=o}return h}function Yc(t,n,e,r){var u=t.length;for(e=B(e),e<0&&(e=-e>u?0:u+e),r=r===i||r>u?u:B(r),r<0&&(r+=u),r=e>r?0:Ao(r);e<r;)t[e++]=n;return t}function ss(t,n){var e=[];return An(t,function(r,u,o){n(r,u,o)&&e.push(r)}),e}function pt(t,n,e,r,u){var o=-1,a=t.length;for(e||(e=Ul),u||(u=[]);++o<a;){var c=t[o];n>0&&e(c)?n>1?pt(c,n-1,e,r,u):mn(u,c):r||(u[u.length]=c)}return u}var li=Os(),os=Os(!0);function en(t,n){return t&&li(t,n,ht)}function hi(t,n){return t&&os(t,n,ht)}function sr(t,n){return yn(n,function(e){return pn(t[e])})}function Nn(t,n){n=Cn(n,t);for(var e=0,r=n.length;t!=null&&e<r;)t=t[un(n[e++])];return e&&e==r?t:i}function as(t,n,e){var r=n(t);return U(t)?r:mn(r,e(t))}function mt(t){return t==null?t===i?Aa:xa:On&&On in j(t)?Ll(t):zl(t)}function di(t,n){return t>n}function Xc(t,n){return t!=null&&Q.call(t,n)}function Qc(t,n){return t!=null&&n in j(t)}function Vc(t,n,e){return t>=gt(n,e)&&t<ft(n,e)}function pi(t,n,e){for(var r=e?Xr:Ke,u=t[0].length,o=t.length,a=o,c=g(o),h=1/0,y=[];a--;){var m=t[a];a&&n&&(m=et(m,Lt(n))),h=gt(m.length,h),c[a]=!e&&(n||u>=120&&m.length>=120)?new Dn(a&&m):i}m=t[0];var x=-1,A=c[0];t:for(;++x<u&&y.length<h;){var I=m[x],O=n?n(I):I;if(I=e||I!==0?I:0,!(A?pe(A,O):r(y,O,e))){for(a=o;--a;){var $=c[a];if(!($?pe($,O):r(t[a],O,e)))continue t}A&&A.push(O),y.push(I)}}return y}function jc(t,n,e,r){return en(t,function(u,o,a){n(r,e(u),o,a)}),r}function Se(t,n,e){n=Cn(n,t),t=Ys(t,n);var r=t==null?t:t[un(zt(n))];return r==null?i:Tt(r,t,e)}function fs(t){return it(t)&&mt(t)==lt}function tl(t){return it(t)&&mt(t)==de}function nl(t){return it(t)&&mt(t)==yt}function Ae(t,n,e,r,u){return t===n?!0:t==null||n==null||!it(t)&&!it(n)?t!==t&&n!==n:el(t,n,e,r,Ae,u)}function el(t,n,e,r,u,o){var a=U(t),c=U(n),h=a?Jt:_t(t),y=c?Jt:_t(n);h=h==lt?on:h,y=y==lt?on:y;var m=h==on,x=y==on,A=h==y;if(A&&In(t)){if(!In(n))return!1;a=!0,m=!1}if(A&&!m)return o||(o=new Qt),a||re(t)?qs(t,n,e,r,u,o):El(t,n,h,e,r,u,o);if(!(e&Y)){var I=m&&Q.call(t,"__wrapped__"),O=x&&Q.call(n,"__wrapped__");if(I||O){var $=I?t.value():t,W=O?n.value():n;return o||(o=new Qt),u($,W,e,r,o)}}return A?(o||(o=new Qt),Tl(t,n,e,r,u,o)):!1}function rl(t){return it(t)&&_t(t)==Zt}function gi(t,n,e,r){var u=e.length,o=u,a=!r;if(t==null)return!o;for(t=j(t);u--;){var c=e[u];if(a&&c[2]?c[1]!==t[c[0]]:!(c[0]in t))return!1}for(;++u<o;){c=e[u];var h=c[0],y=t[h],m=c[1];if(a&&c[2]){if(y===i&&!(h in t))return!1}else{var x=new Qt;if(r)var A=r(y,m,h,t,n,x);if(!(A===i?Ae(m,y,Y|q,r,x):A))return!1}}return!0}function cs(t){if(!rt(t)||Ml(t))return!1;var n=pn(t)?rc:Ga;return n.test(Bn(t))}function il(t){return it(t)&&mt(t)==ce}function ul(t){return it(t)&&_t(t)==Yt}function sl(t){return it(t)&&Ar(t.length)&&!!nt[mt(t)]}function ls(t){return typeof t=="function"?t:t==null?It:typeof t=="object"?U(t)?ps(t[0],t[1]):ds(t):Do(t)}function _i(t){if(!Pe(t))return fc(t);var n=[];for(var e in j(t))Q.call(t,e)&&e!="constructor"&&n.push(e);return n}function ol(t){if(!rt(t))return kl(t);var n=Pe(t),e=[];for(var r in t)r=="constructor"&&(n||!Q.call(t,r))||e.push(r);return e}function vi(t,n){return t<n}function hs(t,n){var e=-1,r=Ct(t)?g(t.length):[];return An(t,function(u,o,a){r[++e]=n(u,o,a)}),r}function ds(t){var n=Oi(t);return n.length==1&&n[0][2]?Js(n[0][0],n[0][1]):function(e){return e===t||gi(e,t,n)}}function ps(t,n){return Di(t)&&Gs(n)?Js(un(t),n):function(e){var r=zi(e,t);return r===i&&r===n?Hi(e,t):Ae(n,r,Y|q)}}function or(t,n,e,r,u){t!==n&&li(n,function(o,a){if(u||(u=new Qt),rt(o))al(t,n,a,e,or,r,u);else{var c=r?r(Ni(t,a),o,a+"",t,n,u):i;c===i&&(c=o),fi(t,a,c)}},Pt)}function al(t,n,e,r,u,o,a){var c=Ni(t,e),h=Ni(n,e),y=a.get(h);if(y){fi(t,e,y);return}var m=o?o(c,h,e+"",t,n,a):i,x=m===i;if(x){var A=U(h),I=!A&&In(h),O=!A&&!I&&re(h);m=h,A||I||O?U(c)?m=c:ut(c)?m=bt(c):I?(x=!1,m=Ps(h,!0)):O?(x=!1,m=Is(h,!0)):m=[]:Re(h)||Mn(h)?(m=c,Mn(c)?m=bo(c):(!rt(c)||pn(c))&&(m=Hs(h))):x=!1}x&&(a.set(h,m),u(m,h,r,o,a),a.delete(h)),fi(t,e,m)}function gs(t,n){var e=t.length;if(e)return n+=n<0?e:0,dn(n,e)?t[n]:i}function _s(t,n,e){n.length?n=et(n,function(o){return U(o)?function(a){return Nn(a,o.length===1?o[0]:o)}:o}):n=[It];var r=-1;n=et(n,Lt(L()));var u=hs(t,function(o,a,c){var h=et(n,function(y){return y(o)});return{criteria:h,index:++r,value:o}});return Ff(u,function(o,a){return xl(o,a,e)})}function fl(t,n){return vs(t,n,function(e,r){return Hi(t,r)})}function vs(t,n,e){for(var r=-1,u=n.length,o={};++r<u;){var a=n[r],c=Nn(t,a);e(c,a)&&be(o,Cn(a,t),c)}return o}function cl(t){return function(n){return Nn(n,t)}}function wi(t,n,e,r){var u=r?Df:Gn,o=-1,a=n.length,c=t;for(t===n&&(n=bt(n)),e&&(c=et(t,Lt(e)));++o<a;)for(var h=0,y=n[o],m=e?e(y):y;(h=u(c,m,h,r))>-1;)c!==t&&Qe.call(c,h,1),Qe.call(t,h,1);return t}function ws(t,n){for(var e=t?n.length:0,r=e-1;e--;){var u=n[e];if(e==r||u!==o){var o=u;dn(u)?Qe.call(t,u,1):Si(t,u)}}return t}function yi(t,n){return t+tr(Vu()*(n-t+1))}function ll(t,n,e,r){for(var u=-1,o=ft(je((n-t)/(e||1)),0),a=g(o);o--;)a[r?o:++u]=t,t+=e;return a}function mi(t,n){var e="";if(!t||n<1||n>nn)return e;do n%2&&(e+=t),n=tr(n/2),n&&(t+=t);while(n);return e}function K(t,n){return Ui(Zs(t,n,It),t+"")}function hl(t){return ns(ie(t))}function dl(t,n){var e=ie(t);return vr(e,Fn(n,0,e.length))}function be(t,n,e,r){if(!rt(t))return t;n=Cn(n,t);for(var u=-1,o=n.length,a=o-1,c=t;c!=null&&++u<o;){var h=un(n[u]),y=e;if(h==="__proto__"||h==="constructor"||h==="prototype")return t;if(u!=a){var m=c[h];y=r?r(m,h,c):i,y===i&&(y=rt(m)?m:dn(n[u+1])?[]:{})}me(c,h,y),c=c[h]}return t}var ys=nr?function(t,n){return nr.set(t,n),t}:It,pl=Ve?function(t,n){return Ve(t,"toString",{configurable:!0,enumerable:!1,value:Ji(n),writable:!0})}:It;function gl(t){return vr(ie(t))}function kt(t,n,e){var r=-1,u=t.length;n<0&&(n=-n>u?0:u+n),e=e>u?u:e,e<0&&(e+=u),u=n>e?0:e-n>>>0,n>>>=0;for(var o=g(u);++r<u;)o[r]=t[r+n];return o}function _l(t,n){var e;return An(t,function(r,u,o){return e=n(r,u,o),!e}),!!e}function ar(t,n,e){var r=0,u=t==null?r:t.length;if(typeof n=="number"&&n===n&&u<=Lr){for(;r<u;){var o=r+u>>>1,a=t[o];a!==null&&!Wt(a)&&(e?a<=n:a<n)?r=o+1:u=o}return u}return xi(t,n,It,e)}function xi(t,n,e,r){var u=0,o=t==null?0:t.length;if(o===0)return 0;n=e(n);for(var a=n!==n,c=n===null,h=Wt(n),y=n===i;u<o;){var m=tr((u+o)/2),x=e(t[m]),A=x!==i,I=x===null,O=x===x,$=Wt(x);if(a)var W=r||O;else y?W=O&&(r||A):c?W=O&&A&&(r||!I):h?W=O&&A&&!I&&(r||!$):I||$?W=!1:W=r?x<=n:x<n;W?u=m+1:o=m}return gt(o,De)}function ms(t,n){for(var e=-1,r=t.length,u=0,o=[];++e<r;){var a=t[e],c=n?n(a):a;if(!e||!Vt(c,h)){var h=c;o[u++]=a===0?0:a}}return o}function xs(t){return typeof t=="number"?t:Wt(t)?kn:+t}function Ot(t){if(typeof t=="string")return t;if(U(t))return et(t,Ot)+"";if(Wt(t))return ju?ju.call(t):"";var n=t+"";return n=="0"&&1/t==-sn?"-0":n}function bn(t,n,e){var r=-1,u=Ke,o=t.length,a=!0,c=[],h=c;if(e)a=!1,u=Xr;else if(o>=_){var y=n?null:Il(t);if(y)return ke(y);a=!1,u=pe,h=new Dn}else h=n?[]:c;t:for(;++r<o;){var m=t[r],x=n?n(m):m;if(m=e||m!==0?m:0,a&&x===x){for(var A=h.length;A--;)if(h[A]===x)continue t;n&&h.push(x),c.push(m)}else u(h,x,e)||(h!==c&&h.push(x),c.push(m))}return c}function Si(t,n){return n=Cn(n,t),t=Ys(t,n),t==null||delete t[un(zt(n))]}function Ss(t,n,e,r){return be(t,n,e(Nn(t,n)),r)}function fr(t,n,e,r){for(var u=t.length,o=r?u:-1;(r?o--:++o<u)&&n(t[o],o,t););return e?kt(t,r?0:o,r?o+1:u):kt(t,r?o+1:0,r?u:o)}function As(t,n){var e=t;return e instanceof z&&(e=e.value()),Qr(n,function(r,u){return u.func.apply(u.thisArg,mn([r],u.args))},e)}function Ai(t,n,e){var r=t.length;if(r<2)return r?bn(t[0]):[];for(var u=-1,o=g(r);++u<r;)for(var a=t[u],c=-1;++c<r;)c!=u&&(o[u]=xe(o[u]||a,t[c],n,e));return bn(pt(o,1),n,e)}function bs(t,n,e){for(var r=-1,u=t.length,o=n.length,a={};++r<u;){var c=r<o?n[r]:i;e(a,t[r],c)}return a}function bi(t){return ut(t)?t:[]}function Ci(t){return typeof t=="function"?t:It}function Cn(t,n){return U(t)?t:Di(t,n)?[t]:js(X(t))}var vl=K;function Pn(t,n,e){var r=t.length;return e=e===i?r:e,!n&&e>=r?t:kt(t,n,e)}var Cs=ic||function(t){return dt.clearTimeout(t)};function Ps(t,n){if(n)return t.slice();var e=t.length,r=Ju?Ju(e):new t.constructor(e);return t.copy(r),r}function Pi(t){var n=new t.constructor(t.byteLength);return new Ye(n).set(new Ye(t)),n}function wl(t,n){var e=n?Pi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.byteLength)}function yl(t){var n=new t.constructor(t.source,fu.exec(t));return n.lastIndex=t.lastIndex,n}function ml(t){return ye?j(ye.call(t)):{}}function Is(t,n){var e=n?Pi(t.buffer):t.buffer;return new t.constructor(e,t.byteOffset,t.length)}function Rs(t,n){if(t!==n){var e=t!==i,r=t===null,u=t===t,o=Wt(t),a=n!==i,c=n===null,h=n===n,y=Wt(n);if(!c&&!y&&!o&&t>n||o&&a&&h&&!c&&!y||r&&a&&h||!e&&h||!u)return 1;if(!r&&!o&&!y&&t<n||y&&e&&u&&!r&&!o||c&&e&&u||!a&&u||!h)return-1}return 0}function xl(t,n,e){for(var r=-1,u=t.criteria,o=n.criteria,a=u.length,c=e.length;++r<a;){var h=Rs(u[r],o[r]);if(h){if(r>=c)return h;var y=e[r];return h*(y=="desc"?-1:1)}}return t.index-n.index}function Es(t,n,e,r){for(var u=-1,o=t.length,a=e.length,c=-1,h=n.length,y=ft(o-a,0),m=g(h+y),x=!r;++c<h;)m[c]=n[c];for(;++u<a;)(x||u<o)&&(m[e[u]]=t[u]);for(;y--;)m[c++]=t[u++];return m}function Ts(t,n,e,r){for(var u=-1,o=t.length,a=-1,c=e.length,h=-1,y=n.length,m=ft(o-c,0),x=g(m+y),A=!r;++u<m;)x[u]=t[u];for(var I=u;++h<y;)x[I+h]=n[h];for(;++a<c;)(A||u<o)&&(x[I+e[a]]=t[u++]);return x}function bt(t,n){var e=-1,r=t.length;for(n||(n=g(r));++e<r;)n[e]=t[e];return n}function rn(t,n,e,r){var u=!e;e||(e={});for(var o=-1,a=n.length;++o<a;){var c=n[o],h=r?r(e[c],t[c],c,e,t):i;h===i&&(h=t[c]),u?cn(e,c,h):me(e,c,h)}return e}function Sl(t,n){return rn(t,Wi(t),n)}function Al(t,n){return rn(t,ks(t),n)}function cr(t,n){return function(e,r){var u=U(e)?Rf:Hc,o=n?n():{};return u(e,t,L(r,2),o)}}function te(t){return K(function(n,e){var r=-1,u=e.length,o=u>1?e[u-1]:i,a=u>2?e[2]:i;for(o=t.length>3&&typeof o=="function"?(u--,o):i,a&&xt(e[0],e[1],a)&&(o=u<3?i:o,u=1),n=j(n);++r<u;){var c=e[r];c&&t(n,c,r,o)}return n})}function Ls(t,n){return function(e,r){if(e==null)return e;if(!Ct(e))return t(e,r);for(var u=e.length,o=n?u:-1,a=j(e);(n?o--:++o<u)&&r(a[o],o,a)!==!1;);return e}}function Os(t){return function(n,e,r){for(var u=-1,o=j(n),a=r(n),c=a.length;c--;){var h=a[t?c:++u];if(e(o[h],h,o)===!1)break}return n}}function bl(t,n,e){var r=n&wt,u=Ce(t);function o(){var a=this&&this!==dt&&this instanceof o?u:t;return a.apply(r?e:this,arguments)}return o}function Ws(t){return function(n){n=X(n);var e=Jn(n)?Xt(n):i,r=e?e[0]:n.charAt(0),u=e?Pn(e,1).join(""):n.slice(1);return r[t]()+u}}function ne(t){return function(n){return Qr(Oo(Lo(n).replace(pf,"")),t,"")}}function Ce(t){return function(){var n=arguments;switch(n.length){case 0:return new t;case 1:return new t(n[0]);case 2:return new t(n[0],n[1]);case 3:return new t(n[0],n[1],n[2]);case 4:return new t(n[0],n[1],n[2],n[3]);case 5:return new t(n[0],n[1],n[2],n[3],n[4]);case 6:return new t(n[0],n[1],n[2],n[3],n[4],n[5]);case 7:return new t(n[0],n[1],n[2],n[3],n[4],n[5],n[6])}var e=jn(t.prototype),r=t.apply(e,n);return rt(r)?r:e}}function Cl(t,n,e){var r=Ce(t);function u(){for(var o=arguments.length,a=g(o),c=o,h=ee(u);c--;)a[c]=arguments[c];var y=o<3&&a[0]!==h&&a[o-1]!==h?[]:xn(a,h);if(o-=y.length,o<e)return Bs(t,n,lr,u.placeholder,i,a,y,i,i,e-o);var m=this&&this!==dt&&this instanceof u?r:t;return Tt(m,this,a)}return u}function Ds(t){return function(n,e,r){var u=j(n);if(!Ct(n)){var o=L(e,3);n=ht(n),e=function(c){return o(u[c],c,u)}}var a=t(n,e,r);return a>-1?u[o?n[a]:a]:i}}function Fs(t){return hn(function(n){var e=n.length,r=e,u=Kt.prototype.thru;for(t&&n.reverse();r--;){var o=n[r];if(typeof o!="function")throw new $t(S);if(u&&!a&&gr(o)=="wrapper")var a=new Kt([],!0)}for(r=a?r:e;++r<e;){o=n[r];var c=gr(o),h=c=="wrapper"?Li(o):i;h&&Fi(h[0])&&h[1]==(At|ot|Gt|Nt)&&!h[4].length&&h[9]==1?a=a[gr(h[0])].apply(a,h[3]):a=o.length==1&&Fi(o)?a[c]():a.thru(o)}return function(){var y=arguments,m=y[0];if(a&&y.length==1&&U(m))return a.plant(m).value();for(var x=0,A=e?n[x].apply(this,y):m;++x<e;)A=n[x].call(this,A);return A}})}function lr(t,n,e,r,u,o,a,c,h,y){var m=n&At,x=n&wt,A=n&Rt,I=n&(ot|En),O=n&Kn,$=A?i:Ce(t);function W(){for(var k=arguments.length,G=g(k),Dt=k;Dt--;)G[Dt]=arguments[Dt];if(I)var St=ee(W),Ft=Uf(G,St);if(r&&(G=Es(G,r,u,I)),o&&(G=Ts(G,o,a,I)),k-=Ft,I&&k<y){var st=xn(G,St);return Bs(t,n,lr,W.placeholder,e,G,st,c,h,y-k)}var jt=x?e:this,_n=A?jt[t]:t;return k=G.length,c?G=Hl(G,c):O&&k>1&&G.reverse(),m&&h<k&&(G.length=h),this&&this!==dt&&this instanceof W&&(_n=$||Ce(_n)),_n.apply(jt,G)}return W}function Ns(t,n){return function(e,r){return jc(e,t,n(r),{})}}function hr(t,n){return function(e,r){var u;if(e===i&&r===i)return n;if(e!==i&&(u=e),r!==i){if(u===i)return r;typeof e=="string"||typeof r=="string"?(e=Ot(e),r=Ot(r)):(e=xs(e),r=xs(r)),u=t(e,r)}return u}}function Ii(t){return hn(function(n){return n=et(n,Lt(L())),K(function(e){var r=this;return t(n,function(u){return Tt(u,r,e)})})})}function dr(t,n){n=n===i?" ":Ot(n);var e=n.length;if(e<2)return e?mi(n,t):n;var r=mi(n,je(t/Zn(n)));return Jn(n)?Pn(Xt(r),0,t).join(""):r.slice(0,t)}function Pl(t,n,e,r){var u=n&wt,o=Ce(t);function a(){for(var c=-1,h=arguments.length,y=-1,m=r.length,x=g(m+h),A=this&&this!==dt&&this instanceof a?o:t;++y<m;)x[y]=r[y];for(;h--;)x[y++]=arguments[++c];return Tt(A,u?e:this,x)}return a}function Us(t){return function(n,e,r){return r&&typeof r!="number"&&xt(n,e,r)&&(e=r=i),n=gn(n),e===i?(e=n,n=0):e=gn(e),r=r===i?n<e?1:-1:gn(r),ll(n,e,r,t)}}function pr(t){return function(n,e){return typeof n=="string"&&typeof e=="string"||(n=Ht(n),e=Ht(e)),t(n,e)}}function Bs(t,n,e,r,u,o,a,c,h,y){var m=n&ot,x=m?a:i,A=m?i:a,I=m?o:i,O=m?i:o;n|=m?Gt:vn,n&=~(m?vn:Gt),n&tn||(n&=-4);var $=[t,n,u,I,x,O,A,c,h,y],W=e.apply(i,$);return Fi(t)&&Xs(W,$),W.placeholder=r,Qs(W,t,n)}function Ri(t){var n=at[t];return function(e,r){if(e=Ht(e),r=r==null?0:gt(B(r),292),r&&Qu(e)){var u=(X(e)+"e").split("e"),o=n(u[0]+"e"+(+u[1]+r));return u=(X(o)+"e").split("e"),+(u[0]+"e"+(+u[1]-r))}return n(e)}}var Il=Qn&&1/ke(new Qn([,-0]))[1]==sn?function(t){return new Qn(t)}:Xi;function Ms(t){return function(n){var e=_t(n);return e==Zt?ii(n):e==Yt?zf(n):Nf(n,t(n))}}function ln(t,n,e,r,u,o,a,c){var h=n&Rt;if(!h&&typeof t!="function")throw new $t(S);var y=r?r.length:0;if(y||(n&=-97,r=u=i),a=a===i?a:ft(B(a),0),c=c===i?c:B(c),y-=u?u.length:0,n&vn){var m=r,x=u;r=u=i}var A=h?i:Li(t),I=[t,n,e,r,u,m,x,o,a,c];if(A&&ql(I,A),t=I[0],n=I[1],e=I[2],r=I[3],u=I[4],c=I[9]=I[9]===i?h?0:t.length:ft(I[9]-y,0),!c&&n&(ot|En)&&(n&=-25),!n||n==wt)var O=bl(t,n,e);else n==ot||n==En?O=Cl(t,n,c):(n==Gt||n==(wt|Gt))&&!u.length?O=Pl(t,n,e,r):O=lr.apply(i,I);var $=A?ys:Xs;return Qs($(O,I),t,n)}function $s(t,n,e,r){return t===i||Vt(t,Xn[e])&&!Q.call(r,e)?n:t}function Ks(t,n,e,r,u,o){return rt(t)&&rt(n)&&(o.set(n,t),or(t,n,i,Ks,o),o.delete(n)),t}function Rl(t){return Re(t)?i:t}function qs(t,n,e,r,u,o){var a=e&Y,c=t.length,h=n.length;if(c!=h&&!(a&&h>c))return!1;var y=o.get(t),m=o.get(n);if(y&&m)return y==n&&m==t;var x=-1,A=!0,I=e&q?new Dn:i;for(o.set(t,n),o.set(n,t);++x<c;){var O=t[x],$=n[x];if(r)var W=a?r($,O,x,n,t,o):r(O,$,x,t,n,o);if(W!==i){if(W)continue;A=!1;break}if(I){if(!Vr(n,function(k,G){if(!pe(I,G)&&(O===k||u(O,k,e,r,o)))return I.push(G)})){A=!1;break}}else if(!(O===$||u(O,$,e,r,o))){A=!1;break}}return o.delete(t),o.delete(n),A}function El(t,n,e,r,u,o,a){switch(e){case zn:if(t.byteLength!=n.byteLength||t.byteOffset!=n.byteOffset)return!1;t=t.buffer,n=n.buffer;case de:return!(t.byteLength!=n.byteLength||!o(new Ye(t),new Ye(n)));case wn:case yt:case fe:return Vt(+t,+n);case Fe:return t.name==n.name&&t.message==n.message;case ce:case le:return t==n+"";case Zt:var c=ii;case Yt:var h=r&Y;if(c||(c=ke),t.size!=n.size&&!h)return!1;var y=a.get(t);if(y)return y==n;r|=q,a.set(t,n);var m=qs(c(t),c(n),r,u,o,a);return a.delete(t),m;case Ue:if(ye)return ye.call(t)==ye.call(n)}return!1}function Tl(t,n,e,r,u,o){var a=e&Y,c=Ei(t),h=c.length,y=Ei(n),m=y.length;if(h!=m&&!a)return!1;for(var x=h;x--;){var A=c[x];if(!(a?A in n:Q.call(n,A)))return!1}var I=o.get(t),O=o.get(n);if(I&&O)return I==n&&O==t;var $=!0;o.set(t,n),o.set(n,t);for(var W=a;++x<h;){A=c[x];var k=t[A],G=n[A];if(r)var Dt=a?r(G,k,A,n,t,o):r(k,G,A,t,n,o);if(!(Dt===i?k===G||u(k,G,e,r,o):Dt)){$=!1;break}W||(W=A=="constructor")}if($&&!W){var St=t.constructor,Ft=n.constructor;St!=Ft&&"constructor"in t&&"constructor"in n&&!(typeof St=="function"&&St instanceof St&&typeof Ft=="function"&&Ft instanceof Ft)&&($=!1)}return o.delete(t),o.delete(n),$}function hn(t){return Ui(Zs(t,i,ro),t+"")}function Ei(t){return as(t,ht,Wi)}function Ti(t){return as(t,Pt,ks)}var Li=nr?function(t){return nr.get(t)}:Xi;function gr(t){for(var n=t.name+"",e=Vn[n],r=Q.call(Vn,n)?e.length:0;r--;){var u=e[r],o=u.func;if(o==null||o==t)return u.name}return n}function ee(t){var n=Q.call(s,"placeholder")?s:t;return n.placeholder}function L(){var t=s.iteratee||Zi;return t=t===Zi?ls:t,arguments.length?t(arguments[0],arguments[1]):t}function _r(t,n){var e=t.__data__;return Bl(n)?e[typeof n=="string"?"string":"hash"]:e.map}function Oi(t){for(var n=ht(t),e=n.length;e--;){var r=n[e],u=t[r];n[e]=[r,u,Gs(u)]}return n}function Un(t,n){var e=Kf(t,n);return cs(e)?e:i}function Ll(t){var n=Q.call(t,On),e=t[On];try{t[On]=i;var r=!0}catch{}var u=Je.call(t);return r&&(n?t[On]=e:delete t[On]),u}var Wi=si?function(t){return t==null?[]:(t=j(t),yn(si(t),function(n){return Yu.call(t,n)}))}:Qi,ks=si?function(t){for(var n=[];t;)mn(n,Wi(t)),t=Xe(t);return n}:Qi,_t=mt;(oi&&_t(new oi(new ArrayBuffer(1)))!=zn||_e&&_t(new _e)!=Zt||ai&&_t(ai.resolve())!=uu||Qn&&_t(new Qn)!=Yt||ve&&_t(new ve)!=he)&&(_t=function(t){var n=mt(t),e=n==on?t.constructor:i,r=e?Bn(e):"";if(r)switch(r){case dc:return zn;case pc:return Zt;case gc:return uu;case _c:return Yt;case vc:return he}return n});function Ol(t,n,e){for(var r=-1,u=e.length;++r<u;){var o=e[r],a=o.size;switch(o.type){case"drop":t+=a;break;case"dropRight":n-=a;break;case"take":n=gt(n,t+a);break;case"takeRight":t=ft(t,n-a);break}}return{start:t,end:n}}function Wl(t){var n=t.match(Ba);return n?n[1].split(Ma):[]}function zs(t,n,e){n=Cn(n,t);for(var r=-1,u=n.length,o=!1;++r<u;){var a=un(n[r]);if(!(o=t!=null&&e(t,a)))break;t=t[a]}return o||++r!=u?o:(u=t==null?0:t.length,!!u&&Ar(u)&&dn(a,u)&&(U(t)||Mn(t)))}function Dl(t){var n=t.length,e=new t.constructor(n);return n&&typeof t[0]=="string"&&Q.call(t,"index")&&(e.index=t.index,e.input=t.input),e}function Hs(t){return typeof t.constructor=="function"&&!Pe(t)?jn(Xe(t)):{}}function Fl(t,n,e){var r=t.constructor;switch(n){case de:return Pi(t);case wn:case yt:return new r(+t);case zn:return wl(t,e);case Or:case Wr:case Dr:case Fr:case Nr:case Ur:case Br:case Mr:case $r:return Is(t,e);case Zt:return new r;case fe:case le:return new r(t);case ce:return yl(t);case Yt:return new r;case Ue:return ml(t)}}function Nl(t,n){var e=n.length;if(!e)return t;var r=e-1;return n[r]=(e>1?"& ":"")+n[r],n=n.join(e>2?", ":" "),t.replace(Ua,`{
9
+ /* [wrapped with `+n+`] */
10
+ `)}function Ul(t){return U(t)||Mn(t)||!!(Xu&&t&&t[Xu])}function dn(t,n){var e=typeof t;return n=n??nn,!!n&&(e=="number"||e!="symbol"&&Za.test(t))&&t>-1&&t%1==0&&t<n}function xt(t,n,e){if(!rt(e))return!1;var r=typeof n;return(r=="number"?Ct(e)&&dn(n,e.length):r=="string"&&n in e)?Vt(e[n],t):!1}function Di(t,n){if(U(t))return!1;var e=typeof t;return e=="number"||e=="symbol"||e=="boolean"||t==null||Wt(t)?!0:Wa.test(t)||!Oa.test(t)||n!=null&&t in j(n)}function Bl(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}function Fi(t){var n=gr(t),e=s[n];if(typeof e!="function"||!(n in z.prototype))return!1;if(t===e)return!0;var r=Li(e);return!!r&&t===r[0]}function Ml(t){return!!Gu&&Gu in t}var $l=He?pn:Vi;function Pe(t){var n=t&&t.constructor,e=typeof n=="function"&&n.prototype||Xn;return t===e}function Gs(t){return t===t&&!rt(t)}function Js(t,n){return function(e){return e==null?!1:e[t]===n&&(n!==i||t in j(e))}}function Kl(t){var n=xr(t,function(r){return e.size===M&&e.clear(),r}),e=n.cache;return n}function ql(t,n){var e=t[1],r=n[1],u=e|r,o=u<(wt|Rt|At),a=r==At&&e==ot||r==At&&e==Nt&&t[7].length<=n[8]||r==(At|Nt)&&n[7].length<=n[8]&&e==ot;if(!(o||a))return t;r&wt&&(t[2]=n[2],u|=e&wt?0:tn);var c=n[3];if(c){var h=t[3];t[3]=h?Es(h,c,n[4]):c,t[4]=h?xn(t[3],R):n[4]}return c=n[5],c&&(h=t[5],t[5]=h?Ts(h,c,n[6]):c,t[6]=h?xn(t[5],R):n[6]),c=n[7],c&&(t[7]=c),r&At&&(t[8]=t[8]==null?n[8]:gt(t[8],n[8])),t[9]==null&&(t[9]=n[9]),t[0]=n[0],t[1]=u,t}function kl(t){var n=[];if(t!=null)for(var e in j(t))n.push(e);return n}function zl(t){return Je.call(t)}function Zs(t,n,e){return n=ft(n===i?t.length-1:n,0),function(){for(var r=arguments,u=-1,o=ft(r.length-n,0),a=g(o);++u<o;)a[u]=r[n+u];u=-1;for(var c=g(n+1);++u<n;)c[u]=r[u];return c[n]=e(a),Tt(t,this,c)}}function Ys(t,n){return n.length<2?t:Nn(t,kt(n,0,-1))}function Hl(t,n){for(var e=t.length,r=gt(n.length,e),u=bt(t);r--;){var o=n[r];t[r]=dn(o,e)?u[o]:i}return t}function Ni(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}var Xs=Vs(ys),Ie=sc||function(t,n){return dt.setTimeout(t,n)},Ui=Vs(pl);function Qs(t,n,e){var r=n+"";return Ui(t,Nl(r,Gl(Wl(r),e)))}function Vs(t){var n=0,e=0;return function(){var r=cc(),u=qn-(r-e);if(e=r,u>0){if(++n>=We)return arguments[0]}else n=0;return t.apply(i,arguments)}}function vr(t,n){var e=-1,r=t.length,u=r-1;for(n=n===i?r:n;++e<n;){var o=yi(e,u),a=t[o];t[o]=t[e],t[e]=a}return t.length=n,t}var js=Kl(function(t){var n=[];return t.charCodeAt(0)===46&&n.push(""),t.replace(Da,function(e,r,u,o){n.push(u?o.replace(qa,"$1"):r||e)}),n});function un(t){if(typeof t=="string"||Wt(t))return t;var n=t+"";return n=="0"&&1/t==-sn?"-0":n}function Bn(t){if(t!=null){try{return Ge.call(t)}catch{}try{return t+""}catch{}}return""}function Gl(t,n){return Mt(V,function(e){var r="_."+e[0];n&e[1]&&!Ke(t,r)&&t.push(r)}),t.sort()}function to(t){if(t instanceof z)return t.clone();var n=new Kt(t.__wrapped__,t.__chain__);return n.__actions__=bt(t.__actions__),n.__index__=t.__index__,n.__values__=t.__values__,n}function Jl(t,n,e){(e?xt(t,n,e):n===i)?n=1:n=ft(B(n),0);var r=t==null?0:t.length;if(!r||n<1)return[];for(var u=0,o=0,a=g(je(r/n));u<r;)a[o++]=kt(t,u,u+=n);return a}function Zl(t){for(var n=-1,e=t==null?0:t.length,r=0,u=[];++n<e;){var o=t[n];o&&(u[r++]=o)}return u}function Yl(){var t=arguments.length;if(!t)return[];for(var n=g(t-1),e=arguments[0],r=t;r--;)n[r-1]=arguments[r];return mn(U(e)?bt(e):[e],pt(n,1))}var Xl=K(function(t,n){return ut(t)?xe(t,pt(n,1,ut,!0)):[]}),Ql=K(function(t,n){var e=zt(n);return ut(e)&&(e=i),ut(t)?xe(t,pt(n,1,ut,!0),L(e,2)):[]}),Vl=K(function(t,n){var e=zt(n);return ut(e)&&(e=i),ut(t)?xe(t,pt(n,1,ut,!0),i,e):[]});function jl(t,n,e){var r=t==null?0:t.length;return r?(n=e||n===i?1:B(n),kt(t,n<0?0:n,r)):[]}function th(t,n,e){var r=t==null?0:t.length;return r?(n=e||n===i?1:B(n),n=r-n,kt(t,0,n<0?0:n)):[]}function nh(t,n){return t&&t.length?fr(t,L(n,3),!0,!0):[]}function eh(t,n){return t&&t.length?fr(t,L(n,3),!0):[]}function rh(t,n,e,r){var u=t==null?0:t.length;return u?(e&&typeof e!="number"&&xt(t,n,e)&&(e=0,r=u),Yc(t,n,e,r)):[]}function no(t,n,e){var r=t==null?0:t.length;if(!r)return-1;var u=e==null?0:B(e);return u<0&&(u=ft(r+u,0)),qe(t,L(n,3),u)}function eo(t,n,e){var r=t==null?0:t.length;if(!r)return-1;var u=r-1;return e!==i&&(u=B(e),u=e<0?ft(r+u,0):gt(u,r-1)),qe(t,L(n,3),u,!0)}function ro(t){var n=t==null?0:t.length;return n?pt(t,1):[]}function ih(t){var n=t==null?0:t.length;return n?pt(t,sn):[]}function uh(t,n){var e=t==null?0:t.length;return e?(n=n===i?1:B(n),pt(t,n)):[]}function sh(t){for(var n=-1,e=t==null?0:t.length,r={};++n<e;){var u=t[n];r[u[0]]=u[1]}return r}function io(t){return t&&t.length?t[0]:i}function oh(t,n,e){var r=t==null?0:t.length;if(!r)return-1;var u=e==null?0:B(e);return u<0&&(u=ft(r+u,0)),Gn(t,n,u)}function ah(t){var n=t==null?0:t.length;return n?kt(t,0,-1):[]}var fh=K(function(t){var n=et(t,bi);return n.length&&n[0]===t[0]?pi(n):[]}),ch=K(function(t){var n=zt(t),e=et(t,bi);return n===zt(e)?n=i:e.pop(),e.length&&e[0]===t[0]?pi(e,L(n,2)):[]}),lh=K(function(t){var n=zt(t),e=et(t,bi);return n=typeof n=="function"?n:i,n&&e.pop(),e.length&&e[0]===t[0]?pi(e,i,n):[]});function hh(t,n){return t==null?"":ac.call(t,n)}function zt(t){var n=t==null?0:t.length;return n?t[n-1]:i}function dh(t,n,e){var r=t==null?0:t.length;if(!r)return-1;var u=r;return e!==i&&(u=B(e),u=u<0?ft(r+u,0):gt(u,r-1)),n===n?Gf(t,n,u):qe(t,Bu,u,!0)}function ph(t,n){return t&&t.length?gs(t,B(n)):i}var gh=K(uo);function uo(t,n){return t&&t.length&&n&&n.length?wi(t,n):t}function _h(t,n,e){return t&&t.length&&n&&n.length?wi(t,n,L(e,2)):t}function vh(t,n,e){return t&&t.length&&n&&n.length?wi(t,n,i,e):t}var wh=hn(function(t,n){var e=t==null?0:t.length,r=ci(t,n);return ws(t,et(n,function(u){return dn(u,e)?+u:u}).sort(Rs)),r});function yh(t,n){var e=[];if(!(t&&t.length))return e;var r=-1,u=[],o=t.length;for(n=L(n,3);++r<o;){var a=t[r];n(a,r,t)&&(e.push(a),u.push(r))}return ws(t,u),e}function Bi(t){return t==null?t:hc.call(t)}function mh(t,n,e){var r=t==null?0:t.length;return r?(e&&typeof e!="number"&&xt(t,n,e)?(n=0,e=r):(n=n==null?0:B(n),e=e===i?r:B(e)),kt(t,n,e)):[]}function xh(t,n){return ar(t,n)}function Sh(t,n,e){return xi(t,n,L(e,2))}function Ah(t,n){var e=t==null?0:t.length;if(e){var r=ar(t,n);if(r<e&&Vt(t[r],n))return r}return-1}function bh(t,n){return ar(t,n,!0)}function Ch(t,n,e){return xi(t,n,L(e,2),!0)}function Ph(t,n){var e=t==null?0:t.length;if(e){var r=ar(t,n,!0)-1;if(Vt(t[r],n))return r}return-1}function Ih(t){return t&&t.length?ms(t):[]}function Rh(t,n){return t&&t.length?ms(t,L(n,2)):[]}function Eh(t){var n=t==null?0:t.length;return n?kt(t,1,n):[]}function Th(t,n,e){return t&&t.length?(n=e||n===i?1:B(n),kt(t,0,n<0?0:n)):[]}function Lh(t,n,e){var r=t==null?0:t.length;return r?(n=e||n===i?1:B(n),n=r-n,kt(t,n<0?0:n,r)):[]}function Oh(t,n){return t&&t.length?fr(t,L(n,3),!1,!0):[]}function Wh(t,n){return t&&t.length?fr(t,L(n,3)):[]}var Dh=K(function(t){return bn(pt(t,1,ut,!0))}),Fh=K(function(t){var n=zt(t);return ut(n)&&(n=i),bn(pt(t,1,ut,!0),L(n,2))}),Nh=K(function(t){var n=zt(t);return n=typeof n=="function"?n:i,bn(pt(t,1,ut,!0),i,n)});function Uh(t){return t&&t.length?bn(t):[]}function Bh(t,n){return t&&t.length?bn(t,L(n,2)):[]}function Mh(t,n){return n=typeof n=="function"?n:i,t&&t.length?bn(t,i,n):[]}function Mi(t){if(!(t&&t.length))return[];var n=0;return t=yn(t,function(e){if(ut(e))return n=ft(e.length,n),!0}),ei(n,function(e){return et(t,jr(e))})}function so(t,n){if(!(t&&t.length))return[];var e=Mi(t);return n==null?e:et(e,function(r){return Tt(n,i,r)})}var $h=K(function(t,n){return ut(t)?xe(t,n):[]}),Kh=K(function(t){return Ai(yn(t,ut))}),qh=K(function(t){var n=zt(t);return ut(n)&&(n=i),Ai(yn(t,ut),L(n,2))}),kh=K(function(t){var n=zt(t);return n=typeof n=="function"?n:i,Ai(yn(t,ut),i,n)}),zh=K(Mi);function Hh(t,n){return bs(t||[],n||[],me)}function Gh(t,n){return bs(t||[],n||[],be)}var Jh=K(function(t){var n=t.length,e=n>1?t[n-1]:i;return e=typeof e=="function"?(t.pop(),e):i,so(t,e)});function oo(t){var n=s(t);return n.__chain__=!0,n}function Zh(t,n){return n(t),t}function wr(t,n){return n(t)}var Yh=hn(function(t){var n=t.length,e=n?t[0]:0,r=this.__wrapped__,u=function(o){return ci(o,t)};return n>1||this.__actions__.length||!(r instanceof z)||!dn(e)?this.thru(u):(r=r.slice(e,+e+(n?1:0)),r.__actions__.push({func:wr,args:[u],thisArg:i}),new Kt(r,this.__chain__).thru(function(o){return n&&!o.length&&o.push(i),o}))});function Xh(){return oo(this)}function Qh(){return new Kt(this.value(),this.__chain__)}function Vh(){this.__values__===i&&(this.__values__=So(this.value()));var t=this.__index__>=this.__values__.length,n=t?i:this.__values__[this.__index__++];return{done:t,value:n}}function jh(){return this}function td(t){for(var n,e=this;e instanceof rr;){var r=to(e);r.__index__=0,r.__values__=i,n?u.__wrapped__=r:n=r;var u=r;e=e.__wrapped__}return u.__wrapped__=t,n}function nd(){var t=this.__wrapped__;if(t instanceof z){var n=t;return this.__actions__.length&&(n=new z(this)),n=n.reverse(),n.__actions__.push({func:wr,args:[Bi],thisArg:i}),new Kt(n,this.__chain__)}return this.thru(Bi)}function ed(){return As(this.__wrapped__,this.__actions__)}var rd=cr(function(t,n,e){Q.call(t,e)?++t[e]:cn(t,e,1)});function id(t,n,e){var r=U(t)?Nu:Zc;return e&&xt(t,n,e)&&(n=i),r(t,L(n,3))}function ud(t,n){var e=U(t)?yn:ss;return e(t,L(n,3))}var sd=Ds(no),od=Ds(eo);function ad(t,n){return pt(yr(t,n),1)}function fd(t,n){return pt(yr(t,n),sn)}function cd(t,n,e){return e=e===i?1:B(e),pt(yr(t,n),e)}function ao(t,n){var e=U(t)?Mt:An;return e(t,L(n,3))}function fo(t,n){var e=U(t)?Ef:us;return e(t,L(n,3))}var ld=cr(function(t,n,e){Q.call(t,e)?t[e].push(n):cn(t,e,[n])});function hd(t,n,e,r){t=Ct(t)?t:ie(t),e=e&&!r?B(e):0;var u=t.length;return e<0&&(e=ft(u+e,0)),br(t)?e<=u&&t.indexOf(n,e)>-1:!!u&&Gn(t,n,e)>-1}var dd=K(function(t,n,e){var r=-1,u=typeof n=="function",o=Ct(t)?g(t.length):[];return An(t,function(a){o[++r]=u?Tt(n,a,e):Se(a,n,e)}),o}),pd=cr(function(t,n,e){cn(t,e,n)});function yr(t,n){var e=U(t)?et:hs;return e(t,L(n,3))}function gd(t,n,e,r){return t==null?[]:(U(n)||(n=n==null?[]:[n]),e=r?i:e,U(e)||(e=e==null?[]:[e]),_s(t,n,e))}var _d=cr(function(t,n,e){t[e?0:1].push(n)},function(){return[[],[]]});function vd(t,n,e){var r=U(t)?Qr:$u,u=arguments.length<3;return r(t,L(n,4),e,u,An)}function wd(t,n,e){var r=U(t)?Tf:$u,u=arguments.length<3;return r(t,L(n,4),e,u,us)}function yd(t,n){var e=U(t)?yn:ss;return e(t,Sr(L(n,3)))}function md(t){var n=U(t)?ns:hl;return n(t)}function xd(t,n,e){(e?xt(t,n,e):n===i)?n=1:n=B(n);var r=U(t)?kc:dl;return r(t,n)}function Sd(t){var n=U(t)?zc:gl;return n(t)}function Ad(t){if(t==null)return 0;if(Ct(t))return br(t)?Zn(t):t.length;var n=_t(t);return n==Zt||n==Yt?t.size:_i(t).length}function bd(t,n,e){var r=U(t)?Vr:_l;return e&&xt(t,n,e)&&(n=i),r(t,L(n,3))}var Cd=K(function(t,n){if(t==null)return[];var e=n.length;return e>1&&xt(t,n[0],n[1])?n=[]:e>2&&xt(n[0],n[1],n[2])&&(n=[n[0]]),_s(t,pt(n,1),[])}),mr=uc||function(){return dt.Date.now()};function Pd(t,n){if(typeof n!="function")throw new $t(S);return t=B(t),function(){if(--t<1)return n.apply(this,arguments)}}function co(t,n,e){return n=e?i:n,n=t&&n==null?t.length:n,ln(t,At,i,i,i,i,n)}function lo(t,n){var e;if(typeof n!="function")throw new $t(S);return t=B(t),function(){return--t>0&&(e=n.apply(this,arguments)),t<=1&&(n=i),e}}var $i=K(function(t,n,e){var r=wt;if(e.length){var u=xn(e,ee($i));r|=Gt}return ln(t,r,n,e,u)}),ho=K(function(t,n,e){var r=wt|Rt;if(e.length){var u=xn(e,ee(ho));r|=Gt}return ln(n,r,t,e,u)});function po(t,n,e){n=e?i:n;var r=ln(t,ot,i,i,i,i,i,n);return r.placeholder=po.placeholder,r}function go(t,n,e){n=e?i:n;var r=ln(t,En,i,i,i,i,i,n);return r.placeholder=go.placeholder,r}function _o(t,n,e){var r,u,o,a,c,h,y=0,m=!1,x=!1,A=!0;if(typeof t!="function")throw new $t(S);n=Ht(n)||0,rt(e)&&(m=!!e.leading,x="maxWait"in e,o=x?ft(Ht(e.maxWait)||0,n):o,A="trailing"in e?!!e.trailing:A);function I(st){var jt=r,_n=u;return r=u=i,y=st,a=t.apply(_n,jt),a}function O(st){return y=st,c=Ie(k,n),m?I(st):a}function $(st){var jt=st-h,_n=st-y,Fo=n-jt;return x?gt(Fo,o-_n):Fo}function W(st){var jt=st-h,_n=st-y;return h===i||jt>=n||jt<0||x&&_n>=o}function k(){var st=mr();if(W(st))return G(st);c=Ie(k,$(st))}function G(st){return c=i,A&&r?I(st):(r=u=i,a)}function Dt(){c!==i&&Cs(c),y=0,r=h=u=c=i}function St(){return c===i?a:G(mr())}function Ft(){var st=mr(),jt=W(st);if(r=arguments,u=this,h=st,jt){if(c===i)return O(h);if(x)return Cs(c),c=Ie(k,n),I(h)}return c===i&&(c=Ie(k,n)),a}return Ft.cancel=Dt,Ft.flush=St,Ft}var Id=K(function(t,n){return is(t,1,n)}),Rd=K(function(t,n,e){return is(t,Ht(n)||0,e)});function Ed(t){return ln(t,Kn)}function xr(t,n){if(typeof t!="function"||n!=null&&typeof n!="function")throw new $t(S);var e=function(){var r=arguments,u=n?n.apply(this,r):r[0],o=e.cache;if(o.has(u))return o.get(u);var a=t.apply(this,r);return e.cache=o.set(u,a)||o,a};return e.cache=new(xr.Cache||fn),e}xr.Cache=fn;function Sr(t){if(typeof t!="function")throw new $t(S);return function(){var n=arguments;switch(n.length){case 0:return!t.call(this);case 1:return!t.call(this,n[0]);case 2:return!t.call(this,n[0],n[1]);case 3:return!t.call(this,n[0],n[1],n[2])}return!t.apply(this,n)}}function Td(t){return lo(2,t)}var Ld=vl(function(t,n){n=n.length==1&&U(n[0])?et(n[0],Lt(L())):et(pt(n,1),Lt(L()));var e=n.length;return K(function(r){for(var u=-1,o=gt(r.length,e);++u<o;)r[u]=n[u].call(this,r[u]);return Tt(t,this,r)})}),Ki=K(function(t,n){var e=xn(n,ee(Ki));return ln(t,Gt,i,n,e)}),vo=K(function(t,n){var e=xn(n,ee(vo));return ln(t,vn,i,n,e)}),Od=hn(function(t,n){return ln(t,Nt,i,i,i,n)});function Wd(t,n){if(typeof t!="function")throw new $t(S);return n=n===i?n:B(n),K(t,n)}function Dd(t,n){if(typeof t!="function")throw new $t(S);return n=n==null?0:ft(B(n),0),K(function(e){var r=e[n],u=Pn(e,0,n);return r&&mn(u,r),Tt(t,this,u)})}function Fd(t,n,e){var r=!0,u=!0;if(typeof t!="function")throw new $t(S);return rt(e)&&(r="leading"in e?!!e.leading:r,u="trailing"in e?!!e.trailing:u),_o(t,n,{leading:r,maxWait:n,trailing:u})}function Nd(t){return co(t,1)}function Ud(t,n){return Ki(Ci(n),t)}function Bd(){if(!arguments.length)return[];var t=arguments[0];return U(t)?t:[t]}function Md(t){return qt(t,F)}function $d(t,n){return n=typeof n=="function"?n:i,qt(t,F,n)}function Kd(t){return qt(t,P|F)}function qd(t,n){return n=typeof n=="function"?n:i,qt(t,P|F,n)}function kd(t,n){return n==null||rs(t,n,ht(n))}function Vt(t,n){return t===n||t!==t&&n!==n}var zd=pr(di),Hd=pr(function(t,n){return t>=n}),Mn=fs(function(){return arguments}())?fs:function(t){return it(t)&&Q.call(t,"callee")&&!Yu.call(t,"callee")},U=g.isArray,Gd=Tu?Lt(Tu):tl;function Ct(t){return t!=null&&Ar(t.length)&&!pn(t)}function ut(t){return it(t)&&Ct(t)}function Jd(t){return t===!0||t===!1||it(t)&&mt(t)==wn}var In=oc||Vi,Zd=Lu?Lt(Lu):nl;function Yd(t){return it(t)&&t.nodeType===1&&!Re(t)}function Xd(t){if(t==null)return!0;if(Ct(t)&&(U(t)||typeof t=="string"||typeof t.splice=="function"||In(t)||re(t)||Mn(t)))return!t.length;var n=_t(t);if(n==Zt||n==Yt)return!t.size;if(Pe(t))return!_i(t).length;for(var e in t)if(Q.call(t,e))return!1;return!0}function Qd(t,n){return Ae(t,n)}function Vd(t,n,e){e=typeof e=="function"?e:i;var r=e?e(t,n):i;return r===i?Ae(t,n,i,e):!!r}function qi(t){if(!it(t))return!1;var n=mt(t);return n==Fe||n==ma||typeof t.message=="string"&&typeof t.name=="string"&&!Re(t)}function jd(t){return typeof t=="number"&&Qu(t)}function pn(t){if(!rt(t))return!1;var n=mt(t);return n==Ne||n==iu||n==Tn||n==Sa}function wo(t){return typeof t=="number"&&t==B(t)}function Ar(t){return typeof t=="number"&&t>-1&&t%1==0&&t<=nn}function rt(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}function it(t){return t!=null&&typeof t=="object"}var yo=Ou?Lt(Ou):rl;function tp(t,n){return t===n||gi(t,n,Oi(n))}function np(t,n,e){return e=typeof e=="function"?e:i,gi(t,n,Oi(n),e)}function ep(t){return mo(t)&&t!=+t}function rp(t){if($l(t))throw new N(v);return cs(t)}function ip(t){return t===null}function up(t){return t==null}function mo(t){return typeof t=="number"||it(t)&&mt(t)==fe}function Re(t){if(!it(t)||mt(t)!=on)return!1;var n=Xe(t);if(n===null)return!0;var e=Q.call(n,"constructor")&&n.constructor;return typeof e=="function"&&e instanceof e&&Ge.call(e)==nc}var ki=Wu?Lt(Wu):il;function sp(t){return wo(t)&&t>=-nn&&t<=nn}var xo=Du?Lt(Du):ul;function br(t){return typeof t=="string"||!U(t)&&it(t)&&mt(t)==le}function Wt(t){return typeof t=="symbol"||it(t)&&mt(t)==Ue}var re=Fu?Lt(Fu):sl;function op(t){return t===i}function ap(t){return it(t)&&_t(t)==he}function fp(t){return it(t)&&mt(t)==ba}var cp=pr(vi),lp=pr(function(t,n){return t<=n});function So(t){if(!t)return[];if(Ct(t))return br(t)?Xt(t):bt(t);if(ge&&t[ge])return kf(t[ge]());var n=_t(t),e=n==Zt?ii:n==Yt?ke:ie;return e(t)}function gn(t){if(!t)return t===0?t:0;if(t=Ht(t),t===sn||t===-sn){var n=t<0?-1:1;return n*Tr}return t===t?t:0}function B(t){var n=gn(t),e=n%1;return n===n?e?n-e:n:0}function Ao(t){return t?Fn(B(t),0,Ut):0}function Ht(t){if(typeof t=="number")return t;if(Wt(t))return kn;if(rt(t)){var n=typeof t.valueOf=="function"?t.valueOf():t;t=rt(n)?n+"":n}if(typeof t!="string")return t===0?t:+t;t=Ku(t);var e=Ha.test(t);return e||Ja.test(t)?Pf(t.slice(2),e?2:8):za.test(t)?kn:+t}function bo(t){return rn(t,Pt(t))}function hp(t){return t?Fn(B(t),-nn,nn):t===0?t:0}function X(t){return t==null?"":Ot(t)}var dp=te(function(t,n){if(Pe(n)||Ct(n)){rn(n,ht(n),t);return}for(var e in n)Q.call(n,e)&&me(t,e,n[e])}),Co=te(function(t,n){rn(n,Pt(n),t)}),Cr=te(function(t,n,e,r){rn(n,Pt(n),t,r)}),pp=te(function(t,n,e,r){rn(n,ht(n),t,r)}),gp=hn(ci);function _p(t,n){var e=jn(t);return n==null?e:es(e,n)}var vp=K(function(t,n){t=j(t);var e=-1,r=n.length,u=r>2?n[2]:i;for(u&&xt(n[0],n[1],u)&&(r=1);++e<r;)for(var o=n[e],a=Pt(o),c=-1,h=a.length;++c<h;){var y=a[c],m=t[y];(m===i||Vt(m,Xn[y])&&!Q.call(t,y))&&(t[y]=o[y])}return t}),wp=K(function(t){return t.push(i,Ks),Tt(Po,i,t)});function yp(t,n){return Uu(t,L(n,3),en)}function mp(t,n){return Uu(t,L(n,3),hi)}function xp(t,n){return t==null?t:li(t,L(n,3),Pt)}function Sp(t,n){return t==null?t:os(t,L(n,3),Pt)}function Ap(t,n){return t&&en(t,L(n,3))}function bp(t,n){return t&&hi(t,L(n,3))}function Cp(t){return t==null?[]:sr(t,ht(t))}function Pp(t){return t==null?[]:sr(t,Pt(t))}function zi(t,n,e){var r=t==null?i:Nn(t,n);return r===i?e:r}function Ip(t,n){return t!=null&&zs(t,n,Xc)}function Hi(t,n){return t!=null&&zs(t,n,Qc)}var Rp=Ns(function(t,n,e){n!=null&&typeof n.toString!="function"&&(n=Je.call(n)),t[n]=e},Ji(It)),Ep=Ns(function(t,n,e){n!=null&&typeof n.toString!="function"&&(n=Je.call(n)),Q.call(t,n)?t[n].push(e):t[n]=[e]},L),Tp=K(Se);function ht(t){return Ct(t)?ts(t):_i(t)}function Pt(t){return Ct(t)?ts(t,!0):ol(t)}function Lp(t,n){var e={};return n=L(n,3),en(t,function(r,u,o){cn(e,n(r,u,o),r)}),e}function Op(t,n){var e={};return n=L(n,3),en(t,function(r,u,o){cn(e,u,n(r,u,o))}),e}var Wp=te(function(t,n,e){or(t,n,e)}),Po=te(function(t,n,e,r){or(t,n,e,r)}),Dp=hn(function(t,n){var e={};if(t==null)return e;var r=!1;n=et(n,function(o){return o=Cn(o,t),r||(r=o.length>1),o}),rn(t,Ti(t),e),r&&(e=qt(e,P|T|F,Rl));for(var u=n.length;u--;)Si(e,n[u]);return e});function Fp(t,n){return Io(t,Sr(L(n)))}var Np=hn(function(t,n){return t==null?{}:fl(t,n)});function Io(t,n){if(t==null)return{};var e=et(Ti(t),function(r){return[r]});return n=L(n),vs(t,e,function(r,u){return n(r,u[0])})}function Up(t,n,e){n=Cn(n,t);var r=-1,u=n.length;for(u||(u=1,t=i);++r<u;){var o=t==null?i:t[un(n[r])];o===i&&(r=u,o=e),t=pn(o)?o.call(t):o}return t}function Bp(t,n,e){return t==null?t:be(t,n,e)}function Mp(t,n,e,r){return r=typeof r=="function"?r:i,t==null?t:be(t,n,e,r)}var Ro=Ms(ht),Eo=Ms(Pt);function $p(t,n,e){var r=U(t),u=r||In(t)||re(t);if(n=L(n,4),e==null){var o=t&&t.constructor;u?e=r?new o:[]:rt(t)?e=pn(o)?jn(Xe(t)):{}:e={}}return(u?Mt:en)(t,function(a,c,h){return n(e,a,c,h)}),e}function Kp(t,n){return t==null?!0:Si(t,n)}function qp(t,n,e){return t==null?t:Ss(t,n,Ci(e))}function kp(t,n,e,r){return r=typeof r=="function"?r:i,t==null?t:Ss(t,n,Ci(e),r)}function ie(t){return t==null?[]:ri(t,ht(t))}function zp(t){return t==null?[]:ri(t,Pt(t))}function Hp(t,n,e){return e===i&&(e=n,n=i),e!==i&&(e=Ht(e),e=e===e?e:0),n!==i&&(n=Ht(n),n=n===n?n:0),Fn(Ht(t),n,e)}function Gp(t,n,e){return n=gn(n),e===i?(e=n,n=0):e=gn(e),t=Ht(t),Vc(t,n,e)}function Jp(t,n,e){if(e&&typeof e!="boolean"&&xt(t,n,e)&&(n=e=i),e===i&&(typeof n=="boolean"?(e=n,n=i):typeof t=="boolean"&&(e=t,t=i)),t===i&&n===i?(t=0,n=1):(t=gn(t),n===i?(n=t,t=0):n=gn(n)),t>n){var r=t;t=n,n=r}if(e||t%1||n%1){var u=Vu();return gt(t+u*(n-t+Cf("1e-"+((u+"").length-1))),n)}return yi(t,n)}var Zp=ne(function(t,n,e){return n=n.toLowerCase(),t+(e?To(n):n)});function To(t){return Gi(X(t).toLowerCase())}function Lo(t){return t=X(t),t&&t.replace(Ya,Bf).replace(gf,"")}function Yp(t,n,e){t=X(t),n=Ot(n);var r=t.length;e=e===i?r:Fn(B(e),0,r);var u=e;return e-=n.length,e>=0&&t.slice(e,u)==n}function Xp(t){return t=X(t),t&&Ea.test(t)?t.replace(ou,Mf):t}function Qp(t){return t=X(t),t&&Fa.test(t)?t.replace(Kr,"\\$&"):t}var Vp=ne(function(t,n,e){return t+(e?"-":"")+n.toLowerCase()}),jp=ne(function(t,n,e){return t+(e?" ":"")+n.toLowerCase()}),tg=Ws("toLowerCase");function ng(t,n,e){t=X(t),n=B(n);var r=n?Zn(t):0;if(!n||r>=n)return t;var u=(n-r)/2;return dr(tr(u),e)+t+dr(je(u),e)}function eg(t,n,e){t=X(t),n=B(n);var r=n?Zn(t):0;return n&&r<n?t+dr(n-r,e):t}function rg(t,n,e){t=X(t),n=B(n);var r=n?Zn(t):0;return n&&r<n?dr(n-r,e)+t:t}function ig(t,n,e){return e||n==null?n=0:n&&(n=+n),lc(X(t).replace(qr,""),n||0)}function ug(t,n,e){return(e?xt(t,n,e):n===i)?n=1:n=B(n),mi(X(t),n)}function sg(){var t=arguments,n=X(t[0]);return t.length<3?n:n.replace(t[1],t[2])}var og=ne(function(t,n,e){return t+(e?"_":"")+n.toLowerCase()});function ag(t,n,e){return e&&typeof e!="number"&&xt(t,n,e)&&(n=e=i),e=e===i?Ut:e>>>0,e?(t=X(t),t&&(typeof n=="string"||n!=null&&!ki(n))&&(n=Ot(n),!n&&Jn(t))?Pn(Xt(t),0,e):t.split(n,e)):[]}var fg=ne(function(t,n,e){return t+(e?" ":"")+Gi(n)});function cg(t,n,e){return t=X(t),e=e==null?0:Fn(B(e),0,t.length),n=Ot(n),t.slice(e,e+n.length)==n}function lg(t,n,e){var r=s.templateSettings;e&&xt(t,n,e)&&(n=i),t=X(t),n=Cr({},n,r,$s);var u=Cr({},n.imports,r.imports,$s),o=ht(u),a=ri(u,o),c,h,y=0,m=n.interpolate||Be,x="__p += '",A=ui((n.escape||Be).source+"|"+m.source+"|"+(m===au?ka:Be).source+"|"+(n.evaluate||Be).source+"|$","g"),I="//# sourceURL="+(Q.call(n,"sourceURL")?(n.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++mf+"]")+`
11
+ `;t.replace(A,function(W,k,G,Dt,St,Ft){return G||(G=Dt),x+=t.slice(y,Ft).replace(Xa,$f),k&&(c=!0,x+=`' +
12
+ __e(`+k+`) +
13
+ '`),St&&(h=!0,x+=`';
14
+ `+St+`;
15
+ __p += '`),G&&(x+=`' +
28
16
  ((__t = (`+G+`)) == null ? '' : __t) +
29
- '`),E=Nt+N.length,N}),T+=`';
30
- `;var D=X.call(e,"variable")&&e.variable;if(!D)T=`with (obj) {
31
- `+T+`
17
+ '`),y=Ft+W.length,W}),x+=`';
18
+ `;var O=Q.call(n,"variable")&&n.variable;if(!O)x=`with (obj) {
19
+ `+x+`
32
20
  }
33
- `;else if(cf.test(D))throw new F(m);T=(b?T.replace(Gl,""):T).replace(Kl,"$1").replace(Yl,"$1;"),T="function("+(D||"obj")+`) {
34
- `+(D?"":`obj || (obj = {});
35
- `)+"var __t, __p = ''"+(g?", __e = _.escape":"")+(b?`, __j = Array.prototype.join;
21
+ `;else if(Ka.test(O))throw new N(E);x=(h?x.replace(Ca,""):x).replace(Pa,"$1").replace(Ia,"$1;"),x="function("+(O||"obj")+`) {
22
+ `+(O?"":`obj || (obj = {});
23
+ `)+"var __t, __p = ''"+(c?", __e = _.escape":"")+(h?`, __j = Array.prototype.join;
36
24
  function print() { __p += __j.call(arguments, '') }
37
25
  `:`;
38
- `)+T+`return __p
39
- }`;var $=hc(function(){return V(l,L+"return "+T).apply(r,d)});if($.source=T,Ri($))throw $;return $}function Lm(t){return Z(t).toLowerCase()}function Bm(t){return Z(t).toUpperCase()}function km(t,e,s){if(t=Z(t),t&&(s||e===r))return va(t);if(!t||!(e=Bt(e)))return t;var o=ne(t),u=ne(e),l=wa(o,u),d=ya(o,u)+1;return Le(o,l,d).join("")}function Dm(t,e,s){if(t=Z(t),t&&(s||e===r))return t.slice(0,Ea(t)+1);if(!t||!(e=Bt(e)))return t;var o=ne(t),u=ya(o,ne(e))+1;return Le(o,0,u).join("")}function Nm(t,e,s){if(t=Z(t),t&&(s||e===r))return t.replace(Rs,"");if(!t||!(e=Bt(e)))return t;var o=ne(t),u=wa(o,ne(e));return Le(o,u).join("")}function Fm(t,e){var s=Ft,o=ft;if(st(e)){var u="separator"in e?e.separator:u;s="length"in e?W(e.length):s,o="omission"in e?Bt(e.omission):o}t=Z(t);var l=t.length;if(cn(t)){var d=ne(t);l=d.length}if(s>=l)return t;var g=s-hn(o);if(g<1)return o;var b=d?Le(d,0,g).join(""):t.slice(0,g);if(u===r)return b+o;if(d&&(g+=b.length-g),Mi(u)){if(t.slice(g).search(u)){var E,x=b;for(u.global||(u=Gs(u.source,Z($o.exec(u))+"g")),u.lastIndex=0;E=u.exec(x);)var T=E.index;b=b.slice(0,T===r?g:T)}}else if(t.indexOf(Bt(u),g)!=g){var M=b.lastIndexOf(u);M>-1&&(b=b.slice(0,M))}return b+o}function Um(t){return t=Z(t),t&&Vl.test(t)?t.replace(Fo,pd):t}var Wm=bn(function(t,e,s){return t+(s?" ":"")+e.toUpperCase()}),Li=lu("toUpperCase");function cc(t,e,s){return t=Z(t),e=s?r:e,e===r?cd(t)?bd(t):td(t):t.match(e)||[]}var hc=z(function(t,e){try{return Ot(t,r,e)}catch(s){return Ri(s)?s:new F(s)}}),$m=me(function(t,e){return $t(e,function(s){s=fe(s),_e(t,s,Ci(t[s],t))}),t});function qm(t){var e=t==null?0:t.length,s=k();return t=e?nt(t,function(o){if(typeof o[1]!="function")throw new qt(p);return[s(o[0]),o[1]]}):[],z(function(o){for(var u=-1;++u<e;){var l=t[u];if(Ot(l[0],this,o))return Ot(l[1],this,o)}})}function zm(t){return pp(Ht(t,C))}function Bi(t){return function(){return t}}function Hm(t,e){return t==null||t!==t?e:t}var Jm=du(),Gm=du(!0);function Mt(t){return t}function ki(t){return za(typeof t=="function"?t:Ht(t,C))}function Km(t){return Ja(Ht(t,C))}function Ym(t,e){return Ga(t,Ht(e,C))}var Vm=z(function(t,e){return function(s){return Hn(s,t,e)}}),Zm=z(function(t,e){return function(s){return Hn(t,s,e)}});function Di(t,e,s){var o=_t(e),u=kr(e,o);s==null&&!(st(e)&&(u.length||!o.length))&&(s=e,e=t,t=this,u=kr(e,_t(e)));var l=!(st(s)&&"chain"in s)||!!s.chain,d=we(t);return $t(u,function(g){var b=e[g];t[g]=b,d&&(t.prototype[g]=function(){var E=this.__chain__;if(l||E){var x=t(this.__wrapped__),T=x.__actions__=Ct(this.__actions__);return T.push({func:b,args:arguments,thisArg:t}),x.__chain__=E,x}return b.apply(t,Ce([this.value()],arguments))})}),t}function Xm(){return bt._===this&&(bt._=Ed),this}function Ni(){}function Qm(t){return t=W(t),z(function(e){return Ka(e,t)})}var jm=pi(nt),tv=pi(pa),ev=pi(Us);function lc(t){return yi(t)?Ws(fe(t)):Pp(t)}function nv(t){return function(e){return t==null?r:Ye(t,e)}}var rv=gu(),sv=gu(!0);function Fi(){return[]}function Ui(){return!1}function iv(){return{}}function ov(){return""}function av(){return!0}function uv(t,e){if(t=W(t),t<1||t>Te)return[];var s=ce,o=vt(t,ce);e=k(e),t-=ce;for(var u=zs(o,e);++s<t;)e(s);return u}function cv(t){return U(t)?nt(t,fe):kt(t)?[t]:Ct(Pu(Z(t)))}function hv(t){var e=++yd;return Z(t)+e}var lv=$r(function(t,e){return t+e},0),fv=gi("ceil"),dv=$r(function(t,e){return t/e},1),pv=gi("floor");function gv(t){return t&&t.length?Br(t,Mt,ti):r}function _v(t,e){return t&&t.length?Br(t,k(e,2),ti):r}function bv(t){return ba(t,Mt)}function mv(t,e){return ba(t,k(e,2))}function vv(t){return t&&t.length?Br(t,Mt,si):r}function wv(t,e){return t&&t.length?Br(t,k(e,2),si):r}var yv=$r(function(t,e){return t*e},1),Sv=gi("round"),Ev=$r(function(t,e){return t-e},0);function xv(t){return t&&t.length?qs(t,Mt):0}function Tv(t,e){return t&&t.length?qs(t,k(e,2)):0}return c.after=K_,c.ary=qu,c.assign=Bb,c.assignIn=nc,c.assignInWith=ts,c.assignWith=kb,c.at=Db,c.before=zu,c.bind=Ci,c.bindAll=$m,c.bindKey=Hu,c.castArray=ib,c.chain=Uu,c.chunk=pg,c.compact=gg,c.concat=_g,c.cond=qm,c.conforms=zm,c.constant=Bi,c.countBy=x_,c.create=Nb,c.curry=Ju,c.curryRight=Gu,c.debounce=Ku,c.defaults=Fb,c.defaultsDeep=Ub,c.defer=Y_,c.delay=V_,c.difference=bg,c.differenceBy=mg,c.differenceWith=vg,c.drop=wg,c.dropRight=yg,c.dropRightWhile=Sg,c.dropWhile=Eg,c.fill=xg,c.filter=A_,c.flatMap=R_,c.flatMapDeep=M_,c.flatMapDepth=P_,c.flatten=ku,c.flattenDeep=Tg,c.flattenDepth=Ag,c.flip=Z_,c.flow=Jm,c.flowRight=Gm,c.fromPairs=Cg,c.functions=Gb,c.functionsIn=Kb,c.groupBy=O_,c.initial=Rg,c.intersection=Mg,c.intersectionBy=Pg,c.intersectionWith=Og,c.invert=Vb,c.invertBy=Zb,c.invokeMap=B_,c.iteratee=ki,c.keyBy=k_,c.keys=_t,c.keysIn=Rt,c.map=Yr,c.mapKeys=Qb,c.mapValues=jb,c.matches=Km,c.matchesProperty=Ym,c.memoize=Zr,c.merge=tm,c.mergeWith=rc,c.method=Vm,c.methodOf=Zm,c.mixin=Di,c.negate=Xr,c.nthArg=Qm,c.omit=em,c.omitBy=nm,c.once=X_,c.orderBy=D_,c.over=jm,c.overArgs=Q_,c.overEvery=tv,c.overSome=ev,c.partial=Ii,c.partialRight=Yu,c.partition=N_,c.pick=rm,c.pickBy=sc,c.property=lc,c.propertyOf=nv,c.pull=Dg,c.pullAll=Nu,c.pullAllBy=Ng,c.pullAllWith=Fg,c.pullAt=Ug,c.range=rv,c.rangeRight=sv,c.rearg=j_,c.reject=W_,c.remove=Wg,c.rest=tb,c.reverse=Ti,c.sampleSize=q_,c.set=im,c.setWith=om,c.shuffle=z_,c.slice=$g,c.sortBy=G_,c.sortedUniq=Yg,c.sortedUniqBy=Vg,c.split=Rm,c.spread=eb,c.tail=Zg,c.take=Xg,c.takeRight=Qg,c.takeRightWhile=jg,c.takeWhile=t_,c.tap=g_,c.throttle=nb,c.thru=Kr,c.toArray=ju,c.toPairs=ic,c.toPairsIn=oc,c.toPath=cv,c.toPlainObject=ec,c.transform=am,c.unary=rb,c.union=e_,c.unionBy=n_,c.unionWith=r_,c.uniq=s_,c.uniqBy=i_,c.uniqWith=o_,c.unset=um,c.unzip=Ai,c.unzipWith=Fu,c.update=cm,c.updateWith=hm,c.values=wn,c.valuesIn=lm,c.without=a_,c.words=cc,c.wrap=sb,c.xor=u_,c.xorBy=c_,c.xorWith=h_,c.zip=l_,c.zipObject=f_,c.zipObjectDeep=d_,c.zipWith=p_,c.entries=ic,c.entriesIn=oc,c.extend=nc,c.extendWith=ts,Di(c,c),c.add=lv,c.attempt=hc,c.camelCase=gm,c.capitalize=ac,c.ceil=fv,c.clamp=fm,c.clone=ob,c.cloneDeep=ub,c.cloneDeepWith=cb,c.cloneWith=ab,c.conformsTo=hb,c.deburr=uc,c.defaultTo=Hm,c.divide=dv,c.endsWith=_m,c.eq=se,c.escape=bm,c.escapeRegExp=mm,c.every=T_,c.find=C_,c.findIndex=Lu,c.findKey=Wb,c.findLast=I_,c.findLastIndex=Bu,c.findLastKey=$b,c.floor=pv,c.forEach=Wu,c.forEachRight=$u,c.forIn=qb,c.forInRight=zb,c.forOwn=Hb,c.forOwnRight=Jb,c.get=Pi,c.gt=lb,c.gte=fb,c.has=Yb,c.hasIn=Oi,c.head=Du,c.identity=Mt,c.includes=L_,c.indexOf=Ig,c.inRange=dm,c.invoke=Xb,c.isArguments=Xe,c.isArray=U,c.isArrayBuffer=db,c.isArrayLike=It,c.isArrayLikeObject=at,c.isBoolean=pb,c.isBuffer=Be,c.isDate=gb,c.isElement=_b,c.isEmpty=bb,c.isEqual=mb,c.isEqualWith=vb,c.isError=Ri,c.isFinite=wb,c.isFunction=we,c.isInteger=Vu,c.isLength=Qr,c.isMap=Zu,c.isMatch=yb,c.isMatchWith=Sb,c.isNaN=Eb,c.isNative=xb,c.isNil=Ab,c.isNull=Tb,c.isNumber=Xu,c.isObject=st,c.isObjectLike=ot,c.isPlainObject=Zn,c.isRegExp=Mi,c.isSafeInteger=Cb,c.isSet=Qu,c.isString=jr,c.isSymbol=kt,c.isTypedArray=vn,c.isUndefined=Ib,c.isWeakMap=Rb,c.isWeakSet=Mb,c.join=Lg,c.kebabCase=vm,c.last=Gt,c.lastIndexOf=Bg,c.lowerCase=wm,c.lowerFirst=ym,c.lt=Pb,c.lte=Ob,c.max=gv,c.maxBy=_v,c.mean=bv,c.meanBy=mv,c.min=vv,c.minBy=wv,c.stubArray=Fi,c.stubFalse=Ui,c.stubObject=iv,c.stubString=ov,c.stubTrue=av,c.multiply=yv,c.nth=kg,c.noConflict=Xm,c.noop=Ni,c.now=Vr,c.pad=Sm,c.padEnd=Em,c.padStart=xm,c.parseInt=Tm,c.random=pm,c.reduce=F_,c.reduceRight=U_,c.repeat=Am,c.replace=Cm,c.result=sm,c.round=Sv,c.runInContext=_,c.sample=$_,c.size=H_,c.snakeCase=Im,c.some=J_,c.sortedIndex=qg,c.sortedIndexBy=zg,c.sortedIndexOf=Hg,c.sortedLastIndex=Jg,c.sortedLastIndexBy=Gg,c.sortedLastIndexOf=Kg,c.startCase=Mm,c.startsWith=Pm,c.subtract=Ev,c.sum=xv,c.sumBy=Tv,c.template=Om,c.times=uv,c.toFinite=ye,c.toInteger=W,c.toLength=tc,c.toLower=Lm,c.toNumber=Kt,c.toSafeInteger=Lb,c.toString=Z,c.toUpper=Bm,c.trim=km,c.trimEnd=Dm,c.trimStart=Nm,c.truncate=Fm,c.unescape=Um,c.uniqueId=hv,c.upperCase=Wm,c.upperFirst=Li,c.each=Wu,c.eachRight=$u,c.first=Du,Di(c,function(){var t={};return he(c,function(e,s){X.call(c.prototype,s)||(t[s]=e)}),t}(),{chain:!1}),c.VERSION=a,$t(["bind","bindKey","curry","curryRight","partial","partialRight"],function(t){c[t].placeholder=c}),$t(["drop","take"],function(t,e){J.prototype[t]=function(s){s=s===r?1:pt(W(s),0);var o=this.__filtered__&&!e?new J(this):this.clone();return o.__filtered__?o.__takeCount__=vt(s,o.__takeCount__):o.__views__.push({size:vt(s,ce),type:t+(o.__dir__<0?"Right":"")}),o},J.prototype[t+"Right"]=function(s){return this.reverse()[t](s).reverse()}}),$t(["filter","map","takeWhile"],function(t,e){var s=e+1,o=s==St||s==kl;J.prototype[t]=function(u){var l=this.clone();return l.__iteratees__.push({iteratee:k(u,3),type:s}),l.__filtered__=l.__filtered__||o,l}}),$t(["head","last"],function(t,e){var s="take"+(e?"Right":"");J.prototype[t]=function(){return this[s](1).value()[0]}}),$t(["initial","tail"],function(t,e){var s="drop"+(e?"":"Right");J.prototype[t]=function(){return this.__filtered__?new J(this):this[s](1)}}),J.prototype.compact=function(){return this.filter(Mt)},J.prototype.find=function(t){return this.filter(t).head()},J.prototype.findLast=function(t){return this.reverse().find(t)},J.prototype.invokeMap=z(function(t,e){return typeof t=="function"?new J(this):this.map(function(s){return Hn(s,t,e)})}),J.prototype.reject=function(t){return this.filter(Xr(k(t)))},J.prototype.slice=function(t,e){t=W(t);var s=this;return s.__filtered__&&(t>0||e<0)?new J(s):(t<0?s=s.takeRight(-t):t&&(s=s.drop(t)),e!==r&&(e=W(e),s=e<0?s.dropRight(-e):s.take(e-t)),s)},J.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},J.prototype.toArray=function(){return this.take(ce)},he(J.prototype,function(t,e){var s=/^(?:filter|find|map|reject)|While$/.test(e),o=/^(?:head|last)$/.test(e),u=c[o?"take"+(e=="last"?"Right":""):e],l=o||/^find/.test(e);u&&(c.prototype[e]=function(){var d=this.__wrapped__,g=o?[1]:arguments,b=d instanceof J,E=g[0],x=b||U(d),T=function(H){var G=u.apply(c,Ce([H],g));return o&&M?G[0]:G};x&&s&&typeof E=="function"&&E.length!=1&&(b=x=!1);var M=this.__chain__,L=!!this.__actions__.length,D=l&&!M,$=b&&!L;if(!l&&x){d=$?d:new J(this);var N=t.apply(d,g);return N.__actions__.push({func:Kr,args:[T],thisArg:r}),new zt(N,M)}return D&&$?t.apply(this,g):(N=this.thru(T),D?o?N.value()[0]:N.value():N)})}),$t(["pop","push","shift","sort","splice","unshift"],function(t){var e=vr[t],s=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",o=/^(?:pop|shift)$/.test(t);c.prototype[t]=function(){var u=arguments;if(o&&!this.__chain__){var l=this.value();return e.apply(U(l)?l:[],u)}return this[s](function(d){return e.apply(U(d)?d:[],u)})}}),he(J.prototype,function(t,e){var s=c[e];if(s){var o=s.name+"";X.call(pn,o)||(pn[o]=[]),pn[o].push({name:e,func:s})}}),pn[Wr(r,ct).name]=[{name:"wrapper",func:r}],J.prototype.clone=Ud,J.prototype.reverse=Wd,J.prototype.value=$d,c.prototype.at=__,c.prototype.chain=b_,c.prototype.commit=m_,c.prototype.next=v_,c.prototype.plant=y_,c.prototype.reverse=S_,c.prototype.toJSON=c.prototype.valueOf=c.prototype.value=E_,c.prototype.first=c.prototype.head,Nn&&(c.prototype[Nn]=w_),c},ln=md();ze?((ze.exports=ln)._=ln,ks._=ln):bt._=ln}).call(oe)}(ir,ir.exports);var bl=ir.exports;const ml=$i(bl);class vl{constructor(i){S(this,"config");this.config=i}async complete(i,r){var a;await this.persist(i,{...r,success:!0}),(a=this.config.logger)==null||a.debug("Transaction completed:",i)}async fail(i,r){var a;await this.persist(i,{...r,success:!1}),(a=this.config.logger)==null||a.debug("Transaction failed:",{...i,...r})}async persist(i,r){await fetch(`${this.config.apiUrl}/transactions/${i.id}`,{body:JSON.stringify(r),method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","x-persona-apikey":this.config.apiKey}})}}class wl{constructor(i,r){S(this,"transaction");S(this,"manager");this.transaction=i,this.manager=r}getFunctionCall(){return this.transaction.functionCall}async invoke(i,r){var m;const a=this.transaction.functionCall;if(!a){await this.fail("No function call found");return}const h=a.name,f=a.args,p=i[h];if(!p){await this.fail(`Tool ${h} not found`);return}try{const w=ml.get(r,"schema.config.parameters.properties",{}),P=(w&&Object.keys(w).length>0?Object.keys(w):((m=p.toString().replace(/\n/g," ").match(/^[^(]*\(([^)]*)\)/))==null?void 0:m[1].split(",").map(A=>A.trim()).filter(Boolean))||[]).map(A=>f[A]),C=await p.apply(null,P);await this.complete(C)}catch(w){await this.fail(`Error executing tool ${h}: ${w}`)}}async complete(i){await this.manager.complete(this.transaction,{success:!0,output:i,error:null})}async fail(i){await this.manager.fail(this.transaction,{success:!1,output:null,error:i})}}class Oo extends Cn{constructor(r){super();S(this,"status");S(this,"autostart");S(this,"session");S(this,"config");S(this,"notify",!0);S(this,"_tools");S(this,"_toolSchema",{});if(this.config=r,this.status="disconnected",this.autostart=!0,Array.isArray(r.tools)){this._tools={};for(const a of r.tools)a.schema&&a.implementation&&(this._tools[a.schema.name]=a.implementation,this._toolSchema[a.schema.name]=a)}else this._tools=r.tools}getName(){return"transaction"}getPriority(){return 0}getToolInstance(r){return this._toolSchema[r]}async connect(r){return this.setStatus("connected"),r}async disconnect(){this.setStatus("disconnected"),this.session=null}async syncSession(r){this.session=r}async sendPacket(r){}onTransaction(r){const a=new vl(this.config),h=new wl(r,a);if(this.config.onTransaction)this.config.onTransaction(h);else{const f=r.functionCall?this.getToolInstance(r.functionCall.name):void 0;h.invoke(this._tools,f)}}getTools(){return this._tools}}const In=B.createContext(void 0);function yl(n){return new Promise((i,r)=>{const a=new FileReader;a.readAsDataURL(n),a.onload=()=>{const f=a.result.split(";base64,")[1];i(f)},a.onerror=h=>{r(h)}})}function Sl(n){const i={rest:r=>r.config.apiUrl,webrtc:r=>r.config.webrtcUrl.replace("/webrtc","").replace("ws://","http://").replace("wss://","https://"),websocket:r=>r.config.webSocketUrl.replace("/websocket","").replace("ws://","http://").replace("wss://","https://")};for(const r of n){const a=i[r.getName()];if(a)return a(r)}return null}function El({dev:n=!1,baseUrl:i,protocols:r,logger:a,children:h,session:f="new",transformMessages:p,...m}){const[w,I]=B.useState(!1),[P,C]=B.useState([]),[A,R]=B.useState(f),[K,At]=B.useState(new Map),gt=B.useRef(!1),ct=B.useMemo(()=>{if(Array.isArray(r))return r;if(typeof r=="object"&&r!==null){const q=n?"localhost:8000":i||"persona.applica.guru/api",ht=n?"http":"https",Q=n?"ws":"wss";let Ft=Object.keys(r).map(ft=>{switch(ft){case"rest":const Ut=r[ft];return Ut===!0?new _s({apiUrl:`${ht}://${q}`,apiKey:m.apiKey,agentId:m.agentId,logger:a}):typeof Ut=="object"&&Ut!==null?new _s(Ut):null;case"webrtc":const it=r[ft];return it===!0?new ms({webrtcUrl:`${Q}://${q}/webrtc`,apiKey:m.apiKey,agentId:m.agentId,logger:a}):typeof it=="object"&&it!==null?new ms(it):null;case"websocket":const St=r[ft];return St===!0?new bs({webSocketUrl:`${Q}://${q}/websocket`,apiKey:m.apiKey,agentId:m.agentId,logger:a}):typeof St=="object"&&St!==null?new bs(St):null;default:throw new Error(`Unknown protocol: ${ft}`)}}).filter(ft=>ft!==null);return m.tools&&Ft.push(new Oo({apiUrl:`${ht}://${q}`,apiKey:m.apiKey,agentId:m.agentId,tools:m.tools,logger:a})),Ft}throw new Error("Invalid protocols configuration")},[]);B.useEffect(()=>{gt.current||(gt.current=!0,a==null||a.debug("Initializing protocols: ",ct.map(q=>q.getName())),ct.forEach(q=>{q.setSession(A),q.clearListeners(),q.addStatusChangeListener(ht=>{a==null||a.debug(`${q.getName()} has notified new status: ${ht}`),K.set(q.getName(),ht),ht==="connected"&&(m.context&&q.sendPacket({type:"command",payload:{command:"set_initial_context",arguments:m.context}}),m.tools&&Array.isArray(m.tools)&&q.sendPacket({type:"command",payload:{command:"set_local_tools",arguments:{tools:m.tools.map(Q=>Q.schema)}}})),At(new Map(K))}),q.addPacketListener(ht=>{if(ht.type==="message"){const Q=ht.payload;(Q==null?void 0:Q.finishReason)==="stop"&&!(Q!=null&&Q.functionResponse)&&!(Q!=null&&Q.thought)&&I(!1),Q.thought&&(Q.type="reasoning"),C(Ft=>{const ft=Po([...Ft,{...Q,protocol:q.getName()}]);return p?p(ft):ft})}else if(ht.type==="reasoning"){const Ft={type:"reasoning",text:ht.payload.thought,role:"assistant",finishReason:"stop"};C(ft=>{const Ut=Po([...ft,{...Ft,protocol:q.getName()}]);return p?p(Ut):Ut})}else ht.type==="transaction"&&ct.filter(Q=>Q!==q).forEach(Q=>Q.onTransaction(ht.payload))}),q.autostart&&q.status==="disconnected"&&(a==null||a.debug(`Connecting to protocol: ${q.getName()}`),q.connect(A),I(!1))}))},[A,ct,a,K,p]);const ar=async q=>{var Ut;if(((Ut=q.content[0])==null?void 0:Ut.type)!=="text")throw new Error("Only text messages are supported");if(!ct.some(it=>it.getName()!=="transaction"&&it.status==="connected")){C(it=>{const St=[...it,{role:"assistant",type:"text",text:"No protocol is connected."}];return p?p(St):St});return}const Q=q.content[0].text;C(it=>{const St=[...it,{role:"user",type:"text",text:Q}];return p?p(St):St}),I(!0);const Ft=ct.sort((it,St)=>St.getPriority()-it.getPriority()).find(it=>it.status==="connected"),ft=[];if(q.attachments)for(const it of q.attachments)it.contentType.startsWith("image/")&&it.file&&ft.push({role:"user",image:{contentType:it.contentType,content:await yl(it.file)},text:"",type:"text"});q.content&&ft.push({role:"user",text:q.content[0].text,type:"text"}),a==null||a.debug("Sending message:",ft),await(Ft==null?void 0:Ft.sendPacket({type:"request",payload:ft}))},Qt=B.useCallback(()=>(I(!1),C([]),R("new"),Promise.resolve()),[]),We=B.useCallback(()=>Promise.resolve(),[]),jt=B.useCallback(()=>P,[P]),$e=ch({isRunning:w,messages:P,convertMessage:gl,onNew:ar,onCancel:Qt,onReload:We,adapters:{attachments:new Xc([new Vc])}});return Ee.jsx(In.Provider,{value:{protocols:ct,protocolsStatus:K,getMessages:jt},children:Ee.jsx(fl,{runtime:$e,children:h})})}function xl({children:n,...i}){return Ee.jsx(El,{...i,children:n})}function Tl(){const n=B.useContext(In);if(!n)throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");return n}function Lo(n){const i=B.useContext(In);if(!i)throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");const r=i.protocols.find(h=>h.getName()===n);if(!r)return null;const a=i.protocolsStatus.get(r.getName());return{...r,connect:r.connect.bind(r),disconnect:r.disconnect.bind(r),sendPacket:r.sendPacket.bind(r),setSession:r.setSession.bind(r),addStatusChangeListener:r.addStatusChangeListener.bind(r),addPacketListener:r.addPacketListener.bind(r),getName:r.getName.bind(r),getPriority:r.getPriority.bind(r),status:a||r.status}}function Al(){const n=B.useContext(In);if(!n)throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");return Sl(n.protocols)}function Cl(){return Lo("webrtc")}function Il(){const n=B.useContext(In);if(!n)throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");return n.getMessages()}class Rl{constructor(){S(this,"prefix","[Persona]")}log(i,...r){console.log(`${this.prefix} - ${i}`,...r)}info(i,...r){console.info(`${this.prefix} - ${i}`,...r)}warn(i,...r){console.warn(`${this.prefix} - ${i}`,...r)}error(i,...r){console.error(`${this.prefix} - ${i}`,...r)}debug(i,...r){console.debug(`${this.prefix} - ${i}`,...r)}}function Fe(n,i,r){return{type:n,description:i,...r}}function Bo(n){const i=Object.entries(n.parameters).filter(([r,a])=>a.required).map(([r])=>r);return{type:"local",name:n.name,description:n.description,config:{timeout:n.timeout||60,parameters:{type:"object",title:n.title||`${n.name} parameters`,required:i,properties:n.parameters},output:{type:"object",title:`${n.name} output`,properties:n.output}}}}function or(n){return{schema:Bo(n),implementation:n.implementation}}function ko(n,i,r,a,h,f){const p={name:n,description:i,title:f==null?void 0:f.title,timeout:f==null?void 0:f.timeout,parameters:a,output:h,implementation:r};return or(p)}const Ml=ko("sum","Sum two numbers",function(i,r){return{result:i+r}},{a:Fe("number","First number to sum",{required:!0}),b:Fe("number","Second number to sum",{required:!0})},{result:Fe("number","Sum of two numbers")}),Pl=or({name:"navigate_to",description:"Allow agent to redirect user to specific sub page like /foo or #/foo or anything like that",title:"Sum two numbers",timeout:60,parameters:{a:Fe("number","First number to sum"),b:Fe("number","Seconth number to sum")},output:{result:Fe("number","Sum of two numbers")},implementation:function(i,r){return{result:i+r}}});function Ol(n){const i=[],r={};return n.forEach(a=>{const{schema:h,implementation:f}=or(a);i.push(h),r[a.name]=f}),{schemas:i,implementations:r}}function Ll(n,i){const{required:r,properties:a}=i.config.parameters;for(const h of r)if(!(h in n))throw new Error(`Missing required parameter: ${h}`);for(const[h,f]of Object.entries(n)){const p=a[h];if(p){if(p.type==="number"&&typeof f!="number")throw new Error(`Parameter ${h} should be a number`);if(p.type==="string"&&typeof f!="string")throw new Error(`Parameter ${h} should be a string`);if(p.type==="boolean"&&typeof f!="boolean")throw new Error(`Parameter ${h} should be a boolean`)}}return!0}Y.PersonaConsoleLogger=Rl,Y.PersonaProtocolBase=Cn,Y.PersonaRESTProtocol=_s,Y.PersonaRuntimeProvider=xl,Y.PersonaTransactionProtocol=Oo,Y.PersonaWebRTCProtocol=ms,Y.PersonaWebSocketProtocol=bs,Y.createParameter=Fe,Y.createTool=or,Y.createToolFromFunction=ko,Y.createToolRegistry=Ol,Y.generateToolSchema=Bo,Y.navigateToToolExample=Pl,Y.sumTool=Ml,Y.usePersonaRuntime=Tl,Y.usePersonaRuntimeEndpoint=Al,Y.usePersonaRuntimeMessages=Il,Y.usePersonaRuntimeProtocol=Lo,Y.usePersonaRuntimeWebRTCProtocol=Cl,Y.validateToolParameters=Ll,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})});
26
+ `)+x+`return __p
27
+ }`;var $=Wo(function(){return Z(o,I+"return "+x).apply(i,a)});if($.source=x,qi($))throw $;return $}function hg(t){return X(t).toLowerCase()}function dg(t){return X(t).toUpperCase()}function pg(t,n,e){if(t=X(t),t&&(e||n===i))return Ku(t);if(!t||!(n=Ot(n)))return t;var r=Xt(t),u=Xt(n),o=qu(r,u),a=ku(r,u)+1;return Pn(r,o,a).join("")}function gg(t,n,e){if(t=X(t),t&&(e||n===i))return t.slice(0,Hu(t)+1);if(!t||!(n=Ot(n)))return t;var r=Xt(t),u=ku(r,Xt(n))+1;return Pn(r,0,u).join("")}function _g(t,n,e){if(t=X(t),t&&(e||n===i))return t.replace(qr,"");if(!t||!(n=Ot(n)))return t;var r=Xt(t),u=qu(r,Xt(n));return Pn(r,u).join("")}function vg(t,n){var e=Oe,r=Et;if(rt(n)){var u="separator"in n?n.separator:u;e="length"in n?B(n.length):e,r="omission"in n?Ot(n.omission):r}t=X(t);var o=t.length;if(Jn(t)){var a=Xt(t);o=a.length}if(e>=o)return t;var c=e-Zn(r);if(c<1)return r;var h=a?Pn(a,0,c).join(""):t.slice(0,c);if(u===i)return h+r;if(a&&(c+=h.length-c),ki(u)){if(t.slice(c).search(u)){var y,m=h;for(u.global||(u=ui(u.source,X(fu.exec(u))+"g")),u.lastIndex=0;y=u.exec(m);)var x=y.index;h=h.slice(0,x===i?c:x)}}else if(t.indexOf(Ot(u),c)!=c){var A=h.lastIndexOf(u);A>-1&&(h=h.slice(0,A))}return h+r}function wg(t){return t=X(t),t&&Ra.test(t)?t.replace(su,Jf):t}var yg=ne(function(t,n,e){return t+(e?" ":"")+n.toUpperCase()}),Gi=Ws("toUpperCase");function Oo(t,n,e){return t=X(t),n=e?i:n,n===i?qf(t)?Xf(t):Wf(t):t.match(n)||[]}var Wo=K(function(t,n){try{return Tt(t,i,n)}catch(e){return qi(e)?e:new N(e)}}),mg=hn(function(t,n){return Mt(n,function(e){e=un(e),cn(t,e,$i(t[e],t))}),t});function xg(t){var n=t==null?0:t.length,e=L();return t=n?et(t,function(r){if(typeof r[1]!="function")throw new $t(S);return[e(r[0]),r[1]]}):[],K(function(r){for(var u=-1;++u<n;){var o=t[u];if(Tt(o[0],this,r))return Tt(o[1],this,r)}})}function Sg(t){return Jc(qt(t,P))}function Ji(t){return function(){return t}}function Ag(t,n){return t==null||t!==t?n:t}var bg=Fs(),Cg=Fs(!0);function It(t){return t}function Zi(t){return ls(typeof t=="function"?t:qt(t,P))}function Pg(t){return ds(qt(t,P))}function Ig(t,n){return ps(t,qt(n,P))}var Rg=K(function(t,n){return function(e){return Se(e,t,n)}}),Eg=K(function(t,n){return function(e){return Se(t,e,n)}});function Yi(t,n,e){var r=ht(n),u=sr(n,r);e==null&&!(rt(n)&&(u.length||!r.length))&&(e=n,n=t,t=this,u=sr(n,ht(n)));var o=!(rt(e)&&"chain"in e)||!!e.chain,a=pn(t);return Mt(u,function(c){var h=n[c];t[c]=h,a&&(t.prototype[c]=function(){var y=this.__chain__;if(o||y){var m=t(this.__wrapped__),x=m.__actions__=bt(this.__actions__);return x.push({func:h,args:arguments,thisArg:t}),m.__chain__=y,m}return h.apply(t,mn([this.value()],arguments))})}),t}function Tg(){return dt._===this&&(dt._=ec),this}function Xi(){}function Lg(t){return t=B(t),K(function(n){return gs(n,t)})}var Og=Ii(et),Wg=Ii(Nu),Dg=Ii(Vr);function Do(t){return Di(t)?jr(un(t)):cl(t)}function Fg(t){return function(n){return t==null?i:Nn(t,n)}}var Ng=Us(),Ug=Us(!0);function Qi(){return[]}function Vi(){return!1}function Bg(){return{}}function Mg(){return""}function $g(){return!0}function Kg(t,n){if(t=B(t),t<1||t>nn)return[];var e=Ut,r=gt(t,Ut);n=L(n),t-=Ut;for(var u=ei(r,n);++e<t;)n(e);return u}function qg(t){return U(t)?et(t,un):Wt(t)?[t]:bt(js(X(t)))}function kg(t){var n=++tc;return X(t)+n}var zg=hr(function(t,n){return t+n},0),Hg=Ri("ceil"),Gg=hr(function(t,n){return t/n},1),Jg=Ri("floor");function Zg(t){return t&&t.length?ur(t,It,di):i}function Yg(t,n){return t&&t.length?ur(t,L(n,2),di):i}function Xg(t){return Mu(t,It)}function Qg(t,n){return Mu(t,L(n,2))}function Vg(t){return t&&t.length?ur(t,It,vi):i}function jg(t,n){return t&&t.length?ur(t,L(n,2),vi):i}var t_=hr(function(t,n){return t*n},1),n_=Ri("round"),e_=hr(function(t,n){return t-n},0);function r_(t){return t&&t.length?ni(t,It):0}function i_(t,n){return t&&t.length?ni(t,L(n,2)):0}return s.after=Pd,s.ary=co,s.assign=dp,s.assignIn=Co,s.assignInWith=Cr,s.assignWith=pp,s.at=gp,s.before=lo,s.bind=$i,s.bindAll=mg,s.bindKey=ho,s.castArray=Bd,s.chain=oo,s.chunk=Jl,s.compact=Zl,s.concat=Yl,s.cond=xg,s.conforms=Sg,s.constant=Ji,s.countBy=rd,s.create=_p,s.curry=po,s.curryRight=go,s.debounce=_o,s.defaults=vp,s.defaultsDeep=wp,s.defer=Id,s.delay=Rd,s.difference=Xl,s.differenceBy=Ql,s.differenceWith=Vl,s.drop=jl,s.dropRight=th,s.dropRightWhile=nh,s.dropWhile=eh,s.fill=rh,s.filter=ud,s.flatMap=ad,s.flatMapDeep=fd,s.flatMapDepth=cd,s.flatten=ro,s.flattenDeep=ih,s.flattenDepth=uh,s.flip=Ed,s.flow=bg,s.flowRight=Cg,s.fromPairs=sh,s.functions=Cp,s.functionsIn=Pp,s.groupBy=ld,s.initial=ah,s.intersection=fh,s.intersectionBy=ch,s.intersectionWith=lh,s.invert=Rp,s.invertBy=Ep,s.invokeMap=dd,s.iteratee=Zi,s.keyBy=pd,s.keys=ht,s.keysIn=Pt,s.map=yr,s.mapKeys=Lp,s.mapValues=Op,s.matches=Pg,s.matchesProperty=Ig,s.memoize=xr,s.merge=Wp,s.mergeWith=Po,s.method=Rg,s.methodOf=Eg,s.mixin=Yi,s.negate=Sr,s.nthArg=Lg,s.omit=Dp,s.omitBy=Fp,s.once=Td,s.orderBy=gd,s.over=Og,s.overArgs=Ld,s.overEvery=Wg,s.overSome=Dg,s.partial=Ki,s.partialRight=vo,s.partition=_d,s.pick=Np,s.pickBy=Io,s.property=Do,s.propertyOf=Fg,s.pull=gh,s.pullAll=uo,s.pullAllBy=_h,s.pullAllWith=vh,s.pullAt=wh,s.range=Ng,s.rangeRight=Ug,s.rearg=Od,s.reject=yd,s.remove=yh,s.rest=Wd,s.reverse=Bi,s.sampleSize=xd,s.set=Bp,s.setWith=Mp,s.shuffle=Sd,s.slice=mh,s.sortBy=Cd,s.sortedUniq=Ih,s.sortedUniqBy=Rh,s.split=ag,s.spread=Dd,s.tail=Eh,s.take=Th,s.takeRight=Lh,s.takeRightWhile=Oh,s.takeWhile=Wh,s.tap=Zh,s.throttle=Fd,s.thru=wr,s.toArray=So,s.toPairs=Ro,s.toPairsIn=Eo,s.toPath=qg,s.toPlainObject=bo,s.transform=$p,s.unary=Nd,s.union=Dh,s.unionBy=Fh,s.unionWith=Nh,s.uniq=Uh,s.uniqBy=Bh,s.uniqWith=Mh,s.unset=Kp,s.unzip=Mi,s.unzipWith=so,s.update=qp,s.updateWith=kp,s.values=ie,s.valuesIn=zp,s.without=$h,s.words=Oo,s.wrap=Ud,s.xor=Kh,s.xorBy=qh,s.xorWith=kh,s.zip=zh,s.zipObject=Hh,s.zipObjectDeep=Gh,s.zipWith=Jh,s.entries=Ro,s.entriesIn=Eo,s.extend=Co,s.extendWith=Cr,Yi(s,s),s.add=zg,s.attempt=Wo,s.camelCase=Zp,s.capitalize=To,s.ceil=Hg,s.clamp=Hp,s.clone=Md,s.cloneDeep=Kd,s.cloneDeepWith=qd,s.cloneWith=$d,s.conformsTo=kd,s.deburr=Lo,s.defaultTo=Ag,s.divide=Gg,s.endsWith=Yp,s.eq=Vt,s.escape=Xp,s.escapeRegExp=Qp,s.every=id,s.find=sd,s.findIndex=no,s.findKey=yp,s.findLast=od,s.findLastIndex=eo,s.findLastKey=mp,s.floor=Jg,s.forEach=ao,s.forEachRight=fo,s.forIn=xp,s.forInRight=Sp,s.forOwn=Ap,s.forOwnRight=bp,s.get=zi,s.gt=zd,s.gte=Hd,s.has=Ip,s.hasIn=Hi,s.head=io,s.identity=It,s.includes=hd,s.indexOf=oh,s.inRange=Gp,s.invoke=Tp,s.isArguments=Mn,s.isArray=U,s.isArrayBuffer=Gd,s.isArrayLike=Ct,s.isArrayLikeObject=ut,s.isBoolean=Jd,s.isBuffer=In,s.isDate=Zd,s.isElement=Yd,s.isEmpty=Xd,s.isEqual=Qd,s.isEqualWith=Vd,s.isError=qi,s.isFinite=jd,s.isFunction=pn,s.isInteger=wo,s.isLength=Ar,s.isMap=yo,s.isMatch=tp,s.isMatchWith=np,s.isNaN=ep,s.isNative=rp,s.isNil=up,s.isNull=ip,s.isNumber=mo,s.isObject=rt,s.isObjectLike=it,s.isPlainObject=Re,s.isRegExp=ki,s.isSafeInteger=sp,s.isSet=xo,s.isString=br,s.isSymbol=Wt,s.isTypedArray=re,s.isUndefined=op,s.isWeakMap=ap,s.isWeakSet=fp,s.join=hh,s.kebabCase=Vp,s.last=zt,s.lastIndexOf=dh,s.lowerCase=jp,s.lowerFirst=tg,s.lt=cp,s.lte=lp,s.max=Zg,s.maxBy=Yg,s.mean=Xg,s.meanBy=Qg,s.min=Vg,s.minBy=jg,s.stubArray=Qi,s.stubFalse=Vi,s.stubObject=Bg,s.stubString=Mg,s.stubTrue=$g,s.multiply=t_,s.nth=ph,s.noConflict=Tg,s.noop=Xi,s.now=mr,s.pad=ng,s.padEnd=eg,s.padStart=rg,s.parseInt=ig,s.random=Jp,s.reduce=vd,s.reduceRight=wd,s.repeat=ug,s.replace=sg,s.result=Up,s.round=n_,s.runInContext=l,s.sample=md,s.size=Ad,s.snakeCase=og,s.some=bd,s.sortedIndex=xh,s.sortedIndexBy=Sh,s.sortedIndexOf=Ah,s.sortedLastIndex=bh,s.sortedLastIndexBy=Ch,s.sortedLastIndexOf=Ph,s.startCase=fg,s.startsWith=cg,s.subtract=e_,s.sum=r_,s.sumBy=i_,s.template=lg,s.times=Kg,s.toFinite=gn,s.toInteger=B,s.toLength=Ao,s.toLower=hg,s.toNumber=Ht,s.toSafeInteger=hp,s.toString=X,s.toUpper=dg,s.trim=pg,s.trimEnd=gg,s.trimStart=_g,s.truncate=vg,s.unescape=wg,s.uniqueId=kg,s.upperCase=yg,s.upperFirst=Gi,s.each=ao,s.eachRight=fo,s.first=io,Yi(s,function(){var t={};return en(s,function(n,e){Q.call(s.prototype,e)||(t[e]=n)}),t}(),{chain:!1}),s.VERSION=p,Mt(["bind","bindKey","curry","curryRight","partial","partialRight"],function(t){s[t].placeholder=s}),Mt(["drop","take"],function(t,n){z.prototype[t]=function(e){e=e===i?1:ft(B(e),0);var r=this.__filtered__&&!n?new z(this):this.clone();return r.__filtered__?r.__takeCount__=gt(e,r.__takeCount__):r.__views__.push({size:gt(e,Ut),type:t+(r.__dir__<0?"Right":"")}),r},z.prototype[t+"Right"]=function(e){return this.reverse()[t](e).reverse()}}),Mt(["filter","map","takeWhile"],function(t,n){var e=n+1,r=e==ae||e==Er;z.prototype[t]=function(u){var o=this.clone();return o.__iteratees__.push({iteratee:L(u,3),type:e}),o.__filtered__=o.__filtered__||r,o}}),Mt(["head","last"],function(t,n){var e="take"+(n?"Right":"");z.prototype[t]=function(){return this[e](1).value()[0]}}),Mt(["initial","tail"],function(t,n){var e="drop"+(n?"":"Right");z.prototype[t]=function(){return this.__filtered__?new z(this):this[e](1)}}),z.prototype.compact=function(){return this.filter(It)},z.prototype.find=function(t){return this.filter(t).head()},z.prototype.findLast=function(t){return this.reverse().find(t)},z.prototype.invokeMap=K(function(t,n){return typeof t=="function"?new z(this):this.map(function(e){return Se(e,t,n)})}),z.prototype.reject=function(t){return this.filter(Sr(L(t)))},z.prototype.slice=function(t,n){t=B(t);var e=this;return e.__filtered__&&(t>0||n<0)?new z(e):(t<0?e=e.takeRight(-t):t&&(e=e.drop(t)),n!==i&&(n=B(n),e=n<0?e.dropRight(-n):e.take(n-t)),e)},z.prototype.takeRightWhile=function(t){return this.reverse().takeWhile(t).reverse()},z.prototype.toArray=function(){return this.take(Ut)},en(z.prototype,function(t,n){var e=/^(?:filter|find|map|reject)|While$/.test(n),r=/^(?:head|last)$/.test(n),u=s[r?"take"+(n=="last"?"Right":""):n],o=r||/^find/.test(n);u&&(s.prototype[n]=function(){var a=this.__wrapped__,c=r?[1]:arguments,h=a instanceof z,y=c[0],m=h||U(a),x=function(k){var G=u.apply(s,mn([k],c));return r&&A?G[0]:G};m&&e&&typeof y=="function"&&y.length!=1&&(h=m=!1);var A=this.__chain__,I=!!this.__actions__.length,O=o&&!A,$=h&&!I;if(!o&&m){a=$?a:new z(this);var W=t.apply(a,c);return W.__actions__.push({func:wr,args:[x],thisArg:i}),new Kt(W,A)}return O&&$?t.apply(this,c):(W=this.thru(x),O?r?W.value()[0]:W.value():W)})}),Mt(["pop","push","shift","sort","splice","unshift"],function(t){var n=ze[t],e=/^(?:push|sort|unshift)$/.test(t)?"tap":"thru",r=/^(?:pop|shift)$/.test(t);s.prototype[t]=function(){var u=arguments;if(r&&!this.__chain__){var o=this.value();return n.apply(U(o)?o:[],u)}return this[e](function(a){return n.apply(U(a)?a:[],u)})}}),en(z.prototype,function(t,n){var e=s[n];if(e){var r=e.name+"";Q.call(Vn,r)||(Vn[r]=[]),Vn[r].push({name:n,func:e})}}),Vn[lr(i,Rt).name]=[{name:"wrapper",func:i}],z.prototype.clone=wc,z.prototype.reverse=yc,z.prototype.value=mc,s.prototype.at=Yh,s.prototype.chain=Xh,s.prototype.commit=Qh,s.prototype.next=Vh,s.prototype.plant=td,s.prototype.reverse=nd,s.prototype.toJSON=s.prototype.valueOf=s.prototype.value=ed,s.prototype.first=s.prototype.head,ge&&(s.prototype[ge]=jh),s},Yn=Qf();Ln?((Ln.exports=Yn)._=Yn,Zr._=Yn):dt._=Yn}).call(se)}(Te,Te.exports);var ko=Te.exports;const zo=qo(ko);class Ho{constructor(f){D(this,"config");this.config=f}async complete(f,i){var p;await this.persist(f,{...i,success:!0}),(p=this.config.logger)==null||p.debug("Transaction completed:",f)}async fail(f,i){var p;await this.persist(f,{...i,success:!1}),(p=this.config.logger)==null||p.debug("Transaction failed:",{...f,...i})}async persist(f,i){await fetch(`${this.config.apiUrl}/transactions/${f.id}`,{body:JSON.stringify(i),method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","x-persona-apikey":this.config.apiKey}})}}class Go{constructor(f,i){D(this,"transaction");D(this,"manager");this.transaction=f,this.manager=i}getFunctionCall(){return this.transaction.functionCall}async invoke(f,i){var E;const p=this.transaction.functionCall;if(!p){await this.fail("No function call found");return}const _=p.name,v=p.args,S=f[_];if(!S){await this.fail(`Tool ${_} not found`);return}try{const C=zo.get(i,"schema.config.parameters.properties",{}),R=(C&&Object.keys(C).length>0?Object.keys(C):((E=S.toString().replace(/\n/g," ").match(/^[^(]*\(([^)]*)\)/))==null?void 0:E[1].split(",").map(T=>T.trim()).filter(Boolean))||[]).map(T=>v[T]),P=await S.apply(null,R);await this.complete(P)}catch(C){await this.fail(`Error executing tool ${_}: ${C}`)}}async complete(f){await this.manager.complete(this.transaction,{success:!0,output:f,error:null})}async fail(f){await this.manager.fail(this.transaction,{success:!1,output:null,error:f})}}class ji extends ue{constructor(i){super();D(this,"status");D(this,"autostart");D(this,"session");D(this,"config");D(this,"notify",!0);D(this,"_tools");D(this,"_toolSchema",{});if(this.config=i,this.status="disconnected",this.autostart=!0,Array.isArray(i.tools)){this._tools={};for(const p of i.tools)p.schema&&p.implementation&&(this._tools[p.schema.name]=p.implementation,this._toolSchema[p.schema.name]=p)}else this._tools=i.tools}getName(){return"transaction"}getPriority(){return 0}getToolInstance(i){return this._toolSchema[i]}async connect(i){return this.setStatus("connected"),i}async disconnect(){this.setStatus("disconnected"),this.session=null}async syncSession(i){this.session=i}async sendPacket(i){}onTransaction(i){const p=new Ho(this.config),_=new Go(i,p);if(this.config.onTransaction)this.config.onTransaction(_);else{const v=i.functionCall?this.getToolInstance(i.functionCall.name):void 0;_.invoke(this._tools,v)}}getTools(){return this._tools}}function Jo(d,f){if(Array.isArray(d))return d;if(typeof d=="object"&&d!==null){const i=f.dev?"localhost:8000":f.baseUrl||"persona.applica.guru/api",p=f.dev?"http":"https",_=f.dev?"ws":"wss";let v=Object.keys(d).map(S=>{switch(S){case"rest":return Zo(d[S],{baseEndpointProtocol:p,baseEndpoint:i,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger});case"webrtc":return Yo(d[S],{baseWebSocketProtocol:_,baseEndpoint:i,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger});case"websocket":return Xo(d[S],{baseWebSocketProtocol:_,baseEndpoint:i,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger});default:throw new Error(`Unknown protocol: ${S}`)}}).filter(S=>S!==null);return f.tools&&v.push(new ji({apiUrl:`${p}://${i}`,apiKey:f.apiKey,agentId:f.agentId,tools:f.tools,logger:f.logger})),v}throw new Error("Invalid protocols configuration")}function Zo(d,f){return d===!0?new Pr({apiUrl:`${f.baseEndpointProtocol}://${f.baseEndpoint}`,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger}):typeof d=="object"&&d!==null?new Pr(d):null}function Yo(d,f){return d===!0?new Rr({webrtcUrl:`${f.baseWebSocketProtocol}://${f.baseEndpoint}/webrtc`,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger}):typeof d=="object"&&d!==null?new Rr(d):null}function Xo(d,f){return d===!0?new Ir({webSocketUrl:`${f.baseWebSocketProtocol}://${f.baseEndpoint}/websocket`,apiKey:f.apiKey,agentId:f.agentId,userId:f.userId,logger:f.logger}):typeof d=="object"&&d!==null?new Ir(d):null}function Qo(d,f,i,p,_){return v=>{v.type==="message"?Vo(v.payload,d,f,i,_):v.type==="reasoning"?jo(v.payload,d,f,_):v.type==="transaction"&&ta(v.payload,d,p)}}function Vo(d,f,i,p,_){d.createdAt||(d.createdAt=new Date),(d==null?void 0:d.finishReason)==="stop"&&!(d!=null&&d.functionResponse)&&!(d!=null&&d.thought)&&p(!1),d.thought&&(d.type="reasoning"),d.protocol=f.getName(),i(v=>{const S=$n([...v,d]);return _?_(S):S})}function jo(d,f,i,p){const _={type:"reasoning",text:d.thought,role:"assistant",finishReason:"stop",protocol:f.getName(),createdAt:new Date};i(v=>{const S=$n([...v,_]);return p?p(S):S})}function ta(d,f,i){i.filter(p=>p!==f).forEach(p=>p.onTransaction(d))}function na(d){return new Promise((f,i)=>{const p=new FileReader;p.readAsDataURL(d),p.onload=()=>{const v=p.result.split(";base64,")[1];f(v)},p.onerror=_=>{i(_)}})}function ea(d){const f={rest:i=>i.config.apiUrl,webrtc:i=>i.config.webrtcUrl.replace("/webrtc","").replace("ws://","http://").replace("wss://","https://"),websocket:i=>i.config.webSocketUrl.replace("/websocket","").replace("ws://","http://").replace("wss://","https://")};for(const i of d){const p=f[i.getName()];if(p)return p(i)}return null}function ra(d,f,i,p,_){return async v=>{var P;if(((P=v.content[0])==null?void 0:P.type)!=="text")throw new Error("Only text messages are supported");if(!d.some(T=>T.getName()!=="transaction"&&T.status==="connected")){f(T=>{const F={role:"assistant",type:"text",text:"No protocol is connected.",createdAt:new Date,finishReason:"stop"},Y=[...T,F];return p?p(Y):Y});return}const C={role:"user",type:"text",text:v.content[0].text,createdAt:new Date};f(T=>{const F=$n([...T,C]);return p?p(F):F}),i(!0);const M=d.sort((T,F)=>F.getPriority()-T.getPriority()).find(T=>T.status==="connected"),R=[];if(v.attachments)for(const T of v.attachments)T.contentType.startsWith("image/")&&T.file&&R.push({role:"user",image:{contentType:T.contentType,content:await na(T.file)},text:"",type:"text",createdAt:new Date});v.content&&R.push({role:"user",text:v.content[0].text,type:"text",createdAt:new Date}),_==null||_.debug("Sending message:",R),await(M==null?void 0:M.sendPacket({type:"request",payload:R}))}}function ia(d,f,i,p,_,v){return async S=>{var Y;if(((Y=S.content[0])==null?void 0:Y.type)!=="text")throw new Error("Only text messages are supported");const E=d.sort((q,wt)=>wt.getPriority()-q.getPriority()).find(q=>q.status==="connected");if(!E){v==null||v.debug("No protocol available for edit");return}const C=S.parentId;if(!C){v==null||v.debug("No parent ID provided for edit");return}const M=f.findIndex(q=>q.id===C);if(M===-1){v==null||v.debug("Parent message not found:",C);return}const R=f.slice(0,M+1),P={role:"user",text:S.content[0].text,type:"text",createdAt:new Date},T=$n([...R,P]);i(_?_(T):T),p(!0);const F=[{role:"user",text:S.content[0].text,type:"text",createdAt:new Date}];v==null||v.debug("Sending edited message:",F),await E.sendPacket({type:"request",payload:F})}}function ua(d,f,i,p,_,v){return async(S,E)=>{const C=d.sort((Y,q)=>q.getPriority()-Y.getPriority()).find(Y=>Y.status==="connected");if(!C){v==null||v.debug("No protocol available for reload");return}const M=E.parentId??S;if(!M){v==null||v.debug("No parent ID provided for reload");return}const R=f.findIndex(Y=>Y.id===M);if(R===-1){v==null||v.debug("Parent message not found:",M);return}const P=f[R];i(Y=>{const q=Y.slice(0,R+1);return _?_(q):q});let T;if(P.role==="assistant"||P.role==="function"){for(let Y=R-1;Y>=0;Y--)if(f[Y].role==="user"){T=f[Y];break}}else P.role==="user"&&(T=P);if(!T){v==null||v.debug("No user message found to regenerate from");return}p(!0);const F=[];T.image&&F.push({role:"user",image:T.image,text:"",type:"text",createdAt:new Date}),F.push({role:"user",text:T.text,type:"text",createdAt:new Date}),v==null||v.debug("Regenerating message with config:",{actualParentId:M,sourceId:E.sourceId,custom:E.runConfig.custom}),await C.sendPacket({type:"request",payload:F})}}function sa(d,f,i,p){return()=>(i(!1),f(_=>{const v=_[_.length-1];if((v==null?void 0:v.role)==="assistant"&&!v.finishReason){const S=[..._];return S[S.length-1]={...v,finishReason:"stop",status:{type:"incomplete"}},p?p(S):S}return _}),d.forEach(_=>{_.status==="connected"&&_.sendPacket({type:"command",payload:{command:"set_initial_context",arguments:{cancel:!0}}}).catch(()=>{})}),Promise.resolve())}const oe=J.createContext(void 0);function oa(){const d=J.useContext(oe);if(!d)throw new Error("usePersonaRuntime must be used within a PersonaRuntimeProvider");return d}function tu(d){const f=J.useContext(oe);if(!f)throw new Error("usePersonaRuntimeProtocol must be used within a PersonaRuntimeProvider");const i=f.protocols.find(_=>_.getName()===d);if(!i)return null;const p=f.protocolsStatus.get(i.getName());return{...i,connect:i.connect.bind(i),disconnect:i.disconnect.bind(i),sendPacket:i.sendPacket.bind(i),setSession:i.setSession.bind(i),addStatusChangeListener:i.addStatusChangeListener.bind(i),addPacketListener:i.addPacketListener.bind(i),getName:i.getName.bind(i),getPriority:i.getPriority.bind(i),status:p||i.status}}function aa(){const d=J.useContext(oe);if(!d)throw new Error("usePersonaRuntimeEndpoint must be used within a PersonaRuntimeProvider");return ea(d.protocols)}function fa(){return tu("webrtc")}function ca(){const d=J.useContext(oe);if(!d)throw new Error("usePersonaRuntimeMessages must be used within a PersonaRuntimeProvider");return d.getMessages()}function la(){const d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let f="";for(let i=0;i<16;i++)f+=d.charAt(Math.floor(Math.random()*d.length));return f}function ha(d,f,i,p,_,v,S,E,C,M,R){return{threadId:d,threads:f.filter(P=>P.status==="regular").map(P=>({id:P.threadId,threadId:P.threadId,title:P.title||`Chat ${P.threadId}`,status:P.status})),archivedThreads:f.filter(P=>P.status==="archived").map(P=>({id:P.threadId,threadId:P.threadId,title:P.title||`Archived Chat ${P.threadId}`,status:P.status})),onSwitchToNewThread:()=>{const P=la();R==null||R.debug("Creating new thread:",P);const T={threadId:P,status:"regular",title:"New Chat"};p(F=>[T,...F]),i(P),v==null||v(P)},onSwitchToThread:P=>{R==null||R.debug("Switching to thread:",P),i(P),S==null||S(P)},onArchive:P=>{R==null||R.debug("Archiving thread:",P),p(T=>T.map(F=>F.threadId===P?{...F,status:"archived"}:F)),E==null||E(P)},onUnarchive:P=>{R==null||R.debug("Unarchiving thread:",P),p(T=>T.map(F=>F.threadId===P?{...F,status:"regular"}:F)),C==null||C(P)},onDelete:async P=>{if(R==null||R.debug("Deleting thread:",P),p(T=>T.filter(F=>F.threadId!==P)),d===P){const T=f.filter(F=>F.threadId!==P&&F.status==="regular");T.length>0&&i(T[0].threadId)}_.remove(P).then(()=>R==null?void 0:R.debug("Thread deleted from backend")).catch(T=>R==null?void 0:R.error("Failed to delete thread:",T)),M==null||M(P)}}}class nu{constructor(f){D(this,"endpoint");D(this,"apiKey");D(this,"pageSize");D(this,"logger");this.endpoint=f.endpoint.replace(/\/$/,""),this.apiKey=f.apiKey,this.pageSize=f.pageSize??200,this.logger=f.logger}buildHeaders(){const f={"Content-Type":"application/json"};return this.apiKey&&(f["x-persona-apikey"]=this.apiKey),f}async sync(f){var p,_;if(!f)return[];const i=`${this.endpoint}/sessions/${encodeURIComponent(String(f))}/messages?page=1&size=${this.pageSize}`;try{const v=await fetch(i,{method:"GET",headers:this.buildHeaders()});if(!v.ok)return(p=this.logger)==null||p.warn("PersonaSessionStorage: failed to fetch messages",v.status,await v.text()),[];const S=await v.json();return Array.isArray(S.items)?S.items.map(C=>({id:C.id??C.messageId??void 0,protocol:C.protocol,thought:C.thought,text:C.text??"",image:C.image,type:C.type??"text",role:C.role??"assistant",file:C.file,sources:C.sources,sessionId:C.sessionId??f,finishReason:C.finishReason,functionCalls:C.functionCalls,functionResponse:C.functionResponse,status:C.status,createdAt:C.createdAt?new Date(C.createdAt):void 0,metadata:C.metadata})):[]}catch(v){return(_=this.logger)==null||_.warn("PersonaSessionStorage: error fetching messages",v),[]}}async remove(f){var p,_;if(!f)return;const i=`${this.endpoint}/sessions/${encodeURIComponent(String(f))}`;try{const v=await fetch(i,{method:"DELETE",headers:this.buildHeaders()});if(!v.ok){const S=await v.text();throw(p=this.logger)==null||p.warn("PersonaSessionStorage: failed to delete session",v.status,S),new Error(`Failed to delete session: ${v.status}`)}return}catch(v){throw(_=this.logger)==null||_.warn("PersonaSessionStorage: error deleting session",v),v}}async clearAll(){return Promise.reject(new Error("PersonaAPIMessageStorage: clearAll not supported"))}async list(f,i){var v,S;const p=new URLSearchParams({page:"1",size:"100"});i&&p.set("userId",i),f&&p.set("agentId",f);const _=`${this.endpoint}/sessions?${p.toString()}`;try{const E=await fetch(_,{method:"GET",headers:this.buildHeaders()});if(!E.ok)return(v=this.logger)==null||v.warn("PersonaSessionStorage: failed to list sessions",E.status),[];const C=await E.json();return Array.isArray(C.items)?C.items.map(R=>({threadId:R.code||R.id,title:R.title||`Session ${R.code||R.id}`,status:R.status==="archived"?"archived":"regular"})):[]}catch(E){return(S=this.logger)==null||S.warn("PersonaSessionStorage: error listing sessions",E),[]}}}function da({dev:d=!1,baseUrl:f,protocols:i,logger:p,children:_,session:v="new",transformMessages:S,enableThreads:E=!1,sessionStorage:C,onThreadCreate:M,onThreadSwitch:R,onThreadRename:P,onThreadArchive:T,onThreadUnarchive:F,onThreadDelete:Y,...q}){const[wt,Rt]=J.useState(!1),[tn,ot]=J.useState([]),[En,Gt]=J.useState(new Map),vn=J.useRef(!1),At=J.useRef(!1),Nt=J.useMemo(()=>C||new nu({apiKey:q.apiKey,endpoint:f||"https://persona.applica.guru/api"}),[C,f,q.apiKey]),[Kn,Oe]=J.useState([]),[Et,We]=J.useState(""),qn=J.useRef(typeof v=="string"?v:"new"),ae=J.useRef(!1);J.useEffect(()=>{!E||ae.current||(ae.current=!0,Nt.list(q.agentId,q.userId).then(V=>{(V==null?void 0:V.length)>0&&(Oe(V),We(V[0].threadId))}).catch(V=>p==null?void 0:p.error("Failed to load threads:",V)))},[E,Nt,q.agentId,q.userId,p]);const ct=J.useMemo(()=>Jo(i,{dev:d||!1,baseUrl:f,apiKey:q.apiKey,agentId:q.agentId,userId:q.userId,tools:q.tools,logger:p}),[i,d,f,q.apiKey,q.agentId,q.userId,q.tools,p]);J.useEffect(()=>{vn.current||(vn.current=!0,p==null||p.debug("Setting up protocols:",ct.map(V=>V.getName())),ct.forEach(V=>{V.setSession(qn.current),V.clearListeners(),V.addStatusChangeListener(lt=>{p==null||p.debug(`${V.getName()} status: ${lt}`),Gt(Jt=>{const Tn=new Map(Jt);return Tn.set(V.getName(),lt),Tn}),lt==="connected"&&!At.current&&(q.context&&V.sendPacket({type:"command",payload:{command:"set_initial_context",arguments:q.context}}).catch(()=>{}),q.tools&&Array.isArray(q.tools)&&V.sendPacket({type:"command",payload:{command:"set_local_tools",arguments:{tools:q.tools.map(Jt=>Jt.schema)}}}).catch(()=>{}))}),V.addPacketListener(Qo(V,ot,Rt,ct,S)),V.autostart&&V.status==="disconnected"&&(p==null||p.debug(`Auto-connecting protocol: ${V.getName()}`),V.connect(qn.current).catch(()=>{}),Rt(!1))}))},[]),J.useEffect(()=>{if(!E||!Et){ot([]);return}if(At.current||Et===qn.current)return;At.current=!0,p==null||p.info("Switching to thread:",Et),(async()=>{try{const lt=ct.filter(yt=>yt.status==="connected");lt.length>0&&await Promise.allSettled(lt.map(yt=>yt.disconnect())),qn.current=Et,await Promise.allSettled(ct.map(yt=>yt.setSession(Et)));const Jt=await Nt.sync(Et),Tn=$n(Jt);ot(S?S(Tn):Tn),p==null||p.debug(`Loaded ${Jt.length} messages for thread ${Et}`);const wn=ct.filter(yt=>yt.autostart);wn.length>0&&await Promise.allSettled(wn.map(yt=>yt.connect(Et)))}catch(lt){p==null||p.error("Failed to switch thread:",lt),ot([])}finally{At.current=!1}})()},[Et,E,ct,Nt,S,p]);const Er=J.useCallback(ra(ct,ot,Rt,S,p),[ct,S,p]),sn=J.useCallback(ia(ct,tn,ot,Rt,S,p),[ct,tn,S,p]),nn=J.useCallback(ua(ct,tn,ot,Rt,S,p),[ct,tn,S,p]),Tr=J.useCallback(sa(ct,ot,Rt,S),[ct,S]),kn=J.useCallback(V=>{const lt=$n([...V]);ot(S?S(lt):lt)},[S]),Ut=J.useCallback(()=>tn,[tn]),De=J.useMemo(()=>{if(E)return ha(Et,Kn,We,Oe,Nt,M,R,T,F,Y,p)},[E,Et,Kn,Nt,M,R,T,F,Y,p]),Lr=Ee.useExternalStoreRuntime({isRunning:wt,messages:tn,convertMessage:$o,setMessages:kn,onNew:Er,onEdit:sn,onCancel:Tr,onReload:nn,adapters:{attachments:new Ee.CompositeAttachmentAdapter([new Ee.SimpleImageAttachmentAdapter]),...De?{threadList:De}:{}}});return vt.jsx(oe.Provider,{value:{protocols:ct,protocolsStatus:En,getMessages:Ut},children:vt.jsx(Ee.AssistantRuntimeProvider,{runtime:Lr,children:_})})}function pa({children:d,...f}){return vt.jsx(da,{...f,children:d})}class ga{constructor(){D(this,"prefix","[Persona]")}log(f,...i){console.log(`${this.prefix} - ${f}`,...i)}info(f,...i){console.info(`${this.prefix} - ${f}`,...i)}warn(f,...i){console.warn(`${this.prefix} - ${f}`,...i)}error(f,...i){console.error(`${this.prefix} - ${f}`,...i)}debug(f,...i){console.debug(`${this.prefix} - ${f}`,...i)}}function Rn(d,f,i){return{type:d,description:f,...i}}function eu(d){const f=Object.entries(d.parameters).filter(([i,p])=>p.required).map(([i])=>i);return{type:"local",name:d.name,description:d.description,config:{timeout:d.timeout||60,parameters:{type:"object",title:d.title||`${d.name} parameters`,required:f,properties:d.parameters},output:{type:"object",title:`${d.name} output`,properties:d.output}}}}function Le(d){return{schema:eu(d),implementation:d.implementation}}function ru(d,f,i,p,_,v){const S={name:d,description:f,title:v==null?void 0:v.title,timeout:v==null?void 0:v.timeout,parameters:p,output:_,implementation:i};return Le(S)}const _a=ru("sum","Sum two numbers",function(f,i){return{result:f+i}},{a:Rn("number","First number to sum",{required:!0}),b:Rn("number","Second number to sum",{required:!0})},{result:Rn("number","Sum of two numbers")}),va=Le({name:"navigate_to",description:"Allow agent to redirect user to specific sub page like /foo or #/foo or anything like that",title:"Sum two numbers",timeout:60,parameters:{a:Rn("number","First number to sum"),b:Rn("number","Seconth number to sum")},output:{result:Rn("number","Sum of two numbers")},implementation:function(f,i){return{result:f+i}}});function wa(d){const f=[],i={};return d.forEach(p=>{const{schema:_,implementation:v}=Le(p);f.push(_),i[p.name]=v}),{schemas:f,implementations:i}}function ya(d,f){const{required:i,properties:p}=f.config.parameters;for(const _ of i)if(!(_ in d))throw new Error(`Missing required parameter: ${_}`);for(const[_,v]of Object.entries(d)){const S=p[_];if(S){if(S.type==="number"&&typeof v!="number")throw new Error(`Parameter ${_} should be a number`);if(S.type==="string"&&typeof v!="string")throw new Error(`Parameter ${_} should be a string`);if(S.type==="boolean"&&typeof v!="boolean")throw new Error(`Parameter ${_} should be a boolean`)}}return!0}H.PersonaConsoleLogger=ga,H.PersonaProtocolBase=ue,H.PersonaRESTProtocol=Pr,H.PersonaRuntimeProvider=pa,H.PersonaSessionStorage=nu,H.PersonaTransactionProtocol=ji,H.PersonaWebRTCProtocol=Rr,H.PersonaWebSocketProtocol=Ir,H.createParameter=Rn,H.createTool=Le,H.createToolFromFunction=ru,H.createToolRegistry=wa,H.generateToolSchema=eu,H.navigateToToolExample=va,H.sumTool=_a,H.usePersonaRuntime=oa,H.usePersonaRuntimeEndpoint=aa,H.usePersonaRuntimeMessages=ca,H.usePersonaRuntimeProtocol=tu,H.usePersonaRuntimeWebRTCProtocol=fa,H.validateToolParameters=ya,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})});
40
28
  //# sourceMappingURL=bundle.umd.js.map